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 | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 23 | static NSString *kLevel31ConstrainedHigh = @"640c1f"; |
| 24 | static NSString *kLevel31ConstrainedBaseline = @"42e01f"; |
magjed | 5dfac33 | 2017-08-01 08:07:59 -0700 | [diff] [blame] | 25 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 26 | bool IsHighProfileEnabled() { |
| 27 | return webrtc::field_trial::IsEnabled(kHighProfileExperiment); |
| 28 | } |
| 29 | |
| 30 | // H264 specific settings. |
| 31 | @implementation RTCCodecSpecificInfoH264 |
| 32 | |
| 33 | @synthesize packetizationMode = _packetizationMode; |
| 34 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 35 | - (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 36 | webrtc::CodecSpecificInfo codecSpecificInfo; |
| 37 | codecSpecificInfo.codecType = webrtc::kVideoCodecH264; |
| 38 | codecSpecificInfo.codec_name = "H264"; |
| 39 | codecSpecificInfo.codecSpecific.H264.packetization_mode = |
| 40 | (webrtc::H264PacketizationMode)_packetizationMode; |
| 41 | |
| 42 | return codecSpecificInfo; |
| 43 | } |
| 44 | |
| 45 | @end |
| 46 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 47 | // Encoder factory. |
| 48 | @implementation RTCVideoEncoderFactoryH264 |
| 49 | |
| 50 | - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 51 | NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array]; |
| 52 | NSString *codecName = [NSString stringWithUTF8String:cricket::kH264CodecName]; |
| 53 | |
| 54 | if (IsHighProfileEnabled()) { |
| 55 | NSDictionary<NSString *, NSString *> *constrainedHighParams = @{ |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 56 | @"profile-level-id" : kLevel31ConstrainedHigh, |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 57 | @"level-asymmetry-allowed" : @"1", |
| 58 | @"packetization-mode" : @"1", |
| 59 | }; |
| 60 | RTCVideoCodecInfo *constrainedHighInfo = |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 61 | [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedHighParams]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 62 | [codecs addObject:constrainedHighInfo]; |
| 63 | } |
| 64 | |
| 65 | NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{ |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 66 | @"profile-level-id" : kLevel31ConstrainedBaseline, |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 67 | @"level-asymmetry-allowed" : @"1", |
| 68 | @"packetization-mode" : @"1", |
| 69 | }; |
| 70 | RTCVideoCodecInfo *constrainedBaselineInfo = |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 71 | [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedBaselineParams]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 72 | [codecs addObject:constrainedBaselineInfo]; |
| 73 | |
| 74 | return [codecs copy]; |
| 75 | } |
| 76 | |
| 77 | - (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info { |
| 78 | return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info]; |
| 79 | } |
| 80 | |
| 81 | @end |
| 82 | |
| 83 | // Decoder factory. |
| 84 | @implementation RTCVideoDecoderFactoryH264 |
| 85 | |
| 86 | - (id<RTCVideoDecoder>)createDecoder:(RTCVideoCodecInfo *)info { |
| 87 | return [[RTCVideoDecoderH264 alloc] init]; |
| 88 | } |
| 89 | |
| 90 | - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 91 | NSString *codecName = [NSString stringWithUTF8String:cricket::kH264CodecName]; |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 92 | return @[ [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:nil] ]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @end |