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