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 49 static ptrdiff_t x; 50 51 #ifdef _ANDROID_ 52 #ifdef USE_ION 53 #include <linux/msm_ion.h> 54 #else 55 #include <linux/android_pmem.h> 56 #endif 57 #include <binder/MemoryHeapBase.h> 58 #include <ui/ANativeObjectBase.h> 59 #include <binder/IServiceManager.h> 60 extern "C"{ 61 #include<utils/Log.h> 62 } 63 #include <linux/videodev2.h> 64 #include <poll.h> 65 #define TIMEOUT 5000 66 #ifdef MAX_RES_720P 67 #define LOG_TAG "OMX-VDEC-720P" 68 #elif MAX_RES_1080P 69 #define LOG_TAG "OMX-VDEC-1080P" 70 #else 71 #define LOG_TAG "OMX-VDEC" 72 #endif 73 #ifdef ENABLE_DEBUG_LOW 74 #define DEBUG_PRINT_LOW ALOGE 75 #else 76 #define DEBUG_PRINT_LOW 77 #endif 78 #ifdef ENABLE_DEBUG_HIGH 79 #define DEBUG_PRINT_HIGH ALOGE 80 #else 81 #define DEBUG_PRINT_HIGH 82 #endif 83 #ifdef ENABLE_DEBUG_ERROR 84 #define DEBUG_PRINT_ERROR ALOGE 85 #else 86 #define DEBUG_PRINT_ERROR 87 #endif 88 89 #else //_ANDROID_ 90 #define DEBUG_PRINT_LOW printf 91 #define DEBUG_PRINT_HIGH printf 92 #define DEBUG_PRINT_ERROR printf 93 #endif // _ANDROID_ 94 95 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 96 #include <media/hardware/HardwareAPI.h> 97 #endif 98 99 #include <unistd.h> 100 101 #if defined (_ANDROID_ICS_) 102 #include <IQService.h> 103 #endif 104 105 #include <pthread.h> 106 #ifndef PC_DEBUG 107 #include <semaphore.h> 108 #endif 109 #include "OMX_Core.h" 110 #include "OMX_QCOMExtns.h" 111 #include "qc_omx_component.h" 112 #include <linux/msm_vidc_dec.h> 113 #include "frameparser.h" 114 #ifdef MAX_RES_1080P 115 #include "mp4_utils.h" 116 #endif 117 #include "extra_data_handler.h" 118 #include "ts_parser.h" 119 #include "vidc_color_converter.h" 120 extern "C" { 121 OMX_API void * get_omx_component_factory_fn(void); 122 } 123 124 #ifdef _ANDROID_ 125 using namespace android; 126 #ifdef USE_ION 127 class VideoHeap : public MemoryHeapBase 128 { 129 public: 130 VideoHeap(int devicefd, size_t size, void* base,struct ion_handle *handle,int mapfd); ~VideoHeap()131 virtual ~VideoHeap() {} 132 private: 133 int m_ion_device_fd; 134 struct ion_handle *m_ion_handle; 135 }; 136 #else 137 // local pmem heap object 138 class VideoHeap : public MemoryHeapBase 139 { 140 public: 141 VideoHeap(int fd, size_t size, void* base); ~VideoHeap()142 virtual ~VideoHeap() {} 143 }; 144 #endif 145 #endif // _ANDROID_ 146 ////////////////////////////////////////////////////////////////////////////// 147 // Module specific globals 148 ////////////////////////////////////////////////////////////////////////////// 149 #define OMX_SPEC_VERSION 0x00000101 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_BYTE 32 163 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_BYTE - 1)/BITS_PER_BYTE) 164 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_BYTE) 165 #define BITMASK_FLAG(mIndex) (1 << ((mIndex) % BITS_PER_BYTE)) 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 32 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 DRIVER_EXTRADATA_MASK 0x0000FFFF 198 199 #define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 200 sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3)) 201 #define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 202 sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3)) 203 #define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\ 204 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3)) 205 206 // Define next macro with required values to enable default extradata, 207 // VDEC_EXTRADATA_MB_ERROR_MAP 208 // OMX_INTERLACE_EXTRADATA 209 // OMX_FRAMEINFO_EXTRADATA 210 // OMX_TIMEINFO_EXTRADATA 211 212 //#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA) 213 214 enum port_indexes 215 { 216 OMX_CORE_INPUT_PORT_INDEX =0, 217 OMX_CORE_OUTPUT_PORT_INDEX =1 218 }; 219 #ifdef USE_ION 220 struct vdec_ion 221 { 222 int ion_device_fd; 223 struct ion_fd_data fd_ion_data; 224 struct ion_allocation_data ion_alloc_data; 225 }; 226 #endif 227 228 struct video_driver_context 229 { 230 int video_driver_fd; 231 enum vdec_codec decoder_format; 232 enum vdec_output_fromat output_format; 233 enum vdec_interlaced_format interlace; 234 enum vdec_output_order picture_order; 235 struct vdec_picsize video_resolution; 236 struct vdec_allocatorproperty ip_buf; 237 struct vdec_allocatorproperty op_buf; 238 struct vdec_bufferpayload *ptr_inputbuffer; 239 struct vdec_bufferpayload *ptr_outputbuffer; 240 struct vdec_output_frameinfo *ptr_respbuffer; 241 #ifdef USE_ION 242 struct vdec_ion *ip_buf_ion_info; 243 struct vdec_ion *op_buf_ion_info; 244 struct vdec_ion h264_mv; 245 #endif 246 struct vdec_framerate frame_rate; 247 unsigned extradata; 248 bool timestamp_adjust; 249 char kind[128]; 250 bool idr_only_decoding; 251 unsigned disable_dmx; 252 }; 253 254 #ifdef _ANDROID_ 255 class DivXDrmDecrypt; 256 #endif //_ANDROID_ 257 258 // OMX video decoder class 259 class omx_vdec: public qc_omx_component 260 { 261 262 public: 263 omx_vdec(); // constructor 264 virtual ~omx_vdec(); // destructor 265 266 static int async_message_process (void *context, void* message); 267 static void process_event_cb(void *ctxt,unsigned char id); 268 269 OMX_ERRORTYPE allocate_buffer( 270 OMX_HANDLETYPE hComp, 271 OMX_BUFFERHEADERTYPE **bufferHdr, 272 OMX_U32 port, 273 OMX_PTR appData, 274 OMX_U32 bytes 275 ); 276 277 278 OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp); 279 280 OMX_ERRORTYPE component_init(OMX_STRING role); 281 282 OMX_ERRORTYPE component_role_enum( 283 OMX_HANDLETYPE hComp, 284 OMX_U8 *role, 285 OMX_U32 index 286 ); 287 288 OMX_ERRORTYPE component_tunnel_request( 289 OMX_HANDLETYPE hComp, 290 OMX_U32 port, 291 OMX_HANDLETYPE peerComponent, 292 OMX_U32 peerPort, 293 OMX_TUNNELSETUPTYPE *tunnelSetup 294 ); 295 296 OMX_ERRORTYPE empty_this_buffer( 297 OMX_HANDLETYPE hComp, 298 OMX_BUFFERHEADERTYPE *buffer 299 ); 300 301 302 303 OMX_ERRORTYPE fill_this_buffer( 304 OMX_HANDLETYPE hComp, 305 OMX_BUFFERHEADERTYPE *buffer 306 ); 307 308 309 OMX_ERRORTYPE free_buffer( 310 OMX_HANDLETYPE hComp, 311 OMX_U32 port, 312 OMX_BUFFERHEADERTYPE *buffer 313 ); 314 315 OMX_ERRORTYPE get_component_version( 316 OMX_HANDLETYPE hComp, 317 OMX_STRING componentName, 318 OMX_VERSIONTYPE *componentVersion, 319 OMX_VERSIONTYPE *specVersion, 320 OMX_UUIDTYPE *componentUUID 321 ); 322 323 OMX_ERRORTYPE get_config( 324 OMX_HANDLETYPE hComp, 325 OMX_INDEXTYPE configIndex, 326 OMX_PTR configData 327 ); 328 329 OMX_ERRORTYPE get_extension_index( 330 OMX_HANDLETYPE hComp, 331 OMX_STRING paramName, 332 OMX_INDEXTYPE *indexType 333 ); 334 335 OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp, 336 OMX_INDEXTYPE paramIndex, 337 OMX_PTR paramData); 338 339 OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp, 340 OMX_STATETYPE *state); 341 342 343 344 OMX_ERRORTYPE send_command(OMX_HANDLETYPE hComp, 345 OMX_COMMANDTYPE cmd, 346 OMX_U32 param1, 347 OMX_PTR cmdData); 348 349 350 OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE hComp, 351 OMX_CALLBACKTYPE *callbacks, 352 OMX_PTR appData); 353 354 OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp, 355 OMX_INDEXTYPE configIndex, 356 OMX_PTR configData); 357 358 OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp, 359 OMX_INDEXTYPE paramIndex, 360 OMX_PTR paramData); 361 362 OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE hComp, 363 OMX_BUFFERHEADERTYPE **bufferHdr, 364 OMX_U32 port, 365 OMX_PTR appData, 366 OMX_U32 bytes, 367 OMX_U8 *buffer); 368 369 OMX_ERRORTYPE use_input_heap_buffers( 370 OMX_HANDLETYPE hComp, 371 OMX_BUFFERHEADERTYPE** bufferHdr, 372 OMX_U32 port, 373 OMX_PTR appData, 374 OMX_U32 bytes, 375 OMX_U8* buffer); 376 377 OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE hComp, 378 OMX_BUFFERHEADERTYPE **bufferHdr, 379 OMX_U32 port, 380 OMX_PTR appData, 381 void * eglImage); 382 void complete_pending_buffer_done_cbs(); 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 #ifdef MAX_RES_720P 553 OMX_ERRORTYPE get_supported_profile_level_for_720p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType); 554 #endif 555 #ifdef MAX_RES_1080P 556 OMX_ERRORTYPE get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType); 557 #endif 558 559 OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index); 560 OMX_ERRORTYPE allocate_output_headers(); 561 bool execute_omx_flush(OMX_U32); 562 bool execute_output_flush(); 563 bool execute_input_flush(); 564 OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp, 565 OMX_BUFFERHEADERTYPE * buffer); 566 567 OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp, 568 OMX_BUFFERHEADERTYPE * buffer); 569 OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE hComp, 570 OMX_BUFFERHEADERTYPE *buffer); 571 572 OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp, 573 OMX_BUFFERHEADERTYPE *buffer 574 ); 575 576 OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp); 577 OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp); 578 OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp); 579 OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp); 580 581 OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE hComp, 582 OMX_BUFFERHEADERTYPE *buffer); 583 bool release_done(); 584 585 bool release_output_done(); 586 bool release_input_done(); 587 OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop); 588 OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop); 589 OMX_ERRORTYPE start_port_reconfig(); 590 OMX_ERRORTYPE update_picture_resolution(); 591 void stream_off(); 592 void adjust_timestamp(OMX_S64 &act_timestamp); 593 void set_frame_rate(OMX_S64 act_timestamp); 594 void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr); 595 OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true); 596 void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra); 597 void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, 598 OMX_U32 interlaced_format_type); 599 void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, 600 OMX_U32 num_conceal_mb, 601 OMX_U32 picture_type, 602 OMX_S64 timestamp, 603 OMX_U32 frame_rate, 604 struct vdec_aspectratioinfo *aspect_ratio_info); 605 void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info, 606 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info); 607 void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra); 608 OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn); 609 void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra); 610 void insert_demux_addr_offset(OMX_U32 address_offset); 611 void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr); 612 OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr); 613 OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra); 614 615 #ifdef USE_ION 616 int alloc_map_ion_memory(OMX_U32 buffer_size, 617 OMX_U32 alignment, struct ion_allocation_data *alloc_data, 618 struct ion_fd_data *fd_data,int flag); 619 void free_ion_memory(struct vdec_ion *buf_ion_info); 620 #else 621 bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size, 622 OMX_U32 alignment); 623 #endif 624 625 626 OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE hComp, 627 OMX_COMMANDTYPE cmd, 628 OMX_U32 param1, 629 OMX_PTR cmdData); 630 bool post_event( unsigned int p1, 631 unsigned int p2, 632 unsigned int id 633 ); clip2(int x)634 inline int clip2(int x) 635 { 636 x = x -1; 637 x = x | x >> 1; 638 x = x | x >> 2; 639 x = x | x >> 4; 640 x = x | x >> 16; 641 x = x + 1; 642 return x; 643 } 644 645 #ifdef MAX_RES_1080P 646 OMX_ERRORTYPE vdec_alloc_h264_mv(); 647 void vdec_dealloc_h264_mv(); 648 #endif 649 omx_report_error()650 inline void omx_report_error () 651 { 652 if (m_cb.EventHandler && !m_error_propogated) 653 { 654 ALOGE("\nERROR: Sending OMX_EventError to Client"); 655 m_error_propogated = true; 656 m_cb.EventHandler(&m_cmp,m_app_data, 657 OMX_EventError,OMX_ErrorHardware,0,NULL); 658 } 659 } 660 #ifdef _ANDROID_ 661 OMX_ERRORTYPE createDivxDrmContext(); 662 #endif //_ANDROID_ 663 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) 664 OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data); 665 #endif 666 667 //************************************************************* 668 //*******************MEMBER VARIABLES ************************* 669 //************************************************************* 670 pthread_mutex_t m_lock; 671 //sem to handle the minimum procesing of commands 672 sem_t m_cmd_lock; 673 bool m_error_propogated; 674 // compression format 675 OMX_VIDEO_CODINGTYPE eCompressionFormat; 676 // OMX State 677 OMX_STATETYPE m_state; 678 // Application data 679 OMX_PTR m_app_data; 680 // Application callbacks 681 OMX_CALLBACKTYPE m_cb; 682 OMX_PRIORITYMGMTTYPE m_priority_mgm ; 683 OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier; 684 // fill this buffer queue 685 omx_cmd_queue m_ftb_q; 686 // Command Q for rest of the events 687 omx_cmd_queue m_cmd_q; 688 omx_cmd_queue m_etb_q; 689 // Input memory pointer 690 OMX_BUFFERHEADERTYPE *m_inp_mem_ptr; 691 // Output memory pointer 692 OMX_BUFFERHEADERTYPE *m_out_mem_ptr; 693 // number of input bitstream error frame count 694 unsigned int m_inp_err_count; 695 #ifdef _ANDROID_ 696 // Timestamp list 697 ts_arr_list m_timestamp_list; 698 #endif 699 700 bool input_flush_progress; 701 bool output_flush_progress; 702 bool input_use_buffer; 703 bool output_use_buffer; 704 bool ouput_egl_buffers; 705 OMX_BOOL m_use_output_pmem; 706 OMX_BOOL m_out_mem_region_smi; 707 OMX_BOOL m_out_pvt_entry_pmem; 708 709 int pending_input_buffers; 710 int pending_output_buffers; 711 // bitmask array size for output side 712 unsigned int m_out_bm_count; 713 // bitmask array size for input side 714 unsigned int m_inp_bm_count; 715 //Input port Populated 716 OMX_BOOL m_inp_bPopulated; 717 //Output port Populated 718 OMX_BOOL m_out_bPopulated; 719 // encapsulate the waiting states. 720 unsigned int m_flags; 721 722 #ifdef _ANDROID_ 723 // Heap pointer to frame buffers 724 struct vidc_heap 725 { 726 sp<MemoryHeapBase> video_heap_ptr; 727 }; 728 struct vidc_heap *m_heap_ptr; 729 unsigned int m_heap_count; 730 #endif //_ANDROID_ 731 // store I/P PORT state 732 OMX_BOOL m_inp_bEnabled; 733 // store O/P PORT state 734 OMX_BOOL m_out_bEnabled; 735 OMX_U32 m_in_alloc_cnt; 736 OMX_U8 m_cRole[OMX_MAX_STRINGNAME_SIZE]; 737 // Platform specific details 738 OMX_QCOM_PLATFORM_PRIVATE_LIST *m_platform_list; 739 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *m_platform_entry; 740 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info; 741 // SPS+PPS sent as part of set_config 742 OMX_VENDOR_EXTRADATATYPE m_vendor_config; 743 744 /*Variables for arbitrary Byte parsing support*/ 745 frame_parse m_frame_parser; 746 omx_cmd_queue m_input_pending_q; 747 omx_cmd_queue m_input_free_q; 748 bool arbitrary_bytes; 749 OMX_BUFFERHEADERTYPE h264_scratch; 750 OMX_BUFFERHEADERTYPE *psource_frame; 751 OMX_BUFFERHEADERTYPE *pdest_frame; 752 OMX_BUFFERHEADERTYPE *m_inp_heap_ptr; 753 OMX_BUFFERHEADERTYPE **m_phdr_pmem_ptr; 754 unsigned int m_heap_inp_bm_count; 755 codec_type codec_type_parse; 756 bool first_frame_meta; 757 unsigned frame_count; 758 unsigned nal_count; 759 unsigned nal_length; 760 bool look_ahead_nal; 761 int first_frame; 762 unsigned char *first_buffer; 763 int first_frame_size; 764 unsigned char m_hwdevice_name[80]; 765 FILE *m_device_file_ptr; 766 enum vc1_profile_type m_vc1_profile; 767 OMX_S64 h264_last_au_ts; 768 OMX_U32 h264_last_au_flags; 769 OMX_U32 m_demux_offsets[8192]; 770 OMX_U32 m_demux_entries; 771 772 OMX_S64 prev_ts; 773 bool rst_prev_ts; 774 OMX_U32 frm_int; 775 776 struct vdec_allocatorproperty op_buf_rcnfg; 777 bool in_reconfig; 778 OMX_NATIVE_WINDOWTYPE m_display_id; 779 h264_stream_parser *h264_parser; 780 OMX_U32 client_extradata; 781 #ifdef _ANDROID_ 782 bool m_debug_timestamp; 783 bool perf_flag; 784 OMX_U32 proc_frms, latency; 785 perf_metrics fps_metrics; 786 perf_metrics dec_time; 787 bool m_enable_android_native_buffers; 788 bool m_use_android_native_buffers; 789 bool m_debug_extradata; 790 bool m_debug_concealedmb; 791 #endif 792 #ifdef MAX_RES_1080P 793 MP4_Utils mp4_headerparser; 794 #endif 795 796 struct h264_mv_buffer{ 797 unsigned char* buffer; 798 int size; 799 int count; 800 int pmem_fd; 801 int offset; 802 }; 803 h264_mv_buffer h264_mv_buff; 804 extra_data_handler extra_data_handle; 805 #ifdef _ANDROID_ 806 DivXDrmDecrypt* iDivXDrmDecrypt; 807 #endif //_ANDROID_ 808 OMX_PARAM_PORTDEFINITIONTYPE m_port_def; 809 omx_time_stamp_reorder time_stamp_dts; 810 desc_buffer_hdr *m_desc_buffer_ptr; 811 bool secure_mode; 812 OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata; 813 bool codec_config_flag; 814 #ifdef _COPPER_ 815 int capture_capability; 816 int output_capability; 817 bool streaming[MAX_PORT]; 818 #endif 819 unsigned int m_fill_output_msg; 820 class allocate_color_convert_buf { 821 public: 822 allocate_color_convert_buf(); 823 ~allocate_color_convert_buf(); 824 void set_vdec_client(void *); 825 void update_client(); 826 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format); 827 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format); 828 bool update_buffer_req(); 829 bool get_buffer_req(unsigned int &buffer_size); 830 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(); 831 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr); 832 OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr); 833 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header); 834 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header); 835 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp, 836 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData, 837 OMX_U32 bytes); 838 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 839 private: 840 #define MAX_COUNT 32 841 omx_vdec *omx; 842 bool enabled; 843 OMX_COLOR_FORMATTYPE ColorFormat; 844 void init_members(); 845 bool color_convert_mode; 846 ColorConvertFormat dest_format; 847 class omx_c2d_conv c2d; 848 unsigned int allocated_count; 849 unsigned int buffer_size_req; 850 unsigned int buffer_alignment_req; 851 OMX_QCOM_PLATFORM_PRIVATE_LIST m_platform_list_client[MAX_COUNT]; 852 OMX_QCOM_PLATFORM_PRIVATE_ENTRY m_platform_entry_client[MAX_COUNT]; 853 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT]; 854 OMX_BUFFERHEADERTYPE m_out_mem_ptr_client[MAX_COUNT]; 855 struct vdec_ion op_buf_ion_info[MAX_COUNT]; 856 unsigned char *pmem_baseaddress[MAX_COUNT]; 857 int pmem_fd[MAX_COUNT]; 858 struct vidc_heap 859 { 860 sp<MemoryHeapBase> video_heap_ptr; 861 }; 862 struct vidc_heap m_heap_ptr[MAX_COUNT]; 863 }; 864 allocate_color_convert_buf client_buffers; 865 static bool m_secure_display; //For qservice 866 int secureDisplay(int mode); 867 int unsecureDisplay(int mode); 868 }; 869 870 #ifdef _COPPER_ 871 enum instance_state { 872 MSM_VIDC_CORE_UNINIT_DONE = 0x0001, 873 MSM_VIDC_CORE_INIT, 874 MSM_VIDC_CORE_INIT_DONE, 875 MSM_VIDC_OPEN, 876 MSM_VIDC_OPEN_DONE, 877 MSM_VIDC_LOAD_RESOURCES, 878 MSM_VIDC_LOAD_RESOURCES_DONE, 879 MSM_VIDC_START, 880 MSM_VIDC_START_DONE, 881 MSM_VIDC_STOP, 882 MSM_VIDC_STOP_DONE, 883 MSM_VIDC_RELEASE_RESOURCES, 884 MSM_VIDC_RELEASE_RESOURCES_DONE, 885 MSM_VIDC_CLOSE, 886 MSM_VIDC_CLOSE_DONE, 887 MSM_VIDC_CORE_UNINIT, 888 }; 889 890 enum vidc_resposes_id { 891 MSM_VIDC_DECODER_FLUSH_DONE = 0x11, 892 MSM_VIDC_DECODER_EVENT_CHANGE, 893 }; 894 895 #endif // _COPPER_ 896 897 #endif // __OMX_VDEC_H__ 898