Skip to content

Commit 6ba494c

Browse files
committed
- changes for mac camera process
1 parent 93b91a8 commit 6ba494c

17 files changed

+275
-40
lines changed

include/cinder/Capture.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class CI_API Capture {
9696
gl::Texture2dRef getTexture() const;
9797
#endif
9898

99+
void requirePermission( std::function<void(bool)> cb );
100+
99101
//! Returns the associated Device for this instace of Capture
100102
const Capture::DeviceRef getDevice() const;
101103

@@ -160,4 +162,4 @@ class CI_API CaptureExcInitFail : public CaptureExc {
160162
class CI_API CaptureExcInvalidChannelOrder : public CaptureExc {
161163
};
162164

163-
} //namespace cinder
165+
} //namespace cinder

include/cinder/CaptureImplAvFoundation.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class CaptureImplAvFoundationDevice : public Capture::Device {
6161
int32_t mExposedFrameBytesPerRow;
6262
int32_t mExposedFrameHeight;
6363
int32_t mExposedFrameWidth;
64+
65+
void (^_completionHandler)(bool permitted);
6466
}
6567

6668
+ (const std::vector<cinder::Capture::DeviceRef>&)getDevices:(BOOL)forceRefresh;
@@ -78,5 +80,6 @@ class CaptureImplAvFoundationDevice : public Capture::Device {
7880
- (int32_t)getCurrentFrameBytesPerRow;
7981
- (int32_t)getCurrentFrameWidth;
8082
- (int32_t)getCurrentFrameHeight;
83+
- (void)requirePermission:(void(^)(bool))handler;
8184

82-
@end
85+
@end

include/cinder/CinderImGui.h

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#endif
2929
#if ! defined( CINDER_IMGUI_EXTERNAL )
3030
#include "imgui/imgui.h"
31+
#include "imgui/imgui_stdlib.h"
3132
#else
3233
#include "imgui.h"
3334
#endif
@@ -137,7 +138,7 @@ namespace ImGui {
137138
CI_API void Image( const ci::gl::Texture2dRef& texture, const ci::vec2& size, const ci::vec2& uv0 = ci::vec2( 0, 0 ), const ci::vec2& uv1 = ci::vec2( 1, 1 ), const ci::vec4& tint_col = ci::vec4( 1, 1, 1, 1 ), const ci::vec4& border_col = ci::vec4( 0, 0, 0, 0 ) );
138139

139140
struct CI_API ScopedWindow : public ci::Noncopyable {
140-
ScopedWindow( const char* label );
141+
ScopedWindow( const char* label, bool fixed = false );
141142
~ScopedWindow();
142143
};
143144

include/cinder/Shape2d.h

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class CI_API Shape2d {
8787
const vec2& getCurrentPoint() const { return mContours.back().getCurrentPoint(); }
8888

8989
//! Appends the contours of \a shape to this Shape2d
90-
void append( const Shape2d &shape );
91-
void appendContour( const Path2d &contour ) { mContours.push_back( contour ); }
92-
void removeContour( size_t i ) { mContours.erase( mContours.begin() + i ); }
90+
void append( const Shape2d &shape );
91+
void appendContour( const Path2d &contour ) { mContours.push_back( contour ); }
92+
void removeContour( size_t i ) { mContours.erase( mContours.begin() + i ); }
9393

9494
//! Translates the Shape2d by \a offset
9595
void translate( const vec2 &offset );

include/cinder/Surface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ class CI_API SurfaceT {
254254

255255
//! Copies the Area \a srcArea of the Surface \a srcSurface to \a this Surface. The destination Area is \a srcArea offset by \a relativeOffset.
256256
void copyFrom( const SurfaceT<T> &srcSurface, const Area &srcArea, const ivec2 &relativeOffset = ivec2() );
257+
void copyFromFlipped(const SurfaceT<T>& srcSurface, const Area& srcArea, const ivec2& relativeOffset = ivec2());
257258

258259
//! Returns an averaged color for the Area defined by \a area
259260
ColorT<T> areaAverage( const Area &area ) const;
@@ -265,6 +266,11 @@ class CI_API SurfaceT {
265266
void copyRawRgbFullAlpha( const SurfaceT<T> &srcSurface, const Area &srcArea, const ivec2 &absoluteOffset );
266267
void copyRawRgb( const SurfaceT<T> &srcSurface, const Area &srcArea, const ivec2 &absoluteOffset );
267268

269+
void copyRawSameChannelOrderFlipped(const SurfaceT<T>& srcSurface, const Area& srcArea, const ivec2& absoluteOffset);
270+
void copyRawRgbaFlipped(const SurfaceT<T>& srcSurface, const Area& srcArea, const ivec2& absoluteOffset);
271+
void copyRawRgbFullAlphaFlipped(const SurfaceT<T>& srcSurface, const Area& srcArea, const ivec2& absoluteOffset);
272+
void copyRawRgbFlipped(const SurfaceT<T>& srcSurface, const Area& srcArea, const ivec2& absoluteOffset);
273+
268274
void initChannels();
269275

270276
int32_t mWidth, mHeight;

include/cinder/qtime/AvfWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,4 @@ class MovieWriterExcFrameEncode : public MovieWriterExc {
170170
class MovieWriterExcAlreadyFinished : public MovieWriterExc {
171171
};
172172

173-
} } // namespace cinder::qtime
173+
} } // namespace cinder::qtime

include/cinder/qtime/QuickTimeImplAvf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,4 @@ class AvfErrorLoadingExc : public AvfExc {
323323
class AvfTextureErrorExc : public AvfExc {
324324
};
325325

326-
} } // namespace cinder::qtime
326+
} } // namespace cinder::qtime

