From 88b7e23cebcb943aa2ce160512f4ff7afe3797a5 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sat, 4 Apr 2009 00:08:19 -0500 Subject: Refactored the heart of the GST play code to startPlay(). --- linden/indra/llmedia/llmediaimplgstreamer.cpp | 11 +++++++---- linden/indra/llmedia/llmediaimplgstreamer.h | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'linden') diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp index 532ec00..2ba33a1 100644 --- a/linden/indra/llmedia/llmediaimplgstreamer.cpp +++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp @@ -713,13 +713,18 @@ bool LLMediaImplGStreamer::play() if (!mPlaybin || mState == GST_STATE_NULL) return true; + startPlay(); + + return true; +} + +void LLMediaImplGStreamer::startPlay() +{ 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 = gst_element_get_state(mPlaybin, NULL, NULL, GST_CLOCK_TIME_NONE); LL_DEBUGS("MediaImpl") << "get_state: " << gst_element_state_change_return_get_name(state_change) << LL_ENDL; @@ -730,8 +735,6 @@ bool LLMediaImplGStreamer::play() setStatus(LLMediaBase::STATUS_STOPPED); stop(); } - - return true; } /////////////////////////////////////////////////////////////////////////////// diff --git a/linden/indra/llmedia/llmediaimplgstreamer.h b/linden/indra/llmedia/llmediaimplgstreamer.h index 37eaf53..be4b3c0 100644 --- a/linden/indra/llmedia/llmediaimplgstreamer.h +++ b/linden/indra/llmedia/llmediaimplgstreamer.h @@ -96,6 +96,9 @@ class LLMediaImplGStreamer: /* virtual */ bool seek( double time ); /* virtual */ bool setVolume( float volume ); + void startPlay(); + + LLMediaEmitter< LLMediaObserver > getEventEmitter() const {return mEventEmitter;}; private: -- cgit v1.1 From 428b32da98c9343b3f02d7da66c4af232b1c4376 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sun, 5 Apr 2009 02:22:49 -0500 Subject: Added LLGstPlayThread class. --- linden/indra/llmedia/CMakeLists.txt | 2 ++ linden/indra/llmedia/llgstplaythread.cpp | 54 ++++++++++++++++++++++++++++ linden/indra/llmedia/llgstplaythread.h | 62 ++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 linden/indra/llmedia/llgstplaythread.cpp create mode 100644 linden/indra/llmedia/llgstplaythread.h (limited to 'linden') diff --git a/linden/indra/llmedia/CMakeLists.txt b/linden/indra/llmedia/CMakeLists.txt index 0440153..0e5b261 100644 --- a/linden/indra/llmedia/CMakeLists.txt +++ b/linden/indra/llmedia/CMakeLists.txt @@ -31,6 +31,7 @@ set(llmedia_SOURCE_FILES llmediamanager.cpp llmediaimplgstreamer.cpp llmediaimplgstreamervidplug.cpp + llgstplaythread.cpp ) set(llmedia_HEADER_FILES @@ -47,6 +48,7 @@ set(llmedia_HEADER_FILES llmediaobserver.h llmediaimplgstreamer.h llmediaimplgstreamervidplug.h + llgstplaythread.h ) # Work around a bad interaction between broken gstreamer headers and diff --git a/linden/indra/llmedia/llgstplaythread.cpp b/linden/indra/llmedia/llgstplaythread.cpp new file mode 100644 index 0000000..152f9d9 --- /dev/null +++ b/linden/indra/llmedia/llgstplaythread.cpp @@ -0,0 +1,54 @@ +/** + * @file llgstplaythread.cpp + * @author Jacek Antonelli + * @brief GStreamer playback management thread class + * + * $LicenseInfo:firstyear=2009&license=viewergpl$ + * + * Copyright (c) 2009, Jacek Antonelli + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * $/LicenseInfo$ + */ + +#include "llgstplaythread.h" +#include "llmediaimplgstreamer.h" + +LLGstPlayThread:: +LLGstPlayThread( LLMediaImplCommon *impl, + const std::string& name, apr_pool_t *poolp ): + LLThread( name, poolp ), + mMediaImpl( impl ) +{ +} + + +LLGstPlayThread::~LLGstPlayThread() +{ +} + + +// virtual +void LLGstPlayThread::run() +{ + ((LLMediaImplGStreamer *)mMediaImpl)->startPlay(); +} diff --git a/linden/indra/llmedia/llgstplaythread.h b/linden/indra/llmedia/llgstplaythread.h new file mode 100644 index 0000000..c3c36a7 --- /dev/null +++ b/linden/indra/llmedia/llgstplaythread.h @@ -0,0 +1,62 @@ +/** + * @file llgstplaythread.h + * @author Jacek Antonelli + * @brief GStreamer playback management thread class + * + * $LicenseInfo:firstyear=2009&license=viewergpl$ + * + * Copyright (c) 2009, Jacek Antonelli + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * $/LicenseInfo$ + */ + + +#ifndef LL_LLGSTPLAYTHREAD_H +#define LL_LLGSTPLAYTHREAD_H + +#include "linden_common.h" + +#include "llthread.h" +#include "llmediaimplcommon.h" + +class LLGstPlayThread: public LLThread +{ + public: + + LLGstPlayThread( LLMediaImplCommon *impl, + const std::string& name, apr_pool_t *poolp ); + + ~LLGstPlayThread(); + + virtual void run(); + + private: + + // Actually, this will really only be an LLMediaImplGStreamer. + // But we have to jump through some hoops to mutual pointer-holding. + // There may be a better way, but I don't have the motivation to find it. + LLMediaImplCommon *mMediaImpl; +}; + + +#endif // LL_LLGSTPLAYTHREAD_H -- cgit v1.1 From 15296967b6beec8e6f6c5ff4b7e8c274e5d05dca Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sun, 5 Apr 2009 23:41:16 -0500 Subject: LLMediaImplGStreamer creates new thread for playing. This keeps the viewer responsive while GStreamer does its thing. --- linden/indra/llmedia/llmediaimplgstreamer.cpp | 27 +++++++++++++++++++++------ linden/indra/llmedia/llmediaimplgstreamer.h | 3 +++ 2 files changed, 24 insertions(+), 6 deletions(-) (limited to 'linden') diff --git a/linden/indra/llmedia/llmediaimplgstreamer.cpp b/linden/indra/llmedia/llmediaimplgstreamer.cpp index 2ba33a1..c8f793d 100644 --- a/linden/indra/llmedia/llmediaimplgstreamer.cpp +++ b/linden/indra/llmedia/llmediaimplgstreamer.cpp @@ -30,10 +30,12 @@ * $/LicenseInfo$ */ -#include "llmediaimplgstreamer.h" - ///#if LL_GSTREAMER_ENABLED +#include "linden_common.h" + +#include "llmediaimplgstreamer.h" + extern "C" { #include #include @@ -43,9 +45,8 @@ extern "C" { #include "llmediaimplregister.h" #include "llmediaimplgstreamervidplug.h" +#include "llgstplaythread.h" -#include "llerror.h" -#include "linden_common.h" // register this impl with media manager factory static LLMediaImplRegister sLLMediaImplGStreamerReg( "LLMediaImplGStreamer", new LLMediaImplGStreamerMaker() ); @@ -72,7 +73,8 @@ LLMediaImplGStreamer () : mPump ( NULL ), mPlaybin ( NULL ), mVideoSink ( NULL ), - mState( GST_STATE_NULL ) + mState( GST_STATE_NULL ), + mPlayThread ( NULL ) { startup( NULL ); // Startup gstreamer if it hasn't been already. @@ -713,7 +715,20 @@ bool LLMediaImplGStreamer::play() if (!mPlaybin || mState == GST_STATE_NULL) return true; - startPlay(); + // Clean up the existing thread, if any. + if( mPlayThread != NULL && mPlayThread->isStopped()) + { + delete mPlayThread; + mPlayThread = NULL; + } + + if( mPlayThread == NULL ) + { + // Make a new thread to start playing. This keeps the viewer + // responsive while the stream is resolved and buffered. + mPlayThread = new LLGstPlayThread( (LLMediaImplCommon *)this, "GstPlayThread", NULL); + mPlayThread->start(); + } return true; } diff --git a/linden/indra/llmedia/llmediaimplgstreamer.h b/linden/indra/llmedia/llmediaimplgstreamer.h index be4b3c0..32e6bd1 100644 --- a/linden/indra/llmedia/llmediaimplgstreamer.h +++ b/linden/indra/llmedia/llmediaimplgstreamer.h @@ -48,6 +48,7 @@ extern "C" { } #include "llmediaimplgstreamervidplug.h" +#include "llgstplaythread.h" class LLMediaManagerData; class LLMediaImplMaker; @@ -124,6 +125,8 @@ class LLMediaImplGStreamer: GstSLVideo *mVideoSink; GstState mState; GstState getState() const { return mState; } + + LLGstPlayThread *mPlayThread; }; class LLMediaImplGStreamerMaker : public LLMediaImplMaker -- cgit v1.1