Search in sources :

Example 1 with DrmInitData

use of com.google.android.exoplayer2.drm.DrmInitData in project ExoPlayer by google.

the class FormatTest method testParcelable.

public void testParcelable() {
    DrmInitData.SchemeData DRM_DATA_1 = new DrmInitData.SchemeData(WIDEVINE_UUID, VIDEO_MP4, TestUtil.buildTestData(128, 1));
    DrmInitData.SchemeData DRM_DATA_2 = new DrmInitData.SchemeData(C.UUID_NIL, VIDEO_WEBM, TestUtil.buildTestData(128, 1));
    DrmInitData drmInitData = new DrmInitData(DRM_DATA_1, DRM_DATA_2);
    byte[] projectionData = new byte[] { 1, 2, 3 };
    Metadata metadata = new Metadata(new TextInformationFrame("id1", "description1", "value1"), new TextInformationFrame("id2", "description2", "value2"));
    Format formatToParcel = new Format("id", MimeTypes.VIDEO_MP4, MimeTypes.VIDEO_H264, null, 1024, 2048, 1920, 1080, 24, 90, 2, projectionData, C.STEREO_MODE_TOP_BOTTOM, 6, 44100, C.ENCODING_PCM_24BIT, 1001, 1002, 0, "und", Format.NO_VALUE, Format.OFFSET_SAMPLE_RELATIVE, INIT_DATA, drmInitData, metadata);
    Parcel parcel = Parcel.obtain();
    formatToParcel.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    Format formatFromParcel = Format.CREATOR.createFromParcel(parcel);
    assertEquals(formatToParcel, formatFromParcel);
    parcel.recycle();
}
Also used : DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) MediaFormat(android.media.MediaFormat) Parcel(android.os.Parcel) Metadata(com.google.android.exoplayer2.metadata.Metadata) TextInformationFrame(com.google.android.exoplayer2.metadata.id3.TextInformationFrame)

Example 2 with DrmInitData

use of com.google.android.exoplayer2.drm.DrmInitData in project ExoPlayer by google.

the class OfflineLicenseHelper method download.

/**
   * Downloads an offline license.
   *
   * @param dataSource The {@link HttpDataSource} to be used for download.
   * @param dashManifest The {@link DashManifest} of the DASH content.
   * @return The downloaded offline license key set id.
   * @throws IOException If an error occurs reading data from the stream.
   * @throws InterruptedException If the thread has been interrupted.
   * @throws DrmSessionException Thrown when there is an error during DRM session.
   */
public byte[] download(HttpDataSource dataSource, DashManifest dashManifest) throws IOException, InterruptedException, DrmSessionException {
    // as per DASH IF Interoperability Recommendations V3.0, 7.5.3.
    if (dashManifest.getPeriodCount() < 1) {
        return null;
    }
    Period period = dashManifest.getPeriod(0);
    int adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_VIDEO);
    if (adaptationSetIndex == C.INDEX_UNSET) {
        adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_AUDIO);
        if (adaptationSetIndex == C.INDEX_UNSET) {
            return null;
        }
    }
    AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex);
    if (adaptationSet.representations.isEmpty()) {
        return null;
    }
    Representation representation = adaptationSet.representations.get(0);
    DrmInitData drmInitData = representation.format.drmInitData;
    if (drmInitData == null) {
        Format sampleFormat = DashUtil.loadSampleFormat(dataSource, representation);
        if (sampleFormat != null) {
            drmInitData = sampleFormat.drmInitData;
        }
        if (drmInitData == null) {
            return null;
        }
    }
    blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
    return drmSessionManager.getOfflineLicenseKeySetId();
}
Also used : Format(com.google.android.exoplayer2.Format) Period(com.google.android.exoplayer2.source.dash.manifest.Period) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation)

Example 3 with DrmInitData

use of com.google.android.exoplayer2.drm.DrmInitData in project ExoPlayer by google.

the class DashManifestParser method buildRepresentation.

protected Representation buildRepresentation(RepresentationInfo representationInfo, String contentId, ArrayList<SchemeData> extraDrmSchemeDatas, ArrayList<SchemeValuePair> extraInbandEventStreams) {
    Format format = representationInfo.format;
    ArrayList<SchemeData> drmSchemeDatas = representationInfo.drmSchemeDatas;
    drmSchemeDatas.addAll(extraDrmSchemeDatas);
    if (!drmSchemeDatas.isEmpty()) {
        format = format.copyWithDrmInitData(new DrmInitData(drmSchemeDatas));
    }
    ArrayList<SchemeValuePair> inbandEventStremas = representationInfo.inbandEventStreams;
    inbandEventStremas.addAll(extraInbandEventStreams);
    return Representation.newInstance(contentId, Representation.REVISION_ID_DEFAULT, format, representationInfo.baseUrl, representationInfo.segmentBase, inbandEventStremas);
}
Also used : Format(com.google.android.exoplayer2.Format) DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData)

Example 4 with DrmInitData

use of com.google.android.exoplayer2.drm.DrmInitData in project ExoPlayer by google.

the class DrmInitData method createSessionCreationData.

