niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
| 11 | #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H |
| 12 | #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H |
| 13 | |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/audio_device/include/audio_device.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 15 | #include "webrtc/system_wrappers/include/file_wrapper.h" |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | class CriticalSectionWrapper; |
| 20 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 21 | const uint32_t kPulsePeriodMs = 1000; |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 22 | const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | class AudioDeviceObserver; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 26 | class AudioDeviceBuffer { |
| 27 | public: |
| 28 | AudioDeviceBuffer(); |
| 29 | virtual ~AudioDeviceBuffer(); |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 30 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 31 | void SetId(uint32_t id); |
| 32 | int32_t RegisterAudioCallback(AudioTransport* audioCallback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 34 | int32_t InitPlayout(); |
| 35 | int32_t InitRecording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 37 | virtual int32_t SetRecordingSampleRate(uint32_t fsHz); |
| 38 | virtual int32_t SetPlayoutSampleRate(uint32_t fsHz); |
| 39 | int32_t RecordingSampleRate() const; |
| 40 | int32_t PlayoutSampleRate() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 42 | virtual int32_t SetRecordingChannels(size_t channels); |
| 43 | virtual int32_t SetPlayoutChannels(size_t channels); |
| 44 | size_t RecordingChannels() const; |
| 45 | size_t PlayoutChannels() const; |
| 46 | int32_t SetRecordingChannel(const AudioDeviceModule::ChannelType channel); |
| 47 | int32_t RecordingChannel(AudioDeviceModule::ChannelType& channel) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 49 | virtual int32_t SetRecordedBuffer(const void* audioBuffer, size_t nSamples); |
| 50 | int32_t SetCurrentMicLevel(uint32_t level); |
| 51 | virtual void SetVQEData(int playDelayMS, int recDelayMS, int clockDrift); |
| 52 | virtual int32_t DeliverRecordedData(); |
| 53 | uint32_t NewMicLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 55 | virtual int32_t RequestPlayoutData(size_t nSamples); |
| 56 | virtual int32_t GetPlayoutData(void* audioBuffer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 58 | int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); |
| 59 | int32_t StopInputFileRecording(); |
| 60 | int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); |
| 61 | int32_t StopOutputFileRecording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 63 | int32_t SetTypingStatus(bool typingStatus); |
niklas.enbom@webrtc.org | 3be565b | 2013-05-07 21:04:24 +0000 | [diff] [blame] | 64 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 65 | private: |
| 66 | int32_t _id; |
| 67 | CriticalSectionWrapper& _critSect; |
| 68 | CriticalSectionWrapper& _critSectCb; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 70 | AudioTransport* _ptrCbAudioTransport; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 72 | uint32_t _recSampleRate; |
| 73 | uint32_t _playSampleRate; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 75 | size_t _recChannels; |
| 76 | size_t _playChannels; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 78 | // selected recording channel (left/right/both) |
| 79 | AudioDeviceModule::ChannelType _recChannel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 81 | // 2 or 4 depending on mono or stereo |
| 82 | size_t _recBytesPerSample; |
| 83 | size_t _playBytesPerSample; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 85 | // 10ms in stereo @ 96kHz |
| 86 | int8_t _recBuffer[kMaxBufferSizeBytes]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 88 | // one sample <=> 2 or 4 bytes |
| 89 | size_t _recSamples; |
| 90 | size_t _recSize; // in bytes |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 92 | // 10ms in stereo @ 96kHz |
| 93 | int8_t _playBuffer[kMaxBufferSizeBytes]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 95 | // one sample <=> 2 or 4 bytes |
| 96 | size_t _playSamples; |
| 97 | size_t _playSize; // in bytes |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 99 | FileWrapper& _recFile; |
| 100 | FileWrapper& _playFile; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 102 | uint32_t _currentMicLevel; |
| 103 | uint32_t _newMicLevel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 105 | bool _typingStatus; |
niklas.enbom@webrtc.org | 3be565b | 2013-05-07 21:04:24 +0000 | [diff] [blame] | 106 | |
henrika | 0fd6801 | 2016-07-04 13:01:19 +0200 | [diff] [blame] | 107 | int _playDelayMS; |
| 108 | int _recDelayMS; |
| 109 | int _clockDrift; |
| 110 | int high_delay_counter_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | } // namespace webrtc |
| 114 | |
| 115 | #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H |