[MSE] Make MediaSourcePrivate, SourceBufferPrivate classes RefCounted.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2013 15:53:49 +0000 (15:53 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2013 15:53:49 +0000 (15:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123350

Reviewed by Darin Adler.

Make the MediaSourcePrivate and SourceBufferPrivate classes RefCounted so that
they can be referenced both by MediaSource/SourceBuffer, and by the MediaPlayerPrivate
which creates them.

Change OwnPtr -> RefPtr everywhere:
* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::addSourceBuffer):
* Modules/mediasource/MediaSourceBase.cpp:
(WebCore::MediaSourceBase::setPrivateAndOpen):
(WebCore::MediaSourceBase::createSourceBufferPrivate):
* Modules/mediasource/MediaSourceBase.h:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::create):
(WebCore::SourceBuffer::SourceBuffer):
* Modules/mediasource/SourceBuffer.h:
* Modules/mediasource/WebKitMediaSource.cpp:
(WebCore::WebKitMediaSource::addSourceBuffer):
* Modules/mediasource/WebKitSourceBuffer.cpp:
(WebCore::WebKitSourceBuffer::create):
(WebCore::WebKitSourceBuffer::WebKitSourceBuffer):
* Modules/mediasource/WebKitSourceBuffer.h:
* html/HTMLMediaSource.h:
* platform/graphics/MediaSourcePrivate.h:
* platform/graphics/SourceBufferPrivate.h:
(WebCore::SourceBufferPrivate::SourceBufferPrivate):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158270 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasource/MediaSource.cpp
Source/WebCore/Modules/mediasource/MediaSourceBase.cpp
Source/WebCore/Modules/mediasource/MediaSourceBase.h
Source/WebCore/Modules/mediasource/SourceBuffer.cpp
Source/WebCore/Modules/mediasource/SourceBuffer.h
Source/WebCore/Modules/mediasource/WebKitMediaSource.cpp
Source/WebCore/Modules/mediasource/WebKitSourceBuffer.cpp
Source/WebCore/Modules/mediasource/WebKitSourceBuffer.h
Source/WebCore/html/HTMLMediaSource.h
Source/WebCore/platform/graphics/MediaSourcePrivate.h
Source/WebCore/platform/graphics/SourceBufferPrivate.h

index bf4054d..5ea626d 100644 (file)
@@ -1,3 +1,36 @@
+2013-10-30  Jer Noble  <jer.noble@apple.com>
+
+        [MSE] Make MediaSourcePrivate, SourceBufferPrivate classes RefCounted.
+        https://bugs.webkit.org/show_bug.cgi?id=123350
+
+        Reviewed by Darin Adler.
+
+        Make the MediaSourcePrivate and SourceBufferPrivate classes RefCounted so that
+        they can be referenced both by MediaSource/SourceBuffer, and by the MediaPlayerPrivate
+        which creates them.
+
+        Change OwnPtr -> RefPtr everywhere:
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::addSourceBuffer):
+        * Modules/mediasource/MediaSourceBase.cpp:
+        (WebCore::MediaSourceBase::setPrivateAndOpen):
+        (WebCore::MediaSourceBase::createSourceBufferPrivate):
+        * Modules/mediasource/MediaSourceBase.h:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::create):
+        (WebCore::SourceBuffer::SourceBuffer):
+        * Modules/mediasource/SourceBuffer.h:
+        * Modules/mediasource/WebKitMediaSource.cpp:
+        (WebCore::WebKitMediaSource::addSourceBuffer):
+        * Modules/mediasource/WebKitSourceBuffer.cpp:
+        (WebCore::WebKitSourceBuffer::create):
+        (WebCore::WebKitSourceBuffer::WebKitSourceBuffer):
+        * Modules/mediasource/WebKitSourceBuffer.h:
+        * html/HTMLMediaSource.h:
+        * platform/graphics/MediaSourcePrivate.h:
+        * platform/graphics/SourceBufferPrivate.h:
+        (WebCore::SourceBufferPrivate::SourceBufferPrivate):
+
 2013-10-30  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         Remove unused runtime enabled
 2013-10-30  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         Remove unused runtime enabled
