Bug 1874684 - Part 31: Correctly reject invalid durations in some RoundDuration calls...
[gecko.git] / media / wmf-clearkey / WMFDecryptedBlock.h
blob1ffa41e7c97a9f3d21f6ac034b0ae3155d9f6625
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/. */
5 #ifndef DOM_MEDIA_PLATFORM_WMF_CLEARKEY_WMFDECRYPTEDBLOCK_H
6 #define DOM_MEDIA_PLATFORM_WMF_CLEARKEY_WMFDECRYPTEDBLOCK_H
8 #include <vector>
10 #include "WMFClearKeyUtils.h"
11 #include "content_decryption_module.h"
13 namespace mozilla {
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());
23 ~WMFDecryptedBuffer() override {
24 LOG("WMFDecryptedBuffer dtor %p, sz=%u", this, Size());
26 WMFDecryptedBuffer(const WMFDecryptedBuffer&) = delete;
27 WMFDecryptedBuffer& operator=(const WMFDecryptedBuffer&) = delete;
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(); }
36 private:
37 std::vector<uint8_t> mBuffer;
40 class WMFDecryptedBlock : public cdm::DecryptedBlock {
41 public:
42 WMFDecryptedBlock() : mBuffer(nullptr), mTimestamp(0) {
43 LOG("WMFDecryptedBlock ctor %p", this);
45 ~WMFDecryptedBlock() override {
46 LOG("WMFDecryptedBlock dtor %p", this);
47 if (mBuffer) {
48 mBuffer->Destroy();
49 mBuffer = nullptr;
52 void SetDecryptedBuffer(cdm::Buffer* aBuffer) override {
53 LOG("WMFDecryptedBlock(%p)::SetDecryptedBuffer, buffer=%p", this, aBuffer);
54 mBuffer = aBuffer;
56 cdm::Buffer* DecryptedBuffer() override { return mBuffer; }
57 void SetTimestamp(int64_t aTimestamp) override { mTimestamp = aTimestamp; }
58 int64_t Timestamp() const override { return mTimestamp; }
60 private:
61 cdm::Buffer* mBuffer;
62 int64_t mTimestamp;
65 } // namespace mozilla
67 #endif // DOM_MEDIA_PLATFORM_WMF_CLEARKEY_WMFDECRYPTEDBLOCK_H