Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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/cpp/audio_config.h" |
| 6 | |
| 7 | #include "ppapi/cpp/instance_handle.h" |
| 8 | #include "ppapi/cpp/module.h" |
| 9 | #include "ppapi/cpp/module_impl.h" |
| 10 | |
| 11 | namespace pp { |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | template <> const char* interface_name<PPB_AudioConfig_1_1>() { |
| 16 | return PPB_AUDIO_CONFIG_INTERFACE_1_1; |
| 17 | } |
| 18 | |
| 19 | template <> const char* interface_name<PPB_AudioConfig_1_0>() { |
| 20 | return PPB_AUDIO_CONFIG_INTERFACE_1_0; |
| 21 | } |
| 22 | |
| 23 | } // namespace |
| 24 | |
| 25 | AudioConfig::AudioConfig() |
| 26 | : sample_rate_(PP_AUDIOSAMPLERATE_NONE), |
| 27 | sample_frame_count_(0) { |
| 28 | } |
| 29 | |
| 30 | AudioConfig::AudioConfig(const InstanceHandle& instance, |
| 31 | PP_AudioSampleRate sample_rate, |
| 32 | uint32_t sample_frame_count) |
| 33 | : sample_rate_(sample_rate), |
| 34 | sample_frame_count_(sample_frame_count) { |
| 35 | if (has_interface<PPB_AudioConfig_1_1>()) { |
| 36 | PassRefFromConstructor( |
| 37 | get_interface<PPB_AudioConfig_1_1>()->CreateStereo16Bit( |
| 38 | instance.pp_instance(), sample_rate, sample_frame_count)); |
| 39 | } else if (has_interface<PPB_AudioConfig_1_0>()) { |
| 40 | PassRefFromConstructor( |
| 41 | get_interface<PPB_AudioConfig_1_0>()->CreateStereo16Bit( |
| 42 | instance.pp_instance(), sample_rate, sample_frame_count)); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // static |
| 47 | PP_AudioSampleRate AudioConfig::RecommendSampleRate( |
| 48 | const InstanceHandle& instance) { |
| 49 | if (has_interface<PPB_AudioConfig_1_1>()) { |
| 50 | return get_interface<PPB_AudioConfig_1_1>()-> |
| 51 | RecommendSampleRate(instance.pp_instance()); |
| 52 | } |
| 53 | return PP_AUDIOSAMPLERATE_NONE; |
| 54 | } |
| 55 | |
| 56 | // static |
| 57 | uint32_t AudioConfig::RecommendSampleFrameCount( |
| 58 | const InstanceHandle& instance, |
| 59 | PP_AudioSampleRate sample_rate, |
| 60 | uint32_t requested_sample_frame_count) { |
| 61 | if (has_interface<PPB_AudioConfig_1_1>()) { |
| 62 | return get_interface<PPB_AudioConfig_1_1>()-> |
| 63 | RecommendSampleFrameCount(instance.pp_instance(), |
| 64 | sample_rate, |
| 65 | requested_sample_frame_count); |
| 66 | } |
| 67 | if (has_interface<PPB_AudioConfig_1_0>()) { |
| 68 | return get_interface<PPB_AudioConfig_1_0>()-> |
| 69 | RecommendSampleFrameCount(sample_rate, |
| 70 | requested_sample_frame_count); |
| 71 | } |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | } // namespace pp |