Merge "Cache Max Subsample Size" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-03-09 21:03:52 +00:00
committed by Android (Google) Code Review
2 changed files with 28 additions and 17 deletions

View File

@@ -300,7 +300,7 @@ class CryptoSession {
CdmResponseType GetSystemIdInternal(uint32_t* system_id); CdmResponseType GetSystemIdInternal(uint32_t* system_id);
CdmResponseType GenerateRsaSignature(const std::string& message, CdmResponseType GenerateRsaSignature(const std::string& message,
std::string* signature); std::string* signature);
bool GetMaxSubsampleRegionSize(size_t* max); size_t GetMaxSubsampleRegionSize();
bool SetDestinationBufferType(); bool SetDestinationBufferType();
@@ -429,6 +429,7 @@ class CryptoSession {
static std::atomic<uint64_t> request_id_index_source_; static std::atomic<uint64_t> request_id_index_source_;
uint32_t api_version_; uint32_t api_version_;
size_t max_subsample_region_size_;
// Stores the most recent error code returned from a call to // Stores the most recent error code returned from a call to
// OEMCrypto_DecryptCENC. This is used to reduce the total number of // OEMCrypto_DecryptCENC. This is used to reduce the total number of

View File

@@ -80,7 +80,7 @@ static_assert(ArraySize(kMaxSubsampleRegionSizes) ==
"The kMaxSubsampleRegionSizes table needs to be updated to " "The kMaxSubsampleRegionSizes table needs to be updated to "
"reflect the supported range of resource rating tiers."); "reflect the supported range of resource rating tiers.");
constexpr size_t kDefaultMaximumChunkSize = 100 * KiB; constexpr size_t kDefaultMaxSubsampleRegionSize = kMaxSubsampleRegionSizes[0];
// This maps a few common OEMCryptoResult to CdmResponseType. Many mappings // This maps a few common OEMCryptoResult to CdmResponseType. Many mappings
// are not universal but are OEMCrypto method specific. Those will be // are not universal but are OEMCrypto method specific. Those will be
@@ -217,7 +217,8 @@ CryptoSession::CryptoSession(metrics::CryptoMetrics* metrics)
requested_security_level_(kLevelDefault), requested_security_level_(kLevelDefault),
usage_support_type_(kUnknownUsageSupport), usage_support_type_(kUnknownUsageSupport),
usage_table_header_(nullptr), usage_table_header_(nullptr),
api_version_(0) { api_version_(0),
max_subsample_region_size_(0) {
assert(metrics); assert(metrics);
Init(); Init();
life_span_.Start(); life_span_.Start();
@@ -1331,14 +1332,28 @@ CdmResponseType CryptoSession::GenerateRsaSignature(const std::string& message,
"OEMCrypto_GenerateRSASignature"); "OEMCrypto_GenerateRSASignature");
} }
bool CryptoSession::GetMaxSubsampleRegionSize(size_t* max) { size_t CryptoSession::GetMaxSubsampleRegionSize() {
uint32_t tier = 0; // If we haven't cached the answer yet, fetch it from OEMCrypto.
if (!GetResourceRatingTier(&tier)) return false; if (max_subsample_region_size_ == 0) {
// Subtract RESOURCE_RATING_TIER_MIN to get a 0-based index into the table. uint32_t tier = 0;
const uint32_t index = tier - RESOURCE_RATING_TIER_MIN; if (GetResourceRatingTier(&tier)) {
if (index >= ArraySize(kMaxSubsampleRegionSizes)) return false; // Subtract RESOURCE_RATING_TIER_MIN to get a 0-based index into the
*max = kMaxSubsampleRegionSizes[index]; // table.
return true; const uint32_t index = tier - RESOURCE_RATING_TIER_MIN;
if (index < ArraySize(kMaxSubsampleRegionSizes)) {
max_subsample_region_size_ = kMaxSubsampleRegionSizes[index];
}
}
// If something went wrong, use the default.
if (max_subsample_region_size_ == 0) {
LOGW("Unable to get maximum subsample region size. Defaulting to %zu.",
kDefaultMaxSubsampleRegionSize);
max_subsample_region_size_ = kDefaultMaxSubsampleRegionSize;
}
}
return max_subsample_region_size_;
} }
CdmResponseType CryptoSession::Decrypt( CdmResponseType CryptoSession::Decrypt(
@@ -2723,12 +2738,7 @@ OEMCryptoResult CryptoSession::DecryptSample(
OEMCryptoResult CryptoSession::LegacyDecrypt( OEMCryptoResult CryptoSession::LegacyDecrypt(
const OEMCrypto_SampleDescription& sample, CdmCipherMode cipher_mode, const OEMCrypto_SampleDescription& sample, CdmCipherMode cipher_mode,
const OEMCrypto_CENCEncryptPatternDesc& pattern) { const OEMCrypto_CENCEncryptPatternDesc& pattern) {
size_t max_chunk_size; const size_t max_chunk_size = GetMaxSubsampleRegionSize();
if (!GetMaxSubsampleRegionSize(&max_chunk_size)) {
LOGW("Unable to get maximum subsample region size. Defaulting to 100 KiB.");
max_chunk_size = kDefaultMaximumChunkSize;
}
OEMCryptoResult sts = OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult sts = OEMCrypto_ERROR_NOT_IMPLEMENTED;
// We can be sure this is only called with one subsample containing one // We can be sure this is only called with one subsample containing one