Skip to content

Commit

Permalink
[GStreamer] GL/DMABuf logging improvements
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274146

Reviewed by Xabier Rodriguez-Calvar.

The webkitdisplay GST_DEBUG category can be used to diagnose WebKit/GL errors now. The DMABuf
rendering code path was also instrumented with logs in order to help diagnosing issues.

* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::pushDMABufToCompositor):
* Source/WebCore/platform/graphics/gstreamer/PlatformDisplayGStreamer.cpp:
(WebCore::ensureDebugCategoryInitialized):
(WebCore::PlatformDisplay::gstGLContext const):

Canonical link: https://commits.webkit.org/278802@main
  • Loading branch information
philn committed May 15, 2024
1 parent b156621 commit ec004d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3448,8 +3448,10 @@ void MediaPlayerPrivateGStreamer::pushDMABufToCompositor()
ASSERT(is<TextureMapperPlatformLayerProxyDMABuf>(proxy));

Locker locker { proxy.lock() };
if (!proxy.isActive())
if (!proxy.isActive()) {
GST_ERROR_OBJECT(pipeline(), "TextureMapperPlatformLayerProxyDMABuf is inactive");
return;
}

// Currently we have to cover two ways of detecting a DMABuf memory. The most reliable is by detecting
// the memory:DMABuf feature on the GstCaps object. All sensible decoders yielding DMABufs specify this.
Expand Down Expand Up @@ -3544,12 +3546,16 @@ void MediaPlayerPrivateGStreamer::pushDMABufToCompositor()
.height = static_cast<uint32_t>GST_VIDEO_INFO_HEIGHT(&videoInfo),
.flags = GBMBufferSwapchain::BufferDescription::LinearStorage,
};
if (bufferDescription.format.fourcc == DMABufFormat::FourCC::Invalid)
if (bufferDescription.format.fourcc == DMABufFormat::FourCC::Invalid) {
GST_ERROR_OBJECT(pipeline(), "Invalid DMABuf fourcc for GStreamer video format %s", gst_video_format_to_string(GST_VIDEO_INFO_FORMAT(&videoInfo)));
return;
}

auto swapchainBuffer = m_swapchain->getBuffer(bufferDescription);
if (!swapchainBuffer)
if (!swapchainBuffer) {
GST_ERROR_OBJECT(pipeline(), "Swap chain has no available buffer");
return;
}

// Destination helper struct, maps the gbm_bo object into CPU-memory space and copies from the accompanying Source in fill().
struct Destination {
Expand Down Expand Up @@ -3614,6 +3620,7 @@ void MediaPlayerPrivateGStreamer::pushDMABufToCompositor()
// The updated buffer is pushed into the composition stage. The DMABufObject handle uses the swapchain address as the handle base.
// When the buffer is pushed for the first time, the lambda will be invoked to retrieve a more complete DMABufObject for the
// given GBMBufferSwapchain::Buffer object.
GST_TRACE_OBJECT(pipeline(), "Pushing DMABuf object to TextureMapper");
downcast<TextureMapperPlatformLayerProxyDMABuf>(proxy).pushDMABuf(
DMABufObject(reinterpret_cast<uintptr_t>(m_swapchain.get()) + swapchainBuffer->handle()),
[&](auto&& initialObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,58 @@
#undef GST_USE_UNSTABLE_API
#include <wtf/glib/GUniquePtr.h>

GST_DEBUG_CATEGORY_EXTERN(webkit_media_player_debug);
#define GST_CAT_DEFAULT webkit_media_player_debug
GST_DEBUG_CATEGORY(webkit_display_debug);
#define GST_CAT_DEFAULT webkit_display_debug

namespace WebCore {

static void ensureDebugCategoryInitialized()
{
static std::once_flag debugRegisteredFlag;
std::call_once(debugRegisteredFlag, [] {
GST_DEBUG_CATEGORY_INIT(webkit_display_debug, "webkitdisplay", 0, "WebKit Display");
});
}

GstGLDisplay* PlatformDisplay::gstGLDisplay() const
{
ensureDebugCategoryInitialized();
if (!m_gstGLDisplay)
m_gstGLDisplay = adoptGRef(GST_GL_DISPLAY(gst_gl_display_egl_new_with_egl_display(eglDisplay())));
GST_TRACE("Using GL display %" GST_PTR_FORMAT, m_gstGLDisplay.get());
return m_gstGLDisplay.get();
}

GstGLContext* PlatformDisplay::gstGLContext() const
{
ensureDebugCategoryInitialized();

if (m_gstGLContext)
return m_gstGLContext.get();

auto* gstDisplay = gstGLDisplay();
if (!gstDisplay)
if (!gstDisplay) {
GST_ERROR("No GL display");
return nullptr;
}

auto* context = const_cast<PlatformDisplay*>(this)->sharingGLContext();
if (!context)
if (!context) {
GST_ERROR("No sharing GL context");
return nullptr;
}

m_gstGLContext = adoptGRef(gst_gl_context_new_wrapped(gstDisplay, reinterpret_cast<guintptr>(context->platformContext()), GST_GL_PLATFORM_EGL, GST_GL_API_GLES2));
{
GLContext::ScopedGLContextCurrent scopedCurrent(*context);
if (gst_gl_context_activate(m_gstGLContext.get(), TRUE)) {
GUniqueOutPtr<GError> error;
if (!gst_gl_context_fill_info(m_gstGLContext.get(), &error.outPtr()))
GST_WARNING("Failed to fill in GStreamer context: %s", error->message);
GST_ERROR("Failed to fill in GStreamer context: %s", error->message);
gst_gl_context_activate(m_gstGLContext.get(), FALSE);
}
}
GST_DEBUG("Created GL context %" GST_PTR_FORMAT, m_gstGLContext.get());
return m_gstGLContext.get();
}

Expand All @@ -78,4 +95,6 @@ void PlatformDisplay::clearGStreamerGLState()

} // namespace WebCore

#undef GST_CAT_DEFAULT

#endif // USE(GSTREAMER_GL)

0 comments on commit ec004d2

Please sign in to comment.