Thu Oct 11 06:35:58 2012

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_GET_TYPE ( id   )     (((int) (id / AST_FORMAT_INC)) * AST_FORMAT_INC)

#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.

00148                         {
00149    /*! structure 1 is identical to structure 2. */
00150    AST_FORMAT_CMP_EQUAL = 0,
00151    /*! structure 1 contains elements not in structure 2. */
00152    AST_FORMAT_CMP_NOT_EQUAL,
00153    /*! structure 1 is a proper subset of the elements in structure 2.*/
00154    AST_FORMAT_CMP_SUBSET,
00155 };

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.

00047                    {
00048    /*! G.723.1 compression */
00049    AST_FORMAT_G723_1           = 1 + AST_FORMAT_TYPE_AUDIO,
00050    /*! GSM compression */
00051    AST_FORMAT_GSM              = 2 + AST_FORMAT_TYPE_AUDIO,
00052    /*! Raw mu-law data (G.711) */
00053    AST_FORMAT_ULAW             = 3 + AST_FORMAT_TYPE_AUDIO,
00054    /*! Raw A-law data (G.711) */
00055    AST_FORMAT_ALAW             = 4 + AST_FORMAT_TYPE_AUDIO,
00056    /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
00057    AST_FORMAT_G726_AAL2        = 5 + AST_FORMAT_TYPE_AUDIO,
00058    /*! ADPCM (IMA) */
00059    AST_FORMAT_ADPCM            = 6 + AST_FORMAT_TYPE_AUDIO,
00060    /*! LPC10, 180 samples/frame */
00061    AST_FORMAT_LPC10            = 7 + AST_FORMAT_TYPE_AUDIO,
00062    /*! G.729A audio */
00063    AST_FORMAT_G729A            = 8 + AST_FORMAT_TYPE_AUDIO,
00064    /*! SpeeX Free Compression */
00065    AST_FORMAT_SPEEX            = 9 + AST_FORMAT_TYPE_AUDIO,
00066    /*! iLBC Free Compression */
00067    AST_FORMAT_ILBC             = 10 + AST_FORMAT_TYPE_AUDIO,
00068    /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
00069    AST_FORMAT_G726             = 11 + AST_FORMAT_TYPE_AUDIO,
00070    /*! G.722 */
00071    AST_FORMAT_G722             = 12 + AST_FORMAT_TYPE_AUDIO,
00072    /*! G.722.1 (also known as Siren7, 32kbps assumed) */
00073    AST_FORMAT_SIREN7           = 13 + AST_FORMAT_TYPE_AUDIO,
00074    /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
00075    AST_FORMAT_SIREN14          = 14 + AST_FORMAT_TYPE_AUDIO,
00076    /*! G.719 (64 kbps assumed) */
00077    AST_FORMAT_G719             = 15 + AST_FORMAT_TYPE_AUDIO,
00078    /*! SpeeX Wideband (16kHz) Free Compression */
00079    AST_FORMAT_SPEEX16          = 16 + AST_FORMAT_TYPE_AUDIO,
00080    /*! Raw mu-law data (G.711) */
00081    AST_FORMAT_TESTLAW          = 17 + AST_FORMAT_TYPE_AUDIO,
00082    /*! SILK format */
00083    AST_FORMAT_SILK             = 18 + AST_FORMAT_TYPE_AUDIO,
00084    /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
00085    AST_FORMAT_SLINEAR          = 19 + AST_FORMAT_TYPE_AUDIO,
00086    /*! Raw 16-bit Signed Linear (12000 Hz) PCM */
00087    AST_FORMAT_SLINEAR12        = 20 + AST_FORMAT_TYPE_AUDIO,
00088    /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
00089    AST_FORMAT_SLINEAR16        = 21 + AST_FORMAT_TYPE_AUDIO,
00090    /*! Raw 16-bit Signed Linear (24000 Hz) PCM */
00091    AST_FORMAT_SLINEAR24        = 22 + AST_FORMAT_TYPE_AUDIO,
00092    /*! Raw 16-bit Signed Linear (32000 Hz) PCM */
00093    AST_FORMAT_SLINEAR32        = 23 + AST_FORMAT_TYPE_AUDIO,
00094    /*! Raw 16-bit Signed Linear (44100 Hz) PCM just because we can. */
00095    AST_FORMAT_SLINEAR44        = 24 + AST_FORMAT_TYPE_AUDIO,
00096    /*! Raw 16-bit Signed Linear (48000 Hz) PCM */
00097    AST_FORMAT_SLINEAR48        = 25 + AST_FORMAT_TYPE_AUDIO,
00098    /*! Raw 16-bit Signed Linear (96000 Hz) PCM */
00099    AST_FORMAT_SLINEAR96        = 26 + AST_FORMAT_TYPE_AUDIO,
00100    /*! Raw 16-bit Signed Linear (192000 Hz) PCM.  maybe we're taking this too far. */
00101    AST_FORMAT_SLINEAR192       = 27 + AST_FORMAT_TYPE_AUDIO,
00102    AST_FORMAT_SPEEX32          = 28 + AST_FORMAT_TYPE_AUDIO,
00103    AST_FORMAT_CELT             = 29 + AST_FORMAT_TYPE_AUDIO,
00104 
00105    /*! H.261 Video */
00106    AST_FORMAT_H261             = 1 + AST_FORMAT_TYPE_VIDEO,
00107    /*! H.263 Video */
00108    AST_FORMAT_H263             = 2 + AST_FORMAT_TYPE_VIDEO,
00109    /*! H.263+ Video */
00110    AST_FORMAT_H263_PLUS        = 3 + AST_FORMAT_TYPE_VIDEO,
00111    /*! H.264 Video */
00112    AST_FORMAT_H264             = 4 + AST_FORMAT_TYPE_VIDEO,
00113    /*! MPEG4 Video */
00114    AST_FORMAT_MP4_VIDEO        = 5 + AST_FORMAT_TYPE_VIDEO,
00115 
00116    /*! JPEG Images */
00117    AST_FORMAT_JPEG             = 1 + AST_FORMAT_TYPE_IMAGE,
00118    /*! PNG Images */
00119    AST_FORMAT_PNG              = 2 + AST_FORMAT_TYPE_IMAGE,
00120 
00121    /*! T.140 RED Text format RFC 4103 */
00122    AST_FORMAT_T140RED          = 1 + AST_FORMAT_TYPE_TEXT,
00123    /*! T.140 Text format - ITU T.140, RFC 4103 */
00124    AST_FORMAT_T140             = 2 + AST_FORMAT_TYPE_TEXT,
00125 };

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:
format to 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().

