blob: b1163c4ff876ac03a18fe69ce8f8217ff8e06737 [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
11#import "ARDVideoEncoderFactory.h"
12
Anders Carlsson6bf43d22017-10-16 13:51:43 +020013#import "ARDSettingsModel.h"
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020014#import "WebRTC/RTCVideoCodec.h"
Anders Carlsson7e042812017-10-05 16:55:38 +020015#import "WebRTC/RTCVideoCodecH264.h"
16#import "WebRTC/RTCVideoEncoderVP8.h"
17#import "WebRTC/RTCVideoEncoderVP9.h"
18
Anders Carlsson7e042812017-10-05 16:55:38 +020019@implementation ARDVideoEncoderFactory
20
Anders Carlsson6bf43d22017-10-16 13:51:43 +020021@synthesize preferredCodec;
22
Anders Carlsson7e042812017-10-05 16:55:38 +020023- (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info {
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020024 if ([info.name isEqualToString:kVideoCodecH264Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020025 return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020026 } else if ([info.name isEqualToString:kVideoCodecVp8Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020027 return [RTCVideoEncoderVP8 vp8Encoder];
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020028 } else if ([info.name isEqualToString:kVideoCodecVp9Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020029 return [RTCVideoEncoderVP9 vp9Encoder];
30 }
31
32 return nil;
33}
34
35- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
36 NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array];
37
38 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
39 @"profile-level-id" : kLevel31ConstrainedHigh,
40 @"level-asymmetry-allowed" : @"1",
41 @"packetization-mode" : @"1",
42 };
43 RTCVideoCodecInfo *constrainedHighInfo =
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020044 [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecH264Name parameters:constrainedHighParams];
Anders Carlsson7e042812017-10-05 16:55:38 +020045 [codecs addObject:constrainedHighInfo];
46
47 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
48 @"profile-level-id" : kLevel31ConstrainedBaseline,
49 @"level-asymmetry-allowed" : @"1",
50 @"packetization-mode" : @"1",
51 };
52 RTCVideoCodecInfo *constrainedBaselineInfo =
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020053 [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecH264Name
54 parameters:constrainedBaselineParams];
Anders Carlsson7e042812017-10-05 16:55:38 +020055 [codecs addObject:constrainedBaselineInfo];
56
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020057 RTCVideoCodecInfo *vp8Info =
58 [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecVp8Name parameters:nil];
Anders Carlsson7e042812017-10-05 16:55:38 +020059 [codecs addObject:vp8Info];
60
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020061 RTCVideoCodecInfo *vp9Info =
62 [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecVp9Name parameters:nil];
Anders Carlsson7e042812017-10-05 16:55:38 +020063 [codecs addObject:vp9Info];
64
Anders Carlsson6bf43d22017-10-16 13:51:43 +020065 NSMutableArray<RTCVideoCodecInfo *> *orderedCodecs = [NSMutableArray array];
66 NSUInteger index = [codecs indexOfObject:self.preferredCodec];
67 if (index != NSNotFound) {
68 [orderedCodecs addObject:[codecs objectAtIndex:index]];
69 [codecs removeObjectAtIndex:index];
70 }
71 [orderedCodecs addObjectsFromArray:codecs];
72
73 return [orderedCodecs copy];
Anders Carlsson7e042812017-10-05 16:55:38 +020074}
75
76@end