OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 // GetPlayoutData() should return on success. It is also the required size of | 35 // GetPlayoutData() should return on success. It is also the required size of |
36 // each recorded buffer used in DeliverRecordedData() calls. | 36 // each recorded buffer used in DeliverRecordedData() calls. |
37 // |sample_rate| is the sample rate of the audio data. This is needed because | 37 // |sample_rate| is the sample rate of the audio data. This is needed because |
38 // |device_buffer| delivers 10ms of data. Given the sample rate the number | 38 // |device_buffer| delivers 10ms of data. Given the sample rate the number |
39 // of samples can be calculated. | 39 // of samples can be calculated. |
40 FineAudioBuffer(AudioDeviceBuffer* device_buffer, | 40 FineAudioBuffer(AudioDeviceBuffer* device_buffer, |
41 size_t desired_frame_size_bytes, | 41 size_t desired_frame_size_bytes, |
42 int sample_rate); | 42 int sample_rate); |
43 ~FineAudioBuffer(); | 43 ~FineAudioBuffer(); |
44 | 44 |
45 // Returns the required size of |buffer| when calling GetPlayoutData(). If | |
46 // the buffer is smaller memory trampling will happen. | |
47 size_t RequiredPlayoutBufferSizeBytes(); | |
48 | |
49 // Clears buffers and counters dealing with playour and/or recording. | 45 // Clears buffers and counters dealing with playour and/or recording. |
50 void ResetPlayout(); | 46 void ResetPlayout(); |
51 void ResetRecord(); | 47 void ResetRecord(); |
52 | 48 |
53 // |buffer| must be of equal or greater size than what is returned by | 49 // |buffer| must be of equal or greater size than what is returned by |
54 // RequiredBufferSize(). This is to avoid unnecessary memcpy. | 50 // RequiredBufferSize(). This is to avoid unnecessary memcpy. |
55 void GetPlayoutData(int8_t* buffer); | 51 void GetPlayoutData(int8_t* buffer); |
56 | 52 |
57 // Consumes the audio data in |buffer| and sends it to the WebRTC layer in | 53 // Consumes the audio data in |buffer| and sends it to the WebRTC layer in |
58 // chunks of 10ms. The provided delay estimates in |playout_delay_ms| and | 54 // chunks of 10ms. The provided delay estimates in |playout_delay_ms| and |
59 // |record_delay_ms| are given to the AEC in the audio processing module. | 55 // |record_delay_ms| are given to the AEC in the audio processing module. |
60 // They can be fixed values on most platforms and they are ignored if an | 56 // They can be fixed values on most platforms and they are ignored if an |
61 // external (hardware/built-in) AEC is used. | 57 // external (hardware/built-in) AEC is used. |
62 // The size of |buffer| is given by |size_in_bytes| and must be equal to | 58 // The size of |buffer| is given by |size_in_bytes| and must be equal to |
63 // |desired_frame_size_bytes_|. A RTC_CHECK will be hit if this is not the | 59 // |desired_frame_size_bytes_|. |
64 // case. | |
65 // Example: buffer size is 5ms => call #1 stores 5ms of data, call #2 stores | 60 // Example: buffer size is 5ms => call #1 stores 5ms of data, call #2 stores |
66 // 5ms of data and sends a total of 10ms to WebRTC and clears the intenal | 61 // 5ms of data and sends a total of 10ms to WebRTC and clears the intenal |
67 // cache. Call #3 restarts the scheme above. | 62 // cache. Call #3 restarts the scheme above. |
68 void DeliverRecordedData(const int8_t* buffer, | 63 void DeliverRecordedData(const int8_t* buffer, |
69 size_t size_in_bytes, | 64 size_t size_in_bytes, |
70 int playout_delay_ms, | 65 int playout_delay_ms, |
71 int record_delay_ms); | 66 int record_delay_ms); |
72 | 67 |
73 private: | 68 private: |
74 // Device buffer that works with 10ms chunks of data both for playout and | 69 // Device buffer that works with 10ms chunks of data both for playout and |
75 // for recording. I.e., the WebRTC side will always be asked for audio to be | 70 // for recording. I.e., the WebRTC side will always be asked for audio to be |
76 // played out in 10ms chunks and recorded audio will be sent to WebRTC in | 71 // played out in 10ms chunks and recorded audio will be sent to WebRTC in |
77 // 10ms chunks as well. This pointer is owned by the constructor of this | 72 // 10ms chunks as well. This pointer is owned by the constructor of this |
78 // class and the owner must ensure that the pointer is valid during the life- | 73 // class and the owner must ensure that the pointer is valid during the life- |
79 // time of this object. | 74 // time of this object. |
80 AudioDeviceBuffer* const device_buffer_; | 75 AudioDeviceBuffer* const device_buffer_; |
81 // Number of bytes delivered by GetPlayoutData() call and provided to | 76 // Number of bytes delivered by GetPlayoutData() call and provided to |
82 // DeliverRecordedData(). | 77 // DeliverRecordedData(). |
83 const size_t desired_frame_size_bytes_; | 78 const size_t desired_frame_size_bytes_; |
84 // Sample rate in Hertz. | 79 // Sample rate in Hertz. |
85 const int sample_rate_; | 80 const int sample_rate_; |
86 // Number of audio samples per 10ms. | 81 // Number of audio samples per 10ms. |
87 const size_t samples_per_10_ms_; | 82 const size_t samples_per_10_ms_; |
88 // Number of audio bytes per 10ms. | 83 // Number of audio bytes per 10ms. |
89 const size_t bytes_per_10_ms_; | 84 const size_t bytes_per_10_ms_; |
90 // Storage for output samples that are not yet asked for. | 85 rtc::BufferT<int8_t> playout_buffer_; |
91 std::unique_ptr<int8_t[]> playout_cache_buffer_; | |
92 // Location of first unread output sample. | |
93 size_t playout_cached_buffer_start_; | |
94 // Number of bytes stored in output (contain samples to be played out) cache. | |
95 size_t playout_cached_bytes_; | |
96 // Storage for input samples that are about to be delivered to the WebRTC | 86 // Storage for input samples that are about to be delivered to the WebRTC |
97 // ADB or remains from the last successful delivery of a 10ms audio buffer. | 87 // ADB or remains from the last successful delivery of a 10ms audio buffer. |
98 rtc::BufferT<int8_t> record_buffer_; | 88 rtc::BufferT<int8_t> record_buffer_; |
99 }; | 89 }; |
100 | 90 |
101 } // namespace webrtc | 91 } // namespace webrtc |
102 | 92 |
103 #endif // WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_ | 93 #endif // WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_ |
OLD | NEW |