audio_frame_proxies.cc (2719B)
1 /* 2 * Copyright (c) 2020 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/include/audio_frame_proxies.h" 12 13 #include "api/audio/audio_frame.h" 14 #include "api/audio/audio_processing.h" 15 #include "api/audio/audio_processing_statistics.h" 16 #include "rtc_base/checks.h" 17 18 namespace webrtc { 19 20 int ProcessAudioFrame(AudioProcessing* ap, AudioFrame* frame) { 21 if (!frame || !ap) { 22 return AudioProcessing::Error::kNullPointerError; 23 } 24 25 StreamConfig input_config(frame->sample_rate_hz_, frame->num_channels_); 26 StreamConfig output_config(frame->sample_rate_hz_, frame->num_channels_); 27 RTC_DCHECK_EQ(frame->samples_per_channel(), input_config.num_frames()); 28 29 int result = ap->ProcessStream(frame->data(), input_config, output_config, 30 frame->mutable_data()); 31 32 AudioProcessingStats stats = ap->GetStatistics(); 33 34 // TODO: https://issues.webrtc.org/42221314 - remove when deleted 35 36 #if defined(__clang__) 37 #pragma clang diagnostic push 38 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 39 #endif 40 if (stats.voice_detected) { 41 frame->vad_activity_ = *stats.voice_detected 42 ? AudioFrame::VADActivity::kVadActive 43 : AudioFrame::VADActivity::kVadPassive; 44 } 45 46 #if defined(__clang__) 47 #pragma clang diagnostic pop 48 #endif 49 50 return result; 51 } 52 53 int ProcessReverseAudioFrame(AudioProcessing* ap, AudioFrame* frame) { 54 if (!frame || !ap) { 55 return AudioProcessing::Error::kNullPointerError; 56 } 57 58 // Must be a native rate. 59 if (frame->sample_rate_hz_ != AudioProcessing::NativeRate::kSampleRate8kHz && 60 frame->sample_rate_hz_ != AudioProcessing::NativeRate::kSampleRate16kHz && 61 frame->sample_rate_hz_ != AudioProcessing::NativeRate::kSampleRate32kHz && 62 frame->sample_rate_hz_ != AudioProcessing::NativeRate::kSampleRate48kHz) { 63 return AudioProcessing::Error::kBadSampleRateError; 64 } 65 66 if (frame->num_channels_ <= 0) { 67 return AudioProcessing::Error::kBadNumberChannelsError; 68 } 69 70 StreamConfig input_config(frame->sample_rate_hz_, frame->num_channels_); 71 StreamConfig output_config(frame->sample_rate_hz_, frame->num_channels_); 72 73 int result = ap->ProcessReverseStream(frame->data(), input_config, 74 output_config, frame->mutable_data()); 75 return result; 76 } 77 78 } // namespace webrtc