38#import <AVFoundation/AVFoundation.h>
39#include <AppKit/NSApplication.h>
41#include <condition_variable>
46#include <unordered_map>
54#define MOD_NAME "[AVFoundation] "
56#define NSAppKitVersionNumber10_8 1187
57#define NSAppKitVersionNumber10_9 1265
59#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 140000
60#define DESK_VIEW_IF_DEFINED ,AVCaptureDeviceTypeDeskViewCamera
62#define DESK_VIEW_IF_DEFINED
65#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000
66#define AVCaptureDeviceTypeExternal AVCaptureDeviceTypeExternalUnknown
73 {
"high", AVCaptureSessionPresetHigh },
74 {
"medium", AVCaptureSessionPresetMedium },
75 {
"low", AVCaptureSessionPresetLow },
76 {
"VGA", AVCaptureSessionPreset640x480 },
77 {
"HD", AVCaptureSessionPreset1280x720 },
80std::unordered_map<CMPixelFormatType, std::tuple<codec_t, int, int, int>>
av_to_uv = {
81 {kCVPixelFormatType_32ARGB, {
RGBA, 8, 16, 24}},
82 {kCVPixelFormatType_32BGRA, {
RGBA, 16, 8, 0}},
83 {kCVPixelFormatType_24RGB, {
RGB, 0, 8, 16}},
89 {kCVPixelFormatType_422YpCbCr8, {
UYVY, 0, 0, 0}},
90 {kCVPixelFormatType_422YpCbCr8_yuvs, {
YUYV, 0, 0, 0}},
94 {kCVPixelFormatType_422YpCbCr10, {
v210, 0, 0, 0}},
104using std::chrono::milliseconds;
113 chrono::steady_clock::time_point
m_t0;
118- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
119fromConnection:(AVCaptureConnection *)connection;
132#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500
133 AVCaptureDeviceDiscoverySession *discoverySession =
134 [AVCaptureDeviceDiscoverySession
135 discoverySessionWithDeviceTypes:@[
136 AVCaptureDeviceTypeBuiltInWideAngleCamera,
137 AVCaptureDeviceTypeExternal DESK_VIEW_IF_DEFINED
139 mediaType:AVMediaTypeVideo
141 AVCaptureDevicePositionUnspecified];
chrono::steady_clock::time_point m_t0
condition_variable m_frame_ready
queue< struct video_frame * > m_queue
AVCaptureSession * m_session
AVCaptureDevice * m_device
std::unordered_map< CMPixelFormatType, std::tuple< codec_t, int, int, int > > av_to_uv
constexpr int MAX_CAPTURE_QUEUE_SIZE
std::unordered_map< std::string, NSString * > preset_to_av
Struct video_frame represents a video frame and contains video description.
@ YUYV
YCbCr 422 8-bit - Y0 Cb Y1 Cr.
@ RGB
RGB 8-bit (packed into 24-bit word)
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
@ RGBA
RGBA 8-bit, big-endian.
@ v210
YCbCr 422 10-bit - xVY0U|xY2UY1|xUY3V|xY5VY4, little-endian (2 bit padding /'x'/),...
This is an umbrella header for video functions.