blob: e4aafccb2c04e55e1641cdfd85fb0ed3dfe389d9 [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"
Anders Carlsson7e042812017-10-05 16:55:38 +020014#import "WebRTC/RTCVideoCodecH264.h"
15#import "WebRTC/RTCVideoEncoderVP8.h"
16#import "WebRTC/RTCVideoEncoderVP9.h"
17
18static NSString *kLevel31ConstrainedHigh = @"640c1f";
19static NSString *kLevel31ConstrainedBaseline = @"42e01f";
20
21@implementation ARDVideoEncoderFactory
22
Anders Carlsson6bf43d22017-10-16 13:51:43 +020023@synthesize preferredCodec;
24
Anders Carlsson7e042812017-10-05 16:55:38 +020025- (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info {
26 if ([info.name isEqualToString:@"H264"]) {
27 return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
28 } else if ([info.name isEqualToString:@"VP8"]) {
29 return [RTCVideoEncoderVP8 vp8Encoder];
30 } else if ([info.name isEqualToString:@"VP9"]) {
31 return [RTCVideoEncoderVP9 vp9Encoder];
32 }
33
34 return nil;
35}
36
37- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
38 NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array];
39
40 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
41 @"profile-level-id" : kLevel31ConstrainedHigh,
42 @"level-asymmetry-allowed" : @"1",
43 @"packetization-mode" : @"1",
44 };
45 RTCVideoCodecInfo *constrainedHighInfo =
46 [[RTCVideoCodecInfo alloc] initWithName:@"H264" parameters:constrainedHighParams];
47 [codecs addObject:constrainedHighInfo];
48
49 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
50 @"profile-level-id" : kLevel31ConstrainedBaseline,
51 @"level-asymmetry-allowed" : @"1",
52 @"packetization-mode" : @"1",
53 };
54 RTCVideoCodecInfo *constrainedBaselineInfo =
55 [[RTCVideoCodecInfo alloc] initWithName:@"H264" parameters:constrainedBaselineParams];
56 [codecs addObject:constrainedBaselineInfo];
57
58 RTCVideoCodecInfo *vp8Info = [[RTCVideoCodecInfo alloc] initWithName:@"VP8" parameters:nil];
59 [codecs addObject:vp8Info];
60
61 RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:@"VP9" parameters:nil];
62 [codecs addObject:vp9Info];
63
Anders Carlsson6bf43d22017-10-16 13:51:43 +020064 NSMutableArray<RTCVideoCodecInfo *> *orderedCodecs = [NSMutableArray array];
65 NSUInteger index = [codecs indexOfObject:self.preferredCodec];
66 if (index != NSNotFound) {
67 [orderedCodecs addObject:[codecs objectAtIndex:index]];
68 [codecs removeObjectAtIndex:index];
69 }
70 [orderedCodecs addObjectsFromArray:codecs];
71
72 return [orderedCodecs copy];
Anders Carlsson7e042812017-10-05 16:55:38 +020073}
74
75@end