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 32
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
76 #define I965_MAX_NUM_ROI_REGIONS 8
78 #define ENCODER_LP_QUALITY_RANGE 8
82 struct object_base *base;
91 const uint32_t (*bin)[4];
94 unsigned int kernel_offset;
99 unsigned char *buffer;
107 struct object_base base;
109 VAEntrypoint entrypoint;
110 VAConfigAttrib attrib_list[I965_MAX_CONFIG_ATTRIBUTES];
113 VAGenericID wrapper_config;
116 #define NUM_SLICES 10
118 struct codec_state_base {
119 uint32_t chroma_formats;
124 struct codec_state_base base;
125 struct buffer_store *pic_param;
126 struct buffer_store **slice_params;
127 struct buffer_store *iq_matrix;
128 struct buffer_store *bit_plane;
129 struct buffer_store *huffman_table;
130 struct buffer_store **slice_datas;
131 struct buffer_store *probability_data;
132 VASurfaceID current_render_target;
133 int max_slice_params;
135 int num_slice_params;
138 struct object_surface *render_object;
139 struct object_surface *reference_objects[16]; /* Up to 2 reference surfaces are valid for MPEG-2,*/
142 #define SLICE_PACKED_DATA_INDEX_TYPE 0x80000000
143 #define SLICE_PACKED_DATA_INDEX_MASK 0x00FFFFFF
147 struct codec_state_base base;
148 struct buffer_store *iq_matrix;
149 struct buffer_store *q_matrix;
150 struct buffer_store *huffman_table;
153 struct buffer_store *seq_param_ext;
154 struct buffer_store *pic_param_ext;
155 struct buffer_store *packed_header_param[5];
156 struct buffer_store *packed_header_data[5];
157 struct buffer_store **slice_params_ext;
158 struct buffer_store *encmb_map;
159 int max_slice_params_ext;
160 int num_slice_params_ext;
162 /* Check the user-configurable packed_header attribute.
163 * Currently it is mainly used to check whether the packed slice_header data
164 * is provided by user or the driver.
165 * TBD: It will check for the packed SPS/PPS/MISC/RAWDATA and so on.
167 unsigned int packed_header_flag;
168 /* For the packed data that needs to be inserted into video clip */
169 /* currently it is mainly to track packed raw data and packed slice_header data. */
170 struct buffer_store **packed_header_params_ext;
171 int max_packed_header_params_ext;
172 int num_packed_header_params_ext;
173 struct buffer_store **packed_header_data_ext;
174 int max_packed_header_data_ext;
175 int num_packed_header_data_ext;
177 /* the index of current vps and sps ,special for HEVC*/
178 int vps_sps_seq_index;
179 /* the index of current slice */
181 /* the array is determined by max_slice_params_ext */
183 /* This is to store the first index of packed data for one slice */
184 int *slice_rawdata_index;
185 /* This is to store the number of packed data for one slice.
186 * Both packed rawdata and slice_header data are tracked by this
187 * this variable. That is to say: When one packed slice_header is parsed,
188 * this variable will also be increased.
190 int *slice_rawdata_count;
192 /* This is to store the index of packed slice header for one slice */
193 int *slice_header_index;
195 int last_packed_header_type;
197 struct buffer_store *misc_param[16];
199 VASurfaceID current_render_target;
200 struct object_surface *input_yuv_object;
201 struct object_surface *reconstructed_object;
202 struct object_buffer *coded_buf_object;
203 struct object_surface *reference_objects[16]; /* Up to 2 reference surfaces are valid for MPEG-2,*/
208 struct codec_state_base base;
209 struct buffer_store *pipeline_param;
211 VASurfaceID current_render_target;
220 struct codec_state_base base;
221 struct decode_state decode;
222 struct encode_state encode;
223 struct proc_state proc;
228 VAStatus (*run)(VADriverContextP ctx,
230 union codec_state *codec_state,
231 struct hw_context *hw_context);
232 void (*destroy)(void *);
233 VAStatus (*get_status)(VADriverContextP ctx,
234 struct hw_context *hw_context,
236 struct intel_batchbuffer *batch;
239 struct object_context
241 struct object_base base;
242 VAContextID context_id;
243 struct object_config *obj_config;
244 VASurfaceID *render_targets; //input->encode, output->decode
245 int num_render_targets;
250 union codec_state codec_state;
251 struct hw_context *hw_context;
253 VAGenericID wrapper_context;
256 #define SURFACE_REFERENCED (1 << 0)
257 #define SURFACE_DERIVED (1 << 2)
258 #define SURFACE_ALL_MASK ((SURFACE_REFERENCED) | \
261 struct object_surface
263 struct object_base base;
264 VASurfaceStatus status;
265 VASubpictureID subpic[I965_MAX_SUBPIC_SUM];
266 struct object_subpic *obj_subpic[I965_MAX_SUBPIC_SUM];
267 unsigned int subpic_render_idx;
269 int width; /* the pitch of plane 0 in bytes in horizontal direction */
270 int height; /* the pitch of plane 0 in bytes in vertical direction */
272 int orig_width; /* the width of plane 0 in pixels */
273 int orig_height; /* the height of plane 0 in pixels */
277 unsigned int expected_format;
278 VAImageID locked_image_id;
279 VAImageID derived_image_id;
280 void (*free_private_data)(void **data);
282 unsigned int subsampling;
290 /* user specified attributes see: VASurfaceAttribExternalBuffers/VA_SURFACE_ATTRIB_MEM_TYPE_VA */
291 uint32_t user_disable_tiling : 1;
292 uint32_t user_h_stride_set : 1;
293 uint32_t user_v_stride_set : 1;
294 /* we need clear right and bottom border for NV12.
295 * to avoid encode run to run issue*/
296 uint32_t border_cleared : 1;
298 VAGenericID wrapper_surface;
300 int exported_primefd;
305 struct object_base base;
306 struct buffer_store *buffer_store;
307 int max_num_elements;
313 unsigned int export_refcount;
314 VABufferInfo export_state;
316 VAGenericID wrapper_buffer;
317 VAContextID context_id;
322 struct object_base base;
325 unsigned int *palette;
326 VASurfaceID derived_surface;
331 struct object_base base;
333 struct object_image *obj_image;
334 VARectangle src_rect;
335 VARectangle dst_rect;
345 #define I965_RING_NULL 0
346 #define I965_RING_BSD 1
347 #define I965_RING_BLT 2
348 #define I965_RING_VEBOX 3
352 VAProcFilterType type;
356 struct i965_driver_data;
360 struct hw_context *(*dec_hw_context_init)(VADriverContextP, struct object_config *);
361 struct hw_context *(*enc_hw_context_init)(VADriverContextP, struct object_config *);
362 struct hw_context *(*proc_hw_context_init)(VADriverContextP, struct object_config *);
363 bool (*render_init)(VADriverContextP);
364 void (*post_processing_context_init)(VADriverContextP, void *, struct intel_batchbuffer *);
365 void (*preinit_hw_codec)(VADriverContextP, struct hw_codec_info *);
368 * Allows HW info to support per-codec max resolution. If this functor is
369 * not initialized, then @max_width and @max_height will be used as the
370 * default maximum resolution for all codecs on this HW info.
372 void (*max_resolution)(struct i965_driver_data *, struct object_config *, int *, int *);
376 int min_linear_wpitch;
377 int min_linear_hpitch;
379 unsigned int h264_mvc_dec_profiles;
380 unsigned int vp9_dec_profiles;
382 unsigned int h264_dec_chroma_formats;
383 unsigned int jpeg_dec_chroma_formats;
384 unsigned int jpeg_enc_chroma_formats;
385 unsigned int hevc_dec_chroma_formats;
386 unsigned int vp9_dec_chroma_formats;
388 unsigned int has_mpeg2_decoding:1;
389 unsigned int has_mpeg2_encoding:1;
390 unsigned int has_h264_decoding:1;
391 unsigned int has_h264_encoding:1;
392 unsigned int has_vc1_decoding:1;
393 unsigned int has_vc1_encoding:1;
394 unsigned int has_jpeg_decoding:1;
395 unsigned int has_jpeg_encoding:1;
396 unsigned int has_vpp:1;
397 unsigned int has_accelerated_getimage:1;
398 unsigned int has_accelerated_putimage:1;
399 unsigned int has_tiled_surface:1;
400 unsigned int has_di_motion_adptive:1;
401 unsigned int has_di_motion_compensated:1;
402 unsigned int has_vp8_decoding:1;
403 unsigned int has_vp8_encoding:1;
404 unsigned int has_h264_mvc_encoding:1;
405 unsigned int has_hevc_decoding:1;
406 unsigned int has_hevc_encoding:1;
407 unsigned int has_hevc10_encoding:1;
408 unsigned int has_hevc10_decoding:1;
409 unsigned int has_vp9_decoding:1;
410 unsigned int has_vpp_p010:1;
411 unsigned int has_lp_h264_encoding:1;
412 unsigned int has_vp9_encoding:1;
414 unsigned int lp_h264_brc_mode;
416 unsigned int num_filters;
417 struct i965_filter filters[VAProcFilterCount];
421 #include "i965_render.h"
423 struct i965_driver_data
425 struct intel_driver_data intel;
426 struct object_heap config_heap;
427 struct object_heap context_heap;
428 struct object_heap surface_heap;
429 struct object_heap buffer_heap;
430 struct object_heap image_heap;
431 struct object_heap subpic_heap;
432 struct hw_codec_info *codec_info;
434 _I965Mutex render_mutex;
436 struct intel_batchbuffer *batch;
437 struct intel_batchbuffer *pp_batch;
438 struct i965_render_state render_state;
442 VADisplayAttribute *display_attributes;
443 unsigned int num_display_attributes;
444 VADisplayAttribute *rotation_attrib;
445 VADisplayAttribute *brightness_attrib;
446 VADisplayAttribute *contrast_attrib;
447 VADisplayAttribute *hue_attrib;
448 VADisplayAttribute *saturation_attrib;
449 VAContextID current_context_id;
451 /* VA/DRI (X11) specific data */
452 struct va_dri_output *dri_output;
454 /* VA/Wayland specific data */
455 struct va_wl_output *wl_output;
457 VADriverContextP wrapper_pdrvctx;
460 #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
461 #define NEW_CONTEXT_ID() object_heap_allocate(&i965->context_heap);
462 #define NEW_SURFACE_ID() object_heap_allocate(&i965->surface_heap);
463 #define NEW_BUFFER_ID() object_heap_allocate(&i965->buffer_heap);
464 #define NEW_IMAGE_ID() object_heap_allocate(&i965->image_heap);
465 #define NEW_SUBPIC_ID() object_heap_allocate(&i965->subpic_heap);
467 #define CONFIG(id) ((struct object_config *)object_heap_lookup(&i965->config_heap, id))
468 #define CONTEXT(id) ((struct object_context *)object_heap_lookup(&i965->context_heap, id))
469 #define SURFACE(id) ((struct object_surface *)object_heap_lookup(&i965->surface_heap, id))
470 #define BUFFER(id) ((struct object_buffer *)object_heap_lookup(&i965->buffer_heap, id))
471 #define IMAGE(id) ((struct object_image *)object_heap_lookup(&i965->image_heap, id))
472 #define SUBPIC(id) ((struct object_subpic *)object_heap_lookup(&i965->subpic_heap, id))
474 #define FOURCC_IA44 0x34344149
475 #define FOURCC_AI44 0x34344941
477 #define STRIDE(w) (((w) + 0xf) & ~0xf)
478 #define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
480 static INLINE struct i965_driver_data *
481 i965_driver_data(VADriverContextP ctx)
483 return (struct i965_driver_data *)(ctx->pDriverData);
487 i965_check_alloc_surface_bo(VADriverContextP ctx,
488 struct object_surface *obj_surface,
491 unsigned int subsampling);
494 va_enc_packed_type_to_idx(int packed_type);
496 /* reserve 2 byte for internal using */
498 #define CODEC_MPEG2 1
499 #define CODEC_H264_MVC 2
505 #define H264_DELIMITER0 0x00
506 #define H264_DELIMITER1 0x00
507 #define H264_DELIMITER2 0x00
508 #define H264_DELIMITER3 0x00
509 #define H264_DELIMITER4 0x00
511 #define MPEG2_DELIMITER0 0x00
512 #define MPEG2_DELIMITER1 0x00
513 #define MPEG2_DELIMITER2 0x00
514 #define MPEG2_DELIMITER3 0x00
515 #define MPEG2_DELIMITER4 0xb0
517 #define HEVC_DELIMITER0 0x00
518 #define HEVC_DELIMITER1 0x00
519 #define HEVC_DELIMITER2 0x00
520 #define HEVC_DELIMITER3 0x00
521 #define HEVC_DELIMITER4 0x00
523 struct i965_coded_buffer_segment
526 VACodedBufferSegment base;
527 unsigned char pad0[64]; /* change the size if sizeof(VACodedBufferSegment) > 64 */
532 unsigned int status_support;
535 unsigned int codec_private_data[512]; /* Store codec private data, must be 16-bytes aligned */
538 #define I965_CODEDBUFFER_HEADER_SIZE ALIGN(sizeof(struct i965_coded_buffer_segment), 0x1000)
540 extern VAStatus i965_MapBuffer(VADriverContextP ctx,
541 VABufferID buf_id, /* in */
542 void **pbuf); /* out */
544 extern VAStatus i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id);
546 extern VAStatus i965_DestroySurfaces(VADriverContextP ctx,
547 VASurfaceID *surface_list,
550 extern VAStatus i965_CreateSurfaces(VADriverContextP ctx,
555 VASurfaceID *surfaces);
556 extern VAStatus i965_SyncSurface(VADriverContextP ctx,
557 VASurfaceID render_target);
559 #define I965_SURFACE_MEM_NATIVE 0
560 #define I965_SURFACE_MEM_GEM_FLINK 1
561 #define I965_SURFACE_MEM_DRM_PRIME 2
564 i965_destroy_surface_storage(struct object_surface *obj_surface);
566 #endif /* _I965_DRV_VIDEO_H_ */