|
| 1 | +/* Simple script which will start an aravis pipeline, then restart ONLY the camera. */ |
| 2 | +#include <gst/gst.h> |
| 3 | +#include <stdio.h> |
| 4 | +#include <unistd.h> |
| 5 | + |
| 6 | +int |
| 7 | +main (int argc, char *argv[]) |
| 8 | +{ |
| 9 | + GstElement *pipeline; |
| 10 | + GstElement *source; |
| 11 | + GstElement *sink; |
| 12 | + GstElement *new_source; |
| 13 | + GstState current_state, pending_state; |
| 14 | + |
| 15 | + gst_init (&argc, &argv); |
| 16 | + |
| 17 | + pipeline = gst_pipeline_new ("aravis_pipeline"); |
| 18 | + source = gst_element_factory_make ("aravissrc", "source"); |
| 19 | + if (!source) { |
| 20 | + printf ("Failed to create the source element\n"); |
| 21 | + return EXIT_FAILURE; |
| 22 | + } |
| 23 | + |
| 24 | + g_object_set(G_OBJECT(source), |
| 25 | + "camera-name", "Aravis-Fake-GV01", |
| 26 | + "num-arv-buffers", 5, |
| 27 | + "packet-resend", FALSE, |
| 28 | + "packet-size", 9000, |
| 29 | + "auto-packet-size", FALSE, |
| 30 | + NULL); |
| 31 | + |
| 32 | + sink = gst_element_factory_make ("fakesink", "fake_sink"); |
| 33 | + |
| 34 | + if (!pipeline || !source || !sink) { |
| 35 | + printf ("Not all elements could be created.\n"); |
| 36 | + return EXIT_FAILURE; |
| 37 | + } |
| 38 | + |
| 39 | + gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL); |
| 40 | + |
| 41 | + if (!gst_element_link (source, sink)) { |
| 42 | + printf ("Elements could not be linked.\n"); |
| 43 | + gst_object_unref (pipeline); |
| 44 | + return EXIT_FAILURE; |
| 45 | + } |
| 46 | + |
| 47 | + printf ("Start the pipeline\n"); |
| 48 | + g_assert_cmpint (gst_element_set_state(pipeline, GST_STATE_PLAYING), ==, GST_STATE_CHANGE_ASYNC); |
| 49 | + |
| 50 | + printf ("Wait for a few frames\n"); |
| 51 | + sleep (1); |
| 52 | + |
| 53 | + printf ("Stop the source\n"); |
| 54 | + g_assert_cmpint (gst_element_set_state(source, GST_STATE_NULL), ==, GST_STATE_CHANGE_SUCCESS); |
| 55 | + |
| 56 | + gst_element_get_state (source, ¤t_state, &pending_state, 0); |
| 57 | + printf ("source current state:%d - pending state:%d\n", current_state, pending_state); |
| 58 | + |
| 59 | + sleep (1); |
| 60 | + |
| 61 | + gst_element_unlink(source, sink); |
| 62 | + g_assert (gst_bin_remove(GST_BIN(pipeline), source)); |
| 63 | + |
| 64 | + printf ("Create a new source\n"); |
| 65 | + new_source = gst_element_factory_make ("aravissrc", "new_source"); |
| 66 | + if (!new_source) { |
| 67 | + printf ("Failed to create the source element\n"); |
| 68 | + return EXIT_FAILURE; |
| 69 | + } |
| 70 | + g_object_set(G_OBJECT(new_source), |
| 71 | + "camera-name", "Aravis-Fake-GV01", |
| 72 | + "num-arv-buffers", 5, |
| 73 | + "packet-resend", FALSE, |
| 74 | + "packet-size", 9000, |
| 75 | + "auto-packet-size", FALSE, |
| 76 | + NULL); |
| 77 | + |
| 78 | + g_assert (gst_bin_add(GST_BIN(pipeline), new_source)); |
| 79 | + g_assert (gst_element_link(new_source, sink)); |
| 80 | + g_assert (gst_element_sync_state_with_parent(new_source)); |
| 81 | + |
| 82 | + gst_element_get_state (source, ¤t_state, &pending_state, 0); |
| 83 | + printf ("new source current state:%d - pending state:%d\n", current_state, pending_state); |
| 84 | + |
| 85 | + printf ("Start the new source\n"); |
| 86 | + g_assert_cmpint (gst_element_set_state(source, GST_STATE_PLAYING), ==, GST_STATE_CHANGE_SUCCESS); |
| 87 | + |
| 88 | + gst_element_get_state (source, ¤t_state, &pending_state, 0); |
| 89 | + printf ("new source current state:%d - pending state:%d\n", current_state, pending_state); |
| 90 | + |
| 91 | + printf ("Wait for a few frames\n"); |
| 92 | + |
| 93 | + printf ("Stop the pipeline\n"); |
| 94 | + g_assert_cmpint (gst_element_set_state (pipeline, GST_STATE_NULL), ==, GST_STATE_CHANGE_SUCCESS); |
| 95 | + |
| 96 | + printf ("Free the pipeline\n"); |
| 97 | + gst_object_unref (pipeline); |
| 98 | + |
| 99 | + return EXIT_SUCCESS; |
| 100 | +} |
0 commit comments