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