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 | |
Oskar Sundbom | 4556f3c | 2017-10-26 11:55:45 +0000 | [diff] [blame^] | 11 | #import "ARDVideoEncoderFactory.h" |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 12 | |
Oskar Sundbom | 4556f3c | 2017-10-26 11:55:45 +0000 | [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 | |
Oskar Sundbom | 4556f3c | 2017-10-26 11:55:45 +0000 | [diff] [blame^] | 19 | @implementation ARDVideoEncoderFactory |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 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 | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 24 | if ([info.name isEqualToString:kRTCVideoCodecH264Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 25 | return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info]; |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 26 | } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 27 | return [RTCVideoEncoderVP8 vp8Encoder]; |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 28 | } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) { |
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 { |
Oskar Sundbom | 4556f3c | 2017-10-26 11:55:45 +0000 | [diff] [blame^] | 36 | 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 Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 65 | |
Anders Carlsson | 6bf43d2 | 2017-10-16 13:51:43 +0200 | [diff] [blame] | 66 | 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 Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @end |