• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6     * Redistributions of source code must retain the above copyright
7       notice, this list of conditions and the following disclaimer.
8     * Redistributions in binary form must reproduce the above copyright
9       notice, this list of conditions and the following disclaimer in the
10       documentation and/or other materials provided with the distribution.
11     * Neither the name of Code Aurora nor
12       the names of its contributors may be used to endorse or promote
13       products derived from this software without specific prior written
14       permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 --------------------------------------------------------------------------*/
28 #ifndef __OMX_VDEC_H__
29 #define __OMX_VDEC_H__
30 /*============================================================================
31                             O p e n M A X   Component
32                                 Video Decoder
33 
34 *//** @file comx_vdec.h
35   This module contains the class definition for openMAX decoder component.
36 
37 *//*========================================================================*/
38 
39 //////////////////////////////////////////////////////////////////////////////
40 //                             Include Files
41 //////////////////////////////////////////////////////////////////////////////
42 
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <inttypes.h>
47 #include <cstddef>
48 
49 static ptrdiff_t x;
50 
51 #ifdef _ANDROID_
52 #ifdef USE_ION
53 #include <linux/msm_ion.h>
54 #endif
55 #include <binder/MemoryHeapBase.h>
56 #include <ui/ANativeObjectBase.h>
57 #include <binder/IServiceManager.h>
58 extern "C"{
59 #include<utils/Log.h>
60 }
61 #include <linux/videodev2.h>
62 #include <poll.h>
63 #define TIMEOUT 5000
64 #ifdef MAX_RES_720P
65 #define LOG_TAG "OMX-VDEC-720P"
66 #elif MAX_RES_1080P
67 #define LOG_TAG "OMX-VDEC-1080P"
68 #else
69 #define LOG_TAG "OMX-VDEC"
70 #endif
71 #ifdef ENABLE_DEBUG_LOW
72 #define DEBUG_PRINT_LOW ALOGE
73 #else
74 #define DEBUG_PRINT_LOW
75 #endif
76 #ifdef ENABLE_DEBUG_HIGH
77 #define DEBUG_PRINT_HIGH ALOGE
78 #else
79 #define DEBUG_PRINT_HIGH
80 #endif
81 #ifdef ENABLE_DEBUG_ERROR
82 #define DEBUG_PRINT_ERROR ALOGE
83 #else
84 #define DEBUG_PRINT_ERROR
85 #endif
86 
87 #else //_ANDROID_
88 #define DEBUG_PRINT_LOW printf
89 #define DEBUG_PRINT_HIGH printf
90 #define DEBUG_PRINT_ERROR printf
91 #endif // _ANDROID_
92 
93 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
94 #include <media/hardware/HardwareAPI.h>
95 #endif
96 
97 #include <unistd.h>
98 
99 #if defined (_ANDROID_ICS_)
100 #include <gralloc_priv.h>
101 #include <IQService.h>
102 #endif
103 
104 #include <pthread.h>
105 #ifndef PC_DEBUG
106 #include <semaphore.h>
107 #endif
108 #include "OMX_Core.h"
109 #include "OMX_QCOMExtns.h"
110 #include "qc_omx_component.h"
111 #include <linux/msm_vidc_dec.h>
112 #include "frameparser.h"
113 #ifdef MAX_RES_1080P
114 #include "mp4_utils.h"
115 #endif
116 #include <linux/android_pmem.h>
117 #include "extra_data_handler.h"
118 #include "ts_parser.h"
119 #include "vidc_color_converter.h"
120 extern "C" {
121   OMX_API void * get_omx_component_factory_fn(void);
122 }
123 
124 #ifdef _ANDROID_
125     using namespace android;
126 #ifdef USE_ION
127     class VideoHeap : public MemoryHeapBase
128     {
129     public:
130         VideoHeap(int devicefd, size_t size, void* base,struct ion_handle *handle,int mapfd);
~VideoHeap()131         virtual ~VideoHeap() {}
132     private:
133        int m_ion_device_fd;
134        struct ion_handle *m_ion_handle;
135     };
136 #else
137     // local pmem heap object
138     class VideoHeap : public MemoryHeapBase
139     {
140     public:
141         VideoHeap(int fd, size_t size, void* base);
~VideoHeap()142         virtual ~VideoHeap() {}
143     };
144 #endif
145 #endif // _ANDROID_
146 //////////////////////////////////////////////////////////////////////////////
147 //                       Module specific globals
148 //////////////////////////////////////////////////////////////////////////////
149 #define OMX_SPEC_VERSION  0x00000101
150 
151 
152 //////////////////////////////////////////////////////////////////////////////
153 //               Macros
154 //////////////////////////////////////////////////////////////////////////////
155 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\
156                        (unsigned) bufHdr,\
157                        (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\
158                        (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\
159                        (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp)
160 
161 // BitMask Management logic
162 #define BITS_PER_BYTE        32
163 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_BYTE - 1)/BITS_PER_BYTE)
164 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_BYTE)
165 #define BITMASK_FLAG(mIndex) (1 << ((mIndex) % BITS_PER_BYTE))
166 #define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \
167         &=  ~(BITMASK_FLAG(mIndex))
168 #define BITMASK_SET(mArray,mIndex)  (mArray)[BITMASK_OFFSET(mIndex)] \
169         |=  BITMASK_FLAG(mIndex)
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 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
175         & BITMASK_FLAG(mIndex))
176 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
177         & BITMASK_FLAG(mIndex)) == 0x0)
178 
179 #define OMX_CORE_CONTROL_CMDQ_SIZE   100
180 #define OMX_CORE_QCIF_HEIGHT         144
181 #define OMX_CORE_QCIF_WIDTH          176
182 #define OMX_CORE_VGA_HEIGHT          480
183 #define OMX_CORE_VGA_WIDTH           640
184 #define OMX_CORE_WVGA_HEIGHT         480
185 #define OMX_CORE_WVGA_WIDTH          800
186 
187 #define DESC_BUFFER_SIZE (8192 * 16)
188 
189 #ifdef _ANDROID_
190 #define MAX_NUM_INPUT_OUTPUT_BUFFERS 32
191 #endif
192 
193 #define OMX_FRAMEINFO_EXTRADATA 0x00010000
194 #define OMX_INTERLACE_EXTRADATA 0x00020000
195 #define OMX_TIMEINFO_EXTRADATA  0x00040000
196 #define OMX_PORTDEF_EXTRADATA   0x00080000
197 #define DRIVER_EXTRADATA_MASK   0x0000FFFF
198 
199 #define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
200                                        sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3))
201 #define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
202                                        sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3))
203 #define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
204                                        sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3))
205 
206 //  Define next macro with required values to enable default extradata,
207 //    VDEC_EXTRADATA_MB_ERROR_MAP
208 //    OMX_INTERLACE_EXTRADATA
209 //    OMX_FRAMEINFO_EXTRADATA
210 //    OMX_TIMEINFO_EXTRADATA
211 
212 //#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA)
213 
214 enum port_indexes
215 {
216     OMX_CORE_INPUT_PORT_INDEX        =0,
217     OMX_CORE_OUTPUT_PORT_INDEX       =1
218 };
219 #ifdef USE_ION
220 struct vdec_ion
221 {
222     int ion_device_fd;
223     struct ion_fd_data fd_ion_data;
224     struct ion_allocation_data ion_alloc_data;
225 };
226 #endif
227 
228 struct video_driver_context
229 {
230     int video_driver_fd;
231     enum vdec_codec decoder_format;
232     enum vdec_output_fromat output_format;
233     enum vdec_interlaced_format interlace;
234     enum vdec_output_order picture_order;
235     struct vdec_picsize video_resolution;
236     struct vdec_allocatorproperty ip_buf;
237     struct vdec_allocatorproperty op_buf;
238     struct vdec_bufferpayload *ptr_inputbuffer;
239     struct vdec_bufferpayload *ptr_outputbuffer;
240     struct vdec_output_frameinfo *ptr_respbuffer;
241 #ifdef USE_ION
242     struct vdec_ion *ip_buf_ion_info;
243     struct vdec_ion *op_buf_ion_info;
244     struct vdec_ion h264_mv;
245 #endif
246     struct vdec_framerate frame_rate;
247     unsigned extradata;
248     bool timestamp_adjust;
249     char kind[128];
250     bool idr_only_decoding;
251     unsigned disable_dmx;
252 };
253 
254 #ifdef _ANDROID_
255 class DivXDrmDecrypt;
256 #endif //_ANDROID_
257 
258 // OMX video decoder class
259 class omx_vdec: public qc_omx_component
260 {
261 
262 public:
263     omx_vdec();  // constructor
264     virtual ~omx_vdec();  // destructor
265 
266     static int async_message_process (void *context, void* message);
267     static void process_event_cb(void *ctxt,unsigned char id);
268 
269     OMX_ERRORTYPE allocate_buffer(
270                                    OMX_HANDLETYPE hComp,
271                                    OMX_BUFFERHEADERTYPE **bufferHdr,
272                                    OMX_U32 port,
273                                    OMX_PTR appData,
274                                    OMX_U32 bytes
275                                   );
276 
277 
278     OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);
279 
280     OMX_ERRORTYPE component_init(OMX_STRING role);
281 
282     OMX_ERRORTYPE component_role_enum(
283                                        OMX_HANDLETYPE hComp,
284                                        OMX_U8 *role,
285                                        OMX_U32 index
286                                       );
287 
288     OMX_ERRORTYPE component_tunnel_request(
289                                             OMX_HANDLETYPE hComp,
290                                             OMX_U32 port,
291                                             OMX_HANDLETYPE  peerComponent,
292                                             OMX_U32 peerPort,
293                                             OMX_TUNNELSETUPTYPE *tunnelSetup
294                                            );
295 
296     OMX_ERRORTYPE empty_this_buffer(
297                                      OMX_HANDLETYPE hComp,
298                                      OMX_BUFFERHEADERTYPE *buffer
299                                     );
300 
301 
302 
303     OMX_ERRORTYPE fill_this_buffer(
304                                     OMX_HANDLETYPE hComp,
305                                     OMX_BUFFERHEADERTYPE *buffer
306                                    );
307 
308 
309     OMX_ERRORTYPE free_buffer(
310                               OMX_HANDLETYPE hComp,
311                               OMX_U32 port,
312                               OMX_BUFFERHEADERTYPE *buffer
313                               );
314 
315     OMX_ERRORTYPE get_component_version(
316                                         OMX_HANDLETYPE hComp,
317                                         OMX_STRING componentName,
318                                         OMX_VERSIONTYPE *componentVersion,
319                                         OMX_VERSIONTYPE *specVersion,
320                                         OMX_UUIDTYPE *componentUUID
321                                         );
322 
323     OMX_ERRORTYPE get_config(
324                               OMX_HANDLETYPE hComp,
325                               OMX_INDEXTYPE configIndex,
326                               OMX_PTR configData
327                              );
328 
329     OMX_ERRORTYPE get_extension_index(
330                                       OMX_HANDLETYPE hComp,
331                                       OMX_STRING paramName,
332                                       OMX_INDEXTYPE *indexType
333                                       );
334 
335     OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp,
336                                 OMX_INDEXTYPE  paramIndex,
337                                 OMX_PTR        paramData);
338 
339     OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp,
340                             OMX_STATETYPE *state);
341 
342 
343 
344     OMX_ERRORTYPE send_command(OMX_HANDLETYPE  hComp,
345                                OMX_COMMANDTYPE cmd,
346                                OMX_U32         param1,
347                                OMX_PTR         cmdData);
348 
349 
350     OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE   hComp,
351                                 OMX_CALLBACKTYPE *callbacks,
352                                 OMX_PTR          appData);
353 
354     OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
355                              OMX_INDEXTYPE  configIndex,
356                              OMX_PTR        configData);
357 
358     OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
359                                 OMX_INDEXTYPE  paramIndex,
360                                 OMX_PTR        paramData);
361 
362     OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE      hComp,
363                              OMX_BUFFERHEADERTYPE **bufferHdr,
364                              OMX_U32              port,
365                              OMX_PTR              appData,
366                              OMX_U32              bytes,
367                              OMX_U8               *buffer);
368 
369     OMX_ERRORTYPE  use_input_heap_buffers(
370                           OMX_HANDLETYPE            hComp,
371                           OMX_BUFFERHEADERTYPE** bufferHdr,
372                           OMX_U32                   port,
373                           OMX_PTR                   appData,
374                           OMX_U32                   bytes,
375                           OMX_U8*                   buffer);
376 
377     OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE     hComp,
378                                 OMX_BUFFERHEADERTYPE **bufferHdr,
379                                 OMX_U32              port,
380                                 OMX_PTR              appData,
381                                 void *               eglImage);
382     void complete_pending_buffer_done_cbs();
383     struct video_driver_context drv_ctx;
384     int  m_pipe_in;
385     int  m_pipe_out;
386     pthread_t msg_thread_id;
387     pthread_t async_thread_id;
388     bool is_component_secure();
389 
390 private:
391     // Bit Positions
392     enum flags_bit_positions
393     {
394         // Defer transition to IDLE
395         OMX_COMPONENT_IDLE_PENDING            =0x1,
396         // Defer transition to LOADING
397         OMX_COMPONENT_LOADING_PENDING         =0x2,
398         // First  Buffer Pending
399         OMX_COMPONENT_FIRST_BUFFER_PENDING    =0x3,
400         // Second Buffer Pending
401         OMX_COMPONENT_SECOND_BUFFER_PENDING   =0x4,
402         // Defer transition to Enable
403         OMX_COMPONENT_INPUT_ENABLE_PENDING    =0x5,
404         // Defer transition to Enable
405         OMX_COMPONENT_OUTPUT_ENABLE_PENDING   =0x6,
406         // Defer transition to Disable
407         OMX_COMPONENT_INPUT_DISABLE_PENDING   =0x7,
408         // Defer transition to Disable
409         OMX_COMPONENT_OUTPUT_DISABLE_PENDING  =0x8,
410         //defer flush notification
411         OMX_COMPONENT_OUTPUT_FLUSH_PENDING    =0x9,
412         OMX_COMPONENT_INPUT_FLUSH_PENDING    =0xA,
413         OMX_COMPONENT_PAUSE_PENDING          =0xB,
414         OMX_COMPONENT_EXECUTE_PENDING        =0xC,
415         OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD,
416         OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE
417     };
418 
419     // Deferred callback identifiers
420     enum
421     {
422         //Event Callbacks from the vdec component thread context
423         OMX_COMPONENT_GENERATE_EVENT       = 0x1,
424         //Buffer Done callbacks from the vdec component thread context
425         OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2,
426         //Frame Done callbacks from the vdec component thread context
427         OMX_COMPONENT_GENERATE_FRAME_DONE  = 0x3,
428         //Buffer Done callbacks from the vdec component thread context
429         OMX_COMPONENT_GENERATE_FTB         = 0x4,
430         //Frame Done callbacks from the vdec component thread context
431         OMX_COMPONENT_GENERATE_ETB         = 0x5,
432         //Command
433         OMX_COMPONENT_GENERATE_COMMAND     = 0x6,
434         //Push-Pending Buffers
435         OMX_COMPONENT_PUSH_PENDING_BUFS    = 0x7,
436         // Empty Buffer Done callbacks
437         OMX_COMPONENT_GENERATE_EBD         = 0x8,
438         //Flush Event Callbacks from the vdec component thread context
439         OMX_COMPONENT_GENERATE_EVENT_FLUSH       = 0x9,
440         OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A,
441         OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B,
442         OMX_COMPONENT_GENERATE_FBD = 0xc,
443         OMX_COMPONENT_GENERATE_START_DONE = 0xD,
444         OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE,
445         OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF,
446         OMX_COMPONENT_GENERATE_STOP_DONE = 0x10,
447         OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11,
448         OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12,
449         OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13,
450         OMX_COMPONENT_GENERATE_EOS_DONE = 0x14,
451         OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15,
452         OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16,
453     };
454 
455     enum vc1_profile_type
456     {
457         VC1_SP_MP_RCV = 1,
458         VC1_AP = 2
459     };
460 
461 #ifdef _COPPER_
462     enum v4l2_ports
463     {
464         CAPTURE_PORT,
465         OUTPUT_PORT,
466         MAX_PORT
467     };
468 #endif
469 
470     struct omx_event
471     {
472         unsigned param1;
473         unsigned param2;
474         unsigned id;
475     };
476 
477     struct omx_cmd_queue
478     {
479         omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE];
480         unsigned m_read;
481         unsigned m_write;
482         unsigned m_size;
483 
484         omx_cmd_queue();
485         ~omx_cmd_queue();
486         bool insert_entry(unsigned p1, unsigned p2, unsigned id);
487         bool pop_entry(unsigned *p1,unsigned *p2, unsigned *id);
488         // get msgtype of the first ele from the queue
489         unsigned get_q_msg_type();
490 
491     };
492 
493 #ifdef _ANDROID_
494     struct ts_entry
495     {
496         OMX_TICKS timestamp;
497         bool valid;
498     };
499 
500     struct ts_arr_list
501     {
502         ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS];
503 
504         ts_arr_list();
505         ~ts_arr_list();
506 
507         bool insert_ts(OMX_TICKS ts);
508         bool pop_min_ts(OMX_TICKS &ts);
509         bool reset_ts_list();
510     };
511 #endif
512 
513     struct desc_buffer_hdr
514     {
515         OMX_U8 *buf_addr;
516         OMX_U32 desc_data_size;
517     };
518     bool allocate_done(void);
519     bool allocate_input_done(void);
520     bool allocate_output_done(void);
521 
522     OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
523     OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex,
524                                     OMX_BUFFERHEADERTYPE *pmem_bufferHdr);
525     OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
526     void free_output_buffer_header();
527     void free_input_buffer_header();
528 
529     OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE       hComp,
530                                              OMX_BUFFERHEADERTYPE **bufferHdr,
531                                              OMX_U32              port,
532                                              OMX_PTR              appData,
533                                              OMX_U32              bytes);
534 
535 
536     OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE       hComp,
537                                         OMX_BUFFERHEADERTYPE **bufferHdr,
538                                         OMX_U32              port,
539                                         OMX_PTR              appData,
540                                         OMX_U32              bytes);
541 
542     OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE       hComp,
543                                          OMX_BUFFERHEADERTYPE **bufferHdr,
544                                          OMX_U32 port,OMX_PTR appData,
545                                          OMX_U32              bytes);
546     OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp,
547                                    OMX_BUFFERHEADERTYPE   **bufferHdr,
548                                    OMX_U32                port,
549                                    OMX_PTR                appData,
550                                    OMX_U32                bytes,
551                                    OMX_U8                 *buffer);
552 #ifdef MAX_RES_720P
553     OMX_ERRORTYPE get_supported_profile_level_for_720p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
554 #endif
555 #ifdef MAX_RES_1080P
556     OMX_ERRORTYPE get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
557 #endif
558 
559     OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index);
560     OMX_ERRORTYPE allocate_output_headers();
561     bool execute_omx_flush(OMX_U32);
562     bool execute_output_flush();
563     bool execute_input_flush();
564     OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp,
565                                     OMX_BUFFERHEADERTYPE * buffer);
566 
567     OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp,
568                                     OMX_BUFFERHEADERTYPE * buffer);
569     OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE       hComp,
570                                         OMX_BUFFERHEADERTYPE *buffer);
571 
572     OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp,
573                                                    OMX_BUFFERHEADERTYPE *buffer
574                                                    );
575 
576     OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp);
577     OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp);
578     OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp);
579     OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp);
580 
581     OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
582                                        OMX_BUFFERHEADERTYPE *buffer);
583     bool release_done();
584 
585     bool release_output_done();
586     bool release_input_done();
587     OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop);
588     OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop);
589     OMX_ERRORTYPE start_port_reconfig();
590     OMX_ERRORTYPE update_picture_resolution();
591 	void stream_off();
592     void adjust_timestamp(OMX_S64 &act_timestamp);
593     void set_frame_rate(OMX_S64 act_timestamp);
594     void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr);
595     OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true);
596     void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra);
597     void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
598                                     OMX_U32 interlaced_format_type);
599     void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
600                                OMX_U32 num_conceal_mb,
601                                OMX_U32 picture_type,
602                                OMX_S64 timestamp,
603                                OMX_U32 frame_rate,
604                                struct vdec_aspectratioinfo *aspect_ratio_info);
605     void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info,
606                                 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info);
607     void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra);
608     OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn);
609     void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra);
610     void insert_demux_addr_offset(OMX_U32 address_offset);
611     void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr);
612     OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr);
613     OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra);
614 
615     bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
616                             OMX_U32 alignment);
617 #ifdef USE_ION
618     int alloc_map_ion_memory(OMX_U32 buffer_size,
619               OMX_U32 alignment, struct ion_allocation_data *alloc_data,
620               struct ion_fd_data *fd_data,int flag);
621     void free_ion_memory(struct vdec_ion *buf_ion_info);
622 #endif
623 
624 
625     OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
626                                      OMX_COMMANDTYPE cmd,
627                                      OMX_U32         param1,
628                                      OMX_PTR         cmdData);
629     bool post_event( unsigned int p1,
630                      unsigned int p2,
631                      unsigned int id
632                     );
clip2(int x)633     inline int clip2(int x)
634     {
635         x = x -1;
636         x = x | x >> 1;
637         x = x | x >> 2;
638         x = x | x >> 4;
639         x = x | x >> 16;
640         x = x + 1;
641         return x;
642     }
643 
644 #ifdef MAX_RES_1080P
645     OMX_ERRORTYPE vdec_alloc_h264_mv();
646     void vdec_dealloc_h264_mv();
647 #endif
648 
omx_report_error()649     inline void omx_report_error ()
650     {
651         if (m_cb.EventHandler && !m_error_propogated)
652         {
653             ALOGE("\nERROR: Sending OMX_EventError to Client");
654             m_error_propogated = true;
655             m_cb.EventHandler(&m_cmp,m_app_data,
656                   OMX_EventError,OMX_ErrorHardware,0,NULL);
657         }
658     }
659 #ifdef _ANDROID_
660     OMX_ERRORTYPE createDivxDrmContext();
661 #endif //_ANDROID_
662 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
663     OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data);
664 #endif
665 #if defined (_ANDROID_ICS_)
666     struct nativebuffer{
667         native_handle_t *nativehandle;
668         int inuse;
669     };
670     nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
671 #endif
672 
673 
674     //*************************************************************
675     //*******************MEMBER VARIABLES *************************
676     //*************************************************************
677     pthread_mutex_t       m_lock;
678     //sem to handle the minimum procesing of commands
679     sem_t                 m_cmd_lock;
680     bool              m_error_propogated;
681     // compression format
682     OMX_VIDEO_CODINGTYPE eCompressionFormat;
683     // OMX State
684     OMX_STATETYPE m_state;
685     // Application data
686     OMX_PTR m_app_data;
687     // Application callbacks
688     OMX_CALLBACKTYPE m_cb;
689     OMX_PRIORITYMGMTTYPE m_priority_mgm ;
690     OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier;
691     // fill this buffer queue
692     omx_cmd_queue         m_ftb_q;
693     // Command Q for rest of the events
694     omx_cmd_queue         m_cmd_q;
695     omx_cmd_queue         m_etb_q;
696     // Input memory pointer
697     OMX_BUFFERHEADERTYPE  *m_inp_mem_ptr;
698     // Output memory pointer
699     OMX_BUFFERHEADERTYPE  *m_out_mem_ptr;
700     // number of input bitstream error frame count
701     unsigned int m_inp_err_count;
702 #ifdef _ANDROID_
703     // Timestamp list
704     ts_arr_list           m_timestamp_list;
705 #endif
706 
707     bool input_flush_progress;
708     bool output_flush_progress;
709     bool input_use_buffer;
710     bool output_use_buffer;
711     bool ouput_egl_buffers;
712     OMX_BOOL m_use_output_pmem;
713     OMX_BOOL m_out_mem_region_smi;
714     OMX_BOOL m_out_pvt_entry_pmem;
715 
716     int pending_input_buffers;
717     int pending_output_buffers;
718     // bitmask array size for output side
719     unsigned int m_out_bm_count;
720     // bitmask array size for input side
721     unsigned int m_inp_bm_count;
722     //Input port Populated
723     OMX_BOOL m_inp_bPopulated;
724     //Output port Populated
725     OMX_BOOL m_out_bPopulated;
726     // encapsulate the waiting states.
727     unsigned int m_flags;
728 
729 #ifdef _ANDROID_
730     // Heap pointer to frame buffers
731     struct vidc_heap
732     {
733         sp<MemoryHeapBase>    video_heap_ptr;
734     };
735     struct vidc_heap *m_heap_ptr;
736     unsigned int m_heap_count;
737 #endif //_ANDROID_
738     // store I/P PORT state
739     OMX_BOOL m_inp_bEnabled;
740     // store O/P PORT state
741     OMX_BOOL m_out_bEnabled;
742     OMX_U32 m_in_alloc_cnt;
743     OMX_U8                m_cRole[OMX_MAX_STRINGNAME_SIZE];
744     // Platform specific details
745     OMX_QCOM_PLATFORM_PRIVATE_LIST      *m_platform_list;
746     OMX_QCOM_PLATFORM_PRIVATE_ENTRY     *m_platform_entry;
747     OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info;
748     // SPS+PPS sent as part of set_config
749     OMX_VENDOR_EXTRADATATYPE            m_vendor_config;
750 
751     /*Variables for arbitrary Byte parsing support*/
752     frame_parse m_frame_parser;
753     omx_cmd_queue m_input_pending_q;
754     omx_cmd_queue m_input_free_q;
755     bool arbitrary_bytes;
756     OMX_BUFFERHEADERTYPE  h264_scratch;
757     OMX_BUFFERHEADERTYPE  *psource_frame;
758     OMX_BUFFERHEADERTYPE  *pdest_frame;
759     OMX_BUFFERHEADERTYPE  *m_inp_heap_ptr;
760     OMX_BUFFERHEADERTYPE  **m_phdr_pmem_ptr;
761     unsigned int m_heap_inp_bm_count;
762     codec_type codec_type_parse;
763     bool first_frame_meta;
764     unsigned frame_count;
765     unsigned nal_count;
766     unsigned nal_length;
767     bool look_ahead_nal;
768     int first_frame;
769     unsigned char *first_buffer;
770     int first_frame_size;
771     unsigned char m_hwdevice_name[80];
772     FILE *m_device_file_ptr;
773     enum vc1_profile_type m_vc1_profile;
774     OMX_S64 h264_last_au_ts;
775     OMX_U32 h264_last_au_flags;
776     OMX_U32 m_demux_offsets[8192];
777     OMX_U32 m_demux_entries;
778 
779     OMX_S64 prev_ts;
780     bool rst_prev_ts;
781     OMX_U32 frm_int;
782 
783     struct vdec_allocatorproperty op_buf_rcnfg;
784     bool in_reconfig;
785     OMX_NATIVE_WINDOWTYPE m_display_id;
786     h264_stream_parser *h264_parser;
787     OMX_U32 client_extradata;
788 #ifdef _ANDROID_
789     bool m_debug_timestamp;
790     bool perf_flag;
791     OMX_U32 proc_frms, latency;
792     perf_metrics fps_metrics;
793     perf_metrics dec_time;
794     bool m_enable_android_native_buffers;
795     bool m_use_android_native_buffers;
796     bool m_debug_extradata;
797     bool m_debug_concealedmb;
798 #endif
799 #ifdef MAX_RES_1080P
800     MP4_Utils mp4_headerparser;
801 #endif
802 
803     struct h264_mv_buffer{
804         unsigned char* buffer;
805         int size;
806         int count;
807         int pmem_fd;
808         int offset;
809     };
810     h264_mv_buffer h264_mv_buff;
811 	extra_data_handler extra_data_handle;
812 #ifdef _ANDROID_
813     DivXDrmDecrypt* iDivXDrmDecrypt;
814 #endif //_ANDROID_
815     OMX_PARAM_PORTDEFINITIONTYPE m_port_def;
816     omx_time_stamp_reorder time_stamp_dts;
817     desc_buffer_hdr *m_desc_buffer_ptr;
818     bool secure_mode;
819     OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata;
820     bool codec_config_flag;
821 #ifdef _COPPER_
822     int capture_capability;
823     int output_capability;
824     bool streaming[MAX_PORT];
825 #endif
826     unsigned int m_fill_output_msg;
827     class allocate_color_convert_buf {
828     public:
829         allocate_color_convert_buf();
830         ~allocate_color_convert_buf();
831         void set_vdec_client(void *);
832         void update_client();
833         bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format);
834         bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format);
835         bool update_buffer_req();
836         bool get_buffer_req(unsigned int &buffer_size);
837         OMX_BUFFERHEADERTYPE* get_il_buf_hdr();
838         OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
839         OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
840         OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header);
841         OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header);
842         OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
843              OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,
844              OMX_U32 bytes);
845         OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
846     private:
847         #define MAX_COUNT 32
848         omx_vdec *omx;
849         bool enabled;
850         OMX_COLOR_FORMATTYPE ColorFormat;
851         void init_members();
852         bool color_convert_mode;
853         ColorConvertFormat dest_format;
854         class omx_c2d_conv c2d;
855         unsigned int allocated_count;
856         unsigned int buffer_size_req;
857         unsigned int buffer_alignment_req;
858         OMX_QCOM_PLATFORM_PRIVATE_LIST      m_platform_list_client[MAX_COUNT];
859         OMX_QCOM_PLATFORM_PRIVATE_ENTRY     m_platform_entry_client[MAX_COUNT];
860         OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT];
861         OMX_BUFFERHEADERTYPE  m_out_mem_ptr_client[MAX_COUNT];
862         struct vdec_ion op_buf_ion_info[MAX_COUNT];
863         unsigned char *pmem_baseaddress[MAX_COUNT];
864         int pmem_fd[MAX_COUNT];
865         struct vidc_heap
866         {
867             sp<MemoryHeapBase>    video_heap_ptr;
868         };
869         struct vidc_heap m_heap_ptr[MAX_COUNT];
870     };
871     allocate_color_convert_buf client_buffers;
872     static bool m_secure_display; //For qservice
873     int secureDisplay(int mode);
874     int unsecureDisplay(int mode);
875 };
876 
877 #ifdef _COPPER_
878 enum instance_state {
879 	MSM_VIDC_CORE_UNINIT_DONE = 0x0001,
880 	MSM_VIDC_CORE_INIT,
881 	MSM_VIDC_CORE_INIT_DONE,
882 	MSM_VIDC_OPEN,
883 	MSM_VIDC_OPEN_DONE,
884 	MSM_VIDC_LOAD_RESOURCES,
885 	MSM_VIDC_LOAD_RESOURCES_DONE,
886 	MSM_VIDC_START,
887 	MSM_VIDC_START_DONE,
888 	MSM_VIDC_STOP,
889 	MSM_VIDC_STOP_DONE,
890 	MSM_VIDC_RELEASE_RESOURCES,
891 	MSM_VIDC_RELEASE_RESOURCES_DONE,
892 	MSM_VIDC_CLOSE,
893 	MSM_VIDC_CLOSE_DONE,
894 	MSM_VIDC_CORE_UNINIT,
895 };
896 
897 enum vidc_resposes_id {
898 	MSM_VIDC_DECODER_FLUSH_DONE = 0x11,
899 	MSM_VIDC_DECODER_EVENT_CHANGE,
900 };
901 
902 #endif // _COPPER_
903 
904 #endif // __OMX_VDEC_H__
905