1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
/**
* @file llmediamanager.cpp
* @brief Manages instances of media impls
*
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. 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
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llmediamanager.h"
#if LL_WINDOWS
// GStreamer 0.10.22 - gstutils.h - conversion from 'guint64' to 'guint8'.
// This was an intentional change to make GStreamer more threadsafe, and
// is okay. Delete this bit if GStreamer ever gets more VS-friendly -- McCabe
#pragma warning(disable : 4244)
#endif
#include "llmediaimplgstreamer.h"
#if LL_WINDOWS
#pragma warning(default : 4244)
#endif
#include "llmediaimplfactory.h"
#include "llmediaimplexample1.h"
#include "llmediaimplexample2.h"
#include "llmediaimplquicktime.h"
#if LL_LLMOZLIB_ENABLED
# include "llmediaimplllmozlib.h"
#endif
#include "llerror.h"
LLMediaManager* LLMediaManager::sInstance = 0;
////////////////////////////////////////////////////////////////////////////////
// (private)
LLMediaManager::LLMediaManager()
{
}
////////////////////////////////////////////////////////////////////////////////
LLMediaManager::~LLMediaManager()
{
}
////////////////////////////////////////////////////////////////////////////////
// Early initialization for web browser for the viewer, so we can show
// the login screen and defer initialization of QuickTime, etc. JC
// (static)
void LLMediaManager::initBrowser( LLMediaManagerData* init_data )
{
if ( ! sInstance )
sInstance = new LLMediaManager();
#if LL_LLMOZLIB_ENABLED
LLMediaImplLLMozLib::startup( init_data );
#endif // LL_LLMOZLIB_ENABLED
}
////////////////////////////////////////////////////////////////////////////////
// (static)
void LLMediaManager::initClass( LLMediaManagerData* init_data )
{
if ( ! sInstance )
sInstance = new LLMediaManager();
LL_DEBUGS("MediaManager") << "LLMediaManager::initClass" << LL_ENDL;
// Initialize impl classes here - this breaks the encapsulation model
// but some of the initialization takes a long time and we only want to
// do it once at app startup before any of the impls have been created
// Each impl provides a static startup method that does any initialization
// which takes a significant amount of time.
LLMediaImplExample1::startup( init_data );
LLMediaImplExample2::startup( init_data );
#if LL_QUICKTIME_ENABLED
LL_DEBUGS("MediaManager") << "LLMediaManager::initClass: starting quicktime." << LL_ENDL;
LLMediaImplQuickTime::startup( init_data );
#endif // LL_QUICKTIME_ENABLED
///#if LL_GSTREAMER_ENABLED
LL_DEBUGS("MediaManager") << "LLMediaManager::initClass: starting gstreamer" << LL_ENDL;
LLMediaImplGStreamer::startup( init_data );
///#endif // LL_GSTREAMER_ENABLED
}
////////////////////////////////////////////////////////////////////////////////
// (static)
void LLMediaManager::updateClass()
{
if (!sInstance) return;
media_impl_container_t::iterator it
= sInstance->mMediaImplContainer.begin();
media_impl_container_t::iterator end
= sInstance->mMediaImplContainer.end();
for ( ; it != end; ++it )
{
LLMediaBase* impl = *it;
impl->updateMedia();
}
}
////////////////////////////////////////////////////////////////////////////////
// (static)
void LLMediaManager::cleanupClass()
{
// Uninitialize impl classes here - this breaks the encapsulation model
// but some of the uninitialization takes a long time and we only want to
// do it once at app startup before any of the impls have been created.
// Each impl provides a static closedown method that does any uninitialization
// which takes a significant amount of time.
LLMediaImplExample1::closedown();
LLMediaImplExample2::closedown();
#if LL_LLMOZLIB_ENABLED
LLMediaImplLLMozLib::closedown();
#endif // LL_LLMOZLIB_ENABLED
#if LL_QUICKTIME_ENABLED
LLMediaImplQuickTime::closedown();
#endif // LL_QUICKTIME_ENABLED
///#if LL_GSTREAMER_ENABLED
LLMediaImplGStreamer::closedown();
///#endif // LL_QUICKTIME_ENABLED
if ( sInstance )
delete sInstance;
sInstance = 0;
}
////////////////////////////////////////////////////////////////////////////////
// (static)
LLMediaManager* LLMediaManager::getInstance()
{
return sInstance;
}
////////////////////////////////////////////////////////////////////////////////
// (static)
void LLMediaManager::setBrowserUserAgent(std::string user_agent)
{
#if LL_LLMOZLIB_ENABLED
// *HACK: Breaks encapsulation model, as initClass does above. JC
LLMediaImplLLMozLib::setBrowserUserAgent(user_agent);
#endif
}
////////////////////////////////////////////////////////////////////////////////
//
LLMediaBase* LLMediaManager::createSourceFromMimeType( std::string scheme, std::string mime_type )
{
LLMediaImplMakerBase* impl_maker = LLMediaImplFactory::getInstance()->getImplMaker( scheme, mime_type );
// If an impl maker is return it means this media type is supported
if ( impl_maker )
{
LLMediaBase* media_impl = impl_maker->create();
if( media_impl )
{
media_impl->setImplMaker( impl_maker );
std::pair< media_impl_container_t::iterator, bool > result =
mMediaImplContainer.insert( media_impl );
if ( result.second )
{
media_impl->setMimeType( mime_type );
media_impl->init();
return media_impl;
};
};
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMediaManager::destroySource( LLMediaBase* media_impl )
{
media_impl_container_t::iterator iter =
mMediaImplContainer.find( media_impl );
if ( iter != mMediaImplContainer.end() )
{
if ( *iter )
{
( *iter)->reset();
delete ( *iter );
mMediaImplContainer.erase( iter );
return true;
};
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMediaManager::addMimeTypeImplNameMap( std::string mime_type, std::string impl_name )
{
std::pair< mime_type_impl_name_container_t::iterator, bool > result =
mMimeTypeImplNameContainer.insert( std::make_pair( mime_type, impl_name ) );
return result.second;
}
////////////////////////////////////////////////////////////////////////////////
//
std::string LLMediaManager::getImplNameFromMimeType( std::string mime_type )
{
mime_type_impl_name_container_t::iterator iter =
mMimeTypeImplNameContainer.find( mime_type );
if ( iter != mMimeTypeImplNameContainer.end() )
{
return ( *iter ).second;
}
else
{
return std::string( "" );
};
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMediaManager::supportsMediaType( const std::string& impl_name, const std::string& scheme, const std::string& mime_type )
{
LLMediaImplMakerBase* impl_maker = LLMediaImplFactory::getInstance()->getImplMaker( impl_name );
if( impl_maker )
{
int idx1 = mime_type.find("/");
int len = (idx1 == std::string::npos) ? 0 : idx1;
std::string category = mime_type.substr(0,len);
return impl_maker->supportsScheme(scheme) ||
impl_maker->supportsMimeType(mime_type) ||
impl_maker->supportsMimeTypeCategory(category);
}
return false;
}
// static
int LLMediaManager::textureWidthFromMediaWidth( int media_width )
{
int texture_width = 1;
while ( texture_width < media_width )
{
texture_width <<= 1;
};
return texture_width;
}
// static
int LLMediaManager::textureHeightFromMediaHeight( int media_height )
{
int texture_height = 1;
while ( texture_height < media_height )
{
texture_height <<= 1;
};
return texture_height;
}
|