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" |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 19 | |
| 20 | // H264 specific settings. |
| 21 | @implementation RTCCodecSpecificInfoH264 |
| 22 | |
| 23 | @synthesize packetizationMode = _packetizationMode; |
| 24 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 25 | - (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 26 | webrtc::CodecSpecificInfo codecSpecificInfo; |
| 27 | codecSpecificInfo.codecType = webrtc::kVideoCodecH264; |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 28 | codecSpecificInfo.codec_name = [kRTCVideoCodecH264Name cStringUsingEncoding:NSUTF8StringEncoding]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 29 | codecSpecificInfo.codecSpecific.H264.packetization_mode = |
| 30 | (webrtc::H264PacketizationMode)_packetizationMode; |
| 31 | |
| 32 | return codecSpecificInfo; |
| 33 | } |
| 34 | |
| 35 | @end |
| 36 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 37 | // Encoder factory. |
| 38 | @implementation RTCVideoEncoderFactoryH264 |
| 39 | |
| 40 | - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 41 | NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array]; |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 42 | NSString *codecName = kRTCVideoCodecH264Name; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 43 | |
Kári Tristan Helgason | cad9444 | 2018-05-02 10:29:12 +0200 | [diff] [blame] | 44 | NSDictionary<NSString *, NSString *> *constrainedHighParams = @{ |
| 45 | @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh, |
| 46 | @"level-asymmetry-allowed" : @"1", |
| 47 | @"packetization-mode" : @"1", |
| 48 | }; |
| 49 | RTCVideoCodecInfo *constrainedHighInfo = |
| 50 | [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedHighParams]; |
| 51 | [codecs addObject:constrainedHighInfo]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 52 | |
| 53 | NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{ |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 54 | @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline, |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 55 | @"level-asymmetry-allowed" : @"1", |
| 56 | @"packetization-mode" : @"1", |
| 57 | }; |
| 58 | RTCVideoCodecInfo *constrainedBaselineInfo = |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 59 | [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedBaselineParams]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 60 | [codecs addObject:constrainedBaselineInfo]; |
| 61 | |
| 62 | return [codecs copy]; |
| 63 | } |
| 64 | |
| 65 | - (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info { |
| 66 | return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info]; |
| 67 | } |
| 68 | |
| 69 | @end |
| 70 | |
| 71 | // Decoder factory. |
| 72 | @implementation RTCVideoDecoderFactoryH264 |
| 73 | |
| 74 | - (id<RTCVideoDecoder>)createDecoder:(RTCVideoCodecInfo *)info { |
| 75 | return [[RTCVideoDecoderH264 alloc] init]; |
| 76 | } |
| 77 | |
| 78 | - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 79 | NSString *codecName = kRTCVideoCodecH264Name; |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 80 | return @[ [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:nil] ]; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @end |