Sat Apr 26 2014 22:02:50

Asterisk developer's documentation


format.h File Reference

Format API. More...

#include "asterisk/astobj2.h"
#include "asterisk/silk.h"
#include "asterisk/celt.h"
Include dependency graph for format.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_format
 Represents a media format within Asterisk. More...
struct  ast_format_attr
 This structure contains the buffer used for format attributes. More...
struct  ast_format_attr_interface
 A format must register an attribute interface if it requires the use of the format attributes void pointer. More...
struct  ast_format_list
 Definition of supported media formats (codecs) More...

Defines

#define AST_FORMAT_ATTR_END   -1
#define AST_FORMAT_ATTR_SIZE   64
#define AST_FORMAT_GET_TYPE(id)   (((int) (id / AST_FORMAT_INC)) * AST_FORMAT_INC)
#define AST_FORMAT_INC   100000

Enumerations

enum  ast_format_cmp_res { AST_FORMAT_CMP_EQUAL = 0, AST_FORMAT_CMP_NOT_EQUAL, AST_FORMAT_CMP_SUBSET }
enum  ast_format_id {
  AST_FORMAT_G723_1 = 1 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_GSM = 2 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_ULAW = 3 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_ALAW = 4 + AST_FORMAT_TYPE_AUDIO,
  AST_FORMAT_G726_AAL2 = 5 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_ADPCM = 6 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_LPC10 = 7 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_G729A = 8 + AST_FORMAT_TYPE_AUDIO,
  AST_FORMAT_SPEEX = 9 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_ILBC = 10 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_G726 = 11 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_G722 = 12 + AST_FORMAT_TYPE_AUDIO,
  AST_FORMAT_SIREN7 = 13 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SIREN14 = 14 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_G719 = 15 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SPEEX16 = 16 + AST_FORMAT_TYPE_AUDIO,
  AST_FORMAT_TESTLAW = 17 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SILK = 18 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SLINEAR = 19 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SLINEAR12 = 20 + AST_FORMAT_TYPE_AUDIO,
  AST_FORMAT_SLINEAR16 = 21 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SLINEAR24 = 22 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SLINEAR32 = 23 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SLINEAR44 = 24 + AST_FORMAT_TYPE_AUDIO,
  AST_FORMAT_SLINEAR48 = 25 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SLINEAR96 = 26 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SLINEAR192 = 27 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_SPEEX32 = 28 + AST_FORMAT_TYPE_AUDIO,
  AST_FORMAT_CELT = 29 + AST_FORMAT_TYPE_AUDIO, AST_FORMAT_H261 = 1 + AST_FORMAT_TYPE_VIDEO, AST_FORMAT_H263 = 2 + AST_FORMAT_TYPE_VIDEO, AST_FORMAT_H263_PLUS = 3 + AST_FORMAT_TYPE_VIDEO,
  AST_FORMAT_H264 = 4 + AST_FORMAT_TYPE_VIDEO, AST_FORMAT_MP4_VIDEO = 5 + AST_FORMAT_TYPE_VIDEO, AST_FORMAT_JPEG = 1 + AST_FORMAT_TYPE_IMAGE, AST_FORMAT_PNG = 2 + AST_FORMAT_TYPE_IMAGE,
  AST_FORMAT_T140RED = 1 + AST_FORMAT_TYPE_TEXT, AST_FORMAT_T140 = 2 + AST_FORMAT_TYPE_TEXT
}
enum  ast_format_type { AST_FORMAT_TYPE_AUDIO = 1 * AST_FORMAT_INC, AST_FORMAT_TYPE_VIDEO = 2 * AST_FORMAT_INC, AST_FORMAT_TYPE_IMAGE = 3 * AST_FORMAT_INC, AST_FORMAT_TYPE_TEXT = 4 * AST_FORMAT_INC }

Functions

const char * ast_codec2str (struct ast_format *format)
 Get a name from a format.
struct ast_formatast_format_append (struct ast_format *format,...)
 After ast_format_set has been used on a function, this function can be used to set additional format attributes to the structure.
int ast_format_attr_reg_interface (const struct ast_format_attr_interface *interface)
 register ast_format_attr_interface with core.
int ast_format_attr_unreg_interface (const struct ast_format_attr_interface *interface)
 unregister format_attr interface with core.
void ast_format_clear (struct ast_format *format)
 Clears the format stucture.
enum ast_format_cmp_res ast_format_cmp (const struct ast_format *format1, const struct ast_format *format2)
 Compare ast_formats structures.
void ast_format_copy (struct ast_format *dst, const struct ast_format *src)
 copy format src into format dst.
struct ast_formatast_format_from_old_bitfield (struct ast_format *dst, uint64_t src)
 convert old bitfield format to ast_format represenatation
int ast_format_get_value (const struct ast_format *format, int key, void *value)
 Get a value from a format containing attributes.
int ast_format_get_video_mark (const struct ast_format *format)
 Determine of the marker bit is set or not on this format.
enum ast_format_id ast_format_id_from_old_bitfield (uint64_t src)
 convert old bitfield format to ast_format_id value
uint64_t ast_format_id_to_old_bitfield (enum ast_format_id id)
 ast_format_id to old bitfield format represenatation
int ast_format_is_slinear (const struct ast_format *format)
 Determine if a format is 16bit signed linear of any sample rate.
int ast_format_isset (const struct ast_format *format,...)
 This function is used to set an ast_format object to represent a media format with optional capability attributes represented by format specific key value pairs.
int ast_format_joint (const struct ast_format *format1, const struct ast_format *format2, struct ast_format *result)
 Find joint format attributes of two ast_format structures containing the same uid and return the intersection in the result structure.
struct ast_format_listast_format_list_destroy (const struct ast_format_list *list)
 Destroy an ast_format_list gotten from ast_format_list_get()
struct ast_format_listast_format_list_get (size_t *size)
 Retrieve the global format list in a read only array.
int ast_format_rate (const struct ast_format *format)
 Get the sample rate for a given format.
void ast_format_sdp_generate (const struct ast_format *format, unsigned int payload, struct ast_str **str)
 This function is used to produce an fmtp SDP line for an Asterisk format. The attributes present on the Asterisk format are translated into the SDP equivalent.
int ast_format_sdp_parse (struct ast_format *format, const char *attributes)
 This function is used to have a media format aware module parse and interpret SDP attribute information. Once interpreted this information is stored on the format itself using Asterisk format attributes.
struct ast_formatast_format_set (struct ast_format *format, enum ast_format_id id, int set_attributes,...)
 This function is used to set an ast_format object to represent a media format with optional format attributes represented by format specific key value pairs.
void ast_format_set_video_mark (struct ast_format *format)
 Set the rtp mark value on the format to indicate to the interface writing this format's payload that a new RTP marker is necessary.
enum ast_format_id ast_format_slin_by_rate (unsigned int rate)
 Get the best slinear format id for a given sample rate.
uint64_t ast_format_to_old_bitfield (const struct ast_format *format)
 ast_format to old bitfield format represenatation
struct ast_formatast_getformatbyname (const char *name, struct ast_format *format)
 Gets a format from a name.
const char * ast_getformatname (const struct ast_format *format)
 Get the name of a format.
