blob: 01e1f155b267ffce4d51259c973b656a36e7b0f6 [file] [log] [blame]
Shalaj Jain273b3e02012-06-22 19:08:03 -07001/*--------------------------------------------------------------------------
Vinay Kaliae4a7d9d2013-01-21 10:16:33 -08002Copyright (c) 2010 - 2013, 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;
86char ouputextradatafilename [] = "/data/extradata";
87#endif
88
89#define DEFAULT_FPS 30
90#define MAX_INPUT_ERROR DEFAULT_FPS
91#define MAX_SUPPORTED_FPS 120
92
93#define VC1_SP_MP_START_CODE 0xC5000000
94#define VC1_SP_MP_START_CODE_MASK 0xFF000000
95#define VC1_AP_SEQ_START_CODE 0x0F010000
96#define VC1_STRUCT_C_PROFILE_MASK 0xF0
97#define VC1_STRUCT_B_LEVEL_MASK 0xE0000000
98#define VC1_SIMPLE_PROFILE 0
99#define VC1_MAIN_PROFILE 1
100#define VC1_ADVANCE_PROFILE 3
101#define VC1_SIMPLE_PROFILE_LOW_LEVEL 0
102#define VC1_SIMPLE_PROFILE_MED_LEVEL 2
103#define VC1_STRUCT_C_LEN 4
104#define VC1_STRUCT_C_POS 8
105#define VC1_STRUCT_A_POS 12
106#define VC1_STRUCT_B_POS 24
107#define VC1_SEQ_LAYER_SIZE 36
Vinay Kaliab09886c2012-08-20 11:27:25 -0700108#define POLL_TIMEOUT 0x7fffffff
Shalaj Jain273b3e02012-06-22 19:08:03 -0700109
110#define MEM_DEVICE "/dev/ion"
111#define MEM_HEAP_ID ION_CP_MM_HEAP_ID
112
113#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700114extern "C" {
115#include<utils/Log.h>
116}
Shalaj Jain273b3e02012-06-22 19:08:03 -0700117#endif//_ANDROID_
118
Vinay Kalia53fa6832012-10-11 17:55:30 -0700119#define SZ_4K 0x1000
120#define SZ_1M 0x100000
121
Shalaj Jain273b3e02012-06-22 19:08:03 -0700122#define Log2(number, power) { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) && power < 16) { temp >>=0x1; power++; } }
123#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 -0700124#define EXTRADATA_IDX(__num_planes) (__num_planes - 1)
125
Vinay Kaliadb90f8c2012-11-19 18:57:56 -0800126#define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA)
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700127
128int debug_level = PRIO_ERROR;
129
Shalaj Jain273b3e02012-06-22 19:08:03 -0700130void* async_message_thread (void *input)
131{
Arun Menon906de572013-06-18 17:01:40 -0700132 OMX_BUFFERHEADERTYPE *buffer;
133 struct v4l2_plane plane[VIDEO_MAX_PLANES];
134 struct pollfd pfd;
135 struct v4l2_buffer v4l2_buf;
136 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
137 struct v4l2_event dqevent;
138 omx_vdec *omx = reinterpret_cast<omx_vdec*>(input);
139 pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI;
140 pfd.fd = omx->drv_ctx.video_driver_fd;
141 int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700142 DEBUG_PRINT_HIGH("omx_vdec: Async thread start");
Arun Menon906de572013-06-18 17:01:40 -0700143 prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0);
144 while (1) {
145 rc = poll(&pfd, 1, POLL_TIMEOUT);
146 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700147 DEBUG_PRINT_ERROR("Poll timedout");
Arun Menon906de572013-06-18 17:01:40 -0700148 break;
149 } else if (rc < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700150 DEBUG_PRINT_ERROR("Error while polling: %d", rc);
Arun Menon906de572013-06-18 17:01:40 -0700151 break;
152 }
153 if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) {
154 struct vdec_msginfo vdec_msg;
155 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
156 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
157 v4l2_buf.length = omx->drv_ctx.num_planes;
158 v4l2_buf.m.planes = plane;
159 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
160 vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
161 vdec_msg.status_code=VDEC_S_SUCCESS;
162 vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf;
163 vdec_msg.msgdata.output_frame.len=plane[0].bytesused;
164 vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr;
165 vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) +
166 (uint64_t)v4l2_buf.timestamp.tv_usec;
167 if (vdec_msg.msgdata.output_frame.len) {
168 vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2];
169 vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3];
170 vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4];
171 vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5];
172 }
173 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700174 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700175 break;
176 }
177 }
178 }
179 if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) {
180 struct vdec_msginfo vdec_msg;
181 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
182 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
183 v4l2_buf.length = 1;
184 v4l2_buf.m.planes = plane;
185 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
186 vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE;
187 vdec_msg.status_code=VDEC_S_SUCCESS;
188 vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf;
189 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700190 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700191 break;
192 }
193 }
194 }
195 if (pfd.revents & POLLPRI) {
196 rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent);
197 if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) {
198 struct vdec_msginfo vdec_msg;
199 vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED;
200 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700201 DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient");
Arun Menon906de572013-06-18 17:01:40 -0700202 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700203 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700204 break;
205 }
206 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) {
207 struct vdec_msginfo vdec_msg;
208 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE;
209 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700210 DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700211 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700212 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700213 break;
214 }
215 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE;
216 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700217 DEBUG_PRINT_HIGH("VIDC Output 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 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700223 DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700224 break;
225 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) {
226 struct vdec_msginfo vdec_msg;
227 vdec_msg.msgcode=VDEC_MSG_EVT_HW_ERROR;
228 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700229 DEBUG_PRINT_HIGH("SYS Error Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700230 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700231 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700232 break;
233 }
Arun Menon45346052013-11-13 12:40:08 -0800234 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) {
Arun Menonbdb80b02013-08-12 17:45:54 -0700235 unsigned int *ptr = (unsigned int *)dqevent.u.data;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700236 DEBUG_PRINT_LOW("REFERENCE RELEASE EVENT RECVD fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700237 omx->buf_ref_remove(ptr[0], ptr[1]);
238 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) {
239 unsigned int *ptr = (unsigned int *)dqevent.u.data;
240 struct vdec_msginfo vdec_msg;
241
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700242 DEBUG_PRINT_LOW("Release unqueued buffer event recvd fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700243
244 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
245 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
246 v4l2_buf.length = omx->drv_ctx.num_planes;
247 v4l2_buf.m.planes = plane;
248 v4l2_buf.index = ptr[5];
249 v4l2_buf.flags = 0;
250
251 vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
252 vdec_msg.status_code = VDEC_S_SUCCESS;
253 vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf;
254 vdec_msg.msgdata.output_frame.len = 0;
255 vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2];
256 vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) +
257 (uint64_t)ptr[4];
258 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700259 DEBUG_PRINT_HIGH("async_message_thread Exitedn");
Arun Menonbdb80b02013-08-12 17:45:54 -0700260 break;
261 }
262 }
Arun Menonbdb80b02013-08-12 17:45:54 -0700263 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700264 DEBUG_PRINT_HIGH("VIDC Some Event recieved");
Arun Menon906de572013-06-18 17:01:40 -0700265 continue;
266 }
267 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -0700268 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700269 DEBUG_PRINT_HIGH("omx_vdec: Async thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700270 return NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700271}
272
273void* message_thread(void *input)
274{
Arun Menon906de572013-06-18 17:01:40 -0700275 omx_vdec* omx = reinterpret_cast<omx_vdec*>(input);
276 unsigned char id;
277 int n;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700278
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700279 DEBUG_PRINT_HIGH("omx_vdec: message thread start");
Arun Menon906de572013-06-18 17:01:40 -0700280 prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0);
281 while (1) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700282
Arun Menon906de572013-06-18 17:01:40 -0700283 n = read(omx->m_pipe_in, &id, 1);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700284
Arun Menon906de572013-06-18 17:01:40 -0700285 if (0 == n) {
286 break;
287 }
288
289 if (1 == n) {
290 omx->process_event_cb(omx, id);
291 }
292 if ((n < 0) && (errno != EINTR)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700293 DEBUG_PRINT_LOW("ERROR: read from pipe failed, ret %d errno %d", n, errno);
Arun Menon906de572013-06-18 17:01:40 -0700294 break;
295 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700296 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700297 DEBUG_PRINT_HIGH("omx_vdec: message thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700298 return 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700299}
300
301void post_message(omx_vdec *omx, unsigned char id)
302{
Arun Menon906de572013-06-18 17:01:40 -0700303 int ret_value;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700304 DEBUG_PRINT_LOW("omx_vdec: post_message %d pipe out%d", id,omx->m_pipe_out);
Arun Menon906de572013-06-18 17:01:40 -0700305 ret_value = write(omx->m_pipe_out, &id, 1);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700306 DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700307}
308
309// omx_cmd_queue destructor
310omx_vdec::omx_cmd_queue::~omx_cmd_queue()
311{
Arun Menon906de572013-06-18 17:01:40 -0700312 // Nothing to do
Shalaj Jain273b3e02012-06-22 19:08:03 -0700313}
314
315// omx cmd queue constructor
316omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0)
317{
318 memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE);
319}
320
321// omx cmd queue insert
322bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id)
323{
Arun Menon906de572013-06-18 17:01:40 -0700324 bool ret = true;
325 if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) {
326 m_q[m_write].id = id;
327 m_q[m_write].param1 = p1;
328 m_q[m_write].param2 = p2;
329 m_write++;
330 m_size ++;
331 if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) {
332 m_write = 0;
333 }
334 } else {
335 ret = false;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700336 DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700337 }
Arun Menon906de572013-06-18 17:01:40 -0700338 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700339}
340
341// omx cmd queue pop
342bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id)
343{
Arun Menon906de572013-06-18 17:01:40 -0700344 bool ret = true;
345 if (m_size > 0) {
346 *id = m_q[m_read].id;
347 *p1 = m_q[m_read].param1;
348 *p2 = m_q[m_read].param2;
349 // Move the read pointer ahead
350 ++m_read;
351 --m_size;
352 if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) {
353 m_read = 0;
354 }
355 } else {
356 ret = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700357 }
Arun Menon906de572013-06-18 17:01:40 -0700358 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700359}
360
361// Retrieve the first mesg type in the queue
362unsigned omx_vdec::omx_cmd_queue::get_q_msg_type()
363{
364 return m_q[m_read].id;
365}
366
367#ifdef _ANDROID_
368omx_vdec::ts_arr_list::ts_arr_list()
369{
Arun Menon906de572013-06-18 17:01:40 -0700370 //initialize timestamps array
371 memset(m_ts_arr_list, 0, ( sizeof(ts_entry) * MAX_NUM_INPUT_OUTPUT_BUFFERS) );
Shalaj Jain273b3e02012-06-22 19:08:03 -0700372}
373omx_vdec::ts_arr_list::~ts_arr_list()
374{
Arun Menon906de572013-06-18 17:01:40 -0700375 //free m_ts_arr_list?
Shalaj Jain273b3e02012-06-22 19:08:03 -0700376}
377
378bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts)
379{
Arun Menon906de572013-06-18 17:01:40 -0700380 bool ret = true;
381 bool duplicate_ts = false;
382 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700383
Arun Menon906de572013-06-18 17:01:40 -0700384 //insert at the first available empty location
385 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
386 if (!m_ts_arr_list[idx].valid) {
387 //found invalid or empty entry, save timestamp
388 m_ts_arr_list[idx].valid = true;
389 m_ts_arr_list[idx].timestamp = ts;
390 DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)",
391 ts, idx);
392 break;
393 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700394 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700395
Arun Menon906de572013-06-18 17:01:40 -0700396 if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) {
397 DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert");
398 ret = false;
399 }
400 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700401}
402
403bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts)
404{
Arun Menon906de572013-06-18 17:01:40 -0700405 bool ret = true;
406 int min_idx = -1;
407 OMX_TICKS min_ts = 0;
408 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700409
Arun Menon906de572013-06-18 17:01:40 -0700410 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700411
Arun Menon906de572013-06-18 17:01:40 -0700412 if (m_ts_arr_list[idx].valid) {
413 //found valid entry, save index
414 if (min_idx < 0) {
415 //first valid entry
416 min_ts = m_ts_arr_list[idx].timestamp;
417 min_idx = idx;
418 } else if (m_ts_arr_list[idx].timestamp < min_ts) {
419 min_ts = m_ts_arr_list[idx].timestamp;
420 min_idx = idx;
421 }
422 }
423
Shalaj Jain273b3e02012-06-22 19:08:03 -0700424 }
425
Arun Menon906de572013-06-18 17:01:40 -0700426 if (min_idx < 0) {
427 //no valid entries found
428 DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop");
429 ts = 0;
430 ret = false;
431 } else {
432 ts = m_ts_arr_list[min_idx].timestamp;
433 m_ts_arr_list[min_idx].valid = false;
434 DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)",
435 ts, min_idx);
436 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700437
Arun Menon906de572013-06-18 17:01:40 -0700438 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700439
440}
441
442
443bool omx_vdec::ts_arr_list::reset_ts_list()
444{
Arun Menon906de572013-06-18 17:01:40 -0700445 bool ret = true;
446 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700447
Arun Menon906de572013-06-18 17:01:40 -0700448 DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list");
449 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
450 m_ts_arr_list[idx].valid = false;
451 }
452 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700453}
454#endif
455
456// factory function executed by the core to create instances
457void *get_omx_component_factory_fn(void)
458{
Arun Menon906de572013-06-18 17:01:40 -0700459 return (new omx_vdec);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700460}
461
462#ifdef _ANDROID_
463#ifdef USE_ION
464VideoHeap::VideoHeap(int devicefd, size_t size, void* base,
Arun Menon906de572013-06-18 17:01:40 -0700465 struct ion_handle *handle, int ionMapfd)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700466{
Arun Menon906de572013-06-18 17:01:40 -0700467 // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700468}
469#else
470VideoHeap::VideoHeap(int fd, size_t size, void* base)
471{
472 // dup file descriptor, map once, use pmem
473 init(dup(fd), base, size, 0 , MEM_DEVICE);
474}
475#endif
476#endif // _ANDROID_
477/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700478 FUNCTION
479 omx_vdec::omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700480
Arun Menon906de572013-06-18 17:01:40 -0700481 DESCRIPTION
482 Constructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700483
Arun Menon906de572013-06-18 17:01:40 -0700484 PARAMETERS
485 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700486
Arun Menon906de572013-06-18 17:01:40 -0700487 RETURN VALUE
488 None.
489 ========================================================================== */
Deva Ramasubramanian5c241242013-02-19 17:25:30 -0800490omx_vdec::omx_vdec(): m_error_propogated(false),
Arun Menon906de572013-06-18 17:01:40 -0700491 m_state(OMX_StateInvalid),
492 m_app_data(NULL),
493 m_inp_mem_ptr(NULL),
494 m_out_mem_ptr(NULL),
495 m_inp_err_count(0),
496 input_flush_progress (false),
497 output_flush_progress (false),
498 input_use_buffer (false),
499 output_use_buffer (false),
500 ouput_egl_buffers(false),
501 m_use_output_pmem(OMX_FALSE),
502 m_out_mem_region_smi(OMX_FALSE),
503 m_out_pvt_entry_pmem(OMX_FALSE),
504 pending_input_buffers(0),
505 pending_output_buffers(0),
506 m_out_bm_count(0),
507 m_inp_bm_count(0),
508 m_inp_bPopulated(OMX_FALSE),
509 m_out_bPopulated(OMX_FALSE),
510 m_flags(0),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700511#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700512 m_heap_ptr(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700513#endif
Arun Menon906de572013-06-18 17:01:40 -0700514 m_inp_bEnabled(OMX_TRUE),
515 m_out_bEnabled(OMX_TRUE),
516 m_in_alloc_cnt(0),
517 m_platform_list(NULL),
518 m_platform_entry(NULL),
519 m_pmem_info(NULL),
520 arbitrary_bytes (true),
521 psource_frame (NULL),
522 pdest_frame (NULL),
523 m_inp_heap_ptr (NULL),
524 m_phdr_pmem_ptr(NULL),
525 m_heap_inp_bm_count (0),
526 codec_type_parse ((codec_type)0),
527 first_frame_meta (true),
528 frame_count (0),
529 nal_count (0),
530 nal_length(0),
531 look_ahead_nal (false),
532 first_frame(0),
533 first_buffer(NULL),
534 first_frame_size (0),
535 m_device_file_ptr(NULL),
536 m_vc1_profile((vc1_profile_type)0),
Arun Menon906de572013-06-18 17:01:40 -0700537 h264_last_au_ts(LLONG_MAX),
538 h264_last_au_flags(0),
Surajit Podderd2644d52013-08-28 17:59:06 +0530539 m_disp_hor_size(0),
540 m_disp_vert_size(0),
Arun Menon906de572013-06-18 17:01:40 -0700541 prev_ts(LLONG_MAX),
542 rst_prev_ts(true),
543 frm_int(0),
Arun Menon906de572013-06-18 17:01:40 -0700544 in_reconfig(false),
545 m_display_id(NULL),
546 h264_parser(NULL),
547 client_extradata(0),
548 m_reject_avc_1080p_mp (0),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700549#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700550 m_enable_android_native_buffers(OMX_FALSE),
551 m_use_android_native_buffers(OMX_FALSE),
552 iDivXDrmDecrypt(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700553#endif
Arun Menon906de572013-06-18 17:01:40 -0700554 m_desc_buffer_ptr(NULL),
555 secure_mode(false),
Surajit Podderd2644d52013-08-28 17:59:06 +0530556 m_profile(0),
Arun Menon906de572013-06-18 17:01:40 -0700557 client_set_fps(false)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700558{
Arun Menon906de572013-06-18 17:01:40 -0700559 /* Assumption is that , to begin with , we have all the frames with decoder */
560 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700561 memset(&m_debug,0,sizeof(m_debug));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700562#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700563 char property_value[PROPERTY_VALUE_MAX] = {0};
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700564 property_get("vidc.debug.level", property_value, "0");
565 debug_level = atoi(property_value);
566 property_value[0] = '\0';
567
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700568 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
569
Arun Menon906de572013-06-18 17:01:40 -0700570 property_get("vidc.dec.debug.perf", property_value, "0");
571 perf_flag = atoi(property_value);
572 if (perf_flag) {
573 DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag);
574 dec_time.start();
575 proc_frms = latency = 0;
576 }
577 prev_n_filled_len = 0;
578 property_value[0] = '\0';
579 property_get("vidc.dec.debug.ts", property_value, "0");
580 m_debug_timestamp = atoi(property_value);
581 DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp);
582 if (m_debug_timestamp) {
583 time_stamp_dts.set_timestamp_reorder_mode(true);
584 time_stamp_dts.enable_debug_print(true);
585 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700586
Arun Menon906de572013-06-18 17:01:40 -0700587 property_value[0] = '\0';
588 property_get("vidc.dec.debug.concealedmb", property_value, "0");
589 m_debug_concealedmb = atoi(property_value);
590 DEBUG_PRINT_HIGH("vidc.dec.debug.concealedmb value is %d",m_debug_concealedmb);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700591
Arun Menon906de572013-06-18 17:01:40 -0700592 property_value[0] = '\0';
593 property_get("vidc.dec.profile.check", property_value, "0");
594 m_reject_avc_1080p_mp = atoi(property_value);
595 DEBUG_PRINT_HIGH("vidc.dec.profile.check value is %d",m_reject_avc_1080p_mp);
Rajeshwar Kurapatye0e7d0c2013-07-30 19:46:26 +0530596
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700597 property_value[0] = '\0';
598 property_get("vidc.dec.log.in", property_value, "0");
599 m_debug.in_buffer_log = atoi(property_value);
600
601 property_value[0] = '\0';
602 property_get("vidc.dec.log.out", property_value, "0");
603 m_debug.out_buffer_log = atoi(property_value);
604 sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC);
605
606 property_value[0] = '\0';
607 property_get("vidc.log.loc", property_value, "");
608 if (*property_value)
609 strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700610#endif
Arun Menon906de572013-06-18 17:01:40 -0700611 memset(&m_cmp,0,sizeof(m_cmp));
612 memset(&m_cb,0,sizeof(m_cb));
613 memset (&drv_ctx,0,sizeof(drv_ctx));
614 memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE));
615 memset (m_hwdevice_name,0,sizeof(m_hwdevice_name));
616 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
617 m_demux_entries = 0;
618 msg_thread_id = 0;
619 async_thread_id = 0;
620 msg_thread_created = false;
621 async_thread_created = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700622#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -0700623 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700624#endif
Arun Menon906de572013-06-18 17:01:40 -0700625 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
626 drv_ctx.timestamp_adjust = false;
627 drv_ctx.video_driver_fd = -1;
628 m_vendor_config.pData = NULL;
629 pthread_mutex_init(&m_lock, NULL);
630 pthread_mutex_init(&c_lock, NULL);
631 sem_init(&m_cmd_lock,0,0);
632 streaming[CAPTURE_PORT] =
633 streaming[OUTPUT_PORT] = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700634#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700635 char extradata_value[PROPERTY_VALUE_MAX] = {0};
636 property_get("vidc.dec.debug.extradata", extradata_value, "0");
637 m_debug_extradata = atoi(extradata_value);
638 DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700639#endif
Arun Menon906de572013-06-18 17:01:40 -0700640 m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB;
641 client_buffers.set_vdec_client(this);
Arun Menonbdb80b02013-08-12 17:45:54 -0700642 dynamic_buf_mode = false;
643 out_dynamic_list = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700644}
645
Vinay Kalia85793762012-06-14 19:12:34 -0700646static const int event_type[] = {
Arun Menon906de572013-06-18 17:01:40 -0700647 V4L2_EVENT_MSM_VIDC_FLUSH_DONE,
648 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT,
649 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT,
Arun Menonbdb80b02013-08-12 17:45:54 -0700650 V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE,
651 V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER,
Arun Menon906de572013-06-18 17:01:40 -0700652 V4L2_EVENT_MSM_VIDC_CLOSE_DONE,
653 V4L2_EVENT_MSM_VIDC_SYS_ERROR
Vinay Kalia85793762012-06-14 19:12:34 -0700654};
655
656static OMX_ERRORTYPE subscribe_to_events(int fd)
657{
Arun Menon906de572013-06-18 17:01:40 -0700658 OMX_ERRORTYPE eRet = OMX_ErrorNone;
659 struct v4l2_event_subscription sub;
660 int array_sz = sizeof(event_type)/sizeof(int);
661 int i,rc;
662 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700663 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700664 return OMX_ErrorBadParameter;
665 }
Vinay Kalia85793762012-06-14 19:12:34 -0700666
Arun Menon906de572013-06-18 17:01:40 -0700667 for (i = 0; i < array_sz; ++i) {
668 memset(&sub, 0, sizeof(sub));
669 sub.type = event_type[i];
670 rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
671 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700672 DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700673 break;
674 }
675 }
676 if (i < array_sz) {
677 for (--i; i >=0 ; i--) {
678 memset(&sub, 0, sizeof(sub));
679 sub.type = event_type[i];
680 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
681 if (rc)
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700682 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700683 }
684 eRet = OMX_ErrorNotImplemented;
685 }
686 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700687}
688
689
690static OMX_ERRORTYPE unsubscribe_to_events(int fd)
691{
Arun Menon906de572013-06-18 17:01:40 -0700692 OMX_ERRORTYPE eRet = OMX_ErrorNone;
693 struct v4l2_event_subscription sub;
694 int array_sz = sizeof(event_type)/sizeof(int);
695 int i,rc;
696 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700697 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700698 return OMX_ErrorBadParameter;
699 }
Vinay Kalia85793762012-06-14 19:12:34 -0700700
Arun Menon906de572013-06-18 17:01:40 -0700701 for (i = 0; i < array_sz; ++i) {
702 memset(&sub, 0, sizeof(sub));
703 sub.type = event_type[i];
704 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
705 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700706 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700707 break;
708 }
709 }
710 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700711}
Shalaj Jain273b3e02012-06-22 19:08:03 -0700712
713/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700714 FUNCTION
715 omx_vdec::~omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700716
Arun Menon906de572013-06-18 17:01:40 -0700717 DESCRIPTION
718 Destructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700719
Arun Menon906de572013-06-18 17:01:40 -0700720 PARAMETERS
721 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700722
Arun Menon906de572013-06-18 17:01:40 -0700723 RETURN VALUE
724 None.
725 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700726omx_vdec::~omx_vdec()
727{
Arun Menon906de572013-06-18 17:01:40 -0700728 m_pmem_info = NULL;
729 struct v4l2_decoder_cmd dec;
730 DEBUG_PRINT_HIGH("In OMX vdec Destructor");
731 if (m_pipe_in) close(m_pipe_in);
732 if (m_pipe_out) close(m_pipe_out);
733 m_pipe_in = -1;
734 m_pipe_out = -1;
735 DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit");
736 if (msg_thread_created)
737 pthread_join(msg_thread_id,NULL);
738 DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit");
739 dec.cmd = V4L2_DEC_CMD_STOP;
740 if (drv_ctx.video_driver_fd >=0 ) {
741 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700742 DEBUG_PRINT_ERROR("STOP Command failed");
Arun Menon906de572013-06-18 17:01:40 -0700743 }
744 if (async_thread_created)
745 pthread_join(async_thread_id,NULL);
746 unsubscribe_to_events(drv_ctx.video_driver_fd);
747 close(drv_ctx.video_driver_fd);
748 pthread_mutex_destroy(&m_lock);
749 pthread_mutex_destroy(&c_lock);
750 sem_destroy(&m_cmd_lock);
751 if (perf_flag) {
752 DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME");
753 dec_time.end();
754 }
755 DEBUG_PRINT_HIGH("Exit OMX vdec Destructor");
Shalaj Jain273b3e02012-06-22 19:08:03 -0700756}
757
Arun Menon906de572013-06-18 17:01:40 -0700758int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type)
759{
760 struct v4l2_requestbuffers bufreq;
761 int rc = 0;
762 if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
763 bufreq.memory = V4L2_MEMORY_USERPTR;
764 bufreq.count = 0;
765 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
766 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Surajit Podder12aefac2013-08-06 18:43:32 +0530767 } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) {
768 bufreq.memory = V4L2_MEMORY_USERPTR;
769 bufreq.count = 0;
770 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
771 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Arun Menon906de572013-06-18 17:01:40 -0700772 }
773 return rc;
Vinay Kaliafeef7032012-09-25 19:23:33 -0700774}
775
Shalaj Jain273b3e02012-06-22 19:08:03 -0700776/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700777 FUNCTION
778 omx_vdec::OMXCntrlProcessMsgCb
Shalaj Jain273b3e02012-06-22 19:08:03 -0700779
Arun Menon906de572013-06-18 17:01:40 -0700780 DESCRIPTION
781 IL Client callbacks are generated through this routine. The decoder
782 provides the thread context for this routine.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700783
Arun Menon906de572013-06-18 17:01:40 -0700784 PARAMETERS
785 ctxt -- Context information related to the self.
786 id -- Event identifier. This could be any of the following:
787 1. Command completion event
788 2. Buffer done callback event
789 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -0700790
Arun Menon906de572013-06-18 17:01:40 -0700791 RETURN VALUE
792 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700793
Arun Menon906de572013-06-18 17:01:40 -0700794 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700795void omx_vdec::process_event_cb(void *ctxt, unsigned char id)
796{
Arun Menon906de572013-06-18 17:01:40 -0700797 signed p1; // Parameter - 1
798 signed p2; // Parameter - 2
799 unsigned ident;
800 unsigned qsize=0; // qsize
801 omx_vdec *pThis = (omx_vdec *) ctxt;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700802
Arun Menon906de572013-06-18 17:01:40 -0700803 if (!pThis) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700804 DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out",
Arun Menon906de572013-06-18 17:01:40 -0700805 __func__);
806 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700807 }
808
Arun Menon906de572013-06-18 17:01:40 -0700809 // Protect the shared queue data structure
810 do {
811 /*Read the message id's from the queue*/
812 pthread_mutex_lock(&pThis->m_lock);
813 qsize = pThis->m_cmd_q.m_size;
814 if (qsize) {
815 pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700816 }
Arun Menon906de572013-06-18 17:01:40 -0700817
818 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
819 qsize = pThis->m_ftb_q.m_size;
820 if (qsize) {
821 pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
822 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700823 }
Arun Menon906de572013-06-18 17:01:40 -0700824
825 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
826 qsize = pThis->m_etb_q.m_size;
827 if (qsize) {
828 pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
829 }
830 }
831 pthread_mutex_unlock(&pThis->m_lock);
832
833 /*process message if we have one*/
834 if (qsize > 0) {
835 id = ident;
836 switch (id) {
837 case OMX_COMPONENT_GENERATE_EVENT:
838 if (pThis->m_cb.EventHandler) {
839 switch (p1) {
840 case OMX_CommandStateSet:
841 pThis->m_state = (OMX_STATETYPE) p2;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700842 DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d",
Arun Menon906de572013-06-18 17:01:40 -0700843 pThis->m_state);
844 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
845 OMX_EventCmdComplete, p1, p2, NULL);
846 break;
847
848 case OMX_EventError:
849 if (p2 == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700850 DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid");
Arun Menon906de572013-06-18 17:01:40 -0700851 pThis->m_state = (OMX_STATETYPE) p2;
852 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
853 OMX_EventError, OMX_ErrorInvalidState, p2, NULL);
854 } else if (p2 == OMX_ErrorHardware) {
855 pThis->omx_report_error();
856 } else {
857 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
858 OMX_EventError, p2, (OMX_U32)NULL, NULL );
859 }
860 break;
861
862 case OMX_CommandPortDisable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700863 DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700864 if (BITMASK_PRESENT(&pThis->m_flags,
865 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
866 BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
867 break;
868 }
869 if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) {
870 OMX_ERRORTYPE eRet = OMX_ErrorNone;
871 pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
872 if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700873 DEBUG_PRINT_HIGH("Failed to release output buffers");
Arun Menon906de572013-06-18 17:01:40 -0700874 OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf);
875 pThis->in_reconfig = false;
876 if (eRet != OMX_ErrorNone) {
877 DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet);
878 pThis->omx_report_error();
879 break;
880 }
881 }
882 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
883 OMX_EventCmdComplete, p1, p2, NULL );
884 break;
885 case OMX_CommandPortEnable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700886 DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700887 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\
888 OMX_EventCmdComplete, p1, p2, NULL );
889 break;
890
891 default:
892 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
893 OMX_EventCmdComplete, p1, p2, NULL );
894 break;
895
896 }
897 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700898 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
Arun Menon906de572013-06-18 17:01:40 -0700899 }
900 break;
901 case OMX_COMPONENT_GENERATE_ETB_ARBITRARY:
902 if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\
903 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700904 DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure");
Arun Menon906de572013-06-18 17:01:40 -0700905 pThis->omx_report_error ();
906 }
907 break;
908 case OMX_COMPONENT_GENERATE_ETB:
909 if (pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\
910 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700911 DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure");
Arun Menon906de572013-06-18 17:01:40 -0700912 pThis->omx_report_error ();
913 }
914 break;
915
916 case OMX_COMPONENT_GENERATE_FTB:
917 if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\
918 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700919 DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure");
Arun Menon906de572013-06-18 17:01:40 -0700920 pThis->omx_report_error ();
921 }
922 break;
923
924 case OMX_COMPONENT_GENERATE_COMMAND:
925 pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\
926 (OMX_U32)p2,(OMX_PTR)NULL);
927 break;
928
929 case OMX_COMPONENT_GENERATE_EBD:
930
931 if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700932 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure");
Arun Menon906de572013-06-18 17:01:40 -0700933 pThis->omx_report_error ();
934 } else {
935 if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) {
936 pThis->m_inp_err_count++;
937 pThis->time_stamp_dts.remove_time_stamp(
938 ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp,
939 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
940 ?true:false);
941 } else {
942 pThis->m_inp_err_count = 0;
943 }
944 if ( pThis->empty_buffer_done(&pThis->m_cmp,
945 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700946 DEBUG_PRINT_ERROR("empty_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -0700947 pThis->omx_report_error ();
948 }
949 if (pThis->m_inp_err_count >= MAX_INPUT_ERROR) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700950 DEBUG_PRINT_ERROR("Input bitstream error for consecutive %d frames.", MAX_INPUT_ERROR);
Arun Menon906de572013-06-18 17:01:40 -0700951 pThis->omx_report_error ();
952 }
953 }
954 break;
955 case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: {
956 int64_t *timestamp = (int64_t *)p1;
957 if (p1) {
958 pThis->time_stamp_dts.remove_time_stamp(*timestamp,
959 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
960 ?true:false);
961 free(timestamp);
962 }
963 }
964 break;
965 case OMX_COMPONENT_GENERATE_FBD:
966 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700967 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure");
Arun Menon906de572013-06-18 17:01:40 -0700968 pThis->omx_report_error ();
969 } else if ( pThis->fill_buffer_done(&pThis->m_cmp,
970 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700971 DEBUG_PRINT_ERROR("fill_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -0700972 pThis->omx_report_error ();
973 }
974 break;
975
976 case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700977 DEBUG_PRINT_HIGH("Driver flush i/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -0700978 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700979 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -0700980 } else {
981 pThis->execute_input_flush();
982 if (pThis->m_cb.EventHandler) {
983 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700984 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure");
Arun Menon906de572013-06-18 17:01:40 -0700985 pThis->omx_report_error ();
986 } else {
987 /*Check if we need generate event for Flush done*/
988 if (BITMASK_PRESENT(&pThis->m_flags,
989 OMX_COMPONENT_INPUT_FLUSH_PENDING)) {
990 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700991 DEBUG_PRINT_LOW("Input Flush completed - Notify Client");
Arun Menon906de572013-06-18 17:01:40 -0700992 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
993 OMX_EventCmdComplete,OMX_CommandFlush,
994 OMX_CORE_INPUT_PORT_INDEX,NULL );
995 }
996 if (BITMASK_PRESENT(&pThis->m_flags,
997 OMX_COMPONENT_IDLE_PENDING)) {
998 if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700999 DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port");
Arun Menon906de572013-06-18 17:01:40 -07001000 pThis->omx_report_error ();
1001 } else {
1002 pThis->streaming[OUTPUT_PORT] = false;
1003 }
1004 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001005 DEBUG_PRINT_LOW("Input flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001006 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1007 OMX_COMPONENT_GENERATE_STOP_DONE);
1008 }
1009 }
1010 }
1011 } else {
1012 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1013 }
1014 }
1015 break;
1016
1017 case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001018 DEBUG_PRINT_HIGH("Driver flush o/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -07001019 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001020 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -07001021 } else {
1022 pThis->execute_output_flush();
1023 if (pThis->m_cb.EventHandler) {
1024 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001025 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed");
Arun Menon906de572013-06-18 17:01:40 -07001026 pThis->omx_report_error ();
1027 } else {
1028 /*Check if we need generate event for Flush done*/
1029 if (BITMASK_PRESENT(&pThis->m_flags,
1030 OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001031 DEBUG_PRINT_LOW("Notify Output Flush done");
Arun Menon906de572013-06-18 17:01:40 -07001032 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
1033 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1034 OMX_EventCmdComplete,OMX_CommandFlush,
1035 OMX_CORE_OUTPUT_PORT_INDEX,NULL );
1036 }
1037 if (BITMASK_PRESENT(&pThis->m_flags,
1038 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001039 DEBUG_PRINT_LOW("Internal flush complete");
Arun Menon906de572013-06-18 17:01:40 -07001040 BITMASK_CLEAR (&pThis->m_flags,
1041 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
1042 if (BITMASK_PRESENT(&pThis->m_flags,
1043 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) {
1044 pThis->post_event(OMX_CommandPortDisable,
1045 OMX_CORE_OUTPUT_PORT_INDEX,
1046 OMX_COMPONENT_GENERATE_EVENT);
1047 BITMASK_CLEAR (&pThis->m_flags,
1048 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
1049
1050 }
1051 }
1052
1053 if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) {
1054 if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001055 DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port");
Arun Menon906de572013-06-18 17:01:40 -07001056 pThis->omx_report_error ();
1057 break;
1058 }
1059 pThis->streaming[CAPTURE_PORT] = false;
1060 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001061 DEBUG_PRINT_LOW("Output flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001062 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1063 OMX_COMPONENT_GENERATE_STOP_DONE);
1064 }
1065 }
1066 }
1067 } else {
1068 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1069 }
1070 }
1071 break;
1072
1073 case OMX_COMPONENT_GENERATE_START_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001074 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001075
1076 if (pThis->m_cb.EventHandler) {
1077 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001078 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure");
Arun Menon906de572013-06-18 17:01:40 -07001079 pThis->omx_report_error ();
1080 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001081 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001082 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001083 DEBUG_PRINT_LOW("Move to executing");
Arun Menon906de572013-06-18 17:01:40 -07001084 // Send the callback now
1085 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1086 pThis->m_state = OMX_StateExecuting;
1087 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1088 OMX_EventCmdComplete,OMX_CommandStateSet,
1089 OMX_StateExecuting, NULL);
1090 } else if (BITMASK_PRESENT(&pThis->m_flags,
1091 OMX_COMPONENT_PAUSE_PENDING)) {
1092 if (/*ioctl (pThis->drv_ctx.video_driver_fd,
1093 VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001094 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed");
Arun Menon906de572013-06-18 17:01:40 -07001095 pThis->omx_report_error ();
1096 }
1097 }
1098 }
1099 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001100 DEBUG_PRINT_LOW("Event Handler callback is NULL");
Arun Menon906de572013-06-18 17:01:40 -07001101 }
1102 break;
1103
1104 case OMX_COMPONENT_GENERATE_PAUSE_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001105 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001106 if (pThis->m_cb.EventHandler) {
1107 if (p2 != VDEC_S_SUCCESS) {
1108 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed");
1109 pThis->omx_report_error ();
1110 } else {
1111 pThis->complete_pending_buffer_done_cbs();
1112 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001113 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity");
Arun Menon906de572013-06-18 17:01:40 -07001114 //Send the callback now
1115 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING);
1116 pThis->m_state = OMX_StatePause;
1117 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1118 OMX_EventCmdComplete,OMX_CommandStateSet,
1119 OMX_StatePause, NULL);
1120 }
1121 }
1122 } else {
1123 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1124 }
1125
1126 break;
1127
1128 case OMX_COMPONENT_GENERATE_RESUME_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001129 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001130 if (pThis->m_cb.EventHandler) {
1131 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001132 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed");
Arun Menon906de572013-06-18 17:01:40 -07001133 pThis->omx_report_error ();
1134 } else {
1135 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001136 DEBUG_PRINT_LOW("Moving the decoder to execute state");
Arun Menon906de572013-06-18 17:01:40 -07001137 // Send the callback now
1138 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1139 pThis->m_state = OMX_StateExecuting;
1140 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1141 OMX_EventCmdComplete,OMX_CommandStateSet,
1142 OMX_StateExecuting,NULL);
1143 }
1144 }
1145 } else {
1146 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1147 }
1148
1149 break;
1150
1151 case OMX_COMPONENT_GENERATE_STOP_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001152 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001153 if (pThis->m_cb.EventHandler) {
1154 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001155 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed");
Arun Menon906de572013-06-18 17:01:40 -07001156 pThis->omx_report_error ();
1157 } else {
1158 pThis->complete_pending_buffer_done_cbs();
1159 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001160 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001161 // Send the callback now
1162 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING);
1163 pThis->m_state = OMX_StateIdle;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001164 DEBUG_PRINT_LOW("Move to Idle State");
Arun Menon906de572013-06-18 17:01:40 -07001165 pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data,
1166 OMX_EventCmdComplete,OMX_CommandStateSet,
1167 OMX_StateIdle,NULL);
1168 }
1169 }
1170 } else {
1171 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1172 }
1173
1174 break;
1175
1176 case OMX_COMPONENT_GENERATE_PORT_RECONFIG:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001177 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PORT_RECONFIG");
Arun Menon906de572013-06-18 17:01:40 -07001178
1179 if (p2 == OMX_IndexParamPortDefinition) {
1180 pThis->in_reconfig = true;
1181 }
1182 if (pThis->m_cb.EventHandler) {
1183 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1184 OMX_EventPortSettingsChanged, p1, p2, NULL );
1185 } else {
1186 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1187 }
1188
Arun Menon906de572013-06-18 17:01:40 -07001189 break;
1190
1191 case OMX_COMPONENT_GENERATE_EOS_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001192 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001193 if (pThis->m_cb.EventHandler) {
1194 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag,
1195 OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL );
1196 } else {
1197 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1198 }
1199 pThis->prev_ts = LLONG_MAX;
1200 pThis->rst_prev_ts = true;
1201 break;
1202
1203 case OMX_COMPONENT_GENERATE_HARDWARE_ERROR:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001204 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR");
Arun Menon906de572013-06-18 17:01:40 -07001205 pThis->omx_report_error ();
1206 break;
1207
1208 case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001209 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING");
Arun Menon906de572013-06-18 17:01:40 -07001210 pThis->omx_report_unsupported_setting();
1211 break;
1212
Arun Menon906de572013-06-18 17:01:40 -07001213 default:
1214 break;
1215 }
1216 }
1217 pthread_mutex_lock(&pThis->m_lock);
1218 qsize = pThis->m_cmd_q.m_size;
1219 if (pThis->m_state != OMX_StatePause)
1220 qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size);
1221 pthread_mutex_unlock(&pThis->m_lock);
1222 } while (qsize>0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001223
1224}
1225
Vinay Kaliab9e98102013-04-02 19:31:43 -07001226int omx_vdec::update_resolution(int width, int height, int stride, int scan_lines)
Vinay Kalia592e4b42012-12-19 15:55:47 -08001227{
Arun Menon906de572013-06-18 17:01:40 -07001228 int format_changed = 0;
Surajit Podderd2644d52013-08-28 17:59:06 +05301229 if ((height != (int)drv_ctx.video_resolution.frame_height) ||
1230 (width != (int)drv_ctx.video_resolution.frame_width)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001231 DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)",
Arun Menon906de572013-06-18 17:01:40 -07001232 width, drv_ctx.video_resolution.frame_width,
1233 height,drv_ctx.video_resolution.frame_height);
1234 format_changed = 1;
1235 }
Vinay Kalia592e4b42012-12-19 15:55:47 -08001236 drv_ctx.video_resolution.frame_height = height;
1237 drv_ctx.video_resolution.frame_width = width;
Vinay Kalia21649b32013-03-18 17:28:07 -07001238 drv_ctx.video_resolution.scan_lines = scan_lines;
1239 drv_ctx.video_resolution.stride = stride;
Vinay Kalia592e4b42012-12-19 15:55:47 -08001240 rectangle.nLeft = 0;
1241 rectangle.nTop = 0;
1242 rectangle.nWidth = drv_ctx.video_resolution.frame_width;
1243 rectangle.nHeight = drv_ctx.video_resolution.frame_height;
Arun Menon906de572013-06-18 17:01:40 -07001244 return format_changed;
Vinay Kalia592e4b42012-12-19 15:55:47 -08001245}
1246
Arun Menon6836ba02013-02-19 20:37:40 -08001247OMX_ERRORTYPE omx_vdec::is_video_session_supported()
1248{
Arun Menon906de572013-06-18 17:01:40 -07001249 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",
1250 OMX_MAX_STRINGNAME_SIZE) &&
1251 (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) {
1252 m_decoder_capability.max_width = 1280;
1253 m_decoder_capability.max_height = 720;
1254 DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP");
1255 }
Arun Menon888aa852013-05-30 11:24:42 -07001256
Arun Menon906de572013-06-18 17:01:40 -07001257 if ((drv_ctx.video_resolution.frame_width *
1258 drv_ctx.video_resolution.frame_height >
1259 m_decoder_capability.max_width *
1260 m_decoder_capability.max_height) ||
1261 (drv_ctx.video_resolution.frame_width*
1262 drv_ctx.video_resolution.frame_height <
1263 m_decoder_capability.min_width *
1264 m_decoder_capability.min_height)) {
1265 DEBUG_PRINT_ERROR(
1266 "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)",
1267 drv_ctx.video_resolution.frame_width,
1268 drv_ctx.video_resolution.frame_height,
1269 m_decoder_capability.min_width,
1270 m_decoder_capability.min_height,
1271 m_decoder_capability.max_width,
1272 m_decoder_capability.max_height);
1273 return OMX_ErrorUnsupportedSetting;
1274 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001275 DEBUG_PRINT_HIGH("video session supported");
Arun Menon906de572013-06-18 17:01:40 -07001276 return OMX_ErrorNone;
Arun Menon6836ba02013-02-19 20:37:40 -08001277}
1278
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001279int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len)
1280{
1281 if (m_debug.in_buffer_log && !m_debug.infile) {
1282 if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) {
1283 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v",
1284 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1285 }
1286 else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) {
1287 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); }
1288 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) {
1289 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263",
1290 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1291 }
1292 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) {
1293 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264",
1294 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1295 }
1296 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) {
1297 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1298 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1299 }
1300 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) {
1301 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1302 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1303 }
1304 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1305 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf",
1306 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1307 }
1308 m_debug.infile = fopen (m_debug.infile_name, "ab");
1309 if (!m_debug.infile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001310 DEBUG_PRINT_HIGH("Failed to open input file: %s for logging", m_debug.infile_name);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001311 m_debug.infile_name[0] = '\0';
1312 return -1;
1313 }
1314 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1315 struct ivf_file_header {
1316 OMX_U8 signature[4]; //='DKIF';
1317 OMX_U8 version ; //= 0;
1318 OMX_U8 headersize ; //= 32;
1319 OMX_U32 FourCC;
1320 OMX_U8 width;
1321 OMX_U8 height;
1322 OMX_U32 rate;
1323 OMX_U32 scale;
1324 OMX_U32 length;
1325 OMX_U8 unused[4];
1326 } file_header;
1327
1328 memset((void *)&file_header,0,sizeof(file_header));
1329 file_header.signature[0] = 'D';
1330 file_header.signature[1] = 'K';
1331 file_header.signature[2] = 'I';
1332 file_header.signature[3] = 'F';
1333 file_header.version = 0;
1334 file_header.headersize = 32;
1335 file_header.FourCC = 0x30385056;
1336 fwrite((const char *)&file_header,
1337 sizeof(file_header),1,m_debug.infile);
1338 }
1339 }
1340 if (m_debug.infile && buffer_addr && buffer_len) {
1341 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1342 struct vp8_ivf_frame_header {
1343 OMX_U32 framesize;
1344 OMX_U32 timestamp_lo;
1345 OMX_U32 timestamp_hi;
1346 } vp8_frame_header;
1347 vp8_frame_header.framesize = buffer_len;
1348 /* Currently FW doesn't use timestamp values */
1349 vp8_frame_header.timestamp_lo = 0;
1350 vp8_frame_header.timestamp_hi = 0;
1351 fwrite((const char *)&vp8_frame_header,
1352 sizeof(vp8_frame_header),1,m_debug.infile);
1353 }
1354 fwrite(buffer_addr, buffer_len, 1, m_debug.infile);
1355 }
1356 return 0;
1357}
1358
1359int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) {
1360 if (m_debug.out_buffer_log && !m_debug.outfile) {
1361 sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv",
1362 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1363 m_debug.outfile = fopen (m_debug.outfile_name, "ab");
1364 if (!m_debug.outfile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001365 DEBUG_PRINT_HIGH("Failed to open output file: %s for logging", m_debug.log_loc);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001366 m_debug.outfile_name[0] = '\0';
1367 return -1;
1368 }
1369 }
1370 if (m_debug.outfile && buffer && buffer->nFilledLen) {
1371 int buf_index = buffer - m_out_mem_ptr;
1372 int stride = drv_ctx.video_resolution.stride;
1373 int scanlines = drv_ctx.video_resolution.scan_lines;
1374 char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr;
1375 unsigned i;
1376 int bytes_written = 0;
1377 for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) {
1378 bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1379 temp += stride;
1380 }
1381 temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines;
1382 int stride_c = stride;
1383 for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) {
1384 bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1385 temp += stride_c;
1386 }
1387 }
1388 return 0;
1389}
1390
Shalaj Jain273b3e02012-06-22 19:08:03 -07001391/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001392 FUNCTION
1393 omx_vdec::ComponentInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07001394
Arun Menon906de572013-06-18 17:01:40 -07001395 DESCRIPTION
1396 Initialize the component.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001397
Arun Menon906de572013-06-18 17:01:40 -07001398 PARAMETERS
1399 ctxt -- Context information related to the self.
1400 id -- Event identifier. This could be any of the following:
1401 1. Command completion event
1402 2. Buffer done callback event
1403 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -07001404
Arun Menon906de572013-06-18 17:01:40 -07001405 RETURN VALUE
1406 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001407
Arun Menon906de572013-06-18 17:01:40 -07001408 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001409OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role)
1410{
1411
Arun Menon906de572013-06-18 17:01:40 -07001412 OMX_ERRORTYPE eRet = OMX_ErrorNone;
1413 struct v4l2_fmtdesc fdesc;
1414 struct v4l2_format fmt;
1415 struct v4l2_requestbuffers bufreq;
1416 struct v4l2_control control;
1417 struct v4l2_frmsizeenum frmsize;
1418 unsigned int alignment = 0,buffer_size = 0;
1419 int fds[2];
1420 int r,ret=0;
1421 bool codec_ambiguous = false;
1422 OMX_STRING device_name = (OMX_STRING)"/dev/video/venus_dec";
Sachin Shahc82a18f2013-03-29 14:45:38 -07001423
1424#ifdef _ANDROID_
Praveen Chavane9e56202013-09-19 03:48:16 -07001425 char platform_name[PROPERTY_VALUE_MAX];
Arun Menon906de572013-06-18 17:01:40 -07001426 property_get("ro.board.platform", platform_name, "0");
1427 if (!strncmp(platform_name, "msm8610", 7)) {
1428 device_name = (OMX_STRING)"/dev/video/q6_dec";
1429 }
Sachin Shahc82a18f2013-03-29 14:45:38 -07001430#endif
1431
Arun Menon906de572013-06-18 17:01:40 -07001432 if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) {
1433 struct v4l2_control control;
1434 secure_mode = true;
1435 arbitrary_bytes = false;
1436 role = (OMX_STRING)"OMX.qcom.video.decoder.avc";
1437 }
Vinay Kalia53fa6832012-10-11 17:55:30 -07001438
Arun Menon906de572013-06-18 17:01:40 -07001439 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001440
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001441 DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open returned fd %d",
Jayasena Sangaraboinac453bd82013-08-01 14:02:52 -07001442 drv_ctx.video_driver_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001443
Arun Menon906de572013-06-18 17:01:40 -07001444 if (drv_ctx.video_driver_fd == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001445 DEBUG_PRINT_ERROR("omx_vdec_msm8974 :: Got fd as 0 for msm_vidc_dec, Opening again");
Arun Menon906de572013-06-18 17:01:40 -07001446 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
1447 close(0);
1448 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001449
Arun Menon906de572013-06-18 17:01:40 -07001450 if (drv_ctx.video_driver_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001451 DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno);
Arun Menon906de572013-06-18 17:01:40 -07001452 return OMX_ErrorInsufficientResources;
1453 }
1454 drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS;
1455 drv_ctx.frame_rate.fps_denominator = 1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001456
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001457 ret = subscribe_to_events(drv_ctx.video_driver_fd);
Vinay Kalia184cd0f2013-04-29 18:26:42 -07001458 if (!ret) {
Arun Menon906de572013-06-18 17:01:40 -07001459 async_thread_created = true;
1460 ret = pthread_create(&async_thread_id,0,async_message_thread,this);
1461 }
1462 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001463 DEBUG_PRINT_ERROR("Failed to create async_message_thread");
Arun Menon906de572013-06-18 17:01:40 -07001464 async_thread_created = false;
1465 return OMX_ErrorInsufficientResources;
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001466 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001467
Shalaj Jain273b3e02012-06-22 19:08:03 -07001468#ifdef OUTPUT_EXTRADATA_LOG
Arun Menon906de572013-06-18 17:01:40 -07001469 outputExtradataFile = fopen (ouputextradatafilename, "ab");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001470#endif
1471
Arun Menon906de572013-06-18 17:01:40 -07001472 // Copy the role information which provides the decoder kind
1473 strlcpy(drv_ctx.kind,role,128);
Vinay Kalia53fa6832012-10-11 17:55:30 -07001474
Arun Menon906de572013-06-18 17:01:40 -07001475 if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\
1476 OMX_MAX_STRINGNAME_SIZE)) {
1477 strlcpy((char *)m_cRole, "video_decoder.mpeg4",\
1478 OMX_MAX_STRINGNAME_SIZE);
1479 drv_ctx.timestamp_adjust = true;
1480 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4;
1481 eCompressionFormat = OMX_VIDEO_CodingMPEG4;
1482 output_capability=V4L2_PIX_FMT_MPEG4;
1483 /*Initialize Start Code for MPEG4*/
1484 codec_type_parse = CODEC_TYPE_MPEG4;
1485 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001486 } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\
1487 OMX_MAX_STRINGNAME_SIZE)) {
1488 strlcpy((char *)m_cRole, "video_decoder.mpeg2",\
1489 OMX_MAX_STRINGNAME_SIZE);
1490 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2;
1491 output_capability = V4L2_PIX_FMT_MPEG2;
1492 eCompressionFormat = OMX_VIDEO_CodingMPEG2;
1493 /*Initialize Start Code for MPEG2*/
1494 codec_type_parse = CODEC_TYPE_MPEG2;
1495 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001496 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\
1497 OMX_MAX_STRINGNAME_SIZE)) {
1498 strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001499 DEBUG_PRINT_LOW("H263 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001500 drv_ctx.decoder_format = VDEC_CODECTYPE_H263;
1501 eCompressionFormat = OMX_VIDEO_CodingH263;
1502 output_capability = V4L2_PIX_FMT_H263;
1503 codec_type_parse = CODEC_TYPE_H263;
1504 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001505 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\
1506 OMX_MAX_STRINGNAME_SIZE)) {
1507 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001508 DEBUG_PRINT_LOW ("DIVX 311 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001509 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3;
1510 output_capability = V4L2_PIX_FMT_DIVX_311;
1511 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1512 codec_type_parse = CODEC_TYPE_DIVX;
1513 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001514
Arun Menon906de572013-06-18 17:01:40 -07001515 eRet = createDivxDrmContext();
1516 if (eRet != OMX_ErrorNone) {
1517 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1518 return eRet;
1519 }
1520 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\
1521 OMX_MAX_STRINGNAME_SIZE)) {
1522 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001523 DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001524 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4;
1525 output_capability = V4L2_PIX_FMT_DIVX;
1526 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1527 codec_type_parse = CODEC_TYPE_DIVX;
1528 codec_ambiguous = true;
1529 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001530
Arun Menon906de572013-06-18 17:01:40 -07001531 eRet = createDivxDrmContext();
1532 if (eRet != OMX_ErrorNone) {
1533 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1534 return eRet;
1535 }
1536 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\
1537 OMX_MAX_STRINGNAME_SIZE)) {
1538 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001539 DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001540 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6;
1541 output_capability = V4L2_PIX_FMT_DIVX;
1542 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1543 codec_type_parse = CODEC_TYPE_DIVX;
1544 codec_ambiguous = true;
1545 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001546
Arun Menon906de572013-06-18 17:01:40 -07001547 eRet = createDivxDrmContext();
1548 if (eRet != OMX_ErrorNone) {
1549 DEBUG_PRINT_ERROR("createDivxDrmContext Failed");
1550 return eRet;
1551 }
Deva Ramasubramanian9403f022012-11-28 18:27:53 -08001552
Arun Menon906de572013-06-18 17:01:40 -07001553 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\
1554 OMX_MAX_STRINGNAME_SIZE)) {
1555 strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
1556 drv_ctx.decoder_format = VDEC_CODECTYPE_H264;
1557 output_capability=V4L2_PIX_FMT_H264;
1558 eCompressionFormat = OMX_VIDEO_CodingAVC;
1559 codec_type_parse = CODEC_TYPE_H264;
1560 m_frame_parser.init_start_codes (codec_type_parse);
1561 m_frame_parser.init_nal_length(nal_length);
Arun Menon906de572013-06-18 17:01:40 -07001562 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\
1563 OMX_MAX_STRINGNAME_SIZE)) {
1564 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1565 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1;
1566 eCompressionFormat = OMX_VIDEO_CodingWMV;
1567 codec_type_parse = CODEC_TYPE_VC1;
1568 output_capability = V4L2_PIX_FMT_VC1_ANNEX_G;
1569 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001570 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\
1571 OMX_MAX_STRINGNAME_SIZE)) {
1572 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1573 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV;
1574 eCompressionFormat = OMX_VIDEO_CodingWMV;
1575 codec_type_parse = CODEC_TYPE_VC1;
1576 output_capability = V4L2_PIX_FMT_VC1_ANNEX_L;
1577 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001578 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \
1579 OMX_MAX_STRINGNAME_SIZE)) {
1580 strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
1581 output_capability=V4L2_PIX_FMT_VP8;
1582 eCompressionFormat = OMX_VIDEO_CodingVPX;
1583 codec_type_parse = CODEC_TYPE_VP8;
1584 arbitrary_bytes = false;
Praneeth Paladugu2b2ef2d2013-04-10 22:04:51 -07001585
Arun Menon906de572013-06-18 17:01:40 -07001586 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001587 DEBUG_PRINT_ERROR("ERROR:Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07001588 eRet = OMX_ErrorInvalidComponentName;
1589 }
Arun Menon906de572013-06-18 17:01:40 -07001590 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001591
Arun Menon906de572013-06-18 17:01:40 -07001592 drv_ctx.output_format = VDEC_YUV_FORMAT_NV12;
Vinay Kaliada4f4422013-01-09 10:45:03 -08001593 OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE)
1594 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
1595 if (!client_buffers.set_color_format(dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001596 DEBUG_PRINT_ERROR("Setting color format failed");
Vinay Kaliada4f4422013-01-09 10:45:03 -08001597 eRet = OMX_ErrorInsufficientResources;
1598 }
1599
Arun Menon906de572013-06-18 17:01:40 -07001600 capture_capability= V4L2_PIX_FMT_NV12;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001601
Arun Menon906de572013-06-18 17:01:40 -07001602 struct v4l2_capability cap;
1603 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap);
1604 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001605 DEBUG_PRINT_ERROR("Failed to query capabilities");
Arun Menon906de572013-06-18 17:01:40 -07001606 /*TODO: How to handle this case */
1607 } else {
1608 DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s,"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001609 " version = %d, capabilities = %x", cap.driver, cap.card,
Arun Menon906de572013-06-18 17:01:40 -07001610 cap.bus_info, cap.version, cap.capabilities);
1611 }
1612 ret=0;
1613 fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1614 fdesc.index=0;
1615 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001616 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001617 fdesc.pixelformat, fdesc.flags);
1618 fdesc.index++;
1619 }
1620 fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1621 fdesc.index=0;
1622 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001623
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001624 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001625 fdesc.pixelformat, fdesc.flags);
1626 fdesc.index++;
1627 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001628 update_resolution(320, 240, 320, 240);
Arun Menon906de572013-06-18 17:01:40 -07001629 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1630 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1631 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1632 fmt.fmt.pix_mp.pixelformat = output_capability;
1633 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1634 if (ret) {
1635 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001636 DEBUG_PRINT_ERROR("Failed to set format on output port");
Arun Menon906de572013-06-18 17:01:40 -07001637 return OMX_ErrorInsufficientResources;
1638 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001639 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001640 if (codec_ambiguous) {
1641 if (output_capability == V4L2_PIX_FMT_DIVX) {
1642 struct v4l2_control divx_ctrl;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001643
Arun Menon906de572013-06-18 17:01:40 -07001644 if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) {
1645 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4;
1646 } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) {
1647 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5;
1648 } else {
1649 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6;
1650 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001651
Arun Menon906de572013-06-18 17:01:40 -07001652 divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT;
1653 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl);
1654 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001655 DEBUG_PRINT_ERROR("Failed to set divx version");
Arun Menon906de572013-06-18 17:01:40 -07001656 }
1657 } else {
1658 DEBUG_PRINT_ERROR("Codec should not be ambiguous");
1659 }
1660 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001661
Arun Menon906de572013-06-18 17:01:40 -07001662 //Get the hardware capabilities
1663 memset((void *)&frmsize,0,sizeof(frmsize));
1664 frmsize.index = 0;
1665 frmsize.pixel_format = output_capability;
1666 ret = ioctl(drv_ctx.video_driver_fd,
1667 VIDIOC_ENUM_FRAMESIZES, &frmsize);
1668 if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001669 DEBUG_PRINT_ERROR("Failed to get framesizes");
Arun Menon906de572013-06-18 17:01:40 -07001670 return OMX_ErrorHardware;
1671 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001672
Arun Menon906de572013-06-18 17:01:40 -07001673 if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1674 m_decoder_capability.min_width = frmsize.stepwise.min_width;
1675 m_decoder_capability.max_width = frmsize.stepwise.max_width;
1676 m_decoder_capability.min_height = frmsize.stepwise.min_height;
1677 m_decoder_capability.max_height = frmsize.stepwise.max_height;
1678 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001679
Arun Menon906de572013-06-18 17:01:40 -07001680 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1681 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1682 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1683 fmt.fmt.pix_mp.pixelformat = capture_capability;
1684 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1685 if (ret) {
1686 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001687 DEBUG_PRINT_ERROR("Failed to set format on capture port");
Arun Menon906de572013-06-18 17:01:40 -07001688 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001689 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001690 if (secure_mode) {
1691 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE;
1692 control.value = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001693 DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001694 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
1695 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001696 DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001697 return OMX_ErrorInsufficientResources;
1698 }
1699 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001700
Arun Menon906de572013-06-18 17:01:40 -07001701 /*Get the Buffer requirements for input and output ports*/
1702 drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT;
1703 drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
1704 if (secure_mode) {
1705 drv_ctx.op_buf.alignment=SZ_1M;
1706 drv_ctx.ip_buf.alignment=SZ_1M;
1707 } else {
1708 drv_ctx.op_buf.alignment=SZ_4K;
1709 drv_ctx.ip_buf.alignment=SZ_4K;
1710 }
1711 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
1712 drv_ctx.extradata = 0;
1713 drv_ctx.picture_order = VDEC_ORDER_DISPLAY;
1714 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
1715 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
1716 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
1717 drv_ctx.idr_only_decoding = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001718
Vinay Kalia5713bb32013-01-16 18:39:59 -08001719 m_state = OMX_StateLoaded;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001720#ifdef DEFAULT_EXTRADATA
Vinay Kalia5713bb32013-01-16 18:39:59 -08001721 if (eRet == OMX_ErrorNone && !secure_mode)
1722 enable_extradata(DEFAULT_EXTRADATA, true, true);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001723#endif
Vinay Kalia5713bb32013-01-16 18:39:59 -08001724 eRet=get_buffer_req(&drv_ctx.ip_buf);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001725 DEBUG_PRINT_HIGH("Input Buffer Size =%d",drv_ctx.ip_buf.buffer_size);
Vinay Kalia5713bb32013-01-16 18:39:59 -08001726 get_buffer_req(&drv_ctx.op_buf);
Arun Menon906de572013-06-18 17:01:40 -07001727 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
1728 if (m_frame_parser.mutils == NULL) {
1729 m_frame_parser.mutils = new H264_Utils();
Shalaj Jain273b3e02012-06-22 19:08:03 -07001730
Arun Menon906de572013-06-18 17:01:40 -07001731 if (m_frame_parser.mutils == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001732 DEBUG_PRINT_ERROR("parser utils Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001733 eRet = OMX_ErrorInsufficientResources;
1734 } else {
1735 h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size;
1736 h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size);
1737 h264_scratch.nFilledLen = 0;
1738 h264_scratch.nOffset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001739
Arun Menon906de572013-06-18 17:01:40 -07001740 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001741 DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001742 return OMX_ErrorInsufficientResources;
1743 }
1744 m_frame_parser.mutils->initialize_frame_checking_environment();
1745 m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size);
1746 }
1747 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001748
Arun Menon906de572013-06-18 17:01:40 -07001749 h264_parser = new h264_stream_parser();
1750 if (!h264_parser) {
1751 DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!");
1752 eRet = OMX_ErrorInsufficientResources;
1753 }
1754 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001755
Arun Menon906de572013-06-18 17:01:40 -07001756 if (pipe(fds)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001757 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001758 eRet = OMX_ErrorInsufficientResources;
1759 } else {
1760 int temp1[2];
1761 if (fds[0] == 0 || fds[1] == 0) {
1762 if (pipe (temp1)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001763 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001764 return OMX_ErrorInsufficientResources;
1765 }
1766 //close (fds[0]);
1767 //close (fds[1]);
1768 fds[0] = temp1 [0];
1769 fds[1] = temp1 [1];
1770 }
1771 m_pipe_in = fds[0];
1772 m_pipe_out = fds[1];
1773 msg_thread_created = true;
1774 r = pthread_create(&msg_thread_id,0,message_thread,this);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001775
Arun Menon906de572013-06-18 17:01:40 -07001776 if (r < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001777 DEBUG_PRINT_ERROR("component_init(): message_thread creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001778 msg_thread_created = false;
1779 eRet = OMX_ErrorInsufficientResources;
1780 }
1781 }
1782 }
1783
1784 if (eRet != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001785 DEBUG_PRINT_ERROR("Component Init Failed");
Arun Menon906de572013-06-18 17:01:40 -07001786 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001787 DEBUG_PRINT_HIGH("omx_vdec::component_init() success");
Arun Menon906de572013-06-18 17:01:40 -07001788 }
1789 //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer));
1790 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001791}
1792
1793/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001794 FUNCTION
1795 omx_vdec::GetComponentVersion
Shalaj Jain273b3e02012-06-22 19:08:03 -07001796
Arun Menon906de572013-06-18 17:01:40 -07001797 DESCRIPTION
1798 Returns the component version.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001799
Arun Menon906de572013-06-18 17:01:40 -07001800 PARAMETERS
1801 TBD.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001802
Arun Menon906de572013-06-18 17:01:40 -07001803 RETURN VALUE
1804 OMX_ErrorNone.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001805
Arun Menon906de572013-06-18 17:01:40 -07001806 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001807OMX_ERRORTYPE omx_vdec::get_component_version
Arun Menon906de572013-06-18 17:01:40 -07001808(
1809 OMX_IN OMX_HANDLETYPE hComp,
1810 OMX_OUT OMX_STRING componentName,
1811 OMX_OUT OMX_VERSIONTYPE* componentVersion,
1812 OMX_OUT OMX_VERSIONTYPE* specVersion,
1813 OMX_OUT OMX_UUIDTYPE* componentUUID
1814 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07001815{
Arun Menon906de572013-06-18 17:01:40 -07001816 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001817 DEBUG_PRINT_ERROR("Get Comp Version in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001818 return OMX_ErrorInvalidState;
1819 }
Arun Menon906de572013-06-18 17:01:40 -07001820 /* TBD -- Return the proper version */
1821 if (specVersion) {
1822 specVersion->nVersion = OMX_SPEC_VERSION;
1823 }
1824 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001825}
1826/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001827 FUNCTION
1828 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07001829
Arun Menon906de572013-06-18 17:01:40 -07001830 DESCRIPTION
1831 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07001832
Arun Menon906de572013-06-18 17:01:40 -07001833 PARAMETERS
1834 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001835
Arun Menon906de572013-06-18 17:01:40 -07001836 RETURN VALUE
1837 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07001838
Arun Menon906de572013-06-18 17:01:40 -07001839 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001840OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07001841 OMX_IN OMX_COMMANDTYPE cmd,
1842 OMX_IN OMX_U32 param1,
1843 OMX_IN OMX_PTR cmdData
1844 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07001845{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001846 DEBUG_PRINT_LOW("send_command: Recieved a Command from Client");
Arun Menon906de572013-06-18 17:01:40 -07001847 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001848 DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001849 return OMX_ErrorInvalidState;
1850 }
1851 if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX
Arun Menon906de572013-06-18 17:01:40 -07001852 && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001853 DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush "
Arun Menon906de572013-06-18 17:01:40 -07001854 "to invalid port: %lu", param1);
1855 return OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001856 }
1857 post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND);
1858 sem_wait(&m_cmd_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001859 DEBUG_PRINT_LOW("send_command: Command Processed");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001860 return OMX_ErrorNone;
1861}
1862
1863/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001864 FUNCTION
1865 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07001866
Arun Menon906de572013-06-18 17:01:40 -07001867 DESCRIPTION
1868 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07001869
Arun Menon906de572013-06-18 17:01:40 -07001870 PARAMETERS
1871 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001872
Arun Menon906de572013-06-18 17:01:40 -07001873 RETURN VALUE
1874 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07001875
Arun Menon906de572013-06-18 17:01:40 -07001876 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001877OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07001878 OMX_IN OMX_COMMANDTYPE cmd,
1879 OMX_IN OMX_U32 param1,
1880 OMX_IN OMX_PTR cmdData
1881 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07001882{
Arun Menon906de572013-06-18 17:01:40 -07001883 OMX_ERRORTYPE eRet = OMX_ErrorNone;
1884 OMX_STATETYPE eState = (OMX_STATETYPE) param1;
1885 int bFlag = 1,sem_posted = 0,ret=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001886
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001887 DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd);
1888 DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d",
Arun Menon906de572013-06-18 17:01:40 -07001889 m_state, eState);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001890
Arun Menon906de572013-06-18 17:01:40 -07001891 if (cmd == OMX_CommandStateSet) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001892 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued");
1893 DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState);
Arun Menon906de572013-06-18 17:01:40 -07001894 /***************************/
1895 /* Current State is Loaded */
1896 /***************************/
1897 if (m_state == OMX_StateLoaded) {
1898 if (eState == OMX_StateIdle) {
1899 //if all buffers are allocated or all ports disabled
1900 if (allocate_done() ||
1901 (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001902 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07001903 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001904 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending");
Arun Menon906de572013-06-18 17:01:40 -07001905 BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING);
1906 // Skip the event notification
1907 bFlag = 0;
1908 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001909 }
Arun Menon906de572013-06-18 17:01:40 -07001910 /* Requesting transition from Loaded to Loaded */
1911 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001912 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07001913 post_event(OMX_EventError,OMX_ErrorSameState,\
1914 OMX_COMPONENT_GENERATE_EVENT);
1915 eRet = OMX_ErrorSameState;
1916 }
1917 /* Requesting transition from Loaded to WaitForResources */
1918 else if (eState == OMX_StateWaitForResources) {
1919 /* Since error is None , we will post an event
1920 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001921 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07001922 }
1923 /* Requesting transition from Loaded to Executing */
1924 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001925 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07001926 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
1927 OMX_COMPONENT_GENERATE_EVENT);
1928 eRet = OMX_ErrorIncorrectStateTransition;
1929 }
1930 /* Requesting transition from Loaded to Pause */
1931 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001932 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07001933 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
1934 OMX_COMPONENT_GENERATE_EVENT);
1935 eRet = OMX_ErrorIncorrectStateTransition;
1936 }
1937 /* Requesting transition from Loaded to Invalid */
1938 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001939 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07001940 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
1941 eRet = OMX_ErrorInvalidState;
1942 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001943 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\
Arun Menon906de572013-06-18 17:01:40 -07001944 eState);
1945 eRet = OMX_ErrorBadParameter;
1946 }
1947 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001948
Arun Menon906de572013-06-18 17:01:40 -07001949 /***************************/
1950 /* Current State is IDLE */
1951 /***************************/
1952 else if (m_state == OMX_StateIdle) {
1953 if (eState == OMX_StateLoaded) {
1954 if (release_done()) {
1955 /*
1956 Since error is None , we will post an event at the end
1957 of this function definition
1958 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001959 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07001960 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001961 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending");
Arun Menon906de572013-06-18 17:01:40 -07001962 BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING);
1963 // Skip the event notification
1964 bFlag = 0;
1965 }
1966 }
1967 /* Requesting transition from Idle to Executing */
1968 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001969 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07001970 //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING);
1971 bFlag = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001972 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07001973 m_state=OMX_StateExecuting;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001974 DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful");
Arun Menon906de572013-06-18 17:01:40 -07001975 }
1976 /* Requesting transition from Idle to Idle */
1977 else if (eState == OMX_StateIdle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001978 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07001979 post_event(OMX_EventError,OMX_ErrorSameState,\
1980 OMX_COMPONENT_GENERATE_EVENT);
1981 eRet = OMX_ErrorSameState;
1982 }
1983 /* Requesting transition from Idle to WaitForResources */
1984 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001985 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07001986 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
1987 OMX_COMPONENT_GENERATE_EVENT);
1988 eRet = OMX_ErrorIncorrectStateTransition;
1989 }
1990 /* Requesting transition from Idle to Pause */
1991 else if (eState == OMX_StatePause) {
1992 /*To pause the Video core we need to start the driver*/
1993 if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START,
1994 NULL) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001995 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED");
Arun Menon906de572013-06-18 17:01:40 -07001996 omx_report_error ();
1997 eRet = OMX_ErrorHardware;
1998 } else {
1999 BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002000 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002001 bFlag = 0;
2002 }
2003 }
2004 /* Requesting transition from Idle to Invalid */
2005 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002006 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002007 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2008 eRet = OMX_ErrorInvalidState;
2009 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002010 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002011 eRet = OMX_ErrorBadParameter;
2012 }
2013 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002014
Arun Menon906de572013-06-18 17:01:40 -07002015 /******************************/
2016 /* Current State is Executing */
2017 /******************************/
2018 else if (m_state == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002019 DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting");
Arun Menon906de572013-06-18 17:01:40 -07002020 /* Requesting transition from Executing to Idle */
2021 if (eState == OMX_StateIdle) {
2022 /* Since error is None , we will post an event
2023 at the end of this function definition
2024 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002025 DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002026 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2027 if (!sem_posted) {
2028 sem_posted = 1;
2029 sem_post (&m_cmd_lock);
2030 execute_omx_flush(OMX_ALL);
2031 }
2032 bFlag = 0;
2033 }
2034 /* Requesting transition from Executing to Paused */
2035 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002036 DEBUG_PRINT_LOW("PAUSE Command Issued");
Arun Menon906de572013-06-18 17:01:40 -07002037 m_state = OMX_StatePause;
2038 bFlag = 1;
2039 }
2040 /* Requesting transition from Executing to Loaded */
2041 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002042 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002043 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2044 OMX_COMPONENT_GENERATE_EVENT);
2045 eRet = OMX_ErrorIncorrectStateTransition;
2046 }
2047 /* Requesting transition from Executing to WaitForResources */
2048 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002049 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002050 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2051 OMX_COMPONENT_GENERATE_EVENT);
2052 eRet = OMX_ErrorIncorrectStateTransition;
2053 }
2054 /* Requesting transition from Executing to Executing */
2055 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002056 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002057 post_event(OMX_EventError,OMX_ErrorSameState,\
2058 OMX_COMPONENT_GENERATE_EVENT);
2059 eRet = OMX_ErrorSameState;
2060 }
2061 /* Requesting transition from Executing to Invalid */
2062 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002063 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002064 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2065 eRet = OMX_ErrorInvalidState;
2066 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002067 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002068 eRet = OMX_ErrorBadParameter;
2069 }
2070 }
2071 /***************************/
2072 /* Current State is Pause */
2073 /***************************/
2074 else if (m_state == OMX_StatePause) {
2075 /* Requesting transition from Pause to Executing */
2076 if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002077 DEBUG_PRINT_LOW("Pause --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002078 m_state = OMX_StateExecuting;
2079 bFlag = 1;
2080 }
2081 /* Requesting transition from Pause to Idle */
2082 else if (eState == OMX_StateIdle) {
2083 /* Since error is None , we will post an event
2084 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002085 DEBUG_PRINT_LOW("Pause --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002086 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2087 if (!sem_posted) {
2088 sem_posted = 1;
2089 sem_post (&m_cmd_lock);
2090 execute_omx_flush(OMX_ALL);
2091 }
2092 bFlag = 0;
2093 }
2094 /* Requesting transition from Pause to loaded */
2095 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002096 DEBUG_PRINT_ERROR("Pause --> loaded");
Arun Menon906de572013-06-18 17:01:40 -07002097 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2098 OMX_COMPONENT_GENERATE_EVENT);
2099 eRet = OMX_ErrorIncorrectStateTransition;
2100 }
2101 /* Requesting transition from Pause to WaitForResources */
2102 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002103 DEBUG_PRINT_ERROR("Pause --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002104 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2105 OMX_COMPONENT_GENERATE_EVENT);
2106 eRet = OMX_ErrorIncorrectStateTransition;
2107 }
2108 /* Requesting transition from Pause to Pause */
2109 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002110 DEBUG_PRINT_ERROR("Pause --> Pause");
Arun Menon906de572013-06-18 17:01:40 -07002111 post_event(OMX_EventError,OMX_ErrorSameState,\
2112 OMX_COMPONENT_GENERATE_EVENT);
2113 eRet = OMX_ErrorSameState;
2114 }
2115 /* Requesting transition from Pause to Invalid */
2116 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002117 DEBUG_PRINT_ERROR("Pause --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002118 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2119 eRet = OMX_ErrorInvalidState;
2120 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002121 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002122 eRet = OMX_ErrorBadParameter;
2123 }
2124 }
2125 /***************************/
2126 /* Current State is WaitForResources */
2127 /***************************/
2128 else if (m_state == OMX_StateWaitForResources) {
2129 /* Requesting transition from WaitForResources to Loaded */
2130 if (eState == OMX_StateLoaded) {
2131 /* Since error is None , we will post an event
2132 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002133 DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002134 }
2135 /* Requesting transition from WaitForResources to WaitForResources */
2136 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002137 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002138 post_event(OMX_EventError,OMX_ErrorSameState,
2139 OMX_COMPONENT_GENERATE_EVENT);
2140 eRet = OMX_ErrorSameState;
2141 }
2142 /* Requesting transition from WaitForResources to Executing */
2143 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002144 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002145 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2146 OMX_COMPONENT_GENERATE_EVENT);
2147 eRet = OMX_ErrorIncorrectStateTransition;
2148 }
2149 /* Requesting transition from WaitForResources to Pause */
2150 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002151 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002152 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2153 OMX_COMPONENT_GENERATE_EVENT);
2154 eRet = OMX_ErrorIncorrectStateTransition;
2155 }
2156 /* Requesting transition from WaitForResources to Invalid */
2157 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002158 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002159 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2160 eRet = OMX_ErrorInvalidState;
2161 }
2162 /* Requesting transition from WaitForResources to Loaded -
2163 is NOT tested by Khronos TS */
2164
2165 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002166 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): %d --> %d(Not Handled)",m_state,eState);
Arun Menon906de572013-06-18 17:01:40 -07002167 eRet = OMX_ErrorBadParameter;
2168 }
2169 }
2170 /********************************/
2171 /* Current State is Invalid */
2172 /*******************************/
2173 else if (m_state == OMX_StateInvalid) {
2174 /* State Transition from Inavlid to any state */
2175 if (eState == (OMX_StateLoaded || OMX_StateWaitForResources
2176 || OMX_StateIdle || OMX_StateExecuting
2177 || OMX_StatePause || OMX_StateInvalid)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002178 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002179 post_event(OMX_EventError,OMX_ErrorInvalidState,\
2180 OMX_COMPONENT_GENERATE_EVENT);
2181 eRet = OMX_ErrorInvalidState;
2182 }
2183 } else if (cmd == OMX_CommandFlush) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002184 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued"
Arun Menon906de572013-06-18 17:01:40 -07002185 "with param1: %lu", param1);
2186 if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2187 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING);
2188 }
2189 if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2190 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
2191 }
2192 if (!sem_posted) {
2193 sem_posted = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002194 DEBUG_PRINT_LOW("Set the Semaphore");
Arun Menon906de572013-06-18 17:01:40 -07002195 sem_post (&m_cmd_lock);
2196 execute_omx_flush(param1);
2197 }
2198 bFlag = 0;
2199 } else if ( cmd == OMX_CommandPortEnable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002200 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued"
Arun Menon906de572013-06-18 17:01:40 -07002201 "with param1: %lu", param1);
2202 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
2203 m_inp_bEnabled = OMX_TRUE;
2204
2205 if ( (m_state == OMX_StateLoaded &&
2206 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2207 || allocate_input_done()) {
2208 post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX,
2209 OMX_COMPONENT_GENERATE_EVENT);
2210 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002211 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002212 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING);
2213 // Skip the event notification
2214 bFlag = 0;
2215 }
2216 }
2217 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002218 DEBUG_PRINT_LOW("Enable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002219 m_out_bEnabled = OMX_TRUE;
2220
2221 if ( (m_state == OMX_StateLoaded &&
2222 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2223 || (allocate_output_done())) {
2224 post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX,
2225 OMX_COMPONENT_GENERATE_EVENT);
2226
2227 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002228 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002229 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
2230 // Skip the event notification
2231 bFlag = 0;
2232 }
2233 }
2234 } else if (cmd == OMX_CommandPortDisable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002235 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued"
Arun Menon906de572013-06-18 17:01:40 -07002236 "with param1: %lu", param1);
2237 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
2238 m_inp_bEnabled = OMX_FALSE;
2239 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2240 && release_input_done()) {
2241 post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX,
2242 OMX_COMPONENT_GENERATE_EVENT);
2243 } else {
2244 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING);
2245 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2246 if (!sem_posted) {
2247 sem_posted = 1;
2248 sem_post (&m_cmd_lock);
2249 }
2250 execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX);
2251 }
2252
2253 // Skip the event notification
2254 bFlag = 0;
2255 }
2256 }
2257 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
2258 m_out_bEnabled = OMX_FALSE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002259 DEBUG_PRINT_LOW("Disable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002260 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2261 && release_output_done()) {
2262 post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\
2263 OMX_COMPONENT_GENERATE_EVENT);
2264 } else {
2265 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
2266 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2267 if (!sem_posted) {
2268 sem_posted = 1;
2269 sem_post (&m_cmd_lock);
2270 }
2271 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
2272 execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX);
2273 }
2274 // Skip the event notification
2275 bFlag = 0;
2276
2277 }
2278 }
2279 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002280 DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd);
Arun Menon906de572013-06-18 17:01:40 -07002281 eRet = OMX_ErrorNotImplemented;
2282 }
2283 if (eRet == OMX_ErrorNone && bFlag) {
2284 post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT);
2285 }
2286 if (!sem_posted) {
2287 sem_post(&m_cmd_lock);
2288 }
2289
2290 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002291}
2292
2293/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002294 FUNCTION
2295 omx_vdec::ExecuteOmxFlush
Shalaj Jain273b3e02012-06-22 19:08:03 -07002296
Arun Menon906de572013-06-18 17:01:40 -07002297 DESCRIPTION
2298 Executes the OMX flush.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002299
Arun Menon906de572013-06-18 17:01:40 -07002300 PARAMETERS
2301 flushtype - input flush(1)/output flush(0)/ both.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002302
Arun Menon906de572013-06-18 17:01:40 -07002303 RETURN VALUE
2304 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002305
Arun Menon906de572013-06-18 17:01:40 -07002306 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002307bool omx_vdec::execute_omx_flush(OMX_U32 flushType)
2308{
Arun Menon906de572013-06-18 17:01:40 -07002309 bool bRet = false;
2310 struct v4l2_plane plane;
2311 struct v4l2_buffer v4l2_buf;
2312 struct v4l2_decoder_cmd dec;
Surajit Podderd2644d52013-08-28 17:59:06 +05302313 DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType);
Arun Menon906de572013-06-18 17:01:40 -07002314 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
2315 dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH;
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002316
Arun Menon906de572013-06-18 17:01:40 -07002317 DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig);
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002318
Arun Menon906de572013-06-18 17:01:40 -07002319 if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) {
2320 output_flush_progress = true;
2321 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2322 } else {
2323 /* XXX: The driver/hardware does not support flushing of individual ports
2324 * in all states. So we pretty much need to flush both ports internally,
2325 * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it
2326 * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set,
2327 * we automatically omit sending the FLUSH done for the "opposite" port. */
2328 input_flush_progress = true;
2329 output_flush_progress = true;
2330 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2331 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002332
Arun Menon906de572013-06-18 17:01:40 -07002333 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002334 DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType);
Arun Menon906de572013-06-18 17:01:40 -07002335 bRet = false;
2336 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002337
Arun Menon906de572013-06-18 17:01:40 -07002338 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002339}
2340/*=========================================================================
2341FUNCTION : execute_output_flush
2342
2343DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002344Executes the OMX flush at OUTPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002345
2346PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002347None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002348
2349RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002350true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002351==========================================================================*/
2352bool omx_vdec::execute_output_flush()
2353{
Arun Menon906de572013-06-18 17:01:40 -07002354 unsigned p1 = 0; // Parameter - 1
2355 unsigned p2 = 0; // Parameter - 2
2356 unsigned ident = 0;
2357 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002358
Arun Menon906de572013-06-18 17:01:40 -07002359 /*Generate FBD for all Buffers in the FTBq*/
2360 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002361 DEBUG_PRINT_LOW("Initiate Output Flush");
Arun Menon906de572013-06-18 17:01:40 -07002362 while (m_ftb_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002363 DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d",
Arun Menon906de572013-06-18 17:01:40 -07002364 m_ftb_q.m_size,pending_output_buffers);
2365 m_ftb_q.pop_entry(&p1,&p2,&ident);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002366 DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2);
Arun Menon906de572013-06-18 17:01:40 -07002367 if (ident == m_fill_output_msg ) {
2368 m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2369 } else if (ident == OMX_COMPONENT_GENERATE_FBD) {
2370 fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2371 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002372 }
Arun Menon906de572013-06-18 17:01:40 -07002373 pthread_mutex_unlock(&m_lock);
2374 output_flush_progress = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002375
Arun Menon906de572013-06-18 17:01:40 -07002376 if (arbitrary_bytes) {
2377 prev_ts = LLONG_MAX;
2378 rst_prev_ts = true;
2379 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002380 DEBUG_PRINT_HIGH("OMX flush o/p Port complete PenBuf(%d)", pending_output_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002381 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002382}
2383/*=========================================================================
2384FUNCTION : execute_input_flush
2385
2386DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002387Executes the OMX flush at INPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002388
2389PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002390None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002391
2392RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002393true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002394==========================================================================*/
2395bool omx_vdec::execute_input_flush()
2396{
Arun Menon906de572013-06-18 17:01:40 -07002397 unsigned i =0;
2398 unsigned p1 = 0; // Parameter - 1
2399 unsigned p2 = 0; // Parameter - 2
2400 unsigned ident = 0;
2401 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002402
Arun Menon906de572013-06-18 17:01:40 -07002403 /*Generate EBD for all Buffers in the ETBq*/
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002404 DEBUG_PRINT_LOW("Initiate Input Flush");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002405
Arun Menon906de572013-06-18 17:01:40 -07002406 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002407 DEBUG_PRINT_LOW("Check if the Queue is empty");
Arun Menon906de572013-06-18 17:01:40 -07002408 while (m_etb_q.m_size) {
2409 m_etb_q.pop_entry(&p1,&p2,&ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002410
Arun Menon906de572013-06-18 17:01:40 -07002411 if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002412 DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2);
Arun Menon906de572013-06-18 17:01:40 -07002413 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2414 } else if (ident == OMX_COMPONENT_GENERATE_ETB) {
2415 pending_input_buffers++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002416 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d",
Arun Menon906de572013-06-18 17:01:40 -07002417 (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers);
2418 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
2419 } else if (ident == OMX_COMPONENT_GENERATE_EBD) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002420 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p",
Arun Menon906de572013-06-18 17:01:40 -07002421 (OMX_BUFFERHEADERTYPE *)p1);
2422 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2423 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002424 }
Arun Menon906de572013-06-18 17:01:40 -07002425 time_stamp_dts.flush_timestamp();
2426 /*Check if Heap Buffers are to be flushed*/
2427 if (arbitrary_bytes && !(codec_config_flag)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002428 DEBUG_PRINT_LOW("Reset all the variables before flusing");
Arun Menon906de572013-06-18 17:01:40 -07002429 h264_scratch.nFilledLen = 0;
2430 nal_count = 0;
2431 look_ahead_nal = false;
2432 frame_count = 0;
2433 h264_last_au_ts = LLONG_MAX;
2434 h264_last_au_flags = 0;
2435 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
2436 m_demux_entries = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002437 DEBUG_PRINT_LOW("Initialize parser");
Arun Menon906de572013-06-18 17:01:40 -07002438 if (m_frame_parser.mutils) {
2439 m_frame_parser.mutils->initialize_frame_checking_environment();
2440 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002441
Arun Menon906de572013-06-18 17:01:40 -07002442 while (m_input_pending_q.m_size) {
2443 m_input_pending_q.pop_entry(&p1,&p2,&ident);
2444 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1);
2445 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002446
Arun Menon906de572013-06-18 17:01:40 -07002447 if (psource_frame) {
2448 m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame);
2449 psource_frame = NULL;
2450 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002451
Arun Menon906de572013-06-18 17:01:40 -07002452 if (pdest_frame) {
2453 pdest_frame->nFilledLen = 0;
2454 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL,
2455 (unsigned int)NULL);
2456 pdest_frame = NULL;
2457 }
2458 m_frame_parser.flush();
2459 } else if (codec_config_flag) {
2460 DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer "
2461 "is not sent to the driver yet");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002462 }
Arun Menon906de572013-06-18 17:01:40 -07002463 pthread_mutex_unlock(&m_lock);
2464 input_flush_progress = false;
2465 if (!arbitrary_bytes) {
2466 prev_ts = LLONG_MAX;
2467 rst_prev_ts = true;
2468 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002469#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07002470 if (m_debug_timestamp) {
2471 m_timestamp_list.reset_ts_list();
2472 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002473#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002474 DEBUG_PRINT_HIGH("OMX flush i/p Port complete PenBuf(%d)", pending_input_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002475 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002476}
2477
2478
2479/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002480 FUNCTION
2481 omx_vdec::SendCommandEvent
Shalaj Jain273b3e02012-06-22 19:08:03 -07002482
Arun Menon906de572013-06-18 17:01:40 -07002483 DESCRIPTION
2484 Send the event to decoder pipe. This is needed to generate the callbacks
2485 in decoder thread context.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002486
Arun Menon906de572013-06-18 17:01:40 -07002487 PARAMETERS
2488 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002489
Arun Menon906de572013-06-18 17:01:40 -07002490 RETURN VALUE
2491 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002492
Arun Menon906de572013-06-18 17:01:40 -07002493 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002494bool omx_vdec::post_event(unsigned int p1,
Arun Menon906de572013-06-18 17:01:40 -07002495 unsigned int p2,
2496 unsigned int id)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002497{
Arun Menon906de572013-06-18 17:01:40 -07002498 bool bRet = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002499
2500
Arun Menon906de572013-06-18 17:01:40 -07002501 pthread_mutex_lock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002502
Arun Menon906de572013-06-18 17:01:40 -07002503 if (id == m_fill_output_msg ||
2504 id == OMX_COMPONENT_GENERATE_FBD) {
2505 m_ftb_q.insert_entry(p1,p2,id);
2506 } else if (id == OMX_COMPONENT_GENERATE_ETB ||
2507 id == OMX_COMPONENT_GENERATE_EBD ||
2508 id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
2509 m_etb_q.insert_entry(p1,p2,id);
2510 } else {
2511 m_cmd_q.insert_entry(p1,p2,id);
2512 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002513
Arun Menon906de572013-06-18 17:01:40 -07002514 bRet = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002515 DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this);
Arun Menon906de572013-06-18 17:01:40 -07002516 post_message(this, id);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002517
Arun Menon906de572013-06-18 17:01:40 -07002518 pthread_mutex_unlock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002519
Arun Menon906de572013-06-18 17:01:40 -07002520 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002521}
2522
2523OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType)
2524{
Arun Menon906de572013-06-18 17:01:40 -07002525 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2526 if (!profileLevelType)
2527 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002528
Arun Menon906de572013-06-18 17:01:40 -07002529 if (profileLevelType->nPortIndex == 0) {
2530 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
2531 if (profileLevelType->nProfileIndex == 0) {
2532 profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline;
2533 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002534
Arun Menon906de572013-06-18 17:01:40 -07002535 } else if (profileLevelType->nProfileIndex == 1) {
2536 profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain;
2537 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2538 } else if (profileLevelType->nProfileIndex == 2) {
2539 profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh;
2540 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2541 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002542 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu",
Arun Menon906de572013-06-18 17:01:40 -07002543 profileLevelType->nProfileIndex);
2544 eRet = OMX_ErrorNoMore;
2545 }
2546 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) {
2547 if (profileLevelType->nProfileIndex == 0) {
2548 profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline;
2549 profileLevelType->eLevel = OMX_VIDEO_H263Level70;
2550 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002551 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002552 eRet = OMX_ErrorNoMore;
2553 }
2554 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
2555 if (profileLevelType->nProfileIndex == 0) {
2556 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple;
2557 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2558 } else if (profileLevelType->nProfileIndex == 1) {
2559 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple;
2560 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2561 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002562 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002563 eRet = OMX_ErrorNoMore;
2564 }
2565 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
2566 eRet = OMX_ErrorNoMore;
2567 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
2568 if (profileLevelType->nProfileIndex == 0) {
2569 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple;
2570 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2571 } else if (profileLevelType->nProfileIndex == 1) {
2572 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain;
2573 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2574 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002575 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002576 eRet = OMX_ErrorNoMore;
2577 }
2578 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002579 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported ret NoMore for codec: %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07002580 eRet = OMX_ErrorNoMore;
2581 }
2582 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002583 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported should be queries on Input port only %lu", profileLevelType->nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07002584 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002585 }
Arun Menon906de572013-06-18 17:01:40 -07002586 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002587}
2588
2589/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002590 FUNCTION
2591 omx_vdec::GetParameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07002592
Arun Menon906de572013-06-18 17:01:40 -07002593 DESCRIPTION
2594 OMX Get Parameter method implementation
Shalaj Jain273b3e02012-06-22 19:08:03 -07002595
Arun Menon906de572013-06-18 17:01:40 -07002596 PARAMETERS
2597 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002598
Arun Menon906de572013-06-18 17:01:40 -07002599 RETURN VALUE
2600 Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002601
Arun Menon906de572013-06-18 17:01:40 -07002602 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002603OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002604 OMX_IN OMX_INDEXTYPE paramIndex,
2605 OMX_INOUT OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002606{
2607 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2608
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002609 DEBUG_PRINT_LOW("get_parameter:");
Arun Menon906de572013-06-18 17:01:40 -07002610 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002611 DEBUG_PRINT_ERROR("Get Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002612 return OMX_ErrorInvalidState;
2613 }
Arun Menon906de572013-06-18 17:01:40 -07002614 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002615 DEBUG_PRINT_LOW("Get Param in Invalid paramData");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002616 return OMX_ErrorBadParameter;
2617 }
Arun Menon906de572013-06-18 17:01:40 -07002618 switch ((unsigned long)paramIndex) {
2619 case OMX_IndexParamPortDefinition: {
2620 OMX_PARAM_PORTDEFINITIONTYPE *portDefn =
2621 (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002622 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition");
Arun Menon906de572013-06-18 17:01:40 -07002623 eRet = update_portdef(portDefn);
2624 if (eRet == OMX_ErrorNone)
2625 m_port_def = *portDefn;
2626 break;
2627 }
2628 case OMX_IndexParamVideoInit: {
2629 OMX_PORT_PARAM_TYPE *portParamType =
2630 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002631 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002632
Arun Menon906de572013-06-18 17:01:40 -07002633 portParamType->nVersion.nVersion = OMX_SPEC_VERSION;
2634 portParamType->nSize = sizeof(portParamType);
2635 portParamType->nPorts = 2;
2636 portParamType->nStartPortNumber = 0;
2637 break;
2638 }
2639 case OMX_IndexParamVideoPortFormat: {
2640 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
2641 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002642 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002643
Arun Menon906de572013-06-18 17:01:40 -07002644 portFmt->nVersion.nVersion = OMX_SPEC_VERSION;
2645 portFmt->nSize = sizeof(portFmt);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002646
Arun Menon906de572013-06-18 17:01:40 -07002647 if (0 == portFmt->nPortIndex) {
2648 if (0 == portFmt->nIndex) {
2649 portFmt->eColorFormat = OMX_COLOR_FormatUnused;
2650 portFmt->eCompressionFormat = eCompressionFormat;
2651 } else {
2652 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002653 " NoMore compression formats");
Arun Menon906de572013-06-18 17:01:40 -07002654 eRet = OMX_ErrorNoMore;
2655 }
2656 } else if (1 == portFmt->nPortIndex) {
2657 portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002658
Arun Menon906de572013-06-18 17:01:40 -07002659 if (0 == portFmt->nIndex)
2660 portFmt->eColorFormat = (OMX_COLOR_FORMATTYPE)
2661 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
2662 else if (1 == portFmt->nIndex)
2663 portFmt->eColorFormat = OMX_COLOR_FormatYUV420Planar;
2664 else {
2665 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002666 " NoMore Color formats");
Arun Menon906de572013-06-18 17:01:40 -07002667 eRet = OMX_ErrorNoMore;
2668 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002669 DEBUG_PRINT_LOW("returning %d", portFmt->eColorFormat);
Arun Menon906de572013-06-18 17:01:40 -07002670 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002671 DEBUG_PRINT_ERROR("get_parameter: Bad port index %d",
Arun Menon906de572013-06-18 17:01:40 -07002672 (int)portFmt->nPortIndex);
2673 eRet = OMX_ErrorBadPortIndex;
2674 }
2675 break;
2676 }
2677 /*Component should support this port definition*/
2678 case OMX_IndexParamAudioInit: {
2679 OMX_PORT_PARAM_TYPE *audioPortParamType =
2680 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002681 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit");
Arun Menon906de572013-06-18 17:01:40 -07002682 audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
2683 audioPortParamType->nSize = sizeof(audioPortParamType);
2684 audioPortParamType->nPorts = 0;
2685 audioPortParamType->nStartPortNumber = 0;
2686 break;
2687 }
2688 /*Component should support this port definition*/
2689 case OMX_IndexParamImageInit: {
2690 OMX_PORT_PARAM_TYPE *imagePortParamType =
2691 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002692 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit");
Arun Menon906de572013-06-18 17:01:40 -07002693 imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
2694 imagePortParamType->nSize = sizeof(imagePortParamType);
2695 imagePortParamType->nPorts = 0;
2696 imagePortParamType->nStartPortNumber = 0;
2697 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002698
Arun Menon906de572013-06-18 17:01:40 -07002699 }
2700 /*Component should support this port definition*/
2701 case OMX_IndexParamOtherInit: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002702 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x",
Arun Menon906de572013-06-18 17:01:40 -07002703 paramIndex);
2704 eRet =OMX_ErrorUnsupportedIndex;
2705 break;
2706 }
2707 case OMX_IndexParamStandardComponentRole: {
2708 OMX_PARAM_COMPONENTROLETYPE *comp_role;
2709 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
2710 comp_role->nVersion.nVersion = OMX_SPEC_VERSION;
2711 comp_role->nSize = sizeof(*comp_role);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002712
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002713 DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d",
Arun Menon906de572013-06-18 17:01:40 -07002714 paramIndex);
2715 strlcpy((char*)comp_role->cRole,(const char*)m_cRole,
2716 OMX_MAX_STRINGNAME_SIZE);
2717 break;
2718 }
2719 /* Added for parameter test */
2720 case OMX_IndexParamPriorityMgmt: {
Shalaj Jain273b3e02012-06-22 19:08:03 -07002721
Arun Menon906de572013-06-18 17:01:40 -07002722 OMX_PRIORITYMGMTTYPE *priorityMgmType =
2723 (OMX_PRIORITYMGMTTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002724 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt");
Arun Menon906de572013-06-18 17:01:40 -07002725 priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION;
2726 priorityMgmType->nSize = sizeof(priorityMgmType);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002727
Arun Menon906de572013-06-18 17:01:40 -07002728 break;
2729 }
2730 /* Added for parameter test */
2731 case OMX_IndexParamCompBufferSupplier: {
2732 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType =
2733 (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002734 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002735
Arun Menon906de572013-06-18 17:01:40 -07002736 bufferSupplierType->nSize = sizeof(bufferSupplierType);
2737 bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION;
2738 if (0 == bufferSupplierType->nPortIndex)
2739 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2740 else if (1 == bufferSupplierType->nPortIndex)
2741 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2742 else
2743 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002744
2745
Arun Menon906de572013-06-18 17:01:40 -07002746 break;
2747 }
2748 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002749 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x",
Arun Menon906de572013-06-18 17:01:40 -07002750 paramIndex);
2751 break;
2752 }
2753 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002754 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002755 paramIndex);
2756 break;
2757 }
2758 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002759 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002760 paramIndex);
2761 break;
2762 }
2763 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002764 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002765 paramIndex);
2766 break;
2767 }
2768 case OMX_IndexParamVideoProfileLevelQuerySupported: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002769 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07002770 OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType =
2771 (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData;
2772 eRet = get_supported_profile_level_for_1080p(profileLevelType);
2773 break;
2774 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002775#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07002776 case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002777 DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage");
Arun Menon906de572013-06-18 17:01:40 -07002778 GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData;
2779 if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07002780
Arun Menon906de572013-06-18 17:01:40 -07002781 if (secure_mode) {
2782 nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED |
2783 GRALLOC_USAGE_PRIVATE_UNCACHED);
2784 } else {
2785 nativeBuffersUsage->nUsage =
2786 (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP |
2787 GRALLOC_USAGE_PRIVATE_UNCACHED);
2788 }
2789 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002790 DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!");
Arun Menon906de572013-06-18 17:01:40 -07002791 eRet = OMX_ErrorBadParameter;
2792 }
2793 }
2794 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002795#endif
2796
Arun Menon906de572013-06-18 17:01:40 -07002797 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002798 DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07002799 eRet =OMX_ErrorUnsupportedIndex;
2800 }
2801
Shalaj Jain273b3e02012-06-22 19:08:03 -07002802 }
2803
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002804 DEBUG_PRINT_LOW("get_parameter returning WxH(%d x %d) SxSH(%d x %d)",
Arun Menon906de572013-06-18 17:01:40 -07002805 drv_ctx.video_resolution.frame_width,
2806 drv_ctx.video_resolution.frame_height,
2807 drv_ctx.video_resolution.stride,
2808 drv_ctx.video_resolution.scan_lines);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002809
Arun Menon906de572013-06-18 17:01:40 -07002810 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002811}
2812
2813#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
2814OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data)
2815{
2816 DEBUG_PRINT_LOW("Inside use_android_native_buffer");
2817 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2818 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data;
2819
Arun Menon906de572013-06-18 17:01:40 -07002820 if ((params == NULL) ||
2821 (params->nativeBuffer == NULL) ||
2822 (params->nativeBuffer->handle == NULL) ||
2823 !m_enable_android_native_buffers)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002824 return OMX_ErrorBadParameter;
2825 m_use_android_native_buffers = OMX_TRUE;
2826 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
2827 private_handle_t *handle = (private_handle_t *)nBuf->handle;
Arun Menon906de572013-06-18 17:01:40 -07002828 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 -07002829 OMX_U8 *buffer = NULL;
Arun Menon906de572013-06-18 17:01:40 -07002830 if (!secure_mode) {
2831 buffer = (OMX_U8*)mmap(0, handle->size,
Shalaj Jain273b3e02012-06-22 19:08:03 -07002832 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
Arun Menon906de572013-06-18 17:01:40 -07002833 if (buffer == MAP_FAILED) {
2834 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
2835 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002836 }
2837 }
2838 eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer);
2839 } else {
2840 eRet = OMX_ErrorBadParameter;
2841 }
2842 return eRet;
2843}
2844#endif
2845/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002846 FUNCTION
2847 omx_vdec::Setparameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07002848
Arun Menon906de572013-06-18 17:01:40 -07002849 DESCRIPTION
2850 OMX Set Parameter method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002851
Arun Menon906de572013-06-18 17:01:40 -07002852 PARAMETERS
2853 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002854
Arun Menon906de572013-06-18 17:01:40 -07002855 RETURN VALUE
2856 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002857
Arun Menon906de572013-06-18 17:01:40 -07002858 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002859OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002860 OMX_IN OMX_INDEXTYPE paramIndex,
2861 OMX_IN OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002862{
2863 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Praneeth Paladugu226667c2012-09-12 16:42:30 -07002864 int ret=0;
2865 struct v4l2_format fmt;
Arun Menon906de572013-06-18 17:01:40 -07002866 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002867 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002868 return OMX_ErrorInvalidState;
2869 }
Arun Menon906de572013-06-18 17:01:40 -07002870 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002871 DEBUG_PRINT_ERROR("Get Param in Invalid paramData");
Arun Menon906de572013-06-18 17:01:40 -07002872 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002873 }
Arun Menon906de572013-06-18 17:01:40 -07002874 if ((m_state != OMX_StateLoaded) &&
2875 BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) &&
2876 (m_out_bEnabled == OMX_TRUE) &&
2877 BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) &&
2878 (m_inp_bEnabled == OMX_TRUE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002879 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002880 return OMX_ErrorIncorrectStateOperation;
2881 }
Arun Menon906de572013-06-18 17:01:40 -07002882 switch ((unsigned long)paramIndex) {
2883 case OMX_IndexParamPortDefinition: {
2884 OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
2885 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
2886 //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has
2887 //been called.
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002888 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d",
Arun Menon906de572013-06-18 17:01:40 -07002889 (int)portDefn->format.video.nFrameHeight,
2890 (int)portDefn->format.video.nFrameWidth);
2891 if (OMX_DirOutput == portDefn->eDir) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002892 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port");
Arun Menon906de572013-06-18 17:01:40 -07002893 m_display_id = portDefn->format.video.pNativeWindow;
2894 unsigned int buffer_size;
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07002895 DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n",
2896 portDefn->format.video.nFrameWidth,
2897 portDefn->format.video.nFrameHeight);
2898 if (portDefn->format.video.nFrameHeight != 0x0 &&
2899 portDefn->format.video.nFrameWidth != 0x0) {
2900 update_resolution(portDefn->format.video.nFrameWidth,
2901 portDefn->format.video.nFrameHeight,
2902 portDefn->format.video.nFrameWidth,
2903 portDefn->format.video.nFrameHeight);
2904 eRet = is_video_session_supported();
2905 if (eRet)
2906 break;
2907 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2908 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
2909 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
2910 fmt.fmt.pix_mp.pixelformat = capture_capability;
2911 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);
2912 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
2913 if (ret) {
2914 DEBUG_PRINT_ERROR("\n Set Resolution failed");
2915 eRet = OMX_ErrorUnsupportedSetting;
2916 } else
2917 eRet = get_buffer_req(&drv_ctx.op_buf);
2918 }
2919
Arun Menon906de572013-06-18 17:01:40 -07002920 if (!client_buffers.get_buffer_req(buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002921 DEBUG_PRINT_ERROR("Error in getting buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07002922 eRet = OMX_ErrorBadParameter;
2923 } else {
2924 if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount &&
2925 portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) {
2926 drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual;
2927 drv_ctx.op_buf.buffer_size = portDefn->nBufferSize;
2928 drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount;
2929 drv_ctx.extradata_info.size = drv_ctx.extradata_info.count *
2930 drv_ctx.extradata_info.buffer_size;
2931 eRet = set_buffer_req(&drv_ctx.op_buf);
2932 if (eRet == OMX_ErrorNone)
2933 m_port_def = *portDefn;
2934 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002935 DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07002936 drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size,
2937 portDefn->nBufferCountActual, portDefn->nBufferSize);
2938 eRet = OMX_ErrorBadParameter;
2939 }
2940 }
2941 } else if (OMX_DirInput == portDefn->eDir) {
2942 bool port_format_changed = false;
2943 if ((portDefn->format.video.xFramerate >> 16) > 0 &&
2944 (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) {
2945 // Frame rate only should be set if this is a "known value" or to
2946 // activate ts prediction logic (arbitrary mode only) sending input
2947 // timestamps with max value (LLONG_MAX).
2948 DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu",
2949 portDefn->format.video.xFramerate >> 16);
2950 Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator,
2951 drv_ctx.frame_rate.fps_denominator);
2952 if (!drv_ctx.frame_rate.fps_numerator) {
2953 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
2954 drv_ctx.frame_rate.fps_numerator = 30;
2955 }
2956 if (drv_ctx.frame_rate.fps_denominator)
2957 drv_ctx.frame_rate.fps_numerator = (int)
2958 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
2959 drv_ctx.frame_rate.fps_denominator = 1;
2960 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
2961 drv_ctx.frame_rate.fps_numerator;
2962 DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)",
2963 frm_int, drv_ctx.frame_rate.fps_numerator /
2964 (float)drv_ctx.frame_rate.fps_denominator);
2965 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002966 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port");
Arun Menon906de572013-06-18 17:01:40 -07002967 if (drv_ctx.video_resolution.frame_height !=
2968 portDefn->format.video.nFrameHeight ||
2969 drv_ctx.video_resolution.frame_width !=
2970 portDefn->format.video.nFrameWidth) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002971 DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)",
Arun Menon906de572013-06-18 17:01:40 -07002972 portDefn->format.video.nFrameWidth,
2973 portDefn->format.video.nFrameHeight);
2974 port_format_changed = true;
2975 if (portDefn->format.video.nFrameHeight != 0x0 &&
2976 portDefn->format.video.nFrameWidth != 0x0) {
2977 update_resolution(portDefn->format.video.nFrameWidth,
2978 portDefn->format.video.nFrameHeight,
2979 portDefn->format.video.nFrameWidth,
2980 portDefn->format.video.nFrameHeight);
2981 eRet = is_video_session_supported();
2982 if (eRet)
2983 break;
2984 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
2985 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
2986 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
2987 fmt.fmt.pix_mp.pixelformat = output_capability;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002988 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 -07002989 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
2990 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002991 DEBUG_PRINT_ERROR("Set Resolution failed");
Arun Menon906de572013-06-18 17:01:40 -07002992 eRet = OMX_ErrorUnsupportedSetting;
2993 } else
2994 eRet = get_buffer_req(&drv_ctx.op_buf);
2995 }
2996 }
2997 if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount
2998 || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) {
2999 port_format_changed = true;
3000 vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf;
3001 drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual;
3002 drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) &
3003 (~(buffer_prop->alignment - 1));
3004 eRet = set_buffer_req(buffer_prop);
3005 }
3006 if (false == port_format_changed) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003007 DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003008 drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size,
3009 portDefn->nBufferCountActual, portDefn->nBufferSize);
3010 eRet = OMX_ErrorBadParameter;
3011 }
3012 } else if (portDefn->eDir == OMX_DirMax) {
3013 DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d",
3014 (int)portDefn->nPortIndex);
3015 eRet = OMX_ErrorBadPortIndex;
3016 }
3017 }
3018 break;
3019 case OMX_IndexParamVideoPortFormat: {
3020 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
3021 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
3022 int ret=0;
3023 struct v4l2_format fmt;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003024 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d",
Arun Menon906de572013-06-18 17:01:40 -07003025 portFmt->eColorFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003026
Arun Menon906de572013-06-18 17:01:40 -07003027 if (1 == portFmt->nPortIndex) {
3028 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3029 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3030 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3031 fmt.fmt.pix_mp.pixelformat = capture_capability;
3032 enum vdec_output_fromat op_format;
3033 if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE)
3034 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) ||
3035 (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar))
3036 op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12;
3037 else if (portFmt->eColorFormat ==
3038 (OMX_COLOR_FORMATTYPE)
3039 QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka)
3040 op_format = VDEC_YUV_FORMAT_TILE_4x2;
3041 else
3042 eRet = OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003043
Arun Menon906de572013-06-18 17:01:40 -07003044 if (eRet == OMX_ErrorNone) {
3045 drv_ctx.output_format = op_format;
3046 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3047 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003048 DEBUG_PRINT_ERROR("Set output format failed");
Arun Menon906de572013-06-18 17:01:40 -07003049 eRet = OMX_ErrorUnsupportedSetting;
3050 /*TODO: How to handle this case */
3051 } else {
3052 eRet = get_buffer_req(&drv_ctx.op_buf);
3053 }
3054 }
3055 if (eRet == OMX_ErrorNone) {
3056 if (!client_buffers.set_color_format(portFmt->eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003057 DEBUG_PRINT_ERROR("Set color format failed");
Arun Menon906de572013-06-18 17:01:40 -07003058 eRet = OMX_ErrorBadParameter;
3059 }
3060 }
3061 }
3062 }
3063 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003064
Arun Menon906de572013-06-18 17:01:40 -07003065 case OMX_QcomIndexPortDefn: {
3066 OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt =
3067 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003068 DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu",
Arun Menon906de572013-06-18 17:01:40 -07003069 portFmt->nFramePackingFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003070
Arun Menon906de572013-06-18 17:01:40 -07003071 /* Input port */
3072 if (portFmt->nPortIndex == 0) {
3073 if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) {
3074 if (secure_mode) {
3075 arbitrary_bytes = false;
3076 DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session");
3077 eRet = OMX_ErrorUnsupportedSetting;
3078 } else {
3079 arbitrary_bytes = true;
3080 }
3081 } else if (portFmt->nFramePackingFormat ==
3082 OMX_QCOM_FramePacking_OnlyOneCompleteFrame) {
3083 arbitrary_bytes = false;
3084 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003085 DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu",
Arun Menon906de572013-06-18 17:01:40 -07003086 portFmt->nFramePackingFormat);
3087 eRet = OMX_ErrorUnsupportedSetting;
3088 }
3089 } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003090 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003091 if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid &&
3092 portFmt->nMemRegion < OMX_QCOM_MemRegionMax) &&
3093 portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) {
3094 m_out_mem_region_smi = OMX_TRUE;
3095 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003096 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003097 m_use_output_pmem = OMX_TRUE;
3098 }
3099 }
3100 }
3101 }
3102 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003103
Arun Menon906de572013-06-18 17:01:40 -07003104 case OMX_IndexParamStandardComponentRole: {
3105 OMX_PARAM_COMPONENTROLETYPE *comp_role;
3106 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003107 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s",
Arun Menon906de572013-06-18 17:01:40 -07003108 comp_role->cRole);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003109
Arun Menon906de572013-06-18 17:01:40 -07003110 if ((m_state == OMX_StateLoaded)&&
3111 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
3112 DEBUG_PRINT_LOW("Set Parameter called in valid state");
3113 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003114 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003115 return OMX_ErrorIncorrectStateOperation;
3116 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003117
Arun Menon906de572013-06-18 17:01:40 -07003118 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3119 if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3120 strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
3121 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003122 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003123 eRet =OMX_ErrorUnsupportedSetting;
3124 }
3125 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3126 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3127 strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
3128 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003129 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003130 eRet = OMX_ErrorUnsupportedSetting;
3131 }
3132 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3133 if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3134 strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
3135 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003136 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003137 eRet =OMX_ErrorUnsupportedSetting;
3138 }
3139 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3140 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3141 strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
3142 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003143 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003144 eRet = OMX_ErrorUnsupportedSetting;
3145 }
3146 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
3147 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE))
3148 ) {
3149 if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) {
3150 strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
3151 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003152 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003153 eRet =OMX_ErrorUnsupportedSetting;
3154 }
3155 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
3156 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
3157 ) {
3158 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) {
3159 strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
3160 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003161 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003162 eRet =OMX_ErrorUnsupportedSetting;
3163 }
3164 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
3165 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) ||
3166 (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) {
3167 strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
3168 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003169 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003170 eRet = OMX_ErrorUnsupportedSetting;
3171 }
3172 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003173 DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07003174 eRet = OMX_ErrorInvalidComponentName;
3175 }
3176 break;
3177 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003178
Arun Menon906de572013-06-18 17:01:40 -07003179 case OMX_IndexParamPriorityMgmt: {
3180 if (m_state != OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003181 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003182 return OMX_ErrorIncorrectStateOperation;
3183 }
3184 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003185 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu",
Arun Menon906de572013-06-18 17:01:40 -07003186 priorityMgmtype->nGroupID);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003187
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003188 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu",
Arun Menon906de572013-06-18 17:01:40 -07003189 priorityMgmtype->nGroupPriority);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003190
Arun Menon906de572013-06-18 17:01:40 -07003191 m_priority_mgm.nGroupID = priorityMgmtype->nGroupID;
3192 m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003193
Arun Menon906de572013-06-18 17:01:40 -07003194 break;
3195 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003196
Arun Menon906de572013-06-18 17:01:40 -07003197 case OMX_IndexParamCompBufferSupplier: {
3198 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003199 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d",
Arun Menon906de572013-06-18 17:01:40 -07003200 bufferSupplierType->eBufferSupplier);
3201 if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
3202 m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003203
Arun Menon906de572013-06-18 17:01:40 -07003204 else
Shalaj Jain273b3e02012-06-22 19:08:03 -07003205
Arun Menon906de572013-06-18 17:01:40 -07003206 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003207
Arun Menon906de572013-06-18 17:01:40 -07003208 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003209
Arun Menon906de572013-06-18 17:01:40 -07003210 }
3211 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003212 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d",
Arun Menon906de572013-06-18 17:01:40 -07003213 paramIndex);
3214 break;
3215 }
3216 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003217 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d",
Arun Menon906de572013-06-18 17:01:40 -07003218 paramIndex);
3219 break;
3220 }
3221 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003222 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d",
Arun Menon906de572013-06-18 17:01:40 -07003223 paramIndex);
3224 break;
3225 }
3226 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003227 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d",
Arun Menon906de572013-06-18 17:01:40 -07003228 paramIndex);
3229 break;
3230 }
3231 case OMX_QcomIndexParamVideoDecoderPictureOrder: {
3232 QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder =
3233 (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData;
3234 struct v4l2_control control;
3235 int pic_order,rc=0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003236 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d",
Arun Menon906de572013-06-18 17:01:40 -07003237 pictureOrder->eOutputPictureOrder);
3238 if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) {
3239 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
3240 } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) {
3241 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3242 time_stamp_dts.set_timestamp_reorder_mode(false);
3243 } else
3244 eRet = OMX_ErrorBadParameter;
3245 if (eRet == OMX_ErrorNone) {
3246 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3247 control.value = pic_order;
3248 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3249 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003250 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003251 eRet = OMX_ErrorUnsupportedSetting;
3252 }
3253 }
3254 break;
3255 }
3256 case OMX_QcomIndexParamConcealMBMapExtraData:
3257 if (!secure_mode)
3258 eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false,
3259 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3260 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003261 DEBUG_PRINT_ERROR("secure mode setting not supported");
Arun Menon906de572013-06-18 17:01:40 -07003262 eRet = OMX_ErrorUnsupportedSetting;
3263 }
3264 break;
3265 case OMX_QcomIndexParamFrameInfoExtraData: {
3266 if (!secure_mode)
3267 eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false,
3268 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3269 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003270 DEBUG_PRINT_ERROR("secure mode setting not supported");
Arun Menon906de572013-06-18 17:01:40 -07003271 eRet = OMX_ErrorUnsupportedSetting;
3272 }
3273 break;
3274 }
3275 case OMX_QcomIndexParamInterlaceExtraData:
3276 if (!secure_mode)
3277 eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false,
3278 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3279 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003280 DEBUG_PRINT_ERROR("secure mode setting not supported");
Arun Menon906de572013-06-18 17:01:40 -07003281 eRet = OMX_ErrorUnsupportedSetting;
3282 }
3283 break;
3284 case OMX_QcomIndexParamH264TimeInfo:
3285 if (!secure_mode)
3286 eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false,
3287 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3288 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003289 DEBUG_PRINT_ERROR("secure mode setting not supported");
Arun Menon906de572013-06-18 17:01:40 -07003290 eRet = OMX_ErrorUnsupportedSetting;
3291 }
3292 break;
3293 case OMX_QcomIndexParamVideoDivx: {
3294 QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData;
3295 }
3296 break;
3297 case OMX_QcomIndexPlatformPvt: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003298 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003299 OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData;
3300 if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
3301 DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type);
3302 eRet = OMX_ErrorUnsupportedSetting;
3303 } else {
3304 m_out_pvt_entry_pmem = OMX_TRUE;
3305 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003306 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003307 m_use_output_pmem = OMX_TRUE;
3308 }
3309 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003310
Arun Menon906de572013-06-18 17:01:40 -07003311 }
3312 break;
3313 case OMX_QcomIndexParamVideoSyncFrameDecodingMode: {
3314 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode");
3315 DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode");
3316 struct v4l2_control control;
3317 int rc;
3318 drv_ctx.idr_only_decoding = 1;
3319 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3320 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3321 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3322 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003323 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003324 eRet = OMX_ErrorUnsupportedSetting;
3325 } else {
3326 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE;
3327 control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE;
3328 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3329 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003330 DEBUG_PRINT_ERROR("Sync frame setting failed");
Arun Menon906de572013-06-18 17:01:40 -07003331 eRet = OMX_ErrorUnsupportedSetting;
3332 }
3333 /*Setting sync frame decoding on driver might change buffer
3334 * requirements so update them here*/
3335 if (get_buffer_req(&drv_ctx.ip_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003336 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer i/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003337 eRet = OMX_ErrorUnsupportedSetting;
3338 }
3339 if (get_buffer_req(&drv_ctx.op_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003340 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer o/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003341 eRet = OMX_ErrorUnsupportedSetting;
3342 }
3343 }
3344 }
3345 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003346
Arun Menon906de572013-06-18 17:01:40 -07003347 case OMX_QcomIndexParamIndexExtraDataType: {
3348 if (!secure_mode) {
3349 QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData;
3350 if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) &&
3351 (extradataIndexType->bEnabled == OMX_TRUE) &&
3352 (extradataIndexType->nPortIndex == 1)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003353 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming");
Arun Menon906de572013-06-18 17:01:40 -07003354 eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled);
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07003355
Arun Menon906de572013-06-18 17:01:40 -07003356 }
3357 }
3358 }
3359 break;
3360 case OMX_QcomIndexParamEnableSmoothStreaming: {
Arun Menonc821d8a2013-06-15 10:03:29 -07003361#ifndef SMOOTH_STREAMING_DISABLED
Arun Menon906de572013-06-18 17:01:40 -07003362 struct v4l2_control control;
3363 struct v4l2_format fmt;
3364 control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER;
3365 control.value = 1;
3366 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3367 if (rc < 0) {
3368 DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver.");
3369 eRet = OMX_ErrorHardware;
3370 }
Arun Menonbc0922f2013-06-24 13:02:15 -07003371#else
Arun Menon906de572013-06-18 17:01:40 -07003372 eRet = OMX_ErrorUnsupportedSetting;
Arun Menonc821d8a2013-06-15 10:03:29 -07003373#endif
Arun Menon906de572013-06-18 17:01:40 -07003374 }
3375 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003376#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07003377 /* Need to allow following two set_parameters even in Idle
3378 * state. This is ANDROID architecture which is not in sync
3379 * with openmax standard. */
3380 case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: {
3381 EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData;
3382 if (enableNativeBuffers) {
3383 m_enable_android_native_buffers = enableNativeBuffers->enable;
3384 }
3385 }
3386 break;
3387 case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: {
3388 eRet = use_android_native_buffer(hComp, paramData);
3389 }
3390 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003391#endif
Arun Menon906de572013-06-18 17:01:40 -07003392 case OMX_QcomIndexParamEnableTimeStampReorder: {
3393 QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData;
3394 if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) {
3395 if (reorder->bEnable == OMX_TRUE) {
3396 frm_int =0;
3397 time_stamp_dts.set_timestamp_reorder_mode(true);
3398 } else
3399 time_stamp_dts.set_timestamp_reorder_mode(false);
3400 } else {
3401 time_stamp_dts.set_timestamp_reorder_mode(false);
3402 if (reorder->bEnable == OMX_TRUE) {
3403 eRet = OMX_ErrorUnsupportedSetting;
3404 }
3405 }
3406 }
3407 break;
3408 case OMX_IndexParamVideoProfileLevelCurrent: {
3409 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam =
3410 (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
3411 if (pParam) {
3412 m_profile_lvl.eProfile = pParam->eProfile;
3413 m_profile_lvl.eLevel = pParam->eLevel;
3414 }
3415 break;
Arun Menon888aa852013-05-30 11:24:42 -07003416
Arun Menon906de572013-06-18 17:01:40 -07003417 }
Arun Menone5652482013-08-04 13:33:05 -07003418 case OMX_QcomIndexParamVideoMetaBufferMode:
3419 {
3420 StoreMetaDataInBuffersParams *metabuffer =
3421 (StoreMetaDataInBuffersParams *)paramData;
3422 if (!metabuffer) {
3423 DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer);
3424 eRet = OMX_ErrorBadParameter;
3425 break;
3426 }
3427 if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
3428 //set property dynamic buffer mode to driver.
3429 struct v4l2_control control;
3430 struct v4l2_format fmt;
3431 control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT;
3432 if (metabuffer->bStoreMetaData == true) {
3433 control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC;
3434 } else {
3435 control.value = V4L2_MPEG_VIDC_VIDEO_STATIC;
3436 }
3437 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3438 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003439 DEBUG_PRINT_HIGH("%s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003440 (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic");
Arun Menonbdb80b02013-08-12 17:45:54 -07003441 dynamic_buf_mode = metabuffer->bStoreMetaData;
Arun Menone5652482013-08-04 13:33:05 -07003442 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003443 DEBUG_PRINT_ERROR("Failed to %s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003444 (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic");
3445 eRet = OMX_ErrorUnsupportedSetting;
3446 }
3447 } else {
3448 DEBUG_PRINT_ERROR(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003449 "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %d",
Arun Menone5652482013-08-04 13:33:05 -07003450 metabuffer->nPortIndex);
3451 eRet = OMX_ErrorUnsupportedSetting;
3452 }
3453 break;
3454 }
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003455 case OMX_QcomIndexParamVideoDownScalar: {
3456 QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData;
3457 struct v4l2_control control;
3458 int rc;
3459 if (pParam) {
3460 is_down_scalar_enabled = pParam->bEnable;
3461 if (is_down_scalar_enabled) {
3462 control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE;
3463 control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY;
3464 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n",
3465 pParam->bEnable);
3466 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3467 if (rc < 0) {
3468 DEBUG_PRINT_ERROR("Failed to set down scalar on driver.");
3469 eRet = OMX_ErrorUnsupportedSetting;
3470 }
3471 control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO;
3472 control.value = 1;
3473 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3474 if (rc < 0) {
3475 DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver.");
3476 eRet = OMX_ErrorUnsupportedSetting;
3477 }
3478 }
3479 }
3480 break;
3481 }
Arun Menon906de572013-06-18 17:01:40 -07003482 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003483 DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003484 eRet = OMX_ErrorUnsupportedIndex;
3485 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003486 }
Arun Menon906de572013-06-18 17:01:40 -07003487 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003488}
3489
3490/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003491 FUNCTION
3492 omx_vdec::GetConfig
Shalaj Jain273b3e02012-06-22 19:08:03 -07003493
Arun Menon906de572013-06-18 17:01:40 -07003494 DESCRIPTION
3495 OMX Get Config Method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003496
Arun Menon906de572013-06-18 17:01:40 -07003497 PARAMETERS
3498 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003499
Arun Menon906de572013-06-18 17:01:40 -07003500 RETURN VALUE
3501 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003502
Arun Menon906de572013-06-18 17:01:40 -07003503 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003504OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003505 OMX_IN OMX_INDEXTYPE configIndex,
3506 OMX_INOUT OMX_PTR configData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003507{
Arun Menon906de572013-06-18 17:01:40 -07003508 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003509
Arun Menon906de572013-06-18 17:01:40 -07003510 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003511 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003512 return OMX_ErrorInvalidState;
3513 }
Arun Menon906de572013-06-18 17:01:40 -07003514
3515 switch ((unsigned long)configIndex) {
3516 case OMX_QcomIndexConfigInterlaced: {
3517 OMX_QCOM_CONFIG_INTERLACETYPE *configFmt =
3518 (OMX_QCOM_CONFIG_INTERLACETYPE *) configData;
3519 if (configFmt->nPortIndex == 1) {
3520 if (configFmt->nIndex == 0) {
3521 configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive;
3522 } else if (configFmt->nIndex == 1) {
3523 configFmt->eInterlaceType =
3524 OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
3525 } else if (configFmt->nIndex == 2) {
3526 configFmt->eInterlaceType =
3527 OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
3528 } else {
3529 DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003530 " NoMore Interlaced formats");
Arun Menon906de572013-06-18 17:01:40 -07003531 eRet = OMX_ErrorNoMore;
3532 }
3533
3534 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003535 DEBUG_PRINT_ERROR("get_config: Bad port index %d queried on only o/p port",
Arun Menon906de572013-06-18 17:01:40 -07003536 (int)configFmt->nPortIndex);
3537 eRet = OMX_ErrorBadPortIndex;
3538 }
3539 break;
3540 }
3541 case OMX_QcomIndexQueryNumberOfVideoDecInstance: {
3542 QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances =
3543 (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData;
3544 decoderinstances->nNumOfInstances = 16;
3545 /*TODO: How to handle this case */
3546 break;
3547 }
3548 case OMX_QcomIndexConfigVideoFramePackingArrangement: {
3549 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
3550 OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
3551 (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
3552 h264_parser->get_frame_pack_data(configFmt);
3553 } else {
3554 DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs");
3555 }
3556 break;
3557 }
3558 case OMX_IndexConfigCommonOutputCrop: {
3559 OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData;
3560 memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE));
3561 break;
3562 }
3563 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003564 DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex);
Arun Menon906de572013-06-18 17:01:40 -07003565 eRet = OMX_ErrorBadParameter;
3566 }
3567
Shalaj Jain273b3e02012-06-22 19:08:03 -07003568 }
Arun Menon906de572013-06-18 17:01:40 -07003569
3570 return eRet;
3571}
3572
3573/* ======================================================================
3574 FUNCTION
3575 omx_vdec::SetConfig
3576
3577 DESCRIPTION
3578 OMX Set Config method implementation
3579
3580 PARAMETERS
3581 <TBD>.
3582
3583 RETURN VALUE
3584 OMX Error None if successful.
3585 ========================================================================== */
3586OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp,
3587 OMX_IN OMX_INDEXTYPE configIndex,
3588 OMX_IN OMX_PTR configData)
3589{
3590 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003591 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003592 return OMX_ErrorInvalidState;
3593 }
3594
3595 OMX_ERRORTYPE ret = OMX_ErrorNone;
3596 OMX_VIDEO_CONFIG_NALSIZE *pNal;
3597
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003598 DEBUG_PRINT_LOW("Set Config Called");
Arun Menon906de572013-06-18 17:01:40 -07003599
3600 if (configIndex == (OMX_INDEXTYPE)OMX_IndexVendorVideoExtraData) {
3601 OMX_VENDOR_EXTRADATATYPE *config = (OMX_VENDOR_EXTRADATATYPE *) configData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003602 DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData called");
Arun Menon906de572013-06-18 17:01:40 -07003603 if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc")) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003604 DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData AVC");
Arun Menon906de572013-06-18 17:01:40 -07003605 OMX_U32 extra_size;
3606 // Parsing done here for the AVC atom is definitely not generic
3607 // Currently this piece of code is working, but certainly
3608 // not tested with all .mp4 files.
3609 // Incase of failure, we might need to revisit this
3610 // for a generic piece of code.
3611
3612 // Retrieve size of NAL length field
3613 // byte #4 contains the size of NAL lenght field
3614 nal_length = (config->pData[4] & 0x03) + 1;
3615
3616 extra_size = 0;
3617 if (nal_length > 2) {
3618 /* Presently we assume that only one SPS and one PPS in AvC1 Atom */
3619 extra_size = (nal_length - 2) * 2;
3620 }
3621
3622 // SPS starts from byte #6
3623 OMX_U8 *pSrcBuf = (OMX_U8 *) (&config->pData[6]);
3624 OMX_U8 *pDestBuf;
3625 m_vendor_config.nPortIndex = config->nPortIndex;
3626
3627 // minus 6 --> SPS starts from byte #6
3628 // minus 1 --> picture param set byte to be ignored from avcatom
3629 m_vendor_config.nDataSize = config->nDataSize - 6 - 1 + extra_size;
3630 m_vendor_config.pData = (OMX_U8 *) malloc(m_vendor_config.nDataSize);
3631 OMX_U32 len;
3632 OMX_U8 index = 0;
3633 // case where SPS+PPS is sent as part of set_config
3634 pDestBuf = m_vendor_config.pData;
3635
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003636 DEBUG_PRINT_LOW("Rxd SPS+PPS nPortIndex[%lu] len[%lu] data[%p]",
Arun Menon906de572013-06-18 17:01:40 -07003637 m_vendor_config.nPortIndex,
3638 m_vendor_config.nDataSize,
3639 m_vendor_config.pData);
3640 while (index < 2) {
3641 uint8 *psize;
3642 len = *pSrcBuf;
3643 len = len << 8;
3644 len |= *(pSrcBuf + 1);
3645 psize = (uint8 *) & len;
3646 memcpy(pDestBuf + nal_length, pSrcBuf + 2,len);
3647 for (unsigned int i = 0; i < nal_length; i++) {
3648 pDestBuf[i] = psize[nal_length - 1 - i];
3649 }
3650 //memcpy(pDestBuf,pSrcBuf,(len+2));
3651 pDestBuf += len + nal_length;
3652 pSrcBuf += len + 2;
3653 index++;
3654 pSrcBuf++; // skip picture param set
3655 len = 0;
3656 }
3657 } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4") ||
3658 !strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2")) {
3659 m_vendor_config.nPortIndex = config->nPortIndex;
3660 m_vendor_config.nDataSize = config->nDataSize;
3661 m_vendor_config.pData = (OMX_U8 *) malloc((config->nDataSize));
3662 memcpy(m_vendor_config.pData, config->pData,config->nDataSize);
3663 } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1")) {
3664 if (m_vendor_config.pData) {
3665 free(m_vendor_config.pData);
3666 m_vendor_config.pData = NULL;
3667 m_vendor_config.nDataSize = 0;
3668 }
3669
3670 if (((*((OMX_U32 *) config->pData)) &
3671 VC1_SP_MP_START_CODE_MASK) ==
3672 VC1_SP_MP_START_CODE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003673 DEBUG_PRINT_LOW("set_config - VC1 simple/main profile");
Arun Menon906de572013-06-18 17:01:40 -07003674 m_vendor_config.nPortIndex = config->nPortIndex;
3675 m_vendor_config.nDataSize = config->nDataSize;
3676 m_vendor_config.pData =
3677 (OMX_U8 *) malloc(config->nDataSize);
3678 memcpy(m_vendor_config.pData, config->pData,
3679 config->nDataSize);
3680 m_vc1_profile = VC1_SP_MP_RCV;
3681 } else if (*((OMX_U32 *) config->pData) == VC1_AP_SEQ_START_CODE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003682 DEBUG_PRINT_LOW("set_config - VC1 Advance profile");
Arun Menon906de572013-06-18 17:01:40 -07003683 m_vendor_config.nPortIndex = config->nPortIndex;
3684 m_vendor_config.nDataSize = config->nDataSize;
3685 m_vendor_config.pData =
3686 (OMX_U8 *) malloc((config->nDataSize));
3687 memcpy(m_vendor_config.pData, config->pData,
3688 config->nDataSize);
3689 m_vc1_profile = VC1_AP;
3690 } else if ((config->nDataSize == VC1_STRUCT_C_LEN)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003691 DEBUG_PRINT_LOW("set_config - VC1 Simple/Main profile struct C only");
Arun Menon906de572013-06-18 17:01:40 -07003692 m_vendor_config.nPortIndex = config->nPortIndex;
3693 m_vendor_config.nDataSize = config->nDataSize;
3694 m_vendor_config.pData = (OMX_U8*)malloc(config->nDataSize);
3695 memcpy(m_vendor_config.pData,config->pData,config->nDataSize);
3696 m_vc1_profile = VC1_SP_MP_RCV;
3697 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003698 DEBUG_PRINT_LOW("set_config - Error: Unknown VC1 profile");
Arun Menon906de572013-06-18 17:01:40 -07003699 }
3700 }
3701 return ret;
3702 } else if (configIndex == OMX_IndexConfigVideoNalSize) {
3703 struct v4l2_control temp;
3704 temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT;
3705
3706 pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData);
3707 switch (pNal->nNaluBytes) {
3708 case 0:
3709 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES;
3710 break;
3711 case 2:
3712 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH;
3713 break;
3714 case 4:
3715 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH;
3716 break;
3717 default:
3718 return OMX_ErrorUnsupportedSetting;
3719 }
3720
3721 if (!arbitrary_bytes) {
3722 /* In arbitrary bytes mode, the assembler strips out nal size and replaces
3723 * with start code, so only need to notify driver in frame by frame mode */
3724 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) {
3725 DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT");
3726 return OMX_ErrorHardware;
3727 }
3728 }
3729
3730 nal_length = pNal->nNaluBytes;
3731 m_frame_parser.init_nal_length(nal_length);
3732
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003733 DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length);
Arun Menon906de572013-06-18 17:01:40 -07003734 return ret;
Surajit Podderd2644d52013-08-28 17:59:06 +05303735 } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) {
Arun Menon906de572013-06-18 17:01:40 -07003736 OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData;
Surajit Podderd2644d52013-08-28 17:59:06 +05303737 DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps);
Arun Menon906de572013-06-18 17:01:40 -07003738
3739 if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) {
3740 if (config->bEnabled) {
3741 if ((config->nFps >> 16) > 0) {
Surajit Podderd2644d52013-08-28 17:59:06 +05303742 DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu",
Arun Menon906de572013-06-18 17:01:40 -07003743 config->nFps >> 16);
3744 Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator,
3745 drv_ctx.frame_rate.fps_denominator);
3746
3747 if (!drv_ctx.frame_rate.fps_numerator) {
3748 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
3749 drv_ctx.frame_rate.fps_numerator = 30;
3750 }
3751
3752 if (drv_ctx.frame_rate.fps_denominator) {
3753 drv_ctx.frame_rate.fps_numerator = (int)
3754 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
3755 }
3756
3757 drv_ctx.frame_rate.fps_denominator = 1;
3758 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
3759 drv_ctx.frame_rate.fps_numerator;
3760
3761 struct v4l2_outputparm oparm;
3762 /*XXX: we're providing timing info as seconds per frame rather than frames
3763 * per second.*/
3764 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
3765 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
3766
3767 struct v4l2_streamparm sparm;
3768 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
3769 sparm.parm.output = oparm;
3770 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
3771 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
3772 performance might be affected");
3773 ret = OMX_ErrorHardware;
3774 }
3775 client_set_fps = true;
3776 } else {
3777 DEBUG_PRINT_ERROR("Frame rate not supported.");
3778 ret = OMX_ErrorUnsupportedSetting;
3779 }
3780 } else {
3781 DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate");
3782 client_set_fps = false;
3783 }
3784 } else {
3785 DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d",
3786 (int)config->nPortIndex);
3787 ret = OMX_ErrorBadPortIndex;
3788 }
3789
3790 return ret;
3791 }
3792
3793 return OMX_ErrorNotImplemented;
3794}
3795
3796/* ======================================================================
3797 FUNCTION
3798 omx_vdec::GetExtensionIndex
3799
3800 DESCRIPTION
3801 OMX GetExtensionIndex method implementaion. <TBD>
3802
3803 PARAMETERS
3804 <TBD>.
3805
3806 RETURN VALUE
3807 OMX Error None if everything successful.
3808
3809 ========================================================================== */
3810OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp,
3811 OMX_IN OMX_STRING paramName,
3812 OMX_OUT OMX_INDEXTYPE* indexType)
3813{
3814 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003815 DEBUG_PRINT_ERROR("Get Extension Index in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003816 return OMX_ErrorInvalidState;
3817 } else if (!strncmp(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode",sizeof("OMX.QCOM.index.param.video.SyncFrameDecodingMode") - 1)) {
3818 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode;
3819 } else if (!strncmp(paramName, "OMX.QCOM.index.param.IndexExtraData",sizeof("OMX.QCOM.index.param.IndexExtraData") - 1)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07003820 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType;
3821 }
3822#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07003823 else if (!strncmp(paramName,"OMX.google.android.index.enableAndroidNativeBuffers", sizeof("OMX.google.android.index.enableAndroidNativeBuffers") - 1)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07003824 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers;
Arun Menon906de572013-06-18 17:01:40 -07003825 } else if (!strncmp(paramName,"OMX.google.android.index.useAndroidNativeBuffer2", sizeof("OMX.google.android.index.enableAndroidNativeBuffer2") - 1)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07003826 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2;
Arun Menon906de572013-06-18 17:01:40 -07003827 } else if (!strncmp(paramName,"OMX.google.android.index.useAndroidNativeBuffer", sizeof("OMX.google.android.index.enableAndroidNativeBuffer") - 1)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003828 DEBUG_PRINT_ERROR("Extension: %s is supported", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003829 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer;
Arun Menon906de572013-06-18 17:01:40 -07003830 } else if (!strncmp(paramName,"OMX.google.android.index.getAndroidNativeBufferUsage", sizeof("OMX.google.android.index.getAndroidNativeBufferUsage") - 1)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07003831 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage;
3832 }
3833#endif
Arun Menone5652482013-08-04 13:33:05 -07003834 else if (!strncmp(paramName, "OMX.google.android.index.storeMetaDataInBuffers", sizeof("OMX.google.android.index.storeMetaDataInBuffers") - 1)) {
3835 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode;
3836 }
Arun Menon906de572013-06-18 17:01:40 -07003837 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003838 DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003839 return OMX_ErrorNotImplemented;
3840 }
3841 return OMX_ErrorNone;
3842}
3843
3844/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003845 FUNCTION
3846 omx_vdec::GetState
Shalaj Jain273b3e02012-06-22 19:08:03 -07003847
Arun Menon906de572013-06-18 17:01:40 -07003848 DESCRIPTION
3849 Returns the state information back to the caller.<TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07003850
Arun Menon906de572013-06-18 17:01:40 -07003851 PARAMETERS
3852 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003853
Arun Menon906de572013-06-18 17:01:40 -07003854 RETURN VALUE
3855 Error None if everything is successful.
3856 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003857OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003858 OMX_OUT OMX_STATETYPE* state)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003859{
Arun Menon906de572013-06-18 17:01:40 -07003860 *state = m_state;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003861 DEBUG_PRINT_LOW("get_state: Returning the state %d",*state);
Arun Menon906de572013-06-18 17:01:40 -07003862 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003863}
3864
3865/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003866 FUNCTION
3867 omx_vdec::ComponentTunnelRequest
Shalaj Jain273b3e02012-06-22 19:08:03 -07003868
Arun Menon906de572013-06-18 17:01:40 -07003869 DESCRIPTION
3870 OMX Component Tunnel Request method implementation. <TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07003871
Arun Menon906de572013-06-18 17:01:40 -07003872 PARAMETERS
3873 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003874
Arun Menon906de572013-06-18 17:01:40 -07003875 RETURN VALUE
3876 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003877
Arun Menon906de572013-06-18 17:01:40 -07003878 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003879OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003880 OMX_IN OMX_U32 port,
3881 OMX_IN OMX_HANDLETYPE peerComponent,
3882 OMX_IN OMX_U32 peerPort,
3883 OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003884{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003885 DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented");
Arun Menon906de572013-06-18 17:01:40 -07003886 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003887}
3888
3889/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003890 FUNCTION
3891 omx_vdec::UseOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07003892
Arun Menon906de572013-06-18 17:01:40 -07003893 DESCRIPTION
3894 Helper function for Use buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07003895
Arun Menon906de572013-06-18 17:01:40 -07003896 PARAMETERS
3897 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003898
Arun Menon906de572013-06-18 17:01:40 -07003899 RETURN VALUE
3900 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07003901
Arun Menon906de572013-06-18 17:01:40 -07003902 ========================================================================== */
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07003903OMX_ERRORTYPE omx_vdec::allocate_extradata()
3904{
3905#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07003906 if (drv_ctx.extradata_info.buffer_size) {
3907 if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) {
3908 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
3909 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
3910 free_ion_memory(&drv_ctx.extradata_info.ion);
3911 }
3912 drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095);
3913 drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory(
3914 drv_ctx.extradata_info.size, 4096,
3915 &drv_ctx.extradata_info.ion.ion_alloc_data,
3916 &drv_ctx.extradata_info.ion.fd_ion_data, 0);
3917 if (drv_ctx.extradata_info.ion.ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003918 DEBUG_PRINT_ERROR("Failed to alloc extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07003919 return OMX_ErrorInsufficientResources;
3920 }
3921 drv_ctx.extradata_info.uaddr = (char *)mmap(NULL,
3922 drv_ctx.extradata_info.size,
3923 PROT_READ|PROT_WRITE, MAP_SHARED,
3924 drv_ctx.extradata_info.ion.fd_ion_data.fd , 0);
3925 if (drv_ctx.extradata_info.uaddr == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003926 DEBUG_PRINT_ERROR("Failed to map extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07003927 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
3928 free_ion_memory(&drv_ctx.extradata_info.ion);
3929 return OMX_ErrorInsufficientResources;
3930 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07003931 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07003932#endif
Arun Menon906de572013-06-18 17:01:40 -07003933 return OMX_ErrorNone;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07003934}
3935
Arun Menon906de572013-06-18 17:01:40 -07003936void omx_vdec::free_extradata()
3937{
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07003938#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07003939 if (drv_ctx.extradata_info.uaddr) {
3940 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
3941 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
3942 free_ion_memory(&drv_ctx.extradata_info.ion);
3943 }
3944 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07003945#endif
3946}
3947
Shalaj Jain273b3e02012-06-22 19:08:03 -07003948OMX_ERRORTYPE omx_vdec::use_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07003949 OMX_IN OMX_HANDLETYPE hComp,
3950 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
3951 OMX_IN OMX_U32 port,
3952 OMX_IN OMX_PTR appData,
3953 OMX_IN OMX_U32 bytes,
3954 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003955{
Arun Menon906de572013-06-18 17:01:40 -07003956 OMX_ERRORTYPE eRet = OMX_ErrorNone;
3957 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
3958 unsigned i= 0; // Temporary counter
3959 struct vdec_setbuffer_cmd setbuffers;
3960 OMX_PTR privateAppData = NULL;
3961 private_handle_t *handle = NULL;
3962 OMX_U8 *buff = buffer;
3963 struct v4l2_buffer buf;
3964 struct v4l2_plane plane[VIDEO_MAX_PLANES];
3965 int extra_idx = 0;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07003966
Arun Menon906de572013-06-18 17:01:40 -07003967 if (!m_out_mem_ptr) {
3968 DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers");
3969 eRet = allocate_output_headers();
3970 if (eRet == OMX_ErrorNone)
3971 eRet = allocate_extradata();
Shalaj Jain273b3e02012-06-22 19:08:03 -07003972 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003973
Arun Menon906de572013-06-18 17:01:40 -07003974 if (eRet == OMX_ErrorNone) {
3975 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
3976 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
3977 break;
3978 }
3979 }
3980 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003981
Arun Menon906de572013-06-18 17:01:40 -07003982 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003983 DEBUG_PRINT_ERROR("Already using %d o/p buffers", drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07003984 eRet = OMX_ErrorInsufficientResources;
3985 }
3986
Arun Menonbdb80b02013-08-12 17:45:54 -07003987 if (dynamic_buf_mode) {
3988 *bufferHdr = (m_out_mem_ptr + i );
3989 (*bufferHdr)->pBuffer = NULL;
3990 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
3991 enum v4l2_buf_type buf_type;
3992 int rr = 0;
3993 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3994 if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
3995 DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr);
3996 return OMX_ErrorInsufficientResources;
3997 } else {
3998 streaming[CAPTURE_PORT] = true;
3999 DEBUG_PRINT_LOW("STREAMON Successful");
4000 }
4001 }
4002 BITMASK_SET(&m_out_bm_count,i);
4003 (*bufferHdr)->pAppPrivate = appData;
4004 (*bufferHdr)->pBuffer = buffer;
4005 (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData);
4006 return eRet;
4007 }
Arun Menon906de572013-06-18 17:01:40 -07004008 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004009#if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004010 if (m_enable_android_native_buffers) {
4011 if (m_use_android_native_buffers) {
4012 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData;
4013 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
4014 handle = (private_handle_t *)nBuf->handle;
4015 privateAppData = params->pAppPrivate;
4016 } else {
4017 handle = (private_handle_t *)buff;
4018 privateAppData = appData;
4019 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004020
Arun Menon906de572013-06-18 17:01:40 -07004021 if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) {
4022 DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback,"
4023 " expected %u, got %lu",
4024 drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size);
4025 return OMX_ErrorBadParameter;
4026 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004027
Arun Menon906de572013-06-18 17:01:40 -07004028 if (!m_use_android_native_buffers) {
4029 if (!secure_mode) {
4030 buff = (OMX_U8*)mmap(0, handle->size,
4031 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
4032 if (buff == MAP_FAILED) {
4033 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
4034 return OMX_ErrorInsufficientResources;
4035 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004036 }
4037 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004038#if defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004039 native_buffer[i].nativehandle = handle;
4040 native_buffer[i].privatehandle = handle;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004041#endif
Arun Menon906de572013-06-18 17:01:40 -07004042 if (!handle) {
4043 DEBUG_PRINT_ERROR("Native Buffer handle is NULL");
4044 return OMX_ErrorBadParameter;
4045 }
4046 drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd;
4047 drv_ctx.ptr_outputbuffer[i].offset = 0;
4048 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4049 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4050 drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size;
4051 } else
4052#endif
4053
4054 if (!ouput_egl_buffers && !m_use_output_pmem) {
4055#ifdef USE_ION
4056 drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
4057 drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment,
4058 &drv_ctx.op_buf_ion_info[i].ion_alloc_data,
4059 &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
4060 if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004061 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 -07004062 return OMX_ErrorInsufficientResources;
4063 }
4064 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4065 drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
4066#else
4067 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4068 open (MEM_DEVICE,O_RDWR);
4069
4070 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004071 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004072 return OMX_ErrorInsufficientResources;
4073 }
4074
4075 /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */
4076 if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) {
4077 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4078 open (MEM_DEVICE,O_RDWR);
4079 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004080 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004081 return OMX_ErrorInsufficientResources;
4082 }
4083 }
4084
4085 if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd,
4086 drv_ctx.op_buf.buffer_size,
4087 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004088 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07004089 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4090 return OMX_ErrorInsufficientResources;
4091 }
4092#endif
4093 if (!secure_mode) {
4094 drv_ctx.ptr_outputbuffer[i].bufferaddr =
4095 (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size,
4096 PROT_READ|PROT_WRITE, MAP_SHARED,
4097 drv_ctx.ptr_outputbuffer[i].pmem_fd,0);
4098 if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) {
4099 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4100#ifdef USE_ION
4101 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
4102#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004103 DEBUG_PRINT_ERROR("Unable to mmap output buffer");
Arun Menon906de572013-06-18 17:01:40 -07004104 return OMX_ErrorInsufficientResources;
4105 }
4106 }
4107 drv_ctx.ptr_outputbuffer[i].offset = 0;
4108 privateAppData = appData;
4109 } else {
4110
4111 DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem);
4112 if (!appData || !bytes ) {
4113 if (!secure_mode && !buffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004114 DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case");
Arun Menon906de572013-06-18 17:01:40 -07004115 return OMX_ErrorBadParameter;
4116 }
4117 }
4118
4119 OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list;
4120 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info;
4121 pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData;
4122 if (!pmem_list->entryList || !pmem_list->entryList->entry ||
4123 !pmem_list->nEntries ||
4124 pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004125 DEBUG_PRINT_ERROR("Pmem info not valid in use buffer");
Arun Menon906de572013-06-18 17:01:40 -07004126 return OMX_ErrorBadParameter;
4127 }
4128 pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
4129 pmem_list->entryList->entry;
4130 DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx",
4131 pmem_info->pmem_fd);
4132 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd;
4133 drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset;
4134 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4135 drv_ctx.ptr_outputbuffer[i].mmaped_size =
4136 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4137 privateAppData = appData;
4138 }
4139 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
4140 m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd;
4141
4142 *bufferHdr = (m_out_mem_ptr + i );
4143 if (secure_mode)
4144 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
4145 //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4146 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i],
4147 sizeof (vdec_bufferpayload));
4148
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004149 DEBUG_PRINT_HIGH("Set the Output Buffer Idx: %d Addr: %p, pmem_fd=0x%x", i,
Arun Menon906de572013-06-18 17:01:40 -07004150 drv_ctx.ptr_outputbuffer[i].bufferaddr,
4151 drv_ctx.ptr_outputbuffer[i].pmem_fd );
4152
4153 buf.index = i;
4154 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4155 buf.memory = V4L2_MEMORY_USERPTR;
4156 plane[0].length = drv_ctx.op_buf.buffer_size;
4157 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
4158 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
4159 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd;
4160 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
4161 plane[0].data_offset = 0;
4162 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
4163 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
4164 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
4165 plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size);
4166#ifdef USE_ION
4167 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
4168#endif
4169 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
4170 plane[extra_idx].data_offset = 0;
4171 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004172 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004173 return OMX_ErrorBadParameter;
4174 }
Arun Menon906de572013-06-18 17:01:40 -07004175 buf.m.planes = plane;
4176 buf.length = drv_ctx.num_planes;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004177
Arun Menon906de572013-06-18 17:01:40 -07004178 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004179 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07004180 /*TODO: How to handle this case */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004181 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004182 }
4183
Arun Menon906de572013-06-18 17:01:40 -07004184 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
4185 enum v4l2_buf_type buf_type;
4186 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4187 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
4188 return OMX_ErrorInsufficientResources;
4189 } else {
4190 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004191 DEBUG_PRINT_LOW("STREAMON Successful");
Shalaj Jain273b3e02012-06-22 19:08:03 -07004192 }
4193 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004194
Arun Menon906de572013-06-18 17:01:40 -07004195 (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size;
4196 if (m_enable_android_native_buffers) {
4197 DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle);
4198 (*bufferHdr)->pBuffer = (OMX_U8 *)handle;
4199 } else {
4200 (*bufferHdr)->pBuffer = buff;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004201 }
Arun Menon906de572013-06-18 17:01:40 -07004202 (*bufferHdr)->pAppPrivate = privateAppData;
4203 BITMASK_SET(&m_out_bm_count,i);
4204 }
4205 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004206}
4207
4208/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004209 FUNCTION
4210 omx_vdec::use_input_heap_buffers
Shalaj Jain273b3e02012-06-22 19:08:03 -07004211
Arun Menon906de572013-06-18 17:01:40 -07004212 DESCRIPTION
4213 OMX Use Buffer Heap allocation method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004214
Arun Menon906de572013-06-18 17:01:40 -07004215 PARAMETERS
4216 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004217
Arun Menon906de572013-06-18 17:01:40 -07004218 RETURN VALUE
4219 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004220
Arun Menon906de572013-06-18 17:01:40 -07004221 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004222OMX_ERRORTYPE omx_vdec::use_input_heap_buffers(
Arun Menon906de572013-06-18 17:01:40 -07004223 OMX_IN OMX_HANDLETYPE hComp,
4224 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4225 OMX_IN OMX_U32 port,
4226 OMX_IN OMX_PTR appData,
4227 OMX_IN OMX_U32 bytes,
4228 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004229{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004230 DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer);
Arun Menon906de572013-06-18 17:01:40 -07004231 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4232 if (!m_inp_heap_ptr)
4233 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*)
4234 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4235 drv_ctx.ip_buf.actualcount);
4236 if (!m_phdr_pmem_ptr)
4237 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**)
4238 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4239 drv_ctx.ip_buf.actualcount);
4240 if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) {
4241 DEBUG_PRINT_ERROR("Insufficent memory");
4242 eRet = OMX_ErrorInsufficientResources;
4243 } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) {
4244 input_use_buffer = true;
4245 memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE));
4246 m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer;
4247 m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes;
4248 m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData;
4249 m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput;
4250 m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax;
4251 *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt];
4252 eRet = allocate_input_buffer(hComp, &m_phdr_pmem_ptr[m_in_alloc_cnt], port, appData, bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004253 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 -07004254 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt],
4255 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004256 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07004257 return OMX_ErrorInsufficientResources;
4258 }
4259 m_in_alloc_cnt++;
4260 } else {
4261 DEBUG_PRINT_ERROR("All i/p buffers have been set!");
4262 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004263 }
Arun Menon906de572013-06-18 17:01:40 -07004264 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004265}
4266
4267/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004268 FUNCTION
4269 omx_vdec::UseBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004270
Arun Menon906de572013-06-18 17:01:40 -07004271 DESCRIPTION
4272 OMX Use Buffer method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004273
Arun Menon906de572013-06-18 17:01:40 -07004274 PARAMETERS
4275 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004276
Arun Menon906de572013-06-18 17:01:40 -07004277 RETURN VALUE
4278 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004279
Arun Menon906de572013-06-18 17:01:40 -07004280 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004281OMX_ERRORTYPE omx_vdec::use_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004282 OMX_IN OMX_HANDLETYPE hComp,
4283 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4284 OMX_IN OMX_U32 port,
4285 OMX_IN OMX_PTR appData,
4286 OMX_IN OMX_U32 bytes,
4287 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004288{
Arun Menon906de572013-06-18 17:01:40 -07004289 OMX_ERRORTYPE error = OMX_ErrorNone;
4290 struct vdec_setbuffer_cmd setbuffers;
4291
4292 if (bufferHdr == NULL || bytes == 0) {
4293 if (!secure_mode && buffer == NULL) {
4294 DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer);
4295 return OMX_ErrorBadParameter;
4296 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004297 }
Arun Menon906de572013-06-18 17:01:40 -07004298 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004299 DEBUG_PRINT_ERROR("Use Buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004300 return OMX_ErrorInvalidState;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004301 }
Arun Menon906de572013-06-18 17:01:40 -07004302 if (port == OMX_CORE_INPUT_PORT_INDEX)
4303 error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer);
4304 else if (port == OMX_CORE_OUTPUT_PORT_INDEX)
4305 error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested
4306 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004307 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07004308 error = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004309 }
Arun Menon906de572013-06-18 17:01:40 -07004310 DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error);
4311 if (error == OMX_ErrorNone) {
4312 if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
4313 // Send the callback now
4314 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
4315 post_event(OMX_CommandStateSet,OMX_StateIdle,
4316 OMX_COMPONENT_GENERATE_EVENT);
4317 }
4318 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated &&
4319 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
4320 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
4321 post_event(OMX_CommandPortEnable,
4322 OMX_CORE_INPUT_PORT_INDEX,
4323 OMX_COMPONENT_GENERATE_EVENT);
4324 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated &&
4325 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
4326 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
4327 post_event(OMX_CommandPortEnable,
4328 OMX_CORE_OUTPUT_PORT_INDEX,
4329 OMX_COMPONENT_GENERATE_EVENT);
4330 }
4331 }
4332 return error;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004333}
4334
4335OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex,
Arun Menon906de572013-06-18 17:01:40 -07004336 OMX_BUFFERHEADERTYPE *pmem_bufferHdr)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004337{
Arun Menon906de572013-06-18 17:01:40 -07004338 if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) {
4339 if (m_inp_heap_ptr[bufferindex].pBuffer)
4340 free(m_inp_heap_ptr[bufferindex].pBuffer);
4341 m_inp_heap_ptr[bufferindex].pBuffer = NULL;
4342 }
4343 if (pmem_bufferHdr)
4344 free_input_buffer(pmem_bufferHdr);
4345 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004346}
4347
4348OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4349{
Arun Menon906de572013-06-18 17:01:40 -07004350 unsigned int index = 0;
4351 if (bufferHdr == NULL || m_inp_mem_ptr == NULL) {
4352 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004353 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004354
Arun Menon906de572013-06-18 17:01:40 -07004355 index = bufferHdr - m_inp_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004356 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004357
4358 if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004359 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004360 if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) {
4361 struct vdec_setbuffer_cmd setbuffers;
4362 setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT;
4363 memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index],
4364 sizeof (vdec_bufferpayload));
4365 if (!secure_mode) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004366 DEBUG_PRINT_LOW("unmap the input buffer fd=%d",
Arun Menon906de572013-06-18 17:01:40 -07004367 drv_ctx.ptr_inputbuffer[index].pmem_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004368 DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07004369 drv_ctx.ptr_inputbuffer[index].mmaped_size,
4370 drv_ctx.ptr_inputbuffer[index].bufferaddr);
4371 munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr,
4372 drv_ctx.ptr_inputbuffer[index].mmaped_size);
4373 }
4374 close (drv_ctx.ptr_inputbuffer[index].pmem_fd);
4375 drv_ctx.ptr_inputbuffer[index].pmem_fd = -1;
4376 if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) {
4377 free(m_desc_buffer_ptr[index].buf_addr);
4378 m_desc_buffer_ptr[index].buf_addr = NULL;
4379 m_desc_buffer_ptr[index].desc_data_size = 0;
4380 }
4381#ifdef USE_ION
4382 free_ion_memory(&drv_ctx.ip_buf_ion_info[index]);
4383#endif
4384 }
4385 }
4386
4387 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004388}
4389
4390OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4391{
Arun Menon906de572013-06-18 17:01:40 -07004392 unsigned int index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004393
Arun Menon906de572013-06-18 17:01:40 -07004394 if (bufferHdr == NULL || m_out_mem_ptr == NULL) {
4395 return OMX_ErrorBadParameter;
4396 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004397
Arun Menon906de572013-06-18 17:01:40 -07004398 index = bufferHdr - m_out_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004399 DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004400
Arun Menon906de572013-06-18 17:01:40 -07004401 if (index < drv_ctx.op_buf.actualcount
4402 && drv_ctx.ptr_outputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004403 DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index,
Arun Menon906de572013-06-18 17:01:40 -07004404 drv_ctx.ptr_outputbuffer[index].bufferaddr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004405
Arun Menon906de572013-06-18 17:01:40 -07004406 struct vdec_setbuffer_cmd setbuffers;
4407 setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4408 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index],
4409 sizeof (vdec_bufferpayload));
Shalaj Jain273b3e02012-06-22 19:08:03 -07004410#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07004411 if (m_enable_android_native_buffers) {
Praveen Chavan212671f2013-04-05 20:00:42 -07004412 if (!secure_mode) {
Arun Menon906de572013-06-18 17:01:40 -07004413 if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) {
4414 munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr,
4415 drv_ctx.ptr_outputbuffer[index].mmaped_size);
4416 }
Praveen Chavan212671f2013-04-05 20:00:42 -07004417 }
Arun Menon906de572013-06-18 17:01:40 -07004418 drv_ctx.ptr_outputbuffer[index].pmem_fd = -1;
4419 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004420#endif
Arun Menon906de572013-06-18 17:01:40 -07004421 if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) {
4422 if (!secure_mode) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004423 DEBUG_PRINT_LOW("unmap the output buffer fd = %d",
Arun Menon906de572013-06-18 17:01:40 -07004424 drv_ctx.ptr_outputbuffer[0].pmem_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004425 DEBUG_PRINT_LOW("unmap the ouput buffer size=%d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07004426 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount,
4427 drv_ctx.ptr_outputbuffer[0].bufferaddr);
4428 munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr,
4429 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount);
4430 }
4431 close (drv_ctx.ptr_outputbuffer[0].pmem_fd);
4432 drv_ctx.ptr_outputbuffer[0].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004433#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004434 free_ion_memory(&drv_ctx.op_buf_ion_info[0]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004435#endif
Arun Menon906de572013-06-18 17:01:40 -07004436 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004437#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07004438 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004439#endif
Arun Menon906de572013-06-18 17:01:40 -07004440 if (release_output_done()) {
4441 free_extradata();
4442 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004443 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004444
Arun Menon906de572013-06-18 17:01:40 -07004445 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004446
4447}
4448
4449OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004450 OMX_BUFFERHEADERTYPE **bufferHdr,
4451 OMX_U32 port,
4452 OMX_PTR appData,
4453 OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004454{
Arun Menon906de572013-06-18 17:01:40 -07004455 OMX_BUFFERHEADERTYPE *input = NULL;
4456 unsigned char *buf_addr = NULL;
4457 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4458 unsigned i = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004459
Arun Menon906de572013-06-18 17:01:40 -07004460 /* Sanity Check*/
4461 if (bufferHdr == NULL) {
4462 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004463 }
4464
Arun Menon906de572013-06-18 17:01:40 -07004465 if (m_inp_heap_ptr == NULL) {
4466 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \
4467 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4468 drv_ctx.ip_buf.actualcount);
4469 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \
4470 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4471 drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004472
Arun Menon906de572013-06-18 17:01:40 -07004473 if (m_inp_heap_ptr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004474 DEBUG_PRINT_ERROR("m_inp_heap_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07004475 return OMX_ErrorInsufficientResources;
4476 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004477 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004478
Arun Menon906de572013-06-18 17:01:40 -07004479 /*Find a Free index*/
4480 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
4481 if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004482 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004483 break;
4484 }
4485 }
4486
4487 if (i < drv_ctx.ip_buf.actualcount) {
4488 buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size);
4489
4490 if (buf_addr == NULL) {
4491 return OMX_ErrorInsufficientResources;
4492 }
4493
4494 *bufferHdr = (m_inp_heap_ptr + i);
4495 input = *bufferHdr;
4496 BITMASK_SET(&m_heap_inp_bm_count,i);
4497
4498 input->pBuffer = (OMX_U8 *)buf_addr;
4499 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
4500 input->nVersion.nVersion = OMX_SPEC_VERSION;
4501 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
4502 input->pAppPrivate = appData;
4503 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004504 DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr );
Arun Menon906de572013-06-18 17:01:40 -07004505 eRet = allocate_input_buffer(hComp,&m_phdr_pmem_ptr [i],port,appData,bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004506 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",m_phdr_pmem_ptr[i]);
Arun Menon906de572013-06-18 17:01:40 -07004507 /*Add the Buffers to freeq*/
4508 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i],
4509 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004510 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07004511 return OMX_ErrorInsufficientResources;
4512 }
4513 } else {
4514 return OMX_ErrorBadParameter;
4515 }
4516
4517 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004518
4519}
4520
4521
4522/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004523 FUNCTION
4524 omx_vdec::AllocateInputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004525
Arun Menon906de572013-06-18 17:01:40 -07004526 DESCRIPTION
4527 Helper function for allocate buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07004528
Arun Menon906de572013-06-18 17:01:40 -07004529 PARAMETERS
4530 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004531
Arun Menon906de572013-06-18 17:01:40 -07004532 RETURN VALUE
4533 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07004534
Arun Menon906de572013-06-18 17:01:40 -07004535 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004536OMX_ERRORTYPE omx_vdec::allocate_input_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004537 OMX_IN OMX_HANDLETYPE hComp,
4538 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4539 OMX_IN OMX_U32 port,
4540 OMX_IN OMX_PTR appData,
4541 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004542{
4543
Arun Menon906de572013-06-18 17:01:40 -07004544 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4545 struct vdec_setbuffer_cmd setbuffers;
4546 OMX_BUFFERHEADERTYPE *input = NULL;
4547 unsigned i = 0;
4548 unsigned char *buf_addr = NULL;
4549 int pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004550
Arun Menon906de572013-06-18 17:01:40 -07004551 if (bytes != drv_ctx.ip_buf.buffer_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004552 DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d",
Arun Menon906de572013-06-18 17:01:40 -07004553 bytes, drv_ctx.ip_buf.buffer_size);
4554 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004555 }
4556
Arun Menon906de572013-06-18 17:01:40 -07004557 if (!m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004558 DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07004559 drv_ctx.ip_buf.actualcount,
4560 drv_ctx.ip_buf.buffer_size);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004561
Arun Menon906de572013-06-18 17:01:40 -07004562 m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \
4563 calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount);
4564
4565 if (m_inp_mem_ptr == NULL) {
4566 return OMX_ErrorInsufficientResources;
4567 }
4568
4569 drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \
4570 calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount);
4571
4572 if (drv_ctx.ptr_inputbuffer == NULL) {
4573 return OMX_ErrorInsufficientResources;
4574 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004575#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004576 drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \
4577 calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004578
Arun Menon906de572013-06-18 17:01:40 -07004579 if (drv_ctx.ip_buf_ion_info == NULL) {
4580 return OMX_ErrorInsufficientResources;
4581 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004582#endif
4583
Arun Menon906de572013-06-18 17:01:40 -07004584 for (i=0; i < drv_ctx.ip_buf.actualcount; i++) {
4585 drv_ctx.ptr_inputbuffer [i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004586#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004587 drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004588#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07004589 }
4590 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004591
Arun Menon906de572013-06-18 17:01:40 -07004592 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
4593 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004594 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004595 break;
4596 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004597 }
Arun Menon906de572013-06-18 17:01:40 -07004598
4599 if (i < drv_ctx.ip_buf.actualcount) {
4600 struct v4l2_buffer buf;
4601 struct v4l2_plane plane;
4602 int rc;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004603 DEBUG_PRINT_LOW("Allocate input Buffer");
Arun Menon906de572013-06-18 17:01:40 -07004604#ifdef USE_ION
4605 drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
4606 drv_ctx.ip_buf.buffer_size,drv_ctx.op_buf.alignment,
4607 &drv_ctx.ip_buf_ion_info[i].ion_alloc_data,
4608 &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
4609 if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) {
4610 return OMX_ErrorInsufficientResources;
4611 }
4612 pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd;
4613#else
4614 pmem_fd = open (MEM_DEVICE,O_RDWR);
4615
4616 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004617 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07004618 return OMX_ErrorInsufficientResources;
4619 }
4620
4621 if (pmem_fd == 0) {
4622 pmem_fd = open (MEM_DEVICE,O_RDWR);
4623
4624 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004625 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07004626 return OMX_ErrorInsufficientResources;
4627 }
4628 }
4629
4630 if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size,
4631 drv_ctx.ip_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004632 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07004633 close(pmem_fd);
4634 return OMX_ErrorInsufficientResources;
4635 }
4636#endif
4637 if (!secure_mode) {
4638 buf_addr = (unsigned char *)mmap(NULL,
4639 drv_ctx.ip_buf.buffer_size,
4640 PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0);
4641
4642 if (buf_addr == MAP_FAILED) {
4643 close(pmem_fd);
4644#ifdef USE_ION
4645 free_ion_memory(&drv_ctx.ip_buf_ion_info[i]);
4646#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004647 DEBUG_PRINT_ERROR("Map Failed to allocate input buffer");
Arun Menon906de572013-06-18 17:01:40 -07004648 return OMX_ErrorInsufficientResources;
4649 }
4650 }
4651 *bufferHdr = (m_inp_mem_ptr + i);
4652 if (secure_mode)
4653 drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr;
4654 else
4655 drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr;
4656 drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd;
4657 drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size;
4658 drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size;
4659 drv_ctx.ptr_inputbuffer [i].offset = 0;
4660
4661
4662 buf.index = i;
4663 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
4664 buf.memory = V4L2_MEMORY_USERPTR;
4665 plane.bytesused = 0;
4666 plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size;
4667 plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr;
4668 plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd;
4669 plane.reserved[1] = 0;
4670 plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset;
4671 buf.m.planes = &plane;
4672 buf.length = 1;
4673
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004674 DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i,
Arun Menon906de572013-06-18 17:01:40 -07004675 drv_ctx.ptr_inputbuffer[i].bufferaddr);
4676
4677 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
4678
4679 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004680 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07004681 /*TODO: How to handle this case */
4682 return OMX_ErrorInsufficientResources;
4683 }
4684
4685 input = *bufferHdr;
4686 BITMASK_SET(&m_inp_bm_count,i);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004687 DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr);
Arun Menon906de572013-06-18 17:01:40 -07004688 if (secure_mode)
4689 input->pBuffer = (OMX_U8 *)drv_ctx.ptr_inputbuffer [i].pmem_fd;
4690 else
4691 input->pBuffer = (OMX_U8 *)buf_addr;
4692 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
4693 input->nVersion.nVersion = OMX_SPEC_VERSION;
4694 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
4695 input->pAppPrivate = appData;
4696 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
4697 input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i];
4698
4699 if (drv_ctx.disable_dmx) {
4700 eRet = allocate_desc_buffer(i);
4701 }
4702 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004703 DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07004704 eRet = OMX_ErrorInsufficientResources;
4705 }
4706 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004707}
4708
4709
4710/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004711 FUNCTION
4712 omx_vdec::AllocateOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004713
Arun Menon906de572013-06-18 17:01:40 -07004714 DESCRIPTION
4715 Helper fn for AllocateBuffer in the output pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07004716
Arun Menon906de572013-06-18 17:01:40 -07004717 PARAMETERS
4718 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004719
Arun Menon906de572013-06-18 17:01:40 -07004720 RETURN VALUE
4721 OMX Error None if everything went well.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004722
Arun Menon906de572013-06-18 17:01:40 -07004723 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004724OMX_ERRORTYPE omx_vdec::allocate_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004725 OMX_IN OMX_HANDLETYPE hComp,
4726 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4727 OMX_IN OMX_U32 port,
4728 OMX_IN OMX_PTR appData,
4729 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004730{
Arun Menon906de572013-06-18 17:01:40 -07004731 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4732 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
4733 unsigned i= 0; // Temporary counter
4734 struct vdec_setbuffer_cmd setbuffers;
4735 int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004736#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004737 int ion_device_fd =-1;
4738 struct ion_allocation_data ion_alloc_data;
4739 struct ion_fd_data fd_ion_data;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004740#endif
Arun Menon906de572013-06-18 17:01:40 -07004741 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004742 DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07004743 drv_ctx.op_buf.actualcount,
4744 drv_ctx.op_buf.buffer_size);
4745 int nBufHdrSize = 0;
4746 int nPlatformEntrySize = 0;
4747 int nPlatformListSize = 0;
4748 int nPMEMInfoSize = 0;
4749 int pmem_fd = -1;
4750 unsigned char *pmem_baseaddress = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004751
Arun Menon906de572013-06-18 17:01:40 -07004752 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
4753 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
4754 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004755
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004756 DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07004757 drv_ctx.op_buf.actualcount);
4758 nBufHdrSize = drv_ctx.op_buf.actualcount *
4759 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004760
Arun Menon906de572013-06-18 17:01:40 -07004761 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
4762 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
4763 nPlatformListSize = drv_ctx.op_buf.actualcount *
4764 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
4765 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
4766 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004767
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004768 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07004769 sizeof(OMX_BUFFERHEADERTYPE),
4770 nPMEMInfoSize,
4771 nPlatformListSize);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004772 DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07004773 drv_ctx.op_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004774#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004775 ion_device_fd = alloc_map_ion_memory(
4776 drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount,
4777 drv_ctx.op_buf.alignment,
4778 &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0);
4779 if (ion_device_fd < 0) {
4780 return OMX_ErrorInsufficientResources;
4781 }
4782 pmem_fd = fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004783#else
Arun Menon906de572013-06-18 17:01:40 -07004784 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004785
Arun Menon906de572013-06-18 17:01:40 -07004786 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004787 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07004788 drv_ctx.op_buf.buffer_size);
4789 return OMX_ErrorInsufficientResources;
4790 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004791
Arun Menon906de572013-06-18 17:01:40 -07004792 if (pmem_fd == 0) {
4793 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004794
Arun Menon906de572013-06-18 17:01:40 -07004795 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004796 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07004797 drv_ctx.op_buf.buffer_size);
4798 return OMX_ErrorInsufficientResources;
4799 }
4800 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004801
Arun Menon906de572013-06-18 17:01:40 -07004802 if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size *
4803 drv_ctx.op_buf.actualcount,
4804 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004805 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07004806 close(pmem_fd);
4807 return OMX_ErrorInsufficientResources;
4808 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004809#endif
Arun Menon906de572013-06-18 17:01:40 -07004810 if (!secure_mode) {
4811 pmem_baseaddress = (unsigned char *)mmap(NULL,
4812 (drv_ctx.op_buf.buffer_size *
4813 drv_ctx.op_buf.actualcount),
4814 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0);
4815 if (pmem_baseaddress == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004816 DEBUG_PRINT_ERROR("MMAP failed for Size %d",
Arun Menon906de572013-06-18 17:01:40 -07004817 drv_ctx.op_buf.buffer_size);
4818 close(pmem_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004819#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004820 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004821#endif
Arun Menon906de572013-06-18 17:01:40 -07004822 return OMX_ErrorInsufficientResources;
4823 }
4824 }
4825 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
4826 // Alloc mem for platform specific info
4827 char *pPtr=NULL;
4828 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
4829 nPMEMInfoSize,1);
4830 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\
4831 calloc (sizeof(struct vdec_bufferpayload),
4832 drv_ctx.op_buf.actualcount);
4833 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
4834 calloc (sizeof (struct vdec_output_frameinfo),
4835 drv_ctx.op_buf.actualcount);
4836#ifdef USE_ION
4837 drv_ctx.op_buf_ion_info = (struct vdec_ion *)\
4838 calloc (sizeof(struct vdec_ion),
4839 drv_ctx.op_buf.actualcount);
4840#endif
4841
4842 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
4843 && drv_ctx.ptr_respbuffer) {
4844 drv_ctx.ptr_outputbuffer[0].mmaped_size =
4845 (drv_ctx.op_buf.buffer_size *
4846 drv_ctx.op_buf.actualcount);
4847 bufHdr = m_out_mem_ptr;
4848 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
4849 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
4850 (((char *) m_platform_list) + nPlatformListSize);
4851 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
4852 (((char *) m_platform_entry) + nPlatformEntrySize);
4853 pPlatformList = m_platform_list;
4854 pPlatformEntry = m_platform_entry;
4855 pPMEMInfo = m_pmem_info;
4856
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004857 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07004858
4859 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004860 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry);
4861 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07004862 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
4863 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
4864 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
4865 // Set the values when we determine the right HxW param
4866 bufHdr->nAllocLen = bytes;
4867 bufHdr->nFilledLen = 0;
4868 bufHdr->pAppPrivate = appData;
4869 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
4870 // Platform specific PMEM Information
4871 // Initialize the Platform Entry
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004872 //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004873 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
4874 pPlatformEntry->entry = pPMEMInfo;
4875 // Initialize the Platform List
4876 pPlatformList->nEntries = 1;
4877 pPlatformList->entryList = pPlatformEntry;
4878 // Keep pBuffer NULL till vdec is opened
4879 bufHdr->pBuffer = NULL;
4880 bufHdr->nOffset = 0;
4881
4882 pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i;
4883 pPMEMInfo->pmem_fd = 0;
4884 bufHdr->pPlatformPrivate = pPlatformList;
4885
4886 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd;
4887 m_pmem_info[i].pmem_fd = pmem_fd;
4888#ifdef USE_ION
4889 drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd;
4890 drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data;
4891 drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data;
4892#endif
4893
4894 /*Create a mapping between buffers*/
4895 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
4896 drv_ctx.ptr_respbuffer[i].client_data = (void *)\
4897 &drv_ctx.ptr_outputbuffer[i];
4898 drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i;
4899 drv_ctx.ptr_outputbuffer[i].bufferaddr =
4900 pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i);
4901
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004902 DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07004903 pmem_fd, drv_ctx.ptr_outputbuffer[i].offset,
4904 drv_ctx.ptr_outputbuffer[i].bufferaddr);
4905 // Move the buffer and buffer header pointers
4906 bufHdr++;
4907 pPMEMInfo++;
4908 pPlatformEntry++;
4909 pPlatformList++;
4910 }
4911 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004912 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07004913 m_out_mem_ptr, pPtr);
4914 if (m_out_mem_ptr) {
4915 free(m_out_mem_ptr);
4916 m_out_mem_ptr = NULL;
4917 }
4918 if (pPtr) {
4919 free(pPtr);
4920 pPtr = NULL;
4921 }
4922 if (drv_ctx.ptr_outputbuffer) {
4923 free(drv_ctx.ptr_outputbuffer);
4924 drv_ctx.ptr_outputbuffer = NULL;
4925 }
4926 if (drv_ctx.ptr_respbuffer) {
4927 free(drv_ctx.ptr_respbuffer);
4928 drv_ctx.ptr_respbuffer = NULL;
4929 }
4930#ifdef USE_ION
4931 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004932 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07004933 free(drv_ctx.op_buf_ion_info);
4934 drv_ctx.op_buf_ion_info = NULL;
4935 }
4936#endif
4937 eRet = OMX_ErrorInsufficientResources;
4938 }
4939 if (eRet == OMX_ErrorNone)
4940 eRet = allocate_extradata();
4941 }
4942
4943 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
4944 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004945 DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004946 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004947 }
4948 }
Arun Menon906de572013-06-18 17:01:40 -07004949
4950 if (eRet == OMX_ErrorNone) {
4951 if (i < drv_ctx.op_buf.actualcount) {
4952 struct v4l2_buffer buf;
4953 struct v4l2_plane plane[VIDEO_MAX_PLANES];
4954 int rc;
4955 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
4956
4957 drv_ctx.ptr_outputbuffer[i].buffer_len =
4958 drv_ctx.op_buf.buffer_size;
4959
4960 *bufferHdr = (m_out_mem_ptr + i );
4961 if (secure_mode) {
4962 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
4963 }
4964 drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size;
4965
4966 buf.index = i;
4967 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4968 buf.memory = V4L2_MEMORY_USERPTR;
4969 plane[0].length = drv_ctx.op_buf.buffer_size;
4970 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
4971 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004972#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004973 plane[0].reserved[0] = drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004974#endif
Arun Menon906de572013-06-18 17:01:40 -07004975 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
4976 plane[0].data_offset = 0;
4977 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
4978 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
4979 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
4980 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 -07004981#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004982 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004983#endif
Arun Menon906de572013-06-18 17:01:40 -07004984 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
4985 plane[extra_idx].data_offset = 0;
4986 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004987 DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07004988 return OMX_ErrorBadParameter;
4989 }
4990 buf.m.planes = plane;
4991 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004992 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 -07004993 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
4994 if (rc) {
4995 /*TODO: How to handle this case */
4996 return OMX_ErrorInsufficientResources;
4997 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004998
Arun Menon906de572013-06-18 17:01:40 -07004999 if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) {
5000 enum v4l2_buf_type buf_type;
5001 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5002 rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
5003 if (rc) {
5004 return OMX_ErrorInsufficientResources;
5005 } else {
5006 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005007 DEBUG_PRINT_LOW("STREAMON Successful");
Arun Menon906de572013-06-18 17:01:40 -07005008 }
5009 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005010
Arun Menon906de572013-06-18 17:01:40 -07005011 (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr;
5012 (*bufferHdr)->pAppPrivate = appData;
5013 BITMASK_SET(&m_out_bm_count,i);
5014 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005015 DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient");
Arun Menon906de572013-06-18 17:01:40 -07005016 eRet = OMX_ErrorInsufficientResources;
5017 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005018 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005019
Arun Menon906de572013-06-18 17:01:40 -07005020 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005021}
5022
5023
5024// AllocateBuffer -- API Call
5025/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005026 FUNCTION
5027 omx_vdec::AllocateBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005028
Arun Menon906de572013-06-18 17:01:40 -07005029 DESCRIPTION
5030 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07005031
Arun Menon906de572013-06-18 17:01:40 -07005032 PARAMETERS
5033 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005034
Arun Menon906de572013-06-18 17:01:40 -07005035 RETURN VALUE
5036 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005037
Arun Menon906de572013-06-18 17:01:40 -07005038 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005039OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005040 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5041 OMX_IN OMX_U32 port,
5042 OMX_IN OMX_PTR appData,
5043 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005044{
5045 unsigned i = 0;
5046 OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type
5047
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005048 DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port);
Arun Menon906de572013-06-18 17:01:40 -07005049 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005050 DEBUG_PRINT_ERROR("Allocate Buf in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005051 return OMX_ErrorInvalidState;
5052 }
5053
Arun Menon906de572013-06-18 17:01:40 -07005054 if (port == OMX_CORE_INPUT_PORT_INDEX) {
5055 if (arbitrary_bytes) {
5056 eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes);
5057 } else {
5058 eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes);
5059 }
5060 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Vinay Kaliada4f4422013-01-09 10:45:03 -08005061 eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port,
5062 appData,bytes);
Arun Menon906de572013-06-18 17:01:40 -07005063 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005064 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07005065 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005066 }
5067 DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done");
Arun Menon906de572013-06-18 17:01:40 -07005068 if (eRet == OMX_ErrorNone) {
5069 if (allocate_done()) {
5070 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005071 // Send the callback now
5072 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
5073 post_event(OMX_CommandStateSet,OMX_StateIdle,
Arun Menon906de572013-06-18 17:01:40 -07005074 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005075 }
5076 }
Arun Menon906de572013-06-18 17:01:40 -07005077 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) {
5078 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
5079 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
5080 post_event(OMX_CommandPortEnable,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005081 OMX_CORE_INPUT_PORT_INDEX,
5082 OMX_COMPONENT_GENERATE_EVENT);
Arun Menon906de572013-06-18 17:01:40 -07005083 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005084 }
Arun Menon906de572013-06-18 17:01:40 -07005085 if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) {
5086 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
5087 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005088 post_event(OMX_CommandPortEnable,
Arun Menon906de572013-06-18 17:01:40 -07005089 OMX_CORE_OUTPUT_PORT_INDEX,
5090 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005091 }
5092 }
5093 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005094 DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005095 return eRet;
5096}
5097
5098// Free Buffer - API call
5099/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005100 FUNCTION
5101 omx_vdec::FreeBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005102
Arun Menon906de572013-06-18 17:01:40 -07005103 DESCRIPTION
Shalaj Jain273b3e02012-06-22 19:08:03 -07005104
Arun Menon906de572013-06-18 17:01:40 -07005105 PARAMETERS
5106 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005107
Arun Menon906de572013-06-18 17:01:40 -07005108 RETURN VALUE
5109 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005110
Arun Menon906de572013-06-18 17:01:40 -07005111 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005112OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005113 OMX_IN OMX_U32 port,
5114 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005115{
5116 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5117 unsigned int nPortIndex;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005118 DEBUG_PRINT_LOW("In for decoder free_buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005119
Arun Menon906de572013-06-18 17:01:40 -07005120 if (m_state == OMX_StateIdle &&
5121 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005122 DEBUG_PRINT_LOW(" free buffer while Component in Loading pending");
Arun Menon906de572013-06-18 17:01:40 -07005123 } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)||
5124 (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005125 DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port);
Arun Menon906de572013-06-18 17:01:40 -07005126 } else if ((port == OMX_CORE_INPUT_PORT_INDEX &&
5127 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) ||
5128 (port == OMX_CORE_OUTPUT_PORT_INDEX &&
5129 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005130 DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port);
Arun Menon906de572013-06-18 17:01:40 -07005131 } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005132 DEBUG_PRINT_ERROR("Invalid state to free buffer,ports need to be disabled");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005133 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005134 OMX_ErrorPortUnpopulated,
5135 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005136
5137 return OMX_ErrorIncorrectStateOperation;
Arun Menon906de572013-06-18 17:01:40 -07005138 } else if (m_state != OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005139 DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005140 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005141 OMX_ErrorPortUnpopulated,
5142 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005143 }
5144
Arun Menon906de572013-06-18 17:01:40 -07005145 if (port == OMX_CORE_INPUT_PORT_INDEX) {
5146 /*Check if arbitrary bytes*/
5147 if (!arbitrary_bytes && !input_use_buffer)
5148 nPortIndex = buffer - m_inp_mem_ptr;
5149 else
5150 nPortIndex = buffer - m_inp_heap_ptr;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005151
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005152 DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %d", nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005153 if (nPortIndex < drv_ctx.ip_buf.actualcount) {
5154 // Clear the bit associated with it.
5155 BITMASK_CLEAR(&m_inp_bm_count,nPortIndex);
5156 BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex);
5157 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005158
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005159 DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005160 if (m_phdr_pmem_ptr)
5161 free_input_buffer(m_phdr_pmem_ptr[nPortIndex]);
5162 } else {
5163 if (arbitrary_bytes) {
5164 if (m_phdr_pmem_ptr)
5165 free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]);
5166 else
5167 free_input_buffer(nPortIndex,NULL);
5168 } else
5169 free_input_buffer(buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005170 }
Arun Menon906de572013-06-18 17:01:40 -07005171 m_inp_bPopulated = OMX_FALSE;
Surajit Podder12aefac2013-08-06 18:43:32 +05305172 if(release_input_done())
5173 release_buffers(this, VDEC_BUFFER_TYPE_INPUT);
Arun Menon906de572013-06-18 17:01:40 -07005174 /*Free the Buffer Header*/
5175 if (release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005176 DEBUG_PRINT_HIGH("ALL input buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07005177 free_input_buffer_header();
5178 }
5179 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005180 DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005181 eRet = OMX_ErrorBadPortIndex;
5182 }
5183
Arun Menon906de572013-06-18 17:01:40 -07005184 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING)
5185 && release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005186 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005187 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING);
5188 post_event(OMX_CommandPortDisable,
Arun Menon906de572013-06-18 17:01:40 -07005189 OMX_CORE_INPUT_PORT_INDEX,
5190 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005191 }
Arun Menon906de572013-06-18 17:01:40 -07005192 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005193 // check if the buffer is valid
Vinay Kaliada4f4422013-01-09 10:45:03 -08005194 nPortIndex = buffer - client_buffers.get_il_buf_hdr();
Arun Menon906de572013-06-18 17:01:40 -07005195 if (nPortIndex < drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005196 DEBUG_PRINT_LOW("free_buffer on o/p port - Port idx %d", nPortIndex);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005197 // Clear the bit associated with it.
5198 BITMASK_CLEAR(&m_out_bm_count,nPortIndex);
5199 m_out_bPopulated = OMX_FALSE;
Vinay Kaliada4f4422013-01-09 10:45:03 -08005200 client_buffers.free_output_buffer (buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005201
Surajit Podder12aefac2013-08-06 18:43:32 +05305202 if(release_output_done()) {
5203 release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT);
5204 }
Arun Menon906de572013-06-18 17:01:40 -07005205 if (release_output_done()) {
5206 free_output_buffer_header();
Shalaj Jain273b3e02012-06-22 19:08:03 -07005207 }
Arun Menon906de572013-06-18 17:01:40 -07005208 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005209 DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005210 eRet = OMX_ErrorBadPortIndex;
5211 }
Arun Menon906de572013-06-18 17:01:40 -07005212 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING)
5213 && release_output_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005214 DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005215
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005216 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Arun Menon906de572013-06-18 17:01:40 -07005217 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005218#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -07005219 if (m_enable_android_native_buffers) {
5220 DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers");
5221 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
5222 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005223#endif
5224
Arun Menon906de572013-06-18 17:01:40 -07005225 post_event(OMX_CommandPortDisable,
5226 OMX_CORE_OUTPUT_PORT_INDEX,
5227 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005228 }
Arun Menon906de572013-06-18 17:01:40 -07005229 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005230 eRet = OMX_ErrorBadPortIndex;
5231 }
Arun Menon906de572013-06-18 17:01:40 -07005232 if ((eRet == OMX_ErrorNone) &&
5233 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
5234 if (release_done()) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005235 // Send the callback now
5236 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING);
5237 post_event(OMX_CommandStateSet, OMX_StateLoaded,
Arun Menon906de572013-06-18 17:01:40 -07005238 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005239 }
5240 }
5241 return eRet;
5242}
5243
5244
5245/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005246 FUNCTION
5247 omx_vdec::EmptyThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005248
Arun Menon906de572013-06-18 17:01:40 -07005249 DESCRIPTION
5250 This routine is used to push the encoded video frames to
5251 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005252
Arun Menon906de572013-06-18 17:01:40 -07005253 PARAMETERS
5254 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005255
Arun Menon906de572013-06-18 17:01:40 -07005256 RETURN VALUE
5257 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005258
Arun Menon906de572013-06-18 17:01:40 -07005259 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005260OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005261 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005262{
Arun Menon906de572013-06-18 17:01:40 -07005263 OMX_ERRORTYPE ret1 = OMX_ErrorNone;
5264 unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005265
Arun Menon906de572013-06-18 17:01:40 -07005266 if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
5267 codec_config_flag = true;
5268 DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__);
5269 } else {
5270 codec_config_flag = false;
5271 }
Praneeth Paladugu80dd03b2013-05-22 16:57:42 -07005272
Arun Menon906de572013-06-18 17:01:40 -07005273 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005274 DEBUG_PRINT_ERROR("Empty this buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07005275 return OMX_ErrorInvalidState;
5276 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005277
Arun Menon906de572013-06-18 17:01:40 -07005278 if (buffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005279 DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL");
Arun Menon906de572013-06-18 17:01:40 -07005280 return OMX_ErrorBadParameter;
5281 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005282
Arun Menon906de572013-06-18 17:01:40 -07005283 if (!m_inp_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005284 DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07005285 return OMX_ErrorIncorrectStateOperation;
5286 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005287
Arun Menon906de572013-06-18 17:01:40 -07005288 if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005289 DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005290 return OMX_ErrorBadPortIndex;
5291 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005292
5293#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005294 if (iDivXDrmDecrypt) {
5295 OMX_ERRORTYPE drmErr = iDivXDrmDecrypt->Decrypt(buffer);
5296 if (drmErr != OMX_ErrorNone) {
5297 // this error can be ignored
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005298 DEBUG_PRINT_LOW("ERROR:iDivXDrmDecrypt->Decrypt %d", drmErr);
Arun Menon906de572013-06-18 17:01:40 -07005299 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005300 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005301#endif //_ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005302 if (perf_flag) {
5303 if (!latency) {
5304 dec_time.stop();
5305 latency = dec_time.processing_time_us();
5306 dec_time.start();
5307 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005308 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005309
Arun Menon906de572013-06-18 17:01:40 -07005310 if (arbitrary_bytes) {
5311 nBufferIndex = buffer - m_inp_heap_ptr;
5312 } else {
5313 if (input_use_buffer == true) {
5314 nBufferIndex = buffer - m_inp_heap_ptr;
5315 m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen;
5316 m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp;
5317 m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags;
5318 buffer = &m_inp_mem_ptr[nBufferIndex];
5319 DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu",
5320 &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen);
5321 } else {
5322 nBufferIndex = buffer - m_inp_mem_ptr;
5323 }
5324 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005325
Arun Menon906de572013-06-18 17:01:40 -07005326 if (nBufferIndex > drv_ctx.ip_buf.actualcount ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005327 DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005328 return OMX_ErrorBadParameter;
5329 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005330
Arun Menon906de572013-06-18 17:01:40 -07005331 DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)",
5332 buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen);
5333 if (arbitrary_bytes) {
5334 post_event ((unsigned)hComp,(unsigned)buffer,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005335 OMX_COMPONENT_GENERATE_ETB_ARBITRARY);
Arun Menon906de572013-06-18 17:01:40 -07005336 } else {
5337 if (!(client_extradata & OMX_TIMEINFO_EXTRADATA))
5338 set_frame_rate(buffer->nTimeStamp);
5339 post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB);
5340 }
5341 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005342}
5343
5344/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005345 FUNCTION
5346 omx_vdec::empty_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07005347
Arun Menon906de572013-06-18 17:01:40 -07005348 DESCRIPTION
5349 This routine is used to push the encoded video frames to
5350 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005351
Arun Menon906de572013-06-18 17:01:40 -07005352 PARAMETERS
5353 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005354
Arun Menon906de572013-06-18 17:01:40 -07005355 RETURN VALUE
5356 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005357
Arun Menon906de572013-06-18 17:01:40 -07005358 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005359OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005360 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005361{
Arun Menon906de572013-06-18 17:01:40 -07005362 int push_cnt = 0,i=0;
5363 unsigned nPortIndex = 0;
5364 OMX_ERRORTYPE ret = OMX_ErrorNone;
5365 struct vdec_input_frameinfo frameinfo;
5366 struct vdec_bufferpayload *temp_buffer;
5367 struct vdec_seqheader seq_header;
5368 bool port_setting_changed = true;
5369 bool not_coded_vop = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005370
Arun Menon906de572013-06-18 17:01:40 -07005371 /*Should we generate a Aync error event*/
5372 if (buffer == NULL || buffer->pInputPortPrivate == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005373 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005374 return OMX_ErrorBadParameter;
5375 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005376
Arun Menon906de572013-06-18 17:01:40 -07005377 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005378
Arun Menon906de572013-06-18 17:01:40 -07005379 if (nPortIndex > drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005380 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]",
Arun Menon906de572013-06-18 17:01:40 -07005381 nPortIndex);
5382 return OMX_ErrorBadParameter;
5383 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005384
Arun Menon906de572013-06-18 17:01:40 -07005385 pending_input_buffers++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005386
Arun Menon906de572013-06-18 17:01:40 -07005387 /* return zero length and not an EOS buffer */
5388 if (!arbitrary_bytes && (buffer->nFilledLen == 0) &&
5389 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005390 DEBUG_PRINT_HIGH("return zero legth buffer");
Arun Menon906de572013-06-18 17:01:40 -07005391 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5392 OMX_COMPONENT_GENERATE_EBD);
5393 return OMX_ErrorNone;
5394 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005395
5396
Arun Menon906de572013-06-18 17:01:40 -07005397 if (codec_type_parse == CODEC_TYPE_MPEG4 || codec_type_parse == CODEC_TYPE_DIVX) {
5398 mp4StreamType psBits;
5399 psBits.data = (unsigned char *)(buffer->pBuffer + buffer->nOffset);
5400 psBits.numBytes = buffer->nFilledLen;
5401 mp4_headerparser.parseHeader(&psBits);
5402 not_coded_vop = mp4_headerparser.is_notcodec_vop(
5403 (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen);
5404 if (not_coded_vop) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005405 DEBUG_PRINT_HIGH("Found Not coded vop len %lu frame number %u",
Arun Menon906de572013-06-18 17:01:40 -07005406 buffer->nFilledLen,frame_count);
5407 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005408 DEBUG_PRINT_HIGH("Eos and Not coded Vop set len to zero");
Arun Menon906de572013-06-18 17:01:40 -07005409 not_coded_vop = false;
5410 buffer->nFilledLen = 0;
5411 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005412 }
5413 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005414
Arun Menon906de572013-06-18 17:01:40 -07005415 if (input_flush_progress == true
Shalaj Jain273b3e02012-06-22 19:08:03 -07005416
Arun Menon906de572013-06-18 17:01:40 -07005417 || not_coded_vop
Shalaj Jain273b3e02012-06-22 19:08:03 -07005418
Arun Menon906de572013-06-18 17:01:40 -07005419 ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005420 DEBUG_PRINT_LOW("Flush in progress return buffer ");
Arun Menon906de572013-06-18 17:01:40 -07005421 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5422 OMX_COMPONENT_GENERATE_EBD);
5423 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005424 }
5425
Arun Menon906de572013-06-18 17:01:40 -07005426 temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005427
Surajit Podderd2644d52013-08-28 17:59:06 +05305428 if ((temp_buffer - drv_ctx.ptr_inputbuffer) > (int)drv_ctx.ip_buf.actualcount) {
Arun Menon906de572013-06-18 17:01:40 -07005429 return OMX_ErrorBadParameter;
5430 }
5431 /* If its first frame, H264 codec and reject is true, then parse the nal
5432 and get the profile. Based on this, reject the clip playback */
5433 if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 &&
5434 m_reject_avc_1080p_mp) {
5435 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005436 DEBUG_PRINT_ERROR("Parse nal to get the profile");
Arun Menon906de572013-06-18 17:01:40 -07005437 h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen,
5438 NALU_TYPE_SPS);
5439 m_profile = h264_parser->get_profile();
5440 ret = is_video_session_supported();
5441 if (ret) {
5442 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD);
5443 post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT);
5444 /* Move the state to Invalid to avoid queueing of pending ETB to the driver */
5445 m_state = OMX_StateInvalid;
5446 return OMX_ErrorNone;
5447 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005448 }
5449
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005450 DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
Arun Menon906de572013-06-18 17:01:40 -07005451 /*for use buffer we need to memcpy the data*/
5452 temp_buffer->buffer_len = buffer->nFilledLen;
5453
5454 if (input_use_buffer) {
5455 if (buffer->nFilledLen <= temp_buffer->buffer_len) {
5456 if (arbitrary_bytes) {
5457 memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen);
5458 } else {
5459 memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset),
5460 buffer->nFilledLen);
5461 }
5462 } else {
5463 return OMX_ErrorBadParameter;
5464 }
5465
5466 }
5467
5468 frameinfo.bufferaddr = temp_buffer->bufferaddr;
5469 frameinfo.client_data = (void *) buffer;
5470 frameinfo.datalen = temp_buffer->buffer_len;
5471 frameinfo.flags = 0;
5472 frameinfo.offset = buffer->nOffset;
5473 frameinfo.pmem_fd = temp_buffer->pmem_fd;
5474 frameinfo.pmem_offset = temp_buffer->offset;
5475 frameinfo.timestamp = buffer->nTimeStamp;
5476 if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) {
5477 DEBUG_PRINT_LOW("ETB: dmx enabled");
5478 if (m_demux_entries == 0) {
5479 extract_demux_addr_offsets(buffer);
5480 }
5481
5482 DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries);
5483 handle_demux_data(buffer);
5484 frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr;
5485 frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size;
5486 } else {
5487 frameinfo.desc_addr = NULL;
5488 frameinfo.desc_size = 0;
5489 }
5490 if (!arbitrary_bytes) {
5491 frameinfo.flags |= buffer->nFlags;
5492 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005493
5494#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005495 if (m_debug_timestamp) {
5496 if (arbitrary_bytes) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005497 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005498 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5499 } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005500 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005501 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5502 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005503 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005504#endif
5505
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005506log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005507
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005508if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Arun Menon906de572013-06-18 17:01:40 -07005509 frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5510 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5511 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005512
Arun Menon906de572013-06-18 17:01:40 -07005513 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005514 DEBUG_PRINT_HIGH("Rxd i/p EOS, Notify Driver that EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07005515 frameinfo.flags |= VDEC_BUFFERFLAG_EOS;
5516 h264_scratch.nFilledLen = 0;
5517 nal_count = 0;
5518 look_ahead_nal = false;
5519 frame_count = 0;
5520 if (m_frame_parser.mutils)
5521 m_frame_parser.mutils->initialize_frame_checking_environment();
5522 m_frame_parser.flush();
5523 h264_last_au_ts = LLONG_MAX;
5524 h264_last_au_flags = 0;
5525 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
5526 m_demux_entries = 0;
5527 }
5528 struct v4l2_buffer buf;
5529 struct v4l2_plane plane;
5530 memset( (void *)&buf, 0, sizeof(buf));
5531 memset( (void *)&plane, 0, sizeof(plane));
5532 int rc;
5533 unsigned long print_count;
5534 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07005535 buf.flags = V4L2_QCOM_BUF_FLAG_EOS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005536 DEBUG_PRINT_HIGH("INPUT EOS reached") ;
Arun Menon906de572013-06-18 17:01:40 -07005537 }
5538 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5539 buf.index = nPortIndex;
5540 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
5541 buf.memory = V4L2_MEMORY_USERPTR;
5542 plane.bytesused = temp_buffer->buffer_len;
5543 plane.length = drv_ctx.ip_buf.buffer_size;
5544 plane.m.userptr = (unsigned long)temp_buffer->bufferaddr -
5545 (unsigned long)temp_buffer->offset;
5546 plane.reserved[0] = temp_buffer->pmem_fd;
5547 plane.reserved[1] = temp_buffer->offset;
5548 plane.data_offset = 0;
5549 buf.m.planes = &plane;
5550 buf.length = 1;
5551 if (frameinfo.timestamp >= LLONG_MAX) {
5552 buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID;
5553 }
5554 //assumption is that timestamp is in milliseconds
5555 buf.timestamp.tv_sec = frameinfo.timestamp / 1000000;
5556 buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000);
5557 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0;
5558 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_DECODEONLY) ? V4L2_QCOM_BUF_FLAG_DECODEONLY: 0;
Deva Ramasubramanian46a17952012-08-24 11:35:26 -07005559
Arun Menon906de572013-06-18 17:01:40 -07005560 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
5561 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005562 DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver");
Arun Menon906de572013-06-18 17:01:40 -07005563 return OMX_ErrorHardware;
5564 }
5565 if (!streaming[OUTPUT_PORT]) {
5566 enum v4l2_buf_type buf_type;
5567 int ret,r;
Vinay Kalia85793762012-06-14 19:12:34 -07005568
Arun Menon906de572013-06-18 17:01:40 -07005569 buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005570 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07005571 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
5572 if (!ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005573 DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful");
Arun Menon906de572013-06-18 17:01:40 -07005574 streaming[OUTPUT_PORT] = true;
5575 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005576 DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT");
Arun Menon906de572013-06-18 17:01:40 -07005577 DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued");
5578 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5579 OMX_COMPONENT_GENERATE_EBD);
5580 return OMX_ErrorBadParameter;
5581 }
5582 }
5583 DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)",
5584 frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen);
5585 time_stamp_dts.insert_timestamp(buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005586
Arun Menon906de572013-06-18 17:01:40 -07005587 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005588}
5589
5590/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005591 FUNCTION
5592 omx_vdec::FillThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005593
Arun Menon906de572013-06-18 17:01:40 -07005594 DESCRIPTION
5595 IL client uses this method to release the frame buffer
5596 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005597
Arun Menon906de572013-06-18 17:01:40 -07005598 PARAMETERS
5599 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005600
Arun Menon906de572013-06-18 17:01:40 -07005601 RETURN VALUE
5602 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005603
Arun Menon906de572013-06-18 17:01:40 -07005604 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005605OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005606 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005607{
Arun Menonbdb80b02013-08-12 17:45:54 -07005608 if (dynamic_buf_mode) {
5609 private_handle_t *handle = NULL;
5610 struct VideoDecoderOutputMetaData *meta;
5611 OMX_U8 *buff = NULL;
5612 unsigned int nPortIndex = 0;
5613
5614 if (!buffer || !buffer->pBuffer) {
5615 DEBUG_PRINT_ERROR("%s: invalid params: %p %p", __FUNCTION__, buffer, buffer->pBuffer);
5616 return OMX_ErrorBadParameter;
5617 }
5618
5619 //get the buffer type and fd info
5620 meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer;
5621 handle = (private_handle_t *)meta->pHandle;
5622 DEBUG_PRINT_LOW("FTB: buftype: %d bufhndl: %p", meta->eType, meta->pHandle);
5623
5624 //map the buffer handle based on the size set on output port definition.
5625 if (!secure_mode) {
5626 buff = (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size,
5627 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
5628 } else {
5629 buff = (OMX_U8*) buffer;
5630 }
5631
5632 //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF
5633 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
5634 drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd;
5635 drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0;
5636 drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = buff;
5637 drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size;
5638 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size;
5639 buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd,
5640 drv_ctx.ptr_outputbuffer[nPortIndex].offset);
5641 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005642
Arun Menon906de572013-06-18 17:01:40 -07005643 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005644 DEBUG_PRINT_ERROR("FTB in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07005645 return OMX_ErrorInvalidState;
5646 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005647
Arun Menon906de572013-06-18 17:01:40 -07005648 if (!m_out_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005649 DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07005650 return OMX_ErrorIncorrectStateOperation;
5651 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005652
Arun Menon906de572013-06-18 17:01:40 -07005653 if (buffer == NULL ||
Surajit Podderd2644d52013-08-28 17:59:06 +05305654 ((buffer - client_buffers.get_il_buf_hdr()) >= (int)drv_ctx.op_buf.actualcount)) {
Arun Menon906de572013-06-18 17:01:40 -07005655 return OMX_ErrorBadParameter;
5656 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005657
Arun Menon906de572013-06-18 17:01:40 -07005658 if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005659 DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005660 return OMX_ErrorBadPortIndex;
5661 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005662
Arun Menon906de572013-06-18 17:01:40 -07005663 DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
5664 post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg);
5665 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005666}
5667/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005668 FUNCTION
5669 omx_vdec::fill_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07005670
Arun Menon906de572013-06-18 17:01:40 -07005671 DESCRIPTION
5672 IL client uses this method to release the frame buffer
5673 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005674
Arun Menon906de572013-06-18 17:01:40 -07005675 PARAMETERS
5676 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005677
Arun Menon906de572013-06-18 17:01:40 -07005678 RETURN VALUE
5679 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005680
Arun Menon906de572013-06-18 17:01:40 -07005681 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005682OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy(
Arun Menon906de572013-06-18 17:01:40 -07005683 OMX_IN OMX_HANDLETYPE hComp,
5684 OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005685{
Arun Menon906de572013-06-18 17:01:40 -07005686 OMX_ERRORTYPE nRet = OMX_ErrorNone;
5687 OMX_BUFFERHEADERTYPE *buffer = bufferAdd;
5688 unsigned nPortIndex = 0;
5689 struct vdec_fillbuffer_cmd fillbuffer;
5690 struct vdec_bufferpayload *ptr_outputbuffer = NULL;
5691 struct vdec_output_frameinfo *ptr_respbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005692
Arun Menon906de572013-06-18 17:01:40 -07005693 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
Shalaj Jain273b3e02012-06-22 19:08:03 -07005694
Arun Menon906de572013-06-18 17:01:40 -07005695 if (bufferAdd == NULL || nPortIndex > drv_ctx.op_buf.actualcount)
5696 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005697
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005698 DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07005699 bufferAdd, bufferAdd->pBuffer);
5700 /*Return back the output buffer to client*/
5701 if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005702 DEBUG_PRINT_LOW("Output Buffers return flush/disable condition");
Arun Menon906de572013-06-18 17:01:40 -07005703 buffer->nFilledLen = 0;
5704 m_cb.FillBufferDone (hComp,m_app_data,buffer);
5705 return OMX_ErrorNone;
5706 }
5707 pending_output_buffers++;
5708 buffer = client_buffers.get_dr_buf_hdr(bufferAdd);
5709 ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate;
5710 if (ptr_respbuffer) {
5711 ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data;
5712 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005713
Arun Menon906de572013-06-18 17:01:40 -07005714 if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) {
5715 DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL");
5716 buffer->nFilledLen = 0;
5717 m_cb.FillBufferDone (hComp,m_app_data,buffer);
5718 pending_output_buffers--;
5719 return OMX_ErrorBadParameter;
5720 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005721
Arun Menon906de572013-06-18 17:01:40 -07005722 int rc = 0;
5723 struct v4l2_buffer buf;
5724 struct v4l2_plane plane[VIDEO_MAX_PLANES];
5725 memset( (void *)&buf, 0, sizeof(buf));
5726 memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES));
5727 int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005728
Arun Menon906de572013-06-18 17:01:40 -07005729 buf.index = nPortIndex;
5730 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5731 buf.memory = V4L2_MEMORY_USERPTR;
5732 plane[0].bytesused = buffer->nFilledLen;
5733 plane[0].length = drv_ctx.op_buf.buffer_size;
5734 plane[0].m.userptr =
5735 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr -
5736 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset;
5737 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd;
5738 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset;
5739 plane[0].data_offset = 0;
5740 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
5741 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
5742 plane[extra_idx].bytesused = 0;
5743 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
5744 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 -07005745#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005746 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07005747#endif
Arun Menon906de572013-06-18 17:01:40 -07005748 plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size;
5749 plane[extra_idx].data_offset = 0;
5750 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005751 DEBUG_PRINT_ERROR("Extradata index higher than expected: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07005752 return OMX_ErrorBadParameter;
5753 }
5754 buf.m.planes = plane;
5755 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005756 DEBUG_PRINT_LOW("SENDING FTB TO F/W - fd[0] = %d fd[1] = %d offset[1] = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07005757 plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]);
5758
Arun Menon906de572013-06-18 17:01:40 -07005759 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
5760 if (rc) {
5761 /*TODO: How to handle this case */
5762 DEBUG_PRINT_ERROR("Failed to qbuf to driver");
5763 }
Arun Menon906de572013-06-18 17:01:40 -07005764return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005765}
5766
5767/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005768 FUNCTION
5769 omx_vdec::SetCallbacks
Shalaj Jain273b3e02012-06-22 19:08:03 -07005770
Arun Menon906de572013-06-18 17:01:40 -07005771 DESCRIPTION
5772 Set the callbacks.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005773
Arun Menon906de572013-06-18 17:01:40 -07005774 PARAMETERS
5775 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005776
Arun Menon906de572013-06-18 17:01:40 -07005777 RETURN VALUE
5778 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005779
Arun Menon906de572013-06-18 17:01:40 -07005780 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005781OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005782 OMX_IN OMX_CALLBACKTYPE* callbacks,
5783 OMX_IN OMX_PTR appData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005784{
5785
Arun Menon906de572013-06-18 17:01:40 -07005786 m_cb = *callbacks;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005787 DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\
Arun Menon906de572013-06-18 17:01:40 -07005788 m_cb.EventHandler,m_cb.FillBufferDone);
5789 m_app_data = appData;
5790 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005791}
5792
5793/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005794 FUNCTION
5795 omx_vdec::ComponentDeInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07005796
Arun Menon906de572013-06-18 17:01:40 -07005797 DESCRIPTION
5798 Destroys the component and release memory allocated to the heap.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005799
Arun Menon906de572013-06-18 17:01:40 -07005800 PARAMETERS
5801 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005802
Arun Menon906de572013-06-18 17:01:40 -07005803 RETURN VALUE
5804 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005805
Arun Menon906de572013-06-18 17:01:40 -07005806 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005807OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
5808{
5809#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005810 if (iDivXDrmDecrypt) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005811 delete iDivXDrmDecrypt;
5812 iDivXDrmDecrypt=NULL;
5813 }
5814#endif //_ANDROID_
5815
Shalaj Jain286b0062013-02-21 20:35:48 -08005816 unsigned i = 0;
Arun Menon906de572013-06-18 17:01:40 -07005817 if (OMX_StateLoaded != m_state) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005818 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\
Arun Menon906de572013-06-18 17:01:40 -07005819 m_state);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005820 DEBUG_PRINT_ERROR("Playback Ended - FAILED");
Arun Menon906de572013-06-18 17:01:40 -07005821 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005822 DEBUG_PRINT_HIGH("Playback Ended - PASSED");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005823 }
5824
5825 /*Check if the output buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07005826 if (m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005827 DEBUG_PRINT_LOW("Freeing the Output Memory");
Arun Menon906de572013-06-18 17:01:40 -07005828 for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) {
5829 free_output_buffer (&m_out_mem_ptr[i]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005830 }
5831#ifdef _ANDROID_ICS_
5832 memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
5833#endif
5834 }
5835
5836 /*Check if the input buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07005837 if (m_inp_mem_ptr || m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005838 DEBUG_PRINT_LOW("Freeing the Input Memory");
Arun Menon906de572013-06-18 17:01:40 -07005839 for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) {
5840 if (m_inp_mem_ptr)
5841 free_input_buffer (i,&m_inp_mem_ptr[i]);
5842 else
5843 free_input_buffer (i,NULL);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005844 }
5845 }
5846 free_input_buffer_header();
5847 free_output_buffer_header();
Arun Menon906de572013-06-18 17:01:40 -07005848 if (h264_scratch.pBuffer) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005849 free(h264_scratch.pBuffer);
5850 h264_scratch.pBuffer = NULL;
5851 }
5852
Arun Menon906de572013-06-18 17:01:40 -07005853 if (h264_parser) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005854 delete h264_parser;
Arun Menon906de572013-06-18 17:01:40 -07005855 h264_parser = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005856 }
5857
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07005858 if (m_frame_parser.mutils) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005859 DEBUG_PRINT_LOW("Free utils parser");
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07005860 delete (m_frame_parser.mutils);
5861 m_frame_parser.mutils = NULL;
5862 }
5863
Arun Menon906de572013-06-18 17:01:40 -07005864 if (m_platform_list) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005865 free(m_platform_list);
5866 m_platform_list = NULL;
5867 }
Arun Menon906de572013-06-18 17:01:40 -07005868 if (m_vendor_config.pData) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005869 free(m_vendor_config.pData);
5870 m_vendor_config.pData = NULL;
5871 }
5872
5873 // Reset counters in mesg queues
5874 m_ftb_q.m_size=0;
5875 m_cmd_q.m_size=0;
5876 m_etb_q.m_size=0;
5877 m_ftb_q.m_read = m_ftb_q.m_write =0;
5878 m_cmd_q.m_read = m_cmd_q.m_write =0;
5879 m_etb_q.m_read = m_etb_q.m_write =0;
5880#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005881 if (m_debug_timestamp) {
5882 m_timestamp_list.reset_ts_list();
Shalaj Jain273b3e02012-06-22 19:08:03 -07005883 }
5884#endif
5885
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005886 DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005887 //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG,
Arun Menon906de572013-06-18 17:01:40 -07005888 // NULL);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005889 DEBUG_PRINT_HIGH("Close the driver instance");
Arun Menon906de572013-06-18 17:01:40 -07005890
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005891 if (m_debug.infile) {
5892 fclose(m_debug.infile);
5893 m_debug.infile = NULL;
5894 }
5895 if (m_debug.outfile) {
5896 fclose(m_debug.outfile);
5897 m_debug.outfile = NULL;
5898 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005899#ifdef OUTPUT_EXTRADATA_LOG
Shalaj Jainaf08f302013-03-18 13:15:35 -07005900 if (outputExtradataFile)
5901 fclose (outputExtradataFile);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005902#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005903 DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete");
Arun Menon906de572013-06-18 17:01:40 -07005904 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005905}
5906
5907/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005908 FUNCTION
5909 omx_vdec::UseEGLImage
Shalaj Jain273b3e02012-06-22 19:08:03 -07005910
Arun Menon906de572013-06-18 17:01:40 -07005911 DESCRIPTION
5912 OMX Use EGL Image method implementation <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005913
Arun Menon906de572013-06-18 17:01:40 -07005914 PARAMETERS
5915 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005916
Arun Menon906de572013-06-18 17:01:40 -07005917 RETURN VALUE
5918 Not Implemented error.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005919
Arun Menon906de572013-06-18 17:01:40 -07005920 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005921OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005922 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5923 OMX_IN OMX_U32 port,
5924 OMX_IN OMX_PTR appData,
5925 OMX_IN void* eglImage)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005926{
Arun Menon906de572013-06-18 17:01:40 -07005927 OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list;
5928 OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry;
5929 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005930
5931#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07005932 PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc;
5933 EGLint fd = -1, offset = 0,pmemPtr = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005934#else
Arun Menon906de572013-06-18 17:01:40 -07005935 int fd = -1, offset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005936#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005937 DEBUG_PRINT_HIGH("use EGL image support for decoder");
Arun Menon906de572013-06-18 17:01:40 -07005938 if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005939 DEBUG_PRINT_ERROR("");
Arun Menon906de572013-06-18 17:01:40 -07005940 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005941#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07005942 if (m_display_id == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005943 DEBUG_PRINT_ERROR("Display ID is not set by IL client");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005944 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07005945 }
5946 egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC)
5947 eglGetProcAddress("eglQueryImageKHR");
5948 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd);
5949 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset);
5950 egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005951#else //with OMX test app
5952 struct temp_egl {
5953 int pmem_fd;
5954 int offset;
5955 };
5956 struct temp_egl *temp_egl_id = NULL;
5957 void * pmemPtr = (void *) eglImage;
5958 temp_egl_id = (struct temp_egl *)eglImage;
Arun Menon906de572013-06-18 17:01:40 -07005959 if (temp_egl_id != NULL) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005960 fd = temp_egl_id->pmem_fd;
5961 offset = temp_egl_id->offset;
5962 }
5963#endif
5964 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005965 DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005966 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07005967 }
5968 pmem_info.pmem_fd = (OMX_U32) fd;
5969 pmem_info.offset = (OMX_U32) offset;
5970 pmem_entry.entry = (void *) &pmem_info;
5971 pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
5972 pmem_list.entryList = &pmem_entry;
5973 pmem_list.nEntries = 1;
5974 ouput_egl_buffers = true;
5975 if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port,
5976 (void *)&pmem_list, drv_ctx.op_buf.buffer_size,
5977 (OMX_U8 *)pmemPtr)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005978 DEBUG_PRINT_ERROR("use buffer call failed for egl image");
Arun Menon906de572013-06-18 17:01:40 -07005979 return OMX_ErrorInsufficientResources;
5980 }
5981 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005982}
5983
5984/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005985 FUNCTION
5986 omx_vdec::ComponentRoleEnum
Shalaj Jain273b3e02012-06-22 19:08:03 -07005987
Arun Menon906de572013-06-18 17:01:40 -07005988 DESCRIPTION
5989 OMX Component Role Enum method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005990
Arun Menon906de572013-06-18 17:01:40 -07005991 PARAMETERS
5992 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005993
Arun Menon906de572013-06-18 17:01:40 -07005994 RETURN VALUE
5995 OMX Error None if everything is successful.
5996 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005997OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005998 OMX_OUT OMX_U8* role,
5999 OMX_IN OMX_U32 index)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006000{
Arun Menon906de572013-06-18 17:01:40 -07006001 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006002
Arun Menon906de572013-06-18 17:01:40 -07006003 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
6004 if ((0 == index) && role) {
6005 strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006006 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006007 } else {
6008 eRet = OMX_ErrorNoMore;
6009 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006010 }
Arun Menon906de572013-06-18 17:01:40 -07006011 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
6012 if ((0 == index) && role) {
6013 strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006014 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006015 } else {
6016 eRet = OMX_ErrorNoMore;
6017 }
6018 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
6019 if ((0 == index) && role) {
6020 strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006021 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006022 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006023 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006024 eRet = OMX_ErrorNoMore;
6025 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006026 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006027
Arun Menon906de572013-06-18 17:01:40 -07006028 else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
6029 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE))
6030 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07006031
Shalaj Jain273b3e02012-06-22 19:08:03 -07006032 {
Arun Menon906de572013-06-18 17:01:40 -07006033 if ((0 == index) && role) {
6034 strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006035 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006036 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006037 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006038 eRet = OMX_ErrorNoMore;
6039 }
6040 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
6041 if ((0 == index) && role) {
6042 strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006043 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006044 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006045 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006046 eRet = OMX_ErrorNoMore;
6047 }
6048 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
6049 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
6050 ) {
6051 if ((0 == index) && role) {
6052 strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006053 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006054 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006055 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006056 eRet = OMX_ErrorNoMore;
6057 }
6058 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
6059 if ((0 == index) && role) {
6060 strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006061 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006062 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006063 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006064 eRet = OMX_ErrorNoMore;
6065 }
6066 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006067 DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07006068 eRet = OMX_ErrorInvalidComponentName;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006069 }
Arun Menon906de572013-06-18 17:01:40 -07006070 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006071}
6072
6073
6074
6075
6076/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006077 FUNCTION
6078 omx_vdec::AllocateDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006079
Arun Menon906de572013-06-18 17:01:40 -07006080 DESCRIPTION
6081 Checks if entire buffer pool is allocated by IL Client or not.
6082 Need this to move to IDLE state.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006083
Arun Menon906de572013-06-18 17:01:40 -07006084 PARAMETERS
6085 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006086
Arun Menon906de572013-06-18 17:01:40 -07006087 RETURN VALUE
6088 true/false.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006089
Arun Menon906de572013-06-18 17:01:40 -07006090 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006091bool omx_vdec::allocate_done(void)
6092{
Arun Menon906de572013-06-18 17:01:40 -07006093 bool bRet = false;
6094 bool bRet_In = false;
6095 bool bRet_Out = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006096
Arun Menon906de572013-06-18 17:01:40 -07006097 bRet_In = allocate_input_done();
6098 bRet_Out = allocate_output_done();
Shalaj Jain273b3e02012-06-22 19:08:03 -07006099
Arun Menon906de572013-06-18 17:01:40 -07006100 if (bRet_In && bRet_Out) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006101 bRet = true;
6102 }
Arun Menon906de572013-06-18 17:01:40 -07006103
6104 return bRet;
6105}
6106/* ======================================================================
6107 FUNCTION
6108 omx_vdec::AllocateInputDone
6109
6110 DESCRIPTION
6111 Checks if I/P buffer pool is allocated by IL Client or not.
6112
6113 PARAMETERS
6114 None.
6115
6116 RETURN VALUE
6117 true/false.
6118
6119 ========================================================================== */
6120bool omx_vdec::allocate_input_done(void)
6121{
6122 bool bRet = false;
6123 unsigned i=0;
6124
6125 if (m_inp_mem_ptr == NULL) {
6126 return bRet;
6127 }
6128 if (m_inp_mem_ptr ) {
6129 for (; i<drv_ctx.ip_buf.actualcount; i++) {
6130 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
6131 break;
6132 }
6133 }
6134 }
6135 if (i == drv_ctx.ip_buf.actualcount) {
6136 bRet = true;
6137 DEBUG_PRINT_HIGH("Allocate done for all i/p buffers");
6138 }
6139 if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) {
6140 m_inp_bPopulated = OMX_TRUE;
6141 }
6142 return bRet;
6143}
6144/* ======================================================================
6145 FUNCTION
6146 omx_vdec::AllocateOutputDone
6147
6148 DESCRIPTION
6149 Checks if entire O/P buffer pool is allocated by IL Client or not.
6150
6151 PARAMETERS
6152 None.
6153
6154 RETURN VALUE
6155 true/false.
6156
6157 ========================================================================== */
6158bool omx_vdec::allocate_output_done(void)
6159{
6160 bool bRet = false;
6161 unsigned j=0;
6162
6163 if (m_out_mem_ptr == NULL) {
6164 return bRet;
6165 }
6166
6167 if (m_out_mem_ptr) {
6168 for (; j < drv_ctx.op_buf.actualcount; j++) {
6169 if (BITMASK_ABSENT(&m_out_bm_count,j)) {
6170 break;
6171 }
6172 }
6173 }
6174
6175 if (j == drv_ctx.op_buf.actualcount) {
6176 bRet = true;
6177 DEBUG_PRINT_HIGH("Allocate done for all o/p buffers");
6178 if (m_out_bEnabled)
6179 m_out_bPopulated = OMX_TRUE;
6180 }
6181
6182 return bRet;
6183}
6184
6185/* ======================================================================
6186 FUNCTION
6187 omx_vdec::ReleaseDone
6188
6189 DESCRIPTION
6190 Checks if IL client has released all the buffers.
6191
6192 PARAMETERS
6193 None.
6194
6195 RETURN VALUE
6196 true/false
6197
6198 ========================================================================== */
6199bool omx_vdec::release_done(void)
6200{
6201 bool bRet = false;
6202
6203 if (release_input_done()) {
6204 if (release_output_done()) {
6205 bRet = true;
6206 }
6207 }
6208 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006209}
6210
6211
6212/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006213 FUNCTION
6214 omx_vdec::ReleaseOutputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006215
Arun Menon906de572013-06-18 17:01:40 -07006216 DESCRIPTION
6217 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006218
Arun Menon906de572013-06-18 17:01:40 -07006219 PARAMETERS
6220 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006221
Arun Menon906de572013-06-18 17:01:40 -07006222 RETURN VALUE
6223 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006224
Arun Menon906de572013-06-18 17:01:40 -07006225 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006226bool omx_vdec::release_output_done(void)
6227{
Arun Menon906de572013-06-18 17:01:40 -07006228 bool bRet = false;
6229 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006230
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006231 DEBUG_PRINT_LOW("Value of m_out_mem_ptr %p",m_inp_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006232 if (m_out_mem_ptr) {
6233 for (; j < drv_ctx.op_buf.actualcount ; j++) {
6234 if (BITMASK_PRESENT(&m_out_bm_count,j)) {
6235 break;
6236 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006237 }
Arun Menon906de572013-06-18 17:01:40 -07006238 if (j == drv_ctx.op_buf.actualcount) {
6239 m_out_bm_count = 0;
6240 bRet = true;
6241 }
6242 } else {
6243 m_out_bm_count = 0;
6244 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006245 }
Arun Menon906de572013-06-18 17:01:40 -07006246 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006247}
6248/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006249 FUNCTION
6250 omx_vdec::ReleaseInputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006251
Arun Menon906de572013-06-18 17:01:40 -07006252 DESCRIPTION
6253 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006254
Arun Menon906de572013-06-18 17:01:40 -07006255 PARAMETERS
6256 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006257
Arun Menon906de572013-06-18 17:01:40 -07006258 RETURN VALUE
6259 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006260
Arun Menon906de572013-06-18 17:01:40 -07006261 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006262bool omx_vdec::release_input_done(void)
6263{
Arun Menon906de572013-06-18 17:01:40 -07006264 bool bRet = false;
6265 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006266
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006267 DEBUG_PRINT_LOW("Value of m_inp_mem_ptr %p",m_inp_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006268 if (m_inp_mem_ptr) {
6269 for (; j<drv_ctx.ip_buf.actualcount; j++) {
6270 if ( BITMASK_PRESENT(&m_inp_bm_count,j)) {
6271 break;
6272 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006273 }
Arun Menon906de572013-06-18 17:01:40 -07006274 if (j==drv_ctx.ip_buf.actualcount) {
6275 bRet = true;
6276 }
6277 } else {
6278 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006279 }
Arun Menon906de572013-06-18 17:01:40 -07006280 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006281}
6282
6283OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006284 OMX_BUFFERHEADERTYPE * buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006285{
Arun Menon906de572013-06-18 17:01:40 -07006286 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL;
Surajit Podderd2644d52013-08-28 17:59:06 +05306287 if (!buffer || (buffer - m_out_mem_ptr) >= (int)drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006288 DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer);
Arun Menon906de572013-06-18 17:01:40 -07006289 return OMX_ErrorBadParameter;
6290 } else if (output_flush_progress) {
6291 DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer);
6292 buffer->nFilledLen = 0;
6293 buffer->nTimeStamp = 0;
6294 buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA;
6295 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
6296 buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT;
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006297 }
6298
Arun Menon906de572013-06-18 17:01:40 -07006299 if (m_debug_extradata) {
6300 if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006301 DEBUG_PRINT_HIGH("");
6302 DEBUG_PRINT_HIGH("***************************************************");
6303 DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received");
6304 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006305 }
6306
6307 if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006308 DEBUG_PRINT_HIGH("");
6309 DEBUG_PRINT_HIGH("***************************************************");
6310 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
6311 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006312 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006313 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006314
6315
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006316 DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006317 buffer, buffer->pBuffer);
6318 pending_output_buffers --;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006319
Arun Menonbdb80b02013-08-12 17:45:54 -07006320 if (dynamic_buf_mode && !secure_mode) {
6321 unsigned int nPortIndex = 0;
6322 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
6323 munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr,
6324 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size);
6325 }
Arun Menon906de572013-06-18 17:01:40 -07006326 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006327 DEBUG_PRINT_HIGH("Output EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07006328 if (!output_flush_progress)
6329 post_event((unsigned)NULL, (unsigned)NULL,
6330 OMX_COMPONENT_GENERATE_EOS_DONE);
6331
6332 if (psource_frame) {
6333 m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame);
6334 psource_frame = NULL;
6335 }
6336 if (pdest_frame) {
6337 pdest_frame->nFilledLen = 0;
6338 m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL,
6339 (unsigned)NULL);
6340 pdest_frame = NULL;
6341 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006342 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006343
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006344 DEBUG_PRINT_LOW("In fill Buffer done call address %p ",buffer);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07006345 log_output_buffers(buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006346
Praneeth Paladugudd29c282013-09-12 15:41:47 -07006347 if (!output_flush_progress && (buffer->nFilledLen > 0)) {
6348 DEBUG_PRINT_LOW("Processing extradata");
6349 handle_extradata(buffer);
6350 }
6351
Arun Menon906de572013-06-18 17:01:40 -07006352 /* For use buffer we need to copy the data */
6353 if (!output_flush_progress) {
6354 /* This is the error check for non-recoverable errros */
6355 bool is_duplicate_ts_valid = true;
6356 bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006357
Arun Menon906de572013-06-18 17:01:40 -07006358 if (output_capability == V4L2_PIX_FMT_MPEG4 ||
6359 output_capability == V4L2_PIX_FMT_MPEG2 ||
6360 output_capability == V4L2_PIX_FMT_DIVX ||
6361 output_capability == V4L2_PIX_FMT_DIVX_311)
6362 is_duplicate_ts_valid = false;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006363
Arun Menon906de572013-06-18 17:01:40 -07006364 if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) {
6365 bool mbaff = (h264_parser)? (h264_parser->is_mbaff()): false;
6366 if (mbaff) {
6367 is_interlaced = false;
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306368 }
Arun Menon906de572013-06-18 17:01:40 -07006369 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306370
Arun Menon906de572013-06-18 17:01:40 -07006371 if (buffer->nFilledLen > 0) {
6372 time_stamp_dts.get_next_timestamp(buffer,
6373 is_interlaced && is_duplicate_ts_valid);
6374 if (m_debug_timestamp) {
6375 {
6376 OMX_TICKS expected_ts = 0;
6377 m_timestamp_list.pop_min_ts(expected_ts);
6378 if (is_interlaced && is_duplicate_ts_valid) {
6379 m_timestamp_list.pop_min_ts(expected_ts);
6380 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006381 DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list",
Arun Menon906de572013-06-18 17:01:40 -07006382 buffer->nTimeStamp, expected_ts);
6383
6384 if (buffer->nTimeStamp != expected_ts) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006385 DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check");
Arun Menon906de572013-06-18 17:01:40 -07006386 }
6387 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306388 }
Arun Menon906de572013-06-18 17:01:40 -07006389 } else {
6390 m_inp_err_count++;
6391 time_stamp_dts.remove_time_stamp(
6392 buffer->nTimeStamp,
6393 is_interlaced && is_duplicate_ts_valid);
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306394 }
Arun Menon906de572013-06-18 17:01:40 -07006395
6396
Praneeth Paladugu8f12e822013-03-11 18:47:58 -07006397 }
Arun Menon906de572013-06-18 17:01:40 -07006398 if (m_cb.FillBufferDone) {
6399 if (buffer->nFilledLen > 0) {
Arun Menon906de572013-06-18 17:01:40 -07006400 if (client_extradata & OMX_TIMEINFO_EXTRADATA)
6401 set_frame_rate(buffer->nTimeStamp);
6402 else if (arbitrary_bytes)
6403 adjust_timestamp(buffer->nTimeStamp);
6404 if (perf_flag) {
6405 if (!proc_frms) {
6406 dec_time.stop();
6407 latency = dec_time.processing_time_us() - latency;
6408 DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3);
6409 dec_time.start();
6410 fps_metrics.start();
6411 }
6412 proc_frms++;
6413 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6414 OMX_U64 proc_time = 0;
6415 fps_metrics.stop();
6416 proc_time = fps_metrics.processing_time_us();
6417 DEBUG_PRINT_HIGH(">>> FBD Metrics: proc_frms(%lu) proc_time(%.2f)S fps(%.2f)",
Shalaj Jain273b3e02012-06-22 19:08:03 -07006418 proc_frms, (float)proc_time / 1e6,
6419 (float)(1e6 * proc_frms) / proc_time);
Arun Menon906de572013-06-18 17:01:40 -07006420 proc_frms = 0;
6421 }
6422 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006423
6424#ifdef OUTPUT_EXTRADATA_LOG
Arun Menon906de572013-06-18 17:01:40 -07006425 if (outputExtradataFile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006426
Arun Menon906de572013-06-18 17:01:40 -07006427 OMX_OTHER_EXTRADATATYPE *p_extra = NULL;
6428 p_extra = (OMX_OTHER_EXTRADATATYPE *)
6429 ((unsigned)(buffer->pBuffer + buffer->nOffset +
6430 buffer->nFilledLen + 3)&(~3));
6431 while (p_extra &&
6432 (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006433 DEBUG_PRINT_LOW("WRITING extradata, size=%d,type=%d",p_extra->nSize, p_extra->eType);
Arun Menon906de572013-06-18 17:01:40 -07006434 fwrite (p_extra,1,p_extra->nSize,outputExtradataFile);
6435 if (p_extra->eType == OMX_ExtraDataNone) {
6436 break;
6437 }
6438 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
6439 }
6440 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006441#endif
Arun Menon906de572013-06-18 17:01:40 -07006442 }
6443 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6444 prev_ts = LLONG_MAX;
6445 rst_prev_ts = true;
6446 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006447
Arun Menon906de572013-06-18 17:01:40 -07006448 pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
6449 ((OMX_QCOM_PLATFORM_PRIVATE_LIST *)
6450 buffer->pPlatformPrivate)->entryList->entry;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006451 DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07006452 OMX_BUFFERHEADERTYPE *il_buffer;
6453 il_buffer = client_buffers.get_il_buf_hdr(buffer);
6454 if (il_buffer)
6455 m_cb.FillBufferDone (hComp,m_app_data,il_buffer);
6456 else {
6457 DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr");
6458 return OMX_ErrorBadParameter;
6459 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006460 DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07006461 } else {
6462 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08006463 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006464
Arun Menon906de572013-06-18 17:01:40 -07006465 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006466}
6467
6468OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006469 OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006470{
6471
Surajit Podderd2644d52013-08-28 17:59:06 +05306472 if (buffer == NULL || ((buffer - m_inp_mem_ptr) > (int)drv_ctx.ip_buf.actualcount)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006473 DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer);
Arun Menon906de572013-06-18 17:01:40 -07006474 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006475 }
6476
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006477 DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006478 buffer, buffer->pBuffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006479 pending_input_buffers--;
6480
Arun Menon906de572013-06-18 17:01:40 -07006481 if (arbitrary_bytes) {
6482 if (pdest_frame == NULL && input_flush_progress == false) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006483 DEBUG_PRINT_LOW("Push input from buffer done address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07006484 pdest_frame = buffer;
6485 buffer->nFilledLen = 0;
6486 buffer->nTimeStamp = LLONG_MAX;
6487 push_input_buffer (hComp);
6488 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006489 DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07006490 buffer->nFilledLen = 0;
6491 if (!m_input_free_q.insert_entry((unsigned)buffer,
6492 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006493 DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error");
Arun Menon906de572013-06-18 17:01:40 -07006494 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006495 }
Arun Menon906de572013-06-18 17:01:40 -07006496 } else if (m_cb.EmptyBufferDone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006497 buffer->nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07006498 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006499 buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr];
6500 }
6501 m_cb.EmptyBufferDone(hComp ,m_app_data, buffer);
6502 }
6503 return OMX_ErrorNone;
6504}
6505
Shalaj Jain273b3e02012-06-22 19:08:03 -07006506int omx_vdec::async_message_process (void *context, void* message)
6507{
Arun Menon906de572013-06-18 17:01:40 -07006508 omx_vdec* omx = NULL;
6509 struct vdec_msginfo *vdec_msg = NULL;
6510 OMX_BUFFERHEADERTYPE* omxhdr = NULL;
6511 struct v4l2_buffer *v4l2_buf_ptr = NULL;
6512 struct vdec_output_frameinfo *output_respbuf = NULL;
6513 int rc=1;
6514 if (context == NULL || message == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006515 DEBUG_PRINT_ERROR("FATAL ERROR in omx_vdec::async_message_process NULL Check");
Arun Menon906de572013-06-18 17:01:40 -07006516 return -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006517 }
Arun Menon906de572013-06-18 17:01:40 -07006518 vdec_msg = (struct vdec_msginfo *)message;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006519
Arun Menon906de572013-06-18 17:01:40 -07006520 omx = reinterpret_cast<omx_vdec*>(context);
Vinay Kaliab9e98102013-04-02 19:31:43 -07006521
Arun Menon906de572013-06-18 17:01:40 -07006522 switch (vdec_msg->msgcode) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006523
Arun Menon906de572013-06-18 17:01:40 -07006524 case VDEC_MSG_EVT_HW_ERROR:
6525 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6526 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
6527 break;
6528
6529 case VDEC_MSG_RESP_START_DONE:
6530 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6531 OMX_COMPONENT_GENERATE_START_DONE);
6532 break;
6533
6534 case VDEC_MSG_RESP_STOP_DONE:
6535 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6536 OMX_COMPONENT_GENERATE_STOP_DONE);
6537 break;
6538
6539 case VDEC_MSG_RESP_RESUME_DONE:
6540 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6541 OMX_COMPONENT_GENERATE_RESUME_DONE);
6542 break;
6543
6544 case VDEC_MSG_RESP_PAUSE_DONE:
6545 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6546 OMX_COMPONENT_GENERATE_PAUSE_DONE);
6547 break;
6548
6549 case VDEC_MSG_RESP_FLUSH_INPUT_DONE:
6550 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6551 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
6552 break;
6553 case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE:
6554 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
6555 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
6556 break;
6557 case VDEC_MSG_RESP_INPUT_FLUSHED:
6558 case VDEC_MSG_RESP_INPUT_BUFFER_DONE:
6559
6560 /* omxhdr = (OMX_BUFFERHEADERTYPE* )
6561 vdec_msg->msgdata.input_frame_clientdata; */
6562
6563 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata;
6564 omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index;
6565 if (omxhdr == NULL ||
Surajit Podderd2644d52013-08-28 17:59:06 +05306566 ((omxhdr - omx->m_inp_mem_ptr) > (int)omx->drv_ctx.ip_buf.actualcount) ) {
Arun Menon906de572013-06-18 17:01:40 -07006567 omxhdr = NULL;
6568 vdec_msg->status_code = VDEC_S_EFATAL;
6569 }
6570 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) {
6571 DEBUG_PRINT_HIGH("Unsupported input");
6572 omx->omx_report_error ();
6573 }
6574 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
6575 vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR;
6576 }
6577 omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code,
6578 OMX_COMPONENT_GENERATE_EBD);
6579 break;
6580 case VDEC_MSG_EVT_INFO_FIELD_DROPPED:
6581 int64_t *timestamp;
6582 timestamp = (int64_t *) malloc(sizeof(int64_t));
6583 if (timestamp) {
6584 *timestamp = vdec_msg->msgdata.output_frame.time_stamp;
6585 omx->post_event ((unsigned int)timestamp, vdec_msg->status_code,
6586 OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006587 DEBUG_PRINT_HIGH("Field dropped time stamp is %lld",
Arun Menon906de572013-06-18 17:01:40 -07006588 vdec_msg->msgdata.output_frame.time_stamp);
6589 }
6590 break;
6591 case VDEC_MSG_RESP_OUTPUT_FLUSHED:
6592 case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE:
6593
6594 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data;
6595 omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index;
6596 DEBUG_PRINT_LOW("[RespBufDone] Buf(%p) Ts(%lld) Pic_type(%u)",
6597 omxhdr, vdec_msg->msgdata.output_frame.time_stamp,
6598 vdec_msg->msgdata.output_frame.pic_type);
6599
6600 if (omxhdr && omxhdr->pOutputPortPrivate &&
Surajit Podderd2644d52013-08-28 17:59:06 +05306601 ((omxhdr - omx->m_out_mem_ptr) < (int)omx->drv_ctx.op_buf.actualcount) &&
Arun Menon906de572013-06-18 17:01:40 -07006602 (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate
Surajit Podderd2644d52013-08-28 17:59:06 +05306603 - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) {
Arun Menonbdb80b02013-08-12 17:45:54 -07006604 if (omx->dynamic_buf_mode && vdec_msg->msgdata.output_frame.len) {
6605 vdec_msg->msgdata.output_frame.len = omxhdr->nAllocLen;
6606 }
Arun Menon906de572013-06-18 17:01:40 -07006607 if ( vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) {
6608 omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len;
6609 omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset;
6610 omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp;
6611 omxhdr->nFlags = 0;
6612
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07006613 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) {
Arun Menon906de572013-06-18 17:01:40 -07006614 omxhdr->nFlags |= OMX_BUFFERFLAG_EOS;
6615 //rc = -1;
6616 }
6617 if (omxhdr->nFilledLen) {
6618 omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
6619 }
6620 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) {
6621 omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
6622 } else {
6623 omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME;
6624 }
6625 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) {
6626 omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
6627 }
6628 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) {
6629 omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY;
6630 }
Arun Menonbdb80b02013-08-12 17:45:54 -07006631 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) {
Arun Menone50f6ef2013-09-30 15:08:27 -07006632 omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY;
Arun Menonbdb80b02013-08-12 17:45:54 -07006633 DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d",
6634 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd);
6635 }
Arun Menonbdb80b02013-08-12 17:45:54 -07006636 if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) {
6637 omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd,
6638 omxhdr->nOffset);
6639 }
Arun Menon906de572013-06-18 17:01:40 -07006640 if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) &&
6641 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) &&
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07006642 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) {
Praneeth Paladugu17364df2013-07-30 11:34:16 -07006643 omx->time_stamp_dts.remove_time_stamp(
6644 omxhdr->nTimeStamp,
6645 (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
6646 ?true:false);
Arun Menon906de572013-06-18 17:01:40 -07006647 omx->post_event ((unsigned)NULL,(unsigned int)omxhdr,
6648 OMX_COMPONENT_GENERATE_FTB);
6649 break;
6650 }
6651 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
6652 omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
6653 }
6654 vdec_msg->msgdata.output_frame.bufferaddr =
6655 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr;
6656 int format_notably_changed = 0;
6657 if (omxhdr->nFilledLen &&
Surajit Podderd2644d52013-08-28 17:59:06 +05306658 (omxhdr->nFilledLen != (unsigned)omx->prev_n_filled_len)) {
Arun Menon906de572013-06-18 17:01:40 -07006659 if ((vdec_msg->msgdata.output_frame.framesize.bottom != omx->drv_ctx.video_resolution.frame_height) ||
6660 (vdec_msg->msgdata.output_frame.framesize.right != omx->drv_ctx.video_resolution.frame_width)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006661 DEBUG_PRINT_HIGH("Height/Width information has changed");
Arun Menon906de572013-06-18 17:01:40 -07006662 omx->drv_ctx.video_resolution.frame_height = vdec_msg->msgdata.output_frame.framesize.bottom;
6663 omx->drv_ctx.video_resolution.frame_width = vdec_msg->msgdata.output_frame.framesize.right;
6664 format_notably_changed = 1;
6665 }
6666 }
6667 if (omxhdr->nFilledLen && (((unsigned)omx->rectangle.nLeft !=
6668 vdec_msg->msgdata.output_frame.framesize.left)
6669 || ((unsigned)omx->rectangle.nTop != vdec_msg->msgdata.output_frame.framesize.top)
6670 || (omx->rectangle.nWidth != vdec_msg->msgdata.output_frame.framesize.right)
6671 || (omx->rectangle.nHeight != vdec_msg->msgdata.output_frame.framesize.bottom))) {
6672 if ((vdec_msg->msgdata.output_frame.framesize.bottom != omx->drv_ctx.video_resolution.frame_height) ||
6673 (vdec_msg->msgdata.output_frame.framesize.right != omx->drv_ctx.video_resolution.frame_width)) {
6674 omx->drv_ctx.video_resolution.frame_height = vdec_msg->msgdata.output_frame.framesize.bottom;
6675 omx->drv_ctx.video_resolution.frame_width = vdec_msg->msgdata.output_frame.framesize.right;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006676 DEBUG_PRINT_HIGH("Height/Width information has changed. W: %d --> %d, H: %d --> %d",
Arun Menon906de572013-06-18 17:01:40 -07006677 omx->drv_ctx.video_resolution.frame_width, vdec_msg->msgdata.output_frame.framesize.right,
6678 omx->drv_ctx.video_resolution.frame_height, vdec_msg->msgdata.output_frame.framesize.bottom);
6679 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006680 DEBUG_PRINT_HIGH("Crop information changed. W: %lu --> %d, H: %lu -> %d",
Arun Menon906de572013-06-18 17:01:40 -07006681 omx->rectangle.nWidth, vdec_msg->msgdata.output_frame.framesize.right,
6682 omx->rectangle.nHeight, vdec_msg->msgdata.output_frame.framesize.bottom);
Jayasena Sangaraboina20283de2013-08-13 11:41:41 -07006683 if (vdec_msg->msgdata.output_frame.framesize.left + vdec_msg->msgdata.output_frame.framesize.right >=
6684 omx->drv_ctx.video_resolution.frame_width) {
6685 vdec_msg->msgdata.output_frame.framesize.left = 0;
6686 if (vdec_msg->msgdata.output_frame.framesize.right > omx->drv_ctx.video_resolution.frame_width) {
6687 vdec_msg->msgdata.output_frame.framesize.right = omx->drv_ctx.video_resolution.frame_width;
6688 }
6689 }
6690 if (vdec_msg->msgdata.output_frame.framesize.top + vdec_msg->msgdata.output_frame.framesize.bottom >=
6691 omx->drv_ctx.video_resolution.frame_height) {
6692 vdec_msg->msgdata.output_frame.framesize.top = 0;
6693 if (vdec_msg->msgdata.output_frame.framesize.bottom > omx->drv_ctx.video_resolution.frame_height) {
6694 vdec_msg->msgdata.output_frame.framesize.bottom = omx->drv_ctx.video_resolution.frame_height;
6695 }
6696 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006697 DEBUG_PRINT_LOW("omx_vdec: Adjusted Dim L: %d, T: %d, R: %d, B: %d, W: %d, H: %d",
Jayasena Sangaraboina20283de2013-08-13 11:41:41 -07006698 vdec_msg->msgdata.output_frame.framesize.left,
6699 vdec_msg->msgdata.output_frame.framesize.top,
6700 vdec_msg->msgdata.output_frame.framesize.right,
6701 vdec_msg->msgdata.output_frame.framesize.bottom,
6702 omx->drv_ctx.video_resolution.frame_width,
6703 omx->drv_ctx.video_resolution.frame_height);
Arun Menon906de572013-06-18 17:01:40 -07006704 omx->rectangle.nLeft = vdec_msg->msgdata.output_frame.framesize.left;
6705 omx->rectangle.nTop = vdec_msg->msgdata.output_frame.framesize.top;
6706 omx->rectangle.nWidth = vdec_msg->msgdata.output_frame.framesize.right;
6707 omx->rectangle.nHeight = vdec_msg->msgdata.output_frame.framesize.bottom;
6708 format_notably_changed = 1;
6709 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006710 DEBUG_PRINT_HIGH("Left: %d, Right: %d, top: %d, Bottom: %d",
Jayasena Sangaraboina20283de2013-08-13 11:41:41 -07006711 vdec_msg->msgdata.output_frame.framesize.left,vdec_msg->msgdata.output_frame.framesize.right,
6712 vdec_msg->msgdata.output_frame.framesize.top, vdec_msg->msgdata.output_frame.framesize.bottom);
Arun Menon906de572013-06-18 17:01:40 -07006713 if (format_notably_changed) {
6714 if (omx->is_video_session_supported()) {
Surajit Podderd2644d52013-08-28 17:59:06 +05306715 omx->post_event (0, vdec_msg->status_code,
Arun Menon906de572013-06-18 17:01:40 -07006716 OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING);
6717 } else {
6718 if (!omx->client_buffers.update_buffer_req()) {
6719 DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed");
6720 }
6721 omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexConfigCommonOutputCrop,
6722 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
6723 }
6724 }
6725 if (omxhdr->nFilledLen)
6726 omx->prev_n_filled_len = omxhdr->nFilledLen;
6727
6728 output_respbuf = (struct vdec_output_frameinfo *)\
6729 omxhdr->pOutputPortPrivate;
6730 output_respbuf->len = vdec_msg->msgdata.output_frame.len;
6731 output_respbuf->offset = vdec_msg->msgdata.output_frame.offset;
6732 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) {
6733 output_respbuf->pic_type = PICTURE_TYPE_I;
6734 }
6735 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) {
6736 output_respbuf->pic_type = PICTURE_TYPE_P;
6737 }
6738 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) {
6739 output_respbuf->pic_type = PICTURE_TYPE_B;
6740 }
6741
6742 if (omx->output_use_buffer)
6743 memcpy ( omxhdr->pBuffer, (void *)
6744 ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr +
6745 (unsigned long)vdec_msg->msgdata.output_frame.offset),
6746 vdec_msg->msgdata.output_frame.len);
6747 } else
6748 omxhdr->nFilledLen = 0;
6749 omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code,
6750 OMX_COMPONENT_GENERATE_FBD);
6751 } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS)
6752 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
6753 OMX_COMPONENT_GENERATE_EOS_DONE);
6754 else
6755 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
6756 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
6757 break;
6758 case VDEC_MSG_EVT_CONFIG_CHANGED:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006759 DEBUG_PRINT_HIGH("Port settings changed");
Arun Menon906de572013-06-18 17:01:40 -07006760 omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition,
6761 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
6762 break;
6763 default:
6764 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006765 }
Arun Menon906de572013-06-18 17:01:40 -07006766 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006767}
6768
6769OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary (
Arun Menon906de572013-06-18 17:01:40 -07006770 OMX_HANDLETYPE hComp,
6771 OMX_BUFFERHEADERTYPE *buffer
6772 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07006773{
Arun Menon906de572013-06-18 17:01:40 -07006774 unsigned address,p2,id;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006775 DEBUG_PRINT_LOW("Empty this arbitrary");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006776
Arun Menon906de572013-06-18 17:01:40 -07006777 if (buffer == NULL) {
6778 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006779 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006780 DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
6781 DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07006782 buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp);
6783
6784 /* return zero length and not an EOS buffer */
6785 /* return buffer if input flush in progress */
6786 if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) &&
6787 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006788 DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress");
Arun Menon906de572013-06-18 17:01:40 -07006789 m_cb.EmptyBufferDone (hComp,m_app_data,buffer);
6790 return OMX_ErrorNone;
6791 }
6792
6793 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006794 DEBUG_PRINT_LOW("Set Buffer as source Buffer %p time stamp %lld",buffer,buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07006795 psource_frame = buffer;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006796 DEBUG_PRINT_LOW("Try to Push One Input Buffer ");
Arun Menon906de572013-06-18 17:01:40 -07006797 push_input_buffer (hComp);
6798 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006799 DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07006800 if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL,
6801 (unsigned)NULL)) {
6802 return OMX_ErrorBadParameter;
6803 }
6804 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006805
6806
Arun Menon906de572013-06-18 17:01:40 -07006807 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006808}
6809
6810OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp)
6811{
Arun Menon906de572013-06-18 17:01:40 -07006812 unsigned address,p2,id;
6813 OMX_ERRORTYPE ret = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006814
Arun Menon906de572013-06-18 17:01:40 -07006815 if (pdest_frame == NULL || psource_frame == NULL) {
6816 /*Check if we have a destination buffer*/
6817 if (pdest_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006818 DEBUG_PRINT_LOW("Get a Destination buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07006819 if (m_input_free_q.m_size) {
6820 m_input_free_q.pop_entry(&address,&p2,&id);
6821 pdest_frame = (OMX_BUFFERHEADERTYPE *)address;
6822 pdest_frame->nFilledLen = 0;
6823 pdest_frame->nTimeStamp = LLONG_MAX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006824 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07006825 }
6826 }
6827
6828 /*Check if we have a destination buffer*/
6829 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006830 DEBUG_PRINT_LOW("Get a source buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07006831 if (m_input_pending_q.m_size) {
6832 m_input_pending_q.pop_entry(&address,&p2,&id);
6833 psource_frame = (OMX_BUFFERHEADERTYPE *)address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006834 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07006835 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006836 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07006837 psource_frame->nFlags,psource_frame->nFilledLen);
6838
6839 }
6840 }
6841
Shalaj Jain273b3e02012-06-22 19:08:03 -07006842 }
6843
Arun Menon906de572013-06-18 17:01:40 -07006844 while ((pdest_frame != NULL) && (psource_frame != NULL)) {
6845 switch (codec_type_parse) {
6846 case CODEC_TYPE_MPEG4:
6847 case CODEC_TYPE_H263:
6848 case CODEC_TYPE_MPEG2:
6849 ret = push_input_sc_codec(hComp);
6850 break;
6851 case CODEC_TYPE_H264:
6852 ret = push_input_h264(hComp);
6853 break;
6854 case CODEC_TYPE_VC1:
6855 ret = push_input_vc1(hComp);
6856 break;
6857 default:
6858 break;
6859 }
6860 if (ret != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006861 DEBUG_PRINT_ERROR("Pushing input Buffer Failed");
Arun Menon906de572013-06-18 17:01:40 -07006862 omx_report_error ();
6863 break;
6864 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006865 }
6866
Arun Menon906de572013-06-18 17:01:40 -07006867 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006868}
6869
6870OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp)
6871{
Arun Menon906de572013-06-18 17:01:40 -07006872 OMX_U32 partial_frame = 1;
6873 OMX_BOOL generate_ebd = OMX_TRUE;
6874 unsigned address = 0, p2 = 0, id = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006875
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006876 DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07006877 psource_frame,psource_frame->nTimeStamp);
6878 if (m_frame_parser.parse_sc_frame(psource_frame,
6879 pdest_frame,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006880 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Arun Menon906de572013-06-18 17:01:40 -07006881 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006882 }
Arun Menon906de572013-06-18 17:01:40 -07006883
6884 if (partial_frame == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006885 DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d",
Arun Menon906de572013-06-18 17:01:40 -07006886 pdest_frame->nFilledLen,psource_frame,frame_count);
6887
6888
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006889 DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07006890 /*First Parsed buffer will have only header Hence skip*/
6891 if (frame_count == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006892 DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame ");
Arun Menon906de572013-06-18 17:01:40 -07006893
6894 if (codec_type_parse == CODEC_TYPE_MPEG4 ||
6895 codec_type_parse == CODEC_TYPE_DIVX) {
6896 mp4StreamType psBits;
6897 psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset;
6898 psBits.numBytes = pdest_frame->nFilledLen;
6899 mp4_headerparser.parseHeader(&psBits);
6900 }
6901
6902 frame_count++;
6903 } else {
6904 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
6905 if (pdest_frame->nFilledLen) {
6906 /*Push the frame to the Decoder*/
6907 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
6908 return OMX_ErrorBadParameter;
6909 }
6910 frame_count++;
6911 pdest_frame = NULL;
6912
6913 if (m_input_free_q.m_size) {
6914 m_input_free_q.pop_entry(&address,&p2,&id);
6915 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
6916 pdest_frame->nFilledLen = 0;
6917 }
6918 } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006919 DEBUG_PRINT_ERROR("Zero len buffer return back to POOL");
Arun Menon906de572013-06-18 17:01:40 -07006920 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL,
6921 (unsigned)NULL);
6922 pdest_frame = NULL;
6923 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006924 }
Arun Menon906de572013-06-18 17:01:40 -07006925 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006926 DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07006927 /*Check if Destination Buffer is full*/
6928 if (pdest_frame->nAllocLen ==
6929 pdest_frame->nFilledLen + pdest_frame->nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006930 DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07006931 return OMX_ErrorStreamCorrupt;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006932 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006933 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006934
Arun Menon906de572013-06-18 17:01:40 -07006935 if (psource_frame->nFilledLen == 0) {
6936 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
6937 if (pdest_frame) {
6938 pdest_frame->nFlags |= psource_frame->nFlags;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006939 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld",
Arun Menon906de572013-06-18 17:01:40 -07006940 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006941 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07006942 pdest_frame->nFilledLen,frame_count++);
6943 /*Push the frame to the Decoder*/
6944 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
6945 return OMX_ErrorBadParameter;
6946 }
6947 frame_count++;
6948 pdest_frame = NULL;
6949 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006950 DEBUG_PRINT_LOW("Last frame in else dest addr") ;
Arun Menon906de572013-06-18 17:01:40 -07006951 generate_ebd = OMX_FALSE;
6952 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006953 }
Arun Menon906de572013-06-18 17:01:40 -07006954 if (generate_ebd) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006955 DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07006956 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
6957 psource_frame = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006958
Arun Menon906de572013-06-18 17:01:40 -07006959 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006960 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07006961 m_input_pending_q.pop_entry(&address,&p2,&id);
6962 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006963 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07006964 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006965 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07006966 psource_frame->nFlags,psource_frame->nFilledLen);
6967 }
6968 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006969 }
Arun Menon906de572013-06-18 17:01:40 -07006970 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006971}
6972
6973OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp)
6974{
Arun Menon906de572013-06-18 17:01:40 -07006975 OMX_U32 partial_frame = 1;
6976 unsigned address = 0, p2 = 0, id = 0;
6977 OMX_BOOL isNewFrame = OMX_FALSE;
6978 OMX_BOOL generate_ebd = OMX_TRUE;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006979
Arun Menon906de572013-06-18 17:01:40 -07006980 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006981 DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated");
Arun Menon906de572013-06-18 17:01:40 -07006982 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006983 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006984 DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu "
Arun Menon906de572013-06-18 17:01:40 -07006985 "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006986 DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07006987 if (h264_scratch.nFilledLen && look_ahead_nal) {
6988 look_ahead_nal = false;
6989 if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
6990 h264_scratch.nFilledLen) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006991 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
6992 h264_scratch.pBuffer,h264_scratch.nFilledLen);
6993 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006994 DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006995 h264_scratch.nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07006996 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006997 DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006998 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006999 }
Arun Menon906de572013-06-18 17:01:40 -07007000 }
Praveen Chavance0b5e82013-08-08 05:23:34 -07007001
7002 /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result
7003 in EOS flag getting associated with the destination
7004 */
7005 if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) &&
7006 pdest_frame->nFilledLen) {
7007 DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'");
7008 generate_ebd = OMX_FALSE;
7009 }
7010
Arun Menon906de572013-06-18 17:01:40 -07007011 if (nal_length == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007012 DEBUG_PRINT_LOW("Zero NAL, hence parse using start code");
Arun Menon906de572013-06-18 17:01:40 -07007013 if (m_frame_parser.parse_sc_frame(psource_frame,
7014 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007015 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007016 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007017 }
Arun Menon906de572013-06-18 17:01:40 -07007018 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007019 DEBUG_PRINT_LOW("Non-zero NAL length clip, hence parse with NAL size %d ",nal_length);
Arun Menon906de572013-06-18 17:01:40 -07007020 if (m_frame_parser.parse_h264_nallength(psource_frame,
7021 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007022 DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error");
Arun Menon906de572013-06-18 17:01:40 -07007023 return OMX_ErrorBadParameter;
7024 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007025 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007026
Arun Menon906de572013-06-18 17:01:40 -07007027 if (partial_frame == 0) {
7028 if (nal_count == 0 && h264_scratch.nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007029 DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip");
Arun Menon906de572013-06-18 17:01:40 -07007030 nal_count++;
7031 h264_scratch.nTimeStamp = psource_frame->nTimeStamp;
7032 h264_scratch.nFlags = psource_frame->nFlags;
7033 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007034 DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007035 if (h264_scratch.nFilledLen) {
7036 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen,
7037 NALU_TYPE_SPS);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007038#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
Arun Menon906de572013-06-18 17:01:40 -07007039 if (client_extradata & OMX_TIMEINFO_EXTRADATA)
7040 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7041 h264_scratch.nFilledLen, NALU_TYPE_SEI);
7042 else if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7043 // If timeinfo is present frame info from SEI is already processed
7044 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7045 h264_scratch.nFilledLen, NALU_TYPE_SEI);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007046#endif
Arun Menon906de572013-06-18 17:01:40 -07007047 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7048 nal_count++;
7049 if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) {
7050 pdest_frame->nTimeStamp = h264_last_au_ts;
7051 pdest_frame->nFlags = h264_last_au_flags;
7052#ifdef PANSCAN_HDLR
7053 if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7054 h264_parser->update_panscan_data(h264_last_au_ts);
7055#endif
7056 }
7057 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR ||
7058 m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) {
7059 h264_last_au_ts = h264_scratch.nTimeStamp;
7060 h264_last_au_flags = h264_scratch.nFlags;
7061#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7062 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7063 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts);
7064 if (!VALID_TS(h264_last_au_ts))
7065 h264_last_au_ts = ts_in_sei;
7066 }
7067#endif
7068 } else
7069 h264_last_au_ts = LLONG_MAX;
7070 }
7071
7072 if (!isNewFrame) {
7073 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7074 h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007075 DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu",
Arun Menon906de572013-06-18 17:01:40 -07007076 h264_scratch.nFilledLen);
7077 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7078 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7079 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7080 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ)
7081 pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
7082 h264_scratch.nFilledLen = 0;
7083 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007084 DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007085 return OMX_ErrorBadParameter;
7086 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007087 } else if(h264_scratch.nFilledLen) {
Arun Menon906de572013-06-18 17:01:40 -07007088 look_ahead_nal = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007089 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007090 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007091 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07007092 pdest_frame->nFilledLen,frame_count++);
7093
7094 if (pdest_frame->nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007095 DEBUG_PRINT_LOW("Copy the Current Frame since and push it");
Arun Menon906de572013-06-18 17:01:40 -07007096 look_ahead_nal = false;
7097 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7098 h264_scratch.nFilledLen) {
7099 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7100 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7101 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7102 h264_scratch.nFilledLen = 0;
7103 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007104 DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007105 return OMX_ErrorBadParameter;
7106 }
7107 } else {
7108 if (psource_frame->nFilledLen || h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007109 DEBUG_PRINT_LOW("Reset the EOS Flag");
Arun Menon906de572013-06-18 17:01:40 -07007110 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
7111 }
7112 /*Push the frame to the Decoder*/
7113 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7114 return OMX_ErrorBadParameter;
7115 }
7116 //frame_count++;
7117 pdest_frame = NULL;
7118 if (m_input_free_q.m_size) {
7119 m_input_free_q.pop_entry(&address,&p2,&id);
7120 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007121 DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07007122 pdest_frame->nFilledLen = 0;
7123 pdest_frame->nFlags = 0;
7124 pdest_frame->nTimeStamp = LLONG_MAX;
7125 }
7126 }
7127 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007128 }
Arun Menon906de572013-06-18 17:01:40 -07007129 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007130 DEBUG_PRINT_LOW("Not a Complete Frame, pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007131 /*Check if Destination Buffer is full*/
7132 if (h264_scratch.nAllocLen ==
7133 h264_scratch.nFilledLen + h264_scratch.nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007134 DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07007135 return OMX_ErrorStreamCorrupt;
7136 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007137 }
Arun Menon906de572013-06-18 17:01:40 -07007138
7139 if (!psource_frame->nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007140 DEBUG_PRINT_LOW("Buffer Consumed return source %p back to client",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007141
7142 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
7143 if (pdest_frame) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007144 DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer");
Arun Menon906de572013-06-18 17:01:40 -07007145 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7146 h264_scratch.nFilledLen) {
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007147 if(pdest_frame->nFilledLen == 0) {
7148 /* No residual frame from before, send whatever
7149 * we have left */
7150 memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7151 h264_scratch.pBuffer, h264_scratch.nFilledLen);
7152 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7153 h264_scratch.nFilledLen = 0;
7154 pdest_frame->nTimeStamp = h264_scratch.nTimeStamp;
7155 } else {
7156 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7157 if(!isNewFrame) {
7158 /* Have a residual frame, but we know that the
7159 * AU in this frame is belonging to whatever
7160 * frame we had left over. So append it */
7161 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7162 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7163 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7164 h264_scratch.nFilledLen = 0;
7165 pdest_frame->nTimeStamp = h264_last_au_ts;
7166 } else {
7167 /* Completely new frame, let's just push what
7168 * we have now. The resulting EBD would trigger
7169 * another push */
7170 generate_ebd = OMX_FALSE;
7171 pdest_frame->nTimeStamp = h264_last_au_ts;
7172 h264_last_au_ts = h264_scratch.nTimeStamp;
7173 }
7174 }
Arun Menon906de572013-06-18 17:01:40 -07007175 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007176 DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007177 return OMX_ErrorBadParameter;
7178 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007179
7180 /* Iff we coalesced two buffers, inherit the flags of both bufs */
7181 if(generate_ebd == OMX_TRUE) {
7182 pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags;
7183 }
Arun Menon906de572013-06-18 17:01:40 -07007184
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007185 DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007186 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007187 DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++);
Arun Menon906de572013-06-18 17:01:40 -07007188#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7189 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7190 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp);
7191 if (!VALID_TS(pdest_frame->nTimeStamp))
7192 pdest_frame->nTimeStamp = ts_in_sei;
7193 }
7194#endif
7195 /*Push the frame to the Decoder*/
7196 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7197 return OMX_ErrorBadParameter;
7198 }
7199 frame_count++;
7200 pdest_frame = NULL;
7201 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007202 DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu",
Arun Menon906de572013-06-18 17:01:40 -07007203 pdest_frame,h264_scratch.nFilledLen);
7204 generate_ebd = OMX_FALSE;
7205 }
7206 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007207 }
Arun Menon906de572013-06-18 17:01:40 -07007208 if (generate_ebd && !psource_frame->nFilledLen) {
7209 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
7210 psource_frame = NULL;
7211 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007212 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007213 m_input_pending_q.pop_entry(&address,&p2,&id);
7214 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007215 DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007216 psource_frame->nFlags,psource_frame->nFilledLen);
7217 }
7218 }
7219 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007220}
7221
7222OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp)
7223{
7224 OMX_U8 *buf, *pdest;
7225 OMX_U32 partial_frame = 1;
7226 OMX_U32 buf_len, dest_len;
7227
Arun Menon906de572013-06-18 17:01:40 -07007228 if (first_frame == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007229 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007230 DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes");
Arun Menon906de572013-06-18 17:01:40 -07007231 if (!m_vendor_config.pData) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007232 DEBUG_PRINT_LOW("Check profile type in 1st source buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007233 buf = psource_frame->pBuffer;
7234 buf_len = psource_frame->nFilledLen;
7235
7236 if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) ==
Arun Menon906de572013-06-18 17:01:40 -07007237 VC1_SP_MP_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007238 m_vc1_profile = VC1_SP_MP_RCV;
Arun Menon906de572013-06-18 17:01:40 -07007239 } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007240 m_vc1_profile = VC1_AP;
Arun Menon906de572013-06-18 17:01:40 -07007241 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007242 DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007243 return OMX_ErrorStreamCorrupt;
7244 }
Arun Menon906de572013-06-18 17:01:40 -07007245 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007246 pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen +
7247 pdest_frame->nOffset;
7248 dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen +
Arun Menon906de572013-06-18 17:01:40 -07007249 pdest_frame->nOffset);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007250
Arun Menon906de572013-06-18 17:01:40 -07007251 if (dest_len < m_vendor_config.nDataSize) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007252 DEBUG_PRINT_ERROR("Destination buffer full");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007253 return OMX_ErrorBadParameter;
Arun Menon906de572013-06-18 17:01:40 -07007254 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007255 memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize);
7256 pdest_frame->nFilledLen += m_vendor_config.nDataSize;
7257 }
7258 }
7259 }
7260
Arun Menon906de572013-06-18 17:01:40 -07007261 switch (m_vc1_profile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007262 case VC1_AP:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007263 DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code");
Arun Menon906de572013-06-18 17:01:40 -07007264 if (push_input_sc_codec(hComp) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007265 DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007266 return OMX_ErrorBadParameter;
7267 }
Arun Menon906de572013-06-18 17:01:40 -07007268 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007269
7270 case VC1_SP_MP_RCV:
7271 default:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007272 DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007273 return OMX_ErrorBadParameter;
7274 }
7275 return OMX_ErrorNone;
7276}
7277
David Ng38e2d232013-03-15 20:05:58 -07007278#ifndef USE_ION
Shalaj Jain273b3e02012-06-22 19:08:03 -07007279bool omx_vdec::align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007280 OMX_U32 alignment)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007281{
Arun Menon906de572013-06-18 17:01:40 -07007282 struct pmem_allocation allocation;
7283 allocation.size = buffer_size;
7284 allocation.align = clip2(alignment);
7285 if (allocation.align < 4096) {
7286 allocation.align = 4096;
7287 }
7288 if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007289 DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)",
Arun Menon906de572013-06-18 17:01:40 -07007290 allocation.align, allocation.size);
7291 return false;
7292 }
7293 return true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007294}
David Ng38e2d232013-03-15 20:05:58 -07007295#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07007296#ifdef USE_ION
7297int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007298 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
7299 struct ion_fd_data *fd_data, int flag)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007300{
Arun Menon906de572013-06-18 17:01:40 -07007301 int fd = -EINVAL;
7302 int rc = -EINVAL;
7303 int ion_dev_flag;
7304 struct vdec_ion ion_buf_info;
7305 if (!alloc_data || buffer_size <= 0 || !fd_data) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007306 DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory");
Arun Menon906de572013-06-18 17:01:40 -07007307 return -EINVAL;
7308 }
7309 ion_dev_flag = O_RDONLY;
7310 fd = open (MEM_DEVICE, ion_dev_flag);
7311 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007312 DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd);
Arun Menon906de572013-06-18 17:01:40 -07007313 return fd;
7314 }
7315 alloc_data->flags = 0;
7316 if (!secure_mode && (flag & ION_FLAG_CACHED)) {
7317 alloc_data->flags |= ION_FLAG_CACHED;
7318 }
7319 alloc_data->len = buffer_size;
7320 alloc_data->align = clip2(alignment);
7321 if (alloc_data->align < 4096) {
7322 alloc_data->align = 4096;
7323 }
7324 if ((secure_mode) && (flag & ION_SECURE))
7325 alloc_data->flags |= ION_SECURE;
Vinay Kalia53fa6832012-10-11 17:55:30 -07007326
Arun Menon906de572013-06-18 17:01:40 -07007327 alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID);
7328 if (secure_mode)
7329 alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID);
7330 rc = ioctl(fd,ION_IOC_ALLOC,alloc_data);
7331 if (rc || !alloc_data->handle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007332 DEBUG_PRINT_ERROR("ION ALLOC memory failed ");
Arun Menon906de572013-06-18 17:01:40 -07007333 alloc_data->handle = NULL;
7334 close(fd);
7335 fd = -ENOMEM;
7336 return fd;
7337 }
7338 fd_data->handle = alloc_data->handle;
7339 rc = ioctl(fd,ION_IOC_MAP,fd_data);
7340 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007341 DEBUG_PRINT_ERROR("ION MAP failed ");
Arun Menon906de572013-06-18 17:01:40 -07007342 ion_buf_info.ion_alloc_data = *alloc_data;
7343 ion_buf_info.ion_device_fd = fd;
7344 ion_buf_info.fd_ion_data = *fd_data;
7345 free_ion_memory(&ion_buf_info);
7346 fd_data->fd =-1;
7347 close(fd);
7348 fd = -ENOMEM;
7349 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007350
Arun Menon906de572013-06-18 17:01:40 -07007351 return fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007352}
7353
Arun Menon906de572013-06-18 17:01:40 -07007354void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info)
7355{
Shalaj Jain273b3e02012-06-22 19:08:03 -07007356
Arun Menon906de572013-06-18 17:01:40 -07007357 if (!buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007358 DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata");
Arun Menon906de572013-06-18 17:01:40 -07007359 return;
7360 }
7361 if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE,
7362 &buf_ion_info->ion_alloc_data.handle)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007363 DEBUG_PRINT_ERROR("ION: free failed" );
Arun Menon906de572013-06-18 17:01:40 -07007364 }
7365 close(buf_ion_info->ion_device_fd);
7366 buf_ion_info->ion_device_fd = -1;
7367 buf_ion_info->ion_alloc_data.handle = NULL;
7368 buf_ion_info->fd_ion_data.fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007369}
7370#endif
7371void omx_vdec::free_output_buffer_header()
7372{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007373 DEBUG_PRINT_HIGH("ALL output buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07007374 output_use_buffer = false;
7375 ouput_egl_buffers = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007376
Arun Menon906de572013-06-18 17:01:40 -07007377 if (m_out_mem_ptr) {
7378 free (m_out_mem_ptr);
7379 m_out_mem_ptr = NULL;
7380 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007381
Arun Menon906de572013-06-18 17:01:40 -07007382 if (m_platform_list) {
7383 free(m_platform_list);
7384 m_platform_list = NULL;
7385 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007386
Arun Menon906de572013-06-18 17:01:40 -07007387 if (drv_ctx.ptr_respbuffer) {
7388 free (drv_ctx.ptr_respbuffer);
7389 drv_ctx.ptr_respbuffer = NULL;
7390 }
7391 if (drv_ctx.ptr_outputbuffer) {
7392 free (drv_ctx.ptr_outputbuffer);
7393 drv_ctx.ptr_outputbuffer = NULL;
7394 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007395#ifdef USE_ION
7396 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007397 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07007398 free(drv_ctx.op_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007399 drv_ctx.op_buf_ion_info = NULL;
7400 }
7401#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07007402 if (out_dynamic_list) {
7403 free(out_dynamic_list);
7404 out_dynamic_list = NULL;
7405 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007406}
7407
7408void omx_vdec::free_input_buffer_header()
7409{
7410 input_use_buffer = false;
Arun Menon906de572013-06-18 17:01:40 -07007411 if (arbitrary_bytes) {
Arun Menon906de572013-06-18 17:01:40 -07007412 if (m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007413 DEBUG_PRINT_LOW("Free input Heap Pointer");
Arun Menon906de572013-06-18 17:01:40 -07007414 free (m_inp_heap_ptr);
7415 m_inp_heap_ptr = NULL;
7416 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007417
Arun Menon906de572013-06-18 17:01:40 -07007418 if (m_phdr_pmem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007419 DEBUG_PRINT_LOW("Free input pmem header Pointer");
Arun Menon906de572013-06-18 17:01:40 -07007420 free (m_phdr_pmem_ptr);
7421 m_phdr_pmem_ptr = NULL;
7422 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007423 }
Arun Menon906de572013-06-18 17:01:40 -07007424 if (m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007425 DEBUG_PRINT_LOW("Free input pmem Pointer area");
Arun Menon906de572013-06-18 17:01:40 -07007426 free (m_inp_mem_ptr);
7427 m_inp_mem_ptr = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007428 }
Leena Winterrowd1d2424a2013-08-20 15:26:02 -07007429 /* We just freed all the buffer headers, every thing in m_input_free_q
7430 * is now invalid */
7431 while (m_input_free_q.m_size) {
7432 unsigned address, p2, id;
7433 m_input_free_q.pop_entry(&address, &p2, &id);
7434 }
Arun Menon906de572013-06-18 17:01:40 -07007435 if (drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007436 DEBUG_PRINT_LOW("Free Driver Context pointer");
Arun Menon906de572013-06-18 17:01:40 -07007437 free (drv_ctx.ptr_inputbuffer);
7438 drv_ctx.ptr_inputbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007439 }
7440#ifdef USE_ION
7441 if (drv_ctx.ip_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007442 DEBUG_PRINT_LOW("Free ion context");
Arun Menon906de572013-06-18 17:01:40 -07007443 free(drv_ctx.ip_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007444 drv_ctx.ip_buf_ion_info = NULL;
7445 }
7446#endif
7447}
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007448
7449int omx_vdec::stream_off(OMX_U32 port)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007450{
Arun Menon906de572013-06-18 17:01:40 -07007451 enum v4l2_buf_type btype;
7452 int rc = 0;
7453 enum v4l2_ports v4l2_port = OUTPUT_PORT;
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007454
Arun Menon906de572013-06-18 17:01:40 -07007455 if (port == OMX_CORE_INPUT_PORT_INDEX) {
7456 btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7457 v4l2_port = OUTPUT_PORT;
7458 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
7459 btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7460 v4l2_port = CAPTURE_PORT;
7461 } else if (port == OMX_ALL) {
7462 int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX);
7463 int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007464
Arun Menon906de572013-06-18 17:01:40 -07007465 if (!rc_input)
7466 return rc_input;
7467 else
7468 return rc_output;
7469 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007470
Arun Menon906de572013-06-18 17:01:40 -07007471 if (!streaming[v4l2_port]) {
7472 // already streamed off, warn and move on
7473 DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port,"
7474 " which is already streamed off", v4l2_port);
7475 return 0;
7476 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007477
Arun Menon906de572013-06-18 17:01:40 -07007478 DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007479
Arun Menon906de572013-06-18 17:01:40 -07007480 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype);
7481 if (rc) {
7482 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007483 DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port);
Arun Menon906de572013-06-18 17:01:40 -07007484 } else {
7485 streaming[v4l2_port] = false;
7486 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07007487
Arun Menon906de572013-06-18 17:01:40 -07007488 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007489}
7490
7491OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop)
7492{
Arun Menon906de572013-06-18 17:01:40 -07007493 OMX_ERRORTYPE eRet = OMX_ErrorNone;
7494 struct v4l2_requestbuffers bufreq;
7495 unsigned int buf_size = 0, extra_data_size = 0, client_extra_data_size = 0;
7496 struct v4l2_format fmt;
7497 int ret = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007498 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
Arun Menon906de572013-06-18 17:01:40 -07007499 buffer_prop->actualcount, buffer_prop->buffer_size);
7500 bufreq.memory = V4L2_MEMORY_USERPTR;
7501 bufreq.count = 1;
7502 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
7503 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7504 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7505 fmt.fmt.pix_mp.pixelformat = output_capability;
7506 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
7507 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7508 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7509 fmt.fmt.pix_mp.pixelformat = capture_capability;
7510 } else {
7511 eRet = OMX_ErrorBadParameter;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07007512 }
Arun Menon906de572013-06-18 17:01:40 -07007513 if (eRet==OMX_ErrorNone) {
7514 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007515 }
Arun Menon906de572013-06-18 17:01:40 -07007516 if (ret) {
7517 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
7518 /*TODO: How to handle this case */
7519 eRet = OMX_ErrorInsufficientResources;
7520 return eRet;
7521 } else {
7522 buffer_prop->actualcount = bufreq.count;
7523 buffer_prop->mincount = bufreq.count;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007524 DEBUG_PRINT_HIGH("Count = %d",bufreq.count);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007525 }
Arun Menon906de572013-06-18 17:01:40 -07007526 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
7527 buffer_prop->actualcount, buffer_prop->buffer_size);
7528
7529 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
7530 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
7531
7532 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
7533
7534 update_resolution(fmt.fmt.pix_mp.width,
7535 fmt.fmt.pix_mp.height,
7536 fmt.fmt.pix_mp.plane_fmt[0].bytesperline,
7537 fmt.fmt.pix_mp.plane_fmt[0].reserved[0]);
7538 if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
7539 drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007540 DEBUG_PRINT_HIGH("Buffer Size = %d",fmt.fmt.pix_mp.plane_fmt[0].sizeimage);
Arun Menon906de572013-06-18 17:01:40 -07007541
7542 if (ret) {
7543 /*TODO: How to handle this case */
7544 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
7545 eRet = OMX_ErrorInsufficientResources;
7546 } else {
7547 int extra_idx = 0;
7548
7549 eRet = is_video_session_supported();
7550 if (eRet)
7551 return eRet;
7552
7553 buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage;
7554 buf_size = buffer_prop->buffer_size;
7555 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
7556 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
7557 extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage;
7558 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007559 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07007560 return OMX_ErrorBadParameter;
7561 }
7562 if (client_extradata & OMX_FRAMEINFO_EXTRADATA) {
7563 DEBUG_PRINT_HIGH("Frame info extra data enabled!");
7564 client_extra_data_size += OMX_FRAMEINFO_EXTRADATA_SIZE;
7565 }
7566 if (client_extradata & OMX_INTERLACE_EXTRADATA) {
7567 client_extra_data_size += OMX_INTERLACE_EXTRADATA_SIZE;
7568 }
7569 if (client_extradata & OMX_PORTDEF_EXTRADATA) {
7570 client_extra_data_size += OMX_PORTDEF_EXTRADATA_SIZE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007571 DEBUG_PRINT_HIGH("Smooth streaming enabled extra_data_size=%d",
Arun Menon906de572013-06-18 17:01:40 -07007572 client_extra_data_size);
7573 }
7574 if (client_extra_data_size) {
7575 client_extra_data_size += sizeof(OMX_OTHER_EXTRADATATYPE); //Space for terminator
7576 buf_size = ((buf_size + 3)&(~3)); //Align extradata start address to 64Bit
7577 }
7578 drv_ctx.extradata_info.size = buffer_prop->actualcount * extra_data_size;
7579 drv_ctx.extradata_info.count = buffer_prop->actualcount;
7580 drv_ctx.extradata_info.buffer_size = extra_data_size;
7581 buf_size += client_extra_data_size;
7582 buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
7583 DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)",
7584 buffer_prop->actualcount, buffer_prop->buffer_size, buf_size);
7585 if (in_reconfig) // BufReq will be set to driver when port is disabled
7586 buffer_prop->buffer_size = buf_size;
7587 else if (buf_size != buffer_prop->buffer_size) {
7588 buffer_prop->buffer_size = buf_size;
7589 eRet = set_buffer_req(buffer_prop);
7590 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007591 }
Arun Menon906de572013-06-18 17:01:40 -07007592 DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)",
7593 buffer_prop->actualcount, buffer_prop->buffer_size);
7594 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007595}
7596
7597OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop)
7598{
Arun Menon906de572013-06-18 17:01:40 -07007599 OMX_ERRORTYPE eRet = OMX_ErrorNone;
7600 unsigned buf_size = 0;
7601 struct v4l2_format fmt;
7602 struct v4l2_requestbuffers bufreq;
7603 int ret;
7604 DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)",
7605 buffer_prop->actualcount, buffer_prop->buffer_size);
7606 buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
7607 if (buf_size != buffer_prop->buffer_size) {
7608 DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)",
7609 buffer_prop->buffer_size, buf_size);
7610 eRet = OMX_ErrorBadParameter;
7611 } else {
7612 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
7613 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07007614
Arun Menon906de572013-06-18 17:01:40 -07007615 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
7616 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7617 fmt.fmt.pix_mp.pixelformat = output_capability;
Shalaj Jaind3902bb2013-10-07 12:42:55 -07007618 fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size;
Arun Menon906de572013-06-18 17:01:40 -07007619 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
7620 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7621 fmt.fmt.pix_mp.pixelformat = capture_capability;
7622 } else {
7623 eRet = OMX_ErrorBadParameter;
7624 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07007625
Arun Menon906de572013-06-18 17:01:40 -07007626 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
7627 if (ret) {
7628 /*TODO: How to handle this case */
7629 DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret);
7630 eRet = OMX_ErrorInsufficientResources;
7631 }
7632
7633 bufreq.memory = V4L2_MEMORY_USERPTR;
7634 bufreq.count = buffer_prop->actualcount;
7635 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
7636 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7637 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
7638 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
7639 } else {
7640 eRet = OMX_ErrorBadParameter;
7641 }
7642
7643 if (eRet==OMX_ErrorNone) {
7644 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
7645 }
7646
7647 if (ret) {
7648 DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret);
7649 /*TODO: How to handle this case */
7650 eRet = OMX_ErrorInsufficientResources;
7651 } else if (bufreq.count < buffer_prop->actualcount) {
7652 DEBUG_PRINT_ERROR("Driver refused to change the number of buffers"
7653 " on v4l2 port %d to %d (prefers %d)", bufreq.type,
7654 buffer_prop->actualcount, bufreq.count);
7655 eRet = OMX_ErrorInsufficientResources;
7656 } else {
7657 if (!client_buffers.update_buffer_req()) {
7658 DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed");
7659 eRet = OMX_ErrorInsufficientResources;
7660 }
7661 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007662 }
Arun Menon906de572013-06-18 17:01:40 -07007663 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007664}
7665
Shalaj Jain273b3e02012-06-22 19:08:03 -07007666OMX_ERRORTYPE omx_vdec::update_picture_resolution()
7667{
Arun Menon906de572013-06-18 17:01:40 -07007668 OMX_ERRORTYPE eRet = OMX_ErrorNone;
7669 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007670}
7671
7672OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn)
7673{
Arun Menon906de572013-06-18 17:01:40 -07007674 OMX_ERRORTYPE eRet = OMX_ErrorNone;
7675 if (!portDefn) {
7676 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08007677 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007678 DEBUG_PRINT_LOW("omx_vdec::update_portdef");
Arun Menon906de572013-06-18 17:01:40 -07007679 portDefn->nVersion.nVersion = OMX_SPEC_VERSION;
7680 portDefn->nSize = sizeof(portDefn);
7681 portDefn->eDomain = OMX_PortDomainVideo;
7682 if (drv_ctx.frame_rate.fps_denominator > 0)
7683 portDefn->format.video.xFramerate = drv_ctx.frame_rate.fps_numerator /
7684 drv_ctx.frame_rate.fps_denominator;
7685 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007686 DEBUG_PRINT_ERROR("Error: Divide by zero");
Arun Menon906de572013-06-18 17:01:40 -07007687 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08007688 }
Arun Menon906de572013-06-18 17:01:40 -07007689 if (0 == portDefn->nPortIndex) {
7690 portDefn->eDir = OMX_DirInput;
7691 portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount;
7692 portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount;
7693 portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size;
7694 portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused;
7695 portDefn->format.video.eCompressionFormat = eCompressionFormat;
7696 portDefn->bEnabled = m_inp_bEnabled;
7697 portDefn->bPopulated = m_inp_bPopulated;
7698 } else if (1 == portDefn->nPortIndex) {
7699 unsigned int buf_size = 0;
7700 if (!client_buffers.update_buffer_req()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007701 DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed");
Arun Menon906de572013-06-18 17:01:40 -07007702 return OMX_ErrorHardware;
7703 }
7704 if (!client_buffers.get_buffer_req(buf_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007705 DEBUG_PRINT_ERROR("update buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07007706 return OMX_ErrorHardware;
7707 }
7708 portDefn->nBufferSize = buf_size;
7709 portDefn->eDir = OMX_DirOutput;
7710 portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount;
7711 portDefn->nBufferCountMin = drv_ctx.op_buf.mincount;
7712 portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
7713 portDefn->bEnabled = m_out_bEnabled;
7714 portDefn->bPopulated = m_out_bPopulated;
7715 if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007716 DEBUG_PRINT_ERROR("Error in getting color format");
Arun Menon906de572013-06-18 17:01:40 -07007717 return OMX_ErrorHardware;
7718 }
7719 } else {
7720 portDefn->eDir = OMX_DirMax;
7721 DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d",
7722 (int)portDefn->nPortIndex);
7723 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007724 }
Arun Menon906de572013-06-18 17:01:40 -07007725 portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height;
7726 portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width;
7727 portDefn->format.video.nStride = drv_ctx.video_resolution.stride;
7728 portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines;
7729 DEBUG_PRINT_HIGH("update_portdef Width = %lu Height = %lu Stride = %ld"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007730 " SliceHeight = %lu", portDefn->format.video.nFrameWidth,
Arun Menon906de572013-06-18 17:01:40 -07007731 portDefn->format.video.nFrameHeight,
7732 portDefn->format.video.nStride,
7733 portDefn->format.video.nSliceHeight);
7734 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007735
7736}
7737
7738OMX_ERRORTYPE omx_vdec::allocate_output_headers()
7739{
Arun Menon906de572013-06-18 17:01:40 -07007740 OMX_ERRORTYPE eRet = OMX_ErrorNone;
7741 OMX_BUFFERHEADERTYPE *bufHdr = NULL;
7742 unsigned i= 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007743
Arun Menon906de572013-06-18 17:01:40 -07007744 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007745 DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation");
Arun Menon906de572013-06-18 17:01:40 -07007746 int nBufHdrSize = 0;
7747 int nPlatformEntrySize = 0;
7748 int nPlatformListSize = 0;
7749 int nPMEMInfoSize = 0;
7750 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
7751 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
7752 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007753
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007754 DEBUG_PRINT_LOW("Setting First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07007755 drv_ctx.op_buf.actualcount);
7756 nBufHdrSize = drv_ctx.op_buf.actualcount *
7757 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007758
Arun Menon906de572013-06-18 17:01:40 -07007759 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
7760 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
7761 nPlatformListSize = drv_ctx.op_buf.actualcount *
7762 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
7763 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
7764 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007765
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007766 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07007767 sizeof(OMX_BUFFERHEADERTYPE),
7768 nPMEMInfoSize,
7769 nPlatformListSize);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007770 DEBUG_PRINT_LOW("PE %d bmSize %d",nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07007771 m_out_bm_count);
7772 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
7773 // Alloc mem for platform specific info
7774 char *pPtr=NULL;
7775 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
7776 nPMEMInfoSize,1);
7777 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \
7778 calloc (sizeof(struct vdec_bufferpayload),
7779 drv_ctx.op_buf.actualcount);
7780 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
7781 calloc (sizeof (struct vdec_output_frameinfo),
7782 drv_ctx.op_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007783#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07007784 drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \
7785 calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007786#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07007787 if (dynamic_buf_mode) {
7788 out_dynamic_list = (struct dynamic_buf_list *) \
7789 calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount);
7790 }
Arun Menon906de572013-06-18 17:01:40 -07007791 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
7792 && drv_ctx.ptr_respbuffer) {
7793 bufHdr = m_out_mem_ptr;
7794 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
7795 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
7796 (((char *) m_platform_list) + nPlatformListSize);
7797 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
7798 (((char *) m_platform_entry) + nPlatformEntrySize);
7799 pPlatformList = m_platform_list;
7800 pPlatformEntry = m_platform_entry;
7801 pPMEMInfo = m_pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007802
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007803 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007804
Arun Menon906de572013-06-18 17:01:40 -07007805 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007806 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr,
Arun Menon906de572013-06-18 17:01:40 -07007807 m_out_mem_ptr,pPlatformEntry);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007808 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07007809 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
7810 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
7811 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
7812 // Set the values when we determine the right HxW param
7813 bufHdr->nAllocLen = 0;
7814 bufHdr->nFilledLen = 0;
7815 bufHdr->pAppPrivate = NULL;
7816 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
7817 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
7818 pPlatformEntry->entry = pPMEMInfo;
7819 // Initialize the Platform List
7820 pPlatformList->nEntries = 1;
7821 pPlatformList->entryList = pPlatformEntry;
7822 // Keep pBuffer NULL till vdec is opened
7823 bufHdr->pBuffer = NULL;
7824 pPMEMInfo->offset = 0;
7825 pPMEMInfo->pmem_fd = 0;
7826 bufHdr->pPlatformPrivate = pPlatformList;
7827 drv_ctx.ptr_outputbuffer[i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007828#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07007829 drv_ctx.op_buf_ion_info[i].ion_device_fd =-1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007830#endif
Arun Menon906de572013-06-18 17:01:40 -07007831 /*Create a mapping between buffers*/
7832 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
7833 drv_ctx.ptr_respbuffer[i].client_data = (void *) \
7834 &drv_ctx.ptr_outputbuffer[i];
7835 // Move the buffer and buffer header pointers
7836 bufHdr++;
7837 pPMEMInfo++;
7838 pPlatformEntry++;
7839 pPlatformList++;
7840 }
7841 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007842 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07007843 m_out_mem_ptr, pPtr);
7844 if (m_out_mem_ptr) {
7845 free(m_out_mem_ptr);
7846 m_out_mem_ptr = NULL;
7847 }
7848 if (pPtr) {
7849 free(pPtr);
7850 pPtr = NULL;
7851 }
7852 if (drv_ctx.ptr_outputbuffer) {
7853 free(drv_ctx.ptr_outputbuffer);
7854 drv_ctx.ptr_outputbuffer = NULL;
7855 }
7856 if (drv_ctx.ptr_respbuffer) {
7857 free(drv_ctx.ptr_respbuffer);
7858 drv_ctx.ptr_respbuffer = NULL;
7859 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007860#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07007861 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007862 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07007863 free(drv_ctx.op_buf_ion_info);
7864 drv_ctx.op_buf_ion_info = NULL;
7865 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007866#endif
Arun Menon906de572013-06-18 17:01:40 -07007867 eRet = OMX_ErrorInsufficientResources;
7868 }
7869 } else {
7870 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007871 }
Arun Menon906de572013-06-18 17:01:40 -07007872 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007873}
7874
7875void omx_vdec::complete_pending_buffer_done_cbs()
7876{
Arun Menon906de572013-06-18 17:01:40 -07007877 unsigned p1;
7878 unsigned p2;
7879 unsigned ident;
7880 omx_cmd_queue tmp_q, pending_bd_q;
7881 pthread_mutex_lock(&m_lock);
7882 // pop all pending GENERATE FDB from ftb queue
7883 while (m_ftb_q.m_size) {
7884 m_ftb_q.pop_entry(&p1,&p2,&ident);
7885 if (ident == OMX_COMPONENT_GENERATE_FBD) {
7886 pending_bd_q.insert_entry(p1,p2,ident);
7887 } else {
7888 tmp_q.insert_entry(p1,p2,ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007889 }
Arun Menon906de572013-06-18 17:01:40 -07007890 }
7891 //return all non GENERATE FDB to ftb queue
7892 while (tmp_q.m_size) {
7893 tmp_q.pop_entry(&p1,&p2,&ident);
7894 m_ftb_q.insert_entry(p1,p2,ident);
7895 }
7896 // pop all pending GENERATE EDB from etb queue
7897 while (m_etb_q.m_size) {
7898 m_etb_q.pop_entry(&p1,&p2,&ident);
7899 if (ident == OMX_COMPONENT_GENERATE_EBD) {
7900 pending_bd_q.insert_entry(p1,p2,ident);
7901 } else {
7902 tmp_q.insert_entry(p1,p2,ident);
7903 }
7904 }
7905 //return all non GENERATE FDB to etb queue
7906 while (tmp_q.m_size) {
7907 tmp_q.pop_entry(&p1,&p2,&ident);
7908 m_etb_q.insert_entry(p1,p2,ident);
7909 }
7910 pthread_mutex_unlock(&m_lock);
7911 // process all pending buffer dones
7912 while (pending_bd_q.m_size) {
7913 pending_bd_q.pop_entry(&p1,&p2,&ident);
7914 switch (ident) {
7915 case OMX_COMPONENT_GENERATE_EBD:
7916 if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007917 DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07007918 omx_report_error ();
7919 }
7920 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007921
Arun Menon906de572013-06-18 17:01:40 -07007922 case OMX_COMPONENT_GENERATE_FBD:
7923 if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007924 DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07007925 omx_report_error ();
7926 }
7927 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007928 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007929 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007930}
7931
7932void omx_vdec::set_frame_rate(OMX_S64 act_timestamp)
7933{
Arun Menon906de572013-06-18 17:01:40 -07007934 OMX_U32 new_frame_interval = 0;
7935 if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts
7936 && llabs(act_timestamp - prev_ts) > 2000) {
7937 new_frame_interval = client_set_fps ? frm_int :
7938 llabs(act_timestamp - prev_ts);
7939 if (new_frame_interval < frm_int || frm_int == 0) {
7940 frm_int = new_frame_interval;
7941 if (frm_int) {
7942 drv_ctx.frame_rate.fps_numerator = 1e6;
7943 drv_ctx.frame_rate.fps_denominator = frm_int;
7944 DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)",
7945 frm_int, drv_ctx.frame_rate.fps_numerator /
7946 (float)drv_ctx.frame_rate.fps_denominator);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07007947
Arun Menon906de572013-06-18 17:01:40 -07007948 /* We need to report the difference between this FBD and the previous FBD
7949 * back to the driver for clock scaling purposes. */
7950 struct v4l2_outputparm oparm;
7951 /*XXX: we're providing timing info as seconds per frame rather than frames
7952 * per second.*/
7953 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
7954 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07007955
Arun Menon906de572013-06-18 17:01:40 -07007956 struct v4l2_streamparm sparm;
7957 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
7958 sparm.parm.output = oparm;
7959 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
7960 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
7961 performance might be affected");
7962 }
7963
7964 }
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07007965 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007966 }
Arun Menon906de572013-06-18 17:01:40 -07007967 prev_ts = act_timestamp;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007968}
7969
7970void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp)
7971{
Arun Menon906de572013-06-18 17:01:40 -07007972 if (rst_prev_ts && VALID_TS(act_timestamp)) {
7973 prev_ts = act_timestamp;
7974 rst_prev_ts = false;
7975 } else if (VALID_TS(prev_ts)) {
7976 bool codec_cond = (drv_ctx.timestamp_adjust)?
7977 (!VALID_TS(act_timestamp) || (((act_timestamp > prev_ts)?
7978 (act_timestamp - prev_ts):(prev_ts - act_timestamp)) <= 2000)):
7979 (!VALID_TS(act_timestamp) || act_timestamp == prev_ts);
7980 if (frm_int > 0 && codec_cond) {
7981 DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp);
7982 act_timestamp = prev_ts + frm_int;
7983 DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp);
7984 prev_ts = act_timestamp;
7985 } else
7986 set_frame_rate(act_timestamp);
7987 } else if (frm_int > 0) // In this case the frame rate was set along
7988 { // with the port definition, start ts with 0
7989 act_timestamp = prev_ts = 0; // and correct if a valid ts is received.
7990 rst_prev_ts = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007991 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007992}
7993
7994void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr)
7995{
Arun Menon906de572013-06-18 17:01:40 -07007996 OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL;
7997 OMX_U32 num_conceal_MB = 0;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05307998 OMX_TICKS time_stamp = 0;
Arun Menon906de572013-06-18 17:01:40 -07007999 OMX_U32 frame_rate = 0;
8000 int consumed_len = 0;
8001 OMX_U32 num_MB_in_frame;
8002 OMX_U32 recovery_sei_flags = 1;
8003 int enable = 0;
8004 OMX_U32 mbaff = 0;
8005 int buf_index = p_buf_hdr - m_out_mem_ptr;
8006 struct msm_vidc_panscan_window_payload *panscan_payload = NULL;
8007 OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) +
8008 p_buf_hdr->nOffset;
8009 if (!drv_ctx.extradata_info.uaddr) {
8010 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008011 }
Arun Menon906de572013-06-18 17:01:40 -07008012 p_extra = (OMX_OTHER_EXTRADATATYPE *)
8013 ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3));
8014 char *p_extradata = drv_ctx.extradata_info.uaddr + buf_index * drv_ctx.extradata_info.buffer_size;
8015 if ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))
8016 p_extra = NULL;
8017 OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata;
8018 if (data) {
8019 while ((consumed_len < drv_ctx.extradata_info.buffer_size)
8020 && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) {
Surajit Podderd2644d52013-08-28 17:59:06 +05308021 if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) {
Arun Menon906de572013-06-18 17:01:40 -07008022 DEBUG_PRINT_LOW("Invalid extra data size");
8023 break;
8024 }
8025 switch ((unsigned long)data->eType) {
8026 case EXTRADATA_INTERLACE_VIDEO:
8027 struct msm_vidc_interlace_payload *payload;
8028 payload = (struct msm_vidc_interlace_payload *)data->data;
8029 mbaff = (h264_parser)? (h264_parser->is_mbaff()): false;
8030 if (payload && (payload->format == INTERLACE_FRAME_PROGRESSIVE) && !mbaff)
8031 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008032 else if (payload && (payload->format == INTERLACE_FRAME_TOPFIELDFIRST ||
8033 payload->format == INTERLACE_FRAME_BOTTOMFIELDFIRST) && !mbaff) {
8034 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
8035 enable = 1;
8036 } else {
Arun Menon906de572013-06-18 17:01:40 -07008037 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8038 enable = 1;
8039 }
8040 if (m_enable_android_native_buffers)
8041 setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle,
8042 PP_PARAM_INTERLACED, (void*)&enable);
8043 if (!secure_mode && (client_extradata & OMX_INTERLACE_EXTRADATA)) {
8044 append_interlace_extradata(p_extra, payload->format);
8045 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8046 }
8047 break;
8048 case EXTRADATA_FRAME_RATE:
8049 struct msm_vidc_framerate_payload *frame_rate_payload;
8050 frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data;
8051 frame_rate = frame_rate_payload->frame_rate;
8052 break;
8053 case EXTRADATA_TIMESTAMP:
8054 struct msm_vidc_ts_payload *time_stamp_payload;
8055 time_stamp_payload = (struct msm_vidc_ts_payload *)data->data;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308056 time_stamp = time_stamp_payload->timestamp_lo;
8057 time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32);
8058 p_buf_hdr->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07008059 break;
8060 case EXTRADATA_NUM_CONCEALED_MB:
8061 struct msm_vidc_concealmb_payload *conceal_mb_payload;
8062 conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data;
8063 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8064 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8065 num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0);
8066 break;
8067 case EXTRADATA_INDEX:
8068 int *etype;
8069 etype = (int *)(data->data);
8070 if (etype && *etype == EXTRADATA_ASPECT_RATIO) {
8071 struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload;
8072 aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype);
8073 if (aspect_ratio_payload) {
8074 ((struct vdec_output_frameinfo *)
8075 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width;
8076 ((struct vdec_output_frameinfo *)
8077 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height;
8078 }
8079 }
8080 break;
8081 case EXTRADATA_RECOVERY_POINT_SEI:
8082 struct msm_vidc_recoverysei_payload *recovery_sei_payload;
8083 recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data;
8084 recovery_sei_flags = recovery_sei_payload->flags;
8085 if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) {
8086 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008087 DEBUG_PRINT_HIGH("");
8088 DEBUG_PRINT_HIGH("***************************************************");
8089 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
8090 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07008091 }
8092 break;
8093 case EXTRADATA_PANSCAN_WINDOW:
8094 panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data;
8095 break;
8096 case EXTRADATA_MPEG2_SEQDISP:
8097 struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload;
8098 seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data;
8099 if (seqdisp_payload) {
8100 m_disp_hor_size = seqdisp_payload->disp_width;
8101 m_disp_vert_size = seqdisp_payload->disp_height;
8102 }
8103 break;
8104 default:
8105 goto unrecognized_extradata;
8106 }
8107 consumed_len += data->nSize;
8108 data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize);
8109 }
8110 if (!secure_mode && (client_extradata & OMX_FRAMEINFO_EXTRADATA)) {
8111 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
8112 append_frame_info_extradata(p_extra,
8113 num_conceal_MB, ((struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate)->pic_type, frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308114 time_stamp, panscan_payload,&((struct vdec_output_frameinfo *)
Arun Menon906de572013-06-18 17:01:40 -07008115 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info);
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008116 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
Arun Menon906de572013-06-18 17:01:40 -07008117 }
8118 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07008119unrecognized_extradata:
Arun Menon906de572013-06-18 17:01:40 -07008120 if (!secure_mode && client_extradata)
8121 append_terminator_extradata(p_extra);
8122 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008123}
8124
Vinay Kalia9c00cae2012-12-06 16:08:20 -08008125OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata,
Arun Menon906de572013-06-18 17:01:40 -07008126 bool is_internal, bool enable)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008127{
Arun Menon906de572013-06-18 17:01:40 -07008128 OMX_ERRORTYPE ret = OMX_ErrorNone;
8129 struct v4l2_control control;
8130 if (m_state != OMX_StateLoaded) {
8131 DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only");
8132 return OMX_ErrorIncorrectStateOperation;
Vinay Kaliadb90f8c2012-11-19 18:57:56 -08008133 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008134 DEBUG_PRINT_HIGH("NOTE: enable_extradata: actual[%lu] requested[%lu] enable[%d], is_internal: %d",
Arun Menon906de572013-06-18 17:01:40 -07008135 client_extradata, requested_extradata, enable, is_internal);
8136
8137 if (!is_internal) {
8138 if (enable)
8139 client_extradata |= requested_extradata;
8140 else
8141 client_extradata = client_extradata & ~requested_extradata;
8142 }
8143
8144 if (enable) {
8145 if (requested_extradata & OMX_INTERLACE_EXTRADATA) {
8146 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8147 control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO;
8148 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8149 DEBUG_PRINT_HIGH("Failed to set interlaced extradata."
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008150 " Quality of interlaced clips might be impacted.");
Arun Menon906de572013-06-18 17:01:40 -07008151 }
8152 } else if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) {
8153 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8154 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE;
8155 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008156 DEBUG_PRINT_HIGH("Failed to set framerate extradata");
Arun Menon906de572013-06-18 17:01:40 -07008157 }
8158 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8159 control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB;
8160 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008161 DEBUG_PRINT_HIGH("Failed to set concealed MB extradata");
Arun Menon906de572013-06-18 17:01:40 -07008162 }
8163 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8164 control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI;
8165 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008166 DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata");
Arun Menon906de572013-06-18 17:01:40 -07008167 }
8168 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8169 control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW;
8170 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008171 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008172 }
8173 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8174 control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO;
8175 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008176 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008177 }
8178 if (output_capability == V4L2_PIX_FMT_MPEG2) {
8179 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8180 control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP;
8181 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008182 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008183 }
8184 }
8185 } else if (requested_extradata & OMX_TIMEINFO_EXTRADATA) {
8186 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8187 control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP;
8188 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008189 DEBUG_PRINT_HIGH("Failed to set timeinfo extradata");
Arun Menon906de572013-06-18 17:01:40 -07008190 }
8191 }
8192 }
8193 ret = get_buffer_req(&drv_ctx.op_buf);
8194 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008195}
8196
8197OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8198{
Arun Menon906de572013-06-18 17:01:40 -07008199 OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0;
8200 OMX_U8 *data_ptr = extra->data, data = 0;
8201 while (byte_count < extra->nDataSize) {
8202 data = *data_ptr;
8203 while (data) {
8204 num_MB += (data&0x01);
8205 data >>= 1;
8206 }
8207 data_ptr++;
8208 byte_count++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008209 }
Arun Menon906de572013-06-18 17:01:40 -07008210 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8211 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8212 return ((num_MB_in_frame > 0)?(num_MB * 100 / num_MB_in_frame) : 0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008213}
8214
8215void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8216{
Arun Menon906de572013-06-18 17:01:40 -07008217 if (!m_debug_extradata)
8218 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008219
8220 DEBUG_PRINT_HIGH(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008221 "============== Extra Data =============="
8222 " Size: %lu"
8223 " Version: %lu"
8224 " PortIndex: %lu"
8225 " Type: %x"
8226 " DataSize: %lu",
Arun Menon906de572013-06-18 17:01:40 -07008227 extra->nSize, extra->nVersion.nVersion,
8228 extra->nPortIndex, extra->eType, extra->nDataSize);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008229
Arun Menon906de572013-06-18 17:01:40 -07008230 if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) {
8231 OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data;
8232 DEBUG_PRINT_HIGH(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008233 "------ Interlace Format ------"
8234 " Size: %lu"
8235 " Version: %lu"
8236 " PortIndex: %lu"
8237 " Is Interlace Format: %d"
8238 " Interlace Formats: %lu"
8239 "=========== End of Interlace ===========",
Arun Menon906de572013-06-18 17:01:40 -07008240 intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex,
8241 intfmt->bInterlaceFormat, intfmt->nInterlaceFormats);
8242 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) {
8243 OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
8244
8245 DEBUG_PRINT_HIGH(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008246 "-------- Frame Format --------"
8247 " Picture Type: %d"
8248 " Interlace Type: %d"
8249 " Pan Scan Total Frame Num: %lu"
8250 " Concealed Macro Blocks: %lu"
8251 " frame rate: %lu"
8252 " Time Stamp: %llu"
8253 " Aspect Ratio X: %lu"
8254 " Aspect Ratio Y: %lu",
Arun Menon906de572013-06-18 17:01:40 -07008255 fminfo->ePicType,
8256 fminfo->interlaceType,
8257 fminfo->panScan.numWindows,
8258 fminfo->nConcealedMacroblocks,
8259 fminfo->nFrameRate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308260 fminfo->nTimeStamp,
Arun Menon906de572013-06-18 17:01:40 -07008261 fminfo->aspectRatio.aspectRatioX,
8262 fminfo->aspectRatio.aspectRatioY);
8263
8264 for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) {
8265 DEBUG_PRINT_HIGH(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008266 "------------------------------"
8267 " Pan Scan Frame Num: %lu"
8268 " Rectangle x: %ld"
8269 " Rectangle y: %ld"
8270 " Rectangle dx: %ld"
8271 " Rectangle dy: %ld",
Arun Menon906de572013-06-18 17:01:40 -07008272 i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y,
8273 fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy);
8274 }
8275
8276 DEBUG_PRINT_HIGH("========= End of Frame Format ==========");
8277 } else if (extra->eType == OMX_ExtraDataNone) {
8278 DEBUG_PRINT_HIGH("========== End of Terminator ===========");
8279 } else {
8280 DEBUG_PRINT_HIGH("======= End of Driver Extradata ========");
Shalaj Jain273b3e02012-06-22 19:08:03 -07008281 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008282}
8283
8284void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon906de572013-06-18 17:01:40 -07008285 OMX_U32 interlaced_format_type)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008286{
Arun Menon906de572013-06-18 17:01:40 -07008287 OMX_STREAMINTERLACEFORMAT *interlace_format;
8288 OMX_U32 mbaff = 0;
8289 if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) {
8290 return;
8291 }
8292 extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE;
8293 extra->nVersion.nVersion = OMX_SPEC_VERSION;
8294 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8295 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat;
8296 extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT);
8297 interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data;
8298 interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT);
8299 interlace_format->nVersion.nVersion = OMX_SPEC_VERSION;
8300 interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8301 mbaff = (h264_parser)? (h264_parser->is_mbaff()): false;
8302 if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !mbaff) {
8303 interlace_format->bInterlaceFormat = OMX_FALSE;
8304 interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive;
8305 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008306 } else if ((interlaced_format_type == INTERLACE_FRAME_TOPFIELDFIRST) && !mbaff) {
8307 interlace_format->bInterlaceFormat = OMX_TRUE;
8308 interlace_format->nInterlaceFormats = OMX_InterlaceFrameTopFieldFirst;
8309 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
8310 } else if ((interlaced_format_type == INTERLACE_FRAME_BOTTOMFIELDFIRST) && !mbaff) {
8311 interlace_format->bInterlaceFormat = OMX_TRUE;
8312 interlace_format->nInterlaceFormats = OMX_InterlaceFrameBottomFieldFirst;
8313 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon906de572013-06-18 17:01:40 -07008314 } else {
8315 interlace_format->bInterlaceFormat = OMX_TRUE;
8316 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst;
8317 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8318 }
8319 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008320}
8321
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08008322void omx_vdec::fill_aspect_ratio_info(
Arun Menon906de572013-06-18 17:01:40 -07008323 struct vdec_aspectratioinfo *aspect_ratio_info,
8324 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info)
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08008325{
Arun Menon906de572013-06-18 17:01:40 -07008326 m_extradata = frame_info;
8327 m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width;
8328 m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308329 DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX,
Arun Menon906de572013-06-18 17:01:40 -07008330 m_extradata->aspectRatio.aspectRatioY);
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08008331}
Shalaj Jain273b3e02012-06-22 19:08:03 -07008332
8333void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon906de572013-06-18 17:01:40 -07008334 OMX_U32 num_conceal_mb, OMX_U32 picture_type, OMX_U32 frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308335 OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload,
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08008336 struct vdec_aspectratioinfo *aspect_ratio_info)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008337{
Arun Menon906de572013-06-18 17:01:40 -07008338 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL;
8339 struct msm_vidc_panscan_window *panscan_window;
8340 if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) {
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08008341 return;
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07008342 }
Arun Menon906de572013-06-18 17:01:40 -07008343 extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE;
8344 extra->nVersion.nVersion = OMX_SPEC_VERSION;
8345 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8346 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo;
8347 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO);
8348 frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
8349 switch (picture_type) {
8350 case PICTURE_TYPE_I:
8351 frame_info->ePicType = OMX_VIDEO_PictureTypeI;
8352 break;
8353 case PICTURE_TYPE_P:
8354 frame_info->ePicType = OMX_VIDEO_PictureTypeP;
8355 break;
8356 case PICTURE_TYPE_B:
8357 frame_info->ePicType = OMX_VIDEO_PictureTypeB;
8358 break;
8359 default:
8360 frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0;
8361 }
8362 if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst)
8363 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
8364 else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst)
8365 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
8366 else
8367 frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive;
8368 memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio));
8369 frame_info->nConcealedMacroblocks = num_conceal_mb;
8370 frame_info->nFrameRate = frame_rate;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308371 frame_info->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07008372 frame_info->panScan.numWindows = 0;
8373 if (output_capability == V4L2_PIX_FMT_MPEG2) {
8374 if (m_disp_hor_size && m_disp_vert_size) {
8375 frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size;
8376 frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size;
8377 }
8378 }
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07008379
Arun Menon906de572013-06-18 17:01:40 -07008380 if (panscan_payload) {
8381 frame_info->panScan.numWindows = panscan_payload->num_panscan_windows;
8382 panscan_window = &panscan_payload->wnd[0];
8383 for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) {
8384 frame_info->panScan.window[i].x = panscan_window->panscan_window_width;
8385 frame_info->panScan.window[i].y = panscan_window->panscan_window_height;
8386 frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset;
8387 frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset;
8388 panscan_window++;
8389 }
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08008390 }
Arun Menon906de572013-06-18 17:01:40 -07008391 fill_aspect_ratio_info(aspect_ratio_info, frame_info);
8392 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008393}
8394
8395void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8396{
Arun Menon906de572013-06-18 17:01:40 -07008397 OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL;
8398 extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE;
8399 extra->nVersion.nVersion = OMX_SPEC_VERSION;
8400 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8401 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef;
8402 extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
8403 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data;
8404 *portDefn = m_port_def;
8405 DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu "
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008406 "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight,
Arun Menon906de572013-06-18 17:01:40 -07008407 portDefn->format.video.nFrameWidth,
8408 portDefn->format.video.nStride,
8409 portDefn->format.video.nSliceHeight);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008410}
8411
8412void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8413{
Arun Menon906de572013-06-18 17:01:40 -07008414 if (!client_extradata) {
8415 return;
8416 }
8417 extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE);
8418 extra->nVersion.nVersion = OMX_SPEC_VERSION;
8419 extra->eType = OMX_ExtraDataNone;
8420 extra->nDataSize = 0;
8421 extra->data[0] = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008422
Arun Menon906de572013-06-18 17:01:40 -07008423 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008424}
8425
8426OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index)
8427{
Arun Menon906de572013-06-18 17:01:40 -07008428 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8429 if (index >= drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008430 DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07008431 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008432 }
Arun Menon906de572013-06-18 17:01:40 -07008433 if (m_desc_buffer_ptr == NULL) {
8434 m_desc_buffer_ptr = (desc_buffer_hdr*) \
8435 calloc( (sizeof(desc_buffer_hdr)),
8436 drv_ctx.ip_buf.actualcount);
8437 if (m_desc_buffer_ptr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008438 DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07008439 return OMX_ErrorInsufficientResources;
8440 }
8441 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008442
Arun Menon906de572013-06-18 17:01:40 -07008443 m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8));
8444 if (m_desc_buffer_ptr[index].buf_addr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008445 DEBUG_PRINT_ERROR("desc buffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07008446 return OMX_ErrorInsufficientResources;
8447 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008448
Arun Menon906de572013-06-18 17:01:40 -07008449 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008450}
8451
8452void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset)
8453{
Arun Menon906de572013-06-18 17:01:40 -07008454 DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries);
8455 if (m_demux_entries < 8192) {
8456 m_demux_offsets[m_demux_entries++] = address_offset;
8457 }
8458 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008459}
8460
8461void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr)
8462{
Arun Menon906de572013-06-18 17:01:40 -07008463 OMX_U32 bytes_to_parse = buf_hdr->nFilledLen;
8464 OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset;
8465 OMX_U32 index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008466
Arun Menon906de572013-06-18 17:01:40 -07008467 m_demux_entries = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008468
Arun Menon906de572013-06-18 17:01:40 -07008469 while (index < bytes_to_parse) {
8470 if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
8471 (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) ||
8472 ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
8473 (buf[index+2] == 0x01)) ) {
8474 //Found start code, insert address offset
8475 insert_demux_addr_offset(index);
8476 if (buf[index+2] == 0x01) // 3 byte start code
8477 index += 3;
8478 else //4 byte start code
8479 index += 4;
8480 } else
8481 index++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008482 }
Arun Menon906de572013-06-18 17:01:40 -07008483 DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries);
8484 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008485}
8486
8487OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr)
8488{
Arun Menon906de572013-06-18 17:01:40 -07008489 //fix this, handle 3 byte start code, vc1 terminator entry
8490 OMX_U8 *p_demux_data = NULL;
8491 OMX_U32 desc_data = 0;
8492 OMX_U32 start_addr = 0;
8493 OMX_U32 nal_size = 0;
8494 OMX_U32 suffix_byte = 0;
8495 OMX_U32 demux_index = 0;
8496 OMX_U32 buffer_index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008497
Arun Menon906de572013-06-18 17:01:40 -07008498 if (m_desc_buffer_ptr == NULL) {
8499 DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries.");
8500 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008501 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008502
Arun Menon906de572013-06-18 17:01:40 -07008503 buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
8504 if (buffer_index > drv_ctx.ip_buf.actualcount) {
8505 DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index);
8506 return OMX_ErrorBadParameter;
8507 }
8508
8509 p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr;
8510
8511 if ( ((OMX_U8*)p_demux_data == NULL) ||
8512 ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) {
8513 DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries.");
8514 return OMX_ErrorBadParameter;
8515 } else {
8516 for (; demux_index < m_demux_entries; demux_index++) {
8517 desc_data = 0;
8518 start_addr = m_demux_offsets[demux_index];
8519 if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) {
8520 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3];
8521 } else {
8522 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4];
8523 }
8524 if (demux_index < (m_demux_entries - 1)) {
8525 nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2;
8526 } else {
8527 nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2;
8528 }
8529 DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)",
8530 (void *)start_addr,
8531 suffix_byte,
8532 nal_size,
8533 demux_index);
8534 desc_data = (start_addr >> 3) << 1;
8535 desc_data |= (start_addr & 7) << 21;
8536 desc_data |= suffix_byte << 24;
8537
8538 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
8539 memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32));
8540 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
8541 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
8542
8543 p_demux_data += 16;
8544 }
8545 if (codec_type_parse == CODEC_TYPE_VC1) {
8546 DEBUG_PRINT_LOW("VC1 terminator entry");
8547 desc_data = 0;
8548 desc_data = 0x82 << 24;
8549 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
8550 memset(p_demux_data + 4, 0, sizeof(OMX_U32));
8551 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
8552 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
8553 p_demux_data += 16;
8554 m_demux_entries++;
8555 }
8556 //Add zero word to indicate end of descriptors
8557 memset(p_demux_data, 0, sizeof(OMX_U32));
8558
8559 m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32);
8560 DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size);
8561 }
8562 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
8563 m_demux_entries = 0;
8564 DEBUG_PRINT_LOW("Demux table complete!");
8565 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008566}
8567
Deva Ramasubramanian9403f022012-11-28 18:27:53 -08008568OMX_ERRORTYPE omx_vdec::createDivxDrmContext()
Shalaj Jain273b3e02012-06-22 19:08:03 -07008569{
Arun Menon906de572013-06-18 17:01:40 -07008570 OMX_ERRORTYPE err = OMX_ErrorNone;
8571 iDivXDrmDecrypt = DivXDrmDecrypt::Create();
8572 if (iDivXDrmDecrypt) {
8573 OMX_ERRORTYPE err = iDivXDrmDecrypt->Init();
8574 if (err!=OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008575 DEBUG_PRINT_ERROR("ERROR :iDivXDrmDecrypt->Init %d", err);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008576 delete iDivXDrmDecrypt;
8577 iDivXDrmDecrypt = NULL;
Arun Menon906de572013-06-18 17:01:40 -07008578 }
8579 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008580 DEBUG_PRINT_ERROR("Unable to Create DIVX DRM");
Arun Menon906de572013-06-18 17:01:40 -07008581 err = OMX_ErrorUndefined;
8582 }
8583 return err;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008584}
Shalaj Jain273b3e02012-06-22 19:08:03 -07008585
Vinay Kaliada4f4422013-01-09 10:45:03 -08008586omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf()
8587{
Arun Menon906de572013-06-18 17:01:40 -07008588 enabled = false;
8589 omx = NULL;
8590 init_members();
8591 ColorFormat = OMX_COLOR_FormatMax;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008592}
8593
8594void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client)
8595{
Arun Menon906de572013-06-18 17:01:40 -07008596 omx = reinterpret_cast<omx_vdec*>(client);
Vinay Kaliada4f4422013-01-09 10:45:03 -08008597}
8598
Arun Menon906de572013-06-18 17:01:40 -07008599void omx_vdec::allocate_color_convert_buf::init_members()
8600{
8601 allocated_count = 0;
8602 buffer_size_req = 0;
8603 buffer_alignment_req = 0;
8604 memset(m_platform_list_client,0,sizeof(m_platform_list_client));
8605 memset(m_platform_entry_client,0,sizeof(m_platform_entry_client));
8606 memset(m_pmem_info_client,0,sizeof(m_pmem_info_client));
8607 memset(m_out_mem_ptr_client,0,sizeof(m_out_mem_ptr_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08008608#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008609 memset(op_buf_ion_info,0,sizeof(m_platform_entry_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08008610#endif
Arun Menon906de572013-06-18 17:01:40 -07008611 for (int i = 0; i < MAX_COUNT; i++)
8612 pmem_fd[i] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008613}
8614
Arun Menon906de572013-06-18 17:01:40 -07008615omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf()
8616{
8617 c2d.destroy();
Vinay Kaliada4f4422013-01-09 10:45:03 -08008618}
8619
8620bool omx_vdec::allocate_color_convert_buf::update_buffer_req()
8621{
Arun Menon906de572013-06-18 17:01:40 -07008622 bool status = true;
8623 unsigned int src_size = 0, destination_size = 0;
8624 OMX_COLOR_FORMATTYPE drv_color_format;
8625 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008626 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07008627 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008628 }
Arun Menon906de572013-06-18 17:01:40 -07008629 if (!enabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008630 DEBUG_PRINT_HIGH("No color conversion required");
Arun Menon906de572013-06-18 17:01:40 -07008631 return status;
8632 }
8633 pthread_mutex_lock(&omx->c_lock);
8634 if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 &&
8635 ColorFormat != OMX_COLOR_FormatYUV420Planar) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008636 DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion");
Arun Menon906de572013-06-18 17:01:40 -07008637 status = false;
8638 goto fail_update_buf_req;
8639 }
8640 c2d.close();
8641 status = c2d.open(omx->drv_ctx.video_resolution.frame_height,
8642 omx->drv_ctx.video_resolution.frame_width,
8643 NV12_128m,YCbCr420P);
8644 if (status) {
8645 status = c2d.get_buffer_size(C2D_INPUT,src_size);
8646 if (status)
8647 status = c2d.get_buffer_size(C2D_OUTPUT,destination_size);
8648 }
8649 if (status) {
8650 if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size ||
8651 !destination_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008652 DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d"
Arun Menon906de572013-06-18 17:01:40 -07008653 "driver size %d destination size %d",
8654 src_size,omx->drv_ctx.op_buf.buffer_size,destination_size);
8655 status = false;
8656 c2d.close();
8657 buffer_size_req = 0;
8658 } else {
8659 buffer_size_req = destination_size;
8660 if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size)
8661 buffer_size_req = omx->drv_ctx.op_buf.buffer_size;
8662 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
8663 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
8664 }
8665 }
Praneeth Paladuguf6995272013-02-04 14:03:56 -08008666fail_update_buf_req:
Arun Menon906de572013-06-18 17:01:40 -07008667 pthread_mutex_unlock(&omx->c_lock);
8668 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008669}
8670
8671bool omx_vdec::allocate_color_convert_buf::set_color_format(
Arun Menon906de572013-06-18 17:01:40 -07008672 OMX_COLOR_FORMATTYPE dest_color_format)
Vinay Kaliada4f4422013-01-09 10:45:03 -08008673{
Arun Menon906de572013-06-18 17:01:40 -07008674 bool status = true;
8675 OMX_COLOR_FORMATTYPE drv_color_format;
8676 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008677 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07008678 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008679 }
Arun Menon906de572013-06-18 17:01:40 -07008680 pthread_mutex_lock(&omx->c_lock);
8681 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
8682 drv_color_format = (OMX_COLOR_FORMATTYPE)
8683 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
8684 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008685 DEBUG_PRINT_ERROR("Incorrect color format");
Arun Menon906de572013-06-18 17:01:40 -07008686 status = false;
8687 }
8688 if (status && (drv_color_format != dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008689 DEBUG_PRINT_LOW("Enabling C2D");
Arun Menon906de572013-06-18 17:01:40 -07008690 if (dest_color_format != OMX_COLOR_FormatYUV420Planar) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008691 DEBUG_PRINT_ERROR("Unsupported color format for c2d");
Arun Menon906de572013-06-18 17:01:40 -07008692 status = false;
8693 } else {
8694 ColorFormat = OMX_COLOR_FormatYUV420Planar;
8695 if (enabled)
8696 c2d.destroy();
8697 enabled = false;
8698 if (!c2d.init()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008699 DEBUG_PRINT_ERROR("open failed for c2d");
Arun Menon906de572013-06-18 17:01:40 -07008700 status = false;
8701 } else
8702 enabled = true;
8703 }
8704 } else {
8705 if (enabled)
8706 c2d.destroy();
8707 enabled = false;
8708 }
8709 pthread_mutex_unlock(&omx->c_lock);
8710 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008711}
8712
8713OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr()
8714{
Arun Menon906de572013-06-18 17:01:40 -07008715 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008716 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07008717 return NULL;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08008718 }
Arun Menon906de572013-06-18 17:01:40 -07008719 if (!enabled)
8720 return omx->m_out_mem_ptr;
8721 return m_out_mem_ptr_client;
8722}
8723
8724 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr
8725(OMX_BUFFERHEADERTYPE *bufadd)
8726{
8727 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008728 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07008729 return NULL;
8730 }
8731 if (!enabled)
8732 return bufadd;
8733
8734 unsigned index = 0;
8735 index = bufadd - omx->m_out_mem_ptr;
8736 if (index < omx->drv_ctx.op_buf.actualcount) {
8737 m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS);
8738 m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp;
8739 bool status;
8740 if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) {
8741 pthread_mutex_lock(&omx->c_lock);
8742 status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd,
8743 omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index],
8744 pmem_baseaddress[index], pmem_baseaddress[index]);
8745 pthread_mutex_unlock(&omx->c_lock);
8746 m_out_mem_ptr_client[index].nFilledLen = buffer_size_req;
8747 if (!status) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008748 DEBUG_PRINT_ERROR("Failed color conversion %d", status);
Arun Menon906de572013-06-18 17:01:40 -07008749 m_out_mem_ptr_client[index].nFilledLen = 0;
8750 return &m_out_mem_ptr_client[index];
8751 }
8752 } else
8753 m_out_mem_ptr_client[index].nFilledLen = 0;
8754 return &m_out_mem_ptr_client[index];
8755 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008756 DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07008757 return NULL;
8758}
8759
8760 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr
8761(OMX_BUFFERHEADERTYPE *bufadd)
8762{
8763 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008764 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07008765 return NULL;
8766 }
8767 if (!enabled)
8768 return bufadd;
8769 unsigned index = 0;
8770 index = bufadd - m_out_mem_ptr_client;
8771 if (index < omx->drv_ctx.op_buf.actualcount) {
8772 return &omx->m_out_mem_ptr[index];
8773 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008774 DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07008775 return NULL;
8776}
8777 bool omx_vdec::allocate_color_convert_buf::get_buffer_req
8778(unsigned int &buffer_size)
8779{
8780 bool status = true;
8781 pthread_mutex_lock(&omx->c_lock);
8782 if (!enabled)
Vinay Kaliada4f4422013-01-09 10:45:03 -08008783 buffer_size = omx->drv_ctx.op_buf.buffer_size;
Arun Menon906de572013-06-18 17:01:40 -07008784 else {
8785 if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008786 DEBUG_PRINT_ERROR("Get buffer size failed");
Arun Menon906de572013-06-18 17:01:40 -07008787 status = false;
8788 goto fail_get_buffer_size;
8789 }
8790 }
8791 if (buffer_size < omx->drv_ctx.op_buf.buffer_size)
8792 buffer_size = omx->drv_ctx.op_buf.buffer_size;
8793 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
8794 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08008795fail_get_buffer_size:
Arun Menon906de572013-06-18 17:01:40 -07008796 pthread_mutex_unlock(&omx->c_lock);
8797 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008798}
8799OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07008800 OMX_BUFFERHEADERTYPE *bufhdr)
8801{
8802 unsigned int index = 0;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008803
Arun Menon906de572013-06-18 17:01:40 -07008804 if (!enabled)
8805 return omx->free_output_buffer(bufhdr);
8806 if (enabled && omx->is_component_secure())
8807 return OMX_ErrorNone;
8808 if (!allocated_count || !bufhdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008809 DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr);
Arun Menon906de572013-06-18 17:01:40 -07008810 return OMX_ErrorBadParameter;
8811 }
8812 index = bufhdr - m_out_mem_ptr_client;
8813 if (index >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008814 DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer");
Arun Menon906de572013-06-18 17:01:40 -07008815 return OMX_ErrorBadParameter;
8816 }
8817 if (pmem_fd[index] > 0) {
8818 munmap(pmem_baseaddress[index], buffer_size_req);
8819 close(pmem_fd[index]);
8820 }
8821 pmem_fd[index] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008822#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008823 omx->free_ion_memory(&op_buf_ion_info[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08008824#endif
Arun Menon906de572013-06-18 17:01:40 -07008825 m_heap_ptr[index].video_heap_ptr = NULL;
8826 if (allocated_count > 0)
8827 allocated_count--;
8828 else
8829 allocated_count = 0;
8830 if (!allocated_count) {
8831 pthread_mutex_lock(&omx->c_lock);
8832 c2d.close();
8833 init_members();
8834 pthread_mutex_unlock(&omx->c_lock);
8835 }
8836 return omx->free_output_buffer(&omx->m_out_mem_ptr[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08008837}
8838
8839OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07008840 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes)
Vinay Kaliada4f4422013-01-09 10:45:03 -08008841{
Arun Menon906de572013-06-18 17:01:40 -07008842 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8843 if (!enabled) {
8844 eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes);
8845 return eRet;
8846 }
8847 if (enabled && omx->is_component_secure()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008848 DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d",
Arun Menon906de572013-06-18 17:01:40 -07008849 omx->is_component_secure());
8850 return OMX_ErrorUnsupportedSetting;
8851 }
8852 if (!bufferHdr || bytes > buffer_size_req) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008853 DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr);
8854 DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu",
Arun Menon906de572013-06-18 17:01:40 -07008855 buffer_size_req,bytes);
8856 return OMX_ErrorBadParameter;
8857 }
8858 if (allocated_count >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008859 DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert");
Arun Menon906de572013-06-18 17:01:40 -07008860 return OMX_ErrorInsufficientResources;
8861 }
8862 OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL;
8863 eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr,
8864 port,appData,omx->drv_ctx.op_buf.buffer_size);
8865 if (eRet != OMX_ErrorNone || !temp_bufferHdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008866 DEBUG_PRINT_ERROR("Buffer allocation failed color_convert");
Arun Menon906de572013-06-18 17:01:40 -07008867 return eRet;
8868 }
8869 if ((temp_bufferHdr - omx->m_out_mem_ptr) >=
Surajit Podderd2644d52013-08-28 17:59:06 +05308870 (int)omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008871 DEBUG_PRINT_ERROR("Invalid header index %d",
Arun Menon906de572013-06-18 17:01:40 -07008872 (temp_bufferHdr - omx->m_out_mem_ptr));
8873 return OMX_ErrorUndefined;
8874 }
8875 unsigned int i = allocated_count;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008876#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008877 op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory(
8878 buffer_size_req,buffer_alignment_req,
8879 &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data,
8880 0);
8881 pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd;
8882 if (op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008883 DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert");
Arun Menon906de572013-06-18 17:01:40 -07008884 return OMX_ErrorInsufficientResources;
8885 }
8886 pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req,
8887 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0);
Vinay Kaliada4f4422013-01-09 10:45:03 -08008888
Arun Menon906de572013-06-18 17:01:40 -07008889 if (pmem_baseaddress[i] == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008890 DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req);
Arun Menon906de572013-06-18 17:01:40 -07008891 close(pmem_fd[i]);
8892 omx->free_ion_memory(&op_buf_ion_info[i]);
8893 return OMX_ErrorInsufficientResources;
8894 }
8895 m_heap_ptr[i].video_heap_ptr = new VideoHeap (
8896 op_buf_ion_info[i].ion_device_fd,buffer_size_req,
8897 pmem_baseaddress[i],op_buf_ion_info[i].ion_alloc_data.handle,pmem_fd[i]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08008898#endif
Arun Menon906de572013-06-18 17:01:40 -07008899 m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get();
8900 m_pmem_info_client[i].offset = 0;
8901 m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i];
8902 m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
8903 m_platform_list_client[i].nEntries = 1;
8904 m_platform_list_client[i].entryList = &m_platform_entry_client[i];
8905 m_out_mem_ptr_client[i].pOutputPortPrivate = NULL;
8906 m_out_mem_ptr_client[i].nAllocLen = buffer_size_req;
8907 m_out_mem_ptr_client[i].nFilledLen = 0;
8908 m_out_mem_ptr_client[i].nFlags = 0;
8909 m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8910 m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE);
8911 m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION;
8912 m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i];
8913 m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i];
8914 m_out_mem_ptr_client[i].pAppPrivate = appData;
8915 *bufferHdr = &m_out_mem_ptr_client[i];
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008916 DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr);
Arun Menon906de572013-06-18 17:01:40 -07008917 allocated_count++;
8918 return eRet;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008919}
8920
8921bool omx_vdec::is_component_secure()
8922{
Arun Menon906de572013-06-18 17:01:40 -07008923 return secure_mode;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008924}
8925
8926bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format)
8927{
Arun Menon906de572013-06-18 17:01:40 -07008928 bool status = true;
8929 if (!enabled) {
8930 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
8931 dest_color_format = (OMX_COLOR_FORMATTYPE)
8932 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
8933 else
8934 status = false;
8935 } else {
8936 if (ColorFormat != OMX_COLOR_FormatYUV420Planar) {
8937 status = false;
8938 } else
8939 dest_color_format = OMX_COLOR_FormatYUV420Planar;
8940 }
8941 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008942}
Arun Menonbdb80b02013-08-12 17:45:54 -07008943
Arun Menonbdb80b02013-08-12 17:45:54 -07008944void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset)
8945{
8946 int i = 0;
8947 bool buf_present = false;
8948 pthread_mutex_lock(&m_lock);
8949 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
8950 //check the buffer fd, offset, uv addr with list contents
8951 //If present increment reference.
8952 if ((out_dynamic_list[i].fd == fd) &&
8953 (out_dynamic_list[i].offset == offset)) {
8954 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008955 DEBUG_PRINT_LOW("buf_ref_add: [ALREADY PRESENT] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07008956 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
8957 buf_present = true;
8958 break;
8959 }
8960 }
8961 if (!buf_present) {
8962 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
8963 //search for a entry to insert details of the new buffer
8964 if (out_dynamic_list[i].dup_fd == 0) {
8965 out_dynamic_list[i].fd = fd;
8966 out_dynamic_list[i].offset = offset;
8967 out_dynamic_list[i].dup_fd = dup(fd);
8968 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008969 DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07008970 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
8971 break;
8972 }
8973 }
8974 }
8975 pthread_mutex_unlock(&m_lock);
8976}
8977
8978void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset)
8979{
8980 int i = 0;
8981 pthread_mutex_lock(&m_lock);
8982 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
8983 //check the buffer fd, offset, uv addr with list contents
8984 //If present decrement reference.
8985 if ((out_dynamic_list[i].fd == fd) &&
8986 (out_dynamic_list[i].offset == offset)) {
8987 out_dynamic_list[i].ref_count--;
8988 if (out_dynamic_list[i].ref_count == 0) {
8989 close(out_dynamic_list[i].dup_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008990 DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07008991 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
8992 out_dynamic_list[i].dup_fd = 0;
8993 out_dynamic_list[i].fd = 0;
8994 out_dynamic_list[i].offset = 0;
8995 }
8996 break;
8997 }
8998 }
8999 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009000 DEBUG_PRINT_ERROR("Error - could not remove ref, no match with any entry in list");
Arun Menonbdb80b02013-08-12 17:45:54 -07009001 }
9002 pthread_mutex_unlock(&m_lock);
9003}