solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef CALL_AUDIO_STATE_H_ |
| 11 | #define CALL_AUDIO_STATE_H_ |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "api/audio/audio_mixer.h" |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 14 | #include "modules/audio_device/include/audio_device.h" |
| 15 | #include "modules/audio_processing/include/audio_processing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "rtc_base/refcount.h" |
| 17 | #include "rtc_base/scoped_ref_ptr.h" |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
Fredrik Solenberg | 63e6072 | 2017-11-20 22:12:21 +0100 | [diff] [blame] | 21 | class AudioTransport; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 22 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 23 | // AudioState holds the state which must be shared between multiple instances of |
| 24 | // webrtc::Call for audio processing purposes. |
| 25 | class AudioState : public rtc::RefCountInterface { |
| 26 | public: |
| 27 | struct Config { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 28 | Config(); |
| 29 | ~Config(); |
| 30 | |
aleloi | 81da488 | 2016-11-08 04:26:30 -0800 | [diff] [blame] | 31 | // The audio mixer connected to active receive streams. One per |
| 32 | // AudioState. |
| 33 | rtc::scoped_refptr<AudioMixer> audio_mixer; |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 34 | |
| 35 | // The audio processing module. |
| 36 | rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing; |
Fredrik Solenberg | cf73c96 | 2017-12-01 20:09:56 +0100 | [diff] [blame] | 37 | |
| 38 | // TODO(solenberg): Temporary: audio device module. |
| 39 | rtc::scoped_refptr<webrtc::AudioDeviceModule> audio_device_module; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 42 | struct Stats { |
| 43 | // Audio peak level (max(abs())), linearly on the interval [0,32767]. |
| 44 | int32_t audio_level = -1; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 45 | // See: |
| 46 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 47 | double total_energy = 0.0f; |
| 48 | double total_duration = 0.0f; |
| 49 | }; |
| 50 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 51 | virtual AudioProcessing* audio_processing() = 0; |
Fredrik Solenberg | 63e6072 | 2017-11-20 22:12:21 +0100 | [diff] [blame] | 52 | virtual AudioTransport* audio_transport() = 0; |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 53 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 54 | // Enable/disable playout of the audio channels. Enabled by default. |
| 55 | // This will stop playout of the underlying audio device but start a task |
| 56 | // which will poll for audio data every 10ms to ensure that audio processing |
| 57 | // happens and the audio stats are updated. |
| 58 | virtual void SetPlayout(bool enabled) = 0; |
| 59 | |
| 60 | // Enable/disable recording of the audio channels. Enabled by default. |
| 61 | // This will stop recording of the underlying audio device and no audio |
| 62 | // packets will be encoded or transmitted. |
| 63 | virtual void SetRecording(bool enabled) = 0; |
| 64 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 65 | virtual Stats GetAudioInputStats() const = 0; |
| 66 | virtual void SetStereoChannelSwapping(bool enable) = 0; |
| 67 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 68 | // TODO(solenberg): Replace scoped_refptr with shared_ptr once we can use it. |
| 69 | static rtc::scoped_refptr<AudioState> Create( |
| 70 | const AudioState::Config& config); |
| 71 | |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 72 | ~AudioState() override {} |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 73 | }; |
| 74 | } // namespace webrtc |
| 75 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 76 | #endif // CALL_AUDIO_STATE_H_ |