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/. */
6 #include "ADTSDemuxer.h"
8 #include "BufferMediaResource.h"
9 #include "FlacDemuxer.h"
10 #include "FuzzingInterface.h"
11 #include "mozilla/AbstractThread.h"
12 #include "mozilla/SpinEventLoopUntil.h"
13 #include "MP3Demuxer.h"
14 #include "MP4Demuxer.h"
15 #include "OggDemuxer.h"
16 #include "systemservices/MediaUtils.h"
17 #include "WaveDemuxer.h"
18 #include "WebMDemuxer.h"
20 using namespace mozilla
;
24 explicit FuzzRunner(Benchmark
* aBenchmark
) : mBenchmark(aBenchmark
) {}
27 // Assert we're on the main thread, otherwise `done` must be synchronized.
28 MOZ_ASSERT(NS_IsMainThread());
32 mBenchmark
->Run()->Then(
33 // Non DocGroup-version of AbstractThread::MainThread() is fine for
35 AbstractThread::MainThread(), __func__
,
36 [&](uint32_t aDecodeFps
) { done
= true; }, [&]() { done
= true; });
38 // Wait until benchmark completes.
39 SpinEventLoopUntil("FuzzRunner::Run"_ns
, [&]() { return done
; });
44 RefPtr
<Benchmark
> mBenchmark
;
47 #define MOZ_MEDIA_FUZZER(_name) \
48 static int FuzzingRunMedia##_name(const uint8_t* data, size_t size) { \
52 RefPtr<BufferMediaResource> resource = \
53 new BufferMediaResource(data, size); \
54 FuzzRunner runner(new Benchmark(new _name##Demuxer(resource))); \
58 MOZ_FUZZING_INTERFACE_RAW(nullptr, FuzzingRunMedia##_name, Media##_name);
60 MOZ_MEDIA_FUZZER(ADTS
);
61 MOZ_MEDIA_FUZZER(Flac
);
62 MOZ_MEDIA_FUZZER(MP3
);
63 MOZ_MEDIA_FUZZER(MP4
);
64 MOZ_MEDIA_FUZZER(Ogg
);
65 MOZ_MEDIA_FUZZER(WAV
);
66 MOZ_MEDIA_FUZZER(WebM
);