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/** 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 44struct SoftAVC : public SoftVideoDecoderOMXComponent { 45 SoftAVC(const char *name, const OMX_CALLBACKTYPE *callbacks, 46 OMX_PTR appData, OMX_COMPONENTTYPE **component); 47 48protected: 49 virtual ~SoftAVC(); 50 51 virtual void onQueueFilled(OMX_U32 portIndex); 52 virtual void onPortFlushCompleted(OMX_U32 portIndex); 53 virtual void onReset(); 54 virtual int getColorAspectPreference(); 55private: 56 // Number of input and output buffers 57 enum { 58 kNumBuffers = 8 59 }; 60 61 iv_obj_t *mCodecCtx; // Codec context 62 63 size_t mNumCores; // Number of cores to be uesd by the codec 64 65 nsecs_t mTimeStart; // Time at the start of decode() 66 nsecs_t mTimeEnd; // Time at the end of decode() 67 68 // Internal buffer to be used to flush out the buffers from decoder 69 uint8_t *mFlushOutBuffer; 70 71 // Status of entries in the timestamp array 72 bool mTimeStampsValid[MAX_TIME_STAMPS]; 73 74 // Timestamp array - Since codec does not take 64 bit timestamps, 75 // they are maintained in the plugin 76 OMX_S64 mTimeStamps[MAX_TIME_STAMPS]; 77 78#ifdef FILE_DUMP_ENABLE 79 char mInFile[200]; 80#endif /* FILE_DUMP_ENABLE */ 81 82 OMX_COLOR_FORMATTYPE mOmxColorFormat; // OMX Color format 83 IV_COLOR_FORMAT_T mIvColorFormat; // Ittiam Color format 84 85 bool mIsInFlush; // codec is flush mode 86 bool mReceivedEOS; // EOS is receieved on input port 87 88 // The input stream has changed to a different resolution, which is still supported by the 89 // codec. So the codec is switching to decode the new resolution. 90 bool mChangingResolution; 91 bool mFlushNeeded; 92 bool mSignalledError; 93 size_t mStride; 94 size_t mInputOffset; 95 96 status_t initDecoder(); 97 status_t deInitDecoder(); 98 status_t setFlushMode(); 99 status_t setParams(size_t stride); 100 void logVersion(); 101 status_t setNumCores(); 102 status_t resetDecoder(); 103 status_t resetPlugin(); 104 105 106 bool setDecodeArgs( 107 ivd_video_decode_ip_t *ps_dec_ip, 108 ivd_video_decode_op_t *ps_dec_op, 109 OMX_BUFFERHEADERTYPE *inHeader, 110 OMX_BUFFERHEADERTYPE *outHeader, 111 size_t timeStampIx); 112 113 bool getVUIParams(); 114 115 DISALLOW_EVIL_CONSTRUCTORS(SoftAVC); 116}; 117 118#ifdef FILE_DUMP_ENABLE 119 120#define INPUT_DUMP_PATH "/sdcard/media/avcd_input" 121#define INPUT_DUMP_EXT "h264" 122 123#define GENERATE_FILE_NAMES() { \ 124 strcpy(mInFile, ""); \ 125 sprintf(mInFile, "%s_%lld.%s", INPUT_DUMP_PATH, \ 126 (long long) mTimeStart, \ 127 INPUT_DUMP_EXT); \ 128} 129 130#define CREATE_DUMP_FILE(m_filename) { \ 131 FILE *fp = fopen(m_filename, "wb"); \ 132 if (fp != NULL) { \ 133 fclose(fp); \ 134 } else { \ 135 ALOGD("Could not open file %s", m_filename); \ 136 } \ 137} 138#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset)\ 139{ \ 140 FILE *fp = fopen(m_filename, "ab"); \ 141 if (fp != NULL && m_buf != NULL && m_offset == 0) { \ 142 int i; \ 143 i = fwrite(m_buf, 1, m_size, fp); \ 144 ALOGD("fwrite ret %d to write %d", i, m_size); \ 145 if (i != (int) m_size) { \ 146 ALOGD("Error in fwrite, returned %d", i); \ 147 perror("Error in write to file"); \ 148 } \ 149 } else if (fp == NULL) { \ 150 ALOGD("Could not write to file %s", m_filename);\ 151 } \ 152 if (fp) { \ 153 fclose(fp); \ 154 } \ 155} 156#else /* FILE_DUMP_ENABLE */ 157#define INPUT_DUMP_PATH 158#define INPUT_DUMP_EXT 159#define OUTPUT_DUMP_PATH 160#define OUTPUT_DUMP_EXT 161#define GENERATE_FILE_NAMES() 162#define CREATE_DUMP_FILE(m_filename) 163#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset) 164#endif /* FILE_DUMP_ENABLE */ 165 166} // namespace android 167 168#endif // SOFT_H264_DEC_H_ 169