00714 {
00715    int x;
00716    const char *ret = "unknown";
00717    size_t f_len;
00718    const struct ast_format_list *f_list = ast_format_list_get(&f_len);
00719 
00720    for (x = 0; x < f_len; x++) {
00721       if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
00722          ret = f_list[x].desc;
00723          break;
00724       }
00725    }
00726    f_list = ast_format_list_destroy(f_list);
00727    return ret;
00728 }

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:
format to set
... var list 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_set_helper().

Referenced by custom_celt_format(), and custom_silk_format().

00195 {
00196    va_list ap;
00197    va_start(ap, format);
00198    format_set_helper(format, ap);
00199    va_end(ap);
00200 
00201    return format;
00202 }

int ast_format_attr_reg_interface ( const struct ast_format_attr_interface interface  ) 

register ast_format_attr_interface with core.

Return values:
0 success
-1 failure

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, ast_format_attr_interface::id, interface_ao2_wrapper::id, interface_ao2_wrapper::interface, load_format_config(), LOG_WARNING, OBJ_NOLOCK, and OBJ_POINTER.

Referenced by load_module().

01348 {
01349    int x;
01350    size_t f_len;
01351    const struct ast_format_list *f_list;
01352    struct interface_ao2_wrapper *wrapper;
01353    struct interface_ao2_wrapper tmp_wrapper = {
01354       .id = interface->id,
01355    };
01356 
01357    /*
01358     * Grab the write lock before checking for duplicates in
01359     * anticipation of adding a new interface and to prevent a
01360     * duplicate from sneaking in between the check and add.
01361     */
01362    ao2_wrlock(interfaces);
01363 
01364    /* check for duplicates first*/
01365    if ((wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
01366       ao2_unlock(interfaces);
01367       ast_log(LOG_WARNING, "Can not register attribute interface for format id %d, interface already exists.\n", interface->id);
01368       ao2_ref(wrapper, -1);
01369       return -1;
01370    }
01371 
01372    wrapper = ao2_alloc_options(sizeof(*wrapper), NULL, AO2_ALLOC_OPT_LOCK_RWLOCK);
01373    if (!wrapper) {
01374       ao2_unlock(interfaces);
01375       return -1;
01376    }
01377 
01378    wrapper->interface = interface;
01379    wrapper->id = interface->id;
01380 
01381    /* The write lock is already held. */
01382    ao2_link_flags(interfaces, wrapper, OBJ_NOLOCK);
01383    ao2_unlock(interfaces);
01384 
01385    ao2_ref(wrapper, -1);
01386 
01387    /* This will find all custom formats in codecs.conf for this new registered interface */
01388    load_format_config();
01389 
01390    /* update the RTP engine to all custom formats created for this interface */
01391    f_list = ast_format_list_get(&f_len);
01392    for (x = 0; x < f_len; x++) {
01393       if (f_list[x].format.id == tmp_wrapper.id) {
01394          ast_rtp_engine_load_format(&f_list[x].format);
01395       }
01396    }
01397    f_list = ast_format_list_destroy(f_list);
01398    return 0;
01399 }

int ast_format_attr_unreg_interface ( const struct ast_format_attr_interface interface  ) 

unregister format_attr interface with core.

Return values:
0 success
-1 failure

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, ast_format_attr_interface::id, interface_ao2_wrapper::id, interface_ao2_wrapper::interface, load_format_config(), OBJ_POINTER, and OBJ_UNLINK.

Referenced by load_module(), and unload_module().

01402 {
01403    int x;
01404    size_t f_len;
01405    const struct ast_format_list *f_list;
01406    struct interface_ao2_wrapper *wrapper;
01407    struct interface_ao2_wrapper tmp_wrapper = {
01408       .id = interface->id,
01409    };
01410 
01411    if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_UNLINK)))) {
01412       return -1;
01413    }
01414 
01415    ao2_wrlock(wrapper);
01416    wrapper->interface = NULL;
01417    ao2_unlock(wrapper);
01418 
01419    ao2_ref(wrapper, -1);
01420 
01421    /* update the RTP engine to remove all custom formats created for this interface */
01422    f_list = ast_format_list_get(&f_len);
01423    for (x = 0; x < f_len; x++) {
01424       if (f_list[x].format.id == tmp_wrapper.id) {
01425          ast_rtp_engine_unload_format(&f_list[x].format);
01426       }
01427    }
01428 
01429    /* This will remove all custom formats previously created for this interface */
01430    load_format_config();
01431    f_list = ast_format_list_destroy(f_list);
01432    return 0;
01433 }

