-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing6.html
executable file
·1963 lines (1461 loc) · 68.3 KB
/
listing6.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>CompressMovies - /DTSQTUtilities.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/QuickTime/index.html">QuickTime</a> > <a href="../../samplecode/QuickTime/idxCompressionDecompression-date.html">Compression & Decompression</a> > <A HREF="javascript:location.replace('index.html');">CompressMovies</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">CompressMovies</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>/DTSQTUtilities.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">/Carbon.r</option>
<option value="listing2.html">/CompressMovie.c</option>
<option value="listing3.html">/CompressMovie.h</option>
<option value="listing4.html">/CompressMoviesMain.c</option>
<option value="listing5.html">/CompressMoviesMain.h</option>
<option value="listing6.html">/DTSQTUtilities.c</option>
<option value="listing7.html">/DTSQTUtilities.h</option></select>
</p>
</form>
<p><strong><a href="CompressMovies.zip">Download Sample</a></strong> (“CompressMovies.zip”, 230.0K)<BR>
<strong><a href="CompressMovies.dmg">Download Sample</a></strong> (“CompressMovies.dmg”, 305.8K)</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: DTSQTUtilities.c
Contains: QuickTime functions.
Written by:
Copyright: Copyright © 1991-2001 by 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):
11/7/2001 srk Carbonized
7/28/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
*/
// INCLUDES
#include "DTSQTUtilities.h"
// MOVIE TOOLBOX FUNCTIONS
/*______________________________________________________________________
QTUIsQuickTimeInstalled - Test if QuickTime is installed.
pascal Boolean QTUIsQuickTimeInstalled(void)
DESCRIPTION
InitQuickTime will test if QuickTime is present. We are not interested in the QuickTime
version.
ISSUES
You could combine this function with the QTUGetQTVersion so you could also fetch the
version level of QT at the same time.
*/
pascal Boolean QTUIsQuickTimeInstalled(void)
{
OSErr anErr = noErr;
long qtVersion;
anErr = Gestalt(gestaltQuickTime, &qtVersion); DebugAssert(anErr == noErr);
if (anErr != noErr)
return false; // no QT present
else
return true;
}
/*______________________________________________________________________
QTUIsQuickTimeCFMInstalled - Test if the QuickTime CFM libraries are installed and in the
right place.
pascal Boolean QTUIsQuickTimeCFMInstalled(void)
DESCRIPTION
QTUIsQuickTimeCFMInstalled will test if the CFM QuickTime libraries are present (QuickTime
PowerPlug, for instance), and if the libraries are still present (this because the libraries are
registered once when Gestalt finds then during runtime, and the end user might delete these,
or move them to another location later)(.
*/
#if TARGET_CPU_PPC
pascal Boolean QTUIsQuickTimeCFMInstalled(void)
{
OSErr anErr = noErr;
long qtFeatures = 0L;
// Test if the library is registered.
anErr = Gestalt(gestaltQuickTimeFeatures, &qtFeatures); DebugAssert(anErr == noErr);
if (!( (anErr == noErr) && (qtFeatures & (1 << gestaltPPCQuickTimeLibPresent)) )) // not true
return false;
// Test if a function is available (the library is not moved from the Extension folder), this is the
// trick to be used concerning testing if a function is available via CFM.
if ( ! CompressImage )
return false;
else
return true;
}
#endif // powerc
/*______________________________________________________________________
QTUGetQTVersion - Return the current QuickTime version number.
pascal long QTUGetQTVersion()
DESCRIPTION
QTUGetQTVersion is a simple function that will return the current QuickTime version number,
and if QuickTime is not installed it will return 0L. The high order word defines the version number,
for instance 0x0161 defines version 1.6.1.
You could also directly assign a boolean value stating if a certain version is true by using this
kind of an expression:
Boolean gHasQT2.0 = (( QTUGetQTVersion() >> 16) & 0xFFFF) >= 0x200;
EXAMPLE
if( (QTUGetQTVersion() >> 16) < 0x150 ) return; // need to work with QT 1.5 or higher.
*/
pascal long QTUGetQTVersion()
{
long version = 0L;
if(Gestalt(gestaltQuickTime, &version) == noErr)
return version;
else
return 0L;
}
/*______________________________________________________________________
QTUAreQuickTimeMusicInstrumentsPresent - Test if the Musical Instruments Extension is
installed.
pascal Boolean QTUAreQuickTimeMusicInstrumentsPresent(void)
DESCRIPTION
QTUAreQuickTimeMusicInstrumentsPresent tests if the QuickTime Musical Instruments
extension (actually a component) is registered. If this is not the case, then most likely
the extension was never placed into the extension folder, and the end user should be
informed about this.
*/
pascal Boolean QTUAreQuickTimeMusicInstrumentsPresent(void)
{
ComponentDescription aCD;
aCD.componentType = 'inst';
aCD.componentSubType = 'ss ';
aCD.componentManufacturer = 'appl';
if(FindNextComponent((Component)0, &aCD) != NULL)
return true;
else
return false;
}
/*______________________________________________________________________
QTUPrerollMovie - Preroll the movie before you start the movie.
pascal OSErr QTUPrerollMovie(Movie theMovie)
theMovie the destination movie for this operation
DESCRIPTION
QTUPrerollMovie will get the movie time, duration and preferred rate, and Preroll the movie
based on this information. Note that StartMovie already does a PrerollMovie so in that case this
is not needed, this is also true of the standard controller that handles the start of movie
when the keyboard or mouse is used.
*/
pascal OSErr QTUPrerollMovie(Movie theMovie)
{
OSErr anErr = noErr;
TimeValue aTimeValue;
TimeValue aMovieDur;
Fixed aPreferredRate;
aTimeValue = GetMovieTime(theMovie, NULL);
aMovieDur = GetMovieDuration(theMovie);
aPreferredRate = GetMoviePreferredRate(theMovie);
if(aTimeValue == aMovieDur) aTimeValue = 0;
anErr = PrerollMovie(theMovie, aTimeValue, aPreferredRate); DebugAssert(anErr == noErr);
return anErr;
}
pascal Boolean QTUFileFilter(ParmBlkPtr theParamBlock);
/*______________________________________________________________________
QTUGetMovie - Get a Movie from a specific file.
pascal Movie QTUGetMovie(FSSpec *theFSSpec, short *theRefNum, short *theResID)
theFSSpec the specific FSSpec used, if NULL the system will use a standard dialog
box for the end user to select a file
theRefNum this is the specific file ref num we want to use later
theResID this is the specific resource ID we want to use later
DESCRIPTION
QTUGetMovie will get a movie resource out from a specified file, if the FSSpec is not provided
then the function will use a StandardGetFilePreview to select the movie.
*/
#if TARGET_OS_WIN32
pascal Movie QTUGetMovie(FSSpec *theFSSpec, short *theRefNum, short *theResID)
{
OSErr anErr = noErr;
SFTypeList aTypeList = {MovieFileType, 0, 0, 0};
StandardFileReply aReply;
Movie aMovie = NULL;
// If we are provided with an FSSpec then use it, otherwise do a standardgetfile dialog box and
// ask the end user to get it.
if(theFSSpec == NULL || theFSSpec->vRefNum == 0)
{
StandardGetFilePreview( NewFileFilterProc(QTUFileFilter), 1, aTypeList, &aReply);
if(! aReply.sfGood)
return NULL;
*theFSSpec = aReply.sfFile;
}
// We should have now a usable FSSpec, just double check this once again before continuing.
DebugAssert(theFSSpec != NULL); if(theFSSpec == NULL) return NULL;
anErr = OpenMovieFile(theFSSpec, theRefNum, fsRdPerm); DebugAssert(anErr == noErr);
// Note we define fsRdPerm, you could use another flag if needed.
if(anErr == noErr)
{
Str255 aMovieName;
Boolean wasChanged;
*theResID = 0; // want first movie
anErr = NewMovieFromFile(&aMovie, *theRefNum, theResID,
aMovieName, newMovieActive, &wasChanged);
DebugAssert(anErr == noErr);
CloseMovieFile(*theRefNum);
}
if(anErr != noErr)
return NULL;
else
return aMovie;
}
#endif
/*______________________________________________________________________
QTUSimpleGetMovie - Get a Movie from a specific file (simpler version)
pascal OSErr QTUSimpleGetMovie(Movie *theMovie)
theMovie will contain the selected movie when function exits.
DESCRIPTION
QTUSimpleGetMovie is a simplified version of getting a movie from a file, no need for
returning refnums, res IDs of keeping track of FSSpecs (compared with QTUGetMovie)
*/
#if TARGET_OS_WIN32
pascal OSErr QTUSimpleGetMovie(Movie *theMovie)
{
OSErr anErr = noErr;
SFTypeList aTypeList = {MovieFileType, 0, 0, 0};
short resFile = 0;
short resID = 0;
StandardFileReply aReply;
Str255 movieName;
Boolean wasChanged;
StandardGetFilePreview(NewFileFilterProc(QTUFileFilter), 1, aTypeList, &aReply);
if(aReply.sfGood)
{
anErr = OpenMovieFile(&aReply.sfFile, &resFile, fsRdPerm); DebugAssert(anErr == noErr);
if(anErr == noErr)
{
anErr = NewMovieFromFile(theMovie, resFile, &resID, movieName, newMovieActive, &wasChanged);
DebugAssert(anErr == noErr);
CloseMovieFile(resFile);
}
}
return anErr;
}
#endif
/*______________________________________________________________________
QTUFileFilter - Skeleton file filter to be used with various MovieToolbox standard dialog utilities.
pascal Boolean QTUFileFilter(ParmBlkPtr theParamBlock)
theParamBlock specifies a particular ParmBlockPtr
DESCRIPTION
QTUFileFilter is a skeleton file filter to be used with various MovieToolbox standard dialog utilities
The function will return a boolean false if it encounters any errors from the Movie toolbox.
*/
pascal Boolean QTUFileFilter(ParmBlkPtr theParamBlock)
{
#pragma unused(theParamBlock)
return false;
}
/*______________________________________________________________________
QTUSaveMovie - Save and flatten a movie resource into a file.
pascal OSErr QTUSaveMovie(Movie theMovie)
theMovie defines the movie to be saved into a file
DESCRIPTION
QTUSaveMovie will provide a user dialog asking for a file name, and will then save the movie
into this file. Note that this function will also automatically flatten the movie so that it's
self-contained, and also make it cross-platform (by adding any possible resource forks to
the end of the data fork. The default name of the movie is also NEWMOVIE.MOV, this reflects
the way movie file names should be named for cross-platform support (Windows). The default
creator type is also 'TVOD' so that MoviePlayer will be the default application that opens the
movie file. If there's an existing movie file with the same name, it will be deleted.
*/
#if TARGET_OS_WIN32
pascal OSErr QTUSaveMovie(Movie theMovie)
{
OSErr anErr = noErr;
StandardFileReply anSFReply;
DebugAssert(theMovie != NULL); if(theMovie == NULL) return invalidMovie;
StandardPutFile("\pSave Movie as:" , "\pNEWMOVIE.MOV", &anSFReply);
if(anSFReply.sfGood)
{
FlattenMovieData(theMovie, flattenAddMovieToDataFork, &anSFReply.sfFile,
'TVOD', smSystemScript, createMovieFileDeleteCurFile );
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
}
return anErr;
}
#endif
/*______________________________________________________________________
QTUFlattenMovieFile - Flatten a movie into a specified file.
pascal OSErr QTUFlattenMovieFile(Movie theMovie, FSSpec *theFile)
theMovie defines the movie to be flattened
theFile defines the target file
DESCRIPTION
FlattenMovie file will take an existing movie, flatten it into a temp file, and then move the
contents of the temp file into the specified FSSpec. This because there are cases where we
can't flatten a movie in place. We will use TickCount as a temp file name.
Note that we need to dispose the movie inside this function? Why? Well, the file is open as
long as there's a pointer to it from the movie resource. And we need to delete the original
movie file as part of the operation of swapping the files.
*/
pascal OSErr QTUFlattenMovieFile(Movie theMovie, FSSpec *theFile)
{
OSErr anErr = noErr;
FSSpec tempFile;
Str255 tempFileName;
DebugAssert(theMovie != NULL); if(theMovie == NULL) return invalidMovie;
// Create the needed temp file.
NumToString(TickCount(), tempFileName);
anErr = FSMakeFSSpec(theFile->vRefNum, theFile->parID, tempFileName, &tempFile);
if(anErr != fnfErr) return anErr;
// Flatten the movie.
FlattenMovie(theMovie, flattenAddMovieToDataFork, &tempFile, 'TVOD', smSystemScript,
createMovieFileDeleteCurFile, 0, NULL);
anErr = GetMoviesError();
if(anErr != noErr)
{
FSpDelete(&tempFile); // remove the temp file
return anErr;
}
DisposeMovie(theMovie);
anErr = FSpDelete(theFile); ReturnIfError(anErr);
anErr = FSpRename(&tempFile, theFile->name); ReturnIfError(anErr);
return anErr;
}
// TRACKS AND MEDIA
/*______________________________________________________________________
QTUMediaTypeInTrack - Check if a particular media type is present in the movie.
pascal Boolean QTUMediaTypeInTrack(Movie theMovie, OSType theMediaType)
theMovie movie to be tested about the media type
theMediaType media type we want to test about
DESCRIPTION
QTUMediaTypeInTrack could be used to scan if a possible media type is present in the movie
(video,sound, other media types).
*/
pascal Boolean QTUMediaTypeInTrack(Movie theMovie, OSType theMediaType)
{
Track aTrack = NULL;
long aTrackCount = 0;
long index;
OSType aMediaType;
Boolean haveMediaType = false;
aTrackCount = GetMovieTrackCount(theMovie);
if(aTrackCount == 0)
return false; // no tracks in movie
for(index = 1; index <= aTrackCount; index++)
{
aTrack = GetMovieIndTrack(theMovie, index);
GetMediaHandlerDescription( GetTrackMedia(aTrack), &aMediaType, NULL, NULL);
haveMediaType = ( aMediaType == theMediaType);
if(haveMediaType == true)
return true;
}
return false; // didn't find the media type track in the movie
}
/*______________________________________________________________________
QTUGetTrackRect - Get the Rect of a specified track.
pascal Rect QTUGetTrackRect(Track theTrack)
theTrack track we are interested in concerning the rect information
DESCRIPTION
QTUMediaTypeInTrack will take a (visual) track and return the track's Rect boundaries that
could be used later for various calculations of the visual track geometries. Note that
this Rect is meaningful with video tracks (and any other tracks that have geometrical
dimensions, otherwise this function will return a rect with zero values.
*/
pascal OSErr QTUGetTrackRect(Track theTrack, Rect *theRect)
{
OSErr anErr = noErr;
Fixed aTrackHeight;
Fixed aTrackWidth;
theRect->top = 0; theRect->left = 0; theRect->bottom = 0; theRect->right = 0;
DebugAssert(theTrack != NULL);
if(theTrack == NULL)
return invalidTrack;
GetTrackDimensions(theTrack, &aTrackHeight, &aTrackWidth);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
if(anErr != noErr)
return anErr;
theRect->right = Fix2Long(aTrackWidth);
theRect->bottom = Fix2Long(aTrackHeight);
return anErr;
}
/*______________________________________________________________________
QTUGetVideoMediaPixelDepth - Return the pixel depth of the video media (sample).
pascal short QTUGetVideoMediaPixelDepth(Media theMedia,short index)
theMedia visual media we want to test concerning pixel depths
index index into the media sample we are interested in
DESCRIPTION
QTUGetVideoMediaPixelDepth will take a specified video media and an index into the media
samples, and look up the pixel depth for the video sample.
*/
pascal short QTUGetVideoMediaPixelDepth(Media theMedia,short index)
{
OSErr anErr = noErr;
short aPixelDepth;
SampleDescriptionHandle anImageDesc = NULL;
OSType mediaType;
DebugAssert(theMedia != NULL);
DebugAssert(index > 0);
// Test if we are indeed dealing with video media.
GetMediaHandlerDescription(theMedia, &mediaType, NULL, NULL);
if(mediaType != VideoMediaType)
return 0;
anImageDesc = (SampleDescriptionHandle)NewHandle(sizeof(Handle)); DebugAssert(anImageDesc != NULL);
if(anImageDesc == NULL)
return 0;
GetMediaSampleDescription(theMedia, index, anImageDesc);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
aPixelDepth = (* (ImageDescriptionHandle)anImageDesc)->depth;
DisposeHandle((Handle)anImageDesc);
return aPixelDepth;
}
/*______________________________________________________________________
QTUCountMediaSamples - Count the amount of known media samples in a movie.
pascal long QTUCountMediaSamples(Movie theMovie, OSType theMediaType)
theMovie the movie with the track(tracks).
theMediaType the type of media we are interested in (video, sound and so on)
DESCRIPTION
QTUCountMediaSamples will take a specified movie and a media type, and calculate the amount
of samples of this particular type. It could be used to find the total amount of video frames in a
movie, or sound samples and so on.
Note that if the movie is long, it will take a long time to go through all the samples, especially
in the case of sound samples.
EXAMPLE:
nFrames = QTUCountMediaSamples(aSourceMovie, VideoMediaType);
ISSUES
This function could be modified to count other types of samples by changing the flags definitions
(nextTimeSyncSample for key frames and so on).
*/
pascal long QTUCountMediaSamples(Movie theMovie, OSType theMediaType)
{
long numFrames = 0;
short flags = nextTimeMediaSample + nextTimeEdgeOK;
TimeValue aDuration = 0;
TimeValue theTime = 0;
GetMovieNextInterestingTime(theMovie, flags, 1, &theMediaType, theTime, 0, &theTime, &aDuration);
if(theTime == -1) return numFrames;
flags = nextTimeMediaSample; // Don't include the nudge after the first interesting time.
while(theTime != -1) // When the returned time equals -1, then there were no more interesting times.
{
numFrames++;
GetMovieNextInterestingTime(theMovie, flags, 1, &theMediaType, theTime, 0, &theTime, &aDuration);
}
return numFrames;
}
/*______________________________________________________________________
QTUGetDurationOfFirstMovieSample - Return the time value of the first sample of a certain
media type.
pascal TimeValue QTUGetDurationOfFirstMovieSample(Movie theMovie, OSType theMediaType)
theMovie the movie with the media track
theMediaType specified media type (VideoMediaType, SoundMediaType and so on)
DESCRIPTION
QTUGetDurationOfFirstMovieSample returns the duration of the first sample of a certain media
in the movie. If there is no such sample, the duration is 0.
This function could be used in known cases where all the samples are assumed to be of the same
duration. For instance in such cases the frame count could be calculated as:
framecount =
GetMovieDuration(theMovie)/QTUGetDurationofFirstMovieSample(theMovie, VideoMediaType);
*/
pascal TimeValue QTUGetDurationOfFirstMovieSample(Movie theMovie, OSType theMediaType)
{
OSErr anErr = noErr;
TimeValue interestingDuration = 0;
short timeFlags = nextTimeMediaSample+nextTimeEdgeOK;
GetMovieNextInterestingTime(theMovie, timeFlags, (TimeValue)1, &theMediaType, 0,
fixed1, NULL, &interestingDuration);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
return interestingDuration;
}
/*______________________________________________________________________
QTUCountMaxSoundRate - Calculate the max sound data rate of a possible sound track
in the movie.
pascal OSErr QTUCountMaxSoundRate(Movie theMovie,long *theMaxSoundRate)
theMovie the movie with the sound track(tracks).
theMaxSoundRate the final returned value
DESCRIPTION
QTUCountMaxSoundRate (taken from the ConvertToMovieJr file) is a simple function that tries
to figure out the maximum sound track rate. This is done by looking at all of the sound tracks
in the source movie, and using the one with the highest sample rate (11khz, 22khz and so on),
This number could then be used for calculating the maximum data rate by extracting the sound rate and
this way we get a loose estimation how much is left for the video data rate.
This is just an approximation, and a better function should take into account non-overlapping
sound tracks, stereo sound data rates, compressed sound tracks and so on.
*/
pascal OSErr QTUCountMaxSoundRate(Movie theMovie,long *theMaxSoundRate)
{
OSErr anErr = noErr;
short index, trackCount;
DebugAssert(theMovie != NULL); if(theMovie == NULL) return invalidMovie;
*theMaxSoundRate = 0; // just for security we place this value in here
trackCount = GetMovieTrackCount(theMovie);
for(index = 1; index <= trackCount; index++)
{
OSType aTrackType;
Track aTrack = NULL;
Media aMedia = NULL;
aTrack = GetMovieIndTrack(theMovie, index); DebugAssert(aTrack != NULL);
aMedia = GetTrackMedia(aTrack); DebugAssert(aMedia != NULL);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
if(anErr != noErr) return anErr;
GetMediaHandlerDescription(aMedia, &aTrackType, 0, 0);
if(aTrackType == SoundMediaType)
{
long aRate;
SampleDescriptionHandle aDesc = NULL;
aDesc = (SampleDescriptionHandle)NewHandle(sizeof(SampleDescription)); DebugAssert(aDesc != NULL);
GetMediaSampleDescription(aMedia, 1, aDesc);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
if(anErr != noErr)
{
DisposeHandle((Handle)aDesc);
continue;
}
aRate = (*(SoundDescriptionHandle)aDesc)->sampleRate >> 16;
if(aRate > *theMaxSoundRate)
*theMaxSoundRate = aRate;
}
}
return anErr;
}
/*______________________________________________________________________
QTUGetMovieFrameCount - Return the amount of frames in the movie based on frame rate estimate.
pascal long QTUGetMovieFrameCount(Movie theMovie, long theFrameRate)
theMovie the movie we want to calculate the frame count for.
theFrameRate the expected frame rate of the movie
DESCRIPTION
QTUGetMovieFrameCount is a simple operation that takes into account the duration of the movie,
the time scale and a suggested frame rate, and based on this will calculate the
amount of frames needed in the movie. We assume that the frame rate will be uniform in the movie.
*/
pascal long QTUGetMovieFrameCount(Movie theMovie, long theFrameRate)
{
long frameCount, duration, timescale;
float exactFrames;
DebugAssert(theMovie != NULL); if(theMovie == NULL) return invalidMovie;
duration = GetMovieDuration(theMovie);
timescale = GetMovieTimeScale(theMovie);
exactFrames = (float)duration * theFrameRate;
frameCount = exactFrames / timescale / 65536;
if(frameCount == 0)
frameCount = 1; // we got to have at least one frame
return frameCount;
}
/*______________________________________________________________________
QTUCopySoundTracks - Copy any sound track from the source movie to the destination movie.
pascal OSErr QTUCopySoundTracks(Movie theSrcMovie, Movie theDestMovie)
aSourceMovie movie from which to copy the sound tracks
aDestinationMovie movie to which we will copy the sound tracks.
DESCRIPTION
QTUCopySoundTracks will take any sound tracks from the source movie, and copy these over to the
destination movie. The destination movie might have no sound track, or then these tracks are
added to the existing sound tracks.
*/
pascal OSErr QTUCopySoundTracks(Movie theSrcMovie, Movie theDestMovie)
{
OSErr anErr = noErr;
long trackCount, index;
DebugAssert(theSrcMovie != NULL); if(theSrcMovie == NULL) return invalidMovie;
DebugAssert(theDestMovie != NULL); if(theDestMovie == NULL) return invalidMovie;
trackCount = GetMovieTrackCount(theSrcMovie);
// Loop through each track, look for sound tracks.
for(index = 1; index <= trackCount; index++)
{
OSType aTrackType;
Track aSrcTrack, aDestTrack;
Media aSrcMedia, aDestMedia;
aSrcTrack = GetMovieIndTrack(theSrcMovie, index); // get next track and media
aSrcMedia = GetTrackMedia(aSrcTrack);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
if(anErr != noErr) return anErr;
// try to find sound tracks/media
GetMediaHandlerDescription(aSrcMedia, &aTrackType, 0, 0);
if(aTrackType == SoundMediaType)
{
// Create the track for the sound media.
aDestTrack = NewMovieTrack(theDestMovie, 0, 0, GetTrackVolume(aSrcTrack));
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
if(anErr != noErr) return anErr;
// Create a media for the sound track and prepare this media for editing.
aDestMedia = NewTrackMedia(aDestTrack, SoundMediaType, GetMediaTimeScale(aSrcMedia), 0, 0);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
if(anErr != noErr) return anErr;
anErr = BeginMediaEdits(aDestMedia); DebugAssert(anErr == noErr);
if(anErr != noErr) return anErr;
// Insert the new track into the destination movie starting at time zero and
// lasting for the entire duration of the movie.
InsertTrackSegment(aSrcTrack, aDestTrack, 0 , GetTrackDuration(aSrcTrack), 0);
anErr = GetMoviesError(); DebugAssert(anErr == noErr);
if(anErr != noErr) return anErr;
// We've done editing the media
EndMediaEdits(aDestMedia);
}
}
return anErr;
}
/*______________________________________________________________________
QTUPrintMoviePICT - Print the existing movie frame pict.
pascal Boolean QTUPrintMoviePICTr(Movie theMovie, short x, short y, long PICTUsed)
theMovie movie that has the poster
x,y starting point coordinates where to place the poster on paper
DESCRIPTION
QTUPrintMoviePICT is a simple function showing how to print movie posters.
ISSUES
Note that in a real application we should put the PrStlDialog code into the Print Setup\xC9 menu
function. The reason it's inside this function is that we use this code for quick testing of
printing.
*/
#if TARGET_OS_WIN32
pascal OSErr QTUPrintMoviePICT(Movie theMovie, short x, short y, long PICTUsed)
{
OSErr anErr = noErr;
PicHandle aPictHandle = NULL;
THPrint aTHPrint = NULL;
GrafPtr aSavedPort;
TPPrPort aPrintPort;
Boolean aResult;
Boolean isPrinting = false;
Rect aPictRect;
DebugAssert(theMovie != NULL); if(theMovie == NULL) return invalidMovie;
GetPort(&aSavedPort);
// Get the PICT to be printed, either the poster pict or the current frame pict.
switch(PICTUsed)
{
case kPrintFrame:
aPictHandle = GetMoviePict(theMovie, GetMovieTime(theMovie, 0L));
break;
case kPrintPoster:
aPictHandle = GetMoviePosterPict(theMovie);
break;
default:
DebugAssert("Should not happen, incorrect constant used"); goto Closure;
}
if(aPictHandle == NULL) goto Closure;
// Get the Print record.
aTHPrint = (THPrint) NewHandleClear(sizeof(TPrint)); DebugAssert(aTHPrint != NULL);
if(aTHPrint == NULL) goto Closure;
PrOpen(); isPrinting = true;
anErr = PrError(); DebugAssert(anErr == noErr);
if(anErr != noErr) goto Closure;
PrintDefault(aTHPrint);
// Move this to Print Setup\xC9if you want to make this look really cool.
aResult = PrStlDialog(aTHPrint); DebugAssert(aResult == true);
if(!aResult) goto Closure;
aResult = PrJobDialog(aTHPrint); DebugAssert(aResult == true);
if(!aResult) goto Closure;
aPrintPort = PrOpenDoc(aTHPrint, NULL, NULL); DebugAssert(aPrintPort != NULL);
PrOpenPage(aPrintPort, NULL);
anErr = PrError(); DebugAssert(anErr == noErr);
if(anErr != noErr) goto Closure;
// Print at x,y position
aPictRect = (*aPictHandle)->picFrame;
OffsetRect(&aPictRect, x - aPictRect.left, y - aPictRect.top);
DrawPicture(aPictHandle, &aPictRect);
// If you want to do additional drawing, do it here.
PrClosePage(aPrintPort);
PrCloseDoc(aPrintPort);
anErr = PrError(); DebugAssert(anErr == noErr);
if(anErr != noErr) goto Closure;
if(( *aTHPrint)->prJob.bJDocLoop == bSpoolLoop)
PrPicFile(aTHPrint, NULL, NULL, NULL, NULL);
// Our closure handling.
Closure:
SetPort(aSavedPort);
if(isPrinting) PrClose();
if(aPictHandle) KillPicture(aPictHandle);
if(aTHPrint) DisposeHandle((Handle)aTHPrint);
return anErr;
}
#endif
/*______________________________________________________________________
QTUCalculateMovieMemorySize - Calculate how much memory a movie takes in the app heap.
pascal OSErr QTUCalculateMovieMemorySize(Movie theMovie, long *theSize)
theMovie movie we want to know the size of in the current application heap
theSize pointer to a long that will contain the movie size in bytes
DESCRIPTION
QTUCalculateMovieMemorySize will return the amount of bytes it is allocating as a handle