-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlisting9.html
executable file
·1180 lines (1016 loc) · 47.2 KB
/
listing9.html
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
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>SimpleVideoOut - /SimpleVideoOut.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/Carbon/index.html">Carbon</a> > <a href="../../samplecode/Carbon/idxQuickTime-date.html">QuickTime</a> > <A HREF="javascript:location.replace('index.html');">SimpleVideoOut</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">SimpleVideoOut</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/SimpleVideoOut.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/ChooseMovieClock.h</option>
<option value="listing2.html">/CVideoOutput.cpp</option>
<option value="listing3.html">/CVideoOutput.h</option>
<option value="listing4.html">/CVideoOutputComponent.cpp</option>
<option value="listing5.html">/CVideoOutputComponent.h</option>
<option value="listing6.html">/GetFile.c</option>
<option value="listing7.html">/GetFile.h</option>
<option value="listing8.html">/plist_carb.r</option>
<option value="listing9.html">/SimpleVideoOut.c</option>
<option value="listing10.html">/SimpleVideoOut_prefix.h</option>
<option value="listing11.html">/SimpleVideoOutMachO_prefix.h</option></select>
</p>
</form>
<p><strong><a href="SimpleVideoOut.zip">Download Sample</a></strong> (“SimpleVideoOut.zip”, 330.7K)<BR>
<strong><a href="SimpleVideoOut.dmg">Download Sample</a></strong> (“SimpleVideoOut.dmg”, 395.5K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/*
File: SimpleVideoOut.c
Description: SimpleVideoOut demonstrates how QuickTime Video Output Components can be
used to play video out to hardware. A common use would be playing a dv stream
(.dv file) out QuickTime's FireWire Video Output Component and recording it
on your handy dandy DV camera.
Author: QuickTime DTS
Version: 2.0.6
Copyright: © Copyright 2000 - 2005 Apple Computer, Inc. All rights reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first): <6> 07/15/03 added oDoc and respect the highQuality hint to
make jmb happy and added Close to make gd happy
<5> 09/25/02 fixed Clock UI to always reflect correct state
<4> 06/14/02 added ability to turn VOut off, minor UI changes
<3> 11/16/01 initial release version 2.0
<2> 07/27/01 carbonized & updated for QT5
<1> 01/28/00 initial release version 1.0
*/
#define TARGET_API_MAC_CARBON 1
#if __APPLE_CC__ || __MACH__
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>
#else
#include <Carbon.h>
#endif
#include <new> // for std::nothrow
#include "CVideoOutput.h"
using namespace dts;
const short kOSXMenuBar = 128;
const short kOS9MenuBar = 129;
const short kFileMenuIDX = 130;
const short kFileMenuID9 = 131;
const short kAlert = 128;
const short kAboutBox = 129;
const short kPopupMenu = 129;
const short kOpenID = 1;
const short kCloseID = 2;
const short kEchoOnID = 1;
const short kEchoOffID = 2;
const short kVOSoundOnID = 4;
const short kVOSoundOffID = 5;
const short kVOClockID = 7;
const short kDefaultClockID = 8;
const short kVOutOnID = 10;
const short kVOutOffID = 11;
const short kHighQOnID = 13;
const short kHighQOffID = 14;
const short kVOSelectID = 16;
const EventTime kMCIdleDuration = kEventDurationSecond / 30;
typedef struct {
WindowRef theWindow;
Movie theMovie;
MovieController theController;
CVideoOutput *pVideoOutput;
MenuRef thePopupMenuRef;
short theMCHeight;
EventLoopTimerRef theTimerRef;
} WindowDataRecord, *WindowDataRecordPtr;
// Globals
static WindowDataRecord gGlobals = { NULL };
static BitMap gScreenBits;
static short gFileMenuID = 0;
int main( void );
void Initialize( void );
OSErr DoOpen( ConstFSSpecPtr inFSSpecPtr, WindowDataRecordPtr inUserDataPtr );
OSErr StartVideoOutput( WindowDataRecordPtr inUserDataPtr );
OSErr DoOpenMovieFromFile( ConstFSSpecPtr inFSSpecPtr, WindowDataRecordPtr inUserDataPtr );
OSErr DoCreateMovieController( WindowDataRecordPtr inUserDataPtr );
void DoError( const unsigned char inErrorText[] );
Boolean IsHighQualityOn( Movie inMovie );
void SetMCEchoOffWindowSize( WindowDataRecordPtr inUserDataPtr );
void SetMCResizeBounds( WindowDataRecordPtr inUserDataPtr, Boolean inResizeable );
void SetMCPopupMenuState( WindowDataRecordPtr inUserDataPtr, short inState );
/* HandleAEOpenApplication
Open Application Event handler
*/
static pascal OSErr HandleAEOpenApplication( const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon )
{
#pragma unused(theAppleEvent, reply, handlerRefcon)
return ( DoOpen( NULL, &gGlobals ) );
}
/* HandleAEOpenDocument
Open Document Apple Event handler
*/
static pascal OSErr HandleAEOpenDocuments( const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon )
{
#pragma unused(reply, handlerRefcon)
AEDescList theDocList;
AEKeyword theKeyWord;
DescType theTypeCode;
FSSpec theFSSpec;
long theActualSize;
long numItems = 0;
OSErr err = noErr;
// only one document at a time
if ( gGlobals.theWindow ) return paramErr;
// get the direct parameter and put it into theDocList
theDocList.dataHandle = NULL;
err = AEGetParamDesc( theAppleEvent, keyDirectObject, typeAEList, &theDocList );
// count the descriptor records in the list
if ( noErr == err )
err = AECountItems( &theDocList, &numItems );
// need at least one, cuz we only grab the first
if ( numItems > 0 ) {
err = AEGetNthPtr( &theDocList, 1, typeFSS, &theKeyWord, &theTypeCode, (Ptr)&theFSSpec, sizeof(FSSpec), &theActualSize );
if ( noErr == err ) {
Boolean canOpenAsMovie;
err = CanQuickTimeOpenFile( &theFSSpec, 0, 0, NULL, &canOpenAsMovie, NULL, 0 );
if ( noErr == err && true == canOpenAsMovie ) {
err = DoOpen( &theFSSpec, &gGlobals );
}
}
}
if ( theDocList.dataHandle )
AEDisposeDesc( &theDocList );
return err;
}
/* HandleAEQuit
Quit Apple Event handler
*/
static pascal OSErr HandleAEQuit( const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon )
{
#pragma unused(theAppleEvent, reply, handlerRefcon)
HICommand theCommand = { kEventAttributeNone, kHICommandQuit };
ProcessHICommand( &theCommand );
return noErr;
}
/* myMCActionFilterWithRefConProc
Movie controller filter proc, this filter handles the custom button and size changed actions.
*/
static pascal Boolean myMCActionFilterWithRefConProc( MovieController theMC, short theAction, void *theParams, long theRefCon )
{
#pragma unused(theParams)
Boolean isHandled = false;
WindowDataRecordPtr pUserData = (WindowDataRecordPtr)theRefCon;
if ( pUserData == NULL ) return isHandled;
switch ( theAction ) {
case mcActionCustomButtonClick:
{
Rect theWindowBoundsRect, theMCBoundsRect;
// Don't want MCIdle calls while in here
SetEventLoopTimerNextFireTime( pUserData->theTimerRef, kEventDurationForever );
// Calculate the position for the CustomButton pop-up menu
RgnHandle theRgn = NewRgn();
GetWindowRegion( pUserData->theWindow, kWindowStructureRgn, theRgn );
GetRegionBounds( theRgn, &theWindowBoundsRect );
DisposeRgn( theRgn );
MCGetControllerBoundsRect( theMC, &theMCBoundsRect );
LocalToGlobal( (Point *)&theMCBoundsRect.bottom );
// Handle the menu selections and settings
long theResult = PopUpMenuSelect( pUserData->thePopupMenuRef, theMCBoundsRect.bottom - pUserData->theMCHeight, theWindowBoundsRect.right + 1, 0 );
short theItem = LoWord( theResult );
switch ( theItem ) {
case kEchoOnID:
MCSetControllerAttached( theMC, true );
pUserData->pVideoOutput->SetEchoPort( GetWindowPort(pUserData->theWindow) );
MCMovieChanged( theMC, pUserData->theMovie );
SetMCResizeBounds( pUserData, true );
MCDoAction( theMC, mcActionControllerSizeChanged, 0 );
SetMCPopupMenuState( pUserData, kEchoOnID );
break;
case kEchoOffID:
MCSetControllerAttached( theMC, false );
MCSetControllerPort( theMC, GetWindowPort( pUserData->theWindow ) );
SetMCResizeBounds( pUserData, false );
// resize the controller and the window to our echo off size
SetMCEchoOffWindowSize( pUserData );
pUserData->pVideoOutput->SetEchoPort();
SetMCPopupMenuState( pUserData, kEchoOffID );
break;
case kVOSoundOnID:
pUserData->pVideoOutput->SetSoundDevice();
// must set the clock after selecting the sound device
pUserData->pVideoOutput->SetClock();
SetMCPopupMenuState( pUserData, kVOSoundOnID );
break;
case kVOSoundOffID:
pUserData->pVideoOutput->SetSoundDevice( false );
// must set the clock after selecting the sound device
pUserData->pVideoOutput->SetClock( false );
SetMCPopupMenuState( pUserData, kVOSoundOffID );
break;
case kVOClockID:
pUserData->pVideoOutput->SetClock();
SetMCPopupMenuState( pUserData, kVOClockID );
break;
case kDefaultClockID:
pUserData->pVideoOutput->SetClock( false );
SetMCPopupMenuState( pUserData, kDefaultClockID );
break;
case kVOutOnID:
MCDoAction( theMC, mcActionPlay, 0 );
MCSetControllerAttached( theMC, true );
StartVideoOutput( pUserData );
SetMCPopupMenuState( pUserData, kVOutOnID );
break;
case kVOutOffID:
MCDoAction( theMC, mcActionPlay, 0 );
MCSetControllerAttached( theMC, true );
pUserData->pVideoOutput->SetEchoPort( GetWindowPort(pUserData->theWindow) );
SetMCResizeBounds( pUserData, true );
MCDoAction( theMC, mcActionControllerSizeChanged, 0 );
MCMovieChanged( theMC, pUserData->theMovie );
pUserData->pVideoOutput->End();
SetMCPopupMenuState( pUserData, kVOutOffID );
break;
case kHighQOnID:
SetMoviePlayHints( pUserData->theMovie, hintsHighQuality, hintsHighQuality );
SetMCPopupMenuState( pUserData, kHighQOnID );
break;
case kHighQOffID:
SetMoviePlayHints( pUserData->theMovie, 0, hintsHighQuality );
SetMCPopupMenuState( pUserData, kHighQOffID );
break;
case kVOSelectID:
MCDoAction( theMC, mcActionPlay, 0 );
MCSetControllerAttached( theMC, true );
MCDoAction( theMC, mcActionControllerSizeChanged, 0 );
// make sure to change the movies GWorld back to a valid window
// before shutting down the video output or bad things could happen
// if the VO component doesn't support echo this call translates to SetMovieGWorld()
pUserData->pVideoOutput->SetEchoPort( GetWindowPort(pUserData->theWindow) );
MCMovieChanged( theMC, pUserData->theMovie );
pUserData->pVideoOutput->Close();
pUserData->pVideoOutput->SelectVideoOutputComponent();
pUserData->pVideoOutput->Open();
if ( pUserData->pVideoOutput->GetError() || StartVideoOutput( pUserData ) ) { return false; }
break;
default:
break;
} // switch
SetEventLoopTimerNextFireTime( pUserData->theTimerRef, kMCIdleDuration );
isHandled = true;
break;
}
case mcActionControllerSizeChanged:
Rect theMCBoundsRect;
MCGetControllerBoundsRect( theMC, &theMCBoundsRect );
SizeWindow( pUserData->theWindow, theMCBoundsRect.right, theMCBoundsRect.bottom, true );
AlignWindow( pUserData->theWindow, false, NULL, NULL );
break;
default:
break;
} // switch
return isHandled;
}
/* myMovieControllerIdleTimer
Idle timer to give time to the MovieController.
*/
static pascal void myMovieControllerIdleTimer(EventLoopTimerRef inTimer, void *inUserData)
{
#pragma unused(inTimer)
WindowDataRecordPtr pUserData = (WindowDataRecordPtr)inUserData;
if ( pUserData->theController == NULL ) return;
MCIdle( pUserData->theController );
}
/* myWindowEventHandler
Carbon event handler for the window - This handler gives events over to
MCIsPlayerEvent so QuickTime can do all the work for us.
*/
static pascal OSStatus myWindowEventHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
#pragma unused(inHandlerCallRef)
UInt32 theEventKind = GetEventKind(inEvent);
OSStatus status = eventNotHandledErr;
static Fixed thePlayRate = 0;
WindowDataRecordPtr pUserData = (WindowDataRecordPtr)inUserData;
if ( pUserData == NULL ) return status;
switch ( theEventKind ) {
case kEventWindowClose:
MCDoAction( pUserData->theController, mcActionPlay, 0 );
MCSetControllerAttached( pUserData->theController, true );
// TransitionWindow will cause us to be re-entered with kEventWindowDeactivated
// so don't toss anything needed (like the TimerRef) before this call.
TransitionWindow( pUserData->theWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL );
// make sure to change the movies GWorld back to the window
// before shutting down the video output or bad things could happen
pUserData->pVideoOutput->SetEchoPort( GetWindowPort(pUserData->theWindow) );
MCMovieChanged( pUserData->theController, pUserData->theMovie );
pUserData->pVideoOutput->End();
RemoveEventLoopTimer( pUserData->theTimerRef );
DisposeMovieController( pUserData->theController );
DisposeMovie( pUserData->theMovie );
ReleaseWindow( pUserData->theWindow );
pUserData->theWindow = NULL;
pUserData->theMovie = NULL;
pUserData->theController = NULL;
pUserData->theMCHeight = 0;
pUserData->theTimerRef = NULL;
status = noErr;
break;
case kEventWindowActivated:
MCDoAction( pUserData->theController, mcActionPlay, (Ptr)thePlayRate );
SetEventLoopTimerNextFireTime( pUserData->theTimerRef, kMCIdleDuration );
goto passEventToController;
case kEventWindowDeactivated:
MCDoAction( pUserData->theController, mcActionGetPlayRate, &thePlayRate );
MCDoAction( pUserData->theController, mcActionPlay, 0 );
SetEventLoopTimerNextFireTime( pUserData->theTimerRef, kEventDurationForever );
// fall through
passEventToController:
default:
EventRecord theEvent;
ConvertEventRefToEventRecord( inEvent, &theEvent );
if ( MCIsPlayerEvent( pUserData->theController, &theEvent )) status = noErr;
break;
}
return status;
}
/* myApplicationEventHandler
Main application carbon event handler takes care of the HI commands and menu commands.
*/
static pascal OSStatus myApplicationEventHandler( EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData )
{
#pragma unused(inHandlerCallRef)
UInt32 theEventClass = GetEventClass( inEvent );
UInt32 theEventKind = GetEventKind( inEvent );
OSStatus status = eventNotHandledErr;
static Fixed thePlayRate = 0;
WindowDataRecordPtr pUserData = (WindowDataRecordPtr)inUserData;
if ( pUserData == NULL ) return status;
switch ( theEventClass ) {
case kEventClassCommand:
if ( kEventCommandProcess == theEventKind ) {
HICommand theCommand;
GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &theCommand );
switch ( theCommand.commandID ) {
case kHICommandAbout:
Alert( kAboutBox, NULL );
status = noErr;
break;
case kHICommandOpen:
status = DoOpen( NULL, pUserData );
break;
case kHICommandClose:
// If the window is open tell it to close
if ( pUserData->theWindow ) {
EventRef theWindowCloseEvent;
CreateEvent( NULL, kEventClassWindow, kEventWindowClose, 0, kEventAttributeNone, &theWindowCloseEvent );
SendEventToEventTarget( theWindowCloseEvent, GetWindowEventTarget( pUserData->theWindow ) );
ReleaseEvent( theWindowCloseEvent );
}
status = noErr;
break;
case kHICommandQuit:
{ // gcc complains without this in brackets
HICommand theCommand = { kEventAttributeNone, kHICommandClose };
ProcessHICommand( &theCommand );
QuitApplicationEventLoop();
status = noErr;
break;
}
default:
break;
}
}
break;
case kEventClassMenu:
{ // gcc complains without this in brackets
MenuRef theMenuRef = NULL;
GetEventParameter( inEvent, kEventParamDirectObject, typeMenuRef, NULL, sizeof(MenuRef), NULL, &theMenuRef );
switch ( theEventKind ) {
case kEventMenuBeginTracking:
if ( pUserData->theController ) {
// If the movie is playing, stop it during menu tracking then start it
// up again or bad things can happen under 9
MCDoAction( pUserData->theController, mcActionGetPlayRate, &thePlayRate );
MCDoAction( pUserData->theController, mcActionPlay, 0 );
SetEventLoopTimerNextFireTime( pUserData->theTimerRef, kEventDurationForever );
status = noErr;
}
break;
case kEventMenuEndTracking:
if ( pUserData->theController ) {
MCDoAction( pUserData->theController, mcActionPlay, (Ptr)thePlayRate );
SetEventLoopTimerNextFireTime( pUserData->theTimerRef, kMCIdleDuration );
status = noErr;
}
break;
case kEventMenuEnableItems:
if ( GetMenuRef( gFileMenuID ) == theMenuRef ) {
WindowRef theDocumentWindowRef = GetFrontWindowOfClass( kDocumentWindowClass, true );
WindowRef theFrontNonFloatingWindowRef = FrontNonFloatingWindow();
if ( pUserData->theWindow &&
pUserData->theWindow == theDocumentWindowRef &&
pUserData->theWindow == theFrontNonFloatingWindowRef ) {
DisableMenuItem( theMenuRef, kOpenID );
EnableMenuItem( theMenuRef, kCloseID );
} else if ( theFrontNonFloatingWindowRef == NULL ) {
EnableMenuItem( theMenuRef, kOpenID );
DisableMenuItem( theMenuRef, kCloseID );
} else {
DisableMenuItem( theMenuRef, 0 );
}
status = noErr;
}
break;
}
break;
}
default:
break;
}
return status;
}
#pragma mark-
/* DoError
Display error alert
*/
void DoError( const unsigned char inErrorText[] )
{
ParamText( inErrorText, NULL, NULL, NULL );
StopAlert( kAlert, NULL );
}
/* IsHighQualityOn
Figure out if any visual tracks in the movie were saved with the
High Quality hint on. If so turn on the HighQuality play hint for the movie.
*/
Boolean IsHighQualityOn( Movie inMovie )
{
Track theTrack;
UInt8 theCount;
Boolean rc = false;
theCount = GetMovieTrackCount( inMovie );
while ( theCount ) {
// get an enabled visual track
theTrack = GetMovieIndTrackType( inMovie, theCount--, VisualMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly );
if ( theTrack ) {
long theDefaultHints;
GetTrackLoadSettings( theTrack, NULL, NULL, NULL, &theDefaultHints );
if ( !GetMoviesError() )
if ( theDefaultHints & hintsHighQuality ) {
rc = true;
break;
}
}
}
return rc;
}
/* SetMCEchoOffWindowSize
When echo is off there's no need to show an empty window so, resize
the controller to a fixed size and size the window appropriately.
*/
void SetMCEchoOffWindowSize( WindowDataRecordPtr inUserDataPtr )
{
Rect theMCBoundsRect = { 0, 0, inUserDataPtr->theMCHeight, 320 };
MCSetControllerBoundsRect( inUserDataPtr->theController, &theMCBoundsRect );
MCDoAction( inUserDataPtr->theController, mcActionControllerSizeChanged, 0 );
}
/* SetMCResizeBounds
Turn on/off the movie controllers ability to resize.
*/
void SetMCResizeBounds( WindowDataRecordPtr inUserDataPtr, Boolean inResizeable )
{
Rect theResizeBounds = { 0, 0, 0, 0 }; // if inResizeable is false use the empty rect to turn it off
if ( inResizeable ) {
// we can resize from full size down to half size
GetMovieNaturalBoundsRect( inUserDataPtr->theMovie, &theResizeBounds );
theResizeBounds.top = theResizeBounds.bottom / 2;
theResizeBounds.left = theResizeBounds.right / 2;
}
MCDoAction( inUserDataPtr->theController, mcActionSetGrowBoxBounds, &theResizeBounds);
}
/* SetMCPopupMenuState
Make sure the menu items are in sync with the video output settings.
*/
void SetMCPopupMenuState( WindowDataRecordPtr inUserDataPtr, short inState )
{
switch (inState) {
case 0: // default state
{
if ( inUserDataPtr->pVideoOutput->CanDoEchoPort() ) {
// SimpleVideoOut always set an echo port if the VO can do it
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID, true );
CheckMenuItem ( inUserDataPtr->thePopupMenuRef, kEchoOffID, false );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID);
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOffID);
} else {
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID, false );
CheckMenuItem ( inUserDataPtr->thePopupMenuRef, kEchoOffID, true );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID);
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOffID);
}
if ( inUserDataPtr->pVideoOutput->HasSoundOutput() ) {
// Begin() by default uses the VO sound output if there is one
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID, false );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID);
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID);
} else {
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID, true );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID);
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID);
}
if ( inUserDataPtr->pVideoOutput->HasClock() ) {
// Begin() by default makes sure to use the VO clock if there is one
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID, false );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID);
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID);
} else {
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID, true );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID);
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID);
}
// Video Output On by default
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOnID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOffID, false );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOffID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOnID );
// High Quality Off by default
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOnID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOffID, true );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOnID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOffID );
break;
}
case kEchoOnID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID, true );
CheckMenuItem ( inUserDataPtr->thePopupMenuRef, kEchoOffID, false );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOffID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID );
break;
case kEchoOffID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID, false );
CheckMenuItem ( inUserDataPtr->thePopupMenuRef, kEchoOffID, true );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOffID );
break;
case kVOSoundOnID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID, false );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID );
if ( inUserDataPtr->pVideoOutput->HasClock() ) {
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID, false );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID );
}
break;
case kVOSoundOffID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID, true );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID );
if ( inUserDataPtr->pVideoOutput->HasClock() ) {
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID, true );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID );
}
break;
case kVOClockID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID, false );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID );
break;
case kDefaultClockID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID, true );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID );
break;
case kVOutOnID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOnID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOffID, false );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOffID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOnID );
break;
case kVOutOffID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOnID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOffID, true );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOnID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOutOffID );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOffID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID, false );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOnID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kEchoOffID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOnID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOSoundOffID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kVOClockID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kDefaultClockID );
break;
case kHighQOnID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOnID, true );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOffID, false );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOffID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOnID );
break;
case kHighQOffID:
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOnID, false );
CheckMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOffID, true );
EnableMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOnID );
DisableMenuItem( inUserDataPtr->thePopupMenuRef, kHighQOffID );
break;
default:
break;
} // switch
}
/* Initialize
Yer basic init stuff, if any of this fails we ask for our bill
and take the express elevator straight to hell - ya, let Bishop go.
*/
void Initialize( void )
{
EventHandlerRef theEventRef = NULL;
Handle theMenuBar = NULL;
const long kVersion10 = 0x00001000;
// Common Application events we want for 9 and X
EventTypeSpec theEventTypes[] = { { kEventClassCommand, kEventCommandProcess},
{ kEventClassMenu, kEventMenuEnableItems }};
// Application events we only want when running on 9
EventTypeSpec theEventTypes9[] = { { kEventClassMenu, kEventMenuBeginTracking},
{ kEventClassMenu, kEventMenuEndTracking }};
long result, systemVersion;
InitCursor();
FlushEvents( everyEvent, 0 );
// Check the cell structure
if ( Gestalt( gestaltQuickTime, &result ) != noErr) {
DoError( "\pQuickTime is not installed...Doh!" );
ExitToShell();
}
// Remember to call EnterMovies even on X!
EnterMovies();
GetQDGlobalsScreenBits( &gScreenBits );
result = Gestalt( gestaltSystemVersion, &systemVersion );
if ( result == noErr ) {
// Can I get a menu?
if ( systemVersion >= kVersion10 ) {
theMenuBar = GetNewMBar( kOSXMenuBar );
gFileMenuID = kFileMenuIDX;
} else {
theMenuBar = GetNewMBar( kOS9MenuBar );
gFileMenuID = kFileMenuID9;
}
if ( theMenuBar ) {
SetMenuBar( theMenuBar );
DrawMenuBar();
} else {
DoError( "\pCould not load menu bar..." );
ExitToShell();
}
} else {
DoError( "\pGestalt gestaltSystemVersion failed..." );
ExitToShell();
}
// Get the movie controller CustomPopup menu
gGlobals.thePopupMenuRef = GetMenu( kPopupMenu );
if ( gGlobals.thePopupMenuRef == NULL ) {
DoError( "\pCould not load menu resource..." );
ExitToShell();
}
// Instantiate a VideoOutput object without a specific Movie
gGlobals.pVideoOutput = new(std::nothrow) CVideoOutput( "\pSimpleVideoOut" );
if ( gGlobals.pVideoOutput == NULL || gGlobals.pVideoOutput->GetError() ) {
DoError( "\pProblem initializing CVideoOutput, or component unavailable..." );
ExitToShell();
}
// Install the Apple event handlers
result = AEInstallEventHandler( kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(HandleAEOpenApplication), 0, false );
if ( result ) { DoError( "\pProblem installing kAEOpenApplication Handler..." ); ExitToShell(); }
result = AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(HandleAEOpenDocuments), 0, false );
if ( result ) { DoError( "\pProblem installing kAEOpenDocuments Handler..." ); ExitToShell(); }
result = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(HandleAEQuit), 0, false );
if ( result ) { DoError( "\pProblem installing kAEQuitApplication Handler..." ); ExitToShell(); }
if ( InstallStandardEventHandler( GetApplicationEventTarget() )) { DoError( "\pProblem installing Standard App. Event Handler..." ); ExitToShell(); }
if ( InstallApplicationEventHandler( NewEventHandlerUPP( myApplicationEventHandler ), GetEventTypeCount( theEventTypes ), theEventTypes, &gGlobals, &theEventRef )) {
DoError( "\pProblem installing Application Event Handler..." );
ExitToShell();
}
if ( systemVersion < kVersion10 ) {
if ( AddEventTypesToHandler( theEventRef, GetEventTypeCount( theEventTypes9 ), theEventTypes9 )) { DoError( "\pProblem adding OS9 Carbon Events..." ); ExitToShell(); }
}
}
/* DoOpenMovieFromFile
This function Opens a selected movie and creates a window.
*/
OSErr DoOpenMovieFromFile( ConstFSSpecPtr inFSSpecPtr, WindowDataRecordPtr inUserDataPtr )
{
Rect theWindowRect = { 50, 20, 300, 300 };
Rect theMovieBox;
short theMovieRefNum;
OSErr rc = noErr;
// Create a new window for the movie
rc = CreateNewWindow( kDocumentWindowClass, kWindowCloseBoxAttribute, &theWindowRect, &(inUserDataPtr->theWindow) );
if ( inUserDataPtr->theWindow == NULL ) rc = errInvalidWindowRef;
if ( rc ) goto bail;
SetWTitle( inUserDataPtr->theWindow, inFSSpecPtr->name );
SetPortWindowPort( inUserDataPtr->theWindow );
// Open the movie file
rc = OpenMovieFile( inFSSpecPtr, &theMovieRefNum, fsRdPerm );
if ( rc ) goto bail;
rc = NewMovieFromFile( &(inUserDataPtr->theMovie), theMovieRefNum, NULL, NULL, newMovieActive, NULL );
CloseMovieFile( theMovieRefNum );
if ( rc ) goto bail;
GetMovieNaturalBoundsRect( inUserDataPtr->theMovie, &theMovieBox );
OffsetRect( &theMovieBox, -theMovieBox.left, -theMovieBox.top );
SetMovieBox( inUserDataPtr->theMovie, &theMovieBox );
// Tell the output component about the movie
inUserDataPtr->pVideoOutput->SetMovie( inUserDataPtr->theMovie );
bail:
return rc;
}
/* DoCreateMovieController
This function creates a movie controller and sizes the window appropriately,
it also installs the windows event handlers, shows the window, installs
the MCAction filter and finally installs the MCIdle carbon timer.
*/
OSErr DoCreateMovieController( WindowDataRecordPtr inUserDataPtr )
{
EventTypeSpec theEventTypes[] = { { kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp },
{ kEventClassKeyboard, kEventRawKeyDown },
{ kEventClassKeyboard, kEventRawKeyRepeat },
{ kEventClassKeyboard, kEventRawKeyUp },
{ kEventClassWindow, kEventWindowUpdate },
{ kEventClassWindow, kEventWindowActivated },
{ kEventClassWindow, kEventWindowDeactivated },
{ kEventClassWindow, kEventWindowClose } };
Rect theMovieBox;
long mcFlags;
OSErr rc = noErr;
GetMovieBox( inUserDataPtr->theMovie, &theMovieBox );
inUserDataPtr->theMCHeight = theMovieBox.bottom;
// Create the movie controller
inUserDataPtr->theController = NewMovieController( inUserDataPtr->theMovie, &theMovieBox, mcTopLeftMovie );
if ( inUserDataPtr->theController == NULL) { rc = illegalControllerOSErr; goto bail; }
// Enable keys, give us a custom button and turn off stuff
MCDoAction( inUserDataPtr->theController, mcActionSetKeysEnabled, (Ptr)true );
MCDoAction( inUserDataPtr->theController, mcActionGetFlags, &mcFlags );
MCDoAction( inUserDataPtr->theController, mcActionSetFlags, (Ptr)( mcFlags | mcFlagsUseCustomButton ));
MCDoAction( inUserDataPtr->theController, mcActionSetDragEnabled, (Ptr)false );
MCDoAction( inUserDataPtr->theController, mcActionSetUseBadge, (Ptr)false );
rc = MCGetControllerBoundsRect( inUserDataPtr->theController, &theMovieBox );
if ( rc ) goto bail;
inUserDataPtr->theMCHeight = theMovieBox.bottom - inUserDataPtr->theMCHeight;