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

Unified Diff: webrtc/modules/audio_processing/test/audio_file_processor.h

Issue 1409943002: Add aecdump support to audioproc_f. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/test/audio_file_processor.h
diff --git a/webrtc/modules/audio_processing/test/audio_file_processor.h b/webrtc/modules/audio_processing/test/audio_file_processor.h
new file mode 100644
index 0000000000000000000000000000000000000000..fd9161bc96155c7e000fb7dc88a69b75614f497c
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/audio_file_processor.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_
+#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_
+
+#include <vector>
+
+#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/common_audio/channel_buffer.h"
+#include "webrtc/common_audio/wav_file.h"
+#include "webrtc/modules/audio_processing/include/audio_processing.h"
+#include "webrtc/modules/audio_processing/test/test_utils.h"
+#include "webrtc/system_wrappers/interface/tick_util.h"
+
+#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
+#include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
+#else
+#include "webrtc/audio_processing/debug.pb.h"
+#endif
+
+namespace webrtc {
+
+// Interface for processing an input file with an AudioProcessing instance and
+// dumping the results to an output file.
+class AudioFileProcessor {
+ public:
+ static const int kChunksPerSecond = 1000 / AudioProcessing::kChunkSizeMs;
+
+ virtual ~AudioFileProcessor() {}
+
+ // Process one AuioProcessing::kChunkSizeMs of data from the input file.
peah-webrtc 2015/10/20 21:17:25 Typo: Should be AudioProcessing
Andrew MacDonald 2015/10/21 00:29:28 Done.
+ virtual bool ProcessChunk() = 0;
peah-webrtc 2015/10/20 21:17:25 I think another name is needed for this method. Wh
Andrew MacDonald 2015/10/21 00:29:28 The name is intentionally ambiguous in order for i
peah-webrtc 2015/10/21 08:10:04 I think ProcessChunk was better than ProcessAndWri
Andrew MacDonald 2015/10/22 00:12:09 Except that it might not process a capture chunk a
peah-webrtc 2015/10/22 04:50:40 Then the loop does not make sense at all. As it is
Andrew MacDonald 2015/10/22 05:11:55 And update the trace time overrider. My point is t
Andrew MacDonald 2015/10/22 16:38:20 I'd like to settle on a name you're happy with (or
peah-webrtc 2015/10/23 07:42:40 From the link I definitely see the risk of confusi
Andrew MacDonald 2015/10/23 23:58:35 We've been using block to refer to the underlying
+
+ // Returns the total execution time of all AudioProcessing calls.
+ int64_t processing_time_ms() const { return processing_time_.Milliseconds(); }
+
+ protected:
+ // RAII class for execution time measurement. Updates the provided
+ // TickInterval with the time between object creation and leaving the
+ // enclosing scope.
+ class ScopedTimer {
+ public:
+ explicit ScopedTimer(TickInterval* interval)
+ : interval_(interval), start_time_(TickTime::Now()) {}
+
+ ~ScopedTimer() { *interval_ += TickTime::Now() - start_time_; }
aluebs-webrtc 2015/10/24 00:53:34 Don't you think it is more intuitive to have a met
Andrew MacDonald 2015/10/29 00:44:50 I find scoped objects quite intuitive (in webrtc,
aluebs-webrtc 2015/10/29 01:03:19 But you can forget to scope it right. But if you f
Andrew MacDonald 2015/10/29 01:14:33 That's true, but I think that's harder (given the
+
+ private:
+ TickInterval* const interval_;
aluebs-webrtc 2015/10/24 00:53:34 What does this const mean?
Andrew MacDonald 2015/10/29 00:44:50 It means the pointer can't be reseated (its value
aluebs-webrtc 2015/10/29 01:03:19 Ok, thanks for clarifying.
+ TickTime start_time_;
+ };
+
+ TickInterval* processing_time() { return &processing_time_; }
+
+ private:
+ TickInterval processing_time_;
+};
+
+// Used to read from and write to WavFile objects.
+class WavFileProcessor final : public AudioFileProcessor {
+ public:
+ // Takes ownership of all parameters.
+ WavFileProcessor(rtc::scoped_ptr<AudioProcessing> ap,
+ rtc::scoped_ptr<WavReader> in_file,
+ rtc::scoped_ptr<WavWriter> out_file);
+ virtual ~WavFileProcessor() {}
+
+ bool ProcessChunk() override;
+
+ private:
+ rtc::scoped_ptr<AudioProcessing> ap_;
+ rtc::scoped_ptr<WavReader> in_file_;
+
+ ChannelBuffer<float> in_buf_;
+ ChannelBuffer<float> out_buf_;
+ std::vector<float> in_interleaved_;
+ const StreamConfig input_config_;
+ const StreamConfig output_config_;
+ ChannelBufferWavWriter buffer_writer_;
+};
+
+// Used to read from an aecdump file and write to a WavWriter.
+class AecDumpFileProcessor final : public AudioFileProcessor {
+ public:
+ // Takes ownership of all parameters.
+ AecDumpFileProcessor(rtc::scoped_ptr<AudioProcessing> ap,
+ FILE* dump_file,
aluebs-webrtc 2015/10/24 00:53:34 Shouldn't this be a scoped_ptr? Else, you could pa
Andrew MacDonald 2015/10/29 00:44:50 It can't be a scoped_ptr unless I specialize the d
aluebs-webrtc 2015/10/29 01:03:19 Oh, I see. Agreed.
+ rtc::scoped_ptr<WavWriter> out_file);
+
+ virtual ~AecDumpFileProcessor();
+
+ // Processes messages from the aecdump file until the first Stream message is
+ // completed.
aluebs-webrtc 2015/10/24 00:53:34 Doesn't this mess with the chunk number in process
Andrew MacDonald 2015/10/29 00:44:50 No, because the chunk counter is indeed for the nu
aluebs-webrtc 2015/10/29 01:03:19 Good point.
+ bool ProcessChunk() override;
+
+ private:
+ void HandleMessage(const webrtc::audioproc::Init& msg);
+ void HandleMessage(const webrtc::audioproc::Stream& msg);
+ void HandleMessage(const webrtc::audioproc::ReverseStream& msg);
+
+ rtc::scoped_ptr<AudioProcessing> ap_;
+ FILE* dump_file_;
+
+ rtc::scoped_ptr<ChannelBuffer<float>> in_buf_;
+ rtc::scoped_ptr<ChannelBuffer<float>> reverse_buf_;
+ ChannelBuffer<float> out_buf_;
+ StreamConfig input_config_;
+ StreamConfig reverse_config_;
+ const StreamConfig output_config_;
+ ChannelBufferWavWriter buffer_writer_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_

Powered by Google App Engine
This is Rietveld 408576698