mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-10 17:35:59 +00:00
x(v)imagesink: catch tags and show title in own window
Refactor the code that sets the window title. Catch tag-events and use title metadata for the window title.
This commit is contained in:
parent
dc706f7f2f
commit
8946be1f0b
4 changed files with 158 additions and 7 deletions
|
@ -801,6 +801,46 @@ gst_ximagesink_xwindow_decorate (GstXImageSink * ximagesink,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_ximagesink_xwindow_set_title (GstXImageSink * ximagesink,
|
||||
const gchar * media_title)
|
||||
{
|
||||
if (media_title) {
|
||||
g_free (ximagesink->media_title);
|
||||
ximagesink->media_title = g_strdup (media_title);
|
||||
}
|
||||
if (ximagesink->xwindow) {
|
||||
/* we have a window */
|
||||
if (ximagesink->xwindow->internal) {
|
||||
XTextProperty xproperty;
|
||||
const gchar *app_name;
|
||||
const gchar *title = NULL;
|
||||
gchar *title_mem = NULL;
|
||||
|
||||
/* set application name as a title */
|
||||
app_name = g_get_application_name ();
|
||||
|
||||
if (app_name && ximagesink->media_title) {
|
||||
title = title_mem = g_strconcat (ximagesink->media_title, " : ",
|
||||
app_name, NULL);
|
||||
} else if (app_name) {
|
||||
title = app_name;
|
||||
} else if (ximagesink->media_title) {
|
||||
title = ximagesink->media_title;
|
||||
}
|
||||
|
||||
if (title) {
|
||||
if ((XStringListToTextProperty (((char **) &title), 1,
|
||||
&xproperty)) != 0)
|
||||
XSetWMName (ximagesink->xcontext->disp, ximagesink->xwindow->win,
|
||||
&xproperty);
|
||||
|
||||
g_free (title_mem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This function handles a GstXWindow creation */
|
||||
static GstXWindow *
|
||||
gst_ximagesink_xwindow_new (GstXImageSink * ximagesink, gint width, gint height)
|
||||
|
@ -826,6 +866,9 @@ gst_ximagesink_xwindow_new (GstXImageSink * ximagesink, gint width, gint height)
|
|||
ConfigureNotify. This takes away flickering of video when resizing. */
|
||||
XSetWindowBackgroundPixmap (ximagesink->xcontext->disp, xwindow->win, None);
|
||||
|
||||
/* set application name as a title */
|
||||
gst_ximagesink_xwindow_set_title (ximagesink, NULL);
|
||||
|
||||
if (ximagesink->handle_events) {
|
||||
Atom wm_delete;
|
||||
|
||||
|
@ -1638,6 +1681,38 @@ no_window:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
gst_ximagesink_event (GstBaseSink * sink, GstEvent * event)
|
||||
{
|
||||
GstXImageSink *ximagesink = GST_XIMAGESINK (sink);
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_TAG:{
|
||||
GstTagList *l;
|
||||
gchar *title = NULL;
|
||||
|
||||
gst_event_parse_tag (event, &l);
|
||||
gst_tag_list_get_string (l, GST_TAG_TITLE, &title);
|
||||
|
||||
if (title) {
|
||||
GST_DEBUG_OBJECT (ximagesink, "got tags, title='%s'", title);
|
||||
gst_ximagesink_xwindow_set_title (ximagesink, title);
|
||||
|
||||
g_free (title);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (GST_BASE_SINK_CLASS (parent_class)->event)
|
||||
return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Buffer management
|
||||
*
|
||||
* The buffer_alloc function must either return a buffer with given size and
|
||||
|
@ -2167,6 +2242,8 @@ gst_ximagesink_finalize (GObject * object)
|
|||
ximagesink->pool_lock = NULL;
|
||||
}
|
||||
|
||||
g_free (ximagesink->media_title);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
@ -2262,6 +2339,7 @@ gst_ximagesink_class_init (GstXImageSinkClass * klass)
|
|||
gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_ximagesink_get_times);
|
||||
gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_ximagesink_show_frame);
|
||||
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_ximagesink_show_frame);
|
||||
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_ximagesink_event);
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
|
|
|
@ -215,6 +215,9 @@ struct _GstXImageSink {
|
|||
gboolean handle_events;
|
||||
gboolean handle_expose;
|
||||
gboolean draw_border;
|
||||
|
||||
/* stream metadata */
|
||||
gchar *media_title;
|
||||
};
|
||||
|
||||
struct _GstXImageSinkClass {
|
||||
|
|
|
@ -906,6 +906,46 @@ gst_xvimagesink_xwindow_decorate (GstXvImageSink * xvimagesink,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_xvimagesink_xwindow_set_title (GstXvImageSink * xvimagesink,
|
||||
const gchar * media_title)
|
||||
{
|
||||
if (media_title) {
|
||||
g_free (xvimagesink->media_title);
|
||||
xvimagesink->media_title = g_strdup (media_title);
|
||||
}
|
||||
if (xvimagesink->xwindow) {
|
||||
/* we have a window */
|
||||
if (xvimagesink->xwindow->internal) {
|
||||
XTextProperty xproperty;
|
||||
const gchar *app_name;
|
||||
const gchar *title = NULL;
|
||||
gchar *title_mem = NULL;
|
||||
|
||||
/* set application name as a title */
|
||||
app_name = g_get_application_name ();
|
||||
|
||||
if (app_name && xvimagesink->media_title) {
|
||||
title = title_mem = g_strconcat (xvimagesink->media_title, " : ",
|
||||
app_name, NULL);
|
||||
} else if (app_name) {
|
||||
title = app_name;
|
||||
} else if (xvimagesink->media_title) {
|
||||
title = xvimagesink->media_title;
|
||||
}
|
||||
|
||||
if (title) {
|
||||
if ((XStringListToTextProperty (((char **) &title), 1,
|
||||
&xproperty)) != 0)
|
||||
XSetWMName (xvimagesink->xcontext->disp, xvimagesink->xwindow->win,
|
||||
&xproperty);
|
||||
|
||||
g_free (title_mem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This function handles a GstXWindow creation
|
||||
* The width and height are the actual pixel size on the display */
|
||||
static GstXWindow *
|
||||
|
@ -914,8 +954,6 @@ gst_xvimagesink_xwindow_new (GstXvImageSink * xvimagesink,
|
|||
{
|
||||
GstXWindow *xwindow = NULL;
|
||||
XGCValues values;
|
||||
XTextProperty xproperty;
|
||||
const gchar *title;
|
||||
|
||||
g_return_val_if_fail (GST_IS_XVIMAGESINK (xvimagesink), NULL);
|
||||
|
||||
|
@ -937,11 +975,7 @@ gst_xvimagesink_xwindow_new (GstXvImageSink * xvimagesink,
|
|||
XSetWindowBackgroundPixmap (xvimagesink->xcontext->disp, xwindow->win, None);
|
||||
|
||||
/* set application name as a title */
|
||||
title = g_get_application_name ();
|
||||
if (title) {
|
||||
if ((XStringListToTextProperty (((char **) &title), 1, &xproperty)) != 0)
|
||||
XSetWMName (xvimagesink->xcontext->disp, xwindow->win, &xproperty);
|
||||
}
|
||||
gst_xvimagesink_xwindow_set_title (xvimagesink, NULL);
|
||||
|
||||
if (xvimagesink->handle_events) {
|
||||
Atom wm_delete;
|
||||
|
@ -2341,6 +2375,36 @@ no_window:
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_xvimagesink_event (GstBaseSink * sink, GstEvent * event)
|
||||
{
|
||||
GstXvImageSink *xvimagesink = GST_XVIMAGESINK (sink);
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_TAG:{
|
||||
GstTagList *l;
|
||||
gchar *title = NULL;
|
||||
|
||||
gst_event_parse_tag (event, &l);
|
||||
gst_tag_list_get_string (l, GST_TAG_TITLE, &title);
|
||||
|
||||
if (title) {
|
||||
GST_DEBUG_OBJECT (xvimagesink, "got tags, title='%s'", title);
|
||||
gst_xvimagesink_xwindow_set_title (xvimagesink, title);
|
||||
|
||||
g_free (title);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (GST_BASE_SINK_CLASS (parent_class)->event)
|
||||
return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Buffer management */
|
||||
|
||||
static GstFlowReturn
|
||||
|
@ -3236,6 +3300,8 @@ gst_xvimagesink_finalize (GObject * object)
|
|||
xvimagesink->pool_lock = NULL;
|
||||
}
|
||||
|
||||
g_free (xvimagesink->media_title);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
@ -3422,6 +3488,7 @@ gst_xvimagesink_class_init (GstXvImageSinkClass * klass)
|
|||
gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_xvimagesink_get_times);
|
||||
gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_xvimagesink_show_frame);
|
||||
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_xvimagesink_show_frame);
|
||||
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_xvimagesink_event);
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
|
|
|
@ -283,6 +283,9 @@ struct _GstXvImageSink {
|
|||
gboolean have_autopaint_colorkey;
|
||||
gboolean have_colorkey;
|
||||
gboolean have_double_buffer;
|
||||
|
||||
/* stream metadata */
|
||||
gchar *media_title;
|
||||
};
|
||||
|
||||
struct _GstXvImageSinkClass {
|
||||
|
|
Loading…
Reference in a new issue