<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: 'Gulim'; COLOR: #000000">
<DIV><FONT face=Gulim>Hi all,</FONT></DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim>As I¡¯m a begginer on gstreamer, I have faced some problem
in my application.</FONT></DIV>
<DIV><FONT face=Gulim>I made a play sound function using gstreamer 1.0 and it
worked fine.</FONT></DIV>
<DIV>But problem is, after finishing a sound play, there is some memory
leak.</DIV>
<DIV><FONT face=Gulim>Could you please check if my code there is something
wrong? FYI, gst_init() was called in main function at startup
stage.</FONT></DIV>
<DIV><FONT face=Gulim>play_sound was called from time to time as needed with
differenent source file.</FONT></DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim>BRs,</FONT></DIV>
<DIV>Peter.</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV>static GstElement *sound_pipeline;</DIV>
<DIV>static GMainLoop *loop;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV>static gboolean</DIV>
<DIV>music_bus_call (GstBus *bus,</DIV>
<DIV> GstMessage
*msg,</DIV>
<DIV>
gpointer data)</DIV>
<DIV>{</DIV>
<DIV> switch (GST_MESSAGE_TYPE (msg)) {</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> case GST_MESSAGE_EOS:</DIV>
<DIV> LOG ("End of stream\n");</DIV>
<DIV> g_main_loop_quit (loop);</DIV>
<DIV> break;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> case GST_MESSAGE_ERROR: {</DIV>
<DIV> gchar *debug;</DIV>
<DIV> GError *error;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> gst_message_parse_error (msg, &error,
&debug);</DIV>
<DIV> g_free (debug);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> LOG ("Error: %s\n",
error->message);</DIV>
<DIV> g_error_free (error);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> g_main_loop_quit (loop);</DIV>
<DIV> break;</DIV>
<DIV> }</DIV>
<DIV> default:</DIV>
<DIV> break;</DIV>
<DIV> }</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> return TRUE;</DIV>
<DIV>}</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV>static GstElement *converter, *sink;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV>static void</DIV>
<DIV>music_on_pad_added (GstElement *element,</DIV>
<DIV>
GstPad *pad,</DIV>
<DIV>
gpointer data)</DIV>
<DIV>{</DIV>
<DIV> GstPad *sinkpad;</DIV>
<DIV> GstCaps *caps;</DIV>
<DIV> GstStructure *str;</DIV>
<DIV> GstElement *conv = (GstElement *) data;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* We can now link this pad with the vorbis-decoder sink pad
*/</DIV>
<DIV> g_print ("Dynamic pad creating, linking decoder/converter\n");</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* check media type */</DIV>
<DIV> caps = gst_pad_query_caps (pad, NULL);</DIV>
<DIV> str = gst_caps_get_structure (caps, 0);</DIV>
<DIV> </DIV>
<DIV>if (g_strrstr (gst_structure_get_name (str), "audio")) {</DIV>
<DIV> sinkpad = gst_element_get_static_pad (conv,
"sink");</DIV>
<DIV> gst_pad_link(pad, sinkpad);</DIV>
<DIV> LOG("music_on_pad_added Linked \n");</DIV>
<DIV>}</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> gst_caps_unref (caps);</DIV>
<DIV> </DIV>
<DIV> gst_object_unref (sinkpad);</DIV>
<DIV> </DIV>
<DIV>}</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV>int</DIV>
<DIV>play_sound (char *soundfile)</DIV>
<DIV>{</DIV>
<DIV> GstElement *decoder;</DIV>
<DIV> GstBus *bus;</DIV>
<DIV> guint bus_watch_id;</DIV>
<DIV> int argc=1;</DIV>
<DIV> char *args[]={"ui-sound",""};</DIV>
<DIV> char **argv=args;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* Initialisation */</DIV>
<DIV> //gst_init (&argc, &argv);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> loop = g_main_loop_new (NULL, FALSE);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* Create gstreamer elements */</DIV>
<DIV> sound_pipeline = gst_pipeline_new ("audio-player");</DIV>
<DIV> decoder =
gst_element_factory_make( "uridecodebin", "uri-decode-bin" );</DIV>
<DIV> converter = gst_element_factory_make
("audioconvert", "converter");</DIV>
<DIV> sink = gst_element_factory_make
("autoaudiosink", "audio-output");</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> if (!sound_pipeline || !decoder || !converter || !sink) {</DIV>
<DIV> LOG ("PLAY_SOUND : One element could not be created.
Exiting.\n");</DIV>
<DIV> return -1;</DIV>
<DIV> }</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* Set up the pipeline */</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* we set the input filename to the source element */</DIV>
<DIV>g_object_set( G_OBJECT(decoder), "uri", soundfile, NULL );</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* we add a message handler */</DIV>
<DIV> bus = gst_pipeline_get_bus (GST_PIPELINE (sound_pipeline));</DIV>
<DIV> bus_watch_id = gst_bus_add_watch (bus, music_bus_call, loop);</DIV>
<DIV> gst_object_unref (bus);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim> </FONT>gst_bin_add_many (GST_BIN
(sound_pipeline),decoder, converter, sink, NULL);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> g_signal_connect( decoder, "pad-added",
G_CALLBACK(music_on_pad_added), converter );</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> GstCaps *caps = gst_caps_new_simple(
"audio/x-raw",</DIV>
<DIV>
"format", G_TYPE_STRING, "S16LE",</DIV>
<DIV>
NULL ); </DIV>
<DIV> if(!gst_element_link_filtered( converter, sink,
caps )) </DIV>
<DIV>
LOG("gst_element_link_filtered( converter, sink failed\n");;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> gst_caps_unref (caps);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> </DIV>
<DIV> /* Set the pipeline to "playing" state*/</DIV>
<DIV> LOG ("PLAY_SOUND : Now playing: %s\n", soundfile);</DIV>
<DIV> gst_element_set_state (sound_pipeline, GST_STATE_PLAYING);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* Iterate */</DIV>
<DIV> LOG ("Sound Running...\n");</DIV>
<DIV> g_main_loop_run (loop);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> /* Out of the main loop, clean up nicely */</DIV>
<DIV> LOG ("Returned, stopping playback\n");</DIV>
<DIV> gst_element_set_state (sound_pipeline, GST_STATE_NULL);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> LOG ("Deleting pipeline\n");</DIV>
<DIV> gst_object_unref (GST_OBJECT (sound_pipeline));</DIV>
<DIV> g_source_remove (bus_watch_id);</DIV>
<DIV> g_main_loop_unref (loop);</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> loop=NULL;</DIV>
<DIV> sound_pipeline=NULL;</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> //gst_deinit();</DIV>
<DIV><FONT face=Gulim></FONT> </DIV>
<DIV> return 0;</DIV>
<DIV>}</DIV>
<DIV><FONT face=Gulim></FONT> </DIV></DIV></DIV></BODY></HTML>
<table style="display:none"><tr><td><img src="http://kr1-mail.worksmobile.com/readReceipt/notify/?img=CQnmKAgmKAumKoudFAtqKAushAM9axpzFA0VaxMdFq3Vtou%2FKoIu3xE9Kx2mFqJuKutrtu9xLx%2FspXFdb4kCW6kZ76kRM4kvpzkvtzwGbX3q74pZp6kvpBFO%2Bzem74eZpm%3D%3D.gif" border="0"></td></tr></table>