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