Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/platforms/agnostic/DummyMediaDataDecoder.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
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
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "DummyMediaDataDecoder.h"
8
#include "AnnexB.h"
9
#include "H264.h"
10
#include "MP4Decoder.h"
11
12
namespace mozilla {
13
14
0
DummyDataCreator::~DummyDataCreator() {}
15
16
DummyMediaDataDecoder::DummyMediaDataDecoder(UniquePtr<DummyDataCreator>&& aCreator,
17
                                             const nsACString& aDescription,
18
                                             const CreateDecoderParams& aParams)
19
  : mCreator(std::move(aCreator))
20
  , mIsH264(MP4Decoder::IsH264(aParams.mConfig.mMimeType))
21
  , mMaxRefFrames(
22
      mIsH264
23
      ? H264::HasSPS(aParams.VideoConfig().mExtraData)
24
        ? H264::ComputeMaxRefFrames(aParams.VideoConfig().mExtraData)
25
        : 16
26
      : 0)
27
  , mType(aParams.mConfig.GetType())
28
  , mDescription(aDescription)
29
0
{
30
0
}
31
32
RefPtr<MediaDataDecoder::InitPromise>
33
DummyMediaDataDecoder::Init()
34
0
{
35
0
  return InitPromise::CreateAndResolve(mType, __func__);
36
0
}
37
38
RefPtr<ShutdownPromise>
39
DummyMediaDataDecoder::Shutdown()
40
0
{
41
0
  return ShutdownPromise::CreateAndResolve(true, __func__);
42
0
}
43
44
RefPtr<MediaDataDecoder::DecodePromise>
45
DummyMediaDataDecoder::Decode(MediaRawData* aSample)
46
0
{
47
0
  RefPtr<MediaData> data = mCreator->Create(aSample);
48
0
49
0
  if (!data) {
50
0
    return DecodePromise::CreateAndReject(NS_ERROR_OUT_OF_MEMORY, __func__);
51
0
  }
52
0
53
0
  // Frames come out in DTS order but we need to output them in PTS order.
54
0
  mReorderQueue.Push(data);
55
0
56
0
  if (mReorderQueue.Length() > mMaxRefFrames) {
57
0
    return DecodePromise::CreateAndResolve(
58
0
      DecodedData{ mReorderQueue.Pop().get() }, __func__);
59
0
  }
60
0
  return DecodePromise::CreateAndResolve(DecodedData(), __func__);
61
0
}
62
63
RefPtr<MediaDataDecoder::DecodePromise>
64
DummyMediaDataDecoder::Drain()
65
0
{
66
0
  DecodedData samples;
67
0
  while (!mReorderQueue.IsEmpty()) {
68
0
    samples.AppendElement(mReorderQueue.Pop().get());
69
0
  }
70
0
  return DecodePromise::CreateAndResolve(samples, __func__);
71
0
}
72
73
RefPtr<MediaDataDecoder::FlushPromise>
74
DummyMediaDataDecoder::Flush()
75
0
{
76
0
  mReorderQueue.Clear();
77
0
  return FlushPromise::CreateAndResolve(true, __func__);
78
0
}
79
80
nsCString
81
DummyMediaDataDecoder::GetDescriptionName() const
82
0
{
83
0
  return NS_LITERAL_CSTRING("blank media data decoder");
84
0
}
85
86
MediaDataDecoder::ConversionRequired
87
DummyMediaDataDecoder::NeedsConversion() const
88
0
{
89
0
  return mIsH264
90
0
         ? ConversionRequired::kNeedAVCC
91
0
         : ConversionRequired::kNeedNone;
92
0
}
93
94
} // namespace mozilla