1 /* 2 * Copyright (c) 2011 Intel Corporation. All Rights Reserved. 3 * 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: 11 * 12 * The above copyright notice and this permission notice (including the 13 * next paragraph) shall be included in all copies or substantial portions 14 * of the Software. 15 * 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. 23 * 24 * Authors: 25 * Waldo Bastian <waldo.bastian (at) intel.com> 26 * 27 */ 28 29 #ifndef _PSB_DRV_VIDEO_H_ 30 #define _PSB_DRV_VIDEO_H_ 31 32 #include <pthread.h> /* POSIX threads headers */ 33 34 #include <va/va_backend.h> 35 #include <va/va.h> 36 #include <va/va_tpi.h> 37 38 #include <va/va_vpp.h> 39 40 #include "object_heap.h" 41 #include "psb_def.h" 42 //#include "psb_drv_debug.h" 43 #include "xf86drm.h" 44 #ifdef ANDROID 45 #ifdef BAYTRAIL 46 #include <linux/vxd_drm.h> 47 #else 48 #include <linux/psb_drm.h> 49 #endif 50 #endif 51 #include "psb_overlay.h" 52 #include "psb_texture.h" 53 #include <stdint.h> 54 #ifndef ANDROID 55 #include <psb_drm.h> 56 #include <X11/Xlibint.h> 57 #include <X11/X.h> 58 #include <X11/extensions/Xv.h> 59 #include <X11/extensions/Xvlib.h> 60 #include <X11/Xlib.h> 61 #else 62 #define XID unsigned int 63 #define INT16 unsigned int 64 #include <cutils/log.h> 65 #undef LOG_TAG 66 #define LOG_TAG "pvr_drv_video" 67 #endif 68 #include "hwdefs/dxva_fw_flags.h" 69 #include <wsbm/wsbm_pool.h> 70 71 #ifdef __GNUC__ 72 # define __maybe_unused __attribute__((__unused__)) 73 #else 74 # define __maybe_unused 75 #endif 76 77 #ifndef min 78 #define min(a, b) ((a) < (b)) ? (a) : (b) 79 #endif 80 81 #ifndef max 82 #define max(a, b) ((a) > (b)) ? (a) : (b) 83 #endif 84 85 //#define _TOPAZHP_PDUMP_ 86 #define TOPAZHP_PIPE_NUM 2 87 88 #define _TNG_RELOC_ 89 //#define _TNG_FRAMES_ 90 #define FORCED_REFERENCE 1 91 #define LTREFHEADER 1 92 //#define _TP_DEBUG_MMU_ 93 //#define _TOPAZHP_REC_ 94 95 /* 96 * WORKAROUND_DMA_OFF_BY_ONE: LLDMA requests may access one additional byte which can cause 97 * a MMU fault if the next byte after the buffer end is on a different page that isn't mapped. 98 */ 99 #define WORKAROUND_DMA_OFF_BY_ONE 100 #define FOURCC_XVVA (('A' << 24) + ('V' << 16) + ('V' << 8) + 'X') 101 102 #define PSB_MAX_PROFILES 32 103 #define PSB_MAX_ENTRYPOINTS 32 104 #define PSB_MAX_CONFIG_ATTRIBUTES VAConfigAttribTypeMax 105 106 /* VABufferTypeMax is large(1000+) because there is big blank space between common libva buffer 107 * type and Intel specific buffer types(for GEN usage only). If use VABufferTypeMax as 108 * PSB_MAX_BUFFERTYPES to define the size of buffer type related arrays in context object, 109 * we will waste about 16K memory. Currently, the max value of buffer type used in psb_video is 110 * VAParseSliceHeaderGroupBufferType(44). 111 */ 112 #define PSB_MAX_BUFFERTYPES 64 113 114 /* Max # of command submission buffers */ 115 #define PSB_MAX_CMDBUFS 10 116 #define LNC_MAX_CMDBUFS_ENCODE 4 117 #define PNW_MAX_CMDBUFS_ENCODE 4 118 #define TNG_MAX_CMDBUFS_ENCODE 4 119 #define VSP_MAX_CMDBUFS 10 120 121 #define PSB_SURFACE_DISPLAYING_F (0x1U<<0) 122 #define PSB_SURFACE_IS_FLAG_SET(flags, mask) (((flags)& PSB_SURFACE_DISPLAYING_F) != 0) 123 124 #define PSB_CTX_TILING_MASK 0x00FF0000 125 126 /*xrandr dirty flag*/ 127 #define PSB_NEW_ROTATION 1 128 #define PSB_NEW_EXTVIDEO 2 129 130 #define PSB_NEW_VA_ROTATION 1 << 0 131 #define PSB_NEW_WM_ROTATION 1 << 1 132 133 #define MAX_SLICES_PER_PICTURE 72 134 #define MAX_MB_ERRORS 72 135 136 /* Some funtions aren't used but we'd like to keep them as reference code in future */ 137 #define PSB_MFLD_DUMMY_CODE 0 138 139 /* 140 * ITU-R BT.601 and BT.709 transfer matrices from VA 2.0 141 * Video Color Field definitions Design Spec(Version 0.03). 142 * [R', G', B'] values are in the range [0, 1], Y' is in the range [0,1] 143 * and [Pb, Pr] components are in the range [-0.5, 0.5]. 144 */ 145 static float s601[9] = { 146 1, -0.000001, 1.402, 147 1, -0.344136, -0.714136, 148 1, 1.772, 0 149 }; 150 151 static float s709[9] = { 152 1, 0, 1.5748, 153 1, -0.187324, -0.468124, 154 1, 1.8556, 0 155 }; 156 157 typedef struct object_config_s *object_config_p; 158 typedef struct object_context_s *object_context_p; 159 typedef struct object_surface_s *object_surface_p; 160 typedef struct object_buffer_s *object_buffer_p; 161 typedef struct object_image_s *object_image_p; 162 typedef struct object_subpic_s *object_subpic_p; 163 typedef struct format_vtable_s *format_vtable_p; 164 typedef struct psb_driver_data_s *psb_driver_data_p; 165 166 typedef struct psb_surface_share_info_s psb_surface_share_info_t, *psb_surface_share_info_p; 167 /* post-processing data structure */ 168 enum psb_output_method_t { 169 PSB_PUTSURFACE_NONE = 0, 170 PSB_PUTSURFACE_X11,/* use x11 method */ 171 PSB_PUTSURFACE_TEXTURE,/* texture xvideo */ 172 PSB_PUTSURFACE_OVERLAY,/* overlay xvideo */ 173 PSB_PUTSURFACE_COVERLAY,/* client overlay */ 174 PSB_PUTSURFACE_CTEXTURE,/* client textureblit */ 175 PSB_PUTSURFACE_TEXSTREAMING,/* texsteaming */ 176 PSB_PUTSURFACE_FORCE_TEXTURE,/* force texture xvideo */ 177 PSB_PUTSURFACE_FORCE_OVERLAY,/* force overlay xvideo */ 178 PSB_PUTSURFACE_FORCE_CTEXTURE,/* force client textureblit */ 179 PSB_PUTSURFACE_FORCE_COVERLAY,/* force client overlay */ 180 PSB_PUTSURFACE_FORCE_TEXSTREAMING,/* force texstreaming */ 181 }; 182 183 typedef struct psb_decode_info { 184 uint32_t num_surface; 185 uint32_t surface_id; 186 } psb_decode_info_t; 187 typedef struct msvdx_decode_info *psb_decode_info_p; 188 189 #define CSC_MATRIX_X (3) 190 #define CSC_MATRIX_Y (3) 191 192 struct psb_driver_data_s { 193 struct object_heap_s config_heap; 194 struct object_heap_s context_heap; 195 struct object_heap_s surface_heap; 196 struct object_heap_s buffer_heap; 197 struct object_heap_s image_heap; 198 struct object_heap_s subpic_heap; 199 char * bus_id; 200 uint32_t dev_id; 201 int drm_fd; 202 int dup_drm_fd; 203 204 /* PM_QoS */ 205 int pm_qos_fd; 206 int dri2; 207 int dri_dummy; 208 XID context_id; 209 drm_context_t drm_context; 210 drmLock *drm_lock; 211 int contended_lock; 212 pthread_mutex_t drm_mutex; 213 format_vtable_p profile2Format[PSB_MAX_PROFILES][PSB_MAX_ENTRYPOINTS]; 214 #ifdef PSBVIDEO_MRFL_VPP 215 format_vtable_p vpp_profile; 216 #endif 217 #ifdef PSBVIDEO_MFLD 218 format_vtable_p vpp_profile; 219 #endif 220 uint32_t msvdx_context_base; 221 int video_sd_disabled; 222 int video_hd_disabled; 223 unsigned char * camera_bo; 224 uint32_t camera_phyaddr; 225 uint32_t camera_size; 226 unsigned char * rar_bo; 227 uint32_t rar_phyaddr; 228 uint32_t rar_size; 229 230 int encode_supported; 231 int decode_supported; 232 int hd_encode_supported; 233 int hd_decode_supported; 234 235 int execIoctlOffset; 236 int getParamIoctlOffset; 237 238 struct _WsbmBufferPool *main_pool; 239 struct _WsbmFenceMgr *fence_mgr; 240 241 enum psb_output_method_t output_method; 242 243 /* whether the post-processing use client overlay or not */ 244 int coverlay; 245 int coverlay_init; 246 PsbPortPrivRec coverlay_priv; 247 248 249 /* whether the post-processing use client textureblit or not */ 250 int ctexture; 251 struct psb_texture_s ctexture_priv; 252 253 /* 254 //whether the post-processing use texstreaing or not 255 int ctexstreaing; 256 struct psb_texstreaing ctexstreaing_priv; 257 */ 258 259 unsigned char *ws_priv; /* window system related data structure */ 260 261 262 VASurfaceID cur_displaying_surface; 263 VASurfaceID last_displaying_surface; 264 265 VADisplayAttribute ble_black_mode; 266 VADisplayAttribute ble_white_mode; 267 268 VADisplayAttribute blueStretch_gain; 269 VADisplayAttribute skinColorCorrection_gain; 270 271 VADisplayAttribute brightness; 272 VADisplayAttribute hue; 273 VADisplayAttribute contrast; 274 VADisplayAttribute saturation; 275 /*Save RenderMode and RenderRect attribute 276 * for medfield android extend video mode.*/ 277 uint32_t render_device; 278 uint32_t render_mode; 279 VARectangle render_rect; 280 281 unsigned int clear_color; 282 283 int is_oold; 284 285 unsigned int load_csc_matrix; 286 float csc_matrix[CSC_MATRIX_X][CSC_MATRIX_Y]; 287 int is_BT601; 288 289 unsigned int set_video_range; 290 unsigned int video_range; 291 292 /* subpic number current buffers support */ 293 unsigned int max_subpic; 294 295 /* for multi-thread safe */ 296 int use_xrandr_thread; 297 pthread_mutex_t output_mutex; 298 pthread_t xrandr_thread_id; 299 int extend_fullscreen; 300 301 int drawable_info; 302 int dummy_putsurface; 303 int fixed_fps; 304 unsigned int frame_count; 305 306 uint32_t blend_mode; 307 uint32_t blend_color; 308 uint32_t overlay_auto_paint_color_key; 309 uint32_t color_key; 310 311 /*output rotation info*/ 312 int disable_msvdx_rotate; 313 int disable_msvdx_rotate_backup; 314 int msvdx_rotate_want; /* msvdx rotate info programed to msvdx */ 315 int va_rotate; /* VA rotate passed from APP */ 316 int mipi0_rotation; /* window manager rotation */ 317 int mipi1_rotation; /* window manager rotation */ 318 int hdmi_rotation; /* window manager rotation */ 319 int local_rotation; /* final device rotate: VA rotate+wm rotate */ 320 int extend_rotation; /* final device rotate: VA rotate+wm rotate */ 321 int rotation_dirty; /*flag for recaculate final rotation*/ 322 323 unsigned int outputmethod_checkinterval; 324 325 uint32_t xrandr_dirty; 326 uint32_t xrandr_update; 327 /*only VAProfileH264ConstrainedBaseline profile enable error concealment*/ 328 uint32_t ec_enabled; 329 uint32_t ved_vpp; 330 331 /* vpp is on or off */ 332 int vpp_on; 333 334 uint32_t pre_surfaceid; 335 psb_decode_info_t decode_info; 336 drm_psb_msvdx_decode_status_t *msvdx_decode_status; 337 VASurfaceDecodeMBErrors *surface_mb_error; 338 339 unsigned char *hPVR2DContext; 340 341 VAGenericID wrapped_surface_id[VIDEO_BUFFER_NUM]; 342 VAGenericID wrapped_subpic_id[VIDEO_BUFFER_NUM]; 343 PVR2DMEMINFO *videoBuf[VIDEO_BUFFER_NUM]; 344 PVR2DMEMINFO *subpicBuf[VIDEO_BUFFER_NUM]; 345 void *native_window; 346 int is_android; 347 /* VA_RT_FORMAT_PROTECTED is set to protected for Widevine case */ 348 int protected; 349 }; 350 351 352 #ifdef _FOR_FPGA_ 353 #define IS_CTP(driver_data) 0 354 #define IS_MFLD(driver_data) 0 355 #define IS_MRFL(driver_data) 1 356 #define IS_MRST(driver_data) 0 357 #else 358 #define IS_CTP(driver_data) (((driver_data->dev_id & 0xffff) == 0x08c0) || \ 359 ((driver_data->dev_id & 0xffff) == 0x08c7) || \ 360 ((driver_data->dev_id & 0xffff) == 0x08c8)) 361 #define IS_MRST(driver_data) ((driver_data->dev_id & 0xFFFC) == 0x4100) 362 #define IS_MFLD(driver_data) (((driver_data->dev_id & 0xFFFC) == 0x0130) || ((driver_data->dev_id & 0xFFFF) == 0x08C0) || ((driver_data->dev_id & 0xFFFF) == 0x08C7) || ((driver_data->dev_id & 0xFFFF) == 0x01FF) || ((driver_data->dev_id & 0xFFFF) == 0x08C8)) 363 #define IS_MRFL(driver_data) (((driver_data->dev_id & 0xFFFC) == 0x1180) || ((driver_data->dev_id & 0xFFFC) == 0x1480)) 364 #define IS_MOFD(driver_data) ((driver_data->dev_id & 0xFFFC) == 0x1480) 365 #define IS_LEXINGTON(driver_data) ((driver_data->dev_id & 0xFFFF) == 0x01FF) 366 #define IS_BAYTRAIL(driver_data) ((driver_data->dev_id & 0xFFFF) == 0x0F31) 367 #endif 368 369 struct object_config_s { 370 struct object_base_s base; 371 VAProfile profile; 372 VAEntrypoint entrypoint; 373 VAConfigAttrib attrib_list[PSB_MAX_CONFIG_ATTRIBUTES]; 374 int attrib_count; 375 format_vtable_p format_vtable; 376 }; 377 378 struct object_context_s { 379 struct object_base_s base; 380 VAContextID context_id; 381 VAConfigID config_id; 382 VAProfile profile; 383 VAEntrypoint entry_point; 384 int picture_width; 385 int picture_height; 386 int num_render_targets; 387 VASurfaceID *render_targets; 388 int va_flags; 389 390 object_surface_p current_render_target; 391 object_surface_p ec_target; 392 object_surface_p ec_candidate; 393 VASurfaceID current_render_surface_id; 394 psb_driver_data_p driver_data; 395 format_vtable_p format_vtable; 396 unsigned char *format_data; 397 struct psb_cmdbuf_s *cmdbuf_list[PSB_MAX_CMDBUFS]; 398 struct lnc_cmdbuf_s *lnc_cmdbuf_list[LNC_MAX_CMDBUFS_ENCODE]; 399 struct pnw_cmdbuf_s *pnw_cmdbuf_list[PNW_MAX_CMDBUFS_ENCODE]; 400 struct tng_cmdbuf_s *tng_cmdbuf_list[TNG_MAX_CMDBUFS_ENCODE]; 401 struct vsp_cmdbuf_s *vsp_cmdbuf_list[VSP_MAX_CMDBUFS]; 402 403 struct psb_cmdbuf_s *cmdbuf; /* Current cmd buffer */ 404 struct lnc_cmdbuf_s *lnc_cmdbuf; 405 struct pnw_cmdbuf_s *pnw_cmdbuf; 406 struct tng_cmdbuf_s *tng_cmdbuf; 407 struct vsp_cmdbuf_s *vsp_cmdbuf; 408 409 int cmdbuf_current; 410 411 /* Buffers */ 412 object_buffer_p buffers_unused[PSB_MAX_BUFFERTYPES]; /* Linked lists (HEAD) of unused buffers for each buffer type */ 413 int buffers_unused_count[PSB_MAX_BUFFERTYPES]; /* Linked lists (HEAD) of unused buffers for each buffer type */ 414 object_buffer_p buffers_unused_tail[PSB_MAX_BUFFERTYPES]; /* Linked lists (TAIL) of unused buffers for each buffer type */ 415 object_buffer_p buffers_active[PSB_MAX_BUFFERTYPES]; /* Linked lists of active buffers for each buffer type */ 416 417 object_buffer_p *buffer_list; /* for vaRenderPicture */ 418 int num_buffers; 419 420 enum { 421 psb_video_none = 0, 422 psb_video_mc, 423 psb_video_vld, 424 psb_video_deblock 425 } video_op; 426 427 uint32_t operating_mode; 428 uint32_t flags; /* See render flags below */ 429 uint32_t first_mb; 430 uint32_t last_mb; 431 432 int is_oold; 433 int msvdx_rotate; 434 int msvdx_scaling; 435 int interlaced_stream; 436 437 /* value is 64bits value, consist of 8 bytes 438 * bytes[0]: entrypoint 439 * bytes[1]: profile 440 * bytes[2]: tile stride | rotated tile stride 441 * bytes[3]: driver_data->protected 442 * bytes[4]: width_in_mb; pass width kernel for VC1/H.264 workaround 443 * bytes[5]: height_in_mb; pass width kernel for VC1/H.264 workaround 444 */ 445 uint64_t ctp_type; 446 447 unsigned long msvdx_tile; /* normal tile | (rotate tile << 4) */ 448 #ifdef SLICE_HEADER_PARSING 449 int msvdx_frame_end; 450 int modular_drm; 451 #endif 452 453 uint32_t msvdx_context; 454 455 int scaling_width; 456 int scaling_height; 457 int scaling_buffer_width; 458 int scaling_buffer_height; 459 int scaling_offset_x; 460 int scaling_offset_y; 461 int scaling_update; 462 463 /* Debug */ 464 uint32_t frame_count; 465 uint32_t slice_count; 466 }; 467 468 #define ROTATE_VA2MSVDX(va_rotate) (va_rotate) 469 #define CONTEXT_ROTATE(obj_context) (obj_context->msvdx_rotate != ROTATE_VA2MSVDX(VA_ROTATION_NONE)) 470 #define CONTEXT_SCALING(obj_context) (obj_context->msvdx_scaling) 471 #define CONTEXT_ALTERNATIVE_OUTPUT(obj_context) (CONTEXT_ROTATE(obj_context) || CONTEXT_SCALING(obj_context)) 472 473 enum force_output_method_t { 474 OUTPUT_FORCE_NULL = 0, 475 OUTPUT_FORCE_GPU, 476 OUTPUT_FORCE_OVERLAY, 477 OUTPUT_FORCE_OVERLAY_FOR_SW_DECODE, 478 }; 479 480 #define MAX_SHARE_INFO_KHANDLES 32 481 struct psb_surface_share_info_s { 482 //int rotation_sf; /*rotaion degree from surface flinger.*/ 483 int surface_rotate; /*rotation degree of current rotation surface*/ 484 int metadata_rotate; /*rotation degree of meta data*/ 485 int width_r; 486 int height_r; 487 int surface_protected; /*whether this surface need be protected*/ 488 /*Force render path. 489 0 : no fore. 490 1 : force gpu render; 491 2 : force overlay render.*/ 492 int force_output_method; 493 unsigned int out_loop_khandle; 494 unsigned int renderStatus; 495 unsigned int used_by_widi; 496 int bob_deinterlace; 497 int tiling; 498 unsigned int width; 499 unsigned int height; 500 unsigned int luma_stride; 501 unsigned int chroma_u_stride; 502 unsigned int chroma_v_stride; 503 unsigned int format; 504 unsigned int khandle; 505 long long timestamp; 506 507 unsigned int out_loop_luma_stride; 508 unsigned int out_loop_chroma_u_stride; 509 unsigned int out_loop_chroma_v_stride; 510 511 long long hwc_timestamp; 512 unsigned int layer_transform; 513 514 void *native_window; 515 unsigned int scaling_khandle; 516 unsigned int width_s; 517 unsigned int height_s; 518 519 unsigned int scaling_luma_stride; 520 unsigned int scaling_chroma_u_stride; 521 unsigned int scaling_chroma_v_stride; 522 523 unsigned int crop_width; 524 unsigned int crop_height; 525 526 unsigned int coded_width; 527 unsigned int coded_height; 528 unsigned int initialized; 529 530 unsigned int csc_mode; 531 unsigned int video_range; 532 533 }; 534 535 struct object_surface_s { 536 struct object_base_s base; 537 VASurfaceID surface_id; 538 VAContextID context_id; 539 int width; 540 int height; 541 int height_origin; 542 int width_r; 543 int height_r; 544 int width_s; 545 int height_s; 546 int buffer_width_s; 547 int buffer_height_s; 548 int offset_x_s; 549 int offset_y_s; 550 551 struct psb_surface_s *psb_surface; 552 struct psb_surface_s *out_loop_surface; /* Alternative output surface for rotation */ 553 struct psb_surface_s *scaling_surface; /* Alternative output surface for scaling */ 554 void *subpictures;/* if not NULL, have subpicture information */ 555 unsigned int subpic_count; /* to ensure output have enough space for PDS & RAST */ 556 unsigned int derived_imgcnt; /* is the surface derived by a VAImage? */ 557 unsigned long display_timestamp; /* record the time point of put surface*/ 558 void *rotate_vaddr; 559 struct psb_surface_share_info_s *share_info; 560 int is_ref_surface; /* If true, vaDeriveImage returns error */ 561 }; 562 563 #define PSB_CODEDBUF_SLICE_NUM_MASK (0xff) 564 #define PSB_CODEDBUF_SLICE_NUM_SHIFT (0) 565 566 #define PSB_CODEDBUF_NONE_VCL_NUM_MASK (0xff) 567 #define PSB_CODEDBUF_NONE_VCL_NUM_SHIFT (8) 568 569 #define SET_CODEDBUF_INFO(flag, aux_info, slice_num) \ 570 do {\ 571 (aux_info) &= ~(PSB_CODEDBUF_##flag##_MASK<<PSB_CODEDBUF_##flag##_SHIFT);\ 572 (aux_info) |= ((slice_num) & PSB_CODEDBUF_##flag##_MASK)\ 573 <<PSB_CODEDBUF_##flag##_SHIFT;\ 574 } while (0) 575 576 #define CLEAR_CODEDBUF_INFO(flag, aux_info) \ 577 do {\ 578 (aux_info) &= ~(PSB_CODEDBUF_##flag##_MASK<<PSB_CODEDBUF_##flag##_SHIFT);\ 579 } while (0) 580 581 #define GET_CODEDBUF_INFO(flag, aux_info) \ 582 (((aux_info)>>PSB_CODEDBUF_##flag##_SHIFT) & PSB_CODEDBUF_##flag##_MASK) 583 584 585 #define PSB_CODEDBUF_SEGMENT_MAX (9) 586 587 struct object_buffer_s { 588 struct object_base_s base; 589 object_buffer_p ptr_next; /* Generic ptr for linked list */ 590 object_buffer_p *pptr_prev_next; /* Generic ptr for linked list */ 591 struct psb_buffer_s *psb_buffer; 592 unsigned char *buffer_data; 593 unsigned int size; 594 unsigned int alloc_size; 595 unsigned int max_num_elements; 596 unsigned int num_elements; 597 object_context_p context; 598 VABufferType type; 599 uint32_t last_used; 600 601 /* for VAEncCodedBufferType */ 602 VACodedBufferSegment codedbuf_mapinfo[PSB_CODEDBUF_SEGMENT_MAX]; 603 uint32_t codedbuf_aux_info; 604 }; 605 606 struct object_image_s { 607 struct object_base_s base; 608 VAImage image; 609 unsigned int palette[16]; 610 int subpic_ref; 611 VASurfaceID derived_surface; 612 }; 613 614 struct object_subpic_s { 615 struct object_base_s base; 616 VASubpictureID subpic_id; 617 618 VAImageID image_id; 619 620 /* chromakey range */ 621 unsigned int chromakey_min; 622 unsigned int chromakey_max; 623 unsigned int chromakey_mask; 624 625 /* global alpha */ 626 unsigned int global_alpha; 627 628 /* flags */ 629 unsigned int flags; /* see below */ 630 631 unsigned char *surfaces; /* surfaces, associated with this subpicture */ 632 }; 633 634 typedef struct _PsbSurfaceAttributeTPI { 635 VASurfaceMemoryType type; 636 unsigned int width; 637 unsigned int height; 638 unsigned int size; 639 unsigned int pixel_format; /* buffer format */ 640 unsigned int tiling; /* the memory is tiling or not */ 641 unsigned int luma_stride; /* luma stride, could be width aligned with a special value */ 642 unsigned int chroma_u_stride; /* chroma stride */ 643 unsigned int chroma_v_stride; 644 unsigned int luma_offset; /* could be 0 */ 645 unsigned int chroma_u_offset; /* U offset from the beginning of the memory */ 646 unsigned int chroma_v_offset; /* V offset from the beginning of the memory */ 647 unsigned int count; /* buffer count for surface creation */ 648 unsigned long *buffers; /* buffer handles or user pointers */ 649 unsigned long reserved[4]; /* used to pass additional information, like 362 650 * Android native window pointer 363 651 */ 652 } PsbSurfaceAttributeTPI; 653 654 #define MEMSET_OBJECT(ptr, data_struct) \ 655 memset((unsigned char *)ptr + sizeof(struct object_base_s),\ 656 0, \ 657 sizeof(data_struct) - sizeof(struct object_base_s)) 658 659 struct format_vtable_s { 660 void (*queryConfigAttributes)( 661 VAProfile profile, 662 VAEntrypoint entrypoint, 663 VAConfigAttrib *attrib_list, 664 int num_attribs 665 ); 666 VAStatus(*validateConfig)( 667 object_config_p obj_config 668 ); 669 VAStatus(*createContext)( 670 object_context_p obj_context, 671 object_config_p obj_config 672 ); 673 void (*destroyContext)( 674 object_context_p obj_context 675 ); 676 VAStatus(*beginPicture)( 677 object_context_p obj_context 678 ); 679 VAStatus(*renderPicture)( 680 object_context_p obj_context, 681 object_buffer_p *buffers, 682 int num_buffers 683 ); 684 VAStatus(*endPicture)( 685 object_context_p obj_context 686 ); 687 }; 688 689 #define psb__bounds_check(x, max) \ 690 do { ASSERT(x < max); if (x >= max) x = max - 1; } while(0); 691 692 static inline unsigned long GetTickCount() 693 { 694 struct timeval tv; 695 if (gettimeofday(&tv, NULL)) 696 return 0; 697 return tv.tv_usec / 1000 + tv.tv_sec * 1000; 698 } 699 700 inline static char * buffer_type_to_string(int type) 701 { 702 switch (type) { 703 case VAPictureParameterBufferType: 704 return "VAPictureParameterBufferType"; 705 case VAIQMatrixBufferType: 706 return "VAIQMatrixBufferType"; 707 case VABitPlaneBufferType: 708 return "VABitPlaneBufferType"; 709 case VASliceGroupMapBufferType: 710 return "VASliceGroupMapBufferType"; 711 case VASliceParameterBufferType: 712 return "VASliceParameterBufferType"; 713 case VASliceDataBufferType: 714 return "VASliceDataBufferType"; 715 case VAProtectedSliceDataBufferType: 716 return "VAProtectedSliceDataBufferType"; 717 case VAMacroblockParameterBufferType: 718 return "VAMacroblockParameterBufferType"; 719 case VAResidualDataBufferType: 720 return "VAResidualDataBufferType"; 721 case VADeblockingParameterBufferType: 722 return "VADeblockingParameterBufferType"; 723 case VAImageBufferType: 724 return "VAImageBufferType"; 725 case VAEncCodedBufferType: 726 return "VAEncCodedBufferType"; 727 case VAEncSequenceParameterBufferType: 728 return "VAEncSequenceParameterBufferType"; 729 case VAEncPictureParameterBufferType: 730 return "VAEncPictureParameterBufferType"; 731 case VAEncSliceParameterBufferType: 732 return "VAEncSliceParameterBufferType"; 733 case VAEncMiscParameterBufferType: 734 return "VAEncMiscParameterBufferType"; 735 case VAProbabilityBufferType: 736 return "VAProbabilityBufferType"; 737 case VAHuffmanTableBufferType: 738 return "VAHuffmanTableBufferType"; 739 case VAQMatrixBufferType: 740 return "VAQMatrixBufferType"; 741 default: 742 return "UnknowBuffer"; 743 } 744 } 745 746 inline static int Angle2Rotation(int angle) 747 { 748 angle %= 360; 749 switch (angle) { 750 case 0: 751 return VA_ROTATION_NONE; 752 case 90: 753 return VA_ROTATION_90; 754 case 180: 755 return VA_ROTATION_180; 756 case 270: 757 return VA_ROTATION_270; 758 default: 759 return -1; 760 } 761 } 762 763 inline static int Rotation2Angle(int rotation) 764 { 765 switch (rotation) { 766 case VA_ROTATION_NONE: 767 return 0; 768 case VA_ROTATION_90: 769 return 90; 770 case VA_ROTATION_180: 771 return 180; 772 case VA_ROTATION_270: 773 return 270; 774 default: 775 return -1; 776 } 777 } 778 779 int psb_parse_config(char *env, char *env_value); 780 void psb__destroy_surface(psb_driver_data_p driver_data, object_surface_p obj_surface); 781 unsigned long psb_tile_stride_mode(int w); 782 VAStatus psb__checkSurfaceDimensions(psb_driver_data_p driver_data, int width, int height); 783 784 int LOCK_HARDWARE(psb_driver_data_p driver_data); 785 int UNLOCK_HARDWARE(psb_driver_data_p driver_data); 786 unsigned long psb__tile_stride_log2_256(int w); 787 int psb_update_context(psb_driver_data_p driver_data, unsigned long ctx_type); 788 789 #define CHECK_SURFACE(obj_surface) \ 790 do { \ 791 if (NULL == obj_surface) { \ 792 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE; \ 793 DEBUG_FAILURE; \ 794 return vaStatus; \ 795 } \ 796 } while (0) 797 798 #define CHECK_CONFIG(obj_config) \ 799 do { \ 800 if (NULL == obj_config) { \ 801 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG; \ 802 DEBUG_FAILURE; \ 803 return vaStatus; \ 804 } \ 805 } while (0) 806 807 #define CHECK_CONTEXT(obj_context) \ 808 do { \ 809 if (NULL == obj_context) { \ 810 vaStatus = VA_STATUS_ERROR_INVALID_CONTEXT; \ 811 DEBUG_FAILURE; \ 812 return vaStatus; \ 813 } \ 814 } while (0) 815 816 #define CHECK_BUFFER(obj_buffer) \ 817 do { \ 818 if (NULL == obj_buffer) { \ 819 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER; \ 820 DEBUG_FAILURE; \ 821 return vaStatus; \ 822 } \ 823 } while (0) 824 825 #define CHECK_IMAGE(obj_image) \ 826 do { \ 827 if (NULL == obj_image) { \ 828 vaStatus = VA_STATUS_ERROR_INVALID_IMAGE; \ 829 DEBUG_FAILURE; \ 830 return vaStatus; \ 831 } \ 832 } while (0) 833 834 #define CHECK_SUBPICTURE(obj_subpic) \ 835 do { \ 836 if (NULL == obj_subpic) { \ 837 vaStatus = VA_STATUS_ERROR_INVALID_SUBPICTURE; \ 838 DEBUG_FAILURE; \ 839 return vaStatus; \ 840 } \ 841 } while (0) 842 843 #define CHECK_ALLOCATION(buf) \ 844 do { \ 845 if (buf == NULL) { \ 846 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; \ 847 DEBUG_FAILURE; \ 848 return vaStatus; \ 849 } \ 850 } while (0) 851 852 #define CHECK_VASTATUS() \ 853 do { \ 854 if (VA_STATUS_SUCCESS != vaStatus) { \ 855 DEBUG_FAILURE; \ 856 return vaStatus; \ 857 } \ 858 } while (0) 859 860 #define CHECK_INVALID_PARAM(param) \ 861 do { \ 862 if (param) { \ 863 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; \ 864 DEBUG_FAILURE; \ 865 return vaStatus; \ 866 } \ 867 } while (0) 868 869 #endif /* _PSB_DRV_VIDEO_H_ */ 870