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 "ImageContainer.h"
9 
10 namespace mozilla {
11 
12 class NullVideoDataCreator : public DummyDataCreator {
13  public:
14   NullVideoDataCreator() = default;
15 
Create(MediaRawData * aSample)16   already_AddRefed<MediaData> Create(MediaRawData* aSample) override {
17     // Create a dummy VideoData with an empty image. This gives us something to
18     // send to media streams if necessary.
19     RefPtr<layers::PlanarYCbCrImage> image =
20         new layers::RecyclingPlanarYCbCrImage(new layers::BufferRecycleBin());
21     return VideoData::CreateFromImage(gfx::IntSize(), aSample->mOffset,
22                                       aSample->mTime, aSample->mDuration, image,
23                                       aSample->mKeyframe, aSample->mTimecode);
24   }
25 };
26 
27 class NullDecoderModule : public PlatformDecoderModule {
28  public:
29   // Decode thread.
CreateVideoDecoder(const CreateDecoderParams & aParams)30   already_AddRefed<MediaDataDecoder> CreateVideoDecoder(
31       const CreateDecoderParams& aParams) override {
32     UniquePtr<DummyDataCreator> creator = MakeUnique<NullVideoDataCreator>();
33     RefPtr<MediaDataDecoder> decoder = new DummyMediaDataDecoder(
34         std::move(creator), "null media data decoder"_ns, aParams);
35     return decoder.forget();
36   }
37 
38   // Decode thread.
CreateAudioDecoder(const CreateDecoderParams & aParams)39   already_AddRefed<MediaDataDecoder> CreateAudioDecoder(
40       const CreateDecoderParams& aParams) override {
41     MOZ_ASSERT(false, "Audio decoders are unsupported.");
42     return nullptr;
43   }
44 
SupportsMimeType(const nsACString & aMimeType,DecoderDoctorDiagnostics * aDiagnostics) const45   bool SupportsMimeType(const nsACString& aMimeType,
46                         DecoderDoctorDiagnostics* aDiagnostics) const override {
47     return true;
48   }
49 };
50 
CreateNullDecoderModule()51 already_AddRefed<PlatformDecoderModule> CreateNullDecoderModule() {
52   RefPtr<PlatformDecoderModule> pdm = new NullDecoderModule();
53   return pdm.forget();
54 }
55 
56 }  // namespace mozilla
57