blob: 1a09fe158bfdc140aeada5626ece5455c042cbcd [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";
magjed73c0eb52017-08-07 06:55:28 -070023static NSString *kLevel31ConstrainedHigh = @"640c1f";
24static NSString *kLevel31ConstrainedBaseline = @"42e01f";
magjed5dfac332017-08-01 08:07:59 -070025
kthelgasonfb143122017-07-25 07:55:58 -070026bool IsHighProfileEnabled() {
27 return webrtc::field_trial::IsEnabled(kHighProfileExperiment);
28}
29
30// H264 specific settings.
31@implementation RTCCodecSpecificInfoH264
32
33@synthesize packetizationMode = _packetizationMode;
34
magjed8eab09c2017-07-31 02:56:35 -070035- (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo {
kthelgasonfb143122017-07-25 07:55:58 -070036 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
kthelgasonfb143122017-07-25 07:55:58 -070047// 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 = @{
magjed73c0eb52017-08-07 06:55:28 -070056 @"profile-level-id" : kLevel31ConstrainedHigh,
kthelgasonfb143122017-07-25 07:55:58 -070057 @"level-asymmetry-allowed" : @"1",
58 @"packetization-mode" : @"1",
59 };
60 RTCVideoCodecInfo *constrainedHighInfo =
andersc81bc5232017-08-18 06:34:09 -070061 [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedHighParams];
kthelgasonfb143122017-07-25 07:55:58 -070062 [codecs addObject:constrainedHighInfo];
63 }
64
65 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
magjed73c0eb52017-08-07 06:55:28 -070066 @"profile-level-id" : kLevel31ConstrainedBaseline,
kthelgasonfb143122017-07-25 07:55:58 -070067 @"level-asymmetry-allowed" : @"1",
68 @"packetization-mode" : @"1",
69 };
70 RTCVideoCodecInfo *constrainedBaselineInfo =
andersc81bc5232017-08-18 06:34:09 -070071 [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:constrainedBaselineParams];
kthelgasonfb143122017-07-25 07:55:58 -070072 [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];
andersc81bc5232017-08-18 06:34:09 -070092 return @[ [[RTCVideoCodecInfo alloc] initWithName:codecName parameters:nil] ];
kthelgasonfb143122017-07-25 07:55:58 -070093}
94
95@end