kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 1 | /* |
| 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" |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/timeutils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "system_wrappers/include/field_trial.h" |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 20 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 21 | const char kHighProfileExperiment[] = "WebRTC-H264HighProfile"; |
magjed | 5dfac33 | 2017-08-01 08:07:59 -0700 | [diff] [blame] | 22 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 23 | bool IsHighProfileEnabled() { |
| 24 | return webrtc::field_trial::IsEnabled(kHighProfileExperiment); |
| 25 | } |
| 26 | |
| 27 | // H264 specific settings. |
| 28 | @implementation RTCCodecSpecificInfoH264 |
| 29 | |
| 30 | @synthesize packetizationMode = _packetizationMode; |
| 31 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 32 | - (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 33 | webrtc::CodecSpecificInfo codecSpecificInfo; |
| 34 | codecSpecificInfo.codecType = webrtc::kVideoCodecH264; |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 35 | codecSpecificInfo.codec_name = [kRTCVideoCodecH264Name cStringUsingEncoding:NSUTF8StringEncoding]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 36 | codecSpecificInfo.codecSpecific.H264.packetization_mode = |
| 37 | (webrtc::H264PacketizationMode)_packetizationMode; |
| 38 | |
| 39 | return codecSpecificInfo; |
| 40 | } |
| 41 | |
| 42 | @end |
| 43 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 44 | // Encoder factory. |
| 45 | @implementation RTCVideoEncoderFactoryH264 |
| 46 | |
| 47 | - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 48 | NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array]; |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 49 | NSString *codecName = kRTCVideoCodecH264Name; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 50 | |
| 51 | if (IsHighProfileEnabled()) { |
| 52 | NSDictionary<NSString *, NSString *> *constrainedHighParams = @{ |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 53 | @"profile-level-id" : kRTCLevel31ConstrainedHigh, |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 54 | @"level-asymmetry-allowed" : @"1", |
| 55 | @"packetization-mode" : @"1", |
| 56 | }; |
| 57 | RTCVideoCodecInfo *constrainedHighInfo = |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 58 | [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedHighParams]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 59 | [codecs addObject:constrainedHighInfo]; |
| 60 | } |
| 61 | |
| 62 | NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{ |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 63 | @"profile-level-id" : kRTCLevel31ConstrainedBaseline, |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 64 | @"level-asymmetry-allowed" : @"1", |
| 65 | @"packetization-mode" : @"1", |
| 66 | }; |
| 67 | RTCVideoCodecInfo *constrainedBaselineInfo = |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 68 | [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedBaselineParams]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 69 | [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 Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 88 | NSString *codecName = kRTCVideoCodecH264Name; |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 89 | return @[ [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:nil] ]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @end |