Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/gmp/DecryptJob.cpp
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
#include "DecryptJob.h"
7
#include "mozilla/Atomics.h"
8
9
namespace mozilla {
10
11
static Atomic<uint32_t> sDecryptJobInstanceCount(0u);
12
13
DecryptJob::DecryptJob(MediaRawData* aSample)
14
  : mId(++sDecryptJobInstanceCount )
15
  , mSample(aSample)
16
0
{
17
0
}
18
19
RefPtr<DecryptPromise>
20
DecryptJob::Ensure()
21
0
{
22
0
  return mPromise.Ensure(__func__);
23
0
}
24
25
void
26
DecryptJob::PostResult(DecryptStatus aResult)
27
0
{
28
0
  nsTArray<uint8_t> empty;
29
0
  PostResult(aResult, empty);
30
0
}
31
32
void
33
DecryptJob::PostResult(DecryptStatus aResult,
34
                       Span<const uint8_t> aDecryptedData)
35
0
{
36
0
  if (aDecryptedData.Length() != mSample->Size()) {
37
0
    NS_WARNING("CDM returned incorrect number of decrypted bytes");
38
0
  }
39
0
  if (aResult == eme::Ok) {
40
0
    UniquePtr<MediaRawDataWriter> writer(mSample->CreateWriter());
41
0
    PodCopy(writer->Data(),
42
0
            aDecryptedData.Elements(),
43
0
            std::min<size_t>(aDecryptedData.Length(), mSample->Size()));
44
0
  } else if (aResult == eme::NoKeyErr) {
45
0
    NS_WARNING("CDM returned NoKeyErr");
46
0
    // We still have the encrypted sample, so we can re-enqueue it to be
47
0
    // decrypted again once the key is usable again.
48
0
  } else {
49
0
    nsAutoCString str("CDM returned decode failure DecryptStatus=");
50
0
    str.AppendInt(aResult);
51
0
    NS_WARNING(str.get());
52
0
  }
53
0
  mPromise.Resolve(DecryptResult(aResult, mSample), __func__);
54
0
}
55
56
} // namespace mozilla