1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2010 - 2018, The Linux Foundation. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions 6 are met: 7 8 * Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above 11 copyright notice, this list of conditions and the following 12 disclaimer in the documentation and/or other materials provided 13 with the distribution. 14 * Neither the name of The Linux Foundation nor the names of its 15 contributors may be used to endorse or promote products derived 16 from this software without specific prior written permission. 17 18 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 25 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 27 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 28 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 --------------------------------------------------------------------------*/ 30 #ifndef __OMX_VDEC_H__ 31 #define __OMX_VDEC_H__ 32 /*============================================================================ 33 O p e n M A X Component 34 Video Decoder 35 36 *//** @file comx_vdec.h 37 This module contains the class definition for openMAX decoder component. 38 39 *//*========================================================================*/ 40 41 ////////////////////////////////////////////////////////////////////////////// 42 // Include Files 43 ////////////////////////////////////////////////////////////////////////////// 44 45 #include <stdlib.h> 46 #include <stdio.h> 47 #include <string.h> 48 #include <inttypes.h> 49 #include <cstddef> 50 #include <dlfcn.h> 51 #include <cutils/atomic.h> 52 #include <qdMetaData.h> 53 #include <color_metadata.h> 54 #define STRINGIFY_ENUMS 55 #include "media/hardware/VideoAPI.h" 56 #include "media/hardware/HardwareAPI.h" 57 #include <unordered_map> 58 #include <media/msm_media_info.h> 59 60 #include <linux/msm_ion.h> 61 #if TARGET_ION_ABI_VERSION >= 2 62 #include <ion/ion.h> 63 #include <linux/dma-buf.h> 64 #else 65 #include <linux/ion.h> 66 #endif 67 68 #include "C2DColorConverter.h" 69 70 static ptrdiff_t x; 71 72 extern "C" { 73 #include <utils/Log.h> 74 } 75 76 #ifdef _ANDROID_ 77 #undef LOG_TAG 78 #define LOG_TAG "OMX-VDEC-1080P" 79 80 #ifdef USE_ION 81 #include <linux/msm_ion.h> 82 //#include <binder/MemoryHeapIon.h> 83 //#else 84 #endif 85 86 #ifdef USE_GBM 87 #include "gbm.h" 88 #include "gbm_priv.h" 89 #endif 90 91 #ifndef NATIVE_BASE_DISABLE 92 #include <nativebase/nativebase.h> 93 #endif 94 #include <linux/videodev2.h> 95 #define VALID_TS(ts) ((ts < LLONG_MAX)? true : false) 96 #include <poll.h> 97 #include "hevc_utils.h" 98 #define TIMEOUT 5000 99 #endif // _ANDROID_ 100 101 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 102 #define STRINGIFY_ENUMS 103 #include <media/hardware/HardwareAPI.h> 104 #endif 105 106 #include <unistd.h> 107 108 #if defined (_ANDROID_ICS_) 109 #include <gralloc_priv.h> 110 #endif 111 112 #include <pthread.h> 113 #ifndef PC_DEBUG 114 #include <semaphore.h> 115 #endif 116 #include "OMX_Core.h" 117 #include "OMX_QCOMExtns.h" 118 #include "OMX_Skype_VideoExtensions.h" 119 #include "OMX_VideoExt.h" 120 #include "OMX_IndexExt.h" 121 #include "qc_omx_component.h" 122 #include "media/msm_vidc_utils.h" 123 #include "frameparser.h" 124 #include "extra_data_handler.h" 125 #include "ts_parser.h" 126 #include "vidc_debug.h" 127 #include "vidc_common.h" 128 #include "vidc_vendor_extensions.h" 129 #ifdef _ANDROID_ 130 #include <cutils/properties.h> 131 #else 132 #define PROPERTY_VALUE_MAX 92 133 #endif 134 extern "C" { 135 OMX_API void * get_omx_component_factory_fn(void); 136 } 137 138 ////////////////////////////////////////////////////////////////////////////// 139 // Module specific globals 140 ////////////////////////////////////////////////////////////////////////////// 141 #define OMX_SPEC_VERSION 0x00000101 142 #define OMX_INIT_STRUCT(_s_, _name_) \ 143 memset((_s_), 0x0, sizeof(_name_)); \ 144 (_s_)->nSize = sizeof(_name_); \ 145 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION \ 146 147 148 ////////////////////////////////////////////////////////////////////////////// 149 // Macros 150 ////////////////////////////////////////////////////////////////////////////// 151 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\ 152 (unsigned) bufHdr,\ 153 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\ 154 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\ 155 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp) 156 157 #define OMX_CORE_CONTROL_CMDQ_SIZE 100 158 #define OMX_CORE_QCIF_HEIGHT 144 159 #define OMX_CORE_QCIF_WIDTH 176 160 #define OMX_CORE_VGA_HEIGHT 480 161 #define OMX_CORE_VGA_WIDTH 640 162 #define OMX_CORE_WVGA_HEIGHT 480 163 #define OMX_CORE_WVGA_WIDTH 800 164 #define OMX_CORE_FWVGA_HEIGHT 480 165 #define OMX_CORE_FWVGA_WIDTH 864 166 167 #define DESC_BUFFER_SIZE (8192 * 16) 168 169 #ifdef _ANDROID_ 170 #define MAX_NUM_INPUT_OUTPUT_BUFFERS 64 171 #endif 172 173 #define MIN_NUM_INPUT_OUTPUT_EXTRADATA_BUFFERS 32 // 32 (max cap when VPP enabled) 174 175 #define OMX_FRAMEINFO_EXTRADATA 0x00010000 176 #define OMX_INTERLACE_EXTRADATA 0x00020000 177 #define OMX_TIMEINFO_EXTRADATA 0x00040000 178 #define OMX_PORTDEF_EXTRADATA 0x00080000 179 #define OMX_EXTNUSER_EXTRADATA 0x00100000 180 #define OMX_FRAMEDIMENSION_EXTRADATA 0x00200000 181 #define OMX_FRAMEPACK_EXTRADATA 0x00400000 182 #define OMX_QP_EXTRADATA 0x00800000 183 #define OMX_BITSINFO_EXTRADATA 0x01000000 184 #define OMX_VQZIPSEI_EXTRADATA 0x02000000 185 #define OMX_OUTPUTCROP_EXTRADATA 0x04000000 186 #define OMX_MB_ERROR_MAP_EXTRADATA 0x08000000 187 188 #define OMX_VUI_DISPLAY_INFO_EXTRADATA 0x08000000 189 #define OMX_MPEG2_SEQDISP_INFO_EXTRADATA 0x10000000 190 #define OMX_VPX_COLORSPACE_INFO_EXTRADATA 0x20000000 191 #define OMX_VC1_SEQDISP_INFO_EXTRADATA 0x40000000 192 #define OMX_DISPLAY_INFO_EXTRADATA 0x80000000 193 #define OMX_HDR_COLOR_INFO_EXTRADATA 0x100000000 194 #define OMX_UBWC_CR_STATS_INFO_EXTRADATA 0x200000000 195 #define DRIVER_EXTRADATA_MASK 0x0000FFFF 196 197 #define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 198 sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3)) 199 #define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 200 sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3)) 201 #define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 202 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3)) 203 #define OMX_FRAMEDIMENSION_EXTRADATA_SIZE (sizeof(OMX_OTHER_EXTRADATATYPE) +\ 204 sizeof(OMX_QCOM_EXTRADATA_FRAMEDIMENSION) + 3)&(~3) 205 #define OMX_FRAMEPACK_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 206 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT) + 3)&(~3)) 207 #define OMX_QP_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 208 sizeof(OMX_QCOM_EXTRADATA_QP) + 3)&(~3)) 209 #define OMX_BITSINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 210 sizeof(OMX_QCOM_EXTRADATA_BITS_INFO) + 3)&(~3)) 211 #define OMX_VQZIPSEI_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 212 sizeof(OMX_QCOM_EXTRADATA_VQZIPSEI) + 3)&(~3)) 213 #define OMX_USERDATA_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 214 + 3)&(~3)) 215 #define OMX_OUTPUTCROP_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 216 sizeof(OMX_QCOM_OUTPUT_CROP) + 3)&(~3)) 217 218 /* STATUS CODES */ 219 /* Base value for status codes */ 220 #define VDEC_S_BASE 0x40000000 221 /* Success */ 222 #define VDEC_S_SUCCESS (VDEC_S_BASE) 223 /* General failure */ 224 #define VDEC_S_EFAIL (VDEC_S_BASE + 1) 225 /* Fatal irrecoverable failure. Need to tear down session. */ 226 #define VDEC_S_EFATAL (VDEC_S_BASE + 2) 227 /* Error with input bistream */ 228 #define VDEC_S_INPUT_BITSTREAM_ERR (VDEC_S_BASE + 3) 229 230 #define VDEC_MSG_BASE 0x0000000 231 /* Codes to identify asynchronous message responses and events that driver 232 wants to communicate to the app.*/ 233 #define VDEC_MSG_RESP_INPUT_BUFFER_DONE (VDEC_MSG_BASE + 1) 234 #define VDEC_MSG_RESP_OUTPUT_BUFFER_DONE (VDEC_MSG_BASE + 2) 235 #define VDEC_MSG_RESP_INPUT_FLUSHED (VDEC_MSG_BASE + 3) 236 #define VDEC_MSG_RESP_OUTPUT_FLUSHED (VDEC_MSG_BASE + 4) 237 #define VDEC_MSG_RESP_FLUSH_INPUT_DONE (VDEC_MSG_BASE + 5) 238 #define VDEC_MSG_RESP_FLUSH_OUTPUT_DONE (VDEC_MSG_BASE + 6) 239 #define VDEC_MSG_RESP_START_DONE (VDEC_MSG_BASE + 7) 240 #define VDEC_MSG_RESP_STOP_DONE (VDEC_MSG_BASE + 8) 241 #define VDEC_MSG_RESP_PAUSE_DONE (VDEC_MSG_BASE + 9) 242 #define VDEC_MSG_RESP_RESUME_DONE (VDEC_MSG_BASE + 10) 243 #define VDEC_MSG_EVT_CONFIG_CHANGED (VDEC_MSG_BASE + 11) 244 #define VDEC_MSG_EVT_HW_ERROR (VDEC_MSG_BASE + 12) 245 #define VDEC_MSG_EVT_INFO_FIELD_DROPPED (VDEC_MSG_BASE + 13) 246 #define VDEC_MSG_EVT_HW_OVERLOAD (VDEC_MSG_BASE + 14) 247 #define VDEC_MSG_EVT_MAX_CLIENTS (VDEC_MSG_BASE + 15) 248 #define VDEC_MSG_EVT_HW_UNSUPPORTED (VDEC_MSG_BASE + 16) 249 250 251 // Define next macro with required values to enable default extradata, 252 // VDEC_EXTRADATA_MB_ERROR_MAP 253 // OMX_INTERLACE_EXTRADATA 254 // OMX_FRAMEINFO_EXTRADATA 255 // OMX_TIMEINFO_EXTRADATA 256 257 //#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA) 258 259 using namespace android; 260 261 enum port_indexes { 262 OMX_CORE_INPUT_PORT_INDEX =0, 263 OMX_CORE_OUTPUT_PORT_INDEX =1, 264 OMX_CORE_INPUT_EXTRADATA_INDEX =2, 265 OMX_CORE_OUTPUT_EXTRADATA_INDEX =3 266 }; 267 268 enum arb_mode_codecs { 269 VDEC_ARB_CODEC_H264 = 0x1, 270 VDEC_ARB_CODEC_HEVC = 0x2, 271 VDEC_ARB_CODEC_MPEG2 = 0x4, 272 }; 273 274 enum vdec_codec { 275 VDEC_CODECTYPE_H264 = 0x1, 276 VDEC_CODECTYPE_H263 = 0x2, 277 VDEC_CODECTYPE_MPEG4 = 0x3, 278 VDEC_CODECTYPE_DIVX_3 = 0x4, 279 VDEC_CODECTYPE_DIVX_4 = 0x5, 280 VDEC_CODECTYPE_DIVX_5 = 0x6, 281 VDEC_CODECTYPE_DIVX_6 = 0x7, 282 VDEC_CODECTYPE_XVID = 0x8, 283 VDEC_CODECTYPE_MPEG1 = 0x9, 284 VDEC_CODECTYPE_MPEG2 = 0xa, 285 VDEC_CODECTYPE_VC1 = 0xb, 286 VDEC_CODECTYPE_VC1_RCV = 0xc, 287 VDEC_CODECTYPE_HEVC = 0xd, 288 VDEC_CODECTYPE_MVC = 0xe, 289 VDEC_CODECTYPE_VP8 = 0xf, 290 VDEC_CODECTYPE_VP9 = 0x10, 291 }; 292 293 enum vdec_output_format { 294 VDEC_YUV_FORMAT_NV12 = 0x1, 295 VDEC_YUV_FORMAT_TILE_4x2 = 0x2, 296 VDEC_YUV_FORMAT_NV12_UBWC = 0x3, 297 VDEC_YUV_FORMAT_NV12_TP10_UBWC = 0x4, 298 VDEC_YUV_FORMAT_P010_VENUS = 0x5, 299 }; 300 301 enum vdec_interlaced_format { 302 VDEC_InterlaceFrameProgressive = 0x1, 303 VDEC_InterlaceInterleaveFrameTopFieldFirst = 0x2, 304 VDEC_InterlaceInterleaveFrameBottomFieldFirst = 0x4, 305 VDEC_InterlaceFrameTopFieldFirst = 0x8, 306 VDEC_InterlaceFrameBottomFieldFirst = 0x10, 307 }; 308 309 enum vdec_output_order { 310 VDEC_ORDER_DISPLAY = 0x1, 311 VDEC_ORDER_DECODE = 0x2 312 }; 313 314 struct vdec_framesize { 315 uint32_t left; 316 uint32_t top; 317 uint32_t right; 318 uint32_t bottom; 319 }; 320 321 struct vdec_picsize { 322 uint32_t frame_width; 323 uint32_t frame_height; 324 uint32_t stride; 325 uint32_t scan_lines; 326 }; 327 328 enum vdec_buffer { 329 VDEC_BUFFER_TYPE_INPUT, 330 VDEC_BUFFER_TYPE_OUTPUT 331 }; 332 333 struct vdec_allocatorproperty { 334 enum vdec_buffer buffer_type; 335 uint32_t mincount; 336 uint32_t maxcount; 337 uint32_t actualcount; 338 size_t buffer_size; 339 uint32_t alignment; 340 uint32_t buf_poolid; 341 size_t meta_buffer_size; 342 }; 343 344 struct vdec_bufferpayload { 345 void *bufferaddr; 346 size_t buffer_len; 347 int pmem_fd; 348 size_t offset; 349 size_t mmaped_size; 350 }; 351 352 enum vdec_picture { 353 PICTURE_TYPE_I, 354 PICTURE_TYPE_P, 355 PICTURE_TYPE_B, 356 PICTURE_TYPE_BI, 357 PICTURE_TYPE_SKIP, 358 PICTURE_TYPE_IDR, 359 PICTURE_TYPE_UNKNOWN 360 }; 361 362 struct vdec_aspectratioinfo { 363 uint32_t aspect_ratio; 364 uint32_t par_width; 365 uint32_t par_height; 366 }; 367 368 struct vdec_sep_metadatainfo { 369 void *metabufaddr; 370 uint32_t size; 371 int fd; 372 int offset; 373 uint32_t buffer_size; 374 }; 375 376 struct vdec_misrinfo { 377 uint32_t misr_dpb_luma; 378 uint32_t misr_dpb_chroma; 379 uint32_t misr_opb_luma; 380 uint32_t misr_opb_chroma; 381 }; 382 383 struct vdec_output_frameinfo { 384 void *bufferaddr; 385 size_t offset; 386 size_t len; 387 uint32_t flags; 388 int64_t time_stamp; 389 enum vdec_picture pic_type; 390 void *client_data; 391 void *input_frame_clientdata; 392 struct vdec_picsize picsize; 393 struct vdec_framesize framesize; 394 enum vdec_interlaced_format interlaced_format; 395 struct vdec_aspectratioinfo aspect_ratio_info; 396 struct vdec_sep_metadatainfo metadata_info; 397 struct vdec_misrinfo misrinfo[2]; 398 }; 399 400 union vdec_msgdata { 401 struct vdec_output_frameinfo output_frame; 402 void *input_frame_clientdata; 403 }; 404 405 struct vdec_msginfo { 406 uint32_t status_code; 407 uint32_t msgcode; 408 union vdec_msgdata msgdata; 409 size_t msgdatasize; 410 }; 411 412 struct vdec_framerate { 413 unsigned long fps_denominator; 414 unsigned long fps_numerator; 415 }; 416 417 #ifdef USE_ION 418 struct vdec_ion { 419 int dev_fd; 420 struct ion_allocation_data alloc_data; 421 int data_fd; 422 }; 423 #endif 424 425 #ifdef USE_GBM 426 struct vdec_gbm { 427 int gbm_device_fd; 428 struct gbm_device *gbm; 429 struct gbm_bo *bo; 430 unsigned long bo_fd; 431 unsigned long meta_fd; 432 }; 433 #endif 434 435 436 struct extradata_buffer_info { 437 unsigned long buffer_size; 438 char* uaddr; 439 int count; 440 int size; 441 #ifdef USE_ION 442 struct vdec_ion ion; 443 #endif 444 }; 445 446 struct video_driver_context { 447 int video_driver_fd; 448 enum vdec_codec decoder_format; 449 enum vdec_output_format output_format; 450 enum vdec_interlaced_format interlace; 451 enum vdec_output_order picture_order; 452 struct vdec_framesize frame_size; 453 struct vdec_picsize video_resolution; 454 struct vdec_allocatorproperty ip_buf; 455 struct vdec_allocatorproperty op_buf; 456 struct vdec_bufferpayload *ptr_inputbuffer; 457 struct vdec_bufferpayload *ptr_outputbuffer; 458 struct vdec_output_frameinfo *ptr_respbuffer; 459 struct vdec_bufferpayload *ptr_intermediate_outputbuffer; 460 struct vdec_output_frameinfo *ptr_intermediate_respbuffer; 461 #ifdef USE_ION 462 struct vdec_ion *ip_buf_ion_info; 463 struct vdec_ion *op_buf_ion_info; 464 struct vdec_ion *op_intermediate_buf_ion_info; 465 struct vdec_ion h264_mv; 466 struct vdec_ion meta_buffer; 467 struct vdec_ion meta_buffer_iommu; 468 #endif 469 #ifdef USE_GBM 470 int gbm_device_fd; 471 struct vdec_gbm *op_buf_gbm_info; 472 struct vdec_gbm *op_intermediate_buf_gbm_info; 473 #endif 474 struct vdec_framerate frame_rate; 475 unsigned extradata; 476 bool timestamp_adjust; 477 char kind[128]; 478 bool idr_only_decoding; 479 unsigned disable_dmx; 480 struct extradata_buffer_info extradata_info; 481 int num_planes; 482 }; 483 484 struct video_decoder_capability { 485 unsigned int min_width; 486 unsigned int max_width; 487 unsigned int min_height; 488 unsigned int max_height; 489 }; 490 491 struct debug_cap { 492 bool in_buffer_log; 493 bool out_buffer_log; 494 bool out_cc_buffer_log; 495 bool out_meta_buffer_log; 496 char infile_name[PROPERTY_VALUE_MAX + 36]; 497 char outfile_name[PROPERTY_VALUE_MAX + 36]; 498 char ccoutfile_name[PROPERTY_VALUE_MAX + 36]; 499 char out_ymetafile_name[PROPERTY_VALUE_MAX + 36]; 500 char out_uvmetafile_name[PROPERTY_VALUE_MAX + 36]; 501 char log_loc[PROPERTY_VALUE_MAX]; 502 FILE *infile; 503 FILE *outfile; 504 FILE *ccoutfile; 505 FILE *out_ymeta_file; 506 FILE *out_uvmeta_file; 507 int64_t session_id; 508 int seq_count; 509 }; 510 511 struct dynamic_buf_list { 512 long fd; 513 long dup_fd; 514 OMX_U32 offset; 515 OMX_U32 ref_count; 516 void *buffaddr; 517 long mapped_size; 518 }; 519 520 struct extradata_info { 521 OMX_BOOL output_crop_updated; 522 OMX_CONFIG_RECTTYPE output_crop_rect; 523 OMX_U32 output_width; 524 OMX_U32 output_height; 525 OMX_QCOM_MISR_INFO misr_info[2]; 526 }; 527 528 struct reconfig_client_data { 529 OMX_U32 width; 530 OMX_U32 height; 531 OMX_U32 dpb_bit_depth; 532 OMX_U32 m_progressive; 533 bool isPortReconfigInsufficient; 534 }; 535 536 struct reconfig_client_crop_data { 537 OMX_U32 width; 538 OMX_U32 height; 539 OMX_U32 left; 540 OMX_U32 top; 541 bool isPortReconfigInsufficient; 542 }; 543 544 typedef std::unordered_map <int, int> ColorSubMapping; 545 typedef std::unordered_map <int, ColorSubMapping> DecColorMapping; 546 typedef std::unordered_map <enum ColorAspects::Primaries, ColorPrimaries> PrimariesMap; 547 typedef std::unordered_map <enum ColorAspects::Transfer, GammaTransfer> TransferMap; 548 typedef std::unordered_map <enum ColorAspects::MatrixCoeffs, MatrixCoEfficients> MatrixCoeffMap; 549 typedef std::unordered_map <enum ColorAspects::Range, ColorRange> RangeMap; 550 551 // OMX video decoder class 552 class omx_vdec: public qc_omx_component 553 { 554 555 public: 556 omx_vdec(); // constructor 557 virtual ~omx_vdec(); // destructor 558 559 static int async_message_process (void *context, void* message); 560 static void process_event_cb(void *ctxt); 561 562 OMX_ERRORTYPE allocate_buffer( 563 OMX_HANDLETYPE hComp, 564 OMX_BUFFERHEADERTYPE **bufferHdr, 565 OMX_U32 port, 566 OMX_PTR appData, 567 OMX_U32 bytes 568 ); 569 570 571 OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp); 572 573 OMX_ERRORTYPE component_init(OMX_STRING role); 574 575 OMX_ERRORTYPE component_role_enum( 576 OMX_HANDLETYPE hComp, 577 OMX_U8 *role, 578 OMX_U32 index 579 ); 580 581 OMX_ERRORTYPE component_tunnel_request( 582 OMX_HANDLETYPE hComp, 583 OMX_U32 port, 584 OMX_HANDLETYPE peerComponent, 585 OMX_U32 peerPort, 586 OMX_TUNNELSETUPTYPE *tunnelSetup 587 ); 588 589 OMX_ERRORTYPE empty_this_buffer( 590 OMX_HANDLETYPE hComp, 591 OMX_BUFFERHEADERTYPE *buffer 592 ); 593 594 595 596 OMX_ERRORTYPE fill_this_buffer( 597 OMX_HANDLETYPE hComp, 598 OMX_BUFFERHEADERTYPE *buffer 599 ); 600 601 602 OMX_ERRORTYPE free_buffer( 603 OMX_HANDLETYPE hComp, 604 OMX_U32 port, 605 OMX_BUFFERHEADERTYPE *buffer 606 ); 607 608 OMX_ERRORTYPE get_component_version( 609 OMX_HANDLETYPE hComp, 610 OMX_STRING componentName, 611 OMX_VERSIONTYPE *componentVersion, 612 OMX_VERSIONTYPE *specVersion, 613 OMX_UUIDTYPE *componentUUID 614 ); 615 616 OMX_ERRORTYPE get_config( 617 OMX_HANDLETYPE hComp, 618 OMX_INDEXTYPE configIndex, 619 OMX_PTR configData 620 ); 621 622 OMX_ERRORTYPE get_extension_index( 623 OMX_HANDLETYPE hComp, 624 OMX_STRING paramName, 625 OMX_INDEXTYPE *indexType 626 ); 627 628 OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp, 629 OMX_INDEXTYPE paramIndex, 630 OMX_PTR paramData); 631 632 OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp, 633 OMX_STATETYPE *state); 634 635 636 637 OMX_ERRORTYPE send_command(OMX_HANDLETYPE hComp, 638 OMX_COMMANDTYPE cmd, 639 OMX_U32 param1, 640 OMX_PTR cmdData); 641 642 643 OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE hComp, 644 OMX_CALLBACKTYPE *callbacks, 645 OMX_PTR appData); 646 647 OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp, 648 OMX_INDEXTYPE configIndex, 649 OMX_PTR configData); 650 651 OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp, 652 OMX_INDEXTYPE paramIndex, 653 OMX_PTR paramData); 654 655 OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE hComp, 656 OMX_BUFFERHEADERTYPE **bufferHdr, 657 OMX_U32 port, 658 OMX_PTR appData, 659 OMX_U32 bytes, 660 OMX_U8 *buffer); 661 662 OMX_ERRORTYPE use_input_heap_buffers( 663 OMX_HANDLETYPE hComp, 664 OMX_BUFFERHEADERTYPE** bufferHdr, 665 OMX_U32 port, 666 OMX_PTR appData, 667 OMX_U32 bytes, 668 OMX_U8* buffer); 669 670 OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE hComp, 671 OMX_BUFFERHEADERTYPE **bufferHdr, 672 OMX_U32 port, 673 OMX_PTR appData, 674 void * eglImage); 675 void complete_pending_buffer_done_cbs(); 676 struct video_driver_context drv_ctx; 677 int m_poll_efd; 678 char *ion_map(int fd, int len); 679 OMX_ERRORTYPE ion_unmap(int fd, void *bufaddr, int len); 680 OMX_ERRORTYPE allocate_extradata(); 681 void free_extradata(); 682 int update_resolution(int width, int height, int stride, int scan_lines); 683 Signal signal; 684 pthread_t msg_thread_id; 685 pthread_t async_thread_id; 686 bool is_component_secure(); 687 OMX_BUFFERHEADERTYPE* get_omx_output_buffer_header(int index); 688 OMX_ERRORTYPE set_dpb(bool is_split_mode); 689 OMX_ERRORTYPE decide_dpb_buffer_mode(); 690 int dpb_bit_depth; 691 bool check_supported_flexible_formats(OMX_COLOR_FORMATTYPE required_format); 692 bool is_flexible_format;//To save status if required format is flexible color formats 693 bool async_thread_force_stop; 694 volatile bool message_thread_stop; 695 struct extradata_info m_extradata_info; 696 int m_progressive; 697 bool is_mbaff; 698 699 enum dither_type { 700 DITHER_DISABLE = 0, 701 DITHER_COLORSPACE_EXCEPTBT2020, 702 DITHER_ALL_COLORSPACE 703 }; 704 enum dither_type m_dither_config; 705 706 enum color_space_type { 707 BT2020 = 0, 708 EXCEPT_BT2020, 709 UNKNOWN 710 }; 711 enum color_space_type m_color_space; 712 713 /* 714 * Class variables to track client set profile and level 715 * via OMX_QTIIndexParamClientConfiguredMaxProfileLevelForSufficiency 716 */ 717 bool mClientSessionForSufficiency; 718 bool isPortReconfigInsufficient; 719 OMX_U32 mClientSetProfile; 720 OMX_U32 mClientSetLevel; 721 inline int get_session_codec_type(); 722 723 private: 724 // Bit Positions 725 enum flags_bit_positions { 726 // Defer transition to IDLE 727 OMX_COMPONENT_IDLE_PENDING =0x1, 728 // Defer transition to LOADING 729 OMX_COMPONENT_LOADING_PENDING =0x2, 730 // First Buffer Pending 731 OMX_COMPONENT_FIRST_BUFFER_PENDING =0x3, 732 // Second Buffer Pending 733 OMX_COMPONENT_SECOND_BUFFER_PENDING =0x4, 734 // Defer transition to Enable 735 OMX_COMPONENT_INPUT_ENABLE_PENDING =0x5, 736 // Defer transition to Enable 737 OMX_COMPONENT_OUTPUT_ENABLE_PENDING =0x6, 738 // Defer transition to Disable 739 OMX_COMPONENT_INPUT_DISABLE_PENDING =0x7, 740 // Defer transition to Disable 741 OMX_COMPONENT_OUTPUT_DISABLE_PENDING =0x8, 742 //defer flush notification 743 OMX_COMPONENT_OUTPUT_FLUSH_PENDING =0x9, 744 OMX_COMPONENT_INPUT_FLUSH_PENDING =0xA, 745 OMX_COMPONENT_PAUSE_PENDING =0xB, 746 OMX_COMPONENT_EXECUTE_PENDING =0xC, 747 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD, 748 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE, 749 OMX_COMPONENT_FLUSH_DEFERRED = 0xF 750 }; 751 752 // Deferred callback identifiers 753 enum { 754 //Event Callbacks from the vdec component thread context 755 OMX_COMPONENT_GENERATE_EVENT = 0x1, 756 //Buffer Done callbacks from the vdec component thread context 757 OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2, 758 //Frame Done callbacks from the vdec component thread context 759 OMX_COMPONENT_GENERATE_FRAME_DONE = 0x3, 760 //Buffer Done callbacks from the vdec component thread context 761 OMX_COMPONENT_GENERATE_FTB = 0x4, 762 //Frame Done callbacks from the vdec component thread context 763 OMX_COMPONENT_GENERATE_ETB = 0x5, 764 //Command 765 OMX_COMPONENT_GENERATE_COMMAND = 0x6, 766 //Push-Pending Buffers 767 OMX_COMPONENT_PUSH_PENDING_BUFS = 0x7, 768 // Empty Buffer Done callbacks 769 OMX_COMPONENT_GENERATE_EBD = 0x8, 770 //Flush Event Callbacks from the vdec component thread context 771 OMX_COMPONENT_GENERATE_EVENT_FLUSH = 0x9, 772 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A, 773 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B, 774 OMX_COMPONENT_GENERATE_FBD = 0xC, 775 OMX_COMPONENT_GENERATE_START_DONE = 0xD, 776 OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE, 777 OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF, 778 OMX_COMPONENT_GENERATE_STOP_DONE = 0x10, 779 OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11, 780 OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12, 781 OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13, 782 OMX_COMPONENT_GENERATE_EOS_DONE = 0x14, 783 OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15, 784 OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16, 785 OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x17, 786 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD = 0x18, 787 OMX_COMPONENT_GENERATE_ION_PREFETCH_PIXEL = 0x19, 788 OMX_COMPONENT_GENERATE_ION_PREFETCH_NON_PIXEL = 0x1A, 789 OMX_COMPONENT_CLOSE_MSG = 0x1B 790 }; 791 792 enum vc1_profile_type { 793 VC1_SP_MP_RCV = 1, 794 VC1_AP = 2 795 }; 796 797 enum v4l2_ports { 798 CAPTURE_PORT, 799 OUTPUT_PORT, 800 MAX_PORT 801 }; 802 803 struct omx_event { 804 unsigned long param1; 805 unsigned long param2; 806 unsigned long id; 807 }; 808 809 struct omx_cmd_queue { 810 omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE]; 811 unsigned long m_read; 812 unsigned long m_write; 813 unsigned long m_size; 814 815 omx_cmd_queue(); 816 ~omx_cmd_queue(); 817 bool insert_entry(unsigned long p1, unsigned long p2, unsigned long id); 818 bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned long *id); 819 // get msgtype of the first ele from the queue 820 unsigned get_q_msg_type(); 821 822 }; 823 struct v4l2_capability cap; 824 #ifdef _ANDROID_ 825 struct ts_entry { 826 OMX_TICKS timestamp; 827 bool valid; 828 }; 829 830 struct ts_arr_list { 831 ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS]; 832 833 ts_arr_list(); 834 ~ts_arr_list(); 835 836 bool insert_ts(OMX_TICKS ts); 837 bool pop_min_ts(OMX_TICKS &ts); 838 bool reset_ts_list(); 839 }; 840 #endif 841 842 struct desc_buffer_hdr { 843 OMX_U8 *buf_addr; 844 OMX_U32 desc_data_size; 845 }; 846 bool allocate_done(void); 847 bool allocate_input_done(void); 848 bool allocate_output_done(void); 849 bool allocate_output_extradata_done(void); 850 851 OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 852 OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex, 853 OMX_BUFFERHEADERTYPE *pmem_bufferHdr); 854 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr, 855 bool intermediate=false); 856 void free_output_buffer_header(bool intermediate=false); 857 void free_input_buffer_header(); 858 void free_output_extradata_buffer_header(); 859 860 OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE hComp, 861 OMX_BUFFERHEADERTYPE **bufferHdr, 862 OMX_U32 port, 863 OMX_PTR appData, 864 OMX_U32 bytes); 865 866 867 OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE hComp, 868 OMX_BUFFERHEADERTYPE **bufferHdr, 869 OMX_U32 port, 870 OMX_PTR appData, 871 OMX_U32 bytes); 872 873 OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE hComp, 874 OMX_BUFFERHEADERTYPE **bufferHdr, 875 OMX_U32 port,OMX_PTR appData, 876 OMX_U32 bytes, 877 bool intermediate=false, 878 int index=-1); 879 OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp, 880 OMX_BUFFERHEADERTYPE **bufferHdr, 881 OMX_U32 port, 882 OMX_PTR appData, 883 OMX_U32 bytes, 884 OMX_U8 *buffer); 885 OMX_ERRORTYPE use_client_output_extradata_buffer(OMX_HANDLETYPE hComp, 886 OMX_BUFFERHEADERTYPE **bufferHdr, 887 OMX_U32 port, 888 OMX_PTR appData, 889 OMX_U32 bytes, 890 OMX_U8 *buffer); 891 OMX_ERRORTYPE get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType); 892 893 OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index); 894 OMX_ERRORTYPE allocate_output_headers(bool intermediate=false); 895 OMX_ERRORTYPE allocate_client_output_extradata_headers(); 896 bool execute_omx_flush(OMX_U32); 897 bool execute_output_flush(); 898 bool execute_input_flush(); 899 void notify_flush_done(void *ctxt); 900 OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp, 901 OMX_BUFFERHEADERTYPE * buffer); 902 903 OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp, 904 OMX_BUFFERHEADERTYPE * buffer); 905 OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE hComp, 906 OMX_BUFFERHEADERTYPE *buffer); 907 908 OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp, 909 OMX_BUFFERHEADERTYPE *buffer 910 ); 911 912 OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp); 913 OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp); 914 OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp); 915 OMX_ERRORTYPE push_input_hevc (OMX_HANDLETYPE hComp); 916 917 OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE hComp, 918 OMX_BUFFERHEADERTYPE *buffer); 919 bool release_done(); 920 921 bool release_output_done(); 922 bool release_input_done(); 923 bool release_output_extradata_done(); 924 OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop); 925 OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop); 926 OMX_ERRORTYPE start_port_reconfig(); 927 OMX_ERRORTYPE update_picture_resolution(); 928 int stream_off(OMX_U32 port); 929 void adjust_timestamp(OMX_S64 &act_timestamp); 930 void set_frame_rate(OMX_S64 act_timestamp); 931 bool handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr); 932 void convert_color_space_info(OMX_U32 primaries, OMX_U32 range, 933 OMX_U32 transfer, OMX_U32 matrix, 934 ColorAspects *aspects); 935 bool handle_color_space_info(void *data); 936 void print_debug_color_aspects(ColorAspects *aspects, const char *prefix); 937 void print_debug_hdr_color_info(HDRStaticInfo *hdr_info, const char *prefix); 938 void print_debug_hdr_color_info_mdata(ColorMetaData* color_mdata); 939 void print_debug_hdr10plus_metadata(ColorMetaData& color_mdata); 940 bool handle_content_light_level_info(void* data); 941 bool handle_mastering_display_color_info(void* data); 942 void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra); 943 void set_colormetadata_in_handle(ColorMetaData *color_mdata, unsigned int buf_index); 944 void prepare_color_aspects_metadata(OMX_U32 primaries, OMX_U32 range, 945 OMX_U32 transfer, OMX_U32 matrix, 946 ColorMetaData *color_mdata); 947 void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, 948 OMX_U32 interlaced_format_type); 949 OMX_ERRORTYPE enable_extradata(OMX_U64 requested_extradata, bool is_internal, 950 bool enable = true); 951 void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, 952 OMX_U32 num_conceal_mb, 953 OMX_U32 recovery_sei_flag, 954 OMX_U32 picture_type, 955 OMX_U32 frame_rate, 956 OMX_TICKS time_stamp, 957 struct msm_vidc_panscan_window_payload *panscan_payload, 958 struct vdec_aspectratioinfo *aspect_ratio_info); 959 void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, 960 OMX_U32 num_conceal_mb, 961 OMX_U32 recovery_sei_flag, 962 OMX_U32 picture_type, 963 OMX_S64 timestamp, 964 OMX_U32 frame_rate, 965 struct vdec_aspectratioinfo *aspect_ratio_info); 966 void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info, 967 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info); 968 void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra); 969 OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn); 970 void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra); 971 void append_frame_dimension_extradata(OMX_OTHER_EXTRADATATYPE *extra); 972 void append_extn_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_extn); 973 void append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_user); 974 void append_concealmb_extradata(OMX_OTHER_EXTRADATATYPE *extra, 975 OMX_OTHER_EXTRADATATYPE *p_concealmb, OMX_U8 *conceal_mb_data); 976 void append_outputcrop_extradata(OMX_OTHER_EXTRADATATYPE *extra, 977 struct msm_vidc_output_crop_payload *output_crop_payload); 978 void append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra, 979 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload); 980 void append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra, 981 struct msm_vidc_frame_qp_payload *qp_payload); 982 void append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra, 983 struct msm_vidc_frame_bits_info_payload *bits_payload); 984 void append_vqzip_extradata(OMX_OTHER_EXTRADATATYPE *extra, 985 struct msm_vidc_vqzip_sei_payload *vqzip_payload); 986 void insert_demux_addr_offset(OMX_U32 address_offset); 987 void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr); 988 OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr); 989 OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra); 990 991 bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size, 992 OMX_U32 alignment); 993 #ifdef USE_ION 994 bool alloc_map_ion_memory(OMX_U32 buffer_size, vdec_ion *ion_info, int flag); 995 void free_ion_memory(struct vdec_ion *buf_ion_info); 996 void do_cache_operations(int fd); 997 #endif 998 999 #ifdef USE_GBM 1000 bool alloc_map_gbm_memory(OMX_U32 w,OMX_U32 h,int gbm_device_fd, 1001 struct vdec_gbm *gbm_info, int flag); 1002 void free_gbm_memory(struct vdec_gbm *buf_gbm_info); 1003 #endif 1004 1005 1006 1007 OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE hComp, 1008 OMX_COMMANDTYPE cmd, 1009 OMX_U32 param1, 1010 OMX_PTR cmdData); 1011 bool post_event( unsigned long p1, 1012 unsigned long p2, 1013 unsigned long id 1014 ); clip2(int x)1015 inline int clip2(int x) { 1016 x = x -1; 1017 x = x | x >> 1; 1018 x = x | x >> 2; 1019 x = x | x >> 4; 1020 x = x | x >> 16; 1021 x = x + 1; 1022 return x; 1023 } 1024 1025 OMX_ERRORTYPE vdec_alloc_h264_mv(); 1026 void vdec_dealloc_h264_mv(); 1027 OMX_ERRORTYPE vdec_alloc_meta_buffers(); 1028 void vdec_dealloc_meta_buffers(); 1029 omx_report_error()1030 inline void omx_report_error () { 1031 if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 1032 DEBUG_PRINT_ERROR("ERROR: Sending OMX_ErrorHardware to Client"); 1033 m_error_propogated = true; 1034 m_cb.EventHandler(&m_cmp,m_app_data, 1035 OMX_EventError,OMX_ErrorHardware,0,NULL); 1036 } 1037 } 1038 omx_report_unsupported_setting()1039 inline void omx_report_unsupported_setting () { 1040 if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 1041 DEBUG_PRINT_ERROR( 1042 "ERROR: Sending OMX_ErrorUnsupportedSetting to Client"); 1043 m_error_propogated = true; 1044 m_cb.EventHandler(&m_cmp, m_app_data, 1045 OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL); 1046 } 1047 } omx_report_hw_overload()1048 inline void omx_report_hw_overload () { 1049 if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 1050 DEBUG_PRINT_ERROR( 1051 "ERROR: Sending OMX_ErrorInsufficientResources to Client"); 1052 m_error_propogated = true; 1053 m_cb.EventHandler(&m_cmp, m_app_data, 1054 OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL); 1055 } 1056 } 1057 1058 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 1059 OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data); 1060 #endif 1061 #if defined (_ANDROID_ICS_) 1062 struct nativebuffer { 1063 native_handle_t *nativehandle; 1064 private_handle_t *privatehandle; 1065 int inuse; 1066 }; 1067 nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS]; 1068 #endif 1069 1070 //************************************************************* 1071 //*******************MEMBER VARIABLES ************************* 1072 //************************************************************* 1073 pthread_mutex_t m_lock; 1074 pthread_mutex_t c_lock; 1075 pthread_mutex_t buf_lock; 1076 //sem to handle the minimum procesing of commands 1077 sem_t m_cmd_lock; 1078 sem_t m_safe_flush; 1079 bool m_error_propogated; 1080 // compression format 1081 OMX_VIDEO_CODINGTYPE eCompressionFormat; 1082 // OMX State 1083 OMX_STATETYPE m_state; 1084 // Application data 1085 OMX_PTR m_app_data; 1086 // Application callbacks 1087 OMX_CALLBACKTYPE m_cb; 1088 OMX_PRIORITYMGMTTYPE m_priority_mgm ; 1089 OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier; 1090 // fill this buffer queue 1091 omx_cmd_queue m_ftb_q; 1092 // Command Q for rest of the events 1093 omx_cmd_queue m_cmd_q; 1094 omx_cmd_queue m_etb_q; 1095 // Input memory pointer 1096 OMX_BUFFERHEADERTYPE *m_inp_mem_ptr; 1097 // Output memory pointer 1098 OMX_BUFFERHEADERTYPE *m_out_mem_ptr; 1099 // Output memory pointer 1100 OMX_BUFFERHEADERTYPE *m_intermediate_out_mem_ptr; 1101 // Client extradata memory pointer 1102 OMX_BUFFERHEADERTYPE *m_client_output_extradata_mem_ptr; 1103 // number of input bitstream error frame count 1104 unsigned int m_inp_err_count; 1105 #ifdef _ANDROID_ 1106 // Timestamp list 1107 ts_arr_list m_timestamp_list; 1108 #endif 1109 1110 bool input_flush_progress; 1111 bool output_flush_progress; 1112 bool input_use_buffer; 1113 bool output_use_buffer; 1114 bool ouput_egl_buffers; 1115 OMX_BOOL m_use_output_pmem; 1116 1117 int pending_input_buffers; 1118 int pending_output_buffers; 1119 // bitmask array size for output side 1120 uint64_t m_out_bm_count; 1121 // bitmask array size for input side 1122 uint64_t m_inp_bm_count; 1123 // bitmask array size for extradata 1124 uint64_t m_out_extradata_bm_count; 1125 //Input port Populated 1126 OMX_BOOL m_inp_bPopulated; 1127 //Output port Populated 1128 OMX_BOOL m_out_bPopulated; 1129 // encapsulate the waiting states. 1130 uint64_t m_flags; 1131 1132 // store I/P PORT state 1133 OMX_BOOL m_inp_bEnabled; 1134 // store O/P PORT state 1135 OMX_BOOL m_out_bEnabled; 1136 OMX_U32 m_in_alloc_cnt; 1137 OMX_U8 m_cRole[OMX_MAX_STRINGNAME_SIZE]; 1138 // Platform specific details 1139 OMX_QCOM_PLATFORM_PRIVATE_LIST *m_platform_list; 1140 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *m_platform_entry; 1141 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info; 1142 // SPS+PPS sent as part of set_config 1143 OMX_VENDOR_EXTRADATATYPE m_vendor_config; 1144 1145 /*Variables for arbitrary Byte parsing support*/ 1146 frame_parse m_frame_parser; 1147 h264_stream_parser *h264_parser; 1148 HEVC_Utils m_hevc_utils; 1149 1150 omx_cmd_queue m_input_pending_q; 1151 omx_cmd_queue m_input_free_q; 1152 bool arbitrary_bytes; 1153 OMX_BUFFERHEADERTYPE h264_scratch; 1154 OMX_BUFFERHEADERTYPE *psource_frame; 1155 OMX_BUFFERHEADERTYPE *pdest_frame; 1156 OMX_BUFFERHEADERTYPE *m_inp_heap_ptr; 1157 OMX_BUFFERHEADERTYPE **m_phdr_pmem_ptr; 1158 unsigned int m_heap_inp_bm_count; 1159 codec_type codec_type_parse; 1160 bool first_frame_meta; 1161 unsigned frame_count; 1162 unsigned nal_count; 1163 unsigned nal_length; 1164 bool look_ahead_nal; 1165 int first_frame; 1166 unsigned char *first_buffer; 1167 int first_frame_size; 1168 unsigned char m_hwdevice_name[80]; 1169 FILE *m_device_file_ptr; 1170 enum vc1_profile_type m_vc1_profile; 1171 OMX_S64 h264_last_au_ts; 1172 OMX_U32 h264_last_au_flags; 1173 OMX_U32 m_demux_offsets[8192]; 1174 OMX_U32 m_demux_entries; 1175 OMX_U32 m_disp_hor_size; 1176 OMX_U32 m_disp_vert_size; 1177 OMX_S64 prev_ts; 1178 OMX_S64 prev_ts_actual; 1179 bool rst_prev_ts; 1180 OMX_U32 frm_int; 1181 OMX_U32 m_fps_received; 1182 float m_fps_prev; 1183 bool m_drc_enable; 1184 1185 struct vdec_allocatorproperty op_buf_rcnfg; 1186 bool in_reconfig; 1187 bool c2d_enable_pending; 1188 OMX_NATIVE_WINDOWTYPE m_display_id; 1189 OMX_U32 client_extradata; 1190 #ifdef _ANDROID_ 1191 bool perf_flag; 1192 OMX_U32 proc_frms, latency; 1193 perf_metrics fps_metrics; 1194 perf_metrics dec_time; 1195 bool m_enable_android_native_buffers; 1196 bool m_use_android_native_buffers; 1197 bool m_debug_extradata; 1198 bool m_disable_dynamic_buf_mode; 1199 OMX_U32 m_conceal_color; 1200 #endif 1201 1202 1203 struct h264_mv_buffer { 1204 unsigned char* buffer; 1205 int size; 1206 int count; 1207 int pmem_fd; 1208 int offset; 1209 }; 1210 h264_mv_buffer h264_mv_buff; 1211 1212 struct meta_buffer { 1213 unsigned char* buffer; 1214 int size; 1215 int count; 1216 int pmem_fd; 1217 int pmem_fd_iommu; 1218 int offset; 1219 }; 1220 meta_buffer meta_buff; 1221 OMX_PARAM_PORTDEFINITIONTYPE m_port_def; 1222 OMX_QCOM_FRAME_PACK_ARRANGEMENT m_frame_pack_arrangement; 1223 omx_time_stamp_reorder time_stamp_dts; 1224 desc_buffer_hdr *m_desc_buffer_ptr; 1225 bool secure_mode; 1226 bool allocate_native_handle; 1227 bool external_meta_buffer; 1228 bool external_meta_buffer_iommu; 1229 OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata; 1230 bool codec_config_flag; 1231 uint32_t capture_capability; 1232 int output_capability; 1233 bool streaming[MAX_PORT]; 1234 OMX_FRAMESIZETYPE framesize; 1235 OMX_CONFIG_RECTTYPE rectangle; 1236 OMX_U32 prev_n_filled_len; 1237 bool m_force_down_scalar; 1238 struct custom_buffersize { 1239 OMX_U32 input_buffersize; 1240 } m_custom_buffersize; 1241 bool m_power_hinted; 1242 bool is_q6_platform; 1243 OMX_ERRORTYPE power_module_register(); 1244 OMX_ERRORTYPE power_module_deregister(); 1245 bool msg_thread_created; 1246 bool async_thread_created; 1247 1248 OMX_VIDEO_PARAM_PROFILELEVELTYPE m_profile_lvl; 1249 QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE m_sParamLowLatency; 1250 1251 //variables to handle dynamic buffer mode 1252 bool dynamic_buf_mode; 1253 OMX_U32 m_reconfig_width; 1254 OMX_U32 m_reconfig_height; 1255 bool m_smoothstreaming_mode; 1256 bool m_decode_order_mode; 1257 bool m_client_req_turbo_mode; 1258 1259 bool m_input_pass_buffer_fd; 1260 DescribeColorAspectsParams m_client_color_space; 1261 DescribeColorAspectsParams m_internal_color_space; 1262 1263 // HDRStaticInfo defined in HardwareAPI.h 1264 DescribeHDRStaticInfoParams m_client_hdr_info; 1265 DescribeHDRStaticInfoParams m_internal_hdr_info; 1266 1267 1268 OMX_U32 operating_frame_rate; 1269 1270 OMX_U32 m_smoothstreaming_width; 1271 OMX_U32 m_smoothstreaming_height; 1272 OMX_ERRORTYPE enable_smoothstreaming(); 1273 OMX_ERRORTYPE enable_adaptive_playback(unsigned long width, unsigned long height); 1274 bool m_disable_ubwc_mode; 1275 OMX_U32 m_downscalar_width; 1276 OMX_U32 m_downscalar_height; 1277 int decide_downscalar(); 1278 int enable_downscalar(); 1279 int disable_downscalar(); 1280 1281 unsigned int m_fill_output_msg; 1282 bool client_set_fps; 1283 unsigned int stereo_output_mode; 1284 class allocate_color_convert_buf 1285 { 1286 public: 1287 allocate_color_convert_buf(); ~allocate_color_convert_buf()1288 ~allocate_color_convert_buf() {}; 1289 void set_vdec_client(void *); 1290 void update_client(); 1291 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format); 1292 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format); 1293 bool update_buffer_req(); 1294 bool get_buffer_req(unsigned int &buffer_size); 1295 OMX_ERRORTYPE set_buffer_req(OMX_U32 buffer_size, OMX_U32 actual_count); 1296 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(); 1297 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr); 1298 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header); 1299 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header); 1300 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp, 1301 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData, 1302 OMX_U32 bytes); 1303 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); is_color_conversion_enabled()1304 bool is_color_conversion_enabled() {return enabled;} 1305 void enable_color_conversion(bool enable); is_client_buffers_disabled()1306 bool is_client_buffers_disabled() {return client_buffers_disabled;} set_client_buffers_disabled(bool val)1307 void set_client_buffers_disabled(bool val) {client_buffers_disabled = val;} 1308 // Returns a specific C2D state, if true current buffers should undergo C2D conversion 1309 // otherwise C2D is in quasi enabled state where in C2D src and dst formats are set but 1310 // color conversion doesnt take place. This state is needed to handle color conversion 1311 // of interlaced clips during port reconfig. client_buffers_invalid()1312 bool client_buffers_invalid() {return (!enabled || client_buffers_disabled);} 1313 private: 1314 #define MAX_COUNT MAX_NUM_INPUT_OUTPUT_BUFFERS 1315 omx_vdec *omx; 1316 bool enabled; 1317 bool client_buffers_disabled; 1318 OMX_COLOR_FORMATTYPE ColorFormat; 1319 void init_members(); 1320 bool color_convert_mode; 1321 ColorConvertFormat dest_format; 1322 ColorConvertFormat src_format; 1323 C2DColorConverter c2dcc; 1324 unsigned int allocated_count; 1325 unsigned int buffer_size_req; 1326 unsigned int buffer_alignment_req; 1327 OMX_U32 m_c2d_width; 1328 OMX_U32 m_c2d_height; 1329 OMX_QCOM_PLATFORM_PRIVATE_LIST m_platform_list_client[MAX_COUNT]; 1330 OMX_QCOM_PLATFORM_PRIVATE_ENTRY m_platform_entry_client[MAX_COUNT]; 1331 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT]; 1332 OMX_BUFFERHEADERTYPE m_out_mem_ptr_client[MAX_COUNT]; 1333 DecColorMapping mMapOutput2DriverColorFormat; 1334 ColorSubMapping mMapOutput2Convert; 1335 #ifdef USE_ION 1336 struct vdec_ion op_buf_ion_info[MAX_COUNT]; 1337 #endif 1338 #ifdef USE_GBM 1339 struct vdec_gbm op_buf_gbm_info[MAX_COUNT]; 1340 #endif 1341 1342 unsigned char *pmem_baseaddress[MAX_COUNT]; 1343 int pmem_fd[MAX_COUNT]; 1344 }; 1345 allocate_color_convert_buf client_buffers; 1346 struct video_decoder_capability m_decoder_capability; 1347 struct debug_cap m_debug; 1348 int log_input_buffers(const char *, int, uint64_t, int); 1349 int log_output_buffers(OMX_BUFFERHEADERTYPE *); 1350 int log_cc_output_buffers(OMX_BUFFERHEADERTYPE *); 1351 void send_codec_config(); 1352 OMX_TICKS m_last_rendered_TS; 1353 int32_t m_dec_hfr_fps; 1354 int32_t m_dec_secure_prefetch_size_internal; 1355 int32_t m_dec_secure_prefetch_size_output; 1356 int32_t m_arb_mode_override; 1357 volatile int32_t m_queued_codec_config_count; 1358 OMX_U32 current_perf_level; 1359 bool secure_scaling_to_non_secure_opb; 1360 bool m_force_compressed_for_dpb; 1361 bool m_is_display_session; 1362 1363 class perf_control { 1364 typedef int (*perf_lock_acquire_t)(int, int, int*, int); 1365 typedef int (*perf_lock_release_t)(int); 1366 1367 private: 1368 void *m_perf_lib; 1369 int m_perf_handle; 1370 perf_lock_acquire_t m_perf_lock_acquire; 1371 perf_lock_release_t m_perf_lock_release; 1372 1373 public: 1374 perf_control(); 1375 ~perf_control(); 1376 bool load_perf_library(); 1377 int perf_lock_acquire(); 1378 void perf_lock_release(); 1379 int m_perf_control_enable; 1380 }; 1381 perf_control m_perf_control; 1382 getPreferredColorFormatNonSurfaceMode(OMX_U32 index)1383 static OMX_COLOR_FORMATTYPE getPreferredColorFormatNonSurfaceMode(OMX_U32 index) { 1384 //On Android, we default to standard YUV formats for non-surface use-cases 1385 //where apps prefer known color formats. 1386 OMX_COLOR_FORMATTYPE formatsNonSurfaceMode[] = { 1387 [0] = OMX_COLOR_FormatYUV420SemiPlanar, 1388 [1] = OMX_COLOR_FormatYUV420Planar, 1389 [2] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m, 1390 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView, 1391 [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed, 1392 }; 1393 return (index < sizeof(formatsNonSurfaceMode) / sizeof(OMX_COLOR_FORMATTYPE)) ? 1394 formatsNonSurfaceMode[index] : OMX_COLOR_FormatMax; 1395 } 1396 getPreferredColorFormatDefaultMode(OMX_U32 index)1397 OMX_COLOR_FORMATTYPE getPreferredColorFormatDefaultMode(OMX_U32 index) { 1398 //for surface mode (normal playback), advertise native/accelerated formats first 1399 OMX_COLOR_FORMATTYPE format = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; 1400 1401 if (!m_disable_ubwc_mode) { 1402 OMX_COLOR_FORMATTYPE formatsDefault[] = { 1403 [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed, 1404 [1] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m, 1405 [2] = OMX_COLOR_FormatYUV420SemiPlanar, 1406 [3] = OMX_COLOR_FormatYUV420Planar, 1407 [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView, 1408 }; 1409 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ? 1410 formatsDefault[index] : OMX_COLOR_FormatMax; 1411 } else { 1412 OMX_COLOR_FORMATTYPE formatsDefault[] = { 1413 [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m, 1414 [1] = OMX_COLOR_FormatYUV420SemiPlanar, 1415 [2] = OMX_COLOR_FormatYUV420Planar, 1416 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView, 1417 }; 1418 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ? 1419 formatsDefault[index] : OMX_COLOR_FormatMax; 1420 } 1421 return format; 1422 } 1423 1424 static OMX_ERRORTYPE describeColorFormat(OMX_PTR params); 1425 bool prefetch_buffers(unsigned long prefetch_count, 1426 unsigned long prefetch_size, unsigned ioctl_code, 1427 unsigned ion_flag); 1428 unsigned char m_prefetch_done; 1429 1430 client_extradata_info m_client_out_extradata_info; 1431 1432 OMX_ERRORTYPE get_vendor_extension_config( 1433 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext); 1434 OMX_ERRORTYPE set_vendor_extension_config( 1435 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext); 1436 1437 void init_vendor_extensions (VendorExtensionStore&); 1438 1439 // list of extensions is not mutable after initialization 1440 const VendorExtensionStore mVendorExtensionStore; 1441 1442 // Map of ColorAspects (VideoAPI.h) to ColorMetaData (color_metadata.h) 1443 PrimariesMap mPrimariesMap; 1444 TransferMap mTransferMap; 1445 MatrixCoeffMap mMatrixCoeffMap; 1446 RangeMap mColorRangeMap; 1447 1448 void init_color_aspects_map(); 1449 void convert_color_aspects_to_metadata(ColorAspects& aspects, ColorMetaData &color_mdata); 1450 void convert_hdr_info_to_metadata(HDRStaticInfo& hdr_info, ColorMetaData &color_mdata); 1451 void get_preferred_color_aspects(ColorAspects& preferredColorAspects); 1452 void get_preferred_hdr_info(HDRStaticInfo& preferredHDRInfo); 1453 bool vdec_query_cap(struct v4l2_queryctrl &cap); 1454 public: 1455 bool is_down_scalar_enabled; 1456 bool m_is_split_mode; 1457 bool m_buffer_error; 1458 }; 1459 1460 enum instance_state { 1461 MSM_VIDC_CORE_UNINIT_DONE = 0x0001, 1462 MSM_VIDC_CORE_INIT, 1463 MSM_VIDC_CORE_INIT_DONE, 1464 MSM_VIDC_OPEN, 1465 MSM_VIDC_OPEN_DONE, 1466 MSM_VIDC_LOAD_RESOURCES, 1467 MSM_VIDC_LOAD_RESOURCES_DONE, 1468 MSM_VIDC_START, 1469 MSM_VIDC_START_DONE, 1470 MSM_VIDC_STOP, 1471 MSM_VIDC_STOP_DONE, 1472 MSM_VIDC_RELEASE_RESOURCES, 1473 MSM_VIDC_RELEASE_RESOURCES_DONE, 1474 MSM_VIDC_CLOSE, 1475 MSM_VIDC_CLOSE_DONE, 1476 MSM_VIDC_CORE_UNINIT, 1477 }; 1478 1479 enum vidc_resposes_id { 1480 MSM_VIDC_DECODER_FLUSH_DONE = 0x11, 1481 MSM_VIDC_DECODER_EVENT_CHANGE, 1482 }; 1483 1484 #endif // __OMX_VDEC_H__ 1485