1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2010-2012, Code Aurora Forum. 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 are met: 6 * Redistributions of source code must retain the above copyright 7 notice, this list of conditions and the following disclaimer. 8 * Redistributions in binary form must reproduce the above copyright 9 notice, this list of conditions and the following disclaimer in the 10 documentation and/or other materials provided with the distribution. 11 * Neither the name of Code Aurora nor 12 the names of its contributors may be used to endorse or promote 13 products derived from this software without specific prior written 14 permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 --------------------------------------------------------------------------*/ 28 #ifndef __OMX_VDEC_H__ 29 #define __OMX_VDEC_H__ 30 /*============================================================================ 31 O p e n M A X Component 32 Video Decoder 33 34 *//** @file comx_vdec.h 35 This module contains the class definition for openMAX decoder component. 36 37 *//*========================================================================*/ 38 39 ////////////////////////////////////////////////////////////////////////////// 40 // Include Files 41 ////////////////////////////////////////////////////////////////////////////// 42 43 #include <stdlib.h> 44 #include <stdio.h> 45 #include <string.h> 46 #include <inttypes.h> 47 #include <cstddef> 48 #include <gralloc_priv.h> 49 50 static ptrdiff_t x; 51 52 #ifdef _ANDROID_ 53 #ifdef USE_ION 54 #include <linux/msm_ion.h> 55 #endif 56 #include <binder/MemoryHeapBase.h> 57 #include <ui/ANativeObjectBase.h> 58 #include <binder/IServiceManager.h> 59 extern "C"{ 60 #include<utils/Log.h> 61 } 62 #include <linux/videodev2.h> 63 #include <poll.h> 64 #define TIMEOUT 5000 65 #ifdef MAX_RES_720P 66 #define LOG_TAG "OMX-VDEC-720P" 67 #elif MAX_RES_1080P 68 #define LOG_TAG "OMX-VDEC-1080P" 69 #else 70 #define LOG_TAG "OMX-VDEC" 71 #endif 72 #ifdef ENABLE_DEBUG_LOW 73 #define DEBUG_PRINT_LOW ALOGE 74 #else 75 #define DEBUG_PRINT_LOW 76 #endif 77 #ifdef ENABLE_DEBUG_HIGH 78 #define DEBUG_PRINT_HIGH ALOGE 79 #else 80 #define DEBUG_PRINT_HIGH 81 #endif 82 #ifdef ENABLE_DEBUG_ERROR 83 #define DEBUG_PRINT_ERROR ALOGE 84 #else 85 #define DEBUG_PRINT_ERROR 86 #endif 87 88 #else //_ANDROID_ 89 #define DEBUG_PRINT_LOW printf 90 #define DEBUG_PRINT_HIGH printf 91 #define DEBUG_PRINT_ERROR printf 92 #endif // _ANDROID_ 93 94 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 95 #include <media/hardware/HardwareAPI.h> 96 #endif 97 98 #include <unistd.h> 99 100 #if defined (_ANDROID_ICS_) 101 #include <IQService.h> 102 #endif 103 104 #include <pthread.h> 105 #ifndef PC_DEBUG 106 #include <semaphore.h> 107 #endif 108 #include "OMX_Core.h" 109 #include "OMX_QCOMExtns.h" 110 #include "qc_omx_component.h" 111 #include <linux/msm_vidc_dec.h> 112 #include "frameparser.h" 113 #ifdef MAX_RES_1080P 114 #include "mp4_utils.h" 115 #endif 116 #include "extra_data_handler.h" 117 #include "ts_parser.h" 118 #include "vidc_color_converter.h" 119 extern "C" { 120 OMX_API void * get_omx_component_factory_fn(void); 121 } 122 123 #ifdef _ANDROID_ 124 using namespace android; 125 #ifdef USE_ION 126 class VideoHeap : public MemoryHeapBase 127 { 128 public: 129 VideoHeap(int devicefd, size_t size, void* base,struct ion_handle *handle,int mapfd); ~VideoHeap()130 virtual ~VideoHeap() {} 131 private: 132 int m_ion_device_fd; 133 struct ion_handle *m_ion_handle; 134 }; 135 #else 136 // local pmem heap object 137 class VideoHeap : public MemoryHeapBase 138 { 139 public: 140 VideoHeap(int fd, size_t size, void* base); ~VideoHeap()141 virtual ~VideoHeap() {} 142 }; 143 #endif 144 #endif // _ANDROID_ 145 ////////////////////////////////////////////////////////////////////////////// 146 // Module specific globals 147 ////////////////////////////////////////////////////////////////////////////// 148 #define OMX_SPEC_VERSION 0x00000101 149 150 151 ////////////////////////////////////////////////////////////////////////////// 152 // Macros 153 ////////////////////////////////////////////////////////////////////////////// 154 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\ 155 (unsigned) bufHdr,\ 156 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\ 157 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\ 158 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp) 159 160 // BitMask Management logic 161 #define BITS_PER_BYTE 32 162 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_BYTE - 1)/BITS_PER_BYTE) 163 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_BYTE) 164 #define BITMASK_FLAG(mIndex) (1 << ((mIndex) % BITS_PER_BYTE)) 165 #define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 166 &= ~(BITMASK_FLAG(mIndex)) 167 #define BITMASK_SET(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 168 |= BITMASK_FLAG(mIndex) 169 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 170 & BITMASK_FLAG(mIndex)) 171 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 172 & BITMASK_FLAG(mIndex)) == 0x0) 173 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 174 & BITMASK_FLAG(mIndex)) 175 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 176 & BITMASK_FLAG(mIndex)) == 0x0) 177 178 #define OMX_CORE_CONTROL_CMDQ_SIZE 100 179 #define OMX_CORE_QCIF_HEIGHT 144 180 #define OMX_CORE_QCIF_WIDTH 176 181 #define OMX_CORE_VGA_HEIGHT 480 182 #define OMX_CORE_VGA_WIDTH 640 183 #define OMX_CORE_WVGA_HEIGHT 480 184 #define OMX_CORE_WVGA_WIDTH 800 185 186 #define DESC_BUFFER_SIZE (8192 * 16) 187 188 #ifdef _ANDROID_ 189 #define MAX_NUM_INPUT_OUTPUT_BUFFERS 32 190 #endif 191 192 #define OMX_FRAMEINFO_EXTRADATA 0x00010000 193 #define OMX_INTERLACE_EXTRADATA 0x00020000 194 #define OMX_TIMEINFO_EXTRADATA 0x00040000 195 #define OMX_PORTDEF_EXTRADATA 0x00080000 196 #define DRIVER_EXTRADATA_MASK 0x0000FFFF 197 198 #define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 199 sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3)) 200 #define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 201 sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3)) 202 #define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 203 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3)) 204 205 // Define next macro with required values to enable default extradata, 206 // VDEC_EXTRADATA_MB_ERROR_MAP 207 // OMX_INTERLACE_EXTRADATA 208 // OMX_FRAMEINFO_EXTRADATA 209 // OMX_TIMEINFO_EXTRADATA 210 211 //#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA) 212 213 enum port_indexes 214 { 215 OMX_CORE_INPUT_PORT_INDEX =0, 216 OMX_CORE_OUTPUT_PORT_INDEX =1 217 }; 218 #ifdef USE_ION 219 struct vdec_ion 220 { 221 int ion_device_fd; 222 struct ion_fd_data fd_ion_data; 223 struct ion_allocation_data ion_alloc_data; 224 }; 225 #endif 226 227 struct video_driver_context 228 { 229 int video_driver_fd; 230 enum vdec_codec decoder_format; 231 enum vdec_output_fromat output_format; 232 enum vdec_interlaced_format interlace; 233 enum vdec_output_order picture_order; 234 struct vdec_picsize video_resolution; 235 struct vdec_allocatorproperty ip_buf; 236 struct vdec_allocatorproperty op_buf; 237 struct vdec_bufferpayload *ptr_inputbuffer; 238 struct vdec_bufferpayload *ptr_outputbuffer; 239 struct vdec_output_frameinfo *ptr_respbuffer; 240 #ifdef USE_ION 241 struct vdec_ion *ip_buf_ion_info; 242 struct vdec_ion *op_buf_ion_info; 243 struct vdec_ion h264_mv; 244 #endif 245 struct vdec_framerate frame_rate; 246 unsigned extradata; 247 bool timestamp_adjust; 248 char kind[128]; 249 bool idr_only_decoding; 250 unsigned disable_dmx; 251 }; 252 253 #ifdef _ANDROID_ 254 class DivXDrmDecrypt; 255 #endif //_ANDROID_ 256 257 // OMX video decoder class 258 class omx_vdec: public qc_omx_component 259 { 260 261 public: 262 omx_vdec(); // constructor 263 virtual ~omx_vdec(); // destructor 264 265 static int async_message_process (void *context, void* message); 266 static void process_event_cb(void *ctxt,unsigned char id); 267 268 OMX_ERRORTYPE allocate_buffer( 269 OMX_HANDLETYPE hComp, 270 OMX_BUFFERHEADERTYPE **bufferHdr, 271 OMX_U32 port, 272 OMX_PTR appData, 273 OMX_U32 bytes 274 ); 275 276 277 OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp); 278 279 OMX_ERRORTYPE component_init(OMX_STRING role); 280 281 OMX_ERRORTYPE component_role_enum( 282 OMX_HANDLETYPE hComp, 283 OMX_U8 *role, 284 OMX_U32 index 285 ); 286 287 OMX_ERRORTYPE component_tunnel_request( 288 OMX_HANDLETYPE hComp, 289 OMX_U32 port, 290 OMX_HANDLETYPE peerComponent, 291 OMX_U32 peerPort, 292 OMX_TUNNELSETUPTYPE *tunnelSetup 293 ); 294 295 OMX_ERRORTYPE empty_this_buffer( 296 OMX_HANDLETYPE hComp, 297 OMX_BUFFERHEADERTYPE *buffer 298 ); 299 300 301 302 OMX_ERRORTYPE fill_this_buffer( 303 OMX_HANDLETYPE hComp, 304 OMX_BUFFERHEADERTYPE *buffer 305 ); 306 307 308 OMX_ERRORTYPE free_buffer( 309 OMX_HANDLETYPE hComp, 310 OMX_U32 port, 311 OMX_BUFFERHEADERTYPE *buffer 312 ); 313 314 OMX_ERRORTYPE get_component_version( 315 OMX_HANDLETYPE hComp, 316 OMX_STRING componentName, 317 OMX_VERSIONTYPE *componentVersion, 318 OMX_VERSIONTYPE *specVersion, 319 OMX_UUIDTYPE *componentUUID 320 ); 321 322 OMX_ERRORTYPE get_config( 323 OMX_HANDLETYPE hComp, 324 OMX_INDEXTYPE configIndex, 325 OMX_PTR configData 326 ); 327 328 OMX_ERRORTYPE get_extension_index( 329 OMX_HANDLETYPE hComp, 330 OMX_STRING paramName, 331 OMX_INDEXTYPE *indexType 332 ); 333 334 OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp, 335 OMX_INDEXTYPE paramIndex, 336 OMX_PTR paramData); 337 338 OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp, 339 OMX_STATETYPE *state); 340 341 342 343 OMX_ERRORTYPE send_command(OMX_HANDLETYPE hComp, 344 OMX_COMMANDTYPE cmd, 345 OMX_U32 param1, 346 OMX_PTR cmdData); 347 348 349 OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE hComp, 350 OMX_CALLBACKTYPE *callbacks, 351 OMX_PTR appData); 352 353 OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp, 354 OMX_INDEXTYPE configIndex, 355 OMX_PTR configData); 356 357 OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp, 358 OMX_INDEXTYPE paramIndex, 359 OMX_PTR paramData); 360 361 OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE hComp, 362 OMX_BUFFERHEADERTYPE **bufferHdr, 363 OMX_U32 port, 364 OMX_PTR appData, 365 OMX_U32 bytes, 366 OMX_U8 *buffer); 367 368 OMX_ERRORTYPE use_input_heap_buffers( 369 OMX_HANDLETYPE hComp, 370 OMX_BUFFERHEADERTYPE** bufferHdr, 371 OMX_U32 port, 372 OMX_PTR appData, 373 OMX_U32 bytes, 374 OMX_U8* buffer); 375 376 OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE hComp, 377 OMX_BUFFERHEADERTYPE **bufferHdr, 378 OMX_U32 port, 379 OMX_PTR appData, 380 void * eglImage); 381 void complete_pending_buffer_done_cbs(); 382 void update_resolution(int width, int height); 383 struct video_driver_context drv_ctx; 384 int m_pipe_in; 385 int m_pipe_out; 386 pthread_t msg_thread_id; 387 pthread_t async_thread_id; 388 bool is_component_secure(); 389 390 private: 391 // Bit Positions 392 enum flags_bit_positions 393 { 394 // Defer transition to IDLE 395 OMX_COMPONENT_IDLE_PENDING =0x1, 396 // Defer transition to LOADING 397 OMX_COMPONENT_LOADING_PENDING =0x2, 398 // First Buffer Pending 399 OMX_COMPONENT_FIRST_BUFFER_PENDING =0x3, 400 // Second Buffer Pending 401 OMX_COMPONENT_SECOND_BUFFER_PENDING =0x4, 402 // Defer transition to Enable 403 OMX_COMPONENT_INPUT_ENABLE_PENDING =0x5, 404 // Defer transition to Enable 405 OMX_COMPONENT_OUTPUT_ENABLE_PENDING =0x6, 406 // Defer transition to Disable 407 OMX_COMPONENT_INPUT_DISABLE_PENDING =0x7, 408 // Defer transition to Disable 409 OMX_COMPONENT_OUTPUT_DISABLE_PENDING =0x8, 410 //defer flush notification 411 OMX_COMPONENT_OUTPUT_FLUSH_PENDING =0x9, 412 OMX_COMPONENT_INPUT_FLUSH_PENDING =0xA, 413 OMX_COMPONENT_PAUSE_PENDING =0xB, 414 OMX_COMPONENT_EXECUTE_PENDING =0xC, 415 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD, 416 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE 417 }; 418 419 // Deferred callback identifiers 420 enum 421 { 422 //Event Callbacks from the vdec component thread context 423 OMX_COMPONENT_GENERATE_EVENT = 0x1, 424 //Buffer Done callbacks from the vdec component thread context 425 OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2, 426 //Frame Done callbacks from the vdec component thread context 427 OMX_COMPONENT_GENERATE_FRAME_DONE = 0x3, 428 //Buffer Done callbacks from the vdec component thread context 429 OMX_COMPONENT_GENERATE_FTB = 0x4, 430 //Frame Done callbacks from the vdec component thread context 431 OMX_COMPONENT_GENERATE_ETB = 0x5, 432 //Command 433 OMX_COMPONENT_GENERATE_COMMAND = 0x6, 434 //Push-Pending Buffers 435 OMX_COMPONENT_PUSH_PENDING_BUFS = 0x7, 436 // Empty Buffer Done callbacks 437 OMX_COMPONENT_GENERATE_EBD = 0x8, 438 //Flush Event Callbacks from the vdec component thread context 439 OMX_COMPONENT_GENERATE_EVENT_FLUSH = 0x9, 440 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A, 441 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B, 442 OMX_COMPONENT_GENERATE_FBD = 0xc, 443 OMX_COMPONENT_GENERATE_START_DONE = 0xD, 444 OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE, 445 OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF, 446 OMX_COMPONENT_GENERATE_STOP_DONE = 0x10, 447 OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11, 448 OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12, 449 OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13, 450 OMX_COMPONENT_GENERATE_EOS_DONE = 0x14, 451 OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15, 452 OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16, 453 }; 454 455 enum vc1_profile_type 456 { 457 VC1_SP_MP_RCV = 1, 458 VC1_AP = 2 459 }; 460 461 #ifdef _COPPER_ 462 enum v4l2_ports 463 { 464 CAPTURE_PORT, 465 OUTPUT_PORT, 466 MAX_PORT 467 }; 468 #endif 469 470 struct omx_event 471 { 472 unsigned param1; 473 unsigned param2; 474 unsigned id; 475 }; 476 477 struct omx_cmd_queue 478 { 479 omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE]; 480 unsigned m_read; 481 unsigned m_write; 482 unsigned m_size; 483 484 omx_cmd_queue(); 485 ~omx_cmd_queue(); 486 bool insert_entry(unsigned p1, unsigned p2, unsigned id); 487 bool pop_entry(unsigned *p1,unsigned *p2, unsigned *id); 488 // get msgtype of the first ele from the queue 489 unsigned get_q_msg_type(); 490 491 }; 492 493 #ifdef _ANDROID_ 494 struct ts_entry 495 { 496 OMX_TICKS timestamp; 497 bool valid; 498 }; 499 500 struct ts_arr_list 501 { 502 ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS]; 503 504 ts_arr_list(); 505 ~ts_arr_list(); 506 507 bool insert_ts(OMX_TICKS ts); 508 bool pop_min_ts(OMX_TICKS &ts); 509 bool reset_ts_list(); 510 }; 511 #endif 512 513 struct desc_buffer_hdr 514 { 515 OMX_U8 *buf_addr; 516 OMX_U32 desc_data_size; 517 }; 518 bool allocate_done(void); 519 bool allocate_input_done(void); 520 bool allocate_output_done(void); 521 522 OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 523 OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex, 524 OMX_BUFFERHEADERTYPE *pmem_bufferHdr); 525 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 526 void free_output_buffer_header(); 527 void free_input_buffer_header(); 528 OMX_ERRORTYPE update_color_format(OMX_COLOR_FORMATTYPE eColorFormat); 529 OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE hComp, 530 OMX_BUFFERHEADERTYPE **bufferHdr, 531 OMX_U32 port, 532 OMX_PTR appData, 533 OMX_U32 bytes); 534 535 536 OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE hComp, 537 OMX_BUFFERHEADERTYPE **bufferHdr, 538 OMX_U32 port, 539 OMX_PTR appData, 540 OMX_U32 bytes); 541 542 OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE hComp, 543 OMX_BUFFERHEADERTYPE **bufferHdr, 544 OMX_U32 port,OMX_PTR appData, 545 OMX_U32 bytes); 546 OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp, 547 OMX_BUFFERHEADERTYPE **bufferHdr, 548 OMX_U32 port, 549 OMX_PTR appData, 550 OMX_U32 bytes, 551 OMX_U8 *buffer); 552 553 #ifdef MAX_RES_720P 554 OMX_ERRORTYPE get_supported_profile_level_for_720p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType); 555 #endif 556 #ifdef MAX_RES_1080P 557 OMX_ERRORTYPE get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType); 558 #endif 559 560 OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index); 561 OMX_ERRORTYPE allocate_output_headers(); 562 bool execute_omx_flush(OMX_U32); 563 bool execute_output_flush(); 564 bool execute_input_flush(); 565 OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp, 566 OMX_BUFFERHEADERTYPE * buffer); 567 568 OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp, 569 OMX_BUFFERHEADERTYPE * buffer); 570 OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE hComp, 571 OMX_BUFFERHEADERTYPE *buffer); 572 573 OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp, 574 OMX_BUFFERHEADERTYPE *buffer 575 ); 576 577 OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp); 578 OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp); 579 OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp); 580 OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp); 581 582 OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE hComp, 583 OMX_BUFFERHEADERTYPE *buffer); 584 bool release_done(); 585 586 bool release_output_done(); 587 bool release_input_done(); 588 OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop); 589 OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop); 590 OMX_ERRORTYPE start_port_reconfig(); 591 OMX_ERRORTYPE update_picture_resolution(); 592 void stream_off(); 593 void adjust_timestamp(OMX_S64 &act_timestamp); 594 void set_frame_rate(OMX_S64 act_timestamp); 595 void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr); 596 OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true); 597 void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra); 598 void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, 599 OMX_U32 interlaced_format_type); 600 void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, 601 OMX_U32 num_conceal_mb, 602 OMX_U32 picture_type, 603 OMX_S64 timestamp, 604 OMX_U32 frame_rate, 605 struct vdec_aspectratioinfo *aspect_ratio_info); 606 void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info, 607 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info); 608 void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra); 609 OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn); 610 void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra); 611 void insert_demux_addr_offset(OMX_U32 address_offset); 612 void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr); 613 OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr); 614 OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra); 615 616 #ifdef USE_ION 617 int alloc_map_ion_memory(OMX_U32 buffer_size, 618 OMX_U32 alignment, struct ion_allocation_data *alloc_data, 619 struct ion_fd_data *fd_data,int flag); 620 void free_ion_memory(struct vdec_ion *buf_ion_info); 621 #else 622 bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size, 623 OMX_U32 alignment); 624 #endif 625 626 627 OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE hComp, 628 OMX_COMMANDTYPE cmd, 629 OMX_U32 param1, 630 OMX_PTR cmdData); 631 bool post_event( unsigned int p1, 632 unsigned int p2, 633 unsigned int id 634 ); clip2(int x)635 inline int clip2(int x) 636 { 637 x = x -1; 638 x = x | x >> 1; 639 x = x | x >> 2; 640 x = x | x >> 4; 641 x = x | x >> 16; 642 x = x + 1; 643 return x; 644 } 645 646 #ifdef MAX_RES_1080P 647 OMX_ERRORTYPE vdec_alloc_h264_mv(); 648 void vdec_dealloc_h264_mv(); 649 #endif 650 omx_report_error()651 inline void omx_report_error () 652 { 653 if (m_cb.EventHandler && !m_error_propogated) 654 { 655 ALOGE("\nERROR: Sending OMX_EventError to Client"); 656 m_error_propogated = true; 657 m_cb.EventHandler(&m_cmp,m_app_data, 658 OMX_EventError,OMX_ErrorHardware,0,NULL); 659 } 660 } 661 #ifdef _ANDROID_ 662 OMX_ERRORTYPE createDivxDrmContext(); 663 #endif //_ANDROID_ 664 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 665 OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data); 666 #endif 667 668 //************************************************************* 669 //*******************MEMBER VARIABLES ************************* 670 //************************************************************* 671 pthread_mutex_t m_lock; 672 pthread_mutex_t c_lock; 673 //sem to handle the minimum procesing of commands 674 sem_t m_cmd_lock; 675 bool m_error_propogated; 676 // compression format 677 OMX_VIDEO_CODINGTYPE eCompressionFormat; 678 // OMX State 679 OMX_STATETYPE m_state; 680 // Application data 681 OMX_PTR m_app_data; 682 // Application callbacks 683 OMX_CALLBACKTYPE m_cb; 684 OMX_PRIORITYMGMTTYPE m_priority_mgm ; 685 OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier; 686 // fill this buffer queue 687 omx_cmd_queue m_ftb_q; 688 // Command Q for rest of the events 689 omx_cmd_queue m_cmd_q; 690 omx_cmd_queue m_etb_q; 691 // Input memory pointer 692 OMX_BUFFERHEADERTYPE *m_inp_mem_ptr; 693 // Output memory pointer 694 OMX_BUFFERHEADERTYPE *m_out_mem_ptr; 695 // number of input bitstream error frame count 696 unsigned int m_inp_err_count; 697 #ifdef _ANDROID_ 698 // Timestamp list 699 ts_arr_list m_timestamp_list; 700 #endif 701 702 bool input_flush_progress; 703 bool output_flush_progress; 704 bool input_use_buffer; 705 bool output_use_buffer; 706 bool ouput_egl_buffers; 707 OMX_BOOL m_use_output_pmem; 708 OMX_BOOL m_out_mem_region_smi; 709 OMX_BOOL m_out_pvt_entry_pmem; 710 711 int pending_input_buffers; 712 int pending_output_buffers; 713 // bitmask array size for output side 714 unsigned int m_out_bm_count; 715 // bitmask array size for input side 716 unsigned int m_inp_bm_count; 717 //Input port Populated 718 OMX_BOOL m_inp_bPopulated; 719 //Output port Populated 720 OMX_BOOL m_out_bPopulated; 721 // encapsulate the waiting states. 722 unsigned int m_flags; 723 724 #ifdef _ANDROID_ 725 // Heap pointer to frame buffers 726 struct vidc_heap 727 { 728 sp<MemoryHeapBase> video_heap_ptr; 729 }; 730 struct vidc_heap *m_heap_ptr; 731 unsigned int m_heap_count; 732 #endif //_ANDROID_ 733 // store I/P PORT state 734 OMX_BOOL m_inp_bEnabled; 735 // store O/P PORT state 736 OMX_BOOL m_out_bEnabled; 737 OMX_U32 m_in_alloc_cnt; 738 OMX_U8 m_cRole[OMX_MAX_STRINGNAME_SIZE]; 739 // Platform specific details 740 OMX_QCOM_PLATFORM_PRIVATE_LIST *m_platform_list; 741 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *m_platform_entry; 742 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info; 743 // SPS+PPS sent as part of set_config 744 OMX_VENDOR_EXTRADATATYPE m_vendor_config; 745 746 /*Variables for arbitrary Byte parsing support*/ 747 frame_parse m_frame_parser; 748 omx_cmd_queue m_input_pending_q; 749 omx_cmd_queue m_input_free_q; 750 bool arbitrary_bytes; 751 OMX_BUFFERHEADERTYPE h264_scratch; 752 OMX_BUFFERHEADERTYPE *psource_frame; 753 OMX_BUFFERHEADERTYPE *pdest_frame; 754 OMX_BUFFERHEADERTYPE *m_inp_heap_ptr; 755 OMX_BUFFERHEADERTYPE **m_phdr_pmem_ptr; 756 unsigned int m_heap_inp_bm_count; 757 codec_type codec_type_parse; 758 bool first_frame_meta; 759 unsigned frame_count; 760 unsigned nal_count; 761 unsigned nal_length; 762 bool look_ahead_nal; 763 int first_frame; 764 unsigned char *first_buffer; 765 int first_frame_size; 766 unsigned char m_hwdevice_name[80]; 767 FILE *m_device_file_ptr; 768 enum vc1_profile_type m_vc1_profile; 769 OMX_S64 h264_last_au_ts; 770 OMX_U32 h264_last_au_flags; 771 OMX_U32 m_demux_offsets[8192]; 772 OMX_U32 m_demux_entries; 773 774 OMX_S64 prev_ts; 775 bool rst_prev_ts; 776 OMX_U32 frm_int; 777 778 struct vdec_allocatorproperty op_buf_rcnfg; 779 bool in_reconfig; 780 OMX_NATIVE_WINDOWTYPE m_display_id; 781 h264_stream_parser *h264_parser; 782 OMX_U32 client_extradata; 783 #ifdef _ANDROID_ 784 bool m_debug_timestamp; 785 bool perf_flag; 786 OMX_U32 proc_frms, latency; 787 perf_metrics fps_metrics; 788 perf_metrics dec_time; 789 bool m_enable_android_native_buffers; 790 bool m_use_android_native_buffers; 791 bool m_debug_extradata; 792 bool m_debug_concealedmb; 793 #endif 794 #ifdef MAX_RES_1080P 795 MP4_Utils mp4_headerparser; 796 #endif 797 798 struct h264_mv_buffer{ 799 unsigned char* buffer; 800 int size; 801 int count; 802 int pmem_fd; 803 int offset; 804 }; 805 h264_mv_buffer h264_mv_buff; 806 extra_data_handler extra_data_handle; 807 #ifdef _ANDROID_ 808 DivXDrmDecrypt* iDivXDrmDecrypt; 809 #endif //_ANDROID_ 810 OMX_PARAM_PORTDEFINITIONTYPE m_port_def; 811 omx_time_stamp_reorder time_stamp_dts; 812 desc_buffer_hdr *m_desc_buffer_ptr; 813 bool secure_mode; 814 OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata; 815 bool codec_config_flag; 816 OMX_CONFIG_RECTTYPE rectangle; 817 #ifdef _COPPER_ 818 int capture_capability; 819 int output_capability; 820 bool streaming[MAX_PORT]; 821 #endif 822 823 // added for smooth streaming 824 private_handle_t * native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS]; 825 bool m_use_smoothstreaming; 826 OMX_U32 m_smoothstreaming_height; 827 OMX_U32 m_smoothstreaming_width; 828 829 unsigned int m_fill_output_msg; 830 class allocate_color_convert_buf { 831 public: 832 allocate_color_convert_buf(); 833 ~allocate_color_convert_buf(); 834 void set_vdec_client(void *); 835 void update_client(); 836 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format); 837 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format); 838 bool update_buffer_req(); 839 bool get_buffer_req(unsigned int &buffer_size); 840 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(); 841 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr); 842 OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr); 843 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header); 844 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header); 845 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp, 846 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData, 847 OMX_U32 bytes); 848 OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp, 849 OMX_BUFFERHEADERTYPE **bufferHdr, OMX_U32 port, OMX_PTR appData, 850 OMX_U32 bytes, OMX_U8 *buffer); 851 852 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); enable_native_buffers(bool enable)853 void enable_native_buffers(bool enable) {m_native_buffers_enabled = enable;} 854 OMX_U32 get_output_stride(); 855 OMX_U32 get_output_scanlines(); 856 private: 857 #define MAX_COUNT 32 858 omx_vdec *omx; 859 bool enabled; 860 bool m_native_buffers_enabled; 861 OMX_COLOR_FORMATTYPE ColorFormat; 862 void init_members(); 863 bool color_convert_mode; 864 ColorConvertFormat dest_format; 865 class omx_c2d_conv c2d; 866 unsigned int allocated_count; 867 unsigned int buffer_size_req; 868 unsigned int buffer_alignment_req; 869 OMX_QCOM_PLATFORM_PRIVATE_LIST m_platform_list_client[MAX_COUNT]; 870 OMX_QCOM_PLATFORM_PRIVATE_ENTRY m_platform_entry_client[MAX_COUNT]; 871 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT]; 872 OMX_BUFFERHEADERTYPE m_out_mem_ptr_client[MAX_COUNT]; 873 struct vdec_ion op_buf_ion_info[MAX_COUNT]; 874 unsigned char *pmem_baseaddress[MAX_COUNT]; 875 int pmem_fd[MAX_COUNT]; 876 struct vidc_heap 877 { 878 sp<MemoryHeapBase> video_heap_ptr; 879 }; 880 struct vidc_heap m_heap_ptr[MAX_COUNT]; 881 }; 882 allocate_color_convert_buf client_buffers; 883 static bool m_secure_display; //For qservice 884 int secureDisplay(int mode); 885 int unsecureDisplay(int mode); 886 }; 887 888 #ifdef _COPPER_ 889 enum instance_state { 890 MSM_VIDC_CORE_UNINIT_DONE = 0x0001, 891 MSM_VIDC_CORE_INIT, 892 MSM_VIDC_CORE_INIT_DONE, 893 MSM_VIDC_OPEN, 894 MSM_VIDC_OPEN_DONE, 895 MSM_VIDC_LOAD_RESOURCES, 896 MSM_VIDC_LOAD_RESOURCES_DONE, 897 MSM_VIDC_START, 898 MSM_VIDC_START_DONE, 899 MSM_VIDC_STOP, 900 MSM_VIDC_STOP_DONE, 901 MSM_VIDC_RELEASE_RESOURCES, 902 MSM_VIDC_RELEASE_RESOURCES_DONE, 903 MSM_VIDC_CLOSE, 904 MSM_VIDC_CLOSE_DONE, 905 MSM_VIDC_CORE_UNINIT, 906 }; 907 908 enum vidc_resposes_id { 909 MSM_VIDC_DECODER_FLUSH_DONE = 0x11, 910 MSM_VIDC_DECODER_EVENT_CHANGE, 911 }; 912 913 #endif // _COPPER_ 914 915 #endif // __OMX_VDEC_H__ 916