Commit 6874ac86 authored by Simon Morlat's avatar Simon Morlat

fix dynamic ptime adjustement in g726 and l16 codecs

parent 2f953745
......@@ -78,18 +78,22 @@ static void enc_preprocess(MSFilter *f){
static void enc_process(MSFilter *f){
EncState *s=(EncState*)f->data;
int16_t *pcmbuf=(int16_t*)alloca(s->nsamples*sizeof(int16_t));
int encoded_bytes=(s->nsamples*2*s->bitrate)/128000;
ms_bufferizer_put_from_queue(s->input,f->inputs[0]);
while(ms_bufferizer_read(s->input,(uint8_t*)pcmbuf,s->nsamples*2)!=0){
mblk_t *om=allocb(encoded_bytes,0);
om->b_wptr+=g726_encode(s->impl,om->b_wptr,pcmbuf,s->nsamples);
mblk_set_timestamp_info(om,s->ts);
s->ts+=s->nsamples;
ms_queue_put(f->outputs[0],om);
ms_filter_lock(f);
{
int16_t *pcmbuf=(int16_t*)alloca(s->nsamples*sizeof(int16_t));
int encoded_bytes=(s->nsamples*2*s->bitrate)/128000;
ms_bufferizer_put_from_queue(s->input,f->inputs[0]);
while(ms_bufferizer_read(s->input,(uint8_t*)pcmbuf,s->nsamples*2)!=0){
mblk_t *om=allocb(encoded_bytes,0);
om->b_wptr+=g726_encode(s->impl,om->b_wptr,pcmbuf,s->nsamples);
mblk_set_timestamp_info(om,s->ts);
s->ts+=s->nsamples;
ms_queue_put(f->outputs[0],om);
}
}
ms_filter_unlock(f);
}
static void enc_uninit(MSFilter *f){
......@@ -109,7 +113,10 @@ static int enc_add_fmtp(MSFilter *f, void *data){
EncState *s=(EncState*)f->data;
char tmp[16];
if (fmtp_get_value((const char*)data,"ptime",tmp,sizeof(tmp))){
ms_filter_lock(f);
set_ptime(s,atoi(tmp));
enc_preprocess(f);
ms_filter_unlock(f);
}
return 0;
}
......@@ -160,7 +167,6 @@ static void dec_uninit(MSFilter *f){
ms_free(s);
}
#ifndef _MSC_VER
#define MAKE_G726_DESC(bitrate) \
......
......@@ -103,7 +103,8 @@ MSFilterDesc ms_genericplc_desc= {
generic_plc_process,
NULL,
generic_plc_unit,
generic_plc_methods
generic_plc_methods,
MS_FILTER_IS_PUMP
};
#else
......
......@@ -34,7 +34,7 @@ static void enc_init(MSFilter *f)
struct EncState *s=(struct EncState*)ms_new(struct EncState,1);
s->ts=0;
s->bufferizer=ms_bufferizer_new();
s->ptime = 20;
s->ptime = 10;
s->rate=8000;
s->nchannels = 1;
f->data=s;
......@@ -48,29 +48,35 @@ static void enc_uninit(MSFilter *f)
f->data = 0;
};
static void enc_update(struct EncState *s){
s->nbytes=(2*s->nchannels*s->rate*s->ptime)/1000;
}
static void enc_preprocess(MSFilter *f){
struct EncState *s=(struct EncState*)f->data;
s->nbytes=(2*s->nchannels*s->rate*s->ptime)/1000;
enc_update(s);
}
static void enc_process(MSFilter *f)
{
static void enc_process(MSFilter *f){
struct EncState *s=(struct EncState*)f->data;
ms_filter_lock(f);
ms_bufferizer_put_from_queue(s->bufferizer,f->inputs[0]);
while(ms_bufferizer_get_avail(s->bufferizer)>=s->nbytes) {
mblk_t *om=allocb(s->nbytes,0);
om->b_wptr+=ms_bufferizer_read(s->bufferizer,om->b_wptr,s->nbytes);
mblk_set_timestamp_info(om,s->ts);
mblk_set_timestamp_info(om,s->ts);
ms_queue_put(f->outputs[0],om);
s->ts += s->nbytes/(2*s->nchannels);
}
ms_filter_unlock(f);
};
static void set_ptime(struct EncState *s, int value){
if (value>0 && value<=100){
s->ptime=value;
enc_update(s);
}
}
......@@ -78,9 +84,11 @@ static int enc_add_attr(MSFilter *f, void *arg)
{
const char *fmtp=(const char*)arg;
struct EncState *s=(struct EncState*)f->data;
if(strstr(fmtp,"ptime:"))
if(strstr(fmtp,"ptime:")){
ms_filter_lock(f);
set_ptime(s,atoi(fmtp+6));
ms_filter_unlock(f);
}
return 0;
};
......@@ -89,7 +97,9 @@ static int enc_add_fmtp(MSFilter *f, void *arg){
struct EncState *s=(struct EncState*)f->data;
char tmp[16]={0};
if (fmtp_get_value(fmtp,"ptime",tmp,sizeof(tmp))){
ms_filter_lock(f);
set_ptime(s,atoi(tmp));
ms_filter_unlock(f);
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment