Allow passing network config constraint as base64 encoded string to preserve values of serialized protos. The values are a serialized byte stream packed into a std::string. To be represented as a NSString they must be base64 encoded or bytes outside of the ASCII range will be encoded into multi byte UTF8 sequences by default.

BUG=0

Review-Url: https://codereview.webrtc.org/2650343006
Cr-Commit-Position: refs/heads/master@{#16435}
This commit is contained in:
haysc 2017-02-03 13:03:39 -08:00 committed by Commit bot
parent 390e64d7eb
commit 98c437458a
2 changed files with 17 additions and 2 deletions

View File

@ -32,6 +32,8 @@ NSString * const kRTCMediaConstraintsMaxFrameRate =
@(webrtc::MediaConstraintsInterface::kMaxFrameRate);
NSString * const kRTCMediaConstraintsLevelControl =
@(webrtc::MediaConstraintsInterface::kLevelControl);
NSString * const kRTCMediaConstraintsAudioNetworkAdaptorConfig =
@(webrtc::MediaConstraintsInterface::kAudioNetworkAdaptorConfig);
NSString * const kRTCMediaConstraintsValueTrue =
@(webrtc::MediaConstraintsInterface::kValueTrue);
@ -109,8 +111,17 @@ MediaConstraints::GetOptional() const {
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));
if ([kRTCMediaConstraintsAudioNetworkAdaptorConfig isEqualToString:key]) {
// This value is base64 encoded.
NSData *charData = [[NSData alloc] initWithBase64EncodedString:value options:0];
std::string configValue =
std::string(reinterpret_cast<const char *>(charData.bytes), charData.length);
nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
key.stdString, configValue));
} else {
nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
key.stdString, value.stdString));
}
}
return nativeConstraints;
}

View File

@ -23,6 +23,10 @@ RTC_EXTERN NSString * const kRTCMediaConstraintsMinHeight;
RTC_EXTERN NSString * const kRTCMediaConstraintsMaxFrameRate;
RTC_EXTERN NSString * const kRTCMediaConstraintsMinFrameRate;
RTC_EXTERN NSString * const kRTCMediaConstraintsLevelControl;
/** The value for this key should be a base64 encoded string containing
* the data from the serialized configuration proto.
*/
RTC_EXTERN NSString * const kRTCMediaConstraintsAudioNetworkAdaptorConfig;
RTC_EXTERN NSString * const kRTCMediaConstraintsValueTrue;
RTC_EXTERN NSString * const kRTCMediaConstraintsValueFalse;