• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #ifndef OMX_VIDEO_DECODER_VP9HWR_H_
20 #define OMX_VIDEO_DECODER_VP9HWR_H_
21 
22 #include "OMXVideoDecoderBase.h"
23 #include "vpx/vpx_decoder.h"
24 #include "vpx/vpx_codec.h"
25 #include "vpx/vp8dx.h"
26 #include <va/va.h>
27 #include <va/va_android.h>
28 #include <va/va_tpi.h>
29 
30 // VAAPI Allocator internal Mem ID
31 typedef struct vaapiMemId
32 {
33     VASurfaceID*       m_surface;
34     unsigned int       m_key; //Gralloc handle from which this srf was created
35     unsigned char*     m_usrAddr;
36     bool               m_render_done;
37     bool               m_released;
38 }vaapiMemId;
39 
40 typedef unsigned int Display;
41 #define ANDROID_DISPLAY_HANDLE 0x18c34078
42 
43 #define DECODE_WITH_GRALLOC_BUFFER
44 #define VPX_DECODE_BORDER 0
45 
46 #define MAX_NATIVE_BUFFER_COUNT 64
47 
48 class OMXVideoDecoderVP9HWR : public OMXVideoDecoderBase {
49 public:
50     OMXVideoDecoderVP9HWR();
51     virtual ~OMXVideoDecoderVP9HWR();
52     vaapiMemId* extMIDs[MAX_NATIVE_BUFFER_COUNT];
53     int extUtilBufferCount;
54     int extMappedNativeBufferCount;
55     unsigned int extNativeBufferSize;
56     // (or mapped from vaSurface) to a pre-set max size.
57     int extActualBufferStride;
58     int extActualBufferHeightStride;
59 
60 protected:
61     virtual OMX_ERRORTYPE InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput);
62     virtual OMX_ERRORTYPE ProcessorInit(void);
63     virtual OMX_ERRORTYPE ProcessorDeinit(void);
64     virtual OMX_ERRORTYPE ProcessorStop(void);
65     virtual OMX_ERRORTYPE ProcessorFlush(OMX_U32 portIndex);
66     virtual OMX_ERRORTYPE ProcessorProcess(
67             OMX_BUFFERHEADERTYPE ***pBuffers,
68             buffer_retain_t *retains,
69             OMX_U32 numberBuffers);
70     virtual OMX_ERRORTYPE ProcessorReset(void);
71 
72     virtual OMX_ERRORTYPE ProcessorPreFillBuffer(OMX_BUFFERHEADERTYPE* buffer);
73     virtual bool IsAllBufferAvailable(void);
74 
75     virtual OMX_ERRORTYPE PrepareConfigBuffer(VideoConfigBuffer *p);
76     virtual OMX_ERRORTYPE PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p);
77 
78     virtual OMX_ERRORTYPE BuildHandlerList(void);
79 
80     virtual OMX_ERRORTYPE FillRenderBuffer(OMX_BUFFERHEADERTYPE **pBuffer,
81                                            buffer_retain_t *retain,
82                                            OMX_U32 inportBufferFlags,
83                                            OMX_BOOL *isResolutionChange);
84 
85     virtual OMX_ERRORTYPE HandleFormatChange(void);
86 
87     virtual OMX_COLOR_FORMATTYPE GetOutputColorFormat(int width);
88     virtual OMX_ERRORTYPE GetDecoderOutputCropSpecific(OMX_PTR pStructure);
89     virtual OMX_ERRORTYPE GetNativeBufferUsageSpecific(OMX_PTR pStructure);
90     virtual OMX_ERRORTYPE SetNativeBufferModeSpecific(OMX_PTR pStructure);
91 
92     friend int reallocVP9FrameBuffer(void *user_priv, unsigned int new_size, vpx_codec_frame_buffer_t *fb);
93 
94     DECLARE_HANDLER(OMXVideoDecoderVP9HWR, ParamVideoVp9);
95 private:
96     OMX_ERRORTYPE initDecoder();
97     OMX_ERRORTYPE destroyDecoder();
98 
99     enum {
100         // OMX_PARAM_PORTDEFINITIONTYPE
101         INPORT_MIN_BUFFER_COUNT = 1,
102         INPORT_ACTUAL_BUFFER_COUNT = 5,
103         INPORT_BUFFER_SIZE = 1382400,
104         OUTPORT_NATIVE_BUFFER_COUNT = 12, // 8 reference + 1 current + 3 for asynchronized mode
105         OUTPORT_ACTUAL_BUFFER_COUNT = 12,  // for raw data mode
106         INTERNAL_MAX_FRAME_WIDTH = 1920,
107         INTERNAL_MAX_FRAME_HEIGHT = 1088,
108     };
109 
110     void *mCtx;
111 
112     //OMX_VIDEO_PARAM_VP9TYPE mParamVp9;
113     vpx_codec_frame_buffer_t* mFrameBuffers;
114     int mNumFrameBuffer;
115 
116     // These members are for Adaptive playback
117     uint32_t mDecodedImageWidth;
118     uint32_t mDecodedImageHeight;
119     uint32_t mDecodedImageNewWidth;
120     uint32_t mDecodedImageNewHeight;
121 
122     Display* mDisplay;
123     VADisplay mVADisplay;
124 };
125 
126 #endif /* OMX_VIDEO_DECODER_VP9HWR_H_ */
127 
128