/src/mozilla-central/dom/media/eme/EMEUtils.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | static LazyLogModule log("EME"); |
14 | 0 | return log; |
15 | 0 | } |
16 | | |
17 | 0 | LogModule* GetEMEVerboseLog() { |
18 | 0 | static LazyLogModule log("EMEV"); |
19 | 0 | return log; |
20 | 0 | } |
21 | | |
22 | | ArrayData |
23 | | GetArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView) |
24 | 0 | { |
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 | 0 | } |
35 | 0 | return ArrayData(nullptr, 0); |
36 | 0 | } |
37 | | |
38 | | void |
39 | | CopyArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView, |
40 | | nsTArray<uint8_t>& aOutData) |
41 | 0 | { |
42 | 0 | ArrayData data = GetArrayBufferViewOrArrayBufferData(aBufferOrView); |
43 | 0 | aOutData.Clear(); |
44 | 0 | if (!data.IsValid()) { |
45 | 0 | return; |
46 | 0 | } |
47 | 0 | aOutData.AppendElements(data.mData, data.mLength); |
48 | 0 | } |
49 | | |
50 | | bool |
51 | | IsClearkeyKeySystem(const nsAString& aKeySystem) |
52 | 0 | { |
53 | 0 | return !CompareUTF8toUTF16(kEMEKeySystemClearkey, aKeySystem); |
54 | 0 | } |
55 | | |
56 | | bool |
57 | | IsWidevineKeySystem(const nsAString& aKeySystem) |
58 | 0 | { |
59 | 0 | return !CompareUTF8toUTF16(kEMEKeySystemWidevine, aKeySystem); |
60 | 0 | } |
61 | | |
62 | | nsString |
63 | | KeySystemToGMPName(const nsAString& aKeySystem) |
64 | 0 | { |
65 | 0 | if (IsClearkeyKeySystem(aKeySystem)) { |
66 | 0 | return NS_LITERAL_STRING("gmp-clearkey"); |
67 | 0 | } |
68 | 0 | if (IsWidevineKeySystem(aKeySystem)) { |
69 | 0 | return NS_LITERAL_STRING("gmp-widevinecdm"); |
70 | 0 | } |
71 | 0 | MOZ_ASSERT(false, "We should only call this for known GMPs"); |
72 | 0 | return EmptyString(); |
73 | 0 | } |
74 | | |
75 | | } // namespace mozilla |