blob: 25bb9bd9f22dcdd7f0b8acf0809d4be417526aed [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
14#include "typedefs.h"
andrew@webrtc.org236d5d32012-09-21 20:46:40 +000015#include "common_audio/resampler/include/resampler.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include "file_wrapper.h"
17#include "audio_device.h"
18#include "list_wrapper.h"
19
20namespace webrtc {
21class CriticalSectionWrapper;
22
pbos@webrtc.org25509882013-04-09 10:30:35 +000023const uint32_t kPulsePeriodMs = 1000;
24const uint32_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26class AudioDeviceObserver;
27class MediaFile;
28
29class AudioDeviceBuffer
30{
31public:
pbos@webrtc.org25509882013-04-09 10:30:35 +000032 void SetId(uint32_t id);
33 int32_t RegisterAudioCallback(AudioTransport* audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
pbos@webrtc.org25509882013-04-09 10:30:35 +000035 int32_t InitPlayout();
36 int32_t InitRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000037
pbos@webrtc.org25509882013-04-09 10:30:35 +000038 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.com470e71d2011-07-07 08:21:25 +000042
pbos@webrtc.org25509882013-04-09 10:30:35 +000043 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.org28f39132012-03-01 18:01:48 +000048 const AudioDeviceModule::ChannelType channel);
pbos@webrtc.org25509882013-04-09 10:30:35 +000049 int32_t RecordingChannel(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000050 AudioDeviceModule::ChannelType& channel) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
pbos@webrtc.org25509882013-04-09 10:30:35 +000052 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.com470e71d2011-07-07 08:21:25 +000059
pbos@webrtc.org25509882013-04-09 10:30:35 +000060 int32_t RequestPlayoutData(uint32_t nSamples);
61 int32_t GetPlayoutData(void* audioBuffer);
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pbos@webrtc.org25509882013-04-09 10:30:35 +000063 int32_t StartInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000064 const char fileName[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +000065 int32_t StopInputFileRecording();
66 int32_t StartOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000067 const char fileName[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +000068 int32_t StopOutputFileRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000069
70 AudioDeviceBuffer();
71 ~AudioDeviceBuffer();
72
73private:
74 void _EmptyList();
75
76private:
pbos@webrtc.org25509882013-04-09 10:30:35 +000077 int32_t _id;
niklase@google.com470e71d2011-07-07 08:21:25 +000078 CriticalSectionWrapper& _critSect;
79 CriticalSectionWrapper& _critSectCb;
80
81 AudioTransport* _ptrCbAudioTransport;
82
pbos@webrtc.org25509882013-04-09 10:30:35 +000083 uint32_t _recSampleRate;
84 uint32_t _playSampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +000085
pbos@webrtc.org25509882013-04-09 10:30:35 +000086 uint8_t _recChannels;
87 uint8_t _playChannels;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
89 // selected recording channel (left/right/both)
90 AudioDeviceModule::ChannelType _recChannel;
91
92 // 2 or 4 depending on mono or stereo
pbos@webrtc.org25509882013-04-09 10:30:35 +000093 uint8_t _recBytesPerSample;
94 uint8_t _playBytesPerSample;
niklase@google.com470e71d2011-07-07 08:21:25 +000095
braveyao@webrtc.org0a185222011-11-25 02:45:39 +000096 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +000097 int8_t _recBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000098
99 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +0000100 uint32_t _recSamples;
101 uint32_t _recSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
braveyao@webrtc.org0a185222011-11-25 02:45:39 +0000103 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +0000104 int8_t _playBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
106 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +0000107 uint32_t _playSamples;
108 uint32_t _playSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
110 FileWrapper& _recFile;
111 FileWrapper& _playFile;
112
pbos@webrtc.org25509882013-04-09 10:30:35 +0000113 uint32_t _currentMicLevel;
114 uint32_t _newMicLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
pbos@webrtc.org25509882013-04-09 10:30:35 +0000116 uint32_t _playDelayMS;
117 uint32_t _recDelayMS;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
pbos@webrtc.org25509882013-04-09 10:30:35 +0000119 int32_t _clockDrift;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
121 bool _measureDelay;
122 ListWrapper _pulseList;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000123 uint32_t _lastPulseTime;
niklase@google.com470e71d2011-07-07 08:21:25 +0000124};
125
126} // namespace webrtc
127
128#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H