1bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber/*
2bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * Copyright (C) 2011 The Android Open Source Project
3bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber *
4bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * you may not use this file except in compliance with the License.
6bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * You may obtain a copy of the License at
7bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber *
8bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber *
10bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * Unless required by applicable law or agreed to in writing, software
11bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * See the License for the specific language governing permissions and
14bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber * limitations under the License.
15bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber */
16bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber
17bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber//#define LOG_NDEBUG 0
18bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber#define LOG_TAG "SoftMPEG4"
19bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber#include <utils/Log.h>
20bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber
21bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber#include "SoftMPEG4.h"
22bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber
23bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber#include <media/stagefright/foundation/ADebug.h>
24bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber#include <media/stagefright/MediaDefs.h>
25bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber#include <media/stagefright/MediaErrors.h>
26457116d3a01618acf9a875020ca5860551ba03a6James Dong#include <media/IOMX.h>
27bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber
28bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber#include "mp4dec_api.h"
29bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber
30bbba88cb1bdc34705d1477208990a06904c022e7Andreas Hubernamespace android {
31bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber
32457116d3a01618acf9a875020ca5860551ba03a6James Dongstatic const CodecProfileLevel kM4VProfileLevels[] = {
33457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0 },
34457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0b },
35457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level1 },
36457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level2 },
37457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level3 },
38457116d3a01618acf9a875020ca5860551ba03a6James Dong};
39457116d3a01618acf9a875020ca5860551ba03a6James Dong
40457116d3a01618acf9a875020ca5860551ba03a6James Dongstatic const CodecProfileLevel kH263ProfileLevels[] = {
41457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10 },
42457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level20 },
43457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level30 },
44457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level45 },
45457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileISWV2,    OMX_VIDEO_H263Level10 },
46457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileISWV2,    OMX_VIDEO_H263Level20 },
47457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileISWV2,    OMX_VIDEO_H263Level30 },
48457116d3a01618acf9a875020ca5860551ba03a6James Dong    { OMX_VIDEO_H263ProfileISWV2,    OMX_VIDEO_H263Level45 },
49457116d3a01618acf9a875020ca5860551ba03a6James Dong};
50457116d3a01618acf9a875020ca5860551ba03a6James Dong
51bbba88cb1bdc34705d1477208990a06904c022e7Andreas Hubertemplate<class T>
52bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huberstatic void InitOMXParams(T *params) {
53bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber    params->nSize = sizeof(T);
54bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber    params->nVersion.s.nVersionMajor = 1;
55bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber    params->nVersion.s.nVersionMinor = 0;
56bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber    params->nVersion.s.nRevision = 0;
57bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber    params->nVersion.s.nStep = 0;
58bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber}
59bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber
60bbba88cb1bdc34705d1477208990a06904c022e7Andreas HuberSoftMPEG4::SoftMPEG4(
61bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber        const char *name,
62bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber        const OMX_CALLBACKTYPE *callbacks,
63bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber        OMX_PTR appData,
64bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber        OMX_COMPONENTTYPE **component)
65bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber    : SimpleSoftOMXComponent(name, callbacks, appData, component),
66bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mMode(MODE_MPEG4),
67bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mHandle(new tagvideoDecControls),
68bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mInputBufferCount(0),
69bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mWidth(352),
70bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mHeight(288),
71bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mCropLeft(0),
72bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mCropTop(0),
73bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mCropRight(mWidth - 1),
74bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mCropBottom(mHeight - 1),
75bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mSignalledError(false),
76bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mInitialized(false),
77bbba88cb1bdc34705d1477208990a06904c022e7Andreas Huber      mFramesConfigured(false),
78