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 | |
| 19 | @synthesize payload = _payload; |
| 20 | @synthesize name = _name; |
| 21 | @synthesize parameters = _parameters; |
| 22 | |
Kári Tristan Helgason | e71f367 | 2017-10-02 14:59:59 +0200 | [diff] [blame^] | 23 | - (instancetype)initWithName:(NSString *)name { |
| 24 | return [self initWithName:name parameters:nil]; |
| 25 | } |
| 26 | |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 27 | - (instancetype)initWithName:(NSString *)name |
| 28 | parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 29 | if (self = [super init]) { |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 30 | _payload = 0; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 31 | _name = name; |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 32 | _parameters = (parameters ? parameters : @{}); |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | return self; |
| 36 | } |
| 37 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 38 | - (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 39 | NSMutableDictionary *params = [NSMutableDictionary dictionary]; |
| 40 | for (auto it = videoCodec.params.begin(); it != videoCodec.params.end(); ++it) { |
| 41 | [params setObject:[NSString stringForStdString:it->second] |
| 42 | forKey:[NSString stringForStdString:it->first]]; |
| 43 | } |
| 44 | return [self initWithPayload:videoCodec.id |
| 45 | name:[NSString stringForStdString:videoCodec.name] |
| 46 | parameters:params]; |
| 47 | } |
| 48 | |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 49 | - (instancetype)initWithPayload:(NSInteger)payload |
| 50 | name:(NSString *)name |
| 51 | parameters:(NSDictionary<NSString *, NSString *> *)parameters { |
| 52 | if (self = [self initWithName:name parameters:parameters]) { |
| 53 | _payload = payload; |
| 54 | } |
| 55 | |
| 56 | return self; |
| 57 | } |
| 58 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 59 | - (cricket::VideoCodec)nativeVideoCodec { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 60 | cricket::VideoCodec codec([NSString stdStringForString:_name]); |
| 61 | for (NSString *paramKey in _parameters.allKeys) { |
| 62 | codec.SetParam([NSString stdStringForString:paramKey], |
| 63 | [NSString stdStringForString:_parameters[paramKey]]); |
| 64 | } |
| 65 | |
| 66 | return codec; |
| 67 | } |
| 68 | |
Kári Tristan Helgason | 3935c34 | 2017-09-28 15:08:47 +0200 | [diff] [blame] | 69 | - (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info { |
| 70 | if (!info || |
| 71 | self.payload != info.payload || |
| 72 | ![self.name isEqualToString:info.name] || |
| 73 | ![self.parameters isEqualToDictionary:info.parameters]) { |
| 74 | return NO; |
| 75 | } |
| 76 | return YES; |
| 77 | } |
| 78 | |
| 79 | - (BOOL)isEqual:(id)object { |
| 80 | if (self == object) |
| 81 | return YES; |
| 82 | if (![object isKindOfClass:[self class]]) |
| 83 | return NO; |
| 84 | return [self isEqualToCodecInfo:object]; |
| 85 | } |
| 86 | |
| 87 | - (NSUInteger)hash { |
| 88 | return [self.name hash] ^ self.payload ^ [self.parameters hash]; |
| 89 | } |
| 90 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 91 | @end |
magjed | 5dfac33 | 2017-08-01 08:07:59 -0700 | [diff] [blame] | 92 | |
| 93 | @implementation RTCVideoEncoderQpThresholds |
| 94 | |
| 95 | @synthesize low = _low; |
| 96 | @synthesize high = _high; |
| 97 | |
| 98 | - (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high { |
| 99 | if (self = [super init]) { |
| 100 | _low = low; |
| 101 | _high = high; |
| 102 | } |
| 103 | return self; |
| 104 | } |
| 105 | |
| 106 | @end |