Search in sources :

Example 1 with HttpDataSource

use of com.google.android.exoplayer2.upstream.HttpDataSource in project ExoPlayer by google.

the class HttpMediaDrmCallback method executePost.

private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url, byte[] data, Map<String, String> requestProperties) throws IOException {
    HttpDataSource dataSource = dataSourceFactory.createDataSource();
    if (requestProperties != null) {
        for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
            dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
        }
    }
    DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null, DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
        return Util.toByteArray(inputStream);
    } finally {
        Util.closeQuietly(inputStream);
    }
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) HashMap(java.util.HashMap) Map(java.util.Map) DataSourceInputStream(com.google.android.exoplayer2.upstream.DataSourceInputStream)

Example 2 with HttpDataSource

use of com.google.android.exoplayer2.upstream.HttpDataSource 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 HttpDataSource

use of com.google.android.exoplayer2.upstream.HttpDataSource in project ExoPlayer by google.

the class OfflineLicenseHelperTest method testGetLicenseDurationRemainingSecExpiredLicense.

public void testGetLicenseDurationRemainingSecExpiredLicense() throws Exception {
    long licenseDuration = 0;
    int playbackDuration = 0;
    setStubLicenseAndPlaybackDurationValues(licenseDuration, playbackDuration);
    setDefaultStubKeySetId();
    DashManifest manifest = newDashManifestWithAllElements();
    byte[] offlineLicenseKeySetId = offlineLicenseHelper.download(httpDataSource, manifest);
    Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
    assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
    assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
}
Also used : DashManifest(com.google.android.exoplayer2.source.dash.manifest.DashManifest)

Example 4 with HttpDataSource

use of com.google.android.exoplayer2.upstream.HttpDataSource in project ExoPlayer by google.

the class OfflineLicenseHelperTest method testDownloadFailsIfThereIsNoAdaptationSet.

public void testDownloadFailsIfThereIsNoAdaptationSet() throws Exception {
    setDefaultStubValues();
    DashManifest manifest = newDashManifest(newPeriods());
    byte[] offlineLicenseKeySetId = offlineLicenseHelper.download(httpDataSource, manifest);
    assertNull(offlineLicenseKeySetId);
}
Also used : DashManifest(com.google.android.exoplayer2.source.dash.manifest.DashManifest)

Example 5 with HttpDataSource

use of com.google.android.exoplayer2.upstream.HttpDataSource in project ExoPlayer by google.

the class OfflineLicenseHelperTest method testGetLicenseDurationRemainingSec.

public void testGetLicenseDurationRemainingSec() throws Exception {
    long licenseDuration = 1000;
    int playbackDuration = 200;
    setStubLicenseAndPlaybackDurationValues(licenseDuration, playbackDuration);
    setDefaultStubKeySetId();
    DashManifest manifest = newDashManifestWithAllElements();
    byte[] offlineLicenseKeySetId = offlineLicenseHelper.download(httpDataSource, manifest);
    Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
    assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
    assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
}
Also used : DashManifest(com.google.android.exoplayer2.source.dash.manifest.DashManifest)

Aggregations

DashManifest (com.google.android.exoplayer2.source.dash.manifest.DashManifest)9 DataSourceInputStream (com.google.android.exoplayer2.upstream.DataSourceInputStream)2 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)2 Format (com.google.android.exoplayer2.Format)1 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)1 DashManifestParser (com.google.android.exoplayer2.source.dash.manifest.DashManifestParser)1 Period (com.google.android.exoplayer2.source.dash.manifest.Period)1 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)1 HttpDataSource (com.google.android.exoplayer2.upstream.HttpDataSource)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1