| OLD | NEW |
| 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/proxy/video_decoder_resource.h" | 5 #include "ppapi/proxy/video_decoder_resource.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 #include "gpu/command_buffer/common/mailbox.h" | 10 #include "gpu/command_buffer/common/mailbox.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 int32_t VideoDecoderResource::Initialize( | 101 int32_t VideoDecoderResource::Initialize( |
| 102 PP_Resource graphics_context, | 102 PP_Resource graphics_context, |
| 103 PP_VideoProfile profile, | 103 PP_VideoProfile profile, |
| 104 PP_HardwareAcceleration acceleration, | 104 PP_HardwareAcceleration acceleration, |
| 105 scoped_refptr<TrackedCallback> callback) { | 105 scoped_refptr<TrackedCallback> callback) { |
| 106 if (initialized_) | 106 if (initialized_) |
| 107 return PP_ERROR_FAILED; | 107 return PP_ERROR_FAILED; |
| 108 if (profile < 0 || profile > PP_VIDEOPROFILE_MAX) | 108 if (profile < 0 || profile > PP_VIDEOPROFILE_MAX) |
| 109 return PP_ERROR_BADARGUMENT; | 109 return PP_ERROR_BADARGUMENT; |
| 110 if (initialize_callback_) | 110 if (initialize_callback_.get()) |
| 111 return PP_ERROR_INPROGRESS; | 111 return PP_ERROR_INPROGRESS; |
| 112 if (!graphics_context) | 112 if (!graphics_context) |
| 113 return PP_ERROR_BADRESOURCE; | 113 return PP_ERROR_BADRESOURCE; |
| 114 | 114 |
| 115 HostResource host_resource; | 115 HostResource host_resource; |
| 116 if (!testing_) { | 116 if (!testing_) { |
| 117 // Create a new Graphics3D resource that can create texture resources to | 117 // Create a new Graphics3D resource that can create texture resources to |
| 118 // share with the plugin. We can't use the plugin's Graphics3D, since we | 118 // share with the plugin. We can't use the plugin's Graphics3D, since we |
| 119 // create textures on a proxy thread, and would interfere with the plugin. | 119 // create textures on a proxy thread, and would interfere with the plugin. |
| 120 thunk::EnterResourceCreationNoLock enter_create(pp_instance()); | 120 thunk::EnterResourceCreationNoLock enter_create(pp_instance()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 146 | 146 |
| 147 return PP_OK_COMPLETIONPENDING; | 147 return PP_OK_COMPLETIONPENDING; |
| 148 } | 148 } |
| 149 | 149 |
| 150 int32_t VideoDecoderResource::Decode(uint32_t decode_id, | 150 int32_t VideoDecoderResource::Decode(uint32_t decode_id, |
| 151 uint32_t size, | 151 uint32_t size, |
| 152 const void* buffer, | 152 const void* buffer, |
| 153 scoped_refptr<TrackedCallback> callback) { | 153 scoped_refptr<TrackedCallback> callback) { |
| 154 if (decoder_last_error_) | 154 if (decoder_last_error_) |
| 155 return decoder_last_error_; | 155 return decoder_last_error_; |
| 156 if (flush_callback_ || reset_callback_) | 156 if (flush_callback_.get() || reset_callback_.get()) |
| 157 return PP_ERROR_FAILED; | 157 return PP_ERROR_FAILED; |
| 158 if (decode_callback_) | 158 if (decode_callback_.get()) |
| 159 return PP_ERROR_INPROGRESS; | 159 return PP_ERROR_INPROGRESS; |
| 160 if (size > kMaximumBitstreamBufferSize) | 160 if (size > kMaximumBitstreamBufferSize) |
| 161 return PP_ERROR_NOMEMORY; | 161 return PP_ERROR_NOMEMORY; |
| 162 | 162 |
| 163 // If we allow the plugin to call Decode again, we must have somewhere to | 163 // If we allow the plugin to call Decode again, we must have somewhere to |
| 164 // copy their buffer. | 164 // copy their buffer. |
| 165 DCHECK(!available_shm_buffers_.empty() || | 165 DCHECK(!available_shm_buffers_.empty() || |
| 166 shm_buffers_.size() < kMaximumPendingDecodes); | 166 shm_buffers_.size() < kMaximumPendingDecodes); |
| 167 | 167 |
| 168 // Count up, wrapping back to 0 before overflowing. | 168 // Count up, wrapping back to 0 before overflowing. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // buffer is available. | 247 // buffer is available. |
| 248 decode_callback_ = callback; | 248 decode_callback_ = callback; |
| 249 return PP_OK_COMPLETIONPENDING; | 249 return PP_OK_COMPLETIONPENDING; |
| 250 } | 250 } |
| 251 | 251 |
| 252 int32_t VideoDecoderResource::GetPicture( | 252 int32_t VideoDecoderResource::GetPicture( |
| 253 PP_VideoPicture* picture, | 253 PP_VideoPicture* picture, |
| 254 scoped_refptr<TrackedCallback> callback) { | 254 scoped_refptr<TrackedCallback> callback) { |
| 255 if (decoder_last_error_) | 255 if (decoder_last_error_) |
| 256 return decoder_last_error_; | 256 return decoder_last_error_; |
| 257 if (reset_callback_) | 257 if (reset_callback_.get()) |
| 258 return PP_ERROR_FAILED; | 258 return PP_ERROR_FAILED; |
| 259 if (get_picture_callback_) | 259 if (get_picture_callback_.get()) |
| 260 return PP_ERROR_INPROGRESS; | 260 return PP_ERROR_INPROGRESS; |
| 261 | 261 |
| 262 // If the next picture is ready, return it synchronously. | 262 // If the next picture is ready, return it synchronously. |
| 263 if (!received_pictures_.empty()) { | 263 if (!received_pictures_.empty()) { |
| 264 WriteNextPicture(picture); | 264 WriteNextPicture(picture); |
| 265 return PP_OK; | 265 return PP_OK; |
| 266 } | 266 } |
| 267 | 267 |
| 268 get_picture_callback_ = callback; | 268 get_picture_callback_ = callback; |
| 269 get_picture_ = picture; | 269 get_picture_ = picture; |
| 270 return PP_OK_COMPLETIONPENDING; | 270 return PP_OK_COMPLETIONPENDING; |
| 271 } | 271 } |
| 272 | 272 |
| 273 void VideoDecoderResource::RecyclePicture(const PP_VideoPicture* picture) { | 273 void VideoDecoderResource::RecyclePicture(const PP_VideoPicture* picture) { |
| 274 if (decoder_last_error_) | 274 if (decoder_last_error_) |
| 275 return; | 275 return; |
| 276 | 276 |
| 277 Post(RENDERER, PpapiHostMsg_VideoDecoder_RecyclePicture(picture->texture_id)); | 277 Post(RENDERER, PpapiHostMsg_VideoDecoder_RecyclePicture(picture->texture_id)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 int32_t VideoDecoderResource::Flush(scoped_refptr<TrackedCallback> callback) { | 280 int32_t VideoDecoderResource::Flush(scoped_refptr<TrackedCallback> callback) { |
| 281 if (decoder_last_error_) | 281 if (decoder_last_error_) |
| 282 return decoder_last_error_; | 282 return decoder_last_error_; |
| 283 if (reset_callback_) | 283 if (reset_callback_.get()) |
| 284 return PP_ERROR_FAILED; | 284 return PP_ERROR_FAILED; |
| 285 if (flush_callback_) | 285 if (flush_callback_.get()) |
| 286 return PP_ERROR_INPROGRESS; | 286 return PP_ERROR_INPROGRESS; |
| 287 flush_callback_ = callback; | 287 flush_callback_ = callback; |
| 288 | 288 |
| 289 Call<PpapiPluginMsg_VideoDecoder_FlushReply>( | 289 Call<PpapiPluginMsg_VideoDecoder_FlushReply>( |
| 290 RENDERER, | 290 RENDERER, |
| 291 PpapiHostMsg_VideoDecoder_Flush(), | 291 PpapiHostMsg_VideoDecoder_Flush(), |
| 292 base::Bind(&VideoDecoderResource::OnPluginMsgFlushComplete, this)); | 292 base::Bind(&VideoDecoderResource::OnPluginMsgFlushComplete, this)); |
| 293 | 293 |
| 294 return PP_OK_COMPLETIONPENDING; | 294 return PP_OK_COMPLETIONPENDING; |
| 295 } | 295 } |
| 296 | 296 |
| 297 int32_t VideoDecoderResource::Reset(scoped_refptr<TrackedCallback> callback) { | 297 int32_t VideoDecoderResource::Reset(scoped_refptr<TrackedCallback> callback) { |
| 298 if (decoder_last_error_) | 298 if (decoder_last_error_) |
| 299 return decoder_last_error_; | 299 return decoder_last_error_; |
| 300 if (flush_callback_) | 300 if (flush_callback_.get()) |
| 301 return PP_ERROR_FAILED; | 301 return PP_ERROR_FAILED; |
| 302 if (reset_callback_) | 302 if (reset_callback_.get()) |
| 303 return PP_ERROR_INPROGRESS; | 303 return PP_ERROR_INPROGRESS; |
| 304 reset_callback_ = callback; | 304 reset_callback_ = callback; |
| 305 | 305 |
| 306 // Cause any pending Decode or GetPicture callbacks to abort after we return, | 306 // Cause any pending Decode or GetPicture callbacks to abort after we return, |
| 307 // to avoid reentering the plugin. | 307 // to avoid reentering the plugin. |
| 308 if (TrackedCallback::IsPending(decode_callback_)) | 308 if (TrackedCallback::IsPending(decode_callback_)) |
| 309 decode_callback_->PostAbort(); | 309 decode_callback_->PostAbort(); |
| 310 decode_callback_ = NULL; | 310 decode_callback_ = NULL; |
| 311 if (TrackedCallback::IsPending(get_picture_callback_)) | 311 if (TrackedCallback::IsPending(get_picture_callback_)) |
| 312 get_picture_callback_->PostAbort(); | 312 get_picture_callback_->PostAbort(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 void VideoDecoderResource::OnPluginMsgDecodeComplete( | 448 void VideoDecoderResource::OnPluginMsgDecodeComplete( |
| 449 const ResourceMessageReplyParams& params, | 449 const ResourceMessageReplyParams& params, |
| 450 uint32_t shm_id) { | 450 uint32_t shm_id) { |
| 451 if (shm_id >= shm_buffers_.size()) { | 451 if (shm_id >= shm_buffers_.size()) { |
| 452 NOTREACHED(); | 452 NOTREACHED(); |
| 453 return; | 453 return; |
| 454 } | 454 } |
| 455 // Make the shm buffer available. | 455 // Make the shm buffer available. |
| 456 available_shm_buffers_.push_back(shm_buffers_[shm_id]); | 456 available_shm_buffers_.push_back(shm_buffers_[shm_id]); |
| 457 // If the plugin is waiting, let it call Decode again. | 457 // If the plugin is waiting, let it call Decode again. |
| 458 if (decode_callback_) { | 458 if (decode_callback_.get()) { |
| 459 scoped_refptr<TrackedCallback> callback; | 459 scoped_refptr<TrackedCallback> callback; |
| 460 callback.swap(decode_callback_); | 460 callback.swap(decode_callback_); |
| 461 callback->Run(PP_OK); | 461 callback->Run(PP_OK); |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 void VideoDecoderResource::OnPluginMsgFlushComplete( | 465 void VideoDecoderResource::OnPluginMsgFlushComplete( |
| 466 const ResourceMessageReplyParams& params) { | 466 const ResourceMessageReplyParams& params) { |
| 467 // All shm buffers should have been made available by now. | 467 // All shm buffers should have been made available by now. |
| 468 DCHECK_EQ(shm_buffers_.size(), available_shm_buffers_.size()); | 468 DCHECK_EQ(shm_buffers_.size(), available_shm_buffers_.size()); |
| 469 | 469 |
| 470 if (get_picture_callback_) { | 470 if (get_picture_callback_.get()) { |
| 471 scoped_refptr<TrackedCallback> callback; | 471 scoped_refptr<TrackedCallback> callback; |
| 472 callback.swap(get_picture_callback_); | 472 callback.swap(get_picture_callback_); |
| 473 callback->Abort(); | 473 callback->Abort(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 scoped_refptr<TrackedCallback> callback; | 476 scoped_refptr<TrackedCallback> callback; |
| 477 callback.swap(flush_callback_); | 477 callback.swap(flush_callback_); |
| 478 callback->Run(params.result()); | 478 callback->Run(params.result()); |
| 479 } | 479 } |
| 480 | 480 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 pp_picture->texture_target = it->second.texture_target; | 522 pp_picture->texture_target = it->second.texture_target; |
| 523 pp_picture->texture_size = it->second.size; | 523 pp_picture->texture_size = it->second.size; |
| 524 } else { | 524 } else { |
| 525 NOTREACHED(); | 525 NOTREACHED(); |
| 526 } | 526 } |
| 527 received_pictures_.pop(); | 527 received_pictures_.pop(); |
| 528 } | 528 } |
| 529 | 529 |
| 530 } // namespace proxy | 530 } // namespace proxy |
| 531 } // namespace ppapi | 531 } // namespace ppapi |
| OLD | NEW |