Gsteamer Memory Leak?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi all,
 
As I’m a begginer on gstreamer, I have faced some problem in my application.
I made a play sound function using gstreamer 1.0 and it worked fine.
But problem is, after finishing a sound play, there is some memory leak.
Could you please check if my code there is something wrong?  FYI, gst_init() was called in main function at startup stage.
play_sound was called from time to time as needed with differenent source file.
 
BRs,
Peter.
 
 
 
static GstElement *sound_pipeline;
static GMainLoop *loop;
 
 
static gboolean
music_bus_call (GstBus     *bus,
          GstMessage *msg,
          gpointer    data)
{
  switch (GST_MESSAGE_TYPE (msg)) {
 
    case GST_MESSAGE_EOS:
      LOG ("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);
 
      LOG ("Error: %s\n", error->message);
      g_error_free (error);
 
      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }
 
  return TRUE;
}
 
static GstElement  *converter, *sink;
 
 
static void
music_on_pad_added (GstElement *element,
              GstPad     *pad,
              gpointer    data)
{
  GstPad *sinkpad;
  GstCaps *caps;
  GstStructure *str;
  GstElement *conv = (GstElement *) data;
 
  /* We can now link this pad with the vorbis-decoder sink pad */
  g_print ("Dynamic pad creating, linking decoder/converter\n");
 
  /* check media type */
  caps = gst_pad_query_caps (pad, NULL);
  str = gst_caps_get_structure (caps, 0);
if (g_strrstr (gst_structure_get_name (str), "audio")) {
      sinkpad = gst_element_get_static_pad (conv, "sink");
       gst_pad_link(pad, sinkpad);
     LOG("music_on_pad_added Linked \n");
}
 
 
  gst_caps_unref (caps);
  gst_object_unref (sinkpad);
}
 
 
int
play_sound (char *soundfile)
{
  GstElement *decoder;
  GstBus *bus;
  guint bus_watch_id;
  int argc=1;
  char *args[]={"ui-sound",""};
  char **argv=args;
 
 
  /* Initialisation */
  //gst_init (&argc, &argv);
 
  loop = g_main_loop_new (NULL, FALSE);
 
  /* Create gstreamer elements */
  sound_pipeline = gst_pipeline_new ("audio-player");
  decoder         = gst_element_factory_make( "uridecodebin", "uri-decode-bin" );
  converter     = gst_element_factory_make ("audioconvert",  "converter");
  sink     = gst_element_factory_make ("autoaudiosink", "audio-output");
 
  if (!sound_pipeline || !decoder || !converter || !sink) {
    LOG ("PLAY_SOUND : 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(decoder), "uri", soundfile, NULL );
 
 
  /* we add a message handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (sound_pipeline));
  bus_watch_id = gst_bus_add_watch (bus, music_bus_call, loop);
  gst_object_unref (bus);
 
  gst_bin_add_many (GST_BIN (sound_pipeline),decoder, converter, sink, NULL);
 
 
   g_signal_connect( decoder, "pad-added", G_CALLBACK(music_on_pad_added), converter );
 
 
    GstCaps *caps = gst_caps_new_simple( "audio/x-raw",
                                         "format", G_TYPE_STRING, "S16LE",
                                         NULL );    
     if(!gst_element_link_filtered( converter, sink, caps ))
          LOG("gst_element_link_filtered( converter, sink failed\n");;
 
   gst_caps_unref (caps);
 
  /* Set the pipeline to "playing" state*/
  LOG ("PLAY_SOUND : Now playing: %s\n", soundfile);
  gst_element_set_state (sound_pipeline, GST_STATE_PLAYING);
 
 
  /* Iterate */
  LOG ("Sound Running...\n");
  g_main_loop_run (loop);
 
 
  /* Out of the main loop, clean up nicely */
  LOG  ("Returned, stopping playback\n");
  gst_element_set_state (sound_pipeline, GST_STATE_NULL);
 
  LOG  ("Deleting pipeline\n");
  gst_object_unref (GST_OBJECT (sound_pipeline));
  g_source_remove (bus_watch_id);
  g_main_loop_unref (loop);
 
  loop=NULL;
  sound_pipeline=NULL;
 
  //gst_deinit();
 
  return 0;
}
 
_______________________________________________
gstreamer-embedded mailing list
gstreamer-embedded@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/gstreamer-embedded

[Index of Archives]     [Linux Embedded]     [Linux ARM Kernel]     [Linux for ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux Media]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux