1 /*-------------------------------------------------------------------------- 2 Copyright (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 are 6 met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above 10 copyright notice, this list of conditions and the following 11 disclaimer in the documentation and/or other materials provided 12 with the distribution. 13 * Neither the name of The Linux Foundation nor the names of its 14 contributors may be used to endorse or promote products derived 15 from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 --------------------------------------------------------------------------*/ 29 30 #ifndef __OMX_VIDEO_BASE_H__ 31 #define __OMX_VIDEO_BASE_H__ 32 /*============================================================================ 33 O p e n M A X Component 34 Video Encoder 35 36 *//** @file comx_video_base.h 37 This module contains the class definition for openMAX decoder component. 38 39 *//*========================================================================*/ 40 41 ////////////////////////////////////////////////////////////////////////////// 42 // Include Files 43 ////////////////////////////////////////////////////////////////////////////// 44 45 #define LOG_TAG "OMX-VENC" 46 #include <stdlib.h> 47 #include <stdio.h> 48 #include <sys/mman.h> 49 #ifdef _ANDROID_ 50 #include <binder/MemoryHeapBase.h> 51 #ifdef _ANDROID_ICS_ 52 #include "QComOMXMetadata.h" 53 #endif 54 #endif // _ANDROID_ 55 #include <pthread.h> 56 #include <semaphore.h> 57 #include <linux/msm_vidc_enc.h> 58 #include <media/hardware/HardwareAPI.h> 59 #include "OMX_Core.h" 60 #include "OMX_QCOMExtns.h" 61 #include "OMX_Skype_VideoExtensions.h" 62 #include "OMX_VideoExt.h" 63 #include "OMX_IndexExt.h" 64 #include "qc_omx_component.h" 65 #include "omx_video_common.h" 66 #include "extra_data_handler.h" 67 #include <linux/videodev2.h> 68 #include <dlfcn.h> 69 #include "C2DColorConverter.h" 70 #include "vidc_debug.h" 71 72 #ifdef _ANDROID_ 73 using namespace android; 74 // local pmem heap object 75 class VideoHeap : public MemoryHeapBase 76 { 77 public: 78 VideoHeap(int fd, size_t size, void* base); 79 virtual ~VideoHeap() {} 80 }; 81 82 #include <utils/Log.h> 83 84 #endif // _ANDROID_ 85 86 #ifdef USE_ION 87 static const char* MEM_DEVICE = "/dev/ion"; 88 #if defined(MAX_RES_720P) && !defined(_MSM8974_) 89 #define MEM_HEAP_ID ION_CAMERA_HEAP_ID 90 #else 91 #ifdef _MSM8974_ 92 #define MEM_HEAP_ID ION_IOMMU_HEAP_ID 93 #else 94 #define MEM_HEAP_ID ION_CP_MM_HEAP_ID 95 #endif 96 #endif 97 #elif MAX_RES_720P 98 static const char* MEM_DEVICE = "/dev/pmem_adsp"; 99 #elif MAX_RES_1080P_EBI 100 static const char* MEM_DEVICE = "/dev/pmem_adsp"; 101 #elif MAX_RES_1080P 102 static const char* MEM_DEVICE = "/dev/pmem_smipool"; 103 #else 104 #error MEM_DEVICE cannot be determined. 105 #endif 106 107 ////////////////////////////////////////////////////////////////////////////// 108 // Module specific globals 109 ////////////////////////////////////////////////////////////////////////////// 110 111 #define OMX_SPEC_VERSION 0x00000101 112 113 ////////////////////////////////////////////////////////////////////////////// 114 // Macros 115 ////////////////////////////////////////////////////////////////////////////// 116 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\ 117 (unsigned) bufHdr,\ 118 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\ 119 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\ 120 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp) 121 122 // BitMask Management logic 123 #define BITS_PER_INDEX 64 124 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_INDEX - 1)/BITS_PER_INDEX) 125 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_INDEX) 126 #define BITMASK_FLAG(mIndex) ((uint64_t)1 << ((mIndex) % BITS_PER_INDEX)) 127 #define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 128 &= ~(BITMASK_FLAG(mIndex)) 129 #define BITMASK_SET(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 130 |= BITMASK_FLAG(mIndex) 131 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 132 & BITMASK_FLAG(mIndex)) 133 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 134 & BITMASK_FLAG(mIndex)) == 0x0) 135 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 136 & BITMASK_FLAG(mIndex)) 137 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 138 & BITMASK_FLAG(mIndex)) == 0x0) 139 140 #define MAX_NUM_INPUT_BUFFERS 64 141 #define MAX_NUM_OUTPUT_BUFFERS 64 142 143 void* message_thread(void *); 144 145 enum omx_venc_extradata_types { 146 VENC_EXTRADATA_SLICEINFO = 0x100, 147 VENC_EXTRADATA_MBINFO = 0x400, 148 VENC_EXTRADATA_FRAMEDIMENSION = 0x1000000, 149 VENC_EXTRADATA_YUV_STATS = 0x800, 150 VENC_EXTRADATA_VQZIP = 0x02000000, 151 }; 152 153 // OMX video class 154 class omx_video: public qc_omx_component 155 { 156 protected: 157 #ifdef _ANDROID_ICS_ 158 bool meta_mode_enable; 159 bool c2d_opened; 160 encoder_media_buffer_type meta_buffers[MAX_NUM_INPUT_BUFFERS]; 161 OMX_BUFFERHEADERTYPE *opaque_buffer_hdr[MAX_NUM_INPUT_BUFFERS]; 162 bool get_syntaxhdr_enable; 163 OMX_BUFFERHEADERTYPE *psource_frame; 164 OMX_BUFFERHEADERTYPE *pdest_frame; 165 bool secure_session; 166 bool hier_b_enabled; 167 //intermediate conversion buffer queued to encoder in case of invalid EOS input 168 OMX_BUFFERHEADERTYPE *mEmptyEosBuffer; 169 170 class omx_c2d_conv 171 { 172 public: 173 omx_c2d_conv(); 174 ~omx_c2d_conv(); 175 bool init(); 176 bool open(unsigned int height,unsigned int width, 177 ColorConvertFormat src, 178 ColorConvertFormat dest,unsigned int src_stride); 179 bool convert(int src_fd, void *src_base, void *src_viraddr, 180 int dest_fd, void *dest_base, void *dest_viraddr); 181 bool get_buffer_size(int port,unsigned int &buf_size); 182 int get_src_format(); 183 void close(); 184 private: 185 C2DColorConverterBase *c2dcc; 186 pthread_mutex_t c_lock; 187 void *mLibHandle; 188 ColorConvertFormat src_format; 189 createC2DColorConverter_t *mConvertOpen; 190 destroyC2DColorConverter_t *mConvertClose; 191 }; 192 omx_c2d_conv c2d_conv; 193 #endif 194 public: 195 196 bool mUseProxyColorFormat; 197 //RGB or non-native input, and we have pre-allocated conversion buffers 198 bool mUsesColorConversion; 199 200 omx_video(); // constructor 201 virtual ~omx_video(); // destructor 202 203 // virtual int async_message_process (void *context, void* message); 204 void process_event_cb(void *ctxt,unsigned char id); 205 206 OMX_ERRORTYPE allocate_buffer( 207 OMX_HANDLETYPE hComp, 208 OMX_BUFFERHEADERTYPE **bufferHdr, 209 OMX_U32 port, 210 OMX_PTR appData, 211 OMX_U32 bytes 212 ); 213 214 215 virtual OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp)= 0; 216 217 virtual OMX_ERRORTYPE component_init(OMX_STRING role)= 0; 218 219 virtual OMX_U32 dev_stop(void) = 0; 220 virtual OMX_U32 dev_pause(void) = 0; 221 virtual OMX_U32 dev_start(void) = 0; 222 virtual OMX_U32 dev_flush(unsigned) = 0; 223 virtual OMX_U32 dev_resume(void) = 0; 224 virtual OMX_U32 dev_start_done(void) = 0; 225 virtual OMX_U32 dev_set_message_thread_id(pthread_t) = 0; 226 virtual bool dev_use_buf(void *,unsigned,unsigned) = 0; 227 virtual bool dev_free_buf(void *,unsigned) = 0; 228 virtual bool dev_empty_buf(void *, void *,unsigned,unsigned) = 0; 229 virtual bool dev_fill_buf(void *buffer, void *,unsigned,unsigned) = 0; 230 virtual bool dev_get_buf_req(OMX_U32 *,OMX_U32 *,OMX_U32 *,OMX_U32) = 0; 231 virtual bool dev_get_seq_hdr(void *, unsigned, unsigned *) = 0; 232 virtual bool dev_loaded_start(void) = 0; 233 virtual bool dev_loaded_stop(void) = 0; 234 virtual bool dev_loaded_start_done(void) = 0; 235 virtual bool dev_loaded_stop_done(void) = 0; 236 virtual bool is_secure_session(void) = 0; 237 virtual int dev_handle_output_extradata(void*) = 0; 238 virtual int dev_handle_input_extradata(void*, int) = 0; 239 virtual void dev_set_extradata_cookie(void*) = 0; 240 virtual int dev_set_format(int) = 0; 241 virtual bool dev_is_video_session_supported(OMX_U32 width, OMX_U32 height) = 0; 242 virtual bool dev_get_capability_ltrcount(OMX_U32 *, OMX_U32 *, OMX_U32 *) = 0; 243 virtual bool dev_get_performance_level(OMX_U32 *) = 0; 244 virtual bool dev_get_vui_timing_info(OMX_U32 *) = 0; 245 virtual bool dev_get_vqzip_sei_info(OMX_U32 *) = 0; 246 virtual bool dev_get_peak_bitrate(OMX_U32 *) = 0; 247 virtual bool dev_get_batch_size(OMX_U32 *) = 0; 248 #ifdef _ANDROID_ICS_ 249 void omx_release_meta_buffer(OMX_BUFFERHEADERTYPE *buffer); 250 #endif 251 virtual bool dev_color_align(OMX_BUFFERHEADERTYPE *buffer, OMX_U32 width, 252 OMX_U32 height) = 0; 253 virtual bool dev_get_output_log_flag() = 0; 254 virtual int dev_output_log_buffers(const char *buffer_addr, int buffer_len) = 0; 255 virtual int dev_extradata_log_buffers(char *buffer_addr) = 0; 256 OMX_ERRORTYPE component_role_enum( 257 OMX_HANDLETYPE hComp, 258 OMX_U8 *role, 259 OMX_U32 index 260 ); 261 262 OMX_ERRORTYPE component_tunnel_request( 263 OMX_HANDLETYPE hComp, 264 OMX_U32 port, 265 OMX_HANDLETYPE peerComponent, 266 OMX_U32 peerPort, 267 OMX_TUNNELSETUPTYPE *tunnelSetup 268 ); 269 270 OMX_ERRORTYPE empty_this_buffer( 271 OMX_HANDLETYPE hComp, 272 OMX_BUFFERHEADERTYPE *buffer 273 ); 274 275 276 277 OMX_ERRORTYPE fill_this_buffer( 278 OMX_HANDLETYPE hComp, 279 OMX_BUFFERHEADERTYPE *buffer 280 ); 281 282 283 OMX_ERRORTYPE free_buffer( 284 OMX_HANDLETYPE hComp, 285 OMX_U32 port, 286 OMX_BUFFERHEADERTYPE *buffer 287 ); 288 289 OMX_ERRORTYPE get_component_version( 290 OMX_HANDLETYPE hComp, 291 OMX_STRING componentName, 292 OMX_VERSIONTYPE *componentVersion, 293 OMX_VERSIONTYPE *specVersion, 294 OMX_UUIDTYPE *componentUUID 295 ); 296 297 OMX_ERRORTYPE get_config( 298 OMX_HANDLETYPE hComp, 299 OMX_INDEXTYPE configIndex, 300 OMX_PTR configData 301 ); 302 303 OMX_ERRORTYPE get_extension_index( 304 OMX_HANDLETYPE hComp, 305 OMX_STRING paramName, 306 OMX_INDEXTYPE *indexType 307 ); 308 309 OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp, 310 OMX_INDEXTYPE paramIndex, 311 OMX_PTR paramData); 312 313 OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp, 314 OMX_STATETYPE *state); 315 316 317 318 OMX_ERRORTYPE send_command(OMX_HANDLETYPE hComp, 319 OMX_COMMANDTYPE cmd, 320 OMX_U32 param1, 321 OMX_PTR cmdData); 322 323 324 OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE hComp, 325 OMX_CALLBACKTYPE *callbacks, 326 OMX_PTR appData); 327 328 virtual OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp, 329 OMX_INDEXTYPE configIndex, 330 OMX_PTR configData) = 0; 331 332 virtual OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp, 333 OMX_INDEXTYPE paramIndex, 334 OMX_PTR paramData) =0; 335 336 OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE hComp, 337 OMX_BUFFERHEADERTYPE **bufferHdr, 338 OMX_U32 port, 339 OMX_PTR appData, 340 OMX_U32 bytes, 341 OMX_U8 *buffer); 342 343 344 OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE hComp, 345 OMX_BUFFERHEADERTYPE **bufferHdr, 346 OMX_U32 port, 347 OMX_PTR appData, 348 void * eglImage); 349 350 351 352 int m_pipe_in; 353 int m_pipe_out; 354 355 pthread_t msg_thread_id; 356 pthread_t async_thread_id; 357 bool async_thread_created; 358 bool msg_thread_created; 359 volatile bool msg_thread_stop; 360 361 OMX_U8 m_nkind[128]; 362 363 364 //int *input_pmem_fd; 365 //int *output_pmem_fd; 366 struct pmem *m_pInput_pmem; 367 struct pmem *m_pOutput_pmem; 368 #ifdef USE_ION 369 struct venc_ion *m_pInput_ion; 370 struct venc_ion *m_pOutput_ion; 371 #endif 372 373 374 375 public: 376 // Bit Positions 377 enum flags_bit_positions { 378 // Defer transition to IDLE 379 OMX_COMPONENT_IDLE_PENDING =0x1, 380 // Defer transition to LOADING 381 OMX_COMPONENT_LOADING_PENDING =0x2, 382 // First Buffer Pending 383 OMX_COMPONENT_FIRST_BUFFER_PENDING =0x3, 384 // Second Buffer Pending 385 OMX_COMPONENT_SECOND_BUFFER_PENDING =0x4, 386 // Defer transition to Enable 387 OMX_COMPONENT_INPUT_ENABLE_PENDING =0x5, 388 // Defer transition to Enable 389 OMX_COMPONENT_OUTPUT_ENABLE_PENDING =0x6, 390 // Defer transition to Disable 391 OMX_COMPONENT_INPUT_DISABLE_PENDING =0x7, 392 // Defer transition to Disable 393 OMX_COMPONENT_OUTPUT_DISABLE_PENDING =0x8, 394 //defer flush notification 395 OMX_COMPONENT_OUTPUT_FLUSH_PENDING =0x9, 396 OMX_COMPONENT_INPUT_FLUSH_PENDING =0xA, 397 OMX_COMPONENT_PAUSE_PENDING =0xB, 398 OMX_COMPONENT_EXECUTE_PENDING =0xC, 399 OMX_COMPONENT_LOADED_START_PENDING = 0xD, 400 OMX_COMPONENT_LOADED_STOP_PENDING = 0xF, 401 402 }; 403 404 // Deferred callback identifiers 405 enum { 406 //Event Callbacks from the venc component thread context 407 OMX_COMPONENT_GENERATE_EVENT = 0x1, 408 //Buffer Done callbacks from the venc component thread context 409 OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2, 410 //Frame Done callbacks from the venc component thread context 411 OMX_COMPONENT_GENERATE_FRAME_DONE = 0x3, 412 //Buffer Done callbacks from the venc component thread context 413 OMX_COMPONENT_GENERATE_FTB = 0x4, 414 //Frame Done callbacks from the venc component thread context 415 OMX_COMPONENT_GENERATE_ETB = 0x5, 416 //Command 417 OMX_COMPONENT_GENERATE_COMMAND = 0x6, 418 //Push-Pending Buffers 419 OMX_COMPONENT_PUSH_PENDING_BUFS = 0x7, 420 // Empty Buffer Done callbacks 421 OMX_COMPONENT_GENERATE_EBD = 0x8, 422 //Flush Event Callbacks from the venc component thread context 423 OMX_COMPONENT_GENERATE_EVENT_FLUSH = 0x9, 424 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A, 425 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B, 426 OMX_COMPONENT_GENERATE_FBD = 0xc, 427 OMX_COMPONENT_GENERATE_START_DONE = 0xD, 428 OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE, 429 OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF, 430 OMX_COMPONENT_GENERATE_STOP_DONE = 0x10, 431 OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11, 432 OMX_COMPONENT_GENERATE_LTRUSE_FAILED = 0x12, 433 OMX_COMPONENT_GENERATE_ETB_OPQ = 0x13, 434 OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x14, 435 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD = 0x15, 436 OMX_COMPONENT_CLOSE_MSG = 0x16 437 }; 438 439 struct omx_event { 440 unsigned long param1; 441 unsigned long param2; 442 unsigned long id; 443 }; 444 445 struct omx_cmd_queue { 446 omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE]; 447 unsigned long m_read; 448 unsigned long m_write; 449 unsigned long m_size; 450 451 omx_cmd_queue(); 452 ~omx_cmd_queue(); 453 bool insert_entry(unsigned long p1, unsigned long p2, unsigned long id); 454 bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned long *id); 455 // get msgtype of the first ele from the queue 456 unsigned get_q_msg_type(); 457 458 }; 459 460 bool allocate_done(void); 461 bool allocate_input_done(void); 462 bool allocate_output_done(void); 463 464 OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 465 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 466 467 OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE hComp, 468 OMX_BUFFERHEADERTYPE **bufferHdr, 469 OMX_U32 port, 470 OMX_PTR appData, 471 OMX_U32 bytes); 472 #ifdef _ANDROID_ICS_ 473 OMX_ERRORTYPE allocate_input_meta_buffer(OMX_HANDLETYPE hComp, 474 OMX_BUFFERHEADERTYPE **bufferHdr, 475 OMX_PTR appData, 476 OMX_U32 bytes); 477 #endif 478 OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE hComp, 479 OMX_BUFFERHEADERTYPE **bufferHdr, 480 OMX_U32 port,OMX_PTR appData, 481 OMX_U32 bytes); 482 483 OMX_ERRORTYPE use_input_buffer(OMX_HANDLETYPE hComp, 484 OMX_BUFFERHEADERTYPE **bufferHdr, 485 OMX_U32 port, 486 OMX_PTR appData, 487 OMX_U32 bytes, 488 OMX_U8 *buffer); 489 490 OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp, 491 OMX_BUFFERHEADERTYPE **bufferHdr, 492 OMX_U32 port, 493 OMX_PTR appData, 494 OMX_U32 bytes, 495 OMX_U8 *buffer); 496 497 bool execute_omx_flush(OMX_U32); 498 bool execute_output_flush(void); 499 bool execute_input_flush(void); 500 #ifdef _MSM8974_ 501 bool execute_flush_all(void); 502 #endif 503 OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp, 504 OMX_BUFFERHEADERTYPE * buffer); 505 506 OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp, 507 OMX_BUFFERHEADERTYPE * buffer); 508 OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE hComp, 509 OMX_BUFFERHEADERTYPE *buffer); 510 OMX_ERRORTYPE empty_this_buffer_opaque(OMX_HANDLETYPE hComp, 511 OMX_BUFFERHEADERTYPE *buffer); 512 OMX_ERRORTYPE push_input_buffer(OMX_HANDLETYPE hComp); 513 OMX_ERRORTYPE convert_queue_buffer(OMX_HANDLETYPE hComp, 514 struct pmem &Input_pmem_info,unsigned long &index); 515 OMX_ERRORTYPE queue_meta_buffer(OMX_HANDLETYPE hComp, 516 struct pmem &Input_pmem_info); 517 OMX_ERRORTYPE push_empty_eos_buffer(OMX_HANDLETYPE hComp, 518 OMX_BUFFERHEADERTYPE *buffer); 519 OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE hComp, 520 OMX_BUFFERHEADERTYPE *buffer); 521 bool release_done(); 522 523 bool release_output_done(); 524 bool release_input_done(); 525 526 OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE hComp, 527 OMX_COMMANDTYPE cmd, 528 OMX_U32 param1, 529 OMX_PTR cmdData); 530 bool post_event( unsigned long p1, 531 unsigned long p2, 532 unsigned long id 533 ); 534 OMX_ERRORTYPE get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType); 535 inline void omx_report_error () { 536 if (m_pCallbacks.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 537 m_error_propogated = true; 538 DEBUG_PRINT_ERROR("ERROR: send OMX_ErrorHardware to Client"); 539 m_pCallbacks.EventHandler(&m_cmp,m_app_data, 540 OMX_EventError,OMX_ErrorHardware,0,NULL); 541 } 542 } 543 544 inline void omx_report_hw_overload () 545 { 546 if (m_pCallbacks.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 547 m_error_propogated = true; 548 DEBUG_PRINT_ERROR("ERROR: send OMX_ErrorInsufficientResources to Client"); 549 m_pCallbacks.EventHandler(&m_cmp, m_app_data, 550 OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL); 551 } 552 } 553 554 inline void omx_report_unsupported_setting () { 555 if (m_pCallbacks.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 556 m_error_propogated = true; 557 m_pCallbacks.EventHandler(&m_cmp,m_app_data, 558 OMX_EventError,OMX_ErrorUnsupportedSetting,0,NULL); 559 } 560 } 561 562 void complete_pending_buffer_done_cbs(); 563 bool is_conv_needed(int, int); 564 565 #ifdef USE_ION 566 int alloc_map_ion_memory(int size, 567 struct ion_allocation_data *alloc_data, 568 struct ion_fd_data *fd_data,int flag); 569 void free_ion_memory(struct venc_ion *buf_ion_info); 570 #endif 571 572 //************************************************************* 573 //*******************MEMBER VARIABLES ************************* 574 //************************************************************* 575 576 pthread_mutex_t m_lock; 577 sem_t m_cmd_lock; 578 bool m_error_propogated; 579 580 //sem to handle the minimum procesing of commands 581 582 583 // compression format 584 //OMX_VIDEO_CODINGTYPE eCompressionFormat; 585 // OMX State 586 OMX_STATETYPE m_state; 587 // Application data 588 OMX_PTR m_app_data; 589 OMX_BOOL m_use_input_pmem; 590 OMX_BOOL m_use_output_pmem; 591 // Application callbacks 592 OMX_CALLBACKTYPE m_pCallbacks; 593 OMX_PORT_PARAM_TYPE m_sPortParam; 594 OMX_VIDEO_PARAM_PROFILELEVELTYPE m_sParamProfileLevel; 595 OMX_VIDEO_PARAM_PORTFORMATTYPE m_sInPortFormat; 596 OMX_VIDEO_PARAM_PORTFORMATTYPE m_sOutPortFormat; 597 OMX_PARAM_PORTDEFINITIONTYPE m_sInPortDef; 598 OMX_PARAM_PORTDEFINITIONTYPE m_sOutPortDef; 599 OMX_VIDEO_PARAM_MPEG4TYPE m_sParamMPEG4; 600 OMX_VIDEO_PARAM_H263TYPE m_sParamH263; 601 OMX_VIDEO_PARAM_AVCTYPE m_sParamAVC; 602 OMX_VIDEO_PARAM_VP8TYPE m_sParamVP8; 603 OMX_VIDEO_PARAM_HEVCTYPE m_sParamHEVC; 604 OMX_PORT_PARAM_TYPE m_sPortParam_img; 605 OMX_PORT_PARAM_TYPE m_sPortParam_audio; 606 OMX_VIDEO_CONFIG_BITRATETYPE m_sConfigBitrate; 607 OMX_CONFIG_FRAMERATETYPE m_sConfigFramerate; 608 OMX_VIDEO_PARAM_BITRATETYPE m_sParamBitrate; 609 OMX_PRIORITYMGMTTYPE m_sPriorityMgmt; 610 OMX_PARAM_BUFFERSUPPLIERTYPE m_sInBufSupplier; 611 OMX_PARAM_BUFFERSUPPLIERTYPE m_sOutBufSupplier; 612 OMX_CONFIG_ROTATIONTYPE m_sConfigFrameRotation; 613 OMX_CONFIG_INTRAREFRESHVOPTYPE m_sConfigIntraRefreshVOP; 614 OMX_VIDEO_PARAM_QUANTIZATIONTYPE m_sSessionQuantization; 615 OMX_QCOM_VIDEO_PARAM_QPRANGETYPE m_sSessionQPRange; 616 OMX_VIDEO_PARAM_AVCSLICEFMO m_sAVCSliceFMO; 617 QOMX_VIDEO_INTRAPERIODTYPE m_sIntraperiod; 618 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE m_sErrorCorrection; 619 OMX_VIDEO_PARAM_INTRAREFRESHTYPE m_sIntraRefresh; 620 QOMX_VIDEO_PARAM_LTRMODE_TYPE m_sParamLTRMode; 621 QOMX_VIDEO_PARAM_LTRCOUNT_TYPE m_sParamLTRCount; 622 QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE m_sConfigLTRPeriod; 623 QOMX_VIDEO_CONFIG_LTRUSE_TYPE m_sConfigLTRUse; 624 OMX_VIDEO_CONFIG_AVCINTRAPERIOD m_sConfigAVCIDRPeriod; 625 OMX_VIDEO_CONFIG_DEINTERLACE m_sConfigDeinterlace; 626 OMX_VIDEO_VP8REFERENCEFRAMETYPE m_sConfigVp8ReferenceFrame; 627 QOMX_VIDEO_HIERARCHICALLAYERS m_sHierLayers; 628 OMX_QOMX_VIDEO_MBI_STATISTICS m_sMBIStatistics; 629 QOMX_EXTNINDEX_VIDEO_INITIALQP m_sParamInitqp; 630 QOMX_EXTNINDEX_VIDEO_MAX_HIER_P_LAYERS m_sMaxHPlayers; 631 OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID m_sBaseLayerID; 632 OMX_SKYPE_VIDEO_PARAM_DRIVERVER m_sDriverVer; 633 OMX_SKYPE_VIDEO_CONFIG_QP m_sConfigQP; 634 QOMX_EXTNINDEX_VIDEO_VENC_SAR m_sSar; 635 PrependSPSPPSToIDRFramesParams m_sPrependSPSPPS; 636 OMX_U32 m_sExtraData; 637 OMX_U32 m_input_msg_id; 638 OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE m_sConfigIntraRefresh; 639 640 // fill this buffer queue 641 omx_cmd_queue m_ftb_q; 642 // Command Q for rest of the events 643 omx_cmd_queue m_cmd_q; 644 omx_cmd_queue m_etb_q; 645 // Input memory pointer 646 OMX_BUFFERHEADERTYPE *m_inp_mem_ptr; 647 // Output memory pointer 648 OMX_BUFFERHEADERTYPE *m_out_mem_ptr; 649 omx_cmd_queue m_opq_meta_q; 650 omx_cmd_queue m_opq_pmem_q; 651 OMX_BUFFERHEADERTYPE meta_buffer_hdr[MAX_NUM_INPUT_BUFFERS]; 652 653 bool input_flush_progress; 654 bool output_flush_progress; 655 bool input_use_buffer; 656 bool output_use_buffer; 657 int pending_input_buffers; 658 int pending_output_buffers; 659 660 uint64_t m_out_bm_count; 661 uint64_t m_inp_bm_count; 662 uint64_t m_flags; 663 uint64_t m_etb_count; 664 uint64_t m_fbd_count; 665 #ifdef _ANDROID_ 666 // Heap pointer to frame buffers 667 sp<MemoryHeapBase> m_heap_ptr; 668 #endif //_ANDROID_ 669 // to know whether Event Port Settings change has been triggered or not. 670 bool m_event_port_settings_sent; 671 OMX_U8 m_cRole[OMX_MAX_STRINGNAME_SIZE]; 672 extra_data_handler extra_data_handle; 673 bool hw_overload; 674 OMX_U32 m_graphicBufferSize; 675 }; 676 677 #endif // __OMX_VIDEO_BASE_H__ 678