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 | |
| 42 | #include <string.h> |
| 43 | #include <pthread.h> |
| 44 | #include <sys/prctl.h> |
| 45 | #include <stdlib.h> |
| 46 | #include <unistd.h> |
| 47 | #include <errno.h> |
| 48 | #include "omx_vdec.h" |
| 49 | #include <fcntl.h> |
| 50 | #include <limits.h> |
Deva Ramasubramanian | 15bbc1c | 2013-05-13 16:05:03 -0700 | [diff] [blame] | 51 | #include <stdlib.h> |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 52 | #include <media/hardware/HardwareAPI.h> |
Vinay Kalia | da8f3cf | 2012-12-21 18:26:21 -0800 | [diff] [blame] | 53 | #include <media/msm_media_info.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 54 | |
| 55 | #ifndef _ANDROID_ |
| 56 | #include <sys/ioctl.h> |
| 57 | #include <sys/mman.h> |
| 58 | #endif //_ANDROID_ |
| 59 | |
| 60 | #ifdef _ANDROID_ |
| 61 | #include <cutils/properties.h> |
| 62 | #undef USE_EGL_IMAGE_GPU |
| 63 | #endif |
| 64 | |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 65 | #include <qdMetaData.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 66 | |
| 67 | #ifdef _ANDROID_ |
| 68 | #include "DivXDrmDecrypt.h" |
| 69 | #endif //_ANDROID_ |
| 70 | |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 71 | #ifdef METADATA_FOR_DYNAMIC_MODE |
Arun Menon | 9af783f | 2013-10-22 12:57:14 -0700 | [diff] [blame] | 72 | #include "QComOMXMetadata.h" |
| 73 | #endif |
| 74 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 75 | #ifdef USE_EGL_IMAGE_GPU |
| 76 | #include <EGL/egl.h> |
| 77 | #include <EGL/eglQCOM.h> |
| 78 | #define EGL_BUFFER_HANDLE_QCOM 0x4F00 |
| 79 | #define EGL_BUFFER_OFFSET_QCOM 0x4F01 |
| 80 | #endif |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 81 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 82 | #define BUFFER_LOG_LOC "/data/misc/media" |
| 83 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 84 | #ifdef OUTPUT_EXTRADATA_LOG |
| 85 | FILE *outputExtradataFile; |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 86 | char output_extradata_filename [] = "/data/misc/extradata"; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 87 | #endif |
| 88 | |
| 89 | #define DEFAULT_FPS 30 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 90 | #define MAX_SUPPORTED_FPS 120 |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 91 | #define DEFAULT_WIDTH_ALIGNMENT 128 |
| 92 | #define DEFAULT_HEIGHT_ALIGNMENT 32 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 93 | |
| 94 | #define VC1_SP_MP_START_CODE 0xC5000000 |
| 95 | #define VC1_SP_MP_START_CODE_MASK 0xFF000000 |
| 96 | #define VC1_AP_SEQ_START_CODE 0x0F010000 |
| 97 | #define VC1_STRUCT_C_PROFILE_MASK 0xF0 |
| 98 | #define VC1_STRUCT_B_LEVEL_MASK 0xE0000000 |
| 99 | #define VC1_SIMPLE_PROFILE 0 |
| 100 | #define VC1_MAIN_PROFILE 1 |
| 101 | #define VC1_ADVANCE_PROFILE 3 |
| 102 | #define VC1_SIMPLE_PROFILE_LOW_LEVEL 0 |
| 103 | #define VC1_SIMPLE_PROFILE_MED_LEVEL 2 |
| 104 | #define VC1_STRUCT_C_LEN 4 |
| 105 | #define VC1_STRUCT_C_POS 8 |
| 106 | #define VC1_STRUCT_A_POS 12 |
| 107 | #define VC1_STRUCT_B_POS 24 |
| 108 | #define VC1_SEQ_LAYER_SIZE 36 |
Vinay Kalia | b09886c | 2012-08-20 11:27:25 -0700 | [diff] [blame] | 109 | #define POLL_TIMEOUT 0x7fffffff |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 110 | |
| 111 | #define MEM_DEVICE "/dev/ion" |
| 112 | #define MEM_HEAP_ID ION_CP_MM_HEAP_ID |
| 113 | |
| 114 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 115 | extern "C" { |
| 116 | #include<utils/Log.h> |
| 117 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 118 | #endif//_ANDROID_ |
| 119 | |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 120 | #define SZ_4K 0x1000 |
| 121 | #define SZ_1M 0x100000 |
| 122 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 123 | #define Log2(number, power) { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) && power < 16) { temp >>=0x1; power++; } } |
| 124 | #define Q16ToFraction(q,num,den) { OMX_U32 power; Log2(q,power); num = q >> power; den = 0x1 << (16 - power); } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 125 | #define EXTRADATA_IDX(__num_planes) (__num_planes - 1) |
| 126 | |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 127 | #define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA) |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 128 | #define DEFAULT_CONCEAL_COLOR "32896" //0x8080, black by default |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 129 | |
| 130 | int debug_level = PRIO_ERROR; |
| 131 | |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 132 | static OMX_U32 maxSmoothStreamingWidth = 1920; |
| 133 | static OMX_U32 maxSmoothStreamingHeight = 1088; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 134 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 135 | void* async_message_thread (void *input) |
| 136 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 137 | OMX_BUFFERHEADERTYPE *buffer; |
| 138 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 139 | struct pollfd pfd; |
| 140 | struct v4l2_buffer v4l2_buf; |
| 141 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 142 | struct v4l2_event dqevent; |
| 143 | omx_vdec *omx = reinterpret_cast<omx_vdec*>(input); |
| 144 | pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI; |
| 145 | pfd.fd = omx->drv_ctx.video_driver_fd; |
| 146 | int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 147 | DEBUG_PRINT_HIGH("omx_vdec: Async thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 148 | prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0); |
| 149 | while (1) { |
| 150 | rc = poll(&pfd, 1, POLL_TIMEOUT); |
| 151 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 152 | DEBUG_PRINT_ERROR("Poll timedout"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 153 | break; |
| 154 | } else if (rc < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 155 | DEBUG_PRINT_ERROR("Error while polling: %d", rc); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 156 | break; |
| 157 | } |
| 158 | if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) { |
| 159 | struct vdec_msginfo vdec_msg; |
| 160 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 161 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 162 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 163 | v4l2_buf.m.planes = plane; |
| 164 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 165 | vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 166 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 167 | vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf; |
| 168 | vdec_msg.msgdata.output_frame.len=plane[0].bytesused; |
| 169 | vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr; |
| 170 | vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) + |
| 171 | (uint64_t)v4l2_buf.timestamp.tv_usec; |
| 172 | if (vdec_msg.msgdata.output_frame.len) { |
| 173 | vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2]; |
| 174 | vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3]; |
| 175 | vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4]; |
| 176 | vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5]; |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 177 | vdec_msg.msgdata.output_frame.picsize.frame_width = plane[0].reserved[6]; |
| 178 | vdec_msg.msgdata.output_frame.picsize.frame_height = plane[0].reserved[7]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 179 | } |
| 180 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 181 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 182 | break; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) { |
| 187 | struct vdec_msginfo vdec_msg; |
| 188 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 189 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 190 | v4l2_buf.length = 1; |
| 191 | v4l2_buf.m.planes = plane; |
| 192 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 193 | vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE; |
| 194 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 195 | vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf; |
| 196 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 197 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 198 | break; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | if (pfd.revents & POLLPRI) { |
| 203 | rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent); |
| 204 | if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) { |
| 205 | struct vdec_msginfo vdec_msg; |
| 206 | vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED; |
| 207 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 208 | DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 209 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 210 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 211 | break; |
| 212 | } |
| 213 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) { |
| 214 | struct vdec_msginfo vdec_msg; |
| 215 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE; |
| 216 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 217 | DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 218 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 219 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE; |
| 223 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 224 | DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 225 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 226 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 227 | break; |
| 228 | } |
| 229 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 230 | DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 231 | break; |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 232 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_HW_OVERLOAD) { |
| 233 | struct vdec_msginfo vdec_msg; |
| 234 | vdec_msg.msgcode=VDEC_MSG_EVT_HW_OVERLOAD; |
| 235 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 236 | DEBUG_PRINT_ERROR("HW Overload received"); |
| 237 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
| 238 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
| 239 | break; |
| 240 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 241 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) { |
| 242 | struct vdec_msginfo vdec_msg; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 243 | vdec_msg.msgcode = VDEC_MSG_EVT_HW_ERROR; |
| 244 | vdec_msg.status_code = VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 245 | DEBUG_PRINT_HIGH("SYS Error Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 246 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 247 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 248 | break; |
| 249 | } |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 250 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 251 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 252 | 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] | 253 | omx->buf_ref_remove(ptr[0], ptr[1]); |
| 254 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) { |
| 255 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
| 256 | struct vdec_msginfo vdec_msg; |
| 257 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 258 | 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] | 259 | |
| 260 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 261 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 262 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 263 | v4l2_buf.m.planes = plane; |
| 264 | v4l2_buf.index = ptr[5]; |
| 265 | v4l2_buf.flags = 0; |
| 266 | |
| 267 | vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 268 | vdec_msg.status_code = VDEC_S_SUCCESS; |
| 269 | vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf; |
| 270 | vdec_msg.msgdata.output_frame.len = 0; |
| 271 | vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2]; |
| 272 | vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) + |
| 273 | (uint64_t)ptr[4]; |
| 274 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 275 | DEBUG_PRINT_HIGH("async_message_thread Exitedn"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 276 | break; |
| 277 | } |
| 278 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 279 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 280 | DEBUG_PRINT_HIGH("VIDC Some Event recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 281 | continue; |
| 282 | } |
| 283 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 284 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 285 | DEBUG_PRINT_HIGH("omx_vdec: Async thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 286 | return NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void* message_thread(void *input) |
| 290 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 291 | omx_vdec* omx = reinterpret_cast<omx_vdec*>(input); |
| 292 | unsigned char id; |
| 293 | int n; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 294 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 295 | DEBUG_PRINT_HIGH("omx_vdec: message thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 296 | prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0); |
| 297 | while (1) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 299 | n = read(omx->m_pipe_in, &id, 1); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 300 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 301 | if (0 == n) { |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | if (1 == n) { |
| 306 | omx->process_event_cb(omx, id); |
| 307 | } |
| 308 | if ((n < 0) && (errno != EINTR)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 309 | 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] | 310 | break; |
| 311 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 312 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 313 | DEBUG_PRINT_HIGH("omx_vdec: message thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 314 | return 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void post_message(omx_vdec *omx, unsigned char id) |
| 318 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 319 | int ret_value; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 320 | 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] | 321 | ret_value = write(omx->m_pipe_out, &id, 1); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 322 | DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // omx_cmd_queue destructor |
| 326 | omx_vdec::omx_cmd_queue::~omx_cmd_queue() |
| 327 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 328 | // Nothing to do |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | // omx cmd queue constructor |
| 332 | omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0) |
| 333 | { |
| 334 | memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE); |
| 335 | } |
| 336 | |
| 337 | // omx cmd queue insert |
| 338 | bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id) |
| 339 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 340 | bool ret = true; |
| 341 | if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 342 | m_q[m_write].id = id; |
| 343 | m_q[m_write].param1 = p1; |
| 344 | m_q[m_write].param2 = p2; |
| 345 | m_write++; |
| 346 | m_size ++; |
| 347 | if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 348 | m_write = 0; |
| 349 | } |
| 350 | } else { |
| 351 | ret = false; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 352 | DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 353 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 354 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | // omx cmd queue pop |
| 358 | bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id) |
| 359 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 360 | bool ret = true; |
| 361 | if (m_size > 0) { |
| 362 | *id = m_q[m_read].id; |
| 363 | *p1 = m_q[m_read].param1; |
| 364 | *p2 = m_q[m_read].param2; |
| 365 | // Move the read pointer ahead |
| 366 | ++m_read; |
| 367 | --m_size; |
| 368 | if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 369 | m_read = 0; |
| 370 | } |
| 371 | } else { |
| 372 | ret = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 373 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 374 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // Retrieve the first mesg type in the queue |
| 378 | unsigned omx_vdec::omx_cmd_queue::get_q_msg_type() |
| 379 | { |
| 380 | return m_q[m_read].id; |
| 381 | } |
| 382 | |
| 383 | #ifdef _ANDROID_ |
| 384 | omx_vdec::ts_arr_list::ts_arr_list() |
| 385 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 386 | //initialize timestamps array |
| 387 | 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] | 388 | } |
| 389 | omx_vdec::ts_arr_list::~ts_arr_list() |
| 390 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 391 | //free m_ts_arr_list? |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts) |
| 395 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 396 | bool ret = true; |
| 397 | bool duplicate_ts = false; |
| 398 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 399 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 400 | //insert at the first available empty location |
| 401 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 402 | if (!m_ts_arr_list[idx].valid) { |
| 403 | //found invalid or empty entry, save timestamp |
| 404 | m_ts_arr_list[idx].valid = true; |
| 405 | m_ts_arr_list[idx].timestamp = ts; |
| 406 | DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)", |
| 407 | ts, idx); |
| 408 | break; |
| 409 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 410 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 411 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 412 | if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 413 | DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert"); |
| 414 | ret = false; |
| 415 | } |
| 416 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts) |
| 420 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 421 | bool ret = true; |
| 422 | int min_idx = -1; |
| 423 | OMX_TICKS min_ts = 0; |
| 424 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 425 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 426 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 427 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 428 | if (m_ts_arr_list[idx].valid) { |
| 429 | //found valid entry, save index |
| 430 | if (min_idx < 0) { |
| 431 | //first valid entry |
| 432 | min_ts = m_ts_arr_list[idx].timestamp; |
| 433 | min_idx = idx; |
| 434 | } else if (m_ts_arr_list[idx].timestamp < min_ts) { |
| 435 | min_ts = m_ts_arr_list[idx].timestamp; |
| 436 | min_idx = idx; |
| 437 | } |
| 438 | } |
| 439 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 442 | if (min_idx < 0) { |
| 443 | //no valid entries found |
| 444 | DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop"); |
| 445 | ts = 0; |
| 446 | ret = false; |
| 447 | } else { |
| 448 | ts = m_ts_arr_list[min_idx].timestamp; |
| 449 | m_ts_arr_list[min_idx].valid = false; |
| 450 | DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)", |
| 451 | ts, min_idx); |
| 452 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 453 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 454 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 455 | |
| 456 | } |
| 457 | |
| 458 | |
| 459 | bool omx_vdec::ts_arr_list::reset_ts_list() |
| 460 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 461 | bool ret = true; |
| 462 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 463 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 464 | DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list"); |
| 465 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 466 | m_ts_arr_list[idx].valid = false; |
| 467 | } |
| 468 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 469 | } |
| 470 | #endif |
| 471 | |
| 472 | // factory function executed by the core to create instances |
| 473 | void *get_omx_component_factory_fn(void) |
| 474 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 475 | return (new omx_vdec); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | #ifdef _ANDROID_ |
| 479 | #ifdef USE_ION |
| 480 | VideoHeap::VideoHeap(int devicefd, size_t size, void* base, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 481 | struct ion_handle *handle, int ionMapfd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 482 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 483 | // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 484 | } |
| 485 | #else |
| 486 | VideoHeap::VideoHeap(int fd, size_t size, void* base) |
| 487 | { |
| 488 | // dup file descriptor, map once, use pmem |
| 489 | init(dup(fd), base, size, 0 , MEM_DEVICE); |
| 490 | } |
| 491 | #endif |
| 492 | #endif // _ANDROID_ |
| 493 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 494 | FUNCTION |
| 495 | omx_vdec::omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 496 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 497 | DESCRIPTION |
| 498 | Constructor |
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 | PARAMETERS |
| 501 | None |
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 | RETURN VALUE |
| 504 | None. |
| 505 | ========================================================================== */ |
Deva Ramasubramanian | 5c24124 | 2013-02-19 17:25:30 -0800 | [diff] [blame] | 506 | omx_vdec::omx_vdec(): m_error_propogated(false), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 507 | m_state(OMX_StateInvalid), |
| 508 | m_app_data(NULL), |
| 509 | m_inp_mem_ptr(NULL), |
| 510 | m_out_mem_ptr(NULL), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 511 | input_flush_progress (false), |
| 512 | output_flush_progress (false), |
| 513 | input_use_buffer (false), |
| 514 | output_use_buffer (false), |
| 515 | ouput_egl_buffers(false), |
| 516 | m_use_output_pmem(OMX_FALSE), |
| 517 | m_out_mem_region_smi(OMX_FALSE), |
| 518 | m_out_pvt_entry_pmem(OMX_FALSE), |
| 519 | pending_input_buffers(0), |
| 520 | pending_output_buffers(0), |
| 521 | m_out_bm_count(0), |
| 522 | m_inp_bm_count(0), |
| 523 | m_inp_bPopulated(OMX_FALSE), |
| 524 | m_out_bPopulated(OMX_FALSE), |
| 525 | m_flags(0), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 526 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 527 | m_heap_ptr(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 528 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 529 | m_inp_bEnabled(OMX_TRUE), |
| 530 | m_out_bEnabled(OMX_TRUE), |
| 531 | m_in_alloc_cnt(0), |
| 532 | m_platform_list(NULL), |
| 533 | m_platform_entry(NULL), |
| 534 | m_pmem_info(NULL), |
| 535 | arbitrary_bytes (true), |
| 536 | psource_frame (NULL), |
| 537 | pdest_frame (NULL), |
| 538 | m_inp_heap_ptr (NULL), |
| 539 | m_phdr_pmem_ptr(NULL), |
| 540 | m_heap_inp_bm_count (0), |
| 541 | codec_type_parse ((codec_type)0), |
| 542 | first_frame_meta (true), |
| 543 | frame_count (0), |
| 544 | nal_count (0), |
| 545 | nal_length(0), |
| 546 | look_ahead_nal (false), |
| 547 | first_frame(0), |
| 548 | first_buffer(NULL), |
| 549 | first_frame_size (0), |
| 550 | m_device_file_ptr(NULL), |
| 551 | m_vc1_profile((vc1_profile_type)0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 552 | h264_last_au_ts(LLONG_MAX), |
| 553 | h264_last_au_flags(0), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 554 | m_disp_hor_size(0), |
| 555 | m_disp_vert_size(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 556 | prev_ts(LLONG_MAX), |
| 557 | rst_prev_ts(true), |
| 558 | frm_int(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 559 | in_reconfig(false), |
| 560 | m_display_id(NULL), |
| 561 | h264_parser(NULL), |
| 562 | client_extradata(0), |
| 563 | m_reject_avc_1080p_mp (0), |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 564 | m_other_extradata(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 565 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 566 | m_enable_android_native_buffers(OMX_FALSE), |
| 567 | m_use_android_native_buffers(OMX_FALSE), |
| 568 | iDivXDrmDecrypt(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 569 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 570 | m_desc_buffer_ptr(NULL), |
| 571 | secure_mode(false), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 572 | m_profile(0), |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 573 | client_set_fps(false), |
Deva Ramasubramanian | 286a358 | 2014-08-25 18:09:38 -0700 | [diff] [blame] | 574 | ignore_not_coded_vops(true), |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 575 | m_last_rendered_TS(-1) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 576 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 577 | /* Assumption is that , to begin with , we have all the frames with decoder */ |
| 578 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 579 | memset(&m_debug,0,sizeof(m_debug)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 580 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 581 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 582 | property_get("vidc.debug.level", property_value, "0"); |
| 583 | debug_level = atoi(property_value); |
| 584 | property_value[0] = '\0'; |
| 585 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 586 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
| 587 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 588 | property_get("vidc.dec.debug.perf", property_value, "0"); |
| 589 | perf_flag = atoi(property_value); |
| 590 | if (perf_flag) { |
| 591 | DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag); |
| 592 | dec_time.start(); |
| 593 | proc_frms = latency = 0; |
| 594 | } |
| 595 | prev_n_filled_len = 0; |
| 596 | property_value[0] = '\0'; |
| 597 | property_get("vidc.dec.debug.ts", property_value, "0"); |
| 598 | m_debug_timestamp = atoi(property_value); |
| 599 | DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp); |
| 600 | if (m_debug_timestamp) { |
| 601 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 602 | time_stamp_dts.enable_debug_print(true); |
| 603 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 604 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 605 | property_value[0] = '\0'; |
| 606 | property_get("vidc.dec.debug.concealedmb", property_value, "0"); |
| 607 | m_debug_concealedmb = atoi(property_value); |
| 608 | DEBUG_PRINT_HIGH("vidc.dec.debug.concealedmb value is %d",m_debug_concealedmb); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 609 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 610 | property_value[0] = '\0'; |
| 611 | property_get("vidc.dec.profile.check", property_value, "0"); |
| 612 | m_reject_avc_1080p_mp = atoi(property_value); |
| 613 | DEBUG_PRINT_HIGH("vidc.dec.profile.check value is %d",m_reject_avc_1080p_mp); |
Rajeshwar Kurapaty | e0e7d0c | 2013-07-30 19:46:26 +0530 | [diff] [blame] | 614 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 615 | property_value[0] = '\0'; |
| 616 | property_get("vidc.dec.log.in", property_value, "0"); |
| 617 | m_debug.in_buffer_log = atoi(property_value); |
| 618 | |
| 619 | property_value[0] = '\0'; |
| 620 | property_get("vidc.dec.log.out", property_value, "0"); |
| 621 | m_debug.out_buffer_log = atoi(property_value); |
| 622 | sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC); |
| 623 | |
| 624 | property_value[0] = '\0'; |
| 625 | property_get("vidc.log.loc", property_value, ""); |
| 626 | if (*property_value) |
| 627 | strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 628 | |
| 629 | property_value[0] = '\0'; |
| 630 | property_get("vidc.dec.120fps.enabled", property_value, "0"); |
| 631 | |
| 632 | //if this feature is not enabled then reset this value -ve |
| 633 | if(atoi(property_value)) { |
| 634 | DEBUG_PRINT_LOW("feature 120 FPS decode enabled"); |
| 635 | m_last_rendered_TS = 0; |
| 636 | } |
| 637 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 638 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 639 | memset(&m_cmp,0,sizeof(m_cmp)); |
| 640 | memset(&m_cb,0,sizeof(m_cb)); |
| 641 | memset (&drv_ctx,0,sizeof(drv_ctx)); |
| 642 | memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE)); |
| 643 | memset (m_hwdevice_name,0,sizeof(m_hwdevice_name)); |
| 644 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 645 | memset(&m_custom_buffersize, 0, sizeof(m_custom_buffersize)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 646 | m_demux_entries = 0; |
| 647 | msg_thread_id = 0; |
| 648 | async_thread_id = 0; |
| 649 | msg_thread_created = false; |
| 650 | async_thread_created = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 651 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 652 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 653 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 654 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 655 | memset(&m_frame_pack_arrangement, 0, sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 656 | drv_ctx.timestamp_adjust = false; |
| 657 | drv_ctx.video_driver_fd = -1; |
| 658 | m_vendor_config.pData = NULL; |
| 659 | pthread_mutex_init(&m_lock, NULL); |
| 660 | pthread_mutex_init(&c_lock, NULL); |
| 661 | sem_init(&m_cmd_lock,0,0); |
| 662 | streaming[CAPTURE_PORT] = |
| 663 | streaming[OUTPUT_PORT] = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 664 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 665 | char extradata_value[PROPERTY_VALUE_MAX] = {0}; |
| 666 | property_get("vidc.dec.debug.extradata", extradata_value, "0"); |
| 667 | m_debug_extradata = atoi(extradata_value); |
| 668 | DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 669 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 670 | m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB; |
| 671 | client_buffers.set_vdec_client(this); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 672 | dynamic_buf_mode = false; |
| 673 | out_dynamic_list = NULL; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 674 | is_down_scalar_enabled = false; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 675 | m_smoothstreaming_mode = false; |
| 676 | m_smoothstreaming_width = 0; |
| 677 | m_smoothstreaming_height = 0; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 678 | is_q6_platform = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 681 | static const int event_type[] = { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 682 | V4L2_EVENT_MSM_VIDC_FLUSH_DONE, |
| 683 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT, |
| 684 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT, |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 685 | V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE, |
| 686 | V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 687 | V4L2_EVENT_MSM_VIDC_CLOSE_DONE, |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 688 | V4L2_EVENT_MSM_VIDC_SYS_ERROR, |
| 689 | V4L2_EVENT_MSM_VIDC_HW_OVERLOAD |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | static OMX_ERRORTYPE subscribe_to_events(int fd) |
| 693 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 694 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 695 | struct v4l2_event_subscription sub; |
| 696 | int array_sz = sizeof(event_type)/sizeof(int); |
| 697 | int i,rc; |
| 698 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 699 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 700 | return OMX_ErrorBadParameter; |
| 701 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 702 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 703 | for (i = 0; i < array_sz; ++i) { |
| 704 | memset(&sub, 0, sizeof(sub)); |
| 705 | sub.type = event_type[i]; |
| 706 | rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub); |
| 707 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 708 | DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 709 | break; |
| 710 | } |
| 711 | } |
| 712 | if (i < array_sz) { |
| 713 | for (--i; i >=0 ; i--) { |
| 714 | memset(&sub, 0, sizeof(sub)); |
| 715 | sub.type = event_type[i]; |
| 716 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 717 | if (rc) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 718 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 719 | } |
| 720 | eRet = OMX_ErrorNotImplemented; |
| 721 | } |
| 722 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | |
| 726 | static OMX_ERRORTYPE unsubscribe_to_events(int fd) |
| 727 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 728 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 729 | struct v4l2_event_subscription sub; |
| 730 | int array_sz = sizeof(event_type)/sizeof(int); |
| 731 | int i,rc; |
| 732 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 733 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 734 | return OMX_ErrorBadParameter; |
| 735 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 736 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 737 | for (i = 0; i < array_sz; ++i) { |
| 738 | memset(&sub, 0, sizeof(sub)); |
| 739 | sub.type = event_type[i]; |
| 740 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 741 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 742 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 743 | break; |
| 744 | } |
| 745 | } |
| 746 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 747 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 748 | |
| 749 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 750 | FUNCTION |
| 751 | omx_vdec::~omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 752 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 753 | DESCRIPTION |
| 754 | Destructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 755 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 756 | PARAMETERS |
| 757 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 758 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 759 | RETURN VALUE |
| 760 | None. |
| 761 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 762 | omx_vdec::~omx_vdec() |
| 763 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 764 | m_pmem_info = NULL; |
| 765 | struct v4l2_decoder_cmd dec; |
| 766 | DEBUG_PRINT_HIGH("In OMX vdec Destructor"); |
| 767 | if (m_pipe_in) close(m_pipe_in); |
| 768 | if (m_pipe_out) close(m_pipe_out); |
| 769 | m_pipe_in = -1; |
| 770 | m_pipe_out = -1; |
| 771 | DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit"); |
| 772 | if (msg_thread_created) |
| 773 | pthread_join(msg_thread_id,NULL); |
| 774 | DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit"); |
| 775 | dec.cmd = V4L2_DEC_CMD_STOP; |
| 776 | if (drv_ctx.video_driver_fd >=0 ) { |
| 777 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 778 | DEBUG_PRINT_ERROR("STOP Command failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 779 | } |
| 780 | if (async_thread_created) |
| 781 | pthread_join(async_thread_id,NULL); |
| 782 | unsubscribe_to_events(drv_ctx.video_driver_fd); |
| 783 | close(drv_ctx.video_driver_fd); |
| 784 | pthread_mutex_destroy(&m_lock); |
| 785 | pthread_mutex_destroy(&c_lock); |
| 786 | sem_destroy(&m_cmd_lock); |
| 787 | if (perf_flag) { |
| 788 | DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME"); |
| 789 | dec_time.end(); |
| 790 | } |
| 791 | DEBUG_PRINT_HIGH("Exit OMX vdec Destructor"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 794 | int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type) |
| 795 | { |
| 796 | struct v4l2_requestbuffers bufreq; |
| 797 | int rc = 0; |
| 798 | if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 799 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 800 | bufreq.count = 0; |
| 801 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 802 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 803 | } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 804 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 805 | bufreq.count = 0; |
| 806 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 807 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 808 | } |
| 809 | return rc; |
Vinay Kalia | feef703 | 2012-09-25 19:23:33 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 812 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 813 | FUNCTION |
| 814 | omx_vdec::OMXCntrlProcessMsgCb |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 815 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 816 | DESCRIPTION |
| 817 | IL Client callbacks are generated through this routine. The decoder |
| 818 | provides the thread context for this routine. |
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 | PARAMETERS |
| 821 | ctxt -- Context information related to the self. |
| 822 | id -- Event identifier. This could be any of the following: |
| 823 | 1. Command completion event |
| 824 | 2. Buffer done callback event |
| 825 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 826 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 827 | RETURN VALUE |
| 828 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 829 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 830 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 831 | void omx_vdec::process_event_cb(void *ctxt, unsigned char id) |
| 832 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 833 | signed p1; // Parameter - 1 |
| 834 | signed p2; // Parameter - 2 |
| 835 | unsigned ident; |
| 836 | unsigned qsize=0; // qsize |
| 837 | omx_vdec *pThis = (omx_vdec *) ctxt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 838 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 839 | if (!pThis) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 840 | DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 841 | __func__); |
| 842 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 845 | // Protect the shared queue data structure |
| 846 | do { |
| 847 | /*Read the message id's from the queue*/ |
| 848 | pthread_mutex_lock(&pThis->m_lock); |
| 849 | qsize = pThis->m_cmd_q.m_size; |
| 850 | if (qsize) { |
| 851 | pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 852 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 853 | |
| 854 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 855 | qsize = pThis->m_ftb_q.m_size; |
| 856 | if (qsize) { |
| 857 | pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 858 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 859 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 860 | |
| 861 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 862 | qsize = pThis->m_etb_q.m_size; |
| 863 | if (qsize) { |
| 864 | pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 865 | } |
| 866 | } |
| 867 | pthread_mutex_unlock(&pThis->m_lock); |
| 868 | |
| 869 | /*process message if we have one*/ |
| 870 | if (qsize > 0) { |
| 871 | id = ident; |
| 872 | switch (id) { |
| 873 | case OMX_COMPONENT_GENERATE_EVENT: |
| 874 | if (pThis->m_cb.EventHandler) { |
| 875 | switch (p1) { |
| 876 | case OMX_CommandStateSet: |
| 877 | pThis->m_state = (OMX_STATETYPE) p2; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 878 | DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 879 | pThis->m_state); |
| 880 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 881 | OMX_EventCmdComplete, p1, p2, NULL); |
| 882 | break; |
| 883 | |
| 884 | case OMX_EventError: |
| 885 | if (p2 == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 886 | DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 887 | pThis->m_state = (OMX_STATETYPE) p2; |
| 888 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 889 | OMX_EventError, OMX_ErrorInvalidState, p2, NULL); |
| 890 | } else if (p2 == OMX_ErrorHardware) { |
| 891 | pThis->omx_report_error(); |
| 892 | } else { |
| 893 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 894 | OMX_EventError, p2, (OMX_U32)NULL, NULL ); |
| 895 | } |
| 896 | break; |
| 897 | |
| 898 | case OMX_CommandPortDisable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 899 | DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 900 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 901 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
| 902 | BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
| 903 | break; |
| 904 | } |
| 905 | if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 906 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 907 | pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
| 908 | if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 909 | DEBUG_PRINT_HIGH("Failed to release output buffers"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 910 | OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf); |
| 911 | pThis->in_reconfig = false; |
| 912 | if (eRet != OMX_ErrorNone) { |
| 913 | DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet); |
| 914 | pThis->omx_report_error(); |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 919 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 920 | break; |
| 921 | case OMX_CommandPortEnable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 922 | DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 923 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\ |
| 924 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 925 | break; |
| 926 | |
| 927 | default: |
| 928 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 929 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 930 | break; |
| 931 | |
| 932 | } |
| 933 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 934 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 935 | } |
| 936 | break; |
| 937 | case OMX_COMPONENT_GENERATE_ETB_ARBITRARY: |
| 938 | if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 939 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 940 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 941 | pThis->omx_report_error (); |
| 942 | } |
| 943 | break; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 944 | case OMX_COMPONENT_GENERATE_ETB: { |
| 945 | OMX_ERRORTYPE iret; |
| 946 | iret = pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1, (OMX_BUFFERHEADERTYPE *)p2); |
| 947 | if (iret == OMX_ErrorInsufficientResources) { |
| 948 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure due to HW overload"); |
| 949 | pThis->omx_report_hw_overload (); |
| 950 | } else if (iret != OMX_ErrorNone) { |
| 951 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure"); |
| 952 | pThis->omx_report_error (); |
| 953 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 954 | } |
| 955 | break; |
| 956 | |
| 957 | case OMX_COMPONENT_GENERATE_FTB: |
| 958 | if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 959 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 960 | DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 961 | pThis->omx_report_error (); |
| 962 | } |
| 963 | break; |
| 964 | |
| 965 | case OMX_COMPONENT_GENERATE_COMMAND: |
| 966 | pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\ |
| 967 | (OMX_U32)p2,(OMX_PTR)NULL); |
| 968 | break; |
| 969 | |
| 970 | case OMX_COMPONENT_GENERATE_EBD: |
| 971 | |
| 972 | if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 973 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 974 | pThis->omx_report_error (); |
| 975 | } else { |
| 976 | if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 977 | pThis->time_stamp_dts.remove_time_stamp( |
| 978 | ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp, |
| 979 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 980 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 981 | } |
Deva Ramasubramanian | 02b0d88 | 2014-04-03 14:58:50 -0700 | [diff] [blame] | 982 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 983 | if ( pThis->empty_buffer_done(&pThis->m_cmp, |
| 984 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 985 | DEBUG_PRINT_ERROR("empty_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 986 | pThis->omx_report_error (); |
| 987 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 988 | } |
| 989 | break; |
| 990 | case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: { |
| 991 | int64_t *timestamp = (int64_t *)p1; |
| 992 | if (p1) { |
| 993 | pThis->time_stamp_dts.remove_time_stamp(*timestamp, |
| 994 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 995 | ?true:false); |
| 996 | free(timestamp); |
| 997 | } |
| 998 | } |
| 999 | break; |
| 1000 | case OMX_COMPONENT_GENERATE_FBD: |
| 1001 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1002 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1003 | pThis->omx_report_error (); |
| 1004 | } else if ( pThis->fill_buffer_done(&pThis->m_cmp, |
| 1005 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1006 | DEBUG_PRINT_ERROR("fill_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1007 | pThis->omx_report_error (); |
| 1008 | } |
| 1009 | break; |
| 1010 | |
| 1011 | case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1012 | DEBUG_PRINT_HIGH("Driver flush i/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1013 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1014 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1015 | } else { |
| 1016 | pThis->execute_input_flush(); |
| 1017 | if (pThis->m_cb.EventHandler) { |
| 1018 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1019 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1020 | pThis->omx_report_error (); |
| 1021 | } else { |
| 1022 | /*Check if we need generate event for Flush done*/ |
| 1023 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1024 | OMX_COMPONENT_INPUT_FLUSH_PENDING)) { |
| 1025 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1026 | DEBUG_PRINT_LOW("Input Flush completed - Notify Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1027 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1028 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1029 | OMX_CORE_INPUT_PORT_INDEX,NULL ); |
| 1030 | } |
| 1031 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1032 | OMX_COMPONENT_IDLE_PENDING)) { |
| 1033 | if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1034 | DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1035 | pThis->omx_report_error (); |
| 1036 | } else { |
| 1037 | pThis->streaming[OUTPUT_PORT] = false; |
| 1038 | } |
| 1039 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1040 | DEBUG_PRINT_LOW("Input flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1041 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1042 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | } else { |
| 1047 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1048 | } |
| 1049 | } |
| 1050 | break; |
| 1051 | |
| 1052 | case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1053 | DEBUG_PRINT_HIGH("Driver flush o/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1054 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1055 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1056 | } else { |
| 1057 | pThis->execute_output_flush(); |
| 1058 | if (pThis->m_cb.EventHandler) { |
| 1059 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1060 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1061 | pThis->omx_report_error (); |
| 1062 | } else { |
| 1063 | /*Check if we need generate event for Flush done*/ |
| 1064 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1065 | OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1066 | DEBUG_PRINT_LOW("Notify Output Flush done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1067 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 1068 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1069 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1070 | OMX_CORE_OUTPUT_PORT_INDEX,NULL ); |
| 1071 | } |
| 1072 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1073 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1074 | DEBUG_PRINT_LOW("Internal flush complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1075 | BITMASK_CLEAR (&pThis->m_flags, |
| 1076 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 1077 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1078 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) { |
| 1079 | pThis->post_event(OMX_CommandPortDisable, |
| 1080 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 1081 | OMX_COMPONENT_GENERATE_EVENT); |
| 1082 | BITMASK_CLEAR (&pThis->m_flags, |
| 1083 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
Praneeth Paladugu | b52072a | 2013-08-23 13:54:43 -0700 | [diff] [blame] | 1084 | BITMASK_CLEAR (&pThis->m_flags, |
| 1085 | OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1086 | |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) { |
| 1091 | if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1092 | DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1093 | pThis->omx_report_error (); |
| 1094 | break; |
| 1095 | } |
| 1096 | pThis->streaming[CAPTURE_PORT] = false; |
| 1097 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1098 | DEBUG_PRINT_LOW("Output flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1099 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1100 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | } else { |
| 1105 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1106 | } |
| 1107 | } |
| 1108 | break; |
| 1109 | |
| 1110 | case OMX_COMPONENT_GENERATE_START_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1111 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1112 | |
| 1113 | if (pThis->m_cb.EventHandler) { |
| 1114 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1115 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1116 | pThis->omx_report_error (); |
| 1117 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1118 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1119 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1120 | DEBUG_PRINT_LOW("Move to executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1121 | // Send the callback now |
| 1122 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1123 | pThis->m_state = OMX_StateExecuting; |
| 1124 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1125 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1126 | OMX_StateExecuting, NULL); |
| 1127 | } else if (BITMASK_PRESENT(&pThis->m_flags, |
| 1128 | OMX_COMPONENT_PAUSE_PENDING)) { |
| 1129 | if (/*ioctl (pThis->drv_ctx.video_driver_fd, |
| 1130 | VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1131 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1132 | pThis->omx_report_error (); |
| 1133 | } |
| 1134 | } |
| 1135 | } |
| 1136 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1137 | DEBUG_PRINT_LOW("Event Handler callback is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1138 | } |
| 1139 | break; |
| 1140 | |
| 1141 | case OMX_COMPONENT_GENERATE_PAUSE_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1142 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1143 | if (pThis->m_cb.EventHandler) { |
| 1144 | if (p2 != VDEC_S_SUCCESS) { |
| 1145 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed"); |
| 1146 | pThis->omx_report_error (); |
| 1147 | } else { |
| 1148 | pThis->complete_pending_buffer_done_cbs(); |
| 1149 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1150 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1151 | //Send the callback now |
| 1152 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING); |
| 1153 | pThis->m_state = OMX_StatePause; |
| 1154 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1155 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1156 | OMX_StatePause, NULL); |
| 1157 | } |
| 1158 | } |
| 1159 | } else { |
| 1160 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1161 | } |
| 1162 | |
| 1163 | break; |
| 1164 | |
| 1165 | case OMX_COMPONENT_GENERATE_RESUME_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1166 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1167 | if (pThis->m_cb.EventHandler) { |
| 1168 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1169 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1170 | pThis->omx_report_error (); |
| 1171 | } else { |
| 1172 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1173 | DEBUG_PRINT_LOW("Moving the decoder to execute state"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1174 | // Send the callback now |
| 1175 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1176 | pThis->m_state = OMX_StateExecuting; |
| 1177 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1178 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1179 | OMX_StateExecuting,NULL); |
| 1180 | } |
| 1181 | } |
| 1182 | } else { |
| 1183 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1184 | } |
| 1185 | |
| 1186 | break; |
| 1187 | |
| 1188 | case OMX_COMPONENT_GENERATE_STOP_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1189 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1190 | if (pThis->m_cb.EventHandler) { |
| 1191 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1192 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1193 | pThis->omx_report_error (); |
| 1194 | } else { |
| 1195 | pThis->complete_pending_buffer_done_cbs(); |
| 1196 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1197 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1198 | // Send the callback now |
| 1199 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 1200 | pThis->m_state = OMX_StateIdle; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1201 | DEBUG_PRINT_LOW("Move to Idle State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1202 | pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data, |
| 1203 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1204 | OMX_StateIdle,NULL); |
| 1205 | } |
| 1206 | } |
| 1207 | } else { |
| 1208 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1209 | } |
| 1210 | |
| 1211 | break; |
| 1212 | |
| 1213 | case OMX_COMPONENT_GENERATE_PORT_RECONFIG: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1214 | if (p2 == OMX_IndexParamPortDefinition) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1215 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1216 | pThis->in_reconfig = true; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1217 | |
| 1218 | } else if (p2 == OMX_IndexConfigCommonOutputCrop) { |
| 1219 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexConfigCommonOutputCrop"); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1220 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1221 | /* Check if resolution is changed in smooth streaming mode */ |
| 1222 | if (pThis->m_smoothstreaming_mode && |
| 1223 | (pThis->framesize.nWidth != |
| 1224 | pThis->drv_ctx.video_resolution.frame_width) || |
| 1225 | (pThis->framesize.nHeight != |
| 1226 | pThis->drv_ctx.video_resolution.frame_height)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1227 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1228 | DEBUG_PRINT_HIGH("Resolution changed from: wxh = %dx%d to: wxh = %dx%d", |
| 1229 | pThis->framesize.nWidth, |
| 1230 | pThis->framesize.nHeight, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1231 | pThis->drv_ctx.video_resolution.frame_width, |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1232 | pThis->drv_ctx.video_resolution.frame_height); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1233 | |
| 1234 | /* Update new resolution */ |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1235 | pThis->framesize.nWidth = |
| 1236 | pThis->drv_ctx.video_resolution.frame_width; |
| 1237 | pThis->framesize.nHeight = |
| 1238 | pThis->drv_ctx.video_resolution.frame_height; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1239 | |
| 1240 | /* Update C2D with new resolution */ |
| 1241 | if (!pThis->client_buffers.update_buffer_req()) { |
| 1242 | DEBUG_PRINT_ERROR("Setting C2D buffer requirements failed"); |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | /* Update new crop information */ |
| 1247 | pThis->rectangle.nLeft = pThis->drv_ctx.frame_size.left; |
| 1248 | pThis->rectangle.nTop = pThis->drv_ctx.frame_size.top; |
| 1249 | pThis->rectangle.nWidth = pThis->drv_ctx.frame_size.right; |
| 1250 | pThis->rectangle.nHeight = pThis->drv_ctx.frame_size.bottom; |
| 1251 | |
| 1252 | /* Validate the new crop information */ |
| 1253 | if (pThis->rectangle.nLeft + pThis->rectangle.nWidth > |
| 1254 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1255 | |
| 1256 | DEBUG_PRINT_HIGH("Crop L[%u] + R[%u] > W[%u]", |
| 1257 | pThis->rectangle.nLeft, pThis->rectangle.nWidth, |
| 1258 | pThis->drv_ctx.video_resolution.frame_width); |
| 1259 | pThis->rectangle.nLeft = 0; |
| 1260 | |
| 1261 | if (pThis->rectangle.nWidth > |
| 1262 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1263 | |
| 1264 | DEBUG_PRINT_HIGH("Crop R[%u] > W[%u]", |
| 1265 | pThis->rectangle.nWidth, |
| 1266 | pThis->drv_ctx.video_resolution.frame_width); |
| 1267 | pThis->rectangle.nWidth = |
| 1268 | pThis->drv_ctx.video_resolution.frame_width; |
| 1269 | } |
| 1270 | } |
| 1271 | if (pThis->rectangle.nTop + pThis->rectangle.nHeight > |
| 1272 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1273 | |
| 1274 | DEBUG_PRINT_HIGH("Crop T[%u] + B[%u] > H[%u]", |
| 1275 | pThis->rectangle.nTop, pThis->rectangle.nHeight, |
| 1276 | pThis->drv_ctx.video_resolution.frame_height); |
| 1277 | pThis->rectangle.nTop = 0; |
| 1278 | |
| 1279 | if (pThis->rectangle.nHeight > |
| 1280 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1281 | |
| 1282 | DEBUG_PRINT_HIGH("Crop B[%u] > H[%u]", |
| 1283 | pThis->rectangle.nHeight, |
| 1284 | pThis->drv_ctx.video_resolution.frame_height); |
| 1285 | pThis->rectangle.nHeight = |
| 1286 | pThis->drv_ctx.video_resolution.frame_height; |
| 1287 | } |
| 1288 | } |
| 1289 | DEBUG_PRINT_HIGH("Updated Crop Info: L: %u, T: %u, R: %u, B: %u", |
| 1290 | pThis->rectangle.nLeft, pThis->rectangle.nTop, |
| 1291 | pThis->rectangle.nWidth, pThis->rectangle.nHeight); |
| 1292 | } else { |
| 1293 | DEBUG_PRINT_ERROR("Rxd Invalid PORT_RECONFIG event (%lu)", p2); |
| 1294 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1295 | } |
| 1296 | if (pThis->m_cb.EventHandler) { |
| 1297 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1298 | OMX_EventPortSettingsChanged, p1, p2, NULL ); |
| 1299 | } else { |
| 1300 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1301 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1302 | break; |
| 1303 | |
| 1304 | case OMX_COMPONENT_GENERATE_EOS_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1305 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1306 | if (pThis->m_cb.EventHandler) { |
| 1307 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag, |
| 1308 | OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL ); |
| 1309 | } else { |
| 1310 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1311 | } |
| 1312 | pThis->prev_ts = LLONG_MAX; |
| 1313 | pThis->rst_prev_ts = true; |
| 1314 | break; |
| 1315 | |
| 1316 | case OMX_COMPONENT_GENERATE_HARDWARE_ERROR: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1317 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1318 | pThis->omx_report_error (); |
| 1319 | break; |
| 1320 | |
| 1321 | case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1322 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1323 | pThis->omx_report_unsupported_setting(); |
| 1324 | break; |
| 1325 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 1326 | case OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD: |
| 1327 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD"); |
| 1328 | pThis->omx_report_hw_overload(); |
| 1329 | break; |
| 1330 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1331 | default: |
| 1332 | break; |
| 1333 | } |
| 1334 | } |
| 1335 | pthread_mutex_lock(&pThis->m_lock); |
| 1336 | qsize = pThis->m_cmd_q.m_size; |
| 1337 | if (pThis->m_state != OMX_StatePause) |
| 1338 | qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size); |
| 1339 | pthread_mutex_unlock(&pThis->m_lock); |
| 1340 | } while (qsize>0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1341 | |
| 1342 | } |
| 1343 | |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 1344 | 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] | 1345 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1346 | int format_changed = 0; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 1347 | if ((height != (int)drv_ctx.video_resolution.frame_height) || |
| 1348 | (width != (int)drv_ctx.video_resolution.frame_width)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1349 | DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1350 | width, drv_ctx.video_resolution.frame_width, |
| 1351 | height,drv_ctx.video_resolution.frame_height); |
| 1352 | format_changed = 1; |
| 1353 | } |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1354 | drv_ctx.video_resolution.frame_height = height; |
| 1355 | drv_ctx.video_resolution.frame_width = width; |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 1356 | drv_ctx.video_resolution.scan_lines = scan_lines; |
| 1357 | drv_ctx.video_resolution.stride = stride; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 1358 | if(!is_down_scalar_enabled) { |
| 1359 | rectangle.nLeft = 0; |
| 1360 | rectangle.nTop = 0; |
| 1361 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1362 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
| 1363 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1364 | return format_changed; |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1367 | OMX_ERRORTYPE omx_vdec::is_video_session_supported() |
| 1368 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1369 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", |
| 1370 | OMX_MAX_STRINGNAME_SIZE) && |
| 1371 | (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) { |
| 1372 | m_decoder_capability.max_width = 1280; |
| 1373 | m_decoder_capability.max_height = 720; |
| 1374 | DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP"); |
| 1375 | } |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 1376 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1377 | if ((drv_ctx.video_resolution.frame_width * |
| 1378 | drv_ctx.video_resolution.frame_height > |
| 1379 | m_decoder_capability.max_width * |
| 1380 | m_decoder_capability.max_height) || |
| 1381 | (drv_ctx.video_resolution.frame_width* |
| 1382 | drv_ctx.video_resolution.frame_height < |
| 1383 | m_decoder_capability.min_width * |
| 1384 | m_decoder_capability.min_height)) { |
| 1385 | DEBUG_PRINT_ERROR( |
| 1386 | "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)", |
| 1387 | drv_ctx.video_resolution.frame_width, |
| 1388 | drv_ctx.video_resolution.frame_height, |
| 1389 | m_decoder_capability.min_width, |
| 1390 | m_decoder_capability.min_height, |
| 1391 | m_decoder_capability.max_width, |
| 1392 | m_decoder_capability.max_height); |
| 1393 | return OMX_ErrorUnsupportedSetting; |
| 1394 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1395 | DEBUG_PRINT_HIGH("video session supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1396 | return OMX_ErrorNone; |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1397 | } |
| 1398 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1399 | int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len) |
| 1400 | { |
| 1401 | if (m_debug.in_buffer_log && !m_debug.infile) { |
| 1402 | if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) { |
| 1403 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v", |
| 1404 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1405 | } |
| 1406 | else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) { |
| 1407 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.mpg", m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); } |
| 1408 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) { |
| 1409 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263", |
| 1410 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1411 | } |
| 1412 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) { |
| 1413 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264", |
| 1414 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1415 | } |
| 1416 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) { |
| 1417 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1418 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1419 | } |
| 1420 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) { |
| 1421 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1422 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1423 | } |
| 1424 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1425 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf", |
| 1426 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1427 | } |
| 1428 | m_debug.infile = fopen (m_debug.infile_name, "ab"); |
| 1429 | if (!m_debug.infile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1430 | 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] | 1431 | m_debug.infile_name[0] = '\0'; |
| 1432 | return -1; |
| 1433 | } |
| 1434 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1435 | struct ivf_file_header { |
| 1436 | OMX_U8 signature[4]; //='DKIF'; |
| 1437 | OMX_U8 version ; //= 0; |
| 1438 | OMX_U8 headersize ; //= 32; |
| 1439 | OMX_U32 FourCC; |
| 1440 | OMX_U8 width; |
| 1441 | OMX_U8 height; |
| 1442 | OMX_U32 rate; |
| 1443 | OMX_U32 scale; |
| 1444 | OMX_U32 length; |
| 1445 | OMX_U8 unused[4]; |
| 1446 | } file_header; |
| 1447 | |
| 1448 | memset((void *)&file_header,0,sizeof(file_header)); |
| 1449 | file_header.signature[0] = 'D'; |
| 1450 | file_header.signature[1] = 'K'; |
| 1451 | file_header.signature[2] = 'I'; |
| 1452 | file_header.signature[3] = 'F'; |
| 1453 | file_header.version = 0; |
| 1454 | file_header.headersize = 32; |
| 1455 | file_header.FourCC = 0x30385056; |
| 1456 | fwrite((const char *)&file_header, |
| 1457 | sizeof(file_header),1,m_debug.infile); |
| 1458 | } |
| 1459 | } |
| 1460 | if (m_debug.infile && buffer_addr && buffer_len) { |
| 1461 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1462 | struct vp8_ivf_frame_header { |
| 1463 | OMX_U32 framesize; |
| 1464 | OMX_U32 timestamp_lo; |
| 1465 | OMX_U32 timestamp_hi; |
| 1466 | } vp8_frame_header; |
| 1467 | vp8_frame_header.framesize = buffer_len; |
| 1468 | /* Currently FW doesn't use timestamp values */ |
| 1469 | vp8_frame_header.timestamp_lo = 0; |
| 1470 | vp8_frame_header.timestamp_hi = 0; |
| 1471 | fwrite((const char *)&vp8_frame_header, |
| 1472 | sizeof(vp8_frame_header),1,m_debug.infile); |
| 1473 | } |
| 1474 | fwrite(buffer_addr, buffer_len, 1, m_debug.infile); |
| 1475 | } |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) { |
| 1480 | if (m_debug.out_buffer_log && !m_debug.outfile) { |
| 1481 | sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv", |
| 1482 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1483 | m_debug.outfile = fopen (m_debug.outfile_name, "ab"); |
| 1484 | if (!m_debug.outfile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1485 | 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] | 1486 | m_debug.outfile_name[0] = '\0'; |
| 1487 | return -1; |
| 1488 | } |
| 1489 | } |
| 1490 | if (m_debug.outfile && buffer && buffer->nFilledLen) { |
| 1491 | int buf_index = buffer - m_out_mem_ptr; |
| 1492 | int stride = drv_ctx.video_resolution.stride; |
| 1493 | int scanlines = drv_ctx.video_resolution.scan_lines; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1494 | if (m_smoothstreaming_mode) { |
| 1495 | stride = drv_ctx.video_resolution.frame_width; |
| 1496 | scanlines = drv_ctx.video_resolution.frame_height; |
| 1497 | stride = (stride + DEFAULT_WIDTH_ALIGNMENT - 1) & (~(DEFAULT_WIDTH_ALIGNMENT - 1)); |
| 1498 | scanlines = (scanlines + DEFAULT_HEIGHT_ALIGNMENT - 1) & (~(DEFAULT_HEIGHT_ALIGNMENT - 1)); |
| 1499 | } |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1500 | char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr; |
| 1501 | unsigned i; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1502 | DEBUG_PRINT_HIGH("Logging width/height(%u/%u) stride/scanlines(%u/%u)", |
| 1503 | drv_ctx.video_resolution.frame_width, |
| 1504 | drv_ctx.video_resolution.frame_height, stride, scanlines); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1505 | int bytes_written = 0; |
| 1506 | for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) { |
| 1507 | bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1508 | temp += stride; |
| 1509 | } |
| 1510 | temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines; |
| 1511 | int stride_c = stride; |
| 1512 | for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) { |
| 1513 | bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1514 | temp += stride_c; |
| 1515 | } |
| 1516 | } |
| 1517 | return 0; |
| 1518 | } |
| 1519 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1520 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1521 | FUNCTION |
| 1522 | omx_vdec::ComponentInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1523 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1524 | DESCRIPTION |
| 1525 | Initialize the component. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1526 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1527 | PARAMETERS |
| 1528 | ctxt -- Context information related to the self. |
| 1529 | id -- Event identifier. This could be any of the following: |
| 1530 | 1. Command completion event |
| 1531 | 2. Buffer done callback event |
| 1532 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1533 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1534 | RETURN VALUE |
| 1535 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1536 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1537 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1538 | OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role) |
| 1539 | { |
| 1540 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1541 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 1542 | struct v4l2_fmtdesc fdesc; |
| 1543 | struct v4l2_format fmt; |
| 1544 | struct v4l2_requestbuffers bufreq; |
| 1545 | struct v4l2_control control; |
| 1546 | struct v4l2_frmsizeenum frmsize; |
| 1547 | unsigned int alignment = 0,buffer_size = 0; |
| 1548 | int fds[2]; |
| 1549 | int r,ret=0; |
| 1550 | bool codec_ambiguous = false; |
| 1551 | OMX_STRING device_name = (OMX_STRING)"/dev/video/venus_dec"; |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 1552 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1553 | |
| 1554 | #ifdef _ANDROID_ |
Praveen Chavan | e9e5620 | 2013-09-19 03:48:16 -0700 | [diff] [blame] | 1555 | char platform_name[PROPERTY_VALUE_MAX]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1556 | property_get("ro.board.platform", platform_name, "0"); |
| 1557 | if (!strncmp(platform_name, "msm8610", 7)) { |
| 1558 | device_name = (OMX_STRING)"/dev/video/q6_dec"; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1559 | is_q6_platform = true; |
| 1560 | maxSmoothStreamingWidth = 1280; |
| 1561 | maxSmoothStreamingHeight = 720; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1562 | } |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1563 | #endif |
| 1564 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1565 | if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) { |
| 1566 | struct v4l2_control control; |
| 1567 | secure_mode = true; |
| 1568 | arbitrary_bytes = false; |
| 1569 | role = (OMX_STRING)"OMX.qcom.video.decoder.avc"; |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 1570 | } else if (!strncmp(role, "OMX.qcom.video.decoder.mpeg2.secure", |
| 1571 | OMX_MAX_STRINGNAME_SIZE)){ |
| 1572 | secure_mode = true; |
| 1573 | arbitrary_bytes = false; |
| 1574 | role = (OMX_STRING)"OMX.qcom.video.decoder.mpeg2"; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1575 | } |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1576 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1577 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1578 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1579 | DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open returned fd %d", |
Jayasena Sangaraboina | c453bd8 | 2013-08-01 14:02:52 -0700 | [diff] [blame] | 1580 | drv_ctx.video_driver_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1581 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1582 | if (drv_ctx.video_driver_fd == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1583 | 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] | 1584 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
| 1585 | close(0); |
| 1586 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1587 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1588 | if (drv_ctx.video_driver_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1589 | DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1590 | return OMX_ErrorInsufficientResources; |
| 1591 | } |
| 1592 | drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS; |
| 1593 | drv_ctx.frame_rate.fps_denominator = 1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1594 | |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1595 | ret = subscribe_to_events(drv_ctx.video_driver_fd); |
Vinay Kalia | 184cd0f | 2013-04-29 18:26:42 -0700 | [diff] [blame] | 1596 | if (!ret) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1597 | async_thread_created = true; |
| 1598 | ret = pthread_create(&async_thread_id,0,async_message_thread,this); |
| 1599 | } |
| 1600 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1601 | DEBUG_PRINT_ERROR("Failed to create async_message_thread"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1602 | async_thread_created = false; |
| 1603 | return OMX_ErrorInsufficientResources; |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1604 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1605 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1606 | #ifdef OUTPUT_EXTRADATA_LOG |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 1607 | outputExtradataFile = fopen (output_extradata_filename, "ab"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1608 | #endif |
| 1609 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1610 | // Copy the role information which provides the decoder kind |
| 1611 | strlcpy(drv_ctx.kind,role,128); |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1612 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1613 | if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\ |
| 1614 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1615 | strlcpy((char *)m_cRole, "video_decoder.mpeg4",\ |
| 1616 | OMX_MAX_STRINGNAME_SIZE); |
| 1617 | drv_ctx.timestamp_adjust = true; |
| 1618 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4; |
| 1619 | eCompressionFormat = OMX_VIDEO_CodingMPEG4; |
| 1620 | output_capability=V4L2_PIX_FMT_MPEG4; |
Deva Ramasubramanian | 14b50b4 | 2014-09-29 12:29:39 -0700 | [diff] [blame] | 1621 | ignore_not_coded_vops = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1622 | /*Initialize Start Code for MPEG4*/ |
| 1623 | codec_type_parse = CODEC_TYPE_MPEG4; |
| 1624 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1625 | } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\ |
| 1626 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1627 | strlcpy((char *)m_cRole, "video_decoder.mpeg2",\ |
| 1628 | OMX_MAX_STRINGNAME_SIZE); |
| 1629 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2; |
| 1630 | output_capability = V4L2_PIX_FMT_MPEG2; |
| 1631 | eCompressionFormat = OMX_VIDEO_CodingMPEG2; |
| 1632 | /*Initialize Start Code for MPEG2*/ |
| 1633 | codec_type_parse = CODEC_TYPE_MPEG2; |
| 1634 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1635 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\ |
| 1636 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1637 | strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1638 | DEBUG_PRINT_LOW("H263 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1639 | drv_ctx.decoder_format = VDEC_CODECTYPE_H263; |
| 1640 | eCompressionFormat = OMX_VIDEO_CodingH263; |
| 1641 | output_capability = V4L2_PIX_FMT_H263; |
| 1642 | codec_type_parse = CODEC_TYPE_H263; |
| 1643 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1644 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\ |
| 1645 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1646 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1647 | DEBUG_PRINT_LOW ("DIVX 311 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1648 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3; |
| 1649 | output_capability = V4L2_PIX_FMT_DIVX_311; |
| 1650 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1651 | codec_type_parse = CODEC_TYPE_DIVX; |
Deva Ramasubramanian | 14b50b4 | 2014-09-29 12:29:39 -0700 | [diff] [blame] | 1652 | ignore_not_coded_vops = true; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1653 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1654 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1655 | eRet = createDivxDrmContext(); |
| 1656 | if (eRet != OMX_ErrorNone) { |
| 1657 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1658 | return eRet; |
| 1659 | } |
| 1660 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\ |
| 1661 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1662 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1663 | DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1664 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4; |
| 1665 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1666 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1667 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1668 | codec_ambiguous = true; |
Deva Ramasubramanian | 14b50b4 | 2014-09-29 12:29:39 -0700 | [diff] [blame] | 1669 | ignore_not_coded_vops = true; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1670 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1671 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1672 | eRet = createDivxDrmContext(); |
| 1673 | if (eRet != OMX_ErrorNone) { |
| 1674 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1675 | return eRet; |
| 1676 | } |
| 1677 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\ |
| 1678 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1679 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1680 | DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1681 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6; |
| 1682 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1683 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1684 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1685 | codec_ambiguous = true; |
Deva Ramasubramanian | 14b50b4 | 2014-09-29 12:29:39 -0700 | [diff] [blame] | 1686 | ignore_not_coded_vops = true; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 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)); |
| 1951 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1955 | FUNCTION |
| 1956 | omx_vdec::GetComponentVersion |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1957 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1958 | DESCRIPTION |
| 1959 | Returns the component version. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1960 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1961 | PARAMETERS |
| 1962 | TBD. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1963 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1964 | RETURN VALUE |
| 1965 | OMX_ErrorNone. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1966 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1967 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1968 | OMX_ERRORTYPE omx_vdec::get_component_version |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1969 | ( |
| 1970 | OMX_IN OMX_HANDLETYPE hComp, |
| 1971 | OMX_OUT OMX_STRING componentName, |
| 1972 | OMX_OUT OMX_VERSIONTYPE* componentVersion, |
| 1973 | OMX_OUT OMX_VERSIONTYPE* specVersion, |
| 1974 | OMX_OUT OMX_UUIDTYPE* componentUUID |
| 1975 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1976 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1977 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1978 | DEBUG_PRINT_ERROR("Get Comp Version in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1979 | return OMX_ErrorInvalidState; |
| 1980 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1981 | /* TBD -- Return the proper version */ |
| 1982 | if (specVersion) { |
| 1983 | specVersion->nVersion = OMX_SPEC_VERSION; |
| 1984 | } |
| 1985 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1986 | } |
| 1987 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1988 | FUNCTION |
| 1989 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1990 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1991 | DESCRIPTION |
| 1992 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1993 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1994 | PARAMETERS |
| 1995 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1996 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1997 | RETURN VALUE |
| 1998 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1999 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2000 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2001 | OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2002 | OMX_IN OMX_COMMANDTYPE cmd, |
| 2003 | OMX_IN OMX_U32 param1, |
| 2004 | OMX_IN OMX_PTR cmdData |
| 2005 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2006 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2007 | DEBUG_PRINT_LOW("send_command: Recieved a Command from Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2008 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2009 | DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2010 | return OMX_ErrorInvalidState; |
| 2011 | } |
| 2012 | if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2013 | && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2014 | DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2015 | "to invalid port: %lu", param1); |
| 2016 | return OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2017 | } |
| 2018 | post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND); |
| 2019 | sem_wait(&m_cmd_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2020 | DEBUG_PRINT_LOW("send_command: Command Processed"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2021 | return OMX_ErrorNone; |
| 2022 | } |
| 2023 | |
| 2024 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2025 | FUNCTION |
| 2026 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2027 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2028 | DESCRIPTION |
| 2029 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2030 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2031 | PARAMETERS |
| 2032 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2033 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2034 | RETURN VALUE |
| 2035 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2036 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2037 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2038 | OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2039 | OMX_IN OMX_COMMANDTYPE cmd, |
| 2040 | OMX_IN OMX_U32 param1, |
| 2041 | OMX_IN OMX_PTR cmdData |
| 2042 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2043 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2044 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2045 | OMX_STATETYPE eState = (OMX_STATETYPE) param1; |
| 2046 | int bFlag = 1,sem_posted = 0,ret=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2047 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2048 | DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd); |
| 2049 | DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2050 | m_state, eState); |
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 | if (cmd == OMX_CommandStateSet) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2053 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued"); |
| 2054 | DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2055 | /***************************/ |
| 2056 | /* Current State is Loaded */ |
| 2057 | /***************************/ |
| 2058 | if (m_state == OMX_StateLoaded) { |
| 2059 | if (eState == OMX_StateIdle) { |
| 2060 | //if all buffers are allocated or all ports disabled |
| 2061 | if (allocate_done() || |
| 2062 | (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2063 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2064 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2065 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2066 | BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING); |
| 2067 | // Skip the event notification |
| 2068 | bFlag = 0; |
| 2069 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2070 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2071 | /* Requesting transition from Loaded to Loaded */ |
| 2072 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2073 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2074 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2075 | OMX_COMPONENT_GENERATE_EVENT); |
| 2076 | eRet = OMX_ErrorSameState; |
| 2077 | } |
| 2078 | /* Requesting transition from Loaded to WaitForResources */ |
| 2079 | else if (eState == OMX_StateWaitForResources) { |
| 2080 | /* Since error is None , we will post an event |
| 2081 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2082 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2083 | } |
| 2084 | /* Requesting transition from Loaded to Executing */ |
| 2085 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2086 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2087 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2088 | OMX_COMPONENT_GENERATE_EVENT); |
| 2089 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2090 | } |
| 2091 | /* Requesting transition from Loaded to Pause */ |
| 2092 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2093 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2094 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2095 | OMX_COMPONENT_GENERATE_EVENT); |
| 2096 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2097 | } |
| 2098 | /* Requesting transition from Loaded to Invalid */ |
| 2099 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2100 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2101 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2102 | eRet = OMX_ErrorInvalidState; |
| 2103 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2104 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2105 | eState); |
| 2106 | eRet = OMX_ErrorBadParameter; |
| 2107 | } |
| 2108 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2109 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2110 | /***************************/ |
| 2111 | /* Current State is IDLE */ |
| 2112 | /***************************/ |
| 2113 | else if (m_state == OMX_StateIdle) { |
| 2114 | if (eState == OMX_StateLoaded) { |
| 2115 | if (release_done()) { |
| 2116 | /* |
| 2117 | Since error is None , we will post an event at the end |
| 2118 | of this function definition |
| 2119 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2120 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2121 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2122 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2123 | BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING); |
| 2124 | // Skip the event notification |
| 2125 | bFlag = 0; |
| 2126 | } |
| 2127 | } |
| 2128 | /* Requesting transition from Idle to Executing */ |
| 2129 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2130 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2131 | //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING); |
| 2132 | bFlag = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2133 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2134 | m_state=OMX_StateExecuting; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2135 | DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2136 | } |
| 2137 | /* Requesting transition from Idle to Idle */ |
| 2138 | else if (eState == OMX_StateIdle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2139 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2140 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2141 | OMX_COMPONENT_GENERATE_EVENT); |
| 2142 | eRet = OMX_ErrorSameState; |
| 2143 | } |
| 2144 | /* Requesting transition from Idle to WaitForResources */ |
| 2145 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2146 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2147 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2148 | OMX_COMPONENT_GENERATE_EVENT); |
| 2149 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2150 | } |
| 2151 | /* Requesting transition from Idle to Pause */ |
| 2152 | else if (eState == OMX_StatePause) { |
| 2153 | /*To pause the Video core we need to start the driver*/ |
| 2154 | if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START, |
| 2155 | NULL) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2156 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2157 | omx_report_error (); |
| 2158 | eRet = OMX_ErrorHardware; |
| 2159 | } else { |
| 2160 | BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2161 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2162 | bFlag = 0; |
| 2163 | } |
| 2164 | } |
| 2165 | /* Requesting transition from Idle to Invalid */ |
| 2166 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2167 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2168 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2169 | eRet = OMX_ErrorInvalidState; |
| 2170 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2171 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2172 | eRet = OMX_ErrorBadParameter; |
| 2173 | } |
| 2174 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2175 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2176 | /******************************/ |
| 2177 | /* Current State is Executing */ |
| 2178 | /******************************/ |
| 2179 | else if (m_state == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2180 | DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2181 | /* Requesting transition from Executing to Idle */ |
| 2182 | if (eState == OMX_StateIdle) { |
| 2183 | /* Since error is None , we will post an event |
| 2184 | at the end of this function definition |
| 2185 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2186 | DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2187 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2188 | if (!sem_posted) { |
| 2189 | sem_posted = 1; |
| 2190 | sem_post (&m_cmd_lock); |
| 2191 | execute_omx_flush(OMX_ALL); |
| 2192 | } |
| 2193 | bFlag = 0; |
| 2194 | } |
| 2195 | /* Requesting transition from Executing to Paused */ |
| 2196 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2197 | DEBUG_PRINT_LOW("PAUSE Command Issued"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2198 | m_state = OMX_StatePause; |
| 2199 | bFlag = 1; |
| 2200 | } |
| 2201 | /* Requesting transition from Executing to Loaded */ |
| 2202 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2203 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2204 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2205 | OMX_COMPONENT_GENERATE_EVENT); |
| 2206 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2207 | } |
| 2208 | /* Requesting transition from Executing to WaitForResources */ |
| 2209 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2210 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2211 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2212 | OMX_COMPONENT_GENERATE_EVENT); |
| 2213 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2214 | } |
| 2215 | /* Requesting transition from Executing to Executing */ |
| 2216 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2217 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2218 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2219 | OMX_COMPONENT_GENERATE_EVENT); |
| 2220 | eRet = OMX_ErrorSameState; |
| 2221 | } |
| 2222 | /* Requesting transition from Executing to Invalid */ |
| 2223 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2224 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2225 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2226 | eRet = OMX_ErrorInvalidState; |
| 2227 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2228 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2229 | eRet = OMX_ErrorBadParameter; |
| 2230 | } |
| 2231 | } |
| 2232 | /***************************/ |
| 2233 | /* Current State is Pause */ |
| 2234 | /***************************/ |
| 2235 | else if (m_state == OMX_StatePause) { |
| 2236 | /* Requesting transition from Pause to Executing */ |
| 2237 | if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2238 | DEBUG_PRINT_LOW("Pause --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2239 | m_state = OMX_StateExecuting; |
| 2240 | bFlag = 1; |
| 2241 | } |
| 2242 | /* Requesting transition from Pause to Idle */ |
| 2243 | else if (eState == OMX_StateIdle) { |
| 2244 | /* Since error is None , we will post an event |
| 2245 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2246 | DEBUG_PRINT_LOW("Pause --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2247 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2248 | if (!sem_posted) { |
| 2249 | sem_posted = 1; |
| 2250 | sem_post (&m_cmd_lock); |
| 2251 | execute_omx_flush(OMX_ALL); |
| 2252 | } |
| 2253 | bFlag = 0; |
| 2254 | } |
| 2255 | /* Requesting transition from Pause to loaded */ |
| 2256 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2257 | DEBUG_PRINT_ERROR("Pause --> loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2258 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2259 | OMX_COMPONENT_GENERATE_EVENT); |
| 2260 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2261 | } |
| 2262 | /* Requesting transition from Pause to WaitForResources */ |
| 2263 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2264 | DEBUG_PRINT_ERROR("Pause --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2265 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2266 | OMX_COMPONENT_GENERATE_EVENT); |
| 2267 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2268 | } |
| 2269 | /* Requesting transition from Pause to Pause */ |
| 2270 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2271 | DEBUG_PRINT_ERROR("Pause --> Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2272 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2273 | OMX_COMPONENT_GENERATE_EVENT); |
| 2274 | eRet = OMX_ErrorSameState; |
| 2275 | } |
| 2276 | /* Requesting transition from Pause to Invalid */ |
| 2277 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2278 | DEBUG_PRINT_ERROR("Pause --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2279 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2280 | eRet = OMX_ErrorInvalidState; |
| 2281 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2282 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2283 | eRet = OMX_ErrorBadParameter; |
| 2284 | } |
| 2285 | } |
| 2286 | /***************************/ |
| 2287 | /* Current State is WaitForResources */ |
| 2288 | /***************************/ |
| 2289 | else if (m_state == OMX_StateWaitForResources) { |
| 2290 | /* Requesting transition from WaitForResources to Loaded */ |
| 2291 | if (eState == OMX_StateLoaded) { |
| 2292 | /* Since error is None , we will post an event |
| 2293 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2294 | DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2295 | } |
| 2296 | /* Requesting transition from WaitForResources to WaitForResources */ |
| 2297 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2298 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2299 | post_event(OMX_EventError,OMX_ErrorSameState, |
| 2300 | OMX_COMPONENT_GENERATE_EVENT); |
| 2301 | eRet = OMX_ErrorSameState; |
| 2302 | } |
| 2303 | /* Requesting transition from WaitForResources to Executing */ |
| 2304 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2305 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2306 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2307 | OMX_COMPONENT_GENERATE_EVENT); |
| 2308 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2309 | } |
| 2310 | /* Requesting transition from WaitForResources to Pause */ |
| 2311 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2312 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2313 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2314 | OMX_COMPONENT_GENERATE_EVENT); |
| 2315 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2316 | } |
| 2317 | /* Requesting transition from WaitForResources to Invalid */ |
| 2318 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2319 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2320 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2321 | eRet = OMX_ErrorInvalidState; |
| 2322 | } |
| 2323 | /* Requesting transition from WaitForResources to Loaded - |
| 2324 | is NOT tested by Khronos TS */ |
| 2325 | |
| 2326 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2327 | 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] | 2328 | eRet = OMX_ErrorBadParameter; |
| 2329 | } |
| 2330 | } |
| 2331 | /********************************/ |
| 2332 | /* Current State is Invalid */ |
| 2333 | /*******************************/ |
| 2334 | else if (m_state == OMX_StateInvalid) { |
| 2335 | /* State Transition from Inavlid to any state */ |
| 2336 | if (eState == (OMX_StateLoaded || OMX_StateWaitForResources |
| 2337 | || OMX_StateIdle || OMX_StateExecuting |
| 2338 | || OMX_StatePause || OMX_StateInvalid)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2339 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2340 | post_event(OMX_EventError,OMX_ErrorInvalidState,\ |
| 2341 | OMX_COMPONENT_GENERATE_EVENT); |
| 2342 | eRet = OMX_ErrorInvalidState; |
| 2343 | } |
| 2344 | } else if (cmd == OMX_CommandFlush) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2345 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2346 | "with param1: %lu", param1); |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2347 | #ifdef _MSM8974_ |
| 2348 | send_codec_config(); |
| 2349 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2350 | if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2351 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING); |
| 2352 | } |
| 2353 | if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2354 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 2355 | } |
| 2356 | if (!sem_posted) { |
| 2357 | sem_posted = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2358 | DEBUG_PRINT_LOW("Set the Semaphore"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2359 | sem_post (&m_cmd_lock); |
| 2360 | execute_omx_flush(param1); |
| 2361 | } |
| 2362 | bFlag = 0; |
| 2363 | } else if ( cmd == OMX_CommandPortEnable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2364 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2365 | "with param1: %lu", param1); |
| 2366 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2367 | m_inp_bEnabled = OMX_TRUE; |
| 2368 | |
| 2369 | if ( (m_state == OMX_StateLoaded && |
| 2370 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2371 | || allocate_input_done()) { |
| 2372 | post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX, |
| 2373 | OMX_COMPONENT_GENERATE_EVENT); |
| 2374 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2375 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2376 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 2377 | // Skip the event notification |
| 2378 | bFlag = 0; |
| 2379 | } |
| 2380 | } |
| 2381 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2382 | DEBUG_PRINT_LOW("Enable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2383 | m_out_bEnabled = OMX_TRUE; |
| 2384 | |
| 2385 | if ( (m_state == OMX_StateLoaded && |
| 2386 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2387 | || (allocate_output_done())) { |
| 2388 | post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX, |
| 2389 | OMX_COMPONENT_GENERATE_EVENT); |
| 2390 | |
| 2391 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2392 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2393 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 2394 | // Skip the event notification |
| 2395 | bFlag = 0; |
| 2396 | } |
| 2397 | } |
| 2398 | } else if (cmd == OMX_CommandPortDisable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2399 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2400 | "with param1: %lu", param1); |
| 2401 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2402 | codec_config_flag = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2403 | m_inp_bEnabled = OMX_FALSE; |
| 2404 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2405 | && release_input_done()) { |
| 2406 | post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX, |
| 2407 | OMX_COMPONENT_GENERATE_EVENT); |
| 2408 | } else { |
| 2409 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 2410 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2411 | if (!sem_posted) { |
| 2412 | sem_posted = 1; |
| 2413 | sem_post (&m_cmd_lock); |
| 2414 | } |
| 2415 | execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX); |
| 2416 | } |
| 2417 | |
| 2418 | // Skip the event notification |
| 2419 | bFlag = 0; |
| 2420 | } |
| 2421 | } |
| 2422 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2423 | m_out_bEnabled = OMX_FALSE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2424 | DEBUG_PRINT_LOW("Disable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2425 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2426 | && release_output_done()) { |
| 2427 | post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\ |
| 2428 | OMX_COMPONENT_GENERATE_EVENT); |
| 2429 | } else { |
| 2430 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
| 2431 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2432 | if (!sem_posted) { |
| 2433 | sem_posted = 1; |
| 2434 | sem_post (&m_cmd_lock); |
| 2435 | } |
| 2436 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 2437 | execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX); |
| 2438 | } |
| 2439 | // Skip the event notification |
| 2440 | bFlag = 0; |
| 2441 | |
| 2442 | } |
| 2443 | } |
| 2444 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2445 | DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2446 | eRet = OMX_ErrorNotImplemented; |
| 2447 | } |
| 2448 | if (eRet == OMX_ErrorNone && bFlag) { |
| 2449 | post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2450 | } |
| 2451 | if (!sem_posted) { |
| 2452 | sem_post(&m_cmd_lock); |
| 2453 | } |
| 2454 | |
| 2455 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2459 | FUNCTION |
| 2460 | omx_vdec::ExecuteOmxFlush |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2461 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2462 | DESCRIPTION |
| 2463 | Executes the OMX flush. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2464 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2465 | PARAMETERS |
| 2466 | flushtype - input flush(1)/output flush(0)/ both. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2467 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2468 | RETURN VALUE |
| 2469 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2470 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2471 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2472 | bool omx_vdec::execute_omx_flush(OMX_U32 flushType) |
| 2473 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2474 | bool bRet = false; |
| 2475 | struct v4l2_plane plane; |
| 2476 | struct v4l2_buffer v4l2_buf; |
| 2477 | struct v4l2_decoder_cmd dec; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 2478 | DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2479 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 2480 | dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH; |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2481 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2482 | DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig); |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2483 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2484 | if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 2485 | output_flush_progress = true; |
| 2486 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2487 | } else { |
| 2488 | /* XXX: The driver/hardware does not support flushing of individual ports |
| 2489 | * in all states. So we pretty much need to flush both ports internally, |
| 2490 | * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it |
| 2491 | * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set, |
| 2492 | * we automatically omit sending the FLUSH done for the "opposite" port. */ |
| 2493 | input_flush_progress = true; |
| 2494 | output_flush_progress = true; |
| 2495 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2496 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2497 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2498 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2499 | DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2500 | bRet = false; |
| 2501 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2502 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2503 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2504 | } |
| 2505 | /*========================================================================= |
| 2506 | FUNCTION : execute_output_flush |
| 2507 | |
| 2508 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2509 | Executes the OMX flush at OUTPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2510 | |
| 2511 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2512 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2513 | |
| 2514 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2515 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2516 | ==========================================================================*/ |
| 2517 | bool omx_vdec::execute_output_flush() |
| 2518 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2519 | unsigned p1 = 0; // Parameter - 1 |
| 2520 | unsigned p2 = 0; // Parameter - 2 |
| 2521 | unsigned ident = 0; |
| 2522 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2523 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2524 | /*Generate FBD for all Buffers in the FTBq*/ |
| 2525 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2526 | DEBUG_PRINT_LOW("Initiate Output Flush"); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 2527 | |
| 2528 | //reset last render TS |
| 2529 | if(m_last_rendered_TS > 0) { |
| 2530 | m_last_rendered_TS = 0; |
| 2531 | } |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 2532 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2533 | while (m_ftb_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2534 | DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2535 | m_ftb_q.m_size,pending_output_buffers); |
| 2536 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2537 | DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2538 | if (ident == m_fill_output_msg ) { |
| 2539 | m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2540 | } else if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 2541 | fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2542 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2543 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2544 | pthread_mutex_unlock(&m_lock); |
| 2545 | output_flush_progress = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2546 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2547 | if (arbitrary_bytes) { |
| 2548 | prev_ts = LLONG_MAX; |
| 2549 | rst_prev_ts = true; |
| 2550 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2551 | 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] | 2552 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2553 | } |
| 2554 | /*========================================================================= |
| 2555 | FUNCTION : execute_input_flush |
| 2556 | |
| 2557 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2558 | Executes the OMX flush at INPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2559 | |
| 2560 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2561 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2562 | |
| 2563 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2564 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2565 | ==========================================================================*/ |
| 2566 | bool omx_vdec::execute_input_flush() |
| 2567 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2568 | unsigned i =0; |
| 2569 | unsigned p1 = 0; // Parameter - 1 |
| 2570 | unsigned p2 = 0; // Parameter - 2 |
| 2571 | unsigned ident = 0; |
| 2572 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2573 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2574 | /*Generate EBD for all Buffers in the ETBq*/ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2575 | DEBUG_PRINT_LOW("Initiate Input Flush"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2576 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2577 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2578 | DEBUG_PRINT_LOW("Check if the Queue is empty"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2579 | while (m_etb_q.m_size) { |
| 2580 | m_etb_q.pop_entry(&p1,&p2,&ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2581 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2582 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2583 | DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2584 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2585 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 2586 | pending_input_buffers++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2587 | 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] | 2588 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 2589 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 2590 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2591 | DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2592 | (OMX_BUFFERHEADERTYPE *)p1); |
| 2593 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2594 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2595 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2596 | time_stamp_dts.flush_timestamp(); |
| 2597 | /*Check if Heap Buffers are to be flushed*/ |
| 2598 | if (arbitrary_bytes && !(codec_config_flag)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2599 | DEBUG_PRINT_LOW("Reset all the variables before flusing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2600 | h264_scratch.nFilledLen = 0; |
| 2601 | nal_count = 0; |
| 2602 | look_ahead_nal = false; |
| 2603 | frame_count = 0; |
| 2604 | h264_last_au_ts = LLONG_MAX; |
| 2605 | h264_last_au_flags = 0; |
| 2606 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 2607 | m_demux_entries = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2608 | DEBUG_PRINT_LOW("Initialize parser"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2609 | if (m_frame_parser.mutils) { |
| 2610 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 2611 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2612 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2613 | while (m_input_pending_q.m_size) { |
| 2614 | m_input_pending_q.pop_entry(&p1,&p2,&ident); |
| 2615 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1); |
| 2616 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2617 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2618 | if (psource_frame) { |
| 2619 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame); |
| 2620 | psource_frame = NULL; |
| 2621 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2622 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2623 | if (pdest_frame) { |
| 2624 | pdest_frame->nFilledLen = 0; |
| 2625 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL, |
| 2626 | (unsigned int)NULL); |
| 2627 | pdest_frame = NULL; |
| 2628 | } |
| 2629 | m_frame_parser.flush(); |
| 2630 | } else if (codec_config_flag) { |
| 2631 | DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer " |
| 2632 | "is not sent to the driver yet"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2633 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2634 | pthread_mutex_unlock(&m_lock); |
| 2635 | input_flush_progress = false; |
| 2636 | if (!arbitrary_bytes) { |
| 2637 | prev_ts = LLONG_MAX; |
| 2638 | rst_prev_ts = true; |
| 2639 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2640 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2641 | if (m_debug_timestamp) { |
| 2642 | m_timestamp_list.reset_ts_list(); |
| 2643 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2644 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2645 | 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] | 2646 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | |
| 2650 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2651 | FUNCTION |
| 2652 | omx_vdec::SendCommandEvent |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2653 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2654 | DESCRIPTION |
| 2655 | Send the event to decoder pipe. This is needed to generate the callbacks |
| 2656 | in decoder thread context. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2657 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2658 | PARAMETERS |
| 2659 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2660 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2661 | RETURN VALUE |
| 2662 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2663 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2664 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2665 | bool omx_vdec::post_event(unsigned int p1, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2666 | unsigned int p2, |
| 2667 | unsigned int id) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2668 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2669 | bool bRet = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2670 | |
| 2671 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2672 | pthread_mutex_lock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2673 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2674 | if (id == m_fill_output_msg || |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 2675 | id == OMX_COMPONENT_GENERATE_FBD || |
| 2676 | id == OMX_COMPONENT_GENERATE_PORT_RECONFIG) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2677 | m_ftb_q.insert_entry(p1,p2,id); |
| 2678 | } else if (id == OMX_COMPONENT_GENERATE_ETB || |
| 2679 | id == OMX_COMPONENT_GENERATE_EBD || |
| 2680 | id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 2681 | m_etb_q.insert_entry(p1,p2,id); |
| 2682 | } else { |
| 2683 | m_cmd_q.insert_entry(p1,p2,id); |
| 2684 | } |
Shalaj 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 | bRet = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2687 | DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2688 | post_message(this, id); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2689 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2690 | pthread_mutex_unlock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2691 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2692 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType) |
| 2696 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2697 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2698 | if (!profileLevelType) |
| 2699 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2700 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2701 | if (profileLevelType->nPortIndex == 0) { |
| 2702 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 2703 | if (profileLevelType->nProfileIndex == 0) { |
| 2704 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline; |
| 2705 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2706 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2707 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2708 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain; |
| 2709 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2710 | } else if (profileLevelType->nProfileIndex == 2) { |
| 2711 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh; |
| 2712 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2713 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2714 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2715 | profileLevelType->nProfileIndex); |
| 2716 | eRet = OMX_ErrorNoMore; |
| 2717 | } |
| 2718 | } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) { |
| 2719 | if (profileLevelType->nProfileIndex == 0) { |
| 2720 | profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline; |
| 2721 | profileLevelType->eLevel = OMX_VIDEO_H263Level70; |
| 2722 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2723 | 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] | 2724 | eRet = OMX_ErrorNoMore; |
| 2725 | } |
| 2726 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 2727 | if (profileLevelType->nProfileIndex == 0) { |
| 2728 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple; |
| 2729 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2730 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2731 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple; |
| 2732 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2733 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2734 | 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] | 2735 | eRet = OMX_ErrorNoMore; |
| 2736 | } |
| 2737 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 2738 | eRet = OMX_ErrorNoMore; |
| 2739 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 2740 | if (profileLevelType->nProfileIndex == 0) { |
| 2741 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple; |
| 2742 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2743 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2744 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain; |
| 2745 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2746 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2747 | 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] | 2748 | eRet = OMX_ErrorNoMore; |
| 2749 | } |
| 2750 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2751 | 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] | 2752 | eRet = OMX_ErrorNoMore; |
| 2753 | } |
| 2754 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2755 | 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] | 2756 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2757 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2758 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2762 | FUNCTION |
| 2763 | omx_vdec::GetParameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2764 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2765 | DESCRIPTION |
| 2766 | OMX Get Parameter method implementation |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2767 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2768 | PARAMETERS |
| 2769 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2770 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2771 | RETURN VALUE |
| 2772 | Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2773 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2774 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2775 | OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2776 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 2777 | OMX_INOUT OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2778 | { |
| 2779 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2780 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2781 | DEBUG_PRINT_LOW("get_parameter:"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2782 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2783 | DEBUG_PRINT_ERROR("Get Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2784 | return OMX_ErrorInvalidState; |
| 2785 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2786 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2787 | DEBUG_PRINT_LOW("Get Param in Invalid paramData"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2788 | return OMX_ErrorBadParameter; |
| 2789 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2790 | switch ((unsigned long)paramIndex) { |
| 2791 | case OMX_IndexParamPortDefinition: { |
| 2792 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = |
| 2793 | (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2794 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2795 | eRet = update_portdef(portDefn); |
| 2796 | if (eRet == OMX_ErrorNone) |
| 2797 | m_port_def = *portDefn; |
| 2798 | break; |
| 2799 | } |
| 2800 | case OMX_IndexParamVideoInit: { |
| 2801 | OMX_PORT_PARAM_TYPE *portParamType = |
| 2802 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2803 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2804 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2805 | portParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2806 | portParamType->nSize = sizeof(portParamType); |
| 2807 | portParamType->nPorts = 2; |
| 2808 | portParamType->nStartPortNumber = 0; |
| 2809 | break; |
| 2810 | } |
| 2811 | case OMX_IndexParamVideoPortFormat: { |
| 2812 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 2813 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2814 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2815 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2816 | portFmt->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2817 | portFmt->nSize = sizeof(portFmt); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2818 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2819 | if (0 == portFmt->nPortIndex) { |
| 2820 | if (0 == portFmt->nIndex) { |
| 2821 | portFmt->eColorFormat = OMX_COLOR_FormatUnused; |
| 2822 | portFmt->eCompressionFormat = eCompressionFormat; |
| 2823 | } else { |
| 2824 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2825 | " NoMore compression formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2826 | eRet = OMX_ErrorNoMore; |
| 2827 | } |
| 2828 | } else if (1 == portFmt->nPortIndex) { |
| 2829 | portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2830 | |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2831 | // Distinguish non-surface mode from normal playback use-case based on |
| 2832 | // usage hinted via "OMX.google.android.index.useAndroidNativeBuffer2" |
| 2833 | // For non-android, use the default list |
| 2834 | bool useNonSurfaceMode = false; |
| 2835 | #if _ANDROID_ |
| 2836 | useNonSurfaceMode = (m_enable_android_native_buffers == OMX_FALSE); |
| 2837 | #endif |
| 2838 | portFmt->eColorFormat = useNonSurfaceMode ? |
| 2839 | getPreferredColorFormatNonSurfaceMode(portFmt->nIndex) : |
| 2840 | getPreferredColorFormatDefaultMode(portFmt->nIndex); |
| 2841 | |
| 2842 | if (portFmt->eColorFormat == OMX_COLOR_FormatMax ) { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2843 | eRet = OMX_ErrorNoMore; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2844 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2845 | " NoMore Color formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2846 | } |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2847 | DEBUG_PRINT_HIGH("returning color-format: 0x%x", portFmt->eColorFormat); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2848 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2849 | DEBUG_PRINT_ERROR("get_parameter: Bad port index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2850 | (int)portFmt->nPortIndex); |
| 2851 | eRet = OMX_ErrorBadPortIndex; |
| 2852 | } |
| 2853 | break; |
| 2854 | } |
| 2855 | /*Component should support this port definition*/ |
| 2856 | case OMX_IndexParamAudioInit: { |
| 2857 | OMX_PORT_PARAM_TYPE *audioPortParamType = |
| 2858 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2859 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2860 | audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2861 | audioPortParamType->nSize = sizeof(audioPortParamType); |
| 2862 | audioPortParamType->nPorts = 0; |
| 2863 | audioPortParamType->nStartPortNumber = 0; |
| 2864 | break; |
| 2865 | } |
| 2866 | /*Component should support this port definition*/ |
| 2867 | case OMX_IndexParamImageInit: { |
| 2868 | OMX_PORT_PARAM_TYPE *imagePortParamType = |
| 2869 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2870 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2871 | imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2872 | imagePortParamType->nSize = sizeof(imagePortParamType); |
| 2873 | imagePortParamType->nPorts = 0; |
| 2874 | imagePortParamType->nStartPortNumber = 0; |
| 2875 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2876 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2877 | } |
| 2878 | /*Component should support this port definition*/ |
| 2879 | case OMX_IndexParamOtherInit: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2880 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2881 | paramIndex); |
| 2882 | eRet =OMX_ErrorUnsupportedIndex; |
| 2883 | break; |
| 2884 | } |
| 2885 | case OMX_IndexParamStandardComponentRole: { |
| 2886 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 2887 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
| 2888 | comp_role->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2889 | comp_role->nSize = sizeof(*comp_role); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2890 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2891 | DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2892 | paramIndex); |
| 2893 | strlcpy((char*)comp_role->cRole,(const char*)m_cRole, |
| 2894 | OMX_MAX_STRINGNAME_SIZE); |
| 2895 | break; |
| 2896 | } |
| 2897 | /* Added for parameter test */ |
| 2898 | case OMX_IndexParamPriorityMgmt: { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2899 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2900 | OMX_PRIORITYMGMTTYPE *priorityMgmType = |
| 2901 | (OMX_PRIORITYMGMTTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2902 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2903 | priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2904 | priorityMgmType->nSize = sizeof(priorityMgmType); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2905 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2906 | break; |
| 2907 | } |
| 2908 | /* Added for parameter test */ |
| 2909 | case OMX_IndexParamCompBufferSupplier: { |
| 2910 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = |
| 2911 | (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2912 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2913 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2914 | bufferSupplierType->nSize = sizeof(bufferSupplierType); |
| 2915 | bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2916 | if (0 == bufferSupplierType->nPortIndex) |
| 2917 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2918 | else if (1 == bufferSupplierType->nPortIndex) |
| 2919 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2920 | else |
| 2921 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2922 | |
| 2923 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2924 | break; |
| 2925 | } |
| 2926 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2927 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2928 | paramIndex); |
| 2929 | break; |
| 2930 | } |
| 2931 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2932 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2933 | paramIndex); |
| 2934 | break; |
| 2935 | } |
| 2936 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2937 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2938 | paramIndex); |
| 2939 | break; |
| 2940 | } |
| 2941 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2942 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2943 | paramIndex); |
| 2944 | break; |
| 2945 | } |
| 2946 | case OMX_IndexParamVideoProfileLevelQuerySupported: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2947 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2948 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType = |
| 2949 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData; |
| 2950 | eRet = get_supported_profile_level_for_1080p(profileLevelType); |
| 2951 | break; |
| 2952 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2953 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2954 | case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2955 | DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2956 | GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData; |
| 2957 | if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2958 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2959 | if (secure_mode) { |
| 2960 | nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED | |
| 2961 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2962 | } else { |
| 2963 | nativeBuffersUsage->nUsage = |
| 2964 | (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | |
| 2965 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2966 | } |
| 2967 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2968 | DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2969 | eRet = OMX_ErrorBadParameter; |
| 2970 | } |
| 2971 | } |
| 2972 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2973 | #endif |
| 2974 | |
Deva Ramasubramanian | 286a358 | 2014-08-25 18:09:38 -0700 | [diff] [blame] | 2975 | case OMX_QcomIndexParamVideoProcessNotCodedVOP: |
| 2976 | { |
| 2977 | DEBUG_PRINT_LOW("get_parameter: OMX_QcomIndexParamVideoProcessNotCodedVOP"); |
| 2978 | ((QOMX_ENABLETYPE *)paramData)->bEnable = (OMX_BOOL)!ignore_not_coded_vops; |
| 2979 | break; |
| 2980 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2981 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2982 | DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2983 | eRet =OMX_ErrorUnsupportedIndex; |
| 2984 | } |
| 2985 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2988 | 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] | 2989 | drv_ctx.video_resolution.frame_width, |
| 2990 | drv_ctx.video_resolution.frame_height, |
| 2991 | drv_ctx.video_resolution.stride, |
| 2992 | drv_ctx.video_resolution.scan_lines); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2993 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2994 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
| 2998 | OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data) |
| 2999 | { |
| 3000 | DEBUG_PRINT_LOW("Inside use_android_native_buffer"); |
| 3001 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 3002 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data; |
| 3003 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3004 | if ((params == NULL) || |
| 3005 | (params->nativeBuffer == NULL) || |
| 3006 | (params->nativeBuffer->handle == NULL) || |
| 3007 | !m_enable_android_native_buffers) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3008 | return OMX_ErrorBadParameter; |
| 3009 | m_use_android_native_buffers = OMX_TRUE; |
| 3010 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 3011 | private_handle_t *handle = (private_handle_t *)nBuf->handle; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3012 | 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] | 3013 | OMX_U8 *buffer = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3014 | if (!secure_mode) { |
| 3015 | buffer = (OMX_U8*)mmap(0, handle->size, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3016 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3017 | if (buffer == MAP_FAILED) { |
| 3018 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 3019 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3020 | } |
| 3021 | } |
| 3022 | eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer); |
| 3023 | } else { |
| 3024 | eRet = OMX_ErrorBadParameter; |
| 3025 | } |
| 3026 | return eRet; |
| 3027 | } |
| 3028 | #endif |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3029 | |
| 3030 | OMX_ERRORTYPE omx_vdec::enable_smoothstreaming() { |
| 3031 | struct v4l2_control control; |
| 3032 | struct v4l2_format fmt; |
| 3033 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER; |
| 3034 | control.value = 1; |
| 3035 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3036 | if (rc < 0) { |
| 3037 | DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver."); |
| 3038 | return OMX_ErrorHardware; |
| 3039 | } |
| 3040 | m_smoothstreaming_mode = true; |
| 3041 | return OMX_ErrorNone; |
| 3042 | } |
| 3043 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3044 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3045 | FUNCTION |
| 3046 | omx_vdec::Setparameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3047 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3048 | DESCRIPTION |
| 3049 | OMX Set Parameter method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3050 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3051 | PARAMETERS |
| 3052 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3053 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3054 | RETURN VALUE |
| 3055 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3056 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3057 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3058 | OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3059 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 3060 | OMX_IN OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3061 | { |
| 3062 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Praneeth Paladugu | 226667c | 2012-09-12 16:42:30 -0700 | [diff] [blame] | 3063 | int ret=0; |
| 3064 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3065 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3066 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3067 | return OMX_ErrorInvalidState; |
| 3068 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3069 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3070 | DEBUG_PRINT_ERROR("Get Param in Invalid paramData"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3071 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3072 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3073 | if ((m_state != OMX_StateLoaded) && |
| 3074 | BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) && |
| 3075 | (m_out_bEnabled == OMX_TRUE) && |
| 3076 | BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) && |
| 3077 | (m_inp_bEnabled == OMX_TRUE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3078 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3079 | return OMX_ErrorIncorrectStateOperation; |
| 3080 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3081 | switch ((unsigned long)paramIndex) { |
| 3082 | case OMX_IndexParamPortDefinition: { |
| 3083 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn; |
| 3084 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
| 3085 | //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has |
| 3086 | //been called. |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3087 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3088 | (int)portDefn->format.video.nFrameHeight, |
| 3089 | (int)portDefn->format.video.nFrameWidth); |
| 3090 | if (OMX_DirOutput == portDefn->eDir) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3091 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port"); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3092 | bool port_format_changed = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3093 | m_display_id = portDefn->format.video.pNativeWindow; |
| 3094 | unsigned int buffer_size; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3095 | /* update output port resolution with client supplied dimensions |
| 3096 | in case scaling is enabled, else it follows input resolution set |
| 3097 | */ |
| 3098 | if (is_down_scalar_enabled) { |
| 3099 | DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n", |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3100 | portDefn->format.video.nFrameWidth, |
| 3101 | portDefn->format.video.nFrameHeight); |
| 3102 | if (portDefn->format.video.nFrameHeight != 0x0 && |
| 3103 | portDefn->format.video.nFrameWidth != 0x0) { |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3104 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
| 3105 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3106 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3107 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 3108 | if (ret) { |
| 3109 | DEBUG_PRINT_ERROR("Get Resolution failed"); |
| 3110 | eRet = OMX_ErrorHardware; |
| 3111 | break; |
| 3112 | } |
| 3113 | if ((portDefn->format.video.nFrameHeight != (int)fmt.fmt.pix_mp.height) || |
| 3114 | (portDefn->format.video.nFrameWidth != (int)fmt.fmt.pix_mp.width)) { |
| 3115 | port_format_changed = true; |
| 3116 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3117 | update_resolution(portDefn->format.video.nFrameWidth, |
| 3118 | portDefn->format.video.nFrameHeight, |
| 3119 | portDefn->format.video.nFrameWidth, |
| 3120 | portDefn->format.video.nFrameHeight); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3121 | |
| 3122 | /* set crop info */ |
| 3123 | rectangle.nLeft = 0; |
| 3124 | rectangle.nTop = 0; |
| 3125 | rectangle.nWidth = portDefn->format.video.nFrameWidth; |
| 3126 | rectangle.nHeight = portDefn->format.video.nFrameHeight; |
| 3127 | |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3128 | eRet = is_video_session_supported(); |
| 3129 | if (eRet) |
| 3130 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3131 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3132 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3133 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3134 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3135 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3136 | DEBUG_PRINT_LOW("\n fmt.fmt.pix_mp.height = %d , fmt.fmt.pix_mp.width = %d \n",fmt.fmt.pix_mp.height,fmt.fmt.pix_mp.width); |
| 3137 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3138 | if (ret) { |
| 3139 | DEBUG_PRINT_ERROR("\n Set Resolution failed"); |
| 3140 | eRet = OMX_ErrorUnsupportedSetting; |
| 3141 | } else |
| 3142 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3143 | } |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3144 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3145 | if (!client_buffers.get_buffer_req(buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3146 | DEBUG_PRINT_ERROR("Error in getting buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3147 | eRet = OMX_ErrorBadParameter; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3148 | } else if (!port_format_changed) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3149 | if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount && |
| 3150 | portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) { |
| 3151 | drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual; |
| 3152 | drv_ctx.op_buf.buffer_size = portDefn->nBufferSize; |
| 3153 | drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount; |
| 3154 | drv_ctx.extradata_info.size = drv_ctx.extradata_info.count * |
| 3155 | drv_ctx.extradata_info.buffer_size; |
| 3156 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 3157 | if (eRet == OMX_ErrorNone) |
| 3158 | m_port_def = *portDefn; |
| 3159 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3160 | DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3161 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size, |
| 3162 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3163 | eRet = OMX_ErrorBadParameter; |
| 3164 | } |
| 3165 | } |
| 3166 | } else if (OMX_DirInput == portDefn->eDir) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3167 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3168 | bool port_format_changed = false; |
| 3169 | if ((portDefn->format.video.xFramerate >> 16) > 0 && |
| 3170 | (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) { |
| 3171 | // Frame rate only should be set if this is a "known value" or to |
| 3172 | // activate ts prediction logic (arbitrary mode only) sending input |
| 3173 | // timestamps with max value (LLONG_MAX). |
| 3174 | DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu", |
| 3175 | portDefn->format.video.xFramerate >> 16); |
| 3176 | Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator, |
| 3177 | drv_ctx.frame_rate.fps_denominator); |
| 3178 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 3179 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 3180 | drv_ctx.frame_rate.fps_numerator = 30; |
| 3181 | } |
| 3182 | if (drv_ctx.frame_rate.fps_denominator) |
| 3183 | drv_ctx.frame_rate.fps_numerator = (int) |
| 3184 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 3185 | drv_ctx.frame_rate.fps_denominator = 1; |
| 3186 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 3187 | drv_ctx.frame_rate.fps_numerator; |
| 3188 | DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)", |
| 3189 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 3190 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3191 | |
| 3192 | struct v4l2_outputparm oparm; |
| 3193 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 3194 | * per second.*/ |
| 3195 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 3196 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 3197 | |
| 3198 | struct v4l2_streamparm sparm; |
| 3199 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3200 | sparm.parm.output = oparm; |
| 3201 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 3202 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, performance might be affected"); |
| 3203 | eRet = OMX_ErrorHardware; |
| 3204 | break; |
| 3205 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3206 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3207 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3208 | if (drv_ctx.video_resolution.frame_height != |
| 3209 | portDefn->format.video.nFrameHeight || |
| 3210 | drv_ctx.video_resolution.frame_width != |
| 3211 | portDefn->format.video.nFrameWidth) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3212 | DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3213 | portDefn->format.video.nFrameWidth, |
| 3214 | portDefn->format.video.nFrameHeight); |
| 3215 | port_format_changed = true; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3216 | OMX_U32 frameWidth = portDefn->format.video.nFrameWidth; |
| 3217 | OMX_U32 frameHeight = portDefn->format.video.nFrameHeight; |
| 3218 | if (frameHeight != 0x0 && frameWidth != 0x0) { |
| 3219 | if (m_smoothstreaming_mode && |
| 3220 | ((frameWidth * frameHeight) < |
| 3221 | (m_smoothstreaming_width * m_smoothstreaming_height))) { |
| 3222 | frameWidth = m_smoothstreaming_width; |
| 3223 | frameHeight = m_smoothstreaming_height; |
| 3224 | DEBUG_PRINT_LOW("NOTE: Setting resolution %lu x %lu for adaptive-playback/smooth-streaming", |
| 3225 | frameWidth, frameHeight); |
| 3226 | } |
| 3227 | update_resolution(frameWidth, frameHeight, |
| 3228 | frameWidth, frameHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3229 | eRet = is_video_session_supported(); |
| 3230 | if (eRet) |
| 3231 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3232 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3233 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3234 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3235 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3236 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3237 | 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] | 3238 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3239 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3240 | DEBUG_PRINT_ERROR("Set Resolution failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3241 | eRet = OMX_ErrorUnsupportedSetting; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3242 | } else { |
| 3243 | if (!is_down_scalar_enabled) |
| 3244 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3245 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3246 | } |
| 3247 | } |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3248 | if (m_custom_buffersize.input_buffersize |
| 3249 | && (portDefn->nBufferSize > m_custom_buffersize.input_buffersize)) { |
| 3250 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size set by client: %d, trying to set: %d", |
| 3251 | m_custom_buffersize.input_buffersize, portDefn->nBufferSize); |
| 3252 | eRet = OMX_ErrorBadParameter; |
| 3253 | break; |
| 3254 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3255 | if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount |
| 3256 | || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) { |
| 3257 | port_format_changed = true; |
| 3258 | vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf; |
| 3259 | drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual; |
| 3260 | drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) & |
| 3261 | (~(buffer_prop->alignment - 1)); |
| 3262 | eRet = set_buffer_req(buffer_prop); |
| 3263 | } |
| 3264 | if (false == port_format_changed) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3265 | DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3266 | drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size, |
| 3267 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3268 | eRet = OMX_ErrorBadParameter; |
| 3269 | } |
| 3270 | } else if (portDefn->eDir == OMX_DirMax) { |
| 3271 | DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d", |
| 3272 | (int)portDefn->nPortIndex); |
| 3273 | eRet = OMX_ErrorBadPortIndex; |
| 3274 | } |
| 3275 | } |
| 3276 | break; |
| 3277 | case OMX_IndexParamVideoPortFormat: { |
| 3278 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 3279 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
| 3280 | int ret=0; |
| 3281 | struct v4l2_format fmt; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3282 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3283 | portFmt->eColorFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3284 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3285 | if (1 == portFmt->nPortIndex) { |
| 3286 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3287 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3288 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3289 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3290 | enum vdec_output_fromat op_format; |
| 3291 | if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE) |
| 3292 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) || |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 3293 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 3294 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3295 | op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3296 | else |
| 3297 | eRet = OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3299 | if (eRet == OMX_ErrorNone) { |
| 3300 | drv_ctx.output_format = op_format; |
| 3301 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3302 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3303 | DEBUG_PRINT_ERROR("Set output format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3304 | eRet = OMX_ErrorUnsupportedSetting; |
| 3305 | /*TODO: How to handle this case */ |
| 3306 | } else { |
| 3307 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3308 | } |
| 3309 | } |
| 3310 | if (eRet == OMX_ErrorNone) { |
| 3311 | if (!client_buffers.set_color_format(portFmt->eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3312 | DEBUG_PRINT_ERROR("Set color format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3313 | eRet = OMX_ErrorBadParameter; |
| 3314 | } |
| 3315 | } |
| 3316 | } |
| 3317 | } |
| 3318 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3319 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3320 | case OMX_QcomIndexPortDefn: { |
| 3321 | OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt = |
| 3322 | (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3323 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3324 | portFmt->nFramePackingFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3325 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3326 | /* Input port */ |
| 3327 | if (portFmt->nPortIndex == 0) { |
| 3328 | if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) { |
| 3329 | if (secure_mode) { |
| 3330 | arbitrary_bytes = false; |
| 3331 | DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session"); |
| 3332 | eRet = OMX_ErrorUnsupportedSetting; |
| 3333 | } else { |
| 3334 | arbitrary_bytes = true; |
| 3335 | } |
| 3336 | } else if (portFmt->nFramePackingFormat == |
| 3337 | OMX_QCOM_FramePacking_OnlyOneCompleteFrame) { |
| 3338 | arbitrary_bytes = false; |
| 3339 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3340 | DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3341 | portFmt->nFramePackingFormat); |
| 3342 | eRet = OMX_ErrorUnsupportedSetting; |
| 3343 | } |
| 3344 | } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3345 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3346 | if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid && |
| 3347 | portFmt->nMemRegion < OMX_QCOM_MemRegionMax) && |
| 3348 | portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) { |
| 3349 | m_out_mem_region_smi = OMX_TRUE; |
| 3350 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3351 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3352 | m_use_output_pmem = OMX_TRUE; |
| 3353 | } |
| 3354 | } |
| 3355 | } |
| 3356 | } |
| 3357 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3358 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3359 | case OMX_IndexParamStandardComponentRole: { |
| 3360 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 3361 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3362 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3363 | comp_role->cRole); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3364 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3365 | if ((m_state == OMX_StateLoaded)&& |
| 3366 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 3367 | DEBUG_PRINT_LOW("Set Parameter called in valid state"); |
| 3368 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3369 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3370 | return OMX_ErrorIncorrectStateOperation; |
| 3371 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3372 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3373 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3374 | if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3375 | strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 3376 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3377 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3378 | eRet =OMX_ErrorUnsupportedSetting; |
| 3379 | } |
| 3380 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3381 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3382 | strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
| 3383 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3384 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3385 | eRet = OMX_ErrorUnsupportedSetting; |
| 3386 | } |
| 3387 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3388 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3389 | strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
| 3390 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3391 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3392 | eRet =OMX_ErrorUnsupportedSetting; |
| 3393 | } |
| 3394 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3395 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3396 | strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
| 3397 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3398 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3399 | eRet = OMX_ErrorUnsupportedSetting; |
| 3400 | } |
| 3401 | } 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^] | 3402 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311", OMX_MAX_STRINGNAME_SIZE)) || |
| 3403 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4", OMX_MAX_STRINGNAME_SIZE)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3404 | ) { |
| 3405 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) { |
| 3406 | strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
| 3407 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3408 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3409 | eRet =OMX_ErrorUnsupportedSetting; |
| 3410 | } |
| 3411 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 3412 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 3413 | ) { |
| 3414 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) { |
| 3415 | strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 3416 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3417 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3418 | eRet =OMX_ErrorUnsupportedSetting; |
| 3419 | } |
| 3420 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 3421 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) || |
| 3422 | (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) { |
| 3423 | strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 3424 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3425 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3426 | eRet = OMX_ErrorUnsupportedSetting; |
| 3427 | } |
| 3428 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3429 | DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3430 | eRet = OMX_ErrorInvalidComponentName; |
| 3431 | } |
| 3432 | break; |
| 3433 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3434 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3435 | case OMX_IndexParamPriorityMgmt: { |
| 3436 | if (m_state != OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3437 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3438 | return OMX_ErrorIncorrectStateOperation; |
| 3439 | } |
| 3440 | OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3441 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3442 | priorityMgmtype->nGroupID); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3443 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3444 | DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3445 | priorityMgmtype->nGroupPriority); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3446 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3447 | m_priority_mgm.nGroupID = priorityMgmtype->nGroupID; |
| 3448 | m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3449 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3450 | break; |
| 3451 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3452 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3453 | case OMX_IndexParamCompBufferSupplier: { |
| 3454 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3455 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3456 | bufferSupplierType->eBufferSupplier); |
| 3457 | if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1) |
| 3458 | m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3459 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3460 | else |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3461 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3462 | eRet = OMX_ErrorBadPortIndex; |
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 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3465 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3466 | } |
| 3467 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3468 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3469 | paramIndex); |
| 3470 | break; |
| 3471 | } |
| 3472 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3473 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3474 | paramIndex); |
| 3475 | break; |
| 3476 | } |
| 3477 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3478 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3479 | paramIndex); |
| 3480 | break; |
| 3481 | } |
| 3482 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3483 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3484 | paramIndex); |
| 3485 | break; |
| 3486 | } |
| 3487 | case OMX_QcomIndexParamVideoDecoderPictureOrder: { |
| 3488 | QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder = |
| 3489 | (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData; |
| 3490 | struct v4l2_control control; |
| 3491 | int pic_order,rc=0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3492 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3493 | pictureOrder->eOutputPictureOrder); |
| 3494 | if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) { |
| 3495 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 3496 | } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) { |
| 3497 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3498 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3499 | } else |
| 3500 | eRet = OMX_ErrorBadParameter; |
| 3501 | if (eRet == OMX_ErrorNone) { |
| 3502 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3503 | control.value = pic_order; |
| 3504 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3505 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3506 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3507 | eRet = OMX_ErrorUnsupportedSetting; |
| 3508 | } |
| 3509 | } |
| 3510 | break; |
| 3511 | } |
| 3512 | case OMX_QcomIndexParamConcealMBMapExtraData: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3513 | eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false, |
| 3514 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3515 | break; |
| 3516 | case OMX_QcomIndexParamFrameInfoExtraData: |
| 3517 | eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false, |
| 3518 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3519 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3520 | case OMX_QcomIndexParamInterlaceExtraData: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3521 | eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false, |
| 3522 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3523 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3524 | case OMX_QcomIndexParamH264TimeInfo: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3525 | eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false, |
| 3526 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3527 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3528 | case OMX_QcomIndexParamVideoFramePackingExtradata: |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3529 | eRet = enable_extradata(OMX_FRAMEPACK_EXTRADATA, false, |
| 3530 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3531 | break; |
| 3532 | case OMX_QcomIndexParamVideoQPExtraData: |
| 3533 | eRet = enable_extradata(OMX_QP_EXTRADATA, false, |
| 3534 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3535 | break; |
| 3536 | case OMX_QcomIndexParamVideoInputBitsInfoExtraData: |
| 3537 | eRet = enable_extradata(OMX_BITSINFO_EXTRADATA, false, |
| 3538 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3539 | break; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 3540 | case OMX_QcomIndexEnableExtnUserData: |
| 3541 | eRet = enable_extradata(OMX_EXTNUSER_EXTRADATA, false, |
| 3542 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3543 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3544 | case OMX_QcomIndexParamVideoDivx: { |
| 3545 | QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData; |
| 3546 | } |
| 3547 | break; |
| 3548 | case OMX_QcomIndexPlatformPvt: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3549 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3550 | OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData; |
| 3551 | if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
| 3552 | DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type); |
| 3553 | eRet = OMX_ErrorUnsupportedSetting; |
| 3554 | } else { |
| 3555 | m_out_pvt_entry_pmem = OMX_TRUE; |
| 3556 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3557 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3558 | m_use_output_pmem = OMX_TRUE; |
| 3559 | } |
| 3560 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3561 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3562 | } |
| 3563 | break; |
| 3564 | case OMX_QcomIndexParamVideoSyncFrameDecodingMode: { |
| 3565 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode"); |
| 3566 | DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode"); |
| 3567 | struct v4l2_control control; |
| 3568 | int rc; |
| 3569 | drv_ctx.idr_only_decoding = 1; |
| 3570 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3571 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3572 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3573 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3574 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3575 | eRet = OMX_ErrorUnsupportedSetting; |
| 3576 | } else { |
| 3577 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE; |
| 3578 | control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE; |
| 3579 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3580 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3581 | DEBUG_PRINT_ERROR("Sync frame setting failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3582 | eRet = OMX_ErrorUnsupportedSetting; |
| 3583 | } |
| 3584 | /*Setting sync frame decoding on driver might change buffer |
| 3585 | * requirements so update them here*/ |
| 3586 | if (get_buffer_req(&drv_ctx.ip_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3587 | 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] | 3588 | eRet = OMX_ErrorUnsupportedSetting; |
| 3589 | } |
| 3590 | if (get_buffer_req(&drv_ctx.op_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3591 | 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] | 3592 | eRet = OMX_ErrorUnsupportedSetting; |
| 3593 | } |
| 3594 | } |
| 3595 | } |
| 3596 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3597 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3598 | case OMX_QcomIndexParamIndexExtraDataType: { |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3599 | QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData; |
| 3600 | if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) && |
| 3601 | (extradataIndexType->bEnabled == OMX_TRUE) && |
| 3602 | (extradataIndexType->nPortIndex == 1)) { |
| 3603 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming"); |
| 3604 | eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled); |
| 3605 | } |
| 3606 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3607 | break; |
| 3608 | case OMX_QcomIndexParamEnableSmoothStreaming: { |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3609 | #ifndef SMOOTH_STREAMING_DISABLED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3610 | eRet = enable_smoothstreaming(); |
Arun Menon | bc0922f | 2013-06-24 13:02:15 -0700 | [diff] [blame] | 3611 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3612 | eRet = OMX_ErrorUnsupportedSetting; |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3613 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3614 | } |
| 3615 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3616 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3617 | /* Need to allow following two set_parameters even in Idle |
| 3618 | * state. This is ANDROID architecture which is not in sync |
| 3619 | * with openmax standard. */ |
| 3620 | case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: { |
| 3621 | EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData; |
| 3622 | if (enableNativeBuffers) { |
| 3623 | m_enable_android_native_buffers = enableNativeBuffers->enable; |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 3624 | } |
| 3625 | if (m_enable_android_native_buffers) { |
| 3626 | // Use the most-preferred-native-color-format as surface-mode is hinted here |
| 3627 | if(!client_buffers.set_color_format(getPreferredColorFormatDefaultMode(0))) { |
| 3628 | DEBUG_PRINT_ERROR("Failed to set native color format!"); |
| 3629 | eRet = OMX_ErrorUnsupportedSetting; |
| 3630 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | break; |
| 3634 | case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: { |
| 3635 | eRet = use_android_native_buffer(hComp, paramData); |
| 3636 | } |
| 3637 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3638 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3639 | case OMX_QcomIndexParamEnableTimeStampReorder: { |
| 3640 | QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData; |
| 3641 | if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) { |
| 3642 | if (reorder->bEnable == OMX_TRUE) { |
| 3643 | frm_int =0; |
| 3644 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 3645 | } else |
| 3646 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3647 | } else { |
| 3648 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3649 | if (reorder->bEnable == OMX_TRUE) { |
| 3650 | eRet = OMX_ErrorUnsupportedSetting; |
| 3651 | } |
| 3652 | } |
| 3653 | } |
| 3654 | break; |
| 3655 | case OMX_IndexParamVideoProfileLevelCurrent: { |
| 3656 | OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = |
| 3657 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData; |
| 3658 | if (pParam) { |
| 3659 | m_profile_lvl.eProfile = pParam->eProfile; |
| 3660 | m_profile_lvl.eLevel = pParam->eLevel; |
| 3661 | } |
| 3662 | break; |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 3663 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3664 | } |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3665 | case OMX_QcomIndexParamVideoMetaBufferMode: |
| 3666 | { |
| 3667 | StoreMetaDataInBuffersParams *metabuffer = |
| 3668 | (StoreMetaDataInBuffersParams *)paramData; |
| 3669 | if (!metabuffer) { |
| 3670 | DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer); |
| 3671 | eRet = OMX_ErrorBadParameter; |
| 3672 | break; |
| 3673 | } |
| 3674 | if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3675 | //set property dynamic buffer mode to driver. |
| 3676 | struct v4l2_control control; |
| 3677 | struct v4l2_format fmt; |
| 3678 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT; |
| 3679 | if (metabuffer->bStoreMetaData == true) { |
| 3680 | control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC; |
| 3681 | } else { |
| 3682 | control.value = V4L2_MPEG_VIDC_VIDEO_STATIC; |
| 3683 | } |
| 3684 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3685 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3686 | DEBUG_PRINT_HIGH("%s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3687 | (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 3688 | dynamic_buf_mode = metabuffer->bStoreMetaData; |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3689 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3690 | DEBUG_PRINT_ERROR("Failed to %s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3691 | (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic"); |
| 3692 | eRet = OMX_ErrorUnsupportedSetting; |
| 3693 | } |
| 3694 | } else { |
| 3695 | DEBUG_PRINT_ERROR( |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3696 | "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %lu", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3697 | metabuffer->nPortIndex); |
| 3698 | eRet = OMX_ErrorUnsupportedSetting; |
| 3699 | } |
| 3700 | break; |
| 3701 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3702 | case OMX_QcomIndexParamVideoDownScalar: { |
| 3703 | QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData; |
| 3704 | struct v4l2_control control; |
| 3705 | int rc; |
| 3706 | if (pParam) { |
| 3707 | is_down_scalar_enabled = pParam->bEnable; |
| 3708 | if (is_down_scalar_enabled) { |
| 3709 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE; |
| 3710 | control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY; |
| 3711 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n", |
| 3712 | pParam->bEnable); |
| 3713 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3714 | if (rc < 0) { |
| 3715 | DEBUG_PRINT_ERROR("Failed to set down scalar on driver."); |
| 3716 | eRet = OMX_ErrorUnsupportedSetting; |
| 3717 | } |
| 3718 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO; |
| 3719 | control.value = 1; |
| 3720 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3721 | if (rc < 0) { |
| 3722 | DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver."); |
| 3723 | eRet = OMX_ErrorUnsupportedSetting; |
| 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | break; |
| 3728 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3729 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
| 3730 | case OMX_QcomIndexParamVideoAdaptivePlaybackMode: |
| 3731 | { |
| 3732 | DEBUG_PRINT_LOW("set_parameter: OMX_GoogleAndroidIndexPrepareForAdaptivePlayback"); |
| 3733 | PrepareForAdaptivePlaybackParams* pParams = |
| 3734 | (PrepareForAdaptivePlaybackParams *) paramData; |
| 3735 | if (pParams->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3736 | if (!pParams->bEnable) { |
| 3737 | return OMX_ErrorNone; |
| 3738 | } |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3739 | if (pParams->nMaxFrameWidth > maxSmoothStreamingWidth |
| 3740 | || pParams->nMaxFrameHeight > maxSmoothStreamingHeight) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3741 | DEBUG_PRINT_ERROR( |
| 3742 | "Adaptive playback request exceeds max supported resolution : [%lu x %lu] vs [%lu x %lu]", |
| 3743 | pParams->nMaxFrameWidth, pParams->nMaxFrameHeight, |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3744 | maxSmoothStreamingWidth, maxSmoothStreamingHeight); |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3745 | eRet = OMX_ErrorBadParameter; |
| 3746 | } else { |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 3747 | eRet = enable_adaptive_playback(pParams->nMaxFrameWidth, pParams->nMaxFrameHeight); |
| 3748 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3749 | } else { |
| 3750 | DEBUG_PRINT_ERROR( |
| 3751 | "Prepare for adaptive playback supported only on output port"); |
| 3752 | eRet = OMX_ErrorBadParameter; |
| 3753 | } |
| 3754 | break; |
| 3755 | } |
| 3756 | |
| 3757 | #endif |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3758 | case OMX_QcomIndexParamVideoCustomBufferSize: |
| 3759 | { |
| 3760 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoCustomBufferSize"); |
| 3761 | QOMX_VIDEO_CUSTOM_BUFFERSIZE* pParam = (QOMX_VIDEO_CUSTOM_BUFFERSIZE*)paramData; |
| 3762 | if (pParam->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 3763 | struct v4l2_control control; |
| 3764 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT; |
| 3765 | control.value = pParam->nBufferSize; |
| 3766 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 3767 | DEBUG_PRINT_ERROR("Failed to set input buffer size"); |
| 3768 | eRet = OMX_ErrorUnsupportedSetting; |
| 3769 | } else { |
| 3770 | eRet = get_buffer_req(&drv_ctx.ip_buf); |
| 3771 | if (eRet == OMX_ErrorNone) { |
| 3772 | m_custom_buffersize.input_buffersize = drv_ctx.ip_buf.buffer_size; |
| 3773 | DEBUG_PRINT_HIGH("Successfully set custom input buffer size = %d", |
| 3774 | m_custom_buffersize.input_buffersize); |
| 3775 | } else { |
| 3776 | DEBUG_PRINT_ERROR("Failed to get buffer requirement"); |
| 3777 | } |
| 3778 | } |
| 3779 | } else { |
| 3780 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size in not supported on output port"); |
| 3781 | eRet = OMX_ErrorBadParameter; |
| 3782 | } |
| 3783 | break; |
| 3784 | } |
Deva Ramasubramanian | 286a358 | 2014-08-25 18:09:38 -0700 | [diff] [blame] | 3785 | case OMX_QcomIndexParamVideoProcessNotCodedVOP: |
| 3786 | { |
| 3787 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoProcessNotCodedVOP"); |
| 3788 | ignore_not_coded_vops = !((QOMX_ENABLETYPE *)paramData)->bEnable; |
| 3789 | break; |
| 3790 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3791 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3792 | DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3793 | eRet = OMX_ErrorUnsupportedIndex; |
| 3794 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3795 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 3796 | if (eRet != OMX_ErrorNone) |
| 3797 | 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] | 3798 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3802 | FUNCTION |
| 3803 | omx_vdec::GetConfig |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3804 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3805 | DESCRIPTION |
| 3806 | OMX Get Config Method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3807 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3808 | PARAMETERS |
| 3809 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3810 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3811 | RETURN VALUE |
| 3812 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3813 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3814 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3815 | OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3816 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3817 | OMX_INOUT OMX_PTR configData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3818 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3819 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3820 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3821 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3822 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3823 | return OMX_ErrorInvalidState; |
| 3824 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3825 | |
| 3826 | switch ((unsigned long)configIndex) { |
| 3827 | case OMX_QcomIndexConfigInterlaced: { |
| 3828 | OMX_QCOM_CONFIG_INTERLACETYPE *configFmt = |
| 3829 | (OMX_QCOM_CONFIG_INTERLACETYPE *) configData; |
| 3830 | if (configFmt->nPortIndex == 1) { |
| 3831 | if (configFmt->nIndex == 0) { |
| 3832 | configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 3833 | } else if (configFmt->nIndex == 1) { |
| 3834 | configFmt->eInterlaceType = |
| 3835 | OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 3836 | } else if (configFmt->nIndex == 2) { |
| 3837 | configFmt->eInterlaceType = |
| 3838 | OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 3839 | } else { |
| 3840 | DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3841 | " NoMore Interlaced formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3842 | eRet = OMX_ErrorNoMore; |
| 3843 | } |
| 3844 | |
| 3845 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3846 | 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] | 3847 | (int)configFmt->nPortIndex); |
| 3848 | eRet = OMX_ErrorBadPortIndex; |
| 3849 | } |
| 3850 | break; |
| 3851 | } |
| 3852 | case OMX_QcomIndexQueryNumberOfVideoDecInstance: { |
| 3853 | QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances = |
| 3854 | (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData; |
| 3855 | decoderinstances->nNumOfInstances = 16; |
| 3856 | /*TODO: How to handle this case */ |
| 3857 | break; |
| 3858 | } |
| 3859 | case OMX_QcomIndexConfigVideoFramePackingArrangement: { |
| 3860 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
| 3861 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt = |
| 3862 | (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3863 | memcpy(configFmt, &m_frame_pack_arrangement, |
| 3864 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3865 | } else { |
| 3866 | DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs"); |
| 3867 | } |
| 3868 | break; |
| 3869 | } |
| 3870 | case OMX_IndexConfigCommonOutputCrop: { |
| 3871 | OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData; |
| 3872 | memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE)); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 3873 | DEBUG_PRINT_HIGH("get_config: crop info: L: %u, T: %u, R: %u, B: %u", |
| 3874 | rectangle.nLeft, rectangle.nTop, |
| 3875 | rectangle.nWidth, rectangle.nHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3876 | break; |
| 3877 | } |
| 3878 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3879 | DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3880 | eRet = OMX_ErrorBadParameter; |
| 3881 | } |
| 3882 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3883 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3884 | |
| 3885 | return eRet; |
| 3886 | } |
| 3887 | |
| 3888 | /* ====================================================================== |
| 3889 | FUNCTION |
| 3890 | omx_vdec::SetConfig |
| 3891 | |
| 3892 | DESCRIPTION |
| 3893 | OMX Set Config method implementation |
| 3894 | |
| 3895 | PARAMETERS |
| 3896 | <TBD>. |
| 3897 | |
| 3898 | RETURN VALUE |
| 3899 | OMX Error None if successful. |
| 3900 | ========================================================================== */ |
| 3901 | OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp, |
| 3902 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3903 | OMX_IN OMX_PTR configData) |
| 3904 | { |
| 3905 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3906 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3907 | return OMX_ErrorInvalidState; |
| 3908 | } |
| 3909 | |
| 3910 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 3911 | OMX_VIDEO_CONFIG_NALSIZE *pNal; |
| 3912 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3913 | DEBUG_PRINT_LOW("Set Config Called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3914 | |
| 3915 | if (configIndex == (OMX_INDEXTYPE)OMX_IndexVendorVideoExtraData) { |
| 3916 | OMX_VENDOR_EXTRADATATYPE *config = (OMX_VENDOR_EXTRADATATYPE *) configData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3917 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3918 | if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3919 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData AVC"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3920 | OMX_U32 extra_size; |
| 3921 | // Parsing done here for the AVC atom is definitely not generic |
| 3922 | // Currently this piece of code is working, but certainly |
| 3923 | // not tested with all .mp4 files. |
| 3924 | // Incase of failure, we might need to revisit this |
| 3925 | // for a generic piece of code. |
| 3926 | |
| 3927 | // Retrieve size of NAL length field |
| 3928 | // byte #4 contains the size of NAL lenght field |
| 3929 | nal_length = (config->pData[4] & 0x03) + 1; |
| 3930 | |
| 3931 | extra_size = 0; |
| 3932 | if (nal_length > 2) { |
| 3933 | /* Presently we assume that only one SPS and one PPS in AvC1 Atom */ |
| 3934 | extra_size = (nal_length - 2) * 2; |
| 3935 | } |
| 3936 | |
| 3937 | // SPS starts from byte #6 |
| 3938 | OMX_U8 *pSrcBuf = (OMX_U8 *) (&config->pData[6]); |
| 3939 | OMX_U8 *pDestBuf; |
| 3940 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3941 | |
| 3942 | // minus 6 --> SPS starts from byte #6 |
| 3943 | // minus 1 --> picture param set byte to be ignored from avcatom |
| 3944 | m_vendor_config.nDataSize = config->nDataSize - 6 - 1 + extra_size; |
| 3945 | m_vendor_config.pData = (OMX_U8 *) malloc(m_vendor_config.nDataSize); |
| 3946 | OMX_U32 len; |
| 3947 | OMX_U8 index = 0; |
| 3948 | // case where SPS+PPS is sent as part of set_config |
| 3949 | pDestBuf = m_vendor_config.pData; |
| 3950 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3951 | DEBUG_PRINT_LOW("Rxd SPS+PPS nPortIndex[%lu] len[%lu] data[%p]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3952 | m_vendor_config.nPortIndex, |
| 3953 | m_vendor_config.nDataSize, |
| 3954 | m_vendor_config.pData); |
| 3955 | while (index < 2) { |
| 3956 | uint8 *psize; |
| 3957 | len = *pSrcBuf; |
| 3958 | len = len << 8; |
| 3959 | len |= *(pSrcBuf + 1); |
| 3960 | psize = (uint8 *) & len; |
| 3961 | memcpy(pDestBuf + nal_length, pSrcBuf + 2,len); |
| 3962 | for (unsigned int i = 0; i < nal_length; i++) { |
| 3963 | pDestBuf[i] = psize[nal_length - 1 - i]; |
| 3964 | } |
| 3965 | //memcpy(pDestBuf,pSrcBuf,(len+2)); |
| 3966 | pDestBuf += len + nal_length; |
| 3967 | pSrcBuf += len + 2; |
| 3968 | index++; |
| 3969 | pSrcBuf++; // skip picture param set |
| 3970 | len = 0; |
| 3971 | } |
| 3972 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4") || |
| 3973 | !strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2")) { |
| 3974 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3975 | m_vendor_config.nDataSize = config->nDataSize; |
| 3976 | m_vendor_config.pData = (OMX_U8 *) malloc((config->nDataSize)); |
| 3977 | memcpy(m_vendor_config.pData, config->pData,config->nDataSize); |
| 3978 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1")) { |
| 3979 | if (m_vendor_config.pData) { |
| 3980 | free(m_vendor_config.pData); |
| 3981 | m_vendor_config.pData = NULL; |
| 3982 | m_vendor_config.nDataSize = 0; |
| 3983 | } |
| 3984 | |
| 3985 | if (((*((OMX_U32 *) config->pData)) & |
| 3986 | VC1_SP_MP_START_CODE_MASK) == |
| 3987 | VC1_SP_MP_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3988 | DEBUG_PRINT_LOW("set_config - VC1 simple/main profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3989 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3990 | m_vendor_config.nDataSize = config->nDataSize; |
| 3991 | m_vendor_config.pData = |
| 3992 | (OMX_U8 *) malloc(config->nDataSize); |
| 3993 | memcpy(m_vendor_config.pData, config->pData, |
| 3994 | config->nDataSize); |
| 3995 | m_vc1_profile = VC1_SP_MP_RCV; |
| 3996 | } else if (*((OMX_U32 *) config->pData) == VC1_AP_SEQ_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3997 | DEBUG_PRINT_LOW("set_config - VC1 Advance profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3998 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 3999 | m_vendor_config.nDataSize = config->nDataSize; |
| 4000 | m_vendor_config.pData = |
| 4001 | (OMX_U8 *) malloc((config->nDataSize)); |
| 4002 | memcpy(m_vendor_config.pData, config->pData, |
| 4003 | config->nDataSize); |
| 4004 | m_vc1_profile = VC1_AP; |
| 4005 | } else if ((config->nDataSize == VC1_STRUCT_C_LEN)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4006 | DEBUG_PRINT_LOW("set_config - VC1 Simple/Main profile struct C only"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4007 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4008 | m_vendor_config.nDataSize = config->nDataSize; |
| 4009 | m_vendor_config.pData = (OMX_U8*)malloc(config->nDataSize); |
| 4010 | memcpy(m_vendor_config.pData,config->pData,config->nDataSize); |
| 4011 | m_vc1_profile = VC1_SP_MP_RCV; |
| 4012 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4013 | DEBUG_PRINT_LOW("set_config - Error: Unknown VC1 profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4014 | } |
| 4015 | } |
| 4016 | return ret; |
| 4017 | } else if (configIndex == OMX_IndexConfigVideoNalSize) { |
| 4018 | struct v4l2_control temp; |
| 4019 | temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT; |
| 4020 | |
| 4021 | pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData); |
| 4022 | switch (pNal->nNaluBytes) { |
| 4023 | case 0: |
| 4024 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES; |
| 4025 | break; |
| 4026 | case 2: |
| 4027 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH; |
| 4028 | break; |
| 4029 | case 4: |
| 4030 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH; |
| 4031 | break; |
| 4032 | default: |
| 4033 | return OMX_ErrorUnsupportedSetting; |
| 4034 | } |
| 4035 | |
| 4036 | if (!arbitrary_bytes) { |
| 4037 | /* In arbitrary bytes mode, the assembler strips out nal size and replaces |
| 4038 | * with start code, so only need to notify driver in frame by frame mode */ |
| 4039 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) { |
| 4040 | DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT"); |
| 4041 | return OMX_ErrorHardware; |
| 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | nal_length = pNal->nNaluBytes; |
| 4046 | m_frame_parser.init_nal_length(nal_length); |
| 4047 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4048 | DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4049 | return ret; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4050 | } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4051 | OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4052 | DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4053 | |
| 4054 | if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 4055 | if (config->bEnabled) { |
| 4056 | if ((config->nFps >> 16) > 0) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4057 | DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4058 | config->nFps >> 16); |
| 4059 | Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator, |
| 4060 | drv_ctx.frame_rate.fps_denominator); |
| 4061 | |
| 4062 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 4063 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 4064 | drv_ctx.frame_rate.fps_numerator = 30; |
| 4065 | } |
| 4066 | |
| 4067 | if (drv_ctx.frame_rate.fps_denominator) { |
| 4068 | drv_ctx.frame_rate.fps_numerator = (int) |
| 4069 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 4070 | } |
| 4071 | |
| 4072 | drv_ctx.frame_rate.fps_denominator = 1; |
| 4073 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 4074 | drv_ctx.frame_rate.fps_numerator; |
| 4075 | |
| 4076 | struct v4l2_outputparm oparm; |
| 4077 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 4078 | * per second.*/ |
| 4079 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 4080 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 4081 | |
| 4082 | struct v4l2_streamparm sparm; |
| 4083 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 4084 | sparm.parm.output = oparm; |
| 4085 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 4086 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 4087 | performance might be affected"); |
| 4088 | ret = OMX_ErrorHardware; |
| 4089 | } |
| 4090 | client_set_fps = true; |
| 4091 | } else { |
| 4092 | DEBUG_PRINT_ERROR("Frame rate not supported."); |
| 4093 | ret = OMX_ErrorUnsupportedSetting; |
| 4094 | } |
| 4095 | } else { |
| 4096 | DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate"); |
| 4097 | client_set_fps = false; |
| 4098 | } |
| 4099 | } else { |
| 4100 | DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d", |
| 4101 | (int)config->nPortIndex); |
| 4102 | ret = OMX_ErrorBadPortIndex; |
| 4103 | } |
| 4104 | |
| 4105 | return ret; |
| 4106 | } |
| 4107 | |
| 4108 | return OMX_ErrorNotImplemented; |
| 4109 | } |
| 4110 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4111 | #define extn_equals(param, extn) (!strncmp(param, extn, strlen(extn))) |
| 4112 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4113 | /* ====================================================================== |
| 4114 | FUNCTION |
| 4115 | omx_vdec::GetExtensionIndex |
| 4116 | |
| 4117 | DESCRIPTION |
| 4118 | OMX GetExtensionIndex method implementaion. <TBD> |
| 4119 | |
| 4120 | PARAMETERS |
| 4121 | <TBD>. |
| 4122 | |
| 4123 | RETURN VALUE |
| 4124 | OMX Error None if everything successful. |
| 4125 | |
| 4126 | ========================================================================== */ |
| 4127 | OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp, |
| 4128 | OMX_IN OMX_STRING paramName, |
| 4129 | OMX_OUT OMX_INDEXTYPE* indexType) |
| 4130 | { |
| 4131 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4132 | DEBUG_PRINT_ERROR("Get Extension Index in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4133 | return OMX_ErrorInvalidState; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4134 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode")) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4135 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4136 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.IndexExtraData")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4137 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4138 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_FRAMEPACKING_EXTRADATA)) { |
| 4139 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoFramePackingExtradata; |
| 4140 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_CONFIG_VIDEO_FRAMEPACKING_INFO)) { |
| 4141 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoFramePackingArrangement; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 4142 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_QP_EXTRADATA)) { |
| 4143 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPExtraData; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 4144 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_INPUTBITSINFO_EXTRADATA)) { |
| 4145 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoInputBitsInfoExtraData; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 4146 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_EXTNUSER_EXTRADATA)) { |
| 4147 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableExtnUserData; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4148 | } |
| 4149 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4150 | else if (extn_equals(paramName, "OMX.google.android.index.enableAndroidNativeBuffers")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4151 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4152 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer2")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4153 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4154 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4155 | DEBUG_PRINT_ERROR("Extension: %s is supported", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4156 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4157 | } else if (extn_equals(paramName, "OMX.google.android.index.getAndroidNativeBufferUsage")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4158 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage; |
| 4159 | } |
| 4160 | #endif |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4161 | else if (extn_equals(paramName, "OMX.google.android.index.storeMetaDataInBuffers")) { |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 4162 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode; |
| 4163 | } |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 4164 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 4165 | else if (extn_equals(paramName, "OMX.google.android.index.prepareForAdaptivePlayback")) { |
| 4166 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoAdaptivePlaybackMode; |
| 4167 | } |
| 4168 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4169 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4170 | DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4171 | return OMX_ErrorNotImplemented; |
| 4172 | } |
| 4173 | return OMX_ErrorNone; |
| 4174 | } |
| 4175 | |
| 4176 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4177 | FUNCTION |
| 4178 | omx_vdec::GetState |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4179 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4180 | DESCRIPTION |
| 4181 | Returns the state information back to the caller.<TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4182 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4183 | PARAMETERS |
| 4184 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4185 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4186 | RETURN VALUE |
| 4187 | Error None if everything is successful. |
| 4188 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4189 | OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4190 | OMX_OUT OMX_STATETYPE* state) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4191 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4192 | *state = m_state; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4193 | DEBUG_PRINT_LOW("get_state: Returning the state %d",*state); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4194 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4198 | FUNCTION |
| 4199 | omx_vdec::ComponentTunnelRequest |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4200 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4201 | DESCRIPTION |
| 4202 | OMX Component Tunnel Request method implementation. <TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4203 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4204 | PARAMETERS |
| 4205 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4206 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4207 | RETURN VALUE |
| 4208 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4209 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4210 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4211 | OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4212 | OMX_IN OMX_U32 port, |
| 4213 | OMX_IN OMX_HANDLETYPE peerComponent, |
| 4214 | OMX_IN OMX_U32 peerPort, |
| 4215 | OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4216 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4217 | DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4218 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4222 | FUNCTION |
| 4223 | omx_vdec::UseOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4224 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4225 | DESCRIPTION |
| 4226 | Helper function for Use buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4227 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4228 | PARAMETERS |
| 4229 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4230 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4231 | RETURN VALUE |
| 4232 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4233 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4234 | ========================================================================== */ |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4235 | OMX_ERRORTYPE omx_vdec::allocate_extradata() |
| 4236 | { |
| 4237 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4238 | if (drv_ctx.extradata_info.buffer_size) { |
| 4239 | if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) { |
| 4240 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4241 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4242 | free_ion_memory(&drv_ctx.extradata_info.ion); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4243 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4244 | } |
| 4245 | drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095); |
| 4246 | drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory( |
| 4247 | drv_ctx.extradata_info.size, 4096, |
| 4248 | &drv_ctx.extradata_info.ion.ion_alloc_data, |
| 4249 | &drv_ctx.extradata_info.ion.fd_ion_data, 0); |
| 4250 | if (drv_ctx.extradata_info.ion.ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4251 | DEBUG_PRINT_ERROR("Failed to alloc extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4252 | return OMX_ErrorInsufficientResources; |
| 4253 | } |
| 4254 | drv_ctx.extradata_info.uaddr = (char *)mmap(NULL, |
| 4255 | drv_ctx.extradata_info.size, |
| 4256 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4257 | drv_ctx.extradata_info.ion.fd_ion_data.fd , 0); |
| 4258 | if (drv_ctx.extradata_info.uaddr == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4259 | DEBUG_PRINT_ERROR("Failed to map extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4260 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4261 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4262 | return OMX_ErrorInsufficientResources; |
| 4263 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4264 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4265 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4266 | if (!m_other_extradata) { |
| 4267 | m_other_extradata = (OMX_OTHER_EXTRADATATYPE *)malloc(drv_ctx.extradata_info.buffer_size); |
| 4268 | if (!m_other_extradata) { |
| 4269 | DEBUG_PRINT_ERROR("Failed to alloc memory\n"); |
| 4270 | return OMX_ErrorInsufficientResources; |
| 4271 | } |
| 4272 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4273 | return OMX_ErrorNone; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4274 | } |
| 4275 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4276 | void omx_vdec::free_extradata() |
| 4277 | { |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4278 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4279 | if (drv_ctx.extradata_info.uaddr) { |
| 4280 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4281 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4282 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4283 | } |
| 4284 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4285 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4286 | if (m_other_extradata) { |
| 4287 | free(m_other_extradata); |
| 4288 | m_other_extradata = NULL; |
| 4289 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4292 | OMX_ERRORTYPE omx_vdec::use_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4293 | OMX_IN OMX_HANDLETYPE hComp, |
| 4294 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4295 | OMX_IN OMX_U32 port, |
| 4296 | OMX_IN OMX_PTR appData, |
| 4297 | OMX_IN OMX_U32 bytes, |
| 4298 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4299 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4300 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4301 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 4302 | unsigned i= 0; // Temporary counter |
| 4303 | struct vdec_setbuffer_cmd setbuffers; |
| 4304 | OMX_PTR privateAppData = NULL; |
| 4305 | private_handle_t *handle = NULL; |
| 4306 | OMX_U8 *buff = buffer; |
| 4307 | struct v4l2_buffer buf; |
| 4308 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 4309 | int extra_idx = 0; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4310 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4311 | if (!m_out_mem_ptr) { |
| 4312 | DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers"); |
| 4313 | eRet = allocate_output_headers(); |
| 4314 | if (eRet == OMX_ErrorNone) |
| 4315 | eRet = allocate_extradata(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4316 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4317 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4318 | if (eRet == OMX_ErrorNone) { |
| 4319 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 4320 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
| 4321 | break; |
| 4322 | } |
| 4323 | } |
| 4324 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4325 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4326 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4327 | 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] | 4328 | eRet = OMX_ErrorInsufficientResources; |
| 4329 | } |
| 4330 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 4331 | if (dynamic_buf_mode) { |
| 4332 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4333 | (*bufferHdr)->pBuffer = NULL; |
| 4334 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4335 | enum v4l2_buf_type buf_type; |
| 4336 | int rr = 0; |
| 4337 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4338 | if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4339 | DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr); |
| 4340 | return OMX_ErrorInsufficientResources; |
| 4341 | } else { |
| 4342 | streaming[CAPTURE_PORT] = true; |
| 4343 | DEBUG_PRINT_LOW("STREAMON Successful"); |
| 4344 | } |
| 4345 | } |
| 4346 | BITMASK_SET(&m_out_bm_count,i); |
| 4347 | (*bufferHdr)->pAppPrivate = appData; |
| 4348 | (*bufferHdr)->pBuffer = buffer; |
| 4349 | (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 4350 | return eRet; |
| 4351 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4352 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4353 | #if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4354 | if (m_enable_android_native_buffers) { |
| 4355 | if (m_use_android_native_buffers) { |
| 4356 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData; |
| 4357 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 4358 | handle = (private_handle_t *)nBuf->handle; |
| 4359 | privateAppData = params->pAppPrivate; |
| 4360 | } else { |
| 4361 | handle = (private_handle_t *)buff; |
| 4362 | privateAppData = appData; |
| 4363 | } |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4364 | if (!handle) { |
| 4365 | DEBUG_PRINT_ERROR("handle is invalid"); |
| 4366 | return OMX_ErrorBadParameter; |
| 4367 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4368 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4369 | if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) { |
| 4370 | DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback," |
| 4371 | " expected %u, got %lu", |
| 4372 | drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size); |
| 4373 | return OMX_ErrorBadParameter; |
| 4374 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4375 | |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 4376 | drv_ctx.op_buf.buffer_size = handle->size; |
| 4377 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4378 | if (!m_use_android_native_buffers) { |
| 4379 | if (!secure_mode) { |
| 4380 | buff = (OMX_U8*)mmap(0, handle->size, |
| 4381 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
| 4382 | if (buff == MAP_FAILED) { |
| 4383 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 4384 | return OMX_ErrorInsufficientResources; |
| 4385 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4386 | } |
| 4387 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4388 | #if defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4389 | native_buffer[i].nativehandle = handle; |
| 4390 | native_buffer[i].privatehandle = handle; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4391 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4392 | if (!handle) { |
| 4393 | DEBUG_PRINT_ERROR("Native Buffer handle is NULL"); |
| 4394 | return OMX_ErrorBadParameter; |
| 4395 | } |
| 4396 | drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd; |
| 4397 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4398 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4399 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4400 | drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size; |
| 4401 | } else |
| 4402 | #endif |
| 4403 | |
| 4404 | if (!ouput_egl_buffers && !m_use_output_pmem) { |
| 4405 | #ifdef USE_ION |
| 4406 | drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 4407 | drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 4408 | &drv_ctx.op_buf_ion_info[i].ion_alloc_data, |
| 4409 | &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4410 | if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4411 | 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] | 4412 | return OMX_ErrorInsufficientResources; |
| 4413 | } |
| 4414 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4415 | drv_ctx.op_buf_ion_info[i].fd_ion_data.fd; |
| 4416 | #else |
| 4417 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4418 | open (MEM_DEVICE,O_RDWR); |
| 4419 | |
| 4420 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4421 | 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] | 4422 | return OMX_ErrorInsufficientResources; |
| 4423 | } |
| 4424 | |
| 4425 | /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */ |
| 4426 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) { |
| 4427 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4428 | open (MEM_DEVICE,O_RDWR); |
| 4429 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4430 | 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] | 4431 | return OMX_ErrorInsufficientResources; |
| 4432 | } |
| 4433 | } |
| 4434 | |
| 4435 | if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd, |
| 4436 | drv_ctx.op_buf.buffer_size, |
| 4437 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4438 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4439 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4440 | return OMX_ErrorInsufficientResources; |
| 4441 | } |
| 4442 | #endif |
| 4443 | if (!secure_mode) { |
| 4444 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 4445 | (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size, |
| 4446 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4447 | drv_ctx.ptr_outputbuffer[i].pmem_fd,0); |
| 4448 | if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) { |
| 4449 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4450 | #ifdef USE_ION |
| 4451 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
| 4452 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4453 | DEBUG_PRINT_ERROR("Unable to mmap output buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4454 | return OMX_ErrorInsufficientResources; |
| 4455 | } |
| 4456 | } |
| 4457 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4458 | privateAppData = appData; |
| 4459 | } else { |
| 4460 | |
| 4461 | DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem); |
| 4462 | if (!appData || !bytes ) { |
| 4463 | if (!secure_mode && !buffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4464 | DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4465 | return OMX_ErrorBadParameter; |
| 4466 | } |
| 4467 | } |
| 4468 | |
| 4469 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list; |
| 4470 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info; |
| 4471 | pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData; |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4472 | if (!pmem_list || !pmem_list->entryList || !pmem_list->entryList->entry || |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4473 | !pmem_list->nEntries || |
| 4474 | pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4475 | DEBUG_PRINT_ERROR("Pmem info not valid in use buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4476 | return OMX_ErrorBadParameter; |
| 4477 | } |
| 4478 | pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 4479 | pmem_list->entryList->entry; |
| 4480 | DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx", |
| 4481 | pmem_info->pmem_fd); |
| 4482 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd; |
| 4483 | drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset; |
| 4484 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4485 | drv_ctx.ptr_outputbuffer[i].mmaped_size = |
| 4486 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4487 | privateAppData = appData; |
| 4488 | } |
| 4489 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 4490 | m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4491 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 4492 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 4493 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4494 | |
| 4495 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4496 | if (secure_mode) |
| 4497 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 4498 | //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4499 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i], |
| 4500 | sizeof (vdec_bufferpayload)); |
| 4501 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4502 | 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] | 4503 | drv_ctx.ptr_outputbuffer[i].bufferaddr, |
| 4504 | drv_ctx.ptr_outputbuffer[i].pmem_fd ); |
| 4505 | |
| 4506 | buf.index = i; |
| 4507 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4508 | buf.memory = V4L2_MEMORY_USERPTR; |
| 4509 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 4510 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 4511 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
| 4512 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
| 4513 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 4514 | plane[0].data_offset = 0; |
| 4515 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 4516 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 4517 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 4518 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
| 4519 | #ifdef USE_ION |
| 4520 | plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd; |
| 4521 | #endif |
| 4522 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 4523 | plane[extra_idx].data_offset = 0; |
| 4524 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4525 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4526 | return OMX_ErrorBadParameter; |
| 4527 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4528 | buf.m.planes = plane; |
| 4529 | buf.length = drv_ctx.num_planes; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4530 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4531 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4532 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4533 | /*TODO: How to handle this case */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4534 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4537 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4538 | enum v4l2_buf_type buf_type; |
| 4539 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4540 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4541 | return OMX_ErrorInsufficientResources; |
| 4542 | } else { |
| 4543 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4544 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4545 | } |
| 4546 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4547 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4548 | (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size; |
| 4549 | if (m_enable_android_native_buffers) { |
| 4550 | DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle); |
| 4551 | (*bufferHdr)->pBuffer = (OMX_U8 *)handle; |
| 4552 | } else { |
| 4553 | (*bufferHdr)->pBuffer = buff; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4554 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4555 | (*bufferHdr)->pAppPrivate = privateAppData; |
| 4556 | BITMASK_SET(&m_out_bm_count,i); |
| 4557 | } |
| 4558 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4562 | FUNCTION |
| 4563 | omx_vdec::use_input_heap_buffers |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4564 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4565 | DESCRIPTION |
| 4566 | OMX Use Buffer Heap allocation method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4567 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4568 | PARAMETERS |
| 4569 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4570 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4571 | RETURN VALUE |
| 4572 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4573 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4574 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4575 | OMX_ERRORTYPE omx_vdec::use_input_heap_buffers( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4576 | OMX_IN OMX_HANDLETYPE hComp, |
| 4577 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4578 | OMX_IN OMX_U32 port, |
| 4579 | OMX_IN OMX_PTR appData, |
| 4580 | OMX_IN OMX_U32 bytes, |
| 4581 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4582 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4583 | DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4584 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4585 | if (!m_inp_heap_ptr) |
| 4586 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) |
| 4587 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4588 | drv_ctx.ip_buf.actualcount); |
| 4589 | if (!m_phdr_pmem_ptr) |
| 4590 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) |
| 4591 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4592 | drv_ctx.ip_buf.actualcount); |
| 4593 | if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) { |
| 4594 | DEBUG_PRINT_ERROR("Insufficent memory"); |
| 4595 | eRet = OMX_ErrorInsufficientResources; |
| 4596 | } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) { |
| 4597 | input_use_buffer = true; |
| 4598 | memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE)); |
| 4599 | m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer; |
| 4600 | m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes; |
| 4601 | m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData; |
| 4602 | m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput; |
| 4603 | m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax; |
| 4604 | *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt]; |
| 4605 | eRet = allocate_input_buffer(hComp, &m_phdr_pmem_ptr[m_in_alloc_cnt], port, appData, bytes); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4606 | 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] | 4607 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt], |
| 4608 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4609 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4610 | return OMX_ErrorInsufficientResources; |
| 4611 | } |
| 4612 | m_in_alloc_cnt++; |
| 4613 | } else { |
| 4614 | DEBUG_PRINT_ERROR("All i/p buffers have been set!"); |
| 4615 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4616 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4617 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4621 | FUNCTION |
| 4622 | omx_vdec::UseBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4623 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4624 | DESCRIPTION |
| 4625 | OMX Use Buffer method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4626 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4627 | PARAMETERS |
| 4628 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4629 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4630 | RETURN VALUE |
| 4631 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4632 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4633 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4634 | OMX_ERRORTYPE omx_vdec::use_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4635 | OMX_IN OMX_HANDLETYPE hComp, |
| 4636 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4637 | OMX_IN OMX_U32 port, |
| 4638 | OMX_IN OMX_PTR appData, |
| 4639 | OMX_IN OMX_U32 bytes, |
| 4640 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4641 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4642 | OMX_ERRORTYPE error = OMX_ErrorNone; |
| 4643 | struct vdec_setbuffer_cmd setbuffers; |
| 4644 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4645 | if (bufferHdr == NULL || bytes == 0 || (!secure_mode && buffer == NULL)) { |
| 4646 | DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer); |
| 4647 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4648 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4649 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4650 | DEBUG_PRINT_ERROR("Use Buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4651 | return OMX_ErrorInvalidState; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4652 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4653 | if (port == OMX_CORE_INPUT_PORT_INDEX) |
| 4654 | error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer); |
| 4655 | else if (port == OMX_CORE_OUTPUT_PORT_INDEX) |
| 4656 | error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested |
| 4657 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4658 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4659 | error = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4660 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4661 | DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error); |
| 4662 | if (error == OMX_ErrorNone) { |
| 4663 | if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 4664 | // Send the callback now |
| 4665 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 4666 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
| 4667 | OMX_COMPONENT_GENERATE_EVENT); |
| 4668 | } |
| 4669 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated && |
| 4670 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 4671 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 4672 | post_event(OMX_CommandPortEnable, |
| 4673 | OMX_CORE_INPUT_PORT_INDEX, |
| 4674 | OMX_COMPONENT_GENERATE_EVENT); |
| 4675 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated && |
| 4676 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 4677 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 4678 | post_event(OMX_CommandPortEnable, |
| 4679 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 4680 | OMX_COMPONENT_GENERATE_EVENT); |
| 4681 | } |
| 4682 | } |
| 4683 | return error; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4687 | OMX_BUFFERHEADERTYPE *pmem_bufferHdr) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4688 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4689 | if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) { |
| 4690 | if (m_inp_heap_ptr[bufferindex].pBuffer) |
| 4691 | free(m_inp_heap_ptr[bufferindex].pBuffer); |
| 4692 | m_inp_heap_ptr[bufferindex].pBuffer = NULL; |
| 4693 | } |
| 4694 | if (pmem_bufferHdr) |
| 4695 | free_input_buffer(pmem_bufferHdr); |
| 4696 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4700 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4701 | unsigned int index = 0; |
| 4702 | if (bufferHdr == NULL || m_inp_mem_ptr == NULL) { |
| 4703 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4704 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4705 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4706 | index = bufferHdr - m_inp_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4707 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4708 | |
| 4709 | if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4710 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4711 | if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) { |
| 4712 | struct vdec_setbuffer_cmd setbuffers; |
| 4713 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 4714 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index], |
| 4715 | sizeof (vdec_bufferpayload)); |
| 4716 | if (!secure_mode) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4717 | DEBUG_PRINT_LOW("unmap the input buffer fd=%d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4718 | drv_ctx.ptr_inputbuffer[index].pmem_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4719 | DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4720 | drv_ctx.ptr_inputbuffer[index].mmaped_size, |
| 4721 | drv_ctx.ptr_inputbuffer[index].bufferaddr); |
| 4722 | munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr, |
| 4723 | drv_ctx.ptr_inputbuffer[index].mmaped_size); |
| 4724 | } |
| 4725 | close (drv_ctx.ptr_inputbuffer[index].pmem_fd); |
| 4726 | drv_ctx.ptr_inputbuffer[index].pmem_fd = -1; |
| 4727 | if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) { |
| 4728 | free(m_desc_buffer_ptr[index].buf_addr); |
| 4729 | m_desc_buffer_ptr[index].buf_addr = NULL; |
| 4730 | m_desc_buffer_ptr[index].desc_data_size = 0; |
| 4731 | } |
| 4732 | #ifdef USE_ION |
| 4733 | free_ion_memory(&drv_ctx.ip_buf_ion_info[index]); |
| 4734 | #endif |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4742 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4743 | unsigned int index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4744 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4745 | if (bufferHdr == NULL || m_out_mem_ptr == NULL) { |
| 4746 | return OMX_ErrorBadParameter; |
| 4747 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4748 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4749 | index = bufferHdr - m_out_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4750 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index); |
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 (index < drv_ctx.op_buf.actualcount |
| 4753 | && drv_ctx.ptr_outputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4754 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4755 | drv_ctx.ptr_outputbuffer[index].bufferaddr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4756 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4757 | struct vdec_setbuffer_cmd setbuffers; |
| 4758 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4759 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index], |
| 4760 | sizeof (vdec_bufferpayload)); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4761 | |
| 4762 | if (!dynamic_buf_mode) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4763 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4764 | if (m_enable_android_native_buffers) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4765 | if (!secure_mode) { |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4766 | if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) { |
| 4767 | munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr, |
| 4768 | drv_ctx.ptr_outputbuffer[index].mmaped_size); |
| 4769 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4770 | } |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4771 | drv_ctx.ptr_outputbuffer[index].pmem_fd = -1; |
| 4772 | } else { |
| 4773 | #endif |
| 4774 | if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) { |
| 4775 | if (!secure_mode) { |
| 4776 | DEBUG_PRINT_LOW("\n unmap the output buffer fd = %d", |
| 4777 | drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4778 | DEBUG_PRINT_LOW("\n unmap the ouput buffer size=%d address = %p", |
| 4779 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount, |
| 4780 | drv_ctx.ptr_outputbuffer[0].bufferaddr); |
| 4781 | munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr, |
| 4782 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount); |
| 4783 | } |
| 4784 | close (drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4785 | drv_ctx.ptr_outputbuffer[0].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4786 | #ifdef USE_ION |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4787 | free_ion_memory(&drv_ctx.op_buf_ion_info[0]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4788 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4789 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4790 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4791 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4792 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4793 | } //!dynamic_buf_mode |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4794 | if (release_output_done()) { |
| 4795 | free_extradata(); |
| 4796 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4797 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4798 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4799 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4800 | |
| 4801 | } |
| 4802 | |
| 4803 | OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4804 | OMX_BUFFERHEADERTYPE **bufferHdr, |
| 4805 | OMX_U32 port, |
| 4806 | OMX_PTR appData, |
| 4807 | OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4808 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4809 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4810 | unsigned char *buf_addr = NULL; |
| 4811 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4812 | unsigned i = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4813 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4814 | /* Sanity Check*/ |
| 4815 | if (bufferHdr == NULL) { |
| 4816 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4819 | if (m_inp_heap_ptr == NULL) { |
| 4820 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4821 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4822 | drv_ctx.ip_buf.actualcount); |
| 4823 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \ |
| 4824 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4825 | drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4826 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4827 | if (m_inp_heap_ptr == NULL || m_phdr_pmem_ptr == NULL) { |
| 4828 | DEBUG_PRINT_ERROR("m_inp_heap_ptr or m_phdr_pmem_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4829 | return OMX_ErrorInsufficientResources; |
| 4830 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4831 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4832 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4833 | /*Find a Free index*/ |
| 4834 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 4835 | if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4836 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4837 | break; |
| 4838 | } |
| 4839 | } |
| 4840 | |
| 4841 | if (i < drv_ctx.ip_buf.actualcount) { |
| 4842 | buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size); |
| 4843 | |
| 4844 | if (buf_addr == NULL) { |
| 4845 | return OMX_ErrorInsufficientResources; |
| 4846 | } |
| 4847 | |
| 4848 | *bufferHdr = (m_inp_heap_ptr + i); |
| 4849 | input = *bufferHdr; |
| 4850 | BITMASK_SET(&m_heap_inp_bm_count,i); |
| 4851 | |
| 4852 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 4853 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 4854 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 4855 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 4856 | input->pAppPrivate = appData; |
| 4857 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4858 | DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4859 | 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] | 4860 | 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] | 4861 | /*Add the Buffers to freeq*/ |
| 4862 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i], |
| 4863 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4864 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4865 | return OMX_ErrorInsufficientResources; |
| 4866 | } |
| 4867 | } else { |
| 4868 | return OMX_ErrorBadParameter; |
| 4869 | } |
| 4870 | |
| 4871 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4872 | |
| 4873 | } |
| 4874 | |
| 4875 | |
| 4876 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4877 | FUNCTION |
| 4878 | omx_vdec::AllocateInputBuffer |
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 | DESCRIPTION |
| 4881 | Helper function for allocate buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4882 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4883 | PARAMETERS |
| 4884 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4885 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4886 | RETURN VALUE |
| 4887 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4888 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4889 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4890 | OMX_ERRORTYPE omx_vdec::allocate_input_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4891 | OMX_IN OMX_HANDLETYPE hComp, |
| 4892 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4893 | OMX_IN OMX_U32 port, |
| 4894 | OMX_IN OMX_PTR appData, |
| 4895 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4896 | { |
| 4897 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4898 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4899 | struct vdec_setbuffer_cmd setbuffers; |
| 4900 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4901 | unsigned i = 0; |
| 4902 | unsigned char *buf_addr = NULL; |
| 4903 | int pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4904 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4905 | if (bytes != drv_ctx.ip_buf.buffer_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4906 | DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4907 | bytes, drv_ctx.ip_buf.buffer_size); |
| 4908 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4909 | } |
| 4910 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4911 | if (!m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4912 | DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4913 | drv_ctx.ip_buf.actualcount, |
| 4914 | drv_ctx.ip_buf.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4915 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4916 | m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4917 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount); |
| 4918 | |
| 4919 | if (m_inp_mem_ptr == NULL) { |
| 4920 | return OMX_ErrorInsufficientResources; |
| 4921 | } |
| 4922 | |
| 4923 | drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \ |
| 4924 | calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount); |
| 4925 | |
| 4926 | if (drv_ctx.ptr_inputbuffer == NULL) { |
| 4927 | return OMX_ErrorInsufficientResources; |
| 4928 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4929 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4930 | drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \ |
| 4931 | calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4932 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4933 | if (drv_ctx.ip_buf_ion_info == NULL) { |
| 4934 | return OMX_ErrorInsufficientResources; |
| 4935 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4936 | #endif |
| 4937 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4938 | for (i=0; i < drv_ctx.ip_buf.actualcount; i++) { |
| 4939 | drv_ctx.ptr_inputbuffer [i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4940 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4941 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4942 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4943 | } |
| 4944 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4945 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4946 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 4947 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4948 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4949 | break; |
| 4950 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4951 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4952 | |
| 4953 | if (i < drv_ctx.ip_buf.actualcount) { |
| 4954 | struct v4l2_buffer buf; |
| 4955 | struct v4l2_plane plane; |
| 4956 | int rc; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4957 | DEBUG_PRINT_LOW("Allocate input Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4958 | #ifdef USE_ION |
| 4959 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 4960 | drv_ctx.ip_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 4961 | &drv_ctx.ip_buf_ion_info[i].ion_alloc_data, |
| 4962 | &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4963 | if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) { |
| 4964 | return OMX_ErrorInsufficientResources; |
| 4965 | } |
| 4966 | pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd; |
| 4967 | #else |
| 4968 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 4969 | |
| 4970 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4971 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4972 | return OMX_ErrorInsufficientResources; |
| 4973 | } |
| 4974 | |
| 4975 | if (pmem_fd == 0) { |
| 4976 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 4977 | |
| 4978 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4979 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4980 | return OMX_ErrorInsufficientResources; |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size, |
| 4985 | drv_ctx.ip_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4986 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4987 | close(pmem_fd); |
| 4988 | return OMX_ErrorInsufficientResources; |
| 4989 | } |
| 4990 | #endif |
| 4991 | if (!secure_mode) { |
| 4992 | buf_addr = (unsigned char *)mmap(NULL, |
| 4993 | drv_ctx.ip_buf.buffer_size, |
| 4994 | PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0); |
| 4995 | |
| 4996 | if (buf_addr == MAP_FAILED) { |
| 4997 | close(pmem_fd); |
| 4998 | #ifdef USE_ION |
| 4999 | free_ion_memory(&drv_ctx.ip_buf_ion_info[i]); |
| 5000 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5001 | DEBUG_PRINT_ERROR("Map Failed to allocate input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5002 | return OMX_ErrorInsufficientResources; |
| 5003 | } |
| 5004 | } |
| 5005 | *bufferHdr = (m_inp_mem_ptr + i); |
| 5006 | if (secure_mode) |
| 5007 | drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr; |
| 5008 | else |
| 5009 | drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr; |
| 5010 | drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd; |
| 5011 | drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size; |
| 5012 | drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size; |
| 5013 | drv_ctx.ptr_inputbuffer [i].offset = 0; |
| 5014 | |
| 5015 | |
| 5016 | buf.index = i; |
| 5017 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5018 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5019 | plane.bytesused = 0; |
| 5020 | plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size; |
| 5021 | plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr; |
| 5022 | plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 5023 | plane.reserved[1] = 0; |
| 5024 | plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset; |
| 5025 | buf.m.planes = &plane; |
| 5026 | buf.length = 1; |
| 5027 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5028 | DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5029 | drv_ctx.ptr_inputbuffer[i].bufferaddr); |
| 5030 | |
| 5031 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5032 | |
| 5033 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5034 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5035 | /*TODO: How to handle this case */ |
| 5036 | return OMX_ErrorInsufficientResources; |
| 5037 | } |
| 5038 | |
| 5039 | input = *bufferHdr; |
| 5040 | BITMASK_SET(&m_inp_bm_count,i); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5041 | DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5042 | if (secure_mode) |
| 5043 | input->pBuffer = (OMX_U8 *)drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 5044 | else |
| 5045 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 5046 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5047 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5048 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 5049 | input->pAppPrivate = appData; |
| 5050 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
| 5051 | input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i]; |
| 5052 | |
| 5053 | if (drv_ctx.disable_dmx) { |
| 5054 | eRet = allocate_desc_buffer(i); |
| 5055 | } |
| 5056 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5057 | DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5058 | eRet = OMX_ErrorInsufficientResources; |
| 5059 | } |
| 5060 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | |
| 5064 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5065 | FUNCTION |
| 5066 | omx_vdec::AllocateOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5067 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5068 | DESCRIPTION |
| 5069 | Helper fn for AllocateBuffer in the output pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5070 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5071 | PARAMETERS |
| 5072 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5073 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5074 | RETURN VALUE |
| 5075 | OMX Error None if everything went well. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5076 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5077 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5078 | OMX_ERRORTYPE omx_vdec::allocate_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5079 | OMX_IN OMX_HANDLETYPE hComp, |
| 5080 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5081 | OMX_IN OMX_U32 port, |
| 5082 | OMX_IN OMX_PTR appData, |
| 5083 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5084 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5085 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5086 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 5087 | unsigned i= 0; // Temporary counter |
| 5088 | struct vdec_setbuffer_cmd setbuffers; |
| 5089 | int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5090 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5091 | int ion_device_fd =-1; |
| 5092 | struct ion_allocation_data ion_alloc_data; |
| 5093 | struct ion_fd_data fd_ion_data; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5094 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5095 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5096 | DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5097 | drv_ctx.op_buf.actualcount, |
| 5098 | drv_ctx.op_buf.buffer_size); |
| 5099 | int nBufHdrSize = 0; |
| 5100 | int nPlatformEntrySize = 0; |
| 5101 | int nPlatformListSize = 0; |
| 5102 | int nPMEMInfoSize = 0; |
| 5103 | int pmem_fd = -1; |
| 5104 | unsigned char *pmem_baseaddress = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5105 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5106 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 5107 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 5108 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5109 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5110 | DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5111 | drv_ctx.op_buf.actualcount); |
| 5112 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 5113 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5114 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5115 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 5116 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 5117 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 5118 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 5119 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 5120 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5121 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5122 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5123 | sizeof(OMX_BUFFERHEADERTYPE), |
| 5124 | nPMEMInfoSize, |
| 5125 | nPlatformListSize); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5126 | DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5127 | drv_ctx.op_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5128 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5129 | ion_device_fd = alloc_map_ion_memory( |
| 5130 | drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount, |
| 5131 | drv_ctx.op_buf.alignment, |
| 5132 | &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 5133 | if (ion_device_fd < 0) { |
| 5134 | return OMX_ErrorInsufficientResources; |
| 5135 | } |
| 5136 | pmem_fd = fd_ion_data.fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5137 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5138 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5139 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5140 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5141 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5142 | drv_ctx.op_buf.buffer_size); |
| 5143 | return OMX_ErrorInsufficientResources; |
| 5144 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5145 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5146 | if (pmem_fd == 0) { |
| 5147 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5148 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5149 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5150 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5151 | drv_ctx.op_buf.buffer_size); |
| 5152 | return OMX_ErrorInsufficientResources; |
| 5153 | } |
| 5154 | } |
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 | if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size * |
| 5157 | drv_ctx.op_buf.actualcount, |
| 5158 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5159 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5160 | close(pmem_fd); |
| 5161 | return OMX_ErrorInsufficientResources; |
| 5162 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5163 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5164 | if (!secure_mode) { |
| 5165 | pmem_baseaddress = (unsigned char *)mmap(NULL, |
| 5166 | (drv_ctx.op_buf.buffer_size * |
| 5167 | drv_ctx.op_buf.actualcount), |
| 5168 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0); |
| 5169 | if (pmem_baseaddress == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5170 | DEBUG_PRINT_ERROR("MMAP failed for Size %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5171 | drv_ctx.op_buf.buffer_size); |
| 5172 | close(pmem_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5173 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5174 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5175 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5176 | return OMX_ErrorInsufficientResources; |
| 5177 | } |
| 5178 | } |
| 5179 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 5180 | // Alloc mem for platform specific info |
| 5181 | char *pPtr=NULL; |
| 5182 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 5183 | nPMEMInfoSize,1); |
| 5184 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\ |
| 5185 | calloc (sizeof(struct vdec_bufferpayload), |
| 5186 | drv_ctx.op_buf.actualcount); |
| 5187 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 5188 | calloc (sizeof (struct vdec_output_frameinfo), |
| 5189 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5190 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 5191 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer "); |
| 5192 | return OMX_ErrorInsufficientResources; |
| 5193 | } |
| 5194 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5195 | #ifdef USE_ION |
| 5196 | drv_ctx.op_buf_ion_info = (struct vdec_ion *)\ |
| 5197 | calloc (sizeof(struct vdec_ion), |
| 5198 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5199 | if (!drv_ctx.op_buf_ion_info) { |
| 5200 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 5201 | return OMX_ErrorInsufficientResources; |
| 5202 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5203 | #endif |
| 5204 | |
| 5205 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 5206 | && drv_ctx.ptr_respbuffer) { |
| 5207 | drv_ctx.ptr_outputbuffer[0].mmaped_size = |
| 5208 | (drv_ctx.op_buf.buffer_size * |
| 5209 | drv_ctx.op_buf.actualcount); |
| 5210 | bufHdr = m_out_mem_ptr; |
| 5211 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 5212 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 5213 | (((char *) m_platform_list) + nPlatformListSize); |
| 5214 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 5215 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 5216 | pPlatformList = m_platform_list; |
| 5217 | pPlatformEntry = m_platform_entry; |
| 5218 | pPMEMInfo = m_pmem_info; |
| 5219 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5220 | 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] | 5221 | |
| 5222 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5223 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry); |
| 5224 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5225 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 5226 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5227 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5228 | // Set the values when we determine the right HxW param |
| 5229 | bufHdr->nAllocLen = bytes; |
| 5230 | bufHdr->nFilledLen = 0; |
| 5231 | bufHdr->pAppPrivate = appData; |
| 5232 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 5233 | // Platform specific PMEM Information |
| 5234 | // Initialize the Platform Entry |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5235 | //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5236 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 5237 | pPlatformEntry->entry = pPMEMInfo; |
| 5238 | // Initialize the Platform List |
| 5239 | pPlatformList->nEntries = 1; |
| 5240 | pPlatformList->entryList = pPlatformEntry; |
| 5241 | // Keep pBuffer NULL till vdec is opened |
| 5242 | bufHdr->pBuffer = NULL; |
| 5243 | bufHdr->nOffset = 0; |
| 5244 | |
| 5245 | pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i; |
| 5246 | pPMEMInfo->pmem_fd = 0; |
| 5247 | bufHdr->pPlatformPrivate = pPlatformList; |
| 5248 | |
| 5249 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd; |
| 5250 | m_pmem_info[i].pmem_fd = pmem_fd; |
| 5251 | #ifdef USE_ION |
| 5252 | drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd; |
| 5253 | drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data; |
| 5254 | drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data; |
| 5255 | #endif |
| 5256 | |
| 5257 | /*Create a mapping between buffers*/ |
| 5258 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 5259 | drv_ctx.ptr_respbuffer[i].client_data = (void *)\ |
| 5260 | &drv_ctx.ptr_outputbuffer[i]; |
| 5261 | drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i; |
| 5262 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 5263 | pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 5264 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 5265 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 5266 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5267 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5268 | DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5269 | pmem_fd, drv_ctx.ptr_outputbuffer[i].offset, |
| 5270 | drv_ctx.ptr_outputbuffer[i].bufferaddr); |
| 5271 | // Move the buffer and buffer header pointers |
| 5272 | bufHdr++; |
| 5273 | pPMEMInfo++; |
| 5274 | pPlatformEntry++; |
| 5275 | pPlatformList++; |
| 5276 | } |
| 5277 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5278 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5279 | m_out_mem_ptr, pPtr); |
| 5280 | if (m_out_mem_ptr) { |
| 5281 | free(m_out_mem_ptr); |
| 5282 | m_out_mem_ptr = NULL; |
| 5283 | } |
| 5284 | if (pPtr) { |
| 5285 | free(pPtr); |
| 5286 | pPtr = NULL; |
| 5287 | } |
| 5288 | if (drv_ctx.ptr_outputbuffer) { |
| 5289 | free(drv_ctx.ptr_outputbuffer); |
| 5290 | drv_ctx.ptr_outputbuffer = NULL; |
| 5291 | } |
| 5292 | if (drv_ctx.ptr_respbuffer) { |
| 5293 | free(drv_ctx.ptr_respbuffer); |
| 5294 | drv_ctx.ptr_respbuffer = NULL; |
| 5295 | } |
| 5296 | #ifdef USE_ION |
| 5297 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5298 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5299 | free(drv_ctx.op_buf_ion_info); |
| 5300 | drv_ctx.op_buf_ion_info = NULL; |
| 5301 | } |
| 5302 | #endif |
| 5303 | eRet = OMX_ErrorInsufficientResources; |
| 5304 | } |
| 5305 | if (eRet == OMX_ErrorNone) |
| 5306 | eRet = allocate_extradata(); |
| 5307 | } |
| 5308 | |
| 5309 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 5310 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5311 | DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5312 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5313 | } |
| 5314 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5315 | |
| 5316 | if (eRet == OMX_ErrorNone) { |
| 5317 | if (i < drv_ctx.op_buf.actualcount) { |
| 5318 | struct v4l2_buffer buf; |
| 5319 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 5320 | int rc; |
| 5321 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 5322 | |
| 5323 | drv_ctx.ptr_outputbuffer[i].buffer_len = |
| 5324 | drv_ctx.op_buf.buffer_size; |
| 5325 | |
| 5326 | *bufferHdr = (m_out_mem_ptr + i ); |
| 5327 | if (secure_mode) { |
| 5328 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 5329 | } |
| 5330 | drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 5331 | |
| 5332 | buf.index = i; |
| 5333 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5334 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5335 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 5336 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 5337 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5338 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5339 | 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] | 5340 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5341 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 5342 | plane[0].data_offset = 0; |
| 5343 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 5344 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 5345 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 5346 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5347 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5348 | 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] | 5349 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5350 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 5351 | plane[extra_idx].data_offset = 0; |
| 5352 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5353 | DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5354 | return OMX_ErrorBadParameter; |
| 5355 | } |
| 5356 | buf.m.planes = plane; |
| 5357 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5358 | 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] | 5359 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5360 | if (rc) { |
| 5361 | /*TODO: How to handle this case */ |
| 5362 | return OMX_ErrorInsufficientResources; |
| 5363 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5364 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5365 | if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) { |
| 5366 | enum v4l2_buf_type buf_type; |
| 5367 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5368 | rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5369 | if (rc) { |
| 5370 | return OMX_ErrorInsufficientResources; |
| 5371 | } else { |
| 5372 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5373 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5374 | } |
| 5375 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5376 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5377 | (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr; |
| 5378 | (*bufferHdr)->pAppPrivate = appData; |
| 5379 | BITMASK_SET(&m_out_bm_count,i); |
| 5380 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5381 | DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5382 | eRet = OMX_ErrorInsufficientResources; |
| 5383 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5384 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5385 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5386 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | |
| 5390 | // AllocateBuffer -- API Call |
| 5391 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5392 | FUNCTION |
| 5393 | omx_vdec::AllocateBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5394 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5395 | DESCRIPTION |
| 5396 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5397 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5398 | PARAMETERS |
| 5399 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5400 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5401 | RETURN VALUE |
| 5402 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5403 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5404 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5405 | OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5406 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5407 | OMX_IN OMX_U32 port, |
| 5408 | OMX_IN OMX_PTR appData, |
| 5409 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5410 | { |
| 5411 | unsigned i = 0; |
| 5412 | OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type |
| 5413 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5414 | DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5415 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5416 | DEBUG_PRINT_ERROR("Allocate Buf in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5417 | return OMX_ErrorInvalidState; |
| 5418 | } |
| 5419 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5420 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5421 | if (arbitrary_bytes) { |
| 5422 | eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes); |
| 5423 | } else { |
| 5424 | eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes); |
| 5425 | } |
| 5426 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5427 | eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port, |
| 5428 | appData,bytes); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5429 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5430 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5431 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5432 | } |
| 5433 | DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5434 | if (eRet == OMX_ErrorNone) { |
| 5435 | if (allocate_done()) { |
| 5436 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5437 | // Send the callback now |
| 5438 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 5439 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5440 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5441 | } |
| 5442 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5443 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) { |
| 5444 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 5445 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 5446 | post_event(OMX_CommandPortEnable, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5447 | OMX_CORE_INPUT_PORT_INDEX, |
| 5448 | OMX_COMPONENT_GENERATE_EVENT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5449 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5450 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5451 | if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) { |
| 5452 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 5453 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5454 | post_event(OMX_CommandPortEnable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5455 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5456 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5457 | } |
| 5458 | } |
| 5459 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5460 | DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5461 | return eRet; |
| 5462 | } |
| 5463 | |
| 5464 | // Free Buffer - API call |
| 5465 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5466 | FUNCTION |
| 5467 | omx_vdec::FreeBuffer |
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 | DESCRIPTION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5470 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5471 | PARAMETERS |
| 5472 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5473 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5474 | RETURN VALUE |
| 5475 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5476 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5477 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5478 | OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5479 | OMX_IN OMX_U32 port, |
| 5480 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5481 | { |
| 5482 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5483 | unsigned int nPortIndex; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5484 | DEBUG_PRINT_LOW("In for decoder free_buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5485 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5486 | if (m_state == OMX_StateIdle && |
| 5487 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5488 | DEBUG_PRINT_LOW(" free buffer while Component in Loading pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5489 | } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)|| |
| 5490 | (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5491 | DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5492 | } else if ((port == OMX_CORE_INPUT_PORT_INDEX && |
| 5493 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) || |
| 5494 | (port == OMX_CORE_OUTPUT_PORT_INDEX && |
| 5495 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5496 | DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5497 | } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5498 | 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] | 5499 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5500 | OMX_ErrorPortUnpopulated, |
| 5501 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5502 | |
| 5503 | return OMX_ErrorIncorrectStateOperation; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5504 | } else if (m_state != OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5505 | DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5506 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5507 | OMX_ErrorPortUnpopulated, |
| 5508 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5509 | } |
| 5510 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5511 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5512 | /*Check if arbitrary bytes*/ |
| 5513 | if (!arbitrary_bytes && !input_use_buffer) |
| 5514 | nPortIndex = buffer - m_inp_mem_ptr; |
| 5515 | else |
| 5516 | nPortIndex = buffer - m_inp_heap_ptr; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5517 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5518 | 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] | 5519 | if (nPortIndex < drv_ctx.ip_buf.actualcount) { |
| 5520 | // Clear the bit associated with it. |
| 5521 | BITMASK_CLEAR(&m_inp_bm_count,nPortIndex); |
| 5522 | BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex); |
| 5523 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5524 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5525 | DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5526 | if (m_phdr_pmem_ptr) |
| 5527 | free_input_buffer(m_phdr_pmem_ptr[nPortIndex]); |
| 5528 | } else { |
| 5529 | if (arbitrary_bytes) { |
| 5530 | if (m_phdr_pmem_ptr) |
| 5531 | free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]); |
| 5532 | else |
| 5533 | free_input_buffer(nPortIndex,NULL); |
| 5534 | } else |
| 5535 | free_input_buffer(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5536 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5537 | m_inp_bPopulated = OMX_FALSE; |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5538 | if(release_input_done()) |
| 5539 | release_buffers(this, VDEC_BUFFER_TYPE_INPUT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5540 | /*Free the Buffer Header*/ |
| 5541 | if (release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5542 | DEBUG_PRINT_HIGH("ALL input buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5543 | free_input_buffer_header(); |
| 5544 | } |
| 5545 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5546 | DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5547 | eRet = OMX_ErrorBadPortIndex; |
| 5548 | } |
| 5549 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5550 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING) |
| 5551 | && release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5552 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5553 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 5554 | post_event(OMX_CommandPortDisable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5555 | OMX_CORE_INPUT_PORT_INDEX, |
| 5556 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5557 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5558 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5559 | // check if the buffer is valid |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5560 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5561 | if (nPortIndex < drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5562 | 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] | 5563 | // Clear the bit associated with it. |
| 5564 | BITMASK_CLEAR(&m_out_bm_count,nPortIndex); |
| 5565 | m_out_bPopulated = OMX_FALSE; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5566 | client_buffers.free_output_buffer (buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5567 | |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5568 | if(release_output_done()) { |
| 5569 | release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT); |
| 5570 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5571 | if (release_output_done()) { |
| 5572 | free_output_buffer_header(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5573 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5574 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5575 | DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5576 | eRet = OMX_ErrorBadPortIndex; |
| 5577 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5578 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING) |
| 5579 | && release_output_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5580 | DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5581 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5582 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5583 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5584 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5585 | if (m_enable_android_native_buffers) { |
| 5586 | DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers"); |
| 5587 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 5588 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5589 | #endif |
| 5590 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5591 | post_event(OMX_CommandPortDisable, |
| 5592 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5593 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5594 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5595 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5596 | eRet = OMX_ErrorBadPortIndex; |
| 5597 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5598 | if ((eRet == OMX_ErrorNone) && |
| 5599 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
| 5600 | if (release_done()) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5601 | // Send the callback now |
| 5602 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING); |
| 5603 | post_event(OMX_CommandStateSet, OMX_StateLoaded, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5604 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5605 | } |
| 5606 | } |
| 5607 | return eRet; |
| 5608 | } |
| 5609 | |
| 5610 | |
| 5611 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5612 | FUNCTION |
| 5613 | omx_vdec::EmptyThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5614 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5615 | DESCRIPTION |
| 5616 | This routine is used to push the encoded video frames to |
| 5617 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5618 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5619 | PARAMETERS |
| 5620 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5621 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5622 | RETURN VALUE |
| 5623 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5624 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5625 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5626 | OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5627 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
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 | OMX_ERRORTYPE ret1 = OMX_ErrorNone; |
| 5630 | unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5631 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5632 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5633 | DEBUG_PRINT_ERROR("Empty this buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5634 | return OMX_ErrorInvalidState; |
| 5635 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5636 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5637 | if (buffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5638 | DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5639 | return OMX_ErrorBadParameter; |
| 5640 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5641 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5642 | if (!m_inp_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5643 | DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5644 | return OMX_ErrorIncorrectStateOperation; |
| 5645 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5646 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5647 | if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5648 | DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5649 | return OMX_ErrorBadPortIndex; |
| 5650 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5651 | |
| 5652 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5653 | if (iDivXDrmDecrypt) { |
| 5654 | OMX_ERRORTYPE drmErr = iDivXDrmDecrypt->Decrypt(buffer); |
| 5655 | if (drmErr != OMX_ErrorNone) { |
| 5656 | // this error can be ignored |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5657 | DEBUG_PRINT_LOW("ERROR:iDivXDrmDecrypt->Decrypt %d", drmErr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5658 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5659 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5660 | #endif //_ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5661 | if (perf_flag) { |
| 5662 | if (!latency) { |
| 5663 | dec_time.stop(); |
| 5664 | latency = dec_time.processing_time_us(); |
| 5665 | dec_time.start(); |
| 5666 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5667 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5668 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5669 | if (arbitrary_bytes) { |
| 5670 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5671 | } else { |
| 5672 | if (input_use_buffer == true) { |
| 5673 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5674 | m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen; |
| 5675 | m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp; |
| 5676 | m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags; |
| 5677 | buffer = &m_inp_mem_ptr[nBufferIndex]; |
| 5678 | DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu", |
| 5679 | &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen); |
| 5680 | } else { |
| 5681 | nBufferIndex = buffer - m_inp_mem_ptr; |
| 5682 | } |
| 5683 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5684 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5685 | if (nBufferIndex > drv_ctx.ip_buf.actualcount ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5686 | DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5687 | return OMX_ErrorBadParameter; |
| 5688 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5689 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 5690 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 5691 | codec_config_flag = true; |
| 5692 | DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__); |
| 5693 | } |
| 5694 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5695 | DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)", |
| 5696 | buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen); |
| 5697 | if (arbitrary_bytes) { |
| 5698 | post_event ((unsigned)hComp,(unsigned)buffer, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5699 | OMX_COMPONENT_GENERATE_ETB_ARBITRARY); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5700 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5701 | post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB); |
| 5702 | } |
| 5703 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5707 | FUNCTION |
| 5708 | omx_vdec::empty_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5709 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5710 | DESCRIPTION |
| 5711 | This routine is used to push the encoded video frames to |
| 5712 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5713 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5714 | PARAMETERS |
| 5715 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5716 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5717 | RETURN VALUE |
| 5718 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5719 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5720 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5721 | 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] | 5722 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5723 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5724 | int push_cnt = 0,i=0; |
| 5725 | unsigned nPortIndex = 0; |
| 5726 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 5727 | struct vdec_input_frameinfo frameinfo; |
| 5728 | struct vdec_bufferpayload *temp_buffer; |
| 5729 | struct vdec_seqheader seq_header; |
| 5730 | bool port_setting_changed = true; |
| 5731 | bool not_coded_vop = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5732 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5733 | /*Should we generate a Aync error event*/ |
| 5734 | if (buffer == NULL || buffer->pInputPortPrivate == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5735 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5736 | return OMX_ErrorBadParameter; |
| 5737 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5738 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5739 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5740 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5741 | if (nPortIndex > drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5742 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5743 | nPortIndex); |
| 5744 | return OMX_ErrorBadParameter; |
| 5745 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5746 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5747 | pending_input_buffers++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5748 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5749 | /* return zero length and not an EOS buffer */ |
| 5750 | if (!arbitrary_bytes && (buffer->nFilledLen == 0) && |
| 5751 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5752 | DEBUG_PRINT_HIGH("return zero legth buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5753 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5754 | OMX_COMPONENT_GENERATE_EBD); |
| 5755 | return OMX_ErrorNone; |
| 5756 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5757 | |
| 5758 | |
Deva Ramasubramanian | 286a358 | 2014-08-25 18:09:38 -0700 | [diff] [blame] | 5759 | if (ignore_not_coded_vops && |
| 5760 | (codec_type_parse == CODEC_TYPE_MPEG4 || |
| 5761 | codec_type_parse == CODEC_TYPE_DIVX)) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5762 | mp4StreamType psBits; |
| 5763 | psBits.data = (unsigned char *)(buffer->pBuffer + buffer->nOffset); |
| 5764 | psBits.numBytes = buffer->nFilledLen; |
| 5765 | mp4_headerparser.parseHeader(&psBits); |
| 5766 | not_coded_vop = mp4_headerparser.is_notcodec_vop( |
| 5767 | (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen); |
| 5768 | if (not_coded_vop) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5769 | DEBUG_PRINT_HIGH("Found Not coded vop len %lu frame number %u", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5770 | buffer->nFilledLen,frame_count); |
| 5771 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5772 | DEBUG_PRINT_HIGH("Eos and Not coded Vop set len to zero"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5773 | not_coded_vop = false; |
| 5774 | buffer->nFilledLen = 0; |
| 5775 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5776 | } |
| 5777 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5778 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5779 | if (input_flush_progress == true |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5780 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5781 | || not_coded_vop |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5782 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5783 | ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5784 | DEBUG_PRINT_LOW("Flush in progress return buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5785 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5786 | OMX_COMPONENT_GENERATE_EBD); |
| 5787 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5788 | } |
| 5789 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5790 | temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5791 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 5792 | 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] | 5793 | return OMX_ErrorBadParameter; |
| 5794 | } |
| 5795 | /* If its first frame, H264 codec and reject is true, then parse the nal |
| 5796 | and get the profile. Based on this, reject the clip playback */ |
| 5797 | if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 && |
| 5798 | m_reject_avc_1080p_mp) { |
| 5799 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5800 | DEBUG_PRINT_ERROR("Parse nal to get the profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5801 | h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen, |
| 5802 | NALU_TYPE_SPS); |
| 5803 | m_profile = h264_parser->get_profile(); |
| 5804 | ret = is_video_session_supported(); |
| 5805 | if (ret) { |
| 5806 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD); |
| 5807 | post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT); |
| 5808 | /* Move the state to Invalid to avoid queueing of pending ETB to the driver */ |
| 5809 | m_state = OMX_StateInvalid; |
| 5810 | return OMX_ErrorNone; |
| 5811 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5814 | DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5815 | /*for use buffer we need to memcpy the data*/ |
| 5816 | temp_buffer->buffer_len = buffer->nFilledLen; |
| 5817 | |
| 5818 | if (input_use_buffer) { |
| 5819 | if (buffer->nFilledLen <= temp_buffer->buffer_len) { |
| 5820 | if (arbitrary_bytes) { |
| 5821 | memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen); |
| 5822 | } else { |
| 5823 | memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset), |
| 5824 | buffer->nFilledLen); |
| 5825 | } |
| 5826 | } else { |
| 5827 | return OMX_ErrorBadParameter; |
| 5828 | } |
| 5829 | |
| 5830 | } |
| 5831 | |
| 5832 | frameinfo.bufferaddr = temp_buffer->bufferaddr; |
| 5833 | frameinfo.client_data = (void *) buffer; |
| 5834 | frameinfo.datalen = temp_buffer->buffer_len; |
| 5835 | frameinfo.flags = 0; |
| 5836 | frameinfo.offset = buffer->nOffset; |
| 5837 | frameinfo.pmem_fd = temp_buffer->pmem_fd; |
| 5838 | frameinfo.pmem_offset = temp_buffer->offset; |
| 5839 | frameinfo.timestamp = buffer->nTimeStamp; |
| 5840 | if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) { |
| 5841 | DEBUG_PRINT_LOW("ETB: dmx enabled"); |
| 5842 | if (m_demux_entries == 0) { |
| 5843 | extract_demux_addr_offsets(buffer); |
| 5844 | } |
| 5845 | |
| 5846 | DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries); |
| 5847 | handle_demux_data(buffer); |
| 5848 | frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr; |
| 5849 | frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size; |
| 5850 | } else { |
| 5851 | frameinfo.desc_addr = NULL; |
| 5852 | frameinfo.desc_size = 0; |
| 5853 | } |
| 5854 | if (!arbitrary_bytes) { |
| 5855 | frameinfo.flags |= buffer->nFlags; |
| 5856 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5857 | |
| 5858 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5859 | if (m_debug_timestamp) { |
| 5860 | if (arbitrary_bytes) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5861 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5862 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5863 | } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5864 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5865 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5866 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5867 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5868 | #endif |
| 5869 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5870 | log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5871 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5872 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5873 | frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5874 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5875 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5876 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5877 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5878 | 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] | 5879 | frameinfo.flags |= VDEC_BUFFERFLAG_EOS; |
| 5880 | h264_scratch.nFilledLen = 0; |
| 5881 | nal_count = 0; |
| 5882 | look_ahead_nal = false; |
| 5883 | frame_count = 0; |
| 5884 | if (m_frame_parser.mutils) |
| 5885 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 5886 | m_frame_parser.flush(); |
| 5887 | h264_last_au_ts = LLONG_MAX; |
| 5888 | h264_last_au_flags = 0; |
| 5889 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 5890 | m_demux_entries = 0; |
| 5891 | } |
| 5892 | struct v4l2_buffer buf; |
| 5893 | struct v4l2_plane plane; |
| 5894 | memset( (void *)&buf, 0, sizeof(buf)); |
| 5895 | memset( (void *)&plane, 0, sizeof(plane)); |
| 5896 | int rc; |
| 5897 | unsigned long print_count; |
| 5898 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 5899 | buf.flags = V4L2_QCOM_BUF_FLAG_EOS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5900 | DEBUG_PRINT_HIGH("INPUT EOS reached") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5901 | } |
| 5902 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5903 | buf.index = nPortIndex; |
| 5904 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5905 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5906 | plane.bytesused = temp_buffer->buffer_len; |
| 5907 | plane.length = drv_ctx.ip_buf.buffer_size; |
| 5908 | plane.m.userptr = (unsigned long)temp_buffer->bufferaddr - |
| 5909 | (unsigned long)temp_buffer->offset; |
| 5910 | plane.reserved[0] = temp_buffer->pmem_fd; |
| 5911 | plane.reserved[1] = temp_buffer->offset; |
| 5912 | plane.data_offset = 0; |
| 5913 | buf.m.planes = &plane; |
| 5914 | buf.length = 1; |
| 5915 | if (frameinfo.timestamp >= LLONG_MAX) { |
| 5916 | buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID; |
| 5917 | } |
| 5918 | //assumption is that timestamp is in milliseconds |
| 5919 | buf.timestamp.tv_sec = frameinfo.timestamp / 1000000; |
| 5920 | buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000); |
| 5921 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0; |
| 5922 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_DECODEONLY) ? V4L2_QCOM_BUF_FLAG_DECODEONLY: 0; |
Deva Ramasubramanian | 46a1795 | 2012-08-24 11:35:26 -0700 | [diff] [blame] | 5923 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5924 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 5925 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5926 | DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5927 | return OMX_ErrorHardware; |
| 5928 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 5929 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 5930 | codec_config_flag = false; |
| 5931 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5932 | if (!streaming[OUTPUT_PORT]) { |
| 5933 | enum v4l2_buf_type buf_type; |
| 5934 | int ret,r; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 5935 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5936 | buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5937 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5938 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5939 | if (!ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5940 | DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5941 | streaming[OUTPUT_PORT] = true; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 5942 | } else if (errno == EBUSY) { |
| 5943 | DEBUG_PRINT_ERROR("Failed to call stream on OUTPUT due to HW_OVERLOAD"); |
| 5944 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
| 5945 | OMX_COMPONENT_GENERATE_EBD); |
| 5946 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5947 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5948 | DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5949 | DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued"); |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 5950 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5951 | OMX_COMPONENT_GENERATE_EBD); |
| 5952 | return OMX_ErrorBadParameter; |
| 5953 | } |
| 5954 | } |
| 5955 | DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)", |
| 5956 | frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen); |
| 5957 | time_stamp_dts.insert_timestamp(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5958 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5959 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5963 | FUNCTION |
| 5964 | omx_vdec::FillThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5965 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5966 | DESCRIPTION |
| 5967 | IL client uses this method to release the frame buffer |
| 5968 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5969 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5970 | PARAMETERS |
| 5971 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5972 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5973 | RETURN VALUE |
| 5974 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5975 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5976 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5977 | OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5978 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5979 | { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 5980 | if (dynamic_buf_mode) { |
| 5981 | private_handle_t *handle = NULL; |
| 5982 | struct VideoDecoderOutputMetaData *meta; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 5983 | unsigned int nPortIndex = 0; |
| 5984 | |
| 5985 | if (!buffer || !buffer->pBuffer) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5986 | DEBUG_PRINT_ERROR("%s: invalid params: %p", __FUNCTION__, buffer); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 5987 | return OMX_ErrorBadParameter; |
| 5988 | } |
| 5989 | |
| 5990 | //get the buffer type and fd info |
| 5991 | meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer; |
| 5992 | handle = (private_handle_t *)meta->pHandle; |
Arun Menon | b49abf2 | 2013-12-14 21:38:10 -0800 | [diff] [blame] | 5993 | DEBUG_PRINT_LOW("FTB: metabuf: %p buftype: %d bufhndl: %p ", meta, meta->eType, meta->pHandle); |
| 5994 | |
| 5995 | if (!handle) { |
| 5996 | DEBUG_PRINT_ERROR("FTB: Error: IL client passed an invalid buf handle - %p", handle); |
| 5997 | return OMX_ErrorBadParameter; |
| 5998 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 5999 | //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF |
| 6000 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6001 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd; |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6002 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = (OMX_U8*) buffer; |
ApurupaPattapu | f693a4d | 2013-12-04 16:07:07 -0800 | [diff] [blame] | 6003 | |
| 6004 | //Store private handle from GraphicBuffer |
| 6005 | native_buffer[nPortIndex].privatehandle = handle; |
| 6006 | native_buffer[nPortIndex].nativehandle = handle; |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6007 | |
| 6008 | //buffer->nAllocLen will be sizeof(struct VideoDecoderOutputMetaData). Overwrite |
| 6009 | //this with a more sane size so that we don't compensate in rest of code |
| 6010 | //We'll restore this size later on, so that it's transparent to client |
| 6011 | buffer->nFilledLen = 0; |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 6012 | buffer->nAllocLen = handle->size; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6013 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6014 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6015 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6016 | DEBUG_PRINT_ERROR("FTB in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6017 | return OMX_ErrorInvalidState; |
| 6018 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6019 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6020 | if (!m_out_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6021 | DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6022 | return OMX_ErrorIncorrectStateOperation; |
| 6023 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6024 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6025 | if (buffer == NULL || |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6026 | ((buffer - client_buffers.get_il_buf_hdr()) >= (int)drv_ctx.op_buf.actualcount)) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6027 | return OMX_ErrorBadParameter; |
| 6028 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6029 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6030 | if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6031 | DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6032 | return OMX_ErrorBadPortIndex; |
| 6033 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6034 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6035 | DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 6036 | post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg); |
| 6037 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6038 | } |
| 6039 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6040 | FUNCTION |
| 6041 | omx_vdec::fill_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6042 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6043 | DESCRIPTION |
| 6044 | IL client uses this method to release the frame buffer |
| 6045 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6046 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6047 | PARAMETERS |
| 6048 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6049 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6050 | RETURN VALUE |
| 6051 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6052 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6053 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6054 | OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6055 | OMX_IN OMX_HANDLETYPE hComp, |
| 6056 | OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6057 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6058 | OMX_ERRORTYPE nRet = OMX_ErrorNone; |
| 6059 | OMX_BUFFERHEADERTYPE *buffer = bufferAdd; |
| 6060 | unsigned nPortIndex = 0; |
| 6061 | struct vdec_fillbuffer_cmd fillbuffer; |
| 6062 | struct vdec_bufferpayload *ptr_outputbuffer = NULL; |
| 6063 | struct vdec_output_frameinfo *ptr_respbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6064 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6065 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
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 (bufferAdd == NULL || nPortIndex > drv_ctx.op_buf.actualcount) |
| 6068 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6069 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6070 | DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6071 | bufferAdd, bufferAdd->pBuffer); |
| 6072 | /*Return back the output buffer to client*/ |
| 6073 | if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6074 | DEBUG_PRINT_LOW("Output Buffers return flush/disable condition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6075 | buffer->nFilledLen = 0; |
| 6076 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6077 | return OMX_ErrorNone; |
| 6078 | } |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6079 | |
| 6080 | if (dynamic_buf_mode) { |
| 6081 | //map the buffer handle based on the size set on output port definition. |
| 6082 | if (!secure_mode) { |
| 6083 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = |
| 6084 | (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size, |
| 6085 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 6086 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, 0); |
| 6087 | } |
| 6088 | drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0; |
| 6089 | drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size; |
| 6090 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 6091 | buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, |
| 6092 | drv_ctx.ptr_outputbuffer[nPortIndex].offset); |
| 6093 | } |
| 6094 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6095 | pending_output_buffers++; |
| 6096 | buffer = client_buffers.get_dr_buf_hdr(bufferAdd); |
| 6097 | ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate; |
| 6098 | if (ptr_respbuffer) { |
| 6099 | ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data; |
| 6100 | } |
Shalaj 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 | if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) { |
| 6103 | DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL"); |
| 6104 | buffer->nFilledLen = 0; |
| 6105 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6106 | pending_output_buffers--; |
| 6107 | return OMX_ErrorBadParameter; |
| 6108 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6109 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6110 | int rc = 0; |
| 6111 | struct v4l2_buffer buf; |
| 6112 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 6113 | memset( (void *)&buf, 0, sizeof(buf)); |
| 6114 | memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES)); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6115 | unsigned int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6116 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6117 | buf.index = nPortIndex; |
| 6118 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 6119 | buf.memory = V4L2_MEMORY_USERPTR; |
| 6120 | plane[0].bytesused = buffer->nFilledLen; |
| 6121 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 6122 | plane[0].m.userptr = |
| 6123 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr - |
| 6124 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6125 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd; |
| 6126 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6127 | plane[0].data_offset = 0; |
| 6128 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 6129 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 6130 | plane[extra_idx].bytesused = 0; |
| 6131 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 6132 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + nPortIndex * drv_ctx.extradata_info.buffer_size); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 6133 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6134 | 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] | 6135 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6136 | plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size; |
| 6137 | plane[extra_idx].data_offset = 0; |
| 6138 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6139 | DEBUG_PRINT_ERROR("Extradata index higher than expected: %u", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6140 | return OMX_ErrorBadParameter; |
| 6141 | } |
| 6142 | buf.m.planes = plane; |
| 6143 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6144 | 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] | 6145 | plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]); |
| 6146 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6147 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 6148 | if (rc) { |
| 6149 | /*TODO: How to handle this case */ |
| 6150 | DEBUG_PRINT_ERROR("Failed to qbuf to driver"); |
| 6151 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6152 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6156 | FUNCTION |
| 6157 | omx_vdec::SetCallbacks |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6158 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6159 | DESCRIPTION |
| 6160 | Set the callbacks. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6161 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6162 | PARAMETERS |
| 6163 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6164 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6165 | RETURN VALUE |
| 6166 | OMX Error None if everything successful. |
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 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6169 | OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6170 | OMX_IN OMX_CALLBACKTYPE* callbacks, |
| 6171 | OMX_IN OMX_PTR appData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6172 | { |
| 6173 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6174 | m_cb = *callbacks; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6175 | DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6176 | m_cb.EventHandler,m_cb.FillBufferDone); |
| 6177 | m_app_data = appData; |
| 6178 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6182 | FUNCTION |
| 6183 | omx_vdec::ComponentDeInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6184 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6185 | DESCRIPTION |
| 6186 | Destroys the component and release memory allocated to the heap. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6187 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6188 | PARAMETERS |
| 6189 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6190 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6191 | RETURN VALUE |
| 6192 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6193 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6194 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6195 | OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp) |
| 6196 | { |
| 6197 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6198 | if (iDivXDrmDecrypt) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6199 | delete iDivXDrmDecrypt; |
| 6200 | iDivXDrmDecrypt=NULL; |
| 6201 | } |
| 6202 | #endif //_ANDROID_ |
| 6203 | |
Shalaj Jain | 286b006 | 2013-02-21 20:35:48 -0800 | [diff] [blame] | 6204 | unsigned i = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6205 | if (OMX_StateLoaded != m_state) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6206 | DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6207 | m_state); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6208 | DEBUG_PRINT_ERROR("Playback Ended - FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6209 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6210 | DEBUG_PRINT_HIGH("Playback Ended - PASSED"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | /*Check if the output buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6214 | if (m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6215 | DEBUG_PRINT_LOW("Freeing the Output Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6216 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) { |
| 6217 | free_output_buffer (&m_out_mem_ptr[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6218 | } |
| 6219 | #ifdef _ANDROID_ICS_ |
| 6220 | memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 6221 | #endif |
| 6222 | } |
| 6223 | |
| 6224 | /*Check if the input buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6225 | if (m_inp_mem_ptr || m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6226 | DEBUG_PRINT_LOW("Freeing the Input Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6227 | for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) { |
| 6228 | if (m_inp_mem_ptr) |
| 6229 | free_input_buffer (i,&m_inp_mem_ptr[i]); |
| 6230 | else |
| 6231 | free_input_buffer (i,NULL); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6232 | } |
| 6233 | } |
| 6234 | free_input_buffer_header(); |
| 6235 | free_output_buffer_header(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6236 | if (h264_scratch.pBuffer) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6237 | free(h264_scratch.pBuffer); |
| 6238 | h264_scratch.pBuffer = NULL; |
| 6239 | } |
| 6240 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6241 | if (h264_parser) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6242 | delete h264_parser; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6243 | h264_parser = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6246 | if (m_frame_parser.mutils) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6247 | DEBUG_PRINT_LOW("Free utils parser"); |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6248 | delete (m_frame_parser.mutils); |
| 6249 | m_frame_parser.mutils = NULL; |
| 6250 | } |
| 6251 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6252 | if (m_platform_list) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6253 | free(m_platform_list); |
| 6254 | m_platform_list = NULL; |
| 6255 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6256 | if (m_vendor_config.pData) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6257 | free(m_vendor_config.pData); |
| 6258 | m_vendor_config.pData = NULL; |
| 6259 | } |
| 6260 | |
| 6261 | // Reset counters in mesg queues |
| 6262 | m_ftb_q.m_size=0; |
| 6263 | m_cmd_q.m_size=0; |
| 6264 | m_etb_q.m_size=0; |
| 6265 | m_ftb_q.m_read = m_ftb_q.m_write =0; |
| 6266 | m_cmd_q.m_read = m_cmd_q.m_write =0; |
| 6267 | m_etb_q.m_read = m_etb_q.m_write =0; |
| 6268 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6269 | if (m_debug_timestamp) { |
| 6270 | m_timestamp_list.reset_ts_list(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6271 | } |
| 6272 | #endif |
| 6273 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6274 | DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6275 | //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6276 | // NULL); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6277 | DEBUG_PRINT_HIGH("Close the driver instance"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6278 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 6279 | if (m_debug.infile) { |
| 6280 | fclose(m_debug.infile); |
| 6281 | m_debug.infile = NULL; |
| 6282 | } |
| 6283 | if (m_debug.outfile) { |
| 6284 | fclose(m_debug.outfile); |
| 6285 | m_debug.outfile = NULL; |
| 6286 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6287 | #ifdef OUTPUT_EXTRADATA_LOG |
Shalaj Jain | af08f30 | 2013-03-18 13:15:35 -0700 | [diff] [blame] | 6288 | if (outputExtradataFile) |
| 6289 | fclose (outputExtradataFile); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6290 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6291 | DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6292 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6296 | FUNCTION |
| 6297 | omx_vdec::UseEGLImage |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6299 | DESCRIPTION |
| 6300 | OMX Use EGL Image method implementation <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6301 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6302 | PARAMETERS |
| 6303 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6304 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6305 | RETURN VALUE |
| 6306 | Not Implemented error. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6307 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6308 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6309 | OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6310 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 6311 | OMX_IN OMX_U32 port, |
| 6312 | OMX_IN OMX_PTR appData, |
| 6313 | OMX_IN void* eglImage) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6314 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6315 | OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list; |
| 6316 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry; |
| 6317 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6318 | |
| 6319 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6320 | PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc; |
| 6321 | EGLint fd = -1, offset = 0,pmemPtr = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6322 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6323 | int fd = -1, offset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6324 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6325 | DEBUG_PRINT_HIGH("use EGL image support for decoder"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6326 | if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6327 | DEBUG_PRINT_ERROR(""); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6328 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6329 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6330 | if (m_display_id == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6331 | DEBUG_PRINT_ERROR("Display ID is not set by IL client"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6332 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6333 | } |
| 6334 | egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC) |
| 6335 | eglGetProcAddress("eglQueryImageKHR"); |
| 6336 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd); |
| 6337 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset); |
| 6338 | egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6339 | #else //with OMX test app |
| 6340 | struct temp_egl { |
| 6341 | int pmem_fd; |
| 6342 | int offset; |
| 6343 | }; |
| 6344 | struct temp_egl *temp_egl_id = NULL; |
| 6345 | void * pmemPtr = (void *) eglImage; |
| 6346 | temp_egl_id = (struct temp_egl *)eglImage; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6347 | if (temp_egl_id != NULL) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6348 | fd = temp_egl_id->pmem_fd; |
| 6349 | offset = temp_egl_id->offset; |
| 6350 | } |
| 6351 | #endif |
| 6352 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6353 | DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6354 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6355 | } |
| 6356 | pmem_info.pmem_fd = (OMX_U32) fd; |
| 6357 | pmem_info.offset = (OMX_U32) offset; |
| 6358 | pmem_entry.entry = (void *) &pmem_info; |
| 6359 | pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 6360 | pmem_list.entryList = &pmem_entry; |
| 6361 | pmem_list.nEntries = 1; |
| 6362 | ouput_egl_buffers = true; |
| 6363 | if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port, |
| 6364 | (void *)&pmem_list, drv_ctx.op_buf.buffer_size, |
| 6365 | (OMX_U8 *)pmemPtr)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6366 | DEBUG_PRINT_ERROR("use buffer call failed for egl image"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6367 | return OMX_ErrorInsufficientResources; |
| 6368 | } |
| 6369 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
| 6372 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6373 | FUNCTION |
| 6374 | omx_vdec::ComponentRoleEnum |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6375 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6376 | DESCRIPTION |
| 6377 | OMX Component Role Enum method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6378 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6379 | PARAMETERS |
| 6380 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6381 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6382 | RETURN VALUE |
| 6383 | OMX Error None if everything is successful. |
| 6384 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6385 | OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6386 | OMX_OUT OMX_U8* role, |
| 6387 | OMX_IN OMX_U32 index) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6388 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6389 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6390 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6391 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 6392 | if ((0 == index) && role) { |
| 6393 | strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6394 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6395 | } else { |
| 6396 | eRet = OMX_ErrorNoMore; |
| 6397 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6398 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6399 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 6400 | if ((0 == index) && role) { |
| 6401 | strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6402 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6403 | } else { |
| 6404 | eRet = OMX_ErrorNoMore; |
| 6405 | } |
| 6406 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 6407 | if ((0 == index) && role) { |
| 6408 | strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6409 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6410 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6411 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6412 | eRet = OMX_ErrorNoMore; |
| 6413 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6414 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6415 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6416 | else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) || |
| 6417 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE)) |
| 6418 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6419 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6420 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6421 | if ((0 == index) && role) { |
| 6422 | strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6423 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6424 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6425 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6426 | eRet = OMX_ErrorNoMore; |
| 6427 | } |
| 6428 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 6429 | if ((0 == index) && role) { |
| 6430 | strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6431 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6432 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6433 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6434 | eRet = OMX_ErrorNoMore; |
| 6435 | } |
| 6436 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 6437 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 6438 | ) { |
| 6439 | if ((0 == index) && role) { |
| 6440 | strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6441 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6442 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6443 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6444 | eRet = OMX_ErrorNoMore; |
| 6445 | } |
| 6446 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 6447 | if ((0 == index) && role) { |
| 6448 | strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6449 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6450 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6451 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6452 | eRet = OMX_ErrorNoMore; |
| 6453 | } |
| 6454 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6455 | DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6456 | eRet = OMX_ErrorInvalidComponentName; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6457 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6458 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | |
| 6462 | |
| 6463 | |
| 6464 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6465 | FUNCTION |
| 6466 | omx_vdec::AllocateDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6467 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6468 | DESCRIPTION |
| 6469 | Checks if entire buffer pool is allocated by IL Client or not. |
| 6470 | Need this to move to IDLE state. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6471 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6472 | PARAMETERS |
| 6473 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6474 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6475 | RETURN VALUE |
| 6476 | true/false. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6477 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6478 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6479 | bool omx_vdec::allocate_done(void) |
| 6480 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6481 | bool bRet = false; |
| 6482 | bool bRet_In = false; |
| 6483 | bool bRet_Out = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6484 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6485 | bRet_In = allocate_input_done(); |
| 6486 | bRet_Out = allocate_output_done(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6487 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6488 | if (bRet_In && bRet_Out) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6489 | bRet = true; |
| 6490 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6491 | |
| 6492 | return bRet; |
| 6493 | } |
| 6494 | /* ====================================================================== |
| 6495 | FUNCTION |
| 6496 | omx_vdec::AllocateInputDone |
| 6497 | |
| 6498 | DESCRIPTION |
| 6499 | Checks if I/P buffer pool is allocated by IL Client or not. |
| 6500 | |
| 6501 | PARAMETERS |
| 6502 | None. |
| 6503 | |
| 6504 | RETURN VALUE |
| 6505 | true/false. |
| 6506 | |
| 6507 | ========================================================================== */ |
| 6508 | bool omx_vdec::allocate_input_done(void) |
| 6509 | { |
| 6510 | bool bRet = false; |
| 6511 | unsigned i=0; |
| 6512 | |
| 6513 | if (m_inp_mem_ptr == NULL) { |
| 6514 | return bRet; |
| 6515 | } |
| 6516 | if (m_inp_mem_ptr ) { |
| 6517 | for (; i<drv_ctx.ip_buf.actualcount; i++) { |
| 6518 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
| 6519 | break; |
| 6520 | } |
| 6521 | } |
| 6522 | } |
| 6523 | if (i == drv_ctx.ip_buf.actualcount) { |
| 6524 | bRet = true; |
| 6525 | DEBUG_PRINT_HIGH("Allocate done for all i/p buffers"); |
| 6526 | } |
| 6527 | if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) { |
| 6528 | m_inp_bPopulated = OMX_TRUE; |
| 6529 | } |
| 6530 | return bRet; |
| 6531 | } |
| 6532 | /* ====================================================================== |
| 6533 | FUNCTION |
| 6534 | omx_vdec::AllocateOutputDone |
| 6535 | |
| 6536 | DESCRIPTION |
| 6537 | Checks if entire O/P buffer pool is allocated by IL Client or not. |
| 6538 | |
| 6539 | PARAMETERS |
| 6540 | None. |
| 6541 | |
| 6542 | RETURN VALUE |
| 6543 | true/false. |
| 6544 | |
| 6545 | ========================================================================== */ |
| 6546 | bool omx_vdec::allocate_output_done(void) |
| 6547 | { |
| 6548 | bool bRet = false; |
| 6549 | unsigned j=0; |
| 6550 | |
| 6551 | if (m_out_mem_ptr == NULL) { |
| 6552 | return bRet; |
| 6553 | } |
| 6554 | |
| 6555 | if (m_out_mem_ptr) { |
| 6556 | for (; j < drv_ctx.op_buf.actualcount; j++) { |
| 6557 | if (BITMASK_ABSENT(&m_out_bm_count,j)) { |
| 6558 | break; |
| 6559 | } |
| 6560 | } |
| 6561 | } |
| 6562 | |
| 6563 | if (j == drv_ctx.op_buf.actualcount) { |
| 6564 | bRet = true; |
| 6565 | DEBUG_PRINT_HIGH("Allocate done for all o/p buffers"); |
| 6566 | if (m_out_bEnabled) |
| 6567 | m_out_bPopulated = OMX_TRUE; |
| 6568 | } |
| 6569 | |
| 6570 | return bRet; |
| 6571 | } |
| 6572 | |
| 6573 | /* ====================================================================== |
| 6574 | FUNCTION |
| 6575 | omx_vdec::ReleaseDone |
| 6576 | |
| 6577 | DESCRIPTION |
| 6578 | Checks if IL client has released all the buffers. |
| 6579 | |
| 6580 | PARAMETERS |
| 6581 | None. |
| 6582 | |
| 6583 | RETURN VALUE |
| 6584 | true/false |
| 6585 | |
| 6586 | ========================================================================== */ |
| 6587 | bool omx_vdec::release_done(void) |
| 6588 | { |
| 6589 | bool bRet = false; |
| 6590 | |
| 6591 | if (release_input_done()) { |
| 6592 | if (release_output_done()) { |
| 6593 | bRet = true; |
| 6594 | } |
| 6595 | } |
| 6596 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | |
| 6600 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6601 | FUNCTION |
| 6602 | omx_vdec::ReleaseOutputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6603 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6604 | DESCRIPTION |
| 6605 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6606 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6607 | PARAMETERS |
| 6608 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6609 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6610 | RETURN VALUE |
| 6611 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6612 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6613 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6614 | bool omx_vdec::release_output_done(void) |
| 6615 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6616 | bool bRet = false; |
| 6617 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6618 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6619 | 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] | 6620 | if (m_out_mem_ptr) { |
| 6621 | for (; j < drv_ctx.op_buf.actualcount ; j++) { |
| 6622 | if (BITMASK_PRESENT(&m_out_bm_count,j)) { |
| 6623 | break; |
| 6624 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6625 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6626 | if (j == drv_ctx.op_buf.actualcount) { |
| 6627 | m_out_bm_count = 0; |
| 6628 | bRet = true; |
| 6629 | } |
| 6630 | } else { |
| 6631 | m_out_bm_count = 0; |
| 6632 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6633 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6634 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6635 | } |
| 6636 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6637 | FUNCTION |
| 6638 | omx_vdec::ReleaseInputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6639 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6640 | DESCRIPTION |
| 6641 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6642 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6643 | PARAMETERS |
| 6644 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6645 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6646 | RETURN VALUE |
| 6647 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6648 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6649 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6650 | bool omx_vdec::release_input_done(void) |
| 6651 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6652 | bool bRet = false; |
| 6653 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6654 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6655 | 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] | 6656 | if (m_inp_mem_ptr) { |
| 6657 | for (; j<drv_ctx.ip_buf.actualcount; j++) { |
| 6658 | if ( BITMASK_PRESENT(&m_inp_bm_count,j)) { |
| 6659 | break; |
| 6660 | } |
Shalaj 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 | if (j==drv_ctx.ip_buf.actualcount) { |
| 6663 | bRet = true; |
| 6664 | } |
| 6665 | } else { |
| 6666 | bRet = true; |
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 bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6672 | OMX_BUFFERHEADERTYPE * buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6673 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6674 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6675 | 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] | 6676 | DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6677 | return OMX_ErrorBadParameter; |
| 6678 | } else if (output_flush_progress) { |
| 6679 | DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer); |
| 6680 | buffer->nFilledLen = 0; |
| 6681 | buffer->nTimeStamp = 0; |
| 6682 | buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA; |
| 6683 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 6684 | buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT; |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6685 | } |
| 6686 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6687 | if (m_debug_extradata) { |
| 6688 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6689 | DEBUG_PRINT_HIGH(""); |
| 6690 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6691 | DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received"); |
| 6692 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6693 | } |
| 6694 | |
| 6695 | if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6696 | DEBUG_PRINT_HIGH(""); |
| 6697 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6698 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 6699 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6700 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6701 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6702 | |
| 6703 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6704 | DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6705 | buffer, buffer->pBuffer); |
| 6706 | pending_output_buffers --; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6707 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6708 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6709 | DEBUG_PRINT_HIGH("Output EOS has been reached"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6710 | if (!output_flush_progress) |
| 6711 | post_event((unsigned)NULL, (unsigned)NULL, |
| 6712 | OMX_COMPONENT_GENERATE_EOS_DONE); |
| 6713 | |
| 6714 | if (psource_frame) { |
| 6715 | m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame); |
| 6716 | psource_frame = NULL; |
| 6717 | } |
| 6718 | if (pdest_frame) { |
| 6719 | pdest_frame->nFilledLen = 0; |
| 6720 | m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL, |
| 6721 | (unsigned)NULL); |
| 6722 | pdest_frame = NULL; |
| 6723 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6724 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6725 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6726 | |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 6727 | if (!output_flush_progress && (buffer->nFilledLen > 0)) { |
| 6728 | DEBUG_PRINT_LOW("Processing extradata"); |
| 6729 | handle_extradata(buffer); |
| 6730 | } |
| 6731 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6732 | /* For use buffer we need to copy the data */ |
| 6733 | if (!output_flush_progress) { |
| 6734 | /* This is the error check for non-recoverable errros */ |
| 6735 | bool is_duplicate_ts_valid = true; |
| 6736 | bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6737 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6738 | if (output_capability == V4L2_PIX_FMT_MPEG4 || |
| 6739 | output_capability == V4L2_PIX_FMT_MPEG2 || |
| 6740 | output_capability == V4L2_PIX_FMT_DIVX || |
| 6741 | output_capability == V4L2_PIX_FMT_DIVX_311) |
| 6742 | is_duplicate_ts_valid = false; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6743 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6744 | if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 6745 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6746 | is_interlaced = false; |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6747 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6748 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6749 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6750 | if (buffer->nFilledLen > 0) { |
| 6751 | time_stamp_dts.get_next_timestamp(buffer, |
| 6752 | is_interlaced && is_duplicate_ts_valid); |
| 6753 | if (m_debug_timestamp) { |
| 6754 | { |
| 6755 | OMX_TICKS expected_ts = 0; |
| 6756 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6757 | if (is_interlaced && is_duplicate_ts_valid) { |
| 6758 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6759 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6760 | DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6761 | buffer->nTimeStamp, expected_ts); |
| 6762 | |
| 6763 | if (buffer->nTimeStamp != expected_ts) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6764 | DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6765 | } |
| 6766 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6767 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6768 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6769 | time_stamp_dts.remove_time_stamp( |
| 6770 | buffer->nTimeStamp, |
| 6771 | is_interlaced && is_duplicate_ts_valid); |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6772 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6773 | |
| 6774 | |
Praneeth Paladugu | 8f12e82 | 2013-03-11 18:47:58 -0700 | [diff] [blame] | 6775 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6776 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6777 | /* Since we're passing around handles, adjust nFilledLen and nAllocLen |
| 6778 | * to size of the handle. Do it _after_ handle_extradata() which |
| 6779 | * requires the respective sizes to be accurate. */ |
| 6780 | if (dynamic_buf_mode) { |
| 6781 | buffer->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 6782 | buffer->nFilledLen = buffer->nFilledLen ? |
| 6783 | sizeof(struct VideoDecoderOutputMetaData) : 0; |
| 6784 | } |
| 6785 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6786 | if (m_cb.FillBufferDone) { |
| 6787 | if (buffer->nFilledLen > 0) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6788 | if (arbitrary_bytes) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6789 | adjust_timestamp(buffer->nTimeStamp); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6790 | else |
| 6791 | set_frame_rate(buffer->nTimeStamp); |
| 6792 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6793 | if (perf_flag) { |
| 6794 | if (!proc_frms) { |
| 6795 | dec_time.stop(); |
| 6796 | latency = dec_time.processing_time_us() - latency; |
| 6797 | DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3); |
| 6798 | dec_time.start(); |
| 6799 | fps_metrics.start(); |
| 6800 | } |
| 6801 | proc_frms++; |
| 6802 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6803 | OMX_U64 proc_time = 0; |
| 6804 | fps_metrics.stop(); |
| 6805 | proc_time = fps_metrics.processing_time_us(); |
| 6806 | DEBUG_PRINT_HIGH(">>> FBD Metrics: proc_frms(%lu) proc_time(%.2f)S fps(%.2f)", |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6807 | proc_frms, (float)proc_time / 1e6, |
| 6808 | (float)(1e6 * proc_frms) / proc_time); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6809 | proc_frms = 0; |
| 6810 | } |
| 6811 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6812 | |
| 6813 | #ifdef OUTPUT_EXTRADATA_LOG |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6814 | if (outputExtradataFile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6815 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6816 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL; |
| 6817 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
| 6818 | ((unsigned)(buffer->pBuffer + buffer->nOffset + |
| 6819 | buffer->nFilledLen + 3)&(~3)); |
| 6820 | while (p_extra && |
| 6821 | (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6822 | 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] | 6823 | fwrite (p_extra,1,p_extra->nSize,outputExtradataFile); |
| 6824 | if (p_extra->eType == OMX_ExtraDataNone) { |
| 6825 | break; |
| 6826 | } |
| 6827 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 6828 | } |
| 6829 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6830 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6831 | } |
| 6832 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6833 | prev_ts = LLONG_MAX; |
| 6834 | rst_prev_ts = true; |
| 6835 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6836 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6837 | pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 6838 | ((OMX_QCOM_PLATFORM_PRIVATE_LIST *) |
| 6839 | buffer->pPlatformPrivate)->entryList->entry; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6840 | DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6841 | OMX_BUFFERHEADERTYPE *il_buffer; |
| 6842 | il_buffer = client_buffers.get_il_buf_hdr(buffer); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6843 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6844 | if (il_buffer && m_last_rendered_TS >= 0) { |
| 6845 | int current_framerate = (int)(drv_ctx.frame_rate.fps_numerator /drv_ctx.frame_rate.fps_denominator); |
Manikanta Kanamarlapudi | fb53b26 | 2014-01-20 16:12:47 +0530 | [diff] [blame] | 6846 | 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] | 6847 | |
| 6848 | // Current frame can be send for rendering if |
| 6849 | // (a) current FPS is <= 60 |
| 6850 | // (b) is the next frame after the frame with TS 0 |
| 6851 | // (c) is the first frame after seek |
| 6852 | // (d) the delta TS b\w two consecutive frames is > 16 ms |
| 6853 | // (e) its TS is equal to previous frame TS |
| 6854 | // (f) if marked EOS |
| 6855 | |
| 6856 | if(current_framerate <= 60 || m_last_rendered_TS == 0 || |
| 6857 | il_buffer->nTimeStamp == 0 || ts_delta >= 16000 || |
| 6858 | ts_delta == 0 || (il_buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6859 | m_last_rendered_TS = il_buffer->nTimeStamp; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6860 | } else { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6861 | //mark for droping |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6862 | buffer->nFilledLen = 0; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6863 | } |
| 6864 | |
| 6865 | DEBUG_PRINT_LOW(" -- %s Frame -- info:: fps(%d) lastRenderTime(%lld) bufferTs(%lld) ts_delta(%d)", |
| 6866 | buffer->nFilledLen? "Rendering":"Dropping",current_framerate,m_last_rendered_TS, |
| 6867 | il_buffer->nTimeStamp,ts_delta); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6868 | } |
| 6869 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6870 | if (il_buffer) { |
Arun Menon | 9230eb8 | 2014-02-11 19:19:02 -0800 | [diff] [blame] | 6871 | log_output_buffers(il_buffer); |
| 6872 | if (dynamic_buf_mode) { |
| 6873 | unsigned int nPortIndex = 0; |
| 6874 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6875 | |
| 6876 | if (!secure_mode) { |
| 6877 | munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr, |
| 6878 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size); |
| 6879 | } |
| 6880 | |
| 6881 | //Clear graphic buffer handles in dynamic mode |
| 6882 | native_buffer[nPortIndex].privatehandle = NULL; |
| 6883 | native_buffer[nPortIndex].nativehandle = NULL; |
| 6884 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6885 | m_cb.FillBufferDone (hComp,m_app_data,il_buffer); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6886 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6887 | DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr"); |
| 6888 | return OMX_ErrorBadParameter; |
| 6889 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6890 | DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6891 | } else { |
| 6892 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 6893 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6894 | |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 6895 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 6896 | if (m_smoothstreaming_mode && m_out_mem_ptr) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 6897 | OMX_U32 buf_index = buffer - m_out_mem_ptr; |
| 6898 | BufferDim_t dim; |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 6899 | private_handle_t *private_handle = NULL; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 6900 | if (is_down_scalar_enabled) { |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 6901 | dim.sliceWidth = framesize.nWidth; |
| 6902 | dim.sliceHeight = framesize.nHeight; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 6903 | } else { |
| 6904 | dim.sliceWidth = drv_ctx.video_resolution.frame_width; |
| 6905 | dim.sliceHeight = drv_ctx.video_resolution.frame_height; |
| 6906 | } |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 6907 | if (native_buffer[buf_index].privatehandle) |
| 6908 | private_handle = native_buffer[buf_index].privatehandle; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 6909 | if (private_handle) { |
| 6910 | DEBUG_PRINT_LOW("set metadata: update buf-geometry with stride %d slice %d", |
| 6911 | dim.sliceWidth, dim.sliceHeight); |
| 6912 | setMetaData(private_handle, UPDATE_BUFFER_GEOMETRY, (void*)&dim); |
| 6913 | } |
| 6914 | } |
| 6915 | #endif |
| 6916 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6917 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6918 | } |
| 6919 | |
| 6920 | OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6921 | OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6922 | { |
| 6923 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6924 | 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] | 6925 | DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6926 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6927 | } |
| 6928 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6929 | DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6930 | buffer, buffer->pBuffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6931 | pending_input_buffers--; |
| 6932 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6933 | if (arbitrary_bytes) { |
| 6934 | if (pdest_frame == NULL && input_flush_progress == false) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6935 | 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] | 6936 | pdest_frame = buffer; |
| 6937 | buffer->nFilledLen = 0; |
| 6938 | buffer->nTimeStamp = LLONG_MAX; |
| 6939 | push_input_buffer (hComp); |
| 6940 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6941 | DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6942 | buffer->nFilledLen = 0; |
| 6943 | if (!m_input_free_q.insert_entry((unsigned)buffer, |
| 6944 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6945 | DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6946 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6947 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6948 | } else if (m_cb.EmptyBufferDone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6949 | buffer->nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6950 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6951 | buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr]; |
| 6952 | } |
| 6953 | m_cb.EmptyBufferDone(hComp ,m_app_data, buffer); |
| 6954 | } |
| 6955 | return OMX_ErrorNone; |
| 6956 | } |
| 6957 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6958 | int omx_vdec::async_message_process (void *context, void* message) |
| 6959 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6960 | omx_vdec* omx = NULL; |
| 6961 | struct vdec_msginfo *vdec_msg = NULL; |
| 6962 | OMX_BUFFERHEADERTYPE* omxhdr = NULL; |
| 6963 | struct v4l2_buffer *v4l2_buf_ptr = NULL; |
| 6964 | struct vdec_output_frameinfo *output_respbuf = NULL; |
| 6965 | int rc=1; |
| 6966 | if (context == NULL || message == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6967 | 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] | 6968 | return -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6969 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6970 | vdec_msg = (struct vdec_msginfo *)message; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6971 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6972 | omx = reinterpret_cast<omx_vdec*>(context); |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 6973 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6974 | switch (vdec_msg->msgcode) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6975 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6976 | case VDEC_MSG_EVT_HW_ERROR: |
| 6977 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6978 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
| 6979 | break; |
| 6980 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 6981 | case VDEC_MSG_EVT_HW_OVERLOAD: |
| 6982 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6983 | OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD); |
| 6984 | break; |
| 6985 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6986 | case VDEC_MSG_RESP_START_DONE: |
| 6987 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6988 | OMX_COMPONENT_GENERATE_START_DONE); |
| 6989 | break; |
| 6990 | |
| 6991 | case VDEC_MSG_RESP_STOP_DONE: |
| 6992 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6993 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 6994 | break; |
| 6995 | |
| 6996 | case VDEC_MSG_RESP_RESUME_DONE: |
| 6997 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 6998 | OMX_COMPONENT_GENERATE_RESUME_DONE); |
| 6999 | break; |
| 7000 | |
| 7001 | case VDEC_MSG_RESP_PAUSE_DONE: |
| 7002 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7003 | OMX_COMPONENT_GENERATE_PAUSE_DONE); |
| 7004 | break; |
| 7005 | |
| 7006 | case VDEC_MSG_RESP_FLUSH_INPUT_DONE: |
| 7007 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7008 | OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH); |
| 7009 | break; |
| 7010 | case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE: |
| 7011 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7012 | OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH); |
| 7013 | break; |
| 7014 | case VDEC_MSG_RESP_INPUT_FLUSHED: |
| 7015 | case VDEC_MSG_RESP_INPUT_BUFFER_DONE: |
| 7016 | |
| 7017 | /* omxhdr = (OMX_BUFFERHEADERTYPE* ) |
| 7018 | vdec_msg->msgdata.input_frame_clientdata; */ |
| 7019 | |
| 7020 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata; |
| 7021 | omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index; |
| 7022 | if (omxhdr == NULL || |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7023 | ((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] | 7024 | omxhdr = NULL; |
| 7025 | vdec_msg->status_code = VDEC_S_EFATAL; |
| 7026 | } |
| 7027 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) { |
| 7028 | DEBUG_PRINT_HIGH("Unsupported input"); |
| 7029 | omx->omx_report_error (); |
| 7030 | } |
| 7031 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7032 | vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR; |
| 7033 | } |
| 7034 | omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code, |
| 7035 | OMX_COMPONENT_GENERATE_EBD); |
| 7036 | break; |
| 7037 | case VDEC_MSG_EVT_INFO_FIELD_DROPPED: |
| 7038 | int64_t *timestamp; |
| 7039 | timestamp = (int64_t *) malloc(sizeof(int64_t)); |
| 7040 | if (timestamp) { |
| 7041 | *timestamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7042 | omx->post_event ((unsigned int)timestamp, vdec_msg->status_code, |
| 7043 | OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7044 | DEBUG_PRINT_HIGH("Field dropped time stamp is %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7045 | vdec_msg->msgdata.output_frame.time_stamp); |
| 7046 | } |
| 7047 | break; |
| 7048 | case VDEC_MSG_RESP_OUTPUT_FLUSHED: |
| 7049 | case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE: |
| 7050 | |
| 7051 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data; |
| 7052 | omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7053 | |
| 7054 | DEBUG_PRINT_LOW("[RespBufDone] Buf(%p) Ts(%lld) PicType(%u) Flags (0x%x) FillLen(%u) Crop: L(%u) T(%u) R(%u) B(%u)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7055 | omxhdr, vdec_msg->msgdata.output_frame.time_stamp, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7056 | vdec_msg->msgdata.output_frame.pic_type, v4l2_buf_ptr->flags, |
| 7057 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7058 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7059 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7060 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7061 | vdec_msg->msgdata.output_frame.framesize.bottom); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7062 | |
| 7063 | if (omxhdr && omxhdr->pOutputPortPrivate && |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7064 | ((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] | 7065 | (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7066 | - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7067 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 7068 | if (vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7069 | omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len; |
| 7070 | omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset; |
| 7071 | omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7072 | omxhdr->nFlags = 0; |
| 7073 | |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7074 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7075 | omxhdr->nFlags |= OMX_BUFFERFLAG_EOS; |
| 7076 | //rc = -1; |
| 7077 | } |
| 7078 | if (omxhdr->nFilledLen) { |
| 7079 | omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; |
| 7080 | } |
| 7081 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) { |
| 7082 | omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; |
| 7083 | } else { |
| 7084 | omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME; |
| 7085 | } |
| 7086 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) { |
| 7087 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7088 | } |
| 7089 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) { |
| 7090 | omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY; |
| 7091 | } |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 7092 | |
| 7093 | if (v4l2_buf_ptr->flags & V4L2_MSM_BUF_FLAG_MBAFF) { |
| 7094 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_MBAFF; |
| 7095 | } |
| 7096 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7097 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) { |
Arun Menon | e50f6ef | 2013-09-30 15:08:27 -0700 | [diff] [blame] | 7098 | omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7099 | DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d", |
| 7100 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd); |
| 7101 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7102 | if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) { |
| 7103 | omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd, |
| 7104 | omxhdr->nOffset); |
| 7105 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7106 | if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) && |
| 7107 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) && |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7108 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) { |
Praneeth Paladugu | 17364df | 2013-07-30 11:34:16 -0700 | [diff] [blame] | 7109 | omx->time_stamp_dts.remove_time_stamp( |
| 7110 | omxhdr->nTimeStamp, |
| 7111 | (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 7112 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7113 | omx->post_event ((unsigned)NULL,(unsigned int)omxhdr, |
| 7114 | OMX_COMPONENT_GENERATE_FTB); |
| 7115 | break; |
| 7116 | } |
| 7117 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7118 | omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
| 7119 | } |
| 7120 | vdec_msg->msgdata.output_frame.bufferaddr = |
| 7121 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7122 | |
| 7123 | /* Post event if resolution OR crop changed */ |
| 7124 | /* filled length will be changed if resolution changed */ |
| 7125 | /* Crop parameters can be changed even without resolution change */ |
| 7126 | if (omxhdr->nFilledLen |
| 7127 | && ((omx->prev_n_filled_len != omxhdr->nFilledLen) |
| 7128 | || (omx->drv_ctx.frame_size.left != vdec_msg->msgdata.output_frame.framesize.left) |
| 7129 | || (omx->drv_ctx.frame_size.top != vdec_msg->msgdata.output_frame.framesize.top) |
| 7130 | || (omx->drv_ctx.frame_size.right != vdec_msg->msgdata.output_frame.framesize.right) |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 7131 | || (omx->drv_ctx.frame_size.bottom != vdec_msg->msgdata.output_frame.framesize.bottom) |
| 7132 | || (omx->drv_ctx.video_resolution.frame_width != vdec_msg->msgdata.output_frame.picsize.frame_width) |
| 7133 | || (omx->drv_ctx.video_resolution.frame_height != vdec_msg->msgdata.output_frame.picsize.frame_height) )) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7134 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 7135 | DEBUG_PRINT_HIGH("Paramters Changed From: Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u --> Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u", |
| 7136 | omx->prev_n_filled_len, |
| 7137 | omx->drv_ctx.video_resolution.frame_width, |
| 7138 | omx->drv_ctx.video_resolution.frame_height, |
| 7139 | omx->drv_ctx.frame_size.left, omx->drv_ctx.frame_size.top, |
| 7140 | omx->drv_ctx.frame_size.right, omx->drv_ctx.frame_size.bottom, |
| 7141 | omxhdr->nFilledLen, vdec_msg->msgdata.output_frame.picsize.frame_width, |
| 7142 | vdec_msg->msgdata.output_frame.picsize.frame_height, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7143 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7144 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7145 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7146 | vdec_msg->msgdata.output_frame.framesize.bottom); |
| 7147 | |
Maheshwar Ajja | 0f840ce | 2014-09-29 16:53:42 +0530 | [diff] [blame] | 7148 | omx->drv_ctx.video_resolution.frame_width = |
| 7149 | vdec_msg->msgdata.output_frame.picsize.frame_width; |
| 7150 | omx->drv_ctx.video_resolution.frame_height = |
| 7151 | vdec_msg->msgdata.output_frame.picsize.frame_height; |
| 7152 | |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7153 | memcpy(&omx->drv_ctx.frame_size, |
| 7154 | &vdec_msg->msgdata.output_frame.framesize, |
| 7155 | sizeof(struct vdec_framesize)); |
| 7156 | |
| 7157 | omx->post_event(OMX_CORE_OUTPUT_PORT_INDEX, |
| 7158 | OMX_IndexConfigCommonOutputCrop, |
| 7159 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7160 | } |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7161 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7162 | if (omxhdr->nFilledLen) |
| 7163 | omx->prev_n_filled_len = omxhdr->nFilledLen; |
| 7164 | |
| 7165 | output_respbuf = (struct vdec_output_frameinfo *)\ |
| 7166 | omxhdr->pOutputPortPrivate; |
| 7167 | output_respbuf->len = vdec_msg->msgdata.output_frame.len; |
| 7168 | output_respbuf->offset = vdec_msg->msgdata.output_frame.offset; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7169 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7170 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) { |
| 7171 | output_respbuf->pic_type = PICTURE_TYPE_I; |
| 7172 | } |
| 7173 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) { |
| 7174 | output_respbuf->pic_type = PICTURE_TYPE_P; |
| 7175 | } |
| 7176 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) { |
| 7177 | output_respbuf->pic_type = PICTURE_TYPE_B; |
| 7178 | } |
| 7179 | |
| 7180 | if (omx->output_use_buffer) |
| 7181 | memcpy ( omxhdr->pBuffer, (void *) |
| 7182 | ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr + |
| 7183 | (unsigned long)vdec_msg->msgdata.output_frame.offset), |
| 7184 | vdec_msg->msgdata.output_frame.len); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7185 | } else { |
| 7186 | DEBUG_PRINT_ERROR("Invalid filled length = %u, buffer size = %u, prev_length = %u", |
| 7187 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7188 | omxhdr->nAllocLen, omx->prev_n_filled_len); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7189 | omxhdr->nFilledLen = 0; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7190 | } |
| 7191 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7192 | omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code, |
| 7193 | OMX_COMPONENT_GENERATE_FBD); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7194 | |
| 7195 | } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7196 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7197 | OMX_COMPONENT_GENERATE_EOS_DONE); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7198 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7199 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7200 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7201 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7202 | break; |
| 7203 | case VDEC_MSG_EVT_CONFIG_CHANGED: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7204 | DEBUG_PRINT_HIGH("Port settings changed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7205 | omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition, |
| 7206 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
| 7207 | break; |
| 7208 | default: |
| 7209 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7210 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7211 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7212 | } |
| 7213 | |
| 7214 | OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary ( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7215 | OMX_HANDLETYPE hComp, |
| 7216 | OMX_BUFFERHEADERTYPE *buffer |
| 7217 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7218 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7219 | unsigned address,p2,id; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7220 | DEBUG_PRINT_LOW("Empty this arbitrary"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7221 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7222 | if (buffer == NULL) { |
| 7223 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7224 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7225 | DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 7226 | DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7227 | buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp); |
| 7228 | |
| 7229 | /* return zero length and not an EOS buffer */ |
| 7230 | /* return buffer if input flush in progress */ |
| 7231 | if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) && |
| 7232 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7233 | DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7234 | m_cb.EmptyBufferDone (hComp,m_app_data,buffer); |
| 7235 | return OMX_ErrorNone; |
| 7236 | } |
| 7237 | |
| 7238 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7239 | 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] | 7240 | psource_frame = buffer; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7241 | DEBUG_PRINT_LOW("Try to Push One Input Buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7242 | push_input_buffer (hComp); |
| 7243 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7244 | DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7245 | if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL, |
| 7246 | (unsigned)NULL)) { |
| 7247 | return OMX_ErrorBadParameter; |
| 7248 | } |
| 7249 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7250 | |
Sowmya Pandiri | 302f5ab | 2014-04-03 13:41:03 -0700 | [diff] [blame] | 7251 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 7252 | codec_config_flag = false; |
| 7253 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7254 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7255 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7256 | } |
| 7257 | |
| 7258 | OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp) |
| 7259 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7260 | unsigned address,p2,id; |
| 7261 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7262 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7263 | if (pdest_frame == NULL || psource_frame == NULL) { |
| 7264 | /*Check if we have a destination buffer*/ |
| 7265 | if (pdest_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7266 | DEBUG_PRINT_LOW("Get a Destination buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7267 | if (m_input_free_q.m_size) { |
| 7268 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7269 | pdest_frame = (OMX_BUFFERHEADERTYPE *)address; |
| 7270 | pdest_frame->nFilledLen = 0; |
| 7271 | pdest_frame->nTimeStamp = LLONG_MAX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7272 | DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7273 | } |
| 7274 | } |
| 7275 | |
| 7276 | /*Check if we have a destination buffer*/ |
| 7277 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7278 | DEBUG_PRINT_LOW("Get a source buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7279 | if (m_input_pending_q.m_size) { |
| 7280 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7281 | psource_frame = (OMX_BUFFERHEADERTYPE *)address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7282 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7283 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7284 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7285 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7286 | |
| 7287 | } |
| 7288 | } |
| 7289 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7290 | } |
| 7291 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7292 | while ((pdest_frame != NULL) && (psource_frame != NULL)) { |
| 7293 | switch (codec_type_parse) { |
| 7294 | case CODEC_TYPE_MPEG4: |
| 7295 | case CODEC_TYPE_H263: |
| 7296 | case CODEC_TYPE_MPEG2: |
| 7297 | ret = push_input_sc_codec(hComp); |
| 7298 | break; |
| 7299 | case CODEC_TYPE_H264: |
| 7300 | ret = push_input_h264(hComp); |
| 7301 | break; |
| 7302 | case CODEC_TYPE_VC1: |
| 7303 | ret = push_input_vc1(hComp); |
| 7304 | break; |
| 7305 | default: |
| 7306 | break; |
| 7307 | } |
| 7308 | if (ret != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7309 | DEBUG_PRINT_ERROR("Pushing input Buffer Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7310 | omx_report_error (); |
| 7311 | break; |
| 7312 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7313 | } |
| 7314 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7315 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp) |
| 7319 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7320 | OMX_U32 partial_frame = 1; |
| 7321 | OMX_BOOL generate_ebd = OMX_TRUE; |
| 7322 | unsigned address = 0, p2 = 0, id = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7323 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7324 | DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7325 | psource_frame,psource_frame->nTimeStamp); |
| 7326 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7327 | pdest_frame,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7328 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7329 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7330 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7331 | |
| 7332 | if (partial_frame == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7333 | DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7334 | pdest_frame->nFilledLen,psource_frame,frame_count); |
| 7335 | |
| 7336 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7337 | DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7338 | /*First Parsed buffer will have only header Hence skip*/ |
| 7339 | if (frame_count == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7340 | DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7341 | |
| 7342 | if (codec_type_parse == CODEC_TYPE_MPEG4 || |
| 7343 | codec_type_parse == CODEC_TYPE_DIVX) { |
| 7344 | mp4StreamType psBits; |
| 7345 | psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset; |
| 7346 | psBits.numBytes = pdest_frame->nFilledLen; |
| 7347 | mp4_headerparser.parseHeader(&psBits); |
| 7348 | } |
| 7349 | |
| 7350 | frame_count++; |
| 7351 | } else { |
| 7352 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7353 | if (pdest_frame->nFilledLen) { |
| 7354 | /*Push the frame to the Decoder*/ |
| 7355 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7356 | return OMX_ErrorBadParameter; |
| 7357 | } |
| 7358 | frame_count++; |
| 7359 | pdest_frame = NULL; |
| 7360 | |
| 7361 | if (m_input_free_q.m_size) { |
| 7362 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7363 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
| 7364 | pdest_frame->nFilledLen = 0; |
| 7365 | } |
| 7366 | } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7367 | DEBUG_PRINT_ERROR("Zero len buffer return back to POOL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7368 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL, |
| 7369 | (unsigned)NULL); |
| 7370 | pdest_frame = NULL; |
| 7371 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7372 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7373 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7374 | DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7375 | /*Check if Destination Buffer is full*/ |
| 7376 | if (pdest_frame->nAllocLen == |
| 7377 | pdest_frame->nFilledLen + pdest_frame->nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7378 | DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7379 | return OMX_ErrorStreamCorrupt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7380 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7381 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7382 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7383 | if (psource_frame->nFilledLen == 0) { |
| 7384 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7385 | if (pdest_frame) { |
| 7386 | pdest_frame->nFlags |= psource_frame->nFlags; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7387 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7388 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7389 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7390 | pdest_frame->nFilledLen,frame_count++); |
| 7391 | /*Push the frame to the Decoder*/ |
| 7392 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7393 | return OMX_ErrorBadParameter; |
| 7394 | } |
| 7395 | frame_count++; |
| 7396 | pdest_frame = NULL; |
| 7397 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7398 | DEBUG_PRINT_LOW("Last frame in else dest addr") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7399 | generate_ebd = OMX_FALSE; |
| 7400 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7401 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7402 | if (generate_ebd) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7403 | DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7404 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7405 | psource_frame = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7406 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7407 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7408 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7409 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7410 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7411 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7412 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7413 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7414 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7415 | } |
| 7416 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7417 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7418 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp) |
| 7422 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7423 | OMX_U32 partial_frame = 1; |
| 7424 | unsigned address = 0, p2 = 0, id = 0; |
| 7425 | OMX_BOOL isNewFrame = OMX_FALSE; |
| 7426 | OMX_BOOL generate_ebd = OMX_TRUE; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7427 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7428 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7429 | DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7430 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7431 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7432 | DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7433 | "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7434 | DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7435 | if (h264_scratch.nFilledLen && look_ahead_nal) { |
| 7436 | look_ahead_nal = false; |
| 7437 | if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7438 | h264_scratch.nFilledLen) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7439 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7440 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7441 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7442 | DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7443 | h264_scratch.nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7444 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7445 | DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7446 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7447 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7448 | } |
Praveen Chavan | ce0b5e8 | 2013-08-08 05:23:34 -0700 | [diff] [blame] | 7449 | |
| 7450 | /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result |
| 7451 | in EOS flag getting associated with the destination |
| 7452 | */ |
| 7453 | if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) && |
| 7454 | pdest_frame->nFilledLen) { |
| 7455 | DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'"); |
| 7456 | generate_ebd = OMX_FALSE; |
| 7457 | } |
| 7458 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7459 | if (nal_length == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7460 | DEBUG_PRINT_LOW("Zero NAL, hence parse using start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7461 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7462 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7463 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7464 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7465 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7466 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7467 | 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] | 7468 | if (m_frame_parser.parse_h264_nallength(psource_frame, |
| 7469 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7470 | DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7471 | return OMX_ErrorBadParameter; |
| 7472 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7473 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7474 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7475 | if (partial_frame == 0) { |
| 7476 | if (nal_count == 0 && h264_scratch.nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7477 | DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7478 | nal_count++; |
| 7479 | h264_scratch.nTimeStamp = psource_frame->nTimeStamp; |
| 7480 | h264_scratch.nFlags = psource_frame->nFlags; |
| 7481 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7482 | DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7483 | if (h264_scratch.nFilledLen) { |
| 7484 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen, |
| 7485 | NALU_TYPE_SPS); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7486 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7487 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) |
| 7488 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7489 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
| 7490 | else if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7491 | // If timeinfo is present frame info from SEI is already processed |
| 7492 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7493 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7494 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7495 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7496 | nal_count++; |
| 7497 | if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) { |
| 7498 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7499 | pdest_frame->nFlags = h264_last_au_flags; |
| 7500 | #ifdef PANSCAN_HDLR |
| 7501 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7502 | h264_parser->update_panscan_data(h264_last_au_ts); |
| 7503 | #endif |
| 7504 | } |
| 7505 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR || |
| 7506 | m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) { |
| 7507 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7508 | h264_last_au_flags = h264_scratch.nFlags; |
| 7509 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7510 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7511 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts); |
| 7512 | if (!VALID_TS(h264_last_au_ts)) |
| 7513 | h264_last_au_ts = ts_in_sei; |
| 7514 | } |
| 7515 | #endif |
| 7516 | } else |
| 7517 | h264_last_au_ts = LLONG_MAX; |
| 7518 | } |
| 7519 | |
| 7520 | if (!isNewFrame) { |
| 7521 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7522 | h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7523 | DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7524 | h264_scratch.nFilledLen); |
| 7525 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7526 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7527 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7528 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ) |
| 7529 | pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7530 | h264_scratch.nFilledLen = 0; |
| 7531 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7532 | DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7533 | return OMX_ErrorBadParameter; |
| 7534 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7535 | } else if(h264_scratch.nFilledLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7536 | look_ahead_nal = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7537 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7538 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7539 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7540 | pdest_frame->nFilledLen,frame_count++); |
| 7541 | |
| 7542 | if (pdest_frame->nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7543 | DEBUG_PRINT_LOW("Copy the Current Frame since and push it"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7544 | look_ahead_nal = false; |
| 7545 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7546 | h264_scratch.nFilledLen) { |
| 7547 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7548 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7549 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7550 | h264_scratch.nFilledLen = 0; |
| 7551 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7552 | DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7553 | return OMX_ErrorBadParameter; |
| 7554 | } |
| 7555 | } else { |
| 7556 | if (psource_frame->nFilledLen || h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7557 | DEBUG_PRINT_LOW("Reset the EOS Flag"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7558 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7559 | } |
| 7560 | /*Push the frame to the Decoder*/ |
| 7561 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7562 | return OMX_ErrorBadParameter; |
| 7563 | } |
| 7564 | //frame_count++; |
| 7565 | pdest_frame = NULL; |
| 7566 | if (m_input_free_q.m_size) { |
| 7567 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7568 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7569 | DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7570 | pdest_frame->nFilledLen = 0; |
| 7571 | pdest_frame->nFlags = 0; |
| 7572 | pdest_frame->nTimeStamp = LLONG_MAX; |
| 7573 | } |
| 7574 | } |
| 7575 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7576 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7577 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7578 | 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] | 7579 | /*Check if Destination Buffer is full*/ |
| 7580 | if (h264_scratch.nAllocLen == |
| 7581 | h264_scratch.nFilledLen + h264_scratch.nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7582 | DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7583 | return OMX_ErrorStreamCorrupt; |
| 7584 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7585 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7586 | |
| 7587 | if (!psource_frame->nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7588 | 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] | 7589 | |
| 7590 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7591 | if (pdest_frame) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7592 | DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7593 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7594 | h264_scratch.nFilledLen) { |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7595 | if(pdest_frame->nFilledLen == 0) { |
| 7596 | /* No residual frame from before, send whatever |
| 7597 | * we have left */ |
| 7598 | memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7599 | h264_scratch.pBuffer, h264_scratch.nFilledLen); |
| 7600 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7601 | h264_scratch.nFilledLen = 0; |
| 7602 | pdest_frame->nTimeStamp = h264_scratch.nTimeStamp; |
| 7603 | } else { |
| 7604 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7605 | if(!isNewFrame) { |
| 7606 | /* Have a residual frame, but we know that the |
| 7607 | * AU in this frame is belonging to whatever |
| 7608 | * frame we had left over. So append it */ |
| 7609 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7610 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7611 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7612 | h264_scratch.nFilledLen = 0; |
| 7613 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7614 | } else { |
| 7615 | /* Completely new frame, let's just push what |
| 7616 | * we have now. The resulting EBD would trigger |
| 7617 | * another push */ |
| 7618 | generate_ebd = OMX_FALSE; |
| 7619 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7620 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7621 | } |
| 7622 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7623 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7624 | DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7625 | return OMX_ErrorBadParameter; |
| 7626 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7627 | |
| 7628 | /* Iff we coalesced two buffers, inherit the flags of both bufs */ |
| 7629 | if(generate_ebd == OMX_TRUE) { |
| 7630 | pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags; |
| 7631 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7632 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7633 | DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7634 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7635 | DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7636 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7637 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7638 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp); |
| 7639 | if (!VALID_TS(pdest_frame->nTimeStamp)) |
| 7640 | pdest_frame->nTimeStamp = ts_in_sei; |
| 7641 | } |
| 7642 | #endif |
| 7643 | /*Push the frame to the Decoder*/ |
| 7644 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7645 | return OMX_ErrorBadParameter; |
| 7646 | } |
| 7647 | frame_count++; |
| 7648 | pdest_frame = NULL; |
| 7649 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7650 | DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7651 | pdest_frame,h264_scratch.nFilledLen); |
| 7652 | generate_ebd = OMX_FALSE; |
| 7653 | } |
| 7654 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7655 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7656 | if (generate_ebd && !psource_frame->nFilledLen) { |
| 7657 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7658 | psource_frame = NULL; |
| 7659 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7660 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7661 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7662 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7663 | DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7664 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7665 | } |
| 7666 | } |
| 7667 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7668 | } |
| 7669 | |
| 7670 | OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp) |
| 7671 | { |
| 7672 | OMX_U8 *buf, *pdest; |
| 7673 | OMX_U32 partial_frame = 1; |
| 7674 | OMX_U32 buf_len, dest_len; |
| 7675 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7676 | if (first_frame == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7677 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7678 | DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7679 | if (!m_vendor_config.pData) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7680 | DEBUG_PRINT_LOW("Check profile type in 1st source buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7681 | buf = psource_frame->pBuffer; |
| 7682 | buf_len = psource_frame->nFilledLen; |
| 7683 | |
| 7684 | if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) == |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7685 | VC1_SP_MP_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7686 | m_vc1_profile = VC1_SP_MP_RCV; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7687 | } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7688 | m_vc1_profile = VC1_AP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7689 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7690 | DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7691 | return OMX_ErrorStreamCorrupt; |
| 7692 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7693 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7694 | pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen + |
| 7695 | pdest_frame->nOffset; |
| 7696 | dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen + |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7697 | pdest_frame->nOffset); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7698 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7699 | if (dest_len < m_vendor_config.nDataSize) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7700 | DEBUG_PRINT_ERROR("Destination buffer full"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7701 | return OMX_ErrorBadParameter; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7702 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7703 | memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize); |
| 7704 | pdest_frame->nFilledLen += m_vendor_config.nDataSize; |
| 7705 | } |
| 7706 | } |
| 7707 | } |
| 7708 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7709 | switch (m_vc1_profile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7710 | case VC1_AP: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7711 | DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7712 | if (push_input_sc_codec(hComp) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7713 | DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7714 | return OMX_ErrorBadParameter; |
| 7715 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7716 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7717 | |
| 7718 | case VC1_SP_MP_RCV: |
| 7719 | default: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7720 | DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7721 | return OMX_ErrorBadParameter; |
| 7722 | } |
| 7723 | return OMX_ErrorNone; |
| 7724 | } |
| 7725 | |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7726 | #ifndef USE_ION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7727 | 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] | 7728 | OMX_U32 alignment) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7729 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7730 | struct pmem_allocation allocation; |
| 7731 | allocation.size = buffer_size; |
| 7732 | allocation.align = clip2(alignment); |
| 7733 | if (allocation.align < 4096) { |
| 7734 | allocation.align = 4096; |
| 7735 | } |
| 7736 | if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7737 | DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7738 | allocation.align, allocation.size); |
| 7739 | return false; |
| 7740 | } |
| 7741 | return true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7742 | } |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7743 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7744 | #ifdef USE_ION |
| 7745 | int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7746 | OMX_U32 alignment, struct ion_allocation_data *alloc_data, |
| 7747 | struct ion_fd_data *fd_data, int flag) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7748 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7749 | int fd = -EINVAL; |
| 7750 | int rc = -EINVAL; |
| 7751 | int ion_dev_flag; |
| 7752 | struct vdec_ion ion_buf_info; |
| 7753 | if (!alloc_data || buffer_size <= 0 || !fd_data) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7754 | DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7755 | return -EINVAL; |
| 7756 | } |
| 7757 | ion_dev_flag = O_RDONLY; |
| 7758 | fd = open (MEM_DEVICE, ion_dev_flag); |
| 7759 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7760 | DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7761 | return fd; |
| 7762 | } |
| 7763 | alloc_data->flags = 0; |
| 7764 | if (!secure_mode && (flag & ION_FLAG_CACHED)) { |
| 7765 | alloc_data->flags |= ION_FLAG_CACHED; |
| 7766 | } |
| 7767 | alloc_data->len = buffer_size; |
| 7768 | alloc_data->align = clip2(alignment); |
| 7769 | if (alloc_data->align < 4096) { |
| 7770 | alloc_data->align = 4096; |
| 7771 | } |
| 7772 | if ((secure_mode) && (flag & ION_SECURE)) |
| 7773 | alloc_data->flags |= ION_SECURE; |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 7774 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7775 | alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 7776 | if (secure_mode && (alloc_data->flags & ION_SECURE)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7777 | alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID); |
| 7778 | rc = ioctl(fd,ION_IOC_ALLOC,alloc_data); |
| 7779 | if (rc || !alloc_data->handle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7780 | DEBUG_PRINT_ERROR("ION ALLOC memory failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7781 | alloc_data->handle = NULL; |
| 7782 | close(fd); |
| 7783 | fd = -ENOMEM; |
| 7784 | return fd; |
| 7785 | } |
| 7786 | fd_data->handle = alloc_data->handle; |
| 7787 | rc = ioctl(fd,ION_IOC_MAP,fd_data); |
| 7788 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7789 | DEBUG_PRINT_ERROR("ION MAP failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7790 | ion_buf_info.ion_alloc_data = *alloc_data; |
| 7791 | ion_buf_info.ion_device_fd = fd; |
| 7792 | ion_buf_info.fd_ion_data = *fd_data; |
| 7793 | free_ion_memory(&ion_buf_info); |
| 7794 | fd_data->fd =-1; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7795 | fd = -ENOMEM; |
| 7796 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7797 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7798 | return fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7799 | } |
| 7800 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7801 | void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info) |
| 7802 | { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7803 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7804 | if (!buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7805 | DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7806 | return; |
| 7807 | } |
| 7808 | if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE, |
| 7809 | &buf_ion_info->ion_alloc_data.handle)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7810 | DEBUG_PRINT_ERROR("ION: free failed" ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7811 | } |
| 7812 | close(buf_ion_info->ion_device_fd); |
| 7813 | buf_ion_info->ion_device_fd = -1; |
| 7814 | buf_ion_info->ion_alloc_data.handle = NULL; |
| 7815 | buf_ion_info->fd_ion_data.fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7816 | } |
| 7817 | #endif |
| 7818 | void omx_vdec::free_output_buffer_header() |
| 7819 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7820 | DEBUG_PRINT_HIGH("ALL output buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7821 | output_use_buffer = false; |
| 7822 | ouput_egl_buffers = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7823 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7824 | if (m_out_mem_ptr) { |
| 7825 | free (m_out_mem_ptr); |
| 7826 | m_out_mem_ptr = NULL; |
| 7827 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7828 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7829 | if (m_platform_list) { |
| 7830 | free(m_platform_list); |
| 7831 | m_platform_list = NULL; |
| 7832 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7833 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7834 | if (drv_ctx.ptr_respbuffer) { |
| 7835 | free (drv_ctx.ptr_respbuffer); |
| 7836 | drv_ctx.ptr_respbuffer = NULL; |
| 7837 | } |
| 7838 | if (drv_ctx.ptr_outputbuffer) { |
| 7839 | free (drv_ctx.ptr_outputbuffer); |
| 7840 | drv_ctx.ptr_outputbuffer = NULL; |
| 7841 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7842 | #ifdef USE_ION |
| 7843 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7844 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7845 | free(drv_ctx.op_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7846 | drv_ctx.op_buf_ion_info = NULL; |
| 7847 | } |
| 7848 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7849 | if (out_dynamic_list) { |
| 7850 | free(out_dynamic_list); |
| 7851 | out_dynamic_list = NULL; |
| 7852 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7853 | } |
| 7854 | |
| 7855 | void omx_vdec::free_input_buffer_header() |
| 7856 | { |
| 7857 | input_use_buffer = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7858 | if (arbitrary_bytes) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7859 | if (m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7860 | DEBUG_PRINT_LOW("Free input Heap Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7861 | free (m_inp_heap_ptr); |
| 7862 | m_inp_heap_ptr = NULL; |
| 7863 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7864 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7865 | if (m_phdr_pmem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7866 | DEBUG_PRINT_LOW("Free input pmem header Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7867 | free (m_phdr_pmem_ptr); |
| 7868 | m_phdr_pmem_ptr = NULL; |
| 7869 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7870 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7871 | if (m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7872 | DEBUG_PRINT_LOW("Free input pmem Pointer area"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7873 | free (m_inp_mem_ptr); |
| 7874 | m_inp_mem_ptr = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7875 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 7876 | /* We just freed all the buffer headers, every thing in m_input_free_q, |
| 7877 | * m_input_pending_q, pdest_frame, and psource_frame is now invalid */ |
Leena Winterrowd | 1d2424a | 2013-08-20 15:26:02 -0700 | [diff] [blame] | 7878 | while (m_input_free_q.m_size) { |
| 7879 | unsigned address, p2, id; |
| 7880 | m_input_free_q.pop_entry(&address, &p2, &id); |
| 7881 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 7882 | while (m_input_pending_q.m_size) { |
| 7883 | unsigned address, p2, id; |
| 7884 | m_input_pending_q.pop_entry(&address, &p2, &id); |
| 7885 | } |
| 7886 | pdest_frame = NULL; |
| 7887 | psource_frame = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7888 | if (drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7889 | DEBUG_PRINT_LOW("Free Driver Context pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7890 | free (drv_ctx.ptr_inputbuffer); |
| 7891 | drv_ctx.ptr_inputbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7892 | } |
| 7893 | #ifdef USE_ION |
| 7894 | if (drv_ctx.ip_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7895 | DEBUG_PRINT_LOW("Free ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7896 | free(drv_ctx.ip_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7897 | drv_ctx.ip_buf_ion_info = NULL; |
| 7898 | } |
| 7899 | #endif |
| 7900 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7901 | |
| 7902 | int omx_vdec::stream_off(OMX_U32 port) |
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 | enum v4l2_buf_type btype; |
| 7905 | int rc = 0; |
| 7906 | enum v4l2_ports v4l2_port = OUTPUT_PORT; |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7907 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7908 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 7909 | btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7910 | v4l2_port = OUTPUT_PORT; |
| 7911 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 7912 | btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7913 | v4l2_port = CAPTURE_PORT; |
| 7914 | } else if (port == OMX_ALL) { |
| 7915 | int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX); |
| 7916 | int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7917 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7918 | if (!rc_input) |
| 7919 | return rc_input; |
| 7920 | else |
| 7921 | return rc_output; |
| 7922 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7923 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7924 | if (!streaming[v4l2_port]) { |
| 7925 | // already streamed off, warn and move on |
| 7926 | DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port," |
| 7927 | " which is already streamed off", v4l2_port); |
| 7928 | return 0; |
| 7929 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7930 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7931 | DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7932 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7933 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype); |
| 7934 | if (rc) { |
| 7935 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7936 | DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7937 | } else { |
| 7938 | streaming[v4l2_port] = false; |
| 7939 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 7940 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7941 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7942 | } |
| 7943 | |
| 7944 | OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 7945 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7946 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 7947 | struct v4l2_requestbuffers bufreq; |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 7948 | 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] | 7949 | unsigned int final_extra_data_size = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7950 | struct v4l2_format fmt; |
| 7951 | int ret = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7952 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7953 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 7954 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 7955 | bufreq.count = 1; |
| 7956 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 7957 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7958 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 7959 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 7960 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 7961 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7962 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 7963 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 7964 | } else { |
| 7965 | eRet = OMX_ErrorBadParameter; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 7966 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7967 | if (eRet==OMX_ErrorNone) { |
| 7968 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7969 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7970 | if (ret) { |
| 7971 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 7972 | /*TODO: How to handle this case */ |
| 7973 | eRet = OMX_ErrorInsufficientResources; |
| 7974 | return eRet; |
| 7975 | } else { |
| 7976 | buffer_prop->actualcount = bufreq.count; |
| 7977 | buffer_prop->mincount = bufreq.count; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7978 | DEBUG_PRINT_HIGH("Count = %d",bufreq.count); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7979 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7980 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
| 7981 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 7982 | |
| 7983 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 7984 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 7985 | |
| 7986 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 7987 | |
| 7988 | update_resolution(fmt.fmt.pix_mp.width, |
| 7989 | fmt.fmt.pix_mp.height, |
| 7990 | fmt.fmt.pix_mp.plane_fmt[0].bytesperline, |
| 7991 | fmt.fmt.pix_mp.plane_fmt[0].reserved[0]); |
| 7992 | if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 7993 | drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7994 | 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] | 7995 | |
| 7996 | if (ret) { |
| 7997 | /*TODO: How to handle this case */ |
| 7998 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 7999 | eRet = OMX_ErrorInsufficientResources; |
| 8000 | } else { |
| 8001 | int extra_idx = 0; |
| 8002 | |
| 8003 | eRet = is_video_session_supported(); |
| 8004 | if (eRet) |
| 8005 | return eRet; |
| 8006 | |
| 8007 | buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage; |
| 8008 | buf_size = buffer_prop->buffer_size; |
| 8009 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 8010 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 8011 | extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage; |
| 8012 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8013 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8014 | return OMX_ErrorBadParameter; |
| 8015 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8016 | |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 8017 | default_extra_data_size = VENUS_EXTRADATA_SIZE( |
| 8018 | drv_ctx.video_resolution.frame_height, |
| 8019 | drv_ctx.video_resolution.frame_width); |
| 8020 | final_extra_data_size = extra_data_size > default_extra_data_size ? |
| 8021 | extra_data_size : default_extra_data_size; |
| 8022 | |
| 8023 | final_extra_data_size = (final_extra_data_size + buffer_prop->alignment - 1) & |
| 8024 | (~(buffer_prop->alignment - 1)); |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 8025 | |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8026 | drv_ctx.extradata_info.size = buffer_prop->actualcount * final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8027 | drv_ctx.extradata_info.count = buffer_prop->actualcount; |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8028 | drv_ctx.extradata_info.buffer_size = final_extra_data_size; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8029 | if (!secure_mode) |
| 8030 | buf_size += final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8031 | buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8032 | DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)", |
| 8033 | buffer_prop->actualcount, buffer_prop->buffer_size, buf_size); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8034 | if (extra_data_size) |
| 8035 | DEBUG_PRINT_LOW("GetBufReq UPDATE: extradata: TotalSize(%d) BufferSize(%d)", |
| 8036 | drv_ctx.extradata_info.size, drv_ctx.extradata_info.buffer_size); |
| 8037 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8038 | if (in_reconfig) // BufReq will be set to driver when port is disabled |
| 8039 | buffer_prop->buffer_size = buf_size; |
| 8040 | else if (buf_size != buffer_prop->buffer_size) { |
| 8041 | buffer_prop->buffer_size = buf_size; |
| 8042 | eRet = set_buffer_req(buffer_prop); |
| 8043 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8044 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8045 | DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)", |
| 8046 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8047 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8048 | } |
| 8049 | |
| 8050 | OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 8051 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8052 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8053 | unsigned buf_size = 0; |
| 8054 | struct v4l2_format fmt; |
| 8055 | struct v4l2_requestbuffers bufreq; |
| 8056 | int ret; |
| 8057 | DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)", |
| 8058 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8059 | buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8060 | if (buf_size != buffer_prop->buffer_size) { |
| 8061 | DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)", |
| 8062 | buffer_prop->buffer_size, buf_size); |
| 8063 | eRet = OMX_ErrorBadParameter; |
| 8064 | } else { |
| 8065 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 8066 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8067 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8068 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8069 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8070 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Shalaj Jain | d3902bb | 2013-10-07 12:42:55 -0700 | [diff] [blame] | 8071 | fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8072 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8073 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8074 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 8075 | } else { |
| 8076 | eRet = OMX_ErrorBadParameter; |
| 8077 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8078 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8079 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 8080 | if (ret) { |
| 8081 | /*TODO: How to handle this case */ |
| 8082 | DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret); |
| 8083 | eRet = OMX_ErrorInsufficientResources; |
| 8084 | } |
| 8085 | |
| 8086 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 8087 | bufreq.count = buffer_prop->actualcount; |
| 8088 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8089 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8090 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8091 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8092 | } else { |
| 8093 | eRet = OMX_ErrorBadParameter; |
| 8094 | } |
| 8095 | |
| 8096 | if (eRet==OMX_ErrorNone) { |
| 8097 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
| 8098 | } |
| 8099 | |
| 8100 | if (ret) { |
| 8101 | DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret); |
| 8102 | /*TODO: How to handle this case */ |
| 8103 | eRet = OMX_ErrorInsufficientResources; |
| 8104 | } else if (bufreq.count < buffer_prop->actualcount) { |
| 8105 | DEBUG_PRINT_ERROR("Driver refused to change the number of buffers" |
| 8106 | " on v4l2 port %d to %d (prefers %d)", bufreq.type, |
| 8107 | buffer_prop->actualcount, bufreq.count); |
| 8108 | eRet = OMX_ErrorInsufficientResources; |
| 8109 | } else { |
| 8110 | if (!client_buffers.update_buffer_req()) { |
| 8111 | DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed"); |
| 8112 | eRet = OMX_ErrorInsufficientResources; |
| 8113 | } |
| 8114 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8115 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8116 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8117 | } |
| 8118 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8119 | OMX_ERRORTYPE omx_vdec::update_picture_resolution() |
| 8120 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8121 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8122 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8123 | } |
| 8124 | |
| 8125 | OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn) |
| 8126 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8127 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8128 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8129 | if (!portDefn) { |
| 8130 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8131 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8132 | DEBUG_PRINT_LOW("omx_vdec::update_portdef"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8133 | portDefn->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8134 | portDefn->nSize = sizeof(portDefn); |
| 8135 | portDefn->eDomain = OMX_PortDomainVideo; |
| 8136 | if (drv_ctx.frame_rate.fps_denominator > 0) |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 8137 | portDefn->format.video.xFramerate = (drv_ctx.frame_rate.fps_numerator / |
| 8138 | drv_ctx.frame_rate.fps_denominator) << 16; //Q16 format |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8139 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8140 | DEBUG_PRINT_ERROR("Error: Divide by zero"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8141 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8142 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8143 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8144 | if (0 == portDefn->nPortIndex) { |
| 8145 | portDefn->eDir = OMX_DirInput; |
| 8146 | portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount; |
| 8147 | portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount; |
| 8148 | portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size; |
| 8149 | portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused; |
| 8150 | portDefn->format.video.eCompressionFormat = eCompressionFormat; |
| 8151 | portDefn->bEnabled = m_inp_bEnabled; |
| 8152 | portDefn->bPopulated = m_inp_bPopulated; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8153 | |
| 8154 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8155 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8156 | } else if (1 == portDefn->nPortIndex) { |
| 8157 | unsigned int buf_size = 0; |
| 8158 | if (!client_buffers.update_buffer_req()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8159 | DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8160 | return OMX_ErrorHardware; |
| 8161 | } |
| 8162 | if (!client_buffers.get_buffer_req(buf_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8163 | DEBUG_PRINT_ERROR("update buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8164 | return OMX_ErrorHardware; |
| 8165 | } |
| 8166 | portDefn->nBufferSize = buf_size; |
| 8167 | portDefn->eDir = OMX_DirOutput; |
| 8168 | portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount; |
| 8169 | portDefn->nBufferCountMin = drv_ctx.op_buf.mincount; |
| 8170 | portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 8171 | portDefn->bEnabled = m_out_bEnabled; |
| 8172 | portDefn->bPopulated = m_out_bPopulated; |
| 8173 | if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8174 | DEBUG_PRINT_ERROR("Error in getting color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8175 | return OMX_ErrorHardware; |
| 8176 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8177 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8178 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8179 | } else { |
| 8180 | portDefn->eDir = OMX_DirMax; |
| 8181 | DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d", |
| 8182 | (int)portDefn->nPortIndex); |
| 8183 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8184 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8185 | if (is_down_scalar_enabled) { |
| 8186 | int ret = 0; |
| 8187 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 8188 | if (ret) { |
| 8189 | DEBUG_PRINT_ERROR("update_portdef : Error in getting port resolution"); |
| 8190 | return OMX_ErrorHardware; |
| 8191 | } else { |
| 8192 | portDefn->format.video.nFrameWidth = fmt.fmt.pix_mp.width; |
| 8193 | portDefn->format.video.nFrameHeight = fmt.fmt.pix_mp.height; |
| 8194 | portDefn->format.video.nStride = fmt.fmt.pix_mp.plane_fmt[0].bytesperline; |
| 8195 | portDefn->format.video.nSliceHeight = fmt.fmt.pix_mp.plane_fmt[0].reserved[0]; |
| 8196 | } |
| 8197 | } else { |
| 8198 | portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height; |
| 8199 | portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width; |
| 8200 | portDefn->format.video.nStride = drv_ctx.video_resolution.stride; |
| 8201 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines; |
| 8202 | } |
| 8203 | |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 8204 | if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 8205 | (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) { |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8206 | portDefn->format.video.nStride = drv_ctx.video_resolution.frame_width; |
| 8207 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height; |
| 8208 | } |
| 8209 | DEBUG_PRINT_HIGH("update_portdef(%lu): Width = %lu Height = %lu Stride = %ld " |
| 8210 | "SliceHeight = %lu eColorFormat = %lu nBufSize %lu nBufCnt %lu", |
| 8211 | portDefn->nPortIndex, |
| 8212 | portDefn->format.video.nFrameWidth, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8213 | portDefn->format.video.nFrameHeight, |
| 8214 | portDefn->format.video.nStride, |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8215 | portDefn->format.video.nSliceHeight, |
| 8216 | portDefn->format.video.eColorFormat, |
| 8217 | portDefn->nBufferSize, |
| 8218 | portDefn->nBufferCountActual); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8219 | |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8220 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8221 | } |
| 8222 | |
| 8223 | OMX_ERRORTYPE omx_vdec::allocate_output_headers() |
| 8224 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8225 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8226 | OMX_BUFFERHEADERTYPE *bufHdr = NULL; |
| 8227 | unsigned i= 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8228 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8229 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8230 | DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8231 | int nBufHdrSize = 0; |
| 8232 | int nPlatformEntrySize = 0; |
| 8233 | int nPlatformListSize = 0; |
| 8234 | int nPMEMInfoSize = 0; |
| 8235 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 8236 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 8237 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8238 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8239 | DEBUG_PRINT_LOW("Setting First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8240 | drv_ctx.op_buf.actualcount); |
| 8241 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 8242 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8243 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8244 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 8245 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 8246 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 8247 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 8248 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 8249 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8250 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8251 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8252 | sizeof(OMX_BUFFERHEADERTYPE), |
| 8253 | nPMEMInfoSize, |
| 8254 | nPlatformListSize); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8255 | DEBUG_PRINT_LOW("PE %d bmSize %d",nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8256 | m_out_bm_count); |
| 8257 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 8258 | // Alloc mem for platform specific info |
| 8259 | char *pPtr=NULL; |
| 8260 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 8261 | nPMEMInfoSize,1); |
| 8262 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \ |
| 8263 | calloc (sizeof(struct vdec_bufferpayload), |
| 8264 | drv_ctx.op_buf.actualcount); |
| 8265 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 8266 | calloc (sizeof (struct vdec_output_frameinfo), |
| 8267 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8268 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 8269 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer"); |
| 8270 | return OMX_ErrorInsufficientResources; |
| 8271 | } |
| 8272 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8273 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8274 | drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \ |
| 8275 | calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8276 | if (!drv_ctx.op_buf_ion_info) { |
| 8277 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 8278 | return OMX_ErrorInsufficientResources; |
| 8279 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8280 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8281 | if (dynamic_buf_mode) { |
| 8282 | out_dynamic_list = (struct dynamic_buf_list *) \ |
| 8283 | calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount); |
| 8284 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8285 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 8286 | && drv_ctx.ptr_respbuffer) { |
| 8287 | bufHdr = m_out_mem_ptr; |
| 8288 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 8289 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 8290 | (((char *) m_platform_list) + nPlatformListSize); |
| 8291 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 8292 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 8293 | pPlatformList = m_platform_list; |
| 8294 | pPlatformEntry = m_platform_entry; |
| 8295 | pPMEMInfo = m_pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8296 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8297 | 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] | 8298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8299 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8300 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8301 | m_out_mem_ptr,pPlatformEntry); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8302 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8303 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 8304 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 8305 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8306 | // Set the values when we determine the right HxW param |
| 8307 | bufHdr->nAllocLen = 0; |
| 8308 | bufHdr->nFilledLen = 0; |
| 8309 | bufHdr->pAppPrivate = NULL; |
| 8310 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8311 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 8312 | pPlatformEntry->entry = pPMEMInfo; |
| 8313 | // Initialize the Platform List |
| 8314 | pPlatformList->nEntries = 1; |
| 8315 | pPlatformList->entryList = pPlatformEntry; |
| 8316 | // Keep pBuffer NULL till vdec is opened |
| 8317 | bufHdr->pBuffer = NULL; |
| 8318 | pPMEMInfo->offset = 0; |
| 8319 | pPMEMInfo->pmem_fd = 0; |
| 8320 | bufHdr->pPlatformPrivate = pPlatformList; |
| 8321 | drv_ctx.ptr_outputbuffer[i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8322 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8323 | drv_ctx.op_buf_ion_info[i].ion_device_fd =-1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8324 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8325 | /*Create a mapping between buffers*/ |
| 8326 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 8327 | drv_ctx.ptr_respbuffer[i].client_data = (void *) \ |
| 8328 | &drv_ctx.ptr_outputbuffer[i]; |
| 8329 | // Move the buffer and buffer header pointers |
| 8330 | bufHdr++; |
| 8331 | pPMEMInfo++; |
| 8332 | pPlatformEntry++; |
| 8333 | pPlatformList++; |
| 8334 | } |
| 8335 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8336 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8337 | m_out_mem_ptr, pPtr); |
| 8338 | if (m_out_mem_ptr) { |
| 8339 | free(m_out_mem_ptr); |
| 8340 | m_out_mem_ptr = NULL; |
| 8341 | } |
| 8342 | if (pPtr) { |
| 8343 | free(pPtr); |
| 8344 | pPtr = NULL; |
| 8345 | } |
| 8346 | if (drv_ctx.ptr_outputbuffer) { |
| 8347 | free(drv_ctx.ptr_outputbuffer); |
| 8348 | drv_ctx.ptr_outputbuffer = NULL; |
| 8349 | } |
| 8350 | if (drv_ctx.ptr_respbuffer) { |
| 8351 | free(drv_ctx.ptr_respbuffer); |
| 8352 | drv_ctx.ptr_respbuffer = NULL; |
| 8353 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8354 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8355 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8356 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8357 | free(drv_ctx.op_buf_ion_info); |
| 8358 | drv_ctx.op_buf_ion_info = NULL; |
| 8359 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8360 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8361 | eRet = OMX_ErrorInsufficientResources; |
| 8362 | } |
| 8363 | } else { |
| 8364 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8365 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8366 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8367 | } |
| 8368 | |
| 8369 | void omx_vdec::complete_pending_buffer_done_cbs() |
| 8370 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8371 | unsigned p1; |
| 8372 | unsigned p2; |
| 8373 | unsigned ident; |
| 8374 | omx_cmd_queue tmp_q, pending_bd_q; |
| 8375 | pthread_mutex_lock(&m_lock); |
| 8376 | // pop all pending GENERATE FDB from ftb queue |
| 8377 | while (m_ftb_q.m_size) { |
| 8378 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
| 8379 | if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 8380 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8381 | } else { |
| 8382 | tmp_q.insert_entry(p1,p2,ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8383 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8384 | } |
| 8385 | //return all non GENERATE FDB to ftb queue |
| 8386 | while (tmp_q.m_size) { |
| 8387 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8388 | m_ftb_q.insert_entry(p1,p2,ident); |
| 8389 | } |
| 8390 | // pop all pending GENERATE EDB from etb queue |
| 8391 | while (m_etb_q.m_size) { |
| 8392 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 8393 | if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 8394 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8395 | } else { |
| 8396 | tmp_q.insert_entry(p1,p2,ident); |
| 8397 | } |
| 8398 | } |
| 8399 | //return all non GENERATE FDB to etb queue |
| 8400 | while (tmp_q.m_size) { |
| 8401 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8402 | m_etb_q.insert_entry(p1,p2,ident); |
| 8403 | } |
| 8404 | pthread_mutex_unlock(&m_lock); |
| 8405 | // process all pending buffer dones |
| 8406 | while (pending_bd_q.m_size) { |
| 8407 | pending_bd_q.pop_entry(&p1,&p2,&ident); |
| 8408 | switch (ident) { |
| 8409 | case OMX_COMPONENT_GENERATE_EBD: |
| 8410 | if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8411 | DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8412 | omx_report_error (); |
| 8413 | } |
| 8414 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8415 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8416 | case OMX_COMPONENT_GENERATE_FBD: |
| 8417 | if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8418 | DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8419 | omx_report_error (); |
| 8420 | } |
| 8421 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8422 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8423 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8424 | } |
| 8425 | |
| 8426 | void omx_vdec::set_frame_rate(OMX_S64 act_timestamp) |
| 8427 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8428 | OMX_U32 new_frame_interval = 0; |
| 8429 | if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts |
| 8430 | && llabs(act_timestamp - prev_ts) > 2000) { |
| 8431 | new_frame_interval = client_set_fps ? frm_int : |
| 8432 | llabs(act_timestamp - prev_ts); |
Arun Menon | d9e49f8 | 2014-04-23 18:50:26 -0700 | [diff] [blame] | 8433 | if (new_frame_interval != frm_int || frm_int == 0) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8434 | frm_int = new_frame_interval; |
| 8435 | if (frm_int) { |
| 8436 | drv_ctx.frame_rate.fps_numerator = 1e6; |
| 8437 | drv_ctx.frame_rate.fps_denominator = frm_int; |
| 8438 | DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)", |
| 8439 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 8440 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8441 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8442 | /* We need to report the difference between this FBD and the previous FBD |
| 8443 | * back to the driver for clock scaling purposes. */ |
| 8444 | struct v4l2_outputparm oparm; |
| 8445 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 8446 | * per second.*/ |
| 8447 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 8448 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8449 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8450 | struct v4l2_streamparm sparm; |
| 8451 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8452 | sparm.parm.output = oparm; |
| 8453 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 8454 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 8455 | performance might be affected"); |
| 8456 | } |
| 8457 | |
| 8458 | } |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8459 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8460 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8461 | prev_ts = act_timestamp; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8462 | } |
| 8463 | |
| 8464 | void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp) |
| 8465 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8466 | if (rst_prev_ts && VALID_TS(act_timestamp)) { |
| 8467 | prev_ts = act_timestamp; |
| 8468 | rst_prev_ts = false; |
| 8469 | } else if (VALID_TS(prev_ts)) { |
| 8470 | bool codec_cond = (drv_ctx.timestamp_adjust)? |
| 8471 | (!VALID_TS(act_timestamp) || (((act_timestamp > prev_ts)? |
| 8472 | (act_timestamp - prev_ts):(prev_ts - act_timestamp)) <= 2000)): |
| 8473 | (!VALID_TS(act_timestamp) || act_timestamp == prev_ts); |
| 8474 | if (frm_int > 0 && codec_cond) { |
| 8475 | DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp); |
| 8476 | act_timestamp = prev_ts + frm_int; |
| 8477 | DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp); |
| 8478 | prev_ts = act_timestamp; |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8479 | } else { |
| 8480 | if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) { |
| 8481 | // ensure that timestamps can never step backwards when in display order |
| 8482 | act_timestamp = prev_ts; |
| 8483 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8484 | set_frame_rate(act_timestamp); |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8485 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8486 | } else if (frm_int > 0) // In this case the frame rate was set along |
| 8487 | { // with the port definition, start ts with 0 |
| 8488 | act_timestamp = prev_ts = 0; // and correct if a valid ts is received. |
| 8489 | rst_prev_ts = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8490 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8491 | } |
| 8492 | |
| 8493 | void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 8494 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8495 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL; |
| 8496 | OMX_U32 num_conceal_MB = 0; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8497 | OMX_TICKS time_stamp = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8498 | OMX_U32 frame_rate = 0; |
| 8499 | int consumed_len = 0; |
| 8500 | OMX_U32 num_MB_in_frame; |
| 8501 | OMX_U32 recovery_sei_flags = 1; |
| 8502 | int enable = 0; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8503 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8504 | int buf_index = p_buf_hdr - m_out_mem_ptr; |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 8505 | if (buf_index >= drv_ctx.extradata_info.count) { |
| 8506 | DEBUG_PRINT_ERROR("handle_extradata: invalid index(%d) max(%d)", |
| 8507 | buf_index, drv_ctx.extradata_info.count); |
| 8508 | return; |
| 8509 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8510 | struct msm_vidc_panscan_window_payload *panscan_payload = NULL; |
| 8511 | OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) + |
| 8512 | p_buf_hdr->nOffset; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8513 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8514 | if (!drv_ctx.extradata_info.uaddr) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8515 | DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8516 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8517 | } |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8518 | |
| 8519 | if (!secure_mode && (drv_ctx.extradata_info.buffer_size > (p_buf_hdr->nAllocLen - p_buf_hdr->nFilledLen)) ) { |
| 8520 | DEBUG_PRINT_ERROR("Error: Insufficient size allocated for extra-data"); |
| 8521 | p_extra = NULL; |
| 8522 | return; |
| 8523 | } |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8524 | if (!secure_mode) |
| 8525 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8526 | ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3)); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8527 | else |
| 8528 | p_extra = m_other_extradata; |
| 8529 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8530 | 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] | 8531 | if (!secure_mode && ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))) { |
| 8532 | DEBUG_PRINT_ERROR("Error: out of bound memory access by p_extra"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8533 | p_extra = NULL; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8534 | return; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8535 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8536 | OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8537 | if (data && p_extra) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8538 | while ((consumed_len < drv_ctx.extradata_info.buffer_size) |
| 8539 | && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 8540 | if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8541 | DEBUG_PRINT_LOW("Invalid extra data size"); |
| 8542 | break; |
| 8543 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8544 | DEBUG_PRINT_LOW("handle_extradata: eType = %d", data->eType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8545 | switch ((unsigned long)data->eType) { |
| 8546 | case EXTRADATA_INTERLACE_VIDEO: |
| 8547 | struct msm_vidc_interlace_payload *payload; |
| 8548 | payload = (struct msm_vidc_interlace_payload *)data->data; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8549 | if (payload) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8550 | enable = 1; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8551 | switch (payload->format) { |
| 8552 | case INTERLACE_FRAME_PROGRESSIVE: |
| 8553 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 8554 | enable = 0; |
| 8555 | break; |
| 8556 | case INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST: |
| 8557 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8558 | break; |
| 8559 | case INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST: |
| 8560 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameBottomFieldFirst; |
| 8561 | break; |
| 8562 | default: |
| 8563 | DEBUG_PRINT_LOW("default case - set interlace to topfield"); |
| 8564 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8565 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8566 | } |
| 8567 | if (m_enable_android_native_buffers) |
| 8568 | setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle, |
| 8569 | PP_PARAM_INTERLACED, (void*)&enable); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8570 | if (client_extradata & OMX_INTERLACE_EXTRADATA) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8571 | append_interlace_extradata(p_extra, payload->format, |
| 8572 | p_buf_hdr->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8573 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8574 | } |
| 8575 | break; |
| 8576 | case EXTRADATA_FRAME_RATE: |
| 8577 | struct msm_vidc_framerate_payload *frame_rate_payload; |
| 8578 | frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data; |
| 8579 | frame_rate = frame_rate_payload->frame_rate; |
| 8580 | break; |
| 8581 | case EXTRADATA_TIMESTAMP: |
| 8582 | struct msm_vidc_ts_payload *time_stamp_payload; |
| 8583 | time_stamp_payload = (struct msm_vidc_ts_payload *)data->data; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8584 | time_stamp = time_stamp_payload->timestamp_lo; |
| 8585 | time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32); |
| 8586 | p_buf_hdr->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8587 | break; |
| 8588 | case EXTRADATA_NUM_CONCEALED_MB: |
| 8589 | struct msm_vidc_concealmb_payload *conceal_mb_payload; |
| 8590 | conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data; |
| 8591 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8592 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8593 | num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0); |
| 8594 | break; |
| 8595 | case EXTRADATA_INDEX: |
| 8596 | int *etype; |
| 8597 | etype = (int *)(data->data); |
| 8598 | if (etype && *etype == EXTRADATA_ASPECT_RATIO) { |
| 8599 | struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload; |
| 8600 | aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype); |
| 8601 | if (aspect_ratio_payload) { |
| 8602 | ((struct vdec_output_frameinfo *) |
| 8603 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width; |
| 8604 | ((struct vdec_output_frameinfo *) |
| 8605 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height; |
| 8606 | } |
| 8607 | } |
| 8608 | break; |
| 8609 | case EXTRADATA_RECOVERY_POINT_SEI: |
| 8610 | struct msm_vidc_recoverysei_payload *recovery_sei_payload; |
| 8611 | recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data; |
| 8612 | recovery_sei_flags = recovery_sei_payload->flags; |
| 8613 | if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) { |
| 8614 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8615 | DEBUG_PRINT_HIGH(""); |
| 8616 | DEBUG_PRINT_HIGH("***************************************************"); |
| 8617 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 8618 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8619 | } |
| 8620 | break; |
| 8621 | case EXTRADATA_PANSCAN_WINDOW: |
| 8622 | panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data; |
| 8623 | break; |
| 8624 | case EXTRADATA_MPEG2_SEQDISP: |
| 8625 | struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload; |
| 8626 | seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data; |
| 8627 | if (seqdisp_payload) { |
| 8628 | m_disp_hor_size = seqdisp_payload->disp_width; |
| 8629 | m_disp_vert_size = seqdisp_payload->disp_height; |
| 8630 | } |
| 8631 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8632 | case EXTRADATA_S3D_FRAME_PACKING: |
| 8633 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload; |
| 8634 | s3d_frame_packing_payload = (struct msm_vidc_s3d_frame_packing_payload *)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8635 | if (client_extradata & OMX_FRAMEPACK_EXTRADATA) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8636 | append_framepack_extradata(p_extra, s3d_frame_packing_payload); |
| 8637 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8638 | } |
| 8639 | break; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8640 | case EXTRADATA_FRAME_QP: |
| 8641 | struct msm_vidc_frame_qp_payload *qp_payload; |
| 8642 | qp_payload = (struct msm_vidc_frame_qp_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8643 | if (client_extradata & OMX_QP_EXTRADATA) { |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8644 | append_qp_extradata(p_extra, qp_payload); |
| 8645 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8646 | } |
| 8647 | break; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8648 | case EXTRADATA_FRAME_BITS_INFO: |
| 8649 | struct msm_vidc_frame_bits_info_payload *bits_info_payload; |
| 8650 | bits_info_payload = (struct msm_vidc_frame_bits_info_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8651 | if (client_extradata & OMX_BITSINFO_EXTRADATA) { |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8652 | append_bitsinfo_extradata(p_extra, bits_info_payload); |
| 8653 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8654 | } |
| 8655 | break; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8656 | case EXTRADATA_STREAM_USERDATA: |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8657 | if (client_extradata & OMX_EXTNUSER_EXTRADATA) { |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8658 | append_user_extradata(p_extra, data); |
| 8659 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8660 | } |
| 8661 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8662 | default: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8663 | DEBUG_PRINT_LOW("Unrecognized extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8664 | goto unrecognized_extradata; |
| 8665 | } |
| 8666 | consumed_len += data->nSize; |
| 8667 | data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize); |
| 8668 | } |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8669 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8670 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
| 8671 | append_frame_info_extradata(p_extra, |
| 8672 | num_conceal_MB, ((struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate)->pic_type, frame_rate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8673 | time_stamp, panscan_payload,&((struct vdec_output_frameinfo *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8674 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info); |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8675 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8676 | } |
| 8677 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8678 | unrecognized_extradata: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8679 | if (client_extradata && p_extra) { |
| 8680 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8681 | append_terminator_extradata(p_extra); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8682 | } |
| 8683 | |
Arun Menon | fd72393 | 2014-05-30 17:56:31 -0700 | [diff] [blame] | 8684 | if (secure_mode && p_extradata && m_other_extradata) { |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8685 | struct vdec_output_frameinfo *ptr_extradatabuff = NULL; |
| 8686 | memcpy(p_extradata, m_other_extradata, drv_ctx.extradata_info.buffer_size); |
| 8687 | ptr_extradatabuff = (struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate; |
| 8688 | ptr_extradatabuff->metadata_info.metabufaddr = (void *)p_extradata; |
| 8689 | ptr_extradatabuff->metadata_info.size = drv_ctx.extradata_info.buffer_size; |
| 8690 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8691 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8692 | } |
| 8693 | |
Vinay Kalia | 9c00cae | 2012-12-06 16:08:20 -0800 | [diff] [blame] | 8694 | OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8695 | bool is_internal, bool enable) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8696 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8697 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 8698 | struct v4l2_control control; |
| 8699 | if (m_state != OMX_StateLoaded) { |
| 8700 | DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only"); |
| 8701 | return OMX_ErrorIncorrectStateOperation; |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 8702 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8703 | 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] | 8704 | client_extradata, requested_extradata, enable, is_internal); |
| 8705 | |
| 8706 | if (!is_internal) { |
| 8707 | if (enable) |
| 8708 | client_extradata |= requested_extradata; |
| 8709 | else |
| 8710 | client_extradata = client_extradata & ~requested_extradata; |
| 8711 | } |
| 8712 | |
| 8713 | if (enable) { |
| 8714 | if (requested_extradata & OMX_INTERLACE_EXTRADATA) { |
| 8715 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8716 | control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO; |
| 8717 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8718 | DEBUG_PRINT_HIGH("Failed to set interlaced extradata." |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8719 | " Quality of interlaced clips might be impacted."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8720 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8721 | } |
| 8722 | if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8723 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8724 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE; |
| 8725 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8726 | DEBUG_PRINT_HIGH("Failed to set framerate extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8727 | } |
| 8728 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8729 | control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB; |
| 8730 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8731 | DEBUG_PRINT_HIGH("Failed to set concealed MB extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8732 | } |
| 8733 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8734 | control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI; |
| 8735 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8736 | DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8737 | } |
| 8738 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8739 | control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW; |
| 8740 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8741 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8742 | } |
| 8743 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8744 | control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO; |
| 8745 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8746 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8747 | } |
| 8748 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 8749 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8750 | control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP; |
| 8751 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8752 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8753 | } |
| 8754 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8755 | } |
| 8756 | if (requested_extradata & OMX_TIMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8757 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8758 | control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP; |
| 8759 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8760 | DEBUG_PRINT_HIGH("Failed to set timeinfo extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8761 | } |
| 8762 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8763 | if (requested_extradata & OMX_FRAMEPACK_EXTRADATA) { |
| 8764 | if (output_capability == V4L2_PIX_FMT_H264) { |
| 8765 | DEBUG_PRINT_HIGH("enable OMX_FRAMEPACK_EXTRADATA"); |
| 8766 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8767 | control.value = V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING; |
| 8768 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8769 | DEBUG_PRINT_HIGH("Failed to set S3D_FRAME_PACKING extradata"); |
| 8770 | } |
| 8771 | } else { |
| 8772 | DEBUG_PRINT_HIGH("OMX_FRAMEPACK_EXTRADATA supported for H264 only"); |
| 8773 | } |
| 8774 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8775 | if (requested_extradata & OMX_QP_EXTRADATA) { |
| 8776 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8777 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP; |
| 8778 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8779 | DEBUG_PRINT_HIGH("Failed to set QP extradata"); |
| 8780 | } |
| 8781 | } |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8782 | if (requested_extradata & OMX_BITSINFO_EXTRADATA) { |
| 8783 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8784 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO; |
| 8785 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8786 | DEBUG_PRINT_HIGH("Failed to set frame bits info extradata"); |
| 8787 | } |
| 8788 | } |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8789 | if (requested_extradata & OMX_EXTNUSER_EXTRADATA) { |
| 8790 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8791 | control.value = V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA; |
| 8792 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8793 | DEBUG_PRINT_HIGH("Failed to set stream userdata extradata"); |
| 8794 | } |
| 8795 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8796 | } |
| 8797 | ret = get_buffer_req(&drv_ctx.op_buf); |
| 8798 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8799 | } |
| 8800 | |
| 8801 | OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8802 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8803 | OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0; |
| 8804 | OMX_U8 *data_ptr = extra->data, data = 0; |
| 8805 | while (byte_count < extra->nDataSize) { |
| 8806 | data = *data_ptr; |
| 8807 | while (data) { |
| 8808 | num_MB += (data&0x01); |
| 8809 | data >>= 1; |
| 8810 | } |
| 8811 | data_ptr++; |
| 8812 | byte_count++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8813 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8814 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8815 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8816 | return ((num_MB_in_frame > 0)?(num_MB * 100 / num_MB_in_frame) : 0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8817 | } |
| 8818 | |
| 8819 | void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8820 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8821 | if (!m_debug_extradata) |
| 8822 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8823 | |
| 8824 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8825 | "============== Extra Data ==============\n" |
| 8826 | " Size: %lu\n" |
| 8827 | " Version: %lu\n" |
| 8828 | " PortIndex: %lu\n" |
| 8829 | " Type: %x\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8830 | " DataSize: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8831 | extra->nSize, extra->nVersion.nVersion, |
| 8832 | extra->nPortIndex, extra->eType, extra->nDataSize); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8833 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8834 | if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) { |
| 8835 | OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 8836 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8837 | "------ Interlace Format ------\n" |
| 8838 | " Size: %lu\n" |
| 8839 | " Version: %lu\n" |
| 8840 | " PortIndex: %lu\n" |
| 8841 | " Is Interlace Format: %d\n" |
| 8842 | " Interlace Formats: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8843 | "=========== End of Interlace ===========", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8844 | intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex, |
| 8845 | intfmt->bInterlaceFormat, intfmt->nInterlaceFormats); |
| 8846 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) { |
| 8847 | OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 8848 | |
| 8849 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8850 | "-------- Frame Format --------\n" |
| 8851 | " Picture Type: %d\n" |
| 8852 | " Interlace Type: %d\n" |
| 8853 | " Pan Scan Total Frame Num: %lu\n" |
| 8854 | " Concealed Macro Blocks: %lu\n" |
| 8855 | " frame rate: %lu\n" |
| 8856 | " Time Stamp: %llu\n" |
| 8857 | " Aspect Ratio X: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8858 | " Aspect Ratio Y: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8859 | fminfo->ePicType, |
| 8860 | fminfo->interlaceType, |
| 8861 | fminfo->panScan.numWindows, |
| 8862 | fminfo->nConcealedMacroblocks, |
| 8863 | fminfo->nFrameRate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8864 | fminfo->nTimeStamp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8865 | fminfo->aspectRatio.aspectRatioX, |
| 8866 | fminfo->aspectRatio.aspectRatioY); |
| 8867 | |
| 8868 | for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) { |
| 8869 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8870 | "------------------------------" |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8871 | " Pan Scan Frame Num: %lu\n" |
| 8872 | " Rectangle x: %ld\n" |
| 8873 | " Rectangle y: %ld\n" |
| 8874 | " Rectangle dx: %ld\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8875 | " Rectangle dy: %ld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8876 | i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y, |
| 8877 | fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy); |
| 8878 | } |
| 8879 | |
| 8880 | DEBUG_PRINT_HIGH("========= End of Frame Format =========="); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8881 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement) { |
| 8882 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 8883 | DEBUG_PRINT_HIGH( |
| 8884 | "------------------ Framepack Format ----------\n" |
| 8885 | " id: %lu \n" |
| 8886 | " cancel_flag: %lu \n" |
| 8887 | " type: %lu \n" |
| 8888 | " quincunx_sampling_flagFormat: %lu \n" |
| 8889 | " content_interpretation_type: %lu \n" |
| 8890 | " content_interpretation_type: %lu \n" |
| 8891 | " spatial_flipping_flag: %lu \n" |
| 8892 | " frame0_flipped_flag: %lu \n" |
| 8893 | " field_views_flag: %lu \n" |
| 8894 | " current_frame_is_frame0_flag: %lu \n" |
| 8895 | " frame0_self_contained_flag: %lu \n" |
| 8896 | " frame1_self_contained_flag: %lu \n" |
| 8897 | " frame0_grid_position_x: %lu \n" |
| 8898 | " frame0_grid_position_y: %lu \n" |
| 8899 | " frame1_grid_position_x: %lu \n" |
| 8900 | " frame1_grid_position_y: %lu \n" |
| 8901 | " reserved_byte: %lu \n" |
| 8902 | " repetition_period: %lu \n" |
| 8903 | " extension_flag: %lu \n" |
| 8904 | "================== End of Framepack ===========", |
| 8905 | framepack->id, |
| 8906 | framepack->cancel_flag, |
| 8907 | framepack->type, |
| 8908 | framepack->quincunx_sampling_flag, |
| 8909 | framepack->content_interpretation_type, |
| 8910 | framepack->spatial_flipping_flag, |
| 8911 | framepack->frame0_flipped_flag, |
| 8912 | framepack->field_views_flag, |
| 8913 | framepack->current_frame_is_frame0_flag, |
| 8914 | framepack->frame0_self_contained_flag, |
| 8915 | framepack->frame1_self_contained_flag, |
| 8916 | framepack->frame0_grid_position_x, |
| 8917 | framepack->frame0_grid_position_y, |
| 8918 | framepack->frame1_grid_position_x, |
| 8919 | framepack->frame1_grid_position_y, |
| 8920 | framepack->reserved_byte, |
| 8921 | framepack->repetition_period, |
| 8922 | framepack->extension_flag); |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8923 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataQP) { |
| 8924 | OMX_QCOM_EXTRADATA_QP * qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 8925 | DEBUG_PRINT_HIGH( |
| 8926 | "---- QP (Frame quantization parameter) ----\n" |
| 8927 | " Frame QP: %lu \n" |
| 8928 | "================ End of QP ================\n", |
| 8929 | qp->nQP); |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8930 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo) { |
| 8931 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = (OMX_QCOM_EXTRADATA_BITS_INFO *)extra->data; |
| 8932 | DEBUG_PRINT_HIGH( |
| 8933 | "--------- Input bits information --------\n" |
| 8934 | " Header bits: %lu \n" |
| 8935 | " Frame bits: %lu \n" |
| 8936 | "===== End of Input bits information =====\n", |
| 8937 | bits->header_bits, bits->frame_bits); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8938 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData) { |
| 8939 | OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)extra->data; |
| 8940 | OMX_U8 *data_ptr = (OMX_U8 *)userdata->data; |
| 8941 | OMX_U32 userdata_size = extra->nDataSize - sizeof(userdata->type); |
| 8942 | OMX_U32 i = 0; |
| 8943 | DEBUG_PRINT_HIGH( |
| 8944 | "-------------- Userdata -------------\n" |
| 8945 | " Stream userdata type: %d\n" |
| 8946 | " userdata size: %d\n" |
| 8947 | " STREAM_USERDATA:", |
| 8948 | userdata->type, userdata_size); |
| 8949 | for (i = 0; i < userdata_size; i+=4) { |
| 8950 | DEBUG_PRINT_HIGH(" %x %x %x %x", |
| 8951 | data_ptr[i], data_ptr[i+1], |
| 8952 | data_ptr[i+2], data_ptr[i+3]); |
| 8953 | } |
| 8954 | DEBUG_PRINT_HIGH( |
| 8955 | "=========== End of Userdata ==========="); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8956 | } else if (extra->eType == OMX_ExtraDataNone) { |
| 8957 | DEBUG_PRINT_HIGH("========== End of Terminator ==========="); |
| 8958 | } else { |
| 8959 | DEBUG_PRINT_HIGH("======= End of Driver Extradata ========"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8960 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8961 | } |
| 8962 | |
| 8963 | void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8964 | OMX_U32 interlaced_format_type, bool is_mbaff) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8965 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8966 | OMX_STREAMINTERLACEFORMAT *interlace_format; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8967 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8968 | if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) { |
| 8969 | return; |
| 8970 | } |
| 8971 | extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE; |
| 8972 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8973 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8974 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat; |
| 8975 | extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 8976 | interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 8977 | interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 8978 | interlace_format->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8979 | interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8980 | |
| 8981 | if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !is_mbaff) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8982 | interlace_format->bInterlaceFormat = OMX_FALSE; |
| 8983 | interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive; |
| 8984 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8985 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8986 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8987 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8988 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8989 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8990 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8991 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameBottomFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8992 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8993 | } else { |
| 8994 | interlace_format->bInterlaceFormat = OMX_TRUE; |
| 8995 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
| 8996 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8997 | } |
| 8998 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8999 | } |
| 9000 | |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9001 | void omx_vdec::fill_aspect_ratio_info( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9002 | struct vdec_aspectratioinfo *aspect_ratio_info, |
| 9003 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info) |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9004 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9005 | m_extradata = frame_info; |
| 9006 | m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width; |
| 9007 | m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9008 | DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9009 | m_extradata->aspectRatio.aspectRatioY); |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9010 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9011 | |
| 9012 | void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9013 | 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] | 9014 | OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload, |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9015 | struct vdec_aspectratioinfo *aspect_ratio_info) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9016 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9017 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL; |
| 9018 | struct msm_vidc_panscan_window *panscan_window; |
| 9019 | if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) { |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9020 | return; |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9021 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9022 | extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE; |
| 9023 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9024 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9025 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo; |
| 9026 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO); |
| 9027 | frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 9028 | switch (picture_type) { |
| 9029 | case PICTURE_TYPE_I: |
| 9030 | frame_info->ePicType = OMX_VIDEO_PictureTypeI; |
| 9031 | break; |
| 9032 | case PICTURE_TYPE_P: |
| 9033 | frame_info->ePicType = OMX_VIDEO_PictureTypeP; |
| 9034 | break; |
| 9035 | case PICTURE_TYPE_B: |
| 9036 | frame_info->ePicType = OMX_VIDEO_PictureTypeB; |
| 9037 | break; |
| 9038 | default: |
| 9039 | frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0; |
| 9040 | } |
| 9041 | if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst) |
| 9042 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 9043 | else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst) |
| 9044 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 9045 | else |
| 9046 | frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 9047 | memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio)); |
| 9048 | frame_info->nConcealedMacroblocks = num_conceal_mb; |
| 9049 | frame_info->nFrameRate = frame_rate; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9050 | frame_info->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9051 | frame_info->panScan.numWindows = 0; |
| 9052 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 9053 | if (m_disp_hor_size && m_disp_vert_size) { |
| 9054 | frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size; |
| 9055 | frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size; |
Pushkaraj Patil | 5e6ebd9 | 2014-03-10 10:29:14 +0530 | [diff] [blame] | 9056 | } else { |
| 9057 | frame_info->displayAspectRatio.displayHorizontalSize = 0; |
| 9058 | frame_info->displayAspectRatio.displayVerticalSize = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9059 | } |
| 9060 | } |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9061 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9062 | if (panscan_payload) { |
| 9063 | frame_info->panScan.numWindows = panscan_payload->num_panscan_windows; |
| 9064 | panscan_window = &panscan_payload->wnd[0]; |
| 9065 | for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) { |
| 9066 | frame_info->panScan.window[i].x = panscan_window->panscan_window_width; |
| 9067 | frame_info->panScan.window[i].y = panscan_window->panscan_window_height; |
| 9068 | frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset; |
| 9069 | frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset; |
| 9070 | panscan_window++; |
| 9071 | } |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9072 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9073 | fill_aspect_ratio_info(aspect_ratio_info, frame_info); |
| 9074 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9075 | } |
| 9076 | |
| 9077 | void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9078 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9079 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL; |
| 9080 | extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE; |
| 9081 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9082 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9083 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef; |
| 9084 | extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
| 9085 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data; |
| 9086 | *portDefn = m_port_def; |
| 9087 | DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu " |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9088 | "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9089 | portDefn->format.video.nFrameWidth, |
| 9090 | portDefn->format.video.nStride, |
| 9091 | portDefn->format.video.nSliceHeight); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9092 | } |
| 9093 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 9094 | void omx_vdec::append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9095 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload) |
| 9096 | { |
| 9097 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack; |
| 9098 | if (FRAME_PACK_SIZE*sizeof(OMX_U32) != sizeof(struct msm_vidc_s3d_frame_packing_payload)) { |
| 9099 | DEBUG_PRINT_ERROR("frame packing size mismatch"); |
| 9100 | return; |
| 9101 | } |
| 9102 | extra->nSize = OMX_FRAMEPACK_EXTRADATA_SIZE; |
| 9103 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9104 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9105 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement; |
| 9106 | extra->nDataSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9107 | framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 9108 | framepack->nSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9109 | framepack->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9110 | framepack->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9111 | memcpy(&framepack->id, s3d_frame_packing_payload, |
| 9112 | sizeof(struct msm_vidc_s3d_frame_packing_payload)); |
| 9113 | memcpy(&m_frame_pack_arrangement, framepack, |
| 9114 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
| 9115 | print_debug_extradata(extra); |
| 9116 | } |
| 9117 | |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 9118 | void omx_vdec::append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9119 | struct msm_vidc_frame_qp_payload *qp_payload) |
| 9120 | { |
| 9121 | OMX_QCOM_EXTRADATA_QP * qp = NULL; |
| 9122 | if (!qp_payload) { |
| 9123 | DEBUG_PRINT_ERROR("QP payload is NULL"); |
| 9124 | return; |
| 9125 | } |
| 9126 | extra->nSize = OMX_QP_EXTRADATA_SIZE; |
| 9127 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9128 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9129 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataQP; |
| 9130 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_QP); |
| 9131 | qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 9132 | qp->nQP = qp_payload->frame_qp; |
| 9133 | print_debug_extradata(extra); |
| 9134 | } |
| 9135 | |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 9136 | void omx_vdec::append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9137 | struct msm_vidc_frame_bits_info_payload *bits_payload) |
| 9138 | { |
| 9139 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = NULL; |
| 9140 | if (!bits_payload) { |
| 9141 | DEBUG_PRINT_ERROR("bits info payload is NULL"); |
| 9142 | return; |
| 9143 | } |
| 9144 | extra->nSize = OMX_BITSINFO_EXTRADATA_SIZE; |
| 9145 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9146 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9147 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo; |
| 9148 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_BITS_INFO); |
| 9149 | bits = (OMX_QCOM_EXTRADATA_BITS_INFO*)extra->data; |
| 9150 | bits->frame_bits = bits_payload->frame_bits; |
| 9151 | bits->header_bits = bits_payload->header_bits; |
| 9152 | print_debug_extradata(extra); |
| 9153 | } |
| 9154 | |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9155 | void omx_vdec::append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9156 | OMX_OTHER_EXTRADATATYPE *p_user) |
| 9157 | { |
| 9158 | int userdata_size = 0; |
| 9159 | struct msm_vidc_stream_userdata_payload *userdata_payload = NULL; |
| 9160 | userdata_payload = |
| 9161 | (struct msm_vidc_stream_userdata_payload *)p_user->data; |
| 9162 | userdata_size = p_user->nDataSize; |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 9163 | extra->nSize = OMX_USERDATA_EXTRADATA_SIZE + p_user->nSize; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9164 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9165 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9166 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData; |
| 9167 | extra->nDataSize = userdata_size; |
| 9168 | if (extra->data && p_user->data && extra->nDataSize) |
| 9169 | memcpy(extra->data, p_user->data, extra->nDataSize); |
| 9170 | print_debug_extradata(extra); |
| 9171 | } |
| 9172 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9173 | void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9174 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9175 | if (!client_extradata) { |
| 9176 | return; |
| 9177 | } |
| 9178 | extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE); |
| 9179 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9180 | extra->eType = OMX_ExtraDataNone; |
| 9181 | extra->nDataSize = 0; |
| 9182 | extra->data[0] = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9183 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9184 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9185 | } |
| 9186 | |
| 9187 | OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index) |
| 9188 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9189 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9190 | if (index >= drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9191 | DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9192 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9193 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9194 | if (m_desc_buffer_ptr == NULL) { |
| 9195 | m_desc_buffer_ptr = (desc_buffer_hdr*) \ |
| 9196 | calloc( (sizeof(desc_buffer_hdr)), |
| 9197 | drv_ctx.ip_buf.actualcount); |
| 9198 | if (m_desc_buffer_ptr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9199 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9200 | return OMX_ErrorInsufficientResources; |
| 9201 | } |
| 9202 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9203 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9204 | m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8)); |
| 9205 | if (m_desc_buffer_ptr[index].buf_addr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9206 | DEBUG_PRINT_ERROR("desc buffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9207 | return OMX_ErrorInsufficientResources; |
| 9208 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9209 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9210 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9211 | } |
| 9212 | |
| 9213 | void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset) |
| 9214 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9215 | DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries); |
| 9216 | if (m_demux_entries < 8192) { |
| 9217 | m_demux_offsets[m_demux_entries++] = address_offset; |
| 9218 | } |
| 9219 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9220 | } |
| 9221 | |
| 9222 | void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr) |
| 9223 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9224 | OMX_U32 bytes_to_parse = buf_hdr->nFilledLen; |
| 9225 | OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset; |
| 9226 | OMX_U32 index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9227 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9228 | m_demux_entries = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9229 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9230 | while (index < bytes_to_parse) { |
| 9231 | if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9232 | (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) || |
| 9233 | ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9234 | (buf[index+2] == 0x01)) ) { |
| 9235 | //Found start code, insert address offset |
| 9236 | insert_demux_addr_offset(index); |
| 9237 | if (buf[index+2] == 0x01) // 3 byte start code |
| 9238 | index += 3; |
| 9239 | else //4 byte start code |
| 9240 | index += 4; |
| 9241 | } else |
| 9242 | index++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9243 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9244 | DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries); |
| 9245 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9246 | } |
| 9247 | |
| 9248 | OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 9249 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9250 | //fix this, handle 3 byte start code, vc1 terminator entry |
| 9251 | OMX_U8 *p_demux_data = NULL; |
| 9252 | OMX_U32 desc_data = 0; |
| 9253 | OMX_U32 start_addr = 0; |
| 9254 | OMX_U32 nal_size = 0; |
| 9255 | OMX_U32 suffix_byte = 0; |
| 9256 | OMX_U32 demux_index = 0; |
| 9257 | OMX_U32 buffer_index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9258 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9259 | if (m_desc_buffer_ptr == NULL) { |
| 9260 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries."); |
| 9261 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9262 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9263 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9264 | buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
| 9265 | if (buffer_index > drv_ctx.ip_buf.actualcount) { |
| 9266 | DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index); |
| 9267 | return OMX_ErrorBadParameter; |
| 9268 | } |
| 9269 | |
| 9270 | p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr; |
| 9271 | |
| 9272 | if ( ((OMX_U8*)p_demux_data == NULL) || |
| 9273 | ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) { |
| 9274 | DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries."); |
| 9275 | return OMX_ErrorBadParameter; |
| 9276 | } else { |
| 9277 | for (; demux_index < m_demux_entries; demux_index++) { |
| 9278 | desc_data = 0; |
| 9279 | start_addr = m_demux_offsets[demux_index]; |
| 9280 | if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) { |
| 9281 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3]; |
| 9282 | } else { |
| 9283 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4]; |
| 9284 | } |
| 9285 | if (demux_index < (m_demux_entries - 1)) { |
| 9286 | nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2; |
| 9287 | } else { |
| 9288 | nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2; |
| 9289 | } |
| 9290 | DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)", |
| 9291 | (void *)start_addr, |
| 9292 | suffix_byte, |
| 9293 | nal_size, |
| 9294 | demux_index); |
| 9295 | desc_data = (start_addr >> 3) << 1; |
| 9296 | desc_data |= (start_addr & 7) << 21; |
| 9297 | desc_data |= suffix_byte << 24; |
| 9298 | |
| 9299 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9300 | memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32)); |
| 9301 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9302 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9303 | |
| 9304 | p_demux_data += 16; |
| 9305 | } |
| 9306 | if (codec_type_parse == CODEC_TYPE_VC1) { |
| 9307 | DEBUG_PRINT_LOW("VC1 terminator entry"); |
| 9308 | desc_data = 0; |
| 9309 | desc_data = 0x82 << 24; |
| 9310 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9311 | memset(p_demux_data + 4, 0, sizeof(OMX_U32)); |
| 9312 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9313 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9314 | p_demux_data += 16; |
| 9315 | m_demux_entries++; |
| 9316 | } |
| 9317 | //Add zero word to indicate end of descriptors |
| 9318 | memset(p_demux_data, 0, sizeof(OMX_U32)); |
| 9319 | |
| 9320 | m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32); |
| 9321 | DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size); |
| 9322 | } |
| 9323 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 9324 | m_demux_entries = 0; |
| 9325 | DEBUG_PRINT_LOW("Demux table complete!"); |
| 9326 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9327 | } |
| 9328 | |
Deva Ramasubramanian | 9403f02 | 2012-11-28 18:27:53 -0800 | [diff] [blame] | 9329 | OMX_ERRORTYPE omx_vdec::createDivxDrmContext() |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9330 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9331 | OMX_ERRORTYPE err = OMX_ErrorNone; |
| 9332 | iDivXDrmDecrypt = DivXDrmDecrypt::Create(); |
| 9333 | if (iDivXDrmDecrypt) { |
| 9334 | OMX_ERRORTYPE err = iDivXDrmDecrypt->Init(); |
| 9335 | if (err!=OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9336 | DEBUG_PRINT_ERROR("ERROR :iDivXDrmDecrypt->Init %d", err); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9337 | delete iDivXDrmDecrypt; |
| 9338 | iDivXDrmDecrypt = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9339 | } |
| 9340 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9341 | DEBUG_PRINT_ERROR("Unable to Create DIVX DRM"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9342 | err = OMX_ErrorUndefined; |
| 9343 | } |
| 9344 | return err; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9345 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9346 | |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9347 | omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf() |
| 9348 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9349 | enabled = false; |
| 9350 | omx = NULL; |
| 9351 | init_members(); |
| 9352 | ColorFormat = OMX_COLOR_FormatMax; |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9353 | dest_format = YCbCr420P; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9354 | } |
| 9355 | |
| 9356 | void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client) |
| 9357 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9358 | omx = reinterpret_cast<omx_vdec*>(client); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9359 | } |
| 9360 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9361 | void omx_vdec::allocate_color_convert_buf::init_members() |
| 9362 | { |
| 9363 | allocated_count = 0; |
| 9364 | buffer_size_req = 0; |
| 9365 | buffer_alignment_req = 0; |
| 9366 | memset(m_platform_list_client,0,sizeof(m_platform_list_client)); |
| 9367 | memset(m_platform_entry_client,0,sizeof(m_platform_entry_client)); |
| 9368 | memset(m_pmem_info_client,0,sizeof(m_pmem_info_client)); |
| 9369 | memset(m_out_mem_ptr_client,0,sizeof(m_out_mem_ptr_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9370 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9371 | memset(op_buf_ion_info,0,sizeof(m_platform_entry_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9372 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9373 | for (int i = 0; i < MAX_COUNT; i++) |
| 9374 | pmem_fd[i] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9375 | } |
| 9376 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9377 | omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf() |
| 9378 | { |
| 9379 | c2d.destroy(); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9380 | } |
| 9381 | |
| 9382 | bool omx_vdec::allocate_color_convert_buf::update_buffer_req() |
| 9383 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9384 | bool status = true; |
| 9385 | unsigned int src_size = 0, destination_size = 0; |
| 9386 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9387 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9388 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9389 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9390 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9391 | if (!enabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9392 | DEBUG_PRINT_HIGH("No color conversion required"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9393 | return status; |
| 9394 | } |
| 9395 | pthread_mutex_lock(&omx->c_lock); |
| 9396 | if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 && |
| 9397 | ColorFormat != OMX_COLOR_FormatYUV420Planar) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9398 | DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9399 | status = false; |
| 9400 | goto fail_update_buf_req; |
| 9401 | } |
| 9402 | c2d.close(); |
| 9403 | status = c2d.open(omx->drv_ctx.video_resolution.frame_height, |
| 9404 | omx->drv_ctx.video_resolution.frame_width, |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9405 | NV12_128m,dest_format); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9406 | if (status) { |
| 9407 | status = c2d.get_buffer_size(C2D_INPUT,src_size); |
| 9408 | if (status) |
| 9409 | status = c2d.get_buffer_size(C2D_OUTPUT,destination_size); |
| 9410 | } |
| 9411 | if (status) { |
| 9412 | if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size || |
| 9413 | !destination_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9414 | DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9415 | "driver size %d destination size %d", |
| 9416 | src_size,omx->drv_ctx.op_buf.buffer_size,destination_size); |
| 9417 | status = false; |
| 9418 | c2d.close(); |
| 9419 | buffer_size_req = 0; |
| 9420 | } else { |
| 9421 | buffer_size_req = destination_size; |
| 9422 | if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size) |
| 9423 | buffer_size_req = omx->drv_ctx.op_buf.buffer_size; |
| 9424 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9425 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
| 9426 | } |
| 9427 | } |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9428 | fail_update_buf_req: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9429 | pthread_mutex_unlock(&omx->c_lock); |
| 9430 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9431 | } |
| 9432 | |
| 9433 | bool omx_vdec::allocate_color_convert_buf::set_color_format( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9434 | OMX_COLOR_FORMATTYPE dest_color_format) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9435 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9436 | bool status = true; |
| 9437 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9438 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9439 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9440 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9441 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9442 | pthread_mutex_lock(&omx->c_lock); |
| 9443 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9444 | drv_color_format = (OMX_COLOR_FORMATTYPE) |
| 9445 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9446 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9447 | DEBUG_PRINT_ERROR("Incorrect color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9448 | status = false; |
| 9449 | } |
| 9450 | if (status && (drv_color_format != dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9451 | DEBUG_PRINT_LOW("Enabling C2D"); |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9452 | if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) && |
| 9453 | (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9454 | DEBUG_PRINT_ERROR("Unsupported color format for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9455 | status = false; |
| 9456 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9457 | ColorFormat = dest_color_format; |
| 9458 | dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ? |
| 9459 | YCbCr420P : YCbCr420SP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9460 | if (enabled) |
| 9461 | c2d.destroy(); |
| 9462 | enabled = false; |
| 9463 | if (!c2d.init()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9464 | DEBUG_PRINT_ERROR("open failed for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9465 | status = false; |
| 9466 | } else |
| 9467 | enabled = true; |
| 9468 | } |
| 9469 | } else { |
| 9470 | if (enabled) |
| 9471 | c2d.destroy(); |
| 9472 | enabled = false; |
| 9473 | } |
| 9474 | pthread_mutex_unlock(&omx->c_lock); |
| 9475 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9476 | } |
| 9477 | |
| 9478 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr() |
| 9479 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9480 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9481 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9482 | return NULL; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9483 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9484 | if (!enabled) |
| 9485 | return omx->m_out_mem_ptr; |
| 9486 | return m_out_mem_ptr_client; |
| 9487 | } |
| 9488 | |
| 9489 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr |
| 9490 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9491 | { |
| 9492 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9493 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9494 | return NULL; |
| 9495 | } |
| 9496 | if (!enabled) |
| 9497 | return bufadd; |
| 9498 | |
| 9499 | unsigned index = 0; |
| 9500 | index = bufadd - omx->m_out_mem_ptr; |
| 9501 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9502 | m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS); |
| 9503 | m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp; |
| 9504 | bool status; |
| 9505 | if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) { |
| 9506 | pthread_mutex_lock(&omx->c_lock); |
| 9507 | status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd, |
| 9508 | omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index], |
| 9509 | pmem_baseaddress[index], pmem_baseaddress[index]); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9510 | if (!status) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9511 | DEBUG_PRINT_ERROR("Failed color conversion %d", status); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9512 | m_out_mem_ptr_client[index].nFilledLen = 0; |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9513 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9514 | return &m_out_mem_ptr_client[index]; |
Praveen Chavan | 6d6b725 | 2014-09-15 17:05:54 -0700 | [diff] [blame] | 9515 | } else { |
| 9516 | unsigned int filledLen = 0; |
| 9517 | c2d.get_output_filled_length(filledLen); |
| 9518 | m_out_mem_ptr_client[index].nFilledLen = filledLen; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9519 | } |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9520 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9521 | } else |
| 9522 | m_out_mem_ptr_client[index].nFilledLen = 0; |
| 9523 | return &m_out_mem_ptr_client[index]; |
| 9524 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9525 | DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9526 | return NULL; |
| 9527 | } |
| 9528 | |
| 9529 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr |
| 9530 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9531 | { |
| 9532 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9533 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9534 | return NULL; |
| 9535 | } |
| 9536 | if (!enabled) |
| 9537 | return bufadd; |
| 9538 | unsigned index = 0; |
| 9539 | index = bufadd - m_out_mem_ptr_client; |
| 9540 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9541 | return &omx->m_out_mem_ptr[index]; |
| 9542 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9543 | DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9544 | return NULL; |
| 9545 | } |
| 9546 | bool omx_vdec::allocate_color_convert_buf::get_buffer_req |
| 9547 | (unsigned int &buffer_size) |
| 9548 | { |
| 9549 | bool status = true; |
| 9550 | pthread_mutex_lock(&omx->c_lock); |
| 9551 | if (!enabled) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9552 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9553 | else { |
| 9554 | if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9555 | DEBUG_PRINT_ERROR("Get buffer size failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9556 | status = false; |
| 9557 | goto fail_get_buffer_size; |
| 9558 | } |
| 9559 | } |
| 9560 | if (buffer_size < omx->drv_ctx.op_buf.buffer_size) |
| 9561 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
| 9562 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9563 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9564 | fail_get_buffer_size: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9565 | pthread_mutex_unlock(&omx->c_lock); |
| 9566 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9567 | } |
| 9568 | OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9569 | OMX_BUFFERHEADERTYPE *bufhdr) |
| 9570 | { |
| 9571 | unsigned int index = 0; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9572 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9573 | if (!enabled) |
| 9574 | return omx->free_output_buffer(bufhdr); |
| 9575 | if (enabled && omx->is_component_secure()) |
| 9576 | return OMX_ErrorNone; |
| 9577 | if (!allocated_count || !bufhdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9578 | DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9579 | return OMX_ErrorBadParameter; |
| 9580 | } |
| 9581 | index = bufhdr - m_out_mem_ptr_client; |
| 9582 | if (index >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9583 | DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9584 | return OMX_ErrorBadParameter; |
| 9585 | } |
| 9586 | if (pmem_fd[index] > 0) { |
| 9587 | munmap(pmem_baseaddress[index], buffer_size_req); |
| 9588 | close(pmem_fd[index]); |
| 9589 | } |
| 9590 | pmem_fd[index] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9591 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9592 | omx->free_ion_memory(&op_buf_ion_info[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9593 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9594 | m_heap_ptr[index].video_heap_ptr = NULL; |
| 9595 | if (allocated_count > 0) |
| 9596 | allocated_count--; |
| 9597 | else |
| 9598 | allocated_count = 0; |
| 9599 | if (!allocated_count) { |
| 9600 | pthread_mutex_lock(&omx->c_lock); |
| 9601 | c2d.close(); |
| 9602 | init_members(); |
| 9603 | pthread_mutex_unlock(&omx->c_lock); |
| 9604 | } |
| 9605 | return omx->free_output_buffer(&omx->m_out_mem_ptr[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9606 | } |
| 9607 | |
| 9608 | 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] | 9609 | OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9610 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9611 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9612 | if (!enabled) { |
| 9613 | eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes); |
| 9614 | return eRet; |
| 9615 | } |
| 9616 | if (enabled && omx->is_component_secure()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9617 | DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9618 | omx->is_component_secure()); |
| 9619 | return OMX_ErrorUnsupportedSetting; |
| 9620 | } |
| 9621 | if (!bufferHdr || bytes > buffer_size_req) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9622 | DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr); |
| 9623 | DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9624 | buffer_size_req,bytes); |
| 9625 | return OMX_ErrorBadParameter; |
| 9626 | } |
| 9627 | if (allocated_count >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9628 | DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9629 | return OMX_ErrorInsufficientResources; |
| 9630 | } |
| 9631 | OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL; |
| 9632 | eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr, |
| 9633 | port,appData,omx->drv_ctx.op_buf.buffer_size); |
| 9634 | if (eRet != OMX_ErrorNone || !temp_bufferHdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9635 | DEBUG_PRINT_ERROR("Buffer allocation failed color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9636 | return eRet; |
| 9637 | } |
| 9638 | if ((temp_bufferHdr - omx->m_out_mem_ptr) >= |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 9639 | (int)omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9640 | DEBUG_PRINT_ERROR("Invalid header index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9641 | (temp_bufferHdr - omx->m_out_mem_ptr)); |
| 9642 | return OMX_ErrorUndefined; |
| 9643 | } |
| 9644 | unsigned int i = allocated_count; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9645 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9646 | op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory( |
| 9647 | buffer_size_req,buffer_alignment_req, |
| 9648 | &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data, |
| 9649 | 0); |
| 9650 | pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd; |
| 9651 | if (op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9652 | DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9653 | return OMX_ErrorInsufficientResources; |
| 9654 | } |
| 9655 | pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req, |
| 9656 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9657 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9658 | if (pmem_baseaddress[i] == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9659 | DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9660 | close(pmem_fd[i]); |
| 9661 | omx->free_ion_memory(&op_buf_ion_info[i]); |
| 9662 | return OMX_ErrorInsufficientResources; |
| 9663 | } |
| 9664 | m_heap_ptr[i].video_heap_ptr = new VideoHeap ( |
| 9665 | op_buf_ion_info[i].ion_device_fd,buffer_size_req, |
| 9666 | pmem_baseaddress[i],op_buf_ion_info[i].ion_alloc_data.handle,pmem_fd[i]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9667 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9668 | m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get(); |
| 9669 | m_pmem_info_client[i].offset = 0; |
| 9670 | m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i]; |
| 9671 | m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 9672 | m_platform_list_client[i].nEntries = 1; |
| 9673 | m_platform_list_client[i].entryList = &m_platform_entry_client[i]; |
| 9674 | m_out_mem_ptr_client[i].pOutputPortPrivate = NULL; |
| 9675 | m_out_mem_ptr_client[i].nAllocLen = buffer_size_req; |
| 9676 | m_out_mem_ptr_client[i].nFilledLen = 0; |
| 9677 | m_out_mem_ptr_client[i].nFlags = 0; |
| 9678 | m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9679 | m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 9680 | m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION; |
| 9681 | m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i]; |
| 9682 | m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i]; |
| 9683 | m_out_mem_ptr_client[i].pAppPrivate = appData; |
| 9684 | *bufferHdr = &m_out_mem_ptr_client[i]; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9685 | DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9686 | allocated_count++; |
| 9687 | return eRet; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9688 | } |
| 9689 | |
| 9690 | bool omx_vdec::is_component_secure() |
| 9691 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9692 | return secure_mode; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9693 | } |
| 9694 | |
| 9695 | bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format) |
| 9696 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9697 | bool status = true; |
| 9698 | if (!enabled) { |
| 9699 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9700 | dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 9701 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9702 | else |
| 9703 | status = false; |
| 9704 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9705 | if (ColorFormat == OMX_COLOR_FormatYUV420Planar || |
| 9706 | ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) { |
| 9707 | dest_color_format = ColorFormat; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9708 | } else |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9709 | status = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9710 | } |
| 9711 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9712 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9713 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9714 | void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset) |
| 9715 | { |
| 9716 | int i = 0; |
| 9717 | bool buf_present = false; |
| 9718 | pthread_mutex_lock(&m_lock); |
| 9719 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9720 | //check the buffer fd, offset, uv addr with list contents |
| 9721 | //If present increment reference. |
| 9722 | if ((out_dynamic_list[i].fd == fd) && |
| 9723 | (out_dynamic_list[i].offset == offset)) { |
| 9724 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9725 | 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] | 9726 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9727 | buf_present = true; |
| 9728 | break; |
| 9729 | } |
| 9730 | } |
| 9731 | if (!buf_present) { |
| 9732 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9733 | //search for a entry to insert details of the new buffer |
| 9734 | if (out_dynamic_list[i].dup_fd == 0) { |
| 9735 | out_dynamic_list[i].fd = fd; |
| 9736 | out_dynamic_list[i].offset = offset; |
| 9737 | out_dynamic_list[i].dup_fd = dup(fd); |
| 9738 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9739 | DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9740 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9741 | break; |
| 9742 | } |
| 9743 | } |
| 9744 | } |
| 9745 | pthread_mutex_unlock(&m_lock); |
| 9746 | } |
| 9747 | |
| 9748 | void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset) |
| 9749 | { |
| 9750 | int i = 0; |
| 9751 | pthread_mutex_lock(&m_lock); |
| 9752 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9753 | //check the buffer fd, offset, uv addr with list contents |
| 9754 | //If present decrement reference. |
| 9755 | if ((out_dynamic_list[i].fd == fd) && |
| 9756 | (out_dynamic_list[i].offset == offset)) { |
| 9757 | out_dynamic_list[i].ref_count--; |
| 9758 | if (out_dynamic_list[i].ref_count == 0) { |
| 9759 | close(out_dynamic_list[i].dup_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9760 | DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9761 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9762 | out_dynamic_list[i].dup_fd = 0; |
| 9763 | out_dynamic_list[i].fd = 0; |
| 9764 | out_dynamic_list[i].offset = 0; |
| 9765 | } |
| 9766 | break; |
| 9767 | } |
| 9768 | } |
| 9769 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9770 | 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] | 9771 | } |
| 9772 | pthread_mutex_unlock(&m_lock); |
| 9773 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 9774 | |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 9775 | OMX_ERRORTYPE omx_vdec::enable_adaptive_playback(unsigned long nMaxFrameWidth, |
| 9776 | unsigned long nMaxFrameHeight) |
| 9777 | { |
| 9778 | |
| 9779 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9780 | int ret = 0; |
| 9781 | unsigned long min_res_buf_count = 0; |
| 9782 | |
| 9783 | eRet = enable_smoothstreaming(); |
| 9784 | if (eRet != OMX_ErrorNone) { |
| 9785 | DEBUG_PRINT_ERROR("Failed to enable Adaptive Playback on driver"); |
| 9786 | return eRet; |
| 9787 | } |
| 9788 | |
| 9789 | DEBUG_PRINT_HIGH("Enabling Adaptive playback for %lu x %lu", |
| 9790 | nMaxFrameWidth, |
| 9791 | nMaxFrameHeight); |
| 9792 | m_smoothstreaming_mode = true; |
| 9793 | m_smoothstreaming_width = nMaxFrameWidth; |
| 9794 | m_smoothstreaming_height = nMaxFrameHeight; |
| 9795 | |
| 9796 | //Get upper limit buffer count for min supported resolution |
| 9797 | struct v4l2_format fmt; |
| 9798 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9799 | fmt.fmt.pix_mp.height = m_decoder_capability.min_height; |
| 9800 | fmt.fmt.pix_mp.width = m_decoder_capability.min_width; |
| 9801 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9802 | |
| 9803 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9804 | if (ret) { |
| 9805 | DEBUG_PRINT_ERROR("Set Resolution failed for HxW = %ux%u", |
| 9806 | m_decoder_capability.min_height, |
| 9807 | m_decoder_capability.min_width); |
| 9808 | return OMX_ErrorUnsupportedSetting; |
| 9809 | } |
| 9810 | |
| 9811 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9812 | if (eRet != OMX_ErrorNone) { |
| 9813 | DEBUG_PRINT_ERROR("failed to get_buffer_req"); |
| 9814 | return eRet; |
| 9815 | } |
| 9816 | |
| 9817 | min_res_buf_count = drv_ctx.op_buf.mincount; |
| 9818 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer count = %lu for HxW %ux%u", |
| 9819 | min_res_buf_count, m_decoder_capability.min_height, m_decoder_capability.min_width); |
| 9820 | |
| 9821 | update_resolution(m_smoothstreaming_width, m_smoothstreaming_height, |
| 9822 | m_smoothstreaming_width, m_smoothstreaming_height); |
| 9823 | eRet = is_video_session_supported(); |
| 9824 | if (eRet != OMX_ErrorNone) { |
| 9825 | DEBUG_PRINT_ERROR("video session is not supported"); |
| 9826 | return eRet; |
| 9827 | } |
| 9828 | |
| 9829 | //Get upper limit buffer size for max smooth streaming resolution set |
| 9830 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9831 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 9832 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 9833 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9834 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9835 | if (ret) { |
| 9836 | DEBUG_PRINT_ERROR("Set Resolution failed for adaptive playback"); |
| 9837 | return OMX_ErrorUnsupportedSetting; |
| 9838 | } |
| 9839 | |
| 9840 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9841 | if (eRet != OMX_ErrorNone) { |
| 9842 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!"); |
| 9843 | return eRet; |
| 9844 | } |
| 9845 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer size = %u", |
| 9846 | drv_ctx.op_buf.buffer_size); |
| 9847 | |
| 9848 | drv_ctx.op_buf.mincount = min_res_buf_count; |
| 9849 | drv_ctx.op_buf.actualcount = min_res_buf_count; |
| 9850 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 9851 | if (eRet != OMX_ErrorNone) { |
| 9852 | DEBUG_PRINT_ERROR("failed to set_buffer_req"); |
| 9853 | return eRet; |
| 9854 | } |
| 9855 | |
| 9856 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9857 | if (eRet != OMX_ErrorNone) { |
| 9858 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!!"); |
| 9859 | return eRet; |
| 9860 | } |
| 9861 | DEBUG_PRINT_HIGH("adaptive playback enabled, buf count = %u bufsize = %u", |
| 9862 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size); |
| 9863 | return eRet; |
| 9864 | } |
| 9865 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 9866 | #ifdef _MSM8974_ |
| 9867 | void omx_vdec::send_codec_config() { |
| 9868 | if (codec_config_flag) { |
| 9869 | unsigned p1 = 0; // Parameter - 1 |
| 9870 | unsigned p2 = 0; // Parameter - 2 |
| 9871 | unsigned ident = 0; |
| 9872 | pthread_mutex_lock(&m_lock); |
| 9873 | DEBUG_PRINT_LOW("\n Check Queue for codec_config buffer \n"); |
| 9874 | while (m_etb_q.m_size) { |
| 9875 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 9876 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 9877 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 9878 | if (empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 9879 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 9880 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy_arbitrary failure"); |
| 9881 | omx_report_error(); |
| 9882 | } |
| 9883 | } else { |
| 9884 | DEBUG_PRINT_LOW("\n Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
| 9885 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 9886 | } |
| 9887 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 9888 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 9889 | if (empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 9890 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 9891 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy failure"); |
| 9892 | omx_report_error (); |
| 9893 | } |
| 9894 | } else { |
| 9895 | pending_input_buffers++; |
| 9896 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d", |
| 9897 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 9898 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 9899 | } |
| 9900 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 9901 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
| 9902 | (OMX_BUFFERHEADERTYPE *)p1); |
| 9903 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 9904 | } |
| 9905 | } |
| 9906 | pthread_mutex_unlock(&m_lock); |
| 9907 | } |
| 9908 | } |
| 9909 | #endif |