blob: 5477791e04f6632ae8ac9aa87db6832a47ac995f [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/RTCVideoCodecH264.h"
12
13#include <vector>
14
15#import "RTCVideoCodec+Private.h"
16#import "WebRTC/RTCVideoCodec.h"
kthelgasonfb143122017-07-25 07:55:58 -070017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/timeutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "system_wrappers/include/field_trial.h"
kthelgasonfb143122017-07-25 07:55:58 -070020
kthelgasonfb143122017-07-25 07:55:58 -070021const char kHighProfileExperiment[] = "WebRTC-H264HighProfile";
magjed5dfac332017-08-01 08:07:59 -070022
kthelgasonfb143122017-07-25 07:55:58 -070023bool IsHighProfileEnabled() {
24 return webrtc::field_trial::IsEnabled(kHighProfileExperiment);
25}
26
27// H264 specific settings.
28@implementation RTCCodecSpecificInfoH264
29
30@synthesize packetizationMode = _packetizationMode;
31
magjed8eab09c2017-07-31 02:56:35 -070032- (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo {
kthelgasonfb143122017-07-25 07:55:58 -070033 webrtc::CodecSpecificInfo codecSpecificInfo;
34 codecSpecificInfo.codecType = webrtc::kVideoCodecH264;
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020035 codecSpecificInfo.codec_name = [kRTCVideoCodecH264Name cStringUsingEncoding:NSUTF8StringEncoding];
kthelgasonfb143122017-07-25 07:55:58 -070036 codecSpecificInfo.codecSpecific.H264.packetization_mode =
37 (webrtc::H264PacketizationMode)_packetizationMode;
38
39 return codecSpecificInfo;
40}
41
42@end
43
kthelgasonfb143122017-07-25 07:55:58 -070044// Encoder factory.
45@implementation RTCVideoEncoderFactoryH264
46
47- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
48 NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array];
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020049 NSString *codecName = kRTCVideoCodecH264Name;
kthelgasonfb143122017-07-25 07:55:58 -070050
51 if (IsHighProfileEnabled()) {
52 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030053 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh,
kthelgasonfb143122017-07-25 07:55:58 -070054 @"level-asymmetry-allowed" : @"1",
55 @"packetization-mode" : @"1",
56 };
57 RTCVideoCodecInfo *constrainedHighInfo =
andersc81bc5232017-08-18 06:34:09 -070058 [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedHighParams];
kthelgasonfb143122017-07-25 07:55:58 -070059 [codecs addObject:constrainedHighInfo];
60 }
61
62 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030063 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline,
kthelgasonfb143122017-07-25 07:55:58 -070064 @"level-asymmetry-allowed" : @"1",
65 @"packetization-mode" : @"1",
66 };
67 RTCVideoCodecInfo *constrainedBaselineInfo =
andersc81bc5232017-08-18 06:34:09 -070068 [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedBaselineParams];
kthelgasonfb143122017-07-25 07:55:58 -070069 [codecs addObject:constrainedBaselineInfo];
70
71 return [codecs copy];
72}
73
74- (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info {
75 return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
76}
77
78@end
79
80// Decoder factory.
81@implementation RTCVideoDecoderFactoryH264
82
83- (id<RTCVideoDecoder>)createDecoder:(RTCVideoCodecInfo *)info {
84 return [[RTCVideoDecoderH264 alloc] init];
85}
86
87- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020088 NSString *codecName = kRTCVideoCodecH264Name;
andersc81bc5232017-08-18 06:34:09 -070089 return @[ [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:nil] ];
kthelgasonfb143122017-07-25 07:55:58 -070090}
91
92@end