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

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

Issue 554733002: Add support for 24kHz audio sample rate and remove the validation check (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.cc ('k') | media/audio/sample_rates.h » ('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 "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 11 matching lines...) Expand all
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
25 #include "media/audio/win/core_audio_util_win.h" 25 #include "media/audio/win/core_audio_util_win.h"
26 #endif 26 #endif
27 27
28 namespace content { 28 namespace content {
29 29
30 namespace { 30 namespace {
31 31
32 // Supported hardware sample rates for output sides.
33 #if defined(OS_WIN) || defined(OS_MACOSX)
34 // AudioHardwareConfig::GetOutputSampleRate() asks the audio layer for its
35 // current sample rate (set by the user) on Windows and Mac OS X. The listed
36 // rates below adds restrictions and Initialize() will fail if the user selects
37 // any rate outside these ranges.
38 const int kValidOutputRates[] = {96000, 48000, 44100, 32000, 16000};
39 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
40 const int kValidOutputRates[] = {48000, 44100};
41 #elif defined(OS_ANDROID)
42 // TODO(leozwang): We want to use native sampling rate on Android to achieve
43 // low latency, currently 16000 is used to work around audio problem on some
44 // Android devices.
45 const int kValidOutputRates[] = {48000, 44100, 16000};
46 #else
47 const int kValidOutputRates[] = {44100};
48 #endif
49
50 // This is a simple wrapper class that's handed out to users of a shared 32 // This is a simple wrapper class that's handed out to users of a shared
51 // WebRtcAudioRenderer instance. This class maintains the per-user 'playing' 33 // WebRtcAudioRenderer instance. This class maintains the per-user 'playing'
52 // and 'started' states to avoid problems related to incorrect usage which 34 // and 'started' states to avoid problems related to incorrect usage which
53 // might violate the implementation assumptions inside WebRtcAudioRenderer 35 // might violate the implementation assumptions inside WebRtcAudioRenderer
54 // (see the play reference count). 36 // (see the play reference count).
55 class SharedAudioRenderer : public MediaStreamAudioRenderer { 37 class SharedAudioRenderer : public MediaStreamAudioRenderer {
56 public: 38 public:
57 // Callback definition for a callback that is called when when Play(), Pause() 39 // Callback definition for a callback that is called when when Play(), Pause()
58 // or SetVolume are called (whenever the internal |playing_state_| changes). 40 // or SetVolume are called (whenever the internal |playing_state_| changes).
59 typedef base::Callback< 41 typedef base::Callback<
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 229 }
248 media::AudioSampleRate asr; 230 media::AudioSampleRate asr;
249 if (media::ToAudioSampleRate(sample_rate, &asr)) { 231 if (media::ToAudioSampleRate(sample_rate, &asr)) {
250 UMA_HISTOGRAM_ENUMERATION( 232 UMA_HISTOGRAM_ENUMERATION(
251 "WebRTC.AudioOutputSampleRate", asr, media::kAudioSampleRateMax + 1); 233 "WebRTC.AudioOutputSampleRate", asr, media::kAudioSampleRateMax + 1);
252 } else { 234 } else {
253 UMA_HISTOGRAM_COUNTS("WebRTC.AudioOutputSampleRateUnexpected", 235 UMA_HISTOGRAM_COUNTS("WebRTC.AudioOutputSampleRateUnexpected",
254 sample_rate); 236 sample_rate);
255 } 237 }
256 238
257 // Verify that the reported output hardware sample rate is supported
258 // on the current platform.
259 if (std::find(&kValidOutputRates[0],
260 &kValidOutputRates[0] + arraysize(kValidOutputRates),
261 sample_rate) ==
262 &kValidOutputRates[arraysize(kValidOutputRates)]) {
263 DLOG(ERROR) << sample_rate << " is not a supported output rate.";
264 return false;
265 }
266
267 // Set up audio parameters for the source, i.e., the WebRTC client. 239 // Set up audio parameters for the source, i.e., the WebRTC client.
268 240
269 // The WebRTC client only supports multiples of 10ms as buffer size where 241 // The WebRTC client only supports multiples of 10ms as buffer size where
270 // 10ms is preferred for lowest possible delay. 242 // 10ms is preferred for lowest possible delay.
271 media::AudioParameters source_params; 243 media::AudioParameters source_params;
272 const int frames_per_10ms = (sample_rate / 100); 244 const int frames_per_10ms = (sample_rate / 100);
273 DVLOG(1) << "Using WebRTC output buffer size: " << frames_per_10ms; 245 DVLOG(1) << "Using WebRTC output buffer size: " << frames_per_10ms;
274 246
275 source_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 247 source_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
276 sink_params_.channel_layout(), sink_params_.channels(), 248 sink_params_.channel_layout(), sink_params_.channels(),
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 if (RemovePlayingState(source, state)) 538 if (RemovePlayingState(source, state))
567 EnterPauseState(); 539 EnterPauseState();
568 } else if (AddPlayingState(source, state)) { 540 } else if (AddPlayingState(source, state)) {
569 EnterPlayState(); 541 EnterPlayState();
570 } 542 }
571 UpdateSourceVolume(source); 543 UpdateSourceVolume(source);
572 } 544 }
573 } 545 }
574 546
575 } // namespace content 547 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.cc ('k') | media/audio/sample_rates.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698