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

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, 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) 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 return PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_0(sample_rate,
28 // hardware, so we always return the input for in-range values. 29 requested_sample_frame_count);
29 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
30 return PP_AUDIOMINSAMPLEFRAMECOUNT;
31 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT)
32 return PP_AUDIOMAXSAMPLEFRAMECOUNT;
33 return requested_sample_frame_count;
34 } 30 }
35 31
32 uint32_t RecommendSampleFrameCount_1_1(PP_Instance instance,
33 PP_AudioSampleRate sample_rate,
34 uint32_t requested_sample_frame_count) {
35 EnterInstance enter(instance);
36 if (enter.failed())
37 return 0;
38 return PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_1(instance,
39 sample_rate, requested_sample_frame_count);
40 }
41
42
36 PP_Bool IsAudioConfig(PP_Resource resource) { 43 PP_Bool IsAudioConfig(PP_Resource resource) {
37 EnterResource<PPB_AudioConfig_API> enter(resource, false); 44 EnterResource<PPB_AudioConfig_API> enter(resource, false);
38 return PP_FromBool(enter.succeeded()); 45 return PP_FromBool(enter.succeeded());
39 } 46 }
40 47
41 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { 48 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) {
42 EnterResource<PPB_AudioConfig_API> enter(config_id, true); 49 EnterResource<PPB_AudioConfig_API> enter(config_id, true);
43 if (enter.failed()) 50 if (enter.failed())
44 return PP_AUDIOSAMPLERATE_NONE; 51 return PP_AUDIOSAMPLERATE_NONE;
45 return enter.object()->GetSampleRate(); 52 return enter.object()->GetSampleRate();
46 } 53 }
47 54
48 uint32_t GetSampleFrameCount(PP_Resource config_id) { 55 uint32_t GetSampleFrameCount(PP_Resource config_id) {
49 EnterResource<PPB_AudioConfig_API> enter(config_id, true); 56 EnterResource<PPB_AudioConfig_API> enter(config_id, true);
50 if (enter.failed()) 57 if (enter.failed())
51 return 0; 58 return 0;
52 return enter.object()->GetSampleFrameCount(); 59 return enter.object()->GetSampleFrameCount();
53 } 60 }
54 61
55 const PPB_AudioConfig g_ppb_audio_config_thunk = { 62 PP_AudioSampleRate RecommendSampleRate(PP_Instance instance) {
63 EnterInstance enter(instance);
64 if (enter.failed())
65 return PP_AUDIOSAMPLERATE_NONE;
66 return PPB_AudioConfig_Shared::RecommendSampleRate(instance);
67 }
68
69 const PPB_AudioConfig_1_0 g_ppb_audio_config_thunk_1_0 = {
56 &CreateStereo16bit, 70 &CreateStereo16bit,
57 &RecommendSampleFrameCount, 71 &RecommendSampleFrameCount_1_0,
58 &IsAudioConfig, 72 &IsAudioConfig,
59 &GetSampleRate, 73 &GetSampleRate,
60 &GetSampleFrameCount 74 &GetSampleFrameCount
61 }; 75 };
62 76
77 const PPB_AudioConfig_1_1 g_ppb_audio_config_thunk_1_1 = {
78 &CreateStereo16bit,
79 &RecommendSampleFrameCount_1_1,
80 &IsAudioConfig,
81 &GetSampleRate,
82 &GetSampleFrameCount,
83 &RecommendSampleRate
84 };
85
86
63 } // namespace 87 } // namespace
64 88
65 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() { 89 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() {
66 return &g_ppb_audio_config_thunk; 90 return &g_ppb_audio_config_thunk_1_0;
91 }
92
93 const PPB_AudioConfig_1_1* GetPPB_AudioConfig_1_1_Thunk() {
94 return &g_ppb_audio_config_thunk_1_1;
67 } 95 }
68 96
69 } // namespace thunk 97 } // namespace thunk
70 } // namespace ppapi 98 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698