blob: 3e4c3162a1d4bfe1ea811c5a9feabd6f7f95043d [file] [log] [blame]
kthelgasonfb143122017-07-25 07:55:58 -07001/*
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 Helgasone71f3672017-10-02 14:59:59 +020023- (instancetype)initWithName:(NSString *)name {
24 return [self initWithName:name parameters:nil];
25}
26
andersc81bc5232017-08-18 06:34:09 -070027- (instancetype)initWithName:(NSString *)name
28 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters {
kthelgasonfb143122017-07-25 07:55:58 -070029 if (self = [super init]) {
andersc81bc5232017-08-18 06:34:09 -070030 _payload = 0;
kthelgasonfb143122017-07-25 07:55:58 -070031 _name = name;
andersc81bc5232017-08-18 06:34:09 -070032 _parameters = (parameters ? parameters : @{});
kthelgasonfb143122017-07-25 07:55:58 -070033 }
34
35 return self;
36}
37
magjed8eab09c2017-07-31 02:56:35 -070038- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec {
kthelgasonfb143122017-07-25 07:55:58 -070039 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
andersc81bc5232017-08-18 06:34:09 -070049- (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
magjed8eab09c2017-07-31 02:56:35 -070059- (cricket::VideoCodec)nativeVideoCodec {
kthelgasonfb143122017-07-25 07:55:58 -070060 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 Helgason3935c342017-09-28 15:08:47 +020069- (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
kthelgasonfb143122017-07-25 07:55:58 -070091@end
magjed5dfac332017-08-01 08:07:59 -070092
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