forked from btrask/EasyCapViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathECVSTK1160Device.m
597 lines (556 loc) · 18.2 KB
/
ECVSTK1160Device.m
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
/* Copyright (c) 2009, Ben Trask
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY BEN TRASK ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BEN TRASK BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#import "ECVSTK1160Device.h"
#import "stk11xx.h"
// Video
#import "ECVDeinterlacingMode.h"
#import "ECVPixelBuffer.h"
// Other Sources
#import "ECVDebug.h"
#import "ECVPixelFormat.h"
// External
#import "BTUserDefaults.h"
#define ECVRotationFrameSkip 2 // This affects the framerate and video quality. '1' doesn't skip frames, but looks bad. '3' looks almost perfect but results in a low framerate. '2' is a balance between the two.
enum {
ECVSTK1160HighFieldFlag = 1 << 6,
ECVSTK1160NewImageFlag = 1 << 7,
};
static NSString *const ECVSTK1160VideoSourceKey = @"ECVSTK1160VideoSource";
static NSString *const ECVSTK1160VideoFormatKey = @"ECVSTK1160VideoFormat";
@interface ECVSTK1160Device(Private)
- (ECVIntegerSize)_inputSize;
- (BOOL)_initializeAudio;
- (BOOL)_initializeResolution;
- (BOOL)_setVideoSource:(ECVSTK1160VideoSource)source;
- (BOOL)_setStreaming:(BOOL)flag;
- (BOOL)_SAA711XExpect:(u_int8_t)val;
@end
@implementation ECVSTK1160Device
#pragma mark -ECVSTK1160Device
@synthesize videoSource = _videoSource;
- (void)setVideoSource:(ECVSTK1160VideoSource)source
{
if(source == _videoSource) return;
ECVPauseWhile(self, { _videoSource = source; });
[[self defaults] setInteger:source forKey:ECVSTK1160VideoSourceKey];
}
@synthesize videoFormat = _videoFormat;
- (void)setVideoFormat:(ECVSTK1160VideoFormat)format
{
if(format == _videoFormat) return;
ECVPauseWhile(self, { _videoFormat = format; });
[[self defaults] setInteger:format forKey:ECVSTK1160VideoFormatKey];
}
#pragma mark -
- (BOOL)readIndex:(UInt16 const)i value:(out UInt8 *const)outValue
{
UInt8 v = 0;
BOOL const r = [self readRequest:kUSBRqGetStatus value:0 index:i length:sizeof(v) data:&v];
if(outValue) *outValue = v;
return r;
}
- (BOOL)writeIndex:(UInt16 const)i value:(UInt8 const)v
{
return [self writeRequest:kUSBRqClearFeature value:v index:i length:0 data:NULL];
}
- (BOOL)setFeatureAtIndex:(u_int16_t)i
{
return [self controlRequestWithType:USBmakebmRequestType(kUSBOut, kUSBStandard, kUSBDevice) request:kUSBRqSetFeature value:0 index:i length:0 data:NULL];
}
#pragma mark -ECVSTK1160Device(Private)
- (ECVIntegerSize)_inputSize
{
return (ECVIntegerSize){720, [self is60HzFormat] ? 480 : 576};
}
- (BOOL)_initializeAudio
{
if(![self writeVT1612ARegister:0x94 value:0x00]) return NO;
if(![self writeIndex:0x0506 value:0x01]) return NO;
if(![self writeIndex:0x0507 value:0x00]) return NO;
if(![_VT1612AChip initialize]) return NO;
ECVLog(ECVNotice, @"Device audio version: %@", [_VT1612AChip vendorAndRevisionString]);
return YES;
}
- (BOOL)_initializeResolution
{
ECVIntegerSize inputSize = [self _inputSize];
ECVIntegerSize standardSize = inputSize;
switch(inputSize.width) {
case 704:
case 352:
case 176:
inputSize.width = 704;
standardSize.width = 706;
break;
case 640:
case 320:
case 160:
inputSize.width = 640;
standardSize.width = 644;
break;
}
switch(inputSize.height) {
case 576:
case 288:
case 144:
inputSize.height = 576;
standardSize.height = 578;
break;
case 480:
case 240:
case 120:
inputSize.height = 480;
standardSize.height = 486;
break;
}
size_t const bpp = ECVPixelFormatBytesPerPixel([self pixelFormatType]);
struct {
u_int16_t reg;
u_int16_t val;
} settings[] = {
{0x110, (standardSize.width - inputSize.width) * bpp},
{0x111, 0},
{0x112, (standardSize.height - inputSize.height) / 2},
{0x113, 0},
{0x114, standardSize.width * bpp},
{0x115, 5},
{0x116, standardSize.height / 2},
{0x117, ![self is60HzFormat]},
};
NSUInteger i = 0;
for(; i < numberof(settings); i++) if(![self writeIndex:settings[i].reg value:settings[i].val]) return NO;
return YES;
}
- (BOOL)_setVideoSource:(ECVSTK1160VideoSource)source
{
UInt8 val = 0;
switch(source) {
case ECVSTK1160SVideoInput:
return YES;
case ECVSTK1160Composite1Input: val = 3; break;
case ECVSTK1160Composite2Input: val = 2; break;
case ECVSTK1160Composite3Input: val = 1; break;
case ECVSTK1160Composite4Input: val = 0; break;
default:
return NO;
}
if(dev_stk0408_write0(self, 1 << 7 | 0x3 << 3, 1 << 7 | val << 3)) return NO;
return YES;
}
- (BOOL)_setStreaming:(BOOL)flag
{
u_int8_t value;
if(![self readIndex:STK0408StatusRegistryIndex value:&value]) return NO;
if(flag) value |= STK0408StatusStreaming;
else value &= ~STK0408StatusStreaming;
return [self writeIndex:STK0408StatusRegistryIndex value:value];
}
- (BOOL)_SAA711XExpect:(u_int8_t)val
{
NSUInteger retry = 4;
u_int8_t result = 0;
while(retry--) {
if(![self readIndex:0x201 value:&result]) return NO;
if(val == result) return YES;
usleep(100);
}
ECVLog(ECVError, @"Invalid SAA711X result %x (expected %x)", (unsigned)result, (unsigned)val);
return NO;
}
#pragma mark -ECVCaptureDevice
- (id)initWithService:(io_service_t)service error:(out NSError **)outError
{
if((self = [super initWithService:service error:outError])) {
BTUserDefaults *const d = [self defaults];
[d registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInteger:ECVSTK1160Composite1Input], ECVSTK1160VideoSourceKey,
[NSNumber numberWithUnsignedInteger:ECVSTK1160NTSCMFormat], ECVSTK1160VideoFormatKey,
nil]];
[self setVideoSource:[d integerForKey:ECVSTK1160VideoSourceKey]];
[self setVideoFormat:[d integerForKey:ECVSTK1160VideoFormatKey]];
_SAA711XChip = [[SAA711XChip alloc] init];
[_SAA711XChip setBrightness:[[d objectForKey:ECVBrightnessKey] doubleValue]];
[_SAA711XChip setContrast:[[d objectForKey:ECVContrastKey] doubleValue]];
[_SAA711XChip setSaturation:[[d objectForKey:ECVSaturationKey] doubleValue]];
[_SAA711XChip setHue:[[d objectForKey:ECVHueKey] doubleValue]];
[_SAA711XChip setDevice:self];
_VT1612AChip = [[VT1612AChip alloc] init];
[_VT1612AChip setDevice:self];
}
return self;
}
#pragma mark -ECVCaptureController(ECVAbstract)
- (BOOL)requiresHighSpeed
{
return YES;
}
- (ECVIntegerSize)captureSize
{
return [self _inputSize];
}
- (UInt8)isochReadingPipe
{
return 2;
}
- (QTTime)frameRate
{
return [self is60HzFormat] ? QTMakeTime(1001, 60000) : QTMakeTime(1, 50); // FIXME: Figure out why the A/V sync goes bad over time.
}
- (OSType)pixelFormatType
{
return k2vuyPixelFormat;
}
#pragma mark -
- (BOOL)threaded_play
{
_offset = 0;
dev_stk0408_initialize_device(self);
if(![_SAA711XChip initialize]) return NO;
ECVLog(ECVNotice, @"Device video version: %lx", (unsigned long)[_SAA711XChip versionNumber]);
if(![self _initializeAudio]) return NO;
if(![self _setVideoSource:[self videoSource]]) return NO;
if(![self _initializeResolution]) return NO;
if(![self setAlternateInterface:5]) return NO;
if(![self _setStreaming:YES]) return NO;
return YES;
}
- (BOOL)threaded_pause
{
(void)[self _setStreaming:NO];
(void)[self setAlternateInterface:0];
return YES;
}
- (BOOL)threaded_watchdog
{
u_int8_t value;
if(![self readIndex:0x01 value:&value]) return NO;
if(0x03 != value) {
ECVLog(ECVError, @"Device watchdog was 0x%02x (should be 0x03).", value);
return NO;
}
return YES;
}
- (void)threaded_nextFieldType:(ECVFieldType)fieldType
{
[super threaded_nextFieldType:fieldType];
_offset = 0;
}
- (void)threaded_readBytes:(UInt8 const *)bytes length:(size_t)length
{
if(!length) return;
size_t skip = 4;
if(ECVSTK1160NewImageFlag & bytes[0]) {
[self threaded_nextFieldType:ECVSTK1160HighFieldFlag & bytes[0] ? ECVHighField : ECVLowField];
skip = 8;
}
if(length <= skip) return;
NSUInteger const realLength = length - skip;
ECVIntegerSize const inputSize = [self _inputSize];
ECVIntegerSize const pixelSize = (ECVIntegerSize){inputSize.width, inputSize.height / 2};
OSType const pixelFormatType = [self pixelFormatType];
NSUInteger const bytesPerRow = ECVPixelFormatBytesPerPixel(pixelFormatType) * pixelSize.width;
ECVPointerPixelBuffer *const buffer = [[ECVPointerPixelBuffer alloc] initWithPixelSize:pixelSize bytesPerRow:bytesPerRow pixelFormat:pixelFormatType bytes:bytes + skip validRange:NSMakeRange(_offset, realLength)];
[self threaded_drawPixelBuffer:buffer atPoint:(ECVIntegerPoint){0, 0}];
[buffer release];
_offset += realLength;
}
#pragma mark -NSObject
- (void)dealloc
{
[_SAA711XChip setDevice:nil];
[_VT1612AChip setDevice:nil];
[_SAA711XChip release];
[_VT1612AChip release];
[super dealloc];
}
#pragma mark -<ECVCaptureControllerConfiguring>
- (NSArray *)allVideoSourceObjects
{
return [NSArray arrayWithObjects:
[NSNumber numberWithUnsignedInteger:ECVSTK1160SVideoInput],
[NSNumber numberWithUnsignedInteger:ECVSTK1160Composite1Input],
[NSNumber numberWithUnsignedInteger:ECVSTK1160Composite2Input],
[NSNumber numberWithUnsignedInteger:ECVSTK1160Composite3Input],
[NSNumber numberWithUnsignedInteger:ECVSTK1160Composite4Input],
nil];
}
- (id)videoSourceObject
{
return [NSNumber numberWithUnsignedInteger:[self videoSource]];
}
- (void)setVideoSourceObject:(id)obj
{
[self setVideoSource:[obj unsignedIntegerValue]];
}
- (NSString *)localizedStringForVideoSourceObject:(id)obj
{
switch([obj unsignedIntegerValue]) {
case ECVSTK1160SVideoInput: return NSLocalizedString(@"S-Video", nil);
case ECVSTK1160Composite1Input: return NSLocalizedString(@"Composite 1", nil);
case ECVSTK1160Composite2Input: return NSLocalizedString(@"Composite 2", nil);
case ECVSTK1160Composite3Input: return NSLocalizedString(@"Composite 3", nil);
case ECVSTK1160Composite4Input: return NSLocalizedString(@"Composite 4", nil);
}
return nil;
}
- (BOOL)isValidVideoSourceObject:(id)obj
{
return YES;
}
- (NSInteger)indentationLevelForVideoSourceObject:(id)obj
{
return 0;
}
#pragma mark -
- (NSArray *)allVideoFormatObjects
{
return [NSArray arrayWithObjects:
NSLocalizedString(@"60Hz", nil),
[NSNumber numberWithUnsignedInteger:ECVSTK1160NTSCMFormat],
[NSNumber numberWithUnsignedInteger:ECVSTK1160PAL60Format],
[NSNumber numberWithUnsignedInteger:ECVSTK1160PALMFormat],
[NSNumber numberWithUnsignedInteger:ECVSTK1160NTSC44360HzFormat],
[NSNumber numberWithUnsignedInteger:ECVSTK1160NTSCJFormat],
NSLocalizedString(@"50Hz", nil),
[NSNumber numberWithUnsignedInteger:ECVSTK1160PALBGDHIFormat],
[NSNumber numberWithUnsignedInteger:ECVSTK1160PALNFormat],
[NSNumber numberWithUnsignedInteger:ECVSTK1160NTSCNFormat],
[NSNumber numberWithUnsignedInteger:ECVSTK1160NTSC44350HzFormat],
[NSNumber numberWithUnsignedInteger:ECVSTK1160SECAMFormat],
nil];
}
- (id)videoFormatObject
{
return [NSNumber numberWithUnsignedInteger:[self videoFormat]];
}
- (void)setVideoFormatObject:(id)obj
{
[self setVideoFormat:[obj unsignedIntegerValue]];
}
- (NSString *)localizedStringForVideoFormatObject:(id)obj
{
if(![obj isKindOfClass:[NSNumber class]]) return [obj description];
switch([obj unsignedIntegerValue]) {
case ECVSTK1160Auto60HzFormat : return NSLocalizedString(@"Auto-detect", nil);
case ECVSTK1160NTSCMFormat : return NSLocalizedString(@"NTSC", nil);
case ECVSTK1160PAL60Format : return NSLocalizedString(@"PAL-60", nil);
case ECVSTK1160PALMFormat : return NSLocalizedString(@"PAL-M", nil);
case ECVSTK1160NTSC44360HzFormat: return NSLocalizedString(@"NTSC 4.43", nil);
case ECVSTK1160NTSCJFormat : return NSLocalizedString(@"NTSC-J", nil);
case ECVSTK1160Auto50HzFormat : return NSLocalizedString(@"Auto-detect", nil);
case ECVSTK1160PALBGDHIFormat : return NSLocalizedString(@"PAL", nil);
case ECVSTK1160PALNFormat : return NSLocalizedString(@"PAL-N", nil);
case ECVSTK1160NTSC44350HzFormat: return NSLocalizedString(@"NTSC 4.43", nil);
case ECVSTK1160NTSCNFormat : return NSLocalizedString(@"NTSC-N", nil);
case ECVSTK1160SECAMFormat : return NSLocalizedString(@"SECAM", nil);
default: return nil;
}
}
- (BOOL)isValidVideoFormatObject:(id)obj
{
return [obj isKindOfClass:[NSNumber class]];
}
- (NSInteger)indentationLevelForVideoFormatObject:(id)obj
{
return [self isValidVideoFormatObject:obj] ? 1 : 0;
}
#pragma mark -
- (CGFloat)brightness
{
return [_SAA711XChip brightness];
}
- (void)setBrightness:(CGFloat)val
{
[_SAA711XChip setBrightness:val];
[[self defaults] setObject:[NSNumber numberWithDouble:val] forKey:ECVBrightnessKey];
}
- (CGFloat)contrast
{
return [_SAA711XChip contrast];
}
- (void)setContrast:(CGFloat)val
{
[_SAA711XChip setContrast:val];
[[self defaults] setObject:[NSNumber numberWithDouble:val] forKey:ECVContrastKey];
}
- (CGFloat)saturation
{
return [_SAA711XChip saturation];
}
- (void)setSaturation:(CGFloat)val
{
[_SAA711XChip setSaturation:val];
[[self defaults] setObject:[NSNumber numberWithDouble:val] forKey:ECVSaturationKey];
}
- (CGFloat)hue
{
return [_SAA711XChip hue];
}
- (void)setHue:(CGFloat)val
{
[_SAA711XChip setHue:val];
[[self defaults] setObject:[NSNumber numberWithDouble:val] forKey:ECVHueKey];
}
#pragma mark -<ECVComponentConfiguring>
- (long)inputCapabilityFlags
{
return digiInDoesNTSC | digiInDoesPAL | digiInDoesSECAM | digiInDoesColor | digiInDoesComposite | digiInDoesSVideo;
}
- (short)inputFormatForVideoSourceObject:(id)obj
{
switch([obj unsignedIntegerValue]) {
case ECVSTK1160SVideoInput:
return sVideoIn;
case ECVSTK1160Composite1Input:
case ECVSTK1160Composite2Input:
case ECVSTK1160Composite3Input:
case ECVSTK1160Composite4Input:
return compositeIn;
default:
ECVAssertNotReached(@"Invalid video source %lu.", (unsigned long)[obj unsignedIntegerValue]);
return 0;
}
}
- (short)inputStandard
{
switch([self videoFormat]) {
case ECVSTK1160NTSCMFormat: return ntscReallyIn;
case ECVSTK1160PALBGDHIFormat: return palIn;
case ECVSTK1160SECAMFormat: return secamIn;
default: return currentIn;
}
}
- (void)setInputStandard:(short)standard
{
ECVSTK1160VideoFormat format;
switch(standard) {
case ntscReallyIn: format = ECVSTK1160NTSCMFormat; break;
case palIn: format = ECVSTK1160PALBGDHIFormat; break;
case secamIn: format = ECVSTK1160SECAMFormat; break;
default: return;
}
[self setVideoFormat:format];
}
#pragma mark -<SAA711XDevice>
- (BOOL)writeSAA711XRegister:(u_int8_t)reg value:(int16_t)val
{
if(![self writeIndex:0x204 value:reg]) return NO;
if(![self writeIndex:0x205 value:val]) return NO;
if(![self writeIndex:0x200 value:0x01]) return NO;
if(![self _SAA711XExpect:0x04]) {
ECVLog(ECVError, @"SAA711X failed to write %x to %x", (unsigned)val, (unsigned)reg);
return NO;
}
return YES;
}
- (BOOL)readSAA711XRegister:(u_int8_t)reg value:(out u_int8_t *)outVal
{
if(![self writeIndex:0x208 value:reg]) return NO;
if(![self writeIndex:0x200 value:0x20]) return NO;
if(![self _SAA711XExpect:0x01]) {
ECVLog(ECVError, @"SAA711X failed to read %x", (unsigned)reg);
return NO;
}
return [self readIndex:0x209 value:outVal];
}
- (SAA711XMODESource)SAA711XMODESource
{
switch([self videoSource]) {
case ECVSTK1160SVideoInput: return SAA711XMODESVideoAI12_YGain;
default: return SAA711XMODECompositeAI11;
}
}
- (BOOL)SVideo
{
return ECVSTK1160SVideoInput == [self videoSource];
}
- (SAA711XCSTDFormat)SAA711XCSTDFormat
{
switch([self videoFormat]) {
case ECVSTK1160Auto60HzFormat: return SAA711XAUTO0AutomaticChrominanceStandardDetection;
case ECVSTK1160NTSCMFormat: return SAA711XCSTDNTSCM;
case ECVSTK1160PAL60Format: return SAA711XCSTDPAL60Hz;
case ECVSTK1160PALMFormat: return SAA711XCSTDPALM;
case ECVSTK1160NTSC44360HzFormat: return SAA711XCSTDNTSC44360Hz;
case ECVSTK1160NTSCJFormat: return SAA711XCSTDNTSCJ;
case ECVSTK1160Auto50HzFormat: return SAA711XAUTO0AutomaticChrominanceStandardDetection;
case ECVSTK1160PALBGDHIFormat: return SAA711XCSTDPAL_BGDHI;
case ECVSTK1160PALNFormat: return SAA711XCSTDPALN;
case ECVSTK1160NTSC44350HzFormat: return SAA711XCSTDNTSC44350Hz;
case ECVSTK1160NTSCNFormat: return SAA711XCSTDNTSCN;
case ECVSTK1160SECAMFormat: return SAA711XCSTDSECAM;
default: return 0;
}
}
- (BOOL)is60HzFormat
{
switch([self videoFormat]) {
case ECVSTK1160Auto60HzFormat:
case ECVSTK1160NTSCMFormat:
case ECVSTK1160PAL60Format:
case ECVSTK1160PALMFormat:
case ECVSTK1160NTSC44360HzFormat:
case ECVSTK1160NTSCJFormat:
return YES;
case ECVSTK1160Auto50HzFormat:
case ECVSTK1160PALBGDHIFormat:
case ECVSTK1160PALNFormat:
case ECVSTK1160NTSCNFormat:
case ECVSTK1160NTSC44350HzFormat:
case ECVSTK1160SECAMFormat:
return NO;
default:
ECVAssertNotReached(@"Invalid video format.");
return NO;
}
}
- (BOOL)SAA711XRTP0OutputPolarityInverted
{
return YES;
}
#pragma mark -<VT1612ADevice>
- (BOOL)writeVT1612ARegister:(u_int8_t)reg value:(u_int16_t)val
{
union {
u_int16_t v16;
u_int8_t v8[2];
} const v = {
.v16 = CFSwapInt16HostToLittle(val),
};
if(![self writeIndex:0x504 value:reg]) return NO;
if(![self writeIndex:0x502 value:v.v8[0]]) return NO;
if(![self writeIndex:0x503 value:v.v8[1]]) return NO;
if(![self writeIndex:0x500 value:0x8c]) return NO;
return YES;
}
- (BOOL)readVT1612ARegister:(u_int8_t)reg value:(out u_int16_t *)outVal
{
if(![self writeIndex:0x504 value:reg]) return NO;
if(![self writeIndex:0x500 value:0x8b]) return NO;
union {
u_int8_t v8[2];
u_int16_t v16;
} val = {};
if(![self readIndex:0x502 value:val.v8 + 0]) return NO;
if(![self readIndex:0x503 value:val.v8 + 1]) return NO;
if(outVal) *outVal = CFSwapInt16LittleToHost(val.v16);
return YES;
}
@end