1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2010-2018, The Linux Foundation. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions 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 #include <stdlib.h> 46 #include <stdio.h> 47 #include <sys/mman.h> 48 #ifdef _ANDROID_ 49 #ifdef _ANDROID_ICS_ 50 #include "QComOMXMetadata.h" 51 #endif 52 #endif // _ANDROID_ 53 #include <pthread.h> 54 #include <semaphore.h> 55 #include <media/hardware/HardwareAPI.h> 56 #include "OMX_Core.h" 57 #include "OMX_QCOMExtns.h" 58 #include "OMX_Skype_VideoExtensions.h" 59 #include "OMX_VideoExt.h" 60 #include "OMX_IndexExt.h" 61 #include "qc_omx_component.h" 62 #include "omx_video_common.h" 63 #include "extra_data_handler.h" 64 #include <linux/videodev2.h> 65 #include <dlfcn.h> 66 #include "C2DColorConverter.h" 67 #include "vidc_debug.h" 68 #include <vector> 69 #include "vidc_vendor_extensions.h" 70 71 #undef LOG_TAG 72 #define LOG_TAG "OMX-VENC" 73 74 #ifdef _ANDROID_ 75 using namespace android; 76 #include <utils/Log.h> 77 78 #endif // _ANDROID_ 79 80 #ifdef USE_ION 81 static const char* MEM_DEVICE = "/dev/ion"; 82 #define MEM_HEAP_ID ION_IOMMU_HEAP_ID 83 #else 84 #error MEM_DEVICE cannot be determined. 85 #endif 86 87 ////////////////////////////////////////////////////////////////////////////// 88 // Module specific globals 89 ////////////////////////////////////////////////////////////////////////////// 90 #define OMX_SPEC_VERSION 0x00000101 91 #define OMX_INIT_STRUCT(_s_, _name_) \ 92 memset((_s_), 0x0, sizeof(_name_)); \ 93 (_s_)->nSize = sizeof(_name_); \ 94 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION 95 96 ////////////////////////////////////////////////////////////////////////////// 97 // Macros 98 ////////////////////////////////////////////////////////////////////////////// 99 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\ 100 (unsigned) bufHdr,\ 101 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\ 102 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\ 103 (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp) 104 105 // BitMask Management logic 106 #define BITS_PER_INDEX 64 107 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_INDEX - 1)/BITS_PER_INDEX) 108 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_INDEX) 109 #define BITMASK_FLAG(mIndex) ((uint64_t)1 << ((mIndex) % BITS_PER_INDEX)) 110 #define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 111 &= ~(BITMASK_FLAG(mIndex)) 112 #define BITMASK_SET(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \ 113 |= BITMASK_FLAG(mIndex) 114 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 115 & BITMASK_FLAG(mIndex)) 116 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 117 & BITMASK_FLAG(mIndex)) == 0x0) 118 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \ 119 & BITMASK_FLAG(mIndex)) 120 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \ 121 & BITMASK_FLAG(mIndex)) == 0x0) 122 123 /** STATUS CODES*/ 124 /* Base value for status codes */ 125 #define VEN_S_BASE 0x00000000 126 #define VEN_S_SUCCESS (VEN_S_BASE)/* Success */ 127 #define VEN_S_EFAIL (VEN_S_BASE+1)/* General failure */ 128 129 /*Asynchronous messages from driver*/ 130 #define VEN_MSG_INDICATION 0 131 #define VEN_MSG_INPUT_BUFFER_DONE 1 132 #define VEN_MSG_OUTPUT_BUFFER_DONE 2 133 #define VEN_MSG_NEED_OUTPUT_BUFFER 3 134 #define VEN_MSG_FLUSH_INPUT_DONE 4 135 #define VEN_MSG_FLUSH_OUPUT_DONE 5 136 #define VEN_MSG_START 6 137 #define VEN_MSG_STOP 7 138 #define VEN_MSG_PAUSE 8 139 #define VEN_MSG_RESUME 9 140 #define VEN_MSG_LTRUSE_FAILED 10 141 #define VEN_MSG_HW_OVERLOAD 11 142 #define VEN_MSG_MAX_CLIENTS 12 143 144 #define MAX_NUM_INPUT_BUFFERS 64 145 #define MAX_NUM_OUTPUT_BUFFERS 64 146 147 #ifdef USE_NATIVE_HANDLE_SOURCE 148 #define LEGACY_CAM_SOURCE kMetadataBufferTypeNativeHandleSource 149 #define LEGACY_CAM_METADATA_TYPE encoder_nativehandle_buffer_type 150 #else 151 #define LEGACY_CAM_SOURCE kMetadataBufferTypeCameraSource 152 #define LEGACY_CAM_METADATA_TYPE encoder_media_buffer_type 153 #endif 154 155 void* message_thread_enc(void *); 156 157 enum omx_venc_extradata_types { 158 VENC_EXTRADATA_SLICEINFO = 0x100, 159 VENC_EXTRADATA_LTRINFO = 0x200, 160 VENC_EXTRADATA_MBINFO = 0x400, 161 VENC_EXTRADATA_FRAMEDIMENSION = 0x1000000, 162 VENC_EXTRADATA_YUV_STATS = 0x800, 163 VENC_EXTRADATA_VQZIP = 0x02000000, 164 VENC_EXTRADATA_ROI = 0x04000000, 165 }; 166 167 struct output_metabuffer { 168 OMX_U32 type; 169 native_handle_t *nh; 170 }; 171 172 struct venc_buffer{ 173 unsigned char *ptrbuffer; 174 unsigned long sz; 175 unsigned long len; 176 unsigned long offset; 177 long long timestamp; 178 unsigned long flags; 179 void *clientdata; 180 }; 181 182 struct venc_bufferpayload{ 183 unsigned char *pbuffer; 184 size_t sz; 185 int fd; 186 unsigned int offset; 187 unsigned int maped_size; 188 unsigned long filled_len; 189 }; 190 191 struct venc_voptimingcfg{ 192 unsigned long voptime_resolution; 193 }; 194 195 struct venc_framerate{ 196 unsigned long fps_denominator; 197 unsigned long fps_numerator; 198 }; 199 200 struct venc_headerextension{ 201 unsigned long header_extension; 202 }; 203 204 struct venc_multiclicecfg{ 205 unsigned long mslice_mode; 206 unsigned long mslice_size; 207 }; 208 209 struct venc_msg{ 210 unsigned long statuscode; 211 unsigned long msgcode; 212 struct venc_buffer buf; 213 unsigned long msgdata_size; 214 }; 215 216 typedef struct encoder_meta_buffer_payload_type { 217 char data[sizeof(LEGACY_CAM_METADATA_TYPE) + sizeof(int)]; 218 } encoder_meta_buffer_payload_type; 219 220 // OMX video class 221 class omx_video: public qc_omx_component 222 { 223 protected: 224 #ifdef _ANDROID_ICS_ 225 bool meta_mode_enable; 226 bool c2d_opened; 227 encoder_meta_buffer_payload_type meta_buffers[MAX_NUM_INPUT_BUFFERS]; 228 OMX_BUFFERHEADERTYPE *opaque_buffer_hdr[MAX_NUM_INPUT_BUFFERS]; 229 bool get_syntaxhdr_enable; 230 OMX_BUFFERHEADERTYPE *psource_frame; 231 OMX_BUFFERHEADERTYPE *pdest_frame; 232 bool secure_session; 233 bool hier_b_enabled; 234 C2DColorConverter c2dcc; 235 ColorMapping mMapPixelFormat2Converter; 236 237 #endif 238 public: 239 240 bool mUseProxyColorFormat; 241 //RGB or non-native input, and we have pre-allocated conversion buffers 242 bool mUsesColorConversion; 243 ColorConvertFormat mC2dSrcFmt; 244 ColorConvertFormat mC2dDestFmt; 245 OMX_U32 mC2DFrameHeight; 246 OMX_U32 mC2DFrameWidth; 247 248 omx_video(); // constructor 249 virtual ~omx_video(); // destructor 250 251 // virtual int async_message_process (void *context, void* message); 252 void process_event_cb(void *ctxt); 253 254 OMX_ERRORTYPE allocate_buffer( 255 OMX_HANDLETYPE hComp, 256 OMX_BUFFERHEADERTYPE **bufferHdr, 257 OMX_U32 port, 258 OMX_PTR appData, 259 OMX_U32 bytes 260 ); 261 262 263 virtual OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp)= 0; 264 265 virtual OMX_ERRORTYPE component_init(OMX_STRING role)= 0; 266 267 virtual OMX_U32 dev_stop(void) = 0; 268 virtual OMX_U32 dev_pause(void) = 0; 269 virtual OMX_U32 dev_start(void) = 0; 270 virtual OMX_U32 dev_flush(unsigned) = 0; 271 virtual OMX_U32 dev_resume(void) = 0; 272 virtual OMX_U32 dev_start_done(void) = 0; 273 virtual OMX_U32 dev_set_message_thread_id(pthread_t) = 0; 274 virtual bool dev_use_buf(unsigned) = 0; 275 virtual bool dev_handle_empty_eos_buffer(void) = 0; 276 virtual bool dev_free_buf(void *,unsigned) = 0; 277 virtual bool dev_empty_buf(void *, void *,unsigned,unsigned) = 0; 278 virtual bool dev_fill_buf(void *buffer, void *,unsigned,unsigned) = 0; 279 virtual bool dev_get_buf_req(OMX_U32 *,OMX_U32 *,OMX_U32 *,OMX_U32) = 0; 280 virtual bool dev_get_dimensions(OMX_U32 ,OMX_U32 *,OMX_U32 *) = 0; 281 virtual bool is_streamon_done(OMX_U32 port) = 0; 282 virtual bool dev_get_seq_hdr(void *, unsigned, unsigned *) = 0; 283 virtual bool dev_loaded_start(void) = 0; 284 virtual bool dev_loaded_stop(void) = 0; 285 virtual bool dev_loaded_start_done(void) = 0; 286 virtual bool dev_loaded_stop_done(void) = 0; 287 virtual bool is_secure_session(void) = 0; 288 virtual int dev_handle_output_extradata(void*, int) = 0; 289 virtual int dev_set_format(int) = 0; 290 virtual bool dev_is_video_session_supported(OMX_U32 width, OMX_U32 height) = 0; 291 virtual bool dev_get_capability_ltrcount(OMX_U32 *, OMX_U32 *, OMX_U32 *) = 0; 292 virtual bool dev_get_vui_timing_info(OMX_U32 *) = 0; 293 virtual bool dev_get_vqzip_sei_info(OMX_U32 *) = 0; 294 virtual bool dev_get_peak_bitrate(OMX_U32 *) = 0; 295 virtual bool dev_get_batch_size(OMX_U32 *) = 0; 296 virtual bool dev_buffer_ready_to_queue(OMX_BUFFERHEADERTYPE *buffer) = 0; 297 virtual bool dev_get_temporal_layer_caps(OMX_U32 * /*nMaxLayers*/, 298 OMX_U32 * /*nMaxBLayers*/, OMX_VIDEO_ANDROID_TEMPORALLAYERINGPATTERNTYPE */*SupportedPattern*/) = 0; 299 virtual OMX_ERRORTYPE dev_get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *) = 0; 300 virtual bool dev_get_supported_color_format(unsigned index, OMX_U32 *colorFormat) = 0; 301 #ifdef _ANDROID_ICS_ 302 void omx_release_meta_buffer(OMX_BUFFERHEADERTYPE *buffer); 303 #endif 304 virtual bool dev_color_align(OMX_BUFFERHEADERTYPE *buffer, OMX_U32 width, 305 OMX_U32 height) = 0; 306 virtual bool dev_get_output_log_flag() = 0; 307 virtual int dev_output_log_buffers(const char *buffer_addr, int buffer_len, uint64_t timestamp) = 0; 308 virtual int dev_extradata_log_buffers(char *buffer_addr) = 0; 309 virtual bool dev_get_hevc_profile(OMX_U32*) = 0; 310 OMX_ERRORTYPE component_role_enum( 311 OMX_HANDLETYPE hComp, 312 OMX_U8 *role, 313 OMX_U32 index 314 ); 315 316 OMX_ERRORTYPE component_tunnel_request( 317 OMX_HANDLETYPE hComp, 318 OMX_U32 port, 319 OMX_HANDLETYPE peerComponent, 320 OMX_U32 peerPort, 321 OMX_TUNNELSETUPTYPE *tunnelSetup 322 ); 323 324 OMX_ERRORTYPE empty_this_buffer( 325 OMX_HANDLETYPE hComp, 326 OMX_BUFFERHEADERTYPE *buffer 327 ); 328 329 330 331 OMX_ERRORTYPE fill_this_buffer( 332 OMX_HANDLETYPE hComp, 333 OMX_BUFFERHEADERTYPE *buffer 334 ); 335 336 337 OMX_ERRORTYPE free_buffer( 338 OMX_HANDLETYPE hComp, 339 OMX_U32 port, 340 OMX_BUFFERHEADERTYPE *buffer 341 ); 342 343 OMX_ERRORTYPE get_component_version( 344 OMX_HANDLETYPE hComp, 345 OMX_STRING componentName, 346 OMX_VERSIONTYPE *componentVersion, 347 OMX_VERSIONTYPE *specVersion, 348 OMX_UUIDTYPE *componentUUID 349 ); 350 351 OMX_ERRORTYPE get_config( 352 OMX_HANDLETYPE hComp, 353 OMX_INDEXTYPE configIndex, 354 OMX_PTR configData 355 ); 356 357 OMX_ERRORTYPE get_extension_index( 358 OMX_HANDLETYPE hComp, 359 OMX_STRING paramName, 360 OMX_INDEXTYPE *indexType 361 ); 362 363 OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp, 364 OMX_INDEXTYPE paramIndex, 365 OMX_PTR paramData); 366 367 OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp, 368 OMX_STATETYPE *state); 369 370 371 372 OMX_ERRORTYPE send_command(OMX_HANDLETYPE hComp, 373 OMX_COMMANDTYPE cmd, 374 OMX_U32 param1, 375 OMX_PTR cmdData); 376 377 378 OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE hComp, 379 OMX_CALLBACKTYPE *callbacks, 380 OMX_PTR appData); 381 382 virtual OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp, 383 OMX_INDEXTYPE configIndex, 384 OMX_PTR configData) = 0; 385 386 virtual OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp, 387 OMX_INDEXTYPE paramIndex, 388 OMX_PTR paramData) =0; 389 390 OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE hComp, 391 OMX_BUFFERHEADERTYPE **bufferHdr, 392 OMX_U32 port, 393 OMX_PTR appData, 394 OMX_U32 bytes, 395 OMX_U8 *buffer); 396 397 398 OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE hComp, 399 OMX_BUFFERHEADERTYPE **bufferHdr, 400 OMX_U32 port, 401 OMX_PTR appData, 402 void * eglImage); 403 404 Signal signal; 405 406 bool reject_param_for_TME_mode(int index); 407 bool reject_config_for_TME_mode(int index); 408 409 pthread_t msg_thread_id; 410 pthread_t async_thread_id; 411 bool async_thread_created; 412 bool msg_thread_created; 413 volatile bool msg_thread_stop; 414 415 OMX_U8 m_nkind[128]; 416 417 418 //int *input_pmem_fd; 419 //int *output_pmem_fd; 420 struct pmem *m_pInput_pmem; 421 struct pmem *m_pOutput_pmem; 422 #ifdef USE_ION 423 struct venc_ion *m_pInput_ion; 424 struct venc_ion *m_pOutput_ion; 425 #endif 426 427 428 429 public: 430 // Bit Positions 431 enum flags_bit_positions { 432 // Defer transition to IDLE 433 OMX_COMPONENT_IDLE_PENDING =0x1, 434 // Defer transition to LOADING 435 OMX_COMPONENT_LOADING_PENDING =0x2, 436 // First Buffer Pending 437 OMX_COMPONENT_FIRST_BUFFER_PENDING =0x3, 438 // Second Buffer Pending 439 OMX_COMPONENT_SECOND_BUFFER_PENDING =0x4, 440 // Defer transition to Enable 441 OMX_COMPONENT_INPUT_ENABLE_PENDING =0x5, 442 // Defer transition to Enable 443 OMX_COMPONENT_OUTPUT_ENABLE_PENDING =0x6, 444 // Defer transition to Disable 445 OMX_COMPONENT_INPUT_DISABLE_PENDING =0x7, 446 // Defer transition to Disable 447 OMX_COMPONENT_OUTPUT_DISABLE_PENDING =0x8, 448 //defer flush notification 449 OMX_COMPONENT_OUTPUT_FLUSH_PENDING =0x9, 450 OMX_COMPONENT_INPUT_FLUSH_PENDING =0xA, 451 OMX_COMPONENT_PAUSE_PENDING =0xB, 452 OMX_COMPONENT_EXECUTE_PENDING =0xC, 453 OMX_COMPONENT_LOADED_START_PENDING = 0xD, 454 OMX_COMPONENT_LOADED_STOP_PENDING = 0xF, 455 456 }; 457 458 // Deferred callback identifiers 459 enum { 460 //Event Callbacks from the venc component thread context 461 OMX_COMPONENT_GENERATE_EVENT = 0x1, 462 //Buffer Done callbacks from the venc component thread context 463 OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2, 464 //Frame Done callbacks from the venc component thread context 465 OMX_COMPONENT_GENERATE_FRAME_DONE = 0x3, 466 //Buffer Done callbacks from the venc component thread context 467 OMX_COMPONENT_GENERATE_FTB = 0x4, 468 //Frame Done callbacks from the venc component thread context 469 OMX_COMPONENT_GENERATE_ETB = 0x5, 470 //Command 471 OMX_COMPONENT_GENERATE_COMMAND = 0x6, 472 //Push-Pending Buffers 473 OMX_COMPONENT_PUSH_PENDING_BUFS = 0x7, 474 // Empty Buffer Done callbacks 475 OMX_COMPONENT_GENERATE_EBD = 0x8, 476 //Flush Event Callbacks from the venc component thread context 477 OMX_COMPONENT_GENERATE_EVENT_FLUSH = 0x9, 478 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A, 479 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B, 480 OMX_COMPONENT_GENERATE_FBD = 0xc, 481 OMX_COMPONENT_GENERATE_START_DONE = 0xD, 482 OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE, 483 OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF, 484 OMX_COMPONENT_GENERATE_STOP_DONE = 0x10, 485 OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11, 486 OMX_COMPONENT_GENERATE_LTRUSE_FAILED = 0x12, 487 OMX_COMPONENT_GENERATE_ETB_OPQ = 0x13, 488 OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x14, 489 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD = 0x15, 490 OMX_COMPONENT_CLOSE_MSG = 0x16 491 }; 492 493 struct omx_event { 494 unsigned long param1; 495 unsigned long param2; 496 unsigned long id; 497 }; 498 499 struct omx_cmd_queue { 500 omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE]; 501 unsigned long m_read; 502 unsigned long m_write; 503 unsigned long m_size; 504 505 omx_cmd_queue(); 506 ~omx_cmd_queue(); 507 bool insert_entry(unsigned long p1, unsigned long p2, unsigned long id); 508 bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned long *id); 509 // get msgtype of the first ele from the queue 510 unsigned get_q_msg_type(); 511 512 }; 513 514 bool allocate_done(void); 515 bool allocate_input_done(void); 516 bool allocate_output_done(void); 517 bool allocate_output_extradata_done(void); 518 519 OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 520 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr); 521 void free_output_extradata_buffer_header(); 522 523 OMX_ERRORTYPE allocate_client_output_extradata_headers(); 524 525 OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE hComp, 526 OMX_BUFFERHEADERTYPE **bufferHdr, 527 OMX_U32 port, 528 OMX_PTR appData, 529 OMX_U32 bytes); 530 #ifdef _ANDROID_ICS_ 531 OMX_ERRORTYPE allocate_input_meta_buffer(OMX_HANDLETYPE hComp, 532 OMX_BUFFERHEADERTYPE **bufferHdr, 533 OMX_PTR appData, 534 OMX_U32 bytes); 535 #endif 536 OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE hComp, 537 OMX_BUFFERHEADERTYPE **bufferHdr, 538 OMX_U32 port,OMX_PTR appData, 539 OMX_U32 bytes); 540 541 OMX_ERRORTYPE use_input_buffer(OMX_HANDLETYPE hComp, 542 OMX_BUFFERHEADERTYPE **bufferHdr, 543 OMX_U32 port, 544 OMX_PTR appData, 545 OMX_U32 bytes, 546 OMX_U8 *buffer); 547 548 OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp, 549 OMX_BUFFERHEADERTYPE **bufferHdr, 550 OMX_U32 port, 551 OMX_PTR appData, 552 OMX_U32 bytes, 553 OMX_U8 *buffer); 554 555 OMX_ERRORTYPE use_client_output_extradata_buffer(OMX_HANDLETYPE hComp, 556 OMX_BUFFERHEADERTYPE **bufferHdr, 557 OMX_U32 port, 558 OMX_PTR appData, 559 OMX_U32 bytes, 560 OMX_U8 *buffer); 561 562 bool execute_omx_flush(OMX_U32); 563 bool execute_output_flush(void); 564 bool execute_input_flush(void); 565 bool execute_flush_all(void); 566 OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp, 567 OMX_BUFFERHEADERTYPE * buffer); 568 569 OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp, 570 OMX_BUFFERHEADERTYPE * buffer); 571 OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE hComp, 572 OMX_BUFFERHEADERTYPE *buffer); 573 OMX_ERRORTYPE empty_this_buffer_opaque(OMX_HANDLETYPE hComp, 574 OMX_BUFFERHEADERTYPE *buffer); 575 OMX_ERRORTYPE push_input_buffer(OMX_HANDLETYPE hComp); 576 OMX_ERRORTYPE convert_queue_buffer(OMX_HANDLETYPE hComp, 577 struct pmem &Input_pmem_info,unsigned long &index); 578 OMX_ERRORTYPE queue_meta_buffer(OMX_HANDLETYPE hComp); 579 OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE hComp, 580 OMX_BUFFERHEADERTYPE *buffer); 581 bool release_done(); 582 OMX_ERRORTYPE handle_empty_eos_buffer(); 583 584 bool release_output_done(); 585 bool release_input_done(); 586 bool release_output_extradata_done(); 587 588 OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE hComp, 589 OMX_COMMANDTYPE cmd, 590 OMX_U32 param1, 591 OMX_PTR cmdData); 592 bool post_event( unsigned long p1, 593 unsigned long p2, 594 unsigned long id 595 ); 596 omx_report_error()597 inline void omx_report_error () { 598 if (m_pCallbacks.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 599 m_error_propogated = true; 600 DEBUG_PRINT_ERROR("ERROR: send OMX_ErrorHardware to Client"); 601 m_pCallbacks.EventHandler(&m_cmp,m_app_data, 602 OMX_EventError,OMX_ErrorHardware,0,NULL); 603 } 604 } 605 omx_report_hw_overload()606 inline void omx_report_hw_overload () 607 { 608 if (m_pCallbacks.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 609 m_error_propogated = true; 610 DEBUG_PRINT_ERROR("ERROR: send OMX_ErrorInsufficientResources to Client"); 611 m_pCallbacks.EventHandler(&m_cmp, m_app_data, 612 OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL); 613 } 614 } 615 omx_report_unsupported_setting()616 inline void omx_report_unsupported_setting () { 617 if (m_pCallbacks.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) { 618 m_error_propogated = true; 619 m_pCallbacks.EventHandler(&m_cmp,m_app_data, 620 OMX_EventError,OMX_ErrorUnsupportedSetting,0,NULL); 621 } 622 } 623 624 client_extradata_info m_client_out_extradata_info; 625 626 void complete_pending_buffer_done_cbs(); 627 bool is_conv_needed(int, int); 628 void print_debug_color_aspects(ColorAspects *aspects, const char *prefix); 629 630 OMX_ERRORTYPE get_vendor_extension_config( 631 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext); 632 OMX_ERRORTYPE set_vendor_extension_config( 633 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext); 634 void init_vendor_extensions(VendorExtensionStore&); 635 // Extensions-store is immutable after initialization (i.e cannot add/remove/change 636 // extensions once added !) 637 const VendorExtensionStore mVendorExtensionStore; 638 639 #ifdef USE_ION 640 int alloc_map_ion_memory(int size, 641 struct ion_allocation_data *alloc_data, 642 struct ion_fd_data *fd_data,int flag); 643 void free_ion_memory(struct venc_ion *buf_ion_info); 644 #endif 645 646 //************************************************************* 647 //*******************MEMBER VARIABLES ************************* 648 //************************************************************* 649 650 pthread_mutex_t m_lock; 651 sem_t m_cmd_lock; 652 bool m_error_propogated; 653 654 //sem to handle the minimum procesing of commands 655 656 657 // compression format 658 //OMX_VIDEO_CODINGTYPE eCompressionFormat; 659 // OMX State 660 OMX_STATETYPE m_state; 661 // Application data 662 OMX_PTR m_app_data; 663 OMX_BOOL m_use_input_pmem; 664 OMX_BOOL m_use_output_pmem; 665 // Application callbacks 666 OMX_CALLBACKTYPE m_pCallbacks; 667 OMX_PORT_PARAM_TYPE m_sPortParam; 668 OMX_VIDEO_PARAM_PROFILELEVELTYPE m_sParamProfileLevel; 669 OMX_VIDEO_PARAM_PORTFORMATTYPE m_sInPortFormat; 670 OMX_VIDEO_PARAM_PORTFORMATTYPE m_sOutPortFormat; 671 OMX_PARAM_PORTDEFINITIONTYPE m_sInPortDef; 672 OMX_PARAM_PORTDEFINITIONTYPE m_sOutPortDef; 673 OMX_VIDEO_PARAM_MPEG4TYPE m_sParamMPEG4; 674 OMX_VIDEO_PARAM_H263TYPE m_sParamH263; 675 OMX_VIDEO_PARAM_AVCTYPE m_sParamAVC; 676 OMX_VIDEO_PARAM_VP8TYPE m_sParamVP8; 677 OMX_VIDEO_PARAM_HEVCTYPE m_sParamHEVC; 678 QOMX_VIDEO_PARAM_TMETYPE m_sParamTME; 679 OMX_U32 tme_payload_version; 680 OMX_PORT_PARAM_TYPE m_sPortParam_img; 681 OMX_PORT_PARAM_TYPE m_sPortParam_audio; 682 OMX_VIDEO_CONFIG_BITRATETYPE m_sConfigBitrate; 683 OMX_CONFIG_FRAMERATETYPE m_sConfigFramerate; 684 OMX_VIDEO_PARAM_BITRATETYPE m_sParamBitrate; 685 OMX_PRIORITYMGMTTYPE m_sPriorityMgmt; 686 OMX_PARAM_BUFFERSUPPLIERTYPE m_sInBufSupplier; 687 OMX_PARAM_BUFFERSUPPLIERTYPE m_sOutBufSupplier; 688 OMX_CONFIG_ROTATIONTYPE m_sConfigFrameRotation; 689 OMX_CONFIG_MIRRORTYPE m_sConfigFrameMirror; 690 OMX_CONFIG_INTRAREFRESHVOPTYPE m_sConfigIntraRefreshVOP; 691 OMX_U32 m_QPSet; 692 OMX_VIDEO_PARAM_QUANTIZATIONTYPE m_sSessionQuantization; 693 OMX_QCOM_VIDEO_PARAM_IPB_QPRANGETYPE m_sSessionQPRange; 694 OMX_VIDEO_PARAM_AVCSLICEFMO m_sAVCSliceFMO; 695 QOMX_VIDEO_INTRAPERIODTYPE m_sIntraperiod; 696 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE m_sErrorCorrection; 697 QOMX_VIDEO_PARAM_SLICE_SPACING_TYPE m_sSliceSpacing; 698 OMX_VIDEO_PARAM_INTRAREFRESHTYPE m_sIntraRefresh; 699 QOMX_VIDEO_PARAM_LTRCOUNT_TYPE m_sParamLTRCount; 700 QOMX_VIDEO_CONFIG_LTRUSE_TYPE m_sConfigLTRUse; 701 QOMX_VIDEO_CONFIG_LTRMARK_TYPE m_sConfigLTRMark; 702 OMX_VIDEO_CONFIG_AVCINTRAPERIOD m_sConfigAVCIDRPeriod; 703 OMX_VIDEO_CONFIG_DEINTERLACE m_sConfigDeinterlace; 704 OMX_VIDEO_VP8REFERENCEFRAMETYPE m_sConfigVp8ReferenceFrame; 705 QOMX_VIDEO_HIERARCHICALLAYERS m_sHierLayers; 706 QOMX_EXTNINDEX_VIDEO_HIER_P_LAYERS m_sHPlayers; 707 OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID m_sBaseLayerID; 708 OMX_SKYPE_VIDEO_PARAM_DRIVERVER m_sDriverVer; 709 OMX_QCOM_VIDEO_CONFIG_QP m_sConfigQP; 710 QOMX_EXTNINDEX_VIDEO_VENC_SAR m_sSar; 711 QOMX_VIDEO_H264ENTROPYCODINGTYPE m_sParamEntropy; 712 QOMX_INDEXDOWNSCALAR m_sParamDownScalar; 713 PrependSPSPPSToIDRFramesParams m_sPrependSPSPPS; 714 struct timestamp_info { 715 OMX_S64 ts; 716 omx_cmd_queue deferred_inbufq; 717 pthread_mutex_t m_lock; 718 } m_TimeStampInfo; 719 OMX_U32 m_sExtraData; 720 OMX_U32 m_sParamConsumerUsage; 721 OMX_U32 m_input_msg_id; 722 OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE m_sConfigIntraRefresh; 723 OMX_QTI_VIDEO_CONFIG_BLURINFO m_blurInfo; 724 DescribeColorAspectsParams m_sConfigColorAspects; 725 OMX_VIDEO_PARAM_ANDROID_TEMPORALLAYERINGTYPE m_sParamTemporalLayers; 726 OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE m_sConfigTemporalLayers; 727 QOMX_ENABLETYPE m_sParamAVTimerTimestampMode; // use VT-timestamps in gralloc-handle 728 QOMX_ENABLETYPE m_sParamControlInputQueue; 729 OMX_TIME_CONFIG_TIMESTAMPTYPE m_sConfigInputTrigTS; 730 QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE m_sParamLowLatency; 731 OMX_U32 m_nOperatingRate; 732 QOMX_ENABLETYPE m_sParamColorSpaceConversion; 733 OMX_VIDEO_PARAM_ANDROID_IMAGEGRIDTYPE m_sParamAndroidImageGrid; 734 735 // fill this buffer queue 736 omx_cmd_queue m_ftb_q; 737 // Command Q for rest of the events 738 omx_cmd_queue m_cmd_q; 739 omx_cmd_queue m_etb_q; 740 // Input memory pointer 741 OMX_BUFFERHEADERTYPE *m_inp_mem_ptr; 742 // Output memory pointer 743 OMX_BUFFERHEADERTYPE *m_out_mem_ptr; 744 // Client extradata memory pointer 745 OMX_BUFFERHEADERTYPE *m_client_output_extradata_mem_ptr; 746 omx_cmd_queue m_opq_meta_q; 747 omx_cmd_queue m_opq_pmem_q; 748 OMX_BUFFERHEADERTYPE meta_buffer_hdr[MAX_NUM_INPUT_BUFFERS]; 749 pthread_mutex_t m_buf_lock; 750 751 bool input_flush_progress; 752 bool output_flush_progress; 753 bool input_use_buffer; 754 bool output_use_buffer; 755 int pending_input_buffers; 756 int pending_output_buffers; 757 758 bool allocate_native_handle; 759 760 uint64_t m_out_bm_count; 761 uint64_t m_client_out_bm_count; 762 uint64_t m_client_in_bm_count; 763 uint64_t m_inp_bm_count; 764 // bitmask array size for extradata 765 uint64_t m_out_extradata_bm_count; 766 uint64_t m_flags; 767 uint64_t m_etb_count; 768 uint64_t m_fbd_count; 769 OMX_TICKS m_etb_timestamp; 770 // to know whether Event Port Settings change has been triggered or not. 771 bool m_event_port_settings_sent; 772 OMX_U8 m_cRole[OMX_MAX_STRINGNAME_SIZE]; 773 bool hw_overload; 774 size_t m_graphicbuffer_size; 775 char m_platform[OMX_MAX_STRINGNAME_SIZE]; 776 777 bool m_buffer_freed; 778 }; 779 780 #endif // __OMX_VIDEO_BASE_H__ 781