[gst-devel] Fwd: Help...

Edward Hervey bilboed at gmail.com
Tue Jul 17 10:40:17 CEST 2007


Forwarding to the list so more people.can help
---------- Forwarded message ----------
From: Madhu T S <tsmadhu at gmail.com>
Date: Jul 16, 2007 5:36 PM
Subject: Help...
To: edward at fluendo.com




Hi Edward,
                      I have been trying to synchronize audio,video
using decodebin pulgin for quite some time, but in vain.Below is the
piece of code, which I am trying to run:

#include <gst/gst.h>

static gboolean my_bus_callback(GstBus *bus,GstMessage *msg,gpointer data)
{
   GMainLoop *loop = 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 = NULL;
              GError *err = NULL;

              gst_message_parse_error (msg, &err, &debug);
              g_print ("Error: %s\n", err->message);
              g_error_free (err);
              g_main_loop_quit (loop);
              break;
          }
          default:
              break;
    }

    return(TRUE);
}

void  new_pad (GstElement *element, GstPad *pad, gpointer ptr)
{
        printf ("new-pad %s\n", GST_PAD_NAME (pad));

        GstCaps *caps;
        GstStructure *str;

        caps = gst_pad_get_caps (pad);
        g_assert (caps != NULL);

        str = gst_caps_get_structure (caps, 0);
        g_assert (str != NULL);

        if (g_strrstr (gst_structure_get_name (str), "video"))
        {
            printf ("+ Linking %s to video queue\n", GST_PAD_NAME (pad));
            gst_pad_link (pad, gst_element_get_pad (VideoQueue, "sink"));
        }

        if (g_strrstr (gst_structure_get_name (str), "audio"))
        {
            printf ("Linking %s to audio queue\n", GST_PAD_NAME (pad));
            gst_pad_link (pad, gst_element_get_pad (AudioQueue,"sink"));
        }

        gst_caps_unref (caps);
}

gint main (gint argc,gchar *argv[])
{
  GMainLoop *loop;
  GstElement *src,*dec,*VideoQueue,*VIdentity,*csp,vsink;
  GstElement *AudioQueue,*AIdentity,*conv,*AudioResample,*asink;
  GstPad *videopad,*audiopad;
  /* init GStreamer */
  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);
  /* make sure we have input */
  if (argc != 2)
  {
    g_print ("Usage: %s <filename>\n", argv[0]);
    return -1;
  }
  /* setup */
  pipeline = gst_pipeline_new ("pipeline");
  gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE
(pipeline)),my_bus_callback, loop);
  src = gst_element_factory_make ("filesrc", "source");
  g_object_set (G_OBJECT (src), "location", argv[1], NULL);
  dec = gst_element_factory_make ("decodebin", "decoder");
  g_signal_connect (G_OBJECT (DecodeBin), "pad-added",G_CALLBACK
(new_pad), DecodeBin);
  gst_bin_add_many (GST_BIN (pipeline), src, dec, NULL);
  gst_element_link (src, dec);
  /* create video output */
  video = gst_bin_new ("videobin");
  VideoQueue = gst_element_factory_make ("queue","VideoQueue");
  VIdentity = gst_element_factory_make ("identity", "VIdentity");
  csp = gst_element_factory_make ("ffmpegcolorspace", "csp");
  videopad = gst_element_get_pad (VideoQueue,"sink");
  vsink = gst_element_factory_make ("xvimagesink","sink");
  gst_bin_add_many (GST_BIN (video),VideoQueue,VIdentity,csp,vsink, NULL);
  gst_element_link_many (VideoQueue,VIdentity,csp,vsink);
  gst_element_add_pad (video,gst_ghost_pad_new ("sink",videopad));
  gst_object_unref (videopad);
  gst_bin_add (GST_BIN (pipeline), video);

  /* create audio output */
  audio = gst_bin_new ("audiobin");
  AudioQueue = gst_element_factory_make ("queue", "AudioQueue");
  AIdentity = gst_element_factory_make ("identity","AIdentity");
  conv = gst_element_factory_make ("audioconvert", "aconv");
  audiopad = gst_element_get_pad (AudioQueue,"sink");
  AudioResample = gst_element_factory_make ("audioresample", "AudioResample");
  asink = gst_element_factory_make ("alsasink","sink");
  gst_bin_add_many (GST_BIN
(audio),AudioQueue,AIdentity,conv,AudioResample,asink,NULL);
  gst_element_link_many(AudioQueue,AIdentity,conv,AudioResample,asink);
  gst_element_add_pad (audio,gst_ghost_pad_new ("sink",audiopad));
  gst_object_unref (audiopad);
  gst_bin_add (GST_BIN (pipeline), audio);
  /* run */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  g_print ("Running ...\n");
  g_main_loop_run (loop);
  /* cleanup */
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (GST_OBJECT (pipeline));
  return 0;
}

but not able to run successfully...please help to fix this problem.
 Looking forward for your help.

With Regards,
Madhu.T.S



-- 
Edward Hervey
Multimedia editing developer
http://www.pitivi.org/




More information about the gstreamer-devel mailing list