Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Unified Diff: webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm

Issue 2650343006: Pass network config constraint as base64 to avoid mangling bytes (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm b/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm
index 0a61f99e9efd43444a672f0e4857befbf14436b6..2196b41954cbfc61faa50a7ea6871f0a03967f1a 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm
+++ b/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm
@@ -10,6 +10,7 @@
#import "RTCMediaConstraints+Private.h"
+#import "NSData+StdString.h"
#import "NSString+StdString.h"
#include <memory>
@@ -63,8 +64,8 @@ MediaConstraints::GetOptional() const {
@implementation RTCMediaConstraints {
- NSDictionary<NSString *, NSString *> *_mandatory;
- NSDictionary<NSString *, NSString *> *_optional;
+ NSMutableDictionary<NSString *, NSObject *> *_mandatory;
+ NSMutableDictionary<NSString *, NSObject *> *_optional;
}
- (instancetype)initWithMandatoryConstraints:
@@ -72,10 +73,10 @@ MediaConstraints::GetOptional() const {
optionalConstraints:
(NSDictionary<NSString *, NSString *> *)optional {
if (self = [super init]) {
- _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
- copyItems:YES];
- _optional = [[NSDictionary alloc] initWithDictionary:optional
- copyItems:YES];
+ _mandatory = [[NSMutableDictionary alloc] initWithDictionary:mandatory
+ copyItems:YES];
+ _optional = [[NSMutableDictionary alloc] initWithDictionary:optional
+ copyItems:YES];
}
return self;
}
@@ -86,6 +87,21 @@ MediaConstraints::GetOptional() const {
_optional];
}
+- (void)addConstraintForKey:(NSString *)key
+ data:(NSData *)data
+ isMandatory:(BOOL)isMandatory {
+ NSAssert(data, @"Invalid data.");
+ NSAssert(key.length, @"Invalid key.");
+ if (!data || !key.length) {
+ return;
tkchin_webrtc 2017/02/02 19:04:53 nit: log error
Chuck 2017/02/03 15:55:50 Gone in latest iteration.
+ }
+ if (isMandatory) {
+ _mandatory[key] = data;
tkchin_webrtc 2017/02/02 19:04:53 might break mac build - make sure to run bots ( do
Chuck 2017/02/03 15:55:50 Gone in latest iteration.
+ } else {
+ _optional[key] = data;
+ }
+}
+
#pragma mark - Private
- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints {
@@ -101,16 +117,24 @@ MediaConstraints::GetOptional() const {
+ (webrtc::MediaConstraintsInterface::Constraints)
nativeConstraintsForConstraints:
- (NSDictionary<NSString *, NSString *> *)constraints {
+ (NSDictionary<NSString *, NSObject *> *)constraints {
webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
for (NSString *key in constraints) {
NSAssert([key isKindOfClass:[NSString class]],
@"%@ is not an NSString.", key);
- NSString *value = [constraints objectForKey:key];
- NSAssert([value isKindOfClass:[NSString class]],
- @"%@ is not an NSString.", value);
- nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
- key.stdString, value.stdString));
+ // value must be either NSString or NSData.
+ NSObject *value = [constraints objectForKey:key];
+ if ([value isKindOfClass:[NSData class]]) {
+ NSData *data = (NSData *)value;
+ nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
+ key.stdString, data.stdString));
+ } else {
tkchin_webrtc 2017/02/02 19:04:53 nit: safer to do an else if NSString then finally
Chuck 2017/02/03 15:55:51 Gone in latest iteration.
+ NSAssert([value isKindOfClass:[NSString class]],
+ @"%@ is not an NSString.", value);
+ NSString *string = (NSString *)value;
+ nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
+ key.stdString, string.stdString));
+ }
}
return nativeConstraints;
}

Powered by Google App Engine
This is Rietveld 408576698