blob: 77aaac7f36dd8d8e953a6c7acaaed7ba49d681f6 [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/common_audio/resampler/include/resampler.h"
15#include "webrtc/modules/audio_device/include/audio_device.h"
16#include "webrtc/system_wrappers/interface/file_wrapper.h"
17#include "webrtc/system_wrappers/interface/list_wrapper.h"
18#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
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:
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000032 AudioDeviceBuffer();
33 virtual ~AudioDeviceBuffer();
34
pbos@webrtc.org25509882013-04-09 10:30:35 +000035 void SetId(uint32_t id);
36 int32_t RegisterAudioCallback(AudioTransport* audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
pbos@webrtc.org25509882013-04-09 10:30:35 +000038 int32_t InitPlayout();
39 int32_t InitRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000040
pbos@webrtc.org25509882013-04-09 10:30:35 +000041 int32_t SetRecordingSampleRate(uint32_t fsHz);
42 int32_t SetPlayoutSampleRate(uint32_t fsHz);
43 int32_t RecordingSampleRate() const;
44 int32_t PlayoutSampleRate() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
pbos@webrtc.org25509882013-04-09 10:30:35 +000046 int32_t SetRecordingChannels(uint8_t channels);
47 int32_t SetPlayoutChannels(uint8_t channels);
48 uint8_t RecordingChannels() const;
49 uint8_t PlayoutChannels() const;
50 int32_t SetRecordingChannel(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000051 const AudioDeviceModule::ChannelType channel);
pbos@webrtc.org25509882013-04-09 10:30:35 +000052 int32_t RecordingChannel(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000053 AudioDeviceModule::ChannelType& channel) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
pbos@webrtc.org25509882013-04-09 10:30:35 +000055 int32_t SetRecordedBuffer(const void* audioBuffer, uint32_t nSamples);
56 int32_t SetCurrentMicLevel(uint32_t level);
57 int32_t SetVQEData(uint32_t playDelayMS,
58 uint32_t recDelayMS,
59 int32_t clockDrift);
60 int32_t DeliverRecordedData();
61 uint32_t NewMicLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000063 virtual int32_t RequestPlayoutData(uint32_t nSamples);
64 virtual int32_t GetPlayoutData(void* audioBuffer);
niklase@google.com470e71d2011-07-07 08:21:25 +000065
pbos@webrtc.org25509882013-04-09 10:30:35 +000066 int32_t StartInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000067 const char fileName[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +000068 int32_t StopInputFileRecording();
69 int32_t StartOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000070 const char fileName[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +000071 int32_t StopOutputFileRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000072
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +000073 int32_t SetTypingStatus(bool typingStatus);
74
niklase@google.com470e71d2011-07-07 08:21:25 +000075private:
pbos@webrtc.org25509882013-04-09 10:30:35 +000076 int32_t _id;
niklase@google.com470e71d2011-07-07 08:21:25 +000077 CriticalSectionWrapper& _critSect;
78 CriticalSectionWrapper& _critSectCb;
79
80 AudioTransport* _ptrCbAudioTransport;
81
pbos@webrtc.org25509882013-04-09 10:30:35 +000082 uint32_t _recSampleRate;
83 uint32_t _playSampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
pbos@webrtc.org25509882013-04-09 10:30:35 +000085 uint8_t _recChannels;
86 uint8_t _playChannels;
niklase@google.com470e71d2011-07-07 08:21:25 +000087
88 // selected recording channel (left/right/both)
89 AudioDeviceModule::ChannelType _recChannel;
90
91 // 2 or 4 depending on mono or stereo
pbos@webrtc.org25509882013-04-09 10:30:35 +000092 uint8_t _recBytesPerSample;
93 uint8_t _playBytesPerSample;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
braveyao@webrtc.org0a185222011-11-25 02:45:39 +000095 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +000096 int8_t _recBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000097
98 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +000099 uint32_t _recSamples;
100 uint32_t _recSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
braveyao@webrtc.org0a185222011-11-25 02:45:39 +0000102 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +0000103 int8_t _playBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
105 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +0000106 uint32_t _playSamples;
107 uint32_t _playSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
109 FileWrapper& _recFile;
110 FileWrapper& _playFile;
111
pbos@webrtc.org25509882013-04-09 10:30:35 +0000112 uint32_t _currentMicLevel;
113 uint32_t _newMicLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +0000115 bool _typingStatus;
116
pbos@webrtc.org25509882013-04-09 10:30:35 +0000117 uint32_t _playDelayMS;
118 uint32_t _recDelayMS;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
pbos@webrtc.org25509882013-04-09 10:30:35 +0000120 int32_t _clockDrift;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121};
122
123} // namespace webrtc
124
125#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H