blob: 1267e08be2cfb9696c083e95141c79ebb2917a9a [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
henrika3f33e2a2016-07-06 00:33:57 -070031 void SetId(uint32_t id) {};
henrika0fd68012016-07-04 13:01:19 +020032 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:
henrika0fd68012016-07-04 13:01:19 +020066 CriticalSectionWrapper& _critSect;
67 CriticalSectionWrapper& _critSectCb;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
henrika0fd68012016-07-04 13:01:19 +020069 AudioTransport* _ptrCbAudioTransport;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
henrika0fd68012016-07-04 13:01:19 +020071 uint32_t _recSampleRate;
72 uint32_t _playSampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +000073
henrika0fd68012016-07-04 13:01:19 +020074 size_t _recChannels;
75 size_t _playChannels;
niklase@google.com470e71d2011-07-07 08:21:25 +000076
henrika0fd68012016-07-04 13:01:19 +020077 // selected recording channel (left/right/both)
78 AudioDeviceModule::ChannelType _recChannel;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
henrika0fd68012016-07-04 13:01:19 +020080 // 2 or 4 depending on mono or stereo
81 size_t _recBytesPerSample;
82 size_t _playBytesPerSample;
niklase@google.com470e71d2011-07-07 08:21:25 +000083
henrika0fd68012016-07-04 13:01:19 +020084 // 10ms in stereo @ 96kHz
85 int8_t _recBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000086
henrika0fd68012016-07-04 13:01:19 +020087 // one sample <=> 2 or 4 bytes
88 size_t _recSamples;
89 size_t _recSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000090
henrika0fd68012016-07-04 13:01:19 +020091 // 10ms in stereo @ 96kHz
92 int8_t _playBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000093
henrika0fd68012016-07-04 13:01:19 +020094 // one sample <=> 2 or 4 bytes
95 size_t _playSamples;
96 size_t _playSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000097
henrika0fd68012016-07-04 13:01:19 +020098 FileWrapper& _recFile;
99 FileWrapper& _playFile;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
henrika0fd68012016-07-04 13:01:19 +0200101 uint32_t _currentMicLevel;
102 uint32_t _newMicLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
henrika0fd68012016-07-04 13:01:19 +0200104 bool _typingStatus;
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +0000105
henrika0fd68012016-07-04 13:01:19 +0200106 int _playDelayMS;
107 int _recDelayMS;
108 int _clockDrift;
109 int high_delay_counter_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110};
111
112} // namespace webrtc
113
114#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H