| ARX 1.0 The next-generation open source augmented reality toolkit.

Loading...
Searching...
No Matches
CameraVideo.h
Go to the documentation of this file.
1/*
2 * CameraVideo.h
3 * artoolkitX
4 *
5 * This file is part of artoolkitX.
6 *
7 * artoolkitX is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * artoolkitX is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with artoolkitX. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * As a special exception, the copyright holders of this library give you
21 * permission to link this library with independent modules to produce an
22 * executable, regardless of the license terms of these independent modules, and to
23 * copy and distribute the resulting executable under terms of your choice,
24 * provided that you also meet, for each linked independent module, the terms and
25 * conditions of the license of that module. An independent module is a module
26 * which is neither derived from nor based on this library. If you modify this
27 * library, you may extend this exception to your version of the library, but you
28 * are not obligated to do so. If you do not wish to do so, delete this exception
29 * statement from your version.
30 *
31 * Copyright 2018 Realmax, Inc.
32 * Copyright 2015 Daqri, LLC.
33 * Copyright 2008-2015 ARToolworks, Inc.
34 *
35 * Author(s): Philip Lamb
36 *
37 * Rev Date Who Changes
38 * 1.0.0 2008-05-04 PRL Written.
39 *
40 */
41
42#import <AVFoundation/AVFoundation.h>
43
44@protocol CameraVideoTookPictureDelegate<NSObject>
45@required
46/*
47 This delegate method is called each time a frame is captured
48 from the video stream.
49
50 The frame can be retrieved with the call:
51
52 UInt64 timestamp;
53 unsigned char *frameData = frameTimestamp:&timestamp;
54 */
55- (void) cameraVideoTookPicture:(id)sender userData:(void *)data;
56@optional
57/*
58 This delegate method is called if the user requested a high-resolution JPEG photo.
59 You can write the JPEG to the user's photo roll with this code:
60
61 #import <AssetsLibrary/AssetsLibrary.h>
62 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
63 [library writeImageDataToSavedPhotosAlbum:jpegData metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
64 if (error) {
65 NSLog(@"Error writing captured photo to photo album.\n");
66 }
67 }];
68 [library release];
69
70 or you can write it directly to a file:
71
72 if (![jpegData writeToFile:jpegPath atomically:NO]) {
73 NSLog(@"Error writing captured photo to '%@'\n", jpegPath);
74 }
75
76 There is no guarantee that this call will be made on any particular thread.
77*/
78- (void) cameravideoTookPictureHires:(id)sender userData:(void *)data jpegData:(NSData *)jpegData;
79@end
80
81 typedef void (^CameraVideoStartAsyncCompletionBlock)(void);
82
83 extern NSString *const CameraVideoiOSDeviceiPhone; // "iPhone"
84 extern NSString *const CameraVideoiOSDeviceiPhone3G; // "iPhone 3G"
85 extern NSString *const CameraVideoiOSDeviceiPhone3GS; // "iPhone 3GS"
86 extern NSString *const CameraVideoiOSDeviceiPhone4; // "iPhone 4"
87 extern NSString *const CameraVideoiOSDeviceiPhone4S; // "iPhone 4S"
88 extern NSString *const CameraVideoiOSDeviceiPhone5; // "iPhone 5"
89 extern NSString *const CameraVideoiOSDeviceiPhone5s; // "iPhone 5s"
90 extern NSString *const CameraVideoiOSDeviceiPhone5c; // "iPhone 5c"
91 extern NSString *const CameraVideoiOSDeviceiPhone6; // "iPhone 6"
92 extern NSString *const CameraVideoiOSDeviceiPhone6Plus; // "iPhone 6 Plus"
93 extern NSString *const CameraVideoiOSDeviceiPhone6S; // "iPhone 6S"
94 extern NSString *const CameraVideoiOSDeviceiPhone6SPlus; // "iPhone 6S Plus"
95 extern NSString *const CameraVideoiOSDeviceiPhoneSE; // "iPhone SE"
96 extern NSString *const CameraVideoiOSDeviceiPhone7; // "iPhone 7"
97 extern NSString *const CameraVideoiOSDeviceiPhone7Plus; // "iPhone 7 Plus"
98 extern NSString *const CameraVideoiOSDeviceiPodTouch4; // "iPod Touch (4th Generation)"
99 extern NSString *const CameraVideoiOSDeviceiPodTouch5; // "iPod Touch (5th Generation)"
100 extern NSString *const CameraVideoiOSDeviceiPodTouch6; // "iPod Touch (6th Generation)"
101 extern NSString *const CameraVideoiOSDeviceiPad2; // "iPad 2"
102 extern NSString *const CameraVideoiOSDeviceiPad3; // "iPad (3rd generation)"
103 extern NSString *const CameraVideoiOSDeviceiPad4; // "iPad (4th generation)"
104 extern NSString *const CameraVideoiOSDeviceiPadAir; // "iPad Air"
105 extern NSString *const CameraVideoiOSDeviceiPadAir2; // "iPad Air 2"
106 extern NSString *const CameraVideoiOSDeviceiPadMini; // "iPad mini"
107 extern NSString *const CameraVideoiOSDeviceiPadMini2; // "iPad mini (2nd generation)"
108 extern NSString *const CameraVideoiOSDeviceiPadMini3; // "iPad mini (3rd generation)"
109 extern NSString *const CameraVideoiOSDeviceiPadMini4; // "iPad mini (4th generation)"
110 extern NSString *const CameraVideoiOSDeviceiPadPro129; // "iPad Pro 12.9\""
111 extern NSString *const CameraVideoiOSDeviceiPadPro97; // "iPad Pro 9.7\""
112 extern NSString *const CameraVideoiOSDeviceiPhoneX; // "iPhone (Unknown model)"
113 extern NSString *const CameraVideoiOSDeviceiPodX; // "iPod (Unknown model)"
114 extern NSString *const CameraVideoiOSDeviceiPadX; // "iPad (Unknown model)"
115 extern NSString *const CameraVideoiOSDeviceAppleTVX; // "Apple TV (Unknown model)"
116
117@class CameraVideo;
118
119@interface CameraVideo : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
120
121- (id) init;
122
123@property(readonly) NSString *iOSDevice;
124
125/*
126 Set or get the video image quality/size.
127
128 Attempts to change this property while (running == TRUE) will be ignored.
129
130 Acceptable values:
131 AVCaptureSessionPresetHigh // iPhone 3G: 400x304.
132 // iPhone 3GS: 640x480.
133 // iPhone 4/iPod touch 4G/iPad 2: rear 1280x720, front 640x480.
134 // iPhone 4S and later, iPad (3rd generation): rear 1920x1080, front 640x480.
135 // iPhone (4th generation), iPad Air, iPad Mini, iPad Mini (2nd generation): rear 1920x1080, front 1280x720
136 // iPhone 5, 5c, 5s: rear 1920x1080, front 1280x720.
137 AVCaptureSessionPresetMedium // iPhone 3G: 400x304
138 // iPhone 3GS/iPhone 4/iPod touch 4G/iPad 2: 480x360
139 AVCaptureSessionPresetLow // iPhone 3G/iPhone 3GS/iPhone 4/iPod touch 4G/iPad 2: 192x144.
140 AVCaptureSessionPreset640x480 // iPhone 3G: not supported. iPhone 3GS/iPhone 4/iPod touch 4G/iPad 2:640x480.
141 AVCaptureSessionPreset1280x720 // iPhone 3G/3GS: not supported. iPhone 4/iPod touch 4G/iPad 2:1280x720.
142 AVCaptureSessionPreset352x288 // iOS 5.0-only, iPhone 3GS and later.
143 AVCaptureSessionPreset1920x1080 // iOS 5.0-only, iPhone 4S and later, iPad (3rd generation) and later.
144 Default value is AVCaptureSessionPresetMedium.
145
146 N.B. 1920x1080 and 1280x720 are 16:9 aspect ratio.
147 640x480, 480x360, 192x144 are 4:3 aspect ratio.
148
149 */
150@property(nonatomic, assign) NSString *captureSessionPreset;
151
152/*
153 Set or get the video device position.
154
155 Attempts to change this property while (running == TRUE) will be ignored.
156
157 Acceptable values:
158 AVCaptureDevicePositionUnspecified
159 AVCaptureDevicePositionBack
160 AVCaptureDevicePositionFront
161 Default value is AVCaptureDevicePositionUnspecified.
162 */
163@property(nonatomic) AVCaptureDevicePosition captureDevicePosition;
164
165/*
166 Set or get the video device index.
167
168 Attempts to change this property while (running == TRUE) will be ignored.
169
170 Set or get the index of the capture device in use.
171 When captureDevicePosition==AVCaptureDevicePositionUnspecified, this is the index into the list of all available devices.
172 Otherwise, it is the index into the list of devices at that position.
173 Default value is 0.
174 */
175@property(nonatomic) int captureDeviceIndex;
176
177@property(nonatomic, readonly) NSString *captureDeviceIDManufacturer;
178@property(nonatomic, readonly) NSString *captureDeviceIDName;
179@property(nonatomic, readonly) NSString *captureDeviceIDModel;
180
181/*
182 Set or get the video device unique ID.
183
184 Attempts to change this property while (running == TRUE) will be ignored.
185
186 Set or get the unique ID of the capture device in use/to use.
187 If set, it will override captureDeviceIndex.
188 Default value set is nil.
189 */
190@property(nonatomic, copy) NSString *captureDeviceIDUID;
191
192/*
193 Set or get the video image pixel format.
194
195 Attempts to change this property while (running == TRUE) will be ignored.
196
197 Acceptable values:
198 kCVPixelFormatType_32BGRA (Default.)
199 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
200 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange (Recommended for iPhone 3GS, 4 and later.)
201 kCVPixelFormatType_422YpCbCr8 (Recommended for iPhone 3G)
202 */
203@property(nonatomic) OSType pixelFormat;
204
205// Starts capture from camera and waits until the first frame has
206// been received. Then sets 'running' and returns to caller.
207// Note that since this runs the runloop, it may deadlock if
208// a runloop task is invoked which waits on this this thread.
209// It is recommended to use -startAsync: instead.
210// In cases of error, 'running' will not be set on return.
211- (void) start;
212
213// Starts capture from camera, sets 'running' and returns to caller
214// immediately. Once the first frame has been received, invokes
215// 'completion' on main queue.
216// In cases of error, 'running' will not be set on return.
217- (void) startAsync:(CameraVideoStartAsyncCompletionBlock)completion;
218
219// Set once -start or -startAsync: has been called successfully.
220@property(nonatomic, readonly) BOOL running;
221@property(nonatomic) BOOL pause;
222
223// The delegate which gets call each time a new frame is available, and its userdata.
224// See discussion of CameraVideoTookPictureDelegate above.
225@property(nonatomic, assign) id <CameraVideoTookPictureDelegate> tookPictureDelegate;
226@property(nonatomic, assign) void *tookPictureDelegateUserData;
227
228// These values are valid only once the first frame has been received.
229// When invalid, they return 0.
230// When a multi-planar format is in use, these are the same as calling
231// -widthOfPlane:0, -heightOfPlane:0 or -bytesPerRowOfPlane:0.
232@property(nonatomic, readonly) size_t width;
233@property(nonatomic, readonly) size_t height;
234@property(nonatomic, readonly) size_t bytesPerRow;
235
236@property(nonatomic, readonly) size_t planeCount; // 0 for non-planar formats, or number of planes (will be 2 for kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange and kCVPixelFormatType_420YpCbCr8BiPlanarFullRange.
237- (size_t)widthOfPlane:(unsigned int)plane;
238- (size_t)heightOfPlane:(unsigned int)plane;
239- (size_t)bytesPerRowOfPlane:(unsigned int)plane;
240
241@property(nonatomic) BOOL flipV;
242@property(nonatomic) BOOL flipH;
243
244// Invoke this method to request the capture of a high resolution photo from the video
245// stream. If successful, the CameraVideoTookPictureDelegate delegate protocol
246// method -cameravideoTookPictureHires:userData:jpegData: will be invoked, so make
247// sure you've set the delegate before invocation.
248- (void) takePhoto;
249// You can also do the same thing, just from a notification with this method.
250- (void) takePhotoViaNotification:(NSNotification *)notification;
251
252// If set, when the next frame arrives it will be saved to the user's camera roll.
253// Only supported when using 32-bit RGB pixel formats, e.g. pixelFormat = kCVPixelFormatType_32BGRA.
254@property BOOL willSaveNextFrame;
255
256// Sets focus mode. When mode == AVCaptureFocusModeAutoFocus, then coords must be a
257// valid 2D coordinate in pixels, with 0,0 at the top-left of the frame where the frame
258// is considered upright when the device is held in landscape mode with the home button on the right.
259// Note that this DOES NOT give a visual indication of the focus point; that is up to the
260// caller to display, should he or she wish to.
261- (BOOL) setFocus:(AVCaptureFocusMode)mode atPixelCoords:(CGPoint)coords;
262
263// Get a pointer to the most recent frame.
264// If timestampOut is non-NULL, it will be filled with a timestamp using the same
265// timebase as CVGetCurrentHostTime().
266- (unsigned char *) frameTimestamp:(UInt64 *)timestampOut;
267
268// Get a pointer to the most recent only if it is newer than 'timestamp'.
269// Otherwise returns NULL.
270// If timestampOut is non-NULL, it will be filled with a timestamp using the same
271// timebase as CVGetCurrentHostTime().
272- (unsigned char *) frameTimestamp:(UInt64 *)timestampOut ifNewerThanTimestamp:(UInt64)timestamp;
273
274- (BOOL) framePlanes:(unsigned char **)bufDataPtrs count:(size_t)count timestamp:(UInt64 *)timestampOut;
275- (BOOL) framePlanes:(unsigned char **)bufDataPtrs count:(size_t)count timestamp:(UInt64 *)timestampOut ifNewerThanTimestamp:(UInt64)timestamp;
276@property(nonatomic, readonly) UInt64 timestampsPerSecond;
277
278// If set, callbacks on the delegate method -cameraVideoTookPicture:userData: will
279// be made on a serial queue not necessarily attached to the main thread.
280// Defaults to FALSE, i.e. callbacks are on the main thread. This allows OpenGL
281// operations, which should normally be on the main thread, to be called during the callback.
282// Changing this variable after calling -start will not take effect until -start is next called.
283@property(nonatomic) BOOL multithreaded;
284
285- (void) stop;
286- (void) dealloc;
287
288
289@end
CameraVideoiOSDeviceiPad3
NSString *const CameraVideoiOSDeviceiPad3
CameraVideoiOSDeviceiPodTouch4
NSString *const CameraVideoiOSDeviceiPodTouch4
CameraVideoiOSDeviceiPodTouch5
NSString *const CameraVideoiOSDeviceiPodTouch5
CameraVideoiOSDeviceiPhone7
NSString *const CameraVideoiOSDeviceiPhone7
CameraVideoiOSDeviceiPhone
NSString *const CameraVideoiOSDeviceiPhone
CameraVideoiOSDeviceiPadMini4
NSString *const CameraVideoiOSDeviceiPadMini4
CameraVideoiOSDeviceiPad2
NSString *const CameraVideoiOSDeviceiPad2
CameraVideoiOSDeviceiPadPro129
NSString *const CameraVideoiOSDeviceiPadPro129
CameraVideoiOSDeviceiPhone6S
NSString *const CameraVideoiOSDeviceiPhone6S
CameraVideoiOSDeviceiPadAir2
NSString *const CameraVideoiOSDeviceiPadAir2
CameraVideoiOSDeviceiPhoneSE
NSString *const CameraVideoiOSDeviceiPhoneSE
CameraVideoiOSDeviceiPhone3G
NSString *const CameraVideoiOSDeviceiPhone3G
CameraVideoiOSDeviceiPhoneX
NSString *const CameraVideoiOSDeviceiPhoneX
CameraVideoiOSDeviceiPodX
NSString *const CameraVideoiOSDeviceiPodX
CameraVideoiOSDeviceiPad4
NSString *const CameraVideoiOSDeviceiPad4
CameraVideoiOSDeviceiPhone3GS
NSString *const CameraVideoiOSDeviceiPhone3GS
CameraVideoiOSDeviceAppleTVX
NSString *const CameraVideoiOSDeviceAppleTVX
CameraVideoStartAsyncCompletionBlock
void(^ CameraVideoStartAsyncCompletionBlock)(void)
Definition: CameraVideo.h:81
CameraVideoiOSDeviceiPadX
NSString *const CameraVideoiOSDeviceiPadX
CameraVideoiOSDeviceiPadAir
NSString *const CameraVideoiOSDeviceiPadAir
CameraVideoiOSDeviceiPhone5c
NSString *const CameraVideoiOSDeviceiPhone5c
CameraVideoiOSDeviceiPhone5
NSString *const CameraVideoiOSDeviceiPhone5
CameraVideoiOSDeviceiPhone4S
NSString *const CameraVideoiOSDeviceiPhone4S
CameraVideoiOSDeviceiPadMini3
NSString *const CameraVideoiOSDeviceiPadMini3
CameraVideoiOSDeviceiPodTouch6
NSString *const CameraVideoiOSDeviceiPodTouch6
CameraVideoiOSDeviceiPhone6
NSString *const CameraVideoiOSDeviceiPhone6
CameraVideoiOSDeviceiPhone7Plus
NSString *const CameraVideoiOSDeviceiPhone7Plus
CameraVideoiOSDeviceiPhone6SPlus
NSString *const CameraVideoiOSDeviceiPhone6SPlus
CameraVideoiOSDeviceiPhone5s
NSString *const CameraVideoiOSDeviceiPhone5s
CameraVideoiOSDeviceiPadPro97
NSString *const CameraVideoiOSDeviceiPadPro97
CameraVideoiOSDeviceiPadMini
NSString *const CameraVideoiOSDeviceiPadMini
CameraVideoiOSDeviceiPhone6Plus
NSString *const CameraVideoiOSDeviceiPhone6Plus
CameraVideoiOSDeviceiPadMini2
NSString *const CameraVideoiOSDeviceiPadMini2
CameraVideoiOSDeviceiPhone4
NSString *const CameraVideoiOSDeviceiPhone4
CameraVideo
Definition: CameraVideo.h:119
CameraVideo::captureSessionPreset
NSString * captureSessionPreset
Definition: CameraVideo.h:150
CameraVideo::running
BOOL running
Definition: CameraVideo.h:220
CameraVideo::bytesPerRow
size_t bytesPerRow
Definition: CameraVideo.h:234
CameraVideo::willSaveNextFrame
BOOL willSaveNextFrame
Definition: CameraVideo.h:254
CameraVideo::multithreaded
BOOL multithreaded
Definition: CameraVideo.h:283
-[CameraVideo dealloc]
void dealloc()
CameraVideo::flipH
BOOL flipH
Definition: CameraVideo.h:242
CameraVideo::planeCount
size_t planeCount
Definition: CameraVideo.h:236
CameraVideo::captureDeviceIndex
int captureDeviceIndex
Definition: CameraVideo.h:175
CameraVideo::timestampsPerSecond
UInt64 timestampsPerSecond
Definition: CameraVideo.h:276
-[CameraVideo init]
id init()
CameraVideo::tookPictureDelegateUserData
void * tookPictureDelegateUserData
Definition: CameraVideo.h:226
-[CameraVideo start]
void start()
CameraVideo::iOSDevice
NSString * iOSDevice
Definition: CameraVideo.h:123
CameraVideo::captureDeviceIDName
NSString * captureDeviceIDName
Definition: CameraVideo.h:178
CameraVideo::height
size_t height
Definition: CameraVideo.h:233
CameraVideo::flipV
BOOL flipV
Definition: CameraVideo.h:241
CameraVideo::captureDeviceIDUID
NSString * captureDeviceIDUID
Definition: CameraVideo.h:190
CameraVideo::pixelFormat
OSType pixelFormat
Definition: CameraVideo.h:203
CameraVideo::captureDeviceIDManufacturer
NSString * captureDeviceIDManufacturer
Definition: CameraVideo.h:177
CameraVideo::width
size_t width
Definition: CameraVideo.h:232
CameraVideo::pause
BOOL pause
Definition: CameraVideo.h:221
CameraVideo::captureDevicePosition
AVCaptureDevicePosition captureDevicePosition
Definition: CameraVideo.h:163
-[CameraVideo stop]
void stop()
-[CameraVideo takePhoto]
void takePhoto()
CameraVideo::tookPictureDelegate
id< CameraVideoTookPictureDelegate > tookPictureDelegate
Definition: CameraVideo.h:225
CameraVideo::captureDeviceIDModel
NSString * captureDeviceIDModel
Definition: CameraVideo.h:179