blob: 8b9ab1663a885a0b12b74650db6745213b5f2d7a [file] [log] [blame]
Shalaj Jain273b3e02012-06-22 19:08:03 -07001/*--------------------------------------------------------------------------
Maheshwar Ajja507d6552014-01-03 14:54:29 +05302Copyright (c) 2010 - 2014, The Linux Foundation. All rights reserved.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
Vinay Kaliae4a7d9d2013-01-21 10:16:33 -080011 * Neither the name of The Linux Foundation nor
Shalaj Jain273b3e02012-06-22 19:08:03 -070012 the names of its contributors may be used to endorse or promote
13 products derived from this software without specific prior written
14 permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27--------------------------------------------------------------------------*/
28
29/*============================================================================
30 O p e n M A X w r a p p e r s
31 O p e n M A X C o r e
32
33*//** @file omx_vdec.cpp
34 This module contains the implementation of the OpenMAX core & component.
35
36*//*========================================================================*/
37
38//////////////////////////////////////////////////////////////////////////////
39// Include Files
40//////////////////////////////////////////////////////////////////////////////
41
Deva Ramasubramanianeb819322014-07-17 14:23:35 -070042#define __STDC_FORMAT_MACROS
43#include <inttypes.h>
44
Shalaj Jain273b3e02012-06-22 19:08:03 -070045#include <string.h>
46#include <pthread.h>
47#include <sys/prctl.h>
48#include <stdlib.h>
49#include <unistd.h>
50#include <errno.h>
51#include "omx_vdec.h"
52#include <fcntl.h>
53#include <limits.h>
Deva Ramasubramanian15bbc1c2013-05-13 16:05:03 -070054#include <stdlib.h>
Arun Menonbdb80b02013-08-12 17:45:54 -070055#include <media/hardware/HardwareAPI.h>
Vinay Kaliada8f3cf2012-12-21 18:26:21 -080056#include <media/msm_media_info.h>
Shalaj Jain273b3e02012-06-22 19:08:03 -070057
58#ifndef _ANDROID_
59#include <sys/ioctl.h>
60#include <sys/mman.h>
61#endif //_ANDROID_
62
63#ifdef _ANDROID_
64#include <cutils/properties.h>
65#undef USE_EGL_IMAGE_GPU
66#endif
67
Vinay Kalia0e75e9a2012-09-27 15:41:53 -070068#include <qdMetaData.h>
Shalaj Jain273b3e02012-06-22 19:08:03 -070069
Arun Menon45346052013-11-13 12:40:08 -080070#ifdef METADATA_FOR_DYNAMIC_MODE
Arun Menon9af783f2013-10-22 12:57:14 -070071#include "QComOMXMetadata.h"
72#endif
73
Shalaj Jain273b3e02012-06-22 19:08:03 -070074#ifdef USE_EGL_IMAGE_GPU
75#include <EGL/egl.h>
76#include <EGL/eglQCOM.h>
77#define EGL_BUFFER_HANDLE_QCOM 0x4F00
78#define EGL_BUFFER_OFFSET_QCOM 0x4F01
79#endif
Vinay Kalia21649b32013-03-18 17:28:07 -070080
Jayasena Sangaraboina51230642013-08-21 18:02:13 -070081#define BUFFER_LOG_LOC "/data/misc/media"
82
Shalaj Jain273b3e02012-06-22 19:08:03 -070083#ifdef OUTPUT_EXTRADATA_LOG
84FILE *outputExtradataFile;
Deva Ramasubramanianee6f1f42014-01-31 12:49:18 -080085char output_extradata_filename [] = "/data/misc/extradata";
Shalaj Jain273b3e02012-06-22 19:08:03 -070086#endif
87
88#define DEFAULT_FPS 30
Shalaj Jain273b3e02012-06-22 19:08:03 -070089#define MAX_SUPPORTED_FPS 120
Deepak Vermaa2efdb12013-12-26 12:30:05 +053090#define DEFAULT_WIDTH_ALIGNMENT 128
91#define DEFAULT_HEIGHT_ALIGNMENT 32
Shalaj Jain273b3e02012-06-22 19:08:03 -070092
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)
Maheshwar Ajja77cd19c2014-06-05 11:23:18 +0530125#define ALIGN(x, to_align) ((((unsigned) x) + (to_align - 1)) & ~(to_align - 1))
Vinay Kalia0e75e9a2012-09-27 15:41:53 -0700126
Vinay Kaliadb90f8c2012-11-19 18:57:56 -0800127#define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA)
Jia Meng3a3c6492013-12-19 17:16:52 +0800128#define DEFAULT_CONCEAL_COLOR "32896" //0x8080, black by default
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700129
130int debug_level = PRIO_ERROR;
131
Deepak Vermaa2efdb12013-12-26 12:30:05 +0530132static OMX_U32 maxSmoothStreamingWidth = 1920;
133static OMX_U32 maxSmoothStreamingHeight = 1088;
Praveen Chavancf924182013-12-06 23:16:23 -0800134
Shalaj Jain273b3e02012-06-22 19:08:03 -0700135void* async_message_thread (void *input)
136{
Arun Menon906de572013-06-18 17:01:40 -0700137 OMX_BUFFERHEADERTYPE *buffer;
138 struct v4l2_plane plane[VIDEO_MAX_PLANES];
139 struct pollfd pfd;
140 struct v4l2_buffer v4l2_buf;
141 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
142 struct v4l2_event dqevent;
143 omx_vdec *omx = reinterpret_cast<omx_vdec*>(input);
144 pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI;
145 pfd.fd = omx->drv_ctx.video_driver_fd;
146 int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700147 DEBUG_PRINT_HIGH("omx_vdec: Async thread start");
Arun Menon906de572013-06-18 17:01:40 -0700148 prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0);
149 while (1) {
150 rc = poll(&pfd, 1, POLL_TIMEOUT);
151 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700152 DEBUG_PRINT_ERROR("Poll timedout");
Arun Menon906de572013-06-18 17:01:40 -0700153 break;
Deepak Kushwah4193f602015-11-17 15:45:22 +0530154 } else if (rc < 0 && errno != EINTR && errno != EAGAIN) {
155 DEBUG_PRINT_ERROR("Error while polling: %d, errno = %d", rc, errno);
Arun Menon906de572013-06-18 17:01:40 -0700156 break;
157 }
158 if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) {
159 struct vdec_msginfo vdec_msg;
160 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
161 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
162 v4l2_buf.length = omx->drv_ctx.num_planes;
163 v4l2_buf.m.planes = plane;
164 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
165 vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
166 vdec_msg.status_code=VDEC_S_SUCCESS;
167 vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf;
168 vdec_msg.msgdata.output_frame.len=plane[0].bytesused;
169 vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr;
170 vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) +
171 (uint64_t)v4l2_buf.timestamp.tv_usec;
172 if (vdec_msg.msgdata.output_frame.len) {
173 vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2];
174 vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3];
175 vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4];
176 vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5];
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +0530177 vdec_msg.msgdata.output_frame.picsize.frame_width = plane[0].reserved[6];
178 vdec_msg.msgdata.output_frame.picsize.frame_height = plane[0].reserved[7];
Arun Menon906de572013-06-18 17:01:40 -0700179 }
180 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700181 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700182 break;
183 }
184 }
185 }
186 if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) {
187 struct vdec_msginfo vdec_msg;
188 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
189 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
190 v4l2_buf.length = 1;
191 v4l2_buf.m.planes = plane;
192 while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) {
193 vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE;
194 vdec_msg.status_code=VDEC_S_SUCCESS;
195 vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf;
196 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700197 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700198 break;
199 }
200 }
201 }
202 if (pfd.revents & POLLPRI) {
203 rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent);
204 if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) {
205 struct vdec_msginfo vdec_msg;
206 vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED;
207 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700208 DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient");
Arun Menon906de572013-06-18 17:01:40 -0700209 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700210 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700211 break;
212 }
213 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) {
214 struct vdec_msginfo vdec_msg;
215 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE;
216 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700217 DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700218 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700219 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700220 break;
221 }
222 vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE;
223 vdec_msg.status_code=VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700224 DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700225 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700226 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700227 break;
228 }
229 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700230 DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700231 break;
Deepak Verma24720fb2014-01-29 16:57:40 +0530232 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_HW_OVERLOAD) {
233 struct vdec_msginfo vdec_msg;
234 vdec_msg.msgcode=VDEC_MSG_EVT_HW_OVERLOAD;
235 vdec_msg.status_code=VDEC_S_SUCCESS;
236 DEBUG_PRINT_ERROR("HW Overload received");
237 if (omx->async_message_process(input,&vdec_msg) < 0) {
238 DEBUG_PRINT_HIGH("async_message_thread Exited");
239 break;
240 }
Arun Menon906de572013-06-18 17:01:40 -0700241 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) {
242 struct vdec_msginfo vdec_msg;
Jia Meng1e236c82014-04-03 10:54:39 +0800243 vdec_msg.msgcode = VDEC_MSG_EVT_HW_ERROR;
244 vdec_msg.status_code = VDEC_S_SUCCESS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700245 DEBUG_PRINT_HIGH("SYS Error Recieved");
Arun Menon906de572013-06-18 17:01:40 -0700246 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700247 DEBUG_PRINT_HIGH("async_message_thread Exited");
Arun Menon906de572013-06-18 17:01:40 -0700248 break;
249 }
Arun Menon45346052013-11-13 12:40:08 -0800250 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) {
Arun Menonbdb80b02013-08-12 17:45:54 -0700251 unsigned int *ptr = (unsigned int *)dqevent.u.data;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700252 DEBUG_PRINT_LOW("REFERENCE RELEASE EVENT RECVD fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700253 omx->buf_ref_remove(ptr[0], ptr[1]);
254 } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) {
255 unsigned int *ptr = (unsigned int *)dqevent.u.data;
256 struct vdec_msginfo vdec_msg;
257
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700258 DEBUG_PRINT_LOW("Release unqueued buffer event recvd fd = %d offset = %d", ptr[0], ptr[1]);
Arun Menonbdb80b02013-08-12 17:45:54 -0700259
260 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
261 v4l2_buf.memory = V4L2_MEMORY_USERPTR;
262 v4l2_buf.length = omx->drv_ctx.num_planes;
263 v4l2_buf.m.planes = plane;
264 v4l2_buf.index = ptr[5];
265 v4l2_buf.flags = 0;
266
267 vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE;
268 vdec_msg.status_code = VDEC_S_SUCCESS;
269 vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf;
270 vdec_msg.msgdata.output_frame.len = 0;
271 vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2];
272 vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) +
273 (uint64_t)ptr[4];
274 if (omx->async_message_process(input,&vdec_msg) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700275 DEBUG_PRINT_HIGH("async_message_thread Exitedn");
Arun Menonbdb80b02013-08-12 17:45:54 -0700276 break;
277 }
278 }
Arun Menonbdb80b02013-08-12 17:45:54 -0700279 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700280 DEBUG_PRINT_HIGH("VIDC Some Event recieved");
Arun Menon906de572013-06-18 17:01:40 -0700281 continue;
282 }
283 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -0700284 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700285 DEBUG_PRINT_HIGH("omx_vdec: Async thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700286 return NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700287}
288
Ashray Kulkarnia97efbc2015-07-15 18:17:23 -0700289void* dec_message_thread(void *input)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700290{
Arun Menon906de572013-06-18 17:01:40 -0700291 omx_vdec* omx = reinterpret_cast<omx_vdec*>(input);
292 unsigned char id;
293 int n;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700294
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700295 DEBUG_PRINT_HIGH("omx_vdec: message thread start");
Arun Menon906de572013-06-18 17:01:40 -0700296 prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0);
297 while (1) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700298
Arun Menon906de572013-06-18 17:01:40 -0700299 n = read(omx->m_pipe_in, &id, 1);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700300
Arun Menon906de572013-06-18 17:01:40 -0700301 if (0 == n) {
302 break;
303 }
304
305 if (1 == n) {
306 omx->process_event_cb(omx, id);
307 }
308 if ((n < 0) && (errno != EINTR)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700309 DEBUG_PRINT_LOW("ERROR: read from pipe failed, ret %d errno %d", n, errno);
Arun Menon906de572013-06-18 17:01:40 -0700310 break;
311 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700312 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700313 DEBUG_PRINT_HIGH("omx_vdec: message thread stop");
Arun Menon906de572013-06-18 17:01:40 -0700314 return 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700315}
316
317void post_message(omx_vdec *omx, unsigned char id)
318{
Arun Menon906de572013-06-18 17:01:40 -0700319 int ret_value;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700320 DEBUG_PRINT_LOW("omx_vdec: post_message %d pipe out%d", id,omx->m_pipe_out);
Arun Menon906de572013-06-18 17:01:40 -0700321 ret_value = write(omx->m_pipe_out, &id, 1);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700322 DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700323}
324
325// omx_cmd_queue destructor
326omx_vdec::omx_cmd_queue::~omx_cmd_queue()
327{
Arun Menon906de572013-06-18 17:01:40 -0700328 // Nothing to do
Shalaj Jain273b3e02012-06-22 19:08:03 -0700329}
330
331// omx cmd queue constructor
332omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0)
333{
334 memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE);
335}
336
337// omx cmd queue insert
338bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id)
339{
Arun Menon906de572013-06-18 17:01:40 -0700340 bool ret = true;
341 if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) {
342 m_q[m_write].id = id;
343 m_q[m_write].param1 = p1;
344 m_q[m_write].param2 = p2;
345 m_write++;
346 m_size ++;
347 if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) {
348 m_write = 0;
349 }
350 } else {
351 ret = false;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700352 DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700353 }
Arun Menon906de572013-06-18 17:01:40 -0700354 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700355}
356
357// omx cmd queue pop
358bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id)
359{
Arun Menon906de572013-06-18 17:01:40 -0700360 bool ret = true;
361 if (m_size > 0) {
362 *id = m_q[m_read].id;
363 *p1 = m_q[m_read].param1;
364 *p2 = m_q[m_read].param2;
365 // Move the read pointer ahead
366 ++m_read;
367 --m_size;
368 if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) {
369 m_read = 0;
370 }
371 } else {
372 ret = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700373 }
Arun Menon906de572013-06-18 17:01:40 -0700374 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700375}
376
377// Retrieve the first mesg type in the queue
378unsigned omx_vdec::omx_cmd_queue::get_q_msg_type()
379{
380 return m_q[m_read].id;
381}
382
383#ifdef _ANDROID_
384omx_vdec::ts_arr_list::ts_arr_list()
385{
Arun Menon906de572013-06-18 17:01:40 -0700386 //initialize timestamps array
387 memset(m_ts_arr_list, 0, ( sizeof(ts_entry) * MAX_NUM_INPUT_OUTPUT_BUFFERS) );
Shalaj Jain273b3e02012-06-22 19:08:03 -0700388}
389omx_vdec::ts_arr_list::~ts_arr_list()
390{
Arun Menon906de572013-06-18 17:01:40 -0700391 //free m_ts_arr_list?
Shalaj Jain273b3e02012-06-22 19:08:03 -0700392}
393
394bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts)
395{
Arun Menon906de572013-06-18 17:01:40 -0700396 bool ret = true;
397 bool duplicate_ts = false;
398 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700399
Arun Menon906de572013-06-18 17:01:40 -0700400 //insert at the first available empty location
401 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
402 if (!m_ts_arr_list[idx].valid) {
403 //found invalid or empty entry, save timestamp
404 m_ts_arr_list[idx].valid = true;
405 m_ts_arr_list[idx].timestamp = ts;
406 DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)",
407 ts, idx);
408 break;
409 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700410 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700411
Arun Menon906de572013-06-18 17:01:40 -0700412 if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) {
413 DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert");
414 ret = false;
415 }
416 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700417}
418
419bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts)
420{
Arun Menon906de572013-06-18 17:01:40 -0700421 bool ret = true;
422 int min_idx = -1;
423 OMX_TICKS min_ts = 0;
424 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700425
Arun Menon906de572013-06-18 17:01:40 -0700426 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
Shalaj Jain273b3e02012-06-22 19:08:03 -0700427
Arun Menon906de572013-06-18 17:01:40 -0700428 if (m_ts_arr_list[idx].valid) {
429 //found valid entry, save index
430 if (min_idx < 0) {
431 //first valid entry
432 min_ts = m_ts_arr_list[idx].timestamp;
433 min_idx = idx;
434 } else if (m_ts_arr_list[idx].timestamp < min_ts) {
435 min_ts = m_ts_arr_list[idx].timestamp;
436 min_idx = idx;
437 }
438 }
439
Shalaj Jain273b3e02012-06-22 19:08:03 -0700440 }
441
Arun Menon906de572013-06-18 17:01:40 -0700442 if (min_idx < 0) {
443 //no valid entries found
444 DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop");
445 ts = 0;
446 ret = false;
447 } else {
448 ts = m_ts_arr_list[min_idx].timestamp;
449 m_ts_arr_list[min_idx].valid = false;
450 DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)",
451 ts, min_idx);
452 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700453
Arun Menon906de572013-06-18 17:01:40 -0700454 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700455
456}
457
458
459bool omx_vdec::ts_arr_list::reset_ts_list()
460{
Arun Menon906de572013-06-18 17:01:40 -0700461 bool ret = true;
462 int idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700463
Arun Menon906de572013-06-18 17:01:40 -0700464 DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list");
465 for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) {
466 m_ts_arr_list[idx].valid = false;
467 }
468 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700469}
470#endif
471
472// factory function executed by the core to create instances
473void *get_omx_component_factory_fn(void)
474{
Arun Menon906de572013-06-18 17:01:40 -0700475 return (new omx_vdec);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700476}
477
478#ifdef _ANDROID_
479#ifdef USE_ION
480VideoHeap::VideoHeap(int devicefd, size_t size, void* base,
Mitchel Humpherys2294c232013-12-10 12:14:04 -0800481 ion_user_handle_t handle, int ionMapfd)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700482{
Arun Menon906de572013-06-18 17:01:40 -0700483 // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700484}
485#else
486VideoHeap::VideoHeap(int fd, size_t size, void* base)
487{
488 // dup file descriptor, map once, use pmem
489 init(dup(fd), base, size, 0 , MEM_DEVICE);
490}
491#endif
492#endif // _ANDROID_
493/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700494 FUNCTION
495 omx_vdec::omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700496
Arun Menon906de572013-06-18 17:01:40 -0700497 DESCRIPTION
498 Constructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700499
Arun Menon906de572013-06-18 17:01:40 -0700500 PARAMETERS
501 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700502
Arun Menon906de572013-06-18 17:01:40 -0700503 RETURN VALUE
504 None.
505 ========================================================================== */
Deva Ramasubramanian5c241242013-02-19 17:25:30 -0800506omx_vdec::omx_vdec(): m_error_propogated(false),
Arun Menon906de572013-06-18 17:01:40 -0700507 m_state(OMX_StateInvalid),
508 m_app_data(NULL),
509 m_inp_mem_ptr(NULL),
510 m_out_mem_ptr(NULL),
Arun Menon906de572013-06-18 17:01:40 -0700511 input_flush_progress (false),
512 output_flush_progress (false),
513 input_use_buffer (false),
514 output_use_buffer (false),
515 ouput_egl_buffers(false),
516 m_use_output_pmem(OMX_FALSE),
517 m_out_mem_region_smi(OMX_FALSE),
518 m_out_pvt_entry_pmem(OMX_FALSE),
519 pending_input_buffers(0),
520 pending_output_buffers(0),
521 m_out_bm_count(0),
522 m_inp_bm_count(0),
523 m_inp_bPopulated(OMX_FALSE),
524 m_out_bPopulated(OMX_FALSE),
525 m_flags(0),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700526#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700527 m_heap_ptr(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700528#endif
Arun Menon906de572013-06-18 17:01:40 -0700529 m_inp_bEnabled(OMX_TRUE),
530 m_out_bEnabled(OMX_TRUE),
531 m_in_alloc_cnt(0),
532 m_platform_list(NULL),
533 m_platform_entry(NULL),
534 m_pmem_info(NULL),
535 arbitrary_bytes (true),
536 psource_frame (NULL),
537 pdest_frame (NULL),
538 m_inp_heap_ptr (NULL),
539 m_phdr_pmem_ptr(NULL),
540 m_heap_inp_bm_count (0),
541 codec_type_parse ((codec_type)0),
542 first_frame_meta (true),
543 frame_count (0),
544 nal_count (0),
545 nal_length(0),
546 look_ahead_nal (false),
547 first_frame(0),
548 first_buffer(NULL),
549 first_frame_size (0),
550 m_device_file_ptr(NULL),
551 m_vc1_profile((vc1_profile_type)0),
Arun Menon906de572013-06-18 17:01:40 -0700552 h264_last_au_ts(LLONG_MAX),
553 h264_last_au_flags(0),
Surajit Podderd2644d52013-08-28 17:59:06 +0530554 m_disp_hor_size(0),
555 m_disp_vert_size(0),
Arun Menon906de572013-06-18 17:01:40 -0700556 prev_ts(LLONG_MAX),
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -0700557 prev_ts_actual(LLONG_MAX),
Arun Menon906de572013-06-18 17:01:40 -0700558 rst_prev_ts(true),
559 frm_int(0),
Arun Menon906de572013-06-18 17:01:40 -0700560 in_reconfig(false),
561 m_display_id(NULL),
562 h264_parser(NULL),
563 client_extradata(0),
564 m_reject_avc_1080p_mp (0),
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +0530565 m_other_extradata(NULL),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700566#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700567 m_enable_android_native_buffers(OMX_FALSE),
568 m_use_android_native_buffers(OMX_FALSE),
Shalaj Jain273b3e02012-06-22 19:08:03 -0700569#endif
Arun Menon906de572013-06-18 17:01:40 -0700570 m_desc_buffer_ptr(NULL),
571 secure_mode(false),
Praveen Chavand443c0d2016-04-19 12:25:46 -0700572 allocate_native_handle(false),
Surajit Podderd2644d52013-08-28 17:59:06 +0530573 m_profile(0),
vivek mehtaa75c69f2014-01-10 21:50:37 -0800574 client_set_fps(false),
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -0700575 m_last_rendered_TS(-1),
Sri Karri38569452018-03-16 12:46:14 +0530576 m_queued_codec_config_count(0),
577 m_buffer_error(false)
Shalaj Jain273b3e02012-06-22 19:08:03 -0700578{
Arun Menon906de572013-06-18 17:01:40 -0700579 /* Assumption is that , to begin with , we have all the frames with decoder */
580 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700581 memset(&m_debug,0,sizeof(m_debug));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700582#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700583 char property_value[PROPERTY_VALUE_MAX] = {0};
Jayasena Sangaraboinac4dfc282013-08-08 12:41:39 -0700584 property_get("vidc.debug.level", property_value, "0");
585 debug_level = atoi(property_value);
586 property_value[0] = '\0';
587
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700588 DEBUG_PRINT_HIGH("In OMX vdec Constructor");
589
Arun Menon906de572013-06-18 17:01:40 -0700590 property_get("vidc.dec.debug.perf", property_value, "0");
591 perf_flag = atoi(property_value);
592 if (perf_flag) {
593 DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag);
594 dec_time.start();
595 proc_frms = latency = 0;
596 }
597 prev_n_filled_len = 0;
598 property_value[0] = '\0';
599 property_get("vidc.dec.debug.ts", property_value, "0");
600 m_debug_timestamp = atoi(property_value);
601 DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp);
602 if (m_debug_timestamp) {
603 time_stamp_dts.set_timestamp_reorder_mode(true);
604 time_stamp_dts.enable_debug_print(true);
605 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700606
Arun Menon906de572013-06-18 17:01:40 -0700607 property_value[0] = '\0';
608 property_get("vidc.dec.debug.concealedmb", property_value, "0");
609 m_debug_concealedmb = atoi(property_value);
610 DEBUG_PRINT_HIGH("vidc.dec.debug.concealedmb value is %d",m_debug_concealedmb);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700611
Arun Menon906de572013-06-18 17:01:40 -0700612 property_value[0] = '\0';
613 property_get("vidc.dec.profile.check", property_value, "0");
614 m_reject_avc_1080p_mp = atoi(property_value);
615 DEBUG_PRINT_HIGH("vidc.dec.profile.check value is %d",m_reject_avc_1080p_mp);
Rajeshwar Kurapatye0e7d0c2013-07-30 19:46:26 +0530616
Jayasena Sangaraboina51230642013-08-21 18:02:13 -0700617 property_value[0] = '\0';
618 property_get("vidc.dec.log.in", property_value, "0");
619 m_debug.in_buffer_log = atoi(property_value);
620
621 property_value[0] = '\0';
622 property_get("vidc.dec.log.out", property_value, "0");
623 m_debug.out_buffer_log = atoi(property_value);
624 sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC);
625
626 property_value[0] = '\0';
627 property_get("vidc.log.loc", property_value, "");
628 if (*property_value)
629 strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX);
vivek mehta79cff222014-01-22 12:17:07 -0800630
631 property_value[0] = '\0';
632 property_get("vidc.dec.120fps.enabled", property_value, "0");
633
634 //if this feature is not enabled then reset this value -ve
635 if(atoi(property_value)) {
636 DEBUG_PRINT_LOW("feature 120 FPS decode enabled");
637 m_last_rendered_TS = 0;
638 }
639
Shalaj Jain273b3e02012-06-22 19:08:03 -0700640#endif
Arun Menon906de572013-06-18 17:01:40 -0700641 memset(&m_cmp,0,sizeof(m_cmp));
642 memset(&m_cb,0,sizeof(m_cb));
643 memset (&drv_ctx,0,sizeof(drv_ctx));
644 memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE));
645 memset (m_hwdevice_name,0,sizeof(m_hwdevice_name));
646 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +0530647 memset(&m_custom_buffersize, 0, sizeof(m_custom_buffersize));
Arun Menon906de572013-06-18 17:01:40 -0700648 m_demux_entries = 0;
649 msg_thread_id = 0;
650 async_thread_id = 0;
651 msg_thread_created = false;
652 async_thread_created = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700653#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -0700654 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
Shalaj Jain273b3e02012-06-22 19:08:03 -0700655#endif
Arun Menon906de572013-06-18 17:01:40 -0700656 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Maheshwar Ajjad2df2182013-10-24 19:20:34 +0530657 memset(&m_frame_pack_arrangement, 0, sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
Arun Menon906de572013-06-18 17:01:40 -0700658 drv_ctx.timestamp_adjust = false;
659 drv_ctx.video_driver_fd = -1;
660 m_vendor_config.pData = NULL;
661 pthread_mutex_init(&m_lock, NULL);
662 pthread_mutex_init(&c_lock, NULL);
Praveen Chavaneac7fd02016-04-25 10:03:42 -0700663 pthread_mutex_init(&buf_lock, NULL);
Arun Menon906de572013-06-18 17:01:40 -0700664 sem_init(&m_cmd_lock,0,0);
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -0700665 sem_init(&m_safe_flush, 0, 0);
Arun Menon906de572013-06-18 17:01:40 -0700666 streaming[CAPTURE_PORT] =
667 streaming[OUTPUT_PORT] = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700668#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -0700669 char extradata_value[PROPERTY_VALUE_MAX] = {0};
670 property_get("vidc.dec.debug.extradata", extradata_value, "0");
671 m_debug_extradata = atoi(extradata_value);
672 DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700673#endif
Arun Menon906de572013-06-18 17:01:40 -0700674 m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB;
675 client_buffers.set_vdec_client(this);
Arun Menonbdb80b02013-08-12 17:45:54 -0700676 dynamic_buf_mode = false;
677 out_dynamic_list = NULL;
Praveen Chavane78460c2013-12-06 23:16:04 -0800678 is_down_scalar_enabled = false;
Praveen Chavancf924182013-12-06 23:16:23 -0800679 m_smoothstreaming_mode = false;
680 m_smoothstreaming_width = 0;
681 m_smoothstreaming_height = 0;
Deepak Vermaa2efdb12013-12-26 12:30:05 +0530682 is_q6_platform = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700683}
684
Vinay Kalia85793762012-06-14 19:12:34 -0700685static const int event_type[] = {
Arun Menon906de572013-06-18 17:01:40 -0700686 V4L2_EVENT_MSM_VIDC_FLUSH_DONE,
687 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT,
688 V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT,
Arun Menonbdb80b02013-08-12 17:45:54 -0700689 V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE,
690 V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER,
Arun Menon906de572013-06-18 17:01:40 -0700691 V4L2_EVENT_MSM_VIDC_CLOSE_DONE,
Jia Meng1e236c82014-04-03 10:54:39 +0800692 V4L2_EVENT_MSM_VIDC_SYS_ERROR,
693 V4L2_EVENT_MSM_VIDC_HW_OVERLOAD
Vinay Kalia85793762012-06-14 19:12:34 -0700694};
695
696static OMX_ERRORTYPE subscribe_to_events(int fd)
697{
Arun Menon906de572013-06-18 17:01:40 -0700698 OMX_ERRORTYPE eRet = OMX_ErrorNone;
699 struct v4l2_event_subscription sub;
700 int array_sz = sizeof(event_type)/sizeof(int);
701 int i,rc;
702 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700703 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700704 return OMX_ErrorBadParameter;
705 }
Vinay Kalia85793762012-06-14 19:12:34 -0700706
Arun Menon906de572013-06-18 17:01:40 -0700707 for (i = 0; i < array_sz; ++i) {
708 memset(&sub, 0, sizeof(sub));
709 sub.type = event_type[i];
710 rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
711 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700712 DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700713 break;
714 }
715 }
716 if (i < array_sz) {
717 for (--i; i >=0 ; i--) {
718 memset(&sub, 0, sizeof(sub));
719 sub.type = event_type[i];
720 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
721 if (rc)
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700722 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700723 }
724 eRet = OMX_ErrorNotImplemented;
725 }
726 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700727}
728
729
730static OMX_ERRORTYPE unsubscribe_to_events(int fd)
731{
Arun Menon906de572013-06-18 17:01:40 -0700732 OMX_ERRORTYPE eRet = OMX_ErrorNone;
733 struct v4l2_event_subscription sub;
734 int array_sz = sizeof(event_type)/sizeof(int);
735 int i,rc;
736 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700737 DEBUG_PRINT_ERROR("Invalid input: %d", fd);
Arun Menon906de572013-06-18 17:01:40 -0700738 return OMX_ErrorBadParameter;
739 }
Vinay Kalia85793762012-06-14 19:12:34 -0700740
Arun Menon906de572013-06-18 17:01:40 -0700741 for (i = 0; i < array_sz; ++i) {
742 memset(&sub, 0, sizeof(sub));
743 sub.type = event_type[i];
744 rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub);
745 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700746 DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type);
Arun Menon906de572013-06-18 17:01:40 -0700747 break;
748 }
749 }
750 return eRet;
Vinay Kalia85793762012-06-14 19:12:34 -0700751}
Shalaj Jain273b3e02012-06-22 19:08:03 -0700752
753/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700754 FUNCTION
755 omx_vdec::~omx_vdec
Shalaj Jain273b3e02012-06-22 19:08:03 -0700756
Arun Menon906de572013-06-18 17:01:40 -0700757 DESCRIPTION
758 Destructor
Shalaj Jain273b3e02012-06-22 19:08:03 -0700759
Arun Menon906de572013-06-18 17:01:40 -0700760 PARAMETERS
761 None
Shalaj Jain273b3e02012-06-22 19:08:03 -0700762
Arun Menon906de572013-06-18 17:01:40 -0700763 RETURN VALUE
764 None.
765 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700766omx_vdec::~omx_vdec()
767{
Arun Menon906de572013-06-18 17:01:40 -0700768 m_pmem_info = NULL;
769 struct v4l2_decoder_cmd dec;
770 DEBUG_PRINT_HIGH("In OMX vdec Destructor");
771 if (m_pipe_in) close(m_pipe_in);
772 if (m_pipe_out) close(m_pipe_out);
773 m_pipe_in = -1;
774 m_pipe_out = -1;
775 DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit");
776 if (msg_thread_created)
777 pthread_join(msg_thread_id,NULL);
778 DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit");
779 dec.cmd = V4L2_DEC_CMD_STOP;
780 if (drv_ctx.video_driver_fd >=0 ) {
781 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700782 DEBUG_PRINT_ERROR("STOP Command failed");
Arun Menon906de572013-06-18 17:01:40 -0700783 }
784 if (async_thread_created)
785 pthread_join(async_thread_id,NULL);
786 unsubscribe_to_events(drv_ctx.video_driver_fd);
787 close(drv_ctx.video_driver_fd);
788 pthread_mutex_destroy(&m_lock);
789 pthread_mutex_destroy(&c_lock);
Praveen Chavaneac7fd02016-04-25 10:03:42 -0700790 pthread_mutex_destroy(&buf_lock);
Arun Menon906de572013-06-18 17:01:40 -0700791 sem_destroy(&m_cmd_lock);
792 if (perf_flag) {
793 DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME");
794 dec_time.end();
795 }
796 DEBUG_PRINT_HIGH("Exit OMX vdec Destructor");
Shalaj Jain273b3e02012-06-22 19:08:03 -0700797}
798
Arun Menon906de572013-06-18 17:01:40 -0700799int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type)
800{
801 struct v4l2_requestbuffers bufreq;
802 int rc = 0;
803 if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
804 bufreq.memory = V4L2_MEMORY_USERPTR;
805 bufreq.count = 0;
806 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
807 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Surajit Podder12aefac2013-08-06 18:43:32 +0530808 } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) {
809 bufreq.memory = V4L2_MEMORY_USERPTR;
810 bufreq.count = 0;
811 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
812 rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Arun Menon906de572013-06-18 17:01:40 -0700813 }
814 return rc;
Vinay Kaliafeef7032012-09-25 19:23:33 -0700815}
816
Shalaj Jain273b3e02012-06-22 19:08:03 -0700817/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -0700818 FUNCTION
819 omx_vdec::OMXCntrlProcessMsgCb
Shalaj Jain273b3e02012-06-22 19:08:03 -0700820
Arun Menon906de572013-06-18 17:01:40 -0700821 DESCRIPTION
822 IL Client callbacks are generated through this routine. The decoder
823 provides the thread context for this routine.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700824
Arun Menon906de572013-06-18 17:01:40 -0700825 PARAMETERS
826 ctxt -- Context information related to the self.
827 id -- Event identifier. This could be any of the following:
828 1. Command completion event
829 2. Buffer done callback event
830 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -0700831
Arun Menon906de572013-06-18 17:01:40 -0700832 RETURN VALUE
833 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -0700834
Arun Menon906de572013-06-18 17:01:40 -0700835 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -0700836void omx_vdec::process_event_cb(void *ctxt, unsigned char id)
837{
Arun Menon906de572013-06-18 17:01:40 -0700838 signed p1; // Parameter - 1
839 signed p2; // Parameter - 2
840 unsigned ident;
841 unsigned qsize=0; // qsize
842 omx_vdec *pThis = (omx_vdec *) ctxt;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700843
Arun Menon906de572013-06-18 17:01:40 -0700844 if (!pThis) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700845 DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out",
Arun Menon906de572013-06-18 17:01:40 -0700846 __func__);
847 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -0700848 }
849
Arun Menon906de572013-06-18 17:01:40 -0700850 // Protect the shared queue data structure
851 do {
852 /*Read the message id's from the queue*/
853 pthread_mutex_lock(&pThis->m_lock);
854 qsize = pThis->m_cmd_q.m_size;
855 if (qsize) {
856 pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -0700857 }
Arun Menon906de572013-06-18 17:01:40 -0700858
859 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
860 qsize = pThis->m_ftb_q.m_size;
861 if (qsize) {
862 pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
863 }
Shalaj Jain273b3e02012-06-22 19:08:03 -0700864 }
Arun Menon906de572013-06-18 17:01:40 -0700865
866 if (qsize == 0 && pThis->m_state != OMX_StatePause) {
867 qsize = pThis->m_etb_q.m_size;
868 if (qsize) {
869 pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident);
870 }
871 }
872 pthread_mutex_unlock(&pThis->m_lock);
873
874 /*process message if we have one*/
875 if (qsize > 0) {
876 id = ident;
877 switch (id) {
878 case OMX_COMPONENT_GENERATE_EVENT:
879 if (pThis->m_cb.EventHandler) {
880 switch (p1) {
881 case OMX_CommandStateSet:
882 pThis->m_state = (OMX_STATETYPE) p2;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700883 DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d",
Arun Menon906de572013-06-18 17:01:40 -0700884 pThis->m_state);
885 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
886 OMX_EventCmdComplete, p1, p2, NULL);
887 break;
888
889 case OMX_EventError:
890 if (p2 == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700891 DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid");
Arun Menon906de572013-06-18 17:01:40 -0700892 pThis->m_state = (OMX_STATETYPE) p2;
893 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
894 OMX_EventError, OMX_ErrorInvalidState, p2, NULL);
895 } else if (p2 == OMX_ErrorHardware) {
896 pThis->omx_report_error();
897 } else {
898 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
899 OMX_EventError, p2, (OMX_U32)NULL, NULL );
900 }
901 break;
902
903 case OMX_CommandPortDisable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700904 DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700905 if (BITMASK_PRESENT(&pThis->m_flags,
906 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
907 BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
908 break;
909 }
910 if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) {
911 OMX_ERRORTYPE eRet = OMX_ErrorNone;
912 pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
913 if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT))
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700914 DEBUG_PRINT_HIGH("Failed to release output buffers");
Arun Menon906de572013-06-18 17:01:40 -0700915 OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf);
916 pThis->in_reconfig = false;
917 if (eRet != OMX_ErrorNone) {
918 DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet);
919 pThis->omx_report_error();
920 break;
921 }
922 }
923 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
924 OMX_EventCmdComplete, p1, p2, NULL );
925 break;
926 case OMX_CommandPortEnable:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700927 DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2);
Arun Menon906de572013-06-18 17:01:40 -0700928 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\
929 OMX_EventCmdComplete, p1, p2, NULL );
930 break;
931
932 default:
933 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
934 OMX_EventCmdComplete, p1, p2, NULL );
935 break;
936
937 }
938 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700939 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
Arun Menon906de572013-06-18 17:01:40 -0700940 }
941 break;
942 case OMX_COMPONENT_GENERATE_ETB_ARBITRARY:
943 if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\
944 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700945 DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure");
Arun Menon906de572013-06-18 17:01:40 -0700946 pThis->omx_report_error ();
947 }
948 break;
Jia Meng1e236c82014-04-03 10:54:39 +0800949 case OMX_COMPONENT_GENERATE_ETB: {
950 OMX_ERRORTYPE iret;
951 iret = pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1, (OMX_BUFFERHEADERTYPE *)p2);
952 if (iret == OMX_ErrorInsufficientResources) {
953 DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure due to HW overload");
954 pThis->omx_report_hw_overload ();
955 } else if (iret != OMX_ErrorNone) {
956 DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure");
957 pThis->omx_report_error ();
958 }
Arun Menon906de572013-06-18 17:01:40 -0700959 }
960 break;
961
962 case OMX_COMPONENT_GENERATE_FTB:
963 if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\
964 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700965 DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure");
Arun Menon906de572013-06-18 17:01:40 -0700966 pThis->omx_report_error ();
967 }
968 break;
969
970 case OMX_COMPONENT_GENERATE_COMMAND:
971 pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\
972 (OMX_U32)p2,(OMX_PTR)NULL);
973 break;
974
975 case OMX_COMPONENT_GENERATE_EBD:
976
977 if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700978 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure");
Arun Menon906de572013-06-18 17:01:40 -0700979 pThis->omx_report_error ();
980 } else {
981 if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) {
Arun Menon906de572013-06-18 17:01:40 -0700982 pThis->time_stamp_dts.remove_time_stamp(
983 ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp,
984 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
985 ?true:false);
Arun Menon906de572013-06-18 17:01:40 -0700986 }
Deva Ramasubramanian02b0d882014-04-03 14:58:50 -0700987
Arun Menon906de572013-06-18 17:01:40 -0700988 if ( pThis->empty_buffer_done(&pThis->m_cmp,
989 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -0700990 DEBUG_PRINT_ERROR("empty_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -0700991 pThis->omx_report_error ();
992 }
Arun Menon906de572013-06-18 17:01:40 -0700993 }
994 break;
995 case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: {
996 int64_t *timestamp = (int64_t *)p1;
997 if (p1) {
998 pThis->time_stamp_dts.remove_time_stamp(*timestamp,
999 (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
1000 ?true:false);
1001 free(timestamp);
1002 }
1003 }
1004 break;
1005 case OMX_COMPONENT_GENERATE_FBD:
1006 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001007 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure");
Arun Menon906de572013-06-18 17:01:40 -07001008 pThis->omx_report_error ();
1009 } else if ( pThis->fill_buffer_done(&pThis->m_cmp,
1010 (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001011 DEBUG_PRINT_ERROR("fill_buffer_done failure");
Arun Menon906de572013-06-18 17:01:40 -07001012 pThis->omx_report_error ();
1013 }
1014 break;
1015
1016 case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001017 DEBUG_PRINT_HIGH("Driver flush i/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -07001018 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001019 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -07001020 } else {
1021 pThis->execute_input_flush();
1022 if (pThis->m_cb.EventHandler) {
1023 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001024 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure");
Arun Menon906de572013-06-18 17:01:40 -07001025 pThis->omx_report_error ();
1026 } else {
1027 /*Check if we need generate event for Flush done*/
1028 if (BITMASK_PRESENT(&pThis->m_flags,
1029 OMX_COMPONENT_INPUT_FLUSH_PENDING)) {
1030 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001031 DEBUG_PRINT_LOW("Input Flush completed - Notify Client");
Arun Menon906de572013-06-18 17:01:40 -07001032 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1033 OMX_EventCmdComplete,OMX_CommandFlush,
1034 OMX_CORE_INPUT_PORT_INDEX,NULL );
1035 }
1036 if (BITMASK_PRESENT(&pThis->m_flags,
1037 OMX_COMPONENT_IDLE_PENDING)) {
1038 if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001039 DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port");
Arun Menon906de572013-06-18 17:01:40 -07001040 pThis->omx_report_error ();
1041 } else {
1042 pThis->streaming[OUTPUT_PORT] = false;
1043 }
1044 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001045 DEBUG_PRINT_LOW("Input flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001046 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1047 OMX_COMPONENT_GENERATE_STOP_DONE);
1048 }
1049 }
1050 }
1051 } else {
1052 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1053 }
1054 }
1055 break;
1056
1057 case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001058 DEBUG_PRINT_HIGH("Driver flush o/p Port complete");
Arun Menon906de572013-06-18 17:01:40 -07001059 if (!pThis->output_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001060 DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver");
Arun Menon906de572013-06-18 17:01:40 -07001061 } else {
1062 pThis->execute_output_flush();
1063 if (pThis->m_cb.EventHandler) {
1064 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001065 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed");
Arun Menon906de572013-06-18 17:01:40 -07001066 pThis->omx_report_error ();
1067 } else {
1068 /*Check if we need generate event for Flush done*/
1069 if (BITMASK_PRESENT(&pThis->m_flags,
1070 OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001071 DEBUG_PRINT_LOW("Notify Output Flush done");
Arun Menon906de572013-06-18 17:01:40 -07001072 BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
1073 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1074 OMX_EventCmdComplete,OMX_CommandFlush,
1075 OMX_CORE_OUTPUT_PORT_INDEX,NULL );
1076 }
1077 if (BITMASK_PRESENT(&pThis->m_flags,
1078 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001079 DEBUG_PRINT_LOW("Internal flush complete");
Arun Menon906de572013-06-18 17:01:40 -07001080 BITMASK_CLEAR (&pThis->m_flags,
1081 OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
1082 if (BITMASK_PRESENT(&pThis->m_flags,
1083 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) {
1084 pThis->post_event(OMX_CommandPortDisable,
1085 OMX_CORE_OUTPUT_PORT_INDEX,
1086 OMX_COMPONENT_GENERATE_EVENT);
1087 BITMASK_CLEAR (&pThis->m_flags,
1088 OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED);
Praneeth Paladugub52072a2013-08-23 13:54:43 -07001089 BITMASK_CLEAR (&pThis->m_flags,
1090 OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
Arun Menon906de572013-06-18 17:01:40 -07001091
1092 }
1093 }
1094
1095 if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) {
1096 if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001097 DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port");
Arun Menon906de572013-06-18 17:01:40 -07001098 pThis->omx_report_error ();
1099 break;
1100 }
1101 pThis->streaming[CAPTURE_PORT] = false;
1102 if (!pThis->input_flush_progress) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001103 DEBUG_PRINT_LOW("Output flush done hence issue stop");
Arun Menon906de572013-06-18 17:01:40 -07001104 pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\
1105 OMX_COMPONENT_GENERATE_STOP_DONE);
1106 }
1107 }
1108 }
1109 } else {
1110 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1111 }
1112 }
1113 break;
1114
1115 case OMX_COMPONENT_GENERATE_START_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001116 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001117
1118 if (pThis->m_cb.EventHandler) {
1119 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001120 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure");
Arun Menon906de572013-06-18 17:01:40 -07001121 pThis->omx_report_error ();
1122 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001123 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001124 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001125 DEBUG_PRINT_LOW("Move to executing");
Arun Menon906de572013-06-18 17:01:40 -07001126 // Send the callback now
1127 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1128 pThis->m_state = OMX_StateExecuting;
1129 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1130 OMX_EventCmdComplete,OMX_CommandStateSet,
1131 OMX_StateExecuting, NULL);
1132 } else if (BITMASK_PRESENT(&pThis->m_flags,
1133 OMX_COMPONENT_PAUSE_PENDING)) {
1134 if (/*ioctl (pThis->drv_ctx.video_driver_fd,
1135 VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001136 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed");
Arun Menon906de572013-06-18 17:01:40 -07001137 pThis->omx_report_error ();
1138 }
1139 }
1140 }
1141 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001142 DEBUG_PRINT_LOW("Event Handler callback is NULL");
Arun Menon906de572013-06-18 17:01:40 -07001143 }
1144 break;
1145
1146 case OMX_COMPONENT_GENERATE_PAUSE_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001147 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001148 if (pThis->m_cb.EventHandler) {
1149 if (p2 != VDEC_S_SUCCESS) {
1150 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed");
1151 pThis->omx_report_error ();
1152 } else {
1153 pThis->complete_pending_buffer_done_cbs();
1154 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001155 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity");
Arun Menon906de572013-06-18 17:01:40 -07001156 //Send the callback now
1157 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING);
1158 pThis->m_state = OMX_StatePause;
1159 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1160 OMX_EventCmdComplete,OMX_CommandStateSet,
1161 OMX_StatePause, NULL);
1162 }
1163 }
1164 } else {
1165 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1166 }
1167
1168 break;
1169
1170 case OMX_COMPONENT_GENERATE_RESUME_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001171 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001172 if (pThis->m_cb.EventHandler) {
1173 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001174 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed");
Arun Menon906de572013-06-18 17:01:40 -07001175 pThis->omx_report_error ();
1176 } else {
1177 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001178 DEBUG_PRINT_LOW("Moving the decoder to execute state");
Arun Menon906de572013-06-18 17:01:40 -07001179 // Send the callback now
1180 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
1181 pThis->m_state = OMX_StateExecuting;
1182 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1183 OMX_EventCmdComplete,OMX_CommandStateSet,
1184 OMX_StateExecuting,NULL);
1185 }
1186 }
1187 } else {
1188 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1189 }
1190
1191 break;
1192
1193 case OMX_COMPONENT_GENERATE_STOP_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001194 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001195 if (pThis->m_cb.EventHandler) {
1196 if (p2 != VDEC_S_SUCCESS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001197 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed");
Arun Menon906de572013-06-18 17:01:40 -07001198 pThis->omx_report_error ();
1199 } else {
1200 pThis->complete_pending_buffer_done_cbs();
1201 if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001202 DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success");
Arun Menon906de572013-06-18 17:01:40 -07001203 // Send the callback now
1204 BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING);
1205 pThis->m_state = OMX_StateIdle;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001206 DEBUG_PRINT_LOW("Move to Idle State");
Arun Menon906de572013-06-18 17:01:40 -07001207 pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data,
1208 OMX_EventCmdComplete,OMX_CommandStateSet,
1209 OMX_StateIdle,NULL);
1210 }
1211 }
1212 } else {
1213 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1214 }
1215
1216 break;
1217
1218 case OMX_COMPONENT_GENERATE_PORT_RECONFIG:
Arun Menon906de572013-06-18 17:01:40 -07001219 if (p2 == OMX_IndexParamPortDefinition) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301220 DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexParamPortDefinition");
Arun Menon906de572013-06-18 17:01:40 -07001221 pThis->in_reconfig = true;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301222
1223 } else if (p2 == OMX_IndexConfigCommonOutputCrop) {
1224 DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexConfigCommonOutputCrop");
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301225
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301226 /* Check if resolution is changed in smooth streaming mode */
1227 if (pThis->m_smoothstreaming_mode &&
1228 (pThis->framesize.nWidth !=
1229 pThis->drv_ctx.video_resolution.frame_width) ||
1230 (pThis->framesize.nHeight !=
1231 pThis->drv_ctx.video_resolution.frame_height)) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301232
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301233 DEBUG_PRINT_HIGH("Resolution changed from: wxh = %dx%d to: wxh = %dx%d",
1234 pThis->framesize.nWidth,
1235 pThis->framesize.nHeight,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301236 pThis->drv_ctx.video_resolution.frame_width,
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301237 pThis->drv_ctx.video_resolution.frame_height);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301238
1239 /* Update new resolution */
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301240 pThis->framesize.nWidth =
1241 pThis->drv_ctx.video_resolution.frame_width;
1242 pThis->framesize.nHeight =
1243 pThis->drv_ctx.video_resolution.frame_height;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05301244
1245 /* Update C2D with new resolution */
1246 if (!pThis->client_buffers.update_buffer_req()) {
1247 DEBUG_PRINT_ERROR("Setting C2D buffer requirements failed");
1248 }
1249 }
1250
1251 /* Update new crop information */
1252 pThis->rectangle.nLeft = pThis->drv_ctx.frame_size.left;
1253 pThis->rectangle.nTop = pThis->drv_ctx.frame_size.top;
1254 pThis->rectangle.nWidth = pThis->drv_ctx.frame_size.right;
1255 pThis->rectangle.nHeight = pThis->drv_ctx.frame_size.bottom;
1256
1257 /* Validate the new crop information */
1258 if (pThis->rectangle.nLeft + pThis->rectangle.nWidth >
1259 pThis->drv_ctx.video_resolution.frame_width) {
1260
1261 DEBUG_PRINT_HIGH("Crop L[%u] + R[%u] > W[%u]",
1262 pThis->rectangle.nLeft, pThis->rectangle.nWidth,
1263 pThis->drv_ctx.video_resolution.frame_width);
1264 pThis->rectangle.nLeft = 0;
1265
1266 if (pThis->rectangle.nWidth >
1267 pThis->drv_ctx.video_resolution.frame_width) {
1268
1269 DEBUG_PRINT_HIGH("Crop R[%u] > W[%u]",
1270 pThis->rectangle.nWidth,
1271 pThis->drv_ctx.video_resolution.frame_width);
1272 pThis->rectangle.nWidth =
1273 pThis->drv_ctx.video_resolution.frame_width;
1274 }
1275 }
1276 if (pThis->rectangle.nTop + pThis->rectangle.nHeight >
1277 pThis->drv_ctx.video_resolution.frame_height) {
1278
1279 DEBUG_PRINT_HIGH("Crop T[%u] + B[%u] > H[%u]",
1280 pThis->rectangle.nTop, pThis->rectangle.nHeight,
1281 pThis->drv_ctx.video_resolution.frame_height);
1282 pThis->rectangle.nTop = 0;
1283
1284 if (pThis->rectangle.nHeight >
1285 pThis->drv_ctx.video_resolution.frame_height) {
1286
1287 DEBUG_PRINT_HIGH("Crop B[%u] > H[%u]",
1288 pThis->rectangle.nHeight,
1289 pThis->drv_ctx.video_resolution.frame_height);
1290 pThis->rectangle.nHeight =
1291 pThis->drv_ctx.video_resolution.frame_height;
1292 }
1293 }
1294 DEBUG_PRINT_HIGH("Updated Crop Info: L: %u, T: %u, R: %u, B: %u",
1295 pThis->rectangle.nLeft, pThis->rectangle.nTop,
1296 pThis->rectangle.nWidth, pThis->rectangle.nHeight);
1297 } else {
1298 DEBUG_PRINT_ERROR("Rxd Invalid PORT_RECONFIG event (%lu)", p2);
1299 break;
Arun Menon906de572013-06-18 17:01:40 -07001300 }
1301 if (pThis->m_cb.EventHandler) {
1302 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
1303 OMX_EventPortSettingsChanged, p1, p2, NULL );
1304 } else {
1305 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1306 }
Arun Menon906de572013-06-18 17:01:40 -07001307 break;
1308
1309 case OMX_COMPONENT_GENERATE_EOS_DONE:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001310 DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE");
Arun Menon906de572013-06-18 17:01:40 -07001311 if (pThis->m_cb.EventHandler) {
1312 pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag,
1313 OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL );
1314 } else {
1315 DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
1316 }
1317 pThis->prev_ts = LLONG_MAX;
1318 pThis->rst_prev_ts = true;
1319 break;
1320
1321 case OMX_COMPONENT_GENERATE_HARDWARE_ERROR:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001322 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR");
Arun Menon906de572013-06-18 17:01:40 -07001323 pThis->omx_report_error ();
1324 break;
1325
1326 case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001327 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING");
Arun Menon906de572013-06-18 17:01:40 -07001328 pThis->omx_report_unsupported_setting();
1329 break;
1330
Deepak Verma24720fb2014-01-29 16:57:40 +05301331 case OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD:
1332 DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD");
1333 pThis->omx_report_hw_overload();
1334 break;
1335
Arun Menon906de572013-06-18 17:01:40 -07001336 default:
1337 break;
1338 }
1339 }
1340 pthread_mutex_lock(&pThis->m_lock);
1341 qsize = pThis->m_cmd_q.m_size;
1342 if (pThis->m_state != OMX_StatePause)
1343 qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size);
1344 pthread_mutex_unlock(&pThis->m_lock);
1345 } while (qsize>0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001346
1347}
1348
Vinay Kaliab9e98102013-04-02 19:31:43 -07001349int omx_vdec::update_resolution(int width, int height, int stride, int scan_lines)
Vinay Kalia592e4b42012-12-19 15:55:47 -08001350{
Arun Menon906de572013-06-18 17:01:40 -07001351 int format_changed = 0;
Surajit Podderd2644d52013-08-28 17:59:06 +05301352 if ((height != (int)drv_ctx.video_resolution.frame_height) ||
1353 (width != (int)drv_ctx.video_resolution.frame_width)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001354 DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)",
Arun Menon906de572013-06-18 17:01:40 -07001355 width, drv_ctx.video_resolution.frame_width,
1356 height,drv_ctx.video_resolution.frame_height);
1357 format_changed = 1;
1358 }
Vinay Kalia592e4b42012-12-19 15:55:47 -08001359 drv_ctx.video_resolution.frame_height = height;
1360 drv_ctx.video_resolution.frame_width = width;
Vinay Kalia21649b32013-03-18 17:28:07 -07001361 drv_ctx.video_resolution.scan_lines = scan_lines;
1362 drv_ctx.video_resolution.stride = stride;
Pushkaraj Patil41588352014-02-25 20:51:34 +05301363 if(!is_down_scalar_enabled) {
1364 rectangle.nLeft = 0;
1365 rectangle.nTop = 0;
1366 rectangle.nWidth = drv_ctx.video_resolution.frame_width;
1367 rectangle.nHeight = drv_ctx.video_resolution.frame_height;
1368 }
Arun Menon906de572013-06-18 17:01:40 -07001369 return format_changed;
Vinay Kalia592e4b42012-12-19 15:55:47 -08001370}
1371
Arun Menon6836ba02013-02-19 20:37:40 -08001372OMX_ERRORTYPE omx_vdec::is_video_session_supported()
1373{
Arun Menon906de572013-06-18 17:01:40 -07001374 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",
1375 OMX_MAX_STRINGNAME_SIZE) &&
1376 (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) {
1377 m_decoder_capability.max_width = 1280;
1378 m_decoder_capability.max_height = 720;
1379 DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP");
1380 }
Arun Menon888aa852013-05-30 11:24:42 -07001381
Arun Menon906de572013-06-18 17:01:40 -07001382 if ((drv_ctx.video_resolution.frame_width *
1383 drv_ctx.video_resolution.frame_height >
1384 m_decoder_capability.max_width *
1385 m_decoder_capability.max_height) ||
1386 (drv_ctx.video_resolution.frame_width*
1387 drv_ctx.video_resolution.frame_height <
1388 m_decoder_capability.min_width *
1389 m_decoder_capability.min_height)) {
1390 DEBUG_PRINT_ERROR(
1391 "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)",
1392 drv_ctx.video_resolution.frame_width,
1393 drv_ctx.video_resolution.frame_height,
1394 m_decoder_capability.min_width,
1395 m_decoder_capability.min_height,
1396 m_decoder_capability.max_width,
1397 m_decoder_capability.max_height);
1398 return OMX_ErrorUnsupportedSetting;
1399 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001400 DEBUG_PRINT_HIGH("video session supported");
Arun Menon906de572013-06-18 17:01:40 -07001401 return OMX_ErrorNone;
Arun Menon6836ba02013-02-19 20:37:40 -08001402}
1403
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001404int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len)
1405{
1406 if (m_debug.in_buffer_log && !m_debug.infile) {
1407 if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) {
1408 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v",
1409 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1410 }
1411 else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) {
1412 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); }
1413 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) {
1414 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263",
1415 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1416 }
1417 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) {
1418 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264",
1419 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1420 }
1421 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) {
1422 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1423 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1424 }
1425 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) {
1426 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1",
1427 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1428 }
1429 else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1430 sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf",
1431 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1432 }
1433 m_debug.infile = fopen (m_debug.infile_name, "ab");
1434 if (!m_debug.infile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001435 DEBUG_PRINT_HIGH("Failed to open input file: %s for logging", m_debug.infile_name);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001436 m_debug.infile_name[0] = '\0';
1437 return -1;
1438 }
1439 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1440 struct ivf_file_header {
1441 OMX_U8 signature[4]; //='DKIF';
1442 OMX_U8 version ; //= 0;
1443 OMX_U8 headersize ; //= 32;
1444 OMX_U32 FourCC;
1445 OMX_U8 width;
1446 OMX_U8 height;
1447 OMX_U32 rate;
1448 OMX_U32 scale;
1449 OMX_U32 length;
1450 OMX_U8 unused[4];
1451 } file_header;
1452
1453 memset((void *)&file_header,0,sizeof(file_header));
1454 file_header.signature[0] = 'D';
1455 file_header.signature[1] = 'K';
1456 file_header.signature[2] = 'I';
1457 file_header.signature[3] = 'F';
1458 file_header.version = 0;
1459 file_header.headersize = 32;
1460 file_header.FourCC = 0x30385056;
1461 fwrite((const char *)&file_header,
1462 sizeof(file_header),1,m_debug.infile);
1463 }
1464 }
1465 if (m_debug.infile && buffer_addr && buffer_len) {
1466 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) {
1467 struct vp8_ivf_frame_header {
1468 OMX_U32 framesize;
1469 OMX_U32 timestamp_lo;
1470 OMX_U32 timestamp_hi;
1471 } vp8_frame_header;
1472 vp8_frame_header.framesize = buffer_len;
1473 /* Currently FW doesn't use timestamp values */
1474 vp8_frame_header.timestamp_lo = 0;
1475 vp8_frame_header.timestamp_hi = 0;
1476 fwrite((const char *)&vp8_frame_header,
1477 sizeof(vp8_frame_header),1,m_debug.infile);
1478 }
1479 fwrite(buffer_addr, buffer_len, 1, m_debug.infile);
1480 }
1481 return 0;
1482}
1483
1484int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) {
1485 if (m_debug.out_buffer_log && !m_debug.outfile) {
1486 sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv",
1487 m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this);
1488 m_debug.outfile = fopen (m_debug.outfile_name, "ab");
1489 if (!m_debug.outfile) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001490 DEBUG_PRINT_HIGH("Failed to open output file: %s for logging", m_debug.log_loc);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001491 m_debug.outfile_name[0] = '\0';
1492 return -1;
1493 }
1494 }
1495 if (m_debug.outfile && buffer && buffer->nFilledLen) {
1496 int buf_index = buffer - m_out_mem_ptr;
1497 int stride = drv_ctx.video_resolution.stride;
1498 int scanlines = drv_ctx.video_resolution.scan_lines;
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301499 if (m_smoothstreaming_mode) {
1500 stride = drv_ctx.video_resolution.frame_width;
1501 scanlines = drv_ctx.video_resolution.frame_height;
1502 stride = (stride + DEFAULT_WIDTH_ALIGNMENT - 1) & (~(DEFAULT_WIDTH_ALIGNMENT - 1));
1503 scanlines = (scanlines + DEFAULT_HEIGHT_ALIGNMENT - 1) & (~(DEFAULT_HEIGHT_ALIGNMENT - 1));
1504 }
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001505 char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr;
1506 unsigned i;
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301507 DEBUG_PRINT_HIGH("Logging width/height(%u/%u) stride/scanlines(%u/%u)",
1508 drv_ctx.video_resolution.frame_width,
1509 drv_ctx.video_resolution.frame_height, stride, scanlines);
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07001510 int bytes_written = 0;
1511 for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) {
1512 bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1513 temp += stride;
1514 }
1515 temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines;
1516 int stride_c = stride;
1517 for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) {
1518 bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile);
1519 temp += stride_c;
1520 }
1521 }
1522 return 0;
1523}
1524
Shalaj Jain273b3e02012-06-22 19:08:03 -07001525/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001526 FUNCTION
1527 omx_vdec::ComponentInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07001528
Arun Menon906de572013-06-18 17:01:40 -07001529 DESCRIPTION
1530 Initialize the component.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001531
Arun Menon906de572013-06-18 17:01:40 -07001532 PARAMETERS
1533 ctxt -- Context information related to the self.
1534 id -- Event identifier. This could be any of the following:
1535 1. Command completion event
1536 2. Buffer done callback event
1537 3. Frame done callback event
Shalaj Jain273b3e02012-06-22 19:08:03 -07001538
Arun Menon906de572013-06-18 17:01:40 -07001539 RETURN VALUE
1540 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001541
Arun Menon906de572013-06-18 17:01:40 -07001542 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001543OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role)
1544{
1545
Arun Menon906de572013-06-18 17:01:40 -07001546 OMX_ERRORTYPE eRet = OMX_ErrorNone;
1547 struct v4l2_fmtdesc fdesc;
1548 struct v4l2_format fmt;
1549 struct v4l2_requestbuffers bufreq;
1550 struct v4l2_control control;
1551 struct v4l2_frmsizeenum frmsize;
1552 unsigned int alignment = 0,buffer_size = 0;
1553 int fds[2];
1554 int r,ret=0;
1555 bool codec_ambiguous = false;
Praveen Chavan00ec0ce2015-05-18 09:44:20 -07001556 OMX_STRING device_name = (OMX_STRING)"/dev/video32";
Jia Meng3a3c6492013-12-19 17:16:52 +08001557 char property_value[PROPERTY_VALUE_MAX] = {0};
Sachin Shahc82a18f2013-03-29 14:45:38 -07001558
1559#ifdef _ANDROID_
Praveen Chavane9e56202013-09-19 03:48:16 -07001560 char platform_name[PROPERTY_VALUE_MAX];
Arun Menon906de572013-06-18 17:01:40 -07001561 property_get("ro.board.platform", platform_name, "0");
1562 if (!strncmp(platform_name, "msm8610", 7)) {
Balamurugan Alagarsamy1693e592015-07-23 19:19:05 +05301563 device_name = (OMX_STRING)"/dev/video34";
Deepak Vermaa2efdb12013-12-26 12:30:05 +05301564 is_q6_platform = true;
1565 maxSmoothStreamingWidth = 1280;
1566 maxSmoothStreamingHeight = 720;
Arun Menon906de572013-06-18 17:01:40 -07001567 }
Sachin Shahc82a18f2013-03-29 14:45:38 -07001568#endif
1569
Arun Menon906de572013-06-18 17:01:40 -07001570 if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) {
1571 struct v4l2_control control;
1572 secure_mode = true;
1573 arbitrary_bytes = false;
1574 role = (OMX_STRING)"OMX.qcom.video.decoder.avc";
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05301575 } else if (!strncmp(role, "OMX.qcom.video.decoder.mpeg2.secure",
1576 OMX_MAX_STRINGNAME_SIZE)){
1577 secure_mode = true;
1578 arbitrary_bytes = false;
1579 role = (OMX_STRING)"OMX.qcom.video.decoder.mpeg2";
Arun Menon906de572013-06-18 17:01:40 -07001580 }
Vinay Kalia53fa6832012-10-11 17:55:30 -07001581
Arun Menon906de572013-06-18 17:01:40 -07001582 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001583
Balamurugan Alagarsamy1693e592015-07-23 19:19:05 +05301584 DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open device %s returned fd %d",
1585 device_name, drv_ctx.video_driver_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001586
Arun Menon906de572013-06-18 17:01:40 -07001587 if (drv_ctx.video_driver_fd == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001588 DEBUG_PRINT_ERROR("omx_vdec_msm8974 :: Got fd as 0 for msm_vidc_dec, Opening again");
Arun Menon906de572013-06-18 17:01:40 -07001589 drv_ctx.video_driver_fd = open(device_name, O_RDWR);
1590 close(0);
1591 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001592
Arun Menon906de572013-06-18 17:01:40 -07001593 if (drv_ctx.video_driver_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001594 DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno);
Arun Menon906de572013-06-18 17:01:40 -07001595 return OMX_ErrorInsufficientResources;
1596 }
1597 drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS;
1598 drv_ctx.frame_rate.fps_denominator = 1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001599
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001600 ret = subscribe_to_events(drv_ctx.video_driver_fd);
Vinay Kalia184cd0f2013-04-29 18:26:42 -07001601 if (!ret) {
Arun Menon906de572013-06-18 17:01:40 -07001602 async_thread_created = true;
1603 ret = pthread_create(&async_thread_id,0,async_message_thread,this);
1604 }
1605 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001606 DEBUG_PRINT_ERROR("Failed to create async_message_thread");
Arun Menon906de572013-06-18 17:01:40 -07001607 async_thread_created = false;
1608 return OMX_ErrorInsufficientResources;
Vinay Kaliadae8ad62013-04-26 20:42:10 -07001609 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001610
Shalaj Jain273b3e02012-06-22 19:08:03 -07001611#ifdef OUTPUT_EXTRADATA_LOG
Deva Ramasubramanianee6f1f42014-01-31 12:49:18 -08001612 outputExtradataFile = fopen (output_extradata_filename, "ab");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001613#endif
1614
Arun Menon906de572013-06-18 17:01:40 -07001615 // Copy the role information which provides the decoder kind
1616 strlcpy(drv_ctx.kind,role,128);
Vinay Kalia53fa6832012-10-11 17:55:30 -07001617
Arun Menon906de572013-06-18 17:01:40 -07001618 if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\
1619 OMX_MAX_STRINGNAME_SIZE)) {
1620 strlcpy((char *)m_cRole, "video_decoder.mpeg4",\
1621 OMX_MAX_STRINGNAME_SIZE);
1622 drv_ctx.timestamp_adjust = true;
1623 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4;
1624 eCompressionFormat = OMX_VIDEO_CodingMPEG4;
1625 output_capability=V4L2_PIX_FMT_MPEG4;
1626 /*Initialize Start Code for MPEG4*/
1627 codec_type_parse = CODEC_TYPE_MPEG4;
1628 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001629 } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\
1630 OMX_MAX_STRINGNAME_SIZE)) {
1631 strlcpy((char *)m_cRole, "video_decoder.mpeg2",\
1632 OMX_MAX_STRINGNAME_SIZE);
1633 drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2;
1634 output_capability = V4L2_PIX_FMT_MPEG2;
1635 eCompressionFormat = OMX_VIDEO_CodingMPEG2;
1636 /*Initialize Start Code for MPEG2*/
1637 codec_type_parse = CODEC_TYPE_MPEG2;
1638 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001639 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\
1640 OMX_MAX_STRINGNAME_SIZE)) {
1641 strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001642 DEBUG_PRINT_LOW("H263 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001643 drv_ctx.decoder_format = VDEC_CODECTYPE_H263;
1644 eCompressionFormat = OMX_VIDEO_CodingH263;
1645 output_capability = V4L2_PIX_FMT_H263;
1646 codec_type_parse = CODEC_TYPE_H263;
1647 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001648 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\
1649 OMX_MAX_STRINGNAME_SIZE)) {
1650 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001651 DEBUG_PRINT_LOW ("DIVX 311 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001652 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3;
1653 output_capability = V4L2_PIX_FMT_DIVX_311;
1654 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1655 codec_type_parse = CODEC_TYPE_DIVX;
1656 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001657
Arun Menon906de572013-06-18 17:01:40 -07001658 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\
1659 OMX_MAX_STRINGNAME_SIZE)) {
1660 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001661 DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001662 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4;
1663 output_capability = V4L2_PIX_FMT_DIVX;
1664 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1665 codec_type_parse = CODEC_TYPE_DIVX;
1666 codec_ambiguous = true;
1667 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001668
Arun Menon906de572013-06-18 17:01:40 -07001669 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\
1670 OMX_MAX_STRINGNAME_SIZE)) {
1671 strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001672 DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected");
Arun Menon906de572013-06-18 17:01:40 -07001673 drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6;
1674 output_capability = V4L2_PIX_FMT_DIVX;
1675 eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx;
1676 codec_type_parse = CODEC_TYPE_DIVX;
1677 codec_ambiguous = true;
1678 m_frame_parser.init_start_codes (codec_type_parse);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001679
Arun Menon906de572013-06-18 17:01:40 -07001680 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\
1681 OMX_MAX_STRINGNAME_SIZE)) {
1682 strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
1683 drv_ctx.decoder_format = VDEC_CODECTYPE_H264;
1684 output_capability=V4L2_PIX_FMT_H264;
1685 eCompressionFormat = OMX_VIDEO_CodingAVC;
1686 codec_type_parse = CODEC_TYPE_H264;
1687 m_frame_parser.init_start_codes (codec_type_parse);
1688 m_frame_parser.init_nal_length(nal_length);
Arun Menon906de572013-06-18 17:01:40 -07001689 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\
1690 OMX_MAX_STRINGNAME_SIZE)) {
1691 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1692 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1;
1693 eCompressionFormat = OMX_VIDEO_CodingWMV;
1694 codec_type_parse = CODEC_TYPE_VC1;
1695 output_capability = V4L2_PIX_FMT_VC1_ANNEX_G;
1696 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001697 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\
1698 OMX_MAX_STRINGNAME_SIZE)) {
1699 strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
1700 drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV;
1701 eCompressionFormat = OMX_VIDEO_CodingWMV;
1702 codec_type_parse = CODEC_TYPE_VC1;
1703 output_capability = V4L2_PIX_FMT_VC1_ANNEX_L;
1704 m_frame_parser.init_start_codes (codec_type_parse);
Arun Menon906de572013-06-18 17:01:40 -07001705 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \
1706 OMX_MAX_STRINGNAME_SIZE)) {
1707 strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
1708 output_capability=V4L2_PIX_FMT_VP8;
Praveen Chavan76b71c32014-07-10 18:10:51 -07001709 eCompressionFormat = OMX_VIDEO_CodingVP8;
Arun Menon906de572013-06-18 17:01:40 -07001710 codec_type_parse = CODEC_TYPE_VP8;
1711 arbitrary_bytes = false;
Praneeth Paladugu2b2ef2d2013-04-10 22:04:51 -07001712
Arun Menon906de572013-06-18 17:01:40 -07001713 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001714 DEBUG_PRINT_ERROR("ERROR:Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07001715 eRet = OMX_ErrorInvalidComponentName;
1716 }
Arun Menon906de572013-06-18 17:01:40 -07001717 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001718
Arun Menon906de572013-06-18 17:01:40 -07001719 drv_ctx.output_format = VDEC_YUV_FORMAT_NV12;
Vinay Kaliada4f4422013-01-09 10:45:03 -08001720 OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE)
1721 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
1722 if (!client_buffers.set_color_format(dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001723 DEBUG_PRINT_ERROR("Setting color format failed");
Vinay Kaliada4f4422013-01-09 10:45:03 -08001724 eRet = OMX_ErrorInsufficientResources;
1725 }
1726
Arun Menon906de572013-06-18 17:01:40 -07001727 capture_capability= V4L2_PIX_FMT_NV12;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001728
Arun Menon906de572013-06-18 17:01:40 -07001729 struct v4l2_capability cap;
1730 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap);
1731 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001732 DEBUG_PRINT_ERROR("Failed to query capabilities");
Arun Menon906de572013-06-18 17:01:40 -07001733 /*TODO: How to handle this case */
1734 } else {
1735 DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s,"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001736 " version = %d, capabilities = %x", cap.driver, cap.card,
Arun Menon906de572013-06-18 17:01:40 -07001737 cap.bus_info, cap.version, cap.capabilities);
1738 }
1739 ret=0;
1740 fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1741 fdesc.index=0;
1742 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001743 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001744 fdesc.pixelformat, fdesc.flags);
1745 fdesc.index++;
1746 }
1747 fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1748 fdesc.index=0;
1749 while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07001750
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001751 DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description,
Arun Menon906de572013-06-18 17:01:40 -07001752 fdesc.pixelformat, fdesc.flags);
1753 fdesc.index++;
1754 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001755 update_resolution(320, 240, 320, 240);
Arun Menon906de572013-06-18 17:01:40 -07001756 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1757 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1758 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1759 fmt.fmt.pix_mp.pixelformat = output_capability;
1760 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1761 if (ret) {
1762 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001763 DEBUG_PRINT_ERROR("Failed to set format on output port");
Arun Menon906de572013-06-18 17:01:40 -07001764 return OMX_ErrorInsufficientResources;
1765 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001766 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001767 if (codec_ambiguous) {
1768 if (output_capability == V4L2_PIX_FMT_DIVX) {
1769 struct v4l2_control divx_ctrl;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001770
Arun Menon906de572013-06-18 17:01:40 -07001771 if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) {
1772 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4;
1773 } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) {
1774 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5;
1775 } else {
1776 divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6;
1777 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001778
Arun Menon906de572013-06-18 17:01:40 -07001779 divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT;
1780 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl);
1781 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001782 DEBUG_PRINT_ERROR("Failed to set divx version");
Arun Menon906de572013-06-18 17:01:40 -07001783 }
1784 } else {
1785 DEBUG_PRINT_ERROR("Codec should not be ambiguous");
1786 }
1787 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001788
Jia Meng3a3c6492013-12-19 17:16:52 +08001789 property_get("persist.vidc.dec.conceal_color", property_value, DEFAULT_CONCEAL_COLOR);
1790 m_conceal_color= atoi(property_value);
1791 DEBUG_PRINT_HIGH("trying to set 0x%x as conceal color\n",m_conceal_color);
1792 control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR;
1793 control.value = m_conceal_color;
1794 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
1795 if (ret) {
1796 DEBUG_PRINT_ERROR("Failed to set conceal color %d\n", ret);
1797 }
1798
Arun Menon906de572013-06-18 17:01:40 -07001799 //Get the hardware capabilities
1800 memset((void *)&frmsize,0,sizeof(frmsize));
1801 frmsize.index = 0;
1802 frmsize.pixel_format = output_capability;
1803 ret = ioctl(drv_ctx.video_driver_fd,
1804 VIDIOC_ENUM_FRAMESIZES, &frmsize);
1805 if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001806 DEBUG_PRINT_ERROR("Failed to get framesizes");
Arun Menon906de572013-06-18 17:01:40 -07001807 return OMX_ErrorHardware;
1808 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001809
Arun Menon906de572013-06-18 17:01:40 -07001810 if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1811 m_decoder_capability.min_width = frmsize.stepwise.min_width;
1812 m_decoder_capability.max_width = frmsize.stepwise.max_width;
1813 m_decoder_capability.min_height = frmsize.stepwise.min_height;
1814 m_decoder_capability.max_height = frmsize.stepwise.max_height;
1815 }
Deva Ramasubramanian3c55b212013-06-18 15:03:49 -07001816
Arun Menon906de572013-06-18 17:01:40 -07001817 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1818 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
1819 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
1820 fmt.fmt.pix_mp.pixelformat = capture_capability;
1821 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
1822 if (ret) {
1823 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001824 DEBUG_PRINT_ERROR("Failed to set format on capture port");
Arun Menon906de572013-06-18 17:01:40 -07001825 }
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05301826 memset(&framesize, 0, sizeof(OMX_FRAMESIZETYPE));
1827 framesize.nWidth = drv_ctx.video_resolution.frame_width;
1828 framesize.nHeight = drv_ctx.video_resolution.frame_height;
1829
1830 memset(&rectangle, 0, sizeof(OMX_CONFIG_RECTTYPE));
1831 rectangle.nWidth = drv_ctx.video_resolution.frame_width;
1832 rectangle.nHeight = drv_ctx.video_resolution.frame_height;
1833
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001834 DEBUG_PRINT_HIGH("Set Format was successful");
Arun Menon906de572013-06-18 17:01:40 -07001835 if (secure_mode) {
1836 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE;
1837 control.value = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001838 DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001839 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
1840 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001841 DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret);
Arun Menon906de572013-06-18 17:01:40 -07001842 return OMX_ErrorInsufficientResources;
1843 }
1844 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001845
Arun Menon906de572013-06-18 17:01:40 -07001846 /*Get the Buffer requirements for input and output ports*/
1847 drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT;
1848 drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
1849 if (secure_mode) {
1850 drv_ctx.op_buf.alignment=SZ_1M;
1851 drv_ctx.ip_buf.alignment=SZ_1M;
1852 } else {
1853 drv_ctx.op_buf.alignment=SZ_4K;
1854 drv_ctx.ip_buf.alignment=SZ_4K;
1855 }
1856 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
1857 drv_ctx.extradata = 0;
1858 drv_ctx.picture_order = VDEC_ORDER_DISPLAY;
1859 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
1860 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
1861 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
1862 drv_ctx.idr_only_decoding = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001863
Vinay Kalia5713bb32013-01-16 18:39:59 -08001864 m_state = OMX_StateLoaded;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001865#ifdef DEFAULT_EXTRADATA
Arun Menonf8908a62013-12-20 17:36:21 -08001866 if (strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",
1867 OMX_MAX_STRINGNAME_SIZE) && (eRet == OMX_ErrorNone))
1868 enable_extradata(DEFAULT_EXTRADATA, true, true);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001869#endif
Vinay Kalia5713bb32013-01-16 18:39:59 -08001870 eRet=get_buffer_req(&drv_ctx.ip_buf);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001871 DEBUG_PRINT_HIGH("Input Buffer Size =%d",drv_ctx.ip_buf.buffer_size);
Vinay Kalia5713bb32013-01-16 18:39:59 -08001872 get_buffer_req(&drv_ctx.op_buf);
Arun Menon906de572013-06-18 17:01:40 -07001873 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
1874 if (m_frame_parser.mutils == NULL) {
1875 m_frame_parser.mutils = new H264_Utils();
Shalaj Jain273b3e02012-06-22 19:08:03 -07001876
Arun Menon906de572013-06-18 17:01:40 -07001877 if (m_frame_parser.mutils == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001878 DEBUG_PRINT_ERROR("parser utils Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001879 eRet = OMX_ErrorInsufficientResources;
1880 } else {
1881 h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size;
1882 h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size);
1883 h264_scratch.nFilledLen = 0;
1884 h264_scratch.nOffset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001885
Arun Menon906de572013-06-18 17:01:40 -07001886 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001887 DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07001888 return OMX_ErrorInsufficientResources;
1889 }
1890 m_frame_parser.mutils->initialize_frame_checking_environment();
1891 m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size);
1892 }
1893 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001894
Arun Menon906de572013-06-18 17:01:40 -07001895 h264_parser = new h264_stream_parser();
1896 if (!h264_parser) {
1897 DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!");
1898 eRet = OMX_ErrorInsufficientResources;
1899 }
1900 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07001901
Arun Menon906de572013-06-18 17:01:40 -07001902 if (pipe(fds)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001903 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001904 eRet = OMX_ErrorInsufficientResources;
1905 } else {
1906 int temp1[2];
1907 if (fds[0] == 0 || fds[1] == 0) {
1908 if (pipe (temp1)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001909 DEBUG_PRINT_ERROR("pipe creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001910 return OMX_ErrorInsufficientResources;
1911 }
1912 //close (fds[0]);
1913 //close (fds[1]);
1914 fds[0] = temp1 [0];
1915 fds[1] = temp1 [1];
1916 }
1917 m_pipe_in = fds[0];
1918 m_pipe_out = fds[1];
1919 msg_thread_created = true;
Ashray Kulkarnia97efbc2015-07-15 18:17:23 -07001920 r = pthread_create(&msg_thread_id,0, dec_message_thread,this);
Shalaj Jain273b3e02012-06-22 19:08:03 -07001921
Arun Menon906de572013-06-18 17:01:40 -07001922 if (r < 0) {
Ashray Kulkarnia97efbc2015-07-15 18:17:23 -07001923 DEBUG_PRINT_ERROR("component_init(): dec_message_thread creation failed");
Arun Menon906de572013-06-18 17:01:40 -07001924 msg_thread_created = false;
1925 eRet = OMX_ErrorInsufficientResources;
1926 }
1927 }
1928 }
1929
1930 if (eRet != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001931 DEBUG_PRINT_ERROR("Component Init Failed");
Arun Menon906de572013-06-18 17:01:40 -07001932 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001933 DEBUG_PRINT_HIGH("omx_vdec::component_init() success");
Arun Menon906de572013-06-18 17:01:40 -07001934 }
1935 //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer));
Praveen Chavan898df262015-04-20 18:52:19 -07001936 control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY;
1937 control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE;
1938
1939 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
1940 DEBUG_PRINT_ERROR("Failed to set Default Priority");
1941 eRet = OMX_ErrorUnsupportedSetting;
1942 }
Arun Menon906de572013-06-18 17:01:40 -07001943 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001944}
1945
1946/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001947 FUNCTION
1948 omx_vdec::GetComponentVersion
Shalaj Jain273b3e02012-06-22 19:08:03 -07001949
Arun Menon906de572013-06-18 17:01:40 -07001950 DESCRIPTION
1951 Returns the component version.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001952
Arun Menon906de572013-06-18 17:01:40 -07001953 PARAMETERS
1954 TBD.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001955
Arun Menon906de572013-06-18 17:01:40 -07001956 RETURN VALUE
1957 OMX_ErrorNone.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001958
Arun Menon906de572013-06-18 17:01:40 -07001959 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001960OMX_ERRORTYPE omx_vdec::get_component_version
Arun Menon906de572013-06-18 17:01:40 -07001961(
1962 OMX_IN OMX_HANDLETYPE hComp,
1963 OMX_OUT OMX_STRING componentName,
1964 OMX_OUT OMX_VERSIONTYPE* componentVersion,
1965 OMX_OUT OMX_VERSIONTYPE* specVersion,
1966 OMX_OUT OMX_UUIDTYPE* componentUUID
1967 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07001968{
Arun Menon906de572013-06-18 17:01:40 -07001969 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001970 DEBUG_PRINT_ERROR("Get Comp Version in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07001971 return OMX_ErrorInvalidState;
1972 }
Arun Menon906de572013-06-18 17:01:40 -07001973 /* TBD -- Return the proper version */
1974 if (specVersion) {
1975 specVersion->nVersion = OMX_SPEC_VERSION;
1976 }
1977 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07001978}
1979/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07001980 FUNCTION
1981 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07001982
Arun Menon906de572013-06-18 17:01:40 -07001983 DESCRIPTION
1984 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07001985
Arun Menon906de572013-06-18 17:01:40 -07001986 PARAMETERS
1987 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07001988
Arun Menon906de572013-06-18 17:01:40 -07001989 RETURN VALUE
1990 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07001991
Arun Menon906de572013-06-18 17:01:40 -07001992 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07001993OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07001994 OMX_IN OMX_COMMANDTYPE cmd,
1995 OMX_IN OMX_U32 param1,
1996 OMX_IN OMX_PTR cmdData
1997 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07001998{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07001999 DEBUG_PRINT_LOW("send_command: Recieved a Command from Client");
Arun Menon906de572013-06-18 17:01:40 -07002000 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002001 DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002002 return OMX_ErrorInvalidState;
2003 }
2004 if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX
Arun Menon906de572013-06-18 17:01:40 -07002005 && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002006 DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush "
Arun Menon906de572013-06-18 17:01:40 -07002007 "to invalid port: %lu", param1);
2008 return OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002009 }
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -07002010
Shalaj Jain273b3e02012-06-22 19:08:03 -07002011 post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND);
2012 sem_wait(&m_cmd_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002013 DEBUG_PRINT_LOW("send_command: Command Processed");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002014 return OMX_ErrorNone;
2015}
2016
2017/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002018 FUNCTION
2019 omx_vdec::SendCommand
Shalaj Jain273b3e02012-06-22 19:08:03 -07002020
Arun Menon906de572013-06-18 17:01:40 -07002021 DESCRIPTION
2022 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07002023
Arun Menon906de572013-06-18 17:01:40 -07002024 PARAMETERS
2025 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002026
Arun Menon906de572013-06-18 17:01:40 -07002027 RETURN VALUE
2028 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002029
Arun Menon906de572013-06-18 17:01:40 -07002030 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002031OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002032 OMX_IN OMX_COMMANDTYPE cmd,
2033 OMX_IN OMX_U32 param1,
2034 OMX_IN OMX_PTR cmdData
2035 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07002036{
Arun Menon906de572013-06-18 17:01:40 -07002037 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2038 OMX_STATETYPE eState = (OMX_STATETYPE) param1;
2039 int bFlag = 1,sem_posted = 0,ret=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002040
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002041 DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd);
2042 DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d",
Arun Menon906de572013-06-18 17:01:40 -07002043 m_state, eState);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002044
Arun Menon906de572013-06-18 17:01:40 -07002045 if (cmd == OMX_CommandStateSet) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002046 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued");
2047 DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState);
Arun Menon906de572013-06-18 17:01:40 -07002048 /***************************/
2049 /* Current State is Loaded */
2050 /***************************/
2051 if (m_state == OMX_StateLoaded) {
2052 if (eState == OMX_StateIdle) {
2053 //if all buffers are allocated or all ports disabled
2054 if (allocate_done() ||
2055 (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002056 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07002057 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002058 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending");
Arun Menon906de572013-06-18 17:01:40 -07002059 BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING);
2060 // Skip the event notification
2061 bFlag = 0;
2062 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002063 }
Arun Menon906de572013-06-18 17:01:40 -07002064 /* Requesting transition from Loaded to Loaded */
2065 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002066 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002067 post_event(OMX_EventError,OMX_ErrorSameState,\
2068 OMX_COMPONENT_GENERATE_EVENT);
2069 eRet = OMX_ErrorSameState;
2070 }
2071 /* Requesting transition from Loaded to WaitForResources */
2072 else if (eState == OMX_StateWaitForResources) {
2073 /* Since error is None , we will post an event
2074 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002075 DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002076 }
2077 /* Requesting transition from Loaded to Executing */
2078 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002079 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002080 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2081 OMX_COMPONENT_GENERATE_EVENT);
2082 eRet = OMX_ErrorIncorrectStateTransition;
2083 }
2084 /* Requesting transition from Loaded to Pause */
2085 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002086 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002087 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2088 OMX_COMPONENT_GENERATE_EVENT);
2089 eRet = OMX_ErrorIncorrectStateTransition;
2090 }
2091 /* Requesting transition from Loaded to Invalid */
2092 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002093 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002094 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2095 eRet = OMX_ErrorInvalidState;
2096 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002097 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\
Arun Menon906de572013-06-18 17:01:40 -07002098 eState);
2099 eRet = OMX_ErrorBadParameter;
2100 }
2101 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002102
Arun Menon906de572013-06-18 17:01:40 -07002103 /***************************/
2104 /* Current State is IDLE */
2105 /***************************/
2106 else if (m_state == OMX_StateIdle) {
2107 if (eState == OMX_StateLoaded) {
2108 if (release_done()) {
2109 /*
2110 Since error is None , we will post an event at the end
2111 of this function definition
2112 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002113 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002114 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002115 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending");
Arun Menon906de572013-06-18 17:01:40 -07002116 BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING);
2117 // Skip the event notification
2118 bFlag = 0;
2119 }
2120 }
2121 /* Requesting transition from Idle to Executing */
2122 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002123 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002124 //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING);
2125 bFlag = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002126 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002127 m_state=OMX_StateExecuting;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002128 DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful");
Arun Menon906de572013-06-18 17:01:40 -07002129 }
2130 /* Requesting transition from Idle to Idle */
2131 else if (eState == OMX_StateIdle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002132 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle");
Arun Menon906de572013-06-18 17:01:40 -07002133 post_event(OMX_EventError,OMX_ErrorSameState,\
2134 OMX_COMPONENT_GENERATE_EVENT);
2135 eRet = OMX_ErrorSameState;
2136 }
2137 /* Requesting transition from Idle to WaitForResources */
2138 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002139 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002140 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2141 OMX_COMPONENT_GENERATE_EVENT);
2142 eRet = OMX_ErrorIncorrectStateTransition;
2143 }
2144 /* Requesting transition from Idle to Pause */
2145 else if (eState == OMX_StatePause) {
2146 /*To pause the Video core we need to start the driver*/
2147 if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START,
2148 NULL) < */0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002149 DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED");
Arun Menon906de572013-06-18 17:01:40 -07002150 omx_report_error ();
2151 eRet = OMX_ErrorHardware;
2152 } else {
2153 BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002154 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002155 bFlag = 0;
2156 }
2157 }
2158 /* Requesting transition from Idle to Invalid */
2159 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002160 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002161 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2162 eRet = OMX_ErrorInvalidState;
2163 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002164 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002165 eRet = OMX_ErrorBadParameter;
2166 }
2167 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002168
Arun Menon906de572013-06-18 17:01:40 -07002169 /******************************/
2170 /* Current State is Executing */
2171 /******************************/
2172 else if (m_state == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002173 DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting");
Arun Menon906de572013-06-18 17:01:40 -07002174 /* Requesting transition from Executing to Idle */
2175 if (eState == OMX_StateIdle) {
2176 /* Since error is None , we will post an event
2177 at the end of this function definition
2178 */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002179 DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002180 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2181 if (!sem_posted) {
2182 sem_posted = 1;
2183 sem_post (&m_cmd_lock);
2184 execute_omx_flush(OMX_ALL);
2185 }
2186 bFlag = 0;
2187 }
2188 /* Requesting transition from Executing to Paused */
2189 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002190 DEBUG_PRINT_LOW("PAUSE Command Issued");
Arun Menon906de572013-06-18 17:01:40 -07002191 m_state = OMX_StatePause;
2192 bFlag = 1;
2193 }
2194 /* Requesting transition from Executing to Loaded */
2195 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002196 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002197 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2198 OMX_COMPONENT_GENERATE_EVENT);
2199 eRet = OMX_ErrorIncorrectStateTransition;
2200 }
2201 /* Requesting transition from Executing to WaitForResources */
2202 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002203 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002204 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2205 OMX_COMPONENT_GENERATE_EVENT);
2206 eRet = OMX_ErrorIncorrectStateTransition;
2207 }
2208 /* Requesting transition from Executing to Executing */
2209 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002210 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002211 post_event(OMX_EventError,OMX_ErrorSameState,\
2212 OMX_COMPONENT_GENERATE_EVENT);
2213 eRet = OMX_ErrorSameState;
2214 }
2215 /* Requesting transition from Executing to Invalid */
2216 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002217 DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002218 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2219 eRet = OMX_ErrorInvalidState;
2220 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002221 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002222 eRet = OMX_ErrorBadParameter;
2223 }
2224 }
2225 /***************************/
2226 /* Current State is Pause */
2227 /***************************/
2228 else if (m_state == OMX_StatePause) {
2229 /* Requesting transition from Pause to Executing */
2230 if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002231 DEBUG_PRINT_LOW("Pause --> Executing");
Arun Menon906de572013-06-18 17:01:40 -07002232 m_state = OMX_StateExecuting;
2233 bFlag = 1;
2234 }
2235 /* Requesting transition from Pause to Idle */
2236 else if (eState == OMX_StateIdle) {
2237 /* Since error is None , we will post an event
2238 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002239 DEBUG_PRINT_LOW("Pause --> Idle");
Arun Menon906de572013-06-18 17:01:40 -07002240 BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
2241 if (!sem_posted) {
2242 sem_posted = 1;
2243 sem_post (&m_cmd_lock);
2244 execute_omx_flush(OMX_ALL);
2245 }
2246 bFlag = 0;
2247 }
2248 /* Requesting transition from Pause to loaded */
2249 else if (eState == OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002250 DEBUG_PRINT_ERROR("Pause --> loaded");
Arun Menon906de572013-06-18 17:01:40 -07002251 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2252 OMX_COMPONENT_GENERATE_EVENT);
2253 eRet = OMX_ErrorIncorrectStateTransition;
2254 }
2255 /* Requesting transition from Pause to WaitForResources */
2256 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002257 DEBUG_PRINT_ERROR("Pause --> WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002258 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2259 OMX_COMPONENT_GENERATE_EVENT);
2260 eRet = OMX_ErrorIncorrectStateTransition;
2261 }
2262 /* Requesting transition from Pause to Pause */
2263 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002264 DEBUG_PRINT_ERROR("Pause --> Pause");
Arun Menon906de572013-06-18 17:01:40 -07002265 post_event(OMX_EventError,OMX_ErrorSameState,\
2266 OMX_COMPONENT_GENERATE_EVENT);
2267 eRet = OMX_ErrorSameState;
2268 }
2269 /* Requesting transition from Pause to Invalid */
2270 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002271 DEBUG_PRINT_ERROR("Pause --> Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002272 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2273 eRet = OMX_ErrorInvalidState;
2274 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002275 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState);
Arun Menon906de572013-06-18 17:01:40 -07002276 eRet = OMX_ErrorBadParameter;
2277 }
2278 }
2279 /***************************/
2280 /* Current State is WaitForResources */
2281 /***************************/
2282 else if (m_state == OMX_StateWaitForResources) {
2283 /* Requesting transition from WaitForResources to Loaded */
2284 if (eState == OMX_StateLoaded) {
2285 /* Since error is None , we will post an event
2286 at the end of this function definition */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002287 DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002288 }
2289 /* Requesting transition from WaitForResources to WaitForResources */
2290 else if (eState == OMX_StateWaitForResources) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002291 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources");
Arun Menon906de572013-06-18 17:01:40 -07002292 post_event(OMX_EventError,OMX_ErrorSameState,
2293 OMX_COMPONENT_GENERATE_EVENT);
2294 eRet = OMX_ErrorSameState;
2295 }
2296 /* Requesting transition from WaitForResources to Executing */
2297 else if (eState == OMX_StateExecuting) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002298 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07002299 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2300 OMX_COMPONENT_GENERATE_EVENT);
2301 eRet = OMX_ErrorIncorrectStateTransition;
2302 }
2303 /* Requesting transition from WaitForResources to Pause */
2304 else if (eState == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002305 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause");
Arun Menon906de572013-06-18 17:01:40 -07002306 post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
2307 OMX_COMPONENT_GENERATE_EVENT);
2308 eRet = OMX_ErrorIncorrectStateTransition;
2309 }
2310 /* Requesting transition from WaitForResources to Invalid */
2311 else if (eState == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002312 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid");
Arun Menon906de572013-06-18 17:01:40 -07002313 post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
2314 eRet = OMX_ErrorInvalidState;
2315 }
2316 /* Requesting transition from WaitForResources to Loaded -
2317 is NOT tested by Khronos TS */
2318
2319 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002320 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): %d --> %d(Not Handled)",m_state,eState);
Arun Menon906de572013-06-18 17:01:40 -07002321 eRet = OMX_ErrorBadParameter;
2322 }
2323 }
2324 /********************************/
2325 /* Current State is Invalid */
2326 /*******************************/
2327 else if (m_state == OMX_StateInvalid) {
2328 /* State Transition from Inavlid to any state */
2329 if (eState == (OMX_StateLoaded || OMX_StateWaitForResources
2330 || OMX_StateIdle || OMX_StateExecuting
2331 || OMX_StatePause || OMX_StateInvalid)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002332 DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded");
Arun Menon906de572013-06-18 17:01:40 -07002333 post_event(OMX_EventError,OMX_ErrorInvalidState,\
2334 OMX_COMPONENT_GENERATE_EVENT);
2335 eRet = OMX_ErrorInvalidState;
2336 }
2337 } else if (cmd == OMX_CommandFlush) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002338 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued"
Arun Menon906de572013-06-18 17:01:40 -07002339 "with param1: %lu", param1);
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07002340#ifdef _MSM8974_
2341 send_codec_config();
2342#endif
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302343 if (cmd == OMX_CommandFlush && (param1 == OMX_CORE_INPUT_PORT_INDEX ||
2344 param1 == OMX_ALL)) {
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05302345 if (android_atomic_add(0, &m_queued_codec_config_count) > 0) {
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302346 struct timespec ts;
2347
2348 clock_gettime(CLOCK_REALTIME, &ts);
2349 ts.tv_sec += 2;
2350 DEBUG_PRINT_LOW("waiting for %d EBDs of CODEC CONFIG buffers ",
2351 m_queued_codec_config_count);
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05302352 BITMASK_SET(&m_flags, OMX_COMPONENT_FLUSH_DEFERRED);
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302353 if (sem_timedwait(&m_safe_flush, &ts)) {
2354 DEBUG_PRINT_ERROR("Failed to wait for EBDs of CODEC CONFIG buffers");
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302355 }
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05302356 BITMASK_CLEAR (&m_flags,OMX_COMPONENT_FLUSH_DEFERRED);
Srinu Gorleaf1b9fb2014-08-29 19:40:27 +05302357 }
2358 }
2359
Arun Menon906de572013-06-18 17:01:40 -07002360 if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2361 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING);
2362 }
2363 if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) {
2364 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
2365 }
2366 if (!sem_posted) {
2367 sem_posted = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002368 DEBUG_PRINT_LOW("Set the Semaphore");
Arun Menon906de572013-06-18 17:01:40 -07002369 sem_post (&m_cmd_lock);
2370 execute_omx_flush(param1);
2371 }
2372 bFlag = 0;
2373 } else if ( cmd == OMX_CommandPortEnable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002374 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued"
Arun Menon906de572013-06-18 17:01:40 -07002375 "with param1: %lu", param1);
2376 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
2377 m_inp_bEnabled = OMX_TRUE;
2378
2379 if ( (m_state == OMX_StateLoaded &&
2380 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2381 || allocate_input_done()) {
2382 post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX,
2383 OMX_COMPONENT_GENERATE_EVENT);
2384 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002385 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002386 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING);
2387 // Skip the event notification
2388 bFlag = 0;
2389 }
2390 }
2391 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002392 DEBUG_PRINT_LOW("Enable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002393 m_out_bEnabled = OMX_TRUE;
2394
2395 if ( (m_state == OMX_StateLoaded &&
2396 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
2397 || (allocate_output_done())) {
2398 post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX,
2399 OMX_COMPONENT_GENERATE_EVENT);
2400
2401 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002402 DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending");
Arun Menon906de572013-06-18 17:01:40 -07002403 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
2404 // Skip the event notification
2405 bFlag = 0;
2406 }
2407 }
2408 } else if (cmd == OMX_CommandPortDisable) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002409 DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued"
Arun Menon906de572013-06-18 17:01:40 -07002410 "with param1: %lu", param1);
2411 if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) {
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07002412 codec_config_flag = false;
Arun Menon906de572013-06-18 17:01:40 -07002413 m_inp_bEnabled = OMX_FALSE;
2414 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2415 && release_input_done()) {
2416 post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX,
2417 OMX_COMPONENT_GENERATE_EVENT);
2418 } else {
2419 BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING);
2420 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2421 if (!sem_posted) {
2422 sem_posted = 1;
2423 sem_post (&m_cmd_lock);
2424 }
2425 execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX);
2426 }
2427
2428 // Skip the event notification
2429 bFlag = 0;
2430 }
2431 }
2432 if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) {
2433 m_out_bEnabled = OMX_FALSE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002434 DEBUG_PRINT_LOW("Disable output Port command recieved");
Arun Menon906de572013-06-18 17:01:40 -07002435 if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
2436 && release_output_done()) {
2437 post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\
2438 OMX_COMPONENT_GENERATE_EVENT);
2439 } else {
2440 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
2441 if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) {
2442 if (!sem_posted) {
2443 sem_posted = 1;
2444 sem_post (&m_cmd_lock);
2445 }
2446 BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING);
2447 execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX);
2448 }
2449 // Skip the event notification
2450 bFlag = 0;
2451
2452 }
2453 }
2454 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002455 DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd);
Arun Menon906de572013-06-18 17:01:40 -07002456 eRet = OMX_ErrorNotImplemented;
2457 }
2458 if (eRet == OMX_ErrorNone && bFlag) {
2459 post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT);
2460 }
2461 if (!sem_posted) {
2462 sem_post(&m_cmd_lock);
2463 }
2464
2465 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002466}
2467
2468/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002469 FUNCTION
2470 omx_vdec::ExecuteOmxFlush
Shalaj Jain273b3e02012-06-22 19:08:03 -07002471
Arun Menon906de572013-06-18 17:01:40 -07002472 DESCRIPTION
2473 Executes the OMX flush.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002474
Arun Menon906de572013-06-18 17:01:40 -07002475 PARAMETERS
2476 flushtype - input flush(1)/output flush(0)/ both.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002477
Arun Menon906de572013-06-18 17:01:40 -07002478 RETURN VALUE
2479 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002480
Arun Menon906de572013-06-18 17:01:40 -07002481 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002482bool omx_vdec::execute_omx_flush(OMX_U32 flushType)
2483{
Arun Menon906de572013-06-18 17:01:40 -07002484 bool bRet = false;
2485 struct v4l2_plane plane;
2486 struct v4l2_buffer v4l2_buf;
2487 struct v4l2_decoder_cmd dec;
Surajit Podderd2644d52013-08-28 17:59:06 +05302488 DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType);
Arun Menon906de572013-06-18 17:01:40 -07002489 memset((void *)&v4l2_buf,0,sizeof(v4l2_buf));
2490 dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH;
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002491
Arun Menon906de572013-06-18 17:01:40 -07002492 DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig);
Deva Ramasubramaniancc8fb902013-05-07 18:19:14 -07002493
Arun Menon906de572013-06-18 17:01:40 -07002494 if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) {
2495 output_flush_progress = true;
2496 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2497 } else {
2498 /* XXX: The driver/hardware does not support flushing of individual ports
2499 * in all states. So we pretty much need to flush both ports internally,
2500 * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it
2501 * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set,
2502 * we automatically omit sending the FLUSH done for the "opposite" port. */
2503 input_flush_progress = true;
2504 output_flush_progress = true;
2505 dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE;
2506 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002507
Arun Menon906de572013-06-18 17:01:40 -07002508 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002509 DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType);
Arun Menon906de572013-06-18 17:01:40 -07002510 bRet = false;
2511 }
Deva Ramasubramanian03c9c742012-07-02 15:00:15 -07002512
Arun Menon906de572013-06-18 17:01:40 -07002513 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002514}
2515/*=========================================================================
2516FUNCTION : execute_output_flush
2517
2518DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002519Executes the OMX flush at OUTPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002520
2521PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002522None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002523
2524RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002525true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002526==========================================================================*/
2527bool omx_vdec::execute_output_flush()
2528{
Arun Menon906de572013-06-18 17:01:40 -07002529 unsigned p1 = 0; // Parameter - 1
2530 unsigned p2 = 0; // Parameter - 2
2531 unsigned ident = 0;
2532 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002533
Arun Menon906de572013-06-18 17:01:40 -07002534 /*Generate FBD for all Buffers in the FTBq*/
2535 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002536 DEBUG_PRINT_LOW("Initiate Output Flush");
vivek mehta79cff222014-01-22 12:17:07 -08002537
2538 //reset last render TS
2539 if(m_last_rendered_TS > 0) {
2540 m_last_rendered_TS = 0;
2541 }
vivek mehtaa75c69f2014-01-10 21:50:37 -08002542
Arun Menon906de572013-06-18 17:01:40 -07002543 while (m_ftb_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002544 DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d",
Arun Menon906de572013-06-18 17:01:40 -07002545 m_ftb_q.m_size,pending_output_buffers);
2546 m_ftb_q.pop_entry(&p1,&p2,&ident);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002547 DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2);
Arun Menon906de572013-06-18 17:01:40 -07002548 if (ident == m_fill_output_msg ) {
2549 m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2550 } else if (ident == OMX_COMPONENT_GENERATE_FBD) {
2551 fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2552 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002553 }
Arun Menon906de572013-06-18 17:01:40 -07002554 pthread_mutex_unlock(&m_lock);
2555 output_flush_progress = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002556
Arun Menon906de572013-06-18 17:01:40 -07002557 if (arbitrary_bytes) {
2558 prev_ts = LLONG_MAX;
2559 rst_prev_ts = true;
2560 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002561 DEBUG_PRINT_HIGH("OMX flush o/p Port complete PenBuf(%d)", pending_output_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002562 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002563}
2564/*=========================================================================
2565FUNCTION : execute_input_flush
2566
2567DESCRIPTION
Arun Menon906de572013-06-18 17:01:40 -07002568Executes the OMX flush at INPUT PORT.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002569
2570PARAMETERS
Arun Menon906de572013-06-18 17:01:40 -07002571None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002572
2573RETURN VALUE
Arun Menon906de572013-06-18 17:01:40 -07002574true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002575==========================================================================*/
2576bool omx_vdec::execute_input_flush()
2577{
Arun Menon906de572013-06-18 17:01:40 -07002578 unsigned i =0;
2579 unsigned p1 = 0; // Parameter - 1
2580 unsigned p2 = 0; // Parameter - 2
2581 unsigned ident = 0;
2582 bool bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002583
Arun Menon906de572013-06-18 17:01:40 -07002584 /*Generate EBD for all Buffers in the ETBq*/
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002585 DEBUG_PRINT_LOW("Initiate Input Flush");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002586
Arun Menon906de572013-06-18 17:01:40 -07002587 pthread_mutex_lock(&m_lock);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002588 DEBUG_PRINT_LOW("Check if the Queue is empty");
Arun Menon906de572013-06-18 17:01:40 -07002589 while (m_etb_q.m_size) {
2590 m_etb_q.pop_entry(&p1,&p2,&ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002591
Arun Menon906de572013-06-18 17:01:40 -07002592 if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002593 DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2);
Arun Menon906de572013-06-18 17:01:40 -07002594 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
2595 } else if (ident == OMX_COMPONENT_GENERATE_ETB) {
2596 pending_input_buffers++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002597 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d",
Arun Menon906de572013-06-18 17:01:40 -07002598 (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers);
2599 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
2600 } else if (ident == OMX_COMPONENT_GENERATE_EBD) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002601 DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p",
Arun Menon906de572013-06-18 17:01:40 -07002602 (OMX_BUFFERHEADERTYPE *)p1);
2603 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
2604 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002605 }
Arun Menon906de572013-06-18 17:01:40 -07002606 time_stamp_dts.flush_timestamp();
2607 /*Check if Heap Buffers are to be flushed*/
2608 if (arbitrary_bytes && !(codec_config_flag)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002609 DEBUG_PRINT_LOW("Reset all the variables before flusing");
Arun Menon906de572013-06-18 17:01:40 -07002610 h264_scratch.nFilledLen = 0;
2611 nal_count = 0;
2612 look_ahead_nal = false;
2613 frame_count = 0;
2614 h264_last_au_ts = LLONG_MAX;
2615 h264_last_au_flags = 0;
2616 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
2617 m_demux_entries = 0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002618 DEBUG_PRINT_LOW("Initialize parser");
Arun Menon906de572013-06-18 17:01:40 -07002619 if (m_frame_parser.mutils) {
2620 m_frame_parser.mutils->initialize_frame_checking_environment();
2621 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002622
Arun Menon906de572013-06-18 17:01:40 -07002623 while (m_input_pending_q.m_size) {
2624 m_input_pending_q.pop_entry(&p1,&p2,&ident);
2625 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1);
2626 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002627
Arun Menon906de572013-06-18 17:01:40 -07002628 if (psource_frame) {
2629 m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame);
2630 psource_frame = NULL;
2631 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002632
Arun Menon906de572013-06-18 17:01:40 -07002633 if (pdest_frame) {
2634 pdest_frame->nFilledLen = 0;
2635 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL,
2636 (unsigned int)NULL);
2637 pdest_frame = NULL;
2638 }
2639 m_frame_parser.flush();
2640 } else if (codec_config_flag) {
2641 DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer "
2642 "is not sent to the driver yet");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002643 }
Arun Menon906de572013-06-18 17:01:40 -07002644 pthread_mutex_unlock(&m_lock);
2645 input_flush_progress = false;
2646 if (!arbitrary_bytes) {
2647 prev_ts = LLONG_MAX;
2648 rst_prev_ts = true;
2649 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002650#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07002651 if (m_debug_timestamp) {
2652 m_timestamp_list.reset_ts_list();
2653 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002654#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002655 DEBUG_PRINT_HIGH("OMX flush i/p Port complete PenBuf(%d)", pending_input_buffers);
Arun Menon906de572013-06-18 17:01:40 -07002656 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002657}
2658
2659
2660/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002661 FUNCTION
2662 omx_vdec::SendCommandEvent
Shalaj Jain273b3e02012-06-22 19:08:03 -07002663
Arun Menon906de572013-06-18 17:01:40 -07002664 DESCRIPTION
2665 Send the event to decoder pipe. This is needed to generate the callbacks
2666 in decoder thread context.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002667
Arun Menon906de572013-06-18 17:01:40 -07002668 PARAMETERS
2669 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002670
Arun Menon906de572013-06-18 17:01:40 -07002671 RETURN VALUE
2672 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07002673
Arun Menon906de572013-06-18 17:01:40 -07002674 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002675bool omx_vdec::post_event(unsigned int p1,
Arun Menon906de572013-06-18 17:01:40 -07002676 unsigned int p2,
2677 unsigned int id)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002678{
Arun Menon906de572013-06-18 17:01:40 -07002679 bool bRet = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002680
2681
Arun Menon906de572013-06-18 17:01:40 -07002682 pthread_mutex_lock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002683
Arun Menon906de572013-06-18 17:01:40 -07002684 if (id == m_fill_output_msg ||
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05302685 id == OMX_COMPONENT_GENERATE_FBD ||
2686 id == OMX_COMPONENT_GENERATE_PORT_RECONFIG) {
Arun Menon906de572013-06-18 17:01:40 -07002687 m_ftb_q.insert_entry(p1,p2,id);
2688 } else if (id == OMX_COMPONENT_GENERATE_ETB ||
2689 id == OMX_COMPONENT_GENERATE_EBD ||
2690 id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
2691 m_etb_q.insert_entry(p1,p2,id);
2692 } else {
2693 m_cmd_q.insert_entry(p1,p2,id);
2694 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002695
Arun Menon906de572013-06-18 17:01:40 -07002696 bRet = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002697 DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this);
Arun Menon906de572013-06-18 17:01:40 -07002698 post_message(this, id);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002699
Arun Menon906de572013-06-18 17:01:40 -07002700 pthread_mutex_unlock(&m_lock);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002701
Arun Menon906de572013-06-18 17:01:40 -07002702 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002703}
2704
2705OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType)
2706{
Arun Menon906de572013-06-18 17:01:40 -07002707 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2708 if (!profileLevelType)
2709 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002710
Arun Menon906de572013-06-18 17:01:40 -07002711 if (profileLevelType->nPortIndex == 0) {
2712 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
2713 if (profileLevelType->nProfileIndex == 0) {
2714 profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline;
2715 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002716
Arun Menon906de572013-06-18 17:01:40 -07002717 } else if (profileLevelType->nProfileIndex == 1) {
2718 profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain;
2719 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2720 } else if (profileLevelType->nProfileIndex == 2) {
2721 profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh;
2722 profileLevelType->eLevel = OMX_VIDEO_AVCLevel4;
2723 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002724 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu",
Arun Menon906de572013-06-18 17:01:40 -07002725 profileLevelType->nProfileIndex);
2726 eRet = OMX_ErrorNoMore;
2727 }
2728 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) {
2729 if (profileLevelType->nProfileIndex == 0) {
2730 profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline;
2731 profileLevelType->eLevel = OMX_VIDEO_H263Level70;
2732 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002733 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002734 eRet = OMX_ErrorNoMore;
2735 }
2736 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
2737 if (profileLevelType->nProfileIndex == 0) {
2738 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple;
2739 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2740 } else if (profileLevelType->nProfileIndex == 1) {
2741 profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple;
2742 profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5;
2743 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002744 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002745 eRet = OMX_ErrorNoMore;
2746 }
2747 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
2748 eRet = OMX_ErrorNoMore;
2749 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
2750 if (profileLevelType->nProfileIndex == 0) {
2751 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple;
2752 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2753 } else if (profileLevelType->nProfileIndex == 1) {
2754 profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain;
2755 profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL;
2756 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002757 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex);
Arun Menon906de572013-06-18 17:01:40 -07002758 eRet = OMX_ErrorNoMore;
2759 }
2760 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002761 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported ret NoMore for codec: %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07002762 eRet = OMX_ErrorNoMore;
2763 }
2764 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002765 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported should be queries on Input port only %lu", profileLevelType->nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07002766 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002767 }
Arun Menon906de572013-06-18 17:01:40 -07002768 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002769}
2770
2771/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07002772 FUNCTION
2773 omx_vdec::GetParameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07002774
Arun Menon906de572013-06-18 17:01:40 -07002775 DESCRIPTION
2776 OMX Get Parameter method implementation
Shalaj Jain273b3e02012-06-22 19:08:03 -07002777
Arun Menon906de572013-06-18 17:01:40 -07002778 PARAMETERS
2779 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002780
Arun Menon906de572013-06-18 17:01:40 -07002781 RETURN VALUE
2782 Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07002783
Arun Menon906de572013-06-18 17:01:40 -07002784 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07002785OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07002786 OMX_IN OMX_INDEXTYPE paramIndex,
2787 OMX_INOUT OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07002788{
2789 OMX_ERRORTYPE eRet = OMX_ErrorNone;
2790
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002791 DEBUG_PRINT_LOW("get_parameter:");
Arun Menon906de572013-06-18 17:01:40 -07002792 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002793 DEBUG_PRINT_ERROR("Get Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002794 return OMX_ErrorInvalidState;
2795 }
Arun Menon906de572013-06-18 17:01:40 -07002796 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002797 DEBUG_PRINT_LOW("Get Param in Invalid paramData");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002798 return OMX_ErrorBadParameter;
2799 }
Arun Menon906de572013-06-18 17:01:40 -07002800 switch ((unsigned long)paramIndex) {
2801 case OMX_IndexParamPortDefinition: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002802 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002803 OMX_PARAM_PORTDEFINITIONTYPE *portDefn =
2804 (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002805 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition");
Arun Menon906de572013-06-18 17:01:40 -07002806 eRet = update_portdef(portDefn);
2807 if (eRet == OMX_ErrorNone)
2808 m_port_def = *portDefn;
2809 break;
2810 }
2811 case OMX_IndexParamVideoInit: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002812 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002813 OMX_PORT_PARAM_TYPE *portParamType =
2814 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002815 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002816
Arun Menon906de572013-06-18 17:01:40 -07002817 portParamType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002818 portParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002819 portParamType->nPorts = 2;
2820 portParamType->nStartPortNumber = 0;
2821 break;
2822 }
2823 case OMX_IndexParamVideoPortFormat: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002824 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002825 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
2826 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002827 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002828
Arun Menon906de572013-06-18 17:01:40 -07002829 portFmt->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002830 portFmt->nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002831
Arun Menon906de572013-06-18 17:01:40 -07002832 if (0 == portFmt->nPortIndex) {
2833 if (0 == portFmt->nIndex) {
2834 portFmt->eColorFormat = OMX_COLOR_FormatUnused;
2835 portFmt->eCompressionFormat = eCompressionFormat;
2836 } else {
2837 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002838 " NoMore compression formats");
Arun Menon906de572013-06-18 17:01:40 -07002839 eRet = OMX_ErrorNoMore;
2840 }
2841 } else if (1 == portFmt->nPortIndex) {
2842 portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002843
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07002844 // Distinguish non-surface mode from normal playback use-case based on
2845 // usage hinted via "OMX.google.android.index.useAndroidNativeBuffer2"
2846 // For non-android, use the default list
Praveen Chavancac86402014-10-18 09:14:52 -07002847 // Also use default format-list if FLEXIBLE YUV is supported,
2848 // as the client negotiates the standard color-format if it needs to
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07002849 bool useNonSurfaceMode = false;
Praveen Chavancac86402014-10-18 09:14:52 -07002850#if defined(_ANDROID_) && !defined(FLEXYUV_SUPPORTED)
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07002851 useNonSurfaceMode = (m_enable_android_native_buffers == OMX_FALSE);
2852#endif
2853 portFmt->eColorFormat = useNonSurfaceMode ?
2854 getPreferredColorFormatNonSurfaceMode(portFmt->nIndex) :
2855 getPreferredColorFormatDefaultMode(portFmt->nIndex);
2856
2857 if (portFmt->eColorFormat == OMX_COLOR_FormatMax ) {
Praveen Chavandb7776f2014-02-06 18:17:25 -08002858 eRet = OMX_ErrorNoMore;
Arun Menon906de572013-06-18 17:01:40 -07002859 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002860 " NoMore Color formats");
Arun Menon906de572013-06-18 17:01:40 -07002861 }
Praveen Chavandb7776f2014-02-06 18:17:25 -08002862 DEBUG_PRINT_HIGH("returning color-format: 0x%x", portFmt->eColorFormat);
Arun Menon906de572013-06-18 17:01:40 -07002863 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002864 DEBUG_PRINT_ERROR("get_parameter: Bad port index %d",
Arun Menon906de572013-06-18 17:01:40 -07002865 (int)portFmt->nPortIndex);
2866 eRet = OMX_ErrorBadPortIndex;
2867 }
2868 break;
2869 }
2870 /*Component should support this port definition*/
2871 case OMX_IndexParamAudioInit: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002872 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002873 OMX_PORT_PARAM_TYPE *audioPortParamType =
2874 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002875 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit");
Arun Menon906de572013-06-18 17:01:40 -07002876 audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002877 audioPortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002878 audioPortParamType->nPorts = 0;
2879 audioPortParamType->nStartPortNumber = 0;
2880 break;
2881 }
2882 /*Component should support this port definition*/
2883 case OMX_IndexParamImageInit: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002884 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002885 OMX_PORT_PARAM_TYPE *imagePortParamType =
2886 (OMX_PORT_PARAM_TYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002887 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit");
Arun Menon906de572013-06-18 17:01:40 -07002888 imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002889 imagePortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE);
Arun Menon906de572013-06-18 17:01:40 -07002890 imagePortParamType->nPorts = 0;
2891 imagePortParamType->nStartPortNumber = 0;
2892 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002893
Arun Menon906de572013-06-18 17:01:40 -07002894 }
2895 /*Component should support this port definition*/
2896 case OMX_IndexParamOtherInit: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002897 DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x",
Arun Menon906de572013-06-18 17:01:40 -07002898 paramIndex);
2899 eRet =OMX_ErrorUnsupportedIndex;
2900 break;
2901 }
2902 case OMX_IndexParamStandardComponentRole: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002903 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE);
Arun Menon906de572013-06-18 17:01:40 -07002904 OMX_PARAM_COMPONENTROLETYPE *comp_role;
2905 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
2906 comp_role->nVersion.nVersion = OMX_SPEC_VERSION;
2907 comp_role->nSize = sizeof(*comp_role);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002908
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002909 DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d",
Arun Menon906de572013-06-18 17:01:40 -07002910 paramIndex);
2911 strlcpy((char*)comp_role->cRole,(const char*)m_cRole,
2912 OMX_MAX_STRINGNAME_SIZE);
2913 break;
2914 }
2915 /* Added for parameter test */
2916 case OMX_IndexParamPriorityMgmt: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002917 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002918 OMX_PRIORITYMGMTTYPE *priorityMgmType =
2919 (OMX_PRIORITYMGMTTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002920 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt");
Arun Menon906de572013-06-18 17:01:40 -07002921 priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07002922 priorityMgmType->nSize = sizeof(OMX_PRIORITYMGMTTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07002923
Arun Menon906de572013-06-18 17:01:40 -07002924 break;
2925 }
2926 /* Added for parameter test */
2927 case OMX_IndexParamCompBufferSupplier: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002928 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002929 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType =
2930 (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002931 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier");
Shalaj Jain273b3e02012-06-22 19:08:03 -07002932
Praveen Chavan366ded52016-04-11 17:33:02 -07002933 bufferSupplierType->nSize = sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE);
Arun Menon906de572013-06-18 17:01:40 -07002934 bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION;
2935 if (0 == bufferSupplierType->nPortIndex)
2936 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2937 else if (1 == bufferSupplierType->nPortIndex)
2938 bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified;
2939 else
2940 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002941
2942
Arun Menon906de572013-06-18 17:01:40 -07002943 break;
2944 }
2945 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002946 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x",
Arun Menon906de572013-06-18 17:01:40 -07002947 paramIndex);
2948 break;
2949 }
2950 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002951 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002952 paramIndex);
2953 break;
2954 }
2955 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002956 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002957 paramIndex);
2958 break;
2959 }
2960 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002961 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x",
Arun Menon906de572013-06-18 17:01:40 -07002962 paramIndex);
2963 break;
2964 }
2965 case OMX_IndexParamVideoProfileLevelQuerySupported: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002966 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002967 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07002968 OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType =
2969 (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData;
2970 eRet = get_supported_profile_level_for_1080p(profileLevelType);
2971 break;
2972 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07002973#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07002974 case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: {
Praveen Chavan366ded52016-04-11 17:33:02 -07002975 VALIDATE_OMX_PARAM_DATA(paramData, GetAndroidNativeBufferUsageParams);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002976 DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage");
Arun Menon906de572013-06-18 17:01:40 -07002977 GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData;
2978 if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07002979
Arun Menon906de572013-06-18 17:01:40 -07002980 if (secure_mode) {
2981 nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED |
2982 GRALLOC_USAGE_PRIVATE_UNCACHED);
2983 } else {
2984 nativeBuffersUsage->nUsage =
2985 (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP |
2986 GRALLOC_USAGE_PRIVATE_UNCACHED);
2987 }
2988 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07002989 DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!");
Arun Menon906de572013-06-18 17:01:40 -07002990 eRet = OMX_ErrorBadParameter;
2991 }
2992 }
2993 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07002994#endif
2995
Praveen Chavan09a82b72014-10-18 09:09:45 -07002996#ifdef FLEXYUV_SUPPORTED
2997 case OMX_QcomIndexFlexibleYUVDescription: {
2998 DEBUG_PRINT_LOW("get_parameter: describeColorFormat");
Praveen Chavan366ded52016-04-11 17:33:02 -07002999 VALIDATE_OMX_PARAM_DATA(paramData, DescribeColorFormatParams);
Praveen Chavan09a82b72014-10-18 09:09:45 -07003000 eRet = describeColorFormat(paramData);
3001 break;
3002 }
3003#endif
3004
Arun Menon906de572013-06-18 17:01:40 -07003005 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003006 DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003007 eRet =OMX_ErrorUnsupportedIndex;
3008 }
3009
Shalaj Jain273b3e02012-06-22 19:08:03 -07003010 }
3011
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003012 DEBUG_PRINT_LOW("get_parameter returning WxH(%d x %d) SxSH(%d x %d)",
Arun Menon906de572013-06-18 17:01:40 -07003013 drv_ctx.video_resolution.frame_width,
3014 drv_ctx.video_resolution.frame_height,
3015 drv_ctx.video_resolution.stride,
3016 drv_ctx.video_resolution.scan_lines);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003017
Arun Menon906de572013-06-18 17:01:40 -07003018 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003019}
3020
3021#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
3022OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data)
3023{
3024 DEBUG_PRINT_LOW("Inside use_android_native_buffer");
3025 OMX_ERRORTYPE eRet = OMX_ErrorNone;
3026 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data;
3027
Arun Menon906de572013-06-18 17:01:40 -07003028 if ((params == NULL) ||
3029 (params->nativeBuffer == NULL) ||
3030 (params->nativeBuffer->handle == NULL) ||
3031 !m_enable_android_native_buffers)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003032 return OMX_ErrorBadParameter;
3033 m_use_android_native_buffers = OMX_TRUE;
3034 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
3035 private_handle_t *handle = (private_handle_t *)nBuf->handle;
Arun Menon906de572013-06-18 17:01:40 -07003036 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 -07003037 OMX_U8 *buffer = NULL;
Arun Menon906de572013-06-18 17:01:40 -07003038 if (!secure_mode) {
3039 buffer = (OMX_U8*)mmap(0, handle->size,
Shalaj Jain273b3e02012-06-22 19:08:03 -07003040 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
Arun Menon906de572013-06-18 17:01:40 -07003041 if (buffer == MAP_FAILED) {
3042 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
3043 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003044 }
3045 }
3046 eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer);
3047 } else {
3048 eRet = OMX_ErrorBadParameter;
3049 }
3050 return eRet;
3051}
3052#endif
Praveen Chavancf924182013-12-06 23:16:23 -08003053
3054OMX_ERRORTYPE omx_vdec::enable_smoothstreaming() {
3055 struct v4l2_control control;
3056 struct v4l2_format fmt;
3057 control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER;
3058 control.value = 1;
3059 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3060 if (rc < 0) {
3061 DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver.");
3062 return OMX_ErrorHardware;
3063 }
3064 m_smoothstreaming_mode = true;
3065 return OMX_ErrorNone;
3066}
3067
Shalaj Jain273b3e02012-06-22 19:08:03 -07003068/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003069 FUNCTION
3070 omx_vdec::Setparameter
Shalaj Jain273b3e02012-06-22 19:08:03 -07003071
Arun Menon906de572013-06-18 17:01:40 -07003072 DESCRIPTION
3073 OMX Set Parameter method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003074
Arun Menon906de572013-06-18 17:01:40 -07003075 PARAMETERS
3076 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003077
Arun Menon906de572013-06-18 17:01:40 -07003078 RETURN VALUE
3079 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003080
Arun Menon906de572013-06-18 17:01:40 -07003081 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003082OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003083 OMX_IN OMX_INDEXTYPE paramIndex,
3084 OMX_IN OMX_PTR paramData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003085{
3086 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Praneeth Paladugu226667c2012-09-12 16:42:30 -07003087 int ret=0;
3088 struct v4l2_format fmt;
Arun Menon906de572013-06-18 17:01:40 -07003089 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003090 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003091 return OMX_ErrorInvalidState;
3092 }
Arun Menon906de572013-06-18 17:01:40 -07003093 if (paramData == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003094 DEBUG_PRINT_ERROR("Get Param in Invalid paramData");
Arun Menon906de572013-06-18 17:01:40 -07003095 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003096 }
Arun Menon906de572013-06-18 17:01:40 -07003097 if ((m_state != OMX_StateLoaded) &&
3098 BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) &&
3099 (m_out_bEnabled == OMX_TRUE) &&
3100 BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) &&
3101 (m_inp_bEnabled == OMX_TRUE)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003102 DEBUG_PRINT_ERROR("Set Param in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003103 return OMX_ErrorIncorrectStateOperation;
3104 }
Arun Menon906de572013-06-18 17:01:40 -07003105 switch ((unsigned long)paramIndex) {
3106 case OMX_IndexParamPortDefinition: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003107 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003108 OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
3109 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
3110 //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has
3111 //been called.
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003112 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d",
Arun Menon906de572013-06-18 17:01:40 -07003113 (int)portDefn->format.video.nFrameHeight,
3114 (int)portDefn->format.video.nFrameWidth);
3115 if (OMX_DirOutput == portDefn->eDir) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003116 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port");
Pushkaraj Patil41588352014-02-25 20:51:34 +05303117 bool port_format_changed = false;
Arun Menon906de572013-06-18 17:01:40 -07003118 m_display_id = portDefn->format.video.pNativeWindow;
3119 unsigned int buffer_size;
Praveen Chavane78460c2013-12-06 23:16:04 -08003120 /* update output port resolution with client supplied dimensions
3121 in case scaling is enabled, else it follows input resolution set
3122 */
3123 if (is_down_scalar_enabled) {
3124 DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n",
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003125 portDefn->format.video.nFrameWidth,
3126 portDefn->format.video.nFrameHeight);
3127 if (portDefn->format.video.nFrameHeight != 0x0 &&
3128 portDefn->format.video.nFrameWidth != 0x0) {
Pushkaraj Patil41588352014-02-25 20:51:34 +05303129 memset(&fmt, 0x0, sizeof(struct v4l2_format));
3130 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3131 fmt.fmt.pix_mp.pixelformat = capture_capability;
3132 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
3133 if (ret) {
3134 DEBUG_PRINT_ERROR("Get Resolution failed");
3135 eRet = OMX_ErrorHardware;
3136 break;
3137 }
3138 if ((portDefn->format.video.nFrameHeight != (int)fmt.fmt.pix_mp.height) ||
3139 (portDefn->format.video.nFrameWidth != (int)fmt.fmt.pix_mp.width)) {
3140 port_format_changed = true;
3141 }
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003142 update_resolution(portDefn->format.video.nFrameWidth,
3143 portDefn->format.video.nFrameHeight,
3144 portDefn->format.video.nFrameWidth,
3145 portDefn->format.video.nFrameHeight);
Pushkaraj Patil41588352014-02-25 20:51:34 +05303146
3147 /* set crop info */
3148 rectangle.nLeft = 0;
3149 rectangle.nTop = 0;
3150 rectangle.nWidth = portDefn->format.video.nFrameWidth;
3151 rectangle.nHeight = portDefn->format.video.nFrameHeight;
3152
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003153 eRet = is_video_session_supported();
3154 if (eRet)
3155 break;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303156 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003157 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3158 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3159 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3160 fmt.fmt.pix_mp.pixelformat = capture_capability;
3161 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);
3162 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3163 if (ret) {
3164 DEBUG_PRINT_ERROR("\n Set Resolution failed");
3165 eRet = OMX_ErrorUnsupportedSetting;
3166 } else
3167 eRet = get_buffer_req(&drv_ctx.op_buf);
3168 }
Praveen Chavane78460c2013-12-06 23:16:04 -08003169 }
Praveen Chavan88256fe2016-04-11 17:32:45 -07003170 if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) {
3171 DEBUG_PRINT_ERROR("Requested o/p buf count (%u) exceeds limit (%u)",
3172 portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS);
3173 eRet = OMX_ErrorBadParameter;
3174 } else if (!client_buffers.get_buffer_req(buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003175 DEBUG_PRINT_ERROR("Error in getting buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07003176 eRet = OMX_ErrorBadParameter;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303177 } else if (!port_format_changed) {
Praveen Chavan88256fe2016-04-11 17:32:45 -07003178
Praveen Chavan58207a22016-08-17 12:19:29 -07003179 // Buffer count can change only when port is unallocated
3180 if (m_out_mem_ptr &&
3181 (portDefn->nBufferCountActual != drv_ctx.op_buf.actualcount ||
3182 portDefn->nBufferSize != drv_ctx.op_buf.buffer_size)) {
3183
Praveen Chavan88256fe2016-04-11 17:32:45 -07003184 DEBUG_PRINT_ERROR("Cannot change o/p buffer count since all buffers are not freed yet !");
3185 eRet = OMX_ErrorInvalidState;
3186 break;
3187 }
3188
Arun Menon906de572013-06-18 17:01:40 -07003189 if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount &&
3190 portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) {
3191 drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual;
3192 drv_ctx.op_buf.buffer_size = portDefn->nBufferSize;
3193 drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount;
3194 drv_ctx.extradata_info.size = drv_ctx.extradata_info.count *
3195 drv_ctx.extradata_info.buffer_size;
3196 eRet = set_buffer_req(&drv_ctx.op_buf);
3197 if (eRet == OMX_ErrorNone)
3198 m_port_def = *portDefn;
3199 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003200 DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003201 drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size,
3202 portDefn->nBufferCountActual, portDefn->nBufferSize);
3203 eRet = OMX_ErrorBadParameter;
3204 }
3205 }
3206 } else if (OMX_DirInput == portDefn->eDir) {
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003207 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port");
Arun Menon906de572013-06-18 17:01:40 -07003208 bool port_format_changed = false;
3209 if ((portDefn->format.video.xFramerate >> 16) > 0 &&
3210 (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) {
3211 // Frame rate only should be set if this is a "known value" or to
3212 // activate ts prediction logic (arbitrary mode only) sending input
3213 // timestamps with max value (LLONG_MAX).
3214 DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu",
3215 portDefn->format.video.xFramerate >> 16);
3216 Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator,
3217 drv_ctx.frame_rate.fps_denominator);
3218 if (!drv_ctx.frame_rate.fps_numerator) {
3219 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
3220 drv_ctx.frame_rate.fps_numerator = 30;
3221 }
3222 if (drv_ctx.frame_rate.fps_denominator)
3223 drv_ctx.frame_rate.fps_numerator = (int)
3224 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
3225 drv_ctx.frame_rate.fps_denominator = 1;
3226 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
3227 drv_ctx.frame_rate.fps_numerator;
3228 DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)",
3229 frm_int, drv_ctx.frame_rate.fps_numerator /
3230 (float)drv_ctx.frame_rate.fps_denominator);
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003231
3232 struct v4l2_outputparm oparm;
3233 /*XXX: we're providing timing info as seconds per frame rather than frames
3234 * per second.*/
3235 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
3236 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
3237
3238 struct v4l2_streamparm sparm;
3239 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
3240 sparm.parm.output = oparm;
3241 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
3242 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, performance might be affected");
3243 eRet = OMX_ErrorHardware;
3244 break;
3245 }
Arun Menon906de572013-06-18 17:01:40 -07003246 }
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08003247
Arun Menon906de572013-06-18 17:01:40 -07003248 if (drv_ctx.video_resolution.frame_height !=
3249 portDefn->format.video.nFrameHeight ||
3250 drv_ctx.video_resolution.frame_width !=
3251 portDefn->format.video.nFrameWidth) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003252 DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003253 portDefn->format.video.nFrameWidth,
3254 portDefn->format.video.nFrameHeight);
3255 port_format_changed = true;
Praveen Chavancf924182013-12-06 23:16:23 -08003256 OMX_U32 frameWidth = portDefn->format.video.nFrameWidth;
3257 OMX_U32 frameHeight = portDefn->format.video.nFrameHeight;
3258 if (frameHeight != 0x0 && frameWidth != 0x0) {
3259 if (m_smoothstreaming_mode &&
3260 ((frameWidth * frameHeight) <
3261 (m_smoothstreaming_width * m_smoothstreaming_height))) {
3262 frameWidth = m_smoothstreaming_width;
3263 frameHeight = m_smoothstreaming_height;
3264 DEBUG_PRINT_LOW("NOTE: Setting resolution %lu x %lu for adaptive-playback/smooth-streaming",
3265 frameWidth, frameHeight);
3266 }
3267 update_resolution(frameWidth, frameHeight,
3268 frameWidth, frameHeight);
Arun Menon906de572013-06-18 17:01:40 -07003269 eRet = is_video_session_supported();
3270 if (eRet)
3271 break;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303272 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Arun Menon906de572013-06-18 17:01:40 -07003273 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
3274 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3275 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3276 fmt.fmt.pix_mp.pixelformat = output_capability;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003277 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 -07003278 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3279 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003280 DEBUG_PRINT_ERROR("Set Resolution failed");
Arun Menon906de572013-06-18 17:01:40 -07003281 eRet = OMX_ErrorUnsupportedSetting;
Pushkaraj Patil41588352014-02-25 20:51:34 +05303282 } else {
3283 if (!is_down_scalar_enabled)
3284 eRet = get_buffer_req(&drv_ctx.op_buf);
3285 }
Arun Menon906de572013-06-18 17:01:40 -07003286 }
3287 }
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303288 if (m_custom_buffersize.input_buffersize
3289 && (portDefn->nBufferSize > m_custom_buffersize.input_buffersize)) {
3290 DEBUG_PRINT_ERROR("ERROR: Custom buffer size set by client: %d, trying to set: %d",
3291 m_custom_buffersize.input_buffersize, portDefn->nBufferSize);
3292 eRet = OMX_ErrorBadParameter;
3293 break;
3294 }
Praveen Chavan88256fe2016-04-11 17:32:45 -07003295 if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) {
3296 DEBUG_PRINT_ERROR("Requested i/p buf count (%u) exceeds limit (%u)",
3297 portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS);
3298 eRet = OMX_ErrorBadParameter;
3299 break;
3300 }
Praveen Chavan58207a22016-08-17 12:19:29 -07003301 // Buffer count can change only when port is unallocated
3302 if (m_inp_mem_ptr &&
3303 (portDefn->nBufferCountActual != drv_ctx.ip_buf.actualcount ||
3304 portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size)) {
Praveen Chavan88256fe2016-04-11 17:32:45 -07003305 DEBUG_PRINT_ERROR("Cannot change i/p buffer count since all buffers are not freed yet !");
3306 eRet = OMX_ErrorInvalidState;
3307 break;
3308 }
3309
Arun Menon906de572013-06-18 17:01:40 -07003310 if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount
3311 || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) {
3312 port_format_changed = true;
3313 vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf;
3314 drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual;
3315 drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) &
3316 (~(buffer_prop->alignment - 1));
3317 eRet = set_buffer_req(buffer_prop);
3318 }
3319 if (false == port_format_changed) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003320 DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)",
Arun Menon906de572013-06-18 17:01:40 -07003321 drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size,
3322 portDefn->nBufferCountActual, portDefn->nBufferSize);
3323 eRet = OMX_ErrorBadParameter;
3324 }
3325 } else if (portDefn->eDir == OMX_DirMax) {
3326 DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d",
3327 (int)portDefn->nPortIndex);
3328 eRet = OMX_ErrorBadPortIndex;
3329 }
3330 }
3331 break;
3332 case OMX_IndexParamVideoPortFormat: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003333 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003334 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
3335 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
3336 int ret=0;
3337 struct v4l2_format fmt;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003338 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d",
Arun Menon906de572013-06-18 17:01:40 -07003339 portFmt->eColorFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003340
Arun Menon906de572013-06-18 17:01:40 -07003341 if (1 == portFmt->nPortIndex) {
3342 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
3343 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
3344 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
3345 fmt.fmt.pix_mp.pixelformat = capture_capability;
3346 enum vdec_output_fromat op_format;
3347 if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE)
3348 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) ||
Praveen Chavandb7776f2014-02-06 18:17:25 -08003349 (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar) ||
3350 (portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar))
Arun Menon906de572013-06-18 17:01:40 -07003351 op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12;
Arun Menon906de572013-06-18 17:01:40 -07003352 else
3353 eRet = OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003354
Arun Menon906de572013-06-18 17:01:40 -07003355 if (eRet == OMX_ErrorNone) {
3356 drv_ctx.output_format = op_format;
3357 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
3358 if (ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003359 DEBUG_PRINT_ERROR("Set output format failed");
Arun Menon906de572013-06-18 17:01:40 -07003360 eRet = OMX_ErrorUnsupportedSetting;
3361 /*TODO: How to handle this case */
3362 } else {
3363 eRet = get_buffer_req(&drv_ctx.op_buf);
3364 }
3365 }
3366 if (eRet == OMX_ErrorNone) {
3367 if (!client_buffers.set_color_format(portFmt->eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003368 DEBUG_PRINT_ERROR("Set color format failed");
Arun Menon906de572013-06-18 17:01:40 -07003369 eRet = OMX_ErrorBadParameter;
3370 }
3371 }
3372 }
3373 }
3374 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003375
Arun Menon906de572013-06-18 17:01:40 -07003376 case OMX_QcomIndexPortDefn: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003377 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003378 OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt =
3379 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003380 DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu",
Arun Menon906de572013-06-18 17:01:40 -07003381 portFmt->nFramePackingFormat);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003382
Arun Menon906de572013-06-18 17:01:40 -07003383 /* Input port */
3384 if (portFmt->nPortIndex == 0) {
Praveen Chavan58207a22016-08-17 12:19:29 -07003385 // arbitrary_bytes mode cannot be changed arbitrarily since this controls how:
3386 // - headers are allocated and
3387 // - headers-indices are derived
3388 // Avoid changing arbitrary_bytes when the port is already allocated
3389 if (m_inp_mem_ptr) {
3390 DEBUG_PRINT_ERROR("Cannot change arbitrary-bytes-mode since input port is not free!");
3391 return OMX_ErrorUnsupportedSetting;
3392 }
Arun Menon906de572013-06-18 17:01:40 -07003393 if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) {
3394 if (secure_mode) {
3395 arbitrary_bytes = false;
3396 DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session");
3397 eRet = OMX_ErrorUnsupportedSetting;
3398 } else {
3399 arbitrary_bytes = true;
3400 }
3401 } else if (portFmt->nFramePackingFormat ==
3402 OMX_QCOM_FramePacking_OnlyOneCompleteFrame) {
3403 arbitrary_bytes = false;
3404 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003405 DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu",
Arun Menon906de572013-06-18 17:01:40 -07003406 portFmt->nFramePackingFormat);
3407 eRet = OMX_ErrorUnsupportedSetting;
3408 }
3409 } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003410 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003411 if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid &&
3412 portFmt->nMemRegion < OMX_QCOM_MemRegionMax) &&
3413 portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) {
3414 m_out_mem_region_smi = OMX_TRUE;
3415 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003416 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003417 m_use_output_pmem = OMX_TRUE;
3418 }
3419 }
3420 }
3421 }
3422 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003423
Arun Menon906de572013-06-18 17:01:40 -07003424 case OMX_IndexParamStandardComponentRole: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003425 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE);
Arun Menon906de572013-06-18 17:01:40 -07003426 OMX_PARAM_COMPONENTROLETYPE *comp_role;
3427 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003428 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s",
Arun Menon906de572013-06-18 17:01:40 -07003429 comp_role->cRole);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003430
Arun Menon906de572013-06-18 17:01:40 -07003431 if ((m_state == OMX_StateLoaded)&&
3432 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
3433 DEBUG_PRINT_LOW("Set Parameter called in valid state");
3434 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003435 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003436 return OMX_ErrorIncorrectStateOperation;
3437 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003438
Arun Menon906de572013-06-18 17:01:40 -07003439 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3440 if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
3441 strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
3442 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003443 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003444 eRet =OMX_ErrorUnsupportedSetting;
3445 }
3446 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3447 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
3448 strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
3449 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003450 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003451 eRet = OMX_ErrorUnsupportedSetting;
3452 }
3453 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3454 if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
3455 strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
3456 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003457 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003458 eRet =OMX_ErrorUnsupportedSetting;
3459 }
3460 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3461 if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
3462 strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
3463 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003464 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003465 eRet = OMX_ErrorUnsupportedSetting;
3466 }
3467 } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
Deva Ramasubramanianba4534b2013-12-17 15:52:37 -08003468 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311", OMX_MAX_STRINGNAME_SIZE)) ||
3469 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4", OMX_MAX_STRINGNAME_SIZE))
Arun Menon906de572013-06-18 17:01:40 -07003470 ) {
3471 if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) {
3472 strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
3473 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003474 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003475 eRet =OMX_ErrorUnsupportedSetting;
3476 }
3477 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
3478 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
3479 ) {
3480 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) {
3481 strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
3482 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003483 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003484 eRet =OMX_ErrorUnsupportedSetting;
3485 }
3486 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
3487 if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) ||
3488 (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) {
3489 strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
3490 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003491 DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole);
Arun Menon906de572013-06-18 17:01:40 -07003492 eRet = OMX_ErrorUnsupportedSetting;
3493 }
3494 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003495 DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind);
Arun Menon906de572013-06-18 17:01:40 -07003496 eRet = OMX_ErrorInvalidComponentName;
3497 }
3498 break;
3499 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003500
Arun Menon906de572013-06-18 17:01:40 -07003501 case OMX_IndexParamPriorityMgmt: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003502 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003503 if (m_state != OMX_StateLoaded) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003504 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07003505 return OMX_ErrorIncorrectStateOperation;
3506 }
3507 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003508 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu",
Arun Menon906de572013-06-18 17:01:40 -07003509 priorityMgmtype->nGroupID);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003510
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003511 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu",
Arun Menon906de572013-06-18 17:01:40 -07003512 priorityMgmtype->nGroupPriority);
Shalaj Jain273b3e02012-06-22 19:08:03 -07003513
Arun Menon906de572013-06-18 17:01:40 -07003514 m_priority_mgm.nGroupID = priorityMgmtype->nGroupID;
3515 m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003516
Arun Menon906de572013-06-18 17:01:40 -07003517 break;
3518 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003519
Arun Menon906de572013-06-18 17:01:40 -07003520 case OMX_IndexParamCompBufferSupplier: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003521 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003522 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003523 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d",
Arun Menon906de572013-06-18 17:01:40 -07003524 bufferSupplierType->eBufferSupplier);
3525 if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
3526 m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003527
Arun Menon906de572013-06-18 17:01:40 -07003528 else
Shalaj Jain273b3e02012-06-22 19:08:03 -07003529
Arun Menon906de572013-06-18 17:01:40 -07003530 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003531
Arun Menon906de572013-06-18 17:01:40 -07003532 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003533
Arun Menon906de572013-06-18 17:01:40 -07003534 }
3535 case OMX_IndexParamVideoAvc: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003536 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d",
Arun Menon906de572013-06-18 17:01:40 -07003537 paramIndex);
3538 break;
3539 }
3540 case OMX_IndexParamVideoH263: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003541 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d",
Arun Menon906de572013-06-18 17:01:40 -07003542 paramIndex);
3543 break;
3544 }
3545 case OMX_IndexParamVideoMpeg4: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003546 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d",
Arun Menon906de572013-06-18 17:01:40 -07003547 paramIndex);
3548 break;
3549 }
3550 case OMX_IndexParamVideoMpeg2: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003551 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d",
Arun Menon906de572013-06-18 17:01:40 -07003552 paramIndex);
3553 break;
3554 }
3555 case OMX_QcomIndexParamVideoDecoderPictureOrder: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003556 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_DECODER_PICTURE_ORDER);
Arun Menon906de572013-06-18 17:01:40 -07003557 QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder =
3558 (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData;
3559 struct v4l2_control control;
3560 int pic_order,rc=0;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003561 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d",
Arun Menon906de572013-06-18 17:01:40 -07003562 pictureOrder->eOutputPictureOrder);
3563 if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) {
3564 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY;
3565 } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) {
3566 pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3567 time_stamp_dts.set_timestamp_reorder_mode(false);
3568 } else
3569 eRet = OMX_ErrorBadParameter;
3570 if (eRet == OMX_ErrorNone) {
3571 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3572 control.value = pic_order;
3573 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3574 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003575 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003576 eRet = OMX_ErrorUnsupportedSetting;
3577 }
3578 }
3579 break;
3580 }
3581 case OMX_QcomIndexParamConcealMBMapExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003582 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303583 eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false,
3584 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3585 break;
3586 case OMX_QcomIndexParamFrameInfoExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003587 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303588 eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false,
3589 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3590 break;
Arun Menon906de572013-06-18 17:01:40 -07003591 case OMX_QcomIndexParamInterlaceExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003592 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303593 eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false,
3594 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3595 break;
Arun Menon906de572013-06-18 17:01:40 -07003596 case OMX_QcomIndexParamH264TimeInfo:
Praveen Chavan366ded52016-04-11 17:33:02 -07003597 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303598 eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false,
3599 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3600 break;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05303601 case OMX_QcomIndexParamVideoFramePackingExtradata:
Praveen Chavan366ded52016-04-11 17:33:02 -07003602 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303603 eRet = enable_extradata(OMX_FRAMEPACK_EXTRADATA, false,
3604 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3605 break;
3606 case OMX_QcomIndexParamVideoQPExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003607 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303608 eRet = enable_extradata(OMX_QP_EXTRADATA, false,
3609 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3610 break;
3611 case OMX_QcomIndexParamVideoInputBitsInfoExtraData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003612 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303613 eRet = enable_extradata(OMX_BITSINFO_EXTRADATA, false,
3614 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3615 break;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05303616 case OMX_QcomIndexEnableExtnUserData:
Praveen Chavan366ded52016-04-11 17:33:02 -07003617 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05303618 eRet = enable_extradata(OMX_EXTNUSER_EXTRADATA, false,
3619 ((QOMX_ENABLETYPE *)paramData)->bEnable);
3620 break;
Arun Menon906de572013-06-18 17:01:40 -07003621 case OMX_QcomIndexParamVideoDivx: {
3622 QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData;
3623 }
3624 break;
3625 case OMX_QcomIndexPlatformPvt: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003626 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PLATFORMPRIVATE_EXTN);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003627 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port");
Arun Menon906de572013-06-18 17:01:40 -07003628 OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData;
3629 if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
3630 DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type);
3631 eRet = OMX_ErrorUnsupportedSetting;
3632 } else {
3633 m_out_pvt_entry_pmem = OMX_TRUE;
3634 if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003635 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set");
Arun Menon906de572013-06-18 17:01:40 -07003636 m_use_output_pmem = OMX_TRUE;
3637 }
3638 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003639
Arun Menon906de572013-06-18 17:01:40 -07003640 }
3641 break;
3642 case OMX_QcomIndexParamVideoSyncFrameDecodingMode: {
3643 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode");
3644 DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode");
3645 struct v4l2_control control;
3646 int rc;
3647 drv_ctx.idr_only_decoding = 1;
3648 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER;
3649 control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE;
3650 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3651 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003652 DEBUG_PRINT_ERROR("Set picture order failed");
Arun Menon906de572013-06-18 17:01:40 -07003653 eRet = OMX_ErrorUnsupportedSetting;
3654 } else {
3655 control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE;
3656 control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE;
3657 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control);
3658 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003659 DEBUG_PRINT_ERROR("Sync frame setting failed");
Arun Menon906de572013-06-18 17:01:40 -07003660 eRet = OMX_ErrorUnsupportedSetting;
3661 }
3662 /*Setting sync frame decoding on driver might change buffer
3663 * requirements so update them here*/
3664 if (get_buffer_req(&drv_ctx.ip_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003665 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer i/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003666 eRet = OMX_ErrorUnsupportedSetting;
3667 }
3668 if (get_buffer_req(&drv_ctx.op_buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003669 DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer o/p requirements");
Arun Menon906de572013-06-18 17:01:40 -07003670 eRet = OMX_ErrorUnsupportedSetting;
3671 }
3672 }
3673 }
3674 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003675
Arun Menon906de572013-06-18 17:01:40 -07003676 case OMX_QcomIndexParamIndexExtraDataType: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003677 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXEXTRADATATYPE);
Srinu Gorle2eb94e42014-02-14 13:37:40 +05303678 QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData;
3679 if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) &&
3680 (extradataIndexType->bEnabled == OMX_TRUE) &&
3681 (extradataIndexType->nPortIndex == 1)) {
3682 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming");
3683 eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled);
3684 }
3685 }
Arun Menon906de572013-06-18 17:01:40 -07003686 break;
3687 case OMX_QcomIndexParamEnableSmoothStreaming: {
Arun Menonc821d8a2013-06-15 10:03:29 -07003688#ifndef SMOOTH_STREAMING_DISABLED
Praveen Chavancf924182013-12-06 23:16:23 -08003689 eRet = enable_smoothstreaming();
Arun Menonbc0922f2013-06-24 13:02:15 -07003690#else
Arun Menon906de572013-06-18 17:01:40 -07003691 eRet = OMX_ErrorUnsupportedSetting;
Arun Menonc821d8a2013-06-15 10:03:29 -07003692#endif
Arun Menon906de572013-06-18 17:01:40 -07003693 }
3694 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003695#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07003696 /* Need to allow following two set_parameters even in Idle
3697 * state. This is ANDROID architecture which is not in sync
3698 * with openmax standard. */
3699 case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003700 VALIDATE_OMX_PARAM_DATA(paramData, EnableAndroidNativeBuffersParams);
Arun Menon906de572013-06-18 17:01:40 -07003701 EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData;
Praveen Chavan58207a22016-08-17 12:19:29 -07003702 if (enableNativeBuffers->nPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) {
3703 DEBUG_PRINT_ERROR("Enable/Disable android-native-buffers allowed only on output port!");
3704 eRet = OMX_ErrorUnsupportedSetting;
3705 break;
3706 } else if (m_out_mem_ptr) {
3707 DEBUG_PRINT_ERROR("Enable/Disable android-native-buffers is not allowed since Output port is not free !");
3708 eRet = OMX_ErrorInvalidState;
3709 break;
3710 }
Arun Menon906de572013-06-18 17:01:40 -07003711 if (enableNativeBuffers) {
3712 m_enable_android_native_buffers = enableNativeBuffers->enable;
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07003713 }
Praveen Chavancac86402014-10-18 09:14:52 -07003714#if !defined(FLEXYUV_SUPPORTED)
Manikanta Kanamarlapudi78b7fb62014-04-04 11:46:02 -07003715 if (m_enable_android_native_buffers) {
3716 // Use the most-preferred-native-color-format as surface-mode is hinted here
3717 if(!client_buffers.set_color_format(getPreferredColorFormatDefaultMode(0))) {
3718 DEBUG_PRINT_ERROR("Failed to set native color format!");
3719 eRet = OMX_ErrorUnsupportedSetting;
3720 }
Arun Menon906de572013-06-18 17:01:40 -07003721 }
Praveen Chavancac86402014-10-18 09:14:52 -07003722#endif
Arun Menon906de572013-06-18 17:01:40 -07003723 }
3724 break;
3725 case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003726 VALIDATE_OMX_PARAM_DATA(paramData, UseAndroidNativeBufferParams);
Arun Menon906de572013-06-18 17:01:40 -07003727 eRet = use_android_native_buffer(hComp, paramData);
3728 }
3729 break;
Praveen Chavand443c0d2016-04-19 12:25:46 -07003730#if ALLOCATE_OUTPUT_NATIVEHANDLE
3731 case OMX_GoogleAndroidIndexAllocateNativeHandle: {
3732 AllocateNativeHandleParams* allocateNativeHandleParams = (AllocateNativeHandleParams *) paramData;
3733 if (allocateNativeHandleParams != NULL) {
3734 allocate_native_handle = allocateNativeHandleParams->enable;
3735 }
3736 }
3737 break;
3738#endif //ALLOCATE_OUTPUT_NATIVEHANDLE
Shalaj Jain273b3e02012-06-22 19:08:03 -07003739#endif
Arun Menon906de572013-06-18 17:01:40 -07003740 case OMX_QcomIndexParamEnableTimeStampReorder: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003741 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXTIMESTAMPREORDER);
Arun Menon906de572013-06-18 17:01:40 -07003742 QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData;
3743 if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) {
3744 if (reorder->bEnable == OMX_TRUE) {
3745 frm_int =0;
3746 time_stamp_dts.set_timestamp_reorder_mode(true);
3747 } else
3748 time_stamp_dts.set_timestamp_reorder_mode(false);
3749 } else {
3750 time_stamp_dts.set_timestamp_reorder_mode(false);
3751 if (reorder->bEnable == OMX_TRUE) {
3752 eRet = OMX_ErrorUnsupportedSetting;
3753 }
3754 }
3755 }
3756 break;
3757 case OMX_IndexParamVideoProfileLevelCurrent: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003758 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003759 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam =
3760 (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
3761 if (pParam) {
3762 m_profile_lvl.eProfile = pParam->eProfile;
3763 m_profile_lvl.eLevel = pParam->eLevel;
3764 }
3765 break;
Arun Menon888aa852013-05-30 11:24:42 -07003766
Arun Menon906de572013-06-18 17:01:40 -07003767 }
Arun Menone5652482013-08-04 13:33:05 -07003768 case OMX_QcomIndexParamVideoMetaBufferMode:
3769 {
Praveen Chavan366ded52016-04-11 17:33:02 -07003770 VALIDATE_OMX_PARAM_DATA(paramData, StoreMetaDataInBuffersParams);
Arun Menone5652482013-08-04 13:33:05 -07003771 StoreMetaDataInBuffersParams *metabuffer =
3772 (StoreMetaDataInBuffersParams *)paramData;
3773 if (!metabuffer) {
3774 DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer);
3775 eRet = OMX_ErrorBadParameter;
3776 break;
3777 }
3778 if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
Praveen Chavan58207a22016-08-17 12:19:29 -07003779
3780 if (m_out_mem_ptr) {
3781 DEBUG_PRINT_ERROR("Enable/Disable dynamic-buffer-mode is not allowed since Output port is not free !");
3782 eRet = OMX_ErrorInvalidState;
3783 break;
3784 }
Arun Menone5652482013-08-04 13:33:05 -07003785 //set property dynamic buffer mode to driver.
3786 struct v4l2_control control;
3787 struct v4l2_format fmt;
3788 control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT;
3789 if (metabuffer->bStoreMetaData == true) {
3790 control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC;
3791 } else {
3792 control.value = V4L2_MPEG_VIDC_VIDEO_STATIC;
3793 }
3794 int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3795 if (!rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003796 DEBUG_PRINT_HIGH("%s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003797 (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic");
Arun Menonbdb80b02013-08-12 17:45:54 -07003798 dynamic_buf_mode = metabuffer->bStoreMetaData;
Arun Menone5652482013-08-04 13:33:05 -07003799 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003800 DEBUG_PRINT_ERROR("Failed to %s buffer mode",
Arun Menone5652482013-08-04 13:33:05 -07003801 (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic");
3802 eRet = OMX_ErrorUnsupportedSetting;
3803 }
3804 } else {
3805 DEBUG_PRINT_ERROR(
Praveen Chavancf924182013-12-06 23:16:23 -08003806 "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %lu",
Arun Menone5652482013-08-04 13:33:05 -07003807 metabuffer->nPortIndex);
3808 eRet = OMX_ErrorUnsupportedSetting;
3809 }
3810 break;
3811 }
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003812 case OMX_QcomIndexParamVideoDownScalar: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003813 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXDOWNSCALAR);
Praneeth Paladugu42306bb2013-08-27 22:01:28 -07003814 QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData;
3815 struct v4l2_control control;
3816 int rc;
3817 if (pParam) {
3818 is_down_scalar_enabled = pParam->bEnable;
3819 if (is_down_scalar_enabled) {
3820 control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE;
3821 control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY;
3822 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n",
3823 pParam->bEnable);
3824 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3825 if (rc < 0) {
3826 DEBUG_PRINT_ERROR("Failed to set down scalar on driver.");
3827 eRet = OMX_ErrorUnsupportedSetting;
3828 }
3829 control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO;
3830 control.value = 1;
3831 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control);
3832 if (rc < 0) {
3833 DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver.");
3834 eRet = OMX_ErrorUnsupportedSetting;
3835 }
3836 }
3837 }
3838 break;
3839 }
Praveen Chavancf924182013-12-06 23:16:23 -08003840#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
3841 case OMX_QcomIndexParamVideoAdaptivePlaybackMode:
3842 {
Praveen Chavan366ded52016-04-11 17:33:02 -07003843 VALIDATE_OMX_PARAM_DATA(paramData, PrepareForAdaptivePlaybackParams);
Praveen Chavancf924182013-12-06 23:16:23 -08003844 DEBUG_PRINT_LOW("set_parameter: OMX_GoogleAndroidIndexPrepareForAdaptivePlayback");
3845 PrepareForAdaptivePlaybackParams* pParams =
3846 (PrepareForAdaptivePlaybackParams *) paramData;
3847 if (pParams->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) {
3848 if (!pParams->bEnable) {
3849 return OMX_ErrorNone;
3850 }
Deepak Vermaa2efdb12013-12-26 12:30:05 +05303851 if (pParams->nMaxFrameWidth > maxSmoothStreamingWidth
3852 || pParams->nMaxFrameHeight > maxSmoothStreamingHeight) {
Praveen Chavancf924182013-12-06 23:16:23 -08003853 DEBUG_PRINT_ERROR(
3854 "Adaptive playback request exceeds max supported resolution : [%lu x %lu] vs [%lu x %lu]",
3855 pParams->nMaxFrameWidth, pParams->nMaxFrameHeight,
Deepak Vermaa2efdb12013-12-26 12:30:05 +05303856 maxSmoothStreamingWidth, maxSmoothStreamingHeight);
Praveen Chavancf924182013-12-06 23:16:23 -08003857 eRet = OMX_ErrorBadParameter;
3858 } else {
Arun Menon1fc764f2014-04-17 15:41:27 -07003859 eRet = enable_adaptive_playback(pParams->nMaxFrameWidth, pParams->nMaxFrameHeight);
3860 }
Praveen Chavancf924182013-12-06 23:16:23 -08003861 } else {
3862 DEBUG_PRINT_ERROR(
3863 "Prepare for adaptive playback supported only on output port");
3864 eRet = OMX_ErrorBadParameter;
3865 }
3866 break;
3867 }
3868
3869#endif
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303870 case OMX_QcomIndexParamVideoCustomBufferSize:
3871 {
Praveen Chavan366ded52016-04-11 17:33:02 -07003872 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_CUSTOM_BUFFERSIZE);
Pushkaraj Patil8d273cb2014-07-21 10:43:22 +05303873 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoCustomBufferSize");
3874 QOMX_VIDEO_CUSTOM_BUFFERSIZE* pParam = (QOMX_VIDEO_CUSTOM_BUFFERSIZE*)paramData;
3875 if (pParam->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) {
3876 struct v4l2_control control;
3877 control.id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT;
3878 control.value = pParam->nBufferSize;
3879 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
3880 DEBUG_PRINT_ERROR("Failed to set input buffer size");
3881 eRet = OMX_ErrorUnsupportedSetting;
3882 } else {
3883 eRet = get_buffer_req(&drv_ctx.ip_buf);
3884 if (eRet == OMX_ErrorNone) {
3885 m_custom_buffersize.input_buffersize = drv_ctx.ip_buf.buffer_size;
3886 DEBUG_PRINT_HIGH("Successfully set custom input buffer size = %d",
3887 m_custom_buffersize.input_buffersize);
3888 } else {
3889 DEBUG_PRINT_ERROR("Failed to get buffer requirement");
3890 }
3891 }
3892 } else {
3893 DEBUG_PRINT_ERROR("ERROR: Custom buffer size in not supported on output port");
3894 eRet = OMX_ErrorBadParameter;
3895 }
3896 break;
3897 }
Arun Menon906de572013-06-18 17:01:40 -07003898 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003899 DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003900 eRet = OMX_ErrorUnsupportedIndex;
3901 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07003902 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08003903 if (eRet != OMX_ErrorNone)
3904 DEBUG_PRINT_ERROR("set_parameter: Error: 0x%x, setting param 0x%x", eRet, paramIndex);
Arun Menon906de572013-06-18 17:01:40 -07003905 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003906}
3907
3908/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07003909 FUNCTION
3910 omx_vdec::GetConfig
Shalaj Jain273b3e02012-06-22 19:08:03 -07003911
Arun Menon906de572013-06-18 17:01:40 -07003912 DESCRIPTION
3913 OMX Get Config Method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003914
Arun Menon906de572013-06-18 17:01:40 -07003915 PARAMETERS
3916 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003917
Arun Menon906de572013-06-18 17:01:40 -07003918 RETURN VALUE
3919 OMX Error None if successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07003920
Arun Menon906de572013-06-18 17:01:40 -07003921 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07003922OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07003923 OMX_IN OMX_INDEXTYPE configIndex,
3924 OMX_INOUT OMX_PTR configData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07003925{
Arun Menon906de572013-06-18 17:01:40 -07003926 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07003927
Arun Menon906de572013-06-18 17:01:40 -07003928 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003929 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07003930 return OMX_ErrorInvalidState;
3931 }
Arun Menon906de572013-06-18 17:01:40 -07003932
3933 switch ((unsigned long)configIndex) {
3934 case OMX_QcomIndexConfigInterlaced: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003935 VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_CONFIG_INTERLACETYPE);
Arun Menon906de572013-06-18 17:01:40 -07003936 OMX_QCOM_CONFIG_INTERLACETYPE *configFmt =
3937 (OMX_QCOM_CONFIG_INTERLACETYPE *) configData;
3938 if (configFmt->nPortIndex == 1) {
3939 if (configFmt->nIndex == 0) {
3940 configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive;
3941 } else if (configFmt->nIndex == 1) {
3942 configFmt->eInterlaceType =
3943 OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
3944 } else if (configFmt->nIndex == 2) {
3945 configFmt->eInterlaceType =
3946 OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
3947 } else {
3948 DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003949 " NoMore Interlaced formats");
Arun Menon906de572013-06-18 17:01:40 -07003950 eRet = OMX_ErrorNoMore;
3951 }
3952
3953 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003954 DEBUG_PRINT_ERROR("get_config: Bad port index %d queried on only o/p port",
Arun Menon906de572013-06-18 17:01:40 -07003955 (int)configFmt->nPortIndex);
3956 eRet = OMX_ErrorBadPortIndex;
3957 }
3958 break;
3959 }
3960 case OMX_QcomIndexQueryNumberOfVideoDecInstance: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003961 VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_QUERY_DECODER_INSTANCES);
Arun Menon906de572013-06-18 17:01:40 -07003962 QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances =
3963 (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData;
3964 decoderinstances->nNumOfInstances = 16;
3965 /*TODO: How to handle this case */
3966 break;
3967 }
3968 case OMX_QcomIndexConfigVideoFramePackingArrangement: {
3969 if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) {
Praveen Chavan366ded52016-04-11 17:33:02 -07003970 VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_FRAME_PACK_ARRANGEMENT);
Arun Menon906de572013-06-18 17:01:40 -07003971 OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
3972 (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05303973 memcpy(configFmt, &m_frame_pack_arrangement,
3974 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
Arun Menon906de572013-06-18 17:01:40 -07003975 } else {
3976 DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs");
3977 }
3978 break;
3979 }
3980 case OMX_IndexConfigCommonOutputCrop: {
Praveen Chavan366ded52016-04-11 17:33:02 -07003981 VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_RECTTYPE);
Arun Menon906de572013-06-18 17:01:40 -07003982 OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData;
3983 memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE));
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05303984 DEBUG_PRINT_HIGH("get_config: crop info: L: %u, T: %u, R: %u, B: %u",
3985 rectangle.nLeft, rectangle.nTop,
3986 rectangle.nWidth, rectangle.nHeight);
Arun Menon906de572013-06-18 17:01:40 -07003987 break;
3988 }
3989 default: {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07003990 DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex);
Arun Menon906de572013-06-18 17:01:40 -07003991 eRet = OMX_ErrorBadParameter;
3992 }
3993
Shalaj Jain273b3e02012-06-22 19:08:03 -07003994 }
Arun Menon906de572013-06-18 17:01:40 -07003995
3996 return eRet;
3997}
3998
3999/* ======================================================================
4000 FUNCTION
4001 omx_vdec::SetConfig
4002
4003 DESCRIPTION
4004 OMX Set Config method implementation
4005
4006 PARAMETERS
4007 <TBD>.
4008
4009 RETURN VALUE
4010 OMX Error None if successful.
4011 ========================================================================== */
4012OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp,
4013 OMX_IN OMX_INDEXTYPE configIndex,
4014 OMX_IN OMX_PTR configData)
4015{
4016 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004017 DEBUG_PRINT_ERROR("Get Config in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004018 return OMX_ErrorInvalidState;
4019 }
4020
4021 OMX_ERRORTYPE ret = OMX_ErrorNone;
4022 OMX_VIDEO_CONFIG_NALSIZE *pNal;
4023
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004024 DEBUG_PRINT_LOW("Set Config Called");
Arun Menon906de572013-06-18 17:01:40 -07004025
Praveen Chavanefda1e02016-04-11 17:32:32 -07004026 if (configIndex == OMX_IndexConfigVideoNalSize) {
Arun Menon906de572013-06-18 17:01:40 -07004027 struct v4l2_control temp;
4028 temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT;
4029
Praveen Chavan366ded52016-04-11 17:33:02 -07004030 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_NALSIZE);
Arun Menon906de572013-06-18 17:01:40 -07004031 pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData);
4032 switch (pNal->nNaluBytes) {
4033 case 0:
4034 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES;
4035 break;
4036 case 2:
4037 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH;
4038 break;
4039 case 4:
4040 temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH;
4041 break;
4042 default:
4043 return OMX_ErrorUnsupportedSetting;
4044 }
4045
4046 if (!arbitrary_bytes) {
4047 /* In arbitrary bytes mode, the assembler strips out nal size and replaces
4048 * with start code, so only need to notify driver in frame by frame mode */
4049 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) {
4050 DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT");
4051 return OMX_ErrorHardware;
4052 }
4053 }
4054
4055 nal_length = pNal->nNaluBytes;
4056 m_frame_parser.init_nal_length(nal_length);
4057
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004058 DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length);
Arun Menon906de572013-06-18 17:01:40 -07004059 return ret;
Surajit Podderd2644d52013-08-28 17:59:06 +05304060 } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) {
Arun Menon906de572013-06-18 17:01:40 -07004061 OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData;
Surajit Podderd2644d52013-08-28 17:59:06 +05304062 DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps);
Arun Menon906de572013-06-18 17:01:40 -07004063
4064 if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) {
4065 if (config->bEnabled) {
4066 if ((config->nFps >> 16) > 0) {
Surajit Podderd2644d52013-08-28 17:59:06 +05304067 DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu",
Arun Menon906de572013-06-18 17:01:40 -07004068 config->nFps >> 16);
4069 Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator,
4070 drv_ctx.frame_rate.fps_denominator);
4071
4072 if (!drv_ctx.frame_rate.fps_numerator) {
4073 DEBUG_PRINT_ERROR("Numerator is zero setting to 30");
4074 drv_ctx.frame_rate.fps_numerator = 30;
4075 }
4076
4077 if (drv_ctx.frame_rate.fps_denominator) {
4078 drv_ctx.frame_rate.fps_numerator = (int)
4079 drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator;
4080 }
4081
4082 drv_ctx.frame_rate.fps_denominator = 1;
4083 frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 /
4084 drv_ctx.frame_rate.fps_numerator;
4085
4086 struct v4l2_outputparm oparm;
4087 /*XXX: we're providing timing info as seconds per frame rather than frames
4088 * per second.*/
4089 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
4090 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
4091
4092 struct v4l2_streamparm sparm;
4093 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
4094 sparm.parm.output = oparm;
4095 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
4096 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
4097 performance might be affected");
4098 ret = OMX_ErrorHardware;
4099 }
4100 client_set_fps = true;
4101 } else {
4102 DEBUG_PRINT_ERROR("Frame rate not supported.");
4103 ret = OMX_ErrorUnsupportedSetting;
4104 }
4105 } else {
4106 DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate");
4107 client_set_fps = false;
4108 }
4109 } else {
4110 DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d",
4111 (int)config->nPortIndex);
4112 ret = OMX_ErrorBadPortIndex;
4113 }
4114
4115 return ret;
Praveen Chavan898df262015-04-20 18:52:19 -07004116 } else if ((int)configIndex == (int)OMX_IndexConfigPriority) {
4117 OMX_PARAM_U32TYPE *priority = (OMX_PARAM_U32TYPE *)configData;
4118 DEBUG_PRINT_LOW("Set_config: priority %d", priority->nU32);
4119
4120 struct v4l2_control control;
4121
4122 control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY;
4123 if (priority->nU32 == 0)
4124 control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_ENABLE;
4125 else
4126 control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE;
4127
4128 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
4129 DEBUG_PRINT_ERROR("Failed to set Priority");
4130 ret = OMX_ErrorUnsupportedSetting;
4131 }
4132 return ret;
Praveen Chavan281d5022015-04-30 20:28:44 -07004133 } else if ((int)configIndex == (int)OMX_IndexConfigOperatingRate) {
4134 OMX_PARAM_U32TYPE *rate = (OMX_PARAM_U32TYPE *)configData;
4135 DEBUG_PRINT_LOW("Set_config: operating-rate %u fps", rate->nU32 >> 16);
4136
4137 struct v4l2_control control;
4138
4139 control.id = V4L2_CID_MPEG_VIDC_VIDEO_OPERATING_RATE;
4140 control.value = rate->nU32;
4141
4142 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
4143 ret = errno == -EBUSY ? OMX_ErrorInsufficientResources :
4144 OMX_ErrorUnsupportedSetting;
4145 DEBUG_PRINT_ERROR("Failed to set operating rate %u fps (%s)",
4146 rate->nU32 >> 16, errno == -EBUSY ? "HW Overload" : strerror(errno));
4147 }
4148 return ret;
Arun Menon906de572013-06-18 17:01:40 -07004149 }
4150
4151 return OMX_ErrorNotImplemented;
4152}
4153
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304154#define extn_equals(param, extn) (!strncmp(param, extn, strlen(extn)))
4155
Arun Menon906de572013-06-18 17:01:40 -07004156/* ======================================================================
4157 FUNCTION
4158 omx_vdec::GetExtensionIndex
4159
4160 DESCRIPTION
4161 OMX GetExtensionIndex method implementaion. <TBD>
4162
4163 PARAMETERS
4164 <TBD>.
4165
4166 RETURN VALUE
4167 OMX Error None if everything successful.
4168
4169 ========================================================================== */
4170OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp,
4171 OMX_IN OMX_STRING paramName,
4172 OMX_OUT OMX_INDEXTYPE* indexType)
4173{
4174 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004175 DEBUG_PRINT_ERROR("Get Extension Index in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004176 return OMX_ErrorInvalidState;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304177 } else if (extn_equals(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode")) {
Arun Menon906de572013-06-18 17:01:40 -07004178 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304179 } else if (extn_equals(paramName, "OMX.QCOM.index.param.IndexExtraData")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004180 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304181 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_FRAMEPACKING_EXTRADATA)) {
4182 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoFramePackingExtradata;
4183 } else if (extn_equals(paramName, OMX_QCOM_INDEX_CONFIG_VIDEO_FRAMEPACKING_INFO)) {
4184 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoFramePackingArrangement;
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08004185 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_QP_EXTRADATA)) {
4186 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPExtraData;
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08004187 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_INPUTBITSINFO_EXTRADATA)) {
4188 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoInputBitsInfoExtraData;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08004189 } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_EXTNUSER_EXTRADATA)) {
4190 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableExtnUserData;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004191 }
4192#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304193 else if (extn_equals(paramName, "OMX.google.android.index.enableAndroidNativeBuffers")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004194 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304195 } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer2")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004196 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304197 } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer")) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004198 DEBUG_PRINT_ERROR("Extension: %s is supported", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004199 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304200 } else if (extn_equals(paramName, "OMX.google.android.index.getAndroidNativeBufferUsage")) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004201 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage;
4202 }
Praveen Chavand443c0d2016-04-19 12:25:46 -07004203#if ALLOCATE_OUTPUT_NATIVEHANDLE
4204 else if (extn_equals(paramName, "OMX.google.android.index.allocateNativeHandle")) {
4205 *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexAllocateNativeHandle;
4206 }
4207#endif //ALLOCATE_OUTPUT_NATIVEHANDLE
Shalaj Jain273b3e02012-06-22 19:08:03 -07004208#endif
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05304209 else if (extn_equals(paramName, "OMX.google.android.index.storeMetaDataInBuffers")) {
Arun Menone5652482013-08-04 13:33:05 -07004210 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode;
4211 }
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05304212#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
Praveen Chavancf924182013-12-06 23:16:23 -08004213 else if (extn_equals(paramName, "OMX.google.android.index.prepareForAdaptivePlayback")) {
4214 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoAdaptivePlaybackMode;
4215 }
4216#endif
Praveen Chavan09a82b72014-10-18 09:09:45 -07004217#ifdef FLEXYUV_SUPPORTED
4218 else if (extn_equals(paramName,"OMX.google.android.index.describeColorFormat")) {
4219 *indexType = (OMX_INDEXTYPE)OMX_QcomIndexFlexibleYUVDescription;
4220 }
4221#endif
Arun Menon906de572013-06-18 17:01:40 -07004222 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004223 DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004224 return OMX_ErrorNotImplemented;
4225 }
4226 return OMX_ErrorNone;
4227}
4228
4229/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004230 FUNCTION
4231 omx_vdec::GetState
Shalaj Jain273b3e02012-06-22 19:08:03 -07004232
Arun Menon906de572013-06-18 17:01:40 -07004233 DESCRIPTION
4234 Returns the state information back to the caller.<TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07004235
Arun Menon906de572013-06-18 17:01:40 -07004236 PARAMETERS
4237 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004238
Arun Menon906de572013-06-18 17:01:40 -07004239 RETURN VALUE
4240 Error None if everything is successful.
4241 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004242OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004243 OMX_OUT OMX_STATETYPE* state)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004244{
Arun Menon906de572013-06-18 17:01:40 -07004245 *state = m_state;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004246 DEBUG_PRINT_LOW("get_state: Returning the state %d",*state);
Arun Menon906de572013-06-18 17:01:40 -07004247 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004248}
4249
4250/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004251 FUNCTION
4252 omx_vdec::ComponentTunnelRequest
Shalaj Jain273b3e02012-06-22 19:08:03 -07004253
Arun Menon906de572013-06-18 17:01:40 -07004254 DESCRIPTION
4255 OMX Component Tunnel Request method implementation. <TBD>
Shalaj Jain273b3e02012-06-22 19:08:03 -07004256
Arun Menon906de572013-06-18 17:01:40 -07004257 PARAMETERS
4258 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004259
Arun Menon906de572013-06-18 17:01:40 -07004260 RETURN VALUE
4261 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004262
Arun Menon906de572013-06-18 17:01:40 -07004263 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004264OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004265 OMX_IN OMX_U32 port,
4266 OMX_IN OMX_HANDLETYPE peerComponent,
4267 OMX_IN OMX_U32 peerPort,
4268 OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004269{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004270 DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented");
Arun Menon906de572013-06-18 17:01:40 -07004271 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004272}
4273
4274/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004275 FUNCTION
4276 omx_vdec::UseOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004277
Arun Menon906de572013-06-18 17:01:40 -07004278 DESCRIPTION
4279 Helper function for Use buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07004280
Arun Menon906de572013-06-18 17:01:40 -07004281 PARAMETERS
4282 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004283
Arun Menon906de572013-06-18 17:01:40 -07004284 RETURN VALUE
4285 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07004286
Arun Menon906de572013-06-18 17:01:40 -07004287 ========================================================================== */
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004288OMX_ERRORTYPE omx_vdec::allocate_extradata()
4289{
4290#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004291 if (drv_ctx.extradata_info.buffer_size) {
4292 if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) {
4293 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
4294 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4295 free_ion_memory(&drv_ctx.extradata_info.ion);
Praveen Chavan61e5d162013-11-01 02:49:19 -07004296 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Arun Menon906de572013-06-18 17:01:40 -07004297 }
4298 drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095);
4299 drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory(
4300 drv_ctx.extradata_info.size, 4096,
4301 &drv_ctx.extradata_info.ion.ion_alloc_data,
4302 &drv_ctx.extradata_info.ion.fd_ion_data, 0);
4303 if (drv_ctx.extradata_info.ion.ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004304 DEBUG_PRINT_ERROR("Failed to alloc extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07004305 return OMX_ErrorInsufficientResources;
4306 }
4307 drv_ctx.extradata_info.uaddr = (char *)mmap(NULL,
4308 drv_ctx.extradata_info.size,
4309 PROT_READ|PROT_WRITE, MAP_SHARED,
4310 drv_ctx.extradata_info.ion.fd_ion_data.fd , 0);
4311 if (drv_ctx.extradata_info.uaddr == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004312 DEBUG_PRINT_ERROR("Failed to map extradata memory");
Arun Menon906de572013-06-18 17:01:40 -07004313 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4314 free_ion_memory(&drv_ctx.extradata_info.ion);
4315 return OMX_ErrorInsufficientResources;
4316 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004317 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004318#endif
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304319 if (!m_other_extradata) {
4320 m_other_extradata = (OMX_OTHER_EXTRADATATYPE *)malloc(drv_ctx.extradata_info.buffer_size);
4321 if (!m_other_extradata) {
4322 DEBUG_PRINT_ERROR("Failed to alloc memory\n");
4323 return OMX_ErrorInsufficientResources;
4324 }
4325 }
Arun Menon906de572013-06-18 17:01:40 -07004326 return OMX_ErrorNone;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004327}
4328
Arun Menon906de572013-06-18 17:01:40 -07004329void omx_vdec::free_extradata()
4330{
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004331#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07004332 if (drv_ctx.extradata_info.uaddr) {
4333 munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size);
4334 close(drv_ctx.extradata_info.ion.fd_ion_data.fd);
4335 free_ion_memory(&drv_ctx.extradata_info.ion);
4336 }
4337 memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info));
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004338#endif
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304339 if (m_other_extradata) {
4340 free(m_other_extradata);
4341 m_other_extradata = NULL;
4342 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004343}
4344
Shalaj Jain273b3e02012-06-22 19:08:03 -07004345OMX_ERRORTYPE omx_vdec::use_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004346 OMX_IN OMX_HANDLETYPE hComp,
4347 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4348 OMX_IN OMX_U32 port,
4349 OMX_IN OMX_PTR appData,
4350 OMX_IN OMX_U32 bytes,
4351 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004352{
Arun Menon906de572013-06-18 17:01:40 -07004353 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4354 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
4355 unsigned i= 0; // Temporary counter
4356 struct vdec_setbuffer_cmd setbuffers;
4357 OMX_PTR privateAppData = NULL;
4358 private_handle_t *handle = NULL;
4359 OMX_U8 *buff = buffer;
4360 struct v4l2_buffer buf;
4361 struct v4l2_plane plane[VIDEO_MAX_PLANES];
4362 int extra_idx = 0;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004363
Arun Menon906de572013-06-18 17:01:40 -07004364 if (!m_out_mem_ptr) {
4365 DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers");
4366 eRet = allocate_output_headers();
4367 if (eRet == OMX_ErrorNone)
4368 eRet = allocate_extradata();
Sri Karri38569452018-03-16 12:46:14 +05304369 output_use_buffer = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004370 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004371
Arun Menon906de572013-06-18 17:01:40 -07004372 if (eRet == OMX_ErrorNone) {
4373 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
4374 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
4375 break;
4376 }
4377 }
4378 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004379
Arun Menon906de572013-06-18 17:01:40 -07004380 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004381 DEBUG_PRINT_ERROR("Already using %d o/p buffers", drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07004382 eRet = OMX_ErrorInsufficientResources;
4383 }
4384
Arun Menonbdb80b02013-08-12 17:45:54 -07004385 if (dynamic_buf_mode) {
4386 *bufferHdr = (m_out_mem_ptr + i );
4387 (*bufferHdr)->pBuffer = NULL;
4388 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
4389 enum v4l2_buf_type buf_type;
4390 int rr = 0;
4391 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4392 if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
4393 DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr);
4394 return OMX_ErrorInsufficientResources;
4395 } else {
4396 streaming[CAPTURE_PORT] = true;
4397 DEBUG_PRINT_LOW("STREAMON Successful");
4398 }
4399 }
4400 BITMASK_SET(&m_out_bm_count,i);
4401 (*bufferHdr)->pAppPrivate = appData;
4402 (*bufferHdr)->pBuffer = buffer;
4403 (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData);
4404 return eRet;
4405 }
Arun Menon906de572013-06-18 17:01:40 -07004406 if (eRet == OMX_ErrorNone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07004407#if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004408 if (m_enable_android_native_buffers) {
4409 if (m_use_android_native_buffers) {
4410 UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData;
4411 sp<android_native_buffer_t> nBuf = params->nativeBuffer;
4412 handle = (private_handle_t *)nBuf->handle;
4413 privateAppData = params->pAppPrivate;
4414 } else {
4415 handle = (private_handle_t *)buff;
4416 privateAppData = appData;
4417 }
Arun Menon8544ead2014-05-08 17:42:29 -07004418 if (!handle) {
4419 DEBUG_PRINT_ERROR("handle is invalid");
4420 return OMX_ErrorBadParameter;
4421 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004422
Arun Menon906de572013-06-18 17:01:40 -07004423 if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) {
4424 DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback,"
4425 " expected %u, got %lu",
4426 drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size);
4427 return OMX_ErrorBadParameter;
4428 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004429
Deva Ramasubramanian03a5bb92014-04-25 19:03:50 -07004430 drv_ctx.op_buf.buffer_size = handle->size;
4431
Arun Menon906de572013-06-18 17:01:40 -07004432 if (!m_use_android_native_buffers) {
4433 if (!secure_mode) {
4434 buff = (OMX_U8*)mmap(0, handle->size,
4435 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
4436 if (buff == MAP_FAILED) {
4437 DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size);
4438 return OMX_ErrorInsufficientResources;
4439 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07004440 }
4441 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004442#if defined(_ANDROID_ICS_)
Arun Menon906de572013-06-18 17:01:40 -07004443 native_buffer[i].nativehandle = handle;
4444 native_buffer[i].privatehandle = handle;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004445#endif
Arun Menon906de572013-06-18 17:01:40 -07004446 if (!handle) {
4447 DEBUG_PRINT_ERROR("Native Buffer handle is NULL");
4448 return OMX_ErrorBadParameter;
4449 }
4450 drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd;
4451 drv_ctx.ptr_outputbuffer[i].offset = 0;
4452 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4453 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4454 drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size;
4455 } else
4456#endif
4457
4458 if (!ouput_egl_buffers && !m_use_output_pmem) {
4459#ifdef USE_ION
4460 drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
4461 drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment,
4462 &drv_ctx.op_buf_ion_info[i].ion_alloc_data,
4463 &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
4464 if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004465 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 -07004466 return OMX_ErrorInsufficientResources;
4467 }
4468 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4469 drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
4470#else
4471 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4472 open (MEM_DEVICE,O_RDWR);
4473
4474 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004475 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004476 return OMX_ErrorInsufficientResources;
4477 }
4478
4479 /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */
4480 if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) {
4481 drv_ctx.ptr_outputbuffer[i].pmem_fd = \
4482 open (MEM_DEVICE,O_RDWR);
4483 if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004484 DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07004485 return OMX_ErrorInsufficientResources;
4486 }
4487 }
4488
4489 if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd,
4490 drv_ctx.op_buf.buffer_size,
4491 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004492 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07004493 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4494 return OMX_ErrorInsufficientResources;
4495 }
4496#endif
4497 if (!secure_mode) {
4498 drv_ctx.ptr_outputbuffer[i].bufferaddr =
4499 (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size,
4500 PROT_READ|PROT_WRITE, MAP_SHARED,
4501 drv_ctx.ptr_outputbuffer[i].pmem_fd,0);
4502 if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) {
4503 close(drv_ctx.ptr_outputbuffer[i].pmem_fd);
4504#ifdef USE_ION
4505 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
4506#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004507 DEBUG_PRINT_ERROR("Unable to mmap output buffer");
Arun Menon906de572013-06-18 17:01:40 -07004508 return OMX_ErrorInsufficientResources;
4509 }
4510 }
4511 drv_ctx.ptr_outputbuffer[i].offset = 0;
4512 privateAppData = appData;
4513 } else {
4514
4515 DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem);
4516 if (!appData || !bytes ) {
4517 if (!secure_mode && !buffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004518 DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case");
Arun Menon906de572013-06-18 17:01:40 -07004519 return OMX_ErrorBadParameter;
4520 }
4521 }
4522
4523 OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list;
4524 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info;
4525 pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData;
Arun Menon8544ead2014-05-08 17:42:29 -07004526 if (!pmem_list || !pmem_list->entryList || !pmem_list->entryList->entry ||
Arun Menon906de572013-06-18 17:01:40 -07004527 !pmem_list->nEntries ||
4528 pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004529 DEBUG_PRINT_ERROR("Pmem info not valid in use buffer");
Arun Menon906de572013-06-18 17:01:40 -07004530 return OMX_ErrorBadParameter;
4531 }
4532 pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
4533 pmem_list->entryList->entry;
4534 DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx",
4535 pmem_info->pmem_fd);
4536 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd;
4537 drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset;
4538 drv_ctx.ptr_outputbuffer[i].bufferaddr = buff;
4539 drv_ctx.ptr_outputbuffer[i].mmaped_size =
4540 drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size;
4541 privateAppData = appData;
4542 }
4543 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
4544 m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd;
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05304545 m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len;
4546 m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size;
4547 m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr;
Arun Menon906de572013-06-18 17:01:40 -07004548
4549 *bufferHdr = (m_out_mem_ptr + i );
4550 if (secure_mode)
4551 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
4552 //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4553 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i],
4554 sizeof (vdec_bufferpayload));
4555
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004556 DEBUG_PRINT_HIGH("Set the Output Buffer Idx: %d Addr: %p, pmem_fd=0x%x", i,
Arun Menon906de572013-06-18 17:01:40 -07004557 drv_ctx.ptr_outputbuffer[i].bufferaddr,
4558 drv_ctx.ptr_outputbuffer[i].pmem_fd );
4559
4560 buf.index = i;
4561 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4562 buf.memory = V4L2_MEMORY_USERPTR;
4563 plane[0].length = drv_ctx.op_buf.buffer_size;
4564 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
4565 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
4566 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd;
4567 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
4568 plane[0].data_offset = 0;
4569 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
4570 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
4571 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
4572 plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size);
4573#ifdef USE_ION
4574 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
4575#endif
4576 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
4577 plane[extra_idx].data_offset = 0;
4578 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004579 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004580 return OMX_ErrorBadParameter;
4581 }
Arun Menon906de572013-06-18 17:01:40 -07004582 buf.m.planes = plane;
4583 buf.length = drv_ctx.num_planes;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004584
Arun Menon906de572013-06-18 17:01:40 -07004585 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004586 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07004587 /*TODO: How to handle this case */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004588 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004589 }
4590
Arun Menon906de572013-06-18 17:01:40 -07004591 if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) {
4592 enum v4l2_buf_type buf_type;
4593 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
4594 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) {
4595 return OMX_ErrorInsufficientResources;
4596 } else {
4597 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004598 DEBUG_PRINT_LOW("STREAMON Successful");
Shalaj Jain273b3e02012-06-22 19:08:03 -07004599 }
4600 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004601
Arun Menon906de572013-06-18 17:01:40 -07004602 (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size;
4603 if (m_enable_android_native_buffers) {
4604 DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle);
4605 (*bufferHdr)->pBuffer = (OMX_U8 *)handle;
4606 } else {
4607 (*bufferHdr)->pBuffer = buff;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004608 }
Arun Menon906de572013-06-18 17:01:40 -07004609 (*bufferHdr)->pAppPrivate = privateAppData;
4610 BITMASK_SET(&m_out_bm_count,i);
4611 }
4612 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004613}
4614
4615/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004616 FUNCTION
4617 omx_vdec::use_input_heap_buffers
Shalaj Jain273b3e02012-06-22 19:08:03 -07004618
Arun Menon906de572013-06-18 17:01:40 -07004619 DESCRIPTION
4620 OMX Use Buffer Heap allocation method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004621
Arun Menon906de572013-06-18 17:01:40 -07004622 PARAMETERS
4623 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004624
Arun Menon906de572013-06-18 17:01:40 -07004625 RETURN VALUE
4626 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004627
Arun Menon906de572013-06-18 17:01:40 -07004628 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004629OMX_ERRORTYPE omx_vdec::use_input_heap_buffers(
Arun Menon906de572013-06-18 17:01:40 -07004630 OMX_IN OMX_HANDLETYPE hComp,
4631 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4632 OMX_IN OMX_U32 port,
4633 OMX_IN OMX_PTR appData,
4634 OMX_IN OMX_U32 bytes,
4635 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004636{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004637 DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer);
Arun Menon906de572013-06-18 17:01:40 -07004638 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4639 if (!m_inp_heap_ptr)
4640 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*)
4641 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4642 drv_ctx.ip_buf.actualcount);
4643 if (!m_phdr_pmem_ptr)
4644 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**)
4645 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4646 drv_ctx.ip_buf.actualcount);
4647 if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) {
4648 DEBUG_PRINT_ERROR("Insufficent memory");
4649 eRet = OMX_ErrorInsufficientResources;
4650 } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) {
4651 input_use_buffer = true;
4652 memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE));
4653 m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer;
4654 m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes;
4655 m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData;
4656 m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput;
4657 m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax;
4658 *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt];
4659 eRet = allocate_input_buffer(hComp, &m_phdr_pmem_ptr[m_in_alloc_cnt], port, appData, bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004660 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 -07004661 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt],
4662 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004663 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07004664 return OMX_ErrorInsufficientResources;
4665 }
4666 m_in_alloc_cnt++;
4667 } else {
4668 DEBUG_PRINT_ERROR("All i/p buffers have been set!");
4669 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004670 }
Arun Menon906de572013-06-18 17:01:40 -07004671 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004672}
4673
4674/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004675 FUNCTION
4676 omx_vdec::UseBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004677
Arun Menon906de572013-06-18 17:01:40 -07004678 DESCRIPTION
4679 OMX Use Buffer method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004680
Arun Menon906de572013-06-18 17:01:40 -07004681 PARAMETERS
4682 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004683
Arun Menon906de572013-06-18 17:01:40 -07004684 RETURN VALUE
4685 OMX Error None , if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004686
Arun Menon906de572013-06-18 17:01:40 -07004687 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004688OMX_ERRORTYPE omx_vdec::use_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004689 OMX_IN OMX_HANDLETYPE hComp,
4690 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4691 OMX_IN OMX_U32 port,
4692 OMX_IN OMX_PTR appData,
4693 OMX_IN OMX_U32 bytes,
4694 OMX_IN OMX_U8* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004695{
Arun Menon906de572013-06-18 17:01:40 -07004696 OMX_ERRORTYPE error = OMX_ErrorNone;
4697 struct vdec_setbuffer_cmd setbuffers;
4698
Arun Menon8544ead2014-05-08 17:42:29 -07004699 if (bufferHdr == NULL || bytes == 0 || (!secure_mode && buffer == NULL)) {
4700 DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer);
4701 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004702 }
Arun Menon906de572013-06-18 17:01:40 -07004703 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004704 DEBUG_PRINT_ERROR("Use Buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07004705 return OMX_ErrorInvalidState;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004706 }
Praveen Chavan58207a22016-08-17 12:19:29 -07004707 if (port == OMX_CORE_INPUT_PORT_INDEX) {
4708 // If this is not the first allocation (i.e m_inp_mem_ptr is allocated),
4709 // ensure that use-buffer was called for previous allocation.
4710 // Mix-and-match of useBuffer and allocateBuffer is not allowed
4711 if (m_inp_mem_ptr && !input_use_buffer) {
4712 DEBUG_PRINT_ERROR("'Use' Input buffer called after 'Allocate' Input buffer !");
4713 return OMX_ErrorUndefined;
4714 }
Arun Menon906de572013-06-18 17:01:40 -07004715 error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer);
Praveen Chavan58207a22016-08-17 12:19:29 -07004716 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX)
Arun Menon906de572013-06-18 17:01:40 -07004717 error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested
4718 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004719 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07004720 error = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004721 }
Arun Menon906de572013-06-18 17:01:40 -07004722 DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error);
4723 if (error == OMX_ErrorNone) {
4724 if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
4725 // Send the callback now
4726 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
4727 post_event(OMX_CommandStateSet,OMX_StateIdle,
4728 OMX_COMPONENT_GENERATE_EVENT);
4729 }
4730 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated &&
4731 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
4732 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
4733 post_event(OMX_CommandPortEnable,
4734 OMX_CORE_INPUT_PORT_INDEX,
4735 OMX_COMPONENT_GENERATE_EVENT);
4736 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated &&
4737 BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
4738 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
4739 post_event(OMX_CommandPortEnable,
4740 OMX_CORE_OUTPUT_PORT_INDEX,
4741 OMX_COMPONENT_GENERATE_EVENT);
4742 }
4743 }
4744 return error;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004745}
4746
4747OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex,
Arun Menon906de572013-06-18 17:01:40 -07004748 OMX_BUFFERHEADERTYPE *pmem_bufferHdr)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004749{
Arun Menon906de572013-06-18 17:01:40 -07004750 if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) {
4751 if (m_inp_heap_ptr[bufferindex].pBuffer)
4752 free(m_inp_heap_ptr[bufferindex].pBuffer);
4753 m_inp_heap_ptr[bufferindex].pBuffer = NULL;
4754 }
4755 if (pmem_bufferHdr)
4756 free_input_buffer(pmem_bufferHdr);
4757 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004758}
4759
4760OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4761{
Arun Menon906de572013-06-18 17:01:40 -07004762 unsigned int index = 0;
4763 if (bufferHdr == NULL || m_inp_mem_ptr == NULL) {
4764 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004765 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004766
Arun Menon906de572013-06-18 17:01:40 -07004767 index = bufferHdr - m_inp_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004768 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004769
Praveen Chavaneac7fd02016-04-25 10:03:42 -07004770 bufferHdr->pInputPortPrivate = NULL;
4771
Arun Menon906de572013-06-18 17:01:40 -07004772 if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004773 DEBUG_PRINT_LOW("Free Input Buffer index = %d",index);
Arun Menon906de572013-06-18 17:01:40 -07004774 if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) {
4775 struct vdec_setbuffer_cmd setbuffers;
4776 setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT;
4777 memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index],
4778 sizeof (vdec_bufferpayload));
4779 if (!secure_mode) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004780 DEBUG_PRINT_LOW("unmap the input buffer fd=%d",
Arun Menon906de572013-06-18 17:01:40 -07004781 drv_ctx.ptr_inputbuffer[index].pmem_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004782 DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07004783 drv_ctx.ptr_inputbuffer[index].mmaped_size,
4784 drv_ctx.ptr_inputbuffer[index].bufferaddr);
4785 munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr,
4786 drv_ctx.ptr_inputbuffer[index].mmaped_size);
Praveen Chavand443c0d2016-04-19 12:25:46 -07004787 close (drv_ctx.ptr_inputbuffer[index].pmem_fd);
4788 } else if (allocate_native_handle){
4789 native_handle_t *nh = (native_handle_t *)bufferHdr->pBuffer;
4790 native_handle_close(nh);
4791 native_handle_delete(nh);
Arun Menon906de572013-06-18 17:01:40 -07004792 }
Arun Menon906de572013-06-18 17:01:40 -07004793 drv_ctx.ptr_inputbuffer[index].pmem_fd = -1;
4794 if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) {
4795 free(m_desc_buffer_ptr[index].buf_addr);
4796 m_desc_buffer_ptr[index].buf_addr = NULL;
4797 m_desc_buffer_ptr[index].desc_data_size = 0;
4798 }
4799#ifdef USE_ION
4800 free_ion_memory(&drv_ctx.ip_buf_ion_info[index]);
4801#endif
4802 }
4803 }
4804
4805 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004806}
4807
4808OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
4809{
Arun Menon906de572013-06-18 17:01:40 -07004810 unsigned int index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004811
Arun Menon906de572013-06-18 17:01:40 -07004812 if (bufferHdr == NULL || m_out_mem_ptr == NULL) {
4813 return OMX_ErrorBadParameter;
4814 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004815
Arun Menon906de572013-06-18 17:01:40 -07004816 index = bufferHdr - m_out_mem_ptr;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004817 DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004818
Arun Menon906de572013-06-18 17:01:40 -07004819 if (index < drv_ctx.op_buf.actualcount
4820 && drv_ctx.ptr_outputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004821 DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index,
Arun Menon906de572013-06-18 17:01:40 -07004822 drv_ctx.ptr_outputbuffer[index].bufferaddr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004823
Arun Menon906de572013-06-18 17:01:40 -07004824 struct vdec_setbuffer_cmd setbuffers;
4825 setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT;
4826 memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index],
4827 sizeof (vdec_bufferpayload));
Praveen Chavan61e5d162013-11-01 02:49:19 -07004828
4829 if (!dynamic_buf_mode) {
Balamurugan Alagarsamye773c582014-12-17 15:10:25 +05304830 if (streaming[CAPTURE_PORT] &&
4831 !(in_reconfig || BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING))) {
4832 if (stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) {
4833 DEBUG_PRINT_ERROR("STREAMOFF Failed");
4834 } else {
4835 DEBUG_PRINT_LOW("STREAMOFF Successful");
4836 }
4837 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004838#ifdef _ANDROID_
Praveen Chavan61e5d162013-11-01 02:49:19 -07004839 if (m_enable_android_native_buffers) {
Arun Menon906de572013-06-18 17:01:40 -07004840 if (!secure_mode) {
Praveen Chavan61e5d162013-11-01 02:49:19 -07004841 if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) {
4842 munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr,
4843 drv_ctx.ptr_outputbuffer[index].mmaped_size);
4844 }
Arun Menon906de572013-06-18 17:01:40 -07004845 }
Praveen Chavan61e5d162013-11-01 02:49:19 -07004846 drv_ctx.ptr_outputbuffer[index].pmem_fd = -1;
4847 } else {
4848#endif
4849 if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) {
4850 if (!secure_mode) {
4851 DEBUG_PRINT_LOW("\n unmap the output buffer fd = %d",
4852 drv_ctx.ptr_outputbuffer[0].pmem_fd);
4853 DEBUG_PRINT_LOW("\n unmap the ouput buffer size=%d address = %p",
4854 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount,
4855 drv_ctx.ptr_outputbuffer[0].bufferaddr);
4856 munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr,
4857 drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount);
4858 }
4859 close (drv_ctx.ptr_outputbuffer[0].pmem_fd);
4860 drv_ctx.ptr_outputbuffer[0].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004861#ifdef USE_ION
Praveen Chavan61e5d162013-11-01 02:49:19 -07004862 free_ion_memory(&drv_ctx.op_buf_ion_info[0]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004863#endif
Praveen Chavan61e5d162013-11-01 02:49:19 -07004864 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004865#ifdef _ANDROID_
Praveen Chavan61e5d162013-11-01 02:49:19 -07004866 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004867#endif
Praveen Chavan61e5d162013-11-01 02:49:19 -07004868 } //!dynamic_buf_mode
Arun Menon906de572013-06-18 17:01:40 -07004869 if (release_output_done()) {
4870 free_extradata();
4871 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07004872 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004873
Arun Menon906de572013-06-18 17:01:40 -07004874 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004875
4876}
4877
4878OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07004879 OMX_BUFFERHEADERTYPE **bufferHdr,
4880 OMX_U32 port,
4881 OMX_PTR appData,
4882 OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004883{
Arun Menon906de572013-06-18 17:01:40 -07004884 OMX_BUFFERHEADERTYPE *input = NULL;
4885 unsigned char *buf_addr = NULL;
4886 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4887 unsigned i = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004888
Arun Menon906de572013-06-18 17:01:40 -07004889 /* Sanity Check*/
4890 if (bufferHdr == NULL) {
4891 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004892 }
4893
Arun Menon906de572013-06-18 17:01:40 -07004894 if (m_inp_heap_ptr == NULL) {
4895 m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \
4896 calloc( (sizeof(OMX_BUFFERHEADERTYPE)),
4897 drv_ctx.ip_buf.actualcount);
4898 m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \
4899 calloc( (sizeof(OMX_BUFFERHEADERTYPE*)),
4900 drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004901
Arun Menon8544ead2014-05-08 17:42:29 -07004902 if (m_inp_heap_ptr == NULL || m_phdr_pmem_ptr == NULL) {
4903 DEBUG_PRINT_ERROR("m_inp_heap_ptr or m_phdr_pmem_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07004904 return OMX_ErrorInsufficientResources;
4905 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004906 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07004907
Arun Menon906de572013-06-18 17:01:40 -07004908 /*Find a Free index*/
4909 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
4910 if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004911 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07004912 break;
4913 }
4914 }
4915
4916 if (i < drv_ctx.ip_buf.actualcount) {
4917 buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size);
4918
4919 if (buf_addr == NULL) {
4920 return OMX_ErrorInsufficientResources;
4921 }
4922
4923 *bufferHdr = (m_inp_heap_ptr + i);
4924 input = *bufferHdr;
4925 BITMASK_SET(&m_heap_inp_bm_count,i);
4926
4927 input->pBuffer = (OMX_U8 *)buf_addr;
4928 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
4929 input->nVersion.nVersion = OMX_SPEC_VERSION;
4930 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
4931 input->pAppPrivate = appData;
4932 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004933 DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr );
Arun Menon906de572013-06-18 17:01:40 -07004934 eRet = allocate_input_buffer(hComp,&m_phdr_pmem_ptr [i],port,appData,bytes);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004935 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",m_phdr_pmem_ptr[i]);
Arun Menon906de572013-06-18 17:01:40 -07004936 /*Add the Buffers to freeq*/
4937 if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i],
4938 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004939 DEBUG_PRINT_ERROR("ERROR:Free_q is full");
Arun Menon906de572013-06-18 17:01:40 -07004940 return OMX_ErrorInsufficientResources;
4941 }
4942 } else {
4943 return OMX_ErrorBadParameter;
4944 }
4945
4946 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004947
4948}
4949
4950
4951/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07004952 FUNCTION
4953 omx_vdec::AllocateInputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07004954
Arun Menon906de572013-06-18 17:01:40 -07004955 DESCRIPTION
4956 Helper function for allocate buffer in the input pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07004957
Arun Menon906de572013-06-18 17:01:40 -07004958 PARAMETERS
4959 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07004960
Arun Menon906de572013-06-18 17:01:40 -07004961 RETURN VALUE
4962 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07004963
Arun Menon906de572013-06-18 17:01:40 -07004964 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07004965OMX_ERRORTYPE omx_vdec::allocate_input_buffer(
Arun Menon906de572013-06-18 17:01:40 -07004966 OMX_IN OMX_HANDLETYPE hComp,
4967 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
4968 OMX_IN OMX_U32 port,
4969 OMX_IN OMX_PTR appData,
4970 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07004971{
4972
Arun Menon906de572013-06-18 17:01:40 -07004973 OMX_ERRORTYPE eRet = OMX_ErrorNone;
4974 struct vdec_setbuffer_cmd setbuffers;
4975 OMX_BUFFERHEADERTYPE *input = NULL;
4976 unsigned i = 0;
4977 unsigned char *buf_addr = NULL;
4978 int pmem_fd = -1;
Sri Karri38569452018-03-16 12:46:14 +05304979 unsigned int align_size = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004980
Arun Menon906de572013-06-18 17:01:40 -07004981 if (bytes != drv_ctx.ip_buf.buffer_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004982 DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d",
Arun Menon906de572013-06-18 17:01:40 -07004983 bytes, drv_ctx.ip_buf.buffer_size);
4984 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07004985 }
4986
Arun Menon906de572013-06-18 17:01:40 -07004987 if (!m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07004988 DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07004989 drv_ctx.ip_buf.actualcount,
4990 drv_ctx.ip_buf.buffer_size);
Shalaj Jain273b3e02012-06-22 19:08:03 -07004991
Arun Menon906de572013-06-18 17:01:40 -07004992 m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \
4993 calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount);
4994
4995 if (m_inp_mem_ptr == NULL) {
4996 return OMX_ErrorInsufficientResources;
4997 }
4998
4999 drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \
5000 calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount);
5001
5002 if (drv_ctx.ptr_inputbuffer == NULL) {
5003 return OMX_ErrorInsufficientResources;
5004 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005005#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005006 drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \
5007 calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005008
Arun Menon906de572013-06-18 17:01:40 -07005009 if (drv_ctx.ip_buf_ion_info == NULL) {
5010 return OMX_ErrorInsufficientResources;
5011 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005012#endif
5013
Arun Menon906de572013-06-18 17:01:40 -07005014 for (i=0; i < drv_ctx.ip_buf.actualcount; i++) {
5015 drv_ctx.ptr_inputbuffer [i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005016#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005017 drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005018#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07005019 }
5020 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005021
Arun Menon906de572013-06-18 17:01:40 -07005022 for (i=0; i< drv_ctx.ip_buf.actualcount; i++) {
5023 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005024 DEBUG_PRINT_LOW("Free Input Buffer Index %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005025 break;
5026 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005027 }
Arun Menon906de572013-06-18 17:01:40 -07005028
5029 if (i < drv_ctx.ip_buf.actualcount) {
5030 struct v4l2_buffer buf;
5031 struct v4l2_plane plane;
5032 int rc;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005033 DEBUG_PRINT_LOW("Allocate input Buffer");
Arun Menon906de572013-06-18 17:01:40 -07005034#ifdef USE_ION
Sri Karri38569452018-03-16 12:46:14 +05305035 align_size = drv_ctx.ip_buf.buffer_size + 512;
5036 align_size = (align_size + drv_ctx.ip_buf.alignment - 1)&(~(drv_ctx.ip_buf.alignment - 1));
Arun Menon906de572013-06-18 17:01:40 -07005037 drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory(
Sri Karri38569452018-03-16 12:46:14 +05305038 align_size, drv_ctx.op_buf.alignment,
Arun Menon906de572013-06-18 17:01:40 -07005039 &drv_ctx.ip_buf_ion_info[i].ion_alloc_data,
5040 &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0);
5041 if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) {
5042 return OMX_ErrorInsufficientResources;
5043 }
5044 pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd;
5045#else
5046 pmem_fd = open (MEM_DEVICE,O_RDWR);
5047
5048 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005049 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07005050 return OMX_ErrorInsufficientResources;
5051 }
5052
5053 if (pmem_fd == 0) {
5054 pmem_fd = open (MEM_DEVICE,O_RDWR);
5055
5056 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005057 DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer");
Arun Menon906de572013-06-18 17:01:40 -07005058 return OMX_ErrorInsufficientResources;
5059 }
5060 }
5061
5062 if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size,
5063 drv_ctx.ip_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005064 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07005065 close(pmem_fd);
5066 return OMX_ErrorInsufficientResources;
5067 }
5068#endif
5069 if (!secure_mode) {
5070 buf_addr = (unsigned char *)mmap(NULL,
5071 drv_ctx.ip_buf.buffer_size,
5072 PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0);
5073
5074 if (buf_addr == MAP_FAILED) {
5075 close(pmem_fd);
5076#ifdef USE_ION
5077 free_ion_memory(&drv_ctx.ip_buf_ion_info[i]);
5078#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005079 DEBUG_PRINT_ERROR("Map Failed to allocate input buffer");
Arun Menon906de572013-06-18 17:01:40 -07005080 return OMX_ErrorInsufficientResources;
5081 }
5082 }
5083 *bufferHdr = (m_inp_mem_ptr + i);
5084 if (secure_mode)
5085 drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr;
5086 else
5087 drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr;
5088 drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd;
5089 drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size;
5090 drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size;
5091 drv_ctx.ptr_inputbuffer [i].offset = 0;
5092
5093
5094 buf.index = i;
5095 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
5096 buf.memory = V4L2_MEMORY_USERPTR;
5097 plane.bytesused = 0;
5098 plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size;
5099 plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr;
5100 plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd;
5101 plane.reserved[1] = 0;
5102 plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset;
5103 buf.m.planes = &plane;
5104 buf.length = 1;
5105
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005106 DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i,
Arun Menon906de572013-06-18 17:01:40 -07005107 drv_ctx.ptr_inputbuffer[i].bufferaddr);
5108
5109 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
5110
5111 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005112 DEBUG_PRINT_ERROR("Failed to prepare bufs");
Arun Menon906de572013-06-18 17:01:40 -07005113 /*TODO: How to handle this case */
5114 return OMX_ErrorInsufficientResources;
5115 }
5116
5117 input = *bufferHdr;
5118 BITMASK_SET(&m_inp_bm_count,i);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005119 DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr);
Praveen Chavand443c0d2016-04-19 12:25:46 -07005120
5121 if (allocate_native_handle) {
5122 native_handle_t *nh = native_handle_create(1 /*numFds*/, 0 /*numInts*/);
5123 nh->data[0] = drv_ctx.ptr_inputbuffer[i].pmem_fd;
5124 input->pBuffer = (OMX_U8 *)nh;
5125 } else if (secure_mode) {
5126 /*Legacy method, pass ion fd stashed directly in pBuffer*/
5127 input->pBuffer = (OMX_U8 *)(intptr_t)drv_ctx.ptr_inputbuffer[i].pmem_fd;
5128 } else {
Arun Menon906de572013-06-18 17:01:40 -07005129 input->pBuffer = (OMX_U8 *)buf_addr;
Praveen Chavand443c0d2016-04-19 12:25:46 -07005130 }
Arun Menon906de572013-06-18 17:01:40 -07005131 input->nSize = sizeof(OMX_BUFFERHEADERTYPE);
5132 input->nVersion.nVersion = OMX_SPEC_VERSION;
5133 input->nAllocLen = drv_ctx.ip_buf.buffer_size;
5134 input->pAppPrivate = appData;
5135 input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX;
5136 input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i];
5137
5138 if (drv_ctx.disable_dmx) {
5139 eRet = allocate_desc_buffer(i);
5140 }
5141 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005142 DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07005143 eRet = OMX_ErrorInsufficientResources;
5144 }
5145 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005146}
5147
5148
5149/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005150 FUNCTION
5151 omx_vdec::AllocateOutputBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005152
Arun Menon906de572013-06-18 17:01:40 -07005153 DESCRIPTION
5154 Helper fn for AllocateBuffer in the output pin
Shalaj Jain273b3e02012-06-22 19:08:03 -07005155
Arun Menon906de572013-06-18 17:01:40 -07005156 PARAMETERS
5157 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005158
Arun Menon906de572013-06-18 17:01:40 -07005159 RETURN VALUE
5160 OMX Error None if everything went well.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005161
Arun Menon906de572013-06-18 17:01:40 -07005162 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005163OMX_ERRORTYPE omx_vdec::allocate_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07005164 OMX_IN OMX_HANDLETYPE hComp,
5165 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5166 OMX_IN OMX_U32 port,
5167 OMX_IN OMX_PTR appData,
5168 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005169{
Arun Menon906de572013-06-18 17:01:40 -07005170 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5171 OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header
5172 unsigned i= 0; // Temporary counter
5173 struct vdec_setbuffer_cmd setbuffers;
5174 int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005175#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005176 int ion_device_fd =-1;
5177 struct ion_allocation_data ion_alloc_data;
5178 struct ion_fd_data fd_ion_data;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005179#endif
Arun Menon906de572013-06-18 17:01:40 -07005180 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005181 DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)",
Arun Menon906de572013-06-18 17:01:40 -07005182 drv_ctx.op_buf.actualcount,
5183 drv_ctx.op_buf.buffer_size);
5184 int nBufHdrSize = 0;
5185 int nPlatformEntrySize = 0;
5186 int nPlatformListSize = 0;
5187 int nPMEMInfoSize = 0;
5188 int pmem_fd = -1;
5189 unsigned char *pmem_baseaddress = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005190
Arun Menon906de572013-06-18 17:01:40 -07005191 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
5192 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
5193 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005194
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005195 DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07005196 drv_ctx.op_buf.actualcount);
5197 nBufHdrSize = drv_ctx.op_buf.actualcount *
5198 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005199
Arun Menon906de572013-06-18 17:01:40 -07005200 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
5201 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
5202 nPlatformListSize = drv_ctx.op_buf.actualcount *
5203 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
5204 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
5205 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005206
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005207 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07005208 sizeof(OMX_BUFFERHEADERTYPE),
5209 nPMEMInfoSize,
5210 nPlatformListSize);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005211 DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07005212 drv_ctx.op_buf.actualcount);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005213#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005214 ion_device_fd = alloc_map_ion_memory(
5215 drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount,
5216 drv_ctx.op_buf.alignment,
5217 &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0);
5218 if (ion_device_fd < 0) {
5219 return OMX_ErrorInsufficientResources;
5220 }
5221 pmem_fd = fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005222#else
Arun Menon906de572013-06-18 17:01:40 -07005223 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005224
Arun Menon906de572013-06-18 17:01:40 -07005225 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005226 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07005227 drv_ctx.op_buf.buffer_size);
5228 return OMX_ErrorInsufficientResources;
5229 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005230
Arun Menon906de572013-06-18 17:01:40 -07005231 if (pmem_fd == 0) {
5232 pmem_fd = open (MEM_DEVICE,O_RDWR);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005233
Arun Menon906de572013-06-18 17:01:40 -07005234 if (pmem_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005235 DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d",
Arun Menon906de572013-06-18 17:01:40 -07005236 drv_ctx.op_buf.buffer_size);
5237 return OMX_ErrorInsufficientResources;
5238 }
5239 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005240
Arun Menon906de572013-06-18 17:01:40 -07005241 if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size *
5242 drv_ctx.op_buf.actualcount,
5243 drv_ctx.op_buf.alignment)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005244 DEBUG_PRINT_ERROR("align_pmem_buffers() failed");
Arun Menon906de572013-06-18 17:01:40 -07005245 close(pmem_fd);
5246 return OMX_ErrorInsufficientResources;
5247 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005248#endif
Arun Menon906de572013-06-18 17:01:40 -07005249 if (!secure_mode) {
5250 pmem_baseaddress = (unsigned char *)mmap(NULL,
5251 (drv_ctx.op_buf.buffer_size *
5252 drv_ctx.op_buf.actualcount),
5253 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0);
5254 if (pmem_baseaddress == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005255 DEBUG_PRINT_ERROR("MMAP failed for Size %d",
Arun Menon906de572013-06-18 17:01:40 -07005256 drv_ctx.op_buf.buffer_size);
5257 close(pmem_fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005258#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005259 free_ion_memory(&drv_ctx.op_buf_ion_info[i]);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005260#endif
Arun Menon906de572013-06-18 17:01:40 -07005261 return OMX_ErrorInsufficientResources;
5262 }
5263 }
5264 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
5265 // Alloc mem for platform specific info
5266 char *pPtr=NULL;
5267 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
5268 nPMEMInfoSize,1);
5269 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\
5270 calloc (sizeof(struct vdec_bufferpayload),
5271 drv_ctx.op_buf.actualcount);
5272 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
5273 calloc (sizeof (struct vdec_output_frameinfo),
5274 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07005275 if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) {
5276 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer ");
5277 return OMX_ErrorInsufficientResources;
5278 }
5279
Arun Menon906de572013-06-18 17:01:40 -07005280#ifdef USE_ION
5281 drv_ctx.op_buf_ion_info = (struct vdec_ion *)\
5282 calloc (sizeof(struct vdec_ion),
5283 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07005284 if (!drv_ctx.op_buf_ion_info) {
5285 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info");
5286 return OMX_ErrorInsufficientResources;
5287 }
Arun Menon906de572013-06-18 17:01:40 -07005288#endif
5289
5290 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
5291 && drv_ctx.ptr_respbuffer) {
5292 drv_ctx.ptr_outputbuffer[0].mmaped_size =
5293 (drv_ctx.op_buf.buffer_size *
5294 drv_ctx.op_buf.actualcount);
5295 bufHdr = m_out_mem_ptr;
5296 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
5297 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
5298 (((char *) m_platform_list) + nPlatformListSize);
5299 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
5300 (((char *) m_platform_entry) + nPlatformEntrySize);
5301 pPlatformList = m_platform_list;
5302 pPlatformEntry = m_platform_entry;
5303 pPMEMInfo = m_pmem_info;
5304
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005305 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07005306
5307 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005308 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry);
5309 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07005310 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
5311 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
5312 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
5313 // Set the values when we determine the right HxW param
5314 bufHdr->nAllocLen = bytes;
5315 bufHdr->nFilledLen = 0;
5316 bufHdr->pAppPrivate = appData;
5317 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
5318 // Platform specific PMEM Information
5319 // Initialize the Platform Entry
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005320 //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005321 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
5322 pPlatformEntry->entry = pPMEMInfo;
5323 // Initialize the Platform List
5324 pPlatformList->nEntries = 1;
5325 pPlatformList->entryList = pPlatformEntry;
5326 // Keep pBuffer NULL till vdec is opened
5327 bufHdr->pBuffer = NULL;
5328 bufHdr->nOffset = 0;
5329
5330 pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i;
5331 pPMEMInfo->pmem_fd = 0;
5332 bufHdr->pPlatformPrivate = pPlatformList;
5333
5334 drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd;
5335 m_pmem_info[i].pmem_fd = pmem_fd;
5336#ifdef USE_ION
5337 drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd;
5338 drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data;
5339 drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data;
5340#endif
5341
5342 /*Create a mapping between buffers*/
5343 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
5344 drv_ctx.ptr_respbuffer[i].client_data = (void *)\
5345 &drv_ctx.ptr_outputbuffer[i];
5346 drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i;
5347 drv_ctx.ptr_outputbuffer[i].bufferaddr =
5348 pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05305349 m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len;
5350 m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size;
5351 m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr;
Arun Menon906de572013-06-18 17:01:40 -07005352
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005353 DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p",
Arun Menon906de572013-06-18 17:01:40 -07005354 pmem_fd, drv_ctx.ptr_outputbuffer[i].offset,
5355 drv_ctx.ptr_outputbuffer[i].bufferaddr);
5356 // Move the buffer and buffer header pointers
5357 bufHdr++;
5358 pPMEMInfo++;
5359 pPlatformEntry++;
5360 pPlatformList++;
5361 }
5362 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005363 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07005364 m_out_mem_ptr, pPtr);
5365 if (m_out_mem_ptr) {
5366 free(m_out_mem_ptr);
5367 m_out_mem_ptr = NULL;
5368 }
5369 if (pPtr) {
5370 free(pPtr);
5371 pPtr = NULL;
5372 }
5373 if (drv_ctx.ptr_outputbuffer) {
5374 free(drv_ctx.ptr_outputbuffer);
5375 drv_ctx.ptr_outputbuffer = NULL;
5376 }
5377 if (drv_ctx.ptr_respbuffer) {
5378 free(drv_ctx.ptr_respbuffer);
5379 drv_ctx.ptr_respbuffer = NULL;
5380 }
5381#ifdef USE_ION
5382 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005383 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07005384 free(drv_ctx.op_buf_ion_info);
5385 drv_ctx.op_buf_ion_info = NULL;
5386 }
5387#endif
5388 eRet = OMX_ErrorInsufficientResources;
5389 }
5390 if (eRet == OMX_ErrorNone)
5391 eRet = allocate_extradata();
5392 }
5393
5394 for (i=0; i< drv_ctx.op_buf.actualcount; i++) {
5395 if (BITMASK_ABSENT(&m_out_bm_count,i)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005396 DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i);
Arun Menon906de572013-06-18 17:01:40 -07005397 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005398 }
5399 }
Arun Menon906de572013-06-18 17:01:40 -07005400
5401 if (eRet == OMX_ErrorNone) {
5402 if (i < drv_ctx.op_buf.actualcount) {
5403 struct v4l2_buffer buf;
5404 struct v4l2_plane plane[VIDEO_MAX_PLANES];
5405 int rc;
5406 m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset;
5407
5408 drv_ctx.ptr_outputbuffer[i].buffer_len =
5409 drv_ctx.op_buf.buffer_size;
5410
5411 *bufferHdr = (m_out_mem_ptr + i );
5412 if (secure_mode) {
5413 drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr;
5414 }
5415 drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size;
5416
5417 buf.index = i;
5418 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5419 buf.memory = V4L2_MEMORY_USERPTR;
5420 plane[0].length = drv_ctx.op_buf.buffer_size;
5421 plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr -
5422 (unsigned long)drv_ctx.ptr_outputbuffer[i].offset;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005423#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005424 plane[0].reserved[0] = drv_ctx.op_buf_ion_info[i].fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005425#endif
Arun Menon906de572013-06-18 17:01:40 -07005426 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset;
5427 plane[0].data_offset = 0;
5428 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
5429 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
5430 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
5431 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 -07005432#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07005433 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005434#endif
Arun Menon906de572013-06-18 17:01:40 -07005435 plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size;
5436 plane[extra_idx].data_offset = 0;
5437 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005438 DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07005439 return OMX_ErrorBadParameter;
5440 }
5441 buf.m.planes = plane;
5442 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005443 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 -07005444 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf);
5445 if (rc) {
5446 /*TODO: How to handle this case */
5447 return OMX_ErrorInsufficientResources;
5448 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005449
Arun Menon906de572013-06-18 17:01:40 -07005450 if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) {
5451 enum v4l2_buf_type buf_type;
5452 buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
5453 rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
5454 if (rc) {
5455 return OMX_ErrorInsufficientResources;
5456 } else {
5457 streaming[CAPTURE_PORT] = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005458 DEBUG_PRINT_LOW("STREAMON Successful");
Arun Menon906de572013-06-18 17:01:40 -07005459 }
5460 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005461
Arun Menon906de572013-06-18 17:01:40 -07005462 (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr;
5463 (*bufferHdr)->pAppPrivate = appData;
5464 BITMASK_SET(&m_out_bm_count,i);
5465 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005466 DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient");
Arun Menon906de572013-06-18 17:01:40 -07005467 eRet = OMX_ErrorInsufficientResources;
5468 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005469 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005470
Arun Menon906de572013-06-18 17:01:40 -07005471 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005472}
5473
5474
5475// AllocateBuffer -- API Call
5476/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005477 FUNCTION
5478 omx_vdec::AllocateBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005479
Arun Menon906de572013-06-18 17:01:40 -07005480 DESCRIPTION
5481 Returns zero if all the buffers released..
Shalaj Jain273b3e02012-06-22 19:08:03 -07005482
Arun Menon906de572013-06-18 17:01:40 -07005483 PARAMETERS
5484 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005485
Arun Menon906de572013-06-18 17:01:40 -07005486 RETURN VALUE
5487 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005488
Arun Menon906de572013-06-18 17:01:40 -07005489 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005490OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005491 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
5492 OMX_IN OMX_U32 port,
5493 OMX_IN OMX_PTR appData,
5494 OMX_IN OMX_U32 bytes)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005495{
5496 unsigned i = 0;
5497 OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type
5498
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005499 DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port);
Arun Menon906de572013-06-18 17:01:40 -07005500 if (m_state == OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005501 DEBUG_PRINT_ERROR("Allocate Buf in Invalid State");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005502 return OMX_ErrorInvalidState;
5503 }
5504
Arun Menon906de572013-06-18 17:01:40 -07005505 if (port == OMX_CORE_INPUT_PORT_INDEX) {
Praveen Chavan58207a22016-08-17 12:19:29 -07005506 // If this is not the first allocation (i.e m_inp_mem_ptr is allocated),
5507 // ensure that use-buffer was never called.
5508 // Mix-and-match of useBuffer and allocateBuffer is not allowed
5509 if (m_inp_mem_ptr && input_use_buffer) {
5510 DEBUG_PRINT_ERROR("'Allocate' Input buffer called after 'Use' Input buffer !");
5511 return OMX_ErrorUndefined;
5512 }
Arun Menon906de572013-06-18 17:01:40 -07005513 if (arbitrary_bytes) {
5514 eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes);
5515 } else {
5516 eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes);
5517 }
5518 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Sri Karri38569452018-03-16 12:46:14 +05305519 if (output_use_buffer) {
5520 DEBUG_PRINT_ERROR("Allocate output buffer not allowed after use buffer");
5521 return OMX_ErrorBadParameter;
5522 }
Vinay Kaliada4f4422013-01-09 10:45:03 -08005523 eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port,
5524 appData,bytes);
Arun Menon906de572013-06-18 17:01:40 -07005525 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005526 DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port);
Arun Menon906de572013-06-18 17:01:40 -07005527 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005528 }
5529 DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done");
Arun Menon906de572013-06-18 17:01:40 -07005530 if (eRet == OMX_ErrorNone) {
5531 if (allocate_done()) {
5532 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005533 // Send the callback now
5534 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
5535 post_event(OMX_CommandStateSet,OMX_StateIdle,
Arun Menon906de572013-06-18 17:01:40 -07005536 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005537 }
5538 }
Arun Menon906de572013-06-18 17:01:40 -07005539 if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) {
5540 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) {
5541 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
5542 post_event(OMX_CommandPortEnable,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005543 OMX_CORE_INPUT_PORT_INDEX,
5544 OMX_COMPONENT_GENERATE_EVENT);
Arun Menon906de572013-06-18 17:01:40 -07005545 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005546 }
Arun Menon906de572013-06-18 17:01:40 -07005547 if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) {
5548 if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) {
5549 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005550 post_event(OMX_CommandPortEnable,
Arun Menon906de572013-06-18 17:01:40 -07005551 OMX_CORE_OUTPUT_PORT_INDEX,
5552 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005553 }
5554 }
5555 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005556 DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005557 return eRet;
5558}
5559
5560// Free Buffer - API call
5561/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005562 FUNCTION
5563 omx_vdec::FreeBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005564
Arun Menon906de572013-06-18 17:01:40 -07005565 DESCRIPTION
Shalaj Jain273b3e02012-06-22 19:08:03 -07005566
Arun Menon906de572013-06-18 17:01:40 -07005567 PARAMETERS
5568 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005569
Arun Menon906de572013-06-18 17:01:40 -07005570 RETURN VALUE
5571 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07005572
Arun Menon906de572013-06-18 17:01:40 -07005573 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005574OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005575 OMX_IN OMX_U32 port,
5576 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005577{
5578 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5579 unsigned int nPortIndex;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005580 DEBUG_PRINT_LOW("In for decoder free_buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005581
Sri Karri38569452018-03-16 12:46:14 +05305582 auto_lock l(buf_lock);
Arun Menon906de572013-06-18 17:01:40 -07005583 if (m_state == OMX_StateIdle &&
5584 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005585 DEBUG_PRINT_LOW(" free buffer while Component in Loading pending");
Arun Menon906de572013-06-18 17:01:40 -07005586 } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)||
5587 (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005588 DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port);
Arun Menon906de572013-06-18 17:01:40 -07005589 } else if ((port == OMX_CORE_INPUT_PORT_INDEX &&
5590 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) ||
5591 (port == OMX_CORE_OUTPUT_PORT_INDEX &&
5592 BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005593 DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port);
Arun Menon906de572013-06-18 17:01:40 -07005594 } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005595 DEBUG_PRINT_ERROR("Invalid state to free buffer,ports need to be disabled");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005596 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005597 OMX_ErrorPortUnpopulated,
5598 OMX_COMPONENT_GENERATE_EVENT);
Sri Karri38569452018-03-16 12:46:14 +05305599 m_buffer_error = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005600 return OMX_ErrorIncorrectStateOperation;
Arun Menon906de572013-06-18 17:01:40 -07005601 } else if (m_state != OMX_StateInvalid) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005602 DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005603 post_event(OMX_EventError,
Arun Menon906de572013-06-18 17:01:40 -07005604 OMX_ErrorPortUnpopulated,
5605 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005606 }
5607
Arun Menon906de572013-06-18 17:01:40 -07005608 if (port == OMX_CORE_INPUT_PORT_INDEX) {
5609 /*Check if arbitrary bytes*/
5610 if (!arbitrary_bytes && !input_use_buffer)
5611 nPortIndex = buffer - m_inp_mem_ptr;
5612 else
5613 nPortIndex = buffer - m_inp_heap_ptr;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005614
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005615 DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %d", nPortIndex);
Praveen Chavan88256fe2016-04-11 17:32:45 -07005616 if (nPortIndex < drv_ctx.ip_buf.actualcount &&
5617 BITMASK_PRESENT(&m_inp_bm_count, nPortIndex)) {
Arun Menon906de572013-06-18 17:01:40 -07005618 // Clear the bit associated with it.
5619 BITMASK_CLEAR(&m_inp_bm_count,nPortIndex);
5620 BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex);
5621 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005622
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005623 DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005624 if (m_phdr_pmem_ptr)
5625 free_input_buffer(m_phdr_pmem_ptr[nPortIndex]);
5626 } else {
5627 if (arbitrary_bytes) {
5628 if (m_phdr_pmem_ptr)
5629 free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]);
5630 else
5631 free_input_buffer(nPortIndex,NULL);
5632 } else
5633 free_input_buffer(buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005634 }
Arun Menon906de572013-06-18 17:01:40 -07005635 m_inp_bPopulated = OMX_FALSE;
Surajit Podder12aefac2013-08-06 18:43:32 +05305636 if(release_input_done())
5637 release_buffers(this, VDEC_BUFFER_TYPE_INPUT);
Arun Menon906de572013-06-18 17:01:40 -07005638 /*Free the Buffer Header*/
5639 if (release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005640 DEBUG_PRINT_HIGH("ALL input buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07005641 free_input_buffer_header();
5642 }
5643 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005644 DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005645 eRet = OMX_ErrorBadPortIndex;
5646 }
5647
Arun Menon906de572013-06-18 17:01:40 -07005648 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING)
5649 && release_input_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005650 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005651 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING);
5652 post_event(OMX_CommandPortDisable,
Arun Menon906de572013-06-18 17:01:40 -07005653 OMX_CORE_INPUT_PORT_INDEX,
5654 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005655 }
Arun Menon906de572013-06-18 17:01:40 -07005656 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005657 // check if the buffer is valid
Vinay Kaliada4f4422013-01-09 10:45:03 -08005658 nPortIndex = buffer - client_buffers.get_il_buf_hdr();
Praveen Chavan88256fe2016-04-11 17:32:45 -07005659 if (nPortIndex < drv_ctx.op_buf.actualcount &&
5660 BITMASK_PRESENT(&m_out_bm_count, nPortIndex)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005661 DEBUG_PRINT_LOW("free_buffer on o/p port - Port idx %d", nPortIndex);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005662 // Clear the bit associated with it.
5663 BITMASK_CLEAR(&m_out_bm_count,nPortIndex);
5664 m_out_bPopulated = OMX_FALSE;
Vinay Kaliada4f4422013-01-09 10:45:03 -08005665 client_buffers.free_output_buffer (buffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005666
Surajit Podder12aefac2013-08-06 18:43:32 +05305667 if(release_output_done()) {
5668 release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT);
5669 }
Arun Menon906de572013-06-18 17:01:40 -07005670 if (release_output_done()) {
5671 free_output_buffer_header();
Shalaj Jain273b3e02012-06-22 19:08:03 -07005672 }
Arun Menon906de572013-06-18 17:01:40 -07005673 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005674 DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005675 eRet = OMX_ErrorBadPortIndex;
5676 }
Arun Menon906de572013-06-18 17:01:40 -07005677 if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING)
5678 && release_output_done()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005679 DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it");
Shalaj Jain273b3e02012-06-22 19:08:03 -07005680
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005681 DEBUG_PRINT_LOW("MOVING TO DISABLED STATE");
Arun Menon906de572013-06-18 17:01:40 -07005682 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005683#ifdef _ANDROID_ICS_
Arun Menon906de572013-06-18 17:01:40 -07005684 if (m_enable_android_native_buffers) {
5685 DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers");
5686 memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
5687 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005688#endif
5689
Arun Menon906de572013-06-18 17:01:40 -07005690 post_event(OMX_CommandPortDisable,
5691 OMX_CORE_OUTPUT_PORT_INDEX,
5692 OMX_COMPONENT_GENERATE_EVENT);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005693 }
Arun Menon906de572013-06-18 17:01:40 -07005694 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005695 eRet = OMX_ErrorBadPortIndex;
5696 }
Arun Menon906de572013-06-18 17:01:40 -07005697 if ((eRet == OMX_ErrorNone) &&
5698 (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) {
5699 if (release_done()) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07005700 // Send the callback now
5701 BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING);
5702 post_event(OMX_CommandStateSet, OMX_StateLoaded,
Arun Menon906de572013-06-18 17:01:40 -07005703 OMX_COMPONENT_GENERATE_EVENT);
Sri Karri38569452018-03-16 12:46:14 +05305704 m_buffer_error = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005705 }
5706 }
5707 return eRet;
5708}
5709
5710
5711/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005712 FUNCTION
5713 omx_vdec::EmptyThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07005714
Arun Menon906de572013-06-18 17:01:40 -07005715 DESCRIPTION
5716 This routine is used to push the encoded video frames to
5717 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005718
Arun Menon906de572013-06-18 17:01:40 -07005719 PARAMETERS
5720 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005721
Arun Menon906de572013-06-18 17:01:40 -07005722 RETURN VALUE
5723 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005724
Arun Menon906de572013-06-18 17:01:40 -07005725 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005726OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005727 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005728{
Arun Menon906de572013-06-18 17:01:40 -07005729 OMX_ERRORTYPE ret1 = OMX_ErrorNone;
5730 unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005731
Praveen Chavaneac7fd02016-04-25 10:03:42 -07005732 if (m_state != OMX_StateExecuting &&
5733 m_state != OMX_StatePause &&
5734 m_state != OMX_StateIdle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005735 DEBUG_PRINT_ERROR("Empty this buffer in Invalid State");
Arun Menon906de572013-06-18 17:01:40 -07005736 return OMX_ErrorInvalidState;
5737 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005738
Arun Menon906de572013-06-18 17:01:40 -07005739 if (buffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005740 DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL");
Arun Menon906de572013-06-18 17:01:40 -07005741 return OMX_ErrorBadParameter;
5742 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005743
Arun Menon906de572013-06-18 17:01:40 -07005744 if (!m_inp_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005745 DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07005746 return OMX_ErrorIncorrectStateOperation;
5747 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005748
Arun Menon906de572013-06-18 17:01:40 -07005749 if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005750 DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07005751 return OMX_ErrorBadPortIndex;
5752 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005753
Arun Menon906de572013-06-18 17:01:40 -07005754 if (perf_flag) {
5755 if (!latency) {
5756 dec_time.stop();
5757 latency = dec_time.processing_time_us();
5758 dec_time.start();
5759 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005760 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005761
Arun Menon906de572013-06-18 17:01:40 -07005762 if (arbitrary_bytes) {
5763 nBufferIndex = buffer - m_inp_heap_ptr;
5764 } else {
5765 if (input_use_buffer == true) {
5766 nBufferIndex = buffer - m_inp_heap_ptr;
Praveen Chavan58207a22016-08-17 12:19:29 -07005767 if (nBufferIndex >= drv_ctx.ip_buf.actualcount ) {
5768 DEBUG_PRINT_ERROR("ERROR: ETB nBufferIndex is invalid in use-buffer mode");
5769 return OMX_ErrorBadParameter;
5770 }
Arun Menon906de572013-06-18 17:01:40 -07005771 m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen;
5772 m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp;
5773 m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags;
5774 buffer = &m_inp_mem_ptr[nBufferIndex];
5775 DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu",
5776 &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen);
5777 } else {
5778 nBufferIndex = buffer - m_inp_mem_ptr;
5779 }
5780 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005781
Praveen Chavan58207a22016-08-17 12:19:29 -07005782 if (nBufferIndex >= drv_ctx.ip_buf.actualcount ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005783 DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005784 return OMX_ErrorBadParameter;
5785 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005786
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07005787 if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
5788 codec_config_flag = true;
5789 DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__);
5790 }
5791
Arun Menon906de572013-06-18 17:01:40 -07005792 DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)",
5793 buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen);
5794 if (arbitrary_bytes) {
5795 post_event ((unsigned)hComp,(unsigned)buffer,
Shalaj Jain273b3e02012-06-22 19:08:03 -07005796 OMX_COMPONENT_GENERATE_ETB_ARBITRARY);
Arun Menon906de572013-06-18 17:01:40 -07005797 } else {
Arun Menon906de572013-06-18 17:01:40 -07005798 post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB);
5799 }
Praveen Chavanece713f2014-12-10 18:00:04 -08005800 time_stamp_dts.insert_timestamp(buffer);
Arun Menon906de572013-06-18 17:01:40 -07005801 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005802}
5803
5804/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07005805 FUNCTION
5806 omx_vdec::empty_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07005807
Arun Menon906de572013-06-18 17:01:40 -07005808 DESCRIPTION
5809 This routine is used to push the encoded video frames to
5810 the video decoder.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005811
Arun Menon906de572013-06-18 17:01:40 -07005812 PARAMETERS
5813 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005814
Arun Menon906de572013-06-18 17:01:40 -07005815 RETURN VALUE
5816 OMX Error None if everything went successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07005817
Arun Menon906de572013-06-18 17:01:40 -07005818 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07005819OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07005820 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07005821{
Arun Menon906de572013-06-18 17:01:40 -07005822 int push_cnt = 0,i=0;
5823 unsigned nPortIndex = 0;
5824 OMX_ERRORTYPE ret = OMX_ErrorNone;
5825 struct vdec_input_frameinfo frameinfo;
5826 struct vdec_bufferpayload *temp_buffer;
5827 struct vdec_seqheader seq_header;
5828 bool port_setting_changed = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005829
Arun Menon906de572013-06-18 17:01:40 -07005830 /*Should we generate a Aync error event*/
5831 if (buffer == NULL || buffer->pInputPortPrivate == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005832 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid");
Arun Menon906de572013-06-18 17:01:40 -07005833 return OMX_ErrorBadParameter;
5834 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005835
Arun Menon906de572013-06-18 17:01:40 -07005836 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005837
Praveen Chavan58207a22016-08-17 12:19:29 -07005838 if (nPortIndex >= drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005839 DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]",
Arun Menon906de572013-06-18 17:01:40 -07005840 nPortIndex);
5841 return OMX_ErrorBadParameter;
5842 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005843
Arun Menon906de572013-06-18 17:01:40 -07005844 pending_input_buffers++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005845
Arun Menon906de572013-06-18 17:01:40 -07005846 /* return zero length and not an EOS buffer */
5847 if (!arbitrary_bytes && (buffer->nFilledLen == 0) &&
5848 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005849 DEBUG_PRINT_HIGH("return zero legth buffer");
Arun Menon906de572013-06-18 17:01:40 -07005850 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5851 OMX_COMPONENT_GENERATE_EBD);
5852 return OMX_ErrorNone;
5853 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005854
c_sridur0af9cef2015-02-05 12:07:17 +05305855 if (input_flush_progress == true) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005856 DEBUG_PRINT_LOW("Flush in progress return buffer ");
Arun Menon906de572013-06-18 17:01:40 -07005857 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,
5858 OMX_COMPONENT_GENERATE_EBD);
5859 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005860 }
5861
Praveen Chavaneac7fd02016-04-25 10:03:42 -07005862 auto_lock l(buf_lock);
Arun Menon906de572013-06-18 17:01:40 -07005863 temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate;
Shalaj Jain273b3e02012-06-22 19:08:03 -07005864
Praveen Chavaneac7fd02016-04-25 10:03:42 -07005865 if (!temp_buffer || (temp_buffer - drv_ctx.ptr_inputbuffer) > (int)drv_ctx.ip_buf.actualcount) {
Arun Menon906de572013-06-18 17:01:40 -07005866 return OMX_ErrorBadParameter;
5867 }
Sri Karri38569452018-03-16 12:46:14 +05305868 if (BITMASK_ABSENT(&m_inp_bm_count, nPortIndex) || m_buffer_error) {
5869 DEBUG_PRINT_ERROR("ETBProxy: ERROR: invalid buffer, nPortIndex %u", nPortIndex);
5870 return OMX_ErrorBadParameter;
5871 }
Arun Menon906de572013-06-18 17:01:40 -07005872 /* If its first frame, H264 codec and reject is true, then parse the nal
5873 and get the profile. Based on this, reject the clip playback */
5874 if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 &&
5875 m_reject_avc_1080p_mp) {
5876 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005877 DEBUG_PRINT_ERROR("Parse nal to get the profile");
Arun Menon906de572013-06-18 17:01:40 -07005878 h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen,
5879 NALU_TYPE_SPS);
5880 m_profile = h264_parser->get_profile();
5881 ret = is_video_session_supported();
5882 if (ret) {
5883 post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD);
5884 post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT);
5885 /* Move the state to Invalid to avoid queueing of pending ETB to the driver */
5886 m_state = OMX_StateInvalid;
5887 return OMX_ErrorNone;
5888 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005889 }
5890
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005891 DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
Arun Menon906de572013-06-18 17:01:40 -07005892 /*for use buffer we need to memcpy the data*/
5893 temp_buffer->buffer_len = buffer->nFilledLen;
5894
Praveen Chavaneac7fd02016-04-25 10:03:42 -07005895 if (input_use_buffer && temp_buffer->bufferaddr) {
Arun Menon906de572013-06-18 17:01:40 -07005896 if (buffer->nFilledLen <= temp_buffer->buffer_len) {
5897 if (arbitrary_bytes) {
5898 memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen);
5899 } else {
5900 memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset),
5901 buffer->nFilledLen);
5902 }
5903 } else {
5904 return OMX_ErrorBadParameter;
5905 }
5906
5907 }
5908
5909 frameinfo.bufferaddr = temp_buffer->bufferaddr;
5910 frameinfo.client_data = (void *) buffer;
5911 frameinfo.datalen = temp_buffer->buffer_len;
5912 frameinfo.flags = 0;
5913 frameinfo.offset = buffer->nOffset;
5914 frameinfo.pmem_fd = temp_buffer->pmem_fd;
5915 frameinfo.pmem_offset = temp_buffer->offset;
5916 frameinfo.timestamp = buffer->nTimeStamp;
5917 if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) {
5918 DEBUG_PRINT_LOW("ETB: dmx enabled");
5919 if (m_demux_entries == 0) {
5920 extract_demux_addr_offsets(buffer);
5921 }
5922
5923 DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries);
5924 handle_demux_data(buffer);
5925 frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr;
5926 frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size;
5927 } else {
5928 frameinfo.desc_addr = NULL;
5929 frameinfo.desc_size = 0;
5930 }
5931 if (!arbitrary_bytes) {
5932 frameinfo.flags |= buffer->nFlags;
5933 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005934
5935#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07005936 if (m_debug_timestamp) {
5937 if (arbitrary_bytes) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005938 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005939 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5940 } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005941 DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07005942 m_timestamp_list.insert_ts(buffer->nTimeStamp);
5943 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005944 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005945#endif
5946
Praveen Chavand443c0d2016-04-19 12:25:46 -07005947 log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len);
Shalaj Jain273b3e02012-06-22 19:08:03 -07005948
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07005949if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Arun Menon906de572013-06-18 17:01:40 -07005950 frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5951 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
5952 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07005953
Arun Menon906de572013-06-18 17:01:40 -07005954 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005955 DEBUG_PRINT_HIGH("Rxd i/p EOS, Notify Driver that EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07005956 frameinfo.flags |= VDEC_BUFFERFLAG_EOS;
5957 h264_scratch.nFilledLen = 0;
5958 nal_count = 0;
5959 look_ahead_nal = false;
5960 frame_count = 0;
5961 if (m_frame_parser.mutils)
5962 m_frame_parser.mutils->initialize_frame_checking_environment();
5963 m_frame_parser.flush();
5964 h264_last_au_ts = LLONG_MAX;
5965 h264_last_au_flags = 0;
5966 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
5967 m_demux_entries = 0;
5968 }
5969 struct v4l2_buffer buf;
5970 struct v4l2_plane plane;
5971 memset( (void *)&buf, 0, sizeof(buf));
5972 memset( (void *)&plane, 0, sizeof(plane));
5973 int rc;
5974 unsigned long print_count;
5975 if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07005976 buf.flags = V4L2_QCOM_BUF_FLAG_EOS;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07005977 DEBUG_PRINT_HIGH("INPUT EOS reached") ;
Arun Menon906de572013-06-18 17:01:40 -07005978 }
5979 OMX_ERRORTYPE eRet = OMX_ErrorNone;
5980 buf.index = nPortIndex;
5981 buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
5982 buf.memory = V4L2_MEMORY_USERPTR;
5983 plane.bytesused = temp_buffer->buffer_len;
5984 plane.length = drv_ctx.ip_buf.buffer_size;
5985 plane.m.userptr = (unsigned long)temp_buffer->bufferaddr -
5986 (unsigned long)temp_buffer->offset;
5987 plane.reserved[0] = temp_buffer->pmem_fd;
5988 plane.reserved[1] = temp_buffer->offset;
5989 plane.data_offset = 0;
5990 buf.m.planes = &plane;
5991 buf.length = 1;
5992 if (frameinfo.timestamp >= LLONG_MAX) {
5993 buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID;
5994 }
5995 //assumption is that timestamp is in milliseconds
5996 buf.timestamp.tv_sec = frameinfo.timestamp / 1000000;
5997 buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000);
5998 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0;
5999 buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_DECODEONLY) ? V4L2_QCOM_BUF_FLAG_DECODEONLY: 0;
Deva Ramasubramanian46a17952012-08-24 11:35:26 -07006000
Pushkaraj Patil20bd6bf2014-12-22 19:33:08 +05306001 if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
6002 DEBUG_PRINT_LOW("Increment codec_config buffer counter");
6003 android_atomic_inc(&m_queued_codec_config_count);
6004 }
6005
Arun Menon906de572013-06-18 17:01:40 -07006006 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
6007 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006008 DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver");
Arun Menon906de572013-06-18 17:01:40 -07006009 return OMX_ErrorHardware;
6010 }
Deva Ramasubramanian1fd93812014-03-26 15:17:15 -07006011
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07006012 if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
6013 codec_config_flag = false;
6014 }
Arun Menon906de572013-06-18 17:01:40 -07006015 if (!streaming[OUTPUT_PORT]) {
6016 enum v4l2_buf_type buf_type;
6017 int ret,r;
Vinay Kalia85793762012-06-14 19:12:34 -07006018
Arun Menon906de572013-06-18 17:01:40 -07006019 buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006020 DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing");
Arun Menon906de572013-06-18 17:01:40 -07006021 ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type);
6022 if (!ret) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006023 DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful");
Arun Menon906de572013-06-18 17:01:40 -07006024 streaming[OUTPUT_PORT] = true;
Jia Meng1e236c82014-04-03 10:54:39 +08006025 } else if (errno == EBUSY) {
6026 DEBUG_PRINT_ERROR("Failed to call stream on OUTPUT due to HW_OVERLOAD");
6027 post_event ((unsigned int)buffer, VDEC_S_SUCCESS,
6028 OMX_COMPONENT_GENERATE_EBD);
6029 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006030 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006031 DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT");
Arun Menon906de572013-06-18 17:01:40 -07006032 DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued");
Jia Meng1e236c82014-04-03 10:54:39 +08006033 post_event ((unsigned int)buffer, VDEC_S_SUCCESS,
Arun Menon906de572013-06-18 17:01:40 -07006034 OMX_COMPONENT_GENERATE_EBD);
6035 return OMX_ErrorBadParameter;
6036 }
6037 }
6038 DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)",
6039 frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006040
Arun Menon906de572013-06-18 17:01:40 -07006041 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006042}
6043
6044/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006045 FUNCTION
6046 omx_vdec::FillThisBuffer
Shalaj Jain273b3e02012-06-22 19:08:03 -07006047
Arun Menon906de572013-06-18 17:01:40 -07006048 DESCRIPTION
6049 IL client uses this method to release the frame buffer
6050 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006051
Arun Menon906de572013-06-18 17:01:40 -07006052 PARAMETERS
6053 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006054
Arun Menon906de572013-06-18 17:01:40 -07006055 RETURN VALUE
6056 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006057
Arun Menon906de572013-06-18 17:01:40 -07006058 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006059OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006060 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006061{
Praveen Chavaneac7fd02016-04-25 10:03:42 -07006062 if (m_state != OMX_StateExecuting &&
6063 m_state != OMX_StatePause &&
6064 m_state != OMX_StateIdle) {
6065 DEBUG_PRINT_ERROR("FTB in Invalid State");
6066 return OMX_ErrorInvalidState;
6067 }
6068
6069 if (!m_out_bEnabled) {
6070 DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled.");
6071 return OMX_ErrorIncorrectStateOperation;
6072 }
6073
Jia Meng2d51b932014-07-10 14:02:54 +08006074 unsigned nPortIndex = 0;
Arun Menonbdb80b02013-08-12 17:45:54 -07006075 if (dynamic_buf_mode) {
6076 private_handle_t *handle = NULL;
6077 struct VideoDecoderOutputMetaData *meta;
Arun Menonbdb80b02013-08-12 17:45:54 -07006078 unsigned int nPortIndex = 0;
6079
6080 if (!buffer || !buffer->pBuffer) {
Arun Menon8544ead2014-05-08 17:42:29 -07006081 DEBUG_PRINT_ERROR("%s: invalid params: %p", __FUNCTION__, buffer);
Arun Menonbdb80b02013-08-12 17:45:54 -07006082 return OMX_ErrorBadParameter;
6083 }
6084
6085 //get the buffer type and fd info
6086 meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer;
6087 handle = (private_handle_t *)meta->pHandle;
Arun Menonb49abf22013-12-14 21:38:10 -08006088 DEBUG_PRINT_LOW("FTB: metabuf: %p buftype: %d bufhndl: %p ", meta, meta->eType, meta->pHandle);
6089
6090 if (!handle) {
6091 DEBUG_PRINT_ERROR("FTB: Error: IL client passed an invalid buf handle - %p", handle);
6092 return OMX_ErrorBadParameter;
6093 }
Arun Menonbdb80b02013-08-12 17:45:54 -07006094 //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF
6095 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
6096 drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd;
Arun Menon50ab1bf2014-01-08 18:02:19 -08006097 drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = (OMX_U8*) buffer;
ApurupaPattapuf693a4d2013-12-04 16:07:07 -08006098
6099 //Store private handle from GraphicBuffer
6100 native_buffer[nPortIndex].privatehandle = handle;
6101 native_buffer[nPortIndex].nativehandle = handle;
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07006102
6103 //buffer->nAllocLen will be sizeof(struct VideoDecoderOutputMetaData). Overwrite
6104 //this with a more sane size so that we don't compensate in rest of code
6105 //We'll restore this size later on, so that it's transparent to client
6106 buffer->nFilledLen = 0;
Deva Ramasubramanian03a5bb92014-04-25 19:03:50 -07006107 buffer->nAllocLen = handle->size;
Arun Menonbdb80b02013-08-12 17:45:54 -07006108 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006109
Arun Menon906de572013-06-18 17:01:40 -07006110 if (!m_out_bEnabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006111 DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled.");
Arun Menon906de572013-06-18 17:01:40 -07006112 return OMX_ErrorIncorrectStateOperation;
6113 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006114
Jia Meng2d51b932014-07-10 14:02:54 +08006115 nPortIndex = buffer - client_buffers.get_il_buf_hdr();
Arun Menon906de572013-06-18 17:01:40 -07006116 if (buffer == NULL ||
Jia Meng2d51b932014-07-10 14:02:54 +08006117 (nPortIndex >= drv_ctx.op_buf.actualcount)) {
6118 DEBUG_PRINT_ERROR("FTB: ERROR: invalid buffer index, nPortIndex %u bufCount %u",
6119 nPortIndex, drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07006120 return OMX_ErrorBadParameter;
6121 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006122
Arun Menon906de572013-06-18 17:01:40 -07006123 if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006124 DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex);
Arun Menon906de572013-06-18 17:01:40 -07006125 return OMX_ErrorBadPortIndex;
6126 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006127
Arun Menon906de572013-06-18 17:01:40 -07006128 DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
6129 post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg);
6130 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006131}
6132/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006133 FUNCTION
6134 omx_vdec::fill_this_buffer_proxy
Shalaj Jain273b3e02012-06-22 19:08:03 -07006135
Arun Menon906de572013-06-18 17:01:40 -07006136 DESCRIPTION
6137 IL client uses this method to release the frame buffer
6138 after displaying them.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006139
Arun Menon906de572013-06-18 17:01:40 -07006140 PARAMETERS
6141 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006142
Arun Menon906de572013-06-18 17:01:40 -07006143 RETURN VALUE
6144 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006145
Arun Menon906de572013-06-18 17:01:40 -07006146 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006147OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy(
Arun Menon906de572013-06-18 17:01:40 -07006148 OMX_IN OMX_HANDLETYPE hComp,
6149 OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006150{
Arun Menon906de572013-06-18 17:01:40 -07006151 OMX_ERRORTYPE nRet = OMX_ErrorNone;
6152 OMX_BUFFERHEADERTYPE *buffer = bufferAdd;
6153 unsigned nPortIndex = 0;
6154 struct vdec_fillbuffer_cmd fillbuffer;
6155 struct vdec_bufferpayload *ptr_outputbuffer = NULL;
6156 struct vdec_output_frameinfo *ptr_respbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006157
Sri Karri38569452018-03-16 12:46:14 +05306158 auto_lock l(buf_lock);
Arun Menon906de572013-06-18 17:01:40 -07006159 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
Shalaj Jain273b3e02012-06-22 19:08:03 -07006160
Praveen Chavan58207a22016-08-17 12:19:29 -07006161 if (bufferAdd == NULL || nPortIndex >= drv_ctx.op_buf.actualcount) {
Jia Meng2d51b932014-07-10 14:02:54 +08006162 DEBUG_PRINT_ERROR("FTBProxy: ERROR: invalid buffer index, nPortIndex %u bufCount %u",
6163 nPortIndex, drv_ctx.op_buf.actualcount);
Arun Menon906de572013-06-18 17:01:40 -07006164 return OMX_ErrorBadParameter;
Jia Meng2d51b932014-07-10 14:02:54 +08006165 }
Sri Karri38569452018-03-16 12:46:14 +05306166 if (BITMASK_ABSENT(&m_out_bm_count, nPortIndex) || m_buffer_error) {
6167 DEBUG_PRINT_ERROR("FTBProxy: ERROR: invalid buffer, nPortIndex %u", nPortIndex);
6168 return OMX_ErrorBadParameter;
6169 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006170 DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006171 bufferAdd, bufferAdd->pBuffer);
6172 /*Return back the output buffer to client*/
6173 if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006174 DEBUG_PRINT_LOW("Output Buffers return flush/disable condition");
Arun Menon906de572013-06-18 17:01:40 -07006175 buffer->nFilledLen = 0;
6176 m_cb.FillBufferDone (hComp,m_app_data,buffer);
6177 return OMX_ErrorNone;
6178 }
Arun Menon50ab1bf2014-01-08 18:02:19 -08006179
6180 if (dynamic_buf_mode) {
6181 //map the buffer handle based on the size set on output port definition.
6182 if (!secure_mode) {
6183 drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr =
6184 (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size,
6185 PROT_READ|PROT_WRITE, MAP_SHARED,
6186 drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, 0);
6187 }
6188 drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0;
6189 drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size;
6190 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size;
6191 buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd,
6192 drv_ctx.ptr_outputbuffer[nPortIndex].offset);
6193 }
6194
Arun Menon906de572013-06-18 17:01:40 -07006195 pending_output_buffers++;
6196 buffer = client_buffers.get_dr_buf_hdr(bufferAdd);
6197 ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate;
6198 if (ptr_respbuffer) {
6199 ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data;
6200 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006201
Arun Menon906de572013-06-18 17:01:40 -07006202 if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) {
6203 DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL");
6204 buffer->nFilledLen = 0;
6205 m_cb.FillBufferDone (hComp,m_app_data,buffer);
6206 pending_output_buffers--;
6207 return OMX_ErrorBadParameter;
6208 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006209
Arun Menon906de572013-06-18 17:01:40 -07006210 int rc = 0;
6211 struct v4l2_buffer buf;
6212 struct v4l2_plane plane[VIDEO_MAX_PLANES];
6213 memset( (void *)&buf, 0, sizeof(buf));
6214 memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES));
Arun Menon8544ead2014-05-08 17:42:29 -07006215 unsigned int extra_idx = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006216
Arun Menon906de572013-06-18 17:01:40 -07006217 buf.index = nPortIndex;
6218 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
6219 buf.memory = V4L2_MEMORY_USERPTR;
6220 plane[0].bytesused = buffer->nFilledLen;
6221 plane[0].length = drv_ctx.op_buf.buffer_size;
6222 plane[0].m.userptr =
6223 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr -
6224 (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset;
6225 plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd;
6226 plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset;
6227 plane[0].data_offset = 0;
6228 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
6229 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
6230 plane[extra_idx].bytesused = 0;
6231 plane[extra_idx].length = drv_ctx.extradata_info.buffer_size;
6232 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 -07006233#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07006234 plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07006235#endif
Arun Menon906de572013-06-18 17:01:40 -07006236 plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size;
6237 plane[extra_idx].data_offset = 0;
6238 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Arun Menon8544ead2014-05-08 17:42:29 -07006239 DEBUG_PRINT_ERROR("Extradata index higher than expected: %u", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07006240 return OMX_ErrorBadParameter;
6241 }
6242 buf.m.planes = plane;
6243 buf.length = drv_ctx.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006244 DEBUG_PRINT_LOW("SENDING FTB TO F/W - fd[0] = %d fd[1] = %d offset[1] = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07006245 plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]);
6246
Arun Menon906de572013-06-18 17:01:40 -07006247 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf);
6248 if (rc) {
6249 /*TODO: How to handle this case */
6250 DEBUG_PRINT_ERROR("Failed to qbuf to driver");
6251 }
Arun Menon906de572013-06-18 17:01:40 -07006252return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006253}
6254
6255/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006256 FUNCTION
6257 omx_vdec::SetCallbacks
Shalaj Jain273b3e02012-06-22 19:08:03 -07006258
Arun Menon906de572013-06-18 17:01:40 -07006259 DESCRIPTION
6260 Set the callbacks.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006261
Arun Menon906de572013-06-18 17:01:40 -07006262 PARAMETERS
6263 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006264
Arun Menon906de572013-06-18 17:01:40 -07006265 RETURN VALUE
6266 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006267
Arun Menon906de572013-06-18 17:01:40 -07006268 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006269OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006270 OMX_IN OMX_CALLBACKTYPE* callbacks,
6271 OMX_IN OMX_PTR appData)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006272{
6273
Arun Menon906de572013-06-18 17:01:40 -07006274 m_cb = *callbacks;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006275 DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\
Arun Menon906de572013-06-18 17:01:40 -07006276 m_cb.EventHandler,m_cb.FillBufferDone);
6277 m_app_data = appData;
6278 return OMX_ErrorNotImplemented;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006279}
6280
6281/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006282 FUNCTION
6283 omx_vdec::ComponentDeInit
Shalaj Jain273b3e02012-06-22 19:08:03 -07006284
Arun Menon906de572013-06-18 17:01:40 -07006285 DESCRIPTION
6286 Destroys the component and release memory allocated to the heap.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006287
Arun Menon906de572013-06-18 17:01:40 -07006288 PARAMETERS
6289 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006290
Arun Menon906de572013-06-18 17:01:40 -07006291 RETURN VALUE
6292 OMX Error None if everything successful.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006293
Arun Menon906de572013-06-18 17:01:40 -07006294 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006295OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
6296{
Shalaj Jain273b3e02012-06-22 19:08:03 -07006297
Shalaj Jain286b0062013-02-21 20:35:48 -08006298 unsigned i = 0;
Arun Menon906de572013-06-18 17:01:40 -07006299 if (OMX_StateLoaded != m_state) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006300 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\
Arun Menon906de572013-06-18 17:01:40 -07006301 m_state);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006302 DEBUG_PRINT_ERROR("Playback Ended - FAILED");
Arun Menon906de572013-06-18 17:01:40 -07006303 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006304 DEBUG_PRINT_HIGH("Playback Ended - PASSED");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006305 }
6306
6307 /*Check if the output buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07006308 if (m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006309 DEBUG_PRINT_LOW("Freeing the Output Memory");
Arun Menon906de572013-06-18 17:01:40 -07006310 for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) {
Praveen Chavan88256fe2016-04-11 17:32:45 -07006311 if (BITMASK_PRESENT(&m_out_bm_count, i)) {
6312 BITMASK_CLEAR(&m_out_bm_count, i);
6313 client_buffers.free_output_buffer (&m_out_mem_ptr[i]);
6314 }
6315
6316 if (release_output_done()) {
6317 break;
6318 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006319 }
6320#ifdef _ANDROID_ICS_
6321 memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
6322#endif
6323 }
6324
6325 /*Check if the input buffers have to be cleaned up*/
Arun Menon906de572013-06-18 17:01:40 -07006326 if (m_inp_mem_ptr || m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006327 DEBUG_PRINT_LOW("Freeing the Input Memory");
Arun Menon906de572013-06-18 17:01:40 -07006328 for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) {
Praveen Chavan88256fe2016-04-11 17:32:45 -07006329
6330 if (BITMASK_PRESENT(&m_inp_bm_count, i)) {
6331 BITMASK_CLEAR(&m_inp_bm_count, i);
6332 if (m_inp_mem_ptr)
6333 free_input_buffer (i,&m_inp_mem_ptr[i]);
6334 else
6335 free_input_buffer (i,NULL);
6336 }
6337
6338 if (release_input_done()) {
6339 break;
6340 }
6341 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006342 }
6343 free_input_buffer_header();
6344 free_output_buffer_header();
Arun Menon906de572013-06-18 17:01:40 -07006345 if (h264_scratch.pBuffer) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006346 free(h264_scratch.pBuffer);
6347 h264_scratch.pBuffer = NULL;
6348 }
6349
Arun Menon906de572013-06-18 17:01:40 -07006350 if (h264_parser) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006351 delete h264_parser;
Arun Menon906de572013-06-18 17:01:40 -07006352 h264_parser = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006353 }
6354
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07006355 if (m_frame_parser.mutils) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006356 DEBUG_PRINT_LOW("Free utils parser");
Leena Winterrowddb9eaca2013-08-23 10:40:41 -07006357 delete (m_frame_parser.mutils);
6358 m_frame_parser.mutils = NULL;
6359 }
6360
Arun Menon906de572013-06-18 17:01:40 -07006361 if (m_platform_list) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006362 free(m_platform_list);
6363 m_platform_list = NULL;
6364 }
Arun Menon906de572013-06-18 17:01:40 -07006365 if (m_vendor_config.pData) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006366 free(m_vendor_config.pData);
6367 m_vendor_config.pData = NULL;
6368 }
6369
6370 // Reset counters in mesg queues
6371 m_ftb_q.m_size=0;
6372 m_cmd_q.m_size=0;
6373 m_etb_q.m_size=0;
6374 m_ftb_q.m_read = m_ftb_q.m_write =0;
6375 m_cmd_q.m_read = m_cmd_q.m_write =0;
6376 m_etb_q.m_read = m_etb_q.m_write =0;
6377#ifdef _ANDROID_
Arun Menon906de572013-06-18 17:01:40 -07006378 if (m_debug_timestamp) {
6379 m_timestamp_list.reset_ts_list();
Shalaj Jain273b3e02012-06-22 19:08:03 -07006380 }
6381#endif
6382
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006383 DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006384 //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG,
Arun Menon906de572013-06-18 17:01:40 -07006385 // NULL);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006386 DEBUG_PRINT_HIGH("Close the driver instance");
Arun Menon906de572013-06-18 17:01:40 -07006387
Jayasena Sangaraboina51230642013-08-21 18:02:13 -07006388 if (m_debug.infile) {
6389 fclose(m_debug.infile);
6390 m_debug.infile = NULL;
6391 }
6392 if (m_debug.outfile) {
6393 fclose(m_debug.outfile);
6394 m_debug.outfile = NULL;
6395 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006396#ifdef OUTPUT_EXTRADATA_LOG
Shalaj Jainaf08f302013-03-18 13:15:35 -07006397 if (outputExtradataFile)
6398 fclose (outputExtradataFile);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006399#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006400 DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete");
Arun Menon906de572013-06-18 17:01:40 -07006401 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006402}
6403
6404/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006405 FUNCTION
6406 omx_vdec::UseEGLImage
Shalaj Jain273b3e02012-06-22 19:08:03 -07006407
Arun Menon906de572013-06-18 17:01:40 -07006408 DESCRIPTION
6409 OMX Use EGL Image method implementation <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006410
Arun Menon906de572013-06-18 17:01:40 -07006411 PARAMETERS
6412 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006413
Arun Menon906de572013-06-18 17:01:40 -07006414 RETURN VALUE
6415 Not Implemented error.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006416
Arun Menon906de572013-06-18 17:01:40 -07006417 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006418OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006419 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
6420 OMX_IN OMX_U32 port,
6421 OMX_IN OMX_PTR appData,
6422 OMX_IN void* eglImage)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006423{
Arun Menon906de572013-06-18 17:01:40 -07006424 OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list;
6425 OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry;
6426 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006427
6428#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07006429 PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc;
6430 EGLint fd = -1, offset = 0,pmemPtr = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006431#else
Arun Menon906de572013-06-18 17:01:40 -07006432 int fd = -1, offset = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006433#endif
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006434 DEBUG_PRINT_HIGH("use EGL image support for decoder");
Arun Menon906de572013-06-18 17:01:40 -07006435 if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006436 DEBUG_PRINT_ERROR("");
Arun Menon906de572013-06-18 17:01:40 -07006437 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006438#ifdef USE_EGL_IMAGE_GPU
Arun Menon906de572013-06-18 17:01:40 -07006439 if (m_display_id == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006440 DEBUG_PRINT_ERROR("Display ID is not set by IL client");
Shalaj Jain273b3e02012-06-22 19:08:03 -07006441 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006442 }
6443 egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC)
6444 eglGetProcAddress("eglQueryImageKHR");
6445 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd);
6446 egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset);
6447 egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006448#else //with OMX test app
6449 struct temp_egl {
6450 int pmem_fd;
6451 int offset;
6452 };
6453 struct temp_egl *temp_egl_id = NULL;
6454 void * pmemPtr = (void *) eglImage;
6455 temp_egl_id = (struct temp_egl *)eglImage;
Arun Menon906de572013-06-18 17:01:40 -07006456 if (temp_egl_id != NULL) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006457 fd = temp_egl_id->pmem_fd;
6458 offset = temp_egl_id->offset;
6459 }
6460#endif
6461 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006462 DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd);
Shalaj Jain273b3e02012-06-22 19:08:03 -07006463 return OMX_ErrorInsufficientResources;
Arun Menon906de572013-06-18 17:01:40 -07006464 }
6465 pmem_info.pmem_fd = (OMX_U32) fd;
6466 pmem_info.offset = (OMX_U32) offset;
6467 pmem_entry.entry = (void *) &pmem_info;
6468 pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
6469 pmem_list.entryList = &pmem_entry;
6470 pmem_list.nEntries = 1;
6471 ouput_egl_buffers = true;
6472 if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port,
6473 (void *)&pmem_list, drv_ctx.op_buf.buffer_size,
6474 (OMX_U8 *)pmemPtr)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006475 DEBUG_PRINT_ERROR("use buffer call failed for egl image");
Arun Menon906de572013-06-18 17:01:40 -07006476 return OMX_ErrorInsufficientResources;
6477 }
6478 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006479}
6480
6481/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006482 FUNCTION
6483 omx_vdec::ComponentRoleEnum
Shalaj Jain273b3e02012-06-22 19:08:03 -07006484
Arun Menon906de572013-06-18 17:01:40 -07006485 DESCRIPTION
6486 OMX Component Role Enum method implementation.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006487
Arun Menon906de572013-06-18 17:01:40 -07006488 PARAMETERS
6489 <TBD>.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006490
Arun Menon906de572013-06-18 17:01:40 -07006491 RETURN VALUE
6492 OMX Error None if everything is successful.
6493 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006494OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006495 OMX_OUT OMX_U8* role,
6496 OMX_IN OMX_U32 index)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006497{
Arun Menon906de572013-06-18 17:01:40 -07006498 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006499
Arun Menon906de572013-06-18 17:01:40 -07006500 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
6501 if ((0 == index) && role) {
6502 strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006503 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006504 } else {
6505 eRet = OMX_ErrorNoMore;
6506 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006507 }
Arun Menon906de572013-06-18 17:01:40 -07006508 if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) {
6509 if ((0 == index) && role) {
6510 strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006511 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006512 } else {
6513 eRet = OMX_ErrorNoMore;
6514 }
6515 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
6516 if ((0 == index) && role) {
6517 strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006518 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006519 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006520 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006521 eRet = OMX_ErrorNoMore;
6522 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006523 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006524
Arun Menon906de572013-06-18 17:01:40 -07006525 else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) ||
6526 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE))
6527 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07006528
Shalaj Jain273b3e02012-06-22 19:08:03 -07006529 {
Arun Menon906de572013-06-18 17:01:40 -07006530 if ((0 == index) && role) {
6531 strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006532 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006533 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006534 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006535 eRet = OMX_ErrorNoMore;
6536 }
6537 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
6538 if ((0 == index) && role) {
6539 strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006540 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006541 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006542 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006543 eRet = OMX_ErrorNoMore;
6544 }
6545 } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) ||
6546 (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE))
6547 ) {
6548 if ((0 == index) && role) {
6549 strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006550 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006551 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006552 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006553 eRet = OMX_ErrorNoMore;
6554 }
6555 } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
6556 if ((0 == index) && role) {
6557 strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006558 DEBUG_PRINT_LOW("component_role_enum: role %s",role);
Arun Menon906de572013-06-18 17:01:40 -07006559 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006560 DEBUG_PRINT_LOW("No more roles");
Arun Menon906de572013-06-18 17:01:40 -07006561 eRet = OMX_ErrorNoMore;
6562 }
6563 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006564 DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component");
Arun Menon906de572013-06-18 17:01:40 -07006565 eRet = OMX_ErrorInvalidComponentName;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006566 }
Arun Menon906de572013-06-18 17:01:40 -07006567 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006568}
6569
6570
6571
6572
6573/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006574 FUNCTION
6575 omx_vdec::AllocateDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006576
Arun Menon906de572013-06-18 17:01:40 -07006577 DESCRIPTION
6578 Checks if entire buffer pool is allocated by IL Client or not.
6579 Need this to move to IDLE state.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006580
Arun Menon906de572013-06-18 17:01:40 -07006581 PARAMETERS
6582 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006583
Arun Menon906de572013-06-18 17:01:40 -07006584 RETURN VALUE
6585 true/false.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006586
Arun Menon906de572013-06-18 17:01:40 -07006587 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006588bool omx_vdec::allocate_done(void)
6589{
Arun Menon906de572013-06-18 17:01:40 -07006590 bool bRet = false;
6591 bool bRet_In = false;
6592 bool bRet_Out = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006593
Arun Menon906de572013-06-18 17:01:40 -07006594 bRet_In = allocate_input_done();
6595 bRet_Out = allocate_output_done();
Shalaj Jain273b3e02012-06-22 19:08:03 -07006596
Arun Menon906de572013-06-18 17:01:40 -07006597 if (bRet_In && bRet_Out) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006598 bRet = true;
6599 }
Arun Menon906de572013-06-18 17:01:40 -07006600
6601 return bRet;
6602}
6603/* ======================================================================
6604 FUNCTION
6605 omx_vdec::AllocateInputDone
6606
6607 DESCRIPTION
6608 Checks if I/P buffer pool is allocated by IL Client or not.
6609
6610 PARAMETERS
6611 None.
6612
6613 RETURN VALUE
6614 true/false.
6615
6616 ========================================================================== */
6617bool omx_vdec::allocate_input_done(void)
6618{
6619 bool bRet = false;
6620 unsigned i=0;
6621
6622 if (m_inp_mem_ptr == NULL) {
6623 return bRet;
6624 }
6625 if (m_inp_mem_ptr ) {
6626 for (; i<drv_ctx.ip_buf.actualcount; i++) {
6627 if (BITMASK_ABSENT(&m_inp_bm_count,i)) {
6628 break;
6629 }
6630 }
6631 }
6632 if (i == drv_ctx.ip_buf.actualcount) {
6633 bRet = true;
6634 DEBUG_PRINT_HIGH("Allocate done for all i/p buffers");
6635 }
6636 if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) {
6637 m_inp_bPopulated = OMX_TRUE;
6638 }
6639 return bRet;
6640}
6641/* ======================================================================
6642 FUNCTION
6643 omx_vdec::AllocateOutputDone
6644
6645 DESCRIPTION
6646 Checks if entire O/P buffer pool is allocated by IL Client or not.
6647
6648 PARAMETERS
6649 None.
6650
6651 RETURN VALUE
6652 true/false.
6653
6654 ========================================================================== */
6655bool omx_vdec::allocate_output_done(void)
6656{
6657 bool bRet = false;
6658 unsigned j=0;
6659
6660 if (m_out_mem_ptr == NULL) {
6661 return bRet;
6662 }
6663
6664 if (m_out_mem_ptr) {
6665 for (; j < drv_ctx.op_buf.actualcount; j++) {
6666 if (BITMASK_ABSENT(&m_out_bm_count,j)) {
6667 break;
6668 }
6669 }
6670 }
6671
6672 if (j == drv_ctx.op_buf.actualcount) {
6673 bRet = true;
6674 DEBUG_PRINT_HIGH("Allocate done for all o/p buffers");
6675 if (m_out_bEnabled)
6676 m_out_bPopulated = OMX_TRUE;
6677 }
6678
6679 return bRet;
6680}
6681
6682/* ======================================================================
6683 FUNCTION
6684 omx_vdec::ReleaseDone
6685
6686 DESCRIPTION
6687 Checks if IL client has released all the buffers.
6688
6689 PARAMETERS
6690 None.
6691
6692 RETURN VALUE
6693 true/false
6694
6695 ========================================================================== */
6696bool omx_vdec::release_done(void)
6697{
6698 bool bRet = false;
6699
6700 if (release_input_done()) {
6701 if (release_output_done()) {
6702 bRet = true;
6703 }
6704 }
6705 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006706}
6707
6708
6709/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006710 FUNCTION
6711 omx_vdec::ReleaseOutputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006712
Arun Menon906de572013-06-18 17:01:40 -07006713 DESCRIPTION
6714 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006715
Arun Menon906de572013-06-18 17:01:40 -07006716 PARAMETERS
6717 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006718
Arun Menon906de572013-06-18 17:01:40 -07006719 RETURN VALUE
6720 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006721
Arun Menon906de572013-06-18 17:01:40 -07006722 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006723bool omx_vdec::release_output_done(void)
6724{
Arun Menon906de572013-06-18 17:01:40 -07006725 bool bRet = false;
6726 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006727
Praveen Chavan88256fe2016-04-11 17:32:45 -07006728 DEBUG_PRINT_LOW("Value of m_out_mem_ptr %p",m_out_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006729 if (m_out_mem_ptr) {
6730 for (; j < drv_ctx.op_buf.actualcount ; j++) {
6731 if (BITMASK_PRESENT(&m_out_bm_count,j)) {
6732 break;
6733 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006734 }
Arun Menon906de572013-06-18 17:01:40 -07006735 if (j == drv_ctx.op_buf.actualcount) {
6736 m_out_bm_count = 0;
6737 bRet = true;
6738 }
6739 } else {
6740 m_out_bm_count = 0;
6741 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006742 }
Arun Menon906de572013-06-18 17:01:40 -07006743 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006744}
6745/* ======================================================================
Arun Menon906de572013-06-18 17:01:40 -07006746 FUNCTION
6747 omx_vdec::ReleaseInputDone
Shalaj Jain273b3e02012-06-22 19:08:03 -07006748
Arun Menon906de572013-06-18 17:01:40 -07006749 DESCRIPTION
6750 Checks if IL client has released all the buffers.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006751
Arun Menon906de572013-06-18 17:01:40 -07006752 PARAMETERS
6753 None.
Shalaj Jain273b3e02012-06-22 19:08:03 -07006754
Arun Menon906de572013-06-18 17:01:40 -07006755 RETURN VALUE
6756 true/false
Shalaj Jain273b3e02012-06-22 19:08:03 -07006757
Arun Menon906de572013-06-18 17:01:40 -07006758 ========================================================================== */
Shalaj Jain273b3e02012-06-22 19:08:03 -07006759bool omx_vdec::release_input_done(void)
6760{
Arun Menon906de572013-06-18 17:01:40 -07006761 bool bRet = false;
6762 unsigned i=0,j=0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006763
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006764 DEBUG_PRINT_LOW("Value of m_inp_mem_ptr %p",m_inp_mem_ptr);
Arun Menon906de572013-06-18 17:01:40 -07006765 if (m_inp_mem_ptr) {
6766 for (; j<drv_ctx.ip_buf.actualcount; j++) {
6767 if ( BITMASK_PRESENT(&m_inp_bm_count,j)) {
6768 break;
6769 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006770 }
Arun Menon906de572013-06-18 17:01:40 -07006771 if (j==drv_ctx.ip_buf.actualcount) {
6772 bRet = true;
6773 }
6774 } else {
6775 bRet = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006776 }
Arun Menon906de572013-06-18 17:01:40 -07006777 return bRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006778}
6779
6780OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07006781 OMX_BUFFERHEADERTYPE * buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07006782{
Arun Menon906de572013-06-18 17:01:40 -07006783 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL;
Surajit Podderd2644d52013-08-28 17:59:06 +05306784 if (!buffer || (buffer - m_out_mem_ptr) >= (int)drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006785 DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer);
Arun Menon906de572013-06-18 17:01:40 -07006786 return OMX_ErrorBadParameter;
6787 } else if (output_flush_progress) {
6788 DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer);
6789 buffer->nFilledLen = 0;
6790 buffer->nTimeStamp = 0;
6791 buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA;
6792 buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ;
6793 buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT;
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006794 }
6795
Arun Menon906de572013-06-18 17:01:40 -07006796 if (m_debug_extradata) {
6797 if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006798 DEBUG_PRINT_HIGH("");
6799 DEBUG_PRINT_HIGH("***************************************************");
6800 DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received");
6801 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006802 }
6803
6804 if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006805 DEBUG_PRINT_HIGH("");
6806 DEBUG_PRINT_HIGH("***************************************************");
6807 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
6808 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07006809 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006810 }
Praneeth Paladugu594e6822013-04-19 10:47:28 -07006811
6812
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006813 DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07006814 buffer, buffer->pBuffer);
6815 pending_output_buffers --;
Shalaj Jain273b3e02012-06-22 19:08:03 -07006816
Arun Menon906de572013-06-18 17:01:40 -07006817 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006818 DEBUG_PRINT_HIGH("Output EOS has been reached");
Arun Menon906de572013-06-18 17:01:40 -07006819 if (!output_flush_progress)
6820 post_event((unsigned)NULL, (unsigned)NULL,
6821 OMX_COMPONENT_GENERATE_EOS_DONE);
6822
6823 if (psource_frame) {
6824 m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame);
6825 psource_frame = NULL;
6826 }
6827 if (pdest_frame) {
6828 pdest_frame->nFilledLen = 0;
6829 m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL,
6830 (unsigned)NULL);
6831 pdest_frame = NULL;
6832 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006833 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006834
Shalaj Jain273b3e02012-06-22 19:08:03 -07006835
Praneeth Paladugudd29c282013-09-12 15:41:47 -07006836 if (!output_flush_progress && (buffer->nFilledLen > 0)) {
6837 DEBUG_PRINT_LOW("Processing extradata");
6838 handle_extradata(buffer);
6839 }
6840
Arun Menon906de572013-06-18 17:01:40 -07006841 /* For use buffer we need to copy the data */
6842 if (!output_flush_progress) {
6843 /* This is the error check for non-recoverable errros */
6844 bool is_duplicate_ts_valid = true;
6845 bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006846
Arun Menon906de572013-06-18 17:01:40 -07006847 if (output_capability == V4L2_PIX_FMT_MPEG4 ||
6848 output_capability == V4L2_PIX_FMT_MPEG2 ||
6849 output_capability == V4L2_PIX_FMT_DIVX ||
6850 output_capability == V4L2_PIX_FMT_DIVX_311)
6851 is_duplicate_ts_valid = false;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07006852
Arun Menon906de572013-06-18 17:01:40 -07006853 if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) {
Arun Menon7b6fd642014-02-13 16:48:36 -08006854 if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF) {
Arun Menon906de572013-06-18 17:01:40 -07006855 is_interlaced = false;
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306856 }
Arun Menon906de572013-06-18 17:01:40 -07006857 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306858
Arun Menon906de572013-06-18 17:01:40 -07006859 if (buffer->nFilledLen > 0) {
6860 time_stamp_dts.get_next_timestamp(buffer,
6861 is_interlaced && is_duplicate_ts_valid);
6862 if (m_debug_timestamp) {
6863 {
6864 OMX_TICKS expected_ts = 0;
6865 m_timestamp_list.pop_min_ts(expected_ts);
6866 if (is_interlaced && is_duplicate_ts_valid) {
6867 m_timestamp_list.pop_min_ts(expected_ts);
6868 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006869 DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list",
Arun Menon906de572013-06-18 17:01:40 -07006870 buffer->nTimeStamp, expected_ts);
6871
6872 if (buffer->nTimeStamp != expected_ts) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006873 DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check");
Arun Menon906de572013-06-18 17:01:40 -07006874 }
6875 }
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306876 }
Arun Menon906de572013-06-18 17:01:40 -07006877 } else {
Arun Menon906de572013-06-18 17:01:40 -07006878 time_stamp_dts.remove_time_stamp(
6879 buffer->nTimeStamp,
6880 is_interlaced && is_duplicate_ts_valid);
Rajeshwar Kurapaty46a24f02013-07-09 15:13:41 +05306881 }
Arun Menon906de572013-06-18 17:01:40 -07006882
6883
Praneeth Paladugu8f12e822013-03-11 18:47:58 -07006884 }
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006885
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07006886 /* Since we're passing around handles, adjust nFilledLen and nAllocLen
6887 * to size of the handle. Do it _after_ handle_extradata() which
6888 * requires the respective sizes to be accurate. */
6889 if (dynamic_buf_mode) {
6890 buffer->nAllocLen = sizeof(struct VideoDecoderOutputMetaData);
6891 buffer->nFilledLen = buffer->nFilledLen ?
6892 sizeof(struct VideoDecoderOutputMetaData) : 0;
6893 }
6894
Arun Menon906de572013-06-18 17:01:40 -07006895 if (m_cb.FillBufferDone) {
6896 if (buffer->nFilledLen > 0) {
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006897 if (arbitrary_bytes)
Arun Menon906de572013-06-18 17:01:40 -07006898 adjust_timestamp(buffer->nTimeStamp);
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08006899 else
6900 set_frame_rate(buffer->nTimeStamp);
6901
Arun Menon906de572013-06-18 17:01:40 -07006902 if (perf_flag) {
6903 if (!proc_frms) {
6904 dec_time.stop();
6905 latency = dec_time.processing_time_us() - latency;
6906 DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3);
6907 dec_time.start();
6908 fps_metrics.start();
6909 }
6910 proc_frms++;
6911 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6912 OMX_U64 proc_time = 0;
6913 fps_metrics.stop();
6914 proc_time = fps_metrics.processing_time_us();
6915 DEBUG_PRINT_HIGH(">>> FBD Metrics: proc_frms(%lu) proc_time(%.2f)S fps(%.2f)",
Shalaj Jain273b3e02012-06-22 19:08:03 -07006916 proc_frms, (float)proc_time / 1e6,
6917 (float)(1e6 * proc_frms) / proc_time);
Arun Menon906de572013-06-18 17:01:40 -07006918 proc_frms = 0;
6919 }
6920 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006921
6922#ifdef OUTPUT_EXTRADATA_LOG
Arun Menon906de572013-06-18 17:01:40 -07006923 if (outputExtradataFile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07006924
Arun Menon906de572013-06-18 17:01:40 -07006925 OMX_OTHER_EXTRADATATYPE *p_extra = NULL;
6926 p_extra = (OMX_OTHER_EXTRADATATYPE *)
6927 ((unsigned)(buffer->pBuffer + buffer->nOffset +
6928 buffer->nFilledLen + 3)&(~3));
6929 while (p_extra &&
6930 (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006931 DEBUG_PRINT_LOW("WRITING extradata, size=%d,type=%d",p_extra->nSize, p_extra->eType);
Arun Menon906de572013-06-18 17:01:40 -07006932 fwrite (p_extra,1,p_extra->nSize,outputExtradataFile);
6933 if (p_extra->eType == OMX_ExtraDataNone) {
6934 break;
6935 }
6936 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
6937 }
6938 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006939#endif
Arun Menon906de572013-06-18 17:01:40 -07006940 }
6941 if (buffer->nFlags & OMX_BUFFERFLAG_EOS) {
6942 prev_ts = LLONG_MAX;
6943 rst_prev_ts = true;
6944 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07006945
Arun Menon906de572013-06-18 17:01:40 -07006946 pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
6947 ((OMX_QCOM_PLATFORM_PRIVATE_LIST *)
6948 buffer->pPlatformPrivate)->entryList->entry;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006949 DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07006950 OMX_BUFFERHEADERTYPE *il_buffer;
6951 il_buffer = client_buffers.get_il_buf_hdr(buffer);
vivek mehtaa75c69f2014-01-10 21:50:37 -08006952
vivek mehta79cff222014-01-22 12:17:07 -08006953 if (il_buffer && m_last_rendered_TS >= 0) {
6954 int current_framerate = (int)(drv_ctx.frame_rate.fps_numerator /drv_ctx.frame_rate.fps_denominator);
Manikanta Kanamarlapudifb53b262014-01-20 16:12:47 +05306955 OMX_TICKS ts_delta = (OMX_TICKS)llabs(il_buffer->nTimeStamp - m_last_rendered_TS);
vivek mehta79cff222014-01-22 12:17:07 -08006956
6957 // Current frame can be send for rendering if
6958 // (a) current FPS is <= 60
6959 // (b) is the next frame after the frame with TS 0
6960 // (c) is the first frame after seek
6961 // (d) the delta TS b\w two consecutive frames is > 16 ms
6962 // (e) its TS is equal to previous frame TS
6963 // (f) if marked EOS
6964
6965 if(current_framerate <= 60 || m_last_rendered_TS == 0 ||
6966 il_buffer->nTimeStamp == 0 || ts_delta >= 16000 ||
6967 ts_delta == 0 || (il_buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
vivek mehtaa75c69f2014-01-10 21:50:37 -08006968 m_last_rendered_TS = il_buffer->nTimeStamp;
vivek mehta79cff222014-01-22 12:17:07 -08006969 } else {
vivek mehtaa75c69f2014-01-10 21:50:37 -08006970 //mark for droping
vivek mehtaa75c69f2014-01-10 21:50:37 -08006971 buffer->nFilledLen = 0;
vivek mehta79cff222014-01-22 12:17:07 -08006972 }
6973
6974 DEBUG_PRINT_LOW(" -- %s Frame -- info:: fps(%d) lastRenderTime(%lld) bufferTs(%lld) ts_delta(%d)",
6975 buffer->nFilledLen? "Rendering":"Dropping",current_framerate,m_last_rendered_TS,
6976 il_buffer->nTimeStamp,ts_delta);
vivek mehtaa75c69f2014-01-10 21:50:37 -08006977 }
6978
vivek mehta79cff222014-01-22 12:17:07 -08006979 if (il_buffer) {
Arun Menon9230eb82014-02-11 19:19:02 -08006980 log_output_buffers(il_buffer);
6981 if (dynamic_buf_mode) {
6982 unsigned int nPortIndex = 0;
6983 nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr());
6984
6985 if (!secure_mode) {
6986 munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr,
6987 drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size);
6988 }
6989
6990 //Clear graphic buffer handles in dynamic mode
6991 native_buffer[nPortIndex].privatehandle = NULL;
6992 native_buffer[nPortIndex].nativehandle = NULL;
6993 }
Arun Menon906de572013-06-18 17:01:40 -07006994 m_cb.FillBufferDone (hComp,m_app_data,il_buffer);
vivek mehta79cff222014-01-22 12:17:07 -08006995 } else {
Arun Menon906de572013-06-18 17:01:40 -07006996 DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr");
6997 return OMX_ErrorBadParameter;
6998 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07006999 DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd);
Arun Menon906de572013-06-18 17:01:40 -07007000 } else {
7001 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08007002 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007003
Praveen Chavancf924182013-12-06 23:16:23 -08007004#ifdef ADAPTIVE_PLAYBACK_SUPPORTED
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05307005 if (m_smoothstreaming_mode && m_out_mem_ptr) {
Praveen Chavancf924182013-12-06 23:16:23 -08007006 OMX_U32 buf_index = buffer - m_out_mem_ptr;
7007 BufferDim_t dim;
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05307008 private_handle_t *private_handle = NULL;
Pushkaraj Patil065b5732014-11-26 11:08:02 +05307009 dim.sliceWidth = framesize.nWidth;
7010 dim.sliceHeight = framesize.nHeight;
Pushkaraj Patil8f98adf2014-02-12 13:32:00 +05307011 if (native_buffer[buf_index].privatehandle)
7012 private_handle = native_buffer[buf_index].privatehandle;
Praveen Chavancf924182013-12-06 23:16:23 -08007013 if (private_handle) {
7014 DEBUG_PRINT_LOW("set metadata: update buf-geometry with stride %d slice %d",
7015 dim.sliceWidth, dim.sliceHeight);
7016 setMetaData(private_handle, UPDATE_BUFFER_GEOMETRY, (void*)&dim);
7017 }
7018 }
7019#endif
7020
Arun Menon906de572013-06-18 17:01:40 -07007021 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007022}
7023
7024OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07007025 OMX_BUFFERHEADERTYPE* buffer)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007026{
7027
Praveen Chavan58207a22016-08-17 12:19:29 -07007028 int nBufferIndex = buffer - m_inp_mem_ptr;
7029
7030 if (buffer == NULL || (nBufferIndex >= (int)drv_ctx.ip_buf.actualcount)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007031 DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer);
Arun Menon906de572013-06-18 17:01:40 -07007032 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007033 }
7034
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007035 DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p",
Arun Menon906de572013-06-18 17:01:40 -07007036 buffer, buffer->pBuffer);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007037 pending_input_buffers--;
7038
Arun Menon906de572013-06-18 17:01:40 -07007039 if (arbitrary_bytes) {
7040 if (pdest_frame == NULL && input_flush_progress == false) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007041 DEBUG_PRINT_LOW("Push input from buffer done address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07007042 pdest_frame = buffer;
7043 buffer->nFilledLen = 0;
7044 buffer->nTimeStamp = LLONG_MAX;
7045 push_input_buffer (hComp);
7046 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007047 DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07007048 buffer->nFilledLen = 0;
7049 if (!m_input_free_q.insert_entry((unsigned)buffer,
7050 (unsigned)NULL, (unsigned)NULL)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007051 DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error");
Arun Menon906de572013-06-18 17:01:40 -07007052 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007053 }
Arun Menon906de572013-06-18 17:01:40 -07007054 } else if (m_cb.EmptyBufferDone) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007055 buffer->nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07007056 if (input_use_buffer == true) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007057 buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr];
7058 }
7059 m_cb.EmptyBufferDone(hComp ,m_app_data, buffer);
7060 }
7061 return OMX_ErrorNone;
7062}
7063
Shalaj Jain273b3e02012-06-22 19:08:03 -07007064int omx_vdec::async_message_process (void *context, void* message)
7065{
Arun Menon906de572013-06-18 17:01:40 -07007066 omx_vdec* omx = NULL;
7067 struct vdec_msginfo *vdec_msg = NULL;
7068 OMX_BUFFERHEADERTYPE* omxhdr = NULL;
7069 struct v4l2_buffer *v4l2_buf_ptr = NULL;
7070 struct vdec_output_frameinfo *output_respbuf = NULL;
7071 int rc=1;
7072 if (context == NULL || message == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007073 DEBUG_PRINT_ERROR("FATAL ERROR in omx_vdec::async_message_process NULL Check");
Arun Menon906de572013-06-18 17:01:40 -07007074 return -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007075 }
Arun Menon906de572013-06-18 17:01:40 -07007076 vdec_msg = (struct vdec_msginfo *)message;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007077
Arun Menon906de572013-06-18 17:01:40 -07007078 omx = reinterpret_cast<omx_vdec*>(context);
Vinay Kaliab9e98102013-04-02 19:31:43 -07007079
Arun Menon906de572013-06-18 17:01:40 -07007080 switch (vdec_msg->msgcode) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007081
Arun Menon906de572013-06-18 17:01:40 -07007082 case VDEC_MSG_EVT_HW_ERROR:
7083 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7084 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
7085 break;
7086
Deepak Verma24720fb2014-01-29 16:57:40 +05307087 case VDEC_MSG_EVT_HW_OVERLOAD:
7088 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7089 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD);
7090 break;
7091
Arun Menon906de572013-06-18 17:01:40 -07007092 case VDEC_MSG_RESP_START_DONE:
7093 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7094 OMX_COMPONENT_GENERATE_START_DONE);
7095 break;
7096
7097 case VDEC_MSG_RESP_STOP_DONE:
7098 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7099 OMX_COMPONENT_GENERATE_STOP_DONE);
7100 break;
7101
7102 case VDEC_MSG_RESP_RESUME_DONE:
7103 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7104 OMX_COMPONENT_GENERATE_RESUME_DONE);
7105 break;
7106
7107 case VDEC_MSG_RESP_PAUSE_DONE:
7108 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7109 OMX_COMPONENT_GENERATE_PAUSE_DONE);
7110 break;
7111
7112 case VDEC_MSG_RESP_FLUSH_INPUT_DONE:
7113 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7114 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
7115 break;
7116 case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE:
7117 omx->post_event ((unsigned)NULL, vdec_msg->status_code,\
7118 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
7119 break;
7120 case VDEC_MSG_RESP_INPUT_FLUSHED:
7121 case VDEC_MSG_RESP_INPUT_BUFFER_DONE:
7122
7123 /* omxhdr = (OMX_BUFFERHEADERTYPE* )
7124 vdec_msg->msgdata.input_frame_clientdata; */
7125
7126 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata;
7127 omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index;
7128 if (omxhdr == NULL ||
Surajit Podderd2644d52013-08-28 17:59:06 +05307129 ((omxhdr - omx->m_inp_mem_ptr) > (int)omx->drv_ctx.ip_buf.actualcount) ) {
Arun Menon906de572013-06-18 17:01:40 -07007130 omxhdr = NULL;
7131 vdec_msg->status_code = VDEC_S_EFATAL;
7132 }
7133 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) {
7134 DEBUG_PRINT_HIGH("Unsupported input");
7135 omx->omx_report_error ();
7136 }
7137 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
7138 vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR;
7139 }
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307140 if (omxhdr->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307141
Pushkaraj Patilc7e0b9a2015-01-22 18:31:13 +05307142 DEBUG_PRINT_LOW("Decrement codec_config buffer counter");
7143 android_atomic_dec(&omx->m_queued_codec_config_count);
7144 if ((android_atomic_add(0, &omx->m_queued_codec_config_count) == 0) &&
7145 BITMASK_PRESENT(&omx->m_flags, OMX_COMPONENT_FLUSH_DEFERRED)) {
7146 DEBUG_PRINT_LOW("sem post for CODEC CONFIG buffer");
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307147 sem_post(&omx->m_safe_flush);
7148 }
Pushkaraj Patil673f14a2014-12-03 14:55:19 +05307149 }
7150
Arun Menon906de572013-06-18 17:01:40 -07007151 omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code,
7152 OMX_COMPONENT_GENERATE_EBD);
7153 break;
7154 case VDEC_MSG_EVT_INFO_FIELD_DROPPED:
7155 int64_t *timestamp;
7156 timestamp = (int64_t *) malloc(sizeof(int64_t));
7157 if (timestamp) {
7158 *timestamp = vdec_msg->msgdata.output_frame.time_stamp;
7159 omx->post_event ((unsigned int)timestamp, vdec_msg->status_code,
7160 OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007161 DEBUG_PRINT_HIGH("Field dropped time stamp is %lld",
Arun Menon906de572013-06-18 17:01:40 -07007162 vdec_msg->msgdata.output_frame.time_stamp);
7163 }
7164 break;
7165 case VDEC_MSG_RESP_OUTPUT_FLUSHED:
7166 case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE:
7167
7168 v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data;
7169 omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307170
7171 DEBUG_PRINT_LOW("[RespBufDone] Buf(%p) Ts(%lld) PicType(%u) Flags (0x%x) FillLen(%u) Crop: L(%u) T(%u) R(%u) B(%u)",
Arun Menon906de572013-06-18 17:01:40 -07007172 omxhdr, vdec_msg->msgdata.output_frame.time_stamp,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307173 vdec_msg->msgdata.output_frame.pic_type, v4l2_buf_ptr->flags,
7174 (unsigned int)vdec_msg->msgdata.output_frame.len,
7175 vdec_msg->msgdata.output_frame.framesize.left,
7176 vdec_msg->msgdata.output_frame.framesize.top,
7177 vdec_msg->msgdata.output_frame.framesize.right,
7178 vdec_msg->msgdata.output_frame.framesize.bottom);
Arun Menon906de572013-06-18 17:01:40 -07007179
7180 if (omxhdr && omxhdr->pOutputPortPrivate &&
Surajit Podderd2644d52013-08-28 17:59:06 +05307181 ((omxhdr - omx->m_out_mem_ptr) < (int)omx->drv_ctx.op_buf.actualcount) &&
Arun Menon906de572013-06-18 17:01:40 -07007182 (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate
Surajit Podderd2644d52013-08-28 17:59:06 +05307183 - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307184
Deva Ramasubramaniancdbd31b2014-04-14 20:14:28 -07007185 if (vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) {
Arun Menon906de572013-06-18 17:01:40 -07007186 omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len;
7187 omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset;
7188 omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp;
7189 omxhdr->nFlags = 0;
7190
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07007191 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) {
Arun Menon906de572013-06-18 17:01:40 -07007192 omxhdr->nFlags |= OMX_BUFFERFLAG_EOS;
7193 //rc = -1;
7194 }
7195 if (omxhdr->nFilledLen) {
7196 omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
7197 }
7198 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) {
7199 omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
7200 } else {
7201 omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME;
7202 }
7203 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) {
7204 omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
7205 }
7206 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) {
7207 omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY;
7208 }
Arun Menon7b6fd642014-02-13 16:48:36 -08007209
7210 if (v4l2_buf_ptr->flags & V4L2_MSM_BUF_FLAG_MBAFF) {
7211 omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_MBAFF;
7212 }
7213
Arun Menonbdb80b02013-08-12 17:45:54 -07007214 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) {
Arun Menone50f6ef2013-09-30 15:08:27 -07007215 omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY;
Arun Menonbdb80b02013-08-12 17:45:54 -07007216 DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d",
7217 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd);
7218 }
Arun Menonbdb80b02013-08-12 17:45:54 -07007219 if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) {
7220 omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd,
7221 omxhdr->nOffset);
7222 }
Arun Menon906de572013-06-18 17:01:40 -07007223 if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) &&
7224 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) &&
Deva Ramasubramanianc1c7c122013-09-10 21:50:43 -07007225 !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) {
Praneeth Paladugu17364df2013-07-30 11:34:16 -07007226 omx->time_stamp_dts.remove_time_stamp(
7227 omxhdr->nTimeStamp,
7228 (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive)
7229 ?true:false);
Arun Menon906de572013-06-18 17:01:40 -07007230 omx->post_event ((unsigned)NULL,(unsigned int)omxhdr,
7231 OMX_COMPONENT_GENERATE_FTB);
7232 break;
7233 }
7234 if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) {
7235 omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
7236 }
7237 vdec_msg->msgdata.output_frame.bufferaddr =
7238 omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307239
7240 /* Post event if resolution OR crop changed */
7241 /* filled length will be changed if resolution changed */
7242 /* Crop parameters can be changed even without resolution change */
7243 if (omxhdr->nFilledLen
7244 && ((omx->prev_n_filled_len != omxhdr->nFilledLen)
7245 || (omx->drv_ctx.frame_size.left != vdec_msg->msgdata.output_frame.framesize.left)
7246 || (omx->drv_ctx.frame_size.top != vdec_msg->msgdata.output_frame.framesize.top)
7247 || (omx->drv_ctx.frame_size.right != vdec_msg->msgdata.output_frame.framesize.right)
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05307248 || (omx->drv_ctx.frame_size.bottom != vdec_msg->msgdata.output_frame.framesize.bottom)
7249 || (omx->drv_ctx.video_resolution.frame_width != vdec_msg->msgdata.output_frame.picsize.frame_width)
7250 || (omx->drv_ctx.video_resolution.frame_height != vdec_msg->msgdata.output_frame.picsize.frame_height) )) {
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307251
Maheshwar Ajja3cdbad42014-08-12 17:00:59 +05307252 DEBUG_PRINT_HIGH("Paramters Changed From: Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u --> Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u",
7253 omx->prev_n_filled_len,
7254 omx->drv_ctx.video_resolution.frame_width,
7255 omx->drv_ctx.video_resolution.frame_height,
7256 omx->drv_ctx.frame_size.left, omx->drv_ctx.frame_size.top,
7257 omx->drv_ctx.frame_size.right, omx->drv_ctx.frame_size.bottom,
7258 omxhdr->nFilledLen, vdec_msg->msgdata.output_frame.picsize.frame_width,
7259 vdec_msg->msgdata.output_frame.picsize.frame_height,
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307260 vdec_msg->msgdata.output_frame.framesize.left,
7261 vdec_msg->msgdata.output_frame.framesize.top,
7262 vdec_msg->msgdata.output_frame.framesize.right,
7263 vdec_msg->msgdata.output_frame.framesize.bottom);
7264
Maheshwar Ajja0f840ce2014-09-29 16:53:42 +05307265 omx->drv_ctx.video_resolution.frame_width =
7266 vdec_msg->msgdata.output_frame.picsize.frame_width;
7267 omx->drv_ctx.video_resolution.frame_height =
7268 vdec_msg->msgdata.output_frame.picsize.frame_height;
Praneeth Paladuguca80be72014-10-22 23:48:54 -07007269 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) {
7270 omx->drv_ctx.video_resolution.stride =
7271 VENUS_Y_STRIDE(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_width);
7272 omx->drv_ctx.video_resolution.scan_lines =
7273 VENUS_Y_SCANLINES(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_height);
7274 }
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307275 memcpy(&omx->drv_ctx.frame_size,
7276 &vdec_msg->msgdata.output_frame.framesize,
7277 sizeof(struct vdec_framesize));
7278
7279 omx->post_event(OMX_CORE_OUTPUT_PORT_INDEX,
7280 OMX_IndexConfigCommonOutputCrop,
7281 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
Arun Menon906de572013-06-18 17:01:40 -07007282 }
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307283
Arun Menon906de572013-06-18 17:01:40 -07007284 if (omxhdr->nFilledLen)
7285 omx->prev_n_filled_len = omxhdr->nFilledLen;
7286
7287 output_respbuf = (struct vdec_output_frameinfo *)\
7288 omxhdr->pOutputPortPrivate;
7289 output_respbuf->len = vdec_msg->msgdata.output_frame.len;
7290 output_respbuf->offset = vdec_msg->msgdata.output_frame.offset;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307291
Arun Menon906de572013-06-18 17:01:40 -07007292 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) {
7293 output_respbuf->pic_type = PICTURE_TYPE_I;
7294 }
7295 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) {
7296 output_respbuf->pic_type = PICTURE_TYPE_P;
7297 }
7298 if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) {
7299 output_respbuf->pic_type = PICTURE_TYPE_B;
7300 }
7301
Sri Karri38569452018-03-16 12:46:14 +05307302 if (!omx->m_enable_android_native_buffers &&
7303 omx->output_use_buffer)
Arun Menon906de572013-06-18 17:01:40 -07007304 memcpy ( omxhdr->pBuffer, (void *)
7305 ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr +
7306 (unsigned long)vdec_msg->msgdata.output_frame.offset),
7307 vdec_msg->msgdata.output_frame.len);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307308 } else {
7309 DEBUG_PRINT_ERROR("Invalid filled length = %u, buffer size = %u, prev_length = %u",
7310 (unsigned int)vdec_msg->msgdata.output_frame.len,
7311 omxhdr->nAllocLen, omx->prev_n_filled_len);
Arun Menon906de572013-06-18 17:01:40 -07007312 omxhdr->nFilledLen = 0;
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307313 }
7314
Arun Menon906de572013-06-18 17:01:40 -07007315 omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code,
7316 OMX_COMPONENT_GENERATE_FBD);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307317
7318 } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) {
Arun Menon906de572013-06-18 17:01:40 -07007319 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
7320 OMX_COMPONENT_GENERATE_EOS_DONE);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307321 } else {
Arun Menon906de572013-06-18 17:01:40 -07007322 omx->post_event ((unsigned int)NULL, vdec_msg->status_code,
7323 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
Maheshwar Ajjac366ad22014-07-09 17:31:13 +05307324 }
Arun Menon906de572013-06-18 17:01:40 -07007325 break;
7326 case VDEC_MSG_EVT_CONFIG_CHANGED:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007327 DEBUG_PRINT_HIGH("Port settings changed");
Arun Menon906de572013-06-18 17:01:40 -07007328 omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition,
7329 OMX_COMPONENT_GENERATE_PORT_RECONFIG);
7330 break;
7331 default:
7332 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007333 }
Arun Menon906de572013-06-18 17:01:40 -07007334 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007335}
7336
7337OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary (
Arun Menon906de572013-06-18 17:01:40 -07007338 OMX_HANDLETYPE hComp,
7339 OMX_BUFFERHEADERTYPE *buffer
7340 )
Shalaj Jain273b3e02012-06-22 19:08:03 -07007341{
Arun Menon906de572013-06-18 17:01:40 -07007342 unsigned address,p2,id;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007343 DEBUG_PRINT_LOW("Empty this arbitrary");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007344
Arun Menon906de572013-06-18 17:01:40 -07007345 if (buffer == NULL) {
7346 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007347 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007348 DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer);
7349 DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07007350 buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp);
7351
7352 /* return zero length and not an EOS buffer */
7353 /* return buffer if input flush in progress */
7354 if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) &&
7355 ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007356 DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress");
Arun Menon906de572013-06-18 17:01:40 -07007357 m_cb.EmptyBufferDone (hComp,m_app_data,buffer);
7358 return OMX_ErrorNone;
7359 }
7360
7361 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007362 DEBUG_PRINT_LOW("Set Buffer as source Buffer %p time stamp %lld",buffer,buffer->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07007363 psource_frame = buffer;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007364 DEBUG_PRINT_LOW("Try to Push One Input Buffer ");
Arun Menon906de572013-06-18 17:01:40 -07007365 push_input_buffer (hComp);
7366 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007367 DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer);
Arun Menon906de572013-06-18 17:01:40 -07007368 if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL,
7369 (unsigned)NULL)) {
7370 return OMX_ErrorBadParameter;
7371 }
7372 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007373
Sowmya Pandiri302f5ab2014-04-03 13:41:03 -07007374 if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
7375 codec_config_flag = false;
7376 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007377
Arun Menon906de572013-06-18 17:01:40 -07007378 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007379}
7380
7381OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp)
7382{
Arun Menon906de572013-06-18 17:01:40 -07007383 unsigned address,p2,id;
7384 OMX_ERRORTYPE ret = OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007385
Arun Menon906de572013-06-18 17:01:40 -07007386 if (pdest_frame == NULL || psource_frame == NULL) {
7387 /*Check if we have a destination buffer*/
7388 if (pdest_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007389 DEBUG_PRINT_LOW("Get a Destination buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07007390 if (m_input_free_q.m_size) {
7391 m_input_free_q.pop_entry(&address,&p2,&id);
7392 pdest_frame = (OMX_BUFFERHEADERTYPE *)address;
7393 pdest_frame->nFilledLen = 0;
7394 pdest_frame->nTimeStamp = LLONG_MAX;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007395 DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07007396 }
7397 }
7398
7399 /*Check if we have a destination buffer*/
7400 if (psource_frame == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007401 DEBUG_PRINT_LOW("Get a source buffer from the queue");
Arun Menon906de572013-06-18 17:01:40 -07007402 if (m_input_pending_q.m_size) {
7403 m_input_pending_q.pop_entry(&address,&p2,&id);
7404 psource_frame = (OMX_BUFFERHEADERTYPE *)address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007405 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07007406 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007407 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007408 psource_frame->nFlags,psource_frame->nFilledLen);
7409
7410 }
7411 }
7412
Shalaj Jain273b3e02012-06-22 19:08:03 -07007413 }
7414
Arun Menon906de572013-06-18 17:01:40 -07007415 while ((pdest_frame != NULL) && (psource_frame != NULL)) {
7416 switch (codec_type_parse) {
7417 case CODEC_TYPE_MPEG4:
7418 case CODEC_TYPE_H263:
7419 case CODEC_TYPE_MPEG2:
7420 ret = push_input_sc_codec(hComp);
7421 break;
7422 case CODEC_TYPE_H264:
7423 ret = push_input_h264(hComp);
7424 break;
7425 case CODEC_TYPE_VC1:
7426 ret = push_input_vc1(hComp);
7427 break;
7428 default:
7429 break;
7430 }
7431 if (ret != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007432 DEBUG_PRINT_ERROR("Pushing input Buffer Failed");
Arun Menon906de572013-06-18 17:01:40 -07007433 omx_report_error ();
7434 break;
7435 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007436 }
7437
Arun Menon906de572013-06-18 17:01:40 -07007438 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007439}
7440
7441OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp)
7442{
Arun Menon906de572013-06-18 17:01:40 -07007443 OMX_U32 partial_frame = 1;
7444 OMX_BOOL generate_ebd = OMX_TRUE;
7445 unsigned address = 0, p2 = 0, id = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007446
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007447 DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld",
Arun Menon906de572013-06-18 17:01:40 -07007448 psource_frame,psource_frame->nTimeStamp);
7449 if (m_frame_parser.parse_sc_frame(psource_frame,
7450 pdest_frame,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007451 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Arun Menon906de572013-06-18 17:01:40 -07007452 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007453 }
Arun Menon906de572013-06-18 17:01:40 -07007454
7455 if (partial_frame == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007456 DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d",
Arun Menon906de572013-06-18 17:01:40 -07007457 pdest_frame->nFilledLen,psource_frame,frame_count);
7458
7459
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007460 DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp);
Arun Menon906de572013-06-18 17:01:40 -07007461 /*First Parsed buffer will have only header Hence skip*/
7462 if (frame_count == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007463 DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame ");
Arun Menon906de572013-06-18 17:01:40 -07007464
7465 if (codec_type_parse == CODEC_TYPE_MPEG4 ||
7466 codec_type_parse == CODEC_TYPE_DIVX) {
7467 mp4StreamType psBits;
7468 psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset;
7469 psBits.numBytes = pdest_frame->nFilledLen;
7470 mp4_headerparser.parseHeader(&psBits);
7471 }
7472
7473 frame_count++;
7474 } else {
7475 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
7476 if (pdest_frame->nFilledLen) {
7477 /*Push the frame to the Decoder*/
7478 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7479 return OMX_ErrorBadParameter;
7480 }
7481 frame_count++;
7482 pdest_frame = NULL;
7483
7484 if (m_input_free_q.m_size) {
7485 m_input_free_q.pop_entry(&address,&p2,&id);
7486 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
7487 pdest_frame->nFilledLen = 0;
7488 }
7489 } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007490 DEBUG_PRINT_ERROR("Zero len buffer return back to POOL");
Arun Menon906de572013-06-18 17:01:40 -07007491 m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL,
7492 (unsigned)NULL);
7493 pdest_frame = NULL;
7494 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007495 }
Arun Menon906de572013-06-18 17:01:40 -07007496 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007497 DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007498 /*Check if Destination Buffer is full*/
7499 if (pdest_frame->nAllocLen ==
7500 pdest_frame->nFilledLen + pdest_frame->nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007501 DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07007502 return OMX_ErrorStreamCorrupt;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007503 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007504 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007505
Arun Menon906de572013-06-18 17:01:40 -07007506 if (psource_frame->nFilledLen == 0) {
7507 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
7508 if (pdest_frame) {
7509 pdest_frame->nFlags |= psource_frame->nFlags;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007510 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld",
Arun Menon906de572013-06-18 17:01:40 -07007511 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007512 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07007513 pdest_frame->nFilledLen,frame_count++);
7514 /*Push the frame to the Decoder*/
7515 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7516 return OMX_ErrorBadParameter;
7517 }
7518 frame_count++;
7519 pdest_frame = NULL;
7520 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007521 DEBUG_PRINT_LOW("Last frame in else dest addr") ;
Arun Menon906de572013-06-18 17:01:40 -07007522 generate_ebd = OMX_FALSE;
7523 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007524 }
Arun Menon906de572013-06-18 17:01:40 -07007525 if (generate_ebd) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007526 DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007527 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
7528 psource_frame = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007529
Arun Menon906de572013-06-18 17:01:40 -07007530 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007531 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007532 m_input_pending_q.pop_entry(&address,&p2,&id);
7533 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007534 DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame,
Arun Menon906de572013-06-18 17:01:40 -07007535 psource_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007536 DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007537 psource_frame->nFlags,psource_frame->nFilledLen);
7538 }
7539 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007540 }
Arun Menon906de572013-06-18 17:01:40 -07007541 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007542}
7543
7544OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp)
7545{
Arun Menon906de572013-06-18 17:01:40 -07007546 OMX_U32 partial_frame = 1;
7547 unsigned address = 0, p2 = 0, id = 0;
7548 OMX_BOOL isNewFrame = OMX_FALSE;
7549 OMX_BOOL generate_ebd = OMX_TRUE;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007550
Arun Menon906de572013-06-18 17:01:40 -07007551 if (h264_scratch.pBuffer == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007552 DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated");
Arun Menon906de572013-06-18 17:01:40 -07007553 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007554 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007555 DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu "
Arun Menon906de572013-06-18 17:01:40 -07007556 "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007557 DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007558 if (h264_scratch.nFilledLen && look_ahead_nal) {
7559 look_ahead_nal = false;
7560 if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7561 h264_scratch.nFilledLen) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007562 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7563 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7564 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007565 DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007566 h264_scratch.nFilledLen = 0;
Arun Menon906de572013-06-18 17:01:40 -07007567 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007568 DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007569 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007570 }
Arun Menon906de572013-06-18 17:01:40 -07007571 }
Praveen Chavance0b5e82013-08-08 05:23:34 -07007572
7573 /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result
7574 in EOS flag getting associated with the destination
7575 */
7576 if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) &&
7577 pdest_frame->nFilledLen) {
7578 DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'");
7579 generate_ebd = OMX_FALSE;
7580 }
7581
Arun Menon906de572013-06-18 17:01:40 -07007582 if (nal_length == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007583 DEBUG_PRINT_LOW("Zero NAL, hence parse using start code");
Arun Menon906de572013-06-18 17:01:40 -07007584 if (m_frame_parser.parse_sc_frame(psource_frame,
7585 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007586 DEBUG_PRINT_ERROR("Error In Parsing Return Error");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007587 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007588 }
Arun Menon906de572013-06-18 17:01:40 -07007589 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007590 DEBUG_PRINT_LOW("Non-zero NAL length clip, hence parse with NAL size %d ",nal_length);
Arun Menon906de572013-06-18 17:01:40 -07007591 if (m_frame_parser.parse_h264_nallength(psource_frame,
7592 &h264_scratch,&partial_frame) == -1) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007593 DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error");
Arun Menon906de572013-06-18 17:01:40 -07007594 return OMX_ErrorBadParameter;
7595 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007596 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007597
Arun Menon906de572013-06-18 17:01:40 -07007598 if (partial_frame == 0) {
7599 if (nal_count == 0 && h264_scratch.nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007600 DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip");
Arun Menon906de572013-06-18 17:01:40 -07007601 nal_count++;
7602 h264_scratch.nTimeStamp = psource_frame->nTimeStamp;
7603 h264_scratch.nFlags = psource_frame->nFlags;
7604 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007605 DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007606 if (h264_scratch.nFilledLen) {
7607 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen,
7608 NALU_TYPE_SPS);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007609#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
Arun Menon906de572013-06-18 17:01:40 -07007610 if (client_extradata & OMX_TIMEINFO_EXTRADATA)
7611 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7612 h264_scratch.nFilledLen, NALU_TYPE_SEI);
7613 else if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7614 // If timeinfo is present frame info from SEI is already processed
7615 h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer,
7616 h264_scratch.nFilledLen, NALU_TYPE_SEI);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007617#endif
Arun Menon906de572013-06-18 17:01:40 -07007618 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7619 nal_count++;
7620 if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) {
7621 pdest_frame->nTimeStamp = h264_last_au_ts;
7622 pdest_frame->nFlags = h264_last_au_flags;
7623#ifdef PANSCAN_HDLR
7624 if (client_extradata & OMX_FRAMEINFO_EXTRADATA)
7625 h264_parser->update_panscan_data(h264_last_au_ts);
7626#endif
7627 }
7628 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR ||
7629 m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) {
7630 h264_last_au_ts = h264_scratch.nTimeStamp;
7631 h264_last_au_flags = h264_scratch.nFlags;
7632#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7633 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7634 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts);
7635 if (!VALID_TS(h264_last_au_ts))
7636 h264_last_au_ts = ts_in_sei;
7637 }
7638#endif
7639 } else
7640 h264_last_au_ts = LLONG_MAX;
7641 }
7642
7643 if (!isNewFrame) {
7644 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7645 h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007646 DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu",
Arun Menon906de572013-06-18 17:01:40 -07007647 h264_scratch.nFilledLen);
7648 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7649 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7650 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7651 if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ)
7652 pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ;
7653 h264_scratch.nFilledLen = 0;
7654 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007655 DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007656 return OMX_ErrorBadParameter;
7657 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007658 } else if(h264_scratch.nFilledLen) {
Arun Menon906de572013-06-18 17:01:40 -07007659 look_ahead_nal = true;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007660 DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007661 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007662 DEBUG_PRINT_LOW("Found a frame size = %lu number = %d",
Arun Menon906de572013-06-18 17:01:40 -07007663 pdest_frame->nFilledLen,frame_count++);
7664
7665 if (pdest_frame->nFilledLen == 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007666 DEBUG_PRINT_LOW("Copy the Current Frame since and push it");
Arun Menon906de572013-06-18 17:01:40 -07007667 look_ahead_nal = false;
7668 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7669 h264_scratch.nFilledLen) {
7670 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7671 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7672 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7673 h264_scratch.nFilledLen = 0;
7674 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007675 DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007676 return OMX_ErrorBadParameter;
7677 }
7678 } else {
7679 if (psource_frame->nFilledLen || h264_scratch.nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007680 DEBUG_PRINT_LOW("Reset the EOS Flag");
Arun Menon906de572013-06-18 17:01:40 -07007681 pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS;
7682 }
7683 /*Push the frame to the Decoder*/
7684 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7685 return OMX_ErrorBadParameter;
7686 }
7687 //frame_count++;
7688 pdest_frame = NULL;
7689 if (m_input_free_q.m_size) {
7690 m_input_free_q.pop_entry(&address,&p2,&id);
7691 pdest_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007692 DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame);
Arun Menon906de572013-06-18 17:01:40 -07007693 pdest_frame->nFilledLen = 0;
7694 pdest_frame->nFlags = 0;
7695 pdest_frame->nTimeStamp = LLONG_MAX;
7696 }
7697 }
7698 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007699 }
Arun Menon906de572013-06-18 17:01:40 -07007700 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007701 DEBUG_PRINT_LOW("Not a Complete Frame, pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen);
Arun Menon906de572013-06-18 17:01:40 -07007702 /*Check if Destination Buffer is full*/
7703 if (h264_scratch.nAllocLen ==
7704 h264_scratch.nFilledLen + h264_scratch.nOffset) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007705 DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled");
Arun Menon906de572013-06-18 17:01:40 -07007706 return OMX_ErrorStreamCorrupt;
7707 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007708 }
Arun Menon906de572013-06-18 17:01:40 -07007709
7710 if (!psource_frame->nFilledLen) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007711 DEBUG_PRINT_LOW("Buffer Consumed return source %p back to client",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007712
7713 if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) {
7714 if (pdest_frame) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007715 DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer");
Arun Menon906de572013-06-18 17:01:40 -07007716 if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >=
7717 h264_scratch.nFilledLen) {
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007718 if(pdest_frame->nFilledLen == 0) {
7719 /* No residual frame from before, send whatever
7720 * we have left */
7721 memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7722 h264_scratch.pBuffer, h264_scratch.nFilledLen);
7723 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7724 h264_scratch.nFilledLen = 0;
7725 pdest_frame->nTimeStamp = h264_scratch.nTimeStamp;
7726 } else {
7727 m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame);
7728 if(!isNewFrame) {
7729 /* Have a residual frame, but we know that the
7730 * AU in this frame is belonging to whatever
7731 * frame we had left over. So append it */
7732 memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen),
7733 h264_scratch.pBuffer,h264_scratch.nFilledLen);
7734 pdest_frame->nFilledLen += h264_scratch.nFilledLen;
7735 h264_scratch.nFilledLen = 0;
Balamurugan Alagarsamyefde3832014-09-22 19:52:20 +05307736 if (h264_last_au_ts != LLONG_MAX)
7737 pdest_frame->nTimeStamp = h264_last_au_ts;
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007738 } else {
7739 /* Completely new frame, let's just push what
7740 * we have now. The resulting EBD would trigger
7741 * another push */
7742 generate_ebd = OMX_FALSE;
7743 pdest_frame->nTimeStamp = h264_last_au_ts;
7744 h264_last_au_ts = h264_scratch.nTimeStamp;
7745 }
7746 }
Arun Menon906de572013-06-18 17:01:40 -07007747 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007748 DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264");
Arun Menon906de572013-06-18 17:01:40 -07007749 return OMX_ErrorBadParameter;
7750 }
Leena Winterrowd5a974ce2013-08-06 15:10:36 -07007751
7752 /* Iff we coalesced two buffers, inherit the flags of both bufs */
7753 if(generate_ebd == OMX_TRUE) {
7754 pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags;
7755 }
Arun Menon906de572013-06-18 17:01:40 -07007756
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007757 DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu",
Arun Menon906de572013-06-18 17:01:40 -07007758 pdest_frame->nFilledLen,pdest_frame->nTimeStamp);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007759 DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++);
Arun Menon906de572013-06-18 17:01:40 -07007760#ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT
7761 if (client_extradata & OMX_TIMEINFO_EXTRADATA) {
7762 OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp);
7763 if (!VALID_TS(pdest_frame->nTimeStamp))
7764 pdest_frame->nTimeStamp = ts_in_sei;
7765 }
7766#endif
7767 /*Push the frame to the Decoder*/
7768 if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) {
7769 return OMX_ErrorBadParameter;
7770 }
7771 frame_count++;
7772 pdest_frame = NULL;
7773 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007774 DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu",
Arun Menon906de572013-06-18 17:01:40 -07007775 pdest_frame,h264_scratch.nFilledLen);
7776 generate_ebd = OMX_FALSE;
7777 }
7778 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007779 }
Arun Menon906de572013-06-18 17:01:40 -07007780 if (generate_ebd && !psource_frame->nFilledLen) {
7781 m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame);
7782 psource_frame = NULL;
7783 if (m_input_pending_q.m_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007784 DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame);
Arun Menon906de572013-06-18 17:01:40 -07007785 m_input_pending_q.pop_entry(&address,&p2,&id);
7786 psource_frame = (OMX_BUFFERHEADERTYPE *) address;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007787 DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu",
Arun Menon906de572013-06-18 17:01:40 -07007788 psource_frame->nFlags,psource_frame->nFilledLen);
7789 }
7790 }
7791 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007792}
7793
7794OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp)
7795{
7796 OMX_U8 *buf, *pdest;
7797 OMX_U32 partial_frame = 1;
7798 OMX_U32 buf_len, dest_len;
7799
Arun Menon906de572013-06-18 17:01:40 -07007800 if (first_frame == 0) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007801 first_frame = 1;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007802 DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes");
Arun Menon906de572013-06-18 17:01:40 -07007803 if (!m_vendor_config.pData) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007804 DEBUG_PRINT_LOW("Check profile type in 1st source buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007805 buf = psource_frame->pBuffer;
7806 buf_len = psource_frame->nFilledLen;
7807
7808 if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) ==
Arun Menon906de572013-06-18 17:01:40 -07007809 VC1_SP_MP_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007810 m_vc1_profile = VC1_SP_MP_RCV;
Arun Menon906de572013-06-18 17:01:40 -07007811 } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007812 m_vc1_profile = VC1_AP;
Arun Menon906de572013-06-18 17:01:40 -07007813 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007814 DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007815 return OMX_ErrorStreamCorrupt;
7816 }
Arun Menon906de572013-06-18 17:01:40 -07007817 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007818 pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen +
7819 pdest_frame->nOffset;
7820 dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen +
Arun Menon906de572013-06-18 17:01:40 -07007821 pdest_frame->nOffset);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007822
Arun Menon906de572013-06-18 17:01:40 -07007823 if (dest_len < m_vendor_config.nDataSize) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007824 DEBUG_PRINT_ERROR("Destination buffer full");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007825 return OMX_ErrorBadParameter;
Arun Menon906de572013-06-18 17:01:40 -07007826 } else {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007827 memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize);
7828 pdest_frame->nFilledLen += m_vendor_config.nDataSize;
7829 }
7830 }
7831 }
7832
Arun Menon906de572013-06-18 17:01:40 -07007833 switch (m_vc1_profile) {
Shalaj Jain273b3e02012-06-22 19:08:03 -07007834 case VC1_AP:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007835 DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code");
Arun Menon906de572013-06-18 17:01:40 -07007836 if (push_input_sc_codec(hComp) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007837 DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007838 return OMX_ErrorBadParameter;
7839 }
Arun Menon906de572013-06-18 17:01:40 -07007840 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007841
7842 case VC1_SP_MP_RCV:
7843 default:
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007844 DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode");
Shalaj Jain273b3e02012-06-22 19:08:03 -07007845 return OMX_ErrorBadParameter;
7846 }
7847 return OMX_ErrorNone;
7848}
7849
David Ng38e2d232013-03-15 20:05:58 -07007850#ifndef USE_ION
Shalaj Jain273b3e02012-06-22 19:08:03 -07007851bool omx_vdec::align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007852 OMX_U32 alignment)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007853{
Arun Menon906de572013-06-18 17:01:40 -07007854 struct pmem_allocation allocation;
7855 allocation.size = buffer_size;
7856 allocation.align = clip2(alignment);
7857 if (allocation.align < 4096) {
7858 allocation.align = 4096;
7859 }
7860 if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007861 DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)",
Arun Menon906de572013-06-18 17:01:40 -07007862 allocation.align, allocation.size);
7863 return false;
7864 }
7865 return true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007866}
David Ng38e2d232013-03-15 20:05:58 -07007867#endif
Shalaj Jain273b3e02012-06-22 19:08:03 -07007868#ifdef USE_ION
7869int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size,
Arun Menon906de572013-06-18 17:01:40 -07007870 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
7871 struct ion_fd_data *fd_data, int flag)
Shalaj Jain273b3e02012-06-22 19:08:03 -07007872{
Arun Menon906de572013-06-18 17:01:40 -07007873 int fd = -EINVAL;
7874 int rc = -EINVAL;
7875 int ion_dev_flag;
7876 struct vdec_ion ion_buf_info;
7877 if (!alloc_data || buffer_size <= 0 || !fd_data) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007878 DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory");
Arun Menon906de572013-06-18 17:01:40 -07007879 return -EINVAL;
7880 }
7881 ion_dev_flag = O_RDONLY;
7882 fd = open (MEM_DEVICE, ion_dev_flag);
7883 if (fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007884 DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd);
Arun Menon906de572013-06-18 17:01:40 -07007885 return fd;
7886 }
7887 alloc_data->flags = 0;
7888 if (!secure_mode && (flag & ION_FLAG_CACHED)) {
7889 alloc_data->flags |= ION_FLAG_CACHED;
7890 }
7891 alloc_data->len = buffer_size;
7892 alloc_data->align = clip2(alignment);
7893 if (alloc_data->align < 4096) {
7894 alloc_data->align = 4096;
7895 }
7896 if ((secure_mode) && (flag & ION_SECURE))
7897 alloc_data->flags |= ION_SECURE;
Vinay Kalia53fa6832012-10-11 17:55:30 -07007898
Arun Menon906de572013-06-18 17:01:40 -07007899 alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05307900 if (secure_mode && (alloc_data->flags & ION_SECURE))
Arun Menon906de572013-06-18 17:01:40 -07007901 alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID);
7902 rc = ioctl(fd,ION_IOC_ALLOC,alloc_data);
7903 if (rc || !alloc_data->handle) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007904 DEBUG_PRINT_ERROR("ION ALLOC memory failed ");
Arun Menon906de572013-06-18 17:01:40 -07007905 alloc_data->handle = NULL;
7906 close(fd);
7907 fd = -ENOMEM;
7908 return fd;
7909 }
7910 fd_data->handle = alloc_data->handle;
7911 rc = ioctl(fd,ION_IOC_MAP,fd_data);
7912 if (rc) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007913 DEBUG_PRINT_ERROR("ION MAP failed ");
Arun Menon906de572013-06-18 17:01:40 -07007914 ion_buf_info.ion_alloc_data = *alloc_data;
7915 ion_buf_info.ion_device_fd = fd;
7916 ion_buf_info.fd_ion_data = *fd_data;
7917 free_ion_memory(&ion_buf_info);
7918 fd_data->fd =-1;
Arun Menon906de572013-06-18 17:01:40 -07007919 fd = -ENOMEM;
7920 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007921
Arun Menon906de572013-06-18 17:01:40 -07007922 return fd;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007923}
7924
Arun Menon906de572013-06-18 17:01:40 -07007925void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info)
7926{
Shalaj Jain273b3e02012-06-22 19:08:03 -07007927
Arun Menon906de572013-06-18 17:01:40 -07007928 if (!buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007929 DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata");
Arun Menon906de572013-06-18 17:01:40 -07007930 return;
7931 }
7932 if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE,
7933 &buf_ion_info->ion_alloc_data.handle)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007934 DEBUG_PRINT_ERROR("ION: free failed" );
Arun Menon906de572013-06-18 17:01:40 -07007935 }
7936 close(buf_ion_info->ion_device_fd);
7937 buf_ion_info->ion_device_fd = -1;
7938 buf_ion_info->ion_alloc_data.handle = NULL;
7939 buf_ion_info->fd_ion_data.fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007940}
7941#endif
7942void omx_vdec::free_output_buffer_header()
7943{
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007944 DEBUG_PRINT_HIGH("ALL output buffers are freed/released");
Arun Menon906de572013-06-18 17:01:40 -07007945 output_use_buffer = false;
7946 ouput_egl_buffers = false;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007947
Arun Menon906de572013-06-18 17:01:40 -07007948 if (m_out_mem_ptr) {
7949 free (m_out_mem_ptr);
7950 m_out_mem_ptr = NULL;
7951 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007952
Arun Menon906de572013-06-18 17:01:40 -07007953 if (m_platform_list) {
7954 free(m_platform_list);
7955 m_platform_list = NULL;
7956 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007957
Arun Menon906de572013-06-18 17:01:40 -07007958 if (drv_ctx.ptr_respbuffer) {
7959 free (drv_ctx.ptr_respbuffer);
7960 drv_ctx.ptr_respbuffer = NULL;
7961 }
7962 if (drv_ctx.ptr_outputbuffer) {
7963 free (drv_ctx.ptr_outputbuffer);
7964 drv_ctx.ptr_outputbuffer = NULL;
7965 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007966#ifdef USE_ION
7967 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007968 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07007969 free(drv_ctx.op_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07007970 drv_ctx.op_buf_ion_info = NULL;
7971 }
7972#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07007973 if (out_dynamic_list) {
7974 free(out_dynamic_list);
7975 out_dynamic_list = NULL;
7976 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007977}
7978
7979void omx_vdec::free_input_buffer_header()
7980{
7981 input_use_buffer = false;
Arun Menon906de572013-06-18 17:01:40 -07007982 if (arbitrary_bytes) {
Arun Menon906de572013-06-18 17:01:40 -07007983 if (m_inp_heap_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007984 DEBUG_PRINT_LOW("Free input Heap Pointer");
Arun Menon906de572013-06-18 17:01:40 -07007985 free (m_inp_heap_ptr);
7986 m_inp_heap_ptr = NULL;
7987 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007988
Arun Menon906de572013-06-18 17:01:40 -07007989 if (m_phdr_pmem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007990 DEBUG_PRINT_LOW("Free input pmem header Pointer");
Arun Menon906de572013-06-18 17:01:40 -07007991 free (m_phdr_pmem_ptr);
7992 m_phdr_pmem_ptr = NULL;
7993 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07007994 }
Arun Menon906de572013-06-18 17:01:40 -07007995 if (m_inp_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07007996 DEBUG_PRINT_LOW("Free input pmem Pointer area");
Arun Menon906de572013-06-18 17:01:40 -07007997 free (m_inp_mem_ptr);
7998 m_inp_mem_ptr = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07007999 }
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07008000 /* We just freed all the buffer headers, every thing in m_input_free_q,
8001 * m_input_pending_q, pdest_frame, and psource_frame is now invalid */
Leena Winterrowd1d2424a2013-08-20 15:26:02 -07008002 while (m_input_free_q.m_size) {
8003 unsigned address, p2, id;
8004 m_input_free_q.pop_entry(&address, &p2, &id);
8005 }
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07008006 while (m_input_pending_q.m_size) {
8007 unsigned address, p2, id;
8008 m_input_pending_q.pop_entry(&address, &p2, &id);
8009 }
8010 pdest_frame = NULL;
8011 psource_frame = NULL;
Arun Menon906de572013-06-18 17:01:40 -07008012 if (drv_ctx.ptr_inputbuffer) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008013 DEBUG_PRINT_LOW("Free Driver Context pointer");
Arun Menon906de572013-06-18 17:01:40 -07008014 free (drv_ctx.ptr_inputbuffer);
8015 drv_ctx.ptr_inputbuffer = NULL;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008016 }
8017#ifdef USE_ION
8018 if (drv_ctx.ip_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008019 DEBUG_PRINT_LOW("Free ion context");
Arun Menon906de572013-06-18 17:01:40 -07008020 free(drv_ctx.ip_buf_ion_info);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008021 drv_ctx.ip_buf_ion_info = NULL;
8022 }
8023#endif
8024}
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008025
8026int omx_vdec::stream_off(OMX_U32 port)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008027{
Arun Menon906de572013-06-18 17:01:40 -07008028 enum v4l2_buf_type btype;
8029 int rc = 0;
8030 enum v4l2_ports v4l2_port = OUTPUT_PORT;
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008031
Arun Menon906de572013-06-18 17:01:40 -07008032 if (port == OMX_CORE_INPUT_PORT_INDEX) {
8033 btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8034 v4l2_port = OUTPUT_PORT;
8035 } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) {
8036 btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8037 v4l2_port = CAPTURE_PORT;
8038 } else if (port == OMX_ALL) {
8039 int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX);
8040 int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008041
Arun Menon906de572013-06-18 17:01:40 -07008042 if (!rc_input)
8043 return rc_input;
8044 else
8045 return rc_output;
8046 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008047
Arun Menon906de572013-06-18 17:01:40 -07008048 if (!streaming[v4l2_port]) {
8049 // already streamed off, warn and move on
8050 DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port,"
8051 " which is already streamed off", v4l2_port);
8052 return 0;
8053 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008054
Arun Menon906de572013-06-18 17:01:40 -07008055 DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port);
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008056
Arun Menon906de572013-06-18 17:01:40 -07008057 rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype);
8058 if (rc) {
8059 /*TODO: How to handle this case */
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008060 DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port);
Arun Menon906de572013-06-18 17:01:40 -07008061 } else {
8062 streaming[v4l2_port] = false;
8063 }
Deva Ramasubramanianf97488b2012-10-26 18:37:05 -07008064
Arun Menon906de572013-06-18 17:01:40 -07008065 return rc;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008066}
8067
8068OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop)
8069{
Arun Menon906de572013-06-18 17:01:40 -07008070 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8071 struct v4l2_requestbuffers bufreq;
Deva Ramasubramanian991d0db2014-05-08 15:02:24 -07008072 unsigned int buf_size = 0, extra_data_size = 0, default_extra_data_size = 0;
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308073 unsigned int final_extra_data_size = 0;
Arun Menon906de572013-06-18 17:01:40 -07008074 struct v4l2_format fmt;
8075 int ret = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008076 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
Arun Menon906de572013-06-18 17:01:40 -07008077 buffer_prop->actualcount, buffer_prop->buffer_size);
8078 bufreq.memory = V4L2_MEMORY_USERPTR;
8079 bufreq.count = 1;
8080 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8081 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8082 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8083 fmt.fmt.pix_mp.pixelformat = output_capability;
8084 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8085 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8086 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8087 fmt.fmt.pix_mp.pixelformat = capture_capability;
8088 } else {
8089 eRet = OMX_ErrorBadParameter;
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07008090 }
Arun Menon906de572013-06-18 17:01:40 -07008091 if (eRet==OMX_ErrorNone) {
8092 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008093 }
Arun Menon906de572013-06-18 17:01:40 -07008094 if (ret) {
8095 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
8096 /*TODO: How to handle this case */
8097 eRet = OMX_ErrorInsufficientResources;
8098 return eRet;
8099 } else {
8100 buffer_prop->actualcount = bufreq.count;
8101 buffer_prop->mincount = bufreq.count;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008102 DEBUG_PRINT_HIGH("Count = %d",bufreq.count);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008103 }
Arun Menon906de572013-06-18 17:01:40 -07008104 DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)",
8105 buffer_prop->actualcount, buffer_prop->buffer_size);
8106
8107 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
8108 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
8109
8110 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
8111
8112 update_resolution(fmt.fmt.pix_mp.width,
8113 fmt.fmt.pix_mp.height,
8114 fmt.fmt.pix_mp.plane_fmt[0].bytesperline,
8115 fmt.fmt.pix_mp.plane_fmt[0].reserved[0]);
8116 if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
8117 drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008118 DEBUG_PRINT_HIGH("Buffer Size = %d",fmt.fmt.pix_mp.plane_fmt[0].sizeimage);
Arun Menon906de572013-06-18 17:01:40 -07008119
8120 if (ret) {
8121 /*TODO: How to handle this case */
8122 DEBUG_PRINT_ERROR("Requesting buffer requirements failed");
8123 eRet = OMX_ErrorInsufficientResources;
8124 } else {
8125 int extra_idx = 0;
8126
8127 eRet = is_video_session_supported();
8128 if (eRet)
8129 return eRet;
8130
8131 buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage;
8132 buf_size = buffer_prop->buffer_size;
8133 extra_idx = EXTRADATA_IDX(drv_ctx.num_planes);
8134 if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) {
8135 extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage;
8136 } else if (extra_idx >= VIDEO_MAX_PLANES) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008137 DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx);
Arun Menon906de572013-06-18 17:01:40 -07008138 return OMX_ErrorBadParameter;
8139 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008140
Deva Ramasubramanian991d0db2014-05-08 15:02:24 -07008141 default_extra_data_size = VENUS_EXTRADATA_SIZE(
8142 drv_ctx.video_resolution.frame_height,
8143 drv_ctx.video_resolution.frame_width);
8144 final_extra_data_size = extra_data_size > default_extra_data_size ?
8145 extra_data_size : default_extra_data_size;
8146
8147 final_extra_data_size = (final_extra_data_size + buffer_prop->alignment - 1) &
8148 (~(buffer_prop->alignment - 1));
Deva Ramasubramanian2ebfed32014-04-24 13:34:24 -07008149
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308150 drv_ctx.extradata_info.size = buffer_prop->actualcount * final_extra_data_size;
Arun Menon906de572013-06-18 17:01:40 -07008151 drv_ctx.extradata_info.count = buffer_prop->actualcount;
Pushkaraj Patil1ab10292014-02-11 20:10:42 +05308152 drv_ctx.extradata_info.buffer_size = final_extra_data_size;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308153 if (!secure_mode)
8154 buf_size += final_extra_data_size;
Arun Menon906de572013-06-18 17:01:40 -07008155 buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
8156 DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)",
8157 buffer_prop->actualcount, buffer_prop->buffer_size, buf_size);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008158 if (extra_data_size)
8159 DEBUG_PRINT_LOW("GetBufReq UPDATE: extradata: TotalSize(%d) BufferSize(%d)",
8160 drv_ctx.extradata_info.size, drv_ctx.extradata_info.buffer_size);
8161
Arun Menon906de572013-06-18 17:01:40 -07008162 if (in_reconfig) // BufReq will be set to driver when port is disabled
8163 buffer_prop->buffer_size = buf_size;
8164 else if (buf_size != buffer_prop->buffer_size) {
8165 buffer_prop->buffer_size = buf_size;
8166 eRet = set_buffer_req(buffer_prop);
8167 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008168 }
Arun Menon906de572013-06-18 17:01:40 -07008169 DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)",
8170 buffer_prop->actualcount, buffer_prop->buffer_size);
8171 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008172}
8173
8174OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop)
8175{
Arun Menon906de572013-06-18 17:01:40 -07008176 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8177 unsigned buf_size = 0;
8178 struct v4l2_format fmt;
8179 struct v4l2_requestbuffers bufreq;
8180 int ret;
8181 DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)",
8182 buffer_prop->actualcount, buffer_prop->buffer_size);
8183 buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1));
8184 if (buf_size != buffer_prop->buffer_size) {
8185 DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)",
8186 buffer_prop->buffer_size, buf_size);
8187 eRet = OMX_ErrorBadParameter;
8188 } else {
8189 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
8190 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07008191
Arun Menon906de572013-06-18 17:01:40 -07008192 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8193 fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8194 fmt.fmt.pix_mp.pixelformat = output_capability;
Shalaj Jaind3902bb2013-10-07 12:42:55 -07008195 fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size;
Arun Menon906de572013-06-18 17:01:40 -07008196 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8197 fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8198 fmt.fmt.pix_mp.pixelformat = capture_capability;
8199 } else {
8200 eRet = OMX_ErrorBadParameter;
8201 }
Deva Ramasubramanian614f79e2012-08-10 21:42:10 -07008202
Arun Menon906de572013-06-18 17:01:40 -07008203 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
8204 if (ret) {
8205 /*TODO: How to handle this case */
8206 DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret);
8207 eRet = OMX_ErrorInsufficientResources;
8208 }
8209
8210 bufreq.memory = V4L2_MEMORY_USERPTR;
8211 bufreq.count = buffer_prop->actualcount;
8212 if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) {
8213 bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8214 } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) {
8215 bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8216 } else {
8217 eRet = OMX_ErrorBadParameter;
8218 }
8219
8220 if (eRet==OMX_ErrorNone) {
8221 ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq);
8222 }
8223
8224 if (ret) {
8225 DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret);
8226 /*TODO: How to handle this case */
8227 eRet = OMX_ErrorInsufficientResources;
8228 } else if (bufreq.count < buffer_prop->actualcount) {
8229 DEBUG_PRINT_ERROR("Driver refused to change the number of buffers"
8230 " on v4l2 port %d to %d (prefers %d)", bufreq.type,
8231 buffer_prop->actualcount, bufreq.count);
8232 eRet = OMX_ErrorInsufficientResources;
8233 } else {
8234 if (!client_buffers.update_buffer_req()) {
8235 DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed");
8236 eRet = OMX_ErrorInsufficientResources;
8237 }
8238 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008239 }
Arun Menon906de572013-06-18 17:01:40 -07008240 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008241}
8242
Shalaj Jain273b3e02012-06-22 19:08:03 -07008243OMX_ERRORTYPE omx_vdec::update_picture_resolution()
8244{
Arun Menon906de572013-06-18 17:01:40 -07008245 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8246 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008247}
8248
8249OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn)
8250{
Arun Menon906de572013-06-18 17:01:40 -07008251 OMX_ERRORTYPE eRet = OMX_ErrorNone;
Pushkaraj Patil41588352014-02-25 20:51:34 +05308252 struct v4l2_format fmt;
Arun Menon906de572013-06-18 17:01:40 -07008253 if (!portDefn) {
8254 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008255 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008256 DEBUG_PRINT_LOW("omx_vdec::update_portdef");
Arun Menon906de572013-06-18 17:01:40 -07008257 portDefn->nVersion.nVersion = OMX_SPEC_VERSION;
Praveen Chavan366ded52016-04-11 17:33:02 -07008258 portDefn->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
Arun Menon906de572013-06-18 17:01:40 -07008259 portDefn->eDomain = OMX_PortDomainVideo;
8260 if (drv_ctx.frame_rate.fps_denominator > 0)
Deva Ramasubramanian9ba5d832014-01-03 18:32:50 -08008261 portDefn->format.video.xFramerate = (drv_ctx.frame_rate.fps_numerator /
8262 drv_ctx.frame_rate.fps_denominator) << 16; //Q16 format
Arun Menon906de572013-06-18 17:01:40 -07008263 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008264 DEBUG_PRINT_ERROR("Error: Divide by zero");
Arun Menon906de572013-06-18 17:01:40 -07008265 return OMX_ErrorBadParameter;
Vinay Kaliada4f4422013-01-09 10:45:03 -08008266 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308267 memset(&fmt, 0x0, sizeof(struct v4l2_format));
Arun Menon906de572013-06-18 17:01:40 -07008268 if (0 == portDefn->nPortIndex) {
8269 portDefn->eDir = OMX_DirInput;
8270 portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount;
8271 portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount;
8272 portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size;
8273 portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused;
8274 portDefn->format.video.eCompressionFormat = eCompressionFormat;
8275 portDefn->bEnabled = m_inp_bEnabled;
8276 portDefn->bPopulated = m_inp_bPopulated;
Pushkaraj Patil41588352014-02-25 20:51:34 +05308277
8278 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8279 fmt.fmt.pix_mp.pixelformat = output_capability;
Arun Menon906de572013-06-18 17:01:40 -07008280 } else if (1 == portDefn->nPortIndex) {
8281 unsigned int buf_size = 0;
8282 if (!client_buffers.update_buffer_req()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008283 DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed");
Arun Menon906de572013-06-18 17:01:40 -07008284 return OMX_ErrorHardware;
8285 }
8286 if (!client_buffers.get_buffer_req(buf_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008287 DEBUG_PRINT_ERROR("update buffer requirements");
Arun Menon906de572013-06-18 17:01:40 -07008288 return OMX_ErrorHardware;
8289 }
8290 portDefn->nBufferSize = buf_size;
8291 portDefn->eDir = OMX_DirOutput;
8292 portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount;
8293 portDefn->nBufferCountMin = drv_ctx.op_buf.mincount;
8294 portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
8295 portDefn->bEnabled = m_out_bEnabled;
8296 portDefn->bPopulated = m_out_bPopulated;
8297 if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008298 DEBUG_PRINT_ERROR("Error in getting color format");
Arun Menon906de572013-06-18 17:01:40 -07008299 return OMX_ErrorHardware;
8300 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308301 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
8302 fmt.fmt.pix_mp.pixelformat = capture_capability;
Arun Menon906de572013-06-18 17:01:40 -07008303 } else {
8304 portDefn->eDir = OMX_DirMax;
8305 DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d",
8306 (int)portDefn->nPortIndex);
8307 eRet = OMX_ErrorBadPortIndex;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008308 }
Pushkaraj Patil41588352014-02-25 20:51:34 +05308309 if (is_down_scalar_enabled) {
8310 int ret = 0;
8311 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
8312 if (ret) {
8313 DEBUG_PRINT_ERROR("update_portdef : Error in getting port resolution");
8314 return OMX_ErrorHardware;
8315 } else {
8316 portDefn->format.video.nFrameWidth = fmt.fmt.pix_mp.width;
8317 portDefn->format.video.nFrameHeight = fmt.fmt.pix_mp.height;
8318 portDefn->format.video.nStride = fmt.fmt.pix_mp.plane_fmt[0].bytesperline;
8319 portDefn->format.video.nSliceHeight = fmt.fmt.pix_mp.plane_fmt[0].reserved[0];
8320 }
8321 } else {
8322 portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height;
8323 portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width;
8324 portDefn->format.video.nStride = drv_ctx.video_resolution.stride;
8325 portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines;
8326 }
8327
Praveen Chavandb7776f2014-02-06 18:17:25 -08008328 if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) ||
8329 (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) {
Maheshwar Ajja77cd19c2014-06-05 11:23:18 +05308330 portDefn->format.video.nStride = ALIGN(drv_ctx.video_resolution.frame_width, 16);
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308331 portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height;
8332 }
8333 DEBUG_PRINT_HIGH("update_portdef(%lu): Width = %lu Height = %lu Stride = %ld "
8334 "SliceHeight = %lu eColorFormat = %lu nBufSize %lu nBufCnt %lu",
8335 portDefn->nPortIndex,
8336 portDefn->format.video.nFrameWidth,
Arun Menon906de572013-06-18 17:01:40 -07008337 portDefn->format.video.nFrameHeight,
8338 portDefn->format.video.nStride,
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308339 portDefn->format.video.nSliceHeight,
8340 portDefn->format.video.eColorFormat,
8341 portDefn->nBufferSize,
8342 portDefn->nBufferCountActual);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008343
Maheshwar Ajja507d6552014-01-03 14:54:29 +05308344 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008345}
8346
8347OMX_ERRORTYPE omx_vdec::allocate_output_headers()
8348{
Arun Menon906de572013-06-18 17:01:40 -07008349 OMX_ERRORTYPE eRet = OMX_ErrorNone;
8350 OMX_BUFFERHEADERTYPE *bufHdr = NULL;
8351 unsigned i= 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008352
Arun Menon906de572013-06-18 17:01:40 -07008353 if (!m_out_mem_ptr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008354 DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation");
Arun Menon906de572013-06-18 17:01:40 -07008355 int nBufHdrSize = 0;
8356 int nPlatformEntrySize = 0;
8357 int nPlatformListSize = 0;
8358 int nPMEMInfoSize = 0;
8359 OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList;
8360 OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry;
8361 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008362
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008363 DEBUG_PRINT_LOW("Setting First Output Buffer(%d)",
Arun Menon906de572013-06-18 17:01:40 -07008364 drv_ctx.op_buf.actualcount);
8365 nBufHdrSize = drv_ctx.op_buf.actualcount *
8366 sizeof(OMX_BUFFERHEADERTYPE);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008367
Arun Menon906de572013-06-18 17:01:40 -07008368 nPMEMInfoSize = drv_ctx.op_buf.actualcount *
8369 sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO);
8370 nPlatformListSize = drv_ctx.op_buf.actualcount *
8371 sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST);
8372 nPlatformEntrySize = drv_ctx.op_buf.actualcount *
8373 sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008374
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008375 DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize,
Arun Menon906de572013-06-18 17:01:40 -07008376 sizeof(OMX_BUFFERHEADERTYPE),
8377 nPMEMInfoSize,
8378 nPlatformListSize);
Steve Kondikf1914362015-11-01 02:50:41 -08008379 DEBUG_PRINT_LOW("PE %d bmSize %" PRId64, nPlatformEntrySize,
Arun Menon906de572013-06-18 17:01:40 -07008380 m_out_bm_count);
8381 m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1);
8382 // Alloc mem for platform specific info
8383 char *pPtr=NULL;
8384 pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize +
8385 nPMEMInfoSize,1);
8386 drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \
8387 calloc (sizeof(struct vdec_bufferpayload),
8388 drv_ctx.op_buf.actualcount);
8389 drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\
8390 calloc (sizeof (struct vdec_output_frameinfo),
8391 drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07008392 if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) {
8393 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer");
8394 return OMX_ErrorInsufficientResources;
8395 }
8396
Shalaj Jain273b3e02012-06-22 19:08:03 -07008397#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008398 drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \
8399 calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount);
Arun Menon8544ead2014-05-08 17:42:29 -07008400 if (!drv_ctx.op_buf_ion_info) {
8401 DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info");
8402 return OMX_ErrorInsufficientResources;
8403 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008404#endif
Arun Menonbdb80b02013-08-12 17:45:54 -07008405 if (dynamic_buf_mode) {
8406 out_dynamic_list = (struct dynamic_buf_list *) \
8407 calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount);
8408 }
Arun Menon906de572013-06-18 17:01:40 -07008409 if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer
8410 && drv_ctx.ptr_respbuffer) {
8411 bufHdr = m_out_mem_ptr;
8412 m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr);
8413 m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *)
8414 (((char *) m_platform_list) + nPlatformListSize);
8415 m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *)
8416 (((char *) m_platform_entry) + nPlatformEntrySize);
8417 pPlatformList = m_platform_list;
8418 pPlatformEntry = m_platform_entry;
8419 pPMEMInfo = m_pmem_info;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008420
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008421 DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008422
Arun Menon906de572013-06-18 17:01:40 -07008423 // Settting the entire storage nicely
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008424 DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr,
Arun Menon906de572013-06-18 17:01:40 -07008425 m_out_mem_ptr,pPlatformEntry);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008426 DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo);
Arun Menon906de572013-06-18 17:01:40 -07008427 for (i=0; i < drv_ctx.op_buf.actualcount ; i++) {
8428 bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
8429 bufHdr->nVersion.nVersion = OMX_SPEC_VERSION;
8430 // Set the values when we determine the right HxW param
8431 bufHdr->nAllocLen = 0;
8432 bufHdr->nFilledLen = 0;
8433 bufHdr->pAppPrivate = NULL;
8434 bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
8435 pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
8436 pPlatformEntry->entry = pPMEMInfo;
8437 // Initialize the Platform List
8438 pPlatformList->nEntries = 1;
8439 pPlatformList->entryList = pPlatformEntry;
8440 // Keep pBuffer NULL till vdec is opened
8441 bufHdr->pBuffer = NULL;
8442 pPMEMInfo->offset = 0;
8443 pPMEMInfo->pmem_fd = 0;
8444 bufHdr->pPlatformPrivate = pPlatformList;
8445 drv_ctx.ptr_outputbuffer[i].pmem_fd = -1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008446#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008447 drv_ctx.op_buf_ion_info[i].ion_device_fd =-1;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008448#endif
Arun Menon906de572013-06-18 17:01:40 -07008449 /*Create a mapping between buffers*/
8450 bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i];
8451 drv_ctx.ptr_respbuffer[i].client_data = (void *) \
8452 &drv_ctx.ptr_outputbuffer[i];
8453 // Move the buffer and buffer header pointers
8454 bufHdr++;
8455 pPMEMInfo++;
8456 pPlatformEntry++;
8457 pPlatformList++;
8458 }
8459 } else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008460 DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\
Arun Menon906de572013-06-18 17:01:40 -07008461 m_out_mem_ptr, pPtr);
8462 if (m_out_mem_ptr) {
8463 free(m_out_mem_ptr);
8464 m_out_mem_ptr = NULL;
8465 }
8466 if (pPtr) {
8467 free(pPtr);
8468 pPtr = NULL;
8469 }
8470 if (drv_ctx.ptr_outputbuffer) {
8471 free(drv_ctx.ptr_outputbuffer);
8472 drv_ctx.ptr_outputbuffer = NULL;
8473 }
8474 if (drv_ctx.ptr_respbuffer) {
8475 free(drv_ctx.ptr_respbuffer);
8476 drv_ctx.ptr_respbuffer = NULL;
8477 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008478#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07008479 if (drv_ctx.op_buf_ion_info) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008480 DEBUG_PRINT_LOW("Free o/p ion context");
Arun Menon906de572013-06-18 17:01:40 -07008481 free(drv_ctx.op_buf_ion_info);
8482 drv_ctx.op_buf_ion_info = NULL;
8483 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008484#endif
Arun Menon906de572013-06-18 17:01:40 -07008485 eRet = OMX_ErrorInsufficientResources;
8486 }
8487 } else {
8488 eRet = OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008489 }
Arun Menon906de572013-06-18 17:01:40 -07008490 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008491}
8492
8493void omx_vdec::complete_pending_buffer_done_cbs()
8494{
Arun Menon906de572013-06-18 17:01:40 -07008495 unsigned p1;
8496 unsigned p2;
8497 unsigned ident;
8498 omx_cmd_queue tmp_q, pending_bd_q;
8499 pthread_mutex_lock(&m_lock);
8500 // pop all pending GENERATE FDB from ftb queue
8501 while (m_ftb_q.m_size) {
8502 m_ftb_q.pop_entry(&p1,&p2,&ident);
8503 if (ident == OMX_COMPONENT_GENERATE_FBD) {
8504 pending_bd_q.insert_entry(p1,p2,ident);
8505 } else {
8506 tmp_q.insert_entry(p1,p2,ident);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008507 }
Arun Menon906de572013-06-18 17:01:40 -07008508 }
8509 //return all non GENERATE FDB to ftb queue
8510 while (tmp_q.m_size) {
8511 tmp_q.pop_entry(&p1,&p2,&ident);
8512 m_ftb_q.insert_entry(p1,p2,ident);
8513 }
8514 // pop all pending GENERATE EDB from etb queue
8515 while (m_etb_q.m_size) {
8516 m_etb_q.pop_entry(&p1,&p2,&ident);
8517 if (ident == OMX_COMPONENT_GENERATE_EBD) {
8518 pending_bd_q.insert_entry(p1,p2,ident);
8519 } else {
8520 tmp_q.insert_entry(p1,p2,ident);
8521 }
8522 }
8523 //return all non GENERATE FDB to etb queue
8524 while (tmp_q.m_size) {
8525 tmp_q.pop_entry(&p1,&p2,&ident);
8526 m_etb_q.insert_entry(p1,p2,ident);
8527 }
8528 pthread_mutex_unlock(&m_lock);
8529 // process all pending buffer dones
8530 while (pending_bd_q.m_size) {
8531 pending_bd_q.pop_entry(&p1,&p2,&ident);
8532 switch (ident) {
8533 case OMX_COMPONENT_GENERATE_EBD:
8534 if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008535 DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07008536 omx_report_error ();
8537 }
8538 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008539
Arun Menon906de572013-06-18 17:01:40 -07008540 case OMX_COMPONENT_GENERATE_FBD:
8541 if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008542 DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!");
Arun Menon906de572013-06-18 17:01:40 -07008543 omx_report_error ();
8544 }
8545 break;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008546 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008547 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008548}
8549
8550void omx_vdec::set_frame_rate(OMX_S64 act_timestamp)
8551{
Arun Menon906de572013-06-18 17:01:40 -07008552 OMX_U32 new_frame_interval = 0;
8553 if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts
8554 && llabs(act_timestamp - prev_ts) > 2000) {
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -07008555 new_frame_interval = client_set_fps ? frm_int : (act_timestamp - prev_ts) > 0 ?
8556 llabs(act_timestamp - prev_ts) : llabs(act_timestamp - prev_ts_actual);
Arun Menond9e49f82014-04-23 18:50:26 -07008557 if (new_frame_interval != frm_int || frm_int == 0) {
Arun Menon906de572013-06-18 17:01:40 -07008558 frm_int = new_frame_interval;
8559 if (frm_int) {
8560 drv_ctx.frame_rate.fps_numerator = 1e6;
8561 drv_ctx.frame_rate.fps_denominator = frm_int;
8562 DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)",
8563 frm_int, drv_ctx.frame_rate.fps_numerator /
8564 (float)drv_ctx.frame_rate.fps_denominator);
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008565
Arun Menon906de572013-06-18 17:01:40 -07008566 /* We need to report the difference between this FBD and the previous FBD
8567 * back to the driver for clock scaling purposes. */
8568 struct v4l2_outputparm oparm;
8569 /*XXX: we're providing timing info as seconds per frame rather than frames
8570 * per second.*/
8571 oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator;
8572 oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator;
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008573
Arun Menon906de572013-06-18 17:01:40 -07008574 struct v4l2_streamparm sparm;
8575 sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
8576 sparm.parm.output = oparm;
8577 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) {
8578 DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \
8579 performance might be affected");
8580 }
8581
8582 }
Deva Ramasubramaniane47e05b2013-04-24 15:23:29 -07008583 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008584 }
Arun Menon906de572013-06-18 17:01:40 -07008585 prev_ts = act_timestamp;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008586}
8587
8588void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp)
8589{
Arun Menon906de572013-06-18 17:01:40 -07008590 if (rst_prev_ts && VALID_TS(act_timestamp)) {
8591 prev_ts = act_timestamp;
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -07008592 prev_ts_actual = act_timestamp;
Arun Menon906de572013-06-18 17:01:40 -07008593 rst_prev_ts = false;
8594 } else if (VALID_TS(prev_ts)) {
8595 bool codec_cond = (drv_ctx.timestamp_adjust)?
Ashray Kulkarni6ecd0372015-09-02 17:51:20 -07008596 (!VALID_TS(act_timestamp) || act_timestamp < prev_ts_actual || llabs(act_timestamp - prev_ts_actual) <= 2000) :
8597 (!VALID_TS(act_timestamp) || act_timestamp <= prev_ts_actual);
8598 prev_ts_actual = act_timestamp; //unadjusted previous timestamp
Arun Menon906de572013-06-18 17:01:40 -07008599 if (frm_int > 0 && codec_cond) {
8600 DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp);
8601 act_timestamp = prev_ts + frm_int;
8602 DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp);
8603 prev_ts = act_timestamp;
Leena Winterrowdd139fdc2014-08-05 18:04:25 -07008604 } else {
8605 if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) {
8606 // ensure that timestamps can never step backwards when in display order
8607 act_timestamp = prev_ts;
8608 }
Arun Menon906de572013-06-18 17:01:40 -07008609 set_frame_rate(act_timestamp);
Leena Winterrowdd139fdc2014-08-05 18:04:25 -07008610 }
Arun Menon906de572013-06-18 17:01:40 -07008611 } else if (frm_int > 0) // In this case the frame rate was set along
8612 { // with the port definition, start ts with 0
8613 act_timestamp = prev_ts = 0; // and correct if a valid ts is received.
8614 rst_prev_ts = true;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008615 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07008616}
8617
8618void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr)
8619{
Arun Menon906de572013-06-18 17:01:40 -07008620 OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL;
8621 OMX_U32 num_conceal_MB = 0;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308622 OMX_TICKS time_stamp = 0;
Arun Menon906de572013-06-18 17:01:40 -07008623 OMX_U32 frame_rate = 0;
8624 int consumed_len = 0;
8625 OMX_U32 num_MB_in_frame;
8626 OMX_U32 recovery_sei_flags = 1;
8627 int enable = 0;
Arun Menon7b6fd642014-02-13 16:48:36 -08008628
Arun Menon906de572013-06-18 17:01:40 -07008629 int buf_index = p_buf_hdr - m_out_mem_ptr;
Praveen Chavan61e5d162013-11-01 02:49:19 -07008630 if (buf_index >= drv_ctx.extradata_info.count) {
8631 DEBUG_PRINT_ERROR("handle_extradata: invalid index(%d) max(%d)",
8632 buf_index, drv_ctx.extradata_info.count);
8633 return;
8634 }
Arun Menon906de572013-06-18 17:01:40 -07008635 struct msm_vidc_panscan_window_payload *panscan_payload = NULL;
8636 OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) +
8637 p_buf_hdr->nOffset;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308638
Arun Menon906de572013-06-18 17:01:40 -07008639 if (!drv_ctx.extradata_info.uaddr) {
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308640 DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr");
Arun Menon906de572013-06-18 17:01:40 -07008641 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008642 }
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308643
8644 if (!secure_mode && (drv_ctx.extradata_info.buffer_size > (p_buf_hdr->nAllocLen - p_buf_hdr->nFilledLen)) ) {
8645 DEBUG_PRINT_ERROR("Error: Insufficient size allocated for extra-data");
8646 p_extra = NULL;
8647 return;
8648 }
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308649 if (!secure_mode)
8650 p_extra = (OMX_OTHER_EXTRADATATYPE *)
Arun Menon906de572013-06-18 17:01:40 -07008651 ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3));
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308652 else
8653 p_extra = m_other_extradata;
8654
Arun Menon906de572013-06-18 17:01:40 -07008655 char *p_extradata = drv_ctx.extradata_info.uaddr + buf_index * drv_ctx.extradata_info.buffer_size;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308656 if (!secure_mode && ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))) {
8657 DEBUG_PRINT_ERROR("Error: out of bound memory access by p_extra");
Arun Menon906de572013-06-18 17:01:40 -07008658 p_extra = NULL;
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308659 return;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008660 }
Arun Menon906de572013-06-18 17:01:40 -07008661 OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008662 if (data && p_extra) {
Arun Menon906de572013-06-18 17:01:40 -07008663 while ((consumed_len < drv_ctx.extradata_info.buffer_size)
8664 && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) {
Surajit Podderd2644d52013-08-28 17:59:06 +05308665 if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) {
Arun Menon906de572013-06-18 17:01:40 -07008666 DEBUG_PRINT_LOW("Invalid extra data size");
8667 break;
8668 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308669 DEBUG_PRINT_LOW("handle_extradata: eType = %d", data->eType);
Arun Menon906de572013-06-18 17:01:40 -07008670 switch ((unsigned long)data->eType) {
8671 case EXTRADATA_INTERLACE_VIDEO:
8672 struct msm_vidc_interlace_payload *payload;
8673 payload = (struct msm_vidc_interlace_payload *)data->data;
Arun Menon7b6fd642014-02-13 16:48:36 -08008674 if (payload) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008675 enable = 1;
Arun Menon7b6fd642014-02-13 16:48:36 -08008676 switch (payload->format) {
8677 case INTERLACE_FRAME_PROGRESSIVE:
8678 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
8679 enable = 0;
8680 break;
8681 case INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST:
8682 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8683 break;
8684 case INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST:
8685 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameBottomFieldFirst;
8686 break;
8687 default:
8688 DEBUG_PRINT_LOW("default case - set interlace to topfield");
8689 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
8690 }
Arun Menon906de572013-06-18 17:01:40 -07008691 }
8692 if (m_enable_android_native_buffers)
8693 setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle,
8694 PP_PARAM_INTERLACED, (void*)&enable);
Pushkaraj Patil0ddb2e02013-11-12 11:53:58 +05308695 if (client_extradata & OMX_INTERLACE_EXTRADATA) {
Arun Menon7b6fd642014-02-13 16:48:36 -08008696 append_interlace_extradata(p_extra, payload->format,
8697 p_buf_hdr->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF);
Arun Menon906de572013-06-18 17:01:40 -07008698 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8699 }
8700 break;
8701 case EXTRADATA_FRAME_RATE:
8702 struct msm_vidc_framerate_payload *frame_rate_payload;
8703 frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data;
8704 frame_rate = frame_rate_payload->frame_rate;
8705 break;
8706 case EXTRADATA_TIMESTAMP:
8707 struct msm_vidc_ts_payload *time_stamp_payload;
8708 time_stamp_payload = (struct msm_vidc_ts_payload *)data->data;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308709 time_stamp = time_stamp_payload->timestamp_lo;
8710 time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32);
8711 p_buf_hdr->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07008712 break;
8713 case EXTRADATA_NUM_CONCEALED_MB:
8714 struct msm_vidc_concealmb_payload *conceal_mb_payload;
8715 conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data;
8716 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8717 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8718 num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0);
8719 break;
8720 case EXTRADATA_INDEX:
8721 int *etype;
8722 etype = (int *)(data->data);
8723 if (etype && *etype == EXTRADATA_ASPECT_RATIO) {
8724 struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload;
8725 aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype);
8726 if (aspect_ratio_payload) {
8727 ((struct vdec_output_frameinfo *)
8728 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width;
8729 ((struct vdec_output_frameinfo *)
8730 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height;
8731 }
8732 }
8733 break;
8734 case EXTRADATA_RECOVERY_POINT_SEI:
8735 struct msm_vidc_recoverysei_payload *recovery_sei_payload;
8736 recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data;
8737 recovery_sei_flags = recovery_sei_payload->flags;
8738 if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) {
8739 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008740 DEBUG_PRINT_HIGH("");
8741 DEBUG_PRINT_HIGH("***************************************************");
8742 DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received");
8743 DEBUG_PRINT_HIGH("***************************************************");
Arun Menon906de572013-06-18 17:01:40 -07008744 }
8745 break;
8746 case EXTRADATA_PANSCAN_WINDOW:
8747 panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data;
8748 break;
8749 case EXTRADATA_MPEG2_SEQDISP:
8750 struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload;
8751 seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data;
8752 if (seqdisp_payload) {
8753 m_disp_hor_size = seqdisp_payload->disp_width;
8754 m_disp_vert_size = seqdisp_payload->disp_height;
8755 }
8756 break;
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308757 case EXTRADATA_S3D_FRAME_PACKING:
8758 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload;
8759 s3d_frame_packing_payload = (struct msm_vidc_s3d_frame_packing_payload *)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308760 if (client_extradata & OMX_FRAMEPACK_EXTRADATA) {
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308761 append_framepack_extradata(p_extra, s3d_frame_packing_payload);
8762 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8763 }
8764 break;
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008765 case EXTRADATA_FRAME_QP:
8766 struct msm_vidc_frame_qp_payload *qp_payload;
8767 qp_payload = (struct msm_vidc_frame_qp_payload*)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308768 if (client_extradata & OMX_QP_EXTRADATA) {
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008769 append_qp_extradata(p_extra, qp_payload);
8770 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8771 }
8772 break;
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008773 case EXTRADATA_FRAME_BITS_INFO:
8774 struct msm_vidc_frame_bits_info_payload *bits_info_payload;
8775 bits_info_payload = (struct msm_vidc_frame_bits_info_payload*)data->data;
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308776 if (client_extradata & OMX_BITSINFO_EXTRADATA) {
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008777 append_bitsinfo_extradata(p_extra, bits_info_payload);
8778 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8779 }
8780 break;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008781 case EXTRADATA_STREAM_USERDATA:
Pushkaraj Patil74b2eaf2014-06-13 17:07:50 +05308782 if (client_extradata & OMX_EXTNUSER_EXTRADATA) {
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008783 append_user_extradata(p_extra, data);
8784 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
8785 }
8786 break;
Arun Menon906de572013-06-18 17:01:40 -07008787 default:
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008788 DEBUG_PRINT_LOW("Unrecognized extradata");
Arun Menon906de572013-06-18 17:01:40 -07008789 goto unrecognized_extradata;
8790 }
8791 consumed_len += data->nSize;
8792 data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize);
8793 }
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308794 if (client_extradata & OMX_FRAMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008795 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
8796 append_frame_info_extradata(p_extra,
8797 num_conceal_MB, ((struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate)->pic_type, frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308798 time_stamp, panscan_payload,&((struct vdec_output_frameinfo *)
Arun Menon906de572013-06-18 17:01:40 -07008799 p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info);
Praneeth Paladugudd29c282013-09-12 15:41:47 -07008800 p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize);
Arun Menon906de572013-06-18 17:01:40 -07008801 }
8802 }
Vinay Kalia0e75e9a2012-09-27 15:41:53 -07008803unrecognized_extradata:
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008804 if (client_extradata && p_extra) {
8805 p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
Arun Menon906de572013-06-18 17:01:40 -07008806 append_terminator_extradata(p_extra);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008807 }
8808
Arun Menonfd723932014-05-30 17:56:31 -07008809 if (secure_mode && p_extradata && m_other_extradata) {
Srinu Gorle2eb94e42014-02-14 13:37:40 +05308810 struct vdec_output_frameinfo *ptr_extradatabuff = NULL;
8811 memcpy(p_extradata, m_other_extradata, drv_ctx.extradata_info.buffer_size);
8812 ptr_extradatabuff = (struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate;
8813 ptr_extradatabuff->metadata_info.metabufaddr = (void *)p_extradata;
8814 ptr_extradatabuff->metadata_info.size = drv_ctx.extradata_info.buffer_size;
8815 }
Arun Menon906de572013-06-18 17:01:40 -07008816 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008817}
8818
Vinay Kalia9c00cae2012-12-06 16:08:20 -08008819OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata,
Arun Menon906de572013-06-18 17:01:40 -07008820 bool is_internal, bool enable)
Shalaj Jain273b3e02012-06-22 19:08:03 -07008821{
Arun Menon906de572013-06-18 17:01:40 -07008822 OMX_ERRORTYPE ret = OMX_ErrorNone;
8823 struct v4l2_control control;
8824 if (m_state != OMX_StateLoaded) {
8825 DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only");
8826 return OMX_ErrorIncorrectStateOperation;
Vinay Kaliadb90f8c2012-11-19 18:57:56 -08008827 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008828 DEBUG_PRINT_HIGH("NOTE: enable_extradata: actual[%lu] requested[%lu] enable[%d], is_internal: %d",
Arun Menon906de572013-06-18 17:01:40 -07008829 client_extradata, requested_extradata, enable, is_internal);
8830
8831 if (!is_internal) {
8832 if (enable)
8833 client_extradata |= requested_extradata;
8834 else
8835 client_extradata = client_extradata & ~requested_extradata;
8836 }
8837
8838 if (enable) {
8839 if (requested_extradata & OMX_INTERLACE_EXTRADATA) {
8840 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8841 control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO;
8842 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8843 DEBUG_PRINT_HIGH("Failed to set interlaced extradata."
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008844 " Quality of interlaced clips might be impacted.");
Arun Menon906de572013-06-18 17:01:40 -07008845 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308846 }
8847 if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008848 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8849 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE;
8850 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008851 DEBUG_PRINT_HIGH("Failed to set framerate extradata");
Arun Menon906de572013-06-18 17:01:40 -07008852 }
8853 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8854 control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB;
8855 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008856 DEBUG_PRINT_HIGH("Failed to set concealed MB extradata");
Arun Menon906de572013-06-18 17:01:40 -07008857 }
8858 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8859 control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI;
8860 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008861 DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata");
Arun Menon906de572013-06-18 17:01:40 -07008862 }
8863 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8864 control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW;
8865 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008866 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008867 }
8868 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8869 control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO;
8870 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008871 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008872 }
8873 if (output_capability == V4L2_PIX_FMT_MPEG2) {
8874 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8875 control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP;
8876 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008877 DEBUG_PRINT_HIGH("Failed to set panscan extradata");
Arun Menon906de572013-06-18 17:01:40 -07008878 }
8879 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308880 }
8881 if (requested_extradata & OMX_TIMEINFO_EXTRADATA) {
Arun Menon906de572013-06-18 17:01:40 -07008882 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8883 control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP;
8884 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008885 DEBUG_PRINT_HIGH("Failed to set timeinfo extradata");
Arun Menon906de572013-06-18 17:01:40 -07008886 }
8887 }
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05308888 if (requested_extradata & OMX_FRAMEPACK_EXTRADATA) {
8889 if (output_capability == V4L2_PIX_FMT_H264) {
8890 DEBUG_PRINT_HIGH("enable OMX_FRAMEPACK_EXTRADATA");
8891 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8892 control.value = V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING;
8893 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8894 DEBUG_PRINT_HIGH("Failed to set S3D_FRAME_PACKING extradata");
8895 }
8896 } else {
8897 DEBUG_PRINT_HIGH("OMX_FRAMEPACK_EXTRADATA supported for H264 only");
8898 }
8899 }
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08008900 if (requested_extradata & OMX_QP_EXTRADATA) {
8901 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8902 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP;
8903 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8904 DEBUG_PRINT_HIGH("Failed to set QP extradata");
8905 }
8906 }
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08008907 if (requested_extradata & OMX_BITSINFO_EXTRADATA) {
8908 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8909 control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO;
8910 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8911 DEBUG_PRINT_HIGH("Failed to set frame bits info extradata");
8912 }
8913 }
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08008914 if (requested_extradata & OMX_EXTNUSER_EXTRADATA) {
8915 control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA;
8916 control.value = V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA;
8917 if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
8918 DEBUG_PRINT_HIGH("Failed to set stream userdata extradata");
8919 }
8920 }
Arun Menon906de572013-06-18 17:01:40 -07008921 }
8922 ret = get_buffer_req(&drv_ctx.op_buf);
8923 return ret;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008924}
8925
8926OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8927{
Arun Menon906de572013-06-18 17:01:40 -07008928 OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0;
8929 OMX_U8 *data_ptr = extra->data, data = 0;
8930 while (byte_count < extra->nDataSize) {
8931 data = *data_ptr;
8932 while (data) {
8933 num_MB += (data&0x01);
8934 data >>= 1;
8935 }
8936 data_ptr++;
8937 byte_count++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008938 }
Arun Menon906de572013-06-18 17:01:40 -07008939 num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) *
8940 (drv_ctx.video_resolution.frame_height + 15)) >> 8;
8941 return ((num_MB_in_frame > 0)?(num_MB * 100 / num_MB_in_frame) : 0);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008942}
8943
8944void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra)
8945{
Arun Menon906de572013-06-18 17:01:40 -07008946 if (!m_debug_extradata)
8947 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07008948
8949 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308950 "============== Extra Data ==============\n"
8951 " Size: %lu\n"
8952 " Version: %lu\n"
8953 " PortIndex: %lu\n"
8954 " Type: %x\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008955 " DataSize: %lu",
Arun Menon906de572013-06-18 17:01:40 -07008956 extra->nSize, extra->nVersion.nVersion,
8957 extra->nPortIndex, extra->eType, extra->nDataSize);
Shalaj Jain273b3e02012-06-22 19:08:03 -07008958
Arun Menon906de572013-06-18 17:01:40 -07008959 if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) {
8960 OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data;
8961 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308962 "------ Interlace Format ------\n"
8963 " Size: %lu\n"
8964 " Version: %lu\n"
8965 " PortIndex: %lu\n"
8966 " Is Interlace Format: %d\n"
8967 " Interlace Formats: %lu\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008968 "=========== End of Interlace ===========",
Arun Menon906de572013-06-18 17:01:40 -07008969 intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex,
8970 intfmt->bInterlaceFormat, intfmt->nInterlaceFormats);
8971 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) {
8972 OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
8973
8974 DEBUG_PRINT_HIGH(
Deepak Verma867d5132013-12-05 12:23:20 +05308975 "-------- Frame Format --------\n"
8976 " Picture Type: %d\n"
8977 " Interlace Type: %d\n"
8978 " Pan Scan Total Frame Num: %lu\n"
8979 " Concealed Macro Blocks: %lu\n"
8980 " frame rate: %lu\n"
8981 " Time Stamp: %llu\n"
8982 " Aspect Ratio X: %lu\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008983 " Aspect Ratio Y: %lu",
Arun Menon906de572013-06-18 17:01:40 -07008984 fminfo->ePicType,
8985 fminfo->interlaceType,
8986 fminfo->panScan.numWindows,
8987 fminfo->nConcealedMacroblocks,
8988 fminfo->nFrameRate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05308989 fminfo->nTimeStamp,
Arun Menon906de572013-06-18 17:01:40 -07008990 fminfo->aspectRatio.aspectRatioX,
8991 fminfo->aspectRatio.aspectRatioY);
8992
8993 for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) {
8994 DEBUG_PRINT_HIGH(
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07008995 "------------------------------"
Deepak Verma867d5132013-12-05 12:23:20 +05308996 " Pan Scan Frame Num: %lu\n"
8997 " Rectangle x: %ld\n"
8998 " Rectangle y: %ld\n"
8999 " Rectangle dx: %ld\n"
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009000 " Rectangle dy: %ld",
Arun Menon906de572013-06-18 17:01:40 -07009001 i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y,
9002 fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy);
9003 }
9004
9005 DEBUG_PRINT_HIGH("========= End of Frame Format ==========");
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05309006 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement) {
9007 OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data;
9008 DEBUG_PRINT_HIGH(
9009 "------------------ Framepack Format ----------\n"
9010 " id: %lu \n"
9011 " cancel_flag: %lu \n"
9012 " type: %lu \n"
9013 " quincunx_sampling_flagFormat: %lu \n"
9014 " content_interpretation_type: %lu \n"
9015 " content_interpretation_type: %lu \n"
9016 " spatial_flipping_flag: %lu \n"
9017 " frame0_flipped_flag: %lu \n"
9018 " field_views_flag: %lu \n"
9019 " current_frame_is_frame0_flag: %lu \n"
9020 " frame0_self_contained_flag: %lu \n"
9021 " frame1_self_contained_flag: %lu \n"
9022 " frame0_grid_position_x: %lu \n"
9023 " frame0_grid_position_y: %lu \n"
9024 " frame1_grid_position_x: %lu \n"
9025 " frame1_grid_position_y: %lu \n"
9026 " reserved_byte: %lu \n"
9027 " repetition_period: %lu \n"
9028 " extension_flag: %lu \n"
9029 "================== End of Framepack ===========",
9030 framepack->id,
9031 framepack->cancel_flag,
9032 framepack->type,
9033 framepack->quincunx_sampling_flag,
9034 framepack->content_interpretation_type,
9035 framepack->spatial_flipping_flag,
9036 framepack->frame0_flipped_flag,
9037 framepack->field_views_flag,
9038 framepack->current_frame_is_frame0_flag,
9039 framepack->frame0_self_contained_flag,
9040 framepack->frame1_self_contained_flag,
9041 framepack->frame0_grid_position_x,
9042 framepack->frame0_grid_position_y,
9043 framepack->frame1_grid_position_x,
9044 framepack->frame1_grid_position_y,
9045 framepack->reserved_byte,
9046 framepack->repetition_period,
9047 framepack->extension_flag);
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08009048 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataQP) {
9049 OMX_QCOM_EXTRADATA_QP * qp = (OMX_QCOM_EXTRADATA_QP *)extra->data;
9050 DEBUG_PRINT_HIGH(
9051 "---- QP (Frame quantization parameter) ----\n"
9052 " Frame QP: %lu \n"
9053 "================ End of QP ================\n",
9054 qp->nQP);
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08009055 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo) {
9056 OMX_QCOM_EXTRADATA_BITS_INFO * bits = (OMX_QCOM_EXTRADATA_BITS_INFO *)extra->data;
9057 DEBUG_PRINT_HIGH(
9058 "--------- Input bits information --------\n"
9059 " Header bits: %lu \n"
9060 " Frame bits: %lu \n"
9061 "===== End of Input bits information =====\n",
9062 bits->header_bits, bits->frame_bits);
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009063 } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData) {
9064 OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)extra->data;
9065 OMX_U8 *data_ptr = (OMX_U8 *)userdata->data;
9066 OMX_U32 userdata_size = extra->nDataSize - sizeof(userdata->type);
9067 OMX_U32 i = 0;
9068 DEBUG_PRINT_HIGH(
9069 "-------------- Userdata -------------\n"
9070 " Stream userdata type: %d\n"
9071 " userdata size: %d\n"
9072 " STREAM_USERDATA:",
9073 userdata->type, userdata_size);
9074 for (i = 0; i < userdata_size; i+=4) {
9075 DEBUG_PRINT_HIGH(" %x %x %x %x",
9076 data_ptr[i], data_ptr[i+1],
9077 data_ptr[i+2], data_ptr[i+3]);
9078 }
9079 DEBUG_PRINT_HIGH(
9080 "=========== End of Userdata ===========");
Arun Menon906de572013-06-18 17:01:40 -07009081 } else if (extra->eType == OMX_ExtraDataNone) {
9082 DEBUG_PRINT_HIGH("========== End of Terminator ===========");
9083 } else {
9084 DEBUG_PRINT_HIGH("======= End of Driver Extradata ========");
Shalaj Jain273b3e02012-06-22 19:08:03 -07009085 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009086}
9087
9088void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon7b6fd642014-02-13 16:48:36 -08009089 OMX_U32 interlaced_format_type, bool is_mbaff)
Shalaj Jain273b3e02012-06-22 19:08:03 -07009090{
Arun Menon906de572013-06-18 17:01:40 -07009091 OMX_STREAMINTERLACEFORMAT *interlace_format;
Arun Menon7b6fd642014-02-13 16:48:36 -08009092
Arun Menon906de572013-06-18 17:01:40 -07009093 if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) {
9094 return;
9095 }
9096 extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE;
9097 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9098 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9099 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat;
9100 extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT);
9101 interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data;
9102 interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT);
9103 interlace_format->nVersion.nVersion = OMX_SPEC_VERSION;
9104 interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
Arun Menon7b6fd642014-02-13 16:48:36 -08009105
9106 if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !is_mbaff) {
Arun Menon906de572013-06-18 17:01:40 -07009107 interlace_format->bInterlaceFormat = OMX_FALSE;
9108 interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive;
9109 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon7b6fd642014-02-13 16:48:36 -08009110 } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST) && !is_mbaff) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009111 interlace_format->bInterlaceFormat = OMX_TRUE;
Arun Menon7b6fd642014-02-13 16:48:36 -08009112 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009113 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon7b6fd642014-02-13 16:48:36 -08009114 } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST) && !is_mbaff) {
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009115 interlace_format->bInterlaceFormat = OMX_TRUE;
Arun Menon7b6fd642014-02-13 16:48:36 -08009116 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameBottomFieldFirst;
Praneeth Paladugudd29c282013-09-12 15:41:47 -07009117 drv_ctx.interlace = VDEC_InterlaceFrameProgressive;
Arun Menon906de572013-06-18 17:01:40 -07009118 } else {
9119 interlace_format->bInterlaceFormat = OMX_TRUE;
9120 interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst;
9121 drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst;
9122 }
9123 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009124}
9125
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009126void omx_vdec::fill_aspect_ratio_info(
Arun Menon906de572013-06-18 17:01:40 -07009127 struct vdec_aspectratioinfo *aspect_ratio_info,
9128 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info)
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009129{
Arun Menon906de572013-06-18 17:01:40 -07009130 m_extradata = frame_info;
9131 m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width;
9132 m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309133 DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX,
Arun Menon906de572013-06-18 17:01:40 -07009134 m_extradata->aspectRatio.aspectRatioY);
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009135}
Shalaj Jain273b3e02012-06-22 19:08:03 -07009136
9137void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
Arun Menon906de572013-06-18 17:01:40 -07009138 OMX_U32 num_conceal_mb, OMX_U32 picture_type, OMX_U32 frame_rate,
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309139 OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload,
Praneeth Paladuguf3a492b2013-01-03 17:35:34 -08009140 struct vdec_aspectratioinfo *aspect_ratio_info)
Shalaj Jain273b3e02012-06-22 19:08:03 -07009141{
Arun Menon906de572013-06-18 17:01:40 -07009142 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL;
9143 struct msm_vidc_panscan_window *panscan_window;
9144 if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) {
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08009145 return;
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07009146 }
Arun Menon906de572013-06-18 17:01:40 -07009147 extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE;
9148 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9149 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9150 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo;
9151 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO);
9152 frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data;
9153 switch (picture_type) {
9154 case PICTURE_TYPE_I:
9155 frame_info->ePicType = OMX_VIDEO_PictureTypeI;
9156 break;
9157 case PICTURE_TYPE_P:
9158 frame_info->ePicType = OMX_VIDEO_PictureTypeP;
9159 break;
9160 case PICTURE_TYPE_B:
9161 frame_info->ePicType = OMX_VIDEO_PictureTypeB;
9162 break;
9163 default:
9164 frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0;
9165 }
9166 if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst)
9167 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst;
9168 else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst)
9169 frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst;
9170 else
9171 frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive;
9172 memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio));
9173 frame_info->nConcealedMacroblocks = num_conceal_mb;
9174 frame_info->nFrameRate = frame_rate;
Rajeshwar Kurapaty90a98112013-09-17 16:07:14 +05309175 frame_info->nTimeStamp = time_stamp;
Arun Menon906de572013-06-18 17:01:40 -07009176 frame_info->panScan.numWindows = 0;
9177 if (output_capability == V4L2_PIX_FMT_MPEG2) {
9178 if (m_disp_hor_size && m_disp_vert_size) {
9179 frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size;
9180 frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size;
Pushkaraj Patil5e6ebd92014-03-10 10:29:14 +05309181 } else {
9182 frame_info->displayAspectRatio.displayHorizontalSize = 0;
9183 frame_info->displayAspectRatio.displayVerticalSize = 0;
Arun Menon906de572013-06-18 17:01:40 -07009184 }
9185 }
Praneeth Paladugud0881ef2013-04-23 23:02:55 -07009186
Arun Menon906de572013-06-18 17:01:40 -07009187 if (panscan_payload) {
9188 frame_info->panScan.numWindows = panscan_payload->num_panscan_windows;
9189 panscan_window = &panscan_payload->wnd[0];
9190 for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) {
9191 frame_info->panScan.window[i].x = panscan_window->panscan_window_width;
9192 frame_info->panScan.window[i].y = panscan_window->panscan_window_height;
9193 frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset;
9194 frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset;
9195 panscan_window++;
9196 }
Praneeth Paladugu48a9a8a2012-12-06 12:12:19 -08009197 }
Arun Menon906de572013-06-18 17:01:40 -07009198 fill_aspect_ratio_info(aspect_ratio_info, frame_info);
9199 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009200}
9201
9202void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra)
9203{
Arun Menon906de572013-06-18 17:01:40 -07009204 OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL;
9205 extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE;
9206 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9207 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9208 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef;
9209 extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
9210 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data;
9211 *portDefn = m_port_def;
9212 DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu "
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009213 "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight,
Arun Menon906de572013-06-18 17:01:40 -07009214 portDefn->format.video.nFrameWidth,
9215 portDefn->format.video.nStride,
9216 portDefn->format.video.nSliceHeight);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009217}
9218
Maheshwar Ajjad2df2182013-10-24 19:20:34 +05309219void omx_vdec::append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9220 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload)
9221{
9222 OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack;
9223 if (FRAME_PACK_SIZE*sizeof(OMX_U32) != sizeof(struct msm_vidc_s3d_frame_packing_payload)) {
9224 DEBUG_PRINT_ERROR("frame packing size mismatch");
9225 return;
9226 }
9227 extra->nSize = OMX_FRAMEPACK_EXTRADATA_SIZE;
9228 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9229 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9230 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement;
9231 extra->nDataSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT);
9232 framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data;
9233 framepack->nSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT);
9234 framepack->nVersion.nVersion = OMX_SPEC_VERSION;
9235 framepack->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9236 memcpy(&framepack->id, s3d_frame_packing_payload,
9237 sizeof(struct msm_vidc_s3d_frame_packing_payload));
9238 memcpy(&m_frame_pack_arrangement, framepack,
9239 sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT));
9240 print_debug_extradata(extra);
9241}
9242
Jorge Solano Altamiranob10850d2014-01-08 11:17:58 -08009243void omx_vdec::append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9244 struct msm_vidc_frame_qp_payload *qp_payload)
9245{
9246 OMX_QCOM_EXTRADATA_QP * qp = NULL;
9247 if (!qp_payload) {
9248 DEBUG_PRINT_ERROR("QP payload is NULL");
9249 return;
9250 }
9251 extra->nSize = OMX_QP_EXTRADATA_SIZE;
9252 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9253 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9254 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataQP;
9255 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_QP);
9256 qp = (OMX_QCOM_EXTRADATA_QP *)extra->data;
9257 qp->nQP = qp_payload->frame_qp;
9258 print_debug_extradata(extra);
9259}
9260
Jorge Solano Altamirano54338452014-01-08 11:04:57 -08009261void omx_vdec::append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9262 struct msm_vidc_frame_bits_info_payload *bits_payload)
9263{
9264 OMX_QCOM_EXTRADATA_BITS_INFO * bits = NULL;
9265 if (!bits_payload) {
9266 DEBUG_PRINT_ERROR("bits info payload is NULL");
9267 return;
9268 }
9269 extra->nSize = OMX_BITSINFO_EXTRADATA_SIZE;
9270 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9271 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9272 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo;
9273 extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_BITS_INFO);
9274 bits = (OMX_QCOM_EXTRADATA_BITS_INFO*)extra->data;
9275 bits->frame_bits = bits_payload->frame_bits;
9276 bits->header_bits = bits_payload->header_bits;
9277 print_debug_extradata(extra);
9278}
9279
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009280void omx_vdec::append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra,
9281 OMX_OTHER_EXTRADATATYPE *p_user)
9282{
9283 int userdata_size = 0;
9284 struct msm_vidc_stream_userdata_payload *userdata_payload = NULL;
9285 userdata_payload =
9286 (struct msm_vidc_stream_userdata_payload *)p_user->data;
9287 userdata_size = p_user->nDataSize;
Deva Ramasubramanian2ebfed32014-04-24 13:34:24 -07009288 extra->nSize = OMX_USERDATA_EXTRADATA_SIZE + p_user->nSize;
Jorge Solano Altamirano1ae09be2014-01-16 12:21:52 -08009289 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9290 extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9291 extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData;
9292 extra->nDataSize = userdata_size;
9293 if (extra->data && p_user->data && extra->nDataSize)
9294 memcpy(extra->data, p_user->data, extra->nDataSize);
9295 print_debug_extradata(extra);
9296}
9297
Shalaj Jain273b3e02012-06-22 19:08:03 -07009298void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra)
9299{
Arun Menon906de572013-06-18 17:01:40 -07009300 if (!client_extradata) {
9301 return;
9302 }
9303 extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE);
9304 extra->nVersion.nVersion = OMX_SPEC_VERSION;
9305 extra->eType = OMX_ExtraDataNone;
9306 extra->nDataSize = 0;
9307 extra->data[0] = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009308
Arun Menon906de572013-06-18 17:01:40 -07009309 print_debug_extradata(extra);
Shalaj Jain273b3e02012-06-22 19:08:03 -07009310}
9311
9312OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index)
9313{
Arun Menon906de572013-06-18 17:01:40 -07009314 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9315 if (index >= drv_ctx.ip_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009316 DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found");
Arun Menon906de572013-06-18 17:01:40 -07009317 return OMX_ErrorInsufficientResources;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009318 }
Arun Menon906de572013-06-18 17:01:40 -07009319 if (m_desc_buffer_ptr == NULL) {
9320 m_desc_buffer_ptr = (desc_buffer_hdr*) \
9321 calloc( (sizeof(desc_buffer_hdr)),
9322 drv_ctx.ip_buf.actualcount);
9323 if (m_desc_buffer_ptr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009324 DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07009325 return OMX_ErrorInsufficientResources;
9326 }
9327 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009328
Arun Menon906de572013-06-18 17:01:40 -07009329 m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8));
9330 if (m_desc_buffer_ptr[index].buf_addr == NULL) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009331 DEBUG_PRINT_ERROR("desc buffer Allocation failed ");
Arun Menon906de572013-06-18 17:01:40 -07009332 return OMX_ErrorInsufficientResources;
9333 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009334
Arun Menon906de572013-06-18 17:01:40 -07009335 return eRet;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009336}
9337
9338void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset)
9339{
Arun Menon906de572013-06-18 17:01:40 -07009340 DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries);
9341 if (m_demux_entries < 8192) {
9342 m_demux_offsets[m_demux_entries++] = address_offset;
9343 }
9344 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009345}
9346
9347void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr)
9348{
Arun Menon906de572013-06-18 17:01:40 -07009349 OMX_U32 bytes_to_parse = buf_hdr->nFilledLen;
9350 OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset;
9351 OMX_U32 index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009352
Arun Menon906de572013-06-18 17:01:40 -07009353 m_demux_entries = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009354
Arun Menon906de572013-06-18 17:01:40 -07009355 while (index < bytes_to_parse) {
9356 if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
9357 (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) ||
9358 ((buf[index] == 0x00) && (buf[index+1] == 0x00) &&
9359 (buf[index+2] == 0x01)) ) {
9360 //Found start code, insert address offset
9361 insert_demux_addr_offset(index);
9362 if (buf[index+2] == 0x01) // 3 byte start code
9363 index += 3;
9364 else //4 byte start code
9365 index += 4;
9366 } else
9367 index++;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009368 }
Arun Menon906de572013-06-18 17:01:40 -07009369 DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries);
9370 return;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009371}
9372
9373OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr)
9374{
Arun Menon906de572013-06-18 17:01:40 -07009375 //fix this, handle 3 byte start code, vc1 terminator entry
9376 OMX_U8 *p_demux_data = NULL;
9377 OMX_U32 desc_data = 0;
9378 OMX_U32 start_addr = 0;
9379 OMX_U32 nal_size = 0;
9380 OMX_U32 suffix_byte = 0;
9381 OMX_U32 demux_index = 0;
9382 OMX_U32 buffer_index = 0;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009383
Arun Menon906de572013-06-18 17:01:40 -07009384 if (m_desc_buffer_ptr == NULL) {
9385 DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries.");
9386 return OMX_ErrorBadParameter;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009387 }
Shalaj Jain273b3e02012-06-22 19:08:03 -07009388
Arun Menon906de572013-06-18 17:01:40 -07009389 buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
9390 if (buffer_index > drv_ctx.ip_buf.actualcount) {
9391 DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index);
9392 return OMX_ErrorBadParameter;
9393 }
9394
9395 p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr;
9396
9397 if ( ((OMX_U8*)p_demux_data == NULL) ||
9398 ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) {
9399 DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries.");
9400 return OMX_ErrorBadParameter;
9401 } else {
9402 for (; demux_index < m_demux_entries; demux_index++) {
9403 desc_data = 0;
9404 start_addr = m_demux_offsets[demux_index];
9405 if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) {
9406 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3];
9407 } else {
9408 suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4];
9409 }
9410 if (demux_index < (m_demux_entries - 1)) {
9411 nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2;
9412 } else {
9413 nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2;
9414 }
9415 DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)",
9416 (void *)start_addr,
9417 suffix_byte,
9418 nal_size,
9419 demux_index);
9420 desc_data = (start_addr >> 3) << 1;
9421 desc_data |= (start_addr & 7) << 21;
9422 desc_data |= suffix_byte << 24;
9423
9424 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
9425 memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32));
9426 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
9427 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
9428
9429 p_demux_data += 16;
9430 }
9431 if (codec_type_parse == CODEC_TYPE_VC1) {
9432 DEBUG_PRINT_LOW("VC1 terminator entry");
9433 desc_data = 0;
9434 desc_data = 0x82 << 24;
9435 memcpy(p_demux_data, &desc_data, sizeof(OMX_U32));
9436 memset(p_demux_data + 4, 0, sizeof(OMX_U32));
9437 memset(p_demux_data + 8, 0, sizeof(OMX_U32));
9438 memset(p_demux_data + 12, 0, sizeof(OMX_U32));
9439 p_demux_data += 16;
9440 m_demux_entries++;
9441 }
9442 //Add zero word to indicate end of descriptors
9443 memset(p_demux_data, 0, sizeof(OMX_U32));
9444
9445 m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32);
9446 DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size);
9447 }
9448 memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) );
9449 m_demux_entries = 0;
9450 DEBUG_PRINT_LOW("Demux table complete!");
9451 return OMX_ErrorNone;
Shalaj Jain273b3e02012-06-22 19:08:03 -07009452}
9453
Vinay Kaliada4f4422013-01-09 10:45:03 -08009454omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf()
9455{
Arun Menon906de572013-06-18 17:01:40 -07009456 enabled = false;
9457 omx = NULL;
9458 init_members();
9459 ColorFormat = OMX_COLOR_FormatMax;
Praveen Chavandb7776f2014-02-06 18:17:25 -08009460 dest_format = YCbCr420P;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009461}
9462
9463void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client)
9464{
Arun Menon906de572013-06-18 17:01:40 -07009465 omx = reinterpret_cast<omx_vdec*>(client);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009466}
9467
Arun Menon906de572013-06-18 17:01:40 -07009468void omx_vdec::allocate_color_convert_buf::init_members()
9469{
9470 allocated_count = 0;
9471 buffer_size_req = 0;
9472 buffer_alignment_req = 0;
9473 memset(m_platform_list_client,0,sizeof(m_platform_list_client));
9474 memset(m_platform_entry_client,0,sizeof(m_platform_entry_client));
9475 memset(m_pmem_info_client,0,sizeof(m_pmem_info_client));
9476 memset(m_out_mem_ptr_client,0,sizeof(m_out_mem_ptr_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08009477#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009478 memset(op_buf_ion_info,0,sizeof(m_platform_entry_client));
Vinay Kaliada4f4422013-01-09 10:45:03 -08009479#endif
Arun Menon906de572013-06-18 17:01:40 -07009480 for (int i = 0; i < MAX_COUNT; i++)
9481 pmem_fd[i] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009482}
9483
Arun Menon906de572013-06-18 17:01:40 -07009484omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf()
9485{
9486 c2d.destroy();
Vinay Kaliada4f4422013-01-09 10:45:03 -08009487}
9488
9489bool omx_vdec::allocate_color_convert_buf::update_buffer_req()
9490{
Arun Menon906de572013-06-18 17:01:40 -07009491 bool status = true;
9492 unsigned int src_size = 0, destination_size = 0;
9493 OMX_COLOR_FORMATTYPE drv_color_format;
9494 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009495 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07009496 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009497 }
Arun Menon906de572013-06-18 17:01:40 -07009498 if (!enabled) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009499 DEBUG_PRINT_HIGH("No color conversion required");
Arun Menon906de572013-06-18 17:01:40 -07009500 return status;
9501 }
9502 pthread_mutex_lock(&omx->c_lock);
9503 if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 &&
9504 ColorFormat != OMX_COLOR_FormatYUV420Planar) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009505 DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion");
Arun Menon906de572013-06-18 17:01:40 -07009506 status = false;
9507 goto fail_update_buf_req;
9508 }
9509 c2d.close();
9510 status = c2d.open(omx->drv_ctx.video_resolution.frame_height,
9511 omx->drv_ctx.video_resolution.frame_width,
Praveen Chavandb7776f2014-02-06 18:17:25 -08009512 NV12_128m,dest_format);
Arun Menon906de572013-06-18 17:01:40 -07009513 if (status) {
9514 status = c2d.get_buffer_size(C2D_INPUT,src_size);
9515 if (status)
9516 status = c2d.get_buffer_size(C2D_OUTPUT,destination_size);
9517 }
9518 if (status) {
9519 if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size ||
9520 !destination_size) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009521 DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d"
Arun Menon906de572013-06-18 17:01:40 -07009522 "driver size %d destination size %d",
9523 src_size,omx->drv_ctx.op_buf.buffer_size,destination_size);
9524 status = false;
9525 c2d.close();
9526 buffer_size_req = 0;
9527 } else {
9528 buffer_size_req = destination_size;
9529 if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size)
9530 buffer_size_req = omx->drv_ctx.op_buf.buffer_size;
9531 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
9532 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
9533 }
9534 }
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009535fail_update_buf_req:
Arun Menon906de572013-06-18 17:01:40 -07009536 pthread_mutex_unlock(&omx->c_lock);
9537 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009538}
9539
9540bool omx_vdec::allocate_color_convert_buf::set_color_format(
Arun Menon906de572013-06-18 17:01:40 -07009541 OMX_COLOR_FORMATTYPE dest_color_format)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009542{
Arun Menon906de572013-06-18 17:01:40 -07009543 bool status = true;
9544 OMX_COLOR_FORMATTYPE drv_color_format;
9545 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009546 DEBUG_PRINT_ERROR("Invalid client in color convert");
Arun Menon906de572013-06-18 17:01:40 -07009547 return false;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009548 }
Arun Menon906de572013-06-18 17:01:40 -07009549 pthread_mutex_lock(&omx->c_lock);
9550 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
9551 drv_color_format = (OMX_COLOR_FORMATTYPE)
9552 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
9553 else {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009554 DEBUG_PRINT_ERROR("Incorrect color format");
Arun Menon906de572013-06-18 17:01:40 -07009555 status = false;
9556 }
9557 if (status && (drv_color_format != dest_color_format)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009558 DEBUG_PRINT_LOW("Enabling C2D");
Praveen Chavandb7776f2014-02-06 18:17:25 -08009559 if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) &&
9560 (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009561 DEBUG_PRINT_ERROR("Unsupported color format for c2d");
Arun Menon906de572013-06-18 17:01:40 -07009562 status = false;
9563 } else {
Praveen Chavandb7776f2014-02-06 18:17:25 -08009564 ColorFormat = dest_color_format;
9565 dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ?
9566 YCbCr420P : YCbCr420SP;
Arun Menon906de572013-06-18 17:01:40 -07009567 if (enabled)
9568 c2d.destroy();
9569 enabled = false;
9570 if (!c2d.init()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009571 DEBUG_PRINT_ERROR("open failed for c2d");
Arun Menon906de572013-06-18 17:01:40 -07009572 status = false;
9573 } else
9574 enabled = true;
9575 }
9576 } else {
9577 if (enabled)
9578 c2d.destroy();
9579 enabled = false;
9580 }
9581 pthread_mutex_unlock(&omx->c_lock);
9582 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009583}
9584
9585OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr()
9586{
Arun Menon906de572013-06-18 17:01:40 -07009587 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009588 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009589 return NULL;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009590 }
Arun Menon906de572013-06-18 17:01:40 -07009591 if (!enabled)
9592 return omx->m_out_mem_ptr;
9593 return m_out_mem_ptr_client;
9594}
9595
9596 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr
9597(OMX_BUFFERHEADERTYPE *bufadd)
9598{
9599 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009600 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009601 return NULL;
9602 }
9603 if (!enabled)
9604 return bufadd;
9605
9606 unsigned index = 0;
9607 index = bufadd - omx->m_out_mem_ptr;
9608 if (index < omx->drv_ctx.op_buf.actualcount) {
9609 m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS);
9610 m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp;
9611 bool status;
9612 if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) {
9613 pthread_mutex_lock(&omx->c_lock);
9614 status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd,
9615 omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index],
9616 pmem_baseaddress[index], pmem_baseaddress[index]);
Arun Menon906de572013-06-18 17:01:40 -07009617 if (!status) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009618 DEBUG_PRINT_ERROR("Failed color conversion %d", status);
Arun Menon906de572013-06-18 17:01:40 -07009619 m_out_mem_ptr_client[index].nFilledLen = 0;
Leena Winterrowd270a7042014-09-30 13:05:55 -07009620 pthread_mutex_unlock(&omx->c_lock);
Arun Menon906de572013-06-18 17:01:40 -07009621 return &m_out_mem_ptr_client[index];
Praveen Chavan6d6b7252014-09-15 17:05:54 -07009622 } else {
9623 unsigned int filledLen = 0;
9624 c2d.get_output_filled_length(filledLen);
9625 m_out_mem_ptr_client[index].nFilledLen = filledLen;
Arun Menon906de572013-06-18 17:01:40 -07009626 }
Leena Winterrowd270a7042014-09-30 13:05:55 -07009627 pthread_mutex_unlock(&omx->c_lock);
Arun Menon906de572013-06-18 17:01:40 -07009628 } else
9629 m_out_mem_ptr_client[index].nFilledLen = 0;
9630 return &m_out_mem_ptr_client[index];
9631 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009632 DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009633 return NULL;
9634}
9635
9636 OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr
9637(OMX_BUFFERHEADERTYPE *bufadd)
9638{
9639 if (!omx) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009640 DEBUG_PRINT_ERROR("Invalid param get_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009641 return NULL;
9642 }
9643 if (!enabled)
9644 return bufadd;
9645 unsigned index = 0;
9646 index = bufadd - m_out_mem_ptr_client;
9647 if (index < omx->drv_ctx.op_buf.actualcount) {
9648 return &omx->m_out_mem_ptr[index];
9649 }
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009650 DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr");
Arun Menon906de572013-06-18 17:01:40 -07009651 return NULL;
9652}
9653 bool omx_vdec::allocate_color_convert_buf::get_buffer_req
9654(unsigned int &buffer_size)
9655{
9656 bool status = true;
9657 pthread_mutex_lock(&omx->c_lock);
9658 if (!enabled)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009659 buffer_size = omx->drv_ctx.op_buf.buffer_size;
Arun Menon906de572013-06-18 17:01:40 -07009660 else {
9661 if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009662 DEBUG_PRINT_ERROR("Get buffer size failed");
Arun Menon906de572013-06-18 17:01:40 -07009663 status = false;
9664 goto fail_get_buffer_size;
9665 }
9666 }
9667 if (buffer_size < omx->drv_ctx.op_buf.buffer_size)
9668 buffer_size = omx->drv_ctx.op_buf.buffer_size;
9669 if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment)
9670 buffer_alignment_req = omx->drv_ctx.op_buf.alignment;
Praneeth Paladuguf6995272013-02-04 14:03:56 -08009671fail_get_buffer_size:
Arun Menon906de572013-06-18 17:01:40 -07009672 pthread_mutex_unlock(&omx->c_lock);
9673 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009674}
9675OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer(
Arun Menon906de572013-06-18 17:01:40 -07009676 OMX_BUFFERHEADERTYPE *bufhdr)
9677{
9678 unsigned int index = 0;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009679
Arun Menon906de572013-06-18 17:01:40 -07009680 if (!enabled)
9681 return omx->free_output_buffer(bufhdr);
9682 if (enabled && omx->is_component_secure())
9683 return OMX_ErrorNone;
9684 if (!allocated_count || !bufhdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009685 DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr);
Arun Menon906de572013-06-18 17:01:40 -07009686 return OMX_ErrorBadParameter;
9687 }
9688 index = bufhdr - m_out_mem_ptr_client;
9689 if (index >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009690 DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer");
Arun Menon906de572013-06-18 17:01:40 -07009691 return OMX_ErrorBadParameter;
9692 }
9693 if (pmem_fd[index] > 0) {
9694 munmap(pmem_baseaddress[index], buffer_size_req);
9695 close(pmem_fd[index]);
9696 }
9697 pmem_fd[index] = -1;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009698#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009699 omx->free_ion_memory(&op_buf_ion_info[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009700#endif
Arun Menon906de572013-06-18 17:01:40 -07009701 m_heap_ptr[index].video_heap_ptr = NULL;
9702 if (allocated_count > 0)
9703 allocated_count--;
9704 else
9705 allocated_count = 0;
9706 if (!allocated_count) {
9707 pthread_mutex_lock(&omx->c_lock);
9708 c2d.close();
9709 init_members();
9710 pthread_mutex_unlock(&omx->c_lock);
9711 }
9712 return omx->free_output_buffer(&omx->m_out_mem_ptr[index]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009713}
9714
9715OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
Arun Menon906de572013-06-18 17:01:40 -07009716 OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes)
Vinay Kaliada4f4422013-01-09 10:45:03 -08009717{
Arun Menon906de572013-06-18 17:01:40 -07009718 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9719 if (!enabled) {
9720 eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes);
9721 return eRet;
9722 }
9723 if (enabled && omx->is_component_secure()) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009724 DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d",
Arun Menon906de572013-06-18 17:01:40 -07009725 omx->is_component_secure());
9726 return OMX_ErrorUnsupportedSetting;
9727 }
9728 if (!bufferHdr || bytes > buffer_size_req) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009729 DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr);
9730 DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu",
Arun Menon906de572013-06-18 17:01:40 -07009731 buffer_size_req,bytes);
9732 return OMX_ErrorBadParameter;
9733 }
9734 if (allocated_count >= omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009735 DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009736 return OMX_ErrorInsufficientResources;
9737 }
9738 OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL;
9739 eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr,
9740 port,appData,omx->drv_ctx.op_buf.buffer_size);
9741 if (eRet != OMX_ErrorNone || !temp_bufferHdr) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009742 DEBUG_PRINT_ERROR("Buffer allocation failed color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009743 return eRet;
9744 }
9745 if ((temp_bufferHdr - omx->m_out_mem_ptr) >=
Surajit Podderd2644d52013-08-28 17:59:06 +05309746 (int)omx->drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009747 DEBUG_PRINT_ERROR("Invalid header index %d",
Arun Menon906de572013-06-18 17:01:40 -07009748 (temp_bufferHdr - omx->m_out_mem_ptr));
9749 return OMX_ErrorUndefined;
9750 }
9751 unsigned int i = allocated_count;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009752#ifdef USE_ION
Arun Menon906de572013-06-18 17:01:40 -07009753 op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory(
9754 buffer_size_req,buffer_alignment_req,
9755 &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data,
9756 0);
9757 pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd;
9758 if (op_buf_ion_info[i].ion_device_fd < 0) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009759 DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert");
Arun Menon906de572013-06-18 17:01:40 -07009760 return OMX_ErrorInsufficientResources;
9761 }
9762 pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req,
9763 PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009764
Arun Menon906de572013-06-18 17:01:40 -07009765 if (pmem_baseaddress[i] == MAP_FAILED) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009766 DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req);
Arun Menon906de572013-06-18 17:01:40 -07009767 close(pmem_fd[i]);
9768 omx->free_ion_memory(&op_buf_ion_info[i]);
9769 return OMX_ErrorInsufficientResources;
9770 }
9771 m_heap_ptr[i].video_heap_ptr = new VideoHeap (
9772 op_buf_ion_info[i].ion_device_fd,buffer_size_req,
9773 pmem_baseaddress[i],op_buf_ion_info[i].ion_alloc_data.handle,pmem_fd[i]);
Vinay Kaliada4f4422013-01-09 10:45:03 -08009774#endif
Arun Menon906de572013-06-18 17:01:40 -07009775 m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get();
9776 m_pmem_info_client[i].offset = 0;
9777 m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i];
9778 m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
9779 m_platform_list_client[i].nEntries = 1;
9780 m_platform_list_client[i].entryList = &m_platform_entry_client[i];
9781 m_out_mem_ptr_client[i].pOutputPortPrivate = NULL;
9782 m_out_mem_ptr_client[i].nAllocLen = buffer_size_req;
9783 m_out_mem_ptr_client[i].nFilledLen = 0;
9784 m_out_mem_ptr_client[i].nFlags = 0;
9785 m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
9786 m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE);
9787 m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION;
9788 m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i];
9789 m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i];
9790 m_out_mem_ptr_client[i].pAppPrivate = appData;
9791 *bufferHdr = &m_out_mem_ptr_client[i];
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009792 DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr);
Arun Menon906de572013-06-18 17:01:40 -07009793 allocated_count++;
9794 return eRet;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009795}
9796
9797bool omx_vdec::is_component_secure()
9798{
Arun Menon906de572013-06-18 17:01:40 -07009799 return secure_mode;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009800}
9801
9802bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format)
9803{
Arun Menon906de572013-06-18 17:01:40 -07009804 bool status = true;
9805 if (!enabled) {
9806 if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12)
9807 dest_color_format = (OMX_COLOR_FORMATTYPE)
9808 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
9809 else
9810 status = false;
9811 } else {
Praveen Chavandb7776f2014-02-06 18:17:25 -08009812 if (ColorFormat == OMX_COLOR_FormatYUV420Planar ||
9813 ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
9814 dest_color_format = ColorFormat;
Arun Menon906de572013-06-18 17:01:40 -07009815 } else
Praveen Chavandb7776f2014-02-06 18:17:25 -08009816 status = false;
Arun Menon906de572013-06-18 17:01:40 -07009817 }
9818 return status;
Vinay Kaliada4f4422013-01-09 10:45:03 -08009819}
Arun Menonbdb80b02013-08-12 17:45:54 -07009820
Arun Menonbdb80b02013-08-12 17:45:54 -07009821void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset)
9822{
9823 int i = 0;
9824 bool buf_present = false;
9825 pthread_mutex_lock(&m_lock);
9826 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9827 //check the buffer fd, offset, uv addr with list contents
9828 //If present increment reference.
9829 if ((out_dynamic_list[i].fd == fd) &&
9830 (out_dynamic_list[i].offset == offset)) {
9831 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009832 DEBUG_PRINT_LOW("buf_ref_add: [ALREADY PRESENT] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009833 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9834 buf_present = true;
9835 break;
9836 }
9837 }
9838 if (!buf_present) {
9839 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9840 //search for a entry to insert details of the new buffer
9841 if (out_dynamic_list[i].dup_fd == 0) {
9842 out_dynamic_list[i].fd = fd;
9843 out_dynamic_list[i].offset = offset;
9844 out_dynamic_list[i].dup_fd = dup(fd);
9845 out_dynamic_list[i].ref_count++;
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009846 DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009847 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9848 break;
9849 }
9850 }
9851 }
9852 pthread_mutex_unlock(&m_lock);
9853}
9854
9855void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset)
9856{
9857 int i = 0;
9858 pthread_mutex_lock(&m_lock);
9859 for (i = 0; i < drv_ctx.op_buf.actualcount; i++) {
9860 //check the buffer fd, offset, uv addr with list contents
9861 //If present decrement reference.
9862 if ((out_dynamic_list[i].fd == fd) &&
9863 (out_dynamic_list[i].offset == offset)) {
9864 out_dynamic_list[i].ref_count--;
9865 if (out_dynamic_list[i].ref_count == 0) {
9866 close(out_dynamic_list[i].dup_fd);
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009867 DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d",
Arun Menonbdb80b02013-08-12 17:45:54 -07009868 out_dynamic_list[i].fd, out_dynamic_list[i].ref_count);
9869 out_dynamic_list[i].dup_fd = 0;
9870 out_dynamic_list[i].fd = 0;
9871 out_dynamic_list[i].offset = 0;
9872 }
9873 break;
9874 }
9875 }
9876 if (i >= drv_ctx.op_buf.actualcount) {
Deva Ramasubramanian43918e22013-10-21 20:04:23 -07009877 DEBUG_PRINT_ERROR("Error - could not remove ref, no match with any entry in list");
Arun Menonbdb80b02013-08-12 17:45:54 -07009878 }
9879 pthread_mutex_unlock(&m_lock);
9880}
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07009881
Arun Menon1fc764f2014-04-17 15:41:27 -07009882OMX_ERRORTYPE omx_vdec::enable_adaptive_playback(unsigned long nMaxFrameWidth,
9883 unsigned long nMaxFrameHeight)
9884{
9885
9886 OMX_ERRORTYPE eRet = OMX_ErrorNone;
9887 int ret = 0;
9888 unsigned long min_res_buf_count = 0;
9889
9890 eRet = enable_smoothstreaming();
9891 if (eRet != OMX_ErrorNone) {
9892 DEBUG_PRINT_ERROR("Failed to enable Adaptive Playback on driver");
9893 return eRet;
9894 }
9895
9896 DEBUG_PRINT_HIGH("Enabling Adaptive playback for %lu x %lu",
9897 nMaxFrameWidth,
9898 nMaxFrameHeight);
9899 m_smoothstreaming_mode = true;
9900 m_smoothstreaming_width = nMaxFrameWidth;
9901 m_smoothstreaming_height = nMaxFrameHeight;
9902
9903 //Get upper limit buffer count for min supported resolution
9904 struct v4l2_format fmt;
9905 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
9906 fmt.fmt.pix_mp.height = m_decoder_capability.min_height;
9907 fmt.fmt.pix_mp.width = m_decoder_capability.min_width;
9908 fmt.fmt.pix_mp.pixelformat = output_capability;
9909
9910 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
9911 if (ret) {
9912 DEBUG_PRINT_ERROR("Set Resolution failed for HxW = %ux%u",
9913 m_decoder_capability.min_height,
9914 m_decoder_capability.min_width);
9915 return OMX_ErrorUnsupportedSetting;
9916 }
9917
9918 eRet = get_buffer_req(&drv_ctx.op_buf);
9919 if (eRet != OMX_ErrorNone) {
9920 DEBUG_PRINT_ERROR("failed to get_buffer_req");
9921 return eRet;
9922 }
9923
9924 min_res_buf_count = drv_ctx.op_buf.mincount;
9925 DEBUG_PRINT_LOW("enable adaptive - upper limit buffer count = %lu for HxW %ux%u",
9926 min_res_buf_count, m_decoder_capability.min_height, m_decoder_capability.min_width);
9927
9928 update_resolution(m_smoothstreaming_width, m_smoothstreaming_height,
9929 m_smoothstreaming_width, m_smoothstreaming_height);
9930 eRet = is_video_session_supported();
9931 if (eRet != OMX_ErrorNone) {
9932 DEBUG_PRINT_ERROR("video session is not supported");
9933 return eRet;
9934 }
9935
9936 //Get upper limit buffer size for max smooth streaming resolution set
9937 fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
9938 fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height;
9939 fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width;
9940 fmt.fmt.pix_mp.pixelformat = output_capability;
9941 ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt);
9942 if (ret) {
9943 DEBUG_PRINT_ERROR("Set Resolution failed for adaptive playback");
9944 return OMX_ErrorUnsupportedSetting;
9945 }
9946
9947 eRet = get_buffer_req(&drv_ctx.op_buf);
9948 if (eRet != OMX_ErrorNone) {
9949 DEBUG_PRINT_ERROR("failed to get_buffer_req!!");
9950 return eRet;
9951 }
9952 DEBUG_PRINT_LOW("enable adaptive - upper limit buffer size = %u",
9953 drv_ctx.op_buf.buffer_size);
9954
9955 drv_ctx.op_buf.mincount = min_res_buf_count;
9956 drv_ctx.op_buf.actualcount = min_res_buf_count;
9957 eRet = set_buffer_req(&drv_ctx.op_buf);
9958 if (eRet != OMX_ErrorNone) {
9959 DEBUG_PRINT_ERROR("failed to set_buffer_req");
9960 return eRet;
9961 }
9962
9963 eRet = get_buffer_req(&drv_ctx.op_buf);
9964 if (eRet != OMX_ErrorNone) {
9965 DEBUG_PRINT_ERROR("failed to get_buffer_req!!!");
9966 return eRet;
9967 }
9968 DEBUG_PRINT_HIGH("adaptive playback enabled, buf count = %u bufsize = %u",
9969 drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size);
9970 return eRet;
9971}
9972
Leena Winterrowd974fd1f2013-10-30 10:58:02 -07009973#ifdef _MSM8974_
9974void omx_vdec::send_codec_config() {
9975 if (codec_config_flag) {
9976 unsigned p1 = 0; // Parameter - 1
9977 unsigned p2 = 0; // Parameter - 2
9978 unsigned ident = 0;
9979 pthread_mutex_lock(&m_lock);
9980 DEBUG_PRINT_LOW("\n Check Queue for codec_config buffer \n");
9981 while (m_etb_q.m_size) {
9982 m_etb_q.pop_entry(&p1,&p2,&ident);
9983 if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) {
9984 if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
9985 if (empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\
9986 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
9987 DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy_arbitrary failure");
9988 omx_report_error();
9989 }
9990 } else {
9991 DEBUG_PRINT_LOW("\n Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2);
9992 m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2);
9993 }
9994 } else if (ident == OMX_COMPONENT_GENERATE_ETB) {
9995 if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
9996 if (empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\
9997 (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) {
9998 DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy failure");
9999 omx_report_error ();
10000 }
10001 } else {
10002 pending_input_buffers++;
10003 DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d",
10004 (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers);
10005 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
10006 }
10007 } else if (ident == OMX_COMPONENT_GENERATE_EBD) {
10008 DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_EBD %p",
10009 (OMX_BUFFERHEADERTYPE *)p1);
10010 empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
10011 }
10012 }
10013 pthread_mutex_unlock(&m_lock);
10014 }
10015}
10016#endif
Praveen Chavan09a82b72014-10-18 09:09:45 -070010017
10018//static
10019OMX_ERRORTYPE omx_vdec::describeColorFormat(OMX_PTR pParam) {
10020
10021#ifndef FLEXYUV_SUPPORTED
10022 (void)pParam;
10023 return OMX_ErrorUndefined;
10024#else
10025
10026 if (pParam == NULL) {
10027 DEBUG_PRINT_ERROR("describeColorFormat: invalid params");
10028 return OMX_ErrorBadParameter;
10029 }
10030
10031 DescribeColorFormatParams *params = (DescribeColorFormatParams*)pParam;
10032
10033 MediaImage *img = &(params->sMediaImage);
10034 switch(params->eColorFormat) {
10035 case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m:
10036 {
10037 img->mType = MediaImage::MEDIA_IMAGE_TYPE_YUV;
10038 img->mNumPlanes = 3;
10039 // mWidth and mHeight represent the W x H of the largest plane
10040 // In our case, this happens to be the Stride x Scanlines of Y plane
10041 img->mWidth = params->nFrameWidth;
10042 img->mHeight = params->nFrameHeight;
10043 size_t planeWidth = VENUS_Y_STRIDE(COLOR_FMT_NV12, params->nFrameWidth);
10044 size_t planeHeight = VENUS_Y_SCANLINES(COLOR_FMT_NV12, params->nFrameHeight);
10045 img->mBitDepth = 8;
10046 //Plane 0 (Y)
10047 img->mPlane[MediaImage::Y].mOffset = 0;
10048 img->mPlane[MediaImage::Y].mColInc = 1;
10049 img->mPlane[MediaImage::Y].mRowInc = planeWidth; //same as stride
10050 img->mPlane[MediaImage::Y].mHorizSubsampling = 1;
10051 img->mPlane[MediaImage::Y].mVertSubsampling = 1;
10052 //Plane 1 (U)
10053 img->mPlane[MediaImage::U].mOffset = planeWidth * planeHeight;
10054 img->mPlane[MediaImage::U].mColInc = 2; //interleaved UV
10055 img->mPlane[MediaImage::U].mRowInc =
10056 VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth);
10057 img->mPlane[MediaImage::U].mHorizSubsampling = 2;
10058 img->mPlane[MediaImage::U].mVertSubsampling = 2;
10059 //Plane 2 (V)
10060 img->mPlane[MediaImage::V].mOffset = planeWidth * planeHeight + 1;
10061 img->mPlane[MediaImage::V].mColInc = 2; //interleaved UV
10062 img->mPlane[MediaImage::V].mRowInc =
10063 VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth);
10064 img->mPlane[MediaImage::V].mHorizSubsampling = 2;
10065 img->mPlane[MediaImage::V].mVertSubsampling = 2;
10066 break;
10067 }
10068
10069 case OMX_COLOR_FormatYUV420Planar:
10070 case OMX_COLOR_FormatYUV420SemiPlanar:
10071 // We need not describe the standard OMX linear formats as these are
10072 // understood by client. Fail this deliberately to let client fill-in
10073 return OMX_ErrorUnsupportedSetting;
10074
10075 default:
10076 // Rest all formats which are non-linear cannot be described
10077 DEBUG_PRINT_LOW("color-format %x is not flexible", params->eColorFormat);
10078 img->mType = MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN;
10079 return OMX_ErrorNone;
10080 };
10081
10082 DEBUG_PRINT_LOW("NOTE: Describe color format : %x", params->eColorFormat);
10083 DEBUG_PRINT_LOW(" FrameWidth x FrameHeight : %d x %d", params->nFrameWidth, params->nFrameHeight);
10084 DEBUG_PRINT_LOW(" YWidth x YHeight : %d x %d", img->mWidth, img->mHeight);
10085 for (size_t i = 0; i < img->mNumPlanes; ++i) {
10086 DEBUG_PRINT_LOW(" Plane[%d] : offset=%d / xStep=%d / yStep = %d",
10087 i, img->mPlane[i].mOffset, img->mPlane[i].mColInc, img->mPlane[i].mRowInc);
10088 }
10089 return OMX_ErrorNone;
10090#endif //FLEXYUV_SUPPORTED
10091}
10092