Index: channels/chan_jingle.c =================================================================== --- channels/chan_jingle.c (revision 89048) +++ channels/chan_jingle.c (working copy) @@ -198,7 +198,7 @@ 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 @@ 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"); Index: channels/chan_phone.c =================================================================== --- channels/chan_phone.c (revision 89048) +++ channels/chan_phone.c (working copy) @@ -594,7 +594,7 @@ } 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; Index: channels/chan_h323.c =================================================================== --- channels/chan_h323.c (revision 89048) +++ channels/chan_h323.c (working copy) @@ -249,7 +249,7 @@ 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 @@ 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); Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 89048) +++ channels/chan_sip.c (working copy) @@ -155,8 +155,6 @@ #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 @@ } /* 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); } Index: channels/chan_skinny.c =================================================================== --- channels/chan_skinny.c (revision 89048) +++ channels/chan_skinny.c (working copy) @@ -1239,7 +1239,7 @@ 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 @@ 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; } Index: channels/chan_mgcp.c =================================================================== --- channels/chan_mgcp.c (revision 89048) +++ channels/chan_mgcp.c (working copy) @@ -2076,7 +2076,7 @@ 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 @@ 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 @@ 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); Index: channels/chan_gtalk.c =================================================================== --- channels/chan_gtalk.c (revision 89048) +++ channels/chan_gtalk.c (working copy) @@ -198,7 +198,7 @@ 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, Index: include/asterisk/translate.h =================================================================== --- include/asterisk/translate.h (revision 89048) +++ include/asterisk/translate.h (working copy) @@ -44,7 +44,7 @@ * 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 Index: include/asterisk/frame.h =================================================================== --- include/asterisk/frame.h (revision 89048) +++ include/asterisk/frame.h (working copy) @@ -243,8 +243,8 @@ #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 @@ #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 @@ /*! \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 */ Index: main/translate.c =================================================================== --- main/translate.c (revision 89048) +++ main/translate.c (working copy) @@ -806,7 +806,7 @@ 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 @@ 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; Index: main/rtp.c =================================================================== --- main/rtp.c (revision 89048) +++ main/rtp.c (working copy) @@ -1571,7 +1571,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 */ Index: main/frame.c =================================================================== --- main/frame.c (revision 89048) +++ main/frame.c (working copy) @@ -104,30 +104,28 @@ /*! \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 @@ 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 @@ 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 @@ char *realname; } ast_codec_alias_table[] = { { "slinear", "slin"}, + { "slinear16", "slin16"}, { "g723.1", "g723"}, }; @@ -586,9 +585,9 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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: Index: main/file.c =================================================================== --- main/file.c (revision 89048) +++ main/file.c (working copy) @@ -148,7 +148,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ 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); Index: codecs/codec_g722.c =================================================================== --- codecs/codec_g722.c (revision 89048) +++ codecs/codec_g722.c (working copy) @@ -74,6 +74,15 @@ 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 @@ 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 @@ 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 @@ 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 @@ .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 @@ 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 @@ { 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();