Title: [237036] trunk/Source/WebCore
Revision
237036
Author
[email protected]
Date
2018-10-11 10:29:30 -0700 (Thu, 11 Oct 2018)

Log Message

[GStreamer] Fix race condition in GStreamerVideoDecoder
https://bugs.webkit.org/show_bug.cgi?id=190470

The GStreamerVideoDecoder.m_dtsPtsMap filed is accessed from
the main thread and some GStreamer streaming thread, make sure
to protect its access.

And use WTF::StdMap instead of std::map.

Patch by Thibault Saunier <[email protected]> on 2018-10-11
Reviewed by Philippe Normand.

Manually tested and a random crash is gone.

* platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:
(WebCore::GStreamerVideoDecoder::newSampleCallback):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (237035 => 237036)


--- trunk/Source/WebCore/ChangeLog	2018-10-11 17:25:18 UTC (rev 237035)
+++ trunk/Source/WebCore/ChangeLog	2018-10-11 17:29:30 UTC (rev 237036)
@@ -1,3 +1,21 @@
+2018-10-11  Thibault Saunier  <[email protected]>
+
+        [GStreamer] Fix race condition in GStreamerVideoDecoder
+        https://bugs.webkit.org/show_bug.cgi?id=190470
+
+        The GStreamerVideoDecoder.m_dtsPtsMap filed is accessed from
+        the main thread and some GStreamer streaming thread, make sure
+        to protect its access.
+
+        And use WTF::StdMap instead of std::map.
+
+        Reviewed by Philippe Normand.
+
+        Manually tested and a random crash is gone.
+
+        * platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:
+        (WebCore::GStreamerVideoDecoder::newSampleCallback):
+
 2018-10-11  Enrique Ocaña González  <[email protected]>
 
         [GStreamer][MSE] Fix height calculation for streams with source aspect ratio

Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp (237035 => 237036)


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2018-10-11 17:25:18 UTC (rev 237035)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2018-10-11 17:29:30 UTC (rev 237036)
@@ -34,6 +34,8 @@
 #include <gst/app/gstappsrc.h>
 #include <gst/video/video.h>
 #include <mutex>
+#include <wtf/Lock.h>
+#include <wtf/StdMap.h>
 #include <wtf/glib/RunLoopSourcePriority.h>
 #include <wtf/text/WTFString.h>
 
@@ -163,7 +165,10 @@
             inputImage._size));
         GST_BUFFER_DTS(buffer.get()) = (static_cast<guint64>(inputImage._timeStamp) * GST_MSECOND) - m_firstBufferDts;
         GST_BUFFER_PTS(buffer.get()) = (static_cast<guint64>(renderTimeMs) * GST_MSECOND) - m_firstBufferPts;
-        m_dtsPtsMap[GST_BUFFER_PTS(buffer.get())] = inputImage._timeStamp;
+        {
+            auto locker = holdLock(m_bufferMapLock);
+            m_dtsPtsMap[GST_BUFFER_PTS(buffer.get())] = inputImage._timeStamp;
+        }
 
         GST_LOG_OBJECT(pipeline(), "%ld Decoding: %" GST_PTR_FORMAT, renderTimeMs, buffer.get());
         auto sample = adoptGRef(gst_sample_new(buffer.get(), GetCapsForFrame(inputImage), nullptr, nullptr));
@@ -223,10 +228,13 @@
         auto sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
         auto buffer = gst_sample_get_buffer(sample);
 
-        // Make sure that the frame.timestamp == previsouly input_frame._timeStamp
-        // as it is required by the VideoDecoder baseclass.
-        GST_BUFFER_DTS(buffer) = m_dtsPtsMap[GST_BUFFER_PTS(buffer)];
-        m_dtsPtsMap.erase(GST_BUFFER_PTS(buffer));
+        {
+            auto locker = holdLock(m_bufferMapLock);
+            // Make sure that the frame.timestamp == previsouly input_frame._timeStamp
+            // as it is required by the VideoDecoder baseclass.
+            GST_BUFFER_DTS(buffer) = m_dtsPtsMap[GST_BUFFER_PTS(buffer)];
+            m_dtsPtsMap.erase(GST_BUFFER_PTS(buffer));
+        }
         auto frame(LibWebRTCVideoFrameFromGStreamerSample(sample, webrtc::kVideoRotation_0));
         GST_BUFFER_DTS(buffer) = GST_CLOCK_TIME_NONE;
         GST_LOG_OBJECT(pipeline(), "Output decoded frame! %d -> %" GST_PTR_FORMAT,
@@ -258,7 +266,8 @@
     GstVideoInfo m_info;
     webrtc::DecodedImageCallback* m_imageReadyCb;
 
-    std::map<GstClockTime, GstClockTime> m_dtsPtsMap;
+    Lock m_bufferMapLock;
+    StdMap<GstClockTime, GstClockTime> m_dtsPtsMap;
     GstClockTime m_firstBufferPts;
     GstClockTime m_firstBufferDts;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to