{"record":{"id":"796958e99a568821","repo":"DrKLO/Telegram","slug":"failed-to-initialize-decoder-796958","errorCode":null,"errorMessage":"Failed to initialize decoder","messagePattern":"Failed to initialize decoder","errorType":"exception","errorClass":"OpusDecoderException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoder.java","lineNumber":137,"sourceCode":"        throw new OpusDecoderException(\"Invalid header, missing stream map\");\n      }\n      numStreams = 1;\n      numCoupled = (channelCount == 2) ? 1 : 0;\n      streamMap[0] = 0;\n      streamMap[1] = 1;\n    } else {\n      if (headerBytes.length < 21 + channelCount) {\n        throw new OpusDecoderException(\"Invalid header length\");\n      }\n      // Read the channel mapping.\n      numStreams = headerBytes[19] & 0xFF;\n      numCoupled = headerBytes[20] & 0xFF;\n      System.arraycopy(headerBytes, 21, streamMap, 0, channelCount);\n    }\n    nativeDecoderContext =\n        opusInit(SAMPLE_RATE, channelCount, numStreams, numCoupled, gain, streamMap);\n    if (nativeDecoderContext == 0) {\n      throw new OpusDecoderException(\"Failed to initialize decoder\");\n    }\n    setInitialInputBufferSize(initialInputBufferSize);\n\n    this.outputFloat = outputFloat;\n    if (outputFloat) {\n      opusSetFloatOutput();\n    }\n  }\n\n  /**\n   * Sets whether discard padding is enabled. When enabled, discard padding samples (provided as\n   * supplemental data on the input buffer) will be removed from the end of the decoder output.\n   *\n   * <p>This method is experimental, and will be renamed or removed in a future release.\n   */\n  public void experimentalSetDiscardPaddingEnabled(boolean enabled) {\n    this.experimentalDiscardPaddingEnabled = enabled;\n  }","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoder.java#L119-L155","documentation":"After all Java-side validation, opusInit (a native JNI call wrapping opus_multistream_decoder_init) must return a non-zero decoder context. A return value of 0 means the native libopus failed to initialize the multistream decoder. The Java checks passed but libopus itself rejected the parameters (numStreams/numCoupled/streamMap inconsistent with channelCount, an unsupported configuration, or a native/memory failure).","triggerScenarios":"opusInit returns 0 - typically because numStreams and numCoupled are inconsistent with channelCount, the stream map is invalid, or the native library hit an allocation/version error.","commonSituations":"A header that passes the shallow Java validation but is internally inconsistent (e.g. a hand-crafted stream map); a native libopus build/version mismatch; low-memory conditions on the native heap.","solutions":["Validate the full Opus header (mapping family, numStreams, numCoupled, stream map) against RFC 7845 before constructing the decoder.","Ensure the bundled native libopus version matches the JNI wrapper and is loaded correctly.","Provide a fallback audio renderer so playback degrades gracefully when Opus init fails."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  decoder = new OpusDecoder(..., format.initializationData, cryptoConfig, outputFloat);\n} catch (OpusDecoderException e) {\n  if (e.getMessage().equals(\"Failed to initialize decoder\")) {\n    // native init failed: fall back to the platform Opus decoder / another renderer\n    decoder = null;\n  } else { throw e; }\n}","preventionTips":["Validate the full Opus header (mapping family, numStreams, numCoupled, stream map) against RFC 7845 upstream.","Keep the native libopus build version in sync with the JNI wrapper.","Register a fallback audio renderer so a native init failure degrades playback rather than aborting."],"tags":["opus","decoder","native","exoplayer","audio"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}