From 24e4c33262d3e7e3b338434387166ab40bf846e6 Mon Sep 17 00:00:00 2001 From: Rahul Frias Date: Sun, 7 Mar 2021 00:03:17 -0800 Subject: [PATCH] Fix deprecated and printf warnings. [ Merge of http://go/wvgerrit/118703 ] Bug: 182058081 Test: WV unit/integration tests Change-Id: I2d8995b8aab864a2d2f5161d12a473d34e67bad4 --- libwvdrmengine/cdm/core/src/crypto_session.cpp | 7 ++++--- libwvdrmengine/cdm/core/src/initialization_data.cpp | 9 ++++++--- .../cdm/core/test/initialization_data_unittest.cpp | 9 ++++++++- libwvdrmengine/cdm/util/include/log.h | 4 +--- libwvdrmengine/cdm/util/include/util_common.h | 11 +++++++++++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index 45a9f9ee..e8b9a23a 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -7,6 +7,7 @@ #include "crypto_session.h" +#include #include #include @@ -1745,11 +1746,11 @@ CdmResponseType CryptoSession::GenerateUsageReport( static_cast(pst_report.pst_length())); LOGV("OEMCrypto_PST_Report.padding: %d\n", static_cast(pst_report.padding())); - LOGV("OEMCrypto_PST_Report.seconds_since_license_received: %ld\n", + LOGV("OEMCrypto_PST_Report.seconds_since_license_received: %" PRId64 "\n", pst_report.seconds_since_license_received()); - LOGV("OEMCrypto_PST_Report.seconds_since_first_decrypt: %ld\n", + LOGV("OEMCrypto_PST_Report.seconds_since_first_decrypt: %" PRId64 "\n", pst_report.seconds_since_first_decrypt()); - LOGV("OEMCrypto_PST_Report.seconds_since_last_decrypt: %ld\n", + LOGV("OEMCrypto_PST_Report.seconds_since_last_decrypt: %" PRId64 "\n", pst_report.seconds_since_last_decrypt()); LOGV("OEMCrypto_PST_Report: %s\n", b2a_hex(*usage_report).c_str()); diff --git a/libwvdrmengine/cdm/core/src/initialization_data.cpp b/libwvdrmengine/cdm/core/src/initialization_data.cpp index fbacf1a8..a969d67e 100644 --- a/libwvdrmengine/cdm/core/src/initialization_data.cpp +++ b/libwvdrmengine/cdm/core/src/initialization_data.cpp @@ -558,13 +558,16 @@ bool InitializationData::ConstructWidevineInitData( // Now format as Widevine init data protobuf WidevinePsshData cenc_header; - // TODO(rfrias): The algorithm is a deprecated field, but proto changes - // have not yet been pushed to production. Set until then. + // TODO(rfrias): The algorithm and provider are deprecated fields, but proto + // changes have not yet been pushed to production. Set until then. + CORE_UTIL_IGNORE_DEPRECATED cenc_header.set_algorithm(WidevinePsshData_Algorithm_AESCTR); + cenc_header.set_provider(provider); + CORE_UTIL_RESTORE_WARNINGS + for (size_t i = 0; i < key_ids.size(); ++i) { cenc_header.add_key_ids(key_ids[i]); } - cenc_header.set_provider(provider); cenc_header.set_content_id(content_id); if (method == kHlsMethodAes128) cenc_header.set_protection_scheme(kFourCcCbc1); diff --git a/libwvdrmengine/cdm/core/test/initialization_data_unittest.cpp b/libwvdrmengine/cdm/core/test/initialization_data_unittest.cpp index 95356fd3..717a00bc 100644 --- a/libwvdrmengine/cdm/core/test/initialization_data_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/initialization_data_unittest.cpp @@ -716,8 +716,13 @@ TEST_P(HlsConstructionTest, InitData) { if (param.success_) { WidevinePsshData cenc_header; EXPECT_TRUE(cenc_header.ParseFromString(value)); + + CORE_UTIL_IGNORE_DEPRECATED EXPECT_EQ(video_widevine::WidevinePsshData_Algorithm_AESCTR, cenc_header.algorithm()); + EXPECT_EQ(param.provider_, cenc_header.provider()); + CORE_UTIL_RESTORE_WARNINGS + for (size_t i = 0; i < param.key_ids_.size(); ++i) { bool key_id_found = false; if (param.key_ids_[i].size() != 32) continue; @@ -729,7 +734,6 @@ TEST_P(HlsConstructionTest, InitData) { } EXPECT_TRUE(key_id_found); } - EXPECT_EQ(param.provider_, cenc_header.provider()); std::vector param_content_id_vec(Base64Decode(param.content_id_)); EXPECT_EQ( std::string(param_content_id_vec.begin(), param_content_id_vec.end()), @@ -822,6 +826,8 @@ TEST_P(HlsParseTest, Parse) { WidevinePsshData cenc_header; EXPECT_TRUE(cenc_header.ParseFromString(init_data.data())); + + CORE_UTIL_IGNORE_DEPRECATED EXPECT_EQ(video_widevine::WidevinePsshData_Algorithm_AESCTR, cenc_header.algorithm()); if (param.key_.compare(kJsonProvider) == 0) { @@ -831,6 +837,7 @@ TEST_P(HlsParseTest, Parse) { } else if (param.key_.compare(kJsonKeyIds) == 0) { EXPECT_EQ(param.value_, b2a_hex(cenc_header.key_ids(0))); } + CORE_UTIL_RESTORE_WARNINGS EXPECT_EQ(kHlsIvHexValue, b2a_hex(init_data.hls_iv())); } else { diff --git a/libwvdrmengine/cdm/util/include/log.h b/libwvdrmengine/cdm/util/include/log.h index 28791f35..c64c67a8 100644 --- a/libwvdrmengine/cdm/util/include/log.h +++ b/libwvdrmengine/cdm/util/include/log.h @@ -78,9 +78,7 @@ struct LoggingUidSetter { // unit tests. CORE_UTIL_EXPORT void InitLogging(); -// Only enable format specifier warnings on LP64 systems. There is -// no easy portable method to handle format specifiers for int64_t. -#if (defined(__GNUC__) || defined(__clang__)) && defined(__LP64__) +#ifdef __GNUC__ [[gnu::format(printf, 5, 6)]] CORE_UTIL_EXPORT void Log(const char* file, const char* function, int line, diff --git a/libwvdrmengine/cdm/util/include/util_common.h b/libwvdrmengine/cdm/util/include/util_common.h index 4477ca1c..5e7b1661 100644 --- a/libwvdrmengine/cdm/util/include/util_common.h +++ b/libwvdrmengine/cdm/util/include/util_common.h @@ -11,12 +11,23 @@ # else # define CORE_UTIL_EXPORT __declspec(dllimport) # endif +# define CORE_UTIL_IGNORE_DEPRECATED +# define CORE_UTIL_RESTORE_WARNINGS #else # ifdef CORE_UTIL_IMPLEMENTATION # define CORE_UTIL_EXPORT __attribute__((visibility("default"))) # else # define CORE_UTIL_EXPORT # endif +# ifdef __GNUC__ +# define CORE_UTIL_IGNORE_DEPRECATED \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +# define CORE_UTIL_RESTORE_WARNINGS _Pragma("GCC diagnostic pop") +# else +# define CORE_UTIL_IGNORE_DEPRECATED +# define CORE_UTIL_RESTORE_WARNINGS +# endif #endif #endif // WVCDM_UTIL_UTIL_COMMON_H_