blob: df5946df81d1e7d20e0336f9ff9f850c055d083d [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
kthelgasonfb143122017-07-25 07:55:58 -070019@synthesize name = _name;
20@synthesize parameters = _parameters;
21
Kári Tristan Helgasone71f3672017-10-02 14:59:59 +020022- (instancetype)initWithName:(NSString *)name {
23 return [self initWithName:name parameters:nil];
24}
25
andersc81bc5232017-08-18 06:34:09 -070026- (instancetype)initWithName:(NSString *)name
27 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters {
kthelgasonfb143122017-07-25 07:55:58 -070028 if (self = [super init]) {
kthelgasonfb143122017-07-25 07:55:58 -070029 _name = name;
andersc81bc5232017-08-18 06:34:09 -070030 _parameters = (parameters ? parameters : @{});
kthelgasonfb143122017-07-25 07:55:58 -070031 }
32
33 return self;
34}
35
Anders Carlsson7e042812017-10-05 16:55:38 +020036- (instancetype)initWithNativeSdpVideoFormat:(webrtc::SdpVideoFormat)format {
kthelgasonfb143122017-07-25 07:55:58 -070037 NSMutableDictionary *params = [NSMutableDictionary dictionary];
Anders Carlsson7e042812017-10-05 16:55:38 +020038 for (auto it = format.parameters.begin(); it != format.parameters.end(); ++it) {
kthelgasonfb143122017-07-25 07:55:58 -070039 [params setObject:[NSString stringForStdString:it->second]
40 forKey:[NSString stringForStdString:it->first]];
41 }
Anders Carlsson7e042812017-10-05 16:55:38 +020042 return [self initWithName:[NSString stringForStdString:format.name] parameters:params];
kthelgasonfb143122017-07-25 07:55:58 -070043}
44
Anders Carlsson7e042812017-10-05 16:55:38 +020045- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec {
46 return [self
47 initWithNativeSdpVideoFormat:webrtc::SdpVideoFormat(videoCodec.name, videoCodec.params)];
kthelgasonfb143122017-07-25 07:55:58 -070048}
49
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020050- (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info {
51 if (!info ||
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020052 ![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 Carlsson7e042812017-10-05 16:55:38 +020068 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 Helgason3935c342017-09-28 15:08:47 +020090}
91
kthelgasonfb143122017-07-25 07:55:58 -070092@end
magjed5dfac332017-08-01 08:07:59 -070093
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