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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 VideoDecoderResource::Texture::Texture(uint32_t texture_target, | 44 VideoDecoderResource::Texture::Texture(uint32_t texture_target, |
45 const PP_Size& size) | 45 const PP_Size& size) |
46 : texture_target(texture_target), size(size) { | 46 : texture_target(texture_target), size(size) { |
47 } | 47 } |
48 | 48 |
49 VideoDecoderResource::Texture::~Texture() { | 49 VideoDecoderResource::Texture::~Texture() { |
50 } | 50 } |
51 | 51 |
52 VideoDecoderResource::Picture::Picture(int32_t decode_id, uint32_t texture_id) | 52 VideoDecoderResource::Picture::Picture(int32_t decode_id, |
53 : decode_id(decode_id), texture_id(texture_id) { | 53 uint32_t texture_id, |
| 54 const PP_Rect& visible_rect) |
| 55 : decode_id(decode_id), texture_id(texture_id), visible_rect(visible_rect) { |
54 } | 56 } |
55 | 57 |
56 VideoDecoderResource::Picture::~Picture() { | 58 VideoDecoderResource::Picture::~Picture() { |
57 } | 59 } |
58 | 60 |
59 VideoDecoderResource::VideoDecoderResource(Connection connection, | 61 VideoDecoderResource::VideoDecoderResource(Connection connection, |
60 PP_Instance instance) | 62 PP_Instance instance) |
61 : PluginResource(connection, instance), | 63 : PluginResource(connection, instance), |
62 num_decodes_(0), | 64 num_decodes_(0), |
63 get_picture_(NULL), | 65 get_picture_(NULL), |
| 66 get_picture_0_1_(NULL), |
64 gles2_impl_(NULL), | 67 gles2_impl_(NULL), |
65 initialized_(false), | 68 initialized_(false), |
66 testing_(false), | 69 testing_(false), |
67 // Set |decoder_last_error_| to PP_OK after successful initialization. | 70 // Set |decoder_last_error_| to PP_OK after successful initialization. |
68 // This makes error checking a little more concise, since we can check | 71 // This makes error checking a little more concise, since we can check |
69 // that the decoder has been initialized and hasn't returned an error by | 72 // that the decoder has been initialized and hasn't returned an error by |
70 // just testing |decoder_last_error_|. | 73 // just testing |decoder_last_error_|. |
71 decoder_last_error_(PP_ERROR_FAILED) { | 74 decoder_last_error_(PP_ERROR_FAILED) { |
72 // Clear the decode_ids_ array. | 75 // Clear the decode_ids_ array. |
73 memset(decode_ids_, 0, arraysize(decode_ids_)); | 76 memset(decode_ids_, 0, arraysize(decode_ids_)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (!available_shm_buffers_.empty() || | 245 if (!available_shm_buffers_.empty() || |
243 shm_buffers_.size() < kMaximumPendingDecodes) | 246 shm_buffers_.size() < kMaximumPendingDecodes) |
244 return PP_OK; | 247 return PP_OK; |
245 | 248 |
246 // All buffers are busy and we can't create more. Delay completion until a | 249 // All buffers are busy and we can't create more. Delay completion until a |
247 // buffer is available. | 250 // buffer is available. |
248 decode_callback_ = callback; | 251 decode_callback_ = callback; |
249 return PP_OK_COMPLETIONPENDING; | 252 return PP_OK_COMPLETIONPENDING; |
250 } | 253 } |
251 | 254 |
| 255 int32_t VideoDecoderResource::GetPicture0_1( |
| 256 PP_VideoPicture_0_1* picture, |
| 257 scoped_refptr<TrackedCallback> callback) { |
| 258 get_picture_0_1_ = picture; |
| 259 return GetPicture(NULL, callback); |
| 260 } |
| 261 |
252 int32_t VideoDecoderResource::GetPicture( | 262 int32_t VideoDecoderResource::GetPicture( |
253 PP_VideoPicture* picture, | 263 PP_VideoPicture* picture, |
254 scoped_refptr<TrackedCallback> callback) { | 264 scoped_refptr<TrackedCallback> callback) { |
255 if (decoder_last_error_) | 265 if (decoder_last_error_) |
256 return decoder_last_error_; | 266 return decoder_last_error_; |
257 if (reset_callback_.get()) | 267 if (reset_callback_.get()) |
258 return PP_ERROR_FAILED; | 268 return PP_ERROR_FAILED; |
259 if (get_picture_callback_.get()) | 269 if (get_picture_callback_.get()) |
260 return PP_ERROR_INPROGRESS; | 270 return PP_ERROR_INPROGRESS; |
261 | 271 |
| 272 get_picture_ = picture; |
| 273 |
262 // If the next picture is ready, return it synchronously. | 274 // If the next picture is ready, return it synchronously. |
263 if (!received_pictures_.empty()) { | 275 if (!received_pictures_.empty()) { |
264 WriteNextPicture(picture); | 276 WriteNextPicture(); |
265 return PP_OK; | 277 return PP_OK; |
266 } | 278 } |
267 | 279 |
268 get_picture_callback_ = callback; | 280 get_picture_callback_ = callback; |
269 get_picture_ = picture; | 281 |
270 return PP_OK_COMPLETIONPENDING; | 282 return PP_OK_COMPLETIONPENDING; |
271 } | 283 } |
272 | 284 |
273 void VideoDecoderResource::RecyclePicture(const PP_VideoPicture* picture) { | 285 void VideoDecoderResource::RecyclePicture(const PP_VideoPicture* picture) { |
274 if (decoder_last_error_) | 286 if (decoder_last_error_) |
275 return; | 287 return; |
276 | 288 |
277 Post(RENDERER, PpapiHostMsg_VideoDecoder_RecyclePicture(picture->texture_id)); | 289 Post(RENDERER, PpapiHostMsg_VideoDecoder_RecyclePicture(picture->texture_id)); |
278 } | 290 } |
279 | 291 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 std::make_pair(texture_ids[i], Texture(texture_target, size))); | 404 std::make_pair(texture_ids[i], Texture(texture_target, size))); |
393 } | 405 } |
394 } | 406 } |
395 | 407 |
396 Post(RENDERER, PpapiHostMsg_VideoDecoder_AssignTextures(size, texture_ids)); | 408 Post(RENDERER, PpapiHostMsg_VideoDecoder_AssignTextures(size, texture_ids)); |
397 } | 409 } |
398 | 410 |
399 void VideoDecoderResource::OnPluginMsgPictureReady( | 411 void VideoDecoderResource::OnPluginMsgPictureReady( |
400 const ResourceMessageReplyParams& params, | 412 const ResourceMessageReplyParams& params, |
401 int32_t decode_id, | 413 int32_t decode_id, |
402 uint32_t texture_id) { | 414 uint32_t texture_id, |
403 received_pictures_.push(Picture(decode_id, texture_id)); | 415 const PP_Rect& visible_rect) { |
| 416 received_pictures_.push(Picture(decode_id, texture_id, visible_rect)); |
404 | 417 |
405 if (TrackedCallback::IsPending(get_picture_callback_)) { | 418 if (TrackedCallback::IsPending(get_picture_callback_)) { |
406 // The plugin may call GetPicture in its callback. | 419 // The plugin may call GetPicture in its callback. |
407 scoped_refptr<TrackedCallback> callback; | 420 scoped_refptr<TrackedCallback> callback; |
408 callback.swap(get_picture_callback_); | 421 callback.swap(get_picture_callback_); |
409 PP_VideoPicture* picture = get_picture_; | 422 WriteNextPicture(); |
410 get_picture_ = NULL; | |
411 WriteNextPicture(picture); | |
412 callback->Run(PP_OK); | 423 callback->Run(PP_OK); |
413 } | 424 } |
414 } | 425 } |
415 | 426 |
416 void VideoDecoderResource::OnPluginMsgDismissPicture( | 427 void VideoDecoderResource::OnPluginMsgDismissPicture( |
417 const ResourceMessageReplyParams& params, | 428 const ResourceMessageReplyParams& params, |
418 uint32_t texture_id) { | 429 uint32_t texture_id) { |
419 DeleteGLTexture(texture_id); | 430 DeleteGLTexture(texture_id); |
420 textures_.erase(texture_id); | 431 textures_.erase(texture_id); |
421 } | 432 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 } | 514 } |
504 } | 515 } |
505 | 516 |
506 void VideoDecoderResource::DeleteGLTexture(uint32_t id) { | 517 void VideoDecoderResource::DeleteGLTexture(uint32_t id) { |
507 if (gles2_impl_) { | 518 if (gles2_impl_) { |
508 gles2_impl_->DeleteTextures(1, &id); | 519 gles2_impl_->DeleteTextures(1, &id); |
509 gles2_impl_->Flush(); | 520 gles2_impl_->Flush(); |
510 } | 521 } |
511 } | 522 } |
512 | 523 |
513 void VideoDecoderResource::WriteNextPicture(PP_VideoPicture* pp_picture) { | 524 void VideoDecoderResource::WriteNextPicture() { |
514 DCHECK(!received_pictures_.empty()); | 525 DCHECK(!received_pictures_.empty()); |
515 Picture& picture = received_pictures_.front(); | 526 Picture& picture = received_pictures_.front(); |
| 527 |
516 // Internally, we identify decodes by a unique id, which the host returns | 528 // Internally, we identify decodes by a unique id, which the host returns |
517 // to us in the picture. Use this to get the plugin's decode_id. | 529 // to us in the picture. Use this to get the plugin's decode_id. |
518 pp_picture->decode_id = decode_ids_[picture.decode_id % kMaximumPictureDelay]; | 530 uint32_t decode_id = decode_ids_[picture.decode_id % kMaximumPictureDelay]; |
519 pp_picture->texture_id = picture.texture_id; | 531 uint32_t texture_id = picture.texture_id; |
| 532 uint32_t texture_target = 0; |
| 533 PP_Size texture_size = PP_MakeSize(0, 0); |
520 TextureMap::iterator it = textures_.find(picture.texture_id); | 534 TextureMap::iterator it = textures_.find(picture.texture_id); |
521 if (it != textures_.end()) { | 535 if (it != textures_.end()) { |
522 pp_picture->texture_target = it->second.texture_target; | 536 texture_target = it->second.texture_target; |
523 pp_picture->texture_size = it->second.size; | 537 texture_size = it->second.size; |
524 } else { | 538 } else { |
525 NOTREACHED(); | 539 NOTREACHED(); |
526 } | 540 } |
| 541 |
| 542 if (get_picture_) { |
| 543 DCHECK(!get_picture_0_1_); |
| 544 get_picture_->decode_id = decode_id; |
| 545 get_picture_->texture_id = texture_id; |
| 546 get_picture_->texture_target = texture_target; |
| 547 get_picture_->texture_size = texture_size; |
| 548 get_picture_->visible_rect = picture.visible_rect; |
| 549 get_picture_ = NULL; |
| 550 } else { |
| 551 DCHECK(get_picture_0_1_); |
| 552 get_picture_0_1_->decode_id = decode_id; |
| 553 get_picture_0_1_->texture_id = texture_id; |
| 554 get_picture_0_1_->texture_target = texture_target; |
| 555 get_picture_0_1_->texture_size = texture_size; |
| 556 get_picture_0_1_ = NULL; |
| 557 } |
| 558 |
527 received_pictures_.pop(); | 559 received_pictures_.pop(); |
528 } | 560 } |
529 | 561 |
530 } // namespace proxy | 562 } // namespace proxy |
531 } // namespace ppapi | 563 } // namespace ppapi |
OLD | NEW |