Line data Source code
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 : #include "GMPEncryptedBufferDataImpl.h"
7 : #include "mozilla/gmp/GMPTypes.h"
8 : #include "MediaData.h"
9 :
10 : namespace mozilla {
11 : namespace gmp {
12 :
13 0 : GMPEncryptedBufferDataImpl::GMPEncryptedBufferDataImpl(const CryptoSample& aCrypto)
14 : : mKeyId(aCrypto.mKeyId)
15 : , mIV(aCrypto.mIV)
16 : , mClearBytes(aCrypto.mPlainSizes)
17 : , mCipherBytes(aCrypto.mEncryptedSizes)
18 0 : , mSessionIdList(aCrypto.mSessionIds)
19 : {
20 0 : }
21 :
22 0 : GMPEncryptedBufferDataImpl::GMPEncryptedBufferDataImpl(const GMPDecryptionData& aData)
23 : : mKeyId(aData.mKeyId())
24 : , mIV(aData.mIV())
25 : , mClearBytes(aData.mClearBytes())
26 : , mCipherBytes(aData.mCipherBytes())
27 0 : , mSessionIdList(aData.mSessionIds())
28 : {
29 0 : MOZ_ASSERT(mClearBytes.Length() == mCipherBytes.Length());
30 0 : }
31 :
32 0 : GMPEncryptedBufferDataImpl::~GMPEncryptedBufferDataImpl()
33 : {
34 0 : }
35 :
36 : void
37 0 : GMPEncryptedBufferDataImpl::RelinquishData(GMPDecryptionData& aData)
38 : {
39 0 : aData.mKeyId() = Move(mKeyId);
40 0 : aData.mIV() = Move(mIV);
41 0 : aData.mClearBytes() = Move(mClearBytes);
42 0 : aData.mCipherBytes() = Move(mCipherBytes);
43 0 : mSessionIdList.RelinquishData(aData.mSessionIds());
44 0 : }
45 :
46 : const uint8_t*
47 0 : GMPEncryptedBufferDataImpl::KeyId() const
48 : {
49 0 : return mKeyId.Elements();
50 : }
51 :
52 : uint32_t
53 0 : GMPEncryptedBufferDataImpl::KeyIdSize() const
54 : {
55 0 : return mKeyId.Length();
56 : }
57 :
58 : const uint8_t*
59 0 : GMPEncryptedBufferDataImpl::IV() const
60 : {
61 0 : return mIV.Elements();
62 : }
63 :
64 : uint32_t
65 0 : GMPEncryptedBufferDataImpl::IVSize() const
66 : {
67 0 : return mIV.Length();
68 : }
69 :
70 : const uint16_t*
71 0 : GMPEncryptedBufferDataImpl::ClearBytes() const
72 : {
73 0 : return mClearBytes.Elements();
74 : }
75 :
76 : const uint32_t*
77 0 : GMPEncryptedBufferDataImpl::CipherBytes() const
78 : {
79 0 : return mCipherBytes.Elements();
80 : }
81 :
82 : const GMPStringList*
83 0 : GMPEncryptedBufferDataImpl::SessionIds() const
84 : {
85 0 : return &mSessionIdList;
86 : }
87 :
88 : uint32_t
89 0 : GMPEncryptedBufferDataImpl::NumSubsamples() const
90 : {
91 0 : MOZ_ASSERT(mClearBytes.Length() == mCipherBytes.Length());
92 : // Return the min of the two, to ensure there's not chance of array index
93 : // out-of-bounds shenanigans.
94 0 : return std::min<uint32_t>(mClearBytes.Length(), mCipherBytes.Length());
95 : }
96 :
97 0 : GMPStringListImpl::GMPStringListImpl(const nsTArray<nsCString>& aStrings)
98 0 : : mStrings(aStrings)
99 : {
100 0 : }
101 :
102 : uint32_t
103 0 : GMPStringListImpl::Size() const
104 : {
105 0 : return mStrings.Length();
106 : }
107 :
108 : void
109 0 : GMPStringListImpl::StringAt(uint32_t aIndex,
110 : const char** aOutString,
111 : uint32_t *aOutLength) const
112 : {
113 0 : if (NS_WARN_IF(aIndex >= Size())) {
114 0 : return;
115 : }
116 :
117 0 : *aOutString = mStrings[aIndex].BeginReading();
118 0 : *aOutLength = mStrings[aIndex].Length();
119 : }
120 :
121 : void
122 0 : GMPStringListImpl::RelinquishData(nsTArray<nsCString>& aStrings)
123 : {
124 0 : aStrings = Move(mStrings);
125 0 : }
126 :
127 0 : GMPStringListImpl::~GMPStringListImpl()
128 : {
129 0 : }
130 :
131 : } // namespace gmp
132 : } // namespace mozilla
|