void ast_format_clear ( struct ast_format format  ) 

enum ast_format_cmp_res ast_format_cmp ( const struct ast_format format1,
const struct ast_format format2 
)

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().

00087 {
00088    *dst = *src;
00089 }

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:
on success, pointer to the dst format in the input parameters
on failure, 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().

00479 {
00480    switch (src) {
00481    /*! G.723.1 compression */
00482    case (1ULL << 0):
00483       return ast_format_set(dst, AST_FORMAT_G723_1, 0);
00484    /*! GSM compression */
00485    case (1ULL << 1):
00486       return ast_format_set(dst, AST_FORMAT_GSM, 0);
00487    /*! Raw mu-law data (G.711) */
00488    case (1ULL << 2):
00489       return ast_format_set(dst, AST_FORMAT_ULAW, 0);
00490    /*! Raw A-law data (G.711) */
00491    case (1ULL << 3):
00492       return ast_format_set(dst, AST_FORMAT_ALAW, 0);
00493    /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
00494    case (1ULL << 4):
00495       return ast_format_set(dst, AST_FORMAT_G726_AAL2, 0);
00496    /*! ADPCM (IMA) */
00497    case (1ULL << 5):
00498       return ast_format_set(dst, AST_FORMAT_ADPCM, 0);
00499    /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
00500    case (1ULL << 6):
00501       return ast_format_set(dst, AST_FORMAT_SLINEAR, 0);
00502    /*! LPC10, 180 samples/frame */
00503    case (1ULL << 7):
00504       return ast_format_set(dst, AST_FORMAT_LPC10, 0);
00505    /*! G.729A audio */
00506    case (1ULL << 8):
00507       return ast_format_set(dst, AST_FORMAT_G729A, 0);
00508    /*! SpeeX Free Compression */
00509    case (1ULL << 9):
00510       return ast_format_set(dst, AST_FORMAT_SPEEX, 0);
00511    /*! iLBC Free Compression */
00512    case (1ULL << 10):
00513       return ast_format_set(dst, AST_FORMAT_ILBC, 0);
00514    /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
00515    case (1ULL << 11):
00516       return ast_format_set(dst, AST_FORMAT_G726, 0);
00517    /*! G.722 */
00518    case (1ULL << 12):
00519       return ast_format_set(dst, AST_FORMAT_G722, 0);
00520    /*! G.722.1 (also known as Siren7, 32kbps assumed) */
00521    case (1ULL << 13):
00522       return ast_format_set(dst, AST_FORMAT_SIREN7, 0);
00523    /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
00524    case (1ULL << 14):
00525       return ast_format_set(dst, AST_FORMAT_SIREN14, 0);
00526    /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
00527    case (1ULL << 15):
00528       return ast_format_set(dst, AST_FORMAT_SLINEAR16, 0);
00529    /*! G.719 (64 kbps assumed) */
00530    case (1ULL << 32):
00531       return ast_format_set(dst, AST_FORMAT_G719, 0);
00532    /*! SpeeX Wideband (16kHz) Free Compression */
00533    case (1ULL << 33):
00534       return ast_format_set(dst, AST_FORMAT_SPEEX16, 0);
00535    /*! Raw mu-law data (G.711) */
00536    case (1ULL << 47):
00537       return ast_format_set(dst, AST_FORMAT_TESTLAW, 0);
00538 
00539    /*! H.261 Video */
00540    case (1ULL << 18):
00541       return ast_format_set(dst, AST_FORMAT_H261, 0);
00542    /*! H.263 Video */
00543    case (1ULL << 19):
00544       return ast_format_set(dst, AST_FORMAT_H263, 0);
00545    /*! H.263+ Video */
00546    case (1ULL << 20):
00547       return ast_format_set(dst, AST_FORMAT_H263_PLUS, 0);
00548    /*! H.264 Video */
00549    case (1ULL << 21):
00550       return ast_format_set(dst, AST_FORMAT_H264, 0);
00551    /*! MPEG4 Video */
00552    case (1ULL << 22):
00553       return ast_format_set(dst, AST_FORMAT_MP4_VIDEO, 0);
00554 
00555    /*! JPEG Images */
00556    case (1ULL << 16):
00557       return ast_format_set(dst, AST_FORMAT_JPEG, 0);
00558    /*! PNG Images */
00559    case (1ULL << 17):
00560       return ast_format_set(dst, AST_FORMAT_PNG, 0);
00561 
00562    /*! T.140 RED Text format RFC 4103 */
00563    case (1ULL << 26):
00564       return ast_format_set(dst, AST_FORMAT_T140RED, 0);
00565    /*! T.140 Text format - ITU T.140, RFC 4103 */
00566    case (1ULL << 27):
00567       return ast_format_set(dst, AST_FORMAT_T140, 0);
00568    }
00569    ast_format_clear(dst);
00570    return NULL;
00571 }

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().

