blob: 42ebadf01e9596d1cebccf64303c8e3b1769875f [file] [log] [blame]
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +03001/*
2 * Copyright 2018 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 "UIDevice+H264Profile.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020012#import "helpers/UIDevice+RTCDevice.h"
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030013
14#include <algorithm>
15
16namespace {
17
Johannes Kronc3fcee72021-04-19 09:09:26 +020018using namespace webrtc;
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030019
20struct SupportedH264Profile {
21 const RTCDeviceType deviceType;
Johannes Kronc3fcee72021-04-19 09:09:26 +020022 const H264ProfileLevelId profile;
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030023};
24
Yura Yaroshevich1d871482018-05-02 13:06:34 +030025constexpr SupportedH264Profile kH264MaxSupportedProfiles[] = {
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030026 // iPhones with at least iOS 9
Johannes Kronc3fcee72021-04-19 09:09:26 +020027 {RTCDeviceTypeIPhone12ProMax,
28 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP832
29 {RTCDeviceTypeIPhone12Pro,
30 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP831
31 {RTCDeviceTypeIPhone12,
32 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP830
33 {RTCDeviceTypeIPhone12Mini,
34 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP829
35 {RTCDeviceTypeIPhone11ProMax,
36 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP806
37 {RTCDeviceTypeIPhone11Pro,
38 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP805
39 {RTCDeviceTypeIPhone11,
40 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP804
41 {RTCDeviceTypeIPhoneXS,
42 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP779
43 {RTCDeviceTypeIPhoneXSMax,
44 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP780
45 {RTCDeviceTypeIPhoneXR,
46 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP781
47 {RTCDeviceTypeIPhoneX,
48 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP770
49 {RTCDeviceTypeIPhone8,
50 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP767
51 {RTCDeviceTypeIPhone8Plus,
52 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP768
53 {RTCDeviceTypeIPhone7,
54 {H264Profile::kProfileHigh, H264Level::kLevel5_1}}, // https://support.apple.com/kb/SP743
55 {RTCDeviceTypeIPhone7Plus,
56 {H264Profile::kProfileHigh, H264Level::kLevel5_1}}, // https://support.apple.com/kb/SP744
57 {RTCDeviceTypeIPhoneSE,
58 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP738
59 {RTCDeviceTypeIPhone6S,
60 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP726
61 {RTCDeviceTypeIPhone6SPlus,
62 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP727
63 {RTCDeviceTypeIPhone6,
64 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP705
65 {RTCDeviceTypeIPhone6Plus,
66 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP706
67 {RTCDeviceTypeIPhone5SGSM,
68 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP685
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030069 {RTCDeviceTypeIPhone5SGSM_CDMA,
Johannes Kronc3fcee72021-04-19 09:09:26 +020070 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP685
71 {RTCDeviceTypeIPhone5GSM,
72 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP655
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030073 {RTCDeviceTypeIPhone5GSM_CDMA,
Johannes Kronc3fcee72021-04-19 09:09:26 +020074 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP655
75 {RTCDeviceTypeIPhone5CGSM,
76 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP684
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030077 {RTCDeviceTypeIPhone5CGSM_CDMA,
Johannes Kronc3fcee72021-04-19 09:09:26 +020078 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP684
79 {RTCDeviceTypeIPhone4S,
80 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP643
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030081
82 // iPods with at least iOS 9
Johannes Kronc3fcee72021-04-19 09:09:26 +020083 {RTCDeviceTypeIPodTouch7G,
84 {H264Profile::kProfileMain, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP796
85 {RTCDeviceTypeIPodTouch6G,
86 {H264Profile::kProfileMain, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP720
87 {RTCDeviceTypeIPodTouch5G,
88 {H264Profile::kProfileMain, H264Level::kLevel3_1}}, // https://support.apple.com/kb/SP657
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030089
90 // iPads with at least iOS 9
Johannes Kronc3fcee72021-04-19 09:09:26 +020091 {RTCDeviceTypeIPadAir4Gen,
92 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP828
93 {RTCDeviceTypeIPad8,
94 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP822
95 {RTCDeviceTypeIPadPro4Gen12Inch,
96 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP815
97 {RTCDeviceTypeIPadPro4Gen11Inch,
98 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP814
99 {RTCDeviceTypeIPadAir3Gen,
100 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP787
101 {RTCDeviceTypeIPadMini5Gen,
102 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP788
Yura Yaroshevichde365952019-10-31 12:01:53 +0300103 {RTCDeviceTypeIPadPro3Gen12Inch,
Johannes Kronc3fcee72021-04-19 09:09:26 +0200104 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP785
Yura Yaroshevichde365952019-10-31 12:01:53 +0300105 {RTCDeviceTypeIPadPro3Gen11Inch,
Johannes Kronc3fcee72021-04-19 09:09:26 +0200106 {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP784
107 {RTCDeviceTypeIPad7Gen10Inch,
108 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP807
109 {RTCDeviceTypeIPad2Wifi,
110 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP622
111 {RTCDeviceTypeIPad2GSM,
112 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP622
113 {RTCDeviceTypeIPad2CDMA,
114 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP622
115 {RTCDeviceTypeIPad2Wifi2,
116 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP622
117 {RTCDeviceTypeIPadMiniWifi,
118 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP661
119 {RTCDeviceTypeIPadMiniGSM,
120 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP661
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300121 {RTCDeviceTypeIPadMiniGSM_CDMA,
Johannes Kronc3fcee72021-04-19 09:09:26 +0200122 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP661
123 {RTCDeviceTypeIPad3Wifi,
124 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP647
125 {RTCDeviceTypeIPad3GSM_CDMA,
126 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP647
127 {RTCDeviceTypeIPad3GSM,
128 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP647
129 {RTCDeviceTypeIPad4Wifi,
130 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP662
131 {RTCDeviceTypeIPad4GSM,
132 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP662
133 {RTCDeviceTypeIPad4GSM_CDMA,
134 {H264Profile::kProfileHigh, H264Level::kLevel4_1}}, // https://support.apple.com/kb/SP662
135 {RTCDeviceTypeIPad5,
136 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP751
137 {RTCDeviceTypeIPad6,
138 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP774
139 {RTCDeviceTypeIPadAirWifi,
140 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP692
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300141 {RTCDeviceTypeIPadAirCellular,
Johannes Kronc3fcee72021-04-19 09:09:26 +0200142 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP692
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300143 {RTCDeviceTypeIPadAirWifiCellular,
Johannes Kronc3fcee72021-04-19 09:09:26 +0200144 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP692
145 {RTCDeviceTypeIPadAir2,
146 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP708
147 {RTCDeviceTypeIPadMini2GWifi,
148 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP693
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300149 {RTCDeviceTypeIPadMini2GCellular,
Johannes Kronc3fcee72021-04-19 09:09:26 +0200150 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP693
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300151 {RTCDeviceTypeIPadMini2GWifiCellular,
Johannes Kronc3fcee72021-04-19 09:09:26 +0200152 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP693
153 {RTCDeviceTypeIPadMini3,
154 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP709
155 {RTCDeviceTypeIPadMini4,
156 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP725
157 {RTCDeviceTypeIPadPro9Inch,
158 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP739
159 {RTCDeviceTypeIPadPro12Inch,
160 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/sp723
161 {RTCDeviceTypeIPadPro12Inch2,
162 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP761
163 {RTCDeviceTypeIPadPro10Inch,
164 {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP762
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300165};
166
Johannes Kronc3fcee72021-04-19 09:09:26 +0200167absl::optional<H264ProfileLevelId> FindMaxSupportedProfileForDevice(RTCDeviceType deviceType) {
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300168 const auto* result = std::find_if(std::begin(kH264MaxSupportedProfiles),
169 std::end(kH264MaxSupportedProfiles),
170 [deviceType](const SupportedH264Profile& supportedProfile) {
171 return supportedProfile.deviceType == deviceType;
172 });
173 if (result != std::end(kH264MaxSupportedProfiles)) {
174 return result->profile;
175 }
Danil Chapovalov196100e2018-06-21 10:17:24 +0200176 return absl::nullopt;
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300177}
178
179} // namespace
180
181@implementation UIDevice (H264Profile)
182
Johannes Kronc3fcee72021-04-19 09:09:26 +0200183+ (absl::optional<webrtc::H264ProfileLevelId>)maxSupportedH264Profile {
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +0300184 return FindMaxSupportedProfileForDevice([self deviceType]);
185}
186
187@end