llmediamanager.cpp

Go to the documentation of this file.
00001 
00032 #include "llmediamanager.h"
00033 #include "llmediaimplfactory.h"
00034 
00035 #include "llmediaimplexample1.h"
00036 #include "llmediaimplexample2.h"
00037 #include "llmediaimplquicktime.h"
00038 #include "llmediaimplgstreamer.h"
00039 #include "llmediaimplllmozlib.h"
00040 
00041 LLMediaManager* LLMediaManager::sInstance = 0;
00042 
00044 // (private)
00045 LLMediaManager::LLMediaManager()
00046 {
00047 }
00048 
00050 LLMediaManager::~LLMediaManager()
00051 {
00052 }
00053 
00055 // (static)
00056 void LLMediaManager::initClass( LLMediaManagerData* init_data )
00057 {
00058         if ( ! sInstance )
00059                 sInstance = new LLMediaManager();
00060 
00061         // Initialize impl classes here - this breaks the encapsulation model
00062         // but some of the initialization takes a long time and we only want to
00063         // do it once at app startup before any of the impls have been created
00064         // Each impl provides a static startup method that does any initialization
00065         // which takes a significant amount of time.
00066         LLMediaImplExample1::startup( init_data );
00067         LLMediaImplExample2::startup( init_data );
00068 
00069 #if LL_QUICKTIME_ENABLED
00070         LLMediaImplQuickTime::startup( init_data );
00071 #endif // LL_QUICKTIME_ENABLED
00072 
00073 #if LL_GSTREAMER_ENABLED
00074         LLMediaImplGStreamer::startup( init_data );
00075 #endif // LL_GSTREAMER_ENABLED
00076 
00077 #if LL_LLMOZLIB_ENABLED
00078         LLMediaImplLLMozLib::startup( init_data );
00079 #endif // LL_LLMOZLIB_ENABLED
00080 }
00081 
00083 // (static)
00084 void LLMediaManager::updateClass()
00085 {
00086         if (!sInstance) return;
00087 
00088         media_impl_container_t::iterator it
00089                 = sInstance->mMediaImplContainer.begin();
00090         media_impl_container_t::iterator end
00091                 = sInstance->mMediaImplContainer.end();
00092         for ( ; it != end; ++it )
00093         {
00094                 LLMediaBase* impl = *it;
00095                 impl->updateMedia();
00096         }
00097 }
00098 
00100 // (static)
00101 void LLMediaManager::cleanupClass()
00102 {
00103         // Uninitialize impl classes here - this breaks the encapsulation model
00104         // but some of the uninitialization takes a long time and we only want to
00105         // do it once at app startup before any of the impls have been created.
00106         // Each impl provides a static closedown method that does any uninitialization
00107         // which takes a significant amount of time.
00108         LLMediaImplExample1::closedown();
00109         LLMediaImplExample2::closedown();
00110 
00111 #if LL_LLMOZLIB_ENABLED
00112         LLMediaImplLLMozLib::closedown();
00113 #endif // LL_LLMOZLIB_ENABLED
00114 
00115 #if LL_QUICKTIME_ENABLED
00116         LLMediaImplQuickTime::closedown();
00117 #endif // LL_QUICKTIME_ENABLED
00118 
00119 #if LL_GSTREAMER_ENABLED
00120         LLMediaImplGStreamer::closedown();
00121 #endif // LL_QUICKTIME_ENABLED
00122 
00123         if ( sInstance )
00124                 delete sInstance;
00125 
00126         sInstance = 0;
00127 }
00128 
00130 // (static)
00131 LLMediaManager* LLMediaManager::getInstance()
00132 {
00133         return sInstance;
00134 }
00135 
00137 //
00138 LLMediaBase* LLMediaManager::createSourceFromMimeType( std::string scheme, std::string mime_type )
00139 {
00140 
00141         LLMediaImplMakerBase* impl_maker = LLMediaImplFactory::getInstance()->getImplMaker( scheme, mime_type );
00142 
00143         // If an impl maker is return it means this media type is supported
00144         if ( impl_maker )
00145         {
00146                 LLMediaBase* media_impl = impl_maker->create();
00147                 if( media_impl )
00148                 {
00149                         media_impl->setImplMaker( impl_maker );
00150                         std::pair< media_impl_container_t::iterator, bool > result =
00151                                 mMediaImplContainer.insert( media_impl );
00152 
00153                         if ( result.second )
00154                         {
00155                                 media_impl->setMimeType( mime_type );
00156 
00157                                 media_impl->init();
00158 
00159                                 return media_impl;
00160                         };
00161                 };
00162         };
00163 
00164         return 0;
00165 }
00166 
00168 //
00169 bool LLMediaManager::destroySource( LLMediaBase* media_impl )
00170 {
00171         media_impl_container_t::iterator iter =
00172                 mMediaImplContainer.find( media_impl );
00173 
00174         if ( iter != mMediaImplContainer.end() )
00175         {
00176                 if ( *iter )
00177                 {
00178                         ( *iter)->reset();
00179 
00180                         delete ( *iter );
00181 
00182                         mMediaImplContainer.erase( iter );
00183 
00184                         return true;
00185                 };
00186         };
00187 
00188         return false;
00189 }
00190 
00192 //
00193 bool LLMediaManager::addMimeTypeImplNameMap( std::string mime_type, std::string impl_name )
00194 {
00195         std::pair< mime_type_impl_name_container_t::iterator, bool > result =
00196                 mMimeTypeImplNameContainer.insert( std::make_pair( mime_type, impl_name ) );
00197 
00198         return result.second;
00199 }
00200 
00202 //
00203 std::string LLMediaManager::getImplNameFromMimeType( std::string mime_type )
00204 {
00205         mime_type_impl_name_container_t::iterator iter =
00206                 mMimeTypeImplNameContainer.find( mime_type );
00207 
00208         if ( iter != mMimeTypeImplNameContainer.end() )
00209         {
00210                 return ( *iter ).second;
00211         }
00212         else
00213         {
00214                 return std::string( "" );
00215         };
00216 }
00218 //
00219 bool LLMediaManager::supportsMediaType( const std::string& impl_name, const std::string& scheme, const std::string& mime_type )
00220 {
00221         LLMediaImplMakerBase* impl_maker = LLMediaImplFactory::getInstance()->getImplMaker( impl_name );
00222         if( impl_maker )
00223         {
00224                 int idx1 = mime_type.find("/");
00225                 int len = (idx1 == std::string::npos) ? 0 : idx1;
00226                 std::string category = mime_type.substr(0,len);
00227 
00228                 return impl_maker->supportsScheme(scheme) ||
00229                                 impl_maker->supportsMimeType(mime_type) ||
00230                                 impl_maker->supportsMimeTypeCategory(category);
00231         }
00232         return false;
00233 }
00234 
00235 // static
00236 int LLMediaManager::textureWidthFromMediaWidth( int media_width )
00237 {
00238         int texture_width = 1;
00239         while ( texture_width < media_width )
00240         {
00241                 texture_width <<= 1;
00242         };
00243         return texture_width;
00244 }
00245 
00246 // static
00247 int LLMediaManager::textureHeightFromMediaHeight( int media_height )
00248 {
00249         int texture_height = 1;
00250         while ( texture_height < media_height )
00251         {
00252                 texture_height <<= 1;
00253         };
00254         return texture_height;
00255 }

Generated on Fri May 16 08:32:21 2008 for SecondLife by  doxygen 1.5.5