WMFDecryptedBlock.h (2207B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef DOM_MEDIA_PLATFORM_WMF_CLEARKEY_WMFDECRYPTEDBLOCK_H 6 #define DOM_MEDIA_PLATFORM_WMF_CLEARKEY_WMFDECRYPTEDBLOCK_H 7 8 #include <vector> 9 10 #include "WMFClearKeyUtils.h" 11 #include "content_decryption_module.h" 12 13 namespace mozilla { 14 15 // This class is used to store the decrypted data. It will be allocated by 16 // `SessionManagerWrapper::Allocate`. 17 class WMFDecryptedBuffer : public cdm::Buffer { 18 public: 19 explicit WMFDecryptedBuffer(size_t aSize) { 20 SetSize(aSize); 21 LOG("WMFDecryptedBuffer ctor %p, sz=%u", this, Size()); 22 } 23 ~WMFDecryptedBuffer() override { 24 LOG("WMFDecryptedBuffer dtor %p, sz=%u", this, Size()); 25 } 26 WMFDecryptedBuffer(const WMFDecryptedBuffer&) = delete; 27 WMFDecryptedBuffer& operator=(const WMFDecryptedBuffer&) = delete; 28 29 // This is not good, but that is how cdm::buffer works. 30 void Destroy() override { delete this; } 31 uint32_t Capacity() const override { return mBuffer.size(); } 32 uint8_t* Data() override { return mBuffer.data(); } 33 void SetSize(uint32_t aSize) override { return mBuffer.resize(aSize); } 34 uint32_t Size() const override { return mBuffer.size(); } 35 36 private: 37 std::vector<uint8_t> mBuffer; 38 }; 39 40 class WMFDecryptedBlock : public cdm::DecryptedBlock { 41 public: 42 WMFDecryptedBlock() : mBuffer(nullptr), mTimestamp(0) { 43 LOG("WMFDecryptedBlock ctor %p", this); 44 } 45 ~WMFDecryptedBlock() override { 46 LOG("WMFDecryptedBlock dtor %p", this); 47 if (mBuffer) { 48 mBuffer->Destroy(); 49 mBuffer = nullptr; 50 } 51 } 52 void SetDecryptedBuffer(cdm::Buffer* aBuffer) override { 53 LOG("WMFDecryptedBlock(%p)::SetDecryptedBuffer, buffer=%p", this, aBuffer); 54 mBuffer = aBuffer; 55 } 56 cdm::Buffer* DecryptedBuffer() override { return mBuffer; } 57 void SetTimestamp(int64_t aTimestamp) override { mTimestamp = aTimestamp; } 58 int64_t Timestamp() const override { return mTimestamp; } 59 60 private: 61 cdm::Buffer* mBuffer; 62 int64_t mTimestamp; 63 }; 64 65 } // namespace mozilla 66 67 #endif // DOM_MEDIA_PLATFORM_WMF_CLEARKEY_WMFDECRYPTEDBLOCK_H