Log cleanup and reformatting for core/ (Part 2-6)
[ Merge of http://go/wvgerrit/83423 ] [ Merge of http://go/wvgerrit/83424 ] [ Merge of http://go/wvgerrit/83425 ] [ Merge of http://go/wvgerrit/83426 ] [ Merge of http://go/wvgerrit/83427 ] Types of cleanup: - Removed function / class prefixes from the logs. - Fixed log string format options to match the types passed - Corrected small spelling mistakes / typos - _Tried_ to make the log format more consistent - Added static_cast<int> conversion on enumerations when logged - Changed several LOGE to LOGW and vice versa - Used LOGE if the triggering condition stops the method/function from completing its task - Used LOGW if the triggering condition changes the expected outcome but does not stop the rest of the method/function's task - Changed several instances of `NULL` to `nullptr` - Ran clang-format on files after cleanup This is part of a larger code quality effort in Widevine DRM. Test: WV linux unittests and WV Android unit tests Bug: 134460638 Bug: 134365840 Bug: 136123217 Change-Id: I958ec70ef99eef95c38dbebd7a1acd62ef304145
This commit is contained in:
@@ -76,9 +76,7 @@ InitializationData::InitializationData(const std::string& type,
|
||||
if (is_cenc()) {
|
||||
bool oec_prefers_entitlements = DetectEntitlementPreference(oec_version);
|
||||
if (!SelectWidevinePssh(data, oec_prefers_entitlements, &data_)) {
|
||||
LOGE(
|
||||
"InitializationData: Unable to select a supported Widevine PSSH "
|
||||
"from the init data.");
|
||||
LOGE("Unable to select a supported Widevine PSSH from the init data");
|
||||
}
|
||||
} else if (is_webm()) {
|
||||
data_ = data;
|
||||
@@ -115,15 +113,11 @@ bool InitializationData::SelectWidevinePssh(const CdmInitData& init_data,
|
||||
// Extract the data payloads from the Widevine PSSHs.
|
||||
std::vector<CdmInitData> pssh_payloads;
|
||||
if (!ExtractWidevinePsshs(init_data, &pssh_payloads)) {
|
||||
LOGE(
|
||||
"InitializationData::SelectWidevinePssh: Unable to parse concatenated "
|
||||
"PSSH boxes.");
|
||||
LOGE("Unable to parse concatenated PSSH boxes");
|
||||
return false;
|
||||
}
|
||||
if (pssh_payloads.empty()) {
|
||||
LOGE(
|
||||
"InitializationData::SelectWidevinePssh: The concatenated PSSH boxes "
|
||||
"could be parsed, but no Widevine PSSH was found.");
|
||||
LOGE("Widevine PSSH was not found in concatenated PSSH boxes");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -133,10 +127,7 @@ bool InitializationData::SelectWidevinePssh(const CdmInitData& init_data,
|
||||
for (size_t i = 0; i < pssh_payloads.size(); ++i) {
|
||||
WidevinePsshData pssh;
|
||||
if (!pssh.ParseFromString(pssh_payloads[i])) {
|
||||
LOGE(
|
||||
"InitializationData::SelectWidevinePssh: Unable to parse PSSH data "
|
||||
"%lu into a protobuf.",
|
||||
i);
|
||||
LOGE("Unable to parse PSSH data into a protobuf: index = %zu", i);
|
||||
continue;
|
||||
}
|
||||
if (pssh.type() == WidevinePsshData_Type_ENTITLED_KEY) {
|
||||
@@ -168,8 +159,8 @@ bool InitializationData::SelectWidevinePssh(const CdmInitData& init_data,
|
||||
|
||||
bool InitializationData::ExtractWidevinePsshs(const CdmInitData& init_data,
|
||||
std::vector<CdmInitData>* psshs) {
|
||||
if (psshs == NULL) {
|
||||
LOGE("InitializationData::ExtractWidevinePsshs: NULL psshs parameter");
|
||||
if (psshs == nullptr) {
|
||||
LOGE("Output parameter |psshs| not provided");
|
||||
return false;
|
||||
}
|
||||
psshs->clear();
|
||||
@@ -180,23 +171,23 @@ bool InitializationData::ExtractWidevinePsshs(const CdmInitData& init_data,
|
||||
BufferReader reader(data_start, init_data.length());
|
||||
|
||||
while (!reader.IsEOF()) {
|
||||
// LOGV is used intentionally as it is expected that the CDM will try
|
||||
// several PSSHs until it finds the correct one.
|
||||
// See b/23419359 for more information.
|
||||
|
||||
const size_t start_pos = reader.pos();
|
||||
|
||||
// Atom size. Used for bounding the inner reader and knowing how far to skip
|
||||
// forward after parsing this PSSH.
|
||||
uint64_t size;
|
||||
if (!reader.Read4Into8(&size)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshs: Unable to read the "
|
||||
"32-bit atom size.");
|
||||
LOGV("Unable to read the 32-bit atom size");
|
||||
return false; // We cannot continue reading safely. Abort.
|
||||
}
|
||||
|
||||
// Skip the atom type for now.
|
||||
if (!reader.SkipBytes(4)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshs: Unable to skip the "
|
||||
"atom type.");
|
||||
LOGV("Unable to skip the atom type");
|
||||
return false; // We cannot continue reading safely. Abort.
|
||||
}
|
||||
|
||||
@@ -204,9 +195,7 @@ bool InitializationData::ExtractWidevinePsshs(const CdmInitData& init_data,
|
||||
// An "atom size" of 1 means the real atom size is a 64-bit number stored
|
||||
// after the atom type.
|
||||
if (!reader.Read8(&size)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshs: Unable to read the "
|
||||
"64-bit atom size.");
|
||||
LOGV("Unable to read the 64-bit atom size");
|
||||
return false; // We cannot continue reading safely. Abort.
|
||||
}
|
||||
} else if (size == 0) {
|
||||
@@ -219,8 +208,8 @@ bool InitializationData::ExtractWidevinePsshs(const CdmInitData& init_data,
|
||||
|
||||
if (!reader.HasBytes(bytes_remaining)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshs: Invalid atom size. The "
|
||||
"atom claims to be larger than the remaining init data.");
|
||||
"Invalid atom size: The atom claims to be larger than the "
|
||||
"remaining init data");
|
||||
return false; // We cannot continue reading safely. Abort.
|
||||
}
|
||||
|
||||
@@ -233,9 +222,7 @@ bool InitializationData::ExtractWidevinePsshs(const CdmInitData& init_data,
|
||||
|
||||
// Skip past the rest of the atom.
|
||||
if (!reader.SkipBytes(bytes_remaining)) {
|
||||
LOGV(
|
||||
"InitializationData::LocateWidevinePsshOffsets: Unable to skip the "
|
||||
"rest of the atom.");
|
||||
LOGV("Unable to skip the rest of the atom");
|
||||
return false; // We cannot continue reading safely. Abort.
|
||||
}
|
||||
}
|
||||
@@ -249,15 +236,16 @@ bool InitializationData::ExtractWidevinePsshs(const CdmInitData& init_data,
|
||||
bool InitializationData::ExtractWidevinePsshData(const uint8_t* data,
|
||||
size_t length,
|
||||
CdmInitData* output) {
|
||||
// LOGV is used intentionally as it is expected that the CDM will try
|
||||
// several PSSHs until it finds the correct one.
|
||||
// See b/23419359 for more information.
|
||||
BufferReader reader(data, length);
|
||||
|
||||
// Read the 32-bit size only so we can check if we need to expect a 64-bit
|
||||
// size.
|
||||
uint64_t size_32;
|
||||
if (!reader.Read4Into8(&size_32)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to read the "
|
||||
"32-bit atom size.");
|
||||
LOGV("Unable to read the 32-bit atom size");
|
||||
return false;
|
||||
}
|
||||
const bool has_size_64 = (size_32 == 1);
|
||||
@@ -265,22 +253,18 @@ bool InitializationData::ExtractWidevinePsshData(const uint8_t* data,
|
||||
// Read the atom type and check that it is "pssh".
|
||||
std::vector<uint8_t> atom_type;
|
||||
if (!reader.ReadVec(&atom_type, 4)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to read the atom "
|
||||
"type.");
|
||||
LOGV("Unable to read the atom type");
|
||||
return false;
|
||||
}
|
||||
if (memcmp(&atom_type[0], "pssh", 4) != 0) {
|
||||
LOGV("InitializationData::ExtractWidevinePsshData: Atom type is not PSSH.");
|
||||
LOGV("Atom type is not PSSH");
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there is a 64-bit size, skip it.
|
||||
if (has_size_64) {
|
||||
if (!reader.SkipBytes(8)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to skip the "
|
||||
"64-bit atom size.");
|
||||
LOGV("Unable to skip the 64-bit atom size");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -288,39 +272,29 @@ bool InitializationData::ExtractWidevinePsshData(const uint8_t* data,
|
||||
// Read the version number and abort if it is not one we can handle.
|
||||
uint8_t version;
|
||||
if (!reader.Read1(&version)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to read the PSSH "
|
||||
"version.");
|
||||
LOGV("Unable to read the PSSH version");
|
||||
return false;
|
||||
}
|
||||
if (version > 1) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unrecognized PSSH "
|
||||
"version.");
|
||||
LOGV("Unrecognized PSSH version: %d", static_cast<int>(version));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip the flags.
|
||||
if (!reader.SkipBytes(3)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to skip the PSSH "
|
||||
"flags.");
|
||||
LOGV("Unable to skip the PSSH flags");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the System ID and validate that it is the Widevine System ID.
|
||||
std::vector<uint8_t> system_id;
|
||||
if (!reader.ReadVec(&system_id, sizeof(kWidevineSystemId))) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to read the "
|
||||
"system ID.");
|
||||
LOGV("Unable to read the system ID");
|
||||
return false;
|
||||
}
|
||||
if (memcmp(&system_id[0], kWidevineSystemId, sizeof(kWidevineSystemId)) !=
|
||||
0) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Found a non-Widevine "
|
||||
"PSSH.");
|
||||
LOGV("Found a non-Widevine PSSH");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -329,17 +303,13 @@ bool InitializationData::ExtractWidevinePsshData(const uint8_t* data,
|
||||
// Read the number of key IDs so we know how far to skip ahead.
|
||||
uint32_t num_key_ids;
|
||||
if (!reader.Read4(&num_key_ids)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to read the "
|
||||
"number of key IDs.");
|
||||
LOGV("Unable to read the number of key IDs");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip the key IDs.
|
||||
if (!reader.SkipBytes(num_key_ids * 16)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to skip the key "
|
||||
"IDs.");
|
||||
LOGV("Unable to skip the key IDs");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -347,18 +317,14 @@ bool InitializationData::ExtractWidevinePsshData(const uint8_t* data,
|
||||
// Read the size of the PSSH data.
|
||||
uint32_t data_length;
|
||||
if (!reader.Read4(&data_length)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to read the PSSH "
|
||||
"data size.");
|
||||
LOGV("Unable to read the PSSH data size");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the PSSH data.
|
||||
output->clear();
|
||||
if (!reader.ReadString(output, data_length)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractWidevinePsshData: Unable to read the PSSH "
|
||||
"data.");
|
||||
LOGV("Unable to read the PSSH data");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -383,20 +349,18 @@ bool InitializationData::ExtractHlsAttributes(const std::string& attribute_list,
|
||||
CdmHlsMethod* method,
|
||||
std::vector<uint8_t>* iv,
|
||||
std::string* uri) {
|
||||
// LOGV is used intentionally as it is expected that the CDM will try
|
||||
// several PSSHs until it finds the correct one.
|
||||
// See b/23419359 for more information.
|
||||
std::string value;
|
||||
if (!ExtractQuotedAttribute(attribute_list, HLS_KEYFORMAT_ATTRIBUTE,
|
||||
&value)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractHlsInitDataAtttribute: Unable to read HLS "
|
||||
"keyformat value");
|
||||
LOGV("Unable to read HLS 'keyformat' value");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.compare(0, sizeof(KEY_SYSTEM) - 1, KEY_SYSTEM) != 0) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractHlsInitDataAtttribute: unrecognized HLS "
|
||||
"keyformat value: %s",
|
||||
value.c_str());
|
||||
LOGV("Unrecognized HLS 'keyformat' value: %s", value.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -413,18 +377,14 @@ bool InitializationData::ExtractHlsAttributes(const std::string& attribute_list,
|
||||
}
|
||||
}
|
||||
if (!supported) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractHlsInitDataAtttribute: HLS keyformat "
|
||||
"version is not supported: %s",
|
||||
value.c_str());
|
||||
LOGV("HLS 'keyformat' version is not supported: value = %s",
|
||||
value.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ExtractAttribute(attribute_list, HLS_METHOD_ATTRIBUTE, &value)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractHlsInitDataAtttribute: Unable to read HLS "
|
||||
"method");
|
||||
LOGV("Unable to read HLS method");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -435,24 +395,17 @@ bool InitializationData::ExtractHlsAttributes(const std::string& attribute_list,
|
||||
} else if (value.compare(HLS_METHOD_NONE) == 0) {
|
||||
*method = kHlsMethodNone;
|
||||
} else {
|
||||
LOGV(
|
||||
"InitializationData::ExtractHlsInitDataAtttribute: HLS method "
|
||||
"unrecognized: %s",
|
||||
value.c_str());
|
||||
LOGV("HLS method unrecognized: value = %s", value.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ExtractHexAttribute(attribute_list, HLS_IV_ATTRIBUTE, iv)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractHlsInitDataAtttribute: HLS IV attribute "
|
||||
"not present");
|
||||
LOGV("HLS IV attribute not present");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ExtractQuotedAttribute(attribute_list, HLS_URI_ATTRIBUTE, uri)) {
|
||||
LOGV(
|
||||
"InitializationData::ExtractHlsInitDataAtttribute: HLS URI attribute "
|
||||
"not present");
|
||||
LOGV("HLS URI attribute not present");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -476,31 +429,27 @@ bool InitializationData::ExtractHlsAttributes(const std::string& attribute_list,
|
||||
bool InitializationData::ConstructWidevineInitData(
|
||||
CdmHlsMethod method, const std::string& uri, CdmInitData* init_data_proto) {
|
||||
if (!init_data_proto) {
|
||||
LOGV("InitializationData::ConstructWidevineInitData: Invalid parameter");
|
||||
LOGE("Output parameter |init_data_proto| not provided");
|
||||
return false;
|
||||
}
|
||||
if (method != kHlsMethodAes128 && method != kHlsMethodSampleAes) {
|
||||
LOGV(
|
||||
"InitializationData::ConstructWidevineInitData: Invalid method"
|
||||
" parameter");
|
||||
LOGE("Invalid HLS method parameter");
|
||||
return false;
|
||||
}
|
||||
|
||||
// LOGV is used intentionally as it is expected that the CDM will try
|
||||
// several PSSHs until it finds the correct one.
|
||||
// See b/23419359 for more information.
|
||||
size_t pos = uri.find(kBase64String);
|
||||
if (pos == std::string::npos) {
|
||||
LOGV(
|
||||
"InitializationData::ConstructWidevineInitData: URI attribute "
|
||||
"unexpected format: %s",
|
||||
uri.c_str());
|
||||
LOGV("URI attribute unexpected format: uri = %s", uri.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> json_init_data =
|
||||
Base64Decode(uri.substr(pos + kBase64String.size()));
|
||||
if (json_init_data.size() == 0) {
|
||||
LOGV(
|
||||
"InitializationData::ConstructWidevineInitData: Base64 decode of json "
|
||||
"data failed");
|
||||
LOGV("Base64 decode of json data failed");
|
||||
return false;
|
||||
}
|
||||
std::string json_string((const char*)(&json_init_data[0]),
|
||||
@@ -515,10 +464,7 @@ bool InitializationData::ConstructWidevineInitData(
|
||||
kDefaultNumJsonTokens);
|
||||
|
||||
if (num_of_tokens <= 0) {
|
||||
LOGV(
|
||||
"InitializationData::ConstructWidevineInitData: Json parsing failed: "
|
||||
"%d",
|
||||
num_of_tokens);
|
||||
LOGV("Json parsing failed: num_of_tokens = %d", num_of_tokens);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -538,9 +484,7 @@ bool InitializationData::ConstructWidevineInitData(
|
||||
// Extract the provider, content_id and key_ids
|
||||
for (int i = 0; i < num_of_tokens; ++i) {
|
||||
if (tokens[i].start < 0 || tokens[i].end < 0) {
|
||||
LOGV(
|
||||
"InitializationData::ConstructWidevineInitData: Invalid start or end "
|
||||
"of token");
|
||||
LOGV("Invalid start and/or end of token");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -593,17 +537,17 @@ bool InitializationData::ConstructWidevineInitData(
|
||||
}
|
||||
|
||||
if (provider.size() == 0) {
|
||||
LOGV("InitializationData::ConstructWidevineInitData: Invalid provider");
|
||||
LOGV("Invalid provider");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (content_id.size() == 0) {
|
||||
LOGV("InitializationData::ConstructWidevineInitData: Invalid content_id");
|
||||
LOGV("Invalid content ID");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key_ids.size() == 0) {
|
||||
LOGV("InitializationData::ConstructWidevineInitData: No key_ids present");
|
||||
LOGV("No key IDs present");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user