[GStreamer] move MediaSample implementation out of mse/
authorphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Jan 2018 10:58:21 +0000 (10:58 +0000)
committerphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Jan 2018 10:58:21 +0000 (10:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179165

Reviewed by Carlos Garcia Campos.

This module isn't specific to MSE and can potentially be reused
elsewhere, for WebRTC for instance. Additionally the
::platformSample() method was implemented and the code was cleaned up.

* platform/GStreamer.cmake:
* platform/MediaSample.h:
* platform/graphics/gstreamer/GStreamerMediaSample.cpp: Renamed from Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaSample.cpp.
(WebCore::GStreamerMediaSample::platformSample):
* platform/graphics/gstreamer/GStreamerMediaSample.h: Renamed from Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaSample.h.
* platform/graphics/gstreamer/mse/PlaybackPipeline.cpp:
(WebCore::PlaybackPipeline::enqueueSample):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/GStreamer.cmake
Source/WebCore/platform/MediaSample.h
Source/WebCore/platform/graphics/gstreamer/MediaSampleGStreamer.cpp [moved from Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaSample.cpp with 71% similarity]
Source/WebCore/platform/graphics/gstreamer/MediaSampleGStreamer.h [moved from Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaSample.h with 72% similarity]
Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp
Source/WebCore/platform/graphics/gstreamer/mse/PlaybackPipeline.cpp

index a7e43af..2e90414 100644 (file)
@@ -1,3 +1,22 @@
+2018-01-03  Philippe Normand  <pnormand@igalia.com>
+
+        [GStreamer] move MediaSample implementation out of mse/
+        https://bugs.webkit.org/show_bug.cgi?id=179165
+
+        Reviewed by Carlos Garcia Campos.
+
+        This module isn't specific to MSE and can potentially be reused
+        elsewhere, for WebRTC for instance. Additionally the
+        ::platformSample() method was implemented and the code was cleaned up.
+
+        * platform/GStreamer.cmake:
+        * platform/MediaSample.h:
+        * platform/graphics/gstreamer/GStreamerMediaSample.cpp: Renamed from Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaSample.cpp.
+        (WebCore::GStreamerMediaSample::platformSample):
+        * platform/graphics/gstreamer/GStreamerMediaSample.h: Renamed from Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaSample.h.
+        * platform/graphics/gstreamer/mse/PlaybackPipeline.cpp:
+        (WebCore::PlaybackPipeline::enqueueSample):
+
 2018-01-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix resource load stats tests on GLib based ports after r226355.
index 7e224d7..8ee8373 100644 (file)
@@ -12,6 +12,7 @@ if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
         platform/graphics/gstreamer/InbandTextTrackPrivateGStreamer.cpp
         platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
         platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp
+        platform/graphics/gstreamer/MediaSampleGStreamer.cpp
         platform/graphics/gstreamer/TextCombinerGStreamer.cpp
         platform/graphics/gstreamer/TextSinkGStreamer.cpp
         platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp
@@ -25,7 +26,6 @@ if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
 
         platform/graphics/gstreamer/mse/AppendPipeline.cpp
         platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp
-        platform/graphics/gstreamer/mse/GStreamerMediaSample.cpp
         platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp
         platform/graphics/gstreamer/mse/MediaSourceClientGStreamerMSE.cpp
         platform/graphics/gstreamer/mse/MediaSourceGStreamer.cpp
index 9f3fcfd..b4ec49c 100644 (file)
@@ -33,6 +33,7 @@
 #include <wtf/text/AtomicString.h>
 
 typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
+typedef struct _GstSample GstSample;
 
 namespace WebCore {
 
@@ -43,10 +44,12 @@ struct PlatformSample {
         None,
         MockSampleBoxType,
         CMSampleBufferType,
+        GStreamerSampleType,
     } type;
     union {
         MockSampleBox* mockSampleBox;
         CMSampleBufferRef cmSampleBuffer;
+        GstSample* gstSample;
     } sample;
 };
 
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2016 Metrological Group B.V.
- * Copyright (C) 2016 Igalia S.L
+ * Copyright (C) 2016, 2017, 2018 Igalia S.L
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  */
 
 #include "config.h"
-#include "GStreamerMediaSample.h"
+#include "MediaSampleGStreamer.h"
 
 #include "GStreamerUtilities.h"
 
-#if ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(MEDIA_SOURCE)
+#if ENABLE(VIDEO) && USE(GSTREAMER)
 
 namespace WebCore {
 
-GStreamerMediaSample::GStreamerMediaSample(GstSample* sample, const FloatSize& presentationSize, const AtomicString& trackId)
-    : MediaSample()
-    , m_pts(MediaTime::zeroTime())
+MediaSampleGStreamer::MediaSampleGStreamer(GRefPtr<GstSample>&& sample, const FloatSize& presentationSize, const AtomicString& trackId)
+    : m_pts(MediaTime::zeroTime())
     , m_dts(MediaTime::zeroTime())
     , m_duration(MediaTime::zeroTime())
     , m_trackId(trackId)
-    , m_size(0)
     , m_presentationSize(presentationSize)
-    , m_flags(MediaSample::IsSync)
 {
-
-    if (!sample)
-        return;
-
-    GstBuffer* buffer = gst_sample_get_buffer(sample);
+    ASSERT(sample);
+    GstBuffer* buffer = gst_sample_get_buffer(sample.get());
     if (!buffer)
         return;
 
@@ -67,9 +61,18 @@ GStreamerMediaSample::GStreamerMediaSample(GstSample* sample, const FloatSize& p
         m_flags = static_cast<MediaSample::SampleFlags>(m_flags | MediaSample::IsNonDisplaying);
 }
 
-Ref<GStreamerMediaSample> GStreamerMediaSample::createFakeSample(GstCaps*, MediaTime pts, MediaTime dts, MediaTime duration, const FloatSize& presentationSize, const AtomicString& trackId)
+MediaSampleGStreamer::MediaSampleGStreamer(const FloatSize& presentationSize, const AtomicString& trackId)
+    : m_pts(MediaTime::zeroTime())
+    , m_dts(MediaTime::zeroTime())
+    , m_duration(MediaTime::zeroTime())
+    , m_trackId(trackId)
+    , m_presentationSize(presentationSize)
+{
+}
+
+Ref<MediaSampleGStreamer> MediaSampleGStreamer::createFakeSample(GstCaps*, MediaTime pts, MediaTime dts, MediaTime duration, const FloatSize& presentationSize, const AtomicString& trackId)
 {
-    GStreamerMediaSample* gstreamerMediaSample = new GStreamerMediaSample(nullptr, presentationSize, trackId);
+    MediaSampleGStreamer* gstreamerMediaSample = new MediaSampleGStreamer(presentationSize, trackId);
     gstreamerMediaSample->m_pts = pts;
     gstreamerMediaSample->m_dts = dts;
     gstreamerMediaSample->m_duration = duration;
@@ -77,7 +80,7 @@ Ref<GStreamerMediaSample> GStreamerMediaSample::createFakeSample(GstCaps*, Media
     return adoptRef(*gstreamerMediaSample);
 }
 
-void GStreamerMediaSample::applyPtsOffset(MediaTime timestampOffset)
+void MediaSampleGStreamer::applyPtsOffset(MediaTime timestampOffset)
 {
     if (m_pts > timestampOffset) {
         m_duration = m_duration + (m_pts - timestampOffset);
@@ -85,20 +88,25 @@ void GStreamerMediaSample::applyPtsOffset(MediaTime timestampOffset)
     }
 }
 
-void GStreamerMediaSample::offsetTimestampsBy(const MediaTime& timestampOffset)
+void MediaSampleGStreamer::offsetTimestampsBy(const MediaTime& timestampOffset)
 {
     if (!timestampOffset)
         return;
     m_pts += timestampOffset;
     m_dts += timestampOffset;
-    GstBuffer* buffer = gst_sample_get_buffer(m_sample.get());
-    if (buffer) {
+    if (auto* buffer = gst_sample_get_buffer(m_sample.get())) {
         GST_BUFFER_PTS(buffer) = toGstClockTime(m_pts);
         GST_BUFFER_DTS(buffer) = toGstClockTime(m_dts);
     }
 }
 
-Ref<MediaSample> GStreamerMediaSample::createNonDisplayingCopy() const
+PlatformSample MediaSampleGStreamer::platformSample()
+{
+    PlatformSample sample = { PlatformSample::GStreamerSampleType, { .gstSample = m_sample.get() } };
+    return sample;
+}
+
+Ref<MediaSample> MediaSampleGStreamer::createNonDisplayingCopy() const
 {
     if (!m_sample)
         return createFakeSample(nullptr, m_pts, m_dts, m_duration, m_presentationSize, m_trackId);
@@ -112,9 +120,9 @@ Ref<MediaSample> GStreamerMediaSample::createNonDisplayingCopy() const
     GstStructure* info = originalInfo ? gst_structure_copy(originalInfo) : nullptr;
     GRefPtr<GstSample> sample = adoptGRef(gst_sample_new(buffer, caps, segment, info));
 
-    return adoptRef(*new GStreamerMediaSample(sample.get(), m_presentationSize, m_trackId));
+    return adoptRef(*new MediaSampleGStreamer(sample.get(), m_presentationSize, m_trackId));
 }
 
 } // namespace WebCore.
 
-#endif // USE(GSTREAMER)
+#endif // ENABLE(VIDEO) && USE(GSTREAMER)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2016 Metrological Group B.V.
- * Copyright (C) 2016 Igalia S.L
+ * Copyright (C) 2016, 2017, 2018 Igalia S.L
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 
 #pragma once
 
-#if ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(MEDIA_SOURCE)
+#if ENABLE(VIDEO) && USE(GSTREAMER)
 
 #include "FloatSize.h"
 #include "GRefPtrGStreamer.h"
 #include "MediaSample.h"
-#include <gst/gst.h>
 #include <wtf/text/AtomicString.h>
 
 namespace WebCore {
 
-class GStreamerMediaSample : public MediaSample {
+class MediaSampleGStreamer final : public MediaSample {
 public:
-    static Ref<GStreamerMediaSample> create(GstSample* sample, const FloatSize& presentationSize, const AtomicString& trackId)
+    static Ref<MediaSampleGStreamer> create(GRefPtr<GstSample>&& sample, const FloatSize& presentationSize, const AtomicString& trackId)
     {
-        return adoptRef(*new GStreamerMediaSample(sample, presentationSize, trackId));
+        return adoptRef(*new MediaSampleGStreamer(WTFMove(sample), presentationSize, trackId));
     }
 
-    static Ref<GStreamerMediaSample> createFakeSample(GstCaps*, MediaTime pts, MediaTime dts, MediaTime duration, const FloatSize& presentationSize, const AtomicString& trackId);
+    static Ref<MediaSampleGStreamer> createFakeSample(GstCaps*, MediaTime pts, MediaTime dts, MediaTime duration, const FloatSize& presentationSize, const AtomicString& trackId);
 
     void applyPtsOffset(MediaTime);
     MediaTime presentationTime() const override { return m_pts; }
@@ -46,7 +45,6 @@ public:
     AtomicString trackID() const override { return m_trackId; }
     void setTrackID(const String& trackId) override { m_trackId = trackId; }
     size_t sizeInBytes() const override { return m_size; }
-    GstSample* sample() const { return m_sample.get(); }
     FloatSize presentationSize() const override { return m_presentationSize; }
     void offsetTimestampsBy(const MediaTime&) override;
     void setTimestamps(const MediaTime&, const MediaTime&) override { }
@@ -54,23 +52,24 @@ public:
     std::pair<RefPtr<MediaSample>, RefPtr<MediaSample>> divide(const MediaTime&) override  { return { nullptr, nullptr }; }
     Ref<MediaSample> createNonDisplayingCopy() const override;
     SampleFlags flags() const override { return m_flags; }
-    PlatformSample platformSample() override  { return PlatformSample(); }
+    PlatformSample platformSample() override;
     void dump(PrintStream&) const override { }
 
 private:
-    GStreamerMediaSample(GstSample*, const FloatSize& presentationSize, const AtomicString& trackId);
-    virtual ~GStreamerMediaSample() = default;
+    MediaSampleGStreamer(GRefPtr<GstSample>&&, const FloatSize& presentationSize, const AtomicString& trackId);
+    MediaSampleGStreamer(const FloatSize& presentationSize, const AtomicString& trackId);
+    virtual ~MediaSampleGStreamer() = default;
 
     MediaTime m_pts;
     MediaTime m_dts;
     MediaTime m_duration;
     AtomicString m_trackId;
-    size_t m_size;
+    size_t m_size { 0 };
     GRefPtr<GstSample> m_sample;
     FloatSize m_presentationSize;
-    MediaSample::SampleFlags m_flags;
+    MediaSample::SampleFlags m_flags { MediaSample::IsSync };
 };
 
 } // namespace WebCore.
 
-#endif // USE(GSTREAMER)
+#endif // ENABLE(VIDEO) && USE(GSTREAMER)
index 74cd28b..cebbf2e 100644 (file)
@@ -27,7 +27,7 @@
 #include "GRefPtrGStreamer.h"
 #include "GStreamerEMEUtilities.h"
 #include "GStreamerMediaDescription.h"
-#include "GStreamerMediaSample.h"
+#include "MediaSampleGStreamer.h"
 #include "InbandTextTrackPrivateGStreamer.h"
 #include "MediaDescription.h"
 #include "SourceBufferPrivateGStreamer.h"
@@ -726,7 +726,7 @@ void AppendPipeline::appsinkNewSample(GstSample* sample)
             return;
         }
 
-        RefPtr<GStreamerMediaSample> mediaSample = WebCore::GStreamerMediaSample::create(sample, m_presentationSize, trackId());
+        RefPtr<MediaSampleGStreamer> mediaSample = WebCore::MediaSampleGStreamer::create(sample, m_presentationSize, trackId());
 
         GST_TRACE("append: trackId=%s PTS=%s DTS=%s DUR=%s presentationSize=%.0fx%.0f",
             mediaSample->trackID().string().utf8().data(),
index 7e60694..53199f6 100644 (file)
@@ -25,7 +25,7 @@
 #if ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(MEDIA_SOURCE)
 
 #include "AudioTrackPrivateGStreamer.h"
-#include "GStreamerMediaSample.h"
+#include "MediaSampleGStreamer.h"
 #include "GStreamerUtilities.h"
 #include "GUniquePtrGStreamer.h"
 #include "MediaSample.h"
@@ -501,11 +501,11 @@ void PlaybackPipeline::enqueueSample(Ref<MediaSample>&& mediaSample)
     // Only modified by the main thread, no need to lock.
     MediaTime lastEnqueuedTime = stream->lastEnqueuedTime;
 
-    GStreamerMediaSample* sample = static_cast<GStreamerMediaSample*>(mediaSample.ptr());
-    if (sample->sample() && gst_sample_get_buffer(sample->sample())) {
-        GRefPtr<GstSample> gstSample = sample->sample();
+    ASSERT(mediaSample->platformSample().type == PlatformSample::GStreamerSampleType);
+    GRefPtr<GstSample> gstSample = mediaSample->platformSample().sample.gstSample;
+    if (gstSample && gst_sample_get_buffer(gstSample.get())) {
         GstBuffer* buffer = gst_sample_get_buffer(gstSample.get());
-        lastEnqueuedTime = sample->presentationTime();
+        lastEnqueuedTime = mediaSample->presentationTime();
 
         GST_BUFFER_FLAG_UNSET(buffer, GST_BUFFER_FLAG_DECODE_ONLY);
         pushSample(GST_APP_SRC(appsrc), gstSample.get());