Hi,
I'm building a pipeline in c with rtspsrc. I want to access the stats property in the rtpsession object created internally with rtspsrc. Is this possible? This is my code for now: #include <gst/gst.h> #include <glib.h> typedef struct myDataTag { GstElement *pipeline; GstElement *source; GstElement *depayloader; GstElement *decoder; GstElement *sink; } myData_t; static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: g_print ("End of stream\n"); g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR: { gchar *debug; GError *error; gst_message_parse_error (msg, &error, &debug); g_free (debug); g_printerr ("Error: %s\n", error->message); g_error_free (error); g_main_loop_quit (loop); break; } default: break; } return TRUE; } static void on_pad_added (GstElement *element, GstPad *pad, gpointer data) { GstPad *sinkpad; GstElement *decoder = (GstElement *) data; /* We can now link this pad with the vorbis-decoder sink pad */ g_print ("Dynamic pad created, linking demuxer/decoder\n"); sinkpad = gst_element_get_static_pad (decoder, "sink"); gst_pad_link (pad, sinkpad); gst_object_unref (sinkpad); } /* pad added handler */ static void pad_added_handler (GstElement *src, GstPad *new_pad, myData_t *pThis) { GstPad *sink_pad = gst_element_get_static_pad (pThis->depayloader, "sink"); GstPadLinkReturn ret; GstCaps *new_pad_caps = NULL; GstStructure *new_pad_struct = NULL; const gchar *new_pad_type = NULL; g_print ("Received new pad '%s' from '%s':\n", GST_PAD_NAME (new_pad), GST_ELEMENT_NAME (src)); /* Check the new pad's name */ if (!g_str_has_prefix (GST_PAD_NAME (new_pad), "recv_rtp_src_")) { g_print (" It is not the right pad. Need recv_rtp_src_. Ignoring.\n"); goto exit; } /* If our converter is already linked, we have nothing to do here */ if (gst_pad_is_linked (sink_pad)) { g_print (" Sink pad from %s already linked. Ignoring.\n", GST_ELEMENT_NAME (src)); goto exit; } /* Check the new pad's type */ new_pad_caps = gst_pad_query_caps (new_pad, NULL); new_pad_struct = gst_caps_get_structure (new_pad_caps, 0); new_pad_type = gst_structure_get_name (new_pad_struct); /* Attempt the link */ ret = gst_pad_link (new_pad, sink_pad); if (GST_PAD_LINK_FAILED (ret)) { g_print (" Type is '%s' but link failed.\n", new_pad_type); } else { g_print (" Link succeeded (type '%s').\n", new_pad_type); } exit: /* Unreference the new pad's caps, if we got them */ if (new_pad_caps != NULL) gst_caps_unref (new_pad_caps); /* Unreference the sink pad */ gst_object_unref (sink_pad); } int main (int argc, char *argv[]) { argv[0] = "gstreamer-test"; argv[1] = "rtsp://ipadress/axis-media/media.amp"; //argv[2] = "para2"; myData_t appData; GMainLoop *loop; GstElement *rtpbin; GstBus *bus; guint bus_watch_id; GstStructure *stats; /* Initialisation */ gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); /* Check input arguments */ if (argc != 2) { g_printerr ("Usage: %s <Ogg/Vorbis filename>\n", argv[0]); return -1; } /* Create gstreamer elements */ appData.pipeline = gst_pipeline_new ("pipeline"); appData.source = gst_element_factory_make ("rtspsrc", "rtspsrc"); g_object_set (G_OBJECT (appData.source), "location", "rtsp://root:spiideo2017@10.0.3.69/axis-media/media.amp", NULL); appData.depayloader = gst_element_factory_make ("rtph264depay","depayloader"); appData.decoder = gst_element_factory_make ("avdec_h264", "avh264decoder"); appData.sink = gst_element_factory_make ("autovideosink", "sink"); if (!appData.pipeline || !appData.source || !appData.depayloader || !appData.decoder || !appData.sink) { g_printerr ("One element could not be created. Exiting.\n"); return -1; } g_signal_connect (appData.source, "pad-added", G_CALLBACK (pad_added_handler), &appData); /* Set up the pipeline */ /* we set the input filename to the source element */ g_object_set (G_OBJECT (appData.source), "location", argv[1], NULL); /* we add a message handler */ bus = gst_pipeline_get_bus (GST_PIPELINE (appData.pipeline)); bus_watch_id = gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); /* we add all elements into the pipeline */ /* file-source | ogg-demuxer | vorbis-decoder | converter | alsa-output */ gst_bin_add_many (GST_BIN (appData.pipeline), appData.source, appData.depayloader, appData.decoder, appData.sink, NULL); /* we link the elements together */ /* file-source -> ogg-demuxer ~> vorbis-decoder -> converter -> alsa-output */ gst_element_link_many (appData.depayloader, appData.decoder, appData.sink, NULL); g_signal_connect (appData.source, "pad-added", G_CALLBACK (pad_added_handler), &appData); /* Set the pipeline to "playing" state*/ g_print ("Now playing: %s\n", argv[1]); gst_element_set_state (appData.pipeline, GST_STATE_PLAYING); /* Iterate */ g_print ("Running...\n"); g_main_loop_run (loop); /* Out of the main loop, clean up nicely */ g_print ("Returned, stopping playback\n"); gst_element_set_state (appData.pipeline, GST_STATE_NULL); g_print ("Deleting pipeline\n"); gst_object_unref (GST_OBJECT (appData.pipeline)); g_source_remove (bus_watch_id); g_main_loop_unref (loop); return 0; -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |