com.google.android.exoplayer2.util.TimestampAdjuster Java Examples

The following examples show how to use com.google.android.exoplayer2.util.TimestampAdjuster. 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: TsExtractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(
    @Mode int mode,
    TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(new byte[BUFFER_SIZE], 0);
  trackIds = new SparseBooleanArray();
  trackPids = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  durationReader = new TsDurationReader();
  pcrPid = -1;
  resetPayloadReaders();
}
 
Example #2
Source File: TsExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(
    @Mode int mode,
    TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(new byte[BUFFER_SIZE], 0);
  trackIds = new SparseBooleanArray();
  trackPids = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  durationReader = new TsDurationReader();
  pcrPid = -1;
  resetPayloadReaders();
}
 
Example #3
Source File: TsExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(
    @Mode int mode,
    TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(new byte[BUFFER_SIZE], 0);
  trackIds = new SparseBooleanArray();
  trackPids = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  durationReader = new TsDurationReader();
  pcrPid = -1;
  resetPayloadReaders();
}
 
Example #4
Source File: DefaultHlsExtractorFactory.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Result buildResultForSameExtractorType(
    Extractor previousExtractor, Format format, TimestampAdjuster timestampAdjuster) {
  if (previousExtractor instanceof WebvttExtractor) {
    return buildResult(new WebvttExtractor(format.language, timestampAdjuster));
  } else if (previousExtractor instanceof AdtsExtractor) {
    return buildResult(new AdtsExtractor());
  } else if (previousExtractor instanceof Ac3Extractor) {
    return buildResult(new Ac3Extractor());
  } else if (previousExtractor instanceof Ac4Extractor) {
    return buildResult(new Ac4Extractor());
  } else if (previousExtractor instanceof Mp3Extractor) {
    return buildResult(new Mp3Extractor());
  } else {
    return null;
  }
}
 
Example #5
Source File: DefaultHlsExtractorFactory.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static FragmentedMp4Extractor createFragmentedMp4Extractor(
    TimestampAdjuster timestampAdjuster,
    Format format,
    DrmInitData drmInitData,
    @Nullable List<Format> muxedCaptionFormats) {
  boolean isVariant = false;
  for (int i = 0; i < format.metadata.length(); i++) {
    Metadata.Entry entry = format.metadata.get(i);
    if (entry instanceof HlsTrackMetadataEntry) {
      isVariant = !((HlsTrackMetadataEntry) entry).variantInfos.isEmpty();
      break;
    }
  }
  // Only enable the EMSG TrackOutput if this is the 'variant' track (i.e. the main one) to avoid
  // creating a separate EMSG track for every audio track in a video stream.
  return new FragmentedMp4Extractor(
      /* flags= */ isVariant ? FragmentedMp4Extractor.FLAG_ENABLE_EMSG_TRACK : 0,
      timestampAdjuster,
      /* sideloadedTrack= */ null,
      drmInitData,
      muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList());
}
 
Example #6
Source File: DefaultHlsExtractorFactory.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static Result buildResultForSameExtractorType(
    Extractor previousExtractor, Format format, TimestampAdjuster timestampAdjuster) {
  if (previousExtractor instanceof WebvttExtractor) {
    return buildResult(new WebvttExtractor(format.language, timestampAdjuster));
  } else if (previousExtractor instanceof AdtsExtractor) {
    return buildResult(new AdtsExtractor());
  } else if (previousExtractor instanceof Ac3Extractor) {
    return buildResult(new Ac3Extractor());
  } else if (previousExtractor instanceof Ac4Extractor) {
    return buildResult(new Ac4Extractor());
  } else if (previousExtractor instanceof Mp3Extractor) {
    return buildResult(new Mp3Extractor());
  } else {
    return null;
  }
}
 
Example #7
Source File: TsExtractor.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_NORMAL}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(@Mode int mode, TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(BUFFER_SIZE);
  tsScratch = new ParsableBitArray(new byte[3]);
  trackIds = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  resetPayloadReaders();
}
 
Example #8
Source File: TsExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(
    @Mode int mode,
    TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(new byte[BUFFER_SIZE], 0);
  trackIds = new SparseBooleanArray();
  trackPids = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  durationReader = new TsDurationReader();
  pcrPid = -1;
  resetPayloadReaders();
}
 
Example #9
Source File: TsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
TsDurationReader() {
  pcrTimestampAdjuster = new TimestampAdjuster(/* firstSampleTimestampUs= */ 0);
  firstPcrValue = C.TIME_UNSET;
  lastPcrValue = C.TIME_UNSET;
  durationUs = C.TIME_UNSET;
  packetBuffer = new ParsableByteArray(DURATION_READ_BYTES);
}
 
Example #10
Source File: PsDurationReader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
PsDurationReader() {
  scrTimestampAdjuster = new TimestampAdjuster(/* firstSampleTimestampUs= */ 0);
  firstScrValue = C.TIME_UNSET;
  lastScrValue = C.TIME_UNSET;
  durationUs = C.TIME_UNSET;
  packetBuffer = new ParsableByteArray();
}
 
Example #11
Source File: TsBinarySearchSeeker.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public TsBinarySearchSeeker(
    TimestampAdjuster pcrTimestampAdjuster, long streamDurationUs, long inputLength, int pcrPid) {
  super(
      new DefaultSeekTimestampConverter(),
      new TsPcrSeeker(pcrPid, pcrTimestampAdjuster),
      streamDurationUs,
      /* floorTimePosition= */ 0,
      /* ceilingTimePosition= */ streamDurationUs + 1,
      /* floorBytePosition= */ 0,
      /* ceilingBytePosition= */ inputLength,
      /* approxBytesPerFrame= */ TsExtractor.TS_PACKET_SIZE,
      MINIMUM_SEARCH_RANGE_BYTES);
}
 
Example #12
Source File: PsBinarySearchSeeker.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public PsBinarySearchSeeker(
    TimestampAdjuster scrTimestampAdjuster, long streamDurationUs, long inputLength) {
  super(
      new DefaultSeekTimestampConverter(),
      new PsScrSeeker(scrTimestampAdjuster),
      streamDurationUs,
      /* floorTimePosition= */ 0,
      /* ceilingTimePosition= */ streamDurationUs + 1,
      /* floorBytePosition= */ 0,
      /* ceilingBytePosition= */ inputLength,
      /* approxBytesPerFrame= */ TsExtractor.TS_PACKET_SIZE,
      MINIMUM_SEARCH_RANGE_BYTES);
}
 
Example #13
Source File: SpliceInfoSectionReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(TimestampAdjuster timestampAdjuster, ExtractorOutput extractorOutput,
    TsPayloadReader.TrackIdGenerator idGenerator) {
  this.timestampAdjuster = timestampAdjuster;
  idGenerator.generateNewId();
  output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_METADATA);
  output.format(Format.createSampleFormat(idGenerator.getFormatId(), MimeTypes.APPLICATION_SCTE35,
      null, Format.NO_VALUE, null));
}
 
Example #14
Source File: TsBinarySearchSeeker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public TsBinarySearchSeeker(
    TimestampAdjuster pcrTimestampAdjuster, long streamDurationUs, long inputLength, int pcrPid) {
  super(
      new DefaultSeekTimestampConverter(),
      new TsPcrSeeker(pcrPid, pcrTimestampAdjuster),
      streamDurationUs,
      /* floorTimePosition= */ 0,
      /* ceilingTimePosition= */ streamDurationUs + 1,
      /* floorBytePosition= */ 0,
      /* ceilingBytePosition= */ inputLength,
      /* approxBytesPerFrame= */ TsExtractor.TS_PACKET_SIZE,
      MINIMUM_SEARCH_RANGE_BYTES);
}
 
Example #15
Source File: TsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
TsDurationReader() {
  pcrTimestampAdjuster = new TimestampAdjuster(/* firstSampleTimestampUs= */ 0);
  firstPcrValue = C.TIME_UNSET;
  lastPcrValue = C.TIME_UNSET;
  durationUs = C.TIME_UNSET;
  packetBuffer = new ParsableByteArray(DURATION_READ_BYTES);
}
 
Example #16
Source File: TsExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param defaultTsPayloadReaderFlags A combination of {@link DefaultTsPayloadReaderFactory}
 *     {@code FLAG_*} values that control the behavior of the payload readers.
 */
public TsExtractor(@Mode int mode, @Flags int defaultTsPayloadReaderFlags) {
  this(
      mode,
      new TimestampAdjuster(0),
      new DefaultTsPayloadReaderFactory(defaultTsPayloadReaderFlags));
}
 
Example #17
Source File: PsBinarySearchSeeker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public PsBinarySearchSeeker(
    TimestampAdjuster scrTimestampAdjuster, long streamDurationUs, long inputLength) {
  super(
      new DefaultSeekTimestampConverter(),
      new PsScrSeeker(scrTimestampAdjuster),
      streamDurationUs,
      /* floorTimePosition= */ 0,
      /* ceilingTimePosition= */ streamDurationUs + 1,
      /* floorBytePosition= */ 0,
      /* ceilingBytePosition= */ inputLength,
      /* approxBytesPerFrame= */ TsExtractor.TS_PACKET_SIZE,
      MINIMUM_SEARCH_RANGE_BYTES);
}
 
