tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WidevineUtils.h (2816B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef WidevineUtils_h_
      7 #define WidevineUtils_h_
      8 
      9 #include "content_decryption_module.h"
     10 #include "mozilla/Logging.h"
     11 #include "nsISupportsImpl.h"
     12 #include "nsTArray.h"
     13 #include "stddef.h"
     14 
     15 namespace mozilla {
     16 
     17 #define ENSURE_TRUE(condition, rv)                                   \
     18  {                                                                  \
     19    if (!(condition)) {                                              \
     20      GMP_LOG_DEBUG("ENSURE_TRUE FAILED %s:%d", __FILE__, __LINE__); \
     21      return rv;                                                     \
     22    }                                                                \
     23  }
     24 
     25 #define ENSURE_GMP_SUCCESS(err, rv)                                         \
     26  {                                                                         \
     27    if (GMP_FAILED(err)) {                                                  \
     28      GMP_LOG_DEBUG("ENSURE_GMP_SUCCESS FAILED %s:%d", __FILE__, __LINE__); \
     29      return rv;                                                            \
     30    }                                                                       \
     31  }
     32 
     33 namespace gmp {
     34 class CDMShmemBuffer;
     35 }
     36 class WidevineBuffer;
     37 
     38 // Base class for our cdm::Buffer implementations, so we can tell at runtime
     39 // whether the buffer is a Shmem or non-Shmem buffer.
     40 class CDMBuffer : public cdm::Buffer {
     41 public:
     42  virtual WidevineBuffer* AsArrayBuffer() { return nullptr; }
     43  virtual gmp::CDMShmemBuffer* AsShmemBuffer() { return nullptr; }
     44 };
     45 
     46 class WidevineBuffer : public CDMBuffer {
     47 public:
     48  explicit WidevineBuffer(size_t aSize);
     49  ~WidevineBuffer() override;
     50  void Destroy() override;
     51  uint32_t Capacity() const override;
     52  uint8_t* Data() override;
     53  void SetSize(uint32_t aSize) override;
     54  uint32_t Size() const override;
     55 
     56  // Moves contents of buffer out into temporary.
     57  // Note: This empties the buffer.
     58  nsTArray<uint8_t> ExtractBuffer();
     59 
     60  WidevineBuffer* AsArrayBuffer() override { return this; }
     61 
     62 private:
     63  nsTArray<uint8_t> mBuffer;
     64  WidevineBuffer(const WidevineBuffer&);
     65  void operator=(const WidevineBuffer&);
     66 };
     67 
     68 class WidevineDecryptedBlock : public cdm::DecryptedBlock {
     69 public:
     70  WidevineDecryptedBlock();
     71  ~WidevineDecryptedBlock() override;
     72  void SetDecryptedBuffer(cdm::Buffer* aBuffer) override;
     73  cdm::Buffer* DecryptedBuffer() override;
     74  void SetTimestamp(int64_t aTimestamp) override;
     75  int64_t Timestamp() const override;
     76 
     77 private:
     78  cdm::Buffer* mBuffer;
     79  int64_t mTimestamp;
     80 };
     81 
     82 }  // namespace mozilla
     83 
     84 #endif  // WidevineUtils_h_