当前位置: 首页>>代码示例>>Java>>正文


Java C.BUFFER_FLAG_KEY_FRAME属性代码示例

本文整理汇总了Java中com.google.android.exoplayer2.C.BUFFER_FLAG_KEY_FRAME属性的典型用法代码示例。如果您正苦于以下问题:Java C.BUFFER_FLAG_KEY_FRAME属性的具体用法?Java C.BUFFER_FLAG_KEY_FRAME怎么用?Java C.BUFFER_FLAG_KEY_FRAME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.android.exoplayer2.C的用法示例。


在下文中一共展示了C.BUFFER_FLAG_KEY_FRAME属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sampleMetadata

@Override
public void sampleMetadata(long timeUs, @C.BufferFlags int flags, int size, int offset,
    byte[] encryptionKey) {
  if (pendingFormatAdjustment) {
    format(lastUnadjustedFormat);
  }
  if (!startWriteOperation()) {
    infoQueue.commitSampleTimestamp(timeUs);
    return;
  }
  try {
    if (pendingSplice) {
      if ((flags & C.BUFFER_FLAG_KEY_FRAME) == 0 || !infoQueue.attemptSplice(timeUs)) {
        return;
      }
      pendingSplice = false;
    }
    timeUs += sampleOffsetUs;
    long absoluteOffset = totalBytesWritten - size - offset;
    infoQueue.commitSample(timeUs, flags, absoluteOffset, size, encryptionKey);
  } finally {
    endWriteOperation();
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:24,代码来源:DefaultTrackOutput.java

示例2: getIndexOfEarlierOrEqualSynchronizationSample

/**
 * Returns the sample index of the closest synchronization sample at or before the given
 * timestamp, if one is available.
 *
 * @param timeUs Timestamp adjacent to which to find a synchronization sample.
 * @return Index of the synchronization sample, or {@link C#INDEX_UNSET} if none.
 */
public int getIndexOfEarlierOrEqualSynchronizationSample(long timeUs) {
  // Video frame timestamps may not be sorted, so the behavior of this call can be undefined.
  // Frames are not reordered past synchronization samples so this works in practice.
  int startIndex = Util.binarySearchFloor(timestampsUs, timeUs, true, false);
  for (int i = startIndex; i >= 0; i--) {
    if ((flags[i] & C.BUFFER_FLAG_KEY_FRAME) != 0) {
      return i;
    }
  }
  return C.INDEX_UNSET;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:18,代码来源:TrackSampleTable.java

示例3: getIndexOfLaterOrEqualSynchronizationSample

/**
 * Returns the sample index of the closest synchronization sample at or after the given timestamp,
 * if one is available.
 *
 * @param timeUs Timestamp adjacent to which to find a synchronization sample.
 * @return index Index of the synchronization sample, or {@link C#INDEX_UNSET} if none.
 */
public int getIndexOfLaterOrEqualSynchronizationSample(long timeUs) {
  int startIndex = Util.binarySearchCeil(timestampsUs, timeUs, true, false);
  for (int i = startIndex; i < timestampsUs.length; i++) {
    if ((flags[i] & C.BUFFER_FLAG_KEY_FRAME) != 0) {
      return i;
    }
  }
  return C.INDEX_UNSET;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:16,代码来源:TrackSampleTable.java

示例4: discardUpstreamSamples

/**
 * Discards samples from the write side of the buffer.
 *
 * @param discardFromIndex The absolute index of the first sample to be discarded.
 * @return The reduced total number of bytes written, after the samples have been discarded.
 */
public long discardUpstreamSamples(int discardFromIndex) {
  int discardCount = getWriteIndex() - discardFromIndex;
  Assertions.checkArgument(0 <= discardCount && discardCount <= queueSize);

  if (discardCount == 0) {
    if (absoluteReadIndex == 0) {
      // queueSize == absoluteReadIndex == 0, so nothing has been written to the queue.
      return 0;
    }
    int lastWriteIndex = (relativeWriteIndex == 0 ? capacity : relativeWriteIndex) - 1;
    return offsets[lastWriteIndex] + sizes[lastWriteIndex];
  }

  queueSize -= discardCount;
  relativeWriteIndex = (relativeWriteIndex + capacity - discardCount) % capacity;
  // Update the largest queued timestamp, assuming that the timestamps prior to a keyframe are
  // always less than the timestamp of the keyframe itself, and of subsequent frames.
  largestQueuedTimestampUs = Long.MIN_VALUE;
  for (int i = queueSize - 1; i >= 0; i--) {
    int sampleIndex = (relativeReadIndex + i) % capacity;
    largestQueuedTimestampUs = Math.max(largestQueuedTimestampUs, timesUs[sampleIndex]);
    if ((flags[sampleIndex] & C.BUFFER_FLAG_KEY_FRAME) != 0) {
      break;
    }
  }
  return offsets[relativeWriteIndex];
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:33,代码来源:DefaultTrackOutput.java

示例5: skipToKeyframeBefore

/**
 * Attempts to locate the keyframe before or at the specified time. If
 * {@code allowTimeBeyondBuffer} is {@code false} then it is also required that {@code timeUs}
 * falls within the buffer.
 *
 * @param timeUs The seek time.
 * @param allowTimeBeyondBuffer Whether the skip can succeed if {@code timeUs} is beyond the end
 *     of the buffer.
 * @return The offset of the keyframe's data if the keyframe was present.
 *     {@link C#POSITION_UNSET} otherwise.
 */
public synchronized long skipToKeyframeBefore(long timeUs, boolean allowTimeBeyondBuffer) {
  if (queueSize == 0 || timeUs < timesUs[relativeReadIndex]) {
    return C.POSITION_UNSET;
  }

  if (timeUs > largestQueuedTimestampUs && !allowTimeBeyondBuffer) {
    return C.POSITION_UNSET;
  }

  // This could be optimized to use a binary search, however in practice callers to this method
  // often pass times near to the start of the buffer. Hence it's unclear whether switching to
  // a binary search would yield any real benefit.
  int sampleCount = 0;
  int sampleCountToKeyframe = -1;
  int searchIndex = relativeReadIndex;
  while (searchIndex != relativeWriteIndex) {
    if (timesUs[searchIndex] > timeUs) {
      // We've gone too far.
      break;
    } else if ((flags[searchIndex] & C.BUFFER_FLAG_KEY_FRAME) != 0) {
      // We've found a keyframe, and we're still before the seek position.
      sampleCountToKeyframe = sampleCount;
    }
    searchIndex = (searchIndex + 1) % capacity;
    sampleCount++;
  }

  if (sampleCountToKeyframe == -1) {
    return C.POSITION_UNSET;
  }

  relativeReadIndex = (relativeReadIndex + sampleCountToKeyframe) % capacity;
  absoluteReadIndex += sampleCountToKeyframe;
  queueSize -= sampleCountToKeyframe;
  return offsets[relativeReadIndex];
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:47,代码来源:DefaultTrackOutput.java

示例6: consume

@Override
public void consume(ParsableByteArray data) {
  int offset = data.getPosition();
  int limit = data.limit();
  byte[] dataArray = data.data;

  // Append the data to the buffer.
  totalBytesWritten += data.bytesLeft();
  output.sampleData(data, data.bytesLeft());

  int searchOffset = offset;
  while (true) {
    int startCodeOffset = NalUnitUtil.findNalUnit(dataArray, searchOffset, limit, prefixFlags);

    if (startCodeOffset == limit) {
      // We've scanned to the end of the data without finding another start code.
      if (!hasOutputFormat) {
        csdBuffer.onData(dataArray, offset, limit);
      }
      return;
    }

    // We've found a start code with the following value.
    int startCodeValue = data.data[startCodeOffset + 3] & 0xFF;

    if (!hasOutputFormat) {
      // This is the number of bytes from the current offset to the start of the next start
      // code. It may be negative if the start code started in the previously consumed data.
      int lengthToStartCode = startCodeOffset - offset;
      if (lengthToStartCode > 0) {
        csdBuffer.onData(dataArray, offset, startCodeOffset);
      }
      // This is the number of bytes belonging to the next start code that have already been
      // passed to csdDataTargetBuffer.
      int bytesAlreadyPassed = lengthToStartCode < 0 ? -lengthToStartCode : 0;
      if (csdBuffer.onStartCode(startCodeValue, bytesAlreadyPassed)) {
        // The csd data is complete, so we can decode and output the media format.
        Pair<Format, Long> result = parseCsdBuffer(csdBuffer, formatId);
        output.format(result.first);
        frameDurationUs = result.second;
        hasOutputFormat = true;
      }
    }

    if (hasOutputFormat && (startCodeValue == START_GROUP || startCodeValue == START_PICTURE)) {
      int bytesWrittenPastStartCode = limit - startCodeOffset;
      if (foundFirstFrameInGroup) {
        @C.BufferFlags int flags = isKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
        int size = (int) (totalBytesWritten - framePosition) - bytesWrittenPastStartCode;
        output.sampleMetadata(frameTimeUs, flags, size, bytesWrittenPastStartCode, null);
        isKeyframe = false;
      }
      if (startCodeValue == START_GROUP) {
        foundFirstFrameInGroup = false;
        isKeyframe = true;
      } else /* startCodeValue == START_PICTURE */ {
        frameTimeUs = pesPtsUsAvailable ? pesTimeUs : (frameTimeUs + frameDurationUs);
        framePosition = totalBytesWritten - bytesWrittenPastStartCode;
        pesPtsUsAvailable = false;
        foundFirstFrameInGroup = true;
      }
    }

    offset = startCodeOffset;
    searchOffset = offset + 3;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:67,代码来源:H262Reader.java

示例7: outputSample

private void outputSample(int offset) {
  @C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
  int size = (int) (nalUnitStartPosition - samplePosition);
  output.sampleMetadata(sampleTimeUs, flags, size, offset, null);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:5,代码来源:H264Reader.java

示例8: rechunk

/**
 * Rechunk the given fixed sample size input to produce a new sequence of samples.
 *
 * @param fixedSampleSize Size in bytes of each sample.
 * @param chunkOffsets Chunk offsets in the MP4 stream to rechunk.
 * @param chunkSampleCounts Sample counts for each of the MP4 stream's chunks.
 * @param timestampDeltaInTimeUnits Timestamp delta between each sample in time units.
 */
public static Results rechunk(int fixedSampleSize, long[] chunkOffsets, int[] chunkSampleCounts,
    long timestampDeltaInTimeUnits) {
  int maxSampleCount = MAX_SAMPLE_SIZE / fixedSampleSize;

  // Count the number of new, rechunked buffers.
  int rechunkedSampleCount = 0;
  for (int chunkSampleCount : chunkSampleCounts) {
    rechunkedSampleCount += Util.ceilDivide(chunkSampleCount, maxSampleCount);
  }

  long[] offsets = new long[rechunkedSampleCount];
  int[] sizes = new int[rechunkedSampleCount];
  int maximumSize = 0;
  long[] timestamps = new long[rechunkedSampleCount];
  int[] flags = new int[rechunkedSampleCount];

  int originalSampleIndex = 0;
  int newSampleIndex = 0;
  for (int chunkIndex = 0; chunkIndex < chunkSampleCounts.length; chunkIndex++) {
    int chunkSamplesRemaining = chunkSampleCounts[chunkIndex];
    long sampleOffset = chunkOffsets[chunkIndex];

    while (chunkSamplesRemaining > 0) {
      int bufferSampleCount = Math.min(maxSampleCount, chunkSamplesRemaining);

      offsets[newSampleIndex] = sampleOffset;
      sizes[newSampleIndex] = fixedSampleSize * bufferSampleCount;
      maximumSize = Math.max(maximumSize, sizes[newSampleIndex]);
      timestamps[newSampleIndex] = (timestampDeltaInTimeUnits * originalSampleIndex);
      flags[newSampleIndex] = C.BUFFER_FLAG_KEY_FRAME;

      sampleOffset += sizes[newSampleIndex];
      originalSampleIndex += bufferSampleCount;

      chunkSamplesRemaining -= bufferSampleCount;
      newSampleIndex++;
    }
  }

  return new Results(offsets, sizes, maximumSize, timestamps, flags);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:49,代码来源:FixedSampleSizeRechunker.java

示例9: endMasterElement

void endMasterElement(int id) throws ParserException {
  switch (id) {
    case ID_SEGMENT_INFO:
      if (timecodeScale == C.TIME_UNSET) {
        // timecodeScale was omitted. Use the default value.
        timecodeScale = 1000000;
      }
      if (durationTimecode != C.TIME_UNSET) {
        durationUs = scaleTimecodeToUs(durationTimecode);
      }
      break;
    case ID_SEEK:
      if (seekEntryId == UNSET_ENTRY_ID || seekEntryPosition == C.POSITION_UNSET) {
        throw new ParserException("Mandatory element SeekID or SeekPosition not found");
      }
      if (seekEntryId == ID_CUES) {
        cuesContentPosition = seekEntryPosition;
      }
      break;
    case ID_CUES:
      if (!sentSeekMap) {
        extractorOutput.seekMap(buildSeekMap());
        sentSeekMap = true;
      } else {
        // We have already built the cues. Ignore.
      }
      break;
    case ID_BLOCK_GROUP:
      if (blockState != BLOCK_STATE_DATA) {
        // We've skipped this block (due to incompatible track number).
        return;
      }
      // If the ReferenceBlock element was not found for this sample, then it is a keyframe.
      if (!sampleSeenReferenceBlock) {
        blockFlags |= C.BUFFER_FLAG_KEY_FRAME;
      }
      commitSampleToOutput(tracks.get(blockTrackNumber), blockTimeUs);
      blockState = BLOCK_STATE_START;
      break;
    case ID_CONTENT_ENCODING:
      if (currentTrack.hasContentEncryption) {
        if (currentTrack.encryptionKeyId == null) {
          throw new ParserException("Encrypted Track found but ContentEncKeyID was not found");
        }
        currentTrack.drmInitData = new DrmInitData(
            new SchemeData(C.UUID_NIL, MimeTypes.VIDEO_WEBM, currentTrack.encryptionKeyId));
      }
      break;
    case ID_CONTENT_ENCODINGS:
      if (currentTrack.hasContentEncryption && currentTrack.sampleStrippedBytes != null) {
        throw new ParserException("Combining encryption and compression is not supported");
      }
      break;
    case ID_TRACK_ENTRY:
      if (isCodecSupported(currentTrack.codecId)) {
        currentTrack.initializeOutput(extractorOutput, currentTrack.number);
        tracks.put(currentTrack.number, currentTrack);
      }
      currentTrack = null;
      break;
    case ID_TRACKS:
      if (tracks.size() == 0) {
        throw new ParserException("No valid tracks were found");
      }
      extractorOutput.endTracks();
      break;
    default:
      break;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:70,代码来源:MatroskaExtractor.java

示例10: commitSample

public synchronized void commitSample(long timeUs, @C.BufferFlags int sampleFlags, long offset,
    int size, byte[] encryptionKey) {
  if (upstreamKeyframeRequired) {
    if ((sampleFlags & C.BUFFER_FLAG_KEY_FRAME) == 0) {
      return;
    }
    upstreamKeyframeRequired = false;
  }
  Assertions.checkState(!upstreamFormatRequired);
  commitSampleTimestamp(timeUs);
  timesUs[relativeWriteIndex] = timeUs;
  offsets[relativeWriteIndex] = offset;
  sizes[relativeWriteIndex] = size;
  flags[relativeWriteIndex] = sampleFlags;
  encryptionKeys[relativeWriteIndex] = encryptionKey;
  formats[relativeWriteIndex] = upstreamFormat;
  sourceIds[relativeWriteIndex] = upstreamSourceId;
  // Increment the write index.
  queueSize++;
  if (queueSize == capacity) {
    // Increase the capacity.
    int newCapacity = capacity + SAMPLE_CAPACITY_INCREMENT;
    int[] newSourceIds = new int[newCapacity];
    long[] newOffsets = new long[newCapacity];
    long[] newTimesUs = new long[newCapacity];
    int[] newFlags = new int[newCapacity];
    int[] newSizes = new int[newCapacity];
    byte[][] newEncryptionKeys = new byte[newCapacity][];
    Format[] newFormats = new Format[newCapacity];
    int beforeWrap = capacity - relativeReadIndex;
    System.arraycopy(offsets, relativeReadIndex, newOffsets, 0, beforeWrap);
    System.arraycopy(timesUs, relativeReadIndex, newTimesUs, 0, beforeWrap);
    System.arraycopy(flags, relativeReadIndex, newFlags, 0, beforeWrap);
    System.arraycopy(sizes, relativeReadIndex, newSizes, 0, beforeWrap);
    System.arraycopy(encryptionKeys, relativeReadIndex, newEncryptionKeys, 0, beforeWrap);
    System.arraycopy(formats, relativeReadIndex, newFormats, 0, beforeWrap);
    System.arraycopy(sourceIds, relativeReadIndex, newSourceIds, 0, beforeWrap);
    int afterWrap = relativeReadIndex;
    System.arraycopy(offsets, 0, newOffsets, beforeWrap, afterWrap);
    System.arraycopy(timesUs, 0, newTimesUs, beforeWrap, afterWrap);
    System.arraycopy(flags, 0, newFlags, beforeWrap, afterWrap);
    System.arraycopy(sizes, 0, newSizes, beforeWrap, afterWrap);
    System.arraycopy(encryptionKeys, 0, newEncryptionKeys, beforeWrap, afterWrap);
    System.arraycopy(formats, 0, newFormats, beforeWrap, afterWrap);
    System.arraycopy(sourceIds, 0, newSourceIds, beforeWrap, afterWrap);
    offsets = newOffsets;
    timesUs = newTimesUs;
    flags = newFlags;
    sizes = newSizes;
    encryptionKeys = newEncryptionKeys;
    formats = newFormats;
    sourceIds = newSourceIds;
    relativeReadIndex = 0;
    relativeWriteIndex = capacity;
    queueSize = capacity;
    capacity = newCapacity;
  } else {
    relativeWriteIndex++;
    if (relativeWriteIndex == capacity) {
      // Wrap around.
      relativeWriteIndex = 0;
    }
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:64,代码来源:DefaultTrackOutput.java


注:本文中的com.google.android.exoplayer2.C.BUFFER_FLAG_KEY_FRAME属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。