1/*
2 * Copyright (C) 2012 Intel Corporation.  All rights reserved.
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
18#ifndef __ISVWorker_H_
19#define __ISVWorker_H_
20
21#include <va/va.h>
22#include <va/va_vpp.h>
23#include <va/va_android.h>
24#include <OMX_Component.h>
25#include <utils/RefBase.h>
26#include "isv_profile.h"
27#include "isv_bufmanager.h"
28
29#define ANDROID_DISPLAY_HANDLE 0x18C34078
30#define Display unsigned int
31
32//FIXME: copy from OMX_Core.h
33
34/* interlaced frame flag: This flag is set to indicate the buffer contains a
35 * top and bottom field and display ordering is top field first.
36 * @ingroup buf
37 */
38#define OMX_BUFFERFLAG_TFF 0x00010000
39
40/* interlaced frame flag: This flag is set to indicate the buffer contains a
41 * top and bottom field and display ordering is bottom field first.
42 * @ingroup buf
43 */
44#define OMX_BUFFERFLAG_BFF 0x00020000
45
46using namespace android;
47
48typedef enum
49{
50    STATUS_OK = 0,
51    STATUS_NOT_SUPPORT,
52    STATUS_ALLOCATION_ERROR,
53    STATUS_ERROR,
54    STATUS_DATA_RENDERING
55} vpp_status;
56
57typedef enum
58{
59    DEINTERLACE_BOB = 0,                   // BOB DI
60    DEINTERLACE_ADI = 1,                   // ADI
61} deinterlace_t;
62
63//Avaiable filter types
64typedef enum
65{
66    FILTER_HQ   = 0,                      // high-quality filter (AVS scaling)
67    FILTER_FAST = 1,                      // fast filter (bilinear scaling)
68} filter_t;
69
70typedef struct {
71    uint32_t srcWidth;
72    uint32_t srcHeight;
73    uint32_t dstWidth;
74    uint32_t dstHeight;
75    uint32_t denoiseLevel;
76    uint32_t sharpnessLevel;
77    uint32_t colorBalanceLevel;
78    deinterlace_t deinterlaceType;
79    filter_t scalarType;
80    uint32_t frameRate;
81    uint32_t hasEncoder;
82    FRC_RATE frcRate;
83} FilterParam;
84
85class ISVBuffer;
86
87class ISVWorker : public RefBase
88{
89
90    public:
91        // config filters on or off based on video info
92        status_t configFilters(uint32_t filters, const FilterParam* filterParam);
93
94        // Initialize: setupVA()->setupFilters()->setupPipelineCaps()
95        status_t init(uint32_t width, uint32_t height);
96        status_t deinit();
97
98        // Get output buffer number needed for processing
99        uint32_t getProcBufCount();
100
101        // Get output buffer number needed for filling
102        uint32_t getFillBufCount();
103
104        // Send input and output buffers to VSP to begin processing
105        status_t process(ISVBuffer* input, Vector<ISVBuffer*> output, uint32_t outputCount, bool isEOS, uint32_t flags);
106
107        // Fill output buffers given, it's a blocking call
108        status_t fill(Vector<ISVBuffer*> output, uint32_t outputCount);
109
110        // reset index
111        status_t reset();
112
113        // set video display mode
114        void setDisplayMode(int32_t mode);
115
116        // get video display mode
117        int32_t getDisplayMode();
118
119        // check HDMI connection status
120        bool isHdmiConnected();
121
122        uint32_t getVppOutputFps();
123
124        // alloc/free VA surface
125        status_t allocSurface(uint32_t* width, uint32_t* height,
126                uint32_t stride, uint32_t format, unsigned long handle, int32_t* surfaceId);
127        status_t freeSurface(int32_t* surfaceId);
128
129        ISVWorker();
130        ~ISVWorker() {}
131
132    private:
133        // Check if VPP is supported
134        bool isSupport() const;
135
136        // Get output buffer number needed for processing
137        uint32_t getOutputBufCount(uint32_t index);
138
139        // Check filter caps and create filter buffers
140        status_t setupFilters();
141
142        // Setup pipeline caps
143        status_t setupPipelineCaps();
144
145        //check if the input fps is suportted in array fpsSet.
146        bool isFpsSupport(int32_t fps, int32_t *fpsSet, int32_t fpsSetCnt);
147
148        // Debug only
149        // Dump YUV frame
150        status_t dumpYUVFrameData(VASurfaceID surfaceID);
151        status_t writeNV12(int width, int height, unsigned char *out_buf, int y_pitch, int uv_pitch);
152
153        ISVWorker(const ISVWorker &);
154        ISVWorker &operator=(const ISVWorker &);
155
156    public:
157        uint32_t mNumForwardReferences;
158
159    private:
160        // VA common variables
161        VAContextID mVAContext;
162        uint32_t mWidth;
163        uint32_t mHeight;
164        Display * mDisplay;
165        VADisplay mVADisplay;
166        VAConfigID mVAConfig;
167
168        // Forward References Surfaces
169        Vector<VABufferID> mPipelineBuffers;
170        Mutex mPipelineBufferLock; // to protect access to mPipelineBuffers
171        VASurfaceID *mForwardReferences;
172        VASurfaceID mPrevInput;
173        VASurfaceID mPrevOutput;
174
175        // VPP Filters Buffers
176        uint32_t mNumFilterBuffers;
177        VABufferID mFilterBuffers[VAProcFilterCount];
178
179        // VPP filter configuration
180        VABufferID mFilterFrc;
181
182        // VPP filter configuration
183        uint32_t mFilters;
184        FilterParam mFilterParam;
185
186        // status
187        uint32_t mInputIndex;
188        uint32_t mOutputIndex;
189        uint32_t mOutputCount;
190
191        // FIXME: not very sure how to check color standard
192        VAProcColorStandardType in_color_standards[VAProcColorStandardCount];
193        VAProcColorStandardType out_color_standards[VAProcColorStandardCount];
194};
195
196#endif //__ISVWorker_H_
197