SoftAVC.h revision 639ffaca514deb9de538bc2dc6e712380db68fd3
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    uint32_t mCropWidth, mCropHeight;
71
72    uint8_t *mFirstPicture;
73    int32_t mFirstPictureId;
74
75    int32_t mPicId;  // Which output picture is for which input buffer?
76
77    // OMX_BUFFERHEADERTYPE may be overkill, but it is convenient
78    // for tracking the following fields: nFlags, nTimeStamp, etc.
79    KeyedVector<int32_t, OMX_BUFFERHEADERTYPE *> mPicToHeaderMap;
80    bool mHeadersDecoded;
81
82    EOSStatus mEOSStatus;
83
84    enum OutputPortSettingChange {
85        NONE,
86        AWAITING_DISABLED,
87        AWAITING_ENABLED
88    };
89    OutputPortSettingChange mOutputPortSettingsChange;
90
91    void initPorts();
92    status_t initDecoder();
93    void updatePortDefinitions();
94    bool drainAllOutputBuffers();
95    void drainOneOutputBuffer(int32_t picId, uint8_t *data);
96    void saveFirstOutputBuffer(int32_t pidId, uint8_t *data);
97    bool handleCropRectEvent(const CropParams* crop);
98    bool handlePortSettingChangeEvent(const H264SwDecInfo *info);
99
100    DISALLOW_EVIL_CONSTRUCTORS(SoftAVC);
101};
102
103}  // namespace android
104
105#endif  // SOFT_AVC_H_
106
107