[GStreamer][MSE] SourceBufferPrivateGStreamer refactoring
authoreocanha@igalia.com <eocanha@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Oct 2016 08:40:33 +0000 (08:40 +0000)
committereocanha@igalia.com <eocanha@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Oct 2016 08:40:33 +0000 (08:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162898

Reviewed by Xabier Rodriguez-Calvar.

Moved SourceBufferPrivateGStreamer to an mse directory and added unimplemented features (abort, enqueueing and sample flow control).

* platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp: Removed.
* platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp: Added.
(WebCore::SourceBufferPrivateGStreamer::create):
(WebCore::SourceBufferPrivateGStreamer::SourceBufferPrivateGStreamer):
(WebCore::SourceBufferPrivateGStreamer::~SourceBufferPrivateGStreamer):
(WebCore::SourceBufferPrivateGStreamer::setClient):
(WebCore::SourceBufferPrivateGStreamer::append):
(WebCore::SourceBufferPrivateGStreamer::abort):
(WebCore::SourceBufferPrivateGStreamer::resetParserState):
(WebCore::SourceBufferPrivateGStreamer::removedFromMediaSource):
(WebCore::SourceBufferPrivateGStreamer::readyState):
(WebCore::SourceBufferPrivateGStreamer::setReadyState):
(WebCore::SourceBufferPrivateGStreamer::flushAndEnqueueNonDisplayingSamples):
(WebCore::SourceBufferPrivateGStreamer::enqueueSample):
(WebCore::SourceBufferPrivateGStreamer::isReadyForMoreSamples):
(WebCore::SourceBufferPrivateGStreamer::setReadyForMoreSamples):
(WebCore::SourceBufferPrivateGStreamer::notifyReadyForMoreSamples):
(WebCore::SourceBufferPrivateGStreamer::setActive):
(WebCore::SourceBufferPrivateGStreamer::stopAskingForMoreSamples):
(WebCore::SourceBufferPrivateGStreamer::notifyClientWhenReadyForMoreSamples):
(WebCore::SourceBufferPrivateGStreamer::didReceiveInitializationSegment):
(WebCore::SourceBufferPrivateGStreamer::didReceiveSample):
(WebCore::SourceBufferPrivateGStreamer::didReceiveAllPendingSamples):
* platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h: Renamed from Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp [moved from Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp with 50% similarity]
Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h [moved from Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h with 53% similarity]

index d4d2224..6f54314 100644 (file)
@@ -1,5 +1,39 @@
 2016-10-26  Enrique Ocaña González  <eocanha@igalia.com>
 
+        [GStreamer][MSE] SourceBufferPrivateGStreamer refactoring
+        https://bugs.webkit.org/show_bug.cgi?id=162898
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Moved SourceBufferPrivateGStreamer to an mse directory and added unimplemented features (abort, enqueueing and sample flow control).
+
+        * platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp: Removed.
+        * platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp: Added.
+        (WebCore::SourceBufferPrivateGStreamer::create):
+        (WebCore::SourceBufferPrivateGStreamer::SourceBufferPrivateGStreamer):
+        (WebCore::SourceBufferPrivateGStreamer::~SourceBufferPrivateGStreamer):
+        (WebCore::SourceBufferPrivateGStreamer::setClient):
+        (WebCore::SourceBufferPrivateGStreamer::append):
+        (WebCore::SourceBufferPrivateGStreamer::abort):
+        (WebCore::SourceBufferPrivateGStreamer::resetParserState):
+        (WebCore::SourceBufferPrivateGStreamer::removedFromMediaSource):
+        (WebCore::SourceBufferPrivateGStreamer::readyState):
+        (WebCore::SourceBufferPrivateGStreamer::setReadyState):
+        (WebCore::SourceBufferPrivateGStreamer::flushAndEnqueueNonDisplayingSamples):
+        (WebCore::SourceBufferPrivateGStreamer::enqueueSample):
+        (WebCore::SourceBufferPrivateGStreamer::isReadyForMoreSamples):
+        (WebCore::SourceBufferPrivateGStreamer::setReadyForMoreSamples):
+        (WebCore::SourceBufferPrivateGStreamer::notifyReadyForMoreSamples):
+        (WebCore::SourceBufferPrivateGStreamer::setActive):
+        (WebCore::SourceBufferPrivateGStreamer::stopAskingForMoreSamples):
+        (WebCore::SourceBufferPrivateGStreamer::notifyClientWhenReadyForMoreSamples):
+        (WebCore::SourceBufferPrivateGStreamer::didReceiveInitializationSegment):
+        (WebCore::SourceBufferPrivateGStreamer::didReceiveSample):
+        (WebCore::SourceBufferPrivateGStreamer::didReceiveAllPendingSamples):
+        * platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h: Renamed from Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h.
+
+2016-10-26  Enrique Ocaña González  <eocanha@igalia.com>
+
         [GStreamer][MSE] MediaSourceClientGStreamerMSE
         https://bugs.webkit.org/show_bug.cgi?id=162896
 
@@ -2,6 +2,8 @@
  * Copyright (C) 2013 Google Inc. All rights reserved.
  * Copyright (C) 2013 Orange
  * Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
+ * Copyright (C) 2015, 2016 Metrological Group B.V.
+ * Copyright (C) 2015, 2016 Igalia, S.L
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
 #if ENABLE(MEDIA_SOURCE) && USE(GSTREAMER)
 
 #include "ContentType.h"
+#include "GStreamerUtilities.h"
+#include "MediaPlayerPrivateGStreamerMSE.h"
+#include "MediaSample.h"
+#include "MediaSourceClientGStreamerMSE.h"
+#include "MediaSourceGStreamer.h"
 #include "NotImplemented.h"
+#include "WebKitMediaSourceGStreamer.h"
 
 namespace WebCore {
 
-Ref<SourceBufferPrivateGStreamer> SourceBufferPrivateGStreamer::create(MediaSourceClientGStreamer& client, const ContentType& contentType)
+Ref<SourceBufferPrivateGStreamer> SourceBufferPrivateGStreamer::create(MediaSourceGStreamer* mediaSource, Ref<MediaSourceClientGStreamerMSE> client, const ContentType& contentType)
 {
-    return adoptRef(*new SourceBufferPrivateGStreamer(client, contentType));
+    return adoptRef(*new SourceBufferPrivateGStreamer(mediaSource, client.get(), contentType));
 }
 
-SourceBufferPrivateGStreamer::SourceBufferPrivateGStreamer(MediaSourceClientGStreamer& client, const ContentType& contentType)
-    : m_type(contentType)
-    , m_client(&client)
-    , m_readyState(MediaPlayer::HaveNothing)
-{
-}
-
-SourceBufferPrivateGStreamer::~SourceBufferPrivateGStreamer()
+SourceBufferPrivateGStreamer::SourceBufferPrivateGStreamer(MediaSourceGStreamer* mediaSource, Ref<MediaSourceClientGStreamerMSE> client, const ContentType& contentType)
+    : SourceBufferPrivate()
+    , m_mediaSource(mediaSource)
+    , m_type(contentType)
+    , m_client(client.get())
 {
 }
 
@@ -63,16 +68,20 @@ void SourceBufferPrivateGStreamer::setClient(SourceBufferPrivateClient* client)
 
 void SourceBufferPrivateGStreamer::append(const unsigned char* data, unsigned length)
 {
-    ASSERT(m_client);
-    ASSERT(m_sourceBufferPrivateClient);
+    ASSERT(m_mediaSource);
+
+    if (!m_sourceBufferPrivateClient)
+        return;
 
-    SourceBufferPrivateClient::AppendResult result = m_client->append(this, data, length);
-    m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(this, result);
+    if (m_client->append(this, data, length))
+        return;
+
+    m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(this, SourceBufferPrivateClient::ReadStreamFailed);
 }
 
 void SourceBufferPrivateGStreamer::abort()
 {
-    notImplemented();
+    m_client->abort(this);
 }
 
 void SourceBufferPrivateGStreamer::resetParserState()
@@ -82,40 +91,57 @@ void SourceBufferPrivateGStreamer::resetParserState()
 
 void SourceBufferPrivateGStreamer::removedFromMediaSource()
 {
+    if (m_mediaSource)
+        m_mediaSource->removeSourceBuffer(this);
     m_client->removedFromMediaSource(this);
 }
 
 MediaPlayer::ReadyState SourceBufferPrivateGStreamer::readyState() const
 {
-    return m_readyState;
+    return m_mediaSource->readyState();
 }
 
 void SourceBufferPrivateGStreamer::setReadyState(MediaPlayer::ReadyState state)
 {
-    m_readyState = state;
+    m_mediaSource->setReadyState(state);
 }
 
-// TODO: Implement these
-void SourceBufferPrivateGStreamer::flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>, AtomicString)
+void SourceBufferPrivateGStreamer::flush(AtomicString trackId)
 {
-    notImplemented();
+    m_client->flush(trackId);
 }
 
-void SourceBufferPrivateGStreamer::enqueueSample(PassRefPtr<MediaSample>, AtomicString)
+void SourceBufferPrivateGStreamer::enqueueSample(PassRefPtr<MediaSample> prpSample, AtomicString)
 {
-    notImplemented();
+    m_notifyWhenReadyForMoreSamples = false;
+
+    RefPtr<MediaSample> protectedPrpSample = prpSample;
+    m_client->enqueueSample(protectedPrpSample);
 }
 
 bool SourceBufferPrivateGStreamer::isReadyForMoreSamples(AtomicString)
 {
-    notImplemented();
+    return m_isReadyForMoreSamples;
+}
 
-    return false;
+void SourceBufferPrivateGStreamer::setReadyForMoreSamples(bool isReady)
+{
+    ASSERT(WTF::isMainThread());
+    m_isReadyForMoreSamples = isReady;
 }
 
-void SourceBufferPrivateGStreamer::setActive(bool)
+void SourceBufferPrivateGStreamer::notifyReadyForMoreSamples()
 {
-    notImplemented();
+    ASSERT(WTF::isMainThread());
+    setReadyForMoreSamples(true);
+    if (m_notifyWhenReadyForMoreSamples)
+        m_sourceBufferPrivateClient->sourceBufferPrivateDidBecomeReadyForMoreSamples(this, m_trackId);
+}
+
+void SourceBufferPrivateGStreamer::setActive(bool isActive)
+{
+    if (m_mediaSource)
+        m_mediaSource->sourceBufferPrivateDidChangeActiveState(this, isActive);
 }
 
 void SourceBufferPrivateGStreamer::stopAskingForMoreSamples(AtomicString)
@@ -123,9 +149,30 @@ void SourceBufferPrivateGStreamer::stopAskingForMoreSamples(AtomicString)
     notImplemented();
 }
 
