Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 1 | /* |
| 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 Carlsson | 6bf43d2 | 2017-10-16 13:51:43 +0200 | [diff] [blame] | 13 | #import "ARDSettingsModel.h" |
Kári Tristan Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 14 | #import "WebRTC/RTCVideoCodec.h" |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 15 | #import "WebRTC/RTCVideoCodecH264.h" |
| 16 | #import "WebRTC/RTCVideoEncoderVP8.h" |
| 17 | #import "WebRTC/RTCVideoEncoderVP9.h" |
| 18 | |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 19 | @implementation ARDVideoEncoderFactory |
| 20 | |
Anders Carlsson | 6bf43d2 | 2017-10-16 13:51:43 +0200 | [diff] [blame] | 21 | @synthesize preferredCodec; |
| 22 | |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 23 | - (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info { |
Kári Tristan Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 24 | if ([info.name isEqualToString:kVideoCodecH264Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 25 | return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info]; |
Kári Tristan Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 26 | } else if ([info.name isEqualToString:kVideoCodecVp8Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 27 | return [RTCVideoEncoderVP8 vp8Encoder]; |
Kári Tristan Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 28 | } else if ([info.name isEqualToString:kVideoCodecVp9Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 29 | 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 Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 44 | [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecH264Name parameters:constrainedHighParams]; |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 45 | [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 Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 53 | [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecH264Name |
| 54 | parameters:constrainedBaselineParams]; |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 55 | [codecs addObject:constrainedBaselineInfo]; |
| 56 | |
Kári Tristan Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 57 | RTCVideoCodecInfo *vp8Info = |
| 58 | [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecVp8Name parameters:nil]; |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 59 | [codecs addObject:vp8Info]; |
| 60 | |
Kári Tristan Helgason | 117c482 | 2017-10-18 14:22:22 +0200 | [diff] [blame] | 61 | RTCVideoCodecInfo *vp9Info = |
| 62 | [[RTCVideoCodecInfo alloc] initWithName:kVideoCodecVp9Name parameters:nil]; |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 63 | [codecs addObject:vp9Info]; |
| 64 | |
Anders Carlsson | 6bf43d2 | 2017-10-16 13:51:43 +0200 | [diff] [blame] | 65 | 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 Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @end |