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

The following examples show how to use com.google.android.exoplayer2.util.NalUnitUtil. 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: MatroskaExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
MatroskaExtractor(EbmlReader reader, @Flags int flags) {
  this.reader = reader;
  this.reader.init(new InnerEbmlProcessor());
  seekForCuesEnabled = (flags & FLAG_DISABLE_SEEK_FOR_CUES) == 0;
  varintReader = new VarintReader();
  tracks = new SparseArray<>();
  scratch = new ParsableByteArray(4);
  vorbisNumPageSamples = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
  seekEntryIdBytes = new ParsableByteArray(4);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  sampleStrippedBytes = new ParsableByteArray();
  subtitleSample = new ParsableByteArray();
  encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
  encryptionSubsampleData = new ParsableByteArray();
}
 
Example #2
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 6 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.
 */
public FragmentedMp4Extractor(@Flags int flags, TimestampAdjuster timestampAdjuster,
    Track sideloadedTrack) {
  this.flags = flags | (sideloadedTrack != null ? FLAG_SIDELOADED : 0);
  this.timestampAdjuster = timestampAdjuster;
  this.sideloadedTrack = sideloadedTrack;
  atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalPrefix = new ParsableByteArray(5);
  nalBuffer = new ParsableByteArray();
  encryptionSignalByte = new ParsableByteArray(1);
  extendedTypeScratch = new byte[16];
  containerAtoms = new Stack<>();
  pendingMetadataSampleInfos = new LinkedList<>();
  trackBundles = new SparseArray<>();
  durationUs = C.TIME_UNSET;
  segmentIndexEarliestPresentationTimeUs = C.TIME_UNSET;
  enterReadingAtomHeaderState();
}
 
Example #3
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
MatroskaExtractor(EbmlReader reader, @Flags int flags) {
  this.reader = reader;
  this.reader.init(new InnerEbmlReaderOutput());
  seekForCuesEnabled = (flags & FLAG_DISABLE_SEEK_FOR_CUES) == 0;
  varintReader = new VarintReader();
  tracks = new SparseArray<>();
  scratch = new ParsableByteArray(4);
  vorbisNumPageSamples = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
  seekEntryIdBytes = new ParsableByteArray(4);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  sampleStrippedBytes = new ParsableByteArray();
  subtitleSample = new ParsableByteArray();
  encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
  encryptionSubsampleData = new ParsableByteArray();
}
 
Example #4
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
MatroskaExtractor(EbmlReader reader, @Flags int flags) {
  this.reader = reader;
  this.reader.init(new InnerEbmlReaderOutput());
  seekForCuesEnabled = (flags & FLAG_DISABLE_SEEK_FOR_CUES) == 0;
  varintReader = new VarintReader();
  tracks = new SparseArray<>();
  scratch = new ParsableByteArray(4);
  vorbisNumPageSamples = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
  seekEntryIdBytes = new ParsableByteArray(4);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  sampleStrippedBytes = new ParsableByteArray();
  subtitleSample = new ParsableByteArray();
  encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
  encryptionSubsampleData = new ParsableByteArray();
}
 
Example #5
Source File: MatroskaExtractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
MatroskaExtractor(EbmlReader reader, @Flags int flags) {
  this.reader = reader;
  this.reader.init(new InnerEbmlProcessor());
  seekForCuesEnabled = (flags & FLAG_DISABLE_SEEK_FOR_CUES) == 0;
  varintReader = new VarintReader();
  tracks = new SparseArray<>();
  scratch = new ParsableByteArray(4);
  vorbisNumPageSamples = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
  seekEntryIdBytes = new ParsableByteArray(4);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  sampleStrippedBytes = new ParsableByteArray();
  subtitleSample = new ParsableByteArray();
  encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
  encryptionSubsampleData = new ParsableByteArray();
  blockAdditionalData = new ParsableByteArray();
}
 
Example #6
Source File: MatroskaExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
MatroskaExtractor(EbmlReader reader, @Flags int flags) {
  this.reader = reader;
  this.reader.init(new InnerEbmlProcessor());
  seekForCuesEnabled = (flags & FLAG_DISABLE_SEEK_FOR_CUES) == 0;
  varintReader = new VarintReader();
  tracks = new SparseArray<>();
  scratch = new ParsableByteArray(4);
  vorbisNumPageSamples = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
  seekEntryIdBytes = new ParsableByteArray(4);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  sampleStrippedBytes = new ParsableByteArray();
  subtitleSample = new ParsableByteArray();
  encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
  encryptionSubsampleData = new ParsableByteArray();
}
 
