2016-12-06 05:22:49 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
#import <OCMock/OCMock.h>
|
|
|
|
|
|
2017-07-07 03:09:51 -07:00
|
|
|
#include "webrtc/rtc_base/gunit.h"
|
2016-12-06 05:22:49 -08:00
|
|
|
|
Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2911053002/ )
Reason for revert:
Take three of relanding this after all internal issues have been resolved.
Original issue's description:
> Revert of Split iOS sdk in to separate targets (patchset #3 id:320001 of https://codereview.webrtc.org/2893843003/ )
>
> Reason for revert:
> Breaks downstream project.
>
> Original issue's description:
> > Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2893593002/ )
> >
> > Reason for revert:
> > Take two of fixing downstream issues?
> >
> > Original issue's description:
> > > Revert of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2890733003/ )
> > >
> > > Reason for revert:
> > > Still problems with downstream projects
> > >
> > > Original issue's description:
> > > > Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2890513002/ )
> > > >
> > > > Reason for revert:
> > > > Fixing downstream breakages
> > > >
> > > > Original issue's description:
> > > > > Revert of Split iOS sdk in to separate targets (patchset #13 id:280001 of https://codereview.webrtc.org/2862543002/ )
> > > > >
> > > > > Reason for revert:
> > > > > Breaking downstream projects.
> > > > >
> > > > > Original issue's description:
> > > > > > Split iOS sdk in to separate targets
> > > > > >
> > > > > > This CL splits the iOS sdk into separate static libraries for video,
> > > > > > audio, ui, common, and peerconnection-related code. This will in the
> > > > > > future make it easier to compile WebRTC without unneeded components.
> > > > > >
> > > > > > BUG=webrtc:4867
> > > > > >
> > > > > > Review-Url: https://codereview.webrtc.org/2862543002
> > > > > > Cr-Commit-Position: refs/heads/master@{#18166}
> > > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/52c83fe7102f566cf35a7533092873d58b38f426
> > > > >
> > > > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,kthelgason@webrtc.org
> > > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > > NOPRESUBMIT=true
> > > > > NOTREECHECKS=true
> > > > > NOTRY=true
> > > > > BUG=webrtc:4867
> > > > >
> > > > > Review-Url: https://codereview.webrtc.org/2890513002
> > > > > Cr-Commit-Position: refs/heads/master@{#18170}
> > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/9756238084707787f735e1294e896e462e459717
> > > >
> > > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > NOPRESUBMIT=true
> > > > NOTREECHECKS=true
> > > > NOTRY=true
> > > > BUG=webrtc:4867
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2890733003
> > > > Cr-Commit-Position: refs/heads/master@{#18174}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/d51e042492bedd057bc0cac7828979d5c7369cea
> > >
> > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4867
> > >
> > > Review-Url: https://codereview.webrtc.org/2893593002
> > > Cr-Commit-Position: refs/heads/master@{#18182}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/37144b214e2baf62ecb262ab878dde8c59cdd6a3
> >
> > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > # Skipping CQ checks because original CL landed less than 1 days ago.
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=webrtc:4867
> >
> > Review-Url: https://codereview.webrtc.org/2893843003
> > Cr-Commit-Position: refs/heads/master@{#18303}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/580c3522d294c877adfe555048c675bd8d166657
>
> TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org,kthelgason@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4867
>
> Review-Url: https://codereview.webrtc.org/2911053002
> Cr-Commit-Position: refs/heads/master@{#18309}
> Committed: https://chromium.googlesource.com/external/webrtc/+/af5c05540cc8208f682cafe88c5c16a505479196
TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org,mbonadei@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4867
Review-Url: https://codereview.webrtc.org/2913753003
Cr-Commit-Position: refs/heads/master@{#18319}
2017-05-30 01:48:47 -07:00
|
|
|
#include "Video/avfoundationformatmapper.h"
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Width and height don't play any role so lets use predefined values throughout
|
|
|
|
|
// the tests.
|
|
|
|
|
static const int kFormatWidth = 789;
|
|
|
|
|
static const int kFormatHeight = 987;
|
|
|
|
|
|
|
|
|
|
// Hardcoded framrate to be used throughout the tests.
|
|
|
|
|
static const int kFramerate = 30;
|
|
|
|
|
|
|
|
|
|
// Same width and height is used so it's ok to expect same cricket::VideoFormat
|
|
|
|
|
static cricket::VideoFormat expectedFormat =
|
|
|
|
|
cricket::VideoFormat(kFormatWidth,
|
|
|
|
|
kFormatHeight,
|
|
|
|
|
cricket::VideoFormat::FpsToInterval(kFramerate),
|
|
|
|
|
cricket::FOURCC_NV12);
|
|
|
|
|
|
|
|
|
|
// Mock class for AVCaptureDeviceFormat.
|
|
|
|
|
// Custom implementation needed because OCMock cannot handle the
|
|
|
|
|
// CMVideoDescriptionRef mocking.
|
|
|
|
|
@interface AVCaptureDeviceFormatMock : NSObject
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, assign) CMVideoFormatDescriptionRef format;
|
|
|
|
|
@property (nonatomic, strong) OCMockObject *rangeMock;
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithMediaSubtype:(FourCharCode)subtype
|
|
|
|
|
minFps:(float)minFps
|
|
|
|
|
maxFps:(float)maxFps;
|
|
|
|
|
+ (instancetype)validFormat;
|
|
|
|
|
+ (instancetype)invalidFpsFormat;
|
|
|
|
|
+ (instancetype)invalidMediaSubtypeFormat;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation AVCaptureDeviceFormatMock
|
|
|
|
|
|
|
|
|
|
@synthesize format = _format;
|
|
|
|
|
@synthesize rangeMock = _rangeMock;
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithMediaSubtype:(FourCharCode)subtype
|
|
|
|
|
minFps:(float)minFps
|
|
|
|
|
maxFps:(float)maxFps {
|
|
|
|
|
if (self = [super init]) {
|
|
|
|
|
CMVideoFormatDescriptionCreate(nil, subtype, kFormatWidth, kFormatHeight,
|
|
|
|
|
nil, &_format);
|
|
|
|
|
// We can use OCMock for the range.
|
|
|
|
|
_rangeMock = [OCMockObject mockForClass:[AVFrameRateRange class]];
|
|
|
|
|
[[[_rangeMock stub] andReturnValue:@(minFps)] minFrameRate];
|
|
|
|
|
[[[_rangeMock stub] andReturnValue:@(maxFps)] maxFrameRate];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (instancetype)validFormat {
|
|
|
|
|
AVCaptureDeviceFormatMock *instance = [[AVCaptureDeviceFormatMock alloc]
|
|
|
|
|
initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
|
|
|
|
|
minFps:0.0
|
|
|
|
|
maxFps:30.0];
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (instancetype)invalidFpsFormat {
|
|
|
|
|
AVCaptureDeviceFormatMock *instance = [[AVCaptureDeviceFormatMock alloc]
|
|
|
|
|
initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
|
|
|
|
|
minFps:0.0
|
|
|
|
|
maxFps:22.0];
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (instancetype)invalidMediaSubtypeFormat {
|
|
|
|
|
AVCaptureDeviceFormatMock *instance = [[AVCaptureDeviceFormatMock alloc]
|
|
|
|
|
initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8Planar
|
|
|
|
|
minFps:0.0
|
|
|
|
|
maxFps:60.0];
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
|
if (_format != nil) {
|
|
|
|
|
CFRelease(_format);
|
|
|
|
|
_format = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Redefinition of AVCaptureDevice methods we want to mock.
|
|
|
|
|
- (CMVideoFormatDescriptionRef)formatDescription {
|
|
|
|
|
return self.format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray *)videoSupportedFrameRateRanges {
|
|
|
|
|
return @[ self.rangeMock ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFramerateFormats) {
|
|
|
|
|
// given
|
2017-02-28 09:14:45 -08:00
|
|
|
id mockDevice = OCMClassMock([AVCaptureDevice class]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// Valid media subtype, invalid framerate
|
|
|
|
|
AVCaptureDeviceFormatMock* mock =
|
|
|
|
|
[AVCaptureDeviceFormatMock invalidFpsFormat];
|
2017-02-28 09:14:45 -08:00
|
|
|
OCMStub([mockDevice formats]).andReturn(@[ mock ]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
std::set<cricket::VideoFormat> result =
|
|
|
|
|
webrtc::GetSupportedVideoFormatsForDevice(mockDevice);
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE(result.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFormats) {
|
|
|
|
|
// given
|
2017-02-28 09:14:45 -08:00
|
|
|
id mockDevice = OCMClassMock([AVCaptureDevice class]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// Invalid media subtype, valid framerate
|
|
|
|
|
AVCaptureDeviceFormatMock* mock =
|
|
|
|
|
[AVCaptureDeviceFormatMock invalidMediaSubtypeFormat];
|
2017-02-28 09:14:45 -08:00
|
|
|
OCMStub([mockDevice formats]).andReturn(@[ mock ]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
std::set<cricket::VideoFormat> result =
|
|
|
|
|
webrtc::GetSupportedVideoFormatsForDevice(mockDevice);
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE(result.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AVFormatMapperTest, SuportedCricketFormats) {
|
|
|
|
|
// given
|
2017-02-28 09:14:45 -08:00
|
|
|
id mockDevice = OCMClassMock([AVCaptureDevice class]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// valid media subtype, valid framerate
|
|
|
|
|
AVCaptureDeviceFormatMock* mock = [AVCaptureDeviceFormatMock validFormat];
|
2017-02-28 09:14:45 -08:00
|
|
|
OCMStub([mockDevice formats]).andReturn(@[ mock ]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
std::set<cricket::VideoFormat> result =
|
|
|
|
|
webrtc::GetSupportedVideoFormatsForDevice(mockDevice);
|
|
|
|
|
|
|
|
|
|
// then
|
2017-01-04 07:11:23 -08:00
|
|
|
EXPECT_EQ(1u, result.size());
|
2016-12-06 05:22:49 -08:00
|
|
|
// make sure the set has the expected format
|
|
|
|
|
EXPECT_EQ(expectedFormat, *result.begin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AVFormatMapperTest, MediaSubtypePreference) {
|
|
|
|
|
// given
|
2017-02-28 09:14:45 -08:00
|
|
|
id mockDevice = OCMClassMock([AVCaptureDevice class]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// valid media subtype, valid framerate
|
|
|
|
|
AVCaptureDeviceFormatMock* mockOne = [[AVCaptureDeviceFormatMock alloc]
|
|
|
|
|
initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
|
|
|
|
|
minFps:0.0
|
|
|
|
|
maxFps:30.0];
|
|
|
|
|
// valid media subtype, valid framerate.
|
|
|
|
|
// This media subtype should be the preffered one.
|
|
|
|
|
AVCaptureDeviceFormatMock* mockTwo = [[AVCaptureDeviceFormatMock alloc]
|
|
|
|
|
initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
|
|
|
|
|
minFps:0.0
|
|
|
|
|
maxFps:30.0];
|
2017-02-28 09:14:45 -08:00
|
|
|
OCMStub([mockDevice lockForConfiguration:[OCMArg setTo:nil]]).andReturn(YES);
|
|
|
|
|
OCMStub([mockDevice unlockForConfiguration]);
|
|
|
|
|
NSArray* array = @[ mockOne, mockTwo ];
|
|
|
|
|
OCMStub([mockDevice formats]).andReturn(array);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// to verify
|
2017-02-28 09:14:45 -08:00
|
|
|
OCMExpect([mockDevice setActiveFormat:(AVCaptureDeviceFormat*)mockTwo]);
|
|
|
|
|
OCMExpect(
|
|
|
|
|
[mockDevice setActiveVideoMinFrameDuration:CMTimeMake(1, kFramerate)]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
bool resultFormat =
|
|
|
|
|
webrtc::SetFormatForCaptureDevice(mockDevice, nil, expectedFormat);
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE(resultFormat);
|
|
|
|
|
[mockDevice verify];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AVFormatMapperTest, SetFormatWhenDeviceCannotLock) {
|
|
|
|
|
// given
|
2017-02-28 09:14:45 -08:00
|
|
|
id mockDevice = OCMClassMock([AVCaptureDevice class]);
|
2016-12-06 05:22:49 -08:00
|
|
|
[[[mockDevice stub] andReturnValue:@(NO)]
|
|
|
|
|
lockForConfiguration:[OCMArg setTo:nil]];
|
|
|
|
|
[[[mockDevice stub] andReturn:@[]] formats];
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
bool resultFormat = webrtc::SetFormatForCaptureDevice(mockDevice, nil,
|
|
|
|
|
cricket::VideoFormat());
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_FALSE(resultFormat);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 09:14:45 -08:00
|
|
|
TEST(AVFormatMapperTest, SetFormatWhenFormatIsIncompatible) {
|
2016-12-06 05:22:49 -08:00
|
|
|
// given
|
2017-02-28 09:14:45 -08:00
|
|
|
id mockDevice = OCMClassMock([AVCaptureDevice class]);
|
|
|
|
|
OCMStub([mockDevice formats]).andReturn(@[]);
|
|
|
|
|
OCMStub([mockDevice lockForConfiguration:[OCMArg setTo:nil]]).andReturn(YES);
|
|
|
|
|
NSException* testException =
|
2016-12-06 05:22:49 -08:00
|
|
|
[NSException exceptionWithName:@"Test exception"
|
|
|
|
|
reason:@"Raised from unit tests"
|
|
|
|
|
userInfo:nil];
|
2017-02-28 09:14:45 -08:00
|
|
|
OCMStub([mockDevice setActiveFormat:[OCMArg any]]).andThrow(testException);
|
|
|
|
|
OCMExpect([mockDevice unlockForConfiguration]);
|
2016-12-06 05:22:49 -08:00
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
bool resultFormat = webrtc::SetFormatForCaptureDevice(mockDevice, nil,
|
|
|
|
|
cricket::VideoFormat());
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_FALSE(resultFormat);
|
2017-02-28 09:14:45 -08:00
|
|
|
|
|
|
|
|
// TODO(denicija): Remove try-catch when Chromium rolls this change:
|
|
|
|
|
// https://github.com/erikdoe/ocmock/commit/de1419415581dc307045e54bfe9c98c86efea96b
|
|
|
|
|
// Without it, stubbed exceptions are being re-raised on [mock verify].
|
|
|
|
|
// More information here:
|
|
|
|
|
//https://github.com/erikdoe/ocmock/issues/241
|
|
|
|
|
@try {
|
|
|
|
|
[mockDevice verify];
|
|
|
|
|
} @catch (NSException* exception) {
|
|
|
|
|
if ([exception.reason isEqual:testException.reason]) {
|
|
|
|
|
// Nothing dangerous here
|
|
|
|
|
EXPECT_TRUE([exception.reason isEqualToString:exception.reason]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-06 05:22:49 -08:00
|
|
|
}
|