char * ast_getformatname_multiple_byid (char *buf, size_t size, enum ast_format_id id)
 Returns a string containing all formats pertaining to an format id.

Detailed Description

Format API.

Author:
David Vossel <dvossel@digium.com>

Definition in file format.h.


Define Documentation

#define AST_FORMAT_ATTR_END   -1

This is the value that ends a var list of format attribute key value pairs.

Definition at line 37 of file format.h.

Referenced by ast_codec_get_samples(), ast_format_rate(), celt_isset(), celt_set(), custom_celt_format(), custom_silk_format(), silk_isset(), and silk_set().

#define AST_FORMAT_ATTR_SIZE   64

Definition at line 32 of file format.h.

#define AST_FORMAT_INC   100000

Definition at line 33 of file format.h.


Enumeration Type Documentation

Enumerator:
AST_FORMAT_CMP_EQUAL 

structure 1 is identical to structure 2.

AST_FORMAT_CMP_NOT_EQUAL 

structure 1 contains elements not in structure 2.

AST_FORMAT_CMP_SUBSET 

structure 1 is a proper subset of the elements in structure 2.

Definition at line 148 of file format.h.

                        {
   /*! structure 1 is identical to structure 2. */
   AST_FORMAT_CMP_EQUAL = 0,
   /*! structure 1 contains elements not in structure 2. */
   AST_FORMAT_CMP_NOT_EQUAL,
   /*! structure 1 is a proper subset of the elements in structure 2.*/
   AST_FORMAT_CMP_SUBSET,
};
Enumerator:
AST_FORMAT_G723_1 

G.723.1 compression

AST_FORMAT_GSM 

GSM compression

AST_FORMAT_ULAW 

Raw mu-law data (G.711)

AST_FORMAT_ALAW 

Raw A-law data (G.711)

AST_FORMAT_G726_AAL2 

ADPCM (G.726, 32kbps, AAL2 codeword packing)

AST_FORMAT_ADPCM 

ADPCM (IMA)

AST_FORMAT_LPC10 

LPC10, 180 samples/frame

AST_FORMAT_G729A 

G.729A audio

AST_FORMAT_SPEEX 

SpeeX Free Compression

AST_FORMAT_ILBC 

iLBC Free Compression

AST_FORMAT_G726 

ADPCM (G.726, 32kbps, RFC3551 codeword packing)

AST_FORMAT_G722 

G.722

AST_FORMAT_SIREN7 

G.722.1 (also known as Siren7, 32kbps assumed)

AST_FORMAT_SIREN14 

G.722.1 Annex C (also known as Siren14, 48kbps assumed)

AST_FORMAT_G719 

G.719 (64 kbps assumed)

AST_FORMAT_SPEEX16 

SpeeX Wideband (16kHz) Free Compression

AST_FORMAT_TESTLAW 

Raw mu-law data (G.711)

AST_FORMAT_SILK 

SILK format

AST_FORMAT_SLINEAR 

Raw 16-bit Signed Linear (8000 Hz) PCM

AST_FORMAT_SLINEAR12 

Raw 16-bit Signed Linear (12000 Hz) PCM

AST_FORMAT_SLINEAR16 

Raw 16-bit Signed Linear (16000 Hz) PCM

AST_FORMAT_SLINEAR24 

Raw 16-bit Signed Linear (24000 Hz) PCM

AST_FORMAT_SLINEAR32 

Raw 16-bit Signed Linear (32000 Hz) PCM

AST_FORMAT_SLINEAR44 

Raw 16-bit Signed Linear (44100 Hz) PCM just because we can.

AST_FORMAT_SLINEAR48 

Raw 16-bit Signed Linear (48000 Hz) PCM

AST_FORMAT_SLINEAR96 

Raw 16-bit Signed Linear (96000 Hz) PCM

AST_FORMAT_SLINEAR192 

Raw 16-bit Signed Linear (192000 Hz) PCM. maybe we're taking this too far.

AST_FORMAT_SPEEX32 
AST_FORMAT_CELT 
AST_FORMAT_H261 

H.261 Video

AST_FORMAT_H263 

H.263 Video

AST_FORMAT_H263_PLUS 

H.263+ Video

AST_FORMAT_H264 

H.264 Video

AST_FORMAT_MP4_VIDEO 

MPEG4 Video

AST_FORMAT_JPEG 

JPEG Images

AST_FORMAT_PNG 

PNG Images

AST_FORMAT_T140RED 

T.140 RED Text format RFC 4103

AST_FORMAT_T140 

T.140 Text format - ITU T.140, RFC 4103

Definition at line 47 of file format.h.

                   {
   /*! G.723.1 compression */
   AST_FORMAT_G723_1           = 1 + AST_FORMAT_TYPE_AUDIO,
   /*! GSM compression */
   AST_FORMAT_GSM              = 2 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw mu-law data (G.711) */
   AST_FORMAT_ULAW             = 3 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw A-law data (G.711) */
   AST_FORMAT_ALAW             = 4 + AST_FORMAT_TYPE_AUDIO,
   /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
   AST_FORMAT_G726_AAL2        = 5 + AST_FORMAT_TYPE_AUDIO,
   /*! ADPCM (IMA) */
   AST_FORMAT_ADPCM            = 6 + AST_FORMAT_TYPE_AUDIO,
   /*! LPC10, 180 samples/frame */
   AST_FORMAT_LPC10            = 7 + AST_FORMAT_TYPE_AUDIO,
   /*! G.729A audio */
   AST_FORMAT_G729A            = 8 + AST_FORMAT_TYPE_AUDIO,
   /*! SpeeX Free Compression */
   AST_FORMAT_SPEEX            = 9 + AST_FORMAT_TYPE_AUDIO,
   /*! iLBC Free Compression */
   AST_FORMAT_ILBC             = 10 + AST_FORMAT_TYPE_AUDIO,
   /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
   AST_FORMAT_G726             = 11 + AST_FORMAT_TYPE_AUDIO,
   /*! G.722 */
   AST_FORMAT_G722             = 12 + AST_FORMAT_TYPE_AUDIO,
   /*! G.722.1 (also known as Siren7, 32kbps assumed) */
   AST_FORMAT_SIREN7           = 13 + AST_FORMAT_TYPE_AUDIO,
   /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
   AST_FORMAT_SIREN14          = 14 + AST_FORMAT_TYPE_AUDIO,
   /*! G.719 (64 kbps assumed) */
   AST_FORMAT_G719             = 15 + AST_FORMAT_TYPE_AUDIO,
   /*! SpeeX Wideband (16kHz) Free Compression */
   AST_FORMAT_SPEEX16          = 16 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw mu-law data (G.711) */
   AST_FORMAT_TESTLAW          = 17 + AST_FORMAT_TYPE_AUDIO,
   /*! SILK format */
   AST_FORMAT_SILK             = 18 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
   AST_FORMAT_SLINEAR          = 19 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (12000 Hz) PCM */
   AST_FORMAT_SLINEAR12        = 20 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
   AST_FORMAT_SLINEAR16        = 21 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (24000 Hz) PCM */
   AST_FORMAT_SLINEAR24        = 22 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (32000 Hz) PCM */
   AST_FORMAT_SLINEAR32        = 23 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (44100 Hz) PCM just because we can. */
   AST_FORMAT_SLINEAR44        = 24 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (48000 Hz) PCM */
   AST_FORMAT_SLINEAR48        = 25 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (96000 Hz) PCM */
   AST_FORMAT_SLINEAR96        = 26 + AST_FORMAT_TYPE_AUDIO,
   /*! Raw 16-bit Signed Linear (192000 Hz) PCM.  maybe we're taking this too far. */
   AST_FORMAT_SLINEAR192       = 27 + AST_FORMAT_TYPE_AUDIO,
   AST_FORMAT_SPEEX32          = 28 + AST_FORMAT_TYPE_AUDIO,
   AST_FORMAT_CELT             = 29 + AST_FORMAT_TYPE_AUDIO,

   /*! H.261 Video */
   AST_FORMAT_H261             = 1 + AST_FORMAT_TYPE_VIDEO,
   /*! H.263 Video */
   AST_FORMAT_H263             = 2 + AST_FORMAT_TYPE_VIDEO,
   /*! H.263+ Video */
   AST_FORMAT_H263_PLUS        = 3 + AST_FORMAT_TYPE_VIDEO,
   /*! H.264 Video */
   AST_FORMAT_H264             = 4 + AST_FORMAT_TYPE_VIDEO,
   /*! MPEG4 Video */
   AST_FORMAT_MP4_VIDEO        = 5 + AST_FORMAT_TYPE_VIDEO,

   /*! JPEG Images */
   AST_FORMAT_JPEG             = 1 + AST_FORMAT_TYPE_IMAGE,
   /*! PNG Images */
   AST_FORMAT_PNG              = 2 + AST_FORMAT_TYPE_IMAGE,

   /*! T.140 RED Text format RFC 4103 */
   AST_FORMAT_T140RED          = 1 + AST_FORMAT_TYPE_TEXT,
   /*! T.140 Text format - ITU T.140, RFC 4103 */
   AST_FORMAT_T140             = 2 + AST_FORMAT_TYPE_TEXT,
};
Enumerator:
AST_FORMAT_TYPE_AUDIO 
AST_FORMAT_TYPE_VIDEO 
AST_FORMAT_TYPE_IMAGE 
AST_FORMAT_TYPE_TEXT 

