kde app with a gstreamer backend

Mike McLean libolt at libolt.net
Wed Jun 2 05:42:36 BST 2004


Hi Ronald,

Ok I'm posting what I hope is the relevent code from my program.

// main 

int main(int argc, char **argv)
{
    KAboutData about("Kmuzikbox", I18N_NOOP("KmuzikBox"), version,
description, KAboutData::License_GPL, "(C) 2004 Mike McLean", 0, 0,
"libolt at libolt.net");
    about.addAuthor( "Mike McLean", 0, "libolt at libolt.net" );
    KCmdLineArgs::init(argc, argv, &about);
    KCmdLineArgs::addCmdLineOptions( options );
    KApplication app;

   /* if (app.isRestored())
    {
        RESTORE(SigCreate);
    }
    else*/
     {
        // no session.. just start up normally
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

        /// @todo do something with the command line args here

        mainWin = new mainMenu();
	app.setMainWidget( mainWin );
        mainWin->show();
//	mainWin->checkState();
//	mainWin->changeStream();
	args->clear();
    }
    // mainWin has WDestructiveClose flag by default, so it will delete
itself.
    return app.exec();
}


// creates the stream for playing and sets up gstreamer

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 *thread;
	string tmp("/home/libolt/mp3s/wire.mp3");
	char* temp = new char[tmp.size()];  

	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;
}

// Plays the stream

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;

	return(0);
}

// End of Stream callback


void kgstreamer::eos ( GstElement*, GstElement*) 
{
 
 QTimer::singleShot( 0, pObject, SLOT( stopPlay() ) );

	kgst.endOfStream = true;

cout << "ended stream" << endl;

}

// stops the stream.

void kgstreamer::stopPlay(void)
{

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

// function to play the stream when the play button is pressed.

void mainMenu::pushButton()
{
	cout << "doh" << endl;
	int x = 0;
	QString fileurl = "dah";
	 QString msg=QString(kgst.fileNameOpened.path());
	cout << "File Opened" << msg << endl;
	cout << "current item = " << fileList->currentItem() << endl;
	cout << "current text = " << fileList->currentText() << endl;
	
	if (!kgst.setupDone)
	{
		string fileName = "/home/libolt/mp3s/wire.mp3";
		kgst.setupStream(&kgst.playListArray[fileList->currentItem()]);
		cout << "current item = " << fileList->currentItem();
		kgst.currentItemPlaying = fileList->currentItem();
		kgst.setupDone = true;
	}
	kgst.playStream();
}


Hope this helps.  Thanks again,

Mike

On Tue, 2004-06-01 at 14:08, Ronald S. Bultje wrote:
> Hey Mike,
> 
> On Wed, 2004-06-02 at 00:44, Mike McLean wrote:
> > I've added the following line to my eos callback:
> > 
> >  QTimer::singleShot( 0, pObject, SLOT( stopPlay() ) );  
> > 
> > Yet I am having a problem figuring out where the main application thread
> > is so that i can stop the stream and start a new one.
> 
> I need more code and context in order to say anything useful here. ;).
> However, the timeout is the right way to handle it, yes.
> 
> Ronald
> _______________________________________________
> kde-multimedia mailing list
> kde-multimedia at kde.org
> https://mail.kde.org/mailman/listinfo/kde-multimedia



More information about the kde-multimedia mailing list