Example #18
Source File: HlsMediaChunk.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * @param dataSource The source from which the data should be loaded.
 * @param dataSpec Defines the data to be loaded.
 * @param initDataSpec Defines the initialization data to be fed to new extractors. May be null.
 * @param hlsUrl The url of the playlist from which this chunk was obtained.
 * @param muxedCaptionFormats List of muxed caption {@link Format}s.
 * @param trackSelectionReason See {@link #trackSelectionReason}.
 * @param trackSelectionData See {@link #trackSelectionData}.
 * @param startTimeUs The start time of the chunk in microseconds.
 * @param endTimeUs The end time of the chunk in microseconds.
 * @param chunkIndex The media sequence number of the chunk.
 * @param discontinuitySequenceNumber The discontinuity sequence number of the chunk.
 * @param isMasterTimestampSource True if the chunk can initialize the timestamp adjuster.
 * @param timestampAdjuster Adjuster corresponding to the provided discontinuity sequence number.
 * @param previousChunk The {@link HlsMediaChunk} that preceded this one. May be null.
 * @param encryptionKey For AES encryption chunks, the encryption key.
 * @param encryptionIv For AES encryption chunks, the encryption initialization vector.
 */
public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, DataSpec initDataSpec,
    HlsUrl hlsUrl, List<Format> muxedCaptionFormats, int trackSelectionReason,
    Object trackSelectionData, long startTimeUs, long endTimeUs, int chunkIndex,
    int discontinuitySequenceNumber, boolean isMasterTimestampSource,
    TimestampAdjuster timestampAdjuster, HlsMediaChunk previousChunk, byte[] encryptionKey,
    byte[] encryptionIv) {
  super(buildDataSource(dataSource, encryptionKey, encryptionIv), dataSpec, hlsUrl.format,
      trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkIndex);
  this.discontinuitySequenceNumber = discontinuitySequenceNumber;
  this.initDataSpec = initDataSpec;
  this.hlsUrl = hlsUrl;
  this.muxedCaptionFormats = muxedCaptionFormats;
  this.isMasterTimestampSource = isMasterTimestampSource;
  this.timestampAdjuster = timestampAdjuster;
  // Note: this.dataSource and dataSource may be different.
  this.isEncrypted = this.dataSource instanceof Aes128DataSource;
  lastPathSegment = dataSpec.uri.getLastPathSegment();
  isPackedAudio = lastPathSegment.endsWith(AAC_FILE_EXTENSION)
      || lastPathSegment.endsWith(AC3_FILE_EXTENSION)
      || lastPathSegment.endsWith(EC3_FILE_EXTENSION)
      || lastPathSegment.endsWith(MP3_FILE_EXTENSION);
  if (previousChunk != null) {
    id3Decoder = previousChunk.id3Decoder;
    id3Data = previousChunk.id3Data;
    previousExtractor = previousChunk.extractor;
    shouldSpliceIn = previousChunk.hlsUrl != hlsUrl;
    needNewExtractor = previousChunk.discontinuitySequenceNumber != discontinuitySequenceNumber
        || shouldSpliceIn;
  } else {
    id3Decoder = isPackedAudio ? new Id3Decoder() : null;
    id3Data = isPackedAudio ? new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH) : null;
    previousExtractor = null;
    shouldSpliceIn = false;
    needNewExtractor = true;
  }
  initDataSource = dataSource;
  uid = UID_SOURCE.getAndIncrement();
}
 
Example #19
Source File: TsBinarySearchSeeker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public TsBinarySearchSeeker(
    TimestampAdjuster pcrTimestampAdjuster, long streamDurationUs, long inputLength, int pcrPid) {
  super(
      new DefaultSeekTimestampConverter(),
      new TsPcrSeeker(pcrPid, pcrTimestampAdjuster),
      streamDurationUs,
      /* floorTimePosition= */ 0,
      /* ceilingTimePosition= */ streamDurationUs + 1,
      /* floorBytePosition= */ 0,
      /* ceilingBytePosition= */ inputLength,
      /* approxBytesPerFrame= */ TsExtractor.TS_PACKET_SIZE,
      MINIMUM_SEARCH_RANGE_BYTES);
}
 
Example #20
Source File: DefaultHlsExtractorFactory.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private Extractor createExtractorByFileExtension(
    Uri uri,
    Format format,
    List<Format> muxedCaptionFormats,
    DrmInitData drmInitData,
    TimestampAdjuster timestampAdjuster) {
  String lastPathSegment = uri.getLastPathSegment();
  if (lastPathSegment == null) {
    lastPathSegment = "";
  }
  if (MimeTypes.TEXT_VTT.equals(format.sampleMimeType)
      || lastPathSegment.endsWith(WEBVTT_FILE_EXTENSION)
      || lastPathSegment.endsWith(VTT_FILE_EXTENSION)) {
    return new WebvttExtractor(format.language, timestampAdjuster);
  } else if (lastPathSegment.endsWith(AAC_FILE_EXTENSION)) {
    return new AdtsExtractor();
  } else if (lastPathSegment.endsWith(AC3_FILE_EXTENSION)
      || lastPathSegment.endsWith(EC3_FILE_EXTENSION)) {
    return new Ac3Extractor();
  } else if (lastPathSegment.endsWith(AC4_FILE_EXTENSION)) {
    return new Ac4Extractor();
  } else if (lastPathSegment.endsWith(MP3_FILE_EXTENSION)) {
    return new Mp3Extractor(/* flags= */ 0, /* forcedFirstSampleTimestampUs= */ 0);
  } else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION)
      || lastPathSegment.startsWith(M4_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 4)
      || lastPathSegment.startsWith(MP4_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 5)
      || lastPathSegment.startsWith(CMF_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 5)) {
    return createFragmentedMp4Extractor(
        timestampAdjuster, format, drmInitData, muxedCaptionFormats);
  } else {
    // For any other file extension, we assume TS format.
    return createTsExtractor(
        payloadReaderFactoryFlags,
        exposeCea608WhenMissingDeclarations,
        format,
        muxedCaptionFormats,
        timestampAdjuster);
  }
}
 
Example #21
Source File: TsDurationReader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
TsDurationReader() {
  pcrTimestampAdjuster = new TimestampAdjuster(/* firstSampleTimestampUs= */ 0);
  firstPcrValue = C.TIME_UNSET;
  lastPcrValue = C.TIME_UNSET;
  durationUs = C.TIME_UNSET;
  packetBuffer = new ParsableByteArray();
}
 
Example #22
Source File: DefaultHlsExtractorFactory.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private Extractor createExtractorByFileExtension(
    Uri uri,
    Format format,
    @Nullable List<Format> muxedCaptionFormats,
    @Nullable DrmInitData drmInitData,
    TimestampAdjuster timestampAdjuster) {
  String lastPathSegment = uri.getLastPathSegment();
  if (lastPathSegment == null) {
    lastPathSegment = "";
  }
  if (MimeTypes.TEXT_VTT.equals(format.sampleMimeType)
      || lastPathSegment.endsWith(WEBVTT_FILE_EXTENSION)
      || lastPathSegment.endsWith(VTT_FILE_EXTENSION)) {
    return new WebvttExtractor(format.language, timestampAdjuster);
  } else if (lastPathSegment.endsWith(AAC_FILE_EXTENSION)) {
    return new AdtsExtractor();
  } else if (lastPathSegment.endsWith(AC3_FILE_EXTENSION)
      || lastPathSegment.endsWith(EC3_FILE_EXTENSION)) {
    return new Ac3Extractor();
  } else if (lastPathSegment.endsWith(AC4_FILE_EXTENSION)) {
    return new Ac4Extractor();
  } else if (lastPathSegment.endsWith(MP3_FILE_EXTENSION)) {
    return new Mp3Extractor(/* flags= */ 0, /* forcedFirstSampleTimestampUs= */ 0);
  } else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION)
      || lastPathSegment.startsWith(M4_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 4)
      || lastPathSegment.startsWith(MP4_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 5)
      || lastPathSegment.startsWith(CMF_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 5)) {
    return createFragmentedMp4Extractor(
        timestampAdjuster, format, drmInitData, muxedCaptionFormats);
  } else {
    // For any other file extension, we assume TS format.
    return createTsExtractor(
        payloadReaderFactoryFlags,
        exposeCea608WhenMissingDeclarations,
        format,
        muxedCaptionFormats,
        timestampAdjuster);
  }
}
 
Example #23
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param flags Flags that control the extractor's behavior.
 * @param timestampAdjuster Adjusts sample timestamps. May be null if no adjustment is needed.
 * @param sideloadedTrack Sideloaded track information, in the case that the extractor will not
 *     receive a moov box in the input data. Null if a moov box is expected.
 * @param sideloadedDrmInitData The {@link DrmInitData} to use for encrypted tracks. If null, the
 *     pssh boxes (if present) will be used.
 * @param closedCaptionFormats For tracks that contain SEI messages, the formats of the closed
 *     caption channels to expose.
 * @param additionalEmsgTrackOutput An extra track output that will receive all emsg messages
 *     targeting the player, even if {@link #FLAG_ENABLE_EMSG_TRACK} is not set. Null if special
 *     handling of emsg messages for players is not required.
 */
public FragmentedMp4Extractor(
    @Flags int flags,
    @Nullable TimestampAdjuster timestampAdjuster,
    @Nullable Track sideloadedTrack,
    @Nullable DrmInitData sideloadedDrmInitData,
    List<Format> closedCaptionFormats,
    @Nullable TrackOutput additionalEmsgTrackOutput) {
  this.flags = flags | (sideloadedTrack != null ? FLAG_SIDELOADED : 0);
  this.timestampAdjuster = timestampAdjuster;
  this.sideloadedTrack = sideloadedTrack;
  this.sideloadedDrmInitData = sideloadedDrmInitData;
  this.closedCaptionFormats = Collections.unmodifiableList(closedCaptionFormats);
  this.additionalEmsgTrackOutput = additionalEmsgTrackOutput;
  atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalPrefix = new ParsableByteArray(5);
  nalBuffer = new ParsableByteArray();
  extendedTypeScratch = new byte[16];
  containerAtoms = new ArrayDeque<>();
  pendingMetadataSampleInfos = new ArrayDeque<>();
  trackBundles = new SparseArray<>();
  durationUs = C.TIME_UNSET;
  pendingSeekTimeUs = C.TIME_UNSET;
  segmentIndexEarliestPresentationTimeUs = C.TIME_UNSET;
  enterReadingAtomHeaderState();
}
 
Example #24
Source File: PsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
PsDurationReader() {
  scrTimestampAdjuster = new TimestampAdjuster(/* firstSampleTimestampUs= */ 0);
  firstScrValue = C.TIME_UNSET;
  lastScrValue = C.TIME_UNSET;
  durationUs = C.TIME_UNSET;
  packetBuffer = new ParsableByteArray(DURATION_READ_BYTES);
}
 
Example #25
Source File: PsDurationReader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
PsDurationReader() {
  scrTimestampAdjuster = new TimestampAdjuster(/* firstSampleTimestampUs= */ 0);
  firstScrValue = C.TIME_UNSET;
  lastScrValue = C.TIME_UNSET;
  durationUs = C.TIME_UNSET;
  packetBuffer = new ParsableByteArray();
}
 
Example #26
Source File: HlsMediaChunk.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void loadMedia() throws IOException, InterruptedException {
  if (!isMasterTimestampSource) {
    timestampAdjuster.waitUntilInitialized();
  } else if (timestampAdjuster.getFirstSampleTimestampUs() == TimestampAdjuster.DO_NOT_OFFSET) {
    // We're the master and we haven't set the desired first sample timestamp yet.
    timestampAdjuster.setFirstSampleTimestampUs(startTimeUs);
  }
  feedDataToExtractor(dataSource, dataSpec, mediaSegmentEncrypted);
}
 
Example #27
Source File: PsBinarySearchSeeker.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private PsScrSeeker(TimestampAdjuster scrTimestampAdjuster) {
  this.scrTimestampAdjuster = scrTimestampAdjuster;
  packetBuffer = new ParsableByteArray();
}
 
Example #28
Source File: TsExtractor.java    From K-Sonic with MIT License 4 votes vote down vote up
public TsExtractor() {
  this(MODE_NORMAL, new TimestampAdjuster(0), new DefaultTsPayloadReaderFactory());
}
 
Example #29
Source File: TimeSignalCommand.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
static TimeSignalCommand parseFromSection(ParsableByteArray sectionData,
    long ptsAdjustment, TimestampAdjuster timestampAdjuster) {
  long ptsTime = parseSpliceTime(sectionData, ptsAdjustment);
  long playbackPositionUs = timestampAdjuster.adjustTsTimestamp(ptsTime);
  return new TimeSignalCommand(ptsTime, playbackPositionUs);
}
 
Example #30
Source File: PsExtractor.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public PesReader(ElementaryStreamReader pesPayloadReader, TimestampAdjuster timestampAdjuster) {
  this.pesPayloadReader = pesPayloadReader;
  this.timestampAdjuster = timestampAdjuster;
  pesScratch = new ParsableBitArray(new byte[PES_SCRATCH_SIZE]);
}