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