| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 OMXFreeHandle omx_free_handle = | 39 OMXFreeHandle omx_free_handle = |
| 40 reinterpret_cast<OMXFreeHandle>(dlsym(omx_handle, "OMX_FreeHandle")); | 40 reinterpret_cast<OMXFreeHandle>(dlsym(omx_handle, "OMX_FreeHandle")); |
| 41 OMXDeinit omx_deinit = | 41 OMXDeinit omx_deinit = |
| 42 reinterpret_cast<OMXDeinit>(dlsym(omx_handle, "OMX_Deinit")); | 42 reinterpret_cast<OMXDeinit>(dlsym(omx_handle, "OMX_Deinit")); |
| 43 | 43 |
| 44 static bool AreOMXFunctionPointersInitialized() { | 44 static bool AreOMXFunctionPointersInitialized() { |
| 45 return (omx_init && omx_gethandle && omx_get_components_of_role && | 45 return (omx_init && omx_gethandle && omx_get_components_of_role && |
| 46 omx_free_handle && omx_deinit); | 46 omx_free_handle && omx_deinit); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Maps the media::H264Profile members to the OMX_VIDEO_AVCPROFILETYPE members. | 49 // Maps h264-related Profile enum values to OMX_VIDEO_AVCPROFILETYPE values. |
| 50 static OMX_U32 MapH264ProfileToOMXAVCProfile(uint32 profile) { | 50 static OMX_U32 MapH264ProfileToOMXAVCProfile(uint32 profile) { |
| 51 switch (profile) { | 51 switch (profile) { |
| 52 case media::H264PROFILE_NONE: | 52 case media::VideoDecodeAccelerator::H264PROFILE_BASELINE: |
| 53 return OMX_VIDEO_AVCProfileMax; | |
| 54 case media::H264PROFILE_BASELINE: | |
| 55 return OMX_VIDEO_AVCProfileBaseline; | 53 return OMX_VIDEO_AVCProfileBaseline; |
| 56 case media::H264PROFILE_MAIN: | 54 case media::VideoDecodeAccelerator::H264PROFILE_MAIN: |
| 57 return OMX_VIDEO_AVCProfileMain; | 55 return OMX_VIDEO_AVCProfileMain; |
| 58 case media::H264PROFILE_EXTENDED: | 56 case media::VideoDecodeAccelerator::H264PROFILE_EXTENDED: |
| 59 return OMX_VIDEO_AVCProfileExtended; | 57 return OMX_VIDEO_AVCProfileExtended; |
| 60 case media::H264PROFILE_HIGH: | 58 case media::VideoDecodeAccelerator::H264PROFILE_HIGH: |
| 61 return OMX_VIDEO_AVCProfileHigh; | 59 return OMX_VIDEO_AVCProfileHigh; |
| 62 case media::H264PROFILE_HIGH10PROFILE: | 60 case media::VideoDecodeAccelerator::H264PROFILE_HIGH10PROFILE: |
| 63 return OMX_VIDEO_AVCProfileHigh10; | 61 return OMX_VIDEO_AVCProfileHigh10; |
| 64 case media::H264PROFILE_HIGH422PROFILE: | 62 case media::VideoDecodeAccelerator::H264PROFILE_HIGH422PROFILE: |
| 65 return OMX_VIDEO_AVCProfileHigh422; | 63 return OMX_VIDEO_AVCProfileHigh422; |
| 66 case media::H264PROFILE_HIGH444PREDICTIVEPROFILE: | 64 case media::VideoDecodeAccelerator::H264PROFILE_HIGH444PREDICTIVEPROFILE: |
| 67 return OMX_VIDEO_AVCProfileHigh444; | 65 return OMX_VIDEO_AVCProfileHigh444; |
| 68 // Below enums don't have equivalent enum in Openmax. | 66 // Below enums don't have equivalent enum in Openmax. |
| 69 case media::H264PROFILE_SCALABLEBASELINE: | 67 case media::VideoDecodeAccelerator::H264PROFILE_SCALABLEBASELINE: |
| 70 case media::H264PROFILE_SCALABLEHIGH: | 68 case media::VideoDecodeAccelerator::H264PROFILE_SCALABLEHIGH: |
| 71 case media::H264PROFILE_STEREOHIGH: | 69 case media::VideoDecodeAccelerator::H264PROFILE_STEREOHIGH: |
| 72 case media::H264PROFILE_MULTIVIEWHIGH: | 70 case media::VideoDecodeAccelerator::H264PROFILE_MULTIVIEWHIGH: |
| 73 // Nvidia OMX video decoder requires the same resources (as that of the | 71 // Nvidia OMX video decoder requires the same resources (as that of the |
| 74 // High profile) in every profile higher to the Main profile. | 72 // High profile) in every profile higher to the Main profile. |
| 75 return OMX_VIDEO_AVCProfileHigh444; | 73 return OMX_VIDEO_AVCProfileHigh444; |
| 74 default: |
| 75 NOTREACHED(); |
| 76 return OMX_VIDEO_AVCProfileMax; |
| 76 } | 77 } |
| 77 NOTREACHED(); | |
| 78 return OMX_VIDEO_AVCProfileMax; | |
| 79 } | 78 } |
| 80 | 79 |
| 81 // Helper macros for dealing with failure. If |result| evaluates false, emit | 80 // Helper macros for dealing with failure. If |result| evaluates false, emit |
| 82 // |log| to ERROR, register |error| with the decoder, and return |ret_val| | 81 // |log| to ERROR, register |error| with the decoder, and return |ret_val| |
| 83 // (which may be omitted for functions that return void). | 82 // (which may be omitted for functions that return void). |
| 84 #define RETURN_ON_FAILURE(result, log, error, ret_val) \ | 83 #define RETURN_ON_FAILURE(result, log, error, ret_val) \ |
| 85 do { \ | 84 do { \ |
| 86 if (!(result)) { \ | 85 if (!(result)) { \ |
| 87 LOG(ERROR) << log; \ | 86 LOG(ERROR) << log; \ |
| 88 StopOnError(error); \ | 87 StopOnError(error); \ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 DCHECK(pictures_.empty()); | 125 DCHECK(pictures_.empty()); |
| 127 } | 126 } |
| 128 | 127 |
| 129 void OmxVideoDecodeAccelerator::SetEglState( | 128 void OmxVideoDecodeAccelerator::SetEglState( |
| 130 EGLDisplay egl_display, EGLContext egl_context) { | 129 EGLDisplay egl_display, EGLContext egl_context) { |
| 131 DCHECK_EQ(message_loop_, MessageLoop::current()); | 130 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 132 egl_display_ = egl_display; | 131 egl_display_ = egl_display; |
| 133 egl_context_ = egl_context; | 132 egl_context_ = egl_context; |
| 134 } | 133 } |
| 135 | 134 |
| 136 bool OmxVideoDecodeAccelerator::VerifyConfigs( | |
| 137 const std::vector<int32>& configs) { | |
| 138 size_t cur; | |
| 139 for (cur = 0; cur + 1 < configs.size(); cur++) { | |
| 140 uint32 n = configs[cur++]; | |
| 141 uint32 v = configs[cur]; | |
| 142 if ((n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_FOURCC && | |
| 143 v == media::VIDEOCODECFOURCC_H264) || | |
| 144 (n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_BITRATE && | |
| 145 v < 14000000 /* Baseline supports up to 14Mbps. */) || | |
| 146 (n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_WIDTH && | |
| 147 v <= 1920 /* Baseline supports upto 1080p. */) || | |
| 148 (n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_HEIGHT && | |
| 149 v <= 1080 /* Baseline supports up to 1080p. */) || | |
| 150 (n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_LEVEL || | |
| 151 n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_PAYLOADFORMAT || | |
| 152 n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_FEATURE_FMO || | |
| 153 n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_FEATURE_ASO || | |
| 154 n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_FEATURE_INTERLACE || | |
| 155 n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_FEATURE_CABAC || | |
| 156 /* TODO(fischman) Shorten the enum name. */ | |
| 157 n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_FEATURE_WEIGHTEDPRED
ICTION) | |
| 158 || | |
| 159 (n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_PROFILE && | |
| 160 (v == media::H264PROFILE_BASELINE || v == media::H264PROFILE_MAIN || | |
| 161 v == media::H264PROFILE_HIGH)) || | |
| 162 (n == media::VIDEOATTRIBUTEKEY_VIDEOCOLORFORMAT && | |
| 163 v == media::VIDEOCOLORFORMAT_RGBA)) { | |
| 164 if (n == media::VIDEOATTRIBUTEKEY_BITSTREAMFORMAT_H264_PROFILE) { | |
| 165 profile_ = v; | |
| 166 } | |
| 167 continue; | |
| 168 } | |
| 169 return false; | |
| 170 } | |
| 171 return cur == configs.size(); | |
| 172 } | |
| 173 | |
| 174 // This is to initialize the OMX data structures to default values. | 135 // This is to initialize the OMX data structures to default values. |
| 175 template <typename T> | 136 template <typename T> |
| 176 static void InitParam(const OmxVideoDecodeAccelerator& dec, T* param) { | 137 static void InitParam(const OmxVideoDecodeAccelerator& dec, T* param) { |
| 177 memset(param, 0, sizeof(T)); | 138 memset(param, 0, sizeof(T)); |
| 178 param->nVersion.nVersion = 0x00000101; | 139 param->nVersion.nVersion = 0x00000101; |
| 179 param->nSize = sizeof(T); | 140 param->nSize = sizeof(T); |
| 180 } | 141 } |
| 181 | 142 |
| 182 bool OmxVideoDecodeAccelerator::Initialize(const std::vector<int32>& config) { | 143 bool OmxVideoDecodeAccelerator::Initialize(Profile profile) { |
| 183 DCHECK_EQ(message_loop_, MessageLoop::current()); | 144 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 184 RETURN_ON_FAILURE(VerifyConfigs(config), "Invalid config", INVALID_ARGUMENT, | 145 |
| 185 false); | 146 RETURN_ON_FAILURE(profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX, |
| 147 "Only h264 supported", INVALID_ARGUMENT, false); |
| 148 profile_ = MapH264ProfileToOMXAVCProfile(profile); |
| 149 RETURN_ON_FAILURE(profile_ != OMX_VIDEO_AVCProfileMax, |
| 150 "Unexpected profile", INVALID_ARGUMENT, false); |
| 151 |
| 186 if (!CreateComponent()) // Does its own RETURN_ON_FAILURE dances. | 152 if (!CreateComponent()) // Does its own RETURN_ON_FAILURE dances. |
| 187 return false; | 153 return false; |
| 188 | 154 |
| 189 DCHECK_EQ(current_state_change_, NO_TRANSITION); | 155 DCHECK_EQ(current_state_change_, NO_TRANSITION); |
| 190 current_state_change_ = INITIALIZING; | 156 current_state_change_ = INITIALIZING; |
| 191 BeginTransitionToState(OMX_StateIdle); | 157 BeginTransitionToState(OMX_StateIdle); |
| 192 | 158 |
| 193 if (!AllocateInputBuffers()) // Does its own RETURN_ON_FAILURE dances. | 159 if (!AllocateInputBuffers()) // Does its own RETURN_ON_FAILURE dances. |
| 194 return false; | 160 return false; |
| 195 | 161 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 OMX_ERRORTYPE result = OMX_SendCommand( | 474 OMX_ERRORTYPE result = OMX_SendCommand( |
| 509 component_handle_, OMX_CommandStateSet, new_state, 0); | 475 component_handle_, OMX_CommandStateSet, new_state, 0); |
| 510 RETURN_ON_OMX_FAILURE(result, "SendCommand(OMX_CommandStateSet) failed", | 476 RETURN_ON_OMX_FAILURE(result, "SendCommand(OMX_CommandStateSet) failed", |
| 511 PLATFORM_FAILURE,); | 477 PLATFORM_FAILURE,); |
| 512 } | 478 } |
| 513 | 479 |
| 514 void OmxVideoDecodeAccelerator::OnReachedIdleInInitializing() { | 480 void OmxVideoDecodeAccelerator::OnReachedIdleInInitializing() { |
| 515 DCHECK_EQ(client_state_, OMX_StateLoaded); | 481 DCHECK_EQ(client_state_, OMX_StateLoaded); |
| 516 client_state_ = OMX_StateIdle; | 482 client_state_ = OMX_StateIdle; |
| 517 // Query the resources with the component. | 483 // Query the resources with the component. |
| 518 if (component_name_is_nvidia_h264ext_ && | 484 if (component_name_is_nvidia_h264ext_) { |
| 519 (profile_ != OMX_VIDEO_AVCProfileMax)) { | 485 OMX_INDEXTYPE extension_index; |
| 520 OMX_INDEXTYPE extension_index; | |
| 521 OMX_ERRORTYPE result = OMX_GetExtensionIndex( | 486 OMX_ERRORTYPE result = OMX_GetExtensionIndex( |
| 522 component_handle_, | 487 component_handle_, |
| 523 const_cast<char*>("OMX.Nvidia.index.config.checkresources"), | 488 const_cast<char*>("OMX.Nvidia.index.config.checkresources"), |
| 524 &extension_index); | 489 &extension_index); |
| 525 RETURN_ON_OMX_FAILURE(result, | 490 RETURN_ON_OMX_FAILURE(result, |
| 526 "Failed to get the extension", | 491 "Failed to get the extension", |
| 527 PLATFORM_FAILURE,); | 492 PLATFORM_FAILURE,); |
| 528 OMX_VIDEO_PARAM_PROFILELEVELTYPE video_profile_level; | 493 OMX_VIDEO_PARAM_PROFILELEVELTYPE video_profile_level; |
| 529 InitParam(*this, &video_profile_level); | 494 InitParam(*this, &video_profile_level); |
| 530 video_profile_level.eProfile = MapH264ProfileToOMXAVCProfile(profile_); | 495 video_profile_level.eProfile = profile_; |
| 531 RETURN_ON_FAILURE(video_profile_level.eProfile != OMX_VIDEO_AVCProfileMax, | |
| 532 "Unexpected profile", INVALID_ARGUMENT,); | |
| 533 result = OMX_SetConfig(component_handle_, extension_index, | 496 result = OMX_SetConfig(component_handle_, extension_index, |
| 534 &video_profile_level); | 497 &video_profile_level); |
| 535 RETURN_ON_OMX_FAILURE(result, | 498 RETURN_ON_OMX_FAILURE(result, |
| 536 "Resource Allocation failed", | 499 "Resource Allocation failed", |
| 537 PLATFORM_FAILURE,); | 500 PLATFORM_FAILURE,); |
| 538 } | 501 } |
| 539 BeginTransitionToState(OMX_StateExecuting); | 502 BeginTransitionToState(OMX_StateExecuting); |
| 540 } | 503 } |
| 541 | 504 |
| 542 void OmxVideoDecodeAccelerator::OnReachedExecutingInInitializing() { | 505 void OmxVideoDecodeAccelerator::OnReachedExecutingInInitializing() { |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 | 1030 |
| 1068 bool OmxVideoDecodeAccelerator::SendCommandToPort( | 1031 bool OmxVideoDecodeAccelerator::SendCommandToPort( |
| 1069 OMX_COMMANDTYPE cmd, int port_index) { | 1032 OMX_COMMANDTYPE cmd, int port_index) { |
| 1070 DCHECK_EQ(message_loop_, MessageLoop::current()); | 1033 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 1071 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, | 1034 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, |
| 1072 cmd, port_index, 0); | 1035 cmd, port_index, 0); |
| 1073 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, | 1036 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, |
| 1074 PLATFORM_FAILURE, false); | 1037 PLATFORM_FAILURE, false); |
| 1075 return true; | 1038 return true; |
| 1076 } | 1039 } |
| OLD | NEW |