OLD | NEW |
(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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_DUMP_CAPTURE_STREAM_INFO_IMPL_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_DUMP_CAPTURE_STREAM_INFO_IMPL_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <utility> |
| 16 #include <vector> |
| 17 |
| 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/ignore_wundef.h" |
| 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/modules/audio_processing/include/aec_dump.h" |
| 22 #include "webrtc/modules/include/module_common_types.h" |
| 23 |
| 24 // Files generated at build-time by the protobuf compiler. |
| 25 RTC_PUSH_IGNORING_WUNDEF() |
| 26 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 27 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" |
| 28 #else |
| 29 #include "webrtc/modules/audio_processing/debug.pb.h" |
| 30 #endif |
| 31 RTC_POP_IGNORING_WUNDEF() |
| 32 |
| 33 namespace webrtc { |
| 34 |
| 35 // Optionally inherit from TaskQueue task. |
| 36 class CaptureStreamInfoImpl final : public AecDump::CaptureStreamInfo { |
| 37 public: |
| 38 explicit CaptureStreamInfoImpl(std::unique_ptr<audioproc::Event> event); |
| 39 ~CaptureStreamInfoImpl() override; |
| 40 void AddInput(const std::vector<rtc::ArrayView<const float>>& src) override; |
| 41 void AddOutput(const std::vector<rtc::ArrayView<const float>>& src) override; |
| 42 |
| 43 void AddInput(const AudioFrame& frame) override; |
| 44 void AddOutput(const AudioFrame& frame) override; |
| 45 |
| 46 void set_delay(int delay) override; |
| 47 void set_drift(int drift) override; |
| 48 void set_level(int level) override; |
| 49 void set_keypress(bool keypress) override; |
| 50 |
| 51 std::unique_ptr<audioproc::Event> GetEventMsg() { |
| 52 return std::unique_ptr<audioproc::Event>(event_.release()); |
| 53 } |
| 54 |
| 55 private: |
| 56 std::unique_ptr<audioproc::Event> event_; |
| 57 }; |
| 58 |
| 59 CaptureStreamInfoImpl::CaptureStreamInfoImpl( |
| 60 std::unique_ptr<audioproc::Event> event) |
| 61 : event_(std::move(event)) { |
| 62 RTC_DCHECK(event_); |
| 63 event_->set_type(audioproc::Event::STREAM); |
| 64 } |
| 65 |
| 66 CaptureStreamInfoImpl::~CaptureStreamInfoImpl() = default; |
| 67 |
| 68 void CaptureStreamInfoImpl::AddInput( |
| 69 const std::vector<rtc::ArrayView<const float>>& src) { |
| 70 if (!event_) { |
| 71 return; |
| 72 } |
| 73 auto* stream = event_->mutable_stream(); |
| 74 for (const auto& channel_view : src) { |
| 75 stream->add_input_channel(channel_view.begin(), channel_view.size()); |
| 76 } |
| 77 } |
| 78 |
| 79 void CaptureStreamInfoImpl::AddOutput( |
| 80 const std::vector<rtc::ArrayView<const float>>& src) { |
| 81 if (!event_) { |
| 82 return; |
| 83 } |
| 84 auto* stream = event_->mutable_stream(); |
| 85 for (const auto& channel_view : src) { |
| 86 stream->add_output_channel(channel_view.begin(), channel_view.size()); |
| 87 } |
| 88 } |
| 89 |
| 90 void CaptureStreamInfoImpl::AddInput(const AudioFrame& frame) { |
| 91 if (!event_) { |
| 92 return; |
| 93 } |
| 94 audioproc::Stream* stream = event_->mutable_stream(); |
| 95 const size_t data_size = |
| 96 sizeof(int16_t) * frame.samples_per_channel_ * frame.num_channels_; |
| 97 stream->set_input_data(frame.data_, data_size); |
| 98 } |
| 99 |
| 100 void CaptureStreamInfoImpl::AddOutput(const AudioFrame& frame) { |
| 101 if (!event_) { |
| 102 return; |
| 103 } |
| 104 audioproc::Stream* stream = event_->mutable_stream(); |
| 105 const size_t data_size = |
| 106 sizeof(int16_t) * frame.samples_per_channel_ * frame.num_channels_; |
| 107 stream->set_output_data(frame.data_, data_size); |
| 108 } |
| 109 |
| 110 void CaptureStreamInfoImpl::set_delay(int delay) { |
| 111 if (!event_) { |
| 112 return; |
| 113 } |
| 114 event_->mutable_stream()->set_delay(delay); |
| 115 } |
| 116 void CaptureStreamInfoImpl::set_drift(int drift) { |
| 117 if (!event_) { |
| 118 return; |
| 119 } |
| 120 event_->mutable_stream()->set_drift(drift); |
| 121 } |
| 122 void CaptureStreamInfoImpl::set_level(int level) { |
| 123 if (!event_) { |
| 124 return; |
| 125 } |
| 126 event_->mutable_stream()->set_level(level); |
| 127 } |
| 128 void CaptureStreamInfoImpl::set_keypress(bool keypress) { |
| 129 if (!event_) { |
| 130 return; |
| 131 } |
| 132 event_->mutable_stream()->set_keypress(keypress); |
| 133 } |
| 134 |
| 135 } // namespace webrtc |
| 136 |
| 137 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_DUMP_CAPTURE_STREAM_INFO_IMPL_H_ |
OLD | NEW |