Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: webrtc/modules/audio_device/fine_audio_buffer.h

Issue 2894873002: Improved audio buffer handling for iOS (Closed)
Patch Set: rebased Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_
12 #define WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_ 12 #define WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include "webrtc/base/array_view.h"
16 #include "webrtc/base/buffer.h" 17 #include "webrtc/base/buffer.h"
17 #include "webrtc/typedefs.h" 18 #include "webrtc/typedefs.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
21 class AudioDeviceBuffer; 22 class AudioDeviceBuffer;
22 23
23 // FineAudioBuffer takes an AudioDeviceBuffer (ADB) which deals with audio data 24 // FineAudioBuffer takes an AudioDeviceBuffer (ADB) which deals with audio data
24 // corresponding to 10ms of data. It then allows for this data to be pulled in 25 // corresponding to 10ms of data. It then allows for this data to be pulled in
25 // a finer or coarser granularity. I.e. interacting with this class instead of 26 // a finer or coarser granularity. I.e. interacting with this class instead of
26 // directly with the AudioDeviceBuffer one can ask for any number of audio data 27 // directly with the AudioDeviceBuffer one can ask for any number of audio data
27 // samples. This class also ensures that audio data can be delivered to the ADB 28 // samples. This class also ensures that audio data can be delivered to the ADB
28 // in 10ms chunks when the size of the provided audio buffers differs from 10ms. 29 // in 10ms chunks when the size of the provided audio buffers differs from 10ms.
29 // As an example: calling DeliverRecordedData() with 5ms buffers will deliver 30 // As an example: calling DeliverRecordedData() with 5ms buffers will deliver
30 // accumulated 10ms worth of data to the ADB every second call. 31 // accumulated 10ms worth of data to the ADB every second call.
32 // TODO(henrika): add support for stereo when mobile platforms need it.
31 class FineAudioBuffer { 33 class FineAudioBuffer {
32 public: 34 public:
33 // |device_buffer| is a buffer that provides 10ms of audio data. 35 // |device_buffer| is a buffer that provides 10ms of audio data.
34 // |desired_frame_size_bytes| is the number of bytes of audio data
35 // GetPlayoutData() should return on success. It is also the required size of
36 // each recorded buffer used in DeliverRecordedData() calls.
37 // |sample_rate| is the sample rate of the audio data. This is needed because 36 // |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 37 // |device_buffer| delivers 10ms of data. Given the sample rate the number
39 // of samples can be calculated. 38 // of samples can be calculated. The |capacity| ensures that the buffer size
39 // can be increased to at least capacity without further reallocation.
40 FineAudioBuffer(AudioDeviceBuffer* device_buffer, 40 FineAudioBuffer(AudioDeviceBuffer* device_buffer,
41 size_t desired_frame_size_bytes, 41 int sample_rate,
42 int sample_rate); 42 size_t capacity);
43 ~FineAudioBuffer(); 43 ~FineAudioBuffer();
44 44
45 // Clears buffers and counters dealing with playour and/or recording. 45 // Clears buffers and counters dealing with playour and/or recording.
46 void ResetPlayout(); 46 void ResetPlayout();
47 void ResetRecord(); 47 void ResetRecord();
48 48
49 // |buffer| must be of equal or greater size than what is returned by 49 // Copies audio samples into |audio_buffer| where number of requested
50 // RequiredBufferSize(). This is to avoid unnecessary memcpy. 50 // elements is specified by |audio_buffer.size()|. The producer will always
51 void GetPlayoutData(int8_t* buffer); 51 // fill up the audio buffer and if no audio exists, the buffer will contain
52 // silence instead.
53 void GetPlayoutData(rtc::ArrayView<int8_t> audio_buffer);
52 54
53 // Consumes the audio data in |buffer| and sends it to the WebRTC layer in 55 // Consumes the audio data in |audio_buffer| and sends it to the WebRTC layer
54 // chunks of 10ms. The provided delay estimates in |playout_delay_ms| and 56 // in chunks of 10ms. The provided delay estimates in |playout_delay_ms| and
55 // |record_delay_ms| are given to the AEC in the audio processing module. 57 // |record_delay_ms| are given to the AEC in the audio processing module.
56 // They can be fixed values on most platforms and they are ignored if an 58 // They can be fixed values on most platforms and they are ignored if an
57 // external (hardware/built-in) AEC is used. 59 // external (hardware/built-in) AEC is used.
58 // The size of |buffer| is given by |size_in_bytes| and must be equal to
59 // |desired_frame_size_bytes_|.
60 // 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
61 // 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
62 // cache. Call #3 restarts the scheme above. 62 // cache. Call #3 restarts the scheme above.
63 void DeliverRecordedData(const int8_t* buffer, 63 void DeliverRecordedData(rtc::ArrayView<const int8_t> audio_buffer,
64 size_t size_in_bytes,
65 int playout_delay_ms, 64 int playout_delay_ms,
66 int record_delay_ms); 65 int record_delay_ms);
67 66
68 private: 67 private:
69 // Device buffer that works with 10ms chunks of data both for playout and 68 // Device buffer that works with 10ms chunks of data both for playout and
70 // for recording. I.e., the WebRTC side will always be asked for audio to be 69 // for recording. I.e., the WebRTC side will always be asked for audio to be
71 // played out in 10ms chunks and recorded audio will be sent to WebRTC in 70 // played out in 10ms chunks and recorded audio will be sent to WebRTC in
72 // 10ms chunks as well. This pointer is owned by the constructor of this 71 // 10ms chunks as well. This pointer is owned by the constructor of this
73 // class and the owner must ensure that the pointer is valid during the life- 72 // class and the owner must ensure that the pointer is valid during the life-
74 // time of this object. 73 // time of this object.
75 AudioDeviceBuffer* const device_buffer_; 74 AudioDeviceBuffer* const device_buffer_;
76 // Number of bytes delivered by GetPlayoutData() call and provided to
77 // DeliverRecordedData().
78 const size_t desired_frame_size_bytes_;
79 // Sample rate in Hertz. 75 // Sample rate in Hertz.
80 const int sample_rate_; 76 const int sample_rate_;
81 // Number of audio samples per 10ms. 77 // Number of audio samples per 10ms.
82 const size_t samples_per_10_ms_; 78 const size_t samples_per_10_ms_;
83 // Number of audio bytes per 10ms. 79 // Number of audio bytes per 10ms.
84 const size_t bytes_per_10_ms_; 80 const size_t bytes_per_10_ms_;
81 // Storage for output samples from which a consumer can read audio buffers
82 // in any size using GetPlayoutData().
85 rtc::BufferT<int8_t> playout_buffer_; 83 rtc::BufferT<int8_t> playout_buffer_;
86 // Storage for input samples that are about to be delivered to the WebRTC 84 // Storage for input samples that are about to be delivered to the WebRTC
87 // ADB or remains from the last successful delivery of a 10ms audio buffer. 85 // ADB or remains from the last successful delivery of a 10ms audio buffer.
88 rtc::BufferT<int8_t> record_buffer_; 86 rtc::BufferT<int8_t> record_buffer_;
89 }; 87 };
90 88
91 } // namespace webrtc 89 } // namespace webrtc
92 90
93 #endif // WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_ 91 #endif // WEBRTC_MODULES_AUDIO_DEVICE_FINE_AUDIO_BUFFER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/android/opensles_recorder.cc ('k') | webrtc/modules/audio_device/fine_audio_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698