rendered paste body#include <gst/gst.h>
#define AUDIO_Z
#define VIDEO_Z
static GMainLoop *loop;
GstElement *pipeline, *source, *abin, *vbin, *vsink, *vqueue, *video_decoder, *identity, *colorspace, *videoscale;
GstElement *audiodepay, *videodepay, *asink, *aconv, *ascale, *audio_decoder, *volume, *aqueue;
static void
new_pad (GstElement *element, GstPad *pad, gpointer data)
{
GstPad *sinkpad=NULL;
GstCaps *caps;
GstStructure *s;
const gchar *mediatype;
caps = gst_pad_get_caps(pad);
g_print (" \n setting caps of rtspsrc \n %" GST_PTR_FORMAT, caps);
s= gst_caps_get_structure(caps,0);
mediatype = gst_structure_get_string(s,"media");
g_print("\n mediatype= %s \n",mediatype);
#ifdef VIDEO_Z
if(!strcmp(mediatype,"video"))
{
g_print("\nEntered video loop\n");
sinkpad = gst_element_get_pad (vbin, "sink");
if(sinkpad != NULL)
{
gst_pad_link (pad, sinkpad);
}
else
g_print("sink pad not existing\n");
gst_object_unref (sinkpad);
}
#endif
#ifdef AUDIO_Z
if(!strcmp(mediatype,"audio"))
{
g_print("\nEntered audio loop\n");
sinkpad = gst_element_get_pad (abin, "sink");
if(sinkpad != NULL)
{
gst_pad_link (pad, sinkpad);
}
else
g_print("sink pad not existing\n");
gst_object_unref (sinkpad);
}
#endif
}
int
main (int argc, char *argv[])
{
GstPad *pad;
gst_init(&argc, &argv);
pipeline = gst_pipeline_new (NULL);
g_assert (pipeline);
source = gst_element_factory_make("rtspsrc", "source");
g_assert (source);
g_object_set (G_OBJECT (source),"location" ,argv[1],NULL);
g_signal_connect (source, "pad-added", G_CALLBACK (new_pad), NULL);
gst_bin_add (GST_BIN (pipeline), source);
#ifdef AUDIO_Z
audiodepay = gst_element_factory_make ("rtpamrdepay", "adepay");
g_assert (audiodepay);
audio_decoder = gst_element_factory_make ("amrnbdec", "audio_dec");
g_assert (audio_decoder);
aconv = gst_element_factory_make ("audioconvert", "aconv");
g_assert (aconv);
aqueue = gst_element_factory_make ("queue", "aqueue");
g_assert (aqueue);
asink = gst_element_factory_make ("alsasink", "asink");
g_assert (asink);
//g_object_set (asink, "sync", FALSE, NULL);
abin = gst_bin_new("abin");
g_assert(abin);
gst_bin_add_many (GST_BIN (abin), audiodepay, audio_decoder, aconv, aqueue, asink, NULL);
gst_element_link_many(audiodepay, audio_decoder, aconv, aqueue, asink, NULL);
pad = gst_element_get_pad (audiodepay, "sink");
gst_element_add_pad (abin, gst_ghost_pad_new ("sink", pad));
gst_object_unref (pad);
#endif
#ifdef VIDEO_Z
videodepay = gst_element_factory_make ("rtpmp4vdepay", "vdepay");
g_assert (videodepay);
video_decoder = gst_element_factory_make ("ffdec_mpeg4", "video_dec");
g_assert (video_decoder);
colorspace = gst_element_factory_make ("ffmpegcolorspace", "colorspace");
g_assert (colorspace);
videoscale = gst_element_factory_make ("videoscale", "vscale");
g_assert (videoscale);
vqueue = gst_element_factory_make ("queue", "vqueue");
g_assert (vqueue);
vsink = gst_element_factory_make ("xvimagesink", "vsink");
g_assert (vsink);
//g_object_set (vsink, "sync", FALSE, NULL);
vbin = gst_bin_new("vbin");
g_assert(vbin);
gst_bin_add_many (GST_BIN(vbin), videodepay, video_decoder, colorspace, videoscale, vqueue, vsink, NULL);
gst_element_link_many(videodepay, video_decoder, colorspace, videoscale, vqueue, vsink, NULL);
pad = gst_element_get_pad (videodepay, "sink");
gst_element_add_pad (vbin, gst_ghost_pad_new ("sink", pad));
gst_object_unref (pad);
#endif
#ifdef AUDIO_Z
gst_bin_add(GST_BIN (pipeline), abin);
#endif
#ifdef VIDEO_Z
gst_bin_add(GST_BIN (pipeline), vbin);
#endif
gst_element_set_state (pipeline, GST_STATE_PLAYING);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
return 0;
}