Skip to content

Commit

Permalink
gstreamer feature builds but does not yet work
Browse files Browse the repository at this point in the history
  • Loading branch information
mnutt committed Jul 17, 2024
1 parent cff724e commit 1e2d1a1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Source/WTF/wtf/PlatformQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ if (USE_GLIB)
glib/Sandbox.h
glib/WTFGType.h
)

if (USE_GSTREAMER)
list(APPEND WTF_PUBLIC_HEADERS
glib/GThreadSafeWeakPtr.h
)
endif ()
endif ()

if (WIN32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ bool ensureGStreamerInitialized()
{
// WARNING: Please note this function can be called from any thread, for instance when creating
// a WebCodec element from a JS Worker.
#if !PLATFORM(QT)
RELEASE_ASSERT(isInWebProcess());
#endif
static std::once_flag onceFlag;
static bool isGStreamerInitialized;
std::call_once(onceFlag, [] {
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ class ImageGStreamer : public RefCounted<ImageGStreamer> {
}
~ImageGStreamer();

#if PLATFORM(QT)
operator bool() const { return !m_image.isNull(); }
#else
operator bool() const { return !!m_image; }
#endif

PlatformImagePtr image() const { return m_image; }

void setCropRect(FloatRect rect) { m_cropRect = rect; }
FloatRect rect()
{
#if PLATFORM(QT)
ASSERT(!m_image.isNull());
#else
ASSERT(m_image);
#endif
if (!m_cropRect.isEmpty())
return FloatRect(m_cropRect);
return FloatRect(0, 0, m_size.width(), m_size.height());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#if ENABLE(VIDEO) && USE(GSTREAMER)

#include "GStreamerCommon.h"
#include "BitmapImage.h"

#include <gst/gst.h>
#include <gst/video/gstvideometa.h>
Expand Down Expand Up @@ -96,17 +97,18 @@ ImageGStreamer::ImageGStreamer(GRefPtr<GstSample>&& sample)
} else
surface = QImage(bufferData, width, height, stride, imageFormat);

#if PLATFORM(QT)
m_image = QImage(surface);
#else
m_image = BitmapImage::create(WTFMove(surface));
#endif

if (GstVideoCropMeta* cropMeta = gst_buffer_get_video_crop_meta(buffer))
setCropRect(FloatRect(cropMeta->x, cropMeta->y, cropMeta->width, cropMeta->height));
}

ImageGStreamer::~ImageGStreamer()
{
if (m_image)
m_image = nullptr;

// We keep the buffer memory mapped until the image is destroyed because the internal
// QImage was created using the buffer data directly.
if (m_frameMapped)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
#include "TextureMapperPlatformLayerProxyGL.h"
#endif // USE(TEXTURE_MAPPER)

#if PLATFORM(QT)
#include "TextureMapperFlags.h"
#endif

#if USE(TEXTURE_MAPPER_DMABUF)
#include "DMABufFormat.h"
#include "DMABufObject.h"
Expand Down Expand Up @@ -1992,6 +1996,7 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
GstState newState;
gst_message_parse_state_changed(message, &currentState, &newState, nullptr);

#if USE(GSTREAMER_GL)
if (isHolePunchRenderingEnabled() && currentState <= GST_STATE_READY && newState >= GST_STATE_READY) {
// If we didn't create a video sink, store a reference to the created one.
if (!m_videoSink) {
Expand All @@ -2010,6 +2015,7 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
}
}
}
#endif

auto& quirksManager = GStreamerQuirksManager::singleton();
if (quirksManager.isEnabled() && currentState <= GST_STATE_READY && newState >= GST_STATE_READY) {
Expand Down Expand Up @@ -4081,13 +4087,13 @@ bool MediaPlayerPrivateGStreamer::setVideoSourceOrientation(ImageOrientation ori
return false;

m_videoSourceOrientation = orientation;
#if USE(TEXTURE_MAPPER) && !PLATFORM(QT)
#if USE(TEXTURE_MAPPER)
updateTextureMapperFlags();
#endif
return true;
}

#if USE(TEXTURE_MAPPER) && !PLATFORM(QT)
#if USE(TEXTURE_MAPPER)
void MediaPlayerPrivateGStreamer::updateTextureMapperFlags()
{
switch (m_videoSourceOrientation.orientation()) {
Expand Down Expand Up @@ -4173,6 +4179,12 @@ GstElement* MediaPlayerPrivateGStreamer::createVideoSinkGL()
}
#endif // USE(GSTREAMER_GL)

#if PLATFORM(QT)
bool MediaPlayerPrivateGStreamer::isHolePunchRenderingEnabled() const
{
return false;
}
#else
class GStreamerHolePunchClient : public TextureMapperPlatformLayerBuffer::HolePunchClient {
public:
GStreamerHolePunchClient(GRefPtr<GstElement>&& videoSink, RefPtr<GStreamerQuirksManager>&& quirksManagerForTesting)
Expand Down Expand Up @@ -4249,6 +4261,7 @@ void MediaPlayerPrivateGStreamer::pushNextHolePunchBuffer()
proxyOperation(*m_platformLayerProxy);
#endif
}
#endif // !PLATFORM(QT)

bool MediaPlayerPrivateGStreamer::shouldIgnoreIntrinsicSize()
{
Expand Down Expand Up @@ -4297,12 +4310,14 @@ GstElement* MediaPlayerPrivateGStreamer::createVideoSink()
return m_videoSink.get();
}

#if USE(GSTREAMER_GL)
if (isHolePunchRenderingEnabled()) {
m_videoSink = createHolePunchVideoSink();
// Do not check the m_videoSink value. The nullptr case will trigger auto-plugging in playbin.
pushNextHolePunchBuffer();
return m_videoSink.get();
}
#endif

#if USE(TEXTURE_MAPPER_DMABUF)
if (!m_videoSink && m_canRenderingBeAccelerated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class MediaPlayerPrivateGStreamer
void loadingFailed(MediaPlayer::NetworkState, MediaPlayer::ReadyState = MediaPlayer::ReadyState::HaveNothing, bool forceNotifications = false);
void loadStateChanged();

#if USE(TEXTURE_MAPPER) && !PLATFORM(QT)
#if USE(TEXTURE_MAPPER)
void updateTextureMapperFlags();
#endif

Expand Down Expand Up @@ -389,7 +389,7 @@ class MediaPlayerPrivateGStreamer
GRefPtr<GstElement> m_source { nullptr };
bool m_areVolumeAndMuteInitialized { false };

#if USE(TEXTURE_MAPPER) && !PLATFORM(QT)
#if USE(TEXTURE_MAPPER)
OptionSet<TextureMapperFlags> m_textureMapperFlags;
#endif

Expand Down
15 changes: 15 additions & 0 deletions Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#if ENABLE(VIDEO) && USE(GSTREAMER)

#include "BitmapImage.h"
#if USE(GSTREAMER_GL)
#include "GLContext.h"
#endif
#include "GStreamerCommon.h"
#include "GraphicsContext.h"
#include "ImageGStreamer.h"
Expand Down Expand Up @@ -149,6 +151,19 @@ RefPtr<VideoFrame> VideoFrame::fromNativeImage(NativeImage& image)
default:
return nullptr;
}
#elif PLATFORM(QT)
QImage platformImage = image.platformImage();
auto width = platformImage.width();
auto height = platformImage.height();
strides[0] = platformImage.bytesPerLine();
auto size = platformImage.sizeInBytes();

auto format = G_BYTE_ORDER == G_LITTLE_ENDIAN ? GST_VIDEO_FORMAT_BGRA : GST_VIDEO_FORMAT_ARGB;
QImage* imagePtr = new QImage(platformImage);
auto buffer = adoptGRef(gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, (void *)platformImage.constBits(), size, 0, size, imagePtr, [](gpointer userData) {
QImage* imagePtr = static_cast<QImage*>(userData);
delete imagePtr;
}));
#endif

gst_buffer_add_video_meta_full(buffer.get(), GST_VIDEO_FRAME_FLAG_NONE, format, width, height, 1, offsets, strides);
Expand Down

0 comments on commit 1e2d1a1

Please sign in to comment.