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 | |
| 18 | using namespace webrtc::H264; |
| 19 | |
| 20 | struct SupportedH264Profile { |
| 21 | const RTCDeviceType deviceType; |
| 22 | const ProfileLevelId profile; |
| 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 |
| 27 | {RTCDeviceTypeIPhoneX, {kProfileHigh, kLevel5_2}}, // https://support.apple.com/kb/SP770 |
| 28 | {RTCDeviceTypeIPhone8, {kProfileHigh, kLevel5_2}}, // https://support.apple.com/kb/SP767 |
| 29 | {RTCDeviceTypeIPhone8Plus, {kProfileHigh, kLevel5_2}}, // https://support.apple.com/kb/SP768 |
| 30 | {RTCDeviceTypeIPhone7, {kProfileHigh, kLevel5_1}}, // https://support.apple.com/kb/SP743 |
| 31 | {RTCDeviceTypeIPhone7Plus, {kProfileHigh, kLevel5_1}}, // https://support.apple.com/kb/SP744 |
| 32 | {RTCDeviceTypeIPhoneSE, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP738 |
| 33 | {RTCDeviceTypeIPhone6S, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP726 |
| 34 | {RTCDeviceTypeIPhone6SPlus, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP727 |
| 35 | {RTCDeviceTypeIPhone6, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP705 |
| 36 | {RTCDeviceTypeIPhone6Plus, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP706 |
| 37 | {RTCDeviceTypeIPhone5SGSM, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP685 |
| 38 | {RTCDeviceTypeIPhone5SGSM_CDMA, |
| 39 | {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP685 |
| 40 | {RTCDeviceTypeIPhone5GSM, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP655 |
| 41 | {RTCDeviceTypeIPhone5GSM_CDMA, |
| 42 | {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP655 |
| 43 | {RTCDeviceTypeIPhone5CGSM, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP684 |
| 44 | {RTCDeviceTypeIPhone5CGSM_CDMA, |
| 45 | {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP684 |
| 46 | {RTCDeviceTypeIPhone4S, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP643 |
| 47 | |
| 48 | // iPods with at least iOS 9 |
| 49 | {RTCDeviceTypeIPodTouch6G, {kProfileMain, kLevel4_1}}, // https://support.apple.com/kb/SP720 |
| 50 | {RTCDeviceTypeIPodTouch5G, {kProfileMain, kLevel3_1}}, // https://support.apple.com/kb/SP657 |
| 51 | |
| 52 | // iPads with at least iOS 9 |
| 53 | {RTCDeviceTypeIPad2Wifi, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP622 |
| 54 | {RTCDeviceTypeIPad2GSM, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP622 |
| 55 | {RTCDeviceTypeIPad2CDMA, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP622 |
| 56 | {RTCDeviceTypeIPad2Wifi2, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP622 |
| 57 | {RTCDeviceTypeIPadMiniWifi, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP661 |
| 58 | {RTCDeviceTypeIPadMiniGSM, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP661 |
| 59 | {RTCDeviceTypeIPadMiniGSM_CDMA, |
| 60 | {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP661 |
| 61 | {RTCDeviceTypeIPad3Wifi, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP647 |
| 62 | {RTCDeviceTypeIPad3GSM_CDMA, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP647 |
| 63 | {RTCDeviceTypeIPad3GSM, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP647 |
| 64 | {RTCDeviceTypeIPad4Wifi, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP662 |
| 65 | {RTCDeviceTypeIPad4GSM, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP662 |
| 66 | {RTCDeviceTypeIPad4GSM_CDMA, {kProfileHigh, kLevel4_1}}, // https://support.apple.com/kb/SP662 |
| 67 | {RTCDeviceTypeIPad5, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP751 |
| 68 | {RTCDeviceTypeIPad6, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP774 |
| 69 | {RTCDeviceTypeIPadAirWifi, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP692 |
| 70 | {RTCDeviceTypeIPadAirCellular, |
| 71 | {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP692 |
| 72 | {RTCDeviceTypeIPadAirWifiCellular, |
| 73 | {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP692 |
| 74 | {RTCDeviceTypeIPadAir2, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP708 |
| 75 | {RTCDeviceTypeIPadMini2GWifi, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP693 |
| 76 | {RTCDeviceTypeIPadMini2GCellular, |
| 77 | {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP693 |
| 78 | {RTCDeviceTypeIPadMini2GWifiCellular, |
| 79 | {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP693 |
| 80 | {RTCDeviceTypeIPadMini3, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP709 |
| 81 | {RTCDeviceTypeIPadMini4, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP725 |
| 82 | {RTCDeviceTypeIPadPro9Inch, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP739 |
| 83 | {RTCDeviceTypeIPadPro12Inch, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/sp723 |
| 84 | {RTCDeviceTypeIPadPro12Inch2, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP761 |
| 85 | {RTCDeviceTypeIPadPro10Inch, {kProfileHigh, kLevel4_2}}, // https://support.apple.com/kb/SP762 |
| 86 | }; |
| 87 | |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 88 | absl::optional<ProfileLevelId> FindMaxSupportedProfileForDevice(RTCDeviceType deviceType) { |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 89 | const auto* result = std::find_if(std::begin(kH264MaxSupportedProfiles), |
| 90 | std::end(kH264MaxSupportedProfiles), |
| 91 | [deviceType](const SupportedH264Profile& supportedProfile) { |
| 92 | return supportedProfile.deviceType == deviceType; |
| 93 | }); |
| 94 | if (result != std::end(kH264MaxSupportedProfiles)) { |
| 95 | return result->profile; |
| 96 | } |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 97 | return absl::nullopt; |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | } // namespace |
| 101 | |
| 102 | @implementation UIDevice (H264Profile) |
| 103 | |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 104 | + (absl::optional<webrtc::H264::ProfileLevelId>)maxSupportedH264Profile { |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 105 | return FindMaxSupportedProfileForDevice([self deviceType]); |
| 106 | } |
| 107 | |
| 108 | @end |