1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2013 Advanced Micro Devices, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifndef VID_DEC_COMMON_H
29bf215546Sopenharmony_ci#define VID_DEC_COMMON_H
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "util/list.h"
32bf215546Sopenharmony_ci#include "util/vl_rbsp.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "vl/vl_compositor.h"
35bf215546Sopenharmony_ci#include "vl/vl_zscan.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "bellagio/vid_dec_av1.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include <OMX_Core.h>
40bf215546Sopenharmony_ci#include <OMX_Types.h>
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci#if ENABLE_ST_OMX_BELLAGIO
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci#include <bellagio/st_static_component_loader.h>
45bf215546Sopenharmony_ci#include <bellagio/omx_base_filter.h>
46bf215546Sopenharmony_ci#include <bellagio/omx_base_video_port.h>
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ciDERIVEDCLASS(vid_dec_PrivateType, omx_base_filter_PrivateType)
49bf215546Sopenharmony_ci#define vid_dec_PrivateType_FIELDS omx_base_filter_PrivateType_FIELDS \
50bf215546Sopenharmony_ci   enum pipe_video_profile profile; \
51bf215546Sopenharmony_ci   struct vl_screen *screen; \
52bf215546Sopenharmony_ci   struct pipe_context *pipe; \
53bf215546Sopenharmony_ci   struct pipe_video_codec *codec; \
54bf215546Sopenharmony_ci   void (*Decode)(vid_dec_PrivateType *priv, struct vl_vlc *vlc, unsigned min_bits_left); \
55bf215546Sopenharmony_ci   void (*EndFrame)(vid_dec_PrivateType *priv); \
56bf215546Sopenharmony_ci   struct pipe_video_buffer *(*Flush)(vid_dec_PrivateType *priv, OMX_TICKS *timestamp); \
57bf215546Sopenharmony_ci   struct pipe_video_buffer *target, *shadow; \
58bf215546Sopenharmony_ci   union { \
59bf215546Sopenharmony_ci      struct { \
60bf215546Sopenharmony_ci         uint8_t intra_matrix[64]; \
61bf215546Sopenharmony_ci         uint8_t non_intra_matrix[64]; \
62bf215546Sopenharmony_ci      } mpeg12; \
63bf215546Sopenharmony_ci      struct { \
64bf215546Sopenharmony_ci         unsigned nal_ref_idc; \
65bf215546Sopenharmony_ci         bool IdrPicFlag; \
66bf215546Sopenharmony_ci         unsigned idr_pic_id; \
67bf215546Sopenharmony_ci         unsigned pic_order_cnt_lsb; \
68bf215546Sopenharmony_ci         unsigned pic_order_cnt_msb; \
69bf215546Sopenharmony_ci         unsigned delta_pic_order_cnt_bottom; \
70bf215546Sopenharmony_ci         unsigned delta_pic_order_cnt[2]; \
71bf215546Sopenharmony_ci         unsigned prevFrameNumOffset; \
72bf215546Sopenharmony_ci         struct pipe_h264_sps sps[32]; \
73bf215546Sopenharmony_ci         struct pipe_h264_pps pps[256]; \
74bf215546Sopenharmony_ci         struct list_head dpb_list; \
75bf215546Sopenharmony_ci         unsigned dpb_num; \
76bf215546Sopenharmony_ci      } h264; \
77bf215546Sopenharmony_ci      struct { \
78bf215546Sopenharmony_ci         unsigned temporal_id; \
79bf215546Sopenharmony_ci         unsigned level_idc; \
80bf215546Sopenharmony_ci         unsigned pic_width_in_luma_samples; \
81bf215546Sopenharmony_ci         unsigned pic_height_in_luma_samples; \
82bf215546Sopenharmony_ci         bool IdrPicFlag; \
83bf215546Sopenharmony_ci         int slice_prev_poc; \
84bf215546Sopenharmony_ci         void *ref_pic_set_list; \
85bf215546Sopenharmony_ci         void *rps; \
86bf215546Sopenharmony_ci         struct pipe_h265_sps sps[16]; \
87bf215546Sopenharmony_ci         struct pipe_h265_pps pps[64]; \
88bf215546Sopenharmony_ci         struct list_head dpb_list; \
89bf215546Sopenharmony_ci         unsigned dpb_num; \
90bf215546Sopenharmony_ci      } h265; \
91bf215546Sopenharmony_ci      struct dec_av1 av1; \
92bf215546Sopenharmony_ci   } codec_data; \
93bf215546Sopenharmony_ci   union { \
94bf215546Sopenharmony_ci      struct pipe_picture_desc base; \
95bf215546Sopenharmony_ci      struct pipe_mpeg12_picture_desc mpeg12; \
96bf215546Sopenharmony_ci      struct pipe_h264_picture_desc h264; \
97bf215546Sopenharmony_ci      struct pipe_h265_picture_desc h265; \
98bf215546Sopenharmony_ci      struct pipe_av1_picture_desc av1; \
99bf215546Sopenharmony_ci   } picture; \
100bf215546Sopenharmony_ci   unsigned num_in_buffers; \
101bf215546Sopenharmony_ci   OMX_BUFFERHEADERTYPE *in_buffers[2]; \
102bf215546Sopenharmony_ci   const void *inputs[2]; \
103bf215546Sopenharmony_ci   unsigned sizes[2]; \
104bf215546Sopenharmony_ci   OMX_TICKS timestamps[2]; \
105bf215546Sopenharmony_ci   OMX_TICKS timestamp; \
106bf215546Sopenharmony_ci   bool first_buf_in_frame; \
107bf215546Sopenharmony_ci   bool frame_finished; \
108bf215546Sopenharmony_ci   bool frame_started; \
109bf215546Sopenharmony_ci   unsigned bytes_left; \
110bf215546Sopenharmony_ci   const void *slice; \
111bf215546Sopenharmony_ci   bool disable_tunnel; \
112bf215546Sopenharmony_ci   struct vl_compositor compositor; \
113bf215546Sopenharmony_ci   struct vl_compositor_state cstate;
114bf215546Sopenharmony_ciENDCLASS(vid_dec_PrivateType)
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci#else
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci#include <tizprc_decls.h>
119bf215546Sopenharmony_ci#include <tizport_decls.h>
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci#include "util/list.h"
122bf215546Sopenharmony_ci#include "util/u_hash_table.h"
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci#include "pipe/p_video_state.h"
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_citypedef struct h264d_prc_class h264d_prc_class_t;
127bf215546Sopenharmony_cistruct h264d_prc_class
128bf215546Sopenharmony_ci{
129bf215546Sopenharmony_ci   /* Class */
130bf215546Sopenharmony_ci   const tiz_prc_class_t _;
131bf215546Sopenharmony_ci   /* NOTE: Class methods might be added in the future */
132bf215546Sopenharmony_ci};
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_citypedef struct h264d_stream_info h264d_stream_info_t;
135bf215546Sopenharmony_cistruct h264d_stream_info
136bf215546Sopenharmony_ci{
137bf215546Sopenharmony_ci   unsigned int width;
138bf215546Sopenharmony_ci   unsigned int height;
139bf215546Sopenharmony_ci};
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_citypedef struct h264d_prc vid_dec_PrivateType;
142bf215546Sopenharmony_cistruct h264d_prc
143bf215546Sopenharmony_ci{
144bf215546Sopenharmony_ci   /* Object */
145bf215546Sopenharmony_ci   const tiz_prc_t _;
146bf215546Sopenharmony_ci   OMX_BUFFERHEADERTYPE *in_buffers[2];
147bf215546Sopenharmony_ci   OMX_BUFFERHEADERTYPE *p_inhdr_;
148bf215546Sopenharmony_ci   OMX_BUFFERHEADERTYPE *p_outhdr_;
149bf215546Sopenharmony_ci   OMX_PARAM_PORTDEFINITIONTYPE out_port_def_;
150bf215546Sopenharmony_ci   const void *inputs[2];
151bf215546Sopenharmony_ci   unsigned sizes[2];
152bf215546Sopenharmony_ci   OMX_TICKS timestamps[2];
153bf215546Sopenharmony_ci   OMX_TICKS timestamp;
154bf215546Sopenharmony_ci   bool eos_;
155bf215546Sopenharmony_ci   bool in_port_disabled_;
156bf215546Sopenharmony_ci   bool out_port_disabled_;
157bf215546Sopenharmony_ci   struct vl_screen *screen;
158bf215546Sopenharmony_ci   struct pipe_context *pipe;
159bf215546Sopenharmony_ci   struct pipe_video_codec *codec;
160bf215546Sopenharmony_ci   struct pipe_video_buffer *target;
161bf215546Sopenharmony_ci   enum pipe_video_profile profile;
162bf215546Sopenharmony_ci   struct hash_table *video_buffer_map;
163bf215546Sopenharmony_ci   union {
164bf215546Sopenharmony_ci         struct {
165bf215546Sopenharmony_ci            unsigned nal_ref_idc;
166bf215546Sopenharmony_ci            bool IdrPicFlag;
167bf215546Sopenharmony_ci            unsigned idr_pic_id;
168bf215546Sopenharmony_ci            unsigned pic_order_cnt_lsb;
169bf215546Sopenharmony_ci            unsigned pic_order_cnt_msb;
170bf215546Sopenharmony_ci            unsigned delta_pic_order_cnt_bottom;
171bf215546Sopenharmony_ci            unsigned delta_pic_order_cnt[2];
172bf215546Sopenharmony_ci            unsigned prevFrameNumOffset;
173bf215546Sopenharmony_ci            struct pipe_h264_sps sps[32];
174bf215546Sopenharmony_ci            struct pipe_h264_pps pps[256];
175bf215546Sopenharmony_ci            struct list_head dpb_list;
176bf215546Sopenharmony_ci            unsigned dpb_num;
177bf215546Sopenharmony_ci         } h264;
178bf215546Sopenharmony_ci   } codec_data;
179bf215546Sopenharmony_ci   union {
180bf215546Sopenharmony_ci      struct pipe_picture_desc base;
181bf215546Sopenharmony_ci      struct pipe_h264_picture_desc h264;
182bf215546Sopenharmony_ci   } picture;
183bf215546Sopenharmony_ci   h264d_stream_info_t stream_info;
184bf215546Sopenharmony_ci   unsigned num_in_buffers;
185bf215546Sopenharmony_ci   bool first_buf_in_frame;
186bf215546Sopenharmony_ci   bool frame_finished;
187bf215546Sopenharmony_ci   bool frame_started;
188bf215546Sopenharmony_ci   unsigned bytes_left;
189bf215546Sopenharmony_ci   const void *slice;
190bf215546Sopenharmony_ci   bool disable_tunnel;
191bf215546Sopenharmony_ci   struct vl_compositor compositor;
192bf215546Sopenharmony_ci   struct vl_compositor_state cstate;
193bf215546Sopenharmony_ci   bool use_eglimage;
194bf215546Sopenharmony_ci};
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_ci#endif
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_civoid vid_dec_NeedTarget(vid_dec_PrivateType* priv);
199bf215546Sopenharmony_civoid vid_dec_FillOutput(vid_dec_PrivateType* priv, struct pipe_video_buffer* buf,
200bf215546Sopenharmony_ci                        OMX_BUFFERHEADERTYPE* output);
201bf215546Sopenharmony_ci#endif
202