Example #7
Source File: MatroskaExtractor.java    From K-Sonic with MIT License 5 votes vote down vote up
MatroskaExtractor(EbmlReader reader) {
  this.reader = reader;
  this.reader.init(new InnerEbmlReaderOutput());
  varintReader = new VarintReader();
  tracks = new SparseArray<>();
  scratch = new ParsableByteArray(4);
  vorbisNumPageSamples = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
  seekEntryIdBytes = new ParsableByteArray(4);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  sampleStrippedBytes = new ParsableByteArray();
  subripSample = new ParsableByteArray();
  encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
  encryptionSubsampleData = new ParsableByteArray();
}
 
Example #8
Source File: H262Reader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  csdBuffer.reset();
  if (userDataReader != null) {
    userData.reset();
  }
  totalBytesWritten = 0;
  startedFirstSample = false;
}
 
Example #9
Source File: H265Reader.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  vps.reset();
  sps.reset();
  pps.reset();
  prefixSei.reset();
  suffixSei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
}
 
Example #10
Source File: H264Reader.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  sps.reset();
  pps.reset();
  sei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
}
 
Example #11
Source File: H262Reader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  csdBuffer.reset();
  if (userDataReader != null) {
    userData.reset();
  }
  totalBytesWritten = 0;
  startedFirstSample = false;
}
 
Example #12
Source File: AvcConfig.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses AVC configuration data.
 *
 * @param data A {@link ParsableByteArray}, whose position is set to the start of the AVC
 *     configuration data to parse.
 * @return A parsed representation of the HEVC configuration data.
 * @throws ParserException If an error occurred parsing the data.
 */
public static AvcConfig parse(ParsableByteArray data) throws ParserException {
  try {
    data.skipBytes(4); // Skip to the AVCDecoderConfigurationRecord (defined in 14496-15)
    int nalUnitLengthFieldLength = (data.readUnsignedByte() & 0x3) + 1;
    if (nalUnitLengthFieldLength == 3) {
      throw new IllegalStateException();
    }
    List<byte[]> initializationData = new ArrayList<>();
    int numSequenceParameterSets = data.readUnsignedByte() & 0x1F;
    for (int j = 0; j < numSequenceParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }
    int numPictureParameterSets = data.readUnsignedByte();
    for (int j = 0; j < numPictureParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }

    int width = Format.NO_VALUE;
    int height = Format.NO_VALUE;
    float pixelWidthAspectRatio = 1;
    if (numSequenceParameterSets > 0) {
      byte[] sps = initializationData.get(0);
      SpsData spsData = NalUnitUtil.parseSpsNalUnit(initializationData.get(0),
          nalUnitLengthFieldLength, sps.length);
      width = spsData.width;
      height = spsData.height;
      pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
    }
    return new AvcConfig(initializationData, nalUnitLengthFieldLength, width, height,
        pixelWidthAspectRatio);
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new ParserException("Error parsing AVC config", e);
  }
}
 
Example #13
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 #14
Source File: Mp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new extractor for unfragmented MP4 streams, using the specified flags to control the
 * extractor's behavior.
 *
 * @param flags Flags that control the extractor's behavior.
 */
public Mp4Extractor(@Flags int flags) {
  this.flags = flags;
  atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE);
  containerAtoms = new ArrayDeque<>();
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  sampleTrackIndex = C.INDEX_UNSET;
}
 
Example #15
Source File: H265Reader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  vps.reset();
  sps.reset();
  pps.reset();
  prefixSei.reset();
  suffixSei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
}
 
Example #16
Source File: AvcConfig.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Parses AVC configuration data.
 *
 * @param data A {@link ParsableByteArray}, whose position is set to the start of the AVC
 *     configuration data to parse.
 * @return A parsed representation of the HEVC configuration data.
 * @throws ParserException If an error occurred parsing the data.
 */
