1/*-------------------------------------------------------------------------- 2Copyright (c) 2010 - 2016, 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 18THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 19WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 25BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 27OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 28IF 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 <cutils/atomic.h> 51#include <qdMetaData.h> 52 53static ptrdiff_t x; 54 55#ifdef _ANDROID_ 56#ifdef MAX_RES_720P 57#define LOG_TAG "OMX-VDEC-720P" 58#elif MAX_RES_1080P 59#define LOG_TAG "OMX-VDEC-1080P" 60#else 61#define LOG_TAG "OMX-VDEC" 62#endif 63 64#ifdef USE_ION 65#include <linux/msm_ion.h> 66//#include <binder/MemoryHeapIon.h> 67//#else 68#endif 69#include <binder/MemoryHeapBase.h> 70#include <ui/ANativeObjectBase.h> 71extern "C" { 72#include <utils/Log.h> 73} 74#include <linux/videodev2.h> 75#include <poll.h> 76#include "hevc_utils.h" 77#define TIMEOUT 5000 78#endif // _ANDROID_ 79 80#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 81#include <media/hardware/HardwareAPI.h> 82#endif 83 84#include <unistd.h> 85 86#if defined (_ANDROID_ICS_) 87#include <gralloc_priv.h> 88#endif 89 90#include <pthread.h> 91#ifndef PC_DEBUG 92#include <semaphore.h> 93#endif 94#include "OMX_Core.h" 95#include "OMX_QCOMExtns.h" 96#include "OMX_Skype_VideoExtensions.h" 97#include "OMX_VideoExt.h" 98#include "OMX_IndexExt.h" 99#include "qc_omx_component.h" 100#include <linux/msm_vidc_dec.h> 101#include <media/msm_vidc.h> 102#include "frameparser.h" 103#ifdef MAX_RES_1080P 104#include "mp4_utils.h" 105#endif 106#include "extra_data_handler.h" 107#include "ts_parser.h" 108#include "vidc_color_converter.h" 109#include "vidc_debug.h" 110#include "vidc_vendor_extensions.h" 111#ifdef _ANDROID_ 112#include <cutils/properties.h> 113#else 114#define PROPERTY_VALUE_MAX 92 115#endif 116extern "C" { 117 OMX_API void * get_omx_component_factory_fn(void); 118} 119 120#ifdef _ANDROID_ 121using namespace android; 122#ifdef USE_ION 123class VideoHeap : public MemoryHeapBase 124{ 125 public: 126 VideoHeap(int devicefd, size_t size, void* base,ion_user_handle_t handle,int mapfd); 127 virtual ~VideoHeap() {} 128 private: 129 int m_ion_device_fd; 130 ion_user_handle_t m_ion_handle; 131}; 132#else 133// local pmem heap object 134class VideoHeap : public MemoryHeapBase 135{ 136 public: 137 VideoHeap(int fd, size_t size, void* base); 138 virtual ~VideoHeap() {} 139}; 140#endif 141#endif // _ANDROID_ 142////////////////////////////////////////////////////////////////////////////// 143// Module specific globals 144////////////////////////////////////////////////////////////////////////////// 145#define OMX_SPEC_VERSION 0x00000101 146#define OMX_INIT_STRUCT(_s_, _name_) \ 147 memset((_s_), 0x0, sizeof(_name_)); \ 148(_s_)->nSize = sizeof(_name_); \ 149(_s_)->nVersion.nVersion = OMX_SPEC_VERSION \ 150 151 152////////////////////////////////////////////////////////////////////////////// 153// Macros 154////////////////////////////////////////////////////////////////////////////// 155#define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\ 156 (unsigned) bufHdr,\ 157 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\ 158 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\ 159 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp) 160 161// BitMask Management logic 162#define BITS_PER_INDEX 64 163#define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_INDEX - 1)/BITS_PER_INDEX) 164#define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_INDEX) 165#define BITMASK_FLAG(mIndex) ((uint64_t)1 << ((mIndex) % BITS_PER_INDEX)) 166#define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 167 &= ~(BITMASK_FLAG(mIndex)) 168#define BITMASK_SET(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 169 |= BITMASK_FLAG(mIndex) 170#define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 171 & BITMASK_FLAG(mIndex)) 172#define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 173 & BITMASK_FLAG(mIndex)) == 0x0) 174#define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 175 & BITMASK_FLAG(mIndex)) 176#define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 177 & BITMASK_FLAG(mIndex)) == 0x0) 178 179#define OMX_CORE_CONTROL_CMDQ_SIZE 100 180#define OMX_CORE_QCIF_HEIGHT 144 181#define OMX_CORE_QCIF_WIDTH 176 182#define OMX_CORE_VGA_HEIGHT 480 183#define OMX_CORE_VGA_WIDTH 640 184#define OMX_CORE_WVGA_HEIGHT 480 185#define OMX_CORE_WVGA_WIDTH 800 186 187#define DESC_BUFFER_SIZE (8192 * 16) 188 189#ifdef _ANDROID_ 190#define MAX_NUM_INPUT_OUTPUT_BUFFERS 64 191#endif 192 193#define OMX_FRAMEINFO_EXTRADATA 0x00010000 194#define OMX_INTERLACE_EXTRADATA 0x00020000 195#define OMX_TIMEINFO_EXTRADATA 0x00040000 196#define OMX_PORTDEF_EXTRADATA 0x00080000 197#define OMX_EXTNUSER_EXTRADATA 0x00100000 198#define OMX_FRAMEDIMENSION_EXTRADATA 0x00200000 199#define OMX_FRAMEPACK_EXTRADATA 0x00400000 200#define OMX_QP_EXTRADATA 0x00800000 201#define OMX_BITSINFO_EXTRADATA 0x01000000 202#define OMX_VQZIPSEI_EXTRADATA 0x02000000 203 204#define OMX_VUI_DISPLAY_INFO_EXTRADATA 0x08000000 205#define OMX_MPEG2_SEQDISP_INFO_EXTRADATA 0x10000000 206#define OMX_VPX_COLORSPACE_INFO_EXTRADATA 0x20000000 207#define OMX_VC1_SEQDISP_INFO_EXTRADATA 0x40000000 208#define OMX_DISPLAY_INFO_EXTRADATA 0x80000000 209#define DRIVER_EXTRADATA_MASK 0x0000FFFF 210 211#define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 212 sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3)) 213#define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 214 sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3)) 215#define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 216 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3)) 217#define OMX_FRAMEDIMENSION_EXTRADATA_SIZE (sizeof(OMX_OTHER_EXTRADATATYPE) +\ 218 sizeof(OMX_QCOM_EXTRADATA_FRAMEDIMENSION) + 3)&(~3) 219#define OMX_FRAMEPACK_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 220 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT) + 3)&(~3)) 221#define OMX_QP_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 222 sizeof(OMX_QCOM_EXTRADATA_QP) + 3)&(~3)) 223#define OMX_BITSINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 224 sizeof(OMX_QCOM_EXTRADATA_BITS_INFO) + 3)&(~3)) 225#define OMX_VQZIPSEI_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 226 sizeof(OMX_QCOM_EXTRADATA_VQZIPSEI) + 3)&(~3)) 227#define OMX_USERDATA_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 228 + 3)&(~3)) 229 230// Define next macro with required values to enable default extradata, 231// VDEC_EXTRADATA_MB_ERROR_MAP 232// OMX_INTERLACE_EXTRADATA 233// OMX_FRAMEINFO_EXTRADATA 234// OMX_TIMEINFO_EXTRADATA 235 236//#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA) 237 238enum port_indexes { 239 OMX_CORE_INPUT_PORT_INDEX =0, 240 OMX_CORE_OUTPUT_PORT_INDEX =1 241}; 242enum vidc_perf_level { 243 VIDC_SVS = 0, 244 VIDC_NOMINAL = 1, 245 VIDC_TURBO = 2 246}; 247#ifdef USE_ION 248struct vdec_ion { 249 int ion_device_fd; 250 struct ion_fd_data fd_ion_data; 251 struct ion_allocation_data ion_alloc_data; 252}; 253#endif 254 255#ifdef _MSM8974_ 256struct extradata_buffer_info { 257 unsigned long buffer_size; 258 char* uaddr; 259 int count; 260 int size; 261#ifdef USE_ION 262 struct vdec_ion ion; 263#endif 264}; 265#endif 266 267struct video_driver_context { 268 int video_driver_fd; 269 enum vdec_codec decoder_format; 270 enum vdec_output_fromat output_format; 271 enum vdec_interlaced_format interlace; 272 enum vdec_output_order picture_order; 273 struct vdec_framesize frame_size; 274 struct vdec_picsize video_resolution; 275 struct vdec_allocatorproperty ip_buf; 276 struct vdec_allocatorproperty op_buf; 277 struct vdec_bufferpayload *ptr_inputbuffer; 278 struct vdec_bufferpayload *ptr_outputbuffer; 279 struct vdec_output_frameinfo *ptr_respbuffer; 280#ifdef USE_ION 281 struct vdec_ion *ip_buf_ion_info; 282 struct vdec_ion *op_buf_ion_info; 283 struct vdec_ion h264_mv; 284 struct vdec_ion meta_buffer; 285 struct vdec_ion meta_buffer_iommu; 286#endif 287 struct vdec_framerate frame_rate; 288 unsigned extradata; 289 bool timestamp_adjust; 290 char kind[128]; 291 bool idr_only_decoding; 292 unsigned disable_dmx; 293#ifdef _MSM8974_ 294 struct extradata_buffer_info extradata_info; 295 int num_planes; 296#endif 297}; 298 299struct video_decoder_capability { 300 unsigned int min_width; 301 unsigned int max_width; 302 unsigned int min_height; 303 unsigned int max_height; 304}; 305 306struct debug_cap { 307 bool in_buffer_log; 308 bool out_buffer_log; 309 bool out_meta_buffer_log; 310 char infile_name[PROPERTY_VALUE_MAX + 36]; 311 char outfile_name[PROPERTY_VALUE_MAX + 36]; 312 char out_ymetafile_name[PROPERTY_VALUE_MAX + 36]; 313 char out_uvmetafile_name[PROPERTY_VALUE_MAX + 36]; 314 char log_loc[PROPERTY_VALUE_MAX]; 315 FILE *infile; 316 FILE *outfile; 317 FILE *out_ymeta_file; 318 FILE *out_uvmeta_file; 319}; 320 321struct dynamic_buf_list { 322 long fd; 323 long dup_fd; 324 OMX_U32 offset; 325 OMX_U32 ref_count; 326 void *buffaddr; 327 long mapped_size; 328}; 329 330// OMX video decoder class 331class omx_vdec: public qc_omx_component 332{ 333 334 public: 335 omx_vdec(); // constructor 336 virtual ~omx_vdec(); // destructor 337 338 static int async_message_process (void *context, void* message); 339 static void process_event_cb(void *ctxt,unsigned char id); 340 341 OMX_ERRORTYPE allocate_buffer( 342 OMX_HANDLETYPE hComp, 343 OMX_BUFFERHEADERTYPE **bufferHdr, 344 OMX_U32 port, 345 OMX_PTR appData, 346 OMX_U32 bytes 347 ); 348 349 350 OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp); 351 352 OMX_ERRORTYPE component_init(OMX_STRING role); 353 354 OMX_ERRORTYPE component_role_enum( 355 OMX_HANDLETYPE hComp, 356 OMX_U8 *role, 357 OMX_U32 index 358 ); 359 360 OMX_ERRORTYPE component_tunnel_request( 361 OMX_HANDLETYPE hComp, 362 OMX_U32 port, 363 OMX_HANDLETYPE peerComponent, 364 OMX_U32 peerPort, 365 OMX_TUNNELSETUPTYPE *tunnelSetup 366 ); 367 368 OMX_ERRORTYPE empty_this_buffer( 369 OMX_HANDLETYPE hComp, 370 OMX_BUFFERHEADERTYPE *buffer 371 ); 372 373 374 375 OMX_ERRORTYPE fill_this_buffer( 376 OMX_HANDLETYPE hComp, 377 OMX_BUFFERHEADERTYPE *buffer 378 ); 379 380 381 OMX_ERRORTYPE free_buffer( 382 OMX_HANDLETYPE hComp, 383 OMX_U32 port, 384 OMX_BUFFERHEADERTYPE *buffer 385 ); 386 387 OMX_ERRORTYPE get_component_version( 388 OMX_HANDLETYPE hComp, 389 OMX_STRING componentName, 390 OMX_VERSIONTYPE *componentVersion, 391 OMX_VERSIONTYPE *specVersion, 392 OMX_UUIDTYPE *componentUUID 393 ); 394 395 OMX_ERRORTYPE get_config( 396 OMX_HANDLETYPE hComp, 397 OMX_INDEXTYPE configIndex, 398 OMX_PTR configData 399 ); 400 401 OMX_ERRORTYPE get_extension_index( 402 OMX_HANDLETYPE hComp, 403 OMX_STRING paramName, 404 OMX_INDEXTYPE *indexType 405 ); 406 407 OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp, 408 OMX_INDEXTYPE paramIndex, 409 OMX_PTR paramData); 410 411 OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp, 412 OMX_STATETYPE *state); 413 414 415 416 OMX_ERRORTYPE send_command(OMX_HANDLETYPE hComp, 417 OMX_COMMANDTYPE cmd, 418 OMX_U32 param1, 419 OMX_PTR cmdData); 420 421 422 OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE hComp, 423 OMX_CALLBACKTYPE *callbacks, 424 OMX_PTR appData); 425 426 OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp, 427 OMX_INDEXTYPE configIndex, 428 OMX_PTR configData); 429 430 OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp, 431 OMX_INDEXTYPE paramIndex, 432 OMX_PTR paramData); 433 434 OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE hComp, 435 OMX_BUFFERHEADERTYPE **bufferHdr, 436 OMX_U32 port, 437 OMX_PTR appData, 438 OMX_U32 bytes, 439 OMX_U8 *buffer); 440 441 OMX_ERRORTYPE use_input_heap_buffers( 442 OMX_HANDLETYPE hComp, 443 OMX_BUFFERHEADERTYPE** bufferHdr, 444 OMX_U32 port, 445 OMX_PTR appData, 446 OMX_U32 bytes, 447 OMX_U8* buffer); 448 449 OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE hComp, 450 OMX_BUFFERHEADERTYPE **bufferHdr, 451 OMX_U32 port, 452 OMX_PTR appData, 453 void * eglImage); 454 void complete_pending_buffer_done_cbs(); 455 struct video_driver_context drv_ctx; 456 int m_poll_efd; 457#ifdef _MSM8974_ 458 OMX_ERRORTYPE allocate_extradata(); 459 void free_extradata(); 460 int update_resolution(int width, int height, int stride, int scan_lines); 461 OMX_ERRORTYPE is_video_session_supported(); 462#endif 463 int m_pipe_in; 464 int m_pipe_out; 465 pthread_t msg_thread_id; 466 pthread_t async_thread_id; 467 bool is_component_secure(); 468 void buf_ref_add(int nPortIndex); 469 void buf_ref_remove(); 470 OMX_ERRORTYPE set_dpb(bool is_split_mode, int dpb_color_format); 471 OMX_ERRORTYPE decide_dpb_buffer_mode(bool force_split_mode); 472 void request_perf_level(enum vidc_perf_level perf_level); 473 int dpb_bit_depth; 474 bool async_thread_force_stop; 475 volatile bool message_thread_stop; 476 477 private: 478 // Bit Positions 479 enum flags_bit_positions { 480 // Defer transition to IDLE 481 OMX_COMPONENT_IDLE_PENDING =0x1, 482 // Defer transition to LOADING 483 OMX_COMPONENT_LOADING_PENDING =0x2, 484 // First Buffer Pending 485 OMX_COMPONENT_FIRST_BUFFER_PENDING =0x3, 486 // Second Buffer Pending 487 OMX_COMPONENT_SECOND_BUFFER_PENDING =0x4, 488 // Defer transition to Enable 489 OMX_COMPONENT_INPUT_ENABLE_PENDING =0x5, 490 // Defer transition to Enable 491 OMX_COMPONENT_OUTPUT_ENABLE_PENDING =0x6, 492 // Defer transition to Disable 493 OMX_COMPONENT_INPUT_DISABLE_PENDING =0x7, 494 // Defer transition to Disable 495 OMX_COMPONENT_OUTPUT_DISABLE_PENDING =0x8, 496 //defer flush notification 497 OMX_COMPONENT_OUTPUT_FLUSH_PENDING =0x9, 498 OMX_COMPONENT_INPUT_FLUSH_PENDING =0xA, 499 OMX_COMPONENT_PAUSE_PENDING =0xB, 500 OMX_COMPONENT_EXECUTE_PENDING =0xC, 501 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD, 502 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE, 503 OMX_COMPONENT_FLUSH_DEFERRED = 0xF 504 }; 505 506 // Deferred callback identifiers 507 enum { 508 //Event Callbacks from the vdec component thread context 509 OMX_COMPONENT_GENERATE_EVENT = 0x1, 510 //Buffer Done callbacks from the vdec component thread context 511 OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2, 512 //Frame Done callbacks from the vdec component thread context 513 OMX_COMPONENT_GENERATE_FRAME_DONE = 0x3, 514 //Buffer Done callbacks from the vdec component thread context 515 OMX_COMPONENT_GENERATE_FTB = 0x4, 516 //Frame Done callbacks from the vdec component thread context 517 OMX_COMPONENT_GENERATE_ETB = 0x5, 518 //Command 519 OMX_COMPONENT_GENERATE_COMMAND = 0x6, 520 //Push-Pending Buffers 521 OMX_COMPONENT_PUSH_PENDING_BUFS = 0x7, 522 // Empty Buffer Done callbacks 523 OMX_COMPONENT_GENERATE_EBD = 0x8, 524 //Flush Event Callbacks from the vdec component thread context 525 OMX_COMPONENT_GENERATE_EVENT_FLUSH = 0x9, 526 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A, 527 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B, 528 OMX_COMPONENT_GENERATE_FBD = 0xc, 529 OMX_COMPONENT_GENERATE_START_DONE = 0xD, 530 OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE, 531 OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF, 532 OMX_COMPONENT_GENERATE_STOP_DONE = 0x10, 533 OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11, 534 OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12, 535 OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13, 536 OMX_COMPONENT_GENERATE_EOS_DONE = 0x14, 537 OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15, 538 OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16, 539 OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x17, 540 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD = 0x18, 541 OMX_COMPONENT_CLOSE_MSG = 0x19 542 }; 543 544 enum vc1_profile_type { 545 VC1_SP_MP_RCV = 1, 546 VC1_AP = 2 547 }; 548 549#ifdef _MSM8974_ 550 enum v4l2_ports { 551 CAPTURE_PORT, 552 OUTPUT_PORT, 553 MAX_PORT 554 }; 555#endif 556 557 struct omx_event { 558 unsigned long param1; 559 unsigned long param2; 560 unsigned long id; 561 }; 562 563 struct omx_cmd_queue { 564 omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE]; 565 unsigned long m_read; 566 unsigned long m_write; 567 unsigned long m_size; 568 569 omx_cmd_queue(); 570 ~omx_cmd_queue(); 571 bool insert_entry(unsigned long p1, unsigned long p2, unsigned long id); 572 bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned long *id); 573 // get msgtype of the first ele from the queue 574 unsigned get_q_msg_type(); 575 576 }; 577 struct v4l2_capability cap; 578#ifdef _ANDROID_ 579 struct ts_entry { 580 OMX_TICKS timestamp; 581 bool valid; 582 }; 583 584 struct ts_arr_list { 585 ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS]; 586 587 ts_arr_list(); 588 ~ts_arr_list(); 589 590 bool insert_ts(OMX_TICKS ts); 591 bool pop_min_ts(OMX_TICKS &ts); 592 bool reset_ts_list(); 593 }; 594#endif 595 596 struct desc_buffer_hdr { 597 OMX_U8 *buf_addr; 598 OMX_U32 desc_data_size; 599 }; 600 bool allocate_done(void); 601 bool allocate_input_done(void); 602 bool allocate_output_done(void); 603 604 OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 605 OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex, 606 OMX_BUFFERHEADERTYPE *pmem_bufferHdr); 607 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 608 void free_output_buffer_header(); 609 void free_input_buffer_header(); 610 611 OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE hComp, 612 OMX_BUFFERHEADERTYPE **bufferHdr, 613 OMX_U32 port, 614 OMX_PTR appData, 615 OMX_U32 bytes); 616 617 618 OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE hComp, 619 OMX_BUFFERHEADERTYPE **bufferHdr, 620 OMX_U32 port, 621 OMX_PTR appData, 622 OMX_U32 bytes); 623 624 OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE hComp, 625 OMX_BUFFERHEADERTYPE **bufferHdr, 626 OMX_U32 port,OMX_PTR appData, 627 OMX_U32 bytes); 628 OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp, 629 OMX_BUFFERHEADERTYPE **bufferHdr, 630 OMX_U32 port, 631 OMX_PTR appData, 632 OMX_U32 bytes, 633 OMX_U8 *buffer); 634 OMX_ERRORTYPE get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType); 635 636 OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index); 637 OMX_ERRORTYPE allocate_output_headers(); 638 bool execute_omx_flush(OMX_U32); 639 bool execute_output_flush(); 640 bool execute_input_flush(); 641 OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp, 642 OMX_BUFFERHEADERTYPE * buffer); 643 644 OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp, 645 OMX_BUFFERHEADERTYPE * buffer); 646 OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE hComp, 647 OMX_BUFFERHEADERTYPE *buffer); 648 649 OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp, 650 OMX_BUFFERHEADERTYPE *buffer 651 ); 652 653 OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp); 654 OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp); 655 OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp); 656 OMX_ERRORTYPE push_input_hevc (OMX_HANDLETYPE hComp); 657 OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp); 658 659 OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE hComp, 660 OMX_BUFFERHEADERTYPE *buffer); 661 bool release_done(); 662 663 bool release_output_done(); 664 bool release_input_done(); 665 OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop); 666 OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop); 667 OMX_ERRORTYPE start_port_reconfig(); 668 OMX_ERRORTYPE update_picture_resolution(); 669 int stream_off(OMX_U32 port); 670 void adjust_timestamp(OMX_S64 &act_timestamp); 671 void set_frame_rate(OMX_S64 act_timestamp); 672 void handle_extradata_secure(OMX_BUFFERHEADERTYPE *p_buf_hdr); 673 void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr); 674 void convert_color_space_info(OMX_U32 primaries, OMX_U32 range, 675 OMX_U32 transfer, OMX_U32 matrix, ColorSpace_t *color_space, 676 ColorAspects *aspects); 677 void handle_color_space_info(void *data, unsigned int buf_index); 678 void set_colorspace_in_handle(ColorSpace_t color, unsigned int buf_index); 679 void print_debug_color_aspects(ColorAspects *aspects, const char *prefix); 680 void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra); 681#ifdef _MSM8974_ 682 void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, 683 OMX_U32 interlaced_format_type, bool is_mbaff); 684 OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool is_internal, 685 bool enable = true); 686 void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, 687 OMX_U32 num_conceal_mb, 688 OMX_U32 picture_type, 689 OMX_U32 frame_rate, 690 OMX_TICKS time_stamp, 691 struct msm_vidc_panscan_window_payload *panscan_payload, 692 struct vdec_aspectratioinfo *aspect_ratio_info); 693#else 694 void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, 695 OMX_U32 interlaced_format_type, OMX_U32 buf_index); 696 OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true); 697#endif 698 void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, 699 OMX_U32 num_conceal_mb, 700 OMX_U32 picture_type, 701 OMX_S64 timestamp, 702 OMX_U32 frame_rate, 703 struct vdec_aspectratioinfo *aspect_ratio_info); 704 void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info, 705 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info); 706 void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra); 707 OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn); 708 void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra); 709 void append_frame_dimension_extradata(OMX_OTHER_EXTRADATATYPE *extra); 710 void append_extn_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_extn); 711 void append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_user); 712 void append_concealmb_extradata(OMX_OTHER_EXTRADATATYPE *extra, 713 OMX_OTHER_EXTRADATATYPE *p_concealmb, OMX_U8 *conceal_mb_data); 714 void append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra, 715 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload); 716 void append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra, 717 struct msm_vidc_frame_qp_payload *qp_payload); 718 void append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra, 719 struct msm_vidc_frame_bits_info_payload *bits_payload); 720 void append_vqzip_extradata(OMX_OTHER_EXTRADATATYPE *extra, 721 struct msm_vidc_vqzip_sei_payload *vqzip_payload); 722 void insert_demux_addr_offset(OMX_U32 address_offset); 723 void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr); 724 OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr); 725 OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra); 726 727 bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size, 728 OMX_U32 alignment); 729#ifdef USE_ION 730 int alloc_map_ion_memory(OMX_U32 buffer_size, 731 OMX_U32 alignment, struct ion_allocation_data *alloc_data, 732 struct ion_fd_data *fd_data,int flag); 733 void free_ion_memory(struct vdec_ion *buf_ion_info); 734#endif 735 736 737 OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE hComp, 738 OMX_COMMANDTYPE cmd, 739 OMX_U32 param1, 740 OMX_PTR cmdData); 741 bool post_event( unsigned long p1, 742 unsigned long p2, 743 unsigned long id 744 ); 745 inline int clip2(int x) { 746 x = x -1; 747 x = x | x >> 1; 748 x = x | x >> 2; 749 x = x | x >> 4; 750 x = x | x >> 16; 751 x = x + 1; 752 return x; 753 } 754 755#ifdef MAX_RES_1080P 756 OMX_ERRORTYPE vdec_alloc_h264_mv(); 757 void vdec_dealloc_h264_mv(); 758 OMX_ERRORTYPE vdec_alloc_meta_buffers(); 759 void vdec_dealloc_meta_buffers(); 760#endif 761 762 inline void omx_report_error () { 763 if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 764 DEBUG_PRINT_ERROR("ERROR: Sending OMX_ErrorHardware to Client"); 765 m_error_propogated = true; 766 m_cb.EventHandler(&m_cmp,m_app_data, 767 OMX_EventError,OMX_ErrorHardware,0,NULL); 768 } 769 } 770 771 inline void omx_report_unsupported_setting () { 772 if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 773 DEBUG_PRINT_ERROR( 774 "ERROR: Sending OMX_ErrorUnsupportedSetting to Client"); 775 m_error_propogated = true; 776 m_cb.EventHandler(&m_cmp, m_app_data, 777 OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL); 778 } 779 } 780 inline void omx_report_hw_overload () { 781 if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 782 DEBUG_PRINT_ERROR( 783 "ERROR: Sending OMX_ErrorInsufficientResources to Client"); 784 m_error_propogated = true; 785 m_cb.EventHandler(&m_cmp, m_app_data, 786 OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL); 787 } 788 } 789 790#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 791 OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data); 792#endif 793#if defined (_ANDROID_ICS_) 794 struct nativebuffer { 795 native_handle_t *nativehandle; 796 private_handle_t *privatehandle; 797 int inuse; 798 }; 799 nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS]; 800#endif 801 802 //************************************************************* 803 //*******************MEMBER VARIABLES ************************* 804 //************************************************************* 805 pthread_mutex_t m_lock; 806 pthread_mutex_t c_lock; 807 pthread_mutex_t buf_lock; 808 //sem to handle the minimum procesing of commands 809 sem_t m_cmd_lock; 810 sem_t m_safe_flush; 811 bool m_error_propogated; 812 // compression format 813 OMX_VIDEO_CODINGTYPE eCompressionFormat; 814 // OMX State 815 OMX_STATETYPE m_state; 816 // Application data 817 OMX_PTR m_app_data; 818 // Application callbacks 819 OMX_CALLBACKTYPE m_cb; 820 OMX_PRIORITYMGMTTYPE m_priority_mgm ; 821 OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier; 822 // fill this buffer queue 823 omx_cmd_queue m_ftb_q; 824 // Command Q for rest of the events 825 omx_cmd_queue m_cmd_q; 826 omx_cmd_queue m_etb_q; 827 // Input memory pointer 828 OMX_BUFFERHEADERTYPE *m_inp_mem_ptr; 829 // Output memory pointer 830 OMX_BUFFERHEADERTYPE *m_out_mem_ptr; 831 // number of input bitstream error frame count 832 unsigned int m_inp_err_count; 833#ifdef _ANDROID_ 834 // Timestamp list 835 ts_arr_list m_timestamp_list; 836#endif 837 838 bool input_flush_progress; 839 bool output_flush_progress; 840 bool input_use_buffer; 841 bool output_use_buffer; 842 bool ouput_egl_buffers; 843 OMX_BOOL m_use_output_pmem; 844 OMX_BOOL m_out_mem_region_smi; 845 OMX_BOOL m_out_pvt_entry_pmem; 846 847 int pending_input_buffers; 848 int pending_output_buffers; 849 // bitmask array size for output side 850 uint64_t m_out_bm_count; 851 // bitmask array size for input side 852 uint64_t m_inp_bm_count; 853 //Input port Populated 854 OMX_BOOL m_inp_bPopulated; 855 //Output port Populated 856 OMX_BOOL m_out_bPopulated; 857 // encapsulate the waiting states. 858 uint64_t m_flags; 859 860#ifdef _ANDROID_ 861 // Heap pointer to frame buffers 862 struct vidc_heap { 863 sp<MemoryHeapBase> video_heap_ptr; 864 }; 865 struct vidc_heap *m_heap_ptr; 866 unsigned int m_heap_count; 867#endif //_ANDROID_ 868 // store I/P PORT state 869 OMX_BOOL m_inp_bEnabled; 870 // store O/P PORT state 871 OMX_BOOL m_out_bEnabled; 872 OMX_U32 m_in_alloc_cnt; 873 OMX_U8 m_cRole[OMX_MAX_STRINGNAME_SIZE]; 874 // Platform specific details 875 OMX_QCOM_PLATFORM_PRIVATE_LIST *m_platform_list; 876 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *m_platform_entry; 877 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info; 878 // SPS+PPS sent as part of set_config 879 OMX_VENDOR_EXTRADATATYPE m_vendor_config; 880 881 /*Variables for arbitrary Byte parsing support*/ 882 frame_parse m_frame_parser; 883 h264_stream_parser *h264_parser; 884 MP4_Utils mp4_headerparser; 885 HEVC_Utils m_hevc_utils; 886 887 omx_cmd_queue m_input_pending_q; 888 omx_cmd_queue m_input_free_q; 889 bool arbitrary_bytes; 890 OMX_BUFFERHEADERTYPE h264_scratch; 891 OMX_BUFFERHEADERTYPE *psource_frame; 892 OMX_BUFFERHEADERTYPE *pdest_frame; 893 OMX_BUFFERHEADERTYPE *m_inp_heap_ptr; 894 OMX_BUFFERHEADERTYPE **m_phdr_pmem_ptr; 895 unsigned int m_heap_inp_bm_count; 896 codec_type codec_type_parse; 897 bool first_frame_meta; 898 unsigned frame_count; 899 unsigned nal_count; 900 unsigned nal_length; 901 bool look_ahead_nal; 902 int first_frame; 903 unsigned char *first_buffer; 904 int first_frame_size; 905 unsigned char m_hwdevice_name[80]; 906 FILE *m_device_file_ptr; 907 enum vc1_profile_type m_vc1_profile; 908 OMX_S64 h264_last_au_ts; 909 OMX_U32 h264_last_au_flags; 910 OMX_U32 m_demux_offsets[8192]; 911 OMX_U32 m_demux_entries; 912 OMX_U32 m_disp_hor_size; 913 OMX_U32 m_disp_vert_size; 914 OMX_S64 prev_ts; 915 OMX_S64 prev_ts_actual; 916 bool rst_prev_ts; 917 OMX_U32 frm_int; 918 919 struct vdec_allocatorproperty op_buf_rcnfg; 920 bool in_reconfig; 921 OMX_NATIVE_WINDOWTYPE m_display_id; 922 OMX_U32 client_extradata; 923#ifdef _ANDROID_ 924 bool m_debug_timestamp; 925 bool perf_flag; 926 OMX_U32 proc_frms, latency; 927 perf_metrics fps_metrics; 928 perf_metrics dec_time; 929 bool m_reject_avc_1080p_mp; 930 bool m_enable_android_native_buffers; 931 bool m_use_android_native_buffers; 932 bool m_debug_extradata; 933 bool m_debug_concealedmb; 934 bool m_disable_dynamic_buf_mode; 935 OMX_U32 m_conceal_color; 936#endif 937 938 939 struct h264_mv_buffer { 940 unsigned char* buffer; 941 int size; 942 int count; 943 int pmem_fd; 944 int offset; 945 }; 946 h264_mv_buffer h264_mv_buff; 947 948 struct meta_buffer { 949 unsigned char* buffer; 950 int size; 951 int count; 952 int pmem_fd; 953 int pmem_fd_iommu; 954 int offset; 955 }; 956 meta_buffer meta_buff; 957 extra_data_handler extra_data_handle; 958 OMX_PARAM_PORTDEFINITIONTYPE m_port_def; 959 OMX_QCOM_FRAME_PACK_ARRANGEMENT m_frame_pack_arrangement; 960 omx_time_stamp_reorder time_stamp_dts; 961 desc_buffer_hdr *m_desc_buffer_ptr; 962 bool secure_mode; 963 bool allocate_native_handle; 964 bool external_meta_buffer; 965 bool external_meta_buffer_iommu; 966 OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata; 967 OMX_OTHER_EXTRADATATYPE *m_other_extradata; 968 bool codec_config_flag; 969#ifdef _MSM8974_ 970 int capture_capability; 971 int output_capability; 972 bool streaming[MAX_PORT]; 973 OMX_FRAMESIZETYPE framesize; 974 OMX_CONFIG_RECTTYPE rectangle; 975 OMX_U32 prev_n_filled_len; 976 bool is_down_scalar_enabled; 977 bool m_force_down_scalar; 978#endif 979 struct custom_buffersize { 980 OMX_U32 input_buffersize; 981 } m_custom_buffersize; 982 bool m_power_hinted; 983 bool is_q6_platform; 984 OMX_ERRORTYPE power_module_register(); 985 OMX_ERRORTYPE power_module_deregister(); 986 bool msg_thread_created; 987 bool async_thread_created; 988 989 OMX_VIDEO_PARAM_PROFILELEVELTYPE m_profile_lvl; 990 OMX_U32 m_profile; 991 992 //variables to handle dynamic buffer mode 993 bool dynamic_buf_mode; 994 struct dynamic_buf_list *out_dynamic_list; 995 OMX_U32 m_reconfig_width; 996 OMX_U32 m_reconfig_height; 997 bool m_smoothstreaming_mode; 998 bool m_decode_order_mode; 999 1000 bool m_input_pass_buffer_fd; 1001 DescribeColorAspectsParams m_client_color_space; 1002 DescribeColorAspectsParams m_internal_color_space; 1003 1004 OMX_U32 m_smoothstreaming_width; 1005 OMX_U32 m_smoothstreaming_height; 1006 OMX_ERRORTYPE enable_smoothstreaming(); 1007 OMX_ERRORTYPE enable_adaptive_playback(unsigned long width, unsigned long height); 1008 bool is_thulium_v1; 1009 bool m_disable_ubwc_mode; 1010 OMX_U32 m_downscalar_width; 1011 OMX_U32 m_downscalar_height; 1012 int decide_downscalar(); 1013 int enable_downscalar(); 1014 int disable_downscalar(); 1015 1016 unsigned int m_fill_output_msg; 1017 bool client_set_fps; 1018 class allocate_color_convert_buf 1019 { 1020 public: 1021 allocate_color_convert_buf(); 1022 ~allocate_color_convert_buf(); 1023 void set_vdec_client(void *); 1024 void update_client(); 1025 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format); 1026 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format); 1027 bool update_buffer_req(); 1028 bool get_buffer_req(unsigned int &buffer_size); 1029 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(); 1030 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr); 1031 OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr); 1032 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header); 1033 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header); 1034 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp, 1035 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData, 1036 OMX_U32 bytes); 1037 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 1038 bool is_color_conversion_enabled() {return enabled;} 1039 private: 1040#define MAX_COUNT MAX_NUM_INPUT_OUTPUT_BUFFERS 1041 omx_vdec *omx; 1042 bool enabled; 1043 OMX_COLOR_FORMATTYPE ColorFormat; 1044 void init_members(); 1045 bool color_convert_mode; 1046 ColorConvertFormat dest_format; 1047 class omx_c2d_conv c2d; 1048 unsigned int allocated_count; 1049 unsigned int buffer_size_req; 1050 unsigned int buffer_alignment_req; 1051 OMX_QCOM_PLATFORM_PRIVATE_LIST m_platform_list_client[MAX_COUNT]; 1052 OMX_QCOM_PLATFORM_PRIVATE_ENTRY m_platform_entry_client[MAX_COUNT]; 1053 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT]; 1054 OMX_BUFFERHEADERTYPE m_out_mem_ptr_client[MAX_COUNT]; 1055#ifdef USE_ION 1056 struct vdec_ion op_buf_ion_info[MAX_COUNT]; 1057#endif 1058 unsigned char *pmem_baseaddress[MAX_COUNT]; 1059 int pmem_fd[MAX_COUNT]; 1060 struct vidc_heap { 1061 sp<MemoryHeapBase> video_heap_ptr; 1062 }; 1063 struct vidc_heap m_heap_ptr[MAX_COUNT]; 1064 1065 OMX_ERRORTYPE cache_ops(unsigned int index, unsigned int cmd); 1066 inline OMX_ERRORTYPE cache_clean_buffer(unsigned int index) { 1067 return cache_ops(index, ION_IOC_CLEAN_CACHES); 1068 } 1069 OMX_ERRORTYPE cache_clean_invalidate_buffer(unsigned int index) { 1070 return cache_ops(index, ION_IOC_CLEAN_INV_CACHES); 1071 } 1072 }; 1073#if defined (_MSM8960_) || defined (_MSM8974_) 1074 allocate_color_convert_buf client_buffers; 1075#endif 1076 struct video_decoder_capability m_decoder_capability; 1077 struct debug_cap m_debug; 1078 int log_input_buffers(const char *, int); 1079 int log_output_buffers(OMX_BUFFERHEADERTYPE *); 1080#ifdef _MSM8974_ 1081 void send_codec_config(); 1082#endif 1083 OMX_TICKS m_last_rendered_TS; 1084 volatile int32_t m_queued_codec_config_count; 1085 OMX_U32 current_perf_level; 1086 bool secure_scaling_to_non_secure_opb; 1087 bool m_force_compressed_for_dpb; 1088 class perf_lock { 1089 private: 1090 pthread_mutex_t mlock; 1091 1092 public: 1093 perf_lock() { 1094 pthread_mutex_init(&mlock, NULL); 1095 } 1096 1097 ~perf_lock() { 1098 pthread_mutex_destroy(&mlock); 1099 } 1100 1101 void lock() { 1102 pthread_mutex_lock(&mlock); 1103 } 1104 1105 void unlock() { 1106 pthread_mutex_unlock(&mlock); 1107 } 1108 }; 1109 1110 class perf_control { 1111 // 2 cores will be requested if framerate is beyond 45 fps 1112 static const int MIN_FRAME_DURATION_FOR_PERF_REQUEST_US = (1e6 / 45); 1113 typedef int (*perf_lock_acquire_t)(int, int, int*, int); 1114 typedef int (*perf_lock_release_t)(int); 1115 1116 private: 1117 void *m_perf_lib; 1118 int m_perf_handle; 1119 perf_lock_acquire_t m_perf_lock_acquire; 1120 perf_lock_release_t m_perf_lock_release; 1121 bool load_lib(); 1122 struct mpctl_stats { 1123 int vid_inst_count; 1124 bool vid_acquired; 1125 int vid_disp_handle; 1126 }; 1127 static struct mpctl_stats mpctl_obj; 1128 static perf_lock m_perf_lock; 1129 1130 public: 1131 perf_control(); 1132 ~perf_control(); 1133 void request_cores(int frame_duration_us); 1134 void send_hint_to_mpctl(bool state); 1135 }; 1136 perf_control m_perf_control; 1137 1138 static OMX_COLOR_FORMATTYPE getPreferredColorFormatNonSurfaceMode(OMX_U32 index) { 1139 //On Android, we default to standard YUV formats for non-surface use-cases 1140 //where apps prefer known color formats. 1141 OMX_COLOR_FORMATTYPE formatsNonSurfaceMode[] = { 1142 [0] = OMX_COLOR_FormatYUV420SemiPlanar, 1143 [1] = OMX_COLOR_FormatYUV420Planar, 1144 [2] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m, 1145 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView, 1146 [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed, 1147 }; 1148 return (index < sizeof(formatsNonSurfaceMode) / sizeof(OMX_COLOR_FORMATTYPE)) ? 1149 formatsNonSurfaceMode[index] : OMX_COLOR_FormatMax; 1150 } 1151 1152 OMX_COLOR_FORMATTYPE getPreferredColorFormatDefaultMode(OMX_U32 index) { 1153 //for surface mode (normal playback), advertise native/accelerated formats first 1154 OMX_COLOR_FORMATTYPE format = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; 1155 1156 if (!m_disable_ubwc_mode) { 1157 OMX_COLOR_FORMATTYPE formatsDefault[] = { 1158 [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed, 1159 [1] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m, 1160 [2] = OMX_COLOR_FormatYUV420SemiPlanar, 1161 [3] = OMX_COLOR_FormatYUV420Planar, 1162 [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView, 1163 }; 1164 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ? 1165 formatsDefault[index] : OMX_COLOR_FormatMax; 1166 } else { 1167 OMX_COLOR_FORMATTYPE formatsDefault[] = { 1168 [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m, 1169 [1] = OMX_COLOR_FormatYUV420SemiPlanar, 1170 [2] = OMX_COLOR_FormatYUV420Planar, 1171 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView, 1172 }; 1173 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ? 1174 formatsDefault[index] : OMX_COLOR_FormatMax; 1175 } 1176 return format; 1177 } 1178 1179 static OMX_ERRORTYPE describeColorFormat(OMX_PTR params); 1180 void prefetchNewBuffers(); 1181 1182 OMX_ERRORTYPE get_vendor_extension_config( 1183 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext); 1184 OMX_ERRORTYPE set_vendor_extension_config( 1185 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext); 1186 1187 void init_vendor_extensions (VendorExtensionStore&); 1188 1189 // list of extensions is not mutable after initialization 1190 const VendorExtensionStore mVendorExtensionStore; 1191}; 1192 1193#ifdef _MSM8974_ 1194enum instance_state { 1195 MSM_VIDC_CORE_UNINIT_DONE = 0x0001, 1196 MSM_VIDC_CORE_INIT, 1197 MSM_VIDC_CORE_INIT_DONE, 1198 MSM_VIDC_OPEN, 1199 MSM_VIDC_OPEN_DONE, 1200 MSM_VIDC_LOAD_RESOURCES, 1201 MSM_VIDC_LOAD_RESOURCES_DONE, 1202 MSM_VIDC_START, 1203 MSM_VIDC_START_DONE, 1204 MSM_VIDC_STOP, 1205 MSM_VIDC_STOP_DONE, 1206 MSM_VIDC_RELEASE_RESOURCES, 1207 MSM_VIDC_RELEASE_RESOURCES_DONE, 1208 MSM_VIDC_CLOSE, 1209 MSM_VIDC_CLOSE_DONE, 1210 MSM_VIDC_CORE_UNINIT, 1211}; 1212 1213enum vidc_resposes_id { 1214 MSM_VIDC_DECODER_FLUSH_DONE = 0x11, 1215 MSM_VIDC_DECODER_EVENT_CHANGE, 1216}; 1217 1218#endif // _MSM8974_ 1219 1220#endif // __OMX_VDEC_H__ 1221