xref: /aosp_15_r20/external/webrtc/modules/audio_processing/aec_dump/capture_stream_info.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 namespace webrtc {
14 
AddInput(const AudioFrameView<const float> & src)15 void CaptureStreamInfo::AddInput(const AudioFrameView<const float>& src) {
16   auto* stream = event_->mutable_stream();
17 
18   for (int i = 0; i < src.num_channels(); ++i) {
19     const auto& channel_view = src.channel(i);
20     stream->add_input_channel(channel_view.begin(),
21                               sizeof(float) * channel_view.size());
22   }
23 }
24 
AddOutput(const AudioFrameView<const float> & src)25 void CaptureStreamInfo::AddOutput(const AudioFrameView<const float>& src) {
26   auto* stream = event_->mutable_stream();
27 
28   for (int i = 0; i < src.num_channels(); ++i) {
29     const auto& channel_view = src.channel(i);
30     stream->add_output_channel(channel_view.begin(),
31                                sizeof(float) * channel_view.size());
32   }
33 }
34 
AddInput(const int16_t * const data,int num_channels,int samples_per_channel)35 void CaptureStreamInfo::AddInput(const int16_t* const data,
36                                  int num_channels,
37                                  int samples_per_channel) {
38   auto* stream = event_->mutable_stream();
39   const size_t data_size = sizeof(int16_t) * samples_per_channel * num_channels;
40   stream->set_input_data(data, data_size);
41 }
42 
AddOutput(const int16_t * const data,int num_channels,int samples_per_channel)43 void CaptureStreamInfo::AddOutput(const int16_t* const data,
44                                   int num_channels,
45                                   int samples_per_channel) {
46   auto* stream = event_->mutable_stream();
47   const size_t data_size = sizeof(int16_t) * samples_per_channel * num_channels;
48   stream->set_output_data(data, data_size);
49 }
50 
AddAudioProcessingState(const AecDump::AudioProcessingState & state)51 void CaptureStreamInfo::AddAudioProcessingState(
52     const AecDump::AudioProcessingState& state) {
53   auto* stream = event_->mutable_stream();
54   stream->set_delay(state.delay);
55   stream->set_drift(state.drift);
56   if (state.applied_input_volume.has_value()) {
57     stream->set_applied_input_volume(*state.applied_input_volume);
58   }
59   stream->set_keypress(state.keypress);
60 }
61 }  // namespace webrtc
62