-void SourceBufferPrivateGStreamer::notifyClientWhenReadyForMoreSamples(AtomicString)
+void SourceBufferPrivateGStreamer::notifyClientWhenReadyForMoreSamples(AtomicString trackId)
 {
-    notImplemented();
+    ASSERT(WTF::isMainThread());
+    m_notifyWhenReadyForMoreSamples = true;
+    m_trackId = trackId;
+}
+
+void SourceBufferPrivateGStreamer::didReceiveInitializationSegment(const SourceBufferPrivateClient::InitializationSegment& initializationSegment)
+{
+    if (m_sourceBufferPrivateClient)
+        m_sourceBufferPrivateClient->sourceBufferPrivateDidReceiveInitializationSegment(this, initializationSegment);
+}
+
+void SourceBufferPrivateGStreamer::didReceiveSample(PassRefPtr<MediaSample> prpSample)
+{
+    RefPtr<MediaSample> protectedPrpSample = prpSample;
+    if (m_sourceBufferPrivateClient)
+        m_sourceBufferPrivateClient->sourceBufferPrivateDidReceiveSample(this, *protectedPrpSample);
+}
+
+void SourceBufferPrivateGStreamer::didReceiveAllPendingSamples()
+{
+    if (m_sourceBufferPrivateClient)
+        m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(this, SourceBufferPrivateClient::AppendSucceeded);
 }
 
 }
