[gst-devel] gstreamer problem

sangita pithadia sangitapithadia at gmail.com
Tue Sep 25 14:18:19 CEST 2007


Hi,

I m trying to play MPEG TS using gstreamer pipeline.
This is the pipeline which i have used to playback the file. It works fine.

gst-launch -v filesrc
location=/root/GStremerDir/gstreamer-0.10.13/ed24p_00.ts !
ffdemux_mpegts ! ffdec_mpeg2video ! queue ! videoscale !
ffmpegcolorspace ! xvimagesink


Same thing i tried to do using the code but it doesnt play.
my code is like..

#include<stdio.h>#define SOURCE "filesrc"#define VSINK
"xvimagesink"#define ASINK "alsasink"#include <stdlib.h>#include
<glib.h>*//#include <gtk/gtk.h>*#include <gst/gst.h>#include
<string.h>
const gchar * location = "file:///root/GStremerDir/ed24p_00.ts";static
GList *seekable_pads = NULL;static GList *rate_pads = NULL;static
GstElement *pipeline;static GList *seekable_elements = NULL;*typedef*
*struct*
{
	const gchar *padname;
	GstPad *target;
	GstElement *bin;
}
dyn_link;
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 *err;

      gst_message_parse_error (msg, &err, &debug);
      g_free (debug);

      g_print ("Error: %s\n", err->message);
      g_error_free (err);

      g_main_loop_quit (loop);
      *break*;
    }
    *default*:
      *break*;
  }
}
static GstElement *
gst_element_factory_make_or_warn (gchar * type, gchar * name)
{
	GstElement *element = gst_element_factory_make (type, name);
	
	*if* (!element) {
	g_warning ("Failed to create element %s of type %s", name, type);
	}
	
	*return* element;
}static void dynamic_link (GstPadTemplate * templ, GstPad * newpad,
gpointer data)
{
	gchar *padname;
	dyn_link *connect = (dyn_link *) data;
	
	padname = gst_pad_get_name (newpad);
	
	*if* (connect->padname == NULL || !strcmp (padname, connect->padname)) {
	*if* (connect->bin)
	gst_bin_add (GST_BIN (pipeline), connect->bin);
	gst_pad_link (newpad, connect->target);
	
	seekable_pads = g_list_prepend (seekable_pads, newpad);
	rate_pads = g_list_prepend (rate_pads, newpad);
	}
	g_free (padname);
}
static void setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
{
	dyn_link *connect;
	
	connect = g_new0 (dyn_link, 1);
	connect->padname = g_strdup (padname);
	connect->target = target;
	connect->bin = bin;
	
	g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
	connect);
}int main(int argc,char *argv[])
{
	static GstElement *bin;	
	GstBus *bus;
	GMainLoop *loop;
	GstElement *pipeline, *audio_bin, *video_bin;
	GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
	GstElement *audiosink, *videosink;
	GstElement *a_queue, *v_queue, *v_scale;
	GstPad *seekable;
	GstPad *pad;
	
	gst_init (&argc, &argv);
	loop = g_main_loop_new (NULL, FALSE);
	*if* (argc != 2)
	{
   		g_print ("Usage: %s <AVI file>\n", argv[0]);
   		*return* -1;
  	}

	pipeline = gst_pipeline_new ("app");
	
	src = gst_element_factory_make_or_warn (SOURCE, "src");
	g_object_set (G_OBJECT (src), "location", argv[1], NULL);
	
	*//demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");*
	demux = gst_element_factory_make_or_warn ("ffdemux_mpegts", "demux");
	
	gst_bin_add (GST_BIN (pipeline), src);
	gst_bin_add (GST_BIN (pipeline), demux);
	gst_element_link (src, demux);
	
	audio_bin = gst_bin_new ("a_decoder_bin");
	a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
	a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
	audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
	gst_bin_add (GST_BIN (audio_bin), a_decoder);
	gst_bin_add (GST_BIN (audio_bin), a_queue);
	gst_bin_add (GST_BIN (audio_bin), audiosink);
	
	gst_element_link (a_decoder, a_queue);
	gst_element_link (a_queue, audiosink);
	
	gst_bin_add (GST_BIN (pipeline), audio_bin);
	
	pad = gst_element_get_pad (a_decoder, "sink");
	gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
	gst_object_unref (pad);
	
	setup_dynamic_link (demux, "audio_c0", gst_element_get_pad (audio_bin,
		"sink"), NULL);
	
	video_bin = gst_bin_new ("v_decoder_bin");
	v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
	v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
	v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
	v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
	videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
	
	gst_bin_add (GST_BIN (video_bin), v_decoder);
	gst_bin_add (GST_BIN (video_bin), v_queue);
	gst_bin_add (GST_BIN (video_bin), v_scale);
	gst_bin_add (GST_BIN (video_bin), v_filter);
	gst_bin_add (GST_BIN (video_bin), videosink);
	
	gst_element_link (v_decoder, v_queue);
	gst_element_link (v_queue, v_scale);
	gst_element_link (v_scale, v_filter);
	gst_element_link (v_filter, videosink);
	
	gst_bin_add (GST_BIN (pipeline), video_bin);
	
	pad = gst_element_get_pad (v_decoder, "sink");
	gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
	gst_object_unref (pad);
	
	setup_dynamic_link (demux, "video_e0", gst_element_get_pad (video_bin,
		"sink"), NULL);
	
	/*seekable = gst_element_get_pad (v_filter, "src");
	seekable_pads = g_list_prepend (seekable_pads, seekable);
	rate_pads = g_list_prepend (rate_pads, seekable);
	rate_pads =
	g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));*/

	bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  	gst_bus_add_watch (bus, bus_call, loop);
  	
	gst_element_set_state (pipeline, GST_STATE_PLAYING);
	*/* now run */*
	g_main_loop_run (loop);

	gst_element_set_state (pipeline, GST_STATE_NULL);
  	gst_object_unref (GST_OBJECT (pipeline));
	gst_object_unref (bus);
  	exit (0);
}


Can anyone tell me what can be the cause of this.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20070925/8c97b8cb/attachment.htm>


More information about the gstreamer-devel mailing list