Propose of this CL: Close the camera properly on MacOS in order to allow other apps to use it.

Changes in this CL:
1. video_capture_qtkit_info_objc.mm _captureDevicesInfo is never released. I have found this memory leak using Instruments from XCode. The patch is releasing it in dealloc.

2. In video_capture_qtkit_objc.h:
a) _captureDeviceName is not needed. Is allocated in the class but never used.
b) I don't see the role of the  NSAutoreleasePool. also if you use it you have to release it when the class is destroyed. Otherwise you will leak memory. Libjingle has for each thread a pool on mac os.

3. In video_capture_qtkit_objc.mm
a) the camera is not stopped properly . See the changes from dealloc. NOTE : If you don't call [[_captureVideoDeviceInput device] close] other apps will not be able to use the camera since you are not closing your app

b) Removed QTCaptureDevice* videoDevice = (QTCaptureDevice*)[_captureDevices objectAtIndex:0]; I don't know why this because the desired camera is opened in setCaptureDeviceById and can be different than position 0 in the camera array. At this moment if you have two cameras and user want to pick the one on index 1 the app also locks the one on 0 .

Other changes I have done to improve (and are not in this CL):
a) I have set the FPS properly to the desired. I have succeeded to reduce the CPU with 3 % doing this. The current code for setting FPS is commented in webrtc
b) I have removed _rLock from the equation. I don't know if it's good or not but I hadn't understood what exactly we are trying to protect with this. Anyway in the current implementation is never released.

Review URL: https://webrtc-codereview.appspot.com/1097014

Patch from Silviu Caragea <silviu.cpp@gmail.com>.

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3886 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2013-04-23 11:57:56 +00:00
parent c1f243f8e7
commit efdf778d3f
4 changed files with 17 additions and 27 deletions

View File

@ -11,3 +11,4 @@ Martin Storsjo <martin@martin.st>
Jie Mao <maojie0924@gmail.com>
Anil Kumar <an1kumar@gmail.com>
Opera Software ASA
Silviu Caragea <silviu.cpp@gmail.com>

View File

@ -41,6 +41,9 @@ using namespace webrtc;
/// ***** Objective-C. Similar to C++ destructor
/// ***** Returns nothing
- (void)dealloc {
[_captureDevicesInfo release];
[super dealloc];
}

View File

@ -30,7 +30,6 @@
@interface VideoCaptureMacQTKitObjC : NSObject{
// class properties
bool _capturing;
int _counter;
int _frameRate;
int _frameWidth;
int _frameHeight;
@ -49,19 +48,8 @@
QTCaptureDecompressedVideoOutput* _captureDecompressedVideoOutput;
NSArray* _captureDevices;
int _captureDeviceCount;
int _captureDeviceIndex;
NSString* _captureDeviceName;
char _captureDeviceNameUTF8[1024];
char _captureDeviceNameUniqueID[1024];
char _captureDeviceNameProductID[1024];
NSString* _key;
NSNumber* _val;
NSDictionary* _videoSettings;
NSString* _captureQuality;
// other
NSAutoreleasePool* _pool;
}
/**************************************************************************
*

View File

@ -47,10 +47,21 @@ using namespace videocapturemodule;
/// ***** Returns nothing
- (void)dealloc {
if(_captureSession)
{
[_captureSession stopRunning];
[_captureSession release];
if (_captureVideoDeviceInput)
{
if([[_captureVideoDeviceInput device] isOpen])
[[_captureVideoDeviceInput device] close];
[_captureVideoDeviceInput release];
}
[_captureDecompressedVideoOutput release];
[_captureSession release];
[_captureDevices release];
[_rLock release];
[super dealloc];
}
@ -279,10 +290,7 @@ using namespace videocapturemodule;
return [NSNumber numberWithInt:0];
}
_pool = [[NSAutoreleasePool alloc]init];
memset(_captureDeviceNameUTF8, 0, 1024);
_counter = 0;
_framesDelivered = 0;
_framesRendered = 0;
_captureDeviceCount = 0;
@ -291,7 +299,6 @@ using namespace videocapturemodule;
_frameRate = DEFAULT_FRAME_RATE;
_frameWidth = DEFAULT_FRAME_WIDTH;
_frameHeight = DEFAULT_FRAME_HEIGHT;
_captureDeviceName = [[NSString alloc] initWithFormat:@""];
_rLock = [[VideoCaptureRecursiveLock alloc] init];
_captureSession = [[QTCaptureSession alloc] init];
_captureDecompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc]
@ -359,18 +366,9 @@ using namespace videocapturemodule;
return [NSNumber numberWithInt:-1];
}
QTCaptureDevice* videoDevice =
(QTCaptureDevice*)[_captureDevices objectAtIndex:0];
bool success = NO;
NSError* error;
success = [videoDevice open:&error];
if(!success)
{
return [NSNumber numberWithInt:-1];
}
[_captureDecompressedVideoOutput setPixelBufferAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:_frameWidth], (id)kCVPixelBufferWidthKey,