1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010 - 2014, 2018, The Linux Foundation. All rights reserved.
3 
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
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         OMX_ERRORTYPE get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
616 
617         OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index);
618         OMX_ERRORTYPE allocate_output_headers();
619         bool execute_omx_flush(OMX_U32);
620         bool execute_output_flush();
621         bool execute_input_flush();
622         OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp,
623                 OMX_BUFFERHEADERTYPE * buffer);
624 
625         OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp,
626                 OMX_BUFFERHEADERTYPE * buffer);
627         OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE       hComp,
628                 OMX_BUFFERHEADERTYPE *buffer);
629 
630         OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp,
631                 OMX_BUFFERHEADERTYPE *buffer
632                 );
633 
634         OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp);
635         OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp);
636         OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp);
637         OMX_ERRORTYPE push_input_hevc (OMX_HANDLETYPE hComp);
638         OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp);
639 
640         OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
641                 OMX_BUFFERHEADERTYPE *buffer);
642         bool release_done();
643 
644         bool release_output_done();
645         bool release_input_done();
646         OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop);
647         OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop);
648         OMX_ERRORTYPE start_port_reconfig();
649         OMX_ERRORTYPE update_picture_resolution();
650         int stream_off(OMX_U32 port);
651         void adjust_timestamp(OMX_S64 &act_timestamp);
652         void set_frame_rate(OMX_S64 act_timestamp);
653         void handle_extradata_secure(OMX_BUFFERHEADERTYPE *p_buf_hdr);
654         void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr);
655         void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra);
656 #ifdef _MSM8974_
657         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
658                 OMX_U32 interlaced_format_type, bool is_mbaff);
659         OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool is_internal,
660                 bool enable = true);
661         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
662                 OMX_U32 num_conceal_mb,
663                 OMX_U32 picture_type,
664                 OMX_U32 frame_rate,
665                 OMX_TICKS time_stamp,
666                 struct msm_vidc_panscan_window_payload *panscan_payload,
667                 struct vdec_aspectratioinfo *aspect_ratio_info);
668 #else
669         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
670                 OMX_U32 interlaced_format_type, OMX_U32 buf_index);
671         OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true);
672 #endif
673         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
674                 OMX_U32 num_conceal_mb,
675                 OMX_U32 picture_type,
676                 OMX_S64 timestamp,
677                 OMX_U32 frame_rate,
678                 struct vdec_aspectratioinfo *aspect_ratio_info);
679         void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info,
680                 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info);
681         void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra);
682         OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn);
683         void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra);
684         void append_frame_dimension_extradata(OMX_OTHER_EXTRADATATYPE *extra);
685         void append_extn_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_extn);
686         void append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_user);
687         void append_concealmb_extradata(OMX_OTHER_EXTRADATATYPE *extra,
688                 OMX_OTHER_EXTRADATATYPE *p_concealmb, OMX_U8 *conceal_mb_data);
689         void append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra,
690                 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload);
691         void append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra,
692                 struct msm_vidc_frame_qp_payload *qp_payload);
693         void append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra,
694                 struct msm_vidc_frame_bits_info_payload *bits_payload);
695         void append_mpeg2_seqdisplay_extradata(OMX_OTHER_EXTRADATATYPE *extra,
696                 struct msm_vidc_mpeg2_seqdisp_payload* seq_display_payload);
697         void insert_demux_addr_offset(OMX_U32 address_offset);
698         void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr);
699         OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr);
700         OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra);
701 
702         bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
703                 OMX_U32 alignment);
704 #ifdef USE_ION
705         int alloc_map_ion_memory(OMX_U32 buffer_size,
706                 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
707                 struct ion_fd_data *fd_data,int flag);
708         void free_ion_memory(struct vdec_ion *buf_ion_info);
709 #endif
710 
711 
712         OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
713                 OMX_COMMANDTYPE cmd,
714                 OMX_U32         param1,
715                 OMX_PTR         cmdData);
716         bool post_event( unsigned long p1,
717                 unsigned long p2,
718                 unsigned long id
719                    );
clip2(int x)720         inline int clip2(int x) {
721             x = x -1;
722             x = x | x >> 1;
723             x = x | x >> 2;
724             x = x | x >> 4;
725             x = x | x >> 16;
726             x = x + 1;
727             return x;
728         }
729 
730 #ifdef MAX_RES_1080P
731         OMX_ERRORTYPE vdec_alloc_h264_mv();
732         void vdec_dealloc_h264_mv();
733         OMX_ERRORTYPE vdec_alloc_meta_buffers();
734         void vdec_dealloc_meta_buffers();
735 #endif
736 
omx_report_error()737         inline void omx_report_error () {
738             if (m_cb.EventHandler && !m_error_propogated) {
739                 DEBUG_PRINT_ERROR("ERROR: Sending OMX_ErrorHardware to Client");
740                 m_error_propogated = true;
741                 m_cb.EventHandler(&m_cmp,m_app_data,
742                         OMX_EventError,OMX_ErrorHardware,0,NULL);
743             }
744         }
745 
omx_report_unsupported_setting()746         inline void omx_report_unsupported_setting () {
747             if (m_cb.EventHandler && !m_error_propogated) {
748                 DEBUG_PRINT_ERROR(
749                         "ERROR: Sending OMX_ErrorUnsupportedSetting to Client");
750                 m_error_propogated = true;
751                 m_cb.EventHandler(&m_cmp,m_app_data,
752                         OMX_EventError,OMX_ErrorUnsupportedSetting,0,NULL);
753             }
754         }
omx_report_hw_overload()755         inline void omx_report_hw_overload () {
756             if (m_cb.EventHandler && !m_error_propogated) {
757                 DEBUG_PRINT_ERROR(
758                         "ERROR: Sending OMX_ErrorInsufficientResources to Client");
759                 m_error_propogated = true;
760                 m_cb.EventHandler(&m_cmp, m_app_data,
761                         OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL);
762             }
763         }
764 
765 #ifdef _ANDROID_
766         OMX_ERRORTYPE createDivxDrmContext();
767 #endif //_ANDROID_
768 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
769         OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data);
770 #endif
771 #if defined (_ANDROID_ICS_)
772         struct nativebuffer {
773             native_handle_t *nativehandle;
774             private_handle_t *privatehandle;
775             int inuse;
776         };
777         nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
778 #endif
779 
780 
781         //*************************************************************
782         //*******************MEMBER VARIABLES *************************
783         //*************************************************************
784         pthread_mutex_t       m_lock;
785         pthread_mutex_t       c_lock;
786         pthread_mutex_t       buf_lock;
787         //sem to handle the minimum procesing of commands
788         sem_t                 m_cmd_lock;
789         sem_t                 m_safe_flush;
790         bool              m_error_propogated;
791         // compression format
792         OMX_VIDEO_CODINGTYPE eCompressionFormat;
793         // OMX State
794         OMX_STATETYPE m_state;
795         // Application data
796         OMX_PTR m_app_data;
797         // Application callbacks
798         OMX_CALLBACKTYPE m_cb;
799         OMX_PRIORITYMGMTTYPE m_priority_mgm ;
800         OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier;
801         // fill this buffer queue
802         omx_cmd_queue         m_ftb_q;
803         // Command Q for rest of the events
804         omx_cmd_queue         m_cmd_q;
805         omx_cmd_queue         m_etb_q;
806         // Input memory pointer
807         OMX_BUFFERHEADERTYPE  *m_inp_mem_ptr;
808         // Output memory pointer
809         OMX_BUFFERHEADERTYPE  *m_out_mem_ptr;
810         // number of input bitstream error frame count
811         unsigned int m_inp_err_count;
812 #ifdef _ANDROID_
813         // Timestamp list
814         ts_arr_list           m_timestamp_list;
815 #endif
816 
817         bool input_flush_progress;
818         bool output_flush_progress;
819         bool input_use_buffer;
820         bool output_use_buffer;
821         bool ouput_egl_buffers;
822         OMX_BOOL m_use_output_pmem;
823         OMX_BOOL m_out_mem_region_smi;
824         OMX_BOOL m_out_pvt_entry_pmem;
825 
826         int pending_input_buffers;
827         int pending_output_buffers;
828         // bitmask array size for output side
829         uint64_t m_out_bm_count;
830         // bitmask array size for input side
831         uint64_t m_inp_bm_count;
832         //Input port Populated
833         OMX_BOOL m_inp_bPopulated;
834         //Output port Populated
835         OMX_BOOL m_out_bPopulated;
836         // encapsulate the waiting states.
837         unsigned int m_flags;
838 
839 #ifdef _ANDROID_
840         // Heap pointer to frame buffers
841         struct vidc_heap {
842             sp<MemoryHeapBase>    video_heap_ptr;
843         };
844         struct vidc_heap *m_heap_ptr;
845         unsigned int m_heap_count;
846 #endif //_ANDROID_
847         // store I/P PORT state
848         OMX_BOOL m_inp_bEnabled;
849         // store O/P PORT state
850         OMX_BOOL m_out_bEnabled;
851         OMX_U32 m_in_alloc_cnt;
852         OMX_U8                m_cRole[OMX_MAX_STRINGNAME_SIZE];
853         // Platform specific details
854         OMX_QCOM_PLATFORM_PRIVATE_LIST      *m_platform_list;
855         OMX_QCOM_PLATFORM_PRIVATE_ENTRY     *m_platform_entry;
856         OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info;
857         // SPS+PPS sent as part of set_config
858         OMX_VENDOR_EXTRADATATYPE            m_vendor_config;
859 
860         /*Variables for arbitrary Byte parsing support*/
861         frame_parse m_frame_parser;
862         h264_stream_parser *h264_parser;
863         MP4_Utils mp4_headerparser;
864         HEVC_Utils m_hevc_utils;
865 
866         omx_cmd_queue m_input_pending_q;
867         omx_cmd_queue m_input_free_q;
868         bool arbitrary_bytes;
869         OMX_BUFFERHEADERTYPE  h264_scratch;
870         OMX_BUFFERHEADERTYPE  *psource_frame;
871         OMX_BUFFERHEADERTYPE  *pdest_frame;
872         OMX_BUFFERHEADERTYPE  *m_inp_heap_ptr;
873         OMX_BUFFERHEADERTYPE  **m_phdr_pmem_ptr;
874         unsigned int m_heap_inp_bm_count;
875         codec_type codec_type_parse;
876         bool first_frame_meta;
877         unsigned frame_count;
878         unsigned nal_count;
879         unsigned nal_length;
880         bool look_ahead_nal;
881         int first_frame;
882         unsigned char *first_buffer;
883         int first_frame_size;
884         unsigned char m_hwdevice_name[80];
885         FILE *m_device_file_ptr;
886         enum vc1_profile_type m_vc1_profile;
887         OMX_S64 h264_last_au_ts;
888         OMX_U32 h264_last_au_flags;
889         OMX_U32 m_demux_offsets[8192];
890         OMX_U32 m_demux_entries;
891         OMX_U32 m_disp_hor_size;
892         OMX_U32 m_disp_vert_size;
893 
894         OMX_S64 prev_ts;
895         bool rst_prev_ts;
896         OMX_U32 frm_int;
897 
898         struct vdec_allocatorproperty op_buf_rcnfg;
899         bool in_reconfig;
900         OMX_NATIVE_WINDOWTYPE m_display_id;
901         OMX_U32 client_extradata;
902 #ifdef _ANDROID_
903         bool m_debug_timestamp;
904         bool perf_flag;
905         OMX_U32 proc_frms, latency;
906         perf_metrics fps_metrics;
907         perf_metrics dec_time;
908         bool m_reject_avc_1080p_mp;
909         bool m_enable_android_native_buffers;
910         bool m_use_android_native_buffers;
911         bool m_debug_extradata;
912         bool m_debug_concealedmb;
913         bool m_disable_dynamic_buf_mode;
914         OMX_U32 m_conceal_color;
915 #endif
916 
917         struct h264_mv_buffer {
918             unsigned char* buffer;
919             int size;
920             int count;
921             int pmem_fd;
922             int offset;
923         };
924         h264_mv_buffer h264_mv_buff;
925 
926         struct meta_buffer {
927             unsigned char* buffer;
928             int size;
929             int count;
930             int pmem_fd;
931             int pmem_fd_iommu;
932             int offset;
933         };
934         meta_buffer meta_buff;
935         extra_data_handler extra_data_handle;
936 #ifdef _ANDROID_
937         DivXDrmDecrypt* iDivXDrmDecrypt;
938 #endif //_ANDROID_
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 allocate_native_handle;
945         bool external_meta_buffer;
946         bool external_meta_buffer_iommu;
947         OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata;
948         OMX_OTHER_EXTRADATATYPE *m_other_extradata;
949         bool codec_config_flag;
950 #ifdef _MSM8974_
951         int capture_capability;
952         int output_capability;
953         bool streaming[MAX_PORT];
954         OMX_FRAMESIZETYPE framesize;
955         OMX_CONFIG_RECTTYPE rectangle;
956         OMX_U32 prev_n_filled_len;
957         bool is_down_scalar_enabled;
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         bool m_smoothstreaming_mode;
976         OMX_U32 m_smoothstreaming_width;
977         OMX_U32 m_smoothstreaming_height;
978         OMX_ERRORTYPE enable_smoothstreaming();
979         OMX_ERRORTYPE enable_adaptive_playback(unsigned long width, unsigned long height);
980 
981         unsigned int m_fill_output_msg;
982         bool client_set_fps;
983         class allocate_color_convert_buf
984         {
985             public:
986                 allocate_color_convert_buf();
987                 ~allocate_color_convert_buf();
988                 void set_vdec_client(void *);
989                 void update_client();
990                 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format);
991                 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format);
992                 bool update_buffer_req();
993                 bool get_buffer_req(unsigned int &buffer_size);
994                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr();
995                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
996                 OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
997                 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header);
998                 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header);
999                 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
1000                         OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,
1001                         OMX_U32 bytes);
1002                 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
is_color_conversion_enabled()1003                 bool is_color_conversion_enabled() {return enabled;}
1004             private:
1005 #define MAX_COUNT 32
1006                 omx_vdec *omx;
1007                 bool enabled;
1008                 OMX_COLOR_FORMATTYPE ColorFormat;
1009                 void init_members();
1010                 bool color_convert_mode;
1011                 ColorConvertFormat dest_format;
1012                 class omx_c2d_conv c2d;
1013                 unsigned int allocated_count;
1014                 unsigned int buffer_size_req;
1015                 unsigned int buffer_alignment_req;
1016                 OMX_QCOM_PLATFORM_PRIVATE_LIST      m_platform_list_client[MAX_COUNT];
1017                 OMX_QCOM_PLATFORM_PRIVATE_ENTRY     m_platform_entry_client[MAX_COUNT];
1018                 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT];
1019                 OMX_BUFFERHEADERTYPE  m_out_mem_ptr_client[MAX_COUNT];
1020 #ifdef USE_ION
1021                 struct vdec_ion op_buf_ion_info[MAX_COUNT];
1022 #endif
1023                 unsigned char *pmem_baseaddress[MAX_COUNT];
1024                 unsigned long pmem_fd[MAX_COUNT];
1025                 struct vidc_heap {
1026                     sp<MemoryHeapBase>    video_heap_ptr;
1027                 };
1028                 struct vidc_heap m_heap_ptr[MAX_COUNT];
1029 
1030                 OMX_ERRORTYPE cache_ops(unsigned int index, unsigned int cmd);
cache_clean_buffer(unsigned int index)1031                 inline OMX_ERRORTYPE cache_clean_buffer(unsigned int index) {
1032                     return cache_ops(index, ION_IOC_CLEAN_CACHES);
1033                 }
cache_clean_invalidate_buffer(unsigned int index)1034                 OMX_ERRORTYPE cache_clean_invalidate_buffer(unsigned int index) {
1035                     return cache_ops(index, ION_IOC_CLEAN_INV_CACHES);
1036                 }
1037         };
1038 #if  defined (_MSM8960_) || defined (_MSM8974_)
1039         allocate_color_convert_buf client_buffers;
1040 #endif
1041         struct video_decoder_capability m_decoder_capability;
1042         struct debug_cap m_debug;
1043         int log_input_buffers(const char *, int);
1044         int log_output_buffers(OMX_BUFFERHEADERTYPE *);
1045 #ifdef _MSM8974_
1046         void send_codec_config();
1047 #endif
1048         OMX_TICKS m_last_rendered_TS;
1049         volatile int32_t m_queued_codec_config_count;
1050         bool secure_scaling_to_non_secure_opb;
1051 
1052         class perf_control {
1053             // 2 cores will be requested if framerate is beyond 45 fps
1054             static const int MIN_FRAME_DURATION_FOR_PERF_REQUEST_US = (1e6 / 45);
1055             typedef int (*perf_lock_acquire_t)(int, int, int*, int);
1056             typedef int (*perf_lock_release_t)(int);
1057 
1058             public:
1059                 perf_control();
1060                 ~perf_control();
1061                 void request_cores(int frame_duration_us);
1062             private:
1063                 void *m_perf_lib;
1064                 int m_perf_handle;
1065                 perf_lock_acquire_t m_perf_lock_acquire;
1066                 perf_lock_release_t m_perf_lock_release;
1067                 //void (*perf_cpu_boost)(int ntasks);
1068                 void load_lib();
1069         };
1070         perf_control m_perf_control;
1071 
getPreferredColorFormatNonSurfaceMode(OMX_U32 index)1072         static OMX_COLOR_FORMATTYPE getPreferredColorFormatNonSurfaceMode(OMX_U32 index) {
1073             //On Android, we default to standard YUV formats for non-surface use-cases
1074             //where apps prefer known color formats.
1075             OMX_COLOR_FORMATTYPE formatsNonSurfaceMode[] = {
1076                 [0] = OMX_COLOR_FormatYUV420SemiPlanar,
1077                 [1] = OMX_COLOR_FormatYUV420Planar,
1078                 [2] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1079                 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1080             };
1081             return (index < sizeof(formatsNonSurfaceMode) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1082                 formatsNonSurfaceMode[index] : OMX_COLOR_FormatMax;
1083         }
1084 
getPreferredColorFormatDefaultMode(OMX_U32 index)1085         static OMX_COLOR_FORMATTYPE getPreferredColorFormatDefaultMode(OMX_U32 index) {
1086             //for surface mode (normal playback), advertise native/accelerated formats first
1087             OMX_COLOR_FORMATTYPE formatsDefault[] = {
1088                 [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1089                 [1] = OMX_COLOR_FormatYUV420SemiPlanar,
1090                 [2] = OMX_COLOR_FormatYUV420Planar,
1091                 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1092             };
1093             return (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1094                 formatsDefault[index] : OMX_COLOR_FormatMax;
1095         }
1096 
1097         static OMX_ERRORTYPE describeColorFormat(OMX_PTR params);
1098         bool m_buffer_error;
1099 };
1100 
1101 #ifdef _MSM8974_
1102 enum instance_state {
1103     MSM_VIDC_CORE_UNINIT_DONE = 0x0001,
1104     MSM_VIDC_CORE_INIT,
1105     MSM_VIDC_CORE_INIT_DONE,
1106     MSM_VIDC_OPEN,
1107     MSM_VIDC_OPEN_DONE,
1108     MSM_VIDC_LOAD_RESOURCES,
1109     MSM_VIDC_LOAD_RESOURCES_DONE,
1110     MSM_VIDC_START,
1111     MSM_VIDC_START_DONE,
1112     MSM_VIDC_STOP,
1113     MSM_VIDC_STOP_DONE,
1114     MSM_VIDC_RELEASE_RESOURCES,
1115     MSM_VIDC_RELEASE_RESOURCES_DONE,
1116     MSM_VIDC_CLOSE,
1117     MSM_VIDC_CLOSE_DONE,
1118     MSM_VIDC_CORE_UNINIT,
1119 };
1120 
1121 enum vidc_resposes_id {
1122     MSM_VIDC_DECODER_FLUSH_DONE = 0x11,
1123     MSM_VIDC_DECODER_EVENT_CHANGE,
1124 };
1125 
1126 #endif // _MSM8974_
1127 
1128 #endif // __OMX_VDEC_H__
1129