com.google.android.exoplayer2.drm.DrmInitData Java Examples
The following examples show how to use
com.google.android.exoplayer2.drm.DrmInitData.
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: Format.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public static Format createAudioSampleFormat( @Nullable String id, @Nullable String sampleMimeType, @Nullable String codecs, int bitrate, int maxInputSize, int channelCount, int sampleRate, @Nullable List<byte[]> initializationData, @Nullable DrmInitData drmInitData, @C.SelectionFlags int selectionFlags, @Nullable String language) { return createAudioSampleFormat( id, sampleMimeType, codecs, bitrate, maxInputSize, channelCount, sampleRate, /* pcmEncoding= */ NO_VALUE, initializationData, drmInitData, selectionFlags, language); }
Example #2
Source File: DtsUtil.java From K-Sonic with MIT License | 6 votes |
/** * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114 * subsections 5.3/5.4. * * @param frame The DTS frame to parse. * @param trackId The track identifier to set on the format, or null. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The DTS format parsed from data in the header. */ public static Format parseDtsFormat(byte[] frame, String trackId, String language, DrmInitData drmInitData) { ParsableBitArray frameBits = new ParsableBitArray(frame); frameBits.skipBits(4 * 8 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE int amode = frameBits.readBits(6); int channelCount = CHANNELS_BY_AMODE[amode]; int sfreq = frameBits.readBits(4); int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq]; int rate = frameBits.readBits(5); int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2; frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language); }
Example #3
Source File: Format.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public static Format createTextSampleFormat( @Nullable String id, @Nullable String sampleMimeType, @Nullable String codecs, int bitrate, @C.SelectionFlags int selectionFlags, @Nullable String language, int accessibilityChannel, @Nullable DrmInitData drmInitData) { return createTextSampleFormat( id, sampleMimeType, codecs, bitrate, selectionFlags, language, accessibilityChannel, drmInitData, OFFSET_SAMPLE_RELATIVE, Collections.emptyList()); }
Example #4
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114 * subsections 5.3/5.4. * * @param frame The DTS frame to parse. * @param trackId The track identifier to set on the format. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The DTS format parsed from data in the header. */ public static Format parseDtsFormat( byte[] frame, String trackId, String language, DrmInitData drmInitData) { ParsableBitArray frameBits = getNormalizedFrameHeader(frame); frameBits.skipBits(32 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE int amode = frameBits.readBits(6); int channelCount = CHANNELS_BY_AMODE[amode]; int sfreq = frameBits.readBits(4); int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq]; int rate = frameBits.readBits(5); int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2; frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language); }
Example #5
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114 * subsections 5.3/5.4. * * @param frame The DTS frame to parse. * @param trackId The track identifier to set on the format. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The DTS format parsed from data in the header. */ public static Format parseDtsFormat( byte[] frame, String trackId, String language, DrmInitData drmInitData) { ParsableBitArray frameBits = getNormalizedFrameHeader(frame); frameBits.skipBits(32 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE int amode = frameBits.readBits(6); int channelCount = CHANNELS_BY_AMODE[amode]; int sfreq = frameBits.readBits(4); int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq]; int rate = frameBits.readBits(5); int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2; frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language); }
Example #6
Source File: FragmentedMp4Extractor.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** Returns DrmInitData from leaf atoms. */ private static DrmInitData getDrmInitDataFromAtoms(List<Atom.LeafAtom> leafChildren) { ArrayList<SchemeData> schemeDatas = null; int leafChildrenSize = leafChildren.size(); for (int i = 0; i < leafChildrenSize; i++) { LeafAtom child = leafChildren.get(i); if (child.type == Atom.TYPE_pssh) { if (schemeDatas == null) { schemeDatas = new ArrayList<>(); } byte[] psshData = child.data.data; UUID uuid = PsshAtomUtil.parseUuid(psshData); if (uuid == null) { Log.w(TAG, "Skipped pssh atom (failed to extract uuid)"); } else { schemeDatas.add(new SchemeData(uuid, MimeTypes.VIDEO_MP4, psshData)); } } } return schemeDatas == null ? null : new DrmInitData(schemeDatas); }
Example #7
Source File: FragmentedMp4Extractor.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** Returns DrmInitData from leaf atoms. */ private static DrmInitData getDrmInitDataFromAtoms(List<Atom.LeafAtom> leafChildren) { ArrayList<SchemeData> schemeDatas = null; int leafChildrenSize = leafChildren.size(); for (int i = 0; i < leafChildrenSize; i++) { LeafAtom child = leafChildren.get(i); if (child.type == Atom.TYPE_pssh) { if (schemeDatas == null) { schemeDatas = new ArrayList<>(); } byte[] psshData = child.data.data; UUID uuid = PsshAtomUtil.parseUuid(psshData); if (uuid == null) { Log.w(TAG, "Skipped pssh atom (failed to extract uuid)"); } else { schemeDatas.add(new SchemeData(uuid, MimeTypes.VIDEO_MP4, psshData)); } } } return schemeDatas == null ? null : new DrmInitData(schemeDatas); }
Example #8
Source File: HlsMediaPeriod.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private static Map<String, DrmInitData> deriveOverridingDrmInitData( List<DrmInitData> sessionKeyDrmInitData) { ArrayList<DrmInitData> mutableSessionKeyDrmInitData = new ArrayList<>(sessionKeyDrmInitData); HashMap<String, DrmInitData> drmInitDataBySchemeType = new HashMap<>(); for (int i = 0; i < mutableSessionKeyDrmInitData.size(); i++) { DrmInitData drmInitData = sessionKeyDrmInitData.get(i); String scheme = drmInitData.schemeType; // Merge any subsequent drmInitData instances that have the same scheme type. This is valid // due to the assumptions documented on HlsMediaSource.Builder.setUseSessionKeys, and is // necessary to get data for different CDNs (e.g. Widevine and PlayReady) into a single // drmInitData. int j = i + 1; while (j < mutableSessionKeyDrmInitData.size()) { DrmInitData nextDrmInitData = mutableSessionKeyDrmInitData.get(j); if (TextUtils.equals(nextDrmInitData.schemeType, scheme)) { drmInitData = drmInitData.merge(nextDrmInitData); mutableSessionKeyDrmInitData.remove(j); } else { j++; } } drmInitDataBySchemeType.put(scheme, drmInitData); } return drmInitDataBySchemeType; }
Example #9
Source File: Ac3Util.java From K-Sonic with MIT License | 6 votes |
/** * Returns the E-AC-3 format given {@code data} containing a syncframe. The reading position of * {@code data} will be modified. * * @param data The data to parse, positioned at the start of the syncframe. * @param trackId The track identifier to set on the format, or null. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The E-AC-3 format parsed from data in the header. */ public static Format parseEac3SyncframeFormat(ParsableBitArray data, String trackId, String language, DrmInitData drmInitData) { data.skipBits(16 + 2 + 3 + 11); // syncword, strmtype, substreamid, frmsiz int sampleRate; int fscod = data.readBits(2); if (fscod == 3) { sampleRate = SAMPLE_RATE_BY_FSCOD2[data.readBits(2)]; } else { data.skipBits(2); // numblkscod sampleRate = SAMPLE_RATE_BY_FSCOD[fscod]; } int acmod = data.readBits(3); boolean lfeon = data.readBit(); return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_E_AC3, null, Format.NO_VALUE, Format.NO_VALUE, CHANNEL_COUNT_BY_ACMOD[acmod] + (lfeon ? 1 : 0), sampleRate, null, drmInitData, 0, language); }
Example #10
Source File: HlsMediaPeriod.java From MediaSDK with Apache License 2.0 | 6 votes |
private static Map<String, DrmInitData> deriveOverridingDrmInitData( List<DrmInitData> sessionKeyDrmInitData) { ArrayList<DrmInitData> mutableSessionKeyDrmInitData = new ArrayList<>(sessionKeyDrmInitData); HashMap<String, DrmInitData> drmInitDataBySchemeType = new HashMap<>(); for (int i = 0; i < mutableSessionKeyDrmInitData.size(); i++) { DrmInitData drmInitData = sessionKeyDrmInitData.get(i); String scheme = drmInitData.schemeType; // Merge any subsequent drmInitData instances that have the same scheme type. This is valid // due to the assumptions documented on HlsMediaSource.Builder.setUseSessionKeys, and is // necessary to get data for different CDNs (e.g. Widevine and PlayReady) into a single // drmInitData. int j = i + 1; while (j < mutableSessionKeyDrmInitData.size()) { DrmInitData nextDrmInitData = mutableSessionKeyDrmInitData.get(j); if (TextUtils.equals(nextDrmInitData.schemeType, scheme)) { drmInitData = drmInitData.merge(nextDrmInitData); mutableSessionKeyDrmInitData.remove(j); } else { j++; } } drmInitDataBySchemeType.put(scheme, drmInitData); } return drmInitDataBySchemeType; }
Example #11
Source File: DashUtil.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Loads {@link DrmInitData} for a given period in a DASH manifest. * * @param dataSource The {@link HttpDataSource} from which data should be loaded. * @param period The {@link Period}. * @return The loaded {@link DrmInitData}, or null if none is defined. * @throws IOException Thrown when there is an error while loading. * @throws InterruptedException Thrown if the thread was interrupted. */ public static @Nullable DrmInitData loadDrmInitData(DataSource dataSource, Period period) throws IOException, InterruptedException { int primaryTrackType = C.TRACK_TYPE_VIDEO; Representation representation = getFirstRepresentation(period, primaryTrackType); if (representation == null) { primaryTrackType = C.TRACK_TYPE_AUDIO; representation = getFirstRepresentation(period, primaryTrackType); if (representation == null) { return null; } } Format manifestFormat = representation.format; Format sampleFormat = DashUtil.loadSampleFormat(dataSource, primaryTrackType, representation); return sampleFormat == null ? manifestFormat.drmInitData : sampleFormat.copyWithManifestFormatInfo(manifestFormat).drmInitData; }
Example #12
Source File: FragmentedMp4Extractor.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** Returns DrmInitData from leaf atoms. */ private static DrmInitData getDrmInitDataFromAtoms(List<Atom.LeafAtom> leafChildren) { ArrayList<SchemeData> schemeDatas = null; int leafChildrenSize = leafChildren.size(); for (int i = 0; i < leafChildrenSize; i++) { LeafAtom child = leafChildren.get(i); if (child.type == Atom.TYPE_pssh) { if (schemeDatas == null) { schemeDatas = new ArrayList<>(); } byte[] psshData = child.data.data; UUID uuid = PsshAtomUtil.parseUuid(psshData); if (uuid == null) { Log.w(TAG, "Skipped pssh atom (failed to extract uuid)"); } else { schemeDatas.add(new SchemeData(uuid, MimeTypes.VIDEO_MP4, psshData)); } } } return schemeDatas == null ? null : new DrmInitData(schemeDatas); }
Example #13
Source File: SsManifestParser.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public Object build() { StreamElement[] streamElementArray = new StreamElement[streamElements.size()]; streamElements.toArray(streamElementArray); if (protectionElement != null) { DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid, MimeTypes.VIDEO_MP4, protectionElement.data)); for (StreamElement streamElement : streamElementArray) { for (int i = 0; i < streamElement.formats.length; i++) { streamElement.formats[i] = streamElement.formats[i].copyWithDrmInitData(drmInitData); } } } return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength, lookAheadCount, isLive, protectionElement, streamElementArray); }
Example #14
Source File: BaseRenderer.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Returns whether {@code drmSessionManager} supports the specified {@code drmInitData}, or true * if {@code drmInitData} is null. * * @param drmSessionManager The drm session manager. * @param drmInitData {@link DrmInitData} of the format to check for support. * @return Whether {@code drmSessionManager} supports the specified {@code drmInitData}, or * true if {@code drmInitData} is null. */ protected static boolean supportsFormatDrm(@Nullable DrmSessionManager<?> drmSessionManager, @Nullable DrmInitData drmInitData) { if (drmInitData == null) { // Content is unencrypted. return true; } else if (drmSessionManager == null) { // Content is encrypted, but no drm session manager is available. return false; } return drmSessionManager.canAcquireSession(drmInitData); }
Example #15
Source File: HlsMasterPlaylist.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * @param baseUri See {@link #baseUri}. * @param tags See {@link #tags}. * @param variants See {@link #variants}. * @param videos See {@link #videos}. * @param audios See {@link #audios}. * @param subtitles See {@link #subtitles}. * @param closedCaptions See {@link #closedCaptions}. * @param muxedAudioFormat See {@link #muxedAudioFormat}. * @param muxedCaptionFormats See {@link #muxedCaptionFormats}. * @param hasIndependentSegments See {@link #hasIndependentSegments}. * @param variableDefinitions See {@link #variableDefinitions}. * @param sessionKeyDrmInitData See {@link #sessionKeyDrmInitData}. */ public HlsMasterPlaylist( String baseUri, List<String> tags, List<Variant> variants, List<Rendition> videos, List<Rendition> audios, List<Rendition> subtitles, List<Rendition> closedCaptions, Format muxedAudioFormat, List<Format> muxedCaptionFormats, boolean hasIndependentSegments, Map<String, String> variableDefinitions, List<DrmInitData> sessionKeyDrmInitData) { super(baseUri, tags, hasIndependentSegments); this.mediaPlaylistUrls = Collections.unmodifiableList( getMediaPlaylistUrls(variants, videos, audios, subtitles, closedCaptions)); this.variants = Collections.unmodifiableList(variants); this.videos = Collections.unmodifiableList(videos); this.audios = Collections.unmodifiableList(audios); this.subtitles = Collections.unmodifiableList(subtitles); this.closedCaptions = Collections.unmodifiableList(closedCaptions); this.muxedAudioFormat = muxedAudioFormat; this.muxedCaptionFormats = muxedCaptionFormats != null ? Collections.unmodifiableList(muxedCaptionFormats) : null; this.variableDefinitions = Collections.unmodifiableMap(variableDefinitions); this.sessionKeyDrmInitData = Collections.unmodifiableList(sessionKeyDrmInitData); }
Example #16
Source File: FragmentedMp4Extractor.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * @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 #17
Source File: Format.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public static Format createImageSampleFormat( @Nullable String id, @Nullable String sampleMimeType, @Nullable String codecs, int bitrate, @C.SelectionFlags int selectionFlags, @Nullable List<byte[]> initializationData, @Nullable String language, @Nullable DrmInitData drmInitData) { return new Format( id, /* label= */ null, /* containerMimeType= */ null, sampleMimeType, codecs, bitrate, /* maxInputSize= */ NO_VALUE, /* width= */ NO_VALUE, /* height= */ NO_VALUE, /* frameRate= */ NO_VALUE, /* rotationDegrees= */ NO_VALUE, /* pixelWidthHeightRatio= */ NO_VALUE, /* projectionData= */ null, /* stereoMode= */ NO_VALUE, /* colorInfo= */ null, /* channelCount= */ NO_VALUE, /* sampleRate= */ NO_VALUE, /* pcmEncoding= */ NO_VALUE, /* encoderDelay= */ NO_VALUE, /* encoderPadding= */ NO_VALUE, selectionFlags, language, /* accessibilityChannel= */ NO_VALUE, OFFSET_SAMPLE_RELATIVE, initializationData, drmInitData, /* metadata=*/ null); }
Example #18
Source File: HlsMediaPlaylist.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * @param playlistType See {@link #playlistType}. * @param baseUri See {@link #baseUri}. * @param tags See {@link #tags}. * @param startOffsetUs See {@link #startOffsetUs}. * @param startTimeUs See {@link #startTimeUs}. * @param hasDiscontinuitySequence See {@link #hasDiscontinuitySequence}. * @param discontinuitySequence See {@link #discontinuitySequence}. * @param mediaSequence See {@link #mediaSequence}. * @param version See {@link #version}. * @param targetDurationUs See {@link #targetDurationUs}. * @param hasIndependentSegments See {@link #hasIndependentSegments}. * @param hasEndTag See {@link #hasEndTag}. * @param hasProgramDateTime See {@link #hasProgramDateTime}. * @param drmInitData See {@link #drmInitData}. * @param segments See {@link #segments}. */ public HlsMediaPlaylist( @PlaylistType int playlistType, String baseUri, List<String> tags, long startOffsetUs, long startTimeUs, boolean hasDiscontinuitySequence, int discontinuitySequence, long mediaSequence, int version, long targetDurationUs, boolean hasIndependentSegments, boolean hasEndTag, boolean hasProgramDateTime, DrmInitData drmInitData, List<Segment> segments) { super(baseUri, tags, hasIndependentSegments); this.playlistType = playlistType; this.startTimeUs = startTimeUs; this.hasDiscontinuitySequence = hasDiscontinuitySequence; this.discontinuitySequence = discontinuitySequence; this.mediaSequence = mediaSequence; this.version = version; this.targetDurationUs = targetDurationUs; this.hasEndTag = hasEndTag; this.hasProgramDateTime = hasProgramDateTime; this.drmInitData = drmInitData; this.segments = Collections.unmodifiableList(segments); if (!segments.isEmpty()) { Segment last = segments.get(segments.size() - 1); durationUs = last.relativeStartTimeUs + last.durationUs; } else { durationUs = 0; } this.startOffsetUs = startOffsetUs == C.TIME_UNSET ? C.TIME_UNSET : startOffsetUs >= 0 ? startOffsetUs : durationUs + startOffsetUs; }
Example #19
Source File: Format.java From K-Sonic with MIT License | 5 votes |
public static Format createAudioSampleFormat(String id, String sampleMimeType, String codecs, int bitrate, int maxInputSize, int channelCount, int sampleRate, List<byte[]> initializationData, DrmInitData drmInitData, @C.SelectionFlags int selectionFlags, String language) { return createAudioSampleFormat(id, sampleMimeType, codecs, bitrate, maxInputSize, channelCount, sampleRate, NO_VALUE, initializationData, drmInitData, selectionFlags, language); }
Example #20
Source File: AtomParsers.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Parses a stsd atom (defined in 14496-12). * * @param stsd The stsd atom to decode. * @param trackId The track's identifier in its container. * @param rotationDegrees The rotation of the track in degrees. * @param language The language of the track. * @param drmInitData {@link DrmInitData} to be included in the format. * @param isQuickTime True for QuickTime media. False otherwise. * @return An object containing the parsed data. */ private static StsdData parseStsd(ParsableByteArray stsd, int trackId, int rotationDegrees, String language, DrmInitData drmInitData, boolean isQuickTime) throws ParserException { stsd.setPosition(Atom.FULL_HEADER_SIZE); int numberOfEntries = stsd.readInt(); StsdData out = new StsdData(numberOfEntries); for (int i = 0; i < numberOfEntries; i++) { int childStartPosition = stsd.getPosition(); int childAtomSize = stsd.readInt(); Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); int childAtomType = stsd.readInt(); if (childAtomType == Atom.TYPE_avc1 || childAtomType == Atom.TYPE_avc3 || childAtomType == Atom.TYPE_encv || childAtomType == Atom.TYPE_mp4v || childAtomType == Atom.TYPE_hvc1 || childAtomType == Atom.TYPE_hev1 || childAtomType == Atom.TYPE_s263 || childAtomType == Atom.TYPE_vp08 || childAtomType == Atom.TYPE_vp09) { parseVideoSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId, rotationDegrees, drmInitData, out, i); } else if (childAtomType == Atom.TYPE_mp4a || childAtomType == Atom.TYPE_enca || childAtomType == Atom.TYPE_ac_3 || childAtomType == Atom.TYPE_ec_3 || childAtomType == Atom.TYPE_dtsc || childAtomType == Atom.TYPE_dtse || childAtomType == Atom.TYPE_dtsh || childAtomType == Atom.TYPE_dtsl || childAtomType == Atom.TYPE_samr || childAtomType == Atom.TYPE_sawb || childAtomType == Atom.TYPE_lpcm || childAtomType == Atom.TYPE_sowt || childAtomType == Atom.TYPE__mp3 || childAtomType == Atom.TYPE_alac) { parseAudioSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId, language, isQuickTime, drmInitData, out, i); } else if (childAtomType == Atom.TYPE_TTML || childAtomType == Atom.TYPE_tx3g || childAtomType == Atom.TYPE_wvtt || childAtomType == Atom.TYPE_stpp || childAtomType == Atom.TYPE_c608) { parseTextSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId, language, out); } else if (childAtomType == Atom.TYPE_camm) { out.format = Format.createSampleFormat(Integer.toString(trackId), MimeTypes.APPLICATION_CAMERA_MOTION, null, Format.NO_VALUE, null); } stsd.setPosition(childStartPosition + childAtomSize); } return out; }
Example #21
Source File: Format.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public static Format createSampleFormat( @Nullable String id, @Nullable String sampleMimeType, @Nullable String codecs, int bitrate, @Nullable DrmInitData drmInitData) { return new Format( id, /* label= */ null, /* containerMimeType= */ null, sampleMimeType, codecs, bitrate, /* maxInputSize= */ NO_VALUE, /* width= */ NO_VALUE, /* height= */ NO_VALUE, /* frameRate= */ NO_VALUE, /* rotationDegrees= */ NO_VALUE, /* pixelWidthHeightRatio= */ NO_VALUE, /* projectionData= */ null, /* stereoMode= */ NO_VALUE, /* colorInfo= */ null, /* channelCount= */ NO_VALUE, /* sampleRate= */ NO_VALUE, /* pcmEncoding= */ NO_VALUE, /* encoderDelay= */ NO_VALUE, /* encoderPadding= */ NO_VALUE, /* selectionFlags= */ 0, /* language= */ null, /* accessibilityChannel= */ NO_VALUE, OFFSET_SAMPLE_RELATIVE, /* initializationData= */ null, drmInitData, /* metadata= */ null); }
Example #22
Source File: Format.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public static Format createImageSampleFormat( @Nullable String id, @Nullable String sampleMimeType, @Nullable String codecs, int bitrate, @C.SelectionFlags int selectionFlags, @Nullable List<byte[]> initializationData, @Nullable String language, @Nullable DrmInitData drmInitData) { return new Format( id, /* label= */ null, selectionFlags, /* roleFlags= */ 0, bitrate, codecs, /* metadata=*/ null, /* containerMimeType= */ null, sampleMimeType, /* maxInputSize= */ NO_VALUE, initializationData, drmInitData, OFFSET_SAMPLE_RELATIVE, /* width= */ NO_VALUE, /* height= */ NO_VALUE, /* frameRate= */ NO_VALUE, /* rotationDegrees= */ NO_VALUE, /* pixelWidthHeightRatio= */ NO_VALUE, /* projectionData= */ null, /* stereoMode= */ NO_VALUE, /* colorInfo= */ null, /* channelCount= */ NO_VALUE, /* sampleRate= */ NO_VALUE, /* pcmEncoding= */ NO_VALUE, /* encoderDelay= */ NO_VALUE, /* encoderPadding= */ NO_VALUE, language, /* accessibilityChannel= */ NO_VALUE); }
Example #23
Source File: BaseRenderer.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Returns whether {@code drmSessionManager} supports the specified {@code drmInitData}, or true * if {@code drmInitData} is null. * * @param drmSessionManager The drm session manager. * @param drmInitData {@link DrmInitData} of the format to check for support. * @return Whether {@code drmSessionManager} supports the specified {@code drmInitData}, or * true if {@code drmInitData} is null. */ protected static boolean supportsFormatDrm(@Nullable DrmSessionManager<?> drmSessionManager, @Nullable DrmInitData drmInitData) { if (drmInitData == null) { // Content is unencrypted. return true; } else if (drmSessionManager == null) { // Content is encrypted, but no drm session manager is available. return false; } return drmSessionManager.canAcquireSession(drmInitData); }
Example #24
Source File: Format.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public static Format createVideoSampleFormat( @Nullable String id, @Nullable String sampleMimeType, @Nullable String codecs, int bitrate, int maxInputSize, int width, int height, float frameRate, @Nullable List<byte[]> initializationData, int rotationDegrees, float pixelWidthHeightRatio, @Nullable DrmInitData drmInitData) { return createVideoSampleFormat( id, sampleMimeType, codecs, bitrate, maxInputSize, width, height, frameRate, initializationData, rotationDegrees, pixelWidthHeightRatio, /* projectionData= */ null, /* stereoMode= */ NO_VALUE, /* colorInfo= */ null, drmInitData); }
Example #25
Source File: HlsMediaPeriod.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private HlsSampleStreamWrapper buildSampleStreamWrapper( int trackType, Uri[] playlistUrls, Format[] playlistFormats, Format muxedAudioFormat, List<Format> muxedCaptionFormats, Map<String, DrmInitData> overridingDrmInitData, long positionUs) { HlsChunkSource defaultChunkSource = new HlsChunkSource( extractorFactory, playlistTracker, playlistUrls, playlistFormats, dataSourceFactory, mediaTransferListener, timestampAdjusterProvider, muxedCaptionFormats); return new HlsSampleStreamWrapper( trackType, /* callback= */ this, defaultChunkSource, overridingDrmInitData, allocator, positionUs, muxedAudioFormat, loadErrorHandlingPolicy, eventDispatcher, metadataType); }
Example #26
Source File: Format.java From K-Sonic with MIT License | 5 votes |
public static Format createVideoSampleFormat(String id, String sampleMimeType, String codecs, int bitrate, int maxInputSize, int width, int height, float frameRate, List<byte[]> initializationData, int rotationDegrees, float pixelWidthHeightRatio, DrmInitData drmInitData) { return createVideoSampleFormat(id, sampleMimeType, codecs, bitrate, maxInputSize, width, height, frameRate, initializationData, rotationDegrees, pixelWidthHeightRatio, null, NO_VALUE, drmInitData); }
Example #27
Source File: AtomParsers.java From K-Sonic with MIT License | 5 votes |
/** * Parses a trak atom (defined in 14496-12). * * @param trak Atom to decode. * @param mvhd Movie header atom, used to get the timescale. * @param duration The duration in units of the timescale declared in the mvhd atom, or * {@link C#TIME_UNSET} if the duration should be parsed from the tkhd atom. * @param drmInitData {@link DrmInitData} to be included in the format. * @param isQuickTime True for QuickTime media. False otherwise. * @return A {@link Track} instance, or {@code null} if the track's type isn't supported. */ public static Track parseTrak(Atom.ContainerAtom trak, Atom.LeafAtom mvhd, long duration, DrmInitData drmInitData, boolean isQuickTime) throws ParserException { Atom.ContainerAtom mdia = trak.getContainerAtomOfType(Atom.TYPE_mdia); int trackType = parseHdlr(mdia.getLeafAtomOfType(Atom.TYPE_hdlr).data); if (trackType == C.TRACK_TYPE_UNKNOWN) { return null; } TkhdData tkhdData = parseTkhd(trak.getLeafAtomOfType(Atom.TYPE_tkhd).data); if (duration == C.TIME_UNSET) { duration = tkhdData.duration; } long movieTimescale = parseMvhd(mvhd.data); long durationUs; if (duration == C.TIME_UNSET) { durationUs = C.TIME_UNSET; } else { durationUs = Util.scaleLargeTimestamp(duration, C.MICROS_PER_SECOND, movieTimescale); } Atom.ContainerAtom stbl = mdia.getContainerAtomOfType(Atom.TYPE_minf) .getContainerAtomOfType(Atom.TYPE_stbl); Pair<Long, String> mdhdData = parseMdhd(mdia.getLeafAtomOfType(Atom.TYPE_mdhd).data); StsdData stsdData = parseStsd(stbl.getLeafAtomOfType(Atom.TYPE_stsd).data, tkhdData.id, tkhdData.rotationDegrees, mdhdData.second, drmInitData, isQuickTime); Pair<long[], long[]> edtsData = parseEdts(trak.getContainerAtomOfType(Atom.TYPE_edts)); return stsdData.format == null ? null : new Track(tkhdData.id, trackType, mdhdData.first, movieTimescale, durationUs, stsdData.format, stsdData.requiredSampleTransformation, stsdData.trackEncryptionBoxes, stsdData.nalUnitLengthFieldLength, edtsData.first, edtsData.second); }
Example #28
Source File: DefaultHlsExtractorFactory.java From MediaSDK with Apache License 2.0 | 5 votes |
private static FragmentedMp4Extractor createFragmentedMp4Extractor( TimestampAdjuster timestampAdjuster, Format format, @Nullable DrmInitData drmInitData, @Nullable List<Format> muxedCaptionFormats) { // 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= */ isFmp4Variant(format) ? FragmentedMp4Extractor.FLAG_ENABLE_EMSG_TRACK : 0, timestampAdjuster, /* sideloadedTrack= */ null, drmInitData, muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList()); }
Example #29
Source File: DefaultHlsExtractorFactory.java From MediaSDK with Apache License 2.0 | 5 votes |
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 #30
Source File: DashManifestParser.java From MediaSDK with Apache License 2.0 | 5 votes |
protected Representation buildRepresentation( RepresentationInfo representationInfo, @Nullable String label, @Nullable String extraDrmSchemeType, ArrayList<SchemeData> extraDrmSchemeDatas, ArrayList<Descriptor> extraInbandEventStreams) { Format format = representationInfo.format; if (label != null) { format = format.copyWithLabel(label); } String drmSchemeType = representationInfo.drmSchemeType != null ? representationInfo.drmSchemeType : extraDrmSchemeType; ArrayList<SchemeData> drmSchemeDatas = representationInfo.drmSchemeDatas; drmSchemeDatas.addAll(extraDrmSchemeDatas); if (!drmSchemeDatas.isEmpty()) { filterRedundantIncompleteSchemeDatas(drmSchemeDatas); DrmInitData drmInitData = new DrmInitData(drmSchemeType, drmSchemeDatas); format = format.copyWithDrmInitData(drmInitData); } ArrayList<Descriptor> inbandEventStreams = representationInfo.inbandEventStreams; inbandEventStreams.addAll(extraInbandEventStreams); return Representation.newInstance( representationInfo.revisionId, format, representationInfo.baseUrl, representationInfo.segmentBase, inbandEventStreams); }