blob: 6a02c2be2439dc1230346de9883f6aa8b04df342 [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
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +000070 int32_t SetTypingStatus(bool typingStatus);
71
niklase@google.com470e71d2011-07-07 08:21:25 +000072 AudioDeviceBuffer();
73 ~AudioDeviceBuffer();
74
75private:
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