Search in sources :

Example 31 with DrmSessionManager

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

the class SimpleDecoderAudioRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = inputFormat;
    inputFormat = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(inputFormat.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (inputFormat.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), inputFormat.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    if (decoderReceivedBuffers) {
        // Signal end of stream and wait for any final output buffers before re-initialization.
        decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
    } else {
        // There aren't any final output buffers, so release the decoder immediately.
        releaseDecoder();
        maybeInitDecoder();
        audioTrackNeedsConfigure = true;
    }
    eventDispatcher.inputFormatChanged(newFormat);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 32 with DrmSessionManager

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

the class LibvpxVideoRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = format;
    format = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(format.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (format.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), format.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    eventDispatcher.inputFormatChanged(format);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 33 with DrmSessionManager

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

the class ExoHostedTest method buildExoPlayer.

@SuppressWarnings("unused")
protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(host, trackSelector, new DefaultLoadControl(), drmSessionManager, SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF, 0);
    player.setVideoSurface(surface);
    return player;
}
Also used : SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl)

Example 34 with DrmSessionManager

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

the class MediaCodecRenderer method onInputFormatChanged.

/**
   * Called when a new format is read from the upstream {@link MediaPeriod}.
   *
   * @param newFormat The new format.
   * @throws ExoPlaybackException If an error occurs reinitializing the {@link MediaCodec}.
   */
protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = format;
    format = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(format.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (format.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), format.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    if (pendingDrmSession == drmSession && codec != null && canReconfigureCodec(codec, codecIsAdaptive, oldFormat, format)) {
        codecReconfigured = true;
        codecReconfigurationState = RECONFIGURATION_STATE_WRITE_PENDING;
        codecNeedsAdaptationWorkaroundBuffer = codecNeedsAdaptationWorkaround && format.width == oldFormat.width && format.height == oldFormat.height;
    } else {
        if (codecReceivedBuffers) {
            // Signal end of stream and wait for any final output buffers before re-initialization.
            codecReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
        } else {
            // There aren't any final output buffers, so perform re-initialization immediately.
            releaseCodec();
            maybeInitCodec();
        }
    }
}
Also used : MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format)

Example 35 with DrmSessionManager

use of com.google.android.exoplayer2.drm.DrmSessionManager in project LeafPic by HoraApps.

the class PlayerActivity method initializePlayer.

// Internal methods
private void initializePlayer() {
    Intent intent = getIntent();
    boolean needNewPlayer = player == null;
    if (needNewPlayer) {
        TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
        trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
        trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory, getThemeHelper());
        lastSeenTrackGroupArray = null;
        UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
        DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
        if (drmSchemeUuid != null) {
            String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
            String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
            boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false);
            int errorStringId = R.string.error_drm_unknown;
            try {
                drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession);
            } catch (UnsupportedDrmException e) {
                errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown;
            }
            if (drmSessionManager == null) {
                showToast(errorStringId);
                return;
            }
        }
        DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
        player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector);
        player.addListener(new PlayerEventListener());
        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(shouldAutoPlay);
    }
    String action = intent.getAction();
    Uri[] uris;
    String[] extensions;
    if (intent.getData() != null && intent.getType() != null) {
        uris = new Uri[] { intent.getData() };
        extensions = new String[] { intent.getType() };
    } else {
        // TODO: 12/7/16 asdasd
        showToast(getString(R.string.unexpected_intent_action, action));
        return;
    }
    MediaSource[] mediaSources = new MediaSource[uris.length];
    for (int i = 0; i < uris.length; i++) {
        mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
    }
    MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
    boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
    if (haveResumePosition) {
        player.seekTo(resumeWindow, resumePosition);
    }
    player.prepare(mediaSource, !haveResumePosition, false);
    inErrorState = false;
    supportInvalidateOptionsMenu();
}
Also used : DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) Intent(android.content.Intent) TrackSelectionHelper(org.horaapps.leafpic.views.videoplayer.TrackSelectionHelper) Uri(android.net.Uri) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) UnsupportedDrmException(com.google.android.exoplayer2.drm.UnsupportedDrmException) UUID(java.util.UUID) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)

Aggregations

Test (org.junit.Test)33 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)20 FakeExoMediaDrm (com.google.android.exoplayer2.testutil.FakeExoMediaDrm)17 Nullable (androidx.annotation.Nullable)16 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)16 MediaSource (com.google.android.exoplayer2.source.MediaSource)15 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)14 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)12 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)12 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)12 Allocator (com.google.android.exoplayer2.upstream.Allocator)12 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)12 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)11 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)10 Format (com.google.android.exoplayer2.Format)9 AppManagedProvider (com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider)7 Util (com.google.android.exoplayer2.util.Util)7 Intent (android.content.Intent)6 Uri (android.net.Uri)6 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)6