[gst-devel] problems deleting elements

Mike McLean libolt at libolt.net
Thu May 27 19:50:02 CEST 2004


Hi,

I'm writing an application that plays mp3s with a KDE interface and a 
gstreamer backend.  I'm using gstreamer 0.8.1.  I've gotten it to where I can 
play the mp3, however when it moves on to the next mp3 in the list I'm having 
trouble getting it to remove the element that was previously played.  So 
after a while ALSA dies with the following: 

ALSA lib pcm_hw.c:324:(snd_pcm_hw_hw_params) SNDRV_PCM_IOCTL_HW_PARAMS failed: 
Cannot allocate memory


The following code sets up the stream for playing:

int kgstreamer::setupStream(string *fileName)
{

	cout << "fileName = " << sizeof(&fileName) << endl;
//	int fileSize = sizeof(fileName);
//	char fileSource[300] = fileName;
	string test(*fileName);
	cout << "test = " << test << endl;
 	char* fileSource = new char[test.size()];
	strncpy(fileSource,"\0",1);
	strncpy(fileSource,test.c_str(),test.size() +1);
//	strncat(fileSource,"\0",1);
	GstElement *filesrc, *decoder, *audiosink;
	// GstElement *thread;
	string tmp("/home/libolt/mp3s/wire.mp3");
	char* temp = new char[tmp.size()];
  
  //strcpy(fileSource, tmp.c_str());
  //exit(0);

	if (!gstInited)
	{
  		gst_init (NULL,NULL);
		gstInited = true;
	}

//	gst_element_set_state (GST_ELEMENT (thread), GST_STATE_NULL);
//	gst_object_unref (GST_OBJECT (thread));

	/* create a new thread to hold the elements */
	thread = gst_thread_new ("thread");
	g_assert (thread != NULL);
	
	cout << "fileSource = " << fileSource << endl;
	/* create a disk reader */
	filesrc = gst_element_factory_make ("filesrc", "disk_source");
	g_assert (filesrc != NULL);
	g_object_set (G_OBJECT (filesrc), "location", fileSource, NULL);
	//exit(0);	
	
	varTest1 += 2;
	
	g_signal_connect (G_OBJECT (filesrc), "eos",
			G_CALLBACK (eos), thread);
	varTest2 += 1;
	/* create an ogg decoder */
	decoder = gst_element_factory_make ("mad", "decoder");
	g_assert (decoder != NULL);
	
	/* and an audio sink */
	audiosink = gst_element_factory_make ("alsasink", "play_audio");
	g_assert (audiosink != NULL);
	
	/* add objects to the thread */
	gst_bin_add_many (GST_BIN (thread), filesrc, decoder, audiosink, NULL);
	/* link them in the logical order */
	gst_element_link_many (filesrc, decoder, audiosink, NULL);
	
	cout << "Stream setup sucessfully" << endl;
}


I then play the stream by executing hte following function:

int kgstreamer::playStream(void) 
{  


  /* start playing */
  gst_element_set_state (GST_ELEMENT(thread), GST_STATE_PLAYING);

  /* do whatever you want here, the thread will be playing */
  g_print ("thread is playing\n");
  
  can_quit = TRUE;
//  gst_main ();

//  gst_object_unref (GST_OBJECT (thread));


  GstElementState state;
//  GstElement *element = src;
//  g_print ("have eos, quitting\n");

//  can_quit = TRUE;
//  exit(0);
  /* stop the bin */
  gst_element_get_state(GST_ELEMENT(thread));
  cout << "state playing = " << state << endl;


	return(0);
}


I also have an end of stream function for the callback:

void eos (GstElement *src, gpointer data) 
{
  GstThread *element = GST_THREAD (data);
  GstElementState state;
//  GstElement *element = src;
//  g_print ("have eos, quitting\n");

//  can_quit = TRUE;
//  exit(0);
  /* stop the bin */
//  gst_element_get_state(GST_ELEMENT(kgst.thread));
//  cout << "state = " << state << endl;
//  gst_element_set_state (GST_ELEMENT(element), GST_STATE_NULL);

// gst_object_unref (GST_OBJECT (element));

//	kgst.endOfStream = true;
//  while (!can_quit) /* waste cycles */ ;
//  gst_main_quit ();

//cout << "kgst.varTest1 = " << kgst.varTest1 << endl;
//cout << "kgst.varTest2 = " << kgst.varTest2 << endl;

//kgst.stopPlay();

cout << "ended stream" << endl;
  mainMenu main;
  main.changeStream();
}

if I enable the line:
gst_element_set_state (GST_ELEMENT(element), GST_STATE_NULL);

I get this error after an mp3 finishes playing:

(process:31844): GStreamer-WARNING **: Thread thread is destroying itself. 
Function call will not return!

I know I must be doing something fundamentally dumb but I can't figure out 
what it is.  Any help would be greatly appreciated.

Mike




More information about the gstreamer-devel mailing list