blob: f4a97a865949e7a83b3ce006431a8e8824dbc940 [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
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020011#import "RTCDefaultVideoDecoderFactory.h"
Anders Carlsson7e042812017-10-05 16:55:38 +020012
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020013#import "RTCH264ProfileLevelId.h"
14#import "RTCVideoDecoderH264.h"
15#import "api/video_codec/RTCVideoCodecConstants.h"
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030016#import "api/video_codec/RTCVideoDecoderAV1.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020017#import "api/video_codec/RTCVideoDecoderVP8.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020018#import "api/video_codec/RTCVideoDecoderVP9.h"
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030019#import "base/RTCVideoCodecInfo.h"
Anders Carlsson7e042812017-10-05 16:55:38 +020020
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020021@implementation RTC_OBJC_TYPE (RTCDefaultVideoDecoderFactory)
Anders Carlsson7e042812017-10-05 16:55:38 +020022
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020023- (NSArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *)supportedCodecs {
Johannes Kron6a29eb12020-03-06 12:47:23 +010024 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
25 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh,
26 @"level-asymmetry-allowed" : @"1",
27 @"packetization-mode" : @"1",
28 };
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020029 RTC_OBJC_TYPE(RTCVideoCodecInfo) *constrainedHighInfo =
30 [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecH264Name
31 parameters:constrainedHighParams];
Johannes Kron6a29eb12020-03-06 12:47:23 +010032
33 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
34 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline,
35 @"level-asymmetry-allowed" : @"1",
36 @"packetization-mode" : @"1",
37 };
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020038 RTC_OBJC_TYPE(RTCVideoCodecInfo) *constrainedBaselineInfo =
39 [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecH264Name
40 parameters:constrainedBaselineParams];
Johannes Kron6a29eb12020-03-06 12:47:23 +010041
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020042 RTC_OBJC_TYPE(RTCVideoCodecInfo) *vp8Info =
43 [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp8Name];
Johannes Kron6a29eb12020-03-06 12:47:23 +010044
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030045 NSMutableArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *result = [@[
Johannes Kron6a29eb12020-03-06 12:47:23 +010046 constrainedHighInfo,
47 constrainedBaselineInfo,
48 vp8Info,
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030049 ] mutableCopy];
50
51 if ([RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) {
52 [result
53 addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp9Name]];
54 }
55
56 if ([RTC_OBJC_TYPE(RTCVideoDecoderAV1) isSupported]) {
57 [result
58 addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecAv1Name]];
59 }
60
61 return result;
Johannes Kron6a29eb12020-03-06 12:47:23 +010062}
63
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020064- (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)createDecoder:(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info {
Anders Carlsson1d4c1522017-10-30 13:07:07 +010065 if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020066 return [[RTC_OBJC_TYPE(RTCVideoDecoderH264) alloc] init];
Anders Carlsson1d4c1522017-10-30 13:07:07 +010067 } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020068 return [RTC_OBJC_TYPE(RTCVideoDecoderVP8) vp8Decoder];
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030069 } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name] &&
70 [RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020071 return [RTC_OBJC_TYPE(RTCVideoDecoderVP9) vp9Decoder];
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030072 } else if ([info.name isEqualToString:kRTCVideoCodecAv1Name] &&
73 [RTC_OBJC_TYPE(RTCVideoDecoderAV1) isSupported]) {
74 return [RTC_OBJC_TYPE(RTCVideoDecoderAV1) av1Decoder];
Anders Carlsson7e042812017-10-05 16:55:38 +020075 }
76
77 return nil;
78}
79
Anders Carlsson7e042812017-10-05 16:55:38 +020080@end