tests: elements: clean up vaapisink test

- Use gst_element_send_event() instead of gst_pad_push_event()
- don't zero App structure
- check for pipeline parsing error
- only get vaapisink for property set
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-05-12 18:17:55 +02:00
parent 5ab5113f6f
commit b02a25cd7f

View file

@ -6,9 +6,7 @@ typedef struct _CustomData
{ {
GstElement *pipeline; GstElement *pipeline;
GstElement *video_sink; GstElement *video_sink;
GstElement *src_sink;
GMainLoop *loop; GMainLoop *loop;
GstPad *src_pad;
gboolean orient_automatic; gboolean orient_automatic;
} AppData; } AppData;
@ -26,7 +24,7 @@ send_rotate_event (AppData * data)
tags[counter++ % G_N_ELEMENTS (tags)], NULL)); tags[counter++ % G_N_ELEMENTS (tags)], NULL));
/* Send the event */ /* Send the event */
res = gst_pad_push_event (data->src_pad, event); res = gst_element_send_event (data->pipeline, event);
g_print ("Sending event %p done: %d\n", event, res); g_print ("Sending event %p done: %d\n", event, res);
} }
@ -67,25 +65,24 @@ main (int argc, char *argv[])
AppData data; AppData data;
GstStateChangeReturn ret; GstStateChangeReturn ret;
GIOChannel *io_stdin; GIOChannel *io_stdin;
GError *err = NULL;
/* Initialize GStreamer */ /* Initialize GStreamer */
gst_init (&argc, &argv); gst_init (&argc, &argv);
/* Initialize our data structure */
memset (&data, 0, sizeof (data));
/* Print usage map */ /* Print usage map */
g_print ("USAGE: Choose one of the following options, then press enter:\n" g_print ("USAGE: Choose one of the following options, then press enter:\n"
" 'r' to send image-orientation tag event\n \ " 'r' to send image-orientation tag event\n"
's' to set orient-automatic\n \ " 's' to set orient-automatic\n" " 'Q' to quit\n");
'Q' to quit\n");
data.pipeline = data.pipeline = gst_parse_launch ("videotestsrc ! vaapisink name=sink", &err);
gst_parse_launch if (err) {
("videotestsrc name=src ! vaapisink name=vaapisink", NULL); g_printerr ("failed to create pipeline: %s\n", err->message);
data.video_sink = gst_bin_get_by_name (GST_BIN (data.pipeline), "vaapisink"); g_error_free (err);
data.src_sink = gst_bin_get_by_name (GST_BIN (data.pipeline), "src"); return -1;
data.src_pad = gst_element_get_static_pad (data.src_sink, "src"); }
data.video_sink = gst_bin_get_by_name (GST_BIN (data.pipeline), "sink");
/* Add a keyboard watch so we get notified of keystrokes */ /* Add a keyboard watch so we get notified of keystrokes */
io_stdin = g_io_channel_unix_new (fileno (stdin)); io_stdin = g_io_channel_unix_new (fileno (stdin));
@ -95,21 +92,21 @@ main (int argc, char *argv[])
ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING); ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) { if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n"); g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (data.pipeline); goto bail;
return -1;
} }
/* Create a GLib Main Loop and set it to run */ /* Create a GLib Main Loop and set it to run */
data.loop = g_main_loop_new (NULL, FALSE); data.loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (data.loop); g_main_loop_run (data.loop);
gst_element_set_state (data.pipeline, GST_STATE_NULL);
bail:
/* Free resources */ /* Free resources */
g_main_loop_unref (data.loop); g_main_loop_unref (data.loop);
g_io_channel_unref (io_stdin); g_io_channel_unref (io_stdin);
gst_element_set_state (data.pipeline, GST_STATE_NULL);
if (data.video_sink != NULL) gst_object_unref (data.video_sink);
gst_object_unref (data.video_sink);
gst_object_unref (data.pipeline); gst_object_unref (data.pipeline);
return 0; return 0;