Java Code Examples for com.google.android.exoplayer2.Format#NO_VALUE

The following examples show how to use com.google.android.exoplayer2.Format#NO_VALUE . 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: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isSupportedAdaptiveAudioTrack(
    Format format,
    int formatSupport,
    AudioConfigurationTuple configuration,
    int maxAudioBitrate,
    boolean allowMixedMimeTypeAdaptiveness,
    boolean allowMixedSampleRateAdaptiveness,
    boolean allowAudioMixedChannelCountAdaptiveness) {
  return isSupported(formatSupport, false)
      && (format.bitrate == Format.NO_VALUE || format.bitrate <= maxAudioBitrate)
      && (allowAudioMixedChannelCountAdaptiveness
          || (format.channelCount != Format.NO_VALUE
              && format.channelCount == configuration.channelCount))
      && (allowMixedMimeTypeAdaptiveness
          || (format.sampleMimeType != null
              && TextUtils.equals(format.sampleMimeType, configuration.mimeType)))
      && (allowMixedSampleRateAdaptiveness
          || (format.sampleRate != Format.NO_VALUE
              && format.sampleRate == configuration.sampleRate));
}
 
Example 2
Source File: SonicAudioProcessor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void reset() {
  speed = 1f;
  pitch = 1f;
  channelCount = Format.NO_VALUE;
  sampleRateHz = Format.NO_VALUE;
  outputSampleRateHz = Format.NO_VALUE;
  buffer = EMPTY_BUFFER;
  shortBuffer = buffer.asShortBuffer();
  outputBuffer = EMPTY_BUFFER;
  pendingOutputSampleRateHz = SAMPLE_RATE_NO_CHANGE;
  sonic = null;
  inputBytes = 0;
  outputBytes = 0;
  inputEnded = false;
}
 
Example 3
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the frame size for audio with {@code channelCount} channels in the specified encoding.
 *
 * @param pcmEncoding The encoding of the audio data.
 * @param channelCount The channel count.
 * @return The size of one audio frame in bytes.
 */
public static int getPcmFrameSize(@C.PcmEncoding int pcmEncoding, int channelCount) {
  switch (pcmEncoding) {
    case C.ENCODING_PCM_8BIT:
      return channelCount;
    case C.ENCODING_PCM_16BIT:
      return channelCount * 2;
    case C.ENCODING_PCM_24BIT:
      return channelCount * 3;
    case C.ENCODING_PCM_32BIT:
    case C.ENCODING_PCM_FLOAT:
      return channelCount * 4;
    case C.ENCODING_PCM_A_LAW:
    case C.ENCODING_PCM_MU_LAW:
    case C.ENCODING_INVALID:
    case Format.NO_VALUE:
    default:
      throw new IllegalArgumentException();
  }
}
 
Example 4
Source File: DashManifestParser.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
protected static int parseCea708AccessibilityChannel(
    List<Descriptor> accessibilityDescriptors) {
  for (int i = 0; i < accessibilityDescriptors.size(); i++) {
    Descriptor descriptor = accessibilityDescriptors.get(i);
    if ("urn:scte:dash:cc:cea-708:2015".equals(descriptor.schemeIdUri)
        && descriptor.value != null) {
      Matcher accessibilityValueMatcher = CEA_708_ACCESSIBILITY_PATTERN.matcher(descriptor.value);
      if (accessibilityValueMatcher.matches()) {
        return Integer.parseInt(accessibilityValueMatcher.group(1));
      } else {
        Log.w(TAG, "Unable to parse CEA-708 service block number from: " + descriptor.value);
      }
    }
  }
  return Format.NO_VALUE;
}
 
Example 5
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onDisabled() {
  currentWidth = Format.NO_VALUE;
  currentHeight = Format.NO_VALUE;
  currentPixelWidthHeightRatio = Format.NO_VALUE;
  pendingPixelWidthHeightRatio = Format.NO_VALUE;
  outputStreamOffsetUs = C.TIME_UNSET;
  lastInputTimeUs = C.TIME_UNSET;
  pendingOutputStreamOffsetCount = 0;
  clearReportedVideoSize();
  clearRenderedFirstFrame();
  frameReleaseTimeHelper.disable();
  tunnelingOnFrameRenderedListener = null;
  tunneling = false;
  try {
    super.onDisabled();
  } finally {
    decoderCounters.ensureUpdated();
    eventDispatcher.disabled(decoderCounters);
  }
}
 
