summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2021-09-18 02:27:51 +0900
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2021-09-18 16:02:15 +0000
commit45409d45589dbd21b476965f638aef57dcad1b5b (patch)
tree157cb8916c0669513416db2a6cd79fe7602d3029
parent3817efb275396c322220182ef3c2e9ab3c821727 (diff)
downloadgstreamer-plugins-bad-45409d45589dbd21b476965f638aef57dcad1b5b.tar.gz
d3d11videosink: Display title of content if possible
Update title text of window (currently it's always "Direct3D11 renderer") when we are rendering on internal HWND, not external HWND. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2529>
-rw-r--r--sys/d3d11/gstd3d11videosink.cpp55
-rw-r--r--sys/d3d11/gstd3d11window.cpp13
-rw-r--r--sys/d3d11/gstd3d11window.h6
-rw-r--r--sys/d3d11/gstd3d11window_win32.cpp20
4 files changed, 94 insertions, 0 deletions
diff --git a/sys/d3d11/gstd3d11videosink.cpp b/sys/d3d11/gstd3d11videosink.cpp
index cbc0db9d0..9cc9c1a33 100644
--- a/sys/d3d11/gstd3d11videosink.cpp
+++ b/sys/d3d11/gstd3d11videosink.cpp
@@ -41,6 +41,7 @@
#include "gstd3d11videosink.h"
#include "gstd3d11videoprocessor.h"
#include "gstd3d11pluginutils.h"
+#include <string>
#if GST_D3D11_WINAPI_APP
#include "gstd3d11window_corewindow.h"
@@ -132,6 +133,8 @@ struct _GstD3D11VideoSink
gboolean drawing;
GstBuffer *current_buffer;
GRecMutex draw_lock;
+
+ gchar *title;
};
static void gst_d3d11_videosink_set_property (GObject * object, guint prop_id,
@@ -164,6 +167,8 @@ static gboolean gst_d3d11_video_sink_query (GstBaseSink * sink,
GstQuery * query);
static gboolean gst_d3d11_video_sink_unlock (GstBaseSink * sink);
static gboolean gst_d3d11_video_sink_unlock_stop (GstBaseSink * sink);
+static gboolean gst_d3d11_video_sink_event (GstBaseSink * sink,
+ GstEvent * event);
static GstFlowReturn
gst_d3d11_video_sink_show_frame (GstVideoSink * sink, GstBuffer * buf);
@@ -320,6 +325,7 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
basesink_class->unlock = GST_DEBUG_FUNCPTR (gst_d3d11_video_sink_unlock);
basesink_class->unlock_stop =
GST_DEBUG_FUNCPTR (gst_d3d11_video_sink_unlock_stop);
+ basesink_class->event = GST_DEBUG_FUNCPTR (gst_d3d11_video_sink_event);
videosink_class->show_frame =
GST_DEBUG_FUNCPTR (gst_d3d11_video_sink_show_frame);
@@ -432,6 +438,7 @@ gst_d3d11_video_sink_finalize (GObject * object)
GstD3D11VideoSink *self = GST_D3D11_VIDEO_SINK (object);
g_rec_mutex_clear (&self->draw_lock);
+ g_free (self->title);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -642,6 +649,11 @@ gst_d3d11_video_sink_update_window (GstD3D11VideoSink * self, GstCaps * caps)
self->processor_in_use = FALSE;
+ if (self->title) {
+ gst_d3d11_window_set_title (self->window, self->title);
+ g_clear_pointer (&self->title, g_free);
+ }
+
return TRUE;
/* ERRORS */
@@ -810,6 +822,8 @@ gst_d3d11_video_sink_stop (GstBaseSink * sink)
gst_clear_object (&self->device);
gst_clear_object (&self->window);
+ g_clear_pointer (&self->title, g_free);
+
return TRUE;
}
@@ -963,6 +977,47 @@ gst_d3d11_video_sink_unlock_stop (GstBaseSink * sink)
}
static gboolean
+gst_d3d11_video_sink_event (GstBaseSink * sink, GstEvent * event)
+{
+ GstD3D11VideoSink *self = GST_D3D11_VIDEO_SINK (sink);
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_TAG:{
+ GstTagList *taglist;
+ gchar *title = nullptr;
+
+ gst_event_parse_tag (event, &taglist);
+ gst_tag_list_get_string (taglist, GST_TAG_TITLE, &title);
+
+ if (title) {
+ const gchar *app_name = g_get_application_name ();
+ std::string title_string;
+
+ if (app_name) {
+ title_string = std::string (title) + " : " + std::string (app_name);
+ } else {
+ title_string = std::string (title);
+ }
+
+ if (self->window) {
+ gst_d3d11_window_set_title (self->window, title_string.c_str ());
+ } else {
+ g_free (self->title);
+ self->title = g_strdup (title_string.c_str ());
+ }
+
+ g_free (title);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
+}
+
+static gboolean
gst_d3d11_video_sink_upload_frame (GstD3D11VideoSink * self, GstBuffer * inbuf,
GstBuffer * outbuf)
{
diff --git a/sys/d3d11/gstd3d11window.cpp b/sys/d3d11/gstd3d11window.cpp
index 85506b1a8..6eb53f318 100644
--- a/sys/d3d11/gstd3d11window.cpp
+++ b/sys/d3d11/gstd3d11window.cpp
@@ -788,6 +788,19 @@ gst_d3d11_window_set_render_rectangle (GstD3D11Window * window,
klass->set_render_rectangle (window, rect);
}
+void
+gst_d3d11_window_set_title (GstD3D11Window * window, const gchar * title)
+{
+ GstD3D11WindowClass *klass;
+
+ g_return_if_fail (GST_IS_D3D11_WINDOW (window));
+
+ klass = GST_D3D11_WINDOW_GET_CLASS (window);
+
+ if (klass->set_title)
+ klass->set_title (window, title);
+}
+
static gboolean
gst_d3d11_window_buffer_ensure_processor_input (GstD3D11Window * self,
GstBuffer * buffer, ID3D11VideoProcessorInputView ** in_view)
diff --git a/sys/d3d11/gstd3d11window.h b/sys/d3d11/gstd3d11window.h
index 257f23bb4..8d35b4ef8 100644
--- a/sys/d3d11/gstd3d11window.h
+++ b/sys/d3d11/gstd3d11window.h
@@ -170,6 +170,9 @@ struct _GstD3D11WindowClass
void (*set_render_rectangle) (GstD3D11Window * window,
const GstVideoRectangle * rect);
+
+ void (*set_title) (GstD3D11Window * window,
+ const gchar *title);
};
GType gst_d3d11_window_get_type (void);
@@ -179,6 +182,9 @@ void gst_d3d11_window_show (GstD3D11Window * window);
void gst_d3d11_window_set_render_rectangle (GstD3D11Window * window,
const GstVideoRectangle * rect);
+void gst_d3d11_window_set_title (GstD3D11Window * window,
+ const gchar *title);
+
gboolean gst_d3d11_window_prepare (GstD3D11Window * window,
guint display_width,
guint display_height,
diff --git a/sys/d3d11/gstd3d11window_win32.cpp b/sys/d3d11/gstd3d11window_win32.cpp
index 644839129..6261c97f6 100644
--- a/sys/d3d11/gstd3d11window_win32.cpp
+++ b/sys/d3d11/gstd3d11window_win32.cpp
@@ -129,6 +129,8 @@ static void gst_d3d11_window_win32_unprepare (GstD3D11Window * window);
static void
gst_d3d11_window_win32_set_render_rectangle (GstD3D11Window * window,
const GstVideoRectangle * rect);
+static void gst_d3d11_window_win32_set_title (GstD3D11Window * window,
+ const gchar * title);
static void
gst_d3d11_window_win32_class_init (GstD3D11WindowWin32Class * klass)
@@ -154,6 +156,8 @@ gst_d3d11_window_win32_class_init (GstD3D11WindowWin32Class * klass)
GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_unprepare);
window_class->set_render_rectangle =
GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_set_render_rectangle);
+ window_class->set_title =
+ GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_set_title);
}
static void
@@ -281,6 +285,22 @@ gst_d3d11_window_win32_set_render_rectangle (GstD3D11Window * window,
}
static void
+gst_d3d11_window_win32_set_title (GstD3D11Window * window, const gchar * title)
+{
+ GstD3D11WindowWin32 *self = GST_D3D11_WINDOW_WIN32 (window);
+
+ /* Do this only when we are rendring on our own HWND */
+ if (!self->external_hwnd && self->internal_hwnd) {
+ gunichar2 *str = g_utf8_to_utf16 (title, -1, nullptr, nullptr, nullptr);
+
+ if (str) {
+ SetWindowTextW (self->internal_hwnd, (LPCWSTR) str);
+ g_free (str);
+ }
+ }
+}
+
+static void
gst_d3d11_window_win32_finalize (GObject * object)
{
GstD3D11WindowWin32 *self = GST_D3D11_WINDOW_WIN32 (object);