public static AvcConfig parse(ParsableByteArray data) throws ParserException {
  try {
    data.skipBytes(4); // Skip to the AVCDecoderConfigurationRecord (defined in 14496-15)
    int nalUnitLengthFieldLength = (data.readUnsignedByte() & 0x3) + 1;
    if (nalUnitLengthFieldLength == 3) {
      throw new IllegalStateException();
    }
    List<byte[]> initializationData = new ArrayList<>();
    int numSequenceParameterSets = data.readUnsignedByte() & 0x1F;
    for (int j = 0; j < numSequenceParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }
    int numPictureParameterSets = data.readUnsignedByte();
    for (int j = 0; j < numPictureParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }

    int width = Format.NO_VALUE;
    int height = Format.NO_VALUE;
    float pixelWidthAspectRatio = 1;
    if (numSequenceParameterSets > 0) {
      byte[] sps = initializationData.get(0);
      SpsData spsData = NalUnitUtil.parseSpsNalUnit(initializationData.get(0),
          nalUnitLengthFieldLength, sps.length);
      width = spsData.width;
      height = spsData.height;
      pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
    }
    return new AvcConfig(initializationData, nalUnitLengthFieldLength, width, height,
        pixelWidthAspectRatio);
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new ParserException("Error parsing AVC config", e);
  }
}
 
Example #17
Source File: H265Reader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  vps.reset();
  sps.reset();
  pps.reset();
  prefixSei.reset();
  suffixSei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
}
 
Example #18
Source File: AvcConfig.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Parses AVC configuration data.
 *
 * @param data A {@link ParsableByteArray}, whose position is set to the start of the AVC
 *     configuration data to parse.
 * @return A parsed representation of the HEVC configuration data.
 * @throws ParserException If an error occurred parsing the data.
 */
public static AvcConfig parse(ParsableByteArray data) throws ParserException {
  try {
    data.skipBytes(4); // Skip to the AVCDecoderConfigurationRecord (defined in 14496-15)
    int nalUnitLengthFieldLength = (data.readUnsignedByte() & 0x3) + 1;
    if (nalUnitLengthFieldLength == 3) {
      throw new IllegalStateException();
    }
    List<byte[]> initializationData = new ArrayList<>();
    int numSequenceParameterSets = data.readUnsignedByte() & 0x1F;
    for (int j = 0; j < numSequenceParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }
    int numPictureParameterSets = data.readUnsignedByte();
    for (int j = 0; j < numPictureParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }

    int width = Format.NO_VALUE;
    int height = Format.NO_VALUE;
    float pixelWidthAspectRatio = 1;
    if (numSequenceParameterSets > 0) {
      byte[] sps = initializationData.get(0);
      SpsData spsData = NalUnitUtil.parseSpsNalUnit(initializationData.get(0),
          nalUnitLengthFieldLength, sps.length);
      width = spsData.width;
      height = spsData.height;
      pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
    }
    return new AvcConfig(initializationData, nalUnitLengthFieldLength, width, height,
        pixelWidthAspectRatio);
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new ParserException("Error parsing AVC config", e);
  }
}
 
Example #19
Source File: H262Reader.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  csdBuffer.reset();
  pesPtsUsAvailable = false;
  foundFirstFrameInGroup = false;
  totalBytesWritten = 0;
}
 
Example #20
Source File: H264Reader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  sps.reset();
  pps.reset();
  sei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
  randomAccessIndicator = false;
}
 
Example #21
Source File: H265Reader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  vps.reset();
  sps.reset();
  pps.reset();
  prefixSei.reset();
  suffixSei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
}
 
Example #22
Source File: Mp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new extractor for unfragmented MP4 streams, using the specified flags to control the
 * extractor's behavior.
 *
 * @param flags Flags that control the extractor's behavior.
 */
public Mp4Extractor(@Flags int flags) {
  this.flags = flags;
  atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE);
  containerAtoms = new ArrayDeque<>();
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  scratch = new ParsableByteArray();
  sampleTrackIndex = C.INDEX_UNSET;
}
 
Example #23
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS 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;
  eventMessageEncoder = new EventMessageEncoder();
  atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalPrefix = new ParsableByteArray(5);
  nalBuffer = new ParsableByteArray();
  scratchBytes = new byte[16];
  scratch = new ParsableByteArray(scratchBytes);
  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: AvcConfig.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses AVC configuration data.
 *
 * @param data A {@link ParsableByteArray}, whose position is set to the start of the AVC
 *     configuration data to parse.
 * @return A parsed representation of the HEVC configuration data.
 * @throws ParserException If an error occurred parsing the data.
 */
