{"record":{"id":"c17321edb91dac77","repo":"DrKLO/Telegram","slug":"unexpected-audio-encoding-encoding","errorCode":null,"errorMessage":"Unexpected audio encoding: {encoding}","messagePattern":"Unexpected audio encoding: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java","lineNumber":1797,"sourceCode":"      case C.ENCODING_DOLBY_TRUEHD:\n        int syncframeOffset = Ac3Util.findTrueHdSyncframeOffset(buffer);\n        return syncframeOffset == C.INDEX_UNSET\n            ? 0\n            : (Ac3Util.parseTrueHdSyncframeAudioSampleCount(buffer, syncframeOffset)\n                * Ac3Util.TRUEHD_RECHUNK_SAMPLE_COUNT);\n      case C.ENCODING_OPUS:\n        return OpusUtil.parsePacketAudioSampleCount(buffer);\n      case C.ENCODING_PCM_16BIT:\n      case C.ENCODING_PCM_16BIT_BIG_ENDIAN:\n      case C.ENCODING_PCM_24BIT:\n      case C.ENCODING_PCM_32BIT:\n      case C.ENCODING_PCM_8BIT:\n      case C.ENCODING_PCM_FLOAT:\n      case C.ENCODING_AAC_ER_BSAC:\n      case C.ENCODING_INVALID:\n      case Format.NO_VALUE:\n      default:\n        throw new IllegalStateException(\"Unexpected audio encoding: \" + encoding);\n    }\n  }\n\n  @RequiresApi(21)\n  private static int writeNonBlockingV21(AudioTrack audioTrack, ByteBuffer buffer, int size) {\n    return audioTrack.write(buffer, size, AudioTrack.WRITE_NON_BLOCKING);\n  }\n\n  @RequiresApi(21)\n  private int writeNonBlockingWithAvSyncV21(\n      AudioTrack audioTrack, ByteBuffer buffer, int size, long presentationTimeUs) {\n    if (Util.SDK_INT >= 26) {\n      // The underlying platform AudioTrack writes AV sync headers directly.\n      return audioTrack.write(\n          buffer, size, AudioTrack.WRITE_NON_BLOCKING, presentationTimeUs * 1000);\n    }\n    if (avSyncHeader == null) {\n      avSyncHeader = ByteBuffer.allocate(16);","sourceCodeStart":1779,"sourceCodeEnd":1815,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java#L1779-L1815","documentation":"DefaultAudioSink.getMediaDurationUsForPresenterTimeUs (the per-encoding switch over `encoding`) throws IllegalStateException('Unexpected audio encoding') when the encoding is not one of the handled compressed encodings (e.g. AC3/E-AC3/AC4/DTS/DTS_HD/TrueHD/Opus) nor the explicitly-listed PCM/INVALID/NO_VALUE cases that fall to default. It indicates the sink reached this code path with an encoding the duration calculation does not cover.","triggerScenarios":"Computing media duration for a presenter time when outputEncoding is a compressed or PCM encoding not enumerated in the switch (or an unrecognized int), so control hits the default branch.","commonSituations":"Adding support for a new encoding without extending the switch; passing a passthrough encoding the helper never expected; an internal state where outputEncoding was left as an unmapped value.","solutions":["Ensure the encoding reaching this path is one enumerated in the switch (extend the switch if you added a new supported encoding).","Avoid requesting presenter-time media duration for unsupported encodings; guard callers before invoking the helper.","Upgrade ExoPlayer — newer versions add cases for encodings missing in older releases."],"exampleFix":"// before\nswitch (encoding) { /* no case for ENCODING_DOLBY_TRUEHD -> default throws */ }\n\n// after\nswitch (encoding) {\n  case C.ENCODING_DOLBY_TRUEHD:\n    return Ac3Util.parseTrueHdSyncframeAudioSampleCount(buffer);\n  // ...\n}","handlingStrategy":"validation","validationCode":"// n/a: internal switch; callers should avoid unsupported encodings reaching this path\n// ensure outputEncoding is a value enumerated in getMediaDurationUsForPresenterTimeUs","typeGuard":null,"tryCatchPattern":"// not generally catchable — IllegalStateException signals a library bug or unsupported encoding;\n// upgrade ExoPlayer or restrict the encodings you feed the sink.","preventionTips":["Keep ExoPlayer up to date so new encodings have switch cases.","Do not introduce custom encodings without extending the switch.","Report the encoding value in any crash to confirm coverage."],"tags":["audio","exoplayer","illegal-state","encoding","internal"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}