// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "webkit/glue/plugins/pepper_audio.h" #include "base/logging.h" #include "ppapi/c/dev/ppb_audio_dev.h" #include "ppapi/c/dev/ppb_audio_trusted_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "webkit/glue/plugins/pepper_common.h" namespace pepper { namespace { // PPB_AudioConfig ------------------------------------------------------------- uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); PP_Resource CreateStereo16bit(PP_Module module_id, PP_AudioSampleRate_Dev sample_rate, uint32_t sample_frame_count) { PluginModule* module = ResourceTracker::Get()->GetModule(module_id); if (!module) return 0; // TODO(brettw): Currently we don't actually check what the hardware // supports, so just allow sample rates of the "guaranteed working" ones. if (sample_rate != PP_AUDIOSAMPLERATE_44100 && sample_rate != PP_AUDIOSAMPLERATE_48000) return 0; // TODO(brettw): Currently we don't actually query to get a value from the // hardware, so just validate the range. if (RecommendSampleFrameCount(sample_frame_count) != sample_frame_count) return 0; scoped_refptr config(new AudioConfig(module, sample_rate, sample_frame_count)); return config->GetReference(); } uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) { // TODO(brettw) Currently we don't actually query to get a value from the // hardware, so we always return the input for in-range values. if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) return PP_AUDIOMINSAMPLEFRAMECOUNT; if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) return PP_AUDIOMAXSAMPLEFRAMECOUNT; return requested_sample_frame_count; } PP_Bool IsAudioConfig(PP_Resource resource) { scoped_refptr config = Resource::GetAs(resource); return BoolToPPBool(!!config); } PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { scoped_refptr config = Resource::GetAs(config_id); return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE; } uint32_t GetSampleFrameCount(PP_Resource config_id) { scoped_refptr config = Resource::GetAs(config_id); return config ? config->sample_frame_count() : 0; } const PPB_AudioConfig_Dev ppb_audioconfig = { &CreateStereo16bit, &RecommendSampleFrameCount, &IsAudioConfig, &GetSampleRate, &GetSampleFrameCount }; // PPB_Audio ------------------------------------------------------------------- PP_Resource Create(PP_Instance instance_id, PP_Resource config_id, PPB_Audio_Callback user_callback, void* user_data) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return 0; if (!user_callback) return 0; scoped_refptr