Definition at line 40 of file format.h.


Function Documentation

const char* ast_codec2str ( struct ast_format format)

Get a name from a format.

Parameters:
formatto get name of
Returns:
This returns a static string identifying the format on success, 0 on error.

Definition at line 713 of file format.c.

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_list_destroy(), ast_format_list_get(), and ast_format_list::desc.

Referenced by moh_alloc().

{
   int x;
   const char *ret = "unknown";
   size_t f_len;
   const struct ast_format_list *f_list = ast_format_list_get(&f_len);

   for (x = 0; x < f_len; x++) {
      if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
         ret = f_list[x].desc;
         break;
      }
   }
   f_list = ast_format_list_destroy(f_list);
   return ret;
}
struct ast_format* ast_format_append ( struct ast_format format,
  ... 
) [read]

After ast_format_set has been used on a function, this function can be used to set additional format attributes to the structure.

Parameters:
formatto set
varlist of attribute key value pairs, must end with AST_FORMAT_ATTR_END;

Example usage. ast_format_set(format, AST_FORMAT_SILK, 0); ast_format_append(format, // SILK has capability attributes. AST_FORMAT_SILK_ATTR_RATE, 24000, AST_FORMAT_SILK_ATTR_RATE, 16000, AST_FORMAT_SILK_ATTR_RATE, 12000, AST_FORMAT_SILK_ATTR_RATE, 8000, AST_FORMAT_ATTR_END);

Returns:
Pointer to ast_format object, same pointer that is passed in by the first argument.

Definition at line 194 of file format.c.

References format, and format_set_helper().

Referenced by custom_celt_format(), and custom_silk_format().

{
   va_list ap;
   va_start(ap, format);
   format_set_helper(format, ap);
   va_end(ap);

   return format;
}
int ast_format_attr_reg_interface ( const struct ast_format_attr_interface interface)

register ast_format_attr_interface with core.

Return values:
0success
-1failure

Definition at line 1347 of file format.c.

References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_alloc_options, ao2_find, ao2_link_flags, ao2_ref, ao2_unlock, ao2_wrlock, ast_format_list_destroy(), ast_format_list_get(), ast_log(), ast_rtp_engine_load_format(), format, interface_ao2_wrapper::id, ast_format_attr_interface::id, interface_ao2_wrapper::interface, load_format_config(), LOG_WARNING, OBJ_NOLOCK, and OBJ_POINTER.

Referenced by load_module().

{
   int x;
   size_t f_len;
   const struct ast_format_list *f_list;
   struct interface_ao2_wrapper *wrapper;
   struct interface_ao2_wrapper tmp_wrapper = {
      .id = interface->id,
   };

   /*
    * Grab the write lock before checking for duplicates in
    * anticipation of adding a new interface and to prevent a
    * duplicate from sneaking in between the check and add.
    */
   ao2_wrlock(interfaces);

   /* check for duplicates first*/
   if ((wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
      ao2_unlock(interfaces);
      ast_log(LOG_WARNING, "Can not register attribute interface for format id %d, interface already exists.\n", interface->id);
      ao2_ref(wrapper, -1);
      return -1;
   }

   wrapper = ao2_alloc_options(sizeof(*wrapper), NULL, AO2_ALLOC_OPT_LOCK_RWLOCK);
   if (!wrapper) {
      ao2_unlock(interfaces);
      return -1;
   }

   wrapper->interface = interface;
   wrapper->id = interface->id;

   /* The write lock is already held. */
   ao2_link_flags(interfaces, wrapper, OBJ_NOLOCK);
   ao2_unlock(interfaces);

   ao2_ref(wrapper, -1);

   /* This will find all custom formats in codecs.conf for this new registered interface */
   load_format_config();

   /* update the RTP engine to all custom formats created for this interface */
   f_list = ast_format_list_get(&f_len);
   for (x = 0; x < f_len; x++) {
      if (f_list[x].format.id == tmp_wrapper.id) {
         ast_rtp_engine_load_format(&f_list[x].format);
      }
   }
   f_list = ast_format_list_destroy(f_list);
   return 0;
}

unregister format_attr interface with core.

Return values:
0success
-1failure

Definition at line 1401 of file format.c.

References ao2_find, ao2_ref, ao2_unlock, ao2_wrlock, ast_format_list_destroy(), ast_format_list_get(), ast_rtp_engine_unload_format(), format, interface_ao2_wrapper::id, ast_format_attr_interface::id, interface_ao2_wrapper::interface, load_format_config(), OBJ_POINTER, and OBJ_UNLINK.

Referenced by load_module(), and unload_module().

{
   int x;
   size_t f_len;
   const struct ast_format_list *f_list;
   struct interface_ao2_wrapper *wrapper;
   struct interface_ao2_wrapper tmp_wrapper = {
      .id = interface->id,
   };

   if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_UNLINK)))) {
      return -1;
   }

   ao2_wrlock(wrapper);
   wrapper->interface = NULL;
   ao2_unlock(wrapper);

   ao2_ref(wrapper, -1);

   /* update the RTP engine to remove all custom formats created for this interface */
   f_list = ast_format_list_get(&f_len);
   for (x = 0; x < f_len; x++) {
      if (f_list[x].format.id == tmp_wrapper.id) {
         ast_rtp_engine_unload_format(&f_list[x].format);
      }
   }

   /* This will remove all custom formats previously created for this interface */
   load_format_config();
   f_list = ast_format_list_destroy(f_list);
   return 0;
}
void ast_format_copy ( struct ast_format dst,
const struct ast_format src 
)

