SoftHEVC.h revision 1640bd2d959432ce2b06a99e2a14e8c5c74efce2
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
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 SoftHEVC: public SoftVideoDecoderOMXComponent {
56    SoftHEVC(const char *name, const OMX_CALLBACKTYPE *callbacks,
57            OMX_PTR appData, OMX_COMPONENTTYPE **component);
58
59    status_t init();
60
61protected:
62    virtual ~SoftHEVC();
63
64    virtual void onQueueFilled(OMX_U32 portIndex);
65    virtual void onPortFlushCompleted(OMX_U32 portIndex);
66    virtual void onReset();
67    virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params);
68private:
69    // Number of input and output buffers
70    enum {
71        kNumBuffers = 8
72    };
73
74    iv_obj_t *mCodecCtx;         // Codec context
75    iv_mem_rec_t *mMemRecords;   // Memory records requested by the codec
76    size_t mNumMemRecords;       // Number of memory records requested by the codec
77
78    size_t mNumCores;            // Number of cores to be uesd by the codec
79
80    struct timeval mTimeStart;   // Time at the start of decode()
81    struct timeval mTimeEnd;     // Time at the end of decode()
82
83    // Internal buffer to be used to flush out the buffers from decoder
84    uint8_t *mFlushOutBuffer;
85
86    // Status of entries in the timestamp array
87    bool mTimeStampsValid[MAX_TIME_STAMPS];
88
89    // Timestamp array - Since codec does not take 64 bit timestamps,
90    // they are maintained in the plugin
91    OMX_S64 mTimeStamps[MAX_TIME_STAMPS];
92
93    OMX_COLOR_FORMATTYPE mOmxColorFormat;    // OMX Color format
94    IV_COLOR_FORMAT_T mIvColorFormat;        // Ittiam Color format
95
96    bool mIsInFlush;        // codec is flush mode
97    bool mReceivedEOS;      // EOS is receieved on input port
98    bool mInitNeeded;
99    uint32_t mNewWidth;
100    uint32_t mNewHeight;
101    // The input stream has changed to a different resolution, which is still supported by the
102    // codec. So the codec is switching to decode the new resolution.
103    bool mChangingResolution;
104    bool mFlushNeeded;
105
106    status_t initDecoder();
107    status_t deInitDecoder();
108    status_t setFlushMode();
109    status_t setParams(size_t stride);
110    void logVersion();
111    status_t setNumCores();
112    status_t resetDecoder();
113    status_t resetPlugin();
114    status_t reInitDecoder();
115
116    void setDecodeArgs(ivd_video_decode_ip_t *ps_dec_ip,
117        ivd_video_decode_op_t *ps_dec_op,
118        OMX_BUFFERHEADERTYPE *inHeader,
119        OMX_BUFFERHEADERTYPE *outHeader,
120        size_t timeStampIx);
121
122    DISALLOW_EVIL_CONSTRUCTORS (SoftHEVC);
123};
124
125} // namespace android
126
127#endif  // SOFT_HEVC_H_
128