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

Unified Diff: ppapi/shared_impl/ppb_audio_config_shared.cc

Issue 9129007: Work on improving PpbAudioConfig:RecommendSampleFrameCount (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/shared_impl/ppb_audio_config_shared.h ('k') | ppapi/tests/test_audio.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/ppb_audio_config_shared.cc
===================================================================
--- ppapi/shared_impl/ppb_audio_config_shared.cc (revision 120806)
+++ ppapi/shared_impl/ppb_audio_config_shared.cc (working copy)
@@ -1,8 +1,9 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/shared_impl/ppb_audio_config_shared.h"
+#include "ppapi/thunk/enter.h"
namespace ppapi {
@@ -46,6 +47,74 @@
return object->GetReference();
}
+// static
+uint32_t PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_0(
+ PP_AudioSampleRate sample_rate,
+ uint32_t requested_sample_frame_count) {
+ // Version 1.0: Don't actually query to get a value from the
+ // hardware; instead return the input for in-range values.
+ if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
+ return PP_AUDIOMINSAMPLEFRAMECOUNT;
+ if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT)
+ return PP_AUDIOMAXSAMPLEFRAMECOUNT;
+ return requested_sample_frame_count;
+}
+
+// static
+uint32_t PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_1(
+ PP_Instance instance,
+ PP_AudioSampleRate sample_rate,
+ uint32_t sample_frame_count) {
+ // Version 1.1: Query the back-end hardware for sample rate and buffer size,
+ // and recommend a best fit based on request.
+ thunk::EnterInstance enter(instance);
+ if (enter.failed())
+ return 0;
+ // Get the hardware config.
brettw 2012/02/14 18:50:18 Can you put a blank line before this?
nfullagar 2012/02/14 23:21:22 Done.
+ PP_AudioSampleRate hardware_sample_rate = static_cast<PP_AudioSampleRate>(
+ enter.functions()->GetAudioHardwareOutputSampleRate(instance));
dmichael (off chromium) 2012/02/14 17:19:24 nit: 4-space indent
nfullagar 2012/02/14 23:21:22 Done.
+ uint32_t hardware_sample_frame_count =
+ enter.functions()->GetAudioHardwareOutputBufferSize(instance);
dmichael (off chromium) 2012/02/14 17:19:24 nit: 4-space indent
nfullagar 2012/02/14 23:21:22 Done.
+ // Clamp the input.
brettw 2012/02/14 18:50:18 This comment is probably not necessary
nfullagar 2012/02/14 23:21:22 Done.
+ if (sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
+ sample_frame_count = PP_AUDIOMINSAMPLEFRAMECOUNT;
+ // If client is using same sample rate as audio hardware, then recommend a
brettw 2012/02/14 18:50:18 I'd also do a blank line above this comment...
nfullagar 2012/02/14 23:21:22 Done.
+ // multiple of the audio hardware's sample frame count.
+ if (hardware_sample_rate == sample_rate && hardware_sample_frame_count > 0) {
+ // Round up input sample_frame_count to nearest multiple.
+ uint32_t multiple = (sample_frame_count + hardware_sample_frame_count - 1) /
+ hardware_sample_frame_count;
+ uint32_t recommendation = hardware_sample_frame_count * multiple;
+ if (recommendation > PP_AUDIOMAXSAMPLEFRAMECOUNT)
+ recommendation = PP_AUDIOMAXSAMPLEFRAMECOUNT;
+ return recommendation;
+ }
+ // Otherwise, recommend a conservative 30ms buffer based on sample rate.
brettw 2012/02/14 18:50:18 ...and here as well.
nfullagar 2012/02/14 23:21:22 Done.
+ const uint32_t kDefault30msAt44100kHz = 1323;
+ const uint32_t kDefault30msAt48000kHz = 1440;
+ switch (sample_rate) {
+ case PP_AUDIOSAMPLERATE_44100:
+ return kDefault30msAt44100kHz;
+ case PP_AUDIOSAMPLERATE_48000:
+ return kDefault30msAt48000kHz;
+ case PP_AUDIOSAMPLERATE_NONE:
+ return 0;
+ }
+ // Unable to make a recommendation.
+ return 0;
+}
+
+// static
+PP_AudioSampleRate PPB_AudioConfig_Shared::RecommendSampleRate(
+ PP_Instance instance) {
+ thunk::EnterInstance enter(instance);
+ if (enter.failed())
+ return PP_AUDIOSAMPLERATE_NONE;
+ PP_AudioSampleRate hardware_sample_rate = static_cast<PP_AudioSampleRate>(
+ enter.functions()->GetAudioHardwareOutputSampleRate(instance));
+ return hardware_sample_rate;
+}
+
thunk::PPB_AudioConfig_API* PPB_AudioConfig_Shared::AsPPB_AudioConfig_API() {
return this;
}
« no previous file with comments | « ppapi/shared_impl/ppb_audio_config_shared.h ('k') | ppapi/tests/test_audio.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698