#include <gst/gst.h>
void on_pad_added (GstElement *element, GstPad *pad, gpointer data){
gst_element_link_pads(element, gst_pad_get_name(pad), GST_ELEMENT(data), "sink");
}
int main(int argc, char *argv[]) {
GstElement *pipeline, *audio_source, *tee, *audio_queue, *audio_convert, *audio_resample, *audio_sink;
GstElement *video_queue, *visual, *video_convert, *video_sink, *video_source, *video_depay, *video_parse, *video_decode;
GstElement *audio_depay, *audio_decode;
GstBus *bus;
GstMessage *msg;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
audio_source = gst_element_factory_make ("rtspsrc", "audio_source");
audio_depay = gst_element_factory_make("rtppcmudepay", "audio_depay");
audio_decode = gst_element_factory_make("mulawdec", "audio_decode");
audio_queue = gst_element_factory_make ("queue", "audio_queue");
audio_convert = gst_element_factory_make ("audioconvert", "audio_convert");
audio_resample = gst_element_factory_make ("audioresample", "audio_resample");
audio_sink = gst_element_factory_make ("autoaudiosink", "audio_sink");
video_queue = gst_element_factory_make ("queue", "video_queue");
video_convert = gst_element_factory_make ("videoconvert", "video_convert");
video_sink = gst_element_factory_make ("autovideosink", "video_sink");
video_source = gst_element_factory_make("rtspsrc", "video_source");
video_depay = gst_element_factory_make("rtph264depay", "video_depay");
video_parse = gst_element_factory_make("h264parse", "h264parse");
video_decode = gst_element_factory_make("vaapih264dec", "hw_h264_decode");
/* Create the empty pipeline */
pipeline = gst_pipeline_new ("test-pipeline");
if (!pipeline || !audio_source || !tee || !audio_queue || !audio_convert || !audio_resample || !audio_sink ||
!video_queue || !visual || !video_convert || !video_sink) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
/* Configure elements */
/* Link all elements that can be automatically linked because they have "Always" pads */
gst_bin_add_many (GST_BIN (pipeline), audio_source, audio_queue, audio_convert, audio_resample, audio_sink,
audio_depay, audio_decode, NULL);
gst_bin_add_many (GST_BIN (pipeline), video_queue, video_convert, video_sink, video_source, video_depay, video_parse, video_decode, NULL);
if (gst_element_link_many (video_queue, video_depay, video_parse, video_decode, video_convert, video_sink, NULL) != TRUE) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}
if (gst_element_link_many (audio_queue, audio_depay, audio_decode, audio_convert, audio_resample, audio_sink, NULL) != TRUE) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}
g_signal_connect(video_source, "pad-added", G_CALLBACK(on_pad_added), video_queue);
g_signal_connect(audio_source, "pad-added", G_CALLBACK(on_pad_added), audio_queue);
g_object_set(G_OBJECT(video_source), "location", "rtsp://192.168.50.246", "user-id","admin", "user-pw","admin12345",NULL);
g_object_set(G_OBJECT(audio_source), "location", "rtsp://192.168.50.246", "user-id","admin", "user-pw","admin12345",NULL);
/* Start playing the pipeline */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* 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);
/* Free resources */
if (msg != NULL)
gst_message_unref (msg);
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}