Source code
Revision control
Copy as Markdown
Other Tools
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "UIDevice+H264Profile.h"
#import "helpers/UIDevice+RTCDevice.h"
#include <algorithm>
namespace {
using namespace webrtc;
struct SupportedH264Profile {
const char* machineName;
const H264ProfileLevelId profile;
};
constexpr SupportedH264Profile kH264MaxSupportedProfiles[] = {
// iPhones with at least iOS 12
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_2}},
{H264Profile::kProfileHigh, H264Level::kLevel4_2}},
{H264Profile::kProfileHigh, H264Level::kLevel4_2}},
{H264Profile::kProfileHigh, H264Level::kLevel4_2}},
{H264Profile::kProfileHigh, H264Level::kLevel4_2}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
// iPods with at least iOS 12
{H264Profile::kProfileMain, H264Level::kLevel4_1}},
{H264Profile::kProfileMain, H264Level::kLevel4_1}},
// iPads with at least iOS 12
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel5_2}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel5_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
{H264Profile::kProfileHigh, H264Level::kLevel4_1}},
};
std::optional<H264ProfileLevelId> FindMaxSupportedProfileForDevice(NSString* machineName) {
const auto* result =
std::find_if(std::begin(kH264MaxSupportedProfiles),
std::end(kH264MaxSupportedProfiles),
[machineName](const SupportedH264Profile& supportedProfile) {
return [machineName isEqualToString:@(supportedProfile.machineName)];
});
if (result != std::end(kH264MaxSupportedProfiles)) {
return result->profile;
}
if ([machineName hasPrefix:@"iPhone"] || [machineName hasPrefix:@"iPad"]) {
H264ProfileLevelId fallbackProfile{H264Profile::kProfileHigh, H264Level::kLevel4_1};
return fallbackProfile;
}
if ([machineName hasPrefix:@"iPod"]) {
H264ProfileLevelId fallbackProfile{H264Profile::kProfileMain, H264Level::kLevel4_1};
return fallbackProfile;
}
return std::nullopt;
}
} // namespace
@implementation UIDevice (H264Profile)
+ (std::optional<webrtc::H264ProfileLevelId>)maxSupportedH264Profile {
return FindMaxSupportedProfileForDevice([UIDevice machineName]);
}
@end