1 /* 2 * Copyright (c) 2022 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 "modules/audio_coding/codecs/g722/audio_decoder_g722.h" 12 #include "test/fuzzers/audio_decoder_fuzzer.h" 13 14 namespace webrtc { FuzzOneInput(const uint8_t * data,size_t size)15void FuzzOneInput(const uint8_t* data, size_t size) { 16 if (size > 10000 || size < 1) { 17 return; 18 } 19 20 std::unique_ptr<AudioDecoder> dec; 21 size_t num_channels; 22 if (data[0] % 2) { 23 dec = std::make_unique<AudioDecoderG722Impl>(); 24 num_channels = 1; 25 } else { 26 dec = std::make_unique<AudioDecoderG722StereoImpl>(); 27 num_channels = 2; 28 } 29 // Allocate a maximum output size of 100 ms. 30 const int sample_rate_hz = dec->SampleRateHz(); 31 const size_t allocated_ouput_size_samples = 32 sample_rate_hz / 10 * num_channels; 33 std::unique_ptr<int16_t[]> output = 34 std::make_unique<int16_t[]>(allocated_ouput_size_samples); 35 FuzzAudioDecoder( 36 DecoderFunctionType::kNormalDecode, data, size, dec.get(), sample_rate_hz, 37 allocated_ouput_size_samples * sizeof(int16_t), output.get()); 38 } 39 } // namespace webrtc 40