1 /*
2  *  Copyright (c) 2016 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 #ifndef MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_REPLAYER_H_
12 #define MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_REPLAYER_H_
13 
14 #include <memory>
15 #include <string>
16 
17 #include "common_audio/channel_buffer.h"
18 #include "modules/audio_processing/include/audio_processing.h"
19 #include "rtc_base/ignore_wundef.h"
20 
21 RTC_PUSH_IGNORING_WUNDEF()
22 #include "modules/audio_processing/debug.pb.h"
RTC_POP_IGNORING_WUNDEF()23 RTC_POP_IGNORING_WUNDEF()
24 
25 namespace webrtc {
26 namespace test {
27 
28 class DebugDumpReplayer {
29  public:
30   DebugDumpReplayer();
31   ~DebugDumpReplayer();
32 
33   // Set dump file
34   bool SetDumpFile(const std::string& filename);
35 
36   // Return next event.
37   absl::optional<audioproc::Event> GetNextEvent() const;
38 
39   // Run the next event. Returns true if succeeded.
40   bool RunNextEvent();
41 
42   const ChannelBuffer<float>* GetOutput() const;
43   StreamConfig GetOutputConfig() const;
44 
45  private:
46   // Following functions are facilities for replaying debug dumps.
47   void OnInitEvent(const audioproc::Init& msg);
48   void OnStreamEvent(const audioproc::Stream& msg);
49   void OnReverseStreamEvent(const audioproc::ReverseStream& msg);
50   void OnConfigEvent(const audioproc::Config& msg);
51   void OnRuntimeSettingEvent(const audioproc::RuntimeSetting& msg);
52 
53   void MaybeRecreateApm(const audioproc::Config& msg);
54   void ConfigureApm(const audioproc::Config& msg);
55 
56   void LoadNextMessage();
57 
58   // Buffer for APM input/output.
59   std::unique_ptr<ChannelBuffer<float>> input_;
60   std::unique_ptr<ChannelBuffer<float>> reverse_;
61   std::unique_ptr<ChannelBuffer<float>> output_;
62 
63   std::unique_ptr<AudioProcessing> apm_;
64 
65   FILE* debug_file_;
66 
67   StreamConfig input_config_;
68   StreamConfig reverse_config_;
69   StreamConfig output_config_;
70 
71   bool has_next_event_;
72   audioproc::Event next_event_;
73 };
74 
75 }  // namespace test
76 }  // namespace webrtc
77 
78 #endif  // MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_REPLAYER_H_
79