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 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 11 | #import "RTCDefaultVideoEncoderFactory.h" |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 12 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 13 | #import "RTCH264ProfileLevelId.h" |
| 14 | #import "RTCVideoEncoderH264.h" |
| 15 | #import "api/video_codec/RTCVideoCodecConstants.h" |
| 16 | #import "api/video_codec/RTCVideoEncoderVP8.h" |
| 17 | #import "base/RTCVideoCodecInfo.h" |
Kári Tristan Helgason | 9555e67 | 2017-12-01 14:27:07 +0100 | [diff] [blame] | 18 | #if !defined(RTC_DISABLE_VP9) |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 19 | #import "api/video_codec/RTCVideoEncoderVP9.h" |
Anders Carlsson | dd8c165 | 2018-01-30 10:32:13 +0100 | [diff] [blame] | 20 | #endif |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 21 | |
Anders Carlsson | 1d4c152 | 2017-10-30 13:07:07 +0100 | [diff] [blame] | 22 | @implementation RTCDefaultVideoEncoderFactory |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 23 | |
Anders Carlsson | 6bf43d2 | 2017-10-16 13:51:43 +0200 | [diff] [blame] | 24 | @synthesize preferredCodec; |
| 25 | |
Anders Carlsson | 1d4c152 | 2017-10-30 13:07:07 +0100 | [diff] [blame] | 26 | + (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 27 | NSDictionary<NSString *, NSString *> *constrainedHighParams = @{ |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 28 | @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh, |
Anders Carlsson | 1d4c152 | 2017-10-30 13:07:07 +0100 | [diff] [blame] | 29 | @"level-asymmetry-allowed" : @"1", |
| 30 | @"packetization-mode" : @"1", |
| 31 | }; |
| 32 | RTCVideoCodecInfo *constrainedHighInfo = |
| 33 | [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name |
| 34 | parameters:constrainedHighParams]; |
| 35 | |
| 36 | NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{ |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 37 | @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline, |
Anders Carlsson | 1d4c152 | 2017-10-30 13:07:07 +0100 | [diff] [blame] | 38 | @"level-asymmetry-allowed" : @"1", |
| 39 | @"packetization-mode" : @"1", |
| 40 | }; |
| 41 | RTCVideoCodecInfo *constrainedBaselineInfo = |
| 42 | [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name |
| 43 | parameters:constrainedBaselineParams]; |
| 44 | |
| 45 | RTCVideoCodecInfo *vp8Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name]; |
| 46 | |
Kári Tristan Helgason | 9555e67 | 2017-12-01 14:27:07 +0100 | [diff] [blame] | 47 | #if !defined(RTC_DISABLE_VP9) |
Anders Carlsson | 1d4c152 | 2017-10-30 13:07:07 +0100 | [diff] [blame] | 48 | RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name]; |
Kári Tristan Helgason | 9555e67 | 2017-12-01 14:27:07 +0100 | [diff] [blame] | 49 | #endif |
Anders Carlsson | dd8c165 | 2018-01-30 10:32:13 +0100 | [diff] [blame] | 50 | |
| 51 | return @[ |
| 52 | constrainedHighInfo, |
| 53 | constrainedBaselineInfo, |
Anders Carlsson | dd8c165 | 2018-01-30 10:32:13 +0100 | [diff] [blame] | 54 | vp8Info, |
| 55 | #if !defined(RTC_DISABLE_VP9) |
| 56 | vp9Info, |
| 57 | #endif |
Anders Carlsson | dd8c165 | 2018-01-30 10:32:13 +0100 | [diff] [blame] | 58 | ]; |
Anders Carlsson | 1d4c152 | 2017-10-30 13:07:07 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 61 | - (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info { |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 62 | if ([info.name isEqualToString:kRTCVideoCodecH264Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 63 | return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info]; |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 64 | } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 65 | return [RTCVideoEncoderVP8 vp8Encoder]; |
Kári Tristan Helgason | 9555e67 | 2017-12-01 14:27:07 +0100 | [diff] [blame] | 66 | #if !defined(RTC_DISABLE_VP9) |
Kári Tristan Helgason | fc313dc | 2017-10-20 11:01:22 +0200 | [diff] [blame] | 67 | } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) { |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 68 | return [RTCVideoEncoderVP9 vp9Encoder]; |
Kári Tristan Helgason | 9555e67 | 2017-12-01 14:27:07 +0100 | [diff] [blame] | 69 | #endif |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | return nil; |
| 73 | } |
| 74 | |
| 75 | - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
Anders Carlsson | 1d4c152 | 2017-10-30 13:07:07 +0100 | [diff] [blame] | 76 | NSMutableArray<RTCVideoCodecInfo *> *codecs = [[[self class] supportedCodecs] mutableCopy]; |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 77 | |
Anders Carlsson | 6bf43d2 | 2017-10-16 13:51:43 +0200 | [diff] [blame] | 78 | NSMutableArray<RTCVideoCodecInfo *> *orderedCodecs = [NSMutableArray array]; |
| 79 | NSUInteger index = [codecs indexOfObject:self.preferredCodec]; |
| 80 | if (index != NSNotFound) { |
| 81 | [orderedCodecs addObject:[codecs objectAtIndex:index]]; |
| 82 | [codecs removeObjectAtIndex:index]; |
| 83 | } |
| 84 | [orderedCodecs addObjectsFromArray:codecs]; |
| 85 | |
| 86 | return [orderedCodecs copy]; |
Anders Carlsson | 7e04281 | 2017-10-05 16:55:38 +0200 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @end |