Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ppapi / cpp / media_stream_audio_track.cc
bloba233bbd046f967125cd51b5bf8701bfadb73f385
1 // Copyright 2014 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/media_stream_audio_track.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_media_stream_audio_track.h"
9 #include "ppapi/cpp/audio_buffer.h"
10 #include "ppapi/cpp/completion_callback.h"
11 #include "ppapi/cpp/module_impl.h"
12 #include "ppapi/cpp/var.h"
14 namespace pp {
16 namespace {
18 template <> const char* interface_name<PPB_MediaStreamAudioTrack_0_1>() {
19 return PPB_MEDIASTREAMAUDIOTRACK_INTERFACE_0_1;
22 } // namespace
24 MediaStreamAudioTrack::MediaStreamAudioTrack() {
27 MediaStreamAudioTrack::MediaStreamAudioTrack(
28 const MediaStreamAudioTrack& other) : Resource(other) {
31 MediaStreamAudioTrack::MediaStreamAudioTrack(const Resource& resource)
32 : Resource(resource) {
33 PP_DCHECK(IsMediaStreamAudioTrack(resource));
36 MediaStreamAudioTrack::MediaStreamAudioTrack(PassRef, PP_Resource resource)
37 : Resource(PASS_REF, resource) {
40 MediaStreamAudioTrack::~MediaStreamAudioTrack() {
43 int32_t MediaStreamAudioTrack::Configure(
44 const int32_t attributes[],
45 const CompletionCallback& callback) {
46 if (has_interface<PPB_MediaStreamAudioTrack_0_1>()) {
47 return get_interface<PPB_MediaStreamAudioTrack_0_1>()->Configure(
48 pp_resource(), attributes, callback.pp_completion_callback());
50 return callback.MayForce(PP_ERROR_NOINTERFACE);
53 int32_t MediaStreamAudioTrack::GetAttrib(PP_MediaStreamAudioTrack_Attrib attrib,
54 int32_t* value) {
55 if (has_interface<PPB_MediaStreamAudioTrack_0_1>()) {
56 return get_interface<PPB_MediaStreamAudioTrack_0_1>()->GetAttrib(
57 pp_resource(), attrib, value);
59 return PP_ERROR_NOINTERFACE;
62 std::string MediaStreamAudioTrack::GetId() const {
63 if (has_interface<PPB_MediaStreamAudioTrack_0_1>()) {
64 pp::Var id(PASS_REF, get_interface<PPB_MediaStreamAudioTrack_0_1>()->GetId(
65 pp_resource()));
66 if (id.is_string())
67 return id.AsString();
69 return std::string();
72 bool MediaStreamAudioTrack::HasEnded() const {
73 if (has_interface<PPB_MediaStreamAudioTrack_0_1>()) {
74 return PP_ToBool(get_interface<PPB_MediaStreamAudioTrack_0_1>()->HasEnded(
75 pp_resource()));
77 return true;
80 int32_t MediaStreamAudioTrack::GetBuffer(
81 const CompletionCallbackWithOutput<AudioBuffer>& callback) {
82 if (has_interface<PPB_MediaStreamAudioTrack_0_1>()) {
83 return get_interface<PPB_MediaStreamAudioTrack_0_1>()->GetBuffer(
84 pp_resource(), callback.output(), callback.pp_completion_callback());
86 return callback.MayForce(PP_ERROR_NOINTERFACE);
89 int32_t MediaStreamAudioTrack::RecycleBuffer(const AudioBuffer& buffer) {
90 if (has_interface<PPB_MediaStreamAudioTrack_0_1>()) {
91 return get_interface<PPB_MediaStreamAudioTrack_0_1>()->RecycleBuffer(
92 pp_resource(), buffer.pp_resource());
94 return PP_ERROR_NOINTERFACE;
97 void MediaStreamAudioTrack::Close() {
98 if (has_interface<PPB_MediaStreamAudioTrack_0_1>())
99 get_interface<PPB_MediaStreamAudioTrack_0_1>()->Close(pp_resource());
102 // static
103 bool MediaStreamAudioTrack::IsMediaStreamAudioTrack(const Resource& resource) {
104 if (has_interface<PPB_MediaStreamAudioTrack_0_1>()) {
105 return PP_ToBool(get_interface<PPB_MediaStreamAudioTrack_0_1>()->
106 IsMediaStreamAudioTrack(resource.pp_resource()));
108 return false;
111 } // namespace pp