2 * Copyright ?2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
26 * Zou Nan hai <nanhai.zou@intel.com>
30 #ifndef _I965_DRV_VIDEO_H_
31 #define _I965_DRV_VIDEO_H_
34 #include <va/va_enc_h264.h>
35 #include <va/va_enc_mpeg2.h>
36 #include <va/va_enc_hevc.h>
37 #include <va/va_enc_jpeg.h>
38 #include <va/va_enc_vp8.h>
39 #include <va/va_vpp.h>
40 #include <va/va_backend.h>
41 #include <va/va_backend_vpp.h>
43 #include "i965_mutext.h"
44 #include "object_heap.h"
45 #include "intel_driver.h"
46 #include "i965_fourcc.h"
48 #define I965_MAX_PROFILES 20
49 #define I965_MAX_ENTRYPOINTS 5
50 #define I965_MAX_CONFIG_ATTRIBUTES 10
51 #define I965_MAX_IMAGE_FORMATS 10
52 #define I965_MAX_SUBPIC_FORMATS 6
53 #define I965_MAX_SUBPIC_SUM 4
54 #define I965_MAX_SURFACE_ATTRIBUTES 16
56 #define INTEL_STR_DRIVER_VENDOR "Intel"
57 #define INTEL_STR_DRIVER_NAME "i965"
59 #define I965_SURFACE_TYPE_IMAGE 0
60 #define I965_SURFACE_TYPE_SURFACE 1
62 #define I965_SURFACE_FLAG_FRAME 0x00000000
63 #define I965_SURFACE_FLAG_TOP_FIELD_FIRST 0x00000001
64 #define I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST 0x00000002
66 #define DEFAULT_BRIGHTNESS 0
67 #define DEFAULT_CONTRAST 50
69 #define DEFAULT_SATURATION 50
71 #define ENCODER_QUALITY_RANGE 2
72 #define ENCODER_DEFAULT_QUALITY 1
73 #define ENCODER_HIGH_QUALITY ENCODER_DEFAULT_QUALITY
74 #define ENCODER_LOW_QUALITY 2
78 struct object_base *base;
87 const uint32_t (*bin)[4];
90 unsigned int kernel_offset;
95 unsigned char *buffer;
103 struct object_base base;
105 VAEntrypoint entrypoint;
106 VAConfigAttrib attrib_list[I965_MAX_CONFIG_ATTRIBUTES];
109 VAGenericID wrapper_config;
112 #define NUM_SLICES 10
114 struct codec_state_base {
115 uint32_t chroma_formats;
120 struct codec_state_base base;
121 struct buffer_store *pic_param;
122 struct buffer_store **slice_params;
123 struct buffer_store *iq_matrix;
124 struct buffer_store *bit_plane;
125 struct buffer_store *huffman_table;
126 struct buffer_store **slice_datas;
127 struct buffer_store *probability_data;
128 VASurfaceID current_render_target;
129 int max_slice_params;
131 int num_slice_params;
134 struct object_surface *render_object;
135 struct object_surface *reference_objects[16]; /* Up to 2 reference surfaces are valid for MPEG-2,*/
138 #define SLICE_PACKED_DATA_INDEX_TYPE 0x80000000
139 #define SLICE_PACKED_DATA_INDEX_MASK 0x00FFFFFF
143 struct codec_state_base base;
144 struct buffer_store *seq_param;
145 struct buffer_store *pic_param;
146 struct buffer_store *pic_control;
147 struct buffer_store *iq_matrix;
148 struct buffer_store *q_matrix;
149 struct buffer_store **slice_params;
150 struct buffer_store *huffman_table;
151 int max_slice_params;
152 int num_slice_params;
155 struct buffer_store *seq_param_ext;
156 struct buffer_store *pic_param_ext;
157 struct buffer_store *packed_header_param[5];
158 struct buffer_store *packed_header_data[5];
159 struct buffer_store **slice_params_ext;
160 int max_slice_params_ext;
161 int num_slice_params_ext;
163 /* Check the user-configurable packed_header attribute.
164 * Currently it is mainly used to check whether the packed slice_header data
165 * is provided by user or the driver.
166 * TBD: It will check for the packed SPS/PPS/MISC/RAWDATA and so on.
168 unsigned int packed_header_flag;
169 /* For the packed data that needs to be inserted into video clip */
170 /* currently it is mainly to track packed raw data and packed slice_header data. */
171 struct buffer_store **packed_header_params_ext;
172 int max_packed_header_params_ext;
173 int num_packed_header_params_ext;
174 struct buffer_store **packed_header_data_ext;
175 int max_packed_header_data_ext;
176 int num_packed_header_data_ext;
178 /* the index of current vps and sps ,special for HEVC*/
179 int vps_sps_seq_index;
180 /* the index of current slice */
182 /* the array is determined by max_slice_params_ext */
184 /* This is to store the first index of packed data for one slice */
185 int *slice_rawdata_index;
186 /* This is to store the number of packed data for one slice.
187 * Both packed rawdata and slice_header data are tracked by this
188 * this variable. That is to say: When one packed slice_header is parsed,
189 * this variable will also be increased.
191 int *slice_rawdata_count;
193 /* This is to store the index of packed slice header for one slice */
194 int *slice_header_index;
196 int last_packed_header_type;
198 struct buffer_store *misc_param[16];
200 VASurfaceID current_render_target;
201 struct object_surface *input_yuv_object;
202 struct object_surface *reconstructed_object;
203 struct object_buffer *coded_buf_object;
204 struct object_surface *reference_objects[16]; /* Up to 2 reference surfaces are valid for MPEG-2,*/
209 struct codec_state_base base;
210 struct buffer_store *pipeline_param;
212 VASurfaceID current_render_target;
221 struct codec_state_base base;
222 struct decode_state decode;
223 struct encode_state encode;
224 struct proc_state proc;
229 VAStatus (*run)(VADriverContextP ctx,
231 union codec_state *codec_state,
232 struct hw_context *hw_context);
233 void (*destroy)(void *);
234 struct intel_batchbuffer *batch;
237 struct object_context
239 struct object_base base;
240 VAContextID context_id;
241 struct object_config *obj_config;
242 VASurfaceID *render_targets; //input->encode, output->decode
243 int num_render_targets;
248 union codec_state codec_state;
249 struct hw_context *hw_context;
251 VAGenericID wrapper_context;
254 #define SURFACE_REFERENCED (1 << 0)
255 #define SURFACE_DERIVED (1 << 2)
256 #define SURFACE_ALL_MASK ((SURFACE_REFERENCED) | \
259 struct object_surface
261 struct object_base base;
262 VASurfaceStatus status;
263 VASubpictureID subpic[I965_MAX_SUBPIC_SUM];
264 struct object_subpic *obj_subpic[I965_MAX_SUBPIC_SUM];
265 unsigned int subpic_render_idx;
267 int width; /* the pitch of plane 0 in bytes in horizontal direction */
268 int height; /* the pitch of plane 0 in bytes in vertical direction */
270 int orig_width; /* the width of plane 0 in pixels */
271 int orig_height; /* the height of plane 0 in pixels */
275 unsigned int expected_format;
276 VAImageID locked_image_id;
277 VAImageID derived_image_id;
278 void (*free_private_data)(void **data);
280 unsigned int subsampling;
288 /* user specified attributes see: VASurfaceAttribExternalBuffers/VA_SURFACE_ATTRIB_MEM_TYPE_VA */
289 uint32_t user_disable_tiling : 1;
290 uint32_t user_h_stride_set : 1;
291 uint32_t user_v_stride_set : 1;
293 VAGenericID wrapper_surface;
295 int exported_primefd;
300 struct object_base base;
301 struct buffer_store *buffer_store;
302 int max_num_elements;
308 unsigned int export_refcount;
309 VABufferInfo export_state;
311 VAGenericID wrapper_buffer;
316 struct object_base base;
319 unsigned int *palette;
320 VASurfaceID derived_surface;
325 struct object_base base;
327 struct object_image *obj_image;
328 VARectangle src_rect;
329 VARectangle dst_rect;
339 #define I965_RING_NULL 0
340 #define I965_RING_BSD 1
341 #define I965_RING_BLT 2
342 #define I965_RING_VEBOX 3
346 VAProcFilterType type;
352 struct hw_context *(*dec_hw_context_init)(VADriverContextP, struct object_config *);
353 struct hw_context *(*enc_hw_context_init)(VADriverContextP, struct object_config *);
354 struct hw_context *(*proc_hw_context_init)(VADriverContextP, struct object_config *);
355 bool (*render_init)(VADriverContextP);
356 void (*post_processing_context_init)(VADriverContextP, void *, struct intel_batchbuffer *);
357 void (*preinit_hw_codec)(VADriverContextP, struct hw_codec_info *);
361 int min_linear_wpitch;
362 int min_linear_hpitch;
364 unsigned int h264_mvc_dec_profiles;
365 unsigned int vp9_dec_profiles;
367 unsigned int h264_dec_chroma_formats;
368 unsigned int jpeg_dec_chroma_formats;
369 unsigned int jpeg_enc_chroma_formats;
370 unsigned int hevc_dec_chroma_formats;
371 unsigned int vp9_dec_chroma_formats;
373 unsigned int has_mpeg2_decoding:1;
374 unsigned int has_mpeg2_encoding:1;
375 unsigned int has_h264_decoding:1;
376 unsigned int has_h264_encoding:1;
377 unsigned int has_vc1_decoding:1;
378 unsigned int has_vc1_encoding:1;
379 unsigned int has_jpeg_decoding:1;
380 unsigned int has_jpeg_encoding:1;
381 unsigned int has_vpp:1;
382 unsigned int has_accelerated_getimage:1;
383 unsigned int has_accelerated_putimage:1;
384 unsigned int has_tiled_surface:1;
385 unsigned int has_di_motion_adptive:1;
386 unsigned int has_di_motion_compensated:1;
387 unsigned int has_vp8_decoding:1;
388 unsigned int has_vp8_encoding:1;
389 unsigned int has_h264_mvc_encoding:1;
390 unsigned int has_hevc_decoding:1;
391 unsigned int has_hevc_encoding:1;
392 unsigned int has_hevc10_decoding:1;
393 unsigned int has_vp9_decoding:1;
394 unsigned int has_vpp_p010:1;
396 unsigned int num_filters;
397 struct i965_filter filters[VAProcFilterCount];
401 #include "i965_render.h"
403 struct i965_driver_data
405 struct intel_driver_data intel;
406 struct object_heap config_heap;
407 struct object_heap context_heap;
408 struct object_heap surface_heap;
409 struct object_heap buffer_heap;
410 struct object_heap image_heap;
411 struct object_heap subpic_heap;
412 struct hw_codec_info *codec_info;
414 _I965Mutex render_mutex;
416 struct intel_batchbuffer *batch;
417 struct intel_batchbuffer *pp_batch;
418 struct i965_render_state render_state;
422 VADisplayAttribute *display_attributes;
423 unsigned int num_display_attributes;
424 VADisplayAttribute *rotation_attrib;
425 VADisplayAttribute *brightness_attrib;
426 VADisplayAttribute *contrast_attrib;
427 VADisplayAttribute *hue_attrib;
428 VADisplayAttribute *saturation_attrib;
429 VAContextID current_context_id;
431 /* VA/DRI (X11) specific data */
432 struct va_dri_output *dri_output;
434 /* VA/Wayland specific data */
435 struct va_wl_output *wl_output;
437 VADriverContextP wrapper_pdrvctx;
440 #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
441 #define NEW_CONTEXT_ID() object_heap_allocate(&i965->context_heap);
442 #define NEW_SURFACE_ID() object_heap_allocate(&i965->surface_heap);
443 #define NEW_BUFFER_ID() object_heap_allocate(&i965->buffer_heap);
444 #define NEW_IMAGE_ID() object_heap_allocate(&i965->image_heap);
445 #define NEW_SUBPIC_ID() object_heap_allocate(&i965->subpic_heap);
447 #define CONFIG(id) ((struct object_config *)object_heap_lookup(&i965->config_heap, id))
448 #define CONTEXT(id) ((struct object_context *)object_heap_lookup(&i965->context_heap, id))
449 #define SURFACE(id) ((struct object_surface *)object_heap_lookup(&i965->surface_heap, id))
450 #define BUFFER(id) ((struct object_buffer *)object_heap_lookup(&i965->buffer_heap, id))
451 #define IMAGE(id) ((struct object_image *)object_heap_lookup(&i965->image_heap, id))
452 #define SUBPIC(id) ((struct object_subpic *)object_heap_lookup(&i965->subpic_heap, id))
454 #define FOURCC_IA44 0x34344149
455 #define FOURCC_AI44 0x34344941
457 #define STRIDE(w) (((w) + 0xf) & ~0xf)
458 #define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
460 static INLINE struct i965_driver_data *
461 i965_driver_data(VADriverContextP ctx)
463 return (struct i965_driver_data *)(ctx->pDriverData);
467 i965_check_alloc_surface_bo(VADriverContextP ctx,
468 struct object_surface *obj_surface,
471 unsigned int subsampling);
474 va_enc_packed_type_to_idx(int packed_type);
476 /* reserve 2 byte for internal using */
478 #define CODEC_MPEG2 1
479 #define CODEC_H264_MVC 2
484 #define H264_DELIMITER0 0x00
485 #define H264_DELIMITER1 0x00
486 #define H264_DELIMITER2 0x00
487 #define H264_DELIMITER3 0x00
488 #define H264_DELIMITER4 0x00
490 #define MPEG2_DELIMITER0 0x00
491 #define MPEG2_DELIMITER1 0x00
492 #define MPEG2_DELIMITER2 0x00
493 #define MPEG2_DELIMITER3 0x00
494 #define MPEG2_DELIMITER4 0xb0
496 #define HEVC_DELIMITER0 0x00
497 #define HEVC_DELIMITER1 0x00
498 #define HEVC_DELIMITER2 0x00
499 #define HEVC_DELIMITER3 0x00
500 #define HEVC_DELIMITER4 0x00
502 struct i965_coded_buffer_segment
504 VACodedBufferSegment base;
505 unsigned char mapped;
509 #define I965_CODEDBUFFER_HEADER_SIZE ALIGN(sizeof(struct i965_coded_buffer_segment), 0x1000)
511 extern VAStatus i965_MapBuffer(VADriverContextP ctx,
512 VABufferID buf_id, /* in */
513 void **pbuf); /* out */
515 extern VAStatus i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id);
517 extern VAStatus i965_DestroySurfaces(VADriverContextP ctx,
518 VASurfaceID *surface_list,
521 extern VAStatus i965_CreateSurfaces(VADriverContextP ctx,
526 VASurfaceID *surfaces);
528 #define I965_SURFACE_MEM_NATIVE 0
529 #define I965_SURFACE_MEM_GEM_FLINK 1
530 #define I965_SURFACE_MEM_DRM_PRIME 2
533 i965_destroy_surface_storage(struct object_surface *obj_surface);
535 #endif /* _I965_DRV_VIDEO_H_ */