Advertisement
Guest User

Untitled

a guest
Jun 11th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.62 KB | None | 0 0
  1. #include <gst/gst.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     GstElement *pipeline, *libcamera_src, *convert, *convert_2, *sink, *sink_2;
  6.     GstBus *bus;
  7.     GstMessage *msg;
  8.     GstStateChangeReturn ret;
  9.  
  10.     /* Initialize GStreamer */
  11.     gst_init(&argc, &argv);
  12.  
  13.     /* Create the elements */
  14.     libcamera_src = gst_element_factory_make("libcamerasrc", "libcamera");
  15.     convert = gst_element_factory_make("videoconvert", "convert");
  16.     // convert_2 = gst_element_factory_make("videoconvert", "convert_2");
  17.  
  18.     sink = gst_element_factory_make("autovideosink", "sink");
  19.     // sink_2 = gst_element_factory_make("autovideosink", "sink_2");
  20.  
  21.     /* Create the empty pipeline */
  22.     pipeline = gst_pipeline_new("test-pipeline");
  23.  
  24.     if (!pipeline || !sink || !libcamera_src || !convert)
  25.     {
  26.         g_printerr("Not all elements could be created.\n");
  27.         return -1;
  28.     }
  29.  
  30.     /* Build the pipeline */
  31.     gst_bin_add_many(GST_BIN(pipeline), libcamera_src, convert, sink, NULL);
  32.     if (gst_element_link_many(libcamera_src, convert, sink, NULL) != TRUE)
  33.     {
  34.         g_printerr("Elements could not be linked (1).\n");
  35.         gst_object_unref(pipeline);
  36.         return -1;
  37.     }
  38.  
  39.     GstPad *req = gst_element_get_request_pad(libcamera_src, "src_1");
  40.     if (req == NULL)
  41.         g_print("null\n");
  42.     else
  43.         g_print("fine\n");
  44.  
  45.     // if (gst_element_link_many(libcamera_src, convert_2, sink_2, NULL) != TRUE)
  46.     // {
  47.         // g_printerr("Elements could not be linked (2).\n");
  48.         // gst_object_unref(pipeline);
  49.         // return -1;
  50.     // }
  51. //
  52.     // GstPad* sink_pad = gst_element_get_static_pad(sink_2, "sink");
  53.     // if (gst_pad_link (req, sink_pad) != GST_PAD_LINK_OK)
  54.     // {
  55.         // g_printerr ("pad could not be linked.\n");
  56.         // gst_object_unref (pipeline);
  57.         // return -1;
  58.     // }
  59.     // gst_object_unref(sink_pad);
  60.  
  61.     /* Start playing */
  62.     ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
  63.     if (ret == GST_STATE_CHANGE_FAILURE)
  64.     {
  65.         g_printerr("Unable to set the pipeline to the playing state.\n");
  66.         gst_object_unref(pipeline);
  67.         return -1;
  68.     }
  69.  
  70.     g_object_set(libcamera_src, "camera-name" , "\\_SB_.PCI0.XHC_.RHUB.HS07-7:1.0-0408:a060", NULL);
  71.  
  72.     /* Wait until error or EOS */
  73.     bus = gst_element_get_bus(pipeline);
  74.     msg =
  75.         gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
  76.                                    GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
  77.  
  78.     /* Parse message */
  79.     if (msg != NULL)
  80.     {
  81.         GError *err;
  82.         gchar *debug_info;
  83.  
  84.         switch (GST_MESSAGE_TYPE(msg))
  85.         {
  86.         case GST_MESSAGE_ERROR:
  87.             gst_message_parse_error(msg, &err, &debug_info);
  88.             g_printerr("Error received from element %s: %s\n",
  89.                        GST_OBJECT_NAME(msg->src), err->message);
  90.             g_printerr("Debugging information: %s\n",
  91.                        debug_info ? debug_info : "none");
  92.             g_clear_error(&err);
  93.             g_free(debug_info);
  94.             break;
  95.         case GST_MESSAGE_EOS:
  96.             g_print("End-Of-Stream reached.\n");
  97.             break;
  98.         default:
  99.             /* We should not reach here because we only asked for ERRORs and EOS */
  100.             g_printerr("Unexpected message received.\n");
  101.             break;
  102.         }
  103.         gst_message_unref(msg);
  104.     }
  105.  
  106.     /* Free resources */
  107.     // gst_element_release_request_pad(libcamera_src, req);
  108.     // gst_object_unref(req);
  109.  
  110.     gst_object_unref(bus);
  111.     gst_element_set_state(pipeline, GST_STATE_NULL);
  112.     gst_object_unref(pipeline);
  113.     return 0;
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement