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
217f616d3cc5366a4b8af20d3d0c768e3de1df0666Lajos Molnar#include "SoftVideoDecoderOMXComponent.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
297f616d3cc5366a4b8af20d3d0c768e3de1df0666Lajos Molnarstruct SoftAVC : public SoftVideoDecoderOMXComponent {
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 void onQueueFilled(OMX_U32 portIndex);
390c1bc742181ded4930842b46e9507372f0b1b963James Dong    virtual void onPortFlushCompleted(OMX_U32 portIndex);
40d94e716af0e49d775f0c0c4f36dd2c136ba5f2b2Andreas Huber    virtual void onReset();
410c1bc742181ded4930842b46e9507372f0b1b963James Dong
420c1bc742181ded4930842b46e9507372f0b1b963James Dongprivate:
430c1bc742181ded4930842b46e9507372f0b1b963James Dong    enum {
440c1bc742181ded4930842b46e9507372f0b1b963James Dong        kNumInputBuffers  = 8,
45486247017e0bfb9db9994a53a28c0dacfebf8567James Dong        kNumOutputBuffers = 2,
460c1bc742181ded4930842b46e9507372f0b1b963James Dong    };
470c1bc742181ded4930842b46e9507372f0b1b963James Dong
480c1bc742181ded4930842b46e9507372f0b1b963James Dong    enum EOSStatus {
490c1bc742181ded4930842b46e9507372f0b1b963James Dong        INPUT_DATA_AVAILABLE,
500c1bc742181ded4930842b46e9507372f0b1b963James Dong        INPUT_EOS_SEEN,
510c1bc742181ded4930842b46e9507372f0b1b963James Dong        OUTPUT_FRAMES_FLUSHED,
520c1bc742181ded4930842b46e9507372f0b1b963James Dong    };
530c1bc742181ded4930842b46e9507372f0b1b963James Dong
540c1bc742181ded4930842b46e9507372f0b1b963James Dong    void *mHandle;
550c1bc742181ded4930842b46e9507372f0b1b963James Dong
560c1bc742181ded4930842b46e9507372f0b1b963James Dong    size_t mInputBufferCount;
570c1bc742181ded4930842b46e9507372f0b1b963James Dong
587f616d3cc5366a4b8af20d3d0c768e3de1df0666Lajos Molnar    uint32_t mPictureSize;
590c1bc742181ded4930842b46e9507372f0b1b963James Dong
600c1bc742181ded4930842b46e9507372f0b1b963James Dong    uint8_t *mFirstPicture;
610c1bc742181ded4930842b46e9507372f0b1b963James Dong    int32_t mFirstPictureId;
620c1bc742181ded4930842b46e9507372f0b1b963James Dong
630c1bc742181ded4930842b46e9507372f0b1b963James Dong    int32_t mPicId;  // Which output picture is for which input buffer?
640c1bc742181ded4930842b46e9507372f0b1b963James Dong
650c1bc742181ded4930842b46e9507372f0b1b963James Dong    // OMX_BUFFERHEADERTYPE may be overkill, but it is convenient
660c1bc742181ded4930842b46e9507372f0b1b963James Dong    // for tracking the following fields: nFlags, nTimeStamp, etc.
670c1bc742181ded4930842b46e9507372f0b1b963James Dong    KeyedVector<int32_t, OMX_BUFFERHEADERTYPE *> mPicToHeaderMap;
680c1bc742181ded4930842b46e9507372f0b1b963James Dong    bool mHeadersDecoded;
690c1bc742181ded4930842b46e9507372f0b1b963James Dong
700c1bc742181ded4930842b46e9507372f0b1b963James Dong    EOSStatus mEOSStatus;
710c1bc742181ded4930842b46e9507372f0b1b963James Dong
722961a85f5f00343c115ac8e5dc17de631694fb6eAndreas Huber    bool mSignalledError;
732961a85f5f00343c115ac8e5dc17de631694fb6eAndreas Huber
740c1bc742181ded4930842b46e9507372f0b1b963James Dong    status_t initDecoder();
752309d1a1ff016a31d9aa68272bcb471e64a26cfaAndreas Huber    void drainAllOutputBuffers(bool eos);
760c1bc742181ded4930842b46e9507372f0b1b963James Dong    void drainOneOutputBuffer(int32_t picId, uint8_t *data);
770c1bc742181ded4930842b46e9507372f0b1b963James Dong    void saveFirstOutputBuffer(int32_t pidId, uint8_t *data);
780c1bc742181ded4930842b46e9507372f0b1b963James Dong    bool handleCropRectEvent(const CropParams* crop);
790c1bc742181ded4930842b46e9507372f0b1b963James Dong    bool handlePortSettingChangeEvent(const H264SwDecInfo *info);
800c1bc742181ded4930842b46e9507372f0b1b963James Dong
810c1bc742181ded4930842b46e9507372f0b1b963James Dong    DISALLOW_EVIL_CONSTRUCTORS(SoftAVC);
820c1bc742181ded4930842b46e9507372f0b1b963James Dong};
830c1bc742181ded4930842b46e9507372f0b1b963James Dong
840c1bc742181ded4930842b46e9507372f0b1b963James Dong}  // namespace android
850c1bc742181ded4930842b46e9507372f0b1b963James Dong
860c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif  // SOFT_AVC_H_
870c1bc742181ded4930842b46e9507372f0b1b963James Dong
88