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 "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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 client_state_ == OMX_StateIdle || | 598 client_state_ == OMX_StateIdle || |
599 client_state_ == OMX_StatePause); | 599 client_state_ == OMX_StatePause); |
600 client_state_ = OMX_StateIdle; | 600 client_state_ = OMX_StateIdle; |
601 | 601 |
602 // Note that during the Executing -> Idle transition, the OMX spec guarantees | 602 // Note that during the Executing -> Idle transition, the OMX spec guarantees |
603 // buffers have been returned to the client, so we don't need to do an | 603 // buffers have been returned to the client, so we don't need to do an |
604 // explicit FlushIOPorts(). | 604 // explicit FlushIOPorts(). |
605 | 605 |
606 BeginTransitionToState(OMX_StateLoaded); | 606 BeginTransitionToState(OMX_StateLoaded); |
607 | 607 |
608 // TODO(fischman): evaluate what these conditionals are doing. What happens | 608 FreeOMXBuffers(); |
609 // if they're false?? | |
610 if (!input_buffers_at_component_) | |
611 FreeInputBuffers(); | |
612 if (!output_buffers_at_component_) | |
613 FreeOutputBuffers(); | |
614 } | 609 } |
615 | 610 |
616 void OmxVideoDecodeAccelerator::OnReachedLoadedInDestroying() { | 611 void OmxVideoDecodeAccelerator::OnReachedLoadedInDestroying() { |
617 DCHECK_EQ(client_state_, OMX_StateIdle); | 612 DCHECK_EQ(client_state_, OMX_StateIdle); |
618 client_state_ = OMX_StateLoaded; | 613 client_state_ = OMX_StateLoaded; |
619 current_state_change_ = NO_TRANSITION; | 614 current_state_change_ = NO_TRANSITION; |
620 ShutdownComponent(); | 615 ShutdownComponent(); |
621 } | 616 } |
622 | 617 |
623 void OmxVideoDecodeAccelerator::OnReachedInvalidInErroring() { | 618 void OmxVideoDecodeAccelerator::OnReachedInvalidInErroring() { |
624 client_state_ = OMX_StateInvalid; | 619 client_state_ = OMX_StateInvalid; |
| 620 FreeOMXBuffers(); |
625 ShutdownComponent(); | 621 ShutdownComponent(); |
626 } | 622 } |
627 | 623 |
628 void OmxVideoDecodeAccelerator::ShutdownComponent() { | 624 void OmxVideoDecodeAccelerator::ShutdownComponent() { |
629 OMX_ERRORTYPE result = omx_free_handle(component_handle_); | 625 OMX_ERRORTYPE result = omx_free_handle(component_handle_); |
630 if (result != OMX_ErrorNone) | 626 if (result != OMX_ErrorNone) |
631 DLOG(ERROR) << "OMX_FreeHandle() error. Error code: " << result; | 627 DLOG(ERROR) << "OMX_FreeHandle() error. Error code: " << result; |
632 client_state_ = OMX_StateMax; | 628 client_state_ = OMX_StateMax; |
633 omx_deinit(); | 629 omx_deinit(); |
634 // Allow BusyLoopInDestroying to exit and delete |this|. | 630 // Allow BusyLoopInDestroying to exit and delete |this|. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 RETURN_ON_OMX_FAILURE(result, "OMX_UseEGLImage", PLATFORM_FAILURE, false); | 704 RETURN_ON_OMX_FAILURE(result, "OMX_UseEGLImage", PLATFORM_FAILURE, false); |
709 // Here we set a garbage bitstream buffer id, and then overwrite it before | 705 // Here we set a garbage bitstream buffer id, and then overwrite it before |
710 // passing to PictureReady. | 706 // passing to PictureReady. |
711 int garbage_bitstream_buffer_id = -1; | 707 int garbage_bitstream_buffer_id = -1; |
712 (*omx_buffer)->pAppPrivate = | 708 (*omx_buffer)->pAppPrivate = |
713 new media::Picture(picture_buffer.id(), garbage_bitstream_buffer_id); | 709 new media::Picture(picture_buffer.id(), garbage_bitstream_buffer_id); |
714 } | 710 } |
715 return true; | 711 return true; |
716 } | 712 } |
717 | 713 |
718 void OmxVideoDecodeAccelerator::FreeInputBuffers() { | 714 void OmxVideoDecodeAccelerator::FreeOMXBuffers() { |
719 DCHECK_EQ(message_loop_, MessageLoop::current()); | 715 DCHECK_EQ(message_loop_, MessageLoop::current()); |
720 // Calls to OMX to free buffers. | 716 bool failure_seen = false; |
721 OMX_ERRORTYPE result; | |
722 OMX_BUFFERHEADERTYPE* omx_buffer; | |
723 while (!free_input_buffers_.empty()) { | 717 while (!free_input_buffers_.empty()) { |
724 omx_buffer = free_input_buffers_.front(); | 718 OMX_BUFFERHEADERTYPE* omx_buffer = free_input_buffers_.front(); |
725 free_input_buffers_.pop(); | 719 free_input_buffers_.pop(); |
726 result = OMX_FreeBuffer(component_handle_, input_port_, omx_buffer); | 720 OMX_ERRORTYPE result = |
727 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); | 721 OMX_FreeBuffer(component_handle_, input_port_, omx_buffer); |
| 722 if (result != OMX_ErrorNone) { |
| 723 DLOG(ERROR) << "OMX_FreeBuffer failed: 0x" << std::hex << result; |
| 724 failure_seen = true; |
| 725 } |
728 } | 726 } |
729 } | |
730 | |
731 void OmxVideoDecodeAccelerator::FreeOutputBuffers() { | |
732 DCHECK_EQ(message_loop_, MessageLoop::current()); | |
733 // Calls to OMX to free buffers. | |
734 OMX_ERRORTYPE result; | |
735 | |
736 for (OutputPictureById::iterator it = pictures_.begin(); | 727 for (OutputPictureById::iterator it = pictures_.begin(); |
737 it != pictures_.end(); ++it) { | 728 it != pictures_.end(); ++it) { |
738 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header; | 729 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header; |
739 DCHECK(omx_buffer); | 730 DCHECK(omx_buffer); |
740 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate); | 731 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate); |
741 result = OMX_FreeBuffer(component_handle_, output_port_, omx_buffer); | 732 OMX_ERRORTYPE result = |
742 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); | 733 OMX_FreeBuffer(component_handle_, output_port_, omx_buffer); |
| 734 if (result != OMX_ErrorNone) { |
| 735 DLOG(ERROR) << "OMX_FreeBuffer failed: 0x" << std::hex << result; |
| 736 failure_seen = true; |
| 737 } |
743 texture_to_egl_image_translator_->DestroyEglImage(egl_display_, | 738 texture_to_egl_image_translator_->DestroyEglImage(egl_display_, |
744 it->second.egl_image); | 739 it->second.egl_image); |
745 if (client_) | 740 if (client_) |
746 client_->DismissPictureBuffer(it->first); | 741 client_->DismissPictureBuffer(it->first); |
747 } | 742 } |
748 pictures_.clear(); | 743 pictures_.clear(); |
| 744 |
| 745 RETURN_ON_FAILURE(!failure_seen, "OMX_FreeBuffer", PLATFORM_FAILURE,); |
749 } | 746 } |
750 | 747 |
751 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() { | 748 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() { |
752 DCHECK_EQ(message_loop_, MessageLoop::current()); | 749 DCHECK_EQ(message_loop_, MessageLoop::current()); |
753 OMX_PARAM_PORTDEFINITIONTYPE port_format; | 750 OMX_PARAM_PORTDEFINITIONTYPE port_format; |
754 InitParam(*this, &port_format); | 751 InitParam(*this, &port_format); |
755 port_format.nPortIndex = output_port_; | 752 port_format.nPortIndex = output_port_; |
756 OMX_ERRORTYPE result = OMX_GetParameter( | 753 OMX_ERRORTYPE result = OMX_GetParameter( |
757 component_handle_, OMX_IndexParamPortDefinition, &port_format); | 754 component_handle_, OMX_IndexParamPortDefinition, &port_format); |
758 RETURN_ON_OMX_FAILURE(result, "OMX_GetParameter", PLATFORM_FAILURE,); | 755 RETURN_ON_OMX_FAILURE(result, "OMX_GetParameter", PLATFORM_FAILURE,); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 | 1099 |
1103 bool OmxVideoDecodeAccelerator::SendCommandToPort( | 1100 bool OmxVideoDecodeAccelerator::SendCommandToPort( |
1104 OMX_COMMANDTYPE cmd, int port_index) { | 1101 OMX_COMMANDTYPE cmd, int port_index) { |
1105 DCHECK_EQ(message_loop_, MessageLoop::current()); | 1102 DCHECK_EQ(message_loop_, MessageLoop::current()); |
1106 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, | 1103 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, |
1107 cmd, port_index, 0); | 1104 cmd, port_index, 0); |
1108 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, | 1105 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, |
1109 PLATFORM_FAILURE, false); | 1106 PLATFORM_FAILURE, false); |
1110 return true; | 1107 return true; |
1111 } | 1108 } |
OLD | NEW |