<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[174460] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/174460">174460</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2014-10-08 10:32:41 -0700 (Wed, 08 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[EME][Mac] Update CDMSessionMediaSourceAVFObjC to match new API provided by AVStreamSession
https://bugs.webkit.org/show_bug.cgi?id=137469

Reviewed by Brent Fulgham.

Update our forward declaration to match the API provided by AVStreamSession.
AVStreamSession now takes an error: parameter in its initialiazer. It also provides the
sessionIdentifier used by the CDM, which CDMSessionMediaSourceAVFObjC will use as the
value of sessionId. Having this identifier allows us to fire a
secure-proof-of-key-release message after the client calls MediaKeySession.close().
Because this call will now generate messages, which have to be responded to in order
to remove those proofs from storage, do not clear the CDMSession from MediaKeySession
after calling close().

* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::~MediaKeySession):
(WebCore::MediaKeySession::close):
(WebCore::MediaKeySession::setError): Deleted.
(WebCore::MediaKeySession::sessionId): Deleted.
* platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h:
(WebCore::CDMSessionMediaSourceAVFObjC::setSessionId):
* platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm:
(-[CDMSessionMediaSourceAVFObjCListener initWithParent:]):
(-[CDMSessionMediaSourceAVFObjCObserver dealloc]):
(-[CDMSessionMediaSourceAVFObjCObserver beginObserving:]):
(-[CDMSessionMediaSourceAVFObjCObserver stopObserving:]):
(-[CDMSessionMediaSourceAVFObjCObserver invalidate]):
(-[CDMSessionMediaSourceAVFObjCListener observeValueForKeyPath:ofObject:change:context:]):
(WebCore::CDMSessionMediaSourceAVFObjC::CDMSessionMediaSourceAVFObjC):
(WebCore::CDMSessionMediaSourceAVFObjC::~CDMSessionMediaSourceAVFObjC):
(WebCore::CDMSessionMediaSourceAVFObjC::releaseKeys):
(WebCore::CDMSessionMediaSourceAVFObjC::update):
(WebCore::CDMSessionMediaSourceAVFObjC::addSourceBuffer):
(WebCore::CDMSessionMediaSourceAVFObjC::removeSourceBuffer):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaMediaKeySessioncpp">trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMSessionMediaSourceAVFObjCh">trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMSessionMediaSourceAVFObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (174459 => 174460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-10-08 17:20:32 UTC (rev 174459)
+++ trunk/Source/WebCore/ChangeLog        2014-10-08 17:32:41 UTC (rev 174460)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2014-10-07  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [EME][Mac] Update CDMSessionMediaSourceAVFObjC to match new API provided by AVStreamSession
+        https://bugs.webkit.org/show_bug.cgi?id=137469
+
+        Reviewed by Brent Fulgham.
+
+        Update our forward declaration to match the API provided by AVStreamSession.
+        AVStreamSession now takes an error: parameter in its initialiazer. It also provides the
+        sessionIdentifier used by the CDM, which CDMSessionMediaSourceAVFObjC will use as the
+        value of sessionId. Having this identifier allows us to fire a
+        secure-proof-of-key-release message after the client calls MediaKeySession.close().
+        Because this call will now generate messages, which have to be responded to in order
+        to remove those proofs from storage, do not clear the CDMSession from MediaKeySession
+        after calling close().
+
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        (WebCore::MediaKeySession::~MediaKeySession):
+        (WebCore::MediaKeySession::close):
+        (WebCore::MediaKeySession::setError): Deleted.
+        (WebCore::MediaKeySession::sessionId): Deleted.
+        * platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h:
+        (WebCore::CDMSessionMediaSourceAVFObjC::setSessionId):
+        * platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm:
+        (-[CDMSessionMediaSourceAVFObjCListener initWithParent:]):
+        (-[CDMSessionMediaSourceAVFObjCObserver dealloc]):
+        (-[CDMSessionMediaSourceAVFObjCObserver beginObserving:]):
+        (-[CDMSessionMediaSourceAVFObjCObserver stopObserving:]):
+        (-[CDMSessionMediaSourceAVFObjCObserver invalidate]):
+        (-[CDMSessionMediaSourceAVFObjCListener observeValueForKeyPath:ofObject:change:context:]):
+        (WebCore::CDMSessionMediaSourceAVFObjC::CDMSessionMediaSourceAVFObjC):
+        (WebCore::CDMSessionMediaSourceAVFObjC::~CDMSessionMediaSourceAVFObjC):
+        (WebCore::CDMSessionMediaSourceAVFObjC::releaseKeys):
+        (WebCore::CDMSessionMediaSourceAVFObjC::update):
+        (WebCore::CDMSessionMediaSourceAVFObjC::addSourceBuffer):
+        (WebCore::CDMSessionMediaSourceAVFObjC::removeSourceBuffer):
+
</ins><span class="cx"> 2014-10-08  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed build fix after r174456.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaMediaKeySessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp (174459 => 174460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp        2014-10-08 17:20:32 UTC (rev 174459)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp        2014-10-08 17:32:41 UTC (rev 174460)
</span><span class="lines">@@ -59,7 +59,12 @@
</span><span class="cx"> 
</span><span class="cx"> MediaKeySession::~MediaKeySession()
</span><span class="cx"> {
</span><del>-    close();
</del><ins>+    if (m_session) {
+        m_session-&gt;setClient(nullptr);
+        m_session = nullptr;
+    }
+
+    m_asyncEventQueue.cancelAllEvents();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaKeySession::setError(MediaKeyError* error)
</span><span class="lines">@@ -69,12 +74,8 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaKeySession::close()
</span><span class="cx"> {
</span><del>-    if (m_session) {
</del><ins>+    if (m_session)
</ins><span class="cx">         m_session-&gt;releaseKeys();
</span><del>-        m_session-&gt;setClient(nullptr);
-    }
-    m_session = nullptr;
-    m_asyncEventQueue.cancelAllEvents();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> const String&amp; MediaKeySession::sessionId() const
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMSessionMediaSourceAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h (174459 => 174460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h        2014-10-08 17:20:32 UTC (rev 174459)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h        2014-10-08 17:32:41 UTC (rev 174460)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA_V2) &amp;&amp; ENABLE(MEDIA_SOURCE)
</span><span class="cx"> 
</span><span class="cx"> OBJC_CLASS AVStreamSession;
</span><ins>+OBJC_CLASS CDMSessionMediaSourceAVFObjCObserver;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -55,6 +56,8 @@
</span><span class="cx">     void addSourceBuffer(SourceBufferPrivateAVFObjC*);
</span><span class="cx">     void removeSourceBuffer(SourceBufferPrivateAVFObjC*);
</span><span class="cx"> 
</span><ins>+    void setSessionId(const String&amp; sessionId) { m_sessionId = sessionId; }
+
</ins><span class="cx"> protected:
</span><span class="cx">     PassRefPtr&lt;Uint8Array&gt; generateKeyReleaseMessage(unsigned short&amp; errorCode, unsigned long&amp; systemCode);
</span><span class="cx"> 
</span><span class="lines">@@ -64,6 +67,7 @@
</span><span class="cx">     RefPtr&lt;Uint8Array&gt; m_initData;
</span><span class="cx">     RefPtr&lt;Uint8Array&gt; m_certificate;
</span><span class="cx">     RetainPtr&lt;NSData&gt; m_expiredSession;
</span><ins>+    RetainPtr&lt;CDMSessionMediaSourceAVFObjCObserver&gt; m_dataParserObserver;
</ins><span class="cx">     String m_sessionId;
</span><span class="cx">     enum { Normal, KeyRelease } m_mode;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMSessionMediaSourceAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm (174459 => 174460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm        2014-10-08 17:20:32 UTC (rev 174459)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm        2014-10-08 17:32:41 UTC (rev 174460)
</span><span class="lines">@@ -51,10 +51,11 @@
</span><span class="cx"> - (void)processContentKeyResponseError:(NSError *)error forTrackID:(CMPersistentTrackID)trackID;
</span><span class="cx"> - (void)renewExpiringContentKeyResponseDataForTrackID:(CMPersistentTrackID)trackID;
</span><span class="cx"> - (NSData *)streamingContentKeyRequestDataForApp:(NSData *)appIdentifier contentIdentifier:(NSData *)contentIdentifier trackID:(CMPersistentTrackID)trackID options:(NSDictionary *)options error:(NSError **)outError;
</span><ins>+- (NSData *)sessionIdentifier;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @interface AVStreamSession : NSObject
</span><del>-- (instancetype)initWithAppIdentifier:(NSData *)appIdentifier storageDirectoryAtURL:(NSURL *)storageURL;
</del><ins>+- (instancetype)initWithAppIdentifier:(NSData *)appIdentifier storageDirectoryAtURL:(NSURL *)storageURL error:(NSError **)outError;
</ins><span class="cx"> - (void)addStreamDataParser:(AVStreamDataParser *)streamDataParser;
</span><span class="cx"> - (void)removeStreamDataParser:(AVStreamDataParser *)streamDataParser;
</span><span class="cx"> - (void)expire;
</span><span class="lines">@@ -62,22 +63,89 @@
</span><span class="cx"> + (void)removePendingExpiredSessionReports:(NSArray *)expiredSessionReports withAppIdentifier:(NSData *)appIdentifier;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface CDMSessionMediaSourceAVFObjCObserver : NSObject {
+    WebCore::CDMSessionMediaSourceAVFObjC *m_parent;
+    HashSet&lt;RetainPtr&lt;AVStreamDataParser&gt;&gt; m_parsers;
+}
+@end
+
+@implementation CDMSessionMediaSourceAVFObjCObserver
+- (id)initWithParent:(WebCore::CDMSessionMediaSourceAVFObjC *)parent
+{
+    if ((self = [super init]))
+        m_parent = parent;
+    return self;
+}
+
+- (void)dealloc
+{
+    [self invalidate];
+    [super dealloc];
+}
+
+- (void)beginObserving:(AVStreamDataParser *)parser
+{
+    ASSERT(!m_parsers.contains(parser));
+    m_parsers.add(parser);
+    [parser addObserver:self forKeyPath:@&quot;sessionIdentifier&quot; options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionInitial) context:nullptr];
+}
+
+- (void)stopObserving:(AVStreamDataParser *)parser
+{
+    ASSERT(m_parsers.contains(parser));
+    m_parsers.remove(parser);
+    [parser removeObserver:self forKeyPath:@&quot;sessionIdentifier&quot; context:nullptr];
+}
+
+- (void)invalidate
+{
+    m_parent = nullptr;
+    for (auto&amp; parser : m_parsers)
+        [parser removeObserver:self forKeyPath:@&quot;sessionIdentifier&quot; context:nullptr];
+    m_parsers.clear();
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void*)context
+{
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(change);
+    UNUSED_PARAM(context);
+
+    if ([keyPath isEqual:@&quot;sessionIdentifier&quot;]) {
+        NSData* identifier = [change valueForKey:NSKeyValueChangeNewKey];
+        if ([identifier isKindOfClass:[NSNull class]])
+            return;
+
+        RetainPtr&lt;NSString&gt; sessionIdentifierString = adoptNS([[NSString alloc] initWithData:identifier encoding:(NSUTF8StringEncoding)]);
+        if (m_parent)
+            m_parent-&gt;setSessionId(sessionIdentifierString.get());
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+@end
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> CDMSessionMediaSourceAVFObjC::CDMSessionMediaSourceAVFObjC()
</span><span class="cx">     : m_client(nullptr)
</span><del>-    , m_sessionId(createCanonicalUUIDString())
</del><ins>+    , m_dataParserObserver(adoptNS([[CDMSessionMediaSourceAVFObjCObserver alloc] initWithParent:this]))
</ins><span class="cx">     , m_mode(Normal)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CDMSessionMediaSourceAVFObjC::~CDMSessionMediaSourceAVFObjC()
</span><span class="cx"> {
</span><del>-    if (m_streamSession) {
-        for (auto&amp; sourceBuffer : m_sourceBuffers)
</del><ins>+    for (auto&amp; sourceBuffer : m_sourceBuffers) {
+        if (m_streamSession)
</ins><span class="cx">             [m_streamSession removeStreamDataParser:sourceBuffer-&gt;parser()];
</span><del>-        m_streamSession = nil;
</del><ins>+
+        [sourceBuffer-&gt;parser() removeObserver:m_dataParserObserver.get() forKeyPath:@&quot;sessionIdentifier&quot; context:nullptr];
</ins><span class="cx">     }
</span><ins>+
+    m_streamSession = nil;
+    [m_dataParserObserver invalidate];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> PassRefPtr&lt;Uint8Array&gt; CDMSessionMediaSourceAVFObjC::generateKeyRequest(const String&amp; mimeType, Uint8Array* initData, String&amp; destinationURL, unsigned short&amp; errorCode, unsigned long&amp; systemCode)
</span><span class="lines">@@ -107,15 +175,20 @@
</span><span class="cx"> 
</span><span class="cx"> void CDMSessionMediaSourceAVFObjC::releaseKeys()
</span><span class="cx"> {
</span><del>-    if (m_mode == KeyRelease) {
-        RetainPtr&lt;NSData&gt; certificateData = adoptNS([[NSData alloc] initWithBytes:m_certificate-&gt;data() length:m_certificate-&gt;length()]);
-        [getAVStreamSessionClass() removePendingExpiredSessionReports:@[m_expiredSession.get()] withAppIdentifier:certificateData.get()];
-        return;
-    }
-
</del><span class="cx">     if (m_streamSession) {
</span><span class="cx">         LOG(Media, &quot;CDMSessionMediaSourceAVFObjC::releaseKeys(%p) - expiring stream session&quot;, this);
</span><span class="cx">         [m_streamSession expire];
</span><ins>+
+        RetainPtr&lt;NSData&gt; certificateData = adoptNS([[NSData alloc] initWithBytes:m_certificate-&gt;data() length:m_certificate-&gt;length()]);
+        NSArray* expiredSessions = [getAVStreamSessionClass() pendingExpiredSessionReportsWithAppIdentifier:certificateData.get()];
+        for (NSData* expiredSessionData in expiredSessions) {
+            NSDictionary *expiredSession = [NSPropertyListSerialization propertyListWithData:expiredSessionData options:kCFPropertyListImmutable format:nullptr error:nullptr];
+            if ([expiredSession objectForKey:m_sessionId]) {
+                m_expiredSession = expiredSessionData;
+                m_client-&gt;sendMessage(Uint8Array::create(static_cast&lt;const uint8_t*&gt;([m_expiredSession bytes]), [m_expiredSession length]).get(), emptyString());
+                break;
+            }
+        }
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -163,6 +236,17 @@
</span><span class="cx">         m_certificate = key;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (isEqual(key, &quot;acknowledged&quot;)) {
+        if (!m_expiredSession) {
+            errorCode = MediaPlayer::InvalidPlayerState;
+            return false;
+        }
+
+        RetainPtr&lt;NSData&gt; certificateData = adoptNS([[NSData alloc] initWithBytes:m_certificate-&gt;data() length:m_certificate-&gt;length()]);
+        [getAVStreamSessionClass() removePendingExpiredSessionReports:@[m_expiredSession.get()] withAppIdentifier:certificateData.get()];
+        m_expiredSession = nullptr;
+    }
+
</ins><span class="cx">     RefPtr&lt;SourceBufferPrivateAVFObjC&gt; protectedSourceBuffer;
</span><span class="cx">     for (auto&amp; sourceBuffer : m_sourceBuffers) {
</span><span class="cx">         if (sourceBuffer-&gt;protectedTrackID() != -1) {
</span><span class="lines">@@ -173,8 +257,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (shouldGenerateKeyRequest) {
</span><span class="cx">         RetainPtr&lt;NSData&gt; certificateData = adoptNS([[NSData alloc] initWithBytes:m_certificate-&gt;data() length:m_certificate-&gt;length()]);
</span><del>-        if (getAVStreamSessionClass()) {
-            m_streamSession = adoptNS([[getAVStreamSessionClass() alloc] initWithAppIdentifier:certificateData.get() storageDirectoryAtURL:[NSURL fileURLWithPath:sessionStorageDirectory()]]);
</del><ins>+        if (getAVStreamSessionClass() &amp;&amp; [getAVStreamSessionClass() instancesRespondToSelector:@selector(initWithAppIdentifier:storageDirectoryAtURL:error:)]) {
+            m_streamSession = adoptNS([[getAVStreamSessionClass() alloc] initWithAppIdentifier:certificateData.get() storageDirectoryAtURL:[NSURL fileURLWithPath:sessionStorageDirectory()] error:nil]);
</ins><span class="cx">             for (auto&amp; sourceBuffer : m_sourceBuffers)
</span><span class="cx">                 [m_streamSession addStreamDataParser:sourceBuffer-&gt;parser()];
</span><span class="cx">             LOG(Media, &quot;CDMSessionMediaSourceAVFObjC::update(%p) - created stream session %p&quot;, this, m_streamSession.get());
</span><span class="lines">@@ -191,6 +275,9 @@
</span><span class="cx">         NSError* error = nil;
</span><span class="cx">         RetainPtr&lt;NSData&gt; request = [protectedSourceBuffer-&gt;parser() streamingContentKeyRequestDataForApp:certificateData.get() contentIdentifier:initData.get() trackID:protectedSourceBuffer-&gt;protectedTrackID() options:nil error:&amp;error];
</span><span class="cx"> 
</span><ins>+        if (![protectedSourceBuffer-&gt;parser() respondsToSelector:@selector(sessionIdentifier)])
+            m_sessionId = createCanonicalUUIDString();
+
</ins><span class="cx">         if (error) {
</span><span class="cx">             LOG(Media, &quot;CDMSessionMediaSourceAVFObjC::update(%p) - error:%@&quot;, this, [error description]);
</span><span class="cx">             errorCode = MediaPlayer::InvalidPlayerState;
</span><span class="lines">@@ -209,6 +296,7 @@
</span><span class="cx">     systemCode = 0;
</span><span class="cx">     RetainPtr&lt;NSData&gt; keyData = adoptNS([[NSData alloc] initWithBytes:key-&gt;data() length:key-&gt;length()]);
</span><span class="cx">     [protectedSourceBuffer-&gt;parser() processContentKeyResponseData:keyData.get() forTrackID:protectedSourceBuffer-&gt;protectedTrackID()];
</span><ins>+
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -238,6 +326,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_streamSession)
</span><span class="cx">         [m_streamSession addStreamDataParser:sourceBuffer-&gt;parser()];
</span><ins>+
+    [m_dataParserObserver beginObserving:sourceBuffer-&gt;parser()];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CDMSessionMediaSourceAVFObjC::removeSourceBuffer(SourceBufferPrivateAVFObjC* sourceBuffer)
</span><span class="lines">@@ -250,6 +340,8 @@
</span><span class="cx"> 
</span><span class="cx">     sourceBuffer-&gt;unregisterForErrorNotifications(this);
</span><span class="cx">     m_sourceBuffers.remove(m_sourceBuffers.find(sourceBuffer));
</span><ins>+
+    [m_dataParserObserver stopObserving:sourceBuffer-&gt;parser()];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> PassRefPtr&lt;Uint8Array&gt; CDMSessionMediaSourceAVFObjC::generateKeyReleaseMessage(unsigned short&amp; errorCode, unsigned long&amp; systemCode)
</span></span></pre>
</div>
</div>

</body>
</html>