SoftAVC.h revision 0c1bc742181ded4930842b46e9507372f0b1b963
1/*
2 * Copyright (C) 2011 The Android Open Source Project
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#ifndef SOFT_AVC_H_
18
19#define SOFT_AVC_H_
20
21#include "SimpleSoftOMXComponent.h"
22#include <utils/KeyedVector.h>
23
24#include "H264SwDecApi.h"
25#include "basetype.h"
26
27namespace android {
28
29struct SoftAVC : public SimpleSoftOMXComponent {
30    SoftAVC(const char *name,
31            const OMX_CALLBACKTYPE *callbacks,
32            OMX_PTR appData,
33            OMX_COMPONENTTYPE **component);
34
35protected:
36    virtual ~SoftAVC();
37
38    virtual OMX_ERRORTYPE internalGetParameter(
39            OMX_INDEXTYPE index, OMX_PTR params);
40
41    virtual OMX_ERRORTYPE internalSetParameter(
42            OMX_INDEXTYPE index, const OMX_PTR params);
43
44    virtual OMX_ERRORTYPE getConfig(OMX_INDEXTYPE index, OMX_PTR params);
45
46    virtual void onQueueFilled(OMX_U32 portIndex);
47    virtual void onPortFlushCompleted(OMX_U32 portIndex);
48    virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
49
50private:
51    enum {
52        kInputPortIndex   = 0,
53        kOutputPortIndex  = 1,
54        kNumInputBuffers  = 8,
55        kNumOutputBuffers = 16,
56    };
57
58    enum EOSStatus {
59        INPUT_DATA_AVAILABLE,
60        INPUT_EOS_SEEN,
61        OUTPUT_FRAMES_FLUSHED,
62    };
63
64    void *mHandle;
65
66    size_t mInputBufferCount;
67
68    uint32_t mWidth, mHeight, mPictureSize;
69    uint32_t mCropLeft, mCropTop;
70
71    uint8_t *mFirstPicture;
72    int32_t mFirstPictureId;
73
74    int32_t mPicId;  // Which output picture is for which input buffer?
75
76    // OMX_BUFFERHEADERTYPE may be overkill, but it is convenient
77    // for tracking the following fields: nFlags, nTimeStamp, etc.
78    KeyedVector<int32_t, OMX_BUFFERHEADERTYPE *> mPicToHeaderMap;
79    bool mHeadersDecoded;
80
81    EOSStatus mEOSStatus;
82
83    enum OutputPortSettingChange {
84        NONE,
85        AWAITING_DISABLED,
86        AWAITING_ENABLED
87    };
88    OutputPortSettingChange mOutputPortSettingsChange;
89
90    void initPorts();
91    status_t initDecoder();
92    void updatePortDefinitions();
93    bool drainAllOutputBuffers();
94    void drainOneOutputBuffer(int32_t picId, uint8_t *data);
95    void saveFirstOutputBuffer(int32_t pidId, uint8_t *data);
96    bool handleCropRectEvent(const CropParams* crop);
97    bool handlePortSettingChangeEvent(const H264SwDecInfo *info);
98
99    DISALLOW_EVIL_CONSTRUCTORS(SoftAVC);
100};
101
102}  // namespace android
103
104#endif  // SOFT_AVC_H_
105
106