• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "ppapi/cpp/media_stream_audio_track.h"
6 
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"
13 
14 namespace pp {
15 
16 namespace {
17 
interface_name()18 template <> const char* interface_name<PPB_MediaStreamAudioTrack_0_1>() {
19   return PPB_MEDIASTREAMAUDIOTRACK_INTERFACE_0_1;
20 }
21 
22 }  // namespace
23 
MediaStreamAudioTrack()24 MediaStreamAudioTrack::MediaStreamAudioTrack() {
25 }
26 
MediaStreamAudioTrack(const MediaStreamAudioTrack & other)27 MediaStreamAudioTrack::MediaStreamAudioTrack(
28     const MediaStreamAudioTrack& other) : Resource(other) {
29 }
30 
MediaStreamAudioTrack(const Resource & resource)31 MediaStreamAudioTrack::MediaStreamAudioTrack(const Resource& resource)
32     : Resource(resource) {
33   PP_DCHECK(IsMediaStreamAudioTrack(resource));
34 }
35 
MediaStreamAudioTrack(PassRef,PP_Resource resource)36 MediaStreamAudioTrack::MediaStreamAudioTrack(PassRef, PP_Resource resource)
37     : Resource(PASS_REF, resource) {
38 }
39 
~MediaStreamAudioTrack()40 MediaStreamAudioTrack::~MediaStreamAudioTrack() {
41 }
42 
Configure(const int32_t attributes[],const CompletionCallback & callback)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());
49   }
50   return callback.MayForce(PP_ERROR_NOINTERFACE);
51 }
52 
GetAttrib(PP_MediaStreamAudioTrack_Attrib attrib,int32_t * value)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);
58   }
59   return PP_ERROR_NOINTERFACE;
60 }
61 
GetId() const62 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();
68   }
69   return std::string();
70 }
71 
HasEnded() const72 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()));
76   }
77   return true;
78 }
79 
GetBuffer(const CompletionCallbackWithOutput<AudioBuffer> & callback)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());
85   }
86   return callback.MayForce(PP_ERROR_NOINTERFACE);
87 }
88 
RecycleBuffer(const AudioBuffer & buffer)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());
93   }
94   return PP_ERROR_NOINTERFACE;
95 }
96 
Close()97 void MediaStreamAudioTrack::Close() {
98   if (has_interface<PPB_MediaStreamAudioTrack_0_1>())
99     get_interface<PPB_MediaStreamAudioTrack_0_1>()->Close(pp_resource());
100 }
101 
102 // static
IsMediaStreamAudioTrack(const Resource & resource)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()));
107   }
108   return false;
109 }
110 
111 }  // namespace pp
112