00282 {
00283    int res = 0;
00284    struct interface_ao2_wrapper *wrapper;
00285 
00286    if (!(wrapper = find_interface(format))) {
00287       return -1;
00288    }
00289    ao2_rdlock(wrapper);
00290    if (!wrapper->interface ||
00291       !wrapper->interface->format_attr_get_val) {
00292 
00293       ao2_unlock(wrapper);
00294       ao2_ref(wrapper, -1);
00295       return -1;
00296    }
00297 
00298    res = wrapper->interface->format_attr_get_val(&format->fattr, key, value);
00299 
00300    ao2_unlock(wrapper);
00301    ao2_ref(wrapper, -1);
00302 
00303    return res;
00304 }

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().

00097 {
00098    return format->fattr.rtp_marker_bit;
00099 }

enum ast_format_id ast_format_id_from_old_bitfield ( uint64_t  src  ) 

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_translate(), drop_translator(), iax2_send(), and socket_process_helper().

00574 {
00575    struct ast_format dst;
00576    if (ast_format_from_old_bitfield(&dst, src)) {
00577       return dst.id;
00578    }
00579    return 0;
00580 }

uint64_t ast_format_id_to_old_bitfield ( enum ast_format_id  id  ) 

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().

00377 {
00378    switch (id) {
00379    /*! G.723.1 compression */
00380    case AST_FORMAT_G723_1:
00381       return (1ULL << 0);
00382    /*! GSM compression */
00383    case AST_FORMAT_GSM:
00384       return (1ULL << 1);
00385    /*! Raw mu-law data (G.711) */
00386    case AST_FORMAT_ULAW:
00387       return (1ULL << 2);
00388    /*! Raw A-law data (G.711) */
00389    case AST_FORMAT_ALAW:
00390       return (1ULL << 3);
00391    /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
00392    case AST_FORMAT_G726_AAL2:
00393       return (1ULL << 4);
00394    /*! ADPCM (IMA) */
00395    case AST_FORMAT_ADPCM:
00396       return (1ULL << 5);
00397    /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
00398    case AST_FORMAT_SLINEAR:
00399       return (1ULL << 6);
00400    /*! LPC10, 180 samples/frame */
00401    case AST_FORMAT_LPC10:
00402       return (1ULL << 7);
00403    /*! G.729A audio */
00404    case AST_FORMAT_G729A:
00405       return (1ULL << 8);
00406    /*! SpeeX Free Compression */
00407    case AST_FORMAT_SPEEX:
00408       return (1ULL << 9);
00409    /*! iLBC Free Compression */
00410    case AST_FORMAT_ILBC:
00411       return (1ULL << 10);
00412    /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
00413    case AST_FORMAT_G726:
00414       return (1ULL << 11);
00415    /*! G.722 */
00416    case AST_FORMAT_G722:
00417       return (1ULL << 12);
00418    /*! G.722.1 (also known as Siren7, 32kbps assumed) */
00419    case AST_FORMAT_SIREN7:
00420       return (1ULL << 13);
00421    /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
00422    case AST_FORMAT_SIREN14:
00423       return (1ULL << 14);
00424    /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
00425    case AST_FORMAT_SLINEAR16:
00426       return (1ULL << 15);
00427    /*! G.719 (64 kbps assumed) */
00428    case AST_FORMAT_G719:
00429       return (1ULL << 32);
00430    /*! SpeeX Wideband (16kHz) Free Compression */
00431    case AST_FORMAT_SPEEX16:
00432       return (1ULL << 33);
00433    /*! Raw mu-law data (G.711) */
00434    case AST_FORMAT_TESTLAW:
00435       return (1ULL << 47);
00436 
00437    /*! H.261 Video */
00438    case AST_FORMAT_H261:
00439       return (1ULL << 18);
00440    /*! H.263 Video */
00441    case AST_FORMAT_H263:
00442       return (1ULL << 19);
00443    /*! H.263+ Video */
00444    case AST_FORMAT_H263_PLUS:
00445       return (1ULL << 20);
00446    /*! H.264 Video */
00447    case AST_FORMAT_H264:
00448       return (1ULL << 21);
00449    /*! MPEG4 Video */
00450    case AST_FORMAT_MP4_VIDEO:
00451       return (1ULL << 22);
00452 
00453    /*! JPEG Images */
00454    case AST_FORMAT_JPEG:
00455       return (1ULL << 16);
00456    /*! PNG Images */
00457    case AST_FORMAT_PNG:
00458       return (1ULL << 17);
00459 
00460    /*! T.140 RED Text format RFC 4103 */
00461    case AST_FORMAT_T140RED:
00462       return (1ULL << 26);
00463    /*! T.140 Text format - ITU T.140, RFC 4103 */
00464    case AST_FORMAT_T140:
00465       return (1ULL << 27);
00466    default:
00467       return 0; /* not supported by old bitfield. */
00468    }
00469 
00470    return 0;
00471 
00472 }

