Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ppapi / cpp / audio.cc
blob04a3062cb18cdf14a9abf99965077f96a3f6dc70
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.
5 #include "ppapi/cpp/audio.h"
7 #include "ppapi/cpp/instance_handle.h"
8 #include "ppapi/cpp/module_impl.h"
10 namespace pp {
12 namespace {
14 template <> const char* interface_name<PPB_Audio_1_0>() {
15 return PPB_AUDIO_INTERFACE_1_0;
18 template <> const char* interface_name<PPB_Audio_1_1>() {
19 return PPB_AUDIO_INTERFACE_1_1;
22 } // namespace
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));
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));
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()));
53 if (has_interface<PPB_Audio_1_0>()) {
54 return PP_ToBool(get_interface<PPB_Audio_1_0>()->StartPlayback(
55 pp_resource()));
57 return false;
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()));
65 if (has_interface<PPB_Audio_1_0>()) {
66 return PP_ToBool(get_interface<PPB_Audio_1_0>()->StopPlayback(
67 pp_resource()));
69 return false;
72 } // namespace pp