AppRTCDemo(iOS): video support; part 1 of 2: webrtc/.

(needs to land separately from the rest because PRESUBMIT)

Original review URL: https://webrtc-codereview.appspot.com/9229004

BUG=2168
TESTED=trybots
RISK=P3 (code is unused ATM)

Patch from Sajid Hussain <shussain@temasys.com.sg>.

R=noahric@google.com

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5671 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org
2014-03-10 17:12:08 +00:00
parent 0537634154
commit f792d17870
5 changed files with 53 additions and 16 deletions

View File

@@ -15,13 +15,18 @@
#include "webrtc/modules/video_capture/ios/video_capture_ios.h"
@interface VideoCaptureIosObjC
// The following class listens to a notification with name:
// 'StatusBarOrientationDidChange'.
// 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<AVCaptureVideoDataOutputSampleBufferDelegate> {
@private
webrtc::videocapturemodule::VideoCaptureIos* _owner;
webrtc::VideoCaptureCapability _capability;
AVCaptureSession* _captureSession;
int _captureId;
AVCaptureConnection* _connection;
}
@property webrtc::VideoCaptureRotation frameRotation;

View File

@@ -9,19 +9,19 @@
*/
#import "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
#import "webrtc/modules/video_capture/ios/video_capture_ios_objc.h"
#import "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h"
#include "webrtc/system_wrappers/interface/trace.h"
using namespace webrtc;
using namespace webrtc::videocapturemodule;
@interface VideoCaptureIosObjC (hidden)
@interface RTCVideoCaptureIosObjC (hidden)
- (int)changeCaptureInputWithName:(NSString*)captureDeviceName;
@end
@implementation VideoCaptureIosObjC
@implementation RTCVideoCaptureIosObjC
@synthesize frameRotation = _framRotation;
@@ -66,11 +66,24 @@ using namespace webrtc::videocapturemodule;
selector:@selector(onVideoError:)
name:AVCaptureSessionRuntimeErrorNotification
object:_captureSession];
[notify addObserver:self
selector:@selector(statusBarOrientationDidChange:)
name:@"StatusBarOrientationDidChange"
object:nil];
}
return self;
}
- (void)statusBarOrientationDidChange:(NSNotification*)notification {
[self setRelativeVideoOrientation];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (BOOL)setCaptureDeviceByUniqueId:(NSString*)uniqueId {
// check to see if the camera is already set
if (_captureSession) {
@@ -149,13 +162,12 @@ using namespace webrtc::videocapturemodule;
[_captureSession setSessionPreset:captureQuality];
// take care of capture framerate now
AVCaptureConnection* connection =
[currentOutput connectionWithMediaType:AVMediaTypeVideo];
_connection = [currentOutput connectionWithMediaType:AVMediaTypeVideo];
[self setRelativeVideoOrientation];
CMTime cm_time = {1, _capability.maxFPS, kCMTimeFlags_Valid, 0};
[connection setVideoMinFrameDuration:cm_time];
[connection setVideoMaxFrameDuration:cm_time];
[_connection setVideoMinFrameDuration:cm_time];
[_connection setVideoMaxFrameDuration:cm_time];
// finished configuring, commit settings to AVCaptureSession.
[_captureSession commitConfiguration];
@@ -167,6 +179,26 @@ using namespace webrtc::videocapturemodule;
return YES;
}
- (void)setRelativeVideoOrientation {
if (!_connection.supportsVideoOrientation)
return;
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationPortrait:
_connection.videoOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIInterfaceOrientationPortraitUpsideDown:
_connection.videoOrientation =
AVCaptureVideoOrientationPortraitUpsideDown;
break;
case UIInterfaceOrientationLandscapeLeft:
_connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIInterfaceOrientationLandscapeRight:
_connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
}
}
- (void)onVideoError {
// TODO(sjlee): make the specific error handling with this notification.
WEBRTC_TRACE(kTraceError,

View File

@@ -13,7 +13,7 @@
#include "webrtc/modules/video_capture/video_capture_impl.h"
@class VideoCaptureIosObjC;
@class RTCVideoCaptureIosObjC;
namespace webrtc {
namespace videocapturemodule {
@@ -33,7 +33,7 @@ class VideoCaptureIos : public VideoCaptureImpl {
virtual int32_t CaptureSettings(VideoCaptureCapability& settings) OVERRIDE;
private:
VideoCaptureIosObjC* capture_device_;
RTCVideoCaptureIosObjC* capture_device_;
bool is_capturing_;
int32_t id_;
VideoCaptureCapability capability_;

View File

@@ -9,7 +9,7 @@
*/
#include "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
#include "webrtc/modules/video_capture/ios/video_capture_ios_objc.h"
#include "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h"
#include "webrtc/system_wrappers/interface/ref_count.h"
#include "webrtc/system_wrappers/interface/scoped_refptr.h"
#include "webrtc/system_wrappers/interface/trace.h"
@@ -53,8 +53,8 @@ VideoCaptureModule* VideoCaptureIos::Create(const int32_t capture_id,
capture_module->_deviceUniqueId[name_length] = '\0';
capture_module->capture_device_ =
[[VideoCaptureIosObjC alloc] initWithOwner:capture_module
captureId:capture_module->id_];
[[RTCVideoCaptureIosObjC alloc] initWithOwner:capture_module
captureId:capture_module->id_];
if (!capture_module->capture_device_) {
return NULL;
}

View File

@@ -108,10 +108,10 @@
'ios/device_info_ios.mm',
'ios/device_info_ios_objc.h',
'ios/device_info_ios_objc.mm',
'ios/rtc_video_capture_ios_objc.h',
'ios/rtc_video_capture_ios_objc.mm',
'ios/video_capture_ios.h',
'ios/video_capture_ios.mm',
'ios/video_capture_ios_objc.h',
'ios/video_capture_ios_objc.mm',
],
'all_dependent_settings': {
'xcode_settings': {