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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 this, &omx_accelerator_callbacks); | 192 this, &omx_accelerator_callbacks); |
193 RETURN_ON_OMX_FAILURE(result, | 193 RETURN_ON_OMX_FAILURE(result, |
194 "Failed to OMX_GetHandle on: " << component.get(), | 194 "Failed to OMX_GetHandle on: " << component.get(), |
195 PLATFORM_FAILURE, false); | 195 PLATFORM_FAILURE, false); |
196 client_state_ = OMX_StateLoaded; | 196 client_state_ = OMX_StateLoaded; |
197 | 197 |
198 component_name_is_nvidia_h264ext_ = !strcmp( | 198 component_name_is_nvidia_h264ext_ = !strcmp( |
199 reinterpret_cast<char *>(component.get()), | 199 reinterpret_cast<char *>(component.get()), |
200 "OMX.Nvidia.h264ext.decode"); | 200 "OMX.Nvidia.h264ext.decode"); |
201 | 201 |
| 202 bool component_name_is_sec_h264ext = !strcmp( |
| 203 reinterpret_cast<char *>(component.get()), |
| 204 "OMX.SEC.AVC.Decoder"); |
| 205 Gles2TextureToEglImageTranslator* texture_to_egl_image_translator = |
| 206 new Gles2TextureToEglImageTranslator(component_name_is_sec_h264ext); |
| 207 texture_to_egl_image_translator_.reset(texture_to_egl_image_translator); |
| 208 |
202 // Get the port information. This will obtain information about the number of | 209 // Get the port information. This will obtain information about the number of |
203 // ports and index of the first port. | 210 // ports and index of the first port. |
204 OMX_PORT_PARAM_TYPE port_param; | 211 OMX_PORT_PARAM_TYPE port_param; |
205 InitParam(*this, &port_param); | 212 InitParam(*this, &port_param); |
206 result = OMX_GetParameter(component_handle_, OMX_IndexParamVideoInit, | 213 result = OMX_GetParameter(component_handle_, OMX_IndexParamVideoInit, |
207 &port_param); | 214 &port_param); |
208 RETURN_ON_FAILURE(result == OMX_ErrorNone && port_param.nPorts == 2, | 215 RETURN_ON_FAILURE(result == OMX_ErrorNone && port_param.nPorts == 2, |
209 "Failed to get Port Param: " << result << ", " | 216 "Failed to get Port Param: " << result << ", " |
210 << port_param.nPorts, | 217 << port_param.nPorts, |
211 PLATFORM_FAILURE, false); | 218 PLATFORM_FAILURE, false); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 344 |
338 void OmxVideoDecodeAccelerator::AssignPictureBuffers( | 345 void OmxVideoDecodeAccelerator::AssignPictureBuffers( |
339 const std::vector<media::PictureBuffer>& buffers) { | 346 const std::vector<media::PictureBuffer>& buffers) { |
340 DCHECK_EQ(message_loop_, MessageLoop::current()); | 347 DCHECK_EQ(message_loop_, MessageLoop::current()); |
341 RETURN_ON_FAILURE(CanFillBuffer(), "Can't fill buffer", ILLEGAL_STATE,); | 348 RETURN_ON_FAILURE(CanFillBuffer(), "Can't fill buffer", ILLEGAL_STATE,); |
342 | 349 |
343 DCHECK_EQ(output_buffers_at_component_, 0); | 350 DCHECK_EQ(output_buffers_at_component_, 0); |
344 DCHECK_EQ(fake_output_buffers_.size(), 0U); | 351 DCHECK_EQ(fake_output_buffers_.size(), 0U); |
345 DCHECK_EQ(pictures_.size(), 0U); | 352 DCHECK_EQ(pictures_.size(), 0U); |
346 | 353 |
347 static Gles2TextureToEglImageTranslator texture2eglImage_translator; | |
348 for (size_t i = 0; i < buffers.size(); ++i) { | 354 for (size_t i = 0; i < buffers.size(); ++i) { |
349 EGLImageKHR egl_image = texture2eglImage_translator.TranslateToEglImage( | 355 EGLImageKHR egl_image = |
350 egl_display_, egl_context_, buffers[i].texture_id()); | 356 texture_to_egl_image_translator_->TranslateToEglImage( |
| 357 egl_display_, egl_context_, |
| 358 buffers[i].texture_id(), |
| 359 last_requested_picture_buffer_dimensions_); |
351 CHECK(pictures_.insert(std::make_pair( | 360 CHECK(pictures_.insert(std::make_pair( |
352 buffers[i].id(), OutputPicture(buffers[i], NULL, egl_image))).second); | 361 buffers[i].id(), OutputPicture(buffers[i], NULL, egl_image))).second); |
353 } | 362 } |
354 | 363 |
355 if (pictures_.size() < kNumPictureBuffers) | 364 if (pictures_.size() < kNumPictureBuffers) |
356 return; // get all the buffers first. | 365 return; // get all the buffers first. |
357 DCHECK_EQ(pictures_.size(), kNumPictureBuffers); | 366 DCHECK_EQ(pictures_.size(), kNumPictureBuffers); |
358 | 367 |
359 // These do their own RETURN_ON_FAILURE dances. | 368 // These do their own RETURN_ON_FAILURE dances. |
360 if (!AllocateOutputBuffers()) | 369 if (!AllocateOutputBuffers()) |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 free_input_buffers_.pop(); | 698 free_input_buffers_.pop(); |
690 result = OMX_FreeBuffer(component_handle_, input_port_, omx_buffer); | 699 result = OMX_FreeBuffer(component_handle_, input_port_, omx_buffer); |
691 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); | 700 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); |
692 } | 701 } |
693 } | 702 } |
694 | 703 |
695 void OmxVideoDecodeAccelerator::FreeOutputBuffers() { | 704 void OmxVideoDecodeAccelerator::FreeOutputBuffers() { |
696 DCHECK_EQ(message_loop_, MessageLoop::current()); | 705 DCHECK_EQ(message_loop_, MessageLoop::current()); |
697 // Calls to OMX to free buffers. | 706 // Calls to OMX to free buffers. |
698 OMX_ERRORTYPE result; | 707 OMX_ERRORTYPE result; |
699 static Gles2TextureToEglImageTranslator texture2eglImage_translator; | |
700 for (OutputPictureById::iterator it = pictures_.begin(); | 708 for (OutputPictureById::iterator it = pictures_.begin(); |
701 it != pictures_.end(); ++it) { | 709 it != pictures_.end(); ++it) { |
702 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header; | 710 OMX_BUFFERHEADERTYPE* omx_buffer = it->second.omx_buffer_header; |
703 DCHECK(omx_buffer); | 711 DCHECK(omx_buffer); |
704 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate); | 712 delete reinterpret_cast<media::Picture*>(omx_buffer->pAppPrivate); |
705 result = OMX_FreeBuffer(component_handle_, output_port_, omx_buffer); | 713 result = OMX_FreeBuffer(component_handle_, output_port_, omx_buffer); |
706 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); | 714 RETURN_ON_OMX_FAILURE(result, "OMX_FreeBuffer", PLATFORM_FAILURE,); |
707 texture2eglImage_translator.DestroyEglImage(egl_display_, | 715 texture_to_egl_image_translator_->DestroyEglImage(egl_display_, |
708 it->second.egl_image); | 716 it->second.egl_image); |
709 if (client_) | 717 if (client_) |
710 client_->DismissPictureBuffer(it->first); | 718 client_->DismissPictureBuffer(it->first); |
711 } | 719 } |
712 pictures_.clear(); | 720 pictures_.clear(); |
713 } | 721 } |
714 | 722 |
715 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() { | 723 void OmxVideoDecodeAccelerator::OnOutputPortDisabled() { |
716 DCHECK_EQ(message_loop_, MessageLoop::current()); | 724 DCHECK_EQ(message_loop_, MessageLoop::current()); |
717 OMX_PARAM_PORTDEFINITIONTYPE port_format; | 725 OMX_PARAM_PORTDEFINITIONTYPE port_format; |
718 InitParam(*this, &port_format); | 726 InitParam(*this, &port_format); |
719 port_format.nPortIndex = output_port_; | 727 port_format.nPortIndex = output_port_; |
720 OMX_ERRORTYPE result = OMX_GetParameter( | 728 OMX_ERRORTYPE result = OMX_GetParameter( |
721 component_handle_, OMX_IndexParamPortDefinition, &port_format); | 729 component_handle_, OMX_IndexParamPortDefinition, &port_format); |
722 RETURN_ON_OMX_FAILURE(result, "OMX_GetParameter", PLATFORM_FAILURE,); | 730 RETURN_ON_OMX_FAILURE(result, "OMX_GetParameter", PLATFORM_FAILURE,); |
723 DCHECK_EQ(port_format.nBufferCountMin, kNumPictureBuffers); | 731 DCHECK_EQ(port_format.nBufferCountMin, kNumPictureBuffers); |
724 | 732 |
725 // TODO(fischman): to support mid-stream resize, need to free/dismiss any | 733 // 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 | 734 // |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). | 735 // this (there's already freeing logic there, which should not be duplicated). |
728 | 736 |
729 // Request picture buffers to be handed to the component. | 737 // Request picture buffers to be handed to the component. |
730 // ProvidePictureBuffers() will trigger AssignPictureBuffers, which ultimately | 738 // ProvidePictureBuffers() will trigger AssignPictureBuffers, which ultimately |
731 // assigns the textures to the component and re-enables the port. | 739 // assigns the textures to the component and re-enables the port. |
732 const OMX_VIDEO_PORTDEFINITIONTYPE& vformat = port_format.format.video; | 740 const OMX_VIDEO_PORTDEFINITIONTYPE& vformat = port_format.format.video; |
| 741 last_requested_picture_buffer_dimensions_.SetSize(vformat.nFrameWidth, |
| 742 vformat.nFrameHeight); |
733 if (client_) { | 743 if (client_) { |
734 client_->ProvidePictureBuffers( | 744 client_->ProvidePictureBuffers( |
735 kNumPictureBuffers, | 745 kNumPictureBuffers, |
736 gfx::Size(vformat.nFrameWidth, vformat.nFrameHeight)); | 746 gfx::Size(vformat.nFrameWidth, vformat.nFrameHeight)); |
737 } | 747 } |
738 } | 748 } |
739 | 749 |
740 void OmxVideoDecodeAccelerator::OnOutputPortEnabled() { | 750 void OmxVideoDecodeAccelerator::OnOutputPortEnabled() { |
741 DCHECK_EQ(message_loop_, MessageLoop::current()); | 751 DCHECK_EQ(message_loop_, MessageLoop::current()); |
742 | 752 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 | 1043 |
1034 bool OmxVideoDecodeAccelerator::SendCommandToPort( | 1044 bool OmxVideoDecodeAccelerator::SendCommandToPort( |
1035 OMX_COMMANDTYPE cmd, int port_index) { | 1045 OMX_COMMANDTYPE cmd, int port_index) { |
1036 DCHECK_EQ(message_loop_, MessageLoop::current()); | 1046 DCHECK_EQ(message_loop_, MessageLoop::current()); |
1037 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, | 1047 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, |
1038 cmd, port_index, 0); | 1048 cmd, port_index, 0); |
1039 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, | 1049 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, |
1040 PLATFORM_FAILURE, false); | 1050 PLATFORM_FAILURE, false); |
1041 return true; | 1051 return true; |
1042 } | 1052 } |
OLD | NEW |