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