Java Code Examples for com.google.android.exoplayer2.C#ENCODING_AC3

The following examples show how to use com.google.android.exoplayer2.C#ENCODING_AC3 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultAudioSink.java    From Telegram with GNU General Public License v2.0 7 votes vote down vote up
private int getDefaultBufferSize() {
  if (isInputPcm) {
    int minBufferSize =
        AudioTrack.getMinBufferSize(outputSampleRate, outputChannelConfig, outputEncoding);
    Assertions.checkState(minBufferSize != ERROR_BAD_VALUE);
    int multipliedBufferSize = minBufferSize * BUFFER_MULTIPLICATION_FACTOR;
    int minAppBufferSize =
        (int) durationUsToFrames(MIN_BUFFER_DURATION_US) * outputPcmFrameSize;
    int maxAppBufferSize =
        (int)
            Math.max(
                minBufferSize, durationUsToFrames(MAX_BUFFER_DURATION_US) * outputPcmFrameSize);
    return Util.constrainValue(multipliedBufferSize, minAppBufferSize, maxAppBufferSize);
  } else {
    int rate = getMaximumEncodedRateBytesPerSecond(outputEncoding);
    if (outputEncoding == C.ENCODING_AC3) {
      rate *= AC3_BUFFER_MULTIPLICATION_FACTOR;
    }
    return (int) (PASSTHROUGH_BUFFER_DURATION_US * rate / C.MICROS_PER_SECOND);
  }
}
 
