Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1 | /*-------------------------------------------------------------------------- |
Vinay Kalia | e4a7d9d | 2013-01-21 10:16:33 -0800 | [diff] [blame] | 2 | Copyright (c) 2010 - 2013, The Linux Foundation. All rights reserved. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, 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 Kalia | e4a7d9d | 2013-01-21 10:16:33 -0800 | [diff] [blame] | 11 | * Neither the name of The Linux Foundation nor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 12 | 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 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | --------------------------------------------------------------------------*/ |
| 28 | |
| 29 | /*============================================================================ |
| 30 | O p e n M A X w r a p p e r s |
| 31 | O p e n M A X C o r e |
| 32 | |
| 33 | *//** @file omx_vdec.cpp |
| 34 | This module contains the implementation of the OpenMAX core & component. |
| 35 | |
| 36 | *//*========================================================================*/ |
| 37 | |
| 38 | ////////////////////////////////////////////////////////////////////////////// |
| 39 | // Include Files |
| 40 | ////////////////////////////////////////////////////////////////////////////// |
| 41 | |
| 42 | #include <string.h> |
| 43 | #include <pthread.h> |
| 44 | #include <sys/prctl.h> |
| 45 | #include <stdlib.h> |
| 46 | #include <unistd.h> |
| 47 | #include <errno.h> |
| 48 | #include "omx_vdec.h" |
| 49 | #include <fcntl.h> |
| 50 | #include <limits.h> |
Deva Ramasubramanian | 15bbc1c | 2013-05-13 16:05:03 -0700 | [diff] [blame] | 51 | #include <stdlib.h> |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 52 | #include <media/hardware/HardwareAPI.h> |
Vinay Kalia | da8f3cf | 2012-12-21 18:26:21 -0800 | [diff] [blame] | 53 | #include <media/msm_media_info.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 54 | |
| 55 | #ifndef _ANDROID_ |
| 56 | #include <sys/ioctl.h> |
| 57 | #include <sys/mman.h> |
| 58 | #endif //_ANDROID_ |
| 59 | |
| 60 | #ifdef _ANDROID_ |
| 61 | #include <cutils/properties.h> |
| 62 | #undef USE_EGL_IMAGE_GPU |
| 63 | #endif |
| 64 | |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 65 | #include <qdMetaData.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 66 | |
| 67 | #ifdef _ANDROID_ |
| 68 | #include "DivXDrmDecrypt.h" |
| 69 | #endif //_ANDROID_ |
| 70 | |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame^] | 71 | #ifdef METADATA_FOR_DYNAMIC_MODE |
Arun Menon | 9af783f | 2013-10-22 12:57:14 -0700 | [diff] [blame] | 72 | #include "QComOMXMetadata.h" |
| 73 | #endif |
| 74 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 75 | #ifdef USE_EGL_IMAGE_GPU |
| 76 | #include <EGL/egl.h> |
| 77 | #include <EGL/eglQCOM.h> |
| 78 | #define EGL_BUFFER_HANDLE_QCOM 0x4F00 |
| 79 | #define EGL_BUFFER_OFFSET_QCOM 0x4F01 |
| 80 | #endif |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 81 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 82 | #define BUFFER_LOG_LOC "/data/misc/media" |
| 83 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 84 | #ifdef OUTPUT_EXTRADATA_LOG |
| 85 | FILE *outputExtradataFile; |
| 86 | char ouputextradatafilename [] = "/data/extradata"; |
| 87 | #endif |
| 88 | |
| 89 | #define DEFAULT_FPS 30 |
| 90 | #define MAX_INPUT_ERROR DEFAULT_FPS |
| 91 | #define MAX_SUPPORTED_FPS 120 |
| 92 | |
| 93 | #define VC1_SP_MP_START_CODE 0xC5000000 |
| 94 | #define VC1_SP_MP_START_CODE_MASK 0xFF000000 |
| 95 | #define VC1_AP_SEQ_START_CODE 0x0F010000 |
| 96 | #define VC1_STRUCT_C_PROFILE_MASK 0xF0 |
| 97 | #define VC1_STRUCT_B_LEVEL_MASK 0xE0000000 |
| 98 | #define VC1_SIMPLE_PROFILE 0 |
| 99 | #define VC1_MAIN_PROFILE 1 |
| 100 | #define VC1_ADVANCE_PROFILE 3 |
| 101 | #define VC1_SIMPLE_PROFILE_LOW_LEVEL 0 |
| 102 | #define VC1_SIMPLE_PROFILE_MED_LEVEL 2 |
| 103 | #define VC1_STRUCT_C_LEN 4 |
| 104 | #define VC1_STRUCT_C_POS 8 |
| 105 | #define VC1_STRUCT_A_POS 12 |
| 106 | #define VC1_STRUCT_B_POS 24 |
| 107 | #define VC1_SEQ_LAYER_SIZE 36 |
Vinay Kalia | b09886c | 2012-08-20 11:27:25 -0700 | [diff] [blame] | 108 | #define POLL_TIMEOUT 0x7fffffff |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 109 | |
| 110 | #define MEM_DEVICE "/dev/ion" |
| 111 | #define MEM_HEAP_ID ION_CP_MM_HEAP_ID |
| 112 | |
| 113 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 114 | extern "C" { |
| 115 | #include<utils/Log.h> |
| 116 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 117 | #endif//_ANDROID_ |
| 118 | |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 119 | #define SZ_4K 0x1000 |
| 120 | #define SZ_1M 0x100000 |
| 121 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 122 | #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 Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 124 | #define EXTRADATA_IDX(__num_planes) (__num_planes - 1) |
| 125 | |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 126 | #define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA) |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 127 | |
| 128 | int debug_level = PRIO_ERROR; |
| 129 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 130 | void* async_message_thread (void *input) |
| 131 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 132 | OMX_BUFFERHEADERTYPE *buffer; |
| 133 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 134 | struct pollfd pfd; |
| 135 | struct v4l2_buffer v4l2_buf; |
| 136 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 137 | struct v4l2_event dqevent; |
| 138 | omx_vdec *omx = reinterpret_cast<omx_vdec*>(input); |
| 139 | pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI; |
| 140 | pfd.fd = omx->drv_ctx.video_driver_fd; |
| 141 | int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 142 | DEBUG_PRINT_HIGH("omx_vdec: Async thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 143 | prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0); |
| 144 | while (1) { |
| 145 | rc = poll(&pfd, 1, POLL_TIMEOUT); |
| 146 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 147 | DEBUG_PRINT_ERROR("Poll timedout"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 148 | break; |
| 149 | } else if (rc < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 150 | DEBUG_PRINT_ERROR("Error while polling: %d", rc); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 151 | break; |
| 152 | } |
| 153 | if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) { |
| 154 | struct vdec_msginfo vdec_msg; |
| 155 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 156 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 157 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 158 | v4l2_buf.m.planes = plane; |
| 159 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 160 | vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 161 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 162 | vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf; |
| 163 | vdec_msg.msgdata.output_frame.len=plane[0].bytesused; |
| 164 | vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr; |
| 165 | vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) + |
| 166 | (uint64_t)v4l2_buf.timestamp.tv_usec; |
| 167 | if (vdec_msg.msgdata.output_frame.len) { |
| 168 | vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2]; |
| 169 | vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3]; |
| 170 | vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4]; |
| 171 | vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5]; |
| 172 | } |
| 173 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 174 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 175 | break; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) { |
| 180 | struct vdec_msginfo vdec_msg; |
| 181 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 182 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 183 | v4l2_buf.length = 1; |
| 184 | v4l2_buf.m.planes = plane; |
| 185 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 186 | vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE; |
| 187 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 188 | vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf; |
| 189 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 190 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 191 | break; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | if (pfd.revents & POLLPRI) { |
| 196 | rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent); |
| 197 | if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) { |
| 198 | struct vdec_msginfo vdec_msg; |
| 199 | vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED; |
| 200 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 201 | DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 202 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 203 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 204 | break; |
| 205 | } |
| 206 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) { |
| 207 | struct vdec_msginfo vdec_msg; |
| 208 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE; |
| 209 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 210 | DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 211 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 212 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE; |
| 216 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 217 | DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 218 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 219 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 223 | DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 224 | break; |
| 225 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) { |
| 226 | struct vdec_msginfo vdec_msg; |
| 227 | vdec_msg.msgcode=VDEC_MSG_EVT_HW_ERROR; |
| 228 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 229 | DEBUG_PRINT_HIGH("SYS Error Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 230 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 231 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 232 | break; |
| 233 | } |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame^] | 234 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 235 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 236 | DEBUG_PRINT_LOW("REFERENCE RELEASE EVENT RECVD fd = %d offset = %d", ptr[0], ptr[1]); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 237 | omx->buf_ref_remove(ptr[0], ptr[1]); |
| 238 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) { |
| 239 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
| 240 | struct vdec_msginfo vdec_msg; |
| 241 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 242 | DEBUG_PRINT_LOW("Release unqueued buffer event recvd fd = %d offset = %d", ptr[0], ptr[1]); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 243 | |
| 244 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 245 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 246 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 247 | v4l2_buf.m.planes = plane; |
| 248 | v4l2_buf.index = ptr[5]; |
| 249 | v4l2_buf.flags = 0; |
| 250 | |
| 251 | vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 252 | vdec_msg.status_code = VDEC_S_SUCCESS; |
| 253 | vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf; |
| 254 | vdec_msg.msgdata.output_frame.len = 0; |
| 255 | vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2]; |
| 256 | vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) + |
| 257 | (uint64_t)ptr[4]; |
| 258 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 259 | DEBUG_PRINT_HIGH("async_message_thread Exitedn"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 260 | break; |
| 261 | } |
| 262 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 263 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 264 | DEBUG_PRINT_HIGH("VIDC Some Event recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 265 | continue; |
| 266 | } |
| 267 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 268 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 269 | DEBUG_PRINT_HIGH("omx_vdec: Async thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 270 | return NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void* message_thread(void *input) |
| 274 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 275 | omx_vdec* omx = reinterpret_cast<omx_vdec*>(input); |
| 276 | unsigned char id; |
| 277 | int n; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 278 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 279 | DEBUG_PRINT_HIGH("omx_vdec: message thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 280 | prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0); |
| 281 | while (1) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 282 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 283 | n = read(omx->m_pipe_in, &id, 1); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 284 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 285 | if (0 == n) { |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | if (1 == n) { |
| 290 | omx->process_event_cb(omx, id); |
| 291 | } |
| 292 | if ((n < 0) && (errno != EINTR)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 293 | DEBUG_PRINT_LOW("ERROR: read from pipe failed, ret %d errno %d", n, errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 294 | break; |
| 295 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 296 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 297 | DEBUG_PRINT_HIGH("omx_vdec: message thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 298 | return 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void post_message(omx_vdec *omx, unsigned char id) |
| 302 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 303 | int ret_value; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 304 | DEBUG_PRINT_LOW("omx_vdec: post_message %d pipe out%d", id,omx->m_pipe_out); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 305 | ret_value = write(omx->m_pipe_out, &id, 1); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 306 | DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // omx_cmd_queue destructor |
| 310 | omx_vdec::omx_cmd_queue::~omx_cmd_queue() |
| 311 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 312 | // Nothing to do |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // omx cmd queue constructor |
| 316 | omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0) |
| 317 | { |
| 318 | memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE); |
| 319 | } |
| 320 | |
| 321 | // omx cmd queue insert |
| 322 | bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id) |
| 323 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 324 | bool ret = true; |
| 325 | if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 326 | m_q[m_write].id = id; |
| 327 | m_q[m_write].param1 = p1; |
| 328 | m_q[m_write].param2 = p2; |
| 329 | m_write++; |
| 330 | m_size ++; |
| 331 | if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 332 | m_write = 0; |
| 333 | } |
| 334 | } else { |
| 335 | ret = false; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 336 | DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 337 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 338 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | // omx cmd queue pop |
| 342 | bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id) |
| 343 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 344 | bool ret = true; |
| 345 | if (m_size > 0) { |
| 346 | *id = m_q[m_read].id; |
| 347 | *p1 = m_q[m_read].param1; |
| 348 | *p2 = m_q[m_read].param2; |
| 349 | // Move the read pointer ahead |
| 350 | ++m_read; |
| 351 | --m_size; |
| 352 | if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 353 | m_read = 0; |
| 354 | } |
| 355 | } else { |
| 356 | ret = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 357 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 358 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // Retrieve the first mesg type in the queue |
| 362 | unsigned omx_vdec::omx_cmd_queue::get_q_msg_type() |
| 363 | { |
| 364 | return m_q[m_read].id; |
| 365 | } |
| 366 | |
| 367 | #ifdef _ANDROID_ |
| 368 | omx_vdec::ts_arr_list::ts_arr_list() |
| 369 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 370 | //initialize timestamps array |
| 371 | memset(m_ts_arr_list, 0, ( sizeof(ts_entry) * MAX_NUM_INPUT_OUTPUT_BUFFERS) ); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 372 | } |
| 373 | omx_vdec::ts_arr_list::~ts_arr_list() |
| 374 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 375 | //free m_ts_arr_list? |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts) |
| 379 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 380 | bool ret = true; |
| 381 | bool duplicate_ts = false; |
| 382 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 383 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 384 | //insert at the first available empty location |
| 385 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 386 | if (!m_ts_arr_list[idx].valid) { |
| 387 | //found invalid or empty entry, save timestamp |
| 388 | m_ts_arr_list[idx].valid = true; |
| 389 | m_ts_arr_list[idx].timestamp = ts; |
| 390 | DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)", |
| 391 | ts, idx); |
| 392 | break; |
| 393 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 394 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 395 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 396 | if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 397 | DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert"); |
| 398 | ret = false; |
| 399 | } |
| 400 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts) |
| 404 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 405 | bool ret = true; |
| 406 | int min_idx = -1; |
| 407 | OMX_TICKS min_ts = 0; |
| 408 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 409 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 410 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 411 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 412 | if (m_ts_arr_list[idx].valid) { |
| 413 | //found valid entry, save index |
| 414 | if (min_idx < 0) { |
| 415 | //first valid entry |
| 416 | min_ts = m_ts_arr_list[idx].timestamp; |
| 417 | min_idx = idx; |
| 418 | } else if (m_ts_arr_list[idx].timestamp < min_ts) { |
| 419 | min_ts = m_ts_arr_list[idx].timestamp; |
| 420 | min_idx = idx; |
| 421 | } |
| 422 | } |
| 423 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 426 | if (min_idx < 0) { |
| 427 | //no valid entries found |
| 428 | DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop"); |
| 429 | ts = 0; |
| 430 | ret = false; |
| 431 | } else { |
| 432 | ts = m_ts_arr_list[min_idx].timestamp; |
| 433 | m_ts_arr_list[min_idx].valid = false; |
| 434 | DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)", |
| 435 | ts, min_idx); |
| 436 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 437 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 438 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 439 | |
| 440 | } |
| 441 | |
| 442 | |
| 443 | bool omx_vdec::ts_arr_list::reset_ts_list() |
| 444 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 445 | bool ret = true; |
| 446 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 447 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 448 | DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list"); |
| 449 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 450 | m_ts_arr_list[idx].valid = false; |
| 451 | } |
| 452 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 453 | } |
| 454 | #endif |
| 455 | |
| 456 | // factory function executed by the core to create instances |
| 457 | void *get_omx_component_factory_fn(void) |
| 458 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 459 | return (new omx_vdec); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | #ifdef _ANDROID_ |
| 463 | #ifdef USE_ION |
| 464 | VideoHeap::VideoHeap(int devicefd, size_t size, void* base, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 465 | struct ion_handle *handle, int ionMapfd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 466 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 467 | // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 468 | } |
| 469 | #else |
| 470 | VideoHeap::VideoHeap(int fd, size_t size, void* base) |
| 471 | { |
| 472 | // dup file descriptor, map once, use pmem |
| 473 | init(dup(fd), base, size, 0 , MEM_DEVICE); |
| 474 | } |
| 475 | #endif |
| 476 | #endif // _ANDROID_ |
| 477 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 478 | FUNCTION |
| 479 | omx_vdec::omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 480 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 481 | DESCRIPTION |
| 482 | Constructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 483 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 484 | PARAMETERS |
| 485 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 486 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 487 | RETURN VALUE |
| 488 | None. |
| 489 | ========================================================================== */ |
Deva Ramasubramanian | 5c24124 | 2013-02-19 17:25:30 -0800 | [diff] [blame] | 490 | omx_vdec::omx_vdec(): m_error_propogated(false), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 491 | m_state(OMX_StateInvalid), |
| 492 | m_app_data(NULL), |
| 493 | m_inp_mem_ptr(NULL), |
| 494 | m_out_mem_ptr(NULL), |
| 495 | m_inp_err_count(0), |
| 496 | input_flush_progress (false), |
| 497 | output_flush_progress (false), |
| 498 | input_use_buffer (false), |
| 499 | output_use_buffer (false), |
| 500 | ouput_egl_buffers(false), |
| 501 | m_use_output_pmem(OMX_FALSE), |
| 502 | m_out_mem_region_smi(OMX_FALSE), |
| 503 | m_out_pvt_entry_pmem(OMX_FALSE), |
| 504 | pending_input_buffers(0), |
| 505 | pending_output_buffers(0), |
| 506 | m_out_bm_count(0), |
| 507 | m_inp_bm_count(0), |
| 508 | m_inp_bPopulated(OMX_FALSE), |
| 509 | m_out_bPopulated(OMX_FALSE), |
| 510 | m_flags(0), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 511 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 512 | m_heap_ptr(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 513 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 514 | m_inp_bEnabled(OMX_TRUE), |
| 515 | m_out_bEnabled(OMX_TRUE), |
| 516 | m_in_alloc_cnt(0), |
| 517 | m_platform_list(NULL), |
| 518 | m_platform_entry(NULL), |
| 519 | m_pmem_info(NULL), |
| 520 | arbitrary_bytes (true), |
| 521 | psource_frame (NULL), |
| 522 | pdest_frame (NULL), |
| 523 | m_inp_heap_ptr (NULL), |
| 524 | m_phdr_pmem_ptr(NULL), |
| 525 | m_heap_inp_bm_count (0), |
| 526 | codec_type_parse ((codec_type)0), |
| 527 | first_frame_meta (true), |
| 528 | frame_count (0), |
| 529 | nal_count (0), |
| 530 | nal_length(0), |
| 531 | look_ahead_nal (false), |
| 532 | first_frame(0), |
| 533 | first_buffer(NULL), |
| 534 | first_frame_size (0), |
| 535 | m_device_file_ptr(NULL), |
| 536 | m_vc1_profile((vc1_profile_type)0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 537 | h264_last_au_ts(LLONG_MAX), |
| 538 | h264_last_au_flags(0), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 539 | m_disp_hor_size(0), |
| 540 | m_disp_vert_size(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 541 | prev_ts(LLONG_MAX), |
| 542 | rst_prev_ts(true), |
| 543 | frm_int(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 544 | in_reconfig(false), |
| 545 | m_display_id(NULL), |
| 546 | h264_parser(NULL), |
| 547 | client_extradata(0), |
| 548 | m_reject_avc_1080p_mp (0), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 549 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 550 | m_enable_android_native_buffers(OMX_FALSE), |
| 551 | m_use_android_native_buffers(OMX_FALSE), |
| 552 | iDivXDrmDecrypt(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 553 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 554 | m_desc_buffer_ptr(NULL), |
| 555 | secure_mode(false), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 556 | m_profile(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 557 | client_set_fps(false) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 558 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 559 | /* Assumption is that , to begin with , we have all the frames with decoder */ |
| 560 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 561 | memset(&m_debug,0,sizeof(m_debug)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 562 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 563 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 564 | property_get("vidc.debug.level", property_value, "0"); |
| 565 | debug_level = atoi(property_value); |
| 566 | property_value[0] = '\0'; |
| 567 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 568 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
| 569 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 570 | property_get("vidc.dec.debug.perf", property_value, "0"); |
| 571 | perf_flag = atoi(property_value); |
| 572 | if (perf_flag) { |
| 573 | DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag); |
| 574 | dec_time.start(); |
| 575 | proc_frms = latency = 0; |
| 576 | } |
| 577 | prev_n_filled_len = 0; |
| 578 | property_value[0] = '\0'; |
| 579 | property_get("vidc.dec.debug.ts", property_value, "0"); |
| 580 | m_debug_timestamp = atoi(property_value); |
| 581 | DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp); |
| 582 | if (m_debug_timestamp) { |
| 583 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 584 | time_stamp_dts.enable_debug_print(true); |
| 585 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 586 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 587 | property_value[0] = '\0'; |
| 588 | property_get("vidc.dec.debug.concealedmb", property_value, "0"); |
| 589 | m_debug_concealedmb = atoi(property_value); |
| 590 | DEBUG_PRINT_HIGH("vidc.dec.debug.concealedmb value is %d",m_debug_concealedmb); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 591 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 592 | property_value[0] = '\0'; |
| 593 | property_get("vidc.dec.profile.check", property_value, "0"); |
| 594 | m_reject_avc_1080p_mp = atoi(property_value); |
| 595 | DEBUG_PRINT_HIGH("vidc.dec.profile.check value is %d",m_reject_avc_1080p_mp); |
Rajeshwar Kurapaty | e0e7d0c | 2013-07-30 19:46:26 +0530 | [diff] [blame] | 596 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 597 | property_value[0] = '\0'; |
| 598 | property_get("vidc.dec.log.in", property_value, "0"); |
| 599 | m_debug.in_buffer_log = atoi(property_value); |
| 600 | |
| 601 | property_value[0] = '\0'; |
| 602 | property_get("vidc.dec.log.out", property_value, "0"); |
| 603 | m_debug.out_buffer_log = atoi(property_value); |
| 604 | sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC); |
| 605 | |
| 606 | property_value[0] = '\0'; |
| 607 | property_get("vidc.log.loc", property_value, ""); |
| 608 | if (*property_value) |
| 609 | strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 610 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 611 | memset(&m_cmp,0,sizeof(m_cmp)); |
| 612 | memset(&m_cb,0,sizeof(m_cb)); |
| 613 | memset (&drv_ctx,0,sizeof(drv_ctx)); |
| 614 | memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE)); |
| 615 | memset (m_hwdevice_name,0,sizeof(m_hwdevice_name)); |
| 616 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 617 | m_demux_entries = 0; |
| 618 | msg_thread_id = 0; |
| 619 | async_thread_id = 0; |
| 620 | msg_thread_created = false; |
| 621 | async_thread_created = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 622 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 623 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 624 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 625 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
| 626 | drv_ctx.timestamp_adjust = false; |
| 627 | drv_ctx.video_driver_fd = -1; |
| 628 | m_vendor_config.pData = NULL; |
| 629 | pthread_mutex_init(&m_lock, NULL); |
| 630 | pthread_mutex_init(&c_lock, NULL); |
| 631 | sem_init(&m_cmd_lock,0,0); |
| 632 | streaming[CAPTURE_PORT] = |
| 633 | streaming[OUTPUT_PORT] = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 634 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 635 | char extradata_value[PROPERTY_VALUE_MAX] = {0}; |
| 636 | property_get("vidc.dec.debug.extradata", extradata_value, "0"); |
| 637 | m_debug_extradata = atoi(extradata_value); |
| 638 | DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 639 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 640 | m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB; |
| 641 | client_buffers.set_vdec_client(this); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 642 | dynamic_buf_mode = false; |
| 643 | out_dynamic_list = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 646 | static const int event_type[] = { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 647 | V4L2_EVENT_MSM_VIDC_FLUSH_DONE, |
| 648 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT, |
| 649 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT, |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 650 | V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE, |
| 651 | V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 652 | V4L2_EVENT_MSM_VIDC_CLOSE_DONE, |
| 653 | V4L2_EVENT_MSM_VIDC_SYS_ERROR |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 654 | }; |
| 655 | |
| 656 | static OMX_ERRORTYPE subscribe_to_events(int fd) |
| 657 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 658 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 659 | struct v4l2_event_subscription sub; |
| 660 | int array_sz = sizeof(event_type)/sizeof(int); |
| 661 | int i,rc; |
| 662 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 663 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 664 | return OMX_ErrorBadParameter; |
| 665 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 666 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 667 | for (i = 0; i < array_sz; ++i) { |
| 668 | memset(&sub, 0, sizeof(sub)); |
| 669 | sub.type = event_type[i]; |
| 670 | rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub); |
| 671 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 672 | DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 673 | break; |
| 674 | } |
| 675 | } |
| 676 | if (i < array_sz) { |
| 677 | for (--i; i >=0 ; i--) { |
| 678 | memset(&sub, 0, sizeof(sub)); |
| 679 | sub.type = event_type[i]; |
| 680 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 681 | if (rc) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 682 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 683 | } |
| 684 | eRet = OMX_ErrorNotImplemented; |
| 685 | } |
| 686 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | |
| 690 | static OMX_ERRORTYPE unsubscribe_to_events(int fd) |
| 691 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 692 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 693 | struct v4l2_event_subscription sub; |
| 694 | int array_sz = sizeof(event_type)/sizeof(int); |
| 695 | int i,rc; |
| 696 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 697 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 698 | return OMX_ErrorBadParameter; |
| 699 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 700 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 701 | for (i = 0; i < array_sz; ++i) { |
| 702 | memset(&sub, 0, sizeof(sub)); |
| 703 | sub.type = event_type[i]; |
| 704 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 705 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 706 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 707 | break; |
| 708 | } |
| 709 | } |
| 710 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 711 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 712 | |
| 713 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 714 | FUNCTION |
| 715 | omx_vdec::~omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 716 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 717 | DESCRIPTION |
| 718 | Destructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 719 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 720 | PARAMETERS |
| 721 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 722 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 723 | RETURN VALUE |
| 724 | None. |
| 725 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 726 | omx_vdec::~omx_vdec() |
| 727 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 728 | m_pmem_info = NULL; |
| 729 | struct v4l2_decoder_cmd dec; |
| 730 | DEBUG_PRINT_HIGH("In OMX vdec Destructor"); |
| 731 | if (m_pipe_in) close(m_pipe_in); |
| 732 | if (m_pipe_out) close(m_pipe_out); |
| 733 | m_pipe_in = -1; |
| 734 | m_pipe_out = -1; |
| 735 | DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit"); |
| 736 | if (msg_thread_created) |
| 737 | pthread_join(msg_thread_id,NULL); |
| 738 | DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit"); |
| 739 | dec.cmd = V4L2_DEC_CMD_STOP; |
| 740 | if (drv_ctx.video_driver_fd >=0 ) { |
| 741 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 742 | DEBUG_PRINT_ERROR("STOP Command failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 743 | } |
| 744 | if (async_thread_created) |
| 745 | pthread_join(async_thread_id,NULL); |
| 746 | unsubscribe_to_events(drv_ctx.video_driver_fd); |
| 747 | close(drv_ctx.video_driver_fd); |
| 748 | pthread_mutex_destroy(&m_lock); |
| 749 | pthread_mutex_destroy(&c_lock); |
| 750 | sem_destroy(&m_cmd_lock); |
| 751 | if (perf_flag) { |
| 752 | DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME"); |
| 753 | dec_time.end(); |
| 754 | } |
| 755 | DEBUG_PRINT_HIGH("Exit OMX vdec Destructor"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 758 | int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type) |
| 759 | { |
| 760 | struct v4l2_requestbuffers bufreq; |
| 761 | int rc = 0; |
| 762 | if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 763 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 764 | bufreq.count = 0; |
| 765 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 766 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 767 | } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 768 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 769 | bufreq.count = 0; |
| 770 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 771 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 772 | } |
| 773 | return rc; |
Vinay Kalia | feef703 | 2012-09-25 19:23:33 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 776 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 777 | FUNCTION |
| 778 | omx_vdec::OMXCntrlProcessMsgCb |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 779 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 780 | DESCRIPTION |
| 781 | IL Client callbacks are generated through this routine. The decoder |
| 782 | provides the thread context for this routine. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 783 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 784 | PARAMETERS |
| 785 | ctxt -- Context information related to the self. |
| 786 | id -- Event identifier. This could be any of the following: |
| 787 | 1. Command completion event |
| 788 | 2. Buffer done callback event |
| 789 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 790 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 791 | RETURN VALUE |
| 792 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 793 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 794 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 795 | void omx_vdec::process_event_cb(void *ctxt, unsigned char id) |
| 796 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 797 | signed p1; // Parameter - 1 |
| 798 | signed p2; // Parameter - 2 |
| 799 | unsigned ident; |
| 800 | unsigned qsize=0; // qsize |
| 801 | omx_vdec *pThis = (omx_vdec *) ctxt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 802 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 803 | if (!pThis) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 804 | DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 805 | __func__); |
| 806 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 809 | // Protect the shared queue data structure |
| 810 | do { |
| 811 | /*Read the message id's from the queue*/ |
| 812 | pthread_mutex_lock(&pThis->m_lock); |
| 813 | qsize = pThis->m_cmd_q.m_size; |
| 814 | if (qsize) { |
| 815 | pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 816 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 817 | |
| 818 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 819 | qsize = pThis->m_ftb_q.m_size; |
| 820 | if (qsize) { |
| 821 | pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 822 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 823 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 824 | |
| 825 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 826 | qsize = pThis->m_etb_q.m_size; |
| 827 | if (qsize) { |
| 828 | pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 829 | } |
| 830 | } |
| 831 | pthread_mutex_unlock(&pThis->m_lock); |
| 832 | |
| 833 | /*process message if we have one*/ |
| 834 | if (qsize > 0) { |
| 835 | id = ident; |
| 836 | switch (id) { |
| 837 | case OMX_COMPONENT_GENERATE_EVENT: |
| 838 | if (pThis->m_cb.EventHandler) { |
| 839 | switch (p1) { |
| 840 | case OMX_CommandStateSet: |
| 841 | pThis->m_state = (OMX_STATETYPE) p2; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 842 | DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 843 | pThis->m_state); |
| 844 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 845 | OMX_EventCmdComplete, p1, p2, NULL); |
| 846 | break; |
| 847 | |
| 848 | case OMX_EventError: |
| 849 | if (p2 == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 850 | DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 851 | pThis->m_state = (OMX_STATETYPE) p2; |
| 852 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 853 | OMX_EventError, OMX_ErrorInvalidState, p2, NULL); |
| 854 | } else if (p2 == OMX_ErrorHardware) { |
| 855 | pThis->omx_report_error(); |
| 856 | } else { |
| 857 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 858 | OMX_EventError, p2, (OMX_U32)NULL, NULL ); |
| 859 | } |
| 860 | break; |
| 861 | |
| 862 | case OMX_CommandPortDisable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 863 | DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 864 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 865 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
| 866 | BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
| 867 | break; |
| 868 | } |
| 869 | if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 870 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 871 | pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
| 872 | if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 873 | DEBUG_PRINT_HIGH("Failed to release output buffers"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 874 | OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf); |
| 875 | pThis->in_reconfig = false; |
| 876 | if (eRet != OMX_ErrorNone) { |
| 877 | DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet); |
| 878 | pThis->omx_report_error(); |
| 879 | break; |
| 880 | } |
| 881 | } |
| 882 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 883 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 884 | break; |
| 885 | case OMX_CommandPortEnable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 886 | DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 887 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\ |
| 888 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 889 | break; |
| 890 | |
| 891 | default: |
| 892 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 893 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 894 | break; |
| 895 | |
| 896 | } |
| 897 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 898 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 899 | } |
| 900 | break; |
| 901 | case OMX_COMPONENT_GENERATE_ETB_ARBITRARY: |
| 902 | if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 903 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 904 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 905 | pThis->omx_report_error (); |
| 906 | } |
| 907 | break; |
| 908 | case OMX_COMPONENT_GENERATE_ETB: |
| 909 | if (pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 910 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 911 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 912 | pThis->omx_report_error (); |
| 913 | } |
| 914 | break; |
| 915 | |
| 916 | case OMX_COMPONENT_GENERATE_FTB: |
| 917 | if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 918 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 919 | DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 920 | pThis->omx_report_error (); |
| 921 | } |
| 922 | break; |
| 923 | |
| 924 | case OMX_COMPONENT_GENERATE_COMMAND: |
| 925 | pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\ |
| 926 | (OMX_U32)p2,(OMX_PTR)NULL); |
| 927 | break; |
| 928 | |
| 929 | case OMX_COMPONENT_GENERATE_EBD: |
| 930 | |
| 931 | if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 932 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 933 | pThis->omx_report_error (); |
| 934 | } else { |
| 935 | if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) { |
| 936 | pThis->m_inp_err_count++; |
| 937 | pThis->time_stamp_dts.remove_time_stamp( |
| 938 | ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp, |
| 939 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 940 | ?true:false); |
| 941 | } else { |
| 942 | pThis->m_inp_err_count = 0; |
| 943 | } |
| 944 | if ( pThis->empty_buffer_done(&pThis->m_cmp, |
| 945 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 946 | DEBUG_PRINT_ERROR("empty_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 947 | pThis->omx_report_error (); |
| 948 | } |
| 949 | if (pThis->m_inp_err_count >= MAX_INPUT_ERROR) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 950 | DEBUG_PRINT_ERROR("Input bitstream error for consecutive %d frames.", MAX_INPUT_ERROR); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 951 | pThis->omx_report_error (); |
| 952 | } |
| 953 | } |
| 954 | break; |
| 955 | case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: { |
| 956 | int64_t *timestamp = (int64_t *)p1; |
| 957 | if (p1) { |
| 958 | pThis->time_stamp_dts.remove_time_stamp(*timestamp, |
| 959 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 960 | ?true:false); |
| 961 | free(timestamp); |
| 962 | } |
| 963 | } |
| 964 | break; |
| 965 | case OMX_COMPONENT_GENERATE_FBD: |
| 966 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 967 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 968 | pThis->omx_report_error (); |
| 969 | } else if ( pThis->fill_buffer_done(&pThis->m_cmp, |
| 970 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 971 | DEBUG_PRINT_ERROR("fill_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 972 | pThis->omx_report_error (); |
| 973 | } |
| 974 | break; |
| 975 | |
| 976 | case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 977 | DEBUG_PRINT_HIGH("Driver flush i/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 978 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 979 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 980 | } else { |
| 981 | pThis->execute_input_flush(); |
| 982 | if (pThis->m_cb.EventHandler) { |
| 983 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 984 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 985 | pThis->omx_report_error (); |
| 986 | } else { |
| 987 | /*Check if we need generate event for Flush done*/ |
| 988 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 989 | OMX_COMPONENT_INPUT_FLUSH_PENDING)) { |
| 990 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 991 | DEBUG_PRINT_LOW("Input Flush completed - Notify Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 992 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 993 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 994 | OMX_CORE_INPUT_PORT_INDEX,NULL ); |
| 995 | } |
| 996 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 997 | OMX_COMPONENT_IDLE_PENDING)) { |
| 998 | if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 999 | DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1000 | pThis->omx_report_error (); |
| 1001 | } else { |
| 1002 | pThis->streaming[OUTPUT_PORT] = false; |
| 1003 | } |
| 1004 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1005 | DEBUG_PRINT_LOW("Input flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1006 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1007 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | } else { |
| 1012 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1013 | } |
| 1014 | } |
| 1015 | break; |
| 1016 | |
| 1017 | case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1018 | DEBUG_PRINT_HIGH("Driver flush o/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1019 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1020 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1021 | } else { |
| 1022 | pThis->execute_output_flush(); |
| 1023 | if (pThis->m_cb.EventHandler) { |
| 1024 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1025 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1026 | pThis->omx_report_error (); |
| 1027 | } else { |
| 1028 | /*Check if we need generate event for Flush done*/ |
| 1029 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1030 | OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1031 | DEBUG_PRINT_LOW("Notify Output Flush done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1032 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 1033 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1034 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1035 | OMX_CORE_OUTPUT_PORT_INDEX,NULL ); |
| 1036 | } |
| 1037 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1038 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1039 | DEBUG_PRINT_LOW("Internal flush complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1040 | BITMASK_CLEAR (&pThis->m_flags, |
| 1041 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 1042 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1043 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) { |
| 1044 | pThis->post_event(OMX_CommandPortDisable, |
| 1045 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 1046 | OMX_COMPONENT_GENERATE_EVENT); |
| 1047 | BITMASK_CLEAR (&pThis->m_flags, |
| 1048 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
| 1049 | |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) { |
| 1054 | if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1055 | DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1056 | pThis->omx_report_error (); |
| 1057 | break; |
| 1058 | } |
| 1059 | pThis->streaming[CAPTURE_PORT] = false; |
| 1060 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1061 | DEBUG_PRINT_LOW("Output flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1062 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1063 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | } else { |
| 1068 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1069 | } |
| 1070 | } |
| 1071 | break; |
| 1072 | |
| 1073 | case OMX_COMPONENT_GENERATE_START_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1074 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1075 | |
| 1076 | if (pThis->m_cb.EventHandler) { |
| 1077 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1078 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1079 | pThis->omx_report_error (); |
| 1080 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1081 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1082 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1083 | DEBUG_PRINT_LOW("Move to executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1084 | // Send the callback now |
| 1085 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1086 | pThis->m_state = OMX_StateExecuting; |
| 1087 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1088 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1089 | OMX_StateExecuting, NULL); |
| 1090 | } else if (BITMASK_PRESENT(&pThis->m_flags, |
| 1091 | OMX_COMPONENT_PAUSE_PENDING)) { |
| 1092 | if (/*ioctl (pThis->drv_ctx.video_driver_fd, |
| 1093 | VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1094 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1095 | pThis->omx_report_error (); |
| 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1100 | DEBUG_PRINT_LOW("Event Handler callback is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1101 | } |
| 1102 | break; |
| 1103 | |
| 1104 | case OMX_COMPONENT_GENERATE_PAUSE_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1105 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1106 | if (pThis->m_cb.EventHandler) { |
| 1107 | if (p2 != VDEC_S_SUCCESS) { |
| 1108 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed"); |
| 1109 | pThis->omx_report_error (); |
| 1110 | } else { |
| 1111 | pThis->complete_pending_buffer_done_cbs(); |
| 1112 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1113 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1114 | //Send the callback now |
| 1115 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING); |
| 1116 | pThis->m_state = OMX_StatePause; |
| 1117 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1118 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1119 | OMX_StatePause, NULL); |
| 1120 | } |
| 1121 | } |
| 1122 | } else { |
| 1123 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1124 | } |
| 1125 | |
| 1126 | break; |
| 1127 | |
| 1128 | case OMX_COMPONENT_GENERATE_RESUME_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1129 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1130 | if (pThis->m_cb.EventHandler) { |
| 1131 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1132 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1133 | pThis->omx_report_error (); |
| 1134 | } else { |
| 1135 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1136 | DEBUG_PRINT_LOW("Moving the decoder to execute state"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1137 | // Send the callback now |
| 1138 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1139 | pThis->m_state = OMX_StateExecuting; |
| 1140 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1141 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1142 | OMX_StateExecuting,NULL); |
| 1143 | } |
| 1144 | } |
| 1145 | } else { |
| 1146 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1147 | } |
| 1148 | |
| 1149 | break; |
| 1150 | |
| 1151 | case OMX_COMPONENT_GENERATE_STOP_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1152 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1153 | if (pThis->m_cb.EventHandler) { |
| 1154 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1155 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1156 | pThis->omx_report_error (); |
| 1157 | } else { |
| 1158 | pThis->complete_pending_buffer_done_cbs(); |
| 1159 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1160 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1161 | // Send the callback now |
| 1162 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 1163 | pThis->m_state = OMX_StateIdle; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1164 | DEBUG_PRINT_LOW("Move to Idle State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1165 | pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data, |
| 1166 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1167 | OMX_StateIdle,NULL); |
| 1168 | } |
| 1169 | } |
| 1170 | } else { |
| 1171 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1172 | } |
| 1173 | |
| 1174 | break; |
| 1175 | |
| 1176 | case OMX_COMPONENT_GENERATE_PORT_RECONFIG: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1177 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PORT_RECONFIG"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1178 | |
| 1179 | if (p2 == OMX_IndexParamPortDefinition) { |
| 1180 | pThis->in_reconfig = true; |
| 1181 | } |
| 1182 | if (pThis->m_cb.EventHandler) { |
| 1183 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1184 | OMX_EventPortSettingsChanged, p1, p2, NULL ); |
| 1185 | } else { |
| 1186 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1187 | } |
| 1188 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1189 | break; |
| 1190 | |
| 1191 | case OMX_COMPONENT_GENERATE_EOS_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1192 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1193 | if (pThis->m_cb.EventHandler) { |
| 1194 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag, |
| 1195 | OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL ); |
| 1196 | } else { |
| 1197 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1198 | } |
| 1199 | pThis->prev_ts = LLONG_MAX; |
| 1200 | pThis->rst_prev_ts = true; |
| 1201 | break; |
| 1202 | |
| 1203 | case OMX_COMPONENT_GENERATE_HARDWARE_ERROR: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1204 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1205 | pThis->omx_report_error (); |
| 1206 | break; |
| 1207 | |
| 1208 | case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1209 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1210 | pThis->omx_report_unsupported_setting(); |
| 1211 | break; |
| 1212 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1213 | default: |
| 1214 | break; |
| 1215 | } |
| 1216 | } |
| 1217 | pthread_mutex_lock(&pThis->m_lock); |
| 1218 | qsize = pThis->m_cmd_q.m_size; |
| 1219 | if (pThis->m_state != OMX_StatePause) |
| 1220 | qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size); |
| 1221 | pthread_mutex_unlock(&pThis->m_lock); |
| 1222 | } while (qsize>0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1223 | |
| 1224 | } |
| 1225 | |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 1226 | int omx_vdec::update_resolution(int width, int height, int stride, int scan_lines) |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1227 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1228 | int format_changed = 0; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 1229 | if ((height != (int)drv_ctx.video_resolution.frame_height) || |
| 1230 | (width != (int)drv_ctx.video_resolution.frame_width)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1231 | DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1232 | width, drv_ctx.video_resolution.frame_width, |
| 1233 | height,drv_ctx.video_resolution.frame_height); |
| 1234 | format_changed = 1; |
| 1235 | } |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1236 | drv_ctx.video_resolution.frame_height = height; |
| 1237 | drv_ctx.video_resolution.frame_width = width; |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 1238 | drv_ctx.video_resolution.scan_lines = scan_lines; |
| 1239 | drv_ctx.video_resolution.stride = stride; |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1240 | rectangle.nLeft = 0; |
| 1241 | rectangle.nTop = 0; |
| 1242 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1243 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1244 | return format_changed; |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1247 | OMX_ERRORTYPE omx_vdec::is_video_session_supported() |
| 1248 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1249 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", |
| 1250 | OMX_MAX_STRINGNAME_SIZE) && |
| 1251 | (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) { |
| 1252 | m_decoder_capability.max_width = 1280; |
| 1253 | m_decoder_capability.max_height = 720; |
| 1254 | DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP"); |
| 1255 | } |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 1256 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1257 | if ((drv_ctx.video_resolution.frame_width * |
| 1258 | drv_ctx.video_resolution.frame_height > |
| 1259 | m_decoder_capability.max_width * |
| 1260 | m_decoder_capability.max_height) || |
| 1261 | (drv_ctx.video_resolution.frame_width* |
| 1262 | drv_ctx.video_resolution.frame_height < |
| 1263 | m_decoder_capability.min_width * |
| 1264 | m_decoder_capability.min_height)) { |
| 1265 | DEBUG_PRINT_ERROR( |
| 1266 | "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)", |
| 1267 | drv_ctx.video_resolution.frame_width, |
| 1268 | drv_ctx.video_resolution.frame_height, |
| 1269 | m_decoder_capability.min_width, |
| 1270 | m_decoder_capability.min_height, |
| 1271 | m_decoder_capability.max_width, |
| 1272 | m_decoder_capability.max_height); |
| 1273 | return OMX_ErrorUnsupportedSetting; |
| 1274 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1275 | DEBUG_PRINT_HIGH("video session supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1276 | return OMX_ErrorNone; |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1277 | } |
| 1278 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1279 | int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len) |
| 1280 | { |
| 1281 | if (m_debug.in_buffer_log && !m_debug.infile) { |
| 1282 | if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) { |
| 1283 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v", |
| 1284 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1285 | } |
| 1286 | else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) { |
| 1287 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.mpg", m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); } |
| 1288 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) { |
| 1289 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263", |
| 1290 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1291 | } |
| 1292 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) { |
| 1293 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264", |
| 1294 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1295 | } |
| 1296 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) { |
| 1297 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1298 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1299 | } |
| 1300 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) { |
| 1301 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1302 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1303 | } |
| 1304 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1305 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf", |
| 1306 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1307 | } |
| 1308 | m_debug.infile = fopen (m_debug.infile_name, "ab"); |
| 1309 | if (!m_debug.infile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1310 | DEBUG_PRINT_HIGH("Failed to open input file: %s for logging", m_debug.infile_name); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1311 | m_debug.infile_name[0] = '\0'; |
| 1312 | return -1; |
| 1313 | } |
| 1314 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1315 | struct ivf_file_header { |
| 1316 | OMX_U8 signature[4]; //='DKIF'; |
| 1317 | OMX_U8 version ; //= 0; |
| 1318 | OMX_U8 headersize ; //= 32; |
| 1319 | OMX_U32 FourCC; |
| 1320 | OMX_U8 width; |
| 1321 | OMX_U8 height; |
| 1322 | OMX_U32 rate; |
| 1323 | OMX_U32 scale; |
| 1324 | OMX_U32 length; |
| 1325 | OMX_U8 unused[4]; |
| 1326 | } file_header; |
| 1327 | |
| 1328 | memset((void *)&file_header,0,sizeof(file_header)); |
| 1329 | file_header.signature[0] = 'D'; |
| 1330 | file_header.signature[1] = 'K'; |
| 1331 | file_header.signature[2] = 'I'; |
| 1332 | file_header.signature[3] = 'F'; |
| 1333 | file_header.version = 0; |
| 1334 | file_header.headersize = 32; |
| 1335 | file_header.FourCC = 0x30385056; |
| 1336 | fwrite((const char *)&file_header, |
| 1337 | sizeof(file_header),1,m_debug.infile); |
| 1338 | } |
| 1339 | } |
| 1340 | if (m_debug.infile && buffer_addr && buffer_len) { |
| 1341 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1342 | struct vp8_ivf_frame_header { |
| 1343 | OMX_U32 framesize; |
| 1344 | OMX_U32 timestamp_lo; |
| 1345 | OMX_U32 timestamp_hi; |
| 1346 | } vp8_frame_header; |
| 1347 | vp8_frame_header.framesize = buffer_len; |
| 1348 | /* Currently FW doesn't use timestamp values */ |
| 1349 | vp8_frame_header.timestamp_lo = 0; |
| 1350 | vp8_frame_header.timestamp_hi = 0; |
| 1351 | fwrite((const char *)&vp8_frame_header, |
| 1352 | sizeof(vp8_frame_header),1,m_debug.infile); |
| 1353 | } |
| 1354 | fwrite(buffer_addr, buffer_len, 1, m_debug.infile); |
| 1355 | } |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) { |
| 1360 | if (m_debug.out_buffer_log && !m_debug.outfile) { |
| 1361 | sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv", |
| 1362 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1363 | m_debug.outfile = fopen (m_debug.outfile_name, "ab"); |
| 1364 | if (!m_debug.outfile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1365 | DEBUG_PRINT_HIGH("Failed to open output file: %s for logging", m_debug.log_loc); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1366 | m_debug.outfile_name[0] = '\0'; |
| 1367 | return -1; |
| 1368 | } |
| 1369 | } |
| 1370 | if (m_debug.outfile && buffer && buffer->nFilledLen) { |
| 1371 | int buf_index = buffer - m_out_mem_ptr; |
| 1372 | int stride = drv_ctx.video_resolution.stride; |
| 1373 | int scanlines = drv_ctx.video_resolution.scan_lines; |
| 1374 | char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr; |
| 1375 | unsigned i; |
| 1376 | int bytes_written = 0; |
| 1377 | for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) { |
| 1378 | bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1379 | temp += stride; |
| 1380 | } |
| 1381 | temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines; |
| 1382 | int stride_c = stride; |
| 1383 | for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) { |
| 1384 | bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1385 | temp += stride_c; |
| 1386 | } |
| 1387 | } |
| 1388 | return 0; |
| 1389 | } |
| 1390 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1391 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1392 | FUNCTION |
| 1393 | omx_vdec::ComponentInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1394 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1395 | DESCRIPTION |
| 1396 | Initialize the component. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1397 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1398 | PARAMETERS |
| 1399 | ctxt -- Context information related to the self. |
| 1400 | id -- Event identifier. This could be any of the following: |
| 1401 | 1. Command completion event |
| 1402 | 2. Buffer done callback event |
| 1403 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1404 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1405 | RETURN VALUE |
| 1406 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1407 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1408 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1409 | OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role) |
| 1410 | { |
| 1411 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1412 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 1413 | struct v4l2_fmtdesc fdesc; |
| 1414 | struct v4l2_format fmt; |
| 1415 | struct v4l2_requestbuffers bufreq; |
| 1416 | struct v4l2_control control; |
| 1417 | struct v4l2_frmsizeenum frmsize; |
| 1418 | unsigned int alignment = 0,buffer_size = 0; |
| 1419 | int fds[2]; |
| 1420 | int r,ret=0; |
| 1421 | bool codec_ambiguous = false; |
| 1422 | OMX_STRING device_name = (OMX_STRING)"/dev/video/venus_dec"; |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1423 | |
| 1424 | #ifdef _ANDROID_ |
Praveen Chavan | e9e5620 | 2013-09-19 03:48:16 -0700 | [diff] [blame] | 1425 | char platform_name[PROPERTY_VALUE_MAX]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1426 | property_get("ro.board.platform", platform_name, "0"); |
| 1427 | if (!strncmp(platform_name, "msm8610", 7)) { |
| 1428 | device_name = (OMX_STRING)"/dev/video/q6_dec"; |
| 1429 | } |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1430 | #endif |
| 1431 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1432 | if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) { |
| 1433 | struct v4l2_control control; |
| 1434 | secure_mode = true; |
| 1435 | arbitrary_bytes = false; |
| 1436 | role = (OMX_STRING)"OMX.qcom.video.decoder.avc"; |
| 1437 | } |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1438 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1439 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1440 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1441 | DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open returned fd %d", |
Jayasena Sangaraboina | c453bd8 | 2013-08-01 14:02:52 -0700 | [diff] [blame] | 1442 | drv_ctx.video_driver_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1443 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1444 | if (drv_ctx.video_driver_fd == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1445 | DEBUG_PRINT_ERROR("omx_vdec_msm8974 :: Got fd as 0 for msm_vidc_dec, Opening again"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1446 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
| 1447 | close(0); |
| 1448 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1449 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1450 | if (drv_ctx.video_driver_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1451 | DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1452 | return OMX_ErrorInsufficientResources; |
| 1453 | } |
| 1454 | drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS; |
| 1455 | drv_ctx.frame_rate.fps_denominator = 1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1456 | |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1457 | ret = subscribe_to_events(drv_ctx.video_driver_fd); |
Vinay Kalia | 184cd0f | 2013-04-29 18:26:42 -0700 | [diff] [blame] | 1458 | if (!ret) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1459 | async_thread_created = true; |
| 1460 | ret = pthread_create(&async_thread_id,0,async_message_thread,this); |
| 1461 | } |
| 1462 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1463 | DEBUG_PRINT_ERROR("Failed to create async_message_thread"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1464 | async_thread_created = false; |
| 1465 | return OMX_ErrorInsufficientResources; |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1466 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1467 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1468 | #ifdef OUTPUT_EXTRADATA_LOG |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1469 | outputExtradataFile = fopen (ouputextradatafilename, "ab"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1470 | #endif |
| 1471 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1472 | // Copy the role information which provides the decoder kind |
| 1473 | strlcpy(drv_ctx.kind,role,128); |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1474 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1475 | if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\ |
| 1476 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1477 | strlcpy((char *)m_cRole, "video_decoder.mpeg4",\ |
| 1478 | OMX_MAX_STRINGNAME_SIZE); |
| 1479 | drv_ctx.timestamp_adjust = true; |
| 1480 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4; |
| 1481 | eCompressionFormat = OMX_VIDEO_CodingMPEG4; |
| 1482 | output_capability=V4L2_PIX_FMT_MPEG4; |
| 1483 | /*Initialize Start Code for MPEG4*/ |
| 1484 | codec_type_parse = CODEC_TYPE_MPEG4; |
| 1485 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1486 | } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\ |
| 1487 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1488 | strlcpy((char *)m_cRole, "video_decoder.mpeg2",\ |
| 1489 | OMX_MAX_STRINGNAME_SIZE); |
| 1490 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2; |
| 1491 | output_capability = V4L2_PIX_FMT_MPEG2; |
| 1492 | eCompressionFormat = OMX_VIDEO_CodingMPEG2; |
| 1493 | /*Initialize Start Code for MPEG2*/ |
| 1494 | codec_type_parse = CODEC_TYPE_MPEG2; |
| 1495 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1496 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\ |
| 1497 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1498 | strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1499 | DEBUG_PRINT_LOW("H263 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1500 | drv_ctx.decoder_format = VDEC_CODECTYPE_H263; |
| 1501 | eCompressionFormat = OMX_VIDEO_CodingH263; |
| 1502 | output_capability = V4L2_PIX_FMT_H263; |
| 1503 | codec_type_parse = CODEC_TYPE_H263; |
| 1504 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1505 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\ |
| 1506 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1507 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1508 | DEBUG_PRINT_LOW ("DIVX 311 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1509 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3; |
| 1510 | output_capability = V4L2_PIX_FMT_DIVX_311; |
| 1511 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1512 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1513 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1514 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1515 | eRet = createDivxDrmContext(); |
| 1516 | if (eRet != OMX_ErrorNone) { |
| 1517 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1518 | return eRet; |
| 1519 | } |
| 1520 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\ |
| 1521 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1522 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1523 | DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1524 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4; |
| 1525 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1526 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1527 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1528 | codec_ambiguous = true; |
| 1529 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1530 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1531 | eRet = createDivxDrmContext(); |
| 1532 | if (eRet != OMX_ErrorNone) { |
| 1533 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1534 | return eRet; |
| 1535 | } |
| 1536 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\ |
| 1537 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1538 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1539 | DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1540 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6; |
| 1541 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1542 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1543 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1544 | codec_ambiguous = true; |
| 1545 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1546 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1547 | eRet = createDivxDrmContext(); |
| 1548 | if (eRet != OMX_ErrorNone) { |
| 1549 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1550 | return eRet; |
| 1551 | } |
Deva Ramasubramanian | 9403f02 | 2012-11-28 18:27:53 -0800 | [diff] [blame] | 1552 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1553 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\ |
| 1554 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1555 | strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 1556 | drv_ctx.decoder_format = VDEC_CODECTYPE_H264; |
| 1557 | output_capability=V4L2_PIX_FMT_H264; |
| 1558 | eCompressionFormat = OMX_VIDEO_CodingAVC; |
| 1559 | codec_type_parse = CODEC_TYPE_H264; |
| 1560 | m_frame_parser.init_start_codes (codec_type_parse); |
| 1561 | m_frame_parser.init_nal_length(nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1562 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\ |
| 1563 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1564 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1565 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1; |
| 1566 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1567 | codec_type_parse = CODEC_TYPE_VC1; |
| 1568 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_G; |
| 1569 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1570 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\ |
| 1571 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1572 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1573 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV; |
| 1574 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1575 | codec_type_parse = CODEC_TYPE_VC1; |
| 1576 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_L; |
| 1577 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1578 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \ |
| 1579 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1580 | strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 1581 | output_capability=V4L2_PIX_FMT_VP8; |
| 1582 | eCompressionFormat = OMX_VIDEO_CodingVPX; |
| 1583 | codec_type_parse = CODEC_TYPE_VP8; |
| 1584 | arbitrary_bytes = false; |
Praneeth Paladugu | 2b2ef2d | 2013-04-10 22:04:51 -0700 | [diff] [blame] | 1585 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1586 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1587 | DEBUG_PRINT_ERROR("ERROR:Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1588 | eRet = OMX_ErrorInvalidComponentName; |
| 1589 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1590 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1591 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1592 | drv_ctx.output_format = VDEC_YUV_FORMAT_NV12; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1593 | OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 1594 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 1595 | if (!client_buffers.set_color_format(dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1596 | DEBUG_PRINT_ERROR("Setting color format failed"); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1597 | eRet = OMX_ErrorInsufficientResources; |
| 1598 | } |
| 1599 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1600 | capture_capability= V4L2_PIX_FMT_NV12; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1601 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1602 | struct v4l2_capability cap; |
| 1603 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap); |
| 1604 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1605 | DEBUG_PRINT_ERROR("Failed to query capabilities"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1606 | /*TODO: How to handle this case */ |
| 1607 | } else { |
| 1608 | DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s," |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1609 | " version = %d, capabilities = %x", cap.driver, cap.card, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1610 | cap.bus_info, cap.version, cap.capabilities); |
| 1611 | } |
| 1612 | ret=0; |
| 1613 | fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1614 | fdesc.index=0; |
| 1615 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1616 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1617 | fdesc.pixelformat, fdesc.flags); |
| 1618 | fdesc.index++; |
| 1619 | } |
| 1620 | fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1621 | fdesc.index=0; |
| 1622 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1623 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1624 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1625 | fdesc.pixelformat, fdesc.flags); |
| 1626 | fdesc.index++; |
| 1627 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1628 | update_resolution(320, 240, 320, 240); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1629 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1630 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1631 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1632 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 1633 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1634 | if (ret) { |
| 1635 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1636 | DEBUG_PRINT_ERROR("Failed to set format on output port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1637 | return OMX_ErrorInsufficientResources; |
| 1638 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1639 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1640 | if (codec_ambiguous) { |
| 1641 | if (output_capability == V4L2_PIX_FMT_DIVX) { |
| 1642 | struct v4l2_control divx_ctrl; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1643 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1644 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) { |
| 1645 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4; |
| 1646 | } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) { |
| 1647 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5; |
| 1648 | } else { |
| 1649 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6; |
| 1650 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1651 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1652 | divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT; |
| 1653 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl); |
| 1654 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1655 | DEBUG_PRINT_ERROR("Failed to set divx version"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1656 | } |
| 1657 | } else { |
| 1658 | DEBUG_PRINT_ERROR("Codec should not be ambiguous"); |
| 1659 | } |
| 1660 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1661 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1662 | //Get the hardware capabilities |
| 1663 | memset((void *)&frmsize,0,sizeof(frmsize)); |
| 1664 | frmsize.index = 0; |
| 1665 | frmsize.pixel_format = output_capability; |
| 1666 | ret = ioctl(drv_ctx.video_driver_fd, |
| 1667 | VIDIOC_ENUM_FRAMESIZES, &frmsize); |
| 1668 | if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1669 | DEBUG_PRINT_ERROR("Failed to get framesizes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1670 | return OMX_ErrorHardware; |
| 1671 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1672 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1673 | if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) { |
| 1674 | m_decoder_capability.min_width = frmsize.stepwise.min_width; |
| 1675 | m_decoder_capability.max_width = frmsize.stepwise.max_width; |
| 1676 | m_decoder_capability.min_height = frmsize.stepwise.min_height; |
| 1677 | m_decoder_capability.max_height = frmsize.stepwise.max_height; |
| 1678 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1679 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1680 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1681 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1682 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1683 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 1684 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1685 | if (ret) { |
| 1686 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1687 | DEBUG_PRINT_ERROR("Failed to set format on capture port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1688 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1689 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1690 | if (secure_mode) { |
| 1691 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE; |
| 1692 | control.value = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1693 | DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1694 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 1695 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1696 | DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1697 | return OMX_ErrorInsufficientResources; |
| 1698 | } |
| 1699 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1700 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1701 | /*Get the Buffer requirements for input and output ports*/ |
| 1702 | drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 1703 | drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 1704 | if (secure_mode) { |
| 1705 | drv_ctx.op_buf.alignment=SZ_1M; |
| 1706 | drv_ctx.ip_buf.alignment=SZ_1M; |
| 1707 | } else { |
| 1708 | drv_ctx.op_buf.alignment=SZ_4K; |
| 1709 | drv_ctx.ip_buf.alignment=SZ_4K; |
| 1710 | } |
| 1711 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 1712 | drv_ctx.extradata = 0; |
| 1713 | drv_ctx.picture_order = VDEC_ORDER_DISPLAY; |
| 1714 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 1715 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 1716 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 1717 | drv_ctx.idr_only_decoding = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1718 | |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1719 | m_state = OMX_StateLoaded; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1720 | #ifdef DEFAULT_EXTRADATA |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1721 | if (eRet == OMX_ErrorNone && !secure_mode) |
| 1722 | enable_extradata(DEFAULT_EXTRADATA, true, true); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1723 | #endif |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1724 | eRet=get_buffer_req(&drv_ctx.ip_buf); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1725 | DEBUG_PRINT_HIGH("Input Buffer Size =%d",drv_ctx.ip_buf.buffer_size); |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1726 | get_buffer_req(&drv_ctx.op_buf); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1727 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
| 1728 | if (m_frame_parser.mutils == NULL) { |
| 1729 | m_frame_parser.mutils = new H264_Utils(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1730 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1731 | if (m_frame_parser.mutils == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1732 | DEBUG_PRINT_ERROR("parser utils Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1733 | eRet = OMX_ErrorInsufficientResources; |
| 1734 | } else { |
| 1735 | h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 1736 | h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size); |
| 1737 | h264_scratch.nFilledLen = 0; |
| 1738 | h264_scratch.nOffset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1739 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1740 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1741 | DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1742 | return OMX_ErrorInsufficientResources; |
| 1743 | } |
| 1744 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 1745 | m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size); |
| 1746 | } |
| 1747 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1748 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1749 | h264_parser = new h264_stream_parser(); |
| 1750 | if (!h264_parser) { |
| 1751 | DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!"); |
| 1752 | eRet = OMX_ErrorInsufficientResources; |
| 1753 | } |
| 1754 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1755 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1756 | if (pipe(fds)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1757 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1758 | eRet = OMX_ErrorInsufficientResources; |
| 1759 | } else { |
| 1760 | int temp1[2]; |
| 1761 | if (fds[0] == 0 || fds[1] == 0) { |
| 1762 | if (pipe (temp1)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1763 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1764 | return OMX_ErrorInsufficientResources; |
| 1765 | } |
| 1766 | //close (fds[0]); |
| 1767 | //close (fds[1]); |
| 1768 | fds[0] = temp1 [0]; |
| 1769 | fds[1] = temp1 [1]; |
| 1770 | } |
| 1771 | m_pipe_in = fds[0]; |
| 1772 | m_pipe_out = fds[1]; |
| 1773 | msg_thread_created = true; |
| 1774 | r = pthread_create(&msg_thread_id,0,message_thread,this); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1775 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1776 | if (r < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1777 | DEBUG_PRINT_ERROR("component_init(): message_thread creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1778 | msg_thread_created = false; |
| 1779 | eRet = OMX_ErrorInsufficientResources; |
| 1780 | } |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | if (eRet != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1785 | DEBUG_PRINT_ERROR("Component Init Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1786 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1787 | DEBUG_PRINT_HIGH("omx_vdec::component_init() success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1788 | } |
| 1789 | //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer)); |
| 1790 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1794 | FUNCTION |
| 1795 | omx_vdec::GetComponentVersion |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1796 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1797 | DESCRIPTION |
| 1798 | Returns the component version. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1799 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1800 | PARAMETERS |
| 1801 | TBD. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1802 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1803 | RETURN VALUE |
| 1804 | OMX_ErrorNone. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1805 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1806 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1807 | OMX_ERRORTYPE omx_vdec::get_component_version |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1808 | ( |
| 1809 | OMX_IN OMX_HANDLETYPE hComp, |
| 1810 | OMX_OUT OMX_STRING componentName, |
| 1811 | OMX_OUT OMX_VERSIONTYPE* componentVersion, |
| 1812 | OMX_OUT OMX_VERSIONTYPE* specVersion, |
| 1813 | OMX_OUT OMX_UUIDTYPE* componentUUID |
| 1814 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1815 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1816 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1817 | DEBUG_PRINT_ERROR("Get Comp Version in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1818 | return OMX_ErrorInvalidState; |
| 1819 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1820 | /* TBD -- Return the proper version */ |
| 1821 | if (specVersion) { |
| 1822 | specVersion->nVersion = OMX_SPEC_VERSION; |
| 1823 | } |
| 1824 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1825 | } |
| 1826 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1827 | FUNCTION |
| 1828 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1829 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1830 | DESCRIPTION |
| 1831 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1832 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1833 | PARAMETERS |
| 1834 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1835 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1836 | RETURN VALUE |
| 1837 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1838 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1839 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1840 | OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1841 | OMX_IN OMX_COMMANDTYPE cmd, |
| 1842 | OMX_IN OMX_U32 param1, |
| 1843 | OMX_IN OMX_PTR cmdData |
| 1844 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1845 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1846 | DEBUG_PRINT_LOW("send_command: Recieved a Command from Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1847 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1848 | DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1849 | return OMX_ErrorInvalidState; |
| 1850 | } |
| 1851 | if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1852 | && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1853 | DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1854 | "to invalid port: %lu", param1); |
| 1855 | return OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1856 | } |
| 1857 | post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND); |
| 1858 | sem_wait(&m_cmd_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1859 | DEBUG_PRINT_LOW("send_command: Command Processed"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1860 | return OMX_ErrorNone; |
| 1861 | } |
| 1862 | |
| 1863 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1864 | FUNCTION |
| 1865 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1866 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1867 | DESCRIPTION |
| 1868 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1869 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1870 | PARAMETERS |
| 1871 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1872 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1873 | RETURN VALUE |
| 1874 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1875 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1876 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1877 | OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1878 | OMX_IN OMX_COMMANDTYPE cmd, |
| 1879 | OMX_IN OMX_U32 param1, |
| 1880 | OMX_IN OMX_PTR cmdData |
| 1881 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1882 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1883 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 1884 | OMX_STATETYPE eState = (OMX_STATETYPE) param1; |
| 1885 | int bFlag = 1,sem_posted = 0,ret=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1886 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1887 | DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd); |
| 1888 | DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1889 | m_state, eState); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1890 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1891 | if (cmd == OMX_CommandStateSet) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1892 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued"); |
| 1893 | DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1894 | /***************************/ |
| 1895 | /* Current State is Loaded */ |
| 1896 | /***************************/ |
| 1897 | if (m_state == OMX_StateLoaded) { |
| 1898 | if (eState == OMX_StateIdle) { |
| 1899 | //if all buffers are allocated or all ports disabled |
| 1900 | if (allocate_done() || |
| 1901 | (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1902 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1903 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1904 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1905 | BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING); |
| 1906 | // Skip the event notification |
| 1907 | bFlag = 0; |
| 1908 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1909 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1910 | /* Requesting transition from Loaded to Loaded */ |
| 1911 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1912 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1913 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 1914 | OMX_COMPONENT_GENERATE_EVENT); |
| 1915 | eRet = OMX_ErrorSameState; |
| 1916 | } |
| 1917 | /* Requesting transition from Loaded to WaitForResources */ |
| 1918 | else if (eState == OMX_StateWaitForResources) { |
| 1919 | /* Since error is None , we will post an event |
| 1920 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1921 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1922 | } |
| 1923 | /* Requesting transition from Loaded to Executing */ |
| 1924 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1925 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1926 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 1927 | OMX_COMPONENT_GENERATE_EVENT); |
| 1928 | eRet = OMX_ErrorIncorrectStateTransition; |
| 1929 | } |
| 1930 | /* Requesting transition from Loaded to Pause */ |
| 1931 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1932 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1933 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 1934 | OMX_COMPONENT_GENERATE_EVENT); |
| 1935 | eRet = OMX_ErrorIncorrectStateTransition; |
| 1936 | } |
| 1937 | /* Requesting transition from Loaded to Invalid */ |
| 1938 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1939 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1940 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 1941 | eRet = OMX_ErrorInvalidState; |
| 1942 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1943 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1944 | eState); |
| 1945 | eRet = OMX_ErrorBadParameter; |
| 1946 | } |
| 1947 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1948 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1949 | /***************************/ |
| 1950 | /* Current State is IDLE */ |
| 1951 | /***************************/ |
| 1952 | else if (m_state == OMX_StateIdle) { |
| 1953 | if (eState == OMX_StateLoaded) { |
| 1954 | if (release_done()) { |
| 1955 | /* |
| 1956 | Since error is None , we will post an event at the end |
| 1957 | of this function definition |
| 1958 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1959 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1960 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1961 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1962 | BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING); |
| 1963 | // Skip the event notification |
| 1964 | bFlag = 0; |
| 1965 | } |
| 1966 | } |
| 1967 | /* Requesting transition from Idle to Executing */ |
| 1968 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1969 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1970 | //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING); |
| 1971 | bFlag = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1972 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1973 | m_state=OMX_StateExecuting; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1974 | DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1975 | } |
| 1976 | /* Requesting transition from Idle to Idle */ |
| 1977 | else if (eState == OMX_StateIdle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1978 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1979 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 1980 | OMX_COMPONENT_GENERATE_EVENT); |
| 1981 | eRet = OMX_ErrorSameState; |
| 1982 | } |
| 1983 | /* Requesting transition from Idle to WaitForResources */ |
| 1984 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1985 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1986 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 1987 | OMX_COMPONENT_GENERATE_EVENT); |
| 1988 | eRet = OMX_ErrorIncorrectStateTransition; |
| 1989 | } |
| 1990 | /* Requesting transition from Idle to Pause */ |
| 1991 | else if (eState == OMX_StatePause) { |
| 1992 | /*To pause the Video core we need to start the driver*/ |
| 1993 | if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START, |
| 1994 | NULL) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1995 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1996 | omx_report_error (); |
| 1997 | eRet = OMX_ErrorHardware; |
| 1998 | } else { |
| 1999 | BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2000 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2001 | bFlag = 0; |
| 2002 | } |
| 2003 | } |
| 2004 | /* Requesting transition from Idle to Invalid */ |
| 2005 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2006 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2007 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2008 | eRet = OMX_ErrorInvalidState; |
| 2009 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2010 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2011 | eRet = OMX_ErrorBadParameter; |
| 2012 | } |
| 2013 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2014 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2015 | /******************************/ |
| 2016 | /* Current State is Executing */ |
| 2017 | /******************************/ |
| 2018 | else if (m_state == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2019 | DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2020 | /* Requesting transition from Executing to Idle */ |
| 2021 | if (eState == OMX_StateIdle) { |
| 2022 | /* Since error is None , we will post an event |
| 2023 | at the end of this function definition |
| 2024 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2025 | DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2026 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2027 | if (!sem_posted) { |
| 2028 | sem_posted = 1; |
| 2029 | sem_post (&m_cmd_lock); |
| 2030 | execute_omx_flush(OMX_ALL); |
| 2031 | } |
| 2032 | bFlag = 0; |
| 2033 | } |
| 2034 | /* Requesting transition from Executing to Paused */ |
| 2035 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2036 | DEBUG_PRINT_LOW("PAUSE Command Issued"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2037 | m_state = OMX_StatePause; |
| 2038 | bFlag = 1; |
| 2039 | } |
| 2040 | /* Requesting transition from Executing to Loaded */ |
| 2041 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2042 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2043 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2044 | OMX_COMPONENT_GENERATE_EVENT); |
| 2045 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2046 | } |
| 2047 | /* Requesting transition from Executing to WaitForResources */ |
| 2048 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2049 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2050 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2051 | OMX_COMPONENT_GENERATE_EVENT); |
| 2052 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2053 | } |
| 2054 | /* Requesting transition from Executing to Executing */ |
| 2055 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2056 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2057 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2058 | OMX_COMPONENT_GENERATE_EVENT); |
| 2059 | eRet = OMX_ErrorSameState; |
| 2060 | } |
| 2061 | /* Requesting transition from Executing to Invalid */ |
| 2062 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2063 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2064 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2065 | eRet = OMX_ErrorInvalidState; |
| 2066 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2067 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2068 | eRet = OMX_ErrorBadParameter; |
| 2069 | } |
| 2070 | } |
| 2071 | /***************************/ |
| 2072 | /* Current State is Pause */ |
| 2073 | /***************************/ |
| 2074 | else if (m_state == OMX_StatePause) { |
| 2075 | /* Requesting transition from Pause to Executing */ |
| 2076 | if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2077 | DEBUG_PRINT_LOW("Pause --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2078 | m_state = OMX_StateExecuting; |
| 2079 | bFlag = 1; |
| 2080 | } |
| 2081 | /* Requesting transition from Pause to Idle */ |
| 2082 | else if (eState == OMX_StateIdle) { |
| 2083 | /* Since error is None , we will post an event |
| 2084 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2085 | DEBUG_PRINT_LOW("Pause --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2086 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2087 | if (!sem_posted) { |
| 2088 | sem_posted = 1; |
| 2089 | sem_post (&m_cmd_lock); |
| 2090 | execute_omx_flush(OMX_ALL); |
| 2091 | } |
| 2092 | bFlag = 0; |
| 2093 | } |
| 2094 | /* Requesting transition from Pause to loaded */ |
| 2095 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2096 | DEBUG_PRINT_ERROR("Pause --> loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2097 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2098 | OMX_COMPONENT_GENERATE_EVENT); |
| 2099 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2100 | } |
| 2101 | /* Requesting transition from Pause to WaitForResources */ |
| 2102 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2103 | DEBUG_PRINT_ERROR("Pause --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2104 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2105 | OMX_COMPONENT_GENERATE_EVENT); |
| 2106 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2107 | } |
| 2108 | /* Requesting transition from Pause to Pause */ |
| 2109 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2110 | DEBUG_PRINT_ERROR("Pause --> Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2111 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2112 | OMX_COMPONENT_GENERATE_EVENT); |
| 2113 | eRet = OMX_ErrorSameState; |
| 2114 | } |
| 2115 | /* Requesting transition from Pause to Invalid */ |
| 2116 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2117 | DEBUG_PRINT_ERROR("Pause --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2118 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2119 | eRet = OMX_ErrorInvalidState; |
| 2120 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2121 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2122 | eRet = OMX_ErrorBadParameter; |
| 2123 | } |
| 2124 | } |
| 2125 | /***************************/ |
| 2126 | /* Current State is WaitForResources */ |
| 2127 | /***************************/ |
| 2128 | else if (m_state == OMX_StateWaitForResources) { |
| 2129 | /* Requesting transition from WaitForResources to Loaded */ |
| 2130 | if (eState == OMX_StateLoaded) { |
| 2131 | /* Since error is None , we will post an event |
| 2132 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2133 | DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2134 | } |
| 2135 | /* Requesting transition from WaitForResources to WaitForResources */ |
| 2136 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2137 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2138 | post_event(OMX_EventError,OMX_ErrorSameState, |
| 2139 | OMX_COMPONENT_GENERATE_EVENT); |
| 2140 | eRet = OMX_ErrorSameState; |
| 2141 | } |
| 2142 | /* Requesting transition from WaitForResources to Executing */ |
| 2143 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2144 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2145 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2146 | OMX_COMPONENT_GENERATE_EVENT); |
| 2147 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2148 | } |
| 2149 | /* Requesting transition from WaitForResources to Pause */ |
| 2150 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2151 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2152 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2153 | OMX_COMPONENT_GENERATE_EVENT); |
| 2154 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2155 | } |
| 2156 | /* Requesting transition from WaitForResources to Invalid */ |
| 2157 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2158 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2159 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2160 | eRet = OMX_ErrorInvalidState; |
| 2161 | } |
| 2162 | /* Requesting transition from WaitForResources to Loaded - |
| 2163 | is NOT tested by Khronos TS */ |
| 2164 | |
| 2165 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2166 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): %d --> %d(Not Handled)",m_state,eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2167 | eRet = OMX_ErrorBadParameter; |
| 2168 | } |
| 2169 | } |
| 2170 | /********************************/ |
| 2171 | /* Current State is Invalid */ |
| 2172 | /*******************************/ |
| 2173 | else if (m_state == OMX_StateInvalid) { |
| 2174 | /* State Transition from Inavlid to any state */ |
| 2175 | if (eState == (OMX_StateLoaded || OMX_StateWaitForResources |
| 2176 | || OMX_StateIdle || OMX_StateExecuting |
| 2177 | || OMX_StatePause || OMX_StateInvalid)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2178 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2179 | post_event(OMX_EventError,OMX_ErrorInvalidState,\ |
| 2180 | OMX_COMPONENT_GENERATE_EVENT); |
| 2181 | eRet = OMX_ErrorInvalidState; |
| 2182 | } |
| 2183 | } else if (cmd == OMX_CommandFlush) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2184 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2185 | "with param1: %lu", param1); |
| 2186 | if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2187 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING); |
| 2188 | } |
| 2189 | if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2190 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 2191 | } |
| 2192 | if (!sem_posted) { |
| 2193 | sem_posted = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2194 | DEBUG_PRINT_LOW("Set the Semaphore"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2195 | sem_post (&m_cmd_lock); |
| 2196 | execute_omx_flush(param1); |
| 2197 | } |
| 2198 | bFlag = 0; |
| 2199 | } else if ( cmd == OMX_CommandPortEnable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2200 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2201 | "with param1: %lu", param1); |
| 2202 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2203 | m_inp_bEnabled = OMX_TRUE; |
| 2204 | |
| 2205 | if ( (m_state == OMX_StateLoaded && |
| 2206 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2207 | || allocate_input_done()) { |
| 2208 | post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX, |
| 2209 | OMX_COMPONENT_GENERATE_EVENT); |
| 2210 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2211 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2212 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 2213 | // Skip the event notification |
| 2214 | bFlag = 0; |
| 2215 | } |
| 2216 | } |
| 2217 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2218 | DEBUG_PRINT_LOW("Enable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2219 | m_out_bEnabled = OMX_TRUE; |
| 2220 | |
| 2221 | if ( (m_state == OMX_StateLoaded && |
| 2222 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2223 | || (allocate_output_done())) { |
| 2224 | post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX, |
| 2225 | OMX_COMPONENT_GENERATE_EVENT); |
| 2226 | |
| 2227 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2228 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2229 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 2230 | // Skip the event notification |
| 2231 | bFlag = 0; |
| 2232 | } |
| 2233 | } |
| 2234 | } else if (cmd == OMX_CommandPortDisable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2235 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2236 | "with param1: %lu", param1); |
| 2237 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2238 | m_inp_bEnabled = OMX_FALSE; |
| 2239 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2240 | && release_input_done()) { |
| 2241 | post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX, |
| 2242 | OMX_COMPONENT_GENERATE_EVENT); |
| 2243 | } else { |
| 2244 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 2245 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2246 | if (!sem_posted) { |
| 2247 | sem_posted = 1; |
| 2248 | sem_post (&m_cmd_lock); |
| 2249 | } |
| 2250 | execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX); |
| 2251 | } |
| 2252 | |
| 2253 | // Skip the event notification |
| 2254 | bFlag = 0; |
| 2255 | } |
| 2256 | } |
| 2257 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2258 | m_out_bEnabled = OMX_FALSE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2259 | DEBUG_PRINT_LOW("Disable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2260 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2261 | && release_output_done()) { |
| 2262 | post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\ |
| 2263 | OMX_COMPONENT_GENERATE_EVENT); |
| 2264 | } else { |
| 2265 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
| 2266 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2267 | if (!sem_posted) { |
| 2268 | sem_posted = 1; |
| 2269 | sem_post (&m_cmd_lock); |
| 2270 | } |
| 2271 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 2272 | execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX); |
| 2273 | } |
| 2274 | // Skip the event notification |
| 2275 | bFlag = 0; |
| 2276 | |
| 2277 | } |
| 2278 | } |
| 2279 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2280 | DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2281 | eRet = OMX_ErrorNotImplemented; |
| 2282 | } |
| 2283 | if (eRet == OMX_ErrorNone && bFlag) { |
| 2284 | post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2285 | } |
| 2286 | if (!sem_posted) { |
| 2287 | sem_post(&m_cmd_lock); |
| 2288 | } |
| 2289 | |
| 2290 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2294 | FUNCTION |
| 2295 | omx_vdec::ExecuteOmxFlush |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2296 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2297 | DESCRIPTION |
| 2298 | Executes the OMX flush. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2299 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2300 | PARAMETERS |
| 2301 | flushtype - input flush(1)/output flush(0)/ both. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2302 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2303 | RETURN VALUE |
| 2304 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2305 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2306 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2307 | bool omx_vdec::execute_omx_flush(OMX_U32 flushType) |
| 2308 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2309 | bool bRet = false; |
| 2310 | struct v4l2_plane plane; |
| 2311 | struct v4l2_buffer v4l2_buf; |
| 2312 | struct v4l2_decoder_cmd dec; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 2313 | DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2314 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 2315 | dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH; |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2316 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2317 | DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig); |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2318 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2319 | if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 2320 | output_flush_progress = true; |
| 2321 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2322 | } else { |
| 2323 | /* XXX: The driver/hardware does not support flushing of individual ports |
| 2324 | * in all states. So we pretty much need to flush both ports internally, |
| 2325 | * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it |
| 2326 | * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set, |
| 2327 | * we automatically omit sending the FLUSH done for the "opposite" port. */ |
| 2328 | input_flush_progress = true; |
| 2329 | output_flush_progress = true; |
| 2330 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2331 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2332 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2333 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2334 | DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2335 | bRet = false; |
| 2336 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2337 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2338 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2339 | } |
| 2340 | /*========================================================================= |
| 2341 | FUNCTION : execute_output_flush |
| 2342 | |
| 2343 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2344 | Executes the OMX flush at OUTPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2345 | |
| 2346 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2347 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2348 | |
| 2349 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2350 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2351 | ==========================================================================*/ |
| 2352 | bool omx_vdec::execute_output_flush() |
| 2353 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2354 | unsigned p1 = 0; // Parameter - 1 |
| 2355 | unsigned p2 = 0; // Parameter - 2 |
| 2356 | unsigned ident = 0; |
| 2357 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2358 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2359 | /*Generate FBD for all Buffers in the FTBq*/ |
| 2360 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2361 | DEBUG_PRINT_LOW("Initiate Output Flush"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2362 | while (m_ftb_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2363 | DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2364 | m_ftb_q.m_size,pending_output_buffers); |
| 2365 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2366 | DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2367 | if (ident == m_fill_output_msg ) { |
| 2368 | m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2369 | } else if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 2370 | fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2371 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2372 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2373 | pthread_mutex_unlock(&m_lock); |
| 2374 | output_flush_progress = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2375 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2376 | if (arbitrary_bytes) { |
| 2377 | prev_ts = LLONG_MAX; |
| 2378 | rst_prev_ts = true; |
| 2379 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2380 | DEBUG_PRINT_HIGH("OMX flush o/p Port complete PenBuf(%d)", pending_output_buffers); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2381 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2382 | } |
| 2383 | /*========================================================================= |
| 2384 | FUNCTION : execute_input_flush |
| 2385 | |
| 2386 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2387 | Executes the OMX flush at INPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2388 | |
| 2389 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2390 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2391 | |
| 2392 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2393 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2394 | ==========================================================================*/ |
| 2395 | bool omx_vdec::execute_input_flush() |
| 2396 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2397 | unsigned i =0; |
| 2398 | unsigned p1 = 0; // Parameter - 1 |
| 2399 | unsigned p2 = 0; // Parameter - 2 |
| 2400 | unsigned ident = 0; |
| 2401 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2402 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2403 | /*Generate EBD for all Buffers in the ETBq*/ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2404 | DEBUG_PRINT_LOW("Initiate Input Flush"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2405 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2406 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2407 | DEBUG_PRINT_LOW("Check if the Queue is empty"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2408 | while (m_etb_q.m_size) { |
| 2409 | m_etb_q.pop_entry(&p1,&p2,&ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2410 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2411 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2412 | DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2413 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2414 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 2415 | pending_input_buffers++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2416 | DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2417 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 2418 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 2419 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2420 | DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2421 | (OMX_BUFFERHEADERTYPE *)p1); |
| 2422 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2423 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2424 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2425 | time_stamp_dts.flush_timestamp(); |
| 2426 | /*Check if Heap Buffers are to be flushed*/ |
| 2427 | if (arbitrary_bytes && !(codec_config_flag)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2428 | DEBUG_PRINT_LOW("Reset all the variables before flusing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2429 | h264_scratch.nFilledLen = 0; |
| 2430 | nal_count = 0; |
| 2431 | look_ahead_nal = false; |
| 2432 | frame_count = 0; |
| 2433 | h264_last_au_ts = LLONG_MAX; |
| 2434 | h264_last_au_flags = 0; |
| 2435 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 2436 | m_demux_entries = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2437 | DEBUG_PRINT_LOW("Initialize parser"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2438 | if (m_frame_parser.mutils) { |
| 2439 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 2440 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2441 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2442 | while (m_input_pending_q.m_size) { |
| 2443 | m_input_pending_q.pop_entry(&p1,&p2,&ident); |
| 2444 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1); |
| 2445 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2446 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2447 | if (psource_frame) { |
| 2448 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame); |
| 2449 | psource_frame = NULL; |
| 2450 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2451 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2452 | if (pdest_frame) { |
| 2453 | pdest_frame->nFilledLen = 0; |
| 2454 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL, |
| 2455 | (unsigned int)NULL); |
| 2456 | pdest_frame = NULL; |
| 2457 | } |
| 2458 | m_frame_parser.flush(); |
| 2459 | } else if (codec_config_flag) { |
| 2460 | DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer " |
| 2461 | "is not sent to the driver yet"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2462 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2463 | pthread_mutex_unlock(&m_lock); |
| 2464 | input_flush_progress = false; |
| 2465 | if (!arbitrary_bytes) { |
| 2466 | prev_ts = LLONG_MAX; |
| 2467 | rst_prev_ts = true; |
| 2468 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2469 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2470 | if (m_debug_timestamp) { |
| 2471 | m_timestamp_list.reset_ts_list(); |
| 2472 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2473 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2474 | DEBUG_PRINT_HIGH("OMX flush i/p Port complete PenBuf(%d)", pending_input_buffers); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2475 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | |
| 2479 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2480 | FUNCTION |
| 2481 | omx_vdec::SendCommandEvent |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2482 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2483 | DESCRIPTION |
| 2484 | Send the event to decoder pipe. This is needed to generate the callbacks |
| 2485 | in decoder thread context. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2486 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2487 | PARAMETERS |
| 2488 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2489 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2490 | RETURN VALUE |
| 2491 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2492 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2493 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2494 | bool omx_vdec::post_event(unsigned int p1, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2495 | unsigned int p2, |
| 2496 | unsigned int id) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2497 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2498 | bool bRet = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2499 | |
| 2500 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2501 | pthread_mutex_lock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2502 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2503 | if (id == m_fill_output_msg || |
| 2504 | id == OMX_COMPONENT_GENERATE_FBD) { |
| 2505 | m_ftb_q.insert_entry(p1,p2,id); |
| 2506 | } else if (id == OMX_COMPONENT_GENERATE_ETB || |
| 2507 | id == OMX_COMPONENT_GENERATE_EBD || |
| 2508 | id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 2509 | m_etb_q.insert_entry(p1,p2,id); |
| 2510 | } else { |
| 2511 | m_cmd_q.insert_entry(p1,p2,id); |
| 2512 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2513 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2514 | bRet = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2515 | DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2516 | post_message(this, id); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2517 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2518 | pthread_mutex_unlock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2519 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2520 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType) |
| 2524 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2525 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2526 | if (!profileLevelType) |
| 2527 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2528 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2529 | if (profileLevelType->nPortIndex == 0) { |
| 2530 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 2531 | if (profileLevelType->nProfileIndex == 0) { |
| 2532 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline; |
| 2533 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2534 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2535 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2536 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain; |
| 2537 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2538 | } else if (profileLevelType->nProfileIndex == 2) { |
| 2539 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh; |
| 2540 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2541 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2542 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2543 | profileLevelType->nProfileIndex); |
| 2544 | eRet = OMX_ErrorNoMore; |
| 2545 | } |
| 2546 | } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) { |
| 2547 | if (profileLevelType->nProfileIndex == 0) { |
| 2548 | profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline; |
| 2549 | profileLevelType->eLevel = OMX_VIDEO_H263Level70; |
| 2550 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2551 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2552 | eRet = OMX_ErrorNoMore; |
| 2553 | } |
| 2554 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 2555 | if (profileLevelType->nProfileIndex == 0) { |
| 2556 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple; |
| 2557 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2558 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2559 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple; |
| 2560 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2561 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2562 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2563 | eRet = OMX_ErrorNoMore; |
| 2564 | } |
| 2565 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 2566 | eRet = OMX_ErrorNoMore; |
| 2567 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 2568 | if (profileLevelType->nProfileIndex == 0) { |
| 2569 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple; |
| 2570 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2571 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2572 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain; |
| 2573 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2574 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2575 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", profileLevelType->nProfileIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2576 | eRet = OMX_ErrorNoMore; |
| 2577 | } |
| 2578 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2579 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported ret NoMore for codec: %s", drv_ctx.kind); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2580 | eRet = OMX_ErrorNoMore; |
| 2581 | } |
| 2582 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2583 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported should be queries on Input port only %lu", profileLevelType->nPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2584 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2585 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2586 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2590 | FUNCTION |
| 2591 | omx_vdec::GetParameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2592 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2593 | DESCRIPTION |
| 2594 | OMX Get Parameter method implementation |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2595 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2596 | PARAMETERS |
| 2597 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2598 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2599 | RETURN VALUE |
| 2600 | Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2601 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2602 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2603 | OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2604 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 2605 | OMX_INOUT OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2606 | { |
| 2607 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2608 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2609 | DEBUG_PRINT_LOW("get_parameter:"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2610 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2611 | DEBUG_PRINT_ERROR("Get Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2612 | return OMX_ErrorInvalidState; |
| 2613 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2614 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2615 | DEBUG_PRINT_LOW("Get Param in Invalid paramData"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2616 | return OMX_ErrorBadParameter; |
| 2617 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2618 | switch ((unsigned long)paramIndex) { |
| 2619 | case OMX_IndexParamPortDefinition: { |
| 2620 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = |
| 2621 | (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2622 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2623 | eRet = update_portdef(portDefn); |
| 2624 | if (eRet == OMX_ErrorNone) |
| 2625 | m_port_def = *portDefn; |
| 2626 | break; |
| 2627 | } |
| 2628 | case OMX_IndexParamVideoInit: { |
| 2629 | OMX_PORT_PARAM_TYPE *portParamType = |
| 2630 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2631 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2632 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2633 | portParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2634 | portParamType->nSize = sizeof(portParamType); |
| 2635 | portParamType->nPorts = 2; |
| 2636 | portParamType->nStartPortNumber = 0; |
| 2637 | break; |
| 2638 | } |
| 2639 | case OMX_IndexParamVideoPortFormat: { |
| 2640 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 2641 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2642 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2643 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2644 | portFmt->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2645 | portFmt->nSize = sizeof(portFmt); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2646 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2647 | if (0 == portFmt->nPortIndex) { |
| 2648 | if (0 == portFmt->nIndex) { |
| 2649 | portFmt->eColorFormat = OMX_COLOR_FormatUnused; |
| 2650 | portFmt->eCompressionFormat = eCompressionFormat; |
| 2651 | } else { |
| 2652 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2653 | " NoMore compression formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2654 | eRet = OMX_ErrorNoMore; |
| 2655 | } |
| 2656 | } else if (1 == portFmt->nPortIndex) { |
| 2657 | portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2658 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2659 | if (0 == portFmt->nIndex) |
| 2660 | portFmt->eColorFormat = (OMX_COLOR_FORMATTYPE) |
| 2661 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 2662 | else if (1 == portFmt->nIndex) |
| 2663 | portFmt->eColorFormat = OMX_COLOR_FormatYUV420Planar; |
| 2664 | else { |
| 2665 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2666 | " NoMore Color formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2667 | eRet = OMX_ErrorNoMore; |
| 2668 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2669 | DEBUG_PRINT_LOW("returning %d", portFmt->eColorFormat); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2670 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2671 | DEBUG_PRINT_ERROR("get_parameter: Bad port index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2672 | (int)portFmt->nPortIndex); |
| 2673 | eRet = OMX_ErrorBadPortIndex; |
| 2674 | } |
| 2675 | break; |
| 2676 | } |
| 2677 | /*Component should support this port definition*/ |
| 2678 | case OMX_IndexParamAudioInit: { |
| 2679 | OMX_PORT_PARAM_TYPE *audioPortParamType = |
| 2680 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2681 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2682 | audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2683 | audioPortParamType->nSize = sizeof(audioPortParamType); |
| 2684 | audioPortParamType->nPorts = 0; |
| 2685 | audioPortParamType->nStartPortNumber = 0; |
| 2686 | break; |
| 2687 | } |
| 2688 | /*Component should support this port definition*/ |
| 2689 | case OMX_IndexParamImageInit: { |
| 2690 | OMX_PORT_PARAM_TYPE *imagePortParamType = |
| 2691 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2692 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2693 | imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2694 | imagePortParamType->nSize = sizeof(imagePortParamType); |
| 2695 | imagePortParamType->nPorts = 0; |
| 2696 | imagePortParamType->nStartPortNumber = 0; |
| 2697 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2698 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2699 | } |
| 2700 | /*Component should support this port definition*/ |
| 2701 | case OMX_IndexParamOtherInit: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2702 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2703 | paramIndex); |
| 2704 | eRet =OMX_ErrorUnsupportedIndex; |
| 2705 | break; |
| 2706 | } |
| 2707 | case OMX_IndexParamStandardComponentRole: { |
| 2708 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 2709 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
| 2710 | comp_role->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2711 | comp_role->nSize = sizeof(*comp_role); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2712 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2713 | DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2714 | paramIndex); |
| 2715 | strlcpy((char*)comp_role->cRole,(const char*)m_cRole, |
| 2716 | OMX_MAX_STRINGNAME_SIZE); |
| 2717 | break; |
| 2718 | } |
| 2719 | /* Added for parameter test */ |
| 2720 | case OMX_IndexParamPriorityMgmt: { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2721 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2722 | OMX_PRIORITYMGMTTYPE *priorityMgmType = |
| 2723 | (OMX_PRIORITYMGMTTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2724 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2725 | priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2726 | priorityMgmType->nSize = sizeof(priorityMgmType); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2727 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2728 | break; |
| 2729 | } |
| 2730 | /* Added for parameter test */ |
| 2731 | case OMX_IndexParamCompBufferSupplier: { |
| 2732 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = |
| 2733 | (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2734 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2735 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2736 | bufferSupplierType->nSize = sizeof(bufferSupplierType); |
| 2737 | bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2738 | if (0 == bufferSupplierType->nPortIndex) |
| 2739 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2740 | else if (1 == bufferSupplierType->nPortIndex) |
| 2741 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2742 | else |
| 2743 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2744 | |
| 2745 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2746 | break; |
| 2747 | } |
| 2748 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2749 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2750 | paramIndex); |
| 2751 | break; |
| 2752 | } |
| 2753 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2754 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2755 | paramIndex); |
| 2756 | break; |
| 2757 | } |
| 2758 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2759 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2760 | paramIndex); |
| 2761 | break; |
| 2762 | } |
| 2763 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2764 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2765 | paramIndex); |
| 2766 | break; |
| 2767 | } |
| 2768 | case OMX_IndexParamVideoProfileLevelQuerySupported: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2769 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2770 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType = |
| 2771 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData; |
| 2772 | eRet = get_supported_profile_level_for_1080p(profileLevelType); |
| 2773 | break; |
| 2774 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2775 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2776 | case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2777 | DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2778 | GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData; |
| 2779 | if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2780 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2781 | if (secure_mode) { |
| 2782 | nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED | |
| 2783 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2784 | } else { |
| 2785 | nativeBuffersUsage->nUsage = |
| 2786 | (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | |
| 2787 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2788 | } |
| 2789 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2790 | DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2791 | eRet = OMX_ErrorBadParameter; |
| 2792 | } |
| 2793 | } |
| 2794 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2795 | #endif |
| 2796 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2797 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2798 | DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2799 | eRet =OMX_ErrorUnsupportedIndex; |
| 2800 | } |
| 2801 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2804 | DEBUG_PRINT_LOW("get_parameter returning WxH(%d x %d) SxSH(%d x %d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2805 | drv_ctx.video_resolution.frame_width, |
| 2806 | drv_ctx.video_resolution.frame_height, |
| 2807 | drv_ctx.video_resolution.stride, |
| 2808 | drv_ctx.video_resolution.scan_lines); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2809 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2810 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
| 2814 | OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data) |
| 2815 | { |
| 2816 | DEBUG_PRINT_LOW("Inside use_android_native_buffer"); |
| 2817 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2818 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data; |
| 2819 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2820 | if ((params == NULL) || |
| 2821 | (params->nativeBuffer == NULL) || |
| 2822 | (params->nativeBuffer->handle == NULL) || |
| 2823 | !m_enable_android_native_buffers) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2824 | return OMX_ErrorBadParameter; |
| 2825 | m_use_android_native_buffers = OMX_TRUE; |
| 2826 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 2827 | private_handle_t *handle = (private_handle_t *)nBuf->handle; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2828 | if (OMX_CORE_OUTPUT_PORT_INDEX == params->nPortIndex) { //android native buffers can be used only on Output port |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2829 | OMX_U8 *buffer = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2830 | if (!secure_mode) { |
| 2831 | buffer = (OMX_U8*)mmap(0, handle->size, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2832 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2833 | if (buffer == MAP_FAILED) { |
| 2834 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 2835 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer); |
| 2839 | } else { |
| 2840 | eRet = OMX_ErrorBadParameter; |
| 2841 | } |
| 2842 | return eRet; |
| 2843 | } |
| 2844 | #endif |
| 2845 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2846 | FUNCTION |
| 2847 | omx_vdec::Setparameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2848 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2849 | DESCRIPTION |
| 2850 | OMX Set Parameter method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2851 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2852 | PARAMETERS |
| 2853 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2854 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2855 | RETURN VALUE |
| 2856 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2857 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2858 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2859 | OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2860 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 2861 | OMX_IN OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2862 | { |
| 2863 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Praneeth Paladugu | 226667c | 2012-09-12 16:42:30 -0700 | [diff] [blame] | 2864 | int ret=0; |
| 2865 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2866 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2867 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2868 | return OMX_ErrorInvalidState; |
| 2869 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2870 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2871 | DEBUG_PRINT_ERROR("Get Param in Invalid paramData"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2872 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2873 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2874 | if ((m_state != OMX_StateLoaded) && |
| 2875 | BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) && |
| 2876 | (m_out_bEnabled == OMX_TRUE) && |
| 2877 | BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) && |
| 2878 | (m_inp_bEnabled == OMX_TRUE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2879 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2880 | return OMX_ErrorIncorrectStateOperation; |
| 2881 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2882 | switch ((unsigned long)paramIndex) { |
| 2883 | case OMX_IndexParamPortDefinition: { |
| 2884 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn; |
| 2885 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
| 2886 | //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has |
| 2887 | //been called. |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2888 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2889 | (int)portDefn->format.video.nFrameHeight, |
| 2890 | (int)portDefn->format.video.nFrameWidth); |
| 2891 | if (OMX_DirOutput == portDefn->eDir) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2892 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2893 | m_display_id = portDefn->format.video.pNativeWindow; |
| 2894 | unsigned int buffer_size; |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 2895 | DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n", |
| 2896 | portDefn->format.video.nFrameWidth, |
| 2897 | portDefn->format.video.nFrameHeight); |
| 2898 | if (portDefn->format.video.nFrameHeight != 0x0 && |
| 2899 | portDefn->format.video.nFrameWidth != 0x0) { |
| 2900 | update_resolution(portDefn->format.video.nFrameWidth, |
| 2901 | portDefn->format.video.nFrameHeight, |
| 2902 | portDefn->format.video.nFrameWidth, |
| 2903 | portDefn->format.video.nFrameHeight); |
| 2904 | eRet = is_video_session_supported(); |
| 2905 | if (eRet) |
| 2906 | break; |
| 2907 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 2908 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 2909 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 2910 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 2911 | DEBUG_PRINT_LOW("\n fmt.fmt.pix_mp.height = %d , fmt.fmt.pix_mp.width = %d \n",fmt.fmt.pix_mp.height,fmt.fmt.pix_mp.width); |
| 2912 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 2913 | if (ret) { |
| 2914 | DEBUG_PRINT_ERROR("\n Set Resolution failed"); |
| 2915 | eRet = OMX_ErrorUnsupportedSetting; |
| 2916 | } else |
| 2917 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 2918 | } |
| 2919 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2920 | if (!client_buffers.get_buffer_req(buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2921 | DEBUG_PRINT_ERROR("Error in getting buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2922 | eRet = OMX_ErrorBadParameter; |
| 2923 | } else { |
| 2924 | if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount && |
| 2925 | portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) { |
| 2926 | drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual; |
| 2927 | drv_ctx.op_buf.buffer_size = portDefn->nBufferSize; |
| 2928 | drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount; |
| 2929 | drv_ctx.extradata_info.size = drv_ctx.extradata_info.count * |
| 2930 | drv_ctx.extradata_info.buffer_size; |
| 2931 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 2932 | if (eRet == OMX_ErrorNone) |
| 2933 | m_port_def = *portDefn; |
| 2934 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2935 | DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2936 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size, |
| 2937 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 2938 | eRet = OMX_ErrorBadParameter; |
| 2939 | } |
| 2940 | } |
| 2941 | } else if (OMX_DirInput == portDefn->eDir) { |
| 2942 | bool port_format_changed = false; |
| 2943 | if ((portDefn->format.video.xFramerate >> 16) > 0 && |
| 2944 | (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) { |
| 2945 | // Frame rate only should be set if this is a "known value" or to |
| 2946 | // activate ts prediction logic (arbitrary mode only) sending input |
| 2947 | // timestamps with max value (LLONG_MAX). |
| 2948 | DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu", |
| 2949 | portDefn->format.video.xFramerate >> 16); |
| 2950 | Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator, |
| 2951 | drv_ctx.frame_rate.fps_denominator); |
| 2952 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 2953 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 2954 | drv_ctx.frame_rate.fps_numerator = 30; |
| 2955 | } |
| 2956 | if (drv_ctx.frame_rate.fps_denominator) |
| 2957 | drv_ctx.frame_rate.fps_numerator = (int) |
| 2958 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 2959 | drv_ctx.frame_rate.fps_denominator = 1; |
| 2960 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 2961 | drv_ctx.frame_rate.fps_numerator; |
| 2962 | DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)", |
| 2963 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 2964 | (float)drv_ctx.frame_rate.fps_denominator); |
| 2965 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2966 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2967 | if (drv_ctx.video_resolution.frame_height != |
| 2968 | portDefn->format.video.nFrameHeight || |
| 2969 | drv_ctx.video_resolution.frame_width != |
| 2970 | portDefn->format.video.nFrameWidth) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2971 | DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2972 | portDefn->format.video.nFrameWidth, |
| 2973 | portDefn->format.video.nFrameHeight); |
| 2974 | port_format_changed = true; |
| 2975 | if (portDefn->format.video.nFrameHeight != 0x0 && |
| 2976 | portDefn->format.video.nFrameWidth != 0x0) { |
| 2977 | update_resolution(portDefn->format.video.nFrameWidth, |
| 2978 | portDefn->format.video.nFrameHeight, |
| 2979 | portDefn->format.video.nFrameWidth, |
| 2980 | portDefn->format.video.nFrameHeight); |
| 2981 | eRet = is_video_session_supported(); |
| 2982 | if (eRet) |
| 2983 | break; |
| 2984 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 2985 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 2986 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 2987 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2988 | 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 Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2989 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 2990 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2991 | DEBUG_PRINT_ERROR("Set Resolution failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2992 | eRet = OMX_ErrorUnsupportedSetting; |
| 2993 | } else |
| 2994 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 2995 | } |
| 2996 | } |
| 2997 | if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount |
| 2998 | || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) { |
| 2999 | port_format_changed = true; |
| 3000 | vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf; |
| 3001 | drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual; |
| 3002 | drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) & |
| 3003 | (~(buffer_prop->alignment - 1)); |
| 3004 | eRet = set_buffer_req(buffer_prop); |
| 3005 | } |
| 3006 | if (false == port_format_changed) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3007 | DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3008 | drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size, |
| 3009 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3010 | eRet = OMX_ErrorBadParameter; |
| 3011 | } |
| 3012 | } else if (portDefn->eDir == OMX_DirMax) { |
| 3013 | DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d", |
| 3014 | (int)portDefn->nPortIndex); |
| 3015 | eRet = OMX_ErrorBadPortIndex; |
| 3016 | } |
| 3017 | } |
| 3018 | break; |
| 3019 | case OMX_IndexParamVideoPortFormat: { |
| 3020 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 3021 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
| 3022 | int ret=0; |
| 3023 | struct v4l2_format fmt; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3024 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3025 | portFmt->eColorFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3026 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3027 | if (1 == portFmt->nPortIndex) { |
| 3028 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3029 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3030 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3031 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3032 | enum vdec_output_fromat op_format; |
| 3033 | if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE) |
| 3034 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) || |
| 3035 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar)) |
| 3036 | op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12; |
| 3037 | else if (portFmt->eColorFormat == |
| 3038 | (OMX_COLOR_FORMATTYPE) |
| 3039 | QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka) |
| 3040 | op_format = VDEC_YUV_FORMAT_TILE_4x2; |
| 3041 | else |
| 3042 | eRet = OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3043 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3044 | if (eRet == OMX_ErrorNone) { |
| 3045 | drv_ctx.output_format = op_format; |
| 3046 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3047 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3048 | DEBUG_PRINT_ERROR("Set output format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3049 | eRet = OMX_ErrorUnsupportedSetting; |
| 3050 | /*TODO: How to handle this case */ |
| 3051 | } else { |
| 3052 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3053 | } |
| 3054 | } |
| 3055 | if (eRet == OMX_ErrorNone) { |
| 3056 | if (!client_buffers.set_color_format(portFmt->eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3057 | DEBUG_PRINT_ERROR("Set color format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3058 | eRet = OMX_ErrorBadParameter; |
| 3059 | } |
| 3060 | } |
| 3061 | } |
| 3062 | } |
| 3063 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3064 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3065 | case OMX_QcomIndexPortDefn: { |
| 3066 | OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt = |
| 3067 | (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3068 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3069 | portFmt->nFramePackingFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3070 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3071 | /* Input port */ |
| 3072 | if (portFmt->nPortIndex == 0) { |
| 3073 | if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) { |
| 3074 | if (secure_mode) { |
| 3075 | arbitrary_bytes = false; |
| 3076 | DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session"); |
| 3077 | eRet = OMX_ErrorUnsupportedSetting; |
| 3078 | } else { |
| 3079 | arbitrary_bytes = true; |
| 3080 | } |
| 3081 | } else if (portFmt->nFramePackingFormat == |
| 3082 | OMX_QCOM_FramePacking_OnlyOneCompleteFrame) { |
| 3083 | arbitrary_bytes = false; |
| 3084 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3085 | DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3086 | portFmt->nFramePackingFormat); |
| 3087 | eRet = OMX_ErrorUnsupportedSetting; |
| 3088 | } |
| 3089 | } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3090 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3091 | if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid && |
| 3092 | portFmt->nMemRegion < OMX_QCOM_MemRegionMax) && |
| 3093 | portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) { |
| 3094 | m_out_mem_region_smi = OMX_TRUE; |
| 3095 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3096 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3097 | m_use_output_pmem = OMX_TRUE; |
| 3098 | } |
| 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3103 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3104 | case OMX_IndexParamStandardComponentRole: { |
| 3105 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 3106 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3107 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3108 | comp_role->cRole); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3109 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3110 | if ((m_state == OMX_StateLoaded)&& |
| 3111 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 3112 | DEBUG_PRINT_LOW("Set Parameter called in valid state"); |
| 3113 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3114 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3115 | return OMX_ErrorIncorrectStateOperation; |
| 3116 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3117 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3118 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3119 | if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3120 | strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 3121 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3122 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3123 | eRet =OMX_ErrorUnsupportedSetting; |
| 3124 | } |
| 3125 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3126 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3127 | strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
| 3128 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3129 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3130 | eRet = OMX_ErrorUnsupportedSetting; |
| 3131 | } |
| 3132 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3133 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3134 | strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
| 3135 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3136 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3137 | eRet =OMX_ErrorUnsupportedSetting; |
| 3138 | } |
| 3139 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3140 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3141 | strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
| 3142 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3143 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3144 | eRet = OMX_ErrorUnsupportedSetting; |
| 3145 | } |
| 3146 | } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) || |
| 3147 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE)) |
| 3148 | ) { |
| 3149 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) { |
| 3150 | strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
| 3151 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3152 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3153 | eRet =OMX_ErrorUnsupportedSetting; |
| 3154 | } |
| 3155 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 3156 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 3157 | ) { |
| 3158 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) { |
| 3159 | strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 3160 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3161 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3162 | eRet =OMX_ErrorUnsupportedSetting; |
| 3163 | } |
| 3164 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 3165 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) || |
| 3166 | (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) { |
| 3167 | strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 3168 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3169 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3170 | eRet = OMX_ErrorUnsupportedSetting; |
| 3171 | } |
| 3172 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3173 | DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3174 | eRet = OMX_ErrorInvalidComponentName; |
| 3175 | } |
| 3176 | break; |
| 3177 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3178 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3179 | case OMX_IndexParamPriorityMgmt: { |
| 3180 | if (m_state != OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3181 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3182 | return OMX_ErrorIncorrectStateOperation; |
| 3183 | } |
| 3184 | OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3185 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3186 | priorityMgmtype->nGroupID); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3187 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3188 | DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3189 | priorityMgmtype->nGroupPriority); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3190 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3191 | m_priority_mgm.nGroupID = priorityMgmtype->nGroupID; |
| 3192 | m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3193 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3194 | break; |
| 3195 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3196 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3197 | case OMX_IndexParamCompBufferSupplier: { |
| 3198 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3199 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3200 | bufferSupplierType->eBufferSupplier); |
| 3201 | if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1) |
| 3202 | m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3203 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3204 | else |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3205 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3206 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3207 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3208 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3209 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3210 | } |
| 3211 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3212 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3213 | paramIndex); |
| 3214 | break; |
| 3215 | } |
| 3216 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3217 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3218 | paramIndex); |
| 3219 | break; |
| 3220 | } |
| 3221 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3222 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3223 | paramIndex); |
| 3224 | break; |
| 3225 | } |
| 3226 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3227 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3228 | paramIndex); |
| 3229 | break; |
| 3230 | } |
| 3231 | case OMX_QcomIndexParamVideoDecoderPictureOrder: { |
| 3232 | QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder = |
| 3233 | (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData; |
| 3234 | struct v4l2_control control; |
| 3235 | int pic_order,rc=0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3236 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3237 | pictureOrder->eOutputPictureOrder); |
| 3238 | if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) { |
| 3239 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 3240 | } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) { |
| 3241 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3242 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3243 | } else |
| 3244 | eRet = OMX_ErrorBadParameter; |
| 3245 | if (eRet == OMX_ErrorNone) { |
| 3246 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3247 | control.value = pic_order; |
| 3248 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3249 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3250 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3251 | eRet = OMX_ErrorUnsupportedSetting; |
| 3252 | } |
| 3253 | } |
| 3254 | break; |
| 3255 | } |
| 3256 | case OMX_QcomIndexParamConcealMBMapExtraData: |
| 3257 | if (!secure_mode) |
| 3258 | eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false, |
| 3259 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3260 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3261 | DEBUG_PRINT_ERROR("secure mode setting not supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3262 | eRet = OMX_ErrorUnsupportedSetting; |
| 3263 | } |
| 3264 | break; |
| 3265 | case OMX_QcomIndexParamFrameInfoExtraData: { |
| 3266 | if (!secure_mode) |
| 3267 | eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false, |
| 3268 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3269 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3270 | DEBUG_PRINT_ERROR("secure mode setting not supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3271 | eRet = OMX_ErrorUnsupportedSetting; |
| 3272 | } |
| 3273 | break; |
| 3274 | } |
| 3275 | case OMX_QcomIndexParamInterlaceExtraData: |
| 3276 | if (!secure_mode) |
| 3277 | eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false, |
| 3278 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3279 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3280 | DEBUG_PRINT_ERROR("secure mode setting not supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3281 | eRet = OMX_ErrorUnsupportedSetting; |
| 3282 | } |
| 3283 | break; |
| 3284 | case OMX_QcomIndexParamH264TimeInfo: |
| 3285 | if (!secure_mode) |
| 3286 | eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false, |
| 3287 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3288 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3289 | DEBUG_PRINT_ERROR("secure mode setting not supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3290 | eRet = OMX_ErrorUnsupportedSetting; |
| 3291 | } |
| 3292 | break; |
| 3293 | case OMX_QcomIndexParamVideoDivx: { |
| 3294 | QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData; |
| 3295 | } |
| 3296 | break; |
| 3297 | case OMX_QcomIndexPlatformPvt: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3298 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3299 | OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData; |
| 3300 | if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
| 3301 | DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type); |
| 3302 | eRet = OMX_ErrorUnsupportedSetting; |
| 3303 | } else { |
| 3304 | m_out_pvt_entry_pmem = OMX_TRUE; |
| 3305 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3306 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3307 | m_use_output_pmem = OMX_TRUE; |
| 3308 | } |
| 3309 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3310 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3311 | } |
| 3312 | break; |
| 3313 | case OMX_QcomIndexParamVideoSyncFrameDecodingMode: { |
| 3314 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode"); |
| 3315 | DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode"); |
| 3316 | struct v4l2_control control; |
| 3317 | int rc; |
| 3318 | drv_ctx.idr_only_decoding = 1; |
| 3319 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3320 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3321 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3322 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3323 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3324 | eRet = OMX_ErrorUnsupportedSetting; |
| 3325 | } else { |
| 3326 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE; |
| 3327 | control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE; |
| 3328 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3329 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3330 | DEBUG_PRINT_ERROR("Sync frame setting failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3331 | eRet = OMX_ErrorUnsupportedSetting; |
| 3332 | } |
| 3333 | /*Setting sync frame decoding on driver might change buffer |
| 3334 | * requirements so update them here*/ |
| 3335 | if (get_buffer_req(&drv_ctx.ip_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3336 | DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer i/p requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3337 | eRet = OMX_ErrorUnsupportedSetting; |
| 3338 | } |
| 3339 | if (get_buffer_req(&drv_ctx.op_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3340 | DEBUG_PRINT_ERROR("Sync frame setting failed: falied to get buffer o/p requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3341 | eRet = OMX_ErrorUnsupportedSetting; |
| 3342 | } |
| 3343 | } |
| 3344 | } |
| 3345 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3346 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3347 | case OMX_QcomIndexParamIndexExtraDataType: { |
| 3348 | if (!secure_mode) { |
| 3349 | QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData; |
| 3350 | if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) && |
| 3351 | (extradataIndexType->bEnabled == OMX_TRUE) && |
| 3352 | (extradataIndexType->nPortIndex == 1)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3353 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3354 | eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled); |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 3355 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3356 | } |
| 3357 | } |
| 3358 | } |
| 3359 | break; |
| 3360 | case OMX_QcomIndexParamEnableSmoothStreaming: { |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3361 | #ifndef SMOOTH_STREAMING_DISABLED |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3362 | struct v4l2_control control; |
| 3363 | struct v4l2_format fmt; |
| 3364 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER; |
| 3365 | control.value = 1; |
| 3366 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3367 | if (rc < 0) { |
| 3368 | DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver."); |
| 3369 | eRet = OMX_ErrorHardware; |
| 3370 | } |
Arun Menon | bc0922f | 2013-06-24 13:02:15 -0700 | [diff] [blame] | 3371 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3372 | eRet = OMX_ErrorUnsupportedSetting; |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3373 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3374 | } |
| 3375 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3376 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3377 | /* Need to allow following two set_parameters even in Idle |
| 3378 | * state. This is ANDROID architecture which is not in sync |
| 3379 | * with openmax standard. */ |
| 3380 | case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: { |
| 3381 | EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData; |
| 3382 | if (enableNativeBuffers) { |
| 3383 | m_enable_android_native_buffers = enableNativeBuffers->enable; |
| 3384 | } |
| 3385 | } |
| 3386 | break; |
| 3387 | case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: { |
| 3388 | eRet = use_android_native_buffer(hComp, paramData); |
| 3389 | } |
| 3390 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3391 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3392 | case OMX_QcomIndexParamEnableTimeStampReorder: { |
| 3393 | QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData; |
| 3394 | if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) { |
| 3395 | if (reorder->bEnable == OMX_TRUE) { |
| 3396 | frm_int =0; |
| 3397 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 3398 | } else |
| 3399 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3400 | } else { |
| 3401 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3402 | if (reorder->bEnable == OMX_TRUE) { |
| 3403 | eRet = OMX_ErrorUnsupportedSetting; |
| 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | break; |
| 3408 | case OMX_IndexParamVideoProfileLevelCurrent: { |
| 3409 | OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = |
| 3410 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData; |
| 3411 | if (pParam) { |
| 3412 | m_profile_lvl.eProfile = pParam->eProfile; |
| 3413 | m_profile_lvl.eLevel = pParam->eLevel; |
| 3414 | } |
| 3415 | break; |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 3416 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3417 | } |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3418 | case OMX_QcomIndexParamVideoMetaBufferMode: |
| 3419 | { |
| 3420 | StoreMetaDataInBuffersParams *metabuffer = |
| 3421 | (StoreMetaDataInBuffersParams *)paramData; |
| 3422 | if (!metabuffer) { |
| 3423 | DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer); |
| 3424 | eRet = OMX_ErrorBadParameter; |
| 3425 | break; |
| 3426 | } |
| 3427 | if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3428 | //set property dynamic buffer mode to driver. |
| 3429 | struct v4l2_control control; |
| 3430 | struct v4l2_format fmt; |
| 3431 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT; |
| 3432 | if (metabuffer->bStoreMetaData == true) { |
| 3433 | control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC; |
| 3434 | } else { |
| 3435 | control.value = V4L2_MPEG_VIDC_VIDEO_STATIC; |
| 3436 | } |
| 3437 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3438 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3439 | DEBUG_PRINT_HIGH("%s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3440 | (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 3441 | dynamic_buf_mode = metabuffer->bStoreMetaData; |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3442 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3443 | DEBUG_PRINT_ERROR("Failed to %s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3444 | (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic"); |
| 3445 | eRet = OMX_ErrorUnsupportedSetting; |
| 3446 | } |
| 3447 | } else { |
| 3448 | DEBUG_PRINT_ERROR( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3449 | "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %d", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3450 | metabuffer->nPortIndex); |
| 3451 | eRet = OMX_ErrorUnsupportedSetting; |
| 3452 | } |
| 3453 | break; |
| 3454 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3455 | case OMX_QcomIndexParamVideoDownScalar: { |
| 3456 | QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData; |
| 3457 | struct v4l2_control control; |
| 3458 | int rc; |
| 3459 | if (pParam) { |
| 3460 | is_down_scalar_enabled = pParam->bEnable; |
| 3461 | if (is_down_scalar_enabled) { |
| 3462 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE; |
| 3463 | control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY; |
| 3464 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n", |
| 3465 | pParam->bEnable); |
| 3466 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3467 | if (rc < 0) { |
| 3468 | DEBUG_PRINT_ERROR("Failed to set down scalar on driver."); |
| 3469 | eRet = OMX_ErrorUnsupportedSetting; |
| 3470 | } |
| 3471 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO; |
| 3472 | control.value = 1; |
| 3473 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3474 | if (rc < 0) { |
| 3475 | DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver."); |
| 3476 | eRet = OMX_ErrorUnsupportedSetting; |
| 3477 | } |
| 3478 | } |
| 3479 | } |
| 3480 | break; |
| 3481 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3482 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3483 | DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3484 | eRet = OMX_ErrorUnsupportedIndex; |
| 3485 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3486 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3487 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3491 | FUNCTION |
| 3492 | omx_vdec::GetConfig |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3493 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3494 | DESCRIPTION |
| 3495 | OMX Get Config Method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3496 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3497 | PARAMETERS |
| 3498 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3499 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3500 | RETURN VALUE |
| 3501 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3502 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3503 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3504 | OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3505 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3506 | OMX_INOUT OMX_PTR configData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3507 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3508 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3509 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3510 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3511 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3512 | return OMX_ErrorInvalidState; |
| 3513 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3514 | |
| 3515 | switch ((unsigned long)configIndex) { |
| 3516 | case OMX_QcomIndexConfigInterlaced: { |
| 3517 | OMX_QCOM_CONFIG_INTERLACETYPE *configFmt = |
| 3518 | (OMX_QCOM_CONFIG_INTERLACETYPE *) configData; |
| 3519 | if (configFmt->nPortIndex == 1) { |
| 3520 | if (configFmt->nIndex == 0) { |
| 3521 | configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 3522 | } else if (configFmt->nIndex == 1) { |
| 3523 | configFmt->eInterlaceType = |
| 3524 | OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 3525 | } else if (configFmt->nIndex == 2) { |
| 3526 | configFmt->eInterlaceType = |
| 3527 | OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 3528 | } else { |
| 3529 | DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3530 | " NoMore Interlaced formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3531 | eRet = OMX_ErrorNoMore; |
| 3532 | } |
| 3533 | |
| 3534 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3535 | DEBUG_PRINT_ERROR("get_config: Bad port index %d queried on only o/p port", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3536 | (int)configFmt->nPortIndex); |
| 3537 | eRet = OMX_ErrorBadPortIndex; |
| 3538 | } |
| 3539 | break; |
| 3540 | } |
| 3541 | case OMX_QcomIndexQueryNumberOfVideoDecInstance: { |
| 3542 | QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances = |
| 3543 | (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData; |
| 3544 | decoderinstances->nNumOfInstances = 16; |
| 3545 | /*TODO: How to handle this case */ |
| 3546 | break; |
| 3547 | } |
| 3548 | case OMX_QcomIndexConfigVideoFramePackingArrangement: { |
| 3549 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
| 3550 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt = |
| 3551 | (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData; |
| 3552 | h264_parser->get_frame_pack_data(configFmt); |
| 3553 | } else { |
| 3554 | DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs"); |
| 3555 | } |
| 3556 | break; |
| 3557 | } |
| 3558 | case OMX_IndexConfigCommonOutputCrop: { |
| 3559 | OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData; |
| 3560 | memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE)); |
| 3561 | break; |
| 3562 | } |
| 3563 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3564 | DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3565 | eRet = OMX_ErrorBadParameter; |
| 3566 | } |
| 3567 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3568 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3569 | |
| 3570 | return eRet; |
| 3571 | } |
| 3572 | |
| 3573 | /* ====================================================================== |
| 3574 | FUNCTION |
| 3575 | omx_vdec::SetConfig |
| 3576 | |
| 3577 | DESCRIPTION |
| 3578 | OMX Set Config method implementation |
| 3579 | |
| 3580 | PARAMETERS |
| 3581 | <TBD>. |
| 3582 | |
| 3583 | RETURN VALUE |
| 3584 | OMX Error None if successful. |
| 3585 | ========================================================================== */ |
| 3586 | OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp, |
| 3587 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3588 | OMX_IN OMX_PTR configData) |
| 3589 | { |
| 3590 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3591 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3592 | return OMX_ErrorInvalidState; |
| 3593 | } |
| 3594 | |
| 3595 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 3596 | OMX_VIDEO_CONFIG_NALSIZE *pNal; |
| 3597 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3598 | DEBUG_PRINT_LOW("Set Config Called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3599 | |
| 3600 | if (configIndex == (OMX_INDEXTYPE)OMX_IndexVendorVideoExtraData) { |
| 3601 | OMX_VENDOR_EXTRADATATYPE *config = (OMX_VENDOR_EXTRADATATYPE *) configData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3602 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3603 | if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3604 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData AVC"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3605 | OMX_U32 extra_size; |
| 3606 | // Parsing done here for the AVC atom is definitely not generic |
| 3607 | // Currently this piece of code is working, but certainly |
| 3608 | // not tested with all .mp4 files. |
| 3609 | // Incase of failure, we might need to revisit this |
| 3610 | // for a generic piece of code. |
| 3611 | |
| 3612 | // Retrieve size of NAL length field |
| 3613 | // byte #4 contains the size of NAL lenght field |
| 3614 | nal_length = (config->pData[4] & 0x03) + 1; |
| 3615 | |
| 3616 | extra_size = 0; |
| 3617 | if (nal_length > 2) { |
| 3618 | /* Presently we assume that only one SPS and one PPS in AvC1 Atom */ |
| 3619 | extra_size = (nal_length - 2) * 2; |
| 3620 | } |
| 3621 | |
| 3622 | // SPS starts from byte #6 |
| 3623 | OMX_U8 *pSrcBuf = (OMX_U8 *) (&config->pData[6]); |
| 3624 | OMX_U8 *pDestBuf; |
| 3625 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3626 | |
| 3627 | // minus 6 --> SPS starts from byte #6 |
| 3628 | // minus 1 --> picture param set byte to be ignored from avcatom |
| 3629 | m_vendor_config.nDataSize = config->nDataSize - 6 - 1 + extra_size; |
| 3630 | m_vendor_config.pData = (OMX_U8 *) malloc(m_vendor_config.nDataSize); |
| 3631 | OMX_U32 len; |
| 3632 | OMX_U8 index = 0; |
| 3633 | // case where SPS+PPS is sent as part of set_config |
| 3634 | pDestBuf = m_vendor_config.pData; |
| 3635 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3636 | DEBUG_PRINT_LOW("Rxd SPS+PPS nPortIndex[%lu] len[%lu] data[%p]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3637 | m_vendor_config.nPortIndex, |
| 3638 | m_vendor_config.nDataSize, |
| 3639 | m_vendor_config.pData); |
| 3640 | while (index < 2) { |
| 3641 | uint8 *psize; |
| 3642 | len = *pSrcBuf; |
| 3643 | len = len << 8; |
| 3644 | len |= *(pSrcBuf + 1); |
| 3645 | psize = (uint8 *) & len; |
| 3646 | memcpy(pDestBuf + nal_length, pSrcBuf + 2,len); |
| 3647 | for (unsigned int i = 0; i < nal_length; i++) { |
| 3648 | pDestBuf[i] = psize[nal_length - 1 - i]; |
| 3649 | } |
| 3650 | //memcpy(pDestBuf,pSrcBuf,(len+2)); |
| 3651 | pDestBuf += len + nal_length; |
| 3652 | pSrcBuf += len + 2; |
| 3653 | index++; |
| 3654 | pSrcBuf++; // skip picture param set |
| 3655 | len = 0; |
| 3656 | } |
| 3657 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4") || |
| 3658 | !strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2")) { |
| 3659 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3660 | m_vendor_config.nDataSize = config->nDataSize; |
| 3661 | m_vendor_config.pData = (OMX_U8 *) malloc((config->nDataSize)); |
| 3662 | memcpy(m_vendor_config.pData, config->pData,config->nDataSize); |
| 3663 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1")) { |
| 3664 | if (m_vendor_config.pData) { |
| 3665 | free(m_vendor_config.pData); |
| 3666 | m_vendor_config.pData = NULL; |
| 3667 | m_vendor_config.nDataSize = 0; |
| 3668 | } |
| 3669 | |
| 3670 | if (((*((OMX_U32 *) config->pData)) & |
| 3671 | VC1_SP_MP_START_CODE_MASK) == |
| 3672 | VC1_SP_MP_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3673 | DEBUG_PRINT_LOW("set_config - VC1 simple/main profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3674 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3675 | m_vendor_config.nDataSize = config->nDataSize; |
| 3676 | m_vendor_config.pData = |
| 3677 | (OMX_U8 *) malloc(config->nDataSize); |
| 3678 | memcpy(m_vendor_config.pData, config->pData, |
| 3679 | config->nDataSize); |
| 3680 | m_vc1_profile = VC1_SP_MP_RCV; |
| 3681 | } else if (*((OMX_U32 *) config->pData) == VC1_AP_SEQ_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3682 | DEBUG_PRINT_LOW("set_config - VC1 Advance profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3683 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3684 | m_vendor_config.nDataSize = config->nDataSize; |
| 3685 | m_vendor_config.pData = |
| 3686 | (OMX_U8 *) malloc((config->nDataSize)); |
| 3687 | memcpy(m_vendor_config.pData, config->pData, |
| 3688 | config->nDataSize); |
| 3689 | m_vc1_profile = VC1_AP; |
| 3690 | } else if ((config->nDataSize == VC1_STRUCT_C_LEN)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3691 | DEBUG_PRINT_LOW("set_config - VC1 Simple/Main profile struct C only"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3692 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3693 | m_vendor_config.nDataSize = config->nDataSize; |
| 3694 | m_vendor_config.pData = (OMX_U8*)malloc(config->nDataSize); |
| 3695 | memcpy(m_vendor_config.pData,config->pData,config->nDataSize); |
| 3696 | m_vc1_profile = VC1_SP_MP_RCV; |
| 3697 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3698 | DEBUG_PRINT_LOW("set_config - Error: Unknown VC1 profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | return ret; |
| 3702 | } else if (configIndex == OMX_IndexConfigVideoNalSize) { |
| 3703 | struct v4l2_control temp; |
| 3704 | temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT; |
| 3705 | |
| 3706 | pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData); |
| 3707 | switch (pNal->nNaluBytes) { |
| 3708 | case 0: |
| 3709 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES; |
| 3710 | break; |
| 3711 | case 2: |
| 3712 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH; |
| 3713 | break; |
| 3714 | case 4: |
| 3715 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH; |
| 3716 | break; |
| 3717 | default: |
| 3718 | return OMX_ErrorUnsupportedSetting; |
| 3719 | } |
| 3720 | |
| 3721 | if (!arbitrary_bytes) { |
| 3722 | /* In arbitrary bytes mode, the assembler strips out nal size and replaces |
| 3723 | * with start code, so only need to notify driver in frame by frame mode */ |
| 3724 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) { |
| 3725 | DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT"); |
| 3726 | return OMX_ErrorHardware; |
| 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | nal_length = pNal->nNaluBytes; |
| 3731 | m_frame_parser.init_nal_length(nal_length); |
| 3732 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3733 | DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3734 | return ret; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 3735 | } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3736 | OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 3737 | DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3738 | |
| 3739 | if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 3740 | if (config->bEnabled) { |
| 3741 | if ((config->nFps >> 16) > 0) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 3742 | DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3743 | config->nFps >> 16); |
| 3744 | Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator, |
| 3745 | drv_ctx.frame_rate.fps_denominator); |
| 3746 | |
| 3747 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 3748 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 3749 | drv_ctx.frame_rate.fps_numerator = 30; |
| 3750 | } |
| 3751 | |
| 3752 | if (drv_ctx.frame_rate.fps_denominator) { |
| 3753 | drv_ctx.frame_rate.fps_numerator = (int) |
| 3754 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 3755 | } |
| 3756 | |
| 3757 | drv_ctx.frame_rate.fps_denominator = 1; |
| 3758 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 3759 | drv_ctx.frame_rate.fps_numerator; |
| 3760 | |
| 3761 | struct v4l2_outputparm oparm; |
| 3762 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 3763 | * per second.*/ |
| 3764 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 3765 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 3766 | |
| 3767 | struct v4l2_streamparm sparm; |
| 3768 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3769 | sparm.parm.output = oparm; |
| 3770 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 3771 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 3772 | performance might be affected"); |
| 3773 | ret = OMX_ErrorHardware; |
| 3774 | } |
| 3775 | client_set_fps = true; |
| 3776 | } else { |
| 3777 | DEBUG_PRINT_ERROR("Frame rate not supported."); |
| 3778 | ret = OMX_ErrorUnsupportedSetting; |
| 3779 | } |
| 3780 | } else { |
| 3781 | DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate"); |
| 3782 | client_set_fps = false; |
| 3783 | } |
| 3784 | } else { |
| 3785 | DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d", |
| 3786 | (int)config->nPortIndex); |
| 3787 | ret = OMX_ErrorBadPortIndex; |
| 3788 | } |
| 3789 | |
| 3790 | return ret; |
| 3791 | } |
| 3792 | |
| 3793 | return OMX_ErrorNotImplemented; |
| 3794 | } |
| 3795 | |
| 3796 | /* ====================================================================== |
| 3797 | FUNCTION |
| 3798 | omx_vdec::GetExtensionIndex |
| 3799 | |
| 3800 | DESCRIPTION |
| 3801 | OMX GetExtensionIndex method implementaion. <TBD> |
| 3802 | |
| 3803 | PARAMETERS |
| 3804 | <TBD>. |
| 3805 | |
| 3806 | RETURN VALUE |
| 3807 | OMX Error None if everything successful. |
| 3808 | |
| 3809 | ========================================================================== */ |
| 3810 | OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp, |
| 3811 | OMX_IN OMX_STRING paramName, |
| 3812 | OMX_OUT OMX_INDEXTYPE* indexType) |
| 3813 | { |
| 3814 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3815 | DEBUG_PRINT_ERROR("Get Extension Index in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3816 | return OMX_ErrorInvalidState; |
| 3817 | } else if (!strncmp(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode",sizeof("OMX.QCOM.index.param.video.SyncFrameDecodingMode") - 1)) { |
| 3818 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode; |
| 3819 | } else if (!strncmp(paramName, "OMX.QCOM.index.param.IndexExtraData",sizeof("OMX.QCOM.index.param.IndexExtraData") - 1)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3820 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType; |
| 3821 | } |
| 3822 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3823 | else if (!strncmp(paramName,"OMX.google.android.index.enableAndroidNativeBuffers", sizeof("OMX.google.android.index.enableAndroidNativeBuffers") - 1)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3824 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3825 | } else if (!strncmp(paramName,"OMX.google.android.index.useAndroidNativeBuffer2", sizeof("OMX.google.android.index.enableAndroidNativeBuffer2") - 1)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3826 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3827 | } else if (!strncmp(paramName,"OMX.google.android.index.useAndroidNativeBuffer", sizeof("OMX.google.android.index.enableAndroidNativeBuffer") - 1)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3828 | DEBUG_PRINT_ERROR("Extension: %s is supported", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3829 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3830 | } else if (!strncmp(paramName,"OMX.google.android.index.getAndroidNativeBufferUsage", sizeof("OMX.google.android.index.getAndroidNativeBufferUsage") - 1)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3831 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage; |
| 3832 | } |
| 3833 | #endif |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3834 | else if (!strncmp(paramName, "OMX.google.android.index.storeMetaDataInBuffers", sizeof("OMX.google.android.index.storeMetaDataInBuffers") - 1)) { |
| 3835 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode; |
| 3836 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3837 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3838 | DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3839 | return OMX_ErrorNotImplemented; |
| 3840 | } |
| 3841 | return OMX_ErrorNone; |
| 3842 | } |
| 3843 | |
| 3844 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3845 | FUNCTION |
| 3846 | omx_vdec::GetState |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3847 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3848 | DESCRIPTION |
| 3849 | Returns the state information back to the caller.<TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3850 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3851 | PARAMETERS |
| 3852 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3853 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3854 | RETURN VALUE |
| 3855 | Error None if everything is successful. |
| 3856 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3857 | OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3858 | OMX_OUT OMX_STATETYPE* state) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3859 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3860 | *state = m_state; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3861 | DEBUG_PRINT_LOW("get_state: Returning the state %d",*state); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3862 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3866 | FUNCTION |
| 3867 | omx_vdec::ComponentTunnelRequest |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3868 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3869 | DESCRIPTION |
| 3870 | OMX Component Tunnel Request method implementation. <TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3871 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3872 | PARAMETERS |
| 3873 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3874 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3875 | RETURN VALUE |
| 3876 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3877 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3878 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3879 | OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3880 | OMX_IN OMX_U32 port, |
| 3881 | OMX_IN OMX_HANDLETYPE peerComponent, |
| 3882 | OMX_IN OMX_U32 peerPort, |
| 3883 | OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3884 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3885 | DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3886 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3890 | FUNCTION |
| 3891 | omx_vdec::UseOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3892 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3893 | DESCRIPTION |
| 3894 | Helper function for Use buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3895 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3896 | PARAMETERS |
| 3897 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3898 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3899 | RETURN VALUE |
| 3900 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3901 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3902 | ========================================================================== */ |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 3903 | OMX_ERRORTYPE omx_vdec::allocate_extradata() |
| 3904 | { |
| 3905 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3906 | if (drv_ctx.extradata_info.buffer_size) { |
| 3907 | if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) { |
| 3908 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 3909 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 3910 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 3911 | } |
| 3912 | drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095); |
| 3913 | drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory( |
| 3914 | drv_ctx.extradata_info.size, 4096, |
| 3915 | &drv_ctx.extradata_info.ion.ion_alloc_data, |
| 3916 | &drv_ctx.extradata_info.ion.fd_ion_data, 0); |
| 3917 | if (drv_ctx.extradata_info.ion.ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3918 | DEBUG_PRINT_ERROR("Failed to alloc extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3919 | return OMX_ErrorInsufficientResources; |
| 3920 | } |
| 3921 | drv_ctx.extradata_info.uaddr = (char *)mmap(NULL, |
| 3922 | drv_ctx.extradata_info.size, |
| 3923 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 3924 | drv_ctx.extradata_info.ion.fd_ion_data.fd , 0); |
| 3925 | if (drv_ctx.extradata_info.uaddr == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3926 | DEBUG_PRINT_ERROR("Failed to map extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3927 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 3928 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 3929 | return OMX_ErrorInsufficientResources; |
| 3930 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 3931 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 3932 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3933 | return OMX_ErrorNone; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3936 | void omx_vdec::free_extradata() |
| 3937 | { |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 3938 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3939 | if (drv_ctx.extradata_info.uaddr) { |
| 3940 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 3941 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 3942 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 3943 | } |
| 3944 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 3945 | #endif |
| 3946 | } |
| 3947 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3948 | OMX_ERRORTYPE omx_vdec::use_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3949 | OMX_IN OMX_HANDLETYPE hComp, |
| 3950 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 3951 | OMX_IN OMX_U32 port, |
| 3952 | OMX_IN OMX_PTR appData, |
| 3953 | OMX_IN OMX_U32 bytes, |
| 3954 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3955 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3956 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 3957 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 3958 | unsigned i= 0; // Temporary counter |
| 3959 | struct vdec_setbuffer_cmd setbuffers; |
| 3960 | OMX_PTR privateAppData = NULL; |
| 3961 | private_handle_t *handle = NULL; |
| 3962 | OMX_U8 *buff = buffer; |
| 3963 | struct v4l2_buffer buf; |
| 3964 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 3965 | int extra_idx = 0; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 3966 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3967 | if (!m_out_mem_ptr) { |
| 3968 | DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers"); |
| 3969 | eRet = allocate_output_headers(); |
| 3970 | if (eRet == OMX_ErrorNone) |
| 3971 | eRet = allocate_extradata(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3972 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3973 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3974 | if (eRet == OMX_ErrorNone) { |
| 3975 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 3976 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
| 3977 | break; |
| 3978 | } |
| 3979 | } |
| 3980 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3981 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3982 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3983 | DEBUG_PRINT_ERROR("Already using %d o/p buffers", drv_ctx.op_buf.actualcount); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3984 | eRet = OMX_ErrorInsufficientResources; |
| 3985 | } |
| 3986 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 3987 | if (dynamic_buf_mode) { |
| 3988 | *bufferHdr = (m_out_mem_ptr + i ); |
| 3989 | (*bufferHdr)->pBuffer = NULL; |
| 3990 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 3991 | enum v4l2_buf_type buf_type; |
| 3992 | int rr = 0; |
| 3993 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3994 | if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 3995 | DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr); |
| 3996 | return OMX_ErrorInsufficientResources; |
| 3997 | } else { |
| 3998 | streaming[CAPTURE_PORT] = true; |
| 3999 | DEBUG_PRINT_LOW("STREAMON Successful"); |
| 4000 | } |
| 4001 | } |
| 4002 | BITMASK_SET(&m_out_bm_count,i); |
| 4003 | (*bufferHdr)->pAppPrivate = appData; |
| 4004 | (*bufferHdr)->pBuffer = buffer; |
| 4005 | (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 4006 | return eRet; |
| 4007 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4008 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4009 | #if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4010 | if (m_enable_android_native_buffers) { |
| 4011 | if (m_use_android_native_buffers) { |
| 4012 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData; |
| 4013 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 4014 | handle = (private_handle_t *)nBuf->handle; |
| 4015 | privateAppData = params->pAppPrivate; |
| 4016 | } else { |
| 4017 | handle = (private_handle_t *)buff; |
| 4018 | privateAppData = appData; |
| 4019 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4020 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4021 | if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) { |
| 4022 | DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback," |
| 4023 | " expected %u, got %lu", |
| 4024 | drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size); |
| 4025 | return OMX_ErrorBadParameter; |
| 4026 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4027 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4028 | if (!m_use_android_native_buffers) { |
| 4029 | if (!secure_mode) { |
| 4030 | buff = (OMX_U8*)mmap(0, handle->size, |
| 4031 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
| 4032 | if (buff == MAP_FAILED) { |
| 4033 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 4034 | return OMX_ErrorInsufficientResources; |
| 4035 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4036 | } |
| 4037 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4038 | #if defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4039 | native_buffer[i].nativehandle = handle; |
| 4040 | native_buffer[i].privatehandle = handle; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4041 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4042 | if (!handle) { |
| 4043 | DEBUG_PRINT_ERROR("Native Buffer handle is NULL"); |
| 4044 | return OMX_ErrorBadParameter; |
| 4045 | } |
| 4046 | drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd; |
| 4047 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4048 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4049 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4050 | drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size; |
| 4051 | } else |
| 4052 | #endif |
| 4053 | |
| 4054 | if (!ouput_egl_buffers && !m_use_output_pmem) { |
| 4055 | #ifdef USE_ION |
| 4056 | drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 4057 | drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 4058 | &drv_ctx.op_buf_ion_info[i].ion_alloc_data, |
| 4059 | &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4060 | if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4061 | DEBUG_PRINT_ERROR("ION device fd is bad %d", drv_ctx.op_buf_ion_info[i].ion_device_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4062 | return OMX_ErrorInsufficientResources; |
| 4063 | } |
| 4064 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4065 | drv_ctx.op_buf_ion_info[i].fd_ion_data.fd; |
| 4066 | #else |
| 4067 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4068 | open (MEM_DEVICE,O_RDWR); |
| 4069 | |
| 4070 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4071 | DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4072 | return OMX_ErrorInsufficientResources; |
| 4073 | } |
| 4074 | |
| 4075 | /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */ |
| 4076 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) { |
| 4077 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4078 | open (MEM_DEVICE,O_RDWR); |
| 4079 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4080 | DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4081 | return OMX_ErrorInsufficientResources; |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd, |
| 4086 | drv_ctx.op_buf.buffer_size, |
| 4087 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4088 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4089 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4090 | return OMX_ErrorInsufficientResources; |
| 4091 | } |
| 4092 | #endif |
| 4093 | if (!secure_mode) { |
| 4094 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 4095 | (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size, |
| 4096 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4097 | drv_ctx.ptr_outputbuffer[i].pmem_fd,0); |
| 4098 | if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) { |
| 4099 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4100 | #ifdef USE_ION |
| 4101 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
| 4102 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4103 | DEBUG_PRINT_ERROR("Unable to mmap output buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4104 | return OMX_ErrorInsufficientResources; |
| 4105 | } |
| 4106 | } |
| 4107 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4108 | privateAppData = appData; |
| 4109 | } else { |
| 4110 | |
| 4111 | DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem); |
| 4112 | if (!appData || !bytes ) { |
| 4113 | if (!secure_mode && !buffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4114 | DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4115 | return OMX_ErrorBadParameter; |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list; |
| 4120 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info; |
| 4121 | pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData; |
| 4122 | if (!pmem_list->entryList || !pmem_list->entryList->entry || |
| 4123 | !pmem_list->nEntries || |
| 4124 | pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4125 | DEBUG_PRINT_ERROR("Pmem info not valid in use buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4126 | return OMX_ErrorBadParameter; |
| 4127 | } |
| 4128 | pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 4129 | pmem_list->entryList->entry; |
| 4130 | DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx", |
| 4131 | pmem_info->pmem_fd); |
| 4132 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd; |
| 4133 | drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset; |
| 4134 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4135 | drv_ctx.ptr_outputbuffer[i].mmaped_size = |
| 4136 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4137 | privateAppData = appData; |
| 4138 | } |
| 4139 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 4140 | m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
| 4141 | |
| 4142 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4143 | if (secure_mode) |
| 4144 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 4145 | //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4146 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i], |
| 4147 | sizeof (vdec_bufferpayload)); |
| 4148 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4149 | DEBUG_PRINT_HIGH("Set the Output Buffer Idx: %d Addr: %p, pmem_fd=0x%x", i, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4150 | drv_ctx.ptr_outputbuffer[i].bufferaddr, |
| 4151 | drv_ctx.ptr_outputbuffer[i].pmem_fd ); |
| 4152 | |
| 4153 | buf.index = i; |
| 4154 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4155 | buf.memory = V4L2_MEMORY_USERPTR; |
| 4156 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 4157 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 4158 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
| 4159 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
| 4160 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 4161 | plane[0].data_offset = 0; |
| 4162 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 4163 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 4164 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 4165 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
| 4166 | #ifdef USE_ION |
| 4167 | plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd; |
| 4168 | #endif |
| 4169 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 4170 | plane[extra_idx].data_offset = 0; |
| 4171 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4172 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4173 | return OMX_ErrorBadParameter; |
| 4174 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4175 | buf.m.planes = plane; |
| 4176 | buf.length = drv_ctx.num_planes; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4177 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4178 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4179 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4180 | /*TODO: How to handle this case */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4181 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4182 | } |
| 4183 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4184 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4185 | enum v4l2_buf_type buf_type; |
| 4186 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4187 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4188 | return OMX_ErrorInsufficientResources; |
| 4189 | } else { |
| 4190 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4191 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4192 | } |
| 4193 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4194 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4195 | (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size; |
| 4196 | if (m_enable_android_native_buffers) { |
| 4197 | DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle); |
| 4198 | (*bufferHdr)->pBuffer = (OMX_U8 *)handle; |
| 4199 | } else { |
| 4200 | (*bufferHdr)->pBuffer = buff; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4201 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4202 | (*bufferHdr)->pAppPrivate = privateAppData; |
| 4203 | BITMASK_SET(&m_out_bm_count,i); |
| 4204 | } |
| 4205 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4209 | FUNCTION |
| 4210 | omx_vdec::use_input_heap_buffers |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4211 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4212 | DESCRIPTION |
| 4213 | OMX Use Buffer Heap allocation method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4214 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4215 | PARAMETERS |
| 4216 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4217 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4218 | RETURN VALUE |
| 4219 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4220 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4221 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4222 | OMX_ERRORTYPE omx_vdec::use_input_heap_buffers( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4223 | OMX_IN OMX_HANDLETYPE hComp, |
| 4224 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4225 | OMX_IN OMX_U32 port, |
| 4226 | OMX_IN OMX_PTR appData, |
| 4227 | OMX_IN OMX_U32 bytes, |
| 4228 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4229 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4230 | DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4231 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4232 | if (!m_inp_heap_ptr) |
| 4233 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) |
| 4234 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4235 | drv_ctx.ip_buf.actualcount); |
| 4236 | if (!m_phdr_pmem_ptr) |
| 4237 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) |
| 4238 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4239 | drv_ctx.ip_buf.actualcount); |
| 4240 | if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) { |
| 4241 | DEBUG_PRINT_ERROR("Insufficent memory"); |
| 4242 | eRet = OMX_ErrorInsufficientResources; |
| 4243 | } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) { |
| 4244 | input_use_buffer = true; |
| 4245 | memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE)); |
| 4246 | m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer; |
| 4247 | m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes; |
| 4248 | m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData; |
| 4249 | m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput; |
| 4250 | m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax; |
| 4251 | *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt]; |
| 4252 | eRet = allocate_input_buffer(hComp, &m_phdr_pmem_ptr[m_in_alloc_cnt], port, appData, bytes); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4253 | DEBUG_PRINT_HIGH("Heap buffer(%p) Pmem buffer(%p)", *bufferHdr, m_phdr_pmem_ptr[m_in_alloc_cnt]); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4254 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt], |
| 4255 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4256 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4257 | return OMX_ErrorInsufficientResources; |
| 4258 | } |
| 4259 | m_in_alloc_cnt++; |
| 4260 | } else { |
| 4261 | DEBUG_PRINT_ERROR("All i/p buffers have been set!"); |
| 4262 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4263 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4264 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4268 | FUNCTION |
| 4269 | omx_vdec::UseBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4270 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4271 | DESCRIPTION |
| 4272 | OMX Use Buffer method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4273 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4274 | PARAMETERS |
| 4275 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4276 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4277 | RETURN VALUE |
| 4278 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4279 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4280 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4281 | OMX_ERRORTYPE omx_vdec::use_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4282 | OMX_IN OMX_HANDLETYPE hComp, |
| 4283 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4284 | OMX_IN OMX_U32 port, |
| 4285 | OMX_IN OMX_PTR appData, |
| 4286 | OMX_IN OMX_U32 bytes, |
| 4287 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4288 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4289 | OMX_ERRORTYPE error = OMX_ErrorNone; |
| 4290 | struct vdec_setbuffer_cmd setbuffers; |
| 4291 | |
| 4292 | if (bufferHdr == NULL || bytes == 0) { |
| 4293 | if (!secure_mode && buffer == NULL) { |
| 4294 | DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer); |
| 4295 | return OMX_ErrorBadParameter; |
| 4296 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4297 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4298 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4299 | DEBUG_PRINT_ERROR("Use Buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4300 | return OMX_ErrorInvalidState; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4301 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4302 | if (port == OMX_CORE_INPUT_PORT_INDEX) |
| 4303 | error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer); |
| 4304 | else if (port == OMX_CORE_OUTPUT_PORT_INDEX) |
| 4305 | error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested |
| 4306 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4307 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4308 | error = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4309 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4310 | DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error); |
| 4311 | if (error == OMX_ErrorNone) { |
| 4312 | if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 4313 | // Send the callback now |
| 4314 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 4315 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
| 4316 | OMX_COMPONENT_GENERATE_EVENT); |
| 4317 | } |
| 4318 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated && |
| 4319 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 4320 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 4321 | post_event(OMX_CommandPortEnable, |
| 4322 | OMX_CORE_INPUT_PORT_INDEX, |
| 4323 | OMX_COMPONENT_GENERATE_EVENT); |
| 4324 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated && |
| 4325 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 4326 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 4327 | post_event(OMX_CommandPortEnable, |
| 4328 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 4329 | OMX_COMPONENT_GENERATE_EVENT); |
| 4330 | } |
| 4331 | } |
| 4332 | return error; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4336 | OMX_BUFFERHEADERTYPE *pmem_bufferHdr) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4337 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4338 | if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) { |
| 4339 | if (m_inp_heap_ptr[bufferindex].pBuffer) |
| 4340 | free(m_inp_heap_ptr[bufferindex].pBuffer); |
| 4341 | m_inp_heap_ptr[bufferindex].pBuffer = NULL; |
| 4342 | } |
| 4343 | if (pmem_bufferHdr) |
| 4344 | free_input_buffer(pmem_bufferHdr); |
| 4345 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4349 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4350 | unsigned int index = 0; |
| 4351 | if (bufferHdr == NULL || m_inp_mem_ptr == NULL) { |
| 4352 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4353 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4354 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4355 | index = bufferHdr - m_inp_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4356 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4357 | |
| 4358 | if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4359 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4360 | if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) { |
| 4361 | struct vdec_setbuffer_cmd setbuffers; |
| 4362 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 4363 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index], |
| 4364 | sizeof (vdec_bufferpayload)); |
| 4365 | if (!secure_mode) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4366 | DEBUG_PRINT_LOW("unmap the input buffer fd=%d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4367 | drv_ctx.ptr_inputbuffer[index].pmem_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4368 | DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4369 | drv_ctx.ptr_inputbuffer[index].mmaped_size, |
| 4370 | drv_ctx.ptr_inputbuffer[index].bufferaddr); |
| 4371 | munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr, |
| 4372 | drv_ctx.ptr_inputbuffer[index].mmaped_size); |
| 4373 | } |
| 4374 | close (drv_ctx.ptr_inputbuffer[index].pmem_fd); |
| 4375 | drv_ctx.ptr_inputbuffer[index].pmem_fd = -1; |
| 4376 | if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) { |
| 4377 | free(m_desc_buffer_ptr[index].buf_addr); |
| 4378 | m_desc_buffer_ptr[index].buf_addr = NULL; |
| 4379 | m_desc_buffer_ptr[index].desc_data_size = 0; |
| 4380 | } |
| 4381 | #ifdef USE_ION |
| 4382 | free_ion_memory(&drv_ctx.ip_buf_ion_info[index]); |
| 4383 | #endif |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4391 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4392 | unsigned int index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4393 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4394 | if (bufferHdr == NULL || m_out_mem_ptr == NULL) { |
| 4395 | return OMX_ErrorBadParameter; |
| 4396 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4397 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4398 | index = bufferHdr - m_out_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4399 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4400 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4401 | if (index < drv_ctx.op_buf.actualcount |
| 4402 | && drv_ctx.ptr_outputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4403 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4404 | drv_ctx.ptr_outputbuffer[index].bufferaddr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4405 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4406 | struct vdec_setbuffer_cmd setbuffers; |
| 4407 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4408 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index], |
| 4409 | sizeof (vdec_bufferpayload)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4410 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4411 | if (m_enable_android_native_buffers) { |
Praveen Chavan | 212671f | 2013-04-05 20:00:42 -0700 | [diff] [blame] | 4412 | if (!secure_mode) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4413 | if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) { |
| 4414 | munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr, |
| 4415 | drv_ctx.ptr_outputbuffer[index].mmaped_size); |
| 4416 | } |
Praveen Chavan | 212671f | 2013-04-05 20:00:42 -0700 | [diff] [blame] | 4417 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4418 | drv_ctx.ptr_outputbuffer[index].pmem_fd = -1; |
| 4419 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4420 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4421 | if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) { |
| 4422 | if (!secure_mode) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4423 | DEBUG_PRINT_LOW("unmap the output buffer fd = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4424 | drv_ctx.ptr_outputbuffer[0].pmem_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4425 | DEBUG_PRINT_LOW("unmap the ouput buffer size=%d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4426 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount, |
| 4427 | drv_ctx.ptr_outputbuffer[0].bufferaddr); |
| 4428 | munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr, |
| 4429 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount); |
| 4430 | } |
| 4431 | close (drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4432 | drv_ctx.ptr_outputbuffer[0].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4433 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4434 | free_ion_memory(&drv_ctx.op_buf_ion_info[0]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4435 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4436 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4437 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4438 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4439 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4440 | if (release_output_done()) { |
| 4441 | free_extradata(); |
| 4442 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4443 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4444 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4445 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4446 | |
| 4447 | } |
| 4448 | |
| 4449 | OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4450 | OMX_BUFFERHEADERTYPE **bufferHdr, |
| 4451 | OMX_U32 port, |
| 4452 | OMX_PTR appData, |
| 4453 | OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4454 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4455 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4456 | unsigned char *buf_addr = NULL; |
| 4457 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4458 | unsigned i = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4459 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4460 | /* Sanity Check*/ |
| 4461 | if (bufferHdr == NULL) { |
| 4462 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4463 | } |
| 4464 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4465 | if (m_inp_heap_ptr == NULL) { |
| 4466 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4467 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4468 | drv_ctx.ip_buf.actualcount); |
| 4469 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \ |
| 4470 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4471 | drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4472 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4473 | if (m_inp_heap_ptr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4474 | DEBUG_PRINT_ERROR("m_inp_heap_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4475 | return OMX_ErrorInsufficientResources; |
| 4476 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4477 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4478 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4479 | /*Find a Free index*/ |
| 4480 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 4481 | if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4482 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4483 | break; |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | if (i < drv_ctx.ip_buf.actualcount) { |
| 4488 | buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size); |
| 4489 | |
| 4490 | if (buf_addr == NULL) { |
| 4491 | return OMX_ErrorInsufficientResources; |
| 4492 | } |
| 4493 | |
| 4494 | *bufferHdr = (m_inp_heap_ptr + i); |
| 4495 | input = *bufferHdr; |
| 4496 | BITMASK_SET(&m_heap_inp_bm_count,i); |
| 4497 | |
| 4498 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 4499 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 4500 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 4501 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 4502 | input->pAppPrivate = appData; |
| 4503 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4504 | DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4505 | eRet = allocate_input_buffer(hComp,&m_phdr_pmem_ptr [i],port,appData,bytes); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4506 | DEBUG_PRINT_LOW("Address of Pmem Buffer %p",m_phdr_pmem_ptr[i]); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4507 | /*Add the Buffers to freeq*/ |
| 4508 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i], |
| 4509 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4510 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4511 | return OMX_ErrorInsufficientResources; |
| 4512 | } |
| 4513 | } else { |
| 4514 | return OMX_ErrorBadParameter; |
| 4515 | } |
| 4516 | |
| 4517 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4518 | |
| 4519 | } |
| 4520 | |
| 4521 | |
| 4522 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4523 | FUNCTION |
| 4524 | omx_vdec::AllocateInputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4525 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4526 | DESCRIPTION |
| 4527 | Helper function for allocate buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4528 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4529 | PARAMETERS |
| 4530 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4531 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4532 | RETURN VALUE |
| 4533 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4534 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4535 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4536 | OMX_ERRORTYPE omx_vdec::allocate_input_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4537 | OMX_IN OMX_HANDLETYPE hComp, |
| 4538 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4539 | OMX_IN OMX_U32 port, |
| 4540 | OMX_IN OMX_PTR appData, |
| 4541 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4542 | { |
| 4543 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4544 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4545 | struct vdec_setbuffer_cmd setbuffers; |
| 4546 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4547 | unsigned i = 0; |
| 4548 | unsigned char *buf_addr = NULL; |
| 4549 | int pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4550 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4551 | if (bytes != drv_ctx.ip_buf.buffer_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4552 | DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4553 | bytes, drv_ctx.ip_buf.buffer_size); |
| 4554 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4555 | } |
| 4556 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4557 | if (!m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4558 | DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4559 | drv_ctx.ip_buf.actualcount, |
| 4560 | drv_ctx.ip_buf.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4561 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4562 | m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4563 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount); |
| 4564 | |
| 4565 | if (m_inp_mem_ptr == NULL) { |
| 4566 | return OMX_ErrorInsufficientResources; |
| 4567 | } |
| 4568 | |
| 4569 | drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \ |
| 4570 | calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount); |
| 4571 | |
| 4572 | if (drv_ctx.ptr_inputbuffer == NULL) { |
| 4573 | return OMX_ErrorInsufficientResources; |
| 4574 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4575 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4576 | drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \ |
| 4577 | calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4578 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4579 | if (drv_ctx.ip_buf_ion_info == NULL) { |
| 4580 | return OMX_ErrorInsufficientResources; |
| 4581 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4582 | #endif |
| 4583 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4584 | for (i=0; i < drv_ctx.ip_buf.actualcount; i++) { |
| 4585 | drv_ctx.ptr_inputbuffer [i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4586 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4587 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4588 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4589 | } |
| 4590 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4591 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4592 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 4593 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4594 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4595 | break; |
| 4596 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4597 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4598 | |
| 4599 | if (i < drv_ctx.ip_buf.actualcount) { |
| 4600 | struct v4l2_buffer buf; |
| 4601 | struct v4l2_plane plane; |
| 4602 | int rc; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4603 | DEBUG_PRINT_LOW("Allocate input Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4604 | #ifdef USE_ION |
| 4605 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 4606 | drv_ctx.ip_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 4607 | &drv_ctx.ip_buf_ion_info[i].ion_alloc_data, |
| 4608 | &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4609 | if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) { |
| 4610 | return OMX_ErrorInsufficientResources; |
| 4611 | } |
| 4612 | pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd; |
| 4613 | #else |
| 4614 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 4615 | |
| 4616 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4617 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4618 | return OMX_ErrorInsufficientResources; |
| 4619 | } |
| 4620 | |
| 4621 | if (pmem_fd == 0) { |
| 4622 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 4623 | |
| 4624 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4625 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4626 | return OMX_ErrorInsufficientResources; |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size, |
| 4631 | drv_ctx.ip_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4632 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4633 | close(pmem_fd); |
| 4634 | return OMX_ErrorInsufficientResources; |
| 4635 | } |
| 4636 | #endif |
| 4637 | if (!secure_mode) { |
| 4638 | buf_addr = (unsigned char *)mmap(NULL, |
| 4639 | drv_ctx.ip_buf.buffer_size, |
| 4640 | PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0); |
| 4641 | |
| 4642 | if (buf_addr == MAP_FAILED) { |
| 4643 | close(pmem_fd); |
| 4644 | #ifdef USE_ION |
| 4645 | free_ion_memory(&drv_ctx.ip_buf_ion_info[i]); |
| 4646 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4647 | DEBUG_PRINT_ERROR("Map Failed to allocate input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4648 | return OMX_ErrorInsufficientResources; |
| 4649 | } |
| 4650 | } |
| 4651 | *bufferHdr = (m_inp_mem_ptr + i); |
| 4652 | if (secure_mode) |
| 4653 | drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr; |
| 4654 | else |
| 4655 | drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr; |
| 4656 | drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd; |
| 4657 | drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size; |
| 4658 | drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size; |
| 4659 | drv_ctx.ptr_inputbuffer [i].offset = 0; |
| 4660 | |
| 4661 | |
| 4662 | buf.index = i; |
| 4663 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 4664 | buf.memory = V4L2_MEMORY_USERPTR; |
| 4665 | plane.bytesused = 0; |
| 4666 | plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size; |
| 4667 | plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr; |
| 4668 | plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 4669 | plane.reserved[1] = 0; |
| 4670 | plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset; |
| 4671 | buf.m.planes = &plane; |
| 4672 | buf.length = 1; |
| 4673 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4674 | DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4675 | drv_ctx.ptr_inputbuffer[i].bufferaddr); |
| 4676 | |
| 4677 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 4678 | |
| 4679 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4680 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4681 | /*TODO: How to handle this case */ |
| 4682 | return OMX_ErrorInsufficientResources; |
| 4683 | } |
| 4684 | |
| 4685 | input = *bufferHdr; |
| 4686 | BITMASK_SET(&m_inp_bm_count,i); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4687 | DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4688 | if (secure_mode) |
| 4689 | input->pBuffer = (OMX_U8 *)drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 4690 | else |
| 4691 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 4692 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 4693 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 4694 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 4695 | input->pAppPrivate = appData; |
| 4696 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
| 4697 | input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i]; |
| 4698 | |
| 4699 | if (drv_ctx.disable_dmx) { |
| 4700 | eRet = allocate_desc_buffer(i); |
| 4701 | } |
| 4702 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4703 | DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4704 | eRet = OMX_ErrorInsufficientResources; |
| 4705 | } |
| 4706 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | |
| 4710 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4711 | FUNCTION |
| 4712 | omx_vdec::AllocateOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4713 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4714 | DESCRIPTION |
| 4715 | Helper fn for AllocateBuffer in the output pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4716 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4717 | PARAMETERS |
| 4718 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4719 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4720 | RETURN VALUE |
| 4721 | OMX Error None if everything went well. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4722 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4723 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4724 | OMX_ERRORTYPE omx_vdec::allocate_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4725 | OMX_IN OMX_HANDLETYPE hComp, |
| 4726 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4727 | OMX_IN OMX_U32 port, |
| 4728 | OMX_IN OMX_PTR appData, |
| 4729 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4730 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4731 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4732 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 4733 | unsigned i= 0; // Temporary counter |
| 4734 | struct vdec_setbuffer_cmd setbuffers; |
| 4735 | int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4736 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4737 | int ion_device_fd =-1; |
| 4738 | struct ion_allocation_data ion_alloc_data; |
| 4739 | struct ion_fd_data fd_ion_data; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4740 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4741 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4742 | DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4743 | drv_ctx.op_buf.actualcount, |
| 4744 | drv_ctx.op_buf.buffer_size); |
| 4745 | int nBufHdrSize = 0; |
| 4746 | int nPlatformEntrySize = 0; |
| 4747 | int nPlatformListSize = 0; |
| 4748 | int nPMEMInfoSize = 0; |
| 4749 | int pmem_fd = -1; |
| 4750 | unsigned char *pmem_baseaddress = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4751 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4752 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 4753 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 4754 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4755 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4756 | DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4757 | drv_ctx.op_buf.actualcount); |
| 4758 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 4759 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4760 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4761 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 4762 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 4763 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 4764 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 4765 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 4766 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4767 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4768 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4769 | sizeof(OMX_BUFFERHEADERTYPE), |
| 4770 | nPMEMInfoSize, |
| 4771 | nPlatformListSize); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4772 | DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4773 | drv_ctx.op_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4774 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4775 | ion_device_fd = alloc_map_ion_memory( |
| 4776 | drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount, |
| 4777 | drv_ctx.op_buf.alignment, |
| 4778 | &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4779 | if (ion_device_fd < 0) { |
| 4780 | return OMX_ErrorInsufficientResources; |
| 4781 | } |
| 4782 | pmem_fd = fd_ion_data.fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4783 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4784 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4785 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4786 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4787 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4788 | drv_ctx.op_buf.buffer_size); |
| 4789 | return OMX_ErrorInsufficientResources; |
| 4790 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4791 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4792 | if (pmem_fd == 0) { |
| 4793 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4794 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4795 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4796 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4797 | drv_ctx.op_buf.buffer_size); |
| 4798 | return OMX_ErrorInsufficientResources; |
| 4799 | } |
| 4800 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4801 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4802 | if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size * |
| 4803 | drv_ctx.op_buf.actualcount, |
| 4804 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4805 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4806 | close(pmem_fd); |
| 4807 | return OMX_ErrorInsufficientResources; |
| 4808 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4809 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4810 | if (!secure_mode) { |
| 4811 | pmem_baseaddress = (unsigned char *)mmap(NULL, |
| 4812 | (drv_ctx.op_buf.buffer_size * |
| 4813 | drv_ctx.op_buf.actualcount), |
| 4814 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0); |
| 4815 | if (pmem_baseaddress == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4816 | DEBUG_PRINT_ERROR("MMAP failed for Size %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4817 | drv_ctx.op_buf.buffer_size); |
| 4818 | close(pmem_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4819 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4820 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4821 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4822 | return OMX_ErrorInsufficientResources; |
| 4823 | } |
| 4824 | } |
| 4825 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 4826 | // Alloc mem for platform specific info |
| 4827 | char *pPtr=NULL; |
| 4828 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 4829 | nPMEMInfoSize,1); |
| 4830 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\ |
| 4831 | calloc (sizeof(struct vdec_bufferpayload), |
| 4832 | drv_ctx.op_buf.actualcount); |
| 4833 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 4834 | calloc (sizeof (struct vdec_output_frameinfo), |
| 4835 | drv_ctx.op_buf.actualcount); |
| 4836 | #ifdef USE_ION |
| 4837 | drv_ctx.op_buf_ion_info = (struct vdec_ion *)\ |
| 4838 | calloc (sizeof(struct vdec_ion), |
| 4839 | drv_ctx.op_buf.actualcount); |
| 4840 | #endif |
| 4841 | |
| 4842 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 4843 | && drv_ctx.ptr_respbuffer) { |
| 4844 | drv_ctx.ptr_outputbuffer[0].mmaped_size = |
| 4845 | (drv_ctx.op_buf.buffer_size * |
| 4846 | drv_ctx.op_buf.actualcount); |
| 4847 | bufHdr = m_out_mem_ptr; |
| 4848 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 4849 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 4850 | (((char *) m_platform_list) + nPlatformListSize); |
| 4851 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 4852 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 4853 | pPlatformList = m_platform_list; |
| 4854 | pPlatformEntry = m_platform_entry; |
| 4855 | pPMEMInfo = m_pmem_info; |
| 4856 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4857 | DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4858 | |
| 4859 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4860 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry); |
| 4861 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4862 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 4863 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 4864 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 4865 | // Set the values when we determine the right HxW param |
| 4866 | bufHdr->nAllocLen = bytes; |
| 4867 | bufHdr->nFilledLen = 0; |
| 4868 | bufHdr->pAppPrivate = appData; |
| 4869 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 4870 | // Platform specific PMEM Information |
| 4871 | // Initialize the Platform Entry |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4872 | //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4873 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 4874 | pPlatformEntry->entry = pPMEMInfo; |
| 4875 | // Initialize the Platform List |
| 4876 | pPlatformList->nEntries = 1; |
| 4877 | pPlatformList->entryList = pPlatformEntry; |
| 4878 | // Keep pBuffer NULL till vdec is opened |
| 4879 | bufHdr->pBuffer = NULL; |
| 4880 | bufHdr->nOffset = 0; |
| 4881 | |
| 4882 | pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i; |
| 4883 | pPMEMInfo->pmem_fd = 0; |
| 4884 | bufHdr->pPlatformPrivate = pPlatformList; |
| 4885 | |
| 4886 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd; |
| 4887 | m_pmem_info[i].pmem_fd = pmem_fd; |
| 4888 | #ifdef USE_ION |
| 4889 | drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd; |
| 4890 | drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data; |
| 4891 | drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data; |
| 4892 | #endif |
| 4893 | |
| 4894 | /*Create a mapping between buffers*/ |
| 4895 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 4896 | drv_ctx.ptr_respbuffer[i].client_data = (void *)\ |
| 4897 | &drv_ctx.ptr_outputbuffer[i]; |
| 4898 | drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i; |
| 4899 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 4900 | pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i); |
| 4901 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4902 | DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4903 | pmem_fd, drv_ctx.ptr_outputbuffer[i].offset, |
| 4904 | drv_ctx.ptr_outputbuffer[i].bufferaddr); |
| 4905 | // Move the buffer and buffer header pointers |
| 4906 | bufHdr++; |
| 4907 | pPMEMInfo++; |
| 4908 | pPlatformEntry++; |
| 4909 | pPlatformList++; |
| 4910 | } |
| 4911 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4912 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4913 | m_out_mem_ptr, pPtr); |
| 4914 | if (m_out_mem_ptr) { |
| 4915 | free(m_out_mem_ptr); |
| 4916 | m_out_mem_ptr = NULL; |
| 4917 | } |
| 4918 | if (pPtr) { |
| 4919 | free(pPtr); |
| 4920 | pPtr = NULL; |
| 4921 | } |
| 4922 | if (drv_ctx.ptr_outputbuffer) { |
| 4923 | free(drv_ctx.ptr_outputbuffer); |
| 4924 | drv_ctx.ptr_outputbuffer = NULL; |
| 4925 | } |
| 4926 | if (drv_ctx.ptr_respbuffer) { |
| 4927 | free(drv_ctx.ptr_respbuffer); |
| 4928 | drv_ctx.ptr_respbuffer = NULL; |
| 4929 | } |
| 4930 | #ifdef USE_ION |
| 4931 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4932 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4933 | free(drv_ctx.op_buf_ion_info); |
| 4934 | drv_ctx.op_buf_ion_info = NULL; |
| 4935 | } |
| 4936 | #endif |
| 4937 | eRet = OMX_ErrorInsufficientResources; |
| 4938 | } |
| 4939 | if (eRet == OMX_ErrorNone) |
| 4940 | eRet = allocate_extradata(); |
| 4941 | } |
| 4942 | |
| 4943 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 4944 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4945 | DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4946 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4947 | } |
| 4948 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4949 | |
| 4950 | if (eRet == OMX_ErrorNone) { |
| 4951 | if (i < drv_ctx.op_buf.actualcount) { |
| 4952 | struct v4l2_buffer buf; |
| 4953 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 4954 | int rc; |
| 4955 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 4956 | |
| 4957 | drv_ctx.ptr_outputbuffer[i].buffer_len = |
| 4958 | drv_ctx.op_buf.buffer_size; |
| 4959 | |
| 4960 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4961 | if (secure_mode) { |
| 4962 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 4963 | } |
| 4964 | drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 4965 | |
| 4966 | buf.index = i; |
| 4967 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4968 | buf.memory = V4L2_MEMORY_USERPTR; |
| 4969 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 4970 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 4971 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4972 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4973 | plane[0].reserved[0] = drv_ctx.op_buf_ion_info[i].fd_ion_data.fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4974 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4975 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 4976 | plane[0].data_offset = 0; |
| 4977 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 4978 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 4979 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 4980 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4981 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4982 | plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4983 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4984 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 4985 | plane[extra_idx].data_offset = 0; |
| 4986 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4987 | DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4988 | return OMX_ErrorBadParameter; |
| 4989 | } |
| 4990 | buf.m.planes = plane; |
| 4991 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4992 | DEBUG_PRINT_LOW("Set the Output Buffer Idx: %d Addr: %p", i, drv_ctx.ptr_outputbuffer[i].bufferaddr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4993 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 4994 | if (rc) { |
| 4995 | /*TODO: How to handle this case */ |
| 4996 | return OMX_ErrorInsufficientResources; |
| 4997 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4998 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4999 | if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) { |
| 5000 | enum v4l2_buf_type buf_type; |
| 5001 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5002 | rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5003 | if (rc) { |
| 5004 | return OMX_ErrorInsufficientResources; |
| 5005 | } else { |
| 5006 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5007 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5008 | } |
| 5009 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5010 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5011 | (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr; |
| 5012 | (*bufferHdr)->pAppPrivate = appData; |
| 5013 | BITMASK_SET(&m_out_bm_count,i); |
| 5014 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5015 | DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5016 | eRet = OMX_ErrorInsufficientResources; |
| 5017 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5018 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5019 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5020 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | |
| 5024 | // AllocateBuffer -- API Call |
| 5025 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5026 | FUNCTION |
| 5027 | omx_vdec::AllocateBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5028 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5029 | DESCRIPTION |
| 5030 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5031 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5032 | PARAMETERS |
| 5033 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5034 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5035 | RETURN VALUE |
| 5036 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5037 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5038 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5039 | OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5040 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5041 | OMX_IN OMX_U32 port, |
| 5042 | OMX_IN OMX_PTR appData, |
| 5043 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5044 | { |
| 5045 | unsigned i = 0; |
| 5046 | OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type |
| 5047 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5048 | DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5049 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5050 | DEBUG_PRINT_ERROR("Allocate Buf in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5051 | return OMX_ErrorInvalidState; |
| 5052 | } |
| 5053 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5054 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5055 | if (arbitrary_bytes) { |
| 5056 | eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes); |
| 5057 | } else { |
| 5058 | eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes); |
| 5059 | } |
| 5060 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5061 | eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port, |
| 5062 | appData,bytes); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5063 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5064 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5065 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5066 | } |
| 5067 | DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5068 | if (eRet == OMX_ErrorNone) { |
| 5069 | if (allocate_done()) { |
| 5070 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5071 | // Send the callback now |
| 5072 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 5073 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5074 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5075 | } |
| 5076 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5077 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) { |
| 5078 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 5079 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 5080 | post_event(OMX_CommandPortEnable, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5081 | OMX_CORE_INPUT_PORT_INDEX, |
| 5082 | OMX_COMPONENT_GENERATE_EVENT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5083 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5084 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5085 | if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) { |
| 5086 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 5087 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5088 | post_event(OMX_CommandPortEnable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5089 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5090 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5091 | } |
| 5092 | } |
| 5093 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5094 | DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5095 | return eRet; |
| 5096 | } |
| 5097 | |
| 5098 | // Free Buffer - API call |
| 5099 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5100 | FUNCTION |
| 5101 | omx_vdec::FreeBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5102 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5103 | DESCRIPTION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5104 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5105 | PARAMETERS |
| 5106 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5107 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5108 | RETURN VALUE |
| 5109 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5110 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5111 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5112 | OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5113 | OMX_IN OMX_U32 port, |
| 5114 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5115 | { |
| 5116 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5117 | unsigned int nPortIndex; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5118 | DEBUG_PRINT_LOW("In for decoder free_buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5119 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5120 | if (m_state == OMX_StateIdle && |
| 5121 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5122 | DEBUG_PRINT_LOW(" free buffer while Component in Loading pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5123 | } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)|| |
| 5124 | (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5125 | DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5126 | } else if ((port == OMX_CORE_INPUT_PORT_INDEX && |
| 5127 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) || |
| 5128 | (port == OMX_CORE_OUTPUT_PORT_INDEX && |
| 5129 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5130 | DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5131 | } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5132 | DEBUG_PRINT_ERROR("Invalid state to free buffer,ports need to be disabled"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5133 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5134 | OMX_ErrorPortUnpopulated, |
| 5135 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5136 | |
| 5137 | return OMX_ErrorIncorrectStateOperation; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5138 | } else if (m_state != OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5139 | DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5140 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5141 | OMX_ErrorPortUnpopulated, |
| 5142 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5145 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5146 | /*Check if arbitrary bytes*/ |
| 5147 | if (!arbitrary_bytes && !input_use_buffer) |
| 5148 | nPortIndex = buffer - m_inp_mem_ptr; |
| 5149 | else |
| 5150 | nPortIndex = buffer - m_inp_heap_ptr; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5151 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5152 | DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %d", nPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5153 | if (nPortIndex < drv_ctx.ip_buf.actualcount) { |
| 5154 | // Clear the bit associated with it. |
| 5155 | BITMASK_CLEAR(&m_inp_bm_count,nPortIndex); |
| 5156 | BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex); |
| 5157 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5158 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5159 | DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5160 | if (m_phdr_pmem_ptr) |
| 5161 | free_input_buffer(m_phdr_pmem_ptr[nPortIndex]); |
| 5162 | } else { |
| 5163 | if (arbitrary_bytes) { |
| 5164 | if (m_phdr_pmem_ptr) |
| 5165 | free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]); |
| 5166 | else |
| 5167 | free_input_buffer(nPortIndex,NULL); |
| 5168 | } else |
| 5169 | free_input_buffer(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5170 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5171 | m_inp_bPopulated = OMX_FALSE; |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5172 | if(release_input_done()) |
| 5173 | release_buffers(this, VDEC_BUFFER_TYPE_INPUT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5174 | /*Free the Buffer Header*/ |
| 5175 | if (release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5176 | DEBUG_PRINT_HIGH("ALL input buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5177 | free_input_buffer_header(); |
| 5178 | } |
| 5179 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5180 | DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5181 | eRet = OMX_ErrorBadPortIndex; |
| 5182 | } |
| 5183 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5184 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING) |
| 5185 | && release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5186 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5187 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 5188 | post_event(OMX_CommandPortDisable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5189 | OMX_CORE_INPUT_PORT_INDEX, |
| 5190 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5191 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5192 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5193 | // check if the buffer is valid |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5194 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5195 | if (nPortIndex < drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5196 | DEBUG_PRINT_LOW("free_buffer on o/p port - Port idx %d", nPortIndex); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5197 | // Clear the bit associated with it. |
| 5198 | BITMASK_CLEAR(&m_out_bm_count,nPortIndex); |
| 5199 | m_out_bPopulated = OMX_FALSE; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5200 | client_buffers.free_output_buffer (buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5201 | |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5202 | if(release_output_done()) { |
| 5203 | release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT); |
| 5204 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5205 | if (release_output_done()) { |
| 5206 | free_output_buffer_header(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5207 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5208 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5209 | DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5210 | eRet = OMX_ErrorBadPortIndex; |
| 5211 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5212 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING) |
| 5213 | && release_output_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5214 | DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5215 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5216 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5217 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5218 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5219 | if (m_enable_android_native_buffers) { |
| 5220 | DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers"); |
| 5221 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 5222 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5223 | #endif |
| 5224 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5225 | post_event(OMX_CommandPortDisable, |
| 5226 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5227 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5228 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5229 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5230 | eRet = OMX_ErrorBadPortIndex; |
| 5231 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5232 | if ((eRet == OMX_ErrorNone) && |
| 5233 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
| 5234 | if (release_done()) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5235 | // Send the callback now |
| 5236 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING); |
| 5237 | post_event(OMX_CommandStateSet, OMX_StateLoaded, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5238 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5239 | } |
| 5240 | } |
| 5241 | return eRet; |
| 5242 | } |
| 5243 | |
| 5244 | |
| 5245 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5246 | FUNCTION |
| 5247 | omx_vdec::EmptyThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5248 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5249 | DESCRIPTION |
| 5250 | This routine is used to push the encoded video frames to |
| 5251 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5252 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5253 | PARAMETERS |
| 5254 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5255 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5256 | RETURN VALUE |
| 5257 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5258 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5259 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5260 | OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5261 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5262 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5263 | OMX_ERRORTYPE ret1 = OMX_ErrorNone; |
| 5264 | unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5265 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5266 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 5267 | codec_config_flag = true; |
| 5268 | DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__); |
| 5269 | } else { |
| 5270 | codec_config_flag = false; |
| 5271 | } |
Praneeth Paladugu | 80dd03b | 2013-05-22 16:57:42 -0700 | [diff] [blame] | 5272 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5273 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5274 | DEBUG_PRINT_ERROR("Empty this buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5275 | return OMX_ErrorInvalidState; |
| 5276 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5277 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5278 | if (buffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5279 | DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5280 | return OMX_ErrorBadParameter; |
| 5281 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5282 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5283 | if (!m_inp_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5284 | DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5285 | return OMX_ErrorIncorrectStateOperation; |
| 5286 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5287 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5288 | if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5289 | DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5290 | return OMX_ErrorBadPortIndex; |
| 5291 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5292 | |
| 5293 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5294 | if (iDivXDrmDecrypt) { |
| 5295 | OMX_ERRORTYPE drmErr = iDivXDrmDecrypt->Decrypt(buffer); |
| 5296 | if (drmErr != OMX_ErrorNone) { |
| 5297 | // this error can be ignored |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5298 | DEBUG_PRINT_LOW("ERROR:iDivXDrmDecrypt->Decrypt %d", drmErr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5299 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5300 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5301 | #endif //_ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5302 | if (perf_flag) { |
| 5303 | if (!latency) { |
| 5304 | dec_time.stop(); |
| 5305 | latency = dec_time.processing_time_us(); |
| 5306 | dec_time.start(); |
| 5307 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5308 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5309 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5310 | if (arbitrary_bytes) { |
| 5311 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5312 | } else { |
| 5313 | if (input_use_buffer == true) { |
| 5314 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5315 | m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen; |
| 5316 | m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp; |
| 5317 | m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags; |
| 5318 | buffer = &m_inp_mem_ptr[nBufferIndex]; |
| 5319 | DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu", |
| 5320 | &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen); |
| 5321 | } else { |
| 5322 | nBufferIndex = buffer - m_inp_mem_ptr; |
| 5323 | } |
| 5324 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5325 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5326 | if (nBufferIndex > drv_ctx.ip_buf.actualcount ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5327 | DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5328 | return OMX_ErrorBadParameter; |
| 5329 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5330 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5331 | DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)", |
| 5332 | buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen); |
| 5333 | if (arbitrary_bytes) { |
| 5334 | post_event ((unsigned)hComp,(unsigned)buffer, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5335 | OMX_COMPONENT_GENERATE_ETB_ARBITRARY); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5336 | } else { |
| 5337 | if (!(client_extradata & OMX_TIMEINFO_EXTRADATA)) |
| 5338 | set_frame_rate(buffer->nTimeStamp); |
| 5339 | post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB); |
| 5340 | } |
| 5341 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5345 | FUNCTION |
| 5346 | omx_vdec::empty_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5347 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5348 | DESCRIPTION |
| 5349 | This routine is used to push the encoded video frames to |
| 5350 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5351 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5352 | PARAMETERS |
| 5353 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5354 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5355 | RETURN VALUE |
| 5356 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5357 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5358 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5359 | OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5360 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5361 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5362 | int push_cnt = 0,i=0; |
| 5363 | unsigned nPortIndex = 0; |
| 5364 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 5365 | struct vdec_input_frameinfo frameinfo; |
| 5366 | struct vdec_bufferpayload *temp_buffer; |
| 5367 | struct vdec_seqheader seq_header; |
| 5368 | bool port_setting_changed = true; |
| 5369 | bool not_coded_vop = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5370 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5371 | /*Should we generate a Aync error event*/ |
| 5372 | if (buffer == NULL || buffer->pInputPortPrivate == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5373 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5374 | return OMX_ErrorBadParameter; |
| 5375 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5376 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5377 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5378 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5379 | if (nPortIndex > drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5380 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5381 | nPortIndex); |
| 5382 | return OMX_ErrorBadParameter; |
| 5383 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5384 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5385 | pending_input_buffers++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5386 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5387 | /* return zero length and not an EOS buffer */ |
| 5388 | if (!arbitrary_bytes && (buffer->nFilledLen == 0) && |
| 5389 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5390 | DEBUG_PRINT_HIGH("return zero legth buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5391 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5392 | OMX_COMPONENT_GENERATE_EBD); |
| 5393 | return OMX_ErrorNone; |
| 5394 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5395 | |
| 5396 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5397 | if (codec_type_parse == CODEC_TYPE_MPEG4 || codec_type_parse == CODEC_TYPE_DIVX) { |
| 5398 | mp4StreamType psBits; |
| 5399 | psBits.data = (unsigned char *)(buffer->pBuffer + buffer->nOffset); |
| 5400 | psBits.numBytes = buffer->nFilledLen; |
| 5401 | mp4_headerparser.parseHeader(&psBits); |
| 5402 | not_coded_vop = mp4_headerparser.is_notcodec_vop( |
| 5403 | (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen); |
| 5404 | if (not_coded_vop) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5405 | DEBUG_PRINT_HIGH("Found Not coded vop len %lu frame number %u", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5406 | buffer->nFilledLen,frame_count); |
| 5407 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5408 | DEBUG_PRINT_HIGH("Eos and Not coded Vop set len to zero"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5409 | not_coded_vop = false; |
| 5410 | buffer->nFilledLen = 0; |
| 5411 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5412 | } |
| 5413 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5414 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5415 | if (input_flush_progress == true |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5416 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5417 | || not_coded_vop |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5418 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5419 | ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5420 | DEBUG_PRINT_LOW("Flush in progress return buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5421 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5422 | OMX_COMPONENT_GENERATE_EBD); |
| 5423 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5424 | } |
| 5425 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5426 | temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5427 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 5428 | if ((temp_buffer - drv_ctx.ptr_inputbuffer) > (int)drv_ctx.ip_buf.actualcount) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5429 | return OMX_ErrorBadParameter; |
| 5430 | } |
| 5431 | /* If its first frame, H264 codec and reject is true, then parse the nal |
| 5432 | and get the profile. Based on this, reject the clip playback */ |
| 5433 | if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 && |
| 5434 | m_reject_avc_1080p_mp) { |
| 5435 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5436 | DEBUG_PRINT_ERROR("Parse nal to get the profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5437 | h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen, |
| 5438 | NALU_TYPE_SPS); |
| 5439 | m_profile = h264_parser->get_profile(); |
| 5440 | ret = is_video_session_supported(); |
| 5441 | if (ret) { |
| 5442 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD); |
| 5443 | post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT); |
| 5444 | /* Move the state to Invalid to avoid queueing of pending ETB to the driver */ |
| 5445 | m_state = OMX_StateInvalid; |
| 5446 | return OMX_ErrorNone; |
| 5447 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5448 | } |
| 5449 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5450 | DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5451 | /*for use buffer we need to memcpy the data*/ |
| 5452 | temp_buffer->buffer_len = buffer->nFilledLen; |
| 5453 | |
| 5454 | if (input_use_buffer) { |
| 5455 | if (buffer->nFilledLen <= temp_buffer->buffer_len) { |
| 5456 | if (arbitrary_bytes) { |
| 5457 | memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen); |
| 5458 | } else { |
| 5459 | memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset), |
| 5460 | buffer->nFilledLen); |
| 5461 | } |
| 5462 | } else { |
| 5463 | return OMX_ErrorBadParameter; |
| 5464 | } |
| 5465 | |
| 5466 | } |
| 5467 | |
| 5468 | frameinfo.bufferaddr = temp_buffer->bufferaddr; |
| 5469 | frameinfo.client_data = (void *) buffer; |
| 5470 | frameinfo.datalen = temp_buffer->buffer_len; |
| 5471 | frameinfo.flags = 0; |
| 5472 | frameinfo.offset = buffer->nOffset; |
| 5473 | frameinfo.pmem_fd = temp_buffer->pmem_fd; |
| 5474 | frameinfo.pmem_offset = temp_buffer->offset; |
| 5475 | frameinfo.timestamp = buffer->nTimeStamp; |
| 5476 | if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) { |
| 5477 | DEBUG_PRINT_LOW("ETB: dmx enabled"); |
| 5478 | if (m_demux_entries == 0) { |
| 5479 | extract_demux_addr_offsets(buffer); |
| 5480 | } |
| 5481 | |
| 5482 | DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries); |
| 5483 | handle_demux_data(buffer); |
| 5484 | frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr; |
| 5485 | frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size; |
| 5486 | } else { |
| 5487 | frameinfo.desc_addr = NULL; |
| 5488 | frameinfo.desc_size = 0; |
| 5489 | } |
| 5490 | if (!arbitrary_bytes) { |
| 5491 | frameinfo.flags |= buffer->nFlags; |
| 5492 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5493 | |
| 5494 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5495 | if (m_debug_timestamp) { |
| 5496 | if (arbitrary_bytes) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5497 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5498 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5499 | } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5500 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5501 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5502 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5503 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5504 | #endif |
| 5505 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5506 | log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5507 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5508 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5509 | frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5510 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5511 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5512 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5513 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5514 | DEBUG_PRINT_HIGH("Rxd i/p EOS, Notify Driver that EOS has been reached"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5515 | frameinfo.flags |= VDEC_BUFFERFLAG_EOS; |
| 5516 | h264_scratch.nFilledLen = 0; |
| 5517 | nal_count = 0; |
| 5518 | look_ahead_nal = false; |
| 5519 | frame_count = 0; |
| 5520 | if (m_frame_parser.mutils) |
| 5521 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 5522 | m_frame_parser.flush(); |
| 5523 | h264_last_au_ts = LLONG_MAX; |
| 5524 | h264_last_au_flags = 0; |
| 5525 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 5526 | m_demux_entries = 0; |
| 5527 | } |
| 5528 | struct v4l2_buffer buf; |
| 5529 | struct v4l2_plane plane; |
| 5530 | memset( (void *)&buf, 0, sizeof(buf)); |
| 5531 | memset( (void *)&plane, 0, sizeof(plane)); |
| 5532 | int rc; |
| 5533 | unsigned long print_count; |
| 5534 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 5535 | buf.flags = V4L2_QCOM_BUF_FLAG_EOS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5536 | DEBUG_PRINT_HIGH("INPUT EOS reached") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5537 | } |
| 5538 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5539 | buf.index = nPortIndex; |
| 5540 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5541 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5542 | plane.bytesused = temp_buffer->buffer_len; |
| 5543 | plane.length = drv_ctx.ip_buf.buffer_size; |
| 5544 | plane.m.userptr = (unsigned long)temp_buffer->bufferaddr - |
| 5545 | (unsigned long)temp_buffer->offset; |
| 5546 | plane.reserved[0] = temp_buffer->pmem_fd; |
| 5547 | plane.reserved[1] = temp_buffer->offset; |
| 5548 | plane.data_offset = 0; |
| 5549 | buf.m.planes = &plane; |
| 5550 | buf.length = 1; |
| 5551 | if (frameinfo.timestamp >= LLONG_MAX) { |
| 5552 | buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID; |
| 5553 | } |
| 5554 | //assumption is that timestamp is in milliseconds |
| 5555 | buf.timestamp.tv_sec = frameinfo.timestamp / 1000000; |
| 5556 | buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000); |
| 5557 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0; |
| 5558 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_DECODEONLY) ? V4L2_QCOM_BUF_FLAG_DECODEONLY: 0; |
Deva Ramasubramanian | 46a1795 | 2012-08-24 11:35:26 -0700 | [diff] [blame] | 5559 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5560 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 5561 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5562 | DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5563 | return OMX_ErrorHardware; |
| 5564 | } |
| 5565 | if (!streaming[OUTPUT_PORT]) { |
| 5566 | enum v4l2_buf_type buf_type; |
| 5567 | int ret,r; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 5568 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5569 | buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5570 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5571 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5572 | if (!ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5573 | DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5574 | streaming[OUTPUT_PORT] = true; |
| 5575 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5576 | DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5577 | DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued"); |
| 5578 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5579 | OMX_COMPONENT_GENERATE_EBD); |
| 5580 | return OMX_ErrorBadParameter; |
| 5581 | } |
| 5582 | } |
| 5583 | DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)", |
| 5584 | frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen); |
| 5585 | time_stamp_dts.insert_timestamp(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5586 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5587 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5591 | FUNCTION |
| 5592 | omx_vdec::FillThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5593 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5594 | DESCRIPTION |
| 5595 | IL client uses this method to release the frame buffer |
| 5596 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5597 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5598 | PARAMETERS |
| 5599 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5600 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5601 | RETURN VALUE |
| 5602 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5603 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5604 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5605 | OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5606 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5607 | { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 5608 | if (dynamic_buf_mode) { |
| 5609 | private_handle_t *handle = NULL; |
| 5610 | struct VideoDecoderOutputMetaData *meta; |
| 5611 | OMX_U8 *buff = NULL; |
| 5612 | unsigned int nPortIndex = 0; |
| 5613 | |
| 5614 | if (!buffer || !buffer->pBuffer) { |
| 5615 | DEBUG_PRINT_ERROR("%s: invalid params: %p %p", __FUNCTION__, buffer, buffer->pBuffer); |
| 5616 | return OMX_ErrorBadParameter; |
| 5617 | } |
| 5618 | |
| 5619 | //get the buffer type and fd info |
| 5620 | meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer; |
| 5621 | handle = (private_handle_t *)meta->pHandle; |
| 5622 | DEBUG_PRINT_LOW("FTB: buftype: %d bufhndl: %p", meta->eType, meta->pHandle); |
| 5623 | |
| 5624 | //map the buffer handle based on the size set on output port definition. |
| 5625 | if (!secure_mode) { |
| 5626 | buff = (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size, |
| 5627 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
| 5628 | } else { |
| 5629 | buff = (OMX_U8*) buffer; |
| 5630 | } |
| 5631 | |
| 5632 | //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF |
| 5633 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 5634 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd; |
| 5635 | drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0; |
| 5636 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = buff; |
| 5637 | drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size; |
| 5638 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 5639 | buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, |
| 5640 | drv_ctx.ptr_outputbuffer[nPortIndex].offset); |
| 5641 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5642 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5643 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5644 | DEBUG_PRINT_ERROR("FTB in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5645 | return OMX_ErrorInvalidState; |
| 5646 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5647 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5648 | if (!m_out_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5649 | DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5650 | return OMX_ErrorIncorrectStateOperation; |
| 5651 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5652 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5653 | if (buffer == NULL || |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 5654 | ((buffer - client_buffers.get_il_buf_hdr()) >= (int)drv_ctx.op_buf.actualcount)) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5655 | return OMX_ErrorBadParameter; |
| 5656 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5657 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5658 | if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5659 | DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5660 | return OMX_ErrorBadPortIndex; |
| 5661 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5662 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5663 | DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 5664 | post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg); |
| 5665 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5666 | } |
| 5667 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5668 | FUNCTION |
| 5669 | omx_vdec::fill_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5670 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5671 | DESCRIPTION |
| 5672 | IL client uses this method to release the frame buffer |
| 5673 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5674 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5675 | PARAMETERS |
| 5676 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5677 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5678 | RETURN VALUE |
| 5679 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5680 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5681 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5682 | OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5683 | OMX_IN OMX_HANDLETYPE hComp, |
| 5684 | OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5685 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5686 | OMX_ERRORTYPE nRet = OMX_ErrorNone; |
| 5687 | OMX_BUFFERHEADERTYPE *buffer = bufferAdd; |
| 5688 | unsigned nPortIndex = 0; |
| 5689 | struct vdec_fillbuffer_cmd fillbuffer; |
| 5690 | struct vdec_bufferpayload *ptr_outputbuffer = NULL; |
| 5691 | struct vdec_output_frameinfo *ptr_respbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5692 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5693 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5694 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5695 | if (bufferAdd == NULL || nPortIndex > drv_ctx.op_buf.actualcount) |
| 5696 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5697 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5698 | DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5699 | bufferAdd, bufferAdd->pBuffer); |
| 5700 | /*Return back the output buffer to client*/ |
| 5701 | if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5702 | DEBUG_PRINT_LOW("Output Buffers return flush/disable condition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5703 | buffer->nFilledLen = 0; |
| 5704 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 5705 | return OMX_ErrorNone; |
| 5706 | } |
| 5707 | pending_output_buffers++; |
| 5708 | buffer = client_buffers.get_dr_buf_hdr(bufferAdd); |
| 5709 | ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate; |
| 5710 | if (ptr_respbuffer) { |
| 5711 | ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data; |
| 5712 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5713 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5714 | if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) { |
| 5715 | DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL"); |
| 5716 | buffer->nFilledLen = 0; |
| 5717 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 5718 | pending_output_buffers--; |
| 5719 | return OMX_ErrorBadParameter; |
| 5720 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5721 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5722 | int rc = 0; |
| 5723 | struct v4l2_buffer buf; |
| 5724 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 5725 | memset( (void *)&buf, 0, sizeof(buf)); |
| 5726 | memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES)); |
| 5727 | int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5728 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5729 | buf.index = nPortIndex; |
| 5730 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5731 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5732 | plane[0].bytesused = buffer->nFilledLen; |
| 5733 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 5734 | plane[0].m.userptr = |
| 5735 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr - |
| 5736 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 5737 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd; |
| 5738 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 5739 | plane[0].data_offset = 0; |
| 5740 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 5741 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 5742 | plane[extra_idx].bytesused = 0; |
| 5743 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 5744 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + nPortIndex * drv_ctx.extradata_info.buffer_size); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 5745 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5746 | plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 5747 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5748 | plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size; |
| 5749 | plane[extra_idx].data_offset = 0; |
| 5750 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5751 | DEBUG_PRINT_ERROR("Extradata index higher than expected: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5752 | return OMX_ErrorBadParameter; |
| 5753 | } |
| 5754 | buf.m.planes = plane; |
| 5755 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5756 | DEBUG_PRINT_LOW("SENDING FTB TO F/W - fd[0] = %d fd[1] = %d offset[1] = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 5757 | plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]); |
| 5758 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5759 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 5760 | if (rc) { |
| 5761 | /*TODO: How to handle this case */ |
| 5762 | DEBUG_PRINT_ERROR("Failed to qbuf to driver"); |
| 5763 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5764 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5768 | FUNCTION |
| 5769 | omx_vdec::SetCallbacks |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5770 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5771 | DESCRIPTION |
| 5772 | Set the callbacks. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5773 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5774 | PARAMETERS |
| 5775 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5776 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5777 | RETURN VALUE |
| 5778 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5779 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5780 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5781 | OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5782 | OMX_IN OMX_CALLBACKTYPE* callbacks, |
| 5783 | OMX_IN OMX_PTR appData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5784 | { |
| 5785 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5786 | m_cb = *callbacks; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5787 | DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5788 | m_cb.EventHandler,m_cb.FillBufferDone); |
| 5789 | m_app_data = appData; |
| 5790 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5794 | FUNCTION |
| 5795 | omx_vdec::ComponentDeInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5796 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5797 | DESCRIPTION |
| 5798 | Destroys the component and release memory allocated to the heap. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5799 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5800 | PARAMETERS |
| 5801 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5802 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5803 | RETURN VALUE |
| 5804 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5805 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5806 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5807 | OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp) |
| 5808 | { |
| 5809 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5810 | if (iDivXDrmDecrypt) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5811 | delete iDivXDrmDecrypt; |
| 5812 | iDivXDrmDecrypt=NULL; |
| 5813 | } |
| 5814 | #endif //_ANDROID_ |
| 5815 | |
Shalaj Jain | 286b006 | 2013-02-21 20:35:48 -0800 | [diff] [blame] | 5816 | unsigned i = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5817 | if (OMX_StateLoaded != m_state) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5818 | DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5819 | m_state); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5820 | DEBUG_PRINT_ERROR("Playback Ended - FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5821 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5822 | DEBUG_PRINT_HIGH("Playback Ended - PASSED"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | /*Check if the output buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5826 | if (m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5827 | DEBUG_PRINT_LOW("Freeing the Output Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5828 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) { |
| 5829 | free_output_buffer (&m_out_mem_ptr[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5830 | } |
| 5831 | #ifdef _ANDROID_ICS_ |
| 5832 | memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 5833 | #endif |
| 5834 | } |
| 5835 | |
| 5836 | /*Check if the input buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5837 | if (m_inp_mem_ptr || m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5838 | DEBUG_PRINT_LOW("Freeing the Input Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5839 | for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) { |
| 5840 | if (m_inp_mem_ptr) |
| 5841 | free_input_buffer (i,&m_inp_mem_ptr[i]); |
| 5842 | else |
| 5843 | free_input_buffer (i,NULL); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5844 | } |
| 5845 | } |
| 5846 | free_input_buffer_header(); |
| 5847 | free_output_buffer_header(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5848 | if (h264_scratch.pBuffer) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5849 | free(h264_scratch.pBuffer); |
| 5850 | h264_scratch.pBuffer = NULL; |
| 5851 | } |
| 5852 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5853 | if (h264_parser) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5854 | delete h264_parser; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5855 | h264_parser = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5856 | } |
| 5857 | |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 5858 | if (m_frame_parser.mutils) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5859 | DEBUG_PRINT_LOW("Free utils parser"); |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 5860 | delete (m_frame_parser.mutils); |
| 5861 | m_frame_parser.mutils = NULL; |
| 5862 | } |
| 5863 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5864 | if (m_platform_list) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5865 | free(m_platform_list); |
| 5866 | m_platform_list = NULL; |
| 5867 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5868 | if (m_vendor_config.pData) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5869 | free(m_vendor_config.pData); |
| 5870 | m_vendor_config.pData = NULL; |
| 5871 | } |
| 5872 | |
| 5873 | // Reset counters in mesg queues |
| 5874 | m_ftb_q.m_size=0; |
| 5875 | m_cmd_q.m_size=0; |
| 5876 | m_etb_q.m_size=0; |
| 5877 | m_ftb_q.m_read = m_ftb_q.m_write =0; |
| 5878 | m_cmd_q.m_read = m_cmd_q.m_write =0; |
| 5879 | m_etb_q.m_read = m_etb_q.m_write =0; |
| 5880 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5881 | if (m_debug_timestamp) { |
| 5882 | m_timestamp_list.reset_ts_list(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5883 | } |
| 5884 | #endif |
| 5885 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5886 | DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5887 | //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5888 | // NULL); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5889 | DEBUG_PRINT_HIGH("Close the driver instance"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5890 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5891 | if (m_debug.infile) { |
| 5892 | fclose(m_debug.infile); |
| 5893 | m_debug.infile = NULL; |
| 5894 | } |
| 5895 | if (m_debug.outfile) { |
| 5896 | fclose(m_debug.outfile); |
| 5897 | m_debug.outfile = NULL; |
| 5898 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5899 | #ifdef OUTPUT_EXTRADATA_LOG |
Shalaj Jain | af08f30 | 2013-03-18 13:15:35 -0700 | [diff] [blame] | 5900 | if (outputExtradataFile) |
| 5901 | fclose (outputExtradataFile); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5902 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5903 | DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5904 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5908 | FUNCTION |
| 5909 | omx_vdec::UseEGLImage |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5910 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5911 | DESCRIPTION |
| 5912 | OMX Use EGL Image method implementation <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5913 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5914 | PARAMETERS |
| 5915 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5916 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5917 | RETURN VALUE |
| 5918 | Not Implemented error. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5919 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5920 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5921 | OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5922 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5923 | OMX_IN OMX_U32 port, |
| 5924 | OMX_IN OMX_PTR appData, |
| 5925 | OMX_IN void* eglImage) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5926 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5927 | OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list; |
| 5928 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry; |
| 5929 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5930 | |
| 5931 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5932 | PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc; |
| 5933 | EGLint fd = -1, offset = 0,pmemPtr = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5934 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5935 | int fd = -1, offset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5936 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5937 | DEBUG_PRINT_HIGH("use EGL image support for decoder"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5938 | if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5939 | DEBUG_PRINT_ERROR(""); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5940 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5941 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5942 | if (m_display_id == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5943 | DEBUG_PRINT_ERROR("Display ID is not set by IL client"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5944 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5945 | } |
| 5946 | egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC) |
| 5947 | eglGetProcAddress("eglQueryImageKHR"); |
| 5948 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd); |
| 5949 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset); |
| 5950 | egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5951 | #else //with OMX test app |
| 5952 | struct temp_egl { |
| 5953 | int pmem_fd; |
| 5954 | int offset; |
| 5955 | }; |
| 5956 | struct temp_egl *temp_egl_id = NULL; |
| 5957 | void * pmemPtr = (void *) eglImage; |
| 5958 | temp_egl_id = (struct temp_egl *)eglImage; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5959 | if (temp_egl_id != NULL) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5960 | fd = temp_egl_id->pmem_fd; |
| 5961 | offset = temp_egl_id->offset; |
| 5962 | } |
| 5963 | #endif |
| 5964 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5965 | DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5966 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5967 | } |
| 5968 | pmem_info.pmem_fd = (OMX_U32) fd; |
| 5969 | pmem_info.offset = (OMX_U32) offset; |
| 5970 | pmem_entry.entry = (void *) &pmem_info; |
| 5971 | pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 5972 | pmem_list.entryList = &pmem_entry; |
| 5973 | pmem_list.nEntries = 1; |
| 5974 | ouput_egl_buffers = true; |
| 5975 | if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port, |
| 5976 | (void *)&pmem_list, drv_ctx.op_buf.buffer_size, |
| 5977 | (OMX_U8 *)pmemPtr)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5978 | DEBUG_PRINT_ERROR("use buffer call failed for egl image"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5979 | return OMX_ErrorInsufficientResources; |
| 5980 | } |
| 5981 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5985 | FUNCTION |
| 5986 | omx_vdec::ComponentRoleEnum |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5987 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5988 | DESCRIPTION |
| 5989 | OMX Component Role Enum method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5990 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5991 | PARAMETERS |
| 5992 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5993 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5994 | RETURN VALUE |
| 5995 | OMX Error None if everything is successful. |
| 5996 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5997 | OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5998 | OMX_OUT OMX_U8* role, |
| 5999 | OMX_IN OMX_U32 index) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6000 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6001 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6002 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6003 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 6004 | if ((0 == index) && role) { |
| 6005 | strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6006 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6007 | } else { |
| 6008 | eRet = OMX_ErrorNoMore; |
| 6009 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6010 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6011 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 6012 | if ((0 == index) && role) { |
| 6013 | strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6014 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6015 | } else { |
| 6016 | eRet = OMX_ErrorNoMore; |
| 6017 | } |
| 6018 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 6019 | if ((0 == index) && role) { |
| 6020 | strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6021 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6022 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6023 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6024 | eRet = OMX_ErrorNoMore; |
| 6025 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6026 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6027 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6028 | else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) || |
| 6029 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE)) |
| 6030 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6031 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6032 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6033 | if ((0 == index) && role) { |
| 6034 | strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6035 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6036 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6037 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6038 | eRet = OMX_ErrorNoMore; |
| 6039 | } |
| 6040 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 6041 | if ((0 == index) && role) { |
| 6042 | strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6043 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6044 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6045 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6046 | eRet = OMX_ErrorNoMore; |
| 6047 | } |
| 6048 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 6049 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 6050 | ) { |
| 6051 | if ((0 == index) && role) { |
| 6052 | strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6053 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6054 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6055 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6056 | eRet = OMX_ErrorNoMore; |
| 6057 | } |
| 6058 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 6059 | if ((0 == index) && role) { |
| 6060 | strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6061 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6062 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6063 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6064 | eRet = OMX_ErrorNoMore; |
| 6065 | } |
| 6066 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6067 | DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6068 | eRet = OMX_ErrorInvalidComponentName; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6069 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6070 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6071 | } |
| 6072 | |
| 6073 | |
| 6074 | |
| 6075 | |
| 6076 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6077 | FUNCTION |
| 6078 | omx_vdec::AllocateDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6079 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6080 | DESCRIPTION |
| 6081 | Checks if entire buffer pool is allocated by IL Client or not. |
| 6082 | Need this to move to IDLE state. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6083 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6084 | PARAMETERS |
| 6085 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6086 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6087 | RETURN VALUE |
| 6088 | true/false. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6089 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6090 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6091 | bool omx_vdec::allocate_done(void) |
| 6092 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6093 | bool bRet = false; |
| 6094 | bool bRet_In = false; |
| 6095 | bool bRet_Out = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6096 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6097 | bRet_In = allocate_input_done(); |
| 6098 | bRet_Out = allocate_output_done(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6099 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6100 | if (bRet_In && bRet_Out) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6101 | bRet = true; |
| 6102 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6103 | |
| 6104 | return bRet; |
| 6105 | } |
| 6106 | /* ====================================================================== |
| 6107 | FUNCTION |
| 6108 | omx_vdec::AllocateInputDone |
| 6109 | |
| 6110 | DESCRIPTION |
| 6111 | Checks if I/P buffer pool is allocated by IL Client or not. |
| 6112 | |
| 6113 | PARAMETERS |
| 6114 | None. |
| 6115 | |
| 6116 | RETURN VALUE |
| 6117 | true/false. |
| 6118 | |
| 6119 | ========================================================================== */ |
| 6120 | bool omx_vdec::allocate_input_done(void) |
| 6121 | { |
| 6122 | bool bRet = false; |
| 6123 | unsigned i=0; |
| 6124 | |
| 6125 | if (m_inp_mem_ptr == NULL) { |
| 6126 | return bRet; |
| 6127 | } |
| 6128 | if (m_inp_mem_ptr ) { |
| 6129 | for (; i<drv_ctx.ip_buf.actualcount; i++) { |
| 6130 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
| 6131 | break; |
| 6132 | } |
| 6133 | } |
| 6134 | } |
| 6135 | if (i == drv_ctx.ip_buf.actualcount) { |
| 6136 | bRet = true; |
| 6137 | DEBUG_PRINT_HIGH("Allocate done for all i/p buffers"); |
| 6138 | } |
| 6139 | if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) { |
| 6140 | m_inp_bPopulated = OMX_TRUE; |
| 6141 | } |
| 6142 | return bRet; |
| 6143 | } |
| 6144 | /* ====================================================================== |
| 6145 | FUNCTION |
| 6146 | omx_vdec::AllocateOutputDone |
| 6147 | |
| 6148 | DESCRIPTION |
| 6149 | Checks if entire O/P buffer pool is allocated by IL Client or not. |
| 6150 | |
| 6151 | PARAMETERS |
| 6152 | None. |
| 6153 | |
| 6154 | RETURN VALUE |
| 6155 | true/false. |
| 6156 | |
| 6157 | ========================================================================== */ |
| 6158 | bool omx_vdec::allocate_output_done(void) |
| 6159 | { |
| 6160 | bool bRet = false; |
| 6161 | unsigned j=0; |
| 6162 | |
| 6163 | if (m_out_mem_ptr == NULL) { |
| 6164 | return bRet; |
| 6165 | } |
| 6166 | |
| 6167 | if (m_out_mem_ptr) { |
| 6168 | for (; j < drv_ctx.op_buf.actualcount; j++) { |
| 6169 | if (BITMASK_ABSENT(&m_out_bm_count,j)) { |
| 6170 | break; |
| 6171 | } |
| 6172 | } |
| 6173 | } |
| 6174 | |
| 6175 | if (j == drv_ctx.op_buf.actualcount) { |
| 6176 | bRet = true; |
| 6177 | DEBUG_PRINT_HIGH("Allocate done for all o/p buffers"); |
| 6178 | if (m_out_bEnabled) |
| 6179 | m_out_bPopulated = OMX_TRUE; |
| 6180 | } |
| 6181 | |
| 6182 | return bRet; |
| 6183 | } |
| 6184 | |
| 6185 | /* ====================================================================== |
| 6186 | FUNCTION |
| 6187 | omx_vdec::ReleaseDone |
| 6188 | |
| 6189 | DESCRIPTION |
| 6190 | Checks if IL client has released all the buffers. |
| 6191 | |
| 6192 | PARAMETERS |
| 6193 | None. |
| 6194 | |
| 6195 | RETURN VALUE |
| 6196 | true/false |
| 6197 | |
| 6198 | ========================================================================== */ |
| 6199 | bool omx_vdec::release_done(void) |
| 6200 | { |
| 6201 | bool bRet = false; |
| 6202 | |
| 6203 | if (release_input_done()) { |
| 6204 | if (release_output_done()) { |
| 6205 | bRet = true; |
| 6206 | } |
| 6207 | } |
| 6208 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6209 | } |
| 6210 | |
| 6211 | |
| 6212 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6213 | FUNCTION |
| 6214 | omx_vdec::ReleaseOutputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6215 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6216 | DESCRIPTION |
| 6217 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6218 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6219 | PARAMETERS |
| 6220 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6221 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6222 | RETURN VALUE |
| 6223 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6224 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6225 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6226 | bool omx_vdec::release_output_done(void) |
| 6227 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6228 | bool bRet = false; |
| 6229 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6230 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6231 | DEBUG_PRINT_LOW("Value of m_out_mem_ptr %p",m_inp_mem_ptr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6232 | if (m_out_mem_ptr) { |
| 6233 | for (; j < drv_ctx.op_buf.actualcount ; j++) { |
| 6234 | if (BITMASK_PRESENT(&m_out_bm_count,j)) { |
| 6235 | break; |
| 6236 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6237 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6238 | if (j == drv_ctx.op_buf.actualcount) { |
| 6239 | m_out_bm_count = 0; |
| 6240 | bRet = true; |
| 6241 | } |
| 6242 | } else { |
| 6243 | m_out_bm_count = 0; |
| 6244 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6245 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6246 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6247 | } |
| 6248 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6249 | FUNCTION |
| 6250 | omx_vdec::ReleaseInputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6251 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6252 | DESCRIPTION |
| 6253 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6254 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6255 | PARAMETERS |
| 6256 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6257 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6258 | RETURN VALUE |
| 6259 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6260 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6261 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6262 | bool omx_vdec::release_input_done(void) |
| 6263 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6264 | bool bRet = false; |
| 6265 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6266 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6267 | DEBUG_PRINT_LOW("Value of m_inp_mem_ptr %p",m_inp_mem_ptr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6268 | if (m_inp_mem_ptr) { |
| 6269 | for (; j<drv_ctx.ip_buf.actualcount; j++) { |
| 6270 | if ( BITMASK_PRESENT(&m_inp_bm_count,j)) { |
| 6271 | break; |
| 6272 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6273 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6274 | if (j==drv_ctx.ip_buf.actualcount) { |
| 6275 | bRet = true; |
| 6276 | } |
| 6277 | } else { |
| 6278 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6279 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6280 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6281 | } |
| 6282 | |
| 6283 | OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6284 | OMX_BUFFERHEADERTYPE * buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6285 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6286 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6287 | if (!buffer || (buffer - m_out_mem_ptr) >= (int)drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6288 | DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6289 | return OMX_ErrorBadParameter; |
| 6290 | } else if (output_flush_progress) { |
| 6291 | DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer); |
| 6292 | buffer->nFilledLen = 0; |
| 6293 | buffer->nTimeStamp = 0; |
| 6294 | buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA; |
| 6295 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 6296 | buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT; |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6297 | } |
| 6298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6299 | if (m_debug_extradata) { |
| 6300 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6301 | DEBUG_PRINT_HIGH(""); |
| 6302 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6303 | DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received"); |
| 6304 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6305 | } |
| 6306 | |
| 6307 | if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6308 | DEBUG_PRINT_HIGH(""); |
| 6309 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6310 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 6311 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6312 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6313 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6314 | |
| 6315 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6316 | DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6317 | buffer, buffer->pBuffer); |
| 6318 | pending_output_buffers --; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6319 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6320 | if (dynamic_buf_mode && !secure_mode) { |
| 6321 | unsigned int nPortIndex = 0; |
| 6322 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6323 | munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr, |
| 6324 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size); |
| 6325 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6326 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6327 | DEBUG_PRINT_HIGH("Output EOS has been reached"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6328 | if (!output_flush_progress) |
| 6329 | post_event((unsigned)NULL, (unsigned)NULL, |
| 6330 | OMX_COMPONENT_GENERATE_EOS_DONE); |
| 6331 | |
| 6332 | if (psource_frame) { |
| 6333 | m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame); |
| 6334 | psource_frame = NULL; |
| 6335 | } |
| 6336 | if (pdest_frame) { |
| 6337 | pdest_frame->nFilledLen = 0; |
| 6338 | m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL, |
| 6339 | (unsigned)NULL); |
| 6340 | pdest_frame = NULL; |
| 6341 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6342 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6343 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6344 | DEBUG_PRINT_LOW("In fill Buffer done call address %p ",buffer); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 6345 | log_output_buffers(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6346 | |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 6347 | if (!output_flush_progress && (buffer->nFilledLen > 0)) { |
| 6348 | DEBUG_PRINT_LOW("Processing extradata"); |
| 6349 | handle_extradata(buffer); |
| 6350 | } |
| 6351 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6352 | /* For use buffer we need to copy the data */ |
| 6353 | if (!output_flush_progress) { |
| 6354 | /* This is the error check for non-recoverable errros */ |
| 6355 | bool is_duplicate_ts_valid = true; |
| 6356 | bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6357 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6358 | if (output_capability == V4L2_PIX_FMT_MPEG4 || |
| 6359 | output_capability == V4L2_PIX_FMT_MPEG2 || |
| 6360 | output_capability == V4L2_PIX_FMT_DIVX || |
| 6361 | output_capability == V4L2_PIX_FMT_DIVX_311) |
| 6362 | is_duplicate_ts_valid = false; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6363 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6364 | if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) { |
| 6365 | bool mbaff = (h264_parser)? (h264_parser->is_mbaff()): false; |
| 6366 | if (mbaff) { |
| 6367 | is_interlaced = false; |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6368 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6369 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6370 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6371 | if (buffer->nFilledLen > 0) { |
| 6372 | time_stamp_dts.get_next_timestamp(buffer, |
| 6373 | is_interlaced && is_duplicate_ts_valid); |
| 6374 | if (m_debug_timestamp) { |
| 6375 | { |
| 6376 | OMX_TICKS expected_ts = 0; |
| 6377 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6378 | if (is_interlaced && is_duplicate_ts_valid) { |
| 6379 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6380 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6381 | DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6382 | buffer->nTimeStamp, expected_ts); |
| 6383 | |
| 6384 | if (buffer->nTimeStamp != expected_ts) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6385 | DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6386 | } |
| 6387 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6388 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6389 | } else { |
| 6390 | m_inp_err_count++; |
| 6391 | time_stamp_dts.remove_time_stamp( |
| 6392 | buffer->nTimeStamp, |
| 6393 | is_interlaced && is_duplicate_ts_valid); |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6394 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6395 | |
| 6396 | |
Praneeth Paladugu | 8f12e82 | 2013-03-11 18:47:58 -0700 | [diff] [blame] | 6397 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6398 | if (m_cb.FillBufferDone) { |
| 6399 | if (buffer->nFilledLen > 0) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6400 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) |
| 6401 | set_frame_rate(buffer->nTimeStamp); |
| 6402 | else if (arbitrary_bytes) |
| 6403 | adjust_timestamp(buffer->nTimeStamp); |
| 6404 | if (perf_flag) { |
| 6405 | if (!proc_frms) { |
| 6406 | dec_time.stop(); |
| 6407 | latency = dec_time.processing_time_us() - latency; |
| 6408 | DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3); |
| 6409 | dec_time.start(); |
| 6410 | fps_metrics.start(); |
| 6411 | } |
| 6412 | proc_frms++; |
| 6413 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6414 | OMX_U64 proc_time = 0; |
| 6415 | fps_metrics.stop(); |
| 6416 | proc_time = fps_metrics.processing_time_us(); |
| 6417 | DEBUG_PRINT_HIGH(">>> FBD Metrics: proc_frms(%lu) proc_time(%.2f)S fps(%.2f)", |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6418 | proc_frms, (float)proc_time / 1e6, |
| 6419 | (float)(1e6 * proc_frms) / proc_time); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6420 | proc_frms = 0; |
| 6421 | } |
| 6422 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6423 | |
| 6424 | #ifdef OUTPUT_EXTRADATA_LOG |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6425 | if (outputExtradataFile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6426 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6427 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL; |
| 6428 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
| 6429 | ((unsigned)(buffer->pBuffer + buffer->nOffset + |
| 6430 | buffer->nFilledLen + 3)&(~3)); |
| 6431 | while (p_extra && |
| 6432 | (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6433 | DEBUG_PRINT_LOW("WRITING extradata, size=%d,type=%d",p_extra->nSize, p_extra->eType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6434 | fwrite (p_extra,1,p_extra->nSize,outputExtradataFile); |
| 6435 | if (p_extra->eType == OMX_ExtraDataNone) { |
| 6436 | break; |
| 6437 | } |
| 6438 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 6439 | } |
| 6440 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6441 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6442 | } |
| 6443 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6444 | prev_ts = LLONG_MAX; |
| 6445 | rst_prev_ts = true; |
| 6446 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6447 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6448 | pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 6449 | ((OMX_QCOM_PLATFORM_PRIVATE_LIST *) |
| 6450 | buffer->pPlatformPrivate)->entryList->entry; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6451 | DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6452 | OMX_BUFFERHEADERTYPE *il_buffer; |
| 6453 | il_buffer = client_buffers.get_il_buf_hdr(buffer); |
| 6454 | if (il_buffer) |
| 6455 | m_cb.FillBufferDone (hComp,m_app_data,il_buffer); |
| 6456 | else { |
| 6457 | DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr"); |
| 6458 | return OMX_ErrorBadParameter; |
| 6459 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6460 | DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6461 | } else { |
| 6462 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 6463 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6464 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6465 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6466 | } |
| 6467 | |
| 6468 | OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6469 | OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6470 | { |
| 6471 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6472 | if (buffer == NULL || ((buffer - m_inp_mem_ptr) > (int)drv_ctx.ip_buf.actualcount)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6473 | DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6474 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6475 | } |
| 6476 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6477 | DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6478 | buffer, buffer->pBuffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6479 | pending_input_buffers--; |
| 6480 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6481 | if (arbitrary_bytes) { |
| 6482 | if (pdest_frame == NULL && input_flush_progress == false) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6483 | DEBUG_PRINT_LOW("Push input from buffer done address of Buffer %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6484 | pdest_frame = buffer; |
| 6485 | buffer->nFilledLen = 0; |
| 6486 | buffer->nTimeStamp = LLONG_MAX; |
| 6487 | push_input_buffer (hComp); |
| 6488 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6489 | DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6490 | buffer->nFilledLen = 0; |
| 6491 | if (!m_input_free_q.insert_entry((unsigned)buffer, |
| 6492 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6493 | DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6494 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6495 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6496 | } else if (m_cb.EmptyBufferDone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6497 | buffer->nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6498 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6499 | buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr]; |
| 6500 | } |
| 6501 | m_cb.EmptyBufferDone(hComp ,m_app_data, buffer); |
| 6502 | } |
| 6503 | return OMX_ErrorNone; |
| 6504 | } |
| 6505 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6506 | int omx_vdec::async_message_process (void *context, void* message) |
| 6507 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6508 | omx_vdec* omx = NULL; |
| 6509 | struct vdec_msginfo *vdec_msg = NULL; |
| 6510 | OMX_BUFFERHEADERTYPE* omxhdr = NULL; |
| 6511 | struct v4l2_buffer *v4l2_buf_ptr = NULL; |
| 6512 | struct vdec_output_frameinfo *output_respbuf = NULL; |
| 6513 | int rc=1; |
| 6514 | if (context == NULL || message == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6515 | DEBUG_PRINT_ERROR("FATAL ERROR in omx_vdec::async_message_process NULL Check"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6516 | return -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6517 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6518 | vdec_msg = (struct vdec_msginfo *)message; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6519 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6520 | omx = reinterpret_cast<omx_vdec*>(context); |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 6521 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6522 | switch (vdec_msg->msgcode) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6523 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6524 | case VDEC_MSG_EVT_HW_ERROR: |
| 6525 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6526 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
| 6527 | break; |
| 6528 | |
| 6529 | case VDEC_MSG_RESP_START_DONE: |
| 6530 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6531 | OMX_COMPONENT_GENERATE_START_DONE); |
| 6532 | break; |
| 6533 | |
| 6534 | case VDEC_MSG_RESP_STOP_DONE: |
| 6535 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6536 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 6537 | break; |
| 6538 | |
| 6539 | case VDEC_MSG_RESP_RESUME_DONE: |
| 6540 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6541 | OMX_COMPONENT_GENERATE_RESUME_DONE); |
| 6542 | break; |
| 6543 | |
| 6544 | case VDEC_MSG_RESP_PAUSE_DONE: |
| 6545 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6546 | OMX_COMPONENT_GENERATE_PAUSE_DONE); |
| 6547 | break; |
| 6548 | |
| 6549 | case VDEC_MSG_RESP_FLUSH_INPUT_DONE: |
| 6550 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6551 | OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH); |
| 6552 | break; |
| 6553 | case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE: |
| 6554 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6555 | OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH); |
| 6556 | break; |
| 6557 | case VDEC_MSG_RESP_INPUT_FLUSHED: |
| 6558 | case VDEC_MSG_RESP_INPUT_BUFFER_DONE: |
| 6559 | |
| 6560 | /* omxhdr = (OMX_BUFFERHEADERTYPE* ) |
| 6561 | vdec_msg->msgdata.input_frame_clientdata; */ |
| 6562 | |
| 6563 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata; |
| 6564 | omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index; |
| 6565 | if (omxhdr == NULL || |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6566 | ((omxhdr - omx->m_inp_mem_ptr) > (int)omx->drv_ctx.ip_buf.actualcount) ) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6567 | omxhdr = NULL; |
| 6568 | vdec_msg->status_code = VDEC_S_EFATAL; |
| 6569 | } |
| 6570 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) { |
| 6571 | DEBUG_PRINT_HIGH("Unsupported input"); |
| 6572 | omx->omx_report_error (); |
| 6573 | } |
| 6574 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 6575 | vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR; |
| 6576 | } |
| 6577 | omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code, |
| 6578 | OMX_COMPONENT_GENERATE_EBD); |
| 6579 | break; |
| 6580 | case VDEC_MSG_EVT_INFO_FIELD_DROPPED: |
| 6581 | int64_t *timestamp; |
| 6582 | timestamp = (int64_t *) malloc(sizeof(int64_t)); |
| 6583 | if (timestamp) { |
| 6584 | *timestamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 6585 | omx->post_event ((unsigned int)timestamp, vdec_msg->status_code, |
| 6586 | OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6587 | DEBUG_PRINT_HIGH("Field dropped time stamp is %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6588 | vdec_msg->msgdata.output_frame.time_stamp); |
| 6589 | } |
| 6590 | break; |
| 6591 | case VDEC_MSG_RESP_OUTPUT_FLUSHED: |
| 6592 | case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE: |
| 6593 | |
| 6594 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data; |
| 6595 | omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index; |
| 6596 | DEBUG_PRINT_LOW("[RespBufDone] Buf(%p) Ts(%lld) Pic_type(%u)", |
| 6597 | omxhdr, vdec_msg->msgdata.output_frame.time_stamp, |
| 6598 | vdec_msg->msgdata.output_frame.pic_type); |
| 6599 | |
| 6600 | if (omxhdr && omxhdr->pOutputPortPrivate && |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6601 | ((omxhdr - omx->m_out_mem_ptr) < (int)omx->drv_ctx.op_buf.actualcount) && |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6602 | (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6603 | - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6604 | if (omx->dynamic_buf_mode && vdec_msg->msgdata.output_frame.len) { |
| 6605 | vdec_msg->msgdata.output_frame.len = omxhdr->nAllocLen; |
| 6606 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6607 | if ( vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) { |
| 6608 | omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len; |
| 6609 | omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset; |
| 6610 | omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 6611 | omxhdr->nFlags = 0; |
| 6612 | |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 6613 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6614 | omxhdr->nFlags |= OMX_BUFFERFLAG_EOS; |
| 6615 | //rc = -1; |
| 6616 | } |
| 6617 | if (omxhdr->nFilledLen) { |
| 6618 | omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; |
| 6619 | } |
| 6620 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) { |
| 6621 | omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; |
| 6622 | } else { |
| 6623 | omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME; |
| 6624 | } |
| 6625 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) { |
| 6626 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 6627 | } |
| 6628 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) { |
| 6629 | omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY; |
| 6630 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6631 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) { |
Arun Menon | e50f6ef | 2013-09-30 15:08:27 -0700 | [diff] [blame] | 6632 | omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6633 | DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d", |
| 6634 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd); |
| 6635 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6636 | if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) { |
| 6637 | omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd, |
| 6638 | omxhdr->nOffset); |
| 6639 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6640 | if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) && |
| 6641 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) && |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 6642 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) { |
Praneeth Paladugu | 17364df | 2013-07-30 11:34:16 -0700 | [diff] [blame] | 6643 | omx->time_stamp_dts.remove_time_stamp( |
| 6644 | omxhdr->nTimeStamp, |
| 6645 | (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 6646 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6647 | omx->post_event ((unsigned)NULL,(unsigned int)omxhdr, |
| 6648 | OMX_COMPONENT_GENERATE_FTB); |
| 6649 | break; |
| 6650 | } |
| 6651 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 6652 | omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
| 6653 | } |
| 6654 | vdec_msg->msgdata.output_frame.bufferaddr = |
| 6655 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr; |
| 6656 | int format_notably_changed = 0; |
| 6657 | if (omxhdr->nFilledLen && |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6658 | (omxhdr->nFilledLen != (unsigned)omx->prev_n_filled_len)) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6659 | if ((vdec_msg->msgdata.output_frame.framesize.bottom != omx->drv_ctx.video_resolution.frame_height) || |
| 6660 | (vdec_msg->msgdata.output_frame.framesize.right != omx->drv_ctx.video_resolution.frame_width)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6661 | DEBUG_PRINT_HIGH("Height/Width information has changed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6662 | omx->drv_ctx.video_resolution.frame_height = vdec_msg->msgdata.output_frame.framesize.bottom; |
| 6663 | omx->drv_ctx.video_resolution.frame_width = vdec_msg->msgdata.output_frame.framesize.right; |
| 6664 | format_notably_changed = 1; |
| 6665 | } |
| 6666 | } |
| 6667 | if (omxhdr->nFilledLen && (((unsigned)omx->rectangle.nLeft != |
| 6668 | vdec_msg->msgdata.output_frame.framesize.left) |
| 6669 | || ((unsigned)omx->rectangle.nTop != vdec_msg->msgdata.output_frame.framesize.top) |
| 6670 | || (omx->rectangle.nWidth != vdec_msg->msgdata.output_frame.framesize.right) |
| 6671 | || (omx->rectangle.nHeight != vdec_msg->msgdata.output_frame.framesize.bottom))) { |
| 6672 | if ((vdec_msg->msgdata.output_frame.framesize.bottom != omx->drv_ctx.video_resolution.frame_height) || |
| 6673 | (vdec_msg->msgdata.output_frame.framesize.right != omx->drv_ctx.video_resolution.frame_width)) { |
| 6674 | omx->drv_ctx.video_resolution.frame_height = vdec_msg->msgdata.output_frame.framesize.bottom; |
| 6675 | omx->drv_ctx.video_resolution.frame_width = vdec_msg->msgdata.output_frame.framesize.right; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6676 | DEBUG_PRINT_HIGH("Height/Width information has changed. W: %d --> %d, H: %d --> %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6677 | omx->drv_ctx.video_resolution.frame_width, vdec_msg->msgdata.output_frame.framesize.right, |
| 6678 | omx->drv_ctx.video_resolution.frame_height, vdec_msg->msgdata.output_frame.framesize.bottom); |
| 6679 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6680 | DEBUG_PRINT_HIGH("Crop information changed. W: %lu --> %d, H: %lu -> %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6681 | omx->rectangle.nWidth, vdec_msg->msgdata.output_frame.framesize.right, |
| 6682 | omx->rectangle.nHeight, vdec_msg->msgdata.output_frame.framesize.bottom); |
Jayasena Sangaraboina | 20283de | 2013-08-13 11:41:41 -0700 | [diff] [blame] | 6683 | if (vdec_msg->msgdata.output_frame.framesize.left + vdec_msg->msgdata.output_frame.framesize.right >= |
| 6684 | omx->drv_ctx.video_resolution.frame_width) { |
| 6685 | vdec_msg->msgdata.output_frame.framesize.left = 0; |
| 6686 | if (vdec_msg->msgdata.output_frame.framesize.right > omx->drv_ctx.video_resolution.frame_width) { |
| 6687 | vdec_msg->msgdata.output_frame.framesize.right = omx->drv_ctx.video_resolution.frame_width; |
| 6688 | } |
| 6689 | } |
| 6690 | if (vdec_msg->msgdata.output_frame.framesize.top + vdec_msg->msgdata.output_frame.framesize.bottom >= |
| 6691 | omx->drv_ctx.video_resolution.frame_height) { |
| 6692 | vdec_msg->msgdata.output_frame.framesize.top = 0; |
| 6693 | if (vdec_msg->msgdata.output_frame.framesize.bottom > omx->drv_ctx.video_resolution.frame_height) { |
| 6694 | vdec_msg->msgdata.output_frame.framesize.bottom = omx->drv_ctx.video_resolution.frame_height; |
| 6695 | } |
| 6696 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6697 | DEBUG_PRINT_LOW("omx_vdec: Adjusted Dim L: %d, T: %d, R: %d, B: %d, W: %d, H: %d", |
Jayasena Sangaraboina | 20283de | 2013-08-13 11:41:41 -0700 | [diff] [blame] | 6698 | vdec_msg->msgdata.output_frame.framesize.left, |
| 6699 | vdec_msg->msgdata.output_frame.framesize.top, |
| 6700 | vdec_msg->msgdata.output_frame.framesize.right, |
| 6701 | vdec_msg->msgdata.output_frame.framesize.bottom, |
| 6702 | omx->drv_ctx.video_resolution.frame_width, |
| 6703 | omx->drv_ctx.video_resolution.frame_height); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6704 | omx->rectangle.nLeft = vdec_msg->msgdata.output_frame.framesize.left; |
| 6705 | omx->rectangle.nTop = vdec_msg->msgdata.output_frame.framesize.top; |
| 6706 | omx->rectangle.nWidth = vdec_msg->msgdata.output_frame.framesize.right; |
| 6707 | omx->rectangle.nHeight = vdec_msg->msgdata.output_frame.framesize.bottom; |
| 6708 | format_notably_changed = 1; |
| 6709 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6710 | DEBUG_PRINT_HIGH("Left: %d, Right: %d, top: %d, Bottom: %d", |
Jayasena Sangaraboina | 20283de | 2013-08-13 11:41:41 -0700 | [diff] [blame] | 6711 | vdec_msg->msgdata.output_frame.framesize.left,vdec_msg->msgdata.output_frame.framesize.right, |
| 6712 | vdec_msg->msgdata.output_frame.framesize.top, vdec_msg->msgdata.output_frame.framesize.bottom); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6713 | if (format_notably_changed) { |
| 6714 | if (omx->is_video_session_supported()) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6715 | omx->post_event (0, vdec_msg->status_code, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6716 | OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING); |
| 6717 | } else { |
| 6718 | if (!omx->client_buffers.update_buffer_req()) { |
| 6719 | DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed"); |
| 6720 | } |
| 6721 | omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexConfigCommonOutputCrop, |
| 6722 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
| 6723 | } |
| 6724 | } |
| 6725 | if (omxhdr->nFilledLen) |
| 6726 | omx->prev_n_filled_len = omxhdr->nFilledLen; |
| 6727 | |
| 6728 | output_respbuf = (struct vdec_output_frameinfo *)\ |
| 6729 | omxhdr->pOutputPortPrivate; |
| 6730 | output_respbuf->len = vdec_msg->msgdata.output_frame.len; |
| 6731 | output_respbuf->offset = vdec_msg->msgdata.output_frame.offset; |
| 6732 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) { |
| 6733 | output_respbuf->pic_type = PICTURE_TYPE_I; |
| 6734 | } |
| 6735 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) { |
| 6736 | output_respbuf->pic_type = PICTURE_TYPE_P; |
| 6737 | } |
| 6738 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) { |
| 6739 | output_respbuf->pic_type = PICTURE_TYPE_B; |
| 6740 | } |
| 6741 | |
| 6742 | if (omx->output_use_buffer) |
| 6743 | memcpy ( omxhdr->pBuffer, (void *) |
| 6744 | ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr + |
| 6745 | (unsigned long)vdec_msg->msgdata.output_frame.offset), |
| 6746 | vdec_msg->msgdata.output_frame.len); |
| 6747 | } else |
| 6748 | omxhdr->nFilledLen = 0; |
| 6749 | omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code, |
| 6750 | OMX_COMPONENT_GENERATE_FBD); |
| 6751 | } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) |
| 6752 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 6753 | OMX_COMPONENT_GENERATE_EOS_DONE); |
| 6754 | else |
| 6755 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 6756 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
| 6757 | break; |
| 6758 | case VDEC_MSG_EVT_CONFIG_CHANGED: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6759 | DEBUG_PRINT_HIGH("Port settings changed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6760 | omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition, |
| 6761 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
| 6762 | break; |
| 6763 | default: |
| 6764 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6765 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6766 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary ( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6770 | OMX_HANDLETYPE hComp, |
| 6771 | OMX_BUFFERHEADERTYPE *buffer |
| 6772 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6773 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6774 | unsigned address,p2,id; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6775 | DEBUG_PRINT_LOW("Empty this arbitrary"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6776 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6777 | if (buffer == NULL) { |
| 6778 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6779 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6780 | DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 6781 | DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6782 | buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp); |
| 6783 | |
| 6784 | /* return zero length and not an EOS buffer */ |
| 6785 | /* return buffer if input flush in progress */ |
| 6786 | if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) && |
| 6787 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6788 | DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6789 | m_cb.EmptyBufferDone (hComp,m_app_data,buffer); |
| 6790 | return OMX_ErrorNone; |
| 6791 | } |
| 6792 | |
| 6793 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6794 | DEBUG_PRINT_LOW("Set Buffer as source Buffer %p time stamp %lld",buffer,buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6795 | psource_frame = buffer; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6796 | DEBUG_PRINT_LOW("Try to Push One Input Buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6797 | push_input_buffer (hComp); |
| 6798 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6799 | DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6800 | if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL, |
| 6801 | (unsigned)NULL)) { |
| 6802 | return OMX_ErrorBadParameter; |
| 6803 | } |
| 6804 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6805 | |
| 6806 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6807 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp) |
| 6811 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6812 | unsigned address,p2,id; |
| 6813 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6814 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6815 | if (pdest_frame == NULL || psource_frame == NULL) { |
| 6816 | /*Check if we have a destination buffer*/ |
| 6817 | if (pdest_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6818 | DEBUG_PRINT_LOW("Get a Destination buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6819 | if (m_input_free_q.m_size) { |
| 6820 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 6821 | pdest_frame = (OMX_BUFFERHEADERTYPE *)address; |
| 6822 | pdest_frame->nFilledLen = 0; |
| 6823 | pdest_frame->nTimeStamp = LLONG_MAX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6824 | DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6825 | } |
| 6826 | } |
| 6827 | |
| 6828 | /*Check if we have a destination buffer*/ |
| 6829 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6830 | DEBUG_PRINT_LOW("Get a source buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6831 | if (m_input_pending_q.m_size) { |
| 6832 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 6833 | psource_frame = (OMX_BUFFERHEADERTYPE *)address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6834 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6835 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6836 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6837 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 6838 | |
| 6839 | } |
| 6840 | } |
| 6841 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6842 | } |
| 6843 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6844 | while ((pdest_frame != NULL) && (psource_frame != NULL)) { |
| 6845 | switch (codec_type_parse) { |
| 6846 | case CODEC_TYPE_MPEG4: |
| 6847 | case CODEC_TYPE_H263: |
| 6848 | case CODEC_TYPE_MPEG2: |
| 6849 | ret = push_input_sc_codec(hComp); |
| 6850 | break; |
| 6851 | case CODEC_TYPE_H264: |
| 6852 | ret = push_input_h264(hComp); |
| 6853 | break; |
| 6854 | case CODEC_TYPE_VC1: |
| 6855 | ret = push_input_vc1(hComp); |
| 6856 | break; |
| 6857 | default: |
| 6858 | break; |
| 6859 | } |
| 6860 | if (ret != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6861 | DEBUG_PRINT_ERROR("Pushing input Buffer Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6862 | omx_report_error (); |
| 6863 | break; |
| 6864 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6865 | } |
| 6866 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6867 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6868 | } |
| 6869 | |
| 6870 | OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp) |
| 6871 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6872 | OMX_U32 partial_frame = 1; |
| 6873 | OMX_BOOL generate_ebd = OMX_TRUE; |
| 6874 | unsigned address = 0, p2 = 0, id = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6875 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6876 | DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6877 | psource_frame,psource_frame->nTimeStamp); |
| 6878 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 6879 | pdest_frame,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6880 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6881 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6882 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6883 | |
| 6884 | if (partial_frame == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6885 | DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6886 | pdest_frame->nFilledLen,psource_frame,frame_count); |
| 6887 | |
| 6888 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6889 | DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6890 | /*First Parsed buffer will have only header Hence skip*/ |
| 6891 | if (frame_count == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6892 | DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6893 | |
| 6894 | if (codec_type_parse == CODEC_TYPE_MPEG4 || |
| 6895 | codec_type_parse == CODEC_TYPE_DIVX) { |
| 6896 | mp4StreamType psBits; |
| 6897 | psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset; |
| 6898 | psBits.numBytes = pdest_frame->nFilledLen; |
| 6899 | mp4_headerparser.parseHeader(&psBits); |
| 6900 | } |
| 6901 | |
| 6902 | frame_count++; |
| 6903 | } else { |
| 6904 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 6905 | if (pdest_frame->nFilledLen) { |
| 6906 | /*Push the frame to the Decoder*/ |
| 6907 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 6908 | return OMX_ErrorBadParameter; |
| 6909 | } |
| 6910 | frame_count++; |
| 6911 | pdest_frame = NULL; |
| 6912 | |
| 6913 | if (m_input_free_q.m_size) { |
| 6914 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 6915 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
| 6916 | pdest_frame->nFilledLen = 0; |
| 6917 | } |
| 6918 | } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6919 | DEBUG_PRINT_ERROR("Zero len buffer return back to POOL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6920 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL, |
| 6921 | (unsigned)NULL); |
| 6922 | pdest_frame = NULL; |
| 6923 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6924 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6925 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6926 | DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6927 | /*Check if Destination Buffer is full*/ |
| 6928 | if (pdest_frame->nAllocLen == |
| 6929 | pdest_frame->nFilledLen + pdest_frame->nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6930 | DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6931 | return OMX_ErrorStreamCorrupt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6932 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6933 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6934 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6935 | if (psource_frame->nFilledLen == 0) { |
| 6936 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6937 | if (pdest_frame) { |
| 6938 | pdest_frame->nFlags |= psource_frame->nFlags; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6939 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6940 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6941 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6942 | pdest_frame->nFilledLen,frame_count++); |
| 6943 | /*Push the frame to the Decoder*/ |
| 6944 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 6945 | return OMX_ErrorBadParameter; |
| 6946 | } |
| 6947 | frame_count++; |
| 6948 | pdest_frame = NULL; |
| 6949 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6950 | DEBUG_PRINT_LOW("Last frame in else dest addr") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6951 | generate_ebd = OMX_FALSE; |
| 6952 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6953 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6954 | if (generate_ebd) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6955 | DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6956 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 6957 | psource_frame = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6958 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6959 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6960 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6961 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 6962 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6963 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6964 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6965 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6966 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 6967 | } |
| 6968 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6969 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6970 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp) |
| 6974 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6975 | OMX_U32 partial_frame = 1; |
| 6976 | unsigned address = 0, p2 = 0, id = 0; |
| 6977 | OMX_BOOL isNewFrame = OMX_FALSE; |
| 6978 | OMX_BOOL generate_ebd = OMX_TRUE; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6979 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6980 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6981 | DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6982 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6983 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6984 | DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6985 | "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6986 | DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6987 | if (h264_scratch.nFilledLen && look_ahead_nal) { |
| 6988 | look_ahead_nal = false; |
| 6989 | if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 6990 | h264_scratch.nFilledLen) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6991 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 6992 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 6993 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6994 | DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6995 | h264_scratch.nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6996 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6997 | DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6998 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6999 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7000 | } |
Praveen Chavan | ce0b5e8 | 2013-08-08 05:23:34 -0700 | [diff] [blame] | 7001 | |
| 7002 | /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result |
| 7003 | in EOS flag getting associated with the destination |
| 7004 | */ |
| 7005 | if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) && |
| 7006 | pdest_frame->nFilledLen) { |
| 7007 | DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'"); |
| 7008 | generate_ebd = OMX_FALSE; |
| 7009 | } |
| 7010 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7011 | if (nal_length == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7012 | DEBUG_PRINT_LOW("Zero NAL, hence parse using start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7013 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7014 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7015 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7016 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7017 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7018 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7019 | DEBUG_PRINT_LOW("Non-zero NAL length clip, hence parse with NAL size %d ",nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7020 | if (m_frame_parser.parse_h264_nallength(psource_frame, |
| 7021 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7022 | DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7023 | return OMX_ErrorBadParameter; |
| 7024 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7025 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7026 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7027 | if (partial_frame == 0) { |
| 7028 | if (nal_count == 0 && h264_scratch.nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7029 | DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7030 | nal_count++; |
| 7031 | h264_scratch.nTimeStamp = psource_frame->nTimeStamp; |
| 7032 | h264_scratch.nFlags = psource_frame->nFlags; |
| 7033 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7034 | DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7035 | if (h264_scratch.nFilledLen) { |
| 7036 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen, |
| 7037 | NALU_TYPE_SPS); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7038 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7039 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) |
| 7040 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7041 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
| 7042 | else if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7043 | // If timeinfo is present frame info from SEI is already processed |
| 7044 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7045 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7046 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7047 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7048 | nal_count++; |
| 7049 | if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) { |
| 7050 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7051 | pdest_frame->nFlags = h264_last_au_flags; |
| 7052 | #ifdef PANSCAN_HDLR |
| 7053 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7054 | h264_parser->update_panscan_data(h264_last_au_ts); |
| 7055 | #endif |
| 7056 | } |
| 7057 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR || |
| 7058 | m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) { |
| 7059 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7060 | h264_last_au_flags = h264_scratch.nFlags; |
| 7061 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7062 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7063 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts); |
| 7064 | if (!VALID_TS(h264_last_au_ts)) |
| 7065 | h264_last_au_ts = ts_in_sei; |
| 7066 | } |
| 7067 | #endif |
| 7068 | } else |
| 7069 | h264_last_au_ts = LLONG_MAX; |
| 7070 | } |
| 7071 | |
| 7072 | if (!isNewFrame) { |
| 7073 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7074 | h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7075 | DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7076 | h264_scratch.nFilledLen); |
| 7077 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7078 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7079 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7080 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ) |
| 7081 | pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7082 | h264_scratch.nFilledLen = 0; |
| 7083 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7084 | DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7085 | return OMX_ErrorBadParameter; |
| 7086 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7087 | } else if(h264_scratch.nFilledLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7088 | look_ahead_nal = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7089 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7090 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7091 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7092 | pdest_frame->nFilledLen,frame_count++); |
| 7093 | |
| 7094 | if (pdest_frame->nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7095 | DEBUG_PRINT_LOW("Copy the Current Frame since and push it"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7096 | look_ahead_nal = false; |
| 7097 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7098 | h264_scratch.nFilledLen) { |
| 7099 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7100 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7101 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7102 | h264_scratch.nFilledLen = 0; |
| 7103 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7104 | DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7105 | return OMX_ErrorBadParameter; |
| 7106 | } |
| 7107 | } else { |
| 7108 | if (psource_frame->nFilledLen || h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7109 | DEBUG_PRINT_LOW("Reset the EOS Flag"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7110 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7111 | } |
| 7112 | /*Push the frame to the Decoder*/ |
| 7113 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7114 | return OMX_ErrorBadParameter; |
| 7115 | } |
| 7116 | //frame_count++; |
| 7117 | pdest_frame = NULL; |
| 7118 | if (m_input_free_q.m_size) { |
| 7119 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7120 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7121 | DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7122 | pdest_frame->nFilledLen = 0; |
| 7123 | pdest_frame->nFlags = 0; |
| 7124 | pdest_frame->nTimeStamp = LLONG_MAX; |
| 7125 | } |
| 7126 | } |
| 7127 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7128 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7129 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7130 | DEBUG_PRINT_LOW("Not a Complete Frame, pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7131 | /*Check if Destination Buffer is full*/ |
| 7132 | if (h264_scratch.nAllocLen == |
| 7133 | h264_scratch.nFilledLen + h264_scratch.nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7134 | DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7135 | return OMX_ErrorStreamCorrupt; |
| 7136 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7137 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7138 | |
| 7139 | if (!psource_frame->nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7140 | DEBUG_PRINT_LOW("Buffer Consumed return source %p back to client",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7141 | |
| 7142 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7143 | if (pdest_frame) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7144 | DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7145 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7146 | h264_scratch.nFilledLen) { |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7147 | if(pdest_frame->nFilledLen == 0) { |
| 7148 | /* No residual frame from before, send whatever |
| 7149 | * we have left */ |
| 7150 | memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7151 | h264_scratch.pBuffer, h264_scratch.nFilledLen); |
| 7152 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7153 | h264_scratch.nFilledLen = 0; |
| 7154 | pdest_frame->nTimeStamp = h264_scratch.nTimeStamp; |
| 7155 | } else { |
| 7156 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7157 | if(!isNewFrame) { |
| 7158 | /* Have a residual frame, but we know that the |
| 7159 | * AU in this frame is belonging to whatever |
| 7160 | * frame we had left over. So append it */ |
| 7161 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7162 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7163 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7164 | h264_scratch.nFilledLen = 0; |
| 7165 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7166 | } else { |
| 7167 | /* Completely new frame, let's just push what |
| 7168 | * we have now. The resulting EBD would trigger |
| 7169 | * another push */ |
| 7170 | generate_ebd = OMX_FALSE; |
| 7171 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7172 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7173 | } |
| 7174 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7175 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7176 | DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7177 | return OMX_ErrorBadParameter; |
| 7178 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7179 | |
| 7180 | /* Iff we coalesced two buffers, inherit the flags of both bufs */ |
| 7181 | if(generate_ebd == OMX_TRUE) { |
| 7182 | pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags; |
| 7183 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7184 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7185 | DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7186 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7187 | DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7188 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7189 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7190 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp); |
| 7191 | if (!VALID_TS(pdest_frame->nTimeStamp)) |
| 7192 | pdest_frame->nTimeStamp = ts_in_sei; |
| 7193 | } |
| 7194 | #endif |
| 7195 | /*Push the frame to the Decoder*/ |
| 7196 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7197 | return OMX_ErrorBadParameter; |
| 7198 | } |
| 7199 | frame_count++; |
| 7200 | pdest_frame = NULL; |
| 7201 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7202 | DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7203 | pdest_frame,h264_scratch.nFilledLen); |
| 7204 | generate_ebd = OMX_FALSE; |
| 7205 | } |
| 7206 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7207 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7208 | if (generate_ebd && !psource_frame->nFilledLen) { |
| 7209 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7210 | psource_frame = NULL; |
| 7211 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7212 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7213 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7214 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7215 | DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7216 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7217 | } |
| 7218 | } |
| 7219 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp) |
| 7223 | { |
| 7224 | OMX_U8 *buf, *pdest; |
| 7225 | OMX_U32 partial_frame = 1; |
| 7226 | OMX_U32 buf_len, dest_len; |
| 7227 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7228 | if (first_frame == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7229 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7230 | DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7231 | if (!m_vendor_config.pData) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7232 | DEBUG_PRINT_LOW("Check profile type in 1st source buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7233 | buf = psource_frame->pBuffer; |
| 7234 | buf_len = psource_frame->nFilledLen; |
| 7235 | |
| 7236 | if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) == |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7237 | VC1_SP_MP_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7238 | m_vc1_profile = VC1_SP_MP_RCV; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7239 | } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7240 | m_vc1_profile = VC1_AP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7241 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7242 | DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7243 | return OMX_ErrorStreamCorrupt; |
| 7244 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7245 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7246 | pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen + |
| 7247 | pdest_frame->nOffset; |
| 7248 | dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen + |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7249 | pdest_frame->nOffset); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7250 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7251 | if (dest_len < m_vendor_config.nDataSize) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7252 | DEBUG_PRINT_ERROR("Destination buffer full"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7253 | return OMX_ErrorBadParameter; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7254 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7255 | memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize); |
| 7256 | pdest_frame->nFilledLen += m_vendor_config.nDataSize; |
| 7257 | } |
| 7258 | } |
| 7259 | } |
| 7260 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7261 | switch (m_vc1_profile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7262 | case VC1_AP: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7263 | DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7264 | if (push_input_sc_codec(hComp) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7265 | DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7266 | return OMX_ErrorBadParameter; |
| 7267 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7268 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7269 | |
| 7270 | case VC1_SP_MP_RCV: |
| 7271 | default: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7272 | DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7273 | return OMX_ErrorBadParameter; |
| 7274 | } |
| 7275 | return OMX_ErrorNone; |
| 7276 | } |
| 7277 | |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7278 | #ifndef USE_ION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7279 | bool omx_vdec::align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7280 | OMX_U32 alignment) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7281 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7282 | struct pmem_allocation allocation; |
| 7283 | allocation.size = buffer_size; |
| 7284 | allocation.align = clip2(alignment); |
| 7285 | if (allocation.align < 4096) { |
| 7286 | allocation.align = 4096; |
| 7287 | } |
| 7288 | if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7289 | DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7290 | allocation.align, allocation.size); |
| 7291 | return false; |
| 7292 | } |
| 7293 | return true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7294 | } |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7295 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7296 | #ifdef USE_ION |
| 7297 | int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7298 | OMX_U32 alignment, struct ion_allocation_data *alloc_data, |
| 7299 | struct ion_fd_data *fd_data, int flag) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7300 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7301 | int fd = -EINVAL; |
| 7302 | int rc = -EINVAL; |
| 7303 | int ion_dev_flag; |
| 7304 | struct vdec_ion ion_buf_info; |
| 7305 | if (!alloc_data || buffer_size <= 0 || !fd_data) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7306 | DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7307 | return -EINVAL; |
| 7308 | } |
| 7309 | ion_dev_flag = O_RDONLY; |
| 7310 | fd = open (MEM_DEVICE, ion_dev_flag); |
| 7311 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7312 | DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7313 | return fd; |
| 7314 | } |
| 7315 | alloc_data->flags = 0; |
| 7316 | if (!secure_mode && (flag & ION_FLAG_CACHED)) { |
| 7317 | alloc_data->flags |= ION_FLAG_CACHED; |
| 7318 | } |
| 7319 | alloc_data->len = buffer_size; |
| 7320 | alloc_data->align = clip2(alignment); |
| 7321 | if (alloc_data->align < 4096) { |
| 7322 | alloc_data->align = 4096; |
| 7323 | } |
| 7324 | if ((secure_mode) && (flag & ION_SECURE)) |
| 7325 | alloc_data->flags |= ION_SECURE; |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 7326 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7327 | alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID); |
| 7328 | if (secure_mode) |
| 7329 | alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID); |
| 7330 | rc = ioctl(fd,ION_IOC_ALLOC,alloc_data); |
| 7331 | if (rc || !alloc_data->handle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7332 | DEBUG_PRINT_ERROR("ION ALLOC memory failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7333 | alloc_data->handle = NULL; |
| 7334 | close(fd); |
| 7335 | fd = -ENOMEM; |
| 7336 | return fd; |
| 7337 | } |
| 7338 | fd_data->handle = alloc_data->handle; |
| 7339 | rc = ioctl(fd,ION_IOC_MAP,fd_data); |
| 7340 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7341 | DEBUG_PRINT_ERROR("ION MAP failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7342 | ion_buf_info.ion_alloc_data = *alloc_data; |
| 7343 | ion_buf_info.ion_device_fd = fd; |
| 7344 | ion_buf_info.fd_ion_data = *fd_data; |
| 7345 | free_ion_memory(&ion_buf_info); |
| 7346 | fd_data->fd =-1; |
| 7347 | close(fd); |
| 7348 | fd = -ENOMEM; |
| 7349 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7350 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7351 | return fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7352 | } |
| 7353 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7354 | void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info) |
| 7355 | { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7356 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7357 | if (!buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7358 | DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7359 | return; |
| 7360 | } |
| 7361 | if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE, |
| 7362 | &buf_ion_info->ion_alloc_data.handle)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7363 | DEBUG_PRINT_ERROR("ION: free failed" ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7364 | } |
| 7365 | close(buf_ion_info->ion_device_fd); |
| 7366 | buf_ion_info->ion_device_fd = -1; |
| 7367 | buf_ion_info->ion_alloc_data.handle = NULL; |
| 7368 | buf_ion_info->fd_ion_data.fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7369 | } |
| 7370 | #endif |
| 7371 | void omx_vdec::free_output_buffer_header() |
| 7372 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7373 | DEBUG_PRINT_HIGH("ALL output buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7374 | output_use_buffer = false; |
| 7375 | ouput_egl_buffers = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7376 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7377 | if (m_out_mem_ptr) { |
| 7378 | free (m_out_mem_ptr); |
| 7379 | m_out_mem_ptr = NULL; |
| 7380 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7381 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7382 | if (m_platform_list) { |
| 7383 | free(m_platform_list); |
| 7384 | m_platform_list = NULL; |
| 7385 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7386 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7387 | if (drv_ctx.ptr_respbuffer) { |
| 7388 | free (drv_ctx.ptr_respbuffer); |
| 7389 | drv_ctx.ptr_respbuffer = NULL; |
| 7390 | } |
| 7391 | if (drv_ctx.ptr_outputbuffer) { |
| 7392 | free (drv_ctx.ptr_outputbuffer); |
| 7393 | drv_ctx.ptr_outputbuffer = NULL; |
| 7394 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7395 | #ifdef USE_ION |
| 7396 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7397 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7398 | free(drv_ctx.op_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7399 | drv_ctx.op_buf_ion_info = NULL; |
| 7400 | } |
| 7401 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7402 | if (out_dynamic_list) { |
| 7403 | free(out_dynamic_list); |
| 7404 | out_dynamic_list = NULL; |
| 7405 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | void omx_vdec::free_input_buffer_header() |
| 7409 | { |
| 7410 | input_use_buffer = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7411 | if (arbitrary_bytes) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7412 | if (m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7413 | DEBUG_PRINT_LOW("Free input Heap Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7414 | free (m_inp_heap_ptr); |
| 7415 | m_inp_heap_ptr = NULL; |
| 7416 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7417 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7418 | if (m_phdr_pmem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7419 | DEBUG_PRINT_LOW("Free input pmem header Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7420 | free (m_phdr_pmem_ptr); |
| 7421 | m_phdr_pmem_ptr = NULL; |
| 7422 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7423 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7424 | if (m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7425 | DEBUG_PRINT_LOW("Free input pmem Pointer area"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7426 | free (m_inp_mem_ptr); |
| 7427 | m_inp_mem_ptr = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7428 | } |
Leena Winterrowd | 1d2424a | 2013-08-20 15:26:02 -0700 | [diff] [blame] | 7429 | /* We just freed all the buffer headers, every thing in m_input_free_q |
| 7430 | * is now invalid */ |
| 7431 | while (m_input_free_q.m_size) { |
| 7432 | unsigned address, p2, id; |
| 7433 | m_input_free_q.pop_entry(&address, &p2, &id); |
| 7434 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7435 | if (drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7436 | DEBUG_PRINT_LOW("Free Driver Context pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7437 | free (drv_ctx.ptr_inputbuffer); |
| 7438 | drv_ctx.ptr_inputbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7439 | } |
| 7440 | #ifdef USE_ION |
| 7441 | if (drv_ctx.ip_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7442 | DEBUG_PRINT_LOW("Free ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7443 | free(drv_ctx.ip_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7444 | drv_ctx.ip_buf_ion_info = NULL; |
| 7445 | } |
| 7446 | #endif |
| 7447 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7448 | |
| 7449 | int omx_vdec::stream_off(OMX_U32 port) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7450 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7451 | enum v4l2_buf_type btype; |
| 7452 | int rc = 0; |
| 7453 | enum v4l2_ports v4l2_port = OUTPUT_PORT; |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7454 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7455 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 7456 | btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7457 | v4l2_port = OUTPUT_PORT; |
| 7458 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 7459 | btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7460 | v4l2_port = CAPTURE_PORT; |
| 7461 | } else if (port == OMX_ALL) { |
| 7462 | int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX); |
| 7463 | int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7464 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7465 | if (!rc_input) |
| 7466 | return rc_input; |
| 7467 | else |
| 7468 | return rc_output; |
| 7469 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7470 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7471 | if (!streaming[v4l2_port]) { |
| 7472 | // already streamed off, warn and move on |
| 7473 | DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port," |
| 7474 | " which is already streamed off", v4l2_port); |
| 7475 | return 0; |
| 7476 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7477 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7478 | DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7479 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7480 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype); |
| 7481 | if (rc) { |
| 7482 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7483 | DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7484 | } else { |
| 7485 | streaming[v4l2_port] = false; |
| 7486 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7487 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7488 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7489 | } |
| 7490 | |
| 7491 | OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 7492 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7493 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 7494 | struct v4l2_requestbuffers bufreq; |
| 7495 | unsigned int buf_size = 0, extra_data_size = 0, client_extra_data_size = 0; |
| 7496 | struct v4l2_format fmt; |
| 7497 | int ret = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7498 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7499 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 7500 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 7501 | bufreq.count = 1; |
| 7502 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 7503 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7504 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7505 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 7506 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 7507 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7508 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7509 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 7510 | } else { |
| 7511 | eRet = OMX_ErrorBadParameter; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 7512 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7513 | if (eRet==OMX_ErrorNone) { |
| 7514 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7515 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7516 | if (ret) { |
| 7517 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 7518 | /*TODO: How to handle this case */ |
| 7519 | eRet = OMX_ErrorInsufficientResources; |
| 7520 | return eRet; |
| 7521 | } else { |
| 7522 | buffer_prop->actualcount = bufreq.count; |
| 7523 | buffer_prop->mincount = bufreq.count; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7524 | DEBUG_PRINT_HIGH("Count = %d",bufreq.count); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7525 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7526 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
| 7527 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 7528 | |
| 7529 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 7530 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 7531 | |
| 7532 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 7533 | |
| 7534 | update_resolution(fmt.fmt.pix_mp.width, |
| 7535 | fmt.fmt.pix_mp.height, |
| 7536 | fmt.fmt.pix_mp.plane_fmt[0].bytesperline, |
| 7537 | fmt.fmt.pix_mp.plane_fmt[0].reserved[0]); |
| 7538 | if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 7539 | drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7540 | DEBUG_PRINT_HIGH("Buffer Size = %d",fmt.fmt.pix_mp.plane_fmt[0].sizeimage); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7541 | |
| 7542 | if (ret) { |
| 7543 | /*TODO: How to handle this case */ |
| 7544 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 7545 | eRet = OMX_ErrorInsufficientResources; |
| 7546 | } else { |
| 7547 | int extra_idx = 0; |
| 7548 | |
| 7549 | eRet = is_video_session_supported(); |
| 7550 | if (eRet) |
| 7551 | return eRet; |
| 7552 | |
| 7553 | buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage; |
| 7554 | buf_size = buffer_prop->buffer_size; |
| 7555 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 7556 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 7557 | extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage; |
| 7558 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7559 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7560 | return OMX_ErrorBadParameter; |
| 7561 | } |
| 7562 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) { |
| 7563 | DEBUG_PRINT_HIGH("Frame info extra data enabled!"); |
| 7564 | client_extra_data_size += OMX_FRAMEINFO_EXTRADATA_SIZE; |
| 7565 | } |
| 7566 | if (client_extradata & OMX_INTERLACE_EXTRADATA) { |
| 7567 | client_extra_data_size += OMX_INTERLACE_EXTRADATA_SIZE; |
| 7568 | } |
| 7569 | if (client_extradata & OMX_PORTDEF_EXTRADATA) { |
| 7570 | client_extra_data_size += OMX_PORTDEF_EXTRADATA_SIZE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7571 | DEBUG_PRINT_HIGH("Smooth streaming enabled extra_data_size=%d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7572 | client_extra_data_size); |
| 7573 | } |
| 7574 | if (client_extra_data_size) { |
| 7575 | client_extra_data_size += sizeof(OMX_OTHER_EXTRADATATYPE); //Space for terminator |
| 7576 | buf_size = ((buf_size + 3)&(~3)); //Align extradata start address to 64Bit |
| 7577 | } |
| 7578 | drv_ctx.extradata_info.size = buffer_prop->actualcount * extra_data_size; |
| 7579 | drv_ctx.extradata_info.count = buffer_prop->actualcount; |
| 7580 | drv_ctx.extradata_info.buffer_size = extra_data_size; |
| 7581 | buf_size += client_extra_data_size; |
| 7582 | buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 7583 | DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)", |
| 7584 | buffer_prop->actualcount, buffer_prop->buffer_size, buf_size); |
| 7585 | if (in_reconfig) // BufReq will be set to driver when port is disabled |
| 7586 | buffer_prop->buffer_size = buf_size; |
| 7587 | else if (buf_size != buffer_prop->buffer_size) { |
| 7588 | buffer_prop->buffer_size = buf_size; |
| 7589 | eRet = set_buffer_req(buffer_prop); |
| 7590 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7591 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7592 | DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)", |
| 7593 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 7594 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 7598 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7599 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 7600 | unsigned buf_size = 0; |
| 7601 | struct v4l2_format fmt; |
| 7602 | struct v4l2_requestbuffers bufreq; |
| 7603 | int ret; |
| 7604 | DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)", |
| 7605 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 7606 | buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 7607 | if (buf_size != buffer_prop->buffer_size) { |
| 7608 | DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)", |
| 7609 | buffer_prop->buffer_size, buf_size); |
| 7610 | eRet = OMX_ErrorBadParameter; |
| 7611 | } else { |
| 7612 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 7613 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 7614 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7615 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 7616 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7617 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Shalaj Jain | d3902bb | 2013-10-07 12:42:55 -0700 | [diff] [blame] | 7618 | fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7619 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 7620 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7621 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 7622 | } else { |
| 7623 | eRet = OMX_ErrorBadParameter; |
| 7624 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 7625 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7626 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 7627 | if (ret) { |
| 7628 | /*TODO: How to handle this case */ |
| 7629 | DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret); |
| 7630 | eRet = OMX_ErrorInsufficientResources; |
| 7631 | } |
| 7632 | |
| 7633 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 7634 | bufreq.count = buffer_prop->actualcount; |
| 7635 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 7636 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7637 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 7638 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7639 | } else { |
| 7640 | eRet = OMX_ErrorBadParameter; |
| 7641 | } |
| 7642 | |
| 7643 | if (eRet==OMX_ErrorNone) { |
| 7644 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
| 7645 | } |
| 7646 | |
| 7647 | if (ret) { |
| 7648 | DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret); |
| 7649 | /*TODO: How to handle this case */ |
| 7650 | eRet = OMX_ErrorInsufficientResources; |
| 7651 | } else if (bufreq.count < buffer_prop->actualcount) { |
| 7652 | DEBUG_PRINT_ERROR("Driver refused to change the number of buffers" |
| 7653 | " on v4l2 port %d to %d (prefers %d)", bufreq.type, |
| 7654 | buffer_prop->actualcount, bufreq.count); |
| 7655 | eRet = OMX_ErrorInsufficientResources; |
| 7656 | } else { |
| 7657 | if (!client_buffers.update_buffer_req()) { |
| 7658 | DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed"); |
| 7659 | eRet = OMX_ErrorInsufficientResources; |
| 7660 | } |
| 7661 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7662 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7663 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7664 | } |
| 7665 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7666 | OMX_ERRORTYPE omx_vdec::update_picture_resolution() |
| 7667 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7668 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 7669 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn) |
| 7673 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7674 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 7675 | if (!portDefn) { |
| 7676 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 7677 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7678 | DEBUG_PRINT_LOW("omx_vdec::update_portdef"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7679 | portDefn->nVersion.nVersion = OMX_SPEC_VERSION; |
| 7680 | portDefn->nSize = sizeof(portDefn); |
| 7681 | portDefn->eDomain = OMX_PortDomainVideo; |
| 7682 | if (drv_ctx.frame_rate.fps_denominator > 0) |
| 7683 | portDefn->format.video.xFramerate = drv_ctx.frame_rate.fps_numerator / |
| 7684 | drv_ctx.frame_rate.fps_denominator; |
| 7685 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7686 | DEBUG_PRINT_ERROR("Error: Divide by zero"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7687 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 7688 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7689 | if (0 == portDefn->nPortIndex) { |
| 7690 | portDefn->eDir = OMX_DirInput; |
| 7691 | portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount; |
| 7692 | portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount; |
| 7693 | portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size; |
| 7694 | portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused; |
| 7695 | portDefn->format.video.eCompressionFormat = eCompressionFormat; |
| 7696 | portDefn->bEnabled = m_inp_bEnabled; |
| 7697 | portDefn->bPopulated = m_inp_bPopulated; |
| 7698 | } else if (1 == portDefn->nPortIndex) { |
| 7699 | unsigned int buf_size = 0; |
| 7700 | if (!client_buffers.update_buffer_req()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7701 | DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7702 | return OMX_ErrorHardware; |
| 7703 | } |
| 7704 | if (!client_buffers.get_buffer_req(buf_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7705 | DEBUG_PRINT_ERROR("update buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7706 | return OMX_ErrorHardware; |
| 7707 | } |
| 7708 | portDefn->nBufferSize = buf_size; |
| 7709 | portDefn->eDir = OMX_DirOutput; |
| 7710 | portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount; |
| 7711 | portDefn->nBufferCountMin = drv_ctx.op_buf.mincount; |
| 7712 | portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 7713 | portDefn->bEnabled = m_out_bEnabled; |
| 7714 | portDefn->bPopulated = m_out_bPopulated; |
| 7715 | if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7716 | DEBUG_PRINT_ERROR("Error in getting color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7717 | return OMX_ErrorHardware; |
| 7718 | } |
| 7719 | } else { |
| 7720 | portDefn->eDir = OMX_DirMax; |
| 7721 | DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d", |
| 7722 | (int)portDefn->nPortIndex); |
| 7723 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7724 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7725 | portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height; |
| 7726 | portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width; |
| 7727 | portDefn->format.video.nStride = drv_ctx.video_resolution.stride; |
| 7728 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines; |
| 7729 | DEBUG_PRINT_HIGH("update_portdef Width = %lu Height = %lu Stride = %ld" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7730 | " SliceHeight = %lu", portDefn->format.video.nFrameWidth, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7731 | portDefn->format.video.nFrameHeight, |
| 7732 | portDefn->format.video.nStride, |
| 7733 | portDefn->format.video.nSliceHeight); |
| 7734 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7735 | |
| 7736 | } |
| 7737 | |
| 7738 | OMX_ERRORTYPE omx_vdec::allocate_output_headers() |
| 7739 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7740 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 7741 | OMX_BUFFERHEADERTYPE *bufHdr = NULL; |
| 7742 | unsigned i= 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7743 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7744 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7745 | DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7746 | int nBufHdrSize = 0; |
| 7747 | int nPlatformEntrySize = 0; |
| 7748 | int nPlatformListSize = 0; |
| 7749 | int nPMEMInfoSize = 0; |
| 7750 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 7751 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 7752 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7753 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7754 | DEBUG_PRINT_LOW("Setting First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7755 | drv_ctx.op_buf.actualcount); |
| 7756 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 7757 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7758 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7759 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 7760 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 7761 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 7762 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 7763 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 7764 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7765 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7766 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7767 | sizeof(OMX_BUFFERHEADERTYPE), |
| 7768 | nPMEMInfoSize, |
| 7769 | nPlatformListSize); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7770 | DEBUG_PRINT_LOW("PE %d bmSize %d",nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7771 | m_out_bm_count); |
| 7772 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 7773 | // Alloc mem for platform specific info |
| 7774 | char *pPtr=NULL; |
| 7775 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 7776 | nPMEMInfoSize,1); |
| 7777 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \ |
| 7778 | calloc (sizeof(struct vdec_bufferpayload), |
| 7779 | drv_ctx.op_buf.actualcount); |
| 7780 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 7781 | calloc (sizeof (struct vdec_output_frameinfo), |
| 7782 | drv_ctx.op_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7783 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7784 | drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \ |
| 7785 | calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7786 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7787 | if (dynamic_buf_mode) { |
| 7788 | out_dynamic_list = (struct dynamic_buf_list *) \ |
| 7789 | calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount); |
| 7790 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7791 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 7792 | && drv_ctx.ptr_respbuffer) { |
| 7793 | bufHdr = m_out_mem_ptr; |
| 7794 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 7795 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 7796 | (((char *) m_platform_list) + nPlatformListSize); |
| 7797 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 7798 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 7799 | pPlatformList = m_platform_list; |
| 7800 | pPlatformEntry = m_platform_entry; |
| 7801 | pPMEMInfo = m_pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7802 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7803 | DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p",m_out_mem_ptr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7804 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7805 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7806 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7807 | m_out_mem_ptr,pPlatformEntry); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7808 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7809 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 7810 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 7811 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 7812 | // Set the values when we determine the right HxW param |
| 7813 | bufHdr->nAllocLen = 0; |
| 7814 | bufHdr->nFilledLen = 0; |
| 7815 | bufHdr->pAppPrivate = NULL; |
| 7816 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 7817 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 7818 | pPlatformEntry->entry = pPMEMInfo; |
| 7819 | // Initialize the Platform List |
| 7820 | pPlatformList->nEntries = 1; |
| 7821 | pPlatformList->entryList = pPlatformEntry; |
| 7822 | // Keep pBuffer NULL till vdec is opened |
| 7823 | bufHdr->pBuffer = NULL; |
| 7824 | pPMEMInfo->offset = 0; |
| 7825 | pPMEMInfo->pmem_fd = 0; |
| 7826 | bufHdr->pPlatformPrivate = pPlatformList; |
| 7827 | drv_ctx.ptr_outputbuffer[i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7828 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7829 | drv_ctx.op_buf_ion_info[i].ion_device_fd =-1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7830 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7831 | /*Create a mapping between buffers*/ |
| 7832 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 7833 | drv_ctx.ptr_respbuffer[i].client_data = (void *) \ |
| 7834 | &drv_ctx.ptr_outputbuffer[i]; |
| 7835 | // Move the buffer and buffer header pointers |
| 7836 | bufHdr++; |
| 7837 | pPMEMInfo++; |
| 7838 | pPlatformEntry++; |
| 7839 | pPlatformList++; |
| 7840 | } |
| 7841 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7842 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7843 | m_out_mem_ptr, pPtr); |
| 7844 | if (m_out_mem_ptr) { |
| 7845 | free(m_out_mem_ptr); |
| 7846 | m_out_mem_ptr = NULL; |
| 7847 | } |
| 7848 | if (pPtr) { |
| 7849 | free(pPtr); |
| 7850 | pPtr = NULL; |
| 7851 | } |
| 7852 | if (drv_ctx.ptr_outputbuffer) { |
| 7853 | free(drv_ctx.ptr_outputbuffer); |
| 7854 | drv_ctx.ptr_outputbuffer = NULL; |
| 7855 | } |
| 7856 | if (drv_ctx.ptr_respbuffer) { |
| 7857 | free(drv_ctx.ptr_respbuffer); |
| 7858 | drv_ctx.ptr_respbuffer = NULL; |
| 7859 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7860 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7861 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7862 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7863 | free(drv_ctx.op_buf_ion_info); |
| 7864 | drv_ctx.op_buf_ion_info = NULL; |
| 7865 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7866 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7867 | eRet = OMX_ErrorInsufficientResources; |
| 7868 | } |
| 7869 | } else { |
| 7870 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7871 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7872 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | void omx_vdec::complete_pending_buffer_done_cbs() |
| 7876 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7877 | unsigned p1; |
| 7878 | unsigned p2; |
| 7879 | unsigned ident; |
| 7880 | omx_cmd_queue tmp_q, pending_bd_q; |
| 7881 | pthread_mutex_lock(&m_lock); |
| 7882 | // pop all pending GENERATE FDB from ftb queue |
| 7883 | while (m_ftb_q.m_size) { |
| 7884 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
| 7885 | if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 7886 | pending_bd_q.insert_entry(p1,p2,ident); |
| 7887 | } else { |
| 7888 | tmp_q.insert_entry(p1,p2,ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7889 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7890 | } |
| 7891 | //return all non GENERATE FDB to ftb queue |
| 7892 | while (tmp_q.m_size) { |
| 7893 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 7894 | m_ftb_q.insert_entry(p1,p2,ident); |
| 7895 | } |
| 7896 | // pop all pending GENERATE EDB from etb queue |
| 7897 | while (m_etb_q.m_size) { |
| 7898 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 7899 | if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 7900 | pending_bd_q.insert_entry(p1,p2,ident); |
| 7901 | } else { |
| 7902 | tmp_q.insert_entry(p1,p2,ident); |
| 7903 | } |
| 7904 | } |
| 7905 | //return all non GENERATE FDB to etb queue |
| 7906 | while (tmp_q.m_size) { |
| 7907 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 7908 | m_etb_q.insert_entry(p1,p2,ident); |
| 7909 | } |
| 7910 | pthread_mutex_unlock(&m_lock); |
| 7911 | // process all pending buffer dones |
| 7912 | while (pending_bd_q.m_size) { |
| 7913 | pending_bd_q.pop_entry(&p1,&p2,&ident); |
| 7914 | switch (ident) { |
| 7915 | case OMX_COMPONENT_GENERATE_EBD: |
| 7916 | if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7917 | DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7918 | omx_report_error (); |
| 7919 | } |
| 7920 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7921 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7922 | case OMX_COMPONENT_GENERATE_FBD: |
| 7923 | if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7924 | DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7925 | omx_report_error (); |
| 7926 | } |
| 7927 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7928 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7929 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7930 | } |
| 7931 | |
| 7932 | void omx_vdec::set_frame_rate(OMX_S64 act_timestamp) |
| 7933 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7934 | OMX_U32 new_frame_interval = 0; |
| 7935 | if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts |
| 7936 | && llabs(act_timestamp - prev_ts) > 2000) { |
| 7937 | new_frame_interval = client_set_fps ? frm_int : |
| 7938 | llabs(act_timestamp - prev_ts); |
| 7939 | if (new_frame_interval < frm_int || frm_int == 0) { |
| 7940 | frm_int = new_frame_interval; |
| 7941 | if (frm_int) { |
| 7942 | drv_ctx.frame_rate.fps_numerator = 1e6; |
| 7943 | drv_ctx.frame_rate.fps_denominator = frm_int; |
| 7944 | DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)", |
| 7945 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 7946 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 7947 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7948 | /* We need to report the difference between this FBD and the previous FBD |
| 7949 | * back to the driver for clock scaling purposes. */ |
| 7950 | struct v4l2_outputparm oparm; |
| 7951 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 7952 | * per second.*/ |
| 7953 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 7954 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 7955 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7956 | struct v4l2_streamparm sparm; |
| 7957 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7958 | sparm.parm.output = oparm; |
| 7959 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 7960 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 7961 | performance might be affected"); |
| 7962 | } |
| 7963 | |
| 7964 | } |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 7965 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7966 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7967 | prev_ts = act_timestamp; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7968 | } |
| 7969 | |
| 7970 | void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp) |
| 7971 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7972 | if (rst_prev_ts && VALID_TS(act_timestamp)) { |
| 7973 | prev_ts = act_timestamp; |
| 7974 | rst_prev_ts = false; |
| 7975 | } else if (VALID_TS(prev_ts)) { |
| 7976 | bool codec_cond = (drv_ctx.timestamp_adjust)? |
| 7977 | (!VALID_TS(act_timestamp) || (((act_timestamp > prev_ts)? |
| 7978 | (act_timestamp - prev_ts):(prev_ts - act_timestamp)) <= 2000)): |
| 7979 | (!VALID_TS(act_timestamp) || act_timestamp == prev_ts); |
| 7980 | if (frm_int > 0 && codec_cond) { |
| 7981 | DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp); |
| 7982 | act_timestamp = prev_ts + frm_int; |
| 7983 | DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp); |
| 7984 | prev_ts = act_timestamp; |
| 7985 | } else |
| 7986 | set_frame_rate(act_timestamp); |
| 7987 | } else if (frm_int > 0) // In this case the frame rate was set along |
| 7988 | { // with the port definition, start ts with 0 |
| 7989 | act_timestamp = prev_ts = 0; // and correct if a valid ts is received. |
| 7990 | rst_prev_ts = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7991 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7992 | } |
| 7993 | |
| 7994 | void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 7995 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7996 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL; |
| 7997 | OMX_U32 num_conceal_MB = 0; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 7998 | OMX_TICKS time_stamp = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7999 | OMX_U32 frame_rate = 0; |
| 8000 | int consumed_len = 0; |
| 8001 | OMX_U32 num_MB_in_frame; |
| 8002 | OMX_U32 recovery_sei_flags = 1; |
| 8003 | int enable = 0; |
| 8004 | OMX_U32 mbaff = 0; |
| 8005 | int buf_index = p_buf_hdr - m_out_mem_ptr; |
| 8006 | struct msm_vidc_panscan_window_payload *panscan_payload = NULL; |
| 8007 | OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) + |
| 8008 | p_buf_hdr->nOffset; |
| 8009 | if (!drv_ctx.extradata_info.uaddr) { |
| 8010 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8011 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8012 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
| 8013 | ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3)); |
| 8014 | char *p_extradata = drv_ctx.extradata_info.uaddr + buf_index * drv_ctx.extradata_info.buffer_size; |
| 8015 | if ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen)) |
| 8016 | p_extra = NULL; |
| 8017 | OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata; |
| 8018 | if (data) { |
| 8019 | while ((consumed_len < drv_ctx.extradata_info.buffer_size) |
| 8020 | && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 8021 | if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8022 | DEBUG_PRINT_LOW("Invalid extra data size"); |
| 8023 | break; |
| 8024 | } |
| 8025 | switch ((unsigned long)data->eType) { |
| 8026 | case EXTRADATA_INTERLACE_VIDEO: |
| 8027 | struct msm_vidc_interlace_payload *payload; |
| 8028 | payload = (struct msm_vidc_interlace_payload *)data->data; |
| 8029 | mbaff = (h264_parser)? (h264_parser->is_mbaff()): false; |
| 8030 | if (payload && (payload->format == INTERLACE_FRAME_PROGRESSIVE) && !mbaff) |
| 8031 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8032 | else if (payload && (payload->format == INTERLACE_FRAME_TOPFIELDFIRST || |
| 8033 | payload->format == INTERLACE_FRAME_BOTTOMFIELDFIRST) && !mbaff) { |
| 8034 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 8035 | enable = 1; |
| 8036 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8037 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8038 | enable = 1; |
| 8039 | } |
| 8040 | if (m_enable_android_native_buffers) |
| 8041 | setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle, |
| 8042 | PP_PARAM_INTERLACED, (void*)&enable); |
| 8043 | if (!secure_mode && (client_extradata & OMX_INTERLACE_EXTRADATA)) { |
| 8044 | append_interlace_extradata(p_extra, payload->format); |
| 8045 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8046 | } |
| 8047 | break; |
| 8048 | case EXTRADATA_FRAME_RATE: |
| 8049 | struct msm_vidc_framerate_payload *frame_rate_payload; |
| 8050 | frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data; |
| 8051 | frame_rate = frame_rate_payload->frame_rate; |
| 8052 | break; |
| 8053 | case EXTRADATA_TIMESTAMP: |
| 8054 | struct msm_vidc_ts_payload *time_stamp_payload; |
| 8055 | time_stamp_payload = (struct msm_vidc_ts_payload *)data->data; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8056 | time_stamp = time_stamp_payload->timestamp_lo; |
| 8057 | time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32); |
| 8058 | p_buf_hdr->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8059 | break; |
| 8060 | case EXTRADATA_NUM_CONCEALED_MB: |
| 8061 | struct msm_vidc_concealmb_payload *conceal_mb_payload; |
| 8062 | conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data; |
| 8063 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8064 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8065 | num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0); |
| 8066 | break; |
| 8067 | case EXTRADATA_INDEX: |
| 8068 | int *etype; |
| 8069 | etype = (int *)(data->data); |
| 8070 | if (etype && *etype == EXTRADATA_ASPECT_RATIO) { |
| 8071 | struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload; |
| 8072 | aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype); |
| 8073 | if (aspect_ratio_payload) { |
| 8074 | ((struct vdec_output_frameinfo *) |
| 8075 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width; |
| 8076 | ((struct vdec_output_frameinfo *) |
| 8077 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height; |
| 8078 | } |
| 8079 | } |
| 8080 | break; |
| 8081 | case EXTRADATA_RECOVERY_POINT_SEI: |
| 8082 | struct msm_vidc_recoverysei_payload *recovery_sei_payload; |
| 8083 | recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data; |
| 8084 | recovery_sei_flags = recovery_sei_payload->flags; |
| 8085 | if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) { |
| 8086 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8087 | DEBUG_PRINT_HIGH(""); |
| 8088 | DEBUG_PRINT_HIGH("***************************************************"); |
| 8089 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 8090 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8091 | } |
| 8092 | break; |
| 8093 | case EXTRADATA_PANSCAN_WINDOW: |
| 8094 | panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data; |
| 8095 | break; |
| 8096 | case EXTRADATA_MPEG2_SEQDISP: |
| 8097 | struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload; |
| 8098 | seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data; |
| 8099 | if (seqdisp_payload) { |
| 8100 | m_disp_hor_size = seqdisp_payload->disp_width; |
| 8101 | m_disp_vert_size = seqdisp_payload->disp_height; |
| 8102 | } |
| 8103 | break; |
| 8104 | default: |
| 8105 | goto unrecognized_extradata; |
| 8106 | } |
| 8107 | consumed_len += data->nSize; |
| 8108 | data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize); |
| 8109 | } |
| 8110 | if (!secure_mode && (client_extradata & OMX_FRAMEINFO_EXTRADATA)) { |
| 8111 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
| 8112 | append_frame_info_extradata(p_extra, |
| 8113 | num_conceal_MB, ((struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate)->pic_type, frame_rate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8114 | time_stamp, panscan_payload,&((struct vdec_output_frameinfo *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8115 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info); |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8116 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8117 | } |
| 8118 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8119 | unrecognized_extradata: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8120 | if (!secure_mode && client_extradata) |
| 8121 | append_terminator_extradata(p_extra); |
| 8122 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8123 | } |
| 8124 | |
Vinay Kalia | 9c00cae | 2012-12-06 16:08:20 -0800 | [diff] [blame] | 8125 | OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8126 | bool is_internal, bool enable) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8127 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8128 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 8129 | struct v4l2_control control; |
| 8130 | if (m_state != OMX_StateLoaded) { |
| 8131 | DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only"); |
| 8132 | return OMX_ErrorIncorrectStateOperation; |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 8133 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8134 | DEBUG_PRINT_HIGH("NOTE: enable_extradata: actual[%lu] requested[%lu] enable[%d], is_internal: %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8135 | client_extradata, requested_extradata, enable, is_internal); |
| 8136 | |
| 8137 | if (!is_internal) { |
| 8138 | if (enable) |
| 8139 | client_extradata |= requested_extradata; |
| 8140 | else |
| 8141 | client_extradata = client_extradata & ~requested_extradata; |
| 8142 | } |
| 8143 | |
| 8144 | if (enable) { |
| 8145 | if (requested_extradata & OMX_INTERLACE_EXTRADATA) { |
| 8146 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8147 | control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO; |
| 8148 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8149 | DEBUG_PRINT_HIGH("Failed to set interlaced extradata." |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8150 | " Quality of interlaced clips might be impacted."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8151 | } |
| 8152 | } else if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) { |
| 8153 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8154 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE; |
| 8155 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8156 | DEBUG_PRINT_HIGH("Failed to set framerate extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8157 | } |
| 8158 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8159 | control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB; |
| 8160 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8161 | DEBUG_PRINT_HIGH("Failed to set concealed MB extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8162 | } |
| 8163 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8164 | control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI; |
| 8165 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8166 | DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8167 | } |
| 8168 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8169 | control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW; |
| 8170 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8171 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8172 | } |
| 8173 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8174 | control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO; |
| 8175 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8176 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8177 | } |
| 8178 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 8179 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8180 | control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP; |
| 8181 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8182 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8183 | } |
| 8184 | } |
| 8185 | } else if (requested_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 8186 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8187 | control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP; |
| 8188 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8189 | DEBUG_PRINT_HIGH("Failed to set timeinfo extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8190 | } |
| 8191 | } |
| 8192 | } |
| 8193 | ret = get_buffer_req(&drv_ctx.op_buf); |
| 8194 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8195 | } |
| 8196 | |
| 8197 | OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8198 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8199 | OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0; |
| 8200 | OMX_U8 *data_ptr = extra->data, data = 0; |
| 8201 | while (byte_count < extra->nDataSize) { |
| 8202 | data = *data_ptr; |
| 8203 | while (data) { |
| 8204 | num_MB += (data&0x01); |
| 8205 | data >>= 1; |
| 8206 | } |
| 8207 | data_ptr++; |
| 8208 | byte_count++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8209 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8210 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8211 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8212 | return ((num_MB_in_frame > 0)?(num_MB * 100 / num_MB_in_frame) : 0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8213 | } |
| 8214 | |
| 8215 | void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8216 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8217 | if (!m_debug_extradata) |
| 8218 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8219 | |
| 8220 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8221 | "============== Extra Data ==============" |
| 8222 | " Size: %lu" |
| 8223 | " Version: %lu" |
| 8224 | " PortIndex: %lu" |
| 8225 | " Type: %x" |
| 8226 | " DataSize: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8227 | extra->nSize, extra->nVersion.nVersion, |
| 8228 | extra->nPortIndex, extra->eType, extra->nDataSize); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8229 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8230 | if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) { |
| 8231 | OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 8232 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8233 | "------ Interlace Format ------" |
| 8234 | " Size: %lu" |
| 8235 | " Version: %lu" |
| 8236 | " PortIndex: %lu" |
| 8237 | " Is Interlace Format: %d" |
| 8238 | " Interlace Formats: %lu" |
| 8239 | "=========== End of Interlace ===========", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8240 | intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex, |
| 8241 | intfmt->bInterlaceFormat, intfmt->nInterlaceFormats); |
| 8242 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) { |
| 8243 | OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 8244 | |
| 8245 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8246 | "-------- Frame Format --------" |
| 8247 | " Picture Type: %d" |
| 8248 | " Interlace Type: %d" |
| 8249 | " Pan Scan Total Frame Num: %lu" |
| 8250 | " Concealed Macro Blocks: %lu" |
| 8251 | " frame rate: %lu" |
| 8252 | " Time Stamp: %llu" |
| 8253 | " Aspect Ratio X: %lu" |
| 8254 | " Aspect Ratio Y: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8255 | fminfo->ePicType, |
| 8256 | fminfo->interlaceType, |
| 8257 | fminfo->panScan.numWindows, |
| 8258 | fminfo->nConcealedMacroblocks, |
| 8259 | fminfo->nFrameRate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8260 | fminfo->nTimeStamp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8261 | fminfo->aspectRatio.aspectRatioX, |
| 8262 | fminfo->aspectRatio.aspectRatioY); |
| 8263 | |
| 8264 | for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) { |
| 8265 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8266 | "------------------------------" |
| 8267 | " Pan Scan Frame Num: %lu" |
| 8268 | " Rectangle x: %ld" |
| 8269 | " Rectangle y: %ld" |
| 8270 | " Rectangle dx: %ld" |
| 8271 | " Rectangle dy: %ld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8272 | i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y, |
| 8273 | fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy); |
| 8274 | } |
| 8275 | |
| 8276 | DEBUG_PRINT_HIGH("========= End of Frame Format =========="); |
| 8277 | } else if (extra->eType == OMX_ExtraDataNone) { |
| 8278 | DEBUG_PRINT_HIGH("========== End of Terminator ==========="); |
| 8279 | } else { |
| 8280 | DEBUG_PRINT_HIGH("======= End of Driver Extradata ========"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8281 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8285 | OMX_U32 interlaced_format_type) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8286 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8287 | OMX_STREAMINTERLACEFORMAT *interlace_format; |
| 8288 | OMX_U32 mbaff = 0; |
| 8289 | if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) { |
| 8290 | return; |
| 8291 | } |
| 8292 | extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE; |
| 8293 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8294 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8295 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat; |
| 8296 | extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 8297 | interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 8298 | interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 8299 | interlace_format->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8300 | interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8301 | mbaff = (h264_parser)? (h264_parser->is_mbaff()): false; |
| 8302 | if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !mbaff) { |
| 8303 | interlace_format->bInterlaceFormat = OMX_FALSE; |
| 8304 | interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive; |
| 8305 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8306 | } else if ((interlaced_format_type == INTERLACE_FRAME_TOPFIELDFIRST) && !mbaff) { |
| 8307 | interlace_format->bInterlaceFormat = OMX_TRUE; |
| 8308 | interlace_format->nInterlaceFormats = OMX_InterlaceFrameTopFieldFirst; |
| 8309 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 8310 | } else if ((interlaced_format_type == INTERLACE_FRAME_BOTTOMFIELDFIRST) && !mbaff) { |
| 8311 | interlace_format->bInterlaceFormat = OMX_TRUE; |
| 8312 | interlace_format->nInterlaceFormats = OMX_InterlaceFrameBottomFieldFirst; |
| 8313 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8314 | } else { |
| 8315 | interlace_format->bInterlaceFormat = OMX_TRUE; |
| 8316 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
| 8317 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8318 | } |
| 8319 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8320 | } |
| 8321 | |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 8322 | void omx_vdec::fill_aspect_ratio_info( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8323 | struct vdec_aspectratioinfo *aspect_ratio_info, |
| 8324 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info) |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 8325 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8326 | m_extradata = frame_info; |
| 8327 | m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width; |
| 8328 | m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8329 | DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8330 | m_extradata->aspectRatio.aspectRatioY); |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 8331 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8332 | |
| 8333 | void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8334 | OMX_U32 num_conceal_mb, OMX_U32 picture_type, OMX_U32 frame_rate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8335 | OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload, |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 8336 | struct vdec_aspectratioinfo *aspect_ratio_info) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8337 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8338 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL; |
| 8339 | struct msm_vidc_panscan_window *panscan_window; |
| 8340 | if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) { |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 8341 | return; |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 8342 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8343 | extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE; |
| 8344 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8345 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8346 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo; |
| 8347 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO); |
| 8348 | frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 8349 | switch (picture_type) { |
| 8350 | case PICTURE_TYPE_I: |
| 8351 | frame_info->ePicType = OMX_VIDEO_PictureTypeI; |
| 8352 | break; |
| 8353 | case PICTURE_TYPE_P: |
| 8354 | frame_info->ePicType = OMX_VIDEO_PictureTypeP; |
| 8355 | break; |
| 8356 | case PICTURE_TYPE_B: |
| 8357 | frame_info->ePicType = OMX_VIDEO_PictureTypeB; |
| 8358 | break; |
| 8359 | default: |
| 8360 | frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0; |
| 8361 | } |
| 8362 | if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst) |
| 8363 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 8364 | else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst) |
| 8365 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 8366 | else |
| 8367 | frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 8368 | memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio)); |
| 8369 | frame_info->nConcealedMacroblocks = num_conceal_mb; |
| 8370 | frame_info->nFrameRate = frame_rate; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8371 | frame_info->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8372 | frame_info->panScan.numWindows = 0; |
| 8373 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 8374 | if (m_disp_hor_size && m_disp_vert_size) { |
| 8375 | frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size; |
| 8376 | frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size; |
| 8377 | } |
| 8378 | } |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 8379 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8380 | if (panscan_payload) { |
| 8381 | frame_info->panScan.numWindows = panscan_payload->num_panscan_windows; |
| 8382 | panscan_window = &panscan_payload->wnd[0]; |
| 8383 | for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) { |
| 8384 | frame_info->panScan.window[i].x = panscan_window->panscan_window_width; |
| 8385 | frame_info->panScan.window[i].y = panscan_window->panscan_window_height; |
| 8386 | frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset; |
| 8387 | frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset; |
| 8388 | panscan_window++; |
| 8389 | } |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 8390 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8391 | fill_aspect_ratio_info(aspect_ratio_info, frame_info); |
| 8392 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8393 | } |
| 8394 | |
| 8395 | void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8396 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8397 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL; |
| 8398 | extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE; |
| 8399 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8400 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8401 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef; |
| 8402 | extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
| 8403 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data; |
| 8404 | *portDefn = m_port_def; |
| 8405 | DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu " |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8406 | "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8407 | portDefn->format.video.nFrameWidth, |
| 8408 | portDefn->format.video.nStride, |
| 8409 | portDefn->format.video.nSliceHeight); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8410 | } |
| 8411 | |
| 8412 | void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8413 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8414 | if (!client_extradata) { |
| 8415 | return; |
| 8416 | } |
| 8417 | extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE); |
| 8418 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8419 | extra->eType = OMX_ExtraDataNone; |
| 8420 | extra->nDataSize = 0; |
| 8421 | extra->data[0] = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8422 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8423 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8424 | } |
| 8425 | |
| 8426 | OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index) |
| 8427 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8428 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8429 | if (index >= drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8430 | DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8431 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8432 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8433 | if (m_desc_buffer_ptr == NULL) { |
| 8434 | m_desc_buffer_ptr = (desc_buffer_hdr*) \ |
| 8435 | calloc( (sizeof(desc_buffer_hdr)), |
| 8436 | drv_ctx.ip_buf.actualcount); |
| 8437 | if (m_desc_buffer_ptr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8438 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8439 | return OMX_ErrorInsufficientResources; |
| 8440 | } |
| 8441 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8442 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8443 | m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8)); |
| 8444 | if (m_desc_buffer_ptr[index].buf_addr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8445 | DEBUG_PRINT_ERROR("desc buffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8446 | return OMX_ErrorInsufficientResources; |
| 8447 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8448 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8449 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8450 | } |
| 8451 | |
| 8452 | void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset) |
| 8453 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8454 | DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries); |
| 8455 | if (m_demux_entries < 8192) { |
| 8456 | m_demux_offsets[m_demux_entries++] = address_offset; |
| 8457 | } |
| 8458 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8459 | } |
| 8460 | |
| 8461 | void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr) |
| 8462 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8463 | OMX_U32 bytes_to_parse = buf_hdr->nFilledLen; |
| 8464 | OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset; |
| 8465 | OMX_U32 index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8466 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8467 | m_demux_entries = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8468 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8469 | while (index < bytes_to_parse) { |
| 8470 | if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 8471 | (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) || |
| 8472 | ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 8473 | (buf[index+2] == 0x01)) ) { |
| 8474 | //Found start code, insert address offset |
| 8475 | insert_demux_addr_offset(index); |
| 8476 | if (buf[index+2] == 0x01) // 3 byte start code |
| 8477 | index += 3; |
| 8478 | else //4 byte start code |
| 8479 | index += 4; |
| 8480 | } else |
| 8481 | index++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8482 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8483 | DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries); |
| 8484 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8485 | } |
| 8486 | |
| 8487 | OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 8488 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8489 | //fix this, handle 3 byte start code, vc1 terminator entry |
| 8490 | OMX_U8 *p_demux_data = NULL; |
| 8491 | OMX_U32 desc_data = 0; |
| 8492 | OMX_U32 start_addr = 0; |
| 8493 | OMX_U32 nal_size = 0; |
| 8494 | OMX_U32 suffix_byte = 0; |
| 8495 | OMX_U32 demux_index = 0; |
| 8496 | OMX_U32 buffer_index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8497 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8498 | if (m_desc_buffer_ptr == NULL) { |
| 8499 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries."); |
| 8500 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8501 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8502 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8503 | buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
| 8504 | if (buffer_index > drv_ctx.ip_buf.actualcount) { |
| 8505 | DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index); |
| 8506 | return OMX_ErrorBadParameter; |
| 8507 | } |
| 8508 | |
| 8509 | p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr; |
| 8510 | |
| 8511 | if ( ((OMX_U8*)p_demux_data == NULL) || |
| 8512 | ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) { |
| 8513 | DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries."); |
| 8514 | return OMX_ErrorBadParameter; |
| 8515 | } else { |
| 8516 | for (; demux_index < m_demux_entries; demux_index++) { |
| 8517 | desc_data = 0; |
| 8518 | start_addr = m_demux_offsets[demux_index]; |
| 8519 | if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) { |
| 8520 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3]; |
| 8521 | } else { |
| 8522 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4]; |
| 8523 | } |
| 8524 | if (demux_index < (m_demux_entries - 1)) { |
| 8525 | nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2; |
| 8526 | } else { |
| 8527 | nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2; |
| 8528 | } |
| 8529 | DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)", |
| 8530 | (void *)start_addr, |
| 8531 | suffix_byte, |
| 8532 | nal_size, |
| 8533 | demux_index); |
| 8534 | desc_data = (start_addr >> 3) << 1; |
| 8535 | desc_data |= (start_addr & 7) << 21; |
| 8536 | desc_data |= suffix_byte << 24; |
| 8537 | |
| 8538 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 8539 | memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32)); |
| 8540 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 8541 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 8542 | |
| 8543 | p_demux_data += 16; |
| 8544 | } |
| 8545 | if (codec_type_parse == CODEC_TYPE_VC1) { |
| 8546 | DEBUG_PRINT_LOW("VC1 terminator entry"); |
| 8547 | desc_data = 0; |
| 8548 | desc_data = 0x82 << 24; |
| 8549 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 8550 | memset(p_demux_data + 4, 0, sizeof(OMX_U32)); |
| 8551 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 8552 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 8553 | p_demux_data += 16; |
| 8554 | m_demux_entries++; |
| 8555 | } |
| 8556 | //Add zero word to indicate end of descriptors |
| 8557 | memset(p_demux_data, 0, sizeof(OMX_U32)); |
| 8558 | |
| 8559 | m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32); |
| 8560 | DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size); |
| 8561 | } |
| 8562 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 8563 | m_demux_entries = 0; |
| 8564 | DEBUG_PRINT_LOW("Demux table complete!"); |
| 8565 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8566 | } |
| 8567 | |
Deva Ramasubramanian | 9403f02 | 2012-11-28 18:27:53 -0800 | [diff] [blame] | 8568 | OMX_ERRORTYPE omx_vdec::createDivxDrmContext() |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8569 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8570 | OMX_ERRORTYPE err = OMX_ErrorNone; |
| 8571 | iDivXDrmDecrypt = DivXDrmDecrypt::Create(); |
| 8572 | if (iDivXDrmDecrypt) { |
| 8573 | OMX_ERRORTYPE err = iDivXDrmDecrypt->Init(); |
| 8574 | if (err!=OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8575 | DEBUG_PRINT_ERROR("ERROR :iDivXDrmDecrypt->Init %d", err); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8576 | delete iDivXDrmDecrypt; |
| 8577 | iDivXDrmDecrypt = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8578 | } |
| 8579 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8580 | DEBUG_PRINT_ERROR("Unable to Create DIVX DRM"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8581 | err = OMX_ErrorUndefined; |
| 8582 | } |
| 8583 | return err; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8584 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8585 | |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8586 | omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf() |
| 8587 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8588 | enabled = false; |
| 8589 | omx = NULL; |
| 8590 | init_members(); |
| 8591 | ColorFormat = OMX_COLOR_FormatMax; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8592 | } |
| 8593 | |
| 8594 | void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client) |
| 8595 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8596 | omx = reinterpret_cast<omx_vdec*>(client); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8597 | } |
| 8598 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8599 | void omx_vdec::allocate_color_convert_buf::init_members() |
| 8600 | { |
| 8601 | allocated_count = 0; |
| 8602 | buffer_size_req = 0; |
| 8603 | buffer_alignment_req = 0; |
| 8604 | memset(m_platform_list_client,0,sizeof(m_platform_list_client)); |
| 8605 | memset(m_platform_entry_client,0,sizeof(m_platform_entry_client)); |
| 8606 | memset(m_pmem_info_client,0,sizeof(m_pmem_info_client)); |
| 8607 | memset(m_out_mem_ptr_client,0,sizeof(m_out_mem_ptr_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8608 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8609 | memset(op_buf_ion_info,0,sizeof(m_platform_entry_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8610 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8611 | for (int i = 0; i < MAX_COUNT; i++) |
| 8612 | pmem_fd[i] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8613 | } |
| 8614 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8615 | omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf() |
| 8616 | { |
| 8617 | c2d.destroy(); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8618 | } |
| 8619 | |
| 8620 | bool omx_vdec::allocate_color_convert_buf::update_buffer_req() |
| 8621 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8622 | bool status = true; |
| 8623 | unsigned int src_size = 0, destination_size = 0; |
| 8624 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 8625 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8626 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8627 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8628 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8629 | if (!enabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8630 | DEBUG_PRINT_HIGH("No color conversion required"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8631 | return status; |
| 8632 | } |
| 8633 | pthread_mutex_lock(&omx->c_lock); |
| 8634 | if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 && |
| 8635 | ColorFormat != OMX_COLOR_FormatYUV420Planar) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8636 | DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8637 | status = false; |
| 8638 | goto fail_update_buf_req; |
| 8639 | } |
| 8640 | c2d.close(); |
| 8641 | status = c2d.open(omx->drv_ctx.video_resolution.frame_height, |
| 8642 | omx->drv_ctx.video_resolution.frame_width, |
| 8643 | NV12_128m,YCbCr420P); |
| 8644 | if (status) { |
| 8645 | status = c2d.get_buffer_size(C2D_INPUT,src_size); |
| 8646 | if (status) |
| 8647 | status = c2d.get_buffer_size(C2D_OUTPUT,destination_size); |
| 8648 | } |
| 8649 | if (status) { |
| 8650 | if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size || |
| 8651 | !destination_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8652 | DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8653 | "driver size %d destination size %d", |
| 8654 | src_size,omx->drv_ctx.op_buf.buffer_size,destination_size); |
| 8655 | status = false; |
| 8656 | c2d.close(); |
| 8657 | buffer_size_req = 0; |
| 8658 | } else { |
| 8659 | buffer_size_req = destination_size; |
| 8660 | if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size) |
| 8661 | buffer_size_req = omx->drv_ctx.op_buf.buffer_size; |
| 8662 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 8663 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
| 8664 | } |
| 8665 | } |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 8666 | fail_update_buf_req: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8667 | pthread_mutex_unlock(&omx->c_lock); |
| 8668 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8669 | } |
| 8670 | |
| 8671 | bool omx_vdec::allocate_color_convert_buf::set_color_format( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8672 | OMX_COLOR_FORMATTYPE dest_color_format) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8673 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8674 | bool status = true; |
| 8675 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 8676 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8677 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8678 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8679 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8680 | pthread_mutex_lock(&omx->c_lock); |
| 8681 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 8682 | drv_color_format = (OMX_COLOR_FORMATTYPE) |
| 8683 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 8684 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8685 | DEBUG_PRINT_ERROR("Incorrect color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8686 | status = false; |
| 8687 | } |
| 8688 | if (status && (drv_color_format != dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8689 | DEBUG_PRINT_LOW("Enabling C2D"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8690 | if (dest_color_format != OMX_COLOR_FormatYUV420Planar) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8691 | DEBUG_PRINT_ERROR("Unsupported color format for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8692 | status = false; |
| 8693 | } else { |
| 8694 | ColorFormat = OMX_COLOR_FormatYUV420Planar; |
| 8695 | if (enabled) |
| 8696 | c2d.destroy(); |
| 8697 | enabled = false; |
| 8698 | if (!c2d.init()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8699 | DEBUG_PRINT_ERROR("open failed for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8700 | status = false; |
| 8701 | } else |
| 8702 | enabled = true; |
| 8703 | } |
| 8704 | } else { |
| 8705 | if (enabled) |
| 8706 | c2d.destroy(); |
| 8707 | enabled = false; |
| 8708 | } |
| 8709 | pthread_mutex_unlock(&omx->c_lock); |
| 8710 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8711 | } |
| 8712 | |
| 8713 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr() |
| 8714 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8715 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8716 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8717 | return NULL; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 8718 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8719 | if (!enabled) |
| 8720 | return omx->m_out_mem_ptr; |
| 8721 | return m_out_mem_ptr_client; |
| 8722 | } |
| 8723 | |
| 8724 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr |
| 8725 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 8726 | { |
| 8727 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8728 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8729 | return NULL; |
| 8730 | } |
| 8731 | if (!enabled) |
| 8732 | return bufadd; |
| 8733 | |
| 8734 | unsigned index = 0; |
| 8735 | index = bufadd - omx->m_out_mem_ptr; |
| 8736 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 8737 | m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS); |
| 8738 | m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp; |
| 8739 | bool status; |
| 8740 | if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) { |
| 8741 | pthread_mutex_lock(&omx->c_lock); |
| 8742 | status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd, |
| 8743 | omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index], |
| 8744 | pmem_baseaddress[index], pmem_baseaddress[index]); |
| 8745 | pthread_mutex_unlock(&omx->c_lock); |
| 8746 | m_out_mem_ptr_client[index].nFilledLen = buffer_size_req; |
| 8747 | if (!status) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8748 | DEBUG_PRINT_ERROR("Failed color conversion %d", status); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8749 | m_out_mem_ptr_client[index].nFilledLen = 0; |
| 8750 | return &m_out_mem_ptr_client[index]; |
| 8751 | } |
| 8752 | } else |
| 8753 | m_out_mem_ptr_client[index].nFilledLen = 0; |
| 8754 | return &m_out_mem_ptr_client[index]; |
| 8755 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8756 | DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8757 | return NULL; |
| 8758 | } |
| 8759 | |
| 8760 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr |
| 8761 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 8762 | { |
| 8763 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8764 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8765 | return NULL; |
| 8766 | } |
| 8767 | if (!enabled) |
| 8768 | return bufadd; |
| 8769 | unsigned index = 0; |
| 8770 | index = bufadd - m_out_mem_ptr_client; |
| 8771 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 8772 | return &omx->m_out_mem_ptr[index]; |
| 8773 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8774 | DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8775 | return NULL; |
| 8776 | } |
| 8777 | bool omx_vdec::allocate_color_convert_buf::get_buffer_req |
| 8778 | (unsigned int &buffer_size) |
| 8779 | { |
| 8780 | bool status = true; |
| 8781 | pthread_mutex_lock(&omx->c_lock); |
| 8782 | if (!enabled) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8783 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8784 | else { |
| 8785 | if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8786 | DEBUG_PRINT_ERROR("Get buffer size failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8787 | status = false; |
| 8788 | goto fail_get_buffer_size; |
| 8789 | } |
| 8790 | } |
| 8791 | if (buffer_size < omx->drv_ctx.op_buf.buffer_size) |
| 8792 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
| 8793 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 8794 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 8795 | fail_get_buffer_size: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8796 | pthread_mutex_unlock(&omx->c_lock); |
| 8797 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8798 | } |
| 8799 | OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8800 | OMX_BUFFERHEADERTYPE *bufhdr) |
| 8801 | { |
| 8802 | unsigned int index = 0; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8803 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8804 | if (!enabled) |
| 8805 | return omx->free_output_buffer(bufhdr); |
| 8806 | if (enabled && omx->is_component_secure()) |
| 8807 | return OMX_ErrorNone; |
| 8808 | if (!allocated_count || !bufhdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8809 | DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8810 | return OMX_ErrorBadParameter; |
| 8811 | } |
| 8812 | index = bufhdr - m_out_mem_ptr_client; |
| 8813 | if (index >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8814 | DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8815 | return OMX_ErrorBadParameter; |
| 8816 | } |
| 8817 | if (pmem_fd[index] > 0) { |
| 8818 | munmap(pmem_baseaddress[index], buffer_size_req); |
| 8819 | close(pmem_fd[index]); |
| 8820 | } |
| 8821 | pmem_fd[index] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8822 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8823 | omx->free_ion_memory(&op_buf_ion_info[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8824 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8825 | m_heap_ptr[index].video_heap_ptr = NULL; |
| 8826 | if (allocated_count > 0) |
| 8827 | allocated_count--; |
| 8828 | else |
| 8829 | allocated_count = 0; |
| 8830 | if (!allocated_count) { |
| 8831 | pthread_mutex_lock(&omx->c_lock); |
| 8832 | c2d.close(); |
| 8833 | init_members(); |
| 8834 | pthread_mutex_unlock(&omx->c_lock); |
| 8835 | } |
| 8836 | return omx->free_output_buffer(&omx->m_out_mem_ptr[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8837 | } |
| 8838 | |
| 8839 | OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::allocate_buffers_color_convert(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8840 | OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8841 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8842 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8843 | if (!enabled) { |
| 8844 | eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes); |
| 8845 | return eRet; |
| 8846 | } |
| 8847 | if (enabled && omx->is_component_secure()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8848 | DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8849 | omx->is_component_secure()); |
| 8850 | return OMX_ErrorUnsupportedSetting; |
| 8851 | } |
| 8852 | if (!bufferHdr || bytes > buffer_size_req) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8853 | DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr); |
| 8854 | DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8855 | buffer_size_req,bytes); |
| 8856 | return OMX_ErrorBadParameter; |
| 8857 | } |
| 8858 | if (allocated_count >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8859 | DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8860 | return OMX_ErrorInsufficientResources; |
| 8861 | } |
| 8862 | OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL; |
| 8863 | eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr, |
| 8864 | port,appData,omx->drv_ctx.op_buf.buffer_size); |
| 8865 | if (eRet != OMX_ErrorNone || !temp_bufferHdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8866 | DEBUG_PRINT_ERROR("Buffer allocation failed color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8867 | return eRet; |
| 8868 | } |
| 8869 | if ((temp_bufferHdr - omx->m_out_mem_ptr) >= |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 8870 | (int)omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8871 | DEBUG_PRINT_ERROR("Invalid header index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8872 | (temp_bufferHdr - omx->m_out_mem_ptr)); |
| 8873 | return OMX_ErrorUndefined; |
| 8874 | } |
| 8875 | unsigned int i = allocated_count; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8876 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8877 | op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory( |
| 8878 | buffer_size_req,buffer_alignment_req, |
| 8879 | &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data, |
| 8880 | 0); |
| 8881 | pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd; |
| 8882 | if (op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8883 | DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8884 | return OMX_ErrorInsufficientResources; |
| 8885 | } |
| 8886 | pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req, |
| 8887 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8888 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8889 | if (pmem_baseaddress[i] == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8890 | DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8891 | close(pmem_fd[i]); |
| 8892 | omx->free_ion_memory(&op_buf_ion_info[i]); |
| 8893 | return OMX_ErrorInsufficientResources; |
| 8894 | } |
| 8895 | m_heap_ptr[i].video_heap_ptr = new VideoHeap ( |
| 8896 | op_buf_ion_info[i].ion_device_fd,buffer_size_req, |
| 8897 | pmem_baseaddress[i],op_buf_ion_info[i].ion_alloc_data.handle,pmem_fd[i]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8898 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8899 | m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get(); |
| 8900 | m_pmem_info_client[i].offset = 0; |
| 8901 | m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i]; |
| 8902 | m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 8903 | m_platform_list_client[i].nEntries = 1; |
| 8904 | m_platform_list_client[i].entryList = &m_platform_entry_client[i]; |
| 8905 | m_out_mem_ptr_client[i].pOutputPortPrivate = NULL; |
| 8906 | m_out_mem_ptr_client[i].nAllocLen = buffer_size_req; |
| 8907 | m_out_mem_ptr_client[i].nFilledLen = 0; |
| 8908 | m_out_mem_ptr_client[i].nFlags = 0; |
| 8909 | m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8910 | m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 8911 | m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION; |
| 8912 | m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i]; |
| 8913 | m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i]; |
| 8914 | m_out_mem_ptr_client[i].pAppPrivate = appData; |
| 8915 | *bufferHdr = &m_out_mem_ptr_client[i]; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8916 | DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8917 | allocated_count++; |
| 8918 | return eRet; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8919 | } |
| 8920 | |
| 8921 | bool omx_vdec::is_component_secure() |
| 8922 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8923 | return secure_mode; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8924 | } |
| 8925 | |
| 8926 | bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format) |
| 8927 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8928 | bool status = true; |
| 8929 | if (!enabled) { |
| 8930 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 8931 | dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 8932 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 8933 | else |
| 8934 | status = false; |
| 8935 | } else { |
| 8936 | if (ColorFormat != OMX_COLOR_FormatYUV420Planar) { |
| 8937 | status = false; |
| 8938 | } else |
| 8939 | dest_color_format = OMX_COLOR_FormatYUV420Planar; |
| 8940 | } |
| 8941 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8942 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8943 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8944 | void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset) |
| 8945 | { |
| 8946 | int i = 0; |
| 8947 | bool buf_present = false; |
| 8948 | pthread_mutex_lock(&m_lock); |
| 8949 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 8950 | //check the buffer fd, offset, uv addr with list contents |
| 8951 | //If present increment reference. |
| 8952 | if ((out_dynamic_list[i].fd == fd) && |
| 8953 | (out_dynamic_list[i].offset == offset)) { |
| 8954 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8955 | DEBUG_PRINT_LOW("buf_ref_add: [ALREADY PRESENT] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8956 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 8957 | buf_present = true; |
| 8958 | break; |
| 8959 | } |
| 8960 | } |
| 8961 | if (!buf_present) { |
| 8962 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 8963 | //search for a entry to insert details of the new buffer |
| 8964 | if (out_dynamic_list[i].dup_fd == 0) { |
| 8965 | out_dynamic_list[i].fd = fd; |
| 8966 | out_dynamic_list[i].offset = offset; |
| 8967 | out_dynamic_list[i].dup_fd = dup(fd); |
| 8968 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8969 | DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8970 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 8971 | break; |
| 8972 | } |
| 8973 | } |
| 8974 | } |
| 8975 | pthread_mutex_unlock(&m_lock); |
| 8976 | } |
| 8977 | |
| 8978 | void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset) |
| 8979 | { |
| 8980 | int i = 0; |
| 8981 | pthread_mutex_lock(&m_lock); |
| 8982 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 8983 | //check the buffer fd, offset, uv addr with list contents |
| 8984 | //If present decrement reference. |
| 8985 | if ((out_dynamic_list[i].fd == fd) && |
| 8986 | (out_dynamic_list[i].offset == offset)) { |
| 8987 | out_dynamic_list[i].ref_count--; |
| 8988 | if (out_dynamic_list[i].ref_count == 0) { |
| 8989 | close(out_dynamic_list[i].dup_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8990 | DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8991 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 8992 | out_dynamic_list[i].dup_fd = 0; |
| 8993 | out_dynamic_list[i].fd = 0; |
| 8994 | out_dynamic_list[i].offset = 0; |
| 8995 | } |
| 8996 | break; |
| 8997 | } |
| 8998 | } |
| 8999 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9000 | DEBUG_PRINT_ERROR("Error - could not remove ref, no match with any entry in list"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9001 | } |
| 9002 | pthread_mutex_unlock(&m_lock); |
| 9003 | } |