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 <array>
12 #include <utility>
13
14 #include "modules/audio_processing/aec_dump/aec_dump_factory.h"
15 #include "rtc_base/task_queue_for_test.h"
16 #include "test/gtest.h"
17 #include "test/testsupport/file_utils.h"
18
19 namespace webrtc {
20
TEST(AecDumper,APICallsDoNotCrash)21 TEST(AecDumper, APICallsDoNotCrash) {
22 // Note order of initialization: Task queue has to be initialized
23 // before AecDump.
24 webrtc::TaskQueueForTest file_writer_queue("file_writer_queue");
25
26 const std::string filename =
27 webrtc::test::TempFilename(webrtc::test::OutputPath(), "aec_dump");
28
29 {
30 std::unique_ptr<webrtc::AecDump> aec_dump =
31 webrtc::AecDumpFactory::Create(filename, -1, &file_writer_queue);
32
33 constexpr int kNumChannels = 1;
34 constexpr int kNumSamplesPerChannel = 160;
35 std::array<int16_t, kNumSamplesPerChannel * kNumChannels> frame;
36 frame.fill(0.f);
37 aec_dump->WriteRenderStreamMessage(frame.data(), kNumChannels,
38 kNumSamplesPerChannel);
39
40 aec_dump->AddCaptureStreamInput(frame.data(), kNumChannels,
41 kNumSamplesPerChannel);
42 aec_dump->AddCaptureStreamOutput(frame.data(), kNumChannels,
43 kNumSamplesPerChannel);
44
45 aec_dump->WriteCaptureStreamMessage();
46
47 webrtc::InternalAPMConfig apm_config;
48 aec_dump->WriteConfig(apm_config);
49
50 webrtc::ProcessingConfig api_format;
51 constexpr int64_t kTimeNowMs = 123456789ll;
52 aec_dump->WriteInitMessage(api_format, kTimeNowMs);
53 }
54 // Remove file after the AecDump d-tor has finished.
55 ASSERT_EQ(0, remove(filename.c_str()));
56 }
57
TEST(AecDumper,WriteToFile)58 TEST(AecDumper, WriteToFile) {
59 webrtc::TaskQueueForTest file_writer_queue("file_writer_queue");
60
61 const std::string filename =
62 webrtc::test::TempFilename(webrtc::test::OutputPath(), "aec_dump");
63
64 {
65 std::unique_ptr<webrtc::AecDump> aec_dump =
66 webrtc::AecDumpFactory::Create(filename, -1, &file_writer_queue);
67
68 constexpr int kNumChannels = 1;
69 constexpr int kNumSamplesPerChannel = 160;
70 std::array<int16_t, kNumSamplesPerChannel * kNumChannels> frame;
71 frame.fill(0.f);
72
73 aec_dump->WriteRenderStreamMessage(frame.data(), kNumChannels,
74 kNumSamplesPerChannel);
75 }
76
77 // Verify the file has been written after the AecDump d-tor has
78 // finished.
79 FILE* fid = fopen(filename.c_str(), "r");
80 ASSERT_TRUE(fid != NULL);
81
82 // Clean it up.
83 ASSERT_EQ(0, fclose(fid));
84 ASSERT_EQ(0, remove(filename.c_str()));
85 }
86
87 } // namespace webrtc
88