| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "content/renderer/pepper/pepper_video_decoder_host.h" | 5 #include "content/renderer/pepper/pepper_video_decoder_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 257 } |
| 258 | 258 |
| 259 int32_t PepperVideoDecoderHost::OnHostMsgAssignTextures( | 259 int32_t PepperVideoDecoderHost::OnHostMsgAssignTextures( |
| 260 ppapi::host::HostMessageContext* context, | 260 ppapi::host::HostMessageContext* context, |
| 261 const PP_Size& size, | 261 const PP_Size& size, |
| 262 const std::vector<uint32_t>& texture_ids) { | 262 const std::vector<uint32_t>& texture_ids) { |
| 263 if (!initialized_) | 263 if (!initialized_) |
| 264 return PP_ERROR_FAILED; | 264 return PP_ERROR_FAILED; |
| 265 DCHECK(decoder_); | 265 DCHECK(decoder_); |
| 266 | 266 |
| 267 pending_texture_requests_--; |
| 268 DCHECK_GE(pending_texture_requests_, 0); |
| 269 |
| 270 // If |assign_textures_messages_to_dismiss_| is not 0 then decrement it and |
| 271 // dismiss the textures. This is necessary to ensure that after SW decoder |
| 272 // fallback the textures that were requested by the failed HW decoder are not |
| 273 // passed to the SW decoder. |
| 274 if (assign_textures_messages_to_dismiss_ > 0) { |
| 275 assign_textures_messages_to_dismiss_--; |
| 276 PictureBufferMap pictures_pending_dismission; |
| 277 for (auto& texture_id : texture_ids) { |
| 278 host()->SendUnsolicitedReply( |
| 279 pp_resource(), |
| 280 PpapiPluginMsg_VideoDecoder_DismissPicture(texture_id)); |
| 281 } |
| 282 picture_buffer_map_.swap(pictures_pending_dismission); |
| 283 return PP_OK; |
| 284 } |
| 285 |
| 267 // Verify that the new texture IDs are unique and store them in | 286 // Verify that the new texture IDs are unique and store them in |
| 268 // |new_textures|. | 287 // |new_textures|. |
| 269 PictureBufferMap new_textures; | 288 PictureBufferMap new_textures; |
| 270 for (uint32_t i = 0; i < texture_ids.size(); i++) { | 289 for (uint32_t i = 0; i < texture_ids.size(); i++) { |
| 271 if (picture_buffer_map_.find(texture_ids[i]) != picture_buffer_map_.end() || | 290 if (picture_buffer_map_.find(texture_ids[i]) != picture_buffer_map_.end() || |
| 272 new_textures.find(texture_ids[i]) != new_textures.end()) { | 291 new_textures.find(texture_ids[i]) != new_textures.end()) { |
| 273 // Can't assign the same texture more than once. | 292 // Can't assign the same texture more than once. |
| 274 return PP_ERROR_BADARGUMENT; | 293 return PP_ERROR_BADARGUMENT; |
| 275 } | 294 } |
| 276 new_textures.insert( | 295 new_textures.insert( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 DCHECK(it != pending_decodes_.end()); | 477 DCHECK(it != pending_decodes_.end()); |
| 459 uint32_t shm_id = it->shm_id; | 478 uint32_t shm_id = it->shm_id; |
| 460 return static_cast<uint8_t*>(shm_buffers_[shm_id]->memory()); | 479 return static_cast<uint8_t*>(shm_buffers_[shm_id]->memory()); |
| 461 } | 480 } |
| 462 | 481 |
| 463 void PepperVideoDecoderHost::RequestTextures( | 482 void PepperVideoDecoderHost::RequestTextures( |
| 464 uint32_t requested_num_of_buffers, | 483 uint32_t requested_num_of_buffers, |
| 465 const gfx::Size& dimensions, | 484 const gfx::Size& dimensions, |
| 466 uint32_t texture_target, | 485 uint32_t texture_target, |
| 467 const std::vector<gpu::Mailbox>& mailboxes) { | 486 const std::vector<gpu::Mailbox>& mailboxes) { |
| 487 pending_texture_requests_++; |
| 468 host()->SendUnsolicitedReply( | 488 host()->SendUnsolicitedReply( |
| 469 pp_resource(), | 489 pp_resource(), |
| 470 PpapiPluginMsg_VideoDecoder_RequestTextures( | 490 PpapiPluginMsg_VideoDecoder_RequestTextures( |
| 471 requested_num_of_buffers, | 491 requested_num_of_buffers, |
| 472 PP_MakeSize(dimensions.width(), dimensions.height()), | 492 PP_MakeSize(dimensions.width(), dimensions.height()), |
| 473 texture_target, | 493 texture_target, |
| 474 mailboxes)); | 494 mailboxes)); |
| 475 } | 495 } |
| 476 | 496 |
| 477 bool PepperVideoDecoderHost::TryFallbackToSoftwareDecoder() { | 497 bool PepperVideoDecoderHost::TryFallbackToSoftwareDecoder() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 498 host()->SendUnsolicitedReply( | 518 host()->SendUnsolicitedReply( |
| 499 pp_resource(), | 519 pp_resource(), |
| 500 PpapiPluginMsg_VideoDecoder_DismissPicture(picture.first)); | 520 PpapiPluginMsg_VideoDecoder_DismissPicture(picture.first)); |
| 501 } else { | 521 } else { |
| 502 pictures_pending_dismission.insert( | 522 pictures_pending_dismission.insert( |
| 503 std::make_pair(picture.first, PictureBufferState::DISMISSED)); | 523 std::make_pair(picture.first, PictureBufferState::DISMISSED)); |
| 504 } | 524 } |
| 505 } | 525 } |
| 506 picture_buffer_map_.swap(pictures_pending_dismission); | 526 picture_buffer_map_.swap(pictures_pending_dismission); |
| 507 | 527 |
| 528 // Dismiss all outstanding texture requests. |
| 529 DCHECK_EQ(assign_textures_messages_to_dismiss_, 0); |
| 530 assign_textures_messages_to_dismiss_ = pending_texture_requests_; |
| 531 |
| 508 // If there was a pending Reset() it can be finished now. | 532 // If there was a pending Reset() it can be finished now. |
| 509 if (reset_reply_context_.is_valid()) { | 533 if (reset_reply_context_.is_valid()) { |
| 510 while (!pending_decodes_.empty()) { | 534 while (!pending_decodes_.empty()) { |
| 511 const PendingDecode& decode = pending_decodes_.front(); | 535 const PendingDecode& decode = pending_decodes_.front(); |
| 512 host()->SendReply(decode.reply_context, | 536 host()->SendReply(decode.reply_context, |
| 513 PpapiPluginMsg_VideoDecoder_DecodeReply(decode.shm_id)); | 537 PpapiPluginMsg_VideoDecoder_DecodeReply(decode.shm_id)); |
| 514 DCHECK(shm_buffer_busy_[decode.shm_id]); | 538 DCHECK(shm_buffer_busy_[decode.shm_id]); |
| 515 shm_buffer_busy_[decode.shm_id] = false; | 539 shm_buffer_busy_[decode.shm_id] = false; |
| 516 pending_decodes_.pop_front(); | 540 pending_decodes_.pop_front(); |
| 517 } | 541 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 535 | 559 |
| 536 PepperVideoDecoderHost::PendingDecodeList::iterator | 560 PepperVideoDecoderHost::PendingDecodeList::iterator |
| 537 PepperVideoDecoderHost::GetPendingDecodeById(int32_t decode_id) { | 561 PepperVideoDecoderHost::GetPendingDecodeById(int32_t decode_id) { |
| 538 return std::find_if(pending_decodes_.begin(), pending_decodes_.end(), | 562 return std::find_if(pending_decodes_.begin(), pending_decodes_.end(), |
| 539 [decode_id](const PendingDecode& item) { | 563 [decode_id](const PendingDecode& item) { |
| 540 return item.decode_id == decode_id; | 564 return item.decode_id == decode_id; |
| 541 }); | 565 }); |
| 542 } | 566 } |
| 543 | 567 |
| 544 } // namespace content | 568 } // namespace content |
| OLD | NEW |