src/cinder/BSpline.cpp

100644100755
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ void BSpline<D,T>::createControl( const VecT *akCtrlPoint )
477477
}
478478

479479
template<int D,typename T>
480-
void BSpline<D,T>::setControlPoint( int i, const VecT &rkCtrl )
481-
{
480+
void BSpline<D,T>::setControlPoint( int i, const VecT &rkCtrl ) {
482481
assert( i >= 0 && i < mNumCtrlPoints );
483482

484483
// set the control point

src/cinder/Capture.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,12 @@ const Capture::DeviceRef Capture::getDevice() const {
165165
#endif
166166
}
167167

168+
void Capture::requirePermission( std::function<void(bool)> cb ){
169+
#if defined( CINDER_COCOA )
170+
[mImpl requirePermission:^(bool permission){
171+
cb(permission);
172+
}];
173+
#endif
174+
}
175+
168176
} //namespace cinder

src/cinder/CaptureImplAvFoundation.mm

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ - (bool)prepareStartCapture
129129
AVCaptureDevice *device = nil;
130130
if( ! mDeviceUniqueId ) {
131131
device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
132-
}
133-
else {
132+
} else {
134133
device = [AVCaptureDevice deviceWithUniqueID:mDeviceUniqueId];
135134
}
136135

@@ -153,8 +152,19 @@ - (bool)prepareStartCapture
153152
[mSession beginConfiguration];
154153
if( cinder::ivec2( mWidth, mHeight ) == cinder::ivec2( 640, 480 ) )
155154
mSession.sessionPreset = AVCaptureSessionPreset640x480;
156-
else if( cinder::ivec2( mWidth, mHeight ) == cinder::ivec2( 1280, 720 ) )
155+
/*else if( cinder::ivec2( mWidth, mHeight ) == cinder::ivec2( 960, 540 ) )
156+
mSession.sessionPreset = AVCaptureSessionPreset960x540;
157+
*/else if( cinder::ivec2( mWidth, mHeight ) == cinder::ivec2( 1280, 720 ) )
157158
mSession.sessionPreset = AVCaptureSessionPreset1280x720;
159+
else if( cinder::ivec2( mWidth, mHeight ) == cinder::ivec2( 1920, 1080 ) )
160+
if (@available(macOS 10.15, *)) {
161+
mSession.sessionPreset = AVCaptureSessionPreset1920x1080;
162+
} else {
163+
// Fallback on earlier versions
164+
mSession.sessionPreset = AVCaptureSessionPreset1280x720;
165+
}
166+
else if( glm::max(mWidth, mHeight) > 900 )
167+
mSession.sessionPreset = AVCaptureSessionPresetHigh;
158168
else
159169
mSession.sessionPreset = AVCaptureSessionPresetMedium;
160170
[mSession commitConfiguration];
@@ -199,23 +209,54 @@ - (void)startCapture
199209
if( mIsCapturing )
200210
return;
201211

202-
@synchronized( self ) {
212+
dispatch_async(dispatch_get_global_queue( QOS_CLASS_DEFAULT, 0), ^(void){
213+
if( [self prepareStartCapture] ) {
214+
//@synchronized( self ) {
215+
mWorkingPixelBuffer = 0;
216+
mHasNewFrame = false;
217+
218+
[mSession startRunning];
219+
mIsCapturing = true;
220+
//}
221+
}
222+
});
223+
224+
/*@synchronized( self ) {
203225
if( [self prepareStartCapture] ) {
204226
mWorkingPixelBuffer = 0;
205227
mHasNewFrame = false;
206228
207229
mIsCapturing = true;
208230
[mSession startRunning];
209231
}
210-
}
232+
}*/
211233
}
212234

213235
- (void)stopCapture
214236
{
215237
if( ! mIsCapturing )
216238
return;
217239

218-
@synchronized( self ) {
240+
dispatch_async(dispatch_get_global_queue( QOS_CLASS_DEFAULT, 0), ^(void){
241+
@synchronized( self ) {
242+
[mSession stopRunning];
243+
244+
if( mWorkingPixelBuffer ) {
245+
::CVBufferRelease( mWorkingPixelBuffer );
246+
mWorkingPixelBuffer = nullptr;
247+
}
248+
249+
[mSession release];
250+
mSession = nil;
251+
252+
mIsCapturing = false;
253+
mHasNewFrame = false;
254+
255+
mCurrentFrame.reset();
256+
}
257+
});
258+
259+
/*@synchronized( self ) {
219260
[mSession stopRunning];
220261
221262
if( mWorkingPixelBuffer ) {
@@ -230,14 +271,45 @@ - (void)stopCapture
230271
mHasNewFrame = false;
231272
232273
mCurrentFrame.reset();
233-
}
274+
}*/
234275
}
235276

236277
- (bool)isCapturing
237278
{
238279
return mIsCapturing;
239280
}
240281

282+
- (void)requirePermission:(void(^)(bool))handler
283+
{
284+
#if defined( CINDER_COCOA_TOUCH )
285+
#else
286+
if (@available(macOS 10.14, *))
287+
#endif
288+
{
289+
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
290+
_completionHandler = [handler copy];
291+
292+
if(status == AVAuthorizationStatusNotDetermined){ // not determined
293+
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
294+
_completionHandler(granted);
295+
[_completionHandler release];
296+
_completionHandler = nil;
297+
}];
298+
} else {
299+
if(status == AVAuthorizationStatusAuthorized) { // authorized
300+
_completionHandler(true);
301+
} else if(status == AVAuthorizationStatusDenied){ // denied
302+
_completionHandler(false);
303+
} else if(status == AVAuthorizationStatusRestricted){ // restricted
304+
_completionHandler(false);
305+
}
306+
307+
[_completionHandler release];
308+
_completionHandler = nil;
309+
}
310+
}
311+
}
312+
241313
// Called initially when the camera is instantiated and then again (hypothetically) if the resolution ever changes
242314
- (void)avCaptureInputPortFormatDescriptionDidChange:(NSNotification *)notification
243315
{
@@ -338,4 +410,4 @@ - (int32_t)getCurrentFrameHeight
338410
return mExposedFrameHeight;
339411
}
340412

341-
@end
413+
@end

0 commit comments

Comments
 (0)