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