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

Reviewed by Žan Doberšek.

Move MediaSourceGStreamer to the mse directory, manage SourceBufferPrivates and delegate WebKitMediaSrc operations to the MSE private player.

* platform/graphics/gstreamer/mse/MediaSourceGStreamer.cpp: Renamed from Source/WebCore/platform/graphics/gstreamer/MediaSourceGStreamer.cpp.
(WebCore::MediaSourceGStreamer::open):
(WebCore::MediaSourceGStreamer::MediaSourceGStreamer):
(WebCore::MediaSourceGStreamer::~MediaSourceGStreamer):
(WebCore::MediaSourceGStreamer::addSourceBuffer):
(WebCore::MediaSourceGStreamer::removeSourceBuffer):
(WebCore::MediaSourceGStreamer::durationChanged):
(WebCore::MediaSourceGStreamer::markEndOfStream):
(WebCore::MediaSourceGStreamer::unmarkEndOfStream):
(WebCore::MediaSourceGStreamer::readyState):
(WebCore::MediaSourceGStreamer::setReadyState):
(WebCore::MediaSourceGStreamer::waitForSeekCompleted):
(WebCore::MediaSourceGStreamer::seekCompleted):
(WebCore::MediaSourceGStreamer::sourceBufferPrivateDidChangeActiveState):
(WebCore::MediaSourceGStreamer::buffered):
* platform/graphics/gstreamer/mse/MediaSourceGStreamer.h: Renamed from Source/WebCore/platform/graphics/gstreamer/MediaSourceGStreamer.h.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/mse/MediaSourceGStreamer.cpp [moved from Source/WebCore/platform/graphics/gstreamer/MediaSourceGStreamer.cpp with 57% similarity]
Source/WebCore/platform/graphics/gstreamer/mse/MediaSourceGStreamer.h [moved from Source/WebCore/platform/graphics/gstreamer/MediaSourceGStreamer.h with 56% similarity]

index 6f54314..0fd907b 100644 (file)
@@ -1,5 +1,31 @@
 2016-10-26  Enrique Ocaña González  <eocanha@igalia.com>
 
+        [GStreamer][MSE] MediaSourceGStreamer refactoring
+        https://bugs.webkit.org/show_bug.cgi?id=162899
+
+        Reviewed by Žan Doberšek.
+
+        Move MediaSourceGStreamer to the mse directory, manage SourceBufferPrivates and delegate WebKitMediaSrc operations to the MSE private player.
+
+        * platform/graphics/gstreamer/mse/MediaSourceGStreamer.cpp: Renamed from Source/WebCore/platform/graphics/gstreamer/MediaSourceGStreamer.cpp.
+        (WebCore::MediaSourceGStreamer::open):
+        (WebCore::MediaSourceGStreamer::MediaSourceGStreamer):
+        (WebCore::MediaSourceGStreamer::~MediaSourceGStreamer):
+        (WebCore::MediaSourceGStreamer::addSourceBuffer):
+        (WebCore::MediaSourceGStreamer::removeSourceBuffer):
+        (WebCore::MediaSourceGStreamer::durationChanged):
+        (WebCore::MediaSourceGStreamer::markEndOfStream):
+        (WebCore::MediaSourceGStreamer::unmarkEndOfStream):
+        (WebCore::MediaSourceGStreamer::readyState):
+        (WebCore::MediaSourceGStreamer::setReadyState):
+        (WebCore::MediaSourceGStreamer::waitForSeekCompleted):
+        (WebCore::MediaSourceGStreamer::seekCompleted):
+        (WebCore::MediaSourceGStreamer::sourceBufferPrivateDidChangeActiveState):
+        (WebCore::MediaSourceGStreamer::buffered):
+        * platform/graphics/gstreamer/mse/MediaSourceGStreamer.h: Renamed from Source/WebCore/platform/graphics/gstreamer/MediaSourceGStreamer.h.
+
+2016-10-26  Enrique Ocaña González  <eocanha@igalia.com>
+
         [GStreamer][MSE] SourceBufferPrivateGStreamer refactoring
         https://bugs.webkit.org/show_bug.cgi?id=162898
 
