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

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

Issue 9346012: Video decode in hardware on ARM platform. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 10 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
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 : message_loop_(MessageLoop::current()), 102 : message_loop_(MessageLoop::current()),
103 component_handle_(NULL), 103 component_handle_(NULL),
104 client_state_(OMX_StateMax), 104 client_state_(OMX_StateMax),
105 current_state_change_(NO_TRANSITION), 105 current_state_change_(NO_TRANSITION),
106 input_buffer_count_(0), 106 input_buffer_count_(0),
107 input_buffer_size_(0), 107 input_buffer_size_(0),
108 input_port_(0), 108 input_port_(0),
109 input_buffers_at_component_(0), 109 input_buffers_at_component_(0),
110 output_port_(0), 110 output_port_(0),
111 output_buffers_at_component_(0), 111 output_buffers_at_component_(0),
112 last_requested_picture_buffer_dimensions_(gfx::Size(-1, -1)),
Ami GONE FROM CHROMIUM 2012/02/20 16:54:28 gfx::Size()'s default ctor initializes with 0's, a
112 client_(client), 113 client_(client),
113 profile_(OMX_VIDEO_AVCProfileMax), 114 profile_(OMX_VIDEO_AVCProfileMax),
114 component_name_is_nvidia_h264ext_(false) { 115 component_name_is_nvidia_h264ext_(false),
116 component_name_is_sec_h264ext_(false) {
115 RETURN_ON_FAILURE(AreOMXFunctionPointersInitialized(), 117 RETURN_ON_FAILURE(AreOMXFunctionPointersInitialized(),
116 "Failed to load openmax library", PLATFORM_FAILURE,); 118 "Failed to load openmax library", PLATFORM_FAILURE,);
117 RETURN_ON_OMX_FAILURE(omx_init(), "Failed to init OpenMAX core", 119 RETURN_ON_OMX_FAILURE(omx_init(), "Failed to init OpenMAX core",
118 PLATFORM_FAILURE,); 120 PLATFORM_FAILURE,);
119 } 121 }
120 122
121 OmxVideoDecodeAccelerator::~OmxVideoDecodeAccelerator() { 123 OmxVideoDecodeAccelerator::~OmxVideoDecodeAccelerator() {
122 DCHECK_EQ(message_loop_, MessageLoop::current()); 124 DCHECK_EQ(message_loop_, MessageLoop::current());
123 DCHECK(free_input_buffers_.empty()); 125 DCHECK(free_input_buffers_.empty());
124 DCHECK_EQ(0, input_buffers_at_component_); 126 DCHECK_EQ(0, input_buffers_at_component_);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 this, &omx_accelerator_callbacks); 194 this, &omx_accelerator_callbacks);
193 RETURN_ON_OMX_FAILURE(result, 195 RETURN_ON_OMX_FAILURE(result,
194 "Failed to OMX_GetHandle on: " << component.get(), 196 "Failed to OMX_GetHandle on: " << component.get(),
195 PLATFORM_FAILURE, false); 197 PLATFORM_FAILURE, false);
196 client_state_ = OMX_StateLoaded; 198 client_state_ = OMX_StateLoaded;
197 199
198 component_name_is_nvidia_h264ext_ = !strcmp( 200 component_name_is_nvidia_h264ext_ = !strcmp(
199 reinterpret_cast<char *>(component.get()), 201 reinterpret_cast<char *>(component.get()),
200 "OMX.Nvidia.h264ext.decode"); 202 "OMX.Nvidia.h264ext.decode");
201 203
204 component_name_is_sec_h264ext_ = !strcmp(
Ami GONE FROM CHROMIUM 2012/02/20 16:54:28 In the interest of keeping CL's minimal, can you r
205 reinterpret_cast<char *>(component.get()),
206 "OMX.SEC.AVC.Decoder");
207 Gles2TextureToEglImageTranslator* texture_to_egl_image_translator =
208 new Gles2TextureToEglImageTranslator(component_name_is_sec_h264ext_);
209 texture_to_egl_image_translator_.reset(texture_to_egl_image_translator);
210
202 // Get the port information. This will obtain information about the number of 211 // Get the port information. This will obtain information about the number of
203 // ports and index of the first port. 212 // ports and index of the first port.
204 OMX_PORT_PARAM_TYPE port_param; 213 OMX_PORT_PARAM_TYPE port_param;
205 InitParam(*this, &port_param); 214 InitParam(*this, &port_param);
206 result = OMX_GetParameter(component_handle_, OMX_IndexParamVideoInit, 215 result = OMX_GetParameter(component_handle_, OMX_IndexParamVideoInit,
207 &port_param); 216 &port_param);
208 RETURN_ON_FAILURE(result == OMX_ErrorNone && port_param.nPorts == 2, 217 RETURN_ON_FAILURE(result == OMX_ErrorNone && port_param.nPorts == 2,
209 "Failed to get Port Param: " << result << ", " 218 "Failed to get Port Param: " << result << ", "
210 << port_param.nPorts, 219 << port_param.nPorts,
211 PLATFORM_FAILURE, false); 220 PLATFORM_FAILURE, false);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 346
338 void OmxVideoDecodeAccelerator::AssignPictureBuffers( 347 void OmxVideoDecodeAccelerator::AssignPictureBuffers(
339 const std::vector<media::PictureBuffer>& buffers) { 348 const std::vector<media::PictureBuffer>& buffers) {
340 DCHECK_EQ(message_loop_, MessageLoop::current()); 349 DCHECK_EQ(message_loop_, MessageLoop::current());
341 RETURN_ON_FAILURE(CanFillBuffer(), "Can't fill buffer", ILLEGAL_STATE,); 350 RETURN_ON_FAILURE(CanFillBuffer(), "Can't fill buffer", ILLEGAL_STATE,);
342 351
343 DCHECK_EQ(output_buffers_at_component_, 0); 352 DCHECK_EQ(output_buffers_at_component_, 0);
344 DCHECK_EQ(fake_output_buffers_.size(), 0U); 353 DCHECK_EQ(fake_output_buffers_.size(), 0U);
345 DCHECK_EQ(pictures_.size(), 0U); 354 DCHECK_EQ(pictures_.size(), 0U);
346 355
347 static Gles2TextureToEglImageTranslator texture2eglImage_translator;
348 for (size_t i = 0; i < buffers.size(); ++i) { 356 for (size_t i = 0; i < buffers.size(); ++i) {
349 EGLImageKHR egl_image = texture2eglImage_translator.TranslateToEglImage( 357 EGLImageKHR egl_image =
350 egl_display_, egl_context_, buffers[i].texture_id()); 358 texture_to_egl_image_translator_->TranslateToEglImage(
Ami GONE FROM CHROMIUM 2012/02/20 16:54:28 indentation is wrong here; it should be 4 spaces f
359 egl_display_, egl_context_,
360 buffers[i].texture_id(),
361 &last_requested_picture_buffer_dimensions_);
351 CHECK(pictures_.insert(std::make_pair( 362 CHECK(pictures_.insert(std::make_pair(
352 buffers[i].id(), OutputPicture(buffers[i], NULL, egl_image))).second); 363 buffers[i].id(), OutputPicture(buffers[i], NULL, egl_image))).second);
353 } 364 }
354 365
355 if (pictures_.size() < kNumPictureBuffers) 366 if (pictures_.size() < kNumPictureBuffers)
356 return; // get all the buffers first. 367 return; // get all the buffers first.
357 DCHECK_EQ(pictures_.size(), kNumPictureBuffers); 368 DCHECK_EQ(pictures_.size(), kNumPictureBuffers);
358 369
359 // These do their own RETURN_ON_FAILURE dances. 370 // These do their own RETURN_ON_FAILURE dances.
360 if (!AllocateOutputBuffers()) 371 if (!AllocateOutputBuffers())
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 free_input_buffers_.pop(); 700 free_input_buffers_.pop();
690 result = OMX_FreeBuffer(component_handle_, input_port_, omx_buffer); 701 result = OMX_FreeBuffer(component_handle_, input_port_, omx_buffer);
691 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); 702 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,);
692 } 703 }
693 } 704 }
694 705
695 void OmxVideoDecodeAccelerator::FreeOutputBuffers() { 706 void OmxVideoDecodeAccelerator::FreeOutputBuffers() {
696 DCHECK_EQ(message_loop_, MessageLoop::current()); 707 DCHECK_EQ(message_loop_, MessageLoop::current());
697 // Calls to OMX to free buffers. 708 // Calls to OMX to free buffers.
698 OMX_ERRORTYPE result; 709 OMX_ERRORTYPE result;
699 static Gles2TextureToEglImageTranslator texture2eglImage_translator;
700 for (OutputPictureById::iterator it = pictures_.begin(); 710 for (OutputPictureById::iterator it = pictures_.begin();
701 it != pictures_.end(); ++it) { 711 it != pictures_.end(); ++it) {
702 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header; 712 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header;
703 DCHECK(omx_buffer); 713 DCHECK(omx_buffer);
704 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate); 714 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate);
705 result = OMX_FreeBuffer(component_handle_, output_port_, omx_buffer); 715 result = OMX_FreeBuffer(component_handle_, output_port_, omx_buffer);
706 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); 716 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,);
707 texture2eglImage_translator.DestroyEglImage(egl_display_, 717 texture_to_egl_image_translator_->DestroyEglImage(egl_display_,
708 it->second.egl_image); 718 it->second.egl_image);
Ami GONE FROM CHROMIUM 2012/02/20 16:54:28 indent is off
709 if (client_) 719 if (client_)
710 client_->DismissPictureBuffer(it->first); 720 client_->DismissPictureBuffer(it->first);
711 } 721 }
712 pictures_.clear(); 722 pictures_.clear();
713 } 723 }
714 724
715 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() { 725 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() {
716 DCHECK_EQ(message_loop_, MessageLoop::current()); 726 DCHECK_EQ(message_loop_, MessageLoop::current());
717 OMX_PARAM_PORTDEFINITIONTYPE port_format; 727 OMX_PARAM_PORTDEFINITIONTYPE port_format;
718 InitParam(*this, &port_format); 728 InitParam(*this, &port_format);
719 port_format.nPortIndex = output_port_; 729 port_format.nPortIndex = output_port_;
720 OMX_ERRORTYPE result = OMX_GetParameter( 730 OMX_ERRORTYPE result = OMX_GetParameter(
721 component_handle_, OMX_IndexParamPortDefinition, &port_format); 731 component_handle_, OMX_IndexParamPortDefinition, &port_format);
722 RETURN_ON_OMX_FAILURE(result, "OMX_GetParameter", PLATFORM_FAILURE,); 732 RETURN_ON_OMX_FAILURE(result, "OMX_GetParameter", PLATFORM_FAILURE,);
723 DCHECK_EQ(port_format.nBufferCountMin, kNumPictureBuffers); 733 DCHECK_EQ(port_format.nBufferCountMin, kNumPictureBuffers);
724 734
725 // TODO(fischman): to support mid-stream resize, need to free/dismiss any 735 // TODO(fischman): to support mid-stream resize, need to free/dismiss any
726 // |pictures_| we already have. Make sure that the shutdown-path agrees with 736 // |pictures_| we already have. Make sure that the shutdown-path agrees with
727 // this (there's already freeing logic there, which should not be duplicated). 737 // this (there's already freeing logic there, which should not be duplicated).
728 738
729 // Request picture buffers to be handed to the component. 739 // Request picture buffers to be handed to the component.
730 // ProvidePictureBuffers() will trigger AssignPictureBuffers, which ultimately 740 // ProvidePictureBuffers() will trigger AssignPictureBuffers, which ultimately
731 // assigns the textures to the component and re-enables the port. 741 // assigns the textures to the component and re-enables the port.
732 const OMX_VIDEO_PORTDEFINITIONTYPE& vformat = port_format.format.video; 742 const OMX_VIDEO_PORTDEFINITIONTYPE& vformat = port_format.format.video;
743 last_requested_picture_buffer_dimensions_.SetSize(vformat.nFrameWidth,
744 vformat.nFrameHeight);
733 if (client_) { 745 if (client_) {
734 client_->ProvidePictureBuffers( 746 client_->ProvidePictureBuffers(
735 kNumPictureBuffers, 747 kNumPictureBuffers,
736 gfx::Size(vformat.nFrameWidth, vformat.nFrameHeight)); 748 gfx::Size(vformat.nFrameWidth, vformat.nFrameHeight));
737 } 749 }
738 } 750 }
739 751
740 void OmxVideoDecodeAccelerator::OnOutputPortEnabled() { 752 void OmxVideoDecodeAccelerator::OnOutputPortEnabled() {
741 DCHECK_EQ(message_loop_, MessageLoop::current()); 753 DCHECK_EQ(message_loop_, MessageLoop::current());
742 754
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 1045
1034 bool OmxVideoDecodeAccelerator::SendCommandToPort( 1046 bool OmxVideoDecodeAccelerator::SendCommandToPort(
1035 OMX_COMMANDTYPE cmd, int port_index) { 1047 OMX_COMMANDTYPE cmd, int port_index) {
1036 DCHECK_EQ(message_loop_, MessageLoop::current()); 1048 DCHECK_EQ(message_loop_, MessageLoop::current());
1037 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, 1049 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_,
1038 cmd, port_index, 0); 1050 cmd, port_index, 0);
1039 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, 1051 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd,
1040 PLATFORM_FAILURE, false); 1052 PLATFORM_FAILURE, false);
1041 return true; 1053 return true;
1042 } 1054 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698