blob: b72296b64f31b0efb45a8bdda639b482afadbda0 [file] [log] [blame]
Anders Carlsson7e042812017-10-05 16:55:38 +02001/*
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
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020011#import "RTCDefaultVideoEncoderFactory.h"
Anders Carlsson7e042812017-10-05 16:55:38 +020012
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020013#import "RTCH264ProfileLevelId.h"
14#import "RTCVideoEncoderH264.h"
15#import "api/video_codec/RTCVideoCodecConstants.h"
16#import "api/video_codec/RTCVideoEncoderVP8.h"
17#import "base/RTCVideoCodecInfo.h"
Mirko Bonadei8ef57932018-11-16 14:38:03 +010018#if defined(RTC_ENABLE_VP9)
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020019#import "api/video_codec/RTCVideoEncoderVP9.h"
Anders Carlssondd8c1652018-01-30 10:32:13 +010020#endif
Anders Carlsson7e042812017-10-05 16:55:38 +020021
Anders Carlsson1d4c1522017-10-30 13:07:07 +010022@implementation RTCDefaultVideoEncoderFactory
Anders Carlsson7e042812017-10-05 16:55:38 +020023
Anders Carlsson6bf43d22017-10-16 13:51:43 +020024@synthesize preferredCodec;
25
Anders Carlsson1d4c1522017-10-30 13:07:07 +010026+ (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
27 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030028 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh,
Anders Carlsson1d4c1522017-10-30 13:07:07 +010029 @"level-asymmetry-allowed" : @"1",
30 @"packetization-mode" : @"1",
31 };
32 RTCVideoCodecInfo *constrainedHighInfo =
33 [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name
34 parameters:constrainedHighParams];
35
36 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030037 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline,
Anders Carlsson1d4c1522017-10-30 13:07:07 +010038 @"level-asymmetry-allowed" : @"1",
39 @"packetization-mode" : @"1",
40 };
41 RTCVideoCodecInfo *constrainedBaselineInfo =
42 [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name
43 parameters:constrainedBaselineParams];
44
45 RTCVideoCodecInfo *vp8Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name];
46
Mirko Bonadei8ef57932018-11-16 14:38:03 +010047#if defined(RTC_ENABLE_VP9)
Anders Carlsson1d4c1522017-10-30 13:07:07 +010048 RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name];
Kári Tristan Helgason9555e672017-12-01 14:27:07 +010049#endif
Anders Carlssondd8c1652018-01-30 10:32:13 +010050
51 return @[
52 constrainedHighInfo,
53 constrainedBaselineInfo,
Anders Carlssondd8c1652018-01-30 10:32:13 +010054 vp8Info,
Mirko Bonadei8ef57932018-11-16 14:38:03 +010055#if defined(RTC_ENABLE_VP9)
Anders Carlssondd8c1652018-01-30 10:32:13 +010056 vp9Info,
57#endif
Anders Carlssondd8c1652018-01-30 10:32:13 +010058 ];
Anders Carlsson1d4c1522017-10-30 13:07:07 +010059}
60
Anders Carlsson7e042812017-10-05 16:55:38 +020061- (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info {
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020062 if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020063 return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020064 } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020065 return [RTCVideoEncoderVP8 vp8Encoder];
Mirko Bonadei8ef57932018-11-16 14:38:03 +010066#if defined(RTC_ENABLE_VP9)
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020067 } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020068 return [RTCVideoEncoderVP9 vp9Encoder];
Kári Tristan Helgason9555e672017-12-01 14:27:07 +010069#endif
Anders Carlsson7e042812017-10-05 16:55:38 +020070 }
71
72 return nil;
73}
74
75- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
Anders Carlsson1d4c1522017-10-30 13:07:07 +010076 NSMutableArray<RTCVideoCodecInfo *> *codecs = [[[self class] supportedCodecs] mutableCopy];
Anders Carlsson7e042812017-10-05 16:55:38 +020077
Anders Carlsson6bf43d22017-10-16 13:51:43 +020078 NSMutableArray<RTCVideoCodecInfo *> *orderedCodecs = [NSMutableArray array];
79 NSUInteger index = [codecs indexOfObject:self.preferredCodec];
80 if (index != NSNotFound) {
81 [orderedCodecs addObject:[codecs objectAtIndex:index]];
82 [codecs removeObjectAtIndex:index];
83 }
84 [orderedCodecs addObjectsFromArray:codecs];
85
86 return [orderedCodecs copy];
Anders Carlsson7e042812017-10-05 16:55:38 +020087}
88
89@end