int ast_format_is_slinear ( const struct ast_format format  ) 

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().

00271 {
00272    va_list ap;
00273    int res;
00274 
00275    va_start(ap, format);
00276    res = format_isset_helper(format, ap);
00277    va_end(ap);
00278    return res;
00279 }

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().

00367 {
00368    if (format1->id != format2->id) {
00369       return -1;
00370    }
00371    result->id = format1->id;
00372    return format_joint_helper(format1, format2, result);
00373 }

struct ast_format_list* ast_format_list_destroy ( const struct ast_format_list list  )  [read]

struct ast_format_list* ast_format_list_get ( size_t *  size  )  [read]

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().

00731 {
00732    switch (format->id) {
00733    case AST_FORMAT_SLINEAR12:
00734       return 12000;
00735    case AST_FORMAT_SLINEAR24:
00736       return 24000;
00737    case AST_FORMAT_SLINEAR32:
00738       return 32000;
00739    case AST_FORMAT_SLINEAR44:
00740       return 44100;
00741    case AST_FORMAT_SLINEAR48:
00742       return 48000;
00743    case AST_FORMAT_SLINEAR96:
00744       return 96000;
00745    case AST_FORMAT_SLINEAR192:
00746       return 192000;
00747    case AST_FORMAT_G722:
00748    case AST_FORMAT_SLINEAR16:
00749    case AST_FORMAT_SIREN7:
00750    case AST_FORMAT_SPEEX16:
00751       return 16000;
00752    case AST_FORMAT_SIREN14:
00753    case AST_FORMAT_SPEEX32:
00754       return 32000;
00755    case AST_FORMAT_G719:
00756       return 48000;
00757    case AST_FORMAT_SILK:
00758       if (!(ast_format_isset(format,
00759          SILK_ATTR_KEY_SAMP_RATE,
00760          SILK_ATTR_VAL_SAMP_24KHZ,
00761          AST_FORMAT_ATTR_END))) {
00762          return 24000;
00763       } else if (!(ast_format_isset(format,
00764          SILK_ATTR_KEY_SAMP_RATE,
00765          SILK_ATTR_VAL_SAMP_16KHZ,
00766          AST_FORMAT_ATTR_END))) {
00767          return 16000;
00768       } else if (!(ast_format_isset(format,
00769          SILK_ATTR_KEY_SAMP_RATE,
00770          SILK_ATTR_VAL_SAMP_12KHZ,
00771          AST_FORMAT_ATTR_END))) {
00772          return 12000;
00773       } else {
00774          return 8000;
00775       }
00776    case AST_FORMAT_CELT:
00777    {
00778       int samplerate;
00779       if (!(ast_format_get_value(format,
00780          CELT_ATTR_KEY_SAMP_RATE,
00781          &samplerate))) {
00782          return samplerate;
00783       }
00784    }
00785    default:
00786       return 8000;
00787    }
00788 }

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:
format to generate an fmtp line for
payload numerical payload for the fmtp line
str structure 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().

