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 27 namespace android { 28 29 struct SoftAVC : public SimpleSoftOMXComponent { 30 SoftAVC(const char *name, 31 const OMX_CALLBACKTYPE *callbacks, 32 OMX_PTR appData, 33 OMX_COMPONENTTYPE **component); 34 35 protected: 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 50 private: 51 enum { 52 kInputPortIndex = 0, 53 kOutputPortIndex = 1, 54 kNumInputBuffers = 8, 55 kNumOutputBuffers = 2, 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 bool mSignalledError; 92 93 void initPorts(); 94 status_t initDecoder(); 95 void updatePortDefinitions(); 96 bool drainAllOutputBuffers(); 97 void drainOneOutputBuffer(int32_t picId, uint8_t *data); 98 void saveFirstOutputBuffer(int32_t pidId, uint8_t *data); 99 bool handleCropRectEvent(const CropParams* crop); 100 bool handlePortSettingChangeEvent(const H264SwDecInfo *info); 101 102 DISALLOW_EVIL_CONSTRUCTORS(SoftAVC); 103 }; 104 105 } // namespace android 106 107 #endif // SOFT_AVC_H_ 108 109