capture_stream_info.cc (2508B)
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 "modules/audio_processing/aec_dump/capture_stream_info.h" 12 13 #include <cstddef> 14 #include <cstdint> 15 16 #include "api/audio/audio_view.h" 17 #include "modules/audio_processing/include/aec_dump.h" 18 #include "modules/audio_processing/include/audio_frame_view.h" 19 20 namespace webrtc { 21 22 void CaptureStreamInfo::AddInput(const AudioFrameView<const float>& src) { 23 for (int i = 0; i < src.num_channels(); ++i) { 24 AddInputChannel(src.channel(i)); 25 } 26 } 27 28 void CaptureStreamInfo::AddInputChannel(MonoView<const float> channel) { 29 auto* stream = event_->mutable_stream(); 30 stream->add_input_channel(channel.begin(), sizeof(float) * channel.size()); 31 } 32 33 void CaptureStreamInfo::AddOutput(const AudioFrameView<const float>& src) { 34 for (int i = 0; i < src.num_channels(); ++i) { 35 AddOutputChannel(src.channel(i)); 36 } 37 } 38 39 void CaptureStreamInfo::AddOutputChannel(MonoView<const float> channel) { 40 auto* stream = event_->mutable_stream(); 41 stream->add_output_channel(channel.begin(), sizeof(float) * channel.size()); 42 } 43 44 void CaptureStreamInfo::AddInput(const int16_t* const data, 45 int num_channels, 46 int samples_per_channel) { 47 auto* stream = event_->mutable_stream(); 48 const size_t data_size = sizeof(int16_t) * samples_per_channel * num_channels; 49 stream->set_input_data(data, data_size); 50 } 51 52 void CaptureStreamInfo::AddOutput(const int16_t* const data, 53 int num_channels, 54 int samples_per_channel) { 55 auto* stream = event_->mutable_stream(); 56 const size_t data_size = sizeof(int16_t) * samples_per_channel * num_channels; 57 stream->set_output_data(data, data_size); 58 } 59 60 void CaptureStreamInfo::AddAudioProcessingState( 61 const AecDump::AudioProcessingState& state) { 62 auto* stream = event_->mutable_stream(); 63 stream->set_delay(state.delay); 64 stream->set_drift(state.drift); 65 if (state.applied_input_volume.has_value()) { 66 stream->set_applied_input_volume(*state.applied_input_volume); 67 } 68 stream->set_keypress(state.keypress); 69 } 70 } // namespace webrtc