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

Side by Side Diff: content/renderer/media/webrtc_audio_renderer.cc

Issue 17209003: Enable low latency mode for audio playback on Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: code review, add TEST= line Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/audio/android/audio_manager_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/webrtc_audio_renderer.h" 5 #include "content/renderer/media/webrtc_audio_renderer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "content/renderer/media/audio_device_factory.h" 10 #include "content/renderer/media/audio_device_factory.h"
(...skipping 20 matching lines...) Expand all
31 // rates below adds restrictions and Initialize() will fail if the user selects 31 // rates below adds restrictions and Initialize() will fail if the user selects
32 // any rate outside these ranges. 32 // any rate outside these ranges.
33 const int kValidOutputRates[] = {96000, 48000, 44100, 32000, 16000}; 33 const int kValidOutputRates[] = {96000, 48000, 44100, 32000, 16000};
34 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 34 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
35 const int kValidOutputRates[] = {48000, 44100}; 35 const int kValidOutputRates[] = {48000, 44100};
36 #elif defined(OS_ANDROID) 36 #elif defined(OS_ANDROID)
37 // TODO(leozwang): We want to use native sampling rate on Android to achieve 37 // TODO(leozwang): We want to use native sampling rate on Android to achieve
38 // low latency, currently 16000 is used to work around audio problem on some 38 // low latency, currently 16000 is used to work around audio problem on some
39 // Android devices. 39 // Android devices.
40 const int kValidOutputRates[] = {48000, 44100, 16000}; 40 const int kValidOutputRates[] = {48000, 44100, 16000};
41 const int kDefaultOutputBufferSize = 2048;
41 #else 42 #else
42 const int kValidOutputRates[] = {44100}; 43 const int kValidOutputRates[] = {44100};
43 #endif 44 #endif
44 45
45 // TODO(xians): Merge the following code to WebRtcAudioCapturer, or remove. 46 // TODO(xians): Merge the following code to WebRtcAudioCapturer, or remove.
46 enum AudioFramesPerBuffer { 47 enum AudioFramesPerBuffer {
47 k160, 48 k160,
48 k320, 49 k320,
49 k440, 50 k440,
50 k480, 51 k480,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 sample_rate, 16, buffer_size); 163 sample_rate, 16, buffer_size);
163 164
164 // Set up audio parameters for the sink, i.e., the native audio output stream. 165 // Set up audio parameters for the sink, i.e., the native audio output stream.
165 // We strive to open up using native parameters to achieve best possible 166 // We strive to open up using native parameters to achieve best possible
166 // performance and to ensure that no FIFO is needed on the browser side to 167 // performance and to ensure that no FIFO is needed on the browser side to
167 // match the client request. Any mismatch between the source and the sink is 168 // match the client request. Any mismatch between the source and the sink is
168 // taken care of in this class instead using a pull FIFO. 169 // taken care of in this class instead using a pull FIFO.
169 170
170 media::AudioParameters sink_params; 171 media::AudioParameters sink_params;
171 172
173 #if defined(OS_ANDROID)
174 buffer_size = kDefaultOutputBufferSize;
175 #else
172 buffer_size = hardware_config->GetOutputBufferSize(); 176 buffer_size = hardware_config->GetOutputBufferSize();
177 #endif
178
173 sink_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 179 sink_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
174 channel_layout, channels, 0, sample_rate, 16, buffer_size); 180 channel_layout, channels, 0, sample_rate, 16, buffer_size);
175 181
176 // Create a FIFO if re-buffering is required to match the source input with 182 // Create a FIFO if re-buffering is required to match the source input with
177 // the sink request. The source acts as provider here and the sink as 183 // the sink request. The source acts as provider here and the sink as
178 // consumer. 184 // consumer.
179 fifo_delay_milliseconds_ = 0; 185 fifo_delay_milliseconds_ = 0;
180 if (source_params.frames_per_buffer() != sink_params.frames_per_buffer()) { 186 if (source_params.frames_per_buffer() != sink_params.frames_per_buffer()) {
181 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer() 187 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer()
182 << " to " << sink_params.frames_per_buffer(); 188 << " to " << sink_params.frames_per_buffer();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 345 }
340 346
341 // De-interleave each channel and convert to 32-bit floating-point 347 // De-interleave each channel and convert to 32-bit floating-point
342 // with nominal range -1.0 -> +1.0 to match the callback format. 348 // with nominal range -1.0 -> +1.0 to match the callback format.
343 audio_bus->FromInterleaved(buffer_.get(), 349 audio_bus->FromInterleaved(buffer_.get(),
344 audio_bus->frames(), 350 audio_bus->frames(),
345 sizeof(buffer_[0])); 351 sizeof(buffer_[0]));
346 } 352 }
347 353
348 } // namespace content 354 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | media/audio/android/audio_manager_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698