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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
/**
* @file llviewerparcelmedia.cpp
* @author Callum Prentice & James Cook
* @brief Handlers for multimedia on a per-parcel basis
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#include "llviewerprecompiledheaders.h"
#include "llviewerparcelmedia.h"
#include "llagent.h"
#include "llviewercontrol.h"
#include "llviewermedia.h"
#include "llviewerregion.h"
#include "llparcel.h"
#include "llviewerparcelmgr.h"
#include "lluuid.h"
#include "message.h"
#include "llviewerparcelmediaautoplay.h"
#include "llfirstuse.h"
// Static Variables
S32 LLViewerParcelMedia::sMediaParcelLocalID = 0;
LLUUID LLViewerParcelMedia::sMediaRegionID;
// Move this to its own file.
// helper class that tries to download a URL from a web site and calls a method
// on the Panel Land Media and to discover the MIME type
class LLMimeDiscoveryResponder : public LLHTTPClient::Responder
{
public:
LLMimeDiscoveryResponder( )
{}
virtual void completedHeader(U32 status, const std::string& reason, const LLSD& content)
{
std::string media_type = content["content-type"].asString();
std::string::size_type idx1 = media_type.find_first_of(";");
std::string mime_type = media_type.substr(0, idx1);
completeAny(status, mime_type);
}
virtual void error( U32 status, const std::string& reason )
{
completeAny(status, "none/none");
}
void completeAny(U32 status, const std::string& mime_type)
{
LLViewerMedia::setMimeType(mime_type);
}
};
// static
void LLViewerParcelMedia::initClass()
{
LLMessageSystem* msg = gMessageSystem;
msg->setHandlerFunc("ParcelMediaCommandMessage", processParcelMediaCommandMessage );
msg->setHandlerFunc("ParcelMediaUpdate", processParcelMediaUpdate );
LLViewerParcelMediaAutoPlay::initClass();
}
//////////////////////////////////////////////////////////////////////////////////////////
// static
void LLViewerParcelMedia::update(LLParcel* parcel)
{
if (/*LLViewerMedia::hasMedia()*/ true)
{
// we have a player
if (parcel)
{
// we're in a parcel
bool new_parcel = false;
S32 parcelid = parcel->getLocalID();
LLUUID regionid = gAgent.getRegion()->getRegionID();
if (parcelid != sMediaParcelLocalID || regionid != sMediaRegionID)
{
sMediaParcelLocalID = parcelid;
sMediaRegionID = regionid;
new_parcel = true;
}
std::string mediaUrl = std::string ( parcel->getMediaURL () );
LLString::trim(mediaUrl);
// has something changed?
if ( ( LLViewerMedia::getMediaURL() != mediaUrl )
|| ( LLViewerMedia::getMediaTextureID() != parcel->getMediaID () ) )
{
bool video_was_playing = FALSE;
bool same_media_id = LLViewerMedia::getMediaTextureID() == parcel->getMediaID ();
if (LLViewerMedia::isMediaPlaying())
{
video_was_playing = TRUE;
}
if ( !mediaUrl.empty() && same_media_id && ! new_parcel)
{
// Someone has "changed the channel", changing the URL of a video
// you were already watching. Automatically play provided the texture ID is the same
if (video_was_playing)
{
// Poke the mime type in before calling play.
// This is necessary because in this instance we are not waiting
// for the results of a header curl. In order to change the channel
// a mime type MUST be provided.
LLViewerMedia::setMimeType(parcel->getMediaType());
play(parcel);
}
}
else
{
stop();
}
// Discover the MIME type
// Disabled for the time being. Get the mime type from the parcel.
if(gSavedSettings.getBOOL("AutoMimeDiscovery"))
{
LLHTTPClient::getHeaderOnly( mediaUrl, new LLMimeDiscoveryResponder());
}
else
{
LLViewerMedia::setMimeType(parcel->getMediaType());
}
}
}
else
{
stop();
}
}
/*
else
{
// no audio player, do a first use dialog if their is media here
if (parcel)
{
std::string mediaUrl = std::string ( parcel->getMediaURL () );
if (!mediaUrl.empty ())
{
if (gSavedSettings.getWarning("QuickTimeInstalled"))
{
gSavedSettings.setWarning("QuickTimeInstalled", FALSE);
LLNotifyBox::showXml("NoQuickTime" );
};
}
}
}
*/
}
// static
void LLViewerParcelMedia::play(LLParcel* parcel)
{
lldebugs << "LLViewerParcelMedia::play" << llendl;
if (!parcel) return;
if (!gSavedSettings.getBOOL("AudioStreamingVideo"))
return;
std::string media_url = parcel->getMediaURL();
std::string mime_type = parcel->getMediaType();
LLUUID placeholder_texture_id = parcel->getMediaID();
U8 media_auto_scale = parcel->getMediaAutoScale();
U8 media_loop = parcel->getMediaLoop();
S32 media_width = parcel->getMediaWidth();
S32 media_height = parcel->getMediaHeight();
LLViewerMedia::play(media_url, mime_type, placeholder_texture_id,
media_width, media_height, media_auto_scale,
media_loop);
LLFirstUse::useMedia();
LLViewerParcelMediaAutoPlay::playStarted();
}
// static
void LLViewerParcelMedia::stop()
{
LLViewerMedia::stop();
}
// static
void LLViewerParcelMedia::pause()
{
LLViewerMedia::pause();
}
// static
void LLViewerParcelMedia::start()
{
LLViewerMedia::start();
LLFirstUse::useMedia();
LLViewerParcelMediaAutoPlay::playStarted();
}
// static
void LLViewerParcelMedia::seek(F32 time)
{
LLViewerMedia::seek(time);
}
// static
LLMediaBase::EStatus LLViewerParcelMedia::getStatus()
{
return LLViewerMedia::getStatus();
}
//////////////////////////////////////////////////////////////////////////////////////////
// static
void LLViewerParcelMedia::processParcelMediaCommandMessage( LLMessageSystem *msg, void ** )
{
// extract the agent id
// LLUUID agent_id;
// msg->getUUID( agent_id );
U32 flags;
U32 command;
F32 time;
msg->getU32( "CommandBlock", "Flags", flags );
msg->getU32( "CommandBlock", "Command", command);
msg->getF32( "CommandBlock", "Time", time );
if (flags &( (1<<PARCEL_MEDIA_COMMAND_STOP)
| (1<<PARCEL_MEDIA_COMMAND_PAUSE)
| (1<<PARCEL_MEDIA_COMMAND_PLAY)
| (1<<PARCEL_MEDIA_COMMAND_LOOP)
| (1<<PARCEL_MEDIA_COMMAND_UNLOAD) ))
{
// stop
if( command == PARCEL_MEDIA_COMMAND_STOP )
{
stop();
}
else
// pause
if( command == PARCEL_MEDIA_COMMAND_PAUSE )
{
pause();
}
else
// play
if( command == PARCEL_MEDIA_COMMAND_PLAY )
{
if (LLViewerMedia::isMediaPaused())
{
start();
}
else
{
LLParcel *parcel = gParcelMgr->getAgentParcel();
play(parcel);
}
}
else
// loop
if( command == PARCEL_MEDIA_COMMAND_LOOP )
{
//llinfos << ">>> LLMediaEngine::process_parcel_media with command = " <<( '0' + command ) << llendl;
// huh? what is play?
//convertImageAndLoadUrl( play );
//convertImageAndLoadUrl( true, false, std::string() );
}
else
// unload
if( command == PARCEL_MEDIA_COMMAND_UNLOAD )
{
stop();
}
}
if (flags & (1<<PARCEL_MEDIA_COMMAND_TIME))
{
if(! LLViewerMedia::hasMedia())
{
LLParcel *parcel = gParcelMgr->getAgentParcel();
play(parcel);
}
seek(time);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// static
void LLViewerParcelMedia::processParcelMediaUpdate( LLMessageSystem *msg, void ** )
{
LLUUID media_id;
std::string media_url;
std::string media_type;
S32 media_width = 0;
S32 media_height = 0;
U8 media_auto_scale = FALSE;
U8 media_loop = FALSE;
msg->getUUID( "DataBlock", "MediaID", media_id );
char media_url_buffer[257];
msg->getString( "DataBlock", "MediaURL", 255, media_url_buffer );
media_url = media_url_buffer;
msg->getU8("DataBlock", "MediaAutoScale", media_auto_scale);
if (msg->getNumberOfBlocks("DataBlockExtended")) // do we have the extended data?
{
char media_type_buffer[257];
msg->getString("DataBlockExtended", "MediaType", 255, media_type_buffer);
media_type = media_type_buffer;
msg->getU8("DataBlockExtended", "MediaLoop", media_loop);
msg->getS32("DataBlockExtended", "MediaWidth", media_width);
msg->getS32("DataBlockExtended", "MediaHeight", media_height);
}
LLParcel *parcel = gParcelMgr->getAgentParcel();
BOOL same = FALSE;
if (parcel)
{
same = ((parcel->getMediaURL() == media_url) &&
(parcel->getMediaType() == media_type) &&
(parcel->getMediaID() == media_id) &&
(parcel->getMediaWidth() == media_width) &&
(parcel->getMediaHeight() == media_height) &&
(parcel->getMediaAutoScale() == media_auto_scale) &&
(parcel->getMediaLoop() == media_loop));
}
if (!same)
LLViewerMedia::play(media_url, media_type, media_id,
media_auto_scale, media_width, media_height,
media_loop);
}
|