Issue Description
The audio codec 8 fails to remain active despite being configured via the SDK. The system automatically reverts to codec 122 during the media transmission phase. This issue typically manifests as an intermittent or consistent fallback during the initial handshake, even if the developer utilized the correct parameter strings.
Platform/SDK
Operating System: Android
SDK: Agora RTC SDK
Error Message
Engineers should search for the following message in the SDK log to confirm the occurrence of this issue:
Audio Codec negotiation: switch codec from 8 to 122
Root Cause
The configuration system within the SDK distinguishes between global-level and connection-level parameters. The audio codec fallback mechanism is governed by a global strategy.
When a new connection is initiated during the joinChannel process, it triggers an internal init_global sequence. This sequence attempts to inherit configuration values from the global storage path. If the codec parameters are defined after the connection has already started its negotiation, the inheritance fails to apply in time. Consequently, the media engine utilizes the default system codec 122 to ensure immediate connectivity, ignoring the late-arriving custom request.
Step-to-Step Solution
-
Enforce Strict Call Sequencing
Instruct the developer to invoke the setParameters or setParametersEx method exclusively before the execution of the
joinChannelcommand. Setting parameters at the engine initialization stage ensures that the configuration is written to the global path before any media sessions are instantiated. -
Example configuration (before channel join):
{ "che.audio.codec_unfallback":[0,8,9], "che.audio.custom_payload_type":8 }Applying these parameters globally ensures that codec 8 remains active and is not replaced by codec 122 during negotiation. In this payload, the value 8 represents G711 and 9 represents G722. By including these in the unfallback list, the SDK is instructed to treat these codecs as mandatory during negotiation.
-
Verify Parameter Scope and Priority
If the issue persists, verify that the application is not calling connection-level overrides that might conflict with the global setting.
Checklist for New Private Parameters
When assisting developers with similar private parameter integrations, confirm the following points:
The parameter key is defined in the global path.
The call is made prior to the connection lifecycle start.
Best Practice
By aligning the parameter configuration with the SDK initialization sequence, every subsequent connection will inherit the locked codec settings. This prevents the switch to codec 122 and ensures that the media stream utilizes the intended G711 or G722 protocol for interoperability with specialized hardware.