frame.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Asterisk internal frame definitions.
  20. * \arg For an explanation of frames, see \ref Def_Frame
  21. * \arg Frames are send of Asterisk channels, see \ref Def_Channel
  22. */
  23. #ifndef _ASTERISK_FRAME_H
  24. #define _ASTERISK_FRAME_H
  25. #if defined(__cplusplus) || defined(c_plusplus)
  26. extern "C" {
  27. #endif
  28. #include <sys/time.h>
  29. #include "asterisk/format.h"
  30. #include "asterisk/endian.h"
  31. #include "asterisk/linkedlists.h"
  32. /*!
  33. * \page Def_Frame AST Multimedia and signalling frames
  34. * \section Def_AstFrame What is an ast_frame ?
  35. * A frame of data read used to communicate between
  36. * between channels and applications.
  37. * Frames are divided into frame types and subclasses.
  38. *
  39. * \par Frame types
  40. * \arg \b VOICE: Voice data, subclass is codec (AST_FORMAT_*)
  41. * \arg \b VIDEO: Video data, subclass is codec (AST_FORMAT_*)
  42. * \arg \b DTMF: A DTMF digit, subclass is the digit
  43. * \arg \b IMAGE: Image transport, mostly used in IAX
  44. * \arg \b TEXT: Text messages and character by character (real time text)
  45. * \arg \b TEXT_DATA: Text messages in an ast_msg_data structure
  46. * \arg \b HTML: URL's and web pages
  47. * \arg \b MODEM: Modulated data encodings, such as T.38 and V.150
  48. * \arg \b IAX: Private frame type for the IAX protocol
  49. * \arg \b CNG: Comfort noice frames
  50. * \arg \b CONTROL:A control frame, subclass defined as AST_CONTROL_
  51. * \arg \b NULL: Empty, useless frame
  52. *
  53. * \par Files
  54. * \arg frame.h Definitions
  55. * \arg frame.c Function library
  56. * \arg \ref Def_Channel Asterisk channels
  57. * \section Def_ControlFrame Control Frames
  58. * Control frames send signalling information between channels
  59. * and devices. They are prefixed with AST_CONTROL_, like AST_CONTROL_FRAME_HANGUP
  60. * \arg \b HANGUP The other end has hungup
  61. * \arg \b RING Local ring
  62. * \arg \b RINGING The other end is ringing
  63. * \arg \b ANSWER The other end has answered
  64. * \arg \b BUSY Remote end is busy
  65. * \arg \b TAKEOFFHOOK Make it go off hook (what's "it" ? )
  66. * \arg \b OFFHOOK Line is off hook
  67. * \arg \b CONGESTION Congestion (circuit is busy, not available)
  68. * \arg \b FLASH Other end sends flash hook
  69. * \arg \b WINK Other end sends wink
  70. * \arg \b OPTION Send low-level option
  71. * \arg \b RADIO_KEY Key radio (see app_rpt.c)
  72. * \arg \b RADIO_UNKEY Un-key radio (see app_rpt.c)
  73. * \arg \b PROGRESS Other end indicates call progress
  74. * \arg \b PROCEEDING Indicates proceeding
  75. * \arg \b HOLD Call is placed on hold
  76. * \arg \b UNHOLD Call is back from hold
  77. * \arg \b VIDUPDATE Video update requested
  78. * \arg \b SRCUPDATE The source of media has changed (RTP marker bit must change)
  79. * \arg \b SRCCHANGE Media source has changed (RTP marker bit and SSRC must change)
  80. * \arg \b CONNECTED_LINE Connected line has changed
  81. * \arg \b REDIRECTING Call redirecting information has changed.
  82. */
  83. /*!
  84. * \brief Frame types
  85. *
  86. * \note It is important that the values of each frame type are never changed,
  87. * because it will break backwards compatability with older versions.
  88. * This is because these constants are transmitted directly over IAX2.
  89. */
  90. enum ast_frame_type {
  91. /*! DTMF end event, subclass is the digit */
  92. AST_FRAME_DTMF_END = 1,
  93. /*! Voice data, subclass is AST_FORMAT_* */
  94. AST_FRAME_VOICE,
  95. /*! Video frame, maybe?? :) */
  96. AST_FRAME_VIDEO,
  97. /*! A control frame, subclass is AST_CONTROL_* */
  98. AST_FRAME_CONTROL,
  99. /*! An empty, useless frame */
  100. AST_FRAME_NULL,
  101. /*! Inter Asterisk Exchange private frame type */
  102. AST_FRAME_IAX,
  103. /*! Text messages */
  104. AST_FRAME_TEXT,
  105. /*! Image Frames */
  106. AST_FRAME_IMAGE,
  107. /*! HTML Frame */
  108. AST_FRAME_HTML,
  109. /*! Comfort Noise frame (subclass is level of CNG in -dBov),
  110. body may include zero or more 8-bit quantization coefficients */
  111. AST_FRAME_CNG,
  112. /*! Modem-over-IP data streams */
  113. AST_FRAME_MODEM,
  114. /*! DTMF begin event, subclass is the digit */
  115. AST_FRAME_DTMF_BEGIN,
  116. /*! Internal bridge module action. */
  117. AST_FRAME_BRIDGE_ACTION,
  118. /*! Internal synchronous bridge module action.
  119. * Synchronous bridge actions may be queued onto bridge
  120. * channels, but they absolutely must not ever be written
  121. * directly into bridges.
  122. */
  123. AST_FRAME_BRIDGE_ACTION_SYNC,
  124. /*! RTCP feedback (the subclass will contain the payload type) */
  125. AST_FRAME_RTCP,
  126. /*! Text message in an ast_msg_data structure */
  127. AST_FRAME_TEXT_DATA,
  128. };
  129. #define AST_FRAME_DTMF AST_FRAME_DTMF_END
  130. enum {
  131. /*! This frame contains valid timing information */
  132. AST_FRFLAG_HAS_TIMING_INFO = (1 << 0),
  133. /*! This frame has been requeued */
  134. AST_FRFLAG_REQUEUED = (1 << 1),
  135. };
  136. struct ast_frame_subclass {
  137. /*! A frame specific code */
  138. int integer;
  139. /*! The asterisk media format */
  140. struct ast_format *format;
  141. /*! For video formats, an indication that a frame ended */
  142. unsigned int frame_ending;
  143. };
  144. /*! \brief Data structure associated with a single frame of data
  145. */
  146. struct ast_frame {
  147. /*! Kind of frame */
  148. enum ast_frame_type frametype;
  149. /*! Subclass, frame dependent */
  150. struct ast_frame_subclass subclass;
  151. /*! Length of data */
  152. int datalen;
  153. /*! Number of samples in this frame */
  154. int samples;
  155. /*! Was the data malloc'd? i.e. should we free it when we discard the frame? */
  156. int mallocd;
  157. /*! The number of bytes allocated for a malloc'd frame header */
  158. size_t mallocd_hdr_len;
  159. /*! How many bytes exist _before_ "data" that can be used if needed */
  160. int offset;
  161. /*! Optional source of frame for debugging */
  162. const char *src;
  163. /*! Pointer to actual data */
  164. union { void *ptr; uint32_t uint32; char pad[8]; } data;
  165. /*! Global delivery time */
  166. struct timeval delivery;
  167. /*! For placing in a linked list */
  168. AST_LIST_ENTRY(ast_frame) frame_list;
  169. /*! Misc. frame flags */
  170. unsigned int flags;
  171. /*! Timestamp in milliseconds */
  172. long ts;
  173. /*! Length in milliseconds */
  174. long len;
  175. /*! Sequence number */
  176. int seqno;
  177. };
  178. /*!
  179. * Set the various field of a frame to point to a buffer.
  180. * Typically you set the base address of the buffer, the offset as
  181. * AST_FRIENDLY_OFFSET, and the datalen as the amount of bytes queued.
  182. * The remaining things (to be done manually) is set the number of
  183. * samples, which cannot be derived from the datalen unless you know
  184. * the number of bits per sample.
  185. */
  186. #define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen) \
  187. { \
  188. (fr)->data.ptr = (char *)_base + (_ofs); \
  189. (fr)->offset = (_ofs); \
  190. (fr)->datalen = (_datalen); \
  191. }
  192. /*! Queueing a null frame is fairly common, so we declare a global null frame object
  193. for this purpose instead of having to declare one on the stack */
  194. extern struct ast_frame ast_null_frame;
  195. /*! \brief Offset into a frame's data buffer.
  196. *
  197. * By providing some "empty" space prior to the actual data of an ast_frame,
  198. * this gives any consumer of the frame ample space to prepend other necessary
  199. * information without having to create a new buffer.
  200. *
  201. * As an example, RTP can use the data from an ast_frame and simply prepend the
  202. * RTP header information into the space provided by AST_FRIENDLY_OFFSET instead
  203. * of having to create a new buffer with the necessary space allocated.
  204. */
  205. #define AST_FRIENDLY_OFFSET 64
  206. #define AST_MIN_OFFSET 32 /*! Make sure we keep at least this much handy */
  207. /*! Need the header be free'd? */
  208. #define AST_MALLOCD_HDR (1 << 0)
  209. /*! Need the data be free'd? */
  210. #define AST_MALLOCD_DATA (1 << 1)
  211. /*! Need the source be free'd? (haha!) */
  212. #define AST_MALLOCD_SRC (1 << 2)
  213. /* MODEM subclasses */
  214. /*! T.38 Fax-over-IP */
  215. #define AST_MODEM_T38 1
  216. /*! V.150 Modem-over-IP */
  217. #define AST_MODEM_V150 2
  218. /* HTML subclasses */
  219. /*! Sending a URL */
  220. #define AST_HTML_URL 1
  221. /*! Data frame */
  222. #define AST_HTML_DATA 2
  223. /*! Beginning frame */
  224. #define AST_HTML_BEGIN 4
  225. /*! End frame */
  226. #define AST_HTML_END 8
  227. /*! Load is complete */
  228. #define AST_HTML_LDCOMPLETE 16
  229. /*! Peer is unable to support HTML */
  230. #define AST_HTML_NOSUPPORT 17
  231. /*! Send URL, and track */
  232. #define AST_HTML_LINKURL 18
  233. /*! No more HTML linkage */
  234. #define AST_HTML_UNLINK 19
  235. /*! Reject link request */
  236. #define AST_HTML_LINKREJECT 20
  237. /*!
  238. * \brief Internal control frame subtype field values.
  239. *
  240. * \warning
  241. * IAX2 sends these values out over the wire. To prevent future
  242. * incompatibilities, pick the next value in the enum from whatever
  243. * is on the current trunk. If you lose the merge race you need to
  244. * fix the previous branches to match what is on trunk. In addition
  245. * you need to change chan_iax2 to explicitly allow the control
  246. * frame over the wire if it makes sense for the frame to be passed
  247. * to another Asterisk instance.
  248. */
  249. enum ast_control_frame_type {
  250. AST_CONTROL_HANGUP = 1, /*!< Other end has hungup */
  251. AST_CONTROL_RING = 2, /*!< Local ring */
  252. AST_CONTROL_RINGING = 3, /*!< Remote end is ringing */
  253. AST_CONTROL_ANSWER = 4, /*!< Remote end has answered */
  254. AST_CONTROL_BUSY = 5, /*!< Remote end is busy */
  255. AST_CONTROL_TAKEOFFHOOK = 6, /*!< Make it go off hook */
  256. AST_CONTROL_OFFHOOK = 7, /*!< Line is off hook */
  257. AST_CONTROL_CONGESTION = 8, /*!< Congestion (circuits busy) */
  258. AST_CONTROL_FLASH = 9, /*!< Flash hook */
  259. AST_CONTROL_WINK = 10, /*!< Wink */
  260. AST_CONTROL_OPTION = 11, /*!< Set a low-level option */
  261. AST_CONTROL_RADIO_KEY = 12, /*!< Key Radio */
  262. AST_CONTROL_RADIO_UNKEY = 13, /*!< Un-Key Radio */
  263. AST_CONTROL_PROGRESS = 14, /*!< Indicate PROGRESS */
  264. AST_CONTROL_PROCEEDING = 15, /*!< Indicate CALL PROCEEDING */
  265. AST_CONTROL_HOLD = 16, /*!< Indicate call is placed on hold */
  266. AST_CONTROL_UNHOLD = 17, /*!< Indicate call is left from hold */
  267. AST_CONTROL_VIDUPDATE = 18, /*!< Indicate video frame update */
  268. _XXX_AST_CONTROL_T38 = 19, /*!< T38 state change request/notification \deprecated This is no longer supported. Use AST_CONTROL_T38_PARAMETERS instead. */
  269. AST_CONTROL_SRCUPDATE = 20, /*!< Indicate source of media has changed */
  270. AST_CONTROL_TRANSFER = 21, /*!< Indicate status of a transfer request */
  271. AST_CONTROL_CONNECTED_LINE = 22,/*!< Indicate connected line has changed */
  272. AST_CONTROL_REDIRECTING = 23, /*!< Indicate redirecting id has changed */
  273. AST_CONTROL_T38_PARAMETERS = 24,/*!< T38 state change request/notification with parameters */
  274. AST_CONTROL_CC = 25, /*!< Indication that Call completion service is possible */
  275. AST_CONTROL_SRCCHANGE = 26, /*!< Media source has changed and requires a new RTP SSRC */
  276. AST_CONTROL_READ_ACTION = 27, /*!< Tell ast_read to take a specific action */
  277. AST_CONTROL_AOC = 28, /*!< Advice of Charge with encoded generic AOC payload */
  278. AST_CONTROL_END_OF_Q = 29, /*!< Indicate that this position was the end of the channel queue for a softhangup. */
  279. AST_CONTROL_INCOMPLETE = 30, /*!< Indication that the extension dialed is incomplete */
  280. AST_CONTROL_MCID = 31, /*!< Indicate that the caller is being malicious. */
  281. AST_CONTROL_UPDATE_RTP_PEER = 32, /*!< Interrupt the bridge and have it update the peer */
  282. AST_CONTROL_PVT_CAUSE_CODE = 33, /*!< Contains an update to the protocol-specific cause-code stored for branching dials */
  283. AST_CONTROL_MASQUERADE_NOTIFY = 34, /*!< A masquerade is about to begin/end. (Never sent as a frame but directly with ast_indicate_data().) */
  284. /*
  285. * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  286. *
  287. * IAX2 sends these values out over the wire. To prevent future
  288. * incompatibilities, pick the next value in the enum from whatever
  289. * is on the current trunk. If you lose the merge race you need to
  290. * fix the previous branches to match what is on trunk. In addition
  291. * you need to change chan_iax2 to explicitly allow the control
  292. * frame over the wire if it makes sense for the frame to be passed
  293. * to another Asterisk instance.
  294. *
  295. * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  296. */
  297. /* Control frames used to manipulate a stream on a channel. The values for these
  298. * must be greater than the allowed value for a 8-bit char, so that they avoid
  299. * conflicts with DTMF values. */
  300. AST_CONTROL_STREAM_STOP = 1000, /*!< Indicate to a channel in playback to stop the stream */
  301. AST_CONTROL_STREAM_SUSPEND = 1001, /*!< Indicate to a channel in playback to suspend the stream */
  302. AST_CONTROL_STREAM_RESTART = 1002, /*!< Indicate to a channel in playback to restart the stream */
  303. AST_CONTROL_STREAM_REVERSE = 1003, /*!< Indicate to a channel in playback to rewind */
  304. AST_CONTROL_STREAM_FORWARD = 1004, /*!< Indicate to a channel in playback to fast forward */
  305. /* Control frames to manipulate recording on a channel. */
  306. AST_CONTROL_RECORD_CANCEL = 1100, /*!< Indicated to a channel in record to stop recording and discard the file */
  307. AST_CONTROL_RECORD_STOP = 1101, /*!< Indicated to a channel in record to stop recording */
  308. AST_CONTROL_RECORD_SUSPEND = 1102, /*!< Indicated to a channel in record to suspend/unsuspend recording */
  309. AST_CONTROL_RECORD_MUTE = 1103, /*!< Indicated to a channel in record to mute/unmute (i.e. write silence) recording */
  310. };
  311. enum ast_frame_read_action {
  312. AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO,
  313. AST_FRAME_READ_ACTION_SEND_TEXT,
  314. };
  315. struct ast_control_read_action_payload {
  316. /* An indicator to ast_read of what action to
  317. * take with the frame;
  318. */
  319. enum ast_frame_read_action action;
  320. /* The size of the frame's payload
  321. */
  322. size_t payload_size;
  323. /* A payload for the frame.
  324. */
  325. unsigned char payload[0];
  326. };
  327. enum ast_control_t38 {
  328. AST_T38_REQUEST_NEGOTIATE = 1, /*!< Request T38 on a channel (voice to fax) */
  329. AST_T38_REQUEST_TERMINATE, /*!< Terminate T38 on a channel (fax to voice) */
  330. AST_T38_NEGOTIATED, /*!< T38 negotiated (fax mode) */
  331. AST_T38_TERMINATED, /*!< T38 terminated (back to voice) */
  332. AST_T38_REFUSED, /*!< T38 refused for some reason (usually rejected by remote end) */
  333. AST_T38_REQUEST_PARMS, /*!< request far end T.38 parameters for a channel in 'negotiating' state */
  334. };
  335. enum ast_control_t38_rate {
  336. AST_T38_RATE_2400 = 1,
  337. AST_T38_RATE_4800,
  338. AST_T38_RATE_7200,
  339. AST_T38_RATE_9600,
  340. AST_T38_RATE_12000,
  341. /* Set to 0 so it's taken as default when unspecified.
  342. * See ITU-T T.38 Implementors' Guide (11 May 2012),
  343. * Table H.2: if the T38MaxBitRate attribute is omitted
  344. * it should use a default of 14400. */
  345. AST_T38_RATE_14400 = 0,
  346. };
  347. enum ast_control_t38_rate_management {
  348. AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF = 0,
  349. AST_T38_RATE_MANAGEMENT_LOCAL_TCF,
  350. };
  351. struct ast_control_t38_parameters {
  352. enum ast_control_t38 request_response; /*!< Request or response of the T38 control frame */
  353. unsigned int version; /*!< Supported T.38 version */
  354. unsigned int max_ifp; /*!< Maximum IFP size supported */
  355. enum ast_control_t38_rate rate; /*!< Maximum fax rate supported */
  356. enum ast_control_t38_rate_management rate_management; /*!< Rate management setting */
  357. unsigned int fill_bit_removal:1; /*!< Set if fill bit removal can be used */
  358. unsigned int transcoding_mmr:1; /*!< Set if MMR transcoding can be used */
  359. unsigned int transcoding_jbig:1; /*!< Set if JBIG transcoding can be used */
  360. };
  361. enum ast_control_transfer {
  362. AST_TRANSFER_SUCCESS = 0, /*!< Transfer request on the channel worked */
  363. AST_TRANSFER_FAILED, /*!< Transfer request on the channel failed */
  364. };
  365. struct ast_control_pvt_cause_code {
  366. char chan_name[AST_CHANNEL_NAME]; /*!< Name of the channel that originated the cause information */
  367. unsigned int emulate_sip_cause:1; /*!< Indicates whether this should be used to emulate SIP_CAUSE support */
  368. int ast_cause; /*!< Asterisk cause code associated with this message */
  369. char code[1]; /*!< Tech-specific cause code information, beginning with the name of the tech */
  370. };
  371. /* Option identifiers and flags */
  372. #define AST_OPTION_FLAG_REQUEST 0
  373. #define AST_OPTION_FLAG_ACCEPT 1
  374. #define AST_OPTION_FLAG_REJECT 2
  375. #define AST_OPTION_FLAG_QUERY 4
  376. #define AST_OPTION_FLAG_ANSWER 5
  377. #define AST_OPTION_FLAG_WTF 6
  378. /*! Verify touchtones by muting audio transmission
  379. * (and reception) and verify the tone is still present
  380. * Option data is a single signed char value 0 or 1 */
  381. #define AST_OPTION_TONE_VERIFY 1
  382. /*! Put a compatible channel into TDD (TTY for the hearing-impared) mode
  383. * Option data is a single signed char value 0 or 1 */
  384. #define AST_OPTION_TDD 2
  385. /*! Relax the parameters for DTMF reception (mainly for radio use)
  386. * Option data is a single signed char value 0 or 1 */
  387. #define AST_OPTION_RELAXDTMF 3
  388. /*! Set (or clear) Audio (Not-Clear) Mode
  389. * Option data is a single signed char value 0 or 1 */
  390. #define AST_OPTION_AUDIO_MODE 4
  391. /*! Set channel transmit gain
  392. * Option data is a single signed char representing number of decibels (dB)
  393. * to set gain to (on top of any gain specified in channel driver) */
  394. #define AST_OPTION_TXGAIN 5
  395. /*! Set channel receive gain
  396. * Option data is a single signed char representing number of decibels (dB)
  397. * to set gain to (on top of any gain specified in channel driver) */
  398. #define AST_OPTION_RXGAIN 6
  399. /* set channel into "Operator Services" mode
  400. * Option data is a struct oprmode
  401. *
  402. * \note This option should never be sent over the network */
  403. #define AST_OPTION_OPRMODE 7
  404. /*! Explicitly enable or disable echo cancelation for the given channel
  405. * Option data is a single signed char value 0 or 1
  406. *
  407. * \note This option appears to be unused in the code. It is handled, but never
  408. * set or queried. */
  409. #define AST_OPTION_ECHOCAN 8
  410. /*! \brief Handle channel write data
  411. * If a channel needs to process the data from a func_channel write operation
  412. * after func_channel_write executes, it can define the setoption callback
  413. * and process this option. A pointer to an ast_chan_write_info_t will be passed.
  414. *
  415. * \note This option should never be passed over the network. */
  416. #define AST_OPTION_CHANNEL_WRITE 9
  417. /* !
  418. * Read-only. Allows query current status of T38 on the channel.
  419. * data: ast_t38state
  420. */
  421. #define AST_OPTION_T38_STATE 10
  422. /*! Request that the channel driver deliver frames in a specific format
  423. * Option data is a format_t */
  424. #define AST_OPTION_FORMAT_READ 11
  425. /*! Request that the channel driver be prepared to accept frames in a specific format
  426. * Option data is a format_t */
  427. #define AST_OPTION_FORMAT_WRITE 12
  428. /*! Request that the channel driver make two channels of the same tech type compatible if possible
  429. * Option data is an ast_channel
  430. *
  431. * \note This option should never be passed over the network */
  432. #define AST_OPTION_MAKE_COMPATIBLE 13
  433. /*! Get or set the digit detection state of the channel
  434. * Option data is a single signed char value 0 or 1 */
  435. #define AST_OPTION_DIGIT_DETECT 14
  436. /*! Get or set the fax tone detection state of the channel
  437. * Option data is a single signed char value 0 or 1 */
  438. #define AST_OPTION_FAX_DETECT 15
  439. /*! Get the device name from the channel (Read only)
  440. * Option data is a character buffer of suitable length */
  441. #define AST_OPTION_DEVICE_NAME 16
  442. /*! Get the CC agent type from the channel (Read only)
  443. * Option data is a character buffer of suitable length */
  444. #define AST_OPTION_CC_AGENT_TYPE 17
  445. /*! Get or set the security options on a channel
  446. * Option data is an integer value of 0 or 1 */
  447. #define AST_OPTION_SECURE_SIGNALING 18
  448. #define AST_OPTION_SECURE_MEDIA 19
  449. struct oprmode {
  450. struct ast_channel *peer;
  451. int mode;
  452. } ;
  453. struct ast_option_header {
  454. /* Always keep in network byte order */
  455. #if __BYTE_ORDER == __BIG_ENDIAN
  456. uint16_t flag:3;
  457. uint16_t option:13;
  458. #else
  459. #if __BYTE_ORDER == __LITTLE_ENDIAN
  460. uint16_t option:13;
  461. uint16_t flag:3;
  462. #else
  463. #error Byte order not defined
  464. #endif
  465. #endif
  466. uint8_t data[0];
  467. };
  468. /*! \brief Requests a frame to be allocated
  469. *
  470. * \param source
  471. * Request a frame be allocated. source is an optional source of the frame,
  472. * len is the requested length, or "0" if the caller will supply the buffer
  473. */
  474. #if 0 /* Unimplemented */
  475. struct ast_frame *ast_fralloc(char *source, int len);
  476. #endif
  477. /*!
  478. * \brief Frees a frame or list of frames
  479. *
  480. * \param fr Frame to free, or head of list to free
  481. * \param cache Whether to consider this frame for frame caching
  482. */
  483. void ast_frame_free(struct ast_frame *fr, int cache);
  484. #define ast_frfree(fr) ast_frame_free(fr, 1)
  485. /*!
  486. * \brief NULL-safe wrapper for \ref ast_frfree, good for \ref RAII_VAR.
  487. * \param frame Frame to free, or head of list to free.
  488. */
  489. void ast_frame_dtor(struct ast_frame *frame);
  490. /*! \brief Makes a frame independent of any static storage
  491. * \param fr frame to act upon
  492. * Take a frame, and if it's not been malloc'd, make a malloc'd copy
  493. * and if the data hasn't been malloced then make the
  494. * data malloc'd. If you need to store frames, say for queueing, then
  495. * you should call this function.
  496. * \return Returns a frame on success, NULL on error
  497. * \note This function may modify the frame passed to it, so you must
  498. * not assume the frame will be intact after the isolated frame has
  499. * been produced. In other words, calling this function on a frame
  500. * should be the last operation you do with that frame before freeing
  501. * it (or exiting the block, if the frame is on the stack.)
  502. */
  503. struct ast_frame *ast_frisolate(struct ast_frame *fr);
  504. /*! \brief Copies a frame
  505. * \param fr frame to copy
  506. * Duplicates a frame -- should only rarely be used, typically frisolate is good enough
  507. * \return Returns a frame on success, NULL on error
  508. */
  509. struct ast_frame *ast_frdup(const struct ast_frame *fr);
  510. void ast_swapcopy_samples(void *dst, const void *src, int samples);
  511. /* Helpers for byteswapping native samples to/from
  512. little-endian and big-endian. */
  513. #if __BYTE_ORDER == __LITTLE_ENDIAN
  514. #define ast_frame_byteswap_le(fr) do { ; } while(0)
  515. #define ast_frame_byteswap_be(fr) do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data.ptr, __f->data.ptr, __f->samples); } while(0)
  516. #else
  517. #define ast_frame_byteswap_le(fr) do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data.ptr, __f->data.ptr, __f->samples); } while(0)
  518. #define ast_frame_byteswap_be(fr) do { ; } while(0)
  519. #endif
  520. void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix);
  521. /*! \brief Appends a frame to the end of a list of frames, truncating the maximum length of the list */
  522. struct ast_frame *ast_frame_enqueue(struct ast_frame *head, struct ast_frame *f, int maxlen, int dupe);
  523. /*!
  524. \brief Adjusts the volume of the audio samples contained in a frame.
  525. \param f The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR)
  526. \param adjustment The number of dB to adjust up or down.
  527. \return 0 for success, non-zero for an error
  528. */
  529. int ast_frame_adjust_volume(struct ast_frame *f, int adjustment);
  530. /*!
  531. \brief Sums two frames of audio samples.
  532. \param f1 The first frame (which will contain the result)
  533. \param f2 The second frame
  534. \return 0 for success, non-zero for an error
  535. The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples,
  536. and must contain the same number of samples.
  537. */
  538. int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2);
  539. /*!
  540. * \brief Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR
  541. */
  542. int ast_frame_clear(struct ast_frame *frame);
  543. /*!
  544. * \brief Copy the discription of a frame's subclass into the provided string
  545. *
  546. * \param f The frame to get the information from
  547. * \param subclass Buffer to fill with subclass information
  548. * \param slen Length of subclass buffer
  549. * \param moreinfo Buffer to fill with additional information
  550. * \param mlen Length of moreinfo buffer
  551. * \since 11
  552. */
  553. void ast_frame_subclass2str(struct ast_frame *f, char *subclass, size_t slen, char *moreinfo, size_t mlen);
  554. /*!
  555. * \brief Copy the discription of a frame type into the provided string
  556. *
  557. * \param frame_type The frame type to be described
  558. * \param ftype Buffer to fill with frame type description
  559. * \param len Length of subclass buffer
  560. * \since 11
  561. */
  562. void ast_frame_type2str(enum ast_frame_type frame_type, char *ftype, size_t len);
  563. #if defined(__cplusplus) || defined(c_plusplus)
  564. }
  565. #endif
  566. #endif /* _ASTERISK_FRAME_H */