blob: 4007f6713b8687087d32f572ed5a33eeaa883b35 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_VOICE_DETECTION_IMPL_H_
12#define MODULES_AUDIO_PROCESSING_VOICE_DETECTION_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
kwiberg88788ad2016-02-19 07:04:49 -080016#include <memory>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/constructor_magic.h"
20#include "rtc_base/critical_section.h"
Yves Gerey988cc082018-10-23 12:03:01 +020021#include "rtc_base/thread_annotations.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23namespace webrtc {
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000024
niklase@google.com470e71d2011-07-07 08:21:25 +000025class AudioBuffer;
26
solenberga29386c2015-12-16 03:31:12 -080027class VoiceDetectionImpl : public VoiceDetection {
niklase@google.com470e71d2011-07-07 08:21:25 +000028 public:
solenberga29386c2015-12-16 03:31:12 -080029 explicit VoiceDetectionImpl(rtc::CriticalSection* crit);
30 ~VoiceDetectionImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
solenberga29386c2015-12-16 03:31:12 -080032 // TODO(peah): Fold into ctor, once public API is removed.
33 void Initialize(int sample_rate_hz);
34 void ProcessCaptureAudio(AudioBuffer* audio);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
36 // VoiceDetection implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000037 int Enable(bool enable) override;
solenberga29386c2015-12-16 03:31:12 -080038 bool is_enabled() const override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000039 int set_stream_has_voice(bool has_voice) override;
40 bool stream_has_voice() const override;
41 int set_likelihood(Likelihood likelihood) override;
42 Likelihood likelihood() const override;
43 int set_frame_size_ms(int size) override;
44 int frame_size_ms() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
solenberga29386c2015-12-16 03:31:12 -080046 private:
47 class Vad;
Yves Gerey988cc082018-10-23 12:03:01 +020048
peahdf3efa82015-11-28 12:35:15 -080049 rtc::CriticalSection* const crit_;
danilchap56359be2017-09-07 07:53:45 -070050 bool enabled_ RTC_GUARDED_BY(crit_) = false;
51 bool stream_has_voice_ RTC_GUARDED_BY(crit_) = false;
52 bool using_external_vad_ RTC_GUARDED_BY(crit_) = false;
53 Likelihood likelihood_ RTC_GUARDED_BY(crit_) = kLowLikelihood;
54 int frame_size_ms_ RTC_GUARDED_BY(crit_) = 10;
55 size_t frame_size_samples_ RTC_GUARDED_BY(crit_) = 0;
56 int sample_rate_hz_ RTC_GUARDED_BY(crit_) = 0;
57 std::unique_ptr<Vad> vad_ RTC_GUARDED_BY(crit_);
solenberga29386c2015-12-16 03:31:12 -080058 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(VoiceDetectionImpl);
niklase@google.com470e71d2011-07-07 08:21:25 +000059};
60} // namespace webrtc
61
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020062#endif // MODULES_AUDIO_PROCESSING_VOICE_DETECTION_IMPL_H_