no sync_bus_handler black magic anymore :)

This commit is contained in:
unknown 2012-04-17 18:43:22 +02:00
parent 62fa2c46da
commit e01b6dd7f5

View file

@ -16,7 +16,6 @@
/* Structure to contain all our information, so we can pass it around */ /* Structure to contain all our information, so we can pass it around */
typedef struct _CustomData { typedef struct _CustomData {
GstElement *playbin2; /* Our one and only pipeline */ GstElement *playbin2; /* Our one and only pipeline */
GstElement *xoverlay_element;
GtkWidget *main_window; GtkWidget *main_window;
GtkWidget *video_window; GtkWidget *video_window;
@ -26,16 +25,14 @@ typedef struct _CustomData {
GstState state; GstState state;
gint64 duration; gint64 duration;
guintptr embed_xid;
} CustomData; } CustomData;
/* Forward definition of the message processing function */ /* Forward definition of the message processing function */
static gboolean handle_message (GstBus *bus, GstMessage *msg, CustomData *data); static gboolean handle_message (GstBus *bus, GstMessage *msg, CustomData *data);
static GstBusSyncReply bus_sync_handler (GstBus *bus, GstMessage *msg, CustomData *data);
static void realize_cb (GtkWidget *widget, CustomData *data) { static void realize_cb (GtkWidget *widget, CustomData *data) {
GdkWindow *window = gtk_widget_get_window (widget); GdkWindow *window = gtk_widget_get_window (widget);
guintptr window_handle;
/* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
* as well */ * as well */
@ -43,12 +40,13 @@ static void realize_cb (GtkWidget *widget, CustomData *data) {
g_error ("Couldn't create native window needed for GstXOverlay!"); g_error ("Couldn't create native window needed for GstXOverlay!");
#if defined (GDK_WINDOWING_WIN32) #if defined (GDK_WINDOWING_WIN32)
data->embed_xid = (guintptr)GDK_WINDOW_HWND (window); window_handle = (guintptr)GDK_WINDOW_HWND (window);
#elif defined (GDK_WINDOWING_QUARTZ) #elif defined (GDK_WINDOWING_QUARTZ)
data->embed_xid = gdk_quartz_window_get_nsview (window); window_handle = gdk_quartz_window_get_nsview (window);
#elif defined (GDK_WINDOWING_X11) #elif defined (GDK_WINDOWING_X11)
data->embed_xid = GDK_WINDOW_XID (window); window_handle = GDK_WINDOW_XID (window);
#endif #endif
gst_x_overlay_set_window_handle (GST_X_OVERLAY (data->playbin2), window_handle);
} }
static void play_cb (GtkButton *button, CustomData *data) { static void play_cb (GtkButton *button, CustomData *data) {
@ -82,9 +80,6 @@ static gboolean draw_cb (GtkWidget *widget, GdkEventExpose *event, CustomData *d
cairo_destroy (cr); cairo_destroy (cr);
} }
if (data->xoverlay_element)
gst_x_overlay_expose (GST_X_OVERLAY (data->xoverlay_element));
return FALSE; return FALSE;
} }
@ -169,8 +164,6 @@ static gboolean refresh_ui (CustomData *data) {
} }
static void reset_app (CustomData *data) { static void reset_app (CustomData *data) {
if (data->xoverlay_element)
gst_object_unref (data->xoverlay_element);
gst_object_unref (data->playbin2); gst_object_unref (data->playbin2);
} }
@ -214,7 +207,6 @@ int main(int argc, char *argv[]) {
create_ui (&data); create_ui (&data);
bus = gst_element_get_bus (data.playbin2); bus = gst_element_get_bus (data.playbin2);
gst_bus_set_sync_handler (bus, (GstBusSyncHandler)bus_sync_handler, &data);
gst_bus_add_watch (bus, (GstBusFunc)handle_message, &data); gst_bus_add_watch (bus, (GstBusFunc)handle_message, &data);
gst_object_unref (bus); gst_object_unref (bus);
@ -349,33 +341,3 @@ static gboolean handle_message (GstBus *bus, GstMessage *msg, CustomData *data)
return TRUE; return TRUE;
} }
static GstBusSyncReply bus_sync_handler (GstBus *bus, GstMessage *msg, CustomData *data) {
/*ignore anything but 'prepare-xwindow-id' element messages */
if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS;
if (!gst_structure_has_name (msg->structure, "prepare-xwindow-id"))
return GST_BUS_PASS;
if (data->embed_xid != 0) {
/* GST_MESSAGE_SRC (message) will be the video sink element */
GstElement *sink = GST_ELEMENT (GST_MESSAGE_SRC (msg));
/* If we were tracking a previous video sink, release it */
if (data->xoverlay_element != NULL)
gst_object_unref (data->xoverlay_element);
/* Get a reference to the new sink */
data->xoverlay_element = GST_ELEMENT (gst_object_ref (sink));
if (g_object_class_find_property (G_OBJECT_GET_CLASS (sink), "force-aspect-ratio")) {
g_object_set (sink, "force-aspect-ratio", TRUE, NULL);
}
gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), data->embed_xid);
} else {
g_warning ("Should have obtained an xid by now!");
}
gst_message_unref (msg);
return GST_BUS_DROP;
}