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