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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
|
/**
* @file llmediaimplquicktime.cpp
* @brief implementation that supports Apple QuickTime media.
*
* Copyright (c) 2005-2007, 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://secondlife.com/developers/opensource/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://secondlife.com/developers/opensource/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.
*/
#include "linden_common.h"
#if LL_QUICKTIME_ENABLED
#include <iostream>
#include "llmediaimplquicktime.h"
#include "llgl.h"
#include "llglheaders.h" // For gl texture modes
///////////////////////////////////////////////////////////////////////////////
//
LLMediaImplQuickTime::
LLMediaImplQuickTime () :
theController ( NULL ),
currentMode ( ModeIdle ),
theGWorld ( 0 ),
theMovie ( 0 ),
mediaData ( 0 ),
loopsLeft ( 0 ),
ownBuffer ( TRUE ),
curVolume ( 0 ),
sizeChangeInProgress ( FALSE ),
initialStartDone ( FALSE ),
autoScaled ( FALSE )
{
// These should probably be in the initializer list above, but that seemed uglier...
#if LL_DARWIN
// Mac OS -- gworld will be xRGB (4 byte pixels, like ARGB, but QuickDraw doesn't actually do alpha...)
mMediaDepthBytes = 4;
mTextureDepth = 4;
mTextureFormatInternal = GL_RGB8;
mTextureFormatPrimary = GL_BGRA;
#ifdef LL_BIG_ENDIAN
mTextureFormatType = GL_UNSIGNED_INT_8_8_8_8_REV;
#else
mTextureFormatType = GL_UNSIGNED_INT_8_8_8_8;
#endif
#else
// Windows -- GWorld will be RGB (3 byte pixels)
mMediaDepthBytes = 3;
mTextureDepth = 3;
mTextureFormatInternal = GL_RGB8;
mTextureFormatPrimary = GL_RGB;
mTextureFormatType = GL_UNSIGNED_BYTE;
#endif
};
///////////////////////////////////////////////////////////////////////////////
//
LLMediaImplQuickTime::
~LLMediaImplQuickTime ()
{
unload();
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
setBuffer ( U8* bufferIn )
{
OSErr err = noErr;
// If we're waiting for a size change, we just got one.
sizeChangeInProgress = FALSE;
// Since we've pointed QuickTime at the old media data buffer directly, we need to be somewhat careful deleting it...
U8* oldMediaData = mediaData;
BOOL ownedMediaData = ownBuffer;
#if LL_DARWIN
GWorldPtr oldGWorld = theGWorld;
#endif
if(bufferIn == NULL)
{
// Passing NULL to this function requests that the object allocate its own buffer.
mediaData = new unsigned char [ mMediaHeight * mMediaRowbytes ];
ownBuffer = TRUE;
}
else
{
// Use the supplied buffer.
mediaData = bufferIn;
ownBuffer = FALSE;
}
if(mediaData == NULL)
{
// This is bad.
llerrs << "LLMediaImplQuickTime::setBuffer: mediaData is NULL" << llendl;
// NOTE: This case doesn't clean up properly. This assert is fatal, so this isn't a huge problem,
// but if this assert is ever removed the code should be fixed to clean up correctly.
return FALSE;
}
err = NewGWorldFromPtr ( &theGWorld, mMediaDepthBytes * 8, &movieRect, NULL, NULL, 0, (Ptr)mediaData, mMediaRowbytes);
if(err == noErr)
{
if(theMovie)
{
// tell the movie about it
SetMovieGWorld ( theMovie, theGWorld, GetGWorldDevice ( theGWorld ) );
}
if(theController)
{
// and tell the movie controller about it.
MCSetControllerPort(theController, theGWorld);
}
#if LL_DARWIN
// NOTE: (CP) This call ultimately leads to a crash in NewGWorldFromPtr on Windows (only)
// Not calling DisposeGWorld doesn't appear to leak anything significant and stops the crash occuring.
// This will eventually be fixed but for now, leaking slightly is better than crashing.
if ( oldGWorld != NULL )
{
// Delete the old GWorld
DisposeGWorld ( oldGWorld );
oldGWorld = NULL;
}
#endif
}
else
{
// Hmm... this may be bad. Assert here?
llerrs << "LLMediaImplQuickTime::setBuffer: NewGWorldFromPtr failed" << llendl;
theGWorld = NULL;
return FALSE;
}
// Delete the old media data buffer iff we owned it.
if ( ownedMediaData )
{
if ( oldMediaData )
{
delete [] oldMediaData;
}
}
// build event and emit it
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
init ()
{
// movied to main application initialization for now because it's non-trivial and only needs to be done once
// (even though it goes against the media framework design)
//if ( InitializeQTML ( 0L ) != 0 )
//{
// return FALSE;
//};
//if ( EnterMovies () != 0 )
//{
// return FALSE;
//};
return LLMediaMovieBase::init();
}
///////////////////////////////////////////////////////////////////////////////
//
void
LLMediaImplQuickTime::
updateMediaSize()
{
if((theController == NULL) && (!isQTLoaded()))
{
// The movie's not loaded enough to get info about it yet.
// Set up a dummy buffer.
movieRect.left = movieRect.top = 0;
movieRect.right = movieRect.bottom = 64;
mMediaRowbytes = mMediaDepthBytes * 64;
mMediaWidth = 64;
mMediaHeight = 64;
mTextureWidth = 64;
mTextureHeight = 64;
return;
}
// pick up the size of the movie
GetMovieBox ( theMovie, &movieRect );
// save the size of the media so consumer of media class can use it
mMediaWidth = movieRect.right - movieRect.left;
mMediaHeight = movieRect.bottom - movieRect.top;
// Giant media could make us try to use textures bigger than the opengl implementation can handle.
// Pin the maximum X or Y dimension to 1024.
// NOTE: 1024x1024 may still hurt a lot, but it shouldn't cause opengl to flame out.
if(mMediaWidth > 1024)
{
mMediaWidth = 1024;
}
if(mMediaHeight > 1024)
{
mMediaHeight = 1024;
}
// calculate the texture size required to hold media of this size (next power of 2 bigger)
for ( mTextureWidth = 1; mTextureWidth < mMediaWidth; mTextureWidth <<= 1 )
{
};
for ( mTextureHeight = 1; mTextureHeight < mMediaHeight; mTextureHeight <<= 1 )
{
};
// llinfos << "Media texture size will be " << mTextureWidth << " x " << mTextureHeight << llendl;
// if autoscale is on we simply make the media & texture sizes the same and quicktime does all the hard work
if ( autoScaled )
{
// Stretch the movie to fill the texture.
mMediaWidth = mTextureWidth;
mMediaHeight = mTextureHeight;
// scale movie using high quality but slow algorithm.
// NOTE: this results in close to same quality as texture scaling option but with (perhaps) significant
// loss of performance (e.g. my machine, release build, frame rate goes from 92 -> 82 fps
// To revert to original behaviour, just remove the line below.
// MBW -- There seems to be serious drop in performance above a particular size, on both low and high end machines.
// 512x256 is fine, while 512x512 is unusable. I theorize that this is due to CPU cache getting broken around that size.
if((mTextureWidth * mTextureHeight) <= (512 * 256))
{
// llinfos << "Setting high-quality hint." << llendl;
SetMoviePlayHints ( theMovie, hintsHighQuality, hintsHighQuality );
}
};
// always flip movie using quicktime (little performance impact and no loss in quality)
if ( TRUE )
{
// Invert the movie in the Y directon to match the expected orientation of GL textures.
MatrixRecord transform;
GetMovieMatrix ( theMovie, &transform );
double centerX = mMediaWidth / 2.0;
double centerY = mMediaHeight / 2.0;
ScaleMatrix ( &transform, X2Fix ( 1.0 ), X2Fix ( -1.0 ), X2Fix ( centerX ), X2Fix ( centerY ) );
SetMovieMatrix ( theMovie, &transform );
};
movieRect.left = 0;
movieRect.top = 0;
movieRect.right = mMediaWidth;
movieRect.bottom = mMediaHeight;
// Calculate the rowbytes of the texture
mMediaRowbytes = mMediaWidth * mMediaDepthBytes;
SetMovieBox(theMovie, &movieRect);
if(theController == NULL)
{
SetGWorld(theGWorld, NULL);
// Create a movie controller for the movie
theController = NewMovieController(theMovie, &movieRect, mcNotVisible|mcTopLeftMovie);
MCSetActionFilterWithRefCon(theController, myMCActionFilterProc, (long)this);
// Allow the movie to dynamically resize (may be necessary for streaming movies to work right...)
SetMoviePlayHints(theMovie, hintsAllowDynamicResize, hintsAllowDynamicResize);
}
else
{
MCPositionController(theController, &movieRect, &movieRect, mcTopLeftMovie|mcPositionDontInvalidate);
}
}
///////////////////////////////////////////////////////////////////////////////
//
void
LLMediaImplQuickTime::
setupDummyBuffer()
{
// Used when the movie can't be drawn for some reason. This sets up a buffer that keeps callers from getting annoyed.
movieRect.left = movieRect.top = 0;
movieRect.right = movieRect.bottom = 64;
mMediaRowbytes = mMediaDepthBytes * 64;
mMediaWidth = 64;
mMediaHeight = 64;
mTextureWidth = 64;
mTextureHeight = 64;
setBuffer ( NULL );
memset(mediaData, 0, mMediaRowbytes * mMediaHeight );
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
load ( const LLString& urlIn )
{
// The movie may do things to the current port when it's created. Make sure we have a valid port set.
setupDummyBuffer();
SetGWorld(theGWorld, NULL);
Size mySize = ( Size ) urlIn.length () + 1;
if ( mySize == 0 )
return FALSE;
Handle myHandle = NewHandleClear ( mySize );
if ( myHandle == NULL )
return FALSE;
BlockMove ( urlIn.c_str (), *myHandle, mySize );
// Might be able to make this asynchronous with (newMovieActive|newMovieAsyncOK|newMovieIdleImportOK)?
OSErr err = NewMovieFromDataRef ( &theMovie, newMovieActive|newMovieDontInteractWithUser|newMovieAsyncOK|newMovieIdleImportOK, NULL, myHandle, URLDataHandlerSubType );
if ( err != noErr )
return false;
// function that gets called when a frame is drawn
SetMovieDrawingCompleteProc ( theMovie, movieDrawingCallWhenChanged, myFrameDrawnCallback, ( long ) this );
if(isQTLoaded())
{
updateMediaSize();
setBuffer(NULL);
}
// Tell the controller to play the movie. This also deals with the movie still loading.
//play();
return LLMediaMovieBase::load(urlIn);
}
///////////////////////////////////////////////////////////////////////////////
//
OSErr
LLMediaImplQuickTime::
myFrameDrawnCallback ( Movie callbackMovie, long refCon )
{
LLMediaImplQuickTime* myQtRenderer = ( LLMediaImplQuickTime* ) refCon;
// The gworld quicktime is playing back into is now wrapped around myQtRenderer->mediaData,
// so there's no need to copy any data here.
#if 0
Ptr pixels = GetPixBaseAddr ( myQtRenderer->pixmapHandle );
LockPixels ( myQtRenderer->pixmapHandle );
memcpy ( ( U8* ) myQtRenderer->mediaData, pixels, myQtRenderer->getMediaBufferSize () ); /* Flawfinder: ignore */
UnlockPixels ( myQtRenderer->pixmapHandle );
#endif
myQtRenderer->bufferChanged();
return 0;
}
///////////////////////////////////////////////////////////////////////////////
Boolean
LLMediaImplQuickTime::myMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon)
{
Boolean result = false;
LLMediaImplQuickTime *self = (LLMediaImplQuickTime*)theRefCon;
switch ( theAction )
{
// handle window resizing
case mcActionControllerSizeChanged:
self->sizeChanged();
break;
// Block any movie controller actions that open URLs.
case mcActionLinkToURL:
case mcActionGetNextURL:
case mcActionLinkToURLExtended:
// Prevent the movie controller from handling the message
result = true;
break;
default:
break;
};
return ( result );
}
///////////////////////////////////////////////////////////////////////////////
//
void
LLMediaImplQuickTime::rewind()
{
// MBW -- XXX -- I don't see an easy way to do this via the movie controller.
GoToBeginningOfMovie ( theMovie );
// Call this afterwards so the movie controller can sync itself with the movie.
MCMovieChanged(theController, theMovie);
#if 0
// Maybe something like this?
TimeRecord when;
when.value.hi = 0;
when.value.lo = 0;
when.scale = GetMovieTimeScale(theMovie);
// This seems like the obvious thing, but a tech note (http://developer.apple.com/technotes/qt/qt_510.html) says otherwise...
// when.base = GetMovieTimeBase(theMovie);
when.base = 0;
MCDoAction(theController, mcActionGoToTime, &when);
#endif
}
///////////////////////////////////////////////////////////////////////////////
//
void
LLMediaImplQuickTime::sizeChanged()
{
// Set the movie to render (well, actually NOT render) to an internal buffer until the size change can be handled.
setupDummyBuffer();
// Make the next call to updateMedia request a size change.
sizeChangeInProgress = true;
// Recalculate the values that depend on the movie rect.
updateMediaSize();
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isQTLoaded()
{
BOOL result = false;
if(theMovie)
{
if(GetMovieLoadState(theMovie) >= kMovieLoadStateLoaded)
{
result = true;
}
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isQTPlaythroughOK()
{
BOOL result = false;
if(theMovie)
{
if(GetMovieLoadState(theMovie) >= kMovieLoadStatePlaythroughOK)
{
result = true;
}
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
unload ()
{
if( theController )
{
// Slight paranoia...
MCSetActionFilterWithRefCon(theController, NULL, (long)this);
DisposeMovieController( theController );
theController = NULL;
};
if ( theMovie )
{
// Slight paranoia...
SetMovieDrawingCompleteProc ( theMovie, movieDrawingCallWhenChanged, nil, ( long ) this );
DisposeMovie ( theMovie );
theMovie = NULL;
};
if ( theGWorld )
{
DisposeGWorld ( theGWorld );
theGWorld = NULL;
};
if ( mediaData )
{
if ( ownBuffer )
{
delete mediaData;
mediaData = NULL;
};
};
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
S32
LLMediaImplQuickTime::
updateMedia ()
{
if(!theController)
{
if(isQTLoaded())
{
// Movie has finished loading. Request a size change to update buffers, etc.
// We MUST update the media size here, so it will be correct before the size change request.
updateMediaSize();
return updateMediaNeedsSizeChange;
}
else
{
// Movie is still loading.
MoviesTask ( theMovie, 0 );
}
}
if(theController)
{
switch(currentMode)
{
case ModePlaying:
case ModeLooping:
if(!initialStartDone)
{
if(isQTPlaythroughOK())
{
// The movie is loaded enough to start playing. Start it now.
MCDoAction(theController, mcActionPrerollAndPlay, (void*)GetMoviePreferredRate(theMovie));
MCDoAction(theController, mcActionSetVolume, (void*)curVolume );
initialStartDone = TRUE;
}
}
break;
}
// // This function may copy decompressed movie frames into our media data pointer. JC
// if (!mediaData)
// {
// llwarns << "LLMediaImplQuickTime::updateMedia() about to update with null media pointer" << llendl;
// }
// else
// {
// // try writing to the pointer to see if it's valid
// *mediaData = 0;
// }
MCIdle(theController);
}
// If we need a size change, that takes precedence.
if(sizeChangeInProgress)
{
return updateMediaNeedsSizeChange;
}
BOOL updated = getBufferChanged();
resetBufferChanged();
if(updated)
return updateMediaNeedsUpdate;
// don't use movie controller for looping - appears to be broken on PCs (volume issue)
if ( currentMode == ModeLooping )
if ( IsMovieDone ( theMovie ) )
loop ( 0 );
return updateMediaNoChanges;
}
///////////////////////////////////////////////////////////////////////////////
//
void
LLMediaImplQuickTime::
setAutoScaled ( BOOL autoScaledIn )
{
autoScaled = autoScaledIn;
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
stop ()
{
currentMode = ModeStopped;
if(theController)
{
Fixed rate = X2Fix(0.0);
MCDoAction(theController, mcActionPlay, (void*)rate);
rewind();
}
return LLMediaMovieBase::stop();
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
play ()
{
currentMode = ModePlaying;
if(theController)
{
if ( IsMovieDone ( theMovie ) )
{
rewind();
};
MCDoAction(theController, mcActionPrerollAndPlay, (void*)GetMoviePreferredRate(theMovie));
MCDoAction(theController, mcActionSetVolume, (void*)curVolume );
}
return LLMediaMovieBase::play();
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
loop ( S32 howMany )
{
currentMode = ModeLooping;
// MBW -- XXX -- This may be harder to do with a movie controller...
// loopsLeft = howMany;
if ( theController )
{
// Movie is loaded and set up.
if ( IsMovieDone ( theMovie ) )
{
rewind();
};
MCDoAction(theController, mcActionPrerollAndPlay, (void*)GetMoviePreferredRate(theMovie));
MCDoAction(theController, mcActionSetVolume, (void*)curVolume );
}
return LLMediaMovieBase::loop(howMany);
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
pause ()
{
currentMode = ModePaused;
if(theController)
{
// Movie is loaded and set up.
Fixed rate = X2Fix(0.0);
MCDoAction(theController, mcActionPlay, (void*)rate);
}
return LLMediaMovieBase::pause();
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
setVolume ( F32 volumeIn )
{
// Fixed point signed short, 8.8
curVolume = (short)(volumeIn * ( F32 ) 0x100);
if(theController != NULL)
{
MCDoAction(theController, mcActionSetVolume, (void*)curVolume);
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
F32
LLMediaImplQuickTime::
getVolume ()
{
return ( ( F32 ) curVolume ) / ( F32 ) 0x100;
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isIdle () const
{
return ( currentMode == ModeIdle );
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isError () const
{
return ( currentMode == ModeError );
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isBuffering () const
{
return ( currentMode == ModeBuffering );
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isLoaded () const
{
// Only tell the caller the movie is loaded if we've had a chance to set up the movie controller.
return (theController != NULL);
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isPlaying () const
{
return ( currentMode == ModePlaying );
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isLooping () const
{
return ( currentMode == ModeLooping );
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isPaused () const
{
return ( currentMode == ModePaused );
};
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
isStopped () const
{
return ( currentMode == ModeStopped );
};
///////////////////////////////////////////////////////////////////////////////
//
U8*
LLMediaImplQuickTime::
getMediaData ()
{
return mediaData;
}
///////////////////////////////////////////////////////////////////////////////
//
BOOL
LLMediaImplQuickTime::
seek ( F64 time )
{
// MBW -- XXX -- This should stash the time if theController is NULL, and seek to there when the movie's loaded.
// Do this later.
if(theController != NULL)
{
TimeRecord when;
when.scale = GetMovieTimeScale(theMovie);
when.base = 0;
// 'time' is in (floating point) seconds. The timebase time will be in 'units', where
// there are 'scale' units per second.
S64 rawTime = (S64)(time * (F64)(when.scale));
when.value.hi = ( SInt32 ) ( rawTime >> 32 );
when.value.lo = ( SInt32 ) ( ( rawTime & 0x00000000FFFFFFFF ) );
MCDoAction(theController, mcActionGoToTime, &when);
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
F64
LLMediaImplQuickTime::
getTime () const
{
F64 result = 0;
if(theController != NULL)
{
TimeValue time;
TimeScale scale = 0;
time = MCGetCurrentTime(theController, &scale);
if(scale != 0)
{
result = ((F64)time) / ((F64)scale);
}
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
//
F64
LLMediaImplQuickTime::
getMediaDuration () const
{
F64 result = 0;
TimeScale scale = GetMovieTimeScale(theMovie);
TimeValue duration = GetMovieDuration(theMovie);
if(duration == kQTSUnknownDuration)
{
// Hmph.
// Return 0 in this case.
}
else if(duration == kQTSInfiniteDuration)
{
// This is the magic number for "indefinite duration", i.e. a live stream.
// Note that the docs claim this value is 0x7FFFFFF, while the symbolic constant is 0x7FFFFFFF. Go figure.
// Return 0 in this case.
}
else if(scale != 0)
{
// Timescale is a useful number. Convert to seconds.
result = (F64)duration;
result /= (F64)scale;
}
return result;
}
#endif
|