blob: 680056631cc4caeba08ff6be849f06ecebdfd8fc [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>
kwiberg88788ad2016-02-19 07:04:49 -080015#include <memory>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/constructor_magic.h"
19#include "rtc_base/critical_section.h"
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "rtc_base/thread_annotations.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22namespace webrtc {
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000023
niklase@google.com470e71d2011-07-07 08:21:25 +000024class AudioBuffer;
25
solenberga29386c2015-12-16 03:31:12 -080026class VoiceDetectionImpl : public VoiceDetection {
niklase@google.com470e71d2011-07-07 08:21:25 +000027 public:
solenberga29386c2015-12-16 03:31:12 -080028 explicit VoiceDetectionImpl(rtc::CriticalSection* crit);
29 ~VoiceDetectionImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
solenberga29386c2015-12-16 03:31:12 -080031 // TODO(peah): Fold into ctor, once public API is removed.
32 void Initialize(int sample_rate_hz);
33 void ProcessCaptureAudio(AudioBuffer* audio);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
35 // VoiceDetection implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 int Enable(bool enable) override;
solenberga29386c2015-12-16 03:31:12 -080037 bool is_enabled() const override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 int set_stream_has_voice(bool has_voice) override;
39 bool stream_has_voice() const override;
40 int set_likelihood(Likelihood likelihood) override;
41 Likelihood likelihood() const override;
42 int set_frame_size_ms(int size) override;
43 int frame_size_ms() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
solenberga29386c2015-12-16 03:31:12 -080045 private:
46 class Vad;
Yves Gerey988cc082018-10-23 12:03:01 +020047
peahdf3efa82015-11-28 12:35:15 -080048 rtc::CriticalSection* const crit_;
danilchap56359be2017-09-07 07:53:45 -070049 bool enabled_ RTC_GUARDED_BY(crit_) = false;
50 bool stream_has_voice_ RTC_GUARDED_BY(crit_) = false;
51 bool using_external_vad_ RTC_GUARDED_BY(crit_) = false;
52 Likelihood likelihood_ RTC_GUARDED_BY(crit_) = kLowLikelihood;
53 int frame_size_ms_ RTC_GUARDED_BY(crit_) = 10;
54 size_t frame_size_samples_ RTC_GUARDED_BY(crit_) = 0;
55 int sample_rate_hz_ RTC_GUARDED_BY(crit_) = 0;
56 std::unique_ptr<Vad> vad_ RTC_GUARDED_BY(crit_);
solenberga29386c2015-12-16 03:31:12 -080057 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(VoiceDetectionImpl);
niklase@google.com470e71d2011-07-07 08:21:25 +000058};
59} // namespace webrtc
60
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020061#endif // MODULES_AUDIO_PROCESSING_VOICE_DETECTION_IMPL_H_