-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CameraAVFoundation
: Move things around reducing boilerplate for upc…
…oming changes (#8643)
- Loading branch information
Showing
4 changed files
with
272 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,131 @@ | ||
typedef void *camera_t; | ||
|
||
camera_t avf_camera_init(int index, int width, int height); | ||
void avf_camera_deinit(camera_t camera); | ||
bool avf_camera_update(camera_t camera); | ||
void avf_camera_start(camera_t camera); | ||
void avf_camera_stop(camera_t camera); | ||
void avf_camera_get_image(camera_t camera, int *width, int *height, int *rowsize, char **data); | ||
bool avf_camera_attempt_framerate_selection(camera_t camera, int fps); | ||
bool avf_camera_attempt_capture_preset(camera_t camera, char* preset); | ||
bool avf_camera_attempt_start_metadata_analysis(camera_t camera); | ||
void avf_camera_get_metadata(camera_t camera, char **metatype, char **data); | ||
bool avf_camera_have_new_metadata(camera_t camera); | ||
void avf_camera_set_video_orientation(camera_t camera, int orientation); | ||
int avf_camera_get_device_orientation(); | ||
void avf_camera_change_input(camera_t camera, int _cameraNum); | ||
void avf_camera_zoom_level(camera_t camera, float zoomLevel); | ||
char *avf_camera_documents_directory(); | ||
void avf_camera_save_pixels(camera_t camera, unsigned char *pixels, int width, int height, char *path, float quality); | ||
#import <AVFoundation/AVFoundation.h> | ||
#import <Foundation/NSException.h> | ||
|
||
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR | ||
#import <UIKit/UIKit.h> | ||
#endif | ||
|
||
|
||
#ifdef WITH_CAMERA_CAPS | ||
typedef enum { | ||
CAM_FRAME_WIDTH, | ||
CAM_FRAME_HEIGHT, | ||
CAM_IOS_DEVICE_FOCUS, | ||
CAM_IOS_DEVICE_EXPOSURE, | ||
CAM_IOS_DEVICE_FLASH, | ||
CAM_IOS_DEVICE_WHITEBALANCE, | ||
CAM_IOS_DEVICE_TORCH | ||
} caps_t; | ||
#endif | ||
|
||
class CameraFrame { | ||
public: | ||
CameraFrame(int width, int height); | ||
~CameraFrame(); | ||
char *data; | ||
unsigned int datasize; | ||
unsigned int rowsize; | ||
int width; | ||
int height; | ||
}; | ||
|
||
class CameraMetadata { | ||
public: | ||
CameraMetadata(); | ||
~CameraMetadata(); | ||
char *type; | ||
char *data; | ||
}; | ||
|
||
@interface KivyCaptureDelegate : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate> | ||
{ | ||
int newFrame; | ||
CVImageBufferRef mCurrentImageBuffer; | ||
CameraFrame* image; | ||
} | ||
|
||
- (void)captureOutput:(AVCaptureOutput *)captureOutput | ||
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer | ||
fromConnection:(AVCaptureConnection *)connection; | ||
|
||
|
||
- (int)updateImage; | ||
- (CameraFrame*)getOutput; | ||
|
||
@end | ||
|
||
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR | ||
|
||
@interface PhotoAppDelegate : NSObject {} | ||
- (void) thisImage:(UIImage *)image photoAppCallback:(NSError *)error usingContextInfo:(void*)ctxInfo; | ||
@end | ||
|
||
@implementation PhotoAppDelegate | ||
- (void) thisImage:(UIImage *)image photoAppCallback:(NSError *)error usingContextInfo:(void*)ctxInfo { | ||
free(ctxInfo); | ||
} | ||
@end | ||
|
||
/* AVCaptureMetadataOutput is not available on MacOS */ | ||
@interface MetadataDelegate : NSObject <AVCaptureMetadataOutputObjectsDelegate> | ||
{ | ||
CameraMetadata* metadata; | ||
int newMetadata; | ||
} | ||
- (void)captureOutput:(AVCaptureOutput *)output | ||
didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects | ||
fromConnection:(AVCaptureConnection *)connection; | ||
- (CameraMetadata*)getOutput; | ||
- (bool)haveNewMetadata; | ||
- (void)setNewMetadata:(bool)newMetadata; | ||
@end | ||
#endif | ||
|
||
class Camera { | ||
|
||
public: | ||
Camera(int cameraNum, int width, int height); | ||
~Camera(); | ||
static int getDeviceOrientation(); | ||
static char* getDocumentsDirectory(); | ||
bool grabFrame(double timeOut); | ||
CameraFrame* retrieveFrame(); | ||
CameraMetadata* retrieveMetadata(); | ||
int startCaptureDevice(); | ||
void stopCaptureDevice(); | ||
bool attemptFrameRateSelection(int desiredFrameRate); | ||
bool attemptCapturePreset(char* preset); | ||
bool attemptStartMetadataAnalysis(); | ||
bool haveNewMetadata(); | ||
void setVideoOrientation(int orientation); | ||
void changeCameraInput(int _cameraNum); | ||
void zoomLevel(float zoomLevel); | ||
void savePixelsToFile(unsigned char *pixels, int width, int height, char *path, float quality); | ||
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR | ||
PhotoAppDelegate *photoapp; | ||
#endif | ||
#ifdef WITH_CAMERA_CAPS | ||
double getProperty(int property_id); | ||
bool setProperty(int property_id, double value); | ||
void setWidthHeight(); | ||
#endif | ||
|
||
private: | ||
AVCaptureSession *mCaptureSession; | ||
AVCaptureDeviceInput *mCaptureDeviceInput; | ||
AVCaptureVideoDataOutput *mCaptureDecompressedVideoOutput; | ||
AVCaptureDevice *mCaptureDevice; | ||
KivyCaptureDelegate *capture; | ||
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR | ||
/* AVCaptureMetadataOutput is not available on MacOS */ | ||
AVCaptureMetadataOutput *mMetadataOutput; | ||
MetadataDelegate *metadata; | ||
#endif | ||
|
||
int cameraNum; | ||
int width; | ||
int height; | ||
int settingWidth; | ||
int settingHeight; | ||
int started; | ||
}; |
Oops, something went wrong.