Commit 248a2b1c authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Fix packet queue overflow by correctly setting the timestamp in the encoded packets.

parent 3f196879
......@@ -75,19 +75,19 @@ static void filter_preprocess(MSFilter *f){
static void decode(MSFilter *f, mblk_t *im) {
isac_decoder_t* obj = (isac_decoder_t*)f->data;
WebRtc_Word16 samples_nb, ret;
WebRtc_Word16 samples_nb, ret;
WebRtc_Word16 speech_type; // needed but not used..
// im is one packet from the encoder, so it's either 30 or 60 ms of audio
ret = WebRtcIsacfix_ReadFrameLen( (const WebRtc_Word16*)im->b_rptr, &samples_nb);
// ms_message("WebRtcIsacfix_ReadFrameLen -> %d", samples_nb);
// ms_message("WebRtcIsacfix_ReadFrameLen -> %d", samples_nb);
if( ret == 0 ) {
mblk_t *om = allocb(samples_nb*2, 0);
mblk_meta_copy(im, om);
obj->ptime = (samples_nb == ISAC_30MS_SAMPLE_COUNT) ? 30 : 60; // update ptime
// ms_message("DECODED om datap @%p", om->b_datap);
// ms_message("DECODED om datap @%p", om->b_datap);
ret = WebRtcIsacfix_Decode(obj->isac,
(const WebRtc_UWord16*)im->b_rptr,
......@@ -98,9 +98,9 @@ static void decode(MSFilter *f, mblk_t *im) {
ms_error( "WebRtcIsacfix_Decode error: %d", WebRtcIsacfix_GetErrorCode(obj->isac) );
freeb(om);
} else {
// ms_message("Decoded %d samples", ret);
// ms_message("Decoded %d samples", ret);
om->b_wptr+= ret*2;
mblk_set_plc_flag(om, (im != NULL)?0:1);
mblk_set_plc_flag(om, 0);
ms_queue_put(f->outputs[0], om);
}
......@@ -118,10 +118,14 @@ static void decode(MSFilter *f, mblk_t *im) {
static void filter_process(MSFilter *f){
isac_decoder_t* obj = (isac_decoder_t*)f->data;
mblk_t* im;
int count = 0;
while(( im= ms_queue_get(f->inputs[0]) ) != NULL ){
im = ms_queue_get( f->inputs[0] );
while( im != NULL ){
decode(f, im);
freemsg(im);
count++;
im = ms_queue_get( f->inputs[0] );
}
if( ms_concealer_context_is_concealement_required(obj->plc_ctx, f->ticker->time) ) {
......@@ -129,7 +133,7 @@ static void filter_process(MSFilter *f){
WebRtc_Word16 flen = (obj->ptime == 30) ? ISAC_30MS_SAMPLE_COUNT
: ISAC_60MS_SAMPLE_COUNT;
mblk_t* plc_blk = allocb(flen*2, 0 );
// ms_message("PLC om datap @%p, nb samples %d", plc_blk->b_datap, flen);
// ms_message("PLC for %d ms", obj->ptime);
// interpolate 1 frame for 30ms ptime, 2 frames for 60ms
WebRtc_Word16 ret = WebRtcIsacfix_DecodePlc(obj->isac,
......
......@@ -32,7 +32,7 @@ struct _isac_encoder_struct_t {
MSBufferizer *bufferizer;
unsigned int ptime;
unsigned int bitrate;
unsigned int totalSize;
unsigned int ts;
};
typedef struct _isac_encoder_struct_t isac_encoder_struct_t;
......@@ -75,6 +75,7 @@ static void filter_init ( MSFilter *f ) {
}
obj->bufferizer = ms_bufferizer_new();
obj->ts = 0;
}
static void filter_preprocess ( MSFilter *f ) {
......@@ -87,6 +88,7 @@ static void filter_process ( MSFilter *f ) {
mblk_t *om=NULL;
u_int8_t* input_buf = NULL;
WebRtc_Word16 ret;
static int out_count = 0;
// get the input data and put it into our buffered input
while( (im = ms_queue_get( f->inputs[0] ) ) != NULL ) {
......@@ -111,23 +113,23 @@ static void filter_process ( MSFilter *f ) {
freeb(om);
} else if( ret == 0 ) {
// Encode buffered the input, not yet able to produce a packet, continue feeding it
// 160 samples per-call, if possible
// Encode() buffered the input, not yet able to produce a packet, continue feeding it
// 160 samples per-call
obj->ts += ISAC_SAMPLES_PER_ENCODE;
freeb(om);
} else {
// a new packet has been encoded, send it
obj->totalSize += ret;
obj->ts += ISAC_SAMPLES_PER_ENCODE;
om->b_wptr += ret;
// ms_message("packet out, size %d", ret);
out_count++;
// ms_message("packet %d out, samples %d", out_count, obj->ts);
mblk_set_timestamp_info( om, obj->totalSize );
mblk_set_timestamp_info( om, obj->ts );
ms_queue_put(f->outputs[0], om);
om = NULL;
break;
}
}
......@@ -172,6 +174,7 @@ static int filter_set_ptime(MSFilter *f, void *arg){
if( asked != 30 && asked != 60 ){
// use the closest
asked = (asked > 45)? 60 : 30;
ms_warning("iSAC doesn't handle %dms ptime, choosing closest: %dms", *(int*)arg, asked);
}
obj->ptime = asked;
......
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