#include #include static gboolean recording = FALSE; static GMainLoop *loop; static GstElement *pipeline1, *pipeline2; static gboolean message_cb (GstBus * bus, GstMessage * message, gpointer user_data) { switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ERROR:{ GError *err = NULL; gchar *name, *debug = NULL; name = gst_object_get_path_string (message->src); gst_message_parse_error (message, &err, &debug); g_printerr ("ERROR: from element %s: %s\n", name, err->message); if (debug != NULL) g_printerr ("Additional debug info:\n%s\n", debug); g_error_free (err); g_free (debug); g_free (name); g_main_loop_quit (loop); break; } case GST_MESSAGE_WARNING:{ GError *err = NULL; gchar *name, *debug = NULL; name = gst_object_get_path_string (message->src); gst_message_parse_warning (message, &err, &debug); g_printerr ("ERROR: from element %s: %s\n", name, err->message); if (debug != NULL) g_printerr ("Additional debug info:\n%s\n", debug); g_error_free (err); g_free (debug); g_free (name); break; } case GST_MESSAGE_EOS:{ g_print ("Got EOS\n"); g_main_loop_quit (loop); gst_element_set_state (pipeline1, GST_STATE_NULL); g_main_loop_unref (loop); gst_object_unref (pipeline1); exit(0); break; } default: break; } return TRUE; } void startRecording() { GstBus *bus2; GstMessage *msg2; g_print("startRecording\n"); pipeline2 = gst_parse_launch ("videotestsrc is-live=true ! nvvidconv ! video/x-raw(memory:NVMM),width=852,height=480 ! nvivafilter customer-lib-name=libnvsample_cudaprocess.so cuda-process=true ! videorate ! nvv4l2h265enc ! h265parse ! qtmux name=muxer ! filesink location=/tmp/cuda.mp4 audiotestsrc is-live=true ! queue ! audioconvert ! audioresample ! avenc_aac ! muxer.", NULL); gst_element_set_state (pipeline2, GST_STATE_PLAYING); g_print("Starting Pipeline2"); recording = TRUE; bus2 = gst_element_get_bus (pipeline2); msg2 = gst_bus_timed_pop_filtered (bus2, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); if (GST_MESSAGE_TYPE (msg2) == GST_MESSAGE_ERROR) { g_error ("An error occured with Pipeline2"); } gst_message_unref (msg2); gst_object_unref (bus2); gst_element_set_state (pipeline2, GST_STATE_NULL); gst_object_unref (pipeline2); } void stopRecording() { g_print("stopRecording\n"); gst_element_send_event(pipeline2, gst_event_new_eos()); recording = FALSE; } int sigintHandler(int unused) { g_print("You ctrl-c-ed!"); if (recording) stopRecording(); else startRecording(); return 0; } int main (int argc, char *argv[]) { GstBus *bus; GstMessage *msg; signal(SIGINT, sigintHandler); /* Initialize Gstreamer */ gst_init (&argc, &argv); /* Build the pipeline */ pipeline1 = gst_parse_launch ("videotestsrc is-live=true ! nvvidconv ! video/x-raw(memory:NVMM),width=852,height=480 ! nvivafilter customer-lib-name=libnvsample_cudaprocess.so cuda-process=true ! videorate ! nvv4l2h264enc insert-sps-pps=1 idrinterval=4 ! rtspclientsink location=rtsp://localhost:8554/mystream", NULL); /* Start playing */ gst_element_set_state (pipeline1, GST_STATE_PLAYING); startRecording(); g_print("Starting camera"); bus = gst_element_get_bus (pipeline1); msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) { g_error ("An error occured with v4l2"); } gst_message_unref (msg); gst_object_unref (bus); gst_element_set_state (pipeline1, GST_STATE_NULL); gst_object_unref (pipeline1); loop = g_main_loop_new(NULL, FALSE); bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline1)); gst_bus_add_signal_watch(bus); g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(message_cb), NULL); return 0; }