| OLD | NEW |
| 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_video_capture_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "ppapi/c/dev/pp_video_capture_dev.h" | 13 #include "ppapi/c/dev/pp_video_capture_dev.h" |
| 12 #include "ppapi/c/dev/ppb_video_capture_dev.h" | 14 #include "ppapi/c/dev/ppb_video_capture_dev.h" |
| 13 #include "ppapi/c/pp_completion_callback.h" | 15 #include "ppapi/c/pp_completion_callback.h" |
| 14 #include "ppapi/c/pp_errors.h" | 16 #include "ppapi/c/pp_errors.h" |
| 15 #include "ppapi/shared_impl/ppapi_globals.h" | 17 #include "ppapi/shared_impl/ppapi_globals.h" |
| 18 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
| 16 #include "ppapi/shared_impl/resource_tracker.h" | 19 #include "ppapi/shared_impl/resource_tracker.h" |
| 20 #include "ppapi/shared_impl/tracked_callback.h" |
| 17 #include "ppapi/thunk/enter.h" | 21 #include "ppapi/thunk/enter.h" |
| 18 #include "webkit/plugins/ppapi/common.h" | 22 #include "webkit/plugins/ppapi/common.h" |
| 19 #include "webkit/plugins/ppapi/plugin_module.h" | 23 #include "webkit/plugins/ppapi/plugin_module.h" |
| 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 21 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 25 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| 22 #include "webkit/plugins/ppapi/resource_helper.h" | 26 #include "webkit/plugins/ppapi/resource_helper.h" |
| 23 | 27 |
| 28 using ppapi::DeviceRefData; |
| 24 using ppapi::PpapiGlobals; | 29 using ppapi::PpapiGlobals; |
| 25 using ppapi::thunk::EnterResourceNoLock; | 30 using ppapi::thunk::EnterResourceNoLock; |
| 26 using ppapi::thunk::PPB_Buffer_API; | 31 using ppapi::thunk::PPB_Buffer_API; |
| 27 using ppapi::thunk::PPB_VideoCapture_API; | 32 using ppapi::thunk::PPB_VideoCapture_API; |
| 33 using ppapi::TrackedCallback; |
| 28 | 34 |
| 29 namespace { | 35 namespace { |
| 30 | 36 |
| 31 // Maximum number of buffers to actually allocate. | 37 // Maximum number of buffers to actually allocate. |
| 32 const uint32_t kMaxBuffers = 20; | 38 const uint32_t kMaxBuffers = 20; |
| 33 | 39 |
| 34 } // namespace | 40 } // namespace |
| 35 | 41 |
| 36 namespace webkit { | 42 namespace webkit { |
| 37 namespace ppapi { | 43 namespace ppapi { |
| 38 | 44 |
| 39 PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PP_Instance instance) | 45 PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PP_Instance instance) |
| 40 : Resource(instance), | 46 : PPB_VideoCapture_Shared(instance), |
| 41 buffer_count_hint_(0), | 47 buffer_count_hint_(0), |
| 42 ppp_videocapture_(NULL), | 48 ppp_videocapture_(NULL), |
| 43 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED), | 49 capability_() { |
| 44 is_dead_(false) { | |
| 45 } | 50 } |
| 46 | 51 |
| 47 PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() { | 52 PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() { |
| 53 Close(); |
| 48 } | 54 } |
| 49 | 55 |
| 50 bool PPB_VideoCapture_Impl::Init() { | 56 bool PPB_VideoCapture_Impl::Init() { |
| 51 DCHECK(!is_dead_); | |
| 52 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); | 57 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 53 if (!instance) | 58 if (!instance) |
| 54 return false; | 59 return false; |
| 55 ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>( | 60 ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>( |
| 56 instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); | 61 instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); |
| 57 if (!ppp_videocapture_) | 62 if (!ppp_videocapture_) |
| 58 return false; | 63 return false; |
| 59 | 64 |
| 60 platform_video_capture_.reset( | 65 return true; |
| 61 instance->delegate()->CreateVideoCapture(this)); | |
| 62 return !!platform_video_capture_.get(); | |
| 63 } | |
| 64 | |
| 65 PPB_VideoCapture_API* PPB_VideoCapture_Impl::AsPPB_VideoCapture_API() { | |
| 66 return this; | |
| 67 } | |
| 68 | |
| 69 void PPB_VideoCapture_Impl::LastPluginRefWasDeleted() { | |
| 70 if (platform_video_capture_.get()) | |
| 71 StopCapture(); | |
| 72 DCHECK(buffers_.empty()); | |
| 73 ppp_videocapture_ = NULL; | |
| 74 is_dead_ = true; | |
| 75 | |
| 76 ::ppapi::Resource::LastPluginRefWasDeleted(); | |
| 77 } | |
| 78 | |
| 79 int32_t PPB_VideoCapture_Impl::StartCapture( | |
| 80 const PP_VideoCaptureDeviceInfo_Dev& requested_info, | |
| 81 uint32_t buffer_count) { | |
| 82 DCHECK(!is_dead_); | |
| 83 switch (status_) { | |
| 84 case PP_VIDEO_CAPTURE_STATUS_STARTING: | |
| 85 case PP_VIDEO_CAPTURE_STATUS_STARTED: | |
| 86 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | |
| 87 default: | |
| 88 return PP_ERROR_FAILED; | |
| 89 case PP_VIDEO_CAPTURE_STATUS_STOPPED: | |
| 90 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | |
| 91 break; | |
| 92 } | |
| 93 DCHECK(buffers_.empty()); | |
| 94 | |
| 95 // Clamp the buffer count to between 1 and |kMaxBuffers|. | |
| 96 buffer_count_hint_ = std::min(std::max(buffer_count, 1U), kMaxBuffers); | |
| 97 media::VideoCapture::VideoCaptureCapability capability = { | |
| 98 requested_info.width, | |
| 99 requested_info.height, | |
| 100 requested_info.frames_per_second, | |
| 101 0, // ignored. | |
| 102 media::VideoFrame::I420, | |
| 103 false, // ignored | |
| 104 }; | |
| 105 status_ = PP_VIDEO_CAPTURE_STATUS_STARTING; | |
| 106 AddRef(); // Balanced in |OnRemoved()|. | |
| 107 platform_video_capture_->StartCapture(this, capability); | |
| 108 return PP_OK; | |
| 109 } | |
| 110 | |
| 111 int32_t PPB_VideoCapture_Impl::ReuseBuffer(uint32_t buffer) { | |
| 112 DCHECK(!is_dead_); | |
| 113 if (buffer >= buffers_.size() || !buffers_[buffer].in_use) | |
| 114 return PP_ERROR_BADARGUMENT; | |
| 115 buffers_[buffer].in_use = false; | |
| 116 return PP_OK; | |
| 117 } | |
| 118 | |
| 119 int32_t PPB_VideoCapture_Impl::StopCapture() { | |
| 120 DCHECK(!is_dead_); | |
| 121 switch (status_) { | |
| 122 case PP_VIDEO_CAPTURE_STATUS_STOPPED: | |
| 123 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | |
| 124 default: | |
| 125 return PP_ERROR_FAILED; | |
| 126 case PP_VIDEO_CAPTURE_STATUS_STARTING: | |
| 127 case PP_VIDEO_CAPTURE_STATUS_STARTED: | |
| 128 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | |
| 129 break; | |
| 130 } | |
| 131 ReleaseBuffers(); | |
| 132 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; | |
| 133 platform_video_capture_->StopCapture(this); | |
| 134 return PP_OK; | |
| 135 } | 66 } |
| 136 | 67 |
| 137 void PPB_VideoCapture_Impl::OnStarted(media::VideoCapture* capture) { | 68 void PPB_VideoCapture_Impl::OnStarted(media::VideoCapture* capture) { |
| 138 if (is_dead_) | 69 if (SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTED, false)) |
| 139 return; | 70 SendStatus(); |
| 140 | |
| 141 switch (status_) { | |
| 142 case PP_VIDEO_CAPTURE_STATUS_STARTING: | |
| 143 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | |
| 144 break; | |
| 145 case PP_VIDEO_CAPTURE_STATUS_STOPPED: | |
| 146 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | |
| 147 case PP_VIDEO_CAPTURE_STATUS_STARTED: | |
| 148 default: | |
| 149 return; | |
| 150 } | |
| 151 status_ = PP_VIDEO_CAPTURE_STATUS_STARTED; | |
| 152 SendStatus(); | |
| 153 } | 71 } |
| 154 | 72 |
| 155 void PPB_VideoCapture_Impl::OnStopped(media::VideoCapture* capture) { | 73 void PPB_VideoCapture_Impl::OnStopped(media::VideoCapture* capture) { |
| 156 if (is_dead_) | 74 if (SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, false)) |
| 157 return; | 75 SendStatus(); |
| 158 | |
| 159 switch (status_) { | |
| 160 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | |
| 161 break; | |
| 162 case PP_VIDEO_CAPTURE_STATUS_STARTING: | |
| 163 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | |
| 164 case PP_VIDEO_CAPTURE_STATUS_STOPPED: | |
| 165 case PP_VIDEO_CAPTURE_STATUS_STARTED: | |
| 166 default: | |
| 167 return; | |
| 168 } | |
| 169 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED; | |
| 170 SendStatus(); | |
| 171 } | 76 } |
| 172 | 77 |
| 173 void PPB_VideoCapture_Impl::OnPaused(media::VideoCapture* capture) { | 78 void PPB_VideoCapture_Impl::OnPaused(media::VideoCapture* capture) { |
| 174 if (is_dead_) | 79 if (SetStatus(PP_VIDEO_CAPTURE_STATUS_PAUSED, false)) |
| 175 return; | 80 SendStatus(); |
| 176 | |
| 177 switch (status_) { | |
| 178 case PP_VIDEO_CAPTURE_STATUS_STARTING: | |
| 179 case PP_VIDEO_CAPTURE_STATUS_STARTED: | |
| 180 break; | |
| 181 case PP_VIDEO_CAPTURE_STATUS_STOPPED: | |
| 182 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | |
| 183 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | |
| 184 default: | |
| 185 return; | |
| 186 } | |
| 187 status_ = PP_VIDEO_CAPTURE_STATUS_PAUSED; | |
| 188 SendStatus(); | |
| 189 } | 81 } |
| 190 | 82 |
| 191 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture, | 83 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture, |
| 192 int error_code) { | 84 int error_code) { |
| 193 if (is_dead_) | |
| 194 return; | |
| 195 | |
| 196 // Today, the media layer only sends "1" as an error. | 85 // Today, the media layer only sends "1" as an error. |
| 197 DCHECK(error_code == 1); | 86 DCHECK(error_code == 1); |
| 198 // It either comes because some error was detected while starting (e.g. 2 | 87 // It either comes because some error was detected while starting (e.g. 2 |
| 199 // conflicting "master" resolution), or because the browser failed to start | 88 // conflicting "master" resolution), or because the browser failed to start |
| 200 // the capture. | 89 // the capture. |
| 201 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED; | 90 SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true); |
| 202 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED); | 91 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED); |
| 203 } | 92 } |
| 204 | 93 |
| 205 void PPB_VideoCapture_Impl::OnRemoved(media::VideoCapture* capture) { | 94 void PPB_VideoCapture_Impl::OnRemoved(media::VideoCapture* capture) { |
| 206 Release(); | |
| 207 } | 95 } |
| 208 | 96 |
| 209 void PPB_VideoCapture_Impl::OnBufferReady( | 97 void PPB_VideoCapture_Impl::OnBufferReady( |
| 210 media::VideoCapture* capture, | 98 media::VideoCapture* capture, |
| 211 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { | 99 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { |
| 212 if (!is_dead_) { | 100 DCHECK(buffer.get()); |
| 213 DCHECK(buffer.get()); | 101 for (uint32_t i = 0; i < buffers_.size(); ++i) { |
| 214 for (uint32_t i = 0; i < buffers_.size(); ++i) { | 102 if (!buffers_[i].in_use) { |
| 215 if (!buffers_[i].in_use) { | 103 // TODO(ihf): Switch to a size calculation based on stride. |
| 216 // TODO(ihf): Switch to a size calculation based on stride. | 104 // Stride is filled out now but not more meaningful than size |
| 217 // Stride is filled out now but not more meaningful than size | 105 // until wjia unifies VideoFrameBuffer and media::VideoFrame. |
| 218 // until wjia unifies VideoFrameBuffer and media::VideoFrame. | 106 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), |
| 219 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), | 107 buffer->buffer_size); |
| 220 buffer->buffer_size); | 108 memcpy(buffers_[i].data, buffer->memory_pointer, size); |
| 221 memcpy(buffers_[i].data, buffer->memory_pointer, size); | 109 buffers_[i].in_use = true; |
| 222 buffers_[i].in_use = true; | 110 platform_video_capture_->FeedBuffer(buffer); |
| 223 platform_video_capture_->FeedBuffer(buffer); | 111 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i); |
| 224 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i); | 112 return; |
| 225 return; | |
| 226 } | |
| 227 } | 113 } |
| 228 } | 114 } |
| 229 // Even after we have stopped and are dead we have to return buffers that | |
| 230 // are in flight to us. Otherwise VideoCaptureController will not tear down. | |
| 231 platform_video_capture_->FeedBuffer(buffer); | |
| 232 } | 115 } |
| 233 | 116 |
| 234 void PPB_VideoCapture_Impl::OnDeviceInfoReceived( | 117 void PPB_VideoCapture_Impl::OnDeviceInfoReceived( |
| 235 media::VideoCapture* capture, | 118 media::VideoCapture* capture, |
| 236 const media::VideoCaptureParams& device_info) { | 119 const media::VideoCaptureParams& device_info) { |
| 237 // No need to call |ReleaseBuffers()|: if we're dead, |StopCapture()| should | |
| 238 // already have been called. | |
| 239 if (is_dead_) | |
| 240 return; | |
| 241 | |
| 242 PP_VideoCaptureDeviceInfo_Dev info = { | 120 PP_VideoCaptureDeviceInfo_Dev info = { |
| 243 device_info.width, | 121 device_info.width, |
| 244 device_info.height, | 122 device_info.height, |
| 245 device_info.frame_per_second | 123 device_info.frame_per_second |
| 246 }; | 124 }; |
| 247 ReleaseBuffers(); | 125 ReleaseBuffers(); |
| 248 | 126 |
| 249 // Allocate buffers. We keep a reference to them, that is released in | 127 // Allocate buffers. We keep a reference to them, that is released in |
| 250 // ReleaseBuffers. | 128 // ReleaseBuffers. |
| 251 // YUV 4:2:0 | 129 // YUV 4:2:0 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 270 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resources[i]); | 148 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resources[i]); |
| 271 break; | 149 break; |
| 272 } | 150 } |
| 273 buffers_.push_back(info); | 151 buffers_.push_back(info); |
| 274 } | 152 } |
| 275 | 153 |
| 276 if (buffers_.empty()) { | 154 if (buffers_.empty()) { |
| 277 // We couldn't allocate/map buffers at all. Send an error and stop the | 155 // We couldn't allocate/map buffers at all. Send an error and stop the |
| 278 // capture. | 156 // capture. |
| 279 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_NOMEMORY); | 157 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_NOMEMORY); |
| 280 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; | 158 SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPING, true); |
| 281 platform_video_capture_->StopCapture(this); | 159 platform_video_capture_->StopCapture(this); |
| 282 return; | 160 return; |
| 283 } | 161 } |
| 284 | 162 |
| 285 ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info, | 163 ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info, |
| 286 buffers_.size(), resources.get()); | 164 buffers_.size(), resources.get()); |
| 287 } | 165 } |
| 288 | 166 |
| 167 void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture, |
| 168 bool succeeded) { |
| 169 DCHECK(capture == platform_video_capture_.get()); |
| 170 |
| 171 OnOpenComplete(succeeded ? PP_OK : PP_ERROR_FAILED); |
| 172 } |
| 173 |
| 174 int32_t PPB_VideoCapture_Impl::InternalEnumerateDevices( |
| 175 PP_Resource* devices, |
| 176 PP_CompletionCallback callback) { |
| 177 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 178 if (!instance) |
| 179 return PP_ERROR_FAILED; |
| 180 |
| 181 devices_ = devices; |
| 182 enumerate_devices_callback_ = new TrackedCallback(this, callback); |
| 183 instance->delegate()->EnumerateDevices( |
| 184 PP_DEVICETYPE_DEV_VIDEOCAPTURE, |
| 185 base::Bind(&PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc, |
| 186 AsWeakPtr())); |
| 187 return PP_OK_COMPLETIONPENDING; |
| 188 } |
| 189 |
| 190 int32_t PPB_VideoCapture_Impl::InternalOpen( |
| 191 const std::string& device_id, |
| 192 const PP_VideoCaptureDeviceInfo_Dev& requested_info, |
| 193 uint32_t buffer_count, |
| 194 PP_CompletionCallback callback) { |
| 195 // It is able to complete synchronously if the default device is used. |
| 196 bool sync_completion = device_id.empty(); |
| 197 |
| 198 if (!callback.func && !sync_completion) |
| 199 return PP_ERROR_BLOCKS_MAIN_THREAD; |
| 200 |
| 201 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 202 if (!instance) |
| 203 return PP_ERROR_FAILED; |
| 204 |
| 205 SetRequestedInfo(requested_info, buffer_count); |
| 206 |
| 207 DCHECK(!platform_video_capture_.get()); |
| 208 platform_video_capture_ = |
| 209 instance->delegate()->CreateVideoCapture(device_id, this); |
| 210 |
| 211 if (sync_completion) { |
| 212 OnInitialized(platform_video_capture_.get(), true); |
| 213 return PP_OK; |
| 214 } else { |
| 215 open_callback_ = new TrackedCallback(this, callback); |
| 216 return PP_OK_COMPLETIONPENDING; |
| 217 } |
| 218 } |
| 219 |
| 220 int32_t PPB_VideoCapture_Impl::InternalStartCapture() { |
| 221 DCHECK(buffers_.empty()); |
| 222 platform_video_capture_->StartCapture(this, capability_); |
| 223 return PP_OK; |
| 224 } |
| 225 |
| 226 int32_t PPB_VideoCapture_Impl::InternalReuseBuffer(uint32_t buffer) { |
| 227 if (buffer >= buffers_.size() || !buffers_[buffer].in_use) |
| 228 return PP_ERROR_BADARGUMENT; |
| 229 buffers_[buffer].in_use = false; |
| 230 return PP_OK; |
| 231 } |
| 232 |
| 233 int32_t PPB_VideoCapture_Impl::InternalStopCapture() { |
| 234 ReleaseBuffers(); |
| 235 platform_video_capture_->StopCapture(this); |
| 236 return PP_OK; |
| 237 } |
| 238 |
| 239 void PPB_VideoCapture_Impl::InternalClose() { |
| 240 StopCapture(); |
| 241 DCHECK(buffers_.empty()); |
| 242 |
| 243 DetachPlatformVideoCapture(); |
| 244 } |
| 245 |
| 246 int32_t PPB_VideoCapture_Impl::InternalStartCapture0_1( |
| 247 const PP_VideoCaptureDeviceInfo_Dev& requested_info, |
| 248 uint32_t buffer_count) { |
| 249 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 250 if (!instance) { |
| 251 SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true); |
| 252 return PP_ERROR_FAILED; |
| 253 } |
| 254 |
| 255 DCHECK(buffers_.empty()); |
| 256 |
| 257 SetRequestedInfo(requested_info, buffer_count); |
| 258 |
| 259 DetachPlatformVideoCapture(); |
| 260 platform_video_capture_ = |
| 261 instance->delegate()->CreateVideoCapture("", this); |
| 262 platform_video_capture_->StartCapture(this, capability_); |
| 263 |
| 264 return PP_OK; |
| 265 } |
| 266 |
| 267 const std::vector<DeviceRefData>& |
| 268 PPB_VideoCapture_Impl::InternalGetDeviceRefData() const { |
| 269 return devices_data_; |
| 270 } |
| 271 |
| 289 void PPB_VideoCapture_Impl::ReleaseBuffers() { | 272 void PPB_VideoCapture_Impl::ReleaseBuffers() { |
| 290 DCHECK(!is_dead_); | |
| 291 ::ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); | 273 ::ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); |
| 292 for (size_t i = 0; i < buffers_.size(); ++i) { | 274 for (size_t i = 0; i < buffers_.size(); ++i) { |
| 293 buffers_[i].buffer->Unmap(); | 275 buffers_[i].buffer->Unmap(); |
| 294 tracker->ReleaseResource(buffers_[i].buffer->pp_resource()); | 276 tracker->ReleaseResource(buffers_[i].buffer->pp_resource()); |
| 295 } | 277 } |
| 296 buffers_.clear(); | 278 buffers_.clear(); |
| 297 } | 279 } |
| 298 | 280 |
| 299 void PPB_VideoCapture_Impl::SendStatus() { | 281 void PPB_VideoCapture_Impl::SendStatus() { |
| 300 DCHECK(!is_dead_); | |
| 301 ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_); | 282 ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_); |
| 302 } | 283 } |
| 303 | 284 |
| 285 void PPB_VideoCapture_Impl::SetRequestedInfo( |
| 286 const PP_VideoCaptureDeviceInfo_Dev& device_info, |
| 287 uint32_t buffer_count) { |
| 288 // Clamp the buffer count to between 1 and |kMaxBuffers|. |
| 289 buffer_count_hint_ = std::min(std::max(buffer_count, 1U), kMaxBuffers); |
| 290 |
| 291 capability_.width = device_info.width; |
| 292 capability_.height = device_info.height; |
| 293 capability_.max_fps = device_info.frames_per_second; |
| 294 capability_.expected_capture_delay = 0; // Ignored. |
| 295 capability_.raw_type = media::VideoFrame::I420; |
| 296 capability_.interlaced = false; // Ignored. |
| 297 } |
| 298 |
| 299 void PPB_VideoCapture_Impl::DetachPlatformVideoCapture() { |
| 300 if (platform_video_capture_.get()) { |
| 301 platform_video_capture_->DetachEventHandler(); |
| 302 platform_video_capture_ = NULL; |
| 303 } |
| 304 } |
| 305 |
| 306 void PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc( |
| 307 int request_id, |
| 308 bool succeeded, |
| 309 const std::vector<DeviceRefData>& devices) { |
| 310 devices_data_.clear(); |
| 311 if (succeeded) |
| 312 devices_data_ = devices; |
| 313 |
| 314 OnEnumerateDevicesComplete(succeeded ? PP_OK : PP_ERROR_FAILED, devices); |
| 315 } |
| 316 |
| 304 PPB_VideoCapture_Impl::BufferInfo::BufferInfo() | 317 PPB_VideoCapture_Impl::BufferInfo::BufferInfo() |
| 305 : in_use(false), | 318 : in_use(false), |
| 306 data(NULL), | 319 data(NULL), |
| 307 buffer() { | 320 buffer() { |
| 308 } | 321 } |
| 309 | 322 |
| 310 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { | 323 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { |
| 311 } | 324 } |
| 312 | 325 |
| 313 } // namespace ppapi | 326 } // namespace ppapi |
| 314 } // namespace webkit | 327 } // namespace webkit |
| OLD | NEW |