• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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 "webrtc/modules/audio_device/include/audio_device.h"
15 #include "webrtc/system_wrappers/interface/file_wrapper.h"
16 #include "webrtc/typedefs.h"
17 
18 namespace webrtc {
19 class CriticalSectionWrapper;
20 
21 const uint32_t kPulsePeriodMs = 1000;
22 const uint32_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz
23 
24 class AudioDeviceObserver;
25 class MediaFile;
26 
27 class AudioDeviceBuffer
28 {
29 public:
30     AudioDeviceBuffer();
31     virtual ~AudioDeviceBuffer();
32 
33     void SetId(uint32_t id);
34     int32_t RegisterAudioCallback(AudioTransport* audioCallback);
35 
36     int32_t InitPlayout();
37     int32_t InitRecording();
38 
39     virtual int32_t SetRecordingSampleRate(uint32_t fsHz);
40     virtual int32_t SetPlayoutSampleRate(uint32_t fsHz);
41     int32_t RecordingSampleRate() const;
42     int32_t PlayoutSampleRate() const;
43 
44     virtual int32_t SetRecordingChannels(uint8_t channels);
45     virtual int32_t SetPlayoutChannels(uint8_t channels);
46     uint8_t RecordingChannels() const;
47     uint8_t PlayoutChannels() const;
48     int32_t SetRecordingChannel(
49         const AudioDeviceModule::ChannelType channel);
50     int32_t RecordingChannel(
51         AudioDeviceModule::ChannelType& channel) const;
52 
53     virtual int32_t SetRecordedBuffer(const void* audioBuffer,
54                                       uint32_t nSamples);
55     int32_t SetCurrentMicLevel(uint32_t level);
56     virtual void SetVQEData(int playDelayMS,
57                             int recDelayMS,
58                             int clockDrift);
59     virtual int32_t DeliverRecordedData();
60     uint32_t NewMicLevel() const;
61 
62     virtual int32_t RequestPlayoutData(uint32_t nSamples);
63     virtual int32_t GetPlayoutData(void* audioBuffer);
64 
65     int32_t StartInputFileRecording(
66         const char fileName[kAdmMaxFileNameSize]);
67     int32_t StopInputFileRecording();
68     int32_t StartOutputFileRecording(
69         const char fileName[kAdmMaxFileNameSize]);
70     int32_t StopOutputFileRecording();
71 
72     int32_t SetTypingStatus(bool typingStatus);
73 
74 private:
75     int32_t                   _id;
76     CriticalSectionWrapper&         _critSect;
77     CriticalSectionWrapper&         _critSectCb;
78 
79     AudioTransport*                 _ptrCbAudioTransport;
80 
81     uint32_t                  _recSampleRate;
82     uint32_t                  _playSampleRate;
83 
84     uint8_t                   _recChannels;
85     uint8_t                   _playChannels;
86 
87     // selected recording channel (left/right/both)
88     AudioDeviceModule::ChannelType _recChannel;
89 
90     // 2 or 4 depending on mono or stereo
91     uint8_t                   _recBytesPerSample;
92     uint8_t                   _playBytesPerSample;
93 
94     // 10ms in stereo @ 96kHz
95     int8_t                          _recBuffer[kMaxBufferSizeBytes];
96 
97     // one sample <=> 2 or 4 bytes
98     uint32_t                  _recSamples;
99     uint32_t                  _recSize;           // in bytes
100 
101     // 10ms in stereo @ 96kHz
102     int8_t                          _playBuffer[kMaxBufferSizeBytes];
103 
104     // one sample <=> 2 or 4 bytes
105     uint32_t                  _playSamples;
106     uint32_t                  _playSize;          // in bytes
107 
108     FileWrapper&                    _recFile;
109     FileWrapper&                    _playFile;
110 
111     uint32_t                  _currentMicLevel;
112     uint32_t                  _newMicLevel;
113 
114     bool                      _typingStatus;
115 
116     int _playDelayMS;
117     int _recDelayMS;
118     int _clockDrift;
119     int high_delay_counter_;
120 };
121 
122 }  // namespace webrtc
123 
124 #endif  // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H
125