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 "OMXVideoDecoderMPEG2.h"
22 
23 // Be sure to have an equal string in VideoDecoderHost.cpp (libmix)
24 static const char* MPEG2_MIME_TYPE = "video/mpeg2";
25 
OMXVideoDecoderMPEG2()26 OMXVideoDecoderMPEG2::OMXVideoDecoderMPEG2() {
27     LOGV("OMXVideoDecoderMPEG2 is constructed.");
28     mVideoDecoder = createVideoDecoder(MPEG2_MIME_TYPE);
29     if (!mVideoDecoder) {
30         LOGE("createVideoDecoder failed for \"%s\"", MPEG2_MIME_TYPE);
31     }
32     mNativeBufferCount = OUTPORT_NATIVE_BUFFER_COUNT;
33     BuildHandlerList();
34 }
35 
~OMXVideoDecoderMPEG2()36 OMXVideoDecoderMPEG2::~OMXVideoDecoderMPEG2() {
37     LOGV("OMXVideoDecoderMPEG2 is destructed.");
38 }
39 
InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE * paramPortDefinitionInput)40 OMX_ERRORTYPE OMXVideoDecoderMPEG2::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)MPEG2_MIME_TYPE;
46     paramPortDefinitionInput->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
47 
48     // OMX_VIDEO_PARAM_MPEG2TYPE
49     memset(&mParamMpeg2, 0, sizeof(mParamMpeg2));
50     SetTypeHeader(&mParamMpeg2, sizeof(mParamMpeg2));
51     mParamMpeg2.nPortIndex = INPORT_INDEX;
52     // TODO: check eProfile/eLevel
53     mParamMpeg2.eProfile = OMX_VIDEO_MPEG2ProfileSimple; //OMX_VIDEO_MPEG2ProfileSimple;
54     mParamMpeg2.eLevel = OMX_VIDEO_MPEG2LevelLL;
55 
56     return OMX_ErrorNone;
57 }
58 
ProcessorInit(void)59 OMX_ERRORTYPE OMXVideoDecoderMPEG2::ProcessorInit(void) {
60     return OMXVideoDecoderBase::ProcessorInit();
61 }
62 
ProcessorDeinit(void)63 OMX_ERRORTYPE OMXVideoDecoderMPEG2::ProcessorDeinit(void) {
64     return OMXVideoDecoderBase::ProcessorDeinit();
65 }
66 
ProcessorProcess(OMX_BUFFERHEADERTYPE *** pBuffers,buffer_retain_t * retains,OMX_U32 numberBuffers)67 OMX_ERRORTYPE OMXVideoDecoderMPEG2::ProcessorProcess(
68         OMX_BUFFERHEADERTYPE ***pBuffers,
69         buffer_retain_t *retains,
70         OMX_U32 numberBuffers) {
71 
72     return OMXVideoDecoderBase::ProcessorProcess(pBuffers, retains, numberBuffers);
73 }
74 
PrepareConfigBuffer(VideoConfigBuffer * p)75 OMX_ERRORTYPE OMXVideoDecoderMPEG2::PrepareConfigBuffer(VideoConfigBuffer *p) {
76     return OMXVideoDecoderBase::PrepareConfigBuffer(p);
77 }
78 
PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE * buffer,buffer_retain_t * retain,VideoDecodeBuffer * p)79 OMX_ERRORTYPE OMXVideoDecoderMPEG2::PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p) {
80     return OMXVideoDecoderBase::PrepareDecodeBuffer(buffer, retain, p);
81 }
82 
BuildHandlerList(void)83 OMX_ERRORTYPE OMXVideoDecoderMPEG2::BuildHandlerList(void) {
84     OMXVideoDecoderBase::BuildHandlerList();
85     AddHandler(OMX_IndexParamVideoMpeg2, GetParamVideoMpeg2, SetParamVideoMpeg2);
86     AddHandler(OMX_IndexParamVideoProfileLevelQuerySupported, GetParamVideoMpeg2ProfileLevel, SetParamVideoMpeg2ProfileLevel);
87     return OMX_ErrorNone;
88 }
89 
GetParamVideoMpeg2(OMX_PTR pStructure)90 OMX_ERRORTYPE OMXVideoDecoderMPEG2::GetParamVideoMpeg2(OMX_PTR pStructure) {
91     OMX_ERRORTYPE ret;
92     OMX_VIDEO_PARAM_MPEG2TYPE *p = (OMX_VIDEO_PARAM_MPEG2TYPE *)pStructure;
93     CHECK_TYPE_HEADER(p);
94     CHECK_PORT_INDEX(p, INPORT_INDEX);
95 
96     memcpy(p, &mParamMpeg2, sizeof(*p));
97     return OMX_ErrorNone;
98 }
99 
SetParamVideoMpeg2(OMX_PTR pStructure)100 OMX_ERRORTYPE OMXVideoDecoderMPEG2::SetParamVideoMpeg2(OMX_PTR pStructure) {
101     OMX_ERRORTYPE ret;
102     OMX_VIDEO_PARAM_MPEG2TYPE *p = (OMX_VIDEO_PARAM_MPEG2TYPE *)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 SetPortMpeg2Param implementation - Can we make simple copy????
109     memcpy(&mParamMpeg2, p, sizeof(mParamMpeg2));
110     return OMX_ErrorNone;
111 }
112 
GetParamVideoMpeg2ProfileLevel(OMX_PTR pStructure)113 OMX_ERRORTYPE OMXVideoDecoderMPEG2::GetParamVideoMpeg2ProfileLevel(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_MPEG2ProfileSimple, OMX_VIDEO_MPEG2LevelML},
123         {OMX_VIDEO_MPEG2ProfileMain, OMX_VIDEO_MPEG2LevelHL}
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 
SetParamVideoMpeg2ProfileLevel(OMX_PTR)135 OMX_ERRORTYPE OMXVideoDecoderMPEG2::SetParamVideoMpeg2ProfileLevel(OMX_PTR) {
136     LOGW("SetParamVideoMpeg2ProfileLevel is not supported.");
137     return OMX_ErrorUnsupportedSetting;
138 }
139 
GetOutputColorFormat(int width)140 OMX_COLOR_FORMATTYPE OMXVideoDecoderMPEG2::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 
SetMaxOutputBufferCount(OMX_PARAM_PORTDEFINITIONTYPE * p)149 OMX_ERRORTYPE OMXVideoDecoderMPEG2::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 
158 DECLARE_OMX_COMPONENT("OMX.Intel.VideoDecoder.MPEG2", "video_decoder.mpeg2", OMXVideoDecoderMPEG2);
159 
160 
161