blob: f862453b5f84e7e2d21d5f271cccecdffd5e81d3 [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"
19#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
20#include "system_wrappers/include/field_trial.h"
kthelgasonfb143122017-07-25 07:55:58 -070021
kthelgasonfb143122017-07-25 07:55:58 -070022const char kHighProfileExperiment[] = "WebRTC-H264HighProfile";
magjed5dfac332017-08-01 08:07:59 -070023
kthelgasonfb143122017-07-25 07:55:58 -070024bool IsHighProfileEnabled() {
25 return webrtc::field_trial::IsEnabled(kHighProfileExperiment);
26}
27
28// H264 specific settings.
29@implementation RTCCodecSpecificInfoH264
30
31@synthesize packetizationMode = _packetizationMode;
32
magjed8eab09c2017-07-31 02:56:35 -070033- (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo {
kthelgasonfb143122017-07-25 07:55:58 -070034 webrtc::CodecSpecificInfo codecSpecificInfo;
35 codecSpecificInfo.codecType = webrtc::kVideoCodecH264;
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020036 codecSpecificInfo.codec_name = [kRTCVideoCodecH264Name cStringUsingEncoding:NSUTF8StringEncoding];
kthelgasonfb143122017-07-25 07:55:58 -070037 codecSpecificInfo.codecSpecific.H264.packetization_mode =
38 (webrtc::H264PacketizationMode)_packetizationMode;
39
40 return codecSpecificInfo;
41}
42
43@end
44
kthelgasonfb143122017-07-25 07:55:58 -070045// Encoder factory.
46@implementation RTCVideoEncoderFactoryH264
47
48- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
49 NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array];
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020050 NSString *codecName = kRTCVideoCodecH264Name;
kthelgasonfb143122017-07-25 07:55:58 -070051
52 if (IsHighProfileEnabled()) {
53 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020054 @"profile-level-id" : kRTCLevel31ConstrainedHigh,
kthelgasonfb143122017-07-25 07:55:58 -070055 @"level-asymmetry-allowed" : @"1",
56 @"packetization-mode" : @"1",
57 };
58 RTCVideoCodecInfo *constrainedHighInfo =
andersc81bc5232017-08-18 06:34:09 -070059 [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedHighParams];
kthelgasonfb143122017-07-25 07:55:58 -070060 [codecs addObject:constrainedHighInfo];
61 }
62
63 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020064 @"profile-level-id" : kRTCLevel31ConstrainedBaseline,
kthelgasonfb143122017-07-25 07:55:58 -070065 @"level-asymmetry-allowed" : @"1",
66 @"packetization-mode" : @"1",
67 };
68 RTCVideoCodecInfo *constrainedBaselineInfo =
andersc81bc5232017-08-18 06:34:09 -070069 [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedBaselineParams];
kthelgasonfb143122017-07-25 07:55:58 -070070 [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 Helgasonfc313dc2017-10-20 11:01:22 +020089 NSString *codecName = kRTCVideoCodecH264Name;
andersc81bc5232017-08-18 06:34:09 -070090 return @[ [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:nil] ];
kthelgasonfb143122017-07-25 07:55:58 -070091}
92
93@end