meetecho / asterisk-opus

Opus (transcoding) and VP8 (passthrough) support for Asterisk, needed for a better WebRTC integration
GNU General Public License v2.0
77 stars 85 forks source link

Chopped audio when transcoding #9

Closed MayamaTakeshi closed 10 years ago

MayamaTakeshi commented 10 years ago

Hello, I successfully installed this patch. Using jitsi with only opus enabled, I can hear audio files (gsm) played by asterisk and they sound perfectly. However, when I make a call to PSTN (transcoding to/from G.711), I get very bad audio quality with chopped sound. Does anyone else see this issue or have any suggestions?

lminiero commented 10 years ago

Hi,

we haven't experienced this, actually, and transcoding is quite frequent as we mostly use this in association with ConfBridge. We sometime get garbled audio from some participants and not others, which seems to indicate, when it happens, decoding problems from Opus participants (e.g., too many lost packets and the decoder having problems sorting them out for good), but no transcoding issue.

Is the audio chopped for the PSTN user only, or also for the Opus user? Just for the sake of completeness, we recently added a way to make Opus encoding "lighter", as by default the highest complexity/quality is used which can make its usage quite heavy on the CPU, especially when several Opus users are being handled. You can do so adding a control in the encoder section, specifically:

 opus_encoder_ctl(opvt->opus, OPUS_SET_COMPLEXITY(NUM));

where num is any number between 1 (lowest complexity, lowest quality) and 10 (highest complexity, highest quality, currently the default). You may want to play a bit with this to check the best compromise for you.

MayamaTakeshi commented 10 years ago

Hi, thanks for the reply. I am getting bad audio quality at both sides.

I tried to add opus_encoder_ctl(opvt->opus, OPUS_SET_COMPLEXITY(1)); in opus_encoder_construct() but could not see any difference.

However, I am new to asterisk and i realized i could get access to a CLI doing 'asterisk -r' and in it I am seeing this when the call is answered at PSTN and transcoding starts:

[May 22 18:58:19] WARNING[2587][C-0000001c]: translate.c:352 framein: Out of buffer space [May 22 18:58:19] WARNING[2587][C-0000001c]: translate.c:352 framein: Out of buffer space [May 22 18:58:19] WARNING[2587][C-0000001c]: translate.c:352 framein: Out of buffer space [May 22 18:58:19] WARNING[2587][C-0000001c]: translate.c:352 framein: Out of buffer space [May 22 18:58:19] WARNING[2587][C-0000001c]: translate.c:352 framein: Out of buffer space [May 22 18:58:19] WARNING[2587][C-0000001c]: translate.c:352 framein: Out of buffer space

Checking the logs, i see these error related to confbridge: May 22 08:23:57 ipx029 asterisk[32281]: ERROR[32281]: config_options.c:512 in aco_process_config: Unable to load config file 'confbridge.conf' May 22 08:23:57 ipx029 asterisk[32281]: ERROR[32281]: app_confbridge.c:2856 in load_module: Unable to load config. Not loading module.

I don't think this is related because I am not using conferencing but in any case I will try to correct it to make sure it doesn't have anything to do with it.

lminiero commented 10 years ago

Is the same problem (especially the "Out of buffer space" warning) happening when transcoding PSTN calls to/from other codecs, e.g., Speex?

lminiero commented 10 years ago

You can also try increasing the BUFFER_SAMPLES value that is used in codec_opus.c, e.g., 16000 instead of 8000 (which will also increase the memory usage for each Opus session, though).

MayamaTakeshi commented 10 years ago

On Thu, May 22, 2014 at 7:38 PM, Lorenzo Miniero notifications@github.comwrote:

Is the same problem (especially the "Out of buffer space" warning) happening when transcoding PSTN calls to/from other codecs, e.g., Speex?

No. All other transcoding calls that i tested: speex - g.711 speex16 - g.711 gsm - g.711 ilbc - g.711 have good audio and don't produce these logs.

MayamaTakeshi commented 10 years ago

On Thu, May 22, 2014 at 7:42 PM, Lorenzo Miniero notifications@github.comwrote:

You can also try increasing the BUFFER_SAMPLES value that is used in codec_opus.c, e.g., 16000 instead of 8000 (which will also increase the memory usage for each Opus session, though).

Thanks. I am seeing something here. I could not solve the audio quality problem by increasing BUFFER_SAMPLES. I even tried to set it to 64000. However, the higher the value of BUFFER_SAMPLES, the more time it takes to "Out of buffer space" to start to show up. So it looks like part of the buffer is not being released after use, but part of it do gets freed because audio quality is bad but it keeps coming.

Also i noticed some warning when compiling codec_opus:

