blob: d6ca592548ccbd7686260d89b08500c519aaed4c [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
Oskar Sundbom4556f3c2017-10-26 11:55:45 +000011#import "ARDVideoEncoderFactory.h"
Anders Carlsson7e042812017-10-05 16:55:38 +020012
Oskar Sundbom4556f3c2017-10-26 11:55:45 +000013#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
Oskar Sundbom4556f3c2017-10-26 11:55:45 +000019@implementation ARDVideoEncoderFactory
Anders Carlsson7e042812017-10-05 16:55:38 +020020
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 Helgasonfc313dc2017-10-20 11:01:22 +020024 if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020025 return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020026 } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020027 return [RTCVideoEncoderVP8 vp8Encoder];
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020028 } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
Anders Carlsson7e042812017-10-05 16:55:38 +020029 return [RTCVideoEncoderVP9 vp9Encoder];
30 }
31
32 return nil;
33}
34
35- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
Oskar Sundbom4556f3c2017-10-26 11:55:45 +000036 NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array];
37
38 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
39 @"profile-level-id" : kRTCLevel31ConstrainedHigh,
40 @"level-asymmetry-allowed" : @"1",
41 @"packetization-mode" : @"1",
42 };
43 RTCVideoCodecInfo *constrainedHighInfo =
44 [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name
45 parameters:constrainedHighParams];
46 [codecs addObject:constrainedHighInfo];
47
48 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
49 @"profile-level-id" : kRTCLevel31ConstrainedBaseline,
50 @"level-asymmetry-allowed" : @"1",
51 @"packetization-mode" : @"1",
52 };
53 RTCVideoCodecInfo *constrainedBaselineInfo =
54 [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name
55 parameters:constrainedBaselineParams];
56 [codecs addObject:constrainedBaselineInfo];
57
58 RTCVideoCodecInfo *vp8Info =
59 [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name parameters:nil];
60 [codecs addObject:vp8Info];
61
62 RTCVideoCodecInfo *vp9Info =
63 [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name parameters:nil];
64 [codecs addObject:vp9Info];
Anders Carlsson7e042812017-10-05 16:55:38 +020065
Anders Carlsson6bf43d22017-10-16 13:51:43 +020066 NSMutableArray<RTCVideoCodecInfo *> *orderedCodecs = [NSMutableArray array];
67 NSUInteger index = [codecs indexOfObject:self.preferredCodec];
68 if (index != NSNotFound) {
69 [orderedCodecs addObject:[codecs objectAtIndex:index]];
70 [codecs removeObjectAtIndex:index];
71 }
72 [orderedCodecs addObjectsFromArray:codecs];
73
74 return [orderedCodecs copy];
Anders Carlsson7e042812017-10-05 16:55:38 +020075}
76
77@end