| 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 30 matching lines...) Expand all Loading... |
| 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 the media::H264Profile members to the OMX_VIDEO_AVCPROFILETYPE members. |
| 50 static OMX_U32 MapH264ProfileToOMXAVCProfile(uint32 profile) { | 50 static OMX_U32 MapH264ProfileToOMXAVCProfile(uint32 profile) { |
| 51 typedef media::VideoDecodeAccelerator::Config Config; |
| 51 switch (profile) { | 52 switch (profile) { |
| 52 case media::H264PROFILE_NONE: | 53 case Config::H264PROFILE_NONE: |
| 53 return OMX_VIDEO_AVCProfileMax; | 54 return OMX_VIDEO_AVCProfileMax; |
| 54 case media::H264PROFILE_BASELINE: | 55 case Config::H264PROFILE_BASELINE: |
| 55 return OMX_VIDEO_AVCProfileBaseline; | 56 return OMX_VIDEO_AVCProfileBaseline; |
| 56 case media::H264PROFILE_MAIN: | 57 case Config::H264PROFILE_MAIN: |
| 57 return OMX_VIDEO_AVCProfileMain; | 58 return OMX_VIDEO_AVCProfileMain; |
| 58 case media::H264PROFILE_EXTENDED: | 59 case Config::H264PROFILE_EXTENDED: |
| 59 return OMX_VIDEO_AVCProfileExtended; | 60 return OMX_VIDEO_AVCProfileExtended; |
| 60 case media::H264PROFILE_HIGH: | 61 case Config::H264PROFILE_HIGH: |
| 61 return OMX_VIDEO_AVCProfileHigh; | 62 return OMX_VIDEO_AVCProfileHigh; |
| 62 case media::H264PROFILE_HIGH10PROFILE: | 63 case Config::H264PROFILE_HIGH10PROFILE: |
| 63 return OMX_VIDEO_AVCProfileHigh10; | 64 return OMX_VIDEO_AVCProfileHigh10; |
| 64 case media::H264PROFILE_HIGH422PROFILE: | 65 case Config::H264PROFILE_HIGH422PROFILE: |
| 65 return OMX_VIDEO_AVCProfileHigh422; | 66 return OMX_VIDEO_AVCProfileHigh422; |
| 66 case media::H264PROFILE_HIGH444PREDICTIVEPROFILE: | 67 case Config::H264PROFILE_HIGH444PREDICTIVEPROFILE: |
| 67 return OMX_VIDEO_AVCProfileHigh444; | 68 return OMX_VIDEO_AVCProfileHigh444; |
| 68 // Below enums don't have equivalent enum in Openmax. | 69 // Below enums don't have equivalent enum in Openmax. |
| 69 case media::H264PROFILE_SCALABLEBASELINE: | 70 case Config::H264PROFILE_SCALABLEBASELINE: |
| 70 case media::H264PROFILE_SCALABLEHIGH: | 71 case Config::H264PROFILE_SCALABLEHIGH: |
| 71 case media::H264PROFILE_STEREOHIGH: | 72 case Config::H264PROFILE_STEREOHIGH: |
| 72 case media::H264PROFILE_MULTIVIEWHIGH: | 73 case Config::H264PROFILE_MULTIVIEWHIGH: |
| 73 // Nvidia OMX video decoder requires the same resources (as that of the | 74 // Nvidia OMX video decoder requires the same resources (as that of the |
| 74 // High profile) in every profile higher to the Main profile. | 75 // High profile) in every profile higher to the Main profile. |
| 75 return OMX_VIDEO_AVCProfileHigh444; | 76 return OMX_VIDEO_AVCProfileHigh444; |
| 76 } | 77 } |
| 77 NOTREACHED(); | 78 NOTREACHED(); |
| 78 return OMX_VIDEO_AVCProfileMax; | 79 return OMX_VIDEO_AVCProfileMax; |
| 79 } | 80 } |
| 80 | 81 |
| 81 // Helper macros for dealing with failure. If |result| evaluates false, emit | 82 // Helper macros for dealing with failure. If |result| evaluates false, emit |
| 82 // |log| to ERROR, register |error| with the decoder, and return |ret_val| | 83 // |log| to ERROR, register |error| with the decoder, and return |ret_val| |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 DCHECK(pictures_.empty()); | 127 DCHECK(pictures_.empty()); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void OmxVideoDecodeAccelerator::SetEglState( | 130 void OmxVideoDecodeAccelerator::SetEglState( |
| 130 EGLDisplay egl_display, EGLContext egl_context) { | 131 EGLDisplay egl_display, EGLContext egl_context) { |
| 131 DCHECK_EQ(message_loop_, MessageLoop::current()); | 132 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 132 egl_display_ = egl_display; | 133 egl_display_ = egl_display; |
| 133 egl_context_ = egl_context; | 134 egl_context_ = egl_context; |
| 134 } | 135 } |
| 135 | 136 |
| 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. | 137 // This is to initialize the OMX data structures to default values. |
| 175 template <typename T> | 138 template <typename T> |
| 176 static void InitParam(const OmxVideoDecodeAccelerator& dec, T* param) { | 139 static void InitParam(const OmxVideoDecodeAccelerator& dec, T* param) { |
| 177 memset(param, 0, sizeof(T)); | 140 memset(param, 0, sizeof(T)); |
| 178 param->nVersion.nVersion = 0x00000101; | 141 param->nVersion.nVersion = 0x00000101; |
| 179 param->nSize = sizeof(T); | 142 param->nSize = sizeof(T); |
| 180 } | 143 } |
| 181 | 144 |
| 182 bool OmxVideoDecodeAccelerator::Initialize(const std::vector<int32>& config) { | 145 bool OmxVideoDecodeAccelerator::Initialize(const Config& config) { |
| 183 DCHECK_EQ(message_loop_, MessageLoop::current()); | 146 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 184 RETURN_ON_FAILURE(VerifyConfigs(config), "Invalid config", INVALID_ARGUMENT, | 147 |
| 185 false); | 148 if (config.format == Config::H264) |
| 149 profile_ = config.h264_profile; |
| 150 RETURN_ON_FAILURE(config.format == Config::H264, "Only h264 supported", |
| 151 INVALID_ARGUMENT, false); |
| 152 |
| 186 if (!CreateComponent()) // Does its own RETURN_ON_FAILURE dances. | 153 if (!CreateComponent()) // Does its own RETURN_ON_FAILURE dances. |
| 187 return false; | 154 return false; |
| 188 | 155 |
| 189 DCHECK_EQ(current_state_change_, NO_TRANSITION); | 156 DCHECK_EQ(current_state_change_, NO_TRANSITION); |
| 190 current_state_change_ = INITIALIZING; | 157 current_state_change_ = INITIALIZING; |
| 191 BeginTransitionToState(OMX_StateIdle); | 158 BeginTransitionToState(OMX_StateIdle); |
| 192 | 159 |
| 193 if (!AllocateInputBuffers()) // Does its own RETURN_ON_FAILURE dances. | 160 if (!AllocateInputBuffers()) // Does its own RETURN_ON_FAILURE dances. |
| 194 return false; | 161 return false; |
| 195 | 162 |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 | 1034 |
| 1068 bool OmxVideoDecodeAccelerator::SendCommandToPort( | 1035 bool OmxVideoDecodeAccelerator::SendCommandToPort( |
| 1069 OMX_COMMANDTYPE cmd, int port_index) { | 1036 OMX_COMMANDTYPE cmd, int port_index) { |
| 1070 DCHECK_EQ(message_loop_, MessageLoop::current()); | 1037 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 1071 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, | 1038 OMX_ERRORTYPE result = OMX_SendCommand(component_handle_, |
| 1072 cmd, port_index, 0); | 1039 cmd, port_index, 0); |
| 1073 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, | 1040 RETURN_ON_OMX_FAILURE(result, "SendCommand() failed" << cmd, |
| 1074 PLATFORM_FAILURE, false); | 1041 PLATFORM_FAILURE, false); |
| 1075 return true; | 1042 return true; |
| 1076 } | 1043 } |
| OLD | NEW |