Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- int main(int argc, char *argv[])
- {
- GstElement *pipeline, *libcamera_src, *convert, *convert_2, *sink, *sink_2;
- GstBus *bus;
- GstMessage *msg;
- GstStateChangeReturn ret;
- /* Initialize GStreamer */
- gst_init(&argc, &argv);
- /* Create the elements */
- libcamera_src = gst_element_factory_make("libcamerasrc", "libcamera");
- convert = gst_element_factory_make("videoconvert", "convert");
- // convert_2 = gst_element_factory_make("videoconvert", "convert_2");
- sink = gst_element_factory_make("autovideosink", "sink");
- // sink_2 = gst_element_factory_make("autovideosink", "sink_2");
- /* Create the empty pipeline */
- pipeline = gst_pipeline_new("test-pipeline");
- if (!pipeline || !sink || !libcamera_src || !convert)
- {
- g_printerr("Not all elements could be created.\n");
- return -1;
- }
- /* Build the pipeline */
- gst_bin_add_many(GST_BIN(pipeline), libcamera_src, convert, sink, NULL);
- if (gst_element_link_many(libcamera_src, convert, sink, NULL) != TRUE)
- {
- g_printerr("Elements could not be linked (1).\n");
- gst_object_unref(pipeline);
- return -1;
- }
- GstPad *req = gst_element_get_request_pad(libcamera_src, "src_1");
- if (req == NULL)
- g_print("null\n");
- else
- g_print("fine\n");
- // if (gst_element_link_many(libcamera_src, convert_2, sink_2, NULL) != TRUE)
- // {
- // g_printerr("Elements could not be linked (2).\n");
- // gst_object_unref(pipeline);
- // return -1;
- // }
- //
- // GstPad* sink_pad = gst_element_get_static_pad(sink_2, "sink");
- // if (gst_pad_link (req, sink_pad) != GST_PAD_LINK_OK)
- // {
- // g_printerr ("pad could not be linked.\n");
- // gst_object_unref (pipeline);
- // return -1;
- // }
- // gst_object_unref(sink_pad);
- /* Start playing */
- ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE)
- {
- g_printerr("Unable to set the pipeline to the playing state.\n");
- gst_object_unref(pipeline);
- return -1;
- }
- g_object_set(libcamera_src, "camera-name" , "\\_SB_.PCI0.XHC_.RHUB.HS07-7:1.0-0408:a060", NULL);
- /* Wait until error or EOS */
- bus = gst_element_get_bus(pipeline);
- msg =
- gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
- GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
- /* Parse message */
- if (msg != NULL)
- {
- GError *err;
- gchar *debug_info;
- switch (GST_MESSAGE_TYPE(msg))
- {
- case GST_MESSAGE_ERROR:
- gst_message_parse_error(msg, &err, &debug_info);
- g_printerr("Error received from element %s: %s\n",
- GST_OBJECT_NAME(msg->src), err->message);
- g_printerr("Debugging information: %s\n",
- debug_info ? debug_info : "none");
- g_clear_error(&err);
- g_free(debug_info);
- break;
- case GST_MESSAGE_EOS:
- g_print("End-Of-Stream reached.\n");
- break;
- default:
- /* We should not reach here because we only asked for ERRORs and EOS */
- g_printerr("Unexpected message received.\n");
- break;
- }
- gst_message_unref(msg);
- }
- /* Free resources */
- // gst_element_release_request_pad(libcamera_src, req);
- // gst_object_unref(req);
- gst_object_unref(bus);
- gst_element_set_state(pipeline, GST_STATE_NULL);
- gst_object_unref(pipeline);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement