SoftAVCDec.h revision eedcd5cccc2be322e34d725759c2d01c227b89e4
1/* 2 * Copyright 2015 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_H264_DEC_H_ 18 19#define SOFT_H264_DEC_H_ 20 21#include "SoftVideoDecoderOMXComponent.h" 22#include <sys/time.h> 23 24namespace android { 25 26#define ivd_aligned_malloc(alignment, size) memalign(alignment, size) 27#define ivd_aligned_free(buf) free(buf) 28 29/** Number of entries in the time-stamp array */ 30#define MAX_TIME_STAMPS 64 31 32/** Maximum number of cores supported by the codec */ 33#define CODEC_MAX_NUM_CORES 4 34 35#define CODEC_MAX_WIDTH 1920 36 37#define CODEC_MAX_HEIGHT 1088 38 39/** Input buffer size */ 40#define INPUT_BUF_SIZE (1024 * 1024) 41 42#define MIN(a, b) ((a) < (b)) ? (a) : (b) 43 44/** Used to remove warnings about unused parameters */ 45#define UNUSED(x) ((void)(x)) 46 47/** Get time */ 48#define GETTIME(a, b) gettimeofday(a, b); 49 50/** Compute difference between start and end */ 51#define TIME_DIFF(start, end, diff) \ 52 diff = ((end.tv_sec - start.tv_sec) * 1000000) + \ 53 (end.tv_usec - start.tv_usec); 54 55struct SoftAVC : public SoftVideoDecoderOMXComponent { 56 SoftAVC(const char *name, const OMX_CALLBACKTYPE *callbacks, 57 OMX_PTR appData, OMX_COMPONENTTYPE **component); 58 59protected: 60 virtual ~SoftAVC(); 61 62 virtual void onQueueFilled(OMX_U32 portIndex); 63 virtual void onPortFlushCompleted(OMX_U32 portIndex); 64 virtual void onReset(); 65 virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params); 66private: 67 // Number of input and output buffers 68 enum { 69 kNumBuffers = 8 70 }; 71 72 iv_obj_t *mCodecCtx; // Codec context 73 iv_mem_rec_t *mMemRecords; // Memory records requested by the codec 74 size_t mNumMemRecords; // Number of memory records requested by the codec 75 76 size_t mNumCores; // Number of cores to be uesd by the codec 77 78 struct timeval mTimeStart; // Time at the start of decode() 79 struct timeval mTimeEnd; // Time at the end of decode() 80 81 // Internal buffer to be used to flush out the buffers from decoder 82 uint8_t *mFlushOutBuffer; 83 84 // Status of entries in the timestamp array 85 bool mTimeStampsValid[MAX_TIME_STAMPS]; 86 87 // Timestamp array - Since codec does not take 64 bit timestamps, 88 // they are maintained in the plugin 89 OMX_S64 mTimeStamps[MAX_TIME_STAMPS]; 90 91#ifdef FILE_DUMP_ENABLE 92 char mInFile[200]; 93#endif /* FILE_DUMP_ENABLE */ 94 95 OMX_COLOR_FORMATTYPE mOmxColorFormat; // OMX Color format 96 IV_COLOR_FORMAT_T mIvColorFormat; // Ittiam Color format 97 98 bool mIsInFlush; // codec is flush mode 99 bool mReceivedEOS; // EOS is receieved on input port 100 bool mInitNeeded; 101 uint32_t mNewWidth; 102 uint32_t mNewHeight; 103 uint32_t mNewLevel; 104 // The input stream has changed to a different resolution, which is still supported by the 105 // codec. So the codec is switching to decode the new resolution. 106 bool mChangingResolution; 107 bool mFlushNeeded; 108 109 status_t initDecoder(); 110 status_t deInitDecoder(); 111 status_t setFlushMode(); 112 status_t setParams(size_t stride); 113 void logVersion(); 114 status_t setNumCores(); 115 status_t resetDecoder(); 116 status_t resetPlugin(); 117 status_t reInitDecoder(); 118 119 void setDecodeArgs( 120 ivd_video_decode_ip_t *ps_dec_ip, 121 ivd_video_decode_op_t *ps_dec_op, 122 OMX_BUFFERHEADERTYPE *inHeader, 123 OMX_BUFFERHEADERTYPE *outHeader, 124 size_t timeStampIx); 125 126 DISALLOW_EVIL_CONSTRUCTORS(SoftAVC); 127}; 128 129#ifdef FILE_DUMP_ENABLE 130 131#define INPUT_DUMP_PATH "/sdcard/media/avcd_input" 132#define INPUT_DUMP_EXT "h264" 133 134#define GENERATE_FILE_NAMES() { \ 135 GETTIME(&mTimeStart, NULL); \ 136 strcpy(mInFile, ""); \ 137 sprintf(mInFile, "%s_%ld.%ld.%s", INPUT_DUMP_PATH, \ 138 mTimeStart.tv_sec, mTimeStart.tv_usec, \ 139 INPUT_DUMP_EXT); \ 140} 141 142#define CREATE_DUMP_FILE(m_filename) { \ 143 FILE *fp = fopen(m_filename, "wb"); \ 144 if (fp != NULL) { \ 145 fclose(fp); \ 146 } else { \ 147 ALOGD("Could not open file %s", m_filename); \ 148 } \ 149} 150#define DUMP_TO_FILE(m_filename, m_buf, m_size) \ 151{ \ 152 FILE *fp = fopen(m_filename, "ab"); \ 153 if (fp != NULL && m_buf != NULL) { \ 154 int i; \ 155 i = fwrite(m_buf, 1, m_size, fp); \ 156 ALOGD("fwrite ret %d to write %d", i, m_size); \ 157 if (i != (int) m_size) { \ 158 ALOGD("Error in fwrite, returned %d", i); \ 159 perror("Error in write to file"); \ 160 } \ 161 fclose(fp); \ 162 } else { \ 163 ALOGD("Could not write to file %s", m_filename);\ 164 } \ 165} 166#else /* FILE_DUMP_ENABLE */ 167#define INPUT_DUMP_PATH 168#define INPUT_DUMP_EXT 169#define OUTPUT_DUMP_PATH 170#define OUTPUT_DUMP_EXT 171#define GENERATE_FILE_NAMES() 172#define CREATE_DUMP_FILE(m_filename) 173#define DUMP_TO_FILE(m_filename, m_buf, m_size) 174#endif /* FILE_DUMP_ENABLE */ 175 176} // namespace android 177 178#endif // SOFT_H264_DEC_H_ 179