[svn-commits] branch mattf/asterisk-wideband - r7385 in
/team/mattf/asterisk-wideband: ./ i...
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Wed Dec 7 16:39:41 CST 2005
Author: mattf
Date: Wed Dec 7 16:39:40 2005
New Revision: 7385
URL: http://svn.digium.com/view/asterisk?rev=7385&view=rev
Log:
Interface changes to prepare for non 8khz audio.
Modified:
team/mattf/asterisk-wideband/frame.c
team/mattf/asterisk-wideband/include/asterisk/frame.h
team/mattf/asterisk-wideband/include/asterisk/time.h
team/mattf/asterisk-wideband/rtp.c
team/mattf/asterisk-wideband/translate.c
Modified: team/mattf/asterisk-wideband/frame.c
URL: http://svn.digium.com/view/asterisk/team/mattf/asterisk-wideband/frame.c?rev=7385&r1=7384&r2=7385&view=diff
==============================================================================
--- team/mattf/asterisk-wideband/frame.c (original)
+++ team/mattf/asterisk-wideband/frame.c Wed Dec 7 16:39:40 2005
@@ -60,6 +60,7 @@
int bits; /*!< bitmask value */
char *name; /*!< short name */
char *desc; /*!< Description */
+ int samplerate;
};
struct ast_smoother {
@@ -79,32 +80,32 @@
/*! \brief Definition of supported media formats (codecs) */
static struct ast_format_list AST_FORMAT_LIST[] = {
- { 1, AST_FORMAT_G723_1 , "g723" , "G.723.1"}, /*!< codec_g723_1.c */
- { 1, AST_FORMAT_GSM, "gsm" , "GSM"}, /*!< codec_gsm.c */
- { 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law" }, /*!< codec_ulaw.c */
- { 1, AST_FORMAT_ALAW, "alaw", "G.711 A-law" }, /*!< codec_alaw.c */
- { 1, AST_FORMAT_G726, "g726", "G.726" }, /*!< codec_g726.c */
- { 1, AST_FORMAT_ADPCM, "adpcm" , "ADPCM"}, /*!< codec_adpcm.c */
- { 1, AST_FORMAT_SLINEAR, "slin", "16 bit Signed Linear PCM"}, /*!< */
- { 1, AST_FORMAT_LPC10, "lpc10", "LPC10" }, /*!< codec_lpc10.c */
- { 1, AST_FORMAT_G729A, "g729", "G.729A" }, /*!< Binary commercial distribution */
- { 1, AST_FORMAT_SPEEX, "speex", "SpeeX" }, /*!< codec_speex.c */
- { 1, AST_FORMAT_ILBC, "ilbc", "iLBC"}, /*!< codec_ilbc.c */
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 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"}, /*!< Image format */
- { 1, AST_FORMAT_H261, "h261", "H.261 Video" }, /*!< Passthrough */
- { 1, AST_FORMAT_H263, "h263", "H.263 Video" }, /*!< Passthrough support, see format_h263.c */
- { 1, AST_FORMAT_H263_PLUS, "h263p", "H.263+ Video" }, /*!< See format_h263.c */
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, AST_FORMAT_MAX_VIDEO, "maxvideo", "Maximum video format" },
+ { 1, AST_FORMAT_G723_1 , "g723" , "G.723.1", 8000}, /*!< codec_g723_1.c */
+ { 1, AST_FORMAT_GSM, "gsm" , "GSM", 8000}, /*!< codec_gsm.c */
+ { 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law", 8000}, /*!< codec_ulaw.c */
+ { 1, AST_FORMAT_ALAW, "alaw", "G.711 A-law", 8000 }, /*!< codec_alaw.c */
+ { 1, AST_FORMAT_G726, "g726", "G.726", 8000 }, /*!< codec_g726.c */
+ { 1, AST_FORMAT_ADPCM, "adpcm" , "ADPCM", 8000}, /*!< codec_adpcm.c */
+ { 1, AST_FORMAT_SLINEAR, "slin", "16 bit Signed Linear PCM (8khz)", 8000}, /*!< */
+ { 1, AST_FORMAT_LPC10, "lpc10", "LPC10", 8000 }, /*!< codec_lpc10.c */
+ { 1, AST_FORMAT_G729A, "g729", "G.729A", 8000 }, /*!< Binary commercial distribution */
+ { 1, AST_FORMAT_SPEEX, "speex", "SpeeX", 8000 }, /*!< codec_speex.c */
+ { 1, AST_FORMAT_ILBC, "ilbc", "iLBC", 8000}, /*!< codec_ilbc.c */
+ { 1, AST_FORMAT_SLINEAR16, "slin16", "16 bit Signed Linear PCM (16khz)", 16000 },
+ { 0, 0, "nothing", "undefined", -1 },
+ { 0, 0, "nothing", "undefined", -1 },
+ { 0, 0, "nothing", "undefined", -1 },
+ { 0, AST_FORMAT_MAX_AUDIO, "maxaudio", "Maximum audio format", -1 },
+ { 1, AST_FORMAT_JPEG, "jpeg", "JPEG image", -1}, /*!< See format_jpeg.c */
+ { 1, AST_FORMAT_PNG, "png", "PNG image", -1}, /*!< Image format */
+ { 1, AST_FORMAT_H261, "h261", "H.261 Video", -1 }, /*!< Passthrough */
+ { 1, AST_FORMAT_H263, "h263", "H.263 Video", -1 }, /*!< Passthrough support, see format_h263.c */
+ { 1, AST_FORMAT_H263_PLUS, "h263p", "H.263+ Video", -1 }, /*!< See format_h263.c */
+ { 0, 0, "nothing", "undefined", -1 },
+ { 0, 0, "nothing", "undefined", -1 },
+ { 0, 0, "nothing", "undefined", -1 },
+ { 0, 0, "nothing", "undefined", -1 },
+ { 0, AST_FORMAT_MAX_VIDEO, "maxvideo", "Maximum video format", -1 },
};
void ast_smoother_reset(struct ast_smoother *s, int size)
@@ -233,7 +234,7 @@
memmove(s->data, s->data + len, s->len);
if (!ast_tvzero(s->delivery)) {
/* If we have delivery time, increment it, otherwise, leave it at 0 */
- s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, 8000));
+ s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, ast_frame_samplerate(&s->f)));
}
}
/* Return frame */
@@ -384,6 +385,28 @@
return out;
}
+int ast_frame_samplerate(struct ast_frame *f)
+{
+ int codec;
+ int i;
+
+ if (!f)
+ return -1;
+
+ if (f->frametype != AST_FRAME_VOICE)
+ return -1;
+
+ if (!(f->subclass & AST_AUDIO_CODEC_MASK))
+ return -1;
+
+ codec = f->subclass;
+
+ for (i = 0; codec; i++)
+ codec >>= 1;
+
+ return AST_FORMAT_LIST[i].samplerate;
+}
+
#if 0
/*
* XXX
Modified: team/mattf/asterisk-wideband/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/team/mattf/asterisk-wideband/include/asterisk/frame.h?rev=7385&r1=7384&r2=7385&view=diff
==============================================================================
--- team/mattf/asterisk-wideband/include/asterisk/frame.h (original)
+++ team/mattf/asterisk-wideband/include/asterisk/frame.h Wed Dec 7 16:39:40 2005
@@ -93,7 +93,7 @@
int subclass;
/*! Length of data */
int datalen;
- /*! Number of 8khz samples in this frame */
+ /*! Number of samples of the specified samplerate in this frame */
int samples;
/*! Was the data malloc'd? i.e. should we free it when we discard the frame? */
int mallocd;
@@ -169,6 +169,7 @@
#define AST_HTML_LINKREJECT 20
/* Data formats for capabilities and frames alike */
+#define AST_AUDIO_CODEC_MASK 0xffff
/*! G.723.1 compression */
#define AST_FORMAT_G723_1 (1 << 0)
/*! GSM compression */
@@ -191,6 +192,8 @@
#define AST_FORMAT_SPEEX (1 << 9)
/*! iLBC Free Compression */
#define AST_FORMAT_ILBC (1 << 10)
+/*! Signed Linear 16khz */
+#define AST_FORMAT_SLINEAR16 (1 << 11)
/*! Maximum audio format */
#define AST_FORMAT_MAX_AUDIO (1 << 15)
/*! JPEG Images */
@@ -418,6 +421,8 @@
#define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 1)
#endif
+extern int ast_frame_samplerate(struct ast_frame *f);
+
extern void ast_frame_dump(char *name, struct ast_frame *f, char *prefix);
/*! \brief Initialize a codec preference to "no preference" */
Modified: team/mattf/asterisk-wideband/include/asterisk/time.h
URL: http://svn.digium.com/view/asterisk/team/mattf/asterisk-wideband/include/asterisk/time.h?rev=7385&r1=7384&r2=7385&view=diff
==============================================================================
--- team/mattf/asterisk-wideband/include/asterisk/time.h (original)
+++ team/mattf/asterisk-wideband/include/asterisk/time.h Wed Dec 7 16:39:40 2005
@@ -140,4 +140,10 @@
}
)
+AST_INLINE_API(
+struct timeval ast_fr2tv(unsigned int _nsamp, unsigned int _rate),
+{
+ return ast_tv(_nsamp / _rate, (_nsamp % _rate) * (1000000 / _rate));
+}
+)
#endif /* _ASTERISK_TIME_H */
Modified: team/mattf/asterisk-wideband/rtp.c
URL: http://svn.digium.com/view/asterisk/team/mattf/asterisk-wideband/rtp.c?rev=7385&r1=7384&r2=7385&view=diff
==============================================================================
--- team/mattf/asterisk-wideband/rtp.c (original)
+++ team/mattf/asterisk-wideband/rtp.c Wed Dec 7 16:39:40 2005
@@ -411,9 +411,9 @@
return &null_frame;
}
-static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark)
-{
- struct timeval ts = ast_samp2tv( timestamp, 8000);
+static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark, int samplerate)
+{
+ struct timeval ts = ast_samp2tv( timestamp, samplerate);
if (ast_tvzero(rtp->rxcore) || mark) {
rtp->rxcore = ast_tvsub(ast_tvnow(), ts);
/* Round to 20ms for nice, pretty timestamps */
@@ -614,9 +614,9 @@
rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET;
if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) {
rtp->f.samples = ast_codec_get_samples(&rtp->f);
- if (rtp->f.subclass == AST_FORMAT_SLINEAR)
+ if ((rtp->f.subclass == AST_FORMAT_SLINEAR) || (rtp->f.subclass == AST_FORMAT_SLINEAR16))
ast_frame_byteswap_be(&rtp->f);
- calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark);
+ calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark, ast_frame_samplerate(&rtp->f));
} else {
/* Video -- samples is # of samples vs. 90000 */
if (!rtp->lastividtimestamp)
Modified: team/mattf/asterisk-wideband/translate.c
URL: http://svn.digium.com/view/asterisk/team/mattf/asterisk-wideband/translate.c?rev=7385&r1=7384&r2=7385&view=diff
==============================================================================
--- team/mattf/asterisk-wideband/translate.c (original)
+++ team/mattf/asterisk-wideband/translate.c Wed Dec 7 16:39:40 2005
@@ -178,7 +178,7 @@
path->nextout = f->delivery;
}
/* Predict next incoming sample */
- path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, 8000));
+ path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, ast_frame_samplerate(f)));
}
delivery = f->delivery;
if (consume)
@@ -203,7 +203,7 @@
/* Predict next outgoing timestamp from samples in this
frame. */
- path->nextout = ast_tvadd(path->nextout, ast_samp2tv( out->samples, 8000));
+ path->nextout = ast_tvadd(path->nextout, ast_samp2tv( out->samples, ast_frame_samplerate(out)));
} else {
out->delivery = ast_tv(0, 0);
}
@@ -225,7 +225,7 @@
struct ast_translator_pvt *pvt;
struct ast_frame *f, *out;
struct timeval start;
- int cost;
+ int cost, rate;
if(!samples)
samples = 1;
@@ -242,9 +242,22 @@
t->cost = 99999;
return;
}
+
+ /* Get the sample rate of the codec based on the frame */
+ f = t->sample();
+ if (!f) {
+ ast_log(LOG_WARNING, "Translator '%s' failed to produce a sample frame.\n", t->name);
+ t->destroy(pvt);
+ t->cost = 99999;
+ return;
+ }
+
+ rate = ast_frame_samplerate(f);
+ ast_frfree(f);
+
start = ast_tvnow();
/* Call the encoder until we've processed one second of time */
- while(sofar < samples * 8000) {
+ while(sofar < samples * rate) {
f = t->sample();
if (!f) {
ast_log(LOG_WARNING, "Translator '%s' failed to produce a sample frame.\n", t->name);
@@ -261,7 +274,8 @@
}
cost = ast_tvdiff_ms(ast_tvnow(), start);
t->destroy(pvt);
- t->cost = cost / samples;
+ /* New cost */
+ t->cost = cost / (samples / (rate / 8000));
if (!t->cost)
t->cost = 1;
}
More information about the svn-commits
mailing list