Example 6
Source File: FfmpegAudioRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws FfmpegDecoderException {
  int initialInputBufferSize =
      format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder =
      new FfmpegDecoder(
          NUM_BUFFERS, NUM_BUFFERS, initialInputBufferSize, format, shouldUseFloatOutput(format));
  return decoder;
}
 
Example 7
Source File: MediaCodecInfo.java    From K-Sonic with MIT License 5 votes vote down vote up
@TargetApi(21)
private static boolean areSizeAndRateSupported(VideoCapabilities capabilities, int width,
    int height, double frameRate) {
  return frameRate == Format.NO_VALUE || frameRate <= 0
      ? capabilities.isSizeSupported(width, height)
      : capabilities.areSizeAndRateSupported(width, height, frameRate);
}
 
Example 8
Source File: SonicAudioProcessor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isActive() {
  return sampleRateHz != Format.NO_VALUE
      && (Math.abs(speed - 1f) >= CLOSE_THRESHOLD
          || Math.abs(pitch - 1f) >= CLOSE_THRESHOLD
          || outputSampleRateHz != sampleRateHz);
}
 
Example 9
Source File: Cea708Decoder.java    From K-Sonic with MIT License 5 votes vote down vote up
public Cea708Decoder(int accessibilityChannel) {
  ccData = new ParsableByteArray();
  serviceBlockPacket = new ParsableBitArray();
  selectedServiceNumber = (accessibilityChannel == Format.NO_VALUE) ? 1 : accessibilityChannel;

  cueBuilders = new CueBuilder[NUM_WINDOWS];
  for (int i = 0; i < NUM_WINDOWS; i++) {
    cueBuilders[i] = new CueBuilder();
  }

  currentCueBuilder = cueBuilders[0];
  resetCueBuilders();
}
 
