1 /* 2 * Copyright (c) 2009-2011 Intel Corporation. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18 //#define LOG_NDEBUG 0 19 #define LOG_TAG "OMXVideoDecoder" 20 #include <wrs_omxil_core/log.h> 21 #include "OMXVideoDecoderPAVC.h" 22 23 // Be sure to have an equal string in VideoDecoderHost.cpp (libmix) 24 static const char* PAVC_MIME_TYPE = "video/PAVC"; 25 #define INVALID_PTS (OMX_S64)-1 26 27 OMXVideoDecoderPAVC()28 OMXVideoDecoderPAVC::OMXVideoDecoderPAVC() { 29 LOGV("OMXVideoDecoderPAVC is constructed."); 30 mVideoDecoder = createVideoDecoder(PAVC_MIME_TYPE); 31 if (!mVideoDecoder) { 32 LOGE("createVideoDecoder failed for \"%s\"", PAVC_MIME_TYPE); 33 } 34 35 BuildHandlerList(); 36 } 37 ~OMXVideoDecoderPAVC()38 OMXVideoDecoderPAVC::~OMXVideoDecoderPAVC() { 39 LOGV("OMXVideoDecoderPAVC is destructed."); 40 } 41 InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE * paramPortDefinitionInput)42 OMX_ERRORTYPE OMXVideoDecoderPAVC::InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput) { 43 // OMX_PARAM_PORTDEFINITIONTYPE 44 paramPortDefinitionInput->nBufferCountActual = INPORT_ACTUAL_BUFFER_COUNT; 45 paramPortDefinitionInput->nBufferCountMin = INPORT_MIN_BUFFER_COUNT; 46 paramPortDefinitionInput->nBufferSize = INPORT_BUFFER_SIZE; 47 paramPortDefinitionInput->format.video.cMIMEType = (OMX_STRING)PAVC_MIME_TYPE; 48 paramPortDefinitionInput->format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; 49 50 // OMX_VIDEO_PARAM_AVCTYPE 51 memset(&mParamAvc, 0, sizeof(mParamAvc)); 52 SetTypeHeader(&mParamAvc, sizeof(mParamAvc)); 53 mParamAvc.nPortIndex = INPORT_INDEX; 54 // TODO: check eProfile/eLevel 55 mParamAvc.eProfile = OMX_VIDEO_AVCProfileMain; //OMX_VIDEO_AVCProfileBaseline; 56 mParamAvc.eLevel = OMX_VIDEO_AVCLevel41; //OMX_VIDEO_AVCLevel1; 57 58 mCurrentProfile = mParamAvc.eProfile; 59 mCurrentLevel = mParamAvc.eLevel; 60 61 return OMX_ErrorNone; 62 } 63 ProcessorInit(void)64 OMX_ERRORTYPE OMXVideoDecoderPAVC::ProcessorInit(void) { 65 return OMXVideoDecoderBase::ProcessorInit(); 66 } 67 ProcessorDeinit(void)68 OMX_ERRORTYPE OMXVideoDecoderPAVC::ProcessorDeinit(void) { 69 return OMXVideoDecoderBase::ProcessorDeinit(); 70 } 71 ProcessorFlush(OMX_U32 portIndex)72 OMX_ERRORTYPE OMXVideoDecoderPAVC::ProcessorFlush(OMX_U32 portIndex) { 73 return OMXVideoDecoderBase::ProcessorFlush(portIndex); 74 } 75 ProcessorProcess(OMX_BUFFERHEADERTYPE *** pBuffers,buffer_retain_t * retains,OMX_U32 numberBuffers)76 OMX_ERRORTYPE OMXVideoDecoderPAVC::ProcessorProcess( 77 OMX_BUFFERHEADERTYPE ***pBuffers, 78 buffer_retain_t *retains, 79 OMX_U32 numberBuffers) { 80 81 return OMXVideoDecoderBase::ProcessorProcess(pBuffers, retains, numberBuffers); 82 } 83 PrepareConfigBuffer(VideoConfigBuffer * p)84 OMX_ERRORTYPE OMXVideoDecoderPAVC::PrepareConfigBuffer(VideoConfigBuffer *p) { 85 OMX_ERRORTYPE ret; 86 ret = OMXVideoDecoderBase::PrepareConfigBuffer(p); 87 CHECK_RETURN_VALUE("OMXVideoDecoderBase::PrepareConfigBuffer"); 88 p->width = 1920; 89 p->height = 1088; 90 p->surfaceNumber = 16; 91 p->profile = VAProfileH264High; 92 p->flag = WANT_SURFACE_PROTECTION | HAS_VA_PROFILE | HAS_SURFACE_NUMBER; 93 return OMX_ErrorNone; 94 } 95 PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE * buffer,buffer_retain_t * retain,VideoDecodeBuffer * p)96 OMX_ERRORTYPE OMXVideoDecoderPAVC::PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p) { 97 OMX_ERRORTYPE ret; 98 ret = OMXVideoDecoderBase::PrepareDecodeBuffer(buffer, retain, p); 99 CHECK_RETURN_VALUE("OMXVideoDecoderBase::PrepareDecodeBuffer"); 100 101 // OMX_BUFFERFLAG_CODECCONFIG is an optional flag 102 // if flag is set, buffer will only contain codec data. 103 if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { 104 LOGV("Received codec data for Protected AVC."); 105 return ret; 106 } 107 108 if (buffer->nFlags & OMX_BUFFERFLAG_EXTRADATA) { 109 p->flag |= HAS_EXTRADATA; 110 } else { 111 LOGW("No extra data found."); 112 } 113 return ret; 114 } 115 BuildHandlerList(void)116 OMX_ERRORTYPE OMXVideoDecoderPAVC::BuildHandlerList(void) { 117 OMXVideoDecoderBase::BuildHandlerList(); 118 AddHandler(OMX_IndexParamVideoAvc, GetParamVideoAvc, SetParamVideoAvc); 119 AddHandler(OMX_IndexParamVideoProfileLevelQuerySupported, GetVideoProfileLevelQuerySupported, SetVideoProfileLevelQuerySupported); 120 AddHandler(OMX_IndexParamVideoProfileLevelCurrent, GetVideoProfileLevelCurrent, SetVideoProfileLevelCurrent); 121 return OMX_ErrorNone; 122 } 123 GetParamVideoAvc(OMX_PTR pStructure)124 OMX_ERRORTYPE OMXVideoDecoderPAVC::GetParamVideoAvc(OMX_PTR pStructure) { 125 OMX_ERRORTYPE ret; 126 OMX_VIDEO_PARAM_AVCTYPE *p = (OMX_VIDEO_PARAM_AVCTYPE *)pStructure; 127 CHECK_TYPE_HEADER(p); 128 CHECK_PORT_INDEX(p, INPORT_INDEX); 129 130 memcpy(p, &mParamAvc, sizeof(*p)); 131 return OMX_ErrorNone; 132 } 133 SetParamVideoAvc(OMX_PTR pStructure)134 OMX_ERRORTYPE OMXVideoDecoderPAVC::SetParamVideoAvc(OMX_PTR pStructure) { 135 OMX_ERRORTYPE ret; 136 OMX_VIDEO_PARAM_AVCTYPE *p = (OMX_VIDEO_PARAM_AVCTYPE *)pStructure; 137 CHECK_TYPE_HEADER(p); 138 CHECK_PORT_INDEX(p, INPORT_INDEX); 139 CHECK_SET_PARAM_STATE(); 140 141 // TODO: do we need to check if port is enabled? 142 // TODO: see SetPortAvcParam implementation - Can we make simple copy???? 143 memcpy(&mParamAvc, p, sizeof(mParamAvc)); 144 return OMX_ErrorNone; 145 } 146 GetVideoProfileLevelQuerySupported(OMX_PTR pStructure)147 OMX_ERRORTYPE OMXVideoDecoderPAVC::GetVideoProfileLevelQuerySupported(OMX_PTR pStructure) { 148 OMX_ERRORTYPE ret; 149 OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure; 150 151 CHECK_TYPE_HEADER(p); 152 CHECK_PORT_INDEX_RANGE(p); 153 154 if (p->nProfileIndex != 0) { 155 LOGE("No more profile index for GetVideoProfileLevelQuerySupported."); 156 return OMX_ErrorNoMore; 157 } 158 p->eProfile = mParamAvc.eProfile; 159 p->eLevel = mParamAvc.eLevel; 160 161 return OMX_ErrorNone; 162 } 163 SetVideoProfileLevelQuerySupported(OMX_PTR)164 OMX_ERRORTYPE OMXVideoDecoderPAVC::SetVideoProfileLevelQuerySupported(OMX_PTR) { 165 LOGE("SetVideoProfileLevelQuerySupported is not supported."); 166 return OMX_ErrorUnsupportedSetting; 167 } 168 GetVideoProfileLevelCurrent(OMX_PTR pStructure)169 OMX_ERRORTYPE OMXVideoDecoderPAVC::GetVideoProfileLevelCurrent(OMX_PTR pStructure) { 170 OMX_ERRORTYPE ret; 171 OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure; 172 173 CHECK_TYPE_HEADER(p); 174 CHECK_PORT_INDEX_RANGE(p); 175 176 if (p->nProfileIndex != 0) { 177 LOGE("No more profile index for GetVideoProfileLevelCurrent."); 178 return OMX_ErrorNoMore; 179 } 180 181 p->eProfile = mCurrentProfile; 182 p->eLevel = mCurrentLevel; 183 184 return OMX_ErrorNone; 185 } 186 SetVideoProfileLevelCurrent(OMX_PTR pStructure)187 OMX_ERRORTYPE OMXVideoDecoderPAVC::SetVideoProfileLevelCurrent(OMX_PTR pStructure) { 188 OMX_ERRORTYPE ret; 189 OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure; 190 191 CHECK_TYPE_HEADER(p); 192 CHECK_PORT_INDEX_RANGE(p); 193 194 if (p->nProfileIndex != 0) { 195 LOGE("Invalid profile index for SetVideoProfileLevelCurrent."); 196 return OMX_ErrorBadParameter; 197 } 198 199 mCurrentProfile = (OMX_VIDEO_AVCPROFILETYPE) p->eProfile; 200 mCurrentLevel = (OMX_VIDEO_AVCLEVELTYPE) p->eLevel; 201 202 return OMX_ErrorNone; 203 } 204 205 DECLARE_OMX_COMPONENT("OMX.Intel.VideoDecoder.PAVC", "video_decoder.pavc", OMXVideoDecoderPAVC); 206 207