mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 14:20:45 +01:00

This is a no-op change because rtc::Optional is an alias to absl::optional This CL generated by running script passing top level directories except rtc_base and api find $@ -type f \( -name \*.h -o -name \*.cc -o -name \*.mm \) \ -exec sed -i 's|rtc::Optional|absl::optional|g' {} \+ \ -exec sed -i 's|rtc::nullopt|absl::nullopt|g' {} \+ \ -exec sed -i 's|#include "api/optional.h"|#include "absl/types/optional.h"|' {} \+ find $@ -type f -name BUILD.gn \ -exec sed -r -i 's|"[\./api]*:optional"|"//third_party/abseil-cpp/absl/types:optional"|' {} \+; git cl format Bug: webrtc:9078 Change-Id: I9465c172e65ba6e6ed4e4fdc35b0b265038d6f71 Reviewed-on: https://webrtc-review.googlesource.com/84584 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23697}
167 lines
4.7 KiB
Text
167 lines
4.7 KiB
Text
/*
|
|
* Copyright 2017 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 "WebRTC/RTCVideoCodec.h"
|
|
|
|
#import "NSString+StdString.h"
|
|
#import "RTCVideoCodec+Private.h"
|
|
#if defined(WEBRTC_IOS)
|
|
#import "UIDevice+H264Profile.h"
|
|
#endif
|
|
#import "WebRTC/RTCVideoCodecFactory.h"
|
|
|
|
#include "media/base/mediaconstants.h"
|
|
|
|
namespace {
|
|
|
|
NSString *MaxSupportedProfileLevelConstrainedHigh();
|
|
NSString *MaxSupportedProfileLevelConstrainedBaseline();
|
|
|
|
} // namespace
|
|
|
|
NSString *const kRTCVideoCodecVp8Name = @(cricket::kVp8CodecName);
|
|
NSString *const kRTCVideoCodecVp9Name = @(cricket::kVp9CodecName);
|
|
NSString *const kRTCVideoCodecH264Name = @(cricket::kH264CodecName);
|
|
NSString *const kRTCLevel31ConstrainedHigh = @"640c1f";
|
|
NSString *const kRTCLevel31ConstrainedBaseline = @"42e01f";
|
|
NSString *const kRTCMaxSupportedH264ProfileLevelConstrainedHigh =
|
|
MaxSupportedProfileLevelConstrainedHigh();
|
|
NSString *const kRTCMaxSupportedH264ProfileLevelConstrainedBaseline =
|
|
MaxSupportedProfileLevelConstrainedBaseline();
|
|
|
|
namespace {
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
using namespace webrtc::H264;
|
|
|
|
NSString *MaxSupportedLevelForProfile(Profile profile) {
|
|
const absl::optional<ProfileLevelId> profileLevelId = [UIDevice maxSupportedH264Profile];
|
|
if (profileLevelId && profileLevelId->profile >= profile) {
|
|
const absl::optional<std::string> profileString =
|
|
ProfileLevelIdToString(ProfileLevelId(profile, profileLevelId->level));
|
|
if (profileString) {
|
|
return [NSString stringForStdString:*profileString];
|
|
}
|
|
}
|
|
return nil;
|
|
}
|
|
#endif
|
|
|
|
NSString *MaxSupportedProfileLevelConstrainedBaseline() {
|
|
#if defined(WEBRTC_IOS)
|
|
NSString *profile = MaxSupportedLevelForProfile(webrtc::H264::kProfileConstrainedBaseline);
|
|
if (profile != nil) {
|
|
return profile;
|
|
}
|
|
#endif
|
|
return kRTCLevel31ConstrainedBaseline;
|
|
}
|
|
|
|
NSString *MaxSupportedProfileLevelConstrainedHigh() {
|
|
#if defined(WEBRTC_IOS)
|
|
NSString *profile = MaxSupportedLevelForProfile(webrtc::H264::kProfileConstrainedHigh);
|
|
if (profile != nil) {
|
|
return profile;
|
|
}
|
|
#endif
|
|
return kRTCLevel31ConstrainedHigh;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
@implementation RTCVideoCodecInfo
|
|
|
|
@synthesize name = _name;
|
|
@synthesize parameters = _parameters;
|
|
|
|
- (instancetype)initWithName:(NSString *)name {
|
|
return [self initWithName:name parameters:nil];
|
|
}
|
|
|
|
- (instancetype)initWithName:(NSString *)name
|
|
parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters {
|
|
if (self = [super init]) {
|
|
_name = name;
|
|
_parameters = (parameters ? parameters : @{});
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithNativeSdpVideoFormat:(webrtc::SdpVideoFormat)format {
|
|
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
|
for (auto it = format.parameters.begin(); it != format.parameters.end(); ++it) {
|
|
[params setObject:[NSString stringForStdString:it->second]
|
|
forKey:[NSString stringForStdString:it->first]];
|
|
}
|
|
return [self initWithName:[NSString stringForStdString:format.name] parameters:params];
|
|
}
|
|
|
|
- (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info {
|
|
if (!info ||
|
|
![self.name isEqualToString:info.name] ||
|
|
![self.parameters isEqualToDictionary:info.parameters]) {
|
|
return NO;
|
|
}
|
|
return YES;
|
|
}
|
|
|
|
- (BOOL)isEqual:(id)object {
|
|
if (self == object)
|
|
return YES;
|
|
if (![object isKindOfClass:[self class]])
|
|
return NO;
|
|
return [self isEqualToCodecInfo:object];
|
|
}
|
|
|
|
- (NSUInteger)hash {
|
|
return [self.name hash] ^ [self.parameters hash];
|
|
}
|
|
|
|
- (webrtc::SdpVideoFormat)nativeSdpVideoFormat {
|
|
std::map<std::string, std::string> parameters;
|
|
for (NSString *paramKey in _parameters.allKeys) {
|
|
std::string key = [NSString stdStringForString:paramKey];
|
|
std::string value = [NSString stdStringForString:_parameters[paramKey]];
|
|
parameters[key] = value;
|
|
}
|
|
|
|
return webrtc::SdpVideoFormat([NSString stdStringForString:_name], parameters);
|
|
}
|
|
|
|
#pragma mark - NSCoding
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)decoder {
|
|
return [self initWithName:[decoder decodeObjectForKey:@"name"]
|
|
parameters:[decoder decodeObjectForKey:@"parameters"]];
|
|
}
|
|
|
|
- (void)encodeWithCoder:(NSCoder *)encoder {
|
|
[encoder encodeObject:_name forKey:@"name"];
|
|
[encoder encodeObject:_parameters forKey:@"parameters"];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation RTCVideoEncoderQpThresholds
|
|
|
|
@synthesize low = _low;
|
|
@synthesize high = _high;
|
|
|
|
- (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high {
|
|
if (self = [super init]) {
|
|
_low = low;
|
|
_high = high;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
@end
|