/**
 * Merges {@link DrmInitData} obtained from a media manifest and a media stream.
 *
 * <p>The result is generated as follows.
 *
 * <ol>
 *   <li>Include all {@link SchemeData}s from {@code manifestData} where {@link
 *       SchemeData#hasData()} is true.
 *   <li>Include all {@link SchemeData}s in {@code mediaData} where {@link SchemeData#hasData()}
 *       is true and for which we did not include an entry from the manifest targeting the same
 *       UUID.
 *   <li>If available, the scheme type from the manifest is used. If not, the scheme type from the
 *       media is used.
 * </ol>
 *
 * @param manifestData DRM session acquisition data obtained from the manifest.
 * @param mediaData DRM session acquisition data obtained from the media.
 * @return A {@link DrmInitData} obtained from merging a media manifest and a media stream.
 */
@Nullable
public static DrmInitData createSessionCreationData(@Nullable DrmInitData manifestData, @Nullable DrmInitData mediaData) {
    ArrayList<SchemeData> result = new ArrayList<>();
    String schemeType = null;
    if (manifestData != null) {
        schemeType = manifestData.schemeType;
        for (SchemeData data : manifestData.schemeDatas) {
            if (data.hasData()) {
                result.add(data);
            }
        }
    }
    if (mediaData != null) {
        if (schemeType == null) {
            schemeType = mediaData.schemeType;
        }
        int manifestDatasCount = result.size();
        for (SchemeData data : mediaData.schemeDatas) {
            if (data.hasData() && !containsSchemeDataWithUuid(result, manifestDatasCount, data.uuid)) {
                result.add(data);
            }
        }
    }
    return result.isEmpty() ? null : new DrmInitData(schemeType, result);
}
Also used : ArrayList(java.util.ArrayList) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData) Nullable(androidx.annotation.Nullable)

Example 5 with DrmInitData

use of com.google.android.exoplayer2.drm.DrmInitData in project ExoPlayer by google.

the class FormatTest method createTestFormat.

private static Format createTestFormat() {
    byte[] initData1 = new byte[] { 1, 2, 3 };
    byte[] initData2 = new byte[] { 4, 5, 6 };
    List<byte[]> initializationData = new ArrayList<>();
    initializationData.add(initData1);
    initializationData.add(initData2);
    DrmInitData.SchemeData drmData1 = new DrmInitData.SchemeData(WIDEVINE_UUID, VIDEO_MP4, buildTestData(128, 1));
    DrmInitData.SchemeData drmData2 = new DrmInitData.SchemeData(C.UUID_NIL, VIDEO_WEBM, buildTestData(128, 1));
    DrmInitData drmInitData = new DrmInitData(drmData1, drmData2);
    byte[] projectionData = new byte[] { 1, 2, 3 };
    Metadata metadata = new Metadata(new FakeMetadataEntry("id1"), new FakeMetadataEntry("id2"));
    ColorInfo colorInfo = new ColorInfo(C.COLOR_SPACE_BT709, C.COLOR_RANGE_LIMITED, C.COLOR_TRANSFER_SDR, new byte[] { 1, 2, 3, 4, 5, 6, 7 });
    return new Format.Builder().setId("id").setLabel("label").setLanguage("language").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).setRoleFlags(C.ROLE_FLAG_MAIN).setAverageBitrate(1024).setPeakBitrate(2048).setCodecs("codec").setMetadata(metadata).setContainerMimeType(VIDEO_MP4).setSampleMimeType(MimeTypes.VIDEO_H264).setMaxInputSize(5000).setInitializationData(initializationData).setDrmInitData(drmInitData).setSubsampleOffsetUs(Format.OFFSET_SAMPLE_RELATIVE).setWidth(1920).setHeight(1080).setFrameRate(24).setRotationDegrees(90).setPixelWidthHeightRatio(4).setProjectionData(projectionData).setStereoMode(C.STEREO_MODE_TOP_BOTTOM).setColorInfo(colorInfo).setChannelCount(6).setSampleRate(44100).setPcmEncoding(C.ENCODING_PCM_24BIT).setEncoderDelay(1001).setEncoderPadding(1002).setAccessibilityChannel(2).setCryptoType(C.CRYPTO_TYPE_CUSTOM_BASE).build();
}
Also used : DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) FakeMetadataEntry(com.google.android.exoplayer2.testutil.FakeMetadataEntry) ArrayList(java.util.ArrayList) Metadata(com.google.android.exoplayer2.metadata.Metadata) ColorInfo(com.google.android.exoplayer2.video.ColorInfo)

Aggregations

DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)17 Nullable (androidx.annotation.Nullable)16 Format (com.google.android.exoplayer2.Format)10 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)10 ArrayList (java.util.ArrayList)10 Metadata (com.google.android.exoplayer2.metadata.Metadata)5 SuppressLint (android.annotation.SuppressLint)4 Uri (android.net.Uri)4 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 ColorInfo (com.google.android.exoplayer2.video.ColorInfo)3 MediaFormat (android.media.MediaFormat)2 Looper (android.os.Looper)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 C (com.google.android.exoplayer2.C)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 DrmSessionReference (com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference)2 AppManagedProvider (com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider)2 GaplessInfoHolder (com.google.android.exoplayer2.extractor.GaplessInfoHolder)2 SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)2 ContainerAtom (com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom)2