mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-21 20:40:10 +00:00
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: https://origsvn.digium.com/svn/asterisk/trunk@89071 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
12
main/file.c
12
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);
|
||||
|
64
main/frame.c
64
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:
|
||||
|
10
main/rtp.c
10
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 */
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user