Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1 | /*-------------------------------------------------------------------------- |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 2 | Copyright (c) 2010 - 2014, 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 | |
Deva Ramasubramanian | eb81932 | 2014-07-17 14:23:35 -0700 | [diff] [blame] | 42 | #define __STDC_FORMAT_MACROS |
| 43 | #include <inttypes.h> |
| 44 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 45 | #include <string.h> |
| 46 | #include <pthread.h> |
| 47 | #include <sys/prctl.h> |
| 48 | #include <stdlib.h> |
| 49 | #include <unistd.h> |
| 50 | #include <errno.h> |
| 51 | #include "omx_vdec.h" |
| 52 | #include <fcntl.h> |
| 53 | #include <limits.h> |
Deva Ramasubramanian | 15bbc1c | 2013-05-13 16:05:03 -0700 | [diff] [blame] | 54 | #include <stdlib.h> |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 55 | #include <media/hardware/HardwareAPI.h> |
Vinay Kalia | da8f3cf | 2012-12-21 18:26:21 -0800 | [diff] [blame] | 56 | #include <media/msm_media_info.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 57 | |
| 58 | #ifndef _ANDROID_ |
| 59 | #include <sys/ioctl.h> |
| 60 | #include <sys/mman.h> |
| 61 | #endif //_ANDROID_ |
| 62 | |
| 63 | #ifdef _ANDROID_ |
| 64 | #include <cutils/properties.h> |
| 65 | #undef USE_EGL_IMAGE_GPU |
| 66 | #endif |
| 67 | |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 68 | #include <qdMetaData.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 69 | |
| 70 | #ifdef _ANDROID_ |
| 71 | #include "DivXDrmDecrypt.h" |
| 72 | #endif //_ANDROID_ |
| 73 | |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 74 | #ifdef METADATA_FOR_DYNAMIC_MODE |
Arun Menon | 9af783f | 2013-10-22 12:57:14 -0700 | [diff] [blame] | 75 | #include "QComOMXMetadata.h" |
| 76 | #endif |
| 77 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 78 | #ifdef USE_EGL_IMAGE_GPU |
| 79 | #include <EGL/egl.h> |
| 80 | #include <EGL/eglQCOM.h> |
| 81 | #define EGL_BUFFER_HANDLE_QCOM 0x4F00 |
| 82 | #define EGL_BUFFER_OFFSET_QCOM 0x4F01 |
| 83 | #endif |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 84 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 85 | #define BUFFER_LOG_LOC "/data/misc/media" |
| 86 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 87 | #ifdef OUTPUT_EXTRADATA_LOG |
| 88 | FILE *outputExtradataFile; |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 89 | char output_extradata_filename [] = "/data/misc/extradata"; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 90 | #endif |
| 91 | |
| 92 | #define DEFAULT_FPS 30 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 93 | #define MAX_SUPPORTED_FPS 120 |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 94 | #define DEFAULT_WIDTH_ALIGNMENT 128 |
| 95 | #define DEFAULT_HEIGHT_ALIGNMENT 32 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 96 | |
| 97 | #define VC1_SP_MP_START_CODE 0xC5000000 |
| 98 | #define VC1_SP_MP_START_CODE_MASK 0xFF000000 |
| 99 | #define VC1_AP_SEQ_START_CODE 0x0F010000 |
| 100 | #define VC1_STRUCT_C_PROFILE_MASK 0xF0 |
| 101 | #define VC1_STRUCT_B_LEVEL_MASK 0xE0000000 |
| 102 | #define VC1_SIMPLE_PROFILE 0 |
| 103 | #define VC1_MAIN_PROFILE 1 |
| 104 | #define VC1_ADVANCE_PROFILE 3 |
| 105 | #define VC1_SIMPLE_PROFILE_LOW_LEVEL 0 |
| 106 | #define VC1_SIMPLE_PROFILE_MED_LEVEL 2 |
| 107 | #define VC1_STRUCT_C_LEN 4 |
| 108 | #define VC1_STRUCT_C_POS 8 |
| 109 | #define VC1_STRUCT_A_POS 12 |
| 110 | #define VC1_STRUCT_B_POS 24 |
| 111 | #define VC1_SEQ_LAYER_SIZE 36 |
Vinay Kalia | b09886c | 2012-08-20 11:27:25 -0700 | [diff] [blame] | 112 | #define POLL_TIMEOUT 0x7fffffff |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 113 | |
| 114 | #define MEM_DEVICE "/dev/ion" |
| 115 | #define MEM_HEAP_ID ION_CP_MM_HEAP_ID |
| 116 | |
| 117 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 118 | extern "C" { |
| 119 | #include<utils/Log.h> |
| 120 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 121 | #endif//_ANDROID_ |
| 122 | |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 123 | #define SZ_4K 0x1000 |
| 124 | #define SZ_1M 0x100000 |
| 125 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 126 | #define Log2(number, power) { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) && power < 16) { temp >>=0x1; power++; } } |
| 127 | #define Q16ToFraction(q,num,den) { OMX_U32 power; Log2(q,power); num = q >> power; den = 0x1 << (16 - power); } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 128 | #define EXTRADATA_IDX(__num_planes) (__num_planes - 1) |
| 129 | |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 130 | #define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA) |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 131 | #define DEFAULT_CONCEAL_COLOR "32896" //0x8080, black by default |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 132 | |
| 133 | int debug_level = PRIO_ERROR; |
| 134 | |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 135 | static OMX_U32 maxSmoothStreamingWidth = 1920; |
| 136 | static OMX_U32 maxSmoothStreamingHeight = 1088; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 137 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 138 | void* async_message_thread (void *input) |
| 139 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 140 | OMX_BUFFERHEADERTYPE *buffer; |
| 141 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 142 | struct pollfd pfd; |
| 143 | struct v4l2_buffer v4l2_buf; |
| 144 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 145 | struct v4l2_event dqevent; |
| 146 | omx_vdec *omx = reinterpret_cast<omx_vdec*>(input); |
| 147 | pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI; |
| 148 | pfd.fd = omx->drv_ctx.video_driver_fd; |
| 149 | int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 150 | DEBUG_PRINT_HIGH("omx_vdec: Async thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 151 | prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0); |
| 152 | while (1) { |
| 153 | rc = poll(&pfd, 1, POLL_TIMEOUT); |
| 154 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 155 | DEBUG_PRINT_ERROR("Poll timedout"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 156 | break; |
| 157 | } else if (rc < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 158 | DEBUG_PRINT_ERROR("Error while polling: %d", rc); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 159 | break; |
| 160 | } |
| 161 | if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) { |
| 162 | struct vdec_msginfo vdec_msg; |
| 163 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 164 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 165 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 166 | v4l2_buf.m.planes = plane; |
| 167 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 168 | vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 169 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 170 | vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf; |
| 171 | vdec_msg.msgdata.output_frame.len=plane[0].bytesused; |
| 172 | vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr; |
| 173 | vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) + |
| 174 | (uint64_t)v4l2_buf.timestamp.tv_usec; |
| 175 | if (vdec_msg.msgdata.output_frame.len) { |
| 176 | vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2]; |
| 177 | vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3]; |
| 178 | vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4]; |
| 179 | vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5]; |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 180 | vdec_msg.msgdata.output_frame.picsize.frame_width = plane[0].reserved[6]; |
| 181 | vdec_msg.msgdata.output_frame.picsize.frame_height = plane[0].reserved[7]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 182 | } |
| 183 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 184 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 185 | break; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) { |
| 190 | struct vdec_msginfo vdec_msg; |
| 191 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 192 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 193 | v4l2_buf.length = 1; |
| 194 | v4l2_buf.m.planes = plane; |
| 195 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 196 | vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE; |
| 197 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 198 | vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf; |
| 199 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 200 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 201 | break; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | if (pfd.revents & POLLPRI) { |
| 206 | rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent); |
| 207 | if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) { |
| 208 | struct vdec_msginfo vdec_msg; |
| 209 | vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED; |
| 210 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 211 | DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 212 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 213 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 214 | break; |
| 215 | } |
| 216 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) { |
| 217 | struct vdec_msginfo vdec_msg; |
| 218 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE; |
| 219 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 220 | DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 221 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 222 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE; |
| 226 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 227 | DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 228 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 229 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 233 | DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 234 | break; |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 235 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_HW_OVERLOAD) { |
| 236 | struct vdec_msginfo vdec_msg; |
| 237 | vdec_msg.msgcode=VDEC_MSG_EVT_HW_OVERLOAD; |
| 238 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 239 | DEBUG_PRINT_ERROR("HW Overload received"); |
| 240 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
| 241 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
| 242 | break; |
| 243 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 244 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) { |
| 245 | struct vdec_msginfo vdec_msg; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 246 | vdec_msg.msgcode = VDEC_MSG_EVT_HW_ERROR; |
| 247 | vdec_msg.status_code = VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 248 | DEBUG_PRINT_HIGH("SYS Error Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 249 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 250 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 251 | break; |
| 252 | } |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 253 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 254 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 255 | 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] | 256 | omx->buf_ref_remove(ptr[0], ptr[1]); |
| 257 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) { |
| 258 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
| 259 | struct vdec_msginfo vdec_msg; |
| 260 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 261 | 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] | 262 | |
| 263 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 264 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 265 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 266 | v4l2_buf.m.planes = plane; |
| 267 | v4l2_buf.index = ptr[5]; |
| 268 | v4l2_buf.flags = 0; |
| 269 | |
| 270 | vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 271 | vdec_msg.status_code = VDEC_S_SUCCESS; |
| 272 | vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf; |
| 273 | vdec_msg.msgdata.output_frame.len = 0; |
| 274 | vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2]; |
| 275 | vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) + |
| 276 | (uint64_t)ptr[4]; |
| 277 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 278 | DEBUG_PRINT_HIGH("async_message_thread Exitedn"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 279 | break; |
| 280 | } |
| 281 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 282 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 283 | DEBUG_PRINT_HIGH("VIDC Some Event recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 284 | continue; |
| 285 | } |
| 286 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 287 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 288 | DEBUG_PRINT_HIGH("omx_vdec: Async thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 289 | return NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void* message_thread(void *input) |
| 293 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 294 | omx_vdec* omx = reinterpret_cast<omx_vdec*>(input); |
| 295 | unsigned char id; |
| 296 | int n; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 297 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 298 | DEBUG_PRINT_HIGH("omx_vdec: message thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 299 | prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0); |
| 300 | while (1) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 301 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 302 | n = read(omx->m_pipe_in, &id, 1); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 303 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 304 | if (0 == n) { |
| 305 | break; |
| 306 | } |
| 307 | |
| 308 | if (1 == n) { |
| 309 | omx->process_event_cb(omx, id); |
| 310 | } |
| 311 | if ((n < 0) && (errno != EINTR)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 312 | 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] | 313 | break; |
| 314 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 315 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 316 | DEBUG_PRINT_HIGH("omx_vdec: message thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 317 | return 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void post_message(omx_vdec *omx, unsigned char id) |
| 321 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 322 | int ret_value; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 323 | 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] | 324 | ret_value = write(omx->m_pipe_out, &id, 1); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 325 | DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | // omx_cmd_queue destructor |
| 329 | omx_vdec::omx_cmd_queue::~omx_cmd_queue() |
| 330 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 331 | // Nothing to do |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // omx cmd queue constructor |
| 335 | omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0) |
| 336 | { |
| 337 | memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE); |
| 338 | } |
| 339 | |
| 340 | // omx cmd queue insert |
| 341 | bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id) |
| 342 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 343 | bool ret = true; |
| 344 | if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 345 | m_q[m_write].id = id; |
| 346 | m_q[m_write].param1 = p1; |
| 347 | m_q[m_write].param2 = p2; |
| 348 | m_write++; |
| 349 | m_size ++; |
| 350 | if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 351 | m_write = 0; |
| 352 | } |
| 353 | } else { |
| 354 | ret = false; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 355 | DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 356 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 357 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | // omx cmd queue pop |
| 361 | bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id) |
| 362 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 363 | bool ret = true; |
| 364 | if (m_size > 0) { |
| 365 | *id = m_q[m_read].id; |
| 366 | *p1 = m_q[m_read].param1; |
| 367 | *p2 = m_q[m_read].param2; |
| 368 | // Move the read pointer ahead |
| 369 | ++m_read; |
| 370 | --m_size; |
| 371 | if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 372 | m_read = 0; |
| 373 | } |
| 374 | } else { |
| 375 | ret = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 376 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 377 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | // Retrieve the first mesg type in the queue |
| 381 | unsigned omx_vdec::omx_cmd_queue::get_q_msg_type() |
| 382 | { |
| 383 | return m_q[m_read].id; |
| 384 | } |
| 385 | |
| 386 | #ifdef _ANDROID_ |
| 387 | omx_vdec::ts_arr_list::ts_arr_list() |
| 388 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 389 | //initialize timestamps array |
| 390 | 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] | 391 | } |
| 392 | omx_vdec::ts_arr_list::~ts_arr_list() |
| 393 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 394 | //free m_ts_arr_list? |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts) |
| 398 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 399 | bool ret = true; |
| 400 | bool duplicate_ts = false; |
| 401 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 402 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 403 | //insert at the first available empty location |
| 404 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 405 | if (!m_ts_arr_list[idx].valid) { |
| 406 | //found invalid or empty entry, save timestamp |
| 407 | m_ts_arr_list[idx].valid = true; |
| 408 | m_ts_arr_list[idx].timestamp = ts; |
| 409 | DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)", |
| 410 | ts, idx); |
| 411 | break; |
| 412 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 413 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 414 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 415 | if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 416 | DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert"); |
| 417 | ret = false; |
| 418 | } |
| 419 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts) |
| 423 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 424 | bool ret = true; |
| 425 | int min_idx = -1; |
| 426 | OMX_TICKS min_ts = 0; |
| 427 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 428 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 429 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 430 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 431 | if (m_ts_arr_list[idx].valid) { |
| 432 | //found valid entry, save index |
| 433 | if (min_idx < 0) { |
| 434 | //first valid entry |
| 435 | min_ts = m_ts_arr_list[idx].timestamp; |
| 436 | min_idx = idx; |
| 437 | } else if (m_ts_arr_list[idx].timestamp < min_ts) { |
| 438 | min_ts = m_ts_arr_list[idx].timestamp; |
| 439 | min_idx = idx; |
| 440 | } |
| 441 | } |
| 442 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 445 | if (min_idx < 0) { |
| 446 | //no valid entries found |
| 447 | DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop"); |
| 448 | ts = 0; |
| 449 | ret = false; |
| 450 | } else { |
| 451 | ts = m_ts_arr_list[min_idx].timestamp; |
| 452 | m_ts_arr_list[min_idx].valid = false; |
| 453 | DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)", |
| 454 | ts, min_idx); |
| 455 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 456 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 457 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 458 | |
| 459 | } |
| 460 | |
| 461 | |
| 462 | bool omx_vdec::ts_arr_list::reset_ts_list() |
| 463 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 464 | bool ret = true; |
| 465 | int idx = 0; |
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 | DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list"); |
| 468 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 469 | m_ts_arr_list[idx].valid = false; |
| 470 | } |
| 471 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 472 | } |
| 473 | #endif |
| 474 | |
| 475 | // factory function executed by the core to create instances |
| 476 | void *get_omx_component_factory_fn(void) |
| 477 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 478 | return (new omx_vdec); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | #ifdef _ANDROID_ |
| 482 | #ifdef USE_ION |
| 483 | VideoHeap::VideoHeap(int devicefd, size_t size, void* base, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 484 | struct ion_handle *handle, int ionMapfd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 485 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 486 | // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 487 | } |
| 488 | #else |
| 489 | VideoHeap::VideoHeap(int fd, size_t size, void* base) |
| 490 | { |
| 491 | // dup file descriptor, map once, use pmem |
| 492 | init(dup(fd), base, size, 0 , MEM_DEVICE); |
| 493 | } |
| 494 | #endif |
| 495 | #endif // _ANDROID_ |
| 496 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 497 | FUNCTION |
| 498 | omx_vdec::omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 499 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 500 | DESCRIPTION |
| 501 | Constructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 502 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 503 | PARAMETERS |
| 504 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 505 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 506 | RETURN VALUE |
| 507 | None. |
| 508 | ========================================================================== */ |
Deva Ramasubramanian | 5c24124 | 2013-02-19 17:25:30 -0800 | [diff] [blame] | 509 | omx_vdec::omx_vdec(): m_error_propogated(false), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 510 | m_state(OMX_StateInvalid), |
| 511 | m_app_data(NULL), |
| 512 | m_inp_mem_ptr(NULL), |
| 513 | m_out_mem_ptr(NULL), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 514 | input_flush_progress (false), |
| 515 | output_flush_progress (false), |
| 516 | input_use_buffer (false), |
| 517 | output_use_buffer (false), |
| 518 | ouput_egl_buffers(false), |
| 519 | m_use_output_pmem(OMX_FALSE), |
| 520 | m_out_mem_region_smi(OMX_FALSE), |
| 521 | m_out_pvt_entry_pmem(OMX_FALSE), |
| 522 | pending_input_buffers(0), |
| 523 | pending_output_buffers(0), |
| 524 | m_out_bm_count(0), |
| 525 | m_inp_bm_count(0), |
| 526 | m_inp_bPopulated(OMX_FALSE), |
| 527 | m_out_bPopulated(OMX_FALSE), |
| 528 | m_flags(0), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 529 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 530 | m_heap_ptr(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 531 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 532 | m_inp_bEnabled(OMX_TRUE), |
| 533 | m_out_bEnabled(OMX_TRUE), |
| 534 | m_in_alloc_cnt(0), |
| 535 | m_platform_list(NULL), |
| 536 | m_platform_entry(NULL), |
| 537 | m_pmem_info(NULL), |
| 538 | arbitrary_bytes (true), |
| 539 | psource_frame (NULL), |
| 540 | pdest_frame (NULL), |
| 541 | m_inp_heap_ptr (NULL), |
| 542 | m_phdr_pmem_ptr(NULL), |
| 543 | m_heap_inp_bm_count (0), |
| 544 | codec_type_parse ((codec_type)0), |
| 545 | first_frame_meta (true), |
| 546 | frame_count (0), |
| 547 | nal_count (0), |
| 548 | nal_length(0), |
| 549 | look_ahead_nal (false), |
| 550 | first_frame(0), |
| 551 | first_buffer(NULL), |
| 552 | first_frame_size (0), |
| 553 | m_device_file_ptr(NULL), |
| 554 | m_vc1_profile((vc1_profile_type)0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 555 | h264_last_au_ts(LLONG_MAX), |
| 556 | h264_last_au_flags(0), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 557 | m_disp_hor_size(0), |
| 558 | m_disp_vert_size(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 559 | prev_ts(LLONG_MAX), |
| 560 | rst_prev_ts(true), |
| 561 | frm_int(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 562 | in_reconfig(false), |
| 563 | m_display_id(NULL), |
| 564 | h264_parser(NULL), |
| 565 | client_extradata(0), |
| 566 | m_reject_avc_1080p_mp (0), |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 567 | m_other_extradata(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 568 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 569 | m_enable_android_native_buffers(OMX_FALSE), |
| 570 | m_use_android_native_buffers(OMX_FALSE), |
| 571 | iDivXDrmDecrypt(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 572 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 573 | m_desc_buffer_ptr(NULL), |
| 574 | secure_mode(false), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 575 | m_profile(0), |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 576 | client_set_fps(false), |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 577 | m_last_rendered_TS(-1), |
| 578 | m_queued_codec_config_count(0) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 579 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 580 | /* Assumption is that , to begin with , we have all the frames with decoder */ |
| 581 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 582 | memset(&m_debug,0,sizeof(m_debug)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 583 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 584 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 585 | property_get("vidc.debug.level", property_value, "0"); |
| 586 | debug_level = atoi(property_value); |
| 587 | property_value[0] = '\0'; |
| 588 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 589 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
| 590 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 591 | property_get("vidc.dec.debug.perf", property_value, "0"); |
| 592 | perf_flag = atoi(property_value); |
| 593 | if (perf_flag) { |
| 594 | DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag); |
| 595 | dec_time.start(); |
| 596 | proc_frms = latency = 0; |
| 597 | } |
| 598 | prev_n_filled_len = 0; |
| 599 | property_value[0] = '\0'; |
| 600 | property_get("vidc.dec.debug.ts", property_value, "0"); |
| 601 | m_debug_timestamp = atoi(property_value); |
| 602 | DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp); |
| 603 | if (m_debug_timestamp) { |
| 604 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 605 | time_stamp_dts.enable_debug_print(true); |
| 606 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 607 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 608 | property_value[0] = '\0'; |
| 609 | property_get("vidc.dec.debug.concealedmb", property_value, "0"); |
| 610 | m_debug_concealedmb = atoi(property_value); |
| 611 | 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] | 612 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 613 | property_value[0] = '\0'; |
| 614 | property_get("vidc.dec.profile.check", property_value, "0"); |
| 615 | m_reject_avc_1080p_mp = atoi(property_value); |
| 616 | 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] | 617 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 618 | property_value[0] = '\0'; |
| 619 | property_get("vidc.dec.log.in", property_value, "0"); |
| 620 | m_debug.in_buffer_log = atoi(property_value); |
| 621 | |
| 622 | property_value[0] = '\0'; |
| 623 | property_get("vidc.dec.log.out", property_value, "0"); |
| 624 | m_debug.out_buffer_log = atoi(property_value); |
| 625 | sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC); |
| 626 | |
| 627 | property_value[0] = '\0'; |
| 628 | property_get("vidc.log.loc", property_value, ""); |
| 629 | if (*property_value) |
| 630 | strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 631 | |
| 632 | property_value[0] = '\0'; |
| 633 | property_get("vidc.dec.120fps.enabled", property_value, "0"); |
| 634 | |
| 635 | //if this feature is not enabled then reset this value -ve |
| 636 | if(atoi(property_value)) { |
| 637 | DEBUG_PRINT_LOW("feature 120 FPS decode enabled"); |
| 638 | m_last_rendered_TS = 0; |
| 639 | } |
| 640 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 641 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 642 | memset(&m_cmp,0,sizeof(m_cmp)); |
| 643 | memset(&m_cb,0,sizeof(m_cb)); |
| 644 | memset (&drv_ctx,0,sizeof(drv_ctx)); |
| 645 | memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE)); |
| 646 | memset (m_hwdevice_name,0,sizeof(m_hwdevice_name)); |
| 647 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 648 | memset(&m_custom_buffersize, 0, sizeof(m_custom_buffersize)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 649 | m_demux_entries = 0; |
| 650 | msg_thread_id = 0; |
| 651 | async_thread_id = 0; |
| 652 | msg_thread_created = false; |
| 653 | async_thread_created = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 654 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 655 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 656 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 657 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 658 | memset(&m_frame_pack_arrangement, 0, sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 659 | drv_ctx.timestamp_adjust = false; |
| 660 | drv_ctx.video_driver_fd = -1; |
| 661 | m_vendor_config.pData = NULL; |
| 662 | pthread_mutex_init(&m_lock, NULL); |
| 663 | pthread_mutex_init(&c_lock, NULL); |
| 664 | sem_init(&m_cmd_lock,0,0); |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 665 | sem_init(&m_safe_flush, 0, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 666 | streaming[CAPTURE_PORT] = |
| 667 | streaming[OUTPUT_PORT] = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 668 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 669 | char extradata_value[PROPERTY_VALUE_MAX] = {0}; |
| 670 | property_get("vidc.dec.debug.extradata", extradata_value, "0"); |
| 671 | m_debug_extradata = atoi(extradata_value); |
| 672 | DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 673 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 674 | m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB; |
| 675 | client_buffers.set_vdec_client(this); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 676 | dynamic_buf_mode = false; |
| 677 | out_dynamic_list = NULL; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 678 | is_down_scalar_enabled = false; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 679 | m_smoothstreaming_mode = false; |
| 680 | m_smoothstreaming_width = 0; |
| 681 | m_smoothstreaming_height = 0; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 682 | is_q6_platform = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 685 | static const int event_type[] = { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 686 | V4L2_EVENT_MSM_VIDC_FLUSH_DONE, |
| 687 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT, |
| 688 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT, |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 689 | V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE, |
| 690 | V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 691 | V4L2_EVENT_MSM_VIDC_CLOSE_DONE, |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 692 | V4L2_EVENT_MSM_VIDC_SYS_ERROR, |
| 693 | V4L2_EVENT_MSM_VIDC_HW_OVERLOAD |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 694 | }; |
| 695 | |
| 696 | static OMX_ERRORTYPE subscribe_to_events(int fd) |
| 697 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 698 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 699 | struct v4l2_event_subscription sub; |
| 700 | int array_sz = sizeof(event_type)/sizeof(int); |
| 701 | int i,rc; |
| 702 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 703 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 704 | return OMX_ErrorBadParameter; |
| 705 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 706 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 707 | for (i = 0; i < array_sz; ++i) { |
| 708 | memset(&sub, 0, sizeof(sub)); |
| 709 | sub.type = event_type[i]; |
| 710 | rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub); |
| 711 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 712 | DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 713 | break; |
| 714 | } |
| 715 | } |
| 716 | if (i < array_sz) { |
| 717 | for (--i; i >=0 ; i--) { |
| 718 | memset(&sub, 0, sizeof(sub)); |
| 719 | sub.type = event_type[i]; |
| 720 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 721 | if (rc) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 722 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 723 | } |
| 724 | eRet = OMX_ErrorNotImplemented; |
| 725 | } |
| 726 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | static OMX_ERRORTYPE unsubscribe_to_events(int fd) |
| 731 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 732 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 733 | struct v4l2_event_subscription sub; |
| 734 | int array_sz = sizeof(event_type)/sizeof(int); |
| 735 | int i,rc; |
| 736 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 737 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 738 | return OMX_ErrorBadParameter; |
| 739 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 740 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 741 | for (i = 0; i < array_sz; ++i) { |
| 742 | memset(&sub, 0, sizeof(sub)); |
| 743 | sub.type = event_type[i]; |
| 744 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 745 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 746 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | } |
| 750 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 751 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 752 | |
| 753 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 754 | FUNCTION |
| 755 | omx_vdec::~omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 756 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 757 | DESCRIPTION |
| 758 | Destructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 759 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 760 | PARAMETERS |
| 761 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 762 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 763 | RETURN VALUE |
| 764 | None. |
| 765 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 766 | omx_vdec::~omx_vdec() |
| 767 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 768 | m_pmem_info = NULL; |
| 769 | struct v4l2_decoder_cmd dec; |
| 770 | DEBUG_PRINT_HIGH("In OMX vdec Destructor"); |
| 771 | if (m_pipe_in) close(m_pipe_in); |
| 772 | if (m_pipe_out) close(m_pipe_out); |
| 773 | m_pipe_in = -1; |
| 774 | m_pipe_out = -1; |
| 775 | DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit"); |
| 776 | if (msg_thread_created) |
| 777 | pthread_join(msg_thread_id,NULL); |
| 778 | DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit"); |
| 779 | dec.cmd = V4L2_DEC_CMD_STOP; |
| 780 | if (drv_ctx.video_driver_fd >=0 ) { |
| 781 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 782 | DEBUG_PRINT_ERROR("STOP Command failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 783 | } |
| 784 | if (async_thread_created) |
| 785 | pthread_join(async_thread_id,NULL); |
| 786 | unsubscribe_to_events(drv_ctx.video_driver_fd); |
| 787 | close(drv_ctx.video_driver_fd); |
| 788 | pthread_mutex_destroy(&m_lock); |
| 789 | pthread_mutex_destroy(&c_lock); |
| 790 | sem_destroy(&m_cmd_lock); |
| 791 | if (perf_flag) { |
| 792 | DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME"); |
| 793 | dec_time.end(); |
| 794 | } |
| 795 | DEBUG_PRINT_HIGH("Exit OMX vdec Destructor"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 798 | int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type) |
| 799 | { |
| 800 | struct v4l2_requestbuffers bufreq; |
| 801 | int rc = 0; |
| 802 | if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 803 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 804 | bufreq.count = 0; |
| 805 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 806 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 807 | } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 808 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 809 | bufreq.count = 0; |
| 810 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 811 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 812 | } |
| 813 | return rc; |
Vinay Kalia | feef703 | 2012-09-25 19:23:33 -0700 | [diff] [blame] | 814 | } |
| 815 | |
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 | FUNCTION |
| 818 | omx_vdec::OMXCntrlProcessMsgCb |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 819 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 820 | DESCRIPTION |
| 821 | IL Client callbacks are generated through this routine. The decoder |
| 822 | provides the thread context for this routine. |
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 | PARAMETERS |
| 825 | ctxt -- Context information related to the self. |
| 826 | id -- Event identifier. This could be any of the following: |
| 827 | 1. Command completion event |
| 828 | 2. Buffer done callback event |
| 829 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 830 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 831 | RETURN VALUE |
| 832 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 833 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 834 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 835 | void omx_vdec::process_event_cb(void *ctxt, unsigned char id) |
| 836 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 837 | signed p1; // Parameter - 1 |
| 838 | signed p2; // Parameter - 2 |
| 839 | unsigned ident; |
| 840 | unsigned qsize=0; // qsize |
| 841 | omx_vdec *pThis = (omx_vdec *) ctxt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 842 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 843 | if (!pThis) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 844 | DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 845 | __func__); |
| 846 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 849 | // Protect the shared queue data structure |
| 850 | do { |
| 851 | /*Read the message id's from the queue*/ |
| 852 | pthread_mutex_lock(&pThis->m_lock); |
| 853 | qsize = pThis->m_cmd_q.m_size; |
| 854 | if (qsize) { |
| 855 | pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 856 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 857 | |
| 858 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 859 | qsize = pThis->m_ftb_q.m_size; |
| 860 | if (qsize) { |
| 861 | pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 862 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 863 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 864 | |
| 865 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 866 | qsize = pThis->m_etb_q.m_size; |
| 867 | if (qsize) { |
| 868 | pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 869 | } |
| 870 | } |
| 871 | pthread_mutex_unlock(&pThis->m_lock); |
| 872 | |
| 873 | /*process message if we have one*/ |
| 874 | if (qsize > 0) { |
| 875 | id = ident; |
| 876 | switch (id) { |
| 877 | case OMX_COMPONENT_GENERATE_EVENT: |
| 878 | if (pThis->m_cb.EventHandler) { |
| 879 | switch (p1) { |
| 880 | case OMX_CommandStateSet: |
| 881 | pThis->m_state = (OMX_STATETYPE) p2; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 882 | DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 883 | pThis->m_state); |
| 884 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 885 | OMX_EventCmdComplete, p1, p2, NULL); |
| 886 | break; |
| 887 | |
| 888 | case OMX_EventError: |
| 889 | if (p2 == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 890 | DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 891 | pThis->m_state = (OMX_STATETYPE) p2; |
| 892 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 893 | OMX_EventError, OMX_ErrorInvalidState, p2, NULL); |
| 894 | } else if (p2 == OMX_ErrorHardware) { |
| 895 | pThis->omx_report_error(); |
| 896 | } else { |
| 897 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 898 | OMX_EventError, p2, (OMX_U32)NULL, NULL ); |
| 899 | } |
| 900 | break; |
| 901 | |
| 902 | case OMX_CommandPortDisable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 903 | DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 904 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 905 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
| 906 | BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
| 907 | break; |
| 908 | } |
| 909 | if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 910 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 911 | pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
| 912 | if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 913 | DEBUG_PRINT_HIGH("Failed to release output buffers"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 914 | OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf); |
| 915 | pThis->in_reconfig = false; |
| 916 | if (eRet != OMX_ErrorNone) { |
| 917 | DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet); |
| 918 | pThis->omx_report_error(); |
| 919 | break; |
| 920 | } |
| 921 | } |
| 922 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 923 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 924 | break; |
| 925 | case OMX_CommandPortEnable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 926 | DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 927 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\ |
| 928 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 929 | break; |
| 930 | |
| 931 | default: |
| 932 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 933 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 934 | break; |
| 935 | |
| 936 | } |
| 937 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 938 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 939 | } |
| 940 | break; |
| 941 | case OMX_COMPONENT_GENERATE_ETB_ARBITRARY: |
| 942 | if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 943 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 944 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 945 | pThis->omx_report_error (); |
| 946 | } |
| 947 | break; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 948 | case OMX_COMPONENT_GENERATE_ETB: { |
| 949 | OMX_ERRORTYPE iret; |
| 950 | iret = pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1, (OMX_BUFFERHEADERTYPE *)p2); |
| 951 | if (iret == OMX_ErrorInsufficientResources) { |
| 952 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure due to HW overload"); |
| 953 | pThis->omx_report_hw_overload (); |
| 954 | } else if (iret != OMX_ErrorNone) { |
| 955 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure"); |
| 956 | pThis->omx_report_error (); |
| 957 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 958 | } |
| 959 | break; |
| 960 | |
| 961 | case OMX_COMPONENT_GENERATE_FTB: |
| 962 | if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 963 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 964 | DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 965 | pThis->omx_report_error (); |
| 966 | } |
| 967 | break; |
| 968 | |
| 969 | case OMX_COMPONENT_GENERATE_COMMAND: |
| 970 | pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\ |
| 971 | (OMX_U32)p2,(OMX_PTR)NULL); |
| 972 | break; |
| 973 | |
| 974 | case OMX_COMPONENT_GENERATE_EBD: |
| 975 | |
| 976 | if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 977 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 978 | pThis->omx_report_error (); |
| 979 | } else { |
| 980 | if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 981 | pThis->time_stamp_dts.remove_time_stamp( |
| 982 | ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp, |
| 983 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 984 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 985 | } |
Deva Ramasubramanian | 02b0d88 | 2014-04-03 14:58:50 -0700 | [diff] [blame] | 986 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 987 | if ( pThis->empty_buffer_done(&pThis->m_cmp, |
| 988 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 989 | DEBUG_PRINT_ERROR("empty_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 990 | pThis->omx_report_error (); |
| 991 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 992 | } |
| 993 | break; |
| 994 | case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: { |
| 995 | int64_t *timestamp = (int64_t *)p1; |
| 996 | if (p1) { |
| 997 | pThis->time_stamp_dts.remove_time_stamp(*timestamp, |
| 998 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 999 | ?true:false); |
| 1000 | free(timestamp); |
| 1001 | } |
| 1002 | } |
| 1003 | break; |
| 1004 | case OMX_COMPONENT_GENERATE_FBD: |
| 1005 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1006 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1007 | pThis->omx_report_error (); |
| 1008 | } else if ( pThis->fill_buffer_done(&pThis->m_cmp, |
| 1009 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1010 | DEBUG_PRINT_ERROR("fill_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1011 | pThis->omx_report_error (); |
| 1012 | } |
| 1013 | break; |
| 1014 | |
| 1015 | case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1016 | DEBUG_PRINT_HIGH("Driver flush i/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1017 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1018 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1019 | } else { |
| 1020 | pThis->execute_input_flush(); |
| 1021 | if (pThis->m_cb.EventHandler) { |
| 1022 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1023 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1024 | pThis->omx_report_error (); |
| 1025 | } else { |
| 1026 | /*Check if we need generate event for Flush done*/ |
| 1027 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1028 | OMX_COMPONENT_INPUT_FLUSH_PENDING)) { |
| 1029 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1030 | DEBUG_PRINT_LOW("Input Flush completed - Notify Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1031 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1032 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1033 | OMX_CORE_INPUT_PORT_INDEX,NULL ); |
| 1034 | } |
| 1035 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1036 | OMX_COMPONENT_IDLE_PENDING)) { |
| 1037 | if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1038 | DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1039 | pThis->omx_report_error (); |
| 1040 | } else { |
| 1041 | pThis->streaming[OUTPUT_PORT] = false; |
| 1042 | } |
| 1043 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1044 | DEBUG_PRINT_LOW("Input flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1045 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1046 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | } else { |
| 1051 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1052 | } |
| 1053 | } |
| 1054 | break; |
| 1055 | |
| 1056 | case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1057 | DEBUG_PRINT_HIGH("Driver flush o/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1058 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1059 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1060 | } else { |
| 1061 | pThis->execute_output_flush(); |
| 1062 | if (pThis->m_cb.EventHandler) { |
| 1063 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1064 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1065 | pThis->omx_report_error (); |
| 1066 | } else { |
| 1067 | /*Check if we need generate event for Flush done*/ |
| 1068 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1069 | OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1070 | DEBUG_PRINT_LOW("Notify Output Flush done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1071 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 1072 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1073 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1074 | OMX_CORE_OUTPUT_PORT_INDEX,NULL ); |
| 1075 | } |
| 1076 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1077 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1078 | DEBUG_PRINT_LOW("Internal flush complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1079 | BITMASK_CLEAR (&pThis->m_flags, |
| 1080 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 1081 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1082 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) { |
| 1083 | pThis->post_event(OMX_CommandPortDisable, |
| 1084 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 1085 | OMX_COMPONENT_GENERATE_EVENT); |
| 1086 | BITMASK_CLEAR (&pThis->m_flags, |
| 1087 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
Praneeth Paladugu | b52072a | 2013-08-23 13:54:43 -0700 | [diff] [blame] | 1088 | BITMASK_CLEAR (&pThis->m_flags, |
| 1089 | OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1090 | |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) { |
| 1095 | if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1096 | DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1097 | pThis->omx_report_error (); |
| 1098 | break; |
| 1099 | } |
| 1100 | pThis->streaming[CAPTURE_PORT] = false; |
| 1101 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1102 | DEBUG_PRINT_LOW("Output flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1103 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1104 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | } else { |
| 1109 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1110 | } |
| 1111 | } |
| 1112 | break; |
| 1113 | |
| 1114 | case OMX_COMPONENT_GENERATE_START_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1115 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1116 | |
| 1117 | if (pThis->m_cb.EventHandler) { |
| 1118 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1119 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1120 | pThis->omx_report_error (); |
| 1121 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1122 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1123 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1124 | DEBUG_PRINT_LOW("Move to executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1125 | // Send the callback now |
| 1126 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1127 | pThis->m_state = OMX_StateExecuting; |
| 1128 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1129 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1130 | OMX_StateExecuting, NULL); |
| 1131 | } else if (BITMASK_PRESENT(&pThis->m_flags, |
| 1132 | OMX_COMPONENT_PAUSE_PENDING)) { |
| 1133 | if (/*ioctl (pThis->drv_ctx.video_driver_fd, |
| 1134 | VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1135 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1136 | pThis->omx_report_error (); |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1141 | DEBUG_PRINT_LOW("Event Handler callback is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1142 | } |
| 1143 | break; |
| 1144 | |
| 1145 | case OMX_COMPONENT_GENERATE_PAUSE_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1146 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1147 | if (pThis->m_cb.EventHandler) { |
| 1148 | if (p2 != VDEC_S_SUCCESS) { |
| 1149 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed"); |
| 1150 | pThis->omx_report_error (); |
| 1151 | } else { |
| 1152 | pThis->complete_pending_buffer_done_cbs(); |
| 1153 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1154 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1155 | //Send the callback now |
| 1156 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING); |
| 1157 | pThis->m_state = OMX_StatePause; |
| 1158 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1159 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1160 | OMX_StatePause, NULL); |
| 1161 | } |
| 1162 | } |
| 1163 | } else { |
| 1164 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1165 | } |
| 1166 | |
| 1167 | break; |
| 1168 | |
| 1169 | case OMX_COMPONENT_GENERATE_RESUME_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1170 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1171 | if (pThis->m_cb.EventHandler) { |
| 1172 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1173 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1174 | pThis->omx_report_error (); |
| 1175 | } else { |
| 1176 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1177 | DEBUG_PRINT_LOW("Moving the decoder to execute state"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1178 | // Send the callback now |
| 1179 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1180 | pThis->m_state = OMX_StateExecuting; |
| 1181 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1182 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1183 | OMX_StateExecuting,NULL); |
| 1184 | } |
| 1185 | } |
| 1186 | } else { |
| 1187 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1188 | } |
| 1189 | |
| 1190 | break; |
| 1191 | |
| 1192 | case OMX_COMPONENT_GENERATE_STOP_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1193 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1194 | if (pThis->m_cb.EventHandler) { |
| 1195 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1196 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1197 | pThis->omx_report_error (); |
| 1198 | } else { |
| 1199 | pThis->complete_pending_buffer_done_cbs(); |
| 1200 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1201 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1202 | // Send the callback now |
| 1203 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 1204 | pThis->m_state = OMX_StateIdle; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1205 | DEBUG_PRINT_LOW("Move to Idle State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1206 | pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data, |
| 1207 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1208 | OMX_StateIdle,NULL); |
| 1209 | } |
| 1210 | } |
| 1211 | } else { |
| 1212 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1213 | } |
| 1214 | |
| 1215 | break; |
| 1216 | |
| 1217 | case OMX_COMPONENT_GENERATE_PORT_RECONFIG: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1218 | if (p2 == OMX_IndexParamPortDefinition) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1219 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1220 | pThis->in_reconfig = true; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1221 | |
| 1222 | } else if (p2 == OMX_IndexConfigCommonOutputCrop) { |
| 1223 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexConfigCommonOutputCrop"); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1224 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1225 | /* Check if resolution is changed in smooth streaming mode */ |
| 1226 | if (pThis->m_smoothstreaming_mode && |
| 1227 | (pThis->framesize.nWidth != |
| 1228 | pThis->drv_ctx.video_resolution.frame_width) || |
| 1229 | (pThis->framesize.nHeight != |
| 1230 | pThis->drv_ctx.video_resolution.frame_height)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1231 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1232 | DEBUG_PRINT_HIGH("Resolution changed from: wxh = %dx%d to: wxh = %dx%d", |
| 1233 | pThis->framesize.nWidth, |
| 1234 | pThis->framesize.nHeight, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1235 | pThis->drv_ctx.video_resolution.frame_width, |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1236 | pThis->drv_ctx.video_resolution.frame_height); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1237 | |
| 1238 | /* Update new resolution */ |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1239 | pThis->framesize.nWidth = |
| 1240 | pThis->drv_ctx.video_resolution.frame_width; |
| 1241 | pThis->framesize.nHeight = |
| 1242 | pThis->drv_ctx.video_resolution.frame_height; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1243 | |
| 1244 | /* Update C2D with new resolution */ |
| 1245 | if (!pThis->client_buffers.update_buffer_req()) { |
| 1246 | DEBUG_PRINT_ERROR("Setting C2D buffer requirements failed"); |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | /* Update new crop information */ |
| 1251 | pThis->rectangle.nLeft = pThis->drv_ctx.frame_size.left; |
| 1252 | pThis->rectangle.nTop = pThis->drv_ctx.frame_size.top; |
| 1253 | pThis->rectangle.nWidth = pThis->drv_ctx.frame_size.right; |
| 1254 | pThis->rectangle.nHeight = pThis->drv_ctx.frame_size.bottom; |
| 1255 | |
| 1256 | /* Validate the new crop information */ |
| 1257 | if (pThis->rectangle.nLeft + pThis->rectangle.nWidth > |
| 1258 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1259 | |
| 1260 | DEBUG_PRINT_HIGH("Crop L[%u] + R[%u] > W[%u]", |
| 1261 | pThis->rectangle.nLeft, pThis->rectangle.nWidth, |
| 1262 | pThis->drv_ctx.video_resolution.frame_width); |
| 1263 | pThis->rectangle.nLeft = 0; |
| 1264 | |
| 1265 | if (pThis->rectangle.nWidth > |
| 1266 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1267 | |
| 1268 | DEBUG_PRINT_HIGH("Crop R[%u] > W[%u]", |
| 1269 | pThis->rectangle.nWidth, |
| 1270 | pThis->drv_ctx.video_resolution.frame_width); |
| 1271 | pThis->rectangle.nWidth = |
| 1272 | pThis->drv_ctx.video_resolution.frame_width; |
| 1273 | } |
| 1274 | } |
| 1275 | if (pThis->rectangle.nTop + pThis->rectangle.nHeight > |
| 1276 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1277 | |
| 1278 | DEBUG_PRINT_HIGH("Crop T[%u] + B[%u] > H[%u]", |
| 1279 | pThis->rectangle.nTop, pThis->rectangle.nHeight, |
| 1280 | pThis->drv_ctx.video_resolution.frame_height); |
| 1281 | pThis->rectangle.nTop = 0; |
| 1282 | |
| 1283 | if (pThis->rectangle.nHeight > |
| 1284 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1285 | |
| 1286 | DEBUG_PRINT_HIGH("Crop B[%u] > H[%u]", |
| 1287 | pThis->rectangle.nHeight, |
| 1288 | pThis->drv_ctx.video_resolution.frame_height); |
| 1289 | pThis->rectangle.nHeight = |
| 1290 | pThis->drv_ctx.video_resolution.frame_height; |
| 1291 | } |
| 1292 | } |
| 1293 | DEBUG_PRINT_HIGH("Updated Crop Info: L: %u, T: %u, R: %u, B: %u", |
| 1294 | pThis->rectangle.nLeft, pThis->rectangle.nTop, |
| 1295 | pThis->rectangle.nWidth, pThis->rectangle.nHeight); |
| 1296 | } else { |
| 1297 | DEBUG_PRINT_ERROR("Rxd Invalid PORT_RECONFIG event (%lu)", p2); |
| 1298 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1299 | } |
| 1300 | if (pThis->m_cb.EventHandler) { |
| 1301 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1302 | OMX_EventPortSettingsChanged, p1, p2, NULL ); |
| 1303 | } else { |
| 1304 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1305 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case OMX_COMPONENT_GENERATE_EOS_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1309 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1310 | if (pThis->m_cb.EventHandler) { |
| 1311 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag, |
| 1312 | OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL ); |
| 1313 | } else { |
| 1314 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1315 | } |
| 1316 | pThis->prev_ts = LLONG_MAX; |
| 1317 | pThis->rst_prev_ts = true; |
| 1318 | break; |
| 1319 | |
| 1320 | case OMX_COMPONENT_GENERATE_HARDWARE_ERROR: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1321 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1322 | pThis->omx_report_error (); |
| 1323 | break; |
| 1324 | |
| 1325 | case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1326 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1327 | pThis->omx_report_unsupported_setting(); |
| 1328 | break; |
| 1329 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 1330 | case OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD: |
| 1331 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD"); |
| 1332 | pThis->omx_report_hw_overload(); |
| 1333 | break; |
| 1334 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1335 | default: |
| 1336 | break; |
| 1337 | } |
| 1338 | } |
| 1339 | pthread_mutex_lock(&pThis->m_lock); |
| 1340 | qsize = pThis->m_cmd_q.m_size; |
| 1341 | if (pThis->m_state != OMX_StatePause) |
| 1342 | qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size); |
| 1343 | pthread_mutex_unlock(&pThis->m_lock); |
| 1344 | } while (qsize>0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1345 | |
| 1346 | } |
| 1347 | |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 1348 | 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] | 1349 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1350 | int format_changed = 0; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 1351 | if ((height != (int)drv_ctx.video_resolution.frame_height) || |
| 1352 | (width != (int)drv_ctx.video_resolution.frame_width)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1353 | DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1354 | width, drv_ctx.video_resolution.frame_width, |
| 1355 | height,drv_ctx.video_resolution.frame_height); |
| 1356 | format_changed = 1; |
| 1357 | } |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1358 | drv_ctx.video_resolution.frame_height = height; |
| 1359 | drv_ctx.video_resolution.frame_width = width; |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 1360 | drv_ctx.video_resolution.scan_lines = scan_lines; |
| 1361 | drv_ctx.video_resolution.stride = stride; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 1362 | if(!is_down_scalar_enabled) { |
| 1363 | rectangle.nLeft = 0; |
| 1364 | rectangle.nTop = 0; |
| 1365 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1366 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
| 1367 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1368 | return format_changed; |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1371 | OMX_ERRORTYPE omx_vdec::is_video_session_supported() |
| 1372 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1373 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", |
| 1374 | OMX_MAX_STRINGNAME_SIZE) && |
| 1375 | (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) { |
| 1376 | m_decoder_capability.max_width = 1280; |
| 1377 | m_decoder_capability.max_height = 720; |
| 1378 | DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP"); |
| 1379 | } |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 1380 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1381 | if ((drv_ctx.video_resolution.frame_width * |
| 1382 | drv_ctx.video_resolution.frame_height > |
| 1383 | m_decoder_capability.max_width * |
| 1384 | m_decoder_capability.max_height) || |
| 1385 | (drv_ctx.video_resolution.frame_width* |
| 1386 | drv_ctx.video_resolution.frame_height < |
| 1387 | m_decoder_capability.min_width * |
| 1388 | m_decoder_capability.min_height)) { |
| 1389 | DEBUG_PRINT_ERROR( |
| 1390 | "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)", |
| 1391 | drv_ctx.video_resolution.frame_width, |
| 1392 | drv_ctx.video_resolution.frame_height, |
| 1393 | m_decoder_capability.min_width, |
| 1394 | m_decoder_capability.min_height, |
| 1395 | m_decoder_capability.max_width, |
| 1396 | m_decoder_capability.max_height); |
| 1397 | return OMX_ErrorUnsupportedSetting; |
| 1398 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1399 | DEBUG_PRINT_HIGH("video session supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1400 | return OMX_ErrorNone; |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1401 | } |
| 1402 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1403 | int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len) |
| 1404 | { |
| 1405 | if (m_debug.in_buffer_log && !m_debug.infile) { |
| 1406 | if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) { |
| 1407 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v", |
| 1408 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1409 | } |
| 1410 | else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) { |
| 1411 | 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); } |
| 1412 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) { |
| 1413 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263", |
| 1414 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1415 | } |
| 1416 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) { |
| 1417 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264", |
| 1418 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1419 | } |
| 1420 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) { |
| 1421 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1422 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1423 | } |
| 1424 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) { |
| 1425 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1426 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1427 | } |
| 1428 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1429 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf", |
| 1430 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1431 | } |
| 1432 | m_debug.infile = fopen (m_debug.infile_name, "ab"); |
| 1433 | if (!m_debug.infile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1434 | 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] | 1435 | m_debug.infile_name[0] = '\0'; |
| 1436 | return -1; |
| 1437 | } |
| 1438 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1439 | struct ivf_file_header { |
| 1440 | OMX_U8 signature[4]; //='DKIF'; |
| 1441 | OMX_U8 version ; //= 0; |
| 1442 | OMX_U8 headersize ; //= 32; |
| 1443 | OMX_U32 FourCC; |
| 1444 | OMX_U8 width; |
| 1445 | OMX_U8 height; |
| 1446 | OMX_U32 rate; |
| 1447 | OMX_U32 scale; |
| 1448 | OMX_U32 length; |
| 1449 | OMX_U8 unused[4]; |
| 1450 | } file_header; |
| 1451 | |
| 1452 | memset((void *)&file_header,0,sizeof(file_header)); |
| 1453 | file_header.signature[0] = 'D'; |
| 1454 | file_header.signature[1] = 'K'; |
| 1455 | file_header.signature[2] = 'I'; |
| 1456 | file_header.signature[3] = 'F'; |
| 1457 | file_header.version = 0; |
| 1458 | file_header.headersize = 32; |
| 1459 | file_header.FourCC = 0x30385056; |
| 1460 | fwrite((const char *)&file_header, |
| 1461 | sizeof(file_header),1,m_debug.infile); |
| 1462 | } |
| 1463 | } |
| 1464 | if (m_debug.infile && buffer_addr && buffer_len) { |
| 1465 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1466 | struct vp8_ivf_frame_header { |
| 1467 | OMX_U32 framesize; |
| 1468 | OMX_U32 timestamp_lo; |
| 1469 | OMX_U32 timestamp_hi; |
| 1470 | } vp8_frame_header; |
| 1471 | vp8_frame_header.framesize = buffer_len; |
| 1472 | /* Currently FW doesn't use timestamp values */ |
| 1473 | vp8_frame_header.timestamp_lo = 0; |
| 1474 | vp8_frame_header.timestamp_hi = 0; |
| 1475 | fwrite((const char *)&vp8_frame_header, |
| 1476 | sizeof(vp8_frame_header),1,m_debug.infile); |
| 1477 | } |
| 1478 | fwrite(buffer_addr, buffer_len, 1, m_debug.infile); |
| 1479 | } |
| 1480 | return 0; |
| 1481 | } |
| 1482 | |
| 1483 | int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) { |
| 1484 | if (m_debug.out_buffer_log && !m_debug.outfile) { |
| 1485 | sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv", |
| 1486 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1487 | m_debug.outfile = fopen (m_debug.outfile_name, "ab"); |
| 1488 | if (!m_debug.outfile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1489 | 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] | 1490 | m_debug.outfile_name[0] = '\0'; |
| 1491 | return -1; |
| 1492 | } |
| 1493 | } |
| 1494 | if (m_debug.outfile && buffer && buffer->nFilledLen) { |
| 1495 | int buf_index = buffer - m_out_mem_ptr; |
| 1496 | int stride = drv_ctx.video_resolution.stride; |
| 1497 | int scanlines = drv_ctx.video_resolution.scan_lines; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1498 | if (m_smoothstreaming_mode) { |
| 1499 | stride = drv_ctx.video_resolution.frame_width; |
| 1500 | scanlines = drv_ctx.video_resolution.frame_height; |
| 1501 | stride = (stride + DEFAULT_WIDTH_ALIGNMENT - 1) & (~(DEFAULT_WIDTH_ALIGNMENT - 1)); |
| 1502 | scanlines = (scanlines + DEFAULT_HEIGHT_ALIGNMENT - 1) & (~(DEFAULT_HEIGHT_ALIGNMENT - 1)); |
| 1503 | } |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1504 | char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr; |
| 1505 | unsigned i; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1506 | DEBUG_PRINT_HIGH("Logging width/height(%u/%u) stride/scanlines(%u/%u)", |
| 1507 | drv_ctx.video_resolution.frame_width, |
| 1508 | drv_ctx.video_resolution.frame_height, stride, scanlines); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1509 | int bytes_written = 0; |
| 1510 | for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) { |
| 1511 | bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1512 | temp += stride; |
| 1513 | } |
| 1514 | temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines; |
| 1515 | int stride_c = stride; |
| 1516 | for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) { |
| 1517 | bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1518 | temp += stride_c; |
| 1519 | } |
| 1520 | } |
| 1521 | return 0; |
| 1522 | } |
| 1523 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1524 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1525 | FUNCTION |
| 1526 | omx_vdec::ComponentInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1527 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1528 | DESCRIPTION |
| 1529 | Initialize the component. |
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 | PARAMETERS |
| 1532 | ctxt -- Context information related to the self. |
| 1533 | id -- Event identifier. This could be any of the following: |
| 1534 | 1. Command completion event |
| 1535 | 2. Buffer done callback event |
| 1536 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1537 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1538 | RETURN VALUE |
| 1539 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1540 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1541 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1542 | OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role) |
| 1543 | { |
| 1544 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1545 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 1546 | struct v4l2_fmtdesc fdesc; |
| 1547 | struct v4l2_format fmt; |
| 1548 | struct v4l2_requestbuffers bufreq; |
| 1549 | struct v4l2_control control; |
| 1550 | struct v4l2_frmsizeenum frmsize; |
| 1551 | unsigned int alignment = 0,buffer_size = 0; |
| 1552 | int fds[2]; |
| 1553 | int r,ret=0; |
| 1554 | bool codec_ambiguous = false; |
Praveen Chavan | 00ec0ce | 2015-05-18 09:44:20 -0700 | [diff] [blame] | 1555 | OMX_STRING device_name = (OMX_STRING)"/dev/video32"; |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 1556 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1557 | |
| 1558 | #ifdef _ANDROID_ |
Praveen Chavan | e9e5620 | 2013-09-19 03:48:16 -0700 | [diff] [blame] | 1559 | char platform_name[PROPERTY_VALUE_MAX]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1560 | property_get("ro.board.platform", platform_name, "0"); |
| 1561 | if (!strncmp(platform_name, "msm8610", 7)) { |
Balamurugan Alagarsamy | 1693e59 | 2015-07-23 19:19:05 +0530 | [diff] [blame] | 1562 | device_name = (OMX_STRING)"/dev/video34"; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1563 | is_q6_platform = true; |
| 1564 | maxSmoothStreamingWidth = 1280; |
| 1565 | maxSmoothStreamingHeight = 720; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1566 | } |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1567 | #endif |
| 1568 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1569 | if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) { |
| 1570 | struct v4l2_control control; |
| 1571 | secure_mode = true; |
| 1572 | arbitrary_bytes = false; |
| 1573 | role = (OMX_STRING)"OMX.qcom.video.decoder.avc"; |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 1574 | } else if (!strncmp(role, "OMX.qcom.video.decoder.mpeg2.secure", |
| 1575 | OMX_MAX_STRINGNAME_SIZE)){ |
| 1576 | secure_mode = true; |
| 1577 | arbitrary_bytes = false; |
| 1578 | role = (OMX_STRING)"OMX.qcom.video.decoder.mpeg2"; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1579 | } |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1580 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1581 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1582 | |
Balamurugan Alagarsamy | 1693e59 | 2015-07-23 19:19:05 +0530 | [diff] [blame] | 1583 | DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open device %s returned fd %d", |
| 1584 | device_name, drv_ctx.video_driver_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1585 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1586 | if (drv_ctx.video_driver_fd == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1587 | 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] | 1588 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
| 1589 | close(0); |
| 1590 | } |
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 | if (drv_ctx.video_driver_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1593 | DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1594 | return OMX_ErrorInsufficientResources; |
| 1595 | } |
| 1596 | drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS; |
| 1597 | drv_ctx.frame_rate.fps_denominator = 1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1598 | |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1599 | ret = subscribe_to_events(drv_ctx.video_driver_fd); |
Vinay Kalia | 184cd0f | 2013-04-29 18:26:42 -0700 | [diff] [blame] | 1600 | if (!ret) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1601 | async_thread_created = true; |
| 1602 | ret = pthread_create(&async_thread_id,0,async_message_thread,this); |
| 1603 | } |
| 1604 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1605 | DEBUG_PRINT_ERROR("Failed to create async_message_thread"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1606 | async_thread_created = false; |
| 1607 | return OMX_ErrorInsufficientResources; |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1608 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1609 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1610 | #ifdef OUTPUT_EXTRADATA_LOG |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 1611 | outputExtradataFile = fopen (output_extradata_filename, "ab"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1612 | #endif |
| 1613 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1614 | // Copy the role information which provides the decoder kind |
| 1615 | strlcpy(drv_ctx.kind,role,128); |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1616 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1617 | if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\ |
| 1618 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1619 | strlcpy((char *)m_cRole, "video_decoder.mpeg4",\ |
| 1620 | OMX_MAX_STRINGNAME_SIZE); |
| 1621 | drv_ctx.timestamp_adjust = true; |
| 1622 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4; |
| 1623 | eCompressionFormat = OMX_VIDEO_CodingMPEG4; |
| 1624 | output_capability=V4L2_PIX_FMT_MPEG4; |
| 1625 | /*Initialize Start Code for MPEG4*/ |
| 1626 | codec_type_parse = CODEC_TYPE_MPEG4; |
| 1627 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1628 | } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\ |
| 1629 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1630 | strlcpy((char *)m_cRole, "video_decoder.mpeg2",\ |
| 1631 | OMX_MAX_STRINGNAME_SIZE); |
| 1632 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2; |
| 1633 | output_capability = V4L2_PIX_FMT_MPEG2; |
| 1634 | eCompressionFormat = OMX_VIDEO_CodingMPEG2; |
| 1635 | /*Initialize Start Code for MPEG2*/ |
| 1636 | codec_type_parse = CODEC_TYPE_MPEG2; |
| 1637 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1638 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\ |
| 1639 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1640 | strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1641 | DEBUG_PRINT_LOW("H263 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1642 | drv_ctx.decoder_format = VDEC_CODECTYPE_H263; |
| 1643 | eCompressionFormat = OMX_VIDEO_CodingH263; |
| 1644 | output_capability = V4L2_PIX_FMT_H263; |
| 1645 | codec_type_parse = CODEC_TYPE_H263; |
| 1646 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1647 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\ |
| 1648 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1649 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1650 | DEBUG_PRINT_LOW ("DIVX 311 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1651 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3; |
| 1652 | output_capability = V4L2_PIX_FMT_DIVX_311; |
| 1653 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1654 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1655 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1656 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1657 | eRet = createDivxDrmContext(); |
| 1658 | if (eRet != OMX_ErrorNone) { |
| 1659 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1660 | return eRet; |
| 1661 | } |
| 1662 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\ |
| 1663 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1664 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1665 | DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1666 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4; |
| 1667 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1668 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1669 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1670 | codec_ambiguous = true; |
| 1671 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1672 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1673 | eRet = createDivxDrmContext(); |
| 1674 | if (eRet != OMX_ErrorNone) { |
| 1675 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1676 | return eRet; |
| 1677 | } |
| 1678 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\ |
| 1679 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1680 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1681 | DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1682 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6; |
| 1683 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1684 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1685 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1686 | codec_ambiguous = true; |
| 1687 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1688 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1689 | eRet = createDivxDrmContext(); |
| 1690 | if (eRet != OMX_ErrorNone) { |
| 1691 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1692 | return eRet; |
| 1693 | } |
Deva Ramasubramanian | 9403f02 | 2012-11-28 18:27:53 -0800 | [diff] [blame] | 1694 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1695 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\ |
| 1696 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1697 | strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 1698 | drv_ctx.decoder_format = VDEC_CODECTYPE_H264; |
| 1699 | output_capability=V4L2_PIX_FMT_H264; |
| 1700 | eCompressionFormat = OMX_VIDEO_CodingAVC; |
| 1701 | codec_type_parse = CODEC_TYPE_H264; |
| 1702 | m_frame_parser.init_start_codes (codec_type_parse); |
| 1703 | m_frame_parser.init_nal_length(nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1704 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\ |
| 1705 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1706 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1707 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1; |
| 1708 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1709 | codec_type_parse = CODEC_TYPE_VC1; |
| 1710 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_G; |
| 1711 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1712 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\ |
| 1713 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1714 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1715 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV; |
| 1716 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1717 | codec_type_parse = CODEC_TYPE_VC1; |
| 1718 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_L; |
| 1719 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1720 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \ |
| 1721 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1722 | strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 1723 | output_capability=V4L2_PIX_FMT_VP8; |
Praveen Chavan | 76b71c3 | 2014-07-10 18:10:51 -0700 | [diff] [blame] | 1724 | eCompressionFormat = OMX_VIDEO_CodingVP8; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1725 | codec_type_parse = CODEC_TYPE_VP8; |
| 1726 | arbitrary_bytes = false; |
Praneeth Paladugu | 2b2ef2d | 2013-04-10 22:04:51 -0700 | [diff] [blame] | 1727 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1728 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1729 | DEBUG_PRINT_ERROR("ERROR:Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1730 | eRet = OMX_ErrorInvalidComponentName; |
| 1731 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1732 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1733 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1734 | drv_ctx.output_format = VDEC_YUV_FORMAT_NV12; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1735 | OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 1736 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 1737 | if (!client_buffers.set_color_format(dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1738 | DEBUG_PRINT_ERROR("Setting color format failed"); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1739 | eRet = OMX_ErrorInsufficientResources; |
| 1740 | } |
| 1741 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1742 | capture_capability= V4L2_PIX_FMT_NV12; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1743 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1744 | struct v4l2_capability cap; |
| 1745 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap); |
| 1746 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1747 | DEBUG_PRINT_ERROR("Failed to query capabilities"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1748 | /*TODO: How to handle this case */ |
| 1749 | } else { |
| 1750 | DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s," |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1751 | " version = %d, capabilities = %x", cap.driver, cap.card, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1752 | cap.bus_info, cap.version, cap.capabilities); |
| 1753 | } |
| 1754 | ret=0; |
| 1755 | fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1756 | fdesc.index=0; |
| 1757 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1758 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1759 | fdesc.pixelformat, fdesc.flags); |
| 1760 | fdesc.index++; |
| 1761 | } |
| 1762 | fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1763 | fdesc.index=0; |
| 1764 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1765 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1766 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1767 | fdesc.pixelformat, fdesc.flags); |
| 1768 | fdesc.index++; |
| 1769 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1770 | update_resolution(320, 240, 320, 240); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1771 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1772 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1773 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1774 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 1775 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1776 | if (ret) { |
| 1777 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1778 | DEBUG_PRINT_ERROR("Failed to set format on output port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1779 | return OMX_ErrorInsufficientResources; |
| 1780 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1781 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1782 | if (codec_ambiguous) { |
| 1783 | if (output_capability == V4L2_PIX_FMT_DIVX) { |
| 1784 | struct v4l2_control divx_ctrl; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1785 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1786 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) { |
| 1787 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4; |
| 1788 | } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) { |
| 1789 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5; |
| 1790 | } else { |
| 1791 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6; |
| 1792 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1793 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1794 | divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT; |
| 1795 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl); |
| 1796 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1797 | DEBUG_PRINT_ERROR("Failed to set divx version"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1798 | } |
| 1799 | } else { |
| 1800 | DEBUG_PRINT_ERROR("Codec should not be ambiguous"); |
| 1801 | } |
| 1802 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1803 | |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 1804 | property_get("persist.vidc.dec.conceal_color", property_value, DEFAULT_CONCEAL_COLOR); |
| 1805 | m_conceal_color= atoi(property_value); |
| 1806 | DEBUG_PRINT_HIGH("trying to set 0x%x as conceal color\n",m_conceal_color); |
| 1807 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR; |
| 1808 | control.value = m_conceal_color; |
| 1809 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 1810 | if (ret) { |
| 1811 | DEBUG_PRINT_ERROR("Failed to set conceal color %d\n", ret); |
| 1812 | } |
| 1813 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1814 | //Get the hardware capabilities |
| 1815 | memset((void *)&frmsize,0,sizeof(frmsize)); |
| 1816 | frmsize.index = 0; |
| 1817 | frmsize.pixel_format = output_capability; |
| 1818 | ret = ioctl(drv_ctx.video_driver_fd, |
| 1819 | VIDIOC_ENUM_FRAMESIZES, &frmsize); |
| 1820 | if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1821 | DEBUG_PRINT_ERROR("Failed to get framesizes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1822 | return OMX_ErrorHardware; |
| 1823 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1824 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1825 | if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) { |
| 1826 | m_decoder_capability.min_width = frmsize.stepwise.min_width; |
| 1827 | m_decoder_capability.max_width = frmsize.stepwise.max_width; |
| 1828 | m_decoder_capability.min_height = frmsize.stepwise.min_height; |
| 1829 | m_decoder_capability.max_height = frmsize.stepwise.max_height; |
| 1830 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1831 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1832 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1833 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1834 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1835 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 1836 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1837 | if (ret) { |
| 1838 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1839 | DEBUG_PRINT_ERROR("Failed to set format on capture port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1840 | } |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1841 | memset(&framesize, 0, sizeof(OMX_FRAMESIZETYPE)); |
| 1842 | framesize.nWidth = drv_ctx.video_resolution.frame_width; |
| 1843 | framesize.nHeight = drv_ctx.video_resolution.frame_height; |
| 1844 | |
| 1845 | memset(&rectangle, 0, sizeof(OMX_CONFIG_RECTTYPE)); |
| 1846 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1847 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
| 1848 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1849 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1850 | if (secure_mode) { |
| 1851 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE; |
| 1852 | control.value = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1853 | DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1854 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 1855 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1856 | DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1857 | return OMX_ErrorInsufficientResources; |
| 1858 | } |
| 1859 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1860 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1861 | /*Get the Buffer requirements for input and output ports*/ |
| 1862 | drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 1863 | drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 1864 | if (secure_mode) { |
| 1865 | drv_ctx.op_buf.alignment=SZ_1M; |
| 1866 | drv_ctx.ip_buf.alignment=SZ_1M; |
| 1867 | } else { |
| 1868 | drv_ctx.op_buf.alignment=SZ_4K; |
| 1869 | drv_ctx.ip_buf.alignment=SZ_4K; |
| 1870 | } |
| 1871 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 1872 | drv_ctx.extradata = 0; |
| 1873 | drv_ctx.picture_order = VDEC_ORDER_DISPLAY; |
| 1874 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 1875 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 1876 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 1877 | drv_ctx.idr_only_decoding = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1878 | |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1879 | m_state = OMX_StateLoaded; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1880 | #ifdef DEFAULT_EXTRADATA |
Arun Menon | f8908a6 | 2013-12-20 17:36:21 -0800 | [diff] [blame] | 1881 | if (strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", |
| 1882 | OMX_MAX_STRINGNAME_SIZE) && (eRet == OMX_ErrorNone)) |
| 1883 | enable_extradata(DEFAULT_EXTRADATA, true, true); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1884 | #endif |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1885 | eRet=get_buffer_req(&drv_ctx.ip_buf); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1886 | 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] | 1887 | get_buffer_req(&drv_ctx.op_buf); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1888 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
| 1889 | if (m_frame_parser.mutils == NULL) { |
| 1890 | m_frame_parser.mutils = new H264_Utils(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1891 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1892 | if (m_frame_parser.mutils == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1893 | DEBUG_PRINT_ERROR("parser utils Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1894 | eRet = OMX_ErrorInsufficientResources; |
| 1895 | } else { |
| 1896 | h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 1897 | h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size); |
| 1898 | h264_scratch.nFilledLen = 0; |
| 1899 | h264_scratch.nOffset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1900 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1901 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1902 | DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1903 | return OMX_ErrorInsufficientResources; |
| 1904 | } |
| 1905 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 1906 | m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size); |
| 1907 | } |
| 1908 | } |
Shalaj 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 | h264_parser = new h264_stream_parser(); |
| 1911 | if (!h264_parser) { |
| 1912 | DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!"); |
| 1913 | eRet = OMX_ErrorInsufficientResources; |
| 1914 | } |
| 1915 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1916 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1917 | if (pipe(fds)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1918 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1919 | eRet = OMX_ErrorInsufficientResources; |
| 1920 | } else { |
| 1921 | int temp1[2]; |
| 1922 | if (fds[0] == 0 || fds[1] == 0) { |
| 1923 | if (pipe (temp1)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1924 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1925 | return OMX_ErrorInsufficientResources; |
| 1926 | } |
| 1927 | //close (fds[0]); |
| 1928 | //close (fds[1]); |
| 1929 | fds[0] = temp1 [0]; |
| 1930 | fds[1] = temp1 [1]; |
| 1931 | } |
| 1932 | m_pipe_in = fds[0]; |
| 1933 | m_pipe_out = fds[1]; |
| 1934 | msg_thread_created = true; |
| 1935 | r = pthread_create(&msg_thread_id,0,message_thread,this); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1936 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1937 | if (r < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1938 | DEBUG_PRINT_ERROR("component_init(): message_thread creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1939 | msg_thread_created = false; |
| 1940 | eRet = OMX_ErrorInsufficientResources; |
| 1941 | } |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | if (eRet != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1946 | DEBUG_PRINT_ERROR("Component Init Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1947 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1948 | DEBUG_PRINT_HIGH("omx_vdec::component_init() success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1949 | } |
| 1950 | //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer)); |
Praveen Chavan | 898df26 | 2015-04-20 18:52:19 -0700 | [diff] [blame] | 1951 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY; |
| 1952 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE; |
| 1953 | |
| 1954 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 1955 | DEBUG_PRINT_ERROR("Failed to set Default Priority"); |
| 1956 | eRet = OMX_ErrorUnsupportedSetting; |
| 1957 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1958 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1962 | FUNCTION |
| 1963 | omx_vdec::GetComponentVersion |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1964 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1965 | DESCRIPTION |
| 1966 | Returns the component version. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1967 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1968 | PARAMETERS |
| 1969 | TBD. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1970 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1971 | RETURN VALUE |
| 1972 | OMX_ErrorNone. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1973 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1974 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1975 | OMX_ERRORTYPE omx_vdec::get_component_version |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1976 | ( |
| 1977 | OMX_IN OMX_HANDLETYPE hComp, |
| 1978 | OMX_OUT OMX_STRING componentName, |
| 1979 | OMX_OUT OMX_VERSIONTYPE* componentVersion, |
| 1980 | OMX_OUT OMX_VERSIONTYPE* specVersion, |
| 1981 | OMX_OUT OMX_UUIDTYPE* componentUUID |
| 1982 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1983 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1984 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1985 | DEBUG_PRINT_ERROR("Get Comp Version in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1986 | return OMX_ErrorInvalidState; |
| 1987 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1988 | /* TBD -- Return the proper version */ |
| 1989 | if (specVersion) { |
| 1990 | specVersion->nVersion = OMX_SPEC_VERSION; |
| 1991 | } |
| 1992 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1993 | } |
| 1994 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1995 | FUNCTION |
| 1996 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1997 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1998 | DESCRIPTION |
| 1999 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2000 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2001 | PARAMETERS |
| 2002 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2003 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2004 | RETURN VALUE |
| 2005 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2006 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2007 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2008 | OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2009 | OMX_IN OMX_COMMANDTYPE cmd, |
| 2010 | OMX_IN OMX_U32 param1, |
| 2011 | OMX_IN OMX_PTR cmdData |
| 2012 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2013 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2014 | DEBUG_PRINT_LOW("send_command: Recieved a Command from Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2015 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2016 | DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2017 | return OMX_ErrorInvalidState; |
| 2018 | } |
| 2019 | if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2020 | && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2021 | DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2022 | "to invalid port: %lu", param1); |
| 2023 | return OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2024 | } |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 2025 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2026 | post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND); |
| 2027 | sem_wait(&m_cmd_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2028 | DEBUG_PRINT_LOW("send_command: Command Processed"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2029 | return OMX_ErrorNone; |
| 2030 | } |
| 2031 | |
| 2032 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2033 | FUNCTION |
| 2034 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2035 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2036 | DESCRIPTION |
| 2037 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2038 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2039 | PARAMETERS |
| 2040 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2041 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2042 | RETURN VALUE |
| 2043 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2044 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2045 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2046 | OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2047 | OMX_IN OMX_COMMANDTYPE cmd, |
| 2048 | OMX_IN OMX_U32 param1, |
| 2049 | OMX_IN OMX_PTR cmdData |
| 2050 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2051 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2052 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2053 | OMX_STATETYPE eState = (OMX_STATETYPE) param1; |
| 2054 | int bFlag = 1,sem_posted = 0,ret=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2055 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2056 | DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd); |
| 2057 | DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2058 | m_state, eState); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2059 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2060 | if (cmd == OMX_CommandStateSet) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2061 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued"); |
| 2062 | DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2063 | /***************************/ |
| 2064 | /* Current State is Loaded */ |
| 2065 | /***************************/ |
| 2066 | if (m_state == OMX_StateLoaded) { |
| 2067 | if (eState == OMX_StateIdle) { |
| 2068 | //if all buffers are allocated or all ports disabled |
| 2069 | if (allocate_done() || |
| 2070 | (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2071 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2072 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2073 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2074 | BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING); |
| 2075 | // Skip the event notification |
| 2076 | bFlag = 0; |
| 2077 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2078 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2079 | /* Requesting transition from Loaded to Loaded */ |
| 2080 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2081 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2082 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2083 | OMX_COMPONENT_GENERATE_EVENT); |
| 2084 | eRet = OMX_ErrorSameState; |
| 2085 | } |
| 2086 | /* Requesting transition from Loaded to WaitForResources */ |
| 2087 | else if (eState == OMX_StateWaitForResources) { |
| 2088 | /* Since error is None , we will post an event |
| 2089 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2090 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2091 | } |
| 2092 | /* Requesting transition from Loaded to Executing */ |
| 2093 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2094 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2095 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2096 | OMX_COMPONENT_GENERATE_EVENT); |
| 2097 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2098 | } |
| 2099 | /* Requesting transition from Loaded to Pause */ |
| 2100 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2101 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2102 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2103 | OMX_COMPONENT_GENERATE_EVENT); |
| 2104 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2105 | } |
| 2106 | /* Requesting transition from Loaded to Invalid */ |
| 2107 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2108 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2109 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2110 | eRet = OMX_ErrorInvalidState; |
| 2111 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2112 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2113 | eState); |
| 2114 | eRet = OMX_ErrorBadParameter; |
| 2115 | } |
| 2116 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2117 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2118 | /***************************/ |
| 2119 | /* Current State is IDLE */ |
| 2120 | /***************************/ |
| 2121 | else if (m_state == OMX_StateIdle) { |
| 2122 | if (eState == OMX_StateLoaded) { |
| 2123 | if (release_done()) { |
| 2124 | /* |
| 2125 | Since error is None , we will post an event at the end |
| 2126 | of this function definition |
| 2127 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2128 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2129 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2130 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2131 | BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING); |
| 2132 | // Skip the event notification |
| 2133 | bFlag = 0; |
| 2134 | } |
| 2135 | } |
| 2136 | /* Requesting transition from Idle to Executing */ |
| 2137 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2138 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2139 | //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING); |
| 2140 | bFlag = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2141 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2142 | m_state=OMX_StateExecuting; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2143 | DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2144 | } |
| 2145 | /* Requesting transition from Idle to Idle */ |
| 2146 | else if (eState == OMX_StateIdle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2147 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2148 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2149 | OMX_COMPONENT_GENERATE_EVENT); |
| 2150 | eRet = OMX_ErrorSameState; |
| 2151 | } |
| 2152 | /* Requesting transition from Idle to WaitForResources */ |
| 2153 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2154 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2155 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2156 | OMX_COMPONENT_GENERATE_EVENT); |
| 2157 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2158 | } |
| 2159 | /* Requesting transition from Idle to Pause */ |
| 2160 | else if (eState == OMX_StatePause) { |
| 2161 | /*To pause the Video core we need to start the driver*/ |
| 2162 | if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START, |
| 2163 | NULL) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2164 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2165 | omx_report_error (); |
| 2166 | eRet = OMX_ErrorHardware; |
| 2167 | } else { |
| 2168 | BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2169 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2170 | bFlag = 0; |
| 2171 | } |
| 2172 | } |
| 2173 | /* Requesting transition from Idle to Invalid */ |
| 2174 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2175 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2176 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2177 | eRet = OMX_ErrorInvalidState; |
| 2178 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2179 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2180 | eRet = OMX_ErrorBadParameter; |
| 2181 | } |
| 2182 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2183 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2184 | /******************************/ |
| 2185 | /* Current State is Executing */ |
| 2186 | /******************************/ |
| 2187 | else if (m_state == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2188 | DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2189 | /* Requesting transition from Executing to Idle */ |
| 2190 | if (eState == OMX_StateIdle) { |
| 2191 | /* Since error is None , we will post an event |
| 2192 | at the end of this function definition |
| 2193 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2194 | DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2195 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2196 | if (!sem_posted) { |
| 2197 | sem_posted = 1; |
| 2198 | sem_post (&m_cmd_lock); |
| 2199 | execute_omx_flush(OMX_ALL); |
| 2200 | } |
| 2201 | bFlag = 0; |
| 2202 | } |
| 2203 | /* Requesting transition from Executing to Paused */ |
| 2204 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2205 | DEBUG_PRINT_LOW("PAUSE Command Issued"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2206 | m_state = OMX_StatePause; |
| 2207 | bFlag = 1; |
| 2208 | } |
| 2209 | /* Requesting transition from Executing to Loaded */ |
| 2210 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2211 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2212 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2213 | OMX_COMPONENT_GENERATE_EVENT); |
| 2214 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2215 | } |
| 2216 | /* Requesting transition from Executing to WaitForResources */ |
| 2217 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2218 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2219 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2220 | OMX_COMPONENT_GENERATE_EVENT); |
| 2221 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2222 | } |
| 2223 | /* Requesting transition from Executing to Executing */ |
| 2224 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2225 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2226 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2227 | OMX_COMPONENT_GENERATE_EVENT); |
| 2228 | eRet = OMX_ErrorSameState; |
| 2229 | } |
| 2230 | /* Requesting transition from Executing to Invalid */ |
| 2231 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2232 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2233 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2234 | eRet = OMX_ErrorInvalidState; |
| 2235 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2236 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2237 | eRet = OMX_ErrorBadParameter; |
| 2238 | } |
| 2239 | } |
| 2240 | /***************************/ |
| 2241 | /* Current State is Pause */ |
| 2242 | /***************************/ |
| 2243 | else if (m_state == OMX_StatePause) { |
| 2244 | /* Requesting transition from Pause to Executing */ |
| 2245 | if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2246 | DEBUG_PRINT_LOW("Pause --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2247 | m_state = OMX_StateExecuting; |
| 2248 | bFlag = 1; |
| 2249 | } |
| 2250 | /* Requesting transition from Pause to Idle */ |
| 2251 | else if (eState == OMX_StateIdle) { |
| 2252 | /* Since error is None , we will post an event |
| 2253 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2254 | DEBUG_PRINT_LOW("Pause --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2255 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2256 | if (!sem_posted) { |
| 2257 | sem_posted = 1; |
| 2258 | sem_post (&m_cmd_lock); |
| 2259 | execute_omx_flush(OMX_ALL); |
| 2260 | } |
| 2261 | bFlag = 0; |
| 2262 | } |
| 2263 | /* Requesting transition from Pause to loaded */ |
| 2264 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2265 | DEBUG_PRINT_ERROR("Pause --> loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2266 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2267 | OMX_COMPONENT_GENERATE_EVENT); |
| 2268 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2269 | } |
| 2270 | /* Requesting transition from Pause to WaitForResources */ |
| 2271 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2272 | DEBUG_PRINT_ERROR("Pause --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2273 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2274 | OMX_COMPONENT_GENERATE_EVENT); |
| 2275 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2276 | } |
| 2277 | /* Requesting transition from Pause to Pause */ |
| 2278 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2279 | DEBUG_PRINT_ERROR("Pause --> Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2280 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2281 | OMX_COMPONENT_GENERATE_EVENT); |
| 2282 | eRet = OMX_ErrorSameState; |
| 2283 | } |
| 2284 | /* Requesting transition from Pause to Invalid */ |
| 2285 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2286 | DEBUG_PRINT_ERROR("Pause --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2287 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2288 | eRet = OMX_ErrorInvalidState; |
| 2289 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2290 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2291 | eRet = OMX_ErrorBadParameter; |
| 2292 | } |
| 2293 | } |
| 2294 | /***************************/ |
| 2295 | /* Current State is WaitForResources */ |
| 2296 | /***************************/ |
| 2297 | else if (m_state == OMX_StateWaitForResources) { |
| 2298 | /* Requesting transition from WaitForResources to Loaded */ |
| 2299 | if (eState == OMX_StateLoaded) { |
| 2300 | /* Since error is None , we will post an event |
| 2301 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2302 | DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2303 | } |
| 2304 | /* Requesting transition from WaitForResources to WaitForResources */ |
| 2305 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2306 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2307 | post_event(OMX_EventError,OMX_ErrorSameState, |
| 2308 | OMX_COMPONENT_GENERATE_EVENT); |
| 2309 | eRet = OMX_ErrorSameState; |
| 2310 | } |
| 2311 | /* Requesting transition from WaitForResources to Executing */ |
| 2312 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2313 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2314 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2315 | OMX_COMPONENT_GENERATE_EVENT); |
| 2316 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2317 | } |
| 2318 | /* Requesting transition from WaitForResources to Pause */ |
| 2319 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2320 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2321 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2322 | OMX_COMPONENT_GENERATE_EVENT); |
| 2323 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2324 | } |
| 2325 | /* Requesting transition from WaitForResources to Invalid */ |
| 2326 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2327 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2328 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2329 | eRet = OMX_ErrorInvalidState; |
| 2330 | } |
| 2331 | /* Requesting transition from WaitForResources to Loaded - |
| 2332 | is NOT tested by Khronos TS */ |
| 2333 | |
| 2334 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2335 | 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] | 2336 | eRet = OMX_ErrorBadParameter; |
| 2337 | } |
| 2338 | } |
| 2339 | /********************************/ |
| 2340 | /* Current State is Invalid */ |
| 2341 | /*******************************/ |
| 2342 | else if (m_state == OMX_StateInvalid) { |
| 2343 | /* State Transition from Inavlid to any state */ |
| 2344 | if (eState == (OMX_StateLoaded || OMX_StateWaitForResources |
| 2345 | || OMX_StateIdle || OMX_StateExecuting |
| 2346 | || OMX_StatePause || OMX_StateInvalid)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2347 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2348 | post_event(OMX_EventError,OMX_ErrorInvalidState,\ |
| 2349 | OMX_COMPONENT_GENERATE_EVENT); |
| 2350 | eRet = OMX_ErrorInvalidState; |
| 2351 | } |
| 2352 | } else if (cmd == OMX_CommandFlush) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2353 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2354 | "with param1: %lu", param1); |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2355 | #ifdef _MSM8974_ |
| 2356 | send_codec_config(); |
| 2357 | #endif |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2358 | if (cmd == OMX_CommandFlush && (param1 == OMX_CORE_INPUT_PORT_INDEX || |
| 2359 | param1 == OMX_ALL)) { |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2360 | if (android_atomic_add(0, &m_queued_codec_config_count) > 0) { |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2361 | struct timespec ts; |
| 2362 | |
| 2363 | clock_gettime(CLOCK_REALTIME, &ts); |
| 2364 | ts.tv_sec += 2; |
| 2365 | DEBUG_PRINT_LOW("waiting for %d EBDs of CODEC CONFIG buffers ", |
| 2366 | m_queued_codec_config_count); |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2367 | BITMASK_SET(&m_flags, OMX_COMPONENT_FLUSH_DEFERRED); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2368 | if (sem_timedwait(&m_safe_flush, &ts)) { |
| 2369 | DEBUG_PRINT_ERROR("Failed to wait for EBDs of CODEC CONFIG buffers"); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2370 | } |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2371 | BITMASK_CLEAR (&m_flags,OMX_COMPONENT_FLUSH_DEFERRED); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2375 | if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2376 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING); |
| 2377 | } |
| 2378 | if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2379 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 2380 | } |
| 2381 | if (!sem_posted) { |
| 2382 | sem_posted = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2383 | DEBUG_PRINT_LOW("Set the Semaphore"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2384 | sem_post (&m_cmd_lock); |
| 2385 | execute_omx_flush(param1); |
| 2386 | } |
| 2387 | bFlag = 0; |
| 2388 | } else if ( cmd == OMX_CommandPortEnable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2389 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2390 | "with param1: %lu", param1); |
| 2391 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2392 | m_inp_bEnabled = OMX_TRUE; |
| 2393 | |
| 2394 | if ( (m_state == OMX_StateLoaded && |
| 2395 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2396 | || allocate_input_done()) { |
| 2397 | post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX, |
| 2398 | OMX_COMPONENT_GENERATE_EVENT); |
| 2399 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2400 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2401 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 2402 | // Skip the event notification |
| 2403 | bFlag = 0; |
| 2404 | } |
| 2405 | } |
| 2406 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2407 | DEBUG_PRINT_LOW("Enable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2408 | m_out_bEnabled = OMX_TRUE; |
| 2409 | |
| 2410 | if ( (m_state == OMX_StateLoaded && |
| 2411 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2412 | || (allocate_output_done())) { |
| 2413 | post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX, |
| 2414 | OMX_COMPONENT_GENERATE_EVENT); |
| 2415 | |
| 2416 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2417 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2418 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 2419 | // Skip the event notification |
| 2420 | bFlag = 0; |
| 2421 | } |
| 2422 | } |
| 2423 | } else if (cmd == OMX_CommandPortDisable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2424 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2425 | "with param1: %lu", param1); |
| 2426 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2427 | codec_config_flag = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2428 | m_inp_bEnabled = OMX_FALSE; |
| 2429 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2430 | && release_input_done()) { |
| 2431 | post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX, |
| 2432 | OMX_COMPONENT_GENERATE_EVENT); |
| 2433 | } else { |
| 2434 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 2435 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2436 | if (!sem_posted) { |
| 2437 | sem_posted = 1; |
| 2438 | sem_post (&m_cmd_lock); |
| 2439 | } |
| 2440 | execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX); |
| 2441 | } |
| 2442 | |
| 2443 | // Skip the event notification |
| 2444 | bFlag = 0; |
| 2445 | } |
| 2446 | } |
| 2447 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2448 | m_out_bEnabled = OMX_FALSE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2449 | DEBUG_PRINT_LOW("Disable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2450 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2451 | && release_output_done()) { |
| 2452 | post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\ |
| 2453 | OMX_COMPONENT_GENERATE_EVENT); |
| 2454 | } else { |
| 2455 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
| 2456 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2457 | if (!sem_posted) { |
| 2458 | sem_posted = 1; |
| 2459 | sem_post (&m_cmd_lock); |
| 2460 | } |
| 2461 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 2462 | execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX); |
| 2463 | } |
| 2464 | // Skip the event notification |
| 2465 | bFlag = 0; |
| 2466 | |
| 2467 | } |
| 2468 | } |
| 2469 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2470 | DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2471 | eRet = OMX_ErrorNotImplemented; |
| 2472 | } |
| 2473 | if (eRet == OMX_ErrorNone && bFlag) { |
| 2474 | post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2475 | } |
| 2476 | if (!sem_posted) { |
| 2477 | sem_post(&m_cmd_lock); |
| 2478 | } |
| 2479 | |
| 2480 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2484 | FUNCTION |
| 2485 | omx_vdec::ExecuteOmxFlush |
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 | DESCRIPTION |
| 2488 | Executes the OMX flush. |
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 | PARAMETERS |
| 2491 | flushtype - input flush(1)/output flush(0)/ both. |
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 | RETURN VALUE |
| 2494 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2495 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2496 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2497 | bool omx_vdec::execute_omx_flush(OMX_U32 flushType) |
| 2498 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2499 | bool bRet = false; |
| 2500 | struct v4l2_plane plane; |
| 2501 | struct v4l2_buffer v4l2_buf; |
| 2502 | struct v4l2_decoder_cmd dec; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 2503 | DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2504 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 2505 | dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH; |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2506 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2507 | DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig); |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2508 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2509 | if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 2510 | output_flush_progress = true; |
| 2511 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2512 | } else { |
| 2513 | /* XXX: The driver/hardware does not support flushing of individual ports |
| 2514 | * in all states. So we pretty much need to flush both ports internally, |
| 2515 | * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it |
| 2516 | * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set, |
| 2517 | * we automatically omit sending the FLUSH done for the "opposite" port. */ |
| 2518 | input_flush_progress = true; |
| 2519 | output_flush_progress = true; |
| 2520 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2521 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2522 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2523 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2524 | DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2525 | bRet = false; |
| 2526 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2527 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2528 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2529 | } |
| 2530 | /*========================================================================= |
| 2531 | FUNCTION : execute_output_flush |
| 2532 | |
| 2533 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2534 | Executes the OMX flush at OUTPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2535 | |
| 2536 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2537 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2538 | |
| 2539 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2540 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2541 | ==========================================================================*/ |
| 2542 | bool omx_vdec::execute_output_flush() |
| 2543 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2544 | unsigned p1 = 0; // Parameter - 1 |
| 2545 | unsigned p2 = 0; // Parameter - 2 |
| 2546 | unsigned ident = 0; |
| 2547 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2548 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2549 | /*Generate FBD for all Buffers in the FTBq*/ |
| 2550 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2551 | DEBUG_PRINT_LOW("Initiate Output Flush"); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 2552 | |
| 2553 | //reset last render TS |
| 2554 | if(m_last_rendered_TS > 0) { |
| 2555 | m_last_rendered_TS = 0; |
| 2556 | } |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 2557 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2558 | while (m_ftb_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2559 | DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2560 | m_ftb_q.m_size,pending_output_buffers); |
| 2561 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2562 | DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2563 | if (ident == m_fill_output_msg ) { |
| 2564 | m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2565 | } else if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 2566 | fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2567 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2568 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2569 | pthread_mutex_unlock(&m_lock); |
| 2570 | output_flush_progress = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2571 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2572 | if (arbitrary_bytes) { |
| 2573 | prev_ts = LLONG_MAX; |
| 2574 | rst_prev_ts = true; |
| 2575 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2576 | 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] | 2577 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2578 | } |
| 2579 | /*========================================================================= |
| 2580 | FUNCTION : execute_input_flush |
| 2581 | |
| 2582 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2583 | Executes the OMX flush at INPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2584 | |
| 2585 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2586 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2587 | |
| 2588 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2589 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2590 | ==========================================================================*/ |
| 2591 | bool omx_vdec::execute_input_flush() |
| 2592 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2593 | unsigned i =0; |
| 2594 | unsigned p1 = 0; // Parameter - 1 |
| 2595 | unsigned p2 = 0; // Parameter - 2 |
| 2596 | unsigned ident = 0; |
| 2597 | bool bRet = true; |
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 | /*Generate EBD for all Buffers in the ETBq*/ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2600 | DEBUG_PRINT_LOW("Initiate Input Flush"); |
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 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2603 | DEBUG_PRINT_LOW("Check if the Queue is empty"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2604 | while (m_etb_q.m_size) { |
| 2605 | m_etb_q.pop_entry(&p1,&p2,&ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2606 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2607 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2608 | DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2609 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2610 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 2611 | pending_input_buffers++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2612 | 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] | 2613 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 2614 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 2615 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2616 | DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2617 | (OMX_BUFFERHEADERTYPE *)p1); |
| 2618 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2619 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2620 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2621 | time_stamp_dts.flush_timestamp(); |
| 2622 | /*Check if Heap Buffers are to be flushed*/ |
| 2623 | if (arbitrary_bytes && !(codec_config_flag)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2624 | DEBUG_PRINT_LOW("Reset all the variables before flusing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2625 | h264_scratch.nFilledLen = 0; |
| 2626 | nal_count = 0; |
| 2627 | look_ahead_nal = false; |
| 2628 | frame_count = 0; |
| 2629 | h264_last_au_ts = LLONG_MAX; |
| 2630 | h264_last_au_flags = 0; |
| 2631 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 2632 | m_demux_entries = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2633 | DEBUG_PRINT_LOW("Initialize parser"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2634 | if (m_frame_parser.mutils) { |
| 2635 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 2636 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2637 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2638 | while (m_input_pending_q.m_size) { |
| 2639 | m_input_pending_q.pop_entry(&p1,&p2,&ident); |
| 2640 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1); |
| 2641 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2642 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2643 | if (psource_frame) { |
| 2644 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame); |
| 2645 | psource_frame = NULL; |
| 2646 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2647 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2648 | if (pdest_frame) { |
| 2649 | pdest_frame->nFilledLen = 0; |
| 2650 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL, |
| 2651 | (unsigned int)NULL); |
| 2652 | pdest_frame = NULL; |
| 2653 | } |
| 2654 | m_frame_parser.flush(); |
| 2655 | } else if (codec_config_flag) { |
| 2656 | DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer " |
| 2657 | "is not sent to the driver yet"); |
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 | pthread_mutex_unlock(&m_lock); |
| 2660 | input_flush_progress = false; |
| 2661 | if (!arbitrary_bytes) { |
| 2662 | prev_ts = LLONG_MAX; |
| 2663 | rst_prev_ts = true; |
| 2664 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2665 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2666 | if (m_debug_timestamp) { |
| 2667 | m_timestamp_list.reset_ts_list(); |
| 2668 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2669 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2670 | 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] | 2671 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | |
| 2675 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2676 | FUNCTION |
| 2677 | omx_vdec::SendCommandEvent |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2678 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2679 | DESCRIPTION |
| 2680 | Send the event to decoder pipe. This is needed to generate the callbacks |
| 2681 | in decoder thread context. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2682 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2683 | PARAMETERS |
| 2684 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2685 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2686 | RETURN VALUE |
| 2687 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2688 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2689 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2690 | bool omx_vdec::post_event(unsigned int p1, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2691 | unsigned int p2, |
| 2692 | unsigned int id) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2693 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2694 | bool bRet = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2695 | |
| 2696 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2697 | pthread_mutex_lock(&m_lock); |
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 | if (id == m_fill_output_msg || |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 2700 | id == OMX_COMPONENT_GENERATE_FBD || |
| 2701 | id == OMX_COMPONENT_GENERATE_PORT_RECONFIG) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2702 | m_ftb_q.insert_entry(p1,p2,id); |
| 2703 | } else if (id == OMX_COMPONENT_GENERATE_ETB || |
| 2704 | id == OMX_COMPONENT_GENERATE_EBD || |
| 2705 | id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 2706 | m_etb_q.insert_entry(p1,p2,id); |
| 2707 | } else { |
| 2708 | m_cmd_q.insert_entry(p1,p2,id); |
| 2709 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2710 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2711 | bRet = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2712 | DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2713 | post_message(this, id); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2714 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2715 | pthread_mutex_unlock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2716 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2717 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType) |
| 2721 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2722 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2723 | if (!profileLevelType) |
| 2724 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2725 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2726 | if (profileLevelType->nPortIndex == 0) { |
| 2727 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 2728 | if (profileLevelType->nProfileIndex == 0) { |
| 2729 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline; |
| 2730 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2731 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2732 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2733 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain; |
| 2734 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2735 | } else if (profileLevelType->nProfileIndex == 2) { |
| 2736 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh; |
| 2737 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2738 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2739 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2740 | profileLevelType->nProfileIndex); |
| 2741 | eRet = OMX_ErrorNoMore; |
| 2742 | } |
| 2743 | } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) { |
| 2744 | if (profileLevelType->nProfileIndex == 0) { |
| 2745 | profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline; |
| 2746 | profileLevelType->eLevel = OMX_VIDEO_H263Level70; |
| 2747 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2748 | 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] | 2749 | eRet = OMX_ErrorNoMore; |
| 2750 | } |
| 2751 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 2752 | if (profileLevelType->nProfileIndex == 0) { |
| 2753 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple; |
| 2754 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2755 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2756 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple; |
| 2757 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2758 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2759 | 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] | 2760 | eRet = OMX_ErrorNoMore; |
| 2761 | } |
| 2762 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 2763 | eRet = OMX_ErrorNoMore; |
| 2764 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 2765 | if (profileLevelType->nProfileIndex == 0) { |
| 2766 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple; |
| 2767 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2768 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2769 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain; |
| 2770 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2771 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2772 | 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] | 2773 | eRet = OMX_ErrorNoMore; |
| 2774 | } |
| 2775 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2776 | 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] | 2777 | eRet = OMX_ErrorNoMore; |
| 2778 | } |
| 2779 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2780 | 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] | 2781 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2782 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2783 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2787 | FUNCTION |
| 2788 | omx_vdec::GetParameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2789 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2790 | DESCRIPTION |
| 2791 | OMX Get Parameter method implementation |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2792 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2793 | PARAMETERS |
| 2794 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2795 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2796 | RETURN VALUE |
| 2797 | Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2798 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2799 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2800 | OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2801 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 2802 | OMX_INOUT OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2803 | { |
| 2804 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2805 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2806 | DEBUG_PRINT_LOW("get_parameter:"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2807 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2808 | DEBUG_PRINT_ERROR("Get Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2809 | return OMX_ErrorInvalidState; |
| 2810 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2811 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2812 | DEBUG_PRINT_LOW("Get Param in Invalid paramData"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2813 | return OMX_ErrorBadParameter; |
| 2814 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2815 | switch ((unsigned long)paramIndex) { |
| 2816 | case OMX_IndexParamPortDefinition: { |
| 2817 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = |
| 2818 | (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2819 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2820 | eRet = update_portdef(portDefn); |
| 2821 | if (eRet == OMX_ErrorNone) |
| 2822 | m_port_def = *portDefn; |
| 2823 | break; |
| 2824 | } |
| 2825 | case OMX_IndexParamVideoInit: { |
| 2826 | OMX_PORT_PARAM_TYPE *portParamType = |
| 2827 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2828 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2829 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2830 | portParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2831 | portParamType->nSize = sizeof(portParamType); |
| 2832 | portParamType->nPorts = 2; |
| 2833 | portParamType->nStartPortNumber = 0; |
| 2834 | break; |
| 2835 | } |
| 2836 | case OMX_IndexParamVideoPortFormat: { |
| 2837 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 2838 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2839 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2840 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2841 | portFmt->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2842 | portFmt->nSize = sizeof(portFmt); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2843 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2844 | if (0 == portFmt->nPortIndex) { |
| 2845 | if (0 == portFmt->nIndex) { |
| 2846 | portFmt->eColorFormat = OMX_COLOR_FormatUnused; |
| 2847 | portFmt->eCompressionFormat = eCompressionFormat; |
| 2848 | } else { |
| 2849 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2850 | " NoMore compression formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2851 | eRet = OMX_ErrorNoMore; |
| 2852 | } |
| 2853 | } else if (1 == portFmt->nPortIndex) { |
| 2854 | portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2855 | |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2856 | // Distinguish non-surface mode from normal playback use-case based on |
| 2857 | // usage hinted via "OMX.google.android.index.useAndroidNativeBuffer2" |
| 2858 | // For non-android, use the default list |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 2859 | // Also use default format-list if FLEXIBLE YUV is supported, |
| 2860 | // as the client negotiates the standard color-format if it needs to |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2861 | bool useNonSurfaceMode = false; |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 2862 | #if defined(_ANDROID_) && !defined(FLEXYUV_SUPPORTED) |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2863 | useNonSurfaceMode = (m_enable_android_native_buffers == OMX_FALSE); |
| 2864 | #endif |
| 2865 | portFmt->eColorFormat = useNonSurfaceMode ? |
| 2866 | getPreferredColorFormatNonSurfaceMode(portFmt->nIndex) : |
| 2867 | getPreferredColorFormatDefaultMode(portFmt->nIndex); |
| 2868 | |
| 2869 | if (portFmt->eColorFormat == OMX_COLOR_FormatMax ) { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2870 | eRet = OMX_ErrorNoMore; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2871 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2872 | " NoMore Color formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2873 | } |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2874 | DEBUG_PRINT_HIGH("returning color-format: 0x%x", portFmt->eColorFormat); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2875 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2876 | DEBUG_PRINT_ERROR("get_parameter: Bad port index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2877 | (int)portFmt->nPortIndex); |
| 2878 | eRet = OMX_ErrorBadPortIndex; |
| 2879 | } |
| 2880 | break; |
| 2881 | } |
| 2882 | /*Component should support this port definition*/ |
| 2883 | case OMX_IndexParamAudioInit: { |
| 2884 | OMX_PORT_PARAM_TYPE *audioPortParamType = |
| 2885 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2886 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2887 | audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2888 | audioPortParamType->nSize = sizeof(audioPortParamType); |
| 2889 | audioPortParamType->nPorts = 0; |
| 2890 | audioPortParamType->nStartPortNumber = 0; |
| 2891 | break; |
| 2892 | } |
| 2893 | /*Component should support this port definition*/ |
| 2894 | case OMX_IndexParamImageInit: { |
| 2895 | OMX_PORT_PARAM_TYPE *imagePortParamType = |
| 2896 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2897 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2898 | imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2899 | imagePortParamType->nSize = sizeof(imagePortParamType); |
| 2900 | imagePortParamType->nPorts = 0; |
| 2901 | imagePortParamType->nStartPortNumber = 0; |
| 2902 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2903 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2904 | } |
| 2905 | /*Component should support this port definition*/ |
| 2906 | case OMX_IndexParamOtherInit: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2907 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2908 | paramIndex); |
| 2909 | eRet =OMX_ErrorUnsupportedIndex; |
| 2910 | break; |
| 2911 | } |
| 2912 | case OMX_IndexParamStandardComponentRole: { |
| 2913 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 2914 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
| 2915 | comp_role->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2916 | comp_role->nSize = sizeof(*comp_role); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2917 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2918 | DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2919 | paramIndex); |
| 2920 | strlcpy((char*)comp_role->cRole,(const char*)m_cRole, |
| 2921 | OMX_MAX_STRINGNAME_SIZE); |
| 2922 | break; |
| 2923 | } |
| 2924 | /* Added for parameter test */ |
| 2925 | case OMX_IndexParamPriorityMgmt: { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2926 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2927 | OMX_PRIORITYMGMTTYPE *priorityMgmType = |
| 2928 | (OMX_PRIORITYMGMTTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2929 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2930 | priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2931 | priorityMgmType->nSize = sizeof(priorityMgmType); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2932 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2933 | break; |
| 2934 | } |
| 2935 | /* Added for parameter test */ |
| 2936 | case OMX_IndexParamCompBufferSupplier: { |
| 2937 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = |
| 2938 | (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2939 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2940 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2941 | bufferSupplierType->nSize = sizeof(bufferSupplierType); |
| 2942 | bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2943 | if (0 == bufferSupplierType->nPortIndex) |
| 2944 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2945 | else if (1 == bufferSupplierType->nPortIndex) |
| 2946 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2947 | else |
| 2948 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2949 | |
| 2950 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2951 | break; |
| 2952 | } |
| 2953 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2954 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2955 | paramIndex); |
| 2956 | break; |
| 2957 | } |
| 2958 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2959 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2960 | paramIndex); |
| 2961 | break; |
| 2962 | } |
| 2963 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2964 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2965 | paramIndex); |
| 2966 | break; |
| 2967 | } |
| 2968 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2969 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2970 | paramIndex); |
| 2971 | break; |
| 2972 | } |
| 2973 | case OMX_IndexParamVideoProfileLevelQuerySupported: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2974 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2975 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType = |
| 2976 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData; |
| 2977 | eRet = get_supported_profile_level_for_1080p(profileLevelType); |
| 2978 | break; |
| 2979 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2980 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2981 | case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2982 | DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2983 | GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData; |
| 2984 | if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2985 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2986 | if (secure_mode) { |
| 2987 | nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED | |
| 2988 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2989 | } else { |
| 2990 | nativeBuffersUsage->nUsage = |
| 2991 | (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | |
| 2992 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2993 | } |
| 2994 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2995 | DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2996 | eRet = OMX_ErrorBadParameter; |
| 2997 | } |
| 2998 | } |
| 2999 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3000 | #endif |
| 3001 | |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 3002 | #ifdef FLEXYUV_SUPPORTED |
| 3003 | case OMX_QcomIndexFlexibleYUVDescription: { |
| 3004 | DEBUG_PRINT_LOW("get_parameter: describeColorFormat"); |
| 3005 | eRet = describeColorFormat(paramData); |
| 3006 | break; |
| 3007 | } |
| 3008 | #endif |
| 3009 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3010 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3011 | DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3012 | eRet =OMX_ErrorUnsupportedIndex; |
| 3013 | } |
| 3014 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3017 | 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] | 3018 | drv_ctx.video_resolution.frame_width, |
| 3019 | drv_ctx.video_resolution.frame_height, |
| 3020 | drv_ctx.video_resolution.stride, |
| 3021 | drv_ctx.video_resolution.scan_lines); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3022 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3023 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
| 3027 | OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data) |
| 3028 | { |
| 3029 | DEBUG_PRINT_LOW("Inside use_android_native_buffer"); |
| 3030 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 3031 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data; |
| 3032 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3033 | if ((params == NULL) || |
| 3034 | (params->nativeBuffer == NULL) || |
| 3035 | (params->nativeBuffer->handle == NULL) || |
| 3036 | !m_enable_android_native_buffers) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3037 | return OMX_ErrorBadParameter; |
| 3038 | m_use_android_native_buffers = OMX_TRUE; |
| 3039 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 3040 | private_handle_t *handle = (private_handle_t *)nBuf->handle; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3041 | 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] | 3042 | OMX_U8 *buffer = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3043 | if (!secure_mode) { |
| 3044 | buffer = (OMX_U8*)mmap(0, handle->size, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3045 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3046 | if (buffer == MAP_FAILED) { |
| 3047 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 3048 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer); |
| 3052 | } else { |
| 3053 | eRet = OMX_ErrorBadParameter; |
| 3054 | } |
| 3055 | return eRet; |
| 3056 | } |
| 3057 | #endif |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3058 | |
| 3059 | OMX_ERRORTYPE omx_vdec::enable_smoothstreaming() { |
| 3060 | struct v4l2_control control; |
| 3061 | struct v4l2_format fmt; |
| 3062 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER; |
| 3063 | control.value = 1; |
| 3064 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3065 | if (rc < 0) { |
| 3066 | DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver."); |
| 3067 | return OMX_ErrorHardware; |
| 3068 | } |
| 3069 | m_smoothstreaming_mode = true; |
| 3070 | return OMX_ErrorNone; |
| 3071 | } |
| 3072 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3073 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3074 | FUNCTION |
| 3075 | omx_vdec::Setparameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3076 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3077 | DESCRIPTION |
| 3078 | OMX Set Parameter method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3079 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3080 | PARAMETERS |
| 3081 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3082 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3083 | RETURN VALUE |
| 3084 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3085 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3086 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3087 | OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3088 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 3089 | OMX_IN OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3090 | { |
| 3091 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Praneeth Paladugu | 226667c | 2012-09-12 16:42:30 -0700 | [diff] [blame] | 3092 | int ret=0; |
| 3093 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3094 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3095 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3096 | return OMX_ErrorInvalidState; |
| 3097 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3098 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3099 | DEBUG_PRINT_ERROR("Get Param in Invalid paramData"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3100 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3101 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3102 | if ((m_state != OMX_StateLoaded) && |
| 3103 | BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) && |
| 3104 | (m_out_bEnabled == OMX_TRUE) && |
| 3105 | BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) && |
| 3106 | (m_inp_bEnabled == OMX_TRUE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3107 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3108 | return OMX_ErrorIncorrectStateOperation; |
| 3109 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3110 | switch ((unsigned long)paramIndex) { |
| 3111 | case OMX_IndexParamPortDefinition: { |
| 3112 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn; |
| 3113 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
| 3114 | //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has |
| 3115 | //been called. |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3116 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3117 | (int)portDefn->format.video.nFrameHeight, |
| 3118 | (int)portDefn->format.video.nFrameWidth); |
| 3119 | if (OMX_DirOutput == portDefn->eDir) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3120 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port"); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3121 | bool port_format_changed = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3122 | m_display_id = portDefn->format.video.pNativeWindow; |
| 3123 | unsigned int buffer_size; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3124 | /* update output port resolution with client supplied dimensions |
| 3125 | in case scaling is enabled, else it follows input resolution set |
| 3126 | */ |
| 3127 | if (is_down_scalar_enabled) { |
| 3128 | DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n", |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3129 | portDefn->format.video.nFrameWidth, |
| 3130 | portDefn->format.video.nFrameHeight); |
| 3131 | if (portDefn->format.video.nFrameHeight != 0x0 && |
| 3132 | portDefn->format.video.nFrameWidth != 0x0) { |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3133 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
| 3134 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3135 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3136 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 3137 | if (ret) { |
| 3138 | DEBUG_PRINT_ERROR("Get Resolution failed"); |
| 3139 | eRet = OMX_ErrorHardware; |
| 3140 | break; |
| 3141 | } |
| 3142 | if ((portDefn->format.video.nFrameHeight != (int)fmt.fmt.pix_mp.height) || |
| 3143 | (portDefn->format.video.nFrameWidth != (int)fmt.fmt.pix_mp.width)) { |
| 3144 | port_format_changed = true; |
| 3145 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3146 | update_resolution(portDefn->format.video.nFrameWidth, |
| 3147 | portDefn->format.video.nFrameHeight, |
| 3148 | portDefn->format.video.nFrameWidth, |
| 3149 | portDefn->format.video.nFrameHeight); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3150 | |
| 3151 | /* set crop info */ |
| 3152 | rectangle.nLeft = 0; |
| 3153 | rectangle.nTop = 0; |
| 3154 | rectangle.nWidth = portDefn->format.video.nFrameWidth; |
| 3155 | rectangle.nHeight = portDefn->format.video.nFrameHeight; |
| 3156 | |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3157 | eRet = is_video_session_supported(); |
| 3158 | if (eRet) |
| 3159 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3160 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3161 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3162 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3163 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3164 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3165 | 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); |
| 3166 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3167 | if (ret) { |
| 3168 | DEBUG_PRINT_ERROR("\n Set Resolution failed"); |
| 3169 | eRet = OMX_ErrorUnsupportedSetting; |
| 3170 | } else |
| 3171 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3172 | } |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3173 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3174 | if (!client_buffers.get_buffer_req(buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3175 | DEBUG_PRINT_ERROR("Error in getting buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3176 | eRet = OMX_ErrorBadParameter; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3177 | } else if (!port_format_changed) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3178 | if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount && |
| 3179 | portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) { |
| 3180 | drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual; |
| 3181 | drv_ctx.op_buf.buffer_size = portDefn->nBufferSize; |
| 3182 | drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount; |
| 3183 | drv_ctx.extradata_info.size = drv_ctx.extradata_info.count * |
| 3184 | drv_ctx.extradata_info.buffer_size; |
| 3185 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 3186 | if (eRet == OMX_ErrorNone) |
| 3187 | m_port_def = *portDefn; |
| 3188 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3189 | DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3190 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size, |
| 3191 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3192 | eRet = OMX_ErrorBadParameter; |
| 3193 | } |
| 3194 | } |
| 3195 | } else if (OMX_DirInput == portDefn->eDir) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3196 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3197 | bool port_format_changed = false; |
| 3198 | if ((portDefn->format.video.xFramerate >> 16) > 0 && |
| 3199 | (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) { |
| 3200 | // Frame rate only should be set if this is a "known value" or to |
| 3201 | // activate ts prediction logic (arbitrary mode only) sending input |
| 3202 | // timestamps with max value (LLONG_MAX). |
| 3203 | DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu", |
| 3204 | portDefn->format.video.xFramerate >> 16); |
| 3205 | Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator, |
| 3206 | drv_ctx.frame_rate.fps_denominator); |
| 3207 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 3208 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 3209 | drv_ctx.frame_rate.fps_numerator = 30; |
| 3210 | } |
| 3211 | if (drv_ctx.frame_rate.fps_denominator) |
| 3212 | drv_ctx.frame_rate.fps_numerator = (int) |
| 3213 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 3214 | drv_ctx.frame_rate.fps_denominator = 1; |
| 3215 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 3216 | drv_ctx.frame_rate.fps_numerator; |
| 3217 | DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)", |
| 3218 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 3219 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3220 | |
| 3221 | struct v4l2_outputparm oparm; |
| 3222 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 3223 | * per second.*/ |
| 3224 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 3225 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 3226 | |
| 3227 | struct v4l2_streamparm sparm; |
| 3228 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3229 | sparm.parm.output = oparm; |
| 3230 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 3231 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, performance might be affected"); |
| 3232 | eRet = OMX_ErrorHardware; |
| 3233 | break; |
| 3234 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3235 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3236 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3237 | if (drv_ctx.video_resolution.frame_height != |
| 3238 | portDefn->format.video.nFrameHeight || |
| 3239 | drv_ctx.video_resolution.frame_width != |
| 3240 | portDefn->format.video.nFrameWidth) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3241 | DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3242 | portDefn->format.video.nFrameWidth, |
| 3243 | portDefn->format.video.nFrameHeight); |
| 3244 | port_format_changed = true; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3245 | OMX_U32 frameWidth = portDefn->format.video.nFrameWidth; |
| 3246 | OMX_U32 frameHeight = portDefn->format.video.nFrameHeight; |
| 3247 | if (frameHeight != 0x0 && frameWidth != 0x0) { |
| 3248 | if (m_smoothstreaming_mode && |
| 3249 | ((frameWidth * frameHeight) < |
| 3250 | (m_smoothstreaming_width * m_smoothstreaming_height))) { |
| 3251 | frameWidth = m_smoothstreaming_width; |
| 3252 | frameHeight = m_smoothstreaming_height; |
| 3253 | DEBUG_PRINT_LOW("NOTE: Setting resolution %lu x %lu for adaptive-playback/smooth-streaming", |
| 3254 | frameWidth, frameHeight); |
| 3255 | } |
| 3256 | update_resolution(frameWidth, frameHeight, |
| 3257 | frameWidth, frameHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3258 | eRet = is_video_session_supported(); |
| 3259 | if (eRet) |
| 3260 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3261 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3262 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3263 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3264 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3265 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3266 | 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] | 3267 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3268 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3269 | DEBUG_PRINT_ERROR("Set Resolution failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3270 | eRet = OMX_ErrorUnsupportedSetting; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3271 | } else { |
| 3272 | if (!is_down_scalar_enabled) |
| 3273 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3274 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3275 | } |
| 3276 | } |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3277 | if (m_custom_buffersize.input_buffersize |
| 3278 | && (portDefn->nBufferSize > m_custom_buffersize.input_buffersize)) { |
| 3279 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size set by client: %d, trying to set: %d", |
| 3280 | m_custom_buffersize.input_buffersize, portDefn->nBufferSize); |
| 3281 | eRet = OMX_ErrorBadParameter; |
| 3282 | break; |
| 3283 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3284 | if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount |
| 3285 | || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) { |
| 3286 | port_format_changed = true; |
| 3287 | vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf; |
| 3288 | drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual; |
| 3289 | drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) & |
| 3290 | (~(buffer_prop->alignment - 1)); |
| 3291 | eRet = set_buffer_req(buffer_prop); |
| 3292 | } |
| 3293 | if (false == port_format_changed) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3294 | DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3295 | drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size, |
| 3296 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3297 | eRet = OMX_ErrorBadParameter; |
| 3298 | } |
| 3299 | } else if (portDefn->eDir == OMX_DirMax) { |
| 3300 | DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d", |
| 3301 | (int)portDefn->nPortIndex); |
| 3302 | eRet = OMX_ErrorBadPortIndex; |
| 3303 | } |
| 3304 | } |
| 3305 | break; |
| 3306 | case OMX_IndexParamVideoPortFormat: { |
| 3307 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 3308 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
| 3309 | int ret=0; |
| 3310 | struct v4l2_format fmt; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3311 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3312 | portFmt->eColorFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3313 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3314 | if (1 == portFmt->nPortIndex) { |
| 3315 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3316 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3317 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3318 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3319 | enum vdec_output_fromat op_format; |
| 3320 | if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE) |
| 3321 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) || |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 3322 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 3323 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3324 | op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3325 | else |
| 3326 | eRet = OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3327 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3328 | if (eRet == OMX_ErrorNone) { |
| 3329 | drv_ctx.output_format = op_format; |
| 3330 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3331 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3332 | DEBUG_PRINT_ERROR("Set output format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3333 | eRet = OMX_ErrorUnsupportedSetting; |
| 3334 | /*TODO: How to handle this case */ |
| 3335 | } else { |
| 3336 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3337 | } |
| 3338 | } |
| 3339 | if (eRet == OMX_ErrorNone) { |
| 3340 | if (!client_buffers.set_color_format(portFmt->eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3341 | DEBUG_PRINT_ERROR("Set color format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3342 | eRet = OMX_ErrorBadParameter; |
| 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | } |
| 3347 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3348 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3349 | case OMX_QcomIndexPortDefn: { |
| 3350 | OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt = |
| 3351 | (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3352 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3353 | portFmt->nFramePackingFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3354 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3355 | /* Input port */ |
| 3356 | if (portFmt->nPortIndex == 0) { |
| 3357 | if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) { |
| 3358 | if (secure_mode) { |
| 3359 | arbitrary_bytes = false; |
| 3360 | DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session"); |
| 3361 | eRet = OMX_ErrorUnsupportedSetting; |
| 3362 | } else { |
| 3363 | arbitrary_bytes = true; |
| 3364 | } |
| 3365 | } else if (portFmt->nFramePackingFormat == |
| 3366 | OMX_QCOM_FramePacking_OnlyOneCompleteFrame) { |
| 3367 | arbitrary_bytes = false; |
| 3368 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3369 | DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3370 | portFmt->nFramePackingFormat); |
| 3371 | eRet = OMX_ErrorUnsupportedSetting; |
| 3372 | } |
| 3373 | } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3374 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3375 | if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid && |
| 3376 | portFmt->nMemRegion < OMX_QCOM_MemRegionMax) && |
| 3377 | portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) { |
| 3378 | m_out_mem_region_smi = OMX_TRUE; |
| 3379 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3380 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3381 | m_use_output_pmem = OMX_TRUE; |
| 3382 | } |
| 3383 | } |
| 3384 | } |
| 3385 | } |
| 3386 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3387 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3388 | case OMX_IndexParamStandardComponentRole: { |
| 3389 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 3390 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3391 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3392 | comp_role->cRole); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3393 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3394 | if ((m_state == OMX_StateLoaded)&& |
| 3395 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 3396 | DEBUG_PRINT_LOW("Set Parameter called in valid state"); |
| 3397 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3398 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3399 | return OMX_ErrorIncorrectStateOperation; |
| 3400 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3401 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3402 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3403 | if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3404 | strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 3405 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3406 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3407 | eRet =OMX_ErrorUnsupportedSetting; |
| 3408 | } |
| 3409 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3410 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3411 | strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
| 3412 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3413 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3414 | eRet = OMX_ErrorUnsupportedSetting; |
| 3415 | } |
| 3416 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3417 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3418 | strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
| 3419 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3420 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3421 | eRet =OMX_ErrorUnsupportedSetting; |
| 3422 | } |
| 3423 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3424 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3425 | strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
| 3426 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3427 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3428 | eRet = OMX_ErrorUnsupportedSetting; |
| 3429 | } |
| 3430 | } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) || |
Deva Ramasubramanian | ba4534b | 2013-12-17 15:52:37 -0800 | [diff] [blame] | 3431 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311", OMX_MAX_STRINGNAME_SIZE)) || |
| 3432 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4", OMX_MAX_STRINGNAME_SIZE)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3433 | ) { |
| 3434 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) { |
| 3435 | strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
| 3436 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3437 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3438 | eRet =OMX_ErrorUnsupportedSetting; |
| 3439 | } |
| 3440 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 3441 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 3442 | ) { |
| 3443 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) { |
| 3444 | strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 3445 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3446 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3447 | eRet =OMX_ErrorUnsupportedSetting; |
| 3448 | } |
| 3449 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 3450 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) || |
| 3451 | (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) { |
| 3452 | strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 3453 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3454 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3455 | eRet = OMX_ErrorUnsupportedSetting; |
| 3456 | } |
| 3457 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3458 | DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3459 | eRet = OMX_ErrorInvalidComponentName; |
| 3460 | } |
| 3461 | break; |
| 3462 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3463 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3464 | case OMX_IndexParamPriorityMgmt: { |
| 3465 | if (m_state != OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3466 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3467 | return OMX_ErrorIncorrectStateOperation; |
| 3468 | } |
| 3469 | OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3470 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3471 | priorityMgmtype->nGroupID); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3472 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3473 | DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3474 | priorityMgmtype->nGroupPriority); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3475 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3476 | m_priority_mgm.nGroupID = priorityMgmtype->nGroupID; |
| 3477 | m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3478 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3479 | break; |
| 3480 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3481 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3482 | case OMX_IndexParamCompBufferSupplier: { |
| 3483 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3484 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3485 | bufferSupplierType->eBufferSupplier); |
| 3486 | if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1) |
| 3487 | m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3488 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3489 | else |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3490 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3491 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3492 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3493 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3494 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3495 | } |
| 3496 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3497 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3498 | paramIndex); |
| 3499 | break; |
| 3500 | } |
| 3501 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3502 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3503 | paramIndex); |
| 3504 | break; |
| 3505 | } |
| 3506 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3507 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3508 | paramIndex); |
| 3509 | break; |
| 3510 | } |
| 3511 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3512 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3513 | paramIndex); |
| 3514 | break; |
| 3515 | } |
| 3516 | case OMX_QcomIndexParamVideoDecoderPictureOrder: { |
| 3517 | QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder = |
| 3518 | (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData; |
| 3519 | struct v4l2_control control; |
| 3520 | int pic_order,rc=0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3521 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3522 | pictureOrder->eOutputPictureOrder); |
| 3523 | if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) { |
| 3524 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 3525 | } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) { |
| 3526 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3527 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3528 | } else |
| 3529 | eRet = OMX_ErrorBadParameter; |
| 3530 | if (eRet == OMX_ErrorNone) { |
| 3531 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3532 | control.value = pic_order; |
| 3533 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3534 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3535 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3536 | eRet = OMX_ErrorUnsupportedSetting; |
| 3537 | } |
| 3538 | } |
| 3539 | break; |
| 3540 | } |
| 3541 | case OMX_QcomIndexParamConcealMBMapExtraData: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3542 | eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false, |
| 3543 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3544 | break; |
| 3545 | case OMX_QcomIndexParamFrameInfoExtraData: |
| 3546 | eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false, |
| 3547 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3548 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3549 | case OMX_QcomIndexParamInterlaceExtraData: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3550 | eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false, |
| 3551 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3552 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3553 | case OMX_QcomIndexParamH264TimeInfo: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3554 | eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false, |
| 3555 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3556 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3557 | case OMX_QcomIndexParamVideoFramePackingExtradata: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3558 | eRet = enable_extradata(OMX_FRAMEPACK_EXTRADATA, false, |
| 3559 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3560 | break; |
| 3561 | case OMX_QcomIndexParamVideoQPExtraData: |
| 3562 | eRet = enable_extradata(OMX_QP_EXTRADATA, false, |
| 3563 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3564 | break; |
| 3565 | case OMX_QcomIndexParamVideoInputBitsInfoExtraData: |
| 3566 | eRet = enable_extradata(OMX_BITSINFO_EXTRADATA, false, |
| 3567 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3568 | break; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 3569 | case OMX_QcomIndexEnableExtnUserData: |
| 3570 | eRet = enable_extradata(OMX_EXTNUSER_EXTRADATA, false, |
| 3571 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3572 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3573 | case OMX_QcomIndexParamVideoDivx: { |
| 3574 | QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData; |
| 3575 | } |
| 3576 | break; |
| 3577 | case OMX_QcomIndexPlatformPvt: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3578 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3579 | OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData; |
| 3580 | if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
| 3581 | DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type); |
| 3582 | eRet = OMX_ErrorUnsupportedSetting; |
| 3583 | } else { |
| 3584 | m_out_pvt_entry_pmem = OMX_TRUE; |
| 3585 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3586 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3587 | m_use_output_pmem = OMX_TRUE; |
| 3588 | } |
| 3589 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3590 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3591 | } |
| 3592 | break; |
| 3593 | case OMX_QcomIndexParamVideoSyncFrameDecodingMode: { |
| 3594 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode"); |
| 3595 | DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode"); |
| 3596 | struct v4l2_control control; |
| 3597 | int rc; |
| 3598 | drv_ctx.idr_only_decoding = 1; |
| 3599 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3600 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3601 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3602 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3603 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3604 | eRet = OMX_ErrorUnsupportedSetting; |
| 3605 | } else { |
| 3606 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE; |
| 3607 | control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE; |
| 3608 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3609 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3610 | DEBUG_PRINT_ERROR("Sync frame setting failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3611 | eRet = OMX_ErrorUnsupportedSetting; |
| 3612 | } |
| 3613 | /*Setting sync frame decoding on driver might change buffer |
| 3614 | * requirements so update them here*/ |
| 3615 | if (get_buffer_req(&drv_ctx.ip_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3616 | 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] | 3617 | eRet = OMX_ErrorUnsupportedSetting; |
| 3618 | } |
| 3619 | if (get_buffer_req(&drv_ctx.op_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3620 | 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] | 3621 | eRet = OMX_ErrorUnsupportedSetting; |
| 3622 | } |
| 3623 | } |
| 3624 | } |
| 3625 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3626 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3627 | case OMX_QcomIndexParamIndexExtraDataType: { |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3628 | QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData; |
| 3629 | if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) && |
| 3630 | (extradataIndexType->bEnabled == OMX_TRUE) && |
| 3631 | (extradataIndexType->nPortIndex == 1)) { |
| 3632 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming"); |
| 3633 | eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled); |
| 3634 | } |
| 3635 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3636 | break; |
| 3637 | case OMX_QcomIndexParamEnableSmoothStreaming: { |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3638 | #ifndef SMOOTH_STREAMING_DISABLED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3639 | eRet = enable_smoothstreaming(); |
Arun Menon | bc0922f | 2013-06-24 13:02:15 -0700 | [diff] [blame] | 3640 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3641 | eRet = OMX_ErrorUnsupportedSetting; |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3642 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3643 | } |
| 3644 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3645 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3646 | /* Need to allow following two set_parameters even in Idle |
| 3647 | * state. This is ANDROID architecture which is not in sync |
| 3648 | * with openmax standard. */ |
| 3649 | case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: { |
| 3650 | EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData; |
| 3651 | if (enableNativeBuffers) { |
| 3652 | m_enable_android_native_buffers = enableNativeBuffers->enable; |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 3653 | } |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 3654 | #if !defined(FLEXYUV_SUPPORTED) |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 3655 | if (m_enable_android_native_buffers) { |
| 3656 | // Use the most-preferred-native-color-format as surface-mode is hinted here |
| 3657 | if(!client_buffers.set_color_format(getPreferredColorFormatDefaultMode(0))) { |
| 3658 | DEBUG_PRINT_ERROR("Failed to set native color format!"); |
| 3659 | eRet = OMX_ErrorUnsupportedSetting; |
| 3660 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3661 | } |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 3662 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3663 | } |
| 3664 | break; |
| 3665 | case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: { |
| 3666 | eRet = use_android_native_buffer(hComp, paramData); |
| 3667 | } |
| 3668 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3669 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3670 | case OMX_QcomIndexParamEnableTimeStampReorder: { |
| 3671 | QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData; |
| 3672 | if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) { |
| 3673 | if (reorder->bEnable == OMX_TRUE) { |
| 3674 | frm_int =0; |
| 3675 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 3676 | } else |
| 3677 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3678 | } else { |
| 3679 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3680 | if (reorder->bEnable == OMX_TRUE) { |
| 3681 | eRet = OMX_ErrorUnsupportedSetting; |
| 3682 | } |
| 3683 | } |
| 3684 | } |
| 3685 | break; |
| 3686 | case OMX_IndexParamVideoProfileLevelCurrent: { |
| 3687 | OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = |
| 3688 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData; |
| 3689 | if (pParam) { |
| 3690 | m_profile_lvl.eProfile = pParam->eProfile; |
| 3691 | m_profile_lvl.eLevel = pParam->eLevel; |
| 3692 | } |
| 3693 | break; |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 3694 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3695 | } |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3696 | case OMX_QcomIndexParamVideoMetaBufferMode: |
| 3697 | { |
| 3698 | StoreMetaDataInBuffersParams *metabuffer = |
| 3699 | (StoreMetaDataInBuffersParams *)paramData; |
| 3700 | if (!metabuffer) { |
| 3701 | DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer); |
| 3702 | eRet = OMX_ErrorBadParameter; |
| 3703 | break; |
| 3704 | } |
| 3705 | if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3706 | //set property dynamic buffer mode to driver. |
| 3707 | struct v4l2_control control; |
| 3708 | struct v4l2_format fmt; |
| 3709 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT; |
| 3710 | if (metabuffer->bStoreMetaData == true) { |
| 3711 | control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC; |
| 3712 | } else { |
| 3713 | control.value = V4L2_MPEG_VIDC_VIDEO_STATIC; |
| 3714 | } |
| 3715 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3716 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3717 | DEBUG_PRINT_HIGH("%s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3718 | (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 3719 | dynamic_buf_mode = metabuffer->bStoreMetaData; |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3720 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3721 | DEBUG_PRINT_ERROR("Failed to %s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3722 | (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic"); |
| 3723 | eRet = OMX_ErrorUnsupportedSetting; |
| 3724 | } |
| 3725 | } else { |
| 3726 | DEBUG_PRINT_ERROR( |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3727 | "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %lu", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3728 | metabuffer->nPortIndex); |
| 3729 | eRet = OMX_ErrorUnsupportedSetting; |
| 3730 | } |
| 3731 | break; |
| 3732 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3733 | case OMX_QcomIndexParamVideoDownScalar: { |
| 3734 | QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData; |
| 3735 | struct v4l2_control control; |
| 3736 | int rc; |
| 3737 | if (pParam) { |
| 3738 | is_down_scalar_enabled = pParam->bEnable; |
| 3739 | if (is_down_scalar_enabled) { |
| 3740 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE; |
| 3741 | control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY; |
| 3742 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n", |
| 3743 | pParam->bEnable); |
| 3744 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3745 | if (rc < 0) { |
| 3746 | DEBUG_PRINT_ERROR("Failed to set down scalar on driver."); |
| 3747 | eRet = OMX_ErrorUnsupportedSetting; |
| 3748 | } |
| 3749 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO; |
| 3750 | control.value = 1; |
| 3751 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3752 | if (rc < 0) { |
| 3753 | DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver."); |
| 3754 | eRet = OMX_ErrorUnsupportedSetting; |
| 3755 | } |
| 3756 | } |
| 3757 | } |
| 3758 | break; |
| 3759 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3760 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
| 3761 | case OMX_QcomIndexParamVideoAdaptivePlaybackMode: |
| 3762 | { |
| 3763 | DEBUG_PRINT_LOW("set_parameter: OMX_GoogleAndroidIndexPrepareForAdaptivePlayback"); |
| 3764 | PrepareForAdaptivePlaybackParams* pParams = |
| 3765 | (PrepareForAdaptivePlaybackParams *) paramData; |
| 3766 | if (pParams->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3767 | if (!pParams->bEnable) { |
| 3768 | return OMX_ErrorNone; |
| 3769 | } |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3770 | if (pParams->nMaxFrameWidth > maxSmoothStreamingWidth |
| 3771 | || pParams->nMaxFrameHeight > maxSmoothStreamingHeight) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3772 | DEBUG_PRINT_ERROR( |
| 3773 | "Adaptive playback request exceeds max supported resolution : [%lu x %lu] vs [%lu x %lu]", |
| 3774 | pParams->nMaxFrameWidth, pParams->nMaxFrameHeight, |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3775 | maxSmoothStreamingWidth, maxSmoothStreamingHeight); |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3776 | eRet = OMX_ErrorBadParameter; |
| 3777 | } else { |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 3778 | eRet = enable_adaptive_playback(pParams->nMaxFrameWidth, pParams->nMaxFrameHeight); |
| 3779 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3780 | } else { |
| 3781 | DEBUG_PRINT_ERROR( |
| 3782 | "Prepare for adaptive playback supported only on output port"); |
| 3783 | eRet = OMX_ErrorBadParameter; |
| 3784 | } |
| 3785 | break; |
| 3786 | } |
| 3787 | |
| 3788 | #endif |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3789 | case OMX_QcomIndexParamVideoCustomBufferSize: |
| 3790 | { |
| 3791 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoCustomBufferSize"); |
| 3792 | QOMX_VIDEO_CUSTOM_BUFFERSIZE* pParam = (QOMX_VIDEO_CUSTOM_BUFFERSIZE*)paramData; |
| 3793 | if (pParam->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 3794 | struct v4l2_control control; |
| 3795 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT; |
| 3796 | control.value = pParam->nBufferSize; |
| 3797 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 3798 | DEBUG_PRINT_ERROR("Failed to set input buffer size"); |
| 3799 | eRet = OMX_ErrorUnsupportedSetting; |
| 3800 | } else { |
| 3801 | eRet = get_buffer_req(&drv_ctx.ip_buf); |
| 3802 | if (eRet == OMX_ErrorNone) { |
| 3803 | m_custom_buffersize.input_buffersize = drv_ctx.ip_buf.buffer_size; |
| 3804 | DEBUG_PRINT_HIGH("Successfully set custom input buffer size = %d", |
| 3805 | m_custom_buffersize.input_buffersize); |
| 3806 | } else { |
| 3807 | DEBUG_PRINT_ERROR("Failed to get buffer requirement"); |
| 3808 | } |
| 3809 | } |
| 3810 | } else { |
| 3811 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size in not supported on output port"); |
| 3812 | eRet = OMX_ErrorBadParameter; |
| 3813 | } |
| 3814 | break; |
| 3815 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3816 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3817 | DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3818 | eRet = OMX_ErrorUnsupportedIndex; |
| 3819 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3820 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 3821 | if (eRet != OMX_ErrorNone) |
| 3822 | DEBUG_PRINT_ERROR("set_parameter: Error: 0x%x, setting param 0x%x", eRet, paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3823 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3827 | FUNCTION |
| 3828 | omx_vdec::GetConfig |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3829 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3830 | DESCRIPTION |
| 3831 | OMX Get Config Method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3832 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3833 | PARAMETERS |
| 3834 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3835 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3836 | RETURN VALUE |
| 3837 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3838 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3839 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3840 | OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3841 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3842 | OMX_INOUT OMX_PTR configData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3843 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3844 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3845 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3846 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3847 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3848 | return OMX_ErrorInvalidState; |
| 3849 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3850 | |
| 3851 | switch ((unsigned long)configIndex) { |
| 3852 | case OMX_QcomIndexConfigInterlaced: { |
| 3853 | OMX_QCOM_CONFIG_INTERLACETYPE *configFmt = |
| 3854 | (OMX_QCOM_CONFIG_INTERLACETYPE *) configData; |
| 3855 | if (configFmt->nPortIndex == 1) { |
| 3856 | if (configFmt->nIndex == 0) { |
| 3857 | configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 3858 | } else if (configFmt->nIndex == 1) { |
| 3859 | configFmt->eInterlaceType = |
| 3860 | OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 3861 | } else if (configFmt->nIndex == 2) { |
| 3862 | configFmt->eInterlaceType = |
| 3863 | OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 3864 | } else { |
| 3865 | DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3866 | " NoMore Interlaced formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3867 | eRet = OMX_ErrorNoMore; |
| 3868 | } |
| 3869 | |
| 3870 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3871 | 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] | 3872 | (int)configFmt->nPortIndex); |
| 3873 | eRet = OMX_ErrorBadPortIndex; |
| 3874 | } |
| 3875 | break; |
| 3876 | } |
| 3877 | case OMX_QcomIndexQueryNumberOfVideoDecInstance: { |
| 3878 | QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances = |
| 3879 | (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData; |
| 3880 | decoderinstances->nNumOfInstances = 16; |
| 3881 | /*TODO: How to handle this case */ |
| 3882 | break; |
| 3883 | } |
| 3884 | case OMX_QcomIndexConfigVideoFramePackingArrangement: { |
| 3885 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
| 3886 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt = |
| 3887 | (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3888 | memcpy(configFmt, &m_frame_pack_arrangement, |
| 3889 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3890 | } else { |
| 3891 | DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs"); |
| 3892 | } |
| 3893 | break; |
| 3894 | } |
| 3895 | case OMX_IndexConfigCommonOutputCrop: { |
| 3896 | OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData; |
| 3897 | memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE)); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 3898 | DEBUG_PRINT_HIGH("get_config: crop info: L: %u, T: %u, R: %u, B: %u", |
| 3899 | rectangle.nLeft, rectangle.nTop, |
| 3900 | rectangle.nWidth, rectangle.nHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3901 | break; |
| 3902 | } |
| 3903 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3904 | DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3905 | eRet = OMX_ErrorBadParameter; |
| 3906 | } |
| 3907 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3908 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3909 | |
| 3910 | return eRet; |
| 3911 | } |
| 3912 | |
| 3913 | /* ====================================================================== |
| 3914 | FUNCTION |
| 3915 | omx_vdec::SetConfig |
| 3916 | |
| 3917 | DESCRIPTION |
| 3918 | OMX Set Config method implementation |
| 3919 | |
| 3920 | PARAMETERS |
| 3921 | <TBD>. |
| 3922 | |
| 3923 | RETURN VALUE |
| 3924 | OMX Error None if successful. |
| 3925 | ========================================================================== */ |
| 3926 | OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp, |
| 3927 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3928 | OMX_IN OMX_PTR configData) |
| 3929 | { |
| 3930 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3931 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3932 | return OMX_ErrorInvalidState; |
| 3933 | } |
| 3934 | |
| 3935 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 3936 | OMX_VIDEO_CONFIG_NALSIZE *pNal; |
| 3937 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3938 | DEBUG_PRINT_LOW("Set Config Called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3939 | |
| 3940 | if (configIndex == (OMX_INDEXTYPE)OMX_IndexVendorVideoExtraData) { |
| 3941 | OMX_VENDOR_EXTRADATATYPE *config = (OMX_VENDOR_EXTRADATATYPE *) configData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3942 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3943 | if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3944 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData AVC"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3945 | OMX_U32 extra_size; |
| 3946 | // Parsing done here for the AVC atom is definitely not generic |
| 3947 | // Currently this piece of code is working, but certainly |
| 3948 | // not tested with all .mp4 files. |
| 3949 | // Incase of failure, we might need to revisit this |
| 3950 | // for a generic piece of code. |
| 3951 | |
| 3952 | // Retrieve size of NAL length field |
| 3953 | // byte #4 contains the size of NAL lenght field |
| 3954 | nal_length = (config->pData[4] & 0x03) + 1; |
| 3955 | |
| 3956 | extra_size = 0; |
| 3957 | if (nal_length > 2) { |
| 3958 | /* Presently we assume that only one SPS and one PPS in AvC1 Atom */ |
| 3959 | extra_size = (nal_length - 2) * 2; |
| 3960 | } |
| 3961 | |
| 3962 | // SPS starts from byte #6 |
| 3963 | OMX_U8 *pSrcBuf = (OMX_U8 *) (&config->pData[6]); |
| 3964 | OMX_U8 *pDestBuf; |
| 3965 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3966 | |
| 3967 | // minus 6 --> SPS starts from byte #6 |
| 3968 | // minus 1 --> picture param set byte to be ignored from avcatom |
| 3969 | m_vendor_config.nDataSize = config->nDataSize - 6 - 1 + extra_size; |
| 3970 | m_vendor_config.pData = (OMX_U8 *) malloc(m_vendor_config.nDataSize); |
| 3971 | OMX_U32 len; |
| 3972 | OMX_U8 index = 0; |
| 3973 | // case where SPS+PPS is sent as part of set_config |
| 3974 | pDestBuf = m_vendor_config.pData; |
| 3975 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3976 | DEBUG_PRINT_LOW("Rxd SPS+PPS nPortIndex[%lu] len[%lu] data[%p]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3977 | m_vendor_config.nPortIndex, |
| 3978 | m_vendor_config.nDataSize, |
| 3979 | m_vendor_config.pData); |
| 3980 | while (index < 2) { |
| 3981 | uint8 *psize; |
| 3982 | len = *pSrcBuf; |
| 3983 | len = len << 8; |
| 3984 | len |= *(pSrcBuf + 1); |
| 3985 | psize = (uint8 *) & len; |
| 3986 | memcpy(pDestBuf + nal_length, pSrcBuf + 2,len); |
| 3987 | for (unsigned int i = 0; i < nal_length; i++) { |
| 3988 | pDestBuf[i] = psize[nal_length - 1 - i]; |
| 3989 | } |
| 3990 | //memcpy(pDestBuf,pSrcBuf,(len+2)); |
| 3991 | pDestBuf += len + nal_length; |
| 3992 | pSrcBuf += len + 2; |
| 3993 | index++; |
| 3994 | pSrcBuf++; // skip picture param set |
| 3995 | len = 0; |
| 3996 | } |
| 3997 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4") || |
| 3998 | !strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2")) { |
| 3999 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4000 | m_vendor_config.nDataSize = config->nDataSize; |
| 4001 | m_vendor_config.pData = (OMX_U8 *) malloc((config->nDataSize)); |
| 4002 | memcpy(m_vendor_config.pData, config->pData,config->nDataSize); |
| 4003 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1")) { |
| 4004 | if (m_vendor_config.pData) { |
| 4005 | free(m_vendor_config.pData); |
| 4006 | m_vendor_config.pData = NULL; |
| 4007 | m_vendor_config.nDataSize = 0; |
| 4008 | } |
| 4009 | |
| 4010 | if (((*((OMX_U32 *) config->pData)) & |
| 4011 | VC1_SP_MP_START_CODE_MASK) == |
| 4012 | VC1_SP_MP_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4013 | DEBUG_PRINT_LOW("set_config - VC1 simple/main profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4014 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4015 | m_vendor_config.nDataSize = config->nDataSize; |
| 4016 | m_vendor_config.pData = |
| 4017 | (OMX_U8 *) malloc(config->nDataSize); |
| 4018 | memcpy(m_vendor_config.pData, config->pData, |
| 4019 | config->nDataSize); |
| 4020 | m_vc1_profile = VC1_SP_MP_RCV; |
| 4021 | } else if (*((OMX_U32 *) config->pData) == VC1_AP_SEQ_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4022 | DEBUG_PRINT_LOW("set_config - VC1 Advance profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4023 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4024 | m_vendor_config.nDataSize = config->nDataSize; |
| 4025 | m_vendor_config.pData = |
| 4026 | (OMX_U8 *) malloc((config->nDataSize)); |
| 4027 | memcpy(m_vendor_config.pData, config->pData, |
| 4028 | config->nDataSize); |
| 4029 | m_vc1_profile = VC1_AP; |
| 4030 | } else if ((config->nDataSize == VC1_STRUCT_C_LEN)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4031 | DEBUG_PRINT_LOW("set_config - VC1 Simple/Main profile struct C only"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4032 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4033 | m_vendor_config.nDataSize = config->nDataSize; |
| 4034 | m_vendor_config.pData = (OMX_U8*)malloc(config->nDataSize); |
| 4035 | memcpy(m_vendor_config.pData,config->pData,config->nDataSize); |
| 4036 | m_vc1_profile = VC1_SP_MP_RCV; |
| 4037 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4038 | DEBUG_PRINT_LOW("set_config - Error: Unknown VC1 profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4039 | } |
| 4040 | } |
| 4041 | return ret; |
| 4042 | } else if (configIndex == OMX_IndexConfigVideoNalSize) { |
| 4043 | struct v4l2_control temp; |
| 4044 | temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT; |
| 4045 | |
| 4046 | pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData); |
| 4047 | switch (pNal->nNaluBytes) { |
| 4048 | case 0: |
| 4049 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES; |
| 4050 | break; |
| 4051 | case 2: |
| 4052 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH; |
| 4053 | break; |
| 4054 | case 4: |
| 4055 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH; |
| 4056 | break; |
| 4057 | default: |
| 4058 | return OMX_ErrorUnsupportedSetting; |
| 4059 | } |
| 4060 | |
| 4061 | if (!arbitrary_bytes) { |
| 4062 | /* In arbitrary bytes mode, the assembler strips out nal size and replaces |
| 4063 | * with start code, so only need to notify driver in frame by frame mode */ |
| 4064 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) { |
| 4065 | DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT"); |
| 4066 | return OMX_ErrorHardware; |
| 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | nal_length = pNal->nNaluBytes; |
| 4071 | m_frame_parser.init_nal_length(nal_length); |
| 4072 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4073 | DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4074 | return ret; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4075 | } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4076 | OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4077 | DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4078 | |
| 4079 | if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 4080 | if (config->bEnabled) { |
| 4081 | if ((config->nFps >> 16) > 0) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4082 | DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4083 | config->nFps >> 16); |
| 4084 | Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator, |
| 4085 | drv_ctx.frame_rate.fps_denominator); |
| 4086 | |
| 4087 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 4088 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 4089 | drv_ctx.frame_rate.fps_numerator = 30; |
| 4090 | } |
| 4091 | |
| 4092 | if (drv_ctx.frame_rate.fps_denominator) { |
| 4093 | drv_ctx.frame_rate.fps_numerator = (int) |
| 4094 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 4095 | } |
| 4096 | |
| 4097 | drv_ctx.frame_rate.fps_denominator = 1; |
| 4098 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 4099 | drv_ctx.frame_rate.fps_numerator; |
| 4100 | |
| 4101 | struct v4l2_outputparm oparm; |
| 4102 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 4103 | * per second.*/ |
| 4104 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 4105 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 4106 | |
| 4107 | struct v4l2_streamparm sparm; |
| 4108 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 4109 | sparm.parm.output = oparm; |
| 4110 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 4111 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 4112 | performance might be affected"); |
| 4113 | ret = OMX_ErrorHardware; |
| 4114 | } |
| 4115 | client_set_fps = true; |
| 4116 | } else { |
| 4117 | DEBUG_PRINT_ERROR("Frame rate not supported."); |
| 4118 | ret = OMX_ErrorUnsupportedSetting; |
| 4119 | } |
| 4120 | } else { |
| 4121 | DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate"); |
| 4122 | client_set_fps = false; |
| 4123 | } |
| 4124 | } else { |
| 4125 | DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d", |
| 4126 | (int)config->nPortIndex); |
| 4127 | ret = OMX_ErrorBadPortIndex; |
| 4128 | } |
| 4129 | |
| 4130 | return ret; |
Praveen Chavan | 898df26 | 2015-04-20 18:52:19 -0700 | [diff] [blame] | 4131 | } else if ((int)configIndex == (int)OMX_IndexConfigPriority) { |
| 4132 | OMX_PARAM_U32TYPE *priority = (OMX_PARAM_U32TYPE *)configData; |
| 4133 | DEBUG_PRINT_LOW("Set_config: priority %d", priority->nU32); |
| 4134 | |
| 4135 | struct v4l2_control control; |
| 4136 | |
| 4137 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY; |
| 4138 | if (priority->nU32 == 0) |
| 4139 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_ENABLE; |
| 4140 | else |
| 4141 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE; |
| 4142 | |
| 4143 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 4144 | DEBUG_PRINT_ERROR("Failed to set Priority"); |
| 4145 | ret = OMX_ErrorUnsupportedSetting; |
| 4146 | } |
| 4147 | return ret; |
Praveen Chavan | 281d502 | 2015-04-30 20:28:44 -0700 | [diff] [blame^] | 4148 | } else if ((int)configIndex == (int)OMX_IndexConfigOperatingRate) { |
| 4149 | OMX_PARAM_U32TYPE *rate = (OMX_PARAM_U32TYPE *)configData; |
| 4150 | DEBUG_PRINT_LOW("Set_config: operating-rate %u fps", rate->nU32 >> 16); |
| 4151 | |
| 4152 | struct v4l2_control control; |
| 4153 | |
| 4154 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OPERATING_RATE; |
| 4155 | control.value = rate->nU32; |
| 4156 | |
| 4157 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 4158 | ret = errno == -EBUSY ? OMX_ErrorInsufficientResources : |
| 4159 | OMX_ErrorUnsupportedSetting; |
| 4160 | DEBUG_PRINT_ERROR("Failed to set operating rate %u fps (%s)", |
| 4161 | rate->nU32 >> 16, errno == -EBUSY ? "HW Overload" : strerror(errno)); |
| 4162 | } |
| 4163 | return ret; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | return OMX_ErrorNotImplemented; |
| 4167 | } |
| 4168 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4169 | #define extn_equals(param, extn) (!strncmp(param, extn, strlen(extn))) |
| 4170 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4171 | /* ====================================================================== |
| 4172 | FUNCTION |
| 4173 | omx_vdec::GetExtensionIndex |
| 4174 | |
| 4175 | DESCRIPTION |
| 4176 | OMX GetExtensionIndex method implementaion. <TBD> |
| 4177 | |
| 4178 | PARAMETERS |
| 4179 | <TBD>. |
| 4180 | |
| 4181 | RETURN VALUE |
| 4182 | OMX Error None if everything successful. |
| 4183 | |
| 4184 | ========================================================================== */ |
| 4185 | OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp, |
| 4186 | OMX_IN OMX_STRING paramName, |
| 4187 | OMX_OUT OMX_INDEXTYPE* indexType) |
| 4188 | { |
| 4189 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4190 | DEBUG_PRINT_ERROR("Get Extension Index in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4191 | return OMX_ErrorInvalidState; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4192 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode")) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4193 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4194 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.IndexExtraData")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4195 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4196 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_FRAMEPACKING_EXTRADATA)) { |
| 4197 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoFramePackingExtradata; |
| 4198 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_CONFIG_VIDEO_FRAMEPACKING_INFO)) { |
| 4199 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoFramePackingArrangement; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 4200 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_QP_EXTRADATA)) { |
| 4201 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPExtraData; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 4202 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_INPUTBITSINFO_EXTRADATA)) { |
| 4203 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoInputBitsInfoExtraData; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 4204 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_EXTNUSER_EXTRADATA)) { |
| 4205 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableExtnUserData; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4206 | } |
| 4207 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4208 | else if (extn_equals(paramName, "OMX.google.android.index.enableAndroidNativeBuffers")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4209 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4210 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer2")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4211 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4212 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4213 | DEBUG_PRINT_ERROR("Extension: %s is supported", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4214 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4215 | } else if (extn_equals(paramName, "OMX.google.android.index.getAndroidNativeBufferUsage")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4216 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage; |
| 4217 | } |
| 4218 | #endif |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4219 | else if (extn_equals(paramName, "OMX.google.android.index.storeMetaDataInBuffers")) { |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 4220 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode; |
| 4221 | } |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 4222 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 4223 | else if (extn_equals(paramName, "OMX.google.android.index.prepareForAdaptivePlayback")) { |
| 4224 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoAdaptivePlaybackMode; |
| 4225 | } |
| 4226 | #endif |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 4227 | #ifdef FLEXYUV_SUPPORTED |
| 4228 | else if (extn_equals(paramName,"OMX.google.android.index.describeColorFormat")) { |
| 4229 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexFlexibleYUVDescription; |
| 4230 | } |
| 4231 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4232 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4233 | DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4234 | return OMX_ErrorNotImplemented; |
| 4235 | } |
| 4236 | return OMX_ErrorNone; |
| 4237 | } |
| 4238 | |
| 4239 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4240 | FUNCTION |
| 4241 | omx_vdec::GetState |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4242 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4243 | DESCRIPTION |
| 4244 | Returns the state information back to the caller.<TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4245 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4246 | PARAMETERS |
| 4247 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4248 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4249 | RETURN VALUE |
| 4250 | Error None if everything is successful. |
| 4251 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4252 | OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4253 | OMX_OUT OMX_STATETYPE* state) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4254 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4255 | *state = m_state; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4256 | DEBUG_PRINT_LOW("get_state: Returning the state %d",*state); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4257 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4261 | FUNCTION |
| 4262 | omx_vdec::ComponentTunnelRequest |
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 | DESCRIPTION |
| 4265 | OMX Component Tunnel Request method implementation. <TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4266 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4267 | PARAMETERS |
| 4268 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4269 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4270 | RETURN VALUE |
| 4271 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4272 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4273 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4274 | OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4275 | OMX_IN OMX_U32 port, |
| 4276 | OMX_IN OMX_HANDLETYPE peerComponent, |
| 4277 | OMX_IN OMX_U32 peerPort, |
| 4278 | OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4279 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4280 | DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4281 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4285 | FUNCTION |
| 4286 | omx_vdec::UseOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4287 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4288 | DESCRIPTION |
| 4289 | Helper function for Use buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4290 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4291 | PARAMETERS |
| 4292 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4293 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4294 | RETURN VALUE |
| 4295 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4296 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4297 | ========================================================================== */ |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4298 | OMX_ERRORTYPE omx_vdec::allocate_extradata() |
| 4299 | { |
| 4300 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4301 | if (drv_ctx.extradata_info.buffer_size) { |
| 4302 | if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) { |
| 4303 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4304 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4305 | free_ion_memory(&drv_ctx.extradata_info.ion); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4306 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4307 | } |
| 4308 | drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095); |
| 4309 | drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory( |
| 4310 | drv_ctx.extradata_info.size, 4096, |
| 4311 | &drv_ctx.extradata_info.ion.ion_alloc_data, |
| 4312 | &drv_ctx.extradata_info.ion.fd_ion_data, 0); |
| 4313 | if (drv_ctx.extradata_info.ion.ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4314 | DEBUG_PRINT_ERROR("Failed to alloc extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4315 | return OMX_ErrorInsufficientResources; |
| 4316 | } |
| 4317 | drv_ctx.extradata_info.uaddr = (char *)mmap(NULL, |
| 4318 | drv_ctx.extradata_info.size, |
| 4319 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4320 | drv_ctx.extradata_info.ion.fd_ion_data.fd , 0); |
| 4321 | if (drv_ctx.extradata_info.uaddr == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4322 | DEBUG_PRINT_ERROR("Failed to map extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4323 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4324 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4325 | return OMX_ErrorInsufficientResources; |
| 4326 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4327 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4328 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4329 | if (!m_other_extradata) { |
| 4330 | m_other_extradata = (OMX_OTHER_EXTRADATATYPE *)malloc(drv_ctx.extradata_info.buffer_size); |
| 4331 | if (!m_other_extradata) { |
| 4332 | DEBUG_PRINT_ERROR("Failed to alloc memory\n"); |
| 4333 | return OMX_ErrorInsufficientResources; |
| 4334 | } |
| 4335 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4336 | return OMX_ErrorNone; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4339 | void omx_vdec::free_extradata() |
| 4340 | { |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4341 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4342 | if (drv_ctx.extradata_info.uaddr) { |
| 4343 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4344 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4345 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4346 | } |
| 4347 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4348 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4349 | if (m_other_extradata) { |
| 4350 | free(m_other_extradata); |
| 4351 | m_other_extradata = NULL; |
| 4352 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4353 | } |
| 4354 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4355 | OMX_ERRORTYPE omx_vdec::use_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4356 | OMX_IN OMX_HANDLETYPE hComp, |
| 4357 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4358 | OMX_IN OMX_U32 port, |
| 4359 | OMX_IN OMX_PTR appData, |
| 4360 | OMX_IN OMX_U32 bytes, |
| 4361 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4362 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4363 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4364 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 4365 | unsigned i= 0; // Temporary counter |
| 4366 | struct vdec_setbuffer_cmd setbuffers; |
| 4367 | OMX_PTR privateAppData = NULL; |
| 4368 | private_handle_t *handle = NULL; |
| 4369 | OMX_U8 *buff = buffer; |
| 4370 | struct v4l2_buffer buf; |
| 4371 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 4372 | int extra_idx = 0; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4373 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4374 | if (!m_out_mem_ptr) { |
| 4375 | DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers"); |
| 4376 | eRet = allocate_output_headers(); |
| 4377 | if (eRet == OMX_ErrorNone) |
| 4378 | eRet = allocate_extradata(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4379 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4380 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4381 | if (eRet == OMX_ErrorNone) { |
| 4382 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 4383 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
| 4384 | break; |
| 4385 | } |
| 4386 | } |
| 4387 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4388 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4389 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4390 | 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] | 4391 | eRet = OMX_ErrorInsufficientResources; |
| 4392 | } |
| 4393 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 4394 | if (dynamic_buf_mode) { |
| 4395 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4396 | (*bufferHdr)->pBuffer = NULL; |
| 4397 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4398 | enum v4l2_buf_type buf_type; |
| 4399 | int rr = 0; |
| 4400 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4401 | if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4402 | DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr); |
| 4403 | return OMX_ErrorInsufficientResources; |
| 4404 | } else { |
| 4405 | streaming[CAPTURE_PORT] = true; |
| 4406 | DEBUG_PRINT_LOW("STREAMON Successful"); |
| 4407 | } |
| 4408 | } |
| 4409 | BITMASK_SET(&m_out_bm_count,i); |
| 4410 | (*bufferHdr)->pAppPrivate = appData; |
| 4411 | (*bufferHdr)->pBuffer = buffer; |
| 4412 | (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 4413 | return eRet; |
| 4414 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4415 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4416 | #if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4417 | if (m_enable_android_native_buffers) { |
| 4418 | if (m_use_android_native_buffers) { |
| 4419 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData; |
| 4420 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 4421 | handle = (private_handle_t *)nBuf->handle; |
| 4422 | privateAppData = params->pAppPrivate; |
| 4423 | } else { |
| 4424 | handle = (private_handle_t *)buff; |
| 4425 | privateAppData = appData; |
| 4426 | } |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4427 | if (!handle) { |
| 4428 | DEBUG_PRINT_ERROR("handle is invalid"); |
| 4429 | return OMX_ErrorBadParameter; |
| 4430 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4431 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4432 | if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) { |
| 4433 | DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback," |
| 4434 | " expected %u, got %lu", |
| 4435 | drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size); |
| 4436 | return OMX_ErrorBadParameter; |
| 4437 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4438 | |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 4439 | drv_ctx.op_buf.buffer_size = handle->size; |
| 4440 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4441 | if (!m_use_android_native_buffers) { |
| 4442 | if (!secure_mode) { |
| 4443 | buff = (OMX_U8*)mmap(0, handle->size, |
| 4444 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
| 4445 | if (buff == MAP_FAILED) { |
| 4446 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 4447 | return OMX_ErrorInsufficientResources; |
| 4448 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4449 | } |
| 4450 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4451 | #if defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4452 | native_buffer[i].nativehandle = handle; |
| 4453 | native_buffer[i].privatehandle = handle; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4454 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4455 | if (!handle) { |
| 4456 | DEBUG_PRINT_ERROR("Native Buffer handle is NULL"); |
| 4457 | return OMX_ErrorBadParameter; |
| 4458 | } |
| 4459 | drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd; |
| 4460 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4461 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4462 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4463 | drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size; |
| 4464 | } else |
| 4465 | #endif |
| 4466 | |
| 4467 | if (!ouput_egl_buffers && !m_use_output_pmem) { |
| 4468 | #ifdef USE_ION |
| 4469 | drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 4470 | drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 4471 | &drv_ctx.op_buf_ion_info[i].ion_alloc_data, |
| 4472 | &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4473 | if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4474 | 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] | 4475 | return OMX_ErrorInsufficientResources; |
| 4476 | } |
| 4477 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4478 | drv_ctx.op_buf_ion_info[i].fd_ion_data.fd; |
| 4479 | #else |
| 4480 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4481 | open (MEM_DEVICE,O_RDWR); |
| 4482 | |
| 4483 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4484 | 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] | 4485 | return OMX_ErrorInsufficientResources; |
| 4486 | } |
| 4487 | |
| 4488 | /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */ |
| 4489 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) { |
| 4490 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4491 | open (MEM_DEVICE,O_RDWR); |
| 4492 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4493 | 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] | 4494 | return OMX_ErrorInsufficientResources; |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd, |
| 4499 | drv_ctx.op_buf.buffer_size, |
| 4500 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4501 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4502 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4503 | return OMX_ErrorInsufficientResources; |
| 4504 | } |
| 4505 | #endif |
| 4506 | if (!secure_mode) { |
| 4507 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 4508 | (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size, |
| 4509 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4510 | drv_ctx.ptr_outputbuffer[i].pmem_fd,0); |
| 4511 | if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) { |
| 4512 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4513 | #ifdef USE_ION |
| 4514 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
| 4515 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4516 | DEBUG_PRINT_ERROR("Unable to mmap output buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4517 | return OMX_ErrorInsufficientResources; |
| 4518 | } |
| 4519 | } |
| 4520 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4521 | privateAppData = appData; |
| 4522 | } else { |
| 4523 | |
| 4524 | DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem); |
| 4525 | if (!appData || !bytes ) { |
| 4526 | if (!secure_mode && !buffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4527 | DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4528 | return OMX_ErrorBadParameter; |
| 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list; |
| 4533 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info; |
| 4534 | pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData; |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4535 | if (!pmem_list || !pmem_list->entryList || !pmem_list->entryList->entry || |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4536 | !pmem_list->nEntries || |
| 4537 | pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4538 | DEBUG_PRINT_ERROR("Pmem info not valid in use buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4539 | return OMX_ErrorBadParameter; |
| 4540 | } |
| 4541 | pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 4542 | pmem_list->entryList->entry; |
| 4543 | DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx", |
| 4544 | pmem_info->pmem_fd); |
| 4545 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd; |
| 4546 | drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset; |
| 4547 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4548 | drv_ctx.ptr_outputbuffer[i].mmaped_size = |
| 4549 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4550 | privateAppData = appData; |
| 4551 | } |
| 4552 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 4553 | m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4554 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 4555 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 4556 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4557 | |
| 4558 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4559 | if (secure_mode) |
| 4560 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 4561 | //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4562 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i], |
| 4563 | sizeof (vdec_bufferpayload)); |
| 4564 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4565 | 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] | 4566 | drv_ctx.ptr_outputbuffer[i].bufferaddr, |
| 4567 | drv_ctx.ptr_outputbuffer[i].pmem_fd ); |
| 4568 | |
| 4569 | buf.index = i; |
| 4570 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4571 | buf.memory = V4L2_MEMORY_USERPTR; |
| 4572 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 4573 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 4574 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
| 4575 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
| 4576 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 4577 | plane[0].data_offset = 0; |
| 4578 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 4579 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 4580 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 4581 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
| 4582 | #ifdef USE_ION |
| 4583 | plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd; |
| 4584 | #endif |
| 4585 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 4586 | plane[extra_idx].data_offset = 0; |
| 4587 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4588 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4589 | return OMX_ErrorBadParameter; |
| 4590 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4591 | buf.m.planes = plane; |
| 4592 | buf.length = drv_ctx.num_planes; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4593 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4594 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4595 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4596 | /*TODO: How to handle this case */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4597 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4600 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4601 | enum v4l2_buf_type buf_type; |
| 4602 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4603 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4604 | return OMX_ErrorInsufficientResources; |
| 4605 | } else { |
| 4606 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4607 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4608 | } |
| 4609 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4610 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4611 | (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size; |
| 4612 | if (m_enable_android_native_buffers) { |
| 4613 | DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle); |
| 4614 | (*bufferHdr)->pBuffer = (OMX_U8 *)handle; |
| 4615 | } else { |
| 4616 | (*bufferHdr)->pBuffer = buff; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4617 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4618 | (*bufferHdr)->pAppPrivate = privateAppData; |
| 4619 | BITMASK_SET(&m_out_bm_count,i); |
| 4620 | } |
| 4621 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4625 | FUNCTION |
| 4626 | omx_vdec::use_input_heap_buffers |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4627 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4628 | DESCRIPTION |
| 4629 | OMX Use Buffer Heap allocation method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4630 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4631 | PARAMETERS |
| 4632 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4633 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4634 | RETURN VALUE |
| 4635 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4636 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4637 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4638 | OMX_ERRORTYPE omx_vdec::use_input_heap_buffers( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4639 | OMX_IN OMX_HANDLETYPE hComp, |
| 4640 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4641 | OMX_IN OMX_U32 port, |
| 4642 | OMX_IN OMX_PTR appData, |
| 4643 | OMX_IN OMX_U32 bytes, |
| 4644 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4645 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4646 | DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4647 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4648 | if (!m_inp_heap_ptr) |
| 4649 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) |
| 4650 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4651 | drv_ctx.ip_buf.actualcount); |
| 4652 | if (!m_phdr_pmem_ptr) |
| 4653 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) |
| 4654 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4655 | drv_ctx.ip_buf.actualcount); |
| 4656 | if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) { |
| 4657 | DEBUG_PRINT_ERROR("Insufficent memory"); |
| 4658 | eRet = OMX_ErrorInsufficientResources; |
| 4659 | } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) { |
| 4660 | input_use_buffer = true; |
| 4661 | memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE)); |
| 4662 | m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer; |
| 4663 | m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes; |
| 4664 | m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData; |
| 4665 | m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput; |
| 4666 | m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax; |
| 4667 | *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt]; |
| 4668 | 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] | 4669 | 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] | 4670 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt], |
| 4671 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4672 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4673 | return OMX_ErrorInsufficientResources; |
| 4674 | } |
| 4675 | m_in_alloc_cnt++; |
| 4676 | } else { |
| 4677 | DEBUG_PRINT_ERROR("All i/p buffers have been set!"); |
| 4678 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4679 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4680 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4684 | FUNCTION |
| 4685 | omx_vdec::UseBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4686 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4687 | DESCRIPTION |
| 4688 | OMX Use Buffer method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4689 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4690 | PARAMETERS |
| 4691 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4692 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4693 | RETURN VALUE |
| 4694 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4695 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4696 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4697 | OMX_ERRORTYPE omx_vdec::use_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4698 | OMX_IN OMX_HANDLETYPE hComp, |
| 4699 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4700 | OMX_IN OMX_U32 port, |
| 4701 | OMX_IN OMX_PTR appData, |
| 4702 | OMX_IN OMX_U32 bytes, |
| 4703 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4704 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4705 | OMX_ERRORTYPE error = OMX_ErrorNone; |
| 4706 | struct vdec_setbuffer_cmd setbuffers; |
| 4707 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4708 | if (bufferHdr == NULL || bytes == 0 || (!secure_mode && buffer == NULL)) { |
| 4709 | DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer); |
| 4710 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4711 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4712 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4713 | DEBUG_PRINT_ERROR("Use Buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4714 | return OMX_ErrorInvalidState; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4715 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4716 | if (port == OMX_CORE_INPUT_PORT_INDEX) |
| 4717 | error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer); |
| 4718 | else if (port == OMX_CORE_OUTPUT_PORT_INDEX) |
| 4719 | error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested |
| 4720 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4721 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4722 | error = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4723 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4724 | DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error); |
| 4725 | if (error == OMX_ErrorNone) { |
| 4726 | if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 4727 | // Send the callback now |
| 4728 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 4729 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
| 4730 | OMX_COMPONENT_GENERATE_EVENT); |
| 4731 | } |
| 4732 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated && |
| 4733 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 4734 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 4735 | post_event(OMX_CommandPortEnable, |
| 4736 | OMX_CORE_INPUT_PORT_INDEX, |
| 4737 | OMX_COMPONENT_GENERATE_EVENT); |
| 4738 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated && |
| 4739 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 4740 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 4741 | post_event(OMX_CommandPortEnable, |
| 4742 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 4743 | OMX_COMPONENT_GENERATE_EVENT); |
| 4744 | } |
| 4745 | } |
| 4746 | return error; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4750 | OMX_BUFFERHEADERTYPE *pmem_bufferHdr) |
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 | if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) { |
| 4753 | if (m_inp_heap_ptr[bufferindex].pBuffer) |
| 4754 | free(m_inp_heap_ptr[bufferindex].pBuffer); |
| 4755 | m_inp_heap_ptr[bufferindex].pBuffer = NULL; |
| 4756 | } |
| 4757 | if (pmem_bufferHdr) |
| 4758 | free_input_buffer(pmem_bufferHdr); |
| 4759 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4763 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4764 | unsigned int index = 0; |
| 4765 | if (bufferHdr == NULL || m_inp_mem_ptr == NULL) { |
| 4766 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4767 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4768 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4769 | index = bufferHdr - m_inp_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4770 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4771 | |
| 4772 | if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4773 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4774 | if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) { |
| 4775 | struct vdec_setbuffer_cmd setbuffers; |
| 4776 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 4777 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index], |
| 4778 | sizeof (vdec_bufferpayload)); |
| 4779 | if (!secure_mode) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4780 | DEBUG_PRINT_LOW("unmap the input buffer fd=%d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4781 | drv_ctx.ptr_inputbuffer[index].pmem_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4782 | DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4783 | drv_ctx.ptr_inputbuffer[index].mmaped_size, |
| 4784 | drv_ctx.ptr_inputbuffer[index].bufferaddr); |
| 4785 | munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr, |
| 4786 | drv_ctx.ptr_inputbuffer[index].mmaped_size); |
| 4787 | } |
| 4788 | close (drv_ctx.ptr_inputbuffer[index].pmem_fd); |
| 4789 | drv_ctx.ptr_inputbuffer[index].pmem_fd = -1; |
| 4790 | if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) { |
| 4791 | free(m_desc_buffer_ptr[index].buf_addr); |
| 4792 | m_desc_buffer_ptr[index].buf_addr = NULL; |
| 4793 | m_desc_buffer_ptr[index].desc_data_size = 0; |
| 4794 | } |
| 4795 | #ifdef USE_ION |
| 4796 | free_ion_memory(&drv_ctx.ip_buf_ion_info[index]); |
| 4797 | #endif |
| 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4805 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4806 | unsigned int index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4807 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4808 | if (bufferHdr == NULL || m_out_mem_ptr == NULL) { |
| 4809 | return OMX_ErrorBadParameter; |
| 4810 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4811 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4812 | index = bufferHdr - m_out_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4813 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4814 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4815 | if (index < drv_ctx.op_buf.actualcount |
| 4816 | && drv_ctx.ptr_outputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4817 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4818 | drv_ctx.ptr_outputbuffer[index].bufferaddr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4819 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4820 | struct vdec_setbuffer_cmd setbuffers; |
| 4821 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4822 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index], |
| 4823 | sizeof (vdec_bufferpayload)); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4824 | |
| 4825 | if (!dynamic_buf_mode) { |
Balamurugan Alagarsamy | e773c58 | 2014-12-17 15:10:25 +0530 | [diff] [blame] | 4826 | if (streaming[CAPTURE_PORT] && |
| 4827 | !(in_reconfig || BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING))) { |
| 4828 | if (stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
| 4829 | DEBUG_PRINT_ERROR("STREAMOFF Failed"); |
| 4830 | } else { |
| 4831 | DEBUG_PRINT_LOW("STREAMOFF Successful"); |
| 4832 | } |
| 4833 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4834 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4835 | if (m_enable_android_native_buffers) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4836 | if (!secure_mode) { |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4837 | if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) { |
| 4838 | munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr, |
| 4839 | drv_ctx.ptr_outputbuffer[index].mmaped_size); |
| 4840 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4841 | } |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4842 | drv_ctx.ptr_outputbuffer[index].pmem_fd = -1; |
| 4843 | } else { |
| 4844 | #endif |
| 4845 | if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) { |
| 4846 | if (!secure_mode) { |
| 4847 | DEBUG_PRINT_LOW("\n unmap the output buffer fd = %d", |
| 4848 | drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4849 | DEBUG_PRINT_LOW("\n unmap the ouput buffer size=%d address = %p", |
| 4850 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount, |
| 4851 | drv_ctx.ptr_outputbuffer[0].bufferaddr); |
| 4852 | munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr, |
| 4853 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount); |
| 4854 | } |
| 4855 | close (drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4856 | drv_ctx.ptr_outputbuffer[0].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4857 | #ifdef USE_ION |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4858 | free_ion_memory(&drv_ctx.op_buf_ion_info[0]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4859 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4860 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4861 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4862 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4863 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4864 | } //!dynamic_buf_mode |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4865 | if (release_output_done()) { |
| 4866 | free_extradata(); |
| 4867 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4868 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4869 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4870 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4871 | |
| 4872 | } |
| 4873 | |
| 4874 | OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4875 | OMX_BUFFERHEADERTYPE **bufferHdr, |
| 4876 | OMX_U32 port, |
| 4877 | OMX_PTR appData, |
| 4878 | OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4879 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4880 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4881 | unsigned char *buf_addr = NULL; |
| 4882 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4883 | unsigned i = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4884 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4885 | /* Sanity Check*/ |
| 4886 | if (bufferHdr == NULL) { |
| 4887 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4888 | } |
| 4889 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4890 | if (m_inp_heap_ptr == NULL) { |
| 4891 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4892 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4893 | drv_ctx.ip_buf.actualcount); |
| 4894 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \ |
| 4895 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4896 | drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4897 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4898 | if (m_inp_heap_ptr == NULL || m_phdr_pmem_ptr == NULL) { |
| 4899 | DEBUG_PRINT_ERROR("m_inp_heap_ptr or m_phdr_pmem_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4900 | return OMX_ErrorInsufficientResources; |
| 4901 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4902 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4903 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4904 | /*Find a Free index*/ |
| 4905 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 4906 | if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4907 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4908 | break; |
| 4909 | } |
| 4910 | } |
| 4911 | |
| 4912 | if (i < drv_ctx.ip_buf.actualcount) { |
| 4913 | buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size); |
| 4914 | |
| 4915 | if (buf_addr == NULL) { |
| 4916 | return OMX_ErrorInsufficientResources; |
| 4917 | } |
| 4918 | |
| 4919 | *bufferHdr = (m_inp_heap_ptr + i); |
| 4920 | input = *bufferHdr; |
| 4921 | BITMASK_SET(&m_heap_inp_bm_count,i); |
| 4922 | |
| 4923 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 4924 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 4925 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 4926 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 4927 | input->pAppPrivate = appData; |
| 4928 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4929 | DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4930 | 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] | 4931 | 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] | 4932 | /*Add the Buffers to freeq*/ |
| 4933 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i], |
| 4934 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4935 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4936 | return OMX_ErrorInsufficientResources; |
| 4937 | } |
| 4938 | } else { |
| 4939 | return OMX_ErrorBadParameter; |
| 4940 | } |
| 4941 | |
| 4942 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4943 | |
| 4944 | } |
| 4945 | |
| 4946 | |
| 4947 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4948 | FUNCTION |
| 4949 | omx_vdec::AllocateInputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4950 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4951 | DESCRIPTION |
| 4952 | Helper function for allocate buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4953 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4954 | PARAMETERS |
| 4955 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4956 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4957 | RETURN VALUE |
| 4958 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4959 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4960 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4961 | OMX_ERRORTYPE omx_vdec::allocate_input_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4962 | OMX_IN OMX_HANDLETYPE hComp, |
| 4963 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4964 | OMX_IN OMX_U32 port, |
| 4965 | OMX_IN OMX_PTR appData, |
| 4966 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4967 | { |
| 4968 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4969 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4970 | struct vdec_setbuffer_cmd setbuffers; |
| 4971 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4972 | unsigned i = 0; |
| 4973 | unsigned char *buf_addr = NULL; |
| 4974 | int pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4975 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4976 | if (bytes != drv_ctx.ip_buf.buffer_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4977 | DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4978 | bytes, drv_ctx.ip_buf.buffer_size); |
| 4979 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4980 | } |
| 4981 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4982 | if (!m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4983 | DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4984 | drv_ctx.ip_buf.actualcount, |
| 4985 | drv_ctx.ip_buf.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4986 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4987 | m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4988 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount); |
| 4989 | |
| 4990 | if (m_inp_mem_ptr == NULL) { |
| 4991 | return OMX_ErrorInsufficientResources; |
| 4992 | } |
| 4993 | |
| 4994 | drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \ |
| 4995 | calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount); |
| 4996 | |
| 4997 | if (drv_ctx.ptr_inputbuffer == NULL) { |
| 4998 | return OMX_ErrorInsufficientResources; |
| 4999 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5000 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5001 | drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \ |
| 5002 | calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5003 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5004 | if (drv_ctx.ip_buf_ion_info == NULL) { |
| 5005 | return OMX_ErrorInsufficientResources; |
| 5006 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5007 | #endif |
| 5008 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5009 | for (i=0; i < drv_ctx.ip_buf.actualcount; i++) { |
| 5010 | drv_ctx.ptr_inputbuffer [i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5011 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5012 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5013 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5014 | } |
| 5015 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5016 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5017 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 5018 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5019 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5020 | break; |
| 5021 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5022 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5023 | |
| 5024 | if (i < drv_ctx.ip_buf.actualcount) { |
| 5025 | struct v4l2_buffer buf; |
| 5026 | struct v4l2_plane plane; |
| 5027 | int rc; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5028 | DEBUG_PRINT_LOW("Allocate input Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5029 | #ifdef USE_ION |
| 5030 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 5031 | drv_ctx.ip_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 5032 | &drv_ctx.ip_buf_ion_info[i].ion_alloc_data, |
| 5033 | &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 5034 | if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) { |
| 5035 | return OMX_ErrorInsufficientResources; |
| 5036 | } |
| 5037 | pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd; |
| 5038 | #else |
| 5039 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 5040 | |
| 5041 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5042 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5043 | return OMX_ErrorInsufficientResources; |
| 5044 | } |
| 5045 | |
| 5046 | if (pmem_fd == 0) { |
| 5047 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 5048 | |
| 5049 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5050 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5051 | return OMX_ErrorInsufficientResources; |
| 5052 | } |
| 5053 | } |
| 5054 | |
| 5055 | if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size, |
| 5056 | drv_ctx.ip_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5057 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5058 | close(pmem_fd); |
| 5059 | return OMX_ErrorInsufficientResources; |
| 5060 | } |
| 5061 | #endif |
| 5062 | if (!secure_mode) { |
| 5063 | buf_addr = (unsigned char *)mmap(NULL, |
| 5064 | drv_ctx.ip_buf.buffer_size, |
| 5065 | PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0); |
| 5066 | |
| 5067 | if (buf_addr == MAP_FAILED) { |
| 5068 | close(pmem_fd); |
| 5069 | #ifdef USE_ION |
| 5070 | free_ion_memory(&drv_ctx.ip_buf_ion_info[i]); |
| 5071 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5072 | DEBUG_PRINT_ERROR("Map Failed to allocate input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5073 | return OMX_ErrorInsufficientResources; |
| 5074 | } |
| 5075 | } |
| 5076 | *bufferHdr = (m_inp_mem_ptr + i); |
| 5077 | if (secure_mode) |
| 5078 | drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr; |
| 5079 | else |
| 5080 | drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr; |
| 5081 | drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd; |
| 5082 | drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size; |
| 5083 | drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size; |
| 5084 | drv_ctx.ptr_inputbuffer [i].offset = 0; |
| 5085 | |
| 5086 | |
| 5087 | buf.index = i; |
| 5088 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5089 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5090 | plane.bytesused = 0; |
| 5091 | plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size; |
| 5092 | plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr; |
| 5093 | plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 5094 | plane.reserved[1] = 0; |
| 5095 | plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset; |
| 5096 | buf.m.planes = &plane; |
| 5097 | buf.length = 1; |
| 5098 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5099 | DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5100 | drv_ctx.ptr_inputbuffer[i].bufferaddr); |
| 5101 | |
| 5102 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5103 | |
| 5104 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5105 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5106 | /*TODO: How to handle this case */ |
| 5107 | return OMX_ErrorInsufficientResources; |
| 5108 | } |
| 5109 | |
| 5110 | input = *bufferHdr; |
| 5111 | BITMASK_SET(&m_inp_bm_count,i); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5112 | DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5113 | if (secure_mode) |
| 5114 | input->pBuffer = (OMX_U8 *)drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 5115 | else |
| 5116 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 5117 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5118 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5119 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 5120 | input->pAppPrivate = appData; |
| 5121 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
| 5122 | input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i]; |
| 5123 | |
| 5124 | if (drv_ctx.disable_dmx) { |
| 5125 | eRet = allocate_desc_buffer(i); |
| 5126 | } |
| 5127 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5128 | DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5129 | eRet = OMX_ErrorInsufficientResources; |
| 5130 | } |
| 5131 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | |
| 5135 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5136 | FUNCTION |
| 5137 | omx_vdec::AllocateOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5138 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5139 | DESCRIPTION |
| 5140 | Helper fn for AllocateBuffer in the output pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5141 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5142 | PARAMETERS |
| 5143 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5144 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5145 | RETURN VALUE |
| 5146 | OMX Error None if everything went well. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5147 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5148 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5149 | OMX_ERRORTYPE omx_vdec::allocate_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5150 | OMX_IN OMX_HANDLETYPE hComp, |
| 5151 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5152 | OMX_IN OMX_U32 port, |
| 5153 | OMX_IN OMX_PTR appData, |
| 5154 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5155 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5156 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5157 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 5158 | unsigned i= 0; // Temporary counter |
| 5159 | struct vdec_setbuffer_cmd setbuffers; |
| 5160 | int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5161 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5162 | int ion_device_fd =-1; |
| 5163 | struct ion_allocation_data ion_alloc_data; |
| 5164 | struct ion_fd_data fd_ion_data; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5165 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5166 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5167 | DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5168 | drv_ctx.op_buf.actualcount, |
| 5169 | drv_ctx.op_buf.buffer_size); |
| 5170 | int nBufHdrSize = 0; |
| 5171 | int nPlatformEntrySize = 0; |
| 5172 | int nPlatformListSize = 0; |
| 5173 | int nPMEMInfoSize = 0; |
| 5174 | int pmem_fd = -1; |
| 5175 | unsigned char *pmem_baseaddress = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5176 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5177 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 5178 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 5179 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5180 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5181 | DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5182 | drv_ctx.op_buf.actualcount); |
| 5183 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 5184 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5185 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5186 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 5187 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 5188 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 5189 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 5190 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 5191 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5192 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5193 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5194 | sizeof(OMX_BUFFERHEADERTYPE), |
| 5195 | nPMEMInfoSize, |
| 5196 | nPlatformListSize); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5197 | DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5198 | drv_ctx.op_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5199 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5200 | ion_device_fd = alloc_map_ion_memory( |
| 5201 | drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount, |
| 5202 | drv_ctx.op_buf.alignment, |
| 5203 | &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 5204 | if (ion_device_fd < 0) { |
| 5205 | return OMX_ErrorInsufficientResources; |
| 5206 | } |
| 5207 | pmem_fd = fd_ion_data.fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5208 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5209 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5210 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5211 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5212 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5213 | drv_ctx.op_buf.buffer_size); |
| 5214 | return OMX_ErrorInsufficientResources; |
| 5215 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5216 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5217 | if (pmem_fd == 0) { |
| 5218 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5219 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5220 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5221 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5222 | drv_ctx.op_buf.buffer_size); |
| 5223 | return OMX_ErrorInsufficientResources; |
| 5224 | } |
| 5225 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5226 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5227 | if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size * |
| 5228 | drv_ctx.op_buf.actualcount, |
| 5229 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5230 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5231 | close(pmem_fd); |
| 5232 | return OMX_ErrorInsufficientResources; |
| 5233 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5234 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5235 | if (!secure_mode) { |
| 5236 | pmem_baseaddress = (unsigned char *)mmap(NULL, |
| 5237 | (drv_ctx.op_buf.buffer_size * |
| 5238 | drv_ctx.op_buf.actualcount), |
| 5239 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0); |
| 5240 | if (pmem_baseaddress == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5241 | DEBUG_PRINT_ERROR("MMAP failed for Size %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5242 | drv_ctx.op_buf.buffer_size); |
| 5243 | close(pmem_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5244 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5245 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5246 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5247 | return OMX_ErrorInsufficientResources; |
| 5248 | } |
| 5249 | } |
| 5250 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 5251 | // Alloc mem for platform specific info |
| 5252 | char *pPtr=NULL; |
| 5253 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 5254 | nPMEMInfoSize,1); |
| 5255 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\ |
| 5256 | calloc (sizeof(struct vdec_bufferpayload), |
| 5257 | drv_ctx.op_buf.actualcount); |
| 5258 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 5259 | calloc (sizeof (struct vdec_output_frameinfo), |
| 5260 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5261 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 5262 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer "); |
| 5263 | return OMX_ErrorInsufficientResources; |
| 5264 | } |
| 5265 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5266 | #ifdef USE_ION |
| 5267 | drv_ctx.op_buf_ion_info = (struct vdec_ion *)\ |
| 5268 | calloc (sizeof(struct vdec_ion), |
| 5269 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5270 | if (!drv_ctx.op_buf_ion_info) { |
| 5271 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 5272 | return OMX_ErrorInsufficientResources; |
| 5273 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5274 | #endif |
| 5275 | |
| 5276 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 5277 | && drv_ctx.ptr_respbuffer) { |
| 5278 | drv_ctx.ptr_outputbuffer[0].mmaped_size = |
| 5279 | (drv_ctx.op_buf.buffer_size * |
| 5280 | drv_ctx.op_buf.actualcount); |
| 5281 | bufHdr = m_out_mem_ptr; |
| 5282 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 5283 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 5284 | (((char *) m_platform_list) + nPlatformListSize); |
| 5285 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 5286 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 5287 | pPlatformList = m_platform_list; |
| 5288 | pPlatformEntry = m_platform_entry; |
| 5289 | pPMEMInfo = m_pmem_info; |
| 5290 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5291 | 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] | 5292 | |
| 5293 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5294 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry); |
| 5295 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5296 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 5297 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5298 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5299 | // Set the values when we determine the right HxW param |
| 5300 | bufHdr->nAllocLen = bytes; |
| 5301 | bufHdr->nFilledLen = 0; |
| 5302 | bufHdr->pAppPrivate = appData; |
| 5303 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 5304 | // Platform specific PMEM Information |
| 5305 | // Initialize the Platform Entry |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5306 | //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5307 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 5308 | pPlatformEntry->entry = pPMEMInfo; |
| 5309 | // Initialize the Platform List |
| 5310 | pPlatformList->nEntries = 1; |
| 5311 | pPlatformList->entryList = pPlatformEntry; |
| 5312 | // Keep pBuffer NULL till vdec is opened |
| 5313 | bufHdr->pBuffer = NULL; |
| 5314 | bufHdr->nOffset = 0; |
| 5315 | |
| 5316 | pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i; |
| 5317 | pPMEMInfo->pmem_fd = 0; |
| 5318 | bufHdr->pPlatformPrivate = pPlatformList; |
| 5319 | |
| 5320 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd; |
| 5321 | m_pmem_info[i].pmem_fd = pmem_fd; |
| 5322 | #ifdef USE_ION |
| 5323 | drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd; |
| 5324 | drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data; |
| 5325 | drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data; |
| 5326 | #endif |
| 5327 | |
| 5328 | /*Create a mapping between buffers*/ |
| 5329 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 5330 | drv_ctx.ptr_respbuffer[i].client_data = (void *)\ |
| 5331 | &drv_ctx.ptr_outputbuffer[i]; |
| 5332 | drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i; |
| 5333 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 5334 | pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 5335 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 5336 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 5337 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5338 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5339 | DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5340 | pmem_fd, drv_ctx.ptr_outputbuffer[i].offset, |
| 5341 | drv_ctx.ptr_outputbuffer[i].bufferaddr); |
| 5342 | // Move the buffer and buffer header pointers |
| 5343 | bufHdr++; |
| 5344 | pPMEMInfo++; |
| 5345 | pPlatformEntry++; |
| 5346 | pPlatformList++; |
| 5347 | } |
| 5348 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5349 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5350 | m_out_mem_ptr, pPtr); |
| 5351 | if (m_out_mem_ptr) { |
| 5352 | free(m_out_mem_ptr); |
| 5353 | m_out_mem_ptr = NULL; |
| 5354 | } |
| 5355 | if (pPtr) { |
| 5356 | free(pPtr); |
| 5357 | pPtr = NULL; |
| 5358 | } |
| 5359 | if (drv_ctx.ptr_outputbuffer) { |
| 5360 | free(drv_ctx.ptr_outputbuffer); |
| 5361 | drv_ctx.ptr_outputbuffer = NULL; |
| 5362 | } |
| 5363 | if (drv_ctx.ptr_respbuffer) { |
| 5364 | free(drv_ctx.ptr_respbuffer); |
| 5365 | drv_ctx.ptr_respbuffer = NULL; |
| 5366 | } |
| 5367 | #ifdef USE_ION |
| 5368 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5369 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5370 | free(drv_ctx.op_buf_ion_info); |
| 5371 | drv_ctx.op_buf_ion_info = NULL; |
| 5372 | } |
| 5373 | #endif |
| 5374 | eRet = OMX_ErrorInsufficientResources; |
| 5375 | } |
| 5376 | if (eRet == OMX_ErrorNone) |
| 5377 | eRet = allocate_extradata(); |
| 5378 | } |
| 5379 | |
| 5380 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 5381 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5382 | DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5383 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5384 | } |
| 5385 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5386 | |
| 5387 | if (eRet == OMX_ErrorNone) { |
| 5388 | if (i < drv_ctx.op_buf.actualcount) { |
| 5389 | struct v4l2_buffer buf; |
| 5390 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 5391 | int rc; |
| 5392 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 5393 | |
| 5394 | drv_ctx.ptr_outputbuffer[i].buffer_len = |
| 5395 | drv_ctx.op_buf.buffer_size; |
| 5396 | |
| 5397 | *bufferHdr = (m_out_mem_ptr + i ); |
| 5398 | if (secure_mode) { |
| 5399 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 5400 | } |
| 5401 | drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 5402 | |
| 5403 | buf.index = i; |
| 5404 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5405 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5406 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 5407 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 5408 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5409 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5410 | 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] | 5411 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5412 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 5413 | plane[0].data_offset = 0; |
| 5414 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 5415 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 5416 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 5417 | 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] | 5418 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5419 | 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] | 5420 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5421 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 5422 | plane[extra_idx].data_offset = 0; |
| 5423 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5424 | DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5425 | return OMX_ErrorBadParameter; |
| 5426 | } |
| 5427 | buf.m.planes = plane; |
| 5428 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5429 | 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] | 5430 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5431 | if (rc) { |
| 5432 | /*TODO: How to handle this case */ |
| 5433 | return OMX_ErrorInsufficientResources; |
| 5434 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5435 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5436 | if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) { |
| 5437 | enum v4l2_buf_type buf_type; |
| 5438 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5439 | rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5440 | if (rc) { |
| 5441 | return OMX_ErrorInsufficientResources; |
| 5442 | } else { |
| 5443 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5444 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5445 | } |
| 5446 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5447 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5448 | (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr; |
| 5449 | (*bufferHdr)->pAppPrivate = appData; |
| 5450 | BITMASK_SET(&m_out_bm_count,i); |
| 5451 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5452 | DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5453 | eRet = OMX_ErrorInsufficientResources; |
| 5454 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5455 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5456 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5457 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | |
| 5461 | // AllocateBuffer -- API Call |
| 5462 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5463 | FUNCTION |
| 5464 | omx_vdec::AllocateBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5465 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5466 | DESCRIPTION |
| 5467 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5468 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5469 | PARAMETERS |
| 5470 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5471 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5472 | RETURN VALUE |
| 5473 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5474 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5475 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5476 | OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5477 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5478 | OMX_IN OMX_U32 port, |
| 5479 | OMX_IN OMX_PTR appData, |
| 5480 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5481 | { |
| 5482 | unsigned i = 0; |
| 5483 | OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type |
| 5484 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5485 | DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5486 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5487 | DEBUG_PRINT_ERROR("Allocate Buf in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5488 | return OMX_ErrorInvalidState; |
| 5489 | } |
| 5490 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5491 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5492 | if (arbitrary_bytes) { |
| 5493 | eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes); |
| 5494 | } else { |
| 5495 | eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes); |
| 5496 | } |
| 5497 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5498 | eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port, |
| 5499 | appData,bytes); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5500 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5501 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5502 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5503 | } |
| 5504 | DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5505 | if (eRet == OMX_ErrorNone) { |
| 5506 | if (allocate_done()) { |
| 5507 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5508 | // Send the callback now |
| 5509 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 5510 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5511 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5512 | } |
| 5513 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5514 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) { |
| 5515 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 5516 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 5517 | post_event(OMX_CommandPortEnable, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5518 | OMX_CORE_INPUT_PORT_INDEX, |
| 5519 | OMX_COMPONENT_GENERATE_EVENT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5520 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5521 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5522 | if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) { |
| 5523 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 5524 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5525 | post_event(OMX_CommandPortEnable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5526 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5527 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5528 | } |
| 5529 | } |
| 5530 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5531 | DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5532 | return eRet; |
| 5533 | } |
| 5534 | |
| 5535 | // Free Buffer - API call |
| 5536 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5537 | FUNCTION |
| 5538 | omx_vdec::FreeBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5539 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5540 | DESCRIPTION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5541 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5542 | PARAMETERS |
| 5543 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5544 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5545 | RETURN VALUE |
| 5546 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5547 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5548 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5549 | OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5550 | OMX_IN OMX_U32 port, |
| 5551 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5552 | { |
| 5553 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5554 | unsigned int nPortIndex; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5555 | DEBUG_PRINT_LOW("In for decoder free_buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5556 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5557 | if (m_state == OMX_StateIdle && |
| 5558 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5559 | DEBUG_PRINT_LOW(" free buffer while Component in Loading pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5560 | } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)|| |
| 5561 | (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5562 | DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5563 | } else if ((port == OMX_CORE_INPUT_PORT_INDEX && |
| 5564 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) || |
| 5565 | (port == OMX_CORE_OUTPUT_PORT_INDEX && |
| 5566 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5567 | DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5568 | } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5569 | 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] | 5570 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5571 | OMX_ErrorPortUnpopulated, |
| 5572 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5573 | |
| 5574 | return OMX_ErrorIncorrectStateOperation; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5575 | } else if (m_state != OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5576 | DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5577 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5578 | OMX_ErrorPortUnpopulated, |
| 5579 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5582 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5583 | /*Check if arbitrary bytes*/ |
| 5584 | if (!arbitrary_bytes && !input_use_buffer) |
| 5585 | nPortIndex = buffer - m_inp_mem_ptr; |
| 5586 | else |
| 5587 | nPortIndex = buffer - m_inp_heap_ptr; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5588 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5589 | 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] | 5590 | if (nPortIndex < drv_ctx.ip_buf.actualcount) { |
| 5591 | // Clear the bit associated with it. |
| 5592 | BITMASK_CLEAR(&m_inp_bm_count,nPortIndex); |
| 5593 | BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex); |
| 5594 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5595 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5596 | DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5597 | if (m_phdr_pmem_ptr) |
| 5598 | free_input_buffer(m_phdr_pmem_ptr[nPortIndex]); |
| 5599 | } else { |
| 5600 | if (arbitrary_bytes) { |
| 5601 | if (m_phdr_pmem_ptr) |
| 5602 | free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]); |
| 5603 | else |
| 5604 | free_input_buffer(nPortIndex,NULL); |
| 5605 | } else |
| 5606 | free_input_buffer(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5607 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5608 | m_inp_bPopulated = OMX_FALSE; |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5609 | if(release_input_done()) |
| 5610 | release_buffers(this, VDEC_BUFFER_TYPE_INPUT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5611 | /*Free the Buffer Header*/ |
| 5612 | if (release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5613 | DEBUG_PRINT_HIGH("ALL input buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5614 | free_input_buffer_header(); |
| 5615 | } |
| 5616 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5617 | DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5618 | eRet = OMX_ErrorBadPortIndex; |
| 5619 | } |
| 5620 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5621 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING) |
| 5622 | && release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5623 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5624 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 5625 | post_event(OMX_CommandPortDisable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5626 | OMX_CORE_INPUT_PORT_INDEX, |
| 5627 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5628 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5629 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5630 | // check if the buffer is valid |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5631 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5632 | if (nPortIndex < drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5633 | 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] | 5634 | // Clear the bit associated with it. |
| 5635 | BITMASK_CLEAR(&m_out_bm_count,nPortIndex); |
| 5636 | m_out_bPopulated = OMX_FALSE; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5637 | client_buffers.free_output_buffer (buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5638 | |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5639 | if(release_output_done()) { |
| 5640 | release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT); |
| 5641 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5642 | if (release_output_done()) { |
| 5643 | free_output_buffer_header(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5644 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5645 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5646 | DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5647 | eRet = OMX_ErrorBadPortIndex; |
| 5648 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5649 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING) |
| 5650 | && release_output_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5651 | DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5652 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5653 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5654 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5655 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5656 | if (m_enable_android_native_buffers) { |
| 5657 | DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers"); |
| 5658 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 5659 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5660 | #endif |
| 5661 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5662 | post_event(OMX_CommandPortDisable, |
| 5663 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5664 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5665 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5666 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5667 | eRet = OMX_ErrorBadPortIndex; |
| 5668 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5669 | if ((eRet == OMX_ErrorNone) && |
| 5670 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
| 5671 | if (release_done()) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5672 | // Send the callback now |
| 5673 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING); |
| 5674 | post_event(OMX_CommandStateSet, OMX_StateLoaded, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5675 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5676 | } |
| 5677 | } |
| 5678 | return eRet; |
| 5679 | } |
| 5680 | |
| 5681 | |
| 5682 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5683 | FUNCTION |
| 5684 | omx_vdec::EmptyThisBuffer |
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 | DESCRIPTION |
| 5687 | This routine is used to push the encoded video frames to |
| 5688 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5689 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5690 | PARAMETERS |
| 5691 | None. |
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 | RETURN VALUE |
| 5694 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5695 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5696 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5697 | OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5698 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5699 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5700 | OMX_ERRORTYPE ret1 = OMX_ErrorNone; |
| 5701 | unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5702 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5703 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5704 | DEBUG_PRINT_ERROR("Empty this buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5705 | return OMX_ErrorInvalidState; |
| 5706 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5707 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5708 | if (buffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5709 | DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5710 | return OMX_ErrorBadParameter; |
| 5711 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5712 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5713 | if (!m_inp_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5714 | DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5715 | return OMX_ErrorIncorrectStateOperation; |
| 5716 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5717 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5718 | if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5719 | DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5720 | return OMX_ErrorBadPortIndex; |
| 5721 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5722 | |
| 5723 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5724 | if (iDivXDrmDecrypt) { |
| 5725 | OMX_ERRORTYPE drmErr = iDivXDrmDecrypt->Decrypt(buffer); |
| 5726 | if (drmErr != OMX_ErrorNone) { |
| 5727 | // this error can be ignored |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5728 | DEBUG_PRINT_LOW("ERROR:iDivXDrmDecrypt->Decrypt %d", drmErr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5729 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5730 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5731 | #endif //_ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5732 | if (perf_flag) { |
| 5733 | if (!latency) { |
| 5734 | dec_time.stop(); |
| 5735 | latency = dec_time.processing_time_us(); |
| 5736 | dec_time.start(); |
| 5737 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5738 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5739 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5740 | if (arbitrary_bytes) { |
| 5741 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5742 | } else { |
| 5743 | if (input_use_buffer == true) { |
| 5744 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5745 | m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen; |
| 5746 | m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp; |
| 5747 | m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags; |
| 5748 | buffer = &m_inp_mem_ptr[nBufferIndex]; |
| 5749 | DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu", |
| 5750 | &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen); |
| 5751 | } else { |
| 5752 | nBufferIndex = buffer - m_inp_mem_ptr; |
| 5753 | } |
| 5754 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5755 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5756 | if (nBufferIndex > drv_ctx.ip_buf.actualcount ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5757 | DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5758 | return OMX_ErrorBadParameter; |
| 5759 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5760 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 5761 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 5762 | codec_config_flag = true; |
| 5763 | DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__); |
| 5764 | } |
| 5765 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5766 | DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)", |
| 5767 | buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen); |
| 5768 | if (arbitrary_bytes) { |
| 5769 | post_event ((unsigned)hComp,(unsigned)buffer, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5770 | OMX_COMPONENT_GENERATE_ETB_ARBITRARY); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5771 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5772 | post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB); |
| 5773 | } |
Praveen Chavan | ece713f | 2014-12-10 18:00:04 -0800 | [diff] [blame] | 5774 | time_stamp_dts.insert_timestamp(buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5775 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5776 | } |
| 5777 | |
| 5778 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5779 | FUNCTION |
| 5780 | omx_vdec::empty_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5781 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5782 | DESCRIPTION |
| 5783 | This routine is used to push the encoded video frames to |
| 5784 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5785 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5786 | PARAMETERS |
| 5787 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5788 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5789 | RETURN VALUE |
| 5790 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5791 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5792 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5793 | 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] | 5794 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5795 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5796 | int push_cnt = 0,i=0; |
| 5797 | unsigned nPortIndex = 0; |
| 5798 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 5799 | struct vdec_input_frameinfo frameinfo; |
| 5800 | struct vdec_bufferpayload *temp_buffer; |
| 5801 | struct vdec_seqheader seq_header; |
| 5802 | bool port_setting_changed = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5803 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5804 | /*Should we generate a Aync error event*/ |
| 5805 | if (buffer == NULL || buffer->pInputPortPrivate == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5806 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5807 | return OMX_ErrorBadParameter; |
| 5808 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5809 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5810 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5811 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5812 | if (nPortIndex > drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5813 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5814 | nPortIndex); |
| 5815 | return OMX_ErrorBadParameter; |
| 5816 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5817 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5818 | pending_input_buffers++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5819 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5820 | /* return zero length and not an EOS buffer */ |
| 5821 | if (!arbitrary_bytes && (buffer->nFilledLen == 0) && |
| 5822 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5823 | DEBUG_PRINT_HIGH("return zero legth buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5824 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5825 | OMX_COMPONENT_GENERATE_EBD); |
| 5826 | return OMX_ErrorNone; |
| 5827 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5828 | |
c_sridur | 0af9cef | 2015-02-05 12:07:17 +0530 | [diff] [blame] | 5829 | if (input_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5830 | DEBUG_PRINT_LOW("Flush in progress return buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5831 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5832 | OMX_COMPONENT_GENERATE_EBD); |
| 5833 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5834 | } |
| 5835 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5836 | temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5837 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 5838 | 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] | 5839 | return OMX_ErrorBadParameter; |
| 5840 | } |
| 5841 | /* If its first frame, H264 codec and reject is true, then parse the nal |
| 5842 | and get the profile. Based on this, reject the clip playback */ |
| 5843 | if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 && |
| 5844 | m_reject_avc_1080p_mp) { |
| 5845 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5846 | DEBUG_PRINT_ERROR("Parse nal to get the profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5847 | h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen, |
| 5848 | NALU_TYPE_SPS); |
| 5849 | m_profile = h264_parser->get_profile(); |
| 5850 | ret = is_video_session_supported(); |
| 5851 | if (ret) { |
| 5852 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD); |
| 5853 | post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT); |
| 5854 | /* Move the state to Invalid to avoid queueing of pending ETB to the driver */ |
| 5855 | m_state = OMX_StateInvalid; |
| 5856 | return OMX_ErrorNone; |
| 5857 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5858 | } |
| 5859 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5860 | DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5861 | /*for use buffer we need to memcpy the data*/ |
| 5862 | temp_buffer->buffer_len = buffer->nFilledLen; |
| 5863 | |
| 5864 | if (input_use_buffer) { |
| 5865 | if (buffer->nFilledLen <= temp_buffer->buffer_len) { |
| 5866 | if (arbitrary_bytes) { |
| 5867 | memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen); |
| 5868 | } else { |
| 5869 | memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset), |
| 5870 | buffer->nFilledLen); |
| 5871 | } |
| 5872 | } else { |
| 5873 | return OMX_ErrorBadParameter; |
| 5874 | } |
| 5875 | |
| 5876 | } |
| 5877 | |
| 5878 | frameinfo.bufferaddr = temp_buffer->bufferaddr; |
| 5879 | frameinfo.client_data = (void *) buffer; |
| 5880 | frameinfo.datalen = temp_buffer->buffer_len; |
| 5881 | frameinfo.flags = 0; |
| 5882 | frameinfo.offset = buffer->nOffset; |
| 5883 | frameinfo.pmem_fd = temp_buffer->pmem_fd; |
| 5884 | frameinfo.pmem_offset = temp_buffer->offset; |
| 5885 | frameinfo.timestamp = buffer->nTimeStamp; |
| 5886 | if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) { |
| 5887 | DEBUG_PRINT_LOW("ETB: dmx enabled"); |
| 5888 | if (m_demux_entries == 0) { |
| 5889 | extract_demux_addr_offsets(buffer); |
| 5890 | } |
| 5891 | |
| 5892 | DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries); |
| 5893 | handle_demux_data(buffer); |
| 5894 | frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr; |
| 5895 | frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size; |
| 5896 | } else { |
| 5897 | frameinfo.desc_addr = NULL; |
| 5898 | frameinfo.desc_size = 0; |
| 5899 | } |
| 5900 | if (!arbitrary_bytes) { |
| 5901 | frameinfo.flags |= buffer->nFlags; |
| 5902 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5903 | |
| 5904 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5905 | if (m_debug_timestamp) { |
| 5906 | if (arbitrary_bytes) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5907 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5908 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5909 | } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5910 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5911 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5912 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5913 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5914 | #endif |
| 5915 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5916 | log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5917 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5918 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5919 | frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5920 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5921 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5922 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5923 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5924 | 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] | 5925 | frameinfo.flags |= VDEC_BUFFERFLAG_EOS; |
| 5926 | h264_scratch.nFilledLen = 0; |
| 5927 | nal_count = 0; |
| 5928 | look_ahead_nal = false; |
| 5929 | frame_count = 0; |
| 5930 | if (m_frame_parser.mutils) |
| 5931 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 5932 | m_frame_parser.flush(); |
| 5933 | h264_last_au_ts = LLONG_MAX; |
| 5934 | h264_last_au_flags = 0; |
| 5935 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 5936 | m_demux_entries = 0; |
| 5937 | } |
| 5938 | struct v4l2_buffer buf; |
| 5939 | struct v4l2_plane plane; |
| 5940 | memset( (void *)&buf, 0, sizeof(buf)); |
| 5941 | memset( (void *)&plane, 0, sizeof(plane)); |
| 5942 | int rc; |
| 5943 | unsigned long print_count; |
| 5944 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 5945 | buf.flags = V4L2_QCOM_BUF_FLAG_EOS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5946 | DEBUG_PRINT_HIGH("INPUT EOS reached") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5947 | } |
| 5948 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5949 | buf.index = nPortIndex; |
| 5950 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5951 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5952 | plane.bytesused = temp_buffer->buffer_len; |
| 5953 | plane.length = drv_ctx.ip_buf.buffer_size; |
| 5954 | plane.m.userptr = (unsigned long)temp_buffer->bufferaddr - |
| 5955 | (unsigned long)temp_buffer->offset; |
| 5956 | plane.reserved[0] = temp_buffer->pmem_fd; |
| 5957 | plane.reserved[1] = temp_buffer->offset; |
| 5958 | plane.data_offset = 0; |
| 5959 | buf.m.planes = &plane; |
| 5960 | buf.length = 1; |
| 5961 | if (frameinfo.timestamp >= LLONG_MAX) { |
| 5962 | buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID; |
| 5963 | } |
| 5964 | //assumption is that timestamp is in milliseconds |
| 5965 | buf.timestamp.tv_sec = frameinfo.timestamp / 1000000; |
| 5966 | buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000); |
| 5967 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0; |
| 5968 | 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] | 5969 | |
Pushkaraj Patil | 20bd6bf | 2014-12-22 19:33:08 +0530 | [diff] [blame] | 5970 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 5971 | DEBUG_PRINT_LOW("Increment codec_config buffer counter"); |
| 5972 | android_atomic_inc(&m_queued_codec_config_count); |
| 5973 | } |
| 5974 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5975 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 5976 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5977 | DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5978 | return OMX_ErrorHardware; |
| 5979 | } |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 5980 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 5981 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 5982 | codec_config_flag = false; |
| 5983 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5984 | if (!streaming[OUTPUT_PORT]) { |
| 5985 | enum v4l2_buf_type buf_type; |
| 5986 | int ret,r; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 5987 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5988 | buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5989 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5990 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5991 | if (!ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5992 | DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5993 | streaming[OUTPUT_PORT] = true; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 5994 | } else if (errno == EBUSY) { |
| 5995 | DEBUG_PRINT_ERROR("Failed to call stream on OUTPUT due to HW_OVERLOAD"); |
| 5996 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
| 5997 | OMX_COMPONENT_GENERATE_EBD); |
| 5998 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5999 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6000 | DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6001 | DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued"); |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 6002 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6003 | OMX_COMPONENT_GENERATE_EBD); |
| 6004 | return OMX_ErrorBadParameter; |
| 6005 | } |
| 6006 | } |
| 6007 | DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)", |
| 6008 | frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6009 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6010 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
| 6013 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6014 | FUNCTION |
| 6015 | omx_vdec::FillThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6016 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6017 | DESCRIPTION |
| 6018 | IL client uses this method to release the frame buffer |
| 6019 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6020 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6021 | PARAMETERS |
| 6022 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6023 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6024 | RETURN VALUE |
| 6025 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6026 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6027 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6028 | OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6029 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6030 | { |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6031 | unsigned nPortIndex = 0; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6032 | if (dynamic_buf_mode) { |
| 6033 | private_handle_t *handle = NULL; |
| 6034 | struct VideoDecoderOutputMetaData *meta; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6035 | unsigned int nPortIndex = 0; |
| 6036 | |
| 6037 | if (!buffer || !buffer->pBuffer) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6038 | DEBUG_PRINT_ERROR("%s: invalid params: %p", __FUNCTION__, buffer); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6039 | return OMX_ErrorBadParameter; |
| 6040 | } |
| 6041 | |
| 6042 | //get the buffer type and fd info |
| 6043 | meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer; |
| 6044 | handle = (private_handle_t *)meta->pHandle; |
Arun Menon | b49abf2 | 2013-12-14 21:38:10 -0800 | [diff] [blame] | 6045 | DEBUG_PRINT_LOW("FTB: metabuf: %p buftype: %d bufhndl: %p ", meta, meta->eType, meta->pHandle); |
| 6046 | |
| 6047 | if (!handle) { |
| 6048 | DEBUG_PRINT_ERROR("FTB: Error: IL client passed an invalid buf handle - %p", handle); |
| 6049 | return OMX_ErrorBadParameter; |
| 6050 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6051 | //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF |
| 6052 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6053 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd; |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6054 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = (OMX_U8*) buffer; |
ApurupaPattapu | f693a4d | 2013-12-04 16:07:07 -0800 | [diff] [blame] | 6055 | |
| 6056 | //Store private handle from GraphicBuffer |
| 6057 | native_buffer[nPortIndex].privatehandle = handle; |
| 6058 | native_buffer[nPortIndex].nativehandle = handle; |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6059 | |
| 6060 | //buffer->nAllocLen will be sizeof(struct VideoDecoderOutputMetaData). Overwrite |
| 6061 | //this with a more sane size so that we don't compensate in rest of code |
| 6062 | //We'll restore this size later on, so that it's transparent to client |
| 6063 | buffer->nFilledLen = 0; |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 6064 | buffer->nAllocLen = handle->size; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6065 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6066 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6067 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6068 | DEBUG_PRINT_ERROR("FTB in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6069 | return OMX_ErrorInvalidState; |
| 6070 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6071 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6072 | if (!m_out_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6073 | DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6074 | return OMX_ErrorIncorrectStateOperation; |
| 6075 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6076 | |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6077 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6078 | if (buffer == NULL || |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6079 | (nPortIndex >= drv_ctx.op_buf.actualcount)) { |
| 6080 | DEBUG_PRINT_ERROR("FTB: ERROR: invalid buffer index, nPortIndex %u bufCount %u", |
| 6081 | nPortIndex, drv_ctx.op_buf.actualcount); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6082 | return OMX_ErrorBadParameter; |
| 6083 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6084 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6085 | if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6086 | DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6087 | return OMX_ErrorBadPortIndex; |
| 6088 | } |
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 | DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 6091 | post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg); |
| 6092 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6093 | } |
| 6094 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6095 | FUNCTION |
| 6096 | omx_vdec::fill_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6097 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6098 | DESCRIPTION |
| 6099 | IL client uses this method to release the frame buffer |
| 6100 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6101 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6102 | PARAMETERS |
| 6103 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6104 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6105 | RETURN VALUE |
| 6106 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6107 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6108 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6109 | OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6110 | OMX_IN OMX_HANDLETYPE hComp, |
| 6111 | OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6112 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6113 | OMX_ERRORTYPE nRet = OMX_ErrorNone; |
| 6114 | OMX_BUFFERHEADERTYPE *buffer = bufferAdd; |
| 6115 | unsigned nPortIndex = 0; |
| 6116 | struct vdec_fillbuffer_cmd fillbuffer; |
| 6117 | struct vdec_bufferpayload *ptr_outputbuffer = NULL; |
| 6118 | struct vdec_output_frameinfo *ptr_respbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6119 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6120 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6121 | |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6122 | if (bufferAdd == NULL || nPortIndex > drv_ctx.op_buf.actualcount) { |
| 6123 | DEBUG_PRINT_ERROR("FTBProxy: ERROR: invalid buffer index, nPortIndex %u bufCount %u", |
| 6124 | nPortIndex, drv_ctx.op_buf.actualcount); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6125 | return OMX_ErrorBadParameter; |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6126 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6127 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6128 | DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6129 | bufferAdd, bufferAdd->pBuffer); |
| 6130 | /*Return back the output buffer to client*/ |
| 6131 | if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6132 | DEBUG_PRINT_LOW("Output Buffers return flush/disable condition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6133 | buffer->nFilledLen = 0; |
| 6134 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6135 | return OMX_ErrorNone; |
| 6136 | } |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6137 | |
| 6138 | if (dynamic_buf_mode) { |
| 6139 | //map the buffer handle based on the size set on output port definition. |
| 6140 | if (!secure_mode) { |
| 6141 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = |
| 6142 | (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size, |
| 6143 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 6144 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, 0); |
| 6145 | } |
| 6146 | drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0; |
| 6147 | drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size; |
| 6148 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 6149 | buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, |
| 6150 | drv_ctx.ptr_outputbuffer[nPortIndex].offset); |
| 6151 | } |
| 6152 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6153 | pending_output_buffers++; |
| 6154 | buffer = client_buffers.get_dr_buf_hdr(bufferAdd); |
| 6155 | ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate; |
| 6156 | if (ptr_respbuffer) { |
| 6157 | ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data; |
| 6158 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6159 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6160 | if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) { |
| 6161 | DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL"); |
| 6162 | buffer->nFilledLen = 0; |
| 6163 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6164 | pending_output_buffers--; |
| 6165 | return OMX_ErrorBadParameter; |
| 6166 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6167 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6168 | int rc = 0; |
| 6169 | struct v4l2_buffer buf; |
| 6170 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 6171 | memset( (void *)&buf, 0, sizeof(buf)); |
| 6172 | memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES)); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6173 | unsigned int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6174 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6175 | buf.index = nPortIndex; |
| 6176 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 6177 | buf.memory = V4L2_MEMORY_USERPTR; |
| 6178 | plane[0].bytesused = buffer->nFilledLen; |
| 6179 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 6180 | plane[0].m.userptr = |
| 6181 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr - |
| 6182 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6183 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd; |
| 6184 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6185 | plane[0].data_offset = 0; |
| 6186 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 6187 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 6188 | plane[extra_idx].bytesused = 0; |
| 6189 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 6190 | 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] | 6191 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6192 | 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] | 6193 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6194 | plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size; |
| 6195 | plane[extra_idx].data_offset = 0; |
| 6196 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6197 | DEBUG_PRINT_ERROR("Extradata index higher than expected: %u", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6198 | return OMX_ErrorBadParameter; |
| 6199 | } |
| 6200 | buf.m.planes = plane; |
| 6201 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6202 | 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] | 6203 | plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]); |
| 6204 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6205 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 6206 | if (rc) { |
| 6207 | /*TODO: How to handle this case */ |
| 6208 | DEBUG_PRINT_ERROR("Failed to qbuf to driver"); |
| 6209 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6210 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6214 | FUNCTION |
| 6215 | omx_vdec::SetCallbacks |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6216 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6217 | DESCRIPTION |
| 6218 | Set the callbacks. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6219 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6220 | PARAMETERS |
| 6221 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6222 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6223 | RETURN VALUE |
| 6224 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6225 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6226 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6227 | OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6228 | OMX_IN OMX_CALLBACKTYPE* callbacks, |
| 6229 | OMX_IN OMX_PTR appData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6230 | { |
| 6231 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6232 | m_cb = *callbacks; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6233 | DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6234 | m_cb.EventHandler,m_cb.FillBufferDone); |
| 6235 | m_app_data = appData; |
| 6236 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6237 | } |
| 6238 | |
| 6239 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6240 | FUNCTION |
| 6241 | omx_vdec::ComponentDeInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6242 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6243 | DESCRIPTION |
| 6244 | Destroys the component and release memory allocated to the heap. |
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 | PARAMETERS |
| 6247 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6248 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6249 | RETURN VALUE |
| 6250 | OMX Error None if everything successful. |
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 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6253 | OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp) |
| 6254 | { |
| 6255 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6256 | if (iDivXDrmDecrypt) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6257 | delete iDivXDrmDecrypt; |
| 6258 | iDivXDrmDecrypt=NULL; |
| 6259 | } |
| 6260 | #endif //_ANDROID_ |
| 6261 | |
Shalaj Jain | 286b006 | 2013-02-21 20:35:48 -0800 | [diff] [blame] | 6262 | unsigned i = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6263 | if (OMX_StateLoaded != m_state) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6264 | DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6265 | m_state); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6266 | DEBUG_PRINT_ERROR("Playback Ended - FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6267 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6268 | DEBUG_PRINT_HIGH("Playback Ended - PASSED"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6269 | } |
| 6270 | |
| 6271 | /*Check if the output buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6272 | if (m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6273 | DEBUG_PRINT_LOW("Freeing the Output Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6274 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) { |
| 6275 | free_output_buffer (&m_out_mem_ptr[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6276 | } |
| 6277 | #ifdef _ANDROID_ICS_ |
| 6278 | memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 6279 | #endif |
| 6280 | } |
| 6281 | |
| 6282 | /*Check if the input buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6283 | if (m_inp_mem_ptr || m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6284 | DEBUG_PRINT_LOW("Freeing the Input Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6285 | for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) { |
| 6286 | if (m_inp_mem_ptr) |
| 6287 | free_input_buffer (i,&m_inp_mem_ptr[i]); |
| 6288 | else |
| 6289 | free_input_buffer (i,NULL); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6290 | } |
| 6291 | } |
| 6292 | free_input_buffer_header(); |
| 6293 | free_output_buffer_header(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6294 | if (h264_scratch.pBuffer) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6295 | free(h264_scratch.pBuffer); |
| 6296 | h264_scratch.pBuffer = NULL; |
| 6297 | } |
| 6298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6299 | if (h264_parser) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6300 | delete h264_parser; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6301 | h264_parser = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6302 | } |
| 6303 | |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6304 | if (m_frame_parser.mutils) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6305 | DEBUG_PRINT_LOW("Free utils parser"); |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6306 | delete (m_frame_parser.mutils); |
| 6307 | m_frame_parser.mutils = NULL; |
| 6308 | } |
| 6309 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6310 | if (m_platform_list) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6311 | free(m_platform_list); |
| 6312 | m_platform_list = NULL; |
| 6313 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6314 | if (m_vendor_config.pData) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6315 | free(m_vendor_config.pData); |
| 6316 | m_vendor_config.pData = NULL; |
| 6317 | } |
| 6318 | |
| 6319 | // Reset counters in mesg queues |
| 6320 | m_ftb_q.m_size=0; |
| 6321 | m_cmd_q.m_size=0; |
| 6322 | m_etb_q.m_size=0; |
| 6323 | m_ftb_q.m_read = m_ftb_q.m_write =0; |
| 6324 | m_cmd_q.m_read = m_cmd_q.m_write =0; |
| 6325 | m_etb_q.m_read = m_etb_q.m_write =0; |
| 6326 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6327 | if (m_debug_timestamp) { |
| 6328 | m_timestamp_list.reset_ts_list(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6329 | } |
| 6330 | #endif |
| 6331 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6332 | DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6333 | //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6334 | // NULL); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6335 | DEBUG_PRINT_HIGH("Close the driver instance"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6336 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 6337 | if (m_debug.infile) { |
| 6338 | fclose(m_debug.infile); |
| 6339 | m_debug.infile = NULL; |
| 6340 | } |
| 6341 | if (m_debug.outfile) { |
| 6342 | fclose(m_debug.outfile); |
| 6343 | m_debug.outfile = NULL; |
| 6344 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6345 | #ifdef OUTPUT_EXTRADATA_LOG |
Shalaj Jain | af08f30 | 2013-03-18 13:15:35 -0700 | [diff] [blame] | 6346 | if (outputExtradataFile) |
| 6347 | fclose (outputExtradataFile); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6348 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6349 | DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6350 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6354 | FUNCTION |
| 6355 | omx_vdec::UseEGLImage |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6356 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6357 | DESCRIPTION |
| 6358 | OMX Use EGL Image method implementation <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6359 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6360 | PARAMETERS |
| 6361 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6362 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6363 | RETURN VALUE |
| 6364 | Not Implemented error. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6365 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6366 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6367 | OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6368 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 6369 | OMX_IN OMX_U32 port, |
| 6370 | OMX_IN OMX_PTR appData, |
| 6371 | OMX_IN void* eglImage) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6372 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6373 | OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list; |
| 6374 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry; |
| 6375 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6376 | |
| 6377 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6378 | PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc; |
| 6379 | EGLint fd = -1, offset = 0,pmemPtr = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6380 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6381 | int fd = -1, offset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6382 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6383 | DEBUG_PRINT_HIGH("use EGL image support for decoder"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6384 | if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6385 | DEBUG_PRINT_ERROR(""); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6386 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6387 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6388 | if (m_display_id == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6389 | DEBUG_PRINT_ERROR("Display ID is not set by IL client"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6390 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6391 | } |
| 6392 | egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC) |
| 6393 | eglGetProcAddress("eglQueryImageKHR"); |
| 6394 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd); |
| 6395 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset); |
| 6396 | egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6397 | #else //with OMX test app |
| 6398 | struct temp_egl { |
| 6399 | int pmem_fd; |
| 6400 | int offset; |
| 6401 | }; |
| 6402 | struct temp_egl *temp_egl_id = NULL; |
| 6403 | void * pmemPtr = (void *) eglImage; |
| 6404 | temp_egl_id = (struct temp_egl *)eglImage; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6405 | if (temp_egl_id != NULL) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6406 | fd = temp_egl_id->pmem_fd; |
| 6407 | offset = temp_egl_id->offset; |
| 6408 | } |
| 6409 | #endif |
| 6410 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6411 | DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6412 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6413 | } |
| 6414 | pmem_info.pmem_fd = (OMX_U32) fd; |
| 6415 | pmem_info.offset = (OMX_U32) offset; |
| 6416 | pmem_entry.entry = (void *) &pmem_info; |
| 6417 | pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 6418 | pmem_list.entryList = &pmem_entry; |
| 6419 | pmem_list.nEntries = 1; |
| 6420 | ouput_egl_buffers = true; |
| 6421 | if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port, |
| 6422 | (void *)&pmem_list, drv_ctx.op_buf.buffer_size, |
| 6423 | (OMX_U8 *)pmemPtr)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6424 | DEBUG_PRINT_ERROR("use buffer call failed for egl image"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6425 | return OMX_ErrorInsufficientResources; |
| 6426 | } |
| 6427 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6431 | FUNCTION |
| 6432 | omx_vdec::ComponentRoleEnum |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6433 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6434 | DESCRIPTION |
| 6435 | OMX Component Role Enum method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6436 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6437 | PARAMETERS |
| 6438 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6439 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6440 | RETURN VALUE |
| 6441 | OMX Error None if everything is successful. |
| 6442 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6443 | OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6444 | OMX_OUT OMX_U8* role, |
| 6445 | OMX_IN OMX_U32 index) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6446 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6447 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6448 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6449 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 6450 | if ((0 == index) && role) { |
| 6451 | strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6452 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6453 | } else { |
| 6454 | eRet = OMX_ErrorNoMore; |
| 6455 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6456 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6457 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 6458 | if ((0 == index) && role) { |
| 6459 | strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6460 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6461 | } else { |
| 6462 | eRet = OMX_ErrorNoMore; |
| 6463 | } |
| 6464 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 6465 | if ((0 == index) && role) { |
| 6466 | strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6467 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6468 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6469 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6470 | eRet = OMX_ErrorNoMore; |
| 6471 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6472 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6473 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6474 | else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) || |
| 6475 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE)) |
| 6476 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6477 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6478 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6479 | if ((0 == index) && role) { |
| 6480 | strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6481 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6482 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6483 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6484 | eRet = OMX_ErrorNoMore; |
| 6485 | } |
| 6486 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 6487 | if ((0 == index) && role) { |
| 6488 | strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6489 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6490 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6491 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6492 | eRet = OMX_ErrorNoMore; |
| 6493 | } |
| 6494 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 6495 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 6496 | ) { |
| 6497 | if ((0 == index) && role) { |
| 6498 | strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6499 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6500 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6501 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6502 | eRet = OMX_ErrorNoMore; |
| 6503 | } |
| 6504 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 6505 | if ((0 == index) && role) { |
| 6506 | strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6507 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6508 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6509 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6510 | eRet = OMX_ErrorNoMore; |
| 6511 | } |
| 6512 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6513 | DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6514 | eRet = OMX_ErrorInvalidComponentName; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6515 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6516 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | |
| 6520 | |
| 6521 | |
| 6522 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6523 | FUNCTION |
| 6524 | omx_vdec::AllocateDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6525 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6526 | DESCRIPTION |
| 6527 | Checks if entire buffer pool is allocated by IL Client or not. |
| 6528 | Need this to move to IDLE state. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6529 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6530 | PARAMETERS |
| 6531 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6532 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6533 | RETURN VALUE |
| 6534 | true/false. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6535 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6536 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6537 | bool omx_vdec::allocate_done(void) |
| 6538 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6539 | bool bRet = false; |
| 6540 | bool bRet_In = false; |
| 6541 | bool bRet_Out = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6542 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6543 | bRet_In = allocate_input_done(); |
| 6544 | bRet_Out = allocate_output_done(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6545 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6546 | if (bRet_In && bRet_Out) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6547 | bRet = true; |
| 6548 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6549 | |
| 6550 | return bRet; |
| 6551 | } |
| 6552 | /* ====================================================================== |
| 6553 | FUNCTION |
| 6554 | omx_vdec::AllocateInputDone |
| 6555 | |
| 6556 | DESCRIPTION |
| 6557 | Checks if I/P buffer pool is allocated by IL Client or not. |
| 6558 | |
| 6559 | PARAMETERS |
| 6560 | None. |
| 6561 | |
| 6562 | RETURN VALUE |
| 6563 | true/false. |
| 6564 | |
| 6565 | ========================================================================== */ |
| 6566 | bool omx_vdec::allocate_input_done(void) |
| 6567 | { |
| 6568 | bool bRet = false; |
| 6569 | unsigned i=0; |
| 6570 | |
| 6571 | if (m_inp_mem_ptr == NULL) { |
| 6572 | return bRet; |
| 6573 | } |
| 6574 | if (m_inp_mem_ptr ) { |
| 6575 | for (; i<drv_ctx.ip_buf.actualcount; i++) { |
| 6576 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
| 6577 | break; |
| 6578 | } |
| 6579 | } |
| 6580 | } |
| 6581 | if (i == drv_ctx.ip_buf.actualcount) { |
| 6582 | bRet = true; |
| 6583 | DEBUG_PRINT_HIGH("Allocate done for all i/p buffers"); |
| 6584 | } |
| 6585 | if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) { |
| 6586 | m_inp_bPopulated = OMX_TRUE; |
| 6587 | } |
| 6588 | return bRet; |
| 6589 | } |
| 6590 | /* ====================================================================== |
| 6591 | FUNCTION |
| 6592 | omx_vdec::AllocateOutputDone |
| 6593 | |
| 6594 | DESCRIPTION |
| 6595 | Checks if entire O/P buffer pool is allocated by IL Client or not. |
| 6596 | |
| 6597 | PARAMETERS |
| 6598 | None. |
| 6599 | |
| 6600 | RETURN VALUE |
| 6601 | true/false. |
| 6602 | |
| 6603 | ========================================================================== */ |
| 6604 | bool omx_vdec::allocate_output_done(void) |
| 6605 | { |
| 6606 | bool bRet = false; |
| 6607 | unsigned j=0; |
| 6608 | |
| 6609 | if (m_out_mem_ptr == NULL) { |
| 6610 | return bRet; |
| 6611 | } |
| 6612 | |
| 6613 | if (m_out_mem_ptr) { |
| 6614 | for (; j < drv_ctx.op_buf.actualcount; j++) { |
| 6615 | if (BITMASK_ABSENT(&m_out_bm_count,j)) { |
| 6616 | break; |
| 6617 | } |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | if (j == drv_ctx.op_buf.actualcount) { |
| 6622 | bRet = true; |
| 6623 | DEBUG_PRINT_HIGH("Allocate done for all o/p buffers"); |
| 6624 | if (m_out_bEnabled) |
| 6625 | m_out_bPopulated = OMX_TRUE; |
| 6626 | } |
| 6627 | |
| 6628 | return bRet; |
| 6629 | } |
| 6630 | |
| 6631 | /* ====================================================================== |
| 6632 | FUNCTION |
| 6633 | omx_vdec::ReleaseDone |
| 6634 | |
| 6635 | DESCRIPTION |
| 6636 | Checks if IL client has released all the buffers. |
| 6637 | |
| 6638 | PARAMETERS |
| 6639 | None. |
| 6640 | |
| 6641 | RETURN VALUE |
| 6642 | true/false |
| 6643 | |
| 6644 | ========================================================================== */ |
| 6645 | bool omx_vdec::release_done(void) |
| 6646 | { |
| 6647 | bool bRet = false; |
| 6648 | |
| 6649 | if (release_input_done()) { |
| 6650 | if (release_output_done()) { |
| 6651 | bRet = true; |
| 6652 | } |
| 6653 | } |
| 6654 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | |
| 6658 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6659 | FUNCTION |
| 6660 | omx_vdec::ReleaseOutputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6661 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6662 | DESCRIPTION |
| 6663 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6664 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6665 | PARAMETERS |
| 6666 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6667 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6668 | RETURN VALUE |
| 6669 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6670 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6671 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6672 | bool omx_vdec::release_output_done(void) |
| 6673 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6674 | bool bRet = false; |
| 6675 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6676 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6677 | 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] | 6678 | if (m_out_mem_ptr) { |
| 6679 | for (; j < drv_ctx.op_buf.actualcount ; j++) { |
| 6680 | if (BITMASK_PRESENT(&m_out_bm_count,j)) { |
| 6681 | break; |
| 6682 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6683 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6684 | if (j == drv_ctx.op_buf.actualcount) { |
| 6685 | m_out_bm_count = 0; |
| 6686 | bRet = true; |
| 6687 | } |
| 6688 | } else { |
| 6689 | m_out_bm_count = 0; |
| 6690 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6691 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6692 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6693 | } |
| 6694 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6695 | FUNCTION |
| 6696 | omx_vdec::ReleaseInputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6697 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6698 | DESCRIPTION |
| 6699 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6700 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6701 | PARAMETERS |
| 6702 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6703 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6704 | RETURN VALUE |
| 6705 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6706 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6707 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6708 | bool omx_vdec::release_input_done(void) |
| 6709 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6710 | bool bRet = false; |
| 6711 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6712 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6713 | 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] | 6714 | if (m_inp_mem_ptr) { |
| 6715 | for (; j<drv_ctx.ip_buf.actualcount; j++) { |
| 6716 | if ( BITMASK_PRESENT(&m_inp_bm_count,j)) { |
| 6717 | break; |
| 6718 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6719 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6720 | if (j==drv_ctx.ip_buf.actualcount) { |
| 6721 | bRet = true; |
| 6722 | } |
| 6723 | } else { |
| 6724 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6725 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6726 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6730 | OMX_BUFFERHEADERTYPE * buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6731 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6732 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6733 | 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] | 6734 | DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6735 | return OMX_ErrorBadParameter; |
| 6736 | } else if (output_flush_progress) { |
| 6737 | DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer); |
| 6738 | buffer->nFilledLen = 0; |
| 6739 | buffer->nTimeStamp = 0; |
| 6740 | buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA; |
| 6741 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 6742 | buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT; |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6743 | } |
| 6744 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6745 | if (m_debug_extradata) { |
| 6746 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6747 | DEBUG_PRINT_HIGH(""); |
| 6748 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6749 | DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received"); |
| 6750 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6754 | DEBUG_PRINT_HIGH(""); |
| 6755 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6756 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 6757 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6758 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6759 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6760 | |
| 6761 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6762 | DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6763 | buffer, buffer->pBuffer); |
| 6764 | pending_output_buffers --; |
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 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6767 | DEBUG_PRINT_HIGH("Output EOS has been reached"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6768 | if (!output_flush_progress) |
| 6769 | post_event((unsigned)NULL, (unsigned)NULL, |
| 6770 | OMX_COMPONENT_GENERATE_EOS_DONE); |
| 6771 | |
| 6772 | if (psource_frame) { |
| 6773 | m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame); |
| 6774 | psource_frame = NULL; |
| 6775 | } |
| 6776 | if (pdest_frame) { |
| 6777 | pdest_frame->nFilledLen = 0; |
| 6778 | m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL, |
| 6779 | (unsigned)NULL); |
| 6780 | pdest_frame = NULL; |
| 6781 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6782 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6783 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6784 | |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 6785 | if (!output_flush_progress && (buffer->nFilledLen > 0)) { |
| 6786 | DEBUG_PRINT_LOW("Processing extradata"); |
| 6787 | handle_extradata(buffer); |
| 6788 | } |
| 6789 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6790 | /* For use buffer we need to copy the data */ |
| 6791 | if (!output_flush_progress) { |
| 6792 | /* This is the error check for non-recoverable errros */ |
| 6793 | bool is_duplicate_ts_valid = true; |
| 6794 | bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6795 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6796 | if (output_capability == V4L2_PIX_FMT_MPEG4 || |
| 6797 | output_capability == V4L2_PIX_FMT_MPEG2 || |
| 6798 | output_capability == V4L2_PIX_FMT_DIVX || |
| 6799 | output_capability == V4L2_PIX_FMT_DIVX_311) |
| 6800 | is_duplicate_ts_valid = false; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6801 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6802 | if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 6803 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6804 | is_interlaced = false; |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6805 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6806 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6807 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6808 | if (buffer->nFilledLen > 0) { |
| 6809 | time_stamp_dts.get_next_timestamp(buffer, |
| 6810 | is_interlaced && is_duplicate_ts_valid); |
| 6811 | if (m_debug_timestamp) { |
| 6812 | { |
| 6813 | OMX_TICKS expected_ts = 0; |
| 6814 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6815 | if (is_interlaced && is_duplicate_ts_valid) { |
| 6816 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6817 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6818 | DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6819 | buffer->nTimeStamp, expected_ts); |
| 6820 | |
| 6821 | if (buffer->nTimeStamp != expected_ts) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6822 | DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6823 | } |
| 6824 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6825 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6826 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6827 | time_stamp_dts.remove_time_stamp( |
| 6828 | buffer->nTimeStamp, |
| 6829 | is_interlaced && is_duplicate_ts_valid); |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6830 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6831 | |
| 6832 | |
Praneeth Paladugu | 8f12e82 | 2013-03-11 18:47:58 -0700 | [diff] [blame] | 6833 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6834 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6835 | /* Since we're passing around handles, adjust nFilledLen and nAllocLen |
| 6836 | * to size of the handle. Do it _after_ handle_extradata() which |
| 6837 | * requires the respective sizes to be accurate. */ |
| 6838 | if (dynamic_buf_mode) { |
| 6839 | buffer->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 6840 | buffer->nFilledLen = buffer->nFilledLen ? |
| 6841 | sizeof(struct VideoDecoderOutputMetaData) : 0; |
| 6842 | } |
| 6843 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6844 | if (m_cb.FillBufferDone) { |
| 6845 | if (buffer->nFilledLen > 0) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6846 | if (arbitrary_bytes) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6847 | adjust_timestamp(buffer->nTimeStamp); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6848 | else |
| 6849 | set_frame_rate(buffer->nTimeStamp); |
| 6850 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6851 | if (perf_flag) { |
| 6852 | if (!proc_frms) { |
| 6853 | dec_time.stop(); |
| 6854 | latency = dec_time.processing_time_us() - latency; |
| 6855 | DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3); |
| 6856 | dec_time.start(); |
| 6857 | fps_metrics.start(); |
| 6858 | } |
| 6859 | proc_frms++; |
| 6860 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6861 | OMX_U64 proc_time = 0; |
| 6862 | fps_metrics.stop(); |
| 6863 | proc_time = fps_metrics.processing_time_us(); |
| 6864 | 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] | 6865 | proc_frms, (float)proc_time / 1e6, |
| 6866 | (float)(1e6 * proc_frms) / proc_time); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6867 | proc_frms = 0; |
| 6868 | } |
| 6869 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6870 | |
| 6871 | #ifdef OUTPUT_EXTRADATA_LOG |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6872 | if (outputExtradataFile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6873 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6874 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL; |
| 6875 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
| 6876 | ((unsigned)(buffer->pBuffer + buffer->nOffset + |
| 6877 | buffer->nFilledLen + 3)&(~3)); |
| 6878 | while (p_extra && |
| 6879 | (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6880 | 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] | 6881 | fwrite (p_extra,1,p_extra->nSize,outputExtradataFile); |
| 6882 | if (p_extra->eType == OMX_ExtraDataNone) { |
| 6883 | break; |
| 6884 | } |
| 6885 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 6886 | } |
| 6887 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6888 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6889 | } |
| 6890 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6891 | prev_ts = LLONG_MAX; |
| 6892 | rst_prev_ts = true; |
| 6893 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6894 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6895 | pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 6896 | ((OMX_QCOM_PLATFORM_PRIVATE_LIST *) |
| 6897 | buffer->pPlatformPrivate)->entryList->entry; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6898 | DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6899 | OMX_BUFFERHEADERTYPE *il_buffer; |
| 6900 | il_buffer = client_buffers.get_il_buf_hdr(buffer); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6901 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6902 | if (il_buffer && m_last_rendered_TS >= 0) { |
| 6903 | int current_framerate = (int)(drv_ctx.frame_rate.fps_numerator /drv_ctx.frame_rate.fps_denominator); |
Manikanta Kanamarlapudi | fb53b26 | 2014-01-20 16:12:47 +0530 | [diff] [blame] | 6904 | OMX_TICKS ts_delta = (OMX_TICKS)llabs(il_buffer->nTimeStamp - m_last_rendered_TS); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6905 | |
| 6906 | // Current frame can be send for rendering if |
| 6907 | // (a) current FPS is <= 60 |
| 6908 | // (b) is the next frame after the frame with TS 0 |
| 6909 | // (c) is the first frame after seek |
| 6910 | // (d) the delta TS b\w two consecutive frames is > 16 ms |
| 6911 | // (e) its TS is equal to previous frame TS |
| 6912 | // (f) if marked EOS |
| 6913 | |
| 6914 | if(current_framerate <= 60 || m_last_rendered_TS == 0 || |
| 6915 | il_buffer->nTimeStamp == 0 || ts_delta >= 16000 || |
| 6916 | ts_delta == 0 || (il_buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6917 | m_last_rendered_TS = il_buffer->nTimeStamp; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6918 | } else { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6919 | //mark for droping |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6920 | buffer->nFilledLen = 0; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | DEBUG_PRINT_LOW(" -- %s Frame -- info:: fps(%d) lastRenderTime(%lld) bufferTs(%lld) ts_delta(%d)", |
| 6924 | buffer->nFilledLen? "Rendering":"Dropping",current_framerate,m_last_rendered_TS, |
| 6925 | il_buffer->nTimeStamp,ts_delta); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6926 | } |
| 6927 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6928 | if (il_buffer) { |
Arun Menon | 9230eb8 | 2014-02-11 19:19:02 -0800 | [diff] [blame] | 6929 | log_output_buffers(il_buffer); |
| 6930 | if (dynamic_buf_mode) { |
| 6931 | unsigned int nPortIndex = 0; |
| 6932 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6933 | |
| 6934 | if (!secure_mode) { |
| 6935 | munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr, |
| 6936 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size); |
| 6937 | } |
| 6938 | |
| 6939 | //Clear graphic buffer handles in dynamic mode |
| 6940 | native_buffer[nPortIndex].privatehandle = NULL; |
| 6941 | native_buffer[nPortIndex].nativehandle = NULL; |
| 6942 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6943 | m_cb.FillBufferDone (hComp,m_app_data,il_buffer); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6944 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6945 | DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr"); |
| 6946 | return OMX_ErrorBadParameter; |
| 6947 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6948 | DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6949 | } else { |
| 6950 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 6951 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6952 | |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 6953 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 6954 | if (m_smoothstreaming_mode && m_out_mem_ptr) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 6955 | OMX_U32 buf_index = buffer - m_out_mem_ptr; |
| 6956 | BufferDim_t dim; |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 6957 | private_handle_t *private_handle = NULL; |
Pushkaraj Patil | 065b573 | 2014-11-26 11:08:02 +0530 | [diff] [blame] | 6958 | dim.sliceWidth = framesize.nWidth; |
| 6959 | dim.sliceHeight = framesize.nHeight; |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 6960 | if (native_buffer[buf_index].privatehandle) |
| 6961 | private_handle = native_buffer[buf_index].privatehandle; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 6962 | if (private_handle) { |
| 6963 | DEBUG_PRINT_LOW("set metadata: update buf-geometry with stride %d slice %d", |
| 6964 | dim.sliceWidth, dim.sliceHeight); |
| 6965 | setMetaData(private_handle, UPDATE_BUFFER_GEOMETRY, (void*)&dim); |
| 6966 | } |
| 6967 | } |
| 6968 | #endif |
| 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::empty_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6974 | OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6975 | { |
| 6976 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6977 | 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] | 6978 | DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6979 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6982 | DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6983 | buffer, buffer->pBuffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6984 | pending_input_buffers--; |
| 6985 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6986 | if (arbitrary_bytes) { |
| 6987 | if (pdest_frame == NULL && input_flush_progress == false) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6988 | 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] | 6989 | pdest_frame = buffer; |
| 6990 | buffer->nFilledLen = 0; |
| 6991 | buffer->nTimeStamp = LLONG_MAX; |
| 6992 | push_input_buffer (hComp); |
| 6993 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6994 | DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6995 | buffer->nFilledLen = 0; |
| 6996 | if (!m_input_free_q.insert_entry((unsigned)buffer, |
| 6997 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6998 | DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6999 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7000 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7001 | } else if (m_cb.EmptyBufferDone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7002 | buffer->nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7003 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7004 | buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr]; |
| 7005 | } |
| 7006 | m_cb.EmptyBufferDone(hComp ,m_app_data, buffer); |
| 7007 | } |
| 7008 | return OMX_ErrorNone; |
| 7009 | } |
| 7010 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7011 | int omx_vdec::async_message_process (void *context, void* message) |
| 7012 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7013 | omx_vdec* omx = NULL; |
| 7014 | struct vdec_msginfo *vdec_msg = NULL; |
| 7015 | OMX_BUFFERHEADERTYPE* omxhdr = NULL; |
| 7016 | struct v4l2_buffer *v4l2_buf_ptr = NULL; |
| 7017 | struct vdec_output_frameinfo *output_respbuf = NULL; |
| 7018 | int rc=1; |
| 7019 | if (context == NULL || message == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7020 | 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] | 7021 | return -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7022 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7023 | vdec_msg = (struct vdec_msginfo *)message; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7024 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7025 | omx = reinterpret_cast<omx_vdec*>(context); |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 7026 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7027 | switch (vdec_msg->msgcode) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7028 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7029 | case VDEC_MSG_EVT_HW_ERROR: |
| 7030 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7031 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
| 7032 | break; |
| 7033 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 7034 | case VDEC_MSG_EVT_HW_OVERLOAD: |
| 7035 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7036 | OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD); |
| 7037 | break; |
| 7038 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7039 | case VDEC_MSG_RESP_START_DONE: |
| 7040 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7041 | OMX_COMPONENT_GENERATE_START_DONE); |
| 7042 | break; |
| 7043 | |
| 7044 | case VDEC_MSG_RESP_STOP_DONE: |
| 7045 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7046 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 7047 | break; |
| 7048 | |
| 7049 | case VDEC_MSG_RESP_RESUME_DONE: |
| 7050 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7051 | OMX_COMPONENT_GENERATE_RESUME_DONE); |
| 7052 | break; |
| 7053 | |
| 7054 | case VDEC_MSG_RESP_PAUSE_DONE: |
| 7055 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7056 | OMX_COMPONENT_GENERATE_PAUSE_DONE); |
| 7057 | break; |
| 7058 | |
| 7059 | case VDEC_MSG_RESP_FLUSH_INPUT_DONE: |
| 7060 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7061 | OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH); |
| 7062 | break; |
| 7063 | case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE: |
| 7064 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7065 | OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH); |
| 7066 | break; |
| 7067 | case VDEC_MSG_RESP_INPUT_FLUSHED: |
| 7068 | case VDEC_MSG_RESP_INPUT_BUFFER_DONE: |
| 7069 | |
| 7070 | /* omxhdr = (OMX_BUFFERHEADERTYPE* ) |
| 7071 | vdec_msg->msgdata.input_frame_clientdata; */ |
| 7072 | |
| 7073 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata; |
| 7074 | omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index; |
| 7075 | if (omxhdr == NULL || |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7076 | ((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] | 7077 | omxhdr = NULL; |
| 7078 | vdec_msg->status_code = VDEC_S_EFATAL; |
| 7079 | } |
| 7080 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) { |
| 7081 | DEBUG_PRINT_HIGH("Unsupported input"); |
| 7082 | omx->omx_report_error (); |
| 7083 | } |
| 7084 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7085 | vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR; |
| 7086 | } |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7087 | if (omxhdr->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7088 | |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 7089 | DEBUG_PRINT_LOW("Decrement codec_config buffer counter"); |
| 7090 | android_atomic_dec(&omx->m_queued_codec_config_count); |
| 7091 | if ((android_atomic_add(0, &omx->m_queued_codec_config_count) == 0) && |
| 7092 | BITMASK_PRESENT(&omx->m_flags, OMX_COMPONENT_FLUSH_DEFERRED)) { |
| 7093 | DEBUG_PRINT_LOW("sem post for CODEC CONFIG buffer"); |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7094 | sem_post(&omx->m_safe_flush); |
| 7095 | } |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7096 | } |
| 7097 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7098 | omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code, |
| 7099 | OMX_COMPONENT_GENERATE_EBD); |
| 7100 | break; |
| 7101 | case VDEC_MSG_EVT_INFO_FIELD_DROPPED: |
| 7102 | int64_t *timestamp; |
| 7103 | timestamp = (int64_t *) malloc(sizeof(int64_t)); |
| 7104 | if (timestamp) { |
| 7105 | *timestamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7106 | omx->post_event ((unsigned int)timestamp, vdec_msg->status_code, |
| 7107 | OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7108 | DEBUG_PRINT_HIGH("Field dropped time stamp is %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7109 | vdec_msg->msgdata.output_frame.time_stamp); |
| 7110 | } |
| 7111 | break; |
| 7112 | case VDEC_MSG_RESP_OUTPUT_FLUSHED: |
| 7113 | case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE: |
| 7114 | |
| 7115 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data; |
| 7116 | omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7117 | |
| 7118 | DEBUG_PRINT_LOW("[RespBufDone] Buf(%p) Ts(%lld) PicType(%u) Flags (0x%x) FillLen(%u) Crop: L(%u) T(%u) R(%u) B(%u)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7119 | omxhdr, vdec_msg->msgdata.output_frame.time_stamp, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7120 | vdec_msg->msgdata.output_frame.pic_type, v4l2_buf_ptr->flags, |
| 7121 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7122 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7123 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7124 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7125 | vdec_msg->msgdata.output_frame.framesize.bottom); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7126 | |
| 7127 | if (omxhdr && omxhdr->pOutputPortPrivate && |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7128 | ((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] | 7129 | (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7130 | - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7131 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 7132 | if (vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7133 | omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len; |
| 7134 | omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset; |
| 7135 | omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7136 | omxhdr->nFlags = 0; |
| 7137 | |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7138 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7139 | omxhdr->nFlags |= OMX_BUFFERFLAG_EOS; |
| 7140 | //rc = -1; |
| 7141 | } |
| 7142 | if (omxhdr->nFilledLen) { |
| 7143 | omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; |
| 7144 | } |
| 7145 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) { |
| 7146 | omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; |
| 7147 | } else { |
| 7148 | omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME; |
| 7149 | } |
| 7150 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) { |
| 7151 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7152 | } |
| 7153 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) { |
| 7154 | omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY; |
| 7155 | } |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 7156 | |
| 7157 | if (v4l2_buf_ptr->flags & V4L2_MSM_BUF_FLAG_MBAFF) { |
| 7158 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_MBAFF; |
| 7159 | } |
| 7160 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7161 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) { |
Arun Menon | e50f6ef | 2013-09-30 15:08:27 -0700 | [diff] [blame] | 7162 | omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7163 | DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d", |
| 7164 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd); |
| 7165 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7166 | if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) { |
| 7167 | omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd, |
| 7168 | omxhdr->nOffset); |
| 7169 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7170 | if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) && |
| 7171 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) && |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7172 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) { |
Praneeth Paladugu | 17364df | 2013-07-30 11:34:16 -0700 | [diff] [blame] | 7173 | omx->time_stamp_dts.remove_time_stamp( |
| 7174 | omxhdr->nTimeStamp, |
| 7175 | (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 7176 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7177 | omx->post_event ((unsigned)NULL,(unsigned int)omxhdr, |
| 7178 | OMX_COMPONENT_GENERATE_FTB); |
| 7179 | break; |
| 7180 | } |
| 7181 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7182 | omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
| 7183 | } |
| 7184 | vdec_msg->msgdata.output_frame.bufferaddr = |
| 7185 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7186 | |
| 7187 | /* Post event if resolution OR crop changed */ |
| 7188 | /* filled length will be changed if resolution changed */ |
| 7189 | /* Crop parameters can be changed even without resolution change */ |
| 7190 | if (omxhdr->nFilledLen |
| 7191 | && ((omx->prev_n_filled_len != omxhdr->nFilledLen) |
| 7192 | || (omx->drv_ctx.frame_size.left != vdec_msg->msgdata.output_frame.framesize.left) |
| 7193 | || (omx->drv_ctx.frame_size.top != vdec_msg->msgdata.output_frame.framesize.top) |
| 7194 | || (omx->drv_ctx.frame_size.right != vdec_msg->msgdata.output_frame.framesize.right) |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 7195 | || (omx->drv_ctx.frame_size.bottom != vdec_msg->msgdata.output_frame.framesize.bottom) |
| 7196 | || (omx->drv_ctx.video_resolution.frame_width != vdec_msg->msgdata.output_frame.picsize.frame_width) |
| 7197 | || (omx->drv_ctx.video_resolution.frame_height != vdec_msg->msgdata.output_frame.picsize.frame_height) )) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7198 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 7199 | DEBUG_PRINT_HIGH("Paramters Changed From: Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u --> Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u", |
| 7200 | omx->prev_n_filled_len, |
| 7201 | omx->drv_ctx.video_resolution.frame_width, |
| 7202 | omx->drv_ctx.video_resolution.frame_height, |
| 7203 | omx->drv_ctx.frame_size.left, omx->drv_ctx.frame_size.top, |
| 7204 | omx->drv_ctx.frame_size.right, omx->drv_ctx.frame_size.bottom, |
| 7205 | omxhdr->nFilledLen, vdec_msg->msgdata.output_frame.picsize.frame_width, |
| 7206 | vdec_msg->msgdata.output_frame.picsize.frame_height, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7207 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7208 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7209 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7210 | vdec_msg->msgdata.output_frame.framesize.bottom); |
| 7211 | |
Maheshwar Ajja | 0f840ce | 2014-09-29 16:53:42 +0530 | [diff] [blame] | 7212 | omx->drv_ctx.video_resolution.frame_width = |
| 7213 | vdec_msg->msgdata.output_frame.picsize.frame_width; |
| 7214 | omx->drv_ctx.video_resolution.frame_height = |
| 7215 | vdec_msg->msgdata.output_frame.picsize.frame_height; |
Praneeth Paladugu | ca80be7 | 2014-10-22 23:48:54 -0700 | [diff] [blame] | 7216 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) { |
| 7217 | omx->drv_ctx.video_resolution.stride = |
| 7218 | VENUS_Y_STRIDE(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_width); |
| 7219 | omx->drv_ctx.video_resolution.scan_lines = |
| 7220 | VENUS_Y_SCANLINES(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_height); |
| 7221 | } |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7222 | memcpy(&omx->drv_ctx.frame_size, |
| 7223 | &vdec_msg->msgdata.output_frame.framesize, |
| 7224 | sizeof(struct vdec_framesize)); |
| 7225 | |
| 7226 | omx->post_event(OMX_CORE_OUTPUT_PORT_INDEX, |
| 7227 | OMX_IndexConfigCommonOutputCrop, |
| 7228 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7229 | } |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7230 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7231 | if (omxhdr->nFilledLen) |
| 7232 | omx->prev_n_filled_len = omxhdr->nFilledLen; |
| 7233 | |
| 7234 | output_respbuf = (struct vdec_output_frameinfo *)\ |
| 7235 | omxhdr->pOutputPortPrivate; |
| 7236 | output_respbuf->len = vdec_msg->msgdata.output_frame.len; |
| 7237 | output_respbuf->offset = vdec_msg->msgdata.output_frame.offset; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7238 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7239 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) { |
| 7240 | output_respbuf->pic_type = PICTURE_TYPE_I; |
| 7241 | } |
| 7242 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) { |
| 7243 | output_respbuf->pic_type = PICTURE_TYPE_P; |
| 7244 | } |
| 7245 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) { |
| 7246 | output_respbuf->pic_type = PICTURE_TYPE_B; |
| 7247 | } |
| 7248 | |
| 7249 | if (omx->output_use_buffer) |
| 7250 | memcpy ( omxhdr->pBuffer, (void *) |
| 7251 | ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr + |
| 7252 | (unsigned long)vdec_msg->msgdata.output_frame.offset), |
| 7253 | vdec_msg->msgdata.output_frame.len); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7254 | } else { |
| 7255 | DEBUG_PRINT_ERROR("Invalid filled length = %u, buffer size = %u, prev_length = %u", |
| 7256 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7257 | omxhdr->nAllocLen, omx->prev_n_filled_len); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7258 | omxhdr->nFilledLen = 0; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7259 | } |
| 7260 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7261 | omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code, |
| 7262 | OMX_COMPONENT_GENERATE_FBD); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7263 | |
| 7264 | } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7265 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7266 | OMX_COMPONENT_GENERATE_EOS_DONE); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7267 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7268 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7269 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7270 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7271 | break; |
| 7272 | case VDEC_MSG_EVT_CONFIG_CHANGED: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7273 | DEBUG_PRINT_HIGH("Port settings changed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7274 | omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition, |
| 7275 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
| 7276 | break; |
| 7277 | default: |
| 7278 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7279 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7280 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7281 | } |
| 7282 | |
| 7283 | OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary ( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7284 | OMX_HANDLETYPE hComp, |
| 7285 | OMX_BUFFERHEADERTYPE *buffer |
| 7286 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7287 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7288 | unsigned address,p2,id; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7289 | DEBUG_PRINT_LOW("Empty this arbitrary"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7290 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7291 | if (buffer == NULL) { |
| 7292 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7293 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7294 | DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 7295 | DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7296 | buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp); |
| 7297 | |
| 7298 | /* return zero length and not an EOS buffer */ |
| 7299 | /* return buffer if input flush in progress */ |
| 7300 | if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) && |
| 7301 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7302 | DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7303 | m_cb.EmptyBufferDone (hComp,m_app_data,buffer); |
| 7304 | return OMX_ErrorNone; |
| 7305 | } |
| 7306 | |
| 7307 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7308 | 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] | 7309 | psource_frame = buffer; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7310 | DEBUG_PRINT_LOW("Try to Push One Input Buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7311 | push_input_buffer (hComp); |
| 7312 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7313 | DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7314 | if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL, |
| 7315 | (unsigned)NULL)) { |
| 7316 | return OMX_ErrorBadParameter; |
| 7317 | } |
| 7318 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7319 | |
Sowmya Pandiri | 302f5ab | 2014-04-03 13:41:03 -0700 | [diff] [blame] | 7320 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 7321 | codec_config_flag = false; |
| 7322 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7323 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7324 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7325 | } |
| 7326 | |
| 7327 | OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp) |
| 7328 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7329 | unsigned address,p2,id; |
| 7330 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7331 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7332 | if (pdest_frame == NULL || psource_frame == NULL) { |
| 7333 | /*Check if we have a destination buffer*/ |
| 7334 | if (pdest_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7335 | DEBUG_PRINT_LOW("Get a Destination buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7336 | if (m_input_free_q.m_size) { |
| 7337 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7338 | pdest_frame = (OMX_BUFFERHEADERTYPE *)address; |
| 7339 | pdest_frame->nFilledLen = 0; |
| 7340 | pdest_frame->nTimeStamp = LLONG_MAX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7341 | DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7342 | } |
| 7343 | } |
| 7344 | |
| 7345 | /*Check if we have a destination buffer*/ |
| 7346 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7347 | DEBUG_PRINT_LOW("Get a source buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7348 | if (m_input_pending_q.m_size) { |
| 7349 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7350 | psource_frame = (OMX_BUFFERHEADERTYPE *)address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7351 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7352 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7353 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7354 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7355 | |
| 7356 | } |
| 7357 | } |
| 7358 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7359 | } |
| 7360 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7361 | while ((pdest_frame != NULL) && (psource_frame != NULL)) { |
| 7362 | switch (codec_type_parse) { |
| 7363 | case CODEC_TYPE_MPEG4: |
| 7364 | case CODEC_TYPE_H263: |
| 7365 | case CODEC_TYPE_MPEG2: |
| 7366 | ret = push_input_sc_codec(hComp); |
| 7367 | break; |
| 7368 | case CODEC_TYPE_H264: |
| 7369 | ret = push_input_h264(hComp); |
| 7370 | break; |
| 7371 | case CODEC_TYPE_VC1: |
| 7372 | ret = push_input_vc1(hComp); |
| 7373 | break; |
| 7374 | default: |
| 7375 | break; |
| 7376 | } |
| 7377 | if (ret != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7378 | DEBUG_PRINT_ERROR("Pushing input Buffer Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7379 | omx_report_error (); |
| 7380 | break; |
| 7381 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7382 | } |
| 7383 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7384 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp) |
| 7388 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7389 | OMX_U32 partial_frame = 1; |
| 7390 | OMX_BOOL generate_ebd = OMX_TRUE; |
| 7391 | unsigned address = 0, p2 = 0, id = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7392 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7393 | DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7394 | psource_frame,psource_frame->nTimeStamp); |
| 7395 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7396 | pdest_frame,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7397 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7398 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7399 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7400 | |
| 7401 | if (partial_frame == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7402 | DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7403 | pdest_frame->nFilledLen,psource_frame,frame_count); |
| 7404 | |
| 7405 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7406 | DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7407 | /*First Parsed buffer will have only header Hence skip*/ |
| 7408 | if (frame_count == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7409 | DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7410 | |
| 7411 | if (codec_type_parse == CODEC_TYPE_MPEG4 || |
| 7412 | codec_type_parse == CODEC_TYPE_DIVX) { |
| 7413 | mp4StreamType psBits; |
| 7414 | psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset; |
| 7415 | psBits.numBytes = pdest_frame->nFilledLen; |
| 7416 | mp4_headerparser.parseHeader(&psBits); |
| 7417 | } |
| 7418 | |
| 7419 | frame_count++; |
| 7420 | } else { |
| 7421 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7422 | if (pdest_frame->nFilledLen) { |
| 7423 | /*Push the frame to the Decoder*/ |
| 7424 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7425 | return OMX_ErrorBadParameter; |
| 7426 | } |
| 7427 | frame_count++; |
| 7428 | pdest_frame = NULL; |
| 7429 | |
| 7430 | if (m_input_free_q.m_size) { |
| 7431 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7432 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
| 7433 | pdest_frame->nFilledLen = 0; |
| 7434 | } |
| 7435 | } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7436 | DEBUG_PRINT_ERROR("Zero len buffer return back to POOL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7437 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL, |
| 7438 | (unsigned)NULL); |
| 7439 | pdest_frame = NULL; |
| 7440 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7441 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7442 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7443 | DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7444 | /*Check if Destination Buffer is full*/ |
| 7445 | if (pdest_frame->nAllocLen == |
| 7446 | pdest_frame->nFilledLen + pdest_frame->nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7447 | DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7448 | return OMX_ErrorStreamCorrupt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7449 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7450 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7451 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7452 | if (psource_frame->nFilledLen == 0) { |
| 7453 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7454 | if (pdest_frame) { |
| 7455 | pdest_frame->nFlags |= psource_frame->nFlags; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7456 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7457 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7458 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7459 | pdest_frame->nFilledLen,frame_count++); |
| 7460 | /*Push the frame to the Decoder*/ |
| 7461 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7462 | return OMX_ErrorBadParameter; |
| 7463 | } |
| 7464 | frame_count++; |
| 7465 | pdest_frame = NULL; |
| 7466 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7467 | DEBUG_PRINT_LOW("Last frame in else dest addr") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7468 | generate_ebd = OMX_FALSE; |
| 7469 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7470 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7471 | if (generate_ebd) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7472 | DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7473 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7474 | psource_frame = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7475 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7476 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7477 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7478 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7479 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7480 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7481 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7482 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7483 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7484 | } |
| 7485 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7486 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7487 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7488 | } |
| 7489 | |
| 7490 | OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp) |
| 7491 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7492 | OMX_U32 partial_frame = 1; |
| 7493 | unsigned address = 0, p2 = 0, id = 0; |
| 7494 | OMX_BOOL isNewFrame = OMX_FALSE; |
| 7495 | OMX_BOOL generate_ebd = OMX_TRUE; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7496 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7497 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7498 | DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7499 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7500 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7501 | DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7502 | "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7503 | DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7504 | if (h264_scratch.nFilledLen && look_ahead_nal) { |
| 7505 | look_ahead_nal = false; |
| 7506 | if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7507 | h264_scratch.nFilledLen) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7508 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7509 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7510 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7511 | DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7512 | h264_scratch.nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7513 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7514 | DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7515 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7516 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7517 | } |
Praveen Chavan | ce0b5e8 | 2013-08-08 05:23:34 -0700 | [diff] [blame] | 7518 | |
| 7519 | /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result |
| 7520 | in EOS flag getting associated with the destination |
| 7521 | */ |
| 7522 | if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) && |
| 7523 | pdest_frame->nFilledLen) { |
| 7524 | DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'"); |
| 7525 | generate_ebd = OMX_FALSE; |
| 7526 | } |
| 7527 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7528 | if (nal_length == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7529 | DEBUG_PRINT_LOW("Zero NAL, hence parse using start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7530 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7531 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7532 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7533 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7534 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7535 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7536 | 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] | 7537 | if (m_frame_parser.parse_h264_nallength(psource_frame, |
| 7538 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7539 | DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7540 | return OMX_ErrorBadParameter; |
| 7541 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7542 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7543 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7544 | if (partial_frame == 0) { |
| 7545 | if (nal_count == 0 && h264_scratch.nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7546 | DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7547 | nal_count++; |
| 7548 | h264_scratch.nTimeStamp = psource_frame->nTimeStamp; |
| 7549 | h264_scratch.nFlags = psource_frame->nFlags; |
| 7550 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7551 | DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7552 | if (h264_scratch.nFilledLen) { |
| 7553 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen, |
| 7554 | NALU_TYPE_SPS); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7555 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7556 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) |
| 7557 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7558 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
| 7559 | else if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7560 | // If timeinfo is present frame info from SEI is already processed |
| 7561 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7562 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7563 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7564 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7565 | nal_count++; |
| 7566 | if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) { |
| 7567 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7568 | pdest_frame->nFlags = h264_last_au_flags; |
| 7569 | #ifdef PANSCAN_HDLR |
| 7570 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7571 | h264_parser->update_panscan_data(h264_last_au_ts); |
| 7572 | #endif |
| 7573 | } |
| 7574 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR || |
| 7575 | m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) { |
| 7576 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7577 | h264_last_au_flags = h264_scratch.nFlags; |
| 7578 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7579 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7580 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts); |
| 7581 | if (!VALID_TS(h264_last_au_ts)) |
| 7582 | h264_last_au_ts = ts_in_sei; |
| 7583 | } |
| 7584 | #endif |
| 7585 | } else |
| 7586 | h264_last_au_ts = LLONG_MAX; |
| 7587 | } |
| 7588 | |
| 7589 | if (!isNewFrame) { |
| 7590 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7591 | h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7592 | DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7593 | h264_scratch.nFilledLen); |
| 7594 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7595 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7596 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7597 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ) |
| 7598 | pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7599 | h264_scratch.nFilledLen = 0; |
| 7600 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7601 | DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7602 | return OMX_ErrorBadParameter; |
| 7603 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7604 | } else if(h264_scratch.nFilledLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7605 | look_ahead_nal = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7606 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7607 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7608 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7609 | pdest_frame->nFilledLen,frame_count++); |
| 7610 | |
| 7611 | if (pdest_frame->nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7612 | DEBUG_PRINT_LOW("Copy the Current Frame since and push it"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7613 | look_ahead_nal = false; |
| 7614 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7615 | h264_scratch.nFilledLen) { |
| 7616 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7617 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7618 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7619 | h264_scratch.nFilledLen = 0; |
| 7620 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7621 | DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7622 | return OMX_ErrorBadParameter; |
| 7623 | } |
| 7624 | } else { |
| 7625 | if (psource_frame->nFilledLen || h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7626 | DEBUG_PRINT_LOW("Reset the EOS Flag"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7627 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7628 | } |
| 7629 | /*Push the frame to the Decoder*/ |
| 7630 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7631 | return OMX_ErrorBadParameter; |
| 7632 | } |
| 7633 | //frame_count++; |
| 7634 | pdest_frame = NULL; |
| 7635 | if (m_input_free_q.m_size) { |
| 7636 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7637 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7638 | DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7639 | pdest_frame->nFilledLen = 0; |
| 7640 | pdest_frame->nFlags = 0; |
| 7641 | pdest_frame->nTimeStamp = LLONG_MAX; |
| 7642 | } |
| 7643 | } |
| 7644 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7645 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7646 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7647 | 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] | 7648 | /*Check if Destination Buffer is full*/ |
| 7649 | if (h264_scratch.nAllocLen == |
| 7650 | h264_scratch.nFilledLen + h264_scratch.nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7651 | DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7652 | return OMX_ErrorStreamCorrupt; |
| 7653 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7654 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7655 | |
| 7656 | if (!psource_frame->nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7657 | 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] | 7658 | |
| 7659 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7660 | if (pdest_frame) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7661 | DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7662 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7663 | h264_scratch.nFilledLen) { |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7664 | if(pdest_frame->nFilledLen == 0) { |
| 7665 | /* No residual frame from before, send whatever |
| 7666 | * we have left */ |
| 7667 | memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7668 | h264_scratch.pBuffer, h264_scratch.nFilledLen); |
| 7669 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7670 | h264_scratch.nFilledLen = 0; |
| 7671 | pdest_frame->nTimeStamp = h264_scratch.nTimeStamp; |
| 7672 | } else { |
| 7673 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7674 | if(!isNewFrame) { |
| 7675 | /* Have a residual frame, but we know that the |
| 7676 | * AU in this frame is belonging to whatever |
| 7677 | * frame we had left over. So append it */ |
| 7678 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7679 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7680 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7681 | h264_scratch.nFilledLen = 0; |
Balamurugan Alagarsamy | efde383 | 2014-09-22 19:52:20 +0530 | [diff] [blame] | 7682 | if (h264_last_au_ts != LLONG_MAX) |
| 7683 | pdest_frame->nTimeStamp = h264_last_au_ts; |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7684 | } else { |
| 7685 | /* Completely new frame, let's just push what |
| 7686 | * we have now. The resulting EBD would trigger |
| 7687 | * another push */ |
| 7688 | generate_ebd = OMX_FALSE; |
| 7689 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7690 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7691 | } |
| 7692 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7693 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7694 | DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7695 | return OMX_ErrorBadParameter; |
| 7696 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7697 | |
| 7698 | /* Iff we coalesced two buffers, inherit the flags of both bufs */ |
| 7699 | if(generate_ebd == OMX_TRUE) { |
| 7700 | pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags; |
| 7701 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7702 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7703 | DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7704 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7705 | DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7706 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7707 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7708 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp); |
| 7709 | if (!VALID_TS(pdest_frame->nTimeStamp)) |
| 7710 | pdest_frame->nTimeStamp = ts_in_sei; |
| 7711 | } |
| 7712 | #endif |
| 7713 | /*Push the frame to the Decoder*/ |
| 7714 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7715 | return OMX_ErrorBadParameter; |
| 7716 | } |
| 7717 | frame_count++; |
| 7718 | pdest_frame = NULL; |
| 7719 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7720 | DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7721 | pdest_frame,h264_scratch.nFilledLen); |
| 7722 | generate_ebd = OMX_FALSE; |
| 7723 | } |
| 7724 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7725 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7726 | if (generate_ebd && !psource_frame->nFilledLen) { |
| 7727 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7728 | psource_frame = NULL; |
| 7729 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7730 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7731 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7732 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7733 | DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7734 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7735 | } |
| 7736 | } |
| 7737 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7738 | } |
| 7739 | |
| 7740 | OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp) |
| 7741 | { |
| 7742 | OMX_U8 *buf, *pdest; |
| 7743 | OMX_U32 partial_frame = 1; |
| 7744 | OMX_U32 buf_len, dest_len; |
| 7745 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7746 | if (first_frame == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7747 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7748 | DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7749 | if (!m_vendor_config.pData) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7750 | DEBUG_PRINT_LOW("Check profile type in 1st source buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7751 | buf = psource_frame->pBuffer; |
| 7752 | buf_len = psource_frame->nFilledLen; |
| 7753 | |
| 7754 | if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) == |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7755 | VC1_SP_MP_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7756 | m_vc1_profile = VC1_SP_MP_RCV; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7757 | } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7758 | m_vc1_profile = VC1_AP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7759 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7760 | DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7761 | return OMX_ErrorStreamCorrupt; |
| 7762 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7763 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7764 | pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen + |
| 7765 | pdest_frame->nOffset; |
| 7766 | dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen + |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7767 | pdest_frame->nOffset); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7768 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7769 | if (dest_len < m_vendor_config.nDataSize) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7770 | DEBUG_PRINT_ERROR("Destination buffer full"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7771 | return OMX_ErrorBadParameter; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7772 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7773 | memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize); |
| 7774 | pdest_frame->nFilledLen += m_vendor_config.nDataSize; |
| 7775 | } |
| 7776 | } |
| 7777 | } |
| 7778 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7779 | switch (m_vc1_profile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7780 | case VC1_AP: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7781 | DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7782 | if (push_input_sc_codec(hComp) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7783 | DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7784 | return OMX_ErrorBadParameter; |
| 7785 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7786 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7787 | |
| 7788 | case VC1_SP_MP_RCV: |
| 7789 | default: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7790 | DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7791 | return OMX_ErrorBadParameter; |
| 7792 | } |
| 7793 | return OMX_ErrorNone; |
| 7794 | } |
| 7795 | |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7796 | #ifndef USE_ION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7797 | 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] | 7798 | OMX_U32 alignment) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7799 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7800 | struct pmem_allocation allocation; |
| 7801 | allocation.size = buffer_size; |
| 7802 | allocation.align = clip2(alignment); |
| 7803 | if (allocation.align < 4096) { |
| 7804 | allocation.align = 4096; |
| 7805 | } |
| 7806 | if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7807 | DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7808 | allocation.align, allocation.size); |
| 7809 | return false; |
| 7810 | } |
| 7811 | return true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7812 | } |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7813 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7814 | #ifdef USE_ION |
| 7815 | int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7816 | OMX_U32 alignment, struct ion_allocation_data *alloc_data, |
| 7817 | struct ion_fd_data *fd_data, int flag) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7818 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7819 | int fd = -EINVAL; |
| 7820 | int rc = -EINVAL; |
| 7821 | int ion_dev_flag; |
| 7822 | struct vdec_ion ion_buf_info; |
| 7823 | if (!alloc_data || buffer_size <= 0 || !fd_data) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7824 | DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7825 | return -EINVAL; |
| 7826 | } |
| 7827 | ion_dev_flag = O_RDONLY; |
| 7828 | fd = open (MEM_DEVICE, ion_dev_flag); |
| 7829 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7830 | DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7831 | return fd; |
| 7832 | } |
| 7833 | alloc_data->flags = 0; |
| 7834 | if (!secure_mode && (flag & ION_FLAG_CACHED)) { |
| 7835 | alloc_data->flags |= ION_FLAG_CACHED; |
| 7836 | } |
| 7837 | alloc_data->len = buffer_size; |
| 7838 | alloc_data->align = clip2(alignment); |
| 7839 | if (alloc_data->align < 4096) { |
| 7840 | alloc_data->align = 4096; |
| 7841 | } |
| 7842 | if ((secure_mode) && (flag & ION_SECURE)) |
| 7843 | alloc_data->flags |= ION_SECURE; |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 7844 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7845 | alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 7846 | if (secure_mode && (alloc_data->flags & ION_SECURE)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7847 | alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID); |
| 7848 | rc = ioctl(fd,ION_IOC_ALLOC,alloc_data); |
| 7849 | if (rc || !alloc_data->handle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7850 | DEBUG_PRINT_ERROR("ION ALLOC memory failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7851 | alloc_data->handle = NULL; |
| 7852 | close(fd); |
| 7853 | fd = -ENOMEM; |
| 7854 | return fd; |
| 7855 | } |
| 7856 | fd_data->handle = alloc_data->handle; |
| 7857 | rc = ioctl(fd,ION_IOC_MAP,fd_data); |
| 7858 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7859 | DEBUG_PRINT_ERROR("ION MAP failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7860 | ion_buf_info.ion_alloc_data = *alloc_data; |
| 7861 | ion_buf_info.ion_device_fd = fd; |
| 7862 | ion_buf_info.fd_ion_data = *fd_data; |
| 7863 | free_ion_memory(&ion_buf_info); |
| 7864 | fd_data->fd =-1; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7865 | fd = -ENOMEM; |
| 7866 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7867 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7868 | return fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7869 | } |
| 7870 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7871 | void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info) |
| 7872 | { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7873 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7874 | if (!buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7875 | DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7876 | return; |
| 7877 | } |
| 7878 | if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE, |
| 7879 | &buf_ion_info->ion_alloc_data.handle)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7880 | DEBUG_PRINT_ERROR("ION: free failed" ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7881 | } |
| 7882 | close(buf_ion_info->ion_device_fd); |
| 7883 | buf_ion_info->ion_device_fd = -1; |
| 7884 | buf_ion_info->ion_alloc_data.handle = NULL; |
| 7885 | buf_ion_info->fd_ion_data.fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7886 | } |
| 7887 | #endif |
| 7888 | void omx_vdec::free_output_buffer_header() |
| 7889 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7890 | DEBUG_PRINT_HIGH("ALL output buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7891 | output_use_buffer = false; |
| 7892 | ouput_egl_buffers = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7893 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7894 | if (m_out_mem_ptr) { |
| 7895 | free (m_out_mem_ptr); |
| 7896 | m_out_mem_ptr = NULL; |
| 7897 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7898 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7899 | if (m_platform_list) { |
| 7900 | free(m_platform_list); |
| 7901 | m_platform_list = NULL; |
| 7902 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7903 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7904 | if (drv_ctx.ptr_respbuffer) { |
| 7905 | free (drv_ctx.ptr_respbuffer); |
| 7906 | drv_ctx.ptr_respbuffer = NULL; |
| 7907 | } |
| 7908 | if (drv_ctx.ptr_outputbuffer) { |
| 7909 | free (drv_ctx.ptr_outputbuffer); |
| 7910 | drv_ctx.ptr_outputbuffer = NULL; |
| 7911 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7912 | #ifdef USE_ION |
| 7913 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7914 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7915 | free(drv_ctx.op_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7916 | drv_ctx.op_buf_ion_info = NULL; |
| 7917 | } |
| 7918 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7919 | if (out_dynamic_list) { |
| 7920 | free(out_dynamic_list); |
| 7921 | out_dynamic_list = NULL; |
| 7922 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7923 | } |
| 7924 | |
| 7925 | void omx_vdec::free_input_buffer_header() |
| 7926 | { |
| 7927 | input_use_buffer = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7928 | if (arbitrary_bytes) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7929 | if (m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7930 | DEBUG_PRINT_LOW("Free input Heap Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7931 | free (m_inp_heap_ptr); |
| 7932 | m_inp_heap_ptr = NULL; |
| 7933 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7934 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7935 | if (m_phdr_pmem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7936 | DEBUG_PRINT_LOW("Free input pmem header Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7937 | free (m_phdr_pmem_ptr); |
| 7938 | m_phdr_pmem_ptr = NULL; |
| 7939 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7940 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7941 | if (m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7942 | DEBUG_PRINT_LOW("Free input pmem Pointer area"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7943 | free (m_inp_mem_ptr); |
| 7944 | m_inp_mem_ptr = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7945 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 7946 | /* We just freed all the buffer headers, every thing in m_input_free_q, |
| 7947 | * m_input_pending_q, pdest_frame, and psource_frame is now invalid */ |
Leena Winterrowd | 1d2424a | 2013-08-20 15:26:02 -0700 | [diff] [blame] | 7948 | while (m_input_free_q.m_size) { |
| 7949 | unsigned address, p2, id; |
| 7950 | m_input_free_q.pop_entry(&address, &p2, &id); |
| 7951 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 7952 | while (m_input_pending_q.m_size) { |
| 7953 | unsigned address, p2, id; |
| 7954 | m_input_pending_q.pop_entry(&address, &p2, &id); |
| 7955 | } |
| 7956 | pdest_frame = NULL; |
| 7957 | psource_frame = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7958 | if (drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7959 | DEBUG_PRINT_LOW("Free Driver Context pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7960 | free (drv_ctx.ptr_inputbuffer); |
| 7961 | drv_ctx.ptr_inputbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7962 | } |
| 7963 | #ifdef USE_ION |
| 7964 | if (drv_ctx.ip_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7965 | DEBUG_PRINT_LOW("Free ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7966 | free(drv_ctx.ip_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7967 | drv_ctx.ip_buf_ion_info = NULL; |
| 7968 | } |
| 7969 | #endif |
| 7970 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7971 | |
| 7972 | int omx_vdec::stream_off(OMX_U32 port) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7973 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7974 | enum v4l2_buf_type btype; |
| 7975 | int rc = 0; |
| 7976 | enum v4l2_ports v4l2_port = OUTPUT_PORT; |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7977 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7978 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 7979 | btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7980 | v4l2_port = OUTPUT_PORT; |
| 7981 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 7982 | btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7983 | v4l2_port = CAPTURE_PORT; |
| 7984 | } else if (port == OMX_ALL) { |
| 7985 | int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX); |
| 7986 | int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7987 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7988 | if (!rc_input) |
| 7989 | return rc_input; |
| 7990 | else |
| 7991 | return rc_output; |
| 7992 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7993 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7994 | if (!streaming[v4l2_port]) { |
| 7995 | // already streamed off, warn and move on |
| 7996 | DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port," |
| 7997 | " which is already streamed off", v4l2_port); |
| 7998 | return 0; |
| 7999 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8000 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8001 | DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8002 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8003 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype); |
| 8004 | if (rc) { |
| 8005 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8006 | DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8007 | } else { |
| 8008 | streaming[v4l2_port] = false; |
| 8009 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8010 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8011 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8012 | } |
| 8013 | |
| 8014 | OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 8015 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8016 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8017 | struct v4l2_requestbuffers bufreq; |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 8018 | unsigned int buf_size = 0, extra_data_size = 0, default_extra_data_size = 0; |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8019 | unsigned int final_extra_data_size = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8020 | struct v4l2_format fmt; |
| 8021 | int ret = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8022 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8023 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8024 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 8025 | bufreq.count = 1; |
| 8026 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8027 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8028 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8029 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 8030 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8031 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8032 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8033 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 8034 | } else { |
| 8035 | eRet = OMX_ErrorBadParameter; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8036 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8037 | if (eRet==OMX_ErrorNone) { |
| 8038 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8039 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8040 | if (ret) { |
| 8041 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 8042 | /*TODO: How to handle this case */ |
| 8043 | eRet = OMX_ErrorInsufficientResources; |
| 8044 | return eRet; |
| 8045 | } else { |
| 8046 | buffer_prop->actualcount = bufreq.count; |
| 8047 | buffer_prop->mincount = bufreq.count; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8048 | DEBUG_PRINT_HIGH("Count = %d",bufreq.count); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8049 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8050 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
| 8051 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8052 | |
| 8053 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 8054 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 8055 | |
| 8056 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 8057 | |
| 8058 | update_resolution(fmt.fmt.pix_mp.width, |
| 8059 | fmt.fmt.pix_mp.height, |
| 8060 | fmt.fmt.pix_mp.plane_fmt[0].bytesperline, |
| 8061 | fmt.fmt.pix_mp.plane_fmt[0].reserved[0]); |
| 8062 | if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 8063 | drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8064 | 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] | 8065 | |
| 8066 | if (ret) { |
| 8067 | /*TODO: How to handle this case */ |
| 8068 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 8069 | eRet = OMX_ErrorInsufficientResources; |
| 8070 | } else { |
| 8071 | int extra_idx = 0; |
| 8072 | |
| 8073 | eRet = is_video_session_supported(); |
| 8074 | if (eRet) |
| 8075 | return eRet; |
| 8076 | |
| 8077 | buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage; |
| 8078 | buf_size = buffer_prop->buffer_size; |
| 8079 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 8080 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 8081 | extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage; |
| 8082 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8083 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8084 | return OMX_ErrorBadParameter; |
| 8085 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8086 | |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 8087 | default_extra_data_size = VENUS_EXTRADATA_SIZE( |
| 8088 | drv_ctx.video_resolution.frame_height, |
| 8089 | drv_ctx.video_resolution.frame_width); |
| 8090 | final_extra_data_size = extra_data_size > default_extra_data_size ? |
| 8091 | extra_data_size : default_extra_data_size; |
| 8092 | |
| 8093 | final_extra_data_size = (final_extra_data_size + buffer_prop->alignment - 1) & |
| 8094 | (~(buffer_prop->alignment - 1)); |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 8095 | |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8096 | drv_ctx.extradata_info.size = buffer_prop->actualcount * final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8097 | drv_ctx.extradata_info.count = buffer_prop->actualcount; |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8098 | drv_ctx.extradata_info.buffer_size = final_extra_data_size; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8099 | if (!secure_mode) |
| 8100 | buf_size += final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8101 | buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8102 | DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)", |
| 8103 | buffer_prop->actualcount, buffer_prop->buffer_size, buf_size); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8104 | if (extra_data_size) |
| 8105 | DEBUG_PRINT_LOW("GetBufReq UPDATE: extradata: TotalSize(%d) BufferSize(%d)", |
| 8106 | drv_ctx.extradata_info.size, drv_ctx.extradata_info.buffer_size); |
| 8107 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8108 | if (in_reconfig) // BufReq will be set to driver when port is disabled |
| 8109 | buffer_prop->buffer_size = buf_size; |
| 8110 | else if (buf_size != buffer_prop->buffer_size) { |
| 8111 | buffer_prop->buffer_size = buf_size; |
| 8112 | eRet = set_buffer_req(buffer_prop); |
| 8113 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8114 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8115 | DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)", |
| 8116 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8117 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8118 | } |
| 8119 | |
| 8120 | OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 8121 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8122 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8123 | unsigned buf_size = 0; |
| 8124 | struct v4l2_format fmt; |
| 8125 | struct v4l2_requestbuffers bufreq; |
| 8126 | int ret; |
| 8127 | DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)", |
| 8128 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8129 | buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8130 | if (buf_size != buffer_prop->buffer_size) { |
| 8131 | DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)", |
| 8132 | buffer_prop->buffer_size, buf_size); |
| 8133 | eRet = OMX_ErrorBadParameter; |
| 8134 | } else { |
| 8135 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 8136 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8137 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8138 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8139 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8140 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Shalaj Jain | d3902bb | 2013-10-07 12:42:55 -0700 | [diff] [blame] | 8141 | fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8142 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8143 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8144 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 8145 | } else { |
| 8146 | eRet = OMX_ErrorBadParameter; |
| 8147 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8148 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8149 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 8150 | if (ret) { |
| 8151 | /*TODO: How to handle this case */ |
| 8152 | DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret); |
| 8153 | eRet = OMX_ErrorInsufficientResources; |
| 8154 | } |
| 8155 | |
| 8156 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 8157 | bufreq.count = buffer_prop->actualcount; |
| 8158 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8159 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8160 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8161 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8162 | } else { |
| 8163 | eRet = OMX_ErrorBadParameter; |
| 8164 | } |
| 8165 | |
| 8166 | if (eRet==OMX_ErrorNone) { |
| 8167 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
| 8168 | } |
| 8169 | |
| 8170 | if (ret) { |
| 8171 | DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret); |
| 8172 | /*TODO: How to handle this case */ |
| 8173 | eRet = OMX_ErrorInsufficientResources; |
| 8174 | } else if (bufreq.count < buffer_prop->actualcount) { |
| 8175 | DEBUG_PRINT_ERROR("Driver refused to change the number of buffers" |
| 8176 | " on v4l2 port %d to %d (prefers %d)", bufreq.type, |
| 8177 | buffer_prop->actualcount, bufreq.count); |
| 8178 | eRet = OMX_ErrorInsufficientResources; |
| 8179 | } else { |
| 8180 | if (!client_buffers.update_buffer_req()) { |
| 8181 | DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed"); |
| 8182 | eRet = OMX_ErrorInsufficientResources; |
| 8183 | } |
| 8184 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8185 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8186 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8187 | } |
| 8188 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8189 | OMX_ERRORTYPE omx_vdec::update_picture_resolution() |
| 8190 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8191 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8192 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8193 | } |
| 8194 | |
| 8195 | OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn) |
| 8196 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8197 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8198 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8199 | if (!portDefn) { |
| 8200 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8201 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8202 | DEBUG_PRINT_LOW("omx_vdec::update_portdef"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8203 | portDefn->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8204 | portDefn->nSize = sizeof(portDefn); |
| 8205 | portDefn->eDomain = OMX_PortDomainVideo; |
| 8206 | if (drv_ctx.frame_rate.fps_denominator > 0) |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 8207 | portDefn->format.video.xFramerate = (drv_ctx.frame_rate.fps_numerator / |
| 8208 | drv_ctx.frame_rate.fps_denominator) << 16; //Q16 format |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8209 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8210 | DEBUG_PRINT_ERROR("Error: Divide by zero"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8211 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8212 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8213 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8214 | if (0 == portDefn->nPortIndex) { |
| 8215 | portDefn->eDir = OMX_DirInput; |
| 8216 | portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount; |
| 8217 | portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount; |
| 8218 | portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size; |
| 8219 | portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused; |
| 8220 | portDefn->format.video.eCompressionFormat = eCompressionFormat; |
| 8221 | portDefn->bEnabled = m_inp_bEnabled; |
| 8222 | portDefn->bPopulated = m_inp_bPopulated; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8223 | |
| 8224 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8225 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8226 | } else if (1 == portDefn->nPortIndex) { |
| 8227 | unsigned int buf_size = 0; |
| 8228 | if (!client_buffers.update_buffer_req()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8229 | DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8230 | return OMX_ErrorHardware; |
| 8231 | } |
| 8232 | if (!client_buffers.get_buffer_req(buf_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8233 | DEBUG_PRINT_ERROR("update buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8234 | return OMX_ErrorHardware; |
| 8235 | } |
| 8236 | portDefn->nBufferSize = buf_size; |
| 8237 | portDefn->eDir = OMX_DirOutput; |
| 8238 | portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount; |
| 8239 | portDefn->nBufferCountMin = drv_ctx.op_buf.mincount; |
| 8240 | portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 8241 | portDefn->bEnabled = m_out_bEnabled; |
| 8242 | portDefn->bPopulated = m_out_bPopulated; |
| 8243 | if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8244 | DEBUG_PRINT_ERROR("Error in getting color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8245 | return OMX_ErrorHardware; |
| 8246 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8247 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8248 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8249 | } else { |
| 8250 | portDefn->eDir = OMX_DirMax; |
| 8251 | DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d", |
| 8252 | (int)portDefn->nPortIndex); |
| 8253 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8254 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8255 | if (is_down_scalar_enabled) { |
| 8256 | int ret = 0; |
| 8257 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 8258 | if (ret) { |
| 8259 | DEBUG_PRINT_ERROR("update_portdef : Error in getting port resolution"); |
| 8260 | return OMX_ErrorHardware; |
| 8261 | } else { |
| 8262 | portDefn->format.video.nFrameWidth = fmt.fmt.pix_mp.width; |
| 8263 | portDefn->format.video.nFrameHeight = fmt.fmt.pix_mp.height; |
| 8264 | portDefn->format.video.nStride = fmt.fmt.pix_mp.plane_fmt[0].bytesperline; |
| 8265 | portDefn->format.video.nSliceHeight = fmt.fmt.pix_mp.plane_fmt[0].reserved[0]; |
| 8266 | } |
| 8267 | } else { |
| 8268 | portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height; |
| 8269 | portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width; |
| 8270 | portDefn->format.video.nStride = drv_ctx.video_resolution.stride; |
| 8271 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines; |
| 8272 | } |
| 8273 | |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 8274 | if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 8275 | (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) { |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8276 | portDefn->format.video.nStride = drv_ctx.video_resolution.frame_width; |
| 8277 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height; |
| 8278 | } |
| 8279 | DEBUG_PRINT_HIGH("update_portdef(%lu): Width = %lu Height = %lu Stride = %ld " |
| 8280 | "SliceHeight = %lu eColorFormat = %lu nBufSize %lu nBufCnt %lu", |
| 8281 | portDefn->nPortIndex, |
| 8282 | portDefn->format.video.nFrameWidth, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8283 | portDefn->format.video.nFrameHeight, |
| 8284 | portDefn->format.video.nStride, |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8285 | portDefn->format.video.nSliceHeight, |
| 8286 | portDefn->format.video.eColorFormat, |
| 8287 | portDefn->nBufferSize, |
| 8288 | portDefn->nBufferCountActual); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8289 | |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8290 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8291 | } |
| 8292 | |
| 8293 | OMX_ERRORTYPE omx_vdec::allocate_output_headers() |
| 8294 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8295 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8296 | OMX_BUFFERHEADERTYPE *bufHdr = NULL; |
| 8297 | unsigned i= 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8299 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8300 | DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8301 | int nBufHdrSize = 0; |
| 8302 | int nPlatformEntrySize = 0; |
| 8303 | int nPlatformListSize = 0; |
| 8304 | int nPMEMInfoSize = 0; |
| 8305 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 8306 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 8307 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8308 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8309 | DEBUG_PRINT_LOW("Setting First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8310 | drv_ctx.op_buf.actualcount); |
| 8311 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 8312 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8313 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8314 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 8315 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 8316 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 8317 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 8318 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 8319 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8320 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8321 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8322 | sizeof(OMX_BUFFERHEADERTYPE), |
| 8323 | nPMEMInfoSize, |
| 8324 | nPlatformListSize); |
Deva Ramasubramanian | eb81932 | 2014-07-17 14:23:35 -0700 | [diff] [blame] | 8325 | DEBUG_PRINT_LOW("PE %d bmSize %"PRId64, nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8326 | m_out_bm_count); |
| 8327 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 8328 | // Alloc mem for platform specific info |
| 8329 | char *pPtr=NULL; |
| 8330 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 8331 | nPMEMInfoSize,1); |
| 8332 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \ |
| 8333 | calloc (sizeof(struct vdec_bufferpayload), |
| 8334 | drv_ctx.op_buf.actualcount); |
| 8335 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 8336 | calloc (sizeof (struct vdec_output_frameinfo), |
| 8337 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8338 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 8339 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer"); |
| 8340 | return OMX_ErrorInsufficientResources; |
| 8341 | } |
| 8342 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8343 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8344 | drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \ |
| 8345 | calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8346 | if (!drv_ctx.op_buf_ion_info) { |
| 8347 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 8348 | return OMX_ErrorInsufficientResources; |
| 8349 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8350 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8351 | if (dynamic_buf_mode) { |
| 8352 | out_dynamic_list = (struct dynamic_buf_list *) \ |
| 8353 | calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount); |
| 8354 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8355 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 8356 | && drv_ctx.ptr_respbuffer) { |
| 8357 | bufHdr = m_out_mem_ptr; |
| 8358 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 8359 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 8360 | (((char *) m_platform_list) + nPlatformListSize); |
| 8361 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 8362 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 8363 | pPlatformList = m_platform_list; |
| 8364 | pPlatformEntry = m_platform_entry; |
| 8365 | pPMEMInfo = m_pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8366 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8367 | 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] | 8368 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8369 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8370 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8371 | m_out_mem_ptr,pPlatformEntry); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8372 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8373 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 8374 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 8375 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8376 | // Set the values when we determine the right HxW param |
| 8377 | bufHdr->nAllocLen = 0; |
| 8378 | bufHdr->nFilledLen = 0; |
| 8379 | bufHdr->pAppPrivate = NULL; |
| 8380 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8381 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 8382 | pPlatformEntry->entry = pPMEMInfo; |
| 8383 | // Initialize the Platform List |
| 8384 | pPlatformList->nEntries = 1; |
| 8385 | pPlatformList->entryList = pPlatformEntry; |
| 8386 | // Keep pBuffer NULL till vdec is opened |
| 8387 | bufHdr->pBuffer = NULL; |
| 8388 | pPMEMInfo->offset = 0; |
| 8389 | pPMEMInfo->pmem_fd = 0; |
| 8390 | bufHdr->pPlatformPrivate = pPlatformList; |
| 8391 | drv_ctx.ptr_outputbuffer[i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8392 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8393 | drv_ctx.op_buf_ion_info[i].ion_device_fd =-1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8394 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8395 | /*Create a mapping between buffers*/ |
| 8396 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 8397 | drv_ctx.ptr_respbuffer[i].client_data = (void *) \ |
| 8398 | &drv_ctx.ptr_outputbuffer[i]; |
| 8399 | // Move the buffer and buffer header pointers |
| 8400 | bufHdr++; |
| 8401 | pPMEMInfo++; |
| 8402 | pPlatformEntry++; |
| 8403 | pPlatformList++; |
| 8404 | } |
| 8405 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8406 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8407 | m_out_mem_ptr, pPtr); |
| 8408 | if (m_out_mem_ptr) { |
| 8409 | free(m_out_mem_ptr); |
| 8410 | m_out_mem_ptr = NULL; |
| 8411 | } |
| 8412 | if (pPtr) { |
| 8413 | free(pPtr); |
| 8414 | pPtr = NULL; |
| 8415 | } |
| 8416 | if (drv_ctx.ptr_outputbuffer) { |
| 8417 | free(drv_ctx.ptr_outputbuffer); |
| 8418 | drv_ctx.ptr_outputbuffer = NULL; |
| 8419 | } |
| 8420 | if (drv_ctx.ptr_respbuffer) { |
| 8421 | free(drv_ctx.ptr_respbuffer); |
| 8422 | drv_ctx.ptr_respbuffer = NULL; |
| 8423 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8424 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8425 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8426 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8427 | free(drv_ctx.op_buf_ion_info); |
| 8428 | drv_ctx.op_buf_ion_info = NULL; |
| 8429 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8430 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8431 | eRet = OMX_ErrorInsufficientResources; |
| 8432 | } |
| 8433 | } else { |
| 8434 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8435 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8436 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8437 | } |
| 8438 | |
| 8439 | void omx_vdec::complete_pending_buffer_done_cbs() |
| 8440 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8441 | unsigned p1; |
| 8442 | unsigned p2; |
| 8443 | unsigned ident; |
| 8444 | omx_cmd_queue tmp_q, pending_bd_q; |
| 8445 | pthread_mutex_lock(&m_lock); |
| 8446 | // pop all pending GENERATE FDB from ftb queue |
| 8447 | while (m_ftb_q.m_size) { |
| 8448 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
| 8449 | if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 8450 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8451 | } else { |
| 8452 | tmp_q.insert_entry(p1,p2,ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8453 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8454 | } |
| 8455 | //return all non GENERATE FDB to ftb queue |
| 8456 | while (tmp_q.m_size) { |
| 8457 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8458 | m_ftb_q.insert_entry(p1,p2,ident); |
| 8459 | } |
| 8460 | // pop all pending GENERATE EDB from etb queue |
| 8461 | while (m_etb_q.m_size) { |
| 8462 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 8463 | if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 8464 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8465 | } else { |
| 8466 | tmp_q.insert_entry(p1,p2,ident); |
| 8467 | } |
| 8468 | } |
| 8469 | //return all non GENERATE FDB to etb queue |
| 8470 | while (tmp_q.m_size) { |
| 8471 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8472 | m_etb_q.insert_entry(p1,p2,ident); |
| 8473 | } |
| 8474 | pthread_mutex_unlock(&m_lock); |
| 8475 | // process all pending buffer dones |
| 8476 | while (pending_bd_q.m_size) { |
| 8477 | pending_bd_q.pop_entry(&p1,&p2,&ident); |
| 8478 | switch (ident) { |
| 8479 | case OMX_COMPONENT_GENERATE_EBD: |
| 8480 | if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8481 | DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8482 | omx_report_error (); |
| 8483 | } |
| 8484 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8485 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8486 | case OMX_COMPONENT_GENERATE_FBD: |
| 8487 | if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8488 | DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8489 | omx_report_error (); |
| 8490 | } |
| 8491 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8492 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8493 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8494 | } |
| 8495 | |
| 8496 | void omx_vdec::set_frame_rate(OMX_S64 act_timestamp) |
| 8497 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8498 | OMX_U32 new_frame_interval = 0; |
| 8499 | if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts |
| 8500 | && llabs(act_timestamp - prev_ts) > 2000) { |
| 8501 | new_frame_interval = client_set_fps ? frm_int : |
| 8502 | llabs(act_timestamp - prev_ts); |
Arun Menon | d9e49f8 | 2014-04-23 18:50:26 -0700 | [diff] [blame] | 8503 | if (new_frame_interval != frm_int || frm_int == 0) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8504 | frm_int = new_frame_interval; |
| 8505 | if (frm_int) { |
| 8506 | drv_ctx.frame_rate.fps_numerator = 1e6; |
| 8507 | drv_ctx.frame_rate.fps_denominator = frm_int; |
| 8508 | DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)", |
| 8509 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 8510 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8511 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8512 | /* We need to report the difference between this FBD and the previous FBD |
| 8513 | * back to the driver for clock scaling purposes. */ |
| 8514 | struct v4l2_outputparm oparm; |
| 8515 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 8516 | * per second.*/ |
| 8517 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 8518 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8519 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8520 | struct v4l2_streamparm sparm; |
| 8521 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8522 | sparm.parm.output = oparm; |
| 8523 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 8524 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 8525 | performance might be affected"); |
| 8526 | } |
| 8527 | |
| 8528 | } |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8529 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8530 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8531 | prev_ts = act_timestamp; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8532 | } |
| 8533 | |
| 8534 | void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp) |
| 8535 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8536 | if (rst_prev_ts && VALID_TS(act_timestamp)) { |
| 8537 | prev_ts = act_timestamp; |
| 8538 | rst_prev_ts = false; |
| 8539 | } else if (VALID_TS(prev_ts)) { |
| 8540 | bool codec_cond = (drv_ctx.timestamp_adjust)? |
Deva Ramasubramanian | 5f3cff3 | 2014-12-04 17:13:01 -0800 | [diff] [blame] | 8541 | (!VALID_TS(act_timestamp) || act_timestamp < prev_ts || llabs(act_timestamp - prev_ts) <= 2000) : |
| 8542 | (!VALID_TS(act_timestamp) || act_timestamp <= prev_ts); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8543 | if (frm_int > 0 && codec_cond) { |
| 8544 | DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp); |
| 8545 | act_timestamp = prev_ts + frm_int; |
| 8546 | DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp); |
| 8547 | prev_ts = act_timestamp; |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8548 | } else { |
| 8549 | if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) { |
| 8550 | // ensure that timestamps can never step backwards when in display order |
| 8551 | act_timestamp = prev_ts; |
| 8552 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8553 | set_frame_rate(act_timestamp); |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8554 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8555 | } else if (frm_int > 0) // In this case the frame rate was set along |
| 8556 | { // with the port definition, start ts with 0 |
| 8557 | act_timestamp = prev_ts = 0; // and correct if a valid ts is received. |
| 8558 | rst_prev_ts = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8559 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8560 | } |
| 8561 | |
| 8562 | void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 8563 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8564 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL; |
| 8565 | OMX_U32 num_conceal_MB = 0; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8566 | OMX_TICKS time_stamp = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8567 | OMX_U32 frame_rate = 0; |
| 8568 | int consumed_len = 0; |
| 8569 | OMX_U32 num_MB_in_frame; |
| 8570 | OMX_U32 recovery_sei_flags = 1; |
| 8571 | int enable = 0; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8572 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8573 | int buf_index = p_buf_hdr - m_out_mem_ptr; |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 8574 | if (buf_index >= drv_ctx.extradata_info.count) { |
| 8575 | DEBUG_PRINT_ERROR("handle_extradata: invalid index(%d) max(%d)", |
| 8576 | buf_index, drv_ctx.extradata_info.count); |
| 8577 | return; |
| 8578 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8579 | struct msm_vidc_panscan_window_payload *panscan_payload = NULL; |
| 8580 | OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) + |
| 8581 | p_buf_hdr->nOffset; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8582 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8583 | if (!drv_ctx.extradata_info.uaddr) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8584 | DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8585 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8586 | } |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8587 | |
| 8588 | if (!secure_mode && (drv_ctx.extradata_info.buffer_size > (p_buf_hdr->nAllocLen - p_buf_hdr->nFilledLen)) ) { |
| 8589 | DEBUG_PRINT_ERROR("Error: Insufficient size allocated for extra-data"); |
| 8590 | p_extra = NULL; |
| 8591 | return; |
| 8592 | } |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8593 | if (!secure_mode) |
| 8594 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8595 | ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3)); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8596 | else |
| 8597 | p_extra = m_other_extradata; |
| 8598 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8599 | char *p_extradata = drv_ctx.extradata_info.uaddr + buf_index * drv_ctx.extradata_info.buffer_size; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8600 | if (!secure_mode && ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))) { |
| 8601 | DEBUG_PRINT_ERROR("Error: out of bound memory access by p_extra"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8602 | p_extra = NULL; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8603 | return; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8604 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8605 | OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8606 | if (data && p_extra) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8607 | while ((consumed_len < drv_ctx.extradata_info.buffer_size) |
| 8608 | && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 8609 | if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8610 | DEBUG_PRINT_LOW("Invalid extra data size"); |
| 8611 | break; |
| 8612 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8613 | DEBUG_PRINT_LOW("handle_extradata: eType = %d", data->eType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8614 | switch ((unsigned long)data->eType) { |
| 8615 | case EXTRADATA_INTERLACE_VIDEO: |
| 8616 | struct msm_vidc_interlace_payload *payload; |
| 8617 | payload = (struct msm_vidc_interlace_payload *)data->data; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8618 | if (payload) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8619 | enable = 1; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8620 | switch (payload->format) { |
| 8621 | case INTERLACE_FRAME_PROGRESSIVE: |
| 8622 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 8623 | enable = 0; |
| 8624 | break; |
| 8625 | case INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST: |
| 8626 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8627 | break; |
| 8628 | case INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST: |
| 8629 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameBottomFieldFirst; |
| 8630 | break; |
| 8631 | default: |
| 8632 | DEBUG_PRINT_LOW("default case - set interlace to topfield"); |
| 8633 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8634 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8635 | } |
| 8636 | if (m_enable_android_native_buffers) |
| 8637 | setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle, |
| 8638 | PP_PARAM_INTERLACED, (void*)&enable); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8639 | if (client_extradata & OMX_INTERLACE_EXTRADATA) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8640 | append_interlace_extradata(p_extra, payload->format, |
| 8641 | p_buf_hdr->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8642 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8643 | } |
| 8644 | break; |
| 8645 | case EXTRADATA_FRAME_RATE: |
| 8646 | struct msm_vidc_framerate_payload *frame_rate_payload; |
| 8647 | frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data; |
| 8648 | frame_rate = frame_rate_payload->frame_rate; |
| 8649 | break; |
| 8650 | case EXTRADATA_TIMESTAMP: |
| 8651 | struct msm_vidc_ts_payload *time_stamp_payload; |
| 8652 | time_stamp_payload = (struct msm_vidc_ts_payload *)data->data; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8653 | time_stamp = time_stamp_payload->timestamp_lo; |
| 8654 | time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32); |
| 8655 | p_buf_hdr->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8656 | break; |
| 8657 | case EXTRADATA_NUM_CONCEALED_MB: |
| 8658 | struct msm_vidc_concealmb_payload *conceal_mb_payload; |
| 8659 | conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data; |
| 8660 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8661 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8662 | num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0); |
| 8663 | break; |
| 8664 | case EXTRADATA_INDEX: |
| 8665 | int *etype; |
| 8666 | etype = (int *)(data->data); |
| 8667 | if (etype && *etype == EXTRADATA_ASPECT_RATIO) { |
| 8668 | struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload; |
| 8669 | aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype); |
| 8670 | if (aspect_ratio_payload) { |
| 8671 | ((struct vdec_output_frameinfo *) |
| 8672 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width; |
| 8673 | ((struct vdec_output_frameinfo *) |
| 8674 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height; |
| 8675 | } |
| 8676 | } |
| 8677 | break; |
| 8678 | case EXTRADATA_RECOVERY_POINT_SEI: |
| 8679 | struct msm_vidc_recoverysei_payload *recovery_sei_payload; |
| 8680 | recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data; |
| 8681 | recovery_sei_flags = recovery_sei_payload->flags; |
| 8682 | if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) { |
| 8683 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8684 | DEBUG_PRINT_HIGH(""); |
| 8685 | DEBUG_PRINT_HIGH("***************************************************"); |
| 8686 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 8687 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8688 | } |
| 8689 | break; |
| 8690 | case EXTRADATA_PANSCAN_WINDOW: |
| 8691 | panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data; |
| 8692 | break; |
| 8693 | case EXTRADATA_MPEG2_SEQDISP: |
| 8694 | struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload; |
| 8695 | seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data; |
| 8696 | if (seqdisp_payload) { |
| 8697 | m_disp_hor_size = seqdisp_payload->disp_width; |
| 8698 | m_disp_vert_size = seqdisp_payload->disp_height; |
| 8699 | } |
| 8700 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8701 | case EXTRADATA_S3D_FRAME_PACKING: |
| 8702 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload; |
| 8703 | s3d_frame_packing_payload = (struct msm_vidc_s3d_frame_packing_payload *)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8704 | if (client_extradata & OMX_FRAMEPACK_EXTRADATA) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8705 | append_framepack_extradata(p_extra, s3d_frame_packing_payload); |
| 8706 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8707 | } |
| 8708 | break; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8709 | case EXTRADATA_FRAME_QP: |
| 8710 | struct msm_vidc_frame_qp_payload *qp_payload; |
| 8711 | qp_payload = (struct msm_vidc_frame_qp_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8712 | if (client_extradata & OMX_QP_EXTRADATA) { |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8713 | append_qp_extradata(p_extra, qp_payload); |
| 8714 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8715 | } |
| 8716 | break; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8717 | case EXTRADATA_FRAME_BITS_INFO: |
| 8718 | struct msm_vidc_frame_bits_info_payload *bits_info_payload; |
| 8719 | bits_info_payload = (struct msm_vidc_frame_bits_info_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8720 | if (client_extradata & OMX_BITSINFO_EXTRADATA) { |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8721 | append_bitsinfo_extradata(p_extra, bits_info_payload); |
| 8722 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8723 | } |
| 8724 | break; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8725 | case EXTRADATA_STREAM_USERDATA: |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8726 | if (client_extradata & OMX_EXTNUSER_EXTRADATA) { |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8727 | append_user_extradata(p_extra, data); |
| 8728 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8729 | } |
| 8730 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8731 | default: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8732 | DEBUG_PRINT_LOW("Unrecognized extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8733 | goto unrecognized_extradata; |
| 8734 | } |
| 8735 | consumed_len += data->nSize; |
| 8736 | data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize); |
| 8737 | } |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8738 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8739 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
| 8740 | append_frame_info_extradata(p_extra, |
| 8741 | 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] | 8742 | time_stamp, panscan_payload,&((struct vdec_output_frameinfo *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8743 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info); |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8744 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8745 | } |
| 8746 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8747 | unrecognized_extradata: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8748 | if (client_extradata && p_extra) { |
| 8749 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8750 | append_terminator_extradata(p_extra); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8751 | } |
| 8752 | |
Arun Menon | fd72393 | 2014-05-30 17:56:31 -0700 | [diff] [blame] | 8753 | if (secure_mode && p_extradata && m_other_extradata) { |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8754 | struct vdec_output_frameinfo *ptr_extradatabuff = NULL; |
| 8755 | memcpy(p_extradata, m_other_extradata, drv_ctx.extradata_info.buffer_size); |
| 8756 | ptr_extradatabuff = (struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate; |
| 8757 | ptr_extradatabuff->metadata_info.metabufaddr = (void *)p_extradata; |
| 8758 | ptr_extradatabuff->metadata_info.size = drv_ctx.extradata_info.buffer_size; |
| 8759 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8760 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8761 | } |
| 8762 | |
Vinay Kalia | 9c00cae | 2012-12-06 16:08:20 -0800 | [diff] [blame] | 8763 | OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8764 | bool is_internal, bool enable) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8765 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8766 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 8767 | struct v4l2_control control; |
| 8768 | if (m_state != OMX_StateLoaded) { |
| 8769 | DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only"); |
| 8770 | return OMX_ErrorIncorrectStateOperation; |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 8771 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8772 | 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] | 8773 | client_extradata, requested_extradata, enable, is_internal); |
| 8774 | |
| 8775 | if (!is_internal) { |
| 8776 | if (enable) |
| 8777 | client_extradata |= requested_extradata; |
| 8778 | else |
| 8779 | client_extradata = client_extradata & ~requested_extradata; |
| 8780 | } |
| 8781 | |
| 8782 | if (enable) { |
| 8783 | if (requested_extradata & OMX_INTERLACE_EXTRADATA) { |
| 8784 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8785 | control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO; |
| 8786 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8787 | DEBUG_PRINT_HIGH("Failed to set interlaced extradata." |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8788 | " Quality of interlaced clips might be impacted."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8789 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8790 | } |
| 8791 | if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8792 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8793 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE; |
| 8794 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8795 | DEBUG_PRINT_HIGH("Failed to set framerate extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8796 | } |
| 8797 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8798 | control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB; |
| 8799 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8800 | DEBUG_PRINT_HIGH("Failed to set concealed MB extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8801 | } |
| 8802 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8803 | control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI; |
| 8804 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8805 | DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8806 | } |
| 8807 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8808 | control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW; |
| 8809 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8810 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8811 | } |
| 8812 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8813 | control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO; |
| 8814 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8815 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8816 | } |
| 8817 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 8818 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8819 | control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP; |
| 8820 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8821 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8822 | } |
| 8823 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8824 | } |
| 8825 | if (requested_extradata & OMX_TIMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8826 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8827 | control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP; |
| 8828 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8829 | DEBUG_PRINT_HIGH("Failed to set timeinfo extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8830 | } |
| 8831 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8832 | if (requested_extradata & OMX_FRAMEPACK_EXTRADATA) { |
| 8833 | if (output_capability == V4L2_PIX_FMT_H264) { |
| 8834 | DEBUG_PRINT_HIGH("enable OMX_FRAMEPACK_EXTRADATA"); |
| 8835 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8836 | control.value = V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING; |
| 8837 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8838 | DEBUG_PRINT_HIGH("Failed to set S3D_FRAME_PACKING extradata"); |
| 8839 | } |
| 8840 | } else { |
| 8841 | DEBUG_PRINT_HIGH("OMX_FRAMEPACK_EXTRADATA supported for H264 only"); |
| 8842 | } |
| 8843 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8844 | if (requested_extradata & OMX_QP_EXTRADATA) { |
| 8845 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8846 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP; |
| 8847 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8848 | DEBUG_PRINT_HIGH("Failed to set QP extradata"); |
| 8849 | } |
| 8850 | } |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8851 | if (requested_extradata & OMX_BITSINFO_EXTRADATA) { |
| 8852 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8853 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO; |
| 8854 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8855 | DEBUG_PRINT_HIGH("Failed to set frame bits info extradata"); |
| 8856 | } |
| 8857 | } |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8858 | if (requested_extradata & OMX_EXTNUSER_EXTRADATA) { |
| 8859 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8860 | control.value = V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA; |
| 8861 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8862 | DEBUG_PRINT_HIGH("Failed to set stream userdata extradata"); |
| 8863 | } |
| 8864 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8865 | } |
| 8866 | ret = get_buffer_req(&drv_ctx.op_buf); |
| 8867 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8868 | } |
| 8869 | |
| 8870 | OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8871 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8872 | OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0; |
| 8873 | OMX_U8 *data_ptr = extra->data, data = 0; |
| 8874 | while (byte_count < extra->nDataSize) { |
| 8875 | data = *data_ptr; |
| 8876 | while (data) { |
| 8877 | num_MB += (data&0x01); |
| 8878 | data >>= 1; |
| 8879 | } |
| 8880 | data_ptr++; |
| 8881 | byte_count++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8882 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8883 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8884 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8885 | 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] | 8886 | } |
| 8887 | |
| 8888 | void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8889 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8890 | if (!m_debug_extradata) |
| 8891 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8892 | |
| 8893 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8894 | "============== Extra Data ==============\n" |
| 8895 | " Size: %lu\n" |
| 8896 | " Version: %lu\n" |
| 8897 | " PortIndex: %lu\n" |
| 8898 | " Type: %x\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8899 | " DataSize: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8900 | extra->nSize, extra->nVersion.nVersion, |
| 8901 | extra->nPortIndex, extra->eType, extra->nDataSize); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8902 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8903 | if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) { |
| 8904 | OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 8905 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8906 | "------ Interlace Format ------\n" |
| 8907 | " Size: %lu\n" |
| 8908 | " Version: %lu\n" |
| 8909 | " PortIndex: %lu\n" |
| 8910 | " Is Interlace Format: %d\n" |
| 8911 | " Interlace Formats: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8912 | "=========== End of Interlace ===========", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8913 | intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex, |
| 8914 | intfmt->bInterlaceFormat, intfmt->nInterlaceFormats); |
| 8915 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) { |
| 8916 | OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 8917 | |
| 8918 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8919 | "-------- Frame Format --------\n" |
| 8920 | " Picture Type: %d\n" |
| 8921 | " Interlace Type: %d\n" |
| 8922 | " Pan Scan Total Frame Num: %lu\n" |
| 8923 | " Concealed Macro Blocks: %lu\n" |
| 8924 | " frame rate: %lu\n" |
| 8925 | " Time Stamp: %llu\n" |
| 8926 | " Aspect Ratio X: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8927 | " Aspect Ratio Y: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8928 | fminfo->ePicType, |
| 8929 | fminfo->interlaceType, |
| 8930 | fminfo->panScan.numWindows, |
| 8931 | fminfo->nConcealedMacroblocks, |
| 8932 | fminfo->nFrameRate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8933 | fminfo->nTimeStamp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8934 | fminfo->aspectRatio.aspectRatioX, |
| 8935 | fminfo->aspectRatio.aspectRatioY); |
| 8936 | |
| 8937 | for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) { |
| 8938 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8939 | "------------------------------" |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8940 | " Pan Scan Frame Num: %lu\n" |
| 8941 | " Rectangle x: %ld\n" |
| 8942 | " Rectangle y: %ld\n" |
| 8943 | " Rectangle dx: %ld\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8944 | " Rectangle dy: %ld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8945 | i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y, |
| 8946 | fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy); |
| 8947 | } |
| 8948 | |
| 8949 | DEBUG_PRINT_HIGH("========= End of Frame Format =========="); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8950 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement) { |
| 8951 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 8952 | DEBUG_PRINT_HIGH( |
| 8953 | "------------------ Framepack Format ----------\n" |
| 8954 | " id: %lu \n" |
| 8955 | " cancel_flag: %lu \n" |
| 8956 | " type: %lu \n" |
| 8957 | " quincunx_sampling_flagFormat: %lu \n" |
| 8958 | " content_interpretation_type: %lu \n" |
| 8959 | " content_interpretation_type: %lu \n" |
| 8960 | " spatial_flipping_flag: %lu \n" |
| 8961 | " frame0_flipped_flag: %lu \n" |
| 8962 | " field_views_flag: %lu \n" |
| 8963 | " current_frame_is_frame0_flag: %lu \n" |
| 8964 | " frame0_self_contained_flag: %lu \n" |
| 8965 | " frame1_self_contained_flag: %lu \n" |
| 8966 | " frame0_grid_position_x: %lu \n" |
| 8967 | " frame0_grid_position_y: %lu \n" |
| 8968 | " frame1_grid_position_x: %lu \n" |
| 8969 | " frame1_grid_position_y: %lu \n" |
| 8970 | " reserved_byte: %lu \n" |
| 8971 | " repetition_period: %lu \n" |
| 8972 | " extension_flag: %lu \n" |
| 8973 | "================== End of Framepack ===========", |
| 8974 | framepack->id, |
| 8975 | framepack->cancel_flag, |
| 8976 | framepack->type, |
| 8977 | framepack->quincunx_sampling_flag, |
| 8978 | framepack->content_interpretation_type, |
| 8979 | framepack->spatial_flipping_flag, |
| 8980 | framepack->frame0_flipped_flag, |
| 8981 | framepack->field_views_flag, |
| 8982 | framepack->current_frame_is_frame0_flag, |
| 8983 | framepack->frame0_self_contained_flag, |
| 8984 | framepack->frame1_self_contained_flag, |
| 8985 | framepack->frame0_grid_position_x, |
| 8986 | framepack->frame0_grid_position_y, |
| 8987 | framepack->frame1_grid_position_x, |
| 8988 | framepack->frame1_grid_position_y, |
| 8989 | framepack->reserved_byte, |
| 8990 | framepack->repetition_period, |
| 8991 | framepack->extension_flag); |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8992 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataQP) { |
| 8993 | OMX_QCOM_EXTRADATA_QP * qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 8994 | DEBUG_PRINT_HIGH( |
| 8995 | "---- QP (Frame quantization parameter) ----\n" |
| 8996 | " Frame QP: %lu \n" |
| 8997 | "================ End of QP ================\n", |
| 8998 | qp->nQP); |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8999 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo) { |
| 9000 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = (OMX_QCOM_EXTRADATA_BITS_INFO *)extra->data; |
| 9001 | DEBUG_PRINT_HIGH( |
| 9002 | "--------- Input bits information --------\n" |
| 9003 | " Header bits: %lu \n" |
| 9004 | " Frame bits: %lu \n" |
| 9005 | "===== End of Input bits information =====\n", |
| 9006 | bits->header_bits, bits->frame_bits); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9007 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData) { |
| 9008 | OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)extra->data; |
| 9009 | OMX_U8 *data_ptr = (OMX_U8 *)userdata->data; |
| 9010 | OMX_U32 userdata_size = extra->nDataSize - sizeof(userdata->type); |
| 9011 | OMX_U32 i = 0; |
| 9012 | DEBUG_PRINT_HIGH( |
| 9013 | "-------------- Userdata -------------\n" |
| 9014 | " Stream userdata type: %d\n" |
| 9015 | " userdata size: %d\n" |
| 9016 | " STREAM_USERDATA:", |
| 9017 | userdata->type, userdata_size); |
| 9018 | for (i = 0; i < userdata_size; i+=4) { |
| 9019 | DEBUG_PRINT_HIGH(" %x %x %x %x", |
| 9020 | data_ptr[i], data_ptr[i+1], |
| 9021 | data_ptr[i+2], data_ptr[i+3]); |
| 9022 | } |
| 9023 | DEBUG_PRINT_HIGH( |
| 9024 | "=========== End of Userdata ==========="); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9025 | } else if (extra->eType == OMX_ExtraDataNone) { |
| 9026 | DEBUG_PRINT_HIGH("========== End of Terminator ==========="); |
| 9027 | } else { |
| 9028 | DEBUG_PRINT_HIGH("======= End of Driver Extradata ========"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9029 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9030 | } |
| 9031 | |
| 9032 | void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9033 | OMX_U32 interlaced_format_type, bool is_mbaff) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9034 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9035 | OMX_STREAMINTERLACEFORMAT *interlace_format; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9036 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9037 | if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) { |
| 9038 | return; |
| 9039 | } |
| 9040 | extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE; |
| 9041 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9042 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9043 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat; |
| 9044 | extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 9045 | interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 9046 | interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 9047 | interlace_format->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9048 | interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9049 | |
| 9050 | if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !is_mbaff) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9051 | interlace_format->bInterlaceFormat = OMX_FALSE; |
| 9052 | interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive; |
| 9053 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9054 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9055 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9056 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9057 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9058 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9059 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9060 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameBottomFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9061 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9062 | } else { |
| 9063 | interlace_format->bInterlaceFormat = OMX_TRUE; |
| 9064 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
| 9065 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 9066 | } |
| 9067 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9068 | } |
| 9069 | |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9070 | void omx_vdec::fill_aspect_ratio_info( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9071 | struct vdec_aspectratioinfo *aspect_ratio_info, |
| 9072 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info) |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9073 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9074 | m_extradata = frame_info; |
| 9075 | m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width; |
| 9076 | m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9077 | DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9078 | m_extradata->aspectRatio.aspectRatioY); |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9079 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9080 | |
| 9081 | void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9082 | 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] | 9083 | OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload, |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9084 | struct vdec_aspectratioinfo *aspect_ratio_info) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9085 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9086 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL; |
| 9087 | struct msm_vidc_panscan_window *panscan_window; |
| 9088 | if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) { |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9089 | return; |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9090 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9091 | extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE; |
| 9092 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9093 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9094 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo; |
| 9095 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO); |
| 9096 | frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 9097 | switch (picture_type) { |
| 9098 | case PICTURE_TYPE_I: |
| 9099 | frame_info->ePicType = OMX_VIDEO_PictureTypeI; |
| 9100 | break; |
| 9101 | case PICTURE_TYPE_P: |
| 9102 | frame_info->ePicType = OMX_VIDEO_PictureTypeP; |
| 9103 | break; |
| 9104 | case PICTURE_TYPE_B: |
| 9105 | frame_info->ePicType = OMX_VIDEO_PictureTypeB; |
| 9106 | break; |
| 9107 | default: |
| 9108 | frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0; |
| 9109 | } |
| 9110 | if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst) |
| 9111 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 9112 | else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst) |
| 9113 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 9114 | else |
| 9115 | frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 9116 | memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio)); |
| 9117 | frame_info->nConcealedMacroblocks = num_conceal_mb; |
| 9118 | frame_info->nFrameRate = frame_rate; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9119 | frame_info->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9120 | frame_info->panScan.numWindows = 0; |
| 9121 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 9122 | if (m_disp_hor_size && m_disp_vert_size) { |
| 9123 | frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size; |
| 9124 | frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size; |
Pushkaraj Patil | 5e6ebd9 | 2014-03-10 10:29:14 +0530 | [diff] [blame] | 9125 | } else { |
| 9126 | frame_info->displayAspectRatio.displayHorizontalSize = 0; |
| 9127 | frame_info->displayAspectRatio.displayVerticalSize = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9128 | } |
| 9129 | } |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9130 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9131 | if (panscan_payload) { |
| 9132 | frame_info->panScan.numWindows = panscan_payload->num_panscan_windows; |
| 9133 | panscan_window = &panscan_payload->wnd[0]; |
| 9134 | for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) { |
| 9135 | frame_info->panScan.window[i].x = panscan_window->panscan_window_width; |
| 9136 | frame_info->panScan.window[i].y = panscan_window->panscan_window_height; |
| 9137 | frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset; |
| 9138 | frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset; |
| 9139 | panscan_window++; |
| 9140 | } |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9141 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9142 | fill_aspect_ratio_info(aspect_ratio_info, frame_info); |
| 9143 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9144 | } |
| 9145 | |
| 9146 | void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9147 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9148 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL; |
| 9149 | extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE; |
| 9150 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9151 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9152 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef; |
| 9153 | extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
| 9154 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data; |
| 9155 | *portDefn = m_port_def; |
| 9156 | DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu " |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9157 | "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9158 | portDefn->format.video.nFrameWidth, |
| 9159 | portDefn->format.video.nStride, |
| 9160 | portDefn->format.video.nSliceHeight); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9161 | } |
| 9162 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 9163 | void omx_vdec::append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9164 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload) |
| 9165 | { |
| 9166 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack; |
| 9167 | if (FRAME_PACK_SIZE*sizeof(OMX_U32) != sizeof(struct msm_vidc_s3d_frame_packing_payload)) { |
| 9168 | DEBUG_PRINT_ERROR("frame packing size mismatch"); |
| 9169 | return; |
| 9170 | } |
| 9171 | extra->nSize = OMX_FRAMEPACK_EXTRADATA_SIZE; |
| 9172 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9173 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9174 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement; |
| 9175 | extra->nDataSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9176 | framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 9177 | framepack->nSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9178 | framepack->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9179 | framepack->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9180 | memcpy(&framepack->id, s3d_frame_packing_payload, |
| 9181 | sizeof(struct msm_vidc_s3d_frame_packing_payload)); |
| 9182 | memcpy(&m_frame_pack_arrangement, framepack, |
| 9183 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
| 9184 | print_debug_extradata(extra); |
| 9185 | } |
| 9186 | |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 9187 | void omx_vdec::append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9188 | struct msm_vidc_frame_qp_payload *qp_payload) |
| 9189 | { |
| 9190 | OMX_QCOM_EXTRADATA_QP * qp = NULL; |
| 9191 | if (!qp_payload) { |
| 9192 | DEBUG_PRINT_ERROR("QP payload is NULL"); |
| 9193 | return; |
| 9194 | } |
| 9195 | extra->nSize = OMX_QP_EXTRADATA_SIZE; |
| 9196 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9197 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9198 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataQP; |
| 9199 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_QP); |
| 9200 | qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 9201 | qp->nQP = qp_payload->frame_qp; |
| 9202 | print_debug_extradata(extra); |
| 9203 | } |
| 9204 | |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 9205 | void omx_vdec::append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9206 | struct msm_vidc_frame_bits_info_payload *bits_payload) |
| 9207 | { |
| 9208 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = NULL; |
| 9209 | if (!bits_payload) { |
| 9210 | DEBUG_PRINT_ERROR("bits info payload is NULL"); |
| 9211 | return; |
| 9212 | } |
| 9213 | extra->nSize = OMX_BITSINFO_EXTRADATA_SIZE; |
| 9214 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9215 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9216 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo; |
| 9217 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_BITS_INFO); |
| 9218 | bits = (OMX_QCOM_EXTRADATA_BITS_INFO*)extra->data; |
| 9219 | bits->frame_bits = bits_payload->frame_bits; |
| 9220 | bits->header_bits = bits_payload->header_bits; |
| 9221 | print_debug_extradata(extra); |
| 9222 | } |
| 9223 | |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9224 | void omx_vdec::append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9225 | OMX_OTHER_EXTRADATATYPE *p_user) |
| 9226 | { |
| 9227 | int userdata_size = 0; |
| 9228 | struct msm_vidc_stream_userdata_payload *userdata_payload = NULL; |
| 9229 | userdata_payload = |
| 9230 | (struct msm_vidc_stream_userdata_payload *)p_user->data; |
| 9231 | userdata_size = p_user->nDataSize; |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 9232 | extra->nSize = OMX_USERDATA_EXTRADATA_SIZE + p_user->nSize; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9233 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9234 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9235 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData; |
| 9236 | extra->nDataSize = userdata_size; |
| 9237 | if (extra->data && p_user->data && extra->nDataSize) |
| 9238 | memcpy(extra->data, p_user->data, extra->nDataSize); |
| 9239 | print_debug_extradata(extra); |
| 9240 | } |
| 9241 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9242 | void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9243 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9244 | if (!client_extradata) { |
| 9245 | return; |
| 9246 | } |
| 9247 | extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE); |
| 9248 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9249 | extra->eType = OMX_ExtraDataNone; |
| 9250 | extra->nDataSize = 0; |
| 9251 | extra->data[0] = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9252 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9253 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9254 | } |
| 9255 | |
| 9256 | OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index) |
| 9257 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9258 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9259 | if (index >= drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9260 | DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9261 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9262 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9263 | if (m_desc_buffer_ptr == NULL) { |
| 9264 | m_desc_buffer_ptr = (desc_buffer_hdr*) \ |
| 9265 | calloc( (sizeof(desc_buffer_hdr)), |
| 9266 | drv_ctx.ip_buf.actualcount); |
| 9267 | if (m_desc_buffer_ptr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9268 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9269 | return OMX_ErrorInsufficientResources; |
| 9270 | } |
| 9271 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9272 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9273 | m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8)); |
| 9274 | if (m_desc_buffer_ptr[index].buf_addr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9275 | DEBUG_PRINT_ERROR("desc buffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9276 | return OMX_ErrorInsufficientResources; |
| 9277 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9278 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9279 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9280 | } |
| 9281 | |
| 9282 | void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset) |
| 9283 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9284 | DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries); |
| 9285 | if (m_demux_entries < 8192) { |
| 9286 | m_demux_offsets[m_demux_entries++] = address_offset; |
| 9287 | } |
| 9288 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9289 | } |
| 9290 | |
| 9291 | void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr) |
| 9292 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9293 | OMX_U32 bytes_to_parse = buf_hdr->nFilledLen; |
| 9294 | OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset; |
| 9295 | OMX_U32 index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9296 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9297 | m_demux_entries = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9299 | while (index < bytes_to_parse) { |
| 9300 | if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9301 | (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) || |
| 9302 | ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9303 | (buf[index+2] == 0x01)) ) { |
| 9304 | //Found start code, insert address offset |
| 9305 | insert_demux_addr_offset(index); |
| 9306 | if (buf[index+2] == 0x01) // 3 byte start code |
| 9307 | index += 3; |
| 9308 | else //4 byte start code |
| 9309 | index += 4; |
| 9310 | } else |
| 9311 | index++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9312 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9313 | DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries); |
| 9314 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9315 | } |
| 9316 | |
| 9317 | OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 9318 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9319 | //fix this, handle 3 byte start code, vc1 terminator entry |
| 9320 | OMX_U8 *p_demux_data = NULL; |
| 9321 | OMX_U32 desc_data = 0; |
| 9322 | OMX_U32 start_addr = 0; |
| 9323 | OMX_U32 nal_size = 0; |
| 9324 | OMX_U32 suffix_byte = 0; |
| 9325 | OMX_U32 demux_index = 0; |
| 9326 | OMX_U32 buffer_index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9327 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9328 | if (m_desc_buffer_ptr == NULL) { |
| 9329 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries."); |
| 9330 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9331 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9332 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9333 | buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
| 9334 | if (buffer_index > drv_ctx.ip_buf.actualcount) { |
| 9335 | DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index); |
| 9336 | return OMX_ErrorBadParameter; |
| 9337 | } |
| 9338 | |
| 9339 | p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr; |
| 9340 | |
| 9341 | if ( ((OMX_U8*)p_demux_data == NULL) || |
| 9342 | ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) { |
| 9343 | DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries."); |
| 9344 | return OMX_ErrorBadParameter; |
| 9345 | } else { |
| 9346 | for (; demux_index < m_demux_entries; demux_index++) { |
| 9347 | desc_data = 0; |
| 9348 | start_addr = m_demux_offsets[demux_index]; |
| 9349 | if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) { |
| 9350 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3]; |
| 9351 | } else { |
| 9352 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4]; |
| 9353 | } |
| 9354 | if (demux_index < (m_demux_entries - 1)) { |
| 9355 | nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2; |
| 9356 | } else { |
| 9357 | nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2; |
| 9358 | } |
| 9359 | DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)", |
| 9360 | (void *)start_addr, |
| 9361 | suffix_byte, |
| 9362 | nal_size, |
| 9363 | demux_index); |
| 9364 | desc_data = (start_addr >> 3) << 1; |
| 9365 | desc_data |= (start_addr & 7) << 21; |
| 9366 | desc_data |= suffix_byte << 24; |
| 9367 | |
| 9368 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9369 | memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32)); |
| 9370 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9371 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9372 | |
| 9373 | p_demux_data += 16; |
| 9374 | } |
| 9375 | if (codec_type_parse == CODEC_TYPE_VC1) { |
| 9376 | DEBUG_PRINT_LOW("VC1 terminator entry"); |
| 9377 | desc_data = 0; |
| 9378 | desc_data = 0x82 << 24; |
| 9379 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9380 | memset(p_demux_data + 4, 0, sizeof(OMX_U32)); |
| 9381 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9382 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9383 | p_demux_data += 16; |
| 9384 | m_demux_entries++; |
| 9385 | } |
| 9386 | //Add zero word to indicate end of descriptors |
| 9387 | memset(p_demux_data, 0, sizeof(OMX_U32)); |
| 9388 | |
| 9389 | m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32); |
| 9390 | DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size); |
| 9391 | } |
| 9392 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 9393 | m_demux_entries = 0; |
| 9394 | DEBUG_PRINT_LOW("Demux table complete!"); |
| 9395 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9396 | } |
| 9397 | |
Deva Ramasubramanian | 9403f02 | 2012-11-28 18:27:53 -0800 | [diff] [blame] | 9398 | OMX_ERRORTYPE omx_vdec::createDivxDrmContext() |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9399 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9400 | OMX_ERRORTYPE err = OMX_ErrorNone; |
| 9401 | iDivXDrmDecrypt = DivXDrmDecrypt::Create(); |
| 9402 | if (iDivXDrmDecrypt) { |
| 9403 | OMX_ERRORTYPE err = iDivXDrmDecrypt->Init(); |
| 9404 | if (err!=OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9405 | DEBUG_PRINT_ERROR("ERROR :iDivXDrmDecrypt->Init %d", err); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9406 | delete iDivXDrmDecrypt; |
| 9407 | iDivXDrmDecrypt = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9408 | } |
| 9409 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9410 | DEBUG_PRINT_ERROR("Unable to Create DIVX DRM"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9411 | err = OMX_ErrorUndefined; |
| 9412 | } |
| 9413 | return err; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9414 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9415 | |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9416 | omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf() |
| 9417 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9418 | enabled = false; |
| 9419 | omx = NULL; |
| 9420 | init_members(); |
| 9421 | ColorFormat = OMX_COLOR_FormatMax; |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9422 | dest_format = YCbCr420P; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9423 | } |
| 9424 | |
| 9425 | void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client) |
| 9426 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9427 | omx = reinterpret_cast<omx_vdec*>(client); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9428 | } |
| 9429 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9430 | void omx_vdec::allocate_color_convert_buf::init_members() |
| 9431 | { |
| 9432 | allocated_count = 0; |
| 9433 | buffer_size_req = 0; |
| 9434 | buffer_alignment_req = 0; |
| 9435 | memset(m_platform_list_client,0,sizeof(m_platform_list_client)); |
| 9436 | memset(m_platform_entry_client,0,sizeof(m_platform_entry_client)); |
| 9437 | memset(m_pmem_info_client,0,sizeof(m_pmem_info_client)); |
| 9438 | 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] | 9439 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9440 | memset(op_buf_ion_info,0,sizeof(m_platform_entry_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9441 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9442 | for (int i = 0; i < MAX_COUNT; i++) |
| 9443 | pmem_fd[i] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9444 | } |
| 9445 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9446 | omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf() |
| 9447 | { |
| 9448 | c2d.destroy(); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9449 | } |
| 9450 | |
| 9451 | bool omx_vdec::allocate_color_convert_buf::update_buffer_req() |
| 9452 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9453 | bool status = true; |
| 9454 | unsigned int src_size = 0, destination_size = 0; |
| 9455 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9456 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9457 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9458 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9459 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9460 | if (!enabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9461 | DEBUG_PRINT_HIGH("No color conversion required"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9462 | return status; |
| 9463 | } |
| 9464 | pthread_mutex_lock(&omx->c_lock); |
| 9465 | if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 && |
| 9466 | ColorFormat != OMX_COLOR_FormatYUV420Planar) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9467 | DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9468 | status = false; |
| 9469 | goto fail_update_buf_req; |
| 9470 | } |
| 9471 | c2d.close(); |
| 9472 | status = c2d.open(omx->drv_ctx.video_resolution.frame_height, |
| 9473 | omx->drv_ctx.video_resolution.frame_width, |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9474 | NV12_128m,dest_format); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9475 | if (status) { |
| 9476 | status = c2d.get_buffer_size(C2D_INPUT,src_size); |
| 9477 | if (status) |
| 9478 | status = c2d.get_buffer_size(C2D_OUTPUT,destination_size); |
| 9479 | } |
| 9480 | if (status) { |
| 9481 | if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size || |
| 9482 | !destination_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9483 | DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9484 | "driver size %d destination size %d", |
| 9485 | src_size,omx->drv_ctx.op_buf.buffer_size,destination_size); |
| 9486 | status = false; |
| 9487 | c2d.close(); |
| 9488 | buffer_size_req = 0; |
| 9489 | } else { |
| 9490 | buffer_size_req = destination_size; |
| 9491 | if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size) |
| 9492 | buffer_size_req = omx->drv_ctx.op_buf.buffer_size; |
| 9493 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9494 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
| 9495 | } |
| 9496 | } |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9497 | fail_update_buf_req: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9498 | pthread_mutex_unlock(&omx->c_lock); |
| 9499 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9500 | } |
| 9501 | |
| 9502 | bool omx_vdec::allocate_color_convert_buf::set_color_format( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9503 | OMX_COLOR_FORMATTYPE dest_color_format) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9504 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9505 | bool status = true; |
| 9506 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9507 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9508 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9509 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9510 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9511 | pthread_mutex_lock(&omx->c_lock); |
| 9512 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9513 | drv_color_format = (OMX_COLOR_FORMATTYPE) |
| 9514 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9515 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9516 | DEBUG_PRINT_ERROR("Incorrect color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9517 | status = false; |
| 9518 | } |
| 9519 | if (status && (drv_color_format != dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9520 | DEBUG_PRINT_LOW("Enabling C2D"); |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9521 | if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) && |
| 9522 | (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9523 | DEBUG_PRINT_ERROR("Unsupported color format for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9524 | status = false; |
| 9525 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9526 | ColorFormat = dest_color_format; |
| 9527 | dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ? |
| 9528 | YCbCr420P : YCbCr420SP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9529 | if (enabled) |
| 9530 | c2d.destroy(); |
| 9531 | enabled = false; |
| 9532 | if (!c2d.init()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9533 | DEBUG_PRINT_ERROR("open failed for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9534 | status = false; |
| 9535 | } else |
| 9536 | enabled = true; |
| 9537 | } |
| 9538 | } else { |
| 9539 | if (enabled) |
| 9540 | c2d.destroy(); |
| 9541 | enabled = false; |
| 9542 | } |
| 9543 | pthread_mutex_unlock(&omx->c_lock); |
| 9544 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9545 | } |
| 9546 | |
| 9547 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr() |
| 9548 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9549 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9550 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9551 | return NULL; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9552 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9553 | if (!enabled) |
| 9554 | return omx->m_out_mem_ptr; |
| 9555 | return m_out_mem_ptr_client; |
| 9556 | } |
| 9557 | |
| 9558 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr |
| 9559 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9560 | { |
| 9561 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9562 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9563 | return NULL; |
| 9564 | } |
| 9565 | if (!enabled) |
| 9566 | return bufadd; |
| 9567 | |
| 9568 | unsigned index = 0; |
| 9569 | index = bufadd - omx->m_out_mem_ptr; |
| 9570 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9571 | m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS); |
| 9572 | m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp; |
| 9573 | bool status; |
| 9574 | if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) { |
| 9575 | pthread_mutex_lock(&omx->c_lock); |
| 9576 | status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd, |
| 9577 | omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index], |
| 9578 | pmem_baseaddress[index], pmem_baseaddress[index]); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9579 | if (!status) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9580 | DEBUG_PRINT_ERROR("Failed color conversion %d", status); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9581 | m_out_mem_ptr_client[index].nFilledLen = 0; |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9582 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9583 | return &m_out_mem_ptr_client[index]; |
Praveen Chavan | 6d6b725 | 2014-09-15 17:05:54 -0700 | [diff] [blame] | 9584 | } else { |
| 9585 | unsigned int filledLen = 0; |
| 9586 | c2d.get_output_filled_length(filledLen); |
| 9587 | m_out_mem_ptr_client[index].nFilledLen = filledLen; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9588 | } |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9589 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9590 | } else |
| 9591 | m_out_mem_ptr_client[index].nFilledLen = 0; |
| 9592 | return &m_out_mem_ptr_client[index]; |
| 9593 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9594 | DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9595 | return NULL; |
| 9596 | } |
| 9597 | |
| 9598 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr |
| 9599 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9600 | { |
| 9601 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9602 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9603 | return NULL; |
| 9604 | } |
| 9605 | if (!enabled) |
| 9606 | return bufadd; |
| 9607 | unsigned index = 0; |
| 9608 | index = bufadd - m_out_mem_ptr_client; |
| 9609 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9610 | return &omx->m_out_mem_ptr[index]; |
| 9611 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9612 | DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9613 | return NULL; |
| 9614 | } |
| 9615 | bool omx_vdec::allocate_color_convert_buf::get_buffer_req |
| 9616 | (unsigned int &buffer_size) |
| 9617 | { |
| 9618 | bool status = true; |
| 9619 | pthread_mutex_lock(&omx->c_lock); |
| 9620 | if (!enabled) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9621 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9622 | else { |
| 9623 | if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9624 | DEBUG_PRINT_ERROR("Get buffer size failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9625 | status = false; |
| 9626 | goto fail_get_buffer_size; |
| 9627 | } |
| 9628 | } |
| 9629 | if (buffer_size < omx->drv_ctx.op_buf.buffer_size) |
| 9630 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
| 9631 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9632 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9633 | fail_get_buffer_size: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9634 | pthread_mutex_unlock(&omx->c_lock); |
| 9635 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9636 | } |
| 9637 | OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9638 | OMX_BUFFERHEADERTYPE *bufhdr) |
| 9639 | { |
| 9640 | unsigned int index = 0; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9641 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9642 | if (!enabled) |
| 9643 | return omx->free_output_buffer(bufhdr); |
| 9644 | if (enabled && omx->is_component_secure()) |
| 9645 | return OMX_ErrorNone; |
| 9646 | if (!allocated_count || !bufhdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9647 | DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9648 | return OMX_ErrorBadParameter; |
| 9649 | } |
| 9650 | index = bufhdr - m_out_mem_ptr_client; |
| 9651 | if (index >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9652 | DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9653 | return OMX_ErrorBadParameter; |
| 9654 | } |
| 9655 | if (pmem_fd[index] > 0) { |
| 9656 | munmap(pmem_baseaddress[index], buffer_size_req); |
| 9657 | close(pmem_fd[index]); |
| 9658 | } |
| 9659 | pmem_fd[index] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9660 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9661 | omx->free_ion_memory(&op_buf_ion_info[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9662 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9663 | m_heap_ptr[index].video_heap_ptr = NULL; |
| 9664 | if (allocated_count > 0) |
| 9665 | allocated_count--; |
| 9666 | else |
| 9667 | allocated_count = 0; |
| 9668 | if (!allocated_count) { |
| 9669 | pthread_mutex_lock(&omx->c_lock); |
| 9670 | c2d.close(); |
| 9671 | init_members(); |
| 9672 | pthread_mutex_unlock(&omx->c_lock); |
| 9673 | } |
| 9674 | return omx->free_output_buffer(&omx->m_out_mem_ptr[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9675 | } |
| 9676 | |
| 9677 | 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] | 9678 | OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9679 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9680 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9681 | if (!enabled) { |
| 9682 | eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes); |
| 9683 | return eRet; |
| 9684 | } |
| 9685 | if (enabled && omx->is_component_secure()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9686 | DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9687 | omx->is_component_secure()); |
| 9688 | return OMX_ErrorUnsupportedSetting; |
| 9689 | } |
| 9690 | if (!bufferHdr || bytes > buffer_size_req) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9691 | DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr); |
| 9692 | DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9693 | buffer_size_req,bytes); |
| 9694 | return OMX_ErrorBadParameter; |
| 9695 | } |
| 9696 | if (allocated_count >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9697 | DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9698 | return OMX_ErrorInsufficientResources; |
| 9699 | } |
| 9700 | OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL; |
| 9701 | eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr, |
| 9702 | port,appData,omx->drv_ctx.op_buf.buffer_size); |
| 9703 | if (eRet != OMX_ErrorNone || !temp_bufferHdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9704 | DEBUG_PRINT_ERROR("Buffer allocation failed color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9705 | return eRet; |
| 9706 | } |
| 9707 | if ((temp_bufferHdr - omx->m_out_mem_ptr) >= |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 9708 | (int)omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9709 | DEBUG_PRINT_ERROR("Invalid header index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9710 | (temp_bufferHdr - omx->m_out_mem_ptr)); |
| 9711 | return OMX_ErrorUndefined; |
| 9712 | } |
| 9713 | unsigned int i = allocated_count; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9714 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9715 | op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory( |
| 9716 | buffer_size_req,buffer_alignment_req, |
| 9717 | &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data, |
| 9718 | 0); |
| 9719 | pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd; |
| 9720 | if (op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9721 | DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9722 | return OMX_ErrorInsufficientResources; |
| 9723 | } |
| 9724 | pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req, |
| 9725 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9726 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9727 | if (pmem_baseaddress[i] == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9728 | DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9729 | close(pmem_fd[i]); |
| 9730 | omx->free_ion_memory(&op_buf_ion_info[i]); |
| 9731 | return OMX_ErrorInsufficientResources; |
| 9732 | } |
| 9733 | m_heap_ptr[i].video_heap_ptr = new VideoHeap ( |
| 9734 | op_buf_ion_info[i].ion_device_fd,buffer_size_req, |
| 9735 | 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] | 9736 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9737 | m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get(); |
| 9738 | m_pmem_info_client[i].offset = 0; |
| 9739 | m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i]; |
| 9740 | m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 9741 | m_platform_list_client[i].nEntries = 1; |
| 9742 | m_platform_list_client[i].entryList = &m_platform_entry_client[i]; |
| 9743 | m_out_mem_ptr_client[i].pOutputPortPrivate = NULL; |
| 9744 | m_out_mem_ptr_client[i].nAllocLen = buffer_size_req; |
| 9745 | m_out_mem_ptr_client[i].nFilledLen = 0; |
| 9746 | m_out_mem_ptr_client[i].nFlags = 0; |
| 9747 | m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9748 | m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 9749 | m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION; |
| 9750 | m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i]; |
| 9751 | m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i]; |
| 9752 | m_out_mem_ptr_client[i].pAppPrivate = appData; |
| 9753 | *bufferHdr = &m_out_mem_ptr_client[i]; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9754 | DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9755 | allocated_count++; |
| 9756 | return eRet; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9757 | } |
| 9758 | |
| 9759 | bool omx_vdec::is_component_secure() |
| 9760 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9761 | return secure_mode; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9762 | } |
| 9763 | |
| 9764 | bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format) |
| 9765 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9766 | bool status = true; |
| 9767 | if (!enabled) { |
| 9768 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9769 | dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 9770 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9771 | else |
| 9772 | status = false; |
| 9773 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9774 | if (ColorFormat == OMX_COLOR_FormatYUV420Planar || |
| 9775 | ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) { |
| 9776 | dest_color_format = ColorFormat; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9777 | } else |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9778 | status = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9779 | } |
| 9780 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9781 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9782 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9783 | void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset) |
| 9784 | { |
| 9785 | int i = 0; |
| 9786 | bool buf_present = false; |
| 9787 | pthread_mutex_lock(&m_lock); |
| 9788 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9789 | //check the buffer fd, offset, uv addr with list contents |
| 9790 | //If present increment reference. |
| 9791 | if ((out_dynamic_list[i].fd == fd) && |
| 9792 | (out_dynamic_list[i].offset == offset)) { |
| 9793 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9794 | 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] | 9795 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9796 | buf_present = true; |
| 9797 | break; |
| 9798 | } |
| 9799 | } |
| 9800 | if (!buf_present) { |
| 9801 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9802 | //search for a entry to insert details of the new buffer |
| 9803 | if (out_dynamic_list[i].dup_fd == 0) { |
| 9804 | out_dynamic_list[i].fd = fd; |
| 9805 | out_dynamic_list[i].offset = offset; |
| 9806 | out_dynamic_list[i].dup_fd = dup(fd); |
| 9807 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9808 | DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9809 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9810 | break; |
| 9811 | } |
| 9812 | } |
| 9813 | } |
| 9814 | pthread_mutex_unlock(&m_lock); |
| 9815 | } |
| 9816 | |
| 9817 | void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset) |
| 9818 | { |
| 9819 | int i = 0; |
| 9820 | pthread_mutex_lock(&m_lock); |
| 9821 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9822 | //check the buffer fd, offset, uv addr with list contents |
| 9823 | //If present decrement reference. |
| 9824 | if ((out_dynamic_list[i].fd == fd) && |
| 9825 | (out_dynamic_list[i].offset == offset)) { |
| 9826 | out_dynamic_list[i].ref_count--; |
| 9827 | if (out_dynamic_list[i].ref_count == 0) { |
| 9828 | close(out_dynamic_list[i].dup_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9829 | DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9830 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9831 | out_dynamic_list[i].dup_fd = 0; |
| 9832 | out_dynamic_list[i].fd = 0; |
| 9833 | out_dynamic_list[i].offset = 0; |
| 9834 | } |
| 9835 | break; |
| 9836 | } |
| 9837 | } |
| 9838 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9839 | 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] | 9840 | } |
| 9841 | pthread_mutex_unlock(&m_lock); |
| 9842 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 9843 | |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 9844 | OMX_ERRORTYPE omx_vdec::enable_adaptive_playback(unsigned long nMaxFrameWidth, |
| 9845 | unsigned long nMaxFrameHeight) |
| 9846 | { |
| 9847 | |
| 9848 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9849 | int ret = 0; |
| 9850 | unsigned long min_res_buf_count = 0; |
| 9851 | |
| 9852 | eRet = enable_smoothstreaming(); |
| 9853 | if (eRet != OMX_ErrorNone) { |
| 9854 | DEBUG_PRINT_ERROR("Failed to enable Adaptive Playback on driver"); |
| 9855 | return eRet; |
| 9856 | } |
| 9857 | |
| 9858 | DEBUG_PRINT_HIGH("Enabling Adaptive playback for %lu x %lu", |
| 9859 | nMaxFrameWidth, |
| 9860 | nMaxFrameHeight); |
| 9861 | m_smoothstreaming_mode = true; |
| 9862 | m_smoothstreaming_width = nMaxFrameWidth; |
| 9863 | m_smoothstreaming_height = nMaxFrameHeight; |
| 9864 | |
| 9865 | //Get upper limit buffer count for min supported resolution |
| 9866 | struct v4l2_format fmt; |
| 9867 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9868 | fmt.fmt.pix_mp.height = m_decoder_capability.min_height; |
| 9869 | fmt.fmt.pix_mp.width = m_decoder_capability.min_width; |
| 9870 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9871 | |
| 9872 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9873 | if (ret) { |
| 9874 | DEBUG_PRINT_ERROR("Set Resolution failed for HxW = %ux%u", |
| 9875 | m_decoder_capability.min_height, |
| 9876 | m_decoder_capability.min_width); |
| 9877 | return OMX_ErrorUnsupportedSetting; |
| 9878 | } |
| 9879 | |
| 9880 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9881 | if (eRet != OMX_ErrorNone) { |
| 9882 | DEBUG_PRINT_ERROR("failed to get_buffer_req"); |
| 9883 | return eRet; |
| 9884 | } |
| 9885 | |
| 9886 | min_res_buf_count = drv_ctx.op_buf.mincount; |
| 9887 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer count = %lu for HxW %ux%u", |
| 9888 | min_res_buf_count, m_decoder_capability.min_height, m_decoder_capability.min_width); |
| 9889 | |
| 9890 | update_resolution(m_smoothstreaming_width, m_smoothstreaming_height, |
| 9891 | m_smoothstreaming_width, m_smoothstreaming_height); |
| 9892 | eRet = is_video_session_supported(); |
| 9893 | if (eRet != OMX_ErrorNone) { |
| 9894 | DEBUG_PRINT_ERROR("video session is not supported"); |
| 9895 | return eRet; |
| 9896 | } |
| 9897 | |
| 9898 | //Get upper limit buffer size for max smooth streaming resolution set |
| 9899 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9900 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 9901 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 9902 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9903 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9904 | if (ret) { |
| 9905 | DEBUG_PRINT_ERROR("Set Resolution failed for adaptive playback"); |
| 9906 | return OMX_ErrorUnsupportedSetting; |
| 9907 | } |
| 9908 | |
| 9909 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9910 | if (eRet != OMX_ErrorNone) { |
| 9911 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!"); |
| 9912 | return eRet; |
| 9913 | } |
| 9914 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer size = %u", |
| 9915 | drv_ctx.op_buf.buffer_size); |
| 9916 | |
| 9917 | drv_ctx.op_buf.mincount = min_res_buf_count; |
| 9918 | drv_ctx.op_buf.actualcount = min_res_buf_count; |
| 9919 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 9920 | if (eRet != OMX_ErrorNone) { |
| 9921 | DEBUG_PRINT_ERROR("failed to set_buffer_req"); |
| 9922 | return eRet; |
| 9923 | } |
| 9924 | |
| 9925 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9926 | if (eRet != OMX_ErrorNone) { |
| 9927 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!!"); |
| 9928 | return eRet; |
| 9929 | } |
| 9930 | DEBUG_PRINT_HIGH("adaptive playback enabled, buf count = %u bufsize = %u", |
| 9931 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size); |
| 9932 | return eRet; |
| 9933 | } |
| 9934 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 9935 | #ifdef _MSM8974_ |
| 9936 | void omx_vdec::send_codec_config() { |
| 9937 | if (codec_config_flag) { |
| 9938 | unsigned p1 = 0; // Parameter - 1 |
| 9939 | unsigned p2 = 0; // Parameter - 2 |
| 9940 | unsigned ident = 0; |
| 9941 | pthread_mutex_lock(&m_lock); |
| 9942 | DEBUG_PRINT_LOW("\n Check Queue for codec_config buffer \n"); |
| 9943 | while (m_etb_q.m_size) { |
| 9944 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 9945 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 9946 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 9947 | if (empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 9948 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 9949 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy_arbitrary failure"); |
| 9950 | omx_report_error(); |
| 9951 | } |
| 9952 | } else { |
| 9953 | DEBUG_PRINT_LOW("\n Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
| 9954 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 9955 | } |
| 9956 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 9957 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 9958 | if (empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 9959 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 9960 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy failure"); |
| 9961 | omx_report_error (); |
| 9962 | } |
| 9963 | } else { |
| 9964 | pending_input_buffers++; |
| 9965 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d", |
| 9966 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 9967 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 9968 | } |
| 9969 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 9970 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
| 9971 | (OMX_BUFFERHEADERTYPE *)p1); |
| 9972 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 9973 | } |
| 9974 | } |
| 9975 | pthread_mutex_unlock(&m_lock); |
| 9976 | } |
| 9977 | } |
| 9978 | #endif |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 9979 | |
| 9980 | //static |
| 9981 | OMX_ERRORTYPE omx_vdec::describeColorFormat(OMX_PTR pParam) { |
| 9982 | |
| 9983 | #ifndef FLEXYUV_SUPPORTED |
| 9984 | (void)pParam; |
| 9985 | return OMX_ErrorUndefined; |
| 9986 | #else |
| 9987 | |
| 9988 | if (pParam == NULL) { |
| 9989 | DEBUG_PRINT_ERROR("describeColorFormat: invalid params"); |
| 9990 | return OMX_ErrorBadParameter; |
| 9991 | } |
| 9992 | |
| 9993 | DescribeColorFormatParams *params = (DescribeColorFormatParams*)pParam; |
| 9994 | |
| 9995 | MediaImage *img = &(params->sMediaImage); |
| 9996 | switch(params->eColorFormat) { |
| 9997 | case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m: |
| 9998 | { |
| 9999 | img->mType = MediaImage::MEDIA_IMAGE_TYPE_YUV; |
| 10000 | img->mNumPlanes = 3; |
| 10001 | // mWidth and mHeight represent the W x H of the largest plane |
| 10002 | // In our case, this happens to be the Stride x Scanlines of Y plane |
| 10003 | img->mWidth = params->nFrameWidth; |
| 10004 | img->mHeight = params->nFrameHeight; |
| 10005 | size_t planeWidth = VENUS_Y_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10006 | size_t planeHeight = VENUS_Y_SCANLINES(COLOR_FMT_NV12, params->nFrameHeight); |
| 10007 | img->mBitDepth = 8; |
| 10008 | //Plane 0 (Y) |
| 10009 | img->mPlane[MediaImage::Y].mOffset = 0; |
| 10010 | img->mPlane[MediaImage::Y].mColInc = 1; |
| 10011 | img->mPlane[MediaImage::Y].mRowInc = planeWidth; //same as stride |
| 10012 | img->mPlane[MediaImage::Y].mHorizSubsampling = 1; |
| 10013 | img->mPlane[MediaImage::Y].mVertSubsampling = 1; |
| 10014 | //Plane 1 (U) |
| 10015 | img->mPlane[MediaImage::U].mOffset = planeWidth * planeHeight; |
| 10016 | img->mPlane[MediaImage::U].mColInc = 2; //interleaved UV |
| 10017 | img->mPlane[MediaImage::U].mRowInc = |
| 10018 | VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10019 | img->mPlane[MediaImage::U].mHorizSubsampling = 2; |
| 10020 | img->mPlane[MediaImage::U].mVertSubsampling = 2; |
| 10021 | //Plane 2 (V) |
| 10022 | img->mPlane[MediaImage::V].mOffset = planeWidth * planeHeight + 1; |
| 10023 | img->mPlane[MediaImage::V].mColInc = 2; //interleaved UV |
| 10024 | img->mPlane[MediaImage::V].mRowInc = |
| 10025 | VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10026 | img->mPlane[MediaImage::V].mHorizSubsampling = 2; |
| 10027 | img->mPlane[MediaImage::V].mVertSubsampling = 2; |
| 10028 | break; |
| 10029 | } |
| 10030 | |
| 10031 | case OMX_COLOR_FormatYUV420Planar: |
| 10032 | case OMX_COLOR_FormatYUV420SemiPlanar: |
| 10033 | // We need not describe the standard OMX linear formats as these are |
| 10034 | // understood by client. Fail this deliberately to let client fill-in |
| 10035 | return OMX_ErrorUnsupportedSetting; |
| 10036 | |
| 10037 | default: |
| 10038 | // Rest all formats which are non-linear cannot be described |
| 10039 | DEBUG_PRINT_LOW("color-format %x is not flexible", params->eColorFormat); |
| 10040 | img->mType = MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN; |
| 10041 | return OMX_ErrorNone; |
| 10042 | }; |
| 10043 | |
| 10044 | DEBUG_PRINT_LOW("NOTE: Describe color format : %x", params->eColorFormat); |
| 10045 | DEBUG_PRINT_LOW(" FrameWidth x FrameHeight : %d x %d", params->nFrameWidth, params->nFrameHeight); |
| 10046 | DEBUG_PRINT_LOW(" YWidth x YHeight : %d x %d", img->mWidth, img->mHeight); |
| 10047 | for (size_t i = 0; i < img->mNumPlanes; ++i) { |
| 10048 | DEBUG_PRINT_LOW(" Plane[%d] : offset=%d / xStep=%d / yStep = %d", |
| 10049 | i, img->mPlane[i].mOffset, img->mPlane[i].mColInc, img->mPlane[i].mRowInc); |
| 10050 | } |
| 10051 | return OMX_ErrorNone; |
| 10052 | #endif //FLEXYUV_SUPPORTED |
| 10053 | } |
| 10054 | |