1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010 - 2015, 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
6   are met:
7 
8     * Redistributions of source code must retain the above copyright
9   notice, this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above
11   copyright notice, this list of conditions and the following
12       disclaimer in the documentation and/or other materials provided
13       with the distribution.
14     * Neither the name of The Linux Foundation nor the names of its
15       contributors may be used to endorse or promote products derived
16       from this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
21 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 --------------------------------------------------------------------------*/
30 #ifndef __OMX_VDEC_H__
31 #define __OMX_VDEC_H__
32 /*============================================================================
33                             O p e n M A X   Component
34                                 Video Decoder
35 
36 *//** @file comx_vdec.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 <string.h>
48 #include <inttypes.h>
49 #include <cstddef>
50 #include <cutils/atomic.h>
51 
52 static ptrdiff_t x;
53 
54 #ifdef _ANDROID_
55 #ifdef MAX_RES_720P
56 #define LOG_TAG "OMX-VDEC-720P"
57 #elif MAX_RES_1080P
58 #define LOG_TAG "OMX-VDEC-1080P"
59 #else
60 #define LOG_TAG "OMX-VDEC"
61 #endif
62 
63 #ifdef USE_ION
64 #include <linux/msm_ion.h>
65 //#include <binder/MemoryHeapIon.h>
66 //#else
67 #endif
68 #include <binder/MemoryHeapBase.h>
69 #include <ui/ANativeObjectBase.h>
70 extern "C" {
71 #include <utils/Log.h>
72 }
73 #include <linux/videodev2.h>
74 #include <poll.h>
75 #include "hevc_utils.h"
76 #define TIMEOUT 5000
77 #endif // _ANDROID_
78 
79 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
80 #include <media/hardware/HardwareAPI.h>
81 #endif
82 
83 #include <unistd.h>
84 
85 #if defined (_ANDROID_ICS_)
86 #include <gralloc_priv.h>
87 #endif
88 
89 #include <pthread.h>
90 #ifndef PC_DEBUG
91 #include <semaphore.h>
92 #endif
93 #include "OMX_Core.h"
94 #include "OMX_QCOMExtns.h"
95 #include "OMX_Skype_VideoExtensions.h"
96 #include "OMX_VideoExt.h"
97 #include "OMX_IndexExt.h"
98 #include "qc_omx_component.h"
99 #include <linux/msm_vidc_dec.h>
100 #include <media/msm_vidc.h>
101 #include "frameparser.h"
102 #ifdef MAX_RES_1080P
103 #include "mp4_utils.h"
104 #endif
105 #include "extra_data_handler.h"
106 #include "ts_parser.h"
107 #include "vidc_color_converter.h"
108 #include "vidc_debug.h"
109 #ifdef _ANDROID_
110 #include <cutils/properties.h>
111 #else
112 #define PROPERTY_VALUE_MAX 92
113 #endif
114 extern "C" {
115     OMX_API void * get_omx_component_factory_fn(void);
116 }
117 
118 #ifdef _ANDROID_
119 using namespace android;
120 #ifdef USE_ION
121 class VideoHeap : public MemoryHeapBase
122 {
123     public:
124         VideoHeap(int devicefd, size_t size, void* base,ion_user_handle_t handle,int mapfd);
~VideoHeap()125         virtual ~VideoHeap() {}
126     private:
127         int m_ion_device_fd;
128         ion_user_handle_t m_ion_handle;
129 };
130 #else
131 // local pmem heap object
132 class VideoHeap : public MemoryHeapBase
133 {
134     public:
135         VideoHeap(int fd, size_t size, void* base);
~VideoHeap()136         virtual ~VideoHeap() {}
137 };
138 #endif
139 #endif // _ANDROID_
140 //////////////////////////////////////////////////////////////////////////////
141 //                       Module specific globals
142 //////////////////////////////////////////////////////////////////////////////
143 #define OMX_SPEC_VERSION  0x00000101
144 
145 
146 //////////////////////////////////////////////////////////////////////////////
147 //               Macros
148 //////////////////////////////////////////////////////////////////////////////
149 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\
150         (unsigned) bufHdr,\
151         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\
152         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\
153         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp)
154 
155 // BitMask Management logic
156 #define BITS_PER_INDEX        64
157 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_INDEX - 1)/BITS_PER_INDEX)
158 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_INDEX)
159 #define BITMASK_FLAG(mIndex) ((uint64_t)1 << ((mIndex) % BITS_PER_INDEX))
160 #define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \
161     &=  ~(BITMASK_FLAG(mIndex))
162 #define BITMASK_SET(mArray,mIndex)  (mArray)[BITMASK_OFFSET(mIndex)] \
163     |=  BITMASK_FLAG(mIndex)
164 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
165         & BITMASK_FLAG(mIndex))
166 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
167             & BITMASK_FLAG(mIndex)) == 0x0)
168 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
169         & BITMASK_FLAG(mIndex))
170 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
171             & BITMASK_FLAG(mIndex)) == 0x0)
172 
173 #define OMX_CORE_CONTROL_CMDQ_SIZE   100
174 #define OMX_CORE_QCIF_HEIGHT         144
175 #define OMX_CORE_QCIF_WIDTH          176
176 #define OMX_CORE_VGA_HEIGHT          480
177 #define OMX_CORE_VGA_WIDTH           640
178 #define OMX_CORE_WVGA_HEIGHT         480
179 #define OMX_CORE_WVGA_WIDTH          800
180 
181 #define DESC_BUFFER_SIZE (8192 * 16)
182 
183 #ifdef _ANDROID_
184 #define MAX_NUM_INPUT_OUTPUT_BUFFERS 64
185 #endif
186 
187 #define OMX_FRAMEINFO_EXTRADATA 0x00010000
188 #define OMX_INTERLACE_EXTRADATA 0x00020000
189 #define OMX_TIMEINFO_EXTRADATA  0x00040000
190 #define OMX_PORTDEF_EXTRADATA   0x00080000
191 #define OMX_EXTNUSER_EXTRADATA  0x00100000
192 #define OMX_FRAMEDIMENSION_EXTRADATA  0x00200000
193 #define OMX_FRAMEPACK_EXTRADATA 0x00400000
194 #define OMX_QP_EXTRADATA        0x00800000
195 #define OMX_BITSINFO_EXTRADATA  0x01000000
196 #define OMX_VQZIPSEI_EXTRADATA  0x02000000
197 
198 #define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
199             sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3))
200 #define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
201             sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3))
202 #define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
203             sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3))
204 #define OMX_FRAMEDIMENSION_EXTRADATA_SIZE (sizeof(OMX_OTHER_EXTRADATATYPE) +\
205             sizeof(OMX_QCOM_EXTRADATA_FRAMEDIMENSION) + 3)&(~3)
206 #define OMX_FRAMEPACK_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
207             sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT) + 3)&(~3))
208 #define OMX_QP_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
209             sizeof(OMX_QCOM_EXTRADATA_QP) + 3)&(~3))
210 #define OMX_BITSINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
211             sizeof(OMX_QCOM_EXTRADATA_BITS_INFO) + 3)&(~3))
212 #define OMX_VQZIPSEI_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
213             sizeof(OMX_QCOM_EXTRADATA_VQZIPSEI) + 3)&(~3))
214 #define OMX_USERDATA_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
215             + 3)&(~3))
216 
217 //  Define next macro with required values to enable default extradata,
218 //    VDEC_EXTRADATA_MB_ERROR_MAP
219 //    OMX_INTERLACE_EXTRADATA
220 //    OMX_FRAMEINFO_EXTRADATA
221 //    OMX_TIMEINFO_EXTRADATA
222 
223 //#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA)
224 
225 enum port_indexes {
226     OMX_CORE_INPUT_PORT_INDEX        =0,
227     OMX_CORE_OUTPUT_PORT_INDEX       =1
228 };
229 enum vidc_perf_level {
230     VIDC_SVS = 0,
231     VIDC_NOMINAL = 1,
232     VIDC_TURBO = 2
233 };
234 #ifdef USE_ION
235 struct vdec_ion {
236     int ion_device_fd;
237     struct ion_fd_data fd_ion_data;
238     struct ion_allocation_data ion_alloc_data;
239 };
240 #endif
241 
242 #ifdef _MSM8974_
243 struct extradata_buffer_info {
244     unsigned long buffer_size;
245     char* uaddr;
246     int count;
247     int size;
248 #ifdef USE_ION
249     struct vdec_ion ion;
250 #endif
251 };
252 #endif
253 
254 struct video_driver_context {
255     int video_driver_fd;
256     enum vdec_codec decoder_format;
257     enum vdec_output_fromat output_format;
258     enum vdec_interlaced_format interlace;
259     enum vdec_output_order picture_order;
260     struct vdec_framesize frame_size;
261     struct vdec_picsize video_resolution;
262     struct vdec_allocatorproperty ip_buf;
263     struct vdec_allocatorproperty op_buf;
264     struct vdec_bufferpayload *ptr_inputbuffer;
265     struct vdec_bufferpayload *ptr_outputbuffer;
266     struct vdec_output_frameinfo *ptr_respbuffer;
267 #ifdef USE_ION
268     struct vdec_ion *ip_buf_ion_info;
269     struct vdec_ion *op_buf_ion_info;
270     struct vdec_ion h264_mv;
271     struct vdec_ion meta_buffer;
272     struct vdec_ion meta_buffer_iommu;
273 #endif
274     struct vdec_framerate frame_rate;
275     unsigned extradata;
276     bool timestamp_adjust;
277     char kind[128];
278     bool idr_only_decoding;
279     unsigned disable_dmx;
280 #ifdef _MSM8974_
281     struct extradata_buffer_info extradata_info;
282     int num_planes;
283 #endif
284 };
285 
286 struct video_decoder_capability {
287     unsigned int min_width;
288     unsigned int max_width;
289     unsigned int min_height;
290     unsigned int max_height;
291 };
292 
293 struct debug_cap {
294     bool in_buffer_log;
295     bool out_buffer_log;
296     bool out_meta_buffer_log;
297     char infile_name[PROPERTY_VALUE_MAX + 36];
298     char outfile_name[PROPERTY_VALUE_MAX + 36];
299     char out_ymetafile_name[PROPERTY_VALUE_MAX + 36];
300     char out_uvmetafile_name[PROPERTY_VALUE_MAX + 36];
301     char log_loc[PROPERTY_VALUE_MAX];
302     FILE *infile;
303     FILE *outfile;
304     FILE *out_ymeta_file;
305     FILE *out_uvmeta_file;
306 };
307 
308 struct dynamic_buf_list {
309     long fd;
310     long dup_fd;
311     OMX_U32 offset;
312     OMX_U32 ref_count;
313     void *buffaddr;
314     long mapped_size;
315 };
316 
317 // OMX video decoder class
318 class omx_vdec: public qc_omx_component
319 {
320 
321     public:
322         omx_vdec();  // constructor
323         virtual ~omx_vdec();  // destructor
324 
325         static int async_message_process (void *context, void* message);
326         static void process_event_cb(void *ctxt,unsigned char id);
327 
328         OMX_ERRORTYPE allocate_buffer(
329                 OMX_HANDLETYPE hComp,
330                 OMX_BUFFERHEADERTYPE **bufferHdr,
331                 OMX_U32 port,
332                 OMX_PTR appData,
333                 OMX_U32 bytes
334                 );
335 
336 
337         OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);
338 
339         OMX_ERRORTYPE component_init(OMX_STRING role);
340 
341         OMX_ERRORTYPE component_role_enum(
342                 OMX_HANDLETYPE hComp,
343                 OMX_U8 *role,
344                 OMX_U32 index
345                 );
346 
347         OMX_ERRORTYPE component_tunnel_request(
348                 OMX_HANDLETYPE hComp,
349                 OMX_U32 port,
350                 OMX_HANDLETYPE  peerComponent,
351                 OMX_U32 peerPort,
352                 OMX_TUNNELSETUPTYPE *tunnelSetup
353                 );
354 
355         OMX_ERRORTYPE empty_this_buffer(
356                 OMX_HANDLETYPE hComp,
357                 OMX_BUFFERHEADERTYPE *buffer
358                 );
359 
360 
361 
362         OMX_ERRORTYPE fill_this_buffer(
363                 OMX_HANDLETYPE hComp,
364                 OMX_BUFFERHEADERTYPE *buffer
365                 );
366 
367 
368         OMX_ERRORTYPE free_buffer(
369                 OMX_HANDLETYPE hComp,
370                 OMX_U32 port,
371                 OMX_BUFFERHEADERTYPE *buffer
372                 );
373 
374         OMX_ERRORTYPE get_component_version(
375                 OMX_HANDLETYPE hComp,
376                 OMX_STRING componentName,
377                 OMX_VERSIONTYPE *componentVersion,
378                 OMX_VERSIONTYPE *specVersion,
379                 OMX_UUIDTYPE *componentUUID
380                 );
381 
382         OMX_ERRORTYPE get_config(
383                 OMX_HANDLETYPE hComp,
384                 OMX_INDEXTYPE configIndex,
385                 OMX_PTR configData
386                 );
387 
388         OMX_ERRORTYPE get_extension_index(
389                 OMX_HANDLETYPE hComp,
390                 OMX_STRING paramName,
391                 OMX_INDEXTYPE *indexType
392                 );
393 
394         OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp,
395                 OMX_INDEXTYPE  paramIndex,
396                 OMX_PTR        paramData);
397 
398         OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp,
399                 OMX_STATETYPE *state);
400 
401 
402 
403         OMX_ERRORTYPE send_command(OMX_HANDLETYPE  hComp,
404                 OMX_COMMANDTYPE cmd,
405                 OMX_U32         param1,
406                 OMX_PTR         cmdData);
407 
408 
409         OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE   hComp,
410                 OMX_CALLBACKTYPE *callbacks,
411                 OMX_PTR          appData);
412 
413         OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
414                 OMX_INDEXTYPE  configIndex,
415                 OMX_PTR        configData);
416 
417         OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
418                 OMX_INDEXTYPE  paramIndex,
419                 OMX_PTR        paramData);
420 
421         OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE      hComp,
422                 OMX_BUFFERHEADERTYPE **bufferHdr,
423                 OMX_U32              port,
424                 OMX_PTR              appData,
425                 OMX_U32              bytes,
426                 OMX_U8               *buffer);
427 
428         OMX_ERRORTYPE  use_input_heap_buffers(
429                 OMX_HANDLETYPE            hComp,
430                 OMX_BUFFERHEADERTYPE** bufferHdr,
431                 OMX_U32                   port,
432                 OMX_PTR                   appData,
433                 OMX_U32                   bytes,
434                 OMX_U8*                   buffer);
435 
436         OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE     hComp,
437                 OMX_BUFFERHEADERTYPE **bufferHdr,
438                 OMX_U32              port,
439                 OMX_PTR              appData,
440                 void *               eglImage);
441         void complete_pending_buffer_done_cbs();
442         struct video_driver_context drv_ctx;
443         int m_poll_efd;
444 #ifdef _MSM8974_
445         OMX_ERRORTYPE allocate_extradata();
446         void free_extradata();
447         int update_resolution(int width, int height, int stride, int scan_lines);
448         OMX_ERRORTYPE is_video_session_supported();
449 #endif
450         int  m_pipe_in;
451         int  m_pipe_out;
452         pthread_t msg_thread_id;
453         pthread_t async_thread_id;
454         bool is_component_secure();
455         void buf_ref_add(int nPortIndex);
456         void buf_ref_remove();
457         OMX_ERRORTYPE set_dpb(bool is_split_mode, int dpb_color_format);
458         OMX_ERRORTYPE decide_dpb_buffer_mode(bool force_split_mode);
459         void request_perf_level(enum vidc_perf_level perf_level);
460         int dpb_bit_depth;
461         bool async_thread_force_stop;
462         volatile bool message_thread_stop;
463 
464     private:
465         // Bit Positions
466         enum flags_bit_positions {
467             // Defer transition to IDLE
468             OMX_COMPONENT_IDLE_PENDING            =0x1,
469             // Defer transition to LOADING
470             OMX_COMPONENT_LOADING_PENDING         =0x2,
471             // First  Buffer Pending
472             OMX_COMPONENT_FIRST_BUFFER_PENDING    =0x3,
473             // Second Buffer Pending
474             OMX_COMPONENT_SECOND_BUFFER_PENDING   =0x4,
475             // Defer transition to Enable
476             OMX_COMPONENT_INPUT_ENABLE_PENDING    =0x5,
477             // Defer transition to Enable
478             OMX_COMPONENT_OUTPUT_ENABLE_PENDING   =0x6,
479             // Defer transition to Disable
480             OMX_COMPONENT_INPUT_DISABLE_PENDING   =0x7,
481             // Defer transition to Disable
482             OMX_COMPONENT_OUTPUT_DISABLE_PENDING  =0x8,
483             //defer flush notification
484             OMX_COMPONENT_OUTPUT_FLUSH_PENDING    =0x9,
485             OMX_COMPONENT_INPUT_FLUSH_PENDING    =0xA,
486             OMX_COMPONENT_PAUSE_PENDING          =0xB,
487             OMX_COMPONENT_EXECUTE_PENDING        =0xC,
488             OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD,
489             OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE,
490             OMX_COMPONENT_FLUSH_DEFERRED = 0xF
491         };
492 
493         // Deferred callback identifiers
494         enum {
495             //Event Callbacks from the vdec component thread context
496             OMX_COMPONENT_GENERATE_EVENT       = 0x1,
497             //Buffer Done callbacks from the vdec component thread context
498             OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2,
499             //Frame Done callbacks from the vdec component thread context
500             OMX_COMPONENT_GENERATE_FRAME_DONE  = 0x3,
501             //Buffer Done callbacks from the vdec component thread context
502             OMX_COMPONENT_GENERATE_FTB         = 0x4,
503             //Frame Done callbacks from the vdec component thread context
504             OMX_COMPONENT_GENERATE_ETB         = 0x5,
505             //Command
506             OMX_COMPONENT_GENERATE_COMMAND     = 0x6,
507             //Push-Pending Buffers
508             OMX_COMPONENT_PUSH_PENDING_BUFS    = 0x7,
509             // Empty Buffer Done callbacks
510             OMX_COMPONENT_GENERATE_EBD         = 0x8,
511             //Flush Event Callbacks from the vdec component thread context
512             OMX_COMPONENT_GENERATE_EVENT_FLUSH       = 0x9,
513             OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A,
514             OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B,
515             OMX_COMPONENT_GENERATE_FBD = 0xc,
516             OMX_COMPONENT_GENERATE_START_DONE = 0xD,
517             OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE,
518             OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF,
519             OMX_COMPONENT_GENERATE_STOP_DONE = 0x10,
520             OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11,
521             OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12,
522             OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13,
523             OMX_COMPONENT_GENERATE_EOS_DONE = 0x14,
524             OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15,
525             OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16,
526             OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x17,
527             OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD = 0x18,
528             OMX_COMPONENT_CLOSE_MSG = 0x19
529         };
530 
531         enum vc1_profile_type {
532             VC1_SP_MP_RCV = 1,
533             VC1_AP = 2
534         };
535 
536 #ifdef _MSM8974_
537         enum v4l2_ports {
538             CAPTURE_PORT,
539             OUTPUT_PORT,
540             MAX_PORT
541         };
542 #endif
543 
544         struct omx_event {
545             unsigned long param1;
546             unsigned long param2;
547             unsigned long id;
548         };
549 
550         struct omx_cmd_queue {
551             omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE];
552             unsigned long m_read;
553             unsigned long m_write;
554             unsigned long m_size;
555 
556             omx_cmd_queue();
557             ~omx_cmd_queue();
558             bool insert_entry(unsigned long p1, unsigned long p2, unsigned long id);
559             bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned long *id);
560             // get msgtype of the first ele from the queue
561             unsigned get_q_msg_type();
562 
563         };
564         struct v4l2_capability cap;
565 #ifdef _ANDROID_
566         struct ts_entry {
567             OMX_TICKS timestamp;
568             bool valid;
569         };
570 
571         struct ts_arr_list {
572             ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS];
573 
574             ts_arr_list();
575             ~ts_arr_list();
576 
577             bool insert_ts(OMX_TICKS ts);
578             bool pop_min_ts(OMX_TICKS &ts);
579             bool reset_ts_list();
580         };
581 #endif
582 
583         struct desc_buffer_hdr {
584             OMX_U8 *buf_addr;
585             OMX_U32 desc_data_size;
586         };
587         bool allocate_done(void);
588         bool allocate_input_done(void);
589         bool allocate_output_done(void);
590 
591         OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
592         OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex,
593                 OMX_BUFFERHEADERTYPE *pmem_bufferHdr);
594         OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
595         void free_output_buffer_header();
596         void free_input_buffer_header();
597 
598         OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE       hComp,
599                 OMX_BUFFERHEADERTYPE **bufferHdr,
600                 OMX_U32              port,
601                 OMX_PTR              appData,
602                 OMX_U32              bytes);
603 
604 
605         OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE       hComp,
606                 OMX_BUFFERHEADERTYPE **bufferHdr,
607                 OMX_U32              port,
608                 OMX_PTR              appData,
609                 OMX_U32              bytes);
610 
611         OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE       hComp,
612                 OMX_BUFFERHEADERTYPE **bufferHdr,
613                 OMX_U32 port,OMX_PTR appData,
614                 OMX_U32              bytes);
615         OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp,
616                 OMX_BUFFERHEADERTYPE   **bufferHdr,
617                 OMX_U32                port,
618                 OMX_PTR                appData,
619                 OMX_U32                bytes,
620                 OMX_U8                 *buffer);
621         OMX_ERRORTYPE get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
622 
623         OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index);
624         OMX_ERRORTYPE allocate_output_headers();
625         bool execute_omx_flush(OMX_U32);
626         bool execute_output_flush();
627         bool execute_input_flush();
628         OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp,
629                 OMX_BUFFERHEADERTYPE * buffer);
630 
631         OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp,
632                 OMX_BUFFERHEADERTYPE * buffer);
633         OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE       hComp,
634                 OMX_BUFFERHEADERTYPE *buffer);
635 
636         OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp,
637                 OMX_BUFFERHEADERTYPE *buffer
638                 );
639 
640         OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp);
641         OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp);
642         OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp);
643         OMX_ERRORTYPE push_input_hevc (OMX_HANDLETYPE hComp);
644         OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp);
645 
646         OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
647                 OMX_BUFFERHEADERTYPE *buffer);
648         bool release_done();
649 
650         bool release_output_done();
651         bool release_input_done();
652         OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop);
653         OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop);
654         OMX_ERRORTYPE start_port_reconfig();
655         OMX_ERRORTYPE update_picture_resolution();
656         int stream_off(OMX_U32 port);
657         void adjust_timestamp(OMX_S64 &act_timestamp);
658         void set_frame_rate(OMX_S64 act_timestamp);
659         void handle_extradata_secure(OMX_BUFFERHEADERTYPE *p_buf_hdr);
660         void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr);
661         void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra);
662 #ifdef _MSM8974_
663         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
664                 OMX_U32 interlaced_format_type, bool is_mbaff);
665         OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool is_internal,
666                 bool enable = true);
667         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
668                 OMX_U32 num_conceal_mb,
669                 OMX_U32 picture_type,
670                 OMX_U32 frame_rate,
671                 OMX_TICKS time_stamp,
672                 struct msm_vidc_panscan_window_payload *panscan_payload,
673                 struct vdec_aspectratioinfo *aspect_ratio_info);
674 #else
675         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
676                 OMX_U32 interlaced_format_type, OMX_U32 buf_index);
677         OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true);
678 #endif
679         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
680                 OMX_U32 num_conceal_mb,
681                 OMX_U32 picture_type,
682                 OMX_S64 timestamp,
683                 OMX_U32 frame_rate,
684                 struct vdec_aspectratioinfo *aspect_ratio_info);
685         void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info,
686                 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info);
687         void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra);
688         OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn);
689         void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra);
690         void append_frame_dimension_extradata(OMX_OTHER_EXTRADATATYPE *extra);
691         void append_extn_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_extn);
692         void append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_user);
693         void append_concealmb_extradata(OMX_OTHER_EXTRADATATYPE *extra,
694                 OMX_OTHER_EXTRADATATYPE *p_concealmb, OMX_U8 *conceal_mb_data);
695         void append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra,
696                 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload);
697         void append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra,
698                 struct msm_vidc_frame_qp_payload *qp_payload);
699         void append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra,
700                 struct msm_vidc_frame_bits_info_payload *bits_payload);
701         void append_vqzip_extradata(OMX_OTHER_EXTRADATATYPE *extra,
702                 struct msm_vidc_vqzip_sei_payload *vqzip_payload);
703         void insert_demux_addr_offset(OMX_U32 address_offset);
704         void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr);
705         OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr);
706         OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra);
707 
708         bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
709                 OMX_U32 alignment);
710 #ifdef USE_ION
711         int alloc_map_ion_memory(OMX_U32 buffer_size,
712                 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
713                 struct ion_fd_data *fd_data,int flag);
714         void free_ion_memory(struct vdec_ion *buf_ion_info);
715 #endif
716 
717 
718         OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
719                 OMX_COMMANDTYPE cmd,
720                 OMX_U32         param1,
721                 OMX_PTR         cmdData);
722         bool post_event( unsigned long p1,
723                 unsigned long p2,
724                 unsigned long id
725                    );
clip2(int x)726         inline int clip2(int x) {
727             x = x -1;
728             x = x | x >> 1;
729             x = x | x >> 2;
730             x = x | x >> 4;
731             x = x | x >> 16;
732             x = x + 1;
733             return x;
734         }
735 
736 #ifdef MAX_RES_1080P
737         OMX_ERRORTYPE vdec_alloc_h264_mv();
738         void vdec_dealloc_h264_mv();
739         OMX_ERRORTYPE vdec_alloc_meta_buffers();
740         void vdec_dealloc_meta_buffers();
741 #endif
742 
omx_report_error()743         inline void omx_report_error () {
744             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
745                 DEBUG_PRINT_ERROR("ERROR: Sending OMX_ErrorHardware to Client");
746                 m_error_propogated = true;
747                 m_cb.EventHandler(&m_cmp,m_app_data,
748                         OMX_EventError,OMX_ErrorHardware,0,NULL);
749             }
750         }
751 
omx_report_unsupported_setting()752         inline void omx_report_unsupported_setting () {
753             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
754                 DEBUG_PRINT_ERROR(
755                         "ERROR: Sending OMX_ErrorUnsupportedSetting to Client");
756                 m_error_propogated = true;
757                 m_cb.EventHandler(&m_cmp, m_app_data,
758                         OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL);
759             }
760         }
omx_report_hw_overload()761         inline void omx_report_hw_overload () {
762             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
763                 DEBUG_PRINT_ERROR(
764                         "ERROR: Sending OMX_ErrorInsufficientResources to Client");
765                 m_error_propogated = true;
766                 m_cb.EventHandler(&m_cmp, m_app_data,
767                         OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL);
768             }
769         }
770 
771 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
772         OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data);
773 #endif
774 #if defined (_ANDROID_ICS_)
775         struct nativebuffer {
776             native_handle_t *nativehandle;
777             private_handle_t *privatehandle;
778             int inuse;
779         };
780         nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
781 #endif
782 
783         //*************************************************************
784         //*******************MEMBER VARIABLES *************************
785         //*************************************************************
786         pthread_mutex_t       m_lock;
787         pthread_mutex_t       c_lock;
788         pthread_mutex_t       buf_lock;
789         //sem to handle the minimum procesing of commands
790         sem_t                 m_cmd_lock;
791         sem_t                 m_safe_flush;
792         bool              m_error_propogated;
793         // compression format
794         OMX_VIDEO_CODINGTYPE eCompressionFormat;
795         // OMX State
796         OMX_STATETYPE m_state;
797         // Application data
798         OMX_PTR m_app_data;
799         // Application callbacks
800         OMX_CALLBACKTYPE m_cb;
801         OMX_PRIORITYMGMTTYPE m_priority_mgm ;
802         OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier;
803         // fill this buffer queue
804         omx_cmd_queue         m_ftb_q;
805         // Command Q for rest of the events
806         omx_cmd_queue         m_cmd_q;
807         omx_cmd_queue         m_etb_q;
808         // Input memory pointer
809         OMX_BUFFERHEADERTYPE  *m_inp_mem_ptr;
810         // Output memory pointer
811         OMX_BUFFERHEADERTYPE  *m_out_mem_ptr;
812         // number of input bitstream error frame count
813         unsigned int m_inp_err_count;
814 #ifdef _ANDROID_
815         // Timestamp list
816         ts_arr_list           m_timestamp_list;
817 #endif
818 
819         bool input_flush_progress;
820         bool output_flush_progress;
821         bool input_use_buffer;
822         bool output_use_buffer;
823         bool ouput_egl_buffers;
824         OMX_BOOL m_use_output_pmem;
825         OMX_BOOL m_out_mem_region_smi;
826         OMX_BOOL m_out_pvt_entry_pmem;
827 
828         int pending_input_buffers;
829         int pending_output_buffers;
830         // bitmask array size for output side
831         uint64_t m_out_bm_count;
832         // bitmask array size for input side
833         uint64_t m_inp_bm_count;
834         //Input port Populated
835         OMX_BOOL m_inp_bPopulated;
836         //Output port Populated
837         OMX_BOOL m_out_bPopulated;
838         // encapsulate the waiting states.
839         uint64_t m_flags;
840 
841 #ifdef _ANDROID_
842         // Heap pointer to frame buffers
843         struct vidc_heap {
844             sp<MemoryHeapBase>    video_heap_ptr;
845         };
846         struct vidc_heap *m_heap_ptr;
847         unsigned int m_heap_count;
848 #endif //_ANDROID_
849         // store I/P PORT state
850         OMX_BOOL m_inp_bEnabled;
851         // store O/P PORT state
852         OMX_BOOL m_out_bEnabled;
853         OMX_U32 m_in_alloc_cnt;
854         OMX_U8                m_cRole[OMX_MAX_STRINGNAME_SIZE];
855         // Platform specific details
856         OMX_QCOM_PLATFORM_PRIVATE_LIST      *m_platform_list;
857         OMX_QCOM_PLATFORM_PRIVATE_ENTRY     *m_platform_entry;
858         OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info;
859         // SPS+PPS sent as part of set_config
860         OMX_VENDOR_EXTRADATATYPE            m_vendor_config;
861 
862         /*Variables for arbitrary Byte parsing support*/
863         frame_parse m_frame_parser;
864         h264_stream_parser *h264_parser;
865         MP4_Utils mp4_headerparser;
866         HEVC_Utils m_hevc_utils;
867 
868         omx_cmd_queue m_input_pending_q;
869         omx_cmd_queue m_input_free_q;
870         bool arbitrary_bytes;
871         OMX_BUFFERHEADERTYPE  h264_scratch;
872         OMX_BUFFERHEADERTYPE  *psource_frame;
873         OMX_BUFFERHEADERTYPE  *pdest_frame;
874         OMX_BUFFERHEADERTYPE  *m_inp_heap_ptr;
875         OMX_BUFFERHEADERTYPE  **m_phdr_pmem_ptr;
876         unsigned int m_heap_inp_bm_count;
877         codec_type codec_type_parse;
878         bool first_frame_meta;
879         unsigned frame_count;
880         unsigned nal_count;
881         unsigned nal_length;
882         bool look_ahead_nal;
883         int first_frame;
884         unsigned char *first_buffer;
885         int first_frame_size;
886         unsigned char m_hwdevice_name[80];
887         FILE *m_device_file_ptr;
888         enum vc1_profile_type m_vc1_profile;
889         OMX_S64 h264_last_au_ts;
890         OMX_U32 h264_last_au_flags;
891         OMX_U32 m_demux_offsets[8192];
892         OMX_U32 m_demux_entries;
893         OMX_U32 m_disp_hor_size;
894         OMX_U32 m_disp_vert_size;
895         OMX_S64 prev_ts;
896         OMX_S64 prev_ts_actual;
897         bool rst_prev_ts;
898         OMX_U32 frm_int;
899 
900         struct vdec_allocatorproperty op_buf_rcnfg;
901         bool in_reconfig;
902         OMX_NATIVE_WINDOWTYPE m_display_id;
903         OMX_U32 client_extradata;
904 #ifdef _ANDROID_
905         bool m_debug_timestamp;
906         bool perf_flag;
907         OMX_U32 proc_frms, latency;
908         perf_metrics fps_metrics;
909         perf_metrics dec_time;
910         bool m_reject_avc_1080p_mp;
911         bool m_enable_android_native_buffers;
912         bool m_use_android_native_buffers;
913         bool m_debug_extradata;
914         bool m_debug_concealedmb;
915         bool m_disable_dynamic_buf_mode;
916         OMX_U32 m_conceal_color;
917 #endif
918 
919 
920         struct h264_mv_buffer {
921             unsigned char* buffer;
922             int size;
923             int count;
924             int pmem_fd;
925             int offset;
926         };
927         h264_mv_buffer h264_mv_buff;
928 
929         struct meta_buffer {
930             unsigned char* buffer;
931             int size;
932             int count;
933             int pmem_fd;
934             int pmem_fd_iommu;
935             int offset;
936         };
937         meta_buffer meta_buff;
938         extra_data_handler extra_data_handle;
939         OMX_PARAM_PORTDEFINITIONTYPE m_port_def;
940         OMX_QCOM_FRAME_PACK_ARRANGEMENT m_frame_pack_arrangement;
941         omx_time_stamp_reorder time_stamp_dts;
942         desc_buffer_hdr *m_desc_buffer_ptr;
943         bool secure_mode;
944         bool external_meta_buffer;
945         bool external_meta_buffer_iommu;
946         OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata;
947         OMX_OTHER_EXTRADATATYPE *m_other_extradata;
948         bool codec_config_flag;
949 #ifdef _MSM8974_
950         int capture_capability;
951         int output_capability;
952         bool streaming[MAX_PORT];
953         OMX_FRAMESIZETYPE framesize;
954         OMX_CONFIG_RECTTYPE rectangle;
955         OMX_U32 prev_n_filled_len;
956         bool is_down_scalar_enabled;
957         bool m_force_down_scalar;
958 #endif
959         struct custom_buffersize {
960             OMX_U32 input_buffersize;
961         } m_custom_buffersize;
962         bool m_power_hinted;
963         bool is_q6_platform;
964         OMX_ERRORTYPE power_module_register();
965         OMX_ERRORTYPE power_module_deregister();
966         bool msg_thread_created;
967         bool async_thread_created;
968 
969         OMX_VIDEO_PARAM_PROFILELEVELTYPE m_profile_lvl;
970         OMX_U32 m_profile;
971 
972         //variables to handle dynamic buffer mode
973         bool dynamic_buf_mode;
974         struct dynamic_buf_list *out_dynamic_list;
975         OMX_U32 m_reconfig_width;
976         OMX_U32 m_reconfig_height;
977         bool m_smoothstreaming_mode;
978 
979         bool m_input_pass_buffer_fd;
980 
981         OMX_U32 m_smoothstreaming_width;
982         OMX_U32 m_smoothstreaming_height;
983         OMX_ERRORTYPE enable_smoothstreaming();
984         OMX_ERRORTYPE enable_adaptive_playback(unsigned long width, unsigned long height);
985         bool is_thulium_v1;
986         bool m_disable_ubwc_mode;
987         OMX_U32 m_downscalar_width;
988         OMX_U32 m_downscalar_height;
989         int decide_downscalar();
990         int enable_downscalar();
991         int disable_downscalar();
992 
993         unsigned int m_fill_output_msg;
994         bool client_set_fps;
995         class allocate_color_convert_buf
996         {
997             public:
998                 allocate_color_convert_buf();
999                 ~allocate_color_convert_buf();
1000                 void set_vdec_client(void *);
1001                 void update_client();
1002                 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format);
1003                 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format);
1004                 bool update_buffer_req();
1005                 bool get_buffer_req(unsigned int &buffer_size);
1006                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr();
1007                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
1008                 OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
1009                 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header);
1010                 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header);
1011                 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
1012                         OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,
1013                         OMX_U32 bytes);
1014                 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
is_color_conversion_enabled()1015                 bool is_color_conversion_enabled() {return enabled;}
1016             private:
1017 #define MAX_COUNT MAX_NUM_INPUT_OUTPUT_BUFFERS
1018                 omx_vdec *omx;
1019                 bool enabled;
1020                 OMX_COLOR_FORMATTYPE ColorFormat;
1021                 void init_members();
1022                 bool color_convert_mode;
1023                 ColorConvertFormat dest_format;
1024                 class omx_c2d_conv c2d;
1025                 unsigned int allocated_count;
1026                 unsigned int buffer_size_req;
1027                 unsigned int buffer_alignment_req;
1028                 OMX_QCOM_PLATFORM_PRIVATE_LIST      m_platform_list_client[MAX_COUNT];
1029                 OMX_QCOM_PLATFORM_PRIVATE_ENTRY     m_platform_entry_client[MAX_COUNT];
1030                 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT];
1031                 OMX_BUFFERHEADERTYPE  m_out_mem_ptr_client[MAX_COUNT];
1032 #ifdef USE_ION
1033                 struct vdec_ion op_buf_ion_info[MAX_COUNT];
1034 #endif
1035                 unsigned char *pmem_baseaddress[MAX_COUNT];
1036                 int pmem_fd[MAX_COUNT];
1037                 struct vidc_heap {
1038                     sp<MemoryHeapBase>    video_heap_ptr;
1039                 };
1040                 struct vidc_heap m_heap_ptr[MAX_COUNT];
1041 
1042                 OMX_ERRORTYPE cache_ops(unsigned int index, unsigned int cmd);
cache_clean_buffer(unsigned int index)1043                 inline OMX_ERRORTYPE cache_clean_buffer(unsigned int index) {
1044                     return cache_ops(index, ION_IOC_CLEAN_CACHES);
1045                 }
cache_clean_invalidate_buffer(unsigned int index)1046                 OMX_ERRORTYPE cache_clean_invalidate_buffer(unsigned int index) {
1047                     return cache_ops(index, ION_IOC_CLEAN_INV_CACHES);
1048                 }
1049         };
1050 #if  defined (_MSM8960_) || defined (_MSM8974_)
1051         allocate_color_convert_buf client_buffers;
1052 #endif
1053         struct video_decoder_capability m_decoder_capability;
1054         struct debug_cap m_debug;
1055         int log_input_buffers(const char *, int);
1056         int log_output_buffers(OMX_BUFFERHEADERTYPE *);
1057 #ifdef _MSM8974_
1058         void send_codec_config();
1059 #endif
1060         OMX_TICKS m_last_rendered_TS;
1061         volatile int32_t m_queued_codec_config_count;
1062         OMX_U32 current_perf_level;
1063         bool secure_scaling_to_non_secure_opb;
1064 	bool m_force_compressed_for_dpb;
1065         class perf_lock {
1066             private:
1067                 pthread_mutex_t mlock;
1068 
1069             public:
perf_lock()1070                 perf_lock() {
1071                     pthread_mutex_init(&mlock, NULL);
1072                 }
1073 
~perf_lock()1074                 ~perf_lock() {
1075                     pthread_mutex_destroy(&mlock);
1076                 }
1077 
lock()1078                 void lock() {
1079                     pthread_mutex_lock(&mlock);
1080                 }
1081 
unlock()1082                 void unlock() {
1083                     pthread_mutex_unlock(&mlock);
1084                 }
1085         };
1086 
1087         class perf_control {
1088             // 2 cores will be requested if framerate is beyond 45 fps
1089             static const int MIN_FRAME_DURATION_FOR_PERF_REQUEST_US = (1e6 / 45);
1090             typedef int (*perf_lock_acquire_t)(int, int, int*, int);
1091             typedef int (*perf_lock_release_t)(int);
1092 
1093             private:
1094                 void *m_perf_lib;
1095                 int m_perf_handle;
1096                 perf_lock_acquire_t m_perf_lock_acquire;
1097                 perf_lock_release_t m_perf_lock_release;
1098                 bool load_lib();
1099                 struct mpctl_stats {
1100                   int vid_inst_count;
1101                   bool vid_acquired;
1102                   int vid_disp_handle;
1103                 };
1104                 static struct mpctl_stats mpctl_obj;
1105                 static perf_lock m_perf_lock;
1106 
1107             public:
1108                 perf_control();
1109                 ~perf_control();
1110                 void request_cores(int frame_duration_us);
1111                 void send_hint_to_mpctl(bool state);
1112         };
1113         perf_control m_perf_control;
1114 
getPreferredColorFormatNonSurfaceMode(OMX_U32 index)1115         static OMX_COLOR_FORMATTYPE getPreferredColorFormatNonSurfaceMode(OMX_U32 index) {
1116             //On Android, we default to standard YUV formats for non-surface use-cases
1117             //where apps prefer known color formats.
1118             OMX_COLOR_FORMATTYPE formatsNonSurfaceMode[] = {
1119                 [0] = OMX_COLOR_FormatYUV420SemiPlanar,
1120                 [1] = OMX_COLOR_FormatYUV420Planar,
1121                 [2] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1122                 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1123                 [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed,
1124             };
1125             return (index < sizeof(formatsNonSurfaceMode) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1126                 formatsNonSurfaceMode[index] : OMX_COLOR_FormatMax;
1127         }
1128 
getPreferredColorFormatDefaultMode(OMX_U32 index)1129         OMX_COLOR_FORMATTYPE getPreferredColorFormatDefaultMode(OMX_U32 index) {
1130             //for surface mode (normal playback), advertise native/accelerated formats first
1131             OMX_COLOR_FORMATTYPE format = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
1132 
1133             if (!m_disable_ubwc_mode) {
1134                 OMX_COLOR_FORMATTYPE formatsDefault[] = {
1135                     [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed,
1136                     [1] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1137                     [2] = OMX_COLOR_FormatYUV420SemiPlanar,
1138                     [3] = OMX_COLOR_FormatYUV420Planar,
1139                     [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1140                 };
1141                 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1142                     formatsDefault[index] : OMX_COLOR_FormatMax;
1143             } else {
1144                 OMX_COLOR_FORMATTYPE formatsDefault[] = {
1145                     [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1146                     [1] = OMX_COLOR_FormatYUV420SemiPlanar,
1147                     [2] = OMX_COLOR_FormatYUV420Planar,
1148                     [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1149                 };
1150                 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1151                     formatsDefault[index] : OMX_COLOR_FormatMax;
1152             }
1153             return format;
1154         }
1155 
1156         static OMX_ERRORTYPE describeColorFormat(OMX_PTR params);
1157 
1158 };
1159 
1160 #ifdef _MSM8974_
1161 enum instance_state {
1162     MSM_VIDC_CORE_UNINIT_DONE = 0x0001,
1163     MSM_VIDC_CORE_INIT,
1164     MSM_VIDC_CORE_INIT_DONE,
1165     MSM_VIDC_OPEN,
1166     MSM_VIDC_OPEN_DONE,
1167     MSM_VIDC_LOAD_RESOURCES,
1168     MSM_VIDC_LOAD_RESOURCES_DONE,
1169     MSM_VIDC_START,
1170     MSM_VIDC_START_DONE,
1171     MSM_VIDC_STOP,
1172     MSM_VIDC_STOP_DONE,
1173     MSM_VIDC_RELEASE_RESOURCES,
1174     MSM_VIDC_RELEASE_RESOURCES_DONE,
1175     MSM_VIDC_CLOSE,
1176     MSM_VIDC_CLOSE_DONE,
1177     MSM_VIDC_CORE_UNINIT,
1178 };
1179 
1180 enum vidc_resposes_id {
1181     MSM_VIDC_DECODER_FLUSH_DONE = 0x11,
1182     MSM_VIDC_DECODER_EVENT_CHANGE,
1183 };
1184 
1185 #endif // _MSM8974_
1186 
1187 #endif // __OMX_VDEC_H__
1188