st/omx/tizonia: Add H.264 encoder
[mesa.git] / src / gallium / state_trackers / omx / vid_enc_common.h
1 /**************************************************************************
2 *
3 * Copyright 2013 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef VID_ENC_COMMON_H
29 #define VID_ENC_COMMON_H
30
31 #include "util/list.h"
32 #include "util/u_memory.h"
33
34 #include "vl/vl_defines.h"
35 #include "vl/vl_compositor.h"
36 #include "vl/vl_winsys.h"
37
38 #include <OMX_Core.h>
39
40 #define OMX_VID_ENC_BITRATE_MIN 64000
41 #define OMX_VID_ENC_BITRATE_MEDIAN 2000000
42 #define OMX_VID_ENC_BITRATE_MAX 240000000
43 #define OMX_VID_ENC_CONTROL_FRAME_RATE_DEN_DEFAULT 1001
44 #define OMX_VID_ENC_QUANT_I_FRAMES_DEFAULT 0x1c
45 #define OMX_VID_ENC_QUANT_P_FRAMES_DEFAULT 0x1c
46 #define OMX_VID_ENC_QUANT_B_FRAMES_DEFAULT 0x1c
47 #define OMX_VID_ENC_SCALING_WIDTH_DEFAULT 0xffffffff
48 #define OMX_VID_ENC_SCALING_HEIGHT_DEFAULT 0xffffffff
49 #define OMX_VID_ENC_IDR_PERIOD_DEFAULT 1000
50 #define OMX_VID_ENC_P_PERIOD_DEFAULT 3
51
52 #define OMX_VID_ENC_NUM_SCALING_BUFFERS 4
53
54 struct encode_task {
55 struct list_head list;
56
57 struct pipe_video_buffer *buf;
58 unsigned pic_order_cnt;
59 struct pipe_resource *bitstream;
60 void *feedback;
61 };
62
63 struct input_buf_private {
64 struct list_head tasks;
65
66 struct pipe_resource *resource;
67 struct pipe_transfer *transfer;
68 };
69
70 struct output_buf_private {
71 struct pipe_resource *bitstream;
72 struct pipe_transfer *transfer;
73 };
74
75 #if ENABLE_ST_OMX_BELLAGIO
76
77 #include <bellagio/omx_base_filter.h>
78
79 DERIVEDCLASS(vid_enc_PrivateType, omx_base_filter_PrivateType)
80 #define vid_enc_PrivateType_FIELDS omx_base_filter_PrivateType_FIELDS \
81 struct vl_screen *screen; \
82 struct pipe_context *s_pipe; \
83 struct pipe_context *t_pipe; \
84 struct pipe_video_codec *codec; \
85 struct list_head free_tasks; \
86 struct list_head used_tasks; \
87 struct list_head b_frames; \
88 struct list_head stacked_tasks; \
89 OMX_U32 frame_rate; \
90 OMX_U32 frame_num; \
91 OMX_U32 pic_order_cnt; \
92 OMX_U32 ref_idx_l0, ref_idx_l1; \
93 OMX_BOOL restricted_b_frames; \
94 OMX_VIDEO_PARAM_BITRATETYPE bitrate; \
95 OMX_VIDEO_PARAM_QUANTIZATIONTYPE quant; \
96 OMX_VIDEO_PARAM_PROFILELEVELTYPE profile_level; \
97 OMX_CONFIG_INTRAREFRESHVOPTYPE force_pic_type; \
98 struct vl_compositor compositor; \
99 struct vl_compositor_state cstate; \
100 struct pipe_video_buffer *scale_buffer[OMX_VID_ENC_NUM_SCALING_BUFFERS]; \
101 OMX_CONFIG_SCALEFACTORTYPE scale; \
102 OMX_U32 current_scale_buffer; \
103 OMX_U32 stacked_frames_num;
104 ENDCLASS(vid_enc_PrivateType)
105
106 #else
107
108 #include <tizprc_decls.h>
109 #include <tizport_decls.h>
110
111 typedef struct h264e_prc_class h264e_prc_class_t;
112 struct h264e_prc_class
113 {
114 /* Class */
115 const tiz_prc_class_t _;
116 /* NOTE: Class methods might be added in the future */
117 };
118
119 typedef struct h264e_prc vid_enc_PrivateType;
120 struct h264e_prc
121 {
122 /* Object */
123 const tiz_prc_t _;
124 OMX_BUFFERHEADERTYPE *p_inhdr_;
125 OMX_BUFFERHEADERTYPE *p_outhdr_;
126 OMX_PARAM_PORTDEFINITIONTYPE in_port_def_;
127 OMX_PARAM_PORTDEFINITIONTYPE out_port_def_;
128 struct vl_screen *screen;
129 struct pipe_context *s_pipe;
130 struct pipe_context *t_pipe;
131 struct pipe_video_codec *codec;
132 struct list_head free_tasks;
133 struct list_head used_tasks;
134 struct list_head b_frames;
135 struct list_head stacked_tasks;
136 OMX_U32 frame_rate;
137 OMX_U32 frame_num;
138 OMX_U32 pic_order_cnt;
139 OMX_U32 ref_idx_l0, ref_idx_l1;
140 OMX_BOOL restricted_b_frames;
141 OMX_VIDEO_PARAM_BITRATETYPE bitrate;
142 OMX_VIDEO_PARAM_QUANTIZATIONTYPE quant;
143 OMX_VIDEO_PARAM_PROFILELEVELTYPE profile_level;
144 OMX_CONFIG_INTRAREFRESHVOPTYPE force_pic_type;
145 struct vl_compositor compositor;
146 struct vl_compositor_state cstate;
147 struct pipe_video_buffer *scale_buffer[OMX_VID_ENC_NUM_SCALING_BUFFERS];
148 OMX_CONFIG_SCALEFACTORTYPE scale;
149 OMX_U32 current_scale_buffer;
150 OMX_U32 stacked_frames_num;
151 bool eos_;
152 bool in_port_disabled_;
153 bool out_port_disabled_;
154 };
155 #endif
156
157 void enc_ReleaseTasks(struct list_head *head);
158 void enc_MoveTasks(struct list_head *from, struct list_head *to);
159 enum pipe_video_profile enc_TranslateOMXProfileToPipe(unsigned omx_profile);
160 unsigned enc_TranslateOMXLevelToPipe(unsigned omx_level);
161 void vid_enc_BufferEncoded_common(vid_enc_PrivateType * priv, OMX_BUFFERHEADERTYPE* input,
162 OMX_BUFFERHEADERTYPE* output);
163 struct encode_task *enc_NeedTask_common(vid_enc_PrivateType * priv,
164 OMX_VIDEO_PORTDEFINITIONTYPE *def);
165 void enc_ScaleInput_common(vid_enc_PrivateType * priv,
166 OMX_VIDEO_PORTDEFINITIONTYPE *def,
167 struct pipe_video_buffer **vbuf, unsigned *size);
168 void enc_ControlPicture_common(vid_enc_PrivateType * priv,
169 struct pipe_h264_enc_picture_desc *picture);
170 OMX_ERRORTYPE enc_LoadImage_common(vid_enc_PrivateType * priv, OMX_VIDEO_PORTDEFINITIONTYPE *def,
171 OMX_BUFFERHEADERTYPE *buf,
172 struct pipe_video_buffer *vbuf);
173 #endif