Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 1 | /* |
| 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 Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 12 | #import "helpers/UIDevice+RTCDevice.h" |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 13 | |
| 14 | #include <algorithm> |
| 15 | |
| 16 | namespace { |
| 17 | |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 18 | using namespace webrtc; |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 19 | |
| 20 | struct SupportedH264Profile { |
| 21 | const RTCDeviceType deviceType; |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 22 | const H264ProfileLevelId profile; |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 23 | }; |
| 24 | |
Yura Yaroshevich | 1d87148 | 2018-05-02 13:06:34 +0300 | [diff] [blame] | 25 | constexpr SupportedH264Profile kH264MaxSupportedProfiles[] = { |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 26 | // iPhones with at least iOS 9 |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 27 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 69 | {RTCDeviceTypeIPhone5SGSM_CDMA, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 70 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 73 | {RTCDeviceTypeIPhone5GSM_CDMA, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 74 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 77 | {RTCDeviceTypeIPhone5CGSM_CDMA, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 78 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 81 | |
| 82 | // iPods with at least iOS 9 |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 83 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 89 | |
| 90 | // iPads with at least iOS 9 |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 91 | {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 Yaroshevich | de36595 | 2019-10-31 12:01:53 +0300 | [diff] [blame] | 103 | {RTCDeviceTypeIPadPro3Gen12Inch, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 104 | {H264Profile::kProfileHigh, H264Level::kLevel5_2}}, // https://support.apple.com/kb/SP785 |
Yura Yaroshevich | de36595 | 2019-10-31 12:01:53 +0300 | [diff] [blame] | 105 | {RTCDeviceTypeIPadPro3Gen11Inch, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 106 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 121 | {RTCDeviceTypeIPadMiniGSM_CDMA, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 122 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 141 | {RTCDeviceTypeIPadAirCellular, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 142 | {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP692 |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 143 | {RTCDeviceTypeIPadAirWifiCellular, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 144 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 149 | {RTCDeviceTypeIPadMini2GCellular, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 150 | {H264Profile::kProfileHigh, H264Level::kLevel4_2}}, // https://support.apple.com/kb/SP693 |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 151 | {RTCDeviceTypeIPadMini2GWifiCellular, |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 152 | {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 Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 165 | }; |
| 166 | |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 167 | absl::optional<H264ProfileLevelId> FindMaxSupportedProfileForDevice(RTCDeviceType deviceType) { |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 168 | 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 Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 176 | return absl::nullopt; |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | } // namespace |
| 180 | |
| 181 | @implementation UIDevice (H264Profile) |
| 182 | |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 183 | + (absl::optional<webrtc::H264ProfileLevelId>)maxSupportedH264Profile { |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 184 | return FindMaxSupportedProfileForDevice([self deviceType]); |
| 185 | } |
| 186 | |
| 187 | @end |