Title: [236466] trunk/Source/WebCore
Revision
236466
Author
[email protected]
Date
2018-09-25 11:41:07 -0700 (Tue, 25 Sep 2018)

Log Message

[WPE][GTK][WebRTC] Fixup VP8 encoding support
https://bugs.webkit.org/show_bug.cgi?id=189921

Previous leak fixing commit introduced a regression in
the way the encoded buffer were prepared in the default
GStreamerVideoEncoder::Fragmentize implementation (when
encoding with VP8 basically).

+ Fix a build warning in the decoder.
+ Fix some wrong object members namings.
+ Properly move the caps reference when setting restriction caps.
+ Do not raise a GStreamer error when GStreamerVideoEncoder::OnEncodedImage
  fails - this might be a network issue and other encoders do not consider that
  fatal.
+ Use GstMappedBuffer where appropriate.

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

* platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:
* platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp:
(WebCore::GStreamerVideoEncoder::InitEncode):
(WebCore::GStreamerVideoEncoder::newSampleCallback):
(WebCore::GStreamerVideoEncoder::Fragmentize):
(WebCore::GStreamerVideoEncoder::SetRestrictionCaps):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (236465 => 236466)


--- trunk/Source/WebCore/ChangeLog	2018-09-25 18:37:29 UTC (rev 236465)
+++ trunk/Source/WebCore/ChangeLog	2018-09-25 18:41:07 UTC (rev 236466)
@@ -1,3 +1,30 @@
+2018-09-25  Thibault Saunier  <[email protected]>
+
+        [WPE][GTK][WebRTC] Fixup VP8 encoding support
+        https://bugs.webkit.org/show_bug.cgi?id=189921
+
+        Previous leak fixing commit introduced a regression in
+        the way the encoded buffer were prepared in the default
+        GStreamerVideoEncoder::Fragmentize implementation (when
+        encoding with VP8 basically).
+
+        + Fix a build warning in the decoder.
+        + Fix some wrong object members namings.
+        + Properly move the caps reference when setting restriction caps.
+        + Do not raise a GStreamer error when GStreamerVideoEncoder::OnEncodedImage
+          fails - this might be a network issue and other encoders do not consider that
+          fatal.
+        + Use GstMappedBuffer where appropriate.
+
+        Reviewed by Philippe Normand.
+
+        * platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:
+        * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp:
+        (WebCore::GStreamerVideoEncoder::InitEncode):
+        (WebCore::GStreamerVideoEncoder::newSampleCallback):
+        (WebCore::GStreamerVideoEncoder::Fragmentize):
+        (WebCore::GStreamerVideoEncoder::SetRestrictionCaps):
+
 2018-09-25  Eric Carlson  <[email protected]>
 
         [MediaStream] Update constraints supported by getDisplayMedia

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


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2018-09-25 18:37:29 UTC (rev 236465)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2018-09-25 18:41:07 UTC (rev 236466)
@@ -165,7 +165,7 @@
         GST_BUFFER_PTS(buffer.get()) = (static_cast<guint64>(renderTimeMs) * GST_MSECOND) - m_firstBufferPts;
         m_dtsPtsMap[GST_BUFFER_PTS(buffer.get())] = inputImage._timeStamp;
 
-        GST_LOG_OBJECT(pipeline(), "%ld Decoding: %" GST_PTR_FORMAT, renderTimeMs, buffer);
+        GST_LOG_OBJECT(pipeline(), "%ld Decoding: %" GST_PTR_FORMAT, renderTimeMs, buffer.get());
         auto sample = adoptGRef(gst_sample_new(buffer.get(), GetCapsForFrame(inputImage), nullptr, nullptr));
         switch (gst_app_src_push_sample(GST_APP_SRC(m_src), sample.get())) {
         case GST_FLOW_OK:

Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp (236465 => 236466)


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp	2018-09-25 18:37:29 UTC (rev 236465)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp	2018-09-25 18:41:07 UTC (rev 236466)
@@ -81,7 +81,7 @@
         auto caps = adoptGRef(gst_caps_copy(m_restrictionCaps.get()));
         gst_caps_set_simple(caps.get(), "framerate", GST_TYPE_FRACTION, frameRate, 1, nullptr);
 
-        SetRestrictionCaps(caps);
+        SetRestrictionCaps(WTFMove(caps));
 
         if (m_bitrateSetter && m_encoder)
             m_bitrateSetter(m_encoder, newBitrate);
@@ -109,7 +109,7 @@
 
         m_encodedFrame._size = codecSettings->width * codecSettings->height * 3;
         m_encodedFrame._buffer = new uint8_t[m_encodedFrame._size];
-        encoded_image_buffer_.reset(m_encodedFrame._buffer);
+        m_encodedImageBuffer.reset(m_encodedFrame._buffer);
         m_encodedFrame._completeFrame = true;
         m_encodedFrame._encodedWidth = 0;
         m_encodedFrame._encodedHeight = 0;
@@ -159,7 +159,7 @@
     int32_t Release() final
     {
         m_encodedFrame._buffer = nullptr;
-        encoded_image_buffer_.reset();
+        m_encodedImageBuffer.reset();
         GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
         gst_bus_set_sync_handler(bus.get(), nullptr, nullptr, nullptr);
 
@@ -230,7 +230,7 @@
         auto caps = gst_sample_get_caps(sample.get());
 
         webrtc::RTPFragmentationHeader fragmentationInfo;
-        Fragmentize(&m_encodedFrame, &encoded_image_buffer_, buffer, &fragmentationInfo);
+        Fragmentize(&m_encodedFrame, &m_encodedImageBuffer, &m_encodedImageBufferSize, buffer, &fragmentationInfo);
         if (!m_encodedFrame._size)
             return GST_FLOW_OK;
 
@@ -249,13 +249,9 @@
         PopulateCodecSpecific(&codecSpecifiInfos, buffer);
 
         webrtc::EncodedImageCallback::Result result = m_imageReadyCb->OnEncodedImage(m_encodedFrame, &codecSpecifiInfos, &fragmentationInfo);
-        if (result.error != webrtc::EncodedImageCallback::Result::OK) {
-            GST_ELEMENT_ERROR(m_pipeline.get(), LIBRARY, FAILED, (nullptr),
-                ("Encode callback failed: %d", result.error));
+        if (result.error != webrtc::EncodedImageCallback::Result::OK)
+            GST_ERROR_OBJECT(m_pipeline.get(), "Encode callback failed: %d", result.error);
 
-            return GST_FLOW_ERROR;
-        }
-
         return GST_FLOW_OK;
     }
 
@@ -359,23 +355,25 @@
 
     virtual void PopulateCodecSpecific(webrtc::CodecSpecificInfo*, GstBuffer*) = 0;
 
-    virtual void Fragmentize(webrtc::EncodedImage* encodedImage, std::unique_ptr<uint8_t[]>* encoded_image_buffer, GstBuffer* buffer,
-        webrtc::RTPFragmentationHeader* fragmentationInfo)
+    virtual void Fragmentize(webrtc::EncodedImage* encodedImage, std::unique_ptr<uint8_t[]>* encodedImageBuffer,
+        size_t* bufferSize, GstBuffer* buffer, webrtc::RTPFragmentationHeader* fragmentationInfo)
     {
-        GstMapInfo map;
+        GstMappedBuffer map(buffer, GST_MAP_READ);
 
-        gst_buffer_map(buffer, &map, GST_MAP_READ);
-        if (encodedImage->_size < map.size) {
-            encodedImage->_size = map.size;
+        if (*bufferSize < map.size()) {
+            encodedImage->_size = map.size();
             encodedImage->_buffer = new uint8_t[encodedImage->_size];
-            encoded_image_buffer->reset(encodedImage->_buffer);
-            memcpy(encodedImage->_buffer, map.data, map.size);
+            encodedImageBuffer->reset(encodedImage->_buffer);
+            *bufferSize = map.size();
         }
-        gst_buffer_unmap(buffer, &map);
 
+        memcpy(encodedImage->_buffer, map.data(), map.size());
+        encodedImage->_length = map.size();
+        encodedImage->_size = map.size();
+
         fragmentationInfo->VerifyAndAllocateFragmentationHeader(1);
         fragmentationInfo->fragmentationOffset[0] = 0;
-        fragmentationInfo->fragmentationLength[0] = gst_buffer_get_size(buffer);
+        fragmentationInfo->fragmentationLength[0] = map.size();
         fragmentationInfo->fragmentationPlType[0] = 0;
         fragmentationInfo->fragmentationTimeDiff[0] = 0;
     }
@@ -392,7 +390,7 @@
     void SetRestrictionCaps(GRefPtr<GstCaps> caps)
     {
         if (caps && m_profile.get() && gst_caps_is_equal(m_restrictionCaps.get(), caps.get()))
-            g_object_set(m_profile.get(), "restriction-caps", caps, nullptr);
+            g_object_set(m_profile.get(), "restriction-caps", caps.get(), nullptr);
 
         m_restrictionCaps = caps;
     }
@@ -413,7 +411,8 @@
     GRefPtr<GstEncodingProfile> m_profile;
     BitrateSetter m_bitrateSetter;
     webrtc::EncodedImage m_encodedFrame;
-    std::unique_ptr<uint8_t[]> encoded_image_buffer_;
+    std::unique_ptr<uint8_t[]> m_encodedImageBuffer;
+    size_t m_encodedImageBufferSize;
 };
 
 class H264Encoder : public GStreamerVideoEncoder {
@@ -431,10 +430,9 @@
     }
 
     // FIXME - MT. safety!
-    void Fragmentize(webrtc::EncodedImage* encodedImage, std::unique_ptr<uint8_t[]>* encoded_image_buffer,
+    void Fragmentize(webrtc::EncodedImage* encodedImage, std::unique_ptr<uint8_t[]>* encodedImageBuffer, size_t *bufferSize,
         GstBuffer* gstbuffer, webrtc::RTPFragmentationHeader* fragmentationHeader) final
     {
-        GstMapInfo map;
         GstH264NalUnit nalu;
         auto parserResult = GST_H264_PARSER_OK;
 
@@ -444,9 +442,9 @@
         std::vector<GstH264NalUnit> nals;
 
         const uint8_t startCode[4] = { 0, 0, 0, 1 };
-        gst_buffer_map(gstbuffer, &map, GST_MAP_READ);
+        GstMappedBuffer map(gstbuffer, GST_MAP_READ);
         while (parserResult == GST_H264_PARSER_OK) {
-            parserResult = gst_h264_parser_identify_nalu(m_parser, map.data, offset, map.size, &nalu);
+            parserResult = gst_h264_parser_identify_nalu(m_parser, map.data(), offset, map.size(), &nalu);
 
             nalu.sc_offset = offset;
             nalu.offset = offset + sizeof(startCode);
@@ -461,7 +459,8 @@
         if (encodedImage->_size < requiredSize) {
             encodedImage->_size = requiredSize;
             encodedImage->_buffer = new uint8_t[encodedImage->_size];
-            encoded_image_buffer->reset(encodedImage->_buffer);
+            encodedImageBuffer->reset(encodedImage->_buffer);
+            *bufferSize = map.size();
         }
 
         // Iterate nal units and fill the Fragmentation info.
@@ -470,20 +469,18 @@
         encodedImage->_length = 0;
         for (std::vector<GstH264NalUnit>::iterator nal = nals.begin(); nal != nals.end(); ++nal, fragmentIndex++) {
 
-            ASSERT(map.data[nal->sc_offset + 0] == startCode[0]);
-            ASSERT(map.data[nal->sc_offset + 1] == startCode[1]);
-            ASSERT(map.data[nal->sc_offset + 2] == startCode[2]);
-            ASSERT(map.data[nal->sc_offset + 3] == startCode[3]);
+            ASSERT(map.data()[nal->sc_offset + 0] == startCode[0]);
+            ASSERT(map.data()[nal->sc_offset + 1] == startCode[1]);
+            ASSERT(map.data()[nal->sc_offset + 2] == startCode[2]);
+            ASSERT(map.data()[nal->sc_offset + 3] == startCode[3]);
 
             fragmentationHeader->fragmentationOffset[fragmentIndex] = nal->offset;
             fragmentationHeader->fragmentationLength[fragmentIndex] = nal->size;
 
-            memcpy(encodedImage->_buffer + encodedImage->_length, &map.data[nal->sc_offset],
+            memcpy(encodedImage->_buffer + encodedImage->_length, &map.data()[nal->sc_offset],
                 sizeof(startCode) + nal->size);
             encodedImage->_length += nal->size + sizeof(startCode);
         }
-
-        gst_buffer_unmap(gstbuffer, &map);
     }
 
     GstElement* CreateFilter() final
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to