blob: 56d5d44075942ba1bf48b099af5805b4bb610c0e [file] [log] [blame]
solenberg566ef242015-11-06 15:34:49 -08001/*
2 * Copyright (c) 2015 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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef CALL_AUDIO_STATE_H_
11#define CALL_AUDIO_STATE_H_
solenberg566ef242015-11-06 15:34:49 -080012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "api/audio/audio_mixer.h"
14#include "rtc_base/refcount.h"
15#include "rtc_base/scoped_ref_ptr.h"
solenberg566ef242015-11-06 15:34:49 -080016
17namespace webrtc {
18
Fredrik Solenbergcf73c962017-12-01 20:09:56 +010019class AudioDeviceModule;
peaha9cc40b2017-06-29 08:32:09 -070020class AudioProcessing;
Fredrik Solenberg63e60722017-11-20 22:12:21 +010021class AudioTransport;
solenberg566ef242015-11-06 15:34:49 -080022class VoiceEngine;
23
Fredrik Solenberga4527c82015-12-03 13:06:20 +010024// WORK IN PROGRESS
25// This class is under development and is not yet intended for for use outside
26// of WebRtc/Libjingle. Please use the VoiceEngine API instead.
27// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4690
28
solenberg566ef242015-11-06 15:34:49 -080029// AudioState holds the state which must be shared between multiple instances of
30// webrtc::Call for audio processing purposes.
31class AudioState : public rtc::RefCountInterface {
32 public:
33 struct Config {
34 // VoiceEngine used for audio streams and audio/video synchronization.
35 // AudioState will tickle the VoE refcount to keep it alive for as long as
36 // the AudioState itself.
37 VoiceEngine* voice_engine = nullptr;
38
aleloi81da4882016-11-08 04:26:30 -080039 // The audio mixer connected to active receive streams. One per
40 // AudioState.
41 rtc::scoped_refptr<AudioMixer> audio_mixer;
peaha9cc40b2017-06-29 08:32:09 -070042
43 // The audio processing module.
44 rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing;
Fredrik Solenbergcf73c962017-12-01 20:09:56 +010045
46 // TODO(solenberg): Temporary: audio device module.
47 rtc::scoped_refptr<webrtc::AudioDeviceModule> audio_device_module;
solenberg566ef242015-11-06 15:34:49 -080048 };
49
Fredrik Solenberg2a877972017-12-15 16:42:15 +010050 struct Stats {
51 // Audio peak level (max(abs())), linearly on the interval [0,32767].
52 int32_t audio_level = -1;
53 // Audio peak level (max(abs())), logarithmically on the interval [0,9].
54 int8_t quantized_audio_level = -1;
55 // See: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
56 double total_energy = 0.0f;
57 double total_duration = 0.0f;
58 };
59
peaha9cc40b2017-06-29 08:32:09 -070060 virtual AudioProcessing* audio_processing() = 0;
Fredrik Solenberg63e60722017-11-20 22:12:21 +010061 virtual AudioTransport* audio_transport() = 0;
peaha9cc40b2017-06-29 08:32:09 -070062
henrika5f6bf242017-11-01 11:06:56 +010063 // Enable/disable playout of the audio channels. Enabled by default.
64 // This will stop playout of the underlying audio device but start a task
65 // which will poll for audio data every 10ms to ensure that audio processing
66 // happens and the audio stats are updated.
67 virtual void SetPlayout(bool enabled) = 0;
68
69 // Enable/disable recording of the audio channels. Enabled by default.
70 // This will stop recording of the underlying audio device and no audio
71 // packets will be encoded or transmitted.
72 virtual void SetRecording(bool enabled) = 0;
73
Fredrik Solenberg2a877972017-12-15 16:42:15 +010074 virtual Stats GetAudioInputStats() const = 0;
75 virtual void SetStereoChannelSwapping(bool enable) = 0;
76
solenberg566ef242015-11-06 15:34:49 -080077 // TODO(solenberg): Replace scoped_refptr with shared_ptr once we can use it.
78 static rtc::scoped_refptr<AudioState> Create(
79 const AudioState::Config& config);
80
81 virtual ~AudioState() {}
82};
83} // namespace webrtc
84
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020085#endif // CALL_AUDIO_STATE_H_