blob: 84df5594b131627696a0967618ccd270df8ed1c0 [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/modules/audio_device/include/audio_device.h"
15#include "webrtc/system_wrappers/interface/file_wrapper.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000016#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
19class CriticalSectionWrapper;
20
pbos@webrtc.org25509882013-04-09 10:30:35 +000021const uint32_t kPulsePeriodMs = 1000;
22const uint32_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24class AudioDeviceObserver;
25class MediaFile;
26
27class AudioDeviceBuffer
28{
29public:
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000030 AudioDeviceBuffer();
31 virtual ~AudioDeviceBuffer();
32
pbos@webrtc.org25509882013-04-09 10:30:35 +000033 void SetId(uint32_t id);
34 int32_t RegisterAudioCallback(AudioTransport* audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
pbos@webrtc.org25509882013-04-09 10:30:35 +000036 int32_t InitPlayout();
37 int32_t InitRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000038
henrike@webrtc.org1fdc51a2013-10-02 14:58:19 +000039 virtual int32_t SetRecordingSampleRate(uint32_t fsHz);
40 virtual int32_t SetPlayoutSampleRate(uint32_t fsHz);
pbos@webrtc.org25509882013-04-09 10:30:35 +000041 int32_t RecordingSampleRate() const;
42 int32_t PlayoutSampleRate() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000043
henrike@webrtc.org1fdc51a2013-10-02 14:58:19 +000044 virtual int32_t SetRecordingChannels(uint8_t channels);
45 virtual int32_t SetPlayoutChannels(uint8_t channels);
pbos@webrtc.org25509882013-04-09 10:30:35 +000046 uint8_t RecordingChannels() const;
47 uint8_t PlayoutChannels() const;
48 int32_t SetRecordingChannel(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000049 const AudioDeviceModule::ChannelType channel);
pbos@webrtc.org25509882013-04-09 10:30:35 +000050 int32_t RecordingChannel(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000051 AudioDeviceModule::ChannelType& channel) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
henrike@webrtc.org1fdc51a2013-10-02 14:58:19 +000053 virtual int32_t SetRecordedBuffer(const void* audioBuffer,
54 uint32_t nSamples);
pbos@webrtc.org25509882013-04-09 10:30:35 +000055 int32_t SetCurrentMicLevel(uint32_t level);
henrike@webrtc.org1fdc51a2013-10-02 14:58:19 +000056 virtual void SetVQEData(int playDelayMS,
57 int recDelayMS,
58 int clockDrift);
59 virtual int32_t DeliverRecordedData();
pbos@webrtc.org25509882013-04-09 10:30:35 +000060 uint32_t NewMicLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000062 virtual int32_t RequestPlayoutData(uint32_t nSamples);
63 virtual int32_t GetPlayoutData(void* audioBuffer);
niklase@google.com470e71d2011-07-07 08:21:25 +000064
pbos@webrtc.org25509882013-04-09 10:30:35 +000065 int32_t StartInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000066 const char fileName[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +000067 int32_t StopInputFileRecording();
68 int32_t StartOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000069 const char fileName[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +000070 int32_t StopOutputFileRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000071
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +000072 int32_t SetTypingStatus(bool typingStatus);
73
niklase@google.com470e71d2011-07-07 08:21:25 +000074private:
pbos@webrtc.org25509882013-04-09 10:30:35 +000075 int32_t _id;
niklase@google.com470e71d2011-07-07 08:21:25 +000076 CriticalSectionWrapper& _critSect;
77 CriticalSectionWrapper& _critSectCb;
78
79 AudioTransport* _ptrCbAudioTransport;
80
pbos@webrtc.org25509882013-04-09 10:30:35 +000081 uint32_t _recSampleRate;
82 uint32_t _playSampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +000083
pbos@webrtc.org25509882013-04-09 10:30:35 +000084 uint8_t _recChannels;
85 uint8_t _playChannels;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
87 // selected recording channel (left/right/both)
88 AudioDeviceModule::ChannelType _recChannel;
89
90 // 2 or 4 depending on mono or stereo
pbos@webrtc.org25509882013-04-09 10:30:35 +000091 uint8_t _recBytesPerSample;
92 uint8_t _playBytesPerSample;
niklase@google.com470e71d2011-07-07 08:21:25 +000093
braveyao@webrtc.org0a185222011-11-25 02:45:39 +000094 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +000095 int8_t _recBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +000096
97 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +000098 uint32_t _recSamples;
99 uint32_t _recSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
braveyao@webrtc.org0a185222011-11-25 02:45:39 +0000101 // 10ms in stereo @ 96kHz
henrika@webrtc.org907bc552012-03-09 08:59:19 +0000102 int8_t _playBuffer[kMaxBufferSizeBytes];
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
104 // one sample <=> 2 or 4 bytes
pbos@webrtc.org25509882013-04-09 10:30:35 +0000105 uint32_t _playSamples;
106 uint32_t _playSize; // in bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
108 FileWrapper& _recFile;
109 FileWrapper& _playFile;
110
pbos@webrtc.org25509882013-04-09 10:30:35 +0000111 uint32_t _currentMicLevel;
112 uint32_t _newMicLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
niklas.enbom@webrtc.org3be565b2013-05-07 21:04:24 +0000114 bool _typingStatus;
115
andrew@webrtc.org5eb997a2013-09-12 01:01:42 +0000116 int _playDelayMS;
117 int _recDelayMS;
118 int _clockDrift;
andrew@webrtc.org8f940132013-09-11 22:35:00 +0000119 int high_delay_counter_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120};
121
122} // namespace webrtc
123
124#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H