mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
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>
This commit is contained in:
parent
3817efb275
commit
45409d4558
4 changed files with 94 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -962,6 +976,47 @@ gst_d3d11_video_sink_unlock_stop (GstBaseSink * sink)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
@ -280,6 +284,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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue