blob: 4a5d45062ae8de515ee2d58a87e94311cda4a2b8 [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
VladimirTechMan80adac02017-11-23 12:22:11 -050017#include "media/base/mediaconstants.h"
18
19NSString *const kRTCVideoCodecVp8Name = @(cricket::kVp8CodecName);
20NSString *const kRTCVideoCodecVp9Name = @(cricket::kVp9CodecName);
21NSString *const kRTCVideoCodecH264Name = @(cricket::kH264CodecName);
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020022NSString *const kRTCLevel31ConstrainedHigh = @"640c1f";
23NSString *const kRTCLevel31ConstrainedBaseline = @"42e01f";
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020024
kthelgasonfb143122017-07-25 07:55:58 -070025@implementation RTCVideoCodecInfo
26
kthelgasonfb143122017-07-25 07:55:58 -070027@synthesize name = _name;
28@synthesize parameters = _parameters;
29
Kári Tristan Helgasone71f3672017-10-02 14:59:59 +020030- (instancetype)initWithName:(NSString *)name {
31 return [self initWithName:name parameters:nil];
32}
33
andersc81bc5232017-08-18 06:34:09 -070034- (instancetype)initWithName:(NSString *)name
35 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters {
kthelgasonfb143122017-07-25 07:55:58 -070036 if (self = [super init]) {
kthelgasonfb143122017-07-25 07:55:58 -070037 _name = name;
andersc81bc5232017-08-18 06:34:09 -070038 _parameters = (parameters ? parameters : @{});
kthelgasonfb143122017-07-25 07:55:58 -070039 }
40
41 return self;
42}
43
Anders Carlsson7e042812017-10-05 16:55:38 +020044- (instancetype)initWithNativeSdpVideoFormat:(webrtc::SdpVideoFormat)format {
kthelgasonfb143122017-07-25 07:55:58 -070045 NSMutableDictionary *params = [NSMutableDictionary dictionary];
Anders Carlsson7e042812017-10-05 16:55:38 +020046 for (auto it = format.parameters.begin(); it != format.parameters.end(); ++it) {
kthelgasonfb143122017-07-25 07:55:58 -070047 [params setObject:[NSString stringForStdString:it->second]
48 forKey:[NSString stringForStdString:it->first]];
49 }
Anders Carlsson7e042812017-10-05 16:55:38 +020050 return [self initWithName:[NSString stringForStdString:format.name] parameters:params];
kthelgasonfb143122017-07-25 07:55:58 -070051}
52
Anders Carlsson7e042812017-10-05 16:55:38 +020053- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec {
54 return [self
55 initWithNativeSdpVideoFormat:webrtc::SdpVideoFormat(videoCodec.name, videoCodec.params)];
kthelgasonfb143122017-07-25 07:55:58 -070056}
57
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020058- (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info {
59 if (!info ||
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020060 ![self.name isEqualToString:info.name] ||
61 ![self.parameters isEqualToDictionary:info.parameters]) {
62 return NO;
63 }
64 return YES;
65}
66
67- (BOOL)isEqual:(id)object {
68 if (self == object)
69 return YES;
70 if (![object isKindOfClass:[self class]])
71 return NO;
72 return [self isEqualToCodecInfo:object];
73}
74
75- (NSUInteger)hash {
Anders Carlsson7e042812017-10-05 16:55:38 +020076 return [self.name hash] ^ [self.parameters hash];
77}
78
79- (webrtc::SdpVideoFormat)nativeSdpVideoFormat {
80 std::map<std::string, std::string> parameters;
81 for (NSString *paramKey in _parameters.allKeys) {
82 std::string key = [NSString stdStringForString:paramKey];
83 std::string value = [NSString stdStringForString:_parameters[paramKey]];
84 parameters[key] = value;
85 }
86
87 return webrtc::SdpVideoFormat([NSString stdStringForString:_name], parameters);
88}
89
90- (cricket::VideoCodec)nativeVideoCodec {
91 cricket::VideoCodec codec([NSString stdStringForString:_name]);
92 for (NSString *paramKey in _parameters.allKeys) {
93 codec.SetParam([NSString stdStringForString:paramKey],
94 [NSString stdStringForString:_parameters[paramKey]]);
95 }
96
97 return codec;
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020098}
99
Anders Carlsson6bf43d22017-10-16 13:51:43 +0200100#pragma mark - NSCoding
101
102- (instancetype)initWithCoder:(NSCoder *)decoder {
103 return [self initWithName:[decoder decodeObjectForKey:@"name"]
104 parameters:[decoder decodeObjectForKey:@"parameters"]];
105}
106
107- (void)encodeWithCoder:(NSCoder *)encoder {
108 [encoder encodeObject:_name forKey:@"name"];
109 [encoder encodeObject:_parameters forKey:@"parameters"];
110}
111
kthelgasonfb143122017-07-25 07:55:58 -0700112@end
magjed5dfac332017-08-01 08:07:59 -0700113
114@implementation RTCVideoEncoderQpThresholds
115
116@synthesize low = _low;
117@synthesize high = _high;
118
119- (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high {
120 if (self = [super init]) {
121 _low = low;
122 _high = high;
123 }
124 return self;
125}
126
127@end