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

Side by Side Diff: ppapi/thunk/ppb_audio_config_thunk.cc

Issue 9129007: Work on improving PpbAudioConfig:RecommendSampleFrameCount (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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) 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 "ppapi/shared_impl/ppb_audio_config_shared.h"
5 #include "ppapi/thunk/thunk.h" 6 #include "ppapi/thunk/thunk.h"
6 #include "ppapi/thunk/enter.h" 7 #include "ppapi/thunk/enter.h"
7 #include "ppapi/thunk/ppb_audio_config_api.h" 8 #include "ppapi/thunk/ppb_audio_config_api.h"
8 #include "ppapi/thunk/resource_creation_api.h" 9 #include "ppapi/thunk/resource_creation_api.h"
9 10
10 namespace ppapi { 11 namespace ppapi {
11 namespace thunk { 12 namespace thunk {
12 13
13 namespace { 14 namespace {
14 15
15 PP_Resource CreateStereo16bit(PP_Instance instance, 16 PP_Resource CreateStereo16bit(PP_Instance instance,
16 PP_AudioSampleRate sample_rate, 17 PP_AudioSampleRate sample_rate,
17 uint32_t sample_frame_count) { 18 uint32_t sample_frame_count) {
18 EnterFunction<ResourceCreationAPI> enter(instance, true); 19 EnterFunction<ResourceCreationAPI> enter(instance, true);
19 if (enter.failed()) 20 if (enter.failed())
20 return 0; 21 return 0;
21 return enter.functions()->CreateAudioConfig(instance, sample_rate, 22 return enter.functions()->CreateAudioConfig(instance, sample_rate,
22 sample_frame_count); 23 sample_frame_count);
23 } 24 }
24 25
25 uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, 26 uint32_t RecommendSampleFrameCount_1_0(PP_AudioSampleRate sample_rate,
26 uint32_t requested_sample_frame_count) { 27 uint32_t requested_sample_frame_count) {
27 // TODO(brettw) Currently we don't actually query to get a value from the 28 // Version 1.0: Don't actually query to get a value from the
28 // hardware, so we always return the input for in-range values. 29 // hardware; instead return the input for in-range values.
29 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) 30 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
30 return PP_AUDIOMINSAMPLEFRAMECOUNT; 31 return PP_AUDIOMINSAMPLEFRAMECOUNT;
31 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) 32 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT)
32 return PP_AUDIOMAXSAMPLEFRAMECOUNT; 33 return PP_AUDIOMAXSAMPLEFRAMECOUNT;
33 return requested_sample_frame_count; 34 return requested_sample_frame_count;
34 } 35 }
35 36
37 uint32_t RecommendSampleFrameCount_1_1(PP_Instance instance,
38 PP_AudioSampleRate sample_rate,
39 uint32_t requested_sample_frame_count) {
40 EnterInstance enter(instance);
41 if (enter.failed())
42 return 0;
43 return PPB_AudioConfig_Shared::RecommendSampleFrameCount(
44 instance, sample_rate, requested_sample_frame_count);
45 }
46
47
36 PP_Bool IsAudioConfig(PP_Resource resource) { 48 PP_Bool IsAudioConfig(PP_Resource resource) {
37 EnterResource<PPB_AudioConfig_API> enter(resource, false); 49 EnterResource<PPB_AudioConfig_API> enter(resource, false);
38 return PP_FromBool(enter.succeeded()); 50 return PP_FromBool(enter.succeeded());
39 } 51 }
40 52
41 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { 53 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) {
42 EnterResource<PPB_AudioConfig_API> enter(config_id, true); 54 EnterResource<PPB_AudioConfig_API> enter(config_id, true);
43 if (enter.failed()) 55 if (enter.failed())
44 return PP_AUDIOSAMPLERATE_NONE; 56 return PP_AUDIOSAMPLERATE_NONE;
45 return enter.object()->GetSampleRate(); 57 return enter.object()->GetSampleRate();
46 } 58 }
47 59
48 uint32_t GetSampleFrameCount(PP_Resource config_id) { 60 uint32_t GetSampleFrameCount(PP_Resource config_id) {
49 EnterResource<PPB_AudioConfig_API> enter(config_id, true); 61 EnterResource<PPB_AudioConfig_API> enter(config_id, true);
50 if (enter.failed()) 62 if (enter.failed())
51 return 0; 63 return 0;
52 return enter.object()->GetSampleFrameCount(); 64 return enter.object()->GetSampleFrameCount();
53 } 65 }
54 66
55 const PPB_AudioConfig g_ppb_audio_config_thunk = { 67 PP_AudioSampleRate RecommendSampleRate(PP_Instance instance) {
68 EnterInstance enter(instance);
69 if (enter.failed())
70 return PP_AUDIOSAMPLERATE_NONE;
71 return PPB_AudioConfig_Shared::RecommendSampleRate(instance);
72 }
73
74 const PPB_AudioConfig_1_0 g_ppb_audio_config_thunk_1_0 = {
56 &CreateStereo16bit, 75 &CreateStereo16bit,
57 &RecommendSampleFrameCount, 76 &RecommendSampleFrameCount_1_0,
58 &IsAudioConfig, 77 &IsAudioConfig,
59 &GetSampleRate, 78 &GetSampleRate,
60 &GetSampleFrameCount 79 &GetSampleFrameCount
61 }; 80 };
62 81
82 const PPB_AudioConfig_1_1 g_ppb_audio_config_thunk_1_1 = {
83 &CreateStereo16bit,
84 &RecommendSampleFrameCount_1_1,
85 &IsAudioConfig,
86 &GetSampleRate,
87 &GetSampleFrameCount,
88 &RecommendSampleRate
89 };
90
91
63 } // namespace 92 } // namespace
64 93
65 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() { 94 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() {
66 return &g_ppb_audio_config_thunk; 95 return &g_ppb_audio_config_thunk_1_0;
96 }
97
98 const PPB_AudioConfig_1_1* GetPPB_AudioConfig_1_1_Thunk() {
99 return &g_ppb_audio_config_thunk_1_1;
67 } 100 }
68 101
69 } // namespace thunk 102 } // namespace thunk
70 } // namespace ppapi 103 } // namespace ppapi
OLDNEW
« ppapi/api/ppb_audio_config.idl ('K') | « ppapi/thunk/interfaces_ppb_public_stable.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698