copy format src into format dst.

Definition at line 86 of file format.c.

Referenced by __ast_play_and_record(), __ast_smoother_feed(), __get_from_jb(), __oh323_new(), add_static_payload(), adsi_transmit_message_full(), agent_new(), ast_async_goto(), ast_channel_start_silence_generator(), ast_codec_pref_append(), ast_codec_pref_convert(), ast_codec_pref_index(), ast_codec_pref_prepend(), ast_codec_pref_remove(), ast_do_masquerade(), ast_format_cap_add(), ast_format_cap_get_compatible_format(), ast_format_cap_iter_next(), ast_frdup(), ast_frisolate(), ast_getformatbyname(), ast_getformatname_multiple(), ast_iax2_new(), ast_openstream_full(), ast_prod(), ast_rtp_codecs_payloads_default(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_read(), ast_rtp_write(), ast_slinfactory_feed(), ast_slinfactory_init_with_format(), ast_smoother_read(), ast_speech_new(), ast_trans_frameout(), ast_translator_best_choice(), ast_writestream(), audiohook_list_translate_to_native(), audiohook_list_translate_to_slin(), audiohook_read_frame_helper(), background_detect_exec(), bridge_channel_join(), bridge_make_compatible(), bridge_request(), builtin_atxfer(), chanspy_exec(), check_goto_on_transfer(), create_jb(), dahdi_decoder_frameout(), dahdi_encoder_frameout(), dahdi_new(), dahdi_read(), dahdiscan_exec(), dictate_exec(), do_bridge_masquerade(), do_waiting(), eagi_exec(), extenspy_exec(), fax_detect_framehook(), fax_gateway_framehook(), find_best_byid_cb(), format_list_add_static(), free_translation(), generic_fax_exec(), gtalk_new(), handle_recordfile(), handle_show_translation_path(), handle_speechrecognize(), hook_event_cb(), iax2_request(), iax_frame_wrap(), iax_park(), ices_exec(), isAnsweringMachine(), jb_get_and_deliver(), jingle_new(), linear_alloc(), local_new(), masq_park_call(), measurenoise(), mgcp_new(), misdn_new(), moh_alloc(), moh_files_alloc(), moh_files_generator(), moh_files_write_format_change(), moh_release(), mohalloc(), mp3_exec(), multicast_rtp_request(), nbs_new(), NBScat_exec(), newpvt(), pcm_read(), phone_new(), phone_read(), phone_setup(), phone_write(), playtones_alloc(), rec_request(), record_exec(), register_translator(), send_waveform_to_channel(), set_format(), set_next_mime_type(), sip_new(), sip_park(), skinny_new(), softmix_process_write_audio(), softmix_translate_helper_entry_alloc(), speech_background(), start_rtp(), tonepair_alloc(), transmit_audio(), and unistim_new().

{
   *dst = *src;
}
struct ast_format* ast_format_from_old_bitfield ( struct ast_format dst,
uint64_t  src 
) [read]

convert old bitfield format to ast_format represenatation

Note:
This is only to be used for IAX2 compatibility
Return values:
onsuccess, pointer to the dst format in the input parameters
onfailure, NULL

G.723.1 compression

GSM compression

Raw mu-law data (G.711)

Raw A-law data (G.711)

ADPCM (G.726, 32kbps, AAL2 codeword packing)

ADPCM (IMA)

Raw 16-bit Signed Linear (8000 Hz) PCM

LPC10, 180 samples/frame

G.729A audio

SpeeX Free Compression

iLBC Free Compression

ADPCM (G.726, 32kbps, RFC3551 codeword packing)

G.722

G.722.1 (also known as Siren7, 32kbps assumed)

G.722.1 Annex C (also known as Siren14, 48kbps assumed)

Raw 16-bit Signed Linear (16000 Hz) PCM

G.719 (64 kbps assumed)

SpeeX Wideband (16kHz) Free Compression

Raw mu-law data (G.711)

H.261 Video

H.263 Video

H.263+ Video

H.264 Video

MPEG4 Video

JPEG Images

PNG Images

T.140 RED Text format RFC 4103

T.140 Text format - ITU T.140, RFC 4103

Definition at line 478 of file format.c.

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, ast_format_clear(), AST_FORMAT_G719, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_H261, AST_FORMAT_H263, AST_FORMAT_H263_PLUS, AST_FORMAT_H264, AST_FORMAT_ILBC, AST_FORMAT_JPEG, AST_FORMAT_LPC10, AST_FORMAT_MP4_VIDEO, AST_FORMAT_PNG, ast_format_set(), AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR16, AST_FORMAT_SPEEX, AST_FORMAT_SPEEX16, AST_FORMAT_T140, AST_FORMAT_T140RED, AST_FORMAT_TESTLAW, and AST_FORMAT_ULAW.

Referenced by __get_from_jb(), ast_format_cap_from_old_bitfield(), ast_format_id_from_old_bitfield(), conf_run(), decode_frame(), iax2_getformatname(), register_translator(), socket_process_helper(), and socket_process_meta().

{
   switch (src) {
   /*! G.723.1 compression */
   case (1ULL << 0):
      return ast_format_set(dst, AST_FORMAT_G723_1, 0);
   /*! GSM compression */
   case (1ULL << 1):
      return ast_format_set(dst, AST_FORMAT_GSM, 0);
   /*! Raw mu-law data (G.711) */
   case (1ULL << 2):
      return ast_format_set(dst, AST_FORMAT_ULAW, 0);
   /*! Raw A-law data (G.711) */
   case (1ULL << 3):
      return ast_format_set(dst, AST_FORMAT_ALAW, 0);
   /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
   case (1ULL << 4):
      return ast_format_set(dst, AST_FORMAT_G726_AAL2, 0);
   /*! ADPCM (IMA) */
   case (1ULL << 5):
      return ast_format_set(dst, AST_FORMAT_ADPCM, 0);
   /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
   case (1ULL << 6):
      return ast_format_set(dst, AST_FORMAT_SLINEAR, 0);
   /*! LPC10, 180 samples/frame */
   case (1ULL << 7):
      return ast_format_set(dst, AST_FORMAT_LPC10, 0);
   /*! G.729A audio */
   case (1ULL << 8):
      return ast_format_set(dst, AST_FORMAT_G729A, 0);
   /*! SpeeX Free Compression */
   case (1ULL << 9):
      return ast_format_set(dst, AST_FORMAT_SPEEX, 0);
   /*! iLBC Free Compression */
   case (1ULL << 10):
      return ast_format_set(dst, AST_FORMAT_ILBC, 0);
   /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
   case (1ULL << 11):
      return ast_format_set(dst, AST_FORMAT_G726, 0);
   /*! G.722 */
   case (1ULL << 12):
      return ast_format_set(dst, AST_FORMAT_G722, 0);
   /*! G.722.1 (also known as Siren7, 32kbps assumed) */
   case (1ULL << 13):
      return ast_format_set(dst, AST_FORMAT_SIREN7, 0);
   /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
   case (1ULL << 14):
      return ast_format_set(dst, AST_FORMAT_SIREN14, 0);
   /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
   case (1ULL << 15):
      return ast_format_set(dst, AST_FORMAT_SLINEAR16, 0);
   /*! G.719 (64 kbps assumed) */
   case (1ULL << 32):
      return ast_format_set(dst, AST_FORMAT_G719, 0);
   /*! SpeeX Wideband (16kHz) Free Compression */
   case (1ULL << 33):
      return ast_format_set(dst, AST_FORMAT_SPEEX16, 0);
   /*! Raw mu-law data (G.711) */
   case (1ULL << 47):
      return ast_format_set(dst, AST_FORMAT_TESTLAW, 0);

   /*! H.261 Video */
   case (1ULL << 18):
      return ast_format_set(dst, AST_FORMAT_H261, 0);
   /*! H.263 Video */
   case (1ULL << 19):
      return ast_format_set(dst, AST_FORMAT_H263, 0);
   /*! H.263+ Video */
   case (1ULL << 20):
      return ast_format_set(dst, AST_FORMAT_H263_PLUS, 0);
   /*! H.264 Video */
   case (1ULL << 21):
      return ast_format_set(dst, AST_FORMAT_H264, 0);
   /*! MPEG4 Video */
   case (1ULL << 22):
      return ast_format_set(dst, AST_FORMAT_MP4_VIDEO, 0);

   /*! JPEG Images */
   case (1ULL << 16):
      return ast_format_set(dst, AST_FORMAT_JPEG, 0);
   /*! PNG Images */
   case (1ULL << 17):
      return ast_format_set(dst, AST_FORMAT_PNG, 0);

   /*! T.140 RED Text format RFC 4103 */
   case (1ULL << 26):
      return ast_format_set(dst, AST_FORMAT_T140RED, 0);
   /*! T.140 Text format - ITU T.140, RFC 4103 */
   case (1ULL << 27):
      return ast_format_set(dst, AST_FORMAT_T140, 0);
   }
   ast_format_clear(dst);
   return NULL;
}
int ast_format_get_value ( const struct ast_format format,
int  key,
void *  value 
)

Get a value from a format containing attributes.

Note:
The key represents the format attribute to be retrieved, and the void pointer is to the structure that value will be stored in. It must be known what structure a key represents.
Return values:
0,success
-1,failure

Definition at line 281 of file format.c.

References ao2_rdlock, ao2_ref, ao2_unlock, ast_format::fattr, find_interface(), ast_format_attr_interface::format_attr_get_val, and interface_ao2_wrapper::interface.

Referenced by ast_format_rate().

{
   int res = 0;
   struct interface_ao2_wrapper *wrapper;

   if (!(wrapper = find_interface(format))) {
      return -1;
   }
   ao2_rdlock(wrapper);
   if (!wrapper->interface ||
      !wrapper->interface->format_attr_get_val) {

      ao2_unlock(wrapper);
      ao2_ref(wrapper, -1);
      return -1;
   }

   res = wrapper->interface->format_attr_get_val(&format->fattr, key, value);

   ao2_unlock(wrapper);
   ao2_ref(wrapper, -1);

   return res;
}
int ast_format_get_video_mark ( const struct ast_format format)

Determine of the marker bit is set or not on this format.

Return values:
1,true
0,false

Definition at line 96 of file format.c.

References ast_format::fattr, and ast_format_attr::rtp_marker_bit.

Referenced by ast_rtp_raw_write(), h263_write(), h264_write(), iax2_send(), and softmix_bridge_write().

{
   return format->fattr.rtp_marker_bit;
}

convert old bitfield format to ast_format_id value

Definition at line 573 of file format.c.

References ast_format_from_old_bitfield(), and ast_format::id.

Referenced by dahdi_destroy(), dahdi_translate(), drop_translator(), iax2_send(), and socket_process_helper().

{
   struct ast_format dst;
   if (ast_format_from_old_bitfield(&dst, src)) {
      return dst.id;
   }
   return 0;
}

ast_format_id to old bitfield format represenatation

G.723.1 compression

GSM compression

Raw mu-law data (G.711)

Raw A-law data (G.711)

ADPCM (G.726, 32kbps, AAL2 codeword packing)

ADPCM (IMA)

Raw 16-bit Signed Linear (8000 Hz) PCM

LPC10, 180 samples/frame

G.729A audio

SpeeX Free Compression

iLBC Free Compression

ADPCM (G.726, 32kbps, RFC3551 codeword packing)

G.722

G.722.1 (also known as Siren7, 32kbps assumed)

G.722.1 Annex C (also known as Siren14, 48kbps assumed)

Raw 16-bit Signed Linear (16000 Hz) PCM

G.719 (64 kbps assumed)

SpeeX Wideband (16kHz) Free Compression

Raw mu-law data (G.711)

H.261 Video

H.263 Video

H.263+ Video

H.264 Video

MPEG4 Video

JPEG Images

PNG Images

T.140 RED Text format RFC 4103

T.140 Text format - ITU T.140, RFC 4103

Definition at line 376 of file format.c.

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_G719, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_H261, AST_FORMAT_H263, AST_FORMAT_H263_PLUS, AST_FORMAT_H264, AST_FORMAT_ILBC, AST_FORMAT_JPEG, AST_FORMAT_LPC10, AST_FORMAT_MP4_VIDEO, AST_FORMAT_PNG, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR16, AST_FORMAT_SPEEX, AST_FORMAT_SPEEX16, AST_FORMAT_T140, AST_FORMAT_T140RED, AST_FORMAT_TESTLAW, and AST_FORMAT_ULAW.

Referenced by ast_format_to_old_bitfield(), and dahdi_translate().

{
   switch (id) {
   /*! G.723.1 compression */
   case AST_FORMAT_G723_1:
      return (1ULL << 0);
   /*! GSM compression */
   case AST_FORMAT_GSM:
      return (1ULL << 1);
   /*! Raw mu-law data (G.711) */
   case AST_FORMAT_ULAW:
      return (1ULL << 2);
   /*! Raw A-law data (G.711) */
   case AST_FORMAT_ALAW:
      return (1ULL << 3);
   /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
   case AST_FORMAT_G726_AAL2:
      return (1ULL << 4);
   /*! ADPCM (IMA) */
   case AST_FORMAT_ADPCM:
      return (1ULL << 5);
   /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
   case AST_FORMAT_SLINEAR:
      return (1ULL << 6);
   /*! LPC10, 180 samples/frame */
   case AST_FORMAT_LPC10:
      return (1ULL << 7);
   /*! G.729A audio */
   case AST_FORMAT_G729A:
      return (1ULL << 8);
   /*! SpeeX Free Compression */
   case AST_FORMAT_SPEEX:
      return (1ULL << 9);
   /*! iLBC Free Compression */
   case AST_FORMAT_ILBC:
      return (1ULL << 10);
   /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
   case AST_FORMAT_G726:
      return (1ULL << 11);
   /*! G.722 */
   case AST_FORMAT_G722:
      return (1ULL << 12);
   /*! G.722.1 (also known as Siren7, 32kbps assumed) */
   case AST_FORMAT_SIREN7:
      return (1ULL << 13);
   /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
   case AST_FORMAT_SIREN14:
      return (1ULL << 14);
   /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
   case AST_FORMAT_SLINEAR16:
      return (1ULL << 15);
   /*! G.719 (64 kbps assumed) */
   case AST_FORMAT_G719:
      return (1ULL << 32);
   /*! SpeeX Wideband (16kHz) Free Compression */
   case AST_FORMAT_SPEEX16:
      return (1ULL << 33);
   /*! Raw mu-law data (G.711) */
   case AST_FORMAT_TESTLAW:
      return (1ULL << 47);

   /*! H.261 Video */
   case AST_FORMAT_H261:
      return (1ULL << 18);
   /*! H.263 Video */
   case AST_FORMAT_H263:
      return (1ULL << 19);
   /*! H.263+ Video */
   case AST_FORMAT_H263_PLUS:
      return (1ULL << 20);
   /*! H.264 Video */
   case AST_FORMAT_H264:
      return (1ULL << 21);
   /*! MPEG4 Video */
   case AST_FORMAT_MP4_VIDEO:
      return (1ULL << 22);

   /*! JPEG Images */
   case AST_FORMAT_JPEG:
      return (1ULL << 16);
   /*! PNG Images */
   case AST_FORMAT_PNG:
      return (1ULL << 17);

   /*! T.140 RED Text format RFC 4103 */
   case AST_FORMAT_T140RED:
      return (1ULL << 26);
   /*! T.140 Text format - ITU T.140, RFC 4103 */
   case AST_FORMAT_T140:
      return (1ULL << 27);
   default:
      return 0; /* not supported by old bitfield. */
   }

   return 0;

}
int ast_format_isset ( const struct ast_format format,
  ... 
)

This function is used to set an ast_format object to represent a media format with optional capability attributes represented by format specific key value pairs.

Example usage. Is this SILK format capable of 8khz is_8khz = ast_format_isset(format, AST_FORMAT_SILK_CAP_RATE, 8000);

Returns:
0, The format key value pairs are within the capabilities defined in this structure.
-1, The format key value pairs are _NOT_ within the capabilities of this structure.

Definition at line 270 of file format.c.

References format_isset_helper().

Referenced by ast_codec_get_samples(), and ast_format_rate().

{
   va_list ap;
   int res;

   va_start(ap, format);
   res = format_isset_helper(format, ap);
   va_end(ap);
   return res;
}
int ast_format_joint ( const struct ast_format format1,
const struct ast_format format2,
struct ast_format result 
)

Find joint format attributes of two ast_format structures containing the same uid and return the intersection in the result structure.

retval 0, joint attribute capabilities exist. retval -1, no joint attribute capabilities exist.

Definition at line 366 of file format.c.

References format_joint_helper(), and ast_format::id.

Referenced by find_joint_cb().

{
   if (format1->id != format2->id) {
      return -1;
   }
   result->id = format1->id;
   return format_joint_helper(format1, format2, result);
}
int ast_format_rate ( const struct ast_format format)

Get the sample rate for a given format.

Definition at line 730 of file format.c.

References AST_FORMAT_ATTR_END, AST_FORMAT_CELT, AST_FORMAT_G719, AST_FORMAT_G722, ast_format_get_value(), ast_format_isset(), AST_FORMAT_SILK, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SLINEAR12, AST_FORMAT_SLINEAR16, AST_FORMAT_SLINEAR192, AST_FORMAT_SLINEAR24, AST_FORMAT_SLINEAR32, AST_FORMAT_SLINEAR44, AST_FORMAT_SLINEAR48, AST_FORMAT_SLINEAR96, AST_FORMAT_SPEEX16, AST_FORMAT_SPEEX32, CELT_ATTR_KEY_SAMP_RATE, ast_format::id, SILK_ATTR_KEY_SAMP_RATE, SILK_ATTR_VAL_SAMP_12KHZ, SILK_ATTR_VAL_SAMP_16KHZ, and SILK_ATTR_VAL_SAMP_24KHZ.

Referenced by __ast_read(), __get_from_jb(), ast_channel_make_compatible_helper(), ast_codec_get_samples(), ast_read_generator_actions(), ast_readaudio_callback(), ast_readvideo_callback(), ast_rtp_engine_load_format(), ast_rtp_read(), ast_smoother_read(), ast_translate(), ast_translator_best_choice(), ast_write(), audiohook_list_translate_to_slin(), audiohook_read_frame_helper(), calc_timestamp(), find_best_byid_cb(), gather_softmix_stats(), generate_computational_cost(), generate_table_cost(), generator_force(), handle_show_translation_path(), hook_event_cb(), load_module(), mixmonitor_save_prep(), msg_create_from_file(), pitch_shift(), resamp_new(), rtp_get_rate(), schedule_delivery(), set_softmix_bridge_data(), speex_callback(), and waitstream_core().

{
   switch (format->id) {
   case AST_FORMAT_SLINEAR12:
      return 12000;
   case AST_FORMAT_SLINEAR24:
      return 24000;
   case AST_FORMAT_SLINEAR32:
      return 32000;
   case AST_FORMAT_SLINEAR44:
      return 44100;
   case AST_FORMAT_SLINEAR48:
      return 48000;
   case AST_FORMAT_SLINEAR96:
      return 96000;
   case AST_FORMAT_SLINEAR192:
      return 192000;
   case AST_FORMAT_G722:
   case AST_FORMAT_SLINEAR16:
   case AST_FORMAT_SIREN7:
   case AST_FORMAT_SPEEX16:
      return 16000;
   case AST_FORMAT_SIREN14:
   case AST_FORMAT_SPEEX32:
      return 32000;
   case AST_FORMAT_G719:
      return 48000;
   case AST_FORMAT_SILK:
      if (!(ast_format_isset(format,
         SILK_ATTR_KEY_SAMP_RATE,
         SILK_ATTR_VAL_SAMP_24KHZ,
         AST_FORMAT_ATTR_END))) {
         return 24000;
      } else if (!(ast_format_isset(format,
         SILK_ATTR_KEY_SAMP_RATE,
         SILK_ATTR_VAL_SAMP_16KHZ,
         AST_FORMAT_ATTR_END))) {
         return 16000;
      } else if (!(ast_format_isset(format,
         SILK_ATTR_KEY_SAMP_RATE,
         SILK_ATTR_VAL_SAMP_12KHZ,
         AST_FORMAT_ATTR_END))) {
         return 12000;
      } else {
         return 8000;
      }
   case AST_FORMAT_CELT:
   {
      int samplerate;
      if (!(ast_format_get_value(format,
         CELT_ATTR_KEY_SAMP_RATE,
         &samplerate))) {
         return samplerate;
      }
   }
   default:
      return 8000;
   }
}
void ast_format_sdp_generate ( const struct ast_format format,
unsigned int  payload,
struct ast_str **  str 
)

This function is used to produce an fmtp SDP line for an Asterisk format. The attributes present on the Asterisk format are translated into the SDP equivalent.

Parameters:
formatto generate an fmtp line for
payloadnumerical payload for the fmtp line
strstructure that the fmtp line will be appended to

Definition at line 146 of file format.c.

References ao2_rdlock, ao2_ref, ao2_unlock, ast_format::fattr, find_interface(), ast_format_attr_interface::format_attr_sdp_generate, and interface_ao2_wrapper::interface.

Referenced by add_codec_to_sdp(), and add_vcodec_to_sdp().

{
   struct interface_ao2_wrapper *wrapper;

   if (!(wrapper = find_interface(format))) {
      return;
   }

   ao2_rdlock(wrapper);
   if (!wrapper->interface || !wrapper->interface->format_attr_sdp_generate) {
      ao2_unlock(wrapper);
      ao2_ref(wrapper, -1);
      return;
   }

   wrapper->interface->format_attr_sdp_generate(&format->fattr, payload, str);

   ao2_unlock(wrapper);
   ao2_ref(wrapper, -1);
}
int ast_format_sdp_parse ( struct ast_format format,
const char *  attributes 
)

This function is used to have a media format aware module parse and interpret SDP attribute information. Once interpreted this information is stored on the format itself using Asterisk format attributes.

Parameters:
formatto set
attributesstring containing the fmtp line from the SDP
Return values:
0success, attribute values were valid
-1failure, values were not acceptable

Definition at line 122 of file format.c.

References ao2_rdlock, ao2_ref, ao2_unlock, ast_format::fattr, find_interface(), ast_format_attr_interface::format_attr_sdp_parse, and interface_ao2_wrapper::interface.

Referenced by process_sdp_a_audio(), and process_sdp_a_video().

{
   struct interface_ao2_wrapper *wrapper;
   int res;

   if (!(wrapper = find_interface(format))) {
      return 0;
   }

   ao2_rdlock(wrapper);
   if (!wrapper->interface || !wrapper->interface->format_attr_sdp_parse) {
      ao2_unlock(wrapper);
      ao2_ref(wrapper, -1);
      return 0;
   }

   res = wrapper->interface->format_attr_sdp_parse(&format->fattr, attributes);

   ao2_unlock(wrapper);
   ao2_ref(wrapper, -1);

   return res;
}
struct ast_format* ast_format_set ( struct ast_format format,
enum ast_format_id  id,
int  set_attributes,
  ... 
) [read]

This function is used to set an ast_format object to represent a media format with optional format attributes represented by format specific key value pairs.

Parameters:
formatto set
id,formatid to set on format
set_attributes,arethere attributes to set on this format. 0 == false, 1 == True.
varlist of attribute key value pairs, must end with AST_FORMAT_ATTR_END;

Example usage. ast_format_set(format, AST_FORMAT_ULAW, 0); // no capability attributes are needed for ULAW

ast_format_set(format, AST_FORMAT_SILK, 1, // SILK has capability attributes. AST_FORMAT_SILK_ATTR_RATE, 24000, AST_FORMAT_SILK_ATTR_RATE, 16000, AST_FORMAT_SILK_ATTR_RATE, 12000, AST_FORMAT_SILK_ATTR_RATE, 8000, AST_FORMAT_ATTR_END);

Note:
This function will initialize the ast_format structure.
Returns:
Pointer to ast_format object, same pointer that is passed in by the first argument.

Definition at line 204 of file format.c.

References ast_format_clear(), format, format_set_helper(), ast_format::id, and id.

Referenced by __adsi_transmit_messages(), _moh_class_malloc(), action_originate(), add_tcodec_to_sdp(), adpcm_sample(), adsi_careful_send(), agent_new(), alaw_sample(), alloc_playback_chan(), alsa_new(), alsa_read(), alsa_request(), analog_ss_thread(), ast_channel_make_compatible_helper(), ast_format_from_old_bitfield(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_engine_init(), ast_rtp_read(), ast_sendtext(), ast_set_read_format_by_id(), ast_set_write_format_by_id(), ast_slinfactory_init(), ast_speech_new(), ast_translate_available_formats(), ast_translator_build_path(), audiohook_list_translate_to_slin(), audiohook_read_frame_both(), audiohook_read_frame_helper(), audiohook_read_frame_single(), audiohook_set_internal_rate(), bridge_request(), build_conf(), cb_events(), codec_skinny2ast(), conf_run(), conf_start_record(), console_new(), custom_celt_format(), custom_silk_format(), dahdi_callwait(), dahdi_new(), dahdi_sendtext(), do_notify(), fax_gateway_framehook(), fax_generator_generate(), format_list_init(), g719read(), g722_sample(), g723_read(), g726_read(), g726_sample(), g729_read(), generic_fax_exec(), generic_read(), generic_recall(), gsm_read(), gsm_sample(), h263_read(), h264_read(), handle_jack_audio(), handle_speechcreate(), ilbc_read(), ilbc_sample(), jpeg_read_image(), linear_generator(), load_module(), load_moh_classes(), local_ast_moh_start(), lpc10_sample(), matrix_rebuild(), milliwatt_generate(), misdn_read(), mixmonitor_thread(), mp3_exec(), mwi_send_init(), mwi_thread(), my_callwait(), my_get_callerid(), my_send_callerid(), NBScat_exec(), new_outgoing(), ogg_vorbis_read(), orig_app(), orig_exten(), originate_exec(), oss_new(), oss_read(), oss_request(), parkandannounce_exec(), phone_new(), phone_setup(), phone_write(), playtones_generator(), process_sdp(), rec_request(), rtp_red_init(), send_cwcidspill(), send_tone_burst(), send_waveform_to_channel(), set_softmix_bridge_data(), silence_generator_generate(), sip_set_default_format_capabilities(), siren14read(), siren7read(), slin16_sample(), slin8_sample(), sms_generate(), softmix_bridge_thread(), softmix_translate_helper_change_rate(), softmix_translate_helper_init(), spandsp_fax_gw_t30_gen(), spandsp_fax_read(), speex16_sample(), speex_sample(), spy_generate(), stream_monitor(), tonepair_generator(), ulaw_sample(), vox_read(), and wav_read().

{
   /* initialize the structure before setting it. */
   ast_format_clear(format);

   format->id = id;

   if (set_attributes) {
      va_list ap;
      va_start(ap, set_attributes);
      format_set_helper(format, ap);
      va_end(ap);
   }

   return format;
}
void ast_format_set_video_mark ( struct ast_format format)

Set the rtp mark value on the format to indicate to the interface writing this format's payload that a new RTP marker is necessary.

Definition at line 91 of file format.c.

References ast_format::fattr, and ast_format_attr::rtp_marker_bit.

Referenced by ast_rtp_read(), h263_read(), h264_read(), and socket_process_helper().

{
   format->fattr.rtp_marker_bit = 1;
}
enum ast_format_id ast_format_slin_by_rate ( unsigned int  rate)

Get the best slinear format id for a given sample rate.

Definition at line 598 of file format.c.

References AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR12, AST_FORMAT_SLINEAR16, AST_FORMAT_SLINEAR192, AST_FORMAT_SLINEAR24, AST_FORMAT_SLINEAR32, AST_FORMAT_SLINEAR44, AST_FORMAT_SLINEAR48, and AST_FORMAT_SLINEAR96.

Referenced by ast_channel_make_compatible_helper(), audiohook_list_translate_to_slin(), audiohook_read_frame_both(), audiohook_read_frame_helper(), audiohook_read_frame_single(), audiohook_set_internal_rate(), mixmonitor_thread(), set_softmix_bridge_data(), softmix_bridge_thread(), softmix_translate_helper_change_rate(), and softmix_translate_helper_init().

{
   if (rate >= 192000) {
      return AST_FORMAT_SLINEAR192;
   } else if (rate >= 96000) {
      return AST_FORMAT_SLINEAR96;
   } else if (rate >= 48000) {
      return AST_FORMAT_SLINEAR48;
   } else if (rate >= 44100) {
      return AST_FORMAT_SLINEAR44;
   } else if (rate >= 32000) {
      return AST_FORMAT_SLINEAR32;
   } else if (rate >= 24000) {
      return AST_FORMAT_SLINEAR24;
   } else if (rate >= 16000) {
      return AST_FORMAT_SLINEAR16;
   } else if (rate >= 12000) {
      return AST_FORMAT_SLINEAR12;
   }
   return AST_FORMAT_SLINEAR;
}
uint64_t ast_format_to_old_bitfield ( const struct ast_format format)

ast_format to old bitfield format represenatation

Note:
This is only to be used for IAX2 compatibility
Return values:
iax2representation of ast_format
0,ifno representation existis for iax2

Definition at line 473 of file format.c.

References ast_format_id_to_old_bitfield(), and ast_format::id.

Referenced by ast_format_cap_to_old_bitfield(), conf_run(), dahdi_translate(), iax2_best_codec(), iax2_codec_choose(), iax2_send(), iax_template_parse(), oh323_rtp_read(), setup_rtp_connection(), and socket_process_helper().

{
   return ast_format_id_to_old_bitfield(format->id);
}
struct ast_format* ast_getformatbyname ( const char *  name,
struct ast_format format 
) [read]

Gets a format from a name.

Parameters:
namestring of format
formatstructure to return the format in.
Returns:
This returns the format pointer given to it on success and NULL on failure

Definition at line 693 of file format.c.

References ast_expand_codec_alias(), ast_format_copy(), ast_format_list_destroy(), ast_format_list_get(), and format.

Referenced by ast_parse_allow_disallow(), iax_template_parse(), load_moh_classes(), local_ast_moh_start(), msg_create_from_file(), reload_config(), and try_suggested_sip_codec().

{
   int x;
   size_t f_len;
   const struct ast_format_list *f_list = ast_format_list_get(&f_len);

   for (x = 0; x < f_len; x++) {
      if (!strcasecmp(f_list[x].name, name) ||
          !strcasecmp(f_list[x].name, ast_expand_codec_alias(name))) {

         ast_format_copy(result, &f_list[x].format);
         f_list = ast_format_list_destroy(f_list);
         return result;
      }
   }
   f_list = ast_format_list_destroy(f_list);

   return NULL;
}
const char* ast_getformatname ( const struct ast_format format)

Get the name of a format.

Parameters:
formatid of format
Returns:
A static string containing the name of the format or "unknown" if unknown.

Definition at line 620 of file format.c.

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_list_destroy(), ast_format_list_get(), and ast_format_list::name.

Referenced by __ast_play_and_record(), __ast_read(), __ast_register_translator(), __ast_smoother_feed(), _sip_show_peer(), _skinny_show_line(), add_codec_to_answer(), add_codec_to_sdp(), add_sdp(), add_static_payload(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), adsi_transmit_message_full(), agent_call(), ast_channel_make_compatible_helper(), ast_codec_get_len(), ast_codec_get_samples(), ast_codec_pref_getsize(), ast_codec_pref_string(), ast_do_masquerade(), ast_dsp_process(), ast_frame_subclass2str(), ast_openvstream(), ast_rtp_write(), ast_slinfactory_feed(), ast_stopstream(), ast_streamfile(), ast_translator_build_path(), ast_unregister_translator(), ast_write(), ast_writestream(), background_detect_exec(), bridge_channel_join(), bridge_make_compatible(), conf_run(), create_addr(), dahdi_read(), dahdi_translate(), dahdi_write(), do_waiting(), eagi_exec(), func_channel_read(), function_iaxpeer(), function_sippeer(), g719write(), g726_write(), g729_write(), generic_write(), gsm_write(), gtalk_rtp_read(), gtalk_show_channels(), gtalk_write(), h263_write(), h264_write(), handle_capabilities_res_message(), handle_cli_core_show_file_formats(), handle_cli_iax2_show_peer(), handle_cli_moh_show_classes(), handle_core_show_image_formats(), handle_open_receive_channel_ack_message(), handle_show_translation_table(), handle_showchan(), iax2_getformatname(), ilbc_write(), isAnsweringMachine(), jack_hook_callback(), jingle_read(), jingle_rtp_read(), jingle_show_channels(), jingle_write(), login_exec(), matrix_rebuild(), mgcp_rtp_read(), mgcp_write(), misdn_write(), moh_files_release(), moh_release(), nbs_xwrite(), ogg_vorbis_write(), oh323_rtp_read(), oh323_write(), pcm_write(), phone_setup(), phone_write(), print_codec_to_cli(), print_frame(), process_sdp_a_audio(), register_translator(), send_start_rtp(), serialize_showchan(), set_format(), set_local_capabilities(), set_peer_capabilities(), setup_rtp_connection(), sip_new(), sip_rtp_read(), sip_write(), siren14write(), siren7write(), skinny_new(), skinny_rtp_read(), skinny_set_rtp_peer(), skinny_write(), socket_process_helper(), start_rtp(), unistim_new(), unistim_rtp_read(), unistim_write(), vox_write(), and wav_write().

{
   int x;
   const char *ret = "unknown";
   size_t f_len;
   const struct ast_format_list *f_list = ast_format_list_get(&f_len);
   for (x = 0; x < f_len; x++) {
      if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
         ret = f_list[x].name;
         break;
      }
   }
   f_list = ast_format_list_destroy(f_list);
   return ret;
}
char* ast_getformatname_multiple_byid ( char *  buf,
size_t  size,
enum ast_format_id  id 
)

Returns a string containing all formats pertaining to an format id.

Parameters:
bufa buffer for the output string
sizesize of buf (bytes)
formatid.
Returns:
The return value is buf.

Definition at line 637 of file format.c.

References ast_copy_string(), ast_format_list_destroy(), ast_format_list_get(), format, len(), and name.

Referenced by ast_translate_path_to_str(), and handle_show_translation_path().

{
   int x;
   unsigned len;
   char *start, *end = buf;
   size_t f_len;
   const struct ast_format_list *f_list = ast_format_list_get(&f_len);

   if (!size) {
      f_list = ast_format_list_destroy(f_list);
      return buf;
   }
   snprintf(end, size, "(");
   len = strlen(end);
   end += len;
   size -= len;
   start = end;
   for (x = 0; x < f_len; x++) {
      if (f_list[x].format.id == id) {
         snprintf(end, size, "%s|", f_list[x].name);
         len = strlen(end);
         end += len;
         size -= len;
      }
   }
   if (start == end) {
      ast_copy_string(start, "nothing)", size);
   } else if (size > 1) {
      *(end - 1) = ')';
   }
   f_list = ast_format_list_destroy(f_list);
   return buf;
}