Increase MessageAttachmentSet::kMaxDescriptorsPerMessage to 128
[chromium-blink-merge.git] / ppapi / cpp / media_stream_video_track.cc
blob47ff1406f75b8f95deb5383e29ccffc39d8a735c
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_video_track.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_media_stream_video_track.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h"
12 #include "ppapi/cpp/video_frame.h"
14 namespace pp {
16 namespace {
18 template <> const char* interface_name<PPB_MediaStreamVideoTrack_1_0>() {
19 return PPB_MEDIASTREAMVIDEOTRACK_INTERFACE_1_0;
22 template <> const char* interface_name<PPB_MediaStreamVideoTrack_0_1>() {
23 return PPB_MEDIASTREAMVIDEOTRACK_INTERFACE_0_1;
26 } // namespace
28 MediaStreamVideoTrack::MediaStreamVideoTrack() {
31 MediaStreamVideoTrack::MediaStreamVideoTrack(
32 const MediaStreamVideoTrack& other) : Resource(other) {
35 MediaStreamVideoTrack::MediaStreamVideoTrack(const Resource& resource)
36 : Resource(resource) {
37 PP_DCHECK(IsMediaStreamVideoTrack(resource));
40 MediaStreamVideoTrack::MediaStreamVideoTrack(const InstanceHandle& instance) {
41 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
42 PassRefFromConstructor(
43 get_interface<PPB_MediaStreamVideoTrack_1_0>()->Create(
44 instance.pp_instance()));
45 return;
47 PP_DCHECK(false);
50 MediaStreamVideoTrack::MediaStreamVideoTrack(PassRef, PP_Resource resource)
51 : Resource(PASS_REF, resource) {
54 MediaStreamVideoTrack::~MediaStreamVideoTrack() {
57 int32_t MediaStreamVideoTrack::Configure(
58 const int32_t attributes[],
59 const CompletionCallback& callback) {
60 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
61 return get_interface<PPB_MediaStreamVideoTrack_1_0>()->Configure(
62 pp_resource(), attributes, callback.pp_completion_callback());
63 } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) {
64 return get_interface<PPB_MediaStreamVideoTrack_0_1>()->Configure(
65 pp_resource(), attributes, callback.pp_completion_callback());
67 return callback.MayForce(PP_ERROR_NOINTERFACE);
70 int32_t MediaStreamVideoTrack::GetAttrib(PP_MediaStreamVideoTrack_Attrib attrib,
71 int32_t* value) {
72 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
73 return get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetAttrib(
74 pp_resource(), attrib, value);
75 } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) {
76 return get_interface<PPB_MediaStreamVideoTrack_0_1>()->GetAttrib(
77 pp_resource(), attrib, value);
79 return PP_ERROR_NOINTERFACE;
82 std::string MediaStreamVideoTrack::GetId() const {
83 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
84 pp::Var id(PASS_REF, get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetId(
85 pp_resource()));
86 if (id.is_string())
87 return id.AsString();
88 } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) {
89 pp::Var id(PASS_REF, get_interface<PPB_MediaStreamVideoTrack_0_1>()->GetId(
90 pp_resource()));
91 if (id.is_string())
92 return id.AsString();
94 return std::string();
97 bool MediaStreamVideoTrack::HasEnded() const {
98 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
99 return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_1_0>()->HasEnded(
100 pp_resource()));
101 } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) {
102 return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_0_1>()->HasEnded(
103 pp_resource()));
105 return true;
108 int32_t MediaStreamVideoTrack::GetFrame(
109 const CompletionCallbackWithOutput<VideoFrame>& callback) {
110 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
111 return get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetFrame(
112 pp_resource(), callback.output(), callback.pp_completion_callback());
113 } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) {
114 return get_interface<PPB_MediaStreamVideoTrack_0_1>()->GetFrame(
115 pp_resource(), callback.output(), callback.pp_completion_callback());
117 return callback.MayForce(PP_ERROR_NOINTERFACE);
120 int32_t MediaStreamVideoTrack::RecycleFrame(const VideoFrame& frame) {
121 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
122 return get_interface<PPB_MediaStreamVideoTrack_1_0>()->RecycleFrame(
123 pp_resource(), frame.pp_resource());
124 } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) {
125 return get_interface<PPB_MediaStreamVideoTrack_0_1>()->RecycleFrame(
126 pp_resource(), frame.pp_resource());
128 return PP_ERROR_NOINTERFACE;
131 void MediaStreamVideoTrack::Close() {
132 if (has_interface<PPB_MediaStreamVideoTrack_1_0>())
133 get_interface<PPB_MediaStreamVideoTrack_1_0>()->Close(pp_resource());
134 else if (has_interface<PPB_MediaStreamVideoTrack_0_1>())
135 get_interface<PPB_MediaStreamVideoTrack_0_1>()->Close(pp_resource());
139 int32_t MediaStreamVideoTrack::GetEmptyFrame(
140 const CompletionCallbackWithOutput<VideoFrame>& callback) {
141 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
142 return get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetEmptyFrame(
143 pp_resource(), callback.output(), callback.pp_completion_callback());
145 return callback.MayForce(PP_ERROR_NOINTERFACE);
148 int32_t MediaStreamVideoTrack::PutFrame(const VideoFrame& frame) {
149 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
150 return get_interface<PPB_MediaStreamVideoTrack_1_0>()->PutFrame(
151 pp_resource(), frame.pp_resource());
153 return PP_ERROR_NOINTERFACE;
156 bool MediaStreamVideoTrack::IsMediaStreamVideoTrack(const Resource& resource) {
157 if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) {
158 return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_1_0>()->
159 IsMediaStreamVideoTrack(resource.pp_resource()));
160 } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) {
161 return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_0_1>()->
162 IsMediaStreamVideoTrack(resource.pp_resource()));
164 return false;
167 } // namespace pp