OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_ |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <limits> | 15 #include <limits> |
16 #include <memory> | 16 #include <memory> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
| 19 #include "webrtc/base/timeutils.h" |
19 #include "webrtc/common_audio/channel_buffer.h" | 20 #include "webrtc/common_audio/channel_buffer.h" |
20 #include "webrtc/common_audio/wav_file.h" | 21 #include "webrtc/common_audio/wav_file.h" |
21 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 22 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
22 #include "webrtc/modules/audio_processing/test/test_utils.h" | 23 #include "webrtc/modules/audio_processing/test/test_utils.h" |
23 #include "webrtc/system_wrappers/include/tick_util.h" | |
24 | 24 |
25 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 25 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
26 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" | 26 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" |
27 #else | 27 #else |
28 #include "webrtc/modules/audio_processing/debug.pb.h" | 28 #include "webrtc/modules/audio_processing/debug.pb.h" |
29 #endif | 29 #endif |
30 | 30 |
31 namespace webrtc { | 31 namespace webrtc { |
32 | 32 |
33 // Holds a few statistics about a series of TickIntervals. | 33 // Holds a few statistics about a series of TickIntervals. |
34 struct TickIntervalStats { | 34 struct TickIntervalStats { |
35 TickIntervalStats() : min(std::numeric_limits<int64_t>::max()) {} | 35 TickIntervalStats() : min(std::numeric_limits<int64_t>::max()) {} |
36 TickInterval sum; | 36 int64_t sum; |
37 TickInterval max; | 37 int64_t max; |
38 TickInterval min; | 38 int64_t min; |
39 }; | 39 }; |
40 | 40 |
41 // Interface for processing an input file with an AudioProcessing instance and | 41 // Interface for processing an input file with an AudioProcessing instance and |
42 // dumping the results to an output file. | 42 // dumping the results to an output file. |
43 class AudioFileProcessor { | 43 class AudioFileProcessor { |
44 public: | 44 public: |
45 static const int kChunksPerSecond = 1000 / AudioProcessing::kChunkSizeMs; | 45 static const int kChunksPerSecond = 1000 / AudioProcessing::kChunkSizeMs; |
46 | 46 |
47 virtual ~AudioFileProcessor() {} | 47 virtual ~AudioFileProcessor() {} |
48 | 48 |
49 // Processes one AudioProcessing::kChunkSizeMs of data from the input file and | 49 // Processes one AudioProcessing::kChunkSizeMs of data from the input file and |
50 // writes to the output file. | 50 // writes to the output file. |
51 virtual bool ProcessChunk() = 0; | 51 virtual bool ProcessChunk() = 0; |
52 | 52 |
53 // Returns the execution time of all AudioProcessing calls. | 53 // Returns the execution time of all AudioProcessing calls. |
54 const TickIntervalStats& proc_time() const { return proc_time_; } | 54 const TickIntervalStats& proc_time() const { return proc_time_; } |
55 | 55 |
56 protected: | 56 protected: |
57 // RAII class for execution time measurement. Updates the provided | 57 // RAII class for execution time measurement. Updates the provided |
58 // TickIntervalStats based on the time between ScopedTimer creation and | 58 // TickIntervalStats based on the time between ScopedTimer creation and |
59 // leaving the enclosing scope. | 59 // leaving the enclosing scope. |
60 class ScopedTimer { | 60 class ScopedTimer { |
61 public: | 61 public: |
62 explicit ScopedTimer(TickIntervalStats* proc_time) | 62 explicit ScopedTimer(TickIntervalStats* proc_time) |
63 : proc_time_(proc_time), start_time_(TickTime::Now()) {} | 63 : proc_time_(proc_time), start_time_(rtc::TimeNanos()) {} |
64 | 64 |
65 ~ScopedTimer() { | 65 ~ScopedTimer() { |
66 TickInterval interval = TickTime::Now() - start_time_; | 66 int64_t interval = rtc::TimeNanos() - start_time_; |
67 proc_time_->sum += interval; | 67 proc_time_->sum += interval; |
68 proc_time_->max = std::max(proc_time_->max, interval); | 68 proc_time_->max = std::max(proc_time_->max, interval); |
69 proc_time_->min = std::min(proc_time_->min, interval); | 69 proc_time_->min = std::min(proc_time_->min, interval); |
70 } | 70 } |
71 | 71 |
72 private: | 72 private: |
73 TickIntervalStats* const proc_time_; | 73 TickIntervalStats* const proc_time_; |
74 TickTime start_time_; | 74 int64_t start_time_; |
75 }; | 75 }; |
76 | 76 |
77 TickIntervalStats* mutable_proc_time() { return &proc_time_; } | 77 TickIntervalStats* mutable_proc_time() { return &proc_time_; } |
78 | 78 |
79 private: | 79 private: |
80 TickIntervalStats proc_time_; | 80 TickIntervalStats proc_time_; |
81 }; | 81 }; |
82 | 82 |
83 // Used to read from and write to WavFile objects. | 83 // Used to read from and write to WavFile objects. |
84 class WavFileProcessor final : public AudioFileProcessor { | 84 class WavFileProcessor final : public AudioFileProcessor { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ChannelBuffer<float> out_buf_; | 138 ChannelBuffer<float> out_buf_; |
139 StreamConfig input_config_; | 139 StreamConfig input_config_; |
140 StreamConfig reverse_config_; | 140 StreamConfig reverse_config_; |
141 const StreamConfig output_config_; | 141 const StreamConfig output_config_; |
142 ChannelBufferWavWriter buffer_writer_; | 142 ChannelBufferWavWriter buffer_writer_; |
143 }; | 143 }; |
144 | 144 |
145 } // namespace webrtc | 145 } // namespace webrtc |
146 | 146 |
147 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_ | 147 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_FILE_PROCESSOR_H_ |
OLD | NEW |