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.h" | 5 #include "ppapi/cpp/audio.h" |
6 | 6 |
7 #include "ppapi/cpp/instance_handle.h" | 7 #include "ppapi/cpp/instance_handle.h" |
8 #include "ppapi/cpp/module_impl.h" | 8 #include "ppapi/cpp/module_impl.h" |
9 | 9 |
10 namespace pp { | 10 namespace pp { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 template <> const char* interface_name<PPB_Audio_1_0>() { | 14 template <> const char* interface_name<PPB_Audio_1_0>() { |
15 return PPB_AUDIO_INTERFACE_1_0; | 15 return PPB_AUDIO_INTERFACE_1_0; |
16 } | 16 } |
17 | 17 |
| 18 template <> const char* interface_name<PPB_Audio_1_1>() { |
| 19 return PPB_AUDIO_INTERFACE_1_1; |
| 20 } |
| 21 |
18 } // namespace | 22 } // namespace |
19 | 23 |
20 Audio::Audio(const InstanceHandle& instance, | 24 Audio::Audio(const InstanceHandle& instance, |
21 const AudioConfig& config, | 25 const AudioConfig& config, |
22 PPB_Audio_Callback callback, | 26 PPB_Audio_Callback callback, |
23 void* user_data) | 27 void* user_data) |
24 : config_(config) { | 28 : config_(config), |
| 29 use_1_0_interface_(false) { |
| 30 if (has_interface<PPB_Audio_1_1>()) { |
| 31 PassRefFromConstructor(get_interface<PPB_Audio_1_1>()->Create( |
| 32 instance.pp_instance(), config.pp_resource(), callback, user_data)); |
| 33 } |
| 34 } |
| 35 |
| 36 Audio::Audio(const InstanceHandle& instance, |
| 37 const AudioConfig& config, |
| 38 PPB_Audio_Callback_1_0 callback, |
| 39 void* user_data) |
| 40 : config_(config), |
| 41 use_1_0_interface_(true) { |
25 if (has_interface<PPB_Audio_1_0>()) { | 42 if (has_interface<PPB_Audio_1_0>()) { |
26 PassRefFromConstructor(get_interface<PPB_Audio_1_0>()->Create( | 43 PassRefFromConstructor(get_interface<PPB_Audio_1_0>()->Create( |
27 instance.pp_instance(), config.pp_resource(), callback, user_data)); | 44 instance.pp_instance(), config.pp_resource(), callback, user_data)); |
28 } | 45 } |
29 } | 46 } |
30 | 47 |
31 bool Audio::StartPlayback() { | 48 bool Audio::StartPlayback() { |
32 return has_interface<PPB_Audio_1_0>() && | 49 if (has_interface<PPB_Audio_1_1>() && !use_1_0_interface_) { |
33 get_interface<PPB_Audio_1_0>()->StartPlayback(pp_resource()); | 50 return PP_ToBool(get_interface<PPB_Audio_1_1>()->StartPlayback( |
| 51 pp_resource())); |
| 52 } |
| 53 if (has_interface<PPB_Audio_1_0>()) { |
| 54 return PP_ToBool(get_interface<PPB_Audio_1_0>()->StartPlayback( |
| 55 pp_resource())); |
| 56 } |
| 57 return false; |
34 } | 58 } |
35 | 59 |
36 bool Audio::StopPlayback() { | 60 bool Audio::StopPlayback() { |
37 return has_interface<PPB_Audio_1_0>() && | 61 if (has_interface<PPB_Audio_1_1>() && !use_1_0_interface_) { |
38 get_interface<PPB_Audio_1_0>()->StopPlayback(pp_resource()); | 62 return PP_ToBool(get_interface<PPB_Audio_1_1>()->StopPlayback( |
| 63 pp_resource())); |
| 64 } |
| 65 if (has_interface<PPB_Audio_1_0>()) { |
| 66 return PP_ToBool(get_interface<PPB_Audio_1_0>()->StopPlayback( |
| 67 pp_resource())); |
| 68 } |
| 69 return false; |
39 } | 70 } |
40 | 71 |
41 } // namespace pp | 72 } // namespace pp |
OLD | NEW |