Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/cpp/audio_config.h" | 5 #include "ppapi/cpp/audio_config.h" |
| 6 | 6 |
| 7 #include "ppapi/cpp/instance_handle.h" | 7 #include "ppapi/cpp/instance_handle.h" |
| 8 #include "ppapi/cpp/module.h" | 8 #include "ppapi/cpp/module.h" |
| 9 #include "ppapi/cpp/module_impl.h" | 9 #include "ppapi/cpp/module_impl.h" |
| 10 | 10 |
| 11 namespace pp { | 11 namespace pp { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 template <> const char* interface_name<PPB_AudioConfig>() { | 15 template <> const char* interface_name<PPB_AudioConfig_1_1>() { |
| 16 return PPB_AUDIO_CONFIG_INTERFACE; | 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; | |
| 17 } | 21 } |
| 18 | 22 |
| 19 } // namespace | 23 } // namespace |
| 20 | 24 |
| 21 AudioConfig::AudioConfig() | 25 AudioConfig::AudioConfig() |
| 22 : sample_rate_(PP_AUDIOSAMPLERATE_NONE), | 26 : sample_rate_(PP_AUDIOSAMPLERATE_NONE), |
| 23 sample_frame_count_(0) { | 27 sample_frame_count_(0) { |
| 24 } | 28 } |
| 25 | 29 |
| 26 AudioConfig::AudioConfig(const InstanceHandle& instance, | 30 AudioConfig::AudioConfig(const InstanceHandle& instance, |
| 27 PP_AudioSampleRate sample_rate, | 31 PP_AudioSampleRate sample_rate, |
| 28 uint32_t sample_frame_count) | 32 uint32_t sample_frame_count) |
| 29 : sample_rate_(sample_rate), | 33 : sample_rate_(sample_rate), |
| 30 sample_frame_count_(sample_frame_count) { | 34 sample_frame_count_(sample_frame_count) { |
| 31 if (has_interface<PPB_AudioConfig>()) { | 35 if (has_interface<PPB_AudioConfig_1_1>()) { |
| 32 PassRefFromConstructor( | 36 PassRefFromConstructor( |
| 33 get_interface<PPB_AudioConfig>()->CreateStereo16Bit( | 37 get_interface<PPB_AudioConfig_1_1>()->CreateStereo16Bit( |
| 38 instance.pp_instance(), sample_rate, sample_frame_count)); | |
| 39 } | |
| 40 if (has_interface<PPB_AudioConfig_1_0>()) { | |
|
yzshen1
2012/03/06 20:54:34
You need an 'else' here. haha.
viettrungluu
2012/03/06 22:17:21
Done, thanks. I'm apparently incapable of making t
| |
| 41 PassRefFromConstructor( | |
| 42 get_interface<PPB_AudioConfig_1_0>()->CreateStereo16Bit( | |
| 34 instance.pp_instance(), sample_rate, sample_frame_count)); | 43 instance.pp_instance(), sample_rate, sample_frame_count)); |
| 35 } | 44 } |
| 36 } | 45 } |
| 37 | 46 |
| 38 // static | 47 // static |
| 39 PP_AudioSampleRate AudioConfig::RecommendSampleRate( | 48 PP_AudioSampleRate AudioConfig::RecommendSampleRate( |
| 40 const InstanceHandle& instance) { | 49 const InstanceHandle& instance) { |
| 41 if (!has_interface<PPB_AudioConfig>()) | 50 if (has_interface<PPB_AudioConfig_1_1>()) { |
| 42 return PP_AUDIOSAMPLERATE_NONE; | 51 return get_interface<PPB_AudioConfig_1_1>()-> |
| 43 return get_interface<PPB_AudioConfig>()-> | 52 RecommendSampleRate(instance.pp_instance()); |
| 44 RecommendSampleRate(instance.pp_instance()); | 53 } |
| 54 if (has_interface<PPB_AudioConfig_1_0>()) | |
| 55 return get_interface<PPB_AudioConfig_1_0>()->RecommendSampleRate(); | |
| 56 return PP_AUDIOSAMPLERATE_NONE; | |
| 45 } | 57 } |
| 46 | 58 |
| 47 // static | 59 // static |
| 48 uint32_t AudioConfig::RecommendSampleFrameCount( | 60 uint32_t AudioConfig::RecommendSampleFrameCount( |
| 49 const InstanceHandle& instance, | 61 const InstanceHandle& instance, |
| 50 PP_AudioSampleRate sample_rate, | 62 PP_AudioSampleRate sample_rate, |
| 51 uint32_t requested_sample_frame_count) { | 63 uint32_t requested_sample_frame_count) { |
| 52 if (!has_interface<PPB_AudioConfig>()) | 64 if (has_interface<PPB_AudioConfig_1_1>()) { |
| 53 return 0; | 65 return get_interface<PPB_AudioConfig_1_1>()-> |
| 54 return get_interface<PPB_AudioConfig>()-> | 66 RecommendSampleFrameCount(instance.pp_instance(), |
| 55 RecommendSampleFrameCount(instance.pp_instance(), | 67 sample_rate, |
| 56 sample_rate, | 68 requested_sample_frame_count); |
| 57 requested_sample_frame_count); | 69 } |
| 70 if (has_interface<PPB_AudioConfig_1_0>()) { | |
| 71 return get_interface<PPB_AudioConfig_1_0>()-> | |
| 72 RecommendSampleFrameCount(instance.pp_instance(), | |
| 73 sample_rate, | |
| 74 requested_sample_frame_count); | |
| 75 } | |
| 76 return 0; | |
| 58 } | 77 } |
| 59 | 78 |
| 60 } // namespace pp | 79 } // namespace pp |
| 61 | |
| OLD | NEW |