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

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

Issue 10808058: Add support for VP8 decode to OmxVideoDecodeAccelerator, for HW that supports it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: scherkus comments. Created 8 years, 5 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 init_begun_(false), 105 init_begun_(false),
106 client_state_(OMX_StateMax), 106 client_state_(OMX_StateMax),
107 current_state_change_(NO_TRANSITION), 107 current_state_change_(NO_TRANSITION),
108 input_buffer_count_(0), 108 input_buffer_count_(0),
109 input_buffer_size_(0), 109 input_buffer_size_(0),
110 input_port_(0), 110 input_port_(0),
111 input_buffers_at_component_(0), 111 input_buffers_at_component_(0),
112 output_port_(0), 112 output_port_(0),
113 output_buffers_at_component_(0), 113 output_buffers_at_component_(0),
114 client_(client), 114 client_(client),
115 profile_(OMX_VIDEO_AVCProfileMax), 115 codec_(UNKNOWN),
116 h264_profile_(OMX_VIDEO_AVCProfileMax),
116 component_name_is_nvidia_h264ext_(false) { 117 component_name_is_nvidia_h264ext_(false) {
117 RETURN_ON_FAILURE(AreOMXFunctionPointersInitialized(), 118 RETURN_ON_FAILURE(AreOMXFunctionPointersInitialized(),
118 "Failed to load openmax library", PLATFORM_FAILURE,); 119 "Failed to load openmax library", PLATFORM_FAILURE,);
119 RETURN_ON_OMX_FAILURE(omx_init(), "Failed to init OpenMAX core", 120 RETURN_ON_OMX_FAILURE(omx_init(), "Failed to init OpenMAX core",
120 PLATFORM_FAILURE,); 121 PLATFORM_FAILURE,);
121 } 122 }
122 123
123 OmxVideoDecodeAccelerator::~OmxVideoDecodeAccelerator() { 124 OmxVideoDecodeAccelerator::~OmxVideoDecodeAccelerator() {
124 DCHECK_EQ(message_loop_, MessageLoop::current()); 125 DCHECK_EQ(message_loop_, MessageLoop::current());
125 DCHECK(free_input_buffers_.empty()); 126 DCHECK(free_input_buffers_.empty());
(...skipping 13 matching lines...) Expand all
139 template <typename T> 140 template <typename T>
140 static void InitParam(const OmxVideoDecodeAccelerator& dec, T* param) { 141 static void InitParam(const OmxVideoDecodeAccelerator& dec, T* param) {
141 memset(param, 0, sizeof(T)); 142 memset(param, 0, sizeof(T));
142 param->nVersion.nVersion = 0x00000101; 143 param->nVersion.nVersion = 0x00000101;
143 param->nSize = sizeof(T); 144 param->nSize = sizeof(T);
144 } 145 }
145 146
146 bool OmxVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile) { 147 bool OmxVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile) {
147 DCHECK_EQ(message_loop_, MessageLoop::current()); 148 DCHECK_EQ(message_loop_, MessageLoop::current());
148 149
149 RETURN_ON_FAILURE((profile >= media::H264PROFILE_MIN && 150 if (profile >= media::H264PROFILE_MIN && profile <= media::H264PROFILE_MAX) {
150 profile <= media::H264PROFILE_MAX), 151 codec_ = H264;
151 "Only h264 supported", INVALID_ARGUMENT, false); 152 h264_profile_ = MapH264ProfileToOMXAVCProfile(profile);
152 profile_ = MapH264ProfileToOMXAVCProfile(profile); 153 RETURN_ON_FAILURE(h264_profile_ != OMX_VIDEO_AVCProfileMax,
153 RETURN_ON_FAILURE(profile_ != OMX_VIDEO_AVCProfileMax, 154 "Unexpected profile", INVALID_ARGUMENT, false);
154 "Unexpected profile", INVALID_ARGUMENT, false); 155 } else if (profile == media::VP8PROFILE_MAIN) {
156 codec_ = VP8;
157 } else {
158 RETURN_ON_FAILURE(false, "Unsupported profile: " << profile,
159 INVALID_ARGUMENT, false);
160 }
155 161
156 if (!CreateComponent()) // Does its own RETURN_ON_FAILURE dances. 162 if (!CreateComponent()) // Does its own RETURN_ON_FAILURE dances.
157 return false; 163 return false;
158 164
159 DCHECK_EQ(current_state_change_, NO_TRANSITION); 165 DCHECK_EQ(current_state_change_, NO_TRANSITION);
160 current_state_change_ = INITIALIZING; 166 current_state_change_ = INITIALIZING;
161 BeginTransitionToState(OMX_StateIdle); 167 BeginTransitionToState(OMX_StateIdle);
162 168
163 if (!AllocateInputBuffers()) // Does its own RETURN_ON_FAILURE dances. 169 if (!AllocateInputBuffers()) // Does its own RETURN_ON_FAILURE dances.
164 return false; 170 return false;
165 if (!AllocateFakeOutputBuffers()) // Does its own RETURN_ON_FAILURE dances. 171 if (!AllocateFakeOutputBuffers()) // Does its own RETURN_ON_FAILURE dances.
166 return false; 172 return false;
167 173
168 init_begun_ = true; 174 init_begun_ = true;
169 return true; 175 return true;
170 } 176 }
171 177
172 bool OmxVideoDecodeAccelerator::CreateComponent() { 178 bool OmxVideoDecodeAccelerator::CreateComponent() {
173 DCHECK_EQ(message_loop_, MessageLoop::current()); 179 DCHECK_EQ(message_loop_, MessageLoop::current());
174 OMX_CALLBACKTYPE omx_accelerator_callbacks = { 180 OMX_CALLBACKTYPE omx_accelerator_callbacks = {
175 &OmxVideoDecodeAccelerator::EventHandler, 181 &OmxVideoDecodeAccelerator::EventHandler,
176 &OmxVideoDecodeAccelerator::EmptyBufferCallback, 182 &OmxVideoDecodeAccelerator::EmptyBufferCallback,
177 &OmxVideoDecodeAccelerator::FillBufferCallback 183 &OmxVideoDecodeAccelerator::FillBufferCallback
178 }; 184 };
179 185
180 // TODO(vhiremath@nvidia.com) Get this role_name from the configs 186 // TODO(vhiremath@nvidia.com) Get this role_name from the configs
181 // For now hard coding to avc. 187 // For now hard-coding.
182 OMX_STRING role_name = const_cast<OMX_STRING>("video_decoder.avc"); 188 OMX_STRING role_name = codec_ == H264 ?
189 const_cast<OMX_STRING>("video_decoder.avc") :
190 const_cast<OMX_STRING>("video_decoder.vpx");
183 // Get the first component for this role and set the role on it. 191 // Get the first component for this role and set the role on it.
184 OMX_U32 num_components = 1; 192 OMX_U32 num_components = 1;
185 scoped_array<OMX_U8> component(new OMX_U8[OMX_MAX_STRINGNAME_SIZE]); 193 std::string component(OMX_MAX_STRINGNAME_SIZE, '\0');
194 char* component_as_array = string_as_array(&component);
186 OMX_ERRORTYPE result = omx_get_components_of_role( 195 OMX_ERRORTYPE result = omx_get_components_of_role(
187 role_name, &num_components, reinterpret_cast<OMX_U8**>(&component)); 196 role_name, &num_components,
188 RETURN_ON_OMX_FAILURE(result, "Unsupport role: " << role_name, 197 reinterpret_cast<OMX_U8**>(&component_as_array));
198 RETURN_ON_OMX_FAILURE(result, "Unsupported role: " << role_name,
189 PLATFORM_FAILURE, false); 199 PLATFORM_FAILURE, false);
190 RETURN_ON_FAILURE(num_components == 1, "No components for: " << role_name, 200 RETURN_ON_FAILURE(num_components == 1, "No components for: " << role_name,
191 PLATFORM_FAILURE, false); 201 PLATFORM_FAILURE, false);
202 component_name_is_nvidia_h264ext_ = component == "OMX.Nvidia.h264ext.decode";
192 203
193 // Get the handle to the component. 204 // Get the handle to the component.
194 result = omx_gethandle( 205 result = omx_gethandle(
195 &component_handle_, reinterpret_cast<OMX_STRING>(component.get()), 206 &component_handle_,
207 reinterpret_cast<OMX_STRING>(string_as_array(&component)),
196 this, &omx_accelerator_callbacks); 208 this, &omx_accelerator_callbacks);
197 RETURN_ON_OMX_FAILURE(result, 209 RETURN_ON_OMX_FAILURE(result,
198 "Failed to OMX_GetHandle on: " << component.get(), 210 "Failed to OMX_GetHandle on: " << component,
199 PLATFORM_FAILURE, false); 211 PLATFORM_FAILURE, false);
200 client_state_ = OMX_StateLoaded; 212 client_state_ = OMX_StateLoaded;
201 213
202 component_name_is_nvidia_h264ext_ = !strcmp( 214 texture_to_egl_image_translator_.reset(new Gles2TextureToEglImageTranslator(
203 reinterpret_cast<char *>(component.get()), 215 StartsWithASCII(component, "OMX.SEC.", true)));
204 "OMX.Nvidia.h264ext.decode");
205
206 bool component_name_is_sec_h264ext = !strcmp(
207 reinterpret_cast<char *>(component.get()),
208 "OMX.SEC.AVC.Decoder");
209 Gles2TextureToEglImageTranslator* texture_to_egl_image_translator =
210 new Gles2TextureToEglImageTranslator(component_name_is_sec_h264ext);
211 texture_to_egl_image_translator_.reset(texture_to_egl_image_translator);
212 216
213 // Get the port information. This will obtain information about the number of 217 // Get the port information. This will obtain information about the number of
214 // ports and index of the first port. 218 // ports and index of the first port.
215 OMX_PORT_PARAM_TYPE port_param; 219 OMX_PORT_PARAM_TYPE port_param;
216 InitParam(*this, &port_param); 220 InitParam(*this, &port_param);
217 result = OMX_GetParameter(component_handle_, OMX_IndexParamVideoInit, 221 result = OMX_GetParameter(component_handle_, OMX_IndexParamVideoInit,
218 &port_param); 222 &port_param);
219 RETURN_ON_FAILURE(result == OMX_ErrorNone && port_param.nPorts == 2, 223 RETURN_ON_FAILURE(result == OMX_ErrorNone && port_param.nPorts == 2,
220 "Failed to get Port Param: " << result << ", " 224 "Failed to get Port Param: " << result << ", "
221 << port_param.nPorts, 225 << port_param.nPorts,
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 OMX_INDEXTYPE extension_index; 495 OMX_INDEXTYPE extension_index;
492 OMX_ERRORTYPE result = OMX_GetExtensionIndex( 496 OMX_ERRORTYPE result = OMX_GetExtensionIndex(
493 component_handle_, 497 component_handle_,
494 const_cast<char*>("OMX.Nvidia.index.config.checkresources"), 498 const_cast<char*>("OMX.Nvidia.index.config.checkresources"),
495 &extension_index); 499 &extension_index);
496 RETURN_ON_OMX_FAILURE(result, 500 RETURN_ON_OMX_FAILURE(result,
497 "Failed to get the extension", 501 "Failed to get the extension",
498 PLATFORM_FAILURE,); 502 PLATFORM_FAILURE,);
499 OMX_VIDEO_PARAM_PROFILELEVELTYPE video_profile_level; 503 OMX_VIDEO_PARAM_PROFILELEVELTYPE video_profile_level;
500 InitParam(*this, &video_profile_level); 504 InitParam(*this, &video_profile_level);
501 video_profile_level.eProfile = profile_; 505 DCHECK_EQ(codec_, H264);
506 video_profile_level.eProfile = h264_profile_;
502 result = OMX_SetConfig(component_handle_, extension_index, 507 result = OMX_SetConfig(component_handle_, extension_index,
503 &video_profile_level); 508 &video_profile_level);
504 RETURN_ON_OMX_FAILURE(result, 509 RETURN_ON_OMX_FAILURE(result,
505 "Resource Allocation failed", 510 "Resource Allocation failed",
506 PLATFORM_FAILURE,); 511 PLATFORM_FAILURE,);
507 } 512 }
508 BeginTransitionToState(OMX_StateExecuting); 513 BeginTransitionToState(OMX_StateExecuting);
509 } 514 }
510 515
511 void OmxVideoDecodeAccelerator::OnReachedExecutingInInitializing() { 516 void OmxVideoDecodeAccelerator::OnReachedExecutingInInitializing() {
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1063
1059 bool OmxVideoDecodeAccelerator::SendCommandToPort( 1064 bool OmxVideoDecodeAccelerator::SendCommandToPort(
1060 OMX_COMMANDTYPE cmd, int port_index) { 1065 OMX_COMMANDTYPE cmd, int port_index) {
1061 DCHECK_EQ(message_loop_, MessageLoop::current()); 1066 DCHECK_EQ(message_loop_, MessageLoop::current());
1062 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, 1067 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_,
1063 cmd, port_index, 0); 1068 cmd, port_index, 0);
1064 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, 1069 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd,
1065 PLATFORM_FAILURE, false); 1070 PLATFORM_FAILURE, false);
1066 return true; 1071 return true;
1067 } 1072 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698