Example 10
Source File: ResamplingAudioProcessor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** Creates a new audio processor that converts audio data to {@link C#ENCODING_PCM_16BIT}. */
public ResamplingAudioProcessor() {
  sampleRateHz = Format.NO_VALUE;
  channelCount = Format.NO_VALUE;
  encoding = C.ENCODING_INVALID;
  buffer = EMPTY_BUFFER;
  outputBuffer = EMPTY_BUFFER;
}
 
Example 11
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected float getCodecOperatingRate(
    float operatingRate, Format format, Format[] streamFormats) {
  // Use the highest known stream frame-rate up front, to avoid having to reconfigure the codec
  // should an adaptive switch to that stream occur.
  float maxFrameRate = -1;
  for (Format streamFormat : streamFormats) {
    float streamFrameRate = streamFormat.frameRate;
    if (streamFrameRate != Format.NO_VALUE) {
      maxFrameRate = Math.max(maxFrameRate, streamFrameRate);
    }
  }
  return maxFrameRate == -1 ? CODEC_OPERATING_RATE_UNSET : (maxFrameRate * operatingRate);
}
 
Example 12
Source File: FlacDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a Flac decoder.
 *
 * @param numInputBuffers The number of input buffers.
 * @param numOutputBuffers The number of output buffers.
 * @param maxInputBufferSize The maximum required input buffer size if known, or {@link
 *     Format#NO_VALUE} otherwise.
 * @param initializationData Codec-specific initialization data. It should contain only one entry
 *     which is the flac file header.
 * @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
 */
public FlacDecoder(
    int numInputBuffers,
    int numOutputBuffers,
    int maxInputBufferSize,
    List<byte[]> initializationData)
    throws FlacDecoderException {
  super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
  if (initializationData.size() != 1) {
    throw new FlacDecoderException("Initialization data must be of length 1");
  }
  decoderJni = new FlacDecoderJni();
  decoderJni.setData(ByteBuffer.wrap(initializationData.get(0)));
  FlacStreamInfo streamInfo;
  try {
    streamInfo = decoderJni.decodeMetadata();
  } catch (IOException | InterruptedException e) {
    // Never happens.
    throw new IllegalStateException(e);
  }
  if (streamInfo == null) {
    throw new FlacDecoderException("Metadata decoding failed");
  }

  int initialInputBufferSize =
      maxInputBufferSize != Format.NO_VALUE ? maxInputBufferSize : streamInfo.maxFrameSize;
  setInitialInputBufferSize(initialInputBufferSize);
  maxOutputBufferSize = streamInfo.maxDecodedFrameSize();
}
 
Example 13
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a maximum input size for a given codec, mime type, width and height.
 *
 * @param codecInfo Information about the {@link MediaCodec} being configured.
 * @param sampleMimeType The format mime type.
 * @param width The width in pixels.
 * @param height The height in pixels.
 * @return A maximum input size in bytes, or {@link Format#NO_VALUE} if a maximum could not be
 *     determined.
 */
private static int getMaxInputSize(
    MediaCodecInfo codecInfo, String sampleMimeType, int width, int height) {
  if (width == Format.NO_VALUE || height == Format.NO_VALUE) {
    // We can't infer a maximum input size without video dimensions.
    return Format.NO_VALUE;
  }

  // Attempt to infer a maximum input size from the format.
  int maxPixels;
  int minCompressionRatio;
  switch (sampleMimeType) {
    case MimeTypes.VIDEO_H263:
    case MimeTypes.VIDEO_MP4V:
      maxPixels = width * height;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_H264:
      if ("BRAVIA 4K 2015".equals(Util.MODEL) // Sony Bravia 4K
          || ("Amazon".equals(Util.MANUFACTURER)
              && ("KFSOWI".equals(Util.MODEL) // Kindle Soho
                  || ("AFTS".equals(Util.MODEL) && codecInfo.secure)))) { // Fire TV Gen 2
        // Use the default value for cases where platform limitations may prevent buffers of the
        // calculated maximum input size from being allocated.
        return Format.NO_VALUE;
      }
      // Round up width/height to an integer number of macroblocks.
      maxPixels = Util.ceilDivide(width, 16) * Util.ceilDivide(height, 16) * 16 * 16;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_VP8:
      // VPX does not specify a ratio so use the values from the platform's SoftVPX.cpp.
      maxPixels = width * height;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_H265:
    case MimeTypes.VIDEO_VP9:
      maxPixels = width * height;
      minCompressionRatio = 4;
      break;
    default:
      // Leave the default max input size.
      return Format.NO_VALUE;
  }
  // Estimate the maximum input size assuming three channel 4:2:0 subsampled input frames.
  return (maxPixels * 3) / (2 * minCompressionRatio);
}
 
Example 14
Source File: BaseAudioProcessor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isActive() {
  return sampleRateHz != Format.NO_VALUE;
}
 
Example 15
Source File: GaplessInfoHolder.java    From K-Sonic with MIT License 4 votes vote down vote up
/**
 * Returns whether {@link #encoderDelay} and {@link #encoderPadding} have been set.
 */
public boolean hasGaplessInfo() {
  return encoderDelay != Format.NO_VALUE && encoderPadding != Format.NO_VALUE;
}
 
Example 16
Source File: ResamplingAudioProcessor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void queueInput(ByteBuffer inputBuffer) {
  // Prepare the output buffer.
  int position = inputBuffer.position();
  int limit = inputBuffer.limit();
  int size = limit - position;
  int resampledSize;
  switch (encoding) {
    case C.ENCODING_PCM_8BIT:
      resampledSize = size * 2;
      break;
    case C.ENCODING_PCM_24BIT:
      resampledSize = (size / 3) * 2;
      break;
    case C.ENCODING_PCM_32BIT:
      resampledSize = size / 2;
      break;
    case C.ENCODING_PCM_16BIT:
    case C.ENCODING_PCM_FLOAT:
    case C.ENCODING_PCM_A_LAW:
    case C.ENCODING_PCM_MU_LAW:
    case C.ENCODING_INVALID:
    case Format.NO_VALUE:
    default:
      throw new IllegalStateException();
  }

  // Resample the little endian input and update the input/output buffers.
  ByteBuffer buffer = replaceOutputBuffer(resampledSize);
  switch (encoding) {
    case C.ENCODING_PCM_8BIT:
      // 8->16 bit resampling. Shift each byte from [0, 256) to [-128, 128) and scale up.
      for (int i = position; i < limit; i++) {
        buffer.put((byte) 0);
        buffer.put((byte) ((inputBuffer.get(i) & 0xFF) - 128));
      }
      break;
    case C.ENCODING_PCM_24BIT:
      // 24->16 bit resampling. Drop the least significant byte.
      for (int i = position; i < limit; i += 3) {
        buffer.put(inputBuffer.get(i + 1));
        buffer.put(inputBuffer.get(i + 2));
      }
      break;
    case C.ENCODING_PCM_32BIT:
      // 32->16 bit resampling. Drop the two least significant bytes.
      for (int i = position; i < limit; i += 4) {
        buffer.put(inputBuffer.get(i + 2));
        buffer.put(inputBuffer.get(i + 3));
      }
      break;
    case C.ENCODING_PCM_16BIT:
    case C.ENCODING_PCM_FLOAT:
    case C.ENCODING_PCM_A_LAW:
    case C.ENCODING_PCM_MU_LAW:
    case C.ENCODING_INVALID:
    case Format.NO_VALUE:
    default:
      // Never happens.
      throw new IllegalStateException();
  }
  inputBuffer.position(inputBuffer.limit());
  buffer.flip();
}
 
Example 17
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private void clearReportedVideoSize() {
  reportedWidth = Format.NO_VALUE;
  reportedHeight = Format.NO_VALUE;
  reportedPixelWidthHeightRatio = Format.NO_VALUE;
  reportedUnappliedRotationDegrees = Format.NO_VALUE;
}
 
Example 18
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a maximum input size for a given codec, MIME type, width and height.
 *
 * @param codecInfo Information about the {@link MediaCodec} being configured.
 * @param sampleMimeType The format mime type.
 * @param width The width in pixels.
 * @param height The height in pixels.
 * @return A maximum input size in bytes, or {@link Format#NO_VALUE} if a maximum could not be
 *     determined.
 */
private static int getCodecMaxInputSize(
    MediaCodecInfo codecInfo, String sampleMimeType, int width, int height) {
  if (width == Format.NO_VALUE || height == Format.NO_VALUE) {
    // We can't infer a maximum input size without video dimensions.
    return Format.NO_VALUE;
  }

  // Attempt to infer a maximum input size from the format.
  int maxPixels;
  int minCompressionRatio;
  switch (sampleMimeType) {
    case MimeTypes.VIDEO_H263:
    case MimeTypes.VIDEO_MP4V:
      maxPixels = width * height;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_H264:
      if ("BRAVIA 4K 2015".equals(Util.MODEL) // Sony Bravia 4K
          || ("Amazon".equals(Util.MANUFACTURER)
              && ("KFSOWI".equals(Util.MODEL) // Kindle Soho
                  || ("AFTS".equals(Util.MODEL) && codecInfo.secure)))) { // Fire TV Gen 2
        // Use the default value for cases where platform limitations may prevent buffers of the
        // calculated maximum input size from being allocated.
        return Format.NO_VALUE;
      }
      // Round up width/height to an integer number of macroblocks.
      maxPixels = Util.ceilDivide(width, 16) * Util.ceilDivide(height, 16) * 16 * 16;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_VP8:
      // VPX does not specify a ratio so use the values from the platform's SoftVPX.cpp.
      maxPixels = width * height;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_H265:
    case MimeTypes.VIDEO_VP9:
      maxPixels = width * height;
      minCompressionRatio = 4;
      break;
    default:
      // Leave the default max input size.
      return Format.NO_VALUE;
  }
  // Estimate the maximum input size assuming three channel 4:2:0 subsampled input frames.
  return (maxPixels * 3) / (2 * minCompressionRatio);
}
 
Example 19
Source File: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Compares two format values for order. A known value is considered greater than {@link
 * Format#NO_VALUE}.
 *
 * @param first The first value.
 * @param second The second value.
 * @return A negative integer if the first value is less than the second. Zero if they are equal.
 *     A positive integer if the first value is greater than the second.
 */
private static int compareFormatValues(int first, int second) {
  return first == Format.NO_VALUE
      ? (second == Format.NO_VALUE ? 0 : -1)
      : (second == Format.NO_VALUE ? 1 : (first - second));
}
 
Example 20
Source File: MediaFormatUtil.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets a {@link MediaFormat} float value. Does nothing if {@code value} is {@link
 * Format#NO_VALUE}.
 *
 * @param format The {@link MediaFormat} being configured.
 * @param key The key to set.
 * @param value The value to set.
 */
public static void maybeSetFloat(MediaFormat format, String key, float value) {
  if (value != Format.NO_VALUE) {
    format.setFloat(key, value);
  }
}