@@ -59,60 +59,25 @@ MediaPlayer.dependencies.Stream = function () {
5959 } ,
6060
6161 // Encrypted Media Extensions
62+ pendingNeedKeyData = [ ] ,
63+ keySystem = undefined ,
6264
6365 handleEMEError = function ( message ) {
6466 this . errHandler . mediaKeySessionError ( message ) ;
6567 this . debug . log ( message ) ;
6668 this . reset ( ) ;
6769 } ,
6870
69- keySystemAccess = null ,
70- pendingNeedKeyData = [ ] ,
71- selectKeySystem = function ( initData ) {
72-
73- // Does the initData contain a key system supported by the player?
74- var supportedKS = this . protectionExt . getSupportedKeySystems ( initData ) ;
75- if ( supportedKS . length === 0 ) {
76- handleEMEError . call ( this , "DRM system for this content not supported by the player!" ) ;
77- return ;
78- }
79-
80- var ksConfig = new MediaPlayer . vo . protection . KeySystemConfiguration (
81- [ new MediaPlayer . vo . protection . MediaCapability ( mediaInfos . audio . codec ) ] ,
82- [ new MediaPlayer . vo . protection . MediaCapability ( mediaInfos . video . codec ) ] ) ;
83- var requestedKeySystems = [ ] ;
84- for ( var i = 0 ; i < supportedKS . length ; i ++ ) {
85- requestedKeySystems . push ( { ks : supportedKS [ i ] . ks , configs : [ ksConfig ] } ) ;
86- }
87-
88- // Callback for KEY_SYSTEM_ACCESS_COMPLETE event
89- var onKeySystemAccessComplete = function ( event ) {
90- this . protectionModel . unsubscribe ( MediaPlayer . models . ProtectionModel . eventList . ENAME_KEY_SYSTEM_ACCESS_COMPLETE , this ) ;
91- if ( ! event . error ) {
92- keySystemAccess = event . data ;
93- this . debug . log ( "KeySystem Access Granted (" + keySystemAccess . keySystem . systemString + ")!" ) ;
94- this . protectionModel . selectKeySystem ( keySystemAccess ) ;
95- } else {
96- handleEMEError . call ( this , event . error ) ;
97- }
98- } ;
99-
100- // Subscribe for event and then perform request
101- this [ MediaPlayer . models . ProtectionModel . eventList . ENAME_KEY_SYSTEM_ACCESS_COMPLETE ] = onKeySystemAccessComplete . bind ( this ) ;
102- this . protectionModel . subscribe ( MediaPlayer . models . ProtectionModel . eventList . ENAME_KEY_SYSTEM_ACCESS_COMPLETE , this ) ;
103- this . protectionModel . requestKeySystemAccess ( requestedKeySystems ) ;
104- } ,
105-
10671 createSession = function ( needKeyInitData ) {
107- var initData = MediaPlayer . dependencies . protection . CommonEncryption . getPSSHForKeySystem ( this . protectionModel . keySystem , needKeyInitData ) ;
72+ var initData = MediaPlayer . dependencies . protection . CommonEncryption . getPSSHForKeySystem ( keySystem , needKeyInitData ) ;
10873 if ( initData ) {
10974 try {
110- this . protectionModel . createKeySession ( initData , "temporary" ) ;
75+ this . protectionController . createKeySession ( initData , "temporary" ) ;
11176 } catch ( error ) {
11277 handleEMEError . call ( this , "Error creating key session! " + error . message ) ;
11378 }
11479 } else {
115- handleEMEError . call ( this , "Selected key system is " + this . protectionModel . keySystem . systemString + ". needkey/encrypted event contains no initData corresponding to that key system!" ) ;
80+ handleEMEError . call ( this , "Selected key system is " + keySystem . systemString + ". needkey/encrypted event contains no initData corresponding to that key system!" ) ;
11681 }
11782 } ,
11883
@@ -123,14 +88,15 @@ MediaPlayer.dependencies.Stream = function () {
12388 return ;
12489 }
12590
126- if ( this . keySystem ) {
91+ if ( keySystem ) {
12792 // We have a key system
12893 createSession . call ( this , event . data . initData ) ;
12994 }
130- else if ( this . keySystem === undefined ) {
95+ else if ( keySystem === undefined ) {
13196 // First time through, so we need to select a key system
132- this . keySystem = null ;
133- selectKeySystem . call ( this , event . data . initData ) ;
97+ keySystem = null ;
98+ this . protectionExt . autoSelectKeySystem ( this . protectionModel , this . protectionController ,
99+ mediaInfos , event . data . initData ) ;
134100 pendingNeedKeyData . push ( event . data . initData ) ;
135101 } else {
136102 // We are in the process of selecting a key system, so just save the data
@@ -143,12 +109,12 @@ MediaPlayer.dependencies.Stream = function () {
143109 // events and process any pending initData generated by needkey/encrypted
144110 // events
145111
146- if ( ! ! this . keySystem && this . keySystem !== this . protectionModel . keySystem ) {
112+ if ( ! ! keySystem && keySystem !== this . protectionModel . keySystem ) {
147113 handleEMEError . call ( this , "DRM: Changing key systems within a single Period is not allowed!" ) ;
148114 }
149- if ( ! this . keySystem ) {
150- this . keySystem = this . protectionModel . keySystem ;
151- this . protectionModel . keySystem . subscribe ( MediaPlayer . dependencies . protection . KeySystem . eventList . ENAME_LICENSE_REQUEST_COMPLETE , this ) ;
115+ if ( ! keySystem ) {
116+ keySystem = this . protectionModel . keySystem ;
117+ keySystem . subscribe ( MediaPlayer . dependencies . protection . KeySystem . eventList . ENAME_LICENSE_REQUEST_COMPLETE , this ) ;
152118 }
153119 for ( var i = 0 ; i < pendingNeedKeyData . length ; i ++ ) {
154120 createSession . call ( this , pendingNeedKeyData [ i ] ) ;
@@ -165,7 +131,7 @@ MediaPlayer.dependencies.Stream = function () {
165131
166132 onKeySessionCreated = function ( event ) {
167133 if ( ! event . error ) {
168- this . debug . log ( "DRM: Session created. SessionID = " + event . data . sessionID ) ;
134+ this . debug . log ( "DRM: Session created. SessionID = " + event . data . getSessionID ( ) ) ;
169135 } else {
170136 handleEMEError . call ( this , event . error ) ;
171137 }
@@ -177,7 +143,7 @@ MediaPlayer.dependencies.Stream = function () {
177143
178144 onLicenseRequestComplete = function ( e ) {
179145 if ( ! e . error ) {
180- this . debug . log ( "DRM: License request successful. Session ID = " + e . data . requestData . sessionID ) ;
146+ this . debug . log ( "DRM: License request successful. Session ID = " + e . data . requestData . getSessionID ( ) ) ;
181147 this . protectionController . updateKeySession ( e . data . requestData , e . data . message ) ;
182148 } else {
183149 handleEMEError . call ( this , e . error ) ;
@@ -186,9 +152,8 @@ MediaPlayer.dependencies.Stream = function () {
186152
187153 onKeyError = function ( event ) {
188154 var session = event . data . sessionToken ,
189- sessionID = ( session . sessionID ) ? session . sessionID : "NONE" ,
190155 msg ;
191- msg = 'DRM: MediaKeyError - sessionId: ' + sessionID + '. ' + event . data . error ;
156+ msg = 'DRM: MediaKeyError - sessionId: ' + session . getSessionID ( ) + '. ' + event . data . error ;
192157 handleEMEError . call ( this , msg ) ;
193158 } ,
194159
@@ -639,9 +604,9 @@ MediaPlayer.dependencies.Stream = function () {
639604 this . protectionModel . unsubscribe ( MediaPlayer . models . ProtectionModel . eventList . ENAME_KEY_SESSION_CREATED , this ) ;
640605 this . protectionModel . unsubscribe ( MediaPlayer . models . ProtectionModel . eventList . ENAME_KEY_SESSION_CLOSED , this ) ;
641606 this . protectionModel . unsubscribe ( MediaPlayer . models . ProtectionModel . eventList . ENAME_KEY_SESSION_REMOVED , this ) ;
642- if ( ! ! this . keySystem ) {
643- this . keySystem . unsubscribe ( MediaPlayer . dependencies . protection . KeySystem . eventList . ENAME_LICENSE_REQUEST_COMPLETE , this ) ;
644- this . keySystem = undefined ;
607+ if ( ! ! keySystem ) {
608+ keySystem . unsubscribe ( MediaPlayer . dependencies . protection . KeySystem . eventList . ENAME_LICENSE_REQUEST_COMPLETE , this ) ;
609+ keySystem = undefined ;
645610 }
646611
647612 this . protectionController . teardown ( ) ;
0 commit comments