diff --git a/dom/media/platforms/moz.build b/dom/media/platforms/moz.build index 42e9a4f03faa..8ad560934ef5 100644 --- a/dom/media/platforms/moz.build +++ b/dom/media/platforms/moz.build @@ -10,6 +10,7 @@ EXPORTS += [ 'agnostic/VPXDecoder.h', 'PlatformDecoderModule.h', 'SharedDecoderManager.h', + 'wrappers/FuzzingWrapper.h', 'wrappers/H264Converter.h' ] @@ -20,6 +21,7 @@ UNIFIED_SOURCES += [ 'agnostic/VPXDecoder.cpp', 'PlatformDecoderModule.cpp', 'SharedDecoderManager.cpp', + 'wrappers/FuzzingWrapper.cpp', 'wrappers/H264Converter.cpp' ] diff --git a/dom/media/platforms/wrappers/FuzzingWrapper.cpp b/dom/media/platforms/wrappers/FuzzingWrapper.cpp new file mode 100644 index 000000000000..193f90ce5150 --- /dev/null +++ b/dom/media/platforms/wrappers/FuzzingWrapper.cpp @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "FuzzingWrapper.h" + +PRLogModuleInfo* GetFuzzingWrapperLog() { + static PRLogModuleInfo* log = nullptr; + if (!log) { + log = PR_NewLogModule("MediaFuzzingWrapper"); + } + return log; +} +#define DFW_LOGD(arg, ...) MOZ_LOG(GetFuzzingWrapperLog(), mozilla::LogLevel::Debug, ("DecoderFuzzingWrapper(%p)::%s: " arg, this, __func__, ##__VA_ARGS__)) +#define DFW_LOGV(arg, ...) MOZ_LOG(GetFuzzingWrapperLog(), mozilla::LogLevel::Verbose, ("DecoderFuzzingWrapper(%p)::%s: " arg, this, __func__, ##__VA_ARGS__)) +#define CFW_LOGD(arg, ...) MOZ_LOG(GetFuzzingWrapperLog(), mozilla::LogLevel::Debug, ("DecoderCallbackFuzzingWrapper(%p)::%s: " arg, this, __func__, ##__VA_ARGS__)) +#define CFW_LOGV(arg, ...) MOZ_LOG(GetFuzzingWrapperLog(), mozilla::LogLevel::Verbose, ("DecoderCallbackFuzzingWrapper(%p)::%s: " arg, this, __func__, ##__VA_ARGS__)) + +namespace mozilla { + +DecoderFuzzingWrapper::DecoderFuzzingWrapper( + already_AddRefed aDecoder, + already_AddRefed aCallbackWrapper) + : mDecoder(aDecoder) + , mCallbackWrapper(aCallbackWrapper) +{ + DFW_LOGV("aDecoder=%p aCallbackWrapper=%p", mDecoder.get(), mCallbackWrapper.get()); +} + +DecoderFuzzingWrapper::~DecoderFuzzingWrapper() +{ + DFW_LOGV(""); +} + +nsRefPtr +DecoderFuzzingWrapper::Init() +{ + DFW_LOGV(""); + MOZ_ASSERT(mDecoder); + return mDecoder->Init(); +} + +nsresult +DecoderFuzzingWrapper::Input(MediaRawData* aData) +{ + DFW_LOGV("aData.mTime=%lld", aData->mTime); + MOZ_ASSERT(mDecoder); + return mDecoder->Input(aData); +} + +nsresult +DecoderFuzzingWrapper::Flush() +{ + DFW_LOGV(""); + MOZ_ASSERT(mDecoder); + return mDecoder->Flush(); +} + +nsresult +DecoderFuzzingWrapper::Drain() +{ + DFW_LOGV(""); + MOZ_ASSERT(mDecoder); + return mDecoder->Drain(); +} + +nsresult +DecoderFuzzingWrapper::Shutdown() +{ + DFW_LOGV(""); + MOZ_ASSERT(mDecoder); + return mDecoder->Shutdown(); +} + +bool +DecoderFuzzingWrapper::IsHardwareAccelerated(nsACString& aFailureReason) const +{ + DFW_LOGV(""); + MOZ_ASSERT(mDecoder); + return mDecoder->IsHardwareAccelerated(aFailureReason); +} + +nsresult +DecoderFuzzingWrapper::ConfigurationChanged(const TrackInfo& aConfig) +{ + DFW_LOGV(""); + MOZ_ASSERT(mDecoder); + return mDecoder->ConfigurationChanged(aConfig); +} + + +DecoderCallbackFuzzingWrapper::DecoderCallbackFuzzingWrapper(MediaDataDecoderCallback* aCallback) + : mCallback(aCallback) +{ + CFW_LOGV("aCallback=%p", aCallback); +} + +DecoderCallbackFuzzingWrapper::~DecoderCallbackFuzzingWrapper() +{ + CFW_LOGV(""); +} + +void +DecoderCallbackFuzzingWrapper::Output(MediaData* aData) +{ + CFW_LOGV("aData.mTime=%lld", aData->mTime); + MOZ_ASSERT(mCallback); + mCallback->Output(aData); +} + +void +DecoderCallbackFuzzingWrapper::Error() +{ + CFW_LOGV(""); + MOZ_ASSERT(mCallback); + mCallback->Error(); +} + +void +DecoderCallbackFuzzingWrapper::InputExhausted() +{ + CFW_LOGV(""); + MOZ_ASSERT(mCallback); + mCallback->InputExhausted(); +} + +void +DecoderCallbackFuzzingWrapper::DrainComplete() +{ + CFW_LOGV(""); + MOZ_ASSERT(mCallback); + mCallback->DrainComplete(); +} + +void +DecoderCallbackFuzzingWrapper::ReleaseMediaResources() +{ + CFW_LOGV(""); + MOZ_ASSERT(mCallback); + mCallback->ReleaseMediaResources(); +} + +bool +DecoderCallbackFuzzingWrapper::OnReaderTaskQueue() +{ + CFW_LOGV(""); + MOZ_ASSERT(mCallback); + return mCallback->OnReaderTaskQueue(); +} + +} // namespace mozilla diff --git a/dom/media/platforms/wrappers/FuzzingWrapper.h b/dom/media/platforms/wrappers/FuzzingWrapper.h new file mode 100644 index 000000000000..26f223a842ac --- /dev/null +++ b/dom/media/platforms/wrappers/FuzzingWrapper.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#if !defined(FuzzingWrapper_h_) +#define FuzzingWrapper_h_ + +#include "PlatformDecoderModule.h" + +namespace mozilla { + +class DecoderCallbackFuzzingWrapper : public MediaDataDecoderCallback +{ +public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecoderCallbackFuzzingWrapper) + + explicit DecoderCallbackFuzzingWrapper(MediaDataDecoderCallback* aCallback); + +private: + virtual ~DecoderCallbackFuzzingWrapper(); + + // MediaDataDecoderCallback implementation. + void Output(MediaData* aData) override; + void Error() override; + void InputExhausted() override; + void DrainComplete() override; + void ReleaseMediaResources() override; + bool OnReaderTaskQueue() override; + + MediaDataDecoderCallback* mCallback; +}; + +class DecoderFuzzingWrapper : public MediaDataDecoder +{ +public: + DecoderFuzzingWrapper(already_AddRefed aDecoder, + already_AddRefed aCallbackWrapper); + virtual ~DecoderFuzzingWrapper(); + +private: + // MediaDataDecoder implementation. + nsRefPtr Init() override; + nsresult Input(MediaRawData* aSample) override; + nsresult Flush() override; + nsresult Drain() override; + nsresult Shutdown() override; + bool IsHardwareAccelerated(nsACString& aFailureReason) const override; + nsresult ConfigurationChanged(const TrackInfo& aConfig) override; + + nsRefPtr mDecoder; + nsRefPtr mCallbackWrapper; +}; + +} // namespace mozilla + +#endif