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