Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: content/common/gpu/media/omx_video_decode_accelerator.cc

Issue 10854146: Always call OMX_FreeBuffer(), even in ERRORING. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/gpu/media/omx_video_decode_accelerator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 DCHECK(current_state_change_ == NO_TRANSITION || 464 DCHECK(current_state_change_ == NO_TRANSITION ||
465 current_state_change_ == FLUSHING || 465 current_state_change_ == FLUSHING ||
466 current_state_change_ == RESETTING) << current_state_change_; 466 current_state_change_ == RESETTING) << current_state_change_;
467 467
468 // If we were never initializeed there's no teardown to do. 468 // If we were never initializeed there's no teardown to do.
469 if (client_state_ == OMX_StateMax) 469 if (client_state_ == OMX_StateMax)
470 return; 470 return;
471 // If we can already call OMX_FreeHandle, simply do so. 471 // If we can already call OMX_FreeHandle, simply do so.
472 if (client_state_ == OMX_StateInvalid || client_state_ == OMX_StateLoaded) { 472 if (client_state_ == OMX_StateInvalid || client_state_ == OMX_StateLoaded) {
473 ShutdownComponent(); 473 ShutdownComponent();
Pawel Osciak 2012/08/14 22:17:14 Can we get here without freeing the buffers first?
Ami GONE FROM CHROMIUM 2012/08/15 04:08:30 No; Invalid & Loaded can only be reached through E
474 return; 474 return;
475 } 475 }
476 DCHECK(client_state_ == OMX_StateExecuting || 476 DCHECK(client_state_ == OMX_StateExecuting ||
477 client_state_ == OMX_StateIdle || 477 client_state_ == OMX_StateIdle ||
478 client_state_ == OMX_StatePause); 478 client_state_ == OMX_StatePause);
479 current_state_change_ = DESTROYING; 479 current_state_change_ = DESTROYING;
480 client_ = NULL; 480 client_ = NULL;
481 BeginTransitionToState(OMX_StateIdle); 481 BeginTransitionToState(OMX_StateIdle);
482 BusyLoopInDestroying(deleter.Pass()); 482 BusyLoopInDestroying(deleter.Pass());
483 } 483 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
Pawel Osciak 2012/08/14 22:17:14 Same here, can we get here without freeing buffers
Ami GONE FROM CHROMIUM 2012/08/15 04:08:30 No, the only way to get to Loaded is through OnRea
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
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.
721 OMX_ERRORTYPE result;
722 OMX_BUFFERHEADERTYPE* omx_buffer;
723 while (!free_input_buffers_.empty()) { 716 while (!free_input_buffers_.empty()) {
724 omx_buffer = free_input_buffers_.front(); 717 OMX_BUFFERHEADERTYPE* omx_buffer = free_input_buffers_.front();
725 free_input_buffers_.pop(); 718 free_input_buffers_.pop();
726 result = OMX_FreeBuffer(component_handle_, input_port_, omx_buffer); 719 OMX_ERRORTYPE result =
720 OMX_FreeBuffer(component_handle_, input_port_, omx_buffer);
727 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); 721 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,);
728 } 722 }
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(); 723 for (OutputPictureById::iterator it = pictures_.begin();
737 it != pictures_.end(); ++it) { 724 it != pictures_.end(); ++it) {
738 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header; 725 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header;
739 DCHECK(omx_buffer); 726 DCHECK(omx_buffer);
740 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate); 727 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate);
741 result = OMX_FreeBuffer(component_handle_, output_port_, omx_buffer); 728 OMX_ERRORTYPE result =
729 OMX_FreeBuffer(component_handle_, output_port_, omx_buffer);
742 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); 730 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,);
marcheu 2012/08/14 22:11:25 Can we keep iterating even if we fail a FreeBuffer
Ami GONE FROM CHROMIUM 2012/08/15 04:08:30 I really dislike this sort of programming. I guess
743 texture_to_egl_image_translator_->DestroyEglImage(egl_display_, 731 texture_to_egl_image_translator_->DestroyEglImage(egl_display_,
744 it->second.egl_image); 732 it->second.egl_image);
745 if (client_) 733 if (client_)
746 client_->DismissPictureBuffer(it->first); 734 client_->DismissPictureBuffer(it->first);
747 } 735 }
748 pictures_.clear(); 736 pictures_.clear();
749 } 737 }
750 738
751 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() { 739 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() {
752 DCHECK_EQ(message_loop_, MessageLoop::current()); 740 DCHECK_EQ(message_loop_, MessageLoop::current());
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1090
1103 bool OmxVideoDecodeAccelerator::SendCommandToPort( 1091 bool OmxVideoDecodeAccelerator::SendCommandToPort(
1104 OMX_COMMANDTYPE cmd, int port_index) { 1092 OMX_COMMANDTYPE cmd, int port_index) {
1105 DCHECK_EQ(message_loop_, MessageLoop::current()); 1093 DCHECK_EQ(message_loop_, MessageLoop::current());
1106 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, 1094 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_,
1107 cmd, port_index, 0); 1095 cmd, port_index, 0);
1108 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, 1096 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd,
1109 PLATFORM_FAILURE, false); 1097 PLATFORM_FAILURE, false);
1110 return true; 1098 return true;
1111 } 1099 }
OLDNEW
« no previous file with comments | « content/common/gpu/media/omx_video_decode_accelerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698