[jitsi-dev] [libjitsi] Opus codec ignores bitrate settings (#41)


#1

http://lists.jitsi.org/pipermail/users/2014-June/007435.html

I've tried to stream audio to a SIP Account with the opus codec. Setting: 128 Kpbs.
I've started the connection and it works, but the upstream was only at 40 Kbps and not at 128 Kbps like configured.

(Issue migrated from https://trac.jitsi.org/ticket/1293)
![image](https://cloud.githubusercontent.com/assets/4939753/7005028/1be33292-dc74-11e4-8e1f-0a876ef6bf31.png)

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41


#2

I can confirm this issue is present with all of Linux, Windows, and Android versions of jitsi. If someone can point me to the involved parts of the code I may be able to at least have a look at what is going wrong here.

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-90070483


#3

We initialize the encoder here: https://github.com/jitsi/libjitsi/blob/master/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIEncoder.java#L246

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-90070808


#4

Did someone already enable debug log and check if the used value is correct in the following output?
```java
logger.debug(
"Encoder settings: audio bandwidth " + bw + ", bitrate "
+ Opus.encoder_get_bitrate(encoder) + ", DTX "
+ Opus.encoder_get_dtx(encoder) + ", FEC "
+ Opus.encoder_get_inband_fec(encoder));

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-162445502


#5

Yes, I checked that and it was correct.

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-162598819


#6

Ok so its strange because you can see the log information tries to ask Opus itself to report the bitrate. Jitsi cannot do more than to ask for the bitrate in setup and then check if it has been set. If the codec itself ignores the request somehow we cannot know at the moment Im afraid. It would need some more testing of the used Opus lib and whats going wrong there.

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-162817911


#7

Boris, I also wrote you a mail...
I think I found the Opus issue... look in the JNIEncoder.java into this function setFormatParameters... there maxaveragebitrate is used to set the bitrate, if any supplied userbitrate is higher:

```
/**
     * Sets the format parameters.

···

*
     * @param fmtps the format parameters to set
     */
    @Override
    public void setFormatParameters(Map<String, String> fmtps)
    {
        if (logger.isDebugEnabled())
            logger.debug("Setting format parameters: " + fmtps);

        /*
         * TODO Use the default value for maxaveragebitrate as defined at
         * http://tools.ietf.org/html/draft-spittka-payload-rtp-opus-02#section-6.1
         */
        int maxaveragebitrate = 40000;

        try
        {
            String s = fmtps.get("maxaveragebitrate");

            if ((s != null) && (s.length() != 0))
                maxaveragebitrate = Integer.parseInt(s);
        }
        catch (Exception e)
        {
            // Ignore and fall back to the default value.
        }
        Opus.encoder_set_bitrate(
                encoder,
                (maxaveragebitrate < bitrate) ? maxaveragebitrate : bitrate);
```

Can it be that this function runs after the initial setup, thereby limiting the encoder to 40kbps as the user wrote? Im sorry I icant test this, I have no Java environment here

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-176428673


#8

Absolutely, this looks like its the problem! Thank you for posting it (I have not received an email from you).

I just pushed [a fix](https://github.com/jitsi/libjitsi/commit/c76e4357eccc413f0b5120baac658c0e72e99a8d). Unfortunately because of [this issue](https://github.com/jitsi/jitsi/issues/193) I haven't tested it with Jitsi, and I don't know when it will land there.

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-176435381


#9

You are welcome. By the way I dont get the point of having maxaveragebitrate and bitrate in this code. Why is this necessary? `(maxaveragebitrate < bitrate) ? maxaveragebitrate : bitrate);`

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-176975748


#10

maxaveragebitrate comes from the remote side. We honor it by not exceeding it, but we shouldn't increase our sending bitrate just because the remote side reported that they can handle it. In practice, if the remote side is Jitsi, maxaveragebitrate isn't included.

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-176991179


#11

Can I already test this in nightly?

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-180992574


#12

Not in the Jitsi nightlies. As Boris said, this will take quite some time.

···

---
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#issuecomment-181096839


#13

Closed #41.

···

--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jitsi/libjitsi/issues/41#event-1048984277