OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H | 11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H |
12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H | 12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H |
13 | 13 |
14 #include "webrtc/typedefs.h" | 14 #include "webrtc/typedefs.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 static const int kAdmMaxDeviceNameSize = 128; | 18 static const int kAdmMaxDeviceNameSize = 128; |
19 static const int kAdmMaxFileNameSize = 512; | 19 static const int kAdmMaxFileNameSize = 512; |
20 static const int kAdmMaxGuidSize = 128; | 20 static const int kAdmMaxGuidSize = 128; |
21 | 21 |
22 static const int kAdmMinPlayoutBufferSizeMs = 10; | 22 static const int kAdmMinPlayoutBufferSizeMs = 10; |
23 static const int kAdmMaxPlayoutBufferSizeMs = 250; | 23 static const int kAdmMaxPlayoutBufferSizeMs = 250; |
24 | 24 |
25 // ---------------------------------------------------------------------------- | 25 // ---------------------------------------------------------------------------- |
26 // AudioDeviceObserver | 26 // AudioDeviceObserver |
27 // ---------------------------------------------------------------------------- | 27 // ---------------------------------------------------------------------------- |
28 | 28 |
29 class AudioDeviceObserver | 29 class AudioDeviceObserver { |
30 { | 30 public: |
31 public: | 31 enum ErrorCode { kRecordingError = 0, kPlayoutError = 1 }; |
32 enum ErrorCode | 32 enum WarningCode { kRecordingWarning = 0, kPlayoutWarning = 1 }; |
33 { | |
34 kRecordingError = 0, | |
35 kPlayoutError = 1 | |
36 }; | |
37 enum WarningCode | |
38 { | |
39 kRecordingWarning = 0, | |
40 kPlayoutWarning = 1 | |
41 }; | |
42 | 33 |
43 virtual void OnErrorIsReported(const ErrorCode error) = 0; | 34 virtual void OnErrorIsReported(const ErrorCode error) = 0; |
44 virtual void OnWarningIsReported(const WarningCode warning) = 0; | 35 virtual void OnWarningIsReported(const WarningCode warning) = 0; |
45 | 36 |
46 protected: | 37 protected: |
47 virtual ~AudioDeviceObserver() {} | 38 virtual ~AudioDeviceObserver() {} |
48 }; | 39 }; |
49 | 40 |
50 // ---------------------------------------------------------------------------- | 41 // ---------------------------------------------------------------------------- |
51 // AudioTransport | 42 // AudioTransport |
52 // ---------------------------------------------------------------------------- | 43 // ---------------------------------------------------------------------------- |
53 | 44 |
54 class AudioTransport | 45 class AudioTransport { |
55 { | 46 public: |
56 public: | 47 virtual int32_t RecordedDataIsAvailable(const void* audioSamples, |
57 virtual int32_t RecordedDataIsAvailable(const void* audioSamples, | 48 const uint32_t nSamples, |
58 const uint32_t nSamples, | 49 const uint8_t nBytesPerSample, |
59 const uint8_t nBytesPerSample, | 50 const uint8_t nChannels, |
60 const uint8_t nChannels, | 51 const uint32_t samplesPerSec, |
61 const uint32_t samplesPerSec, | 52 const uint32_t totalDelayMS, |
62 const uint32_t totalDelayMS, | 53 const int32_t clockDrift, |
63 const int32_t clockDrift, | 54 const uint32_t currentMicLevel, |
64 const uint32_t currentMicLevel, | 55 const bool keyPressed, |
65 const bool keyPressed, | 56 uint32_t& newMicLevel) = 0; |
66 uint32_t& newMicLevel) = 0; | |
67 | 57 |
68 virtual int32_t NeedMorePlayData(const uint32_t nSamples, | 58 virtual int32_t NeedMorePlayData(const uint32_t nSamples, |
69 const uint8_t nBytesPerSample, | 59 const uint8_t nBytesPerSample, |
70 const uint8_t nChannels, | 60 const uint8_t nChannels, |
71 const uint32_t samplesPerSec, | 61 const uint32_t samplesPerSec, |
72 void* audioSamples, | 62 void* audioSamples, |
73 uint32_t& nSamplesOut, | 63 uint32_t& nSamplesOut, |
74 int64_t* elapsed_time_ms, | 64 int64_t* elapsed_time_ms, |
75 int64_t* ntp_time_ms) = 0; | 65 int64_t* ntp_time_ms) = 0; |
76 | 66 |
77 // Method to pass captured data directly and unmixed to network channels. | 67 // Method to pass captured data directly and unmixed to network channels. |
78 // |channel_ids| contains a list of VoE channels which are the | 68 // |channel_ids| contains a list of VoE channels which are the |
79 // sinks to the capture data. |audio_delay_milliseconds| is the sum of | 69 // sinks to the capture data. |audio_delay_milliseconds| is the sum of |
80 // recording delay and playout delay of the hardware. |current_volume| is | 70 // recording delay and playout delay of the hardware. |current_volume| is |
81 // in the range of [0, 255], representing the current microphone analog | 71 // in the range of [0, 255], representing the current microphone analog |
82 // volume. |key_pressed| is used by the typing detection. | 72 // volume. |key_pressed| is used by the typing detection. |
83 // |need_audio_processing| specify if the data needs to be processed by APM. | 73 // |need_audio_processing| specify if the data needs to be processed by APM. |
84 // Currently WebRtc supports only one APM, and Chrome will make sure only | 74 // Currently WebRtc supports only one APM, and Chrome will make sure only |
85 // one stream goes through APM. When |need_audio_processing| is false, the | 75 // one stream goes through APM. When |need_audio_processing| is false, the |
86 // values of |audio_delay_milliseconds|, |current_volume| and |key_pressed| | 76 // values of |audio_delay_milliseconds|, |current_volume| and |key_pressed| |
87 // will be ignored. | 77 // will be ignored. |
88 // The return value is the new microphone volume, in the range of |0, 255]. | 78 // The return value is the new microphone volume, in the range of |0, 255]. |
89 // When the volume does not need to be updated, it returns 0. | 79 // When the volume does not need to be updated, it returns 0. |
90 // TODO(xians): Remove this interface after Chrome and Libjingle switches | 80 // TODO(xians): Remove this interface after Chrome and Libjingle switches |
91 // to OnData(). | 81 // to OnData(). |
92 virtual int OnDataAvailable(const int voe_channels[], | 82 virtual int OnDataAvailable(const int voe_channels[], |
93 int number_of_voe_channels, | 83 int number_of_voe_channels, |
94 const int16_t* audio_data, | 84 const int16_t* audio_data, |
95 int sample_rate, | 85 int sample_rate, |
96 int number_of_channels, | 86 int number_of_channels, |
97 int number_of_frames, | 87 int number_of_frames, |
98 int audio_delay_milliseconds, | 88 int audio_delay_milliseconds, |
99 int current_volume, | 89 int current_volume, |
100 bool key_pressed, | 90 bool key_pressed, |
101 bool need_audio_processing) { return 0; } | 91 bool need_audio_processing) { |
| 92 return 0; |
| 93 } |
102 | 94 |
103 // Method to pass the captured audio data to the specific VoE channel. | 95 // Method to pass the captured audio data to the specific VoE channel. |
104 // |voe_channel| is the id of the VoE channel which is the sink to the | 96 // |voe_channel| is the id of the VoE channel which is the sink to the |
105 // capture data. | 97 // capture data. |
106 // TODO(xians): Remove this interface after Libjingle switches to | 98 // TODO(xians): Remove this interface after Libjingle switches to |
107 // PushCaptureData(). | 99 // PushCaptureData(). |
108 virtual void OnData(int voe_channel, const void* audio_data, | 100 virtual void OnData(int voe_channel, |
109 int bits_per_sample, int sample_rate, | 101 const void* audio_data, |
110 int number_of_channels, | 102 int bits_per_sample, |
111 int number_of_frames) {} | 103 int sample_rate, |
| 104 int number_of_channels, |
| 105 int number_of_frames) {} |
112 | 106 |
113 // Method to push the captured audio data to the specific VoE channel. | 107 // Method to push the captured audio data to the specific VoE channel. |
114 // The data will not undergo audio processing. | 108 // The data will not undergo audio processing. |
115 // |voe_channel| is the id of the VoE channel which is the sink to the | 109 // |voe_channel| is the id of the VoE channel which is the sink to the |
116 // capture data. | 110 // capture data. |
117 // TODO(xians): Make the interface pure virtual after Libjingle | 111 // TODO(xians): Make the interface pure virtual after Libjingle |
118 // has its implementation. | 112 // has its implementation. |
119 virtual void PushCaptureData(int voe_channel, const void* audio_data, | 113 virtual void PushCaptureData(int voe_channel, |
120 int bits_per_sample, int sample_rate, | 114 const void* audio_data, |
121 int number_of_channels, | 115 int bits_per_sample, |
122 int number_of_frames) {} | 116 int sample_rate, |
| 117 int number_of_channels, |
| 118 int number_of_frames) {} |
123 | 119 |
124 // Method to pull mixed render audio data from all active VoE channels. | 120 // Method to pull mixed render audio data from all active VoE channels. |
125 // The data will not be passed as reference for audio processing internally. | 121 // The data will not be passed as reference for audio processing internally. |
126 // TODO(xians): Support getting the unmixed render data from specific VoE | 122 // TODO(xians): Support getting the unmixed render data from specific VoE |
127 // channel. | 123 // channel. |
128 virtual void PullRenderData(int bits_per_sample, int sample_rate, | 124 virtual void PullRenderData(int bits_per_sample, |
129 int number_of_channels, int number_of_frames, | 125 int sample_rate, |
130 void* audio_data, | 126 int number_of_channels, |
131 int64_t* elapsed_time_ms, | 127 int number_of_frames, |
132 int64_t* ntp_time_ms) {} | 128 void* audio_data, |
| 129 int64_t* elapsed_time_ms, |
| 130 int64_t* ntp_time_ms) {} |
133 | 131 |
134 protected: | 132 protected: |
135 virtual ~AudioTransport() {} | 133 virtual ~AudioTransport() {} |
| 134 }; |
| 135 |
| 136 // Helper class for storage of fundamental audio parameters such as sample rate, |
| 137 // number of channels, native buffer size etc. |
| 138 // Note that one audio frame can contain more than one channel sample and each |
| 139 // sample is assumed to be a 16-bit PCM sample. Hence, one audio frame in |
| 140 // stereo contains 2 * (16/8) = 4 bytes of data. |
| 141 class AudioParameters { |
| 142 public: |
| 143 // This implementation does only support 16-bit PCM samples. |
| 144 enum { kBitsPerSample = 16 }; |
| 145 AudioParameters() |
| 146 : sample_rate_(0), |
| 147 channels_(0), |
| 148 frames_per_buffer_(0), |
| 149 frames_per_10ms_buffer_(0) {} |
| 150 AudioParameters(int sample_rate, int channels, int frames_per_buffer) |
| 151 : sample_rate_(sample_rate), |
| 152 channels_(channels), |
| 153 frames_per_buffer_(frames_per_buffer), |
| 154 frames_per_10ms_buffer_(sample_rate / 100) {} |
| 155 void reset(int sample_rate, int channels, int frames_per_buffer) { |
| 156 sample_rate_ = sample_rate; |
| 157 channels_ = channels; |
| 158 frames_per_buffer_ = frames_per_buffer; |
| 159 frames_per_10ms_buffer_ = (sample_rate / 100); |
| 160 } |
| 161 int bits_per_sample() const { return kBitsPerSample; } |
| 162 int sample_rate() const { return sample_rate_; } |
| 163 int channels() const { return channels_; } |
| 164 int frames_per_buffer() const { return frames_per_buffer_; } |
| 165 int frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; } |
| 166 bool is_valid() const { |
| 167 return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0)); |
| 168 } |
| 169 int GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; } |
| 170 int GetBytesPerBuffer() const { |
| 171 return frames_per_buffer_ * GetBytesPerFrame(); |
| 172 } |
| 173 int GetBytesPer10msBuffer() const { |
| 174 return frames_per_10ms_buffer_ * GetBytesPerFrame(); |
| 175 } |
| 176 float GetBufferSizeInMilliseconds() const { |
| 177 if (sample_rate_ == 0) |
| 178 return 0.0f; |
| 179 return frames_per_buffer_ / (sample_rate_ / 1000.0f); |
| 180 } |
| 181 |
| 182 private: |
| 183 int sample_rate_; |
| 184 int channels_; |
| 185 int frames_per_buffer_; |
| 186 int frames_per_10ms_buffer_; |
136 }; | 187 }; |
137 | 188 |
138 } // namespace webrtc | 189 } // namespace webrtc |
139 | 190 |
140 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H | 191 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H |
OLD | NEW |