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