[root@ipx029 asterisk-11.1.2]# make make[1]: Entering directory /usr/local/src/asterisk-11.1.2' CC="cc" CXX="" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" makeopts make[2]: Entering directory/usr/local/src/asterisk-11.1.2/menuselect' make[2]: makeopts' is up to date. make[2]: Leaving directory/usr/local/src/asterisk-11.1.2/menuselect' Generating input for menuselect ... menuselect/menuselect --check-deps menuselect.makeopts Unknown value '@PBX_OPUS@' found in build_tools/menuselect-deps for OPUS Unknown value '' found in build_tools/menuselect-deps for NATIVE_ARCH menuselect/menuselect --check-deps menuselect.makeopts Unknown value '@PBX_OPUS@' found in build_tools/menuselect-deps for OPUS Unknown value '' found in build_tools/menuselect-deps for NATIVE_ARCH Generating embedded module rules ... [CC] codec_opus.c -> codec_opus.o [LD] codec_opus.o -> codec_opus.so make[1]: Leaving directory `/usr/local/src/asterisk-11.1.2'

Should i be worried about these?

Maybe I messed up my installation. I will try do do a clean build.

MayamaTakeshi commented 10 years ago

I did a clean build but the problem persists. And I still see the warnings from make:

[root@ipx029 asterisk-11.1.2]# make make[1]: Entering directory /usr/local/src/asterisk-11.1.2' CC="cc" CXX="" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" makeopts make[2]: Entering directory/usr/local/src/asterisk-11.1.2/menuselect' make[2]: makeopts' is up to date. make[2]: Leaving directory/usr/local/src/asterisk-11.1.2/menuselect' Generating input for menuselect ... menuselect/menuselect --check-deps menuselect.makeopts Unknown value '' found in build_tools/menuselect-deps for NATIVE_ARCH menuselect/menuselect --check-deps menuselect.makeopts
Unknown value '' found in build_tools/menuselect-deps for NATIVE_ARCH Generating embedded module rules ... [CC] codec_opus.c -> codec_opus.o [LD] codec_opus.o -> codec_opus.so make[1]: Leaving directory `/usr/local/src/asterisk-11.1.2' +--------- Asterisk Build Complete ---------+

I am using CentOS 5.4 and I installed opus 1.0.3-1.el5 using yum. So since there is already opus 1.1, i uninstalled opus 1.0.3 and installed 1.1 it from source, but nothing changed.

I will try to install this on ubuntu 12.04 to see if anything changes.

MayamaTakeshi commented 10 years ago

I was able to install asterisk on a VM using Ubuntu 12.04 x86_64 but I see the same symptoms, chopped audio and these logs when transcoding opus (other codecs are fine): [May 27 15:17:40] WARNING[19209][C-00000001]: translate.c:352 framein: Out of buffer space [May 27 15:17:40] WARNING[19209][C-00000001]: translate.c:352 framein: Out of buffer space [May 27 15:17:40] WARNING[19209][C-00000001]: translate.c:352 framein: Out of buffer space

The only difference I see is that now I don't have the warnings when compiling codec_opus: root@WEBUI-HO-PROXY-111:/usr/local/src/asterisk-11.1.2# make make[1]: Entering directory /usr/local/src/asterisk-11.1.2' CC="cc" CXX="" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" makeopts make[2]: Entering directory/usr/local/src/asterisk-11.1.2/menuselect' make[2]: makeopts' is up to date. make[2]: Leaving directory/usr/local/src/asterisk-11.1.2/menuselect' Generating input for menuselect ... menuselect/menuselect --check-deps menuselect.makeopts menuselect/menuselect --check-deps menuselect.makeopts
Generating embedded module rules ... [CC] codec_opus.c -> codec_opus.o [LD] codec_opus.o -> codec_opus.so make[1]: Leaving directory `/usr/local/src/asterisk-11.1.2' +--------- Asterisk Build Complete ---------+

(However, i undestand the reason for this is that I had to disable BUILD_NATIVE in the menuconfig since this is a VM).

But nothing else improved.

lminiero commented 10 years ago

Hi,

as I anticipated, I've never been able to replicate these issues, so it may be something related to the way the G.711 source sends its frames. Is the ptime different than 20ms, for instance?

Have you tried one of the forks of this patch, maybe some that have been adapted to different Asterisk versions to see if those work for you instead?

MayamaTakeshi commented 10 years ago

Hello, ptime is fine. The PSTN gateway agrees to ptime=20:

v=0 o=GANG 0 1 IN IP4 192.168.89.131 s=- c=IN IP4 192.168.89.131 t=0 0 m=audio 28968 RTP/AVP 8 101 a=ptime:20 a=sendrecv a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15

I will try the forks. Thanks for your time.

MayamaTakeshi commented 10 years ago

I forgot to close this ticket (not an issue in this project).

zivsegal commented 10 years ago

@MayamaTakeshi, did you fix this issue? If so, can you please explain how? We are witnessing the same issues.

After some debugging, I also feel there is an issue with opus<==>g.711 transcoding.

MayamaTakeshi commented 9 years ago

@zivsegal, sorry for the very late reply. I only saw your post today. No, I didn't solve this problem. I tried the other forks but they showed the same problem and my manager decided to not pursuit opus because of some other issues at the mobile sip phone side.