| 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 "TGRTCDefaultVideoEncoderFactory.h" |
| 12 |
| 13 | #import "RTCH264ProfileLevelId.h" |
| 14 | #import "TGRTCVideoEncoderH264.h" |
| 15 | #import "api/video_codec/RTCVideoCodecConstants.h" |
| 16 | #import "api/video_codec/RTCVideoEncoderVP8.h" |
| 17 | #import "base/RTCVideoCodecInfo.h" |
| 18 | #if defined(RTC_ENABLE_VP9) |
| 19 | #import "api/video_codec/RTCVideoEncoderVP9.h" |
| 20 | #endif |
| 21 | #if !defined(DISABLE_H265) |
| 22 | #import "RTCH265ProfileLevelId.h" |
| 23 | #import "TGRTCVideoEncoderH265.h" |
| 24 | #endif |
| 25 |
| 26 | @implementation TGRTCDefaultVideoEncoderFactory |
| 27 |
| 28 | @synthesize preferredCodec; |
| 29 |
| 30 | + (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 31 | NSDictionary<NSString *, NSString *> *constrainedHighParams = @{ |
| 32 | @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh, |
| 33 | @"level-asymmetry-allowed" : @"1", |
| 34 | @"packetization-mode" : @"1", |
| 35 | }; |
| 36 | RTCVideoCodecInfo *constrainedHighInfo = |
| 37 | [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name |
| 38 | parameters:constrainedHighParams]; |
| 39 |
| 40 | NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{ |
| 41 | @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline, |
| 42 | @"level-asymmetry-allowed" : @"1", |
| 43 | @"packetization-mode" : @"1", |
| 44 | }; |
| 45 | RTCVideoCodecInfo *constrainedBaselineInfo = |
| 46 | [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name |
| 47 | parameters:constrainedBaselineParams]; |
| 48 |
| 49 | RTCVideoCodecInfo *vp8Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name]; |
| 50 |
| 51 | #if defined(RTC_ENABLE_VP9) |
| 52 | RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name]; |
| 53 | #endif |
| 54 |
| 55 | #if !defined(DISABLE_H265) |
| 56 | RTCVideoCodecInfo *h265Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH265Name]; |
| 57 | #endif |
| 58 |
| 59 | NSMutableArray *result = [[NSMutableArray alloc] initWithArray:@[ |
| 60 | constrainedHighInfo, |
| 61 | constrainedBaselineInfo, |
| 62 | vp8Info, |
| 63 | #if defined(RTC_ENABLE_VP9) |
| 64 | vp9Info, |
| 65 | #endif |
| 66 | ]]; |
| 67 |
| 68 | #if !defined(DISABLE_H265) |
| 69 | #ifdef WEBRTC_IOS |
| 70 | if (@available(iOS 11.0, *)) { |
| 71 | if ([[AVAssetExportSession allExportPresets] containsObject:AVAssetExportPresetHEVCHighestQuality]) { |
| 72 | [result addObject:h265Info]; |
| 73 | } |
| 74 | } |
| 75 | #else // WEBRTC_IOS |
| 76 | if (@available(macOS 10.13, *)) { |
| 77 | if ([[AVAssetExportSession allExportPresets] containsObject:AVAssetExportPresetHEVCHighestQuality]) { |
| 78 | [result addObject:h265Info]; |
| 79 | } |
| 80 | } |
| 81 | #endif // WEBRTC_IOS |
| 82 | #endif |
| 83 |
| 84 | return result; |
| 85 | } |
| 86 |
| 87 | - (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info { |
| 88 | if ([info.name isEqualToString:kRTCVideoCodecH264Name]) { |
| 89 | return [[TGRTCVideoEncoderH264 alloc] initWithCodecInfo:info]; |
| 90 | } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) { |
| 91 | return [RTCVideoEncoderVP8 vp8Encoder]; |
| 92 | } |
| 93 | #if defined(RTC_ENABLE_VP9) |
| 94 | if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) { |
| 95 | return [RTCVideoEncoderVP9 vp9Encoder]; |
| 96 | } |
| 97 | #endif |
| 98 |
| 99 | #if !defined(DISABLE_H265) |
| 100 | #ifdef WEBRTC_IOS |
| 101 | if (@available(iOS 11, *)) { |
| 102 | if ([info.name isEqualToString:kRTCVideoCodecH265Name]) { |
| 103 | return [[TGRTCVideoEncoderH265 alloc] initWithCodecInfo:info]; |
| 104 | } |
| 105 | } |
| 106 | #else // WEBRTC_IOS |
| 107 | if (@available(macOS 10.13, *)) { |
| 108 | if ([info.name isEqualToString:kRTCVideoCodecH265Name]) { |
| 109 | return [[TGRTCVideoEncoderH265 alloc] initWithCodecInfo:info]; |
| 110 | } |
| 111 | } |
| 112 | #endif // WEBRTC_IOS |
| 113 | #endif // !DISABLE_H265 |
| 114 |
| 115 | return nil; |
| 116 | } |
| 117 |
| 118 | - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 119 | NSMutableArray<RTCVideoCodecInfo *> *codecs = [[[self class] supportedCodecs] mutableCopy]; |
| 120 |
| 121 | NSMutableArray<RTCVideoCodecInfo *> *orderedCodecs = [NSMutableArray array]; |
| 122 | NSUInteger index = [codecs indexOfObject:self.preferredCodec]; |
| 123 | if (index != NSNotFound) { |
| 124 | [orderedCodecs addObject:[codecs objectAtIndex:index]]; |
| 125 | [codecs removeObjectAtIndex:index]; |
| 126 | } |
| 127 | [orderedCodecs addObjectsFromArray:codecs]; |
| 128 |
| 129 | return [orderedCodecs copy]; |
| 130 | } |
| 131 |
| 132 | @end |
| 133 |