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 : #include "mozilla/EMEUtils.h"
8 : #include "mozilla/dom/UnionTypes.h"
9 :
10 : namespace mozilla {
11 :
12 0 : LogModule* GetEMELog() {
13 : static LazyLogModule log("EME");
14 0 : return log;
15 : }
16 :
17 0 : LogModule* GetEMEVerboseLog() {
18 : static LazyLogModule log("EMEV");
19 0 : return log;
20 : }
21 :
22 : ArrayData
23 0 : GetArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView)
24 : {
25 0 : MOZ_ASSERT(aBufferOrView.IsArrayBuffer() || aBufferOrView.IsArrayBufferView());
26 0 : if (aBufferOrView.IsArrayBuffer()) {
27 0 : const dom::ArrayBuffer& buffer = aBufferOrView.GetAsArrayBuffer();
28 0 : buffer.ComputeLengthAndData();
29 0 : return ArrayData(buffer.Data(), buffer.Length());
30 0 : } else if (aBufferOrView.IsArrayBufferView()) {
31 0 : const dom::ArrayBufferView& bufferview = aBufferOrView.GetAsArrayBufferView();
32 0 : bufferview.ComputeLengthAndData();
33 0 : return ArrayData(bufferview.Data(), bufferview.Length());
34 : }
35 0 : return ArrayData(nullptr, 0);
36 : }
37 :
38 : void
39 0 : CopyArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView,
40 : nsTArray<uint8_t>& aOutData)
41 : {
42 0 : ArrayData data = GetArrayBufferViewOrArrayBufferData(aBufferOrView);
43 0 : aOutData.Clear();
44 0 : if (!data.IsValid()) {
45 0 : return;
46 : }
47 0 : aOutData.AppendElements(data.mData, data.mLength);
48 : }
49 :
50 : bool
51 0 : IsClearkeyKeySystem(const nsAString& aKeySystem)
52 : {
53 0 : return !CompareUTF8toUTF16(kEMEKeySystemClearkey, aKeySystem);
54 : }
55 :
56 : bool
57 0 : IsWidevineKeySystem(const nsAString& aKeySystem)
58 : {
59 0 : return !CompareUTF8toUTF16(kEMEKeySystemWidevine, aKeySystem);
60 : }
61 :
62 : nsString
63 0 : KeySystemToGMPName(const nsAString& aKeySystem)
64 : {
65 0 : if (IsClearkeyKeySystem(aKeySystem)) {
66 0 : return NS_LITERAL_STRING("gmp-clearkey");
67 : }
68 0 : if (IsWidevineKeySystem(aKeySystem)) {
69 0 : return NS_LITERAL_STRING("gmp-widevinecdm");
70 : }
71 0 : MOZ_ASSERT(false, "We should only call this for known GMPs");
72 : return EmptyString();
73 : }
74 :
75 : CDMType
76 0 : ToCDMTypeTelemetryEnum(const nsString& aKeySystem)
77 : {
78 0 : if (IsWidevineKeySystem(aKeySystem)) {
79 0 : return CDMType::eWidevine;
80 0 : } else if (IsClearkeyKeySystem(aKeySystem)) {
81 0 : return CDMType::eClearKey;
82 : }
83 0 : return CDMType::eUnknown;
84 : }
85 :
86 : } // namespace mozilla
|