WebKit Bugzilla
Attachment 358495 Details for
Bug 192977
: [GStreamer] Add sharedBuffer utility to GstMappedBuffer, and a testsuite
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-192977-20190107160206.patch (text/plain), 16.64 KB, created by
Charlie Turner
on 2019-01-07 08:02:08 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Charlie Turner
Created:
2019-01-07 08:02:08 PST
Size:
16.64 KB
patch
obsolete
>Subversion Revision: 239670 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 9bfdaa6e8c84d17b31a5a52c924bd70d8e8ef2ca..f56f539fa30c597590b4281f7b63754c7825ae6c 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,26 @@ >+2019-01-07 Charlie Turner <cturner@igalia.com> >+ >+ [GStreamer] Add sharedBuffer utility to GstMappedBuffer, and a testsuite >+ https://bugs.webkit.org/show_bug.cgi?id=192977 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Introduce a sharedBuffer() helper that returns a cached instance >+ of a read-only SharedBuffer over the mapped GstBuffer's. >+ >+ This patch also introduces a new gstreamer port API test >+ directory, and includes some tests for GstMappedBuffer. >+ >+ New tests added in API tests. >+ >+ * platform/graphics/gstreamer/GStreamerCommon.cpp: >+ (WebCore::GstMappedBuffer::~GstMappedBuffer): Move the destructor >+ to an implementation file since it's no longer trivial. >+ (WebCore::GstMappedBuffer::sharedBuffer const): >+ * platform/graphics/gstreamer/GStreamerCommon.h: >+ (WebCore::GstMappedBuffer::GstMappedBuffer): >+ (WebCore::GstMappedBuffer::~GstMappedBuffer): Deleted. >+ > 2019-01-07 Zan Dobersek <zdobersek@igalia.com> > > [WPE] Use Widget bounds for PlatformScreen rectangle information >diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp >index 0ba4739a1de5d42168feed7a05b8682d6057a8b1..d7d772d9e96c29e33b18f9b7a9901641c54a8c26 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp >+++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp >@@ -357,6 +357,29 @@ void connectSimpleBusMessageCallback(GstElement* pipeline) > g_signal_connect(bus.get(), "message", G_CALLBACK(simpleBusMessageCallback), pipeline); > } > >+GstMappedBuffer::~GstMappedBuffer() >+{ >+ if (m_isValid) >+ gst_buffer_unmap(m_buffer, &m_info); >+ >+ m_cachedSharedBuffer = nullptr; >+ m_isValid = false; >+} >+ >+RefPtr<SharedBuffer> GstMappedBuffer::sharedBuffer() const >+{ >+ // SharedBuffer provides a read-only view on what it expects are >+ // immutable data. Do not create one if the buffer has not been >+ // mapped or if the buffer is writable and hence mutable. >+ if (!m_isValid || m_info.flags & GST_MAP_WRITE) >+ return nullptr; >+ >+ if (!m_cachedSharedBuffer) >+ m_cachedSharedBuffer = SharedBuffer::create(data(), size()); >+ >+ return m_cachedSharedBuffer; >+} >+ > } > > #endif // USE(GSTREAMER) >diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h >index 2ef15502a005631ee4d07f7fa32b54f4698cfbc8..517847cef867af4066a5929a5f1dfc9fb5503411 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h >+++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h >@@ -23,6 +23,7 @@ > #include "FloatSize.h" > #include "GRefPtrGStreamer.h" > #include "GUniquePtrGStreamer.h" >+#include "SharedBuffer.h" > #include <gst/gst.h> > #include <gst/video/video-format.h> > #include <gst/video/video-info.h> >@@ -80,15 +81,6 @@ inline GstClockTime toGstClockTime(const MediaTime &mediaTime) > class GstMappedBuffer { > WTF_MAKE_NONCOPYABLE(GstMappedBuffer); > public: >- >- GstMappedBuffer(GstMappedBuffer&& other) >- : m_buffer(other.m_buffer) >- , m_info(other.m_info) >- , m_isValid(other.m_isValid) >- { >- other.m_isValid = false; >- } >- > GstMappedBuffer(GstBuffer* buffer, GstMapFlags flags) > : m_buffer(buffer) > { >@@ -100,18 +92,20 @@ public: > GstMappedBuffer(GstBuffer* buffer, int flags) > : GstMappedBuffer(buffer, static_cast<GstMapFlags>(flags)) { } > >- ~GstMappedBuffer() >+ ~GstMappedBuffer(); >+ >+ GstMappedBuffer(GstMappedBuffer&& other) >+ : m_buffer(other.m_buffer) >+ , m_info(other.m_info) >+ , m_isValid(other.m_isValid) > { >- if (m_isValid) >- gst_buffer_unmap(m_buffer, &m_info); >- m_isValid = false; >+ other.m_isValid = false; > } > > uint8_t* data() { ASSERT(m_isValid); return static_cast<uint8_t*>(m_info.data); } > const uint8_t* data() const { ASSERT(m_isValid); return static_cast<uint8_t*>(m_info.data); } >- > size_t size() const { ASSERT(m_isValid); return static_cast<size_t>(m_info.size); } >- >+ RefPtr<SharedBuffer> sharedBuffer() const; > explicit operator bool() const { return m_isValid; } > > private: >@@ -119,6 +113,7 @@ private: > friend bool operator==(const GstMappedBuffer&, const GstBuffer*); > friend bool operator==(const GstBuffer* a, const GstMappedBuffer& b) { return operator==(b, a); } > >+ mutable RefPtr<SharedBuffer> m_cachedSharedBuffer; > GstBuffer* m_buffer { nullptr }; > GstMapInfo m_info; > bool m_isValid { false }; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 3e68f076c1e3ffc6d8e97632187f9ba97e3a8df2..3609d80376a832d4689ce3c092ea9df5f20a15ef 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,19 @@ >+2019-01-07 Charlie Turner <cturner@igalia.com> >+ >+ [GStreamer] Add sharedBuffer utility to GstMappedBuffer, and a testsuite >+ https://bugs.webkit.org/show_bug.cgi?id=192977 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/PlatformGTK.cmake: >+ * TestWebKitAPI/PlatformWPE.cmake: >+ * TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp: Added. >+ (TestWebKitAPI::GStreamerTest::SetUp): >+ (TestWebKitAPI::GStreamerTest::TearDown): >+ * TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.h: Added. >+ * TestWebKitAPI/Tests/WebCore/gstreamer/GstMappedBuffer.cpp: Added. >+ (TestWebKitAPI::TEST_F): >+ > 2019-01-06 Fujii Hironori <Hironori.Fujii@sony.com> > > [Win][Clang] Fix compilation warnings of MiniBrowser >diff --git a/Tools/TestWebKitAPI/PlatformGTK.cmake b/Tools/TestWebKitAPI/PlatformGTK.cmake >index 84499de398b25d25ac0c93602aaad1d690d3de8a..c34fae07cf3c6b0a39c399fee32cd25c3a0aa7f4 100644 >--- a/Tools/TestWebKitAPI/PlatformGTK.cmake >+++ b/Tools/TestWebKitAPI/PlatformGTK.cmake >@@ -25,6 +25,7 @@ include_directories( > include_directories(SYSTEM > ${GDK3_INCLUDE_DIRS} > ${GLIB_INCLUDE_DIRS} >+ ${GSTREAMER_INCLUDE_DIRS} > ${GTK3_INCLUDE_DIRS} > ${LIBSOUP_INCLUDE_DIRS} > ) >@@ -93,6 +94,8 @@ add_executable(TestWebCore > ${TESTWEBKITAPI_DIR}/Tests/WebCore/DNS.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileMonitor.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileSystem.cpp >+ ${TESTWEBKITAPI_DIR}/Tests/WebCore/gstreamer/GstMappedBuffer.cpp >+ ${TESTWEBKITAPI_DIR}/Tests/WebCore/gstreamer/GStreamerTest.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/GridPosition.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/HTMLParserIdioms.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp >diff --git a/Tools/TestWebKitAPI/PlatformWPE.cmake b/Tools/TestWebKitAPI/PlatformWPE.cmake >index fb1b6b52a3563880a52f685588c2e1fbbeabd9e1..b6877598d877de6c8da86b4eb57cc86ff0a2f7ef 100644 >--- a/Tools/TestWebKitAPI/PlatformWPE.cmake >+++ b/Tools/TestWebKitAPI/PlatformWPE.cmake >@@ -23,6 +23,7 @@ include_directories( > include_directories(SYSTEM > ${CAIRO_INCLUDE_DIRS} > ${GLIB_INCLUDE_DIRS} >+ ${GSTREAMER_INCLUDE_DIRS} > ${LIBSOUP_INCLUDE_DIRS} > ${WPE_INCLUDE_DIRS} > ${WPEBACKEND_FDO_INCLUDE_DIRS} >@@ -60,6 +61,8 @@ add_executable(TestWebCore > ${TESTWEBKITAPI_DIR}/TestsController.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileMonitor.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileSystem.cpp >+ ${TESTWEBKITAPI_DIR}/Tests/WebCore/gstreamer/GstMappedBuffer.cpp >+ ${TESTWEBKITAPI_DIR}/Tests/WebCore/gstreamer/GStreamerTest.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/HTMLParserIdioms.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp > ${TESTWEBKITAPI_DIR}/Tests/WebCore/MIMETypeRegistry.cpp >diff --git a/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..202bd9274c6dedf912adb5502b13502257947865 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp >@@ -0,0 +1,55 @@ >+/* >+ * Copyright (C) 2018 Igalia, S.L. >+ * Copyright (C) 2018 Metrological Group B.V. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+ >+#if USE(GSTREAMER) >+#include "GStreamerTest.h" >+ >+#include <WebCore/GStreamerCommon.h> >+#include <gst/gst.h> >+ >+using namespace WebCore; >+ >+namespace TestWebKitAPI { >+ >+void GStreamerTest::SetUp() >+{ >+ if (!gst_is_initialized()) >+ gst_init(NULL, NULL); >+} >+ >+void GStreamerTest::TearDown() >+{ >+ // It might be tempting to call gst_deinit() here. However, that >+ // will tear down the whole process from the GStreamer POV, and the >+ // seemingly symmetrical call to gst_init() will fail to >+ // initialize GStreamer correctly. >+} >+ >+} // namespace TestWebKitAPI >+ >+#endif // USE(GSTREAMER) >diff --git a/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.h b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.h >new file mode 100644 >index 0000000000000000000000000000000000000000..6b2cbaee6165c65979147086a7d01b2117bf5d9c >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.h >@@ -0,0 +1,41 @@ >+/* >+ * Copyright (C) 2018 Igalia, S.L. >+ * Copyright (C) 2018 Metrological Group B.V. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if USE(GSTREAMER) >+ >+namespace TestWebKitAPI { >+ >+class GStreamerTest : public testing::Test { >+public: >+ void SetUp() override; >+ void TearDown() override; >+}; >+ >+} // namespace TestWebKitAPI >+ >+#endif // USE(GSTREAMER) >diff --git a/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GstMappedBuffer.cpp b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GstMappedBuffer.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..8a15f71e6decb6936c5f230b0ee4bd1d38cd70d6 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GstMappedBuffer.cpp >@@ -0,0 +1,117 @@ >+/* >+ * Copyright (C) 2018 Igalia, S.L. >+ * Copyright (C) 2018 Metrological Group B.V. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+ >+#if USE(GSTREAMER) >+ >+#include "GStreamerTest.h" >+#include "Test.h" >+#include <WebCore/GStreamerCommon.h> >+ >+using namespace WebCore; >+ >+namespace TestWebKitAPI { >+ >+TEST_F(GStreamerTest, mappedBufferBasics) >+{ >+ GRefPtr<GstBuffer> buf = adoptGRef(gst_buffer_new_allocate(nullptr, 64, nullptr)); >+ >+ GstMappedBuffer mappedBuf(buf.get(), GST_MAP_READ); >+ >+ EXPECT_TRUE(mappedBuf); >+ EXPECT_EQ(mappedBuf.size(), 64); >+ >+ GstMappedBuffer mappedBuf2(buf.get(), GST_MAP_READ); >+ EXPECT_EQ(mappedBuf, mappedBuf2); >+ EXPECT_EQ(buf.get(), mappedBuf); >+ EXPECT_EQ(mappedBuf2, buf.get()); >+ >+ GstMappedBuffer movedBuf = WTFMove(mappedBuf); >+ EXPECT_TRUE(movedBuf); >+ EXPECT_FALSE(mappedBuf); >+ EXPECT_EQ(movedBuf.size(), 64); >+ EXPECT_EQ(movedBuf, mappedBuf2); >+ EXPECT_EQ(buf.get(), movedBuf); >+} >+ >+TEST_F(GStreamerTest, mappedBufferReadSanity) >+{ >+ gpointer memory = g_malloc(16); >+ memset(memory, 'x', 16); >+ GRefPtr<GstBuffer> buf = adoptGRef(gst_buffer_new_wrapped(memory, 16)); >+ GstMappedBuffer mappedBuf(buf.get(), GST_MAP_READ); >+ EXPECT_EQ(mappedBuf.size(), 16); >+ EXPECT_EQ(memcmp(memory, mappedBuf.data(), 16), 0); >+ EXPECT_EQ(memcmp(memory, mappedBuf.sharedBuffer()->data(), 16), 0); >+} >+ >+TEST_F(GStreamerTest, mappedBufferWriteSanity) >+{ >+ gpointer memory = g_malloc(16); >+ memset(memory, 'x', 16); >+ GRefPtr<GstBuffer> buf = adoptGRef(gst_buffer_new_wrapped(memory, 16)); >+ >+ GstMappedBuffer mappedBuf(buf.get(), GST_MAP_WRITE); >+ EXPECT_EQ(mappedBuf.size(), 16); >+ memset(mappedBuf.data(), 'y', mappedBuf.size()); >+ >+ EXPECT_EQ(memcmp(memory, mappedBuf.data(), 16), 0); >+ >+ // We should not share a writable buffer. >+ ASSERT_FALSE(mappedBuf.sharedBuffer()); >+} >+ >+TEST_F(GStreamerTest, mappedBufferCachesSharedBuffers) >+{ >+ GRefPtr<GstBuffer> buf = adoptGRef(gst_buffer_new_allocate(nullptr, 64, nullptr)); >+ >+ GstMappedBuffer mappedBuf(buf.get(), GST_MAP_READ); >+ RefPtr<SharedBuffer> sharedBuf = mappedBuf.sharedBuffer(); >+ EXPECT_EQ(sharedBuf.get(), mappedBuf.sharedBuffer().get()); >+ EXPECT_EQ(sharedBuf.get(), mappedBuf.sharedBuffer().get()); >+} >+ >+TEST_F(GStreamerTest, mappedBufferDoesNotAddExtraRefs) >+{ >+ // It is important not to ref the passed GStreamer buffers, if we >+ // do so, then in the case of writable buffers, they can become >+ // unwritable, even though we are the sole owners. We also don't >+ // want to take ownership of the buffer from the user-code, since >+ // for transformInPlace use-cases, that would break. >+ GRefPtr<GstBuffer> buf = adoptGRef(gst_buffer_new()); >+ >+ ASSERT_EQ(GST_OBJECT_REFCOUNT(buf.get()), 1); >+ >+ GstMappedBuffer mappedIvBuffer(buf.get(), GST_MAP_READWRITE); >+ ASSERT_TRUE(mappedIvBuffer); >+ >+ ASSERT_EQ(GST_OBJECT_REFCOUNT(buf.get()), 1); >+} >+ >+} // namespace TestWebKitAPI >+ >+#endif // USE(GSTREAMER)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192977
:
357935
|
358495
|
358691
|
358770
|
358774
|
358790
|
359026
|
359027