Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: webrtc/test/fuzzers/residual_echo_detector_fuzzer.cc

Issue 2877803002: Adds fuzzer for the residual echo detector. (Closed)
Patch Set: Review comments by Henrik. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/test/fuzzers/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 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 <math.h>
12 #include <string.h>
13
14 #include <algorithm>
15 #include <bitset>
16 #include <vector>
17
18 #include "webrtc/base/checks.h"
19 #include "webrtc/modules/audio_processing/residual_echo_detector.h"
20
21 namespace webrtc {
22
23 void FuzzOneInput(const uint8_t* data, size_t size) {
24 // Number of times to update the echo detector.
25 constexpr size_t kNrOfUpdates = 7;
26 // Each round of updates requires a call to both AnalyzeRender and
27 // AnalyzeCapture, so the amount of needed input bytes doubles. Also, two
28 // bytes are used to set the call order.
29 constexpr size_t kNrOfNeededInputBytes = 2 * kNrOfUpdates * sizeof(float) + 2;
30 // The maximum audio energy that an audio frame can have is equal to the
31 // number of samples in the frame multiplied by 2^30. We use a single sample
32 // to represent an audio frame in this test, so it should have a maximum value
33 // equal to the square root of that value.
34 const float maxFuzzedValue = sqrtf(20 * 48) * 32768;
35 if (size < kNrOfNeededInputBytes) {
36 return;
37 }
38 size_t read_idx = 0;
39 // Use the first two bytes to choose the call order.
40 uint16_t call_order_int;
41 memcpy(&call_order_int, &data[read_idx], 2);
42 read_idx += 2;
43 std::bitset<16> call_order(call_order_int);
44
45 ResidualEchoDetector echo_detector;
46 std::vector<float> input(1);
47 // Call AnalyzeCaptureAudio once to prevent the flushing of the buffer.
48 echo_detector.AnalyzeCaptureAudio(input);
49 for (size_t i = 0; i < 2 * kNrOfUpdates; ++i) {
50 // Convert 4 input bytes to a float.
51 RTC_DCHECK_LE(read_idx + sizeof(float), size);
52 memcpy(input.data(), &data[read_idx], sizeof(float));
53 read_idx += sizeof(float);
54 if (!isfinite(input[0]) || fabs(input[0]) > maxFuzzedValue) {
55 // Ignore infinity, nan values and values that are unrealistically large.
56 continue;
57 }
58 if (call_order[i]) {
59 echo_detector.AnalyzeRenderAudio(input);
60 } else {
61 echo_detector.AnalyzeCaptureAudio(input);
62 }
63 }
64 }
65
66 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/fuzzers/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698