Update API for Objective-C RTCMediaConstraints.
BUG= Review URL: https://codereview.webrtc.org/1543033003 Cr-Commit-Position: refs/heads/master@{#11172}
This commit is contained in:
@ -26,6 +26,9 @@ if (is_ios) {
|
|||||||
"objc/RTCIceServer+Private.h",
|
"objc/RTCIceServer+Private.h",
|
||||||
"objc/RTCIceServer.h",
|
"objc/RTCIceServer.h",
|
||||||
"objc/RTCIceServer.mm",
|
"objc/RTCIceServer.mm",
|
||||||
|
"objc/RTCMediaConstraints+Private.h",
|
||||||
|
"objc/RTCMediaConstraints.h",
|
||||||
|
"objc/RTCMediaConstraints.mm",
|
||||||
"objc/RTCSessionDescription+Private.h",
|
"objc/RTCSessionDescription+Private.h",
|
||||||
"objc/RTCSessionDescription.h",
|
"objc/RTCSessionDescription.h",
|
||||||
"objc/RTCSessionDescription.mm",
|
"objc/RTCSessionDescription.mm",
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
'objc/RTCIceServer+Private.h',
|
'objc/RTCIceServer+Private.h',
|
||||||
'objc/RTCIceServer.h',
|
'objc/RTCIceServer.h',
|
||||||
'objc/RTCIceServer.mm',
|
'objc/RTCIceServer.mm',
|
||||||
|
'objc/RTCMediaConstraints+Private.h',
|
||||||
|
'objc/RTCMediaConstraints.h',
|
||||||
|
'objc/RTCMediaConstraints.mm',
|
||||||
'objc/RTCSessionDescription+Private.h',
|
'objc/RTCSessionDescription+Private.h',
|
||||||
'objc/RTCSessionDescription.h',
|
'objc/RTCSessionDescription.h',
|
||||||
'objc/RTCSessionDescription.mm',
|
'objc/RTCSessionDescription.mm',
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
'sources': [
|
'sources': [
|
||||||
'objctests/RTCIceCandidateTest.mm',
|
'objctests/RTCIceCandidateTest.mm',
|
||||||
'objctests/RTCIceServerTest.mm',
|
'objctests/RTCIceServerTest.mm',
|
||||||
|
'objctests/RTCMediaConstraintsTest.mm',
|
||||||
'objctests/RTCSessionDescriptionTest.mm',
|
'objctests/RTCSessionDescriptionTest.mm',
|
||||||
],
|
],
|
||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
|
53
webrtc/api/objc/RTCMediaConstraints+Private.h
Normal file
53
webrtc/api/objc/RTCMediaConstraints+Private.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 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 "RTCMediaConstraints.h"
|
||||||
|
|
||||||
|
#include "talk/app/webrtc/mediaconstraintsinterface.h"
|
||||||
|
#include "webrtc/base/scoped_ptr.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
class MediaConstraints : public MediaConstraintsInterface {
|
||||||
|
public:
|
||||||
|
virtual ~MediaConstraints();
|
||||||
|
MediaConstraints();
|
||||||
|
MediaConstraints(
|
||||||
|
const MediaConstraintsInterface::Constraints& mandatory,
|
||||||
|
const MediaConstraintsInterface::Constraints& optional);
|
||||||
|
virtual const Constraints& GetMandatory() const;
|
||||||
|
virtual const Constraints& GetOptional() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MediaConstraintsInterface::Constraints mandatory_;
|
||||||
|
MediaConstraintsInterface::Constraints optional_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface RTCMediaConstraints ()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A MediaConstraints representation of this RTCMediaConstraints object. This is
|
||||||
|
* needed to pass to the underlying C++ APIs.
|
||||||
|
*/
|
||||||
|
- (rtc::scoped_ptr<webrtc::MediaConstraints>)nativeConstraints;
|
||||||
|
|
||||||
|
/** Return a native Constraints object representing these constraints */
|
||||||
|
+ (webrtc::MediaConstraintsInterface::Constraints)
|
||||||
|
nativeConstraintsForConstraints:
|
||||||
|
(NSDictionary<NSString *, NSString *> *)constraints;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
28
webrtc/api/objc/RTCMediaConstraints.h
Normal file
28
webrtc/api/objc/RTCMediaConstraints.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 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>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface RTCMediaConstraints : NSObject
|
||||||
|
|
||||||
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
|
||||||
|
/** Initialize with mandatory and/or optional constraints. */
|
||||||
|
- (instancetype)initWithMandatoryConstraints:
|
||||||
|
(nullable NSDictionary<NSString *, NSString *> *)mandatory
|
||||||
|
optionalConstraints:
|
||||||
|
(nullable NSDictionary<NSString *, NSString *> *)optional
|
||||||
|
NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
92
webrtc/api/objc/RTCMediaConstraints.mm
Normal file
92
webrtc/api/objc/RTCMediaConstraints.mm
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 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 "RTCMediaConstraints.h"
|
||||||
|
|
||||||
|
#import "webrtc/api/objc/RTCMediaConstraints+Private.h"
|
||||||
|
#import "webrtc/base/objc/NSString+StdString.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
MediaConstraints::~MediaConstraints() {}
|
||||||
|
|
||||||
|
MediaConstraints::MediaConstraints() {}
|
||||||
|
|
||||||
|
MediaConstraints::MediaConstraints(
|
||||||
|
const MediaConstraintsInterface::Constraints& mandatory,
|
||||||
|
const MediaConstraintsInterface::Constraints& optional)
|
||||||
|
: mandatory_(mandatory), optional_(optional) {}
|
||||||
|
|
||||||
|
const MediaConstraintsInterface::Constraints&
|
||||||
|
MediaConstraints::GetMandatory() const {
|
||||||
|
return mandatory_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MediaConstraintsInterface::Constraints&
|
||||||
|
MediaConstraints::GetOptional() const {
|
||||||
|
return optional_;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
|
||||||
|
@implementation RTCMediaConstraints {
|
||||||
|
NSDictionary<NSString *, NSString *> *_mandatory;
|
||||||
|
NSDictionary<NSString *, NSString *> *_optional;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithMandatoryConstraints:
|
||||||
|
(NSDictionary<NSString *, NSString *> *)mandatory
|
||||||
|
optionalConstraints:
|
||||||
|
(NSDictionary<NSString *, NSString *> *)optional {
|
||||||
|
if (self = [super init]) {
|
||||||
|
_mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
|
||||||
|
copyItems:YES];
|
||||||
|
_optional = [[NSDictionary alloc] initWithDictionary:optional
|
||||||
|
copyItems:YES];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)description {
|
||||||
|
return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
|
||||||
|
_mandatory,
|
||||||
|
_optional];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Private
|
||||||
|
|
||||||
|
- (rtc::scoped_ptr<webrtc::MediaConstraints>)nativeConstraints {
|
||||||
|
webrtc::MediaConstraintsInterface::Constraints mandatory =
|
||||||
|
[[self class] nativeConstraintsForConstraints:_mandatory];
|
||||||
|
webrtc::MediaConstraintsInterface::Constraints optional =
|
||||||
|
[[self class] nativeConstraintsForConstraints:_optional];
|
||||||
|
|
||||||
|
webrtc::MediaConstraints *nativeConstraints =
|
||||||
|
new webrtc::MediaConstraints(mandatory, optional);
|
||||||
|
return rtc::scoped_ptr<webrtc::MediaConstraints>(nativeConstraints);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (webrtc::MediaConstraintsInterface::Constraints)
|
||||||
|
nativeConstraintsForConstraints:
|
||||||
|
(NSDictionary<NSString *, NSString *> *)constraints {
|
||||||
|
webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
|
||||||
|
for (NSString *key in constraints) {
|
||||||
|
NSAssert([key isKindOfClass:[NSString class]],
|
||||||
|
@"%@ is not an NSString.", key);
|
||||||
|
NSAssert([constraints[key] isKindOfClass:[NSString class]],
|
||||||
|
@"%@ is not an NSString.", constraints[key]);
|
||||||
|
nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
|
||||||
|
key.stdString, constraints[key].stdString));
|
||||||
|
}
|
||||||
|
return nativeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
66
webrtc/api/objctests/RTCMediaConstraintsTest.mm
Normal file
66
webrtc/api/objctests/RTCMediaConstraintsTest.mm
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 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>
|
||||||
|
|
||||||
|
#include "webrtc/base/gunit.h"
|
||||||
|
|
||||||
|
#import "webrtc/api/objc/RTCMediaConstraints.h"
|
||||||
|
#import "webrtc/api/objc/RTCMediaConstraints+Private.h"
|
||||||
|
#import "webrtc/base/objc/NSString+StdString.h"
|
||||||
|
|
||||||
|
@interface RTCMediaConstraintsTest : NSObject
|
||||||
|
- (void)testMediaConstraints;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation RTCMediaConstraintsTest
|
||||||
|
|
||||||
|
- (void)testMediaConstraints {
|
||||||
|
NSDictionary *mandatory = @{@"key1": @"value1", @"key2": @"value2"};
|
||||||
|
NSDictionary *optional = @{@"key3": @"value3", @"key4": @"value4"};
|
||||||
|
|
||||||
|
RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc]
|
||||||
|
initWithMandatoryConstraints:mandatory
|
||||||
|
optionalConstraints:optional];
|
||||||
|
rtc::scoped_ptr<webrtc::MediaConstraints> nativeConstraints =
|
||||||
|
[constraints nativeConstraints];
|
||||||
|
|
||||||
|
webrtc::MediaConstraintsInterface::Constraints nativeMandatory =
|
||||||
|
nativeConstraints->GetMandatory();
|
||||||
|
[self expectConstraints:mandatory inNativeConstraints:nativeMandatory];
|
||||||
|
|
||||||
|
webrtc::MediaConstraintsInterface::Constraints nativeOptional =
|
||||||
|
nativeConstraints->GetOptional();
|
||||||
|
[self expectConstraints:optional inNativeConstraints:nativeOptional];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)expectConstraints:(NSDictionary *)constraints
|
||||||
|
inNativeConstraints:
|
||||||
|
(webrtc::MediaConstraintsInterface::Constraints)nativeConstraints {
|
||||||
|
EXPECT_EQ(constraints.count, nativeConstraints.size());
|
||||||
|
|
||||||
|
for (NSString *key in constraints) {
|
||||||
|
NSString *value = constraints[key];
|
||||||
|
|
||||||
|
std::string nativeValue;
|
||||||
|
bool found = nativeConstraints.FindFirst(key.stdString, &nativeValue);
|
||||||
|
EXPECT_TRUE(found);
|
||||||
|
EXPECT_EQ(value.stdString, nativeValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
TEST(RTCMediaConstraintsTest, MediaConstraintsTest) {
|
||||||
|
@autoreleasepool {
|
||||||
|
RTCMediaConstraintsTest *test = [[RTCMediaConstraintsTest alloc] init];
|
||||||
|
[test testMediaConstraints];
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user