blob: 6e3baa8750458a8d7eb29c22603553bde1f81fa5 [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"
16#import "api/video_codec/RTCVideoDecoderVP8.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020017#import "api/video_codec/RTCVideoDecoderVP9.h"
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030018#import "base/RTCVideoCodecInfo.h"
Anders Carlsson7e042812017-10-05 16:55:38 +020019
philipeld44badf2022-07-04 10:44:14 +020020#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
21#import "api/video_codec/RTCVideoDecoderAV1.h" // nogncheck
22#endif
23
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020024@implementation RTC_OBJC_TYPE (RTCDefaultVideoDecoderFactory)
Anders Carlsson7e042812017-10-05 16:55:38 +020025
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020026- (NSArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *)supportedCodecs {
Johannes Kron6a29eb12020-03-06 12:47:23 +010027 NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
28 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh,
29 @"level-asymmetry-allowed" : @"1",
30 @"packetization-mode" : @"1",
31 };
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020032 RTC_OBJC_TYPE(RTCVideoCodecInfo) *constrainedHighInfo =
33 [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecH264Name
34 parameters:constrainedHighParams];
Johannes Kron6a29eb12020-03-06 12:47:23 +010035
36 NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
37 @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline,
38 @"level-asymmetry-allowed" : @"1",
39 @"packetization-mode" : @"1",
40 };
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020041 RTC_OBJC_TYPE(RTCVideoCodecInfo) *constrainedBaselineInfo =
42 [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecH264Name
43 parameters:constrainedBaselineParams];
Johannes Kron6a29eb12020-03-06 12:47:23 +010044
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020045 RTC_OBJC_TYPE(RTCVideoCodecInfo) *vp8Info =
46 [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp8Name];
Johannes Kron6a29eb12020-03-06 12:47:23 +010047
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030048 NSMutableArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *result = [@[
Johannes Kron6a29eb12020-03-06 12:47:23 +010049 constrainedHighInfo,
50 constrainedBaselineInfo,
51 vp8Info,
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030052 ] mutableCopy];
53
54 if ([RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) {
55 [result
56 addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp9Name]];
57 }
58
philipeld44badf2022-07-04 10:44:14 +020059#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
60 [result addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecAv1Name]];
61#endif
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030062
63 return result;
Johannes Kron6a29eb12020-03-06 12:47:23 +010064}
65
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020066- (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)createDecoder:(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info {
Anders Carlsson1d4c1522017-10-30 13:07:07 +010067 if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020068 return [[RTC_OBJC_TYPE(RTCVideoDecoderH264) alloc] init];
Anders Carlsson1d4c1522017-10-30 13:07:07 +010069 } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020070 return [RTC_OBJC_TYPE(RTCVideoDecoderVP8) vp8Decoder];
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030071 } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name] &&
72 [RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020073 return [RTC_OBJC_TYPE(RTCVideoDecoderVP9) vp9Decoder];
philipeld44badf2022-07-04 10:44:14 +020074 }
75
76#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
77 if ([info.name isEqualToString:kRTCVideoCodecAv1Name]) {
Yura Yaroshevich8cfb2872021-03-03 12:29:42 +030078 return [RTC_OBJC_TYPE(RTCVideoDecoderAV1) av1Decoder];
Anders Carlsson7e042812017-10-05 16:55:38 +020079 }
philipeld44badf2022-07-04 10:44:14 +020080#endif
Anders Carlsson7e042812017-10-05 16:55:38 +020081
82 return nil;
83}
84
Anders Carlsson7e042812017-10-05 16:55:38 +020085@end