blob: 67962d69a56242ac3cad644ce0e1a0b43a825eb3 [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:
pbos@webrtc.org25509882013-04-09 10:30:35 +000074 int32_t _id;
niklase@google.com470e71d2011-07-07 08:21:25 +000075 CriticalSectionWrapper& _critSect;
76 CriticalSectionWrapper& _critSectCb;
77
78 AudioTransport* _ptrCbAudioTransport;
79
pbos@webrtc.org25509882013-04-09 10:30:35 +000080 uint32_t _recSampleRate;
81 uint32_t _playSampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +000082
pbos@webrtc.org25509882013-04-09 10:30:35 +000083 uint8_t _recChannels;
84 uint8_t _playChannels;
niklase@google.com470e71d2011-07-07 08:21:25 +000085
86 // selected recording channel (left/right/both)
87 AudioDeviceModule::ChannelType _recChannel;
88
89 // 2 or 4 depending on mono or stereo
pbos@webrtc.org25509882013-04-09 10:30:35 +000090 uint8_t _recBytesPerSample;
91 uint8_t _playBytesPerSample;
niklase@google.com470e71d2011-07-07 08:21:25 +000092
braveyao@webrtc.org0a185222011-11-25 02:45:39 +000093 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +000094 int8_t _recBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000095
96 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +000097 uint32_t _recSamples;
98 uint32_t _recSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000099
braveyao@webrtc.org0a185222011-11-25 02:45:39 +0000100 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +0000101 int8_t _playBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
103 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +0000104 uint32_t _playSamples;
105 uint32_t _playSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
107 FileWrapper& _recFile;
108 FileWrapper& _playFile;
109
pbos@webrtc.org25509882013-04-09 10:30:35 +0000110 uint32_t _currentMicLevel;
111 uint32_t _newMicLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
pbos@webrtc.org25509882013-04-09 10:30:35 +0000113 uint32_t _playDelayMS;
114 uint32_t _recDelayMS;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
pbos@webrtc.org25509882013-04-09 10:30:35 +0000116 int32_t _clockDrift;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117};
118
119} // namespace webrtc
120
121#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H