blob: b7c4fc85a9a538147e5569b8f8c24f00d51c948f [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
23const WebRtc_UWord32 kPulsePeriodMs = 1000;
braveyao@webrtc.org0a185222011-11-25 02:45:39 +000024const WebRtc_UWord32 kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26class AudioDeviceObserver;
27class MediaFile;
28
29class AudioDeviceBuffer
30{
31public:
32 void SetId(WebRtc_UWord32 id);
33 WebRtc_Word32 RegisterAudioCallback(AudioTransport* audioCallback);
34
35 WebRtc_Word32 InitPlayout();
36 WebRtc_Word32 InitRecording();
37
38 WebRtc_Word32 SetRecordingSampleRate(WebRtc_UWord32 fsHz);
39 WebRtc_Word32 SetPlayoutSampleRate(WebRtc_UWord32 fsHz);
40 WebRtc_Word32 RecordingSampleRate() const;
41 WebRtc_Word32 PlayoutSampleRate() const;
42
43 WebRtc_Word32 SetRecordingChannels(WebRtc_UWord8 channels);
44 WebRtc_Word32 SetPlayoutChannels(WebRtc_UWord8 channels);
45 WebRtc_UWord8 RecordingChannels() const;
46 WebRtc_UWord8 PlayoutChannels() const;
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000047 WebRtc_Word32 SetRecordingChannel(
48 const AudioDeviceModule::ChannelType channel);
49 WebRtc_Word32 RecordingChannel(
50 AudioDeviceModule::ChannelType& channel) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
henrika@webrtc.org907bc552012-03-09 08:59:19 +000052 WebRtc_Word32 SetRecordedBuffer(const void* audioBuffer,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000053 WebRtc_UWord32 nSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000054 WebRtc_Word32 SetCurrentMicLevel(WebRtc_UWord32 level);
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000055 WebRtc_Word32 SetVQEData(WebRtc_UWord32 playDelayMS,
56 WebRtc_UWord32 recDelayMS,
57 WebRtc_Word32 clockDrift);
niklase@google.com470e71d2011-07-07 08:21:25 +000058 WebRtc_Word32 DeliverRecordedData();
59 WebRtc_UWord32 NewMicLevel() const;
60
61 WebRtc_Word32 RequestPlayoutData(WebRtc_UWord32 nSamples);
henrika@webrtc.org907bc552012-03-09 08:59:19 +000062 WebRtc_Word32 GetPlayoutData(void* audioBuffer);
niklase@google.com470e71d2011-07-07 08:21:25 +000063
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000064 WebRtc_Word32 StartInputFileRecording(
65 const char fileName[kAdmMaxFileNameSize]);
niklase@google.com470e71d2011-07-07 08:21:25 +000066 WebRtc_Word32 StopInputFileRecording();
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000067 WebRtc_Word32 StartOutputFileRecording(
68 const char fileName[kAdmMaxFileNameSize]);
niklase@google.com470e71d2011-07-07 08:21:25 +000069 WebRtc_Word32 StopOutputFileRecording();
70
71 AudioDeviceBuffer();
72 ~AudioDeviceBuffer();
73
74private:
75 void _EmptyList();
76
77private:
78 WebRtc_Word32 _id;
79 CriticalSectionWrapper& _critSect;
80 CriticalSectionWrapper& _critSectCb;
81
82 AudioTransport* _ptrCbAudioTransport;
83
84 WebRtc_UWord32 _recSampleRate;
85 WebRtc_UWord32 _playSampleRate;
86
87 WebRtc_UWord8 _recChannels;
88 WebRtc_UWord8 _playChannels;
89
90 // selected recording channel (left/right/both)
91 AudioDeviceModule::ChannelType _recChannel;
92
93 // 2 or 4 depending on mono or stereo
94 WebRtc_UWord8 _recBytesPerSample;
95 WebRtc_UWord8 _playBytesPerSample;
96
braveyao@webrtc.org0a185222011-11-25 02:45:39 +000097 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +000098 int8_t _recBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000099
100 // one sample <=> 2 or 4 bytes
101 WebRtc_UWord32 _recSamples;
102 WebRtc_UWord32 _recSize; // in bytes
103
braveyao@webrtc.org0a185222011-11-25 02:45:39 +0000104 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +0000105 int8_t _playBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
107 // one sample <=> 2 or 4 bytes
108 WebRtc_UWord32 _playSamples;
109 WebRtc_UWord32 _playSize; // in bytes
110
111 FileWrapper& _recFile;
112 FileWrapper& _playFile;
113
114 WebRtc_UWord32 _currentMicLevel;
115 WebRtc_UWord32 _newMicLevel;
116
117 WebRtc_UWord32 _playDelayMS;
118 WebRtc_UWord32 _recDelayMS;
119
120 WebRtc_Word32 _clockDrift;
121
122 bool _measureDelay;
123 ListWrapper _pulseList;
124 WebRtc_UWord32 _lastPulseTime;
125};
126
127} // namespace webrtc
128
129#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H