From e56c5f8e6939a1b79deb401b7e1fcd129e488d77 Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Sat, 28 Mar 2009 18:42:42 -0500
Subject: Print out the plugins gstreamer finds, for debugging.

---
 linden/indra/llmedia/llmediaimplgstreamer.cpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

(limited to 'linden/indra/llmedia')

diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp
index 5d4d553..d661f74 100644
--- a/linden/indra/llmedia/llmediaimplgstreamer.cpp
+++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp
@@ -178,6 +178,21 @@ bool LLMediaImplGStreamer::startup (LLMediaManagerData* init_data)
 		// Init our custom plugins - only really need do this once.
 		gst_slvideo_init_class();
 
+
+		// List the plugins GStreamer can find
+		LL_DEBUGS("MediaImpl") << "Found GStreamer plugins:" << LL_ENDL;
+		GList *list;
+		GstRegistry *registry = gst_registry_get_default();
+		for (list = gst_registry_get_plugin_list(registry);
+		     list != NULL;
+		     list = g_list_next(list))
+		{	 
+			GstPlugin *list_plugin = (GstPlugin *)list->data;
+			LL_DEBUGS("MediaImpl") << gst_plugin_get_name(list_plugin) << LL_ENDL;
+		}
+		gst_plugin_list_free(list);
+
+
 		done_init = true;
 	}
 	return true;
-- 
cgit v1.1


From 6542894a75f826203cab1ae482fdf5187be09205 Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Sat, 28 Mar 2009 18:53:52 -0500
Subject: Moved Windows GST_PLUGIN_PATH setup to LLMediaImplGStreamer.

LLAppViewer::gst_plugin_path -->
   LLMediaImplGStreamer::set_gst_plugin_path
---
 linden/indra/llmedia/llmediaimplgstreamer.cpp | 27 +++++++++++++++++++++++++++
 linden/indra/llmedia/llmediaimplgstreamer.h   |  4 ++++
 2 files changed, 31 insertions(+)

(limited to 'linden/indra/llmedia')

diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp
index d661f74..ed7b36e 100644
--- a/linden/indra/llmedia/llmediaimplgstreamer.cpp
+++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp
@@ -164,6 +164,8 @@ bool LLMediaImplGStreamer::startup (LLMediaManagerData* init_data)
 		// Init the glib type system - we need it.
 		g_type_init();
 
+		set_gst_plugin_path();
+
 		// Protect against GStreamer resetting the locale, yuck.
 		static std::string saved_locale;
 		saved_locale = setlocale(LC_ALL, NULL);
@@ -199,6 +201,31 @@ bool LLMediaImplGStreamer::startup (LLMediaManagerData* init_data)
 }
 
 
