Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/WidevineUtils.h
Line
Count
Source (jump to first uncovered line)
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 "stddef.h"
10
#include "content_decryption_module.h"
11
#include "nsISupportsImpl.h"
12
#include "nsTArray.h"
13
#include "mozilla/Logging.h"
14
15
namespace mozilla {
16
17
#define ENSURE_TRUE(condition, rv)                                             \
18
  {                                                                            \
19
    if (!(condition)) {                                                        \
20
      GMP_LOG("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("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
{
42
public:
43
0
  virtual WidevineBuffer* AsArrayBuffer() { return nullptr; }
44
0
  virtual gmp::CDMShmemBuffer* AsShmemBuffer() { return nullptr; }
45
};
46
47
class WidevineBuffer : public CDMBuffer
48
{
49
public:
50
  explicit WidevineBuffer(size_t aSize);
51
  ~WidevineBuffer() override;
52
  void Destroy() override;
53
  uint32_t Capacity() const override;
54
  uint8_t* Data() override;
55
  void SetSize(uint32_t aSize) override;
56
  uint32_t Size() const override;
57
58
  // Moves contents of buffer out into temporary.
59
  // Note: This empties the buffer.
60
  nsTArray<uint8_t> ExtractBuffer();
61
62
  WidevineBuffer* AsArrayBuffer() override { return this; }
63
64
private:
65
  nsTArray<uint8_t> mBuffer;
66
  WidevineBuffer(const WidevineBuffer&);
67
  void operator=(const WidevineBuffer&);
68
};
69
70
class WidevineDecryptedBlock : public cdm::DecryptedBlock
71
{
72
public:
73
74
  WidevineDecryptedBlock();
75
  ~WidevineDecryptedBlock() override;
76
  void SetDecryptedBuffer(cdm::Buffer* aBuffer) override;
77
  cdm::Buffer* DecryptedBuffer() override;
78
  void SetTimestamp(int64_t aTimestamp) override;
79
  int64_t Timestamp() const override;
80
81
private:
82
  cdm::Buffer* mBuffer;
83
  int64_t mTimestamp;
84
};
85
86
} // namespace mozilla
87
88
#endif // WidevineUtils_h_