From e68102e04666338b7de9d5bc50fc42da197d1c55 Mon Sep 17 00:00:00 2001 From: "fischman@webrtc.org" Date: Tue, 25 Mar 2014 05:15:44 +0000 Subject: [PATCH] iOS VideoEngine: move video_{capture,render} to ARC. Replaces ye olde timey explicit release with teh hotness of automatic reference counting. This is the webrtc/ half; the talk/ half is in https://webrtc-codereview.appspot.com/10499005/ BUG=3054,3055 R=noahric@google.com Review URL: https://webrtc-codereview.appspot.com/10539005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5770 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../video_capture/ios/device_info_ios.mm | 4 ++ .../video_capture/ios/device_info_ios_objc.mm | 4 ++ .../ios/rtc_video_capture_ios_objc.h | 3 +- .../ios/rtc_video_capture_ios_objc.mm | 12 +++-- .../video_capture/ios/video_capture_ios.mm | 5 +- .../modules/video_capture/video_capture.gypi | 3 ++ .../modules/video_render/ios/open_gles20.mm | 4 ++ .../ios/video_render_ios_channel.mm | 4 ++ .../ios/video_render_ios_gles20.mm | 6 ++- .../video_render/ios/video_render_ios_impl.h | 2 +- .../video_render/ios/video_render_ios_impl.mm | 13 +++--- .../video_render/ios/video_render_ios_view.h | 10 +--- .../video_render/ios/video_render_ios_view.mm | 46 ++++++++++--------- webrtc/modules/video_render/video_render.gypi | 3 ++ 14 files changed, 74 insertions(+), 45 deletions(-) diff --git a/webrtc/modules/video_capture/ios/device_info_ios.mm b/webrtc/modules/video_capture/ios/device_info_ios.mm index c51a53a337..dea9fc34a4 100644 --- a/webrtc/modules/video_capture/ios/device_info_ios.mm +++ b/webrtc/modules/video_capture/ios/device_info_ios.mm @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + #include "webrtc/modules/video_capture/ios/device_info_ios.h" #include "webrtc/modules/video_capture/ios/device_info_ios_objc.h" #include "webrtc/modules/video_capture/video_capture_impl.h" diff --git a/webrtc/modules/video_capture/ios/device_info_ios_objc.mm b/webrtc/modules/video_capture/ios/device_info_ios_objc.mm index 2d11a2043f..d06d3361f4 100644 --- a/webrtc/modules/video_capture/ios/device_info_ios_objc.mm +++ b/webrtc/modules/video_capture/ios/device_info_ios_objc.mm @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + #import #import "webrtc/modules/video_capture/ios/device_info_ios_objc.h" diff --git a/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h b/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h index e6fa257ec2..5164990b06 100644 --- a/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h +++ b/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h @@ -11,6 +11,7 @@ #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_OBJC_H_ #define WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_OBJC_H_ +#import #import #include "webrtc/modules/video_capture/ios/video_capture_ios.h" @@ -20,7 +21,7 @@ // This notification must be posted in order for the capturer to reflect the // orientation change in video w.r.t. the application orientation. @interface RTCVideoCaptureIosObjC - : UIViewController { + : NSObject { @private webrtc::videocapturemodule::VideoCaptureIos* _owner; webrtc::VideoCaptureCapability _capability; diff --git a/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.mm b/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.mm index 1af1666c9d..39fac42000 100644 --- a/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.mm +++ b/webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.mm @@ -8,6 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + +#import + #import "webrtc/modules/video_capture/ios/device_info_ios_objc.h" #import "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h" @@ -81,7 +87,6 @@ using namespace webrtc::videocapturemodule; - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; } - (BOOL)setCaptureDeviceByUniqueId:(NSString*)uniqueId { @@ -174,8 +179,6 @@ using namespace webrtc::videocapturemodule; [_captureSession startRunning]; - [captureQuality release]; - return YES; } @@ -199,7 +202,8 @@ using namespace webrtc::videocapturemodule; } } -- (void)onVideoError { +- (void)onVideoError:(NSNotification*)notification { + NSLog(@"onVideoError: %@", notification); // TODO(sjlee): make the specific error handling with this notification. WEBRTC_TRACE(kTraceError, kTraceVideoCapture, diff --git a/webrtc/modules/video_capture/ios/video_capture_ios.mm b/webrtc/modules/video_capture/ios/video_capture_ios.mm index 5c4680d8ef..c605025bd2 100644 --- a/webrtc/modules/video_capture/ios/video_capture_ios.mm +++ b/webrtc/modules/video_capture/ios/video_capture_ios.mm @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + #include "webrtc/modules/video_capture/ios/device_info_ios_objc.h" #include "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h" #include "webrtc/system_wrappers/interface/ref_count.h" @@ -86,7 +90,6 @@ int32_t VideoCaptureIos::StopCapture() { } is_capturing_ = false; - return 0; } diff --git a/webrtc/modules/video_capture/video_capture.gypi b/webrtc/modules/video_capture/video_capture.gypi index 237a7560f1..970b05846c 100644 --- a/webrtc/modules/video_capture/video_capture.gypi +++ b/webrtc/modules/video_capture/video_capture.gypi @@ -113,6 +113,9 @@ 'ios/video_capture_ios.h', 'ios/video_capture_ios.mm', ], + 'xcode_settings': { + 'CLANG_ENABLE_OBJC_ARC': 'YES', + }, 'all_dependent_settings': { 'xcode_settings': { 'OTHER_LDFLAGS': [ diff --git a/webrtc/modules/video_render/ios/open_gles20.mm b/webrtc/modules/video_render/ios/open_gles20.mm index 0707a714b9..9dfa69d1b7 100644 --- a/webrtc/modules/video_render/ios/open_gles20.mm +++ b/webrtc/modules/video_render/ios/open_gles20.mm @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + // This files is mostly copied from // webrtc/modules/video_render/android/video_render_opengles20.h diff --git a/webrtc/modules/video_render/ios/video_render_ios_channel.mm b/webrtc/modules/video_render/ios/video_render_ios_channel.mm index 2a3ca180f7..02814b2223 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_channel.mm +++ b/webrtc/modules/video_render/ios/video_render_ios_channel.mm @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + #include "webrtc/modules/video_render/ios/video_render_ios_channel.h" using namespace webrtc; diff --git a/webrtc/modules/video_render/ios/video_render_ios_gles20.mm b/webrtc/modules/video_render/ios/video_render_ios_gles20.mm index 7bc46bfdad..bbada099ed 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_gles20.mm +++ b/webrtc/modules/video_render/ios/video_render_ios_gles20.mm @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + #include "webrtc/modules/video_render/ios/video_render_ios_gles20.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/event_wrapper.h" @@ -246,7 +250,7 @@ int VideoRenderIosGles20::GetWindowRect(Rect& rect) { int VideoRenderIosGles20::ChangeWindow(void* new_window) { CriticalSectionScoped cs(gles_crit_sec_.get()); - view_ = (VideoRenderIosView*)new_window; + view_ = (__bridge VideoRenderIosView*)new_window; return 0; } diff --git a/webrtc/modules/video_render/ios/video_render_ios_impl.h b/webrtc/modules/video_render/ios/video_render_ios_impl.h index 138a524a0d..e38ed7ae4b 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_impl.h +++ b/webrtc/modules/video_render/ios/video_render_ios_impl.h @@ -99,7 +99,7 @@ class VideoRenderIosImpl : IVideoRender { bool full_screen_; CriticalSectionWrapper* crit_sec_; - VideoRenderIosGles20* ptr_ios_render_; + webrtc::scoped_ptr ptr_ios_render_; }; } // namespace webrtc #endif // WEBRTC_MODULES_VIDEO_RENDER_IOS_VIDEO_RENDER_IOS_IMPL_H_ diff --git a/webrtc/modules/video_render/ios/video_render_ios_impl.mm b/webrtc/modules/video_render/ios/video_render_ios_impl.mm index 089b1e7698..9b8e1d6243 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_impl.mm +++ b/webrtc/modules/video_render/ios/video_render_ios_impl.mm @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + #include "webrtc/modules/video_render/ios/video_render_ios_impl.h" #include "webrtc/modules/video_render/ios/video_render_ios_gles20.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" @@ -33,18 +37,13 @@ VideoRenderIosImpl::VideoRenderIosImpl(const int32_t id, VideoRenderIosImpl::~VideoRenderIosImpl() { delete crit_sec_; - - if (ptr_ios_render_) { - delete ptr_ios_render_; - ptr_ios_render_ = NULL; - } } int32_t VideoRenderIosImpl::Init() { CriticalSectionScoped cs(crit_sec_); - ptr_ios_render_ = new VideoRenderIosGles20( - (VideoRenderIosView*)ptr_window_, full_screen_, id_); + ptr_ios_render_.reset(new VideoRenderIosGles20( + (__bridge VideoRenderIosView*)ptr_window_, full_screen_, id_)); return ptr_ios_render_->Init(); ; diff --git a/webrtc/modules/video_render/ios/video_render_ios_view.h b/webrtc/modules/video_render/ios/video_render_ios_view.h index db05356060..915c0f71e2 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_view.h +++ b/webrtc/modules/video_render/ios/video_render_ios_view.h @@ -16,15 +16,7 @@ #include "webrtc/modules/video_render/ios/open_gles20.h" -@interface VideoRenderIosView : UIView { - @private // NOLINT - EAGLContext* context_; - webrtc::OpenGles20* gles_renderer20_; - int _frameBufferWidth; - int _frameBufferHeight; - unsigned int _defaultFrameBuffer; - unsigned int _colorRenderBuffer; -} +@interface VideoRenderIosView : UIView - (BOOL)createContext; - (BOOL)presentFramebuffer; diff --git a/webrtc/modules/video_render/ios/video_render_ios_view.mm b/webrtc/modules/video_render/ios/video_render_ios_view.mm index d218d32653..2e00e097ee 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_view.mm +++ b/webrtc/modules/video_render/ios/video_render_ios_view.mm @@ -8,12 +8,23 @@ * be found in the AUTHORS file in the root of the source tree. */ +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + #include "webrtc/modules/video_render/ios/video_render_ios_view.h" #include "webrtc/system_wrappers/interface/trace.h" using namespace webrtc; -@implementation VideoRenderIosView +@implementation VideoRenderIosView { + EAGLContext* _context; + webrtc::scoped_ptr _gles_renderer20; + int _frameBufferWidth; + int _frameBufferHeight; + unsigned int _defaultFrameBuffer; + unsigned int _colorRenderBuffer; +} @synthesize context = context_; @@ -25,7 +36,7 @@ using namespace webrtc; // init super class self = [super initWithCoder:coder]; if (self) { - gles_renderer20_ = new OpenGles20(); + _gles_renderer20.reset(new OpenGles20()); } return self; } @@ -34,7 +45,7 @@ using namespace webrtc; // init super class self = [super init]; if (self) { - gles_renderer20_ = new OpenGles20(); + _gles_renderer20.reset(new OpenGles20()); } return self; } @@ -43,7 +54,7 @@ using namespace webrtc; // init super class self = [super initWithFrame:frame]; if (self) { - gles_renderer20_ = new OpenGles20(); + _gles_renderer20.reset(new OpenGles20()); } return self; } @@ -59,13 +70,7 @@ using namespace webrtc; _colorRenderBuffer = 0; } - context_ = nil; - - if (gles_renderer20_) { - delete gles_renderer20_; - } - - [super dealloc]; + [EAGLContext setCurrentContext:nil]; } - (NSString*)description { @@ -84,14 +89,13 @@ using namespace webrtc; kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; - context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - if (!context_) { + if (!_context) { return NO; } - // set current EAGLContext to self context_ - if (![EAGLContext setCurrentContext:context_]) { + if (![EAGLContext setCurrentContext:_context]) { return NO; } @@ -102,7 +106,7 @@ using namespace webrtc; // Create color render buffer and allocate backing store. glGenRenderbuffers(1, &_colorRenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderBuffer); - [context_ renderbufferStorage:GL_RENDERBUFFER + [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer]; glGetRenderbufferParameteriv( GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &_frameBufferWidth); @@ -121,12 +125,12 @@ using namespace webrtc; glBindFramebuffer(GL_FRAMEBUFFER, _defaultFrameBuffer); glViewport(0, 0, self.frame.size.width, self.frame.size.height); - return gles_renderer20_->Setup([self bounds].size.width, + return _gles_renderer20->Setup([self bounds].size.width, [self bounds].size.height); } - (BOOL)presentFramebuffer { - if (![context_ presentRenderbuffer:GL_RENDERBUFFER]) { + if (![_context presentRenderbuffer:GL_RENDERBUFFER]) { WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, 0, @@ -139,11 +143,11 @@ using namespace webrtc; } - (BOOL)renderFrame:(I420VideoFrame*)frameToRender { - if (![EAGLContext setCurrentContext:context_]) { + if (![EAGLContext setCurrentContext:_context]) { return NO; } - return gles_renderer20_->Render(*frameToRender); + return _gles_renderer20->Render(*frameToRender); } - (BOOL)setCoordinatesForZOrder:(const float)zOrder @@ -151,7 +155,7 @@ using namespace webrtc; Top:(const float)top Right:(const float)right Bottom:(const float)bottom { - return gles_renderer20_->SetCoordinates(zOrder, left, top, right, bottom); + return _gles_renderer20->SetCoordinates(zOrder, left, top, right, bottom); } @end diff --git a/webrtc/modules/video_render/video_render.gypi b/webrtc/modules/video_render/video_render.gypi index 4f3844406e..a3c0f6d507 100644 --- a/webrtc/modules/video_render/video_render.gypi +++ b/webrtc/modules/video_render/video_render.gypi @@ -130,6 +130,9 @@ ], }], ['OS=="ios"', { + 'xcode_settings': { + 'CLANG_ENABLE_OBJC_ARC': 'YES', + }, 'all_dependent_settings': { 'xcode_settings': { 'OTHER_LDFLAGS': [