blob: 3b363bc5c594b489000c7262741b29e3d617636a [file] [log] [blame]
Shalaj Jain273b3e02012-06-22 19:08:03 -07001/*--------------------------------------------------------------------------
Maheshwar Ajja507d6552014-01-03 14:54:29 +05302Copyright (c) 2010 - 2014, The Linux Foundation. All rights reserved.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003
4Redistribution and use in source and binary forms, with or without
5modification, 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.
Vinay Kaliae4a7d9d2013-01-21 10:16:33 -080011 * Neither the name of The Linux Foundation nor
Shalaj Jain273b3e02012-06-22 19:08:03 -070012 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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27--------------------------------------------------------------------------*/
28
29/*============================================================================
30 O p e n M A X w r a p p e r s
31 O p e n M A X C o r e
32
33*//** @file omx_vdec.cpp
34 This module contains the implementation of the OpenMAX core & component.
35
36*//*========================================================================*/
37
38//////////////////////////////////////////////////////////////////////////////
39// Include Files
40//////////////////////////////////////////////////////////////////////////////
41
Deva Ramasubramanianeb819322014-07-17 14:23:35 -070042#define __STDC_FORMAT_MACROS
43#include <inttypes.h>
44
Shalaj Jain273b3e02012-06-22 19:08:03 -070045#include <string.h>
46#include <pthread.h>
47#include <sys/prctl.h>
48#include <stdlib.h>
49#include <unistd.h>
50#include <errno.h>
51#include "omx_vdec.h"
52#include <fcntl.h>
53#include <limits.h>
Deva Ramasubramanian15bbc1c2013-05-13 16:05:03 -070054#include <stdlib.h>
Arun Menonbdb80b02013-08-12 17:45:54 -070055#include <media/hardware/HardwareAPI.h>
Vinay Kaliada8f3cf2012-12-21 18:26:21 -080056#include <media/msm_media_info.h>
Shalaj Jain273b3e02012-06-22 19:08:03 -070057
58#ifndef _ANDROID_
59#include <sys/ioctl.h>
60#include <sys/mman.h>
61#endif //_ANDROID_
62
63#ifdef _ANDROID_
64#include <cutils/properties.h>
65#undef USE_EGL_IMAGE_GPU
66#endif
67
Vinay Kalia0e75e9a2012-09-27 15:41:53 -070068#include <qdMetaData.h>
Shalaj Jain273b3e02012-06-22 19:08:03 -070069
70#ifdef _ANDROID_
71#include "DivXDrmDecrypt.h"
72#endif //_ANDROID_
73
Arun Menon45346052013-11-13 12:40:08 -080074#ifdef METADATA_FOR_DYNAMIC_MODE
Arun Menon9af783f2013-10-22 12:57:14 -070075#include "QComOMXMetadata.h"
76#endif
77
Shalaj Jain273b3e02012-06-22 19:08:03 -070078#ifdef USE_EGL_IMAGE_GPU
79#include <EGL/egl.h>
80#include <EGL/eglQCOM.h>
81#define EGL_BUFFER_HANDLE_QCOM 0x4F00
82#define EGL_BUFFER_OFFSET_QCOM 0x4F01
83#endif
Vinay Kalia21649b32013-03-18 17:28:07 -070084
Jayasena Sangaraboina51230642013-08-21 18:02:13 -070085#define BUFFER_LOG_LOC "/data/misc/media"
86
Shalaj Jain273b3e02012-06-22 19:08:03 -070087#ifdef OUTPUT_EXTRADATA_LOG
88FILE *outputExtradataFile;
Deva Ramasubramanianee6f1f42014-01-31 12:49:18 -080089char output_extradata_filename [] = "/data/misc/extradata";
Shalaj Jain273b3e02012-06-22 19:08:03 -070090#endif
91
92#define DEFAULT_FPS 30
Shalaj Jain273b3e02012-06-22 19:08:03 -070093#define MAX_SUPPORTED_FPS 120
Deepak Vermaa2efdb12013-12-26 12:30:05 +053094#define DEFAULT_WIDTH_ALIGNMENT 128
95#define DEFAULT_HEIGHT_ALIGNMENT 32
Shalaj Jain273b3e02012-06-22 19:08:03 -070096
97#define VC1_SP_MP_START_CODE 0xC5000000
98#define VC1_SP_MP_START_CODE_MASK 0xFF000000
99#define VC1_AP_SEQ_START_CODE 0x0F010000
100#define VC1_STRUCT_C_PROFILE_MASK 0xF0
101#define VC1_STRUCT_B_LEVEL_MASK 0xE0000000
102#define VC1_SIMPLE_PROFILE 0
103#define VC1_MAIN_PROFILE 1
104#define VC1_ADVANCE_PROFILE 3
105#define VC1_SIMPLE_PROFILE_LOW_LEVEL 0
106#define VC1_SIMPLE_PROFILE_MED_LEVEL 2
107#define VC1_STRUCT_C_LEN 4
108#define VC1_STRUCT_C_POS 8
109#define VC1_STRUCT_A_POS 12
110#define VC1_STRUCT_B_POS 24
111#define VC1_SEQ_LAYER_SIZE 36
Vinay Kaliab09886c2012-08-20 11:27:25 -0700112#define POLL_TIMEOUT 0x7fffffff
Shalaj Jain273b3e02012-06-22 19:08:03 -0700113
114#define MEM_DEVICE "/dev/ion"
115#define MEM_HEAP_ID ION_CP_MM_HEAP_ID
116
117#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700118extern "C" {
119#include<utils/Log.h>
120}
Shalaj Jain273b3e02012-06-22 19:08:03 -0700121#endif//_ANDROID_
122
Vinay Kalia53fa6832012-10-11 17:55:30 -0700123#define SZ_4K 0x1000
124#define SZ_1M 0x100000
125
Shalaj Jain273b3e02012-06-22 19:08:03 -0700126#define Log2(number, power) { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) && power < 16) { temp >>=0x1; power++; } }
127#define Q16ToFraction(q,num,den) { OMX_U32 power; Log2(q,power); num = q >> power; den = 0x1 << (16 - power); }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -0700128#define EXTRADATA_IDX(__num_planes) (__num_planes - 1)
Maheshwar Ajja77cd19c2014-06-05 11:23:18 +0530129#define ALIGN(x, to_align) ((((unsigned) x) + (to_align - 1)) & ~(to_align - 1))
Vinay Kalia0e75e9a2012-09-27 15:41:53 -0700130
Vinay Kaliadb90f8c2012-11-19 18:57:56 -0800131#define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA)
Jia Meng3a3c6492013-12-19 17:16:52 +0800132#define DEFAULT_CONCEAL_COLOR "32896" //0x8080, black by default
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700133
134int debug_level = PRIO_ERROR;
135
Deepak Vermaa2efdb12013-12-26 12:30:05 +0530136static OMX_U32 maxSmoothStreamingWidth = 1920;
137static OMX_U32 maxSmoothStreamingHeight = 1088;
Praveen Chavancf924182013-12-06 23:16:23 -0800138
Shalaj Jain273b3e02012-06-22 19:08:03 -0700139void* async_message_thread (void *input)
140{
Arun Menon906de572013-06-18 17:01:40 -0700141 OMX_BUFFERHEADERTYPE *buffer;
142 struct v4l2_plane plane[VIDEO_MAX_PLANES];
143 struct pollfd pfd;
144 struct v4l2_buffer v4l2_buf;
145 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
146 struct v4l2_event dqevent;
147 omx_vdec *omx = reinterpret_cast<omx_vdec*>(input);
148 pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI;
149 pfd.fd = omx->drv_ctx.video_driver_fd;
150 int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700151 DEBUG_PRINT_HIGH("omx_vdec: Async thread start");
Arun Menon906de572013-06-18 17:01:40 -0700152 prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0);
153 while (1) {
154 rc = poll(&pfd, 1, POLL_TIMEOUT);
155 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700156 DEBUG_PRINT_ERROR("Poll timedout");
Arun Menon906de572013-06-18 17:01:40 -0700157 break;
Deepak Kushwah4193f602015-11-17 15:45:22 +0530158 } else if (rc < 0 && errno != EINTR && errno != EAGAIN) {
159 DEBUG_PRINT_ERROR("Error while polling: %d, errno = %d", rc, errno);
Arun Menon906de572013-06-18 17:01:40 -0700160 break;
161 }
162 if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) {
163 struct vdec_msginfo vdec_msg;
164 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
165 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
166 v4l2_buf.length = omx->drv_ctx.num_planes;
167 v4l2_buf.m.planes = plane;
168 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
169 vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
170 vdec_msg.status_code=VDEC_S_SUCCESS;
171 vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf;
172 vdec_msg.msgdata.output_frame.len=plane[0].bytesused;
173 vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr;
174 vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) +
175 (uint64_t)v4l2_buf.timestamp.tv_usec;
176 if (vdec_msg.msgdata.output_frame.len) {
177 vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2];
178 vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3];
179 vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4];
180 vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5];
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +0530181 vdec_msg.msgdata.output_frame.picsize.frame_width = plane[0].reserved[6];
182 vdec_msg.msgdata.output_frame.picsize.frame_height = plane[0].reserved[7];
Arun Menon906de572013-06-18 17:01:40 -0700183 }
184 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700185 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700186 break;
187 }
188 }
189 }
190 if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) {
191 struct vdec_msginfo vdec_msg;
192 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
193 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
194 v4l2_buf.length = 1;
195 v4l2_buf.m.planes = plane;
196 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
197 vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE;
198 vdec_msg.status_code=VDEC_S_SUCCESS;
199 vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf;
200 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700201 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700202 break;
203 }
204 }
205 }
206 if (pfd.revents & POLLPRI) {
207 rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent);
208 if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) {
209 struct vdec_msginfo vdec_msg;
210 vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED;
211 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700212 DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient");
Arun Menon906de572013-06-18 17:01:40 -0700213 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700214 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700215 break;
216 }
217 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) {
218 struct vdec_msginfo vdec_msg;
219 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE;
220 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700221 DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700222 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700223 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700224 break;
225 }
226 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE;
227 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700228 DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700229 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700230 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700231 break;
232 }
233 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700234 DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700235 break;
Deepak Verma24720fb2014-01-29 16:57:40 +0530236 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_HW_OVERLOAD) {
237 struct vdec_msginfo vdec_msg;
238 vdec_msg.msgcode=VDEC_MSG_EVT_HW_OVERLOAD;
239 vdec_msg.status_code=VDEC_S_SUCCESS;
240 DEBUG_PRINT_ERROR("HW Overload received");
241 if (omx->async_message_process(input,&vdec_msg) < 0) {
242 DEBUG_PRINT_HIGH("async_message_thread Exited");
243 break;
244 }
Arun Menon906de572013-06-18 17:01:40 -0700245 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) {
246 struct vdec_msginfo vdec_msg;
Jia Meng1e236c82014-04-03 10:54:39 +0800247 vdec_msg.msgcode = VDEC_MSG_EVT_HW_ERROR;
248 vdec_msg.status_code = VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700249 DEBUG_PRINT_HIGH("SYS Error Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700250 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700251 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700252 break;
253 }
Arun Menon45346052013-11-13 12:40:08 -0800254 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) {
Arun Menonbdb80b02013-08-12 17:45:54 -0700255 unsigned int *ptr = (unsigned int *)dqevent.u.data;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700256 DEBUG_PRINT_LOW("REFERENCE RELEASE EVENT RECVD fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700257 omx->buf_ref_remove(ptr[0], ptr[1]);
258 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) {
259 unsigned int *ptr = (unsigned int *)dqevent.u.data;
260 struct vdec_msginfo vdec_msg;
261
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700262 DEBUG_PRINT_LOW("Release unqueued buffer event recvd fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700263
264 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
265 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
266 v4l2_buf.length = omx->drv_ctx.num_planes;
267 v4l2_buf.m.planes = plane;
268 v4l2_buf.index = ptr[5];
269 v4l2_buf.flags = 0;
270
271 vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
272 vdec_msg.status_code = VDEC_S_SUCCESS;
273 vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf;
274 vdec_msg.msgdata.output_frame.len = 0;
275 vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2];
276 vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) +
277 (uint64_t)ptr[4];
278 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700279 DEBUG_PRINT_HIGH("async_message_thread Exitedn");
Arun Menonbdb80b02013-08-12 17:45:54 -0700280 break;
281 }
282 }
Arun Menonbdb80b02013-08-12 17:45:54 -0700283 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700284 DEBUG_PRINT_HIGH("VIDC Some Event recieved");
Arun Menon906de572013-06-18 17:01:40 -0700285 continue;
286 }
287 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -0700288 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700289 DEBUG_PRINT_HIGH("omx_vdec: Async thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700290 return NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700291}
292
Ashray Kulkarnia97efbc2015-07-15 18:17:23 -0700293void* dec_message_thread(void *input)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700294{
Arun Menon906de572013-06-18 17:01:40 -0700295 omx_vdec* omx = reinterpret_cast<omx_vdec*>(input);
296 unsigned char id;
297 int n;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700298
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700299 DEBUG_PRINT_HIGH("omx_vdec: message thread start");
Arun Menon906de572013-06-18 17:01:40 -0700300 prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0);
301 while (1) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700302
Arun Menon906de572013-06-18 17:01:40 -0700303 n = read(omx->m_pipe_in, &id, 1);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700304
Arun Menon906de572013-06-18 17:01:40 -0700305 if (0 == n) {
306 break;
307 }
308
309 if (1 == n) {
310 omx->process_event_cb(omx, id);
311 }
312 if ((n < 0) && (errno != EINTR)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700313 DEBUG_PRINT_LOW("ERROR: read from pipe failed, ret %d errno %d", n, errno);
Arun Menon906de572013-06-18 17:01:40 -0700314 break;
315 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700316 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700317 DEBUG_PRINT_HIGH("omx_vdec: message thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700318 return 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700319}
320
321void post_message(omx_vdec *omx, unsigned char id)
322{
Arun Menon906de572013-06-18 17:01:40 -0700323 int ret_value;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700324 DEBUG_PRINT_LOW("omx_vdec: post_message %d pipe out%d", id,omx->m_pipe_out);
Arun Menon906de572013-06-18 17:01:40 -0700325 ret_value = write(omx->m_pipe_out, &id, 1);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700326 DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700327}
328
329// omx_cmd_queue destructor
330omx_vdec::omx_cmd_queue::~omx_cmd_queue()
331{
Arun Menon906de572013-06-18 17:01:40 -0700332 // Nothing to do
Shalaj Jain273b3e02012-06-22 19:08:03 -0700333}
334
335// omx cmd queue constructor
336omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0)
337{
338 memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE);
339}
340
341// omx cmd queue insert
342bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id)
343{
Arun Menon906de572013-06-18 17:01:40 -0700344 bool ret = true;
345 if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) {
346 m_q[m_write].id = id;
347 m_q[m_write].param1 = p1;
348 m_q[m_write].param2 = p2;
349 m_write++;
350 m_size ++;
351 if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) {
352 m_write = 0;
353 }
354 } else {
355 ret = false;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700356 DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700357 }
Arun Menon906de572013-06-18 17:01:40 -0700358 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700359}
360
361// omx cmd queue pop
362bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id)
363{
Arun Menon906de572013-06-18 17:01:40 -0700364 bool ret = true;
365 if (m_size > 0) {
366 *id = m_q[m_read].id;
367 *p1 = m_q[m_read].param1;
368 *p2 = m_q[m_read].param2;
369 // Move the read pointer ahead
370 ++m_read;
371 --m_size;
372 if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) {
373 m_read = 0;
374 }
375 } else {
376 ret = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700377 }
Arun Menon906de572013-06-18 17:01:40 -0700378 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700379}
380
381// Retrieve the first mesg type in the queue
382unsigned omx_vdec::omx_cmd_queue::get_q_msg_type()
383{
384 return m_q[m_read].id;
385}
386
387#ifdef _ANDROID_
388omx_vdec::ts_arr_list::ts_arr_list()
389{
Arun Menon906de572013-06-18 17:01:40 -0700390 //initialize timestamps array
391 memset(m_ts_arr_list, 0, ( sizeof(ts_entry) * MAX_NUM_INPUT_OUTPUT_BUFFERS) );
Shalaj Jain273b3e02012-06-22 19:08:03 -0700392}
393omx_vdec::ts_arr_list::~ts_arr_list()
394{
Arun Menon906de572013-06-18 17:01:40 -0700395 //free m_ts_arr_list?
Shalaj Jain273b3e02012-06-22 19:08:03 -0700396}
397
398bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts)
399{
Arun Menon906de572013-06-18 17:01:40 -0700400 bool ret = true;
401 bool duplicate_ts = false;
402 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700403
Arun Menon906de572013-06-18 17:01:40 -0700404 //insert at the first available empty location
405 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
406 if (!m_ts_arr_list[idx].valid) {
407 //found invalid or empty entry, save timestamp
408 m_ts_arr_list[idx].valid = true;
409 m_ts_arr_list[idx].timestamp = ts;
410 DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)",
411 ts, idx);
412 break;
413 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700414 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700415
Arun Menon906de572013-06-18 17:01:40 -0700416 if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) {
417 DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert");
418 ret = false;
419 }
420 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700421}
422
423bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts)
424{
Arun Menon906de572013-06-18 17:01:40 -0700425 bool ret = true;
426 int min_idx = -1;
427 OMX_TICKS min_ts = 0;
428 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700429
Arun Menon906de572013-06-18 17:01:40 -0700430 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700431
Arun Menon906de572013-06-18 17:01:40 -0700432 if (m_ts_arr_list[idx].valid) {
433 //found valid entry, save index
434 if (min_idx < 0) {
435 //first valid entry
436 min_ts = m_ts_arr_list[idx].timestamp;
437 min_idx = idx;
438 } else if (m_ts_arr_list[idx].timestamp < min_ts) {
439 min_ts = m_ts_arr_list[idx].timestamp;
440 min_idx = idx;
441 }
442 }
443
Shalaj Jain273b3e02012-06-22 19:08:03 -0700444 }
445
Arun Menon906de572013-06-18 17:01:40 -0700446 if (min_idx < 0) {
447 //no valid entries found
448 DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop");
449 ts = 0;
450 ret = false;
451 } else {
452 ts = m_ts_arr_list[min_idx].timestamp;
453 m_ts_arr_list[min_idx].valid = false;
454 DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)",
455 ts, min_idx);
456 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700457
Arun Menon906de572013-06-18 17:01:40 -0700458 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700459
460}
461
462
463bool omx_vdec::ts_arr_list::reset_ts_list()
464{
Arun Menon906de572013-06-18 17:01:40 -0700465 bool ret = true;
466 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700467
Arun Menon906de572013-06-18 17:01:40 -0700468 DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list");
469 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
470 m_ts_arr_list[idx].valid = false;
471 }
472 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700473}
474#endif
475
476// factory function executed by the core to create instances
477void *get_omx_component_factory_fn(void)
478{
Arun Menon906de572013-06-18 17:01:40 -0700479 return (new omx_vdec);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700480}
481
482#ifdef _ANDROID_
483#ifdef USE_ION
484VideoHeap::VideoHeap(int devicefd, size_t size, void* base,
Mitchel Humpherys2294c232013-12-10 12:14:04 -0800485 ion_user_handle_t handle, int ionMapfd)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700486{
Arun Menon906de572013-06-18 17:01:40 -0700487 // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700488}
489#else
490VideoHeap::VideoHeap(int fd, size_t size, void* base)
491{
492 // dup file descriptor, map once, use pmem
493 init(dup(fd), base, size, 0 , MEM_DEVICE);
494}
495#endif
496#endif // _ANDROID_
497/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700498 FUNCTION
499 omx_vdec::omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700500
Arun Menon906de572013-06-18 17:01:40 -0700501 DESCRIPTION
502 Constructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700503
Arun Menon906de572013-06-18 17:01:40 -0700504 PARAMETERS
505 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700506
Arun Menon906de572013-06-18 17:01:40 -0700507 RETURN VALUE
508 None.
509 ========================================================================== */
Deva Ramasubramanian5c241242013-02-19 17:25:30 -0800510omx_vdec::omx_vdec(): m_error_propogated(false),
Arun Menon906de572013-06-18 17:01:40 -0700511 m_state(OMX_StateInvalid),
512 m_app_data(NULL),
513 m_inp_mem_ptr(NULL),
514 m_out_mem_ptr(NULL),
Arun Menon906de572013-06-18 17:01:40 -0700515 input_flush_progress (false),
516 output_flush_progress (false),
517 input_use_buffer (false),
518 output_use_buffer (false),
519 ouput_egl_buffers(false),
520 m_use_output_pmem(OMX_FALSE),
521 m_out_mem_region_smi(OMX_FALSE),
522 m_out_pvt_entry_pmem(OMX_FALSE),
523 pending_input_buffers(0),
524 pending_output_buffers(0),
525 m_out_bm_count(0),
526 m_inp_bm_count(0),
527 m_inp_bPopulated(OMX_FALSE),
528 m_out_bPopulated(OMX_FALSE),
529 m_flags(0),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700530#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700531 m_heap_ptr(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700532#endif
Arun Menon906de572013-06-18 17:01:40 -0700533 m_inp_bEnabled(OMX_TRUE),
534 m_out_bEnabled(OMX_TRUE),
535 m_in_alloc_cnt(0),
536 m_platform_list(NULL),
537 m_platform_entry(NULL),
538 m_pmem_info(NULL),
539 arbitrary_bytes (true),
540 psource_frame (NULL),
541 pdest_frame (NULL),
542 m_inp_heap_ptr (NULL),
543 m_phdr_pmem_ptr(NULL),
544 m_heap_inp_bm_count (0),
545 codec_type_parse ((codec_type)0),
546 first_frame_meta (true),
547 frame_count (0),
548 nal_count (0),
549 nal_length(0),
550 look_ahead_nal (false),
551 first_frame(0),
552 first_buffer(NULL),
553 first_frame_size (0),
554 m_device_file_ptr(NULL),
555 m_vc1_profile((vc1_profile_type)0),
Arun Menon906de572013-06-18 17:01:40 -0700556 h264_last_au_ts(LLONG_MAX),
557 h264_last_au_flags(0),
Surajit Podderd2644d52013-08-28 17:59:06 +0530558 m_disp_hor_size(0),
559 m_disp_vert_size(0),
Arun Menon906de572013-06-18 17:01:40 -0700560 prev_ts(LLONG_MAX),
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -0700561 prev_ts_actual(LLONG_MAX),
Arun Menon906de572013-06-18 17:01:40 -0700562 rst_prev_ts(true),
563 frm_int(0),
Arun Menon906de572013-06-18 17:01:40 -0700564 in_reconfig(false),
565 m_display_id(NULL),
566 h264_parser(NULL),
567 client_extradata(0),
568 m_reject_avc_1080p_mp (0),
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +0530569 m_other_extradata(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700570#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700571 m_enable_android_native_buffers(OMX_FALSE),
572 m_use_android_native_buffers(OMX_FALSE),
573 iDivXDrmDecrypt(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700574#endif
Arun Menon906de572013-06-18 17:01:40 -0700575 m_desc_buffer_ptr(NULL),
576 secure_mode(false),
Surajit Podderd2644d52013-08-28 17:59:06 +0530577 m_profile(0),
vivek mehtaa75c69f2014-01-10 21:50:37 -0800578 client_set_fps(false),
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -0700579 m_last_rendered_TS(-1),
580 m_queued_codec_config_count(0)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700581{
Arun Menon906de572013-06-18 17:01:40 -0700582 /* Assumption is that , to begin with , we have all the frames with decoder */
583 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700584 memset(&m_debug,0,sizeof(m_debug));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700585#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700586 char property_value[PROPERTY_VALUE_MAX] = {0};
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700587 property_get("vidc.debug.level", property_value, "0");
588 debug_level = atoi(property_value);
589 property_value[0] = '\0';
590
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700591 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
592
Arun Menon906de572013-06-18 17:01:40 -0700593 property_get("vidc.dec.debug.perf", property_value, "0");
594 perf_flag = atoi(property_value);
595 if (perf_flag) {
596 DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag);
597 dec_time.start();
598 proc_frms = latency = 0;
599 }
600 prev_n_filled_len = 0;
601 property_value[0] = '\0';
602 property_get("vidc.dec.debug.ts", property_value, "0");
603 m_debug_timestamp = atoi(property_value);
604 DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp);
605 if (m_debug_timestamp) {
606 time_stamp_dts.set_timestamp_reorder_mode(true);
607 time_stamp_dts.enable_debug_print(true);
608 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700609
Arun Menon906de572013-06-18 17:01:40 -0700610 property_value[0] = '\0';
611 property_get("vidc.dec.debug.concealedmb", property_value, "0");
612 m_debug_concealedmb = atoi(property_value);
613 DEBUG_PRINT_HIGH("vidc.dec.debug.concealedmb value is %d",m_debug_concealedmb);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700614
Arun Menon906de572013-06-18 17:01:40 -0700615 property_value[0] = '\0';
616 property_get("vidc.dec.profile.check", property_value, "0");
617 m_reject_avc_1080p_mp = atoi(property_value);
618 DEBUG_PRINT_HIGH("vidc.dec.profile.check value is %d",m_reject_avc_1080p_mp);
Rajeshwar Kurapatye0e7d0c2013-07-30 19:46:26 +0530619
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700620 property_value[0] = '\0';
621 property_get("vidc.dec.log.in", property_value, "0");
622 m_debug.in_buffer_log = atoi(property_value);
623
624 property_value[0] = '\0';
625 property_get("vidc.dec.log.out", property_value, "0");
626 m_debug.out_buffer_log = atoi(property_value);
627 sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC);
628
629 property_value[0] = '\0';
630 property_get("vidc.log.loc", property_value, "");
631 if (*property_value)
632 strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX);
vivek mehta79cff222014-01-22 12:17:07 -0800633
634 property_value[0] = '\0';
635 property_get("vidc.dec.120fps.enabled", property_value, "0");
636
637 //if this feature is not enabled then reset this value -ve
638 if(atoi(property_value)) {
639 DEBUG_PRINT_LOW("feature 120 FPS decode enabled");
640 m_last_rendered_TS = 0;
641 }
642
Shalaj Jain273b3e02012-06-22 19:08:03 -0700643#endif
Arun Menon906de572013-06-18 17:01:40 -0700644 memset(&m_cmp,0,sizeof(m_cmp));
645 memset(&m_cb,0,sizeof(m_cb));
646 memset (&drv_ctx,0,sizeof(drv_ctx));
647 memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE));
648 memset (m_hwdevice_name,0,sizeof(m_hwdevice_name));
649 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +0530650 memset(&m_custom_buffersize, 0, sizeof(m_custom_buffersize));
Arun Menon906de572013-06-18 17:01:40 -0700651 m_demux_entries = 0;
652 msg_thread_id = 0;
653 async_thread_id = 0;
654 msg_thread_created = false;
655 async_thread_created = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700656#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -0700657 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700658#endif
Arun Menon906de572013-06-18 17:01:40 -0700659 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Maheshwar Ajjad2df2182013-10-24 19:20:34 +0530660 memset(&m_frame_pack_arrangement, 0, sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
Arun Menon906de572013-06-18 17:01:40 -0700661 drv_ctx.timestamp_adjust = false;
662 drv_ctx.video_driver_fd = -1;
663 m_vendor_config.pData = NULL;
664 pthread_mutex_init(&m_lock, NULL);
665 pthread_mutex_init(&c_lock, NULL);
666 sem_init(&m_cmd_lock,0,0);
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -0700667 sem_init(&m_safe_flush, 0, 0);
Arun Menon906de572013-06-18 17:01:40 -0700668 streaming[CAPTURE_PORT] =
669 streaming[OUTPUT_PORT] = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700670#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700671 char extradata_value[PROPERTY_VALUE_MAX] = {0};
672 property_get("vidc.dec.debug.extradata", extradata_value, "0");
673 m_debug_extradata = atoi(extradata_value);
674 DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700675#endif
Arun Menon906de572013-06-18 17:01:40 -0700676 m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB;
677 client_buffers.set_vdec_client(this);
Arun Menonbdb80b02013-08-12 17:45:54 -0700678 dynamic_buf_mode = false;
679 out_dynamic_list = NULL;
Praveen Chavane78460c2013-12-06 23:16:04 -0800680 is_down_scalar_enabled = false;
Praveen Chavancf924182013-12-06 23:16:23 -0800681 m_smoothstreaming_mode = false;
682 m_smoothstreaming_width = 0;
683 m_smoothstreaming_height = 0;
Deepak Vermaa2efdb12013-12-26 12:30:05 +0530684 is_q6_platform = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700685}
686
Vinay Kalia85793762012-06-14 19:12:34 -0700687static const int event_type[] = {
Arun Menon906de572013-06-18 17:01:40 -0700688 V4L2_EVENT_MSM_VIDC_FLUSH_DONE,
689 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT,
690 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT,
Arun Menonbdb80b02013-08-12 17:45:54 -0700691 V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE,
692 V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER,
Arun Menon906de572013-06-18 17:01:40 -0700693 V4L2_EVENT_MSM_VIDC_CLOSE_DONE,
Jia Meng1e236c82014-04-03 10:54:39 +0800694 V4L2_EVENT_MSM_VIDC_SYS_ERROR,
695 V4L2_EVENT_MSM_VIDC_HW_OVERLOAD
Vinay Kalia85793762012-06-14 19:12:34 -0700696};
697
698static OMX_ERRORTYPE subscribe_to_events(int fd)
699{
Arun Menon906de572013-06-18 17:01:40 -0700700 OMX_ERRORTYPE eRet = OMX_ErrorNone;
701 struct v4l2_event_subscription sub;
702 int array_sz = sizeof(event_type)/sizeof(int);
703 int i,rc;
704 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700705 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700706 return OMX_ErrorBadParameter;
707 }
Vinay Kalia85793762012-06-14 19:12:34 -0700708
Arun Menon906de572013-06-18 17:01:40 -0700709 for (i = 0; i < array_sz; ++i) {
710 memset(&sub, 0, sizeof(sub));
711 sub.type = event_type[i];
712 rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
713 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700714 DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700715 break;
716 }
717 }
718 if (i < array_sz) {
719 for (--i; i >=0 ; i--) {
720 memset(&sub, 0, sizeof(sub));
721 sub.type = event_type[i];
722 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
723 if (rc)
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700724 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700725 }
726 eRet = OMX_ErrorNotImplemented;
727 }
728 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700729}
730
731
732static OMX_ERRORTYPE unsubscribe_to_events(int fd)
733{
Arun Menon906de572013-06-18 17:01:40 -0700734 OMX_ERRORTYPE eRet = OMX_ErrorNone;
735 struct v4l2_event_subscription sub;
736 int array_sz = sizeof(event_type)/sizeof(int);
737 int i,rc;
738 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700739 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700740 return OMX_ErrorBadParameter;
741 }
Vinay Kalia85793762012-06-14 19:12:34 -0700742
Arun Menon906de572013-06-18 17:01:40 -0700743 for (i = 0; i < array_sz; ++i) {
744 memset(&sub, 0, sizeof(sub));
745 sub.type = event_type[i];
746 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
747 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700748 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700749 break;
750 }
751 }
752 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700753}
Shalaj Jain273b3e02012-06-22 19:08:03 -0700754
755/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700756 FUNCTION
757 omx_vdec::~omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700758
Arun Menon906de572013-06-18 17:01:40 -0700759 DESCRIPTION
760 Destructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700761
Arun Menon906de572013-06-18 17:01:40 -0700762 PARAMETERS
763 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700764
Arun Menon906de572013-06-18 17:01:40 -0700765 RETURN VALUE
766 None.
767 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700768omx_vdec::~omx_vdec()
769{
Arun Menon906de572013-06-18 17:01:40 -0700770 m_pmem_info = NULL;
771 struct v4l2_decoder_cmd dec;
772 DEBUG_PRINT_HIGH("In OMX vdec Destructor");
773 if (m_pipe_in) close(m_pipe_in);
774 if (m_pipe_out) close(m_pipe_out);
775 m_pipe_in = -1;
776 m_pipe_out = -1;
777 DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit");
778 if (msg_thread_created)
779 pthread_join(msg_thread_id,NULL);
780 DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit");
781 dec.cmd = V4L2_DEC_CMD_STOP;
782 if (drv_ctx.video_driver_fd >=0 ) {
783 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700784 DEBUG_PRINT_ERROR("STOP Command failed");
Arun Menon906de572013-06-18 17:01:40 -0700785 }
786 if (async_thread_created)
787 pthread_join(async_thread_id,NULL);
788 unsubscribe_to_events(drv_ctx.video_driver_fd);
789 close(drv_ctx.video_driver_fd);
790 pthread_mutex_destroy(&m_lock);
791 pthread_mutex_destroy(&c_lock);
792 sem_destroy(&m_cmd_lock);
793 if (perf_flag) {
794 DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME");
795 dec_time.end();
796 }
797 DEBUG_PRINT_HIGH("Exit OMX vdec Destructor");
Shalaj Jain273b3e02012-06-22 19:08:03 -0700798}
799
Arun Menon906de572013-06-18 17:01:40 -0700800int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type)
801{
802 struct v4l2_requestbuffers bufreq;
803 int rc = 0;
804 if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
805 bufreq.memory = V4L2_MEMORY_USERPTR;
806 bufreq.count = 0;
807 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
808 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Surajit Podder12aefac2013-08-06 18:43:32 +0530809 } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) {
810 bufreq.memory = V4L2_MEMORY_USERPTR;
811 bufreq.count = 0;
812 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
813 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Arun Menon906de572013-06-18 17:01:40 -0700814 }
815 return rc;
Vinay Kaliafeef7032012-09-25 19:23:33 -0700816}
817
Shalaj Jain273b3e02012-06-22 19:08:03 -0700818/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700819 FUNCTION
820 omx_vdec::OMXCntrlProcessMsgCb
Shalaj Jain273b3e02012-06-22 19:08:03 -0700821
Arun Menon906de572013-06-18 17:01:40 -0700822 DESCRIPTION
823 IL Client callbacks are generated through this routine. The decoder
824 provides the thread context for this routine.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700825
Arun Menon906de572013-06-18 17:01:40 -0700826 PARAMETERS
827 ctxt -- Context information related to the self.
828 id -- Event identifier. This could be any of the following:
829 1. Command completion event
830 2. Buffer done callback event
831 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -0700832
Arun Menon906de572013-06-18 17:01:40 -0700833 RETURN VALUE
834 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700835
Arun Menon906de572013-06-18 17:01:40 -0700836 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700837void omx_vdec::process_event_cb(void *ctxt, unsigned char id)
838{
Arun Menon906de572013-06-18 17:01:40 -0700839 signed p1; // Parameter - 1
840 signed p2; // Parameter - 2
841 unsigned ident;
842 unsigned qsize=0; // qsize
843 omx_vdec *pThis = (omx_vdec *) ctxt;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700844
Arun Menon906de572013-06-18 17:01:40 -0700845 if (!pThis) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700846 DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out",
Arun Menon906de572013-06-18 17:01:40 -0700847 __func__);
848 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700849 }
850
Arun Menon906de572013-06-18 17:01:40 -0700851 // Protect the shared queue data structure
852 do {
853 /*Read the message id's from the queue*/
854 pthread_mutex_lock(&pThis->m_lock);
855 qsize = pThis->m_cmd_q.m_size;
856 if (qsize) {
857 pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700858 }
Arun Menon906de572013-06-18 17:01:40 -0700859
860 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
861 qsize = pThis->m_ftb_q.m_size;
862 if (qsize) {
863 pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
864 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700865 }
Arun Menon906de572013-06-18 17:01:40 -0700866
867 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
868 qsize = pThis->m_etb_q.m_size;
869 if (qsize) {
870 pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
871 }
872 }
873 pthread_mutex_unlock(&pThis->m_lock);
874
875 /*process message if we have one*/
876 if (qsize > 0) {
877 id = ident;
878 switch (id) {
879 case OMX_COMPONENT_GENERATE_EVENT:
880 if (pThis->m_cb.EventHandler) {
881 switch (p1) {
882 case OMX_CommandStateSet:
883 pThis->m_state = (OMX_STATETYPE) p2;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700884 DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d",
Arun Menon906de572013-06-18 17:01:40 -0700885 pThis->m_state);
886 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
887 OMX_EventCmdComplete, p1, p2, NULL);
888 break;
889
890 case OMX_EventError:
891 if (p2 == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700892 DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid");
Arun Menon906de572013-06-18 17:01:40 -0700893 pThis->m_state = (OMX_STATETYPE) p2;
894 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
895 OMX_EventError, OMX_ErrorInvalidState, p2, NULL);
896 } else if (p2 == OMX_ErrorHardware) {
897 pThis->omx_report_error();
898 } else {
899 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
900 OMX_EventError, p2, (OMX_U32)NULL, NULL );
901 }
902 break;
903
904 case OMX_CommandPortDisable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700905 DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700906 if (BITMASK_PRESENT(&pThis->m_flags,
907 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
908 BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
909 break;
910 }
911 if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) {
912 OMX_ERRORTYPE eRet = OMX_ErrorNone;
913 pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
914 if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700915 DEBUG_PRINT_HIGH("Failed to release output buffers");
Arun Menon906de572013-06-18 17:01:40 -0700916 OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf);
917 pThis->in_reconfig = false;
918 if (eRet != OMX_ErrorNone) {
919 DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet);
920 pThis->omx_report_error();
921 break;
922 }
923 }
924 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
925 OMX_EventCmdComplete, p1, p2, NULL );
926 break;
927 case OMX_CommandPortEnable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700928 DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700929 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\
930 OMX_EventCmdComplete, p1, p2, NULL );
931 break;
932
933 default:
934 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
935 OMX_EventCmdComplete, p1, p2, NULL );
936 break;
937
938 }
939 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700940 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
Arun Menon906de572013-06-18 17:01:40 -0700941 }
942 break;
943 case OMX_COMPONENT_GENERATE_ETB_ARBITRARY:
944 if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\
945 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700946 DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure");
Arun Menon906de572013-06-18 17:01:40 -0700947 pThis->omx_report_error ();
948 }
949 break;
Jia Meng1e236c82014-04-03 10:54:39 +0800950 case OMX_COMPONENT_GENERATE_ETB: {
951 OMX_ERRORTYPE iret;
952 iret = pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1, (OMX_BUFFERHEADERTYPE *)p2);
953 if (iret == OMX_ErrorInsufficientResources) {
954 DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure due to HW overload");
955 pThis->omx_report_hw_overload ();
956 } else if (iret != OMX_ErrorNone) {
957 DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure");
958 pThis->omx_report_error ();
959 }
Arun Menon906de572013-06-18 17:01:40 -0700960 }
961 break;
962
963 case OMX_COMPONENT_GENERATE_FTB:
964 if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\
965 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700966 DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure");
Arun Menon906de572013-06-18 17:01:40 -0700967 pThis->omx_report_error ();
968 }
969 break;
970
971 case OMX_COMPONENT_GENERATE_COMMAND:
972 pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\
973 (OMX_U32)p2,(OMX_PTR)NULL);
974 break;
975
976 case OMX_COMPONENT_GENERATE_EBD:
977
978 if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700979 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure");
Arun Menon906de572013-06-18 17:01:40 -0700980 pThis->omx_report_error ();
981 } else {
982 if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) {
Arun Menon906de572013-06-18 17:01:40 -0700983 pThis->time_stamp_dts.remove_time_stamp(
984 ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp,
985 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
986 ?true:false);
Arun Menon906de572013-06-18 17:01:40 -0700987 }
Deva Ramasubramanian02b0d882014-04-03 14:58:50 -0700988
Arun Menon906de572013-06-18 17:01:40 -0700989 if ( pThis->empty_buffer_done(&pThis->m_cmp,
990 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700991 DEBUG_PRINT_ERROR("empty_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -0700992 pThis->omx_report_error ();
993 }
Arun Menon906de572013-06-18 17:01:40 -0700994 }
995 break;
996 case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: {
997 int64_t *timestamp = (int64_t *)p1;
998 if (p1) {
999 pThis->time_stamp_dts.remove_time_stamp(*timestamp,
1000 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
1001 ?true:false);
1002 free(timestamp);
1003 }
1004 }
1005 break;
1006 case OMX_COMPONENT_GENERATE_FBD:
1007 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001008 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure");
Arun Menon906de572013-06-18 17:01:40 -07001009 pThis->omx_report_error ();
1010 } else if ( pThis->fill_buffer_done(&pThis->m_cmp,
1011 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001012 DEBUG_PRINT_ERROR("fill_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -07001013 pThis->omx_report_error ();
1014 }
1015 break;
1016
1017 case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001018 DEBUG_PRINT_HIGH("Driver flush i/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -07001019 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001020 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -07001021 } else {
1022 pThis->execute_input_flush();
1023 if (pThis->m_cb.EventHandler) {
1024 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001025 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure");
Arun Menon906de572013-06-18 17:01:40 -07001026 pThis->omx_report_error ();
1027 } else {
1028 /*Check if we need generate event for Flush done*/
1029 if (BITMASK_PRESENT(&pThis->m_flags,
1030 OMX_COMPONENT_INPUT_FLUSH_PENDING)) {
1031 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001032 DEBUG_PRINT_LOW("Input Flush completed - Notify Client");
Arun Menon906de572013-06-18 17:01:40 -07001033 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1034 OMX_EventCmdComplete,OMX_CommandFlush,
1035 OMX_CORE_INPUT_PORT_INDEX,NULL );
1036 }
1037 if (BITMASK_PRESENT(&pThis->m_flags,
1038 OMX_COMPONENT_IDLE_PENDING)) {
1039 if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001040 DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port");
Arun Menon906de572013-06-18 17:01:40 -07001041 pThis->omx_report_error ();
1042 } else {
1043 pThis->streaming[OUTPUT_PORT] = false;
1044 }
1045 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001046 DEBUG_PRINT_LOW("Input flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001047 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1048 OMX_COMPONENT_GENERATE_STOP_DONE);
1049 }
1050 }
1051 }
1052 } else {
1053 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1054 }
1055 }
1056 break;
1057
1058 case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001059 DEBUG_PRINT_HIGH("Driver flush o/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -07001060 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001061 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -07001062 } else {
1063 pThis->execute_output_flush();
1064 if (pThis->m_cb.EventHandler) {
1065 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001066 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed");
Arun Menon906de572013-06-18 17:01:40 -07001067 pThis->omx_report_error ();
1068 } else {
1069 /*Check if we need generate event for Flush done*/
1070 if (BITMASK_PRESENT(&pThis->m_flags,
1071 OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001072 DEBUG_PRINT_LOW("Notify Output Flush done");
Arun Menon906de572013-06-18 17:01:40 -07001073 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
1074 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1075 OMX_EventCmdComplete,OMX_CommandFlush,
1076 OMX_CORE_OUTPUT_PORT_INDEX,NULL );
1077 }
1078 if (BITMASK_PRESENT(&pThis->m_flags,
1079 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001080 DEBUG_PRINT_LOW("Internal flush complete");
Arun Menon906de572013-06-18 17:01:40 -07001081 BITMASK_CLEAR (&pThis->m_flags,
1082 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
1083 if (BITMASK_PRESENT(&pThis->m_flags,
1084 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) {
1085 pThis->post_event(OMX_CommandPortDisable,
1086 OMX_CORE_OUTPUT_PORT_INDEX,
1087 OMX_COMPONENT_GENERATE_EVENT);
1088 BITMASK_CLEAR (&pThis->m_flags,
1089 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
Praneeth Paladugub52072a2013-08-23 13:54:43 -07001090 BITMASK_CLEAR (&pThis->m_flags,
1091 OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
Arun Menon906de572013-06-18 17:01:40 -07001092
1093 }
1094 }
1095
1096 if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) {
1097 if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001098 DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port");
Arun Menon906de572013-06-18 17:01:40 -07001099 pThis->omx_report_error ();
1100 break;
1101 }
1102 pThis->streaming[CAPTURE_PORT] = false;
1103 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001104 DEBUG_PRINT_LOW("Output flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001105 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1106 OMX_COMPONENT_GENERATE_STOP_DONE);
1107 }
1108 }
1109 }
1110 } else {
1111 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1112 }
1113 }
1114 break;
1115
1116 case OMX_COMPONENT_GENERATE_START_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001117 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001118
1119 if (pThis->m_cb.EventHandler) {
1120 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001121 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure");
Arun Menon906de572013-06-18 17:01:40 -07001122 pThis->omx_report_error ();
1123 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001124 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001125 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001126 DEBUG_PRINT_LOW("Move to executing");
Arun Menon906de572013-06-18 17:01:40 -07001127 // Send the callback now
1128 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1129 pThis->m_state = OMX_StateExecuting;
1130 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1131 OMX_EventCmdComplete,OMX_CommandStateSet,
1132 OMX_StateExecuting, NULL);
1133 } else if (BITMASK_PRESENT(&pThis->m_flags,
1134 OMX_COMPONENT_PAUSE_PENDING)) {
1135 if (/*ioctl (pThis->drv_ctx.video_driver_fd,
1136 VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001137 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed");
Arun Menon906de572013-06-18 17:01:40 -07001138 pThis->omx_report_error ();
1139 }
1140 }
1141 }
1142 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001143 DEBUG_PRINT_LOW("Event Handler callback is NULL");
Arun Menon906de572013-06-18 17:01:40 -07001144 }
1145 break;
1146
1147 case OMX_COMPONENT_GENERATE_PAUSE_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001148 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001149 if (pThis->m_cb.EventHandler) {
1150 if (p2 != VDEC_S_SUCCESS) {
1151 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed");
1152 pThis->omx_report_error ();
1153 } else {
1154 pThis->complete_pending_buffer_done_cbs();
1155 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001156 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity");
Arun Menon906de572013-06-18 17:01:40 -07001157 //Send the callback now
1158 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING);
1159 pThis->m_state = OMX_StatePause;
1160 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1161 OMX_EventCmdComplete,OMX_CommandStateSet,
1162 OMX_StatePause, NULL);
1163 }
1164 }
1165 } else {
1166 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1167 }
1168
1169 break;
1170
1171 case OMX_COMPONENT_GENERATE_RESUME_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001172 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001173 if (pThis->m_cb.EventHandler) {
1174 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001175 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed");
Arun Menon906de572013-06-18 17:01:40 -07001176 pThis->omx_report_error ();
1177 } else {
1178 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001179 DEBUG_PRINT_LOW("Moving the decoder to execute state");
Arun Menon906de572013-06-18 17:01:40 -07001180 // Send the callback now
1181 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1182 pThis->m_state = OMX_StateExecuting;
1183 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1184 OMX_EventCmdComplete,OMX_CommandStateSet,
1185 OMX_StateExecuting,NULL);
1186 }
1187 }
1188 } else {
1189 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1190 }
1191
1192 break;
1193
1194 case OMX_COMPONENT_GENERATE_STOP_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001195 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001196 if (pThis->m_cb.EventHandler) {
1197 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001198 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed");
Arun Menon906de572013-06-18 17:01:40 -07001199 pThis->omx_report_error ();
1200 } else {
1201 pThis->complete_pending_buffer_done_cbs();
1202 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001203 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001204 // Send the callback now
1205 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING);
1206 pThis->m_state = OMX_StateIdle;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001207 DEBUG_PRINT_LOW("Move to Idle State");
Arun Menon906de572013-06-18 17:01:40 -07001208 pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data,
1209 OMX_EventCmdComplete,OMX_CommandStateSet,
1210 OMX_StateIdle,NULL);
1211 }
1212 }
1213 } else {
1214 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1215 }
1216
1217 break;
1218
1219 case OMX_COMPONENT_GENERATE_PORT_RECONFIG:
Arun Menon906de572013-06-18 17:01:40 -07001220 if (p2 == OMX_IndexParamPortDefinition) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301221 DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexParamPortDefinition");
Arun Menon906de572013-06-18 17:01:40 -07001222 pThis->in_reconfig = true;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301223
1224 } else if (p2 == OMX_IndexConfigCommonOutputCrop) {
1225 DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexConfigCommonOutputCrop");
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301226
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301227 /* Check if resolution is changed in smooth streaming mode */
1228 if (pThis->m_smoothstreaming_mode &&
1229 (pThis->framesize.nWidth !=
1230 pThis->drv_ctx.video_resolution.frame_width) ||
1231 (pThis->framesize.nHeight !=
1232 pThis->drv_ctx.video_resolution.frame_height)) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301233
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301234 DEBUG_PRINT_HIGH("Resolution changed from: wxh = %dx%d to: wxh = %dx%d",
1235 pThis->framesize.nWidth,
1236 pThis->framesize.nHeight,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301237 pThis->drv_ctx.video_resolution.frame_width,
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301238 pThis->drv_ctx.video_resolution.frame_height);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301239
1240 /* Update new resolution */
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301241 pThis->framesize.nWidth =
1242 pThis->drv_ctx.video_resolution.frame_width;
1243 pThis->framesize.nHeight =
1244 pThis->drv_ctx.video_resolution.frame_height;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301245
1246 /* Update C2D with new resolution */
1247 if (!pThis->client_buffers.update_buffer_req()) {
1248 DEBUG_PRINT_ERROR("Setting C2D buffer requirements failed");
1249 }
1250 }
1251
1252 /* Update new crop information */
1253 pThis->rectangle.nLeft = pThis->drv_ctx.frame_size.left;
1254 pThis->rectangle.nTop = pThis->drv_ctx.frame_size.top;
1255 pThis->rectangle.nWidth = pThis->drv_ctx.frame_size.right;
1256 pThis->rectangle.nHeight = pThis->drv_ctx.frame_size.bottom;
1257
1258 /* Validate the new crop information */
1259 if (pThis->rectangle.nLeft + pThis->rectangle.nWidth >
1260 pThis->drv_ctx.video_resolution.frame_width) {
1261
1262 DEBUG_PRINT_HIGH("Crop L[%u] + R[%u] > W[%u]",
1263 pThis->rectangle.nLeft, pThis->rectangle.nWidth,
1264 pThis->drv_ctx.video_resolution.frame_width);
1265 pThis->rectangle.nLeft = 0;
1266
1267 if (pThis->rectangle.nWidth >
1268 pThis->drv_ctx.video_resolution.frame_width) {
1269
1270 DEBUG_PRINT_HIGH("Crop R[%u] > W[%u]",
1271 pThis->rectangle.nWidth,
1272 pThis->drv_ctx.video_resolution.frame_width);
1273 pThis->rectangle.nWidth =
1274 pThis->drv_ctx.video_resolution.frame_width;
1275 }
1276 }
1277 if (pThis->rectangle.nTop + pThis->rectangle.nHeight >
1278 pThis->drv_ctx.video_resolution.frame_height) {
1279
1280 DEBUG_PRINT_HIGH("Crop T[%u] + B[%u] > H[%u]",
1281 pThis->rectangle.nTop, pThis->rectangle.nHeight,
1282 pThis->drv_ctx.video_resolution.frame_height);
1283 pThis->rectangle.nTop = 0;
1284
1285 if (pThis->rectangle.nHeight >
1286 pThis->drv_ctx.video_resolution.frame_height) {
1287
1288 DEBUG_PRINT_HIGH("Crop B[%u] > H[%u]",
1289 pThis->rectangle.nHeight,
1290 pThis->drv_ctx.video_resolution.frame_height);
1291 pThis->rectangle.nHeight =
1292 pThis->drv_ctx.video_resolution.frame_height;
1293 }
1294 }
1295 DEBUG_PRINT_HIGH("Updated Crop Info: L: %u, T: %u, R: %u, B: %u",
1296 pThis->rectangle.nLeft, pThis->rectangle.nTop,
1297 pThis->rectangle.nWidth, pThis->rectangle.nHeight);
1298 } else {
1299 DEBUG_PRINT_ERROR("Rxd Invalid PORT_RECONFIG event (%lu)", p2);
1300 break;
Arun Menon906de572013-06-18 17:01:40 -07001301 }
1302 if (pThis->m_cb.EventHandler) {
1303 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1304 OMX_EventPortSettingsChanged, p1, p2, NULL );
1305 } else {
1306 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1307 }
Arun Menon906de572013-06-18 17:01:40 -07001308 break;
1309
1310 case OMX_COMPONENT_GENERATE_EOS_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001311 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001312 if (pThis->m_cb.EventHandler) {
1313 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag,
1314 OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL );
1315 } else {
1316 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1317 }
1318 pThis->prev_ts = LLONG_MAX;
1319 pThis->rst_prev_ts = true;
1320 break;
1321
1322 case OMX_COMPONENT_GENERATE_HARDWARE_ERROR:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001323 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR");
Arun Menon906de572013-06-18 17:01:40 -07001324 pThis->omx_report_error ();
1325 break;
1326
1327 case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001328 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING");
Arun Menon906de572013-06-18 17:01:40 -07001329 pThis->omx_report_unsupported_setting();
1330 break;
1331
Deepak Verma24720fb2014-01-29 16:57:40 +05301332 case OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD:
1333 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD");
1334 pThis->omx_report_hw_overload();
1335 break;
1336
Arun Menon906de572013-06-18 17:01:40 -07001337 default:
1338 break;
1339 }
1340 }
1341 pthread_mutex_lock(&pThis->m_lock);
1342 qsize = pThis->m_cmd_q.m_size;
1343 if (pThis->m_state != OMX_StatePause)
1344 qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size);
1345 pthread_mutex_unlock(&pThis->m_lock);
1346 } while (qsize>0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001347
1348}
1349
Vinay Kaliab9e98102013-04-02 19:31:43 -07001350int omx_vdec::update_resolution(int width, int height, int stride, int scan_lines)
Vinay Kalia592e4b42012-12-19 15:55:47 -08001351{
Arun Menon906de572013-06-18 17:01:40 -07001352 int format_changed = 0;
Surajit Podderd2644d52013-08-28 17:59:06 +05301353 if ((height != (int)drv_ctx.video_resolution.frame_height) ||
1354 (width != (int)drv_ctx.video_resolution.frame_width)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001355 DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)",
Arun Menon906de572013-06-18 17:01:40 -07001356 width, drv_ctx.video_resolution.frame_width,
1357 height,drv_ctx.video_resolution.frame_height);
1358 format_changed = 1;
1359 }
Vinay Kalia592e4b42012-12-19 15:55:47 -08001360 drv_ctx.video_resolution.frame_height = height;
1361 drv_ctx.video_resolution.frame_width = width;
Vinay Kalia21649b32013-03-18 17:28:07 -07001362 drv_ctx.video_resolution.scan_lines = scan_lines;
1363 drv_ctx.video_resolution.stride = stride;
Pushkaraj Patil41588352014-02-25 20:51:34 +05301364 if(!is_down_scalar_enabled) {
1365 rectangle.nLeft = 0;
1366 rectangle.nTop = 0;
1367 rectangle.nWidth = drv_ctx.video_resolution.frame_width;
1368 rectangle.nHeight = drv_ctx.video_resolution.frame_height;
1369 }
Arun Menon906de572013-06-18 17:01:40 -07001370 return format_changed;
Vinay Kalia592e4b42012-12-19 15:55:47 -08001371}
1372
Arun Menon6836ba02013-02-19 20:37:40 -08001373OMX_ERRORTYPE omx_vdec::is_video_session_supported()
1374{
Arun Menon906de572013-06-18 17:01:40 -07001375 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",
1376 OMX_MAX_STRINGNAME_SIZE) &&
1377 (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) {
1378 m_decoder_capability.max_width = 1280;
1379 m_decoder_capability.max_height = 720;
1380 DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP");
1381 }
Arun Menon888aa852013-05-30 11:24:42 -07001382
Arun Menon906de572013-06-18 17:01:40 -07001383 if ((drv_ctx.video_resolution.frame_width *
1384 drv_ctx.video_resolution.frame_height >
1385 m_decoder_capability.max_width *
1386 m_decoder_capability.max_height) ||
1387 (drv_ctx.video_resolution.frame_width*
1388 drv_ctx.video_resolution.frame_height <
1389 m_decoder_capability.min_width *
1390 m_decoder_capability.min_height)) {
1391 DEBUG_PRINT_ERROR(
1392 "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)",
1393 drv_ctx.video_resolution.frame_width,
1394 drv_ctx.video_resolution.frame_height,
1395 m_decoder_capability.min_width,
1396 m_decoder_capability.min_height,
1397 m_decoder_capability.max_width,
1398 m_decoder_capability.max_height);
1399 return OMX_ErrorUnsupportedSetting;
1400 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001401 DEBUG_PRINT_HIGH("video session supported");
Arun Menon906de572013-06-18 17:01:40 -07001402 return OMX_ErrorNone;
Arun Menon6836ba02013-02-19 20:37:40 -08001403}
1404
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001405int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len)
1406{
1407 if (m_debug.in_buffer_log && !m_debug.infile) {
1408 if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) {
1409 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v",
1410 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1411 }
1412 else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) {
1413 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.mpg", m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); }
1414 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) {
1415 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263",
1416 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1417 }
1418 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) {
1419 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264",
1420 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1421 }
1422 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) {
1423 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1424 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1425 }
1426 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) {
1427 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1428 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1429 }
1430 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1431 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf",
1432 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1433 }
1434 m_debug.infile = fopen (m_debug.infile_name, "ab");
1435 if (!m_debug.infile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001436 DEBUG_PRINT_HIGH("Failed to open input file: %s for logging", m_debug.infile_name);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001437 m_debug.infile_name[0] = '\0';
1438 return -1;
1439 }
1440 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1441 struct ivf_file_header {
1442 OMX_U8 signature[4]; //='DKIF';
1443 OMX_U8 version ; //= 0;
1444 OMX_U8 headersize ; //= 32;
1445 OMX_U32 FourCC;
1446 OMX_U8 width;
1447 OMX_U8 height;
1448 OMX_U32 rate;
1449 OMX_U32 scale;
1450 OMX_U32 length;
1451 OMX_U8 unused[4];
1452 } file_header;
1453
1454 memset((void *)&file_header,0,sizeof(file_header));
1455 file_header.signature[0] = 'D';
1456 file_header.signature[1] = 'K';
1457 file_header.signature[2] = 'I';
1458 file_header.signature[3] = 'F';
1459 file_header.version = 0;
1460 file_header.headersize = 32;
1461 file_header.FourCC = 0x30385056;
1462 fwrite((const char *)&file_header,
1463 sizeof(file_header),1,m_debug.infile);
1464 }
1465 }
1466 if (m_debug.infile && buffer_addr && buffer_len) {
1467 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1468 struct vp8_ivf_frame_header {
1469 OMX_U32 framesize;
1470 OMX_U32 timestamp_lo;
1471 OMX_U32 timestamp_hi;
1472 } vp8_frame_header;
1473 vp8_frame_header.framesize = buffer_len;
1474 /* Currently FW doesn't use timestamp values */
1475 vp8_frame_header.timestamp_lo = 0;
1476 vp8_frame_header.timestamp_hi = 0;
1477 fwrite((const char *)&vp8_frame_header,
1478 sizeof(vp8_frame_header),1,m_debug.infile);
1479 }
1480 fwrite(buffer_addr, buffer_len, 1, m_debug.infile);
1481 }
1482 return 0;
1483}
1484
1485int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) {
1486 if (m_debug.out_buffer_log && !m_debug.outfile) {
1487 sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv",
1488 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1489 m_debug.outfile = fopen (m_debug.outfile_name, "ab");
1490 if (!m_debug.outfile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001491 DEBUG_PRINT_HIGH("Failed to open output file: %s for logging", m_debug.log_loc);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001492 m_debug.outfile_name[0] = '\0';
1493 return -1;
1494 }
1495 }
1496 if (m_debug.outfile && buffer && buffer->nFilledLen) {
1497 int buf_index = buffer - m_out_mem_ptr;
1498 int stride = drv_ctx.video_resolution.stride;
1499 int scanlines = drv_ctx.video_resolution.scan_lines;
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301500 if (m_smoothstreaming_mode) {
1501 stride = drv_ctx.video_resolution.frame_width;
1502 scanlines = drv_ctx.video_resolution.frame_height;
1503 stride = (stride + DEFAULT_WIDTH_ALIGNMENT - 1) & (~(DEFAULT_WIDTH_ALIGNMENT - 1));
1504 scanlines = (scanlines + DEFAULT_HEIGHT_ALIGNMENT - 1) & (~(DEFAULT_HEIGHT_ALIGNMENT - 1));
1505 }
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001506 char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr;
1507 unsigned i;
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301508 DEBUG_PRINT_HIGH("Logging width/height(%u/%u) stride/scanlines(%u/%u)",
1509 drv_ctx.video_resolution.frame_width,
1510 drv_ctx.video_resolution.frame_height, stride, scanlines);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001511 int bytes_written = 0;
1512 for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) {
1513 bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1514 temp += stride;
1515 }
1516 temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines;
1517 int stride_c = stride;
1518 for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) {
1519 bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1520 temp += stride_c;
1521 }
1522 }
1523 return 0;
1524}
1525
Shalaj Jain273b3e02012-06-22 19:08:03 -07001526/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001527 FUNCTION
1528 omx_vdec::ComponentInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07001529
Arun Menon906de572013-06-18 17:01:40 -07001530 DESCRIPTION
1531 Initialize the component.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001532
Arun Menon906de572013-06-18 17:01:40 -07001533 PARAMETERS
1534 ctxt -- Context information related to the self.
1535 id -- Event identifier. This could be any of the following:
1536 1. Command completion event
1537 2. Buffer done callback event
1538 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -07001539
Arun Menon906de572013-06-18 17:01:40 -07001540 RETURN VALUE
1541 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001542
Arun Menon906de572013-06-18 17:01:40 -07001543 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001544OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role)
1545{
1546
Arun Menon906de572013-06-18 17:01:40 -07001547 OMX_ERRORTYPE eRet = OMX_ErrorNone;
1548 struct v4l2_fmtdesc fdesc;
1549 struct v4l2_format fmt;
1550 struct v4l2_requestbuffers bufreq;
1551 struct v4l2_control control;
1552 struct v4l2_frmsizeenum frmsize;
1553 unsigned int alignment = 0,buffer_size = 0;
1554 int fds[2];
1555 int r,ret=0;
1556 bool codec_ambiguous = false;
Praveen Chavan00ec0ce2015-05-18 09:44:20 -07001557 OMX_STRING device_name = (OMX_STRING)"/dev/video32";
Jia Meng3a3c6492013-12-19 17:16:52 +08001558 char property_value[PROPERTY_VALUE_MAX] = {0};
Sachin Shahc82a18f2013-03-29 14:45:38 -07001559
1560#ifdef _ANDROID_
Praveen Chavane9e56202013-09-19 03:48:16 -07001561 char platform_name[PROPERTY_VALUE_MAX];
Arun Menon906de572013-06-18 17:01:40 -07001562 property_get("ro.board.platform", platform_name, "0");
1563 if (!strncmp(platform_name, "msm8610", 7)) {
Balamurugan Alagarsamy1693e592015-07-23 19:19:05 +05301564 device_name = (OMX_STRING)"/dev/video34";
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301565 is_q6_platform = true;
1566 maxSmoothStreamingWidth = 1280;
1567 maxSmoothStreamingHeight = 720;
Arun Menon906de572013-06-18 17:01:40 -07001568 }
Sachin Shahc82a18f2013-03-29 14:45:38 -07001569#endif
1570
Arun Menon906de572013-06-18 17:01:40 -07001571 if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) {
1572 struct v4l2_control control;
1573 secure_mode = true;
1574 arbitrary_bytes = false;
1575 role = (OMX_STRING)"OMX.qcom.video.decoder.avc";
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05301576 } else if (!strncmp(role, "OMX.qcom.video.decoder.mpeg2.secure",
1577 OMX_MAX_STRINGNAME_SIZE)){
1578 secure_mode = true;
1579 arbitrary_bytes = false;
1580 role = (OMX_STRING)"OMX.qcom.video.decoder.mpeg2";
Arun Menon906de572013-06-18 17:01:40 -07001581 }
Vinay Kalia53fa6832012-10-11 17:55:30 -07001582
Arun Menon906de572013-06-18 17:01:40 -07001583 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001584
Balamurugan Alagarsamy1693e592015-07-23 19:19:05 +05301585 DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open device %s returned fd %d",
1586 device_name, drv_ctx.video_driver_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001587
Arun Menon906de572013-06-18 17:01:40 -07001588 if (drv_ctx.video_driver_fd == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001589 DEBUG_PRINT_ERROR("omx_vdec_msm8974 :: Got fd as 0 for msm_vidc_dec, Opening again");
Arun Menon906de572013-06-18 17:01:40 -07001590 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
1591 close(0);
1592 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001593
Arun Menon906de572013-06-18 17:01:40 -07001594 if (drv_ctx.video_driver_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001595 DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno);
Arun Menon906de572013-06-18 17:01:40 -07001596 return OMX_ErrorInsufficientResources;
1597 }
1598 drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS;
1599 drv_ctx.frame_rate.fps_denominator = 1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001600
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001601 ret = subscribe_to_events(drv_ctx.video_driver_fd);
Vinay Kalia184cd0f2013-04-29 18:26:42 -07001602 if (!ret) {
Arun Menon906de572013-06-18 17:01:40 -07001603 async_thread_created = true;
1604 ret = pthread_create(&async_thread_id,0,async_message_thread,this);
1605 }
1606 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001607 DEBUG_PRINT_ERROR("Failed to create async_message_thread");
Arun Menon906de572013-06-18 17:01:40 -07001608 async_thread_created = false;
1609 return OMX_ErrorInsufficientResources;
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001610 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001611
Shalaj Jain273b3e02012-06-22 19:08:03 -07001612#ifdef OUTPUT_EXTRADATA_LOG
Deva Ramasubramanianee6f1f42014-01-31 12:49:18 -08001613 outputExtradataFile = fopen (output_extradata_filename, "ab");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001614#endif
1615
Arun Menon906de572013-06-18 17:01:40 -07001616 // Copy the role information which provides the decoder kind
1617 strlcpy(drv_ctx.kind,role,128);
Vinay Kalia53fa6832012-10-11 17:55:30 -07001618
Arun Menon906de572013-06-18 17:01:40 -07001619 if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\
1620 OMX_MAX_STRINGNAME_SIZE)) {
1621 strlcpy((char *)m_cRole, "video_decoder.mpeg4",\
1622 OMX_MAX_STRINGNAME_SIZE);
1623 drv_ctx.timestamp_adjust = true;
1624 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4;
1625 eCompressionFormat = OMX_VIDEO_CodingMPEG4;
1626 output_capability=V4L2_PIX_FMT_MPEG4;
1627 /*Initialize Start Code for MPEG4*/
1628 codec_type_parse = CODEC_TYPE_MPEG4;
1629 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001630 } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\
1631 OMX_MAX_STRINGNAME_SIZE)) {
1632 strlcpy((char *)m_cRole, "video_decoder.mpeg2",\
1633 OMX_MAX_STRINGNAME_SIZE);
1634 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2;
1635 output_capability = V4L2_PIX_FMT_MPEG2;
1636 eCompressionFormat = OMX_VIDEO_CodingMPEG2;
1637 /*Initialize Start Code for MPEG2*/
1638 codec_type_parse = CODEC_TYPE_MPEG2;
1639 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001640 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\
1641 OMX_MAX_STRINGNAME_SIZE)) {
1642 strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001643 DEBUG_PRINT_LOW("H263 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001644 drv_ctx.decoder_format = VDEC_CODECTYPE_H263;
1645 eCompressionFormat = OMX_VIDEO_CodingH263;
1646 output_capability = V4L2_PIX_FMT_H263;
1647 codec_type_parse = CODEC_TYPE_H263;
1648 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001649 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\
1650 OMX_MAX_STRINGNAME_SIZE)) {
1651 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001652 DEBUG_PRINT_LOW ("DIVX 311 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001653 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3;
1654 output_capability = V4L2_PIX_FMT_DIVX_311;
1655 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1656 codec_type_parse = CODEC_TYPE_DIVX;
1657 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001658
Arun Menon906de572013-06-18 17:01:40 -07001659 eRet = createDivxDrmContext();
1660 if (eRet != OMX_ErrorNone) {
1661 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1662 return eRet;
1663 }
1664 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\
1665 OMX_MAX_STRINGNAME_SIZE)) {
1666 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001667 DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001668 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4;
1669 output_capability = V4L2_PIX_FMT_DIVX;
1670 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1671 codec_type_parse = CODEC_TYPE_DIVX;
1672 codec_ambiguous = true;
1673 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001674
Arun Menon906de572013-06-18 17:01:40 -07001675 eRet = createDivxDrmContext();
1676 if (eRet != OMX_ErrorNone) {
1677 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1678 return eRet;
1679 }
1680 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\
1681 OMX_MAX_STRINGNAME_SIZE)) {
1682 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001683 DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001684 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6;
1685 output_capability = V4L2_PIX_FMT_DIVX;
1686 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1687 codec_type_parse = CODEC_TYPE_DIVX;
1688 codec_ambiguous = true;
1689 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001690
Arun Menon906de572013-06-18 17:01:40 -07001691 eRet = createDivxDrmContext();
1692 if (eRet != OMX_ErrorNone) {
1693 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1694 return eRet;
1695 }
Deva Ramasubramanian9403f022012-11-28 18:27:53 -08001696
Arun Menon906de572013-06-18 17:01:40 -07001697 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\
1698 OMX_MAX_STRINGNAME_SIZE)) {
1699 strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
1700 drv_ctx.decoder_format = VDEC_CODECTYPE_H264;
1701 output_capability=V4L2_PIX_FMT_H264;
1702 eCompressionFormat = OMX_VIDEO_CodingAVC;
1703 codec_type_parse = CODEC_TYPE_H264;
1704 m_frame_parser.init_start_codes (codec_type_parse);
1705 m_frame_parser.init_nal_length(nal_length);
Arun Menon906de572013-06-18 17:01:40 -07001706 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\
1707 OMX_MAX_STRINGNAME_SIZE)) {
1708 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1709 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1;
1710 eCompressionFormat = OMX_VIDEO_CodingWMV;
1711 codec_type_parse = CODEC_TYPE_VC1;
1712 output_capability = V4L2_PIX_FMT_VC1_ANNEX_G;
1713 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001714 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\
1715 OMX_MAX_STRINGNAME_SIZE)) {
1716 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1717 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV;
1718 eCompressionFormat = OMX_VIDEO_CodingWMV;
1719 codec_type_parse = CODEC_TYPE_VC1;
1720 output_capability = V4L2_PIX_FMT_VC1_ANNEX_L;
1721 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001722 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \
1723 OMX_MAX_STRINGNAME_SIZE)) {
1724 strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
1725 output_capability=V4L2_PIX_FMT_VP8;
Praveen Chavan76b71c32014-07-10 18:10:51 -07001726 eCompressionFormat = OMX_VIDEO_CodingVP8;
Arun Menon906de572013-06-18 17:01:40 -07001727 codec_type_parse = CODEC_TYPE_VP8;
1728 arbitrary_bytes = false;
Praneeth Paladugu2b2ef2d2013-04-10 22:04:51 -07001729
Arun Menon906de572013-06-18 17:01:40 -07001730 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001731 DEBUG_PRINT_ERROR("ERROR:Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07001732 eRet = OMX_ErrorInvalidComponentName;
1733 }
Arun Menon906de572013-06-18 17:01:40 -07001734 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001735
Arun Menon906de572013-06-18 17:01:40 -07001736 drv_ctx.output_format = VDEC_YUV_FORMAT_NV12;
Vinay Kaliada4f4422013-01-09 10:45:03 -08001737 OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE)
1738 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
1739 if (!client_buffers.set_color_format(dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001740 DEBUG_PRINT_ERROR("Setting color format failed");
Vinay Kaliada4f4422013-01-09 10:45:03 -08001741 eRet = OMX_ErrorInsufficientResources;
1742 }
1743
Arun Menon906de572013-06-18 17:01:40 -07001744 capture_capability= V4L2_PIX_FMT_NV12;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001745
Arun Menon906de572013-06-18 17:01:40 -07001746 struct v4l2_capability cap;
1747 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap);
1748 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001749 DEBUG_PRINT_ERROR("Failed to query capabilities");
Arun Menon906de572013-06-18 17:01:40 -07001750 /*TODO: How to handle this case */
1751 } else {
1752 DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s,"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001753 " version = %d, capabilities = %x", cap.driver, cap.card,
Arun Menon906de572013-06-18 17:01:40 -07001754 cap.bus_info, cap.version, cap.capabilities);
1755 }
1756 ret=0;
1757 fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1758 fdesc.index=0;
1759 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001760 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001761 fdesc.pixelformat, fdesc.flags);
1762 fdesc.index++;
1763 }
1764 fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1765 fdesc.index=0;
1766 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001767
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001768 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001769 fdesc.pixelformat, fdesc.flags);
1770 fdesc.index++;
1771 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001772 update_resolution(320, 240, 320, 240);
Arun Menon906de572013-06-18 17:01:40 -07001773 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1774 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1775 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1776 fmt.fmt.pix_mp.pixelformat = output_capability;
1777 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1778 if (ret) {
1779 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001780 DEBUG_PRINT_ERROR("Failed to set format on output port");
Arun Menon906de572013-06-18 17:01:40 -07001781 return OMX_ErrorInsufficientResources;
1782 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001783 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001784 if (codec_ambiguous) {
1785 if (output_capability == V4L2_PIX_FMT_DIVX) {
1786 struct v4l2_control divx_ctrl;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001787
Arun Menon906de572013-06-18 17:01:40 -07001788 if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) {
1789 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4;
1790 } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) {
1791 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5;
1792 } else {
1793 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6;
1794 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001795
Arun Menon906de572013-06-18 17:01:40 -07001796 divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT;
1797 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl);
1798 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001799 DEBUG_PRINT_ERROR("Failed to set divx version");
Arun Menon906de572013-06-18 17:01:40 -07001800 }
1801 } else {
1802 DEBUG_PRINT_ERROR("Codec should not be ambiguous");
1803 }
1804 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001805
Jia Meng3a3c6492013-12-19 17:16:52 +08001806 property_get("persist.vidc.dec.conceal_color", property_value, DEFAULT_CONCEAL_COLOR);
1807 m_conceal_color= atoi(property_value);
1808 DEBUG_PRINT_HIGH("trying to set 0x%x as conceal color\n",m_conceal_color);
1809 control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR;
1810 control.value = m_conceal_color;
1811 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
1812 if (ret) {
1813 DEBUG_PRINT_ERROR("Failed to set conceal color %d\n", ret);
1814 }
1815
Arun Menon906de572013-06-18 17:01:40 -07001816 //Get the hardware capabilities
1817 memset((void *)&frmsize,0,sizeof(frmsize));
1818 frmsize.index = 0;
1819 frmsize.pixel_format = output_capability;
1820 ret = ioctl(drv_ctx.video_driver_fd,
1821 VIDIOC_ENUM_FRAMESIZES, &frmsize);
1822 if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001823 DEBUG_PRINT_ERROR("Failed to get framesizes");
Arun Menon906de572013-06-18 17:01:40 -07001824 return OMX_ErrorHardware;
1825 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001826
Arun Menon906de572013-06-18 17:01:40 -07001827 if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1828 m_decoder_capability.min_width = frmsize.stepwise.min_width;
1829 m_decoder_capability.max_width = frmsize.stepwise.max_width;
1830 m_decoder_capability.min_height = frmsize.stepwise.min_height;
1831 m_decoder_capability.max_height = frmsize.stepwise.max_height;
1832 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001833
Arun Menon906de572013-06-18 17:01:40 -07001834 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1835 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1836 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1837 fmt.fmt.pix_mp.pixelformat = capture_capability;
1838 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1839 if (ret) {
1840 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001841 DEBUG_PRINT_ERROR("Failed to set format on capture port");
Arun Menon906de572013-06-18 17:01:40 -07001842 }
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301843 memset(&framesize, 0, sizeof(OMX_FRAMESIZETYPE));
1844 framesize.nWidth = drv_ctx.video_resolution.frame_width;
1845 framesize.nHeight = drv_ctx.video_resolution.frame_height;
1846
1847 memset(&rectangle, 0, sizeof(OMX_CONFIG_RECTTYPE));
1848 rectangle.nWidth = drv_ctx.video_resolution.frame_width;
1849 rectangle.nHeight = drv_ctx.video_resolution.frame_height;
1850
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001851 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001852 if (secure_mode) {
1853 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE;
1854 control.value = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001855 DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001856 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
1857 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001858 DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001859 return OMX_ErrorInsufficientResources;
1860 }
1861 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001862
Arun Menon906de572013-06-18 17:01:40 -07001863 /*Get the Buffer requirements for input and output ports*/
1864 drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT;
1865 drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
1866 if (secure_mode) {
1867 drv_ctx.op_buf.alignment=SZ_1M;
1868 drv_ctx.ip_buf.alignment=SZ_1M;
1869 } else {
1870 drv_ctx.op_buf.alignment=SZ_4K;
1871 drv_ctx.ip_buf.alignment=SZ_4K;
1872 }
1873 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
1874 drv_ctx.extradata = 0;
1875 drv_ctx.picture_order = VDEC_ORDER_DISPLAY;
1876 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
1877 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
1878 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
1879 drv_ctx.idr_only_decoding = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001880
Vinay Kalia5713bb32013-01-16 18:39:59 -08001881 m_state = OMX_StateLoaded;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001882#ifdef DEFAULT_EXTRADATA
Arun Menonf8908a62013-12-20 17:36:21 -08001883 if (strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",
1884 OMX_MAX_STRINGNAME_SIZE) && (eRet == OMX_ErrorNone))
1885 enable_extradata(DEFAULT_EXTRADATA, true, true);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001886#endif
Vinay Kalia5713bb32013-01-16 18:39:59 -08001887 eRet=get_buffer_req(&drv_ctx.ip_buf);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001888 DEBUG_PRINT_HIGH("Input Buffer Size =%d",drv_ctx.ip_buf.buffer_size);
Vinay Kalia5713bb32013-01-16 18:39:59 -08001889 get_buffer_req(&drv_ctx.op_buf);
Arun Menon906de572013-06-18 17:01:40 -07001890 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
1891 if (m_frame_parser.mutils == NULL) {
1892 m_frame_parser.mutils = new H264_Utils();
Shalaj Jain273b3e02012-06-22 19:08:03 -07001893
Arun Menon906de572013-06-18 17:01:40 -07001894 if (m_frame_parser.mutils == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001895 DEBUG_PRINT_ERROR("parser utils Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001896 eRet = OMX_ErrorInsufficientResources;
1897 } else {
1898 h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size;
1899 h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size);
1900 h264_scratch.nFilledLen = 0;
1901 h264_scratch.nOffset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001902
Arun Menon906de572013-06-18 17:01:40 -07001903 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001904 DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001905 return OMX_ErrorInsufficientResources;
1906 }
1907 m_frame_parser.mutils->initialize_frame_checking_environment();
1908 m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size);
1909 }
1910 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001911
Arun Menon906de572013-06-18 17:01:40 -07001912 h264_parser = new h264_stream_parser();
1913 if (!h264_parser) {
1914 DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!");
1915 eRet = OMX_ErrorInsufficientResources;
1916 }
1917 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001918
Arun Menon906de572013-06-18 17:01:40 -07001919 if (pipe(fds)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001920 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001921 eRet = OMX_ErrorInsufficientResources;
1922 } else {
1923 int temp1[2];
1924 if (fds[0] == 0 || fds[1] == 0) {
1925 if (pipe (temp1)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001926 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001927 return OMX_ErrorInsufficientResources;
1928 }
1929 //close (fds[0]);
1930 //close (fds[1]);
1931 fds[0] = temp1 [0];
1932 fds[1] = temp1 [1];
1933 }
1934 m_pipe_in = fds[0];
1935 m_pipe_out = fds[1];
1936 msg_thread_created = true;
Ashray Kulkarnia97efbc2015-07-15 18:17:23 -07001937 r = pthread_create(&msg_thread_id,0, dec_message_thread,this);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001938
Arun Menon906de572013-06-18 17:01:40 -07001939 if (r < 0) {
Ashray Kulkarnia97efbc2015-07-15 18:17:23 -07001940 DEBUG_PRINT_ERROR("component_init(): dec_message_thread creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001941 msg_thread_created = false;
1942 eRet = OMX_ErrorInsufficientResources;
1943 }
1944 }
1945 }
1946
1947 if (eRet != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001948 DEBUG_PRINT_ERROR("Component Init Failed");
Arun Menon906de572013-06-18 17:01:40 -07001949 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001950 DEBUG_PRINT_HIGH("omx_vdec::component_init() success");
Arun Menon906de572013-06-18 17:01:40 -07001951 }
1952 //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer));
Praveen Chavan898df262015-04-20 18:52:19 -07001953 control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY;
1954 control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE;
1955
1956 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
1957 DEBUG_PRINT_ERROR("Failed to set Default Priority");
1958 eRet = OMX_ErrorUnsupportedSetting;
1959 }
Arun Menon906de572013-06-18 17:01:40 -07001960 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001961}
1962
1963/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001964 FUNCTION
1965 omx_vdec::GetComponentVersion
Shalaj Jain273b3e02012-06-22 19:08:03 -07001966
Arun Menon906de572013-06-18 17:01:40 -07001967 DESCRIPTION
1968 Returns the component version.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001969
Arun Menon906de572013-06-18 17:01:40 -07001970 PARAMETERS
1971 TBD.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001972
Arun Menon906de572013-06-18 17:01:40 -07001973 RETURN VALUE
1974 OMX_ErrorNone.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001975
Arun Menon906de572013-06-18 17:01:40 -07001976 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001977OMX_ERRORTYPE omx_vdec::get_component_version
Arun Menon906de572013-06-18 17:01:40 -07001978(
1979 OMX_IN OMX_HANDLETYPE hComp,
1980 OMX_OUT OMX_STRING componentName,
1981 OMX_OUT OMX_VERSIONTYPE* componentVersion,
1982 OMX_OUT OMX_VERSIONTYPE* specVersion,
1983 OMX_OUT OMX_UUIDTYPE* componentUUID
1984 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07001985{
Arun Menon906de572013-06-18 17:01:40 -07001986 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001987 DEBUG_PRINT_ERROR("Get Comp Version in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001988 return OMX_ErrorInvalidState;
1989 }
Arun Menon906de572013-06-18 17:01:40 -07001990 /* TBD -- Return the proper version */
1991 if (specVersion) {
1992 specVersion->nVersion = OMX_SPEC_VERSION;
1993 }
1994 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001995}
1996/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001997 FUNCTION
1998 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07001999
Arun Menon906de572013-06-18 17:01:40 -07002000 DESCRIPTION
2001 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07002002
Arun Menon906de572013-06-18 17:01:40 -07002003 PARAMETERS
2004 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002005
Arun Menon906de572013-06-18 17:01:40 -07002006 RETURN VALUE
2007 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002008
Arun Menon906de572013-06-18 17:01:40 -07002009 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002010OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002011 OMX_IN OMX_COMMANDTYPE cmd,
2012 OMX_IN OMX_U32 param1,
2013 OMX_IN OMX_PTR cmdData
2014 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07002015{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002016 DEBUG_PRINT_LOW("send_command: Recieved a Command from Client");
Arun Menon906de572013-06-18 17:01:40 -07002017 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002018 DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002019 return OMX_ErrorInvalidState;
2020 }
2021 if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX
Arun Menon906de572013-06-18 17:01:40 -07002022 && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002023 DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush "
Arun Menon906de572013-06-18 17:01:40 -07002024 "to invalid port: %lu", param1);
2025 return OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002026 }
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -07002027
Shalaj Jain273b3e02012-06-22 19:08:03 -07002028 post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND);
2029 sem_wait(&m_cmd_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002030 DEBUG_PRINT_LOW("send_command: Command Processed");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002031 return OMX_ErrorNone;
2032}
2033
2034/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002035 FUNCTION
2036 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07002037
Arun Menon906de572013-06-18 17:01:40 -07002038 DESCRIPTION
2039 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07002040
Arun Menon906de572013-06-18 17:01:40 -07002041 PARAMETERS
2042 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002043
Arun Menon906de572013-06-18 17:01:40 -07002044 RETURN VALUE
2045 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002046
Arun Menon906de572013-06-18 17:01:40 -07002047 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002048OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002049 OMX_IN OMX_COMMANDTYPE cmd,
2050 OMX_IN OMX_U32 param1,
2051 OMX_IN OMX_PTR cmdData
2052 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07002053{
Arun Menon906de572013-06-18 17:01:40 -07002054 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2055 OMX_STATETYPE eState = (OMX_STATETYPE) param1;
2056 int bFlag = 1,sem_posted = 0,ret=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002057
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002058 DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd);
2059 DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d",
Arun Menon906de572013-06-18 17:01:40 -07002060 m_state, eState);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002061
Arun Menon906de572013-06-18 17:01:40 -07002062 if (cmd == OMX_CommandStateSet) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002063 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued");
2064 DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState);
Arun Menon906de572013-06-18 17:01:40 -07002065 /***************************/
2066 /* Current State is Loaded */
2067 /***************************/
2068 if (m_state == OMX_StateLoaded) {
2069 if (eState == OMX_StateIdle) {
2070 //if all buffers are allocated or all ports disabled
2071 if (allocate_done() ||
2072 (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002073 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07002074 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002075 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending");
Arun Menon906de572013-06-18 17:01:40 -07002076 BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING);
2077 // Skip the event notification
2078 bFlag = 0;
2079 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002080 }
Arun Menon906de572013-06-18 17:01:40 -07002081 /* Requesting transition from Loaded to Loaded */
2082 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002083 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002084 post_event(OMX_EventError,OMX_ErrorSameState,\
2085 OMX_COMPONENT_GENERATE_EVENT);
2086 eRet = OMX_ErrorSameState;
2087 }
2088 /* Requesting transition from Loaded to WaitForResources */
2089 else if (eState == OMX_StateWaitForResources) {
2090 /* Since error is None , we will post an event
2091 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002092 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002093 }
2094 /* Requesting transition from Loaded to Executing */
2095 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002096 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002097 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2098 OMX_COMPONENT_GENERATE_EVENT);
2099 eRet = OMX_ErrorIncorrectStateTransition;
2100 }
2101 /* Requesting transition from Loaded to Pause */
2102 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002103 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002104 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2105 OMX_COMPONENT_GENERATE_EVENT);
2106 eRet = OMX_ErrorIncorrectStateTransition;
2107 }
2108 /* Requesting transition from Loaded to Invalid */
2109 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002110 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002111 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2112 eRet = OMX_ErrorInvalidState;
2113 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002114 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\
Arun Menon906de572013-06-18 17:01:40 -07002115 eState);
2116 eRet = OMX_ErrorBadParameter;
2117 }
2118 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002119
Arun Menon906de572013-06-18 17:01:40 -07002120 /***************************/
2121 /* Current State is IDLE */
2122 /***************************/
2123 else if (m_state == OMX_StateIdle) {
2124 if (eState == OMX_StateLoaded) {
2125 if (release_done()) {
2126 /*
2127 Since error is None , we will post an event at the end
2128 of this function definition
2129 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002130 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002131 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002132 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending");
Arun Menon906de572013-06-18 17:01:40 -07002133 BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING);
2134 // Skip the event notification
2135 bFlag = 0;
2136 }
2137 }
2138 /* Requesting transition from Idle to Executing */
2139 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002140 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002141 //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING);
2142 bFlag = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002143 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002144 m_state=OMX_StateExecuting;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002145 DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful");
Arun Menon906de572013-06-18 17:01:40 -07002146 }
2147 /* Requesting transition from Idle to Idle */
2148 else if (eState == OMX_StateIdle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002149 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07002150 post_event(OMX_EventError,OMX_ErrorSameState,\
2151 OMX_COMPONENT_GENERATE_EVENT);
2152 eRet = OMX_ErrorSameState;
2153 }
2154 /* Requesting transition from Idle to WaitForResources */
2155 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002156 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002157 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2158 OMX_COMPONENT_GENERATE_EVENT);
2159 eRet = OMX_ErrorIncorrectStateTransition;
2160 }
2161 /* Requesting transition from Idle to Pause */
2162 else if (eState == OMX_StatePause) {
2163 /*To pause the Video core we need to start the driver*/
2164 if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START,
2165 NULL) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002166 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED");
Arun Menon906de572013-06-18 17:01:40 -07002167 omx_report_error ();
2168 eRet = OMX_ErrorHardware;
2169 } else {
2170 BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002171 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002172 bFlag = 0;
2173 }
2174 }
2175 /* Requesting transition from Idle to Invalid */
2176 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002177 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002178 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2179 eRet = OMX_ErrorInvalidState;
2180 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002181 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002182 eRet = OMX_ErrorBadParameter;
2183 }
2184 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002185
Arun Menon906de572013-06-18 17:01:40 -07002186 /******************************/
2187 /* Current State is Executing */
2188 /******************************/
2189 else if (m_state == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002190 DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting");
Arun Menon906de572013-06-18 17:01:40 -07002191 /* Requesting transition from Executing to Idle */
2192 if (eState == OMX_StateIdle) {
2193 /* Since error is None , we will post an event
2194 at the end of this function definition
2195 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002196 DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002197 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2198 if (!sem_posted) {
2199 sem_posted = 1;
2200 sem_post (&m_cmd_lock);
2201 execute_omx_flush(OMX_ALL);
2202 }
2203 bFlag = 0;
2204 }
2205 /* Requesting transition from Executing to Paused */
2206 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002207 DEBUG_PRINT_LOW("PAUSE Command Issued");
Arun Menon906de572013-06-18 17:01:40 -07002208 m_state = OMX_StatePause;
2209 bFlag = 1;
2210 }
2211 /* Requesting transition from Executing to Loaded */
2212 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002213 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002214 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2215 OMX_COMPONENT_GENERATE_EVENT);
2216 eRet = OMX_ErrorIncorrectStateTransition;
2217 }
2218 /* Requesting transition from Executing to WaitForResources */
2219 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002220 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002221 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2222 OMX_COMPONENT_GENERATE_EVENT);
2223 eRet = OMX_ErrorIncorrectStateTransition;
2224 }
2225 /* Requesting transition from Executing to Executing */
2226 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002227 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002228 post_event(OMX_EventError,OMX_ErrorSameState,\
2229 OMX_COMPONENT_GENERATE_EVENT);
2230 eRet = OMX_ErrorSameState;
2231 }
2232 /* Requesting transition from Executing to Invalid */
2233 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002234 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002235 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2236 eRet = OMX_ErrorInvalidState;
2237 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002238 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002239 eRet = OMX_ErrorBadParameter;
2240 }
2241 }
2242 /***************************/
2243 /* Current State is Pause */
2244 /***************************/
2245 else if (m_state == OMX_StatePause) {
2246 /* Requesting transition from Pause to Executing */
2247 if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002248 DEBUG_PRINT_LOW("Pause --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002249 m_state = OMX_StateExecuting;
2250 bFlag = 1;
2251 }
2252 /* Requesting transition from Pause to Idle */
2253 else if (eState == OMX_StateIdle) {
2254 /* Since error is None , we will post an event
2255 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002256 DEBUG_PRINT_LOW("Pause --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002257 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2258 if (!sem_posted) {
2259 sem_posted = 1;
2260 sem_post (&m_cmd_lock);
2261 execute_omx_flush(OMX_ALL);
2262 }
2263 bFlag = 0;
2264 }
2265 /* Requesting transition from Pause to loaded */
2266 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002267 DEBUG_PRINT_ERROR("Pause --> loaded");
Arun Menon906de572013-06-18 17:01:40 -07002268 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2269 OMX_COMPONENT_GENERATE_EVENT);
2270 eRet = OMX_ErrorIncorrectStateTransition;
2271 }
2272 /* Requesting transition from Pause to WaitForResources */
2273 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002274 DEBUG_PRINT_ERROR("Pause --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002275 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2276 OMX_COMPONENT_GENERATE_EVENT);
2277 eRet = OMX_ErrorIncorrectStateTransition;
2278 }
2279 /* Requesting transition from Pause to Pause */
2280 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002281 DEBUG_PRINT_ERROR("Pause --> Pause");
Arun Menon906de572013-06-18 17:01:40 -07002282 post_event(OMX_EventError,OMX_ErrorSameState,\
2283 OMX_COMPONENT_GENERATE_EVENT);
2284 eRet = OMX_ErrorSameState;
2285 }
2286 /* Requesting transition from Pause to Invalid */
2287 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002288 DEBUG_PRINT_ERROR("Pause --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002289 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2290 eRet = OMX_ErrorInvalidState;
2291 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002292 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002293 eRet = OMX_ErrorBadParameter;
2294 }
2295 }
2296 /***************************/
2297 /* Current State is WaitForResources */
2298 /***************************/
2299 else if (m_state == OMX_StateWaitForResources) {
2300 /* Requesting transition from WaitForResources to Loaded */
2301 if (eState == OMX_StateLoaded) {
2302 /* Since error is None , we will post an event
2303 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002304 DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002305 }
2306 /* Requesting transition from WaitForResources to WaitForResources */
2307 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002308 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002309 post_event(OMX_EventError,OMX_ErrorSameState,
2310 OMX_COMPONENT_GENERATE_EVENT);
2311 eRet = OMX_ErrorSameState;
2312 }
2313 /* Requesting transition from WaitForResources to Executing */
2314 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002315 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002316 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2317 OMX_COMPONENT_GENERATE_EVENT);
2318 eRet = OMX_ErrorIncorrectStateTransition;
2319 }
2320 /* Requesting transition from WaitForResources to Pause */
2321 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002322 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002323 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2324 OMX_COMPONENT_GENERATE_EVENT);
2325 eRet = OMX_ErrorIncorrectStateTransition;
2326 }
2327 /* Requesting transition from WaitForResources to Invalid */
2328 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002329 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002330 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2331 eRet = OMX_ErrorInvalidState;
2332 }
2333 /* Requesting transition from WaitForResources to Loaded -
2334 is NOT tested by Khronos TS */
2335
2336 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002337 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): %d --> %d(Not Handled)",m_state,eState);
Arun Menon906de572013-06-18 17:01:40 -07002338 eRet = OMX_ErrorBadParameter;
2339 }
2340 }
2341 /********************************/
2342 /* Current State is Invalid */
2343 /*******************************/
2344 else if (m_state == OMX_StateInvalid) {
2345 /* State Transition from Inavlid to any state */
2346 if (eState == (OMX_StateLoaded || OMX_StateWaitForResources
2347 || OMX_StateIdle || OMX_StateExecuting
2348 || OMX_StatePause || OMX_StateInvalid)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002349 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002350 post_event(OMX_EventError,OMX_ErrorInvalidState,\
2351 OMX_COMPONENT_GENERATE_EVENT);
2352 eRet = OMX_ErrorInvalidState;
2353 }
2354 } else if (cmd == OMX_CommandFlush) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002355 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued"
Arun Menon906de572013-06-18 17:01:40 -07002356 "with param1: %lu", param1);
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07002357#ifdef _MSM8974_
2358 send_codec_config();
2359#endif
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302360 if (cmd == OMX_CommandFlush && (param1 == OMX_CORE_INPUT_PORT_INDEX ||
2361 param1 == OMX_ALL)) {
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05302362 if (android_atomic_add(0, &m_queued_codec_config_count) > 0) {
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302363 struct timespec ts;
2364
2365 clock_gettime(CLOCK_REALTIME, &ts);
2366 ts.tv_sec += 2;
2367 DEBUG_PRINT_LOW("waiting for %d EBDs of CODEC CONFIG buffers ",
2368 m_queued_codec_config_count);
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05302369 BITMASK_SET(&m_flags, OMX_COMPONENT_FLUSH_DEFERRED);
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302370 if (sem_timedwait(&m_safe_flush, &ts)) {
2371 DEBUG_PRINT_ERROR("Failed to wait for EBDs of CODEC CONFIG buffers");
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302372 }
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05302373 BITMASK_CLEAR (&m_flags,OMX_COMPONENT_FLUSH_DEFERRED);
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302374 }
2375 }
2376
Arun Menon906de572013-06-18 17:01:40 -07002377 if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2378 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING);
2379 }
2380 if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2381 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
2382 }
2383 if (!sem_posted) {
2384 sem_posted = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002385 DEBUG_PRINT_LOW("Set the Semaphore");
Arun Menon906de572013-06-18 17:01:40 -07002386 sem_post (&m_cmd_lock);
2387 execute_omx_flush(param1);
2388 }
2389 bFlag = 0;
2390 } else if ( cmd == OMX_CommandPortEnable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002391 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued"
Arun Menon906de572013-06-18 17:01:40 -07002392 "with param1: %lu", param1);
2393 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
2394 m_inp_bEnabled = OMX_TRUE;
2395
2396 if ( (m_state == OMX_StateLoaded &&
2397 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2398 || allocate_input_done()) {
2399 post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX,
2400 OMX_COMPONENT_GENERATE_EVENT);
2401 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002402 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002403 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING);
2404 // Skip the event notification
2405 bFlag = 0;
2406 }
2407 }
2408 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002409 DEBUG_PRINT_LOW("Enable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002410 m_out_bEnabled = OMX_TRUE;
2411
2412 if ( (m_state == OMX_StateLoaded &&
2413 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2414 || (allocate_output_done())) {
2415 post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX,
2416 OMX_COMPONENT_GENERATE_EVENT);
2417
2418 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002419 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002420 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
2421 // Skip the event notification
2422 bFlag = 0;
2423 }
2424 }
2425 } else if (cmd == OMX_CommandPortDisable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002426 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued"
Arun Menon906de572013-06-18 17:01:40 -07002427 "with param1: %lu", param1);
2428 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07002429 codec_config_flag = false;
Arun Menon906de572013-06-18 17:01:40 -07002430 m_inp_bEnabled = OMX_FALSE;
2431 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2432 && release_input_done()) {
2433 post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX,
2434 OMX_COMPONENT_GENERATE_EVENT);
2435 } else {
2436 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING);
2437 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2438 if (!sem_posted) {
2439 sem_posted = 1;
2440 sem_post (&m_cmd_lock);
2441 }
2442 execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX);
2443 }
2444
2445 // Skip the event notification
2446 bFlag = 0;
2447 }
2448 }
2449 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
2450 m_out_bEnabled = OMX_FALSE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002451 DEBUG_PRINT_LOW("Disable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002452 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2453 && release_output_done()) {
2454 post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\
2455 OMX_COMPONENT_GENERATE_EVENT);
2456 } else {
2457 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
2458 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2459 if (!sem_posted) {
2460 sem_posted = 1;
2461 sem_post (&m_cmd_lock);
2462 }
2463 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
2464 execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX);
2465 }
2466 // Skip the event notification
2467 bFlag = 0;
2468
2469 }
2470 }
2471 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002472 DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd);
Arun Menon906de572013-06-18 17:01:40 -07002473 eRet = OMX_ErrorNotImplemented;
2474 }
2475 if (eRet == OMX_ErrorNone && bFlag) {
2476 post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT);
2477 }
2478 if (!sem_posted) {
2479 sem_post(&m_cmd_lock);
2480 }
2481
2482 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002483}
2484
2485/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002486 FUNCTION
2487 omx_vdec::ExecuteOmxFlush
Shalaj Jain273b3e02012-06-22 19:08:03 -07002488
Arun Menon906de572013-06-18 17:01:40 -07002489 DESCRIPTION
2490 Executes the OMX flush.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002491
Arun Menon906de572013-06-18 17:01:40 -07002492 PARAMETERS
2493 flushtype - input flush(1)/output flush(0)/ both.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002494
Arun Menon906de572013-06-18 17:01:40 -07002495 RETURN VALUE
2496 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002497
Arun Menon906de572013-06-18 17:01:40 -07002498 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002499bool omx_vdec::execute_omx_flush(OMX_U32 flushType)
2500{
Arun Menon906de572013-06-18 17:01:40 -07002501 bool bRet = false;
2502 struct v4l2_plane plane;
2503 struct v4l2_buffer v4l2_buf;
2504 struct v4l2_decoder_cmd dec;
Surajit Podderd2644d52013-08-28 17:59:06 +05302505 DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType);
Arun Menon906de572013-06-18 17:01:40 -07002506 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
2507 dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH;
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002508
Arun Menon906de572013-06-18 17:01:40 -07002509 DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig);
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002510
Arun Menon906de572013-06-18 17:01:40 -07002511 if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) {
2512 output_flush_progress = true;
2513 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2514 } else {
2515 /* XXX: The driver/hardware does not support flushing of individual ports
2516 * in all states. So we pretty much need to flush both ports internally,
2517 * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it
2518 * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set,
2519 * we automatically omit sending the FLUSH done for the "opposite" port. */
2520 input_flush_progress = true;
2521 output_flush_progress = true;
2522 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2523 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002524
Arun Menon906de572013-06-18 17:01:40 -07002525 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002526 DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType);
Arun Menon906de572013-06-18 17:01:40 -07002527 bRet = false;
2528 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002529
Arun Menon906de572013-06-18 17:01:40 -07002530 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002531}
2532/*=========================================================================
2533FUNCTION : execute_output_flush
2534
2535DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002536Executes the OMX flush at OUTPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002537
2538PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002539None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002540
2541RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002542true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002543==========================================================================*/
2544bool omx_vdec::execute_output_flush()
2545{
Arun Menon906de572013-06-18 17:01:40 -07002546 unsigned p1 = 0; // Parameter - 1
2547 unsigned p2 = 0; // Parameter - 2
2548 unsigned ident = 0;
2549 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002550
Arun Menon906de572013-06-18 17:01:40 -07002551 /*Generate FBD for all Buffers in the FTBq*/
2552 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002553 DEBUG_PRINT_LOW("Initiate Output Flush");
vivek mehta79cff222014-01-22 12:17:07 -08002554
2555 //reset last render TS
2556 if(m_last_rendered_TS > 0) {
2557 m_last_rendered_TS = 0;
2558 }
vivek mehtaa75c69f2014-01-10 21:50:37 -08002559
Arun Menon906de572013-06-18 17:01:40 -07002560 while (m_ftb_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002561 DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d",
Arun Menon906de572013-06-18 17:01:40 -07002562 m_ftb_q.m_size,pending_output_buffers);
2563 m_ftb_q.pop_entry(&p1,&p2,&ident);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002564 DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2);
Arun Menon906de572013-06-18 17:01:40 -07002565 if (ident == m_fill_output_msg ) {
2566 m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2567 } else if (ident == OMX_COMPONENT_GENERATE_FBD) {
2568 fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2569 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002570 }
Arun Menon906de572013-06-18 17:01:40 -07002571 pthread_mutex_unlock(&m_lock);
2572 output_flush_progress = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002573
Arun Menon906de572013-06-18 17:01:40 -07002574 if (arbitrary_bytes) {
2575 prev_ts = LLONG_MAX;
2576 rst_prev_ts = true;
2577 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002578 DEBUG_PRINT_HIGH("OMX flush o/p Port complete PenBuf(%d)", pending_output_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002579 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002580}
2581/*=========================================================================
2582FUNCTION : execute_input_flush
2583
2584DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002585Executes the OMX flush at INPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002586
2587PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002588None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002589
2590RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002591true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002592==========================================================================*/
2593bool omx_vdec::execute_input_flush()
2594{
Arun Menon906de572013-06-18 17:01:40 -07002595 unsigned i =0;
2596 unsigned p1 = 0; // Parameter - 1
2597 unsigned p2 = 0; // Parameter - 2
2598 unsigned ident = 0;
2599 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002600
Arun Menon906de572013-06-18 17:01:40 -07002601 /*Generate EBD for all Buffers in the ETBq*/
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002602 DEBUG_PRINT_LOW("Initiate Input Flush");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002603
Arun Menon906de572013-06-18 17:01:40 -07002604 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002605 DEBUG_PRINT_LOW("Check if the Queue is empty");
Arun Menon906de572013-06-18 17:01:40 -07002606 while (m_etb_q.m_size) {
2607 m_etb_q.pop_entry(&p1,&p2,&ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002608
Arun Menon906de572013-06-18 17:01:40 -07002609 if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002610 DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2);
Arun Menon906de572013-06-18 17:01:40 -07002611 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2612 } else if (ident == OMX_COMPONENT_GENERATE_ETB) {
2613 pending_input_buffers++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002614 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d",
Arun Menon906de572013-06-18 17:01:40 -07002615 (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers);
2616 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
2617 } else if (ident == OMX_COMPONENT_GENERATE_EBD) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002618 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p",
Arun Menon906de572013-06-18 17:01:40 -07002619 (OMX_BUFFERHEADERTYPE *)p1);
2620 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2621 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002622 }
Arun Menon906de572013-06-18 17:01:40 -07002623 time_stamp_dts.flush_timestamp();
2624 /*Check if Heap Buffers are to be flushed*/
2625 if (arbitrary_bytes && !(codec_config_flag)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002626 DEBUG_PRINT_LOW("Reset all the variables before flusing");
Arun Menon906de572013-06-18 17:01:40 -07002627 h264_scratch.nFilledLen = 0;
2628 nal_count = 0;
2629 look_ahead_nal = false;
2630 frame_count = 0;
2631 h264_last_au_ts = LLONG_MAX;
2632 h264_last_au_flags = 0;
2633 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
2634 m_demux_entries = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002635 DEBUG_PRINT_LOW("Initialize parser");
Arun Menon906de572013-06-18 17:01:40 -07002636 if (m_frame_parser.mutils) {
2637 m_frame_parser.mutils->initialize_frame_checking_environment();
2638 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002639
Arun Menon906de572013-06-18 17:01:40 -07002640 while (m_input_pending_q.m_size) {
2641 m_input_pending_q.pop_entry(&p1,&p2,&ident);
2642 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1);
2643 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002644
Arun Menon906de572013-06-18 17:01:40 -07002645 if (psource_frame) {
2646 m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame);
2647 psource_frame = NULL;
2648 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002649
Arun Menon906de572013-06-18 17:01:40 -07002650 if (pdest_frame) {
2651 pdest_frame->nFilledLen = 0;
2652 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL,
2653 (unsigned int)NULL);
2654 pdest_frame = NULL;
2655 }
2656 m_frame_parser.flush();
2657 } else if (codec_config_flag) {
2658 DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer "
2659 "is not sent to the driver yet");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002660 }
Arun Menon906de572013-06-18 17:01:40 -07002661 pthread_mutex_unlock(&m_lock);
2662 input_flush_progress = false;
2663 if (!arbitrary_bytes) {
2664 prev_ts = LLONG_MAX;
2665 rst_prev_ts = true;
2666 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002667#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07002668 if (m_debug_timestamp) {
2669 m_timestamp_list.reset_ts_list();
2670 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002671#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002672 DEBUG_PRINT_HIGH("OMX flush i/p Port complete PenBuf(%d)", pending_input_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002673 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002674}
2675
2676
2677/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002678 FUNCTION
2679 omx_vdec::SendCommandEvent
Shalaj Jain273b3e02012-06-22 19:08:03 -07002680
Arun Menon906de572013-06-18 17:01:40 -07002681 DESCRIPTION
2682 Send the event to decoder pipe. This is needed to generate the callbacks
2683 in decoder thread context.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002684
Arun Menon906de572013-06-18 17:01:40 -07002685 PARAMETERS
2686 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002687
Arun Menon906de572013-06-18 17:01:40 -07002688 RETURN VALUE
2689 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002690
Arun Menon906de572013-06-18 17:01:40 -07002691 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002692bool omx_vdec::post_event(unsigned int p1,
Arun Menon906de572013-06-18 17:01:40 -07002693 unsigned int p2,
2694 unsigned int id)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002695{
Arun Menon906de572013-06-18 17:01:40 -07002696 bool bRet = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002697
2698
Arun Menon906de572013-06-18 17:01:40 -07002699 pthread_mutex_lock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002700
Arun Menon906de572013-06-18 17:01:40 -07002701 if (id == m_fill_output_msg ||
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05302702 id == OMX_COMPONENT_GENERATE_FBD ||
2703 id == OMX_COMPONENT_GENERATE_PORT_RECONFIG) {
Arun Menon906de572013-06-18 17:01:40 -07002704 m_ftb_q.insert_entry(p1,p2,id);
2705 } else if (id == OMX_COMPONENT_GENERATE_ETB ||
2706 id == OMX_COMPONENT_GENERATE_EBD ||
2707 id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
2708 m_etb_q.insert_entry(p1,p2,id);
2709 } else {
2710 m_cmd_q.insert_entry(p1,p2,id);
2711 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002712
Arun Menon906de572013-06-18 17:01:40 -07002713 bRet = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002714 DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this);
Arun Menon906de572013-06-18 17:01:40 -07002715 post_message(this, id);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002716
Arun Menon906de572013-06-18 17:01:40 -07002717 pthread_mutex_unlock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002718
Arun Menon906de572013-06-18 17:01:40 -07002719 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002720}
2721
2722OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType)
2723{
Arun Menon906de572013-06-18 17:01:40 -07002724 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2725 if (!profileLevelType)
2726 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002727
Arun Menon906de572013-06-18 17:01:40 -07002728 if (profileLevelType->nPortIndex == 0) {
2729 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
2730 if (profileLevelType->nProfileIndex == 0) {
2731 profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline;
2732 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002733
Arun Menon906de572013-06-18 17:01:40 -07002734 } else if (profileLevelType->nProfileIndex == 1) {
2735 profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain;
2736 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2737 } else if (profileLevelType->nProfileIndex == 2) {
2738 profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh;
2739 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2740 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002741 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu",
Arun Menon906de572013-06-18 17:01:40 -07002742 profileLevelType->nProfileIndex);
2743 eRet = OMX_ErrorNoMore;
2744 }
2745 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) {
2746 if (profileLevelType->nProfileIndex == 0) {
2747 profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline;
2748 profileLevelType->eLevel = OMX_VIDEO_H263Level70;
2749 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002750 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002751 eRet = OMX_ErrorNoMore;
2752 }
2753 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
2754 if (profileLevelType->nProfileIndex == 0) {
2755 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple;
2756 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2757 } else if (profileLevelType->nProfileIndex == 1) {
2758 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple;
2759 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2760 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002761 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002762 eRet = OMX_ErrorNoMore;
2763 }
2764 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
2765 eRet = OMX_ErrorNoMore;
2766 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
2767 if (profileLevelType->nProfileIndex == 0) {
2768 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple;
2769 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2770 } else if (profileLevelType->nProfileIndex == 1) {
2771 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain;
2772 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2773 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002774 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002775 eRet = OMX_ErrorNoMore;
2776 }
2777 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002778 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported ret NoMore for codec: %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07002779 eRet = OMX_ErrorNoMore;
2780 }
2781 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002782 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported should be queries on Input port only %lu", profileLevelType->nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07002783 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002784 }
Arun Menon906de572013-06-18 17:01:40 -07002785 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002786}
2787
2788/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002789 FUNCTION
2790 omx_vdec::GetParameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07002791
Arun Menon906de572013-06-18 17:01:40 -07002792 DESCRIPTION
2793 OMX Get Parameter method implementation
Shalaj Jain273b3e02012-06-22 19:08:03 -07002794
Arun Menon906de572013-06-18 17:01:40 -07002795 PARAMETERS
2796 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002797
Arun Menon906de572013-06-18 17:01:40 -07002798 RETURN VALUE
2799 Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002800
Arun Menon906de572013-06-18 17:01:40 -07002801 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002802OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002803 OMX_IN OMX_INDEXTYPE paramIndex,
2804 OMX_INOUT OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002805{
2806 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2807
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002808 DEBUG_PRINT_LOW("get_parameter:");
Arun Menon906de572013-06-18 17:01:40 -07002809 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002810 DEBUG_PRINT_ERROR("Get Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002811 return OMX_ErrorInvalidState;
2812 }
Arun Menon906de572013-06-18 17:01:40 -07002813 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002814 DEBUG_PRINT_LOW("Get Param in Invalid paramData");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002815 return OMX_ErrorBadParameter;
2816 }
Arun Menon906de572013-06-18 17:01:40 -07002817 switch ((unsigned long)paramIndex) {
2818 case OMX_IndexParamPortDefinition: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002819 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002820 OMX_PARAM_PORTDEFINITIONTYPE *portDefn =
2821 (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002822 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition");
Arun Menon906de572013-06-18 17:01:40 -07002823 eRet = update_portdef(portDefn);
2824 if (eRet == OMX_ErrorNone)
2825 m_port_def = *portDefn;
2826 break;
2827 }
2828 case OMX_IndexParamVideoInit: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002829 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002830 OMX_PORT_PARAM_TYPE *portParamType =
2831 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002832 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002833
Arun Menon906de572013-06-18 17:01:40 -07002834 portParamType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002835 portParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002836 portParamType->nPorts = 2;
2837 portParamType->nStartPortNumber = 0;
2838 break;
2839 }
2840 case OMX_IndexParamVideoPortFormat: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002841 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002842 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
2843 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002844 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002845
Arun Menon906de572013-06-18 17:01:40 -07002846 portFmt->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002847 portFmt->nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002848
Arun Menon906de572013-06-18 17:01:40 -07002849 if (0 == portFmt->nPortIndex) {
2850 if (0 == portFmt->nIndex) {
2851 portFmt->eColorFormat = OMX_COLOR_FormatUnused;
2852 portFmt->eCompressionFormat = eCompressionFormat;
2853 } else {
2854 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002855 " NoMore compression formats");
Arun Menon906de572013-06-18 17:01:40 -07002856 eRet = OMX_ErrorNoMore;
2857 }
2858 } else if (1 == portFmt->nPortIndex) {
2859 portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002860
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07002861 // Distinguish non-surface mode from normal playback use-case based on
2862 // usage hinted via "OMX.google.android.index.useAndroidNativeBuffer2"
2863 // For non-android, use the default list
Praveen Chavancac86402014-10-18 09:14:52 -07002864 // Also use default format-list if FLEXIBLE YUV is supported,
2865 // as the client negotiates the standard color-format if it needs to
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07002866 bool useNonSurfaceMode = false;
Praveen Chavancac86402014-10-18 09:14:52 -07002867#if defined(_ANDROID_) && !defined(FLEXYUV_SUPPORTED)
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07002868 useNonSurfaceMode = (m_enable_android_native_buffers == OMX_FALSE);
2869#endif
2870 portFmt->eColorFormat = useNonSurfaceMode ?
2871 getPreferredColorFormatNonSurfaceMode(portFmt->nIndex) :
2872 getPreferredColorFormatDefaultMode(portFmt->nIndex);
2873
2874 if (portFmt->eColorFormat == OMX_COLOR_FormatMax ) {
Praveen Chavandb7776f2014-02-06 18:17:25 -08002875 eRet = OMX_ErrorNoMore;
Arun Menon906de572013-06-18 17:01:40 -07002876 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002877 " NoMore Color formats");
Arun Menon906de572013-06-18 17:01:40 -07002878 }
Praveen Chavandb7776f2014-02-06 18:17:25 -08002879 DEBUG_PRINT_HIGH("returning color-format: 0x%x", portFmt->eColorFormat);
Arun Menon906de572013-06-18 17:01:40 -07002880 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002881 DEBUG_PRINT_ERROR("get_parameter: Bad port index %d",
Arun Menon906de572013-06-18 17:01:40 -07002882 (int)portFmt->nPortIndex);
2883 eRet = OMX_ErrorBadPortIndex;
2884 }
2885 break;
2886 }
2887 /*Component should support this port definition*/
2888 case OMX_IndexParamAudioInit: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002889 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002890 OMX_PORT_PARAM_TYPE *audioPortParamType =
2891 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002892 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit");
Arun Menon906de572013-06-18 17:01:40 -07002893 audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002894 audioPortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002895 audioPortParamType->nPorts = 0;
2896 audioPortParamType->nStartPortNumber = 0;
2897 break;
2898 }
2899 /*Component should support this port definition*/
2900 case OMX_IndexParamImageInit: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002901 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002902 OMX_PORT_PARAM_TYPE *imagePortParamType =
2903 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002904 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit");
Arun Menon906de572013-06-18 17:01:40 -07002905 imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002906 imagePortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002907 imagePortParamType->nPorts = 0;
2908 imagePortParamType->nStartPortNumber = 0;
2909 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002910
Arun Menon906de572013-06-18 17:01:40 -07002911 }
2912 /*Component should support this port definition*/
2913 case OMX_IndexParamOtherInit: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002914 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x",
Arun Menon906de572013-06-18 17:01:40 -07002915 paramIndex);
2916 eRet =OMX_ErrorUnsupportedIndex;
2917 break;
2918 }
2919 case OMX_IndexParamStandardComponentRole: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002920 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE);
Arun Menon906de572013-06-18 17:01:40 -07002921 OMX_PARAM_COMPONENTROLETYPE *comp_role;
2922 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
2923 comp_role->nVersion.nVersion = OMX_SPEC_VERSION;
2924 comp_role->nSize = sizeof(*comp_role);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002925
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002926 DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d",
Arun Menon906de572013-06-18 17:01:40 -07002927 paramIndex);
2928 strlcpy((char*)comp_role->cRole,(const char*)m_cRole,
2929 OMX_MAX_STRINGNAME_SIZE);
2930 break;
2931 }
2932 /* Added for parameter test */
2933 case OMX_IndexParamPriorityMgmt: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002934 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002935 OMX_PRIORITYMGMTTYPE *priorityMgmType =
2936 (OMX_PRIORITYMGMTTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002937 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt");
Arun Menon906de572013-06-18 17:01:40 -07002938 priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002939 priorityMgmType->nSize = sizeof(OMX_PRIORITYMGMTTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002940
Arun Menon906de572013-06-18 17:01:40 -07002941 break;
2942 }
2943 /* Added for parameter test */
2944 case OMX_IndexParamCompBufferSupplier: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002945 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002946 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType =
2947 (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002948 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002949
Praveen Chavan366ded52016-04-11 17:33:02 -07002950 bufferSupplierType->nSize = sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002951 bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION;
2952 if (0 == bufferSupplierType->nPortIndex)
2953 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2954 else if (1 == bufferSupplierType->nPortIndex)
2955 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2956 else
2957 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002958
2959
Arun Menon906de572013-06-18 17:01:40 -07002960 break;
2961 }
2962 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002963 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x",
Arun Menon906de572013-06-18 17:01:40 -07002964 paramIndex);
2965 break;
2966 }
2967 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002968 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002969 paramIndex);
2970 break;
2971 }
2972 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002973 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002974 paramIndex);
2975 break;
2976 }
2977 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002978 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002979 paramIndex);
2980 break;
2981 }
2982 case OMX_IndexParamVideoProfileLevelQuerySupported: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002983 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002984 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07002985 OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType =
2986 (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData;
2987 eRet = get_supported_profile_level_for_1080p(profileLevelType);
2988 break;
2989 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002990#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07002991 case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002992 VALIDATE_OMX_PARAM_DATA(paramData, GetAndroidNativeBufferUsageParams);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002993 DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage");
Arun Menon906de572013-06-18 17:01:40 -07002994 GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData;
2995 if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07002996
Arun Menon906de572013-06-18 17:01:40 -07002997 if (secure_mode) {
2998 nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED |
2999 GRALLOC_USAGE_PRIVATE_UNCACHED);
3000 } else {
3001 nativeBuffersUsage->nUsage =
3002 (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP |
3003 GRALLOC_USAGE_PRIVATE_UNCACHED);
3004 }
3005 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003006 DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!");
Arun Menon906de572013-06-18 17:01:40 -07003007 eRet = OMX_ErrorBadParameter;
3008 }
3009 }
3010 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003011#endif
3012
Praveen Chavan09a82b72014-10-18 09:09:45 -07003013#ifdef FLEXYUV_SUPPORTED
3014 case OMX_QcomIndexFlexibleYUVDescription: {
3015 DEBUG_PRINT_LOW("get_parameter: describeColorFormat");
Praveen Chavan366ded52016-04-11 17:33:02 -07003016 VALIDATE_OMX_PARAM_DATA(paramData, DescribeColorFormatParams);
Praveen Chavan09a82b72014-10-18 09:09:45 -07003017 eRet = describeColorFormat(paramData);
3018 break;
3019 }
3020#endif
3021
Arun Menon906de572013-06-18 17:01:40 -07003022 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003023 DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003024 eRet =OMX_ErrorUnsupportedIndex;
3025 }
3026
Shalaj Jain273b3e02012-06-22 19:08:03 -07003027 }
3028
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003029 DEBUG_PRINT_LOW("get_parameter returning WxH(%d x %d) SxSH(%d x %d)",
Arun Menon906de572013-06-18 17:01:40 -07003030 drv_ctx.video_resolution.frame_width,
3031 drv_ctx.video_resolution.frame_height,
3032 drv_ctx.video_resolution.stride,
3033 drv_ctx.video_resolution.scan_lines);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003034
Arun Menon906de572013-06-18 17:01:40 -07003035 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003036}
3037
3038#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
3039OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data)
3040{
3041 DEBUG_PRINT_LOW("Inside use_android_native_buffer");
3042 OMX_ERRORTYPE eRet = OMX_ErrorNone;
3043 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data;
3044
Arun Menon906de572013-06-18 17:01:40 -07003045 if ((params == NULL) ||
3046 (params->nativeBuffer == NULL) ||
3047 (params->nativeBuffer->handle == NULL) ||
3048 !m_enable_android_native_buffers)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003049 return OMX_ErrorBadParameter;
3050 m_use_android_native_buffers = OMX_TRUE;
3051 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
3052 private_handle_t *handle = (private_handle_t *)nBuf->handle;
Arun Menon906de572013-06-18 17:01:40 -07003053 if (OMX_CORE_OUTPUT_PORT_INDEX == params->nPortIndex) { //android native buffers can be used only on Output port
Shalaj Jain273b3e02012-06-22 19:08:03 -07003054 OMX_U8 *buffer = NULL;
Arun Menon906de572013-06-18 17:01:40 -07003055 if (!secure_mode) {
3056 buffer = (OMX_U8*)mmap(0, handle->size,
Shalaj Jain273b3e02012-06-22 19:08:03 -07003057 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
Arun Menon906de572013-06-18 17:01:40 -07003058 if (buffer == MAP_FAILED) {
3059 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
3060 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003061 }
3062 }
3063 eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer);
3064 } else {
3065 eRet = OMX_ErrorBadParameter;
3066 }
3067 return eRet;
3068}
3069#endif
Praveen Chavancf924182013-12-06 23:16:23 -08003070
3071OMX_ERRORTYPE omx_vdec::enable_smoothstreaming() {
3072 struct v4l2_control control;
3073 struct v4l2_format fmt;
3074 control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER;
3075 control.value = 1;
3076 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3077 if (rc < 0) {
3078 DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver.");
3079 return OMX_ErrorHardware;
3080 }
3081 m_smoothstreaming_mode = true;
3082 return OMX_ErrorNone;
3083}
3084
Shalaj Jain273b3e02012-06-22 19:08:03 -07003085/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003086 FUNCTION
3087 omx_vdec::Setparameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07003088
Arun Menon906de572013-06-18 17:01:40 -07003089 DESCRIPTION
3090 OMX Set Parameter method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003091
Arun Menon906de572013-06-18 17:01:40 -07003092 PARAMETERS
3093 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003094
Arun Menon906de572013-06-18 17:01:40 -07003095 RETURN VALUE
3096 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003097
Arun Menon906de572013-06-18 17:01:40 -07003098 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003099OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003100 OMX_IN OMX_INDEXTYPE paramIndex,
3101 OMX_IN OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003102{
3103 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Praneeth Paladugu226667c2012-09-12 16:42:30 -07003104 int ret=0;
3105 struct v4l2_format fmt;
Arun Menon906de572013-06-18 17:01:40 -07003106 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003107 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003108 return OMX_ErrorInvalidState;
3109 }
Arun Menon906de572013-06-18 17:01:40 -07003110 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003111 DEBUG_PRINT_ERROR("Get Param in Invalid paramData");
Arun Menon906de572013-06-18 17:01:40 -07003112 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003113 }
Arun Menon906de572013-06-18 17:01:40 -07003114 if ((m_state != OMX_StateLoaded) &&
3115 BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) &&
3116 (m_out_bEnabled == OMX_TRUE) &&
3117 BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) &&
3118 (m_inp_bEnabled == OMX_TRUE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003119 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003120 return OMX_ErrorIncorrectStateOperation;
3121 }
Arun Menon906de572013-06-18 17:01:40 -07003122 switch ((unsigned long)paramIndex) {
3123 case OMX_IndexParamPortDefinition: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003124 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003125 OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
3126 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
3127 //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has
3128 //been called.
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003129 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d",
Arun Menon906de572013-06-18 17:01:40 -07003130 (int)portDefn->format.video.nFrameHeight,
3131 (int)portDefn->format.video.nFrameWidth);
3132 if (OMX_DirOutput == portDefn->eDir) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003133 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port");
Pushkaraj Patil41588352014-02-25 20:51:34 +05303134 bool port_format_changed = false;
Arun Menon906de572013-06-18 17:01:40 -07003135 m_display_id = portDefn->format.video.pNativeWindow;
3136 unsigned int buffer_size;
Praveen Chavane78460c2013-12-06 23:16:04 -08003137 /* update output port resolution with client supplied dimensions
3138 in case scaling is enabled, else it follows input resolution set
3139 */
3140 if (is_down_scalar_enabled) {
3141 DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n",
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003142 portDefn->format.video.nFrameWidth,
3143 portDefn->format.video.nFrameHeight);
3144 if (portDefn->format.video.nFrameHeight != 0x0 &&
3145 portDefn->format.video.nFrameWidth != 0x0) {
Pushkaraj Patil41588352014-02-25 20:51:34 +05303146 memset(&fmt, 0x0, sizeof(struct v4l2_format));
3147 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3148 fmt.fmt.pix_mp.pixelformat = capture_capability;
3149 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
3150 if (ret) {
3151 DEBUG_PRINT_ERROR("Get Resolution failed");
3152 eRet = OMX_ErrorHardware;
3153 break;
3154 }
3155 if ((portDefn->format.video.nFrameHeight != (int)fmt.fmt.pix_mp.height) ||
3156 (portDefn->format.video.nFrameWidth != (int)fmt.fmt.pix_mp.width)) {
3157 port_format_changed = true;
3158 }
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003159 update_resolution(portDefn->format.video.nFrameWidth,
3160 portDefn->format.video.nFrameHeight,
3161 portDefn->format.video.nFrameWidth,
3162 portDefn->format.video.nFrameHeight);
Pushkaraj Patil41588352014-02-25 20:51:34 +05303163
3164 /* set crop info */
3165 rectangle.nLeft = 0;
3166 rectangle.nTop = 0;
3167 rectangle.nWidth = portDefn->format.video.nFrameWidth;
3168 rectangle.nHeight = portDefn->format.video.nFrameHeight;
3169
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003170 eRet = is_video_session_supported();
3171 if (eRet)
3172 break;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303173 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003174 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3175 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3176 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3177 fmt.fmt.pix_mp.pixelformat = capture_capability;
3178 DEBUG_PRINT_LOW("\n fmt.fmt.pix_mp.height = %d , fmt.fmt.pix_mp.width = %d \n",fmt.fmt.pix_mp.height,fmt.fmt.pix_mp.width);
3179 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3180 if (ret) {
3181 DEBUG_PRINT_ERROR("\n Set Resolution failed");
3182 eRet = OMX_ErrorUnsupportedSetting;
3183 } else
3184 eRet = get_buffer_req(&drv_ctx.op_buf);
3185 }
Praveen Chavane78460c2013-12-06 23:16:04 -08003186 }
Praveen Chavan88256fe2016-04-11 17:32:45 -07003187 if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) {
3188 DEBUG_PRINT_ERROR("Requested o/p buf count (%u) exceeds limit (%u)",
3189 portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS);
3190 eRet = OMX_ErrorBadParameter;
3191 } else if (!client_buffers.get_buffer_req(buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003192 DEBUG_PRINT_ERROR("Error in getting buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07003193 eRet = OMX_ErrorBadParameter;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303194 } else if (!port_format_changed) {
Praveen Chavan88256fe2016-04-11 17:32:45 -07003195
3196 // Buffer count can change only when port is disabled
3197 if (!release_output_done()) {
3198 DEBUG_PRINT_ERROR("Cannot change o/p buffer count since all buffers are not freed yet !");
3199 eRet = OMX_ErrorInvalidState;
3200 break;
3201 }
3202
Arun Menon906de572013-06-18 17:01:40 -07003203 if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount &&
3204 portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) {
3205 drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual;
3206 drv_ctx.op_buf.buffer_size = portDefn->nBufferSize;
3207 drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount;
3208 drv_ctx.extradata_info.size = drv_ctx.extradata_info.count *
3209 drv_ctx.extradata_info.buffer_size;
3210 eRet = set_buffer_req(&drv_ctx.op_buf);
3211 if (eRet == OMX_ErrorNone)
3212 m_port_def = *portDefn;
3213 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003214 DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003215 drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size,
3216 portDefn->nBufferCountActual, portDefn->nBufferSize);
3217 eRet = OMX_ErrorBadParameter;
3218 }
3219 }
3220 } else if (OMX_DirInput == portDefn->eDir) {
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003221 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port");
Arun Menon906de572013-06-18 17:01:40 -07003222 bool port_format_changed = false;
3223 if ((portDefn->format.video.xFramerate >> 16) > 0 &&
3224 (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) {
3225 // Frame rate only should be set if this is a "known value" or to
3226 // activate ts prediction logic (arbitrary mode only) sending input
3227 // timestamps with max value (LLONG_MAX).
3228 DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu",
3229 portDefn->format.video.xFramerate >> 16);
3230 Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator,
3231 drv_ctx.frame_rate.fps_denominator);
3232 if (!drv_ctx.frame_rate.fps_numerator) {
3233 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
3234 drv_ctx.frame_rate.fps_numerator = 30;
3235 }
3236 if (drv_ctx.frame_rate.fps_denominator)
3237 drv_ctx.frame_rate.fps_numerator = (int)
3238 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
3239 drv_ctx.frame_rate.fps_denominator = 1;
3240 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
3241 drv_ctx.frame_rate.fps_numerator;
3242 DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)",
3243 frm_int, drv_ctx.frame_rate.fps_numerator /
3244 (float)drv_ctx.frame_rate.fps_denominator);
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003245
3246 struct v4l2_outputparm oparm;
3247 /*XXX: we're providing timing info as seconds per frame rather than frames
3248 * per second.*/
3249 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
3250 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
3251
3252 struct v4l2_streamparm sparm;
3253 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
3254 sparm.parm.output = oparm;
3255 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
3256 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, performance might be affected");
3257 eRet = OMX_ErrorHardware;
3258 break;
3259 }
Arun Menon906de572013-06-18 17:01:40 -07003260 }
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003261
Arun Menon906de572013-06-18 17:01:40 -07003262 if (drv_ctx.video_resolution.frame_height !=
3263 portDefn->format.video.nFrameHeight ||
3264 drv_ctx.video_resolution.frame_width !=
3265 portDefn->format.video.nFrameWidth) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003266 DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003267 portDefn->format.video.nFrameWidth,
3268 portDefn->format.video.nFrameHeight);
3269 port_format_changed = true;
Praveen Chavancf924182013-12-06 23:16:23 -08003270 OMX_U32 frameWidth = portDefn->format.video.nFrameWidth;
3271 OMX_U32 frameHeight = portDefn->format.video.nFrameHeight;
3272 if (frameHeight != 0x0 && frameWidth != 0x0) {
3273 if (m_smoothstreaming_mode &&
3274 ((frameWidth * frameHeight) <
3275 (m_smoothstreaming_width * m_smoothstreaming_height))) {
3276 frameWidth = m_smoothstreaming_width;
3277 frameHeight = m_smoothstreaming_height;
3278 DEBUG_PRINT_LOW("NOTE: Setting resolution %lu x %lu for adaptive-playback/smooth-streaming",
3279 frameWidth, frameHeight);
3280 }
3281 update_resolution(frameWidth, frameHeight,
3282 frameWidth, frameHeight);
Arun Menon906de572013-06-18 17:01:40 -07003283 eRet = is_video_session_supported();
3284 if (eRet)
3285 break;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303286 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Arun Menon906de572013-06-18 17:01:40 -07003287 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
3288 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3289 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3290 fmt.fmt.pix_mp.pixelformat = output_capability;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003291 DEBUG_PRINT_LOW("fmt.fmt.pix_mp.height = %d , fmt.fmt.pix_mp.width = %d",fmt.fmt.pix_mp.height,fmt.fmt.pix_mp.width);
Arun Menon906de572013-06-18 17:01:40 -07003292 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3293 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003294 DEBUG_PRINT_ERROR("Set Resolution failed");
Arun Menon906de572013-06-18 17:01:40 -07003295 eRet = OMX_ErrorUnsupportedSetting;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303296 } else {
3297 if (!is_down_scalar_enabled)
3298 eRet = get_buffer_req(&drv_ctx.op_buf);
3299 }
Arun Menon906de572013-06-18 17:01:40 -07003300 }
3301 }
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303302 if (m_custom_buffersize.input_buffersize
3303 && (portDefn->nBufferSize > m_custom_buffersize.input_buffersize)) {
3304 DEBUG_PRINT_ERROR("ERROR: Custom buffer size set by client: %d, trying to set: %d",
3305 m_custom_buffersize.input_buffersize, portDefn->nBufferSize);
3306 eRet = OMX_ErrorBadParameter;
3307 break;
3308 }
Praveen Chavan88256fe2016-04-11 17:32:45 -07003309 if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) {
3310 DEBUG_PRINT_ERROR("Requested i/p buf count (%u) exceeds limit (%u)",
3311 portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS);
3312 eRet = OMX_ErrorBadParameter;
3313 break;
3314 }
3315 // Buffer count can change only when port is disabled
3316 if (!release_input_done()) {
3317 DEBUG_PRINT_ERROR("Cannot change i/p buffer count since all buffers are not freed yet !");
3318 eRet = OMX_ErrorInvalidState;
3319 break;
3320 }
3321
Arun Menon906de572013-06-18 17:01:40 -07003322 if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount
3323 || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) {
3324 port_format_changed = true;
3325 vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf;
3326 drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual;
3327 drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) &
3328 (~(buffer_prop->alignment - 1));
3329 eRet = set_buffer_req(buffer_prop);
3330 }
3331 if (false == port_format_changed) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003332 DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003333 drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size,
3334 portDefn->nBufferCountActual, portDefn->nBufferSize);
3335 eRet = OMX_ErrorBadParameter;
3336 }
3337 } else if (portDefn->eDir == OMX_DirMax) {
3338 DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d",
3339 (int)portDefn->nPortIndex);
3340 eRet = OMX_ErrorBadPortIndex;
3341 }
3342 }
3343 break;
3344 case OMX_IndexParamVideoPortFormat: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003345 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003346 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
3347 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
3348 int ret=0;
3349 struct v4l2_format fmt;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003350 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d",
Arun Menon906de572013-06-18 17:01:40 -07003351 portFmt->eColorFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003352
Arun Menon906de572013-06-18 17:01:40 -07003353 if (1 == portFmt->nPortIndex) {
3354 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3355 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3356 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3357 fmt.fmt.pix_mp.pixelformat = capture_capability;
3358 enum vdec_output_fromat op_format;
3359 if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE)
3360 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) ||
Praveen Chavandb7776f2014-02-06 18:17:25 -08003361 (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar) ||
3362 (portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar))
Arun Menon906de572013-06-18 17:01:40 -07003363 op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12;
Arun Menon906de572013-06-18 17:01:40 -07003364 else
3365 eRet = OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003366
Arun Menon906de572013-06-18 17:01:40 -07003367 if (eRet == OMX_ErrorNone) {
3368 drv_ctx.output_format = op_format;
3369 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3370 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003371 DEBUG_PRINT_ERROR("Set output format failed");
Arun Menon906de572013-06-18 17:01:40 -07003372 eRet = OMX_ErrorUnsupportedSetting;
3373 /*TODO: How to handle this case */
3374 } else {
3375 eRet = get_buffer_req(&drv_ctx.op_buf);
3376 }
3377 }
3378 if (eRet == OMX_ErrorNone) {
3379 if (!client_buffers.set_color_format(portFmt->eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003380 DEBUG_PRINT_ERROR("Set color format failed");
Arun Menon906de572013-06-18 17:01:40 -07003381 eRet = OMX_ErrorBadParameter;
3382 }
3383 }
3384 }
3385 }
3386 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003387
Arun Menon906de572013-06-18 17:01:40 -07003388 case OMX_QcomIndexPortDefn: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003389 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003390 OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt =
3391 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003392 DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu",
Arun Menon906de572013-06-18 17:01:40 -07003393 portFmt->nFramePackingFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003394
Arun Menon906de572013-06-18 17:01:40 -07003395 /* Input port */
3396 if (portFmt->nPortIndex == 0) {
3397 if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) {
3398 if (secure_mode) {
3399 arbitrary_bytes = false;
3400 DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session");
3401 eRet = OMX_ErrorUnsupportedSetting;
3402 } else {
3403 arbitrary_bytes = true;
3404 }
3405 } else if (portFmt->nFramePackingFormat ==
3406 OMX_QCOM_FramePacking_OnlyOneCompleteFrame) {
3407 arbitrary_bytes = false;
3408 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003409 DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu",
Arun Menon906de572013-06-18 17:01:40 -07003410 portFmt->nFramePackingFormat);
3411 eRet = OMX_ErrorUnsupportedSetting;
3412 }
3413 } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003414 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003415 if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid &&
3416 portFmt->nMemRegion < OMX_QCOM_MemRegionMax) &&
3417 portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) {
3418 m_out_mem_region_smi = OMX_TRUE;
3419 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003420 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003421 m_use_output_pmem = OMX_TRUE;
3422 }
3423 }
3424 }
3425 }
3426 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003427
Arun Menon906de572013-06-18 17:01:40 -07003428 case OMX_IndexParamStandardComponentRole: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003429 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE);
Arun Menon906de572013-06-18 17:01:40 -07003430 OMX_PARAM_COMPONENTROLETYPE *comp_role;
3431 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003432 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s",
Arun Menon906de572013-06-18 17:01:40 -07003433 comp_role->cRole);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003434
Arun Menon906de572013-06-18 17:01:40 -07003435 if ((m_state == OMX_StateLoaded)&&
3436 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
3437 DEBUG_PRINT_LOW("Set Parameter called in valid state");
3438 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003439 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003440 return OMX_ErrorIncorrectStateOperation;
3441 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003442
Arun Menon906de572013-06-18 17:01:40 -07003443 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3444 if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3445 strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
3446 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003447 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003448 eRet =OMX_ErrorUnsupportedSetting;
3449 }
3450 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3451 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3452 strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
3453 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003454 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003455 eRet = OMX_ErrorUnsupportedSetting;
3456 }
3457 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3458 if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3459 strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
3460 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003461 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003462 eRet =OMX_ErrorUnsupportedSetting;
3463 }
3464 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3465 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3466 strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
3467 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003468 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003469 eRet = OMX_ErrorUnsupportedSetting;
3470 }
3471 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
Deva Ramasubramanianba4534b2013-12-17 15:52:37 -08003472 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311", OMX_MAX_STRINGNAME_SIZE)) ||
3473 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4", OMX_MAX_STRINGNAME_SIZE))
Arun Menon906de572013-06-18 17:01:40 -07003474 ) {
3475 if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) {
3476 strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
3477 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003478 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003479 eRet =OMX_ErrorUnsupportedSetting;
3480 }
3481 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
3482 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
3483 ) {
3484 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) {
3485 strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
3486 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003487 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003488 eRet =OMX_ErrorUnsupportedSetting;
3489 }
3490 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
3491 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) ||
3492 (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) {
3493 strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
3494 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003495 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003496 eRet = OMX_ErrorUnsupportedSetting;
3497 }
3498 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003499 DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07003500 eRet = OMX_ErrorInvalidComponentName;
3501 }
3502 break;
3503 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003504
Arun Menon906de572013-06-18 17:01:40 -07003505 case OMX_IndexParamPriorityMgmt: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003506 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003507 if (m_state != OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003508 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003509 return OMX_ErrorIncorrectStateOperation;
3510 }
3511 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003512 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu",
Arun Menon906de572013-06-18 17:01:40 -07003513 priorityMgmtype->nGroupID);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003514
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003515 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu",
Arun Menon906de572013-06-18 17:01:40 -07003516 priorityMgmtype->nGroupPriority);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003517
Arun Menon906de572013-06-18 17:01:40 -07003518 m_priority_mgm.nGroupID = priorityMgmtype->nGroupID;
3519 m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003520
Arun Menon906de572013-06-18 17:01:40 -07003521 break;
3522 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003523
Arun Menon906de572013-06-18 17:01:40 -07003524 case OMX_IndexParamCompBufferSupplier: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003525 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003526 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003527 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d",
Arun Menon906de572013-06-18 17:01:40 -07003528 bufferSupplierType->eBufferSupplier);
3529 if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
3530 m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003531
Arun Menon906de572013-06-18 17:01:40 -07003532 else
Shalaj Jain273b3e02012-06-22 19:08:03 -07003533
Arun Menon906de572013-06-18 17:01:40 -07003534 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003535
Arun Menon906de572013-06-18 17:01:40 -07003536 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003537
Arun Menon906de572013-06-18 17:01:40 -07003538 }
3539 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003540 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d",
Arun Menon906de572013-06-18 17:01:40 -07003541 paramIndex);
3542 break;
3543 }
3544 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003545 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d",
Arun Menon906de572013-06-18 17:01:40 -07003546 paramIndex);
3547 break;
3548 }
3549 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003550 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d",
Arun Menon906de572013-06-18 17:01:40 -07003551 paramIndex);
3552 break;
3553 }
3554 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003555 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d",
Arun Menon906de572013-06-18 17:01:40 -07003556 paramIndex);
3557 break;
3558 }
3559 case OMX_QcomIndexParamVideoDecoderPictureOrder: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003560 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_DECODER_PICTURE_ORDER);
Arun Menon906de572013-06-18 17:01:40 -07003561 QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder =
3562 (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData;
3563 struct v4l2_control control;
3564 int pic_order,rc=0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003565 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d",
Arun Menon906de572013-06-18 17:01:40 -07003566 pictureOrder->eOutputPictureOrder);
3567 if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) {
3568 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
3569 } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) {
3570 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3571 time_stamp_dts.set_timestamp_reorder_mode(false);
3572 } else
3573 eRet = OMX_ErrorBadParameter;
3574 if (eRet == OMX_ErrorNone) {
3575 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3576 control.value = pic_order;
3577 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3578 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003579 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003580 eRet = OMX_ErrorUnsupportedSetting;
3581 }
3582 }
3583 break;
3584 }
3585 case OMX_QcomIndexParamConcealMBMapExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003586 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303587 eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false,
3588 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3589 break;
3590 case OMX_QcomIndexParamFrameInfoExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003591 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303592 eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false,
3593 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3594 break;
Arun Menon906de572013-06-18 17:01:40 -07003595 case OMX_QcomIndexParamInterlaceExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003596 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303597 eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false,
3598 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3599 break;
Arun Menon906de572013-06-18 17:01:40 -07003600 case OMX_QcomIndexParamH264TimeInfo:
Praveen Chavan366ded52016-04-11 17:33:02 -07003601 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303602 eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false,
3603 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3604 break;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05303605 case OMX_QcomIndexParamVideoFramePackingExtradata:
Praveen Chavan366ded52016-04-11 17:33:02 -07003606 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303607 eRet = enable_extradata(OMX_FRAMEPACK_EXTRADATA, false,
3608 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3609 break;
3610 case OMX_QcomIndexParamVideoQPExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003611 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303612 eRet = enable_extradata(OMX_QP_EXTRADATA, false,
3613 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3614 break;
3615 case OMX_QcomIndexParamVideoInputBitsInfoExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003616 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303617 eRet = enable_extradata(OMX_BITSINFO_EXTRADATA, false,
3618 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3619 break;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05303620 case OMX_QcomIndexEnableExtnUserData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003621 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05303622 eRet = enable_extradata(OMX_EXTNUSER_EXTRADATA, false,
3623 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3624 break;
Arun Menon906de572013-06-18 17:01:40 -07003625 case OMX_QcomIndexParamVideoDivx: {
3626 QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData;
3627 }
3628 break;
3629 case OMX_QcomIndexPlatformPvt: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003630 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PLATFORMPRIVATE_EXTN);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003631 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003632 OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData;
3633 if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
3634 DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type);
3635 eRet = OMX_ErrorUnsupportedSetting;
3636 } else {
3637 m_out_pvt_entry_pmem = OMX_TRUE;
3638 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003639 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003640 m_use_output_pmem = OMX_TRUE;
3641 }
3642 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003643
Arun Menon906de572013-06-18 17:01:40 -07003644 }
3645 break;
3646 case OMX_QcomIndexParamVideoSyncFrameDecodingMode: {
3647 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode");
3648 DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode");
3649 struct v4l2_control control;
3650 int rc;
3651 drv_ctx.idr_only_decoding = 1;
3652 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3653 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3654 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3655 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003656 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003657 eRet = OMX_ErrorUnsupportedSetting;
3658 } else {
3659 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE;
3660 control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE;
3661 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3662 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003663 DEBUG_PRINT_ERROR("Sync frame setting failed");
Arun Menon906de572013-06-18 17:01:40 -07003664 eRet = OMX_ErrorUnsupportedSetting;
3665 }
3666 /*Setting sync frame decoding on driver might change buffer
3667 * requirements so update them here*/
3668 if (get_buffer_req(&drv_ctx.ip_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003669 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer i/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003670 eRet = OMX_ErrorUnsupportedSetting;
3671 }
3672 if (get_buffer_req(&drv_ctx.op_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003673 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer o/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003674 eRet = OMX_ErrorUnsupportedSetting;
3675 }
3676 }
3677 }
3678 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003679
Arun Menon906de572013-06-18 17:01:40 -07003680 case OMX_QcomIndexParamIndexExtraDataType: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003681 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXEXTRADATATYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303682 QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData;
3683 if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) &&
3684 (extradataIndexType->bEnabled == OMX_TRUE) &&
3685 (extradataIndexType->nPortIndex == 1)) {
3686 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming");
3687 eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled);
3688 }
3689 }
Arun Menon906de572013-06-18 17:01:40 -07003690 break;
3691 case OMX_QcomIndexParamEnableSmoothStreaming: {
Arun Menonc821d8a2013-06-15 10:03:29 -07003692#ifndef SMOOTH_STREAMING_DISABLED
Praveen Chavancf924182013-12-06 23:16:23 -08003693 eRet = enable_smoothstreaming();
Arun Menonbc0922f2013-06-24 13:02:15 -07003694#else
Arun Menon906de572013-06-18 17:01:40 -07003695 eRet = OMX_ErrorUnsupportedSetting;
Arun Menonc821d8a2013-06-15 10:03:29 -07003696#endif
Arun Menon906de572013-06-18 17:01:40 -07003697 }
3698 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003699#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07003700 /* Need to allow following two set_parameters even in Idle
3701 * state. This is ANDROID architecture which is not in sync
3702 * with openmax standard. */
3703 case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003704 VALIDATE_OMX_PARAM_DATA(paramData, EnableAndroidNativeBuffersParams);
Arun Menon906de572013-06-18 17:01:40 -07003705 EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData;
3706 if (enableNativeBuffers) {
3707 m_enable_android_native_buffers = enableNativeBuffers->enable;
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07003708 }
Praveen Chavancac86402014-10-18 09:14:52 -07003709#if !defined(FLEXYUV_SUPPORTED)
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07003710 if (m_enable_android_native_buffers) {
3711 // Use the most-preferred-native-color-format as surface-mode is hinted here
3712 if(!client_buffers.set_color_format(getPreferredColorFormatDefaultMode(0))) {
3713 DEBUG_PRINT_ERROR("Failed to set native color format!");
3714 eRet = OMX_ErrorUnsupportedSetting;
3715 }
Arun Menon906de572013-06-18 17:01:40 -07003716 }
Praveen Chavancac86402014-10-18 09:14:52 -07003717#endif
Arun Menon906de572013-06-18 17:01:40 -07003718 }
3719 break;
3720 case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003721 VALIDATE_OMX_PARAM_DATA(paramData, UseAndroidNativeBufferParams);
Arun Menon906de572013-06-18 17:01:40 -07003722 eRet = use_android_native_buffer(hComp, paramData);
3723 }
3724 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003725#endif
Arun Menon906de572013-06-18 17:01:40 -07003726 case OMX_QcomIndexParamEnableTimeStampReorder: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003727 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXTIMESTAMPREORDER);
Arun Menon906de572013-06-18 17:01:40 -07003728 QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData;
3729 if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) {
3730 if (reorder->bEnable == OMX_TRUE) {
3731 frm_int =0;
3732 time_stamp_dts.set_timestamp_reorder_mode(true);
3733 } else
3734 time_stamp_dts.set_timestamp_reorder_mode(false);
3735 } else {
3736 time_stamp_dts.set_timestamp_reorder_mode(false);
3737 if (reorder->bEnable == OMX_TRUE) {
3738 eRet = OMX_ErrorUnsupportedSetting;
3739 }
3740 }
3741 }
3742 break;
3743 case OMX_IndexParamVideoProfileLevelCurrent: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003744 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003745 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam =
3746 (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
3747 if (pParam) {
3748 m_profile_lvl.eProfile = pParam->eProfile;
3749 m_profile_lvl.eLevel = pParam->eLevel;
3750 }
3751 break;
Arun Menon888aa852013-05-30 11:24:42 -07003752
Arun Menon906de572013-06-18 17:01:40 -07003753 }
Arun Menone5652482013-08-04 13:33:05 -07003754 case OMX_QcomIndexParamVideoMetaBufferMode:
3755 {
Praveen Chavan366ded52016-04-11 17:33:02 -07003756 VALIDATE_OMX_PARAM_DATA(paramData, StoreMetaDataInBuffersParams);
Arun Menone5652482013-08-04 13:33:05 -07003757 StoreMetaDataInBuffersParams *metabuffer =
3758 (StoreMetaDataInBuffersParams *)paramData;
3759 if (!metabuffer) {
3760 DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer);
3761 eRet = OMX_ErrorBadParameter;
3762 break;
3763 }
3764 if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
3765 //set property dynamic buffer mode to driver.
3766 struct v4l2_control control;
3767 struct v4l2_format fmt;
3768 control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT;
3769 if (metabuffer->bStoreMetaData == true) {
3770 control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC;
3771 } else {
3772 control.value = V4L2_MPEG_VIDC_VIDEO_STATIC;
3773 }
3774 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3775 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003776 DEBUG_PRINT_HIGH("%s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003777 (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic");
Arun Menonbdb80b02013-08-12 17:45:54 -07003778 dynamic_buf_mode = metabuffer->bStoreMetaData;
Arun Menone5652482013-08-04 13:33:05 -07003779 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003780 DEBUG_PRINT_ERROR("Failed to %s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003781 (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic");
3782 eRet = OMX_ErrorUnsupportedSetting;
3783 }
3784 } else {
3785 DEBUG_PRINT_ERROR(
Praveen Chavancf924182013-12-06 23:16:23 -08003786 "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %lu",
Arun Menone5652482013-08-04 13:33:05 -07003787 metabuffer->nPortIndex);
3788 eRet = OMX_ErrorUnsupportedSetting;
3789 }
3790 break;
3791 }
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003792 case OMX_QcomIndexParamVideoDownScalar: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003793 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXDOWNSCALAR);
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003794 QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData;
3795 struct v4l2_control control;
3796 int rc;
3797 if (pParam) {
3798 is_down_scalar_enabled = pParam->bEnable;
3799 if (is_down_scalar_enabled) {
3800 control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE;
3801 control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY;
3802 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n",
3803 pParam->bEnable);
3804 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3805 if (rc < 0) {
3806 DEBUG_PRINT_ERROR("Failed to set down scalar on driver.");
3807 eRet = OMX_ErrorUnsupportedSetting;
3808 }
3809 control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO;
3810 control.value = 1;
3811 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3812 if (rc < 0) {
3813 DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver.");
3814 eRet = OMX_ErrorUnsupportedSetting;
3815 }
3816 }
3817 }
3818 break;
3819 }
Praveen Chavancf924182013-12-06 23:16:23 -08003820#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
3821 case OMX_QcomIndexParamVideoAdaptivePlaybackMode:
3822 {
Praveen Chavan366ded52016-04-11 17:33:02 -07003823 VALIDATE_OMX_PARAM_DATA(paramData, PrepareForAdaptivePlaybackParams);
Praveen Chavancf924182013-12-06 23:16:23 -08003824 DEBUG_PRINT_LOW("set_parameter: OMX_GoogleAndroidIndexPrepareForAdaptivePlayback");
3825 PrepareForAdaptivePlaybackParams* pParams =
3826 (PrepareForAdaptivePlaybackParams *) paramData;
3827 if (pParams->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
3828 if (!pParams->bEnable) {
3829 return OMX_ErrorNone;
3830 }
Deepak Vermaa2efdb12013-12-26 12:30:05 +05303831 if (pParams->nMaxFrameWidth > maxSmoothStreamingWidth
3832 || pParams->nMaxFrameHeight > maxSmoothStreamingHeight) {
Praveen Chavancf924182013-12-06 23:16:23 -08003833 DEBUG_PRINT_ERROR(
3834 "Adaptive playback request exceeds max supported resolution : [%lu x %lu] vs [%lu x %lu]",
3835 pParams->nMaxFrameWidth, pParams->nMaxFrameHeight,
Deepak Vermaa2efdb12013-12-26 12:30:05 +05303836 maxSmoothStreamingWidth, maxSmoothStreamingHeight);
Praveen Chavancf924182013-12-06 23:16:23 -08003837 eRet = OMX_ErrorBadParameter;
3838 } else {
Arun Menon1fc764f2014-04-17 15:41:27 -07003839 eRet = enable_adaptive_playback(pParams->nMaxFrameWidth, pParams->nMaxFrameHeight);
3840 }
Praveen Chavancf924182013-12-06 23:16:23 -08003841 } else {
3842 DEBUG_PRINT_ERROR(
3843 "Prepare for adaptive playback supported only on output port");
3844 eRet = OMX_ErrorBadParameter;
3845 }
3846 break;
3847 }
3848
3849#endif
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303850 case OMX_QcomIndexParamVideoCustomBufferSize:
3851 {
Praveen Chavan366ded52016-04-11 17:33:02 -07003852 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_CUSTOM_BUFFERSIZE);
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303853 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoCustomBufferSize");
3854 QOMX_VIDEO_CUSTOM_BUFFERSIZE* pParam = (QOMX_VIDEO_CUSTOM_BUFFERSIZE*)paramData;
3855 if (pParam->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) {
3856 struct v4l2_control control;
3857 control.id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT;
3858 control.value = pParam->nBufferSize;
3859 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
3860 DEBUG_PRINT_ERROR("Failed to set input buffer size");
3861 eRet = OMX_ErrorUnsupportedSetting;
3862 } else {
3863 eRet = get_buffer_req(&drv_ctx.ip_buf);
3864 if (eRet == OMX_ErrorNone) {
3865 m_custom_buffersize.input_buffersize = drv_ctx.ip_buf.buffer_size;
3866 DEBUG_PRINT_HIGH("Successfully set custom input buffer size = %d",
3867 m_custom_buffersize.input_buffersize);
3868 } else {
3869 DEBUG_PRINT_ERROR("Failed to get buffer requirement");
3870 }
3871 }
3872 } else {
3873 DEBUG_PRINT_ERROR("ERROR: Custom buffer size in not supported on output port");
3874 eRet = OMX_ErrorBadParameter;
3875 }
3876 break;
3877 }
Arun Menon906de572013-06-18 17:01:40 -07003878 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003879 DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003880 eRet = OMX_ErrorUnsupportedIndex;
3881 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003882 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08003883 if (eRet != OMX_ErrorNone)
3884 DEBUG_PRINT_ERROR("set_parameter: Error: 0x%x, setting param 0x%x", eRet, paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003885 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003886}
3887
3888/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003889 FUNCTION
3890 omx_vdec::GetConfig
Shalaj Jain273b3e02012-06-22 19:08:03 -07003891
Arun Menon906de572013-06-18 17:01:40 -07003892 DESCRIPTION
3893 OMX Get Config Method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003894
Arun Menon906de572013-06-18 17:01:40 -07003895 PARAMETERS
3896 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003897
Arun Menon906de572013-06-18 17:01:40 -07003898 RETURN VALUE
3899 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003900
Arun Menon906de572013-06-18 17:01:40 -07003901 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003902OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003903 OMX_IN OMX_INDEXTYPE configIndex,
3904 OMX_INOUT OMX_PTR configData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003905{
Arun Menon906de572013-06-18 17:01:40 -07003906 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003907
Arun Menon906de572013-06-18 17:01:40 -07003908 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003909 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003910 return OMX_ErrorInvalidState;
3911 }
Arun Menon906de572013-06-18 17:01:40 -07003912
3913 switch ((unsigned long)configIndex) {
3914 case OMX_QcomIndexConfigInterlaced: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003915 VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_CONFIG_INTERLACETYPE);
Arun Menon906de572013-06-18 17:01:40 -07003916 OMX_QCOM_CONFIG_INTERLACETYPE *configFmt =
3917 (OMX_QCOM_CONFIG_INTERLACETYPE *) configData;
3918 if (configFmt->nPortIndex == 1) {
3919 if (configFmt->nIndex == 0) {
3920 configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive;
3921 } else if (configFmt->nIndex == 1) {
3922 configFmt->eInterlaceType =
3923 OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
3924 } else if (configFmt->nIndex == 2) {
3925 configFmt->eInterlaceType =
3926 OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
3927 } else {
3928 DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003929 " NoMore Interlaced formats");
Arun Menon906de572013-06-18 17:01:40 -07003930 eRet = OMX_ErrorNoMore;
3931 }
3932
3933 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003934 DEBUG_PRINT_ERROR("get_config: Bad port index %d queried on only o/p port",
Arun Menon906de572013-06-18 17:01:40 -07003935 (int)configFmt->nPortIndex);
3936 eRet = OMX_ErrorBadPortIndex;
3937 }
3938 break;
3939 }
3940 case OMX_QcomIndexQueryNumberOfVideoDecInstance: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003941 VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_QUERY_DECODER_INSTANCES);
Arun Menon906de572013-06-18 17:01:40 -07003942 QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances =
3943 (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData;
3944 decoderinstances->nNumOfInstances = 16;
3945 /*TODO: How to handle this case */
3946 break;
3947 }
3948 case OMX_QcomIndexConfigVideoFramePackingArrangement: {
3949 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
Praveen Chavan366ded52016-04-11 17:33:02 -07003950 VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_FRAME_PACK_ARRANGEMENT);
Arun Menon906de572013-06-18 17:01:40 -07003951 OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
3952 (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05303953 memcpy(configFmt, &m_frame_pack_arrangement,
3954 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
Arun Menon906de572013-06-18 17:01:40 -07003955 } else {
3956 DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs");
3957 }
3958 break;
3959 }
3960 case OMX_IndexConfigCommonOutputCrop: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003961 VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_RECTTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003962 OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData;
3963 memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE));
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05303964 DEBUG_PRINT_HIGH("get_config: crop info: L: %u, T: %u, R: %u, B: %u",
3965 rectangle.nLeft, rectangle.nTop,
3966 rectangle.nWidth, rectangle.nHeight);
Arun Menon906de572013-06-18 17:01:40 -07003967 break;
3968 }
3969 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003970 DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex);
Arun Menon906de572013-06-18 17:01:40 -07003971 eRet = OMX_ErrorBadParameter;
3972 }
3973
Shalaj Jain273b3e02012-06-22 19:08:03 -07003974 }
Arun Menon906de572013-06-18 17:01:40 -07003975
3976 return eRet;
3977}
3978
3979/* ======================================================================
3980 FUNCTION
3981 omx_vdec::SetConfig
3982
3983 DESCRIPTION
3984 OMX Set Config method implementation
3985
3986 PARAMETERS
3987 <TBD>.
3988
3989 RETURN VALUE
3990 OMX Error None if successful.
3991 ========================================================================== */
3992OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp,
3993 OMX_IN OMX_INDEXTYPE configIndex,
3994 OMX_IN OMX_PTR configData)
3995{
3996 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003997 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003998 return OMX_ErrorInvalidState;
3999 }
4000
4001 OMX_ERRORTYPE ret = OMX_ErrorNone;
4002 OMX_VIDEO_CONFIG_NALSIZE *pNal;
4003
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004004 DEBUG_PRINT_LOW("Set Config Called");
Arun Menon906de572013-06-18 17:01:40 -07004005
4006 if (configIndex == (OMX_INDEXTYPE)OMX_IndexVendorVideoExtraData) {
4007 OMX_VENDOR_EXTRADATATYPE *config = (OMX_VENDOR_EXTRADATATYPE *) configData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004008 DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData called");
Arun Menon906de572013-06-18 17:01:40 -07004009 if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc")) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004010 DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData AVC");
Arun Menon906de572013-06-18 17:01:40 -07004011 OMX_U32 extra_size;
4012 // Parsing done here for the AVC atom is definitely not generic
4013 // Currently this piece of code is working, but certainly
4014 // not tested with all .mp4 files.
4015 // Incase of failure, we might need to revisit this
4016 // for a generic piece of code.
4017
4018 // Retrieve size of NAL length field
4019 // byte #4 contains the size of NAL lenght field
4020 nal_length = (config->pData[4] & 0x03) + 1;
4021
4022 extra_size = 0;
4023 if (nal_length > 2) {
4024 /* Presently we assume that only one SPS and one PPS in AvC1 Atom */
4025 extra_size = (nal_length - 2) * 2;
4026 }
4027
4028 // SPS starts from byte #6
4029 OMX_U8 *pSrcBuf = (OMX_U8 *) (&config->pData[6]);
4030 OMX_U8 *pDestBuf;
4031 m_vendor_config.nPortIndex = config->nPortIndex;
4032
4033 // minus 6 --> SPS starts from byte #6
4034 // minus 1 --> picture param set byte to be ignored from avcatom
4035 m_vendor_config.nDataSize = config->nDataSize - 6 - 1 + extra_size;
4036 m_vendor_config.pData = (OMX_U8 *) malloc(m_vendor_config.nDataSize);
4037 OMX_U32 len;
4038 OMX_U8 index = 0;
4039 // case where SPS+PPS is sent as part of set_config
4040 pDestBuf = m_vendor_config.pData;
4041
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004042 DEBUG_PRINT_LOW("Rxd SPS+PPS nPortIndex[%lu] len[%lu] data[%p]",
Arun Menon906de572013-06-18 17:01:40 -07004043 m_vendor_config.nPortIndex,
4044 m_vendor_config.nDataSize,
4045 m_vendor_config.pData);
4046 while (index < 2) {
4047 uint8 *psize;
4048 len = *pSrcBuf;
4049 len = len << 8;
4050 len |= *(pSrcBuf + 1);
4051 psize = (uint8 *) & len;
4052 memcpy(pDestBuf + nal_length, pSrcBuf + 2,len);
4053 for (unsigned int i = 0; i < nal_length; i++) {
4054 pDestBuf[i] = psize[nal_length - 1 - i];
4055 }
4056 //memcpy(pDestBuf,pSrcBuf,(len+2));
4057 pDestBuf += len + nal_length;
4058 pSrcBuf += len + 2;
4059 index++;
4060 pSrcBuf++; // skip picture param set
4061 len = 0;
4062 }
4063 } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4") ||
4064 !strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2")) {
4065 m_vendor_config.nPortIndex = config->nPortIndex;
4066 m_vendor_config.nDataSize = config->nDataSize;
4067 m_vendor_config.pData = (OMX_U8 *) malloc((config->nDataSize));
4068 memcpy(m_vendor_config.pData, config->pData,config->nDataSize);
4069 } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1")) {
4070 if (m_vendor_config.pData) {
4071 free(m_vendor_config.pData);
4072 m_vendor_config.pData = NULL;
4073 m_vendor_config.nDataSize = 0;
4074 }
4075
4076 if (((*((OMX_U32 *) config->pData)) &
4077 VC1_SP_MP_START_CODE_MASK) ==
4078 VC1_SP_MP_START_CODE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004079 DEBUG_PRINT_LOW("set_config - VC1 simple/main profile");
Arun Menon906de572013-06-18 17:01:40 -07004080 m_vendor_config.nPortIndex = config->nPortIndex;
4081 m_vendor_config.nDataSize = config->nDataSize;
4082 m_vendor_config.pData =
4083 (OMX_U8 *) malloc(config->nDataSize);
4084 memcpy(m_vendor_config.pData, config->pData,
4085 config->nDataSize);
4086 m_vc1_profile = VC1_SP_MP_RCV;
4087 } else if (*((OMX_U32 *) config->pData) == VC1_AP_SEQ_START_CODE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004088 DEBUG_PRINT_LOW("set_config - VC1 Advance profile");
Arun Menon906de572013-06-18 17:01:40 -07004089 m_vendor_config.nPortIndex = config->nPortIndex;
4090 m_vendor_config.nDataSize = config->nDataSize;
4091 m_vendor_config.pData =
4092 (OMX_U8 *) malloc((config->nDataSize));
4093 memcpy(m_vendor_config.pData, config->pData,
4094 config->nDataSize);
4095 m_vc1_profile = VC1_AP;
4096 } else if ((config->nDataSize == VC1_STRUCT_C_LEN)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004097 DEBUG_PRINT_LOW("set_config - VC1 Simple/Main profile struct C only");
Arun Menon906de572013-06-18 17:01:40 -07004098 m_vendor_config.nPortIndex = config->nPortIndex;
4099 m_vendor_config.nDataSize = config->nDataSize;
4100 m_vendor_config.pData = (OMX_U8*)malloc(config->nDataSize);
4101 memcpy(m_vendor_config.pData,config->pData,config->nDataSize);
4102 m_vc1_profile = VC1_SP_MP_RCV;
4103 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004104 DEBUG_PRINT_LOW("set_config - Error: Unknown VC1 profile");
Arun Menon906de572013-06-18 17:01:40 -07004105 }
4106 }
4107 return ret;
4108 } else if (configIndex == OMX_IndexConfigVideoNalSize) {
4109 struct v4l2_control temp;
4110 temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT;
4111
Praveen Chavan366ded52016-04-11 17:33:02 -07004112 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_NALSIZE);
Arun Menon906de572013-06-18 17:01:40 -07004113 pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData);
4114 switch (pNal->nNaluBytes) {
4115 case 0:
4116 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES;
4117 break;
4118 case 2:
4119 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH;
4120 break;
4121 case 4:
4122 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH;
4123 break;
4124 default:
4125 return OMX_ErrorUnsupportedSetting;
4126 }
4127
4128 if (!arbitrary_bytes) {
4129 /* In arbitrary bytes mode, the assembler strips out nal size and replaces
4130 * with start code, so only need to notify driver in frame by frame mode */
4131 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) {
4132 DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT");
4133 return OMX_ErrorHardware;
4134 }
4135 }
4136
4137 nal_length = pNal->nNaluBytes;
4138 m_frame_parser.init_nal_length(nal_length);
4139
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004140 DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length);
Arun Menon906de572013-06-18 17:01:40 -07004141 return ret;
Surajit Podderd2644d52013-08-28 17:59:06 +05304142 } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) {
Arun Menon906de572013-06-18 17:01:40 -07004143 OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData;
Surajit Podderd2644d52013-08-28 17:59:06 +05304144 DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps);
Arun Menon906de572013-06-18 17:01:40 -07004145
4146 if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) {
4147 if (config->bEnabled) {
4148 if ((config->nFps >> 16) > 0) {
Surajit Podderd2644d52013-08-28 17:59:06 +05304149 DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu",
Arun Menon906de572013-06-18 17:01:40 -07004150 config->nFps >> 16);
4151 Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator,
4152 drv_ctx.frame_rate.fps_denominator);
4153
4154 if (!drv_ctx.frame_rate.fps_numerator) {
4155 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
4156 drv_ctx.frame_rate.fps_numerator = 30;
4157 }
4158
4159 if (drv_ctx.frame_rate.fps_denominator) {
4160 drv_ctx.frame_rate.fps_numerator = (int)
4161 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
4162 }
4163
4164 drv_ctx.frame_rate.fps_denominator = 1;
4165 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
4166 drv_ctx.frame_rate.fps_numerator;
4167
4168 struct v4l2_outputparm oparm;
4169 /*XXX: we're providing timing info as seconds per frame rather than frames
4170 * per second.*/
4171 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
4172 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
4173
4174 struct v4l2_streamparm sparm;
4175 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
4176 sparm.parm.output = oparm;
4177 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
4178 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
4179 performance might be affected");
4180 ret = OMX_ErrorHardware;
4181 }
4182 client_set_fps = true;
4183 } else {
4184 DEBUG_PRINT_ERROR("Frame rate not supported.");
4185 ret = OMX_ErrorUnsupportedSetting;
4186 }
4187 } else {
4188 DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate");
4189 client_set_fps = false;
4190 }
4191 } else {
4192 DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d",
4193 (int)config->nPortIndex);
4194 ret = OMX_ErrorBadPortIndex;
4195 }
4196
4197 return ret;
Praveen Chavan898df262015-04-20 18:52:19 -07004198 } else if ((int)configIndex == (int)OMX_IndexConfigPriority) {
4199 OMX_PARAM_U32TYPE *priority = (OMX_PARAM_U32TYPE *)configData;
4200 DEBUG_PRINT_LOW("Set_config: priority %d", priority->nU32);
4201
4202 struct v4l2_control control;
4203
4204 control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY;
4205 if (priority->nU32 == 0)
4206 control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_ENABLE;
4207 else
4208 control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE;
4209
4210 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
4211 DEBUG_PRINT_ERROR("Failed to set Priority");
4212 ret = OMX_ErrorUnsupportedSetting;
4213 }
4214 return ret;
Praveen Chavan281d5022015-04-30 20:28:44 -07004215 } else if ((int)configIndex == (int)OMX_IndexConfigOperatingRate) {
4216 OMX_PARAM_U32TYPE *rate = (OMX_PARAM_U32TYPE *)configData;
4217 DEBUG_PRINT_LOW("Set_config: operating-rate %u fps", rate->nU32 >> 16);
4218
4219 struct v4l2_control control;
4220
4221 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OPERATING_RATE;
4222 control.value = rate->nU32;
4223
4224 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
4225 ret = errno == -EBUSY ? OMX_ErrorInsufficientResources :
4226 OMX_ErrorUnsupportedSetting;
4227 DEBUG_PRINT_ERROR("Failed to set operating rate %u fps (%s)",
4228 rate->nU32 >> 16, errno == -EBUSY ? "HW Overload" : strerror(errno));
4229 }
4230 return ret;
Arun Menon906de572013-06-18 17:01:40 -07004231 }
4232
4233 return OMX_ErrorNotImplemented;
4234}
4235
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304236#define extn_equals(param, extn) (!strncmp(param, extn, strlen(extn)))
4237
Arun Menon906de572013-06-18 17:01:40 -07004238/* ======================================================================
4239 FUNCTION
4240 omx_vdec::GetExtensionIndex
4241
4242 DESCRIPTION
4243 OMX GetExtensionIndex method implementaion. <TBD>
4244
4245 PARAMETERS
4246 <TBD>.
4247
4248 RETURN VALUE
4249 OMX Error None if everything successful.
4250
4251 ========================================================================== */
4252OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp,
4253 OMX_IN OMX_STRING paramName,
4254 OMX_OUT OMX_INDEXTYPE* indexType)
4255{
4256 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004257 DEBUG_PRINT_ERROR("Get Extension Index in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004258 return OMX_ErrorInvalidState;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304259 } else if (extn_equals(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode")) {
Arun Menon906de572013-06-18 17:01:40 -07004260 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304261 } else if (extn_equals(paramName, "OMX.QCOM.index.param.IndexExtraData")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004262 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304263 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_FRAMEPACKING_EXTRADATA)) {
4264 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoFramePackingExtradata;
4265 } else if (extn_equals(paramName, OMX_QCOM_INDEX_CONFIG_VIDEO_FRAMEPACKING_INFO)) {
4266 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoFramePackingArrangement;
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08004267 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_QP_EXTRADATA)) {
4268 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPExtraData;
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08004269 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_INPUTBITSINFO_EXTRADATA)) {
4270 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoInputBitsInfoExtraData;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08004271 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_EXTNUSER_EXTRADATA)) {
4272 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableExtnUserData;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004273 }
4274#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304275 else if (extn_equals(paramName, "OMX.google.android.index.enableAndroidNativeBuffers")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004276 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304277 } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer2")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004278 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304279 } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer")) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004280 DEBUG_PRINT_ERROR("Extension: %s is supported", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004281 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304282 } else if (extn_equals(paramName, "OMX.google.android.index.getAndroidNativeBufferUsage")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004283 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage;
4284 }
4285#endif
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304286 else if (extn_equals(paramName, "OMX.google.android.index.storeMetaDataInBuffers")) {
Arun Menone5652482013-08-04 13:33:05 -07004287 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode;
4288 }
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05304289#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
Praveen Chavancf924182013-12-06 23:16:23 -08004290 else if (extn_equals(paramName, "OMX.google.android.index.prepareForAdaptivePlayback")) {
4291 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoAdaptivePlaybackMode;
4292 }
4293#endif
Praveen Chavan09a82b72014-10-18 09:09:45 -07004294#ifdef FLEXYUV_SUPPORTED
4295 else if (extn_equals(paramName,"OMX.google.android.index.describeColorFormat")) {
4296 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexFlexibleYUVDescription;
4297 }
4298#endif
Arun Menon906de572013-06-18 17:01:40 -07004299 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004300 DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004301 return OMX_ErrorNotImplemented;
4302 }
4303 return OMX_ErrorNone;
4304}
4305
4306/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004307 FUNCTION
4308 omx_vdec::GetState
Shalaj Jain273b3e02012-06-22 19:08:03 -07004309
Arun Menon906de572013-06-18 17:01:40 -07004310 DESCRIPTION
4311 Returns the state information back to the caller.<TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07004312
Arun Menon906de572013-06-18 17:01:40 -07004313 PARAMETERS
4314 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004315
Arun Menon906de572013-06-18 17:01:40 -07004316 RETURN VALUE
4317 Error None if everything is successful.
4318 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004319OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004320 OMX_OUT OMX_STATETYPE* state)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004321{
Arun Menon906de572013-06-18 17:01:40 -07004322 *state = m_state;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004323 DEBUG_PRINT_LOW("get_state: Returning the state %d",*state);
Arun Menon906de572013-06-18 17:01:40 -07004324 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004325}
4326
4327/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004328 FUNCTION
4329 omx_vdec::ComponentTunnelRequest
Shalaj Jain273b3e02012-06-22 19:08:03 -07004330
Arun Menon906de572013-06-18 17:01:40 -07004331 DESCRIPTION
4332 OMX Component Tunnel Request method implementation. <TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07004333
Arun Menon906de572013-06-18 17:01:40 -07004334 PARAMETERS
4335 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004336
Arun Menon906de572013-06-18 17:01:40 -07004337 RETURN VALUE
4338 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004339
Arun Menon906de572013-06-18 17:01:40 -07004340 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004341OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004342 OMX_IN OMX_U32 port,
4343 OMX_IN OMX_HANDLETYPE peerComponent,
4344 OMX_IN OMX_U32 peerPort,
4345 OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004346{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004347 DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented");
Arun Menon906de572013-06-18 17:01:40 -07004348 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004349}
4350
4351/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004352 FUNCTION
4353 omx_vdec::UseOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004354
Arun Menon906de572013-06-18 17:01:40 -07004355 DESCRIPTION
4356 Helper function for Use buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07004357
Arun Menon906de572013-06-18 17:01:40 -07004358 PARAMETERS
4359 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004360
Arun Menon906de572013-06-18 17:01:40 -07004361 RETURN VALUE
4362 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07004363
Arun Menon906de572013-06-18 17:01:40 -07004364 ========================================================================== */
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004365OMX_ERRORTYPE omx_vdec::allocate_extradata()
4366{
4367#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004368 if (drv_ctx.extradata_info.buffer_size) {
4369 if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) {
4370 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
4371 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4372 free_ion_memory(&drv_ctx.extradata_info.ion);
Praveen Chavan61e5d162013-11-01 02:49:19 -07004373 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Arun Menon906de572013-06-18 17:01:40 -07004374 }
4375 drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095);
4376 drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory(
4377 drv_ctx.extradata_info.size, 4096,
4378 &drv_ctx.extradata_info.ion.ion_alloc_data,
4379 &drv_ctx.extradata_info.ion.fd_ion_data, 0);
4380 if (drv_ctx.extradata_info.ion.ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004381 DEBUG_PRINT_ERROR("Failed to alloc extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07004382 return OMX_ErrorInsufficientResources;
4383 }
4384 drv_ctx.extradata_info.uaddr = (char *)mmap(NULL,
4385 drv_ctx.extradata_info.size,
4386 PROT_READ|PROT_WRITE, MAP_SHARED,
4387 drv_ctx.extradata_info.ion.fd_ion_data.fd , 0);
4388 if (drv_ctx.extradata_info.uaddr == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004389 DEBUG_PRINT_ERROR("Failed to map extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07004390 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4391 free_ion_memory(&drv_ctx.extradata_info.ion);
4392 return OMX_ErrorInsufficientResources;
4393 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004394 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004395#endif
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304396 if (!m_other_extradata) {
4397 m_other_extradata = (OMX_OTHER_EXTRADATATYPE *)malloc(drv_ctx.extradata_info.buffer_size);
4398 if (!m_other_extradata) {
4399 DEBUG_PRINT_ERROR("Failed to alloc memory\n");
4400 return OMX_ErrorInsufficientResources;
4401 }
4402 }
Arun Menon906de572013-06-18 17:01:40 -07004403 return OMX_ErrorNone;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004404}
4405
Arun Menon906de572013-06-18 17:01:40 -07004406void omx_vdec::free_extradata()
4407{
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004408#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004409 if (drv_ctx.extradata_info.uaddr) {
4410 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
4411 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4412 free_ion_memory(&drv_ctx.extradata_info.ion);
4413 }
4414 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004415#endif
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304416 if (m_other_extradata) {
4417 free(m_other_extradata);
4418 m_other_extradata = NULL;
4419 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004420}
4421
Shalaj Jain273b3e02012-06-22 19:08:03 -07004422OMX_ERRORTYPE omx_vdec::use_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004423 OMX_IN OMX_HANDLETYPE hComp,
4424 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4425 OMX_IN OMX_U32 port,
4426 OMX_IN OMX_PTR appData,
4427 OMX_IN OMX_U32 bytes,
4428 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004429{
Arun Menon906de572013-06-18 17:01:40 -07004430 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4431 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
4432 unsigned i= 0; // Temporary counter
4433 struct vdec_setbuffer_cmd setbuffers;
4434 OMX_PTR privateAppData = NULL;
4435 private_handle_t *handle = NULL;
4436 OMX_U8 *buff = buffer;
4437 struct v4l2_buffer buf;
4438 struct v4l2_plane plane[VIDEO_MAX_PLANES];
4439 int extra_idx = 0;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004440
Arun Menon906de572013-06-18 17:01:40 -07004441 if (!m_out_mem_ptr) {
4442 DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers");
4443 eRet = allocate_output_headers();
4444 if (eRet == OMX_ErrorNone)
4445 eRet = allocate_extradata();
Shalaj Jain273b3e02012-06-22 19:08:03 -07004446 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004447
Arun Menon906de572013-06-18 17:01:40 -07004448 if (eRet == OMX_ErrorNone) {
4449 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
4450 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
4451 break;
4452 }
4453 }
4454 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004455
Arun Menon906de572013-06-18 17:01:40 -07004456 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004457 DEBUG_PRINT_ERROR("Already using %d o/p buffers", drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07004458 eRet = OMX_ErrorInsufficientResources;
4459 }
4460
Arun Menonbdb80b02013-08-12 17:45:54 -07004461 if (dynamic_buf_mode) {
4462 *bufferHdr = (m_out_mem_ptr + i );
4463 (*bufferHdr)->pBuffer = NULL;
4464 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
4465 enum v4l2_buf_type buf_type;
4466 int rr = 0;
4467 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4468 if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
4469 DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr);
4470 return OMX_ErrorInsufficientResources;
4471 } else {
4472 streaming[CAPTURE_PORT] = true;
4473 DEBUG_PRINT_LOW("STREAMON Successful");
4474 }
4475 }
4476 BITMASK_SET(&m_out_bm_count,i);
4477 (*bufferHdr)->pAppPrivate = appData;
4478 (*bufferHdr)->pBuffer = buffer;
4479 (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData);
4480 return eRet;
4481 }
Arun Menon906de572013-06-18 17:01:40 -07004482 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004483#if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004484 if (m_enable_android_native_buffers) {
4485 if (m_use_android_native_buffers) {
4486 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData;
4487 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
4488 handle = (private_handle_t *)nBuf->handle;
4489 privateAppData = params->pAppPrivate;
4490 } else {
4491 handle = (private_handle_t *)buff;
4492 privateAppData = appData;
4493 }
Arun Menon8544ead2014-05-08 17:42:29 -07004494 if (!handle) {
4495 DEBUG_PRINT_ERROR("handle is invalid");
4496 return OMX_ErrorBadParameter;
4497 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004498
Arun Menon906de572013-06-18 17:01:40 -07004499 if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) {
4500 DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback,"
4501 " expected %u, got %lu",
4502 drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size);
4503 return OMX_ErrorBadParameter;
4504 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004505
Deva Ramasubramanian03a5bb92014-04-25 19:03:50 -07004506 drv_ctx.op_buf.buffer_size = handle->size;
4507
Arun Menon906de572013-06-18 17:01:40 -07004508 if (!m_use_android_native_buffers) {
4509 if (!secure_mode) {
4510 buff = (OMX_U8*)mmap(0, handle->size,
4511 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
4512 if (buff == MAP_FAILED) {
4513 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
4514 return OMX_ErrorInsufficientResources;
4515 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004516 }
4517 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004518#if defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004519 native_buffer[i].nativehandle = handle;
4520 native_buffer[i].privatehandle = handle;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004521#endif
Arun Menon906de572013-06-18 17:01:40 -07004522 if (!handle) {
4523 DEBUG_PRINT_ERROR("Native Buffer handle is NULL");
4524 return OMX_ErrorBadParameter;
4525 }
4526 drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd;
4527 drv_ctx.ptr_outputbuffer[i].offset = 0;
4528 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4529 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4530 drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size;
4531 } else
4532#endif
4533
4534 if (!ouput_egl_buffers && !m_use_output_pmem) {
4535#ifdef USE_ION
4536 drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
4537 drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment,
4538 &drv_ctx.op_buf_ion_info[i].ion_alloc_data,
4539 &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
4540 if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004541 DEBUG_PRINT_ERROR("ION device fd is bad %d", drv_ctx.op_buf_ion_info[i].ion_device_fd);
Arun Menon906de572013-06-18 17:01:40 -07004542 return OMX_ErrorInsufficientResources;
4543 }
4544 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4545 drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
4546#else
4547 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4548 open (MEM_DEVICE,O_RDWR);
4549
4550 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004551 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004552 return OMX_ErrorInsufficientResources;
4553 }
4554
4555 /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */
4556 if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) {
4557 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4558 open (MEM_DEVICE,O_RDWR);
4559 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004560 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004561 return OMX_ErrorInsufficientResources;
4562 }
4563 }
4564
4565 if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd,
4566 drv_ctx.op_buf.buffer_size,
4567 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004568 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07004569 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4570 return OMX_ErrorInsufficientResources;
4571 }
4572#endif
4573 if (!secure_mode) {
4574 drv_ctx.ptr_outputbuffer[i].bufferaddr =
4575 (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size,
4576 PROT_READ|PROT_WRITE, MAP_SHARED,
4577 drv_ctx.ptr_outputbuffer[i].pmem_fd,0);
4578 if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) {
4579 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4580#ifdef USE_ION
4581 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
4582#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004583 DEBUG_PRINT_ERROR("Unable to mmap output buffer");
Arun Menon906de572013-06-18 17:01:40 -07004584 return OMX_ErrorInsufficientResources;
4585 }
4586 }
4587 drv_ctx.ptr_outputbuffer[i].offset = 0;
4588 privateAppData = appData;
4589 } else {
4590
4591 DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem);
4592 if (!appData || !bytes ) {
4593 if (!secure_mode && !buffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004594 DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case");
Arun Menon906de572013-06-18 17:01:40 -07004595 return OMX_ErrorBadParameter;
4596 }
4597 }
4598
4599 OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list;
4600 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info;
4601 pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData;
Arun Menon8544ead2014-05-08 17:42:29 -07004602 if (!pmem_list || !pmem_list->entryList || !pmem_list->entryList->entry ||
Arun Menon906de572013-06-18 17:01:40 -07004603 !pmem_list->nEntries ||
4604 pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004605 DEBUG_PRINT_ERROR("Pmem info not valid in use buffer");
Arun Menon906de572013-06-18 17:01:40 -07004606 return OMX_ErrorBadParameter;
4607 }
4608 pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
4609 pmem_list->entryList->entry;
4610 DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx",
4611 pmem_info->pmem_fd);
4612 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd;
4613 drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset;
4614 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4615 drv_ctx.ptr_outputbuffer[i].mmaped_size =
4616 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4617 privateAppData = appData;
4618 }
4619 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
4620 m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd;
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304621 m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len;
4622 m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size;
4623 m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr;
Arun Menon906de572013-06-18 17:01:40 -07004624
4625 *bufferHdr = (m_out_mem_ptr + i );
4626 if (secure_mode)
4627 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
4628 //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4629 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i],
4630 sizeof (vdec_bufferpayload));
4631
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004632 DEBUG_PRINT_HIGH("Set the Output Buffer Idx: %d Addr: %p, pmem_fd=0x%x", i,
Arun Menon906de572013-06-18 17:01:40 -07004633 drv_ctx.ptr_outputbuffer[i].bufferaddr,
4634 drv_ctx.ptr_outputbuffer[i].pmem_fd );
4635
4636 buf.index = i;
4637 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4638 buf.memory = V4L2_MEMORY_USERPTR;
4639 plane[0].length = drv_ctx.op_buf.buffer_size;
4640 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
4641 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
4642 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd;
4643 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
4644 plane[0].data_offset = 0;
4645 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
4646 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
4647 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
4648 plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size);
4649#ifdef USE_ION
4650 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
4651#endif
4652 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
4653 plane[extra_idx].data_offset = 0;
4654 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004655 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004656 return OMX_ErrorBadParameter;
4657 }
Arun Menon906de572013-06-18 17:01:40 -07004658 buf.m.planes = plane;
4659 buf.length = drv_ctx.num_planes;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004660
Arun Menon906de572013-06-18 17:01:40 -07004661 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004662 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07004663 /*TODO: How to handle this case */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004664 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004665 }
4666
Arun Menon906de572013-06-18 17:01:40 -07004667 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
4668 enum v4l2_buf_type buf_type;
4669 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4670 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
4671 return OMX_ErrorInsufficientResources;
4672 } else {
4673 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004674 DEBUG_PRINT_LOW("STREAMON Successful");
Shalaj Jain273b3e02012-06-22 19:08:03 -07004675 }
4676 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004677
Arun Menon906de572013-06-18 17:01:40 -07004678 (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size;
4679 if (m_enable_android_native_buffers) {
4680 DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle);
4681 (*bufferHdr)->pBuffer = (OMX_U8 *)handle;
4682 } else {
4683 (*bufferHdr)->pBuffer = buff;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004684 }
Arun Menon906de572013-06-18 17:01:40 -07004685 (*bufferHdr)->pAppPrivate = privateAppData;
4686 BITMASK_SET(&m_out_bm_count,i);
4687 }
4688 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004689}
4690
4691/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004692 FUNCTION
4693 omx_vdec::use_input_heap_buffers
Shalaj Jain273b3e02012-06-22 19:08:03 -07004694
Arun Menon906de572013-06-18 17:01:40 -07004695 DESCRIPTION
4696 OMX Use Buffer Heap allocation method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004697
Arun Menon906de572013-06-18 17:01:40 -07004698 PARAMETERS
4699 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004700
Arun Menon906de572013-06-18 17:01:40 -07004701 RETURN VALUE
4702 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004703
Arun Menon906de572013-06-18 17:01:40 -07004704 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004705OMX_ERRORTYPE omx_vdec::use_input_heap_buffers(
Arun Menon906de572013-06-18 17:01:40 -07004706 OMX_IN OMX_HANDLETYPE hComp,
4707 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4708 OMX_IN OMX_U32 port,
4709 OMX_IN OMX_PTR appData,
4710 OMX_IN OMX_U32 bytes,
4711 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004712{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004713 DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer);
Arun Menon906de572013-06-18 17:01:40 -07004714 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4715 if (!m_inp_heap_ptr)
4716 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*)
4717 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4718 drv_ctx.ip_buf.actualcount);
4719 if (!m_phdr_pmem_ptr)
4720 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**)
4721 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4722 drv_ctx.ip_buf.actualcount);
4723 if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) {
4724 DEBUG_PRINT_ERROR("Insufficent memory");
4725 eRet = OMX_ErrorInsufficientResources;
4726 } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) {
4727 input_use_buffer = true;
4728 memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE));
4729 m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer;
4730 m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes;
4731 m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData;
4732 m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput;
4733 m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax;
4734 *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt];
4735 eRet = allocate_input_buffer(hComp, &m_phdr_pmem_ptr[m_in_alloc_cnt], port, appData, bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004736 DEBUG_PRINT_HIGH("Heap buffer(%p) Pmem buffer(%p)", *bufferHdr, m_phdr_pmem_ptr[m_in_alloc_cnt]);
Arun Menon906de572013-06-18 17:01:40 -07004737 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt],
4738 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004739 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07004740 return OMX_ErrorInsufficientResources;
4741 }
4742 m_in_alloc_cnt++;
4743 } else {
4744 DEBUG_PRINT_ERROR("All i/p buffers have been set!");
4745 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004746 }
Arun Menon906de572013-06-18 17:01:40 -07004747 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004748}
4749
4750/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004751 FUNCTION
4752 omx_vdec::UseBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004753
Arun Menon906de572013-06-18 17:01:40 -07004754 DESCRIPTION
4755 OMX Use Buffer method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004756
Arun Menon906de572013-06-18 17:01:40 -07004757 PARAMETERS
4758 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004759
Arun Menon906de572013-06-18 17:01:40 -07004760 RETURN VALUE
4761 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004762
Arun Menon906de572013-06-18 17:01:40 -07004763 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004764OMX_ERRORTYPE omx_vdec::use_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004765 OMX_IN OMX_HANDLETYPE hComp,
4766 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4767 OMX_IN OMX_U32 port,
4768 OMX_IN OMX_PTR appData,
4769 OMX_IN OMX_U32 bytes,
4770 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004771{
Arun Menon906de572013-06-18 17:01:40 -07004772 OMX_ERRORTYPE error = OMX_ErrorNone;
4773 struct vdec_setbuffer_cmd setbuffers;
4774
Arun Menon8544ead2014-05-08 17:42:29 -07004775 if (bufferHdr == NULL || bytes == 0 || (!secure_mode && buffer == NULL)) {
4776 DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer);
4777 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004778 }
Arun Menon906de572013-06-18 17:01:40 -07004779 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004780 DEBUG_PRINT_ERROR("Use Buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004781 return OMX_ErrorInvalidState;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004782 }
Arun Menon906de572013-06-18 17:01:40 -07004783 if (port == OMX_CORE_INPUT_PORT_INDEX)
4784 error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer);
4785 else if (port == OMX_CORE_OUTPUT_PORT_INDEX)
4786 error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested
4787 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004788 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07004789 error = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004790 }
Arun Menon906de572013-06-18 17:01:40 -07004791 DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error);
4792 if (error == OMX_ErrorNone) {
4793 if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
4794 // Send the callback now
4795 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
4796 post_event(OMX_CommandStateSet,OMX_StateIdle,
4797 OMX_COMPONENT_GENERATE_EVENT);
4798 }
4799 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated &&
4800 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
4801 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
4802 post_event(OMX_CommandPortEnable,
4803 OMX_CORE_INPUT_PORT_INDEX,
4804 OMX_COMPONENT_GENERATE_EVENT);
4805 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated &&
4806 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
4807 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
4808 post_event(OMX_CommandPortEnable,
4809 OMX_CORE_OUTPUT_PORT_INDEX,
4810 OMX_COMPONENT_GENERATE_EVENT);
4811 }
4812 }
4813 return error;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004814}
4815
4816OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex,
Arun Menon906de572013-06-18 17:01:40 -07004817 OMX_BUFFERHEADERTYPE *pmem_bufferHdr)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004818{
Arun Menon906de572013-06-18 17:01:40 -07004819 if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) {
4820 if (m_inp_heap_ptr[bufferindex].pBuffer)
4821 free(m_inp_heap_ptr[bufferindex].pBuffer);
4822 m_inp_heap_ptr[bufferindex].pBuffer = NULL;
4823 }
4824 if (pmem_bufferHdr)
4825 free_input_buffer(pmem_bufferHdr);
4826 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004827}
4828
4829OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4830{
Arun Menon906de572013-06-18 17:01:40 -07004831 unsigned int index = 0;
4832 if (bufferHdr == NULL || m_inp_mem_ptr == NULL) {
4833 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004834 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004835
Arun Menon906de572013-06-18 17:01:40 -07004836 index = bufferHdr - m_inp_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004837 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004838
4839 if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004840 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004841 if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) {
4842 struct vdec_setbuffer_cmd setbuffers;
4843 setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT;
4844 memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index],
4845 sizeof (vdec_bufferpayload));
4846 if (!secure_mode) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004847 DEBUG_PRINT_LOW("unmap the input buffer fd=%d",
Arun Menon906de572013-06-18 17:01:40 -07004848 drv_ctx.ptr_inputbuffer[index].pmem_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004849 DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07004850 drv_ctx.ptr_inputbuffer[index].mmaped_size,
4851 drv_ctx.ptr_inputbuffer[index].bufferaddr);
4852 munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr,
4853 drv_ctx.ptr_inputbuffer[index].mmaped_size);
4854 }
4855 close (drv_ctx.ptr_inputbuffer[index].pmem_fd);
4856 drv_ctx.ptr_inputbuffer[index].pmem_fd = -1;
4857 if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) {
4858 free(m_desc_buffer_ptr[index].buf_addr);
4859 m_desc_buffer_ptr[index].buf_addr = NULL;
4860 m_desc_buffer_ptr[index].desc_data_size = 0;
4861 }
4862#ifdef USE_ION
4863 free_ion_memory(&drv_ctx.ip_buf_ion_info[index]);
4864#endif
4865 }
4866 }
4867
4868 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004869}
4870
4871OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4872{
Arun Menon906de572013-06-18 17:01:40 -07004873 unsigned int index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004874
Arun Menon906de572013-06-18 17:01:40 -07004875 if (bufferHdr == NULL || m_out_mem_ptr == NULL) {
4876 return OMX_ErrorBadParameter;
4877 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004878
Arun Menon906de572013-06-18 17:01:40 -07004879 index = bufferHdr - m_out_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004880 DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004881
Arun Menon906de572013-06-18 17:01:40 -07004882 if (index < drv_ctx.op_buf.actualcount
4883 && drv_ctx.ptr_outputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004884 DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index,
Arun Menon906de572013-06-18 17:01:40 -07004885 drv_ctx.ptr_outputbuffer[index].bufferaddr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004886
Arun Menon906de572013-06-18 17:01:40 -07004887 struct vdec_setbuffer_cmd setbuffers;
4888 setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4889 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index],
4890 sizeof (vdec_bufferpayload));
Praveen Chavan61e5d162013-11-01 02:49:19 -07004891
4892 if (!dynamic_buf_mode) {
Balamurugan Alagarsamye773c582014-12-17 15:10:25 +05304893 if (streaming[CAPTURE_PORT] &&
4894 !(in_reconfig || BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING))) {
4895 if (stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) {
4896 DEBUG_PRINT_ERROR("STREAMOFF Failed");
4897 } else {
4898 DEBUG_PRINT_LOW("STREAMOFF Successful");
4899 }
4900 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004901#ifdef _ANDROID_
Praveen Chavan61e5d162013-11-01 02:49:19 -07004902 if (m_enable_android_native_buffers) {
Arun Menon906de572013-06-18 17:01:40 -07004903 if (!secure_mode) {
Praveen Chavan61e5d162013-11-01 02:49:19 -07004904 if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) {
4905 munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr,
4906 drv_ctx.ptr_outputbuffer[index].mmaped_size);
4907 }
Arun Menon906de572013-06-18 17:01:40 -07004908 }
Praveen Chavan61e5d162013-11-01 02:49:19 -07004909 drv_ctx.ptr_outputbuffer[index].pmem_fd = -1;
4910 } else {
4911#endif
4912 if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) {
4913 if (!secure_mode) {
4914 DEBUG_PRINT_LOW("\n unmap the output buffer fd = %d",
4915 drv_ctx.ptr_outputbuffer[0].pmem_fd);
4916 DEBUG_PRINT_LOW("\n unmap the ouput buffer size=%d address = %p",
4917 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount,
4918 drv_ctx.ptr_outputbuffer[0].bufferaddr);
4919 munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr,
4920 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount);
4921 }
4922 close (drv_ctx.ptr_outputbuffer[0].pmem_fd);
4923 drv_ctx.ptr_outputbuffer[0].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004924#ifdef USE_ION
Praveen Chavan61e5d162013-11-01 02:49:19 -07004925 free_ion_memory(&drv_ctx.op_buf_ion_info[0]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004926#endif
Praveen Chavan61e5d162013-11-01 02:49:19 -07004927 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004928#ifdef _ANDROID_
Praveen Chavan61e5d162013-11-01 02:49:19 -07004929 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004930#endif
Praveen Chavan61e5d162013-11-01 02:49:19 -07004931 } //!dynamic_buf_mode
Arun Menon906de572013-06-18 17:01:40 -07004932 if (release_output_done()) {
4933 free_extradata();
4934 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004935 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004936
Arun Menon906de572013-06-18 17:01:40 -07004937 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004938
4939}
4940
4941OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004942 OMX_BUFFERHEADERTYPE **bufferHdr,
4943 OMX_U32 port,
4944 OMX_PTR appData,
4945 OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004946{
Arun Menon906de572013-06-18 17:01:40 -07004947 OMX_BUFFERHEADERTYPE *input = NULL;
4948 unsigned char *buf_addr = NULL;
4949 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4950 unsigned i = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004951
Arun Menon906de572013-06-18 17:01:40 -07004952 /* Sanity Check*/
4953 if (bufferHdr == NULL) {
4954 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004955 }
4956
Arun Menon906de572013-06-18 17:01:40 -07004957 if (m_inp_heap_ptr == NULL) {
4958 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \
4959 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4960 drv_ctx.ip_buf.actualcount);
4961 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \
4962 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4963 drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004964
Arun Menon8544ead2014-05-08 17:42:29 -07004965 if (m_inp_heap_ptr == NULL || m_phdr_pmem_ptr == NULL) {
4966 DEBUG_PRINT_ERROR("m_inp_heap_ptr or m_phdr_pmem_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07004967 return OMX_ErrorInsufficientResources;
4968 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004969 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004970
Arun Menon906de572013-06-18 17:01:40 -07004971 /*Find a Free index*/
4972 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
4973 if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004974 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004975 break;
4976 }
4977 }
4978
4979 if (i < drv_ctx.ip_buf.actualcount) {
4980 buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size);
4981
4982 if (buf_addr == NULL) {
4983 return OMX_ErrorInsufficientResources;
4984 }
4985
4986 *bufferHdr = (m_inp_heap_ptr + i);
4987 input = *bufferHdr;
4988 BITMASK_SET(&m_heap_inp_bm_count,i);
4989
4990 input->pBuffer = (OMX_U8 *)buf_addr;
4991 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
4992 input->nVersion.nVersion = OMX_SPEC_VERSION;
4993 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
4994 input->pAppPrivate = appData;
4995 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004996 DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr );
Arun Menon906de572013-06-18 17:01:40 -07004997 eRet = allocate_input_buffer(hComp,&m_phdr_pmem_ptr [i],port,appData,bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004998 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",m_phdr_pmem_ptr[i]);
Arun Menon906de572013-06-18 17:01:40 -07004999 /*Add the Buffers to freeq*/
5000 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i],
5001 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005002 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07005003 return OMX_ErrorInsufficientResources;
5004 }
5005 } else {
5006 return OMX_ErrorBadParameter;
5007 }
5008
5009 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005010
5011}
5012
5013
5014/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005015 FUNCTION
5016 omx_vdec::AllocateInputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005017
Arun Menon906de572013-06-18 17:01:40 -07005018 DESCRIPTION
5019 Helper function for allocate buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07005020
Arun Menon906de572013-06-18 17:01:40 -07005021 PARAMETERS
5022 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005023
Arun Menon906de572013-06-18 17:01:40 -07005024 RETURN VALUE
5025 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005026
Arun Menon906de572013-06-18 17:01:40 -07005027 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005028OMX_ERRORTYPE omx_vdec::allocate_input_buffer(
Arun Menon906de572013-06-18 17:01:40 -07005029 OMX_IN OMX_HANDLETYPE hComp,
5030 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5031 OMX_IN OMX_U32 port,
5032 OMX_IN OMX_PTR appData,
5033 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005034{
5035
Arun Menon906de572013-06-18 17:01:40 -07005036 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5037 struct vdec_setbuffer_cmd setbuffers;
5038 OMX_BUFFERHEADERTYPE *input = NULL;
5039 unsigned i = 0;
5040 unsigned char *buf_addr = NULL;
5041 int pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005042
Arun Menon906de572013-06-18 17:01:40 -07005043 if (bytes != drv_ctx.ip_buf.buffer_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005044 DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d",
Arun Menon906de572013-06-18 17:01:40 -07005045 bytes, drv_ctx.ip_buf.buffer_size);
5046 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005047 }
5048
Arun Menon906de572013-06-18 17:01:40 -07005049 if (!m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005050 DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07005051 drv_ctx.ip_buf.actualcount,
5052 drv_ctx.ip_buf.buffer_size);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005053
Arun Menon906de572013-06-18 17:01:40 -07005054 m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \
5055 calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount);
5056
5057 if (m_inp_mem_ptr == NULL) {
5058 return OMX_ErrorInsufficientResources;
5059 }
5060
5061 drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \
5062 calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount);
5063
5064 if (drv_ctx.ptr_inputbuffer == NULL) {
5065 return OMX_ErrorInsufficientResources;
5066 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005067#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005068 drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \
5069 calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005070
Arun Menon906de572013-06-18 17:01:40 -07005071 if (drv_ctx.ip_buf_ion_info == NULL) {
5072 return OMX_ErrorInsufficientResources;
5073 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005074#endif
5075
Arun Menon906de572013-06-18 17:01:40 -07005076 for (i=0; i < drv_ctx.ip_buf.actualcount; i++) {
5077 drv_ctx.ptr_inputbuffer [i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005078#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005079 drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005080#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07005081 }
5082 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005083
Arun Menon906de572013-06-18 17:01:40 -07005084 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
5085 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005086 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005087 break;
5088 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005089 }
Arun Menon906de572013-06-18 17:01:40 -07005090
5091 if (i < drv_ctx.ip_buf.actualcount) {
5092 struct v4l2_buffer buf;
5093 struct v4l2_plane plane;
5094 int rc;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005095 DEBUG_PRINT_LOW("Allocate input Buffer");
Arun Menon906de572013-06-18 17:01:40 -07005096#ifdef USE_ION
5097 drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
5098 drv_ctx.ip_buf.buffer_size,drv_ctx.op_buf.alignment,
5099 &drv_ctx.ip_buf_ion_info[i].ion_alloc_data,
5100 &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
5101 if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) {
5102 return OMX_ErrorInsufficientResources;
5103 }
5104 pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd;
5105#else
5106 pmem_fd = open (MEM_DEVICE,O_RDWR);
5107
5108 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005109 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07005110 return OMX_ErrorInsufficientResources;
5111 }
5112
5113 if (pmem_fd == 0) {
5114 pmem_fd = open (MEM_DEVICE,O_RDWR);
5115
5116 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005117 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07005118 return OMX_ErrorInsufficientResources;
5119 }
5120 }
5121
5122 if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size,
5123 drv_ctx.ip_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005124 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07005125 close(pmem_fd);
5126 return OMX_ErrorInsufficientResources;
5127 }
5128#endif
5129 if (!secure_mode) {
5130 buf_addr = (unsigned char *)mmap(NULL,
5131 drv_ctx.ip_buf.buffer_size,
5132 PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0);
5133
5134 if (buf_addr == MAP_FAILED) {
5135 close(pmem_fd);
5136#ifdef USE_ION
5137 free_ion_memory(&drv_ctx.ip_buf_ion_info[i]);
5138#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005139 DEBUG_PRINT_ERROR("Map Failed to allocate input buffer");
Arun Menon906de572013-06-18 17:01:40 -07005140 return OMX_ErrorInsufficientResources;
5141 }
5142 }
5143 *bufferHdr = (m_inp_mem_ptr + i);
5144 if (secure_mode)
5145 drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr;
5146 else
5147 drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr;
5148 drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd;
5149 drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size;
5150 drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size;
5151 drv_ctx.ptr_inputbuffer [i].offset = 0;
5152
5153
5154 buf.index = i;
5155 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
5156 buf.memory = V4L2_MEMORY_USERPTR;
5157 plane.bytesused = 0;
5158 plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size;
5159 plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr;
5160 plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd;
5161 plane.reserved[1] = 0;
5162 plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset;
5163 buf.m.planes = &plane;
5164 buf.length = 1;
5165
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005166 DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i,
Arun Menon906de572013-06-18 17:01:40 -07005167 drv_ctx.ptr_inputbuffer[i].bufferaddr);
5168
5169 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
5170
5171 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005172 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07005173 /*TODO: How to handle this case */
5174 return OMX_ErrorInsufficientResources;
5175 }
5176
5177 input = *bufferHdr;
5178 BITMASK_SET(&m_inp_bm_count,i);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005179 DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr);
Arun Menon906de572013-06-18 17:01:40 -07005180 if (secure_mode)
5181 input->pBuffer = (OMX_U8 *)drv_ctx.ptr_inputbuffer [i].pmem_fd;
5182 else
5183 input->pBuffer = (OMX_U8 *)buf_addr;
5184 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
5185 input->nVersion.nVersion = OMX_SPEC_VERSION;
5186 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
5187 input->pAppPrivate = appData;
5188 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
5189 input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i];
5190
5191 if (drv_ctx.disable_dmx) {
5192 eRet = allocate_desc_buffer(i);
5193 }
5194 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005195 DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07005196 eRet = OMX_ErrorInsufficientResources;
5197 }
5198 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005199}
5200
5201
5202/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005203 FUNCTION
5204 omx_vdec::AllocateOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005205
Arun Menon906de572013-06-18 17:01:40 -07005206 DESCRIPTION
5207 Helper fn for AllocateBuffer in the output pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07005208
Arun Menon906de572013-06-18 17:01:40 -07005209 PARAMETERS
5210 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005211
Arun Menon906de572013-06-18 17:01:40 -07005212 RETURN VALUE
5213 OMX Error None if everything went well.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005214
Arun Menon906de572013-06-18 17:01:40 -07005215 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005216OMX_ERRORTYPE omx_vdec::allocate_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07005217 OMX_IN OMX_HANDLETYPE hComp,
5218 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5219 OMX_IN OMX_U32 port,
5220 OMX_IN OMX_PTR appData,
5221 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005222{
Arun Menon906de572013-06-18 17:01:40 -07005223 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5224 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
5225 unsigned i= 0; // Temporary counter
5226 struct vdec_setbuffer_cmd setbuffers;
5227 int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005228#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005229 int ion_device_fd =-1;
5230 struct ion_allocation_data ion_alloc_data;
5231 struct ion_fd_data fd_ion_data;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005232#endif
Arun Menon906de572013-06-18 17:01:40 -07005233 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005234 DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07005235 drv_ctx.op_buf.actualcount,
5236 drv_ctx.op_buf.buffer_size);
5237 int nBufHdrSize = 0;
5238 int nPlatformEntrySize = 0;
5239 int nPlatformListSize = 0;
5240 int nPMEMInfoSize = 0;
5241 int pmem_fd = -1;
5242 unsigned char *pmem_baseaddress = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005243
Arun Menon906de572013-06-18 17:01:40 -07005244 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
5245 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
5246 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005247
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005248 DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07005249 drv_ctx.op_buf.actualcount);
5250 nBufHdrSize = drv_ctx.op_buf.actualcount *
5251 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005252
Arun Menon906de572013-06-18 17:01:40 -07005253 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
5254 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
5255 nPlatformListSize = drv_ctx.op_buf.actualcount *
5256 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
5257 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
5258 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005259
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005260 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07005261 sizeof(OMX_BUFFERHEADERTYPE),
5262 nPMEMInfoSize,
5263 nPlatformListSize);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005264 DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07005265 drv_ctx.op_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005266#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005267 ion_device_fd = alloc_map_ion_memory(
5268 drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount,
5269 drv_ctx.op_buf.alignment,
5270 &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0);
5271 if (ion_device_fd < 0) {
5272 return OMX_ErrorInsufficientResources;
5273 }
5274 pmem_fd = fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005275#else
Arun Menon906de572013-06-18 17:01:40 -07005276 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005277
Arun Menon906de572013-06-18 17:01:40 -07005278 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005279 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07005280 drv_ctx.op_buf.buffer_size);
5281 return OMX_ErrorInsufficientResources;
5282 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005283
Arun Menon906de572013-06-18 17:01:40 -07005284 if (pmem_fd == 0) {
5285 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005286
Arun Menon906de572013-06-18 17:01:40 -07005287 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005288 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07005289 drv_ctx.op_buf.buffer_size);
5290 return OMX_ErrorInsufficientResources;
5291 }
5292 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005293
Arun Menon906de572013-06-18 17:01:40 -07005294 if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size *
5295 drv_ctx.op_buf.actualcount,
5296 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005297 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07005298 close(pmem_fd);
5299 return OMX_ErrorInsufficientResources;
5300 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005301#endif
Arun Menon906de572013-06-18 17:01:40 -07005302 if (!secure_mode) {
5303 pmem_baseaddress = (unsigned char *)mmap(NULL,
5304 (drv_ctx.op_buf.buffer_size *
5305 drv_ctx.op_buf.actualcount),
5306 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0);
5307 if (pmem_baseaddress == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005308 DEBUG_PRINT_ERROR("MMAP failed for Size %d",
Arun Menon906de572013-06-18 17:01:40 -07005309 drv_ctx.op_buf.buffer_size);
5310 close(pmem_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005311#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005312 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005313#endif
Arun Menon906de572013-06-18 17:01:40 -07005314 return OMX_ErrorInsufficientResources;
5315 }
5316 }
5317 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
5318 // Alloc mem for platform specific info
5319 char *pPtr=NULL;
5320 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
5321 nPMEMInfoSize,1);
5322 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\
5323 calloc (sizeof(struct vdec_bufferpayload),
5324 drv_ctx.op_buf.actualcount);
5325 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
5326 calloc (sizeof (struct vdec_output_frameinfo),
5327 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07005328 if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) {
5329 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer ");
5330 return OMX_ErrorInsufficientResources;
5331 }
5332
Arun Menon906de572013-06-18 17:01:40 -07005333#ifdef USE_ION
5334 drv_ctx.op_buf_ion_info = (struct vdec_ion *)\
5335 calloc (sizeof(struct vdec_ion),
5336 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07005337 if (!drv_ctx.op_buf_ion_info) {
5338 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info");
5339 return OMX_ErrorInsufficientResources;
5340 }
Arun Menon906de572013-06-18 17:01:40 -07005341#endif
5342
5343 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
5344 && drv_ctx.ptr_respbuffer) {
5345 drv_ctx.ptr_outputbuffer[0].mmaped_size =
5346 (drv_ctx.op_buf.buffer_size *
5347 drv_ctx.op_buf.actualcount);
5348 bufHdr = m_out_mem_ptr;
5349 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
5350 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
5351 (((char *) m_platform_list) + nPlatformListSize);
5352 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
5353 (((char *) m_platform_entry) + nPlatformEntrySize);
5354 pPlatformList = m_platform_list;
5355 pPlatformEntry = m_platform_entry;
5356 pPMEMInfo = m_pmem_info;
5357
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005358 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07005359
5360 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005361 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry);
5362 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07005363 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
5364 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
5365 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
5366 // Set the values when we determine the right HxW param
5367 bufHdr->nAllocLen = bytes;
5368 bufHdr->nFilledLen = 0;
5369 bufHdr->pAppPrivate = appData;
5370 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
5371 // Platform specific PMEM Information
5372 // Initialize the Platform Entry
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005373 //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005374 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
5375 pPlatformEntry->entry = pPMEMInfo;
5376 // Initialize the Platform List
5377 pPlatformList->nEntries = 1;
5378 pPlatformList->entryList = pPlatformEntry;
5379 // Keep pBuffer NULL till vdec is opened
5380 bufHdr->pBuffer = NULL;
5381 bufHdr->nOffset = 0;
5382
5383 pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i;
5384 pPMEMInfo->pmem_fd = 0;
5385 bufHdr->pPlatformPrivate = pPlatformList;
5386
5387 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd;
5388 m_pmem_info[i].pmem_fd = pmem_fd;
5389#ifdef USE_ION
5390 drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd;
5391 drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data;
5392 drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data;
5393#endif
5394
5395 /*Create a mapping between buffers*/
5396 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
5397 drv_ctx.ptr_respbuffer[i].client_data = (void *)\
5398 &drv_ctx.ptr_outputbuffer[i];
5399 drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i;
5400 drv_ctx.ptr_outputbuffer[i].bufferaddr =
5401 pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05305402 m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len;
5403 m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size;
5404 m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr;
Arun Menon906de572013-06-18 17:01:40 -07005405
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005406 DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07005407 pmem_fd, drv_ctx.ptr_outputbuffer[i].offset,
5408 drv_ctx.ptr_outputbuffer[i].bufferaddr);
5409 // Move the buffer and buffer header pointers
5410 bufHdr++;
5411 pPMEMInfo++;
5412 pPlatformEntry++;
5413 pPlatformList++;
5414 }
5415 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005416 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07005417 m_out_mem_ptr, pPtr);
5418 if (m_out_mem_ptr) {
5419 free(m_out_mem_ptr);
5420 m_out_mem_ptr = NULL;
5421 }
5422 if (pPtr) {
5423 free(pPtr);
5424 pPtr = NULL;
5425 }
5426 if (drv_ctx.ptr_outputbuffer) {
5427 free(drv_ctx.ptr_outputbuffer);
5428 drv_ctx.ptr_outputbuffer = NULL;
5429 }
5430 if (drv_ctx.ptr_respbuffer) {
5431 free(drv_ctx.ptr_respbuffer);
5432 drv_ctx.ptr_respbuffer = NULL;
5433 }
5434#ifdef USE_ION
5435 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005436 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07005437 free(drv_ctx.op_buf_ion_info);
5438 drv_ctx.op_buf_ion_info = NULL;
5439 }
5440#endif
5441 eRet = OMX_ErrorInsufficientResources;
5442 }
5443 if (eRet == OMX_ErrorNone)
5444 eRet = allocate_extradata();
5445 }
5446
5447 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
5448 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005449 DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005450 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005451 }
5452 }
Arun Menon906de572013-06-18 17:01:40 -07005453
5454 if (eRet == OMX_ErrorNone) {
5455 if (i < drv_ctx.op_buf.actualcount) {
5456 struct v4l2_buffer buf;
5457 struct v4l2_plane plane[VIDEO_MAX_PLANES];
5458 int rc;
5459 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
5460
5461 drv_ctx.ptr_outputbuffer[i].buffer_len =
5462 drv_ctx.op_buf.buffer_size;
5463
5464 *bufferHdr = (m_out_mem_ptr + i );
5465 if (secure_mode) {
5466 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
5467 }
5468 drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size;
5469
5470 buf.index = i;
5471 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5472 buf.memory = V4L2_MEMORY_USERPTR;
5473 plane[0].length = drv_ctx.op_buf.buffer_size;
5474 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
5475 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005476#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005477 plane[0].reserved[0] = drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005478#endif
Arun Menon906de572013-06-18 17:01:40 -07005479 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
5480 plane[0].data_offset = 0;
5481 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
5482 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
5483 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
5484 plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005485#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005486 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005487#endif
Arun Menon906de572013-06-18 17:01:40 -07005488 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
5489 plane[extra_idx].data_offset = 0;
5490 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005491 DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07005492 return OMX_ErrorBadParameter;
5493 }
5494 buf.m.planes = plane;
5495 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005496 DEBUG_PRINT_LOW("Set the Output Buffer Idx: %d Addr: %p", i, drv_ctx.ptr_outputbuffer[i].bufferaddr);
Arun Menon906de572013-06-18 17:01:40 -07005497 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
5498 if (rc) {
5499 /*TODO: How to handle this case */
5500 return OMX_ErrorInsufficientResources;
5501 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005502
Arun Menon906de572013-06-18 17:01:40 -07005503 if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) {
5504 enum v4l2_buf_type buf_type;
5505 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5506 rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
5507 if (rc) {
5508 return OMX_ErrorInsufficientResources;
5509 } else {
5510 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005511 DEBUG_PRINT_LOW("STREAMON Successful");
Arun Menon906de572013-06-18 17:01:40 -07005512 }
5513 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005514
Arun Menon906de572013-06-18 17:01:40 -07005515 (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr;
5516 (*bufferHdr)->pAppPrivate = appData;
5517 BITMASK_SET(&m_out_bm_count,i);
5518 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005519 DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient");
Arun Menon906de572013-06-18 17:01:40 -07005520 eRet = OMX_ErrorInsufficientResources;
5521 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005522 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005523
Arun Menon906de572013-06-18 17:01:40 -07005524 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005525}
5526
5527
5528// AllocateBuffer -- API Call
5529/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005530 FUNCTION
5531 omx_vdec::AllocateBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005532
Arun Menon906de572013-06-18 17:01:40 -07005533 DESCRIPTION
5534 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07005535
Arun Menon906de572013-06-18 17:01:40 -07005536 PARAMETERS
5537 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005538
Arun Menon906de572013-06-18 17:01:40 -07005539 RETURN VALUE
5540 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005541
Arun Menon906de572013-06-18 17:01:40 -07005542 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005543OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005544 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5545 OMX_IN OMX_U32 port,
5546 OMX_IN OMX_PTR appData,
5547 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005548{
5549 unsigned i = 0;
5550 OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type
5551
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005552 DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port);
Arun Menon906de572013-06-18 17:01:40 -07005553 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005554 DEBUG_PRINT_ERROR("Allocate Buf in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005555 return OMX_ErrorInvalidState;
5556 }
5557
Arun Menon906de572013-06-18 17:01:40 -07005558 if (port == OMX_CORE_INPUT_PORT_INDEX) {
5559 if (arbitrary_bytes) {
5560 eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes);
5561 } else {
5562 eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes);
5563 }
5564 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Vinay Kaliada4f4422013-01-09 10:45:03 -08005565 eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port,
5566 appData,bytes);
Arun Menon906de572013-06-18 17:01:40 -07005567 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005568 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07005569 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005570 }
5571 DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done");
Arun Menon906de572013-06-18 17:01:40 -07005572 if (eRet == OMX_ErrorNone) {
5573 if (allocate_done()) {
5574 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005575 // Send the callback now
5576 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
5577 post_event(OMX_CommandStateSet,OMX_StateIdle,
Arun Menon906de572013-06-18 17:01:40 -07005578 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005579 }
5580 }
Arun Menon906de572013-06-18 17:01:40 -07005581 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) {
5582 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
5583 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
5584 post_event(OMX_CommandPortEnable,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005585 OMX_CORE_INPUT_PORT_INDEX,
5586 OMX_COMPONENT_GENERATE_EVENT);
Arun Menon906de572013-06-18 17:01:40 -07005587 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005588 }
Arun Menon906de572013-06-18 17:01:40 -07005589 if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) {
5590 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
5591 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005592 post_event(OMX_CommandPortEnable,
Arun Menon906de572013-06-18 17:01:40 -07005593 OMX_CORE_OUTPUT_PORT_INDEX,
5594 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005595 }
5596 }
5597 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005598 DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005599 return eRet;
5600}
5601
5602// Free Buffer - API call
5603/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005604 FUNCTION
5605 omx_vdec::FreeBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005606
Arun Menon906de572013-06-18 17:01:40 -07005607 DESCRIPTION
Shalaj Jain273b3e02012-06-22 19:08:03 -07005608
Arun Menon906de572013-06-18 17:01:40 -07005609 PARAMETERS
5610 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005611
Arun Menon906de572013-06-18 17:01:40 -07005612 RETURN VALUE
5613 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005614
Arun Menon906de572013-06-18 17:01:40 -07005615 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005616OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005617 OMX_IN OMX_U32 port,
5618 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005619{
5620 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5621 unsigned int nPortIndex;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005622 DEBUG_PRINT_LOW("In for decoder free_buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005623
Arun Menon906de572013-06-18 17:01:40 -07005624 if (m_state == OMX_StateIdle &&
5625 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005626 DEBUG_PRINT_LOW(" free buffer while Component in Loading pending");
Arun Menon906de572013-06-18 17:01:40 -07005627 } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)||
5628 (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005629 DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port);
Arun Menon906de572013-06-18 17:01:40 -07005630 } else if ((port == OMX_CORE_INPUT_PORT_INDEX &&
5631 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) ||
5632 (port == OMX_CORE_OUTPUT_PORT_INDEX &&
5633 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005634 DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port);
Arun Menon906de572013-06-18 17:01:40 -07005635 } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005636 DEBUG_PRINT_ERROR("Invalid state to free buffer,ports need to be disabled");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005637 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005638 OMX_ErrorPortUnpopulated,
5639 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005640
5641 return OMX_ErrorIncorrectStateOperation;
Arun Menon906de572013-06-18 17:01:40 -07005642 } else if (m_state != OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005643 DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005644 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005645 OMX_ErrorPortUnpopulated,
5646 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005647 }
5648
Arun Menon906de572013-06-18 17:01:40 -07005649 if (port == OMX_CORE_INPUT_PORT_INDEX) {
5650 /*Check if arbitrary bytes*/
5651 if (!arbitrary_bytes && !input_use_buffer)
5652 nPortIndex = buffer - m_inp_mem_ptr;
5653 else
5654 nPortIndex = buffer - m_inp_heap_ptr;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005655
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005656 DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %d", nPortIndex);
Praveen Chavan88256fe2016-04-11 17:32:45 -07005657 if (nPortIndex < drv_ctx.ip_buf.actualcount &&
5658 BITMASK_PRESENT(&m_inp_bm_count, nPortIndex)) {
Arun Menon906de572013-06-18 17:01:40 -07005659 // Clear the bit associated with it.
5660 BITMASK_CLEAR(&m_inp_bm_count,nPortIndex);
5661 BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex);
5662 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005663
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005664 DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005665 if (m_phdr_pmem_ptr)
5666 free_input_buffer(m_phdr_pmem_ptr[nPortIndex]);
5667 } else {
5668 if (arbitrary_bytes) {
5669 if (m_phdr_pmem_ptr)
5670 free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]);
5671 else
5672 free_input_buffer(nPortIndex,NULL);
5673 } else
5674 free_input_buffer(buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005675 }
Arun Menon906de572013-06-18 17:01:40 -07005676 m_inp_bPopulated = OMX_FALSE;
Surajit Podder12aefac2013-08-06 18:43:32 +05305677 if(release_input_done())
5678 release_buffers(this, VDEC_BUFFER_TYPE_INPUT);
Arun Menon906de572013-06-18 17:01:40 -07005679 /*Free the Buffer Header*/
5680 if (release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005681 DEBUG_PRINT_HIGH("ALL input buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07005682 free_input_buffer_header();
5683 }
5684 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005685 DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005686 eRet = OMX_ErrorBadPortIndex;
5687 }
5688
Arun Menon906de572013-06-18 17:01:40 -07005689 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING)
5690 && release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005691 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005692 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING);
5693 post_event(OMX_CommandPortDisable,
Arun Menon906de572013-06-18 17:01:40 -07005694 OMX_CORE_INPUT_PORT_INDEX,
5695 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005696 }
Arun Menon906de572013-06-18 17:01:40 -07005697 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005698 // check if the buffer is valid
Vinay Kaliada4f4422013-01-09 10:45:03 -08005699 nPortIndex = buffer - client_buffers.get_il_buf_hdr();
Praveen Chavan88256fe2016-04-11 17:32:45 -07005700 if (nPortIndex < drv_ctx.op_buf.actualcount &&
5701 BITMASK_PRESENT(&m_out_bm_count, nPortIndex)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005702 DEBUG_PRINT_LOW("free_buffer on o/p port - Port idx %d", nPortIndex);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005703 // Clear the bit associated with it.
5704 BITMASK_CLEAR(&m_out_bm_count,nPortIndex);
5705 m_out_bPopulated = OMX_FALSE;
Vinay Kaliada4f4422013-01-09 10:45:03 -08005706 client_buffers.free_output_buffer (buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005707
Surajit Podder12aefac2013-08-06 18:43:32 +05305708 if(release_output_done()) {
5709 release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT);
5710 }
Arun Menon906de572013-06-18 17:01:40 -07005711 if (release_output_done()) {
5712 free_output_buffer_header();
Shalaj Jain273b3e02012-06-22 19:08:03 -07005713 }
Arun Menon906de572013-06-18 17:01:40 -07005714 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005715 DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005716 eRet = OMX_ErrorBadPortIndex;
5717 }
Arun Menon906de572013-06-18 17:01:40 -07005718 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING)
5719 && release_output_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005720 DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005721
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005722 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Arun Menon906de572013-06-18 17:01:40 -07005723 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005724#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -07005725 if (m_enable_android_native_buffers) {
5726 DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers");
5727 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
5728 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005729#endif
5730
Arun Menon906de572013-06-18 17:01:40 -07005731 post_event(OMX_CommandPortDisable,
5732 OMX_CORE_OUTPUT_PORT_INDEX,
5733 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005734 }
Arun Menon906de572013-06-18 17:01:40 -07005735 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005736 eRet = OMX_ErrorBadPortIndex;
5737 }
Arun Menon906de572013-06-18 17:01:40 -07005738 if ((eRet == OMX_ErrorNone) &&
5739 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
5740 if (release_done()) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005741 // Send the callback now
5742 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING);
5743 post_event(OMX_CommandStateSet, OMX_StateLoaded,
Arun Menon906de572013-06-18 17:01:40 -07005744 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005745 }
5746 }
5747 return eRet;
5748}
5749
5750
5751/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005752 FUNCTION
5753 omx_vdec::EmptyThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005754
Arun Menon906de572013-06-18 17:01:40 -07005755 DESCRIPTION
5756 This routine is used to push the encoded video frames to
5757 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005758
Arun Menon906de572013-06-18 17:01:40 -07005759 PARAMETERS
5760 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005761
Arun Menon906de572013-06-18 17:01:40 -07005762 RETURN VALUE
5763 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005764
Arun Menon906de572013-06-18 17:01:40 -07005765 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005766OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005767 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005768{
Arun Menon906de572013-06-18 17:01:40 -07005769 OMX_ERRORTYPE ret1 = OMX_ErrorNone;
5770 unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005771
Arun Menon906de572013-06-18 17:01:40 -07005772 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005773 DEBUG_PRINT_ERROR("Empty this buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07005774 return OMX_ErrorInvalidState;
5775 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005776
Arun Menon906de572013-06-18 17:01:40 -07005777 if (buffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005778 DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL");
Arun Menon906de572013-06-18 17:01:40 -07005779 return OMX_ErrorBadParameter;
5780 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005781
Arun Menon906de572013-06-18 17:01:40 -07005782 if (!m_inp_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005783 DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07005784 return OMX_ErrorIncorrectStateOperation;
5785 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005786
Arun Menon906de572013-06-18 17:01:40 -07005787 if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005788 DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005789 return OMX_ErrorBadPortIndex;
5790 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005791
5792#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005793 if (iDivXDrmDecrypt) {
5794 OMX_ERRORTYPE drmErr = iDivXDrmDecrypt->Decrypt(buffer);
5795 if (drmErr != OMX_ErrorNone) {
5796 // this error can be ignored
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005797 DEBUG_PRINT_LOW("ERROR:iDivXDrmDecrypt->Decrypt %d", drmErr);
Arun Menon906de572013-06-18 17:01:40 -07005798 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005799 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005800#endif //_ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005801 if (perf_flag) {
5802 if (!latency) {
5803 dec_time.stop();
5804 latency = dec_time.processing_time_us();
5805 dec_time.start();
5806 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005807 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005808
Arun Menon906de572013-06-18 17:01:40 -07005809 if (arbitrary_bytes) {
5810 nBufferIndex = buffer - m_inp_heap_ptr;
5811 } else {
5812 if (input_use_buffer == true) {
5813 nBufferIndex = buffer - m_inp_heap_ptr;
5814 m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen;
5815 m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp;
5816 m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags;
5817 buffer = &m_inp_mem_ptr[nBufferIndex];
5818 DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu",
5819 &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen);
5820 } else {
5821 nBufferIndex = buffer - m_inp_mem_ptr;
5822 }
5823 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005824
Arun Menon906de572013-06-18 17:01:40 -07005825 if (nBufferIndex > drv_ctx.ip_buf.actualcount ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005826 DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005827 return OMX_ErrorBadParameter;
5828 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005829
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07005830 if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
5831 codec_config_flag = true;
5832 DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__);
5833 }
5834
Arun Menon906de572013-06-18 17:01:40 -07005835 DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)",
5836 buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen);
5837 if (arbitrary_bytes) {
5838 post_event ((unsigned)hComp,(unsigned)buffer,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005839 OMX_COMPONENT_GENERATE_ETB_ARBITRARY);
Arun Menon906de572013-06-18 17:01:40 -07005840 } else {
Arun Menon906de572013-06-18 17:01:40 -07005841 post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB);
5842 }
Praveen Chavanece713f2014-12-10 18:00:04 -08005843 time_stamp_dts.insert_timestamp(buffer);
Arun Menon906de572013-06-18 17:01:40 -07005844 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005845}
5846
5847/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005848 FUNCTION
5849 omx_vdec::empty_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07005850
Arun Menon906de572013-06-18 17:01:40 -07005851 DESCRIPTION
5852 This routine is used to push the encoded video frames to
5853 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005854
Arun Menon906de572013-06-18 17:01:40 -07005855 PARAMETERS
5856 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005857
Arun Menon906de572013-06-18 17:01:40 -07005858 RETURN VALUE
5859 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005860
Arun Menon906de572013-06-18 17:01:40 -07005861 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005862OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005863 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005864{
Arun Menon906de572013-06-18 17:01:40 -07005865 int push_cnt = 0,i=0;
5866 unsigned nPortIndex = 0;
5867 OMX_ERRORTYPE ret = OMX_ErrorNone;
5868 struct vdec_input_frameinfo frameinfo;
5869 struct vdec_bufferpayload *temp_buffer;
5870 struct vdec_seqheader seq_header;
5871 bool port_setting_changed = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005872
Arun Menon906de572013-06-18 17:01:40 -07005873 /*Should we generate a Aync error event*/
5874 if (buffer == NULL || buffer->pInputPortPrivate == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005875 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005876 return OMX_ErrorBadParameter;
5877 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005878
Arun Menon906de572013-06-18 17:01:40 -07005879 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005880
Arun Menon906de572013-06-18 17:01:40 -07005881 if (nPortIndex > drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005882 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]",
Arun Menon906de572013-06-18 17:01:40 -07005883 nPortIndex);
5884 return OMX_ErrorBadParameter;
5885 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005886
Arun Menon906de572013-06-18 17:01:40 -07005887 pending_input_buffers++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005888
Arun Menon906de572013-06-18 17:01:40 -07005889 /* return zero length and not an EOS buffer */
5890 if (!arbitrary_bytes && (buffer->nFilledLen == 0) &&
5891 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005892 DEBUG_PRINT_HIGH("return zero legth buffer");
Arun Menon906de572013-06-18 17:01:40 -07005893 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5894 OMX_COMPONENT_GENERATE_EBD);
5895 return OMX_ErrorNone;
5896 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005897
c_sridur0af9cef2015-02-05 12:07:17 +05305898 if (input_flush_progress == true) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005899 DEBUG_PRINT_LOW("Flush in progress return buffer ");
Arun Menon906de572013-06-18 17:01:40 -07005900 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5901 OMX_COMPONENT_GENERATE_EBD);
5902 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005903 }
5904
Arun Menon906de572013-06-18 17:01:40 -07005905 temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005906
Surajit Podderd2644d52013-08-28 17:59:06 +05305907 if ((temp_buffer - drv_ctx.ptr_inputbuffer) > (int)drv_ctx.ip_buf.actualcount) {
Arun Menon906de572013-06-18 17:01:40 -07005908 return OMX_ErrorBadParameter;
5909 }
5910 /* If its first frame, H264 codec and reject is true, then parse the nal
5911 and get the profile. Based on this, reject the clip playback */
5912 if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 &&
5913 m_reject_avc_1080p_mp) {
5914 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005915 DEBUG_PRINT_ERROR("Parse nal to get the profile");
Arun Menon906de572013-06-18 17:01:40 -07005916 h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen,
5917 NALU_TYPE_SPS);
5918 m_profile = h264_parser->get_profile();
5919 ret = is_video_session_supported();
5920 if (ret) {
5921 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD);
5922 post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT);
5923 /* Move the state to Invalid to avoid queueing of pending ETB to the driver */
5924 m_state = OMX_StateInvalid;
5925 return OMX_ErrorNone;
5926 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005927 }
5928
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005929 DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
Arun Menon906de572013-06-18 17:01:40 -07005930 /*for use buffer we need to memcpy the data*/
5931 temp_buffer->buffer_len = buffer->nFilledLen;
5932
5933 if (input_use_buffer) {
5934 if (buffer->nFilledLen <= temp_buffer->buffer_len) {
5935 if (arbitrary_bytes) {
5936 memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen);
5937 } else {
5938 memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset),
5939 buffer->nFilledLen);
5940 }
5941 } else {
5942 return OMX_ErrorBadParameter;
5943 }
5944
5945 }
5946
5947 frameinfo.bufferaddr = temp_buffer->bufferaddr;
5948 frameinfo.client_data = (void *) buffer;
5949 frameinfo.datalen = temp_buffer->buffer_len;
5950 frameinfo.flags = 0;
5951 frameinfo.offset = buffer->nOffset;
5952 frameinfo.pmem_fd = temp_buffer->pmem_fd;
5953 frameinfo.pmem_offset = temp_buffer->offset;
5954 frameinfo.timestamp = buffer->nTimeStamp;
5955 if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) {
5956 DEBUG_PRINT_LOW("ETB: dmx enabled");
5957 if (m_demux_entries == 0) {
5958 extract_demux_addr_offsets(buffer);
5959 }
5960
5961 DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries);
5962 handle_demux_data(buffer);
5963 frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr;
5964 frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size;
5965 } else {
5966 frameinfo.desc_addr = NULL;
5967 frameinfo.desc_size = 0;
5968 }
5969 if (!arbitrary_bytes) {
5970 frameinfo.flags |= buffer->nFlags;
5971 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005972
5973#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005974 if (m_debug_timestamp) {
5975 if (arbitrary_bytes) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005976 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005977 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5978 } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005979 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005980 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5981 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005982 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005983#endif
5984
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005985log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005986
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005987if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Arun Menon906de572013-06-18 17:01:40 -07005988 frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5989 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5990 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005991
Arun Menon906de572013-06-18 17:01:40 -07005992 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005993 DEBUG_PRINT_HIGH("Rxd i/p EOS, Notify Driver that EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07005994 frameinfo.flags |= VDEC_BUFFERFLAG_EOS;
5995 h264_scratch.nFilledLen = 0;
5996 nal_count = 0;
5997 look_ahead_nal = false;
5998 frame_count = 0;
5999 if (m_frame_parser.mutils)
6000 m_frame_parser.mutils->initialize_frame_checking_environment();
6001 m_frame_parser.flush();
6002 h264_last_au_ts = LLONG_MAX;
6003 h264_last_au_flags = 0;
6004 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
6005 m_demux_entries = 0;
6006 }
6007 struct v4l2_buffer buf;
6008 struct v4l2_plane plane;
6009 memset( (void *)&buf, 0, sizeof(buf));
6010 memset( (void *)&plane, 0, sizeof(plane));
6011 int rc;
6012 unsigned long print_count;
6013 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07006014 buf.flags = V4L2_QCOM_BUF_FLAG_EOS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006015 DEBUG_PRINT_HIGH("INPUT EOS reached") ;
Arun Menon906de572013-06-18 17:01:40 -07006016 }
6017 OMX_ERRORTYPE eRet = OMX_ErrorNone;
6018 buf.index = nPortIndex;
6019 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
6020 buf.memory = V4L2_MEMORY_USERPTR;
6021 plane.bytesused = temp_buffer->buffer_len;
6022 plane.length = drv_ctx.ip_buf.buffer_size;
6023 plane.m.userptr = (unsigned long)temp_buffer->bufferaddr -
6024 (unsigned long)temp_buffer->offset;
6025 plane.reserved[0] = temp_buffer->pmem_fd;
6026 plane.reserved[1] = temp_buffer->offset;
6027 plane.data_offset = 0;
6028 buf.m.planes = &plane;
6029 buf.length = 1;
6030 if (frameinfo.timestamp >= LLONG_MAX) {
6031 buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID;
6032 }
6033 //assumption is that timestamp is in milliseconds
6034 buf.timestamp.tv_sec = frameinfo.timestamp / 1000000;
6035 buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000);
6036 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0;
6037 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_DECODEONLY) ? V4L2_QCOM_BUF_FLAG_DECODEONLY: 0;
Deva Ramasubramanian46a17952012-08-24 11:35:26 -07006038
Pushkaraj Patil20bd6bf2014-12-22 19:33:08 +05306039 if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
6040 DEBUG_PRINT_LOW("Increment codec_config buffer counter");
6041 android_atomic_inc(&m_queued_codec_config_count);
6042 }
6043
Arun Menon906de572013-06-18 17:01:40 -07006044 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
6045 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006046 DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver");
Arun Menon906de572013-06-18 17:01:40 -07006047 return OMX_ErrorHardware;
6048 }
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -07006049
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07006050 if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
6051 codec_config_flag = false;
6052 }
Arun Menon906de572013-06-18 17:01:40 -07006053 if (!streaming[OUTPUT_PORT]) {
6054 enum v4l2_buf_type buf_type;
6055 int ret,r;
Vinay Kalia85793762012-06-14 19:12:34 -07006056
Arun Menon906de572013-06-18 17:01:40 -07006057 buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006058 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07006059 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
6060 if (!ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006061 DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful");
Arun Menon906de572013-06-18 17:01:40 -07006062 streaming[OUTPUT_PORT] = true;
Jia Meng1e236c82014-04-03 10:54:39 +08006063 } else if (errno == EBUSY) {
6064 DEBUG_PRINT_ERROR("Failed to call stream on OUTPUT due to HW_OVERLOAD");
6065 post_event ((unsigned int)buffer, VDEC_S_SUCCESS,
6066 OMX_COMPONENT_GENERATE_EBD);
6067 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006068 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006069 DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT");
Arun Menon906de572013-06-18 17:01:40 -07006070 DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued");
Jia Meng1e236c82014-04-03 10:54:39 +08006071 post_event ((unsigned int)buffer, VDEC_S_SUCCESS,
Arun Menon906de572013-06-18 17:01:40 -07006072 OMX_COMPONENT_GENERATE_EBD);
6073 return OMX_ErrorBadParameter;
6074 }
6075 }
6076 DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)",
6077 frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006078
Arun Menon906de572013-06-18 17:01:40 -07006079 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006080}
6081
6082/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006083 FUNCTION
6084 omx_vdec::FillThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07006085
Arun Menon906de572013-06-18 17:01:40 -07006086 DESCRIPTION
6087 IL client uses this method to release the frame buffer
6088 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006089
Arun Menon906de572013-06-18 17:01:40 -07006090 PARAMETERS
6091 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006092
Arun Menon906de572013-06-18 17:01:40 -07006093 RETURN VALUE
6094 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006095
Arun Menon906de572013-06-18 17:01:40 -07006096 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006097OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006098 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006099{
Jia Meng2d51b932014-07-10 14:02:54 +08006100 unsigned nPortIndex = 0;
Arun Menonbdb80b02013-08-12 17:45:54 -07006101 if (dynamic_buf_mode) {
6102 private_handle_t *handle = NULL;
6103 struct VideoDecoderOutputMetaData *meta;
Arun Menonbdb80b02013-08-12 17:45:54 -07006104 unsigned int nPortIndex = 0;
6105
6106 if (!buffer || !buffer->pBuffer) {
Arun Menon8544ead2014-05-08 17:42:29 -07006107 DEBUG_PRINT_ERROR("%s: invalid params: %p", __FUNCTION__, buffer);
Arun Menonbdb80b02013-08-12 17:45:54 -07006108 return OMX_ErrorBadParameter;
6109 }
6110
6111 //get the buffer type and fd info
6112 meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer;
6113 handle = (private_handle_t *)meta->pHandle;
Arun Menonb49abf22013-12-14 21:38:10 -08006114 DEBUG_PRINT_LOW("FTB: metabuf: %p buftype: %d bufhndl: %p ", meta, meta->eType, meta->pHandle);
6115
6116 if (!handle) {
6117 DEBUG_PRINT_ERROR("FTB: Error: IL client passed an invalid buf handle - %p", handle);
6118 return OMX_ErrorBadParameter;
6119 }
Arun Menonbdb80b02013-08-12 17:45:54 -07006120 //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF
6121 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
6122 drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd;
Arun Menon50ab1bf2014-01-08 18:02:19 -08006123 drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = (OMX_U8*) buffer;
ApurupaPattapuf693a4d2013-12-04 16:07:07 -08006124
6125 //Store private handle from GraphicBuffer
6126 native_buffer[nPortIndex].privatehandle = handle;
6127 native_buffer[nPortIndex].nativehandle = handle;
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07006128
6129 //buffer->nAllocLen will be sizeof(struct VideoDecoderOutputMetaData). Overwrite
6130 //this with a more sane size so that we don't compensate in rest of code
6131 //We'll restore this size later on, so that it's transparent to client
6132 buffer->nFilledLen = 0;
Deva Ramasubramanian03a5bb92014-04-25 19:03:50 -07006133 buffer->nAllocLen = handle->size;
Arun Menonbdb80b02013-08-12 17:45:54 -07006134 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006135
Arun Menon906de572013-06-18 17:01:40 -07006136 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006137 DEBUG_PRINT_ERROR("FTB in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07006138 return OMX_ErrorInvalidState;
6139 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006140
Arun Menon906de572013-06-18 17:01:40 -07006141 if (!m_out_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006142 DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07006143 return OMX_ErrorIncorrectStateOperation;
6144 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006145
Jia Meng2d51b932014-07-10 14:02:54 +08006146 nPortIndex = buffer - client_buffers.get_il_buf_hdr();
Arun Menon906de572013-06-18 17:01:40 -07006147 if (buffer == NULL ||
Jia Meng2d51b932014-07-10 14:02:54 +08006148 (nPortIndex >= drv_ctx.op_buf.actualcount)) {
6149 DEBUG_PRINT_ERROR("FTB: ERROR: invalid buffer index, nPortIndex %u bufCount %u",
6150 nPortIndex, drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07006151 return OMX_ErrorBadParameter;
6152 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006153
Arun Menon906de572013-06-18 17:01:40 -07006154 if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006155 DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07006156 return OMX_ErrorBadPortIndex;
6157 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006158
Arun Menon906de572013-06-18 17:01:40 -07006159 DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
6160 post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg);
6161 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006162}
6163/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006164 FUNCTION
6165 omx_vdec::fill_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07006166
Arun Menon906de572013-06-18 17:01:40 -07006167 DESCRIPTION
6168 IL client uses this method to release the frame buffer
6169 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006170
Arun Menon906de572013-06-18 17:01:40 -07006171 PARAMETERS
6172 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006173
Arun Menon906de572013-06-18 17:01:40 -07006174 RETURN VALUE
6175 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006176
Arun Menon906de572013-06-18 17:01:40 -07006177 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006178OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy(
Arun Menon906de572013-06-18 17:01:40 -07006179 OMX_IN OMX_HANDLETYPE hComp,
6180 OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006181{
Arun Menon906de572013-06-18 17:01:40 -07006182 OMX_ERRORTYPE nRet = OMX_ErrorNone;
6183 OMX_BUFFERHEADERTYPE *buffer = bufferAdd;
6184 unsigned nPortIndex = 0;
6185 struct vdec_fillbuffer_cmd fillbuffer;
6186 struct vdec_bufferpayload *ptr_outputbuffer = NULL;
6187 struct vdec_output_frameinfo *ptr_respbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006188
Arun Menon906de572013-06-18 17:01:40 -07006189 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
Shalaj Jain273b3e02012-06-22 19:08:03 -07006190
Jia Meng2d51b932014-07-10 14:02:54 +08006191 if (bufferAdd == NULL || nPortIndex > drv_ctx.op_buf.actualcount) {
6192 DEBUG_PRINT_ERROR("FTBProxy: ERROR: invalid buffer index, nPortIndex %u bufCount %u",
6193 nPortIndex, drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07006194 return OMX_ErrorBadParameter;
Jia Meng2d51b932014-07-10 14:02:54 +08006195 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006196
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006197 DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006198 bufferAdd, bufferAdd->pBuffer);
6199 /*Return back the output buffer to client*/
6200 if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006201 DEBUG_PRINT_LOW("Output Buffers return flush/disable condition");
Arun Menon906de572013-06-18 17:01:40 -07006202 buffer->nFilledLen = 0;
6203 m_cb.FillBufferDone (hComp,m_app_data,buffer);
6204 return OMX_ErrorNone;
6205 }
Arun Menon50ab1bf2014-01-08 18:02:19 -08006206
6207 if (dynamic_buf_mode) {
6208 //map the buffer handle based on the size set on output port definition.
6209 if (!secure_mode) {
6210 drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr =
6211 (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size,
6212 PROT_READ|PROT_WRITE, MAP_SHARED,
6213 drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, 0);
6214 }
6215 drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0;
6216 drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size;
6217 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size;
6218 buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd,
6219 drv_ctx.ptr_outputbuffer[nPortIndex].offset);
6220 }
6221
Arun Menon906de572013-06-18 17:01:40 -07006222 pending_output_buffers++;
6223 buffer = client_buffers.get_dr_buf_hdr(bufferAdd);
6224 ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate;
6225 if (ptr_respbuffer) {
6226 ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data;
6227 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006228
Arun Menon906de572013-06-18 17:01:40 -07006229 if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) {
6230 DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL");
6231 buffer->nFilledLen = 0;
6232 m_cb.FillBufferDone (hComp,m_app_data,buffer);
6233 pending_output_buffers--;
6234 return OMX_ErrorBadParameter;
6235 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006236
Arun Menon906de572013-06-18 17:01:40 -07006237 int rc = 0;
6238 struct v4l2_buffer buf;
6239 struct v4l2_plane plane[VIDEO_MAX_PLANES];
6240 memset( (void *)&buf, 0, sizeof(buf));
6241 memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES));
Arun Menon8544ead2014-05-08 17:42:29 -07006242 unsigned int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006243
Arun Menon906de572013-06-18 17:01:40 -07006244 buf.index = nPortIndex;
6245 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
6246 buf.memory = V4L2_MEMORY_USERPTR;
6247 plane[0].bytesused = buffer->nFilledLen;
6248 plane[0].length = drv_ctx.op_buf.buffer_size;
6249 plane[0].m.userptr =
6250 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr -
6251 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset;
6252 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd;
6253 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset;
6254 plane[0].data_offset = 0;
6255 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
6256 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
6257 plane[extra_idx].bytesused = 0;
6258 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
6259 plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + nPortIndex * drv_ctx.extradata_info.buffer_size);
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07006260#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07006261 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07006262#endif
Arun Menon906de572013-06-18 17:01:40 -07006263 plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size;
6264 plane[extra_idx].data_offset = 0;
6265 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Arun Menon8544ead2014-05-08 17:42:29 -07006266 DEBUG_PRINT_ERROR("Extradata index higher than expected: %u", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07006267 return OMX_ErrorBadParameter;
6268 }
6269 buf.m.planes = plane;
6270 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006271 DEBUG_PRINT_LOW("SENDING FTB TO F/W - fd[0] = %d fd[1] = %d offset[1] = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07006272 plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]);
6273
Arun Menon906de572013-06-18 17:01:40 -07006274 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
6275 if (rc) {
6276 /*TODO: How to handle this case */
6277 DEBUG_PRINT_ERROR("Failed to qbuf to driver");
6278 }
Arun Menon906de572013-06-18 17:01:40 -07006279return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006280}
6281
6282/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006283 FUNCTION
6284 omx_vdec::SetCallbacks
Shalaj Jain273b3e02012-06-22 19:08:03 -07006285
Arun Menon906de572013-06-18 17:01:40 -07006286 DESCRIPTION
6287 Set the callbacks.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006288
Arun Menon906de572013-06-18 17:01:40 -07006289 PARAMETERS
6290 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006291
Arun Menon906de572013-06-18 17:01:40 -07006292 RETURN VALUE
6293 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006294
Arun Menon906de572013-06-18 17:01:40 -07006295 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006296OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006297 OMX_IN OMX_CALLBACKTYPE* callbacks,
6298 OMX_IN OMX_PTR appData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006299{
6300
Arun Menon906de572013-06-18 17:01:40 -07006301 m_cb = *callbacks;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006302 DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\
Arun Menon906de572013-06-18 17:01:40 -07006303 m_cb.EventHandler,m_cb.FillBufferDone);
6304 m_app_data = appData;
6305 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006306}
6307
6308/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006309 FUNCTION
6310 omx_vdec::ComponentDeInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07006311
Arun Menon906de572013-06-18 17:01:40 -07006312 DESCRIPTION
6313 Destroys the component and release memory allocated to the heap.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006314
Arun Menon906de572013-06-18 17:01:40 -07006315 PARAMETERS
6316 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006317
Arun Menon906de572013-06-18 17:01:40 -07006318 RETURN VALUE
6319 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006320
Arun Menon906de572013-06-18 17:01:40 -07006321 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006322OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
6323{
6324#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07006325 if (iDivXDrmDecrypt) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006326 delete iDivXDrmDecrypt;
6327 iDivXDrmDecrypt=NULL;
6328 }
6329#endif //_ANDROID_
6330
Shalaj Jain286b0062013-02-21 20:35:48 -08006331 unsigned i = 0;
Arun Menon906de572013-06-18 17:01:40 -07006332 if (OMX_StateLoaded != m_state) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006333 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\
Arun Menon906de572013-06-18 17:01:40 -07006334 m_state);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006335 DEBUG_PRINT_ERROR("Playback Ended - FAILED");
Arun Menon906de572013-06-18 17:01:40 -07006336 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006337 DEBUG_PRINT_HIGH("Playback Ended - PASSED");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006338 }
6339
6340 /*Check if the output buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07006341 if (m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006342 DEBUG_PRINT_LOW("Freeing the Output Memory");
Arun Menon906de572013-06-18 17:01:40 -07006343 for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) {
Praveen Chavan88256fe2016-04-11 17:32:45 -07006344 if (BITMASK_PRESENT(&m_out_bm_count, i)) {
6345 BITMASK_CLEAR(&m_out_bm_count, i);
6346 client_buffers.free_output_buffer (&m_out_mem_ptr[i]);
6347 }
6348
6349 if (release_output_done()) {
6350 break;
6351 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006352 }
6353#ifdef _ANDROID_ICS_
6354 memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
6355#endif
6356 }
6357
6358 /*Check if the input buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07006359 if (m_inp_mem_ptr || m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006360 DEBUG_PRINT_LOW("Freeing the Input Memory");
Arun Menon906de572013-06-18 17:01:40 -07006361 for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) {
Praveen Chavan88256fe2016-04-11 17:32:45 -07006362
6363 if (BITMASK_PRESENT(&m_inp_bm_count, i)) {
6364 BITMASK_CLEAR(&m_inp_bm_count, i);
6365 if (m_inp_mem_ptr)
6366 free_input_buffer (i,&m_inp_mem_ptr[i]);
6367 else
6368 free_input_buffer (i,NULL);
6369 }
6370
6371 if (release_input_done()) {
6372 break;
6373 }
6374 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006375 }
6376 free_input_buffer_header();
6377 free_output_buffer_header();
Arun Menon906de572013-06-18 17:01:40 -07006378 if (h264_scratch.pBuffer) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006379 free(h264_scratch.pBuffer);
6380 h264_scratch.pBuffer = NULL;
6381 }
6382
Arun Menon906de572013-06-18 17:01:40 -07006383 if (h264_parser) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006384 delete h264_parser;
Arun Menon906de572013-06-18 17:01:40 -07006385 h264_parser = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006386 }
6387
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07006388 if (m_frame_parser.mutils) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006389 DEBUG_PRINT_LOW("Free utils parser");
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07006390 delete (m_frame_parser.mutils);
6391 m_frame_parser.mutils = NULL;
6392 }
6393
Arun Menon906de572013-06-18 17:01:40 -07006394 if (m_platform_list) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006395 free(m_platform_list);
6396 m_platform_list = NULL;
6397 }
Arun Menon906de572013-06-18 17:01:40 -07006398 if (m_vendor_config.pData) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006399 free(m_vendor_config.pData);
6400 m_vendor_config.pData = NULL;
6401 }
6402
6403 // Reset counters in mesg queues
6404 m_ftb_q.m_size=0;
6405 m_cmd_q.m_size=0;
6406 m_etb_q.m_size=0;
6407 m_ftb_q.m_read = m_ftb_q.m_write =0;
6408 m_cmd_q.m_read = m_cmd_q.m_write =0;
6409 m_etb_q.m_read = m_etb_q.m_write =0;
6410#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07006411 if (m_debug_timestamp) {
6412 m_timestamp_list.reset_ts_list();
Shalaj Jain273b3e02012-06-22 19:08:03 -07006413 }
6414#endif
6415
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006416 DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006417 //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG,
Arun Menon906de572013-06-18 17:01:40 -07006418 // NULL);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006419 DEBUG_PRINT_HIGH("Close the driver instance");
Arun Menon906de572013-06-18 17:01:40 -07006420
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07006421 if (m_debug.infile) {
6422 fclose(m_debug.infile);
6423 m_debug.infile = NULL;
6424 }
6425 if (m_debug.outfile) {
6426 fclose(m_debug.outfile);
6427 m_debug.outfile = NULL;
6428 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006429#ifdef OUTPUT_EXTRADATA_LOG
Shalaj Jainaf08f302013-03-18 13:15:35 -07006430 if (outputExtradataFile)
6431 fclose (outputExtradataFile);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006432#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006433 DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete");
Arun Menon906de572013-06-18 17:01:40 -07006434 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006435}
6436
6437/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006438 FUNCTION
6439 omx_vdec::UseEGLImage
Shalaj Jain273b3e02012-06-22 19:08:03 -07006440
Arun Menon906de572013-06-18 17:01:40 -07006441 DESCRIPTION
6442 OMX Use EGL Image method implementation <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006443
Arun Menon906de572013-06-18 17:01:40 -07006444 PARAMETERS
6445 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006446
Arun Menon906de572013-06-18 17:01:40 -07006447 RETURN VALUE
6448 Not Implemented error.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006449
Arun Menon906de572013-06-18 17:01:40 -07006450 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006451OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006452 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
6453 OMX_IN OMX_U32 port,
6454 OMX_IN OMX_PTR appData,
6455 OMX_IN void* eglImage)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006456{
Arun Menon906de572013-06-18 17:01:40 -07006457 OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list;
6458 OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry;
6459 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006460
6461#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07006462 PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc;
6463 EGLint fd = -1, offset = 0,pmemPtr = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006464#else
Arun Menon906de572013-06-18 17:01:40 -07006465 int fd = -1, offset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006466#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006467 DEBUG_PRINT_HIGH("use EGL image support for decoder");
Arun Menon906de572013-06-18 17:01:40 -07006468 if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006469 DEBUG_PRINT_ERROR("");
Arun Menon906de572013-06-18 17:01:40 -07006470 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006471#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07006472 if (m_display_id == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006473 DEBUG_PRINT_ERROR("Display ID is not set by IL client");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006474 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006475 }
6476 egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC)
6477 eglGetProcAddress("eglQueryImageKHR");
6478 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd);
6479 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset);
6480 egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006481#else //with OMX test app
6482 struct temp_egl {
6483 int pmem_fd;
6484 int offset;
6485 };
6486 struct temp_egl *temp_egl_id = NULL;
6487 void * pmemPtr = (void *) eglImage;
6488 temp_egl_id = (struct temp_egl *)eglImage;
Arun Menon906de572013-06-18 17:01:40 -07006489 if (temp_egl_id != NULL) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006490 fd = temp_egl_id->pmem_fd;
6491 offset = temp_egl_id->offset;
6492 }
6493#endif
6494 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006495 DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006496 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006497 }
6498 pmem_info.pmem_fd = (OMX_U32) fd;
6499 pmem_info.offset = (OMX_U32) offset;
6500 pmem_entry.entry = (void *) &pmem_info;
6501 pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
6502 pmem_list.entryList = &pmem_entry;
6503 pmem_list.nEntries = 1;
6504 ouput_egl_buffers = true;
6505 if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port,
6506 (void *)&pmem_list, drv_ctx.op_buf.buffer_size,
6507 (OMX_U8 *)pmemPtr)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006508 DEBUG_PRINT_ERROR("use buffer call failed for egl image");
Arun Menon906de572013-06-18 17:01:40 -07006509 return OMX_ErrorInsufficientResources;
6510 }
6511 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006512}
6513
6514/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006515 FUNCTION
6516 omx_vdec::ComponentRoleEnum
Shalaj Jain273b3e02012-06-22 19:08:03 -07006517
Arun Menon906de572013-06-18 17:01:40 -07006518 DESCRIPTION
6519 OMX Component Role Enum method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006520
Arun Menon906de572013-06-18 17:01:40 -07006521 PARAMETERS
6522 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006523
Arun Menon906de572013-06-18 17:01:40 -07006524 RETURN VALUE
6525 OMX Error None if everything is successful.
6526 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006527OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006528 OMX_OUT OMX_U8* role,
6529 OMX_IN OMX_U32 index)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006530{
Arun Menon906de572013-06-18 17:01:40 -07006531 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006532
Arun Menon906de572013-06-18 17:01:40 -07006533 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
6534 if ((0 == index) && role) {
6535 strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006536 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006537 } else {
6538 eRet = OMX_ErrorNoMore;
6539 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006540 }
Arun Menon906de572013-06-18 17:01:40 -07006541 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
6542 if ((0 == index) && role) {
6543 strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006544 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006545 } else {
6546 eRet = OMX_ErrorNoMore;
6547 }
6548 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
6549 if ((0 == index) && role) {
6550 strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006551 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006552 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006553 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006554 eRet = OMX_ErrorNoMore;
6555 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006556 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006557
Arun Menon906de572013-06-18 17:01:40 -07006558 else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
6559 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE))
6560 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07006561
Shalaj Jain273b3e02012-06-22 19:08:03 -07006562 {
Arun Menon906de572013-06-18 17:01:40 -07006563 if ((0 == index) && role) {
6564 strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006565 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006566 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006567 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006568 eRet = OMX_ErrorNoMore;
6569 }
6570 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
6571 if ((0 == index) && role) {
6572 strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006573 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006574 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006575 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006576 eRet = OMX_ErrorNoMore;
6577 }
6578 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
6579 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
6580 ) {
6581 if ((0 == index) && role) {
6582 strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006583 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006584 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006585 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006586 eRet = OMX_ErrorNoMore;
6587 }
6588 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
6589 if ((0 == index) && role) {
6590 strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006591 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006592 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006593 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006594 eRet = OMX_ErrorNoMore;
6595 }
6596 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006597 DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07006598 eRet = OMX_ErrorInvalidComponentName;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006599 }
Arun Menon906de572013-06-18 17:01:40 -07006600 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006601}
6602
6603
6604
6605
6606/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006607 FUNCTION
6608 omx_vdec::AllocateDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006609
Arun Menon906de572013-06-18 17:01:40 -07006610 DESCRIPTION
6611 Checks if entire buffer pool is allocated by IL Client or not.
6612 Need this to move to IDLE state.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006613
Arun Menon906de572013-06-18 17:01:40 -07006614 PARAMETERS
6615 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006616
Arun Menon906de572013-06-18 17:01:40 -07006617 RETURN VALUE
6618 true/false.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006619
Arun Menon906de572013-06-18 17:01:40 -07006620 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006621bool omx_vdec::allocate_done(void)
6622{
Arun Menon906de572013-06-18 17:01:40 -07006623 bool bRet = false;
6624 bool bRet_In = false;
6625 bool bRet_Out = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006626
Arun Menon906de572013-06-18 17:01:40 -07006627 bRet_In = allocate_input_done();
6628 bRet_Out = allocate_output_done();
Shalaj Jain273b3e02012-06-22 19:08:03 -07006629
Arun Menon906de572013-06-18 17:01:40 -07006630 if (bRet_In && bRet_Out) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006631 bRet = true;
6632 }
Arun Menon906de572013-06-18 17:01:40 -07006633
6634 return bRet;
6635}
6636/* ======================================================================
6637 FUNCTION
6638 omx_vdec::AllocateInputDone
6639
6640 DESCRIPTION
6641 Checks if I/P buffer pool is allocated by IL Client or not.
6642
6643 PARAMETERS
6644 None.
6645
6646 RETURN VALUE
6647 true/false.
6648
6649 ========================================================================== */
6650bool omx_vdec::allocate_input_done(void)
6651{
6652 bool bRet = false;
6653 unsigned i=0;
6654
6655 if (m_inp_mem_ptr == NULL) {
6656 return bRet;
6657 }
6658 if (m_inp_mem_ptr ) {
6659 for (; i<drv_ctx.ip_buf.actualcount; i++) {
6660 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
6661 break;
6662 }
6663 }
6664 }
6665 if (i == drv_ctx.ip_buf.actualcount) {
6666 bRet = true;
6667 DEBUG_PRINT_HIGH("Allocate done for all i/p buffers");
6668 }
6669 if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) {
6670 m_inp_bPopulated = OMX_TRUE;
6671 }
6672 return bRet;
6673}
6674/* ======================================================================
6675 FUNCTION
6676 omx_vdec::AllocateOutputDone
6677
6678 DESCRIPTION
6679 Checks if entire O/P buffer pool is allocated by IL Client or not.
6680
6681 PARAMETERS
6682 None.
6683
6684 RETURN VALUE
6685 true/false.
6686
6687 ========================================================================== */
6688bool omx_vdec::allocate_output_done(void)
6689{
6690 bool bRet = false;
6691 unsigned j=0;
6692
6693 if (m_out_mem_ptr == NULL) {
6694 return bRet;
6695 }
6696
6697 if (m_out_mem_ptr) {
6698 for (; j < drv_ctx.op_buf.actualcount; j++) {
6699 if (BITMASK_ABSENT(&m_out_bm_count,j)) {
6700 break;
6701 }
6702 }
6703 }
6704
6705 if (j == drv_ctx.op_buf.actualcount) {
6706 bRet = true;
6707 DEBUG_PRINT_HIGH("Allocate done for all o/p buffers");
6708 if (m_out_bEnabled)
6709 m_out_bPopulated = OMX_TRUE;
6710 }
6711
6712 return bRet;
6713}
6714
6715/* ======================================================================
6716 FUNCTION
6717 omx_vdec::ReleaseDone
6718
6719 DESCRIPTION
6720 Checks if IL client has released all the buffers.
6721
6722 PARAMETERS
6723 None.
6724
6725 RETURN VALUE
6726 true/false
6727
6728 ========================================================================== */
6729bool omx_vdec::release_done(void)
6730{
6731 bool bRet = false;
6732
6733 if (release_input_done()) {
6734 if (release_output_done()) {
6735 bRet = true;
6736 }
6737 }
6738 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006739}
6740
6741
6742/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006743 FUNCTION
6744 omx_vdec::ReleaseOutputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006745
Arun Menon906de572013-06-18 17:01:40 -07006746 DESCRIPTION
6747 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006748
Arun Menon906de572013-06-18 17:01:40 -07006749 PARAMETERS
6750 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006751
Arun Menon906de572013-06-18 17:01:40 -07006752 RETURN VALUE
6753 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006754
Arun Menon906de572013-06-18 17:01:40 -07006755 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006756bool omx_vdec::release_output_done(void)
6757{
Arun Menon906de572013-06-18 17:01:40 -07006758 bool bRet = false;
6759 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006760
Praveen Chavan88256fe2016-04-11 17:32:45 -07006761 DEBUG_PRINT_LOW("Value of m_out_mem_ptr %p",m_out_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006762 if (m_out_mem_ptr) {
6763 for (; j < drv_ctx.op_buf.actualcount ; j++) {
6764 if (BITMASK_PRESENT(&m_out_bm_count,j)) {
6765 break;
6766 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006767 }
Arun Menon906de572013-06-18 17:01:40 -07006768 if (j == drv_ctx.op_buf.actualcount) {
6769 m_out_bm_count = 0;
6770 bRet = true;
6771 }
6772 } else {
6773 m_out_bm_count = 0;
6774 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006775 }
Arun Menon906de572013-06-18 17:01:40 -07006776 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006777}
6778/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006779 FUNCTION
6780 omx_vdec::ReleaseInputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006781
Arun Menon906de572013-06-18 17:01:40 -07006782 DESCRIPTION
6783 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006784
Arun Menon906de572013-06-18 17:01:40 -07006785 PARAMETERS
6786 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006787
Arun Menon906de572013-06-18 17:01:40 -07006788 RETURN VALUE
6789 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006790
Arun Menon906de572013-06-18 17:01:40 -07006791 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006792bool omx_vdec::release_input_done(void)
6793{
Arun Menon906de572013-06-18 17:01:40 -07006794 bool bRet = false;
6795 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006796
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006797 DEBUG_PRINT_LOW("Value of m_inp_mem_ptr %p",m_inp_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006798 if (m_inp_mem_ptr) {
6799 for (; j<drv_ctx.ip_buf.actualcount; j++) {
6800 if ( BITMASK_PRESENT(&m_inp_bm_count,j)) {
6801 break;
6802 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006803 }
Arun Menon906de572013-06-18 17:01:40 -07006804 if (j==drv_ctx.ip_buf.actualcount) {
6805 bRet = true;
6806 }
6807 } else {
6808 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006809 }
Arun Menon906de572013-06-18 17:01:40 -07006810 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006811}
6812
6813OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006814 OMX_BUFFERHEADERTYPE * buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006815{
Arun Menon906de572013-06-18 17:01:40 -07006816 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL;
Surajit Podderd2644d52013-08-28 17:59:06 +05306817 if (!buffer || (buffer - m_out_mem_ptr) >= (int)drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006818 DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer);
Arun Menon906de572013-06-18 17:01:40 -07006819 return OMX_ErrorBadParameter;
6820 } else if (output_flush_progress) {
6821 DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer);
6822 buffer->nFilledLen = 0;
6823 buffer->nTimeStamp = 0;
6824 buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA;
6825 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
6826 buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT;
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006827 }
6828
Arun Menon906de572013-06-18 17:01:40 -07006829 if (m_debug_extradata) {
6830 if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006831 DEBUG_PRINT_HIGH("");
6832 DEBUG_PRINT_HIGH("***************************************************");
6833 DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received");
6834 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006835 }
6836
6837 if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006838 DEBUG_PRINT_HIGH("");
6839 DEBUG_PRINT_HIGH("***************************************************");
6840 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
6841 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006842 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006843 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006844
6845
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006846 DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006847 buffer, buffer->pBuffer);
6848 pending_output_buffers --;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006849
Arun Menon906de572013-06-18 17:01:40 -07006850 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006851 DEBUG_PRINT_HIGH("Output EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07006852 if (!output_flush_progress)
6853 post_event((unsigned)NULL, (unsigned)NULL,
6854 OMX_COMPONENT_GENERATE_EOS_DONE);
6855
6856 if (psource_frame) {
6857 m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame);
6858 psource_frame = NULL;
6859 }
6860 if (pdest_frame) {
6861 pdest_frame->nFilledLen = 0;
6862 m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL,
6863 (unsigned)NULL);
6864 pdest_frame = NULL;
6865 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006866 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006867
Shalaj Jain273b3e02012-06-22 19:08:03 -07006868
Praneeth Paladugudd29c282013-09-12 15:41:47 -07006869 if (!output_flush_progress && (buffer->nFilledLen > 0)) {
6870 DEBUG_PRINT_LOW("Processing extradata");
6871 handle_extradata(buffer);
6872 }
6873
Arun Menon906de572013-06-18 17:01:40 -07006874 /* For use buffer we need to copy the data */
6875 if (!output_flush_progress) {
6876 /* This is the error check for non-recoverable errros */
6877 bool is_duplicate_ts_valid = true;
6878 bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006879
Arun Menon906de572013-06-18 17:01:40 -07006880 if (output_capability == V4L2_PIX_FMT_MPEG4 ||
6881 output_capability == V4L2_PIX_FMT_MPEG2 ||
6882 output_capability == V4L2_PIX_FMT_DIVX ||
6883 output_capability == V4L2_PIX_FMT_DIVX_311)
6884 is_duplicate_ts_valid = false;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006885
Arun Menon906de572013-06-18 17:01:40 -07006886 if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) {
Arun Menon7b6fd642014-02-13 16:48:36 -08006887 if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF) {
Arun Menon906de572013-06-18 17:01:40 -07006888 is_interlaced = false;
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306889 }
Arun Menon906de572013-06-18 17:01:40 -07006890 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306891
Arun Menon906de572013-06-18 17:01:40 -07006892 if (buffer->nFilledLen > 0) {
6893 time_stamp_dts.get_next_timestamp(buffer,
6894 is_interlaced && is_duplicate_ts_valid);
6895 if (m_debug_timestamp) {
6896 {
6897 OMX_TICKS expected_ts = 0;
6898 m_timestamp_list.pop_min_ts(expected_ts);
6899 if (is_interlaced && is_duplicate_ts_valid) {
6900 m_timestamp_list.pop_min_ts(expected_ts);
6901 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006902 DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list",
Arun Menon906de572013-06-18 17:01:40 -07006903 buffer->nTimeStamp, expected_ts);
6904
6905 if (buffer->nTimeStamp != expected_ts) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006906 DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check");
Arun Menon906de572013-06-18 17:01:40 -07006907 }
6908 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306909 }
Arun Menon906de572013-06-18 17:01:40 -07006910 } else {
Arun Menon906de572013-06-18 17:01:40 -07006911 time_stamp_dts.remove_time_stamp(
6912 buffer->nTimeStamp,
6913 is_interlaced && is_duplicate_ts_valid);
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306914 }
Arun Menon906de572013-06-18 17:01:40 -07006915
6916
Praneeth Paladugu8f12e822013-03-11 18:47:58 -07006917 }
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006918
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07006919 /* Since we're passing around handles, adjust nFilledLen and nAllocLen
6920 * to size of the handle. Do it _after_ handle_extradata() which
6921 * requires the respective sizes to be accurate. */
6922 if (dynamic_buf_mode) {
6923 buffer->nAllocLen = sizeof(struct VideoDecoderOutputMetaData);
6924 buffer->nFilledLen = buffer->nFilledLen ?
6925 sizeof(struct VideoDecoderOutputMetaData) : 0;
6926 }
6927
Arun Menon906de572013-06-18 17:01:40 -07006928 if (m_cb.FillBufferDone) {
6929 if (buffer->nFilledLen > 0) {
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006930 if (arbitrary_bytes)
Arun Menon906de572013-06-18 17:01:40 -07006931 adjust_timestamp(buffer->nTimeStamp);
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006932 else
6933 set_frame_rate(buffer->nTimeStamp);
6934
Arun Menon906de572013-06-18 17:01:40 -07006935 if (perf_flag) {
6936 if (!proc_frms) {
6937 dec_time.stop();
6938 latency = dec_time.processing_time_us() - latency;
6939 DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3);
6940 dec_time.start();
6941 fps_metrics.start();
6942 }
6943 proc_frms++;
6944 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6945 OMX_U64 proc_time = 0;
6946 fps_metrics.stop();
6947 proc_time = fps_metrics.processing_time_us();
6948 DEBUG_PRINT_HIGH(">>> FBD Metrics: proc_frms(%lu) proc_time(%.2f)S fps(%.2f)",
Shalaj Jain273b3e02012-06-22 19:08:03 -07006949 proc_frms, (float)proc_time / 1e6,
6950 (float)(1e6 * proc_frms) / proc_time);
Arun Menon906de572013-06-18 17:01:40 -07006951 proc_frms = 0;
6952 }
6953 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006954
6955#ifdef OUTPUT_EXTRADATA_LOG
Arun Menon906de572013-06-18 17:01:40 -07006956 if (outputExtradataFile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006957
Arun Menon906de572013-06-18 17:01:40 -07006958 OMX_OTHER_EXTRADATATYPE *p_extra = NULL;
6959 p_extra = (OMX_OTHER_EXTRADATATYPE *)
6960 ((unsigned)(buffer->pBuffer + buffer->nOffset +
6961 buffer->nFilledLen + 3)&(~3));
6962 while (p_extra &&
6963 (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006964 DEBUG_PRINT_LOW("WRITING extradata, size=%d,type=%d",p_extra->nSize, p_extra->eType);
Arun Menon906de572013-06-18 17:01:40 -07006965 fwrite (p_extra,1,p_extra->nSize,outputExtradataFile);
6966 if (p_extra->eType == OMX_ExtraDataNone) {
6967 break;
6968 }
6969 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
6970 }
6971 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006972#endif
Arun Menon906de572013-06-18 17:01:40 -07006973 }
6974 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6975 prev_ts = LLONG_MAX;
6976 rst_prev_ts = true;
6977 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006978
Arun Menon906de572013-06-18 17:01:40 -07006979 pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
6980 ((OMX_QCOM_PLATFORM_PRIVATE_LIST *)
6981 buffer->pPlatformPrivate)->entryList->entry;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006982 DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07006983 OMX_BUFFERHEADERTYPE *il_buffer;
6984 il_buffer = client_buffers.get_il_buf_hdr(buffer);
vivek mehtaa75c69f2014-01-10 21:50:37 -08006985
vivek mehta79cff222014-01-22 12:17:07 -08006986 if (il_buffer && m_last_rendered_TS >= 0) {
6987 int current_framerate = (int)(drv_ctx.frame_rate.fps_numerator /drv_ctx.frame_rate.fps_denominator);
Manikanta Kanamarlapudifb53b262014-01-20 16:12:47 +05306988 OMX_TICKS ts_delta = (OMX_TICKS)llabs(il_buffer->nTimeStamp - m_last_rendered_TS);
vivek mehta79cff222014-01-22 12:17:07 -08006989
6990 // Current frame can be send for rendering if
6991 // (a) current FPS is <= 60
6992 // (b) is the next frame after the frame with TS 0
6993 // (c) is the first frame after seek
6994 // (d) the delta TS b\w two consecutive frames is > 16 ms
6995 // (e) its TS is equal to previous frame TS
6996 // (f) if marked EOS
6997
6998 if(current_framerate <= 60 || m_last_rendered_TS == 0 ||
6999 il_buffer->nTimeStamp == 0 || ts_delta >= 16000 ||
7000 ts_delta == 0 || (il_buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
vivek mehtaa75c69f2014-01-10 21:50:37 -08007001 m_last_rendered_TS = il_buffer->nTimeStamp;
vivek mehta79cff222014-01-22 12:17:07 -08007002 } else {
vivek mehtaa75c69f2014-01-10 21:50:37 -08007003 //mark for droping
vivek mehtaa75c69f2014-01-10 21:50:37 -08007004 buffer->nFilledLen = 0;
vivek mehta79cff222014-01-22 12:17:07 -08007005 }
7006
7007 DEBUG_PRINT_LOW(" -- %s Frame -- info:: fps(%d) lastRenderTime(%lld) bufferTs(%lld) ts_delta(%d)",
7008 buffer->nFilledLen? "Rendering":"Dropping",current_framerate,m_last_rendered_TS,
7009 il_buffer->nTimeStamp,ts_delta);
vivek mehtaa75c69f2014-01-10 21:50:37 -08007010 }
7011
vivek mehta79cff222014-01-22 12:17:07 -08007012 if (il_buffer) {
Arun Menon9230eb82014-02-11 19:19:02 -08007013 log_output_buffers(il_buffer);
7014 if (dynamic_buf_mode) {
7015 unsigned int nPortIndex = 0;
7016 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
7017
7018 if (!secure_mode) {
7019 munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr,
7020 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size);
7021 }
7022
7023 //Clear graphic buffer handles in dynamic mode
7024 native_buffer[nPortIndex].privatehandle = NULL;
7025 native_buffer[nPortIndex].nativehandle = NULL;
7026 }
Arun Menon906de572013-06-18 17:01:40 -07007027 m_cb.FillBufferDone (hComp,m_app_data,il_buffer);
vivek mehta79cff222014-01-22 12:17:07 -08007028 } else {
Arun Menon906de572013-06-18 17:01:40 -07007029 DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr");
7030 return OMX_ErrorBadParameter;
7031 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007032 DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07007033 } else {
7034 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08007035 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007036
Praveen Chavancf924182013-12-06 23:16:23 -08007037#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05307038 if (m_smoothstreaming_mode && m_out_mem_ptr) {
Praveen Chavancf924182013-12-06 23:16:23 -08007039 OMX_U32 buf_index = buffer - m_out_mem_ptr;
7040 BufferDim_t dim;
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05307041 private_handle_t *private_handle = NULL;
Pushkaraj Patil065b5732014-11-26 11:08:02 +05307042 dim.sliceWidth = framesize.nWidth;
7043 dim.sliceHeight = framesize.nHeight;
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05307044 if (native_buffer[buf_index].privatehandle)
7045 private_handle = native_buffer[buf_index].privatehandle;
Praveen Chavancf924182013-12-06 23:16:23 -08007046 if (private_handle) {
7047 DEBUG_PRINT_LOW("set metadata: update buf-geometry with stride %d slice %d",
7048 dim.sliceWidth, dim.sliceHeight);
7049 setMetaData(private_handle, UPDATE_BUFFER_GEOMETRY, (void*)&dim);
7050 }
7051 }
7052#endif
7053
Arun Menon906de572013-06-18 17:01:40 -07007054 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007055}
7056
7057OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07007058 OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007059{
7060
Surajit Podderd2644d52013-08-28 17:59:06 +05307061 if (buffer == NULL || ((buffer - m_inp_mem_ptr) > (int)drv_ctx.ip_buf.actualcount)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007062 DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer);
Arun Menon906de572013-06-18 17:01:40 -07007063 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007064 }
7065
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007066 DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07007067 buffer, buffer->pBuffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007068 pending_input_buffers--;
7069
Arun Menon906de572013-06-18 17:01:40 -07007070 if (arbitrary_bytes) {
7071 if (pdest_frame == NULL && input_flush_progress == false) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007072 DEBUG_PRINT_LOW("Push input from buffer done address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07007073 pdest_frame = buffer;
7074 buffer->nFilledLen = 0;
7075 buffer->nTimeStamp = LLONG_MAX;
7076 push_input_buffer (hComp);
7077 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007078 DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07007079 buffer->nFilledLen = 0;
7080 if (!m_input_free_q.insert_entry((unsigned)buffer,
7081 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007082 DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error");
Arun Menon906de572013-06-18 17:01:40 -07007083 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007084 }
Arun Menon906de572013-06-18 17:01:40 -07007085 } else if (m_cb.EmptyBufferDone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007086 buffer->nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07007087 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007088 buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr];
7089 }
7090 m_cb.EmptyBufferDone(hComp ,m_app_data, buffer);
7091 }
7092 return OMX_ErrorNone;
7093}
7094
Shalaj Jain273b3e02012-06-22 19:08:03 -07007095int omx_vdec::async_message_process (void *context, void* message)
7096{
Arun Menon906de572013-06-18 17:01:40 -07007097 omx_vdec* omx = NULL;
7098 struct vdec_msginfo *vdec_msg = NULL;
7099 OMX_BUFFERHEADERTYPE* omxhdr = NULL;
7100 struct v4l2_buffer *v4l2_buf_ptr = NULL;
7101 struct vdec_output_frameinfo *output_respbuf = NULL;
7102 int rc=1;
7103 if (context == NULL || message == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007104 DEBUG_PRINT_ERROR("FATAL ERROR in omx_vdec::async_message_process NULL Check");
Arun Menon906de572013-06-18 17:01:40 -07007105 return -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007106 }
Arun Menon906de572013-06-18 17:01:40 -07007107 vdec_msg = (struct vdec_msginfo *)message;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007108
Arun Menon906de572013-06-18 17:01:40 -07007109 omx = reinterpret_cast<omx_vdec*>(context);
Vinay Kaliab9e98102013-04-02 19:31:43 -07007110
Arun Menon906de572013-06-18 17:01:40 -07007111 switch (vdec_msg->msgcode) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007112
Arun Menon906de572013-06-18 17:01:40 -07007113 case VDEC_MSG_EVT_HW_ERROR:
7114 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7115 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
7116 break;
7117
Deepak Verma24720fb2014-01-29 16:57:40 +05307118 case VDEC_MSG_EVT_HW_OVERLOAD:
7119 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7120 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD);
7121 break;
7122
Arun Menon906de572013-06-18 17:01:40 -07007123 case VDEC_MSG_RESP_START_DONE:
7124 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7125 OMX_COMPONENT_GENERATE_START_DONE);
7126 break;
7127
7128 case VDEC_MSG_RESP_STOP_DONE:
7129 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7130 OMX_COMPONENT_GENERATE_STOP_DONE);
7131 break;
7132
7133 case VDEC_MSG_RESP_RESUME_DONE:
7134 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7135 OMX_COMPONENT_GENERATE_RESUME_DONE);
7136 break;
7137
7138 case VDEC_MSG_RESP_PAUSE_DONE:
7139 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7140 OMX_COMPONENT_GENERATE_PAUSE_DONE);
7141 break;
7142
7143 case VDEC_MSG_RESP_FLUSH_INPUT_DONE:
7144 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7145 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
7146 break;
7147 case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE:
7148 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7149 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
7150 break;
7151 case VDEC_MSG_RESP_INPUT_FLUSHED:
7152 case VDEC_MSG_RESP_INPUT_BUFFER_DONE:
7153
7154 /* omxhdr = (OMX_BUFFERHEADERTYPE* )
7155 vdec_msg->msgdata.input_frame_clientdata; */
7156
7157 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata;
7158 omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index;
7159 if (omxhdr == NULL ||
Surajit Podderd2644d52013-08-28 17:59:06 +05307160 ((omxhdr - omx->m_inp_mem_ptr) > (int)omx->drv_ctx.ip_buf.actualcount) ) {
Arun Menon906de572013-06-18 17:01:40 -07007161 omxhdr = NULL;
7162 vdec_msg->status_code = VDEC_S_EFATAL;
7163 }
7164 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) {
7165 DEBUG_PRINT_HIGH("Unsupported input");
7166 omx->omx_report_error ();
7167 }
7168 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
7169 vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR;
7170 }
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307171 if (omxhdr->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307172
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05307173 DEBUG_PRINT_LOW("Decrement codec_config buffer counter");
7174 android_atomic_dec(&omx->m_queued_codec_config_count);
7175 if ((android_atomic_add(0, &omx->m_queued_codec_config_count) == 0) &&
7176 BITMASK_PRESENT(&omx->m_flags, OMX_COMPONENT_FLUSH_DEFERRED)) {
7177 DEBUG_PRINT_LOW("sem post for CODEC CONFIG buffer");
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307178 sem_post(&omx->m_safe_flush);
7179 }
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307180 }
7181
Arun Menon906de572013-06-18 17:01:40 -07007182 omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code,
7183 OMX_COMPONENT_GENERATE_EBD);
7184 break;
7185 case VDEC_MSG_EVT_INFO_FIELD_DROPPED:
7186 int64_t *timestamp;
7187 timestamp = (int64_t *) malloc(sizeof(int64_t));
7188 if (timestamp) {
7189 *timestamp = vdec_msg->msgdata.output_frame.time_stamp;
7190 omx->post_event ((unsigned int)timestamp, vdec_msg->status_code,
7191 OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007192 DEBUG_PRINT_HIGH("Field dropped time stamp is %lld",
Arun Menon906de572013-06-18 17:01:40 -07007193 vdec_msg->msgdata.output_frame.time_stamp);
7194 }
7195 break;
7196 case VDEC_MSG_RESP_OUTPUT_FLUSHED:
7197 case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE:
7198
7199 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data;
7200 omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307201
7202 DEBUG_PRINT_LOW("[RespBufDone] Buf(%p) Ts(%lld) PicType(%u) Flags (0x%x) FillLen(%u) Crop: L(%u) T(%u) R(%u) B(%u)",
Arun Menon906de572013-06-18 17:01:40 -07007203 omxhdr, vdec_msg->msgdata.output_frame.time_stamp,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307204 vdec_msg->msgdata.output_frame.pic_type, v4l2_buf_ptr->flags,
7205 (unsigned int)vdec_msg->msgdata.output_frame.len,
7206 vdec_msg->msgdata.output_frame.framesize.left,
7207 vdec_msg->msgdata.output_frame.framesize.top,
7208 vdec_msg->msgdata.output_frame.framesize.right,
7209 vdec_msg->msgdata.output_frame.framesize.bottom);
Arun Menon906de572013-06-18 17:01:40 -07007210
7211 if (omxhdr && omxhdr->pOutputPortPrivate &&
Surajit Podderd2644d52013-08-28 17:59:06 +05307212 ((omxhdr - omx->m_out_mem_ptr) < (int)omx->drv_ctx.op_buf.actualcount) &&
Arun Menon906de572013-06-18 17:01:40 -07007213 (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate
Surajit Podderd2644d52013-08-28 17:59:06 +05307214 - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307215
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07007216 if (vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) {
Arun Menon906de572013-06-18 17:01:40 -07007217 omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len;
7218 omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset;
7219 omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp;
7220 omxhdr->nFlags = 0;
7221
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07007222 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) {
Arun Menon906de572013-06-18 17:01:40 -07007223 omxhdr->nFlags |= OMX_BUFFERFLAG_EOS;
7224 //rc = -1;
7225 }
7226 if (omxhdr->nFilledLen) {
7227 omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
7228 }
7229 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) {
7230 omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
7231 } else {
7232 omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME;
7233 }
7234 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) {
7235 omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
7236 }
7237 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) {
7238 omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY;
7239 }
Arun Menon7b6fd642014-02-13 16:48:36 -08007240
7241 if (v4l2_buf_ptr->flags & V4L2_MSM_BUF_FLAG_MBAFF) {
7242 omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_MBAFF;
7243 }
7244
Arun Menonbdb80b02013-08-12 17:45:54 -07007245 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) {
Arun Menone50f6ef2013-09-30 15:08:27 -07007246 omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY;
Arun Menonbdb80b02013-08-12 17:45:54 -07007247 DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d",
7248 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd);
7249 }
Arun Menonbdb80b02013-08-12 17:45:54 -07007250 if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) {
7251 omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd,
7252 omxhdr->nOffset);
7253 }
Arun Menon906de572013-06-18 17:01:40 -07007254 if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) &&
7255 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) &&
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07007256 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) {
Praneeth Paladugu17364df2013-07-30 11:34:16 -07007257 omx->time_stamp_dts.remove_time_stamp(
7258 omxhdr->nTimeStamp,
7259 (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
7260 ?true:false);
Arun Menon906de572013-06-18 17:01:40 -07007261 omx->post_event ((unsigned)NULL,(unsigned int)omxhdr,
7262 OMX_COMPONENT_GENERATE_FTB);
7263 break;
7264 }
7265 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
7266 omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
7267 }
7268 vdec_msg->msgdata.output_frame.bufferaddr =
7269 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307270
7271 /* Post event if resolution OR crop changed */
7272 /* filled length will be changed if resolution changed */
7273 /* Crop parameters can be changed even without resolution change */
7274 if (omxhdr->nFilledLen
7275 && ((omx->prev_n_filled_len != omxhdr->nFilledLen)
7276 || (omx->drv_ctx.frame_size.left != vdec_msg->msgdata.output_frame.framesize.left)
7277 || (omx->drv_ctx.frame_size.top != vdec_msg->msgdata.output_frame.framesize.top)
7278 || (omx->drv_ctx.frame_size.right != vdec_msg->msgdata.output_frame.framesize.right)
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05307279 || (omx->drv_ctx.frame_size.bottom != vdec_msg->msgdata.output_frame.framesize.bottom)
7280 || (omx->drv_ctx.video_resolution.frame_width != vdec_msg->msgdata.output_frame.picsize.frame_width)
7281 || (omx->drv_ctx.video_resolution.frame_height != vdec_msg->msgdata.output_frame.picsize.frame_height) )) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307282
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05307283 DEBUG_PRINT_HIGH("Paramters Changed From: Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u --> Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u",
7284 omx->prev_n_filled_len,
7285 omx->drv_ctx.video_resolution.frame_width,
7286 omx->drv_ctx.video_resolution.frame_height,
7287 omx->drv_ctx.frame_size.left, omx->drv_ctx.frame_size.top,
7288 omx->drv_ctx.frame_size.right, omx->drv_ctx.frame_size.bottom,
7289 omxhdr->nFilledLen, vdec_msg->msgdata.output_frame.picsize.frame_width,
7290 vdec_msg->msgdata.output_frame.picsize.frame_height,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307291 vdec_msg->msgdata.output_frame.framesize.left,
7292 vdec_msg->msgdata.output_frame.framesize.top,
7293 vdec_msg->msgdata.output_frame.framesize.right,
7294 vdec_msg->msgdata.output_frame.framesize.bottom);
7295
Maheshwar Ajja0f840ce2014-09-29 16:53:42 +05307296 omx->drv_ctx.video_resolution.frame_width =
7297 vdec_msg->msgdata.output_frame.picsize.frame_width;
7298 omx->drv_ctx.video_resolution.frame_height =
7299 vdec_msg->msgdata.output_frame.picsize.frame_height;
Praneeth Paladuguca80be72014-10-22 23:48:54 -07007300 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) {
7301 omx->drv_ctx.video_resolution.stride =
7302 VENUS_Y_STRIDE(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_width);
7303 omx->drv_ctx.video_resolution.scan_lines =
7304 VENUS_Y_SCANLINES(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_height);
7305 }
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307306 memcpy(&omx->drv_ctx.frame_size,
7307 &vdec_msg->msgdata.output_frame.framesize,
7308 sizeof(struct vdec_framesize));
7309
7310 omx->post_event(OMX_CORE_OUTPUT_PORT_INDEX,
7311 OMX_IndexConfigCommonOutputCrop,
7312 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
Arun Menon906de572013-06-18 17:01:40 -07007313 }
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307314
Arun Menon906de572013-06-18 17:01:40 -07007315 if (omxhdr->nFilledLen)
7316 omx->prev_n_filled_len = omxhdr->nFilledLen;
7317
7318 output_respbuf = (struct vdec_output_frameinfo *)\
7319 omxhdr->pOutputPortPrivate;
7320 output_respbuf->len = vdec_msg->msgdata.output_frame.len;
7321 output_respbuf->offset = vdec_msg->msgdata.output_frame.offset;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307322
Arun Menon906de572013-06-18 17:01:40 -07007323 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) {
7324 output_respbuf->pic_type = PICTURE_TYPE_I;
7325 }
7326 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) {
7327 output_respbuf->pic_type = PICTURE_TYPE_P;
7328 }
7329 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) {
7330 output_respbuf->pic_type = PICTURE_TYPE_B;
7331 }
7332
7333 if (omx->output_use_buffer)
7334 memcpy ( omxhdr->pBuffer, (void *)
7335 ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr +
7336 (unsigned long)vdec_msg->msgdata.output_frame.offset),
7337 vdec_msg->msgdata.output_frame.len);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307338 } else {
7339 DEBUG_PRINT_ERROR("Invalid filled length = %u, buffer size = %u, prev_length = %u",
7340 (unsigned int)vdec_msg->msgdata.output_frame.len,
7341 omxhdr->nAllocLen, omx->prev_n_filled_len);
Arun Menon906de572013-06-18 17:01:40 -07007342 omxhdr->nFilledLen = 0;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307343 }
7344
Arun Menon906de572013-06-18 17:01:40 -07007345 omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code,
7346 OMX_COMPONENT_GENERATE_FBD);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307347
7348 } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) {
Arun Menon906de572013-06-18 17:01:40 -07007349 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
7350 OMX_COMPONENT_GENERATE_EOS_DONE);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307351 } else {
Arun Menon906de572013-06-18 17:01:40 -07007352 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
7353 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307354 }
Arun Menon906de572013-06-18 17:01:40 -07007355 break;
7356 case VDEC_MSG_EVT_CONFIG_CHANGED:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007357 DEBUG_PRINT_HIGH("Port settings changed");
Arun Menon906de572013-06-18 17:01:40 -07007358 omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition,
7359 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
7360 break;
7361 default:
7362 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007363 }
Arun Menon906de572013-06-18 17:01:40 -07007364 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007365}
7366
7367OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary (
Arun Menon906de572013-06-18 17:01:40 -07007368 OMX_HANDLETYPE hComp,
7369 OMX_BUFFERHEADERTYPE *buffer
7370 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07007371{
Arun Menon906de572013-06-18 17:01:40 -07007372 unsigned address,p2,id;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007373 DEBUG_PRINT_LOW("Empty this arbitrary");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007374
Arun Menon906de572013-06-18 17:01:40 -07007375 if (buffer == NULL) {
7376 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007377 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007378 DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
7379 DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07007380 buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp);
7381
7382 /* return zero length and not an EOS buffer */
7383 /* return buffer if input flush in progress */
7384 if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) &&
7385 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007386 DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress");
Arun Menon906de572013-06-18 17:01:40 -07007387 m_cb.EmptyBufferDone (hComp,m_app_data,buffer);
7388 return OMX_ErrorNone;
7389 }
7390
7391 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007392 DEBUG_PRINT_LOW("Set Buffer as source Buffer %p time stamp %lld",buffer,buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07007393 psource_frame = buffer;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007394 DEBUG_PRINT_LOW("Try to Push One Input Buffer ");
Arun Menon906de572013-06-18 17:01:40 -07007395 push_input_buffer (hComp);
7396 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007397 DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07007398 if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL,
7399 (unsigned)NULL)) {
7400 return OMX_ErrorBadParameter;
7401 }
7402 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007403
Sowmya Pandiri302f5ab2014-04-03 13:41:03 -07007404 if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
7405 codec_config_flag = false;
7406 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007407
Arun Menon906de572013-06-18 17:01:40 -07007408 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007409}
7410
7411OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp)
7412{
Arun Menon906de572013-06-18 17:01:40 -07007413 unsigned address,p2,id;
7414 OMX_ERRORTYPE ret = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007415
Arun Menon906de572013-06-18 17:01:40 -07007416 if (pdest_frame == NULL || psource_frame == NULL) {
7417 /*Check if we have a destination buffer*/
7418 if (pdest_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007419 DEBUG_PRINT_LOW("Get a Destination buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07007420 if (m_input_free_q.m_size) {
7421 m_input_free_q.pop_entry(&address,&p2,&id);
7422 pdest_frame = (OMX_BUFFERHEADERTYPE *)address;
7423 pdest_frame->nFilledLen = 0;
7424 pdest_frame->nTimeStamp = LLONG_MAX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007425 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07007426 }
7427 }
7428
7429 /*Check if we have a destination buffer*/
7430 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007431 DEBUG_PRINT_LOW("Get a source buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07007432 if (m_input_pending_q.m_size) {
7433 m_input_pending_q.pop_entry(&address,&p2,&id);
7434 psource_frame = (OMX_BUFFERHEADERTYPE *)address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007435 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07007436 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007437 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007438 psource_frame->nFlags,psource_frame->nFilledLen);
7439
7440 }
7441 }
7442
Shalaj Jain273b3e02012-06-22 19:08:03 -07007443 }
7444
Arun Menon906de572013-06-18 17:01:40 -07007445 while ((pdest_frame != NULL) && (psource_frame != NULL)) {
7446 switch (codec_type_parse) {
7447 case CODEC_TYPE_MPEG4:
7448 case CODEC_TYPE_H263:
7449 case CODEC_TYPE_MPEG2:
7450 ret = push_input_sc_codec(hComp);
7451 break;
7452 case CODEC_TYPE_H264:
7453 ret = push_input_h264(hComp);
7454 break;
7455 case CODEC_TYPE_VC1:
7456 ret = push_input_vc1(hComp);
7457 break;
7458 default:
7459 break;
7460 }
7461 if (ret != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007462 DEBUG_PRINT_ERROR("Pushing input Buffer Failed");
Arun Menon906de572013-06-18 17:01:40 -07007463 omx_report_error ();
7464 break;
7465 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007466 }
7467
Arun Menon906de572013-06-18 17:01:40 -07007468 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007469}
7470
7471OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp)
7472{
Arun Menon906de572013-06-18 17:01:40 -07007473 OMX_U32 partial_frame = 1;
7474 OMX_BOOL generate_ebd = OMX_TRUE;
7475 unsigned address = 0, p2 = 0, id = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007476
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007477 DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07007478 psource_frame,psource_frame->nTimeStamp);
7479 if (m_frame_parser.parse_sc_frame(psource_frame,
7480 pdest_frame,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007481 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Arun Menon906de572013-06-18 17:01:40 -07007482 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007483 }
Arun Menon906de572013-06-18 17:01:40 -07007484
7485 if (partial_frame == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007486 DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d",
Arun Menon906de572013-06-18 17:01:40 -07007487 pdest_frame->nFilledLen,psource_frame,frame_count);
7488
7489
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007490 DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07007491 /*First Parsed buffer will have only header Hence skip*/
7492 if (frame_count == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007493 DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame ");
Arun Menon906de572013-06-18 17:01:40 -07007494
7495 if (codec_type_parse == CODEC_TYPE_MPEG4 ||
7496 codec_type_parse == CODEC_TYPE_DIVX) {
7497 mp4StreamType psBits;
7498 psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset;
7499 psBits.numBytes = pdest_frame->nFilledLen;
7500 mp4_headerparser.parseHeader(&psBits);
7501 }
7502
7503 frame_count++;
7504 } else {
7505 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
7506 if (pdest_frame->nFilledLen) {
7507 /*Push the frame to the Decoder*/
7508 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7509 return OMX_ErrorBadParameter;
7510 }
7511 frame_count++;
7512 pdest_frame = NULL;
7513
7514 if (m_input_free_q.m_size) {
7515 m_input_free_q.pop_entry(&address,&p2,&id);
7516 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
7517 pdest_frame->nFilledLen = 0;
7518 }
7519 } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007520 DEBUG_PRINT_ERROR("Zero len buffer return back to POOL");
Arun Menon906de572013-06-18 17:01:40 -07007521 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL,
7522 (unsigned)NULL);
7523 pdest_frame = NULL;
7524 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007525 }
Arun Menon906de572013-06-18 17:01:40 -07007526 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007527 DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007528 /*Check if Destination Buffer is full*/
7529 if (pdest_frame->nAllocLen ==
7530 pdest_frame->nFilledLen + pdest_frame->nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007531 DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07007532 return OMX_ErrorStreamCorrupt;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007533 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007534 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007535
Arun Menon906de572013-06-18 17:01:40 -07007536 if (psource_frame->nFilledLen == 0) {
7537 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
7538 if (pdest_frame) {
7539 pdest_frame->nFlags |= psource_frame->nFlags;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007540 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld",
Arun Menon906de572013-06-18 17:01:40 -07007541 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007542 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07007543 pdest_frame->nFilledLen,frame_count++);
7544 /*Push the frame to the Decoder*/
7545 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7546 return OMX_ErrorBadParameter;
7547 }
7548 frame_count++;
7549 pdest_frame = NULL;
7550 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007551 DEBUG_PRINT_LOW("Last frame in else dest addr") ;
Arun Menon906de572013-06-18 17:01:40 -07007552 generate_ebd = OMX_FALSE;
7553 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007554 }
Arun Menon906de572013-06-18 17:01:40 -07007555 if (generate_ebd) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007556 DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007557 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
7558 psource_frame = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007559
Arun Menon906de572013-06-18 17:01:40 -07007560 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007561 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007562 m_input_pending_q.pop_entry(&address,&p2,&id);
7563 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007564 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07007565 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007566 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007567 psource_frame->nFlags,psource_frame->nFilledLen);
7568 }
7569 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007570 }
Arun Menon906de572013-06-18 17:01:40 -07007571 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007572}
7573
7574OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp)
7575{
Arun Menon906de572013-06-18 17:01:40 -07007576 OMX_U32 partial_frame = 1;
7577 unsigned address = 0, p2 = 0, id = 0;
7578 OMX_BOOL isNewFrame = OMX_FALSE;
7579 OMX_BOOL generate_ebd = OMX_TRUE;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007580
Arun Menon906de572013-06-18 17:01:40 -07007581 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007582 DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated");
Arun Menon906de572013-06-18 17:01:40 -07007583 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007584 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007585 DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu "
Arun Menon906de572013-06-18 17:01:40 -07007586 "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007587 DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007588 if (h264_scratch.nFilledLen && look_ahead_nal) {
7589 look_ahead_nal = false;
7590 if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7591 h264_scratch.nFilledLen) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007592 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7593 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7594 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007595 DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007596 h264_scratch.nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07007597 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007598 DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007599 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007600 }
Arun Menon906de572013-06-18 17:01:40 -07007601 }
Praveen Chavance0b5e82013-08-08 05:23:34 -07007602
7603 /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result
7604 in EOS flag getting associated with the destination
7605 */
7606 if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) &&
7607 pdest_frame->nFilledLen) {
7608 DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'");
7609 generate_ebd = OMX_FALSE;
7610 }
7611
Arun Menon906de572013-06-18 17:01:40 -07007612 if (nal_length == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007613 DEBUG_PRINT_LOW("Zero NAL, hence parse using start code");
Arun Menon906de572013-06-18 17:01:40 -07007614 if (m_frame_parser.parse_sc_frame(psource_frame,
7615 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007616 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007617 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007618 }
Arun Menon906de572013-06-18 17:01:40 -07007619 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007620 DEBUG_PRINT_LOW("Non-zero NAL length clip, hence parse with NAL size %d ",nal_length);
Arun Menon906de572013-06-18 17:01:40 -07007621 if (m_frame_parser.parse_h264_nallength(psource_frame,
7622 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007623 DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error");
Arun Menon906de572013-06-18 17:01:40 -07007624 return OMX_ErrorBadParameter;
7625 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007626 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007627
Arun Menon906de572013-06-18 17:01:40 -07007628 if (partial_frame == 0) {
7629 if (nal_count == 0 && h264_scratch.nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007630 DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip");
Arun Menon906de572013-06-18 17:01:40 -07007631 nal_count++;
7632 h264_scratch.nTimeStamp = psource_frame->nTimeStamp;
7633 h264_scratch.nFlags = psource_frame->nFlags;
7634 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007635 DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007636 if (h264_scratch.nFilledLen) {
7637 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen,
7638 NALU_TYPE_SPS);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007639#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
Arun Menon906de572013-06-18 17:01:40 -07007640 if (client_extradata & OMX_TIMEINFO_EXTRADATA)
7641 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7642 h264_scratch.nFilledLen, NALU_TYPE_SEI);
7643 else if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7644 // If timeinfo is present frame info from SEI is already processed
7645 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7646 h264_scratch.nFilledLen, NALU_TYPE_SEI);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007647#endif
Arun Menon906de572013-06-18 17:01:40 -07007648 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7649 nal_count++;
7650 if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) {
7651 pdest_frame->nTimeStamp = h264_last_au_ts;
7652 pdest_frame->nFlags = h264_last_au_flags;
7653#ifdef PANSCAN_HDLR
7654 if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7655 h264_parser->update_panscan_data(h264_last_au_ts);
7656#endif
7657 }
7658 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR ||
7659 m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) {
7660 h264_last_au_ts = h264_scratch.nTimeStamp;
7661 h264_last_au_flags = h264_scratch.nFlags;
7662#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7663 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7664 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts);
7665 if (!VALID_TS(h264_last_au_ts))
7666 h264_last_au_ts = ts_in_sei;
7667 }
7668#endif
7669 } else
7670 h264_last_au_ts = LLONG_MAX;
7671 }
7672
7673 if (!isNewFrame) {
7674 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7675 h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007676 DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu",
Arun Menon906de572013-06-18 17:01:40 -07007677 h264_scratch.nFilledLen);
7678 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7679 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7680 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7681 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ)
7682 pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
7683 h264_scratch.nFilledLen = 0;
7684 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007685 DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007686 return OMX_ErrorBadParameter;
7687 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007688 } else if(h264_scratch.nFilledLen) {
Arun Menon906de572013-06-18 17:01:40 -07007689 look_ahead_nal = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007690 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007691 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007692 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07007693 pdest_frame->nFilledLen,frame_count++);
7694
7695 if (pdest_frame->nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007696 DEBUG_PRINT_LOW("Copy the Current Frame since and push it");
Arun Menon906de572013-06-18 17:01:40 -07007697 look_ahead_nal = false;
7698 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7699 h264_scratch.nFilledLen) {
7700 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7701 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7702 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7703 h264_scratch.nFilledLen = 0;
7704 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007705 DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007706 return OMX_ErrorBadParameter;
7707 }
7708 } else {
7709 if (psource_frame->nFilledLen || h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007710 DEBUG_PRINT_LOW("Reset the EOS Flag");
Arun Menon906de572013-06-18 17:01:40 -07007711 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
7712 }
7713 /*Push the frame to the Decoder*/
7714 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7715 return OMX_ErrorBadParameter;
7716 }
7717 //frame_count++;
7718 pdest_frame = NULL;
7719 if (m_input_free_q.m_size) {
7720 m_input_free_q.pop_entry(&address,&p2,&id);
7721 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007722 DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07007723 pdest_frame->nFilledLen = 0;
7724 pdest_frame->nFlags = 0;
7725 pdest_frame->nTimeStamp = LLONG_MAX;
7726 }
7727 }
7728 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007729 }
Arun Menon906de572013-06-18 17:01:40 -07007730 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007731 DEBUG_PRINT_LOW("Not a Complete Frame, pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007732 /*Check if Destination Buffer is full*/
7733 if (h264_scratch.nAllocLen ==
7734 h264_scratch.nFilledLen + h264_scratch.nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007735 DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07007736 return OMX_ErrorStreamCorrupt;
7737 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007738 }
Arun Menon906de572013-06-18 17:01:40 -07007739
7740 if (!psource_frame->nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007741 DEBUG_PRINT_LOW("Buffer Consumed return source %p back to client",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007742
7743 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
7744 if (pdest_frame) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007745 DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer");
Arun Menon906de572013-06-18 17:01:40 -07007746 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7747 h264_scratch.nFilledLen) {
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007748 if(pdest_frame->nFilledLen == 0) {
7749 /* No residual frame from before, send whatever
7750 * we have left */
7751 memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7752 h264_scratch.pBuffer, h264_scratch.nFilledLen);
7753 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7754 h264_scratch.nFilledLen = 0;
7755 pdest_frame->nTimeStamp = h264_scratch.nTimeStamp;
7756 } else {
7757 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7758 if(!isNewFrame) {
7759 /* Have a residual frame, but we know that the
7760 * AU in this frame is belonging to whatever
7761 * frame we had left over. So append it */
7762 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7763 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7764 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7765 h264_scratch.nFilledLen = 0;
Balamurugan Alagarsamyefde3832014-09-22 19:52:20 +05307766 if (h264_last_au_ts != LLONG_MAX)
7767 pdest_frame->nTimeStamp = h264_last_au_ts;
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007768 } else {
7769 /* Completely new frame, let's just push what
7770 * we have now. The resulting EBD would trigger
7771 * another push */
7772 generate_ebd = OMX_FALSE;
7773 pdest_frame->nTimeStamp = h264_last_au_ts;
7774 h264_last_au_ts = h264_scratch.nTimeStamp;
7775 }
7776 }
Arun Menon906de572013-06-18 17:01:40 -07007777 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007778 DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007779 return OMX_ErrorBadParameter;
7780 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007781
7782 /* Iff we coalesced two buffers, inherit the flags of both bufs */
7783 if(generate_ebd == OMX_TRUE) {
7784 pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags;
7785 }
Arun Menon906de572013-06-18 17:01:40 -07007786
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007787 DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007788 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007789 DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++);
Arun Menon906de572013-06-18 17:01:40 -07007790#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7791 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7792 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp);
7793 if (!VALID_TS(pdest_frame->nTimeStamp))
7794 pdest_frame->nTimeStamp = ts_in_sei;
7795 }
7796#endif
7797 /*Push the frame to the Decoder*/
7798 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7799 return OMX_ErrorBadParameter;
7800 }
7801 frame_count++;
7802 pdest_frame = NULL;
7803 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007804 DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu",
Arun Menon906de572013-06-18 17:01:40 -07007805 pdest_frame,h264_scratch.nFilledLen);
7806 generate_ebd = OMX_FALSE;
7807 }
7808 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007809 }
Arun Menon906de572013-06-18 17:01:40 -07007810 if (generate_ebd && !psource_frame->nFilledLen) {
7811 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
7812 psource_frame = NULL;
7813 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007814 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007815 m_input_pending_q.pop_entry(&address,&p2,&id);
7816 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007817 DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007818 psource_frame->nFlags,psource_frame->nFilledLen);
7819 }
7820 }
7821 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007822}
7823
7824OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp)
7825{
7826 OMX_U8 *buf, *pdest;
7827 OMX_U32 partial_frame = 1;
7828 OMX_U32 buf_len, dest_len;
7829
Arun Menon906de572013-06-18 17:01:40 -07007830 if (first_frame == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007831 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007832 DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes");
Arun Menon906de572013-06-18 17:01:40 -07007833 if (!m_vendor_config.pData) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007834 DEBUG_PRINT_LOW("Check profile type in 1st source buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007835 buf = psource_frame->pBuffer;
7836 buf_len = psource_frame->nFilledLen;
7837
7838 if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) ==
Arun Menon906de572013-06-18 17:01:40 -07007839 VC1_SP_MP_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007840 m_vc1_profile = VC1_SP_MP_RCV;
Arun Menon906de572013-06-18 17:01:40 -07007841 } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007842 m_vc1_profile = VC1_AP;
Arun Menon906de572013-06-18 17:01:40 -07007843 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007844 DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007845 return OMX_ErrorStreamCorrupt;
7846 }
Arun Menon906de572013-06-18 17:01:40 -07007847 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007848 pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen +
7849 pdest_frame->nOffset;
7850 dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen +
Arun Menon906de572013-06-18 17:01:40 -07007851 pdest_frame->nOffset);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007852
Arun Menon906de572013-06-18 17:01:40 -07007853 if (dest_len < m_vendor_config.nDataSize) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007854 DEBUG_PRINT_ERROR("Destination buffer full");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007855 return OMX_ErrorBadParameter;
Arun Menon906de572013-06-18 17:01:40 -07007856 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007857 memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize);
7858 pdest_frame->nFilledLen += m_vendor_config.nDataSize;
7859 }
7860 }
7861 }
7862
Arun Menon906de572013-06-18 17:01:40 -07007863 switch (m_vc1_profile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007864 case VC1_AP:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007865 DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code");
Arun Menon906de572013-06-18 17:01:40 -07007866 if (push_input_sc_codec(hComp) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007867 DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007868 return OMX_ErrorBadParameter;
7869 }
Arun Menon906de572013-06-18 17:01:40 -07007870 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007871
7872 case VC1_SP_MP_RCV:
7873 default:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007874 DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007875 return OMX_ErrorBadParameter;
7876 }
7877 return OMX_ErrorNone;
7878}
7879
David Ng38e2d232013-03-15 20:05:58 -07007880#ifndef USE_ION
Shalaj Jain273b3e02012-06-22 19:08:03 -07007881bool omx_vdec::align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007882 OMX_U32 alignment)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007883{
Arun Menon906de572013-06-18 17:01:40 -07007884 struct pmem_allocation allocation;
7885 allocation.size = buffer_size;
7886 allocation.align = clip2(alignment);
7887 if (allocation.align < 4096) {
7888 allocation.align = 4096;
7889 }
7890 if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007891 DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)",
Arun Menon906de572013-06-18 17:01:40 -07007892 allocation.align, allocation.size);
7893 return false;
7894 }
7895 return true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007896}
David Ng38e2d232013-03-15 20:05:58 -07007897#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07007898#ifdef USE_ION
7899int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007900 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
7901 struct ion_fd_data *fd_data, int flag)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007902{
Arun Menon906de572013-06-18 17:01:40 -07007903 int fd = -EINVAL;
7904 int rc = -EINVAL;
7905 int ion_dev_flag;
7906 struct vdec_ion ion_buf_info;
7907 if (!alloc_data || buffer_size <= 0 || !fd_data) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007908 DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory");
Arun Menon906de572013-06-18 17:01:40 -07007909 return -EINVAL;
7910 }
7911 ion_dev_flag = O_RDONLY;
7912 fd = open (MEM_DEVICE, ion_dev_flag);
7913 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007914 DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd);
Arun Menon906de572013-06-18 17:01:40 -07007915 return fd;
7916 }
7917 alloc_data->flags = 0;
7918 if (!secure_mode && (flag & ION_FLAG_CACHED)) {
7919 alloc_data->flags |= ION_FLAG_CACHED;
7920 }
7921 alloc_data->len = buffer_size;
7922 alloc_data->align = clip2(alignment);
7923 if (alloc_data->align < 4096) {
7924 alloc_data->align = 4096;
7925 }
7926 if ((secure_mode) && (flag & ION_SECURE))
7927 alloc_data->flags |= ION_SECURE;
Vinay Kalia53fa6832012-10-11 17:55:30 -07007928
Arun Menon906de572013-06-18 17:01:40 -07007929 alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05307930 if (secure_mode && (alloc_data->flags & ION_SECURE))
Arun Menon906de572013-06-18 17:01:40 -07007931 alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID);
7932 rc = ioctl(fd,ION_IOC_ALLOC,alloc_data);
7933 if (rc || !alloc_data->handle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007934 DEBUG_PRINT_ERROR("ION ALLOC memory failed ");
Arun Menon906de572013-06-18 17:01:40 -07007935 alloc_data->handle = NULL;
7936 close(fd);
7937 fd = -ENOMEM;
7938 return fd;
7939 }
7940 fd_data->handle = alloc_data->handle;
7941 rc = ioctl(fd,ION_IOC_MAP,fd_data);
7942 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007943 DEBUG_PRINT_ERROR("ION MAP failed ");
Arun Menon906de572013-06-18 17:01:40 -07007944 ion_buf_info.ion_alloc_data = *alloc_data;
7945 ion_buf_info.ion_device_fd = fd;
7946 ion_buf_info.fd_ion_data = *fd_data;
7947 free_ion_memory(&ion_buf_info);
7948 fd_data->fd =-1;
Arun Menon906de572013-06-18 17:01:40 -07007949 fd = -ENOMEM;
7950 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007951
Arun Menon906de572013-06-18 17:01:40 -07007952 return fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007953}
7954
Arun Menon906de572013-06-18 17:01:40 -07007955void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info)
7956{
Shalaj Jain273b3e02012-06-22 19:08:03 -07007957
Arun Menon906de572013-06-18 17:01:40 -07007958 if (!buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007959 DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata");
Arun Menon906de572013-06-18 17:01:40 -07007960 return;
7961 }
7962 if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE,
7963 &buf_ion_info->ion_alloc_data.handle)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007964 DEBUG_PRINT_ERROR("ION: free failed" );
Arun Menon906de572013-06-18 17:01:40 -07007965 }
7966 close(buf_ion_info->ion_device_fd);
7967 buf_ion_info->ion_device_fd = -1;
7968 buf_ion_info->ion_alloc_data.handle = NULL;
7969 buf_ion_info->fd_ion_data.fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007970}
7971#endif
7972void omx_vdec::free_output_buffer_header()
7973{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007974 DEBUG_PRINT_HIGH("ALL output buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07007975 output_use_buffer = false;
7976 ouput_egl_buffers = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007977
Arun Menon906de572013-06-18 17:01:40 -07007978 if (m_out_mem_ptr) {
7979 free (m_out_mem_ptr);
7980 m_out_mem_ptr = NULL;
7981 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007982
Arun Menon906de572013-06-18 17:01:40 -07007983 if (m_platform_list) {
7984 free(m_platform_list);
7985 m_platform_list = NULL;
7986 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007987
Arun Menon906de572013-06-18 17:01:40 -07007988 if (drv_ctx.ptr_respbuffer) {
7989 free (drv_ctx.ptr_respbuffer);
7990 drv_ctx.ptr_respbuffer = NULL;
7991 }
7992 if (drv_ctx.ptr_outputbuffer) {
7993 free (drv_ctx.ptr_outputbuffer);
7994 drv_ctx.ptr_outputbuffer = NULL;
7995 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007996#ifdef USE_ION
7997 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007998 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07007999 free(drv_ctx.op_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008000 drv_ctx.op_buf_ion_info = NULL;
8001 }
8002#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07008003 if (out_dynamic_list) {
8004 free(out_dynamic_list);
8005 out_dynamic_list = NULL;
8006 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008007}
8008
8009void omx_vdec::free_input_buffer_header()
8010{
8011 input_use_buffer = false;
Arun Menon906de572013-06-18 17:01:40 -07008012 if (arbitrary_bytes) {
Arun Menon906de572013-06-18 17:01:40 -07008013 if (m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008014 DEBUG_PRINT_LOW("Free input Heap Pointer");
Arun Menon906de572013-06-18 17:01:40 -07008015 free (m_inp_heap_ptr);
8016 m_inp_heap_ptr = NULL;
8017 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008018
Arun Menon906de572013-06-18 17:01:40 -07008019 if (m_phdr_pmem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008020 DEBUG_PRINT_LOW("Free input pmem header Pointer");
Arun Menon906de572013-06-18 17:01:40 -07008021 free (m_phdr_pmem_ptr);
8022 m_phdr_pmem_ptr = NULL;
8023 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008024 }
Arun Menon906de572013-06-18 17:01:40 -07008025 if (m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008026 DEBUG_PRINT_LOW("Free input pmem Pointer area");
Arun Menon906de572013-06-18 17:01:40 -07008027 free (m_inp_mem_ptr);
8028 m_inp_mem_ptr = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008029 }
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07008030 /* We just freed all the buffer headers, every thing in m_input_free_q,
8031 * m_input_pending_q, pdest_frame, and psource_frame is now invalid */
Leena Winterrowd1d2424a2013-08-20 15:26:02 -07008032 while (m_input_free_q.m_size) {
8033 unsigned address, p2, id;
8034 m_input_free_q.pop_entry(&address, &p2, &id);
8035 }
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07008036 while (m_input_pending_q.m_size) {
8037 unsigned address, p2, id;
8038 m_input_pending_q.pop_entry(&address, &p2, &id);
8039 }
8040 pdest_frame = NULL;
8041 psource_frame = NULL;
Arun Menon906de572013-06-18 17:01:40 -07008042 if (drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008043 DEBUG_PRINT_LOW("Free Driver Context pointer");
Arun Menon906de572013-06-18 17:01:40 -07008044 free (drv_ctx.ptr_inputbuffer);
8045 drv_ctx.ptr_inputbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008046 }
8047#ifdef USE_ION
8048 if (drv_ctx.ip_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008049 DEBUG_PRINT_LOW("Free ion context");
Arun Menon906de572013-06-18 17:01:40 -07008050 free(drv_ctx.ip_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008051 drv_ctx.ip_buf_ion_info = NULL;
8052 }
8053#endif
8054}
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008055
8056int omx_vdec::stream_off(OMX_U32 port)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008057{
Arun Menon906de572013-06-18 17:01:40 -07008058 enum v4l2_buf_type btype;
8059 int rc = 0;
8060 enum v4l2_ports v4l2_port = OUTPUT_PORT;
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008061
Arun Menon906de572013-06-18 17:01:40 -07008062 if (port == OMX_CORE_INPUT_PORT_INDEX) {
8063 btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8064 v4l2_port = OUTPUT_PORT;
8065 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
8066 btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8067 v4l2_port = CAPTURE_PORT;
8068 } else if (port == OMX_ALL) {
8069 int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX);
8070 int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008071
Arun Menon906de572013-06-18 17:01:40 -07008072 if (!rc_input)
8073 return rc_input;
8074 else
8075 return rc_output;
8076 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008077
Arun Menon906de572013-06-18 17:01:40 -07008078 if (!streaming[v4l2_port]) {
8079 // already streamed off, warn and move on
8080 DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port,"
8081 " which is already streamed off", v4l2_port);
8082 return 0;
8083 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008084
Arun Menon906de572013-06-18 17:01:40 -07008085 DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008086
Arun Menon906de572013-06-18 17:01:40 -07008087 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype);
8088 if (rc) {
8089 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008090 DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port);
Arun Menon906de572013-06-18 17:01:40 -07008091 } else {
8092 streaming[v4l2_port] = false;
8093 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008094
Arun Menon906de572013-06-18 17:01:40 -07008095 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008096}
8097
8098OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop)
8099{
Arun Menon906de572013-06-18 17:01:40 -07008100 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8101 struct v4l2_requestbuffers bufreq;
Deva Ramasubramanian991d0db2014-05-08 15:02:24 -07008102 unsigned int buf_size = 0, extra_data_size = 0, default_extra_data_size = 0;
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308103 unsigned int final_extra_data_size = 0;
Arun Menon906de572013-06-18 17:01:40 -07008104 struct v4l2_format fmt;
8105 int ret = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008106 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
Arun Menon906de572013-06-18 17:01:40 -07008107 buffer_prop->actualcount, buffer_prop->buffer_size);
8108 bufreq.memory = V4L2_MEMORY_USERPTR;
8109 bufreq.count = 1;
8110 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8111 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8112 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8113 fmt.fmt.pix_mp.pixelformat = output_capability;
8114 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8115 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8116 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8117 fmt.fmt.pix_mp.pixelformat = capture_capability;
8118 } else {
8119 eRet = OMX_ErrorBadParameter;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07008120 }
Arun Menon906de572013-06-18 17:01:40 -07008121 if (eRet==OMX_ErrorNone) {
8122 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008123 }
Arun Menon906de572013-06-18 17:01:40 -07008124 if (ret) {
8125 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
8126 /*TODO: How to handle this case */
8127 eRet = OMX_ErrorInsufficientResources;
8128 return eRet;
8129 } else {
8130 buffer_prop->actualcount = bufreq.count;
8131 buffer_prop->mincount = bufreq.count;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008132 DEBUG_PRINT_HIGH("Count = %d",bufreq.count);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008133 }
Arun Menon906de572013-06-18 17:01:40 -07008134 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
8135 buffer_prop->actualcount, buffer_prop->buffer_size);
8136
8137 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
8138 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
8139
8140 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
8141
8142 update_resolution(fmt.fmt.pix_mp.width,
8143 fmt.fmt.pix_mp.height,
8144 fmt.fmt.pix_mp.plane_fmt[0].bytesperline,
8145 fmt.fmt.pix_mp.plane_fmt[0].reserved[0]);
8146 if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
8147 drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008148 DEBUG_PRINT_HIGH("Buffer Size = %d",fmt.fmt.pix_mp.plane_fmt[0].sizeimage);
Arun Menon906de572013-06-18 17:01:40 -07008149
8150 if (ret) {
8151 /*TODO: How to handle this case */
8152 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
8153 eRet = OMX_ErrorInsufficientResources;
8154 } else {
8155 int extra_idx = 0;
8156
8157 eRet = is_video_session_supported();
8158 if (eRet)
8159 return eRet;
8160
8161 buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage;
8162 buf_size = buffer_prop->buffer_size;
8163 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
8164 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
8165 extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage;
8166 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008167 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07008168 return OMX_ErrorBadParameter;
8169 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008170
Deva Ramasubramanian991d0db2014-05-08 15:02:24 -07008171 default_extra_data_size = VENUS_EXTRADATA_SIZE(
8172 drv_ctx.video_resolution.frame_height,
8173 drv_ctx.video_resolution.frame_width);
8174 final_extra_data_size = extra_data_size > default_extra_data_size ?
8175 extra_data_size : default_extra_data_size;
8176
8177 final_extra_data_size = (final_extra_data_size + buffer_prop->alignment - 1) &
8178 (~(buffer_prop->alignment - 1));
Deva Ramasubramanian2ebfed32014-04-24 13:34:24 -07008179
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308180 drv_ctx.extradata_info.size = buffer_prop->actualcount * final_extra_data_size;
Arun Menon906de572013-06-18 17:01:40 -07008181 drv_ctx.extradata_info.count = buffer_prop->actualcount;
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308182 drv_ctx.extradata_info.buffer_size = final_extra_data_size;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308183 if (!secure_mode)
8184 buf_size += final_extra_data_size;
Arun Menon906de572013-06-18 17:01:40 -07008185 buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
8186 DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)",
8187 buffer_prop->actualcount, buffer_prop->buffer_size, buf_size);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008188 if (extra_data_size)
8189 DEBUG_PRINT_LOW("GetBufReq UPDATE: extradata: TotalSize(%d) BufferSize(%d)",
8190 drv_ctx.extradata_info.size, drv_ctx.extradata_info.buffer_size);
8191
Arun Menon906de572013-06-18 17:01:40 -07008192 if (in_reconfig) // BufReq will be set to driver when port is disabled
8193 buffer_prop->buffer_size = buf_size;
8194 else if (buf_size != buffer_prop->buffer_size) {
8195 buffer_prop->buffer_size = buf_size;
8196 eRet = set_buffer_req(buffer_prop);
8197 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008198 }
Arun Menon906de572013-06-18 17:01:40 -07008199 DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)",
8200 buffer_prop->actualcount, buffer_prop->buffer_size);
8201 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008202}
8203
8204OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop)
8205{
Arun Menon906de572013-06-18 17:01:40 -07008206 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8207 unsigned buf_size = 0;
8208 struct v4l2_format fmt;
8209 struct v4l2_requestbuffers bufreq;
8210 int ret;
8211 DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)",
8212 buffer_prop->actualcount, buffer_prop->buffer_size);
8213 buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
8214 if (buf_size != buffer_prop->buffer_size) {
8215 DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)",
8216 buffer_prop->buffer_size, buf_size);
8217 eRet = OMX_ErrorBadParameter;
8218 } else {
8219 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
8220 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07008221
Arun Menon906de572013-06-18 17:01:40 -07008222 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8223 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8224 fmt.fmt.pix_mp.pixelformat = output_capability;
Shalaj Jaind3902bb2013-10-07 12:42:55 -07008225 fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size;
Arun Menon906de572013-06-18 17:01:40 -07008226 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8227 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8228 fmt.fmt.pix_mp.pixelformat = capture_capability;
8229 } else {
8230 eRet = OMX_ErrorBadParameter;
8231 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07008232
Arun Menon906de572013-06-18 17:01:40 -07008233 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
8234 if (ret) {
8235 /*TODO: How to handle this case */
8236 DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret);
8237 eRet = OMX_ErrorInsufficientResources;
8238 }
8239
8240 bufreq.memory = V4L2_MEMORY_USERPTR;
8241 bufreq.count = buffer_prop->actualcount;
8242 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8243 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8244 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8245 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8246 } else {
8247 eRet = OMX_ErrorBadParameter;
8248 }
8249
8250 if (eRet==OMX_ErrorNone) {
8251 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
8252 }
8253
8254 if (ret) {
8255 DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret);
8256 /*TODO: How to handle this case */
8257 eRet = OMX_ErrorInsufficientResources;
8258 } else if (bufreq.count < buffer_prop->actualcount) {
8259 DEBUG_PRINT_ERROR("Driver refused to change the number of buffers"
8260 " on v4l2 port %d to %d (prefers %d)", bufreq.type,
8261 buffer_prop->actualcount, bufreq.count);
8262 eRet = OMX_ErrorInsufficientResources;
8263 } else {
8264 if (!client_buffers.update_buffer_req()) {
8265 DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed");
8266 eRet = OMX_ErrorInsufficientResources;
8267 }
8268 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008269 }
Arun Menon906de572013-06-18 17:01:40 -07008270 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008271}
8272
Shalaj Jain273b3e02012-06-22 19:08:03 -07008273OMX_ERRORTYPE omx_vdec::update_picture_resolution()
8274{
Arun Menon906de572013-06-18 17:01:40 -07008275 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8276 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008277}
8278
8279OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn)
8280{
Arun Menon906de572013-06-18 17:01:40 -07008281 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Pushkaraj Patil41588352014-02-25 20:51:34 +05308282 struct v4l2_format fmt;
Arun Menon906de572013-06-18 17:01:40 -07008283 if (!portDefn) {
8284 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008285 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008286 DEBUG_PRINT_LOW("omx_vdec::update_portdef");
Arun Menon906de572013-06-18 17:01:40 -07008287 portDefn->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07008288 portDefn->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07008289 portDefn->eDomain = OMX_PortDomainVideo;
8290 if (drv_ctx.frame_rate.fps_denominator > 0)
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08008291 portDefn->format.video.xFramerate = (drv_ctx.frame_rate.fps_numerator /
8292 drv_ctx.frame_rate.fps_denominator) << 16; //Q16 format
Arun Menon906de572013-06-18 17:01:40 -07008293 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008294 DEBUG_PRINT_ERROR("Error: Divide by zero");
Arun Menon906de572013-06-18 17:01:40 -07008295 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008296 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308297 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Arun Menon906de572013-06-18 17:01:40 -07008298 if (0 == portDefn->nPortIndex) {
8299 portDefn->eDir = OMX_DirInput;
8300 portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount;
8301 portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount;
8302 portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size;
8303 portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused;
8304 portDefn->format.video.eCompressionFormat = eCompressionFormat;
8305 portDefn->bEnabled = m_inp_bEnabled;
8306 portDefn->bPopulated = m_inp_bPopulated;
Pushkaraj Patil41588352014-02-25 20:51:34 +05308307
8308 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8309 fmt.fmt.pix_mp.pixelformat = output_capability;
Arun Menon906de572013-06-18 17:01:40 -07008310 } else if (1 == portDefn->nPortIndex) {
8311 unsigned int buf_size = 0;
8312 if (!client_buffers.update_buffer_req()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008313 DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed");
Arun Menon906de572013-06-18 17:01:40 -07008314 return OMX_ErrorHardware;
8315 }
8316 if (!client_buffers.get_buffer_req(buf_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008317 DEBUG_PRINT_ERROR("update buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07008318 return OMX_ErrorHardware;
8319 }
8320 portDefn->nBufferSize = buf_size;
8321 portDefn->eDir = OMX_DirOutput;
8322 portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount;
8323 portDefn->nBufferCountMin = drv_ctx.op_buf.mincount;
8324 portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
8325 portDefn->bEnabled = m_out_bEnabled;
8326 portDefn->bPopulated = m_out_bPopulated;
8327 if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008328 DEBUG_PRINT_ERROR("Error in getting color format");
Arun Menon906de572013-06-18 17:01:40 -07008329 return OMX_ErrorHardware;
8330 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308331 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8332 fmt.fmt.pix_mp.pixelformat = capture_capability;
Arun Menon906de572013-06-18 17:01:40 -07008333 } else {
8334 portDefn->eDir = OMX_DirMax;
8335 DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d",
8336 (int)portDefn->nPortIndex);
8337 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008338 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308339 if (is_down_scalar_enabled) {
8340 int ret = 0;
8341 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
8342 if (ret) {
8343 DEBUG_PRINT_ERROR("update_portdef : Error in getting port resolution");
8344 return OMX_ErrorHardware;
8345 } else {
8346 portDefn->format.video.nFrameWidth = fmt.fmt.pix_mp.width;
8347 portDefn->format.video.nFrameHeight = fmt.fmt.pix_mp.height;
8348 portDefn->format.video.nStride = fmt.fmt.pix_mp.plane_fmt[0].bytesperline;
8349 portDefn->format.video.nSliceHeight = fmt.fmt.pix_mp.plane_fmt[0].reserved[0];
8350 }
8351 } else {
8352 portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height;
8353 portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width;
8354 portDefn->format.video.nStride = drv_ctx.video_resolution.stride;
8355 portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines;
8356 }
8357
Praveen Chavandb7776f2014-02-06 18:17:25 -08008358 if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) ||
8359 (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) {
Maheshwar Ajja77cd19c2014-06-05 11:23:18 +05308360 portDefn->format.video.nStride = ALIGN(drv_ctx.video_resolution.frame_width, 16);
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308361 portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height;
8362 }
8363 DEBUG_PRINT_HIGH("update_portdef(%lu): Width = %lu Height = %lu Stride = %ld "
8364 "SliceHeight = %lu eColorFormat = %lu nBufSize %lu nBufCnt %lu",
8365 portDefn->nPortIndex,
8366 portDefn->format.video.nFrameWidth,
Arun Menon906de572013-06-18 17:01:40 -07008367 portDefn->format.video.nFrameHeight,
8368 portDefn->format.video.nStride,
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308369 portDefn->format.video.nSliceHeight,
8370 portDefn->format.video.eColorFormat,
8371 portDefn->nBufferSize,
8372 portDefn->nBufferCountActual);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008373
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308374 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008375}
8376
8377OMX_ERRORTYPE omx_vdec::allocate_output_headers()
8378{
Arun Menon906de572013-06-18 17:01:40 -07008379 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8380 OMX_BUFFERHEADERTYPE *bufHdr = NULL;
8381 unsigned i= 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008382
Arun Menon906de572013-06-18 17:01:40 -07008383 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008384 DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation");
Arun Menon906de572013-06-18 17:01:40 -07008385 int nBufHdrSize = 0;
8386 int nPlatformEntrySize = 0;
8387 int nPlatformListSize = 0;
8388 int nPMEMInfoSize = 0;
8389 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
8390 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
8391 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008392
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008393 DEBUG_PRINT_LOW("Setting First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07008394 drv_ctx.op_buf.actualcount);
8395 nBufHdrSize = drv_ctx.op_buf.actualcount *
8396 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008397
Arun Menon906de572013-06-18 17:01:40 -07008398 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
8399 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
8400 nPlatformListSize = drv_ctx.op_buf.actualcount *
8401 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
8402 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
8403 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008404
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008405 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07008406 sizeof(OMX_BUFFERHEADERTYPE),
8407 nPMEMInfoSize,
8408 nPlatformListSize);
Steve Kondikf1914362015-11-01 02:50:41 -08008409 DEBUG_PRINT_LOW("PE %d bmSize %" PRId64, nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07008410 m_out_bm_count);
8411 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
8412 // Alloc mem for platform specific info
8413 char *pPtr=NULL;
8414 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
8415 nPMEMInfoSize,1);
8416 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \
8417 calloc (sizeof(struct vdec_bufferpayload),
8418 drv_ctx.op_buf.actualcount);
8419 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
8420 calloc (sizeof (struct vdec_output_frameinfo),
8421 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07008422 if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) {
8423 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer");
8424 return OMX_ErrorInsufficientResources;
8425 }
8426
Shalaj Jain273b3e02012-06-22 19:08:03 -07008427#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008428 drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \
8429 calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07008430 if (!drv_ctx.op_buf_ion_info) {
8431 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info");
8432 return OMX_ErrorInsufficientResources;
8433 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008434#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07008435 if (dynamic_buf_mode) {
8436 out_dynamic_list = (struct dynamic_buf_list *) \
8437 calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount);
8438 }
Arun Menon906de572013-06-18 17:01:40 -07008439 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
8440 && drv_ctx.ptr_respbuffer) {
8441 bufHdr = m_out_mem_ptr;
8442 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
8443 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
8444 (((char *) m_platform_list) + nPlatformListSize);
8445 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
8446 (((char *) m_platform_entry) + nPlatformEntrySize);
8447 pPlatformList = m_platform_list;
8448 pPlatformEntry = m_platform_entry;
8449 pPMEMInfo = m_pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008450
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008451 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008452
Arun Menon906de572013-06-18 17:01:40 -07008453 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008454 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr,
Arun Menon906de572013-06-18 17:01:40 -07008455 m_out_mem_ptr,pPlatformEntry);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008456 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07008457 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
8458 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
8459 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
8460 // Set the values when we determine the right HxW param
8461 bufHdr->nAllocLen = 0;
8462 bufHdr->nFilledLen = 0;
8463 bufHdr->pAppPrivate = NULL;
8464 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8465 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
8466 pPlatformEntry->entry = pPMEMInfo;
8467 // Initialize the Platform List
8468 pPlatformList->nEntries = 1;
8469 pPlatformList->entryList = pPlatformEntry;
8470 // Keep pBuffer NULL till vdec is opened
8471 bufHdr->pBuffer = NULL;
8472 pPMEMInfo->offset = 0;
8473 pPMEMInfo->pmem_fd = 0;
8474 bufHdr->pPlatformPrivate = pPlatformList;
8475 drv_ctx.ptr_outputbuffer[i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008476#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008477 drv_ctx.op_buf_ion_info[i].ion_device_fd =-1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008478#endif
Arun Menon906de572013-06-18 17:01:40 -07008479 /*Create a mapping between buffers*/
8480 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
8481 drv_ctx.ptr_respbuffer[i].client_data = (void *) \
8482 &drv_ctx.ptr_outputbuffer[i];
8483 // Move the buffer and buffer header pointers
8484 bufHdr++;
8485 pPMEMInfo++;
8486 pPlatformEntry++;
8487 pPlatformList++;
8488 }
8489 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008490 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07008491 m_out_mem_ptr, pPtr);
8492 if (m_out_mem_ptr) {
8493 free(m_out_mem_ptr);
8494 m_out_mem_ptr = NULL;
8495 }
8496 if (pPtr) {
8497 free(pPtr);
8498 pPtr = NULL;
8499 }
8500 if (drv_ctx.ptr_outputbuffer) {
8501 free(drv_ctx.ptr_outputbuffer);
8502 drv_ctx.ptr_outputbuffer = NULL;
8503 }
8504 if (drv_ctx.ptr_respbuffer) {
8505 free(drv_ctx.ptr_respbuffer);
8506 drv_ctx.ptr_respbuffer = NULL;
8507 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008508#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008509 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008510 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07008511 free(drv_ctx.op_buf_ion_info);
8512 drv_ctx.op_buf_ion_info = NULL;
8513 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008514#endif
Arun Menon906de572013-06-18 17:01:40 -07008515 eRet = OMX_ErrorInsufficientResources;
8516 }
8517 } else {
8518 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008519 }
Arun Menon906de572013-06-18 17:01:40 -07008520 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008521}
8522
8523void omx_vdec::complete_pending_buffer_done_cbs()
8524{
Arun Menon906de572013-06-18 17:01:40 -07008525 unsigned p1;
8526 unsigned p2;
8527 unsigned ident;
8528 omx_cmd_queue tmp_q, pending_bd_q;
8529 pthread_mutex_lock(&m_lock);
8530 // pop all pending GENERATE FDB from ftb queue
8531 while (m_ftb_q.m_size) {
8532 m_ftb_q.pop_entry(&p1,&p2,&ident);
8533 if (ident == OMX_COMPONENT_GENERATE_FBD) {
8534 pending_bd_q.insert_entry(p1,p2,ident);
8535 } else {
8536 tmp_q.insert_entry(p1,p2,ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008537 }
Arun Menon906de572013-06-18 17:01:40 -07008538 }
8539 //return all non GENERATE FDB to ftb queue
8540 while (tmp_q.m_size) {
8541 tmp_q.pop_entry(&p1,&p2,&ident);
8542 m_ftb_q.insert_entry(p1,p2,ident);
8543 }
8544 // pop all pending GENERATE EDB from etb queue
8545 while (m_etb_q.m_size) {
8546 m_etb_q.pop_entry(&p1,&p2,&ident);
8547 if (ident == OMX_COMPONENT_GENERATE_EBD) {
8548 pending_bd_q.insert_entry(p1,p2,ident);
8549 } else {
8550 tmp_q.insert_entry(p1,p2,ident);
8551 }
8552 }
8553 //return all non GENERATE FDB to etb queue
8554 while (tmp_q.m_size) {
8555 tmp_q.pop_entry(&p1,&p2,&ident);
8556 m_etb_q.insert_entry(p1,p2,ident);
8557 }
8558 pthread_mutex_unlock(&m_lock);
8559 // process all pending buffer dones
8560 while (pending_bd_q.m_size) {
8561 pending_bd_q.pop_entry(&p1,&p2,&ident);
8562 switch (ident) {
8563 case OMX_COMPONENT_GENERATE_EBD:
8564 if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008565 DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07008566 omx_report_error ();
8567 }
8568 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008569
Arun Menon906de572013-06-18 17:01:40 -07008570 case OMX_COMPONENT_GENERATE_FBD:
8571 if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008572 DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07008573 omx_report_error ();
8574 }
8575 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008576 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008577 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008578}
8579
8580void omx_vdec::set_frame_rate(OMX_S64 act_timestamp)
8581{
Arun Menon906de572013-06-18 17:01:40 -07008582 OMX_U32 new_frame_interval = 0;
8583 if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts
8584 && llabs(act_timestamp - prev_ts) > 2000) {
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -07008585 new_frame_interval = client_set_fps ? frm_int : (act_timestamp - prev_ts) > 0 ?
8586 llabs(act_timestamp - prev_ts) : llabs(act_timestamp - prev_ts_actual);
Arun Menond9e49f82014-04-23 18:50:26 -07008587 if (new_frame_interval != frm_int || frm_int == 0) {
Arun Menon906de572013-06-18 17:01:40 -07008588 frm_int = new_frame_interval;
8589 if (frm_int) {
8590 drv_ctx.frame_rate.fps_numerator = 1e6;
8591 drv_ctx.frame_rate.fps_denominator = frm_int;
8592 DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)",
8593 frm_int, drv_ctx.frame_rate.fps_numerator /
8594 (float)drv_ctx.frame_rate.fps_denominator);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008595
Arun Menon906de572013-06-18 17:01:40 -07008596 /* We need to report the difference between this FBD and the previous FBD
8597 * back to the driver for clock scaling purposes. */
8598 struct v4l2_outputparm oparm;
8599 /*XXX: we're providing timing info as seconds per frame rather than frames
8600 * per second.*/
8601 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
8602 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008603
Arun Menon906de572013-06-18 17:01:40 -07008604 struct v4l2_streamparm sparm;
8605 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8606 sparm.parm.output = oparm;
8607 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
8608 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
8609 performance might be affected");
8610 }
8611
8612 }
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008613 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008614 }
Arun Menon906de572013-06-18 17:01:40 -07008615 prev_ts = act_timestamp;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008616}
8617
8618void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp)
8619{
Arun Menon906de572013-06-18 17:01:40 -07008620 if (rst_prev_ts && VALID_TS(act_timestamp)) {
8621 prev_ts = act_timestamp;
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -07008622 prev_ts_actual = act_timestamp;
Arun Menon906de572013-06-18 17:01:40 -07008623 rst_prev_ts = false;
8624 } else if (VALID_TS(prev_ts)) {
8625 bool codec_cond = (drv_ctx.timestamp_adjust)?
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -07008626 (!VALID_TS(act_timestamp) || act_timestamp < prev_ts_actual || llabs(act_timestamp - prev_ts_actual) <= 2000) :
8627 (!VALID_TS(act_timestamp) || act_timestamp <= prev_ts_actual);
8628 prev_ts_actual = act_timestamp; //unadjusted previous timestamp
Arun Menon906de572013-06-18 17:01:40 -07008629 if (frm_int > 0 && codec_cond) {
8630 DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp);
8631 act_timestamp = prev_ts + frm_int;
8632 DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp);
8633 prev_ts = act_timestamp;
Leena Winterrowdd139fdc2014-08-05 18:04:25 -07008634 } else {
8635 if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) {
8636 // ensure that timestamps can never step backwards when in display order
8637 act_timestamp = prev_ts;
8638 }
Arun Menon906de572013-06-18 17:01:40 -07008639 set_frame_rate(act_timestamp);
Leena Winterrowdd139fdc2014-08-05 18:04:25 -07008640 }
Arun Menon906de572013-06-18 17:01:40 -07008641 } else if (frm_int > 0) // In this case the frame rate was set along
8642 { // with the port definition, start ts with 0
8643 act_timestamp = prev_ts = 0; // and correct if a valid ts is received.
8644 rst_prev_ts = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008645 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008646}
8647
8648void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr)
8649{
Arun Menon906de572013-06-18 17:01:40 -07008650 OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL;
8651 OMX_U32 num_conceal_MB = 0;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308652 OMX_TICKS time_stamp = 0;
Arun Menon906de572013-06-18 17:01:40 -07008653 OMX_U32 frame_rate = 0;
8654 int consumed_len = 0;
8655 OMX_U32 num_MB_in_frame;
8656 OMX_U32 recovery_sei_flags = 1;
8657 int enable = 0;
Arun Menon7b6fd642014-02-13 16:48:36 -08008658
Arun Menon906de572013-06-18 17:01:40 -07008659 int buf_index = p_buf_hdr - m_out_mem_ptr;
Praveen Chavan61e5d162013-11-01 02:49:19 -07008660 if (buf_index >= drv_ctx.extradata_info.count) {
8661 DEBUG_PRINT_ERROR("handle_extradata: invalid index(%d) max(%d)",
8662 buf_index, drv_ctx.extradata_info.count);
8663 return;
8664 }
Arun Menon906de572013-06-18 17:01:40 -07008665 struct msm_vidc_panscan_window_payload *panscan_payload = NULL;
8666 OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) +
8667 p_buf_hdr->nOffset;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308668
Arun Menon906de572013-06-18 17:01:40 -07008669 if (!drv_ctx.extradata_info.uaddr) {
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308670 DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr");
Arun Menon906de572013-06-18 17:01:40 -07008671 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008672 }
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308673
8674 if (!secure_mode && (drv_ctx.extradata_info.buffer_size > (p_buf_hdr->nAllocLen - p_buf_hdr->nFilledLen)) ) {
8675 DEBUG_PRINT_ERROR("Error: Insufficient size allocated for extra-data");
8676 p_extra = NULL;
8677 return;
8678 }
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308679 if (!secure_mode)
8680 p_extra = (OMX_OTHER_EXTRADATATYPE *)
Arun Menon906de572013-06-18 17:01:40 -07008681 ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3));
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308682 else
8683 p_extra = m_other_extradata;
8684
Arun Menon906de572013-06-18 17:01:40 -07008685 char *p_extradata = drv_ctx.extradata_info.uaddr + buf_index * drv_ctx.extradata_info.buffer_size;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308686 if (!secure_mode && ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))) {
8687 DEBUG_PRINT_ERROR("Error: out of bound memory access by p_extra");
Arun Menon906de572013-06-18 17:01:40 -07008688 p_extra = NULL;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308689 return;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008690 }
Arun Menon906de572013-06-18 17:01:40 -07008691 OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008692 if (data && p_extra) {
Arun Menon906de572013-06-18 17:01:40 -07008693 while ((consumed_len < drv_ctx.extradata_info.buffer_size)
8694 && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) {
Surajit Podderd2644d52013-08-28 17:59:06 +05308695 if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) {
Arun Menon906de572013-06-18 17:01:40 -07008696 DEBUG_PRINT_LOW("Invalid extra data size");
8697 break;
8698 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308699 DEBUG_PRINT_LOW("handle_extradata: eType = %d", data->eType);
Arun Menon906de572013-06-18 17:01:40 -07008700 switch ((unsigned long)data->eType) {
8701 case EXTRADATA_INTERLACE_VIDEO:
8702 struct msm_vidc_interlace_payload *payload;
8703 payload = (struct msm_vidc_interlace_payload *)data->data;
Arun Menon7b6fd642014-02-13 16:48:36 -08008704 if (payload) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008705 enable = 1;
Arun Menon7b6fd642014-02-13 16:48:36 -08008706 switch (payload->format) {
8707 case INTERLACE_FRAME_PROGRESSIVE:
8708 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
8709 enable = 0;
8710 break;
8711 case INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST:
8712 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8713 break;
8714 case INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST:
8715 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameBottomFieldFirst;
8716 break;
8717 default:
8718 DEBUG_PRINT_LOW("default case - set interlace to topfield");
8719 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8720 }
Arun Menon906de572013-06-18 17:01:40 -07008721 }
8722 if (m_enable_android_native_buffers)
8723 setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle,
8724 PP_PARAM_INTERLACED, (void*)&enable);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308725 if (client_extradata & OMX_INTERLACE_EXTRADATA) {
Arun Menon7b6fd642014-02-13 16:48:36 -08008726 append_interlace_extradata(p_extra, payload->format,
8727 p_buf_hdr->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF);
Arun Menon906de572013-06-18 17:01:40 -07008728 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8729 }
8730 break;
8731 case EXTRADATA_FRAME_RATE:
8732 struct msm_vidc_framerate_payload *frame_rate_payload;
8733 frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data;
8734 frame_rate = frame_rate_payload->frame_rate;
8735 break;
8736 case EXTRADATA_TIMESTAMP:
8737 struct msm_vidc_ts_payload *time_stamp_payload;
8738 time_stamp_payload = (struct msm_vidc_ts_payload *)data->data;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308739 time_stamp = time_stamp_payload->timestamp_lo;
8740 time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32);
8741 p_buf_hdr->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07008742 break;
8743 case EXTRADATA_NUM_CONCEALED_MB:
8744 struct msm_vidc_concealmb_payload *conceal_mb_payload;
8745 conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data;
8746 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8747 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8748 num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0);
8749 break;
8750 case EXTRADATA_INDEX:
8751 int *etype;
8752 etype = (int *)(data->data);
8753 if (etype && *etype == EXTRADATA_ASPECT_RATIO) {
8754 struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload;
8755 aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype);
8756 if (aspect_ratio_payload) {
8757 ((struct vdec_output_frameinfo *)
8758 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width;
8759 ((struct vdec_output_frameinfo *)
8760 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height;
8761 }
8762 }
8763 break;
8764 case EXTRADATA_RECOVERY_POINT_SEI:
8765 struct msm_vidc_recoverysei_payload *recovery_sei_payload;
8766 recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data;
8767 recovery_sei_flags = recovery_sei_payload->flags;
8768 if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) {
8769 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008770 DEBUG_PRINT_HIGH("");
8771 DEBUG_PRINT_HIGH("***************************************************");
8772 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
8773 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07008774 }
8775 break;
8776 case EXTRADATA_PANSCAN_WINDOW:
8777 panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data;
8778 break;
8779 case EXTRADATA_MPEG2_SEQDISP:
8780 struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload;
8781 seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data;
8782 if (seqdisp_payload) {
8783 m_disp_hor_size = seqdisp_payload->disp_width;
8784 m_disp_vert_size = seqdisp_payload->disp_height;
8785 }
8786 break;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308787 case EXTRADATA_S3D_FRAME_PACKING:
8788 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload;
8789 s3d_frame_packing_payload = (struct msm_vidc_s3d_frame_packing_payload *)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308790 if (client_extradata & OMX_FRAMEPACK_EXTRADATA) {
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308791 append_framepack_extradata(p_extra, s3d_frame_packing_payload);
8792 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8793 }
8794 break;
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008795 case EXTRADATA_FRAME_QP:
8796 struct msm_vidc_frame_qp_payload *qp_payload;
8797 qp_payload = (struct msm_vidc_frame_qp_payload*)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308798 if (client_extradata & OMX_QP_EXTRADATA) {
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008799 append_qp_extradata(p_extra, qp_payload);
8800 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8801 }
8802 break;
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008803 case EXTRADATA_FRAME_BITS_INFO:
8804 struct msm_vidc_frame_bits_info_payload *bits_info_payload;
8805 bits_info_payload = (struct msm_vidc_frame_bits_info_payload*)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308806 if (client_extradata & OMX_BITSINFO_EXTRADATA) {
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008807 append_bitsinfo_extradata(p_extra, bits_info_payload);
8808 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8809 }
8810 break;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008811 case EXTRADATA_STREAM_USERDATA:
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308812 if (client_extradata & OMX_EXTNUSER_EXTRADATA) {
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008813 append_user_extradata(p_extra, data);
8814 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8815 }
8816 break;
Arun Menon906de572013-06-18 17:01:40 -07008817 default:
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008818 DEBUG_PRINT_LOW("Unrecognized extradata");
Arun Menon906de572013-06-18 17:01:40 -07008819 goto unrecognized_extradata;
8820 }
8821 consumed_len += data->nSize;
8822 data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize);
8823 }
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308824 if (client_extradata & OMX_FRAMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008825 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
8826 append_frame_info_extradata(p_extra,
8827 num_conceal_MB, ((struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate)->pic_type, frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308828 time_stamp, panscan_payload,&((struct vdec_output_frameinfo *)
Arun Menon906de572013-06-18 17:01:40 -07008829 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info);
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008830 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
Arun Menon906de572013-06-18 17:01:40 -07008831 }
8832 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07008833unrecognized_extradata:
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008834 if (client_extradata && p_extra) {
8835 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
Arun Menon906de572013-06-18 17:01:40 -07008836 append_terminator_extradata(p_extra);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008837 }
8838
Arun Menonfd723932014-05-30 17:56:31 -07008839 if (secure_mode && p_extradata && m_other_extradata) {
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308840 struct vdec_output_frameinfo *ptr_extradatabuff = NULL;
8841 memcpy(p_extradata, m_other_extradata, drv_ctx.extradata_info.buffer_size);
8842 ptr_extradatabuff = (struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate;
8843 ptr_extradatabuff->metadata_info.metabufaddr = (void *)p_extradata;
8844 ptr_extradatabuff->metadata_info.size = drv_ctx.extradata_info.buffer_size;
8845 }
Arun Menon906de572013-06-18 17:01:40 -07008846 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008847}
8848
Vinay Kalia9c00cae2012-12-06 16:08:20 -08008849OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata,
Arun Menon906de572013-06-18 17:01:40 -07008850 bool is_internal, bool enable)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008851{
Arun Menon906de572013-06-18 17:01:40 -07008852 OMX_ERRORTYPE ret = OMX_ErrorNone;
8853 struct v4l2_control control;
8854 if (m_state != OMX_StateLoaded) {
8855 DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only");
8856 return OMX_ErrorIncorrectStateOperation;
Vinay Kaliadb90f8c2012-11-19 18:57:56 -08008857 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008858 DEBUG_PRINT_HIGH("NOTE: enable_extradata: actual[%lu] requested[%lu] enable[%d], is_internal: %d",
Arun Menon906de572013-06-18 17:01:40 -07008859 client_extradata, requested_extradata, enable, is_internal);
8860
8861 if (!is_internal) {
8862 if (enable)
8863 client_extradata |= requested_extradata;
8864 else
8865 client_extradata = client_extradata & ~requested_extradata;
8866 }
8867
8868 if (enable) {
8869 if (requested_extradata & OMX_INTERLACE_EXTRADATA) {
8870 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8871 control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO;
8872 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8873 DEBUG_PRINT_HIGH("Failed to set interlaced extradata."
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008874 " Quality of interlaced clips might be impacted.");
Arun Menon906de572013-06-18 17:01:40 -07008875 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308876 }
8877 if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008878 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8879 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE;
8880 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008881 DEBUG_PRINT_HIGH("Failed to set framerate extradata");
Arun Menon906de572013-06-18 17:01:40 -07008882 }
8883 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8884 control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB;
8885 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008886 DEBUG_PRINT_HIGH("Failed to set concealed MB extradata");
Arun Menon906de572013-06-18 17:01:40 -07008887 }
8888 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8889 control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI;
8890 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008891 DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata");
Arun Menon906de572013-06-18 17:01:40 -07008892 }
8893 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8894 control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW;
8895 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008896 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008897 }
8898 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8899 control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO;
8900 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008901 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008902 }
8903 if (output_capability == V4L2_PIX_FMT_MPEG2) {
8904 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8905 control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP;
8906 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008907 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008908 }
8909 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308910 }
8911 if (requested_extradata & OMX_TIMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008912 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8913 control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP;
8914 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008915 DEBUG_PRINT_HIGH("Failed to set timeinfo extradata");
Arun Menon906de572013-06-18 17:01:40 -07008916 }
8917 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308918 if (requested_extradata & OMX_FRAMEPACK_EXTRADATA) {
8919 if (output_capability == V4L2_PIX_FMT_H264) {
8920 DEBUG_PRINT_HIGH("enable OMX_FRAMEPACK_EXTRADATA");
8921 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8922 control.value = V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING;
8923 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8924 DEBUG_PRINT_HIGH("Failed to set S3D_FRAME_PACKING extradata");
8925 }
8926 } else {
8927 DEBUG_PRINT_HIGH("OMX_FRAMEPACK_EXTRADATA supported for H264 only");
8928 }
8929 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008930 if (requested_extradata & OMX_QP_EXTRADATA) {
8931 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8932 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP;
8933 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8934 DEBUG_PRINT_HIGH("Failed to set QP extradata");
8935 }
8936 }
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008937 if (requested_extradata & OMX_BITSINFO_EXTRADATA) {
8938 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8939 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO;
8940 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8941 DEBUG_PRINT_HIGH("Failed to set frame bits info extradata");
8942 }
8943 }
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008944 if (requested_extradata & OMX_EXTNUSER_EXTRADATA) {
8945 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8946 control.value = V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA;
8947 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8948 DEBUG_PRINT_HIGH("Failed to set stream userdata extradata");
8949 }
8950 }
Arun Menon906de572013-06-18 17:01:40 -07008951 }
8952 ret = get_buffer_req(&drv_ctx.op_buf);
8953 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008954}
8955
8956OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8957{
Arun Menon906de572013-06-18 17:01:40 -07008958 OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0;
8959 OMX_U8 *data_ptr = extra->data, data = 0;
8960 while (byte_count < extra->nDataSize) {
8961 data = *data_ptr;
8962 while (data) {
8963 num_MB += (data&0x01);
8964 data >>= 1;
8965 }
8966 data_ptr++;
8967 byte_count++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008968 }
Arun Menon906de572013-06-18 17:01:40 -07008969 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8970 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8971 return ((num_MB_in_frame > 0)?(num_MB * 100 / num_MB_in_frame) : 0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008972}
8973
8974void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8975{
Arun Menon906de572013-06-18 17:01:40 -07008976 if (!m_debug_extradata)
8977 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008978
8979 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308980 "============== Extra Data ==============\n"
8981 " Size: %lu\n"
8982 " Version: %lu\n"
8983 " PortIndex: %lu\n"
8984 " Type: %x\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008985 " DataSize: %lu",
Arun Menon906de572013-06-18 17:01:40 -07008986 extra->nSize, extra->nVersion.nVersion,
8987 extra->nPortIndex, extra->eType, extra->nDataSize);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008988
Arun Menon906de572013-06-18 17:01:40 -07008989 if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) {
8990 OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data;
8991 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308992 "------ Interlace Format ------\n"
8993 " Size: %lu\n"
8994 " Version: %lu\n"
8995 " PortIndex: %lu\n"
8996 " Is Interlace Format: %d\n"
8997 " Interlace Formats: %lu\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008998 "=========== End of Interlace ===========",
Arun Menon906de572013-06-18 17:01:40 -07008999 intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex,
9000 intfmt->bInterlaceFormat, intfmt->nInterlaceFormats);
9001 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) {
9002 OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
9003
9004 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05309005 "-------- Frame Format --------\n"
9006 " Picture Type: %d\n"
9007 " Interlace Type: %d\n"
9008 " Pan Scan Total Frame Num: %lu\n"
9009 " Concealed Macro Blocks: %lu\n"
9010 " frame rate: %lu\n"
9011 " Time Stamp: %llu\n"
9012 " Aspect Ratio X: %lu\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009013 " Aspect Ratio Y: %lu",
Arun Menon906de572013-06-18 17:01:40 -07009014 fminfo->ePicType,
9015 fminfo->interlaceType,
9016 fminfo->panScan.numWindows,
9017 fminfo->nConcealedMacroblocks,
9018 fminfo->nFrameRate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309019 fminfo->nTimeStamp,
Arun Menon906de572013-06-18 17:01:40 -07009020 fminfo->aspectRatio.aspectRatioX,
9021 fminfo->aspectRatio.aspectRatioY);
9022
9023 for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) {
9024 DEBUG_PRINT_HIGH(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009025 "------------------------------"
Deepak Verma867d5132013-12-05 12:23:20 +05309026 " Pan Scan Frame Num: %lu\n"
9027 " Rectangle x: %ld\n"
9028 " Rectangle y: %ld\n"
9029 " Rectangle dx: %ld\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009030 " Rectangle dy: %ld",
Arun Menon906de572013-06-18 17:01:40 -07009031 i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y,
9032 fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy);
9033 }
9034
9035 DEBUG_PRINT_HIGH("========= End of Frame Format ==========");
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05309036 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement) {
9037 OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data;
9038 DEBUG_PRINT_HIGH(
9039 "------------------ Framepack Format ----------\n"
9040 " id: %lu \n"
9041 " cancel_flag: %lu \n"
9042 " type: %lu \n"
9043 " quincunx_sampling_flagFormat: %lu \n"
9044 " content_interpretation_type: %lu \n"
9045 " content_interpretation_type: %lu \n"
9046 " spatial_flipping_flag: %lu \n"
9047 " frame0_flipped_flag: %lu \n"
9048 " field_views_flag: %lu \n"
9049 " current_frame_is_frame0_flag: %lu \n"
9050 " frame0_self_contained_flag: %lu \n"
9051 " frame1_self_contained_flag: %lu \n"
9052 " frame0_grid_position_x: %lu \n"
9053 " frame0_grid_position_y: %lu \n"
9054 " frame1_grid_position_x: %lu \n"
9055 " frame1_grid_position_y: %lu \n"
9056 " reserved_byte: %lu \n"
9057 " repetition_period: %lu \n"
9058 " extension_flag: %lu \n"
9059 "================== End of Framepack ===========",
9060 framepack->id,
9061 framepack->cancel_flag,
9062 framepack->type,
9063 framepack->quincunx_sampling_flag,
9064 framepack->content_interpretation_type,
9065 framepack->spatial_flipping_flag,
9066 framepack->frame0_flipped_flag,
9067 framepack->field_views_flag,
9068 framepack->current_frame_is_frame0_flag,
9069 framepack->frame0_self_contained_flag,
9070 framepack->frame1_self_contained_flag,
9071 framepack->frame0_grid_position_x,
9072 framepack->frame0_grid_position_y,
9073 framepack->frame1_grid_position_x,
9074 framepack->frame1_grid_position_y,
9075 framepack->reserved_byte,
9076 framepack->repetition_period,
9077 framepack->extension_flag);
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08009078 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataQP) {
9079 OMX_QCOM_EXTRADATA_QP * qp = (OMX_QCOM_EXTRADATA_QP *)extra->data;
9080 DEBUG_PRINT_HIGH(
9081 "---- QP (Frame quantization parameter) ----\n"
9082 " Frame QP: %lu \n"
9083 "================ End of QP ================\n",
9084 qp->nQP);
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08009085 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo) {
9086 OMX_QCOM_EXTRADATA_BITS_INFO * bits = (OMX_QCOM_EXTRADATA_BITS_INFO *)extra->data;
9087 DEBUG_PRINT_HIGH(
9088 "--------- Input bits information --------\n"
9089 " Header bits: %lu \n"
9090 " Frame bits: %lu \n"
9091 "===== End of Input bits information =====\n",
9092 bits->header_bits, bits->frame_bits);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009093 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData) {
9094 OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)extra->data;
9095 OMX_U8 *data_ptr = (OMX_U8 *)userdata->data;
9096 OMX_U32 userdata_size = extra->nDataSize - sizeof(userdata->type);
9097 OMX_U32 i = 0;
9098 DEBUG_PRINT_HIGH(
9099 "-------------- Userdata -------------\n"
9100 " Stream userdata type: %d\n"
9101 " userdata size: %d\n"
9102 " STREAM_USERDATA:",
9103 userdata->type, userdata_size);
9104 for (i = 0; i < userdata_size; i+=4) {
9105 DEBUG_PRINT_HIGH(" %x %x %x %x",
9106 data_ptr[i], data_ptr[i+1],
9107 data_ptr[i+2], data_ptr[i+3]);
9108 }
9109 DEBUG_PRINT_HIGH(
9110 "=========== End of Userdata ===========");
Arun Menon906de572013-06-18 17:01:40 -07009111 } else if (extra->eType == OMX_ExtraDataNone) {
9112 DEBUG_PRINT_HIGH("========== End of Terminator ===========");
9113 } else {
9114 DEBUG_PRINT_HIGH("======= End of Driver Extradata ========");
Shalaj Jain273b3e02012-06-22 19:08:03 -07009115 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009116}
9117
9118void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon7b6fd642014-02-13 16:48:36 -08009119 OMX_U32 interlaced_format_type, bool is_mbaff)
Shalaj Jain273b3e02012-06-22 19:08:03 -07009120{
Arun Menon906de572013-06-18 17:01:40 -07009121 OMX_STREAMINTERLACEFORMAT *interlace_format;
Arun Menon7b6fd642014-02-13 16:48:36 -08009122
Arun Menon906de572013-06-18 17:01:40 -07009123 if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) {
9124 return;
9125 }
9126 extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE;
9127 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9128 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9129 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat;
9130 extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT);
9131 interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data;
9132 interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT);
9133 interlace_format->nVersion.nVersion = OMX_SPEC_VERSION;
9134 interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
Arun Menon7b6fd642014-02-13 16:48:36 -08009135
9136 if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !is_mbaff) {
Arun Menon906de572013-06-18 17:01:40 -07009137 interlace_format->bInterlaceFormat = OMX_FALSE;
9138 interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive;
9139 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon7b6fd642014-02-13 16:48:36 -08009140 } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST) && !is_mbaff) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009141 interlace_format->bInterlaceFormat = OMX_TRUE;
Arun Menon7b6fd642014-02-13 16:48:36 -08009142 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009143 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon7b6fd642014-02-13 16:48:36 -08009144 } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST) && !is_mbaff) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009145 interlace_format->bInterlaceFormat = OMX_TRUE;
Arun Menon7b6fd642014-02-13 16:48:36 -08009146 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameBottomFieldFirst;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009147 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon906de572013-06-18 17:01:40 -07009148 } else {
9149 interlace_format->bInterlaceFormat = OMX_TRUE;
9150 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst;
9151 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
9152 }
9153 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009154}
9155
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009156void omx_vdec::fill_aspect_ratio_info(
Arun Menon906de572013-06-18 17:01:40 -07009157 struct vdec_aspectratioinfo *aspect_ratio_info,
9158 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info)
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009159{
Arun Menon906de572013-06-18 17:01:40 -07009160 m_extradata = frame_info;
9161 m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width;
9162 m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309163 DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX,
Arun Menon906de572013-06-18 17:01:40 -07009164 m_extradata->aspectRatio.aspectRatioY);
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009165}
Shalaj Jain273b3e02012-06-22 19:08:03 -07009166
9167void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon906de572013-06-18 17:01:40 -07009168 OMX_U32 num_conceal_mb, OMX_U32 picture_type, OMX_U32 frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309169 OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload,
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009170 struct vdec_aspectratioinfo *aspect_ratio_info)
Shalaj Jain273b3e02012-06-22 19:08:03 -07009171{
Arun Menon906de572013-06-18 17:01:40 -07009172 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL;
9173 struct msm_vidc_panscan_window *panscan_window;
9174 if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) {
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08009175 return;
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07009176 }
Arun Menon906de572013-06-18 17:01:40 -07009177 extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE;
9178 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9179 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9180 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo;
9181 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO);
9182 frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
9183 switch (picture_type) {
9184 case PICTURE_TYPE_I:
9185 frame_info->ePicType = OMX_VIDEO_PictureTypeI;
9186 break;
9187 case PICTURE_TYPE_P:
9188 frame_info->ePicType = OMX_VIDEO_PictureTypeP;
9189 break;
9190 case PICTURE_TYPE_B:
9191 frame_info->ePicType = OMX_VIDEO_PictureTypeB;
9192 break;
9193 default:
9194 frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0;
9195 }
9196 if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst)
9197 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
9198 else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst)
9199 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
9200 else
9201 frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive;
9202 memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio));
9203 frame_info->nConcealedMacroblocks = num_conceal_mb;
9204 frame_info->nFrameRate = frame_rate;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309205 frame_info->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07009206 frame_info->panScan.numWindows = 0;
9207 if (output_capability == V4L2_PIX_FMT_MPEG2) {
9208 if (m_disp_hor_size && m_disp_vert_size) {
9209 frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size;
9210 frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size;
Pushkaraj Patil5e6ebd92014-03-10 10:29:14 +05309211 } else {
9212 frame_info->displayAspectRatio.displayHorizontalSize = 0;
9213 frame_info->displayAspectRatio.displayVerticalSize = 0;
Arun Menon906de572013-06-18 17:01:40 -07009214 }
9215 }
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07009216
Arun Menon906de572013-06-18 17:01:40 -07009217 if (panscan_payload) {
9218 frame_info->panScan.numWindows = panscan_payload->num_panscan_windows;
9219 panscan_window = &panscan_payload->wnd[0];
9220 for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) {
9221 frame_info->panScan.window[i].x = panscan_window->panscan_window_width;
9222 frame_info->panScan.window[i].y = panscan_window->panscan_window_height;
9223 frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset;
9224 frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset;
9225 panscan_window++;
9226 }
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08009227 }
Arun Menon906de572013-06-18 17:01:40 -07009228 fill_aspect_ratio_info(aspect_ratio_info, frame_info);
9229 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009230}
9231
9232void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra)
9233{
Arun Menon906de572013-06-18 17:01:40 -07009234 OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL;
9235 extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE;
9236 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9237 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9238 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef;
9239 extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
9240 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data;
9241 *portDefn = m_port_def;
9242 DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu "
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009243 "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight,
Arun Menon906de572013-06-18 17:01:40 -07009244 portDefn->format.video.nFrameWidth,
9245 portDefn->format.video.nStride,
9246 portDefn->format.video.nSliceHeight);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009247}
9248
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05309249void omx_vdec::append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9250 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload)
9251{
9252 OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack;
9253 if (FRAME_PACK_SIZE*sizeof(OMX_U32) != sizeof(struct msm_vidc_s3d_frame_packing_payload)) {
9254 DEBUG_PRINT_ERROR("frame packing size mismatch");
9255 return;
9256 }
9257 extra->nSize = OMX_FRAMEPACK_EXTRADATA_SIZE;
9258 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9259 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9260 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement;
9261 extra->nDataSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT);
9262 framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data;
9263 framepack->nSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT);
9264 framepack->nVersion.nVersion = OMX_SPEC_VERSION;
9265 framepack->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9266 memcpy(&framepack->id, s3d_frame_packing_payload,
9267 sizeof(struct msm_vidc_s3d_frame_packing_payload));
9268 memcpy(&m_frame_pack_arrangement, framepack,
9269 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
9270 print_debug_extradata(extra);
9271}
9272
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08009273void omx_vdec::append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9274 struct msm_vidc_frame_qp_payload *qp_payload)
9275{
9276 OMX_QCOM_EXTRADATA_QP * qp = NULL;
9277 if (!qp_payload) {
9278 DEBUG_PRINT_ERROR("QP payload is NULL");
9279 return;
9280 }
9281 extra->nSize = OMX_QP_EXTRADATA_SIZE;
9282 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9283 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9284 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataQP;
9285 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_QP);
9286 qp = (OMX_QCOM_EXTRADATA_QP *)extra->data;
9287 qp->nQP = qp_payload->frame_qp;
9288 print_debug_extradata(extra);
9289}
9290
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08009291void omx_vdec::append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9292 struct msm_vidc_frame_bits_info_payload *bits_payload)
9293{
9294 OMX_QCOM_EXTRADATA_BITS_INFO * bits = NULL;
9295 if (!bits_payload) {
9296 DEBUG_PRINT_ERROR("bits info payload is NULL");
9297 return;
9298 }
9299 extra->nSize = OMX_BITSINFO_EXTRADATA_SIZE;
9300 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9301 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9302 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo;
9303 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_BITS_INFO);
9304 bits = (OMX_QCOM_EXTRADATA_BITS_INFO*)extra->data;
9305 bits->frame_bits = bits_payload->frame_bits;
9306 bits->header_bits = bits_payload->header_bits;
9307 print_debug_extradata(extra);
9308}
9309
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009310void omx_vdec::append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9311 OMX_OTHER_EXTRADATATYPE *p_user)
9312{
9313 int userdata_size = 0;
9314 struct msm_vidc_stream_userdata_payload *userdata_payload = NULL;
9315 userdata_payload =
9316 (struct msm_vidc_stream_userdata_payload *)p_user->data;
9317 userdata_size = p_user->nDataSize;
Deva Ramasubramanian2ebfed32014-04-24 13:34:24 -07009318 extra->nSize = OMX_USERDATA_EXTRADATA_SIZE + p_user->nSize;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009319 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9320 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9321 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData;
9322 extra->nDataSize = userdata_size;
9323 if (extra->data && p_user->data && extra->nDataSize)
9324 memcpy(extra->data, p_user->data, extra->nDataSize);
9325 print_debug_extradata(extra);
9326}
9327
Shalaj Jain273b3e02012-06-22 19:08:03 -07009328void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra)
9329{
Arun Menon906de572013-06-18 17:01:40 -07009330 if (!client_extradata) {
9331 return;
9332 }
9333 extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE);
9334 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9335 extra->eType = OMX_ExtraDataNone;
9336 extra->nDataSize = 0;
9337 extra->data[0] = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009338
Arun Menon906de572013-06-18 17:01:40 -07009339 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009340}
9341
9342OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index)
9343{
Arun Menon906de572013-06-18 17:01:40 -07009344 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9345 if (index >= drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009346 DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07009347 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009348 }
Arun Menon906de572013-06-18 17:01:40 -07009349 if (m_desc_buffer_ptr == NULL) {
9350 m_desc_buffer_ptr = (desc_buffer_hdr*) \
9351 calloc( (sizeof(desc_buffer_hdr)),
9352 drv_ctx.ip_buf.actualcount);
9353 if (m_desc_buffer_ptr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009354 DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07009355 return OMX_ErrorInsufficientResources;
9356 }
9357 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009358
Arun Menon906de572013-06-18 17:01:40 -07009359 m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8));
9360 if (m_desc_buffer_ptr[index].buf_addr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009361 DEBUG_PRINT_ERROR("desc buffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07009362 return OMX_ErrorInsufficientResources;
9363 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009364
Arun Menon906de572013-06-18 17:01:40 -07009365 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009366}
9367
9368void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset)
9369{
Arun Menon906de572013-06-18 17:01:40 -07009370 DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries);
9371 if (m_demux_entries < 8192) {
9372 m_demux_offsets[m_demux_entries++] = address_offset;
9373 }
9374 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009375}
9376
9377void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr)
9378{
Arun Menon906de572013-06-18 17:01:40 -07009379 OMX_U32 bytes_to_parse = buf_hdr->nFilledLen;
9380 OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset;
9381 OMX_U32 index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009382
Arun Menon906de572013-06-18 17:01:40 -07009383 m_demux_entries = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009384
Arun Menon906de572013-06-18 17:01:40 -07009385 while (index < bytes_to_parse) {
9386 if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
9387 (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) ||
9388 ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
9389 (buf[index+2] == 0x01)) ) {
9390 //Found start code, insert address offset
9391 insert_demux_addr_offset(index);
9392 if (buf[index+2] == 0x01) // 3 byte start code
9393 index += 3;
9394 else //4 byte start code
9395 index += 4;
9396 } else
9397 index++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009398 }
Arun Menon906de572013-06-18 17:01:40 -07009399 DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries);
9400 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009401}
9402
9403OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr)
9404{
Arun Menon906de572013-06-18 17:01:40 -07009405 //fix this, handle 3 byte start code, vc1 terminator entry
9406 OMX_U8 *p_demux_data = NULL;
9407 OMX_U32 desc_data = 0;
9408 OMX_U32 start_addr = 0;
9409 OMX_U32 nal_size = 0;
9410 OMX_U32 suffix_byte = 0;
9411 OMX_U32 demux_index = 0;
9412 OMX_U32 buffer_index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009413
Arun Menon906de572013-06-18 17:01:40 -07009414 if (m_desc_buffer_ptr == NULL) {
9415 DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries.");
9416 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009417 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009418
Arun Menon906de572013-06-18 17:01:40 -07009419 buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
9420 if (buffer_index > drv_ctx.ip_buf.actualcount) {
9421 DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index);
9422 return OMX_ErrorBadParameter;
9423 }
9424
9425 p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr;
9426
9427 if ( ((OMX_U8*)p_demux_data == NULL) ||
9428 ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) {
9429 DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries.");
9430 return OMX_ErrorBadParameter;
9431 } else {
9432 for (; demux_index < m_demux_entries; demux_index++) {
9433 desc_data = 0;
9434 start_addr = m_demux_offsets[demux_index];
9435 if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) {
9436 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3];
9437 } else {
9438 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4];
9439 }
9440 if (demux_index < (m_demux_entries - 1)) {
9441 nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2;
9442 } else {
9443 nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2;
9444 }
9445 DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)",
9446 (void *)start_addr,
9447 suffix_byte,
9448 nal_size,
9449 demux_index);
9450 desc_data = (start_addr >> 3) << 1;
9451 desc_data |= (start_addr & 7) << 21;
9452 desc_data |= suffix_byte << 24;
9453
9454 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
9455 memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32));
9456 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
9457 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
9458
9459 p_demux_data += 16;
9460 }
9461 if (codec_type_parse == CODEC_TYPE_VC1) {
9462 DEBUG_PRINT_LOW("VC1 terminator entry");
9463 desc_data = 0;
9464 desc_data = 0x82 << 24;
9465 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
9466 memset(p_demux_data + 4, 0, sizeof(OMX_U32));
9467 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
9468 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
9469 p_demux_data += 16;
9470 m_demux_entries++;
9471 }
9472 //Add zero word to indicate end of descriptors
9473 memset(p_demux_data, 0, sizeof(OMX_U32));
9474
9475 m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32);
9476 DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size);
9477 }
9478 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
9479 m_demux_entries = 0;
9480 DEBUG_PRINT_LOW("Demux table complete!");
9481 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009482}
9483
Deva Ramasubramanian9403f022012-11-28 18:27:53 -08009484OMX_ERRORTYPE omx_vdec::createDivxDrmContext()
Shalaj Jain273b3e02012-06-22 19:08:03 -07009485{
Arun Menon906de572013-06-18 17:01:40 -07009486 OMX_ERRORTYPE err = OMX_ErrorNone;
9487 iDivXDrmDecrypt = DivXDrmDecrypt::Create();
9488 if (iDivXDrmDecrypt) {
9489 OMX_ERRORTYPE err = iDivXDrmDecrypt->Init();
9490 if (err!=OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009491 DEBUG_PRINT_ERROR("ERROR :iDivXDrmDecrypt->Init %d", err);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009492 delete iDivXDrmDecrypt;
9493 iDivXDrmDecrypt = NULL;
Arun Menon906de572013-06-18 17:01:40 -07009494 }
9495 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009496 DEBUG_PRINT_ERROR("Unable to Create DIVX DRM");
Arun Menon906de572013-06-18 17:01:40 -07009497 err = OMX_ErrorUndefined;
9498 }
9499 return err;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009500}
Shalaj Jain273b3e02012-06-22 19:08:03 -07009501
Vinay Kaliada4f4422013-01-09 10:45:03 -08009502omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf()
9503{
Arun Menon906de572013-06-18 17:01:40 -07009504 enabled = false;
9505 omx = NULL;
9506 init_members();
9507 ColorFormat = OMX_COLOR_FormatMax;
Praveen Chavandb7776f2014-02-06 18:17:25 -08009508 dest_format = YCbCr420P;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009509}
9510
9511void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client)
9512{
Arun Menon906de572013-06-18 17:01:40 -07009513 omx = reinterpret_cast<omx_vdec*>(client);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009514}
9515
Arun Menon906de572013-06-18 17:01:40 -07009516void omx_vdec::allocate_color_convert_buf::init_members()
9517{
9518 allocated_count = 0;
9519 buffer_size_req = 0;
9520 buffer_alignment_req = 0;
9521 memset(m_platform_list_client,0,sizeof(m_platform_list_client));
9522 memset(m_platform_entry_client,0,sizeof(m_platform_entry_client));
9523 memset(m_pmem_info_client,0,sizeof(m_pmem_info_client));
9524 memset(m_out_mem_ptr_client,0,sizeof(m_out_mem_ptr_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08009525#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009526 memset(op_buf_ion_info,0,sizeof(m_platform_entry_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08009527#endif
Arun Menon906de572013-06-18 17:01:40 -07009528 for (int i = 0; i < MAX_COUNT; i++)
9529 pmem_fd[i] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009530}
9531
Arun Menon906de572013-06-18 17:01:40 -07009532omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf()
9533{
9534 c2d.destroy();
Vinay Kaliada4f4422013-01-09 10:45:03 -08009535}
9536
9537bool omx_vdec::allocate_color_convert_buf::update_buffer_req()
9538{
Arun Menon906de572013-06-18 17:01:40 -07009539 bool status = true;
9540 unsigned int src_size = 0, destination_size = 0;
9541 OMX_COLOR_FORMATTYPE drv_color_format;
9542 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009543 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07009544 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009545 }
Arun Menon906de572013-06-18 17:01:40 -07009546 if (!enabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009547 DEBUG_PRINT_HIGH("No color conversion required");
Arun Menon906de572013-06-18 17:01:40 -07009548 return status;
9549 }
9550 pthread_mutex_lock(&omx->c_lock);
9551 if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 &&
9552 ColorFormat != OMX_COLOR_FormatYUV420Planar) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009553 DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion");
Arun Menon906de572013-06-18 17:01:40 -07009554 status = false;
9555 goto fail_update_buf_req;
9556 }
9557 c2d.close();
9558 status = c2d.open(omx->drv_ctx.video_resolution.frame_height,
9559 omx->drv_ctx.video_resolution.frame_width,
Praveen Chavandb7776f2014-02-06 18:17:25 -08009560 NV12_128m,dest_format);
Arun Menon906de572013-06-18 17:01:40 -07009561 if (status) {
9562 status = c2d.get_buffer_size(C2D_INPUT,src_size);
9563 if (status)
9564 status = c2d.get_buffer_size(C2D_OUTPUT,destination_size);
9565 }
9566 if (status) {
9567 if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size ||
9568 !destination_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009569 DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d"
Arun Menon906de572013-06-18 17:01:40 -07009570 "driver size %d destination size %d",
9571 src_size,omx->drv_ctx.op_buf.buffer_size,destination_size);
9572 status = false;
9573 c2d.close();
9574 buffer_size_req = 0;
9575 } else {
9576 buffer_size_req = destination_size;
9577 if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size)
9578 buffer_size_req = omx->drv_ctx.op_buf.buffer_size;
9579 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
9580 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
9581 }
9582 }
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009583fail_update_buf_req:
Arun Menon906de572013-06-18 17:01:40 -07009584 pthread_mutex_unlock(&omx->c_lock);
9585 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009586}
9587
9588bool omx_vdec::allocate_color_convert_buf::set_color_format(
Arun Menon906de572013-06-18 17:01:40 -07009589 OMX_COLOR_FORMATTYPE dest_color_format)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009590{
Arun Menon906de572013-06-18 17:01:40 -07009591 bool status = true;
9592 OMX_COLOR_FORMATTYPE drv_color_format;
9593 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009594 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07009595 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009596 }
Arun Menon906de572013-06-18 17:01:40 -07009597 pthread_mutex_lock(&omx->c_lock);
9598 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
9599 drv_color_format = (OMX_COLOR_FORMATTYPE)
9600 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
9601 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009602 DEBUG_PRINT_ERROR("Incorrect color format");
Arun Menon906de572013-06-18 17:01:40 -07009603 status = false;
9604 }
9605 if (status && (drv_color_format != dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009606 DEBUG_PRINT_LOW("Enabling C2D");
Praveen Chavandb7776f2014-02-06 18:17:25 -08009607 if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) &&
9608 (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009609 DEBUG_PRINT_ERROR("Unsupported color format for c2d");
Arun Menon906de572013-06-18 17:01:40 -07009610 status = false;
9611 } else {
Praveen Chavandb7776f2014-02-06 18:17:25 -08009612 ColorFormat = dest_color_format;
9613 dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ?
9614 YCbCr420P : YCbCr420SP;
Arun Menon906de572013-06-18 17:01:40 -07009615 if (enabled)
9616 c2d.destroy();
9617 enabled = false;
9618 if (!c2d.init()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009619 DEBUG_PRINT_ERROR("open failed for c2d");
Arun Menon906de572013-06-18 17:01:40 -07009620 status = false;
9621 } else
9622 enabled = true;
9623 }
9624 } else {
9625 if (enabled)
9626 c2d.destroy();
9627 enabled = false;
9628 }
9629 pthread_mutex_unlock(&omx->c_lock);
9630 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009631}
9632
9633OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr()
9634{
Arun Menon906de572013-06-18 17:01:40 -07009635 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009636 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009637 return NULL;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009638 }
Arun Menon906de572013-06-18 17:01:40 -07009639 if (!enabled)
9640 return omx->m_out_mem_ptr;
9641 return m_out_mem_ptr_client;
9642}
9643
9644 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr
9645(OMX_BUFFERHEADERTYPE *bufadd)
9646{
9647 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009648 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009649 return NULL;
9650 }
9651 if (!enabled)
9652 return bufadd;
9653
9654 unsigned index = 0;
9655 index = bufadd - omx->m_out_mem_ptr;
9656 if (index < omx->drv_ctx.op_buf.actualcount) {
9657 m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS);
9658 m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp;
9659 bool status;
9660 if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) {
9661 pthread_mutex_lock(&omx->c_lock);
9662 status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd,
9663 omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index],
9664 pmem_baseaddress[index], pmem_baseaddress[index]);
Arun Menon906de572013-06-18 17:01:40 -07009665 if (!status) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009666 DEBUG_PRINT_ERROR("Failed color conversion %d", status);
Arun Menon906de572013-06-18 17:01:40 -07009667 m_out_mem_ptr_client[index].nFilledLen = 0;
Leena Winterrowd270a7042014-09-30 13:05:55 -07009668 pthread_mutex_unlock(&omx->c_lock);
Arun Menon906de572013-06-18 17:01:40 -07009669 return &m_out_mem_ptr_client[index];
Praveen Chavan6d6b7252014-09-15 17:05:54 -07009670 } else {
9671 unsigned int filledLen = 0;
9672 c2d.get_output_filled_length(filledLen);
9673 m_out_mem_ptr_client[index].nFilledLen = filledLen;
Arun Menon906de572013-06-18 17:01:40 -07009674 }
Leena Winterrowd270a7042014-09-30 13:05:55 -07009675 pthread_mutex_unlock(&omx->c_lock);
Arun Menon906de572013-06-18 17:01:40 -07009676 } else
9677 m_out_mem_ptr_client[index].nFilledLen = 0;
9678 return &m_out_mem_ptr_client[index];
9679 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009680 DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009681 return NULL;
9682}
9683
9684 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr
9685(OMX_BUFFERHEADERTYPE *bufadd)
9686{
9687 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009688 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009689 return NULL;
9690 }
9691 if (!enabled)
9692 return bufadd;
9693 unsigned index = 0;
9694 index = bufadd - m_out_mem_ptr_client;
9695 if (index < omx->drv_ctx.op_buf.actualcount) {
9696 return &omx->m_out_mem_ptr[index];
9697 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009698 DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009699 return NULL;
9700}
9701 bool omx_vdec::allocate_color_convert_buf::get_buffer_req
9702(unsigned int &buffer_size)
9703{
9704 bool status = true;
9705 pthread_mutex_lock(&omx->c_lock);
9706 if (!enabled)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009707 buffer_size = omx->drv_ctx.op_buf.buffer_size;
Arun Menon906de572013-06-18 17:01:40 -07009708 else {
9709 if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009710 DEBUG_PRINT_ERROR("Get buffer size failed");
Arun Menon906de572013-06-18 17:01:40 -07009711 status = false;
9712 goto fail_get_buffer_size;
9713 }
9714 }
9715 if (buffer_size < omx->drv_ctx.op_buf.buffer_size)
9716 buffer_size = omx->drv_ctx.op_buf.buffer_size;
9717 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
9718 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009719fail_get_buffer_size:
Arun Menon906de572013-06-18 17:01:40 -07009720 pthread_mutex_unlock(&omx->c_lock);
9721 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009722}
9723OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07009724 OMX_BUFFERHEADERTYPE *bufhdr)
9725{
9726 unsigned int index = 0;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009727
Arun Menon906de572013-06-18 17:01:40 -07009728 if (!enabled)
9729 return omx->free_output_buffer(bufhdr);
9730 if (enabled && omx->is_component_secure())
9731 return OMX_ErrorNone;
9732 if (!allocated_count || !bufhdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009733 DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr);
Arun Menon906de572013-06-18 17:01:40 -07009734 return OMX_ErrorBadParameter;
9735 }
9736 index = bufhdr - m_out_mem_ptr_client;
9737 if (index >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009738 DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer");
Arun Menon906de572013-06-18 17:01:40 -07009739 return OMX_ErrorBadParameter;
9740 }
9741 if (pmem_fd[index] > 0) {
9742 munmap(pmem_baseaddress[index], buffer_size_req);
9743 close(pmem_fd[index]);
9744 }
9745 pmem_fd[index] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009746#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009747 omx->free_ion_memory(&op_buf_ion_info[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009748#endif
Arun Menon906de572013-06-18 17:01:40 -07009749 m_heap_ptr[index].video_heap_ptr = NULL;
9750 if (allocated_count > 0)
9751 allocated_count--;
9752 else
9753 allocated_count = 0;
9754 if (!allocated_count) {
9755 pthread_mutex_lock(&omx->c_lock);
9756 c2d.close();
9757 init_members();
9758 pthread_mutex_unlock(&omx->c_lock);
9759 }
9760 return omx->free_output_buffer(&omx->m_out_mem_ptr[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009761}
9762
9763OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07009764 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009765{
Arun Menon906de572013-06-18 17:01:40 -07009766 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9767 if (!enabled) {
9768 eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes);
9769 return eRet;
9770 }
9771 if (enabled && omx->is_component_secure()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009772 DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d",
Arun Menon906de572013-06-18 17:01:40 -07009773 omx->is_component_secure());
9774 return OMX_ErrorUnsupportedSetting;
9775 }
9776 if (!bufferHdr || bytes > buffer_size_req) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009777 DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr);
9778 DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu",
Arun Menon906de572013-06-18 17:01:40 -07009779 buffer_size_req,bytes);
9780 return OMX_ErrorBadParameter;
9781 }
9782 if (allocated_count >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009783 DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009784 return OMX_ErrorInsufficientResources;
9785 }
9786 OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL;
9787 eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr,
9788 port,appData,omx->drv_ctx.op_buf.buffer_size);
9789 if (eRet != OMX_ErrorNone || !temp_bufferHdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009790 DEBUG_PRINT_ERROR("Buffer allocation failed color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009791 return eRet;
9792 }
9793 if ((temp_bufferHdr - omx->m_out_mem_ptr) >=
Surajit Podderd2644d52013-08-28 17:59:06 +05309794 (int)omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009795 DEBUG_PRINT_ERROR("Invalid header index %d",
Arun Menon906de572013-06-18 17:01:40 -07009796 (temp_bufferHdr - omx->m_out_mem_ptr));
9797 return OMX_ErrorUndefined;
9798 }
9799 unsigned int i = allocated_count;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009800#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009801 op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory(
9802 buffer_size_req,buffer_alignment_req,
9803 &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data,
9804 0);
9805 pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd;
9806 if (op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009807 DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009808 return OMX_ErrorInsufficientResources;
9809 }
9810 pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req,
9811 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009812
Arun Menon906de572013-06-18 17:01:40 -07009813 if (pmem_baseaddress[i] == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009814 DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req);
Arun Menon906de572013-06-18 17:01:40 -07009815 close(pmem_fd[i]);
9816 omx->free_ion_memory(&op_buf_ion_info[i]);
9817 return OMX_ErrorInsufficientResources;
9818 }
9819 m_heap_ptr[i].video_heap_ptr = new VideoHeap (
9820 op_buf_ion_info[i].ion_device_fd,buffer_size_req,
9821 pmem_baseaddress[i],op_buf_ion_info[i].ion_alloc_data.handle,pmem_fd[i]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009822#endif
Arun Menon906de572013-06-18 17:01:40 -07009823 m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get();
9824 m_pmem_info_client[i].offset = 0;
9825 m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i];
9826 m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
9827 m_platform_list_client[i].nEntries = 1;
9828 m_platform_list_client[i].entryList = &m_platform_entry_client[i];
9829 m_out_mem_ptr_client[i].pOutputPortPrivate = NULL;
9830 m_out_mem_ptr_client[i].nAllocLen = buffer_size_req;
9831 m_out_mem_ptr_client[i].nFilledLen = 0;
9832 m_out_mem_ptr_client[i].nFlags = 0;
9833 m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9834 m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE);
9835 m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION;
9836 m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i];
9837 m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i];
9838 m_out_mem_ptr_client[i].pAppPrivate = appData;
9839 *bufferHdr = &m_out_mem_ptr_client[i];
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009840 DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr);
Arun Menon906de572013-06-18 17:01:40 -07009841 allocated_count++;
9842 return eRet;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009843}
9844
9845bool omx_vdec::is_component_secure()
9846{
Arun Menon906de572013-06-18 17:01:40 -07009847 return secure_mode;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009848}
9849
9850bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format)
9851{
Arun Menon906de572013-06-18 17:01:40 -07009852 bool status = true;
9853 if (!enabled) {
9854 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
9855 dest_color_format = (OMX_COLOR_FORMATTYPE)
9856 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
9857 else
9858 status = false;
9859 } else {
Praveen Chavandb7776f2014-02-06 18:17:25 -08009860 if (ColorFormat == OMX_COLOR_FormatYUV420Planar ||
9861 ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
9862 dest_color_format = ColorFormat;
Arun Menon906de572013-06-18 17:01:40 -07009863 } else
Praveen Chavandb7776f2014-02-06 18:17:25 -08009864 status = false;
Arun Menon906de572013-06-18 17:01:40 -07009865 }
9866 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009867}
Arun Menonbdb80b02013-08-12 17:45:54 -07009868
Arun Menonbdb80b02013-08-12 17:45:54 -07009869void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset)
9870{
9871 int i = 0;
9872 bool buf_present = false;
9873 pthread_mutex_lock(&m_lock);
9874 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9875 //check the buffer fd, offset, uv addr with list contents
9876 //If present increment reference.
9877 if ((out_dynamic_list[i].fd == fd) &&
9878 (out_dynamic_list[i].offset == offset)) {
9879 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009880 DEBUG_PRINT_LOW("buf_ref_add: [ALREADY PRESENT] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009881 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9882 buf_present = true;
9883 break;
9884 }
9885 }
9886 if (!buf_present) {
9887 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9888 //search for a entry to insert details of the new buffer
9889 if (out_dynamic_list[i].dup_fd == 0) {
9890 out_dynamic_list[i].fd = fd;
9891 out_dynamic_list[i].offset = offset;
9892 out_dynamic_list[i].dup_fd = dup(fd);
9893 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009894 DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009895 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9896 break;
9897 }
9898 }
9899 }
9900 pthread_mutex_unlock(&m_lock);
9901}
9902
9903void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset)
9904{
9905 int i = 0;
9906 pthread_mutex_lock(&m_lock);
9907 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9908 //check the buffer fd, offset, uv addr with list contents
9909 //If present decrement reference.
9910 if ((out_dynamic_list[i].fd == fd) &&
9911 (out_dynamic_list[i].offset == offset)) {
9912 out_dynamic_list[i].ref_count--;
9913 if (out_dynamic_list[i].ref_count == 0) {
9914 close(out_dynamic_list[i].dup_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009915 DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009916 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9917 out_dynamic_list[i].dup_fd = 0;
9918 out_dynamic_list[i].fd = 0;
9919 out_dynamic_list[i].offset = 0;
9920 }
9921 break;
9922 }
9923 }
9924 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009925 DEBUG_PRINT_ERROR("Error - could not remove ref, no match with any entry in list");
Arun Menonbdb80b02013-08-12 17:45:54 -07009926 }
9927 pthread_mutex_unlock(&m_lock);
9928}
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07009929
Arun Menon1fc764f2014-04-17 15:41:27 -07009930OMX_ERRORTYPE omx_vdec::enable_adaptive_playback(unsigned long nMaxFrameWidth,
9931 unsigned long nMaxFrameHeight)
9932{
9933
9934 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9935 int ret = 0;
9936 unsigned long min_res_buf_count = 0;
9937
9938 eRet = enable_smoothstreaming();
9939 if (eRet != OMX_ErrorNone) {
9940 DEBUG_PRINT_ERROR("Failed to enable Adaptive Playback on driver");
9941 return eRet;
9942 }
9943
9944 DEBUG_PRINT_HIGH("Enabling Adaptive playback for %lu x %lu",
9945 nMaxFrameWidth,
9946 nMaxFrameHeight);
9947 m_smoothstreaming_mode = true;
9948 m_smoothstreaming_width = nMaxFrameWidth;
9949 m_smoothstreaming_height = nMaxFrameHeight;
9950
9951 //Get upper limit buffer count for min supported resolution
9952 struct v4l2_format fmt;
9953 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
9954 fmt.fmt.pix_mp.height = m_decoder_capability.min_height;
9955 fmt.fmt.pix_mp.width = m_decoder_capability.min_width;
9956 fmt.fmt.pix_mp.pixelformat = output_capability;
9957
9958 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
9959 if (ret) {
9960 DEBUG_PRINT_ERROR("Set Resolution failed for HxW = %ux%u",
9961 m_decoder_capability.min_height,
9962 m_decoder_capability.min_width);
9963 return OMX_ErrorUnsupportedSetting;
9964 }
9965
9966 eRet = get_buffer_req(&drv_ctx.op_buf);
9967 if (eRet != OMX_ErrorNone) {
9968 DEBUG_PRINT_ERROR("failed to get_buffer_req");
9969 return eRet;
9970 }
9971
9972 min_res_buf_count = drv_ctx.op_buf.mincount;
9973 DEBUG_PRINT_LOW("enable adaptive - upper limit buffer count = %lu for HxW %ux%u",
9974 min_res_buf_count, m_decoder_capability.min_height, m_decoder_capability.min_width);
9975
9976 update_resolution(m_smoothstreaming_width, m_smoothstreaming_height,
9977 m_smoothstreaming_width, m_smoothstreaming_height);
9978 eRet = is_video_session_supported();
9979 if (eRet != OMX_ErrorNone) {
9980 DEBUG_PRINT_ERROR("video session is not supported");
9981 return eRet;
9982 }
9983
9984 //Get upper limit buffer size for max smooth streaming resolution set
9985 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
9986 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
9987 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
9988 fmt.fmt.pix_mp.pixelformat = output_capability;
9989 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
9990 if (ret) {
9991 DEBUG_PRINT_ERROR("Set Resolution failed for adaptive playback");
9992 return OMX_ErrorUnsupportedSetting;
9993 }
9994
9995 eRet = get_buffer_req(&drv_ctx.op_buf);
9996 if (eRet != OMX_ErrorNone) {
9997 DEBUG_PRINT_ERROR("failed to get_buffer_req!!");
9998 return eRet;
9999 }
10000 DEBUG_PRINT_LOW("enable adaptive - upper limit buffer size = %u",
10001 drv_ctx.op_buf.buffer_size);
10002
10003 drv_ctx.op_buf.mincount = min_res_buf_count;
10004 drv_ctx.op_buf.actualcount = min_res_buf_count;
10005 eRet = set_buffer_req(&drv_ctx.op_buf);
10006 if (eRet != OMX_ErrorNone) {
10007 DEBUG_PRINT_ERROR("failed to set_buffer_req");
10008 return eRet;
10009 }
10010
10011 eRet = get_buffer_req(&drv_ctx.op_buf);
10012 if (eRet != OMX_ErrorNone) {
10013 DEBUG_PRINT_ERROR("failed to get_buffer_req!!!");
10014 return eRet;
10015 }
10016 DEBUG_PRINT_HIGH("adaptive playback enabled, buf count = %u bufsize = %u",
10017 drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size);
10018 return eRet;
10019}
10020
Leena Winterrowd974fd1f2013-10-30 10:58:02 -070010021#ifdef _MSM8974_
10022void omx_vdec::send_codec_config() {
10023 if (codec_config_flag) {
10024 unsigned p1 = 0; // Parameter - 1
10025 unsigned p2 = 0; // Parameter - 2
10026 unsigned ident = 0;
10027 pthread_mutex_lock(&m_lock);
10028 DEBUG_PRINT_LOW("\n Check Queue for codec_config buffer \n");
10029 while (m_etb_q.m_size) {
10030 m_etb_q.pop_entry(&p1,&p2,&ident);
10031 if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
10032 if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
10033 if (empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\
10034 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
10035 DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy_arbitrary failure");
10036 omx_report_error();
10037 }
10038 } else {
10039 DEBUG_PRINT_LOW("\n Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2);
10040 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
10041 }
10042 } else if (ident == OMX_COMPONENT_GENERATE_ETB) {
10043 if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
10044 if (empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\
10045 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
10046 DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy failure");
10047 omx_report_error ();
10048 }
10049 } else {
10050 pending_input_buffers++;
10051 DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d",
10052 (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers);
10053 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
10054 }
10055 } else if (ident == OMX_COMPONENT_GENERATE_EBD) {
10056 DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_EBD %p",
10057 (OMX_BUFFERHEADERTYPE *)p1);
10058 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
10059 }
10060 }
10061 pthread_mutex_unlock(&m_lock);
10062 }
10063}
10064#endif
Praveen Chavan09a82b72014-10-18 09:09:45 -070010065
10066//static
10067OMX_ERRORTYPE omx_vdec::describeColorFormat(OMX_PTR pParam) {
10068
10069#ifndef FLEXYUV_SUPPORTED
10070 (void)pParam;
10071 return OMX_ErrorUndefined;
10072#else
10073
10074 if (pParam == NULL) {
10075 DEBUG_PRINT_ERROR("describeColorFormat: invalid params");
10076 return OMX_ErrorBadParameter;
10077 }
10078
10079 DescribeColorFormatParams *params = (DescribeColorFormatParams*)pParam;
10080
10081 MediaImage *img = &(params->sMediaImage);
10082 switch(params->eColorFormat) {
10083 case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m:
10084 {
10085 img->mType = MediaImage::MEDIA_IMAGE_TYPE_YUV;
10086 img->mNumPlanes = 3;
10087 // mWidth and mHeight represent the W x H of the largest plane
10088 // In our case, this happens to be the Stride x Scanlines of Y plane
10089 img->mWidth = params->nFrameWidth;
10090 img->mHeight = params->nFrameHeight;
10091 size_t planeWidth = VENUS_Y_STRIDE(COLOR_FMT_NV12, params->nFrameWidth);
10092 size_t planeHeight = VENUS_Y_SCANLINES(COLOR_FMT_NV12, params->nFrameHeight);
10093 img->mBitDepth = 8;
10094 //Plane 0 (Y)
10095 img->mPlane[MediaImage::Y].mOffset = 0;
10096 img->mPlane[MediaImage::Y].mColInc = 1;
10097 img->mPlane[MediaImage::Y].mRowInc = planeWidth; //same as stride
10098 img->mPlane[MediaImage::Y].mHorizSubsampling = 1;
10099 img->mPlane[MediaImage::Y].mVertSubsampling = 1;
10100 //Plane 1 (U)
10101 img->mPlane[MediaImage::U].mOffset = planeWidth * planeHeight;
10102 img->mPlane[MediaImage::U].mColInc = 2; //interleaved UV
10103 img->mPlane[MediaImage::U].mRowInc =
10104 VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth);
10105 img->mPlane[MediaImage::U].mHorizSubsampling = 2;
10106 img->mPlane[MediaImage::U].mVertSubsampling = 2;
10107 //Plane 2 (V)
10108 img->mPlane[MediaImage::V].mOffset = planeWidth * planeHeight + 1;
10109 img->mPlane[MediaImage::V].mColInc = 2; //interleaved UV
10110 img->mPlane[MediaImage::V].mRowInc =
10111 VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth);
10112 img->mPlane[MediaImage::V].mHorizSubsampling = 2;
10113 img->mPlane[MediaImage::V].mVertSubsampling = 2;
10114 break;
10115 }
10116
10117 case OMX_COLOR_FormatYUV420Planar:
10118 case OMX_COLOR_FormatYUV420SemiPlanar:
10119 // We need not describe the standard OMX linear formats as these are
10120 // understood by client. Fail this deliberately to let client fill-in
10121 return OMX_ErrorUnsupportedSetting;
10122
10123 default:
10124 // Rest all formats which are non-linear cannot be described
10125 DEBUG_PRINT_LOW("color-format %x is not flexible", params->eColorFormat);
10126 img->mType = MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN;
10127 return OMX_ErrorNone;
10128 };
10129
10130 DEBUG_PRINT_LOW("NOTE: Describe color format : %x", params->eColorFormat);
10131 DEBUG_PRINT_LOW(" FrameWidth x FrameHeight : %d x %d", params->nFrameWidth, params->nFrameHeight);
10132 DEBUG_PRINT_LOW(" YWidth x YHeight : %d x %d", img->mWidth, img->mHeight);
10133 for (size_t i = 0; i < img->mNumPlanes; ++i) {
10134 DEBUG_PRINT_LOW(" Plane[%d] : offset=%d / xStep=%d / yStep = %d",
10135 i, img->mPlane[i].mOffset, img->mPlane[i].mColInc, img->mPlane[i].mRowInc);
10136 }
10137 return OMX_ErrorNone;
10138#endif //FLEXYUV_SUPPORTED
10139}
10140