blob: 8886209fa1c6b594c18b54ed95699d258e3af9eb [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
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020017NSString *const kRTCVideoCodecVp8Name = @"VP8";
18NSString *const kRTCVideoCodecVp9Name = @"VP9";
19NSString *const kRTCVideoCodecH264Name = @"H264";
20NSString *const kRTCLevel31ConstrainedHigh = @"640c1f";
21NSString *const kRTCLevel31ConstrainedBaseline = @"42e01f";
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020022
kthelgasonfb143122017-07-25 07:55:58 -070023@implementation RTCVideoCodecInfo
24
kthelgasonfb143122017-07-25 07:55:58 -070025@synthesize name = _name;
26@synthesize parameters = _parameters;
27
Kári Tristan Helgasone71f3672017-10-02 14:59:59 +020028- (instancetype)initWithName:(NSString *)name {
29 return [self initWithName:name parameters:nil];
30}
31
andersc81bc5232017-08-18 06:34:09 -070032- (instancetype)initWithName:(NSString *)name
33 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters {
kthelgasonfb143122017-07-25 07:55:58 -070034 if (self = [super init]) {
kthelgasonfb143122017-07-25 07:55:58 -070035 _name = name;
andersc81bc5232017-08-18 06:34:09 -070036 _parameters = (parameters ? parameters : @{});
kthelgasonfb143122017-07-25 07:55:58 -070037 }
38
39 return self;
40}
41
Anders Carlsson7e042812017-10-05 16:55:38 +020042- (instancetype)initWithNativeSdpVideoFormat:(webrtc::SdpVideoFormat)format {
kthelgasonfb143122017-07-25 07:55:58 -070043 NSMutableDictionary *params = [NSMutableDictionary dictionary];
Anders Carlsson7e042812017-10-05 16:55:38 +020044 for (auto it = format.parameters.begin(); it != format.parameters.end(); ++it) {
kthelgasonfb143122017-07-25 07:55:58 -070045 [params setObject:[NSString stringForStdString:it->second]
46 forKey:[NSString stringForStdString:it->first]];
47 }
Anders Carlsson7e042812017-10-05 16:55:38 +020048 return [self initWithName:[NSString stringForStdString:format.name] parameters:params];
kthelgasonfb143122017-07-25 07:55:58 -070049}
50
Anders Carlsson7e042812017-10-05 16:55:38 +020051- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec {
52 return [self
53 initWithNativeSdpVideoFormat:webrtc::SdpVideoFormat(videoCodec.name, videoCodec.params)];
kthelgasonfb143122017-07-25 07:55:58 -070054}
55
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020056- (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info {
57 if (!info ||
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020058 ![self.name isEqualToString:info.name] ||
59 ![self.parameters isEqualToDictionary:info.parameters]) {
60 return NO;
61 }
62 return YES;
63}
64
65- (BOOL)isEqual:(id)object {
66 if (self == object)
67 return YES;
68 if (![object isKindOfClass:[self class]])
69 return NO;
70 return [self isEqualToCodecInfo:object];
71}
72
73- (NSUInteger)hash {
Anders Carlsson7e042812017-10-05 16:55:38 +020074 return [self.name hash] ^ [self.parameters hash];
75}
76
77- (webrtc::SdpVideoFormat)nativeSdpVideoFormat {
78 std::map<std::string, std::string> parameters;
79 for (NSString *paramKey in _parameters.allKeys) {
80 std::string key = [NSString stdStringForString:paramKey];
81 std::string value = [NSString stdStringForString:_parameters[paramKey]];
82 parameters[key] = value;
83 }
84
85 return webrtc::SdpVideoFormat([NSString stdStringForString:_name], parameters);
86}
87
88- (cricket::VideoCodec)nativeVideoCodec {
89 cricket::VideoCodec codec([NSString stdStringForString:_name]);
90 for (NSString *paramKey in _parameters.allKeys) {
91 codec.SetParam([NSString stdStringForString:paramKey],
92 [NSString stdStringForString:_parameters[paramKey]]);
93 }
94
95 return codec;
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020096}
97
Anders Carlsson6bf43d22017-10-16 13:51:43 +020098#pragma mark - NSCoding
99
100- (instancetype)initWithCoder:(NSCoder *)decoder {
101 return [self initWithName:[decoder decodeObjectForKey:@"name"]
102 parameters:[decoder decodeObjectForKey:@"parameters"]];
103}
104
105- (void)encodeWithCoder:(NSCoder *)encoder {
106 [encoder encodeObject:_name forKey:@"name"];
107 [encoder encodeObject:_parameters forKey:@"parameters"];
108}
109
kthelgasonfb143122017-07-25 07:55:58 -0700110@end
magjed5dfac332017-08-01 08:07:59 -0700111
112@implementation RTCVideoEncoderQpThresholds
113
114@synthesize low = _low;
115@synthesize high = _high;
116
117- (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high {
118 if (self = [super init]) {
119 _low = low;
120 _high = high;
121 }
122 return self;
123}
124
125@end