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/newview/llviewerparcelmedia.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 '')
-rw-r--r-- | linden/indra/newview/llviewerparcelmedia.cpp | 363 |
1 files changed, 363 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewerparcelmedia.cpp b/linden/indra/newview/llviewerparcelmedia.cpp new file mode 100644 index 0000000..cd0197c --- /dev/null +++ b/linden/indra/newview/llviewerparcelmedia.cpp | |||
@@ -0,0 +1,363 @@ | |||
1 | /** | ||
2 | * @file llviewerparcelmedia.cpp | ||
3 | * @brief Handlers for multimedia on a per-parcel basis | ||
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 "llviewerprecompiledheaders.h" | ||
33 | #include "llviewerparcelmedia.h" | ||
34 | |||
35 | #include "llagent.h" | ||
36 | #include "llviewercontrol.h" | ||
37 | #include "llviewermedia.h" | ||
38 | #include "llviewerregion.h" | ||
39 | #include "llparcel.h" | ||
40 | #include "llviewerparcelmgr.h" | ||
41 | #include "lluuid.h" | ||
42 | #include "message.h" | ||
43 | #include "llviewerparcelmediaautoplay.h" | ||
44 | #include "llfirstuse.h" | ||
45 | |||
46 | // Static Variables | ||
47 | |||
48 | S32 LLViewerParcelMedia::sMediaParcelLocalID = 0; | ||
49 | LLUUID LLViewerParcelMedia::sMediaRegionID; | ||
50 | |||
51 | // Move this to its own file. | ||
52 | // helper class that tries to download a URL from a web site and calls a method | ||
53 | // on the Panel Land Media and to discover the MIME type | ||
54 | class LLMimeDiscoveryResponder : public LLHTTPClient::Responder | ||
55 | { | ||
56 | public: | ||
57 | LLMimeDiscoveryResponder( ) | ||
58 | {} | ||
59 | |||
60 | |||
61 | |||
62 | virtual void completedHeader(U32 status, const std::string& reason, const LLSD& content) | ||
63 | { | ||
64 | std::string media_type = content["content-type"].asString(); | ||
65 | std::string::size_type idx1 = media_type.find_first_of(";"); | ||
66 | std::string mime_type = media_type.substr(0, idx1); | ||
67 | completeAny(status, mime_type); | ||
68 | } | ||
69 | |||
70 | virtual void error( U32 status, const std::string& reason ) | ||
71 | { | ||
72 | completeAny(status, "none/none"); | ||
73 | } | ||
74 | |||
75 | void completeAny(U32 status, const std::string& mime_type) | ||
76 | { | ||
77 | LLViewerMedia::setMimeType(mime_type); | ||
78 | } | ||
79 | }; | ||
80 | |||
81 | // static | ||
82 | void LLViewerParcelMedia::initClass() | ||
83 | { | ||
84 | LLMessageSystem* msg = gMessageSystem; | ||
85 | msg->setHandlerFunc("ParcelMediaCommandMessage", processParcelMediaCommandMessage ); | ||
86 | msg->setHandlerFunc("ParcelMediaUpdate", processParcelMediaUpdate ); | ||
87 | LLViewerParcelMediaAutoPlay::initClass(); | ||
88 | } | ||
89 | |||
90 | ////////////////////////////////////////////////////////////////////////////////////////// | ||
91 | // static | ||
92 | void LLViewerParcelMedia::update(LLParcel* parcel) | ||
93 | { | ||
94 | if (/*LLViewerMedia::hasMedia()*/ true) | ||
95 | { | ||
96 | // we have a player | ||
97 | if (parcel) | ||
98 | { | ||
99 | // we're in a parcel | ||
100 | bool new_parcel = false; | ||
101 | S32 parcelid = parcel->getLocalID(); | ||
102 | LLUUID regionid = gAgent.getRegion()->getRegionID(); | ||
103 | if (parcelid != sMediaParcelLocalID || regionid != sMediaRegionID) | ||
104 | { | ||
105 | sMediaParcelLocalID = parcelid; | ||
106 | sMediaRegionID = regionid; | ||
107 | new_parcel = true; | ||
108 | } | ||
109 | |||
110 | std::string mediaUrl = std::string ( parcel->getMediaURL () ); | ||
111 | LLString::trim(mediaUrl); | ||
112 | |||
113 | // has something changed? | ||
114 | if ( ( LLViewerMedia::getMediaURL() != mediaUrl ) | ||
115 | || ( LLViewerMedia::getMediaTextureID() != parcel->getMediaID () ) ) | ||
116 | { | ||
117 | bool video_was_playing = FALSE; | ||
118 | bool same_media_id = LLViewerMedia::getMediaTextureID() == parcel->getMediaID (); | ||
119 | |||
120 | if (LLViewerMedia::isMediaPlaying()) | ||
121 | { | ||
122 | video_was_playing = TRUE; | ||
123 | } | ||
124 | |||
125 | if ( !mediaUrl.empty() && same_media_id && ! new_parcel) | ||
126 | { | ||
127 | // Someone has "changed the channel", changing the URL of a video | ||
128 | // you were already watching. Automatically play provided the texture ID is the same | ||
129 | if (video_was_playing) | ||
130 | { | ||
131 | // Poke the mime type in before calling play. | ||
132 | // This is necessary because in this instance we are not waiting | ||
133 | // for the results of a header curl. In order to change the channel | ||
134 | // a mime type MUST be provided. | ||
135 | LLViewerMedia::setMimeType(parcel->getMediaType()); | ||
136 | play(parcel); | ||
137 | } | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | stop(); | ||
142 | } | ||
143 | |||
144 | // Discover the MIME type | ||
145 | // Disabled for the time being. Get the mime type from the parcel. | ||
146 | if(gSavedSettings.getBOOL("AutoMimeDiscovery")) | ||
147 | { | ||
148 | LLHTTPClient::getHeaderOnly( mediaUrl, new LLMimeDiscoveryResponder()); | ||
149 | } | ||
150 | else | ||
151 | { | ||
152 | LLViewerMedia::setMimeType(parcel->getMediaType()); | ||
153 | } | ||
154 | |||
155 | } | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | stop(); | ||
160 | } | ||
161 | } | ||
162 | /* | ||
163 | else | ||
164 | { | ||
165 | // no audio player, do a first use dialog if their is media here | ||
166 | if (parcel) | ||
167 | { | ||
168 | std::string mediaUrl = std::string ( parcel->getMediaURL () ); | ||
169 | if (!mediaUrl.empty ()) | ||
170 | { | ||
171 | if (gSavedSettings.getWarning("QuickTimeInstalled")) | ||
172 | { | ||
173 | gSavedSettings.setWarning("QuickTimeInstalled", FALSE); | ||
174 | |||
175 | LLNotifyBox::showXml("NoQuickTime" ); | ||
176 | }; | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | */ | ||
181 | } | ||
182 | |||
183 | // static | ||
184 | void LLViewerParcelMedia::play(LLParcel* parcel) | ||
185 | { | ||
186 | lldebugs << "LLViewerParcelMedia::play" << llendl; | ||
187 | |||
188 | if (!parcel) return; | ||
189 | |||
190 | if (!gSavedSettings.getBOOL("AudioStreamingVideo")) | ||
191 | return; | ||
192 | |||
193 | std::string media_url = parcel->getMediaURL(); | ||
194 | std::string mime_type = parcel->getMediaType(); | ||
195 | LLUUID placeholder_texture_id = parcel->getMediaID(); | ||
196 | U8 media_auto_scale = parcel->getMediaAutoScale(); | ||
197 | U8 media_loop = parcel->getMediaLoop(); | ||
198 | S32 media_width = parcel->getMediaWidth(); | ||
199 | S32 media_height = parcel->getMediaHeight(); | ||
200 | LLViewerMedia::play(media_url, mime_type, placeholder_texture_id, | ||
201 | media_width, media_height, media_auto_scale, | ||
202 | media_loop); | ||
203 | LLFirstUse::useMedia(); | ||
204 | |||
205 | LLViewerParcelMediaAutoPlay::playStarted(); | ||
206 | } | ||
207 | |||
208 | // static | ||
209 | void LLViewerParcelMedia::stop() | ||
210 | { | ||
211 | |||
212 | LLViewerMedia::stop(); | ||
213 | } | ||
214 | |||
215 | // static | ||
216 | void LLViewerParcelMedia::pause() | ||
217 | { | ||
218 | LLViewerMedia::pause(); | ||
219 | } | ||
220 | |||
221 | // static | ||
222 | void LLViewerParcelMedia::start() | ||
223 | { | ||
224 | LLViewerMedia::start(); | ||
225 | LLFirstUse::useMedia(); | ||
226 | |||
227 | LLViewerParcelMediaAutoPlay::playStarted(); | ||
228 | } | ||
229 | |||
230 | // static | ||
231 | void LLViewerParcelMedia::seek(F32 time) | ||
232 | { | ||
233 | LLViewerMedia::seek(time); | ||
234 | } | ||
235 | |||
236 | |||
237 | // static | ||
238 | LLMediaBase::EStatus LLViewerParcelMedia::getStatus() | ||
239 | { | ||
240 | return LLViewerMedia::getStatus(); | ||
241 | } | ||
242 | |||
243 | ////////////////////////////////////////////////////////////////////////////////////////// | ||
244 | // static | ||
245 | void LLViewerParcelMedia::processParcelMediaCommandMessage( LLMessageSystem *msg, void ** ) | ||
246 | { | ||
247 | // extract the agent id | ||
248 | // LLUUID agent_id; | ||
249 | // msg->getUUID( agent_id ); | ||
250 | |||
251 | U32 flags; | ||
252 | U32 command; | ||
253 | F32 time; | ||
254 | msg->getU32( "CommandBlock", "Flags", flags ); | ||
255 | msg->getU32( "CommandBlock", "Command", command); | ||
256 | msg->getF32( "CommandBlock", "Time", time ); | ||
257 | |||
258 | if (flags &( (1<<PARCEL_MEDIA_COMMAND_STOP) | ||
259 | | (1<<PARCEL_MEDIA_COMMAND_PAUSE) | ||
260 | | (1<<PARCEL_MEDIA_COMMAND_PLAY) | ||
261 | | (1<<PARCEL_MEDIA_COMMAND_LOOP) | ||
262 | | (1<<PARCEL_MEDIA_COMMAND_UNLOAD) )) | ||
263 | { | ||
264 | // stop | ||
265 | if( command == PARCEL_MEDIA_COMMAND_STOP ) | ||
266 | { | ||
267 | stop(); | ||
268 | } | ||
269 | else | ||
270 | // pause | ||
271 | if( command == PARCEL_MEDIA_COMMAND_PAUSE ) | ||
272 | { | ||
273 | pause(); | ||
274 | } | ||
275 | else | ||
276 | // play | ||
277 | if( command == PARCEL_MEDIA_COMMAND_PLAY ) | ||
278 | { | ||
279 | if (LLViewerMedia::isMediaPaused()) | ||
280 | { | ||
281 | start(); | ||
282 | } | ||
283 | else | ||
284 | { | ||
285 | LLParcel *parcel = gParcelMgr->getAgentParcel(); | ||
286 | play(parcel); | ||
287 | } | ||
288 | } | ||
289 | else | ||
290 | // loop | ||
291 | if( command == PARCEL_MEDIA_COMMAND_LOOP ) | ||
292 | { | ||
293 | //llinfos << ">>> LLMediaEngine::process_parcel_media with command = " <<( '0' + command ) << llendl; | ||
294 | |||
295 | // huh? what is play? | ||
296 | //convertImageAndLoadUrl( play ); | ||
297 | //convertImageAndLoadUrl( true, false, std::string() ); | ||
298 | } | ||
299 | else | ||
300 | // unload | ||
301 | if( command == PARCEL_MEDIA_COMMAND_UNLOAD ) | ||
302 | { | ||
303 | stop(); | ||
304 | } | ||
305 | } | ||
306 | |||
307 | if (flags & (1<<PARCEL_MEDIA_COMMAND_TIME)) | ||
308 | { | ||
309 | if(! LLViewerMedia::hasMedia()) | ||
310 | { | ||
311 | LLParcel *parcel = gParcelMgr->getAgentParcel(); | ||
312 | play(parcel); | ||
313 | } | ||
314 | seek(time); | ||
315 | } | ||
316 | } | ||
317 | |||
318 | ////////////////////////////////////////////////////////////////////////////////////////// | ||
319 | // static | ||
320 | void LLViewerParcelMedia::processParcelMediaUpdate( LLMessageSystem *msg, void ** ) | ||
321 | { | ||
322 | LLUUID media_id; | ||
323 | std::string media_url; | ||
324 | std::string media_type; | ||
325 | S32 media_width = 0; | ||
326 | S32 media_height = 0; | ||
327 | U8 media_auto_scale = FALSE; | ||
328 | U8 media_loop = FALSE; | ||
329 | |||
330 | msg->getUUID( "DataBlock", "MediaID", media_id ); | ||
331 | char media_url_buffer[257]; | ||
332 | msg->getString( "DataBlock", "MediaURL", 255, media_url_buffer ); | ||
333 | media_url = media_url_buffer; | ||
334 | msg->getU8("DataBlock", "MediaAutoScale", media_auto_scale); | ||
335 | |||
336 | if (msg->getNumberOfBlocks("DataBlockExtended")) // do we have the extended data? | ||
337 | { | ||
338 | char media_type_buffer[257]; | ||
339 | msg->getString("DataBlockExtended", "MediaType", 255, media_type_buffer); | ||
340 | media_type = media_type_buffer; | ||
341 | msg->getU8("DataBlockExtended", "MediaLoop", media_loop); | ||
342 | msg->getS32("DataBlockExtended", "MediaWidth", media_width); | ||
343 | msg->getS32("DataBlockExtended", "MediaHeight", media_height); | ||
344 | } | ||
345 | |||
346 | LLParcel *parcel = gParcelMgr->getAgentParcel(); | ||
347 | BOOL same = FALSE; | ||
348 | if (parcel) | ||
349 | { | ||
350 | same = ((parcel->getMediaURL() == media_url) && | ||
351 | (parcel->getMediaType() == media_type) && | ||
352 | (parcel->getMediaID() == media_id) && | ||
353 | (parcel->getMediaWidth() == media_width) && | ||
354 | (parcel->getMediaHeight() == media_height) && | ||
355 | (parcel->getMediaAutoScale() == media_auto_scale) && | ||
356 | (parcel->getMediaLoop() == media_loop)); | ||
357 | } | ||
358 | |||
359 | if (!same) | ||
360 | LLViewerMedia::play(media_url, media_type, media_id, | ||
361 | media_auto_scale, media_width, media_height, | ||
362 | media_loop); | ||
363 | } | ||