{"record":{"id":"3999abaf5f8968e8","repo":"DrKLO/Telegram","slug":"invalid-sample-rate-or-number-of-channels-sample","errorCode":null,"errorMessage":"Invalid sample rate or number of channels: {sampleRate}, {channelCount}","messagePattern":"Invalid sample rate or number of channels: (.+?), (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/AacUtil.java","lineNumber":285,"sourceCode":"   * @param sampleRate The sample rate in Hz.\n   * @param channelCount The channel count.\n   * @return The AudioSpecificConfig.\n   */\n  public static byte[] buildAacLcAudioSpecificConfig(int sampleRate, int channelCount) {\n    int sampleRateIndex = C.INDEX_UNSET;\n    for (int i = 0; i < AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE.length; ++i) {\n      if (sampleRate == AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[i]) {\n        sampleRateIndex = i;\n      }\n    }\n    int channelConfig = C.INDEX_UNSET;\n    for (int i = 0; i < AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE.length; ++i) {\n      if (channelCount == AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE[i]) {\n        channelConfig = i;\n      }\n    }\n    if (sampleRate == C.INDEX_UNSET || channelConfig == C.INDEX_UNSET) {\n      throw new IllegalArgumentException(\n          \"Invalid sample rate or number of channels: \" + sampleRate + \", \" + channelCount);\n    }\n    return buildAudioSpecificConfig(AUDIO_OBJECT_TYPE_AAC_LC, sampleRateIndex, channelConfig);\n  }\n\n  /**\n   * Builds a simple AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1\n   *\n   * @param audioObjectType The audio object type.\n   * @param sampleRateIndex The sample rate index.\n   * @param channelConfig The channel configuration.\n   * @return The AudioSpecificConfig.\n   */\n  public static byte[] buildAudioSpecificConfig(\n      int audioObjectType, int sampleRateIndex, int channelConfig) {\n    byte[] specificConfig = new byte[2];\n    specificConfig[0] = (byte) (((audioObjectType << 3) & 0xF8) | ((sampleRateIndex >> 1) & 0x07));\n    specificConfig[1] = (byte) (((sampleRateIndex << 7) & 0x80) | ((channelConfig << 3) & 0x78));","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/AacUtil.java#L267-L303","documentation":"AacUtil throws IllegalArgumentException ('Invalid sample rate or number of channels') when, after parsing an AAC AudioSpecificConfig (or building one), the provided sampleRate or channelCount does not appear in the known MPEG-4 AAC tables (AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE for rates: 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350; and AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE for channel counts 0..7). AAC-LC only supports these enumerated rates/counts; anything else cannot be encoded as a standard sampling_frequency_index/channel_configuration and the config cannot be built.","triggerScenarios":"Passing a non-standard sample rate (e.g. 44100 is fine, but 47250 is not) or channel count (e.g. 9 channels) into AacUtil.buildAudioSpecificConfig or a code path that derives the config from raw rate/count; mis-parsed media where the declared rate/channel fields are corrupted; user-selected encoding parameters outside the AAC table.","commonSituations":"Custom audio pipeline building an AAC config from arbitrary user input; transcoding audio whose source container declares an exotic rate; media with a malformed codec private data that decodes to an out-of-table value; testing with synthetic PCM at non-standard rates.","solutions":["Restrict sample rate to one of the 13 AAC standard rates (96000..7350) and channel count to 1..7 (or 8 for the 7.1 entry if supported).","Resample the input PCM to a supported rate before encoding (use SonicAudioProcessor or a resampler to land on 44100/48000).","Down-mix or up-mix channels so the count is within the table (1, 2, ..., 7).","If the input is genuinely unsupported, reject the format upstream and surface a clear 'unsupported AAC input' to the user instead of throwing."],"exampleFix":"// before\nbyte[] cfg = AacUtil.buildAudioSpecificConfig(sampleRate, channelCount); // throws if non-standard\n// after\nint[] validRates = {96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000,7350};\nint rate = pickNearest(validRates, sampleRate); // resample input to `rate`\nint ch  = Math.max(1, Math.min(channelCount, 7));\nbyte[] cfg = AacUtil.buildAudioSpecificConfig(rate, ch);","handlingStrategy":"validation","validationCode":"static final int[] AAC_RATES = {96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000,7350};\nstatic boolean isAacSupported(int rate, int channels) {\n  boolean rateOk = false;\n  for (int r : AAC_RATES) if (r == rate) { rateOk = true; break; }\n  return rateOk && channels >= 1 && channels <= 7;\n}","typeGuard":null,"tryCatchPattern":"try {\n  cfg = AacUtil.buildAudioSpecificConfig(rate, ch);\n} catch (IllegalArgumentException e) {\n  // resample to nearest supported rate and retry\n  rate = nearestSupported(AAC_RATES, rate);\n  cfg = AacUtil.buildAudioSpecificConfig(rate, Math.min(ch, 7));\n}","preventionTips":["Restrict user-facing encoding options to AAC-standard rates/channels.","Validate rate/channel before building the AudioSpecificConfig.","Resample exotic input rates to 44100/48000 before AAC encoding."],"tags":["exoplayer","audio","aac","codec","configuration"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}