OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2015 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 "webrtc/test/fuzzers/audio_decoder_fuzzer.h" |
| 12 |
| 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
| 15 |
| 16 namespace webrtc { |
| 17 namespace { |
| 18 size_t PacketSizeFromTwoBytes(const uint8_t* data, size_t size) { |
| 19 if (size < 2) |
| 20 return 0; |
| 21 return static_cast<size_t>((data[0] << 8) + data[1]); |
| 22 } |
| 23 } // namespace |
| 24 |
| 25 void FuzzAudioDecoder(const uint8_t* data, |
| 26 size_t size, |
| 27 AudioDecoder* decoder, |
| 28 int sample_rate_hz, |
| 29 size_t max_decoded_bytes, |
| 30 int16_t* decoded) { |
| 31 const uint8_t* data_ptr = data; |
| 32 size_t remaining_size = size; |
| 33 size_t packet_len = PacketSizeFromTwoBytes(data_ptr, remaining_size); |
| 34 while (packet_len != 0 && packet_len <= remaining_size - 2) { |
| 35 data_ptr += 2; |
| 36 remaining_size -= 2; |
| 37 AudioDecoder::SpeechType speech_type; |
| 38 decoder->Decode(data_ptr, packet_len, sample_rate_hz, max_decoded_bytes, |
| 39 decoded, &speech_type); |
| 40 data_ptr += packet_len; |
| 41 remaining_size -= packet_len; |
| 42 packet_len = PacketSizeFromTwoBytes(data_ptr, remaining_size); |
| 43 } |
| 44 } |
| 45 } // namespace webrtc |
OLD | NEW |