OMXVideoDecoderPAVC.cpp revision b2257cdcf3ffd7a4a7dedbe4842185689bcf7fb7
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 "OMXVideoDecoderPAVC"
20#include <utils/Log.h>
21#include "OMXVideoDecoderPAVC.h"
22
23// Be sure to have an equal string in VideoDecoderHost.cpp (libmix)
24static const char* PAVC_MIME_TYPE = "video/PAVC";
25#define INVALID_PTS (OMX_S64)-1
26
27
28OMXVideoDecoderPAVC::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
38OMXVideoDecoderPAVC::~OMXVideoDecoderPAVC() {
39    LOGV("OMXVideoDecoderPAVC is destructed.");
40}
41
42OMX_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_AVCProfileHigh; //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
64OMX_ERRORTYPE OMXVideoDecoderPAVC::ProcessorInit(void) {
65    return OMXVideoDecoderBase::ProcessorInit();
66}
67
68OMX_ERRORTYPE OMXVideoDecoderPAVC::ProcessorDeinit(void) {
69    return OMXVideoDecoderBase::ProcessorDeinit();
70}
71
72OMX_ERRORTYPE OMXVideoDecoderPAVC::ProcessorFlush(OMX_U32 portIndex) {
73    return OMXVideoDecoderBase::ProcessorFlush(portIndex);
74}
75
76OMX_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
84OMX_ERRORTYPE OMXVideoDecoderPAVC::PrepareConfigBuffer(VideoConfigBuffer *p) {
85    OMX_ERRORTYPE ret;
86    ret = OMXVideoDecoderBase::PrepareConfigBuffer(p);
87    CHECK_RETURN_VALUE("OMXVideoDecoderBase::PrepareConfigBuffer");
88
89    p->flag |= WANT_SURFACE_PROTECTION;
90    return OMX_ErrorNone;
91}
92
93OMX_ERRORTYPE OMXVideoDecoderPAVC::PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p) {
94    OMX_ERRORTYPE ret;
95    ret = OMXVideoDecoderBase::PrepareDecodeBuffer(buffer, retain, p);
96    CHECK_RETURN_VALUE("OMXVideoDecoderBase::PrepareDecodeBuffer");
97
98    // OMX_BUFFERFLAG_CODECCONFIG is an optional flag
99    // if flag is set, buffer will only contain codec data.
100    if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
101        LOGV("Received codec data for Protected AVC.");
102        return ret;
103    }
104
105    if (buffer->nFlags & OMX_BUFFERFLAG_EXTRADATA) {
106        p->flag |= HAS_EXTRADATA;
107    } else {
108        LOGW("No extra data found.");
109    }
110    return ret;
111}
112
113OMX_ERRORTYPE OMXVideoDecoderPAVC::BuildHandlerList(void) {
114    OMXVideoDecoderBase::BuildHandlerList();
115    AddHandler(OMX_IndexParamVideoAvc, GetParamVideoAvc, SetParamVideoAvc);
116    AddHandler(OMX_IndexParamVideoProfileLevelQuerySupported, GetVideoProfileLevelQuerySupported, SetVideoProfileLevelQuerySupported);
117    AddHandler(OMX_IndexParamVideoProfileLevelCurrent, GetVideoProfileLevelCurrent, SetVideoProfileLevelCurrent);
118    AddHandler(static_cast<OMX_INDEXTYPE>(OMX_IndexExtEnableNativeBuffer),GetNativeBufferMode,SetNativeBufferMode);
119
120    return OMX_ErrorNone;
121}
122
123OMX_ERRORTYPE OMXVideoDecoderPAVC::GetParamVideoAvc(OMX_PTR pStructure) {
124    OMX_ERRORTYPE ret;
125    OMX_VIDEO_PARAM_AVCTYPE *p = (OMX_VIDEO_PARAM_AVCTYPE *)pStructure;
126    CHECK_TYPE_HEADER(p);
127    CHECK_PORT_INDEX(p, INPORT_INDEX);
128
129    memcpy(p, &mParamAvc, sizeof(*p));
130    return OMX_ErrorNone;
131}
132
133OMX_ERRORTYPE OMXVideoDecoderPAVC::SetParamVideoAvc(OMX_PTR pStructure) {
134    OMX_ERRORTYPE ret;
135    OMX_VIDEO_PARAM_AVCTYPE *p = (OMX_VIDEO_PARAM_AVCTYPE *)pStructure;
136    CHECK_TYPE_HEADER(p);
137    CHECK_PORT_INDEX(p, INPORT_INDEX);
138    CHECK_SET_PARAM_STATE();
139
140    // TODO: do we need to check if port is enabled?
141    // TODO: see SetPortAvcParam implementation - Can we make simple copy????
142    memcpy(&mParamAvc, p, sizeof(mParamAvc));
143    return OMX_ErrorNone;
144}
145
146OMX_ERRORTYPE OMXVideoDecoderPAVC::GetVideoProfileLevelQuerySupported(OMX_PTR pStructure) {
147    OMX_ERRORTYPE ret;
148    OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure;
149
150    CHECK_TYPE_HEADER(p);
151    CHECK_PORT_INDEX_RANGE(p);
152
153    if (p->nProfileIndex != 0) {
154        LOGE("No more profile index for GetVideoProfileLevelQuerySupported.");
155        return OMX_ErrorNoMore;
156    }
157    p->eProfile = mParamAvc.eProfile;
158    p->eLevel = mParamAvc.eLevel;
159
160    return OMX_ErrorNone;
161}
162
163OMX_ERRORTYPE OMXVideoDecoderPAVC::SetVideoProfileLevelQuerySupported(OMX_PTR pStructure) {
164    LOGE("SetVideoProfileLevelQuerySupported is not supported.");
165    return OMX_ErrorUnsupportedSetting;
166}
167
168OMX_ERRORTYPE OMXVideoDecoderPAVC::GetVideoProfileLevelCurrent(OMX_PTR pStructure) {
169    OMX_ERRORTYPE ret;
170    OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure;
171
172    CHECK_TYPE_HEADER(p);
173    CHECK_PORT_INDEX_RANGE(p);
174
175    if (p->nProfileIndex != 0) {
176        LOGE("No more profile index for GetVideoProfileLevelCurrent.");
177        return OMX_ErrorNoMore;
178    }
179
180    p->eProfile = mCurrentProfile;
181    p->eLevel = mCurrentLevel;
182
183    return OMX_ErrorNone;
184}
185
186OMX_ERRORTYPE OMXVideoDecoderPAVC::SetVideoProfileLevelCurrent(OMX_PTR pStructure) {
187    OMX_ERRORTYPE ret;
188    OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure;
189
190    CHECK_TYPE_HEADER(p);
191    CHECK_PORT_INDEX_RANGE(p);
192
193    if (p->nProfileIndex != 0) {
194        LOGE("Invalid profile index for SetVideoProfileLevelCurrent.");
195        return OMX_ErrorBadParameter;
196    }
197
198    mCurrentProfile = (OMX_VIDEO_AVCPROFILETYPE) p->eProfile;
199    mCurrentLevel = (OMX_VIDEO_AVCLEVELTYPE) p->eLevel;
200
201    return OMX_ErrorNone;
202}
203
204
205OMX_ERRORTYPE OMXVideoDecoderPAVC::GetNativeBufferMode(OMX_PTR pStructure) {
206     OMX_ERRORTYPE ret;
207     return OMX_ErrorNone; //would not be here
208}
209
210#define MAX_OUTPUT_BUFFER_COUNT_FOR_PAVC 10
211OMX_ERRORTYPE OMXVideoDecoderPAVC::SetNativeBufferMode(OMX_PTR pStructure) {
212   // OMX_ERRORTYPE ret;
213    //EnableAndroidNativeBuffersParams *param = (EnableAndroidNativeBuffersParams*)pStructure;
214    //CHECK_TYPE_HEADER(param);
215    CHECK_SET_PARAM_STATE();
216    mNativeBufferMode = true;
217    PortVideo *port = NULL;
218    port = static_cast<PortVideo *>(this->ports[OUTPORT_INDEX]);
219    OMX_PARAM_PORTDEFINITIONTYPE port_def;
220    memcpy(&port_def,port->GetPortDefinition(),sizeof(port_def));
221    port_def.nBufferCountMin = 1;
222    port_def.nBufferCountActual = MAX_OUTPUT_BUFFER_COUNT_FOR_PAVC;
223    port_def.format.video.cMIMEType = (OMX_STRING)"video/raw_ve";
224    port_def.format.video.eColorFormat =static_cast<OMX_COLOR_FORMATTYPE>(0x7FA00EFF) ;//
225    port->SetPortDefinition(&port_def,true);
226    return OMX_ErrorNone;
227}
228
229
230
231DECLARE_OMX_COMPONENT("OMX.Intel.VideoDecoder.PAVC", "video_decoder.pavc", OMXVideoDecoderPAVC);
232
233