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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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 "ppapi/shared_impl/ppb_audio_config_shared.h" 5 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
6 #include "ppapi/thunk/enter.h"
6 7
7 namespace ppapi { 8 namespace ppapi {
8 9
9 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(PP_Instance instance) 10 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(PP_Instance instance)
10 : Resource(instance), 11 : Resource(instance),
11 sample_rate_(PP_AUDIOSAMPLERATE_NONE), 12 sample_rate_(PP_AUDIOSAMPLERATE_NONE),
12 sample_frame_count_(0) { 13 sample_frame_count_(0) {
13 } 14 }
14 15
15 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared( 16 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(
(...skipping 23 matching lines...) Expand all
39 PP_Instance instance, 40 PP_Instance instance,
40 PP_AudioSampleRate sample_rate, 41 PP_AudioSampleRate sample_rate,
41 uint32_t sample_frame_count) { 42 uint32_t sample_frame_count) {
42 scoped_refptr<PPB_AudioConfig_Shared> object(new PPB_AudioConfig_Shared( 43 scoped_refptr<PPB_AudioConfig_Shared> object(new PPB_AudioConfig_Shared(
43 HostResource::MakeInstanceOnly(instance))); 44 HostResource::MakeInstanceOnly(instance)));
44 if (!object->Init(sample_rate, sample_frame_count)) 45 if (!object->Init(sample_rate, sample_frame_count))
45 return 0; 46 return 0;
46 return object->GetReference(); 47 return object->GetReference();
47 } 48 }
48 49
50 // static
51 uint32_t PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_0(
52 PP_AudioSampleRate sample_rate,
53 uint32_t requested_sample_frame_count) {
54 // Version 1.0: Don't actually query to get a value from the
55 // hardware; instead return the input for in-range values.
56 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
57 return PP_AUDIOMINSAMPLEFRAMECOUNT;
58 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT)
59 return PP_AUDIOMAXSAMPLEFRAMECOUNT;
60 return requested_sample_frame_count;
61 }
62
63 // static
64 uint32_t PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_1(
65 PP_Instance instance,
66 PP_AudioSampleRate sample_rate,
67 uint32_t sample_frame_count) {
68 // Version 1.1: Query the back-end hardware for sample rate and buffer size,
69 // and recommend a best fit based on request.
70 thunk::EnterInstance enter(instance);
71 if (enter.failed())
72 return 0;
73 // 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.
74 PP_AudioSampleRate hardware_sample_rate = static_cast<PP_AudioSampleRate>(
75 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.
76 uint32_t hardware_sample_frame_count =
77 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.
78 // Clamp the input.
brettw 2012/02/14 18:50:18 This comment is probably not necessary
nfullagar 2012/02/14 23:21:22 Done.
79 if (sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
80 sample_frame_count = PP_AUDIOMINSAMPLEFRAMECOUNT;
81 // 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.
82 // multiple of the audio hardware's sample frame count.
83 if (hardware_sample_rate == sample_rate && hardware_sample_frame_count > 0) {
84 // Round up input sample_frame_count to nearest multiple.
85 uint32_t multiple = (sample_frame_count + hardware_sample_frame_count - 1) /
86 hardware_sample_frame_count;
87 uint32_t recommendation = hardware_sample_frame_count * multiple;
88 if (recommendation > PP_AUDIOMAXSAMPLEFRAMECOUNT)
89 recommendation = PP_AUDIOMAXSAMPLEFRAMECOUNT;
90 return recommendation;
91 }
92 // 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.
93 const uint32_t kDefault30msAt44100kHz = 1323;
94 const uint32_t kDefault30msAt48000kHz = 1440;
95 switch (sample_rate) {
96 case PP_AUDIOSAMPLERATE_44100:
97 return kDefault30msAt44100kHz;
98 case PP_AUDIOSAMPLERATE_48000:
99 return kDefault30msAt48000kHz;
100 case PP_AUDIOSAMPLERATE_NONE:
101 return 0;
102 }
103 // Unable to make a recommendation.
104 return 0;
105 }
106
107 // static
108 PP_AudioSampleRate PPB_AudioConfig_Shared::RecommendSampleRate(
109 PP_Instance instance) {
110 thunk::EnterInstance enter(instance);
111 if (enter.failed())
112 return PP_AUDIOSAMPLERATE_NONE;
113 PP_AudioSampleRate hardware_sample_rate = static_cast<PP_AudioSampleRate>(
114 enter.functions()->GetAudioHardwareOutputSampleRate(instance));
115 return hardware_sample_rate;
116 }
117
49 thunk::PPB_AudioConfig_API* PPB_AudioConfig_Shared::AsPPB_AudioConfig_API() { 118 thunk::PPB_AudioConfig_API* PPB_AudioConfig_Shared::AsPPB_AudioConfig_API() {
50 return this; 119 return this;
51 } 120 }
52 121
53 PP_AudioSampleRate PPB_AudioConfig_Shared::GetSampleRate() { 122 PP_AudioSampleRate PPB_AudioConfig_Shared::GetSampleRate() {
54 return sample_rate_; 123 return sample_rate_;
55 } 124 }
56 125
57 uint32_t PPB_AudioConfig_Shared::GetSampleFrameCount() { 126 uint32_t PPB_AudioConfig_Shared::GetSampleFrameCount() {
58 return sample_frame_count_; 127 return sample_frame_count_;
(...skipping 12 matching lines...) Expand all
71 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || 140 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT ||
72 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) 141 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
73 return false; 142 return false;
74 143
75 sample_rate_ = sample_rate; 144 sample_rate_ = sample_rate;
76 sample_frame_count_ = sample_frame_count; 145 sample_frame_count_ = sample_frame_count;
77 return true; 146 return true;
78 } 147 }
79 148
80 } // namespace ppapi 149 } // namespace ppapi
OLDNEW
« 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