Example 2
Source File: MimeTypes.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link C}{@code .ENCODING_*} constant that corresponds to specified MIME type, if
 * it is an encoded (non-PCM) audio format, or {@link C#ENCODING_INVALID} otherwise.
 *
 * @param mimeType The MIME type.
 * @return The {@link C}{@code .ENCODING_*} constant that corresponds to a specified MIME type, or
 *     {@link C#ENCODING_INVALID}.
 */
public static @C.Encoding int getEncoding(String mimeType) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AC3:
      return C.ENCODING_AC3;
    case MimeTypes.AUDIO_E_AC3:
    case MimeTypes.AUDIO_E_AC3_JOC:
      return C.ENCODING_E_AC3;
    case MimeTypes.AUDIO_DTS:
      return C.ENCODING_DTS;
    case MimeTypes.AUDIO_DTS_HD:
      return C.ENCODING_DTS_HD;
    case MimeTypes.AUDIO_TRUEHD:
      return C.ENCODING_DOLBY_TRUEHD;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 3
Source File: DefaultAudioSink.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static int getFramesPerEncodedSample(@C.Encoding int encoding, ByteBuffer buffer) {
  if (encoding == C.ENCODING_DTS || encoding == C.ENCODING_DTS_HD) {
    return DtsUtil.parseDtsAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_AC3) {
    return Ac3Util.getAc3SyncframeAudioSampleCount();
  } else if (encoding == C.ENCODING_E_AC3 || encoding == C.ENCODING_E_AC3_JOC) {
    return Ac3Util.parseEAc3SyncframeAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_AC4) {
    return Ac4Util.parseAc4SyncframeAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_DOLBY_TRUEHD) {
    int syncframeOffset = Ac3Util.findTrueHdSyncframeOffset(buffer);
    return syncframeOffset == C.INDEX_UNSET
        ? 0
        : (Ac3Util.parseTrueHdSyncframeAudioSampleCount(buffer, syncframeOffset)
            * Ac3Util.TRUEHD_RECHUNK_SAMPLE_COUNT);
  } else {
    throw new IllegalStateException("Unexpected audio encoding: " + encoding);
  }
}
 
Example 4
Source File: MimeTypes.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link C}{@code .ENCODING_*} constant that corresponds to specified MIME type, if
 * it is an encoded (non-PCM) audio format, or {@link C#ENCODING_INVALID} otherwise.
 *
 * @param mimeType The MIME type.
 * @return The {@link C}{@code .ENCODING_*} constant that corresponds to a specified MIME type, or
 *     {@link C#ENCODING_INVALID}.
 */
public static @C.Encoding int getEncoding(String mimeType) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AC3:
      return C.ENCODING_AC3;
    case MimeTypes.AUDIO_E_AC3:
      return C.ENCODING_E_AC3;
    case MimeTypes.AUDIO_E_AC3_JOC:
      return C.ENCODING_E_AC3_JOC;
    case MimeTypes.AUDIO_AC4:
      return C.ENCODING_AC4;
    case MimeTypes.AUDIO_DTS:
      return C.ENCODING_DTS;
    case MimeTypes.AUDIO_DTS_HD:
      return C.ENCODING_DTS_HD;
    case MimeTypes.AUDIO_TRUEHD:
      return C.ENCODING_DOLBY_TRUEHD;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 5
Source File: DefaultAudioSink.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private int getDefaultBufferSize() {
  if (isInputPcm) {
    int minBufferSize =
        AudioTrack.getMinBufferSize(outputSampleRate, outputChannelConfig, outputEncoding);
    Assertions.checkState(minBufferSize != ERROR_BAD_VALUE);
    int multipliedBufferSize = minBufferSize * BUFFER_MULTIPLICATION_FACTOR;
    int minAppBufferSize =
        (int) durationUsToFrames(MIN_BUFFER_DURATION_US) * outputPcmFrameSize;
    int maxAppBufferSize =
        (int)
            Math.max(
                minBufferSize, durationUsToFrames(MAX_BUFFER_DURATION_US) * outputPcmFrameSize);
    return Util.constrainValue(multipliedBufferSize, minAppBufferSize, maxAppBufferSize);
  } else {
    int rate = getMaximumEncodedRateBytesPerSecond(outputEncoding);
    if (outputEncoding == C.ENCODING_AC3) {
      rate *= AC3_BUFFER_MULTIPLICATION_FACTOR;
    }
    return (int) (PASSTHROUGH_BUFFER_DURATION_US * rate / C.MICROS_PER_SECOND);
  }
}
 
Example 6
Source File: MimeTypes.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link C}{@code .ENCODING_*} constant that corresponds to specified MIME type, if
 * it is an encoded (non-PCM) audio format, or {@link C#ENCODING_INVALID} otherwise.
 *
 * @param mimeType The MIME type.
 * @return The {@link C}{@code .ENCODING_*} constant that corresponds to a specified MIME type, or
 *     {@link C#ENCODING_INVALID}.
 */
public static @C.Encoding int getEncoding(String mimeType) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AC3:
      return C.ENCODING_AC3;
    case MimeTypes.AUDIO_E_AC3:
      return C.ENCODING_E_AC3;
    case MimeTypes.AUDIO_E_AC3_JOC:
      return C.ENCODING_E_AC3_JOC;
    case MimeTypes.AUDIO_AC4:
      return C.ENCODING_AC4;
    case MimeTypes.AUDIO_DTS:
      return C.ENCODING_DTS;
    case MimeTypes.AUDIO_DTS_HD:
      return C.ENCODING_DTS_HD;
    case MimeTypes.AUDIO_TRUEHD:
      return C.ENCODING_DOLBY_TRUEHD;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 7
Source File: DefaultAudioSink.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static int getFramesPerEncodedSample(@C.Encoding int encoding, ByteBuffer buffer) {
  if (encoding == C.ENCODING_DTS || encoding == C.ENCODING_DTS_HD) {
    return DtsUtil.parseDtsAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_AC3) {
    return Ac3Util.getAc3SyncframeAudioSampleCount();
  } else if (encoding == C.ENCODING_E_AC3) {
    return Ac3Util.parseEAc3SyncframeAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_DOLBY_TRUEHD) {
    int syncframeOffset = Ac3Util.findTrueHdSyncframeOffset(buffer);
    return syncframeOffset == C.INDEX_UNSET
        ? 0
        : (Ac3Util.parseTrueHdSyncframeAudioSampleCount(buffer, syncframeOffset)
            * Ac3Util.TRUEHD_RECHUNK_SAMPLE_COUNT);
  } else {
    throw new IllegalStateException("Unexpected audio encoding: " + encoding);
  }
}
 
Example 8
Source File: MimeTypes.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link C}{@code .ENCODING_*} constant that corresponds to specified MIME type, if
 * it is an encoded (non-PCM) audio format, or {@link C#ENCODING_INVALID} otherwise.
 *
 * @param mimeType The MIME type.
 * @return The {@link C}{@code .ENCODING_*} constant that corresponds to a specified MIME type, or
 *     {@link C#ENCODING_INVALID}.
 */
public static @C.Encoding int getEncoding(String mimeType) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AC3:
      return C.ENCODING_AC3;
    case MimeTypes.AUDIO_E_AC3:
    case MimeTypes.AUDIO_E_AC3_JOC:
      return C.ENCODING_E_AC3;
    case MimeTypes.AUDIO_DTS:
      return C.ENCODING_DTS;
    case MimeTypes.AUDIO_DTS_HD:
      return C.ENCODING_DTS_HD;
    case MimeTypes.AUDIO_TRUEHD:
      return C.ENCODING_DOLBY_TRUEHD;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 9
Source File: DefaultAudioSink.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private int getDefaultBufferSize() {
  if (isInputPcm) {
    int minBufferSize =
        AudioTrack.getMinBufferSize(outputSampleRate, outputChannelConfig, outputEncoding);
    Assertions.checkState(minBufferSize != ERROR_BAD_VALUE);
    int multipliedBufferSize = minBufferSize * BUFFER_MULTIPLICATION_FACTOR;
    int minAppBufferSize =
        (int) durationUsToFrames(MIN_BUFFER_DURATION_US) * outputPcmFrameSize;
    int maxAppBufferSize =
        (int)
            Math.max(
                minBufferSize, durationUsToFrames(MAX_BUFFER_DURATION_US) * outputPcmFrameSize);
    return Util.constrainValue(multipliedBufferSize, minAppBufferSize, maxAppBufferSize);
  } else {
    int rate = getMaximumEncodedRateBytesPerSecond(outputEncoding);
    if (outputEncoding == C.ENCODING_AC3) {
      rate *= AC3_BUFFER_MULTIPLICATION_FACTOR;
    }
    return (int) (PASSTHROUGH_BUFFER_DURATION_US * rate / C.MICROS_PER_SECOND);
  }
}
 
Example 10
Source File: DefaultAudioSink.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static int getFramesPerEncodedSample(@C.Encoding int encoding, ByteBuffer buffer) {
  if (encoding == C.ENCODING_DTS || encoding == C.ENCODING_DTS_HD) {
    return DtsUtil.parseDtsAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_AC3) {
    return Ac3Util.getAc3SyncframeAudioSampleCount();
  } else if (encoding == C.ENCODING_E_AC3 || encoding == C.ENCODING_E_AC3_JOC) {
    return Ac3Util.parseEAc3SyncframeAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_AC4) {
    return Ac4Util.parseAc4SyncframeAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_DOLBY_TRUEHD) {
    int syncframeOffset = Ac3Util.findTrueHdSyncframeOffset(buffer);
    return syncframeOffset == C.INDEX_UNSET
        ? 0
        : (Ac3Util.parseTrueHdSyncframeAudioSampleCount(buffer, syncframeOffset)
            * Ac3Util.TRUEHD_RECHUNK_SAMPLE_COUNT);
  } else {
    throw new IllegalStateException("Unexpected audio encoding: " + encoding);
  }
}
 
Example 11
Source File: MimeTypes.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link C}{@code .ENCODING_*} constant that corresponds to specified MIME type, if
 * it is an encoded (non-PCM) audio format, or {@link C#ENCODING_INVALID} otherwise.
 *
 * @param mimeType The MIME type.
 * @return The {@link C}{@code .ENCODING_*} constant that corresponds to a specified MIME type, or
 *     {@link C#ENCODING_INVALID}.
 */
public static @C.Encoding int getEncoding(String mimeType) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AC3:
      return C.ENCODING_AC3;
    case MimeTypes.AUDIO_E_AC3:
      return C.ENCODING_E_AC3;
    case MimeTypes.AUDIO_E_AC3_JOC:
      return C.ENCODING_E_AC3_JOC;
    case MimeTypes.AUDIO_AC4:
      return C.ENCODING_AC4;
    case MimeTypes.AUDIO_DTS:
      return C.ENCODING_DTS;
    case MimeTypes.AUDIO_DTS_HD:
      return C.ENCODING_DTS_HD;
    case MimeTypes.AUDIO_TRUEHD:
      return C.ENCODING_DOLBY_TRUEHD;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 12
Source File: DefaultAudioSink.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static int getMaximumEncodedRateBytesPerSecond(@C.Encoding int encoding) {
  switch (encoding) {
    case C.ENCODING_AC3:
      return 640 * 1000 / 8;
    case C.ENCODING_E_AC3:
    case C.ENCODING_E_AC3_JOC:
      return 6144 * 1000 / 8;
    case C.ENCODING_AC4:
      return 2688 * 1000 / 8;
    case C.ENCODING_DTS:
      // DTS allows an 'open' bitrate, but we assume the maximum listed value: 1536 kbit/s.
      return 1536 * 1000 / 8;
    case C.ENCODING_DTS_HD:
      return 18000 * 1000 / 8;
    case C.ENCODING_DOLBY_TRUEHD:
      return 24500 * 1000 / 8;
    case C.ENCODING_INVALID:
    case C.ENCODING_PCM_16BIT:
    case C.ENCODING_PCM_24BIT:
    case C.ENCODING_PCM_32BIT:
    case C.ENCODING_PCM_8BIT:
    case C.ENCODING_PCM_A_LAW:
    case C.ENCODING_PCM_FLOAT:
    case C.ENCODING_PCM_MU_LAW:
    case Format.NO_VALUE:
    default:
      throw new IllegalArgumentException();
  }
}
 
Example 13
Source File: AudioTrack.java    From K-Sonic with MIT License 5 votes vote down vote up
@C.Encoding
private static int getEncodingForMimeType(String mimeType) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AC3:
      return C.ENCODING_AC3;
    case MimeTypes.AUDIO_E_AC3:
      return C.ENCODING_E_AC3;
    case MimeTypes.AUDIO_DTS:
      return C.ENCODING_DTS;
    case MimeTypes.AUDIO_DTS_HD:
      return C.ENCODING_DTS_HD;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 14
Source File: AudioTrack.java    From K-Sonic with MIT License 5 votes vote down vote up
private static int getFramesPerEncodedSample(@C.Encoding int encoding, ByteBuffer buffer) {
  if (encoding == C.ENCODING_DTS || encoding == C.ENCODING_DTS_HD) {
    return DtsUtil.parseDtsAudioSampleCount(buffer);
  } else if (encoding == C.ENCODING_AC3) {
    return Ac3Util.getAc3SyncframeAudioSampleCount();
  } else if (encoding == C.ENCODING_E_AC3) {
    return Ac3Util.parseEAc3SyncframeAudioSampleCount(buffer);
  } else {
    throw new IllegalStateException("Unexpected audio encoding: " + encoding);
  }
}
 
Example 15
Source File: DefaultAudioSink.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static int getMaximumEncodedRateBytesPerSecond(@C.Encoding int encoding) {
  switch (encoding) {
    case C.ENCODING_AC3:
      return 640 * 1000 / 8;
    case C.ENCODING_E_AC3:
    case C.ENCODING_E_AC3_JOC:
      return 6144 * 1000 / 8;
    case C.ENCODING_AC4:
      return 2688 * 1000 / 8;
    case C.ENCODING_DTS:
      // DTS allows an 'open' bitrate, but we assume the maximum listed value: 1536 kbit/s.
      return 1536 * 1000 / 8;
    case C.ENCODING_DTS_HD:
      return 18000 * 1000 / 8;
    case C.ENCODING_DOLBY_TRUEHD:
      return 24500 * 1000 / 8;
    case C.ENCODING_INVALID:
    case C.ENCODING_PCM_16BIT:
    case C.ENCODING_PCM_24BIT:
    case C.ENCODING_PCM_32BIT:
    case C.ENCODING_PCM_8BIT:
    case C.ENCODING_PCM_A_LAW:
    case C.ENCODING_PCM_FLOAT:
    case C.ENCODING_PCM_MU_LAW:
    case Format.NO_VALUE:
    default:
      throw new IllegalArgumentException();
  }
}
 
Example 16
Source File: AudioTrackPositionTracker.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether to work around problems with passthrough audio tracks. See [Internal:
 * b/18899620, b/19187573, b/21145353].
 */
private static boolean needsPassthroughWorkarounds(@C.Encoding int outputEncoding) {
  return Util.SDK_INT < 23
      && (outputEncoding == C.ENCODING_AC3 || outputEncoding == C.ENCODING_E_AC3);
}
 
Example 17
Source File: AudioTrackPositionTracker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether to work around problems with passthrough audio tracks. See [Internal:
 * b/18899620, b/19187573, b/21145353].
 */
private static boolean needsPassthroughWorkarounds(@C.Encoding int outputEncoding) {
  return Util.SDK_INT < 23
      && (outputEncoding == C.ENCODING_AC3 || outputEncoding == C.ENCODING_E_AC3);
}
 
Example 18
Source File: AudioTrack.java    From K-Sonic with MIT License 4 votes vote down vote up
/**
 * Returns whether to work around problems with passthrough audio tracks.
 * See [Internal: b/18899620, b/19187573, b/21145353].
 */
private boolean needsPassthroughWorkarounds() {
  return Util.SDK_INT < 23
      && (outputEncoding == C.ENCODING_AC3 || outputEncoding == C.ENCODING_E_AC3);
}
 
Example 19
Source File: AudioTrackPositionTracker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether to work around problems with passthrough audio tracks. See [Internal:
 * b/18899620, b/19187573, b/21145353].
 */
private static boolean needsPassthroughWorkarounds(@C.Encoding int outputEncoding) {
  return Util.SDK_INT < 23
      && (outputEncoding == C.ENCODING_AC3 || outputEncoding == C.ENCODING_E_AC3);
}
 
Example 20
Source File: AudioTrackPositionTracker.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether to work around problems with passthrough audio tracks. See [Internal:
 * b/18899620, b/19187573, b/21145353].
 */
private static boolean needsPassthroughWorkarounds(@C.Encoding int outputEncoding) {
  return Util.SDK_INT < 23
      && (outputEncoding == C.ENCODING_AC3 || outputEncoding == C.ENCODING_E_AC3);
}