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 {
CaptureStreamInfo(std::unique_ptr<WriteToFileTask> task)14 CaptureStreamInfo::CaptureStreamInfo(std::unique_ptr<WriteToFileTask> task)
15 : task_(std::move(task)) {
16 RTC_DCHECK(task_);
17 task_->GetEvent()->set_type(audioproc::Event::STREAM);
18 }
19
20 CaptureStreamInfo::~CaptureStreamInfo() = default;
21
AddInput(const AudioFrameView<const float> & src)22 void CaptureStreamInfo::AddInput(const AudioFrameView<const float>& src) {
23 RTC_DCHECK(task_);
24 auto* stream = task_->GetEvent()->mutable_stream();
25
26 for (size_t i = 0; i < src.num_channels(); ++i) {
27 const auto& channel_view = src.channel(i);
28 stream->add_input_channel(channel_view.begin(),
29 sizeof(float) * channel_view.size());
30 }
31 }
32
AddOutput(const AudioFrameView<const float> & src)33 void CaptureStreamInfo::AddOutput(const AudioFrameView<const float>& src) {
34 RTC_DCHECK(task_);
35 auto* stream = task_->GetEvent()->mutable_stream();
36
37 for (size_t i = 0; i < src.num_channels(); ++i) {
38 const auto& channel_view = src.channel(i);
39 stream->add_output_channel(channel_view.begin(),
40 sizeof(float) * channel_view.size());
41 }
42 }
43
AddInput(const int16_t * const data,int num_channels,int samples_per_channel)44 void CaptureStreamInfo::AddInput(const int16_t* const data,
45 int num_channels,
46 int samples_per_channel) {
47 RTC_DCHECK(task_);
48 auto* stream = task_->GetEvent()->mutable_stream();
49 const size_t data_size = sizeof(int16_t) * samples_per_channel * num_channels;
50 stream->set_input_data(data, data_size);
51 }
52
AddOutput(const int16_t * const data,int num_channels,int samples_per_channel)53 void CaptureStreamInfo::AddOutput(const int16_t* const data,
54 int num_channels,
55 int samples_per_channel) {
56 RTC_DCHECK(task_);
57 auto* stream = task_->GetEvent()->mutable_stream();
58 const size_t data_size = sizeof(int16_t) * samples_per_channel * num_channels;
59 stream->set_output_data(data, data_size);
60 }
61
AddAudioProcessingState(const AecDump::AudioProcessingState & state)62 void CaptureStreamInfo::AddAudioProcessingState(
63 const AecDump::AudioProcessingState& state) {
64 RTC_DCHECK(task_);
65 auto* stream = task_->GetEvent()->mutable_stream();
66 stream->set_delay(state.delay);
67 stream->set_drift(state.drift);
68 stream->set_level(state.level);
69 stream->set_keypress(state.keypress);
70 }
71 } // namespace webrtc
72