00147 {
00148    struct interface_ao2_wrapper *wrapper;
00149 
00150    if (!(wrapper = find_interface(format))) {
00151       return;
00152    }
00153 
00154    ao2_rdlock(wrapper);
00155    if (!(wrapper->interface || !wrapper->interface->format_attr_sdp_generate)) {
00156       ao2_unlock(wrapper);
00157       ao2_ref(wrapper, -1);
00158       return;
00159    }
00160 
00161    wrapper->interface->format_attr_sdp_generate(&format->fattr, payload, str);
00162 
00163    ao2_unlock(wrapper);
00164    ao2_ref(wrapper, -1);
00165 }

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:
format to set
attributes string containing the fmtp line from the SDP
Return values:
0 success, attribute values were valid
-1 failure, 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().

00123 {
00124    struct interface_ao2_wrapper *wrapper;
00125    int res;
00126 
00127    if (!(wrapper = find_interface(format))) {
00128       return 0;
00129    }
00130 
00131    ao2_rdlock(wrapper);
00132    if (!(wrapper->interface || !wrapper->interface->format_attr_sdp_parse)) {
00133       ao2_unlock(wrapper);
00134       ao2_ref(wrapper, -1);
00135       return 0;
00136    }
00137 
00138    res = wrapper->interface->format_attr_sdp_parse(&format->fattr, attributes);
00139 
00140    ao2_unlock(wrapper);
00141    ao2_ref(wrapper, -1);
00142 
00143    return res;
00144 }

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:
format to set
id format id to set on format
set_attributes are there attributes to set on this format. 0 == false, 1 == True.
... var list 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_set_helper(), and ast_format::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_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().

