• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.exoplayer2.drm;
17 
18 import android.os.Looper;
19 import androidx.annotation.Nullable;
20 import com.google.android.exoplayer2.C;
21 import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
22 import com.google.android.exoplayer2.util.MediaSourceEventDispatcher;
23 
24 /** Manages a DRM session. */
25 public interface DrmSessionManager {
26 
27   /** Returns {@link #DUMMY}. */
getDummyDrmSessionManager()28   static DrmSessionManager getDummyDrmSessionManager() {
29     return DUMMY;
30   }
31 
32   /** {@link DrmSessionManager} that supports no DRM schemes. */
33   DrmSessionManager DUMMY =
34       new DrmSessionManager() {
35 
36         @Override
37         public boolean canAcquireSession(DrmInitData drmInitData) {
38           return false;
39         }
40 
41         @Override
42         public DrmSession acquireSession(
43             Looper playbackLooper,
44             @Nullable MediaSourceEventDispatcher eventDispatcher,
45             DrmInitData drmInitData) {
46           return new ErrorStateDrmSession(
47               new DrmSession.DrmSessionException(
48                   new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME)));
49         }
50 
51         @Override
52         @Nullable
53         public Class<ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData) {
54           return null;
55         }
56       };
57 
58   /**
59    * Acquires any required resources.
60    *
61    * <p>{@link #release()} must be called to ensure the acquired resources are released. After
62    * releasing, an instance may be re-prepared.
63    */
prepare()64   default void prepare() {
65     // Do nothing.
66   }
67 
68   /** Releases any acquired resources. */
release()69   default void release() {
70     // Do nothing.
71   }
72 
73   /**
74    * Returns whether the manager is capable of acquiring a session for the given
75    * {@link DrmInitData}.
76    *
77    * @param drmInitData DRM initialization data.
78    * @return Whether the manager is capable of acquiring a session for the given
79    *     {@link DrmInitData}.
80    */
canAcquireSession(DrmInitData drmInitData)81   boolean canAcquireSession(DrmInitData drmInitData);
82 
83   /**
84    * Returns a {@link DrmSession} that does not execute key requests, with an incremented reference
85    * count. When the caller no longer needs to use the instance, it must call {@link
86    * DrmSession#release(MediaSourceEventDispatcher)} to decrement the reference count.
87    *
88    * <p>Placeholder {@link DrmSession DrmSessions} may be used to configure secure decoders for
89    * playback of clear content periods. This can reduce the cost of transitioning between clear and
90    * encrypted content periods.
91    *
92    * @param playbackLooper The looper associated with the media playback thread.
93    * @param trackType The type of the track to acquire a placeholder session for. Must be one of the
94    *     {@link C}{@code .TRACK_TYPE_*} constants.
95    * @return The placeholder DRM session, or null if this DRM session manager does not support
96    *     placeholder sessions.
97    */
98   @Nullable
acquirePlaceholderSession(Looper playbackLooper, int trackType)99   default DrmSession acquirePlaceholderSession(Looper playbackLooper, int trackType) {
100     return null;
101   }
102 
103   /**
104    * Returns a {@link DrmSession} for the specified {@link DrmInitData}, with an incremented
105    * reference count. When the caller no longer needs to use the instance, it must call {@link
106    * DrmSession#release(MediaSourceEventDispatcher)} to decrement the reference count.
107    *
108    * @param playbackLooper The looper associated with the media playback thread.
109    * @param eventDispatcher The {@link MediaSourceEventDispatcher} used to distribute events, and
110    *     passed on to {@link DrmSession#acquire(MediaSourceEventDispatcher)}.
111    * @param drmInitData DRM initialization data. All contained {@link SchemeData}s must contain
112    *     non-null {@link SchemeData#data}.
113    * @return The DRM session.
114    */
acquireSession( Looper playbackLooper, @Nullable MediaSourceEventDispatcher eventDispatcher, DrmInitData drmInitData)115   DrmSession acquireSession(
116       Looper playbackLooper,
117       @Nullable MediaSourceEventDispatcher eventDispatcher,
118       DrmInitData drmInitData);
119 
120   /**
121    * Returns the {@link ExoMediaCrypto} type returned by sessions acquired using the given {@link
122    * DrmInitData}, or null if a session cannot be acquired with the given {@link DrmInitData}.
123    */
124   @Nullable
getExoMediaCryptoType(DrmInitData drmInitData)125   Class<? extends ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData);
126 }
127