From b26f3306625fe3f97d730c256cbb9b0722242a5b Mon Sep 17 00:00:00 2001 From: Christian Hoene Date: Fri, 6 May 2016 19:22:44 +0200 Subject: Some minor issues --- modules/mpa/decode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/mpa/decode.c') diff --git a/modules/mpa/decode.c b/modules/mpa/decode.c index d62bd60..5554d25 100644 --- a/modules/mpa/decode.c +++ b/modules/mpa/decode.c @@ -108,7 +108,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, const uint8_t *buf, size_t len) { - int result, channels, encoding, i; + int result, channels, encoding, i, result2; long samplerate; size_t n; spx_uint32_t intermediate_len; @@ -131,10 +131,10 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, intermediate_len = n / 2 / ads->channels; /* intermediate_len counts samples per channel */ out_len = *sampc; - result=speex_resampler_process_interleaved_int( + result2=speex_resampler_process_interleaved_int( ads->resampler, ads->intermediate_buffer, &intermediate_len, sampv, &out_len); - if (result!=RESAMPLER_ERR_SUCCESS) { + if (result2!=RESAMPLER_ERR_SUCCESS) { error("mpa: upsample error: %s %d %d\n", strerror(result), out_len, *sampc/2); return EPROTO; -- cgit v1.2.3 From 5fd811194ffa1f3c3a37ec9a0b32232bfc39b25d Mon Sep 17 00:00:00 2001 From: Christian Hoene Date: Wed, 11 May 2016 14:37:31 +0200 Subject: Rewrote decoding, fixed memory leaks, add cr to print outs --- modules/mpa/decode.c | 97 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 41 deletions(-) (limited to 'modules/mpa/decode.c') diff --git a/modules/mpa/decode.c b/modules/mpa/decode.c index 5554d25..e862a1e 100644 --- a/modules/mpa/decode.c +++ b/modules/mpa/decode.c @@ -24,6 +24,9 @@ static void destructor(void *arg) { struct audec_state *ads = arg; + if(ads->resampler) + speex_resampler_destroy(ads->resampler); + mpg123_close(ads->dec); mpg123_delete(ads->dec); #ifdef DEBUG @@ -71,7 +74,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, result = mpg123_param(ads->dec, MPG123_VERBOSE, 0, 0.); #endif if (result != MPG123_OK) { - error("MPA libmpg123 param error %s", + error("MPA libmpg123 param error %s\n", mpg123_plain_strerror(result)); err = EINVAL; goto out; @@ -80,7 +83,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, result = mpg123_format_all(ads->dec); if (result != MPG123_OK) { - error("MPA libmpg123 format error %s", + error("MPA libmpg123 format error %s\n", mpg123_plain_strerror(result)); err = EINVAL; goto out; @@ -88,7 +91,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, result = mpg123_open_feed(ads->dec); if (result != MPG123_OK) { - error("MPA libmpg123 open feed error %s", + error("MPA libmpg123 open feed error %s\n", mpg123_plain_strerror(result)); err = EINVAL; goto out; @@ -108,12 +111,16 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, const uint8_t *buf, size_t len) { - int result, channels, encoding, i, result2; + int result, channels, encoding, i; long samplerate; size_t n; spx_uint32_t intermediate_len; spx_uint32_t out_len; +#ifdef DEBUG + info("mpa decode start %d %ld\n",len, *sampc); +#endif + if (!ads || !sampv || !sampc || !buf || len<=4) return EINVAL; @@ -123,46 +130,16 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, return EPROTO; } - if (ads->resampler) { + n = 0; result = mpg123_decode(ads->dec, buf+4, len-4, (unsigned char*)ads->intermediate_buffer, sizeof(ads->intermediate_buffer), &n); /* n counts bytes */ - intermediate_len = n / 2 / ads->channels; - /* intermediate_len counts samples per channel */ - out_len = *sampc; - result2=speex_resampler_process_interleaved_int( - ads->resampler, ads->intermediate_buffer, - &intermediate_len, sampv, &out_len); - if (result2!=RESAMPLER_ERR_SUCCESS) { - error("mpa: upsample error: %s %d %d\n", - strerror(result), out_len, *sampc/2); - return EPROTO; - } -#ifdef DEBUG - info("mpa decode %d %d %d %d\n",intermediate_len,*sampc, - out_len,n); -#endif - *sampc = out_len * ads->channels; - } - else { - result = mpg123_decode(ads->dec, buf+4, len-4, - (unsigned char*)sampv, *sampc*2, &n); + #ifdef DEBUG - info("mpa decode %d %d\n",*sampc,n); + info("mpa decoded %d %d %d %d\n",result, len-4, n, ads->channels); #endif - *sampc = n / 2; - } - if (ads->start<100) { /* mpg123 needs some to sync */ - ads->start++; - *sampc=0; - } - if (ads->channels==1) { - for (i=*sampc-1;i>=0;i--) - sampv[i+i+1]=sampv[i+i]=sampv[i]; - *sampc *= 2; - } if (result == MPG123_NEW_FORMAT) { mpg123_getformat(ads->dec, &samplerate, &channels, &encoding); @@ -171,6 +148,8 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, ads->channels = channels; ads->start = 0; + if(ads->resampler) + speex_resampler_destroy(ads->resampler); if (samplerate != 48000) { ads->resampler = speex_resampler_init(channels, samplerate, 48000, 3, &result); @@ -183,17 +162,53 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, else ads->resampler = NULL; } - else if (result == MPG123_NEED_MORE) - return 0; + else if (result == MPG123_NEED_MORE) ; +// return 0; else if (result != MPG123_OK) { - error("MPA libmpg123 feed error %d %s", result, + error("MPA libmpg123 feed error %d %s\n", result, mpg123_plain_strerror(result)); return EPROTO; } + if (ads->resampler) { + intermediate_len = n / 2 / ads->channels; + /* intermediate_len counts samples per channel */ + out_len = *sampc / 2; + + result=speex_resampler_process_interleaved_int( + ads->resampler, ads->intermediate_buffer, + &intermediate_len, sampv, &out_len); + if (result!=RESAMPLER_ERR_SUCCESS) { + error("mpa: upsample error: %s %d %d\n", + strerror(result), out_len, *sampc/2); + return EPROTO; + } + if (ads->channels==1) { + for (i=out_len-1;i>=0;i--) + sampv[i+i+1]=sampv[i+i]=sampv[i]; + *sampc = out_len * 2; + } + else + *sampc = out_len * ads->channels; + } + else { + n /= 2; + if(ads->channels!=1) { + for(i=0;(unsigned)iintermediate_buffer[i]; + *sampc = n; + } + else { + for(i=0;(unsigned)iintermediate_buffer[i]; + *sampc = n * 2; + } + #ifdef DEBUG - debug("mpa decode %d %d %d\n",*sampc,len,n); + info("mpa decode done %d\n",*sampc); #endif + } + return 0; } -- cgit v1.2.3 From a2713e0da4a884373b42b5d6672101c61bf443d2 Mon Sep 17 00:00:00 2001 From: Christian Hoene Date: Thu, 12 May 2016 11:24:25 +0200 Subject: debug output pretty print --- modules/mpa/decode.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'modules/mpa/decode.c') diff --git a/modules/mpa/decode.c b/modules/mpa/decode.c index e862a1e..6ad1ffb 100644 --- a/modules/mpa/decode.c +++ b/modules/mpa/decode.c @@ -30,7 +30,7 @@ static void destructor(void *arg) mpg123_close(ads->dec); mpg123_delete(ads->dec); #ifdef DEBUG - debug("mpa: decoder destroyed\n"); + debug("MPA dec destroyed\n"); #endif } @@ -47,7 +47,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, ads = *adsp; #ifdef DEBUG - debug("mpa: decoder created %s\n",fmtp); + debug("MPA dec created %s\n",fmtp); #endif if (ads) @@ -73,8 +73,8 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, #else result = mpg123_param(ads->dec, MPG123_VERBOSE, 0, 0.); #endif - if (result != MPG123_OK) { - error("MPA libmpg123 param error %s\n", + if ( result != MPG123_OK) { + error("MPA dec param error %s\n", mpg123_plain_strerror(result)); err = EINVAL; goto out; @@ -82,16 +82,16 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, result = mpg123_format_all(ads->dec); - if (result != MPG123_OK) { - error("MPA libmpg123 format error %s\n", + if ( result != MPG123_OK) { + error("MPA dec format error %s\n", mpg123_plain_strerror(result)); err = EINVAL; goto out; } result = mpg123_open_feed(ads->dec); - if (result != MPG123_OK) { - error("MPA libmpg123 open feed error %s\n", + if ( result != MPG123_OK) { + error("MPA dec open feed error %s\n", mpg123_plain_strerror(result)); err = EINVAL; goto out; @@ -118,32 +118,32 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, spx_uint32_t out_len; #ifdef DEBUG - info("mpa decode start %d %ld\n",len, *sampc); + debug("MPA dec start %d %ld\n",len, *sampc); #endif if (!ads || !sampv || !sampc || !buf || len<=4) return EINVAL; if(*(uint32_t*)buf != 0) { - error("MPA header is not zero %08X, not supported yet\n", + error("MPA dec header is not zero %08X, not supported yet\n", *(uint32_t*)buf); return EPROTO; } - n = 0; - result = mpg123_decode(ads->dec, buf+4, len-4, + n = 0; + result = mpg123_decode(ads->dec, buf+4, len-4, (unsigned char*)ads->intermediate_buffer, sizeof(ads->intermediate_buffer), &n); /* n counts bytes */ #ifdef DEBUG - info("mpa decoded %d %d %d %d\n",result, len-4, n, ads->channels); + debug("MPA dec %d %d %d %d\n",result, len-4, n, ads->channels); #endif if (result == MPG123_NEW_FORMAT) { mpg123_getformat(ads->dec, &samplerate, &channels, &encoding); - info("MPA libmpg123 format change %d %d %04X\n",samplerate + info("MPA dec format change %d %d %04X\n",samplerate ,channels,encoding); ads->channels = channels; @@ -155,17 +155,17 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, samplerate, 48000, 3, &result); if (result!=RESAMPLER_ERR_SUCCESS || ads->resampler==NULL) { - error("mpa: upsampler failed %d\n",result); + error("MPA dec upsampler failed %d\n",result); return EINVAL; } } else ads->resampler = NULL; } - else if (result == MPG123_NEED_MORE) ; -// return 0; + else if (result == MPG123_NEED_MORE) + ; /* workaround: do nothing */ else if (result != MPG123_OK) { - error("MPA libmpg123 feed error %d %s\n", result, + error("MPA dec feed error %d %s\n", result, mpg123_plain_strerror(result)); return EPROTO; } @@ -179,7 +179,7 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, ads->resampler, ads->intermediate_buffer, &intermediate_len, sampv, &out_len); if (result!=RESAMPLER_ERR_SUCCESS) { - error("mpa: upsample error: %s %d %d\n", + error("MPA dec upsample error: %s %d %d\n", strerror(result), out_len, *sampc/2); return EPROTO; } @@ -205,7 +205,7 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, } #ifdef DEBUG - info("mpa decode done %d\n",*sampc); + debug("MPA dec done %d\n",*sampc); #endif } -- cgit v1.2.3 From 5a7c10a7242805c1649c13453a68307bfff8f7b1 Mon Sep 17 00:00:00 2001 From: Christian Hoene Date: Thu, 12 May 2016 11:40:40 +0200 Subject: Considered ccheck hints --- modules/mpa/decode.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules/mpa/decode.c') diff --git a/modules/mpa/decode.c b/modules/mpa/decode.c index 6ad1ffb..c45bbf6 100644 --- a/modules/mpa/decode.c +++ b/modules/mpa/decode.c @@ -24,7 +24,7 @@ static void destructor(void *arg) { struct audec_state *ads = arg; - if(ads->resampler) + if (ads->resampler) speex_resampler_destroy(ads->resampler); mpg123_close(ads->dec); @@ -73,7 +73,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, #else result = mpg123_param(ads->dec, MPG123_VERBOSE, 0, 0.); #endif - if ( result != MPG123_OK) { + if (result != MPG123_OK) { error("MPA dec param error %s\n", mpg123_plain_strerror(result)); err = EINVAL; @@ -82,7 +82,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, result = mpg123_format_all(ads->dec); - if ( result != MPG123_OK) { + if (result != MPG123_OK) { error("MPA dec format error %s\n", mpg123_plain_strerror(result)); err = EINVAL; @@ -90,7 +90,7 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac, } result = mpg123_open_feed(ads->dec); - if ( result != MPG123_OK) { + if (result != MPG123_OK) { error("MPA dec open feed error %s\n", mpg123_plain_strerror(result)); err = EINVAL; @@ -124,7 +124,7 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, if (!ads || !sampv || !sampc || !buf || len<=4) return EINVAL; - if(*(uint32_t*)buf != 0) { + if (*(uint32_t*)buf != 0) { error("MPA dec header is not zero %08X, not supported yet\n", *(uint32_t*)buf); return EPROTO; @@ -148,7 +148,7 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, ads->channels = channels; ads->start = 0; - if(ads->resampler) + if (ads->resampler) speex_resampler_destroy(ads->resampler); if (samplerate != 48000) { ads->resampler = speex_resampler_init(channels, -- cgit v1.2.3 From 0ae298b7c56183b15547141865ccb87d8889e442 Mon Sep 17 00:00:00 2001 From: Christian Hoene Date: Sat, 14 May 2016 12:45:49 +0200 Subject: minor nicify --- modules/mpa/decode.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'modules/mpa/decode.c') diff --git a/modules/mpa/decode.c b/modules/mpa/decode.c index c45bbf6..3a1c0a2 100644 --- a/modules/mpa/decode.c +++ b/modules/mpa/decode.c @@ -162,8 +162,8 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, else ads->resampler = NULL; } - else if (result == MPG123_NEED_MORE) - ; /* workaround: do nothing */ + else if (result == MPG123_NEED_MORE) + ; /* workaround: do nothing */ else if (result != MPG123_OK) { error("MPA dec feed error %d %s\n", result, mpg123_plain_strerror(result)); @@ -174,7 +174,7 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, intermediate_len = n / 2 / ads->channels; /* intermediate_len counts samples per channel */ out_len = *sampc / 2; - + result=speex_resampler_process_interleaved_int( ads->resampler, ads->intermediate_buffer, &intermediate_len, sampv, &out_len); @@ -193,14 +193,15 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc, } else { n /= 2; - if(ads->channels!=1) { - for(i=0;(unsigned)ichannels!=1) { + for (i=0;(unsigned)iintermediate_buffer[i]; *sampc = n; } else { - for(i=0;(unsigned)iintermediate_buffer[i]; + for (i=0;(unsigned)iintermediate_buffer[i]; *sampc = n * 2; } -- cgit v1.2.3