OLD | NEW |
---|---|
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); | |
brettw
2012/02/10 19:01:33
The thunks shouldn't have actual code in them. I w
nfullagar
2012/02/14 00:42:37
code moved, shared_impl func takes the same args a
| |
41 if (enter.failed()) | |
42 return 0; | |
43 uint32_t hardware_sample_rate = | |
44 enter.functions()->AudioHardwareOutputSampleRate(instance); | |
45 uint32_t hardware_sample_frame_count = | |
46 enter.functions()->AudioHardwareOutputBufferSize(instance); | |
47 return PPB_AudioConfig_Shared::RecommendSampleFrameCount( | |
48 sample_rate, | |
49 requested_sample_frame_count, | |
50 static_cast<PP_AudioSampleRate>(hardware_sample_rate), | |
51 hardware_sample_frame_count); | |
52 } | |
53 | |
54 | |
36 PP_Bool IsAudioConfig(PP_Resource resource) { | 55 PP_Bool IsAudioConfig(PP_Resource resource) { |
37 EnterResource<PPB_AudioConfig_API> enter(resource, false); | 56 EnterResource<PPB_AudioConfig_API> enter(resource, false); |
38 return PP_FromBool(enter.succeeded()); | 57 return PP_FromBool(enter.succeeded()); |
39 } | 58 } |
40 | 59 |
41 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { | 60 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { |
42 EnterResource<PPB_AudioConfig_API> enter(config_id, true); | 61 EnterResource<PPB_AudioConfig_API> enter(config_id, true); |
43 if (enter.failed()) | 62 if (enter.failed()) |
44 return PP_AUDIOSAMPLERATE_NONE; | 63 return PP_AUDIOSAMPLERATE_NONE; |
45 return enter.object()->GetSampleRate(); | 64 return enter.object()->GetSampleRate(); |
46 } | 65 } |
47 | 66 |
48 uint32_t GetSampleFrameCount(PP_Resource config_id) { | 67 uint32_t GetSampleFrameCount(PP_Resource config_id) { |
49 EnterResource<PPB_AudioConfig_API> enter(config_id, true); | 68 EnterResource<PPB_AudioConfig_API> enter(config_id, true); |
50 if (enter.failed()) | 69 if (enter.failed()) |
51 return 0; | 70 return 0; |
52 return enter.object()->GetSampleFrameCount(); | 71 return enter.object()->GetSampleFrameCount(); |
53 } | 72 } |
54 | 73 |
55 const PPB_AudioConfig g_ppb_audio_config_thunk = { | 74 PP_AudioSampleRate RecommendSampleRate(PP_Instance instance) { |
75 EnterInstance enter(instance); | |
76 if (enter.failed()) | |
77 return PP_AUDIOSAMPLERATE_NONE; | |
78 return static_cast<PP_AudioSampleRate>( | |
79 enter.functions()->AudioHardwareOutputSampleRate(instance)); | |
80 } | |
81 | |
82 const PPB_AudioConfig_1_0 g_ppb_audio_config_thunk_1_0 = { | |
56 &CreateStereo16bit, | 83 &CreateStereo16bit, |
57 &RecommendSampleFrameCount, | 84 &RecommendSampleFrameCount_1_0, |
58 &IsAudioConfig, | 85 &IsAudioConfig, |
59 &GetSampleRate, | 86 &GetSampleRate, |
60 &GetSampleFrameCount | 87 &GetSampleFrameCount |
61 }; | 88 }; |
62 | 89 |
90 const PPB_AudioConfig_1_1 g_ppb_audio_config_thunk_1_1 = { | |
91 &CreateStereo16bit, | |
92 &RecommendSampleFrameCount_1_1, | |
93 &IsAudioConfig, | |
94 &GetSampleRate, | |
95 &GetSampleFrameCount, | |
96 &RecommendSampleRate | |
97 }; | |
98 | |
99 | |
63 } // namespace | 100 } // namespace |
64 | 101 |
65 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() { | 102 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() { |
66 return &g_ppb_audio_config_thunk; | 103 return &g_ppb_audio_config_thunk_1_0; |
104 } | |
105 | |
106 const PPB_AudioConfig_1_1* GetPPB_AudioConfig_1_1_Thunk() { | |
107 return &g_ppb_audio_config_thunk_1_1; | |
67 } | 108 } |
68 | 109 |
69 } // namespace thunk | 110 } // namespace thunk |
70 } // namespace ppapi | 111 } // namespace ppapi |
OLD | NEW |