1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010 - 2020, 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 <dlfcn.h>
51 #include <cutils/atomic.h>
52 #include <qdMetaData.h>
53 #include <color_metadata.h>
54 #define STRINGIFY_ENUMS
55 #include "media/hardware/VideoAPI.h"
56 #include "media/hardware/HardwareAPI.h"
57 #include <unordered_map>
58 #include <media/msm_media_info.h>
59 #include <OMX_Core.h>
60 #include <list>
61 
62 #include <linux/msm_ion.h>
63 #if TARGET_ION_ABI_VERSION >= 2
64 #include <ion/ion.h>
65 #include <linux/dma-buf.h>
66 #else
67 #include <linux/ion.h>
68 #endif
69 
70 #include "C2DColorConverter.h"
71 
72 static ptrdiff_t x;
73 
74 extern "C" {
75 #include <utils/Log.h>
76 }
77 
78 #ifdef _ANDROID_
79 #undef LOG_TAG
80 #define LOG_TAG "OMX-VDEC-1080P"
81 
82 #ifdef USE_ION
83 #include <linux/msm_ion.h>
84 //#include <binder/MemoryHeapIon.h>
85 //#else
86 #endif
87 
88 #ifdef USE_GBM
89 #include "gbm.h"
90 #include "gbm_priv.h"
91 #endif
92 
93 #ifndef NATIVE_BASE_DISABLE
94 #include <nativebase/nativebase.h>
95 #endif
96 #include <linux/videodev2.h>
97 #define VALID_TS(ts)      ((ts < LLONG_MAX)? true : false)
98 #include <poll.h>
99 #define TIMEOUT 5000
100 #endif // _ANDROID_
101 
102 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
103 #define STRINGIFY_ENUMS
104 #include <media/hardware/HardwareAPI.h>
105 #endif
106 
107 #include <unistd.h>
108 
109 #if defined (_ANDROID_ICS_)
110 #include <gralloc_priv.h>
111 #endif
112 
113 #include <pthread.h>
114 #ifndef PC_DEBUG
115 #include <semaphore.h>
116 #endif
117 #include "OMX_Core.h"
118 #include "OMX_QCOMExtns.h"
119 #include "OMX_Skype_VideoExtensions.h"
120 #include "OMX_VideoExt.h"
121 #include "OMX_IndexExt.h"
122 #include "qc_omx_component.h"
123 #include "media/msm_vidc_utils.h"
124 #include "extra_data_handler.h"
125 #include "ts_parser.h"
126 #include "vidc_debug.h"
127 #include "vidc_common.h"
128 #include "vidc_vendor_extensions.h"
129 extern "C" {
130     OMX_API void * get_omx_component_factory_fn(void);
131 }
132 
133 //////////////////////////////////////////////////////////////////////////////
134 //                       Module specific globals
135 //////////////////////////////////////////////////////////////////////////////
136 #define OMX_SPEC_VERSION  0x00000101
137 #define OMX_INIT_STRUCT(_s_, _name_)         \
138     memset((_s_), 0x0, sizeof(_name_));      \
139 (_s_)->nSize = sizeof(_name_);               \
140 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION  \
141 
142 
143 //////////////////////////////////////////////////////////////////////////////
144 //               Macros
145 //////////////////////////////////////////////////////////////////////////////
146 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\
147         (unsigned) bufHdr,\
148         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\
149         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\
150         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp)
151 
152 #define DEFAULT_FPS 30
153 #define MAX_SUPPORTED_FPS 960
154 #define DEFAULT_WIDTH_ALIGNMENT 128
155 #define DEFAULT_HEIGHT_ALIGNMENT 32
156 
157 #define SZ_4K 0x1000
158 #define SZ_1M 0x100000
159 
160 #define Log2(number, power)  { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) &&  power < 16) { temp >>=0x1; power++; } }
161 #define Q16ToFraction(q,num,den) { OMX_U32 power; Log2(q,power);  num = q >> power; den = 0x1 << (16 - power); }
162 #define EXTRADATA_IDX(__num_planes) ((__num_planes) ? (__num_planes) - 1 : 0)
163 #undef ALIGN
164 #define ALIGN(x, to_align) ((((unsigned) x) + (to_align - 1)) & ~(to_align - 1))
165 
166 // Y=16(0-9bits), Cb(10-19bits)=Cr(20-29bits)=128, black by default
167 #define DEFAULT_VIDEO_CONCEAL_COLOR_BLACK 0x8020010
168 
169 #define OMX_CORE_CONTROL_CMDQ_SIZE   100
170 #define OMX_CORE_QCIF_HEIGHT         144
171 #define OMX_CORE_QCIF_WIDTH          176
172 #define OMX_CORE_VGA_HEIGHT          480
173 #define OMX_CORE_VGA_WIDTH           640
174 #define OMX_CORE_WVGA_HEIGHT         480
175 #define OMX_CORE_WVGA_WIDTH          800
176 #define OMX_CORE_FWVGA_HEIGHT        480
177 #define OMX_CORE_FWVGA_WIDTH         864
178 
179 #define DESC_BUFFER_SIZE (8192 * 16)
180 
181 #ifdef _ANDROID_
182 #define MAX_NUM_INPUT_OUTPUT_BUFFERS VIDEO_MAX_FRAME
183 #endif
184 
185 // Aligning to MAX NUM INPUT & OUTPUT
186 #define MIN_NUM_INPUT_OUTPUT_EXTRADATA_BUFFERS MAX_NUM_INPUT_OUTPUT_BUFFERS
187 
188 /* STATUS CODES */
189 /* Base value for status codes */
190 #define VDEC_S_BASE	0x40000000
191 /* Success */
192 #define VDEC_S_SUCCESS	(VDEC_S_BASE)
193 /* General failure */
194 #define VDEC_S_EFAIL	(VDEC_S_BASE + 1)
195 /* Fatal irrecoverable  failure. Need to  tear down session. */
196 #define VDEC_S_EFATAL   (VDEC_S_BASE + 2)
197 /* Error with input bistream */
198 #define VDEC_S_INPUT_BITSTREAM_ERR (VDEC_S_BASE + 3)
199 
200 #define VDEC_MSG_BASE	0x0000000
201 /* Codes to identify asynchronous message responses and events that driver
202   wants to communicate to the app.*/
203 #define VDEC_MSG_RESP_INPUT_BUFFER_DONE	(VDEC_MSG_BASE + 1)
204 #define VDEC_MSG_RESP_OUTPUT_BUFFER_DONE	(VDEC_MSG_BASE + 2)
205 #define VDEC_MSG_RESP_INPUT_FLUSHED	(VDEC_MSG_BASE + 3)
206 #define VDEC_MSG_RESP_OUTPUT_FLUSHED	(VDEC_MSG_BASE + 4)
207 #define VDEC_MSG_RESP_FLUSH_INPUT_DONE	(VDEC_MSG_BASE + 5)
208 #define VDEC_MSG_RESP_FLUSH_OUTPUT_DONE	(VDEC_MSG_BASE + 6)
209 #define VDEC_MSG_RESP_START_DONE	(VDEC_MSG_BASE + 7)
210 #define VDEC_MSG_RESP_STOP_DONE	(VDEC_MSG_BASE + 8)
211 #define VDEC_MSG_RESP_PAUSE_DONE	(VDEC_MSG_BASE + 9)
212 #define VDEC_MSG_RESP_RESUME_DONE	(VDEC_MSG_BASE + 10)
213 #define VDEC_MSG_EVT_CONFIG_CHANGED	(VDEC_MSG_BASE + 11)
214 #define VDEC_MSG_EVT_HW_ERROR	(VDEC_MSG_BASE + 12)
215 #define VDEC_MSG_EVT_INFO_FIELD_DROPPED	(VDEC_MSG_BASE + 13)
216 #define VDEC_MSG_EVT_HW_OVERLOAD	(VDEC_MSG_BASE + 14)
217 #define VDEC_MSG_EVT_MAX_CLIENTS	(VDEC_MSG_BASE + 15)
218 #define VDEC_MSG_EVT_HW_UNSUPPORTED	(VDEC_MSG_BASE + 16)
219 
220 using namespace android;
221 
222 enum port_indexes {
223     OMX_CORE_INPUT_PORT_INDEX        =0,
224     OMX_CORE_OUTPUT_PORT_INDEX       =1,
225     OMX_CORE_INPUT_EXTRADATA_INDEX   =2,
226     OMX_CORE_OUTPUT_EXTRADATA_INDEX  =3
227 };
228 
229 enum vdec_codec {
230 	VDEC_CODECTYPE_H264 = 0x1,
231 	VDEC_CODECTYPE_H263 = 0x2,
232 	VDEC_CODECTYPE_MPEG4 = 0x3,
233 	VDEC_CODECTYPE_DIVX_3 = 0x4,
234 	VDEC_CODECTYPE_DIVX_4 = 0x5,
235 	VDEC_CODECTYPE_DIVX_5 = 0x6,
236 	VDEC_CODECTYPE_DIVX_6 = 0x7,
237 	VDEC_CODECTYPE_XVID = 0x8,
238 	VDEC_CODECTYPE_MPEG1 = 0x9,
239 	VDEC_CODECTYPE_MPEG2 = 0xa,
240 	VDEC_CODECTYPE_VC1 = 0xb,
241 	VDEC_CODECTYPE_VC1_RCV = 0xc,
242 	VDEC_CODECTYPE_HEVC = 0xd,
243 	VDEC_CODECTYPE_MVC = 0xe,
244 	VDEC_CODECTYPE_VP8 = 0xf,
245 	VDEC_CODECTYPE_VP9 = 0x10,
246 };
247 
248 enum vdec_output_format {
249 	VDEC_YUV_FORMAT_NV12 = 0x1,
250 	VDEC_YUV_FORMAT_TILE_4x2 = 0x2,
251 	VDEC_YUV_FORMAT_NV12_UBWC = 0x3,
252 	VDEC_YUV_FORMAT_NV12_TP10_UBWC = 0x4,
253 	VDEC_YUV_FORMAT_P010_VENUS = 0x5,
254 };
255 
256 enum vdec_interlaced_format {
257     VDEC_InterlaceFrameProgressive = 0x1,
258     VDEC_InterlaceInterleaveFrameTopFieldFirst = 0x2,
259     VDEC_InterlaceInterleaveFrameBottomFieldFirst = 0x4,
260     VDEC_InterlaceFrameTopFieldFirst = 0x8,
261     VDEC_InterlaceFrameBottomFieldFirst = 0x10,
262 };
263 
264 enum vdec_output_order {
265 	VDEC_ORDER_DISPLAY = 0x1,
266 	VDEC_ORDER_DECODE = 0x2
267 };
268 
269 struct vdec_framesize {
270 	uint32_t   left;
271 	uint32_t   top;
272 	uint32_t   right;
273 	uint32_t   bottom;
274 };
275 
276 struct vdec_picsize {
277 	uint32_t frame_width;
278 	uint32_t frame_height;
279 	uint32_t stride;
280 	uint32_t scan_lines;
281 };
282 
283 enum vdec_buffer {
284 	VDEC_BUFFER_TYPE_INPUT,
285 	VDEC_BUFFER_TYPE_OUTPUT
286 };
287 
288 struct vdec_allocatorproperty {
289 	enum vdec_buffer buffer_type;
290 	uint32_t mincount;
291 	uint32_t maxcount;
292 	uint32_t actualcount;
293 	size_t buffer_size;
294 	uint32_t alignment;
295 	uint32_t buf_poolid;
296 	size_t meta_buffer_size;
297 };
298 
299 struct vdec_bufferpayload {
300 	void *bufferaddr;
301 	size_t buffer_len;
302 	int pmem_fd;
303 	size_t offset;
304 	size_t mmaped_size;
305 };
306 
307 enum vdec_picture {
308 	PICTURE_TYPE_I,
309 	PICTURE_TYPE_P,
310 	PICTURE_TYPE_B,
311 	PICTURE_TYPE_BI,
312 	PICTURE_TYPE_SKIP,
313 	PICTURE_TYPE_IDR,
314 	PICTURE_TYPE_UNKNOWN
315 };
316 
317 struct vdec_misrinfo {
318         uint32_t misr_dpb_luma;
319         uint32_t misr_dpb_chroma;
320         uint32_t misr_opb_luma;
321         uint32_t misr_opb_chroma;
322 };
323 
324 struct vdec_output_frameinfo {
325 	void *bufferaddr;
326 	size_t offset;
327 	size_t len;
328 	uint32_t flags;
329 	uint64_t time_stamp;
330 	enum vdec_picture pic_type;
331 	void *client_data;
332 	struct vdec_picsize picsize;
333 	struct vdec_framesize framesize;
334 };
335 
336 union vdec_msgdata {
337 	struct vdec_output_frameinfo output_frame;
338 	void *input_frame_clientdata;
339 };
340 
341 struct vdec_msginfo {
342 	uint32_t status_code;
343 	uint32_t msgcode;
344 	union vdec_msgdata msgdata;
345 	size_t msgdatasize;
346 };
347 
348 struct vdec_framerate {
349 	unsigned long fps_denominator;
350 	unsigned long fps_numerator;
351 };
352 
353 struct hdr10plusInfo {
354     bool is_new;
355     unsigned int cookie;
356     OMX_TICKS timestamp;
357     OMX_U32 nSize;
358     OMX_VERSIONTYPE nVersion;
359     OMX_U32 nPortIndex;
360     OMX_U32 nParamSize;
361     OMX_U32 nParamSizeUsed;
362     OMX_U8 payload[MAX_HDR10PLUSINFO_SIZE];
363 };
364 
365 #ifdef USE_ION
366 struct vdec_ion {
367     int dev_fd;
368     struct ion_allocation_data alloc_data;
369     int data_fd;
370     char *uaddr;
371 };
372 #endif
373 
374 #ifdef USE_GBM
375 struct vdec_gbm {
376     int gbm_device_fd;
377     struct gbm_device *gbm;
378     struct gbm_bo *bo;
379     unsigned long bo_fd;
380     unsigned long meta_fd;
381 };
382 #endif
383 
384 
385 struct extradata_buffer_info {
386     unsigned long buffer_size;
387     int count;
388 #ifdef USE_ION
389     struct vdec_ion ion[VIDEO_MAX_FRAME];
390 #endif
391 };
392 
393 struct video_driver_context {
394     int video_driver_fd;
395     enum vdec_codec decoder_format;
396     enum vdec_output_format output_format;
397     enum vdec_interlaced_format interlace;
398     enum vdec_output_order picture_order;
399     struct vdec_framesize frame_size;
400     struct vdec_picsize video_resolution;
401     struct vdec_allocatorproperty ip_buf;
402     struct vdec_allocatorproperty op_buf;
403     struct vdec_bufferpayload *ptr_inputbuffer;
404     struct vdec_bufferpayload *ptr_outputbuffer;
405     struct vdec_output_frameinfo *ptr_respbuffer;
406     struct vdec_bufferpayload *ptr_intermediate_outputbuffer;
407     struct vdec_output_frameinfo *ptr_intermediate_respbuffer;
408 #ifdef USE_ION
409     struct vdec_ion *ip_buf_ion_info;
410     struct vdec_ion *op_buf_ion_info;
411     struct vdec_ion *op_intermediate_buf_ion_info;
412     struct vdec_ion h264_mv;
413     struct vdec_ion meta_buffer;
414     struct vdec_ion meta_buffer_iommu;
415 #endif
416 #ifdef USE_GBM
417     int gbm_device_fd;
418     struct vdec_gbm *op_buf_gbm_info;
419     struct vdec_gbm *op_intermediate_buf_gbm_info;
420 #endif
421     struct vdec_framerate frame_rate;
422     bool timestamp_adjust;
423     char kind[128];
424     bool idr_only_decoding;
425     unsigned disable_dmx;
426     struct extradata_buffer_info extradata_info;
427     int num_planes;
428 };
429 
430 struct video_decoder_capability {
431     unsigned int min_width;
432     unsigned int max_width;
433     unsigned int min_height;
434     unsigned int max_height;
435 };
436 
437 struct dynamic_buf_list {
438     long fd;
439     long dup_fd;
440     OMX_U32 offset;
441     OMX_U32 ref_count;
442     void *buffaddr;
443     long mapped_size;
444 };
445 
446 struct extradata_misr_info {
447     OMX_BOOL output_crop_updated;
448     OMX_CONFIG_RECTTYPE output_crop_rect;
449     OMX_U32 output_width;
450     OMX_U32 output_height;
451     OMX_QCOM_MISR_INFO misr_info[2];
452 };
453 
454 struct reconfig_client_data {
455     OMX_U32 width;
456     OMX_U32 height;
457     OMX_U32 dpb_bit_depth;
458     OMX_U32 m_progressive;
459     bool isPortReconfigInsufficient;
460 };
461 
462 struct reconfig_client_crop_data {
463     OMX_U32 width;
464     OMX_U32 height;
465     OMX_U32 left;
466     OMX_U32 top;
467     bool isPortReconfigInsufficient;
468 };
469 
470 typedef std::unordered_map <int, int> ColorSubMapping;
471 typedef std::unordered_map <int, ColorSubMapping> DecColorMapping;
472 typedef std::unordered_map <enum ColorAspects::Primaries, ColorPrimaries> PrimariesMap;
473 typedef std::unordered_map <enum ColorAspects::Transfer, GammaTransfer> TransferMap;
474 typedef std::unordered_map <enum ColorAspects::MatrixCoeffs, MatrixCoEfficients> MatrixCoeffMap;
475 typedef std::unordered_map <enum ColorAspects::Range, ColorRange> RangeMap;
476 
477 class perf_metrics
478 {
479     public:
perf_metrics()480         perf_metrics() :
481             start_time(0),
482             proc_time(0),
483             active(false) {
484             };
~perf_metrics()485         ~perf_metrics() {};
486         void start();
487         void stop();
488         void end(OMX_U32 units_cntr = 0);
489         void reset();
490         OMX_U64 processing_time_us();
491     private:
492         inline OMX_U64 get_act_time();
493         OMX_U64 start_time;
494         OMX_U64 proc_time;
495         bool active;
496 };
497 
498 // OMX video decoder class
499 class omx_vdec: public qc_omx_component
500 {
501 
502     public:
503         omx_vdec();  // constructor
504         virtual ~omx_vdec();  // destructor
505 
506         static int async_message_process (void *context, void* message);
507         static void process_event_cb(void *ctxt);
508 
509         OMX_ERRORTYPE allocate_buffer(
510                 OMX_HANDLETYPE hComp,
511                 OMX_BUFFERHEADERTYPE **bufferHdr,
512                 OMX_U32 port,
513                 OMX_PTR appData,
514                 OMX_U32 bytes
515                 );
516 
517 
518         OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);
519 
520         OMX_ERRORTYPE component_init(OMX_STRING role);
521 
522         OMX_ERRORTYPE component_role_enum(
523                 OMX_HANDLETYPE hComp,
524                 OMX_U8 *role,
525                 OMX_U32 index
526                 );
527 
528         OMX_ERRORTYPE component_tunnel_request(
529                 OMX_HANDLETYPE hComp,
530                 OMX_U32 port,
531                 OMX_HANDLETYPE  peerComponent,
532                 OMX_U32 peerPort,
533                 OMX_TUNNELSETUPTYPE *tunnelSetup
534                 );
535 
536         OMX_ERRORTYPE empty_this_buffer(
537                 OMX_HANDLETYPE hComp,
538                 OMX_BUFFERHEADERTYPE *buffer
539                 );
540 
541 
542 
543         OMX_ERRORTYPE fill_this_buffer(
544                 OMX_HANDLETYPE hComp,
545                 OMX_BUFFERHEADERTYPE *buffer
546                 );
547 
548 
549         OMX_ERRORTYPE free_buffer(
550                 OMX_HANDLETYPE hComp,
551                 OMX_U32 port,
552                 OMX_BUFFERHEADERTYPE *buffer
553                 );
554 
555         OMX_ERRORTYPE get_component_version(
556                 OMX_HANDLETYPE hComp,
557                 OMX_STRING componentName,
558                 OMX_VERSIONTYPE *componentVersion,
559                 OMX_VERSIONTYPE *specVersion,
560                 OMX_UUIDTYPE *componentUUID
561                 );
562 
563         OMX_ERRORTYPE get_config(
564                 OMX_HANDLETYPE hComp,
565                 OMX_INDEXTYPE configIndex,
566                 OMX_PTR configData
567                 );
568 
569         OMX_ERRORTYPE get_extension_index(
570                 OMX_HANDLETYPE hComp,
571                 OMX_STRING paramName,
572                 OMX_INDEXTYPE *indexType
573                 );
574 
575         OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp,
576                 OMX_INDEXTYPE  paramIndex,
577                 OMX_PTR        paramData);
578 
579         OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp,
580                 OMX_STATETYPE *state);
581 
582 
583 
584         OMX_ERRORTYPE send_command(OMX_HANDLETYPE  hComp,
585                 OMX_COMMANDTYPE cmd,
586                 OMX_U32         param1,
587                 OMX_PTR         cmdData);
588 
589 
590         OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE   hComp,
591                 OMX_CALLBACKTYPE *callbacks,
592                 OMX_PTR          appData);
593 
594         OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
595                 OMX_INDEXTYPE  configIndex,
596                 OMX_PTR        configData);
597 
598         OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
599                 OMX_INDEXTYPE  paramIndex,
600                 OMX_PTR        paramData);
601 
602         OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE      hComp,
603                 OMX_BUFFERHEADERTYPE **bufferHdr,
604                 OMX_U32              port,
605                 OMX_PTR              appData,
606                 OMX_U32              bytes,
607                 OMX_U8               *buffer);
608 
609         OMX_ERRORTYPE  use_input_heap_buffers(
610                 OMX_HANDLETYPE            hComp,
611                 OMX_BUFFERHEADERTYPE** bufferHdr,
612                 OMX_U32                   port,
613                 OMX_PTR                   appData,
614                 OMX_U32                   bytes,
615                 OMX_U8*                   buffer);
616 
617         OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE     hComp,
618                 OMX_BUFFERHEADERTYPE **bufferHdr,
619                 OMX_U32              port,
620                 OMX_PTR              appData,
621                 void *               eglImage);
622         void complete_pending_buffer_done_cbs();
623         struct video_driver_context drv_ctx;
624         int m_poll_efd;
625         char *ion_map(int fd, int len);
626         OMX_ERRORTYPE ion_unmap(int fd, void *bufaddr, int len);
627         OMX_ERRORTYPE allocate_extradata();
628         void free_extradata();
629         int update_resolution(int width, int height, int stride, int scan_lines);
630         Signal signal;
631         pthread_t msg_thread_id;
632         pthread_t async_thread_id;
633         bool is_component_secure();
634         OMX_BUFFERHEADERTYPE* get_omx_output_buffer_header(int index);
635         int dpb_bit_depth;
636         bool check_supported_flexible_formats(OMX_COLOR_FORMATTYPE required_format);
637         bool is_flexible_format;//To save status if required format is flexible color formats
638         bool async_thread_force_stop;
639         volatile bool message_thread_stop;
640         struct extradata_misr_info m_extradata_misr;
641         int m_progressive;
642         bool is_mbaff;
643 
644         enum color_space_type {
645             BT2020 = 0,
646             EXCEPT_BT2020,
647             UNKNOWN
648         };
649         enum color_space_type m_color_space;
650 
651         /*
652          * Class variables to track client set profile and level
653          * via OMX_QTIIndexParamClientConfiguredMaxProfileLevelForSufficiency
654          */
655         bool isPortReconfigInsufficient;
656         inline int get_session_codec_type();
657 
658     private:
659         // Bit Positions
660         enum flags_bit_positions {
661             // Defer transition to IDLE
662             OMX_COMPONENT_IDLE_PENDING            =0x1,
663             // Defer transition to LOADING
664             OMX_COMPONENT_LOADING_PENDING         =0x2,
665             // First  Buffer Pending
666             OMX_COMPONENT_FIRST_BUFFER_PENDING    =0x3,
667             // Second Buffer Pending
668             OMX_COMPONENT_SECOND_BUFFER_PENDING   =0x4,
669             // Defer transition to Enable
670             OMX_COMPONENT_INPUT_ENABLE_PENDING    =0x5,
671             // Defer transition to Enable
672             OMX_COMPONENT_OUTPUT_ENABLE_PENDING   =0x6,
673             // Defer transition to Disable
674             OMX_COMPONENT_INPUT_DISABLE_PENDING   =0x7,
675             // Defer transition to Disable
676             OMX_COMPONENT_OUTPUT_DISABLE_PENDING  =0x8,
677             //defer flush notification
678             OMX_COMPONENT_OUTPUT_FLUSH_PENDING    =0x9,
679             OMX_COMPONENT_INPUT_FLUSH_PENDING    =0xA,
680             OMX_COMPONENT_PAUSE_PENDING          =0xB,
681             OMX_COMPONENT_EXECUTE_PENDING        =0xC,
682             OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD,
683             OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE,
684             OMX_COMPONENT_FLUSH_DEFERRED = 0xF
685         };
686 
687         // Deferred callback identifiers
688         enum {
689             //Event Callbacks from the vdec component thread context
690             OMX_COMPONENT_GENERATE_EVENT       = 0x1,
691             //Buffer Done callbacks from the vdec component thread context
692             OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2,
693             //Frame Done callbacks from the vdec component thread context
694             OMX_COMPONENT_GENERATE_FRAME_DONE  = 0x3,
695             //Buffer Done callbacks from the vdec component thread context
696             OMX_COMPONENT_GENERATE_FTB         = 0x4,
697             //Frame Done callbacks from the vdec component thread context
698             OMX_COMPONENT_GENERATE_ETB         = 0x5,
699             //Command
700             OMX_COMPONENT_GENERATE_COMMAND     = 0x6,
701             //Push-Pending Buffers
702             OMX_COMPONENT_PUSH_PENDING_BUFS    = 0x7,
703             // Empty Buffer Done callbacks
704             OMX_COMPONENT_GENERATE_EBD         = 0x8,
705             //Flush Event Callbacks from the vdec component thread context
706             OMX_COMPONENT_GENERATE_EVENT_FLUSH       = 0x9,
707             OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A,
708             OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B,
709             OMX_COMPONENT_GENERATE_FBD = 0xC,
710             OMX_COMPONENT_GENERATE_START_DONE = 0xD,
711             OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE,
712             OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF,
713             OMX_COMPONENT_GENERATE_STOP_DONE = 0x10,
714             OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11,
715             OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12,
716             OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13,
717             OMX_COMPONENT_GENERATE_EOS_DONE = 0x14,
718             OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15,
719             OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16,
720             OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x17,
721             OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD = 0x18,
722             OMX_COMPONENT_GENERATE_ION_PREFETCH_PIXEL = 0x19,
723             OMX_COMPONENT_GENERATE_ION_PREFETCH_NON_PIXEL = 0x1A,
724             OMX_COMPONENT_CLOSE_MSG = 0x1B
725         };
726 
727         enum vc1_profile_type {
728             VC1_SP_MP_RCV = 1,
729             VC1_AP = 2
730         };
731 
732         enum v4l2_ports {
733             CAPTURE_PORT,
734             OUTPUT_PORT,
735             MAX_PORT
736         };
737 
738         struct omx_event {
739             unsigned long param1;
740             unsigned long param2;
741             unsigned long id;
742         };
743 
744         struct omx_cmd_queue {
745             omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE];
746             unsigned long m_read;
747             unsigned long m_write;
748             unsigned long m_size;
749 
750             omx_cmd_queue();
751             ~omx_cmd_queue();
752             bool insert_entry(unsigned long p1, unsigned long p2, unsigned long id);
753             bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned long *id);
754             // get msgtype of the first ele from the queue
755             unsigned get_q_msg_type();
756 
757         };
758         struct v4l2_capability cap;
759 #ifdef _ANDROID_
760         struct ts_entry {
761             OMX_TICKS timestamp;
762             bool valid;
763         };
764 
765         struct ts_arr_list {
766             ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS];
767 
768             ts_arr_list();
769             ~ts_arr_list();
770 
771             bool insert_ts(OMX_TICKS ts);
772             bool pop_min_ts(OMX_TICKS &ts);
773             bool reset_ts_list();
774         };
775 #endif
776 
777         struct desc_buffer_hdr {
778             OMX_U8 *buf_addr;
779             OMX_U32 desc_data_size;
780         };
781         bool allocate_done(void);
782         bool allocate_input_done(void);
783         bool allocate_output_done(void);
784         bool allocate_output_extradata_done(void);
785 
786         OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
787         OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex,
788                 OMX_BUFFERHEADERTYPE *pmem_bufferHdr);
789         OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr,
790                                          bool                 intermediate=false);
791         void free_output_buffer_header(bool intermediate=false);
792         void free_input_buffer_header();
793         void free_output_extradata_buffer_header();
794 
795         OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE       hComp,
796                 OMX_BUFFERHEADERTYPE **bufferHdr,
797                 OMX_U32              port,
798                 OMX_PTR              appData,
799                 OMX_U32              bytes);
800 
801 
802         OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE       hComp,
803                 OMX_BUFFERHEADERTYPE **bufferHdr,
804                 OMX_U32              port,
805                 OMX_PTR              appData,
806                 OMX_U32              bytes);
807 
808         OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE       hComp,
809                 OMX_BUFFERHEADERTYPE **bufferHdr,
810                 OMX_U32 port,OMX_PTR appData,
811                 OMX_U32              bytes,
812                 bool                 intermediate=false,
813                 int                  index=-1);
814         OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp,
815                 OMX_BUFFERHEADERTYPE   **bufferHdr,
816                 OMX_U32                port,
817                 OMX_PTR                appData,
818                 OMX_U32                bytes,
819                 OMX_U8                 *buffer);
820         OMX_ERRORTYPE use_client_output_extradata_buffer(OMX_HANDLETYPE hComp,
821                 OMX_BUFFERHEADERTYPE   **bufferHdr,
822                 OMX_U32                port,
823                 OMX_PTR                appData,
824                 OMX_U32                bytes,
825                 OMX_U8                 *buffer);
826         OMX_ERRORTYPE get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
827 
828         OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index);
829         OMX_ERRORTYPE allocate_output_headers(bool intermediate=false);
830         OMX_ERRORTYPE allocate_client_output_extradata_headers();
831         bool execute_omx_flush(OMX_U32);
832         bool execute_output_flush();
833         bool execute_input_flush();
834         void notify_flush_done(void *ctxt);
835         OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp,
836                 OMX_BUFFERHEADERTYPE * buffer);
837 
838         OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp,
839                 OMX_BUFFERHEADERTYPE * buffer);
840         OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE       hComp,
841                 OMX_BUFFERHEADERTYPE *buffer);
842 
843         OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp,
844                 OMX_BUFFERHEADERTYPE *buffer
845                 );
846 
847         OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp);
848         OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp);
849         OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp);
850         OMX_ERRORTYPE push_input_hevc (OMX_HANDLETYPE hComp);
851 
852         OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
853                 OMX_BUFFERHEADERTYPE *buffer);
854         bool release_done();
855 
856         bool release_output_done();
857         bool release_input_done();
858         bool release_output_extradata_done();
859         OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop);
860         OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop);
861         OMX_ERRORTYPE start_port_reconfig();
862         OMX_ERRORTYPE update_picture_resolution();
863         int stream_off(OMX_U32 port);
864         void adjust_timestamp(OMX_S64 &act_timestamp);
865         void set_frame_rate(OMX_S64 act_timestamp);
866         bool handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr);
867         void convert_color_space_info(OMX_U32 primaries,
868             OMX_U32 transfer, OMX_U32 matrix,
869             ColorAspects *aspects);
870         bool handle_color_space_info(void *data);
871         bool handle_content_light_level_info(void* data);
872         bool handle_mastering_display_color_info(void* data);
873         OMX_ERRORTYPE enable_extradata(OMX_U64 requested_extradata);
874         OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn);
875         void fix_drv_output_format();
876         void insert_demux_addr_offset(OMX_U32 address_offset);
877         void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr);
878         OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr);
879         OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra);
880         void set_histogram_metadata(private_handle_t *private_handle);
881         struct VideoHistogramMetadata m_hist_metadata;
882 
883         bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
884                 OMX_U32 alignment);
885 #ifdef USE_ION
886         bool alloc_map_ion_memory(OMX_U32 buffer_size, vdec_ion *ion_info, int flag);
887         void free_ion_memory(struct vdec_ion *buf_ion_info);
888 #endif
889 
890 #ifdef USE_GBM
891         bool alloc_map_gbm_memory(OMX_U32 w,OMX_U32 h,int gbm_device_fd,
892               struct vdec_gbm *gbm_info, int flag);
893         void free_gbm_memory(struct vdec_gbm *buf_gbm_info);
894 #endif
895 
896 
897 
898         OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
899                 OMX_COMMANDTYPE cmd,
900                 OMX_U32         param1,
901                 OMX_PTR         cmdData);
902         bool post_event( unsigned long p1,
903                 unsigned long p2,
904                 unsigned long id
905                    );
clip2(int x)906         inline int clip2(int x) {
907             x = x -1;
908             x = x | x >> 1;
909             x = x | x >> 2;
910             x = x | x >> 4;
911             x = x | x >> 16;
912             x = x + 1;
913             return x;
914         }
915 
916         OMX_ERRORTYPE vdec_alloc_h264_mv();
917         void vdec_dealloc_h264_mv();
918         OMX_ERRORTYPE vdec_alloc_meta_buffers();
919         void vdec_dealloc_meta_buffers();
920 
omx_report_error()921         inline void omx_report_error () {
922             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
923                 DEBUG_PRINT_ERROR("ERROR: Sending OMX_ErrorHardware to Client");
924                 m_error_propogated = true;
925                 m_cb.EventHandler(&m_cmp,m_app_data,
926                         OMX_EventError,OMX_ErrorHardware,0,NULL);
927             }
928         }
929 
omx_report_unsupported_setting()930         inline void omx_report_unsupported_setting () {
931             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
932                 DEBUG_PRINT_ERROR(
933                         "ERROR: Sending OMX_ErrorUnsupportedSetting to Client");
934                 m_error_propogated = true;
935                 m_cb.EventHandler(&m_cmp, m_app_data,
936                         OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL);
937             }
938         }
omx_report_hw_overload()939         inline void omx_report_hw_overload () {
940             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
941                 DEBUG_PRINT_ERROR(
942                         "ERROR: Sending OMX_ErrorInsufficientResources to Client");
943                 m_error_propogated = true;
944                 m_cb.EventHandler(&m_cmp, m_app_data,
945                         OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL);
946             }
947         }
948 
949 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
950         OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data);
951 #endif
952 #if defined (_ANDROID_ICS_)
953         struct nativebuffer {
954             native_handle_t *nativehandle;
955             private_handle_t *privatehandle;
956             int inuse;
957         };
958         nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
959 #endif
960 
961         //*************************************************************
962         //*******************MEMBER VARIABLES *************************
963         //*************************************************************
964         pthread_mutex_t       m_lock;
965         pthread_mutex_t       c_lock;
966         pthread_mutex_t       buf_lock;
967         //sem to handle the minimum procesing of commands
968         sem_t                 m_cmd_lock;
969         sem_t                 m_safe_flush;
970         bool              m_error_propogated;
971         // compression format
972         OMX_VIDEO_CODINGTYPE eCompressionFormat;
973         // OMX State
974         OMX_STATETYPE m_state;
975         // Application data
976         OMX_PTR m_app_data;
977         // Application callbacks
978         OMX_CALLBACKTYPE m_cb;
979         OMX_PRIORITYMGMTTYPE m_priority_mgm ;
980         OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier;
981         // fill this buffer queue
982         omx_cmd_queue         m_ftb_q;
983         // Command Q for rest of the events
984         omx_cmd_queue         m_cmd_q;
985         omx_cmd_queue         m_etb_q;
986         // Input memory pointer
987         OMX_BUFFERHEADERTYPE  *m_inp_mem_ptr;
988         // Output memory pointer
989         OMX_BUFFERHEADERTYPE  *m_out_mem_ptr;
990         // Output memory pointer
991         OMX_BUFFERHEADERTYPE  *m_intermediate_out_mem_ptr;
992         // Client extradata memory pointer
993         OMX_BUFFERHEADERTYPE  *m_client_output_extradata_mem_ptr;
994         // number of input bitstream error frame count
995         unsigned int m_inp_err_count;
996 
997         pthread_mutex_t m_hdr10pluslock;
998         std::list<hdr10plusInfo> m_hdr10pluslist;
999 #ifdef _ANDROID_
1000         // Timestamp list
1001         ts_arr_list           m_timestamp_list;
1002 #endif
1003 
1004         char m_platform_name[PROPERTY_VALUE_MAX] = {0};
1005         bool input_flush_progress;
1006         bool output_flush_progress;
1007         bool input_use_buffer;
1008         bool output_use_buffer;
1009         bool ouput_egl_buffers;
1010         OMX_BOOL m_use_output_pmem;
1011 
1012         int pending_input_buffers;
1013         int pending_output_buffers;
1014         // bitmask array size for output side
1015         uint64_t m_out_bm_count;
1016         // bitmask array size for input side
1017         uint64_t m_inp_bm_count;
1018         // bitmask array size for extradata
1019         uint64_t m_out_extradata_bm_count;
1020         //Input port Populated
1021         OMX_BOOL m_inp_bPopulated;
1022         //Output port Populated
1023         OMX_BOOL m_out_bPopulated;
1024         // encapsulate the waiting states.
1025         uint64_t m_flags;
1026 
1027         OMX_U32 m_etb_count;
1028         OMX_TICKS m_etb_timestamp;
1029         // store I/P PORT state
1030         OMX_BOOL m_inp_bEnabled;
1031         // store O/P PORT state
1032         OMX_BOOL m_out_bEnabled;
1033         OMX_U32 m_in_alloc_cnt;
1034         OMX_U8                m_cRole[OMX_MAX_STRINGNAME_SIZE];
1035         // Platform specific details
1036         OMX_QCOM_PLATFORM_PRIVATE_LIST      *m_platform_list;
1037         OMX_QCOM_PLATFORM_PRIVATE_ENTRY     *m_platform_entry;
1038         OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info;
1039         // SPS+PPS sent as part of set_config
1040         OMX_VENDOR_EXTRADATATYPE            m_vendor_config;
1041 
1042         omx_cmd_queue m_input_pending_q;
1043         omx_cmd_queue m_input_free_q;
1044         OMX_BUFFERHEADERTYPE  *psource_frame;
1045         OMX_BUFFERHEADERTYPE  *pdest_frame;
1046         OMX_BUFFERHEADERTYPE  *m_inp_heap_ptr;
1047         OMX_BUFFERHEADERTYPE  **m_phdr_pmem_ptr;
1048         unsigned int m_heap_inp_bm_count;
1049         bool first_frame_meta;
1050         unsigned frame_count;
1051         unsigned nal_count;
1052         unsigned nal_length;
1053         int first_frame;
1054         unsigned char *first_buffer;
1055         int first_frame_size;
1056         unsigned char m_hwdevice_name[80];
1057         FILE *m_device_file_ptr;
1058         enum vc1_profile_type m_vc1_profile;
1059         OMX_U32 m_demux_offsets[8192];
1060         OMX_U32 m_demux_entries;
1061         OMX_U32 m_disp_hor_size;
1062         OMX_U32 m_disp_vert_size;
1063         OMX_S64 prev_ts;
1064         OMX_U32 frm_int;
1065         OMX_U32 m_fps_received;
1066 
1067         struct vdec_allocatorproperty op_buf_rcnfg;
1068         bool in_reconfig;
1069         bool c2d_enable_pending;
1070         OMX_NATIVE_WINDOWTYPE m_display_id;
1071         OMX_U32 m_client_extradata;
1072 #ifdef _ANDROID_
1073         bool perf_flag;
1074         OMX_U32 proc_frms, latency;
1075         perf_metrics fps_metrics;
1076         perf_metrics dec_time;
1077         bool m_enable_android_native_buffers;
1078         bool m_use_android_native_buffers;
1079         bool m_disable_dynamic_buf_mode;
1080 #endif
1081 
1082         struct meta_buffer {
1083             unsigned char* buffer;
1084             int size;
1085             int count;
1086             int pmem_fd;
1087             int pmem_fd_iommu;
1088             int offset;
1089         };
1090         meta_buffer meta_buff;
1091         OMX_PARAM_PORTDEFINITIONTYPE m_port_def;
1092         omx_time_stamp_reorder time_stamp_dts;
1093         desc_buffer_hdr *m_desc_buffer_ptr;
1094         bool secure_mode;
1095         bool allocate_native_handle;
1096         bool external_meta_buffer;
1097         bool external_meta_buffer_iommu;
1098         OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata;
1099         bool codec_config_flag;
1100         uint32_t capture_capability;
1101         int output_capability;
1102         bool streaming[MAX_PORT];
1103         OMX_FRAMESIZETYPE framesize;
1104         OMX_CONFIG_RECTTYPE rectangle;
1105         OMX_U32 prev_n_filled_len;
1106         struct custom_buffersize {
1107             OMX_U32 input_buffersize;
1108         } m_custom_buffersize;
1109         OMX_ERRORTYPE power_module_register();
1110         OMX_ERRORTYPE power_module_deregister();
1111         bool msg_thread_created;
1112         bool async_thread_created;
1113 
1114         OMX_VIDEO_PARAM_PROFILELEVELTYPE clientSet_profile_level;
1115         QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE m_sParamLowLatency;
1116 
1117         //variables to handle dynamic buffer mode
1118         bool dynamic_buf_mode;
1119         OMX_U32 m_reconfig_width;
1120         OMX_U32 m_reconfig_height;
1121         bool m_decode_order_mode;
1122 
1123         bool m_input_pass_buffer_fd;
1124         DescribeColorAspectsParams m_client_color_space;
1125         DescribeColorAspectsParams m_internal_color_space;
1126 
1127         // HDRStaticInfo defined in HardwareAPI.h
1128         DescribeHDRStaticInfoParams m_client_hdr_info;
1129         DescribeHDRStaticInfoParams m_internal_hdr_info;
1130 
1131         bool m_disable_ubwc_mode;
1132 
1133         unsigned int m_fill_output_msg;
1134         bool client_set_fps;
1135         unsigned int stereo_output_mode;
1136         class allocate_color_convert_buf
1137         {
1138             public:
1139                 allocate_color_convert_buf();
~allocate_color_convert_buf()1140                 ~allocate_color_convert_buf() {};
1141                 void set_vdec_client(void *);
1142                 void update_client();
1143                 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format);
1144                 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format);
1145                 bool update_buffer_req();
1146                 bool get_buffer_req(unsigned int &buffer_size);
1147                 OMX_ERRORTYPE set_buffer_req(OMX_U32 buffer_size, OMX_U32 actual_count);
1148                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr();
1149                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
1150                 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header);
1151                 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header);
1152                 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
1153                         OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,
1154                         OMX_U32 bytes);
1155                 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
is_color_conversion_enabled()1156                 bool is_color_conversion_enabled() {return enabled;}
1157                 void enable_color_conversion(bool enable);
is_client_buffers_disabled()1158                 bool is_client_buffers_disabled() {return client_buffers_disabled;}
set_client_buffers_disabled(bool val)1159                 void set_client_buffers_disabled(bool val) {client_buffers_disabled = val;}
1160                 // Returns a specific C2D state, if true current buffers should undergo C2D conversion
1161                 // otherwise C2D is in quasi enabled state where in C2D src and dst formats are set but
1162                 // color conversion doesnt take place. This state is needed to handle color conversion
1163                 // of interlaced clips during port reconfig.
client_buffers_invalid()1164                 bool client_buffers_invalid() {return (!enabled || client_buffers_disabled);}
1165             private:
1166 #define MAX_COUNT MAX_NUM_INPUT_OUTPUT_BUFFERS
1167                 omx_vdec *omx;
1168                 bool enabled;
1169                 bool client_buffers_disabled;
1170                 OMX_COLOR_FORMATTYPE ColorFormat;
1171                 void init_members();
1172                 bool color_convert_mode;
1173                 ColorConvertFormat dest_format;
1174                 ColorConvertFormat src_format;
1175                 C2DColorConverter c2dcc;
1176                 unsigned int allocated_count;
1177                 unsigned int buffer_size_req;
1178                 unsigned int buffer_alignment_req;
1179                 OMX_U32 m_c2d_width;
1180                 OMX_U32 m_c2d_height;
1181                 OMX_QCOM_PLATFORM_PRIVATE_LIST      m_platform_list_client[MAX_COUNT];
1182                 OMX_QCOM_PLATFORM_PRIVATE_ENTRY     m_platform_entry_client[MAX_COUNT];
1183                 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT];
1184                 OMX_BUFFERHEADERTYPE  m_out_mem_ptr_client[MAX_COUNT];
1185                 DecColorMapping mMapOutput2DriverColorFormat;
1186                 ColorSubMapping mMapOutput2Convert;
1187 #ifdef USE_ION
1188                 struct vdec_ion op_buf_ion_info[MAX_COUNT];
1189 #endif
1190 #ifdef USE_GBM
1191                 struct vdec_gbm op_buf_gbm_info[MAX_COUNT];
1192 #endif
1193 
1194                 unsigned char *pmem_baseaddress[MAX_COUNT];
1195                 int pmem_fd[MAX_COUNT];
1196         };
1197         allocate_color_convert_buf client_buffers;
1198         struct video_decoder_capability m_decoder_capability;
1199         struct debug_cap m_debug;
1200         int log_input_buffers(const char *, int, uint64_t, int);
1201         int log_output_buffers(OMX_BUFFERHEADERTYPE *);
1202         int log_cc_output_buffers(OMX_BUFFERHEADERTYPE *);
1203         void send_codec_config();
1204         OMX_TICKS m_prev_timestampUs;
1205         bool m_prev_frame_rendered;
1206         int32_t m_dec_hfr_fps;
1207         int32_t m_dec_secure_prefetch_size_internal;
1208         int32_t m_dec_secure_prefetch_size_output;
1209         int32_t m_arb_mode_override;
1210         int32_t m_disable_hdr;
1211         int32_t m_dec_output_rate;
1212         volatile int32_t m_queued_codec_config_count;
1213         OMX_U32 current_perf_level;
1214         int32_t m_thumbnail_yuv_output;
1215 
1216         class perf_control {
1217             typedef int (*perf_lock_acquire_t)(int, int, int*, int);
1218             typedef int (*perf_lock_release_t)(int);
1219 
1220             private:
1221                 void *m_perf_lib;
1222                 int m_perf_handle;
1223                 perf_lock_acquire_t m_perf_lock_acquire;
1224                 perf_lock_release_t m_perf_lock_release;
1225 
1226             public:
1227                 perf_control();
1228                 ~perf_control();
1229                 bool load_perf_library();
1230                 int perf_lock_acquire();
1231                 void perf_lock_release();
1232                 int m_perf_control_enable;
1233         };
1234         perf_control m_perf_control;
1235 
getPreferredColorFormatNonSurfaceMode(OMX_U32 index)1236         static OMX_COLOR_FORMATTYPE getPreferredColorFormatNonSurfaceMode(OMX_U32 index) {
1237             //On Android, we default to standard YUV formats for non-surface use-cases
1238             //where apps prefer known color formats.
1239             OMX_COLOR_FORMATTYPE formatsNonSurfaceMode[] = {
1240                 [0] = OMX_COLOR_FormatYUV420SemiPlanar,
1241                 [1] = OMX_COLOR_FormatYUV420Planar,
1242                 [2] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1243                 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1244                 [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed,
1245                 [5] = OMX_COLOR_Format16bitRGB565,
1246             };
1247             return (index < sizeof(formatsNonSurfaceMode) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1248                 formatsNonSurfaceMode[index] : OMX_COLOR_FormatMax;
1249         }
1250 
getPreferredColorFormatDefaultMode(OMX_U32 index)1251         OMX_COLOR_FORMATTYPE getPreferredColorFormatDefaultMode(OMX_U32 index) {
1252             //for surface mode (normal playback), advertise native/accelerated formats first
1253             OMX_COLOR_FORMATTYPE format = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
1254 
1255             if (!m_disable_ubwc_mode) {
1256                 OMX_COLOR_FORMATTYPE formatsDefault[] = {
1257                     [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed,
1258                     [1] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1259                     [2] = OMX_COLOR_FormatYUV420SemiPlanar,
1260                     [3] = OMX_COLOR_FormatYUV420Planar,
1261                     [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1262                     [5] = OMX_COLOR_Format16bitRGB565,
1263                 };
1264                 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1265                     formatsDefault[index] : OMX_COLOR_FormatMax;
1266             } else {
1267                 OMX_COLOR_FORMATTYPE formatsDefault[] = {
1268                     [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
1269                     [1] = OMX_COLOR_FormatYUV420SemiPlanar,
1270                     [2] = OMX_COLOR_FormatYUV420Planar,
1271                     [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
1272                 };
1273                 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ?
1274                     formatsDefault[index] : OMX_COLOR_FormatMax;
1275             }
1276             return format;
1277         }
1278 
1279         static OMX_ERRORTYPE describeColorFormat(OMX_PTR params);
1280         bool prefetch_buffers(unsigned long prefetch_count,
1281                     unsigned long prefetch_size, unsigned ioctl_code,
1282                     unsigned ion_flag);
1283         unsigned char m_prefetch_done;
1284         client_extradata_info m_client_out_extradata_info;
1285 
1286         OMX_ERRORTYPE get_vendor_extension_config(
1287                 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext);
1288         OMX_ERRORTYPE set_vendor_extension_config(
1289                 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext);
1290 
1291         void init_vendor_extensions (VendorExtensionStore&);
1292 
1293         // list of extensions is not mutable after initialization
1294         const VendorExtensionStore mVendorExtensionStore;
1295 
1296         // Map of ColorAspects (VideoAPI.h) to ColorMetaData (color_metadata.h)
1297         PrimariesMap mPrimariesMap;
1298         TransferMap mTransferMap;
1299         MatrixCoeffMap mMatrixCoeffMap;
1300         RangeMap mColorRangeMap;
1301 
1302         void init_color_aspects_map();
1303         void convert_color_aspects_to_metadata(ColorAspects& aspects, ColorMetaData &color_mdata);
1304         void convert_hdr_info_to_metadata(HDRStaticInfo& hdr_info, ColorMetaData &color_mdata);
1305         void get_preferred_color_aspects(ColorAspects& preferredColorAspects);
1306         void get_preferred_hdr_info(HDRStaticInfo& preferredHDRInfo);
1307         bool vdec_query_cap(struct v4l2_queryctrl &cap);
1308         bool store_vp9_hdr10plusinfo(DescribeHDR10PlusInfoParams *hdr10plusinfo);
1309         bool store_hevc_hdr10plusinfo(uint32_t payload_size,
1310             msm_vidc_stream_userdata_payload *hdr10plusdata);
1311         void update_hdr10plusinfo_cookie_using_timestamp(OMX_PTR cookie, OMX_TICKS timestamp);
1312         void convert_hdr10plusinfo_to_metadata(OMX_PTR cookie, ColorMetaData &colorData);
1313         void remove_hdr10plusinfo_using_cookie(OMX_PTR cookie);
1314         void clear_hdr10plusinfo();
1315         void get_hdr10plusinfo(DescribeHDR10PlusInfoParams *hdr10plusdata);
1316         void print_hdr10plusinfo(DescribeHDR10PlusInfoParams *hdr10plusdata);
1317 public:
1318         bool m_buffer_error;
get_clientSet_profile_level()1319         OMX_VIDEO_PARAM_PROFILELEVELTYPE get_clientSet_profile_level() {
1320             return clientSet_profile_level;
1321         }
1322 
1323 };
1324 
1325 enum instance_state {
1326     MSM_VIDC_CORE_UNINIT_DONE = 0x0001,
1327     MSM_VIDC_CORE_INIT,
1328     MSM_VIDC_CORE_INIT_DONE,
1329     MSM_VIDC_OPEN,
1330     MSM_VIDC_OPEN_DONE,
1331     MSM_VIDC_LOAD_RESOURCES,
1332     MSM_VIDC_LOAD_RESOURCES_DONE,
1333     MSM_VIDC_START,
1334     MSM_VIDC_START_DONE,
1335     MSM_VIDC_STOP,
1336     MSM_VIDC_STOP_DONE,
1337     MSM_VIDC_RELEASE_RESOURCES,
1338     MSM_VIDC_RELEASE_RESOURCES_DONE,
1339     MSM_VIDC_CLOSE,
1340     MSM_VIDC_CLOSE_DONE,
1341     MSM_VIDC_CORE_UNINIT,
1342 };
1343 
1344 enum vidc_resposes_id {
1345     MSM_VIDC_DECODER_FLUSH_DONE = 0x11,
1346     MSM_VIDC_DECODER_EVENT_CHANGE,
1347 };
1348 
1349 #endif // __OMX_VDEC_H__
1350