1 /* 2 * Copyright (C) 2014 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_HEVC_H_ 18 19 #define SOFT_HEVC_H_ 20 21 #include "SoftVideoDecoderOMXComponent.h" 22 #include <sys/time.h> 23 24 namespace android { 25 26 /** Number of entries in the time-stamp array */ 27 #define MAX_TIME_STAMPS 64 28 29 /** Maximum number of cores supported by the codec */ 30 #define CODEC_MAX_NUM_CORES 4 31 32 #define CODEC_MAX_WIDTH 1920 33 34 #define CODEC_MAX_HEIGHT 1088 35 36 /** Input buffer size */ 37 #define INPUT_BUF_SIZE (1024 * 1024) 38 39 #define MIN(a, b) ((a) < (b)) ? (a) : (b) 40 41 /** Used to remove warnings about unused parameters */ 42 #define UNUSED(x) ((void)(x)) 43 44 /** Get time */ 45 #define GETTIME(a, b) gettimeofday(a, b); 46 47 /** Compute difference between start and end */ 48 #define TIME_DIFF(start, end, diff) \ 49 diff = ((end.tv_sec - start.tv_sec) * 1000000) + \ 50 (end.tv_usec - start.tv_usec); 51 52 struct SoftHEVC: public SoftVideoDecoderOMXComponent { 53 SoftHEVC(const char *name, const OMX_CALLBACKTYPE *callbacks, 54 OMX_PTR appData, OMX_COMPONENTTYPE **component); 55 56 status_t init(); 57 58 protected: 59 virtual ~SoftHEVC(); 60 61 virtual void onQueueFilled(OMX_U32 portIndex); 62 virtual void onPortFlushCompleted(OMX_U32 portIndex); 63 virtual void onReset(); 64 virtual int getColorAspectPreference(); 65 private: 66 // Number of input and output buffers 67 enum { 68 kNumBuffers = 8 69 }; 70 71 iv_obj_t *mCodecCtx; // Codec context 72 73 size_t mNumCores; // Number of cores to be uesd by the codec 74 75 struct timeval mTimeStart; // Time at the start of decode() 76 struct timeval mTimeEnd; // Time at the end of decode() 77 78 // Internal buffer to be used to flush out the buffers from decoder 79 uint8_t *mFlushOutBuffer; 80 81 // Status of entries in the timestamp array 82 bool mTimeStampsValid[MAX_TIME_STAMPS]; 83 84 // Timestamp array - Since codec does not take 64 bit timestamps, 85 // they are maintained in the plugin 86 OMX_S64 mTimeStamps[MAX_TIME_STAMPS]; 87 88 OMX_COLOR_FORMATTYPE mOmxColorFormat; // OMX Color format 89 IV_COLOR_FORMAT_T mIvColorFormat; // Ittiam Color format 90 91 bool mIsInFlush; // codec is flush mode 92 bool mReceivedEOS; // EOS is receieved on input port 93 94 // The input stream has changed to a different resolution, which is still supported by the 95 // codec. So the codec is switching to decode the new resolution. 96 bool mChangingResolution; 97 bool mFlushNeeded; 98 bool mSignalledError; 99 size_t mStride; 100 101 status_t initDecoder(); 102 status_t deInitDecoder(); 103 status_t setFlushMode(); 104 status_t setParams(size_t stride); 105 void logVersion(); 106 status_t setNumCores(); 107 status_t resetDecoder(); 108 status_t resetPlugin(); 109 110 bool setDecodeArgs(ivd_video_decode_ip_t *ps_dec_ip, 111 ivd_video_decode_op_t *ps_dec_op, 112 OMX_BUFFERHEADERTYPE *inHeader, 113 OMX_BUFFERHEADERTYPE *outHeader, 114 size_t timeStampIx); 115 116 bool getVUIParams(); 117 118 DISALLOW_EVIL_CONSTRUCTORS (SoftHEVC); 119 }; 120 121 } // namespace android 122 123 #endif // SOFT_HEVC_H_ 124