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

How do I get OPUS to sample at higher than 8kHz? #14

Closed bennnjamin closed 9 years ago

bennnjamin commented 9 years ago

From what I can tell, asterisk is operating Opus at 8kHz instead of varying the sample rate/bitrate even when there is plenty of bandwidth. I'm using a SIP client on a phone, connecting directly to my Asterisk server and I'm simply making an inbound connection (no call outside to a cell phone or anything that would use another 8k codec). When I do huge debug I see:

[Opus] [Decoder #14 (8000)] 960 samples, 281 bytes [Opus] [Decoder #14 (8000)] >> Got 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] >> Got 960 samples, 6 bytes [Opus] [Decoder #14 (8000)] 960 samples, 281 bytes [Opus] [Decoder #14 (8000)] >> Got 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] >> Got 960 samples, 6 bytes [Opus] [Decoder #14 (8000)] 960 samples, 281 bytes [Opus] [Decoder #14 (8000)] >> Got 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] >> Got 960 samples, 6 bytes [Opus] [Decoder #14 (8000)] 960 samples, 281 bytes [Opus] [Decoder #14 (8000)] >> Got 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] >> Got 960 samples, 6 bytes [Opus] [Decoder #14 (8000)] 960 samples, 281 bytes [Opus] [Decoder #14 (8000)] >> Got 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] >> Got 960 samples, 6 bytes [Opus] [Decoder #14 (8000)] 960 samples, 281 bytes [Opus] [Decoder #14 (8000)] >> Got 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] 160 samples, 320 bytes [Opus] [Encoder #17 (8000)] >> Got 960 samples, 6 bytes\

How can I get Opus to encode & decode at 48kHz?

lminiero commented 9 years ago

The reason for this is that we create the encoder/decoder contexts according to what we're going to bridge to. If you're going to dial to a GSM encoded call, there's no benefit in exploiting the 48kHz range of Opus, as the other peer will only get and originate 8kHz samples anyway. The Opus context in Asterisk as such is automatically capped at the advertized sampling of the other peer: for instance, if you call or get called by a wideband Speex user, the context will be 16kHz. At the same time, if you configure, for instance, a ConfBridge profile of 48kHz, that's what will be created Opus-wise.

As such, the 8kHz you see there are necessarily the result of something that constraints the sampling rate to the narrowband context you get.

bennnjamin commented 9 years ago

Thank you for your quick response. I'm using a really simple dialplan to just test the 48kHz range because ultimately I will be bridging two clients using Opus exclusively. Right now it looks like this:

  1. SIP Client using Opus connects to server
  2. Meetme()
  3. MixMonitor()
  4. StopMixMonitor on hangup()

I have read that these Applications used to be limited to narrowband but have since been patched to support wideband. I have also tried this dialplan without Meetme() and it still is recording in 8kHz.

lminiero commented 9 years ago

AFAIK MeetMe only supports narrowband. If you try with ConfBridge you'll be able to specify the mix sampling rate in the bridge profile. MixMonitor may be requesting slin (8kHz) frames as well to record a narrowband wav. Not sure how you can configure that to behave differently.

bennnjamin commented 9 years ago

I was literally just typing a reply to say that I tested with ConfBridge! I did verify that it's encoded and decoded at 48kHz, thanks! Now I'm not sure if you can help with this but the when I set it to record the conference it still downsamples the file to 8kHz, even though I've requested an internal sample rate of 48kHz. If this is beyond the scope of this Opus project I understand but you've been very helpful so far.

lminiero commented 9 years ago

Yes, this is something that needs to be configured in Asterisk: the Opus codec just creates the context it is asked. Not sure if you can actually configure the sampling rate of recordings in ConfBridge, though: you may have to look in the code there to see what is passed to MixMonitor.

Closing the issue as it's not an issue in the module.