OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/gpu/media/omx_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/omx_video_decode_accelerator.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
10 #include "content/common/gpu/media/gles2_texture_to_egl_image_translator.h" | 10 #include "content/common/gpu/media/gles2_texture_to_egl_image_translator.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 buffer->nOutputPortIndex = output_port_; | 271 buffer->nOutputPortIndex = output_port_; |
272 CHECK(fake_output_buffers_.insert(buffer).second); | 272 CHECK(fake_output_buffers_.insert(buffer).second); |
273 } | 273 } |
274 | 274 |
275 return true; | 275 return true; |
276 } | 276 } |
277 | 277 |
278 void OmxVideoDecodeAccelerator::Decode( | 278 void OmxVideoDecodeAccelerator::Decode( |
279 const media::BitstreamBuffer& bitstream_buffer) { | 279 const media::BitstreamBuffer& bitstream_buffer) { |
280 DCHECK_EQ(message_loop_, MessageLoop::current()); | 280 DCHECK_EQ(message_loop_, MessageLoop::current()); |
281 DCHECK(!free_input_buffers_.empty()); | |
282 | 281 |
283 if (current_state_change_ == RESETTING || | 282 if (current_state_change_ == RESETTING || |
284 !queued_bitstream_buffers_.empty()) { | 283 !queued_bitstream_buffers_.empty() || |
| 284 free_input_buffers_.empty()) { |
285 queued_bitstream_buffers_.push_back(bitstream_buffer); | 285 queued_bitstream_buffers_.push_back(bitstream_buffer); |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 RETURN_ON_FAILURE(current_state_change_ == NO_TRANSITION && | 289 RETURN_ON_FAILURE(current_state_change_ == NO_TRANSITION && |
290 (client_state_ == OMX_StateIdle || | 290 (client_state_ == OMX_StateIdle || |
291 client_state_ == OMX_StateExecuting), | 291 client_state_ == OMX_StateExecuting), |
292 "Call to Decode() during invalid state or transition: " | 292 "Call to Decode() during invalid state or transition: " |
293 << current_state_change_ << ", " << client_state_, | 293 << current_state_change_ << ", " << client_state_, |
294 ILLEGAL_STATE,); | 294 ILLEGAL_STATE,); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 if (client_) | 503 if (client_) |
504 client_->NotifyFlushDone(); | 504 client_->NotifyFlushDone(); |
505 } | 505 } |
506 | 506 |
507 void OmxVideoDecodeAccelerator::OnReachedPauseInResetting() { | 507 void OmxVideoDecodeAccelerator::OnReachedPauseInResetting() { |
508 DCHECK_EQ(client_state_, OMX_StateExecuting); | 508 DCHECK_EQ(client_state_, OMX_StateExecuting); |
509 client_state_ = OMX_StatePause; | 509 client_state_ = OMX_StatePause; |
510 FlushIOPorts(); | 510 FlushIOPorts(); |
511 } | 511 } |
512 | 512 |
| 513 void OmxVideoDecodeAccelerator::DecodeQueuedBitstreamBuffers() { |
| 514 BitstreamBufferList buffers; |
| 515 buffers.swap(queued_bitstream_buffers_); |
| 516 for (size_t i = 0; i < buffers.size(); ++i) |
| 517 Decode(buffers[i]); |
| 518 } |
| 519 |
513 void OmxVideoDecodeAccelerator::OnReachedExecutingInResetting() { | 520 void OmxVideoDecodeAccelerator::OnReachedExecutingInResetting() { |
514 DCHECK_EQ(client_state_, OMX_StatePause); | 521 DCHECK_EQ(client_state_, OMX_StatePause); |
515 client_state_ = OMX_StateExecuting; | 522 client_state_ = OMX_StateExecuting; |
516 current_state_change_ = NO_TRANSITION; | 523 current_state_change_ = NO_TRANSITION; |
517 if (!client_) | 524 if (!client_) |
518 return; | 525 return; |
519 | 526 |
520 // Drain queued bitstream & picture buffers that were held away from the | 527 // Drain queues of input & output buffers held during the reset. |
521 // decoder during the reset. | 528 DecodeQueuedBitstreamBuffers(); |
522 BitstreamBufferList buffers; | |
523 buffers.swap(queued_bitstream_buffers_); | |
524 for (size_t i = 0; i < buffers.size(); ++i) | |
525 Decode(buffers[i]); | |
526 // Ensure the Decode() calls above didn't end up re-enqueuing. | |
527 DCHECK(queued_bitstream_buffers_.empty()); | |
528 for (size_t i = 0; i < queued_picture_buffer_ids_.size(); ++i) | 529 for (size_t i = 0; i < queued_picture_buffer_ids_.size(); ++i) |
529 ReusePictureBuffer(queued_picture_buffer_ids_[i]); | 530 ReusePictureBuffer(queued_picture_buffer_ids_[i]); |
530 queued_picture_buffer_ids_.clear(); | 531 queued_picture_buffer_ids_.clear(); |
531 | 532 |
532 client_->NotifyResetDone(); | 533 client_->NotifyResetDone(); |
533 } | 534 } |
534 | 535 |
535 // Alert: HORROR ahead! OMX shutdown is an asynchronous dance but our clients | 536 // Alert: HORROR ahead! OMX shutdown is an asynchronous dance but our clients |
536 // enjoy the fire-and-forget nature of a synchronous Destroy() call that | 537 // enjoy the fire-and-forget nature of a synchronous Destroy() call that |
537 // ensures no further callbacks are made. Since the interface between OMX | 538 // ensures no further callbacks are made. Since the interface between OMX |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 | 789 |
789 // Retrieve the corresponding BitstreamBuffer's id and notify the client of | 790 // Retrieve the corresponding BitstreamBuffer's id and notify the client of |
790 // its completion. | 791 // its completion. |
791 SharedMemoryAndId* input_buffer_details = | 792 SharedMemoryAndId* input_buffer_details = |
792 reinterpret_cast<SharedMemoryAndId*>(buffer->pAppPrivate); | 793 reinterpret_cast<SharedMemoryAndId*>(buffer->pAppPrivate); |
793 DCHECK(input_buffer_details); | 794 DCHECK(input_buffer_details); |
794 buffer->pAppPrivate = NULL; | 795 buffer->pAppPrivate = NULL; |
795 if (client_) | 796 if (client_) |
796 client_->NotifyEndOfBitstreamBuffer(input_buffer_details->second); | 797 client_->NotifyEndOfBitstreamBuffer(input_buffer_details->second); |
797 delete input_buffer_details; | 798 delete input_buffer_details; |
| 799 |
| 800 DecodeQueuedBitstreamBuffers(); |
798 } | 801 } |
799 | 802 |
800 void OmxVideoDecodeAccelerator::DispatchStateReached(OMX_STATETYPE reached) { | 803 void OmxVideoDecodeAccelerator::DispatchStateReached(OMX_STATETYPE reached) { |
801 DCHECK_EQ(message_loop_, MessageLoop::current()); | 804 DCHECK_EQ(message_loop_, MessageLoop::current()); |
802 switch (current_state_change_) { | 805 switch (current_state_change_) { |
803 case INITIALIZING: | 806 case INITIALIZING: |
804 switch (reached) { | 807 switch (reached) { |
805 case OMX_StateIdle: | 808 case OMX_StateIdle: |
806 OnReachedIdleInInitializing(); | 809 OnReachedIdleInInitializing(); |
807 return; | 810 return; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 | 1014 |
1012 bool OmxVideoDecodeAccelerator::SendCommandToPort( | 1015 bool OmxVideoDecodeAccelerator::SendCommandToPort( |
1013 OMX_COMMANDTYPE cmd, int port_index) { | 1016 OMX_COMMANDTYPE cmd, int port_index) { |
1014 DCHECK_EQ(message_loop_, MessageLoop::current()); | 1017 DCHECK_EQ(message_loop_, MessageLoop::current()); |
1015 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, | 1018 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, |
1016 cmd, port_index, 0); | 1019 cmd, port_index, 0); |
1017 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, | 1020 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, |
1018 PLATFORM_FAILURE, false); | 1021 PLATFORM_FAILURE, false); |
1019 return true; | 1022 return true; |
1020 } | 1023 } |
OLD | NEW |