|
| 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 "ADTSDemuxer.h" |
| 7 | +#include "Benchmark.h" |
| 8 | +#include "BufferMediaResource.h" |
| 9 | +#include "FlacDemuxer.h" |
| 10 | +#include "FuzzingInterface.h" |
| 11 | +#include "mozilla/AbstractThread.h" |
| 12 | +#include "MP3Demuxer.h" |
| 13 | +#include "MP4Demuxer.h" |
| 14 | +#include "OggDemuxer.h" |
| 15 | +#include "systemservices/MediaUtils.h" |
| 16 | +#include "WaveDemuxer.h" |
| 17 | +#include "WebMDemuxer.h" |
| 18 | + |
| 19 | +using namespace mozilla; |
| 20 | + |
| 21 | +class FuzzRunner { |
| 22 | + public: |
| 23 | + explicit FuzzRunner(Benchmark* aBenchmark) : mBenchmark(aBenchmark) {} |
| 24 | + |
| 25 | + void Run() { |
| 26 | + mBenchmark->Init(); |
| 27 | + media::Await( |
| 28 | + GetMediaThreadPool(MediaThreadType::PLAYBACK), mBenchmark->Run(), |
| 29 | + [&](uint32_t aDecodeFps) {}, [&](const MediaResult& aError) {}); |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + private: |
| 34 | + RefPtr<Benchmark> mBenchmark; |
| 35 | +}; |
| 36 | + |
| 37 | +static int FuzzingInitMedia(int* argc, char*** argv) { |
| 38 | + /* Generic no-op initialization used for all targets */ |
| 39 | + return 0; |
| 40 | +} |
| 41 | + |
| 42 | +#define MOZ_MEDIA_FUZZER(_name) \ |
| 43 | + static int FuzzingRunMedia##_name(const uint8_t* data, size_t size) { \ |
| 44 | + if (!size) { \ |
| 45 | + return 0; \ |
| 46 | + } \ |
| 47 | + RefPtr<BufferMediaResource> resource = \ |
| 48 | + new BufferMediaResource(data, size); \ |
| 49 | + FuzzRunner runner(new Benchmark(new _name##Demuxer(resource))); \ |
| 50 | + runner.Run(); \ |
| 51 | + return 0; \ |
| 52 | + } \ |
| 53 | + MOZ_FUZZING_INTERFACE_RAW(FuzzingInitMedia, FuzzingRunMedia##_name, \ |
| 54 | + Media##_name); |
| 55 | + |
| 56 | +MOZ_MEDIA_FUZZER(ADTS); |
| 57 | +MOZ_MEDIA_FUZZER(Flac); |
| 58 | +MOZ_MEDIA_FUZZER(MP3); |
| 59 | +MOZ_MEDIA_FUZZER(MP4); |
| 60 | +MOZ_MEDIA_FUZZER(Ogg); |
| 61 | +MOZ_MEDIA_FUZZER(WAV); |
| 62 | +MOZ_MEDIA_FUZZER(WebM); |
0 commit comments