summaryrefslogtreecommitdiff
path: root/modules/mpa/encode.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mpa/encode.c')
-rw-r--r--modules/mpa/encode.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/modules/mpa/encode.c b/modules/mpa/encode.c
index 6504c38..0715d67 100644
--- a/modules/mpa/encode.c
+++ b/modules/mpa/encode.c
@@ -13,9 +13,10 @@
struct auenc_state {
twolame_options *enc;
- int channels;
+ int channels, samplerate;
SpeexResamplerState *resampler;
int16_t intermediate_buffer[BARESIP_FRAMESIZE];
+ uint32_t timestamp;
};
@@ -59,16 +60,18 @@ int mpa_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
mem_deref(aes);
return ENOMEM;
}
- aes->channels = ac->ch;
#ifdef DEBUG
debug("MPA enc created %s\n",fmtp);
#endif
+ aes->channels = ac->ch;
+ aes->timestamp = rand_u32();
- prm.samplerate = 32000;
+ prm.samplerate = 48000;
prm.bitrate = 128000;
prm.layer = 2;
prm.mode = SINGLE_CHANNEL;
mpa_decode_fmtp(&prm, fmtp);
+ aes->samplerate = prm.samplerate;
result = 0;
#ifdef DEBUG
@@ -103,8 +106,8 @@ int mpa_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
#ifdef DEBUG
twolame_print_config(aes->enc);
#endif
- if (prm.samplerate != 48000) {
- aes->resampler = speex_resampler_init(2, 48000,
+ if (prm.samplerate != MPA_IORATE) {
+ aes->resampler = speex_resampler_init(2, MPA_IORATE,
prm.samplerate, 3, &result);
if (result!=RESAMPLER_ERR_SUCCESS) {
error("MPA enc resampler init failed %d\n",result);
@@ -136,7 +139,7 @@ int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
return EINVAL;
if (aes->resampler) {
- in_len = sampc/2;
+ in_len = (uint32_t)sampc/2;
intermediate_len = sizeof(aes->intermediate_buffer)
/ sizeof(aes->intermediate_buffer[0]);
n=speex_resampler_process_interleaved_int(aes->resampler,
@@ -149,7 +152,7 @@ int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
}
n = twolame_encode_buffer_interleaved(aes->enc,
aes->intermediate_buffer, intermediate_len,
- buf+4, (*len)-4);
+ buf+4, (int)(*len)-4);
#ifdef DEBUG
debug("MPA enc %d %d %d %d %d\n",intermediate_len,sampc,
aes->channels,*len,n);
@@ -157,7 +160,7 @@ int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
}
else
n = twolame_encode_buffer_interleaved(aes->enc, sampv,
- (int)(sampc/2), buf+4, (*len)-4);
+ (int)(sampc/2), buf+4, (int)(*len)-4);
if (n < 0) {
error("MPA enc error %s\n", strerror((int)n));
@@ -165,7 +168,7 @@ int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
}
if (n > 0) {
- *(uint32_t*)buf = 0;
+ *(uint32_t*)(void *)buf = 0;
*len = n+4;
}
else
@@ -174,6 +177,8 @@ int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
#ifdef DEBUG
debug("MPA enc done %d %d %d %d\n",sampc,aes->channels,*len,n);
#endif
- return 0;
+ aes->timestamp += ((MPA_FRAMESIZE*MPA_RTPRATE)<<4) / aes->samplerate;
+
+ return 0x00010000 | ((aes->timestamp>>4) & 0x0000ffff);
}