kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #import "WebRTC/RTCVideoCodec.h" |
| 12 | |
| 13 | #import "NSString+StdString.h" |
| 14 | #import "RTCVideoCodec+Private.h" |
| 15 | #import "WebRTC/RTCVideoCodecFactory.h" |
| 16 | |
| 17 | @implementation RTCVideoCodecInfo |
| 18 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 19 | @synthesize name = _name; |
| 20 | @synthesize parameters = _parameters; |
| 21 | |
Kári Tristan Helgason | e71f367 | 2017-10-02 14:59:59 +0200 | [diff] [blame] | 22 | - (instancetype)initWithName:(NSString *)name { |
| 23 | return [self initWithName:name parameters:nil]; |
| 24 | } |
| 25 | |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 26 | - (instancetype)initWithName:(NSString *)name |
| 27 | parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 28 | if (self = [super init]) { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 29 | _name = name; |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 30 | _parameters = (parameters ? parameters : @{}); |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | return self; |
| 34 | } |
| 35 | |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame^] | 36 | - (instancetype)initWithNativeSdpVideoFormat:(webrtc::SdpVideoFormat)format { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 37 | NSMutableDictionary *params = [NSMutableDictionary dictionary]; |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame^] | 38 | for (auto it = format.parameters.begin(); it != format.parameters.end(); ++it) { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 39 | [params setObject:[NSString stringForStdString:it->second] |
| 40 | forKey:[NSString stringForStdString:it->first]]; |
| 41 | } |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame^] | 42 | return [self initWithName:[NSString stringForStdString:format.name] parameters:params]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame^] | 45 | - (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec { |
| 46 | return [self |
| 47 | initWithNativeSdpVideoFormat:webrtc::SdpVideoFormat(videoCodec.name, videoCodec.params)]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Kári Tristan Helgason | 3935c34 | 2017-09-28 15:08:47 +0200 | [diff] [blame] | 50 | - (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info { |
| 51 | if (!info || |
Kári Tristan Helgason | 3935c34 | 2017-09-28 15:08:47 +0200 | [diff] [blame] | 52 | ![self.name isEqualToString:info.name] || |
| 53 | ![self.parameters isEqualToDictionary:info.parameters]) { |
| 54 | return NO; |
| 55 | } |
| 56 | return YES; |
| 57 | } |
| 58 | |
| 59 | - (BOOL)isEqual:(id)object { |
| 60 | if (self == object) |
| 61 | return YES; |
| 62 | if (![object isKindOfClass:[self class]]) |
| 63 | return NO; |
| 64 | return [self isEqualToCodecInfo:object]; |
| 65 | } |
| 66 | |
| 67 | - (NSUInteger)hash { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame^] | 68 | return [self.name hash] ^ [self.parameters hash]; |
| 69 | } |
| 70 | |
| 71 | - (webrtc::SdpVideoFormat)nativeSdpVideoFormat { |
| 72 | std::map<std::string, std::string> parameters; |
| 73 | for (NSString *paramKey in _parameters.allKeys) { |
| 74 | std::string key = [NSString stdStringForString:paramKey]; |
| 75 | std::string value = [NSString stdStringForString:_parameters[paramKey]]; |
| 76 | parameters[key] = value; |
| 77 | } |
| 78 | |
| 79 | return webrtc::SdpVideoFormat([NSString stdStringForString:_name], parameters); |
| 80 | } |
| 81 | |
| 82 | - (cricket::VideoCodec)nativeVideoCodec { |
| 83 | cricket::VideoCodec codec([NSString stdStringForString:_name]); |
| 84 | for (NSString *paramKey in _parameters.allKeys) { |
| 85 | codec.SetParam([NSString stdStringForString:paramKey], |
| 86 | [NSString stdStringForString:_parameters[paramKey]]); |
| 87 | } |
| 88 | |
| 89 | return codec; |
Kári Tristan Helgason | 3935c34 | 2017-09-28 15:08:47 +0200 | [diff] [blame] | 90 | } |
| 91 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 92 | @end |
magjed | 5dfac33 | 2017-08-01 08:07:59 -0700 | [diff] [blame] | 93 | |
| 94 | @implementation RTCVideoEncoderQpThresholds |
| 95 | |
| 96 | @synthesize low = _low; |
| 97 | @synthesize high = _high; |
| 98 | |
| 99 | - (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high { |
| 100 | if (self = [super init]) { |
| 101 | _low = low; |
| 102 | _high = high; |
| 103 | } |
| 104 | return self; |
| 105 | } |
| 106 | |
| 107 | @end |