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