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. 4 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" 10 11 namespace ppapi { 12 namespace thunk { 13 14 namespace { 15 16 PP_Resource CreateStereo16bit(PP_Instance instance, 17 PP_AudioSampleRate sample_rate, 18 uint32_t sample_frame_count) { 19 VLOG(4) << "PPB_AudioConfig::CreateStereo16Bit()"; 20 EnterResourceCreation enter(instance); 21 if (enter.failed()) 22 return 0; 23 return enter.functions()->CreateAudioConfig(instance, sample_rate, 24 sample_frame_count); 25 } 26 27 uint32_t RecommendSampleFrameCount_1_0(PP_AudioSampleRate sample_rate, 28 uint32_t requested_sample_frame_count) { 29 VLOG(4) << "PPB_AudioConfig::RecommendSampleFrameCount()"; 30 return PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_0(sample_rate, 31 requested_sample_frame_count); 32 } 33 34 uint32_t RecommendSampleFrameCount_1_1(PP_Instance instance, 35 PP_AudioSampleRate sample_rate, 36 uint32_t requested_sample_frame_count) { 37 VLOG(4) << "PPB_AudioConfig::RecommendSampleFrameCount()"; 38 EnterInstance enter(instance); 39 if (enter.failed()) 40 return 0; 41 return PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_1(instance, 42 sample_rate, requested_sample_frame_count); 43 } 44 45 46 PP_Bool IsAudioConfig(PP_Resource resource) { 47 VLOG(4) << "PPB_AudioConfig::IsAudioConfig()"; 48 EnterResource<PPB_AudioConfig_API> enter(resource, false); 49 return PP_FromBool(enter.succeeded()); 50 } 51 52 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { 53 VLOG(4) << "PPB_AudioConfig::GetSampleRate()"; 54 EnterResource<PPB_AudioConfig_API> enter(config_id, true); 55 if (enter.failed()) 56 return PP_AUDIOSAMPLERATE_NONE; 57 return enter.object()->GetSampleRate(); 58 } 59 60 uint32_t GetSampleFrameCount(PP_Resource config_id) { 61 VLOG(4) << "PPB_AudioConfig::GetSampleFrameCount()"; 62 EnterResource<PPB_AudioConfig_API> enter(config_id, true); 63 if (enter.failed()) 64 return 0; 65 return enter.object()->GetSampleFrameCount(); 66 } 67 68 PP_AudioSampleRate RecommendSampleRate(PP_Instance instance) { 69 VLOG(4) << "PPB_AudioConfig::RecommendSampleRate()"; 70 EnterInstance enter(instance); 71 if (enter.failed()) 72 return PP_AUDIOSAMPLERATE_NONE; 73 return PPB_AudioConfig_Shared::RecommendSampleRate(instance); 74 } 75 76 const PPB_AudioConfig_1_0 g_ppb_audio_config_thunk_1_0 = { 77 &CreateStereo16bit, 78 &RecommendSampleFrameCount_1_0, 79 &IsAudioConfig, 80 &GetSampleRate, 81 &GetSampleFrameCount 82 }; 83 84 const PPB_AudioConfig_1_1 g_ppb_audio_config_thunk_1_1 = { 85 &CreateStereo16bit, 86 &RecommendSampleFrameCount_1_1, 87 &IsAudioConfig, 88 &GetSampleRate, 89 &GetSampleFrameCount, 90 &RecommendSampleRate 91 }; 92 93 94 } // namespace 95 96 const PPB_AudioConfig_1_0* GetPPB_AudioConfig_1_0_Thunk() { 97 return &g_ppb_audio_config_thunk_1_0; 98 } 99 100 const PPB_AudioConfig_1_1* GetPPB_AudioConfig_1_1_Thunk() { 101 return &g_ppb_audio_config_thunk_1_1; 102 } 103 104 } // namespace thunk 105 } // namespace ppapi 106