DrKLO/Telegram · error · UnhandledAudioFormatException

Unhandled format: {inputAudioFormat}

Error message

Unhandled format: {inputAudioFormat}

What it means

TrimmingAudioProcessor.onConfigure rejects any input AudioFormat whose encoding is not the processor's OUTPUT_ENCODING (16-bit PCM). It throws UnhandledAudioFormatException to signal that the processor can only be inserted into a PCM-16-bit audio pipeline. The check happens before any reconfiguration is applied, so the processor never silently drops data of an incompatible type.

Source

Thrown at TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/TrimmingAudioProcessor.java:76

  /** Sets the trimmed frame count returned by {@link #getTrimmedFrameCount()} to zero. */
  public void resetTrimmedFrameCount() {
    trimmedFrameCount = 0;
  }

  /**
   * Returns the number of audio frames trimmed since the last call to {@link
   * #resetTrimmedFrameCount()}.
   */
  public long getTrimmedFrameCount() {
    return trimmedFrameCount;
  }

  @Override
  public AudioFormat onConfigure(AudioFormat inputAudioFormat)
      throws UnhandledAudioFormatException {
    if (inputAudioFormat.encoding != OUTPUT_ENCODING) {
      throw new UnhandledAudioFormatException(inputAudioFormat);
    }
    reconfigurationPending = true;
    return trimStartFrames != 0 || trimEndFrames != 0 ? inputAudioFormat : AudioFormat.NOT_SET;
  }

  @Override
  public void queueInput(ByteBuffer inputBuffer) {
    int position = inputBuffer.position();
    int limit = inputBuffer.limit();
    int remaining = limit - position;

    if (remaining == 0) {
      return;
    }

    // Trim any pending start bytes from the input buffer.
    int trimBytes = min(remaining, pendingTrimStartBytes);
    trimmedFrameCount += trimBytes / inputAudioFormat.bytesPerFrame;

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Feed only 16-bit PCM audio into TrimmingAudioProcessor, or insert a format-converting processor upstream so the encoding reaching it is ENCODING_PCM_16BIT.
  2. Verify the input AudioFormat.encoding equals the processor's OUTPUT_ENCODING before adding the processor to the AudioProcessor chain.
  3. Skip trimming when the pipeline uses float/high-bit-depth PCM and trim is not strictly required.

Example fix

// before
sink.addAudioProcessor(trimmingProcessor); // fed by a PCM_FLOAT chain

// after
if (inputAudioFormat.encoding == AudioFormat.ENCODING_PCM_16BIT) {
  sink.addAudioProcessor(trimmingProcessor);
}
Defensive patterns

Strategy: validation

Validate before calling

// before adding TrimmingAudioProcessor to the chain
AudioFormat in = /* upstream output format */;
if (in.encoding == TrimmingAudioProcessor.OUTPUT_ENCODING /* ENCODING_PCM_16BIT */) {
  chain.add(trimmingProcessor);
}

Type guard

// n/a: encoding is an int constant; guard by equality check, not a type guard
static boolean canTrim(AudioFormat f) {
  return f != null && f.encoding == AudioFormat.ENCODING_PCM_16BIT;
}

Try / catch

try { processor.onConfigure(inputAudioFormat); }
catch (UnhandledAudioFormatException e) { /* skip this processor or convert PCM to 16-bit upstream */ }

Prevention

When it happens

Trigger: Inserting TrimmingAudioProcessor into an audio chain whose upstream delivers a non-PCM-16BIT encoding (e.g. ENCODING_PCM_FLOAT, ENCODING_PCM_24BIT, or a passthrough/offload encoding). The mismatch is detected when the audio sink calls onConfigure during format setup.

Common situations: Applying trim to float or 24/32-bit PCM output; chaining the trimmer after another processor that converted PCM to float; enabling audio offload so the encoding reaching the processor is not 16-bit.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/d489b65e64e9f3f8. Report an issue: GitHub.