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.h"
6
7 #include "ppapi/cpp/instance_handle.h"
8 #include "ppapi/cpp/module_impl.h"
9
10 namespace pp {
11
12 namespace {
13
interface_name()14 template <> const char* interface_name<PPB_Audio_1_0>() {
15 return PPB_AUDIO_INTERFACE_1_0;
16 }
17
interface_name()18 template <> const char* interface_name<PPB_Audio_1_1>() {
19 return PPB_AUDIO_INTERFACE_1_1;
20 }
21
22 } // namespace
23
Audio(const InstanceHandle & instance,const AudioConfig & config,PPB_Audio_Callback callback,void * user_data)24 Audio::Audio(const InstanceHandle& instance,
25 const AudioConfig& config,
26 PPB_Audio_Callback callback,
27 void* user_data)
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
Audio(const InstanceHandle & instance,const AudioConfig & config,PPB_Audio_Callback_1_0 callback,void * user_data)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) {
42 if (has_interface<PPB_Audio_1_0>()) {
43 PassRefFromConstructor(get_interface<PPB_Audio_1_0>()->Create(
44 instance.pp_instance(), config.pp_resource(), callback, user_data));
45 }
46 }
47
StartPlayback()48 bool Audio::StartPlayback() {
49 if (has_interface<PPB_Audio_1_1>() && !use_1_0_interface_) {
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;
58 }
59
StopPlayback()60 bool Audio::StopPlayback() {
61 if (has_interface<PPB_Audio_1_1>() && !use_1_0_interface_) {
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;
70 }
71
72 } // namespace pp
73