Home | History | Annotate | Download | only in hevcdec
      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 #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 
     55 struct SoftHEVC: public SoftVideoDecoderOMXComponent {
     56     SoftHEVC(const char *name, const OMX_CALLBACKTYPE *callbacks,
     57             OMX_PTR appData, OMX_COMPONENTTYPE **component);
     58 
     59 protected:
     60     virtual ~SoftHEVC();
     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);
     66 private:
     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     OMX_COLOR_FORMATTYPE mOmxColorFormat;    // OMX Color format
     92     IV_COLOR_FORMAT_T mIvColorFormat;        // Ittiam Color format
     93 
     94     bool mIsInFlush;        // codec is flush mode
     95     bool mReceivedEOS;      // EOS is receieved on input port
     96     bool mInitNeeded;
     97     uint32_t mNewWidth;
     98     uint32_t mNewHeight;
     99     // The input stream has changed to a different resolution, which is still supported by the
    100     // codec. So the codec is switching to decode the new resolution.
    101     bool mChangingResolution;
    102     bool mFlushNeeded;
    103 
    104     status_t initDecoder();
    105     status_t deInitDecoder();
    106     status_t setFlushMode();
    107     status_t setParams(size_t stride);
    108     void logVersion();
    109     status_t setNumCores();
    110     status_t resetDecoder();
    111     status_t resetPlugin();
    112     status_t reInitDecoder();
    113 
    114     void setDecodeArgs(ivd_video_decode_ip_t *ps_dec_ip,
    115         ivd_video_decode_op_t *ps_dec_op,
    116         OMX_BUFFERHEADERTYPE *inHeader,
    117         OMX_BUFFERHEADERTYPE *outHeader,
    118         size_t timeStampIx);
    119 
    120     DISALLOW_EVIL_CONSTRUCTORS (SoftHEVC);
    121 };
    122 
    123 } // namespace android
    124 
    125 #endif  // SOFT_HEVC_H_
    126