@@ -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 "MediaPlayerPrivateGStreamer.h"
+#include "MediaPlayerPrivateGStreamerMSE.h"
+#include "MediaSourceClientGStreamerMSE.h"
 #include "NotImplemented.h"
 #include "SourceBufferPrivateGStreamer.h"
+#include "TimeRanges.h"
 #include "WebKitMediaSourceGStreamer.h"
-
+#include <wtf/PassRefPtr.h>
 #include <wtf/glib/GRefPtr.h>
 
 namespace WebCore {
 
-void MediaSourceGStreamer::open(MediaSourcePrivateClient* mediaSource, WebKitMediaSrc* src)
+void MediaSourceGStreamer::open(MediaSourcePrivateClient& mediaSource, MediaPlayerPrivateGStreamerMSE& playerPrivate)
 {
-    ASSERT(mediaSource);
-    mediaSource->setPrivateAndOpen(adoptRef(*new MediaSourceGStreamer(mediaSource, src)));
+    mediaSource.setPrivateAndOpen(adoptRef(*new MediaSourceGStreamer(mediaSource, playerPrivate)));
 }
 
-MediaSourceGStreamer::MediaSourceGStreamer(MediaSourcePrivateClient* mediaSource, WebKitMediaSrc* src)
-    : m_client(adoptRef(new MediaSourceClientGStreamer(src)))
+MediaSourceGStreamer::MediaSourceGStreamer(MediaSourcePrivateClient& mediaSource, MediaPlayerPrivateGStreamerMSE& playerPrivate)
+    : MediaSourcePrivate()
+    , m_client(MediaSourceClientGStreamerMSE::create(playerPrivate))
     , m_mediaSource(mediaSource)
-    , m_readyState(MediaPlayer::HaveNothing)
+    , m_playerPrivate(playerPrivate)
 {
-    ASSERT(m_client);
 }
 
 MediaSourceGStreamer::~MediaSourceGStreamer()
 {
+    for (auto& sourceBufferPrivate : m_sourceBuffers)
+        sourceBufferPrivate->clearMediaSource();
 }
 
 MediaSourceGStreamer::AddStatus MediaSourceGStreamer::addSourceBuffer(const ContentType& contentType, RefPtr<SourceBufferPrivate>& sourceBufferPrivate)
 {
-    RefPtr<SourceBufferPrivateGStreamer> sourceBufferPrivateGStreamer = SourceBufferPrivateGStreamer::create(*m_client, contentType);
-    sourceBufferPrivate = sourceBufferPrivateGStreamer;
+    sourceBufferPrivate = SourceBufferPrivateGStreamer::create(this, m_client.get(), contentType);
+    RefPtr<SourceBufferPrivateGStreamer> sourceBufferPrivateGStreamer = static_cast<SourceBufferPrivateGStreamer*>(sourceBufferPrivate.get());
+    m_sourceBuffers.add(sourceBufferPrivateGStreamer);
     return m_client->addSourceBuffer(sourceBufferPrivateGStreamer, contentType);
 }
 
+void MediaSourceGStreamer::removeSourceBuffer(SourceBufferPrivate* sourceBufferPrivate)
+{
+    RefPtr<SourceBufferPrivateGStreamer> sourceBufferPrivateGStreamer = static_cast<SourceBufferPrivateGStreamer*>(sourceBufferPrivate);
+    ASSERT(m_sourceBuffers.contains(sourceBufferPrivateGStreamer));
+
+    sourceBufferPrivateGStreamer->clearMediaSource();
+    m_sourceBuffers.remove(sourceBufferPrivateGStreamer);
+    m_activeSourceBuffers.remove(sourceBufferPrivateGStreamer.get());
+}
+
 void MediaSourceGStreamer::durationChanged()
 {
     m_client->durationChanged(m_mediaSource->duration());
@@ -85,22 +104,35 @@ void MediaSourceGStreamer::unmarkEndOfStream()
 
 MediaPlayer::ReadyState MediaSourceGStreamer::readyState() const
 {
-    return m_readyState;
+    return m_playerPrivate.readyState();
 }
 
 void MediaSourceGStreamer::setReadyState(MediaPlayer::ReadyState state)
 {
-    m_readyState = state;
+    m_playerPrivate.setReadyState(state);
 }
 
 void MediaSourceGStreamer::waitForSeekCompleted()
 {
-    notImplemented();
+    m_playerPrivate.waitForSeekCompleted();
 }
 
 void MediaSourceGStreamer::seekCompleted()
 {
-    notImplemented();
+    m_playerPrivate.seekCompleted();
+}
+
+void MediaSourceGStreamer::sourceBufferPrivateDidChangeActiveState(SourceBufferPrivateGStreamer* sourceBufferPrivate, bool isActive)
+{
+    if (!isActive)
+        m_activeSourceBuffers.remove(sourceBufferPrivate);
+    else if (!m_activeSourceBuffers.contains(sourceBufferPrivate))
+        m_activeSourceBuffers.add(sourceBufferPrivate);
+}
+
+std::unique_ptr<PlatformTimeRanges> MediaSourceGStreamer::buffered()
+{
+    return m_mediaSource->buffered();
 }
 
 }
@@ -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 MediaSourceGStreamer_h
-#define MediaSourceGStreamer_h
+#pragma once
 
 #if ENABLE(MEDIA_SOURCE) && USE(GSTREAMER)
-#include "MediaSource.h"
-#include "WebKitMediaSourceGStreamer.h"
+#include "MediaSourcePrivate.h"
+
+#include <wtf/Forward.h>
+#include <wtf/HashSet.h>
+
+typedef struct _WebKitMediaSrc WebKitMediaSrc;
 
 namespace WebCore {
 
+class SourceBufferPrivateGStreamer;
+class MediaSourceClientGStreamerMSE;
+class MediaPlayerPrivateGStreamerMSE;
+class PlatformTimeRanges;
+
 // FIXME: Should this be called MediaSourcePrivateGStreamer?
 class MediaSourceGStreamer final : public MediaSourcePrivate {
 public:
-    static void open(MediaSourcePrivateClient*, WebKitMediaSrc*);
+    static void open(MediaSourcePrivateClient&, MediaPlayerPrivateGStreamerMSE&);
     virtual ~MediaSourceGStreamer();
 
-    virtual AddStatus addSourceBuffer(const ContentType&, RefPtr<SourceBufferPrivate>&);
-    virtual void durationChanged();
-    virtual void markEndOfStream(EndOfStreamStatus);
-    virtual void unmarkEndOfStream();
+    MediaSourceClientGStreamerMSE& client() { return m_client.get(); }
+    AddStatus addSourceBuffer(const ContentType&, RefPtr<SourceBufferPrivate>&) override;
+    void removeSourceBuffer(SourceBufferPrivate*);
+
+    void durationChanged() override;
+    void markEndOfStream(EndOfStreamStatus) override;
+    void unmarkEndOfStream() override;
 
-    virtual MediaPlayer::ReadyState readyState() const;
-    virtual void setReadyState(MediaPlayer::ReadyState);
+    MediaPlayer::ReadyState readyState() const override;
+    void setReadyState(MediaPlayer::ReadyState) override;
 
-    virtual void waitForSeekCompleted();
-    virtual void seekCompleted();
+    void waitForSeekCompleted() override;
+    void seekCompleted() override;
+
+    void sourceBufferPrivateDidChangeActiveState(SourceBufferPrivateGStreamer*, bool);
+
+    std::unique_ptr<PlatformTimeRanges> buffered();
 
 private:
-    MediaSourceGStreamer(MediaSourcePrivateClient*, WebKitMediaSrc*);
+    MediaSourceGStreamer(MediaSourcePrivateClient&, MediaPlayerPrivateGStreamerMSE&);
 
-    RefPtr<MediaSourceClientGStreamer> m_client;
-    MediaSourcePrivateClient* m_mediaSource;
-    MediaPlayer::ReadyState m_readyState;
+    HashSet<RefPtr<SourceBufferPrivateGStreamer>> m_sourceBuffers;
+    HashSet<SourceBufferPrivateGStreamer*> m_activeSourceBuffers;
+    Ref<MediaSourceClientGStreamerMSE> m_client;
+    Ref<MediaSourcePrivateClient> m_mediaSource;
+    MediaPlayerPrivateGStreamerMSE& m_playerPrivate;
 };
 
 }
 
 #endif
-#endif