00205 {
00206    /* initialize the structure before setting it. */
00207    ast_format_clear(format);
00208 
00209    format->id = id;
00210 
00211    if (set_attributes) {
00212       va_list ap;
00213       va_start(ap, set_attributes);
00214       format_set_helper(format, ap);
00215       va_end(ap);
00216    }
00217 
00218    return format;
00219 }

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().

00092 {
00093    format->fattr.rtp_marker_bit = 1;
00094 }

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().

00599 {
00600    if (rate >= 192000) {
00601       return AST_FORMAT_SLINEAR192;
00602    } else if (rate >= 96000) {
00603       return AST_FORMAT_SLINEAR96;
00604    } else if (rate >= 48000) {
00605       return AST_FORMAT_SLINEAR48;
00606    } else if (rate >= 44100) {
00607       return AST_FORMAT_SLINEAR44;
00608    } else if (rate >= 32000) {
00609       return AST_FORMAT_SLINEAR32;
00610    } else if (rate >= 24000) {
00611       return AST_FORMAT_SLINEAR24;
00612    } else if (rate >= 16000) {
00613       return AST_FORMAT_SLINEAR16;
00614    } else if (rate >= 12000) {
00615       return AST_FORMAT_SLINEAR12;
00616    }
00617    return AST_FORMAT_SLINEAR;
00618 }

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:
iax2 representation of ast_format
0,if no 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().

00474 {
00475    return ast_format_id_to_old_bitfield(format->id);
00476 }

struct ast_format* ast_getformatbyname ( const char *  name,
struct ast_format format 
) [read]

Gets a format from a name.

Parameters:
name string of format
format structure 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().

00694 {
00695    int x;
00696    size_t f_len;
00697    const struct ast_format_list *f_list = ast_format_list_get(&f_len);
00698 
00699    for (x = 0; x < f_len; x++) {
00700       if (!strcasecmp(f_list[x].name, name) ||
00701           !strcasecmp(f_list[x].name, ast_expand_codec_alias(name))) {
00702 
00703          ast_format_copy(result, &f_list[x].format);
00704          f_list = ast_format_list_destroy(f_list);
00705          return result;
00706       }
00707    }
00708    f_list = ast_format_list_destroy(f_list);
00709 
00710    return NULL;
00711 }

const char* ast_getformatname ( const struct ast_format format  ) 

Get the name of a format.

Parameters:
format id 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().

00621 {
00622    int x;
00623    const char *ret = "unknown";
00624    size_t f_len;
00625    const struct ast_format_list *f_list = ast_format_list_get(&f_len);
00626    for (x = 0; x < f_len; x++) {
00627       if (ast_format_cmp(&f_list[x].format, format) == AST_FORMAT_CMP_EQUAL) {
00628          ret = f_list[x].name;
00629          break;
00630       }
00631    }
00632    f_list = ast_format_list_destroy(f_list);
00633    return ret;
00634 }

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:
buf a buffer for the output string
size size of buf (bytes)
id format id.
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().

00638 {
00639    int x;
00640    unsigned len;
00641    char *start, *end = buf;
00642    size_t f_len;
00643    const struct ast_format_list *f_list = ast_format_list_get(&f_len);
00644 
00645    if (!size) {
00646       f_list = ast_format_list_destroy(f_list);
00647       return buf;
00648    }
00649    snprintf(end, size, "(");
00650    len = strlen(end);
00651    end += len;
00652    size -= len;
00653    start = end;
00654    for (x = 0; x < f_len; x++) {
00655       if (f_list[x].format.id == id) {
00656          snprintf(end, size, "%s|", f_list[x].name);
00657          len = strlen(end);
00658          end += len;
00659          size -= len;
00660       }
00661    }
00662    if (start == end) {
00663       ast_copy_string(start, "nothing)", size);
00664    } else if (size > 1) {
00665       *(end - 1) = ')';
00666    }
00667    f_list = ast_format_list_destroy(f_list);
00668    return buf;
00669 }


Generated on Thu Oct 11 06:35:58 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6