@@ -2,6 +2,8 @@
  * Copyright (C) 2013 Google Inc. All rights reserved.
  * Copyright (C) 2013 Orange
  * Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
+ * Copyright (C) 2015, 2016 Metrological Group B.V.
+ * Copyright (C) 2015, 2016 Igalia, S.L
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef SourceBufferPrivateGStreamer_h
-#define SourceBufferPrivateGStreamer_h
+#pragma once
 
 #if ENABLE(MEDIA_SOURCE) && USE(GSTREAMER)
 
 #include "ContentType.h"
+#include "MediaPlayerPrivateGStreamerMSE.h"
 #include "SourceBufferPrivate.h"
+#include "SourceBufferPrivateClient.h"
 #include "WebKitMediaSourceGStreamer.h"
 
 namespace WebCore {
 
+class MediaSourceGStreamer;
+
 class SourceBufferPrivateGStreamer final : public SourceBufferPrivate {
+
 public:
-    static Ref<SourceBufferPrivateGStreamer> create(MediaSourceClientGStreamer&, const ContentType&);
-    virtual ~SourceBufferPrivateGStreamer();
+    static Ref<SourceBufferPrivateGStreamer> create(MediaSourceGStreamer*, Ref<MediaSourceClientGStreamerMSE>, const ContentType&);
+    virtual ~SourceBufferPrivateGStreamer() = default;
 
-    virtual void setClient(SourceBufferPrivateClient*);
+    void clearMediaSource() { m_mediaSource = nullptr; }
 
-    virtual void append(const unsigned char* data, unsigned length);
-    virtual void abort();
-    virtual void resetParserState();
-    virtual void removedFromMediaSource();
+    void setClient(SourceBufferPrivateClient*) override;
+    void append(const unsigned char*, unsigned) override;
+    void abort() override;
+    void resetParserState() override;
+    void removedFromMediaSource() override;
+    MediaPlayer::ReadyState readyState() const override;
+    void setReadyState(MediaPlayer::ReadyState) override;
 
-    virtual MediaPlayer::ReadyState readyState() const;
-    virtual void setReadyState(MediaPlayer::ReadyState);
+    void flush(AtomicString) override;
+    void enqueueSample(PassRefPtr<MediaSample>, AtomicString) override;
+    bool isReadyForMoreSamples(AtomicString) override;
+    void setActive(bool) override;
+    void stopAskingForMoreSamples(AtomicString) override;
+    void notifyClientWhenReadyForMoreSamples(AtomicString) override;
 
-    virtual void flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>, AtomicString);
-    virtual void enqueueSample(PassRefPtr<MediaSample>, AtomicString);
-    virtual bool isReadyForMoreSamples(AtomicString);
-    virtual void setActive(bool);
-    virtual void stopAskingForMoreSamples(AtomicString);
-    virtual void notifyClientWhenReadyForMoreSamples(AtomicString);
+    void setReadyForMoreSamples(bool);
+    void notifyReadyForMoreSamples();
+
+    void didReceiveInitializationSegment(const SourceBufferPrivateClient::InitializationSegment&);
+    void didReceiveSample(PassRefPtr<MediaSample>);
+    void didReceiveAllPendingSamples();
 
 private:
-    SourceBufferPrivateGStreamer(MediaSourceClientGStreamer&, const ContentType&);
+    SourceBufferPrivateGStreamer(MediaSourceGStreamer*, Ref<MediaSourceClientGStreamerMSE>, const ContentType&);
+    friend class MediaSourceClientGStreamerMSE;
 
+    MediaSourceGStreamer* m_mediaSource;
     ContentType m_type;
-    RefPtr<MediaSourceClientGStreamer> m_client;
+    Ref<MediaSourceClientGStreamerMSE> m_client;
     SourceBufferPrivateClient* m_sourceBufferPrivateClient;
-    MediaPlayer::ReadyState m_readyState;
+    bool m_isReadyForMoreSamples = true;
+    bool m_notifyWhenReadyForMoreSamples = false;
+    AtomicString m_trackId;
 };
 
 }
 
 #endif
-#endif