10c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
20c1bc742181ded4930842b46e9507372f0b1b963James Dong * Copyright (C) 2011 The Android Open Source Project
30c1bc742181ded4930842b46e9507372f0b1b963James Dong *
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * Licensed under the Apache License, Version 2.0 (the "License");
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * you may not use this file except in compliance with the License.
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * You may obtain a copy of the License at
70c1bc742181ded4930842b46e9507372f0b1b963James Dong *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong *      http://www.apache.org/licenses/LICENSE-2.0
90c1bc742181ded4930842b46e9507372f0b1b963James Dong *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong * Unless required by applicable law or agreed to in writing, software
110c1bc742181ded4930842b46e9507372f0b1b963James Dong * distributed under the License is distributed on an "AS IS" BASIS,
120c1bc742181ded4930842b46e9507372f0b1b963James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * See the License for the specific language governing permissions and
140c1bc742181ded4930842b46e9507372f0b1b963James Dong * limitations under the License.
150c1bc742181ded4930842b46e9507372f0b1b963James Dong */
160c1bc742181ded4930842b46e9507372f0b1b963James Dong
170c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef SOFT_AVC_H_
180c1bc742181ded4930842b46e9507372f0b1b963James Dong
190c1bc742181ded4930842b46e9507372f0b1b963James Dong#define SOFT_AVC_H_
200c1bc742181ded4930842b46e9507372f0b1b963James Dong
210c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "SimpleSoftOMXComponent.h"
220c1bc742181ded4930842b46e9507372f0b1b963James Dong#include <utils/KeyedVector.h>
230c1bc742181ded4930842b46e9507372f0b1b963James Dong
240c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "H264SwDecApi.h"
250c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "basetype.h"
260c1bc742181ded4930842b46e9507372f0b1b963James Dong
270c1bc742181ded4930842b46e9507372f0b1b963James Dongnamespace android {
280c1bc742181ded4930842b46e9507372f0b1b963James Dong
290c1bc742181ded4930842b46e9507372f0b1b963James Dongstruct SoftAVC : public SimpleSoftOMXComponent {
300c1bc742181ded4930842b46e9507372f0b1b963James Dong    SoftAVC(const char *name,
310c1bc742181ded4930842b46e9507372f0b1b963James Dong            const OMX_CALLBACKTYPE *callbacks,
320c1bc742181ded4930842b46e9507372f0b1b963James Dong            OMX_PTR appData,
330c1bc742181ded4930842b46e9507372f0b1b963James Dong            OMX_COMPONENTTYPE **component);
340c1bc742181ded4930842b46e9507372f0b1b963James Dong
350c1bc742181ded4930842b46e9507372f0b1b963James Dongprotected:
360c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual ~SoftAVC();
370c1bc742181ded4930842b46e9507372f0b1b963James Dong
380c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual OMX_ERRORTYPE internalGetParameter(
390c1bc742181ded4930842b46e9507372f0b1b963James Dong            OMX_INDEXTYPE index, OMX_PTR params);
400c1bc742181ded4930842b46e9507372f0b1b963James Dong
410c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual OMX_ERRORTYPE internalSetParameter(
420c1bc742181ded4930842b46e9507372f0b1b963James Dong            OMX_INDEXTYPE index, const OMX_PTR params);
430c1bc742181ded4930842b46e9507372f0b1b963James Dong
440c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual OMX_ERRORTYPE getConfig(OMX_INDEXTYPE index, OMX_PTR params);
450c1bc742181ded4930842b46e9507372f0b1b963James Dong
460c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual void onQueueFilled(OMX_U32 portIndex);
470c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual void onPortFlushCompleted(OMX_U32 portIndex);
480c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
490c1bc742181ded4930842b46e9507372f0b1b963James Dong
500c1bc742181ded4930842b46e9507372f0b1b963James Dongprivate:
510c1bc742181ded4930842b46e9507372f0b1b963James Dong    enum {
520c1bc742181ded4930842b46e9507372f0b1b963James Dong        kInputPortIndex   = 0,
530c1bc742181ded4930842b46e9507372f0b1b963James Dong        kOutputPortIndex  = 1,
540c1bc742181ded4930842b46e9507372f0b1b963James Dong        kNumInputBuffers  = 8,
55486247017e0bfb9db9994a53a28c0dacfebf8567James Dong        kNumOutputBuffers = 2,
560c1bc742181ded4930842b46e9507372f0b1b963James Dong    };
570c1bc742181ded4930842b46e9507372f0b1b963James Dong
580c1bc742181ded4930842b46e9507372f0b1b963James Dong    enum EOSStatus {
590c1bc742181ded4930842b46e9507372f0b1b963James Dong        INPUT_DATA_AVAILABLE,
600c1bc742181ded4930842b46e9507372f0b1b963James Dong        INPUT_EOS_SEEN,
610c1bc742181ded4930842b46e9507372f0b1b963James Dong        OUTPUT_FRAMES_FLUSHED,
620c1bc742181ded4930842b46e9507372f0b1b963James Dong    };
630c1bc742181ded4930842b46e9507372f0b1b963James Dong
640c1bc742181ded4930842b46e9507372f0b1b963James Dong    void *mHandle;
650c1bc742181ded4930842b46e9507372f0b1b963James Dong
660c1bc742181ded4930842b46e9507372f0b1b963James Dong    size_t mInputBufferCount;
670c1bc742181ded4930842b46e9507372f0b1b963James Dong
680c1bc742181ded4930842b46e9507372f0b1b963James Dong    uint32_t mWidth, mHeight, mPictureSize;
690c1bc742181ded4930842b46e9507372f0b1b963James Dong    uint32_t mCropLeft, mCropTop;
70639ffaca514deb9de538bc2dc6e712380db68fd3James Dong    uint32_t mCropWidth, mCropHeight;
710c1bc742181ded4930842b46e9507372f0b1b963James Dong
720c1bc742181ded4930842b46e9507372f0b1b963James Dong    uint8_t *mFirstPicture;
730c1bc742181ded4930842b46e9507372f0b1b963James Dong    int32_t mFirstPictureId;
740c1bc742181ded4930842b46e9507372f0b1b963James Dong
750c1bc742181ded4930842b46e9507372f0b1b963James Dong    int32_t mPicId;  // Which output picture is for which input buffer?
760c1bc742181ded4930842b46e9507372f0b1b963James Dong
770c1bc742181ded4930842b46e9507372f0b1b963James Dong    // OMX_BUFFERHEADERTYPE may be overkill, but it is convenient
780c1bc742181ded4930842b46e9507372f0b1b963James Dong    // for tracking the following fields: nFlags, nTimeStamp, etc.
790c1bc742181ded4930842b46e9507372f0b1b963James Dong    KeyedVector<int32_t, OMX_BUFFERHEADERTYPE *> mPicToHeaderMap;
800c1bc742181ded4930842b46e9507372f0b1b963James Dong    bool mHeadersDecoded;
810c1bc742181ded4930842b46e9507372f0b1b963James Dong
820c1bc742181ded4930842b46e9507372f0b1b963James Dong    EOSStatus mEOSStatus;
830c1bc742181ded4930842b46e9507372f0b1b963James Dong
840c1bc742181ded4930842b46e9507372f0b1b963James Dong    enum OutputPortSettingChange {
850c1bc742181ded4930842b46e9507372f0b1b963James Dong        NONE,
860c1bc742181ded4930842b46e9507372f0b1b963James Dong        AWAITING_DISABLED,
870c1bc742181ded4930842b46e9507372f0b1b963James Dong        AWAITING_ENABLED
880c1bc742181ded4930842b46e9507372f0b1b963James Dong    };
890c1bc742181ded4930842b46e9507372f0b1b963James Dong    OutputPortSettingChange mOutputPortSettingsChange;
900c1bc742181ded4930842b46e9507372f0b1b963James Dong
912961a85f5f00343c115ac8e5dc17de631694fb6eAndreas Huber    bool mSignalledError;
922961a85f5f00343c115ac8e5dc17de631694fb6eAndreas Huber
930c1bc742181ded4930842b46e9507372f0b1b963James Dong    void initPorts();
940c1bc742181ded4930842b46e9507372f0b1b963James Dong    status_t initDecoder();
950c1bc742181ded4930842b46e9507372f0b1b963James Dong    void updatePortDefinitions();
960c1bc742181ded4930842b46e9507372f0b1b963James Dong    bool drainAllOutputBuffers();
970c1bc742181ded4930842b46e9507372f0b1b963James Dong    void drainOneOutputBuffer(int32_t picId, uint8_t *data);
980c1bc742181ded4930842b46e9507372f0b1b963James Dong    void saveFirstOutputBuffer(int32_t pidId, uint8_t *data);
990c1bc742181ded4930842b46e9507372f0b1b963James Dong    bool handleCropRectEvent(const CropParams* crop);
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong    bool handlePortSettingChangeEvent(const H264SwDecInfo *info);
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong    DISALLOW_EVIL_CONSTRUCTORS(SoftAVC);
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong};
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong}  // namespace android
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif  // SOFT_AVC_H_
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong
109