Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef EME_LOG_H_
8 : #define EME_LOG_H_
9 :
10 : #include "VideoUtils.h"
11 : #include "mozilla/Logging.h"
12 : #include "nsString.h"
13 : #include "nsTArray.h"
14 :
15 : namespace mozilla {
16 :
17 : namespace dom {
18 : class ArrayBufferViewOrArrayBuffer;
19 : }
20 :
21 : #ifndef EME_LOG
22 : LogModule* GetEMELog();
23 : #define EME_LOG(...) MOZ_LOG(GetEMELog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
24 : #define EME_LOG_ENABLED() MOZ_LOG_TEST(GetEMELog(), mozilla::LogLevel::Debug)
25 : #endif
26 :
27 : #ifndef EME_VERBOSE_LOG
28 : LogModule* GetEMEVerboseLog();
29 : #define EME_VERBOSE_LOG(...) MOZ_LOG(GetEMEVerboseLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
30 : #else
31 : #ifndef EME_LOG
32 : #define EME_LOG(...)
33 : #endif
34 :
35 : #ifndef EME_VERBOSE_LOG
36 : #define EME_VERBOSE_LOG(...)
37 : #endif
38 : #endif
39 :
40 : // Helper function to extract a copy of data coming in from JS in an
41 : // (ArrayBuffer or ArrayBufferView) IDL typed function argument.
42 : //
43 : // Only call this on a properly initialized ArrayBufferViewOrArrayBuffer.
44 : void
45 : CopyArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView,
46 : nsTArray<uint8_t>& aOutData);
47 :
48 : struct ArrayData {
49 0 : explicit ArrayData(const uint8_t* aData, size_t aLength)
50 0 : : mData(aData)
51 0 : , mLength(aLength)
52 : {
53 0 : }
54 : const uint8_t* mData;
55 : const size_t mLength;
56 0 : bool IsValid() const {
57 0 : return mData != nullptr && mLength != 0;
58 : }
59 0 : bool operator== (const nsTArray<uint8_t>& aOther) const {
60 0 : return mLength == aOther.Length() &&
61 0 : memcmp(mData, aOther.Elements(), mLength) == 0;
62 : }
63 : };
64 :
65 : // Helper function to extract data coming in from JS in an
66 : // (ArrayBuffer or ArrayBufferView) IDL typed function argument.
67 : //
68 : // Be *very* careful with this!
69 : //
70 : // Only use returned ArrayData inside the lifetime of the
71 : // ArrayBufferViewOrArrayBuffer; the ArrayData struct does not contain
72 : // a copy of the data!
73 : //
74 : // And do *not* call out to anything that could call into JavaScript,
75 : // while the ArrayData is live, as then all bets about the data not changing
76 : // are off! No calls into JS, no calls into JS-implemented WebIDL or XPIDL,
77 : // nothing. Beware!
78 : //
79 : // Only call this on a properly initialized ArrayBufferViewOrArrayBuffer.
80 : ArrayData
81 : GetArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView);
82 :
83 : nsString
84 : KeySystemToGMPName(const nsAString& aKeySystem);
85 :
86 : bool
87 : IsClearkeyKeySystem(const nsAString& aKeySystem);
88 :
89 : bool
90 : IsWidevineKeySystem(const nsAString& aKeySystem);
91 :
92 : // Note: Primetime is now unsupported, but we leave it in the enum so
93 : // that the telemetry enum values are not changed; doing so would break
94 : // existing telemetry probes.
95 : enum CDMType {
96 : eClearKey = 0,
97 : ePrimetime = 1, // Note: Unsupported.
98 : eWidevine = 2,
99 : eUnknown = 3
100 : };
101 :
102 : CDMType
103 : ToCDMTypeTelemetryEnum(const nsString& aKeySystem);
104 :
105 : } // namespace mozilla
106 :
107 : #endif // EME_LOG_H_
|