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

Side by Side Diff: ppapi/shared_impl/ppb_video_capture_shared.cc

Issue 11274036: Refactor video capture to new design (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: export Created 8 years, 1 month 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
« no previous file with comments | « ppapi/shared_impl/ppb_video_capture_shared.h ('k') | ppapi/thunk/interfaces_ppb_public_dev.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ppapi/shared_impl/ppb_video_capture_shared.h"
6
7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
10 #include "ppapi/shared_impl/ppb_resource_array_shared.h"
11
12 namespace ppapi {
13
14 PPB_VideoCapture_Shared::PPB_VideoCapture_Shared(PP_Instance instance)
15 : Resource(OBJECT_IS_IMPL, instance),
16 open_state_(BEFORE_OPEN),
17 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
18 devices_(NULL),
19 resource_object_type_(OBJECT_IS_IMPL) {
20 }
21
22 PPB_VideoCapture_Shared::PPB_VideoCapture_Shared(
23 const HostResource& host_resource)
24 : Resource(OBJECT_IS_PROXY, host_resource),
25 open_state_(BEFORE_OPEN),
26 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
27 devices_(NULL),
28 resource_object_type_(OBJECT_IS_PROXY) {
29 }
30
31 PPB_VideoCapture_Shared::~PPB_VideoCapture_Shared() {
32 }
33
34 thunk::PPB_VideoCapture_API* PPB_VideoCapture_Shared::AsPPB_VideoCapture_API() {
35 return this;
36 }
37
38 int32_t PPB_VideoCapture_Shared::EnumerateDevices(
39 PP_Resource* devices,
40 scoped_refptr<TrackedCallback> callback) {
41 if (TrackedCallback::IsPending(enumerate_devices_callback_))
42 return PP_ERROR_INPROGRESS;
43
44 return InternalEnumerateDevices(devices, callback);
45 }
46
47 int32_t PPB_VideoCapture_Shared::Open(
48 const std::string& device_id,
49 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
50 uint32_t buffer_count,
51 scoped_refptr<TrackedCallback> callback) {
52 if (open_state_ != BEFORE_OPEN)
53 return PP_ERROR_FAILED;
54
55 if (TrackedCallback::IsPending(open_callback_))
56 return PP_ERROR_INPROGRESS;
57
58 return InternalOpen(device_id, requested_info, buffer_count, callback);
59 }
60
61 int32_t PPB_VideoCapture_Shared::StartCapture() {
62 if (open_state_ != OPENED ||
63 !SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTING, false)) {
64 return PP_ERROR_FAILED;
65 }
66
67 return InternalStartCapture();
68 }
69
70 int32_t PPB_VideoCapture_Shared::ReuseBuffer(uint32_t buffer) {
71 return InternalReuseBuffer(buffer);
72 }
73
74 int32_t PPB_VideoCapture_Shared::StopCapture() {
75 if (open_state_ != OPENED ||
76 !SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPING, false)) {
77 return PP_ERROR_FAILED;
78 }
79
80 return InternalStopCapture();
81 }
82
83 void PPB_VideoCapture_Shared::Close() {
84 if (open_state_ == CLOSED)
85 return;
86
87 InternalClose();
88 open_state_ = CLOSED;
89
90 if (TrackedCallback::IsPending(open_callback_))
91 open_callback_->PostAbort();
92 }
93
94 int32_t PPB_VideoCapture_Shared::StartCapture0_1(
95 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
96 uint32_t buffer_count) {
97 if (open_state_ == BEFORE_OPEN) {
98 if (TrackedCallback::IsPending(open_callback_))
99 return PP_ERROR_FAILED;
100 open_state_ = OPENED;
101 } else if (open_state_ == CLOSED) {
102 return PP_ERROR_FAILED;
103 }
104
105 if (!SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTING, false))
106 return PP_ERROR_FAILED;
107
108 return InternalStartCapture0_1(requested_info, buffer_count);
109 }
110
111 const std::vector<DeviceRefData>& PPB_VideoCapture_Shared::GetDeviceRefData(
112 ) const {
113 return InternalGetDeviceRefData();
114 }
115
116 void PPB_VideoCapture_Shared::OnEnumerateDevicesComplete(
117 int32_t result,
118 const std::vector<DeviceRefData>& devices) {
119 DCHECK(TrackedCallback::IsPending(enumerate_devices_callback_));
120
121 if (result == PP_OK && devices_) {
122 *devices_ = PPB_DeviceRef_Shared::CreateResourceArray(
123 resource_object_type_, pp_instance(), devices);
124 }
125 devices_ = NULL;
126
127 enumerate_devices_callback_->Run(result);
128 }
129
130 void PPB_VideoCapture_Shared::OnOpenComplete(int32_t result) {
131 if (open_state_ == BEFORE_OPEN && result == PP_OK)
132 open_state_ = OPENED;
133
134 // The callback may have been aborted by Close(), or the open operation is
135 // completed synchronously.
136 if (TrackedCallback::IsPending(open_callback_))
137 open_callback_->Run(result);
138 }
139
140 bool PPB_VideoCapture_Shared::SetStatus(PP_VideoCaptureStatus_Dev status,
141 bool forced) {
142 if (!forced) {
143 switch (status) {
144 case PP_VIDEO_CAPTURE_STATUS_STOPPED:
145 if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPING)
146 return false;
147 break;
148 case PP_VIDEO_CAPTURE_STATUS_STARTING:
149 if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPED)
150 return false;
151 break;
152 case PP_VIDEO_CAPTURE_STATUS_STARTED:
153 switch (status_) {
154 case PP_VIDEO_CAPTURE_STATUS_STARTING:
155 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
156 break;
157 default:
158 return false;
159 }
160 break;
161 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
162 switch (status_) {
163 case PP_VIDEO_CAPTURE_STATUS_STARTING:
164 case PP_VIDEO_CAPTURE_STATUS_STARTED:
165 break;
166 default:
167 return false;
168 }
169 break;
170 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
171 switch (status_) {
172 case PP_VIDEO_CAPTURE_STATUS_STARTING:
173 case PP_VIDEO_CAPTURE_STATUS_STARTED:
174 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
175 break;
176 default:
177 return false;
178 }
179 break;
180 }
181 }
182
183 status_ = status;
184 return true;
185 }
186
187 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_video_capture_shared.h ('k') | ppapi/thunk/interfaces_ppb_public_dev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698