# HG changeset patch # User Sylvestre Ledru # Date 1542633937 0 # Node ID 0ceae9db9ec0be18daa1a279511ad305723185d4 # Parent 4e4b190e0e1e1186d7301d3dd08daf4919d8192e Bug 1204606 - Reformat of dom/media r=jya # skip-blame Differential Revision: https://phabricator.services.mozilla.com/D12251 diff --git a/dom/media/fake-cdm/cdm-fake.cpp b/dom/media/fake-cdm/cdm-fake.cpp --- a/dom/media/fake-cdm/cdm-fake.cpp +++ b/dom/media/fake-cdm/cdm-fake.cpp @@ -36,37 +36,29 @@ #include "stddef.h" #include "cdm-test-decryptor.h" #include "content_decryption_module.h" #include "content_decryption_module_ext.h" extern "C" { CDM_API -void INITIALIZE_CDM_MODULE() { - -} +void INITIALIZE_CDM_MODULE() {} CDM_API -void* CreateCdmInstance(int cdm_interface_version, - const char* key_system, +void* CreateCdmInstance(int cdm_interface_version, const char* key_system, uint32_t key_system_size, - GetCdmHostFunc get_cdm_host_func, - void* user_data) -{ + GetCdmHostFunc get_cdm_host_func, void* user_data) { if (cdm_interface_version != cdm::ContentDecryptionModule_9::kVersion) { // Only support CDM version 9 currently. return nullptr; } cdm::Host_9* host = static_cast( - get_cdm_host_func(cdm_interface_version, user_data)); + get_cdm_host_func(cdm_interface_version, user_data)); return new FakeDecryptor(host); } - CDM_API -bool -VerifyCdmHost_0(const cdm::HostFile* aHostFiles, uint32_t aNumFiles) -{ +bool VerifyCdmHost_0(const cdm::HostFile* aHostFiles, uint32_t aNumFiles) { return true; } -} // extern "C" +} // extern "C" diff --git a/dom/media/fake-cdm/cdm-test-decryptor.cpp b/dom/media/fake-cdm/cdm-test-decryptor.cpp --- a/dom/media/fake-cdm/cdm-test-decryptor.cpp +++ b/dom/media/fake-cdm/cdm-test-decryptor.cpp @@ -20,17 +20,17 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" using namespace std; FakeDecryptor* FakeDecryptor::sInstance = nullptr; class TestManager { -public: + public: TestManager() = default; // Register a test with the test manager. void BeginTest(const string& aTestID) { std::lock_guard lock(mMutex); auto found = mTestIDs.find(aTestID); if (found == mTestIDs.end()) { mTestIDs.insert(aTestID); @@ -56,253 +56,231 @@ public: } } if (isEmpty) { Finish(); delete this; } } -private: + private: ~TestManager() = default; - static void Error(const string& msg) { - FakeDecryptor::Message(msg); - } + static void Error(const string& msg) { FakeDecryptor::Message(msg); } - static void Finish() { - FakeDecryptor::Message("test-storage complete"); - } + static void Finish() { FakeDecryptor::Message("test-storage complete"); } std::mutex mMutex; set mTestIDs; }; -FakeDecryptor::FakeDecryptor(cdm::Host_9* aHost) - : mHost(aHost) -{ +FakeDecryptor::FakeDecryptor(cdm::Host_9* aHost) : mHost(aHost) { MOZ_ASSERT(!sInstance); sInstance = this; } -void -FakeDecryptor::Message(const std::string& aMessage) -{ +void FakeDecryptor::Message(const std::string& aMessage) { MOZ_ASSERT(sInstance); const static std::string sid("fake-session-id"); - sInstance->mHost->OnSessionMessage(sid.c_str(), - sid.size(), + sInstance->mHost->OnSessionMessage(sid.c_str(), sid.size(), cdm::MessageType::kLicenseRequest, - aMessage.c_str(), - aMessage.size()); + aMessage.c_str(), aMessage.size()); } -std::vector -Tokenize(const std::string& aString) -{ +std::vector Tokenize(const std::string& aString) { std::stringstream strstr(aString); std::istream_iterator it(strstr), end; return std::vector(it, end); } static const string TruncateRecordId = "truncate-record-id"; static const string TruncateRecordData = "I will soon be truncated"; -template +template class WriteRecordSuccessTask { -public: + public: WriteRecordSuccessTask(string aId, Continuation aThen) - : mId(aId) - , mThen(move(aThen)) - {} + : mId(aId), mThen(move(aThen)) {} - void operator()() - { - ReadRecord(FakeDecryptor::sInstance->mHost, mId, mThen); - } + void operator()() { ReadRecord(FakeDecryptor::sInstance->mHost, mId, mThen); } string mId; Continuation mThen; }; class WriteRecordFailureTask { -public: + public: explicit WriteRecordFailureTask(const string& aMessage, TestManager* aTestManager = nullptr, const string& aTestID = "") - : mMessage(aMessage), mTestmanager(aTestManager), mTestID(aTestID) {} + : mMessage(aMessage), mTestmanager(aTestManager), mTestID(aTestID) {} - void operator()() - { + void operator()() { FakeDecryptor::Message(mMessage); if (mTestmanager) { mTestmanager->EndTest(mTestID); } } -private: + private: string mMessage; TestManager* const mTestmanager; const string mTestID; }; class TestEmptyContinuation : public ReadContinuation { -public: + public: TestEmptyContinuation(TestManager* aTestManager, const string& aTestID) - : mTestmanager(aTestManager), mTestID(aTestID) {} + : mTestmanager(aTestManager), mTestID(aTestID) {} - virtual void operator()(bool aSuccess, - const uint8_t* aData, - uint32_t aDataSize) override - { + virtual void operator()(bool aSuccess, const uint8_t* aData, + uint32_t aDataSize) override { if (aDataSize) { - FakeDecryptor::Message("FAIL TestEmptyContinuation record was not truncated"); + FakeDecryptor::Message( + "FAIL TestEmptyContinuation record was not truncated"); } mTestmanager->EndTest(mTestID); } -private: + private: TestManager* const mTestmanager; const string mTestID; }; class TruncateContinuation : public ReadContinuation { -public: - TruncateContinuation(const string& aID, - TestManager* aTestManager, + public: + TruncateContinuation(const string& aID, TestManager* aTestManager, const string& aTestID) - : mID(aID), mTestmanager(aTestManager), mTestID(aTestID) {} + : mID(aID), mTestmanager(aTestManager), mTestID(aTestID) {} - virtual void operator()(bool aSuccess, - const uint8_t* aData, - uint32_t aDataSize) override - { - if (string(reinterpret_cast(aData), aDataSize) != TruncateRecordData) { - FakeDecryptor::Message("FAIL TruncateContinuation read data doesn't match written data"); + virtual void operator()(bool aSuccess, const uint8_t* aData, + uint32_t aDataSize) override { + if (string(reinterpret_cast(aData), aDataSize) != + TruncateRecordData) { + FakeDecryptor::Message( + "FAIL TruncateContinuation read data doesn't match written data"); } auto cont = TestEmptyContinuation(mTestmanager, mTestID); auto msg = "FAIL in TruncateContinuation write."; WriteRecord(FakeDecryptor::sInstance->mHost, mID, nullptr, 0, WriteRecordSuccessTask(mID, cont), WriteRecordFailureTask(msg, mTestmanager, mTestID)); } -private: + private: const string mID; TestManager* const mTestmanager; const string mTestID; }; class VerifyAndFinishContinuation : public ReadContinuation { -public: - explicit VerifyAndFinishContinuation(string aValue, - TestManager* aTestManager, + public: + explicit VerifyAndFinishContinuation(string aValue, TestManager* aTestManager, const string& aTestID) - : mValue(aValue), mTestmanager(aTestManager), mTestID(aTestID) {} + : mValue(aValue), mTestmanager(aTestManager), mTestID(aTestID) {} - virtual void operator()(bool aSuccess, - const uint8_t* aData, - uint32_t aDataSize) override - { + virtual void operator()(bool aSuccess, const uint8_t* aData, + uint32_t aDataSize) override { if (string(reinterpret_cast(aData), aDataSize) != mValue) { - FakeDecryptor::Message("FAIL VerifyAndFinishContinuation read data doesn't match expected data"); + FakeDecryptor::Message( + "FAIL VerifyAndFinishContinuation read data doesn't match expected " + "data"); } mTestmanager->EndTest(mTestID); } -private: + private: string mValue; TestManager* const mTestmanager; const string mTestID; }; class VerifyAndOverwriteContinuation : public ReadContinuation { -public: + public: VerifyAndOverwriteContinuation(string aId, string aValue, string aOverwrite, - TestManager* aTestManager, const string& aTestID) - : mId(aId) - , mValue(aValue) - , mOverwrite(aOverwrite) - , mTestmanager(aTestManager) - , mTestID(aTestID) - {} + TestManager* aTestManager, + const string& aTestID) + : mId(aId), + mValue(aValue), + mOverwrite(aOverwrite), + mTestmanager(aTestManager), + mTestID(aTestID) {} - virtual void operator()(bool aSuccess, - const uint8_t* aData, - uint32_t aDataSize) override - { + virtual void operator()(bool aSuccess, const uint8_t* aData, + uint32_t aDataSize) override { if (string(reinterpret_cast(aData), aDataSize) != mValue) { - FakeDecryptor::Message("FAIL VerifyAndOverwriteContinuation read data doesn't match expected data"); + FakeDecryptor::Message( + "FAIL VerifyAndOverwriteContinuation read data doesn't match " + "expected data"); } auto cont = VerifyAndFinishContinuation(mOverwrite, mTestmanager, mTestID); auto msg = "FAIL in VerifyAndOverwriteContinuation write."; WriteRecord(FakeDecryptor::sInstance->mHost, mId, mOverwrite, WriteRecordSuccessTask(mId, cont), WriteRecordFailureTask(msg, mTestmanager, mTestID)); } -private: + private: string mId; string mValue; string mOverwrite; TestManager* const mTestmanager; const string mTestID; }; static const string OpenAgainRecordId = "open-again-record-id"; class OpenedSecondTimeContinuation : public OpenContinuation { -public: + public: explicit OpenedSecondTimeContinuation(TestManager* aTestManager, const string& aTestID) - : mTestmanager(aTestManager), mTestID(aTestID) - { - } + : mTestmanager(aTestManager), mTestID(aTestID) {} void operator()(bool aSuccess) override { if (!aSuccess) { - FakeDecryptor::Message("FAIL OpenSecondTimeContinuation should not be able to re-open record."); + FakeDecryptor::Message( + "FAIL OpenSecondTimeContinuation should not be able to re-open " + "record."); } // Succeeded, open should have failed. mTestmanager->EndTest(mTestID); } -private: + private: TestManager* const mTestmanager; const string mTestID; }; class OpenedFirstTimeContinuation : public OpenContinuation { -public: - OpenedFirstTimeContinuation(const string& aID, - TestManager* aTestManager, + public: + OpenedFirstTimeContinuation(const string& aID, TestManager* aTestManager, const string& aTestID) - : mID(aID), mTestmanager(aTestManager), mTestID(aTestID) {} + : mID(aID), mTestmanager(aTestManager), mTestID(aTestID) {} void operator()(bool aSuccess) override { if (!aSuccess) { - FakeDecryptor::Message("FAIL OpenAgainContinuation to open record initially."); + FakeDecryptor::Message( + "FAIL OpenAgainContinuation to open record initially."); mTestmanager->EndTest(mTestID); return; } auto cont = OpenedSecondTimeContinuation(mTestmanager, mTestID); OpenRecord(FakeDecryptor::sInstance->mHost, mID, cont); } -private: + private: const string mID; TestManager* const mTestmanager; const string mTestID; }; -static void -DoTestStorage(const string& aPrefix, TestManager* aTestManager) -{ - MOZ_ASSERT(FakeDecryptor::sInstance->mHost, "FakeDecryptor::sInstance->mHost should not be null"); +static void DoTestStorage(const string& aPrefix, TestManager* aTestManager) { + MOZ_ASSERT(FakeDecryptor::sInstance->mHost, + "FakeDecryptor::sInstance->mHost should not be null"); // Basic I/O tests. We run three cases concurrently. The tests, like // CDMStorage run asynchronously. When they've all passed, we send // a message back to the parent process, or a failure message if not. // Test 1: Basic I/O test, and test that writing 0 bytes in a record // deletes record. // // Write data to truncate record, then @@ -328,145 +306,128 @@ DoTestStorage(const string& aPrefix, Tes string id2 = aPrefix + "record1"; string record1 = "This is the first write to a record."; string overwrite = "A shorter record"; const string testID2 = aPrefix + "write-test-2"; aTestManager->BeginTest(testID2); auto task2 = VerifyAndOverwriteContinuation(id2, record1, overwrite, aTestManager, testID2); auto msg2 = "FAIL in TestStorage writing record1."; - WriteRecord(FakeDecryptor::sInstance->mHost, id2, record1, - WriteRecordSuccessTask(id2, task2), - WriteRecordFailureTask(msg2, aTestManager, testID2)); + WriteRecord( + FakeDecryptor::sInstance->mHost, id2, record1, + WriteRecordSuccessTask(id2, task2), + WriteRecordFailureTask(msg2, aTestManager, testID2)); // Test 3: Test that opening a record while it's already open fails. // // Open record1, then // open record1, should fail. // close record1 const string id3 = aPrefix + OpenAgainRecordId; const string testID3 = aPrefix + "open-test-1"; aTestManager->BeginTest(testID3); auto task3 = OpenedFirstTimeContinuation(id3, aTestManager, testID3); OpenRecord(FakeDecryptor::sInstance->mHost, id3, task3); } -void -FakeDecryptor::TestStorage() -{ +void FakeDecryptor::TestStorage() { auto* testManager = new TestManager(); // Main thread tests. DoTestStorage("mt1-", testManager); DoTestStorage("mt2-", testManager); // Note: Once all tests finish, TestManager will dispatch "test-pass" message, // which ends the test for the parent. } -class ReportWritten -{ -public: +class ReportWritten { + public: ReportWritten(const string& aRecordId, const string& aValue) - : mRecordId(aRecordId) - , mValue(aValue) - {} + : mRecordId(aRecordId), mValue(aValue) {} void operator()() { FakeDecryptor::Message("stored " + mRecordId + " " + mValue); } const string mRecordId; const string mValue; }; class ReportReadStatusContinuation : public ReadContinuation { -public: + public: explicit ReportReadStatusContinuation(const string& aRecordId) - : mRecordId(aRecordId) - {} - void operator()(bool aSuccess, - const uint8_t* aData, - uint32_t aDataSize) override - { + : mRecordId(aRecordId) {} + void operator()(bool aSuccess, const uint8_t* aData, + uint32_t aDataSize) override { if (!aSuccess) { FakeDecryptor::Message("retrieve " + mRecordId + " failed"); } else { stringstream ss; ss << aDataSize; string len; ss >> len; FakeDecryptor::Message("retrieve " + mRecordId + " succeeded (length " + len + " bytes)"); } } string mRecordId; }; class ReportReadRecordContinuation : public ReadContinuation { -public: + public: explicit ReportReadRecordContinuation(const string& aRecordId) - : mRecordId(aRecordId) - {} - void operator()(bool aSuccess, - const uint8_t* aData, - uint32_t aDataSize) override - { + : mRecordId(aRecordId) {} + void operator()(bool aSuccess, const uint8_t* aData, + uint32_t aDataSize) override { if (!aSuccess) { FakeDecryptor::Message("retrieved " + mRecordId + " failed"); } else { - FakeDecryptor::Message("retrieved " + mRecordId + " " + - string(reinterpret_cast(aData), - aDataSize)); + FakeDecryptor::Message( + "retrieved " + mRecordId + " " + + string(reinterpret_cast(aData), aDataSize)); } } string mRecordId; }; -enum ShutdownMode { - ShutdownNormal, - ShutdownTimeout, - ShutdownStoreToken -}; +enum ShutdownMode { ShutdownNormal, ShutdownTimeout, ShutdownStoreToken }; static ShutdownMode sShutdownMode = ShutdownNormal; static string sShutdownToken; -void -FakeDecryptor::UpdateSession(uint32_t aPromiseId, - const char* aSessionId, - uint32_t aSessionIdLength, - const uint8_t* aResponse, - uint32_t aResponseSize) -{ - MOZ_ASSERT(FakeDecryptor::sInstance->mHost, "FakeDecryptor::sInstance->mHost should not be null"); - std::string response((const char*)aResponse, (const char*)(aResponse)+aResponseSize); +void FakeDecryptor::UpdateSession(uint32_t aPromiseId, const char* aSessionId, + uint32_t aSessionIdLength, + const uint8_t* aResponse, + uint32_t aResponseSize) { + MOZ_ASSERT(FakeDecryptor::sInstance->mHost, + "FakeDecryptor::sInstance->mHost should not be null"); + std::string response((const char*)aResponse, + (const char*)(aResponse) + aResponseSize); std::vector tokens = Tokenize(response); const string& task = tokens[0]; if (task == "test-storage") { TestStorage(); } else if (task == "store") { - // send "stored record" message on complete. + // send "stored record" message on complete. const string& id = tokens[1]; const string& value = tokens[2]; - WriteRecord(FakeDecryptor::sInstance->mHost, - id, - value, + WriteRecord(FakeDecryptor::sInstance->mHost, id, value, ReportWritten(id, value), WriteRecordFailureTask("FAIL in writing record.")); } else if (task == "retrieve") { const string& id = tokens[1]; - ReadRecord(FakeDecryptor::sInstance->mHost, id, ReportReadStatusContinuation(id)); + ReadRecord(FakeDecryptor::sInstance->mHost, id, + ReportReadStatusContinuation(id)); } else if (task == "shutdown-mode") { const string& mode = tokens[1]; if (mode == "timeout") { sShutdownMode = ShutdownTimeout; } else if (mode == "token") { sShutdownMode = ShutdownStoreToken; sShutdownToken = tokens[2]; Message("shutdown-token received " + sShutdownToken); } } else if (task == "retrieve-shutdown-token") { - ReadRecord(FakeDecryptor::sInstance->mHost, - "shutdown-token", + ReadRecord(FakeDecryptor::sInstance->mHost, "shutdown-token", ReportReadRecordContinuation("shutdown-token")); } else if (task == "test-op-apis") { mozilla::cdmtest::TestOuputProtectionAPIs(); } } diff --git a/dom/media/fake-cdm/cdm-test-decryptor.h b/dom/media/fake-cdm/cdm-test-decryptor.h --- a/dom/media/fake-cdm/cdm-test-decryptor.h +++ b/dom/media/fake-cdm/cdm-test-decryptor.h @@ -6,143 +6,100 @@ #ifndef FAKE_DECRYPTOR_H__ #define FAKE_DECRYPTOR_H__ #include "content_decryption_module.h" #include #include "mozilla/Attributes.h" class FakeDecryptor : public cdm::ContentDecryptionModule_9 { -public: + public: explicit FakeDecryptor(cdm::Host_9* aHost); void Initialize(bool aAllowDistinctiveIdentifier, - bool aAllowPersistentState) override - { - } + bool aAllowPersistentState) override {} void GetStatusForPolicy(uint32_t aPromiseId, - const cdm::Policy& aPolicy) override - { - } + const cdm::Policy& aPolicy) override {} void SetServerCertificate(uint32_t aPromiseId, const uint8_t* aServerCertificateData, - uint32_t aServerCertificateDataSize) - override - { - } + uint32_t aServerCertificateDataSize) override {} void CreateSessionAndGenerateRequest(uint32_t aPromiseId, cdm::SessionType aSessionType, cdm::InitDataType aInitDataType, const uint8_t* aInitData, - uint32_t aInitDataSize) - override - { - } + uint32_t aInitDataSize) override {} - void LoadSession(uint32_t aPromiseId, - cdm::SessionType aSessionType, - const char* aSessionId, - uint32_t aSessionIdSize) override - { - } + void LoadSession(uint32_t aPromiseId, cdm::SessionType aSessionType, + const char* aSessionId, uint32_t aSessionIdSize) override {} - void UpdateSession(uint32_t aPromiseId, - const char* aSessionId, - uint32_t aSessionIdSize, - const uint8_t* aResponse, + void UpdateSession(uint32_t aPromiseId, const char* aSessionId, + uint32_t aSessionIdSize, const uint8_t* aResponse, uint32_t aResponseSize) override; - void CloseSession(uint32_t aPromiseId, - const char* aSessionId, - uint32_t aSessionIdSize) override - { - } + void CloseSession(uint32_t aPromiseId, const char* aSessionId, + uint32_t aSessionIdSize) override {} - void RemoveSession(uint32_t aPromiseId, - const char* aSessionId, - uint32_t aSessionIdSize) override - { - } + void RemoveSession(uint32_t aPromiseId, const char* aSessionId, + uint32_t aSessionIdSize) override {} - void TimerExpired(void* aContext) override - { - } + void TimerExpired(void* aContext) override {} cdm::Status Decrypt(const cdm::InputBuffer_1& aEncryptedBuffer, - cdm::DecryptedBlock* aDecryptedBuffer) override - { + cdm::DecryptedBlock* aDecryptedBuffer) override { return cdm::Status::kDecodeError; } cdm::Status InitializeAudioDecoder( - const cdm::AudioDecoderConfig_1& aAudioDecoderConfig) override - { + const cdm::AudioDecoderConfig_1& aAudioDecoderConfig) override { return cdm::Status::kDecodeError; } cdm::Status InitializeVideoDecoder( - const cdm::VideoDecoderConfig_1& aVideoDecoderConfig) override - { + const cdm::VideoDecoderConfig_1& aVideoDecoderConfig) override { return cdm::Status::kDecodeError; } - void DeinitializeDecoder(cdm::StreamType aDecoderType) override - { - } + void DeinitializeDecoder(cdm::StreamType aDecoderType) override {} - void ResetDecoder(cdm::StreamType aDecoderType) override - { - } + void ResetDecoder(cdm::StreamType aDecoderType) override {} cdm::Status DecryptAndDecodeFrame(const cdm::InputBuffer_1& aEncryptedBuffer, - cdm::VideoFrame* aVideoFrame) override - { + cdm::VideoFrame* aVideoFrame) override { return cdm::Status::kDecodeError; } cdm::Status DecryptAndDecodeSamples( - const cdm::InputBuffer_1& aEncryptedBuffer, - cdm::AudioFrames* aAudioFrame) override - { + const cdm::InputBuffer_1& aEncryptedBuffer, + cdm::AudioFrames* aAudioFrame) override { return cdm::Status::kDecodeError; } void OnPlatformChallengeResponse( - const cdm::PlatformChallengeResponse& aResponse) override - { - } + const cdm::PlatformChallengeResponse& aResponse) override {} void OnQueryOutputProtectionStatus(cdm::QueryResult aResult, uint32_t aLinkMask, - uint32_t aOutputProtectionMask) override - { - } + uint32_t aOutputProtectionMask) override {} - void OnStorageId(uint32_t aVersion, - const uint8_t* aStorageId, - uint32_t aStorageIdSize) override - { - } + void OnStorageId(uint32_t aVersion, const uint8_t* aStorageId, + uint32_t aStorageIdSize) override {} - void Destroy() override - { + void Destroy() override { delete this; sInstance = nullptr; } static void Message(const std::string& aMessage); cdm::Host_9* mHost; static FakeDecryptor* sInstance; -private: - + private: virtual ~FakeDecryptor() {} void TestStorage(); - }; #endif diff --git a/dom/media/fake-cdm/cdm-test-output-protection.h b/dom/media/fake-cdm/cdm-test-output-protection.h --- a/dom/media/fake-cdm/cdm-test-output-protection.h +++ b/dom/media/fake-cdm/cdm-test-output-protection.h @@ -1,74 +1,75 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #if defined(XP_WIN) -#include // needed to prevent re-definition of enums +#include // needed to prevent re-definition of enums #include #include #include #include #include "opmapi.h" #endif namespace mozilla { namespace cdmtest { #if defined(XP_WIN) -typedef HRESULT(STDAPICALLTYPE * OPMGetVideoOutputsFromHMONITORProc) - (HMONITOR, OPM_VIDEO_OUTPUT_SEMANTICS, ULONG*, IOPMVideoOutput***); +typedef HRESULT(STDAPICALLTYPE* OPMGetVideoOutputsFromHMONITORProc)( + HMONITOR, OPM_VIDEO_OUTPUT_SEMANTICS, ULONG*, IOPMVideoOutput***); -static OPMGetVideoOutputsFromHMONITORProc sOPMGetVideoOutputsFromHMONITORProc = nullptr; +static OPMGetVideoOutputsFromHMONITORProc sOPMGetVideoOutputsFromHMONITORProc = + nullptr; static BOOL CALLBACK EnumDisplayMonitorsCallback(HMONITOR hMonitor, HDC hdc, - LPRECT lprc, LPARAM pData) -{ + LPRECT lprc, LPARAM pData) { std::vector* failureMsgs = (std::vector*)pData; MONITORINFOEXA miex; ZeroMemory(&miex, sizeof(miex)); miex.cbSize = sizeof(miex); if (!GetMonitorInfoA(hMonitor, &miex)) { failureMsgs->push_back("FAIL GetMonitorInfoA call failed"); } ULONG numVideoOutputs = 0; IOPMVideoOutput** opmVideoOutputArray = nullptr; - HRESULT hr = sOPMGetVideoOutputsFromHMONITORProc(hMonitor, - OPM_VOS_OPM_SEMANTICS, - &numVideoOutputs, - &opmVideoOutputArray); + HRESULT hr = sOPMGetVideoOutputsFromHMONITORProc( + hMonitor, OPM_VOS_OPM_SEMANTICS, &numVideoOutputs, &opmVideoOutputArray); if (S_OK != hr) { - if ((HRESULT)0x8007001f != hr && (HRESULT)0x80070032 != hr && (HRESULT)0xc02625e5 != hr) { + if ((HRESULT)0x8007001f != hr && (HRESULT)0x80070032 != hr && + (HRESULT)0xc02625e5 != hr) { char msg[100]; - sprintf(msg, "FAIL OPMGetVideoOutputsFromHMONITOR call failed: HRESULT=0x%08lx", hr); + sprintf( + msg, + "FAIL OPMGetVideoOutputsFromHMONITOR call failed: HRESULT=0x%08lx", + hr); failureMsgs->push_back(msg); } return true; } DISPLAY_DEVICEA dd; ZeroMemory(&dd, sizeof(dd)); dd.cb = sizeof(dd); if (!EnumDisplayDevicesA(miex.szDevice, 0, &dd, 1)) { failureMsgs->push_back("FAIL EnumDisplayDevicesA call failed"); } for (ULONG i = 0; i < numVideoOutputs; ++i) { OPM_RANDOM_NUMBER opmRandomNumber; BYTE* certificate = nullptr; ULONG certificateLength = 0; - hr = opmVideoOutputArray[i]->StartInitialization(&opmRandomNumber, - &certificate, - &certificateLength); + hr = opmVideoOutputArray[i]->StartInitialization( + &opmRandomNumber, &certificate, &certificateLength); if (S_OK != hr) { char msg[100]; sprintf(msg, "FAIL StartInitialization call failed: HRESULT=0x%08lx", hr); failureMsgs->push_back(msg); } if (certificate) { CoTaskMemFree(certificate); @@ -80,50 +81,48 @@ static BOOL CALLBACK EnumDisplayMonitors if (opmVideoOutputArray) { CoTaskMemFree(opmVideoOutputArray); } return true; } #endif -static void -RunOutputProtectionAPITests() -{ +static void RunOutputProtectionAPITests() { #if defined(XP_WIN) // Get hold of OPMGetVideoOutputsFromHMONITOR function. HMODULE hDvax2DLL = GetModuleHandleW(L"dxva2.dll"); if (!hDvax2DLL) { FakeDecryptor::Message("FAIL GetModuleHandleW call failed for dxva2.dll"); return; } - sOPMGetVideoOutputsFromHMONITORProc = (OPMGetVideoOutputsFromHMONITORProc) - GetProcAddress(hDvax2DLL, "OPMGetVideoOutputsFromHMONITOR"); + sOPMGetVideoOutputsFromHMONITORProc = + (OPMGetVideoOutputsFromHMONITORProc)GetProcAddress( + hDvax2DLL, "OPMGetVideoOutputsFromHMONITOR"); if (!sOPMGetVideoOutputsFromHMONITORProc) { - FakeDecryptor::Message("FAIL GetProcAddress call failed for OPMGetVideoOutputsFromHMONITOR"); + FakeDecryptor::Message( + "FAIL GetProcAddress call failed for OPMGetVideoOutputsFromHMONITOR"); return; } // Test EnumDisplayMonitors. // Other APIs are tested in the callback function. std::vector failureMsgs; if (!EnumDisplayMonitors(NULL, NULL, EnumDisplayMonitorsCallback, - (LPARAM) &failureMsgs)) { + (LPARAM)&failureMsgs)) { FakeDecryptor::Message("FAIL EnumDisplayMonitors call failed"); } // Report any failures in the callback function. for (size_t i = 0; i < failureMsgs.size(); i++) { FakeDecryptor::Message(failureMsgs[i]); } #endif } -static void -TestOuputProtectionAPIs() -{ +static void TestOuputProtectionAPIs() { RunOutputProtectionAPITests(); FakeDecryptor::Message("OP tests completed"); } -} // namespace cdmtest -} // namespace mozilla +} // namespace cdmtest +} // namespace mozilla diff --git a/dom/media/fake-cdm/cdm-test-storage.cpp b/dom/media/fake-cdm/cdm-test-storage.cpp --- a/dom/media/fake-cdm/cdm-test-storage.cpp +++ b/dom/media/fake-cdm/cdm-test-storage.cpp @@ -7,60 +7,47 @@ #include #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" using namespace cdm; using namespace std; -class WriteRecordClient : public FileIOClient -{ -public: +class WriteRecordClient : public FileIOClient { + public: WriteRecordClient(function&& aOnSuccess, - function&& aOnFailure, - const uint8_t* aData, + function&& aOnFailure, const uint8_t* aData, uint32_t aDataSize) - : mOnSuccess(move(aOnSuccess)) - , mOnFailure(move(aOnFailure)) - { + : mOnSuccess(move(aOnSuccess)), mOnFailure(move(aOnFailure)) { mData.insert(mData.end(), aData, aData + aDataSize); } - void OnOpenComplete(Status aStatus) override - { + void OnOpenComplete(Status aStatus) override { // If we hit an error, fail. if (aStatus != Status::kSuccess) { Done(aStatus); - } else if (mFileIO) { // Otherwise, write our data to the file. + } else if (mFileIO) { // Otherwise, write our data to the file. mFileIO->Write(mData.empty() ? nullptr : &mData.front(), mData.size()); } } - void OnReadComplete(Status aStatus, - const uint8_t* aData, - uint32_t aDataSize) override - { - } + void OnReadComplete(Status aStatus, const uint8_t* aData, + uint32_t aDataSize) override {} - void OnWriteComplete(Status aStatus) override - { - Done(aStatus); - } + void OnWriteComplete(Status aStatus) override { Done(aStatus); } - void Do(const string& aName, Host_9* aHost) - { + void Do(const string& aName, Host_9* aHost) { // Initialize the FileIO. mFileIO = aHost->CreateFileIO(this); mFileIO->Open(aName.c_str(), aName.size()); } -private: - void Done(cdm::FileIOClient::Status aStatus) - { + private: + void Done(cdm::FileIOClient::Status aStatus) { // Note: Call Close() before running continuation, in case the // continuation tries to open the same record; if we call Close() // after running the continuation, the Close() call will arrive // just after the Open() call succeeds, immediately closing the // record we just opened. if (mFileIO) { // will delete mFileIO inside Close. mFileIO->Close(); @@ -76,87 +63,62 @@ private: } FileIO* mFileIO = nullptr; function mOnSuccess; function mOnFailure; std::vector mData; }; -void -WriteRecord(Host_9* aHost, - const std::string& aRecordName, - const uint8_t* aData, - uint32_t aNumBytes, - function&& aOnSuccess, - function&& aOnFailure) -{ +void WriteRecord(Host_9* aHost, const std::string& aRecordName, + const uint8_t* aData, uint32_t aNumBytes, + function&& aOnSuccess, function&& aOnFailure) { // client will be delete in WriteRecordClient::Done - WriteRecordClient* client = new WriteRecordClient(move(aOnSuccess), - move(aOnFailure), - aData, - aNumBytes); + WriteRecordClient* client = new WriteRecordClient( + move(aOnSuccess), move(aOnFailure), aData, aNumBytes); client->Do(aRecordName, aHost); } -void -WriteRecord(Host_9* aHost, - const std::string& aRecordName, - const std::string& aData, - function &&aOnSuccess, - function&& aOnFailure) -{ - return WriteRecord(aHost, - aRecordName, - (const uint8_t*)aData.c_str(), - aData.size(), - move(aOnSuccess), - move(aOnFailure)); +void WriteRecord(Host_9* aHost, const std::string& aRecordName, + const std::string& aData, function&& aOnSuccess, + function&& aOnFailure) { + return WriteRecord(aHost, aRecordName, (const uint8_t*)aData.c_str(), + aData.size(), move(aOnSuccess), move(aOnFailure)); } -class ReadRecordClient : public FileIOClient -{ -public: - explicit ReadRecordClient(function&& aOnReadComplete) - : mOnReadComplete(move(aOnReadComplete)) - { - } +class ReadRecordClient : public FileIOClient { + public: + explicit ReadRecordClient( + function&& aOnReadComplete) + : mOnReadComplete(move(aOnReadComplete)) {} - void OnOpenComplete(Status aStatus) override - { + void OnOpenComplete(Status aStatus) override { auto err = aStatus; if (aStatus != Status::kSuccess) { Done(err, reinterpret_cast(""), 0); } else { mFileIO->Read(); } } - void OnReadComplete(Status aStatus, - const uint8_t* aData, - uint32_t aDataSize) override - { + void OnReadComplete(Status aStatus, const uint8_t* aData, + uint32_t aDataSize) override { Done(aStatus, aData, aDataSize); } - void OnWriteComplete(Status aStatus) override - { - } + void OnWriteComplete(Status aStatus) override {} - void Do(const string& aName, Host_9* aHost) - { + void Do(const string& aName, Host_9* aHost) { mFileIO = aHost->CreateFileIO(this); mFileIO->Open(aName.c_str(), aName.size()); } -private: - void Done(cdm::FileIOClient::Status aStatus, - const uint8_t* aData, - uint32_t aDataSize) - { + private: + void Done(cdm::FileIOClient::Status aStatus, const uint8_t* aData, + uint32_t aDataSize) { // Note: Call Close() before running continuation, in case the // continuation tries to open the same record; if we call Close() // after running the continuation, the Close() call will arrive // just after the Open() call succeeds, immediately closing the // record we just opened. if (mFileIO) { // will delete mFileIO inside Close. mFileIO->Close(); @@ -170,59 +132,44 @@ private: delete this; } FileIO* mFileIO = nullptr; function mOnReadComplete; }; -void -ReadRecord(Host_9* aHost, - const std::string& aRecordName, - function&& aOnReadComplete) -{ +void ReadRecord( + Host_9* aHost, const std::string& aRecordName, + function&& aOnReadComplete) { // client will be delete in ReadRecordClient::Done ReadRecordClient* client = new ReadRecordClient(move(aOnReadComplete)); client->Do(aRecordName, aHost); } -class OpenRecordClient : public FileIOClient -{ -public: +class OpenRecordClient : public FileIOClient { + public: explicit OpenRecordClient(function&& aOpenComplete) - : mOpenComplete(move(aOpenComplete)) - { - } + : mOpenComplete(move(aOpenComplete)) {} - void OnOpenComplete(Status aStatus) override - { - Done(aStatus); - } + void OnOpenComplete(Status aStatus) override { Done(aStatus); } - void OnReadComplete(Status aStatus, - const uint8_t* aData, - uint32_t aDataSize) override - { - } + void OnReadComplete(Status aStatus, const uint8_t* aData, + uint32_t aDataSize) override {} - void OnWriteComplete(Status aStatus) override - { - } + void OnWriteComplete(Status aStatus) override {} - void Do(const string& aName, Host_9* aHost) - { + void Do(const string& aName, Host_9* aHost) { // Initialize the FileIO. mFileIO = aHost->CreateFileIO(this); mFileIO->Open(aName.c_str(), aName.size()); } -private: - void Done(cdm::FileIOClient::Status aStatus) - { + private: + void Done(cdm::FileIOClient::Status aStatus) { // Note: Call Close() before running continuation, in case the // continuation tries to open the same record; if we call Close() // after running the continuation, the Close() call will arrive // just after the Open() call succeeds, immediately closing the // record we just opened. if (mFileIO) { // will delete mFileIO inside Close. mFileIO->Close(); @@ -233,20 +180,18 @@ private: } else { mOpenComplete(false); } delete this; } FileIO* mFileIO = nullptr; - function mOpenComplete;; + function mOpenComplete; + ; }; -void -OpenRecord(Host_9* aHost, - const std::string& aRecordName, - function&& aOpenComplete) -{ +void OpenRecord(Host_9* aHost, const std::string& aRecordName, + function&& aOpenComplete) { // client will be delete in OpenRecordClient::Done OpenRecordClient* client = new OpenRecordClient(move(aOpenComplete)); client->Do(aRecordName, aHost); } diff --git a/dom/media/fake-cdm/cdm-test-storage.h b/dom/media/fake-cdm/cdm-test-storage.h --- a/dom/media/fake-cdm/cdm-test-storage.h +++ b/dom/media/fake-cdm/cdm-test-storage.h @@ -13,42 +13,36 @@ // on Unix systems. #include "stddef.h" #include "content_decryption_module.h" #define IO_SUCCEEDED(x) ((x) == cdm::FileIOClient::Status::kSuccess) #define IO_FAILED(x) ((x) != cdm::FileIOClient::Status::kSuccess) class ReadContinuation { -public: + public: virtual ~ReadContinuation() {} - virtual void operator()(bool aSuccess, - const uint8_t* aData, + virtual void operator()(bool aSuccess, const uint8_t* aData, uint32_t aDataSize) = 0; }; -void WriteRecord(cdm::Host_9* aHost, - const std::string& aRecordName, - const std::string& aData, +void WriteRecord(cdm::Host_9* aHost, const std::string& aRecordName, + const std::string& aData, std::function&& aOnSuccess, + std::function&& aOnFailure); + +void WriteRecord(cdm::Host_9* aHost, const std::string& aRecordName, + const uint8_t* aData, uint32_t aNumBytes, std::function&& aOnSuccess, std::function&& aOnFailure); -void WriteRecord(cdm::Host_9* aHost, - const std::string& aRecordName, - const uint8_t* aData, - uint32_t aNumBytes, - std::function&& aOnSuccess, - std::function&& aOnFailure); - -void ReadRecord(cdm::Host_9* aHost, - const std::string& aRecordName, - std::function&& aOnReadComplete); +void ReadRecord( + cdm::Host_9* aHost, const std::string& aRecordName, + std::function&& aOnReadComplete); class OpenContinuation { -public: + public: virtual ~OpenContinuation() {} virtual void operator()(bool aSuccess) = 0; }; -void OpenRecord(cdm::Host_9* aHost, - const std::string& aRecordName, +void OpenRecord(cdm::Host_9* aHost, const std::string& aRecordName, std::function&& aOpenComplete); -#endif // TEST_CDM_STORAGE_H__ +#endif // TEST_CDM_STORAGE_H__