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

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
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 6
7 namespace ppapi { 7 namespace ppapi {
8 8
9 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(PP_Instance instance) 9 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(PP_Instance instance)
10 : Resource(instance), 10 : Resource(instance),
11 sample_rate_(PP_AUDIOSAMPLERATE_NONE), 11 sample_rate_(PP_AUDIOSAMPLERATE_NONE),
(...skipping 27 matching lines...) Expand all
39 PP_Instance instance, 39 PP_Instance instance,
40 PP_AudioSampleRate sample_rate, 40 PP_AudioSampleRate sample_rate,
41 uint32_t sample_frame_count) { 41 uint32_t sample_frame_count) {
42 scoped_refptr<PPB_AudioConfig_Shared> object(new PPB_AudioConfig_Shared( 42 scoped_refptr<PPB_AudioConfig_Shared> object(new PPB_AudioConfig_Shared(
43 HostResource::MakeInstanceOnly(instance))); 43 HostResource::MakeInstanceOnly(instance)));
44 if (!object->Init(sample_rate, sample_frame_count)) 44 if (!object->Init(sample_rate, sample_frame_count))
45 return 0; 45 return 0;
46 return object->GetReference(); 46 return object->GetReference();
47 } 47 }
48 48
49 // static
50 uint32_t PPB_AudioConfig_Shared::RecommendSampleFrameCount(
51 PP_AudioSampleRate sample_rate,
52 uint32_t sample_frame_count,
53 PP_AudioSampleRate hardware_sample_rate,
54 uint32_t hardware_sample_frame_count) {
55 if (sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
56 sample_frame_count = PP_AUDIOMINSAMPLEFRAMECOUNT;
57 // If client is using same sample rate as audio hardware, then recommend a
58 // multiple of the audio hardware's sample frame count.
59 if (hardware_sample_rate == sample_rate && hardware_sample_frame_count > 0) {
60 // Round up input sample_frame_count to nearest multiple.
61 uint32_t multiple = (sample_frame_count + hardware_sample_frame_count - 1) /
62 hardware_sample_frame_count;
63 uint32_t recommendation = hardware_sample_frame_count * multiple;
64 if (recommendation > PP_AUDIOMAXSAMPLEFRAMECOUNT)
65 recommendation = PP_AUDIOMAXSAMPLEFRAMECOUNT;
66 return recommendation;
67 }
68 // Otherwise, recommend a conservative 30ms buffer based on sample rate.
69 const uint32_t kDefault30msAt44100kHz = 1323;
70 const uint32_t kDefault30msAt48000kHz = 1440;
71 switch (sample_rate) {
72 case PP_AUDIOSAMPLERATE_44100:
73 return kDefault30msAt44100kHz;
74 case PP_AUDIOSAMPLERATE_48000:
75 return kDefault30msAt48000kHz;
76 case PP_AUDIOSAMPLERATE_NONE:
77 return 0;
78 }
79 // Unable to make a recommendation.
80 return 0;
81 }
82
49 thunk::PPB_AudioConfig_API* PPB_AudioConfig_Shared::AsPPB_AudioConfig_API() { 83 thunk::PPB_AudioConfig_API* PPB_AudioConfig_Shared::AsPPB_AudioConfig_API() {
50 return this; 84 return this;
51 } 85 }
52 86
53 PP_AudioSampleRate PPB_AudioConfig_Shared::GetSampleRate() { 87 PP_AudioSampleRate PPB_AudioConfig_Shared::GetSampleRate() {
54 return sample_rate_; 88 return sample_rate_;
55 } 89 }
56 90
57 uint32_t PPB_AudioConfig_Shared::GetSampleFrameCount() { 91 uint32_t PPB_AudioConfig_Shared::GetSampleFrameCount() {
58 return sample_frame_count_; 92 return sample_frame_count_;
(...skipping 12 matching lines...) Expand all
71 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || 105 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT ||
72 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) 106 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
73 return false; 107 return false;
74 108
75 sample_rate_ = sample_rate; 109 sample_rate_ = sample_rate;
76 sample_frame_count_ = sample_frame_count; 110 sample_frame_count_ = sample_frame_count;
77 return true; 111 return true;
78 } 112 }
79 113
80 } // namespace ppapi 114 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698