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 "OMXVideoDecoderWMV.h"
22
23// Be sure to have an equal string in VideoDecoderHost.cpp (libmix)
24static const char* WMV_MIME_TYPE = "video/wmv";
25
26OMXVideoDecoderWMV::OMXVideoDecoderWMV() {
27    LOGV("OMXVideoDecoderWMV is constructed.");
28    mVideoDecoder = createVideoDecoder(WMV_MIME_TYPE);
29    if (!mVideoDecoder) {
30        LOGE("createVideoDecoder failed for \"%s\"", WMV_MIME_TYPE);
31    }
32    mNativeBufferCount = OUTPORT_NATIVE_BUFFER_COUNT;
33    BuildHandlerList();
34}
35
36OMXVideoDecoderWMV::~OMXVideoDecoderWMV() {
37    LOGV("OMXVideoDecoderWMV is destructed.");
38}
39
40OMX_ERRORTYPE OMXVideoDecoderWMV::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)WMV_MIME_TYPE;
46    paramPortDefinitionInput->format.video.eCompressionFormat = OMX_VIDEO_CodingWMV;
47
48    // OMX_VIDEO_PARAM_WMVTYPE
49    memset(&mParamWmv, 0, sizeof(mParamWmv));
50    SetTypeHeader(&mParamWmv, sizeof(mParamWmv));
51    mParamWmv.nPortIndex = INPORT_INDEX;
52    mParamWmv.eFormat = OMX_VIDEO_WMVFormat9;
53
54    return OMX_ErrorNone;
55}
56
57OMX_ERRORTYPE OMXVideoDecoderWMV::ProcessorInit(void) {
58    return OMXVideoDecoderBase::ProcessorInit();
59}
60
61OMX_ERRORTYPE OMXVideoDecoderWMV::ProcessorDeinit(void) {
62    return OMXVideoDecoderBase::ProcessorDeinit();
63}
64
65OMX_ERRORTYPE OMXVideoDecoderWMV::ProcessorProcess(
66        OMX_BUFFERHEADERTYPE ***pBuffers,
67        buffer_retain_t *retains,
68        OMX_U32 numberBuffers) {
69
70    return OMXVideoDecoderBase::ProcessorProcess(pBuffers, retains, numberBuffers);
71}
72
73OMX_ERRORTYPE OMXVideoDecoderWMV::PrepareConfigBuffer(VideoConfigBuffer *p) {
74    return OMXVideoDecoderBase::PrepareConfigBuffer(p);
75}
76
77OMX_ERRORTYPE OMXVideoDecoderWMV::PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p) {
78    return OMXVideoDecoderBase::PrepareDecodeBuffer(buffer, retain, p);
79}
80
81OMX_ERRORTYPE OMXVideoDecoderWMV::BuildHandlerList(void) {
82    OMXVideoDecoderBase::BuildHandlerList();
83    AddHandler(OMX_IndexParamVideoWmv, GetParamVideoWmv, SetParamVideoWmv);
84    return OMX_ErrorNone;
85}
86
87OMX_ERRORTYPE OMXVideoDecoderWMV::GetParamVideoWmv(OMX_PTR pStructure) {
88    OMX_ERRORTYPE ret;
89    OMX_VIDEO_PARAM_WMVTYPE *p = (OMX_VIDEO_PARAM_WMVTYPE *)pStructure;
90    CHECK_TYPE_HEADER(p);
91    CHECK_PORT_INDEX(p, INPORT_INDEX);
92
93    memcpy(p, &mParamWmv, sizeof(*p));
94    return OMX_ErrorNone;
95}
96
97OMX_ERRORTYPE OMXVideoDecoderWMV::SetParamVideoWmv(OMX_PTR pStructure) {
98    OMX_ERRORTYPE ret;
99    OMX_VIDEO_PARAM_WMVTYPE *p = (OMX_VIDEO_PARAM_WMVTYPE *)pStructure;
100    CHECK_TYPE_HEADER(p);
101    CHECK_PORT_INDEX(p, INPORT_INDEX);
102    CHECK_SET_PARAM_STATE();
103
104    // TODO: do we need to check if port is enabled?
105    memcpy(&mParamWmv, p, sizeof(mParamWmv));
106    return OMX_ErrorNone;
107}
108
109OMX_COLOR_FORMATTYPE OMXVideoDecoderWMV::GetOutputColorFormat(int width)
110{
111#ifdef USE_GEN_HW
112    return OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled;
113#else
114    return OMXVideoDecoderBase::GetOutputColorFormat(width);
115#endif
116}
117
118OMX_ERRORTYPE OMXVideoDecoderWMV::SetMaxOutputBufferCount(OMX_PARAM_PORTDEFINITIONTYPE *p) {
119    OMX_ERRORTYPE ret;
120    CHECK_TYPE_HEADER(p);
121    CHECK_PORT_INDEX(p, OUTPORT_INDEX);
122
123    p->nBufferCountActual = OUTPORT_NATIVE_BUFFER_COUNT;
124    return OMXVideoDecoderBase::SetMaxOutputBufferCount(p);
125}
126DECLARE_OMX_COMPONENT("OMX.Intel.VideoDecoder.WMV", "video_decoder.wmv", OMXVideoDecoderWMV);
127