reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofAVFoundationGrabber.h
Go to the documentation of this file.
1/*
2 * AVFoundationVideoGrabber.h
3 */
4
5#pragma once
6
7#include "ofConstants.h"
8
9#ifdef OF_VIDEO_CAPTURE_AVF
10
11//------
12#include "ofVideoBaseTypes.h"
13#include "ofTexture.h"
14#include "ofThread.h"
15#include "ofPixels.h"
16#include <mutex>
17
18#ifdef __OBJC__
19
20#import <Foundation/Foundation.h>
21#import <AVFoundation/AVFoundation.h>
22#import <Accelerate/Accelerate.h>
23#import <CoreMedia/CoreMedia.h>
24#import <CoreVideo/CoreVideo.h>
25
26class ofAVFoundationGrabber;
27
28@interface OSXVideoGrabber : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate> {
29
30 @public
31 CGImageRef currentFrame;
32
33 int width;
34 int height;
35
36 BOOL bInitCalled;
37 int deviceID;
38
39 AVCaptureDeviceInput *captureInput;
40 AVCaptureVideoDataOutput *captureOutput;
41 AVCaptureDevice *device;
42 AVCaptureSession *captureSession;
43
44 ofAVFoundationGrabber * grabberPtr;
45}
46
47-(BOOL)initCapture:(int)framerate capWidth:(int)w capHeight:(int)h;
48-(void)startCapture;
49-(void)stopCapture;
50-(void)lockExposureAndFocus;
51-(std::vector <std::string>)listDevices;
52-(void)setDevice:(int)_device;
53-(void)eraseGrabberPtr;
54
55-(CGImageRef)getCurrentFrame;
56
57@end
58
59//------
60
61#endif
62
63
64class ofAVFoundationGrabber : virtual public ofBaseVideoGrabber{
65
66 public:
67 ofAVFoundationGrabber();
68 ~ofAVFoundationGrabber();
69
70 void setDeviceID(int deviceID);
71 void setDesiredFrameRate(int capRate);
72 bool setPixelFormat(ofPixelFormat PixelFormat);
73
74 bool setup(int w, int h);
75 void update();
76 bool isFrameNew() const;
77 void close();
78
80 const ofPixels& getPixels() const;
81
82 float getWidth() const{
83 return width;
84 }
85 float getHeight() const{
86 return height;
87 }
88
89 bool isInitialized() const;
90
91 void updatePixelsCB();
92 std::vector <ofVideoDevice> listDevices() const;
94
95 protected:
96 bool newFrame = false;
97 bool bHavePixelsChanged = false;
98 void clear();
99 int width, height;
100
101 int device = 0;
102 bool bIsInit = false;
103
104 int fps = -1;
105 ofTexture tex;
106 ofPixels pixels;
107
108 #ifdef __OBJC__
109 OSXVideoGrabber * grabber;
110 #else
111 void * grabber;
112 #endif
113
114 public:
115 ofPixelFormat pixelFormat;
116 ofPixels pixelsTmp;
117 bool bLock = false;
118 std::mutex capMutex;
119
120};
121
122#endif
virtual ofPixels_< unsigned char > & getPixels()=0
Get a reference to the underlying ofPixels.
virtual void update()=0
Update the object's state.
A base class representing a video device such as a camera.
Definition ofVideoBaseTypes.h:110
virtual void setDesiredFrameRate(int framerate)
Set the video grabber's desired frame rate.
Definition ofBaseTypes.cpp:23
virtual bool setup(int w, int h)=0
Set up the grabber with the requested width and height.
virtual void setDeviceID(int deviceID)
Set the video grabber's device ID.
Definition ofBaseTypes.cpp:18
virtual float getHeight() const =0
Get the video grabber's height.
virtual float getWidth() const =0
Get the video grabber's width.
virtual std::vector< ofVideoDevice > listDevices() const =0
Get a list of available video grabber devices.
virtual ofPixelFormat getPixelFormat() const =0
virtual bool setPixelFormat(ofPixelFormat pixelFormat)=0
Set the requested ofPixelFormat.
virtual bool isInitialized() const =0
Determine if the video source is initialized.
virtual void close()=0
Close the video source.
virtual bool isFrameNew() const =0
A wrapper class for an OpenGL texture.
Definition ofTexture.h:253
Definition ofPixels.h:1522
map< string, int > device
Definition ofAppEGLWindow.cpp:36
unsigned int height
Definition ofAppEGLWindow.cpp:125
unsigned int width
Definition ofAppEGLWindow.cpp:124
ofPixelFormat
Used to represent the available pixel formats.
Definition ofPixels.h:68