blob: dac95f02f83954f0e4040f23eb2086c3b5a8195a [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
2 * Copyright (c) 2013 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_NETEQ_POST_DECODE_VAD_H_
12#define MODULES_AUDIO_CODING_NETEQ_POST_DECODE_VAD_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
14#include <string> // size_t
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/audio_codecs/audio_decoder.h"
17#include "common_audio/vad/include/webrtc_vad.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "common_types.h" // NOLINT(build/include) // NULL
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_coding/neteq/defines.h"
20#include "modules/audio_coding/neteq/packet.h"
21#include "rtc_base/constructormagic.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020022#include "typedefs.h" // NOLINT(build/include)
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000023
24namespace webrtc {
25
26class PostDecodeVad {
27 public:
28 PostDecodeVad()
29 : enabled_(false),
30 running_(false),
31 active_speech_(true),
32 sid_interval_counter_(0),
Yves Gerey665174f2018-06-19 15:03:05 +020033 vad_instance_(NULL) {}
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000034
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000035 virtual ~PostDecodeVad();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000036
37 // Enables post-decode VAD.
38 void Enable();
39
40 // Disables post-decode VAD.
41 void Disable();
42
43 // Initializes post-decode VAD.
44 void Init();
45
46 // Updates post-decode VAD with the audio data in |signal| having |length|
47 // samples. The data is of type |speech_type|, at the sample rate |fs_hz|.
Yves Gerey665174f2018-06-19 15:03:05 +020048 void Update(int16_t* signal,
49 size_t length,
50 AudioDecoder::SpeechType speech_type,
51 bool sid_frame,
52 int fs_hz);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000053
54 // Accessors.
55 bool enabled() const { return enabled_; }
56 bool running() const { return running_; }
57 bool active_speech() const { return active_speech_; }
58
59 private:
60 static const int kVadMode = 0; // Sets aggressiveness to "Normal".
61 // Number of Update() calls without CNG/SID before re-enabling VAD.
62 static const int kVadAutoEnable = 3000;
63
64 bool enabled_;
65 bool running_;
66 bool active_speech_;
67 int sid_interval_counter_;
68 ::VadInst* vad_instance_;
69
henrikg3c089d72015-09-16 05:37:44 -070070 RTC_DISALLOW_COPY_AND_ASSIGN(PostDecodeVad);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000071};
72
73} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#endif // MODULES_AUDIO_CODING_NETEQ_POST_DECODE_VAD_H_