[gst-devel] Converting pipeline to C

Gabriel Duarte confusosk8 at gmail.com
Wed Oct 28 03:18:29 CET 2009


On Wed, Oct 28, 2009 at 12:12 AM, Gabriel Duarte <confusosk8 at gmail.com>wrote:

> sorry, I sent the wrong code, this is the right:
>
>  #include <gst/gst.h>
> #include <glib.h>
>
>
> static gboolean
> cb_print_position (GstElement *pipeline)
> {
>   GstFormat fmt = GST_FORMAT_TIME;
>   gint64 pos, len;
>
>   if (gst_element_query_position (pipeline, &fmt, &pos)
>     && gst_element_query_duration (pipeline, &fmt, &len)) {
>     g_print ("Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "\r",
>      GST_TIME_ARGS (pos), GST_TIME_ARGS (len));
>   }
>
>   /* call me again */
>   return TRUE;
> }
>
>
>
> 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);
> }
>
>
>
> int
> main (int   argc,
>       char *argv[])
> {
>   GMainLoop *loop;
>
>   GstElement *pipeline, *source, *demuxer, *decoder, *sink;
>   GstBus *bus;
>
>   /* 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;
>   }*/
>
> /*gst-launch-0.10 dv1394src num-buffers=8192 ! dvdemux ! dvdec !
> xvimagesink  sync=false*/
>   /* Create gstreamer elements */
>   pipeline = gst_pipeline_new ("DV_FIREWIRE");
>   source   = gst_element_factory_make ("dv1394src",       "dv1394src");
>   demuxer  = gst_element_factory_make ("dvdemux",      "dvdemux");
>   decoder  = gst_element_factory_make ("dvdec",     "dvdec");
>   sink     = gst_element_factory_make ("ximagesink", "ximagesink");
>
>   if (!pipeline || !source || !demuxer || !decoder || !sink) {
>     g_printerr ("One element could not be created. Exiting.\n");
>     return -1;
>   }
>
>   /* Set up the pipeline */
>
>   /* we set the input filename to the source element */
>   /*g_object_set (G_OBJECT (sink), "sync", FALSE, NULL);*/
>
>   /* we add a message handler */
>   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
>   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 (pipeline), source, demuxer, decoder, sink,
> NULL);
>
>   /* we link the elements together */
>   /* file-source -> ogg-demuxer ~> vorbis-decoder -> converter ->
> alsa-output */
>   /*  gst_element_link (source, demuxer);*/
>   gst_element_link_many (source, demuxer, decoder, sink,  NULL);
>   g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added),
> decoder);
>
>   /* note that the demuxer will be linked to the decoder dynamically.
>      The reason is that Ogg may contain various streams (for example
>      audio and video). The source pad(s) will be created at run time,
>      by the demuxer when it detects the amount and nature of streams.
>      Therefore we connect a callback function which will be executed
>      when the "pad-added" is emitted.*/
>
>
>   /* Set the pipeline to "playing" state*/
>   g_print ("Now playing: %s\n", argv[1]);
>   gst_element_set_state (pipeline, GST_STATE_PLAYING);
>
>
>   /* Iterate */
>   g_print ("Running...\n");
>   g_timeout_add (200, (GSourceFunc) cb_print_position, pipeline);
>   g_main_loop_run (loop);
>
>
>   /* Out of the main loop, clean up nicely */
>   g_print ("Returned, stopping playback\n");
>   gst_element_set_state (pipeline, GST_STATE_NULL);
>
>   g_print ("Deleting pipeline\n");
>   gst_object_unref (GST_OBJECT (pipeline));
>  printf("THE END\n");
>   return 0;
> }
>
>
> On Tue, Oct 27, 2009 at 8:24 PM, Gabriel Duarte <confusosk8 at gmail.com>wrote:
>
>> hello all, I'm trying to convert this pipeline to C, but I'm having
>> problems....
>>
>>
>> gst-launch-0.10 dv1394src num-buffers=8192 ! dvdemux ! dvdec ! xvimagesink
>>  sync=false
>>
>>
>> I've wrote this code:
>>
>>
>> #include <string.h> /* for memset () */
>> #include <gst/gst.h>
>>
>> static void
>> cb_handoff (GstElement *fakesrc,
>> 	    GstBuffer  *buffer,
>> 	    GstPad     *pad,
>> 	    gpointer    user_data)
>> {
>>   static gboolean white = FALSE;
>>
>>   /* this makes the image black/white */
>>   memset (GST_BUFFER_DATA (buffer), white ? 0xff : 0x0,
>> 	  GST_BUFFER_SIZE (buffer));
>>   white = !white;
>> }
>>
>> gint
>> main (gint   argc,
>>       gchar *argv[])
>> {
>>   GstElement *pipeline, *fakesrc, *flt, *conv, *videosink;
>>   GMainLoop *loop;
>>
>>   /* init GStreamer */
>>   gst_init (&argc, &argv);
>>   loop = g_main_loop_new (NULL, FALSE);
>>
>>   /* setup pipeline */
>>   pipeline = gst_pipeline_new ("pipeline");
>>   fakesrc = gst_element_factory_make ("fakesrc", "source");
>>   flt = gst_element_factory_make ("capsfilter", "flt");
>>   conv = gst_element_factory_make ("ffmpegcolorspace", "conv");
>>   videosink = gst_element_factory_make ("xvimagesink", "videosink");
>>
>>   /* setup */
>>   g_object_set (G_OBJECT (flt), "caps",
>>   		gst_caps_new_simple ("video/x-raw-rgb",
>> 				     "width", G_TYPE_INT, 384,
>> 				     "height", G_TYPE_INT, 288,
>> 				     "framerate", GST_TYPE_FRACTION, 1, 1,
>> 				     "bpp", G_TYPE_INT, 16,
>> 				     "depth", G_TYPE_INT, 16,
>> 				     "endianness", G_TYPE_INT, G_BYTE_ORDER,
>> 				     NULL), NULL);
>>   gst_bin_add_many (GST_BIN (pipeline), fakesrc, flt, conv, videosink, NULL);
>>   gst_element_link_many (fakesrc, flt, conv, videosink, NULL);
>>
>>   /* setup fake source */
>>   g_object_set (G_OBJECT (fakesrc),
>> 		"signal-handoffs", TRUE,
>> 		"sizemax", 384 * 288 * 2,
>> 		"sizetype", 2, NULL);
>>   g_signal_connect (fakesrc, "handoff", G_CALLBACK (cb_handoff), NULL);
>>
>>   /* play */
>>   gst_element_set_state (pipeline, GST_STATE_PLAYING);
>>   g_main_loop_run (loop);
>>
>>   /* clean up */
>>   gst_element_set_state (pipeline, GST_STATE_NULL);
>>   gst_object_unref (GST_OBJECT (pipeline));
>>
>>   return 0;
>> }
>>
>>
>>
>> Any ideas???
>>
>> Best regards :D
>>
>>
>>
>>
>>
>>
>> --
>> Gabriel Duarte
>> Linux User #471185
>> Rio de Janeiro - RJ
>> http://kinuxlinux.org/gabriel_duarte
>>
>> Phones:
>> (55) (21) 9463-7760 /*Mobile*/
>> (55) (21) 2464-9302 /*Home*/
>> (55) (21) 2529-5080 /*Work*/
>>
>>
>> -----BEGIN GEEK CODE BLOCK-----
>> Version: 3.12
>> GCS d- s: a--- C++ UL+++ P L++++ E- W+ N++ o++ K++ w---
>> O- M- V- PS++ PE++ Y PGP- t++ 5-- X+++ R tv++ b++ DI+ D++
>> G++ e+ h* r+ y++++
>> ------END GEEK CODE BLOCK------
>>
>
>
>
> --
> Gabriel Duarte
> Linux User #471185
> Rio de Janeiro - RJ
> http://kinuxlinux.org/gabriel_duarte
>
> Phones:
> (55) (21) 9463-7760 /*Mobile*/
> (55) (21) 2464-9302 /*Home*/
> (55) (21) 2529-5080 /*Work*/
>
>
> -----BEGIN GEEK CODE BLOCK-----
> Version: 3.12
> GCS d- s: a--- C++ UL+++ P L++++ E- W+ N++ o++ K++ w---
> O- M- V- PS++ PE++ Y PGP- t++ 5-- X+++ R tv++ b++ DI+ D++
> G++ e+ h* r+ y++++
> ------END GEEK CODE BLOCK------
>



-- 
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://kinuxlinux.org/gabriel_duarte

Phones:
(55) (21) 9463-7760 /*Mobile*/
(55) (21) 2464-9302 /*Home*/
(55) (21) 2529-5080 /*Work*/


-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s: a--- C++ UL+++ P L++++ E- W+ N++ o++ K++ w---
O- M- V- PS++ PE++ Y PGP- t++ 5-- X+++ R tv++ b++ DI+ D++
G++ e+ h* r+ y++++
------END GEEK CODE BLOCK------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20091028/acca5f00/attachment.htm>


More information about the gstreamer-devel mailing list