mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
prefer high res frame grabs on retina ipads
git-svn-id: https://zxing.googlecode.com/svn/trunk@2298 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
2dd5d26c4a
commit
4a561f4599
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:objc; c-basic-offset:2; indent-tabs-mode:nil -*-
|
||||||
/**
|
/**
|
||||||
* Copyright 2009 Jeff Verkoeyen
|
* Copyright 2009 Jeff Verkoeyen
|
||||||
*
|
*
|
||||||
|
@ -301,12 +302,30 @@
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark AVFoundation
|
#pragma mark AVFoundation
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
// Gross, I know, but ...
|
||||||
|
static bool isIPad() {
|
||||||
|
static int is_ipad = -1;
|
||||||
|
if (is_ipad < 0) {
|
||||||
|
size_t size;
|
||||||
|
sysctlbyname("hw.machine", NULL, &size, NULL, 0); // Get size of data to be returned.
|
||||||
|
char *name = malloc(size);
|
||||||
|
sysctlbyname("hw.machine", name, &size, NULL, 0);
|
||||||
|
NSString *machine = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
|
||||||
|
free(name);
|
||||||
|
is_ipad = [machine hasPrefix:@"iPad"];
|
||||||
|
}
|
||||||
|
return !!is_ipad;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)initCapture {
|
- (void)initCapture {
|
||||||
#if HAS_AVFF
|
#if HAS_AVFF
|
||||||
|
AVCaptureDevice* inputDevice =
|
||||||
|
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
|
||||||
AVCaptureDeviceInput *captureInput =
|
AVCaptureDeviceInput *captureInput =
|
||||||
[AVCaptureDeviceInput deviceInputWithDevice:
|
[AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil];
|
||||||
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]
|
|
||||||
error:nil];
|
|
||||||
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
|
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
|
||||||
captureOutput.alwaysDiscardsLateVideoFrames = YES;
|
captureOutput.alwaysDiscardsLateVideoFrames = YES;
|
||||||
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
|
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
|
||||||
|
@ -315,7 +334,21 @@
|
||||||
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
|
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
|
||||||
[captureOutput setVideoSettings:videoSettings];
|
[captureOutput setVideoSettings:videoSettings];
|
||||||
self.captureSession = [[[AVCaptureSession alloc] init] autorelease];
|
self.captureSession = [[[AVCaptureSession alloc] init] autorelease];
|
||||||
self.captureSession.sessionPreset = AVCaptureSessionPresetMedium; // 480x360 on a 4
|
|
||||||
|
NSString* preset = 0;
|
||||||
|
if (NSClassFromString(@"NSOrderedSet") && // Proxy for "is this iOS 5" ...
|
||||||
|
[UIScreen mainScreen].scale > 1 &&
|
||||||
|
isIPad() &&
|
||||||
|
[inputDevice
|
||||||
|
supportsAVCaptureSessionPreset:AVCaptureSessionPresetiFrame960x540]) {
|
||||||
|
NSLog(@"960");
|
||||||
|
preset = AVCaptureSessionPresetiFrame960x540;
|
||||||
|
}
|
||||||
|
if (!preset) {
|
||||||
|
NSLog(@"MED");
|
||||||
|
preset = AVCaptureSessionPresetMedium;
|
||||||
|
}
|
||||||
|
self.captureSession.sessionPreset = preset;
|
||||||
|
|
||||||
[self.captureSession addInput:captureInput];
|
[self.captureSession addInput:captureInput];
|
||||||
[self.captureSession addOutput:captureOutput];
|
[self.captureSession addOutput:captureOutput];
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
#define ZXMediaTypeVideo QTMediaTypeVideo
|
#define ZXMediaTypeVideo QTMediaTypeVideo
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ZXAV(1)+0
|
||||||
|
static bool isIPad();
|
||||||
|
#endif
|
||||||
|
|
||||||
@implementation ZXCapture
|
@implementation ZXCapture
|
||||||
|
|
||||||
@synthesize delegate;
|
@synthesize delegate;
|
||||||
|
@ -128,6 +132,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
|
ZXAV({
|
||||||
|
NSString* preset = 0;
|
||||||
|
if (NSClassFromString(@"NSOrderedSet") && // Proxy for "is this iOS 5" ...
|
||||||
|
[UIScreen mainScreen].scale > 1 &&
|
||||||
|
isIPad() &&
|
||||||
|
[zxd supportsAVCaptureSessionPreset:AVCaptureSessionPresetiFrame960x540]) {
|
||||||
|
// NSLog(@"960");
|
||||||
|
preset = AVCaptureSessionPresetiFrame960x540;
|
||||||
|
}
|
||||||
|
if (!preset) {
|
||||||
|
// NSLog(@"MED");
|
||||||
|
preset = AVCaptureSessionPresetMedium;
|
||||||
|
}
|
||||||
|
session.sessionPreset = preset;
|
||||||
|
});
|
||||||
[session addInput:input ZXQT(error:nil)];
|
[session addInput:input ZXQT(error:nil)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +154,6 @@
|
||||||
- (ZXCaptureSession*)session {
|
- (ZXCaptureSession*)session {
|
||||||
if (session == 0) {
|
if (session == 0) {
|
||||||
session = [[ZXCaptureSession alloc] init];
|
session = [[ZXCaptureSession alloc] init];
|
||||||
ZXAV({session.sessionPreset = AVCaptureSessionPresetMedium;});
|
|
||||||
[self replaceInput];
|
[self replaceInput];
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
|
@ -553,6 +571,28 @@ ZXAV(didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
// If you try to define this higher, there (seem to be) clashes with something(s) defined
|
||||||
|
// in the includes ...
|
||||||
|
|
||||||
|
#if ZXAV(1)+0
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
// Gross, I know, but ...
|
||||||
|
static bool isIPad() {
|
||||||
|
static int is_ipad = -1;
|
||||||
|
if (is_ipad < 0) {
|
||||||
|
size_t size;
|
||||||
|
sysctlbyname("hw.machine", NULL, &size, NULL, 0); // Get size of data to be returned.
|
||||||
|
char* name = (char*)malloc(size);
|
||||||
|
sysctlbyname("hw.machine", name, &size, NULL, 0);
|
||||||
|
NSString *machine = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
|
||||||
|
free(name);
|
||||||
|
is_ipad = [machine hasPrefix:@"iPad"];
|
||||||
|
}
|
||||||
|
return !!is_ipad;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@implementation ZXCapture
|
@implementation ZXCapture
|
||||||
|
|
Loading…
Reference in a new issue