Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ppapi / thunk / ppb_audio_config_thunk.cc
blob2dfa1129cefb14f41234a3325d8949e36aa54926
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
3 // found in the LICENSE file.
5 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
6 #include "ppapi/thunk/thunk.h"
7 #include "ppapi/thunk/enter.h"
8 #include "ppapi/thunk/ppb_audio_config_api.h"
9 #include "ppapi/thunk/resource_creation_api.h"
11 namespace ppapi {
12 namespace thunk {
14 namespace {
16 PP_Resource CreateStereo16bit(PP_Instance instance,
17 PP_AudioSampleRate sample_rate,
18 uint32_t sample_frame_count) {
19 EnterResourceCreation enter(instance);
20 if (enter.failed())
21 return 0;
22 return enter.functions()->CreateAudioConfig(instance, sample_rate,
23 sample_frame_count);
26 uint32_t RecommendSampleFrameCount_1_0(PP_AudioSampleRate sample_rate,
27 uint32_t requested_sample_frame_count) {
28 return PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_0(sample_rate,
29 requested_sample_frame_count);
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);
43 PP_Bool IsAudioConfig(PP_Resource resource) {
44 EnterResource<PPB_AudioConfig_API> enter(resource, false);
45 return PP_FromBool(enter.succeeded());
48 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) {
49 EnterResource<PPB_AudioConfig_API> enter(config_id, true);
50 if (enter.failed())
51 return PP_AUDIOSAMPLERATE_NONE;
52 return enter.object()->GetSampleRate();
55 uint32_t GetSampleFrameCount(PP_Resource config_id) {
56 EnterResource<PPB_AudioConfig_API> enter(config_id, true);
57 if (enter.failed())
58 return 0;
59 return enter.object()->GetSampleFrameCount();
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);
69 const PPB_AudioConfig_1_0 g_ppb_audio_config_thunk_1_0 = {
70 &CreateStereo16bit,
71 &RecommendSampleFrameCount_1_0,
72 &IsAudioConfig,
73 &GetSampleRate,
74 &GetSampleFrameCount
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
87 } // namespace
89 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() {
90 return &g_ppb_audio_config_thunk_1_0;
93 const PPB_AudioConfig_1_1* GetPPB_AudioConfig_1_1_Thunk() {
94 return &g_ppb_audio_config_thunk_1_1;
97 } // namespace thunk
98 } // namespace ppapi