Java Code Examples for com.google.android.exoplayer2.util.MimeTypes#VIDEO_WEBM

The following examples show how to use com.google.android.exoplayer2.util.MimeTypes#VIDEO_WEBM . 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 MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Called when the end of a master element is encountered.
 *
 * @see EbmlProcessor#endMasterElement(int)
 */
@CallSuper
protected 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;
      }
      // Commit sample metadata.
      int sampleOffset = 0;
      for (int i = 0; i < blockSampleCount; i++) {
        sampleOffset += blockSampleSizes[i];
      }
      Track track = tracks.get(blockTrackNumber);
      for (int i = 0; i < blockSampleCount; i++) {
        long sampleTimeUs = blockTimeUs + (i * track.defaultSampleDurationNs) / 1000;
        int sampleFlags = blockFlags;
        if (i == 0 && !blockHasReferenceBlock) {
          // If the ReferenceBlock element was not found in this block, then the first frame is a
          // keyframe.
          sampleFlags |= C.BUFFER_FLAG_KEY_FRAME;
        }
        int sampleSize = blockSampleSizes[i];
        sampleOffset -= sampleSize; // The offset is to the end of the sample.
        commitSampleToOutput(track, sampleTimeUs, sampleFlags, sampleSize, sampleOffset);
      }
      blockState = BLOCK_STATE_START;
      break;
    case ID_CONTENT_ENCODING:
      if (currentTrack.hasContentEncryption) {
        if (currentTrack.cryptoData == 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.cryptoData.encryptionKey));
      }
      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;
  }
}
 
Example 2
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
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.cryptoData == 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.cryptoData.encryptionKey));
      }
      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;
  }
}
 
Example 3
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
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.cryptoData == 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.cryptoData.encryptionKey));
      }
      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;
  }
}
 
Example 4
Source File: MatroskaExtractor.java    From K-Sonic with MIT License 4 votes vote down vote up
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;
  }
}
 
Example 5
Source File: MatroskaExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Called when the end of a master element is encountered.
 *
 * @see EbmlProcessor#endMasterElement(int)
 */
@CallSuper
protected 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.cryptoData == 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.cryptoData.encryptionKey));
      }
      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;
  }
}
 
Example 6
Source File: MatroskaExtractor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Called when the end of a master element is encountered.
 *
 * @see EbmlProcessor#endMasterElement(int)
 */
@CallSuper
protected 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.cryptoData == 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.cryptoData.encryptionKey));
      }
      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;
  }
}