blob: 11b49c1100b50881f93e63272849cb76d4a101fa [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org811269d2013-07-11 13:24:38 +000014#include "webrtc/modules/audio_device/include/audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010015#include "webrtc/system_wrappers/include/file_wrapper.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000016#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
19class CriticalSectionWrapper;
20
pbos@webrtc.org25509882013-04-09 10:30:35 +000021const uint32_t kPulsePeriodMs = 1000;
henrika0fd68012016-07-04 13:01:19 +020022const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24class AudioDeviceObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000025
henrika0fd68012016-07-04 13:01:19 +020026class AudioDeviceBuffer {
27 public:
28 AudioDeviceBuffer();
29 virtual ~AudioDeviceBuffer();
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000030
henrika0fd68012016-07-04 13:01:19 +020031 void SetId(uint32_t id);
32 int32_t RegisterAudioCallback(AudioTransport* audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
henrika0fd68012016-07-04 13:01:19 +020034 int32_t InitPlayout();
35 int32_t InitRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000036
henrika0fd68012016-07-04 13:01:19 +020037 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.com470e71d2011-07-07 08:21:25 +000041
henrika0fd68012016-07-04 13:01:19 +020042 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.com470e71d2011-07-07 08:21:25 +000048
henrika0fd68012016-07-04 13:01:19 +020049 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.com470e71d2011-07-07 08:21:25 +000054
henrika0fd68012016-07-04 13:01:19 +020055 virtual int32_t RequestPlayoutData(size_t nSamples);
56 virtual int32_t GetPlayoutData(void* audioBuffer);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
henrika0fd68012016-07-04 13:01:19 +020058 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.com470e71d2011-07-07 08:21:25 +000062
henrika0fd68012016-07-04 13:01:19 +020063 int32_t SetTypingStatus(bool typingStatus);
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +000064
henrika0fd68012016-07-04 13:01:19 +020065 private:
66 int32_t _id;
67 CriticalSectionWrapper& _critSect;
68 CriticalSectionWrapper& _critSectCb;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
henrika0fd68012016-07-04 13:01:19 +020070 AudioTransport* _ptrCbAudioTransport;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
henrika0fd68012016-07-04 13:01:19 +020072 uint32_t _recSampleRate;
73 uint32_t _playSampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +000074
henrika0fd68012016-07-04 13:01:19 +020075 size_t _recChannels;
76 size_t _playChannels;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
henrika0fd68012016-07-04 13:01:19 +020078 // selected recording channel (left/right/both)
79 AudioDeviceModule::ChannelType _recChannel;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
henrika0fd68012016-07-04 13:01:19 +020081 // 2 or 4 depending on mono or stereo
82 size_t _recBytesPerSample;
83 size_t _playBytesPerSample;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
henrika0fd68012016-07-04 13:01:19 +020085 // 10ms in stereo @ 96kHz
86 int8_t _recBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000087
henrika0fd68012016-07-04 13:01:19 +020088 // one sample <=> 2 or 4 bytes
89 size_t _recSamples;
90 size_t _recSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000091
henrika0fd68012016-07-04 13:01:19 +020092 // 10ms in stereo @ 96kHz
93 int8_t _playBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000094
henrika0fd68012016-07-04 13:01:19 +020095 // one sample <=> 2 or 4 bytes
96 size_t _playSamples;
97 size_t _playSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000098
henrika0fd68012016-07-04 13:01:19 +020099 FileWrapper& _recFile;
100 FileWrapper& _playFile;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
henrika0fd68012016-07-04 13:01:19 +0200102 uint32_t _currentMicLevel;
103 uint32_t _newMicLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
henrika0fd68012016-07-04 13:01:19 +0200105 bool _typingStatus;
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +0000106
henrika0fd68012016-07-04 13:01:19 +0200107 int _playDelayMS;
108 int _recDelayMS;
109 int _clockDrift;
110 int high_delay_counter_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111};
112
113} // namespace webrtc
114
115#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H