Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: ppapi/cpp/dev/video_capture_dev.cc

Issue 9372122: Make VideoCapture_Dev backward compatible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/dev/video_capture_dev.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/cpp/dev/video_capture_dev.h" 5 #include "ppapi/cpp/dev/video_capture_dev.h"
6 6
7 #include "ppapi/c/dev/ppb_video_capture_dev.h" 7 #include "ppapi/c/dev/ppb_video_capture_dev.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/completion_callback.h" 9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/dev/device_ref_dev.h" 10 #include "ppapi/cpp/dev/device_ref_dev.h"
11 #include "ppapi/cpp/dev/resource_array_dev.h" 11 #include "ppapi/cpp/dev/resource_array_dev.h"
12 #include "ppapi/cpp/instance.h" 12 #include "ppapi/cpp/instance.h"
13 #include "ppapi/cpp/module.h" 13 #include "ppapi/cpp/module.h"
14 #include "ppapi/cpp/module_impl.h" 14 #include "ppapi/cpp/module_impl.h"
15 15
16 namespace pp { 16 namespace pp {
17 17
18 namespace { 18 namespace {
19 19
20 template <> const char* interface_name<PPB_VideoCapture_Dev>() { 20 template <> const char* interface_name<PPB_VideoCapture_Dev_0_2>() {
21 return PPB_VIDEOCAPTURE_DEV_INTERFACE; 21 return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2;
22 }
23
24 template <> const char* interface_name<PPB_VideoCapture_Dev_0_1>() {
25 return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1;
22 } 26 }
23 27
24 } // namespace 28 } // namespace
25 29
26 struct VideoCapture_Dev::EnumerateDevicesState { 30 struct VideoCapture_Dev::EnumerateDevicesState {
27 EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices, 31 EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices,
28 const CompletionCallback& in_callback, 32 const CompletionCallback& in_callback,
29 VideoCapture_Dev* in_video_capture) 33 VideoCapture_Dev* in_video_capture)
30 : devices_resource(0), 34 : devices_resource(0),
31 devices(in_devices), 35 devices(in_devices),
32 callback(in_callback), 36 callback(in_callback),
33 video_capture(in_video_capture) { 37 video_capture(in_video_capture) {
34 } 38 }
35 39
36 PP_Resource devices_resource; 40 PP_Resource devices_resource;
37 std::vector<DeviceRef_Dev>* devices; 41 std::vector<DeviceRef_Dev>* devices;
38 CompletionCallback callback; 42 CompletionCallback callback;
39 VideoCapture_Dev* video_capture; 43 VideoCapture_Dev* video_capture;
40 }; 44 };
41 45
42 VideoCapture_Dev::VideoCapture_Dev(const Instance& instance) 46 VideoCapture_Dev::VideoCapture_Dev(const Instance& instance)
43 : enum_state_(NULL) { 47 : enum_state_(NULL),
44 if (!has_interface<PPB_VideoCapture_Dev>()) 48 requested_info_(),
45 return; 49 buffer_count_(0) {
46 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev>()->Create( 50 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
47 instance.pp_instance())); 51 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_2>()->Create(
52 instance.pp_instance()));
53 } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
54 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_1>()->Create(
55 instance.pp_instance()));
56 }
48 } 57 }
49 58
50 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource) 59 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource)
51 : Resource(resource), 60 : Resource(resource),
52 enum_state_(NULL) { 61 enum_state_(NULL),
62 requested_info_(),
63 buffer_count_(0) {
53 } 64 }
54 65
55 VideoCapture_Dev::VideoCapture_Dev(const VideoCapture_Dev& other) 66 VideoCapture_Dev::VideoCapture_Dev(const VideoCapture_Dev& other)
56 : Resource(other), 67 : Resource(other),
57 enum_state_(NULL) { 68 enum_state_(NULL),
69 requested_info_(other.requested_info_),
70 buffer_count_(other.buffer_count_) {
58 } 71 }
59 72
60 VideoCapture_Dev::~VideoCapture_Dev() { 73 VideoCapture_Dev::~VideoCapture_Dev() {
61 AbortEnumerateDevices(); 74 AbortEnumerateDevices();
62 } 75 }
63 76
64 VideoCapture_Dev& VideoCapture_Dev::operator=( 77 VideoCapture_Dev& VideoCapture_Dev::operator=(
65 const VideoCapture_Dev& other) { 78 const VideoCapture_Dev& other) {
66 AbortEnumerateDevices(); 79 AbortEnumerateDevices();
67 80
68 Resource::operator=(other); 81 Resource::operator=(other);
82 requested_info_ = other.requested_info_;
83 buffer_count_ = other.buffer_count_;
69 return *this; 84 return *this;
70 } 85 }
71 86
72 // static 87 // static
73 bool VideoCapture_Dev::IsAvailable() { 88 bool VideoCapture_Dev::IsAvailable() {
74 return has_interface<PPB_VideoCapture_Dev>(); 89 return has_interface<PPB_VideoCapture_Dev_0_2>() ||
90 has_interface<PPB_VideoCapture_Dev_0_1>();
75 } 91 }
76 92
77 int32_t VideoCapture_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices, 93 int32_t VideoCapture_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices,
78 const CompletionCallback& callback) { 94 const CompletionCallback& callback) {
79 if (!has_interface<PPB_VideoCapture_Dev>()) 95 if (!has_interface<PPB_VideoCapture_Dev_0_2>())
80 return callback.MayForce(PP_ERROR_NOINTERFACE); 96 return callback.MayForce(PP_ERROR_NOINTERFACE);
81 if (!devices) 97 if (!devices)
82 return callback.MayForce(PP_ERROR_BADARGUMENT); 98 return callback.MayForce(PP_ERROR_BADARGUMENT);
83 if (!callback.pp_completion_callback().func) 99 if (!callback.pp_completion_callback().func)
84 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD); 100 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD);
85 if (enum_state_) 101 if (enum_state_)
86 return callback.MayForce(PP_ERROR_INPROGRESS); 102 return callback.MayForce(PP_ERROR_INPROGRESS);
87 103
88 // It will be deleted in OnEnumerateDevicesComplete(). 104 // It will be deleted in OnEnumerateDevicesComplete().
89 enum_state_ = new EnumerateDevicesState(devices, callback, this); 105 enum_state_ = new EnumerateDevicesState(devices, callback, this);
90 return get_interface<PPB_VideoCapture_Dev>()->EnumerateDevices( 106 return get_interface<PPB_VideoCapture_Dev_0_2>()->EnumerateDevices(
91 pp_resource(), &enum_state_->devices_resource, 107 pp_resource(), &enum_state_->devices_resource,
92 PP_MakeCompletionCallback(&VideoCapture_Dev::OnEnumerateDevicesComplete, 108 PP_MakeCompletionCallback(&VideoCapture_Dev::OnEnumerateDevicesComplete,
93 enum_state_)); 109 enum_state_));
94 } 110 }
95 111
96 int32_t VideoCapture_Dev::Open( 112 int32_t VideoCapture_Dev::Open(
97 const DeviceRef_Dev& device_ref, 113 const DeviceRef_Dev& device_ref,
98 const PP_VideoCaptureDeviceInfo_Dev& requested_info, 114 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
99 uint32_t buffer_count, 115 uint32_t buffer_count,
100 const CompletionCallback& callback) { 116 const CompletionCallback& callback) {
101 if (!has_interface<PPB_VideoCapture_Dev>()) 117 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
102 return callback.MayForce(PP_ERROR_NOINTERFACE); 118 return get_interface<PPB_VideoCapture_Dev_0_2>()->Open(
103 return get_interface<PPB_VideoCapture_Dev>()->Open( 119 pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count,
104 pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count, 120 callback.pp_completion_callback());
105 callback.pp_completion_callback()); 121 } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
122 if (device_ref.is_null()) {
123 requested_info_ = requested_info;
124 buffer_count_ = buffer_count;
125 return callback.MayForce(PP_OK);
126 }
viettrungluu 2012/02/27 19:29:19 Nit: Maybe you should return something other than
yzshen1 2012/02/27 19:38:07 Done.
127 }
128
129 return callback.MayForce(PP_ERROR_NOINTERFACE);
106 } 130 }
107 131
108 int32_t VideoCapture_Dev::StartCapture() { 132 int32_t VideoCapture_Dev::StartCapture() {
109 if (!has_interface<PPB_VideoCapture_Dev>()) 133 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
110 return PP_ERROR_NOINTERFACE; 134 return get_interface<PPB_VideoCapture_Dev_0_2>()->StartCapture(
111 return get_interface<PPB_VideoCapture_Dev>()->StartCapture(pp_resource()); 135 pp_resource());
136 } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
viettrungluu 2012/02/27 19:29:19 "else" unneeded.
yzshen1 2012/02/27 19:38:07 Done.
137 return get_interface<PPB_VideoCapture_Dev_0_1>()->StartCapture(
138 pp_resource(), &requested_info_, buffer_count_);
139 }
140
141 return PP_ERROR_NOINTERFACE;
112 } 142 }
113 143
114 int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) { 144 int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) {
115 if (!has_interface<PPB_VideoCapture_Dev>()) 145 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
116 return PP_ERROR_NOINTERFACE; 146 return get_interface<PPB_VideoCapture_Dev_0_2>()->ReuseBuffer(pp_resource(),
117 return get_interface<PPB_VideoCapture_Dev>()->ReuseBuffer( 147 buffer);
118 pp_resource(), buffer); 148 } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
viettrungluu 2012/02/27 19:29:19 "
yzshen1 2012/02/27 19:38:07 Done.
149 return get_interface<PPB_VideoCapture_Dev_0_1>()->ReuseBuffer(pp_resource(),
150 buffer);
151 }
152
153 return PP_ERROR_NOINTERFACE;
119 } 154 }
120 155
121 int32_t VideoCapture_Dev::StopCapture() { 156 int32_t VideoCapture_Dev::StopCapture() {
122 if (!has_interface<PPB_VideoCapture_Dev>()) 157 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
123 return PP_ERROR_NOINTERFACE; 158 return get_interface<PPB_VideoCapture_Dev_0_2>()->StopCapture(
124 return get_interface<PPB_VideoCapture_Dev>()->StopCapture(pp_resource()); 159 pp_resource());
160 } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
viettrungluu 2012/02/27 19:29:19 "
yzshen1 2012/02/27 19:38:07 Done.
161 return get_interface<PPB_VideoCapture_Dev_0_1>()->StopCapture(
162 pp_resource());
163 }
164
165 return PP_ERROR_NOINTERFACE;
125 } 166 }
126 167
127 void VideoCapture_Dev::Close() { 168 void VideoCapture_Dev::Close() {
128 if (has_interface<PPB_VideoCapture_Dev>()) 169 if (has_interface<PPB_VideoCapture_Dev_0_2>())
129 get_interface<PPB_VideoCapture_Dev>()->Close(pp_resource()); 170 get_interface<PPB_VideoCapture_Dev_0_2>()->Close(pp_resource());
130 } 171 }
131 172
132 void VideoCapture_Dev::AbortEnumerateDevices() { 173 void VideoCapture_Dev::AbortEnumerateDevices() {
133 if (enum_state_) { 174 if (enum_state_) {
134 enum_state_->devices = NULL; 175 enum_state_->devices = NULL;
135 Module::Get()->core()->CallOnMainThread(0, enum_state_->callback, 176 Module::Get()->core()->CallOnMainThread(0, enum_state_->callback,
136 PP_ERROR_ABORTED); 177 PP_ERROR_ABORTED);
137 enum_state_->video_capture = NULL; 178 enum_state_->video_capture = NULL;
138 enum_state_ = NULL; 179 enum_state_ = NULL;
139 } 180 }
(...skipping 23 matching lines...) Expand all
163 204
164 if (need_to_callback) { 205 if (need_to_callback) {
165 enum_state->video_capture->enum_state_ = NULL; 206 enum_state->video_capture->enum_state_ = NULL;
166 enum_state->callback.Run(result); 207 enum_state->callback.Run(result);
167 } 208 }
168 209
169 delete enum_state; 210 delete enum_state;
170 } 211 }
171 212
172 } // namespace pp 213 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/video_capture_dev.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698