index f1b85e8..162406c 100644 (file)
@@ -96,7 +96,7 @@ SourceBuffer* MediaSource::addSourceBuffer(const String& type, ExceptionCode& ec
     // 5. Create a new SourceBuffer object and associated resources.
     ContentType contentType(type);
     Vector<String> codecs = contentType.codecs();
     // 5. Create a new SourceBuffer object and associated resources.
     ContentType contentType(type);
     Vector<String> codecs = contentType.codecs();
-    OwnPtr<SourceBufferPrivate> sourceBufferPrivate = createSourceBufferPrivate(contentType.type(), codecs, ec);
+    RefPtr<SourceBufferPrivate> sourceBufferPrivate = createSourceBufferPrivate(contentType, ec);
 
     if (!sourceBufferPrivate) {
         ASSERT(ec == NOT_SUPPORTED_ERR || ec == QUOTA_EXCEEDED_ERR);
 
     if (!sourceBufferPrivate) {
         ASSERT(ec == NOT_SUPPORTED_ERR || ec == QUOTA_EXCEEDED_ERR);
@@ -105,7 +105,7 @@ SourceBuffer* MediaSource::addSourceBuffer(const String& type, ExceptionCode& ec
         return 0;
     }
 
         return 0;
     }
 
-    RefPtr<SourceBuffer> buffer = SourceBuffer::create(sourceBufferPrivate.release(), this);
+    RefPtr<SourceBuffer> buffer = SourceBuffer::create(sourceBufferPrivate.releaseNonNull(), this);
     // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
     m_sourceBuffers->add(buffer);
     m_activeSourceBuffers->add(buffer);
     // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
     m_sourceBuffers->add(buffer);
     m_activeSourceBuffers->add(buffer);
index f457d18..95baa27 100644 (file)
@@ -75,12 +75,11 @@ const AtomicString& MediaSourceBase::endedKeyword()
     return ended;
 }
 
     return ended;
 }
 
-void MediaSourceBase::setPrivateAndOpen(PassOwnPtr<MediaSourcePrivate> mediaSourcePrivate)
+void MediaSourceBase::setPrivateAndOpen(PassRef<MediaSourcePrivate> mediaSourcePrivate)
 {
 {
-    ASSERT(mediaSourcePrivate);
     ASSERT(!m_private);
     ASSERT(m_attached);
     ASSERT(!m_private);
     ASSERT(m_attached);
-    m_private = mediaSourcePrivate;
+    m_private = std::move(mediaSourcePrivate);
     setReadyState(openKeyword());
 }
 
     setReadyState(openKeyword());
 }
 
@@ -257,12 +256,12 @@ void MediaSourceBase::stop()
     m_private.clear();
 }
 
     m_private.clear();
 }
 
-PassOwnPtr<SourceBufferPrivate> MediaSourceBase::createSourceBufferPrivate(const String& type, const MediaSourcePrivate::CodecsArray& codecs, ExceptionCode& ec)
+RefPtr<SourceBufferPrivate> MediaSourceBase::createSourceBufferPrivate(const ContentType& type, ExceptionCode& ec)
 {
 {
-    OwnPtr<SourceBufferPrivate> sourceBufferPrivate;
-    switch (m_private->addSourceBuffer(type, codecs, &sourceBufferPrivate)) {
+    RefPtr<SourceBufferPrivate> sourceBufferPrivate;
+    switch (m_private->addSourceBuffer(type, sourceBufferPrivate)) {
     case MediaSourcePrivate::Ok: {
     case MediaSourcePrivate::Ok: {
-        return sourceBufferPrivate.release();
+        return sourceBufferPrivate;
     }
     case MediaSourcePrivate::NotSupported:
         // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type
     }
     case MediaSourcePrivate::NotSupported:
         // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type
index b50ab3b..15844ae 100644 (file)
@@ -62,7 +62,7 @@ public:
 
     // HTMLMediaSource
     virtual bool attachToElement() OVERRIDE;
 
     // HTMLMediaSource
     virtual bool attachToElement() OVERRIDE;
-    virtual void setPrivateAndOpen(PassOwnPtr<MediaSourcePrivate>) OVERRIDE;
+    virtual void setPrivateAndOpen(PassRef<MediaSourcePrivate>) OVERRIDE;
     virtual void close() OVERRIDE;
     virtual bool isClosed() const OVERRIDE;
     virtual double duration() const OVERRIDE;
     virtual void close() OVERRIDE;
     virtual bool isClosed() const OVERRIDE;
     virtual double duration() const OVERRIDE;
@@ -97,12 +97,12 @@ protected:
     virtual void onReadyStateChange(const AtomicString& oldState, const AtomicString& newState) = 0;
     virtual Vector<RefPtr<TimeRanges>> activeRanges() const = 0;
 
     virtual void onReadyStateChange(const AtomicString& oldState, const AtomicString& newState) = 0;
     virtual Vector<RefPtr<TimeRanges>> activeRanges() const = 0;
 
-    PassOwnPtr<SourceBufferPrivate> createSourceBufferPrivate(const String& type, const MediaSourcePrivate::CodecsArray&, ExceptionCode&);
+    RefPtr<SourceBufferPrivate> createSourceBufferPrivate(const ContentType&, ExceptionCode&);
     void scheduleEvent(const AtomicString& eventName);
     GenericEventQueue& asyncEventQueue() { return m_asyncEventQueue; }
 
 private:
     void scheduleEvent(const AtomicString& eventName);
     GenericEventQueue& asyncEventQueue() { return m_asyncEventQueue; }
 
 private:
-    OwnPtr<MediaSourcePrivate> m_private;
+    RefPtr<MediaSourcePrivate> m_private;
     AtomicString m_readyState;
     GenericEventQueue m_asyncEventQueue;
     bool m_attached;
     AtomicString m_readyState;
     GenericEventQueue m_asyncEventQueue;
     bool m_attached;
index 3ca872f..63c4638 100644 (file)
 
 namespace WebCore {
 
 
 namespace WebCore {
 
-PassRefPtr<SourceBuffer> SourceBuffer::create(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate, MediaSource* source)
+PassRef<SourceBuffer> SourceBuffer::create(PassRef<SourceBufferPrivate> sourceBufferPrivate, MediaSource* source)
 {
 {
-    RefPtr<SourceBuffer> sourceBuffer(adoptRef(new SourceBuffer(sourceBufferPrivate, source)));
+    RefPtr<SourceBuffer> sourceBuffer(adoptRef(new SourceBuffer(std::move(sourceBufferPrivate), source)));
     sourceBuffer->suspendIfNeeded();
     sourceBuffer->suspendIfNeeded();
-    return sourceBuffer.release();
+    return sourceBuffer.releaseNonNull();
 }
 
 }
 
-SourceBuffer::SourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate, MediaSource* source)
+SourceBuffer::SourceBuffer(PassRef<SourceBufferPrivate> sourceBufferPrivate, MediaSource* source)
     : ActiveDOMObject(source->scriptExecutionContext())
     : ActiveDOMObject(source->scriptExecutionContext())
-    , m_private(sourceBufferPrivate)
+    , m_private(std::move(sourceBufferPrivate))
     , m_source(source)
     , m_asyncEventQueue(*this)
     , m_updating(false)
     , m_source(source)
     , m_asyncEventQueue(*this)
     , m_updating(false)
index 59b0710..3a72584 100644 (file)
@@ -51,7 +51,7 @@ class TimeRanges;
 
 class SourceBuffer FINAL : public RefCounted<SourceBuffer>, public ActiveDOMObject, public EventTargetWithInlineData, public ScriptWrappable {
 public:
 
 class SourceBuffer FINAL : public RefCounted<SourceBuffer>, public ActiveDOMObject, public EventTargetWithInlineData, public ScriptWrappable {
 public:
-    static PassRefPtr<SourceBuffer> create(PassOwnPtr<SourceBufferPrivate>, MediaSource*);
+    static PassRef<SourceBuffer> create(PassRef<SourceBufferPrivate>, MediaSource*);
 
     virtual ~SourceBuffer();
 
 
     virtual ~SourceBuffer();
 
@@ -84,7 +84,7 @@ protected:
     virtual void derefEventTarget() OVERRIDE { deref(); }
 
 private:
     virtual void derefEventTarget() OVERRIDE { deref(); }
 
 private:
-    SourceBuffer(PassOwnPtr<SourceBufferPrivate>, MediaSource*);
+    SourceBuffer(PassRef<SourceBufferPrivate>, MediaSource*);
 
     bool isRemoved() const;
     void scheduleEvent(const AtomicString& eventName);
 
     bool isRemoved() const;
     void scheduleEvent(const AtomicString& eventName);
@@ -92,7 +92,7 @@ private:
     void appendBufferInternal(unsigned char*, unsigned, ExceptionCode&);
     void appendBufferTimerFired(Timer<SourceBuffer>*);
 
     void appendBufferInternal(unsigned char*, unsigned, ExceptionCode&);
     void appendBufferTimerFired(Timer<SourceBuffer>*);
 
-    OwnPtr<SourceBufferPrivate> m_private;
+    RefPtr<SourceBufferPrivate> m_private;
     MediaSource* m_source;
     GenericEventQueue m_asyncEventQueue;
 
     MediaSource* m_source;
     GenericEventQueue m_asyncEventQueue;
 
index 8f61bf3..8eb4c90 100644 (file)
@@ -47,7 +47,7 @@ PassRefPtr<WebKitMediaSource> WebKitMediaSource::create(ScriptExecutionContext*
 {
     RefPtr<WebKitMediaSource> mediaSource(adoptRef(new WebKitMediaSource(context)));
     mediaSource->suspendIfNeeded();
 {
     RefPtr<WebKitMediaSource> mediaSource(adoptRef(new WebKitMediaSource(context)));
     mediaSource->suspendIfNeeded();
-    return mediaSource.release();
+    return mediaSource.releaseNonNull();
 }
 
 WebKitMediaSource::WebKitMediaSource(ScriptExecutionContext* context)
 }
 
 WebKitMediaSource::WebKitMediaSource(ScriptExecutionContext* context)
@@ -96,11 +96,11 @@ WebKitSourceBuffer* WebKitMediaSource::addSourceBuffer(const String& type, Excep
     // 5. Create a new SourceBuffer object and associated resources.
     ContentType contentType(type);
     Vector<String> codecs = contentType.codecs();
     // 5. Create a new SourceBuffer object and associated resources.
     ContentType contentType(type);
     Vector<String> codecs = contentType.codecs();
-    OwnPtr<SourceBufferPrivate> sourceBufferPrivate = createSourceBufferPrivate(contentType.type(), codecs, ec);
+    RefPtr<SourceBufferPrivate> sourceBufferPrivate = createSourceBufferPrivate(contentType, ec);
     if (!sourceBufferPrivate)
         return 0;
 
     if (!sourceBufferPrivate)
         return 0;
 
-    RefPtr<WebKitSourceBuffer> buffer = WebKitSourceBuffer::create(sourceBufferPrivate.release(), this);
+    RefPtr<WebKitSourceBuffer> buffer = WebKitSourceBuffer::create(sourceBufferPrivate.releaseNonNull(), *this);
     // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
     m_sourceBuffers->add(buffer);
     m_activeSourceBuffers->add(buffer);
     // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
     m_sourceBuffers->add(buffer);
     m_activeSourceBuffers->add(buffer);
index 0970847..16a8535 100644 (file)
 
 namespace WebCore {
 
 
 namespace WebCore {
 
-PassRefPtr<WebKitSourceBuffer> WebKitSourceBuffer::create(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate, PassRefPtr<WebKitMediaSource> source)
+PassRef<WebKitSourceBuffer> WebKitSourceBuffer::create(PassRef<SourceBufferPrivate> sourceBufferPrivate, PassRef<WebKitMediaSource> source)
 {
 {
-    return adoptRef(new WebKitSourceBuffer(sourceBufferPrivate, source));
+    return adoptRef(*new WebKitSourceBuffer(std::move(sourceBufferPrivate), std::move(source)));
 }
 
 }
 
-WebKitSourceBuffer::WebKitSourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate, PassRefPtr<WebKitMediaSource> source)
-    : m_private(sourceBufferPrivate)
-    , m_source(source)
+WebKitSourceBuffer::WebKitSourceBuffer(PassRef<SourceBufferPrivate> sourceBufferPrivate, PassRef<WebKitMediaSource> source)
+    : m_private(std::move(sourceBufferPrivate))
+    , m_source(std::move(source))
     , m_timestampOffset(0)
 {
     ASSERT(m_private);
     , m_timestampOffset(0)
 {
     ASSERT(m_private);
index fc8455a..22e4515 100644 (file)
@@ -47,7 +47,7 @@ class WebKitMediaSource;
 
 class WebKitSourceBuffer : public RefCounted<WebKitSourceBuffer>, public ScriptWrappable {
 public:
 
 class WebKitSourceBuffer : public RefCounted<WebKitSourceBuffer>, public ScriptWrappable {
 public:
-    static PassRefPtr<WebKitSourceBuffer> create(PassOwnPtr<SourceBufferPrivate>, PassRefPtr<WebKitMediaSource>);
+    static PassRef<WebKitSourceBuffer> create(PassRef<SourceBufferPrivate>, PassRef<WebKitMediaSource>);
 
     virtual ~WebKitSourceBuffer();
 
 
     virtual ~WebKitSourceBuffer();
 
@@ -61,11 +61,11 @@ public:
     void removedFromMediaSource();
 
 private:
     void removedFromMediaSource();
 
 private:
-    WebKitSourceBuffer(PassOwnPtr<SourceBufferPrivate>, PassRefPtr<WebKitMediaSource>);
+    WebKitSourceBuffer(PassRef<SourceBufferPrivate>, PassRef<WebKitMediaSource>);
 
     bool isRemoved() const;
 
 
     bool isRemoved() const;
 
-    OwnPtr<SourceBufferPrivate> m_private;
+    RefPtr<SourceBufferPrivate> m_private;
     RefPtr<WebKitMediaSource> m_source;
 
     double m_timestampOffset;
     RefPtr<WebKitMediaSource> m_source;
 
     double m_timestampOffset;
index 9523bf5..198fdfe 100644 (file)
@@ -53,7 +53,7 @@ public:
     // 'closed' state, and returns true to indicate attachment success.
     // Reattachment allowed by first calling close() (even if already in 'closed').
     virtual bool attachToElement() = 0;
     // 'closed' state, and returns true to indicate attachment success.
     // Reattachment allowed by first calling close() (even if already in 'closed').
     virtual bool attachToElement() = 0;
-    virtual void setPrivateAndOpen(PassOwnPtr<MediaSourcePrivate>) = 0;
+    virtual void setPrivateAndOpen(PassRef<MediaSourcePrivate>) = 0;
     virtual void close() = 0;
     virtual bool isClosed() const = 0;
     virtual double duration() const = 0;
     virtual void close() = 0;
     virtual bool isClosed() const = 0;
     virtual double duration() const = 0;
index 2dfd58a..eed776f 100644 (file)
 #if ENABLE(MEDIA_SOURCE)
 
 #include <wtf/Forward.h>
 #if ENABLE(MEDIA_SOURCE)
 
 #include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
 
 namespace WebCore {
 
+class ContentType;
 class SourceBufferPrivate;
 
 class SourceBufferPrivate;
 
-class MediaSourcePrivate {
+class MediaSourcePrivate : public RefCounted<MediaSourcePrivate> {
 public:
 public:
-    typedef Vector<String, 0> CodecsArray;
+    typedef Vector<String> CodecsArray;
 
     MediaSourcePrivate() { }
     virtual ~MediaSourcePrivate() { }
 
     enum AddStatus { Ok, NotSupported, ReachedIdLimit };
 
     MediaSourcePrivate() { }
     virtual ~MediaSourcePrivate() { }
 
     enum AddStatus { Ok, NotSupported, ReachedIdLimit };
-    virtual AddStatus addSourceBuffer(const String& type, const CodecsArray&, OwnPtr<SourceBufferPrivate>*) = 0;
+    virtual AddStatus addSourceBuffer(const ContentType&, RefPtr<SourceBufferPrivate>&) = 0;
     virtual double duration() = 0;
     virtual void setDuration(double) = 0;
     enum EndOfStreamStatus { EosNoError, EosNetworkError, EosDecodeError };
     virtual double duration() = 0;
     virtual void setDuration(double) = 0;
     enum EndOfStreamStatus { EosNoError, EosNetworkError, EosDecodeError };
index 009badf..a035fdc 100644 (file)
 #if ENABLE(MEDIA_SOURCE)
 
 #include "TimeRanges.h"
 #if ENABLE(MEDIA_SOURCE)
 
 #include "TimeRanges.h"
+#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
 
 namespace WebCore {
 
-class SourceBufferPrivate {
+class SourceBufferPrivate : public RefCounted<SourceBufferPrivate> {
 public:
 public:
-    SourceBufferPrivate() { }
     virtual ~SourceBufferPrivate() { }
 
     virtual PassRefPtr<TimeRanges> buffered() = 0;
     virtual ~SourceBufferPrivate() { }
 
     virtual PassRefPtr<TimeRanges> buffered() = 0;