diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llmedia/llmediamanager.cpp | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/llmedia/llmediamanager.cpp')
-rw-r--r-- | linden/indra/llmedia/llmediamanager.cpp | 255 |
1 files changed, 255 insertions, 0 deletions
diff --git a/linden/indra/llmedia/llmediamanager.cpp b/linden/indra/llmedia/llmediamanager.cpp new file mode 100644 index 0000000..c9b673d --- /dev/null +++ b/linden/indra/llmedia/llmediamanager.cpp | |||
@@ -0,0 +1,255 @@ | |||
1 | /** | ||
2 | * @file llmediamanager.cpp | ||
3 | * @brief Manages instances of media impls | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-2008, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | * $/LicenseInfo$ | ||
30 | */ | ||
31 | |||
32 | #include "llmediamanager.h" | ||
33 | #include "llmediaimplfactory.h" | ||
34 | |||
35 | #include "llmediaimplexample1.h" | ||
36 | #include "llmediaimplexample2.h" | ||
37 | #include "llmediaimplquicktime.h" | ||
38 | #include "llmediaimplgstreamer.h" | ||
39 | #include "llmediaimplllmozlib.h" | ||
40 | |||
41 | LLMediaManager* LLMediaManager::sInstance = 0; | ||
42 | |||
43 | //////////////////////////////////////////////////////////////////////////////// | ||
44 | // (private) | ||
45 | LLMediaManager::LLMediaManager() | ||
46 | { | ||
47 | } | ||
48 | |||
49 | //////////////////////////////////////////////////////////////////////////////// | ||
50 | LLMediaManager::~LLMediaManager() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | //////////////////////////////////////////////////////////////////////////////// | ||
55 | // (static) | ||
56 | void LLMediaManager::initClass( LLMediaManagerData* init_data ) | ||
57 | { | ||
58 | if ( ! sInstance ) | ||
59 | sInstance = new LLMediaManager(); | ||
60 | |||
61 | // Initialize impl classes here - this breaks the encapsulation model | ||
62 | // but some of the initialization takes a long time and we only want to | ||
63 | // do it once at app startup before any of the impls have been created | ||
64 | // Each impl provides a static startup method that does any initialization | ||
65 | // which takes a significant amount of time. | ||
66 | LLMediaImplExample1::startup( init_data ); | ||
67 | LLMediaImplExample2::startup( init_data ); | ||
68 | |||
69 | #if LL_QUICKTIME_ENABLED | ||
70 | LLMediaImplQuickTime::startup( init_data ); | ||
71 | #endif // LL_QUICKTIME_ENABLED | ||
72 | |||
73 | #if LL_GSTREAMER_ENABLED | ||
74 | LLMediaImplGStreamer::startup( init_data ); | ||
75 | #endif // LL_GSTREAMER_ENABLED | ||
76 | |||
77 | #if LL_LLMOZLIB_ENABLED | ||
78 | LLMediaImplLLMozLib::startup( init_data ); | ||
79 | #endif // LL_LLMOZLIB_ENABLED | ||
80 | } | ||
81 | |||
82 | //////////////////////////////////////////////////////////////////////////////// | ||
83 | // (static) | ||
84 | void LLMediaManager::updateClass() | ||
85 | { | ||
86 | if (!sInstance) return; | ||
87 | |||
88 | media_impl_container_t::iterator it | ||
89 | = sInstance->mMediaImplContainer.begin(); | ||
90 | media_impl_container_t::iterator end | ||
91 | = sInstance->mMediaImplContainer.end(); | ||
92 | for ( ; it != end; ++it ) | ||
93 | { | ||
94 | LLMediaBase* impl = *it; | ||
95 | impl->updateMedia(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | //////////////////////////////////////////////////////////////////////////////// | ||
100 | // (static) | ||
101 | void LLMediaManager::cleanupClass() | ||
102 | { | ||
103 | // Uninitialize impl classes here - this breaks the encapsulation model | ||
104 | // but some of the uninitialization takes a long time and we only want to | ||
105 | // do it once at app startup before any of the impls have been created. | ||
106 | // Each impl provides a static closedown method that does any uninitialization | ||
107 | // which takes a significant amount of time. | ||
108 | LLMediaImplExample1::closedown(); | ||
109 | LLMediaImplExample2::closedown(); | ||
110 | |||
111 | #if LL_LLMOZLIB_ENABLED | ||
112 | LLMediaImplLLMozLib::closedown(); | ||
113 | #endif // LL_LLMOZLIB_ENABLED | ||
114 | |||
115 | #if LL_QUICKTIME_ENABLED | ||
116 | LLMediaImplQuickTime::closedown(); | ||
117 | #endif // LL_QUICKTIME_ENABLED | ||
118 | |||
119 | #if LL_GSTREAMER_ENABLED | ||
120 | LLMediaImplGStreamer::closedown(); | ||
121 | #endif // LL_QUICKTIME_ENABLED | ||
122 | |||
123 | if ( sInstance ) | ||
124 | delete sInstance; | ||
125 | |||
126 | sInstance = 0; | ||
127 | } | ||
128 | |||
129 | //////////////////////////////////////////////////////////////////////////////// | ||
130 | // (static) | ||
131 | LLMediaManager* LLMediaManager::getInstance() | ||
132 | { | ||
133 | return sInstance; | ||
134 | } | ||
135 | |||
136 | //////////////////////////////////////////////////////////////////////////////// | ||
137 | // | ||
138 | LLMediaBase* LLMediaManager::createSourceFromMimeType( std::string scheme, std::string mime_type ) | ||
139 | { | ||
140 | |||
141 | LLMediaImplMakerBase* impl_maker = LLMediaImplFactory::getInstance()->getImplMaker( scheme, mime_type ); | ||
142 | |||
143 | // If an impl maker is return it means this media type is supported | ||
144 | if ( impl_maker ) | ||
145 | { | ||
146 | LLMediaBase* media_impl = impl_maker->create(); | ||
147 | if( media_impl ) | ||
148 | { | ||
149 | media_impl->setImplMaker( impl_maker ); | ||
150 | std::pair< media_impl_container_t::iterator, bool > result = | ||
151 | mMediaImplContainer.insert( media_impl ); | ||
152 | |||
153 | if ( result.second ) | ||
154 | { | ||
155 | media_impl->setMimeType( mime_type ); | ||
156 | |||
157 | media_impl->init(); | ||
158 | |||
159 | return media_impl; | ||
160 | }; | ||
161 | }; | ||
162 | }; | ||
163 | |||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | //////////////////////////////////////////////////////////////////////////////// | ||
168 | // | ||
169 | bool LLMediaManager::destroySource( LLMediaBase* media_impl ) | ||
170 | { | ||
171 | media_impl_container_t::iterator iter = | ||
172 | mMediaImplContainer.find( media_impl ); | ||
173 | |||
174 | if ( iter != mMediaImplContainer.end() ) | ||
175 | { | ||
176 | if ( *iter ) | ||
177 | { | ||
178 | ( *iter)->reset(); | ||
179 | |||
180 | delete ( *iter ); | ||
181 | |||
182 | mMediaImplContainer.erase( iter ); | ||
183 | |||
184 | return true; | ||
185 | }; | ||
186 | }; | ||
187 | |||
188 | return false; | ||
189 | } | ||
190 | |||
191 | //////////////////////////////////////////////////////////////////////////////// | ||
192 | // | ||
193 | bool LLMediaManager::addMimeTypeImplNameMap( std::string mime_type, std::string impl_name ) | ||
194 | { | ||
195 | std::pair< mime_type_impl_name_container_t::iterator, bool > result = | ||
196 | mMimeTypeImplNameContainer.insert( std::make_pair( mime_type, impl_name ) ); | ||
197 | |||
198 | return result.second; | ||
199 | } | ||
200 | |||
201 | //////////////////////////////////////////////////////////////////////////////// | ||
202 | // | ||
203 | std::string LLMediaManager::getImplNameFromMimeType( std::string mime_type ) | ||
204 | { | ||
205 | mime_type_impl_name_container_t::iterator iter = | ||
206 | mMimeTypeImplNameContainer.find( mime_type ); | ||
207 | |||
208 | if ( iter != mMimeTypeImplNameContainer.end() ) | ||
209 | { | ||
210 | return ( *iter ).second; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | return std::string( "" ); | ||
215 | }; | ||
216 | } | ||
217 | //////////////////////////////////////////////////////////////////////////////// | ||
218 | // | ||
219 | bool LLMediaManager::supportsMediaType( const std::string& impl_name, const std::string& scheme, const std::string& mime_type ) | ||
220 | { | ||
221 | LLMediaImplMakerBase* impl_maker = LLMediaImplFactory::getInstance()->getImplMaker( impl_name ); | ||
222 | if( impl_maker ) | ||
223 | { | ||
224 | int idx1 = mime_type.find("/"); | ||
225 | int len = (idx1 == std::string::npos) ? 0 : idx1; | ||
226 | std::string category = mime_type.substr(0,len); | ||
227 | |||
228 | return impl_maker->supportsScheme(scheme) || | ||
229 | impl_maker->supportsMimeType(mime_type) || | ||
230 | impl_maker->supportsMimeTypeCategory(category); | ||
231 | } | ||
232 | return false; | ||
233 | } | ||
234 | |||
235 | // static | ||
236 | int LLMediaManager::textureWidthFromMediaWidth( int media_width ) | ||
237 | { | ||
238 | int texture_width = 1; | ||
239 | while ( texture_width < media_width ) | ||
240 | { | ||
241 | texture_width <<= 1; | ||
242 | }; | ||
243 | return texture_width; | ||
244 | } | ||
245 | |||
246 | // static | ||
247 | int LLMediaManager::textureHeightFromMediaHeight( int media_height ) | ||
248 | { | ||
249 | int texture_height = 1; | ||
250 | while ( texture_height < media_height ) | ||
251 | { | ||
252 | texture_height <<= 1; | ||
253 | }; | ||
254 | return texture_height; | ||
255 | } | ||