opus icon indicating copy to clipboard operation
opus copied to clipboard

OPUS_GET_BITRATE always returns default value for opus_multistream_encoder

Open Spacechild1 opened this issue 5 years ago • 2 comments

When I call the OPUS_GET_BITRATE control on a multistream encoder, it always returns the default value, e.g. 144000 for 2 channels at 48 kHz

int32_t bitrate = 64000; // could also be OPUS_BITRATE_MAX

opus_multistream_encoder_ctl(state, OPUS_SET_BITRATE(bitrate));

 // always returns the default...
opus_multistream_encoder_ctl(state, OPUS_GET_BITRATE(&bitrate));

other controls like OPUS_GET_COMPLEXITY or OPUS_GET_SIGNAL work as expected.

Here's the reason:

opus_multistream_encoder has a dedicated field bitrate_bps and OPUS_SET_BITRATE sets it as expected. OPUS_GET_BITRATE, however, internally calls opus_encoder_ctl on the sub-states, which gets the value of user_bitrate_bps. Since the latter is initialized to OPUS_AUTO and never overriden, it would always return the value of the default bitrate.

Not sure what's the best approach to fix this...

Spacechild1 avatar Apr 25 '20 16:04 Spacechild1

I can reproduce this, so it's not just you. The function itself appears correct, but somehow the allocation isn't being propagated to all the channels.

It looks like there's no test converage of the multistream encoder api, so not surprising it's broken.

Thanks for the report. I'll try to investigate over the coming week if no one beats me to it.

rillian avatar Apr 27 '20 06:04 rillian

Oh, I didn't notice your edit. Thanks for investigating further. That sounds about right.

Step one, write some tests!

rillian avatar Apr 27 '20 06:04 rillian