-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing37.html
executable file
·2247 lines (1878 loc) · 121 KB
/
listing37.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>SoftVDigX - /SoftVDigX/SoftVDigX.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/idxQuickTimeComponentCreation-date.html">QuickTime Component Creation</a> > <A HREF="javascript:location.replace('index.html');">SoftVDigX</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">SoftVDigX</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>/SoftVDigX/SoftVDigX.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">/SoftVDigKEXT/ImageData.h</option>
<option value="listing2.html">/SoftVDigKEXT/Images/ImageData_00.h</option>
<option value="listing3.html">/SoftVDigKEXT/Images/ImageData_01.h</option>
<option value="listing4.html">/SoftVDigKEXT/Images/ImageData_02.h</option>
<option value="listing5.html">/SoftVDigKEXT/Images/ImageData_03.h</option>
<option value="listing6.html">/SoftVDigKEXT/Images/ImageData_04.h</option>
<option value="listing7.html">/SoftVDigKEXT/Images/ImageData_05.h</option>
<option value="listing8.html">/SoftVDigKEXT/Images/ImageData_06.h</option>
<option value="listing9.html">/SoftVDigKEXT/Images/ImageData_07.h</option>
<option value="listing10.html">/SoftVDigKEXT/Images/ImageData_08.h</option>
<option value="listing11.html">/SoftVDigKEXT/Images/ImageData_09.h</option>
<option value="listing12.html">/SoftVDigKEXT/Images/ImageData_10.h</option>
<option value="listing13.html">/SoftVDigKEXT/Images/ImageData_11.h</option>
<option value="listing14.html">/SoftVDigKEXT/Images/ImageData_12.h</option>
<option value="listing15.html">/SoftVDigKEXT/Images/ImageData_13.h</option>
<option value="listing16.html">/SoftVDigKEXT/Images/ImageData_14.h</option>
<option value="listing17.html">/SoftVDigKEXT/Images/ImageData_15.h</option>
<option value="listing18.html">/SoftVDigKEXT/Images/ImageData_16.h</option>
<option value="listing19.html">/SoftVDigKEXT/Images/ImageData_17.h</option>
<option value="listing20.html">/SoftVDigKEXT/Images/ImageData_18.h</option>
<option value="listing21.html">/SoftVDigKEXT/Images/ImageData_19.h</option>
<option value="listing22.html">/SoftVDigKEXT/Images/ImageData_20.h</option>
<option value="listing23.html">/SoftVDigKEXT/Images/ImageData_21.h</option>
<option value="listing24.html">/SoftVDigKEXT/Images/ImageData_22.h</option>
<option value="listing25.html">/SoftVDigKEXT/Images/ImageData_23.h</option>
<option value="listing26.html">/SoftVDigKEXT/Images/ImageData_24.h</option>
<option value="listing27.html">/SoftVDigKEXT/Images/ImageData_25.h</option>
<option value="listing28.html">/SoftVDigKEXT/Images/ImageData_26.h</option>
<option value="listing29.html">/SoftVDigKEXT/Images/ImageData_27.h</option>
<option value="listing30.html">/SoftVDigKEXT/Images/ImageData_28.h</option>
<option value="listing31.html">/SoftVDigKEXT/Images/ImageData_29.h</option>
<option value="listing32.html">/SoftVDigKEXT/SoftVDigKEXT.cpp</option>
<option value="listing33.html">/SoftVDigKEXT/SoftVDigKEXT.h</option>
<option value="listing34.html">/SoftVDigKEXT/SoftVDigKEXT_UC.cpp</option>
<option value="listing35.html">/SoftVDigKEXT/SoftVDigKEXTCommon.h</option>
<option value="listing36.html">/SoftVDigKEXT/SoftVDigXUC.h</option>
<option value="listing37.html">/SoftVDigX/SoftVDigX.c</option>
<option value="listing38.html">/SoftVDigX/SoftVDigX.h</option>
<option value="listing39.html">/SoftVDigX/SoftVDigX.r</option>
<option value="listing40.html">/SoftVDigX/SoftVDigXDispatch.h</option></select>
</p>
</form>
<p><strong><a href="SoftVDigX.zip">Download Sample</a></strong> (“SoftVDigX.zip”, 2.60M)<BR>
<strong><a href="SoftVDigX.dmg">Download Sample</a></strong> (“SoftVDigX.dmg”, 3.61M)</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: SoftVDigX.c
Description: QuickTime Compressed Source Video Digitizer for MacOS X.
Note: Accompanying KEXT must be loaded for this sample to work do this by following these steps:
First copy the file to /tmp
1) sudo cp -R /Users/ed/Desktop/SoftVDigKEXT.kext /tmp/
Second, load the kext
2) sudo kextload -v /tmp/SoftVDigKEXT.kext
Author: QuickTime Engineering (the usual suspects)
Developer Techical Support
FCP information provided by FCP engineering
Parts from the code of the past:
SoftVDig & SoftVDig2000 originally written by QuickTime engineering.
Develop Issue 14, "Video Digitizing Under QuickTime",
for some details.
Copyright: © Copyright 1993-2007 Apple Computer, Inc. All rights reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by
Apple 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 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):
<3> 02/07/07 dts Updated for QuickTime 7.1 - added Image Description properties
as outlined in Ice Floe 19
<2> 08/14/05 dts updated to build universal binary
<1> 08/14/03 dts initial release for X
*/
/* Selected excerpts from the famous VIDEO DIGITIZING UNDER QUICKTIME by Casey King and Gary Woodcock
Develop Issue 14 which pertain to the task at hand - Published a long time ago in the far away land
of QuickTime 1.5.
Enjoy!
"...And the evolution of this technology has just begun. - 1993"
***** COMPRESSED SOURCE VIDEO DIGITIZERS FOR MACINTOSH OS X *****
BACKGROUND - THE VIDEO CAPTURE PROCESS
The process of making movies involves several components. The sequence grabber component (component type 'barg')
plays an especially critical role. It's responsible for coordinating the activities of the lower-level components
to achieve different results -- like displaying video in a window, grabbing a single picture, or grabbing a movie.
By protecting application developers from having to deal with the low-level management of the video digitizer, the
sequence grabber makes it much easier to incorporate video input capabilities in applications. Note that the sequence
grabber also handles audio input devices and synchronization of picture and sound.
Data flow in the video digitizing pipeline begins with a video source for example, a video camera, VCR, direct broadcast
feed and so on. The video digitizing hardware is responsible for converting the video source to digital form and can
optionally perform resizing, color conversion, or clipping. In the absence of hardware support for these operations,
the sequence grabber will sometimes provide them.
The video digitizer's ('vdig') primary purpose in life is to provide QuickTime with a consistent software interface used
to interact with the video digitizer hardware. The data supplied by the 'vdig' component can either be displayed on screen
or be processed further through the use of the sequence grabber component.
From a video digitizing perspective, displaying live video in a window is called play through(*), and capturing video to a movie
is called capturing or grabbing. The sequence grabber calls these operations previewing and recording respectively. When a movie
is requested, an image compressor may process the data further, and the result is stored either in system memory or to disk.
(*)It is very important to note that for a compress-only video digitizer, playthough support at the 'vdig' level is ignored. Hardware
on MacOS X cannot go directly to the screen, so video digitizer functions supporting playthough are not required. Playthough
is handled by QuickTime and is mentioned in the above description for completeness.
THE SEQUENCE GRABBER
The sequence grabber makes life easier for application programmers by handling all the messy details of controlling video digitizers,
sound input devices, and compressors. The sequence grabber plays such an important role in a video digitizing application that a brief
introduction is in order. The HackTV Carbon sample is a good introduction to the Sequence Grabber set of APIs.
PREVIEWING
Previewing video with the sequence grabber is the equivalent of setting up the 'vdig' in play-through mode to display live video on the
computer screen. Remember that the sequence grabber performs the live video play through and devices should not do hardware play
through or attempt to directly draw to the screen on MacOS X.
In general the steps are, establish a connection to the sequence grabber component in the usual way, with OpenADefaultComponent.
Initialize the sequence grabber, set up the graphics environment, and allocate a new channel for video preview (using the seqGrabPreview flag).
If for example you want the displayed video to be one-quarter size, you would call SGGetSrcVideoBounds to see what size the source video
is. This function calls VDGetDigitizerRect, which returns the source video size equal to the digitizer rectangle. You would Scale the
height and width accordingly, and then send the new size to the sequence grabber via the SGSetChannelBounds routine.
Finally, call SGStartPreview, which turns on the video digitizer by calling the digitizer function VDSetCompressionOnOff, and previewing
begins.
Make sure to always call SGSetGWorld to establish the graphics port for the sequence grabber component. This is required even if you do
not plan to work with a video channel.
RECORDING
Recording is very similar to previewing and is almost as simple.
There are several small differences between recording and previewing. For example you can set up the sequence grabber to record and to play
through while recording (using the seqGrabRecord | seqGrabPlayDuringRecord flags). We need to specify a file for the movie to be written
to, indicating that the movie be grabbed directly to disk. For a short movie, we could grab to memory if we wanted. By default,
the recording time is limited by the system resources available -- in this case, disk space.
The SGStartRecord call initiates the grab to disk. SGIdle is called repetitively to provide processing time to the sequence grabber.
You should call SGIdle as often as possible while recording. When the user clicks the mouse button, or when the disk is full, recording
will stop, and we call SGStop to complete the recording process.
That's all there is to simple recording. If you want to do more sophisticated tasks with the sequence grabber, such as replacing the
standard sequence grabber disk- or compression-bottleneck routines with your own, or using a DataProc for faster captures consult the
QuickTime Sequence Grabber documentation and Sample Code.
http://developer.apple.com/documentation/QuickTime/RM/CreatingMovies/SeqGrabComp/index.html
http://developer.apple.com/samplecode/Sample_Code/QuickTime/Capturing.htm
***********************************
*** SOME VIDEO DIGITIZER BASICS ***
We'll discuss a few QuickTime 'vdig' topics that seem to give developers the most trouble when they first undertake the task of
writing a video digitizer component. In practice, how you write a video digitizer component depends heavily on your particular
digitizer hardware implementation. For the sake of illustration, however, we'll simulate some hardware features with software
that provides the required functionality.
IDENTIFYING DIGITIZER TYPES AND CAPABILITIES
No two video digitizers are alike. To make sure your 'vdig' component works smoothly with
QuickTime, it's critical to identify the capabilities your hardware provides.
This sample demonstrates hardware not attached to a FrameBuffer (a FireWire device for example):
- Set digiOutDoesCompress, this implies the use of the Compressed Source APIs such as VDCompressDone(), VDReleaseCompressBuffer(),
VDCompressOneFrameAsync() and so on.
Note: Be sure to tell the truth when reporting the number of queued frames (queuedFrameCount number).
The Ptr value in VDCompressDone()- can be any memory address to read from.
- Set digiOutDoesCompressOnly when above flag is set.
- Set digiOutDoesNotNeedCopyOfCompressData - When the Sequence Grabber is recording, QuickTime can manage capture buffers for you
automatically. Sometimes, you don't want QuickTime buffer management - setting this flag informs QuickTime that you specifically
DO NOT want this behavior, therefore the Sequence Grabber will not buffer any of your compressed data. In other words you don't
want the Sequence Grabber copying your data to system memory before writing it to disk. This allows for DMA directly over the
PCI bus avoiding a trip though system memory before the sample data hits the disk.
The 'vdig' component interface attempts to be very flexible in allowing you to indicate what your hardware
can do. A 'vdig' specifies its type and capabilities in the DigitizerInfo structure, shown below. Two
calls -- VDGetDigitzerInfo and VDGetCurrentFlags give a client (normally the sequence grabber)
access to information contained in this structure.
struct DigitizerInfo {
short vdigType;
long inputCapabilityFlags;
long outputCapabilityFlags;
long inputCurrentFlags;
long outputCurrentFlags;
short slot;
GDHandle gdh;
GDHandle maskgdh;
short minDestHeight;
short minDestWidth;
short maxDestHeight;
short maxDestWidth;
short blendLevels;
long reserved;
};
In the vdigType field, you specify the type of digitizer you are. Compressed Source Digitizers are basic
rectangular digitizing devices - vdTypeBasic.
In the capability flags fields, you indicate to clients all capabilities a particular digitizer instance provides.
The current flags fields use the same attribute bit fields as the capability flags, but they indicate the
currently available capabilities, not the total possible capabilities. By nature, some capabilities are
mutually exclusive. For instance, if you support NTSC and PAL input formats, at any given time you're actively
doing only one of them. The bit corresponding to the active standard is the one that would be set in the current flags,
while both would be set in the capability flags.
A full description of the flags can be found later in this sample before the SoftVDigXGetDigitizerInfo function, and
at the following URL:
http://developer.apple.com/documentation/QuickTime/INMAC/QTC/imVideoDigComp.10.htm
Clients of your digitizer will be much happier if you truthfully state what you can and can't do. The sequence grabber,
in particular, will function much better.
THE EXAMPLE - SoftVDigX by Kext-O-Tron
As an example we'll describe the "hardware" used in this sample:
A fictional digitizer company "Kext-O-Tron", announces a video digitizer with the following
capabilities:
The fictional hardware has one video input and can support only the NTSC video standard.
The fictional hardware supports compression and provides '2vuy' pixel data. (the same 30 frames over and over)
The fictional hardware only supports capture at 320x240 and does not support clipping, resizing or zooming.
The fictional hardware will be relying on the sequence grabber to do resizing, color conversion, and on-screen
placement operations.
The interesting fields and their values are:
vdigType = vdTypeBasic;
inputCapabilityFlags = digiInDoesNTSC | digiInDoesColor | digiInDoesComponent;
outputCapabilityFlags = digiOutDoes32 |
digiOutDoesCompress |
digiOutDoesCompressOnly |
digiOutDoesNotNeedCopyOfCompressData;
GETTING VIDEO COORDINATE SYSTEMS STRAIGHT
http://developer.apple.com/documentation/QuickTime/INMAC/QTC/imVideoDigComp.4.htm
The coordinate system for video digitizers can seem confusing, but it's actually quite straightforward.
The critical point to keep in mind is that when referencing the video source, you're working in a coordinate
system that's specific to your digitizing hardware. All cropping rectangles are relative to this coordinate system.
Four rectangles define the video source. The MaxSrcRect defines the maximum source area that the digitizer is
capable of grabbing. Typically this area includes all or portions of the vertical and horizontal blanking areas.
Note that you don't have to define the top left point of MaxSrcRect as 0,0; this is an entirely arbitrary reference
point that 'vdig' developers can define as they choose. The other three rectangles are defined in relation to MaxSrcRect.
The ActiveSrcRect is the region of the maximum source rectangle that contains the actual video image.
The first pixel of active video is the top left corner, and the last pixel is the bottom right.
The DigitizerRect describes the area of the MaxSrcRect to be captured -- the image that the user will
actually see, although it hasn't been scaled yet. The default DigitizerRect is the same as the ActiveSrcRect.
It's not uncommon for part of the blanking signal to be displayed in the ActiveSrcRect. This is because different
source devices -- like VCRs, and broadcast signals -- send out slightly different analog signals. To align the image,
a 'vdig' client can nudge the DigitizerRect a few pixels in the appropriate direction using VDSetDigitizerRect.
To describe a cropped image, the DigitizerRect is usually defined as a portion of the ActiveSrcRect.
The last rectangle, VBlankRect, defines the area of vertical blanking. This region can contain vertical
interval time code (VITC), closed captioning, and teletext.
Remember, all rectangle coordinates are relative to MaxSrcRect.
MaxSrcRect, ActiveSrcRect, and VBlankRect are hardware dependent. The only control that a client has is in the
definition of DigitizerRect.
Note that in the SoftVDigXSetDigitizerRect function, the requested DigitizerRect must fully intersect the MaxSrcRect.
One more very important point to understand about video coordinate systems is that scaling and
translation can be specified either as a matrix or as a destination rectangle. Your digitizer may support
both transformation methods. If the matrix is NULL, use the destination rectangle; otherwise, ignore it
and use the matrix. The 'vdig' must offset the top left of the DigitizerRect to 0,0 before applying the
matrix, or the video won't be positioned correctly. This isn't necessary when using the destination
rectangle. By the way, the sequence grabber uses the destination rectangle, and not the matrix, to
specify scaling and translation, although this may change at any time.
Note: If you claim you only record at one size, this is not your problem. QuickTime will take care of
resizing the video as required.
DIGITIZATION CONTROL
Video digitizers should time-stamp the video frames they produce and implement the VDSetTimeBase routine.
VDSetTimeBase allows clients to specify the time coordinate system the video digitizer should use when time-stamping
video frames.
A second routine called VDSetFrameRate, allows applications to tell a digitizer the precise frame rate to
use for capture. Digitizers used to capture video at only one frame rate -- as fast as possible.
However, the advent of full-frame-rate digitizing hardware and compressed-source devices has made
it increasingly important for clients to manage the tradeoff between frame rate, image size, and
compression quality. The rate in VDSetFrameRate is expressed as a fixed-point value, typically
between 0 and 29.97 (see "Frame Rates and Motion Quality" for a discussion of frame rate values).
Additionally VDGetDataRate retrieves information describing the performance capabilities of a video digitizer. It is
extremely useful because it gives clients a way to determine the performance capabilities of your video digitizer. It is
called before recording has started and allows you to report milliseconds per frame, frames per second and bytes per second.
You can safely return 0 for milliSecPerFrame, bytesPerSecond however MUST BE ACCURATE. For framesPerSecond you should return
the frame rate you can "really" do, but you can also return 0 if you can't control the frame rate. You MUST return
bytesPerSecond, this is not an option!
COMPRESSED-SOURCE DEVICES
Compressed-source video digitizers gives users access to full-size, full-frame-rate digital video.
Eight functions are needed for servicing compressed-source video digitizers.
VDGetCompressionTypes simply returns a handle to the list of compressors that your video digitizer implements.
Each element of the list contains the component ID, type, name, format, and capabilities of a compressor.
VDSetCompression specifies which of all the possible compressors a digitizer should use. The parameters for
VDSetCompression specify the spatial quality, temporal quality, depth, and other characteristics of the compression.
VDCompressOneFrameAsync starts the digitizing process for compressed-source devices. A compressed-source digitizer
handles all the management of data buffers itself, without external assistance from the caller.
VDCompressDone allows a caller to determine when a frame has been completed.
The VDReleaseCompressBuffer tells a compressed-source device to free the buffer returned by the VDCompressDone call.
The VDResetCompressSequence call instructs a digitizer to insert a key frame into a frame-differenced image sequence as soon
as possible after it receives this call.
The VDGetImageDescription routine prompts the digitizer to return an image description structure corresponding to the current settings.
This structure is the same structure that's used to describe image data in movie files.
The VDSetCompressionOnOff routine starts and stops the digitizer. To give the digitizer adequate time to prepare itself for the
requested operation, clients must call this routine before calling VDSetCompression or VDCompressOneFrameAsync.
Typically, compressed-source devices are able to act as hardware decompressors and have a corresponding QuickTime image decompressor
component that clients can use to play back the compressed images. However, if your hardware produces compressed data that can't be
read by any of the standard QuickTime image decompressor components, you need to provide an appropriate software-only decompressor
component. This way, users who don't have your hardware will still be able to play movies produced with your compressor.
FRAME RATES AND MOTION QUALITY
The term frame rate is frequently tossed about in discussions of the pros and cons of video digitizers.
Frame rate is the rate at which frames appear during video playback.
It's commonly held that the frame rate corresponding to full-motion video is 30 frames per second
(fps). However, 30 fps is not the only interesting frame rate or even the only "true" full-motion
frame rate.
Most video digitizing hardware have a fixed frame rate:
29.97 fps is the usual frame rate for NTSC video and broadcast production.
25 fps is the usual frame rate for PAL and SECAM video and broadcast production.
24 fps is the usual frame rate for film production.
But QuickTime does not limit frame rate to only the above values. It could be anything. A Video Digitizer will be told
what frame rate QuickTime wants to record at. If the Video Digitizer cannot achive this frame rate, QuickTime will try
it's best to do it. However, results may vary and implementing rate control on the hardware side will result in better
accuracy.
See QuickTime Image Rates and Video in Ice Floe 19 for the the full description of the issues related to TimeScale and
sample durations:
http://developer.apple.com/quicktime/icefloe/dispatch019.html
NTSC and digital 525 video have exactly 30/1.001 frames per second. A media TimeScale of 30000 and media
sample durations of 1001, along with a movie TimeScale of 30000, provide 19.9 hours of time in 32 bits.
The 30/1.001 rate of NTSC and digital 525 is sometimes approximated to (or mistaken to be) 29.97, which does
not equal 30/1.001. The average rate of drop-frame timecode (e.g., LTC and VITC used in the video industry) over
24 hours is exactly 29.97, but the use of drop-frame timecode does not modify the video signal rate. Some existing
movies have a media TimeScale of 2997, media sample durations of 100, and a movie TimeScale of 2997. This provides
8.2 days of time before 32-bit overflow, however after 4.6 hours, this representation deviates from the actual video
timing by half a frame time. For tracks with a 2997 timescale which are longer than 4.6 hours, a frame-accurate
representation of the video timing is only possible if the frames are allowed to have differing durations.
Most applications today only deal with material shorter than 4.6 hours. These applications should be able to read video
movies with either 2997 or 30000 TimeScales. They may write either, but the 30000 TimeScale is preferred since it has a
sufficient overflow time and precisely models the video signal.
Final Cut Pro uses 2997/100 and 2500/100. It will report that is has detected a dropped frame if the returned
frame durations do not match what was expected.
In addition to frame rate, there are two other terms you should know about. If the "frame rate" measures the
speed at which the movie is played back for the viewer, the "capture rate" is the rate at which the
'vdig' hardware is capable of capturing frames. The "effective capture rate" is the number of
frames per second that end up in a QuickTime movie. Many factors can make the effective
capture rate less than the intrinsic rate the hardware can support.
*/
#pragma mark-
//-----------------------------------------------------------------------
// includes
#include <Carbon/Carbon.h>
#include <IOKit/IOKitLib.h>
#include <stdio.h>
#include <QuickTime/ImageCodec.h> // for ImageDescription extentions
#include "SoftVDigX.h"
#include "SoftVDigKEXTCommon.h" // indexes for calling the user client
//-----------------------------------------------------------------------
/************************************************************************************/
// Setup required for ComponentDispatchHelper.c
#define VD_BASENAME() SoftVDigX
#define VD_GLOBALS() SoftVDigXGlobalsPtr storage
#define CALLCOMPONENT_BASENAME() VD_BASENAME()
#define CALLCOMPONENT_GLOBALS() VD_GLOBALS()
#define COMPONENT_DISPATCH_FILE "SoftVDigXDispatch.h"
#define COMPONENT_UPP_SELECT_ROOT() VD
#include <CoreServices/Components.k.h>
#include <QuickTime/QuickTimeComponents.k.h>
#include <QuickTime/ComponentDispatchHelper.c>
/************************************************************************************/
#define kComponentVersion 1
/************************************************************************************/
#pragma mark- kCompressionFormat
// the compression format - we only support k422YpCbCr8CodecType
const OSType kCompressionFormat = k422YpCbCr8CodecType;
#pragma mark---- Hardware Specific Calls
/* Digitizer Hardware Specific Calls */
// GetDeviceName - return the name from the IORegistry
static kern_return_t GetDeviceName(const io_service_t inObj, char outDeviceName[])
{
CFMutableDictionaryRef properties;
CFStringRef strDesc;
kern_return_t err;
err = IORegistryEntryCreateCFProperties(inObj, &properties, kCFAllocatorDefault, kNilOptions);
if (err) return err;
strDesc = (CFStringRef)CFDictionaryGetValue(properties, CFSTR("DeviceName"));
if(strDesc) {
CFStringGetCString(strDesc, outDeviceName, 33, kCFStringEncodingMacRoman);
}
CFRelease(properties);
return KERN_SUCCESS;
}
// ConnectToKEXT - attempt to find our driver and instantiate the user client
static Boolean ConnectToKEXT(SoftVDigXGlobalsPtr storage)
{
kern_return_t kernResult;
mach_port_t masterPort;
io_service_t serviceObject = 0;
io_iterator_t iterator;
CFDictionaryRef classToMatch;
Boolean result = true; // assume success
// return the mach port used to initiate communication with IOKit
kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (kernResult != KERN_SUCCESS) {
result = false;
goto bail;
}
classToMatch = IOServiceMatching( "com_dts_iokit_SoftVDigKEXT" );
if (NULL == classToMatch) {
result = false;
goto bail;
}
// create an io_iterator_t of all instances of our driver's class
// that exist in the IORegistry
kernResult = IOServiceGetMatchingServices(masterPort, classToMatch, &iterator);
if (kernResult != KERN_SUCCESS) {
result = false;
goto bail;
}
// get the first item in the iterator.
serviceObject = IOIteratorNext(iterator);
// release the io_iterator_t now that we're done with it.
IOObjectRelease(iterator);
if (0 == serviceObject){
result = false;
goto bail;
}
// instantiate the user client
kernResult = IOServiceOpen(serviceObject, mach_task_self(), 0, &(storage->userClient));
if(kernResult != KERN_SUCCESS) {
result = false;
goto bail;
}
// get the device name out of the registry
kernResult = GetDeviceName(serviceObject, storage->deviceName);
if(kernResult != KERN_SUCCESS) {
result = false;
goto bail;
}
kernResult = IOConnectMapMemory(storage->userClient,
1,
mach_task_self(),
&storage->framePtr,
&storage->frameSize,
kIOMapAnywhere );
bail:
if (serviceObject) {
// release the io_service_t now that we're done with it
IOObjectRelease(serviceObject);
}
return result;
}
// GetMaxSrcRectFromKEXT - call the driver to get the max source rect
static void GetMaxSrcRectFromKEXT(SoftVDigXGlobalsPtr storage, Rect* rect)
{
kern_return_t kernResult;
IOByteCount rectSize = sizeof(Rect);
kernResult = IOConnectMethodStructureIStructureO(storage->userClient,
kGetMaxSrcRect,
0, // input structure size
&rectSize, // ptr to output structure size
NULL, // ptr to input structure
rect); // ptr to output structure
}
/************************************************************************************/
#pragma mark---- Utility Functions
/* Utility Functions */
static void TimeToTimeCode(const TimeRecord *inAtTime, const TimeCodeDef *inTimeCodeDef, TimeCodeTime *inTimeCodeTime)
{
TimeRecord tr = *inAtTime;
UInt16 fps = inTimeCodeDef->numFrames;
SInt32 remainder;
UInt32 frameCount;
ConvertTimeScale(&tr, inTimeCodeDef->fTimeScale);
frameCount = CompDiv(&tr.value, inTimeCodeDef->frameDuration, &remainder);
if (inTimeCodeDef->flags & tcDropFrame) {
UInt32 number10s, number1s;
UInt32 fpm = fps * 60 - 2;
UInt32 fpm10 = fps * 10 * 60 - 9 * 2;
UInt32 frameAdjust;
UInt32 numberFramesLeft;
number10s = frameCount / fpm10;
frameAdjust = number10s * (9 * 2);
numberFramesLeft = frameCount % fpm10;
if (numberFramesLeft >= fps * 60) {
numberFramesLeft -= fps * 60;
number1s = numberFramesLeft / fpm;
frameAdjust += (number1s + 1) * 2;
}
frameCount += frameAdjust;
}
inTimeCodeTime->frames = frameCount % fps;
frameCount /= fps;
inTimeCodeTime->seconds = frameCount % 60;
frameCount /= 60;
inTimeCodeTime->minutes = frameCount % 60;
frameCount /= 60;
if (inTimeCodeDef->flags & tc24HourMax) {
frameCount %= 24;
}
inTimeCodeTime->hours = frameCount + 1; // we want to start at 1:00:00;00
}
/************************************************************************************/
#pragma mark---- Standard Component Calls
/* Standard Component Calls */
// Component Open Request - Required
// Note QuickTime may call you Video Digitizers Open many times - be sure to
// only perform a very minimum amount of work in this call
pascal ComponentResult SoftVDigXOpen(SoftVDigXGlobalsPtr storage, ComponentInstance self)
{
SInt32 response;
ComponentResult err;
// 10.4.8 or later
err = Gestalt(gestaltSystemVersion, &response);
if (err || (response < 0x1048)) return -1;
// we can only have one instance
if (CountComponentInstances((Component)self) > (short)kMaxSoftVDigXCount) return -1;
// allocate some memory for our globals...
storage = (SoftVDigXGlobalsPtr)NewPtrClear(sizeof(SoftVDigXGlobalsRecord));
if (err = MemError()) goto bail;
//...and tell the component manager about it
storage->self = self;
SetComponentInstanceStorage(self, (Handle)storage);
// see if we can connect to the KEXT
if(!ConnectToKEXT(storage)) return -1;
// ConnectToKext gets the device name from the IORegistry, and this is
// the base for the input name used in VDGetInputName - for our example
// device always append " 8-bit NTSC" because it's all that we do
strcat(storage->deviceName, " 8-bit NTSC");
// allocate an image description for the compressed type we support
storage->desc = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription));
if (err = MemError()) goto bail;
// initialize image description
// For information regarding the Image Description version number
// and proerties being added to the Image Description, please consult
// Ice Floe Dispach 19 and note how the information applies to the formats
// your Video Digitizer is supplying
// http://developer.apple.com/quicktime/icefloe/dispatch019.html
(**(storage->desc)).idSize = sizeof(ImageDescription);
(**(storage->desc)).cType = kCompressionFormat;
(**(storage->desc)).resvd1 = 0;
(**(storage->desc)).resvd2 = 0;
(**(storage->desc)).dataRefIndex = 0;
(**(storage->desc)).version = 2;
(**(storage->desc)).revisionLevel = 0;
(**(storage->desc)).vendor = 'dts ';
(**(storage->desc)).temporalQuality = 0; // not used
(**(storage->desc)).spatialQuality = codecLosslessQuality;
(**(storage->desc)).width = 0; // we fill in size later
(**(storage->desc)).height = 0;
(**(storage->desc)).hRes = 72 << 16; // not used, set to 72dpi
(**(storage->desc)).vRes = 72 << 16;
(**(storage->desc)).dataSize = 0;
(**(storage->desc)).frameCount = 1;
(**(storage->desc)).depth = 24;
(**(storage->desc)).clutID = -1; // no clut
err = GetComponentIndString((Component)storage->self, (*(storage->desc))->name, 200, 2);
if (err) goto bail;
// Add the ImageDescription properties
if (1 == (**(storage->desc)).version && (**(storage->desc)).revisionLevel == 1) {
// The 'colr' extension supersedes the previously defined 'gama' ImageDescription extension.
// Writers of QuickTime files should never write both into an ImageDescription.
// Readers of QuickTime files should ignore 'gama' if 'colr' is present.
Fixed gamma = FixRatio(22, 10);
err = ICMImageDescriptionSetProperty(storage->desc, kQTPropertyClass_ImageDescription,
kICMImageDescriptionPropertyID_GammaLevel,
sizeof(Fixed),
&gamma);
if (err) goto bail;
}
if (2 == (**(storage->desc)).version) {
// NOTE: these values may vary depending on your specific format - consult Ice Floe 19
// Field property
/*
* Information about the number and order of fields, if available.
*/
FieldInfoImageDescriptionExtension2 fieldInfo;
// http://developer.apple.com/quicktime/icefloe/dispatch019.html#fiel
fieldInfo.fields = kQTFieldsProgressiveScan;
fieldInfo.detail = kQTFieldDetailUnknown;
err = ICMImageDescriptionSetProperty(storage->desc, kQTPropertyClass_ImageDescription,
kICMImageDescriptionPropertyID_FieldInfo,
sizeof(FieldInfoImageDescriptionExtension2),
&fieldInfo);
if (err) goto bail;
CleanApertureImageDescriptionExtension cleanAperture;
PixelAspectRatioImageDescriptionExtension pixelAspectRatio;
// http://developer.apple.com/quicktime/icefloe/dispatch019.html#clap
cleanAperture.cleanApertureWidthN = 320;
cleanAperture.cleanApertureWidthD = 1;
cleanAperture.cleanApertureHeightN = 240;
cleanAperture.cleanApertureHeightD = 1;
cleanAperture.horizOffN = 0;
cleanAperture.horizOffD = 1;
cleanAperture.vertOffN = 0;
cleanAperture.vertOffD = 1;
// http://developer.apple.com/quicktime/icefloe/dispatch019.html#pasp
pixelAspectRatio.hSpacing = 1;
pixelAspectRatio.vSpacing = 1;
// Add the ImageDescription properties
// Clean Aperture
/*
* Describes the clean aperture of the buffer.
*/
err = ICMImageDescriptionSetProperty(storage->desc, kQTPropertyClass_ImageDescription,
kICMImageDescriptionPropertyID_CleanAperture,
sizeof(CleanApertureImageDescriptionExtension),
&cleanAperture);
if (err) goto bail;
// Pixel Aspect Ratio
/*
* Describes the pixel aspect ratio.
*/
err = ICMImageDescriptionSetProperty(storage->desc, kQTPropertyClass_ImageDescription,
kICMImageDescriptionPropertyID_PixelAspectRatio,
sizeof(PixelAspectRatioImageDescriptionExtension),
&pixelAspectRatio);
if (err) goto bail;
NCLCColorInfoImageDescriptionExtension colorInfo;
// http://developer.apple.com/quicktime/icefloe/dispatch019.html#colr
colorInfo.colorParamType = kVideoColorInfoImageDescriptionExtensionType;
colorInfo.primaries = kQTPrimaries_SMPTE_C;
colorInfo.transferFunction = kQTTransferFunction_ITU_R709_2;
colorInfo.matrix = kQTMatrix_ITU_R_601_4;
// Color Info
/*
* Color information, if available in the
* NCLCColorInfoImageDescriptionExtension format.
*/
err = ICMImageDescriptionSetProperty(storage->desc, kQTPropertyClass_ImageDescription,
kICMImageDescriptionPropertyID_NCLCColorInfo,
sizeof(NCLCColorInfoImageDescriptionExtension),
&colorInfo);
if (err) goto bail;
}
// initialize some of the global storage members
err = SoftVDigXGetMaxSrcRect(storage, ntscIn, &(storage->maxSrcRect));
if (err) goto bail;
storage->digiRect = storage->maxSrcRect;
err = SoftVDigXGetVideoDefaults(storage,
&(storage->blackLevel),
&(storage->whiteLevel),
&(storage->brightness),
&(storage->hue),
&(storage->saturation),
&(storage->contrast),
&(storage->sharpness));
bail:
return err;
}
// Component Close Request - Required
pascal ComponentResult SoftVDigXClose(SoftVDigXGlobalsPtr storage, ComponentInstance self)
{
#pragma unused(self)
// clean up
if (storage) {
if (storage->framePtr) {
// if we mapped in some memory (in ConnectToKEXT) from the kernel, unmap it here
IOConnectUnmapMemory(storage->userClient, 1, mach_task_self(), storage->framePtr);
}
// if we allocated memory for an image description, get rid of it
if (storage->desc) DisposeHandle((Handle)storage->desc);
// dispose of storage last
DisposePtr((Ptr)storage);
}
return noErr;
}
// Component Version Request - Required
pascal ComponentResult SoftVDigXVersion(SoftVDigXGlobalsPtr storage)
{
#pragma unused(store)
return (vdigInterfaceRev << 16) | kComponentVersion;
}
/************************************************************************************/
#pragma mark---- Video Digitizer Calls
/* Setting Source Characteristics
This section discusses the video digitizer component functions that allow applications to set the spatial
characteristics of the source video signal. Applications use these functions to set and retrieve
information about the maximum source rectangle, the active source rectangle, the vertical blanking rectangle,
and the digitizer rectangle. You can use the VDGetMaxSrcRect function in your application to get the size and
location of the maximum source rectangle. Similarly, the VDGetActiveSrcRect function allows you to get this information
about the active source rectangle, and the VDGetVBlankRect function enables you to obtain information about the vertical
blanking rectangle. You can use the VDSetDigitizerRect function to set the size and location of the digitizer rectangle.
The VDGetDigitizerRect function lets you retrieve the size and location of this rectangle. */
// VDGetMaxSrcRect - All video digitizer components must support this function.
// Returns the maximum source rectangle.
pascal VideoDigitizerError SoftVDigXGetMaxSrcRect(SoftVDigXGlobalsPtr storage, short inputStd, Rect *maxSrcRect)
{
// we only support NTSC
if (inputStd != ntscIn) {
DebugStr("\pSoftVDigXGetActiveSrcRect - returned qtParamErr");
return qtParamErr;
}
GetMaxSrcRectFromKEXT(storage, maxSrcRect); // ask the 'hardware' for it's maximum source rectangle
storage->maxSrcRect = *maxSrcRect; // remember it
return noErr;
}
// VDGetActiveSrcRect - All video digitizer components must support this function.
// Return the size and location information for the active source rectangle.
pascal VideoDigitizerError SoftVDigXGetActiveSrcRect(SoftVDigXGlobalsPtr storage, short inputStd, Rect *activeSrcRect)
{
// we only support NTSC
if (inputStd != ntscIn) {
DebugStr("\pSoftVDigXGetActiveSrcRect - returned qtParamErr");
return qtParamErr;
}
if (EmptyRect(&storage->maxSrcRect)) return badCallOrderErr;
// our active source rectangle is the same as our maximum source rectangle, yours may be different
*activeSrcRect = storage->maxSrcRect;
return noErr;
}
// VDSetDigitizerRect - All video digitizer components must support this function.
// Sets the current video digitizer rectangle.
pascal VideoDigitizerError SoftVDigXSetDigitizerRect(SoftVDigXGlobalsPtr storage, Rect *digiRect)
{
Rect tempR;
// can't be empty
if (!digiRect || EmptyRect(digiRect)) return qtParamErr;
// they must intersect
if (!SectRect(digiRect, &(storage->maxSrcRect), &tempR)) return qtParamErr;
// completely...
if (!MacEqualRect(digiRect, &tempR)) return qtParamErr;
storage->digiRect = *digiRect;
return noErr;
}
// VDGetDigitizerRec - All video digitizer components must support this function.
// Returns the current digitizer rectangle.
pascal VideoDigitizerError SoftVDigXGetDigitizerRect(SoftVDigXGlobalsPtr storage, Rect *digiRect)
{
*digiRect = storage->digiRect;
return noErr;
}
// VDGetVBlankRect - All video digitizer components must support this function.