1/*
2 * Copyright (C) 2013 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_VIDEO_DECODER_OMX_COMPONENT_H_
18
19#define SOFT_VIDEO_DECODER_OMX_COMPONENT_H_
20
21#include "SimpleSoftOMXComponent.h"
22
23#include <media/stagefright/foundation/AHandlerReflector.h>
24#include <media/IOMX.h>
25
26#include <utils/RefBase.h>
27#include <utils/threads.h>
28#include <utils/Vector.h>
29
30namespace android {
31
32struct SoftVideoDecoderOMXComponent : public SimpleSoftOMXComponent {
33    SoftVideoDecoderOMXComponent(
34            const char *name,
35            const char *componentRole,
36            OMX_VIDEO_CODINGTYPE codingType,
37            const CodecProfileLevel *profileLevels,
38            size_t numProfileLevels,
39            int32_t width,
40            int32_t height,
41            const OMX_CALLBACKTYPE *callbacks,
42            OMX_PTR appData,
43            OMX_COMPONENTTYPE **component);
44
45protected:
46    virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
47    virtual void onReset();
48
49    virtual OMX_ERRORTYPE internalGetParameter(
50            OMX_INDEXTYPE index, OMX_PTR params);
51
52    virtual OMX_ERRORTYPE internalSetParameter(
53            OMX_INDEXTYPE index, const OMX_PTR params);
54
55    virtual OMX_ERRORTYPE getConfig(
56            OMX_INDEXTYPE index, OMX_PTR params);
57
58    virtual OMX_ERRORTYPE getExtensionIndex(
59            const char *name, OMX_INDEXTYPE *index);
60
61    void initPorts(OMX_U32 numInputBuffers,
62            OMX_U32 inputBufferSize,
63            OMX_U32 numOutputBuffers,
64            const char *mimeType,
65            OMX_U32 minCompressionRatio = 1u);
66
67    virtual void updatePortDefinitions(bool updateCrop = true, bool updateInputSize = false);
68
69    uint32_t outputBufferWidth();
70    uint32_t outputBufferHeight();
71
72    enum CropSettingsMode {
73        kCropUnSet = 0,
74        kCropSet,
75        kCropChanged,
76    };
77    void handlePortSettingsChange(
78            bool *portWillReset, uint32_t width, uint32_t height,
79            CropSettingsMode cropSettingsMode = kCropUnSet, bool fakeStride = false);
80
81    void copyYV12FrameToOutputBuffer(
82            uint8_t *dst, const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
83            size_t srcYStride, size_t srcUStride, size_t srcVStride);
84
85    enum {
86        kInputPortIndex  = 0,
87        kOutputPortIndex = 1,
88        kMaxPortIndex = 1,
89    };
90
91    bool mIsAdaptive;
92    uint32_t mAdaptiveMaxWidth, mAdaptiveMaxHeight;
93    uint32_t mWidth, mHeight;
94    uint32_t mCropLeft, mCropTop, mCropWidth, mCropHeight;
95
96    enum {
97        NONE,
98        AWAITING_DISABLED,
99        AWAITING_ENABLED
100    } mOutputPortSettingsChange;
101
102private:
103    uint32_t mMinInputBufferSize;
104    uint32_t mMinCompressionRatio;
105
106    const char *mComponentRole;
107    OMX_VIDEO_CODINGTYPE mCodingType;
108    const CodecProfileLevel *mProfileLevels;
109    size_t mNumProfileLevels;
110
111    DISALLOW_EVIL_CONSTRUCTORS(SoftVideoDecoderOMXComponent);
112};
113
114}  // namespace android
115
116#endif  // SOFT_VIDEO_DECODER_OMX_COMPONENT_H_
117