+void LLMediaImplGStreamer::set_gst_plugin_path()
+{
+#ifdef LL_WINDOWS
+	char* buffer;
+
+	// Get the current working directory: 
+	if((buffer = _getcwd(NULL,0)) == NULL)
+	{
+		LL_INFOS("InitInfo") << "_getcwd error" << LL_ENDL;
+	}
+	else
+	{
+		LL_INFOS("InitInfo") << "Imprudence is installed at " << buffer << LL_ENDL;
+		
+		std::string plugin_path = "GST_PLUGIN_PATH=" + std::string(buffer) + "\\lib\\gstreamer-plugins";
+
+		// Place GST_PLUGIN_PATH in the environment settings for imprudence.exe
+		const char* gst_plugin_path = plugin_path.c_str();
+		putenv(gst_plugin_path);
+		LL_INFOS("InitInfo") << "GST_PLUGIN_PATH set to " << getenv("GST_PLUGIN_PATH") << LL_ENDL;
+	}
+#endif //LL_WINDOWS
+}
+
+
 bool LLMediaImplGStreamer::closedown()
 {
 	return true;
diff --git a/linden/indra/llmedia/llmediaimplgstreamer.h b/linden/indra/llmedia/llmediaimplgstreamer.h
index dec970a..2918416 100644
--- a/linden/indra/llmedia/llmediaimplgstreamer.h
+++ b/linden/indra/llmedia/llmediaimplgstreamer.h
@@ -66,6 +66,9 @@ class LLMediaImplGStreamer:
 		static bool startup( LLMediaManagerData* init_data );
 		static bool closedown();
 
+		// Sets GST_PLUGIN_PATH env var for GStreamer.
+		static void set_gst_plugin_path();
+
 		/* virtual */ std::string getVersion();
 		/* virtual */ bool navigateTo( const std::string url );
 		/* virtual */ bool updateMedia();
@@ -79,6 +82,7 @@ class LLMediaImplGStreamer:
 	        LLMediaEmitter< LLMediaObserver > getEventEmitter() const {return mEventEmitter;};
 
 	private:
+
         	// misc
 	        bool unload();
 	        bool pause();
-- 
cgit v1.1


From 9538403155fdc574c8562cdaedbeb09fbdcff55e Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Sat, 28 Mar 2009 19:29:40 -0500
Subject: Improved set_gst_plugin_path, more comprehensive path.

Also tried to tidy up a bit.
---
 linden/indra/llmedia/llmediaimplgstreamer.cpp | 47 ++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 9 deletions(-)

(limited to 'linden/indra/llmedia')

diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp
index ed7b36e..0cc1e8f 100644
--- a/linden/indra/llmedia/llmediaimplgstreamer.cpp
+++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp
@@ -203,25 +203,54 @@ bool LLMediaImplGStreamer::startup (LLMediaManagerData* init_data)
 
 void LLMediaImplGStreamer::set_gst_plugin_path()
 {
+	// Only needed for Windows.
+	// Linux sets in wrapper.sh, Mac sets in Info-Imprudence.plist
 #ifdef LL_WINDOWS
-	char* buffer;
+
+	char* imp_cwd;
 
 	// Get the current working directory: 
-	if((buffer = _getcwd(NULL,0)) == NULL)
+	imp_cwd = _getcwd(NULL,0);
+
+	if(imp_cwd == NULL)
 	{
-		LL_INFOS("InitInfo") << "_getcwd error" << LL_ENDL;
+		LL_DEBUGS("LLMediaImpl") << "_getcwd failed, not setting GST_PLUGIN_PATH."
+		                         << LL_ENDL;
 	}
 	else
 	{
-		LL_INFOS("InitInfo") << "Imprudence is installed at " << buffer << LL_ENDL;
-		
-		std::string plugin_path = "GST_PLUGIN_PATH=" + std::string(buffer) + "\\lib\\gstreamer-plugins";
+		LL_DEBUGS("LLMediaImpl") << "Imprudence is installed at "
+		                         << buffer << LL_ENDL;
+
+		// Grab the current path, if it's set.
+		std::string old_plugin_path = "";
+		char *old_path = getenv("GST_PLUGIN_PATH");
+		if(old_path == NULL)
+		{
+			LL_DEBUGS("LLMediaImpl") << "Did not find user-set GST_PLUGIN_PATH."
+			                         << LL_ENDL;
+		}
+		else
+		{
+			old_plugin_path = std::string( old_path ) + ":";
+		}
+
+
+		// Search both Imprudence and Imprudence\lib\gstreamer-plugins.
+		// But we also want to first search the path the user has set, if any.
+		std::string plugin_path =
+		  "GST_PLUGIN_PATH=" +
+		  old_plugin_path +
+		  std::string(imp_cwd) + ":" + 
+		  std::string(imp_cwd) + "\\lib\\gstreamer-plugins";
 
 		// Place GST_PLUGIN_PATH in the environment settings for imprudence.exe
-		const char* gst_plugin_path = plugin_path.c_str();
-		putenv(gst_plugin_path);
-		LL_INFOS("InitInfo") << "GST_PLUGIN_PATH set to " << getenv("GST_PLUGIN_PATH") << LL_ENDL;
+		putenv( plugin_path.c_str() );
+
+		LL_DEBUGS("LLMediaImpl") << "GST_PLUGIN_PATH set to "
+		                         << getenv("GST_PLUGIN_PATH") << LL_ENDL;
 	}
+
 #endif //LL_WINDOWS
 }
 
-- 
cgit v1.1


From 0779047440604c5c5ecfd685803059b763a29325 Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Sat, 28 Mar 2009 19:43:35 -0500
Subject: Fixed some minor mistakes in set_gst_plugin_path().

---
 linden/indra/llmedia/llmediaimplgstreamer.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'linden/indra/llmedia')

diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp
index 0cc1e8f..9a51b7f 100644
--- a/linden/indra/llmedia/llmediaimplgstreamer.cpp
+++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp
@@ -220,7 +220,7 @@ void LLMediaImplGStreamer::set_gst_plugin_path()
 	else
 	{
 		LL_DEBUGS("LLMediaImpl") << "Imprudence is installed at "
-		                         << buffer << LL_ENDL;
+		                         << imp_cwd << LL_ENDL;
 
 		// Grab the current path, if it's set.
 		std::string old_plugin_path = "";
@@ -245,7 +245,7 @@ void LLMediaImplGStreamer::set_gst_plugin_path()
 		  std::string(imp_cwd) + "\\lib\\gstreamer-plugins";
 
 		// Place GST_PLUGIN_PATH in the environment settings for imprudence.exe
-		putenv( plugin_path.c_str() );
+		putenv( (char*)plugin_path.c_str() );
 
 		LL_DEBUGS("LLMediaImpl") << "GST_PLUGIN_PATH set to "
 		                         << getenv("GST_PLUGIN_PATH") << LL_ENDL;
-- 
cgit v1.1


From c7aedac540588fe86a25da77d18608d237fbb130 Mon Sep 17 00:00:00 2001
From: McCabe Maxsted
Date: Sun, 29 Mar 2009 22:44:29 -0700
Subject: Added loading info to log's plugin list, set_gst_plugin_path now
 compiles for windows

---
 linden/indra/llmedia/llmediaimplgstreamer.cpp | 36 +++++++++++++++++----------
 1 file changed, 23 insertions(+), 13 deletions(-)

(limited to 'linden/indra/llmedia')

diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp
index debc95c..3c4d0a0 100644
--- a/linden/indra/llmedia/llmediaimplgstreamer.cpp
+++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp
@@ -48,6 +48,8 @@ extern "C" {
 
 #if LL_WINDOWS
 	#pragma warning(default : 4244)
+#include <direct.h>
+#include <stdlib.h>
 #endif
 
 #include "llmediamanager.h"
@@ -196,12 +198,14 @@ bool LLMediaImplGStreamer::startup (LLMediaManagerData* init_data)
 		LL_DEBUGS("MediaImpl") << "Found GStreamer plugins:" << LL_ENDL;
 		GList *list;
 		GstRegistry *registry = gst_registry_get_default();
+		std::string loaded = "";
 		for (list = gst_registry_get_plugin_list(registry);
 		     list != NULL;
 		     list = g_list_next(list))
 		{	 
 			GstPlugin *list_plugin = (GstPlugin *)list->data;
-			LL_DEBUGS("MediaImpl") << gst_plugin_get_name(list_plugin) << LL_ENDL;
+			(bool)gst_plugin_is_loaded(list_plugin) ? loaded = "Yes" : loaded = "No";
+			LL_DEBUGS("MediaImpl") << gst_plugin_get_name(list_plugin) << ", loaded? " << loaded << LL_ENDL;
 		}
 		gst_plugin_list_free(list);
 
@@ -225,12 +229,12 @@ void LLMediaImplGStreamer::set_gst_plugin_path()
 
 	if(imp_cwd == NULL)
 	{
-		LL_DEBUGS("LLMediaImpl") << "_getcwd failed, not setting GST_PLUGIN_PATH."
+		LL_DEBUGS("MediaImpl") << "_getcwd failed, not setting GST_PLUGIN_PATH."
 		                         << LL_ENDL;
 	}
 	else
 	{
-		LL_DEBUGS("LLMediaImpl") << "Imprudence is installed at "
+		LL_DEBUGS("MediaImpl") << "Imprudence is installed at "
 		                         << imp_cwd << LL_ENDL;
 
 		// Grab the current path, if it's set.
@@ -238,28 +242,34 @@ void LLMediaImplGStreamer::set_gst_plugin_path()
 		char *old_path = getenv("GST_PLUGIN_PATH");
 		if(old_path == NULL)
 		{
-			LL_DEBUGS("LLMediaImpl") << "Did not find user-set GST_PLUGIN_PATH."
+			LL_DEBUGS("MediaImpl") << "Did not find user-set GST_PLUGIN_PATH."
 			                         << LL_ENDL;
 		}
 		else
 		{
-			old_plugin_path = std::string( old_path ) + ":";
+			old_plugin_path = ";" + std::string( old_path );
 		}
 
 
 		// Search both Imprudence and Imprudence\lib\gstreamer-plugins.
-		// But we also want to first search the path the user has set, if any.
+		// If those fail, search the path the user has set, if any.
 		std::string plugin_path =
 		  "GST_PLUGIN_PATH=" +
-		  old_plugin_path +
-		  std::string(imp_cwd) + ":" + 
-		  std::string(imp_cwd) + "\\lib\\gstreamer-plugins";
+		  std::string(imp_cwd) + "\\lib\\gstreamer-plugins;" +
+		  std::string(imp_cwd) +
+		  old_plugin_path;
 
 		// Place GST_PLUGIN_PATH in the environment settings for imprudence.exe
-		putenv( (char*)plugin_path.c_str() );
-
-		LL_DEBUGS("LLMediaImpl") << "GST_PLUGIN_PATH set to "
-		                         << getenv("GST_PLUGIN_PATH") << LL_ENDL;
+		// Returns 0 on success
+		if(_putenv( (char*)plugin_path.c_str() ))
+		{	
+			LL_WARNS("MediaImpl") << "Setting environment variable failed!" << LL_ENDL;
+		}
+		else
+		{
+			LL_DEBUGS("MediaImpl") << "GST_PLUGIN_PATH set to "
+									 << getenv("GST_PLUGIN_PATH") << LL_ENDL;
+		}
 	}
 
 #endif //LL_WINDOWS
-- 
cgit v1.1


From b145debcba6af423e990fddea6430ea414a37e06 Mon Sep 17 00:00:00 2001
From: McCabe Maxsted
Date: Mon, 30 Mar 2009 01:56:18 -0700
Subject: removed gst_element_get_state

---
 linden/indra/llmedia/llmediaimplgstreamer.cpp | 74 ++++++++++++++++-----------
 1 file changed, 45 insertions(+), 29 deletions(-)

(limited to 'linden/indra/llmedia')

diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp
index 3c4d0a0..952e22f 100644
--- a/linden/indra/llmedia/llmediaimplgstreamer.cpp
+++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp
@@ -653,20 +653,23 @@ bool LLMediaImplGStreamer::stop()
 	if (!mPlaybin || mState == GST_STATE_NULL)
 		return true;
 
-	GstElement *pipeline = (GstElement *)gst_object_ref(GST_OBJECT(mPlaybin));
-	gst_object_unref(pipeline);
-	
-	gst_element_set_state(pipeline, GST_STATE_READY);
+	GstStateChangeReturn state_change;
 
-	if (mState == GST_STATE_PLAYING)
-		mState = GST_STATE_VOID_PENDING;
-	else
-		mState = GST_STATE_READY; 
+	state_change = gst_element_set_state(mPlaybin, GST_STATE_READY);
 
-	GstStateChangeReturn state_change = gst_element_get_state(mPlaybin, NULL, NULL, GST_MSECOND*5);
-	LL_DEBUGS("MediaImpl") << "get_state: " << gst_element_state_change_return_get_name(state_change) << LL_ENDL;
+	LL_DEBUGS("MediaImpl") << "result: " 
+							<< gst_element_state_change_return_get_name(state_change) << LL_ENDL;
 
-	return true;
+	if (state_change == GST_STATE_CHANGE_FAILURE)
+	{
+		LL_WARNS("MediaImpl") << "could not stop stream!" << LL_ENDL;
+		return false;
+	}
+	else
+	{
+		mState = GST_STATE_READY;
+		return true;
+	}
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -678,25 +681,28 @@ bool LLMediaImplGStreamer::play()
 	if (!mPlaybin || mState == GST_STATE_NULL)
 		return true;
 
-	GstElement *pipeline = (GstElement *)gst_object_ref(GST_OBJECT(mPlaybin));
-	gst_object_unref(pipeline);
-	
-	gst_element_set_state(pipeline, GST_STATE_PLAYING);
-	mState = GST_STATE_PLAYING;
-	/*gst_element_set_state(mPlaybin, GST_STATE_PLAYING);
-	mState = GST_STATE_PLAYING;*/
+	GstStateChangeReturn state_change;
+
+	state_change = gst_element_set_state(mPlaybin, GST_STATE_PLAYING);
 
-	GstStateChangeReturn state_change = gst_element_get_state(mPlaybin, NULL, NULL, GST_MSECOND*5);
-	LL_DEBUGS("MediaImpl") << "get_state: " << gst_element_state_change_return_get_name(state_change) << LL_ENDL;
+	LL_DEBUGS("MediaImpl") << "result: " 
+							<< gst_element_state_change_return_get_name(state_change) << LL_ENDL;
 
 	// Check to make sure playing was successful. If not, stop.
+	// NOTE: state_change is almost always GST_STATE_CHANGE_ASYNC
 	if (state_change == GST_STATE_CHANGE_FAILURE)
 	{
-		setStatus(LLMediaBase::STATUS_STOPPED);
+		// If failing from a bad stream, go into pending state
+		// (this is stopped at the callback)
+		mState = GST_STATE_VOID_PENDING;
 		stop();
+		return false;
+	}
+	else
+	{
+		mState = GST_STATE_PLAYING;
+		return true;
 	}
-
-	return true;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -708,13 +714,23 @@ bool LLMediaImplGStreamer::pause()
 	if (!mPlaybin || mState == GST_STATE_NULL)
 		return true;
 
-	gst_element_set_state(mPlaybin, GST_STATE_PAUSED);
-	mState = GST_STATE_PAUSED;
-	
-	GstStateChangeReturn state_change = gst_element_get_state(mPlaybin, NULL, NULL, GST_MSECOND*5);
-	LL_DEBUGS("MediaImpl") << "get_state: " << gst_element_state_change_return_get_name(state_change) << LL_ENDL;
+	GstStateChangeReturn state_change;
 
-	return true;
+	state_change = gst_element_set_state(mPlaybin, GST_STATE_PAUSED);
+
+	LL_DEBUGS("MediaImpl") << "result: " 
+							<< gst_element_state_change_return_get_name(state_change) << LL_ENDL;
+
+	if (state_change == GST_STATE_CHANGE_FAILURE)
+	{
+		LL_WARNS("MediaImpl") << "could not pause stream!" << LL_ENDL;
+		return false;
+	}
+	else
+	{
+		mState = GST_STATE_PAUSED;
+		return true;
+	}
 };
 
 
-- 
cgit v1.1