blob: 7705773837f54f02e2a19077c031fca235a14bdc [file] [log] [blame]
Alex Loikoe5b94162019-04-08 17:19:41 +02001/*
2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "api/audio_codecs/opus/audio_decoder_multi_channel_opus.h"
12#include "api/audio_codecs/opus/audio_decoder_multi_channel_opus_config.h"
13#include "test/fuzzers/audio_decoder_fuzzer.h"
14
15namespace webrtc {
16
17AudioDecoderMultiChannelOpusConfig MakeDecoderConfig(
18 int num_channels,
19 int coupled_streams,
20 std::vector<unsigned char> channel_mapping) {
21 AudioDecoderMultiChannelOpusConfig config;
22 config.num_channels = num_channels;
23 config.coupled_streams = coupled_streams;
24 config.channel_mapping = channel_mapping;
25 return config;
26}
27
28void FuzzOneInput(const uint8_t* data, size_t size) {
29 const std::vector<AudioDecoderMultiChannelOpusConfig> surround_configs = {
30 MakeDecoderConfig(1, 0, {0}), // Mono
31
32 MakeDecoderConfig(2, 0, {0, 0}), // Copy the first (of
33 // 2) decoded streams
34 // into both output
35 // channel 0 and output
36 // channel 1. Ignore
37 // the 2nd decoded
38 // stream.
39
40 MakeDecoderConfig(4, 2, {0, 1, 2, 3}), // Quad.
41 MakeDecoderConfig(6, 2, {0, 4, 1, 2, 3, 5}), // 5.1
42 MakeDecoderConfig(8, 3, {0, 6, 1, 2, 3, 4, 5, 7}) // 7.1
43 };
44
45 const auto config = surround_configs[data[0] % surround_configs.size()];
46 std::unique_ptr<AudioDecoder> dec =
47 AudioDecoderMultiChannelOpus::MakeAudioDecoder(config);
48 RTC_CHECK(dec);
49 const int kSampleRateHz = 48000;
50 const size_t kAllocatedOuputSizeSamples =
51 4 * kSampleRateHz / 10; // 4x100 ms, 4 times the size of the output array
52 // for the stereo Opus codec. It should be enough
53 // for 8 channels.
54 int16_t output[kAllocatedOuputSizeSamples];
55 FuzzAudioDecoder(DecoderFunctionType::kNormalDecode, data, size, dec.get(),
56 kSampleRateHz, sizeof(output), output);
57}
58} // namespace webrtc