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 "OMXVideoDecoderMPEG4.h" 22 23// Be sure to have an equal string in VideoDecoderHost.cpp (libmix) 24static const char* MPEG4_MIME_TYPE = "video/mpeg4"; 25 26OMXVideoDecoderMPEG4::OMXVideoDecoderMPEG4() { 27 LOGV("OMXVideoDecoderMPEG4 is constructed."); 28 mVideoDecoder = createVideoDecoder(MPEG4_MIME_TYPE); 29 if (!mVideoDecoder) { 30 LOGE("createVideoDecoder failed for \"%s\"", MPEG4_MIME_TYPE); 31 } 32 mNativeBufferCount = OUTPORT_NATIVE_BUFFER_COUNT; 33 BuildHandlerList(); 34} 35 36OMXVideoDecoderMPEG4::~OMXVideoDecoderMPEG4() { 37 LOGV("OMXVideoDecoderMPEG4 is destructed."); 38} 39 40OMX_ERRORTYPE OMXVideoDecoderMPEG4::InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput) { 41 // OMX_PARAM_PORTDEFINITIONTYPE 42 paramPortDefinitionInput->nBufferCountActual = INPORT_ACTUAL_BUFFER_COUNT; 43 paramPortDefinitionInput->nBufferCountMin = INPORT_MIN_BUFFER_COUNT; 44 paramPortDefinitionInput->nBufferSize = INPORT_BUFFER_SIZE; 45 paramPortDefinitionInput->format.video.cMIMEType = (OMX_STRING)MPEG4_MIME_TYPE; 46 paramPortDefinitionInput->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 47 48 // OMX_VIDEO_PARAM_MPEG4TYPE 49 memset(&mParamMpeg4, 0, sizeof(mParamMpeg4)); 50 SetTypeHeader(&mParamMpeg4, sizeof(mParamMpeg4)); 51 mParamMpeg4.nPortIndex = INPORT_INDEX; 52 // TODO: check eProfile/eLevel 53 mParamMpeg4.eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple; //OMX_VIDEO_MPEG4ProfileSimple; 54 mParamMpeg4.eLevel = OMX_VIDEO_MPEG4Level3; 55 56 return OMX_ErrorNone; 57} 58 59OMX_ERRORTYPE OMXVideoDecoderMPEG4::ProcessorInit(void) { 60 return OMXVideoDecoderBase::ProcessorInit(); 61} 62 63OMX_ERRORTYPE OMXVideoDecoderMPEG4::ProcessorDeinit(void) { 64 return OMXVideoDecoderBase::ProcessorDeinit(); 65} 66 67OMX_ERRORTYPE OMXVideoDecoderMPEG4::ProcessorProcess( 68 OMX_BUFFERHEADERTYPE ***pBuffers, 69 buffer_retain_t *retains, 70 OMX_U32 numberBuffers) { 71 72 return OMXVideoDecoderBase::ProcessorProcess(pBuffers, retains, numberBuffers); 73} 74 75OMX_ERRORTYPE OMXVideoDecoderMPEG4::PrepareConfigBuffer(VideoConfigBuffer *p) { 76 return OMXVideoDecoderBase::PrepareConfigBuffer(p); 77} 78 79OMX_ERRORTYPE OMXVideoDecoderMPEG4::PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p) { 80 return OMXVideoDecoderBase::PrepareDecodeBuffer(buffer, retain, p); 81} 82 83OMX_ERRORTYPE OMXVideoDecoderMPEG4::BuildHandlerList(void) { 84 OMXVideoDecoderBase::BuildHandlerList(); 85 AddHandler(OMX_IndexParamVideoMpeg4, GetParamVideoMpeg4, SetParamVideoMpeg4); 86 AddHandler(OMX_IndexParamVideoProfileLevelQuerySupported, GetParamVideoMpeg4ProfileLevel, SetParamVideoMpeg4ProfileLevel); 87 return OMX_ErrorNone; 88} 89 90OMX_ERRORTYPE OMXVideoDecoderMPEG4::GetParamVideoMpeg4(OMX_PTR pStructure) { 91 OMX_ERRORTYPE ret; 92 OMX_VIDEO_PARAM_MPEG4TYPE *p = (OMX_VIDEO_PARAM_MPEG4TYPE *)pStructure; 93 CHECK_TYPE_HEADER(p); 94 CHECK_PORT_INDEX(p, INPORT_INDEX); 95 96 memcpy(p, &mParamMpeg4, sizeof(*p)); 97 return OMX_ErrorNone; 98} 99 100OMX_ERRORTYPE OMXVideoDecoderMPEG4::SetParamVideoMpeg4(OMX_PTR pStructure) { 101 OMX_ERRORTYPE ret; 102 OMX_VIDEO_PARAM_MPEG4TYPE *p = (OMX_VIDEO_PARAM_MPEG4TYPE *)pStructure; 103 CHECK_TYPE_HEADER(p); 104 CHECK_PORT_INDEX(p, INPORT_INDEX); 105 CHECK_SET_PARAM_STATE(); 106 107 // TODO: do we need to check if port is enabled? 108 // TODO: see SetPortMpeg4Param implementation - Can we make simple copy???? 109 memcpy(&mParamMpeg4, p, sizeof(mParamMpeg4)); 110 return OMX_ErrorNone; 111} 112 113OMX_ERRORTYPE OMXVideoDecoderMPEG4::GetParamVideoMpeg4ProfileLevel(OMX_PTR pStructure) { 114 OMX_ERRORTYPE ret; 115 OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure; 116 CHECK_TYPE_HEADER(p); 117 118 struct ProfileLevelTable { 119 OMX_U32 profile; 120 OMX_U32 level; 121 } plTable[] = { 122 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level3}, 123 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level5} 124 }; 125 126 OMX_U32 count = sizeof(plTable)/sizeof(ProfileLevelTable); 127 CHECK_ENUMERATION_RANGE(p->nProfileIndex,count); 128 129 p->eProfile = plTable[p->nProfileIndex].profile; 130 p->eLevel = plTable[p->nProfileIndex].level; 131 132 return OMX_ErrorNone; 133} 134 135OMX_ERRORTYPE OMXVideoDecoderMPEG4::SetParamVideoMpeg4ProfileLevel(OMX_PTR) { 136 LOGW("SetParamVideoMpeg4ProfileLevel is not supported."); 137 return OMX_ErrorUnsupportedSetting; 138} 139 140OMX_COLOR_FORMATTYPE OMXVideoDecoderMPEG4::GetOutputColorFormat(int width) 141{ 142#ifdef USE_GEN_HW 143 return (OMX_COLOR_FORMATTYPE)HAL_PIXEL_FORMAT_NV12_X_TILED_INTEL; 144#else 145 return OMXVideoDecoderBase::GetOutputColorFormat(width); 146#endif 147} 148 149OMX_ERRORTYPE OMXVideoDecoderMPEG4::SetMaxOutputBufferCount(OMX_PARAM_PORTDEFINITIONTYPE *p) { 150 OMX_ERRORTYPE ret; 151 CHECK_TYPE_HEADER(p); 152 CHECK_PORT_INDEX(p, OUTPORT_INDEX); 153 154 p->nBufferCountActual = OUTPORT_NATIVE_BUFFER_COUNT; 155 return OMXVideoDecoderBase::SetMaxOutputBufferCount(p); 156} 157 158DECLARE_OMX_COMPONENT("OMX.Intel.VideoDecoder.MPEG4", "video_decoder.mpeg4", OMXVideoDecoderMPEG4); 159 160 161