public static AvcConfig parse(ParsableByteArray data) throws ParserException {
  try {
    data.skipBytes(4); // Skip to the AVCDecoderConfigurationRecord (defined in 14496-15)
    int nalUnitLengthFieldLength = (data.readUnsignedByte() & 0x3) + 1;
    if (nalUnitLengthFieldLength == 3) {
      throw new IllegalStateException();
    }
    List<byte[]> initializationData = new ArrayList<>();
    int numSequenceParameterSets = data.readUnsignedByte() & 0x1F;
    for (int j = 0; j < numSequenceParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }
    int numPictureParameterSets = data.readUnsignedByte();
    for (int j = 0; j < numPictureParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }

    int width = Format.NO_VALUE;
    int height = Format.NO_VALUE;
    float pixelWidthAspectRatio = 1;
    if (numSequenceParameterSets > 0) {
      byte[] sps = initializationData.get(0);
      SpsData spsData = NalUnitUtil.parseSpsNalUnit(initializationData.get(0),
          nalUnitLengthFieldLength, sps.length);
      width = spsData.width;
      height = spsData.height;
      pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
    }
    return new AvcConfig(initializationData, nalUnitLengthFieldLength, width, height,
        pixelWidthAspectRatio);
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new ParserException("Error parsing AVC config", e);
  }
}
 
Example #25
Source File: H262Reader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  csdBuffer.reset();
  if (userDataReader != null) {
    userData.reset();
  }
  totalBytesWritten = 0;
  startedFirstSample = false;
}
 
Example #26
Source File: H264Reader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  sps.reset();
  pps.reset();
  sei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
  randomAccessIndicator = false;
}
 
Example #27
Source File: H265Reader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seek() {
  NalUnitUtil.clearPrefixFlags(prefixFlags);
  vps.reset();
  sps.reset();
  pps.reset();
  prefixSei.reset();
  suffixSei.reset();
  sampleReader.reset();
  totalBytesWritten = 0;
}
 
Example #28
Source File: Mp4Extractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new extractor for unfragmented MP4 streams, using the specified flags to control the
 * extractor's behavior.
 *
 * @param flags Flags that control the extractor's behavior.
 */
public Mp4Extractor(@Flags int flags) {
  this.flags = flags;
  atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE);
  containerAtoms = new ArrayDeque<>();
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalLength = new ParsableByteArray(4);
  scratch = new ParsableByteArray();
  sampleTrackIndex = C.INDEX_UNSET;
}
 
Example #29
Source File: FragmentedMp4Extractor.java    From Telegram 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;
  eventMessageEncoder = new EventMessageEncoder();
  atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE);
  nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
  nalPrefix = new ParsableByteArray(5);
  nalBuffer = new ParsableByteArray();
  scratchBytes = new byte[16];
  scratch = new ParsableByteArray(scratchBytes);
  containerAtoms = new ArrayDeque<>();
  pendingMetadataSampleInfos = new ArrayDeque<>();
  trackBundles = new SparseArray<>();
  durationUs = C.TIME_UNSET;
  pendingSeekTimeUs = C.TIME_UNSET;
  segmentIndexEarliestPresentationTimeUs = C.TIME_UNSET;
  enterReadingAtomHeaderState();
}
 
Example #30
Source File: AvcConfig.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses AVC configuration data.
 *
 * @param data A {@link ParsableByteArray}, whose position is set to the start of the AVC
 *     configuration data to parse.
 * @return A parsed representation of the HEVC configuration data.
 * @throws ParserException If an error occurred parsing the data.
 */
public static AvcConfig parse(ParsableByteArray data) throws ParserException {
  try {
    data.skipBytes(4); // Skip to the AVCDecoderConfigurationRecord (defined in 14496-15)
    int nalUnitLengthFieldLength = (data.readUnsignedByte() & 0x3) + 1;
    if (nalUnitLengthFieldLength == 3) {
      throw new IllegalStateException();
    }
    List<byte[]> initializationData = new ArrayList<>();
    int numSequenceParameterSets = data.readUnsignedByte() & 0x1F;
    for (int j = 0; j < numSequenceParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }
    int numPictureParameterSets = data.readUnsignedByte();
    for (int j = 0; j < numPictureParameterSets; j++) {
      initializationData.add(buildNalUnitForChild(data));
    }

    int width = Format.NO_VALUE;
    int height = Format.NO_VALUE;
    float pixelWidthAspectRatio = 1;
    if (numSequenceParameterSets > 0) {
      byte[] sps = initializationData.get(0);
      SpsData spsData = NalUnitUtil.parseSpsNalUnit(initializationData.get(0),
          nalUnitLengthFieldLength, sps.length);
      width = spsData.width;
      height = spsData.height;
      pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
    }
    return new AvcConfig(initializationData, nalUnitLengthFieldLength, width, height,
        pixelWidthAspectRatio);
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new ParserException("Error parsing AVC config", e);
  }
}