xref: /aosp_15_r20/external/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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
11#import "RTCDefaultVideoDecoderFactory.h"
12
13#import "RTCH264ProfileLevelId.h"
14#import "RTCVideoDecoderH264.h"
15#import "api/video_codec/RTCVideoCodecConstants.h"
16#import "api/video_codec/RTCVideoDecoderVP8.h"
17#import "api/video_codec/RTCVideoDecoderVP9.h"
18#import "base/RTCVideoCodecInfo.h"
19
20#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
21#import "api/video_codec/RTCVideoDecoderAV1.h"  // nogncheck
22#endif
23
24@implementation RTC_OBJC_TYPE (RTCDefaultVideoDecoderFactory)
25
26- (NSArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *)supportedCodecs {
27  NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
28    @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedHigh,
29    @"level-asymmetry-allowed" : @"1",
30    @"packetization-mode" : @"1",
31  };
32  RTC_OBJC_TYPE(RTCVideoCodecInfo) *constrainedHighInfo =
33      [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecH264Name
34                                                  parameters:constrainedHighParams];
35
36  NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
37    @"profile-level-id" : kRTCMaxSupportedH264ProfileLevelConstrainedBaseline,
38    @"level-asymmetry-allowed" : @"1",
39    @"packetization-mode" : @"1",
40  };
41  RTC_OBJC_TYPE(RTCVideoCodecInfo) *constrainedBaselineInfo =
42      [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecH264Name
43                                                  parameters:constrainedBaselineParams];
44
45  RTC_OBJC_TYPE(RTCVideoCodecInfo) *vp8Info =
46      [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp8Name];
47
48  NSMutableArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *result = [@[
49    constrainedHighInfo,
50    constrainedBaselineInfo,
51    vp8Info,
52  ] mutableCopy];
53
54  if ([RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) {
55    [result
56        addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp9Name]];
57  }
58
59#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
60  [result addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecAv1Name]];
61#endif
62
63  return result;
64}
65
66- (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)createDecoder:(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info {
67  if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
68    return [[RTC_OBJC_TYPE(RTCVideoDecoderH264) alloc] init];
69  } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
70    return [RTC_OBJC_TYPE(RTCVideoDecoderVP8) vp8Decoder];
71  } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name] &&
72             [RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) {
73    return [RTC_OBJC_TYPE(RTCVideoDecoderVP9) vp9Decoder];
74  }
75
76#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
77  if ([info.name isEqualToString:kRTCVideoCodecAv1Name]) {
78    return [RTC_OBJC_TYPE(RTCVideoDecoderAV1) av1Decoder];
79  }
80#endif
81
82  return nil;
83}
84
85@end
86