blob: 9d82f688f20adbae88ac8ba09022fa94b8275bbd [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
42#include <string.h>
43#include <pthread.h>
44#include <sys/prctl.h>
45#include <stdlib.h>
46#include <unistd.h>
47#include <errno.h>
48#include "omx_vdec.h"
49#include <fcntl.h>
50#include <limits.h>
Deva Ramasubramanian15bbc1c2013-05-13 16:05:03 -070051#include <stdlib.h>
Arun Menonbdb80b02013-08-12 17:45:54 -070052#include <media/hardware/HardwareAPI.h>
Vinay Kaliada8f3cf2012-12-21 18:26:21 -080053#include <media/msm_media_info.h>
Shalaj Jain273b3e02012-06-22 19:08:03 -070054
55#ifndef _ANDROID_
56#include <sys/ioctl.h>
57#include <sys/mman.h>
58#endif //_ANDROID_
59
60#ifdef _ANDROID_
61#include <cutils/properties.h>
62#undef USE_EGL_IMAGE_GPU
63#endif
64
Vinay Kalia0e75e9a2012-09-27 15:41:53 -070065#include <qdMetaData.h>
Shalaj Jain273b3e02012-06-22 19:08:03 -070066
67#ifdef _ANDROID_
68#include "DivXDrmDecrypt.h"
69#endif //_ANDROID_
70
Arun Menon45346052013-11-13 12:40:08 -080071#ifdef METADATA_FOR_DYNAMIC_MODE
Arun Menon9af783f2013-10-22 12:57:14 -070072#include "QComOMXMetadata.h"
73#endif
74
Shalaj Jain273b3e02012-06-22 19:08:03 -070075#ifdef USE_EGL_IMAGE_GPU
76#include <EGL/egl.h>
77#include <EGL/eglQCOM.h>
78#define EGL_BUFFER_HANDLE_QCOM 0x4F00
79#define EGL_BUFFER_OFFSET_QCOM 0x4F01
80#endif
Vinay Kalia21649b32013-03-18 17:28:07 -070081
Jayasena Sangaraboina51230642013-08-21 18:02:13 -070082#define BUFFER_LOG_LOC "/data/misc/media"
83
Shalaj Jain273b3e02012-06-22 19:08:03 -070084#ifdef OUTPUT_EXTRADATA_LOG
85FILE *outputExtradataFile;
Deva Ramasubramanianee6f1f42014-01-31 12:49:18 -080086char output_extradata_filename [] = "/data/misc/extradata";
Shalaj Jain273b3e02012-06-22 19:08:03 -070087#endif
88
89#define DEFAULT_FPS 30
Shalaj Jain273b3e02012-06-22 19:08:03 -070090#define MAX_SUPPORTED_FPS 120
Deepak Vermaa2efdb12013-12-26 12:30:05 +053091#define DEFAULT_WIDTH_ALIGNMENT 128
92#define DEFAULT_HEIGHT_ALIGNMENT 32
Shalaj Jain273b3e02012-06-22 19:08:03 -070093
94#define VC1_SP_MP_START_CODE 0xC5000000
95#define VC1_SP_MP_START_CODE_MASK 0xFF000000
96#define VC1_AP_SEQ_START_CODE 0x0F010000
97#define VC1_STRUCT_C_PROFILE_MASK 0xF0
98#define VC1_STRUCT_B_LEVEL_MASK 0xE0000000
99#define VC1_SIMPLE_PROFILE 0
100#define VC1_MAIN_PROFILE 1
101#define VC1_ADVANCE_PROFILE 3
102#define VC1_SIMPLE_PROFILE_LOW_LEVEL 0
103#define VC1_SIMPLE_PROFILE_MED_LEVEL 2
104#define VC1_STRUCT_C_LEN 4
105#define VC1_STRUCT_C_POS 8
106#define VC1_STRUCT_A_POS 12
107#define VC1_STRUCT_B_POS 24
108#define VC1_SEQ_LAYER_SIZE 36
Vinay Kaliab09886c2012-08-20 11:27:25 -0700109#define POLL_TIMEOUT 0x7fffffff
Shalaj Jain273b3e02012-06-22 19:08:03 -0700110
111#define MEM_DEVICE "/dev/ion"
112#define MEM_HEAP_ID ION_CP_MM_HEAP_ID
113
114#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700115extern "C" {
116#include<utils/Log.h>
117}
Shalaj Jain273b3e02012-06-22 19:08:03 -0700118#endif//_ANDROID_
119
Vinay Kalia53fa6832012-10-11 17:55:30 -0700120#define SZ_4K 0x1000
121#define SZ_1M 0x100000
122
Shalaj Jain273b3e02012-06-22 19:08:03 -0700123#define Log2(number, power) { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) && power < 16) { temp >>=0x1; power++; } }
124#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 -0700125#define EXTRADATA_IDX(__num_planes) (__num_planes - 1)
126
Vinay Kaliadb90f8c2012-11-19 18:57:56 -0800127#define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA)
Jia Meng3a3c6492013-12-19 17:16:52 +0800128#define DEFAULT_CONCEAL_COLOR "32896" //0x8080, black by default
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700129
130int debug_level = PRIO_ERROR;
131
Deepak Vermaa2efdb12013-12-26 12:30:05 +0530132static OMX_U32 maxSmoothStreamingWidth = 1920;
133static OMX_U32 maxSmoothStreamingHeight = 1088;
Praveen Chavancf924182013-12-06 23:16:23 -0800134
Shalaj Jain273b3e02012-06-22 19:08:03 -0700135void* async_message_thread (void *input)
136{
Arun Menon906de572013-06-18 17:01:40 -0700137 OMX_BUFFERHEADERTYPE *buffer;
138 struct v4l2_plane plane[VIDEO_MAX_PLANES];
139 struct pollfd pfd;
140 struct v4l2_buffer v4l2_buf;
141 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
142 struct v4l2_event dqevent;
143 omx_vdec *omx = reinterpret_cast<omx_vdec*>(input);
144 pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI;
145 pfd.fd = omx->drv_ctx.video_driver_fd;
146 int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700147 DEBUG_PRINT_HIGH("omx_vdec: Async thread start");
Arun Menon906de572013-06-18 17:01:40 -0700148 prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0);
149 while (1) {
150 rc = poll(&pfd, 1, POLL_TIMEOUT);
151 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700152 DEBUG_PRINT_ERROR("Poll timedout");
Arun Menon906de572013-06-18 17:01:40 -0700153 break;
154 } else if (rc < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700155 DEBUG_PRINT_ERROR("Error while polling: %d", rc);
Arun Menon906de572013-06-18 17:01:40 -0700156 break;
157 }
158 if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) {
159 struct vdec_msginfo vdec_msg;
160 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
161 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
162 v4l2_buf.length = omx->drv_ctx.num_planes;
163 v4l2_buf.m.planes = plane;
164 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
165 vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
166 vdec_msg.status_code=VDEC_S_SUCCESS;
167 vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf;
168 vdec_msg.msgdata.output_frame.len=plane[0].bytesused;
169 vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr;
170 vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) +
171 (uint64_t)v4l2_buf.timestamp.tv_usec;
172 if (vdec_msg.msgdata.output_frame.len) {
173 vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2];
174 vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3];
175 vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4];
176 vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5];
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +0530177 vdec_msg.msgdata.output_frame.picsize.frame_width = plane[0].reserved[6];
178 vdec_msg.msgdata.output_frame.picsize.frame_height = plane[0].reserved[7];
Arun Menon906de572013-06-18 17:01:40 -0700179 }
180 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700181 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700182 break;
183 }
184 }
185 }
186 if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) {
187 struct vdec_msginfo vdec_msg;
188 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
189 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
190 v4l2_buf.length = 1;
191 v4l2_buf.m.planes = plane;
192 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
193 vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE;
194 vdec_msg.status_code=VDEC_S_SUCCESS;
195 vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf;
196 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700197 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700198 break;
199 }
200 }
201 }
202 if (pfd.revents & POLLPRI) {
203 rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent);
204 if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) {
205 struct vdec_msginfo vdec_msg;
206 vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED;
207 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700208 DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient");
Arun Menon906de572013-06-18 17:01:40 -0700209 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700210 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700211 break;
212 }
213 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) {
214 struct vdec_msginfo vdec_msg;
215 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE;
216 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700217 DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700218 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700219 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700220 break;
221 }
222 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE;
223 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700224 DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700225 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700226 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700227 break;
228 }
229 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700230 DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700231 break;
Deepak Verma24720fb2014-01-29 16:57:40 +0530232 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_HW_OVERLOAD) {
233 struct vdec_msginfo vdec_msg;
234 vdec_msg.msgcode=VDEC_MSG_EVT_HW_OVERLOAD;
235 vdec_msg.status_code=VDEC_S_SUCCESS;
236 DEBUG_PRINT_ERROR("HW Overload received");
237 if (omx->async_message_process(input,&vdec_msg) < 0) {
238 DEBUG_PRINT_HIGH("async_message_thread Exited");
239 break;
240 }
Arun Menon906de572013-06-18 17:01:40 -0700241 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) {
242 struct vdec_msginfo vdec_msg;
Jia Meng1e236c82014-04-03 10:54:39 +0800243 vdec_msg.msgcode = VDEC_MSG_EVT_HW_ERROR;
244 vdec_msg.status_code = VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700245 DEBUG_PRINT_HIGH("SYS Error Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700246 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700247 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700248 break;
249 }
Arun Menon45346052013-11-13 12:40:08 -0800250 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) {
Arun Menonbdb80b02013-08-12 17:45:54 -0700251 unsigned int *ptr = (unsigned int *)dqevent.u.data;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700252 DEBUG_PRINT_LOW("REFERENCE RELEASE EVENT RECVD fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700253 omx->buf_ref_remove(ptr[0], ptr[1]);
254 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) {
255 unsigned int *ptr = (unsigned int *)dqevent.u.data;
256 struct vdec_msginfo vdec_msg;
257
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700258 DEBUG_PRINT_LOW("Release unqueued buffer event recvd fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700259
260 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
261 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
262 v4l2_buf.length = omx->drv_ctx.num_planes;
263 v4l2_buf.m.planes = plane;
264 v4l2_buf.index = ptr[5];
265 v4l2_buf.flags = 0;
266
267 vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
268 vdec_msg.status_code = VDEC_S_SUCCESS;
269 vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf;
270 vdec_msg.msgdata.output_frame.len = 0;
271 vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2];
272 vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) +
273 (uint64_t)ptr[4];
274 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700275 DEBUG_PRINT_HIGH("async_message_thread Exitedn");
Arun Menonbdb80b02013-08-12 17:45:54 -0700276 break;
277 }
278 }
Arun Menonbdb80b02013-08-12 17:45:54 -0700279 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700280 DEBUG_PRINT_HIGH("VIDC Some Event recieved");
Arun Menon906de572013-06-18 17:01:40 -0700281 continue;
282 }
283 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -0700284 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700285 DEBUG_PRINT_HIGH("omx_vdec: Async thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700286 return NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700287}
288
289void* message_thread(void *input)
290{
Arun Menon906de572013-06-18 17:01:40 -0700291 omx_vdec* omx = reinterpret_cast<omx_vdec*>(input);
292 unsigned char id;
293 int n;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700294
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700295 DEBUG_PRINT_HIGH("omx_vdec: message thread start");
Arun Menon906de572013-06-18 17:01:40 -0700296 prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0);
297 while (1) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700298
Arun Menon906de572013-06-18 17:01:40 -0700299 n = read(omx->m_pipe_in, &id, 1);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700300
Arun Menon906de572013-06-18 17:01:40 -0700301 if (0 == n) {
302 break;
303 }
304
305 if (1 == n) {
306 omx->process_event_cb(omx, id);
307 }
308 if ((n < 0) && (errno != EINTR)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700309 DEBUG_PRINT_LOW("ERROR: read from pipe failed, ret %d errno %d", n, errno);
Arun Menon906de572013-06-18 17:01:40 -0700310 break;
311 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700312 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700313 DEBUG_PRINT_HIGH("omx_vdec: message thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700314 return 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700315}
316
317void post_message(omx_vdec *omx, unsigned char id)
318{
Arun Menon906de572013-06-18 17:01:40 -0700319 int ret_value;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700320 DEBUG_PRINT_LOW("omx_vdec: post_message %d pipe out%d", id,omx->m_pipe_out);
Arun Menon906de572013-06-18 17:01:40 -0700321 ret_value = write(omx->m_pipe_out, &id, 1);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700322 DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700323}
324
325// omx_cmd_queue destructor
326omx_vdec::omx_cmd_queue::~omx_cmd_queue()
327{
Arun Menon906de572013-06-18 17:01:40 -0700328 // Nothing to do
Shalaj Jain273b3e02012-06-22 19:08:03 -0700329}
330
331// omx cmd queue constructor
332omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0)
333{
334 memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE);
335}
336
337// omx cmd queue insert
338bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id)
339{
Arun Menon906de572013-06-18 17:01:40 -0700340 bool ret = true;
341 if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) {
342 m_q[m_write].id = id;
343 m_q[m_write].param1 = p1;
344 m_q[m_write].param2 = p2;
345 m_write++;
346 m_size ++;
347 if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) {
348 m_write = 0;
349 }
350 } else {
351 ret = false;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700352 DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700353 }
Arun Menon906de572013-06-18 17:01:40 -0700354 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700355}
356
357// omx cmd queue pop
358bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id)
359{
Arun Menon906de572013-06-18 17:01:40 -0700360 bool ret = true;
361 if (m_size > 0) {
362 *id = m_q[m_read].id;
363 *p1 = m_q[m_read].param1;
364 *p2 = m_q[m_read].param2;
365 // Move the read pointer ahead
366 ++m_read;
367 --m_size;
368 if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) {
369 m_read = 0;
370 }
371 } else {
372 ret = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700373 }
Arun Menon906de572013-06-18 17:01:40 -0700374 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700375}
376
377// Retrieve the first mesg type in the queue
378unsigned omx_vdec::omx_cmd_queue::get_q_msg_type()
379{
380 return m_q[m_read].id;
381}
382
383#ifdef _ANDROID_
384omx_vdec::ts_arr_list::ts_arr_list()
385{
Arun Menon906de572013-06-18 17:01:40 -0700386 //initialize timestamps array
387 memset(m_ts_arr_list, 0, ( sizeof(ts_entry) * MAX_NUM_INPUT_OUTPUT_BUFFERS) );
Shalaj Jain273b3e02012-06-22 19:08:03 -0700388}
389omx_vdec::ts_arr_list::~ts_arr_list()
390{
Arun Menon906de572013-06-18 17:01:40 -0700391 //free m_ts_arr_list?
Shalaj Jain273b3e02012-06-22 19:08:03 -0700392}
393
394bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts)
395{
Arun Menon906de572013-06-18 17:01:40 -0700396 bool ret = true;
397 bool duplicate_ts = false;
398 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700399
Arun Menon906de572013-06-18 17:01:40 -0700400 //insert at the first available empty location
401 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
402 if (!m_ts_arr_list[idx].valid) {
403 //found invalid or empty entry, save timestamp
404 m_ts_arr_list[idx].valid = true;
405 m_ts_arr_list[idx].timestamp = ts;
406 DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)",
407 ts, idx);
408 break;
409 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700410 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700411
Arun Menon906de572013-06-18 17:01:40 -0700412 if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) {
413 DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert");
414 ret = false;
415 }
416 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700417}
418
419bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts)
420{
Arun Menon906de572013-06-18 17:01:40 -0700421 bool ret = true;
422 int min_idx = -1;
423 OMX_TICKS min_ts = 0;
424 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700425
Arun Menon906de572013-06-18 17:01:40 -0700426 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700427
Arun Menon906de572013-06-18 17:01:40 -0700428 if (m_ts_arr_list[idx].valid) {
429 //found valid entry, save index
430 if (min_idx < 0) {
431 //first valid entry
432 min_ts = m_ts_arr_list[idx].timestamp;
433 min_idx = idx;
434 } else if (m_ts_arr_list[idx].timestamp < min_ts) {
435 min_ts = m_ts_arr_list[idx].timestamp;
436 min_idx = idx;
437 }
438 }
439
Shalaj Jain273b3e02012-06-22 19:08:03 -0700440 }
441
Arun Menon906de572013-06-18 17:01:40 -0700442 if (min_idx < 0) {
443 //no valid entries found
444 DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop");
445 ts = 0;
446 ret = false;
447 } else {
448 ts = m_ts_arr_list[min_idx].timestamp;
449 m_ts_arr_list[min_idx].valid = false;
450 DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)",
451 ts, min_idx);
452 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700453
Arun Menon906de572013-06-18 17:01:40 -0700454 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700455
456}
457
458
459bool omx_vdec::ts_arr_list::reset_ts_list()
460{
Arun Menon906de572013-06-18 17:01:40 -0700461 bool ret = true;
462 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700463
Arun Menon906de572013-06-18 17:01:40 -0700464 DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list");
465 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
466 m_ts_arr_list[idx].valid = false;
467 }
468 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700469}
470#endif
471
472// factory function executed by the core to create instances
473void *get_omx_component_factory_fn(void)
474{
Arun Menon906de572013-06-18 17:01:40 -0700475 return (new omx_vdec);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700476}
477
478#ifdef _ANDROID_
479#ifdef USE_ION
480VideoHeap::VideoHeap(int devicefd, size_t size, void* base,
Arun Menon906de572013-06-18 17:01:40 -0700481 struct ion_handle *handle, int ionMapfd)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700482{
Arun Menon906de572013-06-18 17:01:40 -0700483 // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700484}
485#else
486VideoHeap::VideoHeap(int fd, size_t size, void* base)
487{
488 // dup file descriptor, map once, use pmem
489 init(dup(fd), base, size, 0 , MEM_DEVICE);
490}
491#endif
492#endif // _ANDROID_
493/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700494 FUNCTION
495 omx_vdec::omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700496
Arun Menon906de572013-06-18 17:01:40 -0700497 DESCRIPTION
498 Constructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700499
Arun Menon906de572013-06-18 17:01:40 -0700500 PARAMETERS
501 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700502
Arun Menon906de572013-06-18 17:01:40 -0700503 RETURN VALUE
504 None.
505 ========================================================================== */
Deva Ramasubramanian5c241242013-02-19 17:25:30 -0800506omx_vdec::omx_vdec(): m_error_propogated(false),
Arun Menon906de572013-06-18 17:01:40 -0700507 m_state(OMX_StateInvalid),
508 m_app_data(NULL),
509 m_inp_mem_ptr(NULL),
510 m_out_mem_ptr(NULL),
Arun Menon906de572013-06-18 17:01:40 -0700511 input_flush_progress (false),
512 output_flush_progress (false),
513 input_use_buffer (false),
514 output_use_buffer (false),
515 ouput_egl_buffers(false),
516 m_use_output_pmem(OMX_FALSE),
517 m_out_mem_region_smi(OMX_FALSE),
518 m_out_pvt_entry_pmem(OMX_FALSE),
519 pending_input_buffers(0),
520 pending_output_buffers(0),
521 m_out_bm_count(0),
522 m_inp_bm_count(0),
523 m_inp_bPopulated(OMX_FALSE),
524 m_out_bPopulated(OMX_FALSE),
525 m_flags(0),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700526#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700527 m_heap_ptr(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700528#endif
Arun Menon906de572013-06-18 17:01:40 -0700529 m_inp_bEnabled(OMX_TRUE),
530 m_out_bEnabled(OMX_TRUE),
531 m_in_alloc_cnt(0),
532 m_platform_list(NULL),
533 m_platform_entry(NULL),
534 m_pmem_info(NULL),
535 arbitrary_bytes (true),
536 psource_frame (NULL),
537 pdest_frame (NULL),
538 m_inp_heap_ptr (NULL),
539 m_phdr_pmem_ptr(NULL),
540 m_heap_inp_bm_count (0),
541 codec_type_parse ((codec_type)0),
542 first_frame_meta (true),
543 frame_count (0),
544 nal_count (0),
545 nal_length(0),
546 look_ahead_nal (false),
547 first_frame(0),
548 first_buffer(NULL),
549 first_frame_size (0),
550 m_device_file_ptr(NULL),
551 m_vc1_profile((vc1_profile_type)0),
Arun Menon906de572013-06-18 17:01:40 -0700552 h264_last_au_ts(LLONG_MAX),
553 h264_last_au_flags(0),
Surajit Podderd2644d52013-08-28 17:59:06 +0530554 m_disp_hor_size(0),
555 m_disp_vert_size(0),
Arun Menon906de572013-06-18 17:01:40 -0700556 prev_ts(LLONG_MAX),
557 rst_prev_ts(true),
558 frm_int(0),
Arun Menon906de572013-06-18 17:01:40 -0700559 in_reconfig(false),
560 m_display_id(NULL),
561 h264_parser(NULL),
562 client_extradata(0),
563 m_reject_avc_1080p_mp (0),
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +0530564 m_other_extradata(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700565#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700566 m_enable_android_native_buffers(OMX_FALSE),
567 m_use_android_native_buffers(OMX_FALSE),
568 iDivXDrmDecrypt(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700569#endif
Arun Menon906de572013-06-18 17:01:40 -0700570 m_desc_buffer_ptr(NULL),
571 secure_mode(false),
Surajit Podderd2644d52013-08-28 17:59:06 +0530572 m_profile(0),
vivek mehtaa75c69f2014-01-10 21:50:37 -0800573 client_set_fps(false),
Deva Ramasubramanian286a3582014-08-25 18:09:38 -0700574 ignore_not_coded_vops(true),
vivek mehtaa75c69f2014-01-10 21:50:37 -0800575 m_last_rendered_TS(-1)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700576{
Arun Menon906de572013-06-18 17:01:40 -0700577 /* Assumption is that , to begin with , we have all the frames with decoder */
578 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700579 memset(&m_debug,0,sizeof(m_debug));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700580#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700581 char property_value[PROPERTY_VALUE_MAX] = {0};
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700582 property_get("vidc.debug.level", property_value, "0");
583 debug_level = atoi(property_value);
584 property_value[0] = '\0';
585
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700586 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
587
Arun Menon906de572013-06-18 17:01:40 -0700588 property_get("vidc.dec.debug.perf", property_value, "0");
589 perf_flag = atoi(property_value);
590 if (perf_flag) {
591 DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag);
592 dec_time.start();
593 proc_frms = latency = 0;
594 }
595 prev_n_filled_len = 0;
596 property_value[0] = '\0';
597 property_get("vidc.dec.debug.ts", property_value, "0");
598 m_debug_timestamp = atoi(property_value);
599 DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp);
600 if (m_debug_timestamp) {
601 time_stamp_dts.set_timestamp_reorder_mode(true);
602 time_stamp_dts.enable_debug_print(true);
603 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700604
Arun Menon906de572013-06-18 17:01:40 -0700605 property_value[0] = '\0';
606 property_get("vidc.dec.debug.concealedmb", property_value, "0");
607 m_debug_concealedmb = atoi(property_value);
608 DEBUG_PRINT_HIGH("vidc.dec.debug.concealedmb value is %d",m_debug_concealedmb);
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.profile.check", property_value, "0");
612 m_reject_avc_1080p_mp = atoi(property_value);
613 DEBUG_PRINT_HIGH("vidc.dec.profile.check value is %d",m_reject_avc_1080p_mp);
Rajeshwar Kurapatye0e7d0c2013-07-30 19:46:26 +0530614
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700615 property_value[0] = '\0';
616 property_get("vidc.dec.log.in", property_value, "0");
617 m_debug.in_buffer_log = atoi(property_value);
618
619 property_value[0] = '\0';
620 property_get("vidc.dec.log.out", property_value, "0");
621 m_debug.out_buffer_log = atoi(property_value);
622 sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC);
623
624 property_value[0] = '\0';
625 property_get("vidc.log.loc", property_value, "");
626 if (*property_value)
627 strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX);
vivek mehta79cff222014-01-22 12:17:07 -0800628
629 property_value[0] = '\0';
630 property_get("vidc.dec.120fps.enabled", property_value, "0");
631
632 //if this feature is not enabled then reset this value -ve
633 if(atoi(property_value)) {
634 DEBUG_PRINT_LOW("feature 120 FPS decode enabled");
635 m_last_rendered_TS = 0;
636 }
637
Shalaj Jain273b3e02012-06-22 19:08:03 -0700638#endif
Arun Menon906de572013-06-18 17:01:40 -0700639 memset(&m_cmp,0,sizeof(m_cmp));
640 memset(&m_cb,0,sizeof(m_cb));
641 memset (&drv_ctx,0,sizeof(drv_ctx));
642 memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE));
643 memset (m_hwdevice_name,0,sizeof(m_hwdevice_name));
644 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +0530645 memset(&m_custom_buffersize, 0, sizeof(m_custom_buffersize));
Arun Menon906de572013-06-18 17:01:40 -0700646 m_demux_entries = 0;
647 msg_thread_id = 0;
648 async_thread_id = 0;
649 msg_thread_created = false;
650 async_thread_created = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700651#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -0700652 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700653#endif
Arun Menon906de572013-06-18 17:01:40 -0700654 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Maheshwar Ajjad2df2182013-10-24 19:20:34 +0530655 memset(&m_frame_pack_arrangement, 0, sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
Arun Menon906de572013-06-18 17:01:40 -0700656 drv_ctx.timestamp_adjust = false;
657 drv_ctx.video_driver_fd = -1;
658 m_vendor_config.pData = NULL;
659 pthread_mutex_init(&m_lock, NULL);
660 pthread_mutex_init(&c_lock, NULL);
661 sem_init(&m_cmd_lock,0,0);
662 streaming[CAPTURE_PORT] =
663 streaming[OUTPUT_PORT] = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700664#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700665 char extradata_value[PROPERTY_VALUE_MAX] = {0};
666 property_get("vidc.dec.debug.extradata", extradata_value, "0");
667 m_debug_extradata = atoi(extradata_value);
668 DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700669#endif
Arun Menon906de572013-06-18 17:01:40 -0700670 m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB;
671 client_buffers.set_vdec_client(this);
Arun Menonbdb80b02013-08-12 17:45:54 -0700672 dynamic_buf_mode = false;
673 out_dynamic_list = NULL;
Praveen Chavane78460c2013-12-06 23:16:04 -0800674 is_down_scalar_enabled = false;
Praveen Chavancf924182013-12-06 23:16:23 -0800675 m_smoothstreaming_mode = false;
676 m_smoothstreaming_width = 0;
677 m_smoothstreaming_height = 0;
Deepak Vermaa2efdb12013-12-26 12:30:05 +0530678 is_q6_platform = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700679}
680
Vinay Kalia85793762012-06-14 19:12:34 -0700681static const int event_type[] = {
Arun Menon906de572013-06-18 17:01:40 -0700682 V4L2_EVENT_MSM_VIDC_FLUSH_DONE,
683 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT,
684 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT,
Arun Menonbdb80b02013-08-12 17:45:54 -0700685 V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE,
686 V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER,
Arun Menon906de572013-06-18 17:01:40 -0700687 V4L2_EVENT_MSM_VIDC_CLOSE_DONE,
Jia Meng1e236c82014-04-03 10:54:39 +0800688 V4L2_EVENT_MSM_VIDC_SYS_ERROR,
689 V4L2_EVENT_MSM_VIDC_HW_OVERLOAD
Vinay Kalia85793762012-06-14 19:12:34 -0700690};
691
692static OMX_ERRORTYPE subscribe_to_events(int fd)
693{
Arun Menon906de572013-06-18 17:01:40 -0700694 OMX_ERRORTYPE eRet = OMX_ErrorNone;
695 struct v4l2_event_subscription sub;
696 int array_sz = sizeof(event_type)/sizeof(int);
697 int i,rc;
698 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700699 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700700 return OMX_ErrorBadParameter;
701 }
Vinay Kalia85793762012-06-14 19:12:34 -0700702
Arun Menon906de572013-06-18 17:01:40 -0700703 for (i = 0; i < array_sz; ++i) {
704 memset(&sub, 0, sizeof(sub));
705 sub.type = event_type[i];
706 rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
707 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700708 DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700709 break;
710 }
711 }
712 if (i < array_sz) {
713 for (--i; i >=0 ; i--) {
714 memset(&sub, 0, sizeof(sub));
715 sub.type = event_type[i];
716 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
717 if (rc)
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700718 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700719 }
720 eRet = OMX_ErrorNotImplemented;
721 }
722 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700723}
724
725
726static OMX_ERRORTYPE unsubscribe_to_events(int fd)
727{
Arun Menon906de572013-06-18 17:01:40 -0700728 OMX_ERRORTYPE eRet = OMX_ErrorNone;
729 struct v4l2_event_subscription sub;
730 int array_sz = sizeof(event_type)/sizeof(int);
731 int i,rc;
732 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700733 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700734 return OMX_ErrorBadParameter;
735 }
Vinay Kalia85793762012-06-14 19:12:34 -0700736
Arun Menon906de572013-06-18 17:01:40 -0700737 for (i = 0; i < array_sz; ++i) {
738 memset(&sub, 0, sizeof(sub));
739 sub.type = event_type[i];
740 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
741 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700742 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700743 break;
744 }
745 }
746 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700747}
Shalaj Jain273b3e02012-06-22 19:08:03 -0700748
749/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700750 FUNCTION
751 omx_vdec::~omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700752
Arun Menon906de572013-06-18 17:01:40 -0700753 DESCRIPTION
754 Destructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700755
Arun Menon906de572013-06-18 17:01:40 -0700756 PARAMETERS
757 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700758
Arun Menon906de572013-06-18 17:01:40 -0700759 RETURN VALUE
760 None.
761 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700762omx_vdec::~omx_vdec()
763{
Arun Menon906de572013-06-18 17:01:40 -0700764 m_pmem_info = NULL;
765 struct v4l2_decoder_cmd dec;
766 DEBUG_PRINT_HIGH("In OMX vdec Destructor");
767 if (m_pipe_in) close(m_pipe_in);
768 if (m_pipe_out) close(m_pipe_out);
769 m_pipe_in = -1;
770 m_pipe_out = -1;
771 DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit");
772 if (msg_thread_created)
773 pthread_join(msg_thread_id,NULL);
774 DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit");
775 dec.cmd = V4L2_DEC_CMD_STOP;
776 if (drv_ctx.video_driver_fd >=0 ) {
777 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700778 DEBUG_PRINT_ERROR("STOP Command failed");
Arun Menon906de572013-06-18 17:01:40 -0700779 }
780 if (async_thread_created)
781 pthread_join(async_thread_id,NULL);
782 unsubscribe_to_events(drv_ctx.video_driver_fd);
783 close(drv_ctx.video_driver_fd);
784 pthread_mutex_destroy(&m_lock);
785 pthread_mutex_destroy(&c_lock);
786 sem_destroy(&m_cmd_lock);
787 if (perf_flag) {
788 DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME");
789 dec_time.end();
790 }
791 DEBUG_PRINT_HIGH("Exit OMX vdec Destructor");
Shalaj Jain273b3e02012-06-22 19:08:03 -0700792}
793
Arun Menon906de572013-06-18 17:01:40 -0700794int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type)
795{
796 struct v4l2_requestbuffers bufreq;
797 int rc = 0;
798 if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
799 bufreq.memory = V4L2_MEMORY_USERPTR;
800 bufreq.count = 0;
801 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
802 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Surajit Podder12aefac2013-08-06 18:43:32 +0530803 } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) {
804 bufreq.memory = V4L2_MEMORY_USERPTR;
805 bufreq.count = 0;
806 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
807 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Arun Menon906de572013-06-18 17:01:40 -0700808 }
809 return rc;
Vinay Kaliafeef7032012-09-25 19:23:33 -0700810}
811
Shalaj Jain273b3e02012-06-22 19:08:03 -0700812/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700813 FUNCTION
814 omx_vdec::OMXCntrlProcessMsgCb
Shalaj Jain273b3e02012-06-22 19:08:03 -0700815
Arun Menon906de572013-06-18 17:01:40 -0700816 DESCRIPTION
817 IL Client callbacks are generated through this routine. The decoder
818 provides the thread context for this routine.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700819
Arun Menon906de572013-06-18 17:01:40 -0700820 PARAMETERS
821 ctxt -- Context information related to the self.
822 id -- Event identifier. This could be any of the following:
823 1. Command completion event
824 2. Buffer done callback event
825 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -0700826
Arun Menon906de572013-06-18 17:01:40 -0700827 RETURN VALUE
828 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700829
Arun Menon906de572013-06-18 17:01:40 -0700830 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700831void omx_vdec::process_event_cb(void *ctxt, unsigned char id)
832{
Arun Menon906de572013-06-18 17:01:40 -0700833 signed p1; // Parameter - 1
834 signed p2; // Parameter - 2
835 unsigned ident;
836 unsigned qsize=0; // qsize
837 omx_vdec *pThis = (omx_vdec *) ctxt;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700838
Arun Menon906de572013-06-18 17:01:40 -0700839 if (!pThis) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700840 DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out",
Arun Menon906de572013-06-18 17:01:40 -0700841 __func__);
842 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700843 }
844
Arun Menon906de572013-06-18 17:01:40 -0700845 // Protect the shared queue data structure
846 do {
847 /*Read the message id's from the queue*/
848 pthread_mutex_lock(&pThis->m_lock);
849 qsize = pThis->m_cmd_q.m_size;
850 if (qsize) {
851 pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700852 }
Arun Menon906de572013-06-18 17:01:40 -0700853
854 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
855 qsize = pThis->m_ftb_q.m_size;
856 if (qsize) {
857 pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
858 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700859 }
Arun Menon906de572013-06-18 17:01:40 -0700860
861 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
862 qsize = pThis->m_etb_q.m_size;
863 if (qsize) {
864 pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
865 }
866 }
867 pthread_mutex_unlock(&pThis->m_lock);
868
869 /*process message if we have one*/
870 if (qsize > 0) {
871 id = ident;
872 switch (id) {
873 case OMX_COMPONENT_GENERATE_EVENT:
874 if (pThis->m_cb.EventHandler) {
875 switch (p1) {
876 case OMX_CommandStateSet:
877 pThis->m_state = (OMX_STATETYPE) p2;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700878 DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d",
Arun Menon906de572013-06-18 17:01:40 -0700879 pThis->m_state);
880 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
881 OMX_EventCmdComplete, p1, p2, NULL);
882 break;
883
884 case OMX_EventError:
885 if (p2 == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700886 DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid");
Arun Menon906de572013-06-18 17:01:40 -0700887 pThis->m_state = (OMX_STATETYPE) p2;
888 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
889 OMX_EventError, OMX_ErrorInvalidState, p2, NULL);
890 } else if (p2 == OMX_ErrorHardware) {
891 pThis->omx_report_error();
892 } else {
893 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
894 OMX_EventError, p2, (OMX_U32)NULL, NULL );
895 }
896 break;
897
898 case OMX_CommandPortDisable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700899 DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700900 if (BITMASK_PRESENT(&pThis->m_flags,
901 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
902 BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
903 break;
904 }
905 if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) {
906 OMX_ERRORTYPE eRet = OMX_ErrorNone;
907 pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
908 if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700909 DEBUG_PRINT_HIGH("Failed to release output buffers");
Arun Menon906de572013-06-18 17:01:40 -0700910 OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf);
911 pThis->in_reconfig = false;
912 if (eRet != OMX_ErrorNone) {
913 DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet);
914 pThis->omx_report_error();
915 break;
916 }
917 }
918 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
919 OMX_EventCmdComplete, p1, p2, NULL );
920 break;
921 case OMX_CommandPortEnable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700922 DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700923 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\
924 OMX_EventCmdComplete, p1, p2, NULL );
925 break;
926
927 default:
928 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
929 OMX_EventCmdComplete, p1, p2, NULL );
930 break;
931
932 }
933 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700934 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
Arun Menon906de572013-06-18 17:01:40 -0700935 }
936 break;
937 case OMX_COMPONENT_GENERATE_ETB_ARBITRARY:
938 if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\
939 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700940 DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure");
Arun Menon906de572013-06-18 17:01:40 -0700941 pThis->omx_report_error ();
942 }
943 break;
Jia Meng1e236c82014-04-03 10:54:39 +0800944 case OMX_COMPONENT_GENERATE_ETB: {
945 OMX_ERRORTYPE iret;
946 iret = pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1, (OMX_BUFFERHEADERTYPE *)p2);
947 if (iret == OMX_ErrorInsufficientResources) {
948 DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure due to HW overload");
949 pThis->omx_report_hw_overload ();
950 } else if (iret != OMX_ErrorNone) {
951 DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure");
952 pThis->omx_report_error ();
953 }
Arun Menon906de572013-06-18 17:01:40 -0700954 }
955 break;
956
957 case OMX_COMPONENT_GENERATE_FTB:
958 if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\
959 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700960 DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure");
Arun Menon906de572013-06-18 17:01:40 -0700961 pThis->omx_report_error ();
962 }
963 break;
964
965 case OMX_COMPONENT_GENERATE_COMMAND:
966 pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\
967 (OMX_U32)p2,(OMX_PTR)NULL);
968 break;
969
970 case OMX_COMPONENT_GENERATE_EBD:
971
972 if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700973 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure");
Arun Menon906de572013-06-18 17:01:40 -0700974 pThis->omx_report_error ();
975 } else {
976 if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) {
Arun Menon906de572013-06-18 17:01:40 -0700977 pThis->time_stamp_dts.remove_time_stamp(
978 ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp,
979 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
980 ?true:false);
Arun Menon906de572013-06-18 17:01:40 -0700981 }
Deva Ramasubramanian02b0d882014-04-03 14:58:50 -0700982
Arun Menon906de572013-06-18 17:01:40 -0700983 if ( pThis->empty_buffer_done(&pThis->m_cmp,
984 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700985 DEBUG_PRINT_ERROR("empty_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -0700986 pThis->omx_report_error ();
987 }
Arun Menon906de572013-06-18 17:01:40 -0700988 }
989 break;
990 case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: {
991 int64_t *timestamp = (int64_t *)p1;
992 if (p1) {
993 pThis->time_stamp_dts.remove_time_stamp(*timestamp,
994 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
995 ?true:false);
996 free(timestamp);
997 }
998 }
999 break;
1000 case OMX_COMPONENT_GENERATE_FBD:
1001 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001002 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure");
Arun Menon906de572013-06-18 17:01:40 -07001003 pThis->omx_report_error ();
1004 } else if ( pThis->fill_buffer_done(&pThis->m_cmp,
1005 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001006 DEBUG_PRINT_ERROR("fill_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -07001007 pThis->omx_report_error ();
1008 }
1009 break;
1010
1011 case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001012 DEBUG_PRINT_HIGH("Driver flush i/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -07001013 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001014 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -07001015 } else {
1016 pThis->execute_input_flush();
1017 if (pThis->m_cb.EventHandler) {
1018 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001019 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure");
Arun Menon906de572013-06-18 17:01:40 -07001020 pThis->omx_report_error ();
1021 } else {
1022 /*Check if we need generate event for Flush done*/
1023 if (BITMASK_PRESENT(&pThis->m_flags,
1024 OMX_COMPONENT_INPUT_FLUSH_PENDING)) {
1025 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001026 DEBUG_PRINT_LOW("Input Flush completed - Notify Client");
Arun Menon906de572013-06-18 17:01:40 -07001027 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1028 OMX_EventCmdComplete,OMX_CommandFlush,
1029 OMX_CORE_INPUT_PORT_INDEX,NULL );
1030 }
1031 if (BITMASK_PRESENT(&pThis->m_flags,
1032 OMX_COMPONENT_IDLE_PENDING)) {
1033 if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001034 DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port");
Arun Menon906de572013-06-18 17:01:40 -07001035 pThis->omx_report_error ();
1036 } else {
1037 pThis->streaming[OUTPUT_PORT] = false;
1038 }
1039 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001040 DEBUG_PRINT_LOW("Input flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001041 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1042 OMX_COMPONENT_GENERATE_STOP_DONE);
1043 }
1044 }
1045 }
1046 } else {
1047 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1048 }
1049 }
1050 break;
1051
1052 case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001053 DEBUG_PRINT_HIGH("Driver flush o/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -07001054 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001055 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -07001056 } else {
1057 pThis->execute_output_flush();
1058 if (pThis->m_cb.EventHandler) {
1059 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001060 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed");
Arun Menon906de572013-06-18 17:01:40 -07001061 pThis->omx_report_error ();
1062 } else {
1063 /*Check if we need generate event for Flush done*/
1064 if (BITMASK_PRESENT(&pThis->m_flags,
1065 OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001066 DEBUG_PRINT_LOW("Notify Output Flush done");
Arun Menon906de572013-06-18 17:01:40 -07001067 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
1068 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1069 OMX_EventCmdComplete,OMX_CommandFlush,
1070 OMX_CORE_OUTPUT_PORT_INDEX,NULL );
1071 }
1072 if (BITMASK_PRESENT(&pThis->m_flags,
1073 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001074 DEBUG_PRINT_LOW("Internal flush complete");
Arun Menon906de572013-06-18 17:01:40 -07001075 BITMASK_CLEAR (&pThis->m_flags,
1076 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
1077 if (BITMASK_PRESENT(&pThis->m_flags,
1078 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) {
1079 pThis->post_event(OMX_CommandPortDisable,
1080 OMX_CORE_OUTPUT_PORT_INDEX,
1081 OMX_COMPONENT_GENERATE_EVENT);
1082 BITMASK_CLEAR (&pThis->m_flags,
1083 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
Praneeth Paladugub52072a2013-08-23 13:54:43 -07001084 BITMASK_CLEAR (&pThis->m_flags,
1085 OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
Arun Menon906de572013-06-18 17:01:40 -07001086
1087 }
1088 }
1089
1090 if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) {
1091 if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001092 DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port");
Arun Menon906de572013-06-18 17:01:40 -07001093 pThis->omx_report_error ();
1094 break;
1095 }
1096 pThis->streaming[CAPTURE_PORT] = false;
1097 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001098 DEBUG_PRINT_LOW("Output flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001099 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1100 OMX_COMPONENT_GENERATE_STOP_DONE);
1101 }
1102 }
1103 }
1104 } else {
1105 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1106 }
1107 }
1108 break;
1109
1110 case OMX_COMPONENT_GENERATE_START_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001111 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001112
1113 if (pThis->m_cb.EventHandler) {
1114 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001115 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure");
Arun Menon906de572013-06-18 17:01:40 -07001116 pThis->omx_report_error ();
1117 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001118 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001119 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001120 DEBUG_PRINT_LOW("Move to executing");
Arun Menon906de572013-06-18 17:01:40 -07001121 // Send the callback now
1122 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1123 pThis->m_state = OMX_StateExecuting;
1124 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1125 OMX_EventCmdComplete,OMX_CommandStateSet,
1126 OMX_StateExecuting, NULL);
1127 } else if (BITMASK_PRESENT(&pThis->m_flags,
1128 OMX_COMPONENT_PAUSE_PENDING)) {
1129 if (/*ioctl (pThis->drv_ctx.video_driver_fd,
1130 VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001131 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed");
Arun Menon906de572013-06-18 17:01:40 -07001132 pThis->omx_report_error ();
1133 }
1134 }
1135 }
1136 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001137 DEBUG_PRINT_LOW("Event Handler callback is NULL");
Arun Menon906de572013-06-18 17:01:40 -07001138 }
1139 break;
1140
1141 case OMX_COMPONENT_GENERATE_PAUSE_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001142 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001143 if (pThis->m_cb.EventHandler) {
1144 if (p2 != VDEC_S_SUCCESS) {
1145 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed");
1146 pThis->omx_report_error ();
1147 } else {
1148 pThis->complete_pending_buffer_done_cbs();
1149 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001150 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity");
Arun Menon906de572013-06-18 17:01:40 -07001151 //Send the callback now
1152 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING);
1153 pThis->m_state = OMX_StatePause;
1154 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1155 OMX_EventCmdComplete,OMX_CommandStateSet,
1156 OMX_StatePause, NULL);
1157 }
1158 }
1159 } else {
1160 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1161 }
1162
1163 break;
1164
1165 case OMX_COMPONENT_GENERATE_RESUME_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001166 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001167 if (pThis->m_cb.EventHandler) {
1168 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001169 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed");
Arun Menon906de572013-06-18 17:01:40 -07001170 pThis->omx_report_error ();
1171 } else {
1172 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001173 DEBUG_PRINT_LOW("Moving the decoder to execute state");
Arun Menon906de572013-06-18 17:01:40 -07001174 // Send the callback now
1175 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1176 pThis->m_state = OMX_StateExecuting;
1177 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1178 OMX_EventCmdComplete,OMX_CommandStateSet,
1179 OMX_StateExecuting,NULL);
1180 }
1181 }
1182 } else {
1183 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1184 }
1185
1186 break;
1187
1188 case OMX_COMPONENT_GENERATE_STOP_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001189 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001190 if (pThis->m_cb.EventHandler) {
1191 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001192 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed");
Arun Menon906de572013-06-18 17:01:40 -07001193 pThis->omx_report_error ();
1194 } else {
1195 pThis->complete_pending_buffer_done_cbs();
1196 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001197 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001198 // Send the callback now
1199 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING);
1200 pThis->m_state = OMX_StateIdle;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001201 DEBUG_PRINT_LOW("Move to Idle State");
Arun Menon906de572013-06-18 17:01:40 -07001202 pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data,
1203 OMX_EventCmdComplete,OMX_CommandStateSet,
1204 OMX_StateIdle,NULL);
1205 }
1206 }
1207 } else {
1208 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1209 }
1210
1211 break;
1212
1213 case OMX_COMPONENT_GENERATE_PORT_RECONFIG:
Arun Menon906de572013-06-18 17:01:40 -07001214 if (p2 == OMX_IndexParamPortDefinition) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301215 DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexParamPortDefinition");
Arun Menon906de572013-06-18 17:01:40 -07001216 pThis->in_reconfig = true;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301217
1218 } else if (p2 == OMX_IndexConfigCommonOutputCrop) {
1219 DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexConfigCommonOutputCrop");
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301220
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301221 /* Check if resolution is changed in smooth streaming mode */
1222 if (pThis->m_smoothstreaming_mode &&
1223 (pThis->framesize.nWidth !=
1224 pThis->drv_ctx.video_resolution.frame_width) ||
1225 (pThis->framesize.nHeight !=
1226 pThis->drv_ctx.video_resolution.frame_height)) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301227
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301228 DEBUG_PRINT_HIGH("Resolution changed from: wxh = %dx%d to: wxh = %dx%d",
1229 pThis->framesize.nWidth,
1230 pThis->framesize.nHeight,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301231 pThis->drv_ctx.video_resolution.frame_width,
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301232 pThis->drv_ctx.video_resolution.frame_height);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301233
1234 /* Update new resolution */
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301235 pThis->framesize.nWidth =
1236 pThis->drv_ctx.video_resolution.frame_width;
1237 pThis->framesize.nHeight =
1238 pThis->drv_ctx.video_resolution.frame_height;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301239
1240 /* Update C2D with new resolution */
1241 if (!pThis->client_buffers.update_buffer_req()) {
1242 DEBUG_PRINT_ERROR("Setting C2D buffer requirements failed");
1243 }
1244 }
1245
1246 /* Update new crop information */
1247 pThis->rectangle.nLeft = pThis->drv_ctx.frame_size.left;
1248 pThis->rectangle.nTop = pThis->drv_ctx.frame_size.top;
1249 pThis->rectangle.nWidth = pThis->drv_ctx.frame_size.right;
1250 pThis->rectangle.nHeight = pThis->drv_ctx.frame_size.bottom;
1251
1252 /* Validate the new crop information */
1253 if (pThis->rectangle.nLeft + pThis->rectangle.nWidth >
1254 pThis->drv_ctx.video_resolution.frame_width) {
1255
1256 DEBUG_PRINT_HIGH("Crop L[%u] + R[%u] > W[%u]",
1257 pThis->rectangle.nLeft, pThis->rectangle.nWidth,
1258 pThis->drv_ctx.video_resolution.frame_width);
1259 pThis->rectangle.nLeft = 0;
1260
1261 if (pThis->rectangle.nWidth >
1262 pThis->drv_ctx.video_resolution.frame_width) {
1263
1264 DEBUG_PRINT_HIGH("Crop R[%u] > W[%u]",
1265 pThis->rectangle.nWidth,
1266 pThis->drv_ctx.video_resolution.frame_width);
1267 pThis->rectangle.nWidth =
1268 pThis->drv_ctx.video_resolution.frame_width;
1269 }
1270 }
1271 if (pThis->rectangle.nTop + pThis->rectangle.nHeight >
1272 pThis->drv_ctx.video_resolution.frame_height) {
1273
1274 DEBUG_PRINT_HIGH("Crop T[%u] + B[%u] > H[%u]",
1275 pThis->rectangle.nTop, pThis->rectangle.nHeight,
1276 pThis->drv_ctx.video_resolution.frame_height);
1277 pThis->rectangle.nTop = 0;
1278
1279 if (pThis->rectangle.nHeight >
1280 pThis->drv_ctx.video_resolution.frame_height) {
1281
1282 DEBUG_PRINT_HIGH("Crop B[%u] > H[%u]",
1283 pThis->rectangle.nHeight,
1284 pThis->drv_ctx.video_resolution.frame_height);
1285 pThis->rectangle.nHeight =
1286 pThis->drv_ctx.video_resolution.frame_height;
1287 }
1288 }
1289 DEBUG_PRINT_HIGH("Updated Crop Info: L: %u, T: %u, R: %u, B: %u",
1290 pThis->rectangle.nLeft, pThis->rectangle.nTop,
1291 pThis->rectangle.nWidth, pThis->rectangle.nHeight);
1292 } else {
1293 DEBUG_PRINT_ERROR("Rxd Invalid PORT_RECONFIG event (%lu)", p2);
1294 break;
Arun Menon906de572013-06-18 17:01:40 -07001295 }
1296 if (pThis->m_cb.EventHandler) {
1297 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1298 OMX_EventPortSettingsChanged, p1, p2, NULL );
1299 } else {
1300 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1301 }
Arun Menon906de572013-06-18 17:01:40 -07001302 break;
1303
1304 case OMX_COMPONENT_GENERATE_EOS_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001305 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001306 if (pThis->m_cb.EventHandler) {
1307 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag,
1308 OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL );
1309 } else {
1310 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1311 }
1312 pThis->prev_ts = LLONG_MAX;
1313 pThis->rst_prev_ts = true;
1314 break;
1315
1316 case OMX_COMPONENT_GENERATE_HARDWARE_ERROR:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001317 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR");
Arun Menon906de572013-06-18 17:01:40 -07001318 pThis->omx_report_error ();
1319 break;
1320
1321 case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001322 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING");
Arun Menon906de572013-06-18 17:01:40 -07001323 pThis->omx_report_unsupported_setting();
1324 break;
1325
Deepak Verma24720fb2014-01-29 16:57:40 +05301326 case OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD:
1327 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD");
1328 pThis->omx_report_hw_overload();
1329 break;
1330
Arun Menon906de572013-06-18 17:01:40 -07001331 default:
1332 break;
1333 }
1334 }
1335 pthread_mutex_lock(&pThis->m_lock);
1336 qsize = pThis->m_cmd_q.m_size;
1337 if (pThis->m_state != OMX_StatePause)
1338 qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size);
1339 pthread_mutex_unlock(&pThis->m_lock);
1340 } while (qsize>0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001341
1342}
1343
Vinay Kaliab9e98102013-04-02 19:31:43 -07001344int omx_vdec::update_resolution(int width, int height, int stride, int scan_lines)
Vinay Kalia592e4b42012-12-19 15:55:47 -08001345{
Arun Menon906de572013-06-18 17:01:40 -07001346 int format_changed = 0;
Surajit Podderd2644d52013-08-28 17:59:06 +05301347 if ((height != (int)drv_ctx.video_resolution.frame_height) ||
1348 (width != (int)drv_ctx.video_resolution.frame_width)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001349 DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)",
Arun Menon906de572013-06-18 17:01:40 -07001350 width, drv_ctx.video_resolution.frame_width,
1351 height,drv_ctx.video_resolution.frame_height);
1352 format_changed = 1;
1353 }
Vinay Kalia592e4b42012-12-19 15:55:47 -08001354 drv_ctx.video_resolution.frame_height = height;
1355 drv_ctx.video_resolution.frame_width = width;
Vinay Kalia21649b32013-03-18 17:28:07 -07001356 drv_ctx.video_resolution.scan_lines = scan_lines;
1357 drv_ctx.video_resolution.stride = stride;
Pushkaraj Patil41588352014-02-25 20:51:34 +05301358 if(!is_down_scalar_enabled) {
1359 rectangle.nLeft = 0;
1360 rectangle.nTop = 0;
1361 rectangle.nWidth = drv_ctx.video_resolution.frame_width;
1362 rectangle.nHeight = drv_ctx.video_resolution.frame_height;
1363 }
Arun Menon906de572013-06-18 17:01:40 -07001364 return format_changed;
Vinay Kalia592e4b42012-12-19 15:55:47 -08001365}
1366
Arun Menon6836ba02013-02-19 20:37:40 -08001367OMX_ERRORTYPE omx_vdec::is_video_session_supported()
1368{
Arun Menon906de572013-06-18 17:01:40 -07001369 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",
1370 OMX_MAX_STRINGNAME_SIZE) &&
1371 (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) {
1372 m_decoder_capability.max_width = 1280;
1373 m_decoder_capability.max_height = 720;
1374 DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP");
1375 }
Arun Menon888aa852013-05-30 11:24:42 -07001376
Arun Menon906de572013-06-18 17:01:40 -07001377 if ((drv_ctx.video_resolution.frame_width *
1378 drv_ctx.video_resolution.frame_height >
1379 m_decoder_capability.max_width *
1380 m_decoder_capability.max_height) ||
1381 (drv_ctx.video_resolution.frame_width*
1382 drv_ctx.video_resolution.frame_height <
1383 m_decoder_capability.min_width *
1384 m_decoder_capability.min_height)) {
1385 DEBUG_PRINT_ERROR(
1386 "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)",
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 m_decoder_capability.max_width,
1392 m_decoder_capability.max_height);
1393 return OMX_ErrorUnsupportedSetting;
1394 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001395 DEBUG_PRINT_HIGH("video session supported");
Arun Menon906de572013-06-18 17:01:40 -07001396 return OMX_ErrorNone;
Arun Menon6836ba02013-02-19 20:37:40 -08001397}
1398
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001399int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len)
1400{
1401 if (m_debug.in_buffer_log && !m_debug.infile) {
1402 if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) {
1403 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v",
1404 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1405 }
1406 else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) {
1407 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); }
1408 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) {
1409 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263",
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.avc", OMX_MAX_STRINGNAME_SIZE)) {
1413 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264",
1414 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1415 }
1416 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) {
1417 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1418 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1419 }
1420 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) {
1421 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1422 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1423 }
1424 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1425 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf",
1426 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1427 }
1428 m_debug.infile = fopen (m_debug.infile_name, "ab");
1429 if (!m_debug.infile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001430 DEBUG_PRINT_HIGH("Failed to open input file: %s for logging", m_debug.infile_name);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001431 m_debug.infile_name[0] = '\0';
1432 return -1;
1433 }
1434 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1435 struct ivf_file_header {
1436 OMX_U8 signature[4]; //='DKIF';
1437 OMX_U8 version ; //= 0;
1438 OMX_U8 headersize ; //= 32;
1439 OMX_U32 FourCC;
1440 OMX_U8 width;
1441 OMX_U8 height;
1442 OMX_U32 rate;
1443 OMX_U32 scale;
1444 OMX_U32 length;
1445 OMX_U8 unused[4];
1446 } file_header;
1447
1448 memset((void *)&file_header,0,sizeof(file_header));
1449 file_header.signature[0] = 'D';
1450 file_header.signature[1] = 'K';
1451 file_header.signature[2] = 'I';
1452 file_header.signature[3] = 'F';
1453 file_header.version = 0;
1454 file_header.headersize = 32;
1455 file_header.FourCC = 0x30385056;
1456 fwrite((const char *)&file_header,
1457 sizeof(file_header),1,m_debug.infile);
1458 }
1459 }
1460 if (m_debug.infile && buffer_addr && buffer_len) {
1461 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1462 struct vp8_ivf_frame_header {
1463 OMX_U32 framesize;
1464 OMX_U32 timestamp_lo;
1465 OMX_U32 timestamp_hi;
1466 } vp8_frame_header;
1467 vp8_frame_header.framesize = buffer_len;
1468 /* Currently FW doesn't use timestamp values */
1469 vp8_frame_header.timestamp_lo = 0;
1470 vp8_frame_header.timestamp_hi = 0;
1471 fwrite((const char *)&vp8_frame_header,
1472 sizeof(vp8_frame_header),1,m_debug.infile);
1473 }
1474 fwrite(buffer_addr, buffer_len, 1, m_debug.infile);
1475 }
1476 return 0;
1477}
1478
1479int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) {
1480 if (m_debug.out_buffer_log && !m_debug.outfile) {
1481 sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv",
1482 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1483 m_debug.outfile = fopen (m_debug.outfile_name, "ab");
1484 if (!m_debug.outfile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001485 DEBUG_PRINT_HIGH("Failed to open output file: %s for logging", m_debug.log_loc);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001486 m_debug.outfile_name[0] = '\0';
1487 return -1;
1488 }
1489 }
1490 if (m_debug.outfile && buffer && buffer->nFilledLen) {
1491 int buf_index = buffer - m_out_mem_ptr;
1492 int stride = drv_ctx.video_resolution.stride;
1493 int scanlines = drv_ctx.video_resolution.scan_lines;
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301494 if (m_smoothstreaming_mode) {
1495 stride = drv_ctx.video_resolution.frame_width;
1496 scanlines = drv_ctx.video_resolution.frame_height;
1497 stride = (stride + DEFAULT_WIDTH_ALIGNMENT - 1) & (~(DEFAULT_WIDTH_ALIGNMENT - 1));
1498 scanlines = (scanlines + DEFAULT_HEIGHT_ALIGNMENT - 1) & (~(DEFAULT_HEIGHT_ALIGNMENT - 1));
1499 }
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001500 char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr;
1501 unsigned i;
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301502 DEBUG_PRINT_HIGH("Logging width/height(%u/%u) stride/scanlines(%u/%u)",
1503 drv_ctx.video_resolution.frame_width,
1504 drv_ctx.video_resolution.frame_height, stride, scanlines);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001505 int bytes_written = 0;
1506 for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) {
1507 bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1508 temp += stride;
1509 }
1510 temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines;
1511 int stride_c = stride;
1512 for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) {
1513 bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1514 temp += stride_c;
1515 }
1516 }
1517 return 0;
1518}
1519
Shalaj Jain273b3e02012-06-22 19:08:03 -07001520/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001521 FUNCTION
1522 omx_vdec::ComponentInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07001523
Arun Menon906de572013-06-18 17:01:40 -07001524 DESCRIPTION
1525 Initialize the component.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001526
Arun Menon906de572013-06-18 17:01:40 -07001527 PARAMETERS
1528 ctxt -- Context information related to the self.
1529 id -- Event identifier. This could be any of the following:
1530 1. Command completion event
1531 2. Buffer done callback event
1532 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -07001533
Arun Menon906de572013-06-18 17:01:40 -07001534 RETURN VALUE
1535 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001536
Arun Menon906de572013-06-18 17:01:40 -07001537 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001538OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role)
1539{
1540
Arun Menon906de572013-06-18 17:01:40 -07001541 OMX_ERRORTYPE eRet = OMX_ErrorNone;
1542 struct v4l2_fmtdesc fdesc;
1543 struct v4l2_format fmt;
1544 struct v4l2_requestbuffers bufreq;
1545 struct v4l2_control control;
1546 struct v4l2_frmsizeenum frmsize;
1547 unsigned int alignment = 0,buffer_size = 0;
1548 int fds[2];
1549 int r,ret=0;
1550 bool codec_ambiguous = false;
1551 OMX_STRING device_name = (OMX_STRING)"/dev/video/venus_dec";
Jia Meng3a3c6492013-12-19 17:16:52 +08001552 char property_value[PROPERTY_VALUE_MAX] = {0};
Sachin Shahc82a18f2013-03-29 14:45:38 -07001553
1554#ifdef _ANDROID_
Praveen Chavane9e56202013-09-19 03:48:16 -07001555 char platform_name[PROPERTY_VALUE_MAX];
Arun Menon906de572013-06-18 17:01:40 -07001556 property_get("ro.board.platform", platform_name, "0");
1557 if (!strncmp(platform_name, "msm8610", 7)) {
1558 device_name = (OMX_STRING)"/dev/video/q6_dec";
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301559 is_q6_platform = true;
1560 maxSmoothStreamingWidth = 1280;
1561 maxSmoothStreamingHeight = 720;
Arun Menon906de572013-06-18 17:01:40 -07001562 }
Sachin Shahc82a18f2013-03-29 14:45:38 -07001563#endif
1564
Arun Menon906de572013-06-18 17:01:40 -07001565 if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) {
1566 struct v4l2_control control;
1567 secure_mode = true;
1568 arbitrary_bytes = false;
1569 role = (OMX_STRING)"OMX.qcom.video.decoder.avc";
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05301570 } else if (!strncmp(role, "OMX.qcom.video.decoder.mpeg2.secure",
1571 OMX_MAX_STRINGNAME_SIZE)){
1572 secure_mode = true;
1573 arbitrary_bytes = false;
1574 role = (OMX_STRING)"OMX.qcom.video.decoder.mpeg2";
Arun Menon906de572013-06-18 17:01:40 -07001575 }
Vinay Kalia53fa6832012-10-11 17:55:30 -07001576
Arun Menon906de572013-06-18 17:01:40 -07001577 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001578
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001579 DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open returned fd %d",
Jayasena Sangaraboinac453bd82013-08-01 14:02:52 -07001580 drv_ctx.video_driver_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001581
Arun Menon906de572013-06-18 17:01:40 -07001582 if (drv_ctx.video_driver_fd == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001583 DEBUG_PRINT_ERROR("omx_vdec_msm8974 :: Got fd as 0 for msm_vidc_dec, Opening again");
Arun Menon906de572013-06-18 17:01:40 -07001584 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
1585 close(0);
1586 }
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::Comp Init Returning failure, errno %d", errno);
Arun Menon906de572013-06-18 17:01:40 -07001590 return OMX_ErrorInsufficientResources;
1591 }
1592 drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS;
1593 drv_ctx.frame_rate.fps_denominator = 1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001594
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001595 ret = subscribe_to_events(drv_ctx.video_driver_fd);
Vinay Kalia184cd0f2013-04-29 18:26:42 -07001596 if (!ret) {
Arun Menon906de572013-06-18 17:01:40 -07001597 async_thread_created = true;
1598 ret = pthread_create(&async_thread_id,0,async_message_thread,this);
1599 }
1600 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001601 DEBUG_PRINT_ERROR("Failed to create async_message_thread");
Arun Menon906de572013-06-18 17:01:40 -07001602 async_thread_created = false;
1603 return OMX_ErrorInsufficientResources;
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001604 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001605
Shalaj Jain273b3e02012-06-22 19:08:03 -07001606#ifdef OUTPUT_EXTRADATA_LOG
Deva Ramasubramanianee6f1f42014-01-31 12:49:18 -08001607 outputExtradataFile = fopen (output_extradata_filename, "ab");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001608#endif
1609
Arun Menon906de572013-06-18 17:01:40 -07001610 // Copy the role information which provides the decoder kind
1611 strlcpy(drv_ctx.kind,role,128);
Vinay Kalia53fa6832012-10-11 17:55:30 -07001612
Arun Menon906de572013-06-18 17:01:40 -07001613 if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\
1614 OMX_MAX_STRINGNAME_SIZE)) {
1615 strlcpy((char *)m_cRole, "video_decoder.mpeg4",\
1616 OMX_MAX_STRINGNAME_SIZE);
1617 drv_ctx.timestamp_adjust = true;
1618 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4;
1619 eCompressionFormat = OMX_VIDEO_CodingMPEG4;
1620 output_capability=V4L2_PIX_FMT_MPEG4;
Deva Ramasubramanian14b50b42014-09-29 12:29:39 -07001621 ignore_not_coded_vops = false;
Arun Menon906de572013-06-18 17:01:40 -07001622 /*Initialize Start Code for MPEG4*/
1623 codec_type_parse = CODEC_TYPE_MPEG4;
1624 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001625 } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\
1626 OMX_MAX_STRINGNAME_SIZE)) {
1627 strlcpy((char *)m_cRole, "video_decoder.mpeg2",\
1628 OMX_MAX_STRINGNAME_SIZE);
1629 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2;
1630 output_capability = V4L2_PIX_FMT_MPEG2;
1631 eCompressionFormat = OMX_VIDEO_CodingMPEG2;
1632 /*Initialize Start Code for MPEG2*/
1633 codec_type_parse = CODEC_TYPE_MPEG2;
1634 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001635 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\
1636 OMX_MAX_STRINGNAME_SIZE)) {
1637 strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001638 DEBUG_PRINT_LOW("H263 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001639 drv_ctx.decoder_format = VDEC_CODECTYPE_H263;
1640 eCompressionFormat = OMX_VIDEO_CodingH263;
1641 output_capability = V4L2_PIX_FMT_H263;
1642 codec_type_parse = CODEC_TYPE_H263;
1643 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001644 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\
1645 OMX_MAX_STRINGNAME_SIZE)) {
1646 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001647 DEBUG_PRINT_LOW ("DIVX 311 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001648 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3;
1649 output_capability = V4L2_PIX_FMT_DIVX_311;
1650 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1651 codec_type_parse = CODEC_TYPE_DIVX;
Deva Ramasubramanian14b50b42014-09-29 12:29:39 -07001652 ignore_not_coded_vops = true;
Arun Menon906de572013-06-18 17:01:40 -07001653 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001654
Arun Menon906de572013-06-18 17:01:40 -07001655 eRet = createDivxDrmContext();
1656 if (eRet != OMX_ErrorNone) {
1657 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1658 return eRet;
1659 }
1660 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\
1661 OMX_MAX_STRINGNAME_SIZE)) {
1662 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001663 DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001664 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4;
1665 output_capability = V4L2_PIX_FMT_DIVX;
1666 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1667 codec_type_parse = CODEC_TYPE_DIVX;
1668 codec_ambiguous = true;
Deva Ramasubramanian14b50b42014-09-29 12:29:39 -07001669 ignore_not_coded_vops = true;
Arun Menon906de572013-06-18 17:01:40 -07001670 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001671
Arun Menon906de572013-06-18 17:01:40 -07001672 eRet = createDivxDrmContext();
1673 if (eRet != OMX_ErrorNone) {
1674 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1675 return eRet;
1676 }
1677 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\
1678 OMX_MAX_STRINGNAME_SIZE)) {
1679 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001680 DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001681 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6;
1682 output_capability = V4L2_PIX_FMT_DIVX;
1683 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1684 codec_type_parse = CODEC_TYPE_DIVX;
1685 codec_ambiguous = true;
Deva Ramasubramanian14b50b42014-09-29 12:29:39 -07001686 ignore_not_coded_vops = true;
Arun Menon906de572013-06-18 17:01:40 -07001687 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001688
Arun Menon906de572013-06-18 17:01:40 -07001689 eRet = createDivxDrmContext();
1690 if (eRet != OMX_ErrorNone) {
1691 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1692 return eRet;
1693 }
Deva Ramasubramanian9403f022012-11-28 18:27:53 -08001694
Arun Menon906de572013-06-18 17:01:40 -07001695 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\
1696 OMX_MAX_STRINGNAME_SIZE)) {
1697 strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
1698 drv_ctx.decoder_format = VDEC_CODECTYPE_H264;
1699 output_capability=V4L2_PIX_FMT_H264;
1700 eCompressionFormat = OMX_VIDEO_CodingAVC;
1701 codec_type_parse = CODEC_TYPE_H264;
1702 m_frame_parser.init_start_codes (codec_type_parse);
1703 m_frame_parser.init_nal_length(nal_length);
Arun Menon906de572013-06-18 17:01:40 -07001704 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\
1705 OMX_MAX_STRINGNAME_SIZE)) {
1706 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1707 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1;
1708 eCompressionFormat = OMX_VIDEO_CodingWMV;
1709 codec_type_parse = CODEC_TYPE_VC1;
1710 output_capability = V4L2_PIX_FMT_VC1_ANNEX_G;
1711 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001712 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\
1713 OMX_MAX_STRINGNAME_SIZE)) {
1714 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1715 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV;
1716 eCompressionFormat = OMX_VIDEO_CodingWMV;
1717 codec_type_parse = CODEC_TYPE_VC1;
1718 output_capability = V4L2_PIX_FMT_VC1_ANNEX_L;
1719 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001720 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \
1721 OMX_MAX_STRINGNAME_SIZE)) {
1722 strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
1723 output_capability=V4L2_PIX_FMT_VP8;
Praveen Chavan76b71c32014-07-10 18:10:51 -07001724 eCompressionFormat = OMX_VIDEO_CodingVP8;
Arun Menon906de572013-06-18 17:01:40 -07001725 codec_type_parse = CODEC_TYPE_VP8;
1726 arbitrary_bytes = false;
Praneeth Paladugu2b2ef2d2013-04-10 22:04:51 -07001727
Arun Menon906de572013-06-18 17:01:40 -07001728 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001729 DEBUG_PRINT_ERROR("ERROR:Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07001730 eRet = OMX_ErrorInvalidComponentName;
1731 }
Arun Menon906de572013-06-18 17:01:40 -07001732 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001733
Arun Menon906de572013-06-18 17:01:40 -07001734 drv_ctx.output_format = VDEC_YUV_FORMAT_NV12;
Vinay Kaliada4f4422013-01-09 10:45:03 -08001735 OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE)
1736 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
1737 if (!client_buffers.set_color_format(dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001738 DEBUG_PRINT_ERROR("Setting color format failed");
Vinay Kaliada4f4422013-01-09 10:45:03 -08001739 eRet = OMX_ErrorInsufficientResources;
1740 }
1741
Arun Menon906de572013-06-18 17:01:40 -07001742 capture_capability= V4L2_PIX_FMT_NV12;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001743
Arun Menon906de572013-06-18 17:01:40 -07001744 struct v4l2_capability cap;
1745 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap);
1746 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001747 DEBUG_PRINT_ERROR("Failed to query capabilities");
Arun Menon906de572013-06-18 17:01:40 -07001748 /*TODO: How to handle this case */
1749 } else {
1750 DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s,"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001751 " version = %d, capabilities = %x", cap.driver, cap.card,
Arun Menon906de572013-06-18 17:01:40 -07001752 cap.bus_info, cap.version, cap.capabilities);
1753 }
1754 ret=0;
1755 fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1756 fdesc.index=0;
1757 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001758 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001759 fdesc.pixelformat, fdesc.flags);
1760 fdesc.index++;
1761 }
1762 fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1763 fdesc.index=0;
1764 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001765
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001766 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001767 fdesc.pixelformat, fdesc.flags);
1768 fdesc.index++;
1769 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001770 update_resolution(320, 240, 320, 240);
Arun Menon906de572013-06-18 17:01:40 -07001771 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1772 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1773 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1774 fmt.fmt.pix_mp.pixelformat = output_capability;
1775 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1776 if (ret) {
1777 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001778 DEBUG_PRINT_ERROR("Failed to set format on output port");
Arun Menon906de572013-06-18 17:01:40 -07001779 return OMX_ErrorInsufficientResources;
1780 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001781 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001782 if (codec_ambiguous) {
1783 if (output_capability == V4L2_PIX_FMT_DIVX) {
1784 struct v4l2_control divx_ctrl;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001785
Arun Menon906de572013-06-18 17:01:40 -07001786 if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) {
1787 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4;
1788 } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) {
1789 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5;
1790 } else {
1791 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6;
1792 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001793
Arun Menon906de572013-06-18 17:01:40 -07001794 divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT;
1795 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl);
1796 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001797 DEBUG_PRINT_ERROR("Failed to set divx version");
Arun Menon906de572013-06-18 17:01:40 -07001798 }
1799 } else {
1800 DEBUG_PRINT_ERROR("Codec should not be ambiguous");
1801 }
1802 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001803
Jia Meng3a3c6492013-12-19 17:16:52 +08001804 property_get("persist.vidc.dec.conceal_color", property_value, DEFAULT_CONCEAL_COLOR);
1805 m_conceal_color= atoi(property_value);
1806 DEBUG_PRINT_HIGH("trying to set 0x%x as conceal color\n",m_conceal_color);
1807 control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR;
1808 control.value = m_conceal_color;
1809 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
1810 if (ret) {
1811 DEBUG_PRINT_ERROR("Failed to set conceal color %d\n", ret);
1812 }
1813
Arun Menon906de572013-06-18 17:01:40 -07001814 //Get the hardware capabilities
1815 memset((void *)&frmsize,0,sizeof(frmsize));
1816 frmsize.index = 0;
1817 frmsize.pixel_format = output_capability;
1818 ret = ioctl(drv_ctx.video_driver_fd,
1819 VIDIOC_ENUM_FRAMESIZES, &frmsize);
1820 if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001821 DEBUG_PRINT_ERROR("Failed to get framesizes");
Arun Menon906de572013-06-18 17:01:40 -07001822 return OMX_ErrorHardware;
1823 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001824
Arun Menon906de572013-06-18 17:01:40 -07001825 if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1826 m_decoder_capability.min_width = frmsize.stepwise.min_width;
1827 m_decoder_capability.max_width = frmsize.stepwise.max_width;
1828 m_decoder_capability.min_height = frmsize.stepwise.min_height;
1829 m_decoder_capability.max_height = frmsize.stepwise.max_height;
1830 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001831
Arun Menon906de572013-06-18 17:01:40 -07001832 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1833 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1834 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1835 fmt.fmt.pix_mp.pixelformat = capture_capability;
1836 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1837 if (ret) {
1838 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001839 DEBUG_PRINT_ERROR("Failed to set format on capture port");
Arun Menon906de572013-06-18 17:01:40 -07001840 }
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301841 memset(&framesize, 0, sizeof(OMX_FRAMESIZETYPE));
1842 framesize.nWidth = drv_ctx.video_resolution.frame_width;
1843 framesize.nHeight = drv_ctx.video_resolution.frame_height;
1844
1845 memset(&rectangle, 0, sizeof(OMX_CONFIG_RECTTYPE));
1846 rectangle.nWidth = drv_ctx.video_resolution.frame_width;
1847 rectangle.nHeight = drv_ctx.video_resolution.frame_height;
1848
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001849 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001850 if (secure_mode) {
1851 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE;
1852 control.value = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001853 DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001854 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
1855 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001856 DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001857 return OMX_ErrorInsufficientResources;
1858 }
1859 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001860
Arun Menon906de572013-06-18 17:01:40 -07001861 /*Get the Buffer requirements for input and output ports*/
1862 drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT;
1863 drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
1864 if (secure_mode) {
1865 drv_ctx.op_buf.alignment=SZ_1M;
1866 drv_ctx.ip_buf.alignment=SZ_1M;
1867 } else {
1868 drv_ctx.op_buf.alignment=SZ_4K;
1869 drv_ctx.ip_buf.alignment=SZ_4K;
1870 }
1871 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
1872 drv_ctx.extradata = 0;
1873 drv_ctx.picture_order = VDEC_ORDER_DISPLAY;
1874 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
1875 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
1876 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
1877 drv_ctx.idr_only_decoding = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001878
Vinay Kalia5713bb32013-01-16 18:39:59 -08001879 m_state = OMX_StateLoaded;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001880#ifdef DEFAULT_EXTRADATA
Arun Menonf8908a62013-12-20 17:36:21 -08001881 if (strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",
1882 OMX_MAX_STRINGNAME_SIZE) && (eRet == OMX_ErrorNone))
1883 enable_extradata(DEFAULT_EXTRADATA, true, true);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001884#endif
Vinay Kalia5713bb32013-01-16 18:39:59 -08001885 eRet=get_buffer_req(&drv_ctx.ip_buf);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001886 DEBUG_PRINT_HIGH("Input Buffer Size =%d",drv_ctx.ip_buf.buffer_size);
Vinay Kalia5713bb32013-01-16 18:39:59 -08001887 get_buffer_req(&drv_ctx.op_buf);
Arun Menon906de572013-06-18 17:01:40 -07001888 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
1889 if (m_frame_parser.mutils == NULL) {
1890 m_frame_parser.mutils = new H264_Utils();
Shalaj Jain273b3e02012-06-22 19:08:03 -07001891
Arun Menon906de572013-06-18 17:01:40 -07001892 if (m_frame_parser.mutils == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001893 DEBUG_PRINT_ERROR("parser utils Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001894 eRet = OMX_ErrorInsufficientResources;
1895 } else {
1896 h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size;
1897 h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size);
1898 h264_scratch.nFilledLen = 0;
1899 h264_scratch.nOffset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001900
Arun Menon906de572013-06-18 17:01:40 -07001901 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001902 DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001903 return OMX_ErrorInsufficientResources;
1904 }
1905 m_frame_parser.mutils->initialize_frame_checking_environment();
1906 m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size);
1907 }
1908 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001909
Arun Menon906de572013-06-18 17:01:40 -07001910 h264_parser = new h264_stream_parser();
1911 if (!h264_parser) {
1912 DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!");
1913 eRet = OMX_ErrorInsufficientResources;
1914 }
1915 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001916
Arun Menon906de572013-06-18 17:01:40 -07001917 if (pipe(fds)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001918 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001919 eRet = OMX_ErrorInsufficientResources;
1920 } else {
1921 int temp1[2];
1922 if (fds[0] == 0 || fds[1] == 0) {
1923 if (pipe (temp1)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001924 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001925 return OMX_ErrorInsufficientResources;
1926 }
1927 //close (fds[0]);
1928 //close (fds[1]);
1929 fds[0] = temp1 [0];
1930 fds[1] = temp1 [1];
1931 }
1932 m_pipe_in = fds[0];
1933 m_pipe_out = fds[1];
1934 msg_thread_created = true;
1935 r = pthread_create(&msg_thread_id,0,message_thread,this);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001936
Arun Menon906de572013-06-18 17:01:40 -07001937 if (r < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001938 DEBUG_PRINT_ERROR("component_init(): message_thread creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001939 msg_thread_created = false;
1940 eRet = OMX_ErrorInsufficientResources;
1941 }
1942 }
1943 }
1944
1945 if (eRet != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001946 DEBUG_PRINT_ERROR("Component Init Failed");
Arun Menon906de572013-06-18 17:01:40 -07001947 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001948 DEBUG_PRINT_HIGH("omx_vdec::component_init() success");
Arun Menon906de572013-06-18 17:01:40 -07001949 }
1950 //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer));
1951 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001952}
1953
1954/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001955 FUNCTION
1956 omx_vdec::GetComponentVersion
Shalaj Jain273b3e02012-06-22 19:08:03 -07001957
Arun Menon906de572013-06-18 17:01:40 -07001958 DESCRIPTION
1959 Returns the component version.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001960
Arun Menon906de572013-06-18 17:01:40 -07001961 PARAMETERS
1962 TBD.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001963
Arun Menon906de572013-06-18 17:01:40 -07001964 RETURN VALUE
1965 OMX_ErrorNone.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001966
Arun Menon906de572013-06-18 17:01:40 -07001967 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001968OMX_ERRORTYPE omx_vdec::get_component_version
Arun Menon906de572013-06-18 17:01:40 -07001969(
1970 OMX_IN OMX_HANDLETYPE hComp,
1971 OMX_OUT OMX_STRING componentName,
1972 OMX_OUT OMX_VERSIONTYPE* componentVersion,
1973 OMX_OUT OMX_VERSIONTYPE* specVersion,
1974 OMX_OUT OMX_UUIDTYPE* componentUUID
1975 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07001976{
Arun Menon906de572013-06-18 17:01:40 -07001977 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001978 DEBUG_PRINT_ERROR("Get Comp Version in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001979 return OMX_ErrorInvalidState;
1980 }
Arun Menon906de572013-06-18 17:01:40 -07001981 /* TBD -- Return the proper version */
1982 if (specVersion) {
1983 specVersion->nVersion = OMX_SPEC_VERSION;
1984 }
1985 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001986}
1987/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001988 FUNCTION
1989 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07001990
Arun Menon906de572013-06-18 17:01:40 -07001991 DESCRIPTION
1992 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07001993
Arun Menon906de572013-06-18 17:01:40 -07001994 PARAMETERS
1995 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001996
Arun Menon906de572013-06-18 17:01:40 -07001997 RETURN VALUE
1998 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07001999
Arun Menon906de572013-06-18 17:01:40 -07002000 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002001OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002002 OMX_IN OMX_COMMANDTYPE cmd,
2003 OMX_IN OMX_U32 param1,
2004 OMX_IN OMX_PTR cmdData
2005 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07002006{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002007 DEBUG_PRINT_LOW("send_command: Recieved a Command from Client");
Arun Menon906de572013-06-18 17:01:40 -07002008 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002009 DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002010 return OMX_ErrorInvalidState;
2011 }
2012 if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX
Arun Menon906de572013-06-18 17:01:40 -07002013 && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002014 DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush "
Arun Menon906de572013-06-18 17:01:40 -07002015 "to invalid port: %lu", param1);
2016 return OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002017 }
2018 post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND);
2019 sem_wait(&m_cmd_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002020 DEBUG_PRINT_LOW("send_command: Command Processed");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002021 return OMX_ErrorNone;
2022}
2023
2024/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002025 FUNCTION
2026 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07002027
Arun Menon906de572013-06-18 17:01:40 -07002028 DESCRIPTION
2029 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07002030
Arun Menon906de572013-06-18 17:01:40 -07002031 PARAMETERS
2032 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002033
Arun Menon906de572013-06-18 17:01:40 -07002034 RETURN VALUE
2035 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002036
Arun Menon906de572013-06-18 17:01:40 -07002037 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002038OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002039 OMX_IN OMX_COMMANDTYPE cmd,
2040 OMX_IN OMX_U32 param1,
2041 OMX_IN OMX_PTR cmdData
2042 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07002043{
Arun Menon906de572013-06-18 17:01:40 -07002044 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2045 OMX_STATETYPE eState = (OMX_STATETYPE) param1;
2046 int bFlag = 1,sem_posted = 0,ret=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002047
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002048 DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd);
2049 DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d",
Arun Menon906de572013-06-18 17:01:40 -07002050 m_state, eState);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002051
Arun Menon906de572013-06-18 17:01:40 -07002052 if (cmd == OMX_CommandStateSet) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002053 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued");
2054 DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState);
Arun Menon906de572013-06-18 17:01:40 -07002055 /***************************/
2056 /* Current State is Loaded */
2057 /***************************/
2058 if (m_state == OMX_StateLoaded) {
2059 if (eState == OMX_StateIdle) {
2060 //if all buffers are allocated or all ports disabled
2061 if (allocate_done() ||
2062 (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002063 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07002064 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002065 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending");
Arun Menon906de572013-06-18 17:01:40 -07002066 BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING);
2067 // Skip the event notification
2068 bFlag = 0;
2069 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002070 }
Arun Menon906de572013-06-18 17:01:40 -07002071 /* Requesting transition from Loaded to Loaded */
2072 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002073 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002074 post_event(OMX_EventError,OMX_ErrorSameState,\
2075 OMX_COMPONENT_GENERATE_EVENT);
2076 eRet = OMX_ErrorSameState;
2077 }
2078 /* Requesting transition from Loaded to WaitForResources */
2079 else if (eState == OMX_StateWaitForResources) {
2080 /* Since error is None , we will post an event
2081 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002082 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002083 }
2084 /* Requesting transition from Loaded to Executing */
2085 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002086 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002087 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2088 OMX_COMPONENT_GENERATE_EVENT);
2089 eRet = OMX_ErrorIncorrectStateTransition;
2090 }
2091 /* Requesting transition from Loaded to Pause */
2092 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002093 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002094 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2095 OMX_COMPONENT_GENERATE_EVENT);
2096 eRet = OMX_ErrorIncorrectStateTransition;
2097 }
2098 /* Requesting transition from Loaded to Invalid */
2099 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002100 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002101 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2102 eRet = OMX_ErrorInvalidState;
2103 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002104 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\
Arun Menon906de572013-06-18 17:01:40 -07002105 eState);
2106 eRet = OMX_ErrorBadParameter;
2107 }
2108 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002109
Arun Menon906de572013-06-18 17:01:40 -07002110 /***************************/
2111 /* Current State is IDLE */
2112 /***************************/
2113 else if (m_state == OMX_StateIdle) {
2114 if (eState == OMX_StateLoaded) {
2115 if (release_done()) {
2116 /*
2117 Since error is None , we will post an event at the end
2118 of this function definition
2119 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002120 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002121 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002122 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending");
Arun Menon906de572013-06-18 17:01:40 -07002123 BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING);
2124 // Skip the event notification
2125 bFlag = 0;
2126 }
2127 }
2128 /* Requesting transition from Idle to Executing */
2129 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002130 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002131 //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING);
2132 bFlag = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002133 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002134 m_state=OMX_StateExecuting;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002135 DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful");
Arun Menon906de572013-06-18 17:01:40 -07002136 }
2137 /* Requesting transition from Idle to Idle */
2138 else if (eState == OMX_StateIdle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002139 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07002140 post_event(OMX_EventError,OMX_ErrorSameState,\
2141 OMX_COMPONENT_GENERATE_EVENT);
2142 eRet = OMX_ErrorSameState;
2143 }
2144 /* Requesting transition from Idle to WaitForResources */
2145 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002146 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002147 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2148 OMX_COMPONENT_GENERATE_EVENT);
2149 eRet = OMX_ErrorIncorrectStateTransition;
2150 }
2151 /* Requesting transition from Idle to Pause */
2152 else if (eState == OMX_StatePause) {
2153 /*To pause the Video core we need to start the driver*/
2154 if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START,
2155 NULL) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002156 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED");
Arun Menon906de572013-06-18 17:01:40 -07002157 omx_report_error ();
2158 eRet = OMX_ErrorHardware;
2159 } else {
2160 BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002161 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002162 bFlag = 0;
2163 }
2164 }
2165 /* Requesting transition from Idle to Invalid */
2166 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002167 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002168 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2169 eRet = OMX_ErrorInvalidState;
2170 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002171 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002172 eRet = OMX_ErrorBadParameter;
2173 }
2174 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002175
Arun Menon906de572013-06-18 17:01:40 -07002176 /******************************/
2177 /* Current State is Executing */
2178 /******************************/
2179 else if (m_state == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002180 DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting");
Arun Menon906de572013-06-18 17:01:40 -07002181 /* Requesting transition from Executing to Idle */
2182 if (eState == OMX_StateIdle) {
2183 /* Since error is None , we will post an event
2184 at the end of this function definition
2185 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002186 DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002187 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2188 if (!sem_posted) {
2189 sem_posted = 1;
2190 sem_post (&m_cmd_lock);
2191 execute_omx_flush(OMX_ALL);
2192 }
2193 bFlag = 0;
2194 }
2195 /* Requesting transition from Executing to Paused */
2196 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002197 DEBUG_PRINT_LOW("PAUSE Command Issued");
Arun Menon906de572013-06-18 17:01:40 -07002198 m_state = OMX_StatePause;
2199 bFlag = 1;
2200 }
2201 /* Requesting transition from Executing to Loaded */
2202 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002203 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002204 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2205 OMX_COMPONENT_GENERATE_EVENT);
2206 eRet = OMX_ErrorIncorrectStateTransition;
2207 }
2208 /* Requesting transition from Executing to WaitForResources */
2209 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002210 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002211 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2212 OMX_COMPONENT_GENERATE_EVENT);
2213 eRet = OMX_ErrorIncorrectStateTransition;
2214 }
2215 /* Requesting transition from Executing to Executing */
2216 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002217 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002218 post_event(OMX_EventError,OMX_ErrorSameState,\
2219 OMX_COMPONENT_GENERATE_EVENT);
2220 eRet = OMX_ErrorSameState;
2221 }
2222 /* Requesting transition from Executing to Invalid */
2223 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002224 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002225 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2226 eRet = OMX_ErrorInvalidState;
2227 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002228 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002229 eRet = OMX_ErrorBadParameter;
2230 }
2231 }
2232 /***************************/
2233 /* Current State is Pause */
2234 /***************************/
2235 else if (m_state == OMX_StatePause) {
2236 /* Requesting transition from Pause to Executing */
2237 if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002238 DEBUG_PRINT_LOW("Pause --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002239 m_state = OMX_StateExecuting;
2240 bFlag = 1;
2241 }
2242 /* Requesting transition from Pause to Idle */
2243 else if (eState == OMX_StateIdle) {
2244 /* Since error is None , we will post an event
2245 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002246 DEBUG_PRINT_LOW("Pause --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002247 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2248 if (!sem_posted) {
2249 sem_posted = 1;
2250 sem_post (&m_cmd_lock);
2251 execute_omx_flush(OMX_ALL);
2252 }
2253 bFlag = 0;
2254 }
2255 /* Requesting transition from Pause to loaded */
2256 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002257 DEBUG_PRINT_ERROR("Pause --> loaded");
Arun Menon906de572013-06-18 17:01:40 -07002258 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2259 OMX_COMPONENT_GENERATE_EVENT);
2260 eRet = OMX_ErrorIncorrectStateTransition;
2261 }
2262 /* Requesting transition from Pause to WaitForResources */
2263 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002264 DEBUG_PRINT_ERROR("Pause --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002265 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2266 OMX_COMPONENT_GENERATE_EVENT);
2267 eRet = OMX_ErrorIncorrectStateTransition;
2268 }
2269 /* Requesting transition from Pause to Pause */
2270 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002271 DEBUG_PRINT_ERROR("Pause --> Pause");
Arun Menon906de572013-06-18 17:01:40 -07002272 post_event(OMX_EventError,OMX_ErrorSameState,\
2273 OMX_COMPONENT_GENERATE_EVENT);
2274 eRet = OMX_ErrorSameState;
2275 }
2276 /* Requesting transition from Pause to Invalid */
2277 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002278 DEBUG_PRINT_ERROR("Pause --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002279 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2280 eRet = OMX_ErrorInvalidState;
2281 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002282 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002283 eRet = OMX_ErrorBadParameter;
2284 }
2285 }
2286 /***************************/
2287 /* Current State is WaitForResources */
2288 /***************************/
2289 else if (m_state == OMX_StateWaitForResources) {
2290 /* Requesting transition from WaitForResources to Loaded */
2291 if (eState == OMX_StateLoaded) {
2292 /* Since error is None , we will post an event
2293 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002294 DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002295 }
2296 /* Requesting transition from WaitForResources to WaitForResources */
2297 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002298 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002299 post_event(OMX_EventError,OMX_ErrorSameState,
2300 OMX_COMPONENT_GENERATE_EVENT);
2301 eRet = OMX_ErrorSameState;
2302 }
2303 /* Requesting transition from WaitForResources to Executing */
2304 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002305 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002306 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2307 OMX_COMPONENT_GENERATE_EVENT);
2308 eRet = OMX_ErrorIncorrectStateTransition;
2309 }
2310 /* Requesting transition from WaitForResources to Pause */
2311 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002312 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002313 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2314 OMX_COMPONENT_GENERATE_EVENT);
2315 eRet = OMX_ErrorIncorrectStateTransition;
2316 }
2317 /* Requesting transition from WaitForResources to Invalid */
2318 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002319 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002320 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2321 eRet = OMX_ErrorInvalidState;
2322 }
2323 /* Requesting transition from WaitForResources to Loaded -
2324 is NOT tested by Khronos TS */
2325
2326 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002327 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): %d --> %d(Not Handled)",m_state,eState);
Arun Menon906de572013-06-18 17:01:40 -07002328 eRet = OMX_ErrorBadParameter;
2329 }
2330 }
2331 /********************************/
2332 /* Current State is Invalid */
2333 /*******************************/
2334 else if (m_state == OMX_StateInvalid) {
2335 /* State Transition from Inavlid to any state */
2336 if (eState == (OMX_StateLoaded || OMX_StateWaitForResources
2337 || OMX_StateIdle || OMX_StateExecuting
2338 || OMX_StatePause || OMX_StateInvalid)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002339 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002340 post_event(OMX_EventError,OMX_ErrorInvalidState,\
2341 OMX_COMPONENT_GENERATE_EVENT);
2342 eRet = OMX_ErrorInvalidState;
2343 }
2344 } else if (cmd == OMX_CommandFlush) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002345 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued"
Arun Menon906de572013-06-18 17:01:40 -07002346 "with param1: %lu", param1);
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07002347#ifdef _MSM8974_
2348 send_codec_config();
2349#endif
Arun Menon906de572013-06-18 17:01:40 -07002350 if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2351 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING);
2352 }
2353 if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2354 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
2355 }
2356 if (!sem_posted) {
2357 sem_posted = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002358 DEBUG_PRINT_LOW("Set the Semaphore");
Arun Menon906de572013-06-18 17:01:40 -07002359 sem_post (&m_cmd_lock);
2360 execute_omx_flush(param1);
2361 }
2362 bFlag = 0;
2363 } else if ( cmd == OMX_CommandPortEnable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002364 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued"
Arun Menon906de572013-06-18 17:01:40 -07002365 "with param1: %lu", param1);
2366 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
2367 m_inp_bEnabled = OMX_TRUE;
2368
2369 if ( (m_state == OMX_StateLoaded &&
2370 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2371 || allocate_input_done()) {
2372 post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX,
2373 OMX_COMPONENT_GENERATE_EVENT);
2374 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002375 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002376 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING);
2377 // Skip the event notification
2378 bFlag = 0;
2379 }
2380 }
2381 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002382 DEBUG_PRINT_LOW("Enable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002383 m_out_bEnabled = OMX_TRUE;
2384
2385 if ( (m_state == OMX_StateLoaded &&
2386 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2387 || (allocate_output_done())) {
2388 post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX,
2389 OMX_COMPONENT_GENERATE_EVENT);
2390
2391 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002392 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002393 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
2394 // Skip the event notification
2395 bFlag = 0;
2396 }
2397 }
2398 } else if (cmd == OMX_CommandPortDisable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002399 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued"
Arun Menon906de572013-06-18 17:01:40 -07002400 "with param1: %lu", param1);
2401 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07002402 codec_config_flag = false;
Arun Menon906de572013-06-18 17:01:40 -07002403 m_inp_bEnabled = OMX_FALSE;
2404 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2405 && release_input_done()) {
2406 post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX,
2407 OMX_COMPONENT_GENERATE_EVENT);
2408 } else {
2409 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING);
2410 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2411 if (!sem_posted) {
2412 sem_posted = 1;
2413 sem_post (&m_cmd_lock);
2414 }
2415 execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX);
2416 }
2417
2418 // Skip the event notification
2419 bFlag = 0;
2420 }
2421 }
2422 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
2423 m_out_bEnabled = OMX_FALSE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002424 DEBUG_PRINT_LOW("Disable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002425 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2426 && release_output_done()) {
2427 post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\
2428 OMX_COMPONENT_GENERATE_EVENT);
2429 } else {
2430 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
2431 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2432 if (!sem_posted) {
2433 sem_posted = 1;
2434 sem_post (&m_cmd_lock);
2435 }
2436 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
2437 execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX);
2438 }
2439 // Skip the event notification
2440 bFlag = 0;
2441
2442 }
2443 }
2444 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002445 DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd);
Arun Menon906de572013-06-18 17:01:40 -07002446 eRet = OMX_ErrorNotImplemented;
2447 }
2448 if (eRet == OMX_ErrorNone && bFlag) {
2449 post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT);
2450 }
2451 if (!sem_posted) {
2452 sem_post(&m_cmd_lock);
2453 }
2454
2455 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002456}
2457
2458/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002459 FUNCTION
2460 omx_vdec::ExecuteOmxFlush
Shalaj Jain273b3e02012-06-22 19:08:03 -07002461
Arun Menon906de572013-06-18 17:01:40 -07002462 DESCRIPTION
2463 Executes the OMX flush.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002464
Arun Menon906de572013-06-18 17:01:40 -07002465 PARAMETERS
2466 flushtype - input flush(1)/output flush(0)/ both.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002467
Arun Menon906de572013-06-18 17:01:40 -07002468 RETURN VALUE
2469 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002470
Arun Menon906de572013-06-18 17:01:40 -07002471 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002472bool omx_vdec::execute_omx_flush(OMX_U32 flushType)
2473{
Arun Menon906de572013-06-18 17:01:40 -07002474 bool bRet = false;
2475 struct v4l2_plane plane;
2476 struct v4l2_buffer v4l2_buf;
2477 struct v4l2_decoder_cmd dec;
Surajit Podderd2644d52013-08-28 17:59:06 +05302478 DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType);
Arun Menon906de572013-06-18 17:01:40 -07002479 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
2480 dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH;
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002481
Arun Menon906de572013-06-18 17:01:40 -07002482 DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig);
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002483
Arun Menon906de572013-06-18 17:01:40 -07002484 if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) {
2485 output_flush_progress = true;
2486 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2487 } else {
2488 /* XXX: The driver/hardware does not support flushing of individual ports
2489 * in all states. So we pretty much need to flush both ports internally,
2490 * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it
2491 * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set,
2492 * we automatically omit sending the FLUSH done for the "opposite" port. */
2493 input_flush_progress = true;
2494 output_flush_progress = true;
2495 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2496 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002497
Arun Menon906de572013-06-18 17:01:40 -07002498 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002499 DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType);
Arun Menon906de572013-06-18 17:01:40 -07002500 bRet = false;
2501 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002502
Arun Menon906de572013-06-18 17:01:40 -07002503 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002504}
2505/*=========================================================================
2506FUNCTION : execute_output_flush
2507
2508DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002509Executes the OMX flush at OUTPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002510
2511PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002512None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002513
2514RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002515true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002516==========================================================================*/
2517bool omx_vdec::execute_output_flush()
2518{
Arun Menon906de572013-06-18 17:01:40 -07002519 unsigned p1 = 0; // Parameter - 1
2520 unsigned p2 = 0; // Parameter - 2
2521 unsigned ident = 0;
2522 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002523
Arun Menon906de572013-06-18 17:01:40 -07002524 /*Generate FBD for all Buffers in the FTBq*/
2525 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002526 DEBUG_PRINT_LOW("Initiate Output Flush");
vivek mehta79cff222014-01-22 12:17:07 -08002527
2528 //reset last render TS
2529 if(m_last_rendered_TS > 0) {
2530 m_last_rendered_TS = 0;
2531 }
vivek mehtaa75c69f2014-01-10 21:50:37 -08002532
Arun Menon906de572013-06-18 17:01:40 -07002533 while (m_ftb_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002534 DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d",
Arun Menon906de572013-06-18 17:01:40 -07002535 m_ftb_q.m_size,pending_output_buffers);
2536 m_ftb_q.pop_entry(&p1,&p2,&ident);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002537 DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2);
Arun Menon906de572013-06-18 17:01:40 -07002538 if (ident == m_fill_output_msg ) {
2539 m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2540 } else if (ident == OMX_COMPONENT_GENERATE_FBD) {
2541 fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2542 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002543 }
Arun Menon906de572013-06-18 17:01:40 -07002544 pthread_mutex_unlock(&m_lock);
2545 output_flush_progress = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002546
Arun Menon906de572013-06-18 17:01:40 -07002547 if (arbitrary_bytes) {
2548 prev_ts = LLONG_MAX;
2549 rst_prev_ts = true;
2550 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002551 DEBUG_PRINT_HIGH("OMX flush o/p Port complete PenBuf(%d)", pending_output_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002552 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002553}
2554/*=========================================================================
2555FUNCTION : execute_input_flush
2556
2557DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002558Executes the OMX flush at INPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002559
2560PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002561None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002562
2563RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002564true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002565==========================================================================*/
2566bool omx_vdec::execute_input_flush()
2567{
Arun Menon906de572013-06-18 17:01:40 -07002568 unsigned i =0;
2569 unsigned p1 = 0; // Parameter - 1
2570 unsigned p2 = 0; // Parameter - 2
2571 unsigned ident = 0;
2572 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002573
Arun Menon906de572013-06-18 17:01:40 -07002574 /*Generate EBD for all Buffers in the ETBq*/
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002575 DEBUG_PRINT_LOW("Initiate Input Flush");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002576
Arun Menon906de572013-06-18 17:01:40 -07002577 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002578 DEBUG_PRINT_LOW("Check if the Queue is empty");
Arun Menon906de572013-06-18 17:01:40 -07002579 while (m_etb_q.m_size) {
2580 m_etb_q.pop_entry(&p1,&p2,&ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002581
Arun Menon906de572013-06-18 17:01:40 -07002582 if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002583 DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2);
Arun Menon906de572013-06-18 17:01:40 -07002584 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2585 } else if (ident == OMX_COMPONENT_GENERATE_ETB) {
2586 pending_input_buffers++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002587 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d",
Arun Menon906de572013-06-18 17:01:40 -07002588 (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers);
2589 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
2590 } else if (ident == OMX_COMPONENT_GENERATE_EBD) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002591 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p",
Arun Menon906de572013-06-18 17:01:40 -07002592 (OMX_BUFFERHEADERTYPE *)p1);
2593 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2594 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002595 }
Arun Menon906de572013-06-18 17:01:40 -07002596 time_stamp_dts.flush_timestamp();
2597 /*Check if Heap Buffers are to be flushed*/
2598 if (arbitrary_bytes && !(codec_config_flag)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002599 DEBUG_PRINT_LOW("Reset all the variables before flusing");
Arun Menon906de572013-06-18 17:01:40 -07002600 h264_scratch.nFilledLen = 0;
2601 nal_count = 0;
2602 look_ahead_nal = false;
2603 frame_count = 0;
2604 h264_last_au_ts = LLONG_MAX;
2605 h264_last_au_flags = 0;
2606 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
2607 m_demux_entries = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002608 DEBUG_PRINT_LOW("Initialize parser");
Arun Menon906de572013-06-18 17:01:40 -07002609 if (m_frame_parser.mutils) {
2610 m_frame_parser.mutils->initialize_frame_checking_environment();
2611 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002612
Arun Menon906de572013-06-18 17:01:40 -07002613 while (m_input_pending_q.m_size) {
2614 m_input_pending_q.pop_entry(&p1,&p2,&ident);
2615 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1);
2616 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002617
Arun Menon906de572013-06-18 17:01:40 -07002618 if (psource_frame) {
2619 m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame);
2620 psource_frame = NULL;
2621 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002622
Arun Menon906de572013-06-18 17:01:40 -07002623 if (pdest_frame) {
2624 pdest_frame->nFilledLen = 0;
2625 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL,
2626 (unsigned int)NULL);
2627 pdest_frame = NULL;
2628 }
2629 m_frame_parser.flush();
2630 } else if (codec_config_flag) {
2631 DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer "
2632 "is not sent to the driver yet");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002633 }
Arun Menon906de572013-06-18 17:01:40 -07002634 pthread_mutex_unlock(&m_lock);
2635 input_flush_progress = false;
2636 if (!arbitrary_bytes) {
2637 prev_ts = LLONG_MAX;
2638 rst_prev_ts = true;
2639 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002640#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07002641 if (m_debug_timestamp) {
2642 m_timestamp_list.reset_ts_list();
2643 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002644#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002645 DEBUG_PRINT_HIGH("OMX flush i/p Port complete PenBuf(%d)", pending_input_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002646 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002647}
2648
2649
2650/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002651 FUNCTION
2652 omx_vdec::SendCommandEvent
Shalaj Jain273b3e02012-06-22 19:08:03 -07002653
Arun Menon906de572013-06-18 17:01:40 -07002654 DESCRIPTION
2655 Send the event to decoder pipe. This is needed to generate the callbacks
2656 in decoder thread context.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002657
Arun Menon906de572013-06-18 17:01:40 -07002658 PARAMETERS
2659 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002660
Arun Menon906de572013-06-18 17:01:40 -07002661 RETURN VALUE
2662 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002663
Arun Menon906de572013-06-18 17:01:40 -07002664 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002665bool omx_vdec::post_event(unsigned int p1,
Arun Menon906de572013-06-18 17:01:40 -07002666 unsigned int p2,
2667 unsigned int id)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002668{
Arun Menon906de572013-06-18 17:01:40 -07002669 bool bRet = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002670
2671
Arun Menon906de572013-06-18 17:01:40 -07002672 pthread_mutex_lock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002673
Arun Menon906de572013-06-18 17:01:40 -07002674 if (id == m_fill_output_msg ||
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05302675 id == OMX_COMPONENT_GENERATE_FBD ||
2676 id == OMX_COMPONENT_GENERATE_PORT_RECONFIG) {
Arun Menon906de572013-06-18 17:01:40 -07002677 m_ftb_q.insert_entry(p1,p2,id);
2678 } else if (id == OMX_COMPONENT_GENERATE_ETB ||
2679 id == OMX_COMPONENT_GENERATE_EBD ||
2680 id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
2681 m_etb_q.insert_entry(p1,p2,id);
2682 } else {
2683 m_cmd_q.insert_entry(p1,p2,id);
2684 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002685
Arun Menon906de572013-06-18 17:01:40 -07002686 bRet = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002687 DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this);
Arun Menon906de572013-06-18 17:01:40 -07002688 post_message(this, id);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002689
Arun Menon906de572013-06-18 17:01:40 -07002690 pthread_mutex_unlock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002691
Arun Menon906de572013-06-18 17:01:40 -07002692 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002693}
2694
2695OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType)
2696{
Arun Menon906de572013-06-18 17:01:40 -07002697 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2698 if (!profileLevelType)
2699 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002700
Arun Menon906de572013-06-18 17:01:40 -07002701 if (profileLevelType->nPortIndex == 0) {
2702 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
2703 if (profileLevelType->nProfileIndex == 0) {
2704 profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline;
2705 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002706
Arun Menon906de572013-06-18 17:01:40 -07002707 } else if (profileLevelType->nProfileIndex == 1) {
2708 profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain;
2709 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2710 } else if (profileLevelType->nProfileIndex == 2) {
2711 profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh;
2712 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2713 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002714 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu",
Arun Menon906de572013-06-18 17:01:40 -07002715 profileLevelType->nProfileIndex);
2716 eRet = OMX_ErrorNoMore;
2717 }
2718 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) {
2719 if (profileLevelType->nProfileIndex == 0) {
2720 profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline;
2721 profileLevelType->eLevel = OMX_VIDEO_H263Level70;
2722 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002723 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002724 eRet = OMX_ErrorNoMore;
2725 }
2726 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
2727 if (profileLevelType->nProfileIndex == 0) {
2728 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple;
2729 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2730 } else if (profileLevelType->nProfileIndex == 1) {
2731 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple;
2732 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2733 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002734 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002735 eRet = OMX_ErrorNoMore;
2736 }
2737 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
2738 eRet = OMX_ErrorNoMore;
2739 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
2740 if (profileLevelType->nProfileIndex == 0) {
2741 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple;
2742 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2743 } else if (profileLevelType->nProfileIndex == 1) {
2744 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain;
2745 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2746 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002747 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002748 eRet = OMX_ErrorNoMore;
2749 }
2750 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002751 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported ret NoMore for codec: %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07002752 eRet = OMX_ErrorNoMore;
2753 }
2754 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002755 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported should be queries on Input port only %lu", profileLevelType->nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07002756 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002757 }
Arun Menon906de572013-06-18 17:01:40 -07002758 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002759}
2760
2761/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002762 FUNCTION
2763 omx_vdec::GetParameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07002764
Arun Menon906de572013-06-18 17:01:40 -07002765 DESCRIPTION
2766 OMX Get Parameter method implementation
Shalaj Jain273b3e02012-06-22 19:08:03 -07002767
Arun Menon906de572013-06-18 17:01:40 -07002768 PARAMETERS
2769 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002770
Arun Menon906de572013-06-18 17:01:40 -07002771 RETURN VALUE
2772 Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002773
Arun Menon906de572013-06-18 17:01:40 -07002774 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002775OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002776 OMX_IN OMX_INDEXTYPE paramIndex,
2777 OMX_INOUT OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002778{
2779 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2780
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002781 DEBUG_PRINT_LOW("get_parameter:");
Arun Menon906de572013-06-18 17:01:40 -07002782 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002783 DEBUG_PRINT_ERROR("Get Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002784 return OMX_ErrorInvalidState;
2785 }
Arun Menon906de572013-06-18 17:01:40 -07002786 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002787 DEBUG_PRINT_LOW("Get Param in Invalid paramData");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002788 return OMX_ErrorBadParameter;
2789 }
Arun Menon906de572013-06-18 17:01:40 -07002790 switch ((unsigned long)paramIndex) {
2791 case OMX_IndexParamPortDefinition: {
2792 OMX_PARAM_PORTDEFINITIONTYPE *portDefn =
2793 (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002794 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition");
Arun Menon906de572013-06-18 17:01:40 -07002795 eRet = update_portdef(portDefn);
2796 if (eRet == OMX_ErrorNone)
2797 m_port_def = *portDefn;
2798 break;
2799 }
2800 case OMX_IndexParamVideoInit: {
2801 OMX_PORT_PARAM_TYPE *portParamType =
2802 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002803 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002804
Arun Menon906de572013-06-18 17:01:40 -07002805 portParamType->nVersion.nVersion = OMX_SPEC_VERSION;
2806 portParamType->nSize = sizeof(portParamType);
2807 portParamType->nPorts = 2;
2808 portParamType->nStartPortNumber = 0;
2809 break;
2810 }
2811 case OMX_IndexParamVideoPortFormat: {
2812 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
2813 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002814 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002815
Arun Menon906de572013-06-18 17:01:40 -07002816 portFmt->nVersion.nVersion = OMX_SPEC_VERSION;
2817 portFmt->nSize = sizeof(portFmt);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002818
Arun Menon906de572013-06-18 17:01:40 -07002819 if (0 == portFmt->nPortIndex) {
2820 if (0 == portFmt->nIndex) {
2821 portFmt->eColorFormat = OMX_COLOR_FormatUnused;
2822 portFmt->eCompressionFormat = eCompressionFormat;
2823 } else {
2824 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002825 " NoMore compression formats");
Arun Menon906de572013-06-18 17:01:40 -07002826 eRet = OMX_ErrorNoMore;
2827 }
2828 } else if (1 == portFmt->nPortIndex) {
2829 portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002830
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07002831 // Distinguish non-surface mode from normal playback use-case based on
2832 // usage hinted via "OMX.google.android.index.useAndroidNativeBuffer2"
2833 // For non-android, use the default list
2834 bool useNonSurfaceMode = false;
2835#if _ANDROID_
2836 useNonSurfaceMode = (m_enable_android_native_buffers == OMX_FALSE);
2837#endif
2838 portFmt->eColorFormat = useNonSurfaceMode ?
2839 getPreferredColorFormatNonSurfaceMode(portFmt->nIndex) :
2840 getPreferredColorFormatDefaultMode(portFmt->nIndex);
2841
2842 if (portFmt->eColorFormat == OMX_COLOR_FormatMax ) {
Praveen Chavandb7776f2014-02-06 18:17:25 -08002843 eRet = OMX_ErrorNoMore;
Arun Menon906de572013-06-18 17:01:40 -07002844 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002845 " NoMore Color formats");
Arun Menon906de572013-06-18 17:01:40 -07002846 }
Praveen Chavandb7776f2014-02-06 18:17:25 -08002847 DEBUG_PRINT_HIGH("returning color-format: 0x%x", portFmt->eColorFormat);
Arun Menon906de572013-06-18 17:01:40 -07002848 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002849 DEBUG_PRINT_ERROR("get_parameter: Bad port index %d",
Arun Menon906de572013-06-18 17:01:40 -07002850 (int)portFmt->nPortIndex);
2851 eRet = OMX_ErrorBadPortIndex;
2852 }
2853 break;
2854 }
2855 /*Component should support this port definition*/
2856 case OMX_IndexParamAudioInit: {
2857 OMX_PORT_PARAM_TYPE *audioPortParamType =
2858 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002859 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit");
Arun Menon906de572013-06-18 17:01:40 -07002860 audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
2861 audioPortParamType->nSize = sizeof(audioPortParamType);
2862 audioPortParamType->nPorts = 0;
2863 audioPortParamType->nStartPortNumber = 0;
2864 break;
2865 }
2866 /*Component should support this port definition*/
2867 case OMX_IndexParamImageInit: {
2868 OMX_PORT_PARAM_TYPE *imagePortParamType =
2869 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002870 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit");
Arun Menon906de572013-06-18 17:01:40 -07002871 imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
2872 imagePortParamType->nSize = sizeof(imagePortParamType);
2873 imagePortParamType->nPorts = 0;
2874 imagePortParamType->nStartPortNumber = 0;
2875 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002876
Arun Menon906de572013-06-18 17:01:40 -07002877 }
2878 /*Component should support this port definition*/
2879 case OMX_IndexParamOtherInit: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002880 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x",
Arun Menon906de572013-06-18 17:01:40 -07002881 paramIndex);
2882 eRet =OMX_ErrorUnsupportedIndex;
2883 break;
2884 }
2885 case OMX_IndexParamStandardComponentRole: {
2886 OMX_PARAM_COMPONENTROLETYPE *comp_role;
2887 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
2888 comp_role->nVersion.nVersion = OMX_SPEC_VERSION;
2889 comp_role->nSize = sizeof(*comp_role);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002890
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002891 DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d",
Arun Menon906de572013-06-18 17:01:40 -07002892 paramIndex);
2893 strlcpy((char*)comp_role->cRole,(const char*)m_cRole,
2894 OMX_MAX_STRINGNAME_SIZE);
2895 break;
2896 }
2897 /* Added for parameter test */
2898 case OMX_IndexParamPriorityMgmt: {
Shalaj Jain273b3e02012-06-22 19:08:03 -07002899
Arun Menon906de572013-06-18 17:01:40 -07002900 OMX_PRIORITYMGMTTYPE *priorityMgmType =
2901 (OMX_PRIORITYMGMTTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002902 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt");
Arun Menon906de572013-06-18 17:01:40 -07002903 priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION;
2904 priorityMgmType->nSize = sizeof(priorityMgmType);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002905
Arun Menon906de572013-06-18 17:01:40 -07002906 break;
2907 }
2908 /* Added for parameter test */
2909 case OMX_IndexParamCompBufferSupplier: {
2910 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType =
2911 (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002912 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002913
Arun Menon906de572013-06-18 17:01:40 -07002914 bufferSupplierType->nSize = sizeof(bufferSupplierType);
2915 bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION;
2916 if (0 == bufferSupplierType->nPortIndex)
2917 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2918 else if (1 == bufferSupplierType->nPortIndex)
2919 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2920 else
2921 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002922
2923
Arun Menon906de572013-06-18 17:01:40 -07002924 break;
2925 }
2926 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002927 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x",
Arun Menon906de572013-06-18 17:01:40 -07002928 paramIndex);
2929 break;
2930 }
2931 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002932 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002933 paramIndex);
2934 break;
2935 }
2936 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002937 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002938 paramIndex);
2939 break;
2940 }
2941 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002942 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002943 paramIndex);
2944 break;
2945 }
2946 case OMX_IndexParamVideoProfileLevelQuerySupported: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002947 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07002948 OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType =
2949 (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData;
2950 eRet = get_supported_profile_level_for_1080p(profileLevelType);
2951 break;
2952 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002953#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07002954 case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002955 DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage");
Arun Menon906de572013-06-18 17:01:40 -07002956 GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData;
2957 if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07002958
Arun Menon906de572013-06-18 17:01:40 -07002959 if (secure_mode) {
2960 nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED |
2961 GRALLOC_USAGE_PRIVATE_UNCACHED);
2962 } else {
2963 nativeBuffersUsage->nUsage =
2964 (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP |
2965 GRALLOC_USAGE_PRIVATE_UNCACHED);
2966 }
2967 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002968 DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!");
Arun Menon906de572013-06-18 17:01:40 -07002969 eRet = OMX_ErrorBadParameter;
2970 }
2971 }
2972 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002973#endif
2974
Deva Ramasubramanian286a3582014-08-25 18:09:38 -07002975 case OMX_QcomIndexParamVideoProcessNotCodedVOP:
2976 {
2977 DEBUG_PRINT_LOW("get_parameter: OMX_QcomIndexParamVideoProcessNotCodedVOP");
2978 ((QOMX_ENABLETYPE *)paramData)->bEnable = (OMX_BOOL)!ignore_not_coded_vops;
2979 break;
2980 }
Arun Menon906de572013-06-18 17:01:40 -07002981 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002982 DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07002983 eRet =OMX_ErrorUnsupportedIndex;
2984 }
2985
Shalaj Jain273b3e02012-06-22 19:08:03 -07002986 }
2987
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002988 DEBUG_PRINT_LOW("get_parameter returning WxH(%d x %d) SxSH(%d x %d)",
Arun Menon906de572013-06-18 17:01:40 -07002989 drv_ctx.video_resolution.frame_width,
2990 drv_ctx.video_resolution.frame_height,
2991 drv_ctx.video_resolution.stride,
2992 drv_ctx.video_resolution.scan_lines);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002993
Arun Menon906de572013-06-18 17:01:40 -07002994 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002995}
2996
2997#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
2998OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data)
2999{
3000 DEBUG_PRINT_LOW("Inside use_android_native_buffer");
3001 OMX_ERRORTYPE eRet = OMX_ErrorNone;
3002 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data;
3003
Arun Menon906de572013-06-18 17:01:40 -07003004 if ((params == NULL) ||
3005 (params->nativeBuffer == NULL) ||
3006 (params->nativeBuffer->handle == NULL) ||
3007 !m_enable_android_native_buffers)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003008 return OMX_ErrorBadParameter;
3009 m_use_android_native_buffers = OMX_TRUE;
3010 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
3011 private_handle_t *handle = (private_handle_t *)nBuf->handle;
Arun Menon906de572013-06-18 17:01:40 -07003012 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 -07003013 OMX_U8 *buffer = NULL;
Arun Menon906de572013-06-18 17:01:40 -07003014 if (!secure_mode) {
3015 buffer = (OMX_U8*)mmap(0, handle->size,
Shalaj Jain273b3e02012-06-22 19:08:03 -07003016 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
Arun Menon906de572013-06-18 17:01:40 -07003017 if (buffer == MAP_FAILED) {
3018 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
3019 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003020 }
3021 }
3022 eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer);
3023 } else {
3024 eRet = OMX_ErrorBadParameter;
3025 }
3026 return eRet;
3027}
3028#endif
Praveen Chavancf924182013-12-06 23:16:23 -08003029
3030OMX_ERRORTYPE omx_vdec::enable_smoothstreaming() {
3031 struct v4l2_control control;
3032 struct v4l2_format fmt;
3033 control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER;
3034 control.value = 1;
3035 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3036 if (rc < 0) {
3037 DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver.");
3038 return OMX_ErrorHardware;
3039 }
3040 m_smoothstreaming_mode = true;
3041 return OMX_ErrorNone;
3042}
3043
Shalaj Jain273b3e02012-06-22 19:08:03 -07003044/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003045 FUNCTION
3046 omx_vdec::Setparameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07003047
Arun Menon906de572013-06-18 17:01:40 -07003048 DESCRIPTION
3049 OMX Set Parameter method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003050
Arun Menon906de572013-06-18 17:01:40 -07003051 PARAMETERS
3052 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003053
Arun Menon906de572013-06-18 17:01:40 -07003054 RETURN VALUE
3055 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003056
Arun Menon906de572013-06-18 17:01:40 -07003057 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003058OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003059 OMX_IN OMX_INDEXTYPE paramIndex,
3060 OMX_IN OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003061{
3062 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Praneeth Paladugu226667c2012-09-12 16:42:30 -07003063 int ret=0;
3064 struct v4l2_format fmt;
Arun Menon906de572013-06-18 17:01:40 -07003065 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003066 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003067 return OMX_ErrorInvalidState;
3068 }
Arun Menon906de572013-06-18 17:01:40 -07003069 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003070 DEBUG_PRINT_ERROR("Get Param in Invalid paramData");
Arun Menon906de572013-06-18 17:01:40 -07003071 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003072 }
Arun Menon906de572013-06-18 17:01:40 -07003073 if ((m_state != OMX_StateLoaded) &&
3074 BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) &&
3075 (m_out_bEnabled == OMX_TRUE) &&
3076 BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) &&
3077 (m_inp_bEnabled == OMX_TRUE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003078 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003079 return OMX_ErrorIncorrectStateOperation;
3080 }
Arun Menon906de572013-06-18 17:01:40 -07003081 switch ((unsigned long)paramIndex) {
3082 case OMX_IndexParamPortDefinition: {
3083 OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
3084 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
3085 //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has
3086 //been called.
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003087 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d",
Arun Menon906de572013-06-18 17:01:40 -07003088 (int)portDefn->format.video.nFrameHeight,
3089 (int)portDefn->format.video.nFrameWidth);
3090 if (OMX_DirOutput == portDefn->eDir) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003091 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port");
Pushkaraj Patil41588352014-02-25 20:51:34 +05303092 bool port_format_changed = false;
Arun Menon906de572013-06-18 17:01:40 -07003093 m_display_id = portDefn->format.video.pNativeWindow;
3094 unsigned int buffer_size;
Praveen Chavane78460c2013-12-06 23:16:04 -08003095 /* update output port resolution with client supplied dimensions
3096 in case scaling is enabled, else it follows input resolution set
3097 */
3098 if (is_down_scalar_enabled) {
3099 DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n",
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003100 portDefn->format.video.nFrameWidth,
3101 portDefn->format.video.nFrameHeight);
3102 if (portDefn->format.video.nFrameHeight != 0x0 &&
3103 portDefn->format.video.nFrameWidth != 0x0) {
Pushkaraj Patil41588352014-02-25 20:51:34 +05303104 memset(&fmt, 0x0, sizeof(struct v4l2_format));
3105 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3106 fmt.fmt.pix_mp.pixelformat = capture_capability;
3107 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
3108 if (ret) {
3109 DEBUG_PRINT_ERROR("Get Resolution failed");
3110 eRet = OMX_ErrorHardware;
3111 break;
3112 }
3113 if ((portDefn->format.video.nFrameHeight != (int)fmt.fmt.pix_mp.height) ||
3114 (portDefn->format.video.nFrameWidth != (int)fmt.fmt.pix_mp.width)) {
3115 port_format_changed = true;
3116 }
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003117 update_resolution(portDefn->format.video.nFrameWidth,
3118 portDefn->format.video.nFrameHeight,
3119 portDefn->format.video.nFrameWidth,
3120 portDefn->format.video.nFrameHeight);
Pushkaraj Patil41588352014-02-25 20:51:34 +05303121
3122 /* set crop info */
3123 rectangle.nLeft = 0;
3124 rectangle.nTop = 0;
3125 rectangle.nWidth = portDefn->format.video.nFrameWidth;
3126 rectangle.nHeight = portDefn->format.video.nFrameHeight;
3127
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003128 eRet = is_video_session_supported();
3129 if (eRet)
3130 break;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303131 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003132 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3133 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3134 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3135 fmt.fmt.pix_mp.pixelformat = capture_capability;
3136 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);
3137 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3138 if (ret) {
3139 DEBUG_PRINT_ERROR("\n Set Resolution failed");
3140 eRet = OMX_ErrorUnsupportedSetting;
3141 } else
3142 eRet = get_buffer_req(&drv_ctx.op_buf);
3143 }
Praveen Chavane78460c2013-12-06 23:16:04 -08003144 }
Arun Menon906de572013-06-18 17:01:40 -07003145 if (!client_buffers.get_buffer_req(buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003146 DEBUG_PRINT_ERROR("Error in getting buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07003147 eRet = OMX_ErrorBadParameter;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303148 } else if (!port_format_changed) {
Arun Menon906de572013-06-18 17:01:40 -07003149 if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount &&
3150 portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) {
3151 drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual;
3152 drv_ctx.op_buf.buffer_size = portDefn->nBufferSize;
3153 drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount;
3154 drv_ctx.extradata_info.size = drv_ctx.extradata_info.count *
3155 drv_ctx.extradata_info.buffer_size;
3156 eRet = set_buffer_req(&drv_ctx.op_buf);
3157 if (eRet == OMX_ErrorNone)
3158 m_port_def = *portDefn;
3159 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003160 DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003161 drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size,
3162 portDefn->nBufferCountActual, portDefn->nBufferSize);
3163 eRet = OMX_ErrorBadParameter;
3164 }
3165 }
3166 } else if (OMX_DirInput == portDefn->eDir) {
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003167 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port");
Arun Menon906de572013-06-18 17:01:40 -07003168 bool port_format_changed = false;
3169 if ((portDefn->format.video.xFramerate >> 16) > 0 &&
3170 (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) {
3171 // Frame rate only should be set if this is a "known value" or to
3172 // activate ts prediction logic (arbitrary mode only) sending input
3173 // timestamps with max value (LLONG_MAX).
3174 DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu",
3175 portDefn->format.video.xFramerate >> 16);
3176 Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator,
3177 drv_ctx.frame_rate.fps_denominator);
3178 if (!drv_ctx.frame_rate.fps_numerator) {
3179 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
3180 drv_ctx.frame_rate.fps_numerator = 30;
3181 }
3182 if (drv_ctx.frame_rate.fps_denominator)
3183 drv_ctx.frame_rate.fps_numerator = (int)
3184 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
3185 drv_ctx.frame_rate.fps_denominator = 1;
3186 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
3187 drv_ctx.frame_rate.fps_numerator;
3188 DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)",
3189 frm_int, drv_ctx.frame_rate.fps_numerator /
3190 (float)drv_ctx.frame_rate.fps_denominator);
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003191
3192 struct v4l2_outputparm oparm;
3193 /*XXX: we're providing timing info as seconds per frame rather than frames
3194 * per second.*/
3195 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
3196 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
3197
3198 struct v4l2_streamparm sparm;
3199 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
3200 sparm.parm.output = oparm;
3201 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
3202 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, performance might be affected");
3203 eRet = OMX_ErrorHardware;
3204 break;
3205 }
Arun Menon906de572013-06-18 17:01:40 -07003206 }
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003207
Arun Menon906de572013-06-18 17:01:40 -07003208 if (drv_ctx.video_resolution.frame_height !=
3209 portDefn->format.video.nFrameHeight ||
3210 drv_ctx.video_resolution.frame_width !=
3211 portDefn->format.video.nFrameWidth) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003212 DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003213 portDefn->format.video.nFrameWidth,
3214 portDefn->format.video.nFrameHeight);
3215 port_format_changed = true;
Praveen Chavancf924182013-12-06 23:16:23 -08003216 OMX_U32 frameWidth = portDefn->format.video.nFrameWidth;
3217 OMX_U32 frameHeight = portDefn->format.video.nFrameHeight;
3218 if (frameHeight != 0x0 && frameWidth != 0x0) {
3219 if (m_smoothstreaming_mode &&
3220 ((frameWidth * frameHeight) <
3221 (m_smoothstreaming_width * m_smoothstreaming_height))) {
3222 frameWidth = m_smoothstreaming_width;
3223 frameHeight = m_smoothstreaming_height;
3224 DEBUG_PRINT_LOW("NOTE: Setting resolution %lu x %lu for adaptive-playback/smooth-streaming",
3225 frameWidth, frameHeight);
3226 }
3227 update_resolution(frameWidth, frameHeight,
3228 frameWidth, frameHeight);
Arun Menon906de572013-06-18 17:01:40 -07003229 eRet = is_video_session_supported();
3230 if (eRet)
3231 break;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303232 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Arun Menon906de572013-06-18 17:01:40 -07003233 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
3234 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3235 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3236 fmt.fmt.pix_mp.pixelformat = output_capability;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003237 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 -07003238 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3239 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003240 DEBUG_PRINT_ERROR("Set Resolution failed");
Arun Menon906de572013-06-18 17:01:40 -07003241 eRet = OMX_ErrorUnsupportedSetting;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303242 } else {
3243 if (!is_down_scalar_enabled)
3244 eRet = get_buffer_req(&drv_ctx.op_buf);
3245 }
Arun Menon906de572013-06-18 17:01:40 -07003246 }
3247 }
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303248 if (m_custom_buffersize.input_buffersize
3249 && (portDefn->nBufferSize > m_custom_buffersize.input_buffersize)) {
3250 DEBUG_PRINT_ERROR("ERROR: Custom buffer size set by client: %d, trying to set: %d",
3251 m_custom_buffersize.input_buffersize, portDefn->nBufferSize);
3252 eRet = OMX_ErrorBadParameter;
3253 break;
3254 }
Arun Menon906de572013-06-18 17:01:40 -07003255 if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount
3256 || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) {
3257 port_format_changed = true;
3258 vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf;
3259 drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual;
3260 drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) &
3261 (~(buffer_prop->alignment - 1));
3262 eRet = set_buffer_req(buffer_prop);
3263 }
3264 if (false == port_format_changed) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003265 DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003266 drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size,
3267 portDefn->nBufferCountActual, portDefn->nBufferSize);
3268 eRet = OMX_ErrorBadParameter;
3269 }
3270 } else if (portDefn->eDir == OMX_DirMax) {
3271 DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d",
3272 (int)portDefn->nPortIndex);
3273 eRet = OMX_ErrorBadPortIndex;
3274 }
3275 }
3276 break;
3277 case OMX_IndexParamVideoPortFormat: {
3278 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
3279 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
3280 int ret=0;
3281 struct v4l2_format fmt;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003282 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d",
Arun Menon906de572013-06-18 17:01:40 -07003283 portFmt->eColorFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003284
Arun Menon906de572013-06-18 17:01:40 -07003285 if (1 == portFmt->nPortIndex) {
3286 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3287 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3288 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3289 fmt.fmt.pix_mp.pixelformat = capture_capability;
3290 enum vdec_output_fromat op_format;
3291 if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE)
3292 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) ||
Praveen Chavandb7776f2014-02-06 18:17:25 -08003293 (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar) ||
3294 (portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar))
Arun Menon906de572013-06-18 17:01:40 -07003295 op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12;
Arun Menon906de572013-06-18 17:01:40 -07003296 else
3297 eRet = OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003298
Arun Menon906de572013-06-18 17:01:40 -07003299 if (eRet == OMX_ErrorNone) {
3300 drv_ctx.output_format = op_format;
3301 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3302 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003303 DEBUG_PRINT_ERROR("Set output format failed");
Arun Menon906de572013-06-18 17:01:40 -07003304 eRet = OMX_ErrorUnsupportedSetting;
3305 /*TODO: How to handle this case */
3306 } else {
3307 eRet = get_buffer_req(&drv_ctx.op_buf);
3308 }
3309 }
3310 if (eRet == OMX_ErrorNone) {
3311 if (!client_buffers.set_color_format(portFmt->eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003312 DEBUG_PRINT_ERROR("Set color format failed");
Arun Menon906de572013-06-18 17:01:40 -07003313 eRet = OMX_ErrorBadParameter;
3314 }
3315 }
3316 }
3317 }
3318 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003319
Arun Menon906de572013-06-18 17:01:40 -07003320 case OMX_QcomIndexPortDefn: {
3321 OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt =
3322 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003323 DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu",
Arun Menon906de572013-06-18 17:01:40 -07003324 portFmt->nFramePackingFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003325
Arun Menon906de572013-06-18 17:01:40 -07003326 /* Input port */
3327 if (portFmt->nPortIndex == 0) {
3328 if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) {
3329 if (secure_mode) {
3330 arbitrary_bytes = false;
3331 DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session");
3332 eRet = OMX_ErrorUnsupportedSetting;
3333 } else {
3334 arbitrary_bytes = true;
3335 }
3336 } else if (portFmt->nFramePackingFormat ==
3337 OMX_QCOM_FramePacking_OnlyOneCompleteFrame) {
3338 arbitrary_bytes = false;
3339 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003340 DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu",
Arun Menon906de572013-06-18 17:01:40 -07003341 portFmt->nFramePackingFormat);
3342 eRet = OMX_ErrorUnsupportedSetting;
3343 }
3344 } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003345 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003346 if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid &&
3347 portFmt->nMemRegion < OMX_QCOM_MemRegionMax) &&
3348 portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) {
3349 m_out_mem_region_smi = OMX_TRUE;
3350 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003351 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003352 m_use_output_pmem = OMX_TRUE;
3353 }
3354 }
3355 }
3356 }
3357 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003358
Arun Menon906de572013-06-18 17:01:40 -07003359 case OMX_IndexParamStandardComponentRole: {
3360 OMX_PARAM_COMPONENTROLETYPE *comp_role;
3361 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003362 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s",
Arun Menon906de572013-06-18 17:01:40 -07003363 comp_role->cRole);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003364
Arun Menon906de572013-06-18 17:01:40 -07003365 if ((m_state == OMX_StateLoaded)&&
3366 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
3367 DEBUG_PRINT_LOW("Set Parameter called in valid state");
3368 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003369 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003370 return OMX_ErrorIncorrectStateOperation;
3371 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003372
Arun Menon906de572013-06-18 17:01:40 -07003373 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3374 if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3375 strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
3376 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003377 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003378 eRet =OMX_ErrorUnsupportedSetting;
3379 }
3380 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3381 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3382 strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
3383 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003384 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003385 eRet = OMX_ErrorUnsupportedSetting;
3386 }
3387 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3388 if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3389 strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
3390 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003391 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003392 eRet =OMX_ErrorUnsupportedSetting;
3393 }
3394 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3395 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3396 strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
3397 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003398 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003399 eRet = OMX_ErrorUnsupportedSetting;
3400 }
3401 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
Deva Ramasubramanianba4534b2013-12-17 15:52:37 -08003402 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311", OMX_MAX_STRINGNAME_SIZE)) ||
3403 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4", OMX_MAX_STRINGNAME_SIZE))
Arun Menon906de572013-06-18 17:01:40 -07003404 ) {
3405 if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) {
3406 strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
3407 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003408 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003409 eRet =OMX_ErrorUnsupportedSetting;
3410 }
3411 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
3412 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
3413 ) {
3414 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) {
3415 strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
3416 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003417 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003418 eRet =OMX_ErrorUnsupportedSetting;
3419 }
3420 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
3421 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) ||
3422 (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) {
3423 strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
3424 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003425 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003426 eRet = OMX_ErrorUnsupportedSetting;
3427 }
3428 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003429 DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07003430 eRet = OMX_ErrorInvalidComponentName;
3431 }
3432 break;
3433 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003434
Arun Menon906de572013-06-18 17:01:40 -07003435 case OMX_IndexParamPriorityMgmt: {
3436 if (m_state != OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003437 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003438 return OMX_ErrorIncorrectStateOperation;
3439 }
3440 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003441 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu",
Arun Menon906de572013-06-18 17:01:40 -07003442 priorityMgmtype->nGroupID);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003443
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003444 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu",
Arun Menon906de572013-06-18 17:01:40 -07003445 priorityMgmtype->nGroupPriority);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003446
Arun Menon906de572013-06-18 17:01:40 -07003447 m_priority_mgm.nGroupID = priorityMgmtype->nGroupID;
3448 m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003449
Arun Menon906de572013-06-18 17:01:40 -07003450 break;
3451 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003452
Arun Menon906de572013-06-18 17:01:40 -07003453 case OMX_IndexParamCompBufferSupplier: {
3454 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003455 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d",
Arun Menon906de572013-06-18 17:01:40 -07003456 bufferSupplierType->eBufferSupplier);
3457 if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
3458 m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003459
Arun Menon906de572013-06-18 17:01:40 -07003460 else
Shalaj Jain273b3e02012-06-22 19:08:03 -07003461
Arun Menon906de572013-06-18 17:01:40 -07003462 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003463
Arun Menon906de572013-06-18 17:01:40 -07003464 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003465
Arun Menon906de572013-06-18 17:01:40 -07003466 }
3467 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003468 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d",
Arun Menon906de572013-06-18 17:01:40 -07003469 paramIndex);
3470 break;
3471 }
3472 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003473 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d",
Arun Menon906de572013-06-18 17:01:40 -07003474 paramIndex);
3475 break;
3476 }
3477 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003478 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d",
Arun Menon906de572013-06-18 17:01:40 -07003479 paramIndex);
3480 break;
3481 }
3482 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003483 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d",
Arun Menon906de572013-06-18 17:01:40 -07003484 paramIndex);
3485 break;
3486 }
3487 case OMX_QcomIndexParamVideoDecoderPictureOrder: {
3488 QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder =
3489 (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData;
3490 struct v4l2_control control;
3491 int pic_order,rc=0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003492 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d",
Arun Menon906de572013-06-18 17:01:40 -07003493 pictureOrder->eOutputPictureOrder);
3494 if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) {
3495 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
3496 } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) {
3497 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3498 time_stamp_dts.set_timestamp_reorder_mode(false);
3499 } else
3500 eRet = OMX_ErrorBadParameter;
3501 if (eRet == OMX_ErrorNone) {
3502 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3503 control.value = pic_order;
3504 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3505 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003506 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003507 eRet = OMX_ErrorUnsupportedSetting;
3508 }
3509 }
3510 break;
3511 }
3512 case OMX_QcomIndexParamConcealMBMapExtraData:
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303513 eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false,
3514 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3515 break;
3516 case OMX_QcomIndexParamFrameInfoExtraData:
3517 eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false,
3518 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3519 break;
Arun Menon906de572013-06-18 17:01:40 -07003520 case OMX_QcomIndexParamInterlaceExtraData:
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303521 eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false,
3522 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3523 break;
Arun Menon906de572013-06-18 17:01:40 -07003524 case OMX_QcomIndexParamH264TimeInfo:
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303525 eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false,
3526 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3527 break;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05303528 case OMX_QcomIndexParamVideoFramePackingExtradata:
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303529 eRet = enable_extradata(OMX_FRAMEPACK_EXTRADATA, false,
3530 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3531 break;
3532 case OMX_QcomIndexParamVideoQPExtraData:
3533 eRet = enable_extradata(OMX_QP_EXTRADATA, false,
3534 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3535 break;
3536 case OMX_QcomIndexParamVideoInputBitsInfoExtraData:
3537 eRet = enable_extradata(OMX_BITSINFO_EXTRADATA, false,
3538 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3539 break;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05303540 case OMX_QcomIndexEnableExtnUserData:
3541 eRet = enable_extradata(OMX_EXTNUSER_EXTRADATA, false,
3542 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3543 break;
Arun Menon906de572013-06-18 17:01:40 -07003544 case OMX_QcomIndexParamVideoDivx: {
3545 QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData;
3546 }
3547 break;
3548 case OMX_QcomIndexPlatformPvt: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003549 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003550 OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData;
3551 if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
3552 DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type);
3553 eRet = OMX_ErrorUnsupportedSetting;
3554 } else {
3555 m_out_pvt_entry_pmem = OMX_TRUE;
3556 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003557 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003558 m_use_output_pmem = OMX_TRUE;
3559 }
3560 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003561
Arun Menon906de572013-06-18 17:01:40 -07003562 }
3563 break;
3564 case OMX_QcomIndexParamVideoSyncFrameDecodingMode: {
3565 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode");
3566 DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode");
3567 struct v4l2_control control;
3568 int rc;
3569 drv_ctx.idr_only_decoding = 1;
3570 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3571 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3572 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3573 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003574 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003575 eRet = OMX_ErrorUnsupportedSetting;
3576 } else {
3577 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE;
3578 control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE;
3579 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3580 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003581 DEBUG_PRINT_ERROR("Sync frame setting failed");
Arun Menon906de572013-06-18 17:01:40 -07003582 eRet = OMX_ErrorUnsupportedSetting;
3583 }
3584 /*Setting sync frame decoding on driver might change buffer
3585 * requirements so update them here*/
3586 if (get_buffer_req(&drv_ctx.ip_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003587 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer i/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003588 eRet = OMX_ErrorUnsupportedSetting;
3589 }
3590 if (get_buffer_req(&drv_ctx.op_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003591 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer o/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003592 eRet = OMX_ErrorUnsupportedSetting;
3593 }
3594 }
3595 }
3596 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003597
Arun Menon906de572013-06-18 17:01:40 -07003598 case OMX_QcomIndexParamIndexExtraDataType: {
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303599 QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData;
3600 if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) &&
3601 (extradataIndexType->bEnabled == OMX_TRUE) &&
3602 (extradataIndexType->nPortIndex == 1)) {
3603 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming");
3604 eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled);
3605 }
3606 }
Arun Menon906de572013-06-18 17:01:40 -07003607 break;
3608 case OMX_QcomIndexParamEnableSmoothStreaming: {
Arun Menonc821d8a2013-06-15 10:03:29 -07003609#ifndef SMOOTH_STREAMING_DISABLED
Praveen Chavancf924182013-12-06 23:16:23 -08003610 eRet = enable_smoothstreaming();
Arun Menonbc0922f2013-06-24 13:02:15 -07003611#else
Arun Menon906de572013-06-18 17:01:40 -07003612 eRet = OMX_ErrorUnsupportedSetting;
Arun Menonc821d8a2013-06-15 10:03:29 -07003613#endif
Arun Menon906de572013-06-18 17:01:40 -07003614 }
3615 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003616#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07003617 /* Need to allow following two set_parameters even in Idle
3618 * state. This is ANDROID architecture which is not in sync
3619 * with openmax standard. */
3620 case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: {
3621 EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData;
3622 if (enableNativeBuffers) {
3623 m_enable_android_native_buffers = enableNativeBuffers->enable;
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07003624 }
3625 if (m_enable_android_native_buffers) {
3626 // Use the most-preferred-native-color-format as surface-mode is hinted here
3627 if(!client_buffers.set_color_format(getPreferredColorFormatDefaultMode(0))) {
3628 DEBUG_PRINT_ERROR("Failed to set native color format!");
3629 eRet = OMX_ErrorUnsupportedSetting;
3630 }
Arun Menon906de572013-06-18 17:01:40 -07003631 }
3632 }
3633 break;
3634 case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: {
3635 eRet = use_android_native_buffer(hComp, paramData);
3636 }
3637 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003638#endif
Arun Menon906de572013-06-18 17:01:40 -07003639 case OMX_QcomIndexParamEnableTimeStampReorder: {
3640 QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData;
3641 if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) {
3642 if (reorder->bEnable == OMX_TRUE) {
3643 frm_int =0;
3644 time_stamp_dts.set_timestamp_reorder_mode(true);
3645 } else
3646 time_stamp_dts.set_timestamp_reorder_mode(false);
3647 } else {
3648 time_stamp_dts.set_timestamp_reorder_mode(false);
3649 if (reorder->bEnable == OMX_TRUE) {
3650 eRet = OMX_ErrorUnsupportedSetting;
3651 }
3652 }
3653 }
3654 break;
3655 case OMX_IndexParamVideoProfileLevelCurrent: {
3656 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam =
3657 (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
3658 if (pParam) {
3659 m_profile_lvl.eProfile = pParam->eProfile;
3660 m_profile_lvl.eLevel = pParam->eLevel;
3661 }
3662 break;
Arun Menon888aa852013-05-30 11:24:42 -07003663
Arun Menon906de572013-06-18 17:01:40 -07003664 }
Arun Menone5652482013-08-04 13:33:05 -07003665 case OMX_QcomIndexParamVideoMetaBufferMode:
3666 {
3667 StoreMetaDataInBuffersParams *metabuffer =
3668 (StoreMetaDataInBuffersParams *)paramData;
3669 if (!metabuffer) {
3670 DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer);
3671 eRet = OMX_ErrorBadParameter;
3672 break;
3673 }
3674 if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
3675 //set property dynamic buffer mode to driver.
3676 struct v4l2_control control;
3677 struct v4l2_format fmt;
3678 control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT;
3679 if (metabuffer->bStoreMetaData == true) {
3680 control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC;
3681 } else {
3682 control.value = V4L2_MPEG_VIDC_VIDEO_STATIC;
3683 }
3684 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3685 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003686 DEBUG_PRINT_HIGH("%s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003687 (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic");
Arun Menonbdb80b02013-08-12 17:45:54 -07003688 dynamic_buf_mode = metabuffer->bStoreMetaData;
Arun Menone5652482013-08-04 13:33:05 -07003689 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003690 DEBUG_PRINT_ERROR("Failed to %s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003691 (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic");
3692 eRet = OMX_ErrorUnsupportedSetting;
3693 }
3694 } else {
3695 DEBUG_PRINT_ERROR(
Praveen Chavancf924182013-12-06 23:16:23 -08003696 "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %lu",
Arun Menone5652482013-08-04 13:33:05 -07003697 metabuffer->nPortIndex);
3698 eRet = OMX_ErrorUnsupportedSetting;
3699 }
3700 break;
3701 }
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003702 case OMX_QcomIndexParamVideoDownScalar: {
3703 QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData;
3704 struct v4l2_control control;
3705 int rc;
3706 if (pParam) {
3707 is_down_scalar_enabled = pParam->bEnable;
3708 if (is_down_scalar_enabled) {
3709 control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE;
3710 control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY;
3711 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n",
3712 pParam->bEnable);
3713 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3714 if (rc < 0) {
3715 DEBUG_PRINT_ERROR("Failed to set down scalar on driver.");
3716 eRet = OMX_ErrorUnsupportedSetting;
3717 }
3718 control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO;
3719 control.value = 1;
3720 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3721 if (rc < 0) {
3722 DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver.");
3723 eRet = OMX_ErrorUnsupportedSetting;
3724 }
3725 }
3726 }
3727 break;
3728 }
Praveen Chavancf924182013-12-06 23:16:23 -08003729#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
3730 case OMX_QcomIndexParamVideoAdaptivePlaybackMode:
3731 {
3732 DEBUG_PRINT_LOW("set_parameter: OMX_GoogleAndroidIndexPrepareForAdaptivePlayback");
3733 PrepareForAdaptivePlaybackParams* pParams =
3734 (PrepareForAdaptivePlaybackParams *) paramData;
3735 if (pParams->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
3736 if (!pParams->bEnable) {
3737 return OMX_ErrorNone;
3738 }
Deepak Vermaa2efdb12013-12-26 12:30:05 +05303739 if (pParams->nMaxFrameWidth > maxSmoothStreamingWidth
3740 || pParams->nMaxFrameHeight > maxSmoothStreamingHeight) {
Praveen Chavancf924182013-12-06 23:16:23 -08003741 DEBUG_PRINT_ERROR(
3742 "Adaptive playback request exceeds max supported resolution : [%lu x %lu] vs [%lu x %lu]",
3743 pParams->nMaxFrameWidth, pParams->nMaxFrameHeight,
Deepak Vermaa2efdb12013-12-26 12:30:05 +05303744 maxSmoothStreamingWidth, maxSmoothStreamingHeight);
Praveen Chavancf924182013-12-06 23:16:23 -08003745 eRet = OMX_ErrorBadParameter;
3746 } else {
Arun Menon1fc764f2014-04-17 15:41:27 -07003747 eRet = enable_adaptive_playback(pParams->nMaxFrameWidth, pParams->nMaxFrameHeight);
3748 }
Praveen Chavancf924182013-12-06 23:16:23 -08003749 } else {
3750 DEBUG_PRINT_ERROR(
3751 "Prepare for adaptive playback supported only on output port");
3752 eRet = OMX_ErrorBadParameter;
3753 }
3754 break;
3755 }
3756
3757#endif
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303758 case OMX_QcomIndexParamVideoCustomBufferSize:
3759 {
3760 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoCustomBufferSize");
3761 QOMX_VIDEO_CUSTOM_BUFFERSIZE* pParam = (QOMX_VIDEO_CUSTOM_BUFFERSIZE*)paramData;
3762 if (pParam->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) {
3763 struct v4l2_control control;
3764 control.id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT;
3765 control.value = pParam->nBufferSize;
3766 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
3767 DEBUG_PRINT_ERROR("Failed to set input buffer size");
3768 eRet = OMX_ErrorUnsupportedSetting;
3769 } else {
3770 eRet = get_buffer_req(&drv_ctx.ip_buf);
3771 if (eRet == OMX_ErrorNone) {
3772 m_custom_buffersize.input_buffersize = drv_ctx.ip_buf.buffer_size;
3773 DEBUG_PRINT_HIGH("Successfully set custom input buffer size = %d",
3774 m_custom_buffersize.input_buffersize);
3775 } else {
3776 DEBUG_PRINT_ERROR("Failed to get buffer requirement");
3777 }
3778 }
3779 } else {
3780 DEBUG_PRINT_ERROR("ERROR: Custom buffer size in not supported on output port");
3781 eRet = OMX_ErrorBadParameter;
3782 }
3783 break;
3784 }
Deva Ramasubramanian286a3582014-08-25 18:09:38 -07003785 case OMX_QcomIndexParamVideoProcessNotCodedVOP:
3786 {
3787 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoProcessNotCodedVOP");
3788 ignore_not_coded_vops = !((QOMX_ENABLETYPE *)paramData)->bEnable;
3789 break;
3790 }
Arun Menon906de572013-06-18 17:01:40 -07003791 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003792 DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003793 eRet = OMX_ErrorUnsupportedIndex;
3794 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003795 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08003796 if (eRet != OMX_ErrorNone)
3797 DEBUG_PRINT_ERROR("set_parameter: Error: 0x%x, setting param 0x%x", eRet, paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003798 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003799}
3800
3801/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003802 FUNCTION
3803 omx_vdec::GetConfig
Shalaj Jain273b3e02012-06-22 19:08:03 -07003804
Arun Menon906de572013-06-18 17:01:40 -07003805 DESCRIPTION
3806 OMX Get Config Method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003807
Arun Menon906de572013-06-18 17:01:40 -07003808 PARAMETERS
3809 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003810
Arun Menon906de572013-06-18 17:01:40 -07003811 RETURN VALUE
3812 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003813
Arun Menon906de572013-06-18 17:01:40 -07003814 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003815OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003816 OMX_IN OMX_INDEXTYPE configIndex,
3817 OMX_INOUT OMX_PTR configData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003818{
Arun Menon906de572013-06-18 17:01:40 -07003819 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003820
Arun Menon906de572013-06-18 17:01:40 -07003821 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003822 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003823 return OMX_ErrorInvalidState;
3824 }
Arun Menon906de572013-06-18 17:01:40 -07003825
3826 switch ((unsigned long)configIndex) {
3827 case OMX_QcomIndexConfigInterlaced: {
3828 OMX_QCOM_CONFIG_INTERLACETYPE *configFmt =
3829 (OMX_QCOM_CONFIG_INTERLACETYPE *) configData;
3830 if (configFmt->nPortIndex == 1) {
3831 if (configFmt->nIndex == 0) {
3832 configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive;
3833 } else if (configFmt->nIndex == 1) {
3834 configFmt->eInterlaceType =
3835 OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
3836 } else if (configFmt->nIndex == 2) {
3837 configFmt->eInterlaceType =
3838 OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
3839 } else {
3840 DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003841 " NoMore Interlaced formats");
Arun Menon906de572013-06-18 17:01:40 -07003842 eRet = OMX_ErrorNoMore;
3843 }
3844
3845 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003846 DEBUG_PRINT_ERROR("get_config: Bad port index %d queried on only o/p port",
Arun Menon906de572013-06-18 17:01:40 -07003847 (int)configFmt->nPortIndex);
3848 eRet = OMX_ErrorBadPortIndex;
3849 }
3850 break;
3851 }
3852 case OMX_QcomIndexQueryNumberOfVideoDecInstance: {
3853 QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances =
3854 (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData;
3855 decoderinstances->nNumOfInstances = 16;
3856 /*TODO: How to handle this case */
3857 break;
3858 }
3859 case OMX_QcomIndexConfigVideoFramePackingArrangement: {
3860 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
3861 OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
3862 (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05303863 memcpy(configFmt, &m_frame_pack_arrangement,
3864 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
Arun Menon906de572013-06-18 17:01:40 -07003865 } else {
3866 DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs");
3867 }
3868 break;
3869 }
3870 case OMX_IndexConfigCommonOutputCrop: {
3871 OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData;
3872 memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE));
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05303873 DEBUG_PRINT_HIGH("get_config: crop info: L: %u, T: %u, R: %u, B: %u",
3874 rectangle.nLeft, rectangle.nTop,
3875 rectangle.nWidth, rectangle.nHeight);
Arun Menon906de572013-06-18 17:01:40 -07003876 break;
3877 }
3878 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003879 DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex);
Arun Menon906de572013-06-18 17:01:40 -07003880 eRet = OMX_ErrorBadParameter;
3881 }
3882
Shalaj Jain273b3e02012-06-22 19:08:03 -07003883 }
Arun Menon906de572013-06-18 17:01:40 -07003884
3885 return eRet;
3886}
3887
3888/* ======================================================================
3889 FUNCTION
3890 omx_vdec::SetConfig
3891
3892 DESCRIPTION
3893 OMX Set Config method implementation
3894
3895 PARAMETERS
3896 <TBD>.
3897
3898 RETURN VALUE
3899 OMX Error None if successful.
3900 ========================================================================== */
3901OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp,
3902 OMX_IN OMX_INDEXTYPE configIndex,
3903 OMX_IN OMX_PTR configData)
3904{
3905 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003906 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003907 return OMX_ErrorInvalidState;
3908 }
3909
3910 OMX_ERRORTYPE ret = OMX_ErrorNone;
3911 OMX_VIDEO_CONFIG_NALSIZE *pNal;
3912
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003913 DEBUG_PRINT_LOW("Set Config Called");
Arun Menon906de572013-06-18 17:01:40 -07003914
3915 if (configIndex == (OMX_INDEXTYPE)OMX_IndexVendorVideoExtraData) {
3916 OMX_VENDOR_EXTRADATATYPE *config = (OMX_VENDOR_EXTRADATATYPE *) configData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003917 DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData called");
Arun Menon906de572013-06-18 17:01:40 -07003918 if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc")) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003919 DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData AVC");
Arun Menon906de572013-06-18 17:01:40 -07003920 OMX_U32 extra_size;
3921 // Parsing done here for the AVC atom is definitely not generic
3922 // Currently this piece of code is working, but certainly
3923 // not tested with all .mp4 files.
3924 // Incase of failure, we might need to revisit this
3925 // for a generic piece of code.
3926
3927 // Retrieve size of NAL length field
3928 // byte #4 contains the size of NAL lenght field
3929 nal_length = (config->pData[4] & 0x03) + 1;
3930
3931 extra_size = 0;
3932 if (nal_length > 2) {
3933 /* Presently we assume that only one SPS and one PPS in AvC1 Atom */
3934 extra_size = (nal_length - 2) * 2;
3935 }
3936
3937 // SPS starts from byte #6
3938 OMX_U8 *pSrcBuf = (OMX_U8 *) (&config->pData[6]);
3939 OMX_U8 *pDestBuf;
3940 m_vendor_config.nPortIndex = config->nPortIndex;
3941
3942 // minus 6 --> SPS starts from byte #6
3943 // minus 1 --> picture param set byte to be ignored from avcatom
3944 m_vendor_config.nDataSize = config->nDataSize - 6 - 1 + extra_size;
3945 m_vendor_config.pData = (OMX_U8 *) malloc(m_vendor_config.nDataSize);
3946 OMX_U32 len;
3947 OMX_U8 index = 0;
3948 // case where SPS+PPS is sent as part of set_config
3949 pDestBuf = m_vendor_config.pData;
3950
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003951 DEBUG_PRINT_LOW("Rxd SPS+PPS nPortIndex[%lu] len[%lu] data[%p]",
Arun Menon906de572013-06-18 17:01:40 -07003952 m_vendor_config.nPortIndex,
3953 m_vendor_config.nDataSize,
3954 m_vendor_config.pData);
3955 while (index < 2) {
3956 uint8 *psize;
3957 len = *pSrcBuf;
3958 len = len << 8;
3959 len |= *(pSrcBuf + 1);
3960 psize = (uint8 *) & len;
3961 memcpy(pDestBuf + nal_length, pSrcBuf + 2,len);
3962 for (unsigned int i = 0; i < nal_length; i++) {
3963 pDestBuf[i] = psize[nal_length - 1 - i];
3964 }
3965 //memcpy(pDestBuf,pSrcBuf,(len+2));
3966 pDestBuf += len + nal_length;
3967 pSrcBuf += len + 2;
3968 index++;
3969 pSrcBuf++; // skip picture param set
3970 len = 0;
3971 }
3972 } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4") ||
3973 !strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2")) {
3974 m_vendor_config.nPortIndex = config->nPortIndex;
3975 m_vendor_config.nDataSize = config->nDataSize;
3976 m_vendor_config.pData = (OMX_U8 *) malloc((config->nDataSize));
3977 memcpy(m_vendor_config.pData, config->pData,config->nDataSize);
3978 } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1")) {
3979 if (m_vendor_config.pData) {
3980 free(m_vendor_config.pData);
3981 m_vendor_config.pData = NULL;
3982 m_vendor_config.nDataSize = 0;
3983 }
3984
3985 if (((*((OMX_U32 *) config->pData)) &
3986 VC1_SP_MP_START_CODE_MASK) ==
3987 VC1_SP_MP_START_CODE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003988 DEBUG_PRINT_LOW("set_config - VC1 simple/main profile");
Arun Menon906de572013-06-18 17:01:40 -07003989 m_vendor_config.nPortIndex = config->nPortIndex;
3990 m_vendor_config.nDataSize = config->nDataSize;
3991 m_vendor_config.pData =
3992 (OMX_U8 *) malloc(config->nDataSize);
3993 memcpy(m_vendor_config.pData, config->pData,
3994 config->nDataSize);
3995 m_vc1_profile = VC1_SP_MP_RCV;
3996 } else if (*((OMX_U32 *) config->pData) == VC1_AP_SEQ_START_CODE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003997 DEBUG_PRINT_LOW("set_config - VC1 Advance profile");
Arun Menon906de572013-06-18 17:01:40 -07003998 m_vendor_config.nPortIndex = config->nPortIndex;
3999 m_vendor_config.nDataSize = config->nDataSize;
4000 m_vendor_config.pData =
4001 (OMX_U8 *) malloc((config->nDataSize));
4002 memcpy(m_vendor_config.pData, config->pData,
4003 config->nDataSize);
4004 m_vc1_profile = VC1_AP;
4005 } else if ((config->nDataSize == VC1_STRUCT_C_LEN)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004006 DEBUG_PRINT_LOW("set_config - VC1 Simple/Main profile struct C only");
Arun Menon906de572013-06-18 17:01:40 -07004007 m_vendor_config.nPortIndex = config->nPortIndex;
4008 m_vendor_config.nDataSize = config->nDataSize;
4009 m_vendor_config.pData = (OMX_U8*)malloc(config->nDataSize);
4010 memcpy(m_vendor_config.pData,config->pData,config->nDataSize);
4011 m_vc1_profile = VC1_SP_MP_RCV;
4012 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004013 DEBUG_PRINT_LOW("set_config - Error: Unknown VC1 profile");
Arun Menon906de572013-06-18 17:01:40 -07004014 }
4015 }
4016 return ret;
4017 } else if (configIndex == OMX_IndexConfigVideoNalSize) {
4018 struct v4l2_control temp;
4019 temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT;
4020
4021 pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData);
4022 switch (pNal->nNaluBytes) {
4023 case 0:
4024 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES;
4025 break;
4026 case 2:
4027 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH;
4028 break;
4029 case 4:
4030 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH;
4031 break;
4032 default:
4033 return OMX_ErrorUnsupportedSetting;
4034 }
4035
4036 if (!arbitrary_bytes) {
4037 /* In arbitrary bytes mode, the assembler strips out nal size and replaces
4038 * with start code, so only need to notify driver in frame by frame mode */
4039 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) {
4040 DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT");
4041 return OMX_ErrorHardware;
4042 }
4043 }
4044
4045 nal_length = pNal->nNaluBytes;
4046 m_frame_parser.init_nal_length(nal_length);
4047
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004048 DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length);
Arun Menon906de572013-06-18 17:01:40 -07004049 return ret;
Surajit Podderd2644d52013-08-28 17:59:06 +05304050 } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) {
Arun Menon906de572013-06-18 17:01:40 -07004051 OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData;
Surajit Podderd2644d52013-08-28 17:59:06 +05304052 DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps);
Arun Menon906de572013-06-18 17:01:40 -07004053
4054 if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) {
4055 if (config->bEnabled) {
4056 if ((config->nFps >> 16) > 0) {
Surajit Podderd2644d52013-08-28 17:59:06 +05304057 DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu",
Arun Menon906de572013-06-18 17:01:40 -07004058 config->nFps >> 16);
4059 Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator,
4060 drv_ctx.frame_rate.fps_denominator);
4061
4062 if (!drv_ctx.frame_rate.fps_numerator) {
4063 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
4064 drv_ctx.frame_rate.fps_numerator = 30;
4065 }
4066
4067 if (drv_ctx.frame_rate.fps_denominator) {
4068 drv_ctx.frame_rate.fps_numerator = (int)
4069 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
4070 }
4071
4072 drv_ctx.frame_rate.fps_denominator = 1;
4073 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
4074 drv_ctx.frame_rate.fps_numerator;
4075
4076 struct v4l2_outputparm oparm;
4077 /*XXX: we're providing timing info as seconds per frame rather than frames
4078 * per second.*/
4079 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
4080 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
4081
4082 struct v4l2_streamparm sparm;
4083 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
4084 sparm.parm.output = oparm;
4085 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
4086 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
4087 performance might be affected");
4088 ret = OMX_ErrorHardware;
4089 }
4090 client_set_fps = true;
4091 } else {
4092 DEBUG_PRINT_ERROR("Frame rate not supported.");
4093 ret = OMX_ErrorUnsupportedSetting;
4094 }
4095 } else {
4096 DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate");
4097 client_set_fps = false;
4098 }
4099 } else {
4100 DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d",
4101 (int)config->nPortIndex);
4102 ret = OMX_ErrorBadPortIndex;
4103 }
4104
4105 return ret;
4106 }
4107
4108 return OMX_ErrorNotImplemented;
4109}
4110
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304111#define extn_equals(param, extn) (!strncmp(param, extn, strlen(extn)))
4112
Arun Menon906de572013-06-18 17:01:40 -07004113/* ======================================================================
4114 FUNCTION
4115 omx_vdec::GetExtensionIndex
4116
4117 DESCRIPTION
4118 OMX GetExtensionIndex method implementaion. <TBD>
4119
4120 PARAMETERS
4121 <TBD>.
4122
4123 RETURN VALUE
4124 OMX Error None if everything successful.
4125
4126 ========================================================================== */
4127OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp,
4128 OMX_IN OMX_STRING paramName,
4129 OMX_OUT OMX_INDEXTYPE* indexType)
4130{
4131 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004132 DEBUG_PRINT_ERROR("Get Extension Index in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004133 return OMX_ErrorInvalidState;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304134 } else if (extn_equals(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode")) {
Arun Menon906de572013-06-18 17:01:40 -07004135 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304136 } else if (extn_equals(paramName, "OMX.QCOM.index.param.IndexExtraData")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004137 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304138 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_FRAMEPACKING_EXTRADATA)) {
4139 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoFramePackingExtradata;
4140 } else if (extn_equals(paramName, OMX_QCOM_INDEX_CONFIG_VIDEO_FRAMEPACKING_INFO)) {
4141 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoFramePackingArrangement;
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08004142 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_QP_EXTRADATA)) {
4143 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPExtraData;
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08004144 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_INPUTBITSINFO_EXTRADATA)) {
4145 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoInputBitsInfoExtraData;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08004146 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_EXTNUSER_EXTRADATA)) {
4147 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableExtnUserData;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004148 }
4149#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304150 else if (extn_equals(paramName, "OMX.google.android.index.enableAndroidNativeBuffers")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004151 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304152 } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer2")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004153 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304154 } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer")) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004155 DEBUG_PRINT_ERROR("Extension: %s is supported", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004156 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304157 } else if (extn_equals(paramName, "OMX.google.android.index.getAndroidNativeBufferUsage")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004158 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage;
4159 }
4160#endif
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304161 else if (extn_equals(paramName, "OMX.google.android.index.storeMetaDataInBuffers")) {
Arun Menone5652482013-08-04 13:33:05 -07004162 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode;
4163 }
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05304164#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
Praveen Chavancf924182013-12-06 23:16:23 -08004165 else if (extn_equals(paramName, "OMX.google.android.index.prepareForAdaptivePlayback")) {
4166 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoAdaptivePlaybackMode;
4167 }
4168#endif
Arun Menon906de572013-06-18 17:01:40 -07004169 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004170 DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004171 return OMX_ErrorNotImplemented;
4172 }
4173 return OMX_ErrorNone;
4174}
4175
4176/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004177 FUNCTION
4178 omx_vdec::GetState
Shalaj Jain273b3e02012-06-22 19:08:03 -07004179
Arun Menon906de572013-06-18 17:01:40 -07004180 DESCRIPTION
4181 Returns the state information back to the caller.<TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07004182
Arun Menon906de572013-06-18 17:01:40 -07004183 PARAMETERS
4184 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004185
Arun Menon906de572013-06-18 17:01:40 -07004186 RETURN VALUE
4187 Error None if everything is successful.
4188 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004189OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004190 OMX_OUT OMX_STATETYPE* state)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004191{
Arun Menon906de572013-06-18 17:01:40 -07004192 *state = m_state;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004193 DEBUG_PRINT_LOW("get_state: Returning the state %d",*state);
Arun Menon906de572013-06-18 17:01:40 -07004194 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004195}
4196
4197/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004198 FUNCTION
4199 omx_vdec::ComponentTunnelRequest
Shalaj Jain273b3e02012-06-22 19:08:03 -07004200
Arun Menon906de572013-06-18 17:01:40 -07004201 DESCRIPTION
4202 OMX Component Tunnel Request method implementation. <TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07004203
Arun Menon906de572013-06-18 17:01:40 -07004204 PARAMETERS
4205 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004206
Arun Menon906de572013-06-18 17:01:40 -07004207 RETURN VALUE
4208 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004209
Arun Menon906de572013-06-18 17:01:40 -07004210 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004211OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004212 OMX_IN OMX_U32 port,
4213 OMX_IN OMX_HANDLETYPE peerComponent,
4214 OMX_IN OMX_U32 peerPort,
4215 OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004216{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004217 DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented");
Arun Menon906de572013-06-18 17:01:40 -07004218 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004219}
4220
4221/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004222 FUNCTION
4223 omx_vdec::UseOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004224
Arun Menon906de572013-06-18 17:01:40 -07004225 DESCRIPTION
4226 Helper function for Use buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07004227
Arun Menon906de572013-06-18 17:01:40 -07004228 PARAMETERS
4229 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004230
Arun Menon906de572013-06-18 17:01:40 -07004231 RETURN VALUE
4232 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07004233
Arun Menon906de572013-06-18 17:01:40 -07004234 ========================================================================== */
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004235OMX_ERRORTYPE omx_vdec::allocate_extradata()
4236{
4237#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004238 if (drv_ctx.extradata_info.buffer_size) {
4239 if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) {
4240 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
4241 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4242 free_ion_memory(&drv_ctx.extradata_info.ion);
Praveen Chavan61e5d162013-11-01 02:49:19 -07004243 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Arun Menon906de572013-06-18 17:01:40 -07004244 }
4245 drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095);
4246 drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory(
4247 drv_ctx.extradata_info.size, 4096,
4248 &drv_ctx.extradata_info.ion.ion_alloc_data,
4249 &drv_ctx.extradata_info.ion.fd_ion_data, 0);
4250 if (drv_ctx.extradata_info.ion.ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004251 DEBUG_PRINT_ERROR("Failed to alloc extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07004252 return OMX_ErrorInsufficientResources;
4253 }
4254 drv_ctx.extradata_info.uaddr = (char *)mmap(NULL,
4255 drv_ctx.extradata_info.size,
4256 PROT_READ|PROT_WRITE, MAP_SHARED,
4257 drv_ctx.extradata_info.ion.fd_ion_data.fd , 0);
4258 if (drv_ctx.extradata_info.uaddr == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004259 DEBUG_PRINT_ERROR("Failed to map extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07004260 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4261 free_ion_memory(&drv_ctx.extradata_info.ion);
4262 return OMX_ErrorInsufficientResources;
4263 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004264 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004265#endif
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304266 if (!m_other_extradata) {
4267 m_other_extradata = (OMX_OTHER_EXTRADATATYPE *)malloc(drv_ctx.extradata_info.buffer_size);
4268 if (!m_other_extradata) {
4269 DEBUG_PRINT_ERROR("Failed to alloc memory\n");
4270 return OMX_ErrorInsufficientResources;
4271 }
4272 }
Arun Menon906de572013-06-18 17:01:40 -07004273 return OMX_ErrorNone;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004274}
4275
Arun Menon906de572013-06-18 17:01:40 -07004276void omx_vdec::free_extradata()
4277{
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004278#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004279 if (drv_ctx.extradata_info.uaddr) {
4280 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
4281 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4282 free_ion_memory(&drv_ctx.extradata_info.ion);
4283 }
4284 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004285#endif
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304286 if (m_other_extradata) {
4287 free(m_other_extradata);
4288 m_other_extradata = NULL;
4289 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004290}
4291
Shalaj Jain273b3e02012-06-22 19:08:03 -07004292OMX_ERRORTYPE omx_vdec::use_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004293 OMX_IN OMX_HANDLETYPE hComp,
4294 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4295 OMX_IN OMX_U32 port,
4296 OMX_IN OMX_PTR appData,
4297 OMX_IN OMX_U32 bytes,
4298 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004299{
Arun Menon906de572013-06-18 17:01:40 -07004300 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4301 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
4302 unsigned i= 0; // Temporary counter
4303 struct vdec_setbuffer_cmd setbuffers;
4304 OMX_PTR privateAppData = NULL;
4305 private_handle_t *handle = NULL;
4306 OMX_U8 *buff = buffer;
4307 struct v4l2_buffer buf;
4308 struct v4l2_plane plane[VIDEO_MAX_PLANES];
4309 int extra_idx = 0;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004310
Arun Menon906de572013-06-18 17:01:40 -07004311 if (!m_out_mem_ptr) {
4312 DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers");
4313 eRet = allocate_output_headers();
4314 if (eRet == OMX_ErrorNone)
4315 eRet = allocate_extradata();
Shalaj Jain273b3e02012-06-22 19:08:03 -07004316 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004317
Arun Menon906de572013-06-18 17:01:40 -07004318 if (eRet == OMX_ErrorNone) {
4319 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
4320 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
4321 break;
4322 }
4323 }
4324 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004325
Arun Menon906de572013-06-18 17:01:40 -07004326 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004327 DEBUG_PRINT_ERROR("Already using %d o/p buffers", drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07004328 eRet = OMX_ErrorInsufficientResources;
4329 }
4330
Arun Menonbdb80b02013-08-12 17:45:54 -07004331 if (dynamic_buf_mode) {
4332 *bufferHdr = (m_out_mem_ptr + i );
4333 (*bufferHdr)->pBuffer = NULL;
4334 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
4335 enum v4l2_buf_type buf_type;
4336 int rr = 0;
4337 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4338 if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
4339 DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr);
4340 return OMX_ErrorInsufficientResources;
4341 } else {
4342 streaming[CAPTURE_PORT] = true;
4343 DEBUG_PRINT_LOW("STREAMON Successful");
4344 }
4345 }
4346 BITMASK_SET(&m_out_bm_count,i);
4347 (*bufferHdr)->pAppPrivate = appData;
4348 (*bufferHdr)->pBuffer = buffer;
4349 (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData);
4350 return eRet;
4351 }
Arun Menon906de572013-06-18 17:01:40 -07004352 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004353#if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004354 if (m_enable_android_native_buffers) {
4355 if (m_use_android_native_buffers) {
4356 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData;
4357 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
4358 handle = (private_handle_t *)nBuf->handle;
4359 privateAppData = params->pAppPrivate;
4360 } else {
4361 handle = (private_handle_t *)buff;
4362 privateAppData = appData;
4363 }
Arun Menon8544ead2014-05-08 17:42:29 -07004364 if (!handle) {
4365 DEBUG_PRINT_ERROR("handle is invalid");
4366 return OMX_ErrorBadParameter;
4367 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004368
Arun Menon906de572013-06-18 17:01:40 -07004369 if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) {
4370 DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback,"
4371 " expected %u, got %lu",
4372 drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size);
4373 return OMX_ErrorBadParameter;
4374 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004375
Deva Ramasubramanian03a5bb92014-04-25 19:03:50 -07004376 drv_ctx.op_buf.buffer_size = handle->size;
4377
Arun Menon906de572013-06-18 17:01:40 -07004378 if (!m_use_android_native_buffers) {
4379 if (!secure_mode) {
4380 buff = (OMX_U8*)mmap(0, handle->size,
4381 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
4382 if (buff == MAP_FAILED) {
4383 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
4384 return OMX_ErrorInsufficientResources;
4385 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004386 }
4387 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004388#if defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004389 native_buffer[i].nativehandle = handle;
4390 native_buffer[i].privatehandle = handle;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004391#endif
Arun Menon906de572013-06-18 17:01:40 -07004392 if (!handle) {
4393 DEBUG_PRINT_ERROR("Native Buffer handle is NULL");
4394 return OMX_ErrorBadParameter;
4395 }
4396 drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd;
4397 drv_ctx.ptr_outputbuffer[i].offset = 0;
4398 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4399 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4400 drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size;
4401 } else
4402#endif
4403
4404 if (!ouput_egl_buffers && !m_use_output_pmem) {
4405#ifdef USE_ION
4406 drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
4407 drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment,
4408 &drv_ctx.op_buf_ion_info[i].ion_alloc_data,
4409 &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
4410 if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004411 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 -07004412 return OMX_ErrorInsufficientResources;
4413 }
4414 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4415 drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
4416#else
4417 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4418 open (MEM_DEVICE,O_RDWR);
4419
4420 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004421 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004422 return OMX_ErrorInsufficientResources;
4423 }
4424
4425 /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */
4426 if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) {
4427 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4428 open (MEM_DEVICE,O_RDWR);
4429 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004430 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004431 return OMX_ErrorInsufficientResources;
4432 }
4433 }
4434
4435 if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd,
4436 drv_ctx.op_buf.buffer_size,
4437 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004438 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07004439 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4440 return OMX_ErrorInsufficientResources;
4441 }
4442#endif
4443 if (!secure_mode) {
4444 drv_ctx.ptr_outputbuffer[i].bufferaddr =
4445 (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size,
4446 PROT_READ|PROT_WRITE, MAP_SHARED,
4447 drv_ctx.ptr_outputbuffer[i].pmem_fd,0);
4448 if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) {
4449 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4450#ifdef USE_ION
4451 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
4452#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004453 DEBUG_PRINT_ERROR("Unable to mmap output buffer");
Arun Menon906de572013-06-18 17:01:40 -07004454 return OMX_ErrorInsufficientResources;
4455 }
4456 }
4457 drv_ctx.ptr_outputbuffer[i].offset = 0;
4458 privateAppData = appData;
4459 } else {
4460
4461 DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem);
4462 if (!appData || !bytes ) {
4463 if (!secure_mode && !buffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004464 DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case");
Arun Menon906de572013-06-18 17:01:40 -07004465 return OMX_ErrorBadParameter;
4466 }
4467 }
4468
4469 OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list;
4470 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info;
4471 pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData;
Arun Menon8544ead2014-05-08 17:42:29 -07004472 if (!pmem_list || !pmem_list->entryList || !pmem_list->entryList->entry ||
Arun Menon906de572013-06-18 17:01:40 -07004473 !pmem_list->nEntries ||
4474 pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004475 DEBUG_PRINT_ERROR("Pmem info not valid in use buffer");
Arun Menon906de572013-06-18 17:01:40 -07004476 return OMX_ErrorBadParameter;
4477 }
4478 pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
4479 pmem_list->entryList->entry;
4480 DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx",
4481 pmem_info->pmem_fd);
4482 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd;
4483 drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset;
4484 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4485 drv_ctx.ptr_outputbuffer[i].mmaped_size =
4486 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4487 privateAppData = appData;
4488 }
4489 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
4490 m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd;
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304491 m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len;
4492 m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size;
4493 m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr;
Arun Menon906de572013-06-18 17:01:40 -07004494
4495 *bufferHdr = (m_out_mem_ptr + i );
4496 if (secure_mode)
4497 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
4498 //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4499 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i],
4500 sizeof (vdec_bufferpayload));
4501
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004502 DEBUG_PRINT_HIGH("Set the Output Buffer Idx: %d Addr: %p, pmem_fd=0x%x", i,
Arun Menon906de572013-06-18 17:01:40 -07004503 drv_ctx.ptr_outputbuffer[i].bufferaddr,
4504 drv_ctx.ptr_outputbuffer[i].pmem_fd );
4505
4506 buf.index = i;
4507 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4508 buf.memory = V4L2_MEMORY_USERPTR;
4509 plane[0].length = drv_ctx.op_buf.buffer_size;
4510 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
4511 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
4512 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd;
4513 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
4514 plane[0].data_offset = 0;
4515 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
4516 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
4517 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
4518 plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size);
4519#ifdef USE_ION
4520 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
4521#endif
4522 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
4523 plane[extra_idx].data_offset = 0;
4524 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004525 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004526 return OMX_ErrorBadParameter;
4527 }
Arun Menon906de572013-06-18 17:01:40 -07004528 buf.m.planes = plane;
4529 buf.length = drv_ctx.num_planes;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004530
Arun Menon906de572013-06-18 17:01:40 -07004531 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004532 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07004533 /*TODO: How to handle this case */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004534 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004535 }
4536
Arun Menon906de572013-06-18 17:01:40 -07004537 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
4538 enum v4l2_buf_type buf_type;
4539 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4540 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
4541 return OMX_ErrorInsufficientResources;
4542 } else {
4543 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004544 DEBUG_PRINT_LOW("STREAMON Successful");
Shalaj Jain273b3e02012-06-22 19:08:03 -07004545 }
4546 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004547
Arun Menon906de572013-06-18 17:01:40 -07004548 (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size;
4549 if (m_enable_android_native_buffers) {
4550 DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle);
4551 (*bufferHdr)->pBuffer = (OMX_U8 *)handle;
4552 } else {
4553 (*bufferHdr)->pBuffer = buff;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004554 }
Arun Menon906de572013-06-18 17:01:40 -07004555 (*bufferHdr)->pAppPrivate = privateAppData;
4556 BITMASK_SET(&m_out_bm_count,i);
4557 }
4558 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004559}
4560
4561/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004562 FUNCTION
4563 omx_vdec::use_input_heap_buffers
Shalaj Jain273b3e02012-06-22 19:08:03 -07004564
Arun Menon906de572013-06-18 17:01:40 -07004565 DESCRIPTION
4566 OMX Use Buffer Heap allocation method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004567
Arun Menon906de572013-06-18 17:01:40 -07004568 PARAMETERS
4569 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004570
Arun Menon906de572013-06-18 17:01:40 -07004571 RETURN VALUE
4572 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004573
Arun Menon906de572013-06-18 17:01:40 -07004574 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004575OMX_ERRORTYPE omx_vdec::use_input_heap_buffers(
Arun Menon906de572013-06-18 17:01:40 -07004576 OMX_IN OMX_HANDLETYPE hComp,
4577 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4578 OMX_IN OMX_U32 port,
4579 OMX_IN OMX_PTR appData,
4580 OMX_IN OMX_U32 bytes,
4581 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004582{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004583 DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer);
Arun Menon906de572013-06-18 17:01:40 -07004584 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4585 if (!m_inp_heap_ptr)
4586 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*)
4587 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4588 drv_ctx.ip_buf.actualcount);
4589 if (!m_phdr_pmem_ptr)
4590 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**)
4591 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4592 drv_ctx.ip_buf.actualcount);
4593 if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) {
4594 DEBUG_PRINT_ERROR("Insufficent memory");
4595 eRet = OMX_ErrorInsufficientResources;
4596 } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) {
4597 input_use_buffer = true;
4598 memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE));
4599 m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer;
4600 m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes;
4601 m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData;
4602 m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput;
4603 m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax;
4604 *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt];
4605 eRet = allocate_input_buffer(hComp, &m_phdr_pmem_ptr[m_in_alloc_cnt], port, appData, bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004606 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 -07004607 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt],
4608 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004609 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07004610 return OMX_ErrorInsufficientResources;
4611 }
4612 m_in_alloc_cnt++;
4613 } else {
4614 DEBUG_PRINT_ERROR("All i/p buffers have been set!");
4615 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004616 }
Arun Menon906de572013-06-18 17:01:40 -07004617 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004618}
4619
4620/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004621 FUNCTION
4622 omx_vdec::UseBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004623
Arun Menon906de572013-06-18 17:01:40 -07004624 DESCRIPTION
4625 OMX Use Buffer method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004626
Arun Menon906de572013-06-18 17:01:40 -07004627 PARAMETERS
4628 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004629
Arun Menon906de572013-06-18 17:01:40 -07004630 RETURN VALUE
4631 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004632
Arun Menon906de572013-06-18 17:01:40 -07004633 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004634OMX_ERRORTYPE omx_vdec::use_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004635 OMX_IN OMX_HANDLETYPE hComp,
4636 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4637 OMX_IN OMX_U32 port,
4638 OMX_IN OMX_PTR appData,
4639 OMX_IN OMX_U32 bytes,
4640 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004641{
Arun Menon906de572013-06-18 17:01:40 -07004642 OMX_ERRORTYPE error = OMX_ErrorNone;
4643 struct vdec_setbuffer_cmd setbuffers;
4644
Arun Menon8544ead2014-05-08 17:42:29 -07004645 if (bufferHdr == NULL || bytes == 0 || (!secure_mode && buffer == NULL)) {
4646 DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer);
4647 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004648 }
Arun Menon906de572013-06-18 17:01:40 -07004649 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004650 DEBUG_PRINT_ERROR("Use Buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004651 return OMX_ErrorInvalidState;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004652 }
Arun Menon906de572013-06-18 17:01:40 -07004653 if (port == OMX_CORE_INPUT_PORT_INDEX)
4654 error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer);
4655 else if (port == OMX_CORE_OUTPUT_PORT_INDEX)
4656 error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested
4657 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004658 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07004659 error = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004660 }
Arun Menon906de572013-06-18 17:01:40 -07004661 DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error);
4662 if (error == OMX_ErrorNone) {
4663 if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
4664 // Send the callback now
4665 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
4666 post_event(OMX_CommandStateSet,OMX_StateIdle,
4667 OMX_COMPONENT_GENERATE_EVENT);
4668 }
4669 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated &&
4670 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
4671 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
4672 post_event(OMX_CommandPortEnable,
4673 OMX_CORE_INPUT_PORT_INDEX,
4674 OMX_COMPONENT_GENERATE_EVENT);
4675 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated &&
4676 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
4677 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
4678 post_event(OMX_CommandPortEnable,
4679 OMX_CORE_OUTPUT_PORT_INDEX,
4680 OMX_COMPONENT_GENERATE_EVENT);
4681 }
4682 }
4683 return error;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004684}
4685
4686OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex,
Arun Menon906de572013-06-18 17:01:40 -07004687 OMX_BUFFERHEADERTYPE *pmem_bufferHdr)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004688{
Arun Menon906de572013-06-18 17:01:40 -07004689 if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) {
4690 if (m_inp_heap_ptr[bufferindex].pBuffer)
4691 free(m_inp_heap_ptr[bufferindex].pBuffer);
4692 m_inp_heap_ptr[bufferindex].pBuffer = NULL;
4693 }
4694 if (pmem_bufferHdr)
4695 free_input_buffer(pmem_bufferHdr);
4696 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004697}
4698
4699OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4700{
Arun Menon906de572013-06-18 17:01:40 -07004701 unsigned int index = 0;
4702 if (bufferHdr == NULL || m_inp_mem_ptr == NULL) {
4703 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004704 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004705
Arun Menon906de572013-06-18 17:01:40 -07004706 index = bufferHdr - m_inp_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004707 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004708
4709 if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004710 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004711 if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) {
4712 struct vdec_setbuffer_cmd setbuffers;
4713 setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT;
4714 memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index],
4715 sizeof (vdec_bufferpayload));
4716 if (!secure_mode) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004717 DEBUG_PRINT_LOW("unmap the input buffer fd=%d",
Arun Menon906de572013-06-18 17:01:40 -07004718 drv_ctx.ptr_inputbuffer[index].pmem_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004719 DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07004720 drv_ctx.ptr_inputbuffer[index].mmaped_size,
4721 drv_ctx.ptr_inputbuffer[index].bufferaddr);
4722 munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr,
4723 drv_ctx.ptr_inputbuffer[index].mmaped_size);
4724 }
4725 close (drv_ctx.ptr_inputbuffer[index].pmem_fd);
4726 drv_ctx.ptr_inputbuffer[index].pmem_fd = -1;
4727 if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) {
4728 free(m_desc_buffer_ptr[index].buf_addr);
4729 m_desc_buffer_ptr[index].buf_addr = NULL;
4730 m_desc_buffer_ptr[index].desc_data_size = 0;
4731 }
4732#ifdef USE_ION
4733 free_ion_memory(&drv_ctx.ip_buf_ion_info[index]);
4734#endif
4735 }
4736 }
4737
4738 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004739}
4740
4741OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4742{
Arun Menon906de572013-06-18 17:01:40 -07004743 unsigned int index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004744
Arun Menon906de572013-06-18 17:01:40 -07004745 if (bufferHdr == NULL || m_out_mem_ptr == NULL) {
4746 return OMX_ErrorBadParameter;
4747 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004748
Arun Menon906de572013-06-18 17:01:40 -07004749 index = bufferHdr - m_out_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004750 DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004751
Arun Menon906de572013-06-18 17:01:40 -07004752 if (index < drv_ctx.op_buf.actualcount
4753 && drv_ctx.ptr_outputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004754 DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index,
Arun Menon906de572013-06-18 17:01:40 -07004755 drv_ctx.ptr_outputbuffer[index].bufferaddr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004756
Arun Menon906de572013-06-18 17:01:40 -07004757 struct vdec_setbuffer_cmd setbuffers;
4758 setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4759 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index],
4760 sizeof (vdec_bufferpayload));
Praveen Chavan61e5d162013-11-01 02:49:19 -07004761
4762 if (!dynamic_buf_mode) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004763#ifdef _ANDROID_
Praveen Chavan61e5d162013-11-01 02:49:19 -07004764 if (m_enable_android_native_buffers) {
Arun Menon906de572013-06-18 17:01:40 -07004765 if (!secure_mode) {
Praveen Chavan61e5d162013-11-01 02:49:19 -07004766 if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) {
4767 munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr,
4768 drv_ctx.ptr_outputbuffer[index].mmaped_size);
4769 }
Arun Menon906de572013-06-18 17:01:40 -07004770 }
Praveen Chavan61e5d162013-11-01 02:49:19 -07004771 drv_ctx.ptr_outputbuffer[index].pmem_fd = -1;
4772 } else {
4773#endif
4774 if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) {
4775 if (!secure_mode) {
4776 DEBUG_PRINT_LOW("\n unmap the output buffer fd = %d",
4777 drv_ctx.ptr_outputbuffer[0].pmem_fd);
4778 DEBUG_PRINT_LOW("\n unmap the ouput buffer size=%d address = %p",
4779 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount,
4780 drv_ctx.ptr_outputbuffer[0].bufferaddr);
4781 munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr,
4782 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount);
4783 }
4784 close (drv_ctx.ptr_outputbuffer[0].pmem_fd);
4785 drv_ctx.ptr_outputbuffer[0].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004786#ifdef USE_ION
Praveen Chavan61e5d162013-11-01 02:49:19 -07004787 free_ion_memory(&drv_ctx.op_buf_ion_info[0]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004788#endif
Praveen Chavan61e5d162013-11-01 02:49:19 -07004789 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004790#ifdef _ANDROID_
Praveen Chavan61e5d162013-11-01 02:49:19 -07004791 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004792#endif
Praveen Chavan61e5d162013-11-01 02:49:19 -07004793 } //!dynamic_buf_mode
Arun Menon906de572013-06-18 17:01:40 -07004794 if (release_output_done()) {
4795 free_extradata();
4796 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004797 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004798
Arun Menon906de572013-06-18 17:01:40 -07004799 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004800
4801}
4802
4803OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004804 OMX_BUFFERHEADERTYPE **bufferHdr,
4805 OMX_U32 port,
4806 OMX_PTR appData,
4807 OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004808{
Arun Menon906de572013-06-18 17:01:40 -07004809 OMX_BUFFERHEADERTYPE *input = NULL;
4810 unsigned char *buf_addr = NULL;
4811 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4812 unsigned i = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004813
Arun Menon906de572013-06-18 17:01:40 -07004814 /* Sanity Check*/
4815 if (bufferHdr == NULL) {
4816 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004817 }
4818
Arun Menon906de572013-06-18 17:01:40 -07004819 if (m_inp_heap_ptr == NULL) {
4820 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \
4821 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4822 drv_ctx.ip_buf.actualcount);
4823 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \
4824 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4825 drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004826
Arun Menon8544ead2014-05-08 17:42:29 -07004827 if (m_inp_heap_ptr == NULL || m_phdr_pmem_ptr == NULL) {
4828 DEBUG_PRINT_ERROR("m_inp_heap_ptr or m_phdr_pmem_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07004829 return OMX_ErrorInsufficientResources;
4830 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004831 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004832
Arun Menon906de572013-06-18 17:01:40 -07004833 /*Find a Free index*/
4834 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
4835 if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004836 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004837 break;
4838 }
4839 }
4840
4841 if (i < drv_ctx.ip_buf.actualcount) {
4842 buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size);
4843
4844 if (buf_addr == NULL) {
4845 return OMX_ErrorInsufficientResources;
4846 }
4847
4848 *bufferHdr = (m_inp_heap_ptr + i);
4849 input = *bufferHdr;
4850 BITMASK_SET(&m_heap_inp_bm_count,i);
4851
4852 input->pBuffer = (OMX_U8 *)buf_addr;
4853 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
4854 input->nVersion.nVersion = OMX_SPEC_VERSION;
4855 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
4856 input->pAppPrivate = appData;
4857 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004858 DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr );
Arun Menon906de572013-06-18 17:01:40 -07004859 eRet = allocate_input_buffer(hComp,&m_phdr_pmem_ptr [i],port,appData,bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004860 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",m_phdr_pmem_ptr[i]);
Arun Menon906de572013-06-18 17:01:40 -07004861 /*Add the Buffers to freeq*/
4862 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i],
4863 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004864 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07004865 return OMX_ErrorInsufficientResources;
4866 }
4867 } else {
4868 return OMX_ErrorBadParameter;
4869 }
4870
4871 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004872
4873}
4874
4875
4876/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004877 FUNCTION
4878 omx_vdec::AllocateInputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004879
Arun Menon906de572013-06-18 17:01:40 -07004880 DESCRIPTION
4881 Helper function for allocate buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07004882
Arun Menon906de572013-06-18 17:01:40 -07004883 PARAMETERS
4884 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004885
Arun Menon906de572013-06-18 17:01:40 -07004886 RETURN VALUE
4887 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07004888
Arun Menon906de572013-06-18 17:01:40 -07004889 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004890OMX_ERRORTYPE omx_vdec::allocate_input_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004891 OMX_IN OMX_HANDLETYPE hComp,
4892 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4893 OMX_IN OMX_U32 port,
4894 OMX_IN OMX_PTR appData,
4895 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004896{
4897
Arun Menon906de572013-06-18 17:01:40 -07004898 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4899 struct vdec_setbuffer_cmd setbuffers;
4900 OMX_BUFFERHEADERTYPE *input = NULL;
4901 unsigned i = 0;
4902 unsigned char *buf_addr = NULL;
4903 int pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004904
Arun Menon906de572013-06-18 17:01:40 -07004905 if (bytes != drv_ctx.ip_buf.buffer_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004906 DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d",
Arun Menon906de572013-06-18 17:01:40 -07004907 bytes, drv_ctx.ip_buf.buffer_size);
4908 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004909 }
4910
Arun Menon906de572013-06-18 17:01:40 -07004911 if (!m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004912 DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07004913 drv_ctx.ip_buf.actualcount,
4914 drv_ctx.ip_buf.buffer_size);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004915
Arun Menon906de572013-06-18 17:01:40 -07004916 m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \
4917 calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount);
4918
4919 if (m_inp_mem_ptr == NULL) {
4920 return OMX_ErrorInsufficientResources;
4921 }
4922
4923 drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \
4924 calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount);
4925
4926 if (drv_ctx.ptr_inputbuffer == NULL) {
4927 return OMX_ErrorInsufficientResources;
4928 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004929#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004930 drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \
4931 calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004932
Arun Menon906de572013-06-18 17:01:40 -07004933 if (drv_ctx.ip_buf_ion_info == NULL) {
4934 return OMX_ErrorInsufficientResources;
4935 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004936#endif
4937
Arun Menon906de572013-06-18 17:01:40 -07004938 for (i=0; i < drv_ctx.ip_buf.actualcount; i++) {
4939 drv_ctx.ptr_inputbuffer [i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004940#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004941 drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004942#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07004943 }
4944 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004945
Arun Menon906de572013-06-18 17:01:40 -07004946 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
4947 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004948 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004949 break;
4950 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004951 }
Arun Menon906de572013-06-18 17:01:40 -07004952
4953 if (i < drv_ctx.ip_buf.actualcount) {
4954 struct v4l2_buffer buf;
4955 struct v4l2_plane plane;
4956 int rc;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004957 DEBUG_PRINT_LOW("Allocate input Buffer");
Arun Menon906de572013-06-18 17:01:40 -07004958#ifdef USE_ION
4959 drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
4960 drv_ctx.ip_buf.buffer_size,drv_ctx.op_buf.alignment,
4961 &drv_ctx.ip_buf_ion_info[i].ion_alloc_data,
4962 &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
4963 if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) {
4964 return OMX_ErrorInsufficientResources;
4965 }
4966 pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd;
4967#else
4968 pmem_fd = open (MEM_DEVICE,O_RDWR);
4969
4970 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004971 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07004972 return OMX_ErrorInsufficientResources;
4973 }
4974
4975 if (pmem_fd == 0) {
4976 pmem_fd = open (MEM_DEVICE,O_RDWR);
4977
4978 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004979 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07004980 return OMX_ErrorInsufficientResources;
4981 }
4982 }
4983
4984 if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size,
4985 drv_ctx.ip_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004986 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07004987 close(pmem_fd);
4988 return OMX_ErrorInsufficientResources;
4989 }
4990#endif
4991 if (!secure_mode) {
4992 buf_addr = (unsigned char *)mmap(NULL,
4993 drv_ctx.ip_buf.buffer_size,
4994 PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0);
4995
4996 if (buf_addr == MAP_FAILED) {
4997 close(pmem_fd);
4998#ifdef USE_ION
4999 free_ion_memory(&drv_ctx.ip_buf_ion_info[i]);
5000#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005001 DEBUG_PRINT_ERROR("Map Failed to allocate input buffer");
Arun Menon906de572013-06-18 17:01:40 -07005002 return OMX_ErrorInsufficientResources;
5003 }
5004 }
5005 *bufferHdr = (m_inp_mem_ptr + i);
5006 if (secure_mode)
5007 drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr;
5008 else
5009 drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr;
5010 drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd;
5011 drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size;
5012 drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size;
5013 drv_ctx.ptr_inputbuffer [i].offset = 0;
5014
5015
5016 buf.index = i;
5017 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
5018 buf.memory = V4L2_MEMORY_USERPTR;
5019 plane.bytesused = 0;
5020 plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size;
5021 plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr;
5022 plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd;
5023 plane.reserved[1] = 0;
5024 plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset;
5025 buf.m.planes = &plane;
5026 buf.length = 1;
5027
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005028 DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i,
Arun Menon906de572013-06-18 17:01:40 -07005029 drv_ctx.ptr_inputbuffer[i].bufferaddr);
5030
5031 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
5032
5033 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005034 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07005035 /*TODO: How to handle this case */
5036 return OMX_ErrorInsufficientResources;
5037 }
5038
5039 input = *bufferHdr;
5040 BITMASK_SET(&m_inp_bm_count,i);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005041 DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr);
Arun Menon906de572013-06-18 17:01:40 -07005042 if (secure_mode)
5043 input->pBuffer = (OMX_U8 *)drv_ctx.ptr_inputbuffer [i].pmem_fd;
5044 else
5045 input->pBuffer = (OMX_U8 *)buf_addr;
5046 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
5047 input->nVersion.nVersion = OMX_SPEC_VERSION;
5048 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
5049 input->pAppPrivate = appData;
5050 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
5051 input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i];
5052
5053 if (drv_ctx.disable_dmx) {
5054 eRet = allocate_desc_buffer(i);
5055 }
5056 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005057 DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07005058 eRet = OMX_ErrorInsufficientResources;
5059 }
5060 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005061}
5062
5063
5064/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005065 FUNCTION
5066 omx_vdec::AllocateOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005067
Arun Menon906de572013-06-18 17:01:40 -07005068 DESCRIPTION
5069 Helper fn for AllocateBuffer in the output pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07005070
Arun Menon906de572013-06-18 17:01:40 -07005071 PARAMETERS
5072 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005073
Arun Menon906de572013-06-18 17:01:40 -07005074 RETURN VALUE
5075 OMX Error None if everything went well.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005076
Arun Menon906de572013-06-18 17:01:40 -07005077 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005078OMX_ERRORTYPE omx_vdec::allocate_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07005079 OMX_IN OMX_HANDLETYPE hComp,
5080 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5081 OMX_IN OMX_U32 port,
5082 OMX_IN OMX_PTR appData,
5083 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005084{
Arun Menon906de572013-06-18 17:01:40 -07005085 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5086 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
5087 unsigned i= 0; // Temporary counter
5088 struct vdec_setbuffer_cmd setbuffers;
5089 int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005090#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005091 int ion_device_fd =-1;
5092 struct ion_allocation_data ion_alloc_data;
5093 struct ion_fd_data fd_ion_data;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005094#endif
Arun Menon906de572013-06-18 17:01:40 -07005095 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005096 DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07005097 drv_ctx.op_buf.actualcount,
5098 drv_ctx.op_buf.buffer_size);
5099 int nBufHdrSize = 0;
5100 int nPlatformEntrySize = 0;
5101 int nPlatformListSize = 0;
5102 int nPMEMInfoSize = 0;
5103 int pmem_fd = -1;
5104 unsigned char *pmem_baseaddress = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005105
Arun Menon906de572013-06-18 17:01:40 -07005106 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
5107 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
5108 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005109
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005110 DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07005111 drv_ctx.op_buf.actualcount);
5112 nBufHdrSize = drv_ctx.op_buf.actualcount *
5113 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005114
Arun Menon906de572013-06-18 17:01:40 -07005115 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
5116 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
5117 nPlatformListSize = drv_ctx.op_buf.actualcount *
5118 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
5119 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
5120 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005121
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005122 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07005123 sizeof(OMX_BUFFERHEADERTYPE),
5124 nPMEMInfoSize,
5125 nPlatformListSize);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005126 DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07005127 drv_ctx.op_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005128#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005129 ion_device_fd = alloc_map_ion_memory(
5130 drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount,
5131 drv_ctx.op_buf.alignment,
5132 &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0);
5133 if (ion_device_fd < 0) {
5134 return OMX_ErrorInsufficientResources;
5135 }
5136 pmem_fd = fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005137#else
Arun Menon906de572013-06-18 17:01:40 -07005138 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005139
Arun Menon906de572013-06-18 17:01:40 -07005140 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005141 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07005142 drv_ctx.op_buf.buffer_size);
5143 return OMX_ErrorInsufficientResources;
5144 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005145
Arun Menon906de572013-06-18 17:01:40 -07005146 if (pmem_fd == 0) {
5147 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005148
Arun Menon906de572013-06-18 17:01:40 -07005149 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005150 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07005151 drv_ctx.op_buf.buffer_size);
5152 return OMX_ErrorInsufficientResources;
5153 }
5154 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005155
Arun Menon906de572013-06-18 17:01:40 -07005156 if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size *
5157 drv_ctx.op_buf.actualcount,
5158 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005159 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07005160 close(pmem_fd);
5161 return OMX_ErrorInsufficientResources;
5162 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005163#endif
Arun Menon906de572013-06-18 17:01:40 -07005164 if (!secure_mode) {
5165 pmem_baseaddress = (unsigned char *)mmap(NULL,
5166 (drv_ctx.op_buf.buffer_size *
5167 drv_ctx.op_buf.actualcount),
5168 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0);
5169 if (pmem_baseaddress == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005170 DEBUG_PRINT_ERROR("MMAP failed for Size %d",
Arun Menon906de572013-06-18 17:01:40 -07005171 drv_ctx.op_buf.buffer_size);
5172 close(pmem_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005173#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005174 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005175#endif
Arun Menon906de572013-06-18 17:01:40 -07005176 return OMX_ErrorInsufficientResources;
5177 }
5178 }
5179 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
5180 // Alloc mem for platform specific info
5181 char *pPtr=NULL;
5182 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
5183 nPMEMInfoSize,1);
5184 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\
5185 calloc (sizeof(struct vdec_bufferpayload),
5186 drv_ctx.op_buf.actualcount);
5187 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
5188 calloc (sizeof (struct vdec_output_frameinfo),
5189 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07005190 if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) {
5191 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer ");
5192 return OMX_ErrorInsufficientResources;
5193 }
5194
Arun Menon906de572013-06-18 17:01:40 -07005195#ifdef USE_ION
5196 drv_ctx.op_buf_ion_info = (struct vdec_ion *)\
5197 calloc (sizeof(struct vdec_ion),
5198 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07005199 if (!drv_ctx.op_buf_ion_info) {
5200 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info");
5201 return OMX_ErrorInsufficientResources;
5202 }
Arun Menon906de572013-06-18 17:01:40 -07005203#endif
5204
5205 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
5206 && drv_ctx.ptr_respbuffer) {
5207 drv_ctx.ptr_outputbuffer[0].mmaped_size =
5208 (drv_ctx.op_buf.buffer_size *
5209 drv_ctx.op_buf.actualcount);
5210 bufHdr = m_out_mem_ptr;
5211 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
5212 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
5213 (((char *) m_platform_list) + nPlatformListSize);
5214 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
5215 (((char *) m_platform_entry) + nPlatformEntrySize);
5216 pPlatformList = m_platform_list;
5217 pPlatformEntry = m_platform_entry;
5218 pPMEMInfo = m_pmem_info;
5219
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005220 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07005221
5222 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005223 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry);
5224 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07005225 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
5226 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
5227 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
5228 // Set the values when we determine the right HxW param
5229 bufHdr->nAllocLen = bytes;
5230 bufHdr->nFilledLen = 0;
5231 bufHdr->pAppPrivate = appData;
5232 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
5233 // Platform specific PMEM Information
5234 // Initialize the Platform Entry
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005235 //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005236 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
5237 pPlatformEntry->entry = pPMEMInfo;
5238 // Initialize the Platform List
5239 pPlatformList->nEntries = 1;
5240 pPlatformList->entryList = pPlatformEntry;
5241 // Keep pBuffer NULL till vdec is opened
5242 bufHdr->pBuffer = NULL;
5243 bufHdr->nOffset = 0;
5244
5245 pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i;
5246 pPMEMInfo->pmem_fd = 0;
5247 bufHdr->pPlatformPrivate = pPlatformList;
5248
5249 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd;
5250 m_pmem_info[i].pmem_fd = pmem_fd;
5251#ifdef USE_ION
5252 drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd;
5253 drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data;
5254 drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data;
5255#endif
5256
5257 /*Create a mapping between buffers*/
5258 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
5259 drv_ctx.ptr_respbuffer[i].client_data = (void *)\
5260 &drv_ctx.ptr_outputbuffer[i];
5261 drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i;
5262 drv_ctx.ptr_outputbuffer[i].bufferaddr =
5263 pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05305264 m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len;
5265 m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size;
5266 m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr;
Arun Menon906de572013-06-18 17:01:40 -07005267
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005268 DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07005269 pmem_fd, drv_ctx.ptr_outputbuffer[i].offset,
5270 drv_ctx.ptr_outputbuffer[i].bufferaddr);
5271 // Move the buffer and buffer header pointers
5272 bufHdr++;
5273 pPMEMInfo++;
5274 pPlatformEntry++;
5275 pPlatformList++;
5276 }
5277 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005278 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07005279 m_out_mem_ptr, pPtr);
5280 if (m_out_mem_ptr) {
5281 free(m_out_mem_ptr);
5282 m_out_mem_ptr = NULL;
5283 }
5284 if (pPtr) {
5285 free(pPtr);
5286 pPtr = NULL;
5287 }
5288 if (drv_ctx.ptr_outputbuffer) {
5289 free(drv_ctx.ptr_outputbuffer);
5290 drv_ctx.ptr_outputbuffer = NULL;
5291 }
5292 if (drv_ctx.ptr_respbuffer) {
5293 free(drv_ctx.ptr_respbuffer);
5294 drv_ctx.ptr_respbuffer = NULL;
5295 }
5296#ifdef USE_ION
5297 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005298 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07005299 free(drv_ctx.op_buf_ion_info);
5300 drv_ctx.op_buf_ion_info = NULL;
5301 }
5302#endif
5303 eRet = OMX_ErrorInsufficientResources;
5304 }
5305 if (eRet == OMX_ErrorNone)
5306 eRet = allocate_extradata();
5307 }
5308
5309 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
5310 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005311 DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005312 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005313 }
5314 }
Arun Menon906de572013-06-18 17:01:40 -07005315
5316 if (eRet == OMX_ErrorNone) {
5317 if (i < drv_ctx.op_buf.actualcount) {
5318 struct v4l2_buffer buf;
5319 struct v4l2_plane plane[VIDEO_MAX_PLANES];
5320 int rc;
5321 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
5322
5323 drv_ctx.ptr_outputbuffer[i].buffer_len =
5324 drv_ctx.op_buf.buffer_size;
5325
5326 *bufferHdr = (m_out_mem_ptr + i );
5327 if (secure_mode) {
5328 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
5329 }
5330 drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size;
5331
5332 buf.index = i;
5333 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5334 buf.memory = V4L2_MEMORY_USERPTR;
5335 plane[0].length = drv_ctx.op_buf.buffer_size;
5336 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
5337 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005338#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005339 plane[0].reserved[0] = drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005340#endif
Arun Menon906de572013-06-18 17:01:40 -07005341 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
5342 plane[0].data_offset = 0;
5343 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
5344 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
5345 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
5346 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 -07005347#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005348 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005349#endif
Arun Menon906de572013-06-18 17:01:40 -07005350 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
5351 plane[extra_idx].data_offset = 0;
5352 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005353 DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07005354 return OMX_ErrorBadParameter;
5355 }
5356 buf.m.planes = plane;
5357 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005358 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 -07005359 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
5360 if (rc) {
5361 /*TODO: How to handle this case */
5362 return OMX_ErrorInsufficientResources;
5363 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005364
Arun Menon906de572013-06-18 17:01:40 -07005365 if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) {
5366 enum v4l2_buf_type buf_type;
5367 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5368 rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
5369 if (rc) {
5370 return OMX_ErrorInsufficientResources;
5371 } else {
5372 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005373 DEBUG_PRINT_LOW("STREAMON Successful");
Arun Menon906de572013-06-18 17:01:40 -07005374 }
5375 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005376
Arun Menon906de572013-06-18 17:01:40 -07005377 (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr;
5378 (*bufferHdr)->pAppPrivate = appData;
5379 BITMASK_SET(&m_out_bm_count,i);
5380 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005381 DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient");
Arun Menon906de572013-06-18 17:01:40 -07005382 eRet = OMX_ErrorInsufficientResources;
5383 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005384 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005385
Arun Menon906de572013-06-18 17:01:40 -07005386 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005387}
5388
5389
5390// AllocateBuffer -- API Call
5391/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005392 FUNCTION
5393 omx_vdec::AllocateBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005394
Arun Menon906de572013-06-18 17:01:40 -07005395 DESCRIPTION
5396 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07005397
Arun Menon906de572013-06-18 17:01:40 -07005398 PARAMETERS
5399 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005400
Arun Menon906de572013-06-18 17:01:40 -07005401 RETURN VALUE
5402 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005403
Arun Menon906de572013-06-18 17:01:40 -07005404 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005405OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005406 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5407 OMX_IN OMX_U32 port,
5408 OMX_IN OMX_PTR appData,
5409 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005410{
5411 unsigned i = 0;
5412 OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type
5413
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005414 DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port);
Arun Menon906de572013-06-18 17:01:40 -07005415 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005416 DEBUG_PRINT_ERROR("Allocate Buf in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005417 return OMX_ErrorInvalidState;
5418 }
5419
Arun Menon906de572013-06-18 17:01:40 -07005420 if (port == OMX_CORE_INPUT_PORT_INDEX) {
5421 if (arbitrary_bytes) {
5422 eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes);
5423 } else {
5424 eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes);
5425 }
5426 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Vinay Kaliada4f4422013-01-09 10:45:03 -08005427 eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port,
5428 appData,bytes);
Arun Menon906de572013-06-18 17:01:40 -07005429 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005430 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07005431 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005432 }
5433 DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done");
Arun Menon906de572013-06-18 17:01:40 -07005434 if (eRet == OMX_ErrorNone) {
5435 if (allocate_done()) {
5436 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005437 // Send the callback now
5438 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
5439 post_event(OMX_CommandStateSet,OMX_StateIdle,
Arun Menon906de572013-06-18 17:01:40 -07005440 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005441 }
5442 }
Arun Menon906de572013-06-18 17:01:40 -07005443 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) {
5444 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
5445 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
5446 post_event(OMX_CommandPortEnable,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005447 OMX_CORE_INPUT_PORT_INDEX,
5448 OMX_COMPONENT_GENERATE_EVENT);
Arun Menon906de572013-06-18 17:01:40 -07005449 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005450 }
Arun Menon906de572013-06-18 17:01:40 -07005451 if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) {
5452 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
5453 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005454 post_event(OMX_CommandPortEnable,
Arun Menon906de572013-06-18 17:01:40 -07005455 OMX_CORE_OUTPUT_PORT_INDEX,
5456 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005457 }
5458 }
5459 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005460 DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005461 return eRet;
5462}
5463
5464// Free Buffer - API call
5465/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005466 FUNCTION
5467 omx_vdec::FreeBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005468
Arun Menon906de572013-06-18 17:01:40 -07005469 DESCRIPTION
Shalaj Jain273b3e02012-06-22 19:08:03 -07005470
Arun Menon906de572013-06-18 17:01:40 -07005471 PARAMETERS
5472 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005473
Arun Menon906de572013-06-18 17:01:40 -07005474 RETURN VALUE
5475 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005476
Arun Menon906de572013-06-18 17:01:40 -07005477 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005478OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005479 OMX_IN OMX_U32 port,
5480 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005481{
5482 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5483 unsigned int nPortIndex;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005484 DEBUG_PRINT_LOW("In for decoder free_buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005485
Arun Menon906de572013-06-18 17:01:40 -07005486 if (m_state == OMX_StateIdle &&
5487 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005488 DEBUG_PRINT_LOW(" free buffer while Component in Loading pending");
Arun Menon906de572013-06-18 17:01:40 -07005489 } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)||
5490 (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005491 DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port);
Arun Menon906de572013-06-18 17:01:40 -07005492 } else if ((port == OMX_CORE_INPUT_PORT_INDEX &&
5493 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) ||
5494 (port == OMX_CORE_OUTPUT_PORT_INDEX &&
5495 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005496 DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port);
Arun Menon906de572013-06-18 17:01:40 -07005497 } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005498 DEBUG_PRINT_ERROR("Invalid state to free buffer,ports need to be disabled");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005499 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005500 OMX_ErrorPortUnpopulated,
5501 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005502
5503 return OMX_ErrorIncorrectStateOperation;
Arun Menon906de572013-06-18 17:01:40 -07005504 } else if (m_state != OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005505 DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005506 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005507 OMX_ErrorPortUnpopulated,
5508 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005509 }
5510
Arun Menon906de572013-06-18 17:01:40 -07005511 if (port == OMX_CORE_INPUT_PORT_INDEX) {
5512 /*Check if arbitrary bytes*/
5513 if (!arbitrary_bytes && !input_use_buffer)
5514 nPortIndex = buffer - m_inp_mem_ptr;
5515 else
5516 nPortIndex = buffer - m_inp_heap_ptr;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005517
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005518 DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %d", nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005519 if (nPortIndex < drv_ctx.ip_buf.actualcount) {
5520 // Clear the bit associated with it.
5521 BITMASK_CLEAR(&m_inp_bm_count,nPortIndex);
5522 BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex);
5523 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005524
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005525 DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005526 if (m_phdr_pmem_ptr)
5527 free_input_buffer(m_phdr_pmem_ptr[nPortIndex]);
5528 } else {
5529 if (arbitrary_bytes) {
5530 if (m_phdr_pmem_ptr)
5531 free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]);
5532 else
5533 free_input_buffer(nPortIndex,NULL);
5534 } else
5535 free_input_buffer(buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005536 }
Arun Menon906de572013-06-18 17:01:40 -07005537 m_inp_bPopulated = OMX_FALSE;
Surajit Podder12aefac2013-08-06 18:43:32 +05305538 if(release_input_done())
5539 release_buffers(this, VDEC_BUFFER_TYPE_INPUT);
Arun Menon906de572013-06-18 17:01:40 -07005540 /*Free the Buffer Header*/
5541 if (release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005542 DEBUG_PRINT_HIGH("ALL input buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07005543 free_input_buffer_header();
5544 }
5545 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005546 DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005547 eRet = OMX_ErrorBadPortIndex;
5548 }
5549
Arun Menon906de572013-06-18 17:01:40 -07005550 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING)
5551 && release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005552 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005553 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING);
5554 post_event(OMX_CommandPortDisable,
Arun Menon906de572013-06-18 17:01:40 -07005555 OMX_CORE_INPUT_PORT_INDEX,
5556 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005557 }
Arun Menon906de572013-06-18 17:01:40 -07005558 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005559 // check if the buffer is valid
Vinay Kaliada4f4422013-01-09 10:45:03 -08005560 nPortIndex = buffer - client_buffers.get_il_buf_hdr();
Arun Menon906de572013-06-18 17:01:40 -07005561 if (nPortIndex < drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005562 DEBUG_PRINT_LOW("free_buffer on o/p port - Port idx %d", nPortIndex);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005563 // Clear the bit associated with it.
5564 BITMASK_CLEAR(&m_out_bm_count,nPortIndex);
5565 m_out_bPopulated = OMX_FALSE;
Vinay Kaliada4f4422013-01-09 10:45:03 -08005566 client_buffers.free_output_buffer (buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005567
Surajit Podder12aefac2013-08-06 18:43:32 +05305568 if(release_output_done()) {
5569 release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT);
5570 }
Arun Menon906de572013-06-18 17:01:40 -07005571 if (release_output_done()) {
5572 free_output_buffer_header();
Shalaj Jain273b3e02012-06-22 19:08:03 -07005573 }
Arun Menon906de572013-06-18 17:01:40 -07005574 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005575 DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005576 eRet = OMX_ErrorBadPortIndex;
5577 }
Arun Menon906de572013-06-18 17:01:40 -07005578 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING)
5579 && release_output_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005580 DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005581
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005582 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Arun Menon906de572013-06-18 17:01:40 -07005583 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005584#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -07005585 if (m_enable_android_native_buffers) {
5586 DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers");
5587 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
5588 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005589#endif
5590
Arun Menon906de572013-06-18 17:01:40 -07005591 post_event(OMX_CommandPortDisable,
5592 OMX_CORE_OUTPUT_PORT_INDEX,
5593 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005594 }
Arun Menon906de572013-06-18 17:01:40 -07005595 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005596 eRet = OMX_ErrorBadPortIndex;
5597 }
Arun Menon906de572013-06-18 17:01:40 -07005598 if ((eRet == OMX_ErrorNone) &&
5599 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
5600 if (release_done()) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005601 // Send the callback now
5602 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING);
5603 post_event(OMX_CommandStateSet, OMX_StateLoaded,
Arun Menon906de572013-06-18 17:01:40 -07005604 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005605 }
5606 }
5607 return eRet;
5608}
5609
5610
5611/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005612 FUNCTION
5613 omx_vdec::EmptyThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005614
Arun Menon906de572013-06-18 17:01:40 -07005615 DESCRIPTION
5616 This routine is used to push the encoded video frames to
5617 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005618
Arun Menon906de572013-06-18 17:01:40 -07005619 PARAMETERS
5620 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005621
Arun Menon906de572013-06-18 17:01:40 -07005622 RETURN VALUE
5623 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005624
Arun Menon906de572013-06-18 17:01:40 -07005625 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005626OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005627 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005628{
Arun Menon906de572013-06-18 17:01:40 -07005629 OMX_ERRORTYPE ret1 = OMX_ErrorNone;
5630 unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005631
Arun Menon906de572013-06-18 17:01:40 -07005632 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005633 DEBUG_PRINT_ERROR("Empty this buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07005634 return OMX_ErrorInvalidState;
5635 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005636
Arun Menon906de572013-06-18 17:01:40 -07005637 if (buffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005638 DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL");
Arun Menon906de572013-06-18 17:01:40 -07005639 return OMX_ErrorBadParameter;
5640 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005641
Arun Menon906de572013-06-18 17:01:40 -07005642 if (!m_inp_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005643 DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07005644 return OMX_ErrorIncorrectStateOperation;
5645 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005646
Arun Menon906de572013-06-18 17:01:40 -07005647 if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005648 DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005649 return OMX_ErrorBadPortIndex;
5650 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005651
5652#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005653 if (iDivXDrmDecrypt) {
5654 OMX_ERRORTYPE drmErr = iDivXDrmDecrypt->Decrypt(buffer);
5655 if (drmErr != OMX_ErrorNone) {
5656 // this error can be ignored
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005657 DEBUG_PRINT_LOW("ERROR:iDivXDrmDecrypt->Decrypt %d", drmErr);
Arun Menon906de572013-06-18 17:01:40 -07005658 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005659 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005660#endif //_ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005661 if (perf_flag) {
5662 if (!latency) {
5663 dec_time.stop();
5664 latency = dec_time.processing_time_us();
5665 dec_time.start();
5666 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005667 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005668
Arun Menon906de572013-06-18 17:01:40 -07005669 if (arbitrary_bytes) {
5670 nBufferIndex = buffer - m_inp_heap_ptr;
5671 } else {
5672 if (input_use_buffer == true) {
5673 nBufferIndex = buffer - m_inp_heap_ptr;
5674 m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen;
5675 m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp;
5676 m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags;
5677 buffer = &m_inp_mem_ptr[nBufferIndex];
5678 DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu",
5679 &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen);
5680 } else {
5681 nBufferIndex = buffer - m_inp_mem_ptr;
5682 }
5683 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005684
Arun Menon906de572013-06-18 17:01:40 -07005685 if (nBufferIndex > drv_ctx.ip_buf.actualcount ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005686 DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005687 return OMX_ErrorBadParameter;
5688 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005689
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07005690 if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
5691 codec_config_flag = true;
5692 DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__);
5693 }
5694
Arun Menon906de572013-06-18 17:01:40 -07005695 DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)",
5696 buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen);
5697 if (arbitrary_bytes) {
5698 post_event ((unsigned)hComp,(unsigned)buffer,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005699 OMX_COMPONENT_GENERATE_ETB_ARBITRARY);
Arun Menon906de572013-06-18 17:01:40 -07005700 } else {
Arun Menon906de572013-06-18 17:01:40 -07005701 post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB);
5702 }
5703 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005704}
5705
5706/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005707 FUNCTION
5708 omx_vdec::empty_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07005709
Arun Menon906de572013-06-18 17:01:40 -07005710 DESCRIPTION
5711 This routine is used to push the encoded video frames to
5712 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005713
Arun Menon906de572013-06-18 17:01:40 -07005714 PARAMETERS
5715 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005716
Arun Menon906de572013-06-18 17:01:40 -07005717 RETURN VALUE
5718 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005719
Arun Menon906de572013-06-18 17:01:40 -07005720 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005721OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005722 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005723{
Arun Menon906de572013-06-18 17:01:40 -07005724 int push_cnt = 0,i=0;
5725 unsigned nPortIndex = 0;
5726 OMX_ERRORTYPE ret = OMX_ErrorNone;
5727 struct vdec_input_frameinfo frameinfo;
5728 struct vdec_bufferpayload *temp_buffer;
5729 struct vdec_seqheader seq_header;
5730 bool port_setting_changed = true;
5731 bool not_coded_vop = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005732
Arun Menon906de572013-06-18 17:01:40 -07005733 /*Should we generate a Aync error event*/
5734 if (buffer == NULL || buffer->pInputPortPrivate == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005735 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005736 return OMX_ErrorBadParameter;
5737 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005738
Arun Menon906de572013-06-18 17:01:40 -07005739 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005740
Arun Menon906de572013-06-18 17:01:40 -07005741 if (nPortIndex > drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005742 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]",
Arun Menon906de572013-06-18 17:01:40 -07005743 nPortIndex);
5744 return OMX_ErrorBadParameter;
5745 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005746
Arun Menon906de572013-06-18 17:01:40 -07005747 pending_input_buffers++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005748
Arun Menon906de572013-06-18 17:01:40 -07005749 /* return zero length and not an EOS buffer */
5750 if (!arbitrary_bytes && (buffer->nFilledLen == 0) &&
5751 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005752 DEBUG_PRINT_HIGH("return zero legth buffer");
Arun Menon906de572013-06-18 17:01:40 -07005753 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5754 OMX_COMPONENT_GENERATE_EBD);
5755 return OMX_ErrorNone;
5756 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005757
5758
Deva Ramasubramanian286a3582014-08-25 18:09:38 -07005759 if (ignore_not_coded_vops &&
5760 (codec_type_parse == CODEC_TYPE_MPEG4 ||
5761 codec_type_parse == CODEC_TYPE_DIVX)) {
Arun Menon906de572013-06-18 17:01:40 -07005762 mp4StreamType psBits;
5763 psBits.data = (unsigned char *)(buffer->pBuffer + buffer->nOffset);
5764 psBits.numBytes = buffer->nFilledLen;
5765 mp4_headerparser.parseHeader(&psBits);
5766 not_coded_vop = mp4_headerparser.is_notcodec_vop(
5767 (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen);
5768 if (not_coded_vop) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005769 DEBUG_PRINT_HIGH("Found Not coded vop len %lu frame number %u",
Arun Menon906de572013-06-18 17:01:40 -07005770 buffer->nFilledLen,frame_count);
5771 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005772 DEBUG_PRINT_HIGH("Eos and Not coded Vop set len to zero");
Arun Menon906de572013-06-18 17:01:40 -07005773 not_coded_vop = false;
5774 buffer->nFilledLen = 0;
5775 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005776 }
5777 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005778
Arun Menon906de572013-06-18 17:01:40 -07005779 if (input_flush_progress == true
Shalaj Jain273b3e02012-06-22 19:08:03 -07005780
Arun Menon906de572013-06-18 17:01:40 -07005781 || not_coded_vop
Shalaj Jain273b3e02012-06-22 19:08:03 -07005782
Arun Menon906de572013-06-18 17:01:40 -07005783 ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005784 DEBUG_PRINT_LOW("Flush in progress return buffer ");
Arun Menon906de572013-06-18 17:01:40 -07005785 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5786 OMX_COMPONENT_GENERATE_EBD);
5787 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005788 }
5789
Arun Menon906de572013-06-18 17:01:40 -07005790 temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005791
Surajit Podderd2644d52013-08-28 17:59:06 +05305792 if ((temp_buffer - drv_ctx.ptr_inputbuffer) > (int)drv_ctx.ip_buf.actualcount) {
Arun Menon906de572013-06-18 17:01:40 -07005793 return OMX_ErrorBadParameter;
5794 }
5795 /* If its first frame, H264 codec and reject is true, then parse the nal
5796 and get the profile. Based on this, reject the clip playback */
5797 if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 &&
5798 m_reject_avc_1080p_mp) {
5799 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005800 DEBUG_PRINT_ERROR("Parse nal to get the profile");
Arun Menon906de572013-06-18 17:01:40 -07005801 h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen,
5802 NALU_TYPE_SPS);
5803 m_profile = h264_parser->get_profile();
5804 ret = is_video_session_supported();
5805 if (ret) {
5806 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD);
5807 post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT);
5808 /* Move the state to Invalid to avoid queueing of pending ETB to the driver */
5809 m_state = OMX_StateInvalid;
5810 return OMX_ErrorNone;
5811 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005812 }
5813
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005814 DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
Arun Menon906de572013-06-18 17:01:40 -07005815 /*for use buffer we need to memcpy the data*/
5816 temp_buffer->buffer_len = buffer->nFilledLen;
5817
5818 if (input_use_buffer) {
5819 if (buffer->nFilledLen <= temp_buffer->buffer_len) {
5820 if (arbitrary_bytes) {
5821 memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen);
5822 } else {
5823 memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset),
5824 buffer->nFilledLen);
5825 }
5826 } else {
5827 return OMX_ErrorBadParameter;
5828 }
5829
5830 }
5831
5832 frameinfo.bufferaddr = temp_buffer->bufferaddr;
5833 frameinfo.client_data = (void *) buffer;
5834 frameinfo.datalen = temp_buffer->buffer_len;
5835 frameinfo.flags = 0;
5836 frameinfo.offset = buffer->nOffset;
5837 frameinfo.pmem_fd = temp_buffer->pmem_fd;
5838 frameinfo.pmem_offset = temp_buffer->offset;
5839 frameinfo.timestamp = buffer->nTimeStamp;
5840 if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) {
5841 DEBUG_PRINT_LOW("ETB: dmx enabled");
5842 if (m_demux_entries == 0) {
5843 extract_demux_addr_offsets(buffer);
5844 }
5845
5846 DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries);
5847 handle_demux_data(buffer);
5848 frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr;
5849 frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size;
5850 } else {
5851 frameinfo.desc_addr = NULL;
5852 frameinfo.desc_size = 0;
5853 }
5854 if (!arbitrary_bytes) {
5855 frameinfo.flags |= buffer->nFlags;
5856 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005857
5858#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005859 if (m_debug_timestamp) {
5860 if (arbitrary_bytes) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005861 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005862 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5863 } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005864 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005865 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5866 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005867 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005868#endif
5869
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005870log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005871
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005872if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Arun Menon906de572013-06-18 17:01:40 -07005873 frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5874 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5875 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005876
Arun Menon906de572013-06-18 17:01:40 -07005877 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005878 DEBUG_PRINT_HIGH("Rxd i/p EOS, Notify Driver that EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07005879 frameinfo.flags |= VDEC_BUFFERFLAG_EOS;
5880 h264_scratch.nFilledLen = 0;
5881 nal_count = 0;
5882 look_ahead_nal = false;
5883 frame_count = 0;
5884 if (m_frame_parser.mutils)
5885 m_frame_parser.mutils->initialize_frame_checking_environment();
5886 m_frame_parser.flush();
5887 h264_last_au_ts = LLONG_MAX;
5888 h264_last_au_flags = 0;
5889 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
5890 m_demux_entries = 0;
5891 }
5892 struct v4l2_buffer buf;
5893 struct v4l2_plane plane;
5894 memset( (void *)&buf, 0, sizeof(buf));
5895 memset( (void *)&plane, 0, sizeof(plane));
5896 int rc;
5897 unsigned long print_count;
5898 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07005899 buf.flags = V4L2_QCOM_BUF_FLAG_EOS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005900 DEBUG_PRINT_HIGH("INPUT EOS reached") ;
Arun Menon906de572013-06-18 17:01:40 -07005901 }
5902 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5903 buf.index = nPortIndex;
5904 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
5905 buf.memory = V4L2_MEMORY_USERPTR;
5906 plane.bytesused = temp_buffer->buffer_len;
5907 plane.length = drv_ctx.ip_buf.buffer_size;
5908 plane.m.userptr = (unsigned long)temp_buffer->bufferaddr -
5909 (unsigned long)temp_buffer->offset;
5910 plane.reserved[0] = temp_buffer->pmem_fd;
5911 plane.reserved[1] = temp_buffer->offset;
5912 plane.data_offset = 0;
5913 buf.m.planes = &plane;
5914 buf.length = 1;
5915 if (frameinfo.timestamp >= LLONG_MAX) {
5916 buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID;
5917 }
5918 //assumption is that timestamp is in milliseconds
5919 buf.timestamp.tv_sec = frameinfo.timestamp / 1000000;
5920 buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000);
5921 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0;
5922 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_DECODEONLY) ? V4L2_QCOM_BUF_FLAG_DECODEONLY: 0;
Deva Ramasubramanian46a17952012-08-24 11:35:26 -07005923
Arun Menon906de572013-06-18 17:01:40 -07005924 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
5925 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005926 DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver");
Arun Menon906de572013-06-18 17:01:40 -07005927 return OMX_ErrorHardware;
5928 }
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07005929 if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
5930 codec_config_flag = false;
5931 }
Arun Menon906de572013-06-18 17:01:40 -07005932 if (!streaming[OUTPUT_PORT]) {
5933 enum v4l2_buf_type buf_type;
5934 int ret,r;
Vinay Kalia85793762012-06-14 19:12:34 -07005935
Arun Menon906de572013-06-18 17:01:40 -07005936 buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005937 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07005938 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
5939 if (!ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005940 DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful");
Arun Menon906de572013-06-18 17:01:40 -07005941 streaming[OUTPUT_PORT] = true;
Jia Meng1e236c82014-04-03 10:54:39 +08005942 } else if (errno == EBUSY) {
5943 DEBUG_PRINT_ERROR("Failed to call stream on OUTPUT due to HW_OVERLOAD");
5944 post_event ((unsigned int)buffer, VDEC_S_SUCCESS,
5945 OMX_COMPONENT_GENERATE_EBD);
5946 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07005947 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005948 DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT");
Arun Menon906de572013-06-18 17:01:40 -07005949 DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued");
Jia Meng1e236c82014-04-03 10:54:39 +08005950 post_event ((unsigned int)buffer, VDEC_S_SUCCESS,
Arun Menon906de572013-06-18 17:01:40 -07005951 OMX_COMPONENT_GENERATE_EBD);
5952 return OMX_ErrorBadParameter;
5953 }
5954 }
5955 DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)",
5956 frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen);
5957 time_stamp_dts.insert_timestamp(buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005958
Arun Menon906de572013-06-18 17:01:40 -07005959 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005960}
5961
5962/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005963 FUNCTION
5964 omx_vdec::FillThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005965
Arun Menon906de572013-06-18 17:01:40 -07005966 DESCRIPTION
5967 IL client uses this method to release the frame buffer
5968 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005969
Arun Menon906de572013-06-18 17:01:40 -07005970 PARAMETERS
5971 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005972
Arun Menon906de572013-06-18 17:01:40 -07005973 RETURN VALUE
5974 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005975
Arun Menon906de572013-06-18 17:01:40 -07005976 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005977OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005978 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005979{
Arun Menonbdb80b02013-08-12 17:45:54 -07005980 if (dynamic_buf_mode) {
5981 private_handle_t *handle = NULL;
5982 struct VideoDecoderOutputMetaData *meta;
Arun Menonbdb80b02013-08-12 17:45:54 -07005983 unsigned int nPortIndex = 0;
5984
5985 if (!buffer || !buffer->pBuffer) {
Arun Menon8544ead2014-05-08 17:42:29 -07005986 DEBUG_PRINT_ERROR("%s: invalid params: %p", __FUNCTION__, buffer);
Arun Menonbdb80b02013-08-12 17:45:54 -07005987 return OMX_ErrorBadParameter;
5988 }
5989
5990 //get the buffer type and fd info
5991 meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer;
5992 handle = (private_handle_t *)meta->pHandle;
Arun Menonb49abf22013-12-14 21:38:10 -08005993 DEBUG_PRINT_LOW("FTB: metabuf: %p buftype: %d bufhndl: %p ", meta, meta->eType, meta->pHandle);
5994
5995 if (!handle) {
5996 DEBUG_PRINT_ERROR("FTB: Error: IL client passed an invalid buf handle - %p", handle);
5997 return OMX_ErrorBadParameter;
5998 }
Arun Menonbdb80b02013-08-12 17:45:54 -07005999 //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF
6000 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
6001 drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd;
Arun Menon50ab1bf2014-01-08 18:02:19 -08006002 drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = (OMX_U8*) buffer;
ApurupaPattapuf693a4d2013-12-04 16:07:07 -08006003
6004 //Store private handle from GraphicBuffer
6005 native_buffer[nPortIndex].privatehandle = handle;
6006 native_buffer[nPortIndex].nativehandle = handle;
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07006007
6008 //buffer->nAllocLen will be sizeof(struct VideoDecoderOutputMetaData). Overwrite
6009 //this with a more sane size so that we don't compensate in rest of code
6010 //We'll restore this size later on, so that it's transparent to client
6011 buffer->nFilledLen = 0;
Deva Ramasubramanian03a5bb92014-04-25 19:03:50 -07006012 buffer->nAllocLen = handle->size;
Arun Menonbdb80b02013-08-12 17:45:54 -07006013 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006014
Arun Menon906de572013-06-18 17:01:40 -07006015 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006016 DEBUG_PRINT_ERROR("FTB in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07006017 return OMX_ErrorInvalidState;
6018 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006019
Arun Menon906de572013-06-18 17:01:40 -07006020 if (!m_out_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006021 DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07006022 return OMX_ErrorIncorrectStateOperation;
6023 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006024
Arun Menon906de572013-06-18 17:01:40 -07006025 if (buffer == NULL ||
Surajit Podderd2644d52013-08-28 17:59:06 +05306026 ((buffer - client_buffers.get_il_buf_hdr()) >= (int)drv_ctx.op_buf.actualcount)) {
Arun Menon906de572013-06-18 17:01:40 -07006027 return OMX_ErrorBadParameter;
6028 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006029
Arun Menon906de572013-06-18 17:01:40 -07006030 if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006031 DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07006032 return OMX_ErrorBadPortIndex;
6033 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006034
Arun Menon906de572013-06-18 17:01:40 -07006035 DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
6036 post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg);
6037 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006038}
6039/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006040 FUNCTION
6041 omx_vdec::fill_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07006042
Arun Menon906de572013-06-18 17:01:40 -07006043 DESCRIPTION
6044 IL client uses this method to release the frame buffer
6045 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006046
Arun Menon906de572013-06-18 17:01:40 -07006047 PARAMETERS
6048 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006049
Arun Menon906de572013-06-18 17:01:40 -07006050 RETURN VALUE
6051 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006052
Arun Menon906de572013-06-18 17:01:40 -07006053 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006054OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy(
Arun Menon906de572013-06-18 17:01:40 -07006055 OMX_IN OMX_HANDLETYPE hComp,
6056 OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006057{
Arun Menon906de572013-06-18 17:01:40 -07006058 OMX_ERRORTYPE nRet = OMX_ErrorNone;
6059 OMX_BUFFERHEADERTYPE *buffer = bufferAdd;
6060 unsigned nPortIndex = 0;
6061 struct vdec_fillbuffer_cmd fillbuffer;
6062 struct vdec_bufferpayload *ptr_outputbuffer = NULL;
6063 struct vdec_output_frameinfo *ptr_respbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006064
Arun Menon906de572013-06-18 17:01:40 -07006065 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
Shalaj Jain273b3e02012-06-22 19:08:03 -07006066
Arun Menon906de572013-06-18 17:01:40 -07006067 if (bufferAdd == NULL || nPortIndex > drv_ctx.op_buf.actualcount)
6068 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006069
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006070 DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006071 bufferAdd, bufferAdd->pBuffer);
6072 /*Return back the output buffer to client*/
6073 if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006074 DEBUG_PRINT_LOW("Output Buffers return flush/disable condition");
Arun Menon906de572013-06-18 17:01:40 -07006075 buffer->nFilledLen = 0;
6076 m_cb.FillBufferDone (hComp,m_app_data,buffer);
6077 return OMX_ErrorNone;
6078 }
Arun Menon50ab1bf2014-01-08 18:02:19 -08006079
6080 if (dynamic_buf_mode) {
6081 //map the buffer handle based on the size set on output port definition.
6082 if (!secure_mode) {
6083 drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr =
6084 (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size,
6085 PROT_READ|PROT_WRITE, MAP_SHARED,
6086 drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, 0);
6087 }
6088 drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0;
6089 drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size;
6090 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size;
6091 buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd,
6092 drv_ctx.ptr_outputbuffer[nPortIndex].offset);
6093 }
6094
Arun Menon906de572013-06-18 17:01:40 -07006095 pending_output_buffers++;
6096 buffer = client_buffers.get_dr_buf_hdr(bufferAdd);
6097 ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate;
6098 if (ptr_respbuffer) {
6099 ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data;
6100 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006101
Arun Menon906de572013-06-18 17:01:40 -07006102 if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) {
6103 DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL");
6104 buffer->nFilledLen = 0;
6105 m_cb.FillBufferDone (hComp,m_app_data,buffer);
6106 pending_output_buffers--;
6107 return OMX_ErrorBadParameter;
6108 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006109
Arun Menon906de572013-06-18 17:01:40 -07006110 int rc = 0;
6111 struct v4l2_buffer buf;
6112 struct v4l2_plane plane[VIDEO_MAX_PLANES];
6113 memset( (void *)&buf, 0, sizeof(buf));
6114 memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES));
Arun Menon8544ead2014-05-08 17:42:29 -07006115 unsigned int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006116
Arun Menon906de572013-06-18 17:01:40 -07006117 buf.index = nPortIndex;
6118 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
6119 buf.memory = V4L2_MEMORY_USERPTR;
6120 plane[0].bytesused = buffer->nFilledLen;
6121 plane[0].length = drv_ctx.op_buf.buffer_size;
6122 plane[0].m.userptr =
6123 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr -
6124 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset;
6125 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd;
6126 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset;
6127 plane[0].data_offset = 0;
6128 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
6129 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
6130 plane[extra_idx].bytesused = 0;
6131 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
6132 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 -07006133#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07006134 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07006135#endif
Arun Menon906de572013-06-18 17:01:40 -07006136 plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size;
6137 plane[extra_idx].data_offset = 0;
6138 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Arun Menon8544ead2014-05-08 17:42:29 -07006139 DEBUG_PRINT_ERROR("Extradata index higher than expected: %u", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07006140 return OMX_ErrorBadParameter;
6141 }
6142 buf.m.planes = plane;
6143 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006144 DEBUG_PRINT_LOW("SENDING FTB TO F/W - fd[0] = %d fd[1] = %d offset[1] = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07006145 plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]);
6146
Arun Menon906de572013-06-18 17:01:40 -07006147 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
6148 if (rc) {
6149 /*TODO: How to handle this case */
6150 DEBUG_PRINT_ERROR("Failed to qbuf to driver");
6151 }
Arun Menon906de572013-06-18 17:01:40 -07006152return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006153}
6154
6155/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006156 FUNCTION
6157 omx_vdec::SetCallbacks
Shalaj Jain273b3e02012-06-22 19:08:03 -07006158
Arun Menon906de572013-06-18 17:01:40 -07006159 DESCRIPTION
6160 Set the callbacks.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006161
Arun Menon906de572013-06-18 17:01:40 -07006162 PARAMETERS
6163 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006164
Arun Menon906de572013-06-18 17:01:40 -07006165 RETURN VALUE
6166 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006167
Arun Menon906de572013-06-18 17:01:40 -07006168 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006169OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006170 OMX_IN OMX_CALLBACKTYPE* callbacks,
6171 OMX_IN OMX_PTR appData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006172{
6173
Arun Menon906de572013-06-18 17:01:40 -07006174 m_cb = *callbacks;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006175 DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\
Arun Menon906de572013-06-18 17:01:40 -07006176 m_cb.EventHandler,m_cb.FillBufferDone);
6177 m_app_data = appData;
6178 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006179}
6180
6181/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006182 FUNCTION
6183 omx_vdec::ComponentDeInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07006184
Arun Menon906de572013-06-18 17:01:40 -07006185 DESCRIPTION
6186 Destroys the component and release memory allocated to the heap.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006187
Arun Menon906de572013-06-18 17:01:40 -07006188 PARAMETERS
6189 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006190
Arun Menon906de572013-06-18 17:01:40 -07006191 RETURN VALUE
6192 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006193
Arun Menon906de572013-06-18 17:01:40 -07006194 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006195OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
6196{
6197#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07006198 if (iDivXDrmDecrypt) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006199 delete iDivXDrmDecrypt;
6200 iDivXDrmDecrypt=NULL;
6201 }
6202#endif //_ANDROID_
6203
Shalaj Jain286b0062013-02-21 20:35:48 -08006204 unsigned i = 0;
Arun Menon906de572013-06-18 17:01:40 -07006205 if (OMX_StateLoaded != m_state) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006206 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\
Arun Menon906de572013-06-18 17:01:40 -07006207 m_state);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006208 DEBUG_PRINT_ERROR("Playback Ended - FAILED");
Arun Menon906de572013-06-18 17:01:40 -07006209 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006210 DEBUG_PRINT_HIGH("Playback Ended - PASSED");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006211 }
6212
6213 /*Check if the output buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07006214 if (m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006215 DEBUG_PRINT_LOW("Freeing the Output Memory");
Arun Menon906de572013-06-18 17:01:40 -07006216 for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) {
6217 free_output_buffer (&m_out_mem_ptr[i]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006218 }
6219#ifdef _ANDROID_ICS_
6220 memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
6221#endif
6222 }
6223
6224 /*Check if the input buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07006225 if (m_inp_mem_ptr || m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006226 DEBUG_PRINT_LOW("Freeing the Input Memory");
Arun Menon906de572013-06-18 17:01:40 -07006227 for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) {
6228 if (m_inp_mem_ptr)
6229 free_input_buffer (i,&m_inp_mem_ptr[i]);
6230 else
6231 free_input_buffer (i,NULL);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006232 }
6233 }
6234 free_input_buffer_header();
6235 free_output_buffer_header();
Arun Menon906de572013-06-18 17:01:40 -07006236 if (h264_scratch.pBuffer) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006237 free(h264_scratch.pBuffer);
6238 h264_scratch.pBuffer = NULL;
6239 }
6240
Arun Menon906de572013-06-18 17:01:40 -07006241 if (h264_parser) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006242 delete h264_parser;
Arun Menon906de572013-06-18 17:01:40 -07006243 h264_parser = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006244 }
6245
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07006246 if (m_frame_parser.mutils) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006247 DEBUG_PRINT_LOW("Free utils parser");
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07006248 delete (m_frame_parser.mutils);
6249 m_frame_parser.mutils = NULL;
6250 }
6251
Arun Menon906de572013-06-18 17:01:40 -07006252 if (m_platform_list) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006253 free(m_platform_list);
6254 m_platform_list = NULL;
6255 }
Arun Menon906de572013-06-18 17:01:40 -07006256 if (m_vendor_config.pData) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006257 free(m_vendor_config.pData);
6258 m_vendor_config.pData = NULL;
6259 }
6260
6261 // Reset counters in mesg queues
6262 m_ftb_q.m_size=0;
6263 m_cmd_q.m_size=0;
6264 m_etb_q.m_size=0;
6265 m_ftb_q.m_read = m_ftb_q.m_write =0;
6266 m_cmd_q.m_read = m_cmd_q.m_write =0;
6267 m_etb_q.m_read = m_etb_q.m_write =0;
6268#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07006269 if (m_debug_timestamp) {
6270 m_timestamp_list.reset_ts_list();
Shalaj Jain273b3e02012-06-22 19:08:03 -07006271 }
6272#endif
6273
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006274 DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006275 //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG,
Arun Menon906de572013-06-18 17:01:40 -07006276 // NULL);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006277 DEBUG_PRINT_HIGH("Close the driver instance");
Arun Menon906de572013-06-18 17:01:40 -07006278
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07006279 if (m_debug.infile) {
6280 fclose(m_debug.infile);
6281 m_debug.infile = NULL;
6282 }
6283 if (m_debug.outfile) {
6284 fclose(m_debug.outfile);
6285 m_debug.outfile = NULL;
6286 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006287#ifdef OUTPUT_EXTRADATA_LOG
Shalaj Jainaf08f302013-03-18 13:15:35 -07006288 if (outputExtradataFile)
6289 fclose (outputExtradataFile);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006290#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006291 DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete");
Arun Menon906de572013-06-18 17:01:40 -07006292 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006293}
6294
6295/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006296 FUNCTION
6297 omx_vdec::UseEGLImage
Shalaj Jain273b3e02012-06-22 19:08:03 -07006298
Arun Menon906de572013-06-18 17:01:40 -07006299 DESCRIPTION
6300 OMX Use EGL Image method implementation <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006301
Arun Menon906de572013-06-18 17:01:40 -07006302 PARAMETERS
6303 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006304
Arun Menon906de572013-06-18 17:01:40 -07006305 RETURN VALUE
6306 Not Implemented error.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006307
Arun Menon906de572013-06-18 17:01:40 -07006308 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006309OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006310 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
6311 OMX_IN OMX_U32 port,
6312 OMX_IN OMX_PTR appData,
6313 OMX_IN void* eglImage)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006314{
Arun Menon906de572013-06-18 17:01:40 -07006315 OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list;
6316 OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry;
6317 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006318
6319#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07006320 PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc;
6321 EGLint fd = -1, offset = 0,pmemPtr = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006322#else
Arun Menon906de572013-06-18 17:01:40 -07006323 int fd = -1, offset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006324#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006325 DEBUG_PRINT_HIGH("use EGL image support for decoder");
Arun Menon906de572013-06-18 17:01:40 -07006326 if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006327 DEBUG_PRINT_ERROR("");
Arun Menon906de572013-06-18 17:01:40 -07006328 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006329#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07006330 if (m_display_id == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006331 DEBUG_PRINT_ERROR("Display ID is not set by IL client");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006332 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006333 }
6334 egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC)
6335 eglGetProcAddress("eglQueryImageKHR");
6336 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd);
6337 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset);
6338 egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006339#else //with OMX test app
6340 struct temp_egl {
6341 int pmem_fd;
6342 int offset;
6343 };
6344 struct temp_egl *temp_egl_id = NULL;
6345 void * pmemPtr = (void *) eglImage;
6346 temp_egl_id = (struct temp_egl *)eglImage;
Arun Menon906de572013-06-18 17:01:40 -07006347 if (temp_egl_id != NULL) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006348 fd = temp_egl_id->pmem_fd;
6349 offset = temp_egl_id->offset;
6350 }
6351#endif
6352 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006353 DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006354 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006355 }
6356 pmem_info.pmem_fd = (OMX_U32) fd;
6357 pmem_info.offset = (OMX_U32) offset;
6358 pmem_entry.entry = (void *) &pmem_info;
6359 pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
6360 pmem_list.entryList = &pmem_entry;
6361 pmem_list.nEntries = 1;
6362 ouput_egl_buffers = true;
6363 if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port,
6364 (void *)&pmem_list, drv_ctx.op_buf.buffer_size,
6365 (OMX_U8 *)pmemPtr)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006366 DEBUG_PRINT_ERROR("use buffer call failed for egl image");
Arun Menon906de572013-06-18 17:01:40 -07006367 return OMX_ErrorInsufficientResources;
6368 }
6369 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006370}
6371
6372/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006373 FUNCTION
6374 omx_vdec::ComponentRoleEnum
Shalaj Jain273b3e02012-06-22 19:08:03 -07006375
Arun Menon906de572013-06-18 17:01:40 -07006376 DESCRIPTION
6377 OMX Component Role Enum method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006378
Arun Menon906de572013-06-18 17:01:40 -07006379 PARAMETERS
6380 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006381
Arun Menon906de572013-06-18 17:01:40 -07006382 RETURN VALUE
6383 OMX Error None if everything is successful.
6384 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006385OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006386 OMX_OUT OMX_U8* role,
6387 OMX_IN OMX_U32 index)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006388{
Arun Menon906de572013-06-18 17:01:40 -07006389 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006390
Arun Menon906de572013-06-18 17:01:40 -07006391 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
6392 if ((0 == index) && role) {
6393 strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006394 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006395 } else {
6396 eRet = OMX_ErrorNoMore;
6397 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006398 }
Arun Menon906de572013-06-18 17:01:40 -07006399 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
6400 if ((0 == index) && role) {
6401 strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006402 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006403 } else {
6404 eRet = OMX_ErrorNoMore;
6405 }
6406 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
6407 if ((0 == index) && role) {
6408 strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006409 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006410 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006411 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006412 eRet = OMX_ErrorNoMore;
6413 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006414 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006415
Arun Menon906de572013-06-18 17:01:40 -07006416 else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
6417 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE))
6418 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07006419
Shalaj Jain273b3e02012-06-22 19:08:03 -07006420 {
Arun Menon906de572013-06-18 17:01:40 -07006421 if ((0 == index) && role) {
6422 strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006423 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006424 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006425 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006426 eRet = OMX_ErrorNoMore;
6427 }
6428 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
6429 if ((0 == index) && role) {
6430 strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006431 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006432 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006433 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006434 eRet = OMX_ErrorNoMore;
6435 }
6436 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
6437 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
6438 ) {
6439 if ((0 == index) && role) {
6440 strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006441 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006442 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006443 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006444 eRet = OMX_ErrorNoMore;
6445 }
6446 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
6447 if ((0 == index) && role) {
6448 strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006449 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006450 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006451 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006452 eRet = OMX_ErrorNoMore;
6453 }
6454 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006455 DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07006456 eRet = OMX_ErrorInvalidComponentName;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006457 }
Arun Menon906de572013-06-18 17:01:40 -07006458 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006459}
6460
6461
6462
6463
6464/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006465 FUNCTION
6466 omx_vdec::AllocateDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006467
Arun Menon906de572013-06-18 17:01:40 -07006468 DESCRIPTION
6469 Checks if entire buffer pool is allocated by IL Client or not.
6470 Need this to move to IDLE state.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006471
Arun Menon906de572013-06-18 17:01:40 -07006472 PARAMETERS
6473 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006474
Arun Menon906de572013-06-18 17:01:40 -07006475 RETURN VALUE
6476 true/false.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006477
Arun Menon906de572013-06-18 17:01:40 -07006478 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006479bool omx_vdec::allocate_done(void)
6480{
Arun Menon906de572013-06-18 17:01:40 -07006481 bool bRet = false;
6482 bool bRet_In = false;
6483 bool bRet_Out = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006484
Arun Menon906de572013-06-18 17:01:40 -07006485 bRet_In = allocate_input_done();
6486 bRet_Out = allocate_output_done();
Shalaj Jain273b3e02012-06-22 19:08:03 -07006487
Arun Menon906de572013-06-18 17:01:40 -07006488 if (bRet_In && bRet_Out) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006489 bRet = true;
6490 }
Arun Menon906de572013-06-18 17:01:40 -07006491
6492 return bRet;
6493}
6494/* ======================================================================
6495 FUNCTION
6496 omx_vdec::AllocateInputDone
6497
6498 DESCRIPTION
6499 Checks if I/P buffer pool is allocated by IL Client or not.
6500
6501 PARAMETERS
6502 None.
6503
6504 RETURN VALUE
6505 true/false.
6506
6507 ========================================================================== */
6508bool omx_vdec::allocate_input_done(void)
6509{
6510 bool bRet = false;
6511 unsigned i=0;
6512
6513 if (m_inp_mem_ptr == NULL) {
6514 return bRet;
6515 }
6516 if (m_inp_mem_ptr ) {
6517 for (; i<drv_ctx.ip_buf.actualcount; i++) {
6518 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
6519 break;
6520 }
6521 }
6522 }
6523 if (i == drv_ctx.ip_buf.actualcount) {
6524 bRet = true;
6525 DEBUG_PRINT_HIGH("Allocate done for all i/p buffers");
6526 }
6527 if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) {
6528 m_inp_bPopulated = OMX_TRUE;
6529 }
6530 return bRet;
6531}
6532/* ======================================================================
6533 FUNCTION
6534 omx_vdec::AllocateOutputDone
6535
6536 DESCRIPTION
6537 Checks if entire O/P buffer pool is allocated by IL Client or not.
6538
6539 PARAMETERS
6540 None.
6541
6542 RETURN VALUE
6543 true/false.
6544
6545 ========================================================================== */
6546bool omx_vdec::allocate_output_done(void)
6547{
6548 bool bRet = false;
6549 unsigned j=0;
6550
6551 if (m_out_mem_ptr == NULL) {
6552 return bRet;
6553 }
6554
6555 if (m_out_mem_ptr) {
6556 for (; j < drv_ctx.op_buf.actualcount; j++) {
6557 if (BITMASK_ABSENT(&m_out_bm_count,j)) {
6558 break;
6559 }
6560 }
6561 }
6562
6563 if (j == drv_ctx.op_buf.actualcount) {
6564 bRet = true;
6565 DEBUG_PRINT_HIGH("Allocate done for all o/p buffers");
6566 if (m_out_bEnabled)
6567 m_out_bPopulated = OMX_TRUE;
6568 }
6569
6570 return bRet;
6571}
6572
6573/* ======================================================================
6574 FUNCTION
6575 omx_vdec::ReleaseDone
6576
6577 DESCRIPTION
6578 Checks if IL client has released all the buffers.
6579
6580 PARAMETERS
6581 None.
6582
6583 RETURN VALUE
6584 true/false
6585
6586 ========================================================================== */
6587bool omx_vdec::release_done(void)
6588{
6589 bool bRet = false;
6590
6591 if (release_input_done()) {
6592 if (release_output_done()) {
6593 bRet = true;
6594 }
6595 }
6596 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006597}
6598
6599
6600/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006601 FUNCTION
6602 omx_vdec::ReleaseOutputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006603
Arun Menon906de572013-06-18 17:01:40 -07006604 DESCRIPTION
6605 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006606
Arun Menon906de572013-06-18 17:01:40 -07006607 PARAMETERS
6608 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006609
Arun Menon906de572013-06-18 17:01:40 -07006610 RETURN VALUE
6611 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006612
Arun Menon906de572013-06-18 17:01:40 -07006613 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006614bool omx_vdec::release_output_done(void)
6615{
Arun Menon906de572013-06-18 17:01:40 -07006616 bool bRet = false;
6617 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006618
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006619 DEBUG_PRINT_LOW("Value of m_out_mem_ptr %p",m_inp_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006620 if (m_out_mem_ptr) {
6621 for (; j < drv_ctx.op_buf.actualcount ; j++) {
6622 if (BITMASK_PRESENT(&m_out_bm_count,j)) {
6623 break;
6624 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006625 }
Arun Menon906de572013-06-18 17:01:40 -07006626 if (j == drv_ctx.op_buf.actualcount) {
6627 m_out_bm_count = 0;
6628 bRet = true;
6629 }
6630 } else {
6631 m_out_bm_count = 0;
6632 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006633 }
Arun Menon906de572013-06-18 17:01:40 -07006634 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006635}
6636/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006637 FUNCTION
6638 omx_vdec::ReleaseInputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006639
Arun Menon906de572013-06-18 17:01:40 -07006640 DESCRIPTION
6641 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006642
Arun Menon906de572013-06-18 17:01:40 -07006643 PARAMETERS
6644 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006645
Arun Menon906de572013-06-18 17:01:40 -07006646 RETURN VALUE
6647 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006648
Arun Menon906de572013-06-18 17:01:40 -07006649 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006650bool omx_vdec::release_input_done(void)
6651{
Arun Menon906de572013-06-18 17:01:40 -07006652 bool bRet = false;
6653 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006654
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006655 DEBUG_PRINT_LOW("Value of m_inp_mem_ptr %p",m_inp_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006656 if (m_inp_mem_ptr) {
6657 for (; j<drv_ctx.ip_buf.actualcount; j++) {
6658 if ( BITMASK_PRESENT(&m_inp_bm_count,j)) {
6659 break;
6660 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006661 }
Arun Menon906de572013-06-18 17:01:40 -07006662 if (j==drv_ctx.ip_buf.actualcount) {
6663 bRet = true;
6664 }
6665 } else {
6666 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006667 }
Arun Menon906de572013-06-18 17:01:40 -07006668 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006669}
6670
6671OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006672 OMX_BUFFERHEADERTYPE * buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006673{
Arun Menon906de572013-06-18 17:01:40 -07006674 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL;
Surajit Podderd2644d52013-08-28 17:59:06 +05306675 if (!buffer || (buffer - m_out_mem_ptr) >= (int)drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006676 DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer);
Arun Menon906de572013-06-18 17:01:40 -07006677 return OMX_ErrorBadParameter;
6678 } else if (output_flush_progress) {
6679 DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer);
6680 buffer->nFilledLen = 0;
6681 buffer->nTimeStamp = 0;
6682 buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA;
6683 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
6684 buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT;
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006685 }
6686
Arun Menon906de572013-06-18 17:01:40 -07006687 if (m_debug_extradata) {
6688 if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006689 DEBUG_PRINT_HIGH("");
6690 DEBUG_PRINT_HIGH("***************************************************");
6691 DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received");
6692 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006693 }
6694
6695 if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006696 DEBUG_PRINT_HIGH("");
6697 DEBUG_PRINT_HIGH("***************************************************");
6698 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
6699 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006700 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006701 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006702
6703
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006704 DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006705 buffer, buffer->pBuffer);
6706 pending_output_buffers --;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006707
Arun Menon906de572013-06-18 17:01:40 -07006708 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006709 DEBUG_PRINT_HIGH("Output EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07006710 if (!output_flush_progress)
6711 post_event((unsigned)NULL, (unsigned)NULL,
6712 OMX_COMPONENT_GENERATE_EOS_DONE);
6713
6714 if (psource_frame) {
6715 m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame);
6716 psource_frame = NULL;
6717 }
6718 if (pdest_frame) {
6719 pdest_frame->nFilledLen = 0;
6720 m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL,
6721 (unsigned)NULL);
6722 pdest_frame = NULL;
6723 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006724 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006725
Shalaj Jain273b3e02012-06-22 19:08:03 -07006726
Praneeth Paladugudd29c282013-09-12 15:41:47 -07006727 if (!output_flush_progress && (buffer->nFilledLen > 0)) {
6728 DEBUG_PRINT_LOW("Processing extradata");
6729 handle_extradata(buffer);
6730 }
6731
Arun Menon906de572013-06-18 17:01:40 -07006732 /* For use buffer we need to copy the data */
6733 if (!output_flush_progress) {
6734 /* This is the error check for non-recoverable errros */
6735 bool is_duplicate_ts_valid = true;
6736 bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006737
Arun Menon906de572013-06-18 17:01:40 -07006738 if (output_capability == V4L2_PIX_FMT_MPEG4 ||
6739 output_capability == V4L2_PIX_FMT_MPEG2 ||
6740 output_capability == V4L2_PIX_FMT_DIVX ||
6741 output_capability == V4L2_PIX_FMT_DIVX_311)
6742 is_duplicate_ts_valid = false;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006743
Arun Menon906de572013-06-18 17:01:40 -07006744 if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) {
Arun Menon7b6fd642014-02-13 16:48:36 -08006745 if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF) {
Arun Menon906de572013-06-18 17:01:40 -07006746 is_interlaced = false;
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306747 }
Arun Menon906de572013-06-18 17:01:40 -07006748 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306749
Arun Menon906de572013-06-18 17:01:40 -07006750 if (buffer->nFilledLen > 0) {
6751 time_stamp_dts.get_next_timestamp(buffer,
6752 is_interlaced && is_duplicate_ts_valid);
6753 if (m_debug_timestamp) {
6754 {
6755 OMX_TICKS expected_ts = 0;
6756 m_timestamp_list.pop_min_ts(expected_ts);
6757 if (is_interlaced && is_duplicate_ts_valid) {
6758 m_timestamp_list.pop_min_ts(expected_ts);
6759 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006760 DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list",
Arun Menon906de572013-06-18 17:01:40 -07006761 buffer->nTimeStamp, expected_ts);
6762
6763 if (buffer->nTimeStamp != expected_ts) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006764 DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check");
Arun Menon906de572013-06-18 17:01:40 -07006765 }
6766 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306767 }
Arun Menon906de572013-06-18 17:01:40 -07006768 } else {
Arun Menon906de572013-06-18 17:01:40 -07006769 time_stamp_dts.remove_time_stamp(
6770 buffer->nTimeStamp,
6771 is_interlaced && is_duplicate_ts_valid);
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306772 }
Arun Menon906de572013-06-18 17:01:40 -07006773
6774
Praneeth Paladugu8f12e822013-03-11 18:47:58 -07006775 }
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006776
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07006777 /* Since we're passing around handles, adjust nFilledLen and nAllocLen
6778 * to size of the handle. Do it _after_ handle_extradata() which
6779 * requires the respective sizes to be accurate. */
6780 if (dynamic_buf_mode) {
6781 buffer->nAllocLen = sizeof(struct VideoDecoderOutputMetaData);
6782 buffer->nFilledLen = buffer->nFilledLen ?
6783 sizeof(struct VideoDecoderOutputMetaData) : 0;
6784 }
6785
Arun Menon906de572013-06-18 17:01:40 -07006786 if (m_cb.FillBufferDone) {
6787 if (buffer->nFilledLen > 0) {
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006788 if (arbitrary_bytes)
Arun Menon906de572013-06-18 17:01:40 -07006789 adjust_timestamp(buffer->nTimeStamp);
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006790 else
6791 set_frame_rate(buffer->nTimeStamp);
6792
Arun Menon906de572013-06-18 17:01:40 -07006793 if (perf_flag) {
6794 if (!proc_frms) {
6795 dec_time.stop();
6796 latency = dec_time.processing_time_us() - latency;
6797 DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3);
6798 dec_time.start();
6799 fps_metrics.start();
6800 }
6801 proc_frms++;
6802 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6803 OMX_U64 proc_time = 0;
6804 fps_metrics.stop();
6805 proc_time = fps_metrics.processing_time_us();
6806 DEBUG_PRINT_HIGH(">>> FBD Metrics: proc_frms(%lu) proc_time(%.2f)S fps(%.2f)",
Shalaj Jain273b3e02012-06-22 19:08:03 -07006807 proc_frms, (float)proc_time / 1e6,
6808 (float)(1e6 * proc_frms) / proc_time);
Arun Menon906de572013-06-18 17:01:40 -07006809 proc_frms = 0;
6810 }
6811 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006812
6813#ifdef OUTPUT_EXTRADATA_LOG
Arun Menon906de572013-06-18 17:01:40 -07006814 if (outputExtradataFile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006815
Arun Menon906de572013-06-18 17:01:40 -07006816 OMX_OTHER_EXTRADATATYPE *p_extra = NULL;
6817 p_extra = (OMX_OTHER_EXTRADATATYPE *)
6818 ((unsigned)(buffer->pBuffer + buffer->nOffset +
6819 buffer->nFilledLen + 3)&(~3));
6820 while (p_extra &&
6821 (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006822 DEBUG_PRINT_LOW("WRITING extradata, size=%d,type=%d",p_extra->nSize, p_extra->eType);
Arun Menon906de572013-06-18 17:01:40 -07006823 fwrite (p_extra,1,p_extra->nSize,outputExtradataFile);
6824 if (p_extra->eType == OMX_ExtraDataNone) {
6825 break;
6826 }
6827 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
6828 }
6829 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006830#endif
Arun Menon906de572013-06-18 17:01:40 -07006831 }
6832 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6833 prev_ts = LLONG_MAX;
6834 rst_prev_ts = true;
6835 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006836
Arun Menon906de572013-06-18 17:01:40 -07006837 pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
6838 ((OMX_QCOM_PLATFORM_PRIVATE_LIST *)
6839 buffer->pPlatformPrivate)->entryList->entry;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006840 DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07006841 OMX_BUFFERHEADERTYPE *il_buffer;
6842 il_buffer = client_buffers.get_il_buf_hdr(buffer);
vivek mehtaa75c69f2014-01-10 21:50:37 -08006843
vivek mehta79cff222014-01-22 12:17:07 -08006844 if (il_buffer && m_last_rendered_TS >= 0) {
6845 int current_framerate = (int)(drv_ctx.frame_rate.fps_numerator /drv_ctx.frame_rate.fps_denominator);
Manikanta Kanamarlapudifb53b262014-01-20 16:12:47 +05306846 OMX_TICKS ts_delta = (OMX_TICKS)llabs(il_buffer->nTimeStamp - m_last_rendered_TS);
vivek mehta79cff222014-01-22 12:17:07 -08006847
6848 // Current frame can be send for rendering if
6849 // (a) current FPS is <= 60
6850 // (b) is the next frame after the frame with TS 0
6851 // (c) is the first frame after seek
6852 // (d) the delta TS b\w two consecutive frames is > 16 ms
6853 // (e) its TS is equal to previous frame TS
6854 // (f) if marked EOS
6855
6856 if(current_framerate <= 60 || m_last_rendered_TS == 0 ||
6857 il_buffer->nTimeStamp == 0 || ts_delta >= 16000 ||
6858 ts_delta == 0 || (il_buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
vivek mehtaa75c69f2014-01-10 21:50:37 -08006859 m_last_rendered_TS = il_buffer->nTimeStamp;
vivek mehta79cff222014-01-22 12:17:07 -08006860 } else {
vivek mehtaa75c69f2014-01-10 21:50:37 -08006861 //mark for droping
vivek mehtaa75c69f2014-01-10 21:50:37 -08006862 buffer->nFilledLen = 0;
vivek mehta79cff222014-01-22 12:17:07 -08006863 }
6864
6865 DEBUG_PRINT_LOW(" -- %s Frame -- info:: fps(%d) lastRenderTime(%lld) bufferTs(%lld) ts_delta(%d)",
6866 buffer->nFilledLen? "Rendering":"Dropping",current_framerate,m_last_rendered_TS,
6867 il_buffer->nTimeStamp,ts_delta);
vivek mehtaa75c69f2014-01-10 21:50:37 -08006868 }
6869
vivek mehta79cff222014-01-22 12:17:07 -08006870 if (il_buffer) {
Arun Menon9230eb82014-02-11 19:19:02 -08006871 log_output_buffers(il_buffer);
6872 if (dynamic_buf_mode) {
6873 unsigned int nPortIndex = 0;
6874 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
6875
6876 if (!secure_mode) {
6877 munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr,
6878 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size);
6879 }
6880
6881 //Clear graphic buffer handles in dynamic mode
6882 native_buffer[nPortIndex].privatehandle = NULL;
6883 native_buffer[nPortIndex].nativehandle = NULL;
6884 }
Arun Menon906de572013-06-18 17:01:40 -07006885 m_cb.FillBufferDone (hComp,m_app_data,il_buffer);
vivek mehta79cff222014-01-22 12:17:07 -08006886 } else {
Arun Menon906de572013-06-18 17:01:40 -07006887 DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr");
6888 return OMX_ErrorBadParameter;
6889 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006890 DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07006891 } else {
6892 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08006893 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006894
Praveen Chavancf924182013-12-06 23:16:23 -08006895#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05306896 if (m_smoothstreaming_mode && m_out_mem_ptr) {
Praveen Chavancf924182013-12-06 23:16:23 -08006897 OMX_U32 buf_index = buffer - m_out_mem_ptr;
6898 BufferDim_t dim;
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05306899 private_handle_t *private_handle = NULL;
Pushkaraj Patil41588352014-02-25 20:51:34 +05306900 if (is_down_scalar_enabled) {
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05306901 dim.sliceWidth = framesize.nWidth;
6902 dim.sliceHeight = framesize.nHeight;
Pushkaraj Patil41588352014-02-25 20:51:34 +05306903 } else {
6904 dim.sliceWidth = drv_ctx.video_resolution.frame_width;
6905 dim.sliceHeight = drv_ctx.video_resolution.frame_height;
6906 }
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05306907 if (native_buffer[buf_index].privatehandle)
6908 private_handle = native_buffer[buf_index].privatehandle;
Praveen Chavancf924182013-12-06 23:16:23 -08006909 if (private_handle) {
6910 DEBUG_PRINT_LOW("set metadata: update buf-geometry with stride %d slice %d",
6911 dim.sliceWidth, dim.sliceHeight);
6912 setMetaData(private_handle, UPDATE_BUFFER_GEOMETRY, (void*)&dim);
6913 }
6914 }
6915#endif
6916
Arun Menon906de572013-06-18 17:01:40 -07006917 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006918}
6919
6920OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006921 OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006922{
6923
Surajit Podderd2644d52013-08-28 17:59:06 +05306924 if (buffer == NULL || ((buffer - m_inp_mem_ptr) > (int)drv_ctx.ip_buf.actualcount)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006925 DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer);
Arun Menon906de572013-06-18 17:01:40 -07006926 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006927 }
6928
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006929 DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006930 buffer, buffer->pBuffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006931 pending_input_buffers--;
6932
Arun Menon906de572013-06-18 17:01:40 -07006933 if (arbitrary_bytes) {
6934 if (pdest_frame == NULL && input_flush_progress == false) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006935 DEBUG_PRINT_LOW("Push input from buffer done address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07006936 pdest_frame = buffer;
6937 buffer->nFilledLen = 0;
6938 buffer->nTimeStamp = LLONG_MAX;
6939 push_input_buffer (hComp);
6940 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006941 DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07006942 buffer->nFilledLen = 0;
6943 if (!m_input_free_q.insert_entry((unsigned)buffer,
6944 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006945 DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error");
Arun Menon906de572013-06-18 17:01:40 -07006946 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006947 }
Arun Menon906de572013-06-18 17:01:40 -07006948 } else if (m_cb.EmptyBufferDone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006949 buffer->nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07006950 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006951 buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr];
6952 }
6953 m_cb.EmptyBufferDone(hComp ,m_app_data, buffer);
6954 }
6955 return OMX_ErrorNone;
6956}
6957
Shalaj Jain273b3e02012-06-22 19:08:03 -07006958int omx_vdec::async_message_process (void *context, void* message)
6959{
Arun Menon906de572013-06-18 17:01:40 -07006960 omx_vdec* omx = NULL;
6961 struct vdec_msginfo *vdec_msg = NULL;
6962 OMX_BUFFERHEADERTYPE* omxhdr = NULL;
6963 struct v4l2_buffer *v4l2_buf_ptr = NULL;
6964 struct vdec_output_frameinfo *output_respbuf = NULL;
6965 int rc=1;
6966 if (context == NULL || message == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006967 DEBUG_PRINT_ERROR("FATAL ERROR in omx_vdec::async_message_process NULL Check");
Arun Menon906de572013-06-18 17:01:40 -07006968 return -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006969 }
Arun Menon906de572013-06-18 17:01:40 -07006970 vdec_msg = (struct vdec_msginfo *)message;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006971
Arun Menon906de572013-06-18 17:01:40 -07006972 omx = reinterpret_cast<omx_vdec*>(context);
Vinay Kaliab9e98102013-04-02 19:31:43 -07006973
Arun Menon906de572013-06-18 17:01:40 -07006974 switch (vdec_msg->msgcode) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006975
Arun Menon906de572013-06-18 17:01:40 -07006976 case VDEC_MSG_EVT_HW_ERROR:
6977 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6978 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
6979 break;
6980
Deepak Verma24720fb2014-01-29 16:57:40 +05306981 case VDEC_MSG_EVT_HW_OVERLOAD:
6982 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6983 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD);
6984 break;
6985
Arun Menon906de572013-06-18 17:01:40 -07006986 case VDEC_MSG_RESP_START_DONE:
6987 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6988 OMX_COMPONENT_GENERATE_START_DONE);
6989 break;
6990
6991 case VDEC_MSG_RESP_STOP_DONE:
6992 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6993 OMX_COMPONENT_GENERATE_STOP_DONE);
6994 break;
6995
6996 case VDEC_MSG_RESP_RESUME_DONE:
6997 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6998 OMX_COMPONENT_GENERATE_RESUME_DONE);
6999 break;
7000
7001 case VDEC_MSG_RESP_PAUSE_DONE:
7002 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7003 OMX_COMPONENT_GENERATE_PAUSE_DONE);
7004 break;
7005
7006 case VDEC_MSG_RESP_FLUSH_INPUT_DONE:
7007 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7008 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
7009 break;
7010 case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE:
7011 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7012 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
7013 break;
7014 case VDEC_MSG_RESP_INPUT_FLUSHED:
7015 case VDEC_MSG_RESP_INPUT_BUFFER_DONE:
7016
7017 /* omxhdr = (OMX_BUFFERHEADERTYPE* )
7018 vdec_msg->msgdata.input_frame_clientdata; */
7019
7020 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata;
7021 omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index;
7022 if (omxhdr == NULL ||
Surajit Podderd2644d52013-08-28 17:59:06 +05307023 ((omxhdr - omx->m_inp_mem_ptr) > (int)omx->drv_ctx.ip_buf.actualcount) ) {
Arun Menon906de572013-06-18 17:01:40 -07007024 omxhdr = NULL;
7025 vdec_msg->status_code = VDEC_S_EFATAL;
7026 }
7027 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) {
7028 DEBUG_PRINT_HIGH("Unsupported input");
7029 omx->omx_report_error ();
7030 }
7031 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
7032 vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR;
7033 }
7034 omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code,
7035 OMX_COMPONENT_GENERATE_EBD);
7036 break;
7037 case VDEC_MSG_EVT_INFO_FIELD_DROPPED:
7038 int64_t *timestamp;
7039 timestamp = (int64_t *) malloc(sizeof(int64_t));
7040 if (timestamp) {
7041 *timestamp = vdec_msg->msgdata.output_frame.time_stamp;
7042 omx->post_event ((unsigned int)timestamp, vdec_msg->status_code,
7043 OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007044 DEBUG_PRINT_HIGH("Field dropped time stamp is %lld",
Arun Menon906de572013-06-18 17:01:40 -07007045 vdec_msg->msgdata.output_frame.time_stamp);
7046 }
7047 break;
7048 case VDEC_MSG_RESP_OUTPUT_FLUSHED:
7049 case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE:
7050
7051 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data;
7052 omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307053
7054 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 -07007055 omxhdr, vdec_msg->msgdata.output_frame.time_stamp,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307056 vdec_msg->msgdata.output_frame.pic_type, v4l2_buf_ptr->flags,
7057 (unsigned int)vdec_msg->msgdata.output_frame.len,
7058 vdec_msg->msgdata.output_frame.framesize.left,
7059 vdec_msg->msgdata.output_frame.framesize.top,
7060 vdec_msg->msgdata.output_frame.framesize.right,
7061 vdec_msg->msgdata.output_frame.framesize.bottom);
Arun Menon906de572013-06-18 17:01:40 -07007062
7063 if (omxhdr && omxhdr->pOutputPortPrivate &&
Surajit Podderd2644d52013-08-28 17:59:06 +05307064 ((omxhdr - omx->m_out_mem_ptr) < (int)omx->drv_ctx.op_buf.actualcount) &&
Arun Menon906de572013-06-18 17:01:40 -07007065 (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate
Surajit Podderd2644d52013-08-28 17:59:06 +05307066 - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307067
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07007068 if (vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) {
Arun Menon906de572013-06-18 17:01:40 -07007069 omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len;
7070 omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset;
7071 omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp;
7072 omxhdr->nFlags = 0;
7073
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07007074 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) {
Arun Menon906de572013-06-18 17:01:40 -07007075 omxhdr->nFlags |= OMX_BUFFERFLAG_EOS;
7076 //rc = -1;
7077 }
7078 if (omxhdr->nFilledLen) {
7079 omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
7080 }
7081 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) {
7082 omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
7083 } else {
7084 omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME;
7085 }
7086 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) {
7087 omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
7088 }
7089 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) {
7090 omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY;
7091 }
Arun Menon7b6fd642014-02-13 16:48:36 -08007092
7093 if (v4l2_buf_ptr->flags & V4L2_MSM_BUF_FLAG_MBAFF) {
7094 omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_MBAFF;
7095 }
7096
Arun Menonbdb80b02013-08-12 17:45:54 -07007097 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) {
Arun Menone50f6ef2013-09-30 15:08:27 -07007098 omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY;
Arun Menonbdb80b02013-08-12 17:45:54 -07007099 DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d",
7100 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd);
7101 }
Arun Menonbdb80b02013-08-12 17:45:54 -07007102 if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) {
7103 omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd,
7104 omxhdr->nOffset);
7105 }
Arun Menon906de572013-06-18 17:01:40 -07007106 if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) &&
7107 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) &&
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07007108 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) {
Praneeth Paladugu17364df2013-07-30 11:34:16 -07007109 omx->time_stamp_dts.remove_time_stamp(
7110 omxhdr->nTimeStamp,
7111 (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
7112 ?true:false);
Arun Menon906de572013-06-18 17:01:40 -07007113 omx->post_event ((unsigned)NULL,(unsigned int)omxhdr,
7114 OMX_COMPONENT_GENERATE_FTB);
7115 break;
7116 }
7117 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
7118 omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
7119 }
7120 vdec_msg->msgdata.output_frame.bufferaddr =
7121 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307122
7123 /* Post event if resolution OR crop changed */
7124 /* filled length will be changed if resolution changed */
7125 /* Crop parameters can be changed even without resolution change */
7126 if (omxhdr->nFilledLen
7127 && ((omx->prev_n_filled_len != omxhdr->nFilledLen)
7128 || (omx->drv_ctx.frame_size.left != vdec_msg->msgdata.output_frame.framesize.left)
7129 || (omx->drv_ctx.frame_size.top != vdec_msg->msgdata.output_frame.framesize.top)
7130 || (omx->drv_ctx.frame_size.right != vdec_msg->msgdata.output_frame.framesize.right)
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05307131 || (omx->drv_ctx.frame_size.bottom != vdec_msg->msgdata.output_frame.framesize.bottom)
7132 || (omx->drv_ctx.video_resolution.frame_width != vdec_msg->msgdata.output_frame.picsize.frame_width)
7133 || (omx->drv_ctx.video_resolution.frame_height != vdec_msg->msgdata.output_frame.picsize.frame_height) )) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307134
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05307135 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",
7136 omx->prev_n_filled_len,
7137 omx->drv_ctx.video_resolution.frame_width,
7138 omx->drv_ctx.video_resolution.frame_height,
7139 omx->drv_ctx.frame_size.left, omx->drv_ctx.frame_size.top,
7140 omx->drv_ctx.frame_size.right, omx->drv_ctx.frame_size.bottom,
7141 omxhdr->nFilledLen, vdec_msg->msgdata.output_frame.picsize.frame_width,
7142 vdec_msg->msgdata.output_frame.picsize.frame_height,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307143 vdec_msg->msgdata.output_frame.framesize.left,
7144 vdec_msg->msgdata.output_frame.framesize.top,
7145 vdec_msg->msgdata.output_frame.framesize.right,
7146 vdec_msg->msgdata.output_frame.framesize.bottom);
7147
Maheshwar Ajja0f840ce2014-09-29 16:53:42 +05307148 omx->drv_ctx.video_resolution.frame_width =
7149 vdec_msg->msgdata.output_frame.picsize.frame_width;
7150 omx->drv_ctx.video_resolution.frame_height =
7151 vdec_msg->msgdata.output_frame.picsize.frame_height;
7152
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307153 memcpy(&omx->drv_ctx.frame_size,
7154 &vdec_msg->msgdata.output_frame.framesize,
7155 sizeof(struct vdec_framesize));
7156
7157 omx->post_event(OMX_CORE_OUTPUT_PORT_INDEX,
7158 OMX_IndexConfigCommonOutputCrop,
7159 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
Arun Menon906de572013-06-18 17:01:40 -07007160 }
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307161
Arun Menon906de572013-06-18 17:01:40 -07007162 if (omxhdr->nFilledLen)
7163 omx->prev_n_filled_len = omxhdr->nFilledLen;
7164
7165 output_respbuf = (struct vdec_output_frameinfo *)\
7166 omxhdr->pOutputPortPrivate;
7167 output_respbuf->len = vdec_msg->msgdata.output_frame.len;
7168 output_respbuf->offset = vdec_msg->msgdata.output_frame.offset;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307169
Arun Menon906de572013-06-18 17:01:40 -07007170 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) {
7171 output_respbuf->pic_type = PICTURE_TYPE_I;
7172 }
7173 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) {
7174 output_respbuf->pic_type = PICTURE_TYPE_P;
7175 }
7176 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) {
7177 output_respbuf->pic_type = PICTURE_TYPE_B;
7178 }
7179
7180 if (omx->output_use_buffer)
7181 memcpy ( omxhdr->pBuffer, (void *)
7182 ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr +
7183 (unsigned long)vdec_msg->msgdata.output_frame.offset),
7184 vdec_msg->msgdata.output_frame.len);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307185 } else {
7186 DEBUG_PRINT_ERROR("Invalid filled length = %u, buffer size = %u, prev_length = %u",
7187 (unsigned int)vdec_msg->msgdata.output_frame.len,
7188 omxhdr->nAllocLen, omx->prev_n_filled_len);
Arun Menon906de572013-06-18 17:01:40 -07007189 omxhdr->nFilledLen = 0;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307190 }
7191
Arun Menon906de572013-06-18 17:01:40 -07007192 omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code,
7193 OMX_COMPONENT_GENERATE_FBD);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307194
7195 } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) {
Arun Menon906de572013-06-18 17:01:40 -07007196 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
7197 OMX_COMPONENT_GENERATE_EOS_DONE);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307198 } else {
Arun Menon906de572013-06-18 17:01:40 -07007199 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
7200 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307201 }
Arun Menon906de572013-06-18 17:01:40 -07007202 break;
7203 case VDEC_MSG_EVT_CONFIG_CHANGED:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007204 DEBUG_PRINT_HIGH("Port settings changed");
Arun Menon906de572013-06-18 17:01:40 -07007205 omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition,
7206 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
7207 break;
7208 default:
7209 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007210 }
Arun Menon906de572013-06-18 17:01:40 -07007211 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007212}
7213
7214OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary (
Arun Menon906de572013-06-18 17:01:40 -07007215 OMX_HANDLETYPE hComp,
7216 OMX_BUFFERHEADERTYPE *buffer
7217 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07007218{
Arun Menon906de572013-06-18 17:01:40 -07007219 unsigned address,p2,id;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007220 DEBUG_PRINT_LOW("Empty this arbitrary");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007221
Arun Menon906de572013-06-18 17:01:40 -07007222 if (buffer == NULL) {
7223 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007224 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007225 DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
7226 DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07007227 buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp);
7228
7229 /* return zero length and not an EOS buffer */
7230 /* return buffer if input flush in progress */
7231 if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) &&
7232 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007233 DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress");
Arun Menon906de572013-06-18 17:01:40 -07007234 m_cb.EmptyBufferDone (hComp,m_app_data,buffer);
7235 return OMX_ErrorNone;
7236 }
7237
7238 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007239 DEBUG_PRINT_LOW("Set Buffer as source Buffer %p time stamp %lld",buffer,buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07007240 psource_frame = buffer;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007241 DEBUG_PRINT_LOW("Try to Push One Input Buffer ");
Arun Menon906de572013-06-18 17:01:40 -07007242 push_input_buffer (hComp);
7243 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007244 DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07007245 if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL,
7246 (unsigned)NULL)) {
7247 return OMX_ErrorBadParameter;
7248 }
7249 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007250
Sowmya Pandiri302f5ab2014-04-03 13:41:03 -07007251 if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
7252 codec_config_flag = false;
7253 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007254
Arun Menon906de572013-06-18 17:01:40 -07007255 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007256}
7257
7258OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp)
7259{
Arun Menon906de572013-06-18 17:01:40 -07007260 unsigned address,p2,id;
7261 OMX_ERRORTYPE ret = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007262
Arun Menon906de572013-06-18 17:01:40 -07007263 if (pdest_frame == NULL || psource_frame == NULL) {
7264 /*Check if we have a destination buffer*/
7265 if (pdest_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007266 DEBUG_PRINT_LOW("Get a Destination buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07007267 if (m_input_free_q.m_size) {
7268 m_input_free_q.pop_entry(&address,&p2,&id);
7269 pdest_frame = (OMX_BUFFERHEADERTYPE *)address;
7270 pdest_frame->nFilledLen = 0;
7271 pdest_frame->nTimeStamp = LLONG_MAX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007272 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07007273 }
7274 }
7275
7276 /*Check if we have a destination buffer*/
7277 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007278 DEBUG_PRINT_LOW("Get a source buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07007279 if (m_input_pending_q.m_size) {
7280 m_input_pending_q.pop_entry(&address,&p2,&id);
7281 psource_frame = (OMX_BUFFERHEADERTYPE *)address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007282 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07007283 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007284 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007285 psource_frame->nFlags,psource_frame->nFilledLen);
7286
7287 }
7288 }
7289
Shalaj Jain273b3e02012-06-22 19:08:03 -07007290 }
7291
Arun Menon906de572013-06-18 17:01:40 -07007292 while ((pdest_frame != NULL) && (psource_frame != NULL)) {
7293 switch (codec_type_parse) {
7294 case CODEC_TYPE_MPEG4:
7295 case CODEC_TYPE_H263:
7296 case CODEC_TYPE_MPEG2:
7297 ret = push_input_sc_codec(hComp);
7298 break;
7299 case CODEC_TYPE_H264:
7300 ret = push_input_h264(hComp);
7301 break;
7302 case CODEC_TYPE_VC1:
7303 ret = push_input_vc1(hComp);
7304 break;
7305 default:
7306 break;
7307 }
7308 if (ret != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007309 DEBUG_PRINT_ERROR("Pushing input Buffer Failed");
Arun Menon906de572013-06-18 17:01:40 -07007310 omx_report_error ();
7311 break;
7312 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007313 }
7314
Arun Menon906de572013-06-18 17:01:40 -07007315 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007316}
7317
7318OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp)
7319{
Arun Menon906de572013-06-18 17:01:40 -07007320 OMX_U32 partial_frame = 1;
7321 OMX_BOOL generate_ebd = OMX_TRUE;
7322 unsigned address = 0, p2 = 0, id = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007323
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007324 DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07007325 psource_frame,psource_frame->nTimeStamp);
7326 if (m_frame_parser.parse_sc_frame(psource_frame,
7327 pdest_frame,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007328 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Arun Menon906de572013-06-18 17:01:40 -07007329 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007330 }
Arun Menon906de572013-06-18 17:01:40 -07007331
7332 if (partial_frame == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007333 DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d",
Arun Menon906de572013-06-18 17:01:40 -07007334 pdest_frame->nFilledLen,psource_frame,frame_count);
7335
7336
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007337 DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07007338 /*First Parsed buffer will have only header Hence skip*/
7339 if (frame_count == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007340 DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame ");
Arun Menon906de572013-06-18 17:01:40 -07007341
7342 if (codec_type_parse == CODEC_TYPE_MPEG4 ||
7343 codec_type_parse == CODEC_TYPE_DIVX) {
7344 mp4StreamType psBits;
7345 psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset;
7346 psBits.numBytes = pdest_frame->nFilledLen;
7347 mp4_headerparser.parseHeader(&psBits);
7348 }
7349
7350 frame_count++;
7351 } else {
7352 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
7353 if (pdest_frame->nFilledLen) {
7354 /*Push the frame to the Decoder*/
7355 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7356 return OMX_ErrorBadParameter;
7357 }
7358 frame_count++;
7359 pdest_frame = NULL;
7360
7361 if (m_input_free_q.m_size) {
7362 m_input_free_q.pop_entry(&address,&p2,&id);
7363 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
7364 pdest_frame->nFilledLen = 0;
7365 }
7366 } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007367 DEBUG_PRINT_ERROR("Zero len buffer return back to POOL");
Arun Menon906de572013-06-18 17:01:40 -07007368 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL,
7369 (unsigned)NULL);
7370 pdest_frame = NULL;
7371 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007372 }
Arun Menon906de572013-06-18 17:01:40 -07007373 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007374 DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007375 /*Check if Destination Buffer is full*/
7376 if (pdest_frame->nAllocLen ==
7377 pdest_frame->nFilledLen + pdest_frame->nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007378 DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07007379 return OMX_ErrorStreamCorrupt;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007380 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007381 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007382
Arun Menon906de572013-06-18 17:01:40 -07007383 if (psource_frame->nFilledLen == 0) {
7384 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
7385 if (pdest_frame) {
7386 pdest_frame->nFlags |= psource_frame->nFlags;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007387 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld",
Arun Menon906de572013-06-18 17:01:40 -07007388 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007389 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07007390 pdest_frame->nFilledLen,frame_count++);
7391 /*Push the frame to the Decoder*/
7392 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7393 return OMX_ErrorBadParameter;
7394 }
7395 frame_count++;
7396 pdest_frame = NULL;
7397 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007398 DEBUG_PRINT_LOW("Last frame in else dest addr") ;
Arun Menon906de572013-06-18 17:01:40 -07007399 generate_ebd = OMX_FALSE;
7400 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007401 }
Arun Menon906de572013-06-18 17:01:40 -07007402 if (generate_ebd) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007403 DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007404 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
7405 psource_frame = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007406
Arun Menon906de572013-06-18 17:01:40 -07007407 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007408 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007409 m_input_pending_q.pop_entry(&address,&p2,&id);
7410 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007411 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07007412 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007413 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007414 psource_frame->nFlags,psource_frame->nFilledLen);
7415 }
7416 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007417 }
Arun Menon906de572013-06-18 17:01:40 -07007418 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007419}
7420
7421OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp)
7422{
Arun Menon906de572013-06-18 17:01:40 -07007423 OMX_U32 partial_frame = 1;
7424 unsigned address = 0, p2 = 0, id = 0;
7425 OMX_BOOL isNewFrame = OMX_FALSE;
7426 OMX_BOOL generate_ebd = OMX_TRUE;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007427
Arun Menon906de572013-06-18 17:01:40 -07007428 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007429 DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated");
Arun Menon906de572013-06-18 17:01:40 -07007430 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007431 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007432 DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu "
Arun Menon906de572013-06-18 17:01:40 -07007433 "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007434 DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007435 if (h264_scratch.nFilledLen && look_ahead_nal) {
7436 look_ahead_nal = false;
7437 if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7438 h264_scratch.nFilledLen) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007439 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7440 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7441 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007442 DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007443 h264_scratch.nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07007444 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007445 DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007446 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007447 }
Arun Menon906de572013-06-18 17:01:40 -07007448 }
Praveen Chavance0b5e82013-08-08 05:23:34 -07007449
7450 /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result
7451 in EOS flag getting associated with the destination
7452 */
7453 if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) &&
7454 pdest_frame->nFilledLen) {
7455 DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'");
7456 generate_ebd = OMX_FALSE;
7457 }
7458
Arun Menon906de572013-06-18 17:01:40 -07007459 if (nal_length == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007460 DEBUG_PRINT_LOW("Zero NAL, hence parse using start code");
Arun Menon906de572013-06-18 17:01:40 -07007461 if (m_frame_parser.parse_sc_frame(psource_frame,
7462 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007463 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007464 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007465 }
Arun Menon906de572013-06-18 17:01:40 -07007466 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007467 DEBUG_PRINT_LOW("Non-zero NAL length clip, hence parse with NAL size %d ",nal_length);
Arun Menon906de572013-06-18 17:01:40 -07007468 if (m_frame_parser.parse_h264_nallength(psource_frame,
7469 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007470 DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error");
Arun Menon906de572013-06-18 17:01:40 -07007471 return OMX_ErrorBadParameter;
7472 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007473 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007474
Arun Menon906de572013-06-18 17:01:40 -07007475 if (partial_frame == 0) {
7476 if (nal_count == 0 && h264_scratch.nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007477 DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip");
Arun Menon906de572013-06-18 17:01:40 -07007478 nal_count++;
7479 h264_scratch.nTimeStamp = psource_frame->nTimeStamp;
7480 h264_scratch.nFlags = psource_frame->nFlags;
7481 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007482 DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007483 if (h264_scratch.nFilledLen) {
7484 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen,
7485 NALU_TYPE_SPS);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007486#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
Arun Menon906de572013-06-18 17:01:40 -07007487 if (client_extradata & OMX_TIMEINFO_EXTRADATA)
7488 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7489 h264_scratch.nFilledLen, NALU_TYPE_SEI);
7490 else if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7491 // If timeinfo is present frame info from SEI is already processed
7492 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7493 h264_scratch.nFilledLen, NALU_TYPE_SEI);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007494#endif
Arun Menon906de572013-06-18 17:01:40 -07007495 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7496 nal_count++;
7497 if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) {
7498 pdest_frame->nTimeStamp = h264_last_au_ts;
7499 pdest_frame->nFlags = h264_last_au_flags;
7500#ifdef PANSCAN_HDLR
7501 if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7502 h264_parser->update_panscan_data(h264_last_au_ts);
7503#endif
7504 }
7505 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR ||
7506 m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) {
7507 h264_last_au_ts = h264_scratch.nTimeStamp;
7508 h264_last_au_flags = h264_scratch.nFlags;
7509#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7510 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7511 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts);
7512 if (!VALID_TS(h264_last_au_ts))
7513 h264_last_au_ts = ts_in_sei;
7514 }
7515#endif
7516 } else
7517 h264_last_au_ts = LLONG_MAX;
7518 }
7519
7520 if (!isNewFrame) {
7521 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7522 h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007523 DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu",
Arun Menon906de572013-06-18 17:01:40 -07007524 h264_scratch.nFilledLen);
7525 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7526 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7527 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7528 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ)
7529 pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
7530 h264_scratch.nFilledLen = 0;
7531 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007532 DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007533 return OMX_ErrorBadParameter;
7534 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007535 } else if(h264_scratch.nFilledLen) {
Arun Menon906de572013-06-18 17:01:40 -07007536 look_ahead_nal = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007537 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007538 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007539 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07007540 pdest_frame->nFilledLen,frame_count++);
7541
7542 if (pdest_frame->nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007543 DEBUG_PRINT_LOW("Copy the Current Frame since and push it");
Arun Menon906de572013-06-18 17:01:40 -07007544 look_ahead_nal = false;
7545 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7546 h264_scratch.nFilledLen) {
7547 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7548 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7549 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7550 h264_scratch.nFilledLen = 0;
7551 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007552 DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007553 return OMX_ErrorBadParameter;
7554 }
7555 } else {
7556 if (psource_frame->nFilledLen || h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007557 DEBUG_PRINT_LOW("Reset the EOS Flag");
Arun Menon906de572013-06-18 17:01:40 -07007558 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
7559 }
7560 /*Push the frame to the Decoder*/
7561 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7562 return OMX_ErrorBadParameter;
7563 }
7564 //frame_count++;
7565 pdest_frame = NULL;
7566 if (m_input_free_q.m_size) {
7567 m_input_free_q.pop_entry(&address,&p2,&id);
7568 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007569 DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07007570 pdest_frame->nFilledLen = 0;
7571 pdest_frame->nFlags = 0;
7572 pdest_frame->nTimeStamp = LLONG_MAX;
7573 }
7574 }
7575 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007576 }
Arun Menon906de572013-06-18 17:01:40 -07007577 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007578 DEBUG_PRINT_LOW("Not a Complete Frame, pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007579 /*Check if Destination Buffer is full*/
7580 if (h264_scratch.nAllocLen ==
7581 h264_scratch.nFilledLen + h264_scratch.nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007582 DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07007583 return OMX_ErrorStreamCorrupt;
7584 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007585 }
Arun Menon906de572013-06-18 17:01:40 -07007586
7587 if (!psource_frame->nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007588 DEBUG_PRINT_LOW("Buffer Consumed return source %p back to client",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007589
7590 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
7591 if (pdest_frame) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007592 DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer");
Arun Menon906de572013-06-18 17:01:40 -07007593 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7594 h264_scratch.nFilledLen) {
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007595 if(pdest_frame->nFilledLen == 0) {
7596 /* No residual frame from before, send whatever
7597 * we have left */
7598 memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7599 h264_scratch.pBuffer, h264_scratch.nFilledLen);
7600 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7601 h264_scratch.nFilledLen = 0;
7602 pdest_frame->nTimeStamp = h264_scratch.nTimeStamp;
7603 } else {
7604 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7605 if(!isNewFrame) {
7606 /* Have a residual frame, but we know that the
7607 * AU in this frame is belonging to whatever
7608 * frame we had left over. So append it */
7609 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7610 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7611 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7612 h264_scratch.nFilledLen = 0;
7613 pdest_frame->nTimeStamp = h264_last_au_ts;
7614 } else {
7615 /* Completely new frame, let's just push what
7616 * we have now. The resulting EBD would trigger
7617 * another push */
7618 generate_ebd = OMX_FALSE;
7619 pdest_frame->nTimeStamp = h264_last_au_ts;
7620 h264_last_au_ts = h264_scratch.nTimeStamp;
7621 }
7622 }
Arun Menon906de572013-06-18 17:01:40 -07007623 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007624 DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007625 return OMX_ErrorBadParameter;
7626 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007627
7628 /* Iff we coalesced two buffers, inherit the flags of both bufs */
7629 if(generate_ebd == OMX_TRUE) {
7630 pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags;
7631 }
Arun Menon906de572013-06-18 17:01:40 -07007632
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007633 DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007634 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007635 DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++);
Arun Menon906de572013-06-18 17:01:40 -07007636#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7637 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7638 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp);
7639 if (!VALID_TS(pdest_frame->nTimeStamp))
7640 pdest_frame->nTimeStamp = ts_in_sei;
7641 }
7642#endif
7643 /*Push the frame to the Decoder*/
7644 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7645 return OMX_ErrorBadParameter;
7646 }
7647 frame_count++;
7648 pdest_frame = NULL;
7649 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007650 DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu",
Arun Menon906de572013-06-18 17:01:40 -07007651 pdest_frame,h264_scratch.nFilledLen);
7652 generate_ebd = OMX_FALSE;
7653 }
7654 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007655 }
Arun Menon906de572013-06-18 17:01:40 -07007656 if (generate_ebd && !psource_frame->nFilledLen) {
7657 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
7658 psource_frame = NULL;
7659 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007660 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007661 m_input_pending_q.pop_entry(&address,&p2,&id);
7662 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007663 DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007664 psource_frame->nFlags,psource_frame->nFilledLen);
7665 }
7666 }
7667 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007668}
7669
7670OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp)
7671{
7672 OMX_U8 *buf, *pdest;
7673 OMX_U32 partial_frame = 1;
7674 OMX_U32 buf_len, dest_len;
7675
Arun Menon906de572013-06-18 17:01:40 -07007676 if (first_frame == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007677 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007678 DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes");
Arun Menon906de572013-06-18 17:01:40 -07007679 if (!m_vendor_config.pData) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007680 DEBUG_PRINT_LOW("Check profile type in 1st source buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007681 buf = psource_frame->pBuffer;
7682 buf_len = psource_frame->nFilledLen;
7683
7684 if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) ==
Arun Menon906de572013-06-18 17:01:40 -07007685 VC1_SP_MP_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007686 m_vc1_profile = VC1_SP_MP_RCV;
Arun Menon906de572013-06-18 17:01:40 -07007687 } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007688 m_vc1_profile = VC1_AP;
Arun Menon906de572013-06-18 17:01:40 -07007689 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007690 DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007691 return OMX_ErrorStreamCorrupt;
7692 }
Arun Menon906de572013-06-18 17:01:40 -07007693 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007694 pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen +
7695 pdest_frame->nOffset;
7696 dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen +
Arun Menon906de572013-06-18 17:01:40 -07007697 pdest_frame->nOffset);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007698
Arun Menon906de572013-06-18 17:01:40 -07007699 if (dest_len < m_vendor_config.nDataSize) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007700 DEBUG_PRINT_ERROR("Destination buffer full");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007701 return OMX_ErrorBadParameter;
Arun Menon906de572013-06-18 17:01:40 -07007702 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007703 memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize);
7704 pdest_frame->nFilledLen += m_vendor_config.nDataSize;
7705 }
7706 }
7707 }
7708
Arun Menon906de572013-06-18 17:01:40 -07007709 switch (m_vc1_profile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007710 case VC1_AP:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007711 DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code");
Arun Menon906de572013-06-18 17:01:40 -07007712 if (push_input_sc_codec(hComp) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007713 DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007714 return OMX_ErrorBadParameter;
7715 }
Arun Menon906de572013-06-18 17:01:40 -07007716 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007717
7718 case VC1_SP_MP_RCV:
7719 default:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007720 DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007721 return OMX_ErrorBadParameter;
7722 }
7723 return OMX_ErrorNone;
7724}
7725
David Ng38e2d232013-03-15 20:05:58 -07007726#ifndef USE_ION
Shalaj Jain273b3e02012-06-22 19:08:03 -07007727bool omx_vdec::align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007728 OMX_U32 alignment)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007729{
Arun Menon906de572013-06-18 17:01:40 -07007730 struct pmem_allocation allocation;
7731 allocation.size = buffer_size;
7732 allocation.align = clip2(alignment);
7733 if (allocation.align < 4096) {
7734 allocation.align = 4096;
7735 }
7736 if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007737 DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)",
Arun Menon906de572013-06-18 17:01:40 -07007738 allocation.align, allocation.size);
7739 return false;
7740 }
7741 return true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007742}
David Ng38e2d232013-03-15 20:05:58 -07007743#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07007744#ifdef USE_ION
7745int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007746 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
7747 struct ion_fd_data *fd_data, int flag)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007748{
Arun Menon906de572013-06-18 17:01:40 -07007749 int fd = -EINVAL;
7750 int rc = -EINVAL;
7751 int ion_dev_flag;
7752 struct vdec_ion ion_buf_info;
7753 if (!alloc_data || buffer_size <= 0 || !fd_data) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007754 DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory");
Arun Menon906de572013-06-18 17:01:40 -07007755 return -EINVAL;
7756 }
7757 ion_dev_flag = O_RDONLY;
7758 fd = open (MEM_DEVICE, ion_dev_flag);
7759 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007760 DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd);
Arun Menon906de572013-06-18 17:01:40 -07007761 return fd;
7762 }
7763 alloc_data->flags = 0;
7764 if (!secure_mode && (flag & ION_FLAG_CACHED)) {
7765 alloc_data->flags |= ION_FLAG_CACHED;
7766 }
7767 alloc_data->len = buffer_size;
7768 alloc_data->align = clip2(alignment);
7769 if (alloc_data->align < 4096) {
7770 alloc_data->align = 4096;
7771 }
7772 if ((secure_mode) && (flag & ION_SECURE))
7773 alloc_data->flags |= ION_SECURE;
Vinay Kalia53fa6832012-10-11 17:55:30 -07007774
Arun Menon906de572013-06-18 17:01:40 -07007775 alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05307776 if (secure_mode && (alloc_data->flags & ION_SECURE))
Arun Menon906de572013-06-18 17:01:40 -07007777 alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID);
7778 rc = ioctl(fd,ION_IOC_ALLOC,alloc_data);
7779 if (rc || !alloc_data->handle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007780 DEBUG_PRINT_ERROR("ION ALLOC memory failed ");
Arun Menon906de572013-06-18 17:01:40 -07007781 alloc_data->handle = NULL;
7782 close(fd);
7783 fd = -ENOMEM;
7784 return fd;
7785 }
7786 fd_data->handle = alloc_data->handle;
7787 rc = ioctl(fd,ION_IOC_MAP,fd_data);
7788 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007789 DEBUG_PRINT_ERROR("ION MAP failed ");
Arun Menon906de572013-06-18 17:01:40 -07007790 ion_buf_info.ion_alloc_data = *alloc_data;
7791 ion_buf_info.ion_device_fd = fd;
7792 ion_buf_info.fd_ion_data = *fd_data;
7793 free_ion_memory(&ion_buf_info);
7794 fd_data->fd =-1;
Arun Menon906de572013-06-18 17:01:40 -07007795 fd = -ENOMEM;
7796 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007797
Arun Menon906de572013-06-18 17:01:40 -07007798 return fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007799}
7800
Arun Menon906de572013-06-18 17:01:40 -07007801void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info)
7802{
Shalaj Jain273b3e02012-06-22 19:08:03 -07007803
Arun Menon906de572013-06-18 17:01:40 -07007804 if (!buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007805 DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata");
Arun Menon906de572013-06-18 17:01:40 -07007806 return;
7807 }
7808 if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE,
7809 &buf_ion_info->ion_alloc_data.handle)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007810 DEBUG_PRINT_ERROR("ION: free failed" );
Arun Menon906de572013-06-18 17:01:40 -07007811 }
7812 close(buf_ion_info->ion_device_fd);
7813 buf_ion_info->ion_device_fd = -1;
7814 buf_ion_info->ion_alloc_data.handle = NULL;
7815 buf_ion_info->fd_ion_data.fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007816}
7817#endif
7818void omx_vdec::free_output_buffer_header()
7819{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007820 DEBUG_PRINT_HIGH("ALL output buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07007821 output_use_buffer = false;
7822 ouput_egl_buffers = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007823
Arun Menon906de572013-06-18 17:01:40 -07007824 if (m_out_mem_ptr) {
7825 free (m_out_mem_ptr);
7826 m_out_mem_ptr = NULL;
7827 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007828
Arun Menon906de572013-06-18 17:01:40 -07007829 if (m_platform_list) {
7830 free(m_platform_list);
7831 m_platform_list = NULL;
7832 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007833
Arun Menon906de572013-06-18 17:01:40 -07007834 if (drv_ctx.ptr_respbuffer) {
7835 free (drv_ctx.ptr_respbuffer);
7836 drv_ctx.ptr_respbuffer = NULL;
7837 }
7838 if (drv_ctx.ptr_outputbuffer) {
7839 free (drv_ctx.ptr_outputbuffer);
7840 drv_ctx.ptr_outputbuffer = NULL;
7841 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007842#ifdef USE_ION
7843 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007844 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07007845 free(drv_ctx.op_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007846 drv_ctx.op_buf_ion_info = NULL;
7847 }
7848#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07007849 if (out_dynamic_list) {
7850 free(out_dynamic_list);
7851 out_dynamic_list = NULL;
7852 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007853}
7854
7855void omx_vdec::free_input_buffer_header()
7856{
7857 input_use_buffer = false;
Arun Menon906de572013-06-18 17:01:40 -07007858 if (arbitrary_bytes) {
Arun Menon906de572013-06-18 17:01:40 -07007859 if (m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007860 DEBUG_PRINT_LOW("Free input Heap Pointer");
Arun Menon906de572013-06-18 17:01:40 -07007861 free (m_inp_heap_ptr);
7862 m_inp_heap_ptr = NULL;
7863 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007864
Arun Menon906de572013-06-18 17:01:40 -07007865 if (m_phdr_pmem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007866 DEBUG_PRINT_LOW("Free input pmem header Pointer");
Arun Menon906de572013-06-18 17:01:40 -07007867 free (m_phdr_pmem_ptr);
7868 m_phdr_pmem_ptr = NULL;
7869 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007870 }
Arun Menon906de572013-06-18 17:01:40 -07007871 if (m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007872 DEBUG_PRINT_LOW("Free input pmem Pointer area");
Arun Menon906de572013-06-18 17:01:40 -07007873 free (m_inp_mem_ptr);
7874 m_inp_mem_ptr = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007875 }
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07007876 /* We just freed all the buffer headers, every thing in m_input_free_q,
7877 * m_input_pending_q, pdest_frame, and psource_frame is now invalid */
Leena Winterrowd1d2424a2013-08-20 15:26:02 -07007878 while (m_input_free_q.m_size) {
7879 unsigned address, p2, id;
7880 m_input_free_q.pop_entry(&address, &p2, &id);
7881 }
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07007882 while (m_input_pending_q.m_size) {
7883 unsigned address, p2, id;
7884 m_input_pending_q.pop_entry(&address, &p2, &id);
7885 }
7886 pdest_frame = NULL;
7887 psource_frame = NULL;
Arun Menon906de572013-06-18 17:01:40 -07007888 if (drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007889 DEBUG_PRINT_LOW("Free Driver Context pointer");
Arun Menon906de572013-06-18 17:01:40 -07007890 free (drv_ctx.ptr_inputbuffer);
7891 drv_ctx.ptr_inputbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007892 }
7893#ifdef USE_ION
7894 if (drv_ctx.ip_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007895 DEBUG_PRINT_LOW("Free ion context");
Arun Menon906de572013-06-18 17:01:40 -07007896 free(drv_ctx.ip_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007897 drv_ctx.ip_buf_ion_info = NULL;
7898 }
7899#endif
7900}
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007901
7902int omx_vdec::stream_off(OMX_U32 port)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007903{
Arun Menon906de572013-06-18 17:01:40 -07007904 enum v4l2_buf_type btype;
7905 int rc = 0;
7906 enum v4l2_ports v4l2_port = OUTPUT_PORT;
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007907
Arun Menon906de572013-06-18 17:01:40 -07007908 if (port == OMX_CORE_INPUT_PORT_INDEX) {
7909 btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7910 v4l2_port = OUTPUT_PORT;
7911 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
7912 btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7913 v4l2_port = CAPTURE_PORT;
7914 } else if (port == OMX_ALL) {
7915 int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX);
7916 int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007917
Arun Menon906de572013-06-18 17:01:40 -07007918 if (!rc_input)
7919 return rc_input;
7920 else
7921 return rc_output;
7922 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007923
Arun Menon906de572013-06-18 17:01:40 -07007924 if (!streaming[v4l2_port]) {
7925 // already streamed off, warn and move on
7926 DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port,"
7927 " which is already streamed off", v4l2_port);
7928 return 0;
7929 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007930
Arun Menon906de572013-06-18 17:01:40 -07007931 DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007932
Arun Menon906de572013-06-18 17:01:40 -07007933 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype);
7934 if (rc) {
7935 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007936 DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port);
Arun Menon906de572013-06-18 17:01:40 -07007937 } else {
7938 streaming[v4l2_port] = false;
7939 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007940
Arun Menon906de572013-06-18 17:01:40 -07007941 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007942}
7943
7944OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop)
7945{
Arun Menon906de572013-06-18 17:01:40 -07007946 OMX_ERRORTYPE eRet = OMX_ErrorNone;
7947 struct v4l2_requestbuffers bufreq;
Deva Ramasubramanian991d0db2014-05-08 15:02:24 -07007948 unsigned int buf_size = 0, extra_data_size = 0, default_extra_data_size = 0;
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05307949 unsigned int final_extra_data_size = 0;
Arun Menon906de572013-06-18 17:01:40 -07007950 struct v4l2_format fmt;
7951 int ret = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007952 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
Arun Menon906de572013-06-18 17:01:40 -07007953 buffer_prop->actualcount, buffer_prop->buffer_size);
7954 bufreq.memory = V4L2_MEMORY_USERPTR;
7955 bufreq.count = 1;
7956 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
7957 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7958 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7959 fmt.fmt.pix_mp.pixelformat = output_capability;
7960 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
7961 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7962 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7963 fmt.fmt.pix_mp.pixelformat = capture_capability;
7964 } else {
7965 eRet = OMX_ErrorBadParameter;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07007966 }
Arun Menon906de572013-06-18 17:01:40 -07007967 if (eRet==OMX_ErrorNone) {
7968 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007969 }
Arun Menon906de572013-06-18 17:01:40 -07007970 if (ret) {
7971 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
7972 /*TODO: How to handle this case */
7973 eRet = OMX_ErrorInsufficientResources;
7974 return eRet;
7975 } else {
7976 buffer_prop->actualcount = bufreq.count;
7977 buffer_prop->mincount = bufreq.count;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007978 DEBUG_PRINT_HIGH("Count = %d",bufreq.count);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007979 }
Arun Menon906de572013-06-18 17:01:40 -07007980 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
7981 buffer_prop->actualcount, buffer_prop->buffer_size);
7982
7983 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
7984 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
7985
7986 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
7987
7988 update_resolution(fmt.fmt.pix_mp.width,
7989 fmt.fmt.pix_mp.height,
7990 fmt.fmt.pix_mp.plane_fmt[0].bytesperline,
7991 fmt.fmt.pix_mp.plane_fmt[0].reserved[0]);
7992 if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
7993 drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007994 DEBUG_PRINT_HIGH("Buffer Size = %d",fmt.fmt.pix_mp.plane_fmt[0].sizeimage);
Arun Menon906de572013-06-18 17:01:40 -07007995
7996 if (ret) {
7997 /*TODO: How to handle this case */
7998 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
7999 eRet = OMX_ErrorInsufficientResources;
8000 } else {
8001 int extra_idx = 0;
8002
8003 eRet = is_video_session_supported();
8004 if (eRet)
8005 return eRet;
8006
8007 buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage;
8008 buf_size = buffer_prop->buffer_size;
8009 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
8010 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
8011 extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage;
8012 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008013 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07008014 return OMX_ErrorBadParameter;
8015 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008016
Deva Ramasubramanian991d0db2014-05-08 15:02:24 -07008017 default_extra_data_size = VENUS_EXTRADATA_SIZE(
8018 drv_ctx.video_resolution.frame_height,
8019 drv_ctx.video_resolution.frame_width);
8020 final_extra_data_size = extra_data_size > default_extra_data_size ?
8021 extra_data_size : default_extra_data_size;
8022
8023 final_extra_data_size = (final_extra_data_size + buffer_prop->alignment - 1) &
8024 (~(buffer_prop->alignment - 1));
Deva Ramasubramanian2ebfed32014-04-24 13:34:24 -07008025
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308026 drv_ctx.extradata_info.size = buffer_prop->actualcount * final_extra_data_size;
Arun Menon906de572013-06-18 17:01:40 -07008027 drv_ctx.extradata_info.count = buffer_prop->actualcount;
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308028 drv_ctx.extradata_info.buffer_size = final_extra_data_size;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308029 if (!secure_mode)
8030 buf_size += final_extra_data_size;
Arun Menon906de572013-06-18 17:01:40 -07008031 buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
8032 DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)",
8033 buffer_prop->actualcount, buffer_prop->buffer_size, buf_size);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008034 if (extra_data_size)
8035 DEBUG_PRINT_LOW("GetBufReq UPDATE: extradata: TotalSize(%d) BufferSize(%d)",
8036 drv_ctx.extradata_info.size, drv_ctx.extradata_info.buffer_size);
8037
Arun Menon906de572013-06-18 17:01:40 -07008038 if (in_reconfig) // BufReq will be set to driver when port is disabled
8039 buffer_prop->buffer_size = buf_size;
8040 else if (buf_size != buffer_prop->buffer_size) {
8041 buffer_prop->buffer_size = buf_size;
8042 eRet = set_buffer_req(buffer_prop);
8043 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008044 }
Arun Menon906de572013-06-18 17:01:40 -07008045 DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)",
8046 buffer_prop->actualcount, buffer_prop->buffer_size);
8047 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008048}
8049
8050OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop)
8051{
Arun Menon906de572013-06-18 17:01:40 -07008052 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8053 unsigned buf_size = 0;
8054 struct v4l2_format fmt;
8055 struct v4l2_requestbuffers bufreq;
8056 int ret;
8057 DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)",
8058 buffer_prop->actualcount, buffer_prop->buffer_size);
8059 buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
8060 if (buf_size != buffer_prop->buffer_size) {
8061 DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)",
8062 buffer_prop->buffer_size, buf_size);
8063 eRet = OMX_ErrorBadParameter;
8064 } else {
8065 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
8066 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07008067
Arun Menon906de572013-06-18 17:01:40 -07008068 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8069 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8070 fmt.fmt.pix_mp.pixelformat = output_capability;
Shalaj Jaind3902bb2013-10-07 12:42:55 -07008071 fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size;
Arun Menon906de572013-06-18 17:01:40 -07008072 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8073 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8074 fmt.fmt.pix_mp.pixelformat = capture_capability;
8075 } else {
8076 eRet = OMX_ErrorBadParameter;
8077 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07008078
Arun Menon906de572013-06-18 17:01:40 -07008079 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
8080 if (ret) {
8081 /*TODO: How to handle this case */
8082 DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret);
8083 eRet = OMX_ErrorInsufficientResources;
8084 }
8085
8086 bufreq.memory = V4L2_MEMORY_USERPTR;
8087 bufreq.count = buffer_prop->actualcount;
8088 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8089 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8090 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8091 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8092 } else {
8093 eRet = OMX_ErrorBadParameter;
8094 }
8095
8096 if (eRet==OMX_ErrorNone) {
8097 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
8098 }
8099
8100 if (ret) {
8101 DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret);
8102 /*TODO: How to handle this case */
8103 eRet = OMX_ErrorInsufficientResources;
8104 } else if (bufreq.count < buffer_prop->actualcount) {
8105 DEBUG_PRINT_ERROR("Driver refused to change the number of buffers"
8106 " on v4l2 port %d to %d (prefers %d)", bufreq.type,
8107 buffer_prop->actualcount, bufreq.count);
8108 eRet = OMX_ErrorInsufficientResources;
8109 } else {
8110 if (!client_buffers.update_buffer_req()) {
8111 DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed");
8112 eRet = OMX_ErrorInsufficientResources;
8113 }
8114 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008115 }
Arun Menon906de572013-06-18 17:01:40 -07008116 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008117}
8118
Shalaj Jain273b3e02012-06-22 19:08:03 -07008119OMX_ERRORTYPE omx_vdec::update_picture_resolution()
8120{
Arun Menon906de572013-06-18 17:01:40 -07008121 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8122 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008123}
8124
8125OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn)
8126{
Arun Menon906de572013-06-18 17:01:40 -07008127 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Pushkaraj Patil41588352014-02-25 20:51:34 +05308128 struct v4l2_format fmt;
Arun Menon906de572013-06-18 17:01:40 -07008129 if (!portDefn) {
8130 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008131 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008132 DEBUG_PRINT_LOW("omx_vdec::update_portdef");
Arun Menon906de572013-06-18 17:01:40 -07008133 portDefn->nVersion.nVersion = OMX_SPEC_VERSION;
8134 portDefn->nSize = sizeof(portDefn);
8135 portDefn->eDomain = OMX_PortDomainVideo;
8136 if (drv_ctx.frame_rate.fps_denominator > 0)
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08008137 portDefn->format.video.xFramerate = (drv_ctx.frame_rate.fps_numerator /
8138 drv_ctx.frame_rate.fps_denominator) << 16; //Q16 format
Arun Menon906de572013-06-18 17:01:40 -07008139 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008140 DEBUG_PRINT_ERROR("Error: Divide by zero");
Arun Menon906de572013-06-18 17:01:40 -07008141 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008142 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308143 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Arun Menon906de572013-06-18 17:01:40 -07008144 if (0 == portDefn->nPortIndex) {
8145 portDefn->eDir = OMX_DirInput;
8146 portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount;
8147 portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount;
8148 portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size;
8149 portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused;
8150 portDefn->format.video.eCompressionFormat = eCompressionFormat;
8151 portDefn->bEnabled = m_inp_bEnabled;
8152 portDefn->bPopulated = m_inp_bPopulated;
Pushkaraj Patil41588352014-02-25 20:51:34 +05308153
8154 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8155 fmt.fmt.pix_mp.pixelformat = output_capability;
Arun Menon906de572013-06-18 17:01:40 -07008156 } else if (1 == portDefn->nPortIndex) {
8157 unsigned int buf_size = 0;
8158 if (!client_buffers.update_buffer_req()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008159 DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed");
Arun Menon906de572013-06-18 17:01:40 -07008160 return OMX_ErrorHardware;
8161 }
8162 if (!client_buffers.get_buffer_req(buf_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008163 DEBUG_PRINT_ERROR("update buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07008164 return OMX_ErrorHardware;
8165 }
8166 portDefn->nBufferSize = buf_size;
8167 portDefn->eDir = OMX_DirOutput;
8168 portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount;
8169 portDefn->nBufferCountMin = drv_ctx.op_buf.mincount;
8170 portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
8171 portDefn->bEnabled = m_out_bEnabled;
8172 portDefn->bPopulated = m_out_bPopulated;
8173 if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008174 DEBUG_PRINT_ERROR("Error in getting color format");
Arun Menon906de572013-06-18 17:01:40 -07008175 return OMX_ErrorHardware;
8176 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308177 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8178 fmt.fmt.pix_mp.pixelformat = capture_capability;
Arun Menon906de572013-06-18 17:01:40 -07008179 } else {
8180 portDefn->eDir = OMX_DirMax;
8181 DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d",
8182 (int)portDefn->nPortIndex);
8183 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008184 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308185 if (is_down_scalar_enabled) {
8186 int ret = 0;
8187 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
8188 if (ret) {
8189 DEBUG_PRINT_ERROR("update_portdef : Error in getting port resolution");
8190 return OMX_ErrorHardware;
8191 } else {
8192 portDefn->format.video.nFrameWidth = fmt.fmt.pix_mp.width;
8193 portDefn->format.video.nFrameHeight = fmt.fmt.pix_mp.height;
8194 portDefn->format.video.nStride = fmt.fmt.pix_mp.plane_fmt[0].bytesperline;
8195 portDefn->format.video.nSliceHeight = fmt.fmt.pix_mp.plane_fmt[0].reserved[0];
8196 }
8197 } else {
8198 portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height;
8199 portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width;
8200 portDefn->format.video.nStride = drv_ctx.video_resolution.stride;
8201 portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines;
8202 }
8203
Praveen Chavandb7776f2014-02-06 18:17:25 -08008204 if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) ||
8205 (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) {
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308206 portDefn->format.video.nStride = drv_ctx.video_resolution.frame_width;
8207 portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height;
8208 }
8209 DEBUG_PRINT_HIGH("update_portdef(%lu): Width = %lu Height = %lu Stride = %ld "
8210 "SliceHeight = %lu eColorFormat = %lu nBufSize %lu nBufCnt %lu",
8211 portDefn->nPortIndex,
8212 portDefn->format.video.nFrameWidth,
Arun Menon906de572013-06-18 17:01:40 -07008213 portDefn->format.video.nFrameHeight,
8214 portDefn->format.video.nStride,
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308215 portDefn->format.video.nSliceHeight,
8216 portDefn->format.video.eColorFormat,
8217 portDefn->nBufferSize,
8218 portDefn->nBufferCountActual);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008219
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308220 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008221}
8222
8223OMX_ERRORTYPE omx_vdec::allocate_output_headers()
8224{
Arun Menon906de572013-06-18 17:01:40 -07008225 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8226 OMX_BUFFERHEADERTYPE *bufHdr = NULL;
8227 unsigned i= 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008228
Arun Menon906de572013-06-18 17:01:40 -07008229 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008230 DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation");
Arun Menon906de572013-06-18 17:01:40 -07008231 int nBufHdrSize = 0;
8232 int nPlatformEntrySize = 0;
8233 int nPlatformListSize = 0;
8234 int nPMEMInfoSize = 0;
8235 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
8236 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
8237 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008238
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008239 DEBUG_PRINT_LOW("Setting First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07008240 drv_ctx.op_buf.actualcount);
8241 nBufHdrSize = drv_ctx.op_buf.actualcount *
8242 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008243
Arun Menon906de572013-06-18 17:01:40 -07008244 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
8245 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
8246 nPlatformListSize = drv_ctx.op_buf.actualcount *
8247 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
8248 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
8249 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008250
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008251 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07008252 sizeof(OMX_BUFFERHEADERTYPE),
8253 nPMEMInfoSize,
8254 nPlatformListSize);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008255 DEBUG_PRINT_LOW("PE %d bmSize %d",nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07008256 m_out_bm_count);
8257 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
8258 // Alloc mem for platform specific info
8259 char *pPtr=NULL;
8260 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
8261 nPMEMInfoSize,1);
8262 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \
8263 calloc (sizeof(struct vdec_bufferpayload),
8264 drv_ctx.op_buf.actualcount);
8265 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
8266 calloc (sizeof (struct vdec_output_frameinfo),
8267 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07008268 if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) {
8269 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer");
8270 return OMX_ErrorInsufficientResources;
8271 }
8272
Shalaj Jain273b3e02012-06-22 19:08:03 -07008273#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008274 drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \
8275 calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07008276 if (!drv_ctx.op_buf_ion_info) {
8277 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info");
8278 return OMX_ErrorInsufficientResources;
8279 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008280#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07008281 if (dynamic_buf_mode) {
8282 out_dynamic_list = (struct dynamic_buf_list *) \
8283 calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount);
8284 }
Arun Menon906de572013-06-18 17:01:40 -07008285 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
8286 && drv_ctx.ptr_respbuffer) {
8287 bufHdr = m_out_mem_ptr;
8288 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
8289 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
8290 (((char *) m_platform_list) + nPlatformListSize);
8291 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
8292 (((char *) m_platform_entry) + nPlatformEntrySize);
8293 pPlatformList = m_platform_list;
8294 pPlatformEntry = m_platform_entry;
8295 pPMEMInfo = m_pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008296
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008297 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008298
Arun Menon906de572013-06-18 17:01:40 -07008299 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008300 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr,
Arun Menon906de572013-06-18 17:01:40 -07008301 m_out_mem_ptr,pPlatformEntry);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008302 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07008303 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
8304 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
8305 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
8306 // Set the values when we determine the right HxW param
8307 bufHdr->nAllocLen = 0;
8308 bufHdr->nFilledLen = 0;
8309 bufHdr->pAppPrivate = NULL;
8310 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8311 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
8312 pPlatformEntry->entry = pPMEMInfo;
8313 // Initialize the Platform List
8314 pPlatformList->nEntries = 1;
8315 pPlatformList->entryList = pPlatformEntry;
8316 // Keep pBuffer NULL till vdec is opened
8317 bufHdr->pBuffer = NULL;
8318 pPMEMInfo->offset = 0;
8319 pPMEMInfo->pmem_fd = 0;
8320 bufHdr->pPlatformPrivate = pPlatformList;
8321 drv_ctx.ptr_outputbuffer[i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008322#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008323 drv_ctx.op_buf_ion_info[i].ion_device_fd =-1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008324#endif
Arun Menon906de572013-06-18 17:01:40 -07008325 /*Create a mapping between buffers*/
8326 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
8327 drv_ctx.ptr_respbuffer[i].client_data = (void *) \
8328 &drv_ctx.ptr_outputbuffer[i];
8329 // Move the buffer and buffer header pointers
8330 bufHdr++;
8331 pPMEMInfo++;
8332 pPlatformEntry++;
8333 pPlatformList++;
8334 }
8335 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008336 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07008337 m_out_mem_ptr, pPtr);
8338 if (m_out_mem_ptr) {
8339 free(m_out_mem_ptr);
8340 m_out_mem_ptr = NULL;
8341 }
8342 if (pPtr) {
8343 free(pPtr);
8344 pPtr = NULL;
8345 }
8346 if (drv_ctx.ptr_outputbuffer) {
8347 free(drv_ctx.ptr_outputbuffer);
8348 drv_ctx.ptr_outputbuffer = NULL;
8349 }
8350 if (drv_ctx.ptr_respbuffer) {
8351 free(drv_ctx.ptr_respbuffer);
8352 drv_ctx.ptr_respbuffer = NULL;
8353 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008354#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008355 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008356 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07008357 free(drv_ctx.op_buf_ion_info);
8358 drv_ctx.op_buf_ion_info = NULL;
8359 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008360#endif
Arun Menon906de572013-06-18 17:01:40 -07008361 eRet = OMX_ErrorInsufficientResources;
8362 }
8363 } else {
8364 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008365 }
Arun Menon906de572013-06-18 17:01:40 -07008366 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008367}
8368
8369void omx_vdec::complete_pending_buffer_done_cbs()
8370{
Arun Menon906de572013-06-18 17:01:40 -07008371 unsigned p1;
8372 unsigned p2;
8373 unsigned ident;
8374 omx_cmd_queue tmp_q, pending_bd_q;
8375 pthread_mutex_lock(&m_lock);
8376 // pop all pending GENERATE FDB from ftb queue
8377 while (m_ftb_q.m_size) {
8378 m_ftb_q.pop_entry(&p1,&p2,&ident);
8379 if (ident == OMX_COMPONENT_GENERATE_FBD) {
8380 pending_bd_q.insert_entry(p1,p2,ident);
8381 } else {
8382 tmp_q.insert_entry(p1,p2,ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008383 }
Arun Menon906de572013-06-18 17:01:40 -07008384 }
8385 //return all non GENERATE FDB to ftb queue
8386 while (tmp_q.m_size) {
8387 tmp_q.pop_entry(&p1,&p2,&ident);
8388 m_ftb_q.insert_entry(p1,p2,ident);
8389 }
8390 // pop all pending GENERATE EDB from etb queue
8391 while (m_etb_q.m_size) {
8392 m_etb_q.pop_entry(&p1,&p2,&ident);
8393 if (ident == OMX_COMPONENT_GENERATE_EBD) {
8394 pending_bd_q.insert_entry(p1,p2,ident);
8395 } else {
8396 tmp_q.insert_entry(p1,p2,ident);
8397 }
8398 }
8399 //return all non GENERATE FDB to etb queue
8400 while (tmp_q.m_size) {
8401 tmp_q.pop_entry(&p1,&p2,&ident);
8402 m_etb_q.insert_entry(p1,p2,ident);
8403 }
8404 pthread_mutex_unlock(&m_lock);
8405 // process all pending buffer dones
8406 while (pending_bd_q.m_size) {
8407 pending_bd_q.pop_entry(&p1,&p2,&ident);
8408 switch (ident) {
8409 case OMX_COMPONENT_GENERATE_EBD:
8410 if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008411 DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07008412 omx_report_error ();
8413 }
8414 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008415
Arun Menon906de572013-06-18 17:01:40 -07008416 case OMX_COMPONENT_GENERATE_FBD:
8417 if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008418 DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07008419 omx_report_error ();
8420 }
8421 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008422 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008423 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008424}
8425
8426void omx_vdec::set_frame_rate(OMX_S64 act_timestamp)
8427{
Arun Menon906de572013-06-18 17:01:40 -07008428 OMX_U32 new_frame_interval = 0;
8429 if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts
8430 && llabs(act_timestamp - prev_ts) > 2000) {
8431 new_frame_interval = client_set_fps ? frm_int :
8432 llabs(act_timestamp - prev_ts);
Arun Menond9e49f82014-04-23 18:50:26 -07008433 if (new_frame_interval != frm_int || frm_int == 0) {
Arun Menon906de572013-06-18 17:01:40 -07008434 frm_int = new_frame_interval;
8435 if (frm_int) {
8436 drv_ctx.frame_rate.fps_numerator = 1e6;
8437 drv_ctx.frame_rate.fps_denominator = frm_int;
8438 DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)",
8439 frm_int, drv_ctx.frame_rate.fps_numerator /
8440 (float)drv_ctx.frame_rate.fps_denominator);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008441
Arun Menon906de572013-06-18 17:01:40 -07008442 /* We need to report the difference between this FBD and the previous FBD
8443 * back to the driver for clock scaling purposes. */
8444 struct v4l2_outputparm oparm;
8445 /*XXX: we're providing timing info as seconds per frame rather than frames
8446 * per second.*/
8447 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
8448 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008449
Arun Menon906de572013-06-18 17:01:40 -07008450 struct v4l2_streamparm sparm;
8451 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8452 sparm.parm.output = oparm;
8453 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
8454 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
8455 performance might be affected");
8456 }
8457
8458 }
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008459 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008460 }
Arun Menon906de572013-06-18 17:01:40 -07008461 prev_ts = act_timestamp;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008462}
8463
8464void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp)
8465{
Arun Menon906de572013-06-18 17:01:40 -07008466 if (rst_prev_ts && VALID_TS(act_timestamp)) {
8467 prev_ts = act_timestamp;
8468 rst_prev_ts = false;
8469 } else if (VALID_TS(prev_ts)) {
8470 bool codec_cond = (drv_ctx.timestamp_adjust)?
8471 (!VALID_TS(act_timestamp) || (((act_timestamp > prev_ts)?
8472 (act_timestamp - prev_ts):(prev_ts - act_timestamp)) <= 2000)):
8473 (!VALID_TS(act_timestamp) || act_timestamp == prev_ts);
8474 if (frm_int > 0 && codec_cond) {
8475 DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp);
8476 act_timestamp = prev_ts + frm_int;
8477 DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp);
8478 prev_ts = act_timestamp;
Leena Winterrowdd139fdc2014-08-05 18:04:25 -07008479 } else {
8480 if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) {
8481 // ensure that timestamps can never step backwards when in display order
8482 act_timestamp = prev_ts;
8483 }
Arun Menon906de572013-06-18 17:01:40 -07008484 set_frame_rate(act_timestamp);
Leena Winterrowdd139fdc2014-08-05 18:04:25 -07008485 }
Arun Menon906de572013-06-18 17:01:40 -07008486 } else if (frm_int > 0) // In this case the frame rate was set along
8487 { // with the port definition, start ts with 0
8488 act_timestamp = prev_ts = 0; // and correct if a valid ts is received.
8489 rst_prev_ts = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008490 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008491}
8492
8493void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr)
8494{
Arun Menon906de572013-06-18 17:01:40 -07008495 OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL;
8496 OMX_U32 num_conceal_MB = 0;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308497 OMX_TICKS time_stamp = 0;
Arun Menon906de572013-06-18 17:01:40 -07008498 OMX_U32 frame_rate = 0;
8499 int consumed_len = 0;
8500 OMX_U32 num_MB_in_frame;
8501 OMX_U32 recovery_sei_flags = 1;
8502 int enable = 0;
Arun Menon7b6fd642014-02-13 16:48:36 -08008503
Arun Menon906de572013-06-18 17:01:40 -07008504 int buf_index = p_buf_hdr - m_out_mem_ptr;
Praveen Chavan61e5d162013-11-01 02:49:19 -07008505 if (buf_index >= drv_ctx.extradata_info.count) {
8506 DEBUG_PRINT_ERROR("handle_extradata: invalid index(%d) max(%d)",
8507 buf_index, drv_ctx.extradata_info.count);
8508 return;
8509 }
Arun Menon906de572013-06-18 17:01:40 -07008510 struct msm_vidc_panscan_window_payload *panscan_payload = NULL;
8511 OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) +
8512 p_buf_hdr->nOffset;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308513
Arun Menon906de572013-06-18 17:01:40 -07008514 if (!drv_ctx.extradata_info.uaddr) {
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308515 DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr");
Arun Menon906de572013-06-18 17:01:40 -07008516 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008517 }
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308518
8519 if (!secure_mode && (drv_ctx.extradata_info.buffer_size > (p_buf_hdr->nAllocLen - p_buf_hdr->nFilledLen)) ) {
8520 DEBUG_PRINT_ERROR("Error: Insufficient size allocated for extra-data");
8521 p_extra = NULL;
8522 return;
8523 }
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308524 if (!secure_mode)
8525 p_extra = (OMX_OTHER_EXTRADATATYPE *)
Arun Menon906de572013-06-18 17:01:40 -07008526 ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3));
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308527 else
8528 p_extra = m_other_extradata;
8529
Arun Menon906de572013-06-18 17:01:40 -07008530 char *p_extradata = drv_ctx.extradata_info.uaddr + buf_index * drv_ctx.extradata_info.buffer_size;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308531 if (!secure_mode && ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))) {
8532 DEBUG_PRINT_ERROR("Error: out of bound memory access by p_extra");
Arun Menon906de572013-06-18 17:01:40 -07008533 p_extra = NULL;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308534 return;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008535 }
Arun Menon906de572013-06-18 17:01:40 -07008536 OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008537 if (data && p_extra) {
Arun Menon906de572013-06-18 17:01:40 -07008538 while ((consumed_len < drv_ctx.extradata_info.buffer_size)
8539 && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) {
Surajit Podderd2644d52013-08-28 17:59:06 +05308540 if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) {
Arun Menon906de572013-06-18 17:01:40 -07008541 DEBUG_PRINT_LOW("Invalid extra data size");
8542 break;
8543 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308544 DEBUG_PRINT_LOW("handle_extradata: eType = %d", data->eType);
Arun Menon906de572013-06-18 17:01:40 -07008545 switch ((unsigned long)data->eType) {
8546 case EXTRADATA_INTERLACE_VIDEO:
8547 struct msm_vidc_interlace_payload *payload;
8548 payload = (struct msm_vidc_interlace_payload *)data->data;
Arun Menon7b6fd642014-02-13 16:48:36 -08008549 if (payload) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008550 enable = 1;
Arun Menon7b6fd642014-02-13 16:48:36 -08008551 switch (payload->format) {
8552 case INTERLACE_FRAME_PROGRESSIVE:
8553 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
8554 enable = 0;
8555 break;
8556 case INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST:
8557 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8558 break;
8559 case INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST:
8560 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameBottomFieldFirst;
8561 break;
8562 default:
8563 DEBUG_PRINT_LOW("default case - set interlace to topfield");
8564 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8565 }
Arun Menon906de572013-06-18 17:01:40 -07008566 }
8567 if (m_enable_android_native_buffers)
8568 setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle,
8569 PP_PARAM_INTERLACED, (void*)&enable);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308570 if (client_extradata & OMX_INTERLACE_EXTRADATA) {
Arun Menon7b6fd642014-02-13 16:48:36 -08008571 append_interlace_extradata(p_extra, payload->format,
8572 p_buf_hdr->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF);
Arun Menon906de572013-06-18 17:01:40 -07008573 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8574 }
8575 break;
8576 case EXTRADATA_FRAME_RATE:
8577 struct msm_vidc_framerate_payload *frame_rate_payload;
8578 frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data;
8579 frame_rate = frame_rate_payload->frame_rate;
8580 break;
8581 case EXTRADATA_TIMESTAMP:
8582 struct msm_vidc_ts_payload *time_stamp_payload;
8583 time_stamp_payload = (struct msm_vidc_ts_payload *)data->data;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308584 time_stamp = time_stamp_payload->timestamp_lo;
8585 time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32);
8586 p_buf_hdr->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07008587 break;
8588 case EXTRADATA_NUM_CONCEALED_MB:
8589 struct msm_vidc_concealmb_payload *conceal_mb_payload;
8590 conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data;
8591 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8592 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8593 num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0);
8594 break;
8595 case EXTRADATA_INDEX:
8596 int *etype;
8597 etype = (int *)(data->data);
8598 if (etype && *etype == EXTRADATA_ASPECT_RATIO) {
8599 struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload;
8600 aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype);
8601 if (aspect_ratio_payload) {
8602 ((struct vdec_output_frameinfo *)
8603 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width;
8604 ((struct vdec_output_frameinfo *)
8605 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height;
8606 }
8607 }
8608 break;
8609 case EXTRADATA_RECOVERY_POINT_SEI:
8610 struct msm_vidc_recoverysei_payload *recovery_sei_payload;
8611 recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data;
8612 recovery_sei_flags = recovery_sei_payload->flags;
8613 if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) {
8614 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008615 DEBUG_PRINT_HIGH("");
8616 DEBUG_PRINT_HIGH("***************************************************");
8617 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
8618 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07008619 }
8620 break;
8621 case EXTRADATA_PANSCAN_WINDOW:
8622 panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data;
8623 break;
8624 case EXTRADATA_MPEG2_SEQDISP:
8625 struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload;
8626 seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data;
8627 if (seqdisp_payload) {
8628 m_disp_hor_size = seqdisp_payload->disp_width;
8629 m_disp_vert_size = seqdisp_payload->disp_height;
8630 }
8631 break;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308632 case EXTRADATA_S3D_FRAME_PACKING:
8633 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload;
8634 s3d_frame_packing_payload = (struct msm_vidc_s3d_frame_packing_payload *)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308635 if (client_extradata & OMX_FRAMEPACK_EXTRADATA) {
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308636 append_framepack_extradata(p_extra, s3d_frame_packing_payload);
8637 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8638 }
8639 break;
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008640 case EXTRADATA_FRAME_QP:
8641 struct msm_vidc_frame_qp_payload *qp_payload;
8642 qp_payload = (struct msm_vidc_frame_qp_payload*)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308643 if (client_extradata & OMX_QP_EXTRADATA) {
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008644 append_qp_extradata(p_extra, qp_payload);
8645 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8646 }
8647 break;
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008648 case EXTRADATA_FRAME_BITS_INFO:
8649 struct msm_vidc_frame_bits_info_payload *bits_info_payload;
8650 bits_info_payload = (struct msm_vidc_frame_bits_info_payload*)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308651 if (client_extradata & OMX_BITSINFO_EXTRADATA) {
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008652 append_bitsinfo_extradata(p_extra, bits_info_payload);
8653 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8654 }
8655 break;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008656 case EXTRADATA_STREAM_USERDATA:
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308657 if (client_extradata & OMX_EXTNUSER_EXTRADATA) {
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008658 append_user_extradata(p_extra, data);
8659 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8660 }
8661 break;
Arun Menon906de572013-06-18 17:01:40 -07008662 default:
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008663 DEBUG_PRINT_LOW("Unrecognized extradata");
Arun Menon906de572013-06-18 17:01:40 -07008664 goto unrecognized_extradata;
8665 }
8666 consumed_len += data->nSize;
8667 data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize);
8668 }
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308669 if (client_extradata & OMX_FRAMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008670 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
8671 append_frame_info_extradata(p_extra,
8672 num_conceal_MB, ((struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate)->pic_type, frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308673 time_stamp, panscan_payload,&((struct vdec_output_frameinfo *)
Arun Menon906de572013-06-18 17:01:40 -07008674 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info);
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008675 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
Arun Menon906de572013-06-18 17:01:40 -07008676 }
8677 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07008678unrecognized_extradata:
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008679 if (client_extradata && p_extra) {
8680 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
Arun Menon906de572013-06-18 17:01:40 -07008681 append_terminator_extradata(p_extra);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008682 }
8683
Arun Menonfd723932014-05-30 17:56:31 -07008684 if (secure_mode && p_extradata && m_other_extradata) {
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308685 struct vdec_output_frameinfo *ptr_extradatabuff = NULL;
8686 memcpy(p_extradata, m_other_extradata, drv_ctx.extradata_info.buffer_size);
8687 ptr_extradatabuff = (struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate;
8688 ptr_extradatabuff->metadata_info.metabufaddr = (void *)p_extradata;
8689 ptr_extradatabuff->metadata_info.size = drv_ctx.extradata_info.buffer_size;
8690 }
Arun Menon906de572013-06-18 17:01:40 -07008691 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008692}
8693
Vinay Kalia9c00cae2012-12-06 16:08:20 -08008694OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata,
Arun Menon906de572013-06-18 17:01:40 -07008695 bool is_internal, bool enable)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008696{
Arun Menon906de572013-06-18 17:01:40 -07008697 OMX_ERRORTYPE ret = OMX_ErrorNone;
8698 struct v4l2_control control;
8699 if (m_state != OMX_StateLoaded) {
8700 DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only");
8701 return OMX_ErrorIncorrectStateOperation;
Vinay Kaliadb90f8c2012-11-19 18:57:56 -08008702 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008703 DEBUG_PRINT_HIGH("NOTE: enable_extradata: actual[%lu] requested[%lu] enable[%d], is_internal: %d",
Arun Menon906de572013-06-18 17:01:40 -07008704 client_extradata, requested_extradata, enable, is_internal);
8705
8706 if (!is_internal) {
8707 if (enable)
8708 client_extradata |= requested_extradata;
8709 else
8710 client_extradata = client_extradata & ~requested_extradata;
8711 }
8712
8713 if (enable) {
8714 if (requested_extradata & OMX_INTERLACE_EXTRADATA) {
8715 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8716 control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO;
8717 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8718 DEBUG_PRINT_HIGH("Failed to set interlaced extradata."
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008719 " Quality of interlaced clips might be impacted.");
Arun Menon906de572013-06-18 17:01:40 -07008720 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308721 }
8722 if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008723 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8724 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE;
8725 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008726 DEBUG_PRINT_HIGH("Failed to set framerate extradata");
Arun Menon906de572013-06-18 17:01:40 -07008727 }
8728 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8729 control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB;
8730 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008731 DEBUG_PRINT_HIGH("Failed to set concealed MB extradata");
Arun Menon906de572013-06-18 17:01:40 -07008732 }
8733 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8734 control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI;
8735 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008736 DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata");
Arun Menon906de572013-06-18 17:01:40 -07008737 }
8738 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8739 control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW;
8740 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008741 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008742 }
8743 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8744 control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO;
8745 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008746 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008747 }
8748 if (output_capability == V4L2_PIX_FMT_MPEG2) {
8749 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8750 control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP;
8751 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008752 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008753 }
8754 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308755 }
8756 if (requested_extradata & OMX_TIMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008757 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8758 control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP;
8759 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008760 DEBUG_PRINT_HIGH("Failed to set timeinfo extradata");
Arun Menon906de572013-06-18 17:01:40 -07008761 }
8762 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308763 if (requested_extradata & OMX_FRAMEPACK_EXTRADATA) {
8764 if (output_capability == V4L2_PIX_FMT_H264) {
8765 DEBUG_PRINT_HIGH("enable OMX_FRAMEPACK_EXTRADATA");
8766 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8767 control.value = V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING;
8768 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8769 DEBUG_PRINT_HIGH("Failed to set S3D_FRAME_PACKING extradata");
8770 }
8771 } else {
8772 DEBUG_PRINT_HIGH("OMX_FRAMEPACK_EXTRADATA supported for H264 only");
8773 }
8774 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008775 if (requested_extradata & OMX_QP_EXTRADATA) {
8776 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8777 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP;
8778 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8779 DEBUG_PRINT_HIGH("Failed to set QP extradata");
8780 }
8781 }
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008782 if (requested_extradata & OMX_BITSINFO_EXTRADATA) {
8783 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8784 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO;
8785 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8786 DEBUG_PRINT_HIGH("Failed to set frame bits info extradata");
8787 }
8788 }
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008789 if (requested_extradata & OMX_EXTNUSER_EXTRADATA) {
8790 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8791 control.value = V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA;
8792 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8793 DEBUG_PRINT_HIGH("Failed to set stream userdata extradata");
8794 }
8795 }
Arun Menon906de572013-06-18 17:01:40 -07008796 }
8797 ret = get_buffer_req(&drv_ctx.op_buf);
8798 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008799}
8800
8801OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8802{
Arun Menon906de572013-06-18 17:01:40 -07008803 OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0;
8804 OMX_U8 *data_ptr = extra->data, data = 0;
8805 while (byte_count < extra->nDataSize) {
8806 data = *data_ptr;
8807 while (data) {
8808 num_MB += (data&0x01);
8809 data >>= 1;
8810 }
8811 data_ptr++;
8812 byte_count++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008813 }
Arun Menon906de572013-06-18 17:01:40 -07008814 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8815 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8816 return ((num_MB_in_frame > 0)?(num_MB * 100 / num_MB_in_frame) : 0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008817}
8818
8819void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8820{
Arun Menon906de572013-06-18 17:01:40 -07008821 if (!m_debug_extradata)
8822 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008823
8824 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308825 "============== Extra Data ==============\n"
8826 " Size: %lu\n"
8827 " Version: %lu\n"
8828 " PortIndex: %lu\n"
8829 " Type: %x\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008830 " DataSize: %lu",
Arun Menon906de572013-06-18 17:01:40 -07008831 extra->nSize, extra->nVersion.nVersion,
8832 extra->nPortIndex, extra->eType, extra->nDataSize);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008833
Arun Menon906de572013-06-18 17:01:40 -07008834 if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) {
8835 OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data;
8836 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308837 "------ Interlace Format ------\n"
8838 " Size: %lu\n"
8839 " Version: %lu\n"
8840 " PortIndex: %lu\n"
8841 " Is Interlace Format: %d\n"
8842 " Interlace Formats: %lu\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008843 "=========== End of Interlace ===========",
Arun Menon906de572013-06-18 17:01:40 -07008844 intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex,
8845 intfmt->bInterlaceFormat, intfmt->nInterlaceFormats);
8846 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) {
8847 OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
8848
8849 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308850 "-------- Frame Format --------\n"
8851 " Picture Type: %d\n"
8852 " Interlace Type: %d\n"
8853 " Pan Scan Total Frame Num: %lu\n"
8854 " Concealed Macro Blocks: %lu\n"
8855 " frame rate: %lu\n"
8856 " Time Stamp: %llu\n"
8857 " Aspect Ratio X: %lu\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008858 " Aspect Ratio Y: %lu",
Arun Menon906de572013-06-18 17:01:40 -07008859 fminfo->ePicType,
8860 fminfo->interlaceType,
8861 fminfo->panScan.numWindows,
8862 fminfo->nConcealedMacroblocks,
8863 fminfo->nFrameRate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308864 fminfo->nTimeStamp,
Arun Menon906de572013-06-18 17:01:40 -07008865 fminfo->aspectRatio.aspectRatioX,
8866 fminfo->aspectRatio.aspectRatioY);
8867
8868 for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) {
8869 DEBUG_PRINT_HIGH(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008870 "------------------------------"
Deepak Verma867d5132013-12-05 12:23:20 +05308871 " Pan Scan Frame Num: %lu\n"
8872 " Rectangle x: %ld\n"
8873 " Rectangle y: %ld\n"
8874 " Rectangle dx: %ld\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008875 " Rectangle dy: %ld",
Arun Menon906de572013-06-18 17:01:40 -07008876 i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y,
8877 fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy);
8878 }
8879
8880 DEBUG_PRINT_HIGH("========= End of Frame Format ==========");
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308881 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement) {
8882 OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data;
8883 DEBUG_PRINT_HIGH(
8884 "------------------ Framepack Format ----------\n"
8885 " id: %lu \n"
8886 " cancel_flag: %lu \n"
8887 " type: %lu \n"
8888 " quincunx_sampling_flagFormat: %lu \n"
8889 " content_interpretation_type: %lu \n"
8890 " content_interpretation_type: %lu \n"
8891 " spatial_flipping_flag: %lu \n"
8892 " frame0_flipped_flag: %lu \n"
8893 " field_views_flag: %lu \n"
8894 " current_frame_is_frame0_flag: %lu \n"
8895 " frame0_self_contained_flag: %lu \n"
8896 " frame1_self_contained_flag: %lu \n"
8897 " frame0_grid_position_x: %lu \n"
8898 " frame0_grid_position_y: %lu \n"
8899 " frame1_grid_position_x: %lu \n"
8900 " frame1_grid_position_y: %lu \n"
8901 " reserved_byte: %lu \n"
8902 " repetition_period: %lu \n"
8903 " extension_flag: %lu \n"
8904 "================== End of Framepack ===========",
8905 framepack->id,
8906 framepack->cancel_flag,
8907 framepack->type,
8908 framepack->quincunx_sampling_flag,
8909 framepack->content_interpretation_type,
8910 framepack->spatial_flipping_flag,
8911 framepack->frame0_flipped_flag,
8912 framepack->field_views_flag,
8913 framepack->current_frame_is_frame0_flag,
8914 framepack->frame0_self_contained_flag,
8915 framepack->frame1_self_contained_flag,
8916 framepack->frame0_grid_position_x,
8917 framepack->frame0_grid_position_y,
8918 framepack->frame1_grid_position_x,
8919 framepack->frame1_grid_position_y,
8920 framepack->reserved_byte,
8921 framepack->repetition_period,
8922 framepack->extension_flag);
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008923 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataQP) {
8924 OMX_QCOM_EXTRADATA_QP * qp = (OMX_QCOM_EXTRADATA_QP *)extra->data;
8925 DEBUG_PRINT_HIGH(
8926 "---- QP (Frame quantization parameter) ----\n"
8927 " Frame QP: %lu \n"
8928 "================ End of QP ================\n",
8929 qp->nQP);
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008930 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo) {
8931 OMX_QCOM_EXTRADATA_BITS_INFO * bits = (OMX_QCOM_EXTRADATA_BITS_INFO *)extra->data;
8932 DEBUG_PRINT_HIGH(
8933 "--------- Input bits information --------\n"
8934 " Header bits: %lu \n"
8935 " Frame bits: %lu \n"
8936 "===== End of Input bits information =====\n",
8937 bits->header_bits, bits->frame_bits);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008938 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData) {
8939 OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)extra->data;
8940 OMX_U8 *data_ptr = (OMX_U8 *)userdata->data;
8941 OMX_U32 userdata_size = extra->nDataSize - sizeof(userdata->type);
8942 OMX_U32 i = 0;
8943 DEBUG_PRINT_HIGH(
8944 "-------------- Userdata -------------\n"
8945 " Stream userdata type: %d\n"
8946 " userdata size: %d\n"
8947 " STREAM_USERDATA:",
8948 userdata->type, userdata_size);
8949 for (i = 0; i < userdata_size; i+=4) {
8950 DEBUG_PRINT_HIGH(" %x %x %x %x",
8951 data_ptr[i], data_ptr[i+1],
8952 data_ptr[i+2], data_ptr[i+3]);
8953 }
8954 DEBUG_PRINT_HIGH(
8955 "=========== End of Userdata ===========");
Arun Menon906de572013-06-18 17:01:40 -07008956 } else if (extra->eType == OMX_ExtraDataNone) {
8957 DEBUG_PRINT_HIGH("========== End of Terminator ===========");
8958 } else {
8959 DEBUG_PRINT_HIGH("======= End of Driver Extradata ========");
Shalaj Jain273b3e02012-06-22 19:08:03 -07008960 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008961}
8962
8963void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon7b6fd642014-02-13 16:48:36 -08008964 OMX_U32 interlaced_format_type, bool is_mbaff)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008965{
Arun Menon906de572013-06-18 17:01:40 -07008966 OMX_STREAMINTERLACEFORMAT *interlace_format;
Arun Menon7b6fd642014-02-13 16:48:36 -08008967
Arun Menon906de572013-06-18 17:01:40 -07008968 if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) {
8969 return;
8970 }
8971 extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE;
8972 extra->nVersion.nVersion = OMX_SPEC_VERSION;
8973 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8974 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat;
8975 extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT);
8976 interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data;
8977 interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT);
8978 interlace_format->nVersion.nVersion = OMX_SPEC_VERSION;
8979 interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
Arun Menon7b6fd642014-02-13 16:48:36 -08008980
8981 if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !is_mbaff) {
Arun Menon906de572013-06-18 17:01:40 -07008982 interlace_format->bInterlaceFormat = OMX_FALSE;
8983 interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive;
8984 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon7b6fd642014-02-13 16:48:36 -08008985 } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST) && !is_mbaff) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008986 interlace_format->bInterlaceFormat = OMX_TRUE;
Arun Menon7b6fd642014-02-13 16:48:36 -08008987 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008988 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon7b6fd642014-02-13 16:48:36 -08008989 } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST) && !is_mbaff) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008990 interlace_format->bInterlaceFormat = OMX_TRUE;
Arun Menon7b6fd642014-02-13 16:48:36 -08008991 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameBottomFieldFirst;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008992 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon906de572013-06-18 17:01:40 -07008993 } else {
8994 interlace_format->bInterlaceFormat = OMX_TRUE;
8995 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst;
8996 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8997 }
8998 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008999}
9000
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009001void omx_vdec::fill_aspect_ratio_info(
Arun Menon906de572013-06-18 17:01:40 -07009002 struct vdec_aspectratioinfo *aspect_ratio_info,
9003 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info)
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009004{
Arun Menon906de572013-06-18 17:01:40 -07009005 m_extradata = frame_info;
9006 m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width;
9007 m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309008 DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX,
Arun Menon906de572013-06-18 17:01:40 -07009009 m_extradata->aspectRatio.aspectRatioY);
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009010}
Shalaj Jain273b3e02012-06-22 19:08:03 -07009011
9012void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon906de572013-06-18 17:01:40 -07009013 OMX_U32 num_conceal_mb, OMX_U32 picture_type, OMX_U32 frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309014 OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload,
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009015 struct vdec_aspectratioinfo *aspect_ratio_info)
Shalaj Jain273b3e02012-06-22 19:08:03 -07009016{
Arun Menon906de572013-06-18 17:01:40 -07009017 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL;
9018 struct msm_vidc_panscan_window *panscan_window;
9019 if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) {
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08009020 return;
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07009021 }
Arun Menon906de572013-06-18 17:01:40 -07009022 extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE;
9023 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9024 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9025 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo;
9026 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO);
9027 frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
9028 switch (picture_type) {
9029 case PICTURE_TYPE_I:
9030 frame_info->ePicType = OMX_VIDEO_PictureTypeI;
9031 break;
9032 case PICTURE_TYPE_P:
9033 frame_info->ePicType = OMX_VIDEO_PictureTypeP;
9034 break;
9035 case PICTURE_TYPE_B:
9036 frame_info->ePicType = OMX_VIDEO_PictureTypeB;
9037 break;
9038 default:
9039 frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0;
9040 }
9041 if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst)
9042 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
9043 else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst)
9044 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
9045 else
9046 frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive;
9047 memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio));
9048 frame_info->nConcealedMacroblocks = num_conceal_mb;
9049 frame_info->nFrameRate = frame_rate;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309050 frame_info->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07009051 frame_info->panScan.numWindows = 0;
9052 if (output_capability == V4L2_PIX_FMT_MPEG2) {
9053 if (m_disp_hor_size && m_disp_vert_size) {
9054 frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size;
9055 frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size;
Pushkaraj Patil5e6ebd92014-03-10 10:29:14 +05309056 } else {
9057 frame_info->displayAspectRatio.displayHorizontalSize = 0;
9058 frame_info->displayAspectRatio.displayVerticalSize = 0;
Arun Menon906de572013-06-18 17:01:40 -07009059 }
9060 }
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07009061
Arun Menon906de572013-06-18 17:01:40 -07009062 if (panscan_payload) {
9063 frame_info->panScan.numWindows = panscan_payload->num_panscan_windows;
9064 panscan_window = &panscan_payload->wnd[0];
9065 for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) {
9066 frame_info->panScan.window[i].x = panscan_window->panscan_window_width;
9067 frame_info->panScan.window[i].y = panscan_window->panscan_window_height;
9068 frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset;
9069 frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset;
9070 panscan_window++;
9071 }
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08009072 }
Arun Menon906de572013-06-18 17:01:40 -07009073 fill_aspect_ratio_info(aspect_ratio_info, frame_info);
9074 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009075}
9076
9077void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra)
9078{
Arun Menon906de572013-06-18 17:01:40 -07009079 OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL;
9080 extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE;
9081 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9082 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9083 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef;
9084 extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
9085 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data;
9086 *portDefn = m_port_def;
9087 DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu "
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009088 "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight,
Arun Menon906de572013-06-18 17:01:40 -07009089 portDefn->format.video.nFrameWidth,
9090 portDefn->format.video.nStride,
9091 portDefn->format.video.nSliceHeight);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009092}
9093
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05309094void omx_vdec::append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9095 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload)
9096{
9097 OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack;
9098 if (FRAME_PACK_SIZE*sizeof(OMX_U32) != sizeof(struct msm_vidc_s3d_frame_packing_payload)) {
9099 DEBUG_PRINT_ERROR("frame packing size mismatch");
9100 return;
9101 }
9102 extra->nSize = OMX_FRAMEPACK_EXTRADATA_SIZE;
9103 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9104 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9105 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement;
9106 extra->nDataSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT);
9107 framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data;
9108 framepack->nSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT);
9109 framepack->nVersion.nVersion = OMX_SPEC_VERSION;
9110 framepack->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9111 memcpy(&framepack->id, s3d_frame_packing_payload,
9112 sizeof(struct msm_vidc_s3d_frame_packing_payload));
9113 memcpy(&m_frame_pack_arrangement, framepack,
9114 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
9115 print_debug_extradata(extra);
9116}
9117
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08009118void omx_vdec::append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9119 struct msm_vidc_frame_qp_payload *qp_payload)
9120{
9121 OMX_QCOM_EXTRADATA_QP * qp = NULL;
9122 if (!qp_payload) {
9123 DEBUG_PRINT_ERROR("QP payload is NULL");
9124 return;
9125 }
9126 extra->nSize = OMX_QP_EXTRADATA_SIZE;
9127 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9128 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9129 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataQP;
9130 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_QP);
9131 qp = (OMX_QCOM_EXTRADATA_QP *)extra->data;
9132 qp->nQP = qp_payload->frame_qp;
9133 print_debug_extradata(extra);
9134}
9135
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08009136void omx_vdec::append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9137 struct msm_vidc_frame_bits_info_payload *bits_payload)
9138{
9139 OMX_QCOM_EXTRADATA_BITS_INFO * bits = NULL;
9140 if (!bits_payload) {
9141 DEBUG_PRINT_ERROR("bits info payload is NULL");
9142 return;
9143 }
9144 extra->nSize = OMX_BITSINFO_EXTRADATA_SIZE;
9145 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9146 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9147 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo;
9148 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_BITS_INFO);
9149 bits = (OMX_QCOM_EXTRADATA_BITS_INFO*)extra->data;
9150 bits->frame_bits = bits_payload->frame_bits;
9151 bits->header_bits = bits_payload->header_bits;
9152 print_debug_extradata(extra);
9153}
9154
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009155void omx_vdec::append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9156 OMX_OTHER_EXTRADATATYPE *p_user)
9157{
9158 int userdata_size = 0;
9159 struct msm_vidc_stream_userdata_payload *userdata_payload = NULL;
9160 userdata_payload =
9161 (struct msm_vidc_stream_userdata_payload *)p_user->data;
9162 userdata_size = p_user->nDataSize;
Deva Ramasubramanian2ebfed32014-04-24 13:34:24 -07009163 extra->nSize = OMX_USERDATA_EXTRADATA_SIZE + p_user->nSize;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009164 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9165 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9166 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData;
9167 extra->nDataSize = userdata_size;
9168 if (extra->data && p_user->data && extra->nDataSize)
9169 memcpy(extra->data, p_user->data, extra->nDataSize);
9170 print_debug_extradata(extra);
9171}
9172
Shalaj Jain273b3e02012-06-22 19:08:03 -07009173void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra)
9174{
Arun Menon906de572013-06-18 17:01:40 -07009175 if (!client_extradata) {
9176 return;
9177 }
9178 extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE);
9179 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9180 extra->eType = OMX_ExtraDataNone;
9181 extra->nDataSize = 0;
9182 extra->data[0] = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009183
Arun Menon906de572013-06-18 17:01:40 -07009184 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009185}
9186
9187OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index)
9188{
Arun Menon906de572013-06-18 17:01:40 -07009189 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9190 if (index >= drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009191 DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07009192 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009193 }
Arun Menon906de572013-06-18 17:01:40 -07009194 if (m_desc_buffer_ptr == NULL) {
9195 m_desc_buffer_ptr = (desc_buffer_hdr*) \
9196 calloc( (sizeof(desc_buffer_hdr)),
9197 drv_ctx.ip_buf.actualcount);
9198 if (m_desc_buffer_ptr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009199 DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07009200 return OMX_ErrorInsufficientResources;
9201 }
9202 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009203
Arun Menon906de572013-06-18 17:01:40 -07009204 m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8));
9205 if (m_desc_buffer_ptr[index].buf_addr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009206 DEBUG_PRINT_ERROR("desc buffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07009207 return OMX_ErrorInsufficientResources;
9208 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009209
Arun Menon906de572013-06-18 17:01:40 -07009210 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009211}
9212
9213void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset)
9214{
Arun Menon906de572013-06-18 17:01:40 -07009215 DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries);
9216 if (m_demux_entries < 8192) {
9217 m_demux_offsets[m_demux_entries++] = address_offset;
9218 }
9219 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009220}
9221
9222void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr)
9223{
Arun Menon906de572013-06-18 17:01:40 -07009224 OMX_U32 bytes_to_parse = buf_hdr->nFilledLen;
9225 OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset;
9226 OMX_U32 index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009227
Arun Menon906de572013-06-18 17:01:40 -07009228 m_demux_entries = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009229
Arun Menon906de572013-06-18 17:01:40 -07009230 while (index < bytes_to_parse) {
9231 if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
9232 (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) ||
9233 ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
9234 (buf[index+2] == 0x01)) ) {
9235 //Found start code, insert address offset
9236 insert_demux_addr_offset(index);
9237 if (buf[index+2] == 0x01) // 3 byte start code
9238 index += 3;
9239 else //4 byte start code
9240 index += 4;
9241 } else
9242 index++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009243 }
Arun Menon906de572013-06-18 17:01:40 -07009244 DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries);
9245 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009246}
9247
9248OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr)
9249{
Arun Menon906de572013-06-18 17:01:40 -07009250 //fix this, handle 3 byte start code, vc1 terminator entry
9251 OMX_U8 *p_demux_data = NULL;
9252 OMX_U32 desc_data = 0;
9253 OMX_U32 start_addr = 0;
9254 OMX_U32 nal_size = 0;
9255 OMX_U32 suffix_byte = 0;
9256 OMX_U32 demux_index = 0;
9257 OMX_U32 buffer_index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009258
Arun Menon906de572013-06-18 17:01:40 -07009259 if (m_desc_buffer_ptr == NULL) {
9260 DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries.");
9261 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009262 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009263
Arun Menon906de572013-06-18 17:01:40 -07009264 buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
9265 if (buffer_index > drv_ctx.ip_buf.actualcount) {
9266 DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index);
9267 return OMX_ErrorBadParameter;
9268 }
9269
9270 p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr;
9271
9272 if ( ((OMX_U8*)p_demux_data == NULL) ||
9273 ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) {
9274 DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries.");
9275 return OMX_ErrorBadParameter;
9276 } else {
9277 for (; demux_index < m_demux_entries; demux_index++) {
9278 desc_data = 0;
9279 start_addr = m_demux_offsets[demux_index];
9280 if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) {
9281 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3];
9282 } else {
9283 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4];
9284 }
9285 if (demux_index < (m_demux_entries - 1)) {
9286 nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2;
9287 } else {
9288 nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2;
9289 }
9290 DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)",
9291 (void *)start_addr,
9292 suffix_byte,
9293 nal_size,
9294 demux_index);
9295 desc_data = (start_addr >> 3) << 1;
9296 desc_data |= (start_addr & 7) << 21;
9297 desc_data |= suffix_byte << 24;
9298
9299 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
9300 memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32));
9301 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
9302 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
9303
9304 p_demux_data += 16;
9305 }
9306 if (codec_type_parse == CODEC_TYPE_VC1) {
9307 DEBUG_PRINT_LOW("VC1 terminator entry");
9308 desc_data = 0;
9309 desc_data = 0x82 << 24;
9310 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
9311 memset(p_demux_data + 4, 0, sizeof(OMX_U32));
9312 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
9313 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
9314 p_demux_data += 16;
9315 m_demux_entries++;
9316 }
9317 //Add zero word to indicate end of descriptors
9318 memset(p_demux_data, 0, sizeof(OMX_U32));
9319
9320 m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32);
9321 DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size);
9322 }
9323 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
9324 m_demux_entries = 0;
9325 DEBUG_PRINT_LOW("Demux table complete!");
9326 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009327}
9328
Deva Ramasubramanian9403f022012-11-28 18:27:53 -08009329OMX_ERRORTYPE omx_vdec::createDivxDrmContext()
Shalaj Jain273b3e02012-06-22 19:08:03 -07009330{
Arun Menon906de572013-06-18 17:01:40 -07009331 OMX_ERRORTYPE err = OMX_ErrorNone;
9332 iDivXDrmDecrypt = DivXDrmDecrypt::Create();
9333 if (iDivXDrmDecrypt) {
9334 OMX_ERRORTYPE err = iDivXDrmDecrypt->Init();
9335 if (err!=OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009336 DEBUG_PRINT_ERROR("ERROR :iDivXDrmDecrypt->Init %d", err);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009337 delete iDivXDrmDecrypt;
9338 iDivXDrmDecrypt = NULL;
Arun Menon906de572013-06-18 17:01:40 -07009339 }
9340 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009341 DEBUG_PRINT_ERROR("Unable to Create DIVX DRM");
Arun Menon906de572013-06-18 17:01:40 -07009342 err = OMX_ErrorUndefined;
9343 }
9344 return err;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009345}
Shalaj Jain273b3e02012-06-22 19:08:03 -07009346
Vinay Kaliada4f4422013-01-09 10:45:03 -08009347omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf()
9348{
Arun Menon906de572013-06-18 17:01:40 -07009349 enabled = false;
9350 omx = NULL;
9351 init_members();
9352 ColorFormat = OMX_COLOR_FormatMax;
Praveen Chavandb7776f2014-02-06 18:17:25 -08009353 dest_format = YCbCr420P;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009354}
9355
9356void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client)
9357{
Arun Menon906de572013-06-18 17:01:40 -07009358 omx = reinterpret_cast<omx_vdec*>(client);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009359}
9360
Arun Menon906de572013-06-18 17:01:40 -07009361void omx_vdec::allocate_color_convert_buf::init_members()
9362{
9363 allocated_count = 0;
9364 buffer_size_req = 0;
9365 buffer_alignment_req = 0;
9366 memset(m_platform_list_client,0,sizeof(m_platform_list_client));
9367 memset(m_platform_entry_client,0,sizeof(m_platform_entry_client));
9368 memset(m_pmem_info_client,0,sizeof(m_pmem_info_client));
9369 memset(m_out_mem_ptr_client,0,sizeof(m_out_mem_ptr_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08009370#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009371 memset(op_buf_ion_info,0,sizeof(m_platform_entry_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08009372#endif
Arun Menon906de572013-06-18 17:01:40 -07009373 for (int i = 0; i < MAX_COUNT; i++)
9374 pmem_fd[i] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009375}
9376
Arun Menon906de572013-06-18 17:01:40 -07009377omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf()
9378{
9379 c2d.destroy();
Vinay Kaliada4f4422013-01-09 10:45:03 -08009380}
9381
9382bool omx_vdec::allocate_color_convert_buf::update_buffer_req()
9383{
Arun Menon906de572013-06-18 17:01:40 -07009384 bool status = true;
9385 unsigned int src_size = 0, destination_size = 0;
9386 OMX_COLOR_FORMATTYPE drv_color_format;
9387 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009388 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07009389 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009390 }
Arun Menon906de572013-06-18 17:01:40 -07009391 if (!enabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009392 DEBUG_PRINT_HIGH("No color conversion required");
Arun Menon906de572013-06-18 17:01:40 -07009393 return status;
9394 }
9395 pthread_mutex_lock(&omx->c_lock);
9396 if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 &&
9397 ColorFormat != OMX_COLOR_FormatYUV420Planar) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009398 DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion");
Arun Menon906de572013-06-18 17:01:40 -07009399 status = false;
9400 goto fail_update_buf_req;
9401 }
9402 c2d.close();
9403 status = c2d.open(omx->drv_ctx.video_resolution.frame_height,
9404 omx->drv_ctx.video_resolution.frame_width,
Praveen Chavandb7776f2014-02-06 18:17:25 -08009405 NV12_128m,dest_format);
Arun Menon906de572013-06-18 17:01:40 -07009406 if (status) {
9407 status = c2d.get_buffer_size(C2D_INPUT,src_size);
9408 if (status)
9409 status = c2d.get_buffer_size(C2D_OUTPUT,destination_size);
9410 }
9411 if (status) {
9412 if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size ||
9413 !destination_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009414 DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d"
Arun Menon906de572013-06-18 17:01:40 -07009415 "driver size %d destination size %d",
9416 src_size,omx->drv_ctx.op_buf.buffer_size,destination_size);
9417 status = false;
9418 c2d.close();
9419 buffer_size_req = 0;
9420 } else {
9421 buffer_size_req = destination_size;
9422 if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size)
9423 buffer_size_req = omx->drv_ctx.op_buf.buffer_size;
9424 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
9425 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
9426 }
9427 }
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009428fail_update_buf_req:
Arun Menon906de572013-06-18 17:01:40 -07009429 pthread_mutex_unlock(&omx->c_lock);
9430 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009431}
9432
9433bool omx_vdec::allocate_color_convert_buf::set_color_format(
Arun Menon906de572013-06-18 17:01:40 -07009434 OMX_COLOR_FORMATTYPE dest_color_format)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009435{
Arun Menon906de572013-06-18 17:01:40 -07009436 bool status = true;
9437 OMX_COLOR_FORMATTYPE drv_color_format;
9438 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009439 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07009440 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009441 }
Arun Menon906de572013-06-18 17:01:40 -07009442 pthread_mutex_lock(&omx->c_lock);
9443 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
9444 drv_color_format = (OMX_COLOR_FORMATTYPE)
9445 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
9446 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009447 DEBUG_PRINT_ERROR("Incorrect color format");
Arun Menon906de572013-06-18 17:01:40 -07009448 status = false;
9449 }
9450 if (status && (drv_color_format != dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009451 DEBUG_PRINT_LOW("Enabling C2D");
Praveen Chavandb7776f2014-02-06 18:17:25 -08009452 if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) &&
9453 (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009454 DEBUG_PRINT_ERROR("Unsupported color format for c2d");
Arun Menon906de572013-06-18 17:01:40 -07009455 status = false;
9456 } else {
Praveen Chavandb7776f2014-02-06 18:17:25 -08009457 ColorFormat = dest_color_format;
9458 dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ?
9459 YCbCr420P : YCbCr420SP;
Arun Menon906de572013-06-18 17:01:40 -07009460 if (enabled)
9461 c2d.destroy();
9462 enabled = false;
9463 if (!c2d.init()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009464 DEBUG_PRINT_ERROR("open failed for c2d");
Arun Menon906de572013-06-18 17:01:40 -07009465 status = false;
9466 } else
9467 enabled = true;
9468 }
9469 } else {
9470 if (enabled)
9471 c2d.destroy();
9472 enabled = false;
9473 }
9474 pthread_mutex_unlock(&omx->c_lock);
9475 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009476}
9477
9478OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr()
9479{
Arun Menon906de572013-06-18 17:01:40 -07009480 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009481 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009482 return NULL;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009483 }
Arun Menon906de572013-06-18 17:01:40 -07009484 if (!enabled)
9485 return omx->m_out_mem_ptr;
9486 return m_out_mem_ptr_client;
9487}
9488
9489 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr
9490(OMX_BUFFERHEADERTYPE *bufadd)
9491{
9492 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009493 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009494 return NULL;
9495 }
9496 if (!enabled)
9497 return bufadd;
9498
9499 unsigned index = 0;
9500 index = bufadd - omx->m_out_mem_ptr;
9501 if (index < omx->drv_ctx.op_buf.actualcount) {
9502 m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS);
9503 m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp;
9504 bool status;
9505 if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) {
9506 pthread_mutex_lock(&omx->c_lock);
9507 status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd,
9508 omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index],
9509 pmem_baseaddress[index], pmem_baseaddress[index]);
Arun Menon906de572013-06-18 17:01:40 -07009510 if (!status) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009511 DEBUG_PRINT_ERROR("Failed color conversion %d", status);
Arun Menon906de572013-06-18 17:01:40 -07009512 m_out_mem_ptr_client[index].nFilledLen = 0;
Leena Winterrowd270a7042014-09-30 13:05:55 -07009513 pthread_mutex_unlock(&omx->c_lock);
Arun Menon906de572013-06-18 17:01:40 -07009514 return &m_out_mem_ptr_client[index];
Praveen Chavan6d6b7252014-09-15 17:05:54 -07009515 } else {
9516 unsigned int filledLen = 0;
9517 c2d.get_output_filled_length(filledLen);
9518 m_out_mem_ptr_client[index].nFilledLen = filledLen;
Arun Menon906de572013-06-18 17:01:40 -07009519 }
Leena Winterrowd270a7042014-09-30 13:05:55 -07009520 pthread_mutex_unlock(&omx->c_lock);
Arun Menon906de572013-06-18 17:01:40 -07009521 } else
9522 m_out_mem_ptr_client[index].nFilledLen = 0;
9523 return &m_out_mem_ptr_client[index];
9524 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009525 DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009526 return NULL;
9527}
9528
9529 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr
9530(OMX_BUFFERHEADERTYPE *bufadd)
9531{
9532 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009533 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009534 return NULL;
9535 }
9536 if (!enabled)
9537 return bufadd;
9538 unsigned index = 0;
9539 index = bufadd - m_out_mem_ptr_client;
9540 if (index < omx->drv_ctx.op_buf.actualcount) {
9541 return &omx->m_out_mem_ptr[index];
9542 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009543 DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009544 return NULL;
9545}
9546 bool omx_vdec::allocate_color_convert_buf::get_buffer_req
9547(unsigned int &buffer_size)
9548{
9549 bool status = true;
9550 pthread_mutex_lock(&omx->c_lock);
9551 if (!enabled)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009552 buffer_size = omx->drv_ctx.op_buf.buffer_size;
Arun Menon906de572013-06-18 17:01:40 -07009553 else {
9554 if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009555 DEBUG_PRINT_ERROR("Get buffer size failed");
Arun Menon906de572013-06-18 17:01:40 -07009556 status = false;
9557 goto fail_get_buffer_size;
9558 }
9559 }
9560 if (buffer_size < omx->drv_ctx.op_buf.buffer_size)
9561 buffer_size = omx->drv_ctx.op_buf.buffer_size;
9562 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
9563 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009564fail_get_buffer_size:
Arun Menon906de572013-06-18 17:01:40 -07009565 pthread_mutex_unlock(&omx->c_lock);
9566 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009567}
9568OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07009569 OMX_BUFFERHEADERTYPE *bufhdr)
9570{
9571 unsigned int index = 0;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009572
Arun Menon906de572013-06-18 17:01:40 -07009573 if (!enabled)
9574 return omx->free_output_buffer(bufhdr);
9575 if (enabled && omx->is_component_secure())
9576 return OMX_ErrorNone;
9577 if (!allocated_count || !bufhdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009578 DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr);
Arun Menon906de572013-06-18 17:01:40 -07009579 return OMX_ErrorBadParameter;
9580 }
9581 index = bufhdr - m_out_mem_ptr_client;
9582 if (index >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009583 DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer");
Arun Menon906de572013-06-18 17:01:40 -07009584 return OMX_ErrorBadParameter;
9585 }
9586 if (pmem_fd[index] > 0) {
9587 munmap(pmem_baseaddress[index], buffer_size_req);
9588 close(pmem_fd[index]);
9589 }
9590 pmem_fd[index] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009591#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009592 omx->free_ion_memory(&op_buf_ion_info[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009593#endif
Arun Menon906de572013-06-18 17:01:40 -07009594 m_heap_ptr[index].video_heap_ptr = NULL;
9595 if (allocated_count > 0)
9596 allocated_count--;
9597 else
9598 allocated_count = 0;
9599 if (!allocated_count) {
9600 pthread_mutex_lock(&omx->c_lock);
9601 c2d.close();
9602 init_members();
9603 pthread_mutex_unlock(&omx->c_lock);
9604 }
9605 return omx->free_output_buffer(&omx->m_out_mem_ptr[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009606}
9607
9608OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07009609 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009610{
Arun Menon906de572013-06-18 17:01:40 -07009611 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9612 if (!enabled) {
9613 eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes);
9614 return eRet;
9615 }
9616 if (enabled && omx->is_component_secure()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009617 DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d",
Arun Menon906de572013-06-18 17:01:40 -07009618 omx->is_component_secure());
9619 return OMX_ErrorUnsupportedSetting;
9620 }
9621 if (!bufferHdr || bytes > buffer_size_req) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009622 DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr);
9623 DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu",
Arun Menon906de572013-06-18 17:01:40 -07009624 buffer_size_req,bytes);
9625 return OMX_ErrorBadParameter;
9626 }
9627 if (allocated_count >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009628 DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009629 return OMX_ErrorInsufficientResources;
9630 }
9631 OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL;
9632 eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr,
9633 port,appData,omx->drv_ctx.op_buf.buffer_size);
9634 if (eRet != OMX_ErrorNone || !temp_bufferHdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009635 DEBUG_PRINT_ERROR("Buffer allocation failed color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009636 return eRet;
9637 }
9638 if ((temp_bufferHdr - omx->m_out_mem_ptr) >=
Surajit Podderd2644d52013-08-28 17:59:06 +05309639 (int)omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009640 DEBUG_PRINT_ERROR("Invalid header index %d",
Arun Menon906de572013-06-18 17:01:40 -07009641 (temp_bufferHdr - omx->m_out_mem_ptr));
9642 return OMX_ErrorUndefined;
9643 }
9644 unsigned int i = allocated_count;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009645#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009646 op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory(
9647 buffer_size_req,buffer_alignment_req,
9648 &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data,
9649 0);
9650 pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd;
9651 if (op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009652 DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009653 return OMX_ErrorInsufficientResources;
9654 }
9655 pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req,
9656 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009657
Arun Menon906de572013-06-18 17:01:40 -07009658 if (pmem_baseaddress[i] == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009659 DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req);
Arun Menon906de572013-06-18 17:01:40 -07009660 close(pmem_fd[i]);
9661 omx->free_ion_memory(&op_buf_ion_info[i]);
9662 return OMX_ErrorInsufficientResources;
9663 }
9664 m_heap_ptr[i].video_heap_ptr = new VideoHeap (
9665 op_buf_ion_info[i].ion_device_fd,buffer_size_req,
9666 pmem_baseaddress[i],op_buf_ion_info[i].ion_alloc_data.handle,pmem_fd[i]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009667#endif
Arun Menon906de572013-06-18 17:01:40 -07009668 m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get();
9669 m_pmem_info_client[i].offset = 0;
9670 m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i];
9671 m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
9672 m_platform_list_client[i].nEntries = 1;
9673 m_platform_list_client[i].entryList = &m_platform_entry_client[i];
9674 m_out_mem_ptr_client[i].pOutputPortPrivate = NULL;
9675 m_out_mem_ptr_client[i].nAllocLen = buffer_size_req;
9676 m_out_mem_ptr_client[i].nFilledLen = 0;
9677 m_out_mem_ptr_client[i].nFlags = 0;
9678 m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9679 m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE);
9680 m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION;
9681 m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i];
9682 m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i];
9683 m_out_mem_ptr_client[i].pAppPrivate = appData;
9684 *bufferHdr = &m_out_mem_ptr_client[i];
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009685 DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr);
Arun Menon906de572013-06-18 17:01:40 -07009686 allocated_count++;
9687 return eRet;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009688}
9689
9690bool omx_vdec::is_component_secure()
9691{
Arun Menon906de572013-06-18 17:01:40 -07009692 return secure_mode;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009693}
9694
9695bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format)
9696{
Arun Menon906de572013-06-18 17:01:40 -07009697 bool status = true;
9698 if (!enabled) {
9699 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
9700 dest_color_format = (OMX_COLOR_FORMATTYPE)
9701 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
9702 else
9703 status = false;
9704 } else {
Praveen Chavandb7776f2014-02-06 18:17:25 -08009705 if (ColorFormat == OMX_COLOR_FormatYUV420Planar ||
9706 ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
9707 dest_color_format = ColorFormat;
Arun Menon906de572013-06-18 17:01:40 -07009708 } else
Praveen Chavandb7776f2014-02-06 18:17:25 -08009709 status = false;
Arun Menon906de572013-06-18 17:01:40 -07009710 }
9711 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009712}
Arun Menonbdb80b02013-08-12 17:45:54 -07009713
Arun Menonbdb80b02013-08-12 17:45:54 -07009714void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset)
9715{
9716 int i = 0;
9717 bool buf_present = false;
9718 pthread_mutex_lock(&m_lock);
9719 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9720 //check the buffer fd, offset, uv addr with list contents
9721 //If present increment reference.
9722 if ((out_dynamic_list[i].fd == fd) &&
9723 (out_dynamic_list[i].offset == offset)) {
9724 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009725 DEBUG_PRINT_LOW("buf_ref_add: [ALREADY PRESENT] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009726 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9727 buf_present = true;
9728 break;
9729 }
9730 }
9731 if (!buf_present) {
9732 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9733 //search for a entry to insert details of the new buffer
9734 if (out_dynamic_list[i].dup_fd == 0) {
9735 out_dynamic_list[i].fd = fd;
9736 out_dynamic_list[i].offset = offset;
9737 out_dynamic_list[i].dup_fd = dup(fd);
9738 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009739 DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009740 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9741 break;
9742 }
9743 }
9744 }
9745 pthread_mutex_unlock(&m_lock);
9746}
9747
9748void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset)
9749{
9750 int i = 0;
9751 pthread_mutex_lock(&m_lock);
9752 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9753 //check the buffer fd, offset, uv addr with list contents
9754 //If present decrement reference.
9755 if ((out_dynamic_list[i].fd == fd) &&
9756 (out_dynamic_list[i].offset == offset)) {
9757 out_dynamic_list[i].ref_count--;
9758 if (out_dynamic_list[i].ref_count == 0) {
9759 close(out_dynamic_list[i].dup_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009760 DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009761 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9762 out_dynamic_list[i].dup_fd = 0;
9763 out_dynamic_list[i].fd = 0;
9764 out_dynamic_list[i].offset = 0;
9765 }
9766 break;
9767 }
9768 }
9769 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009770 DEBUG_PRINT_ERROR("Error - could not remove ref, no match with any entry in list");
Arun Menonbdb80b02013-08-12 17:45:54 -07009771 }
9772 pthread_mutex_unlock(&m_lock);
9773}
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07009774
Arun Menon1fc764f2014-04-17 15:41:27 -07009775OMX_ERRORTYPE omx_vdec::enable_adaptive_playback(unsigned long nMaxFrameWidth,
9776 unsigned long nMaxFrameHeight)
9777{
9778
9779 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9780 int ret = 0;
9781 unsigned long min_res_buf_count = 0;
9782
9783 eRet = enable_smoothstreaming();
9784 if (eRet != OMX_ErrorNone) {
9785 DEBUG_PRINT_ERROR("Failed to enable Adaptive Playback on driver");
9786 return eRet;
9787 }
9788
9789 DEBUG_PRINT_HIGH("Enabling Adaptive playback for %lu x %lu",
9790 nMaxFrameWidth,
9791 nMaxFrameHeight);
9792 m_smoothstreaming_mode = true;
9793 m_smoothstreaming_width = nMaxFrameWidth;
9794 m_smoothstreaming_height = nMaxFrameHeight;
9795
9796 //Get upper limit buffer count for min supported resolution
9797 struct v4l2_format fmt;
9798 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
9799 fmt.fmt.pix_mp.height = m_decoder_capability.min_height;
9800 fmt.fmt.pix_mp.width = m_decoder_capability.min_width;
9801 fmt.fmt.pix_mp.pixelformat = output_capability;
9802
9803 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
9804 if (ret) {
9805 DEBUG_PRINT_ERROR("Set Resolution failed for HxW = %ux%u",
9806 m_decoder_capability.min_height,
9807 m_decoder_capability.min_width);
9808 return OMX_ErrorUnsupportedSetting;
9809 }
9810
9811 eRet = get_buffer_req(&drv_ctx.op_buf);
9812 if (eRet != OMX_ErrorNone) {
9813 DEBUG_PRINT_ERROR("failed to get_buffer_req");
9814 return eRet;
9815 }
9816
9817 min_res_buf_count = drv_ctx.op_buf.mincount;
9818 DEBUG_PRINT_LOW("enable adaptive - upper limit buffer count = %lu for HxW %ux%u",
9819 min_res_buf_count, m_decoder_capability.min_height, m_decoder_capability.min_width);
9820
9821 update_resolution(m_smoothstreaming_width, m_smoothstreaming_height,
9822 m_smoothstreaming_width, m_smoothstreaming_height);
9823 eRet = is_video_session_supported();
9824 if (eRet != OMX_ErrorNone) {
9825 DEBUG_PRINT_ERROR("video session is not supported");
9826 return eRet;
9827 }
9828
9829 //Get upper limit buffer size for max smooth streaming resolution set
9830 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
9831 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
9832 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
9833 fmt.fmt.pix_mp.pixelformat = output_capability;
9834 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
9835 if (ret) {
9836 DEBUG_PRINT_ERROR("Set Resolution failed for adaptive playback");
9837 return OMX_ErrorUnsupportedSetting;
9838 }
9839
9840 eRet = get_buffer_req(&drv_ctx.op_buf);
9841 if (eRet != OMX_ErrorNone) {
9842 DEBUG_PRINT_ERROR("failed to get_buffer_req!!");
9843 return eRet;
9844 }
9845 DEBUG_PRINT_LOW("enable adaptive - upper limit buffer size = %u",
9846 drv_ctx.op_buf.buffer_size);
9847
9848 drv_ctx.op_buf.mincount = min_res_buf_count;
9849 drv_ctx.op_buf.actualcount = min_res_buf_count;
9850 eRet = set_buffer_req(&drv_ctx.op_buf);
9851 if (eRet != OMX_ErrorNone) {
9852 DEBUG_PRINT_ERROR("failed to set_buffer_req");
9853 return eRet;
9854 }
9855
9856 eRet = get_buffer_req(&drv_ctx.op_buf);
9857 if (eRet != OMX_ErrorNone) {
9858 DEBUG_PRINT_ERROR("failed to get_buffer_req!!!");
9859 return eRet;
9860 }
9861 DEBUG_PRINT_HIGH("adaptive playback enabled, buf count = %u bufsize = %u",
9862 drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size);
9863 return eRet;
9864}
9865
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07009866#ifdef _MSM8974_
9867void omx_vdec::send_codec_config() {
9868 if (codec_config_flag) {
9869 unsigned p1 = 0; // Parameter - 1
9870 unsigned p2 = 0; // Parameter - 2
9871 unsigned ident = 0;
9872 pthread_mutex_lock(&m_lock);
9873 DEBUG_PRINT_LOW("\n Check Queue for codec_config buffer \n");
9874 while (m_etb_q.m_size) {
9875 m_etb_q.pop_entry(&p1,&p2,&ident);
9876 if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
9877 if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
9878 if (empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\
9879 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
9880 DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy_arbitrary failure");
9881 omx_report_error();
9882 }
9883 } else {
9884 DEBUG_PRINT_LOW("\n Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2);
9885 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
9886 }
9887 } else if (ident == OMX_COMPONENT_GENERATE_ETB) {
9888 if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
9889 if (empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\
9890 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
9891 DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy failure");
9892 omx_report_error ();
9893 }
9894 } else {
9895 pending_input_buffers++;
9896 DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d",
9897 (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers);
9898 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
9899 }
9900 } else if (ident == OMX_COMPONENT_GENERATE_EBD) {
9901 DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_EBD %p",
9902 (OMX_BUFFERHEADERTYPE *)p1);
9903 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
9904 }
9905 }
9906 pthread_mutex_unlock(&m_lock);
9907 }
9908}
9909#endif