WebKit Bugzilla
Attachment 357935 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-20181221091454.patch (text/plain), 15.90 KB, created by
Charlie Turner
on 2018-12-21 01:14:55 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Charlie Turner
Created:
2018-12-21 01:14:55 PST
Size:
15.90 KB
patch
obsolete
>Subversion Revision: 239438 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 2ab911fdf7cb3446e56afa8f49fdbccd53859356..a7af74119345f8e6a747487b2e9f788c436f66c2 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,26 @@ >+2018-12-21 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::cachedSharedBuffers): >+ (WebCore::GstMappedBuffer::~GstMappedBuffer): >+ (WebCore::GstMappedBuffer::sharedBuffer const): >+ * platform/graphics/gstreamer/GStreamerCommon.h: >+ (WebCore::GstMappedBuffer::GstMappedBuffer): >+ (WebCore::GstMappedBuffer::data const): >+ > 2018-12-19 Michael Catanzaro <mcatanzaro@igalia.com> > > Unreviewed, fix GTK build after r239410 >diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp >index 1fe8b881e199806b122da56f70f80c35eaacd62a..841e8d21a54cb5c48fa17d2985f1a3adf4244497 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp >+++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp >@@ -357,6 +357,37 @@ void connectSimpleBusMessageCallback(GstElement* pipeline) > g_signal_connect(bus.get(), "message", G_CALLBACK(simpleBusMessageCallback), pipeline); > } > >+static Lock cachedSharedBuffersLock; >+static HashMap<GstBuffer*, RefPtr<SharedBuffer>>& cachedSharedBuffers() >+{ >+ static NeverDestroyed<HashMap<GstBuffer*, RefPtr<SharedBuffer>>> map; >+ return map; >+} >+ >+GstMappedBuffer::~GstMappedBuffer() >+{ >+ auto locker = holdLock(cachedSharedBuffersLock); >+ auto iterator = cachedSharedBuffers().find(m_buffer); >+ if (iterator != cachedSharedBuffers().end()) >+ cachedSharedBuffers().remove(iterator); >+ >+ if (m_isValid) >+ gst_buffer_unmap(m_buffer, &m_info); >+ >+ m_isValid = false; >+} >+ >+RefPtr<SharedBuffer> GstMappedBuffer::sharedBuffer() const >+{ >+ auto locker = holdLock(cachedSharedBuffersLock); >+ if (!cachedSharedBuffers().contains(m_buffer)) { >+ RefPtr<SharedBuffer> cachedBuffer = SharedBuffer::create(data(), size()).ptr(); >+ cachedSharedBuffers().set(m_buffer, WTFMove(cachedBuffer)); >+ } >+ >+ return cachedSharedBuffers().get(m_buffer); >+} >+ > } > > #endif // USE(GSTREAMER) >diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h >index 2ef15502a005631ee4d07f7fa32b54f4698cfbc8..9e1b1d57e614c9a2541bd9fe9f98db7027c48cc1 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: >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 070e9778b18f1c95bee76c4c8cc19ce739f845b2..de8850e6e505355e63f42f5832efd38aa1a284f1 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,22 @@ >+2018-12-21 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!). >+ >+ Add new platform directory for GStreamer ports, and introduce some >+ tests for the GstMappedBuffer class. >+ >+ * 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): >+ > 2018-12-20 Carlos Garcia Campos <cgarcia@igalia.com> > > [GTK][WPE] Bump webkitgtk-test-fonts to 0.0.8 >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..e4659707670f75ff4801431074815b28b78522e8 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp >@@ -0,0 +1,53 @@ >+/* >+ * 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() >+{ >+ // Might be tempting to call gst_deint() here, don't, despite the naming, >+ // gst_init() doesn't reverse that call. >+} >+ >+} // 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..c70fa092bed9981920322c914451c1dc97a3212b >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GstMappedBuffer.cpp >@@ -0,0 +1,109 @@ >+/* >+ * 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) >+{ >+ GstBuffer* buf = gst_buffer_new_allocate(NULL, 64, NULL); >+ >+ GstMappedBuffer mappedBuf(buf, GST_MAP_READ); >+ >+ EXPECT_TRUE(mappedBuf); >+ EXPECT_EQ(mappedBuf.size(), 64); >+ >+ GstMappedBuffer mappedBuf2(buf, GST_MAP_READ); >+ EXPECT_EQ(mappedBuf, mappedBuf2); >+ EXPECT_EQ(buf, mappedBuf); >+ EXPECT_EQ(mappedBuf2, buf); >+ >+ GstMappedBuffer movedBuf = WTFMove(mappedBuf); >+ EXPECT_TRUE(movedBuf); >+ EXPECT_FALSE(mappedBuf); >+ EXPECT_EQ(movedBuf.size(), 64); >+ EXPECT_EQ(movedBuf, mappedBuf2); >+ EXPECT_EQ(buf, movedBuf); >+} >+ >+TEST_F(GStreamerTest, mappedBufferReadSanity) >+{ >+ gpointer memory = g_malloc(16); >+ memset(memory, 'x', 16); >+ GstBuffer* buf = gst_buffer_new_wrapped(memory, 16); >+ GstMappedBuffer mappedBuf(buf, 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); >+ GstBuffer* buf = gst_buffer_new_wrapped(memory, 16); >+ >+ GstMappedBuffer mappedBuf(buf, GST_MAP_WRITE); >+ EXPECT_EQ(mappedBuf.size(), 16); >+ memset(mappedBuf.data(), 'y', mappedBuf.size()); >+ >+ EXPECT_EQ(memcmp(memory, mappedBuf.data(), 16), 0); >+} >+ >+TEST_F(GStreamerTest, mappedBufferCachesSharedBuffers) >+{ >+ GstBuffer* buf = gst_buffer_new_allocate(NULL, 64, NULL); >+ >+ GstMappedBuffer mappedBuf(buf, 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) >+{ >+ GstBuffer* buf = gst_buffer_new(); >+ >+ ASSERT_EQ(GST_OBJECT_REFCOUNT(buf), 1); >+ >+ GstMappedBuffer mappedIvBuffer(buf, GST_MAP_READ); >+ ASSERT_TRUE(mappedIvBuffer); >+ >+ ASSERT_EQ(GST_OBJECT_REFCOUNT(buf), 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