From 4b2fc9d3e738dbb2e7dd297de2f35e571e350691 Mon Sep 17 00:00:00 2001 From: tilghman Date: Tue, 6 Nov 2007 22:51:48 +0000 Subject: [PATCH] Commit some cleanups to the format type code. - Remove the AST_FORMAT_MAX_* types, as these are consuming 3 out of our available 32 bits. - Add a native slin16 type, so that 16kHz codecs can translate without losing resolution. (This doesn't affect anything immediately, until another codec has wb support.) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@89071 f38db490-d61c-443f-a65b-d21fe96a405b --- channels/chan_gtalk.c | 2 +- channels/chan_h323.c | 4 +- channels/chan_jingle.c | 7 +--- channels/chan_mgcp.c | 6 +-- channels/chan_phone.c | 2 +- channels/chan_sip.c | 10 ++--- channels/chan_skinny.c | 4 +- codecs/codec_g722.c | 76 +++++++++++++++++++++++++++++++++++- include/asterisk/frame.h | 12 ++---- include/asterisk/translate.h | 2 +- main/file.c | 12 +++--- main/frame.c | 64 +++++++++++++++--------------- main/rtp.c | 10 ++--- main/translate.c | 4 +- 14 files changed, 141 insertions(+), 74 deletions(-) diff --git a/channels/chan_gtalk.c b/channels/chan_gtalk.c index 5666af95c..6f106bde9 100644 --- a/channels/chan_gtalk.c +++ b/channels/chan_gtalk.c @@ -198,7 +198,7 @@ static int gtalk_get_codec(struct ast_channel *chan); static const struct ast_channel_tech gtalk_tech = { .type = "Gtalk", .description = "Gtalk Channel Driver", - .capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1), + .capabilities = AST_FORMAT_AUDIO_MASK, .requester = gtalk_request, .send_digit_begin = gtalk_digit_begin, .send_digit_end = gtalk_digit_end, diff --git a/channels/chan_h323.c b/channels/chan_h323.c index da324cf6d..99b2086ae 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -249,7 +249,7 @@ static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) static const struct ast_channel_tech oh323_tech = { .type = "H323", .description = tdesc, - .capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1), + .capabilities = AST_FORMAT_AUDIO_MASK, .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER, .requester = oh323_request, .send_digit_begin = oh323_digit_begin, @@ -1739,7 +1739,7 @@ static struct ast_channel *oh323_request(const char *type, int format, void *dat return NULL; } oldformat = format; - format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1); + format &= AST_FORMAT_AUDIO_MASK; if (!format) { ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format); oh323_destroy(pvt); diff --git a/channels/chan_jingle.c b/channels/chan_jingle.c index e332159db..16d906c91 100644 --- a/channels/chan_jingle.c +++ b/channels/chan_jingle.c @@ -198,7 +198,7 @@ static int jingle_get_codec(struct ast_channel *chan); static const struct ast_channel_tech jingle_tech = { .type = "Jingle", .description = "Jingle Channel Driver", - .capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1), + .capabilities = AST_FORMAT_AUDIO_MASK, .requester = jingle_request, .send_digit_begin = jingle_digit_begin, .send_digit_end = jingle_digit_end, @@ -340,10 +340,7 @@ static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p) continue; if (alreadysent & pref_codec) continue; - if (pref_codec <= AST_FORMAT_MAX_AUDIO) - add_codec_to_answer(p, pref_codec, dcodecs); - else - add_codec_to_answer(p, pref_codec, dcodecs); + add_codec_to_answer(p, pref_codec, dcodecs); alreadysent |= pref_codec; } payload_red = iks_new("payload-type"); diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 9eb0fa112..b0b138a00 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -2076,7 +2076,7 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr)); ast_copy_string(t, "t=0 0\r\n", sizeof(t)); snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port)); - for (x = 1; x <= AST_FORMAT_MAX_AUDIO; x <<= 1) { + for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) { if (p->capability & x) { if (mgcpdebug) { ast_verbose("Answering with capability %d\n", x); @@ -2142,7 +2142,7 @@ static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp return 0; } ast_copy_string(local, "p:20", sizeof(local)); - for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) { + for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) { if (p->capability & x) { snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0)); strncat(local, tmp, sizeof(local) - strlen(local) - 1); @@ -2172,7 +2172,7 @@ static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp struct mgcp_endpoint *p = sub->parent; ast_copy_string(local, "p:20", sizeof(local)); - for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) { + for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) { if (p->capability & x) { snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0)); strncat(local, tmp, sizeof(local) - strlen(local) - 1); diff --git a/channels/chan_phone.c b/channels/chan_phone.c index 33f515d5e..17204fda5 100644 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -594,7 +594,7 @@ static struct ast_frame *phone_read(struct ast_channel *ast) } p->fr.samples = 240; p->fr.datalen = res; - p->fr.frametype = p->lastinput <= AST_FORMAT_MAX_AUDIO ? + p->fr.frametype = p->lastinput <= AST_FORMAT_AUDIO_MASK ? AST_FRAME_VOICE : p->lastinput <= AST_FORMAT_PNG ? AST_FRAME_IMAGE : AST_FRAME_VIDEO; diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 7b4764b6d..2e231d35d 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -155,8 +155,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define XMIT_ERROR -2 -#define VIDEO_CODEC_MASK 0x1fc0000 /*!< Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO */ - /* #define VOCAL_DATA_HACK */ #define DEFAULT_DEFAULT_EXPIRY 120 @@ -7228,20 +7226,20 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p) } /* Now send any other common audio and video codecs, and non-codec formats: */ - for (x = 1; x <= (needtext ? AST_FORMAT_MAX_TEXT : (needvideo ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO)); x <<= 1) { + for (x = 1; x <= (needtext ? AST_FORMAT_TEXT_MASK : (needvideo ? AST_FORMAT_VIDEO_MASK : AST_FORMAT_AUDIO_MASK)); x <<= 1) { if (!(capability & x)) /* Codec not requested */ continue; if (alreadysent & x) /* Already added to SDP */ continue; - if (x <= AST_FORMAT_MAX_AUDIO) + if (x & AST_FORMAT_AUDIO_MASK) add_codec_to_sdp(p, x, SDP_SAMPLE_RATE(x), &m_audio, &a_audio, debug, &min_audio_packet_size); - else if (x <= AST_FORMAT_MAX_VIDEO) + else if (x & AST_FORMAT_VIDEO_MASK) add_vcodec_to_sdp(p, x, 90000, &m_video, &a_video, debug, &min_video_packet_size); - else if (x <= AST_FORMAT_MAX_TEXT) + else if (x & AST_FORMAT_TEXT_MASK) add_tcodec_to_sdp(p, x, 1000, &m_text, &a_text, debug, &min_text_packet_size); } diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index 86d2a5b95..6808d32a4 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -1239,7 +1239,7 @@ static int handle_time_date_req_message(struct skinny_req *req, struct skinnyses static const struct ast_channel_tech skinny_tech = { .type = "Skinny", .description = tdesc, - .capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1), + .capabilities = AST_FORMAT_AUDIO_MASK, .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER, .requester = skinny_request, .devicestate = skinny_devicestate, @@ -5395,7 +5395,7 @@ static struct ast_channel *skinny_request(const char *type, int format, void *da oldformat = format; - if (!(format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1))) { + if (!(format &= AST_FORMAT_AUDIO_MASK)) { ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format); return NULL; } diff --git a/codecs/codec_g722.c b/codecs/codec_g722.c index 00e36fb33..54802dc8b 100644 --- a/codecs/codec_g722.c +++ b/codecs/codec_g722.c @@ -74,6 +74,15 @@ static int lintog722_new(struct ast_trans_pvt *pvt) return 0; } +static int lin16tog722_new(struct ast_trans_pvt *pvt) +{ + struct g722_encoder_pvt *tmp = pvt->pvt; + + g722_encode_init(&tmp->g722, 64000, 0); + + return 0; +} + /*! \brief init a new instance of g722_encoder_pvt. */ static int g722tolin_new(struct ast_trans_pvt *pvt) { @@ -84,6 +93,15 @@ static int g722tolin_new(struct ast_trans_pvt *pvt) return 0; } +static int g722tolin16_new(struct ast_trans_pvt *pvt) +{ + struct g722_decoder_pvt *tmp = pvt->pvt; + + g722_decode_init(&tmp->g722, 64000, 0); + + return 0; +} + static int g722tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { struct g722_decoder_pvt *tmp = pvt->pvt; @@ -125,6 +143,20 @@ static struct ast_frame *g722tolin_sample(void) return &f; } +static struct ast_frame *g722tolin16_sample(void) +{ + static struct ast_frame f = { + .frametype = AST_FRAME_VOICE, + .subclass = AST_FORMAT_G722, + .datalen = sizeof(slin_g722_ex), + .samples = sizeof(slin_g722_ex) / sizeof(slin_g722_ex[0]), + .src = __PRETTY_FUNCTION__, + .data = slin_g722_ex, + }; + + return &f; +} + static struct ast_frame *lintog722_sample (void) { static struct ast_frame f = { @@ -139,6 +171,20 @@ static struct ast_frame *lintog722_sample (void) return &f; } +static struct ast_frame *lin16tog722_sample (void) +{ + static struct ast_frame f = { + .frametype = AST_FRAME_VOICE, + .subclass = AST_FORMAT_SLINEAR16, + .datalen = sizeof(slin_g722_ex), + .samples = sizeof(slin_g722_ex) / sizeof(slin_g722_ex[0]), + .src = __PRETTY_FUNCTION__, + .data = slin_g722_ex, + }; + + return &f; +} + static struct ast_translator g722tolin = { .name = "g722tolin", .srcfmt = AST_FORMAT_G722, @@ -164,6 +210,31 @@ static struct ast_translator lintog722 = { .buf_size = BUFFER_SAMPLES, }; +static struct ast_translator g722tolin16 = { + .name = "g722tolin16", + .srcfmt = AST_FORMAT_G722, + .dstfmt = AST_FORMAT_SLINEAR16, + .newpvt = g722tolin16_new, /* same for both directions */ + .framein = g722tolin_framein, + .sample = g722tolin16_sample, + .desc_size = sizeof(struct g722_decoder_pvt), + .buffer_samples = BUFFER_SAMPLES, + .buf_size = BUFFER_SAMPLES, + .plc_samples = 160, +}; + +static struct ast_translator lin16tog722 = { + .name = "lin16tog722", + .srcfmt = AST_FORMAT_SLINEAR16, + .dstfmt = AST_FORMAT_G722, + .newpvt = lin16tog722_new, /* same for both directions */ + .framein = lintog722_framein, + .sample = lin16tog722_sample, + .desc_size = sizeof(struct g722_encoder_pvt), + .buffer_samples = BUFFER_SAMPLES, + .buf_size = BUFFER_SAMPLES, +}; + static int parse_config(int reload) { struct ast_variable *var; @@ -198,6 +269,8 @@ static int unload_module(void) res |= ast_unregister_translator(&g722tolin); res |= ast_unregister_translator(&lintog722); + res |= ast_unregister_translator(&g722tolin16); + res |= ast_unregister_translator(&lin16tog722); return res; } @@ -206,12 +279,13 @@ static int load_module(void) { int res = 0; - if (parse_config(0)) return AST_MODULE_LOAD_DECLINE; res |= ast_register_translator(&g722tolin); res |= ast_register_translator(&lintog722); + res |= ast_register_translator(&g722tolin16); + res |= ast_register_translator(&lin16tog722); if (res) { unload_module(); diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h index b18575aaf..e51f6e638 100644 --- a/include/asterisk/frame.h +++ b/include/asterisk/frame.h @@ -243,8 +243,8 @@ extern struct ast_frame ast_null_frame; #define AST_FORMAT_G726 (1 << 11) /*! G.722 */ #define AST_FORMAT_G722 (1 << 12) -/*! Maximum audio format */ -#define AST_FORMAT_MAX_AUDIO (1 << 15) +/*! Raw 16-bit Signed Linear (16000 Hz) PCM */ +#define AST_FORMAT_SLINEAR16 (1 << 15) /*! Maximum audio mask */ #define AST_FORMAT_AUDIO_MASK ((1 << 16)-1) /*! JPEG Images */ @@ -261,14 +261,10 @@ extern struct ast_frame ast_null_frame; #define AST_FORMAT_H264 (1 << 21) /*! MPEG4 Video */ #define AST_FORMAT_MP4_VIDEO (1 << 22) -/*! Maximum video format */ -#define AST_FORMAT_MAX_VIDEO (1 << 24) #define AST_FORMAT_VIDEO_MASK (((1 << 25)-1) & ~(AST_FORMAT_AUDIO_MASK)) /*! T.140 Text format - ITU T.140, RFC 4351*/ #define AST_FORMAT_T140 (1 << 25) -/*! Maximum text mask */ -#define AST_FORMAT_MAX_TEXT (1 << 26) -#define AST_FORMAT_TEXT_MASK (((1 << 27)-1) & ~(AST_FORMAT_AUDIO_MASK) & ~(AST_FORMAT_VIDEO_MASK)) +#define AST_FORMAT_TEXT_MASK (((1 << 30)-1) & ~(AST_FORMAT_AUDIO_MASK) & ~(AST_FORMAT_VIDEO_MASK)) enum ast_control_frame_type { AST_CONTROL_HANGUP = 1, /*!< Other end has hungup */ @@ -361,9 +357,9 @@ struct ast_option_header { /*! \brief Definition of supported media formats (codecs) */ struct ast_format_list { - int visible; /*!< Can we see this entry */ int bits; /*!< bitmask value */ char *name; /*!< short name */ + int samplespersecond; /*!< Number of samples per second (8000/16000) */ char *desc; /*!< Description */ int fr_len; /*!< Single frame length in bytes */ int min_ms; /*!< Min value */ diff --git a/include/asterisk/translate.h b/include/asterisk/translate.h index 1de3fe61d..75023f0ad 100644 --- a/include/asterisk/translate.h +++ b/include/asterisk/translate.h @@ -44,7 +44,7 @@ struct ast_trans_pvt; /* declared below */ * related to run-time operation (size of buffers, auxiliary * descriptors, etc). * - * A coded registers itself by filling the relevant fields + * A codec registers itself by filling the relevant fields * of a structure and passing it as an argument to * ast_register_translator(). The structure should not be * modified after a successful registration, and its address diff --git a/main/file.c b/main/file.c index 453d82f8e..3fb5fa845 100644 --- a/main/file.c +++ b/main/file.c @@ -148,7 +148,7 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f) int res = -1; int alt = 0; if (f->frametype == AST_FRAME_VIDEO) { - if (fs->fmt->format < AST_FORMAT_MAX_AUDIO) { + if (fs->fmt->format & AST_FORMAT_AUDIO_MASK) { /* This is the audio portion. Call the video one... */ if (!fs->vfs && fs->filename) { const char *type = ast_getformatname(f->subclass & ~0x1); @@ -381,7 +381,7 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm struct ast_filestream *s; if ( !(chan->writeformat & f->format) && - !(f->format >= AST_FORMAT_MAX_AUDIO && fmt)) { + !(f->format & AST_FORMAT_AUDIO_MASK && fmt)) { ast_free(fn); continue; /* not a supported format */ } @@ -407,7 +407,7 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm s->fmt = f; s->trans = NULL; s->filename = NULL; - if (s->fmt->format < AST_FORMAT_MAX_AUDIO) { + if (s->fmt->format & AST_FORMAT_AUDIO_MASK) { if (chan->stream) ast_closestream(chan->stream); chan->stream = s; @@ -577,7 +577,7 @@ struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *fil if (buf == NULL) return NULL; - for (format = AST_FORMAT_MAX_AUDIO << 1; format <= AST_FORMAT_MAX_VIDEO; format = format << 1) { + for (format = AST_FORMAT_AUDIO_MASK + 1; format <= AST_FORMAT_VIDEO_MASK; format = format << 1) { int fd; const char *fmt; @@ -710,7 +710,7 @@ int ast_playstream(struct ast_filestream *s) { enum fsread_res res; - if (s->fmt->format < AST_FORMAT_MAX_AUDIO) + if (s->fmt->format & AST_FORMAT_AUDIO_MASK) res = ast_readaudio_callback(s); else res = ast_readvideo_callback(s); @@ -749,7 +749,7 @@ int ast_closestream(struct ast_filestream *f) size_t size = 0; /* Stop a running stream if there is one */ if (f->owner) { - if (f->fmt->format < AST_FORMAT_MAX_AUDIO) { + if (f->fmt->format & AST_FORMAT_AUDIO_MASK) { f->owner->stream = NULL; if (f->owner->streamid > -1) ast_sched_del(f->owner->sched, f->owner->streamid); diff --git a/main/frame.c b/main/frame.c index 98b0800c9..a0109fd67 100644 --- a/main/frame.c +++ b/main/frame.c @@ -104,30 +104,28 @@ struct ast_smoother { /*! \brief Definition of supported media formats (codecs) */ static struct ast_format_list AST_FORMAT_LIST[] = { - { 1, AST_FORMAT_G723_1 , "g723" , "G.723.1", 20, 30, 300, 30, 30 }, /*!< G723.1 */ - { 1, AST_FORMAT_GSM, "gsm" , "GSM", 33, 20, 300, 20, 20 }, /*!< codec_gsm.c */ - { 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law", 80, 10, 150, 10, 20 }, /*!< codec_ulaw.c */ - { 1, AST_FORMAT_ALAW, "alaw", "G.711 A-law", 80, 10, 150, 10, 20 }, /*!< codec_alaw.c */ - { 1, AST_FORMAT_G726, "g726", "G.726 RFC3551", 40, 10, 300, 10, 20 }, /*!< codec_g726.c */ - { 1, AST_FORMAT_ADPCM, "adpcm" , "ADPCM", 40, 10, 300, 10, 20 }, /*!< codec_adpcm.c */ - { 1, AST_FORMAT_SLINEAR, "slin", "16 bit Signed Linear PCM", 160, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE }, /*!< Signed linear */ - { 1, AST_FORMAT_LPC10, "lpc10", "LPC10", 7, 20, 20, 20, 20 }, /*!< codec_lpc10.c */ - { 1, AST_FORMAT_G729A, "g729", "G.729A", 10, 10, 230, 10, 20, AST_SMOOTHER_FLAG_G729 }, /*!< Binary commercial distribution */ - { 1, AST_FORMAT_SPEEX, "speex", "SpeeX", 10, 10, 60, 10, 20 }, /*!< codec_speex.c */ - { 1, AST_FORMAT_ILBC, "ilbc", "iLBC", 50, 30, 30, 30, 30 }, /*!< codec_ilbc.c */ /* inc=30ms - workaround */ - { 1, AST_FORMAT_G726_AAL2, "g726aal2", "G.726 AAL2", 40, 10, 300, 10, 20 }, /*!< codec_g726.c */ - { 1, AST_FORMAT_G722, "g722", "G722", 80, 10, 150, 10, 20 }, /*!< G722 Passthrough */ - { 0, AST_FORMAT_MAX_AUDIO, "maxaudio", "Maximum audio format" }, - { 1, AST_FORMAT_JPEG, "jpeg", "JPEG image"}, /*!< See format_jpeg.c */ - { 1, AST_FORMAT_PNG, "png", "PNG image"}, /*!< PNG Image format */ - { 1, AST_FORMAT_H261, "h261", "H.261 Video" }, /*!< H.261 Video Passthrough */ - { 1, AST_FORMAT_H263, "h263", "H.263 Video" }, /*!< H.263 Passthrough support, see format_h263.c */ - { 1, AST_FORMAT_H263_PLUS, "h263p", "H.263+ Video" }, /*!< H.263plus passthrough support See format_h263.c */ - { 1, AST_FORMAT_H264, "h264", "H.264 Video" }, /*!< Passthrough support, see format_h263.c */ - { 1, AST_FORMAT_MP4_VIDEO, "mpeg4", "MPEG4 Video" }, /*!< Passthrough support for MPEG4 */ - { 0, AST_FORMAT_MAX_VIDEO, "maxvideo", "Maximum video format" }, - { 1, AST_FORMAT_T140, "t140", "Passthrough T.140 Realtime Text" }, /*!< Passthrough support for T.140 Realtime Text */ - { 0, AST_FORMAT_MAX_TEXT, "maxtext", "Maximum text format" }, + { AST_FORMAT_G723_1 , "g723", 8000, "G.723.1", 20, 30, 300, 30, 30 }, /*!< G723.1 */ + { AST_FORMAT_GSM, "gsm", 8000, "GSM", 33, 20, 300, 20, 20 }, /*!< codec_gsm.c */ + { AST_FORMAT_ULAW, "ulaw", 8000, "G.711 u-law", 80, 10, 150, 10, 20 }, /*!< codec_ulaw.c */ + { AST_FORMAT_ALAW, "alaw", 8000, "G.711 A-law", 80, 10, 150, 10, 20 }, /*!< codec_alaw.c */ + { AST_FORMAT_G726, "g726", 8000, "G.726 RFC3551", 40, 10, 300, 10, 20 }, /*!< codec_g726.c */ + { AST_FORMAT_ADPCM, "adpcm" , 8000, "ADPCM", 40, 10, 300, 10, 20 }, /*!< codec_adpcm.c */ + { AST_FORMAT_SLINEAR, "slin", 8000, "16 bit Signed Linear PCM", 160, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE }, /*!< Signed linear */ + { AST_FORMAT_LPC10, "lpc10", 8000, "LPC10", 7, 20, 20, 20, 20 }, /*!< codec_lpc10.c */ + { AST_FORMAT_G729A, "g729", 8000, "G.729A", 10, 10, 230, 10, 20, AST_SMOOTHER_FLAG_G729 }, /*!< Binary commercial distribution */ + { AST_FORMAT_SPEEX, "speex", 8000, "SpeeX", 10, 10, 60, 10, 20 }, /*!< codec_speex.c */ + { AST_FORMAT_ILBC, "ilbc", 8000, "iLBC", 50, 30, 30, 30, 30 }, /*!< codec_ilbc.c */ /* inc=30ms - workaround */ + { AST_FORMAT_G726_AAL2, "g726aal2", 8000, "G.726 AAL2", 40, 10, 300, 10, 20 }, /*!< codec_g726.c */ + { AST_FORMAT_G722, "g722", 16000, "G722", 80, 10, 150, 10, 20 }, /*!< codec_g722.c */ + { AST_FORMAT_SLINEAR16, "slin16", 16000, "16 bit Signed Linear PCM (16kHz)", 320, 10, 70, 10, 20 }, /*!< Signed linear (16kHz) */ + { AST_FORMAT_JPEG, "jpeg", 0, "JPEG image"}, /*!< See format_jpeg.c */ + { AST_FORMAT_PNG, "png", 0, "PNG image"}, /*!< PNG Image format */ + { AST_FORMAT_H261, "h261", 0, "H.261 Video" }, /*!< H.261 Video Passthrough */ + { AST_FORMAT_H263, "h263", 0, "H.263 Video" }, /*!< H.263 Passthrough support, see format_h263.c */ + { AST_FORMAT_H263_PLUS, "h263p", 0, "H.263+ Video" }, /*!< H.263plus passthrough support See format_h263.c */ + { AST_FORMAT_H264, "h264", 0, "H.264 Video" }, /*!< Passthrough support, see format_h263.c */ + { AST_FORMAT_MP4_VIDEO, "mpeg4", 0, "MPEG4 Video" }, /*!< Passthrough support for MPEG4 */ + { AST_FORMAT_T140, "t140", 0, "Passthrough T.140 Realtime Text" }, /*!< Passthrough support for T.140 Realtime Text */ }; struct ast_frame ast_null_frame = { AST_FRAME_NULL, }; @@ -525,7 +523,7 @@ char* ast_getformatname(int format) int x; char *ret = "unknown"; for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { - if (AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == format) { + if (AST_FORMAT_LIST[x].bits == format) { ret = AST_FORMAT_LIST[x].name; break; } @@ -547,7 +545,7 @@ char *ast_getformatname_multiple(char *buf, size_t size, int format) size -= len; start = end; for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { - if (AST_FORMAT_LIST[x].visible && (AST_FORMAT_LIST[x].bits & format)) { + if (AST_FORMAT_LIST[x].bits & format) { snprintf(end, size,"%s|",AST_FORMAT_LIST[x].name); len = strlen(end); end += len; @@ -566,6 +564,7 @@ static struct ast_codec_alias_table { char *realname; } ast_codec_alias_table[] = { { "slinear", "slin"}, + { "slinear16", "slin16"}, { "g723.1", "g723"}, }; @@ -586,9 +585,9 @@ int ast_getformatbyname(const char *name) all = strcasecmp(name, "all") ? 0 : 1; for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { - if (AST_FORMAT_LIST[x].visible && (all || + if (all || !strcasecmp(AST_FORMAT_LIST[x].name,name) || - !strcasecmp(AST_FORMAT_LIST[x].name,ast_expand_codec_alias(name)))) { + !strcasecmp(AST_FORMAT_LIST[x].name,ast_expand_codec_alias(name))) { format |= AST_FORMAT_LIST[x].bits; if (!all) break; @@ -603,7 +602,7 @@ char *ast_codec2str(int codec) int x; char *ret = "unknown"; for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { - if (AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == codec) { + if (AST_FORMAT_LIST[x].bits == codec) { ret = AST_FORMAT_LIST[x].desc; break; } @@ -1357,7 +1356,7 @@ int ast_codec_get_samples(struct ast_frame *f) samples = speex_samples(f->data, f->datalen); break; case AST_FORMAT_G723_1: - samples = g723_samples(f->data, f->datalen); + samples = g723_samples(f->data, f->datalen); break; case AST_FORMAT_ILBC: samples = 240 * (f->datalen / 50); @@ -1369,10 +1368,11 @@ int ast_codec_get_samples(struct ast_frame *f) samples = f->datalen * 8; break; case AST_FORMAT_SLINEAR: + case AST_FORMAT_SLINEAR16: samples = f->datalen / 2; break; case AST_FORMAT_LPC10: - /* assumes that the RTP packet contains one LPC10 frame */ + /* assumes that the RTP packet contains one LPC10 frame */ samples = 22 * 8; samples += (((char *)(f->data))[7] & 0x1) * 8; break; @@ -1411,10 +1411,12 @@ int ast_codec_get_len(int format, int samples) len = samples / 8; break; case AST_FORMAT_SLINEAR: + case AST_FORMAT_SLINEAR16: len = samples * 2; break; case AST_FORMAT_ULAW: case AST_FORMAT_ALAW: + case AST_FORMAT_G722: len = samples; break; case AST_FORMAT_ADPCM: diff --git a/main/rtp.c b/main/rtp.c index ef1cf0ddf..5ab4eb658 100644 --- a/main/rtp.c +++ b/main/rtp.c @@ -1571,7 +1571,7 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp) return f ? f : &ast_null_frame; } rtp->lastrxformat = rtp->f.subclass = rtpPT.code; - rtp->f.frametype = (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) ? AST_FRAME_VOICE : (rtp->f.subclass < AST_FORMAT_MAX_VIDEO) ? AST_FRAME_VIDEO : AST_FRAME_TEXT; + rtp->f.frametype = (rtp->f.subclass & AST_FORMAT_AUDIO_MASK) ? AST_FRAME_VOICE : (rtp->f.subclass & AST_FORMAT_VIDEO_MASK) ? AST_FRAME_VIDEO : AST_FRAME_TEXT; if (!rtp->lastrxts) rtp->lastrxts = timestamp; @@ -1586,7 +1586,7 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp) rtp->f.data = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET; rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET; rtp->f.seqno = seqno; - if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) { + if (rtp->f.subclass & AST_FORMAT_AUDIO_MASK) { rtp->f.samples = ast_codec_get_samples(&rtp->f); if (rtp->f.subclass == AST_FORMAT_SLINEAR) ast_frame_byteswap_be(&rtp->f); @@ -1595,7 +1595,7 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp) rtp->f.has_timing_info = 1; rtp->f.ts = timestamp / 8; rtp->f.len = rtp->f.samples / 8; - } else if(rtp->f.subclass < AST_FORMAT_MAX_VIDEO) { + } else if(rtp->f.subclass & AST_FORMAT_VIDEO_MASK) { /* Video -- samples is # of samples vs. 90000 */ if (!rtp->lastividtimestamp) rtp->lastividtimestamp = timestamp; @@ -2958,7 +2958,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec ms = calc_txstamp(rtp, &f->delivery); /* Default prediction */ - if (f->subclass < AST_FORMAT_MAX_AUDIO) { + if (f->subclass & AST_FORMAT_AUDIO_MASK) { pred = rtp->lastts + f->samples; /* Re-calculate last TS */ @@ -2973,7 +2973,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec mark = 1; } } - } else if(f->subclass < AST_FORMAT_MAX_VIDEO) { + } else if(f->subclass & AST_FORMAT_VIDEO_MASK) { mark = f->subclass & 0x1; pred = rtp->lastovidtimestamp + f->samples; /* Re-calculate last TS */ diff --git a/main/translate.c b/main/translate.c index 535257afa..09722a427 100644 --- a/main/translate.c +++ b/main/translate.c @@ -806,7 +806,7 @@ unsigned int ast_translate_available_formats(unsigned int dest, unsigned int src known audio formats to determine whether there exists a translation path from the source format to the destination format. */ - for (x = 1; src_audio && x < AST_FORMAT_MAX_AUDIO; x <<= 1) { + for (x = 1; src_audio && (x & AST_FORMAT_AUDIO_MASK); x <<= 1) { /* if this is not a desired format, nothing to do */ if (!dest & x) continue; @@ -832,7 +832,7 @@ unsigned int ast_translate_available_formats(unsigned int dest, unsigned int src known video formats to determine whether there exists a translation path from the source format to the destination format. */ - for (; src_video && x < AST_FORMAT_MAX_VIDEO; x <<= 1) { + for (; src_video && (x & AST_FORMAT_VIDEO_MASK); x <<= 1) { /* if this is not a desired format, nothing to do */ if (!dest & x) continue;