Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
143d7d6c
authored
Sep 11, 2019
by
aquilescanta
Committed by
Oliver Woodman
Sep 13, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Implement acquirePlaceholderSession in DefaultDrmSessionManager
Issue:#4867 PiperOrigin-RevId: 268497377
parent
f7e9e185
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
33 deletions
library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManager.java
library/core/src/main/java/com/google/android/exoplayer2/drm/FrameworkMediaCrypto.java
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java
library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManager.java
View file @
143d7d6c
...
@@ -93,11 +93,13 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
...
@@ -93,11 +93,13 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
@Nullable
private
final
HashMap
<
String
,
String
>
optionalKeyRequestParameters
;
@Nullable
private
final
HashMap
<
String
,
String
>
optionalKeyRequestParameters
;
private
final
EventDispatcher
<
DefaultDrmSessionEventListener
>
eventDispatcher
;
private
final
EventDispatcher
<
DefaultDrmSessionEventListener
>
eventDispatcher
;
private
final
boolean
multiSession
;
private
final
boolean
multiSession
;
private
final
boolean
allowPlaceholderSessions
;
private
final
LoadErrorHandlingPolicy
loadErrorHandlingPolicy
;
private
final
LoadErrorHandlingPolicy
loadErrorHandlingPolicy
;
private
final
List
<
DefaultDrmSession
<
T
>>
sessions
;
private
final
List
<
DefaultDrmSession
<
T
>>
sessions
;
private
final
List
<
DefaultDrmSession
<
T
>>
provisioningSessions
;
private
final
List
<
DefaultDrmSession
<
T
>>
provisioningSessions
;
@Nullable
private
DefaultDrmSession
<
T
>
placeholderDrmSession
;
@Nullable
private
Looper
playbackLooper
;
@Nullable
private
Looper
playbackLooper
;
private
int
mode
;
private
int
mode
;
@Nullable
private
byte
[]
offlineLicenseKeySetId
;
@Nullable
private
byte
[]
offlineLicenseKeySetId
;
...
@@ -232,6 +234,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
...
@@ -232,6 +234,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
callback
,
callback
,
optionalKeyRequestParameters
,
optionalKeyRequestParameters
,
multiSession
,
multiSession
,
/* allowPlaceholderSessions= */
false
,
new
DefaultLoadErrorHandlingPolicy
(
initialDrmRequestRetryCount
));
new
DefaultLoadErrorHandlingPolicy
(
initialDrmRequestRetryCount
));
}
}
...
@@ -241,6 +244,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
...
@@ -241,6 +244,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
MediaDrmCallback
callback
,
MediaDrmCallback
callback
,
@Nullable
HashMap
<
String
,
String
>
optionalKeyRequestParameters
,
@Nullable
HashMap
<
String
,
String
>
optionalKeyRequestParameters
,
boolean
multiSession
,
boolean
multiSession
,
boolean
allowPlaceholderSessions
,
LoadErrorHandlingPolicy
loadErrorHandlingPolicy
)
{
LoadErrorHandlingPolicy
loadErrorHandlingPolicy
)
{
Assertions
.
checkNotNull
(
uuid
);
Assertions
.
checkNotNull
(
uuid
);
Assertions
.
checkNotNull
(
mediaDrm
);
Assertions
.
checkNotNull
(
mediaDrm
);
...
@@ -251,6 +255,11 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
...
@@ -251,6 +255,11 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
this
.
optionalKeyRequestParameters
=
optionalKeyRequestParameters
;
this
.
optionalKeyRequestParameters
=
optionalKeyRequestParameters
;
this
.
eventDispatcher
=
new
EventDispatcher
<>();
this
.
eventDispatcher
=
new
EventDispatcher
<>();
this
.
multiSession
=
multiSession
;
this
.
multiSession
=
multiSession
;
boolean
canAcquirePlaceholderSessions
=
!
FrameworkMediaCrypto
.
class
.
equals
(
mediaDrm
.
getExoMediaCryptoType
())
||
!
FrameworkMediaCrypto
.
WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC
;
// TODO: Allow customization once this class has a Builder.
this
.
allowPlaceholderSessions
=
canAcquirePlaceholderSessions
&&
allowPlaceholderSessions
;
this
.
loadErrorHandlingPolicy
=
loadErrorHandlingPolicy
;
this
.
loadErrorHandlingPolicy
=
loadErrorHandlingPolicy
;
mode
=
MODE_PLAYBACK
;
mode
=
MODE_PLAYBACK
;
sessions
=
new
ArrayList
<>();
sessions
=
new
ArrayList
<>();
...
@@ -399,14 +408,25 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
...
@@ -399,14 +408,25 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
}
}
@Override
@Override
public
DrmSession
<
T
>
acquireSession
(
Looper
playbackLooper
,
DrmInitData
drmInitData
)
{
@Nullable
Assertions
.
checkState
(
this
.
playbackLooper
==
null
||
this
.
playbackLooper
==
playbackLooper
);
public
DrmSession
<
T
>
acquirePlaceholderSession
(
Looper
playbackLooper
)
{
if
(
sessions
.
isEmpty
())
{
if
(!
allowPlaceholderSessions
)
{
this
.
playbackLooper
=
playbackLooper
;
return
null
;
if
(
mediaDrmHandler
==
null
)
{
mediaDrmHandler
=
new
MediaDrmHandler
(
playbackLooper
);
}
}
}
maybeCreateMediaDrmHandler
(
playbackLooper
);
if
(
placeholderDrmSession
==
null
)
{
DefaultDrmSession
<
T
>
placeholderDrmSession
=
createNewDefaultSession
(
/* schemeDatas= */
null
,
/* isPlaceholderSession= */
true
);
sessions
.
add
(
placeholderDrmSession
);
this
.
placeholderDrmSession
=
placeholderDrmSession
;
}
placeholderDrmSession
.
acquireReference
();
return
placeholderDrmSession
;
}
@Override
public
DrmSession
<
T
>
acquireSession
(
Looper
playbackLooper
,
DrmInitData
drmInitData
)
{
maybeCreateMediaDrmHandler
(
playbackLooper
);
List
<
SchemeData
>
schemeDatas
=
null
;
List
<
SchemeData
>
schemeDatas
=
null
;
if
(
offlineLicenseKeySetId
==
null
)
{
if
(
offlineLicenseKeySetId
==
null
)
{
...
@@ -434,27 +454,41 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
...
@@ -434,27 +454,41 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
if
(
session
==
null
)
{
if
(
session
==
null
)
{
// Create a new session.
// Create a new session.
session
=
session
=
createNewDefaultSession
(
schemeDatas
,
/* isPlaceholderSession= */
false
);
new
DefaultDrmSession
<>(
uuid
,
mediaDrm
,
/* provisioningManager= */
this
,
/* releaseCallback= */
this
::
onSessionReleased
,
schemeDatas
,
mode
,
/* isPlaceholderSession= */
false
,
offlineLicenseKeySetId
,
optionalKeyRequestParameters
,
callback
,
playbackLooper
,
eventDispatcher
,
loadErrorHandlingPolicy
);
sessions
.
add
(
session
);
sessions
.
add
(
session
);
}
}
session
.
acquireReference
();
session
.
acquireReference
();
return
session
;
return
session
;
}
}
private
DefaultDrmSession
<
T
>
createNewDefaultSession
(
@Nullable
List
<
SchemeData
>
schemeDatas
,
boolean
isPlaceholderSession
)
{
return
new
DefaultDrmSession
<>(
uuid
,
mediaDrm
,
/* provisioningManager= */
this
,
/* releaseCallback= */
this
::
onSessionReleased
,
schemeDatas
,
mode
,
isPlaceholderSession
,
offlineLicenseKeySetId
,
optionalKeyRequestParameters
,
callback
,
Assertions
.
checkNotNull
(
playbackLooper
),
eventDispatcher
,
loadErrorHandlingPolicy
);
}
private
void
maybeCreateMediaDrmHandler
(
Looper
playbackLooper
)
{
Assertions
.
checkState
(
this
.
playbackLooper
==
null
||
this
.
playbackLooper
==
playbackLooper
);
if
(
sessions
.
isEmpty
())
{
this
.
playbackLooper
=
playbackLooper
;
if
(
mediaDrmHandler
==
null
)
{
mediaDrmHandler
=
new
MediaDrmHandler
(
playbackLooper
);
}
}
}
@Override
@Override
@Nullable
@Nullable
public
Class
<
T
>
getExoMediaCryptoType
(
DrmInitData
drmInitData
)
{
public
Class
<
T
>
getExoMediaCryptoType
(
DrmInitData
drmInitData
)
{
...
@@ -496,6 +530,9 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
...
@@ -496,6 +530,9 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
private
void
onSessionReleased
(
DefaultDrmSession
<
T
>
drmSession
)
{
private
void
onSessionReleased
(
DefaultDrmSession
<
T
>
drmSession
)
{
sessions
.
remove
(
drmSession
);
sessions
.
remove
(
drmSession
);
if
(
placeholderDrmSession
==
drmSession
)
{
placeholderDrmSession
=
null
;
}
if
(
provisioningSessions
.
size
()
>
1
&&
provisioningSessions
.
get
(
0
)
==
drmSession
)
{
if
(
provisioningSessions
.
size
()
>
1
&&
provisioningSessions
.
get
(
0
)
==
drmSession
)
{
// Other sessions were waiting for the released session to complete a provision operation.
// Other sessions were waiting for the released session to complete a provision operation.
// We need to have one of those sessions perform the provision operation instead.
// We need to have one of those sessions perform the provision operation instead.
...
...
library/core/src/main/java/com/google/android/exoplayer2/drm/FrameworkMediaCrypto.java
View file @
143d7d6c
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
com
.
google
.
android
.
exoplayer2
.
drm
;
package
com
.
google
.
android
.
exoplayer2
.
drm
;
import
android.media.MediaCrypto
;
import
android.media.MediaCrypto
;
import
com.google.android.exoplayer2.util.Util
;
import
java.util.UUID
;
import
java.util.UUID
;
/**
/**
...
@@ -24,6 +25,15 @@ import java.util.UUID;
...
@@ -24,6 +25,15 @@ import java.util.UUID;
*/
*/
public
final
class
FrameworkMediaCrypto
implements
ExoMediaCrypto
{
public
final
class
FrameworkMediaCrypto
implements
ExoMediaCrypto
{
/**
* Whether the device needs keys to have been loaded into the {@link DrmSession} before codec
* configuration.
*/
public
static
final
boolean
WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC
=
"Amazon"
.
equals
(
Util
.
MANUFACTURER
)
&&
(
"AFTM"
.
equals
(
Util
.
MODEL
)
// Fire TV Stick Gen 1
||
"AFTB"
.
equals
(
Util
.
MODEL
));
// Fire TV Gen 1
/** The DRM scheme UUID. */
/** The DRM scheme UUID. */
public
final
UUID
uuid
;
public
final
UUID
uuid
;
/** The DRM session id. */
/** The DRM session id. */
...
...
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java
View file @
143d7d6c
...
@@ -521,7 +521,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
...
@@ -521,7 +521,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
&&
mediaCrypto
.
requiresSecureDecoderComponent
(
mimeType
);
&&
mediaCrypto
.
requiresSecureDecoderComponent
(
mimeType
);
}
}
}
}
if
(
deviceNeedsDrmKeysToConfigureCodecWorkaround
()
)
{
if
(
FrameworkMediaCrypto
.
WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC
)
{
@DrmSession
.
State
int
drmSessionState
=
codecDrmSession
.
getState
();
@DrmSession
.
State
int
drmSessionState
=
codecDrmSession
.
getState
();
if
(
drmSessionState
==
DrmSession
.
STATE_ERROR
)
{
if
(
drmSessionState
==
DrmSession
.
STATE_ERROR
)
{
throw
ExoPlaybackException
.
createForRenderer
(
codecDrmSession
.
getError
(),
getIndex
());
throw
ExoPlaybackException
.
createForRenderer
(
codecDrmSession
.
getError
(),
getIndex
());
...
@@ -1755,16 +1755,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
...
@@ -1755,16 +1755,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
}
}
/**
/**
* Returns whether the device needs keys to have been loaded into the {@link DrmSession} before
* codec configuration.
*/
private
boolean
deviceNeedsDrmKeysToConfigureCodecWorkaround
()
{
return
"Amazon"
.
equals
(
Util
.
MANUFACTURER
)
&&
(
"AFTM"
.
equals
(
Util
.
MODEL
)
// Fire TV Stick Gen 1
||
"AFTB"
.
equals
(
Util
.
MODEL
));
// Fire TV Gen 1
}
/**
* Returns whether the decoder is known to fail when flushed.
* Returns whether the decoder is known to fail when flushed.
* <p>
* <p>
* If true is returned, the renderer will work around the issue by releasing the decoder and
* If true is returned, the renderer will work around the issue by releasing the decoder and
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment