Changeset 173197 in webkit


Ignore:
Timestamp:
Sep 2, 2014 6:28:33 PM (10 years ago)
Author:
jer.noble@apple.com
Message:

[EME][Mac] Refactor CDMPrivateMediaSourceAVFObjC to allow sessions to be created without being attached to an AVStreamDataParser.
https://bugs.webkit.org/show_bug.cgi?id=136016

Reviewed by Eric Carlson.

The CDMPrivateMediaPlayer class will delegate creation of CDMSession instances to the current MediaPlayer. This
of course requires the MediaKeys object owning the CDM to be attached to a HTMLMediaElement, and specifically to
one with a valid src attribute or source node which has sucessfully begun loading. For certain CDM operations,
it would be better if a given MediaKeys could create a session without actually being connected to a
HTMLMediaElement (yet).

To facilitate this for CDMSessionPrivateMediaSourceAVFObjC, add a new class, CDMPrivateMediaSourceAVFObjC, which
is the primary factory for CDMSessionPrivateMediaSOurceAVFObjC. Disclaim responsibility for creating these sessions
in MediaPlayerPrivateMediaSourceAVFObjC by not passing the "supportsKeySystem" method when registering itself.

Add methods to CDMSessionPrivateMediaSourceAVFObjC to allow SourceBuffers to be added and removed from the session,
to support adding the session to the HTMLMediaElement after the session has been created.

Since MediaPlayerPrivate instance and CDMSession instances must be able to communicate with one another, add a type()
enum and virtual method to allow CDMSession instnaces to be distinguisted from (and casted to) one another.

  • Modules/encryptedmedia/CDM.cpp:

(WebCore::installedCDMFactories): Register CDMPrivateMediaSourceAVFObjC.
(WebCore::CDM::createSession): Notify the MediaPlayer of the new CDMSession.

  • Modules/encryptedmedia/MediaKeySession.h:
  • Modules/encryptedmedia/MediaKeys.cpp:

(WebCore::MediaKeys::setMediaElement): Notify the HTMLMediaElement of any existing sessions.

  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/CDMSession.h:

(WebCore::CDMSession::type): Added.

  • platform/graphics/MediaPlayer.cpp:

(WebCore::MediaPlayer::setCDMSession): Pass through to the MediaPlayerPrivate.

  • platform/graphics/MediaPlayer.h:
  • platform/graphics/MediaPlayerPrivate.h:

(WebCore::MediaPlayerPrivateInterface::setCDMSession): Added. Default no-op.

  • platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.h: Added.

(WebCore::CDMPrivateMediaSourceAVFObjC::CDMPrivateMediaSourceAVFObjC): Simple constructor.
(WebCore::CDMPrivateMediaSourceAVFObjC::~CDMPrivateMediaSourceAVFObjC): Simple destructor.
(WebCore::CDMPrivateMediaSourceAVFObjC::create): Simple factory.
(WebCore::CDMPrivateMediaSourceAVFObjC::cdm): Simple accessor.

  • platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:

(WebCore::CDMPrivateMediaSourceAVFObjC::supportsKeySystem): Moved from MediaPlayerPrivateMediaSourceAVFObjC.
(WebCore::CDMPrivateMediaSourceAVFObjC::supportsKeySystemAndMimeType): Ditto.
(WebCore::CDMPrivateMediaSourceAVFObjC::supportsMIMEType): Ditto.
(WebCore::CDMPrivateMediaSourceAVFObjC::createSession): Returns new CDMSessionMediaSourceAVFObjC.

  • platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h:

(WebCore::CDMSessionAVFoundationObjC::type): Added.

  • platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h:

(WebCore::CDMSessionMediaSourceAVFObjC::type): Added.
(WebCore::toCDMSessionMediaSourceAVFObjC): Throw assertion if type() is not correct.

  • platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm:

(WebCore::CDMSessionMediaSourceAVFObjC::CDMSessionMediaSourceAVFObjC): Removed m_parent ivar.
(WebCore::CDMSessionMediaSourceAVFObjC::~CDMSessionMediaSourceAVFObjC): Ditto.
(WebCore::CDMSessionMediaSourceAVFObjC::update): Determing which SourceBuffer is protected.
(WebCore::CDMSessionMediaSourceAVFObjC::addSourceBuffer): Added.
(WebCore::CDMSessionMediaSourceAVFObjC::removeSourceBuffer): Added.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
  • platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:

(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::registerMediaEngine): Remove supportsKeyType parameter.
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::supportsType): Remove keyType check.
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setCDMSession): Tell the CDMSession about outstanding SourceBuffers.

  • platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.h:
  • platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm:
Location:
trunk/Source/WebCore
Files:
1 added
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r173196 r173197  
     12014-09-02  Jer Noble  <jer.noble@apple.com>
     2
     3        [EME][Mac] Refactor CDMPrivateMediaSourceAVFObjC to allow sessions to be created without being attached to an AVStreamDataParser.
     4        https://bugs.webkit.org/show_bug.cgi?id=136016
     5
     6        Reviewed by Eric Carlson.
     7
     8        The CDMPrivateMediaPlayer class will delegate creation of CDMSession instances to the current MediaPlayer. This
     9        of course requires the MediaKeys object owning the CDM to be attached to a HTMLMediaElement, and specifically to
     10        one with a valid src attribute or source node which has sucessfully begun loading. For certain CDM operations,
     11        it would be better if a given MediaKeys could create a session without actually being connected to a
     12        HTMLMediaElement (yet).
     13
     14        To facilitate this for CDMSessionPrivateMediaSourceAVFObjC, add a new class, CDMPrivateMediaSourceAVFObjC, which
     15        is the primary factory for CDMSessionPrivateMediaSOurceAVFObjC. Disclaim responsibility for creating these sessions
     16        in MediaPlayerPrivateMediaSourceAVFObjC by not passing the "supportsKeySystem" method when registering itself.
     17
     18        Add methods to CDMSessionPrivateMediaSourceAVFObjC to allow SourceBuffers to be added and removed from the session,
     19        to support adding the session to the HTMLMediaElement after the session has been created.
     20
     21        Since MediaPlayerPrivate instance and  CDMSession instances must be able to communicate with one another, add a type()
     22        enum and virtual method to allow CDMSession instnaces to be distinguisted from (and casted to) one another.
     23
     24        * Modules/encryptedmedia/CDM.cpp:
     25        (WebCore::installedCDMFactories): Register CDMPrivateMediaSourceAVFObjC.
     26        (WebCore::CDM::createSession): Notify the MediaPlayer of the new CDMSession.
     27        * Modules/encryptedmedia/MediaKeySession.h:
     28        * Modules/encryptedmedia/MediaKeys.cpp:
     29        (WebCore::MediaKeys::setMediaElement): Notify the HTMLMediaElement of any existing sessions.
     30        * WebCore.xcodeproj/project.pbxproj:
     31        * platform/graphics/CDMSession.h:
     32        (WebCore::CDMSession::type): Added.
     33        * platform/graphics/MediaPlayer.cpp:
     34        (WebCore::MediaPlayer::setCDMSession): Pass through to the MediaPlayerPrivate.
     35        * platform/graphics/MediaPlayer.h:
     36        * platform/graphics/MediaPlayerPrivate.h:
     37        (WebCore::MediaPlayerPrivateInterface::setCDMSession): Added. Default no-op.
     38        * platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.h: Added.
     39        (WebCore::CDMPrivateMediaSourceAVFObjC::CDMPrivateMediaSourceAVFObjC): Simple constructor.
     40        (WebCore::CDMPrivateMediaSourceAVFObjC::~CDMPrivateMediaSourceAVFObjC): Simple destructor.
     41        (WebCore::CDMPrivateMediaSourceAVFObjC::create): Simple factory.
     42        (WebCore::CDMPrivateMediaSourceAVFObjC::cdm): Simple accessor.
     43        * platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
     44        (WebCore::CDMPrivateMediaSourceAVFObjC::supportsKeySystem): Moved from MediaPlayerPrivateMediaSourceAVFObjC.
     45        (WebCore::CDMPrivateMediaSourceAVFObjC::supportsKeySystemAndMimeType): Ditto.
     46        (WebCore::CDMPrivateMediaSourceAVFObjC::supportsMIMEType): Ditto.
     47        (WebCore::CDMPrivateMediaSourceAVFObjC::createSession): Returns new CDMSessionMediaSourceAVFObjC.
     48        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h:
     49        (WebCore::CDMSessionAVFoundationObjC::type): Added.
     50        * platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h:
     51        (WebCore::CDMSessionMediaSourceAVFObjC::type): Added.
     52        (WebCore::toCDMSessionMediaSourceAVFObjC): Throw assertion if type() is not correct.
     53        * platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm:
     54        (WebCore::CDMSessionMediaSourceAVFObjC::CDMSessionMediaSourceAVFObjC): Removed m_parent ivar.
     55        (WebCore::CDMSessionMediaSourceAVFObjC::~CDMSessionMediaSourceAVFObjC): Ditto.
     56        (WebCore::CDMSessionMediaSourceAVFObjC::update): Determing which SourceBuffer is protected.
     57        (WebCore::CDMSessionMediaSourceAVFObjC::addSourceBuffer): Added.
     58        (WebCore::CDMSessionMediaSourceAVFObjC::removeSourceBuffer): Added.
     59        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
     60        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
     61        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC):
     62        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::registerMediaEngine): Remove supportsKeyType parameter.
     63        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::supportsType): Remove keyType check.
     64        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setCDMSession): Tell the CDMSession about outstanding SourceBuffers.
     65        * platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.h:
     66        * platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm:
     67
    1682014-09-02  Daniel Bates  <dabates@apple.com>
    269
  • trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp

    r170650 r173197  
    3434#include "MediaKeyError.h"
    3535#include "MediaKeys.h"
     36#include "MediaPlayer.h"
    3637#include <wtf/NeverDestroyed.h>
    3738#include <wtf/text/WTFString.h>
     39
     40#if PLATFORM(MAC) && ENABLE(MEDIA_SOURCE)
     41#include "CDMPrivateMediaSourceAVFObjC.h"
     42#endif
    3843
    3944namespace WebCore {
     
    6368        // FIXME: initialize specific UA CDMs. http://webkit.org/b/109318, http://webkit.org/b/109320
    6469        cdms.get().append(new CDMFactory(CDMPrivateMediaPlayer::create, CDMPrivateMediaPlayer::supportsKeySystem, CDMPrivateMediaPlayer::supportsKeySystemAndMimeType));
     70
     71#if PLATFORM(MAC) && ENABLE(MEDIA_SOURCE)
     72        cdms.get().append(new CDMFactory(CDMPrivateMediaSourceAVFObjC::create, CDMPrivateMediaSourceAVFObjC::supportsKeySystem, CDMPrivateMediaSourceAVFObjC::supportsKeySystemAndMimeType));
     73#endif
    6574    }
    6675
     
    121130std::unique_ptr<CDMSession> CDM::createSession()
    122131{
    123     return m_private->createSession();
     132    std::unique_ptr<CDMSession> session = m_private->createSession();
     133    if (mediaPlayer())
     134        mediaPlayer()->setCDMSession(session.get());
     135    return session;
    124136}
    125137
  • trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h

    r169830 r173197  
    5252
    5353    const String& keySystem() const { return m_keySystem; }
     54    CDMSession* session() { return m_session.get(); }
    5455    const String& sessionId() const;
    5556
  • trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp

    r170774 r173197  
    145145void MediaKeys::setMediaElement(HTMLMediaElement* element)
    146146{
     147    if (m_mediaElement)
     148        m_mediaElement->player()->setCDMSession(nullptr);
     149
    147150    m_mediaElement = element;
     151
     152    if (m_mediaElement && !m_sessions.isEmpty())
     153        m_mediaElement->player()->setCDMSession(m_sessions.last()->session());
    148154}
    149155
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r173192 r173197  
    55925592                CD2F4A2718D8A3490063746D /* AudioHardwareListenerMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD2F4A2518D8A3490063746D /* AudioHardwareListenerMac.cpp */; };
    55935593                CD2F4A2818D8A3490063746D /* AudioHardwareListenerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = CD2F4A2618D8A3490063746D /* AudioHardwareListenerMac.h */; };
     5594                CD318622199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD318620199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.mm */; };
     5595                CD318623199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CD318621199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.h */; };
    55945596                CD336F6117F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD336F5F17F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm */; };
    55955597                CD336F6217F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6017F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h */; };
     
    1300413006                CD2F4A2518D8A3490063746D /* AudioHardwareListenerMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioHardwareListenerMac.cpp; sourceTree = "<group>"; };
    1300513007                CD2F4A2618D8A3490063746D /* AudioHardwareListenerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioHardwareListenerMac.h; sourceTree = "<group>"; };
     13008                CD318620199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CDMPrivateMediaSourceAVFObjC.mm; sourceTree = "<group>"; };
     13009                CD318621199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMPrivateMediaSourceAVFObjC.h; sourceTree = "<group>"; };
    1300613010                CD32A189184EB46A0029B1BB /* mediaControlsiOS.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = mediaControlsiOS.js; sourceTree = "<group>"; };
    1300713011                CD336F5F17F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AVTrackPrivateAVFObjCImpl.mm; sourceTree = "<group>"; };
     
    2157921583                                CD336F6017F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h */,
    2158021584                                CD336F5F17F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm */,
     21585                                CD318621199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.h */,
     21586                                CD318620199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.mm */,
    2158121587                                CDDE02EA18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.h */,
    2158221588                                CDDE02EB18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.mm */,
     
    2451724523                                4B3480940EEF50D400AC1B41 /* ImageSourceCG.h in Headers */,
    2451824524                                316FE1180E6E1DA700BF6088 /* ImplicitAnimation.h in Headers */,
     24525                                CD318623199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.h in Headers */,
    2451924526                                BE16C59317CFE17200852C04 /* InbandGenericTextTrack.h in Headers */,
    2452024527                                07941792166E855F009416C2 /* InbandTextTrack.h in Headers */,
     
    2744627453                                93F9B6570BA0F35E00854064 /* DOMHTMLCanvasElement.mm in Sources */,
    2744727454                                85DF2F8F0AA3C88100AD64C5 /* DOMHTMLCollection.mm in Sources */,
     27455                                CD318622199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.mm in Sources */,
    2744827456                                F5C041E40FFCA96D00839D4A /* DOMHTMLDataListElement.mm in Sources */,
    2744927457                                D359D792129CA3C00006E5D2 /* DOMHTMLDetailsElement.mm in Sources */,
  • trunk/Source/WebCore/platform/graphics/CDMSession.h

    r169830 r173197  
    5353};
    5454
     55enum CDMSessionType {
     56    CDMSessionTypeUnknown,
     57    CDMSessionTypeAVFoundationObjC,
     58    CDMSessionTypeMediaSourceAVFObjC,
     59};
     60
    5561class CDMSession {
    5662public:
     
    5864    virtual ~CDMSession() { }
    5965
     66    virtual CDMSessionType type() { return CDMSessionTypeUnknown; }
    6067    virtual void setClient(CDMSessionClient*) = 0;
    6168    virtual const String& sessionId() const = 0;
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp

    r172868 r173197  
    511511    return m_private->createSession(keySystem);
    512512}
     513
     514void MediaPlayer::setCDMSession(CDMSession* session)
     515{
     516    m_private->setCDMSession(session);
     517}
    513518#endif
    514519   
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.h

    r172868 r173197  
    360360#if ENABLE(ENCRYPTED_MEDIA_V2)
    361361    std::unique_ptr<CDMSession> createSession(const String& keySystem);
     362    void setCDMSession(CDMSession*);
    362363#endif
    363364
  • trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h

    r172868 r173197  
    222222#if ENABLE(ENCRYPTED_MEDIA_V2)
    223223    virtual std::unique_ptr<CDMSession> createSession(const String&) { return nullptr; }
     224    virtual void setCDMSession(CDMSession*) { }
    224225#endif
    225226
  • trunk/Source/WebCore/platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.h

    r173196 r173197  
    2424 */
    2525
    26 #ifndef CDMSessionAVFoundationObjC_h
    27 #define CDMSessionAVFoundationObjC_h
     26#ifndef CDMPrivateMediaSourceAVFObjC_h
     27#define CDMPrivateMediaSourceAVFObjC_h
    2828
    29 #include "CDMSession.h"
    30 #include <wtf/PassOwnPtr.h>
    31 #include <wtf/RetainPtr.h>
     29#if ENABLE(ENCRYPTED_MEDIA_V2) && ENABLE(MEDIA_SOURCE)
    3230
    33 #if ENABLE(ENCRYPTED_MEDIA_V2) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    34 
    35 OBJC_CLASS AVAssetResourceLoadingRequest;
     31#include "CDMPrivate.h"
    3632
    3733namespace WebCore {
    3834
    39 class MediaPlayerPrivateAVFoundationObjC;
     35class CDM;
    4036
    41 class CDMSessionAVFoundationObjC : public CDMSession {
     37class CDMPrivateMediaSourceAVFObjC : public CDMPrivateInterface {
    4238public:
    43     CDMSessionAVFoundationObjC(MediaPlayerPrivateAVFoundationObjC* parent);
    44     virtual ~CDMSessionAVFoundationObjC() { }
     39    explicit CDMPrivateMediaSourceAVFObjC(CDM* cdm)
     40        : m_cdm(cdm)
     41    { }
     42    virtual ~CDMPrivateMediaSourceAVFObjC() { }
    4543
    46     virtual void setClient(CDMSessionClient* client) override { m_client = client; }
    47     virtual const String& sessionId() const override { return m_sessionId; }
    48     virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) override;
    49     virtual void releaseKeys() override;
    50     virtual bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) override;
     44    static std::unique_ptr<CDMPrivateInterface> create(CDM* cdm) { return std::make_unique<CDMPrivateMediaSourceAVFObjC>(cdm); }
     45    static bool supportsKeySystem(const String&);
     46    static bool supportsKeySystemAndMimeType(const String& keySystem, const String& mimeType);
     47
     48    virtual bool supportsMIMEType(const String& mimeType) override;
     49    virtual std::unique_ptr<CDMSession> createSession() override;
     50
     51    CDM* cdm() const { return m_cdm; }
    5152
    5253protected:
    53     MediaPlayerPrivateAVFoundationObjC* m_parent;
    54     CDMSessionClient* m_client;
    55     String m_sessionId;
    56     RetainPtr<AVAssetResourceLoadingRequest> m_request;
     54    CDM* m_cdm;
    5755};
    5856
    5957}
    6058
    61 #endif
     59#endif // ENABLE(ENCRYPTED_MEDIA_V2) && ENABLE(MEDIA_SOURCE)
    6260
    63 #endif // CDMSessionAVFoundationObjC_h
     61#endif // CDMPrivateMediaSourceAVFObjC_h
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h

    r164514 r173197  
    4444    virtual ~CDMSessionAVFoundationObjC() { }
    4545
     46    virtual CDMSessionType type() { return CDMSessionTypeAVFoundationObjC; }
    4647    virtual void setClient(CDMSessionClient* client) override { m_client = client; }
    4748    virtual const String& sessionId() const override { return m_sessionId; }
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h

    r172651 r173197  
    4040class CDMSessionMediaSourceAVFObjC : public CDMSession, public SourceBufferPrivateAVFObjCErrorClient {
    4141public:
    42     CDMSessionMediaSourceAVFObjC(SourceBufferPrivateAVFObjC* parent);
     42    CDMSessionMediaSourceAVFObjC();
    4343    virtual ~CDMSessionMediaSourceAVFObjC();
    4444
     45    virtual CDMSessionType type() { return CDMSessionTypeMediaSourceAVFObjC; }
    4546    virtual void setClient(CDMSessionClient* client) override { m_client = client; }
    4647    virtual const String& sessionId() const override { return m_sessionId; }
     
    5253    virtual void rendererDidReceiveError(AVSampleBufferAudioRenderer *, NSError *);
    5354
     55    void addSourceBuffer(SourceBufferPrivateAVFObjC*);
     56    void removeSourceBuffer(SourceBufferPrivateAVFObjC*);
     57
    5458protected:
    55     RefPtr<SourceBufferPrivateAVFObjC> m_parent;
     59    Vector<RefPtr<SourceBufferPrivateAVFObjC>> m_sourceBuffers;
    5660    CDMSessionClient* m_client;
    5761    RetainPtr<AVStreamSession> m_streamSession;
     
    6165};
    6266
     67inline CDMSessionMediaSourceAVFObjC* toCDMSessionMediaSourceAVFObjC(CDMSession* session)
     68{
     69    if (!session || session->type() != CDMSessionTypeMediaSourceAVFObjC)
     70        return nullptr;
     71    return static_cast<CDMSessionMediaSourceAVFObjC*>(session);
     72}
     73
    6374}
    6475
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm

    r172651 r173197  
    6363namespace WebCore {
    6464
    65 CDMSessionMediaSourceAVFObjC::CDMSessionMediaSourceAVFObjC(SourceBufferPrivateAVFObjC* parent)
    66     : m_parent(parent)
    67     , m_client(nullptr)
     65CDMSessionMediaSourceAVFObjC::CDMSessionMediaSourceAVFObjC()
     66    : m_client(nullptr)
    6867    , m_sessionId(createCanonicalUUIDString())
    6968{
    70     ASSERT(parent);
    71     parent->registerForErrorNotifications(this);
    7269}
    7370
     
    7572{
    7673    if (m_streamSession) {
    77         [m_streamSession removeStreamDataParser:m_parent->parser()];
     74        for (auto& sourceBuffer : m_sourceBuffers)
     75            [m_streamSession removeStreamDataParser:sourceBuffer->parser()];
    7876        m_streamSession = nil;
    7977    }
    80     m_parent->unregisterForErrorNotifications(this);
    81     m_client = nullptr;
    8278}
    8379
     
    135131    }
    136132
     133    RefPtr<SourceBufferPrivateAVFObjC> protectedSourceBuffer;
     134    for (auto& sourceBuffer : m_sourceBuffers) {
     135        if (sourceBuffer->protectedTrackID() != -1) {
     136            protectedSourceBuffer = sourceBuffer;
     137            break;
     138        }
     139    }
     140
    137141    if (shouldGenerateKeyRequest) {
    138142        RetainPtr<NSData> certificateData = adoptNS([[NSData alloc] initWithBytes:m_certificate->data() length:m_certificate->length()]);
    139143        if (getAVStreamSessionClass()) {
    140144            m_streamSession = adoptNS([[getAVStreamSessionClass() alloc] initWithAppIdentifier:certificateData.get()]);
    141             [m_streamSession addStreamDataParser:m_parent->parser()];
     145            for (auto& sourceBuffer : m_sourceBuffers)
     146                [m_streamSession addStreamDataParser:sourceBuffer->parser()];
    142147            LOG(Media, "CDMSessionMediaSourceAVFObjC::update(%p) - created stream session %p", this, m_streamSession.get());
    143148        }
    144149
     150        if (m_sourceBuffers.isEmpty())
     151            return true;
     152
     153        if (!protectedSourceBuffer)
     154            return true;
     155
    145156        RetainPtr<NSData> initData = adoptNS([[NSData alloc] initWithBytes:m_initData->data() length:m_initData->length()]);
    146157
    147158        NSError* error = nil;
    148         RetainPtr<NSData> request = [m_parent->parser() streamingContentKeyRequestDataForApp:certificateData.get() contentIdentifier:initData.get() trackID:m_parent->protectedTrackID() options:nil error:&error];
     159        RetainPtr<NSData> request = [protectedSourceBuffer->parser() streamingContentKeyRequestDataForApp:certificateData.get() contentIdentifier:initData.get() trackID:protectedSourceBuffer->protectedTrackID() options:nil error:&error];
    149160
    150161        if (error) {
     
    160171    }
    161172
     173    ASSERT(!m_sourceBuffers.isEmpty());
    162174    LOG(Media, "CDMSessionMediaSourceAVFObjC::update(%p) - key data", this);
    163175    errorCode = MediaPlayer::NoError;
    164176    systemCode = 0;
    165177    RetainPtr<NSData> keyData = adoptNS([[NSData alloc] initWithBytes:key->data() length:key->length()]);
    166     [m_parent->parser() processContentKeyResponseData:keyData.get() forTrackID:m_parent->protectedTrackID()];
     178    [protectedSourceBuffer->parser() processContentKeyResponseData:keyData.get() forTrackID:protectedSourceBuffer->protectedTrackID()];
    167179    return true;
    168180}
     
    184196}
    185197
     198void CDMSessionMediaSourceAVFObjC::addSourceBuffer(SourceBufferPrivateAVFObjC* sourceBuffer)
     199{
     200    ASSERT(!m_sourceBuffers.contains(sourceBuffer));
     201    ASSERT(sourceBuffer);
     202
     203    m_sourceBuffers.append(sourceBuffer);
     204    sourceBuffer->registerForErrorNotifications(this);
     205
     206    if (m_streamSession)
     207        [m_streamSession addStreamDataParser:sourceBuffer->parser()];
     208}
     209
     210void CDMSessionMediaSourceAVFObjC::removeSourceBuffer(SourceBufferPrivateAVFObjC* sourceBuffer)
     211{
     212    ASSERT(m_sourceBuffers.contains(sourceBuffer));
     213    ASSERT(sourceBuffer);
     214
     215    if (m_streamSession)
     216        [m_streamSession removeStreamDataParser:sourceBuffer->parser()];
     217
     218    sourceBuffer->unregisterForErrorNotifications(this);
     219    m_sourceBuffers.remove(m_sourceBuffers.find(sourceBuffer));
     220}
     221
    186222}
    187223
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h

    r172507 r173197  
    4444namespace WebCore {
    4545
     46class CDMSessionMediaSourceAVFObjC;
    4647class PlatformClockCM;
    4748class MediaSourcePrivateAVFObjC;
     
    5354
    5455    static void registerMediaEngine(MediaEngineRegistrar);
     56
     57    // MediaPlayer Factory Methods
     58    static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
     59    static bool isAvailable();
     60    static void getSupportedTypes(HashSet<String>& types);
     61    static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&);
    5562
    5663    void addDisplayLayer(AVSampleBufferDisplayLayer*);
     
    7683
    7784#if ENABLE(ENCRYPTED_MEDIA_V2)
    78     virtual std::unique_ptr<CDMSession> createSession(const String&);
     85    virtual void setCDMSession(CDMSession*) override;
    7986    void keyNeeded(Uint8Array*);
    8087#endif
     
    161168    bool shouldBePlaying() const;
    162169    void seekTimerFired(Timer<MediaPlayerPrivateMediaSourceAVFObjC>&);
    163 
    164     // MediaPlayer Factory Methods
    165     static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
    166     static bool isAvailable();
    167     static void getSupportedTypes(HashSet<String>& types);
    168     static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&);
    169     static bool supportsKeySystem(const String& keySystem, const String& mimeType);
    170170
    171171    friend class MediaSourcePrivateAVFObjC;
     
    194194    RetainPtr<id> m_durationObserver;
    195195    Timer<MediaPlayerPrivateMediaSourceAVFObjC> m_seekTimer;
     196    CDMSessionMediaSourceAVFObjC* m_session;
    196197    MediaPlayer::NetworkState m_networkState;
    197198    MediaPlayer::ReadyState m_readyState;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm

    r172507 r173197  
    2929#if ENABLE(MEDIA_SOURCE) && USE(AVFOUNDATION)
    3030
    31 #import "CDMSession.h"
     31#import "CDMSessionMediaSourceAVFObjC.h"
    3232#import "Logging.h"
    3333#import "MediaSourcePrivateAVFObjC.h"
     
    137137    , m_synchronizer(adoptNS([[getAVSampleBufferRenderSynchronizerClass() alloc] init]))
    138138    , m_seekTimer(this, &MediaPlayerPrivateMediaSourceAVFObjC::seekTimerFired)
     139    , m_session(nullptr)
    139140    , m_networkState(MediaPlayer::Empty)
    140141    , m_readyState(MediaPlayer::HaveNothing)
     
    195196{
    196197    if (isAvailable())
    197         registrar(create, getSupportedTypes, supportsType, 0, 0, 0, supportsKeySystem);
     198        registrar(create, getSupportedTypes, supportsType, 0, 0, 0, 0);
    198199}
    199200
     
    234235}
    235236
    236 #if ENABLE(ENCRYPTED_MEDIA_V2)
    237 static bool keySystemIsSupported(const String& keySystem)
    238 {
    239     return equalIgnoringCase(keySystem, "com.apple.fps.2_0");
    240 }
    241 #endif
    242 
    243237MediaPlayer::SupportsType MediaPlayerPrivateMediaSourceAVFObjC::supportsType(const MediaEngineSupportParameters& parameters)
    244238{
    245 #if ENABLE(ENCRYPTED_MEDIA_V2)
    246     if (!parameters.keySystem.isEmpty() && !keySystemIsSupported(parameters.keySystem))
    247             return MediaPlayer::IsNotSupported;
    248 #endif
    249 
    250239    // This engine does not support non-media-source sources.
    251240    if (!parameters.isMediaSource)
     
    262251    NSString *typeString = [NSString stringWithFormat:@"%@; codecs=\"%@\"", (NSString *)parameters.type, (NSString *)parameters.codecs];
    263252    return [getAVURLAssetClass() isPlayableExtendedMIMEType:typeString] ? MediaPlayer::IsSupported : MediaPlayer::MayBeSupported;;
    264 }
    265 
    266 bool MediaPlayerPrivateMediaSourceAVFObjC::supportsKeySystem(const String& keySystem, const String& mimeType)
    267 {
    268 #if ENABLE(ENCRYPTED_MEDIA_V2)
    269     if (!wkQueryDecoderAvailability())
    270         return false;
    271 
    272     if (!keySystem.isEmpty()) {
    273         if (!keySystemIsSupported(keySystem))
    274             return false;
    275 
    276         if (!mimeType.isEmpty() && !mimeTypeCache().contains(mimeType))
    277             return false;
    278 
    279         return true;
    280     }
    281 #else
    282     UNUSED_PARAM(keySystem);
    283     UNUSED_PARAM(mimeType);
    284 #endif
    285     return false;
    286253}
    287254
     
    693660
    694661#if ENABLE(ENCRYPTED_MEDIA_V2)
    695 std::unique_ptr<CDMSession> MediaPlayerPrivateMediaSourceAVFObjC::createSession(const String& keySystem)
    696 {
    697     if (!m_mediaSourcePrivate)
    698         return nullptr;
    699 
    700     return m_mediaSourcePrivate->createSession(keySystem);
     662void MediaPlayerPrivateMediaSourceAVFObjC::setCDMSession(CDMSession* session)
     663{
     664    if (m_session) {
     665        for (auto& sourceBuffer : m_mediaSourcePrivate->sourceBuffers())
     666            m_session->removeSourceBuffer(sourceBuffer.get());
     667        m_session = nullptr;
     668    }
     669
     670    m_session = toCDMSessionMediaSourceAVFObjC(session);
     671
     672    if (m_session) {
     673        for (auto& sourceBuffer : m_mediaSourcePrivate->sourceBuffers())
     674            m_session->addSourceBuffer(sourceBuffer.get());
     675    }
    701676}
    702677
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.h

    r171033 r173197  
    5656
    5757    MediaPlayerPrivateMediaSourceAVFObjC* player() const { return m_player; }
     58    const Vector<RefPtr<SourceBufferPrivateAVFObjC>>& sourceBuffers() const { return m_sourceBuffers; }
    5859    const Vector<SourceBufferPrivateAVFObjC*>& activeSourceBuffers() const { return m_activeSourceBuffers; }
    5960
     
    7677    MediaTime fastSeekTimeForMediaTime(const MediaTime&, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold);
    7778    IntSize naturalSize() const;
    78 
    79 #if ENABLE(ENCRYPTED_MEDIA_V2)
    80     std::unique_ptr<CDMSession> createSession(const String&);
    81 #endif
    8279
    8380private:
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm

    r171033 r173197  
    154154
    155155#if ENABLE(ENCRYPTED_MEDIA_V2)
    156 std::unique_ptr<CDMSession> MediaSourcePrivateAVFObjC::createSession(const String&)
    157 {
    158 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    159     if (m_sourceBuffersNeedingSessions.isEmpty())
    160         return nullptr;
    161     return std::make_unique<CDMSessionMediaSourceAVFObjC>(m_sourceBuffersNeedingSessions.takeFirst());
    162 #endif
    163     return nullptr;
    164 }
    165 #endif
    166 
    167 #if ENABLE(ENCRYPTED_MEDIA_V2)
    168156void MediaSourcePrivateAVFObjC::sourceBufferKeyNeeded(SourceBufferPrivateAVFObjC* buffer, Uint8Array* initData)
    169157{
Note: See TracChangeset for help on using the changeset viewer.