Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1 | /*-------------------------------------------------------------------------- |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 2 | Copyright (c) 2010 - 2014, The Linux Foundation. All rights reserved. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are met: |
| 6 | * Redistributions of source code must retain the above copyright |
| 7 | notice, this list of conditions and the following disclaimer. |
| 8 | * Redistributions in binary form must reproduce the above copyright |
| 9 | notice, this list of conditions and the following disclaimer in the |
| 10 | documentation and/or other materials provided with the distribution. |
Vinay Kalia | e4a7d9d | 2013-01-21 10:16:33 -0800 | [diff] [blame] | 11 | * Neither the name of The Linux Foundation nor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 12 | the names of its contributors may be used to endorse or promote |
| 13 | products derived from this software without specific prior written |
| 14 | permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | --------------------------------------------------------------------------*/ |
| 28 | |
| 29 | /*============================================================================ |
| 30 | O p e n M A X w r a p p e r s |
| 31 | O p e n M A X C o r e |
| 32 | |
| 33 | *//** @file omx_vdec.cpp |
| 34 | This module contains the implementation of the OpenMAX core & component. |
| 35 | |
| 36 | *//*========================================================================*/ |
| 37 | |
| 38 | ////////////////////////////////////////////////////////////////////////////// |
| 39 | // Include Files |
| 40 | ////////////////////////////////////////////////////////////////////////////// |
| 41 | |
Deva Ramasubramanian | eb81932 | 2014-07-17 14:23:35 -0700 | [diff] [blame] | 42 | #define __STDC_FORMAT_MACROS |
| 43 | #include <inttypes.h> |
| 44 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 45 | #include <string.h> |
| 46 | #include <pthread.h> |
| 47 | #include <sys/prctl.h> |
| 48 | #include <stdlib.h> |
| 49 | #include <unistd.h> |
| 50 | #include <errno.h> |
| 51 | #include "omx_vdec.h" |
| 52 | #include <fcntl.h> |
| 53 | #include <limits.h> |
Deva Ramasubramanian | 15bbc1c | 2013-05-13 16:05:03 -0700 | [diff] [blame] | 54 | #include <stdlib.h> |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 55 | #include <media/hardware/HardwareAPI.h> |
Vinay Kalia | da8f3cf | 2012-12-21 18:26:21 -0800 | [diff] [blame] | 56 | #include <media/msm_media_info.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 57 | |
| 58 | #ifndef _ANDROID_ |
| 59 | #include <sys/ioctl.h> |
| 60 | #include <sys/mman.h> |
| 61 | #endif //_ANDROID_ |
| 62 | |
| 63 | #ifdef _ANDROID_ |
| 64 | #include <cutils/properties.h> |
| 65 | #undef USE_EGL_IMAGE_GPU |
| 66 | #endif |
| 67 | |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 68 | #include <qdMetaData.h> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 69 | |
| 70 | #ifdef _ANDROID_ |
| 71 | #include "DivXDrmDecrypt.h" |
| 72 | #endif //_ANDROID_ |
| 73 | |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 74 | #ifdef METADATA_FOR_DYNAMIC_MODE |
Arun Menon | 9af783f | 2013-10-22 12:57:14 -0700 | [diff] [blame] | 75 | #include "QComOMXMetadata.h" |
| 76 | #endif |
| 77 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 78 | #ifdef USE_EGL_IMAGE_GPU |
| 79 | #include <EGL/egl.h> |
| 80 | #include <EGL/eglQCOM.h> |
| 81 | #define EGL_BUFFER_HANDLE_QCOM 0x4F00 |
| 82 | #define EGL_BUFFER_OFFSET_QCOM 0x4F01 |
| 83 | #endif |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 84 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 85 | #define BUFFER_LOG_LOC "/data/misc/media" |
| 86 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 87 | #ifdef OUTPUT_EXTRADATA_LOG |
| 88 | FILE *outputExtradataFile; |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 89 | char output_extradata_filename [] = "/data/misc/extradata"; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 90 | #endif |
| 91 | |
| 92 | #define DEFAULT_FPS 30 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 93 | #define MAX_SUPPORTED_FPS 120 |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 94 | #define DEFAULT_WIDTH_ALIGNMENT 128 |
| 95 | #define DEFAULT_HEIGHT_ALIGNMENT 32 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 96 | |
| 97 | #define VC1_SP_MP_START_CODE 0xC5000000 |
| 98 | #define VC1_SP_MP_START_CODE_MASK 0xFF000000 |
| 99 | #define VC1_AP_SEQ_START_CODE 0x0F010000 |
| 100 | #define VC1_STRUCT_C_PROFILE_MASK 0xF0 |
| 101 | #define VC1_STRUCT_B_LEVEL_MASK 0xE0000000 |
| 102 | #define VC1_SIMPLE_PROFILE 0 |
| 103 | #define VC1_MAIN_PROFILE 1 |
| 104 | #define VC1_ADVANCE_PROFILE 3 |
| 105 | #define VC1_SIMPLE_PROFILE_LOW_LEVEL 0 |
| 106 | #define VC1_SIMPLE_PROFILE_MED_LEVEL 2 |
| 107 | #define VC1_STRUCT_C_LEN 4 |
| 108 | #define VC1_STRUCT_C_POS 8 |
| 109 | #define VC1_STRUCT_A_POS 12 |
| 110 | #define VC1_STRUCT_B_POS 24 |
| 111 | #define VC1_SEQ_LAYER_SIZE 36 |
Vinay Kalia | b09886c | 2012-08-20 11:27:25 -0700 | [diff] [blame] | 112 | #define POLL_TIMEOUT 0x7fffffff |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 113 | |
| 114 | #define MEM_DEVICE "/dev/ion" |
| 115 | #define MEM_HEAP_ID ION_CP_MM_HEAP_ID |
| 116 | |
| 117 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 118 | extern "C" { |
| 119 | #include<utils/Log.h> |
| 120 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 121 | #endif//_ANDROID_ |
| 122 | |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 123 | #define SZ_4K 0x1000 |
| 124 | #define SZ_1M 0x100000 |
| 125 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 126 | #define Log2(number, power) { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) && power < 16) { temp >>=0x1; power++; } } |
| 127 | #define Q16ToFraction(q,num,den) { OMX_U32 power; Log2(q,power); num = q >> power; den = 0x1 << (16 - power); } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 128 | #define EXTRADATA_IDX(__num_planes) (__num_planes - 1) |
Maheshwar Ajja | 77cd19c | 2014-06-05 11:23:18 +0530 | [diff] [blame] | 129 | #define ALIGN(x, to_align) ((((unsigned) x) + (to_align - 1)) & ~(to_align - 1)) |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 130 | |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 131 | #define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA) |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 132 | #define DEFAULT_CONCEAL_COLOR "32896" //0x8080, black by default |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 133 | |
| 134 | int debug_level = PRIO_ERROR; |
| 135 | |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 136 | static OMX_U32 maxSmoothStreamingWidth = 1920; |
| 137 | static OMX_U32 maxSmoothStreamingHeight = 1088; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 138 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 139 | void* async_message_thread (void *input) |
| 140 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 141 | OMX_BUFFERHEADERTYPE *buffer; |
| 142 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 143 | struct pollfd pfd; |
| 144 | struct v4l2_buffer v4l2_buf; |
| 145 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 146 | struct v4l2_event dqevent; |
| 147 | omx_vdec *omx = reinterpret_cast<omx_vdec*>(input); |
| 148 | pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI; |
| 149 | pfd.fd = omx->drv_ctx.video_driver_fd; |
| 150 | int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 151 | DEBUG_PRINT_HIGH("omx_vdec: Async thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 152 | prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0); |
| 153 | while (1) { |
| 154 | rc = poll(&pfd, 1, POLL_TIMEOUT); |
| 155 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 156 | DEBUG_PRINT_ERROR("Poll timedout"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 157 | break; |
Deepak Kushwah | 4193f60 | 2015-11-17 15:45:22 +0530 | [diff] [blame] | 158 | } else if (rc < 0 && errno != EINTR && errno != EAGAIN) { |
| 159 | DEBUG_PRINT_ERROR("Error while polling: %d, errno = %d", rc, errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) { |
| 163 | struct vdec_msginfo vdec_msg; |
| 164 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 165 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 166 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 167 | v4l2_buf.m.planes = plane; |
| 168 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 169 | vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 170 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 171 | vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf; |
| 172 | vdec_msg.msgdata.output_frame.len=plane[0].bytesused; |
| 173 | vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr; |
| 174 | vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) + |
| 175 | (uint64_t)v4l2_buf.timestamp.tv_usec; |
| 176 | if (vdec_msg.msgdata.output_frame.len) { |
| 177 | vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2]; |
| 178 | vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3]; |
| 179 | vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4]; |
| 180 | vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5]; |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 181 | vdec_msg.msgdata.output_frame.picsize.frame_width = plane[0].reserved[6]; |
| 182 | vdec_msg.msgdata.output_frame.picsize.frame_height = plane[0].reserved[7]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 183 | } |
| 184 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 185 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 186 | break; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) { |
| 191 | struct vdec_msginfo vdec_msg; |
| 192 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 193 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 194 | v4l2_buf.length = 1; |
| 195 | v4l2_buf.m.planes = plane; |
| 196 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 197 | vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE; |
| 198 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 199 | vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf; |
| 200 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 201 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 202 | break; |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | if (pfd.revents & POLLPRI) { |
| 207 | rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent); |
| 208 | if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) { |
| 209 | struct vdec_msginfo vdec_msg; |
| 210 | vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED; |
| 211 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 212 | DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 213 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 214 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) { |
| 218 | struct vdec_msginfo vdec_msg; |
| 219 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE; |
| 220 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 221 | DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 222 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 223 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 224 | break; |
| 225 | } |
| 226 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE; |
| 227 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 228 | DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 229 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 230 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 234 | DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 235 | break; |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 236 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_HW_OVERLOAD) { |
| 237 | struct vdec_msginfo vdec_msg; |
| 238 | vdec_msg.msgcode=VDEC_MSG_EVT_HW_OVERLOAD; |
| 239 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 240 | DEBUG_PRINT_ERROR("HW Overload received"); |
| 241 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
| 242 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
| 243 | break; |
| 244 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 245 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) { |
| 246 | struct vdec_msginfo vdec_msg; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 247 | vdec_msg.msgcode = VDEC_MSG_EVT_HW_ERROR; |
| 248 | vdec_msg.status_code = VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 249 | DEBUG_PRINT_HIGH("SYS Error Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 250 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 251 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 252 | break; |
| 253 | } |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 254 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 255 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 256 | 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] | 257 | omx->buf_ref_remove(ptr[0], ptr[1]); |
| 258 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) { |
| 259 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
| 260 | struct vdec_msginfo vdec_msg; |
| 261 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 262 | 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] | 263 | |
| 264 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 265 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 266 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 267 | v4l2_buf.m.planes = plane; |
| 268 | v4l2_buf.index = ptr[5]; |
| 269 | v4l2_buf.flags = 0; |
| 270 | |
| 271 | vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 272 | vdec_msg.status_code = VDEC_S_SUCCESS; |
| 273 | vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf; |
| 274 | vdec_msg.msgdata.output_frame.len = 0; |
| 275 | vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2]; |
| 276 | vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) + |
| 277 | (uint64_t)ptr[4]; |
| 278 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 279 | DEBUG_PRINT_HIGH("async_message_thread Exitedn"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 283 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 284 | DEBUG_PRINT_HIGH("VIDC Some Event recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 285 | continue; |
| 286 | } |
| 287 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 288 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 289 | DEBUG_PRINT_HIGH("omx_vdec: Async thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 290 | return NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Ashray Kulkarni | a97efbc | 2015-07-15 18:17:23 -0700 | [diff] [blame] | 293 | void* dec_message_thread(void *input) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 294 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 295 | omx_vdec* omx = reinterpret_cast<omx_vdec*>(input); |
| 296 | unsigned char id; |
| 297 | int n; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 298 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 299 | DEBUG_PRINT_HIGH("omx_vdec: message thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 300 | prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0); |
| 301 | while (1) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 302 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 303 | n = read(omx->m_pipe_in, &id, 1); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 304 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 305 | if (0 == n) { |
| 306 | break; |
| 307 | } |
| 308 | |
| 309 | if (1 == n) { |
| 310 | omx->process_event_cb(omx, id); |
| 311 | } |
| 312 | if ((n < 0) && (errno != EINTR)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 313 | 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] | 314 | break; |
| 315 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 316 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 317 | DEBUG_PRINT_HIGH("omx_vdec: message thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 318 | return 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void post_message(omx_vdec *omx, unsigned char id) |
| 322 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 323 | int ret_value; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 324 | 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] | 325 | ret_value = write(omx->m_pipe_out, &id, 1); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 326 | DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | // omx_cmd_queue destructor |
| 330 | omx_vdec::omx_cmd_queue::~omx_cmd_queue() |
| 331 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 332 | // Nothing to do |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | // omx cmd queue constructor |
| 336 | omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0) |
| 337 | { |
| 338 | memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE); |
| 339 | } |
| 340 | |
| 341 | // omx cmd queue insert |
| 342 | bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id) |
| 343 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 344 | bool ret = true; |
| 345 | if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 346 | m_q[m_write].id = id; |
| 347 | m_q[m_write].param1 = p1; |
| 348 | m_q[m_write].param2 = p2; |
| 349 | m_write++; |
| 350 | m_size ++; |
| 351 | if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 352 | m_write = 0; |
| 353 | } |
| 354 | } else { |
| 355 | ret = false; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 356 | DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 357 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 358 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // omx cmd queue pop |
| 362 | bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id) |
| 363 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 364 | bool ret = true; |
| 365 | if (m_size > 0) { |
| 366 | *id = m_q[m_read].id; |
| 367 | *p1 = m_q[m_read].param1; |
| 368 | *p2 = m_q[m_read].param2; |
| 369 | // Move the read pointer ahead |
| 370 | ++m_read; |
| 371 | --m_size; |
| 372 | if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 373 | m_read = 0; |
| 374 | } |
| 375 | } else { |
| 376 | ret = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 377 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 378 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | // Retrieve the first mesg type in the queue |
| 382 | unsigned omx_vdec::omx_cmd_queue::get_q_msg_type() |
| 383 | { |
| 384 | return m_q[m_read].id; |
| 385 | } |
| 386 | |
| 387 | #ifdef _ANDROID_ |
| 388 | omx_vdec::ts_arr_list::ts_arr_list() |
| 389 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 390 | //initialize timestamps array |
| 391 | 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] | 392 | } |
| 393 | omx_vdec::ts_arr_list::~ts_arr_list() |
| 394 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 395 | //free m_ts_arr_list? |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts) |
| 399 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 400 | bool ret = true; |
| 401 | bool duplicate_ts = false; |
| 402 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 403 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 404 | //insert at the first available empty location |
| 405 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 406 | if (!m_ts_arr_list[idx].valid) { |
| 407 | //found invalid or empty entry, save timestamp |
| 408 | m_ts_arr_list[idx].valid = true; |
| 409 | m_ts_arr_list[idx].timestamp = ts; |
| 410 | DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)", |
| 411 | ts, idx); |
| 412 | break; |
| 413 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 414 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 415 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 416 | if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 417 | DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert"); |
| 418 | ret = false; |
| 419 | } |
| 420 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts) |
| 424 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 425 | bool ret = true; |
| 426 | int min_idx = -1; |
| 427 | OMX_TICKS min_ts = 0; |
| 428 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 429 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 430 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 431 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 432 | if (m_ts_arr_list[idx].valid) { |
| 433 | //found valid entry, save index |
| 434 | if (min_idx < 0) { |
| 435 | //first valid entry |
| 436 | min_ts = m_ts_arr_list[idx].timestamp; |
| 437 | min_idx = idx; |
| 438 | } else if (m_ts_arr_list[idx].timestamp < min_ts) { |
| 439 | min_ts = m_ts_arr_list[idx].timestamp; |
| 440 | min_idx = idx; |
| 441 | } |
| 442 | } |
| 443 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 446 | if (min_idx < 0) { |
| 447 | //no valid entries found |
| 448 | DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop"); |
| 449 | ts = 0; |
| 450 | ret = false; |
| 451 | } else { |
| 452 | ts = m_ts_arr_list[min_idx].timestamp; |
| 453 | m_ts_arr_list[min_idx].valid = false; |
| 454 | DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)", |
| 455 | ts, min_idx); |
| 456 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 457 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 458 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 459 | |
| 460 | } |
| 461 | |
| 462 | |
| 463 | bool omx_vdec::ts_arr_list::reset_ts_list() |
| 464 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 465 | bool ret = true; |
| 466 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 467 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 468 | DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list"); |
| 469 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 470 | m_ts_arr_list[idx].valid = false; |
| 471 | } |
| 472 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 473 | } |
| 474 | #endif |
| 475 | |
| 476 | // factory function executed by the core to create instances |
| 477 | void *get_omx_component_factory_fn(void) |
| 478 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 479 | return (new omx_vdec); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | #ifdef _ANDROID_ |
| 483 | #ifdef USE_ION |
| 484 | VideoHeap::VideoHeap(int devicefd, size_t size, void* base, |
Mitchel Humpherys | 2294c23 | 2013-12-10 12:14:04 -0800 | [diff] [blame] | 485 | ion_user_handle_t handle, int ionMapfd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 486 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 487 | // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 488 | } |
| 489 | #else |
| 490 | VideoHeap::VideoHeap(int fd, size_t size, void* base) |
| 491 | { |
| 492 | // dup file descriptor, map once, use pmem |
| 493 | init(dup(fd), base, size, 0 , MEM_DEVICE); |
| 494 | } |
| 495 | #endif |
| 496 | #endif // _ANDROID_ |
| 497 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 498 | FUNCTION |
| 499 | omx_vdec::omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 500 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 501 | DESCRIPTION |
| 502 | Constructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 503 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 504 | PARAMETERS |
| 505 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 506 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 507 | RETURN VALUE |
| 508 | None. |
| 509 | ========================================================================== */ |
Deva Ramasubramanian | 5c24124 | 2013-02-19 17:25:30 -0800 | [diff] [blame] | 510 | omx_vdec::omx_vdec(): m_error_propogated(false), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 511 | m_state(OMX_StateInvalid), |
| 512 | m_app_data(NULL), |
| 513 | m_inp_mem_ptr(NULL), |
| 514 | m_out_mem_ptr(NULL), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 515 | input_flush_progress (false), |
| 516 | output_flush_progress (false), |
| 517 | input_use_buffer (false), |
| 518 | output_use_buffer (false), |
| 519 | ouput_egl_buffers(false), |
| 520 | m_use_output_pmem(OMX_FALSE), |
| 521 | m_out_mem_region_smi(OMX_FALSE), |
| 522 | m_out_pvt_entry_pmem(OMX_FALSE), |
| 523 | pending_input_buffers(0), |
| 524 | pending_output_buffers(0), |
| 525 | m_out_bm_count(0), |
| 526 | m_inp_bm_count(0), |
| 527 | m_inp_bPopulated(OMX_FALSE), |
| 528 | m_out_bPopulated(OMX_FALSE), |
| 529 | m_flags(0), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 530 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 531 | m_heap_ptr(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 532 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 533 | m_inp_bEnabled(OMX_TRUE), |
| 534 | m_out_bEnabled(OMX_TRUE), |
| 535 | m_in_alloc_cnt(0), |
| 536 | m_platform_list(NULL), |
| 537 | m_platform_entry(NULL), |
| 538 | m_pmem_info(NULL), |
| 539 | arbitrary_bytes (true), |
| 540 | psource_frame (NULL), |
| 541 | pdest_frame (NULL), |
| 542 | m_inp_heap_ptr (NULL), |
| 543 | m_phdr_pmem_ptr(NULL), |
| 544 | m_heap_inp_bm_count (0), |
| 545 | codec_type_parse ((codec_type)0), |
| 546 | first_frame_meta (true), |
| 547 | frame_count (0), |
| 548 | nal_count (0), |
| 549 | nal_length(0), |
| 550 | look_ahead_nal (false), |
| 551 | first_frame(0), |
| 552 | first_buffer(NULL), |
| 553 | first_frame_size (0), |
| 554 | m_device_file_ptr(NULL), |
| 555 | m_vc1_profile((vc1_profile_type)0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 556 | h264_last_au_ts(LLONG_MAX), |
| 557 | h264_last_au_flags(0), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 558 | m_disp_hor_size(0), |
| 559 | m_disp_vert_size(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 560 | prev_ts(LLONG_MAX), |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 561 | prev_ts_actual(LLONG_MAX), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 562 | rst_prev_ts(true), |
| 563 | frm_int(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 564 | in_reconfig(false), |
| 565 | m_display_id(NULL), |
| 566 | h264_parser(NULL), |
| 567 | client_extradata(0), |
| 568 | m_reject_avc_1080p_mp (0), |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 569 | m_other_extradata(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 570 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 571 | m_enable_android_native_buffers(OMX_FALSE), |
| 572 | m_use_android_native_buffers(OMX_FALSE), |
| 573 | iDivXDrmDecrypt(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 574 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 575 | m_desc_buffer_ptr(NULL), |
| 576 | secure_mode(false), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 577 | m_profile(0), |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 578 | client_set_fps(false), |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 579 | m_last_rendered_TS(-1), |
| 580 | m_queued_codec_config_count(0) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 581 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 582 | /* Assumption is that , to begin with , we have all the frames with decoder */ |
| 583 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 584 | memset(&m_debug,0,sizeof(m_debug)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 585 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 586 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 587 | property_get("vidc.debug.level", property_value, "0"); |
| 588 | debug_level = atoi(property_value); |
| 589 | property_value[0] = '\0'; |
| 590 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 591 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
| 592 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 593 | property_get("vidc.dec.debug.perf", property_value, "0"); |
| 594 | perf_flag = atoi(property_value); |
| 595 | if (perf_flag) { |
| 596 | DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag); |
| 597 | dec_time.start(); |
| 598 | proc_frms = latency = 0; |
| 599 | } |
| 600 | prev_n_filled_len = 0; |
| 601 | property_value[0] = '\0'; |
| 602 | property_get("vidc.dec.debug.ts", property_value, "0"); |
| 603 | m_debug_timestamp = atoi(property_value); |
| 604 | DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp); |
| 605 | if (m_debug_timestamp) { |
| 606 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 607 | time_stamp_dts.enable_debug_print(true); |
| 608 | } |
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.debug.concealedmb", property_value, "0"); |
| 612 | m_debug_concealedmb = atoi(property_value); |
| 613 | 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] | 614 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 615 | property_value[0] = '\0'; |
| 616 | property_get("vidc.dec.profile.check", property_value, "0"); |
| 617 | m_reject_avc_1080p_mp = atoi(property_value); |
| 618 | 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] | 619 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 620 | property_value[0] = '\0'; |
| 621 | property_get("vidc.dec.log.in", property_value, "0"); |
| 622 | m_debug.in_buffer_log = atoi(property_value); |
| 623 | |
| 624 | property_value[0] = '\0'; |
| 625 | property_get("vidc.dec.log.out", property_value, "0"); |
| 626 | m_debug.out_buffer_log = atoi(property_value); |
| 627 | sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC); |
| 628 | |
| 629 | property_value[0] = '\0'; |
| 630 | property_get("vidc.log.loc", property_value, ""); |
| 631 | if (*property_value) |
| 632 | strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 633 | |
| 634 | property_value[0] = '\0'; |
| 635 | property_get("vidc.dec.120fps.enabled", property_value, "0"); |
| 636 | |
| 637 | //if this feature is not enabled then reset this value -ve |
| 638 | if(atoi(property_value)) { |
| 639 | DEBUG_PRINT_LOW("feature 120 FPS decode enabled"); |
| 640 | m_last_rendered_TS = 0; |
| 641 | } |
| 642 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 643 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 644 | memset(&m_cmp,0,sizeof(m_cmp)); |
| 645 | memset(&m_cb,0,sizeof(m_cb)); |
| 646 | memset (&drv_ctx,0,sizeof(drv_ctx)); |
| 647 | memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE)); |
| 648 | memset (m_hwdevice_name,0,sizeof(m_hwdevice_name)); |
| 649 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 650 | memset(&m_custom_buffersize, 0, sizeof(m_custom_buffersize)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 651 | m_demux_entries = 0; |
| 652 | msg_thread_id = 0; |
| 653 | async_thread_id = 0; |
| 654 | msg_thread_created = false; |
| 655 | async_thread_created = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 656 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 657 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 658 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 659 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 660 | memset(&m_frame_pack_arrangement, 0, sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 661 | drv_ctx.timestamp_adjust = false; |
| 662 | drv_ctx.video_driver_fd = -1; |
| 663 | m_vendor_config.pData = NULL; |
| 664 | pthread_mutex_init(&m_lock, NULL); |
| 665 | pthread_mutex_init(&c_lock, NULL); |
| 666 | sem_init(&m_cmd_lock,0,0); |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 667 | sem_init(&m_safe_flush, 0, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 668 | streaming[CAPTURE_PORT] = |
| 669 | streaming[OUTPUT_PORT] = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 670 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 671 | char extradata_value[PROPERTY_VALUE_MAX] = {0}; |
| 672 | property_get("vidc.dec.debug.extradata", extradata_value, "0"); |
| 673 | m_debug_extradata = atoi(extradata_value); |
| 674 | 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] | 675 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 676 | m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB; |
| 677 | client_buffers.set_vdec_client(this); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 678 | dynamic_buf_mode = false; |
| 679 | out_dynamic_list = NULL; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 680 | is_down_scalar_enabled = false; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 681 | m_smoothstreaming_mode = false; |
| 682 | m_smoothstreaming_width = 0; |
| 683 | m_smoothstreaming_height = 0; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 684 | is_q6_platform = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 687 | static const int event_type[] = { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 688 | V4L2_EVENT_MSM_VIDC_FLUSH_DONE, |
| 689 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT, |
| 690 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT, |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 691 | V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE, |
| 692 | V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 693 | V4L2_EVENT_MSM_VIDC_CLOSE_DONE, |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 694 | V4L2_EVENT_MSM_VIDC_SYS_ERROR, |
| 695 | V4L2_EVENT_MSM_VIDC_HW_OVERLOAD |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 696 | }; |
| 697 | |
| 698 | static OMX_ERRORTYPE subscribe_to_events(int fd) |
| 699 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 700 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 701 | struct v4l2_event_subscription sub; |
| 702 | int array_sz = sizeof(event_type)/sizeof(int); |
| 703 | int i,rc; |
| 704 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 705 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 706 | return OMX_ErrorBadParameter; |
| 707 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 708 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 709 | for (i = 0; i < array_sz; ++i) { |
| 710 | memset(&sub, 0, sizeof(sub)); |
| 711 | sub.type = event_type[i]; |
| 712 | rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub); |
| 713 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 714 | DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 715 | break; |
| 716 | } |
| 717 | } |
| 718 | if (i < array_sz) { |
| 719 | for (--i; i >=0 ; i--) { |
| 720 | memset(&sub, 0, sizeof(sub)); |
| 721 | sub.type = event_type[i]; |
| 722 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 723 | if (rc) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 724 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 725 | } |
| 726 | eRet = OMX_ErrorNotImplemented; |
| 727 | } |
| 728 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | |
| 732 | static OMX_ERRORTYPE unsubscribe_to_events(int fd) |
| 733 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 734 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 735 | struct v4l2_event_subscription sub; |
| 736 | int array_sz = sizeof(event_type)/sizeof(int); |
| 737 | int i,rc; |
| 738 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 739 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 740 | return OMX_ErrorBadParameter; |
| 741 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 742 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 743 | for (i = 0; i < array_sz; ++i) { |
| 744 | memset(&sub, 0, sizeof(sub)); |
| 745 | sub.type = event_type[i]; |
| 746 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 747 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 748 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 749 | break; |
| 750 | } |
| 751 | } |
| 752 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 753 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 754 | |
| 755 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 756 | FUNCTION |
| 757 | omx_vdec::~omx_vdec |
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 | DESCRIPTION |
| 760 | Destructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 761 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 762 | PARAMETERS |
| 763 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 764 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 765 | RETURN VALUE |
| 766 | None. |
| 767 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 768 | omx_vdec::~omx_vdec() |
| 769 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 770 | m_pmem_info = NULL; |
| 771 | struct v4l2_decoder_cmd dec; |
| 772 | DEBUG_PRINT_HIGH("In OMX vdec Destructor"); |
| 773 | if (m_pipe_in) close(m_pipe_in); |
| 774 | if (m_pipe_out) close(m_pipe_out); |
| 775 | m_pipe_in = -1; |
| 776 | m_pipe_out = -1; |
| 777 | DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit"); |
| 778 | if (msg_thread_created) |
| 779 | pthread_join(msg_thread_id,NULL); |
| 780 | DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit"); |
| 781 | dec.cmd = V4L2_DEC_CMD_STOP; |
| 782 | if (drv_ctx.video_driver_fd >=0 ) { |
| 783 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 784 | DEBUG_PRINT_ERROR("STOP Command failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 785 | } |
| 786 | if (async_thread_created) |
| 787 | pthread_join(async_thread_id,NULL); |
| 788 | unsubscribe_to_events(drv_ctx.video_driver_fd); |
| 789 | close(drv_ctx.video_driver_fd); |
| 790 | pthread_mutex_destroy(&m_lock); |
| 791 | pthread_mutex_destroy(&c_lock); |
| 792 | sem_destroy(&m_cmd_lock); |
| 793 | if (perf_flag) { |
| 794 | DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME"); |
| 795 | dec_time.end(); |
| 796 | } |
| 797 | DEBUG_PRINT_HIGH("Exit OMX vdec Destructor"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 800 | int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type) |
| 801 | { |
| 802 | struct v4l2_requestbuffers bufreq; |
| 803 | int rc = 0; |
| 804 | if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 805 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 806 | bufreq.count = 0; |
| 807 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 808 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 809 | } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 810 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 811 | bufreq.count = 0; |
| 812 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 813 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 814 | } |
| 815 | return rc; |
Vinay Kalia | feef703 | 2012-09-25 19:23:33 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 818 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 819 | FUNCTION |
| 820 | omx_vdec::OMXCntrlProcessMsgCb |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 821 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 822 | DESCRIPTION |
| 823 | IL Client callbacks are generated through this routine. The decoder |
| 824 | provides the thread context for this routine. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 825 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 826 | PARAMETERS |
| 827 | ctxt -- Context information related to the self. |
| 828 | id -- Event identifier. This could be any of the following: |
| 829 | 1. Command completion event |
| 830 | 2. Buffer done callback event |
| 831 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 832 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 833 | RETURN VALUE |
| 834 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 835 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 836 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 837 | void omx_vdec::process_event_cb(void *ctxt, unsigned char id) |
| 838 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 839 | signed p1; // Parameter - 1 |
| 840 | signed p2; // Parameter - 2 |
| 841 | unsigned ident; |
| 842 | unsigned qsize=0; // qsize |
| 843 | omx_vdec *pThis = (omx_vdec *) ctxt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 844 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 845 | if (!pThis) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 846 | DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 847 | __func__); |
| 848 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 851 | // Protect the shared queue data structure |
| 852 | do { |
| 853 | /*Read the message id's from the queue*/ |
| 854 | pthread_mutex_lock(&pThis->m_lock); |
| 855 | qsize = pThis->m_cmd_q.m_size; |
| 856 | if (qsize) { |
| 857 | pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 858 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 859 | |
| 860 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 861 | qsize = pThis->m_ftb_q.m_size; |
| 862 | if (qsize) { |
| 863 | pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 864 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 865 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 866 | |
| 867 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 868 | qsize = pThis->m_etb_q.m_size; |
| 869 | if (qsize) { |
| 870 | pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 871 | } |
| 872 | } |
| 873 | pthread_mutex_unlock(&pThis->m_lock); |
| 874 | |
| 875 | /*process message if we have one*/ |
| 876 | if (qsize > 0) { |
| 877 | id = ident; |
| 878 | switch (id) { |
| 879 | case OMX_COMPONENT_GENERATE_EVENT: |
| 880 | if (pThis->m_cb.EventHandler) { |
| 881 | switch (p1) { |
| 882 | case OMX_CommandStateSet: |
| 883 | pThis->m_state = (OMX_STATETYPE) p2; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 884 | DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 885 | pThis->m_state); |
| 886 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 887 | OMX_EventCmdComplete, p1, p2, NULL); |
| 888 | break; |
| 889 | |
| 890 | case OMX_EventError: |
| 891 | if (p2 == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 892 | DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 893 | pThis->m_state = (OMX_STATETYPE) p2; |
| 894 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 895 | OMX_EventError, OMX_ErrorInvalidState, p2, NULL); |
| 896 | } else if (p2 == OMX_ErrorHardware) { |
| 897 | pThis->omx_report_error(); |
| 898 | } else { |
| 899 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 900 | OMX_EventError, p2, (OMX_U32)NULL, NULL ); |
| 901 | } |
| 902 | break; |
| 903 | |
| 904 | case OMX_CommandPortDisable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 905 | DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 906 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 907 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
| 908 | BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
| 909 | break; |
| 910 | } |
| 911 | if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 912 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 913 | pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
| 914 | if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 915 | DEBUG_PRINT_HIGH("Failed to release output buffers"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 916 | OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf); |
| 917 | pThis->in_reconfig = false; |
| 918 | if (eRet != OMX_ErrorNone) { |
| 919 | DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet); |
| 920 | pThis->omx_report_error(); |
| 921 | break; |
| 922 | } |
| 923 | } |
| 924 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 925 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 926 | break; |
| 927 | case OMX_CommandPortEnable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 928 | DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 929 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\ |
| 930 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 931 | break; |
| 932 | |
| 933 | default: |
| 934 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 935 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 936 | break; |
| 937 | |
| 938 | } |
| 939 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 940 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 941 | } |
| 942 | break; |
| 943 | case OMX_COMPONENT_GENERATE_ETB_ARBITRARY: |
| 944 | if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 945 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 946 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 947 | pThis->omx_report_error (); |
| 948 | } |
| 949 | break; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 950 | case OMX_COMPONENT_GENERATE_ETB: { |
| 951 | OMX_ERRORTYPE iret; |
| 952 | iret = pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1, (OMX_BUFFERHEADERTYPE *)p2); |
| 953 | if (iret == OMX_ErrorInsufficientResources) { |
| 954 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure due to HW overload"); |
| 955 | pThis->omx_report_hw_overload (); |
| 956 | } else if (iret != OMX_ErrorNone) { |
| 957 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure"); |
| 958 | pThis->omx_report_error (); |
| 959 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 960 | } |
| 961 | break; |
| 962 | |
| 963 | case OMX_COMPONENT_GENERATE_FTB: |
| 964 | if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 965 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 966 | DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 967 | pThis->omx_report_error (); |
| 968 | } |
| 969 | break; |
| 970 | |
| 971 | case OMX_COMPONENT_GENERATE_COMMAND: |
| 972 | pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\ |
| 973 | (OMX_U32)p2,(OMX_PTR)NULL); |
| 974 | break; |
| 975 | |
| 976 | case OMX_COMPONENT_GENERATE_EBD: |
| 977 | |
| 978 | if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 979 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 980 | pThis->omx_report_error (); |
| 981 | } else { |
| 982 | if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 983 | pThis->time_stamp_dts.remove_time_stamp( |
| 984 | ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp, |
| 985 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 986 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 987 | } |
Deva Ramasubramanian | 02b0d88 | 2014-04-03 14:58:50 -0700 | [diff] [blame] | 988 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 989 | if ( pThis->empty_buffer_done(&pThis->m_cmp, |
| 990 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 991 | DEBUG_PRINT_ERROR("empty_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 992 | pThis->omx_report_error (); |
| 993 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 994 | } |
| 995 | break; |
| 996 | case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: { |
| 997 | int64_t *timestamp = (int64_t *)p1; |
| 998 | if (p1) { |
| 999 | pThis->time_stamp_dts.remove_time_stamp(*timestamp, |
| 1000 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 1001 | ?true:false); |
| 1002 | free(timestamp); |
| 1003 | } |
| 1004 | } |
| 1005 | break; |
| 1006 | case OMX_COMPONENT_GENERATE_FBD: |
| 1007 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1008 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1009 | pThis->omx_report_error (); |
| 1010 | } else if ( pThis->fill_buffer_done(&pThis->m_cmp, |
| 1011 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1012 | DEBUG_PRINT_ERROR("fill_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1013 | pThis->omx_report_error (); |
| 1014 | } |
| 1015 | break; |
| 1016 | |
| 1017 | case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1018 | DEBUG_PRINT_HIGH("Driver flush i/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1019 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1020 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1021 | } else { |
| 1022 | pThis->execute_input_flush(); |
| 1023 | if (pThis->m_cb.EventHandler) { |
| 1024 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1025 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1026 | pThis->omx_report_error (); |
| 1027 | } else { |
| 1028 | /*Check if we need generate event for Flush done*/ |
| 1029 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1030 | OMX_COMPONENT_INPUT_FLUSH_PENDING)) { |
| 1031 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1032 | DEBUG_PRINT_LOW("Input Flush completed - Notify Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1033 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1034 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1035 | OMX_CORE_INPUT_PORT_INDEX,NULL ); |
| 1036 | } |
| 1037 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1038 | OMX_COMPONENT_IDLE_PENDING)) { |
| 1039 | if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1040 | DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1041 | pThis->omx_report_error (); |
| 1042 | } else { |
| 1043 | pThis->streaming[OUTPUT_PORT] = false; |
| 1044 | } |
| 1045 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1046 | DEBUG_PRINT_LOW("Input flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1047 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1048 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | } else { |
| 1053 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1054 | } |
| 1055 | } |
| 1056 | break; |
| 1057 | |
| 1058 | case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1059 | DEBUG_PRINT_HIGH("Driver flush o/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1060 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1061 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1062 | } else { |
| 1063 | pThis->execute_output_flush(); |
| 1064 | if (pThis->m_cb.EventHandler) { |
| 1065 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1066 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1067 | pThis->omx_report_error (); |
| 1068 | } else { |
| 1069 | /*Check if we need generate event for Flush done*/ |
| 1070 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1071 | OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1072 | DEBUG_PRINT_LOW("Notify Output Flush done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1073 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 1074 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1075 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1076 | OMX_CORE_OUTPUT_PORT_INDEX,NULL ); |
| 1077 | } |
| 1078 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1079 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1080 | DEBUG_PRINT_LOW("Internal flush complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1081 | BITMASK_CLEAR (&pThis->m_flags, |
| 1082 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 1083 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1084 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) { |
| 1085 | pThis->post_event(OMX_CommandPortDisable, |
| 1086 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 1087 | OMX_COMPONENT_GENERATE_EVENT); |
| 1088 | BITMASK_CLEAR (&pThis->m_flags, |
| 1089 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
Praneeth Paladugu | b52072a | 2013-08-23 13:54:43 -0700 | [diff] [blame] | 1090 | BITMASK_CLEAR (&pThis->m_flags, |
| 1091 | OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1092 | |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) { |
| 1097 | if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1098 | DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1099 | pThis->omx_report_error (); |
| 1100 | break; |
| 1101 | } |
| 1102 | pThis->streaming[CAPTURE_PORT] = false; |
| 1103 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1104 | DEBUG_PRINT_LOW("Output flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1105 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1106 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | } else { |
| 1111 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1112 | } |
| 1113 | } |
| 1114 | break; |
| 1115 | |
| 1116 | case OMX_COMPONENT_GENERATE_START_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1117 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1118 | |
| 1119 | if (pThis->m_cb.EventHandler) { |
| 1120 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1121 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1122 | pThis->omx_report_error (); |
| 1123 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1124 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1125 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1126 | DEBUG_PRINT_LOW("Move to executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1127 | // Send the callback now |
| 1128 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1129 | pThis->m_state = OMX_StateExecuting; |
| 1130 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1131 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1132 | OMX_StateExecuting, NULL); |
| 1133 | } else if (BITMASK_PRESENT(&pThis->m_flags, |
| 1134 | OMX_COMPONENT_PAUSE_PENDING)) { |
| 1135 | if (/*ioctl (pThis->drv_ctx.video_driver_fd, |
| 1136 | VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1137 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1138 | pThis->omx_report_error (); |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1143 | DEBUG_PRINT_LOW("Event Handler callback is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1144 | } |
| 1145 | break; |
| 1146 | |
| 1147 | case OMX_COMPONENT_GENERATE_PAUSE_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1148 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1149 | if (pThis->m_cb.EventHandler) { |
| 1150 | if (p2 != VDEC_S_SUCCESS) { |
| 1151 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed"); |
| 1152 | pThis->omx_report_error (); |
| 1153 | } else { |
| 1154 | pThis->complete_pending_buffer_done_cbs(); |
| 1155 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1156 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1157 | //Send the callback now |
| 1158 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING); |
| 1159 | pThis->m_state = OMX_StatePause; |
| 1160 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1161 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1162 | OMX_StatePause, NULL); |
| 1163 | } |
| 1164 | } |
| 1165 | } else { |
| 1166 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1167 | } |
| 1168 | |
| 1169 | break; |
| 1170 | |
| 1171 | case OMX_COMPONENT_GENERATE_RESUME_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1172 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1173 | if (pThis->m_cb.EventHandler) { |
| 1174 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1175 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1176 | pThis->omx_report_error (); |
| 1177 | } else { |
| 1178 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1179 | DEBUG_PRINT_LOW("Moving the decoder to execute state"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1180 | // Send the callback now |
| 1181 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1182 | pThis->m_state = OMX_StateExecuting; |
| 1183 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1184 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1185 | OMX_StateExecuting,NULL); |
| 1186 | } |
| 1187 | } |
| 1188 | } else { |
| 1189 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1190 | } |
| 1191 | |
| 1192 | break; |
| 1193 | |
| 1194 | case OMX_COMPONENT_GENERATE_STOP_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1195 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1196 | if (pThis->m_cb.EventHandler) { |
| 1197 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1198 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1199 | pThis->omx_report_error (); |
| 1200 | } else { |
| 1201 | pThis->complete_pending_buffer_done_cbs(); |
| 1202 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1203 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1204 | // Send the callback now |
| 1205 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 1206 | pThis->m_state = OMX_StateIdle; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1207 | DEBUG_PRINT_LOW("Move to Idle State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1208 | pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data, |
| 1209 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1210 | OMX_StateIdle,NULL); |
| 1211 | } |
| 1212 | } |
| 1213 | } else { |
| 1214 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1215 | } |
| 1216 | |
| 1217 | break; |
| 1218 | |
| 1219 | case OMX_COMPONENT_GENERATE_PORT_RECONFIG: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1220 | if (p2 == OMX_IndexParamPortDefinition) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1221 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1222 | pThis->in_reconfig = true; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1223 | |
| 1224 | } else if (p2 == OMX_IndexConfigCommonOutputCrop) { |
| 1225 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexConfigCommonOutputCrop"); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1226 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1227 | /* Check if resolution is changed in smooth streaming mode */ |
| 1228 | if (pThis->m_smoothstreaming_mode && |
| 1229 | (pThis->framesize.nWidth != |
| 1230 | pThis->drv_ctx.video_resolution.frame_width) || |
| 1231 | (pThis->framesize.nHeight != |
| 1232 | pThis->drv_ctx.video_resolution.frame_height)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1233 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1234 | DEBUG_PRINT_HIGH("Resolution changed from: wxh = %dx%d to: wxh = %dx%d", |
| 1235 | pThis->framesize.nWidth, |
| 1236 | pThis->framesize.nHeight, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1237 | pThis->drv_ctx.video_resolution.frame_width, |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1238 | pThis->drv_ctx.video_resolution.frame_height); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1239 | |
| 1240 | /* Update new resolution */ |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1241 | pThis->framesize.nWidth = |
| 1242 | pThis->drv_ctx.video_resolution.frame_width; |
| 1243 | pThis->framesize.nHeight = |
| 1244 | pThis->drv_ctx.video_resolution.frame_height; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1245 | |
| 1246 | /* Update C2D with new resolution */ |
| 1247 | if (!pThis->client_buffers.update_buffer_req()) { |
| 1248 | DEBUG_PRINT_ERROR("Setting C2D buffer requirements failed"); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | /* Update new crop information */ |
| 1253 | pThis->rectangle.nLeft = pThis->drv_ctx.frame_size.left; |
| 1254 | pThis->rectangle.nTop = pThis->drv_ctx.frame_size.top; |
| 1255 | pThis->rectangle.nWidth = pThis->drv_ctx.frame_size.right; |
| 1256 | pThis->rectangle.nHeight = pThis->drv_ctx.frame_size.bottom; |
| 1257 | |
| 1258 | /* Validate the new crop information */ |
| 1259 | if (pThis->rectangle.nLeft + pThis->rectangle.nWidth > |
| 1260 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1261 | |
| 1262 | DEBUG_PRINT_HIGH("Crop L[%u] + R[%u] > W[%u]", |
| 1263 | pThis->rectangle.nLeft, pThis->rectangle.nWidth, |
| 1264 | pThis->drv_ctx.video_resolution.frame_width); |
| 1265 | pThis->rectangle.nLeft = 0; |
| 1266 | |
| 1267 | if (pThis->rectangle.nWidth > |
| 1268 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1269 | |
| 1270 | DEBUG_PRINT_HIGH("Crop R[%u] > W[%u]", |
| 1271 | pThis->rectangle.nWidth, |
| 1272 | pThis->drv_ctx.video_resolution.frame_width); |
| 1273 | pThis->rectangle.nWidth = |
| 1274 | pThis->drv_ctx.video_resolution.frame_width; |
| 1275 | } |
| 1276 | } |
| 1277 | if (pThis->rectangle.nTop + pThis->rectangle.nHeight > |
| 1278 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1279 | |
| 1280 | DEBUG_PRINT_HIGH("Crop T[%u] + B[%u] > H[%u]", |
| 1281 | pThis->rectangle.nTop, pThis->rectangle.nHeight, |
| 1282 | pThis->drv_ctx.video_resolution.frame_height); |
| 1283 | pThis->rectangle.nTop = 0; |
| 1284 | |
| 1285 | if (pThis->rectangle.nHeight > |
| 1286 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1287 | |
| 1288 | DEBUG_PRINT_HIGH("Crop B[%u] > H[%u]", |
| 1289 | pThis->rectangle.nHeight, |
| 1290 | pThis->drv_ctx.video_resolution.frame_height); |
| 1291 | pThis->rectangle.nHeight = |
| 1292 | pThis->drv_ctx.video_resolution.frame_height; |
| 1293 | } |
| 1294 | } |
| 1295 | DEBUG_PRINT_HIGH("Updated Crop Info: L: %u, T: %u, R: %u, B: %u", |
| 1296 | pThis->rectangle.nLeft, pThis->rectangle.nTop, |
| 1297 | pThis->rectangle.nWidth, pThis->rectangle.nHeight); |
| 1298 | } else { |
| 1299 | DEBUG_PRINT_ERROR("Rxd Invalid PORT_RECONFIG event (%lu)", p2); |
| 1300 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1301 | } |
| 1302 | if (pThis->m_cb.EventHandler) { |
| 1303 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1304 | OMX_EventPortSettingsChanged, p1, p2, NULL ); |
| 1305 | } else { |
| 1306 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1307 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1308 | break; |
| 1309 | |
| 1310 | case OMX_COMPONENT_GENERATE_EOS_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1311 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1312 | if (pThis->m_cb.EventHandler) { |
| 1313 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag, |
| 1314 | OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL ); |
| 1315 | } else { |
| 1316 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1317 | } |
| 1318 | pThis->prev_ts = LLONG_MAX; |
| 1319 | pThis->rst_prev_ts = true; |
| 1320 | break; |
| 1321 | |
| 1322 | case OMX_COMPONENT_GENERATE_HARDWARE_ERROR: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1323 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1324 | pThis->omx_report_error (); |
| 1325 | break; |
| 1326 | |
| 1327 | case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1328 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1329 | pThis->omx_report_unsupported_setting(); |
| 1330 | break; |
| 1331 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 1332 | case OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD: |
| 1333 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD"); |
| 1334 | pThis->omx_report_hw_overload(); |
| 1335 | break; |
| 1336 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1337 | default: |
| 1338 | break; |
| 1339 | } |
| 1340 | } |
| 1341 | pthread_mutex_lock(&pThis->m_lock); |
| 1342 | qsize = pThis->m_cmd_q.m_size; |
| 1343 | if (pThis->m_state != OMX_StatePause) |
| 1344 | qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size); |
| 1345 | pthread_mutex_unlock(&pThis->m_lock); |
| 1346 | } while (qsize>0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1347 | |
| 1348 | } |
| 1349 | |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 1350 | 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] | 1351 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1352 | int format_changed = 0; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 1353 | if ((height != (int)drv_ctx.video_resolution.frame_height) || |
| 1354 | (width != (int)drv_ctx.video_resolution.frame_width)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1355 | DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1356 | width, drv_ctx.video_resolution.frame_width, |
| 1357 | height,drv_ctx.video_resolution.frame_height); |
| 1358 | format_changed = 1; |
| 1359 | } |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1360 | drv_ctx.video_resolution.frame_height = height; |
| 1361 | drv_ctx.video_resolution.frame_width = width; |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 1362 | drv_ctx.video_resolution.scan_lines = scan_lines; |
| 1363 | drv_ctx.video_resolution.stride = stride; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 1364 | if(!is_down_scalar_enabled) { |
| 1365 | rectangle.nLeft = 0; |
| 1366 | rectangle.nTop = 0; |
| 1367 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1368 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
| 1369 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1370 | return format_changed; |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1371 | } |
| 1372 | |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1373 | OMX_ERRORTYPE omx_vdec::is_video_session_supported() |
| 1374 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1375 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", |
| 1376 | OMX_MAX_STRINGNAME_SIZE) && |
| 1377 | (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) { |
| 1378 | m_decoder_capability.max_width = 1280; |
| 1379 | m_decoder_capability.max_height = 720; |
| 1380 | DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP"); |
| 1381 | } |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 1382 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1383 | if ((drv_ctx.video_resolution.frame_width * |
| 1384 | drv_ctx.video_resolution.frame_height > |
| 1385 | m_decoder_capability.max_width * |
| 1386 | m_decoder_capability.max_height) || |
| 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 | DEBUG_PRINT_ERROR( |
| 1392 | "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)", |
| 1393 | drv_ctx.video_resolution.frame_width, |
| 1394 | drv_ctx.video_resolution.frame_height, |
| 1395 | m_decoder_capability.min_width, |
| 1396 | m_decoder_capability.min_height, |
| 1397 | m_decoder_capability.max_width, |
| 1398 | m_decoder_capability.max_height); |
| 1399 | return OMX_ErrorUnsupportedSetting; |
| 1400 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1401 | DEBUG_PRINT_HIGH("video session supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1402 | return OMX_ErrorNone; |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1405 | int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len) |
| 1406 | { |
| 1407 | if (m_debug.in_buffer_log && !m_debug.infile) { |
| 1408 | if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) { |
| 1409 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v", |
| 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.mpeg2", OMX_MAX_STRINGNAME_SIZE)) { |
| 1413 | 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); } |
| 1414 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) { |
| 1415 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263", |
| 1416 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1417 | } |
| 1418 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) { |
| 1419 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264", |
| 1420 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1421 | } |
| 1422 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) { |
| 1423 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1424 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1425 | } |
| 1426 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) { |
| 1427 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1428 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1429 | } |
| 1430 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1431 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf", |
| 1432 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1433 | } |
| 1434 | m_debug.infile = fopen (m_debug.infile_name, "ab"); |
| 1435 | if (!m_debug.infile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1436 | 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] | 1437 | m_debug.infile_name[0] = '\0'; |
| 1438 | return -1; |
| 1439 | } |
| 1440 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1441 | struct ivf_file_header { |
| 1442 | OMX_U8 signature[4]; //='DKIF'; |
| 1443 | OMX_U8 version ; //= 0; |
| 1444 | OMX_U8 headersize ; //= 32; |
| 1445 | OMX_U32 FourCC; |
| 1446 | OMX_U8 width; |
| 1447 | OMX_U8 height; |
| 1448 | OMX_U32 rate; |
| 1449 | OMX_U32 scale; |
| 1450 | OMX_U32 length; |
| 1451 | OMX_U8 unused[4]; |
| 1452 | } file_header; |
| 1453 | |
| 1454 | memset((void *)&file_header,0,sizeof(file_header)); |
| 1455 | file_header.signature[0] = 'D'; |
| 1456 | file_header.signature[1] = 'K'; |
| 1457 | file_header.signature[2] = 'I'; |
| 1458 | file_header.signature[3] = 'F'; |
| 1459 | file_header.version = 0; |
| 1460 | file_header.headersize = 32; |
| 1461 | file_header.FourCC = 0x30385056; |
| 1462 | fwrite((const char *)&file_header, |
| 1463 | sizeof(file_header),1,m_debug.infile); |
| 1464 | } |
| 1465 | } |
| 1466 | if (m_debug.infile && buffer_addr && buffer_len) { |
| 1467 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1468 | struct vp8_ivf_frame_header { |
| 1469 | OMX_U32 framesize; |
| 1470 | OMX_U32 timestamp_lo; |
| 1471 | OMX_U32 timestamp_hi; |
| 1472 | } vp8_frame_header; |
| 1473 | vp8_frame_header.framesize = buffer_len; |
| 1474 | /* Currently FW doesn't use timestamp values */ |
| 1475 | vp8_frame_header.timestamp_lo = 0; |
| 1476 | vp8_frame_header.timestamp_hi = 0; |
| 1477 | fwrite((const char *)&vp8_frame_header, |
| 1478 | sizeof(vp8_frame_header),1,m_debug.infile); |
| 1479 | } |
| 1480 | fwrite(buffer_addr, buffer_len, 1, m_debug.infile); |
| 1481 | } |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
| 1485 | int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) { |
| 1486 | if (m_debug.out_buffer_log && !m_debug.outfile) { |
| 1487 | sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv", |
| 1488 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1489 | m_debug.outfile = fopen (m_debug.outfile_name, "ab"); |
| 1490 | if (!m_debug.outfile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1491 | 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] | 1492 | m_debug.outfile_name[0] = '\0'; |
| 1493 | return -1; |
| 1494 | } |
| 1495 | } |
| 1496 | if (m_debug.outfile && buffer && buffer->nFilledLen) { |
| 1497 | int buf_index = buffer - m_out_mem_ptr; |
| 1498 | int stride = drv_ctx.video_resolution.stride; |
| 1499 | int scanlines = drv_ctx.video_resolution.scan_lines; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1500 | if (m_smoothstreaming_mode) { |
| 1501 | stride = drv_ctx.video_resolution.frame_width; |
| 1502 | scanlines = drv_ctx.video_resolution.frame_height; |
| 1503 | stride = (stride + DEFAULT_WIDTH_ALIGNMENT - 1) & (~(DEFAULT_WIDTH_ALIGNMENT - 1)); |
| 1504 | scanlines = (scanlines + DEFAULT_HEIGHT_ALIGNMENT - 1) & (~(DEFAULT_HEIGHT_ALIGNMENT - 1)); |
| 1505 | } |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1506 | char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr; |
| 1507 | unsigned i; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1508 | DEBUG_PRINT_HIGH("Logging width/height(%u/%u) stride/scanlines(%u/%u)", |
| 1509 | drv_ctx.video_resolution.frame_width, |
| 1510 | drv_ctx.video_resolution.frame_height, stride, scanlines); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1511 | int bytes_written = 0; |
| 1512 | for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) { |
| 1513 | bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1514 | temp += stride; |
| 1515 | } |
| 1516 | temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines; |
| 1517 | int stride_c = stride; |
| 1518 | for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) { |
| 1519 | bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1520 | temp += stride_c; |
| 1521 | } |
| 1522 | } |
| 1523 | return 0; |
| 1524 | } |
| 1525 | |
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 | FUNCTION |
| 1528 | omx_vdec::ComponentInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1529 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1530 | DESCRIPTION |
| 1531 | Initialize the component. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1532 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1533 | PARAMETERS |
| 1534 | ctxt -- Context information related to the self. |
| 1535 | id -- Event identifier. This could be any of the following: |
| 1536 | 1. Command completion event |
| 1537 | 2. Buffer done callback event |
| 1538 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1539 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1540 | RETURN VALUE |
| 1541 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1542 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1543 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1544 | OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role) |
| 1545 | { |
| 1546 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1547 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 1548 | struct v4l2_fmtdesc fdesc; |
| 1549 | struct v4l2_format fmt; |
| 1550 | struct v4l2_requestbuffers bufreq; |
| 1551 | struct v4l2_control control; |
| 1552 | struct v4l2_frmsizeenum frmsize; |
| 1553 | unsigned int alignment = 0,buffer_size = 0; |
| 1554 | int fds[2]; |
| 1555 | int r,ret=0; |
| 1556 | bool codec_ambiguous = false; |
Praveen Chavan | 00ec0ce | 2015-05-18 09:44:20 -0700 | [diff] [blame] | 1557 | OMX_STRING device_name = (OMX_STRING)"/dev/video32"; |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 1558 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1559 | |
| 1560 | #ifdef _ANDROID_ |
Praveen Chavan | e9e5620 | 2013-09-19 03:48:16 -0700 | [diff] [blame] | 1561 | char platform_name[PROPERTY_VALUE_MAX]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1562 | property_get("ro.board.platform", platform_name, "0"); |
| 1563 | if (!strncmp(platform_name, "msm8610", 7)) { |
Balamurugan Alagarsamy | 1693e59 | 2015-07-23 19:19:05 +0530 | [diff] [blame] | 1564 | device_name = (OMX_STRING)"/dev/video34"; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1565 | is_q6_platform = true; |
| 1566 | maxSmoothStreamingWidth = 1280; |
| 1567 | maxSmoothStreamingHeight = 720; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1568 | } |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1569 | #endif |
| 1570 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1571 | if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) { |
| 1572 | struct v4l2_control control; |
| 1573 | secure_mode = true; |
| 1574 | arbitrary_bytes = false; |
| 1575 | role = (OMX_STRING)"OMX.qcom.video.decoder.avc"; |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 1576 | } else if (!strncmp(role, "OMX.qcom.video.decoder.mpeg2.secure", |
| 1577 | OMX_MAX_STRINGNAME_SIZE)){ |
| 1578 | secure_mode = true; |
| 1579 | arbitrary_bytes = false; |
| 1580 | role = (OMX_STRING)"OMX.qcom.video.decoder.mpeg2"; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1581 | } |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1582 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1583 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1584 | |
Balamurugan Alagarsamy | 1693e59 | 2015-07-23 19:19:05 +0530 | [diff] [blame] | 1585 | DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open device %s returned fd %d", |
| 1586 | device_name, drv_ctx.video_driver_fd); |
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_msm8974 :: Got fd as 0 for msm_vidc_dec, Opening again"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1590 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
| 1591 | close(0); |
| 1592 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1593 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1594 | if (drv_ctx.video_driver_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1595 | DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1596 | return OMX_ErrorInsufficientResources; |
| 1597 | } |
| 1598 | drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS; |
| 1599 | drv_ctx.frame_rate.fps_denominator = 1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1600 | |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1601 | ret = subscribe_to_events(drv_ctx.video_driver_fd); |
Vinay Kalia | 184cd0f | 2013-04-29 18:26:42 -0700 | [diff] [blame] | 1602 | if (!ret) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1603 | async_thread_created = true; |
| 1604 | ret = pthread_create(&async_thread_id,0,async_message_thread,this); |
| 1605 | } |
| 1606 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1607 | DEBUG_PRINT_ERROR("Failed to create async_message_thread"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1608 | async_thread_created = false; |
| 1609 | return OMX_ErrorInsufficientResources; |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1610 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1611 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1612 | #ifdef OUTPUT_EXTRADATA_LOG |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 1613 | outputExtradataFile = fopen (output_extradata_filename, "ab"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1614 | #endif |
| 1615 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1616 | // Copy the role information which provides the decoder kind |
| 1617 | strlcpy(drv_ctx.kind,role,128); |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1618 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1619 | if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\ |
| 1620 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1621 | strlcpy((char *)m_cRole, "video_decoder.mpeg4",\ |
| 1622 | OMX_MAX_STRINGNAME_SIZE); |
| 1623 | drv_ctx.timestamp_adjust = true; |
| 1624 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4; |
| 1625 | eCompressionFormat = OMX_VIDEO_CodingMPEG4; |
| 1626 | output_capability=V4L2_PIX_FMT_MPEG4; |
| 1627 | /*Initialize Start Code for MPEG4*/ |
| 1628 | codec_type_parse = CODEC_TYPE_MPEG4; |
| 1629 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1630 | } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\ |
| 1631 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1632 | strlcpy((char *)m_cRole, "video_decoder.mpeg2",\ |
| 1633 | OMX_MAX_STRINGNAME_SIZE); |
| 1634 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2; |
| 1635 | output_capability = V4L2_PIX_FMT_MPEG2; |
| 1636 | eCompressionFormat = OMX_VIDEO_CodingMPEG2; |
| 1637 | /*Initialize Start Code for MPEG2*/ |
| 1638 | codec_type_parse = CODEC_TYPE_MPEG2; |
| 1639 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1640 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\ |
| 1641 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1642 | strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1643 | DEBUG_PRINT_LOW("H263 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1644 | drv_ctx.decoder_format = VDEC_CODECTYPE_H263; |
| 1645 | eCompressionFormat = OMX_VIDEO_CodingH263; |
| 1646 | output_capability = V4L2_PIX_FMT_H263; |
| 1647 | codec_type_parse = CODEC_TYPE_H263; |
| 1648 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1649 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\ |
| 1650 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1651 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1652 | DEBUG_PRINT_LOW ("DIVX 311 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1653 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3; |
| 1654 | output_capability = V4L2_PIX_FMT_DIVX_311; |
| 1655 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1656 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1657 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1658 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1659 | eRet = createDivxDrmContext(); |
| 1660 | if (eRet != OMX_ErrorNone) { |
| 1661 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1662 | return eRet; |
| 1663 | } |
| 1664 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\ |
| 1665 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1666 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1667 | DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1668 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4; |
| 1669 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1670 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1671 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1672 | codec_ambiguous = true; |
| 1673 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1674 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1675 | eRet = createDivxDrmContext(); |
| 1676 | if (eRet != OMX_ErrorNone) { |
| 1677 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1678 | return eRet; |
| 1679 | } |
| 1680 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\ |
| 1681 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1682 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1683 | DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1684 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6; |
| 1685 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1686 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1687 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1688 | codec_ambiguous = true; |
| 1689 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1690 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1691 | eRet = createDivxDrmContext(); |
| 1692 | if (eRet != OMX_ErrorNone) { |
| 1693 | DEBUG_PRINT_ERROR("createDivxDrmContext Failed"); |
| 1694 | return eRet; |
| 1695 | } |
Deva Ramasubramanian | 9403f02 | 2012-11-28 18:27:53 -0800 | [diff] [blame] | 1696 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1697 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\ |
| 1698 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1699 | strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 1700 | drv_ctx.decoder_format = VDEC_CODECTYPE_H264; |
| 1701 | output_capability=V4L2_PIX_FMT_H264; |
| 1702 | eCompressionFormat = OMX_VIDEO_CodingAVC; |
| 1703 | codec_type_parse = CODEC_TYPE_H264; |
| 1704 | m_frame_parser.init_start_codes (codec_type_parse); |
| 1705 | m_frame_parser.init_nal_length(nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1706 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\ |
| 1707 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1708 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1709 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1; |
| 1710 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1711 | codec_type_parse = CODEC_TYPE_VC1; |
| 1712 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_G; |
| 1713 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1714 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\ |
| 1715 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1716 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1717 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV; |
| 1718 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1719 | codec_type_parse = CODEC_TYPE_VC1; |
| 1720 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_L; |
| 1721 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1722 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \ |
| 1723 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1724 | strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 1725 | output_capability=V4L2_PIX_FMT_VP8; |
Praveen Chavan | 76b71c3 | 2014-07-10 18:10:51 -0700 | [diff] [blame] | 1726 | eCompressionFormat = OMX_VIDEO_CodingVP8; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1727 | codec_type_parse = CODEC_TYPE_VP8; |
| 1728 | arbitrary_bytes = false; |
Praneeth Paladugu | 2b2ef2d | 2013-04-10 22:04:51 -0700 | [diff] [blame] | 1729 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1730 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1731 | DEBUG_PRINT_ERROR("ERROR:Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1732 | eRet = OMX_ErrorInvalidComponentName; |
| 1733 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1734 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1735 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1736 | drv_ctx.output_format = VDEC_YUV_FORMAT_NV12; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1737 | OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 1738 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 1739 | if (!client_buffers.set_color_format(dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1740 | DEBUG_PRINT_ERROR("Setting color format failed"); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1741 | eRet = OMX_ErrorInsufficientResources; |
| 1742 | } |
| 1743 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1744 | capture_capability= V4L2_PIX_FMT_NV12; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1745 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1746 | struct v4l2_capability cap; |
| 1747 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap); |
| 1748 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1749 | DEBUG_PRINT_ERROR("Failed to query capabilities"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1750 | /*TODO: How to handle this case */ |
| 1751 | } else { |
| 1752 | DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s," |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1753 | " version = %d, capabilities = %x", cap.driver, cap.card, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1754 | cap.bus_info, cap.version, cap.capabilities); |
| 1755 | } |
| 1756 | ret=0; |
| 1757 | fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1758 | fdesc.index=0; |
| 1759 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1760 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1761 | fdesc.pixelformat, fdesc.flags); |
| 1762 | fdesc.index++; |
| 1763 | } |
| 1764 | fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1765 | fdesc.index=0; |
| 1766 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1767 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1768 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1769 | fdesc.pixelformat, fdesc.flags); |
| 1770 | fdesc.index++; |
| 1771 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1772 | update_resolution(320, 240, 320, 240); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1773 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1774 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1775 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1776 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 1777 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1778 | if (ret) { |
| 1779 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1780 | DEBUG_PRINT_ERROR("Failed to set format on output port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1781 | return OMX_ErrorInsufficientResources; |
| 1782 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1783 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1784 | if (codec_ambiguous) { |
| 1785 | if (output_capability == V4L2_PIX_FMT_DIVX) { |
| 1786 | struct v4l2_control divx_ctrl; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1787 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1788 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) { |
| 1789 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4; |
| 1790 | } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) { |
| 1791 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5; |
| 1792 | } else { |
| 1793 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6; |
| 1794 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1795 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1796 | divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT; |
| 1797 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl); |
| 1798 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1799 | DEBUG_PRINT_ERROR("Failed to set divx version"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1800 | } |
| 1801 | } else { |
| 1802 | DEBUG_PRINT_ERROR("Codec should not be ambiguous"); |
| 1803 | } |
| 1804 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1805 | |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 1806 | property_get("persist.vidc.dec.conceal_color", property_value, DEFAULT_CONCEAL_COLOR); |
| 1807 | m_conceal_color= atoi(property_value); |
| 1808 | DEBUG_PRINT_HIGH("trying to set 0x%x as conceal color\n",m_conceal_color); |
| 1809 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR; |
| 1810 | control.value = m_conceal_color; |
| 1811 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 1812 | if (ret) { |
| 1813 | DEBUG_PRINT_ERROR("Failed to set conceal color %d\n", ret); |
| 1814 | } |
| 1815 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1816 | //Get the hardware capabilities |
| 1817 | memset((void *)&frmsize,0,sizeof(frmsize)); |
| 1818 | frmsize.index = 0; |
| 1819 | frmsize.pixel_format = output_capability; |
| 1820 | ret = ioctl(drv_ctx.video_driver_fd, |
| 1821 | VIDIOC_ENUM_FRAMESIZES, &frmsize); |
| 1822 | if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1823 | DEBUG_PRINT_ERROR("Failed to get framesizes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1824 | return OMX_ErrorHardware; |
| 1825 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1826 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1827 | if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) { |
| 1828 | m_decoder_capability.min_width = frmsize.stepwise.min_width; |
| 1829 | m_decoder_capability.max_width = frmsize.stepwise.max_width; |
| 1830 | m_decoder_capability.min_height = frmsize.stepwise.min_height; |
| 1831 | m_decoder_capability.max_height = frmsize.stepwise.max_height; |
| 1832 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1833 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1834 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1835 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1836 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1837 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 1838 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1839 | if (ret) { |
| 1840 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1841 | DEBUG_PRINT_ERROR("Failed to set format on capture port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1842 | } |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1843 | memset(&framesize, 0, sizeof(OMX_FRAMESIZETYPE)); |
| 1844 | framesize.nWidth = drv_ctx.video_resolution.frame_width; |
| 1845 | framesize.nHeight = drv_ctx.video_resolution.frame_height; |
| 1846 | |
| 1847 | memset(&rectangle, 0, sizeof(OMX_CONFIG_RECTTYPE)); |
| 1848 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1849 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
| 1850 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1851 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1852 | if (secure_mode) { |
| 1853 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE; |
| 1854 | control.value = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1855 | DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1856 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 1857 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1858 | DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1859 | return OMX_ErrorInsufficientResources; |
| 1860 | } |
| 1861 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1862 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1863 | /*Get the Buffer requirements for input and output ports*/ |
| 1864 | drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 1865 | drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 1866 | if (secure_mode) { |
| 1867 | drv_ctx.op_buf.alignment=SZ_1M; |
| 1868 | drv_ctx.ip_buf.alignment=SZ_1M; |
| 1869 | } else { |
| 1870 | drv_ctx.op_buf.alignment=SZ_4K; |
| 1871 | drv_ctx.ip_buf.alignment=SZ_4K; |
| 1872 | } |
| 1873 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 1874 | drv_ctx.extradata = 0; |
| 1875 | drv_ctx.picture_order = VDEC_ORDER_DISPLAY; |
| 1876 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 1877 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 1878 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 1879 | drv_ctx.idr_only_decoding = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1880 | |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1881 | m_state = OMX_StateLoaded; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1882 | #ifdef DEFAULT_EXTRADATA |
Arun Menon | f8908a6 | 2013-12-20 17:36:21 -0800 | [diff] [blame] | 1883 | if (strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", |
| 1884 | OMX_MAX_STRINGNAME_SIZE) && (eRet == OMX_ErrorNone)) |
| 1885 | enable_extradata(DEFAULT_EXTRADATA, true, true); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1886 | #endif |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1887 | eRet=get_buffer_req(&drv_ctx.ip_buf); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1888 | 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] | 1889 | get_buffer_req(&drv_ctx.op_buf); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1890 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
| 1891 | if (m_frame_parser.mutils == NULL) { |
| 1892 | m_frame_parser.mutils = new H264_Utils(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1893 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1894 | if (m_frame_parser.mutils == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1895 | DEBUG_PRINT_ERROR("parser utils Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1896 | eRet = OMX_ErrorInsufficientResources; |
| 1897 | } else { |
| 1898 | h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 1899 | h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size); |
| 1900 | h264_scratch.nFilledLen = 0; |
| 1901 | h264_scratch.nOffset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1902 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1903 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1904 | DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1905 | return OMX_ErrorInsufficientResources; |
| 1906 | } |
| 1907 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 1908 | m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size); |
| 1909 | } |
| 1910 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1911 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1912 | h264_parser = new h264_stream_parser(); |
| 1913 | if (!h264_parser) { |
| 1914 | DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!"); |
| 1915 | eRet = OMX_ErrorInsufficientResources; |
| 1916 | } |
| 1917 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1918 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1919 | if (pipe(fds)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1920 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1921 | eRet = OMX_ErrorInsufficientResources; |
| 1922 | } else { |
| 1923 | int temp1[2]; |
| 1924 | if (fds[0] == 0 || fds[1] == 0) { |
| 1925 | if (pipe (temp1)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1926 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1927 | return OMX_ErrorInsufficientResources; |
| 1928 | } |
| 1929 | //close (fds[0]); |
| 1930 | //close (fds[1]); |
| 1931 | fds[0] = temp1 [0]; |
| 1932 | fds[1] = temp1 [1]; |
| 1933 | } |
| 1934 | m_pipe_in = fds[0]; |
| 1935 | m_pipe_out = fds[1]; |
| 1936 | msg_thread_created = true; |
Ashray Kulkarni | a97efbc | 2015-07-15 18:17:23 -0700 | [diff] [blame] | 1937 | r = pthread_create(&msg_thread_id,0, dec_message_thread,this); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1938 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1939 | if (r < 0) { |
Ashray Kulkarni | a97efbc | 2015-07-15 18:17:23 -0700 | [diff] [blame] | 1940 | DEBUG_PRINT_ERROR("component_init(): dec_message_thread creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1941 | msg_thread_created = false; |
| 1942 | eRet = OMX_ErrorInsufficientResources; |
| 1943 | } |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | if (eRet != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1948 | DEBUG_PRINT_ERROR("Component Init Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1949 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1950 | DEBUG_PRINT_HIGH("omx_vdec::component_init() success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1951 | } |
| 1952 | //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer)); |
Praveen Chavan | 898df26 | 2015-04-20 18:52:19 -0700 | [diff] [blame] | 1953 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY; |
| 1954 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE; |
| 1955 | |
| 1956 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 1957 | DEBUG_PRINT_ERROR("Failed to set Default Priority"); |
| 1958 | eRet = OMX_ErrorUnsupportedSetting; |
| 1959 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1960 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1964 | FUNCTION |
| 1965 | omx_vdec::GetComponentVersion |
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 | DESCRIPTION |
| 1968 | Returns the component version. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1969 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1970 | PARAMETERS |
| 1971 | TBD. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1972 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1973 | RETURN VALUE |
| 1974 | OMX_ErrorNone. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1975 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1976 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1977 | OMX_ERRORTYPE omx_vdec::get_component_version |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1978 | ( |
| 1979 | OMX_IN OMX_HANDLETYPE hComp, |
| 1980 | OMX_OUT OMX_STRING componentName, |
| 1981 | OMX_OUT OMX_VERSIONTYPE* componentVersion, |
| 1982 | OMX_OUT OMX_VERSIONTYPE* specVersion, |
| 1983 | OMX_OUT OMX_UUIDTYPE* componentUUID |
| 1984 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1985 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1986 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1987 | DEBUG_PRINT_ERROR("Get Comp Version in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1988 | return OMX_ErrorInvalidState; |
| 1989 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1990 | /* TBD -- Return the proper version */ |
| 1991 | if (specVersion) { |
| 1992 | specVersion->nVersion = OMX_SPEC_VERSION; |
| 1993 | } |
| 1994 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1995 | } |
| 1996 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1997 | FUNCTION |
| 1998 | omx_vdec::SendCommand |
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 | DESCRIPTION |
| 2001 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2002 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2003 | PARAMETERS |
| 2004 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2005 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2006 | RETURN VALUE |
| 2007 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2008 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2009 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2010 | OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2011 | OMX_IN OMX_COMMANDTYPE cmd, |
| 2012 | OMX_IN OMX_U32 param1, |
| 2013 | OMX_IN OMX_PTR cmdData |
| 2014 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2015 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2016 | DEBUG_PRINT_LOW("send_command: Recieved a Command from Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2017 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2018 | DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2019 | return OMX_ErrorInvalidState; |
| 2020 | } |
| 2021 | if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2022 | && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2023 | DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2024 | "to invalid port: %lu", param1); |
| 2025 | return OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2026 | } |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 2027 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2028 | post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND); |
| 2029 | sem_wait(&m_cmd_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2030 | DEBUG_PRINT_LOW("send_command: Command Processed"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2031 | return OMX_ErrorNone; |
| 2032 | } |
| 2033 | |
| 2034 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2035 | FUNCTION |
| 2036 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2037 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2038 | DESCRIPTION |
| 2039 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2040 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2041 | PARAMETERS |
| 2042 | None. |
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 | RETURN VALUE |
| 2045 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2046 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2047 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2048 | OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2049 | OMX_IN OMX_COMMANDTYPE cmd, |
| 2050 | OMX_IN OMX_U32 param1, |
| 2051 | OMX_IN OMX_PTR cmdData |
| 2052 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2053 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2054 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2055 | OMX_STATETYPE eState = (OMX_STATETYPE) param1; |
| 2056 | int bFlag = 1,sem_posted = 0,ret=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2057 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2058 | DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd); |
| 2059 | DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2060 | m_state, eState); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2061 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2062 | if (cmd == OMX_CommandStateSet) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2063 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued"); |
| 2064 | DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2065 | /***************************/ |
| 2066 | /* Current State is Loaded */ |
| 2067 | /***************************/ |
| 2068 | if (m_state == OMX_StateLoaded) { |
| 2069 | if (eState == OMX_StateIdle) { |
| 2070 | //if all buffers are allocated or all ports disabled |
| 2071 | if (allocate_done() || |
| 2072 | (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2073 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2074 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2075 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2076 | BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING); |
| 2077 | // Skip the event notification |
| 2078 | bFlag = 0; |
| 2079 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2080 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2081 | /* Requesting transition from Loaded to Loaded */ |
| 2082 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2083 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2084 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2085 | OMX_COMPONENT_GENERATE_EVENT); |
| 2086 | eRet = OMX_ErrorSameState; |
| 2087 | } |
| 2088 | /* Requesting transition from Loaded to WaitForResources */ |
| 2089 | else if (eState == OMX_StateWaitForResources) { |
| 2090 | /* Since error is None , we will post an event |
| 2091 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2092 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2093 | } |
| 2094 | /* Requesting transition from Loaded to Executing */ |
| 2095 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2096 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2097 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2098 | OMX_COMPONENT_GENERATE_EVENT); |
| 2099 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2100 | } |
| 2101 | /* Requesting transition from Loaded to Pause */ |
| 2102 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2103 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2104 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2105 | OMX_COMPONENT_GENERATE_EVENT); |
| 2106 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2107 | } |
| 2108 | /* Requesting transition from Loaded to Invalid */ |
| 2109 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2110 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2111 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2112 | eRet = OMX_ErrorInvalidState; |
| 2113 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2114 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2115 | eState); |
| 2116 | eRet = OMX_ErrorBadParameter; |
| 2117 | } |
| 2118 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2119 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2120 | /***************************/ |
| 2121 | /* Current State is IDLE */ |
| 2122 | /***************************/ |
| 2123 | else if (m_state == OMX_StateIdle) { |
| 2124 | if (eState == OMX_StateLoaded) { |
| 2125 | if (release_done()) { |
| 2126 | /* |
| 2127 | Since error is None , we will post an event at the end |
| 2128 | of this function definition |
| 2129 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2130 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2131 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2132 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2133 | BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING); |
| 2134 | // Skip the event notification |
| 2135 | bFlag = 0; |
| 2136 | } |
| 2137 | } |
| 2138 | /* Requesting transition from Idle to Executing */ |
| 2139 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2140 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2141 | //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING); |
| 2142 | bFlag = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2143 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2144 | m_state=OMX_StateExecuting; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2145 | DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2146 | } |
| 2147 | /* Requesting transition from Idle to Idle */ |
| 2148 | else if (eState == OMX_StateIdle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2149 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2150 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2151 | OMX_COMPONENT_GENERATE_EVENT); |
| 2152 | eRet = OMX_ErrorSameState; |
| 2153 | } |
| 2154 | /* Requesting transition from Idle to WaitForResources */ |
| 2155 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2156 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2157 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2158 | OMX_COMPONENT_GENERATE_EVENT); |
| 2159 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2160 | } |
| 2161 | /* Requesting transition from Idle to Pause */ |
| 2162 | else if (eState == OMX_StatePause) { |
| 2163 | /*To pause the Video core we need to start the driver*/ |
| 2164 | if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START, |
| 2165 | NULL) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2166 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2167 | omx_report_error (); |
| 2168 | eRet = OMX_ErrorHardware; |
| 2169 | } else { |
| 2170 | BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2171 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2172 | bFlag = 0; |
| 2173 | } |
| 2174 | } |
| 2175 | /* Requesting transition from Idle to Invalid */ |
| 2176 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2177 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2178 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2179 | eRet = OMX_ErrorInvalidState; |
| 2180 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2181 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2182 | eRet = OMX_ErrorBadParameter; |
| 2183 | } |
| 2184 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2185 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2186 | /******************************/ |
| 2187 | /* Current State is Executing */ |
| 2188 | /******************************/ |
| 2189 | else if (m_state == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2190 | DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2191 | /* Requesting transition from Executing to Idle */ |
| 2192 | if (eState == OMX_StateIdle) { |
| 2193 | /* Since error is None , we will post an event |
| 2194 | at the end of this function definition |
| 2195 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2196 | DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2197 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2198 | if (!sem_posted) { |
| 2199 | sem_posted = 1; |
| 2200 | sem_post (&m_cmd_lock); |
| 2201 | execute_omx_flush(OMX_ALL); |
| 2202 | } |
| 2203 | bFlag = 0; |
| 2204 | } |
| 2205 | /* Requesting transition from Executing to Paused */ |
| 2206 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2207 | DEBUG_PRINT_LOW("PAUSE Command Issued"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2208 | m_state = OMX_StatePause; |
| 2209 | bFlag = 1; |
| 2210 | } |
| 2211 | /* Requesting transition from Executing to Loaded */ |
| 2212 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2213 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2214 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2215 | OMX_COMPONENT_GENERATE_EVENT); |
| 2216 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2217 | } |
| 2218 | /* Requesting transition from Executing to WaitForResources */ |
| 2219 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2220 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2221 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2222 | OMX_COMPONENT_GENERATE_EVENT); |
| 2223 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2224 | } |
| 2225 | /* Requesting transition from Executing to Executing */ |
| 2226 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2227 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2228 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2229 | OMX_COMPONENT_GENERATE_EVENT); |
| 2230 | eRet = OMX_ErrorSameState; |
| 2231 | } |
| 2232 | /* Requesting transition from Executing to Invalid */ |
| 2233 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2234 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2235 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2236 | eRet = OMX_ErrorInvalidState; |
| 2237 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2238 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2239 | eRet = OMX_ErrorBadParameter; |
| 2240 | } |
| 2241 | } |
| 2242 | /***************************/ |
| 2243 | /* Current State is Pause */ |
| 2244 | /***************************/ |
| 2245 | else if (m_state == OMX_StatePause) { |
| 2246 | /* Requesting transition from Pause to Executing */ |
| 2247 | if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2248 | DEBUG_PRINT_LOW("Pause --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2249 | m_state = OMX_StateExecuting; |
| 2250 | bFlag = 1; |
| 2251 | } |
| 2252 | /* Requesting transition from Pause to Idle */ |
| 2253 | else if (eState == OMX_StateIdle) { |
| 2254 | /* Since error is None , we will post an event |
| 2255 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2256 | DEBUG_PRINT_LOW("Pause --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2257 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2258 | if (!sem_posted) { |
| 2259 | sem_posted = 1; |
| 2260 | sem_post (&m_cmd_lock); |
| 2261 | execute_omx_flush(OMX_ALL); |
| 2262 | } |
| 2263 | bFlag = 0; |
| 2264 | } |
| 2265 | /* Requesting transition from Pause to loaded */ |
| 2266 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2267 | DEBUG_PRINT_ERROR("Pause --> loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2268 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2269 | OMX_COMPONENT_GENERATE_EVENT); |
| 2270 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2271 | } |
| 2272 | /* Requesting transition from Pause to WaitForResources */ |
| 2273 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2274 | DEBUG_PRINT_ERROR("Pause --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2275 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2276 | OMX_COMPONENT_GENERATE_EVENT); |
| 2277 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2278 | } |
| 2279 | /* Requesting transition from Pause to Pause */ |
| 2280 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2281 | DEBUG_PRINT_ERROR("Pause --> Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2282 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2283 | OMX_COMPONENT_GENERATE_EVENT); |
| 2284 | eRet = OMX_ErrorSameState; |
| 2285 | } |
| 2286 | /* Requesting transition from Pause to Invalid */ |
| 2287 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2288 | DEBUG_PRINT_ERROR("Pause --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2289 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2290 | eRet = OMX_ErrorInvalidState; |
| 2291 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2292 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2293 | eRet = OMX_ErrorBadParameter; |
| 2294 | } |
| 2295 | } |
| 2296 | /***************************/ |
| 2297 | /* Current State is WaitForResources */ |
| 2298 | /***************************/ |
| 2299 | else if (m_state == OMX_StateWaitForResources) { |
| 2300 | /* Requesting transition from WaitForResources to Loaded */ |
| 2301 | if (eState == OMX_StateLoaded) { |
| 2302 | /* Since error is None , we will post an event |
| 2303 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2304 | DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2305 | } |
| 2306 | /* Requesting transition from WaitForResources to WaitForResources */ |
| 2307 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2308 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2309 | post_event(OMX_EventError,OMX_ErrorSameState, |
| 2310 | OMX_COMPONENT_GENERATE_EVENT); |
| 2311 | eRet = OMX_ErrorSameState; |
| 2312 | } |
| 2313 | /* Requesting transition from WaitForResources to Executing */ |
| 2314 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2315 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2316 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2317 | OMX_COMPONENT_GENERATE_EVENT); |
| 2318 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2319 | } |
| 2320 | /* Requesting transition from WaitForResources to Pause */ |
| 2321 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2322 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2323 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2324 | OMX_COMPONENT_GENERATE_EVENT); |
| 2325 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2326 | } |
| 2327 | /* Requesting transition from WaitForResources to Invalid */ |
| 2328 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2329 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2330 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2331 | eRet = OMX_ErrorInvalidState; |
| 2332 | } |
| 2333 | /* Requesting transition from WaitForResources to Loaded - |
| 2334 | is NOT tested by Khronos TS */ |
| 2335 | |
| 2336 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2337 | 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] | 2338 | eRet = OMX_ErrorBadParameter; |
| 2339 | } |
| 2340 | } |
| 2341 | /********************************/ |
| 2342 | /* Current State is Invalid */ |
| 2343 | /*******************************/ |
| 2344 | else if (m_state == OMX_StateInvalid) { |
| 2345 | /* State Transition from Inavlid to any state */ |
| 2346 | if (eState == (OMX_StateLoaded || OMX_StateWaitForResources |
| 2347 | || OMX_StateIdle || OMX_StateExecuting |
| 2348 | || OMX_StatePause || OMX_StateInvalid)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2349 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2350 | post_event(OMX_EventError,OMX_ErrorInvalidState,\ |
| 2351 | OMX_COMPONENT_GENERATE_EVENT); |
| 2352 | eRet = OMX_ErrorInvalidState; |
| 2353 | } |
| 2354 | } else if (cmd == OMX_CommandFlush) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2355 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2356 | "with param1: %lu", param1); |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2357 | #ifdef _MSM8974_ |
| 2358 | send_codec_config(); |
| 2359 | #endif |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2360 | if (cmd == OMX_CommandFlush && (param1 == OMX_CORE_INPUT_PORT_INDEX || |
| 2361 | param1 == OMX_ALL)) { |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2362 | if (android_atomic_add(0, &m_queued_codec_config_count) > 0) { |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2363 | struct timespec ts; |
| 2364 | |
| 2365 | clock_gettime(CLOCK_REALTIME, &ts); |
| 2366 | ts.tv_sec += 2; |
| 2367 | DEBUG_PRINT_LOW("waiting for %d EBDs of CODEC CONFIG buffers ", |
| 2368 | m_queued_codec_config_count); |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2369 | BITMASK_SET(&m_flags, OMX_COMPONENT_FLUSH_DEFERRED); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2370 | if (sem_timedwait(&m_safe_flush, &ts)) { |
| 2371 | DEBUG_PRINT_ERROR("Failed to wait for EBDs of CODEC CONFIG buffers"); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2372 | } |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2373 | BITMASK_CLEAR (&m_flags,OMX_COMPONENT_FLUSH_DEFERRED); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2377 | if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2378 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING); |
| 2379 | } |
| 2380 | if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2381 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 2382 | } |
| 2383 | if (!sem_posted) { |
| 2384 | sem_posted = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2385 | DEBUG_PRINT_LOW("Set the Semaphore"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2386 | sem_post (&m_cmd_lock); |
| 2387 | execute_omx_flush(param1); |
| 2388 | } |
| 2389 | bFlag = 0; |
| 2390 | } else if ( cmd == OMX_CommandPortEnable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2391 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2392 | "with param1: %lu", param1); |
| 2393 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2394 | m_inp_bEnabled = OMX_TRUE; |
| 2395 | |
| 2396 | if ( (m_state == OMX_StateLoaded && |
| 2397 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2398 | || allocate_input_done()) { |
| 2399 | post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX, |
| 2400 | OMX_COMPONENT_GENERATE_EVENT); |
| 2401 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2402 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2403 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 2404 | // Skip the event notification |
| 2405 | bFlag = 0; |
| 2406 | } |
| 2407 | } |
| 2408 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2409 | DEBUG_PRINT_LOW("Enable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2410 | m_out_bEnabled = OMX_TRUE; |
| 2411 | |
| 2412 | if ( (m_state == OMX_StateLoaded && |
| 2413 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2414 | || (allocate_output_done())) { |
| 2415 | post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX, |
| 2416 | OMX_COMPONENT_GENERATE_EVENT); |
| 2417 | |
| 2418 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2419 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2420 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 2421 | // Skip the event notification |
| 2422 | bFlag = 0; |
| 2423 | } |
| 2424 | } |
| 2425 | } else if (cmd == OMX_CommandPortDisable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2426 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2427 | "with param1: %lu", param1); |
| 2428 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2429 | codec_config_flag = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2430 | m_inp_bEnabled = OMX_FALSE; |
| 2431 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2432 | && release_input_done()) { |
| 2433 | post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX, |
| 2434 | OMX_COMPONENT_GENERATE_EVENT); |
| 2435 | } else { |
| 2436 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 2437 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2438 | if (!sem_posted) { |
| 2439 | sem_posted = 1; |
| 2440 | sem_post (&m_cmd_lock); |
| 2441 | } |
| 2442 | execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX); |
| 2443 | } |
| 2444 | |
| 2445 | // Skip the event notification |
| 2446 | bFlag = 0; |
| 2447 | } |
| 2448 | } |
| 2449 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2450 | m_out_bEnabled = OMX_FALSE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2451 | DEBUG_PRINT_LOW("Disable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2452 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2453 | && release_output_done()) { |
| 2454 | post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\ |
| 2455 | OMX_COMPONENT_GENERATE_EVENT); |
| 2456 | } else { |
| 2457 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
| 2458 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2459 | if (!sem_posted) { |
| 2460 | sem_posted = 1; |
| 2461 | sem_post (&m_cmd_lock); |
| 2462 | } |
| 2463 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 2464 | execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX); |
| 2465 | } |
| 2466 | // Skip the event notification |
| 2467 | bFlag = 0; |
| 2468 | |
| 2469 | } |
| 2470 | } |
| 2471 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2472 | DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2473 | eRet = OMX_ErrorNotImplemented; |
| 2474 | } |
| 2475 | if (eRet == OMX_ErrorNone && bFlag) { |
| 2476 | post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2477 | } |
| 2478 | if (!sem_posted) { |
| 2479 | sem_post(&m_cmd_lock); |
| 2480 | } |
| 2481 | |
| 2482 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2486 | FUNCTION |
| 2487 | omx_vdec::ExecuteOmxFlush |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2488 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2489 | DESCRIPTION |
| 2490 | Executes the OMX flush. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2491 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2492 | PARAMETERS |
| 2493 | flushtype - input flush(1)/output flush(0)/ both. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2494 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2495 | RETURN VALUE |
| 2496 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2497 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2498 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2499 | bool omx_vdec::execute_omx_flush(OMX_U32 flushType) |
| 2500 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2501 | bool bRet = false; |
| 2502 | struct v4l2_plane plane; |
| 2503 | struct v4l2_buffer v4l2_buf; |
| 2504 | struct v4l2_decoder_cmd dec; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 2505 | DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2506 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 2507 | dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH; |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2508 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2509 | DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig); |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2510 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2511 | if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 2512 | output_flush_progress = true; |
| 2513 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2514 | } else { |
| 2515 | /* XXX: The driver/hardware does not support flushing of individual ports |
| 2516 | * in all states. So we pretty much need to flush both ports internally, |
| 2517 | * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it |
| 2518 | * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set, |
| 2519 | * we automatically omit sending the FLUSH done for the "opposite" port. */ |
| 2520 | input_flush_progress = true; |
| 2521 | output_flush_progress = true; |
| 2522 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2523 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2524 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2525 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2526 | DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2527 | bRet = false; |
| 2528 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2529 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2530 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2531 | } |
| 2532 | /*========================================================================= |
| 2533 | FUNCTION : execute_output_flush |
| 2534 | |
| 2535 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2536 | Executes the OMX flush at OUTPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2537 | |
| 2538 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2539 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2540 | |
| 2541 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2542 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2543 | ==========================================================================*/ |
| 2544 | bool omx_vdec::execute_output_flush() |
| 2545 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2546 | unsigned p1 = 0; // Parameter - 1 |
| 2547 | unsigned p2 = 0; // Parameter - 2 |
| 2548 | unsigned ident = 0; |
| 2549 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2550 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2551 | /*Generate FBD for all Buffers in the FTBq*/ |
| 2552 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2553 | DEBUG_PRINT_LOW("Initiate Output Flush"); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 2554 | |
| 2555 | //reset last render TS |
| 2556 | if(m_last_rendered_TS > 0) { |
| 2557 | m_last_rendered_TS = 0; |
| 2558 | } |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 2559 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2560 | while (m_ftb_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2561 | DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2562 | m_ftb_q.m_size,pending_output_buffers); |
| 2563 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2564 | DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2565 | if (ident == m_fill_output_msg ) { |
| 2566 | m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2567 | } else if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 2568 | fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2569 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2570 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2571 | pthread_mutex_unlock(&m_lock); |
| 2572 | output_flush_progress = false; |
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 | if (arbitrary_bytes) { |
| 2575 | prev_ts = LLONG_MAX; |
| 2576 | rst_prev_ts = true; |
| 2577 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2578 | 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] | 2579 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2580 | } |
| 2581 | /*========================================================================= |
| 2582 | FUNCTION : execute_input_flush |
| 2583 | |
| 2584 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2585 | Executes the OMX flush at INPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2586 | |
| 2587 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2588 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2589 | |
| 2590 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2591 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2592 | ==========================================================================*/ |
| 2593 | bool omx_vdec::execute_input_flush() |
| 2594 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2595 | unsigned i =0; |
| 2596 | unsigned p1 = 0; // Parameter - 1 |
| 2597 | unsigned p2 = 0; // Parameter - 2 |
| 2598 | unsigned ident = 0; |
| 2599 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2600 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2601 | /*Generate EBD for all Buffers in the ETBq*/ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2602 | DEBUG_PRINT_LOW("Initiate Input Flush"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2603 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2604 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2605 | DEBUG_PRINT_LOW("Check if the Queue is empty"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2606 | while (m_etb_q.m_size) { |
| 2607 | m_etb_q.pop_entry(&p1,&p2,&ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2608 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2609 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2610 | DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2611 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2612 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 2613 | pending_input_buffers++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2614 | 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] | 2615 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 2616 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 2617 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2618 | DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2619 | (OMX_BUFFERHEADERTYPE *)p1); |
| 2620 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 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 | time_stamp_dts.flush_timestamp(); |
| 2624 | /*Check if Heap Buffers are to be flushed*/ |
| 2625 | if (arbitrary_bytes && !(codec_config_flag)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2626 | DEBUG_PRINT_LOW("Reset all the variables before flusing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2627 | h264_scratch.nFilledLen = 0; |
| 2628 | nal_count = 0; |
| 2629 | look_ahead_nal = false; |
| 2630 | frame_count = 0; |
| 2631 | h264_last_au_ts = LLONG_MAX; |
| 2632 | h264_last_au_flags = 0; |
| 2633 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 2634 | m_demux_entries = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2635 | DEBUG_PRINT_LOW("Initialize parser"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2636 | if (m_frame_parser.mutils) { |
| 2637 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 2638 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2639 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2640 | while (m_input_pending_q.m_size) { |
| 2641 | m_input_pending_q.pop_entry(&p1,&p2,&ident); |
| 2642 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1); |
| 2643 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2644 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2645 | if (psource_frame) { |
| 2646 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame); |
| 2647 | psource_frame = NULL; |
| 2648 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2649 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2650 | if (pdest_frame) { |
| 2651 | pdest_frame->nFilledLen = 0; |
| 2652 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL, |
| 2653 | (unsigned int)NULL); |
| 2654 | pdest_frame = NULL; |
| 2655 | } |
| 2656 | m_frame_parser.flush(); |
| 2657 | } else if (codec_config_flag) { |
| 2658 | DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer " |
| 2659 | "is not sent to the driver yet"); |
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 | pthread_mutex_unlock(&m_lock); |
| 2662 | input_flush_progress = false; |
| 2663 | if (!arbitrary_bytes) { |
| 2664 | prev_ts = LLONG_MAX; |
| 2665 | rst_prev_ts = true; |
| 2666 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2667 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2668 | if (m_debug_timestamp) { |
| 2669 | m_timestamp_list.reset_ts_list(); |
| 2670 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2671 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2672 | 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] | 2673 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | |
| 2677 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2678 | FUNCTION |
| 2679 | omx_vdec::SendCommandEvent |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2680 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2681 | DESCRIPTION |
| 2682 | Send the event to decoder pipe. This is needed to generate the callbacks |
| 2683 | in decoder thread context. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2684 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2685 | PARAMETERS |
| 2686 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2687 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2688 | RETURN VALUE |
| 2689 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2690 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2691 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2692 | bool omx_vdec::post_event(unsigned int p1, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2693 | unsigned int p2, |
| 2694 | unsigned int id) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2695 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2696 | bool bRet = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2697 | |
| 2698 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2699 | pthread_mutex_lock(&m_lock); |
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 (id == m_fill_output_msg || |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 2702 | id == OMX_COMPONENT_GENERATE_FBD || |
| 2703 | id == OMX_COMPONENT_GENERATE_PORT_RECONFIG) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2704 | m_ftb_q.insert_entry(p1,p2,id); |
| 2705 | } else if (id == OMX_COMPONENT_GENERATE_ETB || |
| 2706 | id == OMX_COMPONENT_GENERATE_EBD || |
| 2707 | id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 2708 | m_etb_q.insert_entry(p1,p2,id); |
| 2709 | } else { |
| 2710 | m_cmd_q.insert_entry(p1,p2,id); |
| 2711 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2712 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2713 | bRet = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2714 | DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2715 | post_message(this, id); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2716 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2717 | pthread_mutex_unlock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2718 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2719 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType) |
| 2723 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2724 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2725 | if (!profileLevelType) |
| 2726 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2727 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2728 | if (profileLevelType->nPortIndex == 0) { |
| 2729 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 2730 | if (profileLevelType->nProfileIndex == 0) { |
| 2731 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline; |
| 2732 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2733 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2734 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2735 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain; |
| 2736 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2737 | } else if (profileLevelType->nProfileIndex == 2) { |
| 2738 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh; |
| 2739 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2740 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2741 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2742 | profileLevelType->nProfileIndex); |
| 2743 | eRet = OMX_ErrorNoMore; |
| 2744 | } |
| 2745 | } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) { |
| 2746 | if (profileLevelType->nProfileIndex == 0) { |
| 2747 | profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline; |
| 2748 | profileLevelType->eLevel = OMX_VIDEO_H263Level70; |
| 2749 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2750 | 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] | 2751 | eRet = OMX_ErrorNoMore; |
| 2752 | } |
| 2753 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 2754 | if (profileLevelType->nProfileIndex == 0) { |
| 2755 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple; |
| 2756 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2757 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2758 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple; |
| 2759 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2760 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2761 | 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] | 2762 | eRet = OMX_ErrorNoMore; |
| 2763 | } |
| 2764 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 2765 | eRet = OMX_ErrorNoMore; |
| 2766 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 2767 | if (profileLevelType->nProfileIndex == 0) { |
| 2768 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple; |
| 2769 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2770 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2771 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain; |
| 2772 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2773 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2774 | 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] | 2775 | eRet = OMX_ErrorNoMore; |
| 2776 | } |
| 2777 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2778 | 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] | 2779 | eRet = OMX_ErrorNoMore; |
| 2780 | } |
| 2781 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2782 | 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] | 2783 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2784 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2785 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2789 | FUNCTION |
| 2790 | omx_vdec::GetParameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2791 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2792 | DESCRIPTION |
| 2793 | OMX Get Parameter method implementation |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2794 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2795 | PARAMETERS |
| 2796 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2797 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2798 | RETURN VALUE |
| 2799 | Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2800 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2801 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2802 | OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2803 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 2804 | OMX_INOUT OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2805 | { |
| 2806 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2807 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2808 | DEBUG_PRINT_LOW("get_parameter:"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2809 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2810 | DEBUG_PRINT_ERROR("Get Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2811 | return OMX_ErrorInvalidState; |
| 2812 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2813 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2814 | DEBUG_PRINT_LOW("Get Param in Invalid paramData"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2815 | return OMX_ErrorBadParameter; |
| 2816 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2817 | switch ((unsigned long)paramIndex) { |
| 2818 | case OMX_IndexParamPortDefinition: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2819 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2820 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = |
| 2821 | (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2822 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2823 | eRet = update_portdef(portDefn); |
| 2824 | if (eRet == OMX_ErrorNone) |
| 2825 | m_port_def = *portDefn; |
| 2826 | break; |
| 2827 | } |
| 2828 | case OMX_IndexParamVideoInit: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2829 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2830 | OMX_PORT_PARAM_TYPE *portParamType = |
| 2831 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2832 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2833 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2834 | portParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2835 | portParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2836 | portParamType->nPorts = 2; |
| 2837 | portParamType->nStartPortNumber = 0; |
| 2838 | break; |
| 2839 | } |
| 2840 | case OMX_IndexParamVideoPortFormat: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2841 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2842 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 2843 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2844 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2845 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2846 | portFmt->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2847 | portFmt->nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2848 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2849 | if (0 == portFmt->nPortIndex) { |
| 2850 | if (0 == portFmt->nIndex) { |
| 2851 | portFmt->eColorFormat = OMX_COLOR_FormatUnused; |
| 2852 | portFmt->eCompressionFormat = eCompressionFormat; |
| 2853 | } else { |
| 2854 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2855 | " NoMore compression formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2856 | eRet = OMX_ErrorNoMore; |
| 2857 | } |
| 2858 | } else if (1 == portFmt->nPortIndex) { |
| 2859 | portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2860 | |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2861 | // Distinguish non-surface mode from normal playback use-case based on |
| 2862 | // usage hinted via "OMX.google.android.index.useAndroidNativeBuffer2" |
| 2863 | // For non-android, use the default list |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 2864 | // Also use default format-list if FLEXIBLE YUV is supported, |
| 2865 | // as the client negotiates the standard color-format if it needs to |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2866 | bool useNonSurfaceMode = false; |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 2867 | #if defined(_ANDROID_) && !defined(FLEXYUV_SUPPORTED) |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2868 | useNonSurfaceMode = (m_enable_android_native_buffers == OMX_FALSE); |
| 2869 | #endif |
| 2870 | portFmt->eColorFormat = useNonSurfaceMode ? |
| 2871 | getPreferredColorFormatNonSurfaceMode(portFmt->nIndex) : |
| 2872 | getPreferredColorFormatDefaultMode(portFmt->nIndex); |
| 2873 | |
| 2874 | if (portFmt->eColorFormat == OMX_COLOR_FormatMax ) { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2875 | eRet = OMX_ErrorNoMore; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2876 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2877 | " NoMore Color formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2878 | } |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2879 | DEBUG_PRINT_HIGH("returning color-format: 0x%x", portFmt->eColorFormat); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2880 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2881 | DEBUG_PRINT_ERROR("get_parameter: Bad port index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2882 | (int)portFmt->nPortIndex); |
| 2883 | eRet = OMX_ErrorBadPortIndex; |
| 2884 | } |
| 2885 | break; |
| 2886 | } |
| 2887 | /*Component should support this port definition*/ |
| 2888 | case OMX_IndexParamAudioInit: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2889 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2890 | OMX_PORT_PARAM_TYPE *audioPortParamType = |
| 2891 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2892 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2893 | audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2894 | audioPortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2895 | audioPortParamType->nPorts = 0; |
| 2896 | audioPortParamType->nStartPortNumber = 0; |
| 2897 | break; |
| 2898 | } |
| 2899 | /*Component should support this port definition*/ |
| 2900 | case OMX_IndexParamImageInit: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2901 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2902 | OMX_PORT_PARAM_TYPE *imagePortParamType = |
| 2903 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2904 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2905 | imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2906 | imagePortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2907 | imagePortParamType->nPorts = 0; |
| 2908 | imagePortParamType->nStartPortNumber = 0; |
| 2909 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2910 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2911 | } |
| 2912 | /*Component should support this port definition*/ |
| 2913 | case OMX_IndexParamOtherInit: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2914 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2915 | paramIndex); |
| 2916 | eRet =OMX_ErrorUnsupportedIndex; |
| 2917 | break; |
| 2918 | } |
| 2919 | case OMX_IndexParamStandardComponentRole: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2920 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2921 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 2922 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
| 2923 | comp_role->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2924 | comp_role->nSize = sizeof(*comp_role); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2925 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2926 | DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2927 | paramIndex); |
| 2928 | strlcpy((char*)comp_role->cRole,(const char*)m_cRole, |
| 2929 | OMX_MAX_STRINGNAME_SIZE); |
| 2930 | break; |
| 2931 | } |
| 2932 | /* Added for parameter test */ |
| 2933 | case OMX_IndexParamPriorityMgmt: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2934 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2935 | OMX_PRIORITYMGMTTYPE *priorityMgmType = |
| 2936 | (OMX_PRIORITYMGMTTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2937 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2938 | priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2939 | priorityMgmType->nSize = sizeof(OMX_PRIORITYMGMTTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2940 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2941 | break; |
| 2942 | } |
| 2943 | /* Added for parameter test */ |
| 2944 | case OMX_IndexParamCompBufferSupplier: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2945 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2946 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = |
| 2947 | (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2948 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2949 | |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2950 | bufferSupplierType->nSize = sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2951 | bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2952 | if (0 == bufferSupplierType->nPortIndex) |
| 2953 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2954 | else if (1 == bufferSupplierType->nPortIndex) |
| 2955 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2956 | else |
| 2957 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2958 | |
| 2959 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2960 | break; |
| 2961 | } |
| 2962 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2963 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2964 | paramIndex); |
| 2965 | break; |
| 2966 | } |
| 2967 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2968 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2969 | paramIndex); |
| 2970 | break; |
| 2971 | } |
| 2972 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2973 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2974 | paramIndex); |
| 2975 | break; |
| 2976 | } |
| 2977 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2978 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2979 | paramIndex); |
| 2980 | break; |
| 2981 | } |
| 2982 | case OMX_IndexParamVideoProfileLevelQuerySupported: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2983 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2984 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2985 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType = |
| 2986 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData; |
| 2987 | eRet = get_supported_profile_level_for_1080p(profileLevelType); |
| 2988 | break; |
| 2989 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2990 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2991 | case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 2992 | VALIDATE_OMX_PARAM_DATA(paramData, GetAndroidNativeBufferUsageParams); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2993 | DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2994 | GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData; |
| 2995 | if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2996 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2997 | if (secure_mode) { |
| 2998 | nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED | |
| 2999 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 3000 | } else { |
| 3001 | nativeBuffersUsage->nUsage = |
| 3002 | (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | |
| 3003 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 3004 | } |
| 3005 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3006 | DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3007 | eRet = OMX_ErrorBadParameter; |
| 3008 | } |
| 3009 | } |
| 3010 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3011 | #endif |
| 3012 | |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 3013 | #ifdef FLEXYUV_SUPPORTED |
| 3014 | case OMX_QcomIndexFlexibleYUVDescription: { |
| 3015 | DEBUG_PRINT_LOW("get_parameter: describeColorFormat"); |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3016 | VALIDATE_OMX_PARAM_DATA(paramData, DescribeColorFormatParams); |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 3017 | eRet = describeColorFormat(paramData); |
| 3018 | break; |
| 3019 | } |
| 3020 | #endif |
| 3021 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3022 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3023 | DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3024 | eRet =OMX_ErrorUnsupportedIndex; |
| 3025 | } |
| 3026 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3029 | 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] | 3030 | drv_ctx.video_resolution.frame_width, |
| 3031 | drv_ctx.video_resolution.frame_height, |
| 3032 | drv_ctx.video_resolution.stride, |
| 3033 | drv_ctx.video_resolution.scan_lines); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3034 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3035 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
| 3039 | OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data) |
| 3040 | { |
| 3041 | DEBUG_PRINT_LOW("Inside use_android_native_buffer"); |
| 3042 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 3043 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data; |
| 3044 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3045 | if ((params == NULL) || |
| 3046 | (params->nativeBuffer == NULL) || |
| 3047 | (params->nativeBuffer->handle == NULL) || |
| 3048 | !m_enable_android_native_buffers) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3049 | return OMX_ErrorBadParameter; |
| 3050 | m_use_android_native_buffers = OMX_TRUE; |
| 3051 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 3052 | private_handle_t *handle = (private_handle_t *)nBuf->handle; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3053 | 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] | 3054 | OMX_U8 *buffer = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3055 | if (!secure_mode) { |
| 3056 | buffer = (OMX_U8*)mmap(0, handle->size, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3057 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3058 | if (buffer == MAP_FAILED) { |
| 3059 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 3060 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3061 | } |
| 3062 | } |
| 3063 | eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer); |
| 3064 | } else { |
| 3065 | eRet = OMX_ErrorBadParameter; |
| 3066 | } |
| 3067 | return eRet; |
| 3068 | } |
| 3069 | #endif |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3070 | |
| 3071 | OMX_ERRORTYPE omx_vdec::enable_smoothstreaming() { |
| 3072 | struct v4l2_control control; |
| 3073 | struct v4l2_format fmt; |
| 3074 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER; |
| 3075 | control.value = 1; |
| 3076 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3077 | if (rc < 0) { |
| 3078 | DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver."); |
| 3079 | return OMX_ErrorHardware; |
| 3080 | } |
| 3081 | m_smoothstreaming_mode = true; |
| 3082 | return OMX_ErrorNone; |
| 3083 | } |
| 3084 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3085 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3086 | FUNCTION |
| 3087 | omx_vdec::Setparameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3088 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3089 | DESCRIPTION |
| 3090 | OMX Set Parameter method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3091 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3092 | PARAMETERS |
| 3093 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3094 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3095 | RETURN VALUE |
| 3096 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3097 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3098 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3099 | OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3100 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 3101 | OMX_IN OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3102 | { |
| 3103 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Praneeth Paladugu | 226667c | 2012-09-12 16:42:30 -0700 | [diff] [blame] | 3104 | int ret=0; |
| 3105 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3106 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3107 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3108 | return OMX_ErrorInvalidState; |
| 3109 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3110 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3111 | DEBUG_PRINT_ERROR("Get Param in Invalid paramData"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3112 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3113 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3114 | if ((m_state != OMX_StateLoaded) && |
| 3115 | BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) && |
| 3116 | (m_out_bEnabled == OMX_TRUE) && |
| 3117 | BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) && |
| 3118 | (m_inp_bEnabled == OMX_TRUE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3119 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3120 | return OMX_ErrorIncorrectStateOperation; |
| 3121 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3122 | switch ((unsigned long)paramIndex) { |
| 3123 | case OMX_IndexParamPortDefinition: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3124 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3125 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn; |
| 3126 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
| 3127 | //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has |
| 3128 | //been called. |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3129 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3130 | (int)portDefn->format.video.nFrameHeight, |
| 3131 | (int)portDefn->format.video.nFrameWidth); |
| 3132 | if (OMX_DirOutput == portDefn->eDir) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3133 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port"); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3134 | bool port_format_changed = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3135 | m_display_id = portDefn->format.video.pNativeWindow; |
| 3136 | unsigned int buffer_size; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3137 | /* update output port resolution with client supplied dimensions |
| 3138 | in case scaling is enabled, else it follows input resolution set |
| 3139 | */ |
| 3140 | if (is_down_scalar_enabled) { |
| 3141 | DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n", |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3142 | portDefn->format.video.nFrameWidth, |
| 3143 | portDefn->format.video.nFrameHeight); |
| 3144 | if (portDefn->format.video.nFrameHeight != 0x0 && |
| 3145 | portDefn->format.video.nFrameWidth != 0x0) { |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3146 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
| 3147 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3148 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3149 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 3150 | if (ret) { |
| 3151 | DEBUG_PRINT_ERROR("Get Resolution failed"); |
| 3152 | eRet = OMX_ErrorHardware; |
| 3153 | break; |
| 3154 | } |
| 3155 | if ((portDefn->format.video.nFrameHeight != (int)fmt.fmt.pix_mp.height) || |
| 3156 | (portDefn->format.video.nFrameWidth != (int)fmt.fmt.pix_mp.width)) { |
| 3157 | port_format_changed = true; |
| 3158 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3159 | update_resolution(portDefn->format.video.nFrameWidth, |
| 3160 | portDefn->format.video.nFrameHeight, |
| 3161 | portDefn->format.video.nFrameWidth, |
| 3162 | portDefn->format.video.nFrameHeight); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3163 | |
| 3164 | /* set crop info */ |
| 3165 | rectangle.nLeft = 0; |
| 3166 | rectangle.nTop = 0; |
| 3167 | rectangle.nWidth = portDefn->format.video.nFrameWidth; |
| 3168 | rectangle.nHeight = portDefn->format.video.nFrameHeight; |
| 3169 | |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3170 | eRet = is_video_session_supported(); |
| 3171 | if (eRet) |
| 3172 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3173 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3174 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3175 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3176 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3177 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3178 | 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); |
| 3179 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3180 | if (ret) { |
| 3181 | DEBUG_PRINT_ERROR("\n Set Resolution failed"); |
| 3182 | eRet = OMX_ErrorUnsupportedSetting; |
| 3183 | } else |
| 3184 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3185 | } |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3186 | } |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3187 | if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 3188 | DEBUG_PRINT_ERROR("Requested o/p buf count (%u) exceeds limit (%u)", |
| 3189 | portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS); |
| 3190 | eRet = OMX_ErrorBadParameter; |
| 3191 | } else if (!client_buffers.get_buffer_req(buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3192 | DEBUG_PRINT_ERROR("Error in getting buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3193 | eRet = OMX_ErrorBadParameter; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3194 | } else if (!port_format_changed) { |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3195 | |
| 3196 | // Buffer count can change only when port is disabled |
| 3197 | if (!release_output_done()) { |
| 3198 | DEBUG_PRINT_ERROR("Cannot change o/p buffer count since all buffers are not freed yet !"); |
| 3199 | eRet = OMX_ErrorInvalidState; |
| 3200 | break; |
| 3201 | } |
| 3202 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3203 | if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount && |
| 3204 | portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) { |
| 3205 | drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual; |
| 3206 | drv_ctx.op_buf.buffer_size = portDefn->nBufferSize; |
| 3207 | drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount; |
| 3208 | drv_ctx.extradata_info.size = drv_ctx.extradata_info.count * |
| 3209 | drv_ctx.extradata_info.buffer_size; |
| 3210 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 3211 | if (eRet == OMX_ErrorNone) |
| 3212 | m_port_def = *portDefn; |
| 3213 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3214 | DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3215 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size, |
| 3216 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3217 | eRet = OMX_ErrorBadParameter; |
| 3218 | } |
| 3219 | } |
| 3220 | } else if (OMX_DirInput == portDefn->eDir) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3221 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3222 | bool port_format_changed = false; |
| 3223 | if ((portDefn->format.video.xFramerate >> 16) > 0 && |
| 3224 | (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) { |
| 3225 | // Frame rate only should be set if this is a "known value" or to |
| 3226 | // activate ts prediction logic (arbitrary mode only) sending input |
| 3227 | // timestamps with max value (LLONG_MAX). |
| 3228 | DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu", |
| 3229 | portDefn->format.video.xFramerate >> 16); |
| 3230 | Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator, |
| 3231 | drv_ctx.frame_rate.fps_denominator); |
| 3232 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 3233 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 3234 | drv_ctx.frame_rate.fps_numerator = 30; |
| 3235 | } |
| 3236 | if (drv_ctx.frame_rate.fps_denominator) |
| 3237 | drv_ctx.frame_rate.fps_numerator = (int) |
| 3238 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 3239 | drv_ctx.frame_rate.fps_denominator = 1; |
| 3240 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 3241 | drv_ctx.frame_rate.fps_numerator; |
| 3242 | DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)", |
| 3243 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 3244 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3245 | |
| 3246 | struct v4l2_outputparm oparm; |
| 3247 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 3248 | * per second.*/ |
| 3249 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 3250 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 3251 | |
| 3252 | struct v4l2_streamparm sparm; |
| 3253 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3254 | sparm.parm.output = oparm; |
| 3255 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 3256 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, performance might be affected"); |
| 3257 | eRet = OMX_ErrorHardware; |
| 3258 | break; |
| 3259 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3260 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3261 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3262 | if (drv_ctx.video_resolution.frame_height != |
| 3263 | portDefn->format.video.nFrameHeight || |
| 3264 | drv_ctx.video_resolution.frame_width != |
| 3265 | portDefn->format.video.nFrameWidth) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3266 | DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3267 | portDefn->format.video.nFrameWidth, |
| 3268 | portDefn->format.video.nFrameHeight); |
| 3269 | port_format_changed = true; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3270 | OMX_U32 frameWidth = portDefn->format.video.nFrameWidth; |
| 3271 | OMX_U32 frameHeight = portDefn->format.video.nFrameHeight; |
| 3272 | if (frameHeight != 0x0 && frameWidth != 0x0) { |
| 3273 | if (m_smoothstreaming_mode && |
| 3274 | ((frameWidth * frameHeight) < |
| 3275 | (m_smoothstreaming_width * m_smoothstreaming_height))) { |
| 3276 | frameWidth = m_smoothstreaming_width; |
| 3277 | frameHeight = m_smoothstreaming_height; |
| 3278 | DEBUG_PRINT_LOW("NOTE: Setting resolution %lu x %lu for adaptive-playback/smooth-streaming", |
| 3279 | frameWidth, frameHeight); |
| 3280 | } |
| 3281 | update_resolution(frameWidth, frameHeight, |
| 3282 | frameWidth, frameHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3283 | eRet = is_video_session_supported(); |
| 3284 | if (eRet) |
| 3285 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3286 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3287 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3288 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3289 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3290 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3291 | 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] | 3292 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3293 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3294 | DEBUG_PRINT_ERROR("Set Resolution failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3295 | eRet = OMX_ErrorUnsupportedSetting; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3296 | } else { |
| 3297 | if (!is_down_scalar_enabled) |
| 3298 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3299 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3300 | } |
| 3301 | } |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3302 | if (m_custom_buffersize.input_buffersize |
| 3303 | && (portDefn->nBufferSize > m_custom_buffersize.input_buffersize)) { |
| 3304 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size set by client: %d, trying to set: %d", |
| 3305 | m_custom_buffersize.input_buffersize, portDefn->nBufferSize); |
| 3306 | eRet = OMX_ErrorBadParameter; |
| 3307 | break; |
| 3308 | } |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3309 | if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 3310 | DEBUG_PRINT_ERROR("Requested i/p buf count (%u) exceeds limit (%u)", |
| 3311 | portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS); |
| 3312 | eRet = OMX_ErrorBadParameter; |
| 3313 | break; |
| 3314 | } |
| 3315 | // Buffer count can change only when port is disabled |
| 3316 | if (!release_input_done()) { |
| 3317 | DEBUG_PRINT_ERROR("Cannot change i/p buffer count since all buffers are not freed yet !"); |
| 3318 | eRet = OMX_ErrorInvalidState; |
| 3319 | break; |
| 3320 | } |
| 3321 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3322 | if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount |
| 3323 | || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) { |
| 3324 | port_format_changed = true; |
| 3325 | vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf; |
| 3326 | drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual; |
| 3327 | drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) & |
| 3328 | (~(buffer_prop->alignment - 1)); |
| 3329 | eRet = set_buffer_req(buffer_prop); |
| 3330 | } |
| 3331 | if (false == port_format_changed) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3332 | DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3333 | drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size, |
| 3334 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3335 | eRet = OMX_ErrorBadParameter; |
| 3336 | } |
| 3337 | } else if (portDefn->eDir == OMX_DirMax) { |
| 3338 | DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d", |
| 3339 | (int)portDefn->nPortIndex); |
| 3340 | eRet = OMX_ErrorBadPortIndex; |
| 3341 | } |
| 3342 | } |
| 3343 | break; |
| 3344 | case OMX_IndexParamVideoPortFormat: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3345 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3346 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 3347 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
| 3348 | int ret=0; |
| 3349 | struct v4l2_format fmt; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3350 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3351 | portFmt->eColorFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3352 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3353 | if (1 == portFmt->nPortIndex) { |
| 3354 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3355 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3356 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3357 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3358 | enum vdec_output_fromat op_format; |
| 3359 | if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE) |
| 3360 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) || |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 3361 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 3362 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3363 | op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3364 | else |
| 3365 | eRet = OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3366 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3367 | if (eRet == OMX_ErrorNone) { |
| 3368 | drv_ctx.output_format = op_format; |
| 3369 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3370 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3371 | DEBUG_PRINT_ERROR("Set output format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3372 | eRet = OMX_ErrorUnsupportedSetting; |
| 3373 | /*TODO: How to handle this case */ |
| 3374 | } else { |
| 3375 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3376 | } |
| 3377 | } |
| 3378 | if (eRet == OMX_ErrorNone) { |
| 3379 | if (!client_buffers.set_color_format(portFmt->eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3380 | DEBUG_PRINT_ERROR("Set color format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3381 | eRet = OMX_ErrorBadParameter; |
| 3382 | } |
| 3383 | } |
| 3384 | } |
| 3385 | } |
| 3386 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3387 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3388 | case OMX_QcomIndexPortDefn: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3389 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3390 | OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt = |
| 3391 | (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3392 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3393 | portFmt->nFramePackingFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3394 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3395 | /* Input port */ |
| 3396 | if (portFmt->nPortIndex == 0) { |
| 3397 | if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) { |
| 3398 | if (secure_mode) { |
| 3399 | arbitrary_bytes = false; |
| 3400 | DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session"); |
| 3401 | eRet = OMX_ErrorUnsupportedSetting; |
| 3402 | } else { |
| 3403 | arbitrary_bytes = true; |
| 3404 | } |
| 3405 | } else if (portFmt->nFramePackingFormat == |
| 3406 | OMX_QCOM_FramePacking_OnlyOneCompleteFrame) { |
| 3407 | arbitrary_bytes = false; |
| 3408 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3409 | DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3410 | portFmt->nFramePackingFormat); |
| 3411 | eRet = OMX_ErrorUnsupportedSetting; |
| 3412 | } |
| 3413 | } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3414 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3415 | if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid && |
| 3416 | portFmt->nMemRegion < OMX_QCOM_MemRegionMax) && |
| 3417 | portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) { |
| 3418 | m_out_mem_region_smi = OMX_TRUE; |
| 3419 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3420 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3421 | m_use_output_pmem = OMX_TRUE; |
| 3422 | } |
| 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3427 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3428 | case OMX_IndexParamStandardComponentRole: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3429 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3430 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 3431 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3432 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3433 | comp_role->cRole); |
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 | if ((m_state == OMX_StateLoaded)&& |
| 3436 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 3437 | DEBUG_PRINT_LOW("Set Parameter called in valid state"); |
| 3438 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3439 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3440 | return OMX_ErrorIncorrectStateOperation; |
| 3441 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3442 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3443 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3444 | if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3445 | strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 3446 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3447 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3448 | eRet =OMX_ErrorUnsupportedSetting; |
| 3449 | } |
| 3450 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3451 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3452 | strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
| 3453 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3454 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3455 | eRet = OMX_ErrorUnsupportedSetting; |
| 3456 | } |
| 3457 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3458 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3459 | strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
| 3460 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3461 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3462 | eRet =OMX_ErrorUnsupportedSetting; |
| 3463 | } |
| 3464 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3465 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3466 | strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
| 3467 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3468 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3469 | eRet = OMX_ErrorUnsupportedSetting; |
| 3470 | } |
| 3471 | } 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] | 3472 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311", OMX_MAX_STRINGNAME_SIZE)) || |
| 3473 | (!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] | 3474 | ) { |
| 3475 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) { |
| 3476 | strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
| 3477 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3478 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3479 | eRet =OMX_ErrorUnsupportedSetting; |
| 3480 | } |
| 3481 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 3482 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 3483 | ) { |
| 3484 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) { |
| 3485 | strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 3486 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3487 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3488 | eRet =OMX_ErrorUnsupportedSetting; |
| 3489 | } |
| 3490 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 3491 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) || |
| 3492 | (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) { |
| 3493 | strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 3494 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3495 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3496 | eRet = OMX_ErrorUnsupportedSetting; |
| 3497 | } |
| 3498 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3499 | DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3500 | eRet = OMX_ErrorInvalidComponentName; |
| 3501 | } |
| 3502 | break; |
| 3503 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3504 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3505 | case OMX_IndexParamPriorityMgmt: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3506 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3507 | if (m_state != OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3508 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3509 | return OMX_ErrorIncorrectStateOperation; |
| 3510 | } |
| 3511 | OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3512 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3513 | priorityMgmtype->nGroupID); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3514 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3515 | DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3516 | priorityMgmtype->nGroupPriority); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3517 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3518 | m_priority_mgm.nGroupID = priorityMgmtype->nGroupID; |
| 3519 | m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3520 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3521 | break; |
| 3522 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3523 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3524 | case OMX_IndexParamCompBufferSupplier: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3525 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3526 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3527 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3528 | bufferSupplierType->eBufferSupplier); |
| 3529 | if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1) |
| 3530 | m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3531 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3532 | else |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3533 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3534 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3535 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3536 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3537 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3538 | } |
| 3539 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3540 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3541 | paramIndex); |
| 3542 | break; |
| 3543 | } |
| 3544 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3545 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3546 | paramIndex); |
| 3547 | break; |
| 3548 | } |
| 3549 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3550 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3551 | paramIndex); |
| 3552 | break; |
| 3553 | } |
| 3554 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3555 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3556 | paramIndex); |
| 3557 | break; |
| 3558 | } |
| 3559 | case OMX_QcomIndexParamVideoDecoderPictureOrder: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3560 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_DECODER_PICTURE_ORDER); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3561 | QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder = |
| 3562 | (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData; |
| 3563 | struct v4l2_control control; |
| 3564 | int pic_order,rc=0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3565 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3566 | pictureOrder->eOutputPictureOrder); |
| 3567 | if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) { |
| 3568 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 3569 | } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) { |
| 3570 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3571 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3572 | } else |
| 3573 | eRet = OMX_ErrorBadParameter; |
| 3574 | if (eRet == OMX_ErrorNone) { |
| 3575 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3576 | control.value = pic_order; |
| 3577 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3578 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3579 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3580 | eRet = OMX_ErrorUnsupportedSetting; |
| 3581 | } |
| 3582 | } |
| 3583 | break; |
| 3584 | } |
| 3585 | case OMX_QcomIndexParamConcealMBMapExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3586 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3587 | eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false, |
| 3588 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3589 | break; |
| 3590 | case OMX_QcomIndexParamFrameInfoExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3591 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3592 | eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false, |
| 3593 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3594 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3595 | case OMX_QcomIndexParamInterlaceExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3596 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3597 | eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false, |
| 3598 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3599 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3600 | case OMX_QcomIndexParamH264TimeInfo: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3601 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3602 | eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false, |
| 3603 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3604 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3605 | case OMX_QcomIndexParamVideoFramePackingExtradata: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3606 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3607 | eRet = enable_extradata(OMX_FRAMEPACK_EXTRADATA, false, |
| 3608 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3609 | break; |
| 3610 | case OMX_QcomIndexParamVideoQPExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3611 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3612 | eRet = enable_extradata(OMX_QP_EXTRADATA, false, |
| 3613 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3614 | break; |
| 3615 | case OMX_QcomIndexParamVideoInputBitsInfoExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3616 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3617 | eRet = enable_extradata(OMX_BITSINFO_EXTRADATA, false, |
| 3618 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3619 | break; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 3620 | case OMX_QcomIndexEnableExtnUserData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3621 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 3622 | eRet = enable_extradata(OMX_EXTNUSER_EXTRADATA, false, |
| 3623 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3624 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3625 | case OMX_QcomIndexParamVideoDivx: { |
| 3626 | QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData; |
| 3627 | } |
| 3628 | break; |
| 3629 | case OMX_QcomIndexPlatformPvt: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3630 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PLATFORMPRIVATE_EXTN); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3631 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3632 | OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData; |
| 3633 | if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
| 3634 | DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type); |
| 3635 | eRet = OMX_ErrorUnsupportedSetting; |
| 3636 | } else { |
| 3637 | m_out_pvt_entry_pmem = OMX_TRUE; |
| 3638 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3639 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3640 | m_use_output_pmem = OMX_TRUE; |
| 3641 | } |
| 3642 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3643 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3644 | } |
| 3645 | break; |
| 3646 | case OMX_QcomIndexParamVideoSyncFrameDecodingMode: { |
| 3647 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode"); |
| 3648 | DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode"); |
| 3649 | struct v4l2_control control; |
| 3650 | int rc; |
| 3651 | drv_ctx.idr_only_decoding = 1; |
| 3652 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3653 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3654 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3655 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3656 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3657 | eRet = OMX_ErrorUnsupportedSetting; |
| 3658 | } else { |
| 3659 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE; |
| 3660 | control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE; |
| 3661 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3662 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3663 | DEBUG_PRINT_ERROR("Sync frame setting failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3664 | eRet = OMX_ErrorUnsupportedSetting; |
| 3665 | } |
| 3666 | /*Setting sync frame decoding on driver might change buffer |
| 3667 | * requirements so update them here*/ |
| 3668 | if (get_buffer_req(&drv_ctx.ip_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3669 | 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] | 3670 | eRet = OMX_ErrorUnsupportedSetting; |
| 3671 | } |
| 3672 | if (get_buffer_req(&drv_ctx.op_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3673 | 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] | 3674 | eRet = OMX_ErrorUnsupportedSetting; |
| 3675 | } |
| 3676 | } |
| 3677 | } |
| 3678 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3679 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3680 | case OMX_QcomIndexParamIndexExtraDataType: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3681 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXEXTRADATATYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3682 | QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData; |
| 3683 | if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) && |
| 3684 | (extradataIndexType->bEnabled == OMX_TRUE) && |
| 3685 | (extradataIndexType->nPortIndex == 1)) { |
| 3686 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming"); |
| 3687 | eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled); |
| 3688 | } |
| 3689 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3690 | break; |
| 3691 | case OMX_QcomIndexParamEnableSmoothStreaming: { |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3692 | #ifndef SMOOTH_STREAMING_DISABLED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3693 | eRet = enable_smoothstreaming(); |
Arun Menon | bc0922f | 2013-06-24 13:02:15 -0700 | [diff] [blame] | 3694 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3695 | eRet = OMX_ErrorUnsupportedSetting; |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3696 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3697 | } |
| 3698 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3699 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3700 | /* Need to allow following two set_parameters even in Idle |
| 3701 | * state. This is ANDROID architecture which is not in sync |
| 3702 | * with openmax standard. */ |
| 3703 | case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3704 | VALIDATE_OMX_PARAM_DATA(paramData, EnableAndroidNativeBuffersParams); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3705 | EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData; |
| 3706 | if (enableNativeBuffers) { |
| 3707 | m_enable_android_native_buffers = enableNativeBuffers->enable; |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 3708 | } |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 3709 | #if !defined(FLEXYUV_SUPPORTED) |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 3710 | if (m_enable_android_native_buffers) { |
| 3711 | // Use the most-preferred-native-color-format as surface-mode is hinted here |
| 3712 | if(!client_buffers.set_color_format(getPreferredColorFormatDefaultMode(0))) { |
| 3713 | DEBUG_PRINT_ERROR("Failed to set native color format!"); |
| 3714 | eRet = OMX_ErrorUnsupportedSetting; |
| 3715 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3716 | } |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 3717 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3718 | } |
| 3719 | break; |
| 3720 | case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3721 | VALIDATE_OMX_PARAM_DATA(paramData, UseAndroidNativeBufferParams); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3722 | eRet = use_android_native_buffer(hComp, paramData); |
| 3723 | } |
| 3724 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3725 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3726 | case OMX_QcomIndexParamEnableTimeStampReorder: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3727 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXTIMESTAMPREORDER); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3728 | QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData; |
| 3729 | if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) { |
| 3730 | if (reorder->bEnable == OMX_TRUE) { |
| 3731 | frm_int =0; |
| 3732 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 3733 | } else |
| 3734 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3735 | } else { |
| 3736 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3737 | if (reorder->bEnable == OMX_TRUE) { |
| 3738 | eRet = OMX_ErrorUnsupportedSetting; |
| 3739 | } |
| 3740 | } |
| 3741 | } |
| 3742 | break; |
| 3743 | case OMX_IndexParamVideoProfileLevelCurrent: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3744 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3745 | OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = |
| 3746 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData; |
| 3747 | if (pParam) { |
| 3748 | m_profile_lvl.eProfile = pParam->eProfile; |
| 3749 | m_profile_lvl.eLevel = pParam->eLevel; |
| 3750 | } |
| 3751 | break; |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 3752 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3753 | } |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3754 | case OMX_QcomIndexParamVideoMetaBufferMode: |
| 3755 | { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3756 | VALIDATE_OMX_PARAM_DATA(paramData, StoreMetaDataInBuffersParams); |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3757 | StoreMetaDataInBuffersParams *metabuffer = |
| 3758 | (StoreMetaDataInBuffersParams *)paramData; |
| 3759 | if (!metabuffer) { |
| 3760 | DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer); |
| 3761 | eRet = OMX_ErrorBadParameter; |
| 3762 | break; |
| 3763 | } |
| 3764 | if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3765 | //set property dynamic buffer mode to driver. |
| 3766 | struct v4l2_control control; |
| 3767 | struct v4l2_format fmt; |
| 3768 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT; |
| 3769 | if (metabuffer->bStoreMetaData == true) { |
| 3770 | control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC; |
| 3771 | } else { |
| 3772 | control.value = V4L2_MPEG_VIDC_VIDEO_STATIC; |
| 3773 | } |
| 3774 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3775 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3776 | DEBUG_PRINT_HIGH("%s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3777 | (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 3778 | dynamic_buf_mode = metabuffer->bStoreMetaData; |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3779 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3780 | DEBUG_PRINT_ERROR("Failed to %s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3781 | (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic"); |
| 3782 | eRet = OMX_ErrorUnsupportedSetting; |
| 3783 | } |
| 3784 | } else { |
| 3785 | DEBUG_PRINT_ERROR( |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3786 | "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %lu", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3787 | metabuffer->nPortIndex); |
| 3788 | eRet = OMX_ErrorUnsupportedSetting; |
| 3789 | } |
| 3790 | break; |
| 3791 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3792 | case OMX_QcomIndexParamVideoDownScalar: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3793 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXDOWNSCALAR); |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3794 | QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData; |
| 3795 | struct v4l2_control control; |
| 3796 | int rc; |
| 3797 | if (pParam) { |
| 3798 | is_down_scalar_enabled = pParam->bEnable; |
| 3799 | if (is_down_scalar_enabled) { |
| 3800 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE; |
| 3801 | control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY; |
| 3802 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n", |
| 3803 | pParam->bEnable); |
| 3804 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3805 | if (rc < 0) { |
| 3806 | DEBUG_PRINT_ERROR("Failed to set down scalar on driver."); |
| 3807 | eRet = OMX_ErrorUnsupportedSetting; |
| 3808 | } |
| 3809 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO; |
| 3810 | control.value = 1; |
| 3811 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3812 | if (rc < 0) { |
| 3813 | DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver."); |
| 3814 | eRet = OMX_ErrorUnsupportedSetting; |
| 3815 | } |
| 3816 | } |
| 3817 | } |
| 3818 | break; |
| 3819 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3820 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
| 3821 | case OMX_QcomIndexParamVideoAdaptivePlaybackMode: |
| 3822 | { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3823 | VALIDATE_OMX_PARAM_DATA(paramData, PrepareForAdaptivePlaybackParams); |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3824 | DEBUG_PRINT_LOW("set_parameter: OMX_GoogleAndroidIndexPrepareForAdaptivePlayback"); |
| 3825 | PrepareForAdaptivePlaybackParams* pParams = |
| 3826 | (PrepareForAdaptivePlaybackParams *) paramData; |
| 3827 | if (pParams->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3828 | if (!pParams->bEnable) { |
| 3829 | return OMX_ErrorNone; |
| 3830 | } |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3831 | if (pParams->nMaxFrameWidth > maxSmoothStreamingWidth |
| 3832 | || pParams->nMaxFrameHeight > maxSmoothStreamingHeight) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3833 | DEBUG_PRINT_ERROR( |
| 3834 | "Adaptive playback request exceeds max supported resolution : [%lu x %lu] vs [%lu x %lu]", |
| 3835 | pParams->nMaxFrameWidth, pParams->nMaxFrameHeight, |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3836 | maxSmoothStreamingWidth, maxSmoothStreamingHeight); |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3837 | eRet = OMX_ErrorBadParameter; |
| 3838 | } else { |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 3839 | eRet = enable_adaptive_playback(pParams->nMaxFrameWidth, pParams->nMaxFrameHeight); |
| 3840 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3841 | } else { |
| 3842 | DEBUG_PRINT_ERROR( |
| 3843 | "Prepare for adaptive playback supported only on output port"); |
| 3844 | eRet = OMX_ErrorBadParameter; |
| 3845 | } |
| 3846 | break; |
| 3847 | } |
| 3848 | |
| 3849 | #endif |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3850 | case OMX_QcomIndexParamVideoCustomBufferSize: |
| 3851 | { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3852 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_CUSTOM_BUFFERSIZE); |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3853 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoCustomBufferSize"); |
| 3854 | QOMX_VIDEO_CUSTOM_BUFFERSIZE* pParam = (QOMX_VIDEO_CUSTOM_BUFFERSIZE*)paramData; |
| 3855 | if (pParam->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 3856 | struct v4l2_control control; |
| 3857 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT; |
| 3858 | control.value = pParam->nBufferSize; |
| 3859 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 3860 | DEBUG_PRINT_ERROR("Failed to set input buffer size"); |
| 3861 | eRet = OMX_ErrorUnsupportedSetting; |
| 3862 | } else { |
| 3863 | eRet = get_buffer_req(&drv_ctx.ip_buf); |
| 3864 | if (eRet == OMX_ErrorNone) { |
| 3865 | m_custom_buffersize.input_buffersize = drv_ctx.ip_buf.buffer_size; |
| 3866 | DEBUG_PRINT_HIGH("Successfully set custom input buffer size = %d", |
| 3867 | m_custom_buffersize.input_buffersize); |
| 3868 | } else { |
| 3869 | DEBUG_PRINT_ERROR("Failed to get buffer requirement"); |
| 3870 | } |
| 3871 | } |
| 3872 | } else { |
| 3873 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size in not supported on output port"); |
| 3874 | eRet = OMX_ErrorBadParameter; |
| 3875 | } |
| 3876 | break; |
| 3877 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3878 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3879 | DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3880 | eRet = OMX_ErrorUnsupportedIndex; |
| 3881 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3882 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 3883 | if (eRet != OMX_ErrorNone) |
| 3884 | 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] | 3885 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3889 | FUNCTION |
| 3890 | omx_vdec::GetConfig |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3891 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3892 | DESCRIPTION |
| 3893 | OMX Get Config Method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3894 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3895 | PARAMETERS |
| 3896 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3897 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3898 | RETURN VALUE |
| 3899 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3900 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3901 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3902 | OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3903 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3904 | OMX_INOUT OMX_PTR configData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3905 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3906 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3907 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3908 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3909 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3910 | return OMX_ErrorInvalidState; |
| 3911 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3912 | |
| 3913 | switch ((unsigned long)configIndex) { |
| 3914 | case OMX_QcomIndexConfigInterlaced: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3915 | VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_CONFIG_INTERLACETYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3916 | OMX_QCOM_CONFIG_INTERLACETYPE *configFmt = |
| 3917 | (OMX_QCOM_CONFIG_INTERLACETYPE *) configData; |
| 3918 | if (configFmt->nPortIndex == 1) { |
| 3919 | if (configFmt->nIndex == 0) { |
| 3920 | configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 3921 | } else if (configFmt->nIndex == 1) { |
| 3922 | configFmt->eInterlaceType = |
| 3923 | OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 3924 | } else if (configFmt->nIndex == 2) { |
| 3925 | configFmt->eInterlaceType = |
| 3926 | OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 3927 | } else { |
| 3928 | DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3929 | " NoMore Interlaced formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3930 | eRet = OMX_ErrorNoMore; |
| 3931 | } |
| 3932 | |
| 3933 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3934 | 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] | 3935 | (int)configFmt->nPortIndex); |
| 3936 | eRet = OMX_ErrorBadPortIndex; |
| 3937 | } |
| 3938 | break; |
| 3939 | } |
| 3940 | case OMX_QcomIndexQueryNumberOfVideoDecInstance: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3941 | VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_QUERY_DECODER_INSTANCES); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3942 | QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances = |
| 3943 | (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData; |
| 3944 | decoderinstances->nNumOfInstances = 16; |
| 3945 | /*TODO: How to handle this case */ |
| 3946 | break; |
| 3947 | } |
| 3948 | case OMX_QcomIndexConfigVideoFramePackingArrangement: { |
| 3949 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3950 | VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3951 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt = |
| 3952 | (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3953 | memcpy(configFmt, &m_frame_pack_arrangement, |
| 3954 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3955 | } else { |
| 3956 | DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs"); |
| 3957 | } |
| 3958 | break; |
| 3959 | } |
| 3960 | case OMX_IndexConfigCommonOutputCrop: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 3961 | VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_RECTTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3962 | OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData; |
| 3963 | memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE)); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 3964 | DEBUG_PRINT_HIGH("get_config: crop info: L: %u, T: %u, R: %u, B: %u", |
| 3965 | rectangle.nLeft, rectangle.nTop, |
| 3966 | rectangle.nWidth, rectangle.nHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3967 | break; |
| 3968 | } |
| 3969 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3970 | DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3971 | eRet = OMX_ErrorBadParameter; |
| 3972 | } |
| 3973 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3974 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3975 | |
| 3976 | return eRet; |
| 3977 | } |
| 3978 | |
| 3979 | /* ====================================================================== |
| 3980 | FUNCTION |
| 3981 | omx_vdec::SetConfig |
| 3982 | |
| 3983 | DESCRIPTION |
| 3984 | OMX Set Config method implementation |
| 3985 | |
| 3986 | PARAMETERS |
| 3987 | <TBD>. |
| 3988 | |
| 3989 | RETURN VALUE |
| 3990 | OMX Error None if successful. |
| 3991 | ========================================================================== */ |
| 3992 | OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp, |
| 3993 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3994 | OMX_IN OMX_PTR configData) |
| 3995 | { |
| 3996 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3997 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3998 | return OMX_ErrorInvalidState; |
| 3999 | } |
| 4000 | |
| 4001 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 4002 | OMX_VIDEO_CONFIG_NALSIZE *pNal; |
| 4003 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4004 | DEBUG_PRINT_LOW("Set Config Called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4005 | |
| 4006 | if (configIndex == (OMX_INDEXTYPE)OMX_IndexVendorVideoExtraData) { |
| 4007 | OMX_VENDOR_EXTRADATATYPE *config = (OMX_VENDOR_EXTRADATATYPE *) configData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4008 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4009 | if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4010 | DEBUG_PRINT_LOW("Index OMX_IndexVendorVideoExtraData AVC"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4011 | OMX_U32 extra_size; |
| 4012 | // Parsing done here for the AVC atom is definitely not generic |
| 4013 | // Currently this piece of code is working, but certainly |
| 4014 | // not tested with all .mp4 files. |
| 4015 | // Incase of failure, we might need to revisit this |
| 4016 | // for a generic piece of code. |
| 4017 | |
| 4018 | // Retrieve size of NAL length field |
| 4019 | // byte #4 contains the size of NAL lenght field |
| 4020 | nal_length = (config->pData[4] & 0x03) + 1; |
| 4021 | |
| 4022 | extra_size = 0; |
| 4023 | if (nal_length > 2) { |
| 4024 | /* Presently we assume that only one SPS and one PPS in AvC1 Atom */ |
| 4025 | extra_size = (nal_length - 2) * 2; |
| 4026 | } |
| 4027 | |
| 4028 | // SPS starts from byte #6 |
| 4029 | OMX_U8 *pSrcBuf = (OMX_U8 *) (&config->pData[6]); |
| 4030 | OMX_U8 *pDestBuf; |
| 4031 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4032 | |
| 4033 | // minus 6 --> SPS starts from byte #6 |
| 4034 | // minus 1 --> picture param set byte to be ignored from avcatom |
| 4035 | m_vendor_config.nDataSize = config->nDataSize - 6 - 1 + extra_size; |
| 4036 | m_vendor_config.pData = (OMX_U8 *) malloc(m_vendor_config.nDataSize); |
| 4037 | OMX_U32 len; |
| 4038 | OMX_U8 index = 0; |
| 4039 | // case where SPS+PPS is sent as part of set_config |
| 4040 | pDestBuf = m_vendor_config.pData; |
| 4041 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4042 | DEBUG_PRINT_LOW("Rxd SPS+PPS nPortIndex[%lu] len[%lu] data[%p]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4043 | m_vendor_config.nPortIndex, |
| 4044 | m_vendor_config.nDataSize, |
| 4045 | m_vendor_config.pData); |
| 4046 | while (index < 2) { |
| 4047 | uint8 *psize; |
| 4048 | len = *pSrcBuf; |
| 4049 | len = len << 8; |
| 4050 | len |= *(pSrcBuf + 1); |
| 4051 | psize = (uint8 *) & len; |
| 4052 | memcpy(pDestBuf + nal_length, pSrcBuf + 2,len); |
| 4053 | for (unsigned int i = 0; i < nal_length; i++) { |
| 4054 | pDestBuf[i] = psize[nal_length - 1 - i]; |
| 4055 | } |
| 4056 | //memcpy(pDestBuf,pSrcBuf,(len+2)); |
| 4057 | pDestBuf += len + nal_length; |
| 4058 | pSrcBuf += len + 2; |
| 4059 | index++; |
| 4060 | pSrcBuf++; // skip picture param set |
| 4061 | len = 0; |
| 4062 | } |
| 4063 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4") || |
| 4064 | !strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2")) { |
| 4065 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4066 | m_vendor_config.nDataSize = config->nDataSize; |
| 4067 | m_vendor_config.pData = (OMX_U8 *) malloc((config->nDataSize)); |
| 4068 | memcpy(m_vendor_config.pData, config->pData,config->nDataSize); |
| 4069 | } else if (!strcmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1")) { |
| 4070 | if (m_vendor_config.pData) { |
| 4071 | free(m_vendor_config.pData); |
| 4072 | m_vendor_config.pData = NULL; |
| 4073 | m_vendor_config.nDataSize = 0; |
| 4074 | } |
| 4075 | |
| 4076 | if (((*((OMX_U32 *) config->pData)) & |
| 4077 | VC1_SP_MP_START_CODE_MASK) == |
| 4078 | VC1_SP_MP_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4079 | DEBUG_PRINT_LOW("set_config - VC1 simple/main profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4080 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4081 | m_vendor_config.nDataSize = config->nDataSize; |
| 4082 | m_vendor_config.pData = |
| 4083 | (OMX_U8 *) malloc(config->nDataSize); |
| 4084 | memcpy(m_vendor_config.pData, config->pData, |
| 4085 | config->nDataSize); |
| 4086 | m_vc1_profile = VC1_SP_MP_RCV; |
| 4087 | } else if (*((OMX_U32 *) config->pData) == VC1_AP_SEQ_START_CODE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4088 | DEBUG_PRINT_LOW("set_config - VC1 Advance profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4089 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4090 | m_vendor_config.nDataSize = config->nDataSize; |
| 4091 | m_vendor_config.pData = |
| 4092 | (OMX_U8 *) malloc((config->nDataSize)); |
| 4093 | memcpy(m_vendor_config.pData, config->pData, |
| 4094 | config->nDataSize); |
| 4095 | m_vc1_profile = VC1_AP; |
| 4096 | } else if ((config->nDataSize == VC1_STRUCT_C_LEN)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4097 | DEBUG_PRINT_LOW("set_config - VC1 Simple/Main profile struct C only"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4098 | m_vendor_config.nPortIndex = config->nPortIndex; |
| 4099 | m_vendor_config.nDataSize = config->nDataSize; |
| 4100 | m_vendor_config.pData = (OMX_U8*)malloc(config->nDataSize); |
| 4101 | memcpy(m_vendor_config.pData,config->pData,config->nDataSize); |
| 4102 | m_vc1_profile = VC1_SP_MP_RCV; |
| 4103 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4104 | DEBUG_PRINT_LOW("set_config - Error: Unknown VC1 profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4105 | } |
| 4106 | } |
| 4107 | return ret; |
| 4108 | } else if (configIndex == OMX_IndexConfigVideoNalSize) { |
| 4109 | struct v4l2_control temp; |
| 4110 | temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT; |
| 4111 | |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 4112 | VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_NALSIZE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4113 | pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData); |
| 4114 | switch (pNal->nNaluBytes) { |
| 4115 | case 0: |
| 4116 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES; |
| 4117 | break; |
| 4118 | case 2: |
| 4119 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH; |
| 4120 | break; |
| 4121 | case 4: |
| 4122 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH; |
| 4123 | break; |
| 4124 | default: |
| 4125 | return OMX_ErrorUnsupportedSetting; |
| 4126 | } |
| 4127 | |
| 4128 | if (!arbitrary_bytes) { |
| 4129 | /* In arbitrary bytes mode, the assembler strips out nal size and replaces |
| 4130 | * with start code, so only need to notify driver in frame by frame mode */ |
| 4131 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) { |
| 4132 | DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT"); |
| 4133 | return OMX_ErrorHardware; |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | nal_length = pNal->nNaluBytes; |
| 4138 | m_frame_parser.init_nal_length(nal_length); |
| 4139 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4140 | DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4141 | return ret; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4142 | } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4143 | OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4144 | DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4145 | |
| 4146 | if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 4147 | if (config->bEnabled) { |
| 4148 | if ((config->nFps >> 16) > 0) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4149 | DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4150 | config->nFps >> 16); |
| 4151 | Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator, |
| 4152 | drv_ctx.frame_rate.fps_denominator); |
| 4153 | |
| 4154 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 4155 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 4156 | drv_ctx.frame_rate.fps_numerator = 30; |
| 4157 | } |
| 4158 | |
| 4159 | if (drv_ctx.frame_rate.fps_denominator) { |
| 4160 | drv_ctx.frame_rate.fps_numerator = (int) |
| 4161 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 4162 | } |
| 4163 | |
| 4164 | drv_ctx.frame_rate.fps_denominator = 1; |
| 4165 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 4166 | drv_ctx.frame_rate.fps_numerator; |
| 4167 | |
| 4168 | struct v4l2_outputparm oparm; |
| 4169 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 4170 | * per second.*/ |
| 4171 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 4172 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 4173 | |
| 4174 | struct v4l2_streamparm sparm; |
| 4175 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 4176 | sparm.parm.output = oparm; |
| 4177 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 4178 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 4179 | performance might be affected"); |
| 4180 | ret = OMX_ErrorHardware; |
| 4181 | } |
| 4182 | client_set_fps = true; |
| 4183 | } else { |
| 4184 | DEBUG_PRINT_ERROR("Frame rate not supported."); |
| 4185 | ret = OMX_ErrorUnsupportedSetting; |
| 4186 | } |
| 4187 | } else { |
| 4188 | DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate"); |
| 4189 | client_set_fps = false; |
| 4190 | } |
| 4191 | } else { |
| 4192 | DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d", |
| 4193 | (int)config->nPortIndex); |
| 4194 | ret = OMX_ErrorBadPortIndex; |
| 4195 | } |
| 4196 | |
| 4197 | return ret; |
Praveen Chavan | 898df26 | 2015-04-20 18:52:19 -0700 | [diff] [blame] | 4198 | } else if ((int)configIndex == (int)OMX_IndexConfigPriority) { |
| 4199 | OMX_PARAM_U32TYPE *priority = (OMX_PARAM_U32TYPE *)configData; |
| 4200 | DEBUG_PRINT_LOW("Set_config: priority %d", priority->nU32); |
| 4201 | |
| 4202 | struct v4l2_control control; |
| 4203 | |
| 4204 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY; |
| 4205 | if (priority->nU32 == 0) |
| 4206 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_ENABLE; |
| 4207 | else |
| 4208 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE; |
| 4209 | |
| 4210 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 4211 | DEBUG_PRINT_ERROR("Failed to set Priority"); |
| 4212 | ret = OMX_ErrorUnsupportedSetting; |
| 4213 | } |
| 4214 | return ret; |
Praveen Chavan | 281d502 | 2015-04-30 20:28:44 -0700 | [diff] [blame] | 4215 | } else if ((int)configIndex == (int)OMX_IndexConfigOperatingRate) { |
| 4216 | OMX_PARAM_U32TYPE *rate = (OMX_PARAM_U32TYPE *)configData; |
| 4217 | DEBUG_PRINT_LOW("Set_config: operating-rate %u fps", rate->nU32 >> 16); |
| 4218 | |
| 4219 | struct v4l2_control control; |
| 4220 | |
| 4221 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OPERATING_RATE; |
| 4222 | control.value = rate->nU32; |
| 4223 | |
| 4224 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 4225 | ret = errno == -EBUSY ? OMX_ErrorInsufficientResources : |
| 4226 | OMX_ErrorUnsupportedSetting; |
| 4227 | DEBUG_PRINT_ERROR("Failed to set operating rate %u fps (%s)", |
| 4228 | rate->nU32 >> 16, errno == -EBUSY ? "HW Overload" : strerror(errno)); |
| 4229 | } |
| 4230 | return ret; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | return OMX_ErrorNotImplemented; |
| 4234 | } |
| 4235 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4236 | #define extn_equals(param, extn) (!strncmp(param, extn, strlen(extn))) |
| 4237 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4238 | /* ====================================================================== |
| 4239 | FUNCTION |
| 4240 | omx_vdec::GetExtensionIndex |
| 4241 | |
| 4242 | DESCRIPTION |
| 4243 | OMX GetExtensionIndex method implementaion. <TBD> |
| 4244 | |
| 4245 | PARAMETERS |
| 4246 | <TBD>. |
| 4247 | |
| 4248 | RETURN VALUE |
| 4249 | OMX Error None if everything successful. |
| 4250 | |
| 4251 | ========================================================================== */ |
| 4252 | OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp, |
| 4253 | OMX_IN OMX_STRING paramName, |
| 4254 | OMX_OUT OMX_INDEXTYPE* indexType) |
| 4255 | { |
| 4256 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4257 | DEBUG_PRINT_ERROR("Get Extension Index in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4258 | return OMX_ErrorInvalidState; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4259 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode")) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4260 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4261 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.IndexExtraData")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4262 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4263 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_FRAMEPACKING_EXTRADATA)) { |
| 4264 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoFramePackingExtradata; |
| 4265 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_CONFIG_VIDEO_FRAMEPACKING_INFO)) { |
| 4266 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoFramePackingArrangement; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 4267 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_QP_EXTRADATA)) { |
| 4268 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPExtraData; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 4269 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_INPUTBITSINFO_EXTRADATA)) { |
| 4270 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoInputBitsInfoExtraData; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 4271 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_EXTNUSER_EXTRADATA)) { |
| 4272 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableExtnUserData; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4273 | } |
| 4274 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4275 | else if (extn_equals(paramName, "OMX.google.android.index.enableAndroidNativeBuffers")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4276 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4277 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer2")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4278 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4279 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4280 | DEBUG_PRINT_ERROR("Extension: %s is supported", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4281 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4282 | } else if (extn_equals(paramName, "OMX.google.android.index.getAndroidNativeBufferUsage")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4283 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage; |
| 4284 | } |
| 4285 | #endif |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4286 | else if (extn_equals(paramName, "OMX.google.android.index.storeMetaDataInBuffers")) { |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 4287 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode; |
| 4288 | } |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 4289 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 4290 | else if (extn_equals(paramName, "OMX.google.android.index.prepareForAdaptivePlayback")) { |
| 4291 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoAdaptivePlaybackMode; |
| 4292 | } |
| 4293 | #endif |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 4294 | #ifdef FLEXYUV_SUPPORTED |
| 4295 | else if (extn_equals(paramName,"OMX.google.android.index.describeColorFormat")) { |
| 4296 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexFlexibleYUVDescription; |
| 4297 | } |
| 4298 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4299 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4300 | DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4301 | return OMX_ErrorNotImplemented; |
| 4302 | } |
| 4303 | return OMX_ErrorNone; |
| 4304 | } |
| 4305 | |
| 4306 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4307 | FUNCTION |
| 4308 | omx_vdec::GetState |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4309 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4310 | DESCRIPTION |
| 4311 | Returns the state information back to the caller.<TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4312 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4313 | PARAMETERS |
| 4314 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4315 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4316 | RETURN VALUE |
| 4317 | Error None if everything is successful. |
| 4318 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4319 | OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4320 | OMX_OUT OMX_STATETYPE* state) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4321 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4322 | *state = m_state; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4323 | DEBUG_PRINT_LOW("get_state: Returning the state %d",*state); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4324 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4328 | FUNCTION |
| 4329 | omx_vdec::ComponentTunnelRequest |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4330 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4331 | DESCRIPTION |
| 4332 | OMX Component Tunnel Request method implementation. <TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4333 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4334 | PARAMETERS |
| 4335 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4336 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4337 | RETURN VALUE |
| 4338 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4339 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4340 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4341 | OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4342 | OMX_IN OMX_U32 port, |
| 4343 | OMX_IN OMX_HANDLETYPE peerComponent, |
| 4344 | OMX_IN OMX_U32 peerPort, |
| 4345 | OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4346 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4347 | DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4348 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4352 | FUNCTION |
| 4353 | omx_vdec::UseOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4354 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4355 | DESCRIPTION |
| 4356 | Helper function for Use buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4357 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4358 | PARAMETERS |
| 4359 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4360 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4361 | RETURN VALUE |
| 4362 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4363 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4364 | ========================================================================== */ |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4365 | OMX_ERRORTYPE omx_vdec::allocate_extradata() |
| 4366 | { |
| 4367 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4368 | if (drv_ctx.extradata_info.buffer_size) { |
| 4369 | if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) { |
| 4370 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4371 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4372 | free_ion_memory(&drv_ctx.extradata_info.ion); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4373 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4374 | } |
| 4375 | drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095); |
| 4376 | drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory( |
| 4377 | drv_ctx.extradata_info.size, 4096, |
| 4378 | &drv_ctx.extradata_info.ion.ion_alloc_data, |
| 4379 | &drv_ctx.extradata_info.ion.fd_ion_data, 0); |
| 4380 | if (drv_ctx.extradata_info.ion.ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4381 | DEBUG_PRINT_ERROR("Failed to alloc extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4382 | return OMX_ErrorInsufficientResources; |
| 4383 | } |
| 4384 | drv_ctx.extradata_info.uaddr = (char *)mmap(NULL, |
| 4385 | drv_ctx.extradata_info.size, |
| 4386 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4387 | drv_ctx.extradata_info.ion.fd_ion_data.fd , 0); |
| 4388 | if (drv_ctx.extradata_info.uaddr == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4389 | DEBUG_PRINT_ERROR("Failed to map extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4390 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4391 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4392 | return OMX_ErrorInsufficientResources; |
| 4393 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4394 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4395 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4396 | if (!m_other_extradata) { |
| 4397 | m_other_extradata = (OMX_OTHER_EXTRADATATYPE *)malloc(drv_ctx.extradata_info.buffer_size); |
| 4398 | if (!m_other_extradata) { |
| 4399 | DEBUG_PRINT_ERROR("Failed to alloc memory\n"); |
| 4400 | return OMX_ErrorInsufficientResources; |
| 4401 | } |
| 4402 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4403 | return OMX_ErrorNone; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4406 | void omx_vdec::free_extradata() |
| 4407 | { |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4408 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4409 | if (drv_ctx.extradata_info.uaddr) { |
| 4410 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4411 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4412 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4413 | } |
| 4414 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4415 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4416 | if (m_other_extradata) { |
| 4417 | free(m_other_extradata); |
| 4418 | m_other_extradata = NULL; |
| 4419 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4422 | OMX_ERRORTYPE omx_vdec::use_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4423 | OMX_IN OMX_HANDLETYPE hComp, |
| 4424 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4425 | OMX_IN OMX_U32 port, |
| 4426 | OMX_IN OMX_PTR appData, |
| 4427 | OMX_IN OMX_U32 bytes, |
| 4428 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4429 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4430 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4431 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 4432 | unsigned i= 0; // Temporary counter |
| 4433 | struct vdec_setbuffer_cmd setbuffers; |
| 4434 | OMX_PTR privateAppData = NULL; |
| 4435 | private_handle_t *handle = NULL; |
| 4436 | OMX_U8 *buff = buffer; |
| 4437 | struct v4l2_buffer buf; |
| 4438 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 4439 | int extra_idx = 0; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4440 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4441 | if (!m_out_mem_ptr) { |
| 4442 | DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers"); |
| 4443 | eRet = allocate_output_headers(); |
| 4444 | if (eRet == OMX_ErrorNone) |
| 4445 | eRet = allocate_extradata(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4446 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4447 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4448 | if (eRet == OMX_ErrorNone) { |
| 4449 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 4450 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
| 4451 | break; |
| 4452 | } |
| 4453 | } |
| 4454 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4455 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4456 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4457 | 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] | 4458 | eRet = OMX_ErrorInsufficientResources; |
| 4459 | } |
| 4460 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 4461 | if (dynamic_buf_mode) { |
| 4462 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4463 | (*bufferHdr)->pBuffer = NULL; |
| 4464 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4465 | enum v4l2_buf_type buf_type; |
| 4466 | int rr = 0; |
| 4467 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4468 | if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4469 | DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr); |
| 4470 | return OMX_ErrorInsufficientResources; |
| 4471 | } else { |
| 4472 | streaming[CAPTURE_PORT] = true; |
| 4473 | DEBUG_PRINT_LOW("STREAMON Successful"); |
| 4474 | } |
| 4475 | } |
| 4476 | BITMASK_SET(&m_out_bm_count,i); |
| 4477 | (*bufferHdr)->pAppPrivate = appData; |
| 4478 | (*bufferHdr)->pBuffer = buffer; |
| 4479 | (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 4480 | return eRet; |
| 4481 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4482 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4483 | #if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4484 | if (m_enable_android_native_buffers) { |
| 4485 | if (m_use_android_native_buffers) { |
| 4486 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData; |
| 4487 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 4488 | handle = (private_handle_t *)nBuf->handle; |
| 4489 | privateAppData = params->pAppPrivate; |
| 4490 | } else { |
| 4491 | handle = (private_handle_t *)buff; |
| 4492 | privateAppData = appData; |
| 4493 | } |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4494 | if (!handle) { |
| 4495 | DEBUG_PRINT_ERROR("handle is invalid"); |
| 4496 | return OMX_ErrorBadParameter; |
| 4497 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4498 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4499 | if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) { |
| 4500 | DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback," |
| 4501 | " expected %u, got %lu", |
| 4502 | drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size); |
| 4503 | return OMX_ErrorBadParameter; |
| 4504 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4505 | |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 4506 | drv_ctx.op_buf.buffer_size = handle->size; |
| 4507 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4508 | if (!m_use_android_native_buffers) { |
| 4509 | if (!secure_mode) { |
| 4510 | buff = (OMX_U8*)mmap(0, handle->size, |
| 4511 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
| 4512 | if (buff == MAP_FAILED) { |
| 4513 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 4514 | return OMX_ErrorInsufficientResources; |
| 4515 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4516 | } |
| 4517 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4518 | #if defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4519 | native_buffer[i].nativehandle = handle; |
| 4520 | native_buffer[i].privatehandle = handle; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4521 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4522 | if (!handle) { |
| 4523 | DEBUG_PRINT_ERROR("Native Buffer handle is NULL"); |
| 4524 | return OMX_ErrorBadParameter; |
| 4525 | } |
| 4526 | drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd; |
| 4527 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4528 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4529 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4530 | drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size; |
| 4531 | } else |
| 4532 | #endif |
| 4533 | |
| 4534 | if (!ouput_egl_buffers && !m_use_output_pmem) { |
| 4535 | #ifdef USE_ION |
| 4536 | drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 4537 | drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 4538 | &drv_ctx.op_buf_ion_info[i].ion_alloc_data, |
| 4539 | &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4540 | if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4541 | 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] | 4542 | return OMX_ErrorInsufficientResources; |
| 4543 | } |
| 4544 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4545 | drv_ctx.op_buf_ion_info[i].fd_ion_data.fd; |
| 4546 | #else |
| 4547 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4548 | open (MEM_DEVICE,O_RDWR); |
| 4549 | |
| 4550 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4551 | 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] | 4552 | return OMX_ErrorInsufficientResources; |
| 4553 | } |
| 4554 | |
| 4555 | /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */ |
| 4556 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) { |
| 4557 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4558 | open (MEM_DEVICE,O_RDWR); |
| 4559 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4560 | 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] | 4561 | return OMX_ErrorInsufficientResources; |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd, |
| 4566 | drv_ctx.op_buf.buffer_size, |
| 4567 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4568 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4569 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4570 | return OMX_ErrorInsufficientResources; |
| 4571 | } |
| 4572 | #endif |
| 4573 | if (!secure_mode) { |
| 4574 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 4575 | (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size, |
| 4576 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4577 | drv_ctx.ptr_outputbuffer[i].pmem_fd,0); |
| 4578 | if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) { |
| 4579 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4580 | #ifdef USE_ION |
| 4581 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
| 4582 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4583 | DEBUG_PRINT_ERROR("Unable to mmap output buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4584 | return OMX_ErrorInsufficientResources; |
| 4585 | } |
| 4586 | } |
| 4587 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4588 | privateAppData = appData; |
| 4589 | } else { |
| 4590 | |
| 4591 | DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem); |
| 4592 | if (!appData || !bytes ) { |
| 4593 | if (!secure_mode && !buffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4594 | DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4595 | return OMX_ErrorBadParameter; |
| 4596 | } |
| 4597 | } |
| 4598 | |
| 4599 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list; |
| 4600 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info; |
| 4601 | pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData; |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4602 | if (!pmem_list || !pmem_list->entryList || !pmem_list->entryList->entry || |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4603 | !pmem_list->nEntries || |
| 4604 | pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4605 | DEBUG_PRINT_ERROR("Pmem info not valid in use buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4606 | return OMX_ErrorBadParameter; |
| 4607 | } |
| 4608 | pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 4609 | pmem_list->entryList->entry; |
| 4610 | DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx", |
| 4611 | pmem_info->pmem_fd); |
| 4612 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd; |
| 4613 | drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset; |
| 4614 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4615 | drv_ctx.ptr_outputbuffer[i].mmaped_size = |
| 4616 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4617 | privateAppData = appData; |
| 4618 | } |
| 4619 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 4620 | 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] | 4621 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 4622 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 4623 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4624 | |
| 4625 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4626 | if (secure_mode) |
| 4627 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 4628 | //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4629 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i], |
| 4630 | sizeof (vdec_bufferpayload)); |
| 4631 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4632 | 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] | 4633 | drv_ctx.ptr_outputbuffer[i].bufferaddr, |
| 4634 | drv_ctx.ptr_outputbuffer[i].pmem_fd ); |
| 4635 | |
| 4636 | buf.index = i; |
| 4637 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4638 | buf.memory = V4L2_MEMORY_USERPTR; |
| 4639 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 4640 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 4641 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
| 4642 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
| 4643 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 4644 | plane[0].data_offset = 0; |
| 4645 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 4646 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 4647 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 4648 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
| 4649 | #ifdef USE_ION |
| 4650 | plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd; |
| 4651 | #endif |
| 4652 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 4653 | plane[extra_idx].data_offset = 0; |
| 4654 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4655 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4656 | return OMX_ErrorBadParameter; |
| 4657 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4658 | buf.m.planes = plane; |
| 4659 | buf.length = drv_ctx.num_planes; |
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 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4662 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4663 | /*TODO: How to handle this case */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4664 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4665 | } |
| 4666 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4667 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4668 | enum v4l2_buf_type buf_type; |
| 4669 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4670 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4671 | return OMX_ErrorInsufficientResources; |
| 4672 | } else { |
| 4673 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4674 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4675 | } |
| 4676 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4677 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4678 | (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size; |
| 4679 | if (m_enable_android_native_buffers) { |
| 4680 | DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle); |
| 4681 | (*bufferHdr)->pBuffer = (OMX_U8 *)handle; |
| 4682 | } else { |
| 4683 | (*bufferHdr)->pBuffer = buff; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4684 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4685 | (*bufferHdr)->pAppPrivate = privateAppData; |
| 4686 | BITMASK_SET(&m_out_bm_count,i); |
| 4687 | } |
| 4688 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4692 | FUNCTION |
| 4693 | omx_vdec::use_input_heap_buffers |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4694 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4695 | DESCRIPTION |
| 4696 | OMX Use Buffer Heap allocation method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4697 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4698 | PARAMETERS |
| 4699 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4700 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4701 | RETURN VALUE |
| 4702 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4703 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4704 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4705 | OMX_ERRORTYPE omx_vdec::use_input_heap_buffers( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4706 | OMX_IN OMX_HANDLETYPE hComp, |
| 4707 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4708 | OMX_IN OMX_U32 port, |
| 4709 | OMX_IN OMX_PTR appData, |
| 4710 | OMX_IN OMX_U32 bytes, |
| 4711 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4712 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4713 | DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4714 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4715 | if (!m_inp_heap_ptr) |
| 4716 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) |
| 4717 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4718 | drv_ctx.ip_buf.actualcount); |
| 4719 | if (!m_phdr_pmem_ptr) |
| 4720 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) |
| 4721 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4722 | drv_ctx.ip_buf.actualcount); |
| 4723 | if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) { |
| 4724 | DEBUG_PRINT_ERROR("Insufficent memory"); |
| 4725 | eRet = OMX_ErrorInsufficientResources; |
| 4726 | } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) { |
| 4727 | input_use_buffer = true; |
| 4728 | memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE)); |
| 4729 | m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer; |
| 4730 | m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes; |
| 4731 | m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData; |
| 4732 | m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput; |
| 4733 | m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax; |
| 4734 | *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt]; |
| 4735 | 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] | 4736 | 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] | 4737 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt], |
| 4738 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4739 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4740 | return OMX_ErrorInsufficientResources; |
| 4741 | } |
| 4742 | m_in_alloc_cnt++; |
| 4743 | } else { |
| 4744 | DEBUG_PRINT_ERROR("All i/p buffers have been set!"); |
| 4745 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4746 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4747 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4748 | } |
| 4749 | |
| 4750 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4751 | FUNCTION |
| 4752 | omx_vdec::UseBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4753 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4754 | DESCRIPTION |
| 4755 | OMX Use Buffer method implementation. |
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 | PARAMETERS |
| 4758 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4759 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4760 | RETURN VALUE |
| 4761 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4762 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4763 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4764 | OMX_ERRORTYPE omx_vdec::use_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4765 | OMX_IN OMX_HANDLETYPE hComp, |
| 4766 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4767 | OMX_IN OMX_U32 port, |
| 4768 | OMX_IN OMX_PTR appData, |
| 4769 | OMX_IN OMX_U32 bytes, |
| 4770 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4771 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4772 | OMX_ERRORTYPE error = OMX_ErrorNone; |
| 4773 | struct vdec_setbuffer_cmd setbuffers; |
| 4774 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4775 | if (bufferHdr == NULL || bytes == 0 || (!secure_mode && buffer == NULL)) { |
| 4776 | DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer); |
| 4777 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4778 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4779 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4780 | DEBUG_PRINT_ERROR("Use Buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4781 | return OMX_ErrorInvalidState; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4782 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4783 | if (port == OMX_CORE_INPUT_PORT_INDEX) |
| 4784 | error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer); |
| 4785 | else if (port == OMX_CORE_OUTPUT_PORT_INDEX) |
| 4786 | error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested |
| 4787 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4788 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4789 | error = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4790 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4791 | DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error); |
| 4792 | if (error == OMX_ErrorNone) { |
| 4793 | if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 4794 | // Send the callback now |
| 4795 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 4796 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
| 4797 | OMX_COMPONENT_GENERATE_EVENT); |
| 4798 | } |
| 4799 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated && |
| 4800 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 4801 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 4802 | post_event(OMX_CommandPortEnable, |
| 4803 | OMX_CORE_INPUT_PORT_INDEX, |
| 4804 | OMX_COMPONENT_GENERATE_EVENT); |
| 4805 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated && |
| 4806 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 4807 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 4808 | post_event(OMX_CommandPortEnable, |
| 4809 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 4810 | OMX_COMPONENT_GENERATE_EVENT); |
| 4811 | } |
| 4812 | } |
| 4813 | return error; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4817 | OMX_BUFFERHEADERTYPE *pmem_bufferHdr) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4818 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4819 | if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) { |
| 4820 | if (m_inp_heap_ptr[bufferindex].pBuffer) |
| 4821 | free(m_inp_heap_ptr[bufferindex].pBuffer); |
| 4822 | m_inp_heap_ptr[bufferindex].pBuffer = NULL; |
| 4823 | } |
| 4824 | if (pmem_bufferHdr) |
| 4825 | free_input_buffer(pmem_bufferHdr); |
| 4826 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4830 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4831 | unsigned int index = 0; |
| 4832 | if (bufferHdr == NULL || m_inp_mem_ptr == NULL) { |
| 4833 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4834 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4835 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4836 | index = bufferHdr - m_inp_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4837 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4838 | |
| 4839 | if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4840 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4841 | if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) { |
| 4842 | struct vdec_setbuffer_cmd setbuffers; |
| 4843 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 4844 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index], |
| 4845 | sizeof (vdec_bufferpayload)); |
| 4846 | if (!secure_mode) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4847 | DEBUG_PRINT_LOW("unmap the input buffer fd=%d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4848 | drv_ctx.ptr_inputbuffer[index].pmem_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4849 | DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4850 | drv_ctx.ptr_inputbuffer[index].mmaped_size, |
| 4851 | drv_ctx.ptr_inputbuffer[index].bufferaddr); |
| 4852 | munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr, |
| 4853 | drv_ctx.ptr_inputbuffer[index].mmaped_size); |
| 4854 | } |
| 4855 | close (drv_ctx.ptr_inputbuffer[index].pmem_fd); |
| 4856 | drv_ctx.ptr_inputbuffer[index].pmem_fd = -1; |
| 4857 | if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) { |
| 4858 | free(m_desc_buffer_ptr[index].buf_addr); |
| 4859 | m_desc_buffer_ptr[index].buf_addr = NULL; |
| 4860 | m_desc_buffer_ptr[index].desc_data_size = 0; |
| 4861 | } |
| 4862 | #ifdef USE_ION |
| 4863 | free_ion_memory(&drv_ctx.ip_buf_ion_info[index]); |
| 4864 | #endif |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4872 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4873 | unsigned int index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4874 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4875 | if (bufferHdr == NULL || m_out_mem_ptr == NULL) { |
| 4876 | return OMX_ErrorBadParameter; |
| 4877 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4878 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4879 | index = bufferHdr - m_out_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4880 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4881 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4882 | if (index < drv_ctx.op_buf.actualcount |
| 4883 | && drv_ctx.ptr_outputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4884 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4885 | drv_ctx.ptr_outputbuffer[index].bufferaddr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4886 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4887 | struct vdec_setbuffer_cmd setbuffers; |
| 4888 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4889 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index], |
| 4890 | sizeof (vdec_bufferpayload)); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4891 | |
| 4892 | if (!dynamic_buf_mode) { |
Balamurugan Alagarsamy | e773c58 | 2014-12-17 15:10:25 +0530 | [diff] [blame] | 4893 | if (streaming[CAPTURE_PORT] && |
| 4894 | !(in_reconfig || BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING))) { |
| 4895 | if (stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
| 4896 | DEBUG_PRINT_ERROR("STREAMOFF Failed"); |
| 4897 | } else { |
| 4898 | DEBUG_PRINT_LOW("STREAMOFF Successful"); |
| 4899 | } |
| 4900 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4901 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4902 | if (m_enable_android_native_buffers) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4903 | if (!secure_mode) { |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4904 | if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) { |
| 4905 | munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr, |
| 4906 | drv_ctx.ptr_outputbuffer[index].mmaped_size); |
| 4907 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4908 | } |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4909 | drv_ctx.ptr_outputbuffer[index].pmem_fd = -1; |
| 4910 | } else { |
| 4911 | #endif |
| 4912 | if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) { |
| 4913 | if (!secure_mode) { |
| 4914 | DEBUG_PRINT_LOW("\n unmap the output buffer fd = %d", |
| 4915 | drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4916 | DEBUG_PRINT_LOW("\n unmap the ouput buffer size=%d address = %p", |
| 4917 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount, |
| 4918 | drv_ctx.ptr_outputbuffer[0].bufferaddr); |
| 4919 | munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr, |
| 4920 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount); |
| 4921 | } |
| 4922 | close (drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4923 | drv_ctx.ptr_outputbuffer[0].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4924 | #ifdef USE_ION |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4925 | free_ion_memory(&drv_ctx.op_buf_ion_info[0]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4926 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4927 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4928 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4929 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4930 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4931 | } //!dynamic_buf_mode |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4932 | if (release_output_done()) { |
| 4933 | free_extradata(); |
| 4934 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4935 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4936 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4937 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4938 | |
| 4939 | } |
| 4940 | |
| 4941 | OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4942 | OMX_BUFFERHEADERTYPE **bufferHdr, |
| 4943 | OMX_U32 port, |
| 4944 | OMX_PTR appData, |
| 4945 | OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4946 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4947 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4948 | unsigned char *buf_addr = NULL; |
| 4949 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4950 | unsigned i = 0; |
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 | /* Sanity Check*/ |
| 4953 | if (bufferHdr == NULL) { |
| 4954 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4955 | } |
| 4956 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4957 | if (m_inp_heap_ptr == NULL) { |
| 4958 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4959 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4960 | drv_ctx.ip_buf.actualcount); |
| 4961 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \ |
| 4962 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4963 | drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4964 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4965 | if (m_inp_heap_ptr == NULL || m_phdr_pmem_ptr == NULL) { |
| 4966 | 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] | 4967 | return OMX_ErrorInsufficientResources; |
| 4968 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4969 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4970 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4971 | /*Find a Free index*/ |
| 4972 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 4973 | if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4974 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4975 | break; |
| 4976 | } |
| 4977 | } |
| 4978 | |
| 4979 | if (i < drv_ctx.ip_buf.actualcount) { |
| 4980 | buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size); |
| 4981 | |
| 4982 | if (buf_addr == NULL) { |
| 4983 | return OMX_ErrorInsufficientResources; |
| 4984 | } |
| 4985 | |
| 4986 | *bufferHdr = (m_inp_heap_ptr + i); |
| 4987 | input = *bufferHdr; |
| 4988 | BITMASK_SET(&m_heap_inp_bm_count,i); |
| 4989 | |
| 4990 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 4991 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 4992 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 4993 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 4994 | input->pAppPrivate = appData; |
| 4995 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4996 | DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4997 | 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] | 4998 | 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] | 4999 | /*Add the Buffers to freeq*/ |
| 5000 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i], |
| 5001 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5002 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5003 | return OMX_ErrorInsufficientResources; |
| 5004 | } |
| 5005 | } else { |
| 5006 | return OMX_ErrorBadParameter; |
| 5007 | } |
| 5008 | |
| 5009 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5010 | |
| 5011 | } |
| 5012 | |
| 5013 | |
| 5014 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5015 | FUNCTION |
| 5016 | omx_vdec::AllocateInputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5017 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5018 | DESCRIPTION |
| 5019 | Helper function for allocate buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5020 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5021 | PARAMETERS |
| 5022 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5023 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5024 | RETURN VALUE |
| 5025 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5026 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5027 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5028 | OMX_ERRORTYPE omx_vdec::allocate_input_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5029 | OMX_IN OMX_HANDLETYPE hComp, |
| 5030 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5031 | OMX_IN OMX_U32 port, |
| 5032 | OMX_IN OMX_PTR appData, |
| 5033 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5034 | { |
| 5035 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5036 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5037 | struct vdec_setbuffer_cmd setbuffers; |
| 5038 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 5039 | unsigned i = 0; |
| 5040 | unsigned char *buf_addr = NULL; |
| 5041 | int pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5042 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5043 | if (bytes != drv_ctx.ip_buf.buffer_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5044 | DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5045 | bytes, drv_ctx.ip_buf.buffer_size); |
| 5046 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5049 | if (!m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5050 | DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5051 | drv_ctx.ip_buf.actualcount, |
| 5052 | drv_ctx.ip_buf.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5053 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5054 | m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 5055 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount); |
| 5056 | |
| 5057 | if (m_inp_mem_ptr == NULL) { |
| 5058 | return OMX_ErrorInsufficientResources; |
| 5059 | } |
| 5060 | |
| 5061 | drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \ |
| 5062 | calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount); |
| 5063 | |
| 5064 | if (drv_ctx.ptr_inputbuffer == NULL) { |
| 5065 | return OMX_ErrorInsufficientResources; |
| 5066 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5067 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5068 | drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \ |
| 5069 | calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount); |
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 | if (drv_ctx.ip_buf_ion_info == NULL) { |
| 5072 | return OMX_ErrorInsufficientResources; |
| 5073 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5074 | #endif |
| 5075 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5076 | for (i=0; i < drv_ctx.ip_buf.actualcount; i++) { |
| 5077 | drv_ctx.ptr_inputbuffer [i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5078 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5079 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5080 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5081 | } |
| 5082 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5083 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5084 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 5085 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5086 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5087 | break; |
| 5088 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5089 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5090 | |
| 5091 | if (i < drv_ctx.ip_buf.actualcount) { |
| 5092 | struct v4l2_buffer buf; |
| 5093 | struct v4l2_plane plane; |
| 5094 | int rc; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5095 | DEBUG_PRINT_LOW("Allocate input Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5096 | #ifdef USE_ION |
| 5097 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 5098 | drv_ctx.ip_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 5099 | &drv_ctx.ip_buf_ion_info[i].ion_alloc_data, |
| 5100 | &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 5101 | if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) { |
| 5102 | return OMX_ErrorInsufficientResources; |
| 5103 | } |
| 5104 | pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd; |
| 5105 | #else |
| 5106 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 5107 | |
| 5108 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5109 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5110 | return OMX_ErrorInsufficientResources; |
| 5111 | } |
| 5112 | |
| 5113 | if (pmem_fd == 0) { |
| 5114 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 5115 | |
| 5116 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5117 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5118 | return OMX_ErrorInsufficientResources; |
| 5119 | } |
| 5120 | } |
| 5121 | |
| 5122 | if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size, |
| 5123 | drv_ctx.ip_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5124 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5125 | close(pmem_fd); |
| 5126 | return OMX_ErrorInsufficientResources; |
| 5127 | } |
| 5128 | #endif |
| 5129 | if (!secure_mode) { |
| 5130 | buf_addr = (unsigned char *)mmap(NULL, |
| 5131 | drv_ctx.ip_buf.buffer_size, |
| 5132 | PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0); |
| 5133 | |
| 5134 | if (buf_addr == MAP_FAILED) { |
| 5135 | close(pmem_fd); |
| 5136 | #ifdef USE_ION |
| 5137 | free_ion_memory(&drv_ctx.ip_buf_ion_info[i]); |
| 5138 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5139 | DEBUG_PRINT_ERROR("Map Failed to allocate input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5140 | return OMX_ErrorInsufficientResources; |
| 5141 | } |
| 5142 | } |
| 5143 | *bufferHdr = (m_inp_mem_ptr + i); |
| 5144 | if (secure_mode) |
| 5145 | drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr; |
| 5146 | else |
| 5147 | drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr; |
| 5148 | drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd; |
| 5149 | drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size; |
| 5150 | drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size; |
| 5151 | drv_ctx.ptr_inputbuffer [i].offset = 0; |
| 5152 | |
| 5153 | |
| 5154 | buf.index = i; |
| 5155 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5156 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5157 | plane.bytesused = 0; |
| 5158 | plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size; |
| 5159 | plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr; |
| 5160 | plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 5161 | plane.reserved[1] = 0; |
| 5162 | plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset; |
| 5163 | buf.m.planes = &plane; |
| 5164 | buf.length = 1; |
| 5165 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5166 | DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5167 | drv_ctx.ptr_inputbuffer[i].bufferaddr); |
| 5168 | |
| 5169 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5170 | |
| 5171 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5172 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5173 | /*TODO: How to handle this case */ |
| 5174 | return OMX_ErrorInsufficientResources; |
| 5175 | } |
| 5176 | |
| 5177 | input = *bufferHdr; |
| 5178 | BITMASK_SET(&m_inp_bm_count,i); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5179 | DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5180 | if (secure_mode) |
| 5181 | input->pBuffer = (OMX_U8 *)drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 5182 | else |
| 5183 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 5184 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5185 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5186 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 5187 | input->pAppPrivate = appData; |
| 5188 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
| 5189 | input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i]; |
| 5190 | |
| 5191 | if (drv_ctx.disable_dmx) { |
| 5192 | eRet = allocate_desc_buffer(i); |
| 5193 | } |
| 5194 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5195 | DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5196 | eRet = OMX_ErrorInsufficientResources; |
| 5197 | } |
| 5198 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | |
| 5202 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5203 | FUNCTION |
| 5204 | omx_vdec::AllocateOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5205 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5206 | DESCRIPTION |
| 5207 | Helper fn for AllocateBuffer in the output pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5208 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5209 | PARAMETERS |
| 5210 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5211 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5212 | RETURN VALUE |
| 5213 | OMX Error None if everything went well. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5214 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5215 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5216 | OMX_ERRORTYPE omx_vdec::allocate_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5217 | OMX_IN OMX_HANDLETYPE hComp, |
| 5218 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5219 | OMX_IN OMX_U32 port, |
| 5220 | OMX_IN OMX_PTR appData, |
| 5221 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5222 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5223 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5224 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 5225 | unsigned i= 0; // Temporary counter |
| 5226 | struct vdec_setbuffer_cmd setbuffers; |
| 5227 | int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5228 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5229 | int ion_device_fd =-1; |
| 5230 | struct ion_allocation_data ion_alloc_data; |
| 5231 | struct ion_fd_data fd_ion_data; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5232 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5233 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5234 | DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5235 | drv_ctx.op_buf.actualcount, |
| 5236 | drv_ctx.op_buf.buffer_size); |
| 5237 | int nBufHdrSize = 0; |
| 5238 | int nPlatformEntrySize = 0; |
| 5239 | int nPlatformListSize = 0; |
| 5240 | int nPMEMInfoSize = 0; |
| 5241 | int pmem_fd = -1; |
| 5242 | unsigned char *pmem_baseaddress = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5243 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5244 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 5245 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 5246 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5247 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5248 | DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5249 | drv_ctx.op_buf.actualcount); |
| 5250 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 5251 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5252 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5253 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 5254 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 5255 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 5256 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 5257 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 5258 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5259 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5260 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5261 | sizeof(OMX_BUFFERHEADERTYPE), |
| 5262 | nPMEMInfoSize, |
| 5263 | nPlatformListSize); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5264 | DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5265 | drv_ctx.op_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5266 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5267 | ion_device_fd = alloc_map_ion_memory( |
| 5268 | drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount, |
| 5269 | drv_ctx.op_buf.alignment, |
| 5270 | &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 5271 | if (ion_device_fd < 0) { |
| 5272 | return OMX_ErrorInsufficientResources; |
| 5273 | } |
| 5274 | pmem_fd = fd_ion_data.fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5275 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5276 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5277 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5278 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5279 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5280 | drv_ctx.op_buf.buffer_size); |
| 5281 | return OMX_ErrorInsufficientResources; |
| 5282 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5283 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5284 | if (pmem_fd == 0) { |
| 5285 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5286 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5287 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5288 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5289 | drv_ctx.op_buf.buffer_size); |
| 5290 | return OMX_ErrorInsufficientResources; |
| 5291 | } |
| 5292 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5293 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5294 | if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size * |
| 5295 | drv_ctx.op_buf.actualcount, |
| 5296 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5297 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5298 | close(pmem_fd); |
| 5299 | return OMX_ErrorInsufficientResources; |
| 5300 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5301 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5302 | if (!secure_mode) { |
| 5303 | pmem_baseaddress = (unsigned char *)mmap(NULL, |
| 5304 | (drv_ctx.op_buf.buffer_size * |
| 5305 | drv_ctx.op_buf.actualcount), |
| 5306 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0); |
| 5307 | if (pmem_baseaddress == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5308 | DEBUG_PRINT_ERROR("MMAP failed for Size %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5309 | drv_ctx.op_buf.buffer_size); |
| 5310 | close(pmem_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5311 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5312 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5313 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5314 | return OMX_ErrorInsufficientResources; |
| 5315 | } |
| 5316 | } |
| 5317 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 5318 | // Alloc mem for platform specific info |
| 5319 | char *pPtr=NULL; |
| 5320 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 5321 | nPMEMInfoSize,1); |
| 5322 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\ |
| 5323 | calloc (sizeof(struct vdec_bufferpayload), |
| 5324 | drv_ctx.op_buf.actualcount); |
| 5325 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 5326 | calloc (sizeof (struct vdec_output_frameinfo), |
| 5327 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5328 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 5329 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer "); |
| 5330 | return OMX_ErrorInsufficientResources; |
| 5331 | } |
| 5332 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5333 | #ifdef USE_ION |
| 5334 | drv_ctx.op_buf_ion_info = (struct vdec_ion *)\ |
| 5335 | calloc (sizeof(struct vdec_ion), |
| 5336 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5337 | if (!drv_ctx.op_buf_ion_info) { |
| 5338 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 5339 | return OMX_ErrorInsufficientResources; |
| 5340 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5341 | #endif |
| 5342 | |
| 5343 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 5344 | && drv_ctx.ptr_respbuffer) { |
| 5345 | drv_ctx.ptr_outputbuffer[0].mmaped_size = |
| 5346 | (drv_ctx.op_buf.buffer_size * |
| 5347 | drv_ctx.op_buf.actualcount); |
| 5348 | bufHdr = m_out_mem_ptr; |
| 5349 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 5350 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 5351 | (((char *) m_platform_list) + nPlatformListSize); |
| 5352 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 5353 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 5354 | pPlatformList = m_platform_list; |
| 5355 | pPlatformEntry = m_platform_entry; |
| 5356 | pPMEMInfo = m_pmem_info; |
| 5357 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5358 | 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] | 5359 | |
| 5360 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5361 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry); |
| 5362 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5363 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 5364 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5365 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5366 | // Set the values when we determine the right HxW param |
| 5367 | bufHdr->nAllocLen = bytes; |
| 5368 | bufHdr->nFilledLen = 0; |
| 5369 | bufHdr->pAppPrivate = appData; |
| 5370 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 5371 | // Platform specific PMEM Information |
| 5372 | // Initialize the Platform Entry |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5373 | //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5374 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 5375 | pPlatformEntry->entry = pPMEMInfo; |
| 5376 | // Initialize the Platform List |
| 5377 | pPlatformList->nEntries = 1; |
| 5378 | pPlatformList->entryList = pPlatformEntry; |
| 5379 | // Keep pBuffer NULL till vdec is opened |
| 5380 | bufHdr->pBuffer = NULL; |
| 5381 | bufHdr->nOffset = 0; |
| 5382 | |
| 5383 | pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i; |
| 5384 | pPMEMInfo->pmem_fd = 0; |
| 5385 | bufHdr->pPlatformPrivate = pPlatformList; |
| 5386 | |
| 5387 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd; |
| 5388 | m_pmem_info[i].pmem_fd = pmem_fd; |
| 5389 | #ifdef USE_ION |
| 5390 | drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd; |
| 5391 | drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data; |
| 5392 | drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data; |
| 5393 | #endif |
| 5394 | |
| 5395 | /*Create a mapping between buffers*/ |
| 5396 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 5397 | drv_ctx.ptr_respbuffer[i].client_data = (void *)\ |
| 5398 | &drv_ctx.ptr_outputbuffer[i]; |
| 5399 | drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i; |
| 5400 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 5401 | pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 5402 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 5403 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 5404 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5405 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5406 | DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5407 | pmem_fd, drv_ctx.ptr_outputbuffer[i].offset, |
| 5408 | drv_ctx.ptr_outputbuffer[i].bufferaddr); |
| 5409 | // Move the buffer and buffer header pointers |
| 5410 | bufHdr++; |
| 5411 | pPMEMInfo++; |
| 5412 | pPlatformEntry++; |
| 5413 | pPlatformList++; |
| 5414 | } |
| 5415 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5416 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5417 | m_out_mem_ptr, pPtr); |
| 5418 | if (m_out_mem_ptr) { |
| 5419 | free(m_out_mem_ptr); |
| 5420 | m_out_mem_ptr = NULL; |
| 5421 | } |
| 5422 | if (pPtr) { |
| 5423 | free(pPtr); |
| 5424 | pPtr = NULL; |
| 5425 | } |
| 5426 | if (drv_ctx.ptr_outputbuffer) { |
| 5427 | free(drv_ctx.ptr_outputbuffer); |
| 5428 | drv_ctx.ptr_outputbuffer = NULL; |
| 5429 | } |
| 5430 | if (drv_ctx.ptr_respbuffer) { |
| 5431 | free(drv_ctx.ptr_respbuffer); |
| 5432 | drv_ctx.ptr_respbuffer = NULL; |
| 5433 | } |
| 5434 | #ifdef USE_ION |
| 5435 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5436 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5437 | free(drv_ctx.op_buf_ion_info); |
| 5438 | drv_ctx.op_buf_ion_info = NULL; |
| 5439 | } |
| 5440 | #endif |
| 5441 | eRet = OMX_ErrorInsufficientResources; |
| 5442 | } |
| 5443 | if (eRet == OMX_ErrorNone) |
| 5444 | eRet = allocate_extradata(); |
| 5445 | } |
| 5446 | |
| 5447 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 5448 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5449 | DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5450 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5451 | } |
| 5452 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5453 | |
| 5454 | if (eRet == OMX_ErrorNone) { |
| 5455 | if (i < drv_ctx.op_buf.actualcount) { |
| 5456 | struct v4l2_buffer buf; |
| 5457 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 5458 | int rc; |
| 5459 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 5460 | |
| 5461 | drv_ctx.ptr_outputbuffer[i].buffer_len = |
| 5462 | drv_ctx.op_buf.buffer_size; |
| 5463 | |
| 5464 | *bufferHdr = (m_out_mem_ptr + i ); |
| 5465 | if (secure_mode) { |
| 5466 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 5467 | } |
| 5468 | drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 5469 | |
| 5470 | buf.index = i; |
| 5471 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5472 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5473 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 5474 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 5475 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5476 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5477 | 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] | 5478 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5479 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 5480 | plane[0].data_offset = 0; |
| 5481 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 5482 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 5483 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 5484 | 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] | 5485 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5486 | 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] | 5487 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5488 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 5489 | plane[extra_idx].data_offset = 0; |
| 5490 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5491 | DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5492 | return OMX_ErrorBadParameter; |
| 5493 | } |
| 5494 | buf.m.planes = plane; |
| 5495 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5496 | 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] | 5497 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5498 | if (rc) { |
| 5499 | /*TODO: How to handle this case */ |
| 5500 | return OMX_ErrorInsufficientResources; |
| 5501 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5502 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5503 | if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) { |
| 5504 | enum v4l2_buf_type buf_type; |
| 5505 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5506 | rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5507 | if (rc) { |
| 5508 | return OMX_ErrorInsufficientResources; |
| 5509 | } else { |
| 5510 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5511 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5512 | } |
| 5513 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5514 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5515 | (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr; |
| 5516 | (*bufferHdr)->pAppPrivate = appData; |
| 5517 | BITMASK_SET(&m_out_bm_count,i); |
| 5518 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5519 | DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5520 | eRet = OMX_ErrorInsufficientResources; |
| 5521 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5522 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5523 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5524 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | |
| 5528 | // AllocateBuffer -- API Call |
| 5529 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5530 | FUNCTION |
| 5531 | omx_vdec::AllocateBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5532 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5533 | DESCRIPTION |
| 5534 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5535 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5536 | PARAMETERS |
| 5537 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5538 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5539 | RETURN VALUE |
| 5540 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5541 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5542 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5543 | OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5544 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5545 | OMX_IN OMX_U32 port, |
| 5546 | OMX_IN OMX_PTR appData, |
| 5547 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5548 | { |
| 5549 | unsigned i = 0; |
| 5550 | OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type |
| 5551 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5552 | DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5553 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5554 | DEBUG_PRINT_ERROR("Allocate Buf in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5555 | return OMX_ErrorInvalidState; |
| 5556 | } |
| 5557 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5558 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5559 | if (arbitrary_bytes) { |
| 5560 | eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes); |
| 5561 | } else { |
| 5562 | eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes); |
| 5563 | } |
| 5564 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5565 | eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port, |
| 5566 | appData,bytes); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5567 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5568 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5569 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5570 | } |
| 5571 | DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5572 | if (eRet == OMX_ErrorNone) { |
| 5573 | if (allocate_done()) { |
| 5574 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5575 | // Send the callback now |
| 5576 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 5577 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5578 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5579 | } |
| 5580 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5581 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) { |
| 5582 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 5583 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 5584 | post_event(OMX_CommandPortEnable, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5585 | OMX_CORE_INPUT_PORT_INDEX, |
| 5586 | OMX_COMPONENT_GENERATE_EVENT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5587 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5588 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5589 | if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) { |
| 5590 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 5591 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5592 | post_event(OMX_CommandPortEnable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5593 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5594 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5595 | } |
| 5596 | } |
| 5597 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5598 | DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5599 | return eRet; |
| 5600 | } |
| 5601 | |
| 5602 | // Free Buffer - API call |
| 5603 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5604 | FUNCTION |
| 5605 | omx_vdec::FreeBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5606 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5607 | DESCRIPTION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5608 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5609 | PARAMETERS |
| 5610 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5611 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5612 | RETURN VALUE |
| 5613 | true/false |
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 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5616 | OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5617 | OMX_IN OMX_U32 port, |
| 5618 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5619 | { |
| 5620 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5621 | unsigned int nPortIndex; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5622 | DEBUG_PRINT_LOW("In for decoder free_buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5623 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5624 | if (m_state == OMX_StateIdle && |
| 5625 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5626 | DEBUG_PRINT_LOW(" free buffer while Component in Loading pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5627 | } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)|| |
| 5628 | (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5629 | DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5630 | } else if ((port == OMX_CORE_INPUT_PORT_INDEX && |
| 5631 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) || |
| 5632 | (port == OMX_CORE_OUTPUT_PORT_INDEX && |
| 5633 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5634 | DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5635 | } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5636 | 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] | 5637 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5638 | OMX_ErrorPortUnpopulated, |
| 5639 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5640 | |
| 5641 | return OMX_ErrorIncorrectStateOperation; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5642 | } else if (m_state != OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5643 | DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5644 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5645 | OMX_ErrorPortUnpopulated, |
| 5646 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5649 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5650 | /*Check if arbitrary bytes*/ |
| 5651 | if (!arbitrary_bytes && !input_use_buffer) |
| 5652 | nPortIndex = buffer - m_inp_mem_ptr; |
| 5653 | else |
| 5654 | nPortIndex = buffer - m_inp_heap_ptr; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5655 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5656 | DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %d", nPortIndex); |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 5657 | if (nPortIndex < drv_ctx.ip_buf.actualcount && |
| 5658 | BITMASK_PRESENT(&m_inp_bm_count, nPortIndex)) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5659 | // Clear the bit associated with it. |
| 5660 | BITMASK_CLEAR(&m_inp_bm_count,nPortIndex); |
| 5661 | BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex); |
| 5662 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5663 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5664 | DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5665 | if (m_phdr_pmem_ptr) |
| 5666 | free_input_buffer(m_phdr_pmem_ptr[nPortIndex]); |
| 5667 | } else { |
| 5668 | if (arbitrary_bytes) { |
| 5669 | if (m_phdr_pmem_ptr) |
| 5670 | free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]); |
| 5671 | else |
| 5672 | free_input_buffer(nPortIndex,NULL); |
| 5673 | } else |
| 5674 | free_input_buffer(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5675 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5676 | m_inp_bPopulated = OMX_FALSE; |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5677 | if(release_input_done()) |
| 5678 | release_buffers(this, VDEC_BUFFER_TYPE_INPUT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5679 | /*Free the Buffer Header*/ |
| 5680 | if (release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5681 | DEBUG_PRINT_HIGH("ALL input buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5682 | free_input_buffer_header(); |
| 5683 | } |
| 5684 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5685 | DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5686 | eRet = OMX_ErrorBadPortIndex; |
| 5687 | } |
| 5688 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5689 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING) |
| 5690 | && release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5691 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5692 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 5693 | post_event(OMX_CommandPortDisable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5694 | OMX_CORE_INPUT_PORT_INDEX, |
| 5695 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5696 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5697 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5698 | // check if the buffer is valid |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5699 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 5700 | if (nPortIndex < drv_ctx.op_buf.actualcount && |
| 5701 | BITMASK_PRESENT(&m_out_bm_count, nPortIndex)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5702 | 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] | 5703 | // Clear the bit associated with it. |
| 5704 | BITMASK_CLEAR(&m_out_bm_count,nPortIndex); |
| 5705 | m_out_bPopulated = OMX_FALSE; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5706 | client_buffers.free_output_buffer (buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5707 | |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5708 | if(release_output_done()) { |
| 5709 | release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT); |
| 5710 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5711 | if (release_output_done()) { |
| 5712 | free_output_buffer_header(); |
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 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5715 | DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5716 | eRet = OMX_ErrorBadPortIndex; |
| 5717 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5718 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING) |
| 5719 | && release_output_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5720 | DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5721 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5722 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5723 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5724 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5725 | if (m_enable_android_native_buffers) { |
| 5726 | DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers"); |
| 5727 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 5728 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5729 | #endif |
| 5730 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5731 | post_event(OMX_CommandPortDisable, |
| 5732 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5733 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5734 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5735 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5736 | eRet = OMX_ErrorBadPortIndex; |
| 5737 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5738 | if ((eRet == OMX_ErrorNone) && |
| 5739 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
| 5740 | if (release_done()) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5741 | // Send the callback now |
| 5742 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING); |
| 5743 | post_event(OMX_CommandStateSet, OMX_StateLoaded, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5744 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5745 | } |
| 5746 | } |
| 5747 | return eRet; |
| 5748 | } |
| 5749 | |
| 5750 | |
| 5751 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5752 | FUNCTION |
| 5753 | omx_vdec::EmptyThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5754 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5755 | DESCRIPTION |
| 5756 | This routine is used to push the encoded video frames to |
| 5757 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5758 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5759 | PARAMETERS |
| 5760 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5761 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5762 | RETURN VALUE |
| 5763 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5764 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5765 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5766 | OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5767 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5768 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5769 | OMX_ERRORTYPE ret1 = OMX_ErrorNone; |
| 5770 | unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5771 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5772 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5773 | DEBUG_PRINT_ERROR("Empty this buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5774 | return OMX_ErrorInvalidState; |
| 5775 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5776 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5777 | if (buffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5778 | DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5779 | return OMX_ErrorBadParameter; |
| 5780 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5781 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5782 | if (!m_inp_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5783 | DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5784 | return OMX_ErrorIncorrectStateOperation; |
| 5785 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5786 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5787 | if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5788 | DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5789 | return OMX_ErrorBadPortIndex; |
| 5790 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5791 | |
| 5792 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5793 | if (iDivXDrmDecrypt) { |
| 5794 | OMX_ERRORTYPE drmErr = iDivXDrmDecrypt->Decrypt(buffer); |
| 5795 | if (drmErr != OMX_ErrorNone) { |
| 5796 | // this error can be ignored |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5797 | DEBUG_PRINT_LOW("ERROR:iDivXDrmDecrypt->Decrypt %d", drmErr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5798 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5799 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5800 | #endif //_ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5801 | if (perf_flag) { |
| 5802 | if (!latency) { |
| 5803 | dec_time.stop(); |
| 5804 | latency = dec_time.processing_time_us(); |
| 5805 | dec_time.start(); |
| 5806 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5807 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5808 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5809 | if (arbitrary_bytes) { |
| 5810 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5811 | } else { |
| 5812 | if (input_use_buffer == true) { |
| 5813 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5814 | m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen; |
| 5815 | m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp; |
| 5816 | m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags; |
| 5817 | buffer = &m_inp_mem_ptr[nBufferIndex]; |
| 5818 | DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu", |
| 5819 | &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen); |
| 5820 | } else { |
| 5821 | nBufferIndex = buffer - m_inp_mem_ptr; |
| 5822 | } |
| 5823 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5824 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5825 | if (nBufferIndex > drv_ctx.ip_buf.actualcount ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5826 | DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5827 | return OMX_ErrorBadParameter; |
| 5828 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5829 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 5830 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 5831 | codec_config_flag = true; |
| 5832 | DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__); |
| 5833 | } |
| 5834 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5835 | DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)", |
| 5836 | buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen); |
| 5837 | if (arbitrary_bytes) { |
| 5838 | post_event ((unsigned)hComp,(unsigned)buffer, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5839 | OMX_COMPONENT_GENERATE_ETB_ARBITRARY); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5840 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5841 | post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB); |
| 5842 | } |
Praveen Chavan | ece713f | 2014-12-10 18:00:04 -0800 | [diff] [blame] | 5843 | time_stamp_dts.insert_timestamp(buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5844 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5848 | FUNCTION |
| 5849 | omx_vdec::empty_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5850 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5851 | DESCRIPTION |
| 5852 | This routine is used to push the encoded video frames to |
| 5853 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5854 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5855 | PARAMETERS |
| 5856 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5857 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5858 | RETURN VALUE |
| 5859 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5860 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5861 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5862 | 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] | 5863 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5864 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5865 | int push_cnt = 0,i=0; |
| 5866 | unsigned nPortIndex = 0; |
| 5867 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 5868 | struct vdec_input_frameinfo frameinfo; |
| 5869 | struct vdec_bufferpayload *temp_buffer; |
| 5870 | struct vdec_seqheader seq_header; |
| 5871 | bool port_setting_changed = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5872 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5873 | /*Should we generate a Aync error event*/ |
| 5874 | if (buffer == NULL || buffer->pInputPortPrivate == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5875 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5876 | return OMX_ErrorBadParameter; |
| 5877 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5878 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5879 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5880 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5881 | if (nPortIndex > drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5882 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5883 | nPortIndex); |
| 5884 | return OMX_ErrorBadParameter; |
| 5885 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5886 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5887 | pending_input_buffers++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5888 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5889 | /* return zero length and not an EOS buffer */ |
| 5890 | if (!arbitrary_bytes && (buffer->nFilledLen == 0) && |
| 5891 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5892 | DEBUG_PRINT_HIGH("return zero legth buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5893 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5894 | OMX_COMPONENT_GENERATE_EBD); |
| 5895 | return OMX_ErrorNone; |
| 5896 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5897 | |
c_sridur | 0af9cef | 2015-02-05 12:07:17 +0530 | [diff] [blame] | 5898 | if (input_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5899 | DEBUG_PRINT_LOW("Flush in progress return buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5900 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5901 | OMX_COMPONENT_GENERATE_EBD); |
| 5902 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5903 | } |
| 5904 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5905 | temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5906 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 5907 | 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] | 5908 | return OMX_ErrorBadParameter; |
| 5909 | } |
| 5910 | /* If its first frame, H264 codec and reject is true, then parse the nal |
| 5911 | and get the profile. Based on this, reject the clip playback */ |
| 5912 | if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 && |
| 5913 | m_reject_avc_1080p_mp) { |
| 5914 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5915 | DEBUG_PRINT_ERROR("Parse nal to get the profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5916 | h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen, |
| 5917 | NALU_TYPE_SPS); |
| 5918 | m_profile = h264_parser->get_profile(); |
| 5919 | ret = is_video_session_supported(); |
| 5920 | if (ret) { |
| 5921 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD); |
| 5922 | post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT); |
| 5923 | /* Move the state to Invalid to avoid queueing of pending ETB to the driver */ |
| 5924 | m_state = OMX_StateInvalid; |
| 5925 | return OMX_ErrorNone; |
| 5926 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5927 | } |
| 5928 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5929 | DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5930 | /*for use buffer we need to memcpy the data*/ |
| 5931 | temp_buffer->buffer_len = buffer->nFilledLen; |
| 5932 | |
| 5933 | if (input_use_buffer) { |
| 5934 | if (buffer->nFilledLen <= temp_buffer->buffer_len) { |
| 5935 | if (arbitrary_bytes) { |
| 5936 | memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen); |
| 5937 | } else { |
| 5938 | memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset), |
| 5939 | buffer->nFilledLen); |
| 5940 | } |
| 5941 | } else { |
| 5942 | return OMX_ErrorBadParameter; |
| 5943 | } |
| 5944 | |
| 5945 | } |
| 5946 | |
| 5947 | frameinfo.bufferaddr = temp_buffer->bufferaddr; |
| 5948 | frameinfo.client_data = (void *) buffer; |
| 5949 | frameinfo.datalen = temp_buffer->buffer_len; |
| 5950 | frameinfo.flags = 0; |
| 5951 | frameinfo.offset = buffer->nOffset; |
| 5952 | frameinfo.pmem_fd = temp_buffer->pmem_fd; |
| 5953 | frameinfo.pmem_offset = temp_buffer->offset; |
| 5954 | frameinfo.timestamp = buffer->nTimeStamp; |
| 5955 | if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) { |
| 5956 | DEBUG_PRINT_LOW("ETB: dmx enabled"); |
| 5957 | if (m_demux_entries == 0) { |
| 5958 | extract_demux_addr_offsets(buffer); |
| 5959 | } |
| 5960 | |
| 5961 | DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries); |
| 5962 | handle_demux_data(buffer); |
| 5963 | frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr; |
| 5964 | frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size; |
| 5965 | } else { |
| 5966 | frameinfo.desc_addr = NULL; |
| 5967 | frameinfo.desc_size = 0; |
| 5968 | } |
| 5969 | if (!arbitrary_bytes) { |
| 5970 | frameinfo.flags |= buffer->nFlags; |
| 5971 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5972 | |
| 5973 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5974 | if (m_debug_timestamp) { |
| 5975 | if (arbitrary_bytes) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5976 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5977 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5978 | } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5979 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5980 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5981 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5982 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5983 | #endif |
| 5984 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5985 | log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5986 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5987 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5988 | frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5989 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5990 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5991 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5992 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5993 | 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] | 5994 | frameinfo.flags |= VDEC_BUFFERFLAG_EOS; |
| 5995 | h264_scratch.nFilledLen = 0; |
| 5996 | nal_count = 0; |
| 5997 | look_ahead_nal = false; |
| 5998 | frame_count = 0; |
| 5999 | if (m_frame_parser.mutils) |
| 6000 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 6001 | m_frame_parser.flush(); |
| 6002 | h264_last_au_ts = LLONG_MAX; |
| 6003 | h264_last_au_flags = 0; |
| 6004 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 6005 | m_demux_entries = 0; |
| 6006 | } |
| 6007 | struct v4l2_buffer buf; |
| 6008 | struct v4l2_plane plane; |
| 6009 | memset( (void *)&buf, 0, sizeof(buf)); |
| 6010 | memset( (void *)&plane, 0, sizeof(plane)); |
| 6011 | int rc; |
| 6012 | unsigned long print_count; |
| 6013 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 6014 | buf.flags = V4L2_QCOM_BUF_FLAG_EOS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6015 | DEBUG_PRINT_HIGH("INPUT EOS reached") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6016 | } |
| 6017 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 6018 | buf.index = nPortIndex; |
| 6019 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 6020 | buf.memory = V4L2_MEMORY_USERPTR; |
| 6021 | plane.bytesused = temp_buffer->buffer_len; |
| 6022 | plane.length = drv_ctx.ip_buf.buffer_size; |
| 6023 | plane.m.userptr = (unsigned long)temp_buffer->bufferaddr - |
| 6024 | (unsigned long)temp_buffer->offset; |
| 6025 | plane.reserved[0] = temp_buffer->pmem_fd; |
| 6026 | plane.reserved[1] = temp_buffer->offset; |
| 6027 | plane.data_offset = 0; |
| 6028 | buf.m.planes = &plane; |
| 6029 | buf.length = 1; |
| 6030 | if (frameinfo.timestamp >= LLONG_MAX) { |
| 6031 | buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID; |
| 6032 | } |
| 6033 | //assumption is that timestamp is in milliseconds |
| 6034 | buf.timestamp.tv_sec = frameinfo.timestamp / 1000000; |
| 6035 | buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000); |
| 6036 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0; |
| 6037 | 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] | 6038 | |
Pushkaraj Patil | 20bd6bf | 2014-12-22 19:33:08 +0530 | [diff] [blame] | 6039 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 6040 | DEBUG_PRINT_LOW("Increment codec_config buffer counter"); |
| 6041 | android_atomic_inc(&m_queued_codec_config_count); |
| 6042 | } |
| 6043 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6044 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 6045 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6046 | DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6047 | return OMX_ErrorHardware; |
| 6048 | } |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 6049 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 6050 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 6051 | codec_config_flag = false; |
| 6052 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6053 | if (!streaming[OUTPUT_PORT]) { |
| 6054 | enum v4l2_buf_type buf_type; |
| 6055 | int ret,r; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 6056 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6057 | buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6058 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6059 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 6060 | if (!ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6061 | DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6062 | streaming[OUTPUT_PORT] = true; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 6063 | } else if (errno == EBUSY) { |
| 6064 | DEBUG_PRINT_ERROR("Failed to call stream on OUTPUT due to HW_OVERLOAD"); |
| 6065 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
| 6066 | OMX_COMPONENT_GENERATE_EBD); |
| 6067 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6068 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6069 | DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6070 | DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued"); |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 6071 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6072 | OMX_COMPONENT_GENERATE_EBD); |
| 6073 | return OMX_ErrorBadParameter; |
| 6074 | } |
| 6075 | } |
| 6076 | DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)", |
| 6077 | frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6078 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6079 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6083 | FUNCTION |
| 6084 | omx_vdec::FillThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6085 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6086 | DESCRIPTION |
| 6087 | IL client uses this method to release the frame buffer |
| 6088 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6089 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6090 | PARAMETERS |
| 6091 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6092 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6093 | RETURN VALUE |
| 6094 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6095 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6096 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6097 | OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6098 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6099 | { |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6100 | unsigned nPortIndex = 0; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6101 | if (dynamic_buf_mode) { |
| 6102 | private_handle_t *handle = NULL; |
| 6103 | struct VideoDecoderOutputMetaData *meta; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6104 | unsigned int nPortIndex = 0; |
| 6105 | |
| 6106 | if (!buffer || !buffer->pBuffer) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6107 | DEBUG_PRINT_ERROR("%s: invalid params: %p", __FUNCTION__, buffer); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6108 | return OMX_ErrorBadParameter; |
| 6109 | } |
| 6110 | |
| 6111 | //get the buffer type and fd info |
| 6112 | meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer; |
| 6113 | handle = (private_handle_t *)meta->pHandle; |
Arun Menon | b49abf2 | 2013-12-14 21:38:10 -0800 | [diff] [blame] | 6114 | DEBUG_PRINT_LOW("FTB: metabuf: %p buftype: %d bufhndl: %p ", meta, meta->eType, meta->pHandle); |
| 6115 | |
| 6116 | if (!handle) { |
| 6117 | DEBUG_PRINT_ERROR("FTB: Error: IL client passed an invalid buf handle - %p", handle); |
| 6118 | return OMX_ErrorBadParameter; |
| 6119 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6120 | //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF |
| 6121 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6122 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd; |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6123 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = (OMX_U8*) buffer; |
ApurupaPattapu | f693a4d | 2013-12-04 16:07:07 -0800 | [diff] [blame] | 6124 | |
| 6125 | //Store private handle from GraphicBuffer |
| 6126 | native_buffer[nPortIndex].privatehandle = handle; |
| 6127 | native_buffer[nPortIndex].nativehandle = handle; |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6128 | |
| 6129 | //buffer->nAllocLen will be sizeof(struct VideoDecoderOutputMetaData). Overwrite |
| 6130 | //this with a more sane size so that we don't compensate in rest of code |
| 6131 | //We'll restore this size later on, so that it's transparent to client |
| 6132 | buffer->nFilledLen = 0; |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 6133 | buffer->nAllocLen = handle->size; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6134 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6135 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6136 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6137 | DEBUG_PRINT_ERROR("FTB in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6138 | return OMX_ErrorInvalidState; |
| 6139 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6140 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6141 | if (!m_out_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6142 | DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6143 | return OMX_ErrorIncorrectStateOperation; |
| 6144 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6145 | |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6146 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6147 | if (buffer == NULL || |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6148 | (nPortIndex >= drv_ctx.op_buf.actualcount)) { |
| 6149 | DEBUG_PRINT_ERROR("FTB: ERROR: invalid buffer index, nPortIndex %u bufCount %u", |
| 6150 | nPortIndex, drv_ctx.op_buf.actualcount); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6151 | return OMX_ErrorBadParameter; |
| 6152 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6153 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6154 | if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6155 | DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6156 | return OMX_ErrorBadPortIndex; |
| 6157 | } |
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 | DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 6160 | post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg); |
| 6161 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6162 | } |
| 6163 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6164 | FUNCTION |
| 6165 | omx_vdec::fill_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6166 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6167 | DESCRIPTION |
| 6168 | IL client uses this method to release the frame buffer |
| 6169 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6170 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6171 | PARAMETERS |
| 6172 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6173 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6174 | RETURN VALUE |
| 6175 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6176 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6177 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6178 | OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6179 | OMX_IN OMX_HANDLETYPE hComp, |
| 6180 | OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6181 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6182 | OMX_ERRORTYPE nRet = OMX_ErrorNone; |
| 6183 | OMX_BUFFERHEADERTYPE *buffer = bufferAdd; |
| 6184 | unsigned nPortIndex = 0; |
| 6185 | struct vdec_fillbuffer_cmd fillbuffer; |
| 6186 | struct vdec_bufferpayload *ptr_outputbuffer = NULL; |
| 6187 | struct vdec_output_frameinfo *ptr_respbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6188 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6189 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6190 | |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6191 | if (bufferAdd == NULL || nPortIndex > drv_ctx.op_buf.actualcount) { |
| 6192 | DEBUG_PRINT_ERROR("FTBProxy: ERROR: invalid buffer index, nPortIndex %u bufCount %u", |
| 6193 | nPortIndex, drv_ctx.op_buf.actualcount); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6194 | return OMX_ErrorBadParameter; |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6195 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6196 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6197 | DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6198 | bufferAdd, bufferAdd->pBuffer); |
| 6199 | /*Return back the output buffer to client*/ |
| 6200 | if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6201 | DEBUG_PRINT_LOW("Output Buffers return flush/disable condition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6202 | buffer->nFilledLen = 0; |
| 6203 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6204 | return OMX_ErrorNone; |
| 6205 | } |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6206 | |
| 6207 | if (dynamic_buf_mode) { |
| 6208 | //map the buffer handle based on the size set on output port definition. |
| 6209 | if (!secure_mode) { |
| 6210 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = |
| 6211 | (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size, |
| 6212 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 6213 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, 0); |
| 6214 | } |
| 6215 | drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0; |
| 6216 | drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size; |
| 6217 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 6218 | buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, |
| 6219 | drv_ctx.ptr_outputbuffer[nPortIndex].offset); |
| 6220 | } |
| 6221 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6222 | pending_output_buffers++; |
| 6223 | buffer = client_buffers.get_dr_buf_hdr(bufferAdd); |
| 6224 | ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate; |
| 6225 | if (ptr_respbuffer) { |
| 6226 | ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data; |
| 6227 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6228 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6229 | if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) { |
| 6230 | DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL"); |
| 6231 | buffer->nFilledLen = 0; |
| 6232 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6233 | pending_output_buffers--; |
| 6234 | return OMX_ErrorBadParameter; |
| 6235 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6236 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6237 | int rc = 0; |
| 6238 | struct v4l2_buffer buf; |
| 6239 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 6240 | memset( (void *)&buf, 0, sizeof(buf)); |
| 6241 | memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES)); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6242 | unsigned int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6243 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6244 | buf.index = nPortIndex; |
| 6245 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 6246 | buf.memory = V4L2_MEMORY_USERPTR; |
| 6247 | plane[0].bytesused = buffer->nFilledLen; |
| 6248 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 6249 | plane[0].m.userptr = |
| 6250 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr - |
| 6251 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6252 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd; |
| 6253 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6254 | plane[0].data_offset = 0; |
| 6255 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 6256 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 6257 | plane[extra_idx].bytesused = 0; |
| 6258 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 6259 | 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] | 6260 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6261 | 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] | 6262 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6263 | plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size; |
| 6264 | plane[extra_idx].data_offset = 0; |
| 6265 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6266 | DEBUG_PRINT_ERROR("Extradata index higher than expected: %u", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6267 | return OMX_ErrorBadParameter; |
| 6268 | } |
| 6269 | buf.m.planes = plane; |
| 6270 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6271 | 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] | 6272 | plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]); |
| 6273 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6274 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 6275 | if (rc) { |
| 6276 | /*TODO: How to handle this case */ |
| 6277 | DEBUG_PRINT_ERROR("Failed to qbuf to driver"); |
| 6278 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6279 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6283 | FUNCTION |
| 6284 | omx_vdec::SetCallbacks |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6285 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6286 | DESCRIPTION |
| 6287 | Set the callbacks. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6288 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6289 | PARAMETERS |
| 6290 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6291 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6292 | RETURN VALUE |
| 6293 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6294 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6295 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6296 | OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6297 | OMX_IN OMX_CALLBACKTYPE* callbacks, |
| 6298 | OMX_IN OMX_PTR appData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6299 | { |
| 6300 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6301 | m_cb = *callbacks; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6302 | DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6303 | m_cb.EventHandler,m_cb.FillBufferDone); |
| 6304 | m_app_data = appData; |
| 6305 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6309 | FUNCTION |
| 6310 | omx_vdec::ComponentDeInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6311 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6312 | DESCRIPTION |
| 6313 | Destroys the component and release memory allocated to the heap. |
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 | PARAMETERS |
| 6316 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6317 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6318 | RETURN VALUE |
| 6319 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6320 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6321 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6322 | OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp) |
| 6323 | { |
| 6324 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6325 | if (iDivXDrmDecrypt) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6326 | delete iDivXDrmDecrypt; |
| 6327 | iDivXDrmDecrypt=NULL; |
| 6328 | } |
| 6329 | #endif //_ANDROID_ |
| 6330 | |
Shalaj Jain | 286b006 | 2013-02-21 20:35:48 -0800 | [diff] [blame] | 6331 | unsigned i = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6332 | if (OMX_StateLoaded != m_state) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6333 | DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6334 | m_state); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6335 | DEBUG_PRINT_ERROR("Playback Ended - FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6336 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6337 | DEBUG_PRINT_HIGH("Playback Ended - PASSED"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6338 | } |
| 6339 | |
| 6340 | /*Check if the output buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6341 | if (m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6342 | DEBUG_PRINT_LOW("Freeing the Output Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6343 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) { |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 6344 | if (BITMASK_PRESENT(&m_out_bm_count, i)) { |
| 6345 | BITMASK_CLEAR(&m_out_bm_count, i); |
| 6346 | client_buffers.free_output_buffer (&m_out_mem_ptr[i]); |
| 6347 | } |
| 6348 | |
| 6349 | if (release_output_done()) { |
| 6350 | break; |
| 6351 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6352 | } |
| 6353 | #ifdef _ANDROID_ICS_ |
| 6354 | memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 6355 | #endif |
| 6356 | } |
| 6357 | |
| 6358 | /*Check if the input buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6359 | if (m_inp_mem_ptr || m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6360 | DEBUG_PRINT_LOW("Freeing the Input Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6361 | for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) { |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 6362 | |
| 6363 | if (BITMASK_PRESENT(&m_inp_bm_count, i)) { |
| 6364 | BITMASK_CLEAR(&m_inp_bm_count, i); |
| 6365 | if (m_inp_mem_ptr) |
| 6366 | free_input_buffer (i,&m_inp_mem_ptr[i]); |
| 6367 | else |
| 6368 | free_input_buffer (i,NULL); |
| 6369 | } |
| 6370 | |
| 6371 | if (release_input_done()) { |
| 6372 | break; |
| 6373 | } |
| 6374 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6375 | } |
| 6376 | free_input_buffer_header(); |
| 6377 | free_output_buffer_header(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6378 | if (h264_scratch.pBuffer) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6379 | free(h264_scratch.pBuffer); |
| 6380 | h264_scratch.pBuffer = NULL; |
| 6381 | } |
| 6382 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6383 | if (h264_parser) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6384 | delete h264_parser; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6385 | h264_parser = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6386 | } |
| 6387 | |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6388 | if (m_frame_parser.mutils) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6389 | DEBUG_PRINT_LOW("Free utils parser"); |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6390 | delete (m_frame_parser.mutils); |
| 6391 | m_frame_parser.mutils = NULL; |
| 6392 | } |
| 6393 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6394 | if (m_platform_list) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6395 | free(m_platform_list); |
| 6396 | m_platform_list = NULL; |
| 6397 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6398 | if (m_vendor_config.pData) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6399 | free(m_vendor_config.pData); |
| 6400 | m_vendor_config.pData = NULL; |
| 6401 | } |
| 6402 | |
| 6403 | // Reset counters in mesg queues |
| 6404 | m_ftb_q.m_size=0; |
| 6405 | m_cmd_q.m_size=0; |
| 6406 | m_etb_q.m_size=0; |
| 6407 | m_ftb_q.m_read = m_ftb_q.m_write =0; |
| 6408 | m_cmd_q.m_read = m_cmd_q.m_write =0; |
| 6409 | m_etb_q.m_read = m_etb_q.m_write =0; |
| 6410 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6411 | if (m_debug_timestamp) { |
| 6412 | m_timestamp_list.reset_ts_list(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6413 | } |
| 6414 | #endif |
| 6415 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6416 | DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6417 | //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6418 | // NULL); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6419 | DEBUG_PRINT_HIGH("Close the driver instance"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6420 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 6421 | if (m_debug.infile) { |
| 6422 | fclose(m_debug.infile); |
| 6423 | m_debug.infile = NULL; |
| 6424 | } |
| 6425 | if (m_debug.outfile) { |
| 6426 | fclose(m_debug.outfile); |
| 6427 | m_debug.outfile = NULL; |
| 6428 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6429 | #ifdef OUTPUT_EXTRADATA_LOG |
Shalaj Jain | af08f30 | 2013-03-18 13:15:35 -0700 | [diff] [blame] | 6430 | if (outputExtradataFile) |
| 6431 | fclose (outputExtradataFile); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6432 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6433 | DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6434 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6438 | FUNCTION |
| 6439 | omx_vdec::UseEGLImage |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6440 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6441 | DESCRIPTION |
| 6442 | OMX Use EGL Image method implementation <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6443 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6444 | PARAMETERS |
| 6445 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6446 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6447 | RETURN VALUE |
| 6448 | Not Implemented error. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6449 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6450 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6451 | OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6452 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 6453 | OMX_IN OMX_U32 port, |
| 6454 | OMX_IN OMX_PTR appData, |
| 6455 | OMX_IN void* eglImage) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6456 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6457 | OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list; |
| 6458 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry; |
| 6459 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6460 | |
| 6461 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6462 | PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc; |
| 6463 | EGLint fd = -1, offset = 0,pmemPtr = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6464 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6465 | int fd = -1, offset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6466 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6467 | DEBUG_PRINT_HIGH("use EGL image support for decoder"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6468 | if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6469 | DEBUG_PRINT_ERROR(""); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6470 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6471 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6472 | if (m_display_id == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6473 | DEBUG_PRINT_ERROR("Display ID is not set by IL client"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6474 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6475 | } |
| 6476 | egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC) |
| 6477 | eglGetProcAddress("eglQueryImageKHR"); |
| 6478 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd); |
| 6479 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset); |
| 6480 | egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6481 | #else //with OMX test app |
| 6482 | struct temp_egl { |
| 6483 | int pmem_fd; |
| 6484 | int offset; |
| 6485 | }; |
| 6486 | struct temp_egl *temp_egl_id = NULL; |
| 6487 | void * pmemPtr = (void *) eglImage; |
| 6488 | temp_egl_id = (struct temp_egl *)eglImage; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6489 | if (temp_egl_id != NULL) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6490 | fd = temp_egl_id->pmem_fd; |
| 6491 | offset = temp_egl_id->offset; |
| 6492 | } |
| 6493 | #endif |
| 6494 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6495 | DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6496 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6497 | } |
| 6498 | pmem_info.pmem_fd = (OMX_U32) fd; |
| 6499 | pmem_info.offset = (OMX_U32) offset; |
| 6500 | pmem_entry.entry = (void *) &pmem_info; |
| 6501 | pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 6502 | pmem_list.entryList = &pmem_entry; |
| 6503 | pmem_list.nEntries = 1; |
| 6504 | ouput_egl_buffers = true; |
| 6505 | if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port, |
| 6506 | (void *)&pmem_list, drv_ctx.op_buf.buffer_size, |
| 6507 | (OMX_U8 *)pmemPtr)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6508 | DEBUG_PRINT_ERROR("use buffer call failed for egl image"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6509 | return OMX_ErrorInsufficientResources; |
| 6510 | } |
| 6511 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6512 | } |
| 6513 | |
| 6514 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6515 | FUNCTION |
| 6516 | omx_vdec::ComponentRoleEnum |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6517 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6518 | DESCRIPTION |
| 6519 | OMX Component Role Enum method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6520 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6521 | PARAMETERS |
| 6522 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6523 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6524 | RETURN VALUE |
| 6525 | OMX Error None if everything is successful. |
| 6526 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6527 | OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6528 | OMX_OUT OMX_U8* role, |
| 6529 | OMX_IN OMX_U32 index) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6530 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6531 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6532 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6533 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 6534 | if ((0 == index) && role) { |
| 6535 | strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6536 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6537 | } else { |
| 6538 | eRet = OMX_ErrorNoMore; |
| 6539 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6540 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6541 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 6542 | if ((0 == index) && role) { |
| 6543 | strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6544 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6545 | } else { |
| 6546 | eRet = OMX_ErrorNoMore; |
| 6547 | } |
| 6548 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 6549 | if ((0 == index) && role) { |
| 6550 | strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6551 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6552 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6553 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6554 | eRet = OMX_ErrorNoMore; |
| 6555 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6556 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6557 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6558 | else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) || |
| 6559 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE)) |
| 6560 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6561 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6562 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6563 | if ((0 == index) && role) { |
| 6564 | strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6565 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6566 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6567 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6568 | eRet = OMX_ErrorNoMore; |
| 6569 | } |
| 6570 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 6571 | if ((0 == index) && role) { |
| 6572 | strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6573 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6574 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6575 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6576 | eRet = OMX_ErrorNoMore; |
| 6577 | } |
| 6578 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 6579 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 6580 | ) { |
| 6581 | if ((0 == index) && role) { |
| 6582 | strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6583 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6584 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6585 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6586 | eRet = OMX_ErrorNoMore; |
| 6587 | } |
| 6588 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 6589 | if ((0 == index) && role) { |
| 6590 | strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6591 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6592 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6593 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6594 | eRet = OMX_ErrorNoMore; |
| 6595 | } |
| 6596 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6597 | DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6598 | eRet = OMX_ErrorInvalidComponentName; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6599 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6600 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6601 | } |
| 6602 | |
| 6603 | |
| 6604 | |
| 6605 | |
| 6606 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6607 | FUNCTION |
| 6608 | omx_vdec::AllocateDone |
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 | DESCRIPTION |
| 6611 | Checks if entire buffer pool is allocated by IL Client or not. |
| 6612 | Need this to move to IDLE state. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6613 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6614 | PARAMETERS |
| 6615 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6616 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6617 | RETURN VALUE |
| 6618 | true/false. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6619 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6620 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6621 | bool omx_vdec::allocate_done(void) |
| 6622 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6623 | bool bRet = false; |
| 6624 | bool bRet_In = false; |
| 6625 | bool bRet_Out = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6626 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6627 | bRet_In = allocate_input_done(); |
| 6628 | bRet_Out = allocate_output_done(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6629 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6630 | if (bRet_In && bRet_Out) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6631 | bRet = true; |
| 6632 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6633 | |
| 6634 | return bRet; |
| 6635 | } |
| 6636 | /* ====================================================================== |
| 6637 | FUNCTION |
| 6638 | omx_vdec::AllocateInputDone |
| 6639 | |
| 6640 | DESCRIPTION |
| 6641 | Checks if I/P buffer pool is allocated by IL Client or not. |
| 6642 | |
| 6643 | PARAMETERS |
| 6644 | None. |
| 6645 | |
| 6646 | RETURN VALUE |
| 6647 | true/false. |
| 6648 | |
| 6649 | ========================================================================== */ |
| 6650 | bool omx_vdec::allocate_input_done(void) |
| 6651 | { |
| 6652 | bool bRet = false; |
| 6653 | unsigned i=0; |
| 6654 | |
| 6655 | if (m_inp_mem_ptr == NULL) { |
| 6656 | return bRet; |
| 6657 | } |
| 6658 | if (m_inp_mem_ptr ) { |
| 6659 | for (; i<drv_ctx.ip_buf.actualcount; i++) { |
| 6660 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
| 6661 | break; |
| 6662 | } |
| 6663 | } |
| 6664 | } |
| 6665 | if (i == drv_ctx.ip_buf.actualcount) { |
| 6666 | bRet = true; |
| 6667 | DEBUG_PRINT_HIGH("Allocate done for all i/p buffers"); |
| 6668 | } |
| 6669 | if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) { |
| 6670 | m_inp_bPopulated = OMX_TRUE; |
| 6671 | } |
| 6672 | return bRet; |
| 6673 | } |
| 6674 | /* ====================================================================== |
| 6675 | FUNCTION |
| 6676 | omx_vdec::AllocateOutputDone |
| 6677 | |
| 6678 | DESCRIPTION |
| 6679 | Checks if entire O/P buffer pool is allocated by IL Client or not. |
| 6680 | |
| 6681 | PARAMETERS |
| 6682 | None. |
| 6683 | |
| 6684 | RETURN VALUE |
| 6685 | true/false. |
| 6686 | |
| 6687 | ========================================================================== */ |
| 6688 | bool omx_vdec::allocate_output_done(void) |
| 6689 | { |
| 6690 | bool bRet = false; |
| 6691 | unsigned j=0; |
| 6692 | |
| 6693 | if (m_out_mem_ptr == NULL) { |
| 6694 | return bRet; |
| 6695 | } |
| 6696 | |
| 6697 | if (m_out_mem_ptr) { |
| 6698 | for (; j < drv_ctx.op_buf.actualcount; j++) { |
| 6699 | if (BITMASK_ABSENT(&m_out_bm_count,j)) { |
| 6700 | break; |
| 6701 | } |
| 6702 | } |
| 6703 | } |
| 6704 | |
| 6705 | if (j == drv_ctx.op_buf.actualcount) { |
| 6706 | bRet = true; |
| 6707 | DEBUG_PRINT_HIGH("Allocate done for all o/p buffers"); |
| 6708 | if (m_out_bEnabled) |
| 6709 | m_out_bPopulated = OMX_TRUE; |
| 6710 | } |
| 6711 | |
| 6712 | return bRet; |
| 6713 | } |
| 6714 | |
| 6715 | /* ====================================================================== |
| 6716 | FUNCTION |
| 6717 | omx_vdec::ReleaseDone |
| 6718 | |
| 6719 | DESCRIPTION |
| 6720 | Checks if IL client has released all the buffers. |
| 6721 | |
| 6722 | PARAMETERS |
| 6723 | None. |
| 6724 | |
| 6725 | RETURN VALUE |
| 6726 | true/false |
| 6727 | |
| 6728 | ========================================================================== */ |
| 6729 | bool omx_vdec::release_done(void) |
| 6730 | { |
| 6731 | bool bRet = false; |
| 6732 | |
| 6733 | if (release_input_done()) { |
| 6734 | if (release_output_done()) { |
| 6735 | bRet = true; |
| 6736 | } |
| 6737 | } |
| 6738 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6739 | } |
| 6740 | |
| 6741 | |
| 6742 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6743 | FUNCTION |
| 6744 | omx_vdec::ReleaseOutputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6745 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6746 | DESCRIPTION |
| 6747 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6748 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6749 | PARAMETERS |
| 6750 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6751 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6752 | RETURN VALUE |
| 6753 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6754 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6755 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6756 | bool omx_vdec::release_output_done(void) |
| 6757 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6758 | bool bRet = false; |
| 6759 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6760 | |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 6761 | DEBUG_PRINT_LOW("Value of m_out_mem_ptr %p",m_out_mem_ptr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6762 | if (m_out_mem_ptr) { |
| 6763 | for (; j < drv_ctx.op_buf.actualcount ; j++) { |
| 6764 | if (BITMASK_PRESENT(&m_out_bm_count,j)) { |
| 6765 | break; |
| 6766 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6767 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6768 | if (j == drv_ctx.op_buf.actualcount) { |
| 6769 | m_out_bm_count = 0; |
| 6770 | bRet = true; |
| 6771 | } |
| 6772 | } else { |
| 6773 | m_out_bm_count = 0; |
| 6774 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6775 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6776 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6777 | } |
| 6778 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6779 | FUNCTION |
| 6780 | omx_vdec::ReleaseInputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6781 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6782 | DESCRIPTION |
| 6783 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6784 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6785 | PARAMETERS |
| 6786 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6787 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6788 | RETURN VALUE |
| 6789 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6790 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6791 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6792 | bool omx_vdec::release_input_done(void) |
| 6793 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6794 | bool bRet = false; |
| 6795 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6796 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6797 | 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] | 6798 | if (m_inp_mem_ptr) { |
| 6799 | for (; j<drv_ctx.ip_buf.actualcount; j++) { |
| 6800 | if ( BITMASK_PRESENT(&m_inp_bm_count,j)) { |
| 6801 | break; |
| 6802 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6803 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6804 | if (j==drv_ctx.ip_buf.actualcount) { |
| 6805 | bRet = true; |
| 6806 | } |
| 6807 | } else { |
| 6808 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6809 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6810 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6814 | OMX_BUFFERHEADERTYPE * buffer) |
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_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6817 | 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] | 6818 | DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6819 | return OMX_ErrorBadParameter; |
| 6820 | } else if (output_flush_progress) { |
| 6821 | DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer); |
| 6822 | buffer->nFilledLen = 0; |
| 6823 | buffer->nTimeStamp = 0; |
| 6824 | buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA; |
| 6825 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 6826 | buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT; |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6827 | } |
| 6828 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6829 | if (m_debug_extradata) { |
| 6830 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6831 | DEBUG_PRINT_HIGH(""); |
| 6832 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6833 | DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received"); |
| 6834 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6838 | DEBUG_PRINT_HIGH(""); |
| 6839 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6840 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 6841 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6842 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6843 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6844 | |
| 6845 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6846 | DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6847 | buffer, buffer->pBuffer); |
| 6848 | pending_output_buffers --; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6849 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6850 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6851 | DEBUG_PRINT_HIGH("Output EOS has been reached"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6852 | if (!output_flush_progress) |
| 6853 | post_event((unsigned)NULL, (unsigned)NULL, |
| 6854 | OMX_COMPONENT_GENERATE_EOS_DONE); |
| 6855 | |
| 6856 | if (psource_frame) { |
| 6857 | m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame); |
| 6858 | psource_frame = NULL; |
| 6859 | } |
| 6860 | if (pdest_frame) { |
| 6861 | pdest_frame->nFilledLen = 0; |
| 6862 | m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL, |
| 6863 | (unsigned)NULL); |
| 6864 | pdest_frame = NULL; |
| 6865 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6866 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6867 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6868 | |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 6869 | if (!output_flush_progress && (buffer->nFilledLen > 0)) { |
| 6870 | DEBUG_PRINT_LOW("Processing extradata"); |
| 6871 | handle_extradata(buffer); |
| 6872 | } |
| 6873 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6874 | /* For use buffer we need to copy the data */ |
| 6875 | if (!output_flush_progress) { |
| 6876 | /* This is the error check for non-recoverable errros */ |
| 6877 | bool is_duplicate_ts_valid = true; |
| 6878 | bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6879 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6880 | if (output_capability == V4L2_PIX_FMT_MPEG4 || |
| 6881 | output_capability == V4L2_PIX_FMT_MPEG2 || |
| 6882 | output_capability == V4L2_PIX_FMT_DIVX || |
| 6883 | output_capability == V4L2_PIX_FMT_DIVX_311) |
| 6884 | is_duplicate_ts_valid = false; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6885 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6886 | if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 6887 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6888 | is_interlaced = false; |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6889 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6890 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6891 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6892 | if (buffer->nFilledLen > 0) { |
| 6893 | time_stamp_dts.get_next_timestamp(buffer, |
| 6894 | is_interlaced && is_duplicate_ts_valid); |
| 6895 | if (m_debug_timestamp) { |
| 6896 | { |
| 6897 | OMX_TICKS expected_ts = 0; |
| 6898 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6899 | if (is_interlaced && is_duplicate_ts_valid) { |
| 6900 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6901 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6902 | DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6903 | buffer->nTimeStamp, expected_ts); |
| 6904 | |
| 6905 | if (buffer->nTimeStamp != expected_ts) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6906 | DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6907 | } |
| 6908 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6909 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6910 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6911 | time_stamp_dts.remove_time_stamp( |
| 6912 | buffer->nTimeStamp, |
| 6913 | is_interlaced && is_duplicate_ts_valid); |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6914 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6915 | |
| 6916 | |
Praneeth Paladugu | 8f12e82 | 2013-03-11 18:47:58 -0700 | [diff] [blame] | 6917 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6918 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6919 | /* Since we're passing around handles, adjust nFilledLen and nAllocLen |
| 6920 | * to size of the handle. Do it _after_ handle_extradata() which |
| 6921 | * requires the respective sizes to be accurate. */ |
| 6922 | if (dynamic_buf_mode) { |
| 6923 | buffer->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 6924 | buffer->nFilledLen = buffer->nFilledLen ? |
| 6925 | sizeof(struct VideoDecoderOutputMetaData) : 0; |
| 6926 | } |
| 6927 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6928 | if (m_cb.FillBufferDone) { |
| 6929 | if (buffer->nFilledLen > 0) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6930 | if (arbitrary_bytes) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6931 | adjust_timestamp(buffer->nTimeStamp); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6932 | else |
| 6933 | set_frame_rate(buffer->nTimeStamp); |
| 6934 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6935 | if (perf_flag) { |
| 6936 | if (!proc_frms) { |
| 6937 | dec_time.stop(); |
| 6938 | latency = dec_time.processing_time_us() - latency; |
| 6939 | DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3); |
| 6940 | dec_time.start(); |
| 6941 | fps_metrics.start(); |
| 6942 | } |
| 6943 | proc_frms++; |
| 6944 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6945 | OMX_U64 proc_time = 0; |
| 6946 | fps_metrics.stop(); |
| 6947 | proc_time = fps_metrics.processing_time_us(); |
| 6948 | 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] | 6949 | proc_frms, (float)proc_time / 1e6, |
| 6950 | (float)(1e6 * proc_frms) / proc_time); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6951 | proc_frms = 0; |
| 6952 | } |
| 6953 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6954 | |
| 6955 | #ifdef OUTPUT_EXTRADATA_LOG |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6956 | if (outputExtradataFile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6957 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6958 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL; |
| 6959 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
| 6960 | ((unsigned)(buffer->pBuffer + buffer->nOffset + |
| 6961 | buffer->nFilledLen + 3)&(~3)); |
| 6962 | while (p_extra && |
| 6963 | (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6964 | 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] | 6965 | fwrite (p_extra,1,p_extra->nSize,outputExtradataFile); |
| 6966 | if (p_extra->eType == OMX_ExtraDataNone) { |
| 6967 | break; |
| 6968 | } |
| 6969 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 6970 | } |
| 6971 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6972 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6973 | } |
| 6974 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6975 | prev_ts = LLONG_MAX; |
| 6976 | rst_prev_ts = true; |
| 6977 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6978 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6979 | pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 6980 | ((OMX_QCOM_PLATFORM_PRIVATE_LIST *) |
| 6981 | buffer->pPlatformPrivate)->entryList->entry; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6982 | DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6983 | OMX_BUFFERHEADERTYPE *il_buffer; |
| 6984 | il_buffer = client_buffers.get_il_buf_hdr(buffer); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6985 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6986 | if (il_buffer && m_last_rendered_TS >= 0) { |
| 6987 | 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] | 6988 | 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] | 6989 | |
| 6990 | // Current frame can be send for rendering if |
| 6991 | // (a) current FPS is <= 60 |
| 6992 | // (b) is the next frame after the frame with TS 0 |
| 6993 | // (c) is the first frame after seek |
| 6994 | // (d) the delta TS b\w two consecutive frames is > 16 ms |
| 6995 | // (e) its TS is equal to previous frame TS |
| 6996 | // (f) if marked EOS |
| 6997 | |
| 6998 | if(current_framerate <= 60 || m_last_rendered_TS == 0 || |
| 6999 | il_buffer->nTimeStamp == 0 || ts_delta >= 16000 || |
| 7000 | ts_delta == 0 || (il_buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 7001 | m_last_rendered_TS = il_buffer->nTimeStamp; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 7002 | } else { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 7003 | //mark for droping |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 7004 | buffer->nFilledLen = 0; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | DEBUG_PRINT_LOW(" -- %s Frame -- info:: fps(%d) lastRenderTime(%lld) bufferTs(%lld) ts_delta(%d)", |
| 7008 | buffer->nFilledLen? "Rendering":"Dropping",current_framerate,m_last_rendered_TS, |
| 7009 | il_buffer->nTimeStamp,ts_delta); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 7010 | } |
| 7011 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 7012 | if (il_buffer) { |
Arun Menon | 9230eb8 | 2014-02-11 19:19:02 -0800 | [diff] [blame] | 7013 | log_output_buffers(il_buffer); |
| 7014 | if (dynamic_buf_mode) { |
| 7015 | unsigned int nPortIndex = 0; |
| 7016 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 7017 | |
| 7018 | if (!secure_mode) { |
| 7019 | munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr, |
| 7020 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size); |
| 7021 | } |
| 7022 | |
| 7023 | //Clear graphic buffer handles in dynamic mode |
| 7024 | native_buffer[nPortIndex].privatehandle = NULL; |
| 7025 | native_buffer[nPortIndex].nativehandle = NULL; |
| 7026 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7027 | m_cb.FillBufferDone (hComp,m_app_data,il_buffer); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 7028 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7029 | DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr"); |
| 7030 | return OMX_ErrorBadParameter; |
| 7031 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7032 | DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7033 | } else { |
| 7034 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 7035 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7036 | |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 7037 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 7038 | if (m_smoothstreaming_mode && m_out_mem_ptr) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 7039 | OMX_U32 buf_index = buffer - m_out_mem_ptr; |
| 7040 | BufferDim_t dim; |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 7041 | private_handle_t *private_handle = NULL; |
Pushkaraj Patil | 065b573 | 2014-11-26 11:08:02 +0530 | [diff] [blame] | 7042 | dim.sliceWidth = framesize.nWidth; |
| 7043 | dim.sliceHeight = framesize.nHeight; |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 7044 | if (native_buffer[buf_index].privatehandle) |
| 7045 | private_handle = native_buffer[buf_index].privatehandle; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 7046 | if (private_handle) { |
| 7047 | DEBUG_PRINT_LOW("set metadata: update buf-geometry with stride %d slice %d", |
| 7048 | dim.sliceWidth, dim.sliceHeight); |
| 7049 | setMetaData(private_handle, UPDATE_BUFFER_GEOMETRY, (void*)&dim); |
| 7050 | } |
| 7051 | } |
| 7052 | #endif |
| 7053 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7054 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7055 | } |
| 7056 | |
| 7057 | OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7058 | OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7059 | { |
| 7060 | |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7061 | 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] | 7062 | DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7063 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7064 | } |
| 7065 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7066 | DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7067 | buffer, buffer->pBuffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7068 | pending_input_buffers--; |
| 7069 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7070 | if (arbitrary_bytes) { |
| 7071 | if (pdest_frame == NULL && input_flush_progress == false) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7072 | 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] | 7073 | pdest_frame = buffer; |
| 7074 | buffer->nFilledLen = 0; |
| 7075 | buffer->nTimeStamp = LLONG_MAX; |
| 7076 | push_input_buffer (hComp); |
| 7077 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7078 | DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7079 | buffer->nFilledLen = 0; |
| 7080 | if (!m_input_free_q.insert_entry((unsigned)buffer, |
| 7081 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7082 | DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7083 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7084 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7085 | } else if (m_cb.EmptyBufferDone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7086 | buffer->nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7087 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7088 | buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr]; |
| 7089 | } |
| 7090 | m_cb.EmptyBufferDone(hComp ,m_app_data, buffer); |
| 7091 | } |
| 7092 | return OMX_ErrorNone; |
| 7093 | } |
| 7094 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7095 | int omx_vdec::async_message_process (void *context, void* message) |
| 7096 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7097 | omx_vdec* omx = NULL; |
| 7098 | struct vdec_msginfo *vdec_msg = NULL; |
| 7099 | OMX_BUFFERHEADERTYPE* omxhdr = NULL; |
| 7100 | struct v4l2_buffer *v4l2_buf_ptr = NULL; |
| 7101 | struct vdec_output_frameinfo *output_respbuf = NULL; |
| 7102 | int rc=1; |
| 7103 | if (context == NULL || message == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7104 | 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] | 7105 | return -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7106 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7107 | vdec_msg = (struct vdec_msginfo *)message; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7108 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7109 | omx = reinterpret_cast<omx_vdec*>(context); |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 7110 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7111 | switch (vdec_msg->msgcode) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7112 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7113 | case VDEC_MSG_EVT_HW_ERROR: |
| 7114 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7115 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
| 7116 | break; |
| 7117 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 7118 | case VDEC_MSG_EVT_HW_OVERLOAD: |
| 7119 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7120 | OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD); |
| 7121 | break; |
| 7122 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7123 | case VDEC_MSG_RESP_START_DONE: |
| 7124 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7125 | OMX_COMPONENT_GENERATE_START_DONE); |
| 7126 | break; |
| 7127 | |
| 7128 | case VDEC_MSG_RESP_STOP_DONE: |
| 7129 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7130 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 7131 | break; |
| 7132 | |
| 7133 | case VDEC_MSG_RESP_RESUME_DONE: |
| 7134 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7135 | OMX_COMPONENT_GENERATE_RESUME_DONE); |
| 7136 | break; |
| 7137 | |
| 7138 | case VDEC_MSG_RESP_PAUSE_DONE: |
| 7139 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7140 | OMX_COMPONENT_GENERATE_PAUSE_DONE); |
| 7141 | break; |
| 7142 | |
| 7143 | case VDEC_MSG_RESP_FLUSH_INPUT_DONE: |
| 7144 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7145 | OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH); |
| 7146 | break; |
| 7147 | case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE: |
| 7148 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7149 | OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH); |
| 7150 | break; |
| 7151 | case VDEC_MSG_RESP_INPUT_FLUSHED: |
| 7152 | case VDEC_MSG_RESP_INPUT_BUFFER_DONE: |
| 7153 | |
| 7154 | /* omxhdr = (OMX_BUFFERHEADERTYPE* ) |
| 7155 | vdec_msg->msgdata.input_frame_clientdata; */ |
| 7156 | |
| 7157 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata; |
| 7158 | omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index; |
| 7159 | if (omxhdr == NULL || |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7160 | ((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] | 7161 | omxhdr = NULL; |
| 7162 | vdec_msg->status_code = VDEC_S_EFATAL; |
| 7163 | } |
| 7164 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) { |
| 7165 | DEBUG_PRINT_HIGH("Unsupported input"); |
| 7166 | omx->omx_report_error (); |
| 7167 | } |
| 7168 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7169 | vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR; |
| 7170 | } |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7171 | if (omxhdr->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7172 | |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 7173 | DEBUG_PRINT_LOW("Decrement codec_config buffer counter"); |
| 7174 | android_atomic_dec(&omx->m_queued_codec_config_count); |
| 7175 | if ((android_atomic_add(0, &omx->m_queued_codec_config_count) == 0) && |
| 7176 | BITMASK_PRESENT(&omx->m_flags, OMX_COMPONENT_FLUSH_DEFERRED)) { |
| 7177 | DEBUG_PRINT_LOW("sem post for CODEC CONFIG buffer"); |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7178 | sem_post(&omx->m_safe_flush); |
| 7179 | } |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7180 | } |
| 7181 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7182 | omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code, |
| 7183 | OMX_COMPONENT_GENERATE_EBD); |
| 7184 | break; |
| 7185 | case VDEC_MSG_EVT_INFO_FIELD_DROPPED: |
| 7186 | int64_t *timestamp; |
| 7187 | timestamp = (int64_t *) malloc(sizeof(int64_t)); |
| 7188 | if (timestamp) { |
| 7189 | *timestamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7190 | omx->post_event ((unsigned int)timestamp, vdec_msg->status_code, |
| 7191 | OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7192 | DEBUG_PRINT_HIGH("Field dropped time stamp is %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7193 | vdec_msg->msgdata.output_frame.time_stamp); |
| 7194 | } |
| 7195 | break; |
| 7196 | case VDEC_MSG_RESP_OUTPUT_FLUSHED: |
| 7197 | case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE: |
| 7198 | |
| 7199 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data; |
| 7200 | omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7201 | |
| 7202 | 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] | 7203 | omxhdr, vdec_msg->msgdata.output_frame.time_stamp, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7204 | vdec_msg->msgdata.output_frame.pic_type, v4l2_buf_ptr->flags, |
| 7205 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7206 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7207 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7208 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7209 | vdec_msg->msgdata.output_frame.framesize.bottom); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7210 | |
| 7211 | if (omxhdr && omxhdr->pOutputPortPrivate && |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7212 | ((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] | 7213 | (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7214 | - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7215 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 7216 | if (vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7217 | omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len; |
| 7218 | omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset; |
| 7219 | omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7220 | omxhdr->nFlags = 0; |
| 7221 | |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7222 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7223 | omxhdr->nFlags |= OMX_BUFFERFLAG_EOS; |
| 7224 | //rc = -1; |
| 7225 | } |
| 7226 | if (omxhdr->nFilledLen) { |
| 7227 | omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; |
| 7228 | } |
| 7229 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) { |
| 7230 | omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; |
| 7231 | } else { |
| 7232 | omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME; |
| 7233 | } |
| 7234 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) { |
| 7235 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7236 | } |
| 7237 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) { |
| 7238 | omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY; |
| 7239 | } |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 7240 | |
| 7241 | if (v4l2_buf_ptr->flags & V4L2_MSM_BUF_FLAG_MBAFF) { |
| 7242 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_MBAFF; |
| 7243 | } |
| 7244 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7245 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) { |
Arun Menon | e50f6ef | 2013-09-30 15:08:27 -0700 | [diff] [blame] | 7246 | omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7247 | DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d", |
| 7248 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd); |
| 7249 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7250 | if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) { |
| 7251 | omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd, |
| 7252 | omxhdr->nOffset); |
| 7253 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7254 | if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) && |
| 7255 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) && |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7256 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) { |
Praneeth Paladugu | 17364df | 2013-07-30 11:34:16 -0700 | [diff] [blame] | 7257 | omx->time_stamp_dts.remove_time_stamp( |
| 7258 | omxhdr->nTimeStamp, |
| 7259 | (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 7260 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7261 | omx->post_event ((unsigned)NULL,(unsigned int)omxhdr, |
| 7262 | OMX_COMPONENT_GENERATE_FTB); |
| 7263 | break; |
| 7264 | } |
| 7265 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7266 | omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
| 7267 | } |
| 7268 | vdec_msg->msgdata.output_frame.bufferaddr = |
| 7269 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7270 | |
| 7271 | /* Post event if resolution OR crop changed */ |
| 7272 | /* filled length will be changed if resolution changed */ |
| 7273 | /* Crop parameters can be changed even without resolution change */ |
| 7274 | if (omxhdr->nFilledLen |
| 7275 | && ((omx->prev_n_filled_len != omxhdr->nFilledLen) |
| 7276 | || (omx->drv_ctx.frame_size.left != vdec_msg->msgdata.output_frame.framesize.left) |
| 7277 | || (omx->drv_ctx.frame_size.top != vdec_msg->msgdata.output_frame.framesize.top) |
| 7278 | || (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] | 7279 | || (omx->drv_ctx.frame_size.bottom != vdec_msg->msgdata.output_frame.framesize.bottom) |
| 7280 | || (omx->drv_ctx.video_resolution.frame_width != vdec_msg->msgdata.output_frame.picsize.frame_width) |
| 7281 | || (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] | 7282 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 7283 | 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", |
| 7284 | omx->prev_n_filled_len, |
| 7285 | omx->drv_ctx.video_resolution.frame_width, |
| 7286 | omx->drv_ctx.video_resolution.frame_height, |
| 7287 | omx->drv_ctx.frame_size.left, omx->drv_ctx.frame_size.top, |
| 7288 | omx->drv_ctx.frame_size.right, omx->drv_ctx.frame_size.bottom, |
| 7289 | omxhdr->nFilledLen, vdec_msg->msgdata.output_frame.picsize.frame_width, |
| 7290 | vdec_msg->msgdata.output_frame.picsize.frame_height, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7291 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7292 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7293 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7294 | vdec_msg->msgdata.output_frame.framesize.bottom); |
| 7295 | |
Maheshwar Ajja | 0f840ce | 2014-09-29 16:53:42 +0530 | [diff] [blame] | 7296 | omx->drv_ctx.video_resolution.frame_width = |
| 7297 | vdec_msg->msgdata.output_frame.picsize.frame_width; |
| 7298 | omx->drv_ctx.video_resolution.frame_height = |
| 7299 | vdec_msg->msgdata.output_frame.picsize.frame_height; |
Praneeth Paladugu | ca80be7 | 2014-10-22 23:48:54 -0700 | [diff] [blame] | 7300 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) { |
| 7301 | omx->drv_ctx.video_resolution.stride = |
| 7302 | VENUS_Y_STRIDE(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_width); |
| 7303 | omx->drv_ctx.video_resolution.scan_lines = |
| 7304 | VENUS_Y_SCANLINES(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_height); |
| 7305 | } |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7306 | memcpy(&omx->drv_ctx.frame_size, |
| 7307 | &vdec_msg->msgdata.output_frame.framesize, |
| 7308 | sizeof(struct vdec_framesize)); |
| 7309 | |
| 7310 | omx->post_event(OMX_CORE_OUTPUT_PORT_INDEX, |
| 7311 | OMX_IndexConfigCommonOutputCrop, |
| 7312 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7313 | } |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7314 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7315 | if (omxhdr->nFilledLen) |
| 7316 | omx->prev_n_filled_len = omxhdr->nFilledLen; |
| 7317 | |
| 7318 | output_respbuf = (struct vdec_output_frameinfo *)\ |
| 7319 | omxhdr->pOutputPortPrivate; |
| 7320 | output_respbuf->len = vdec_msg->msgdata.output_frame.len; |
| 7321 | output_respbuf->offset = vdec_msg->msgdata.output_frame.offset; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7322 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7323 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) { |
| 7324 | output_respbuf->pic_type = PICTURE_TYPE_I; |
| 7325 | } |
| 7326 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) { |
| 7327 | output_respbuf->pic_type = PICTURE_TYPE_P; |
| 7328 | } |
| 7329 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) { |
| 7330 | output_respbuf->pic_type = PICTURE_TYPE_B; |
| 7331 | } |
| 7332 | |
| 7333 | if (omx->output_use_buffer) |
| 7334 | memcpy ( omxhdr->pBuffer, (void *) |
| 7335 | ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr + |
| 7336 | (unsigned long)vdec_msg->msgdata.output_frame.offset), |
| 7337 | vdec_msg->msgdata.output_frame.len); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7338 | } else { |
| 7339 | DEBUG_PRINT_ERROR("Invalid filled length = %u, buffer size = %u, prev_length = %u", |
| 7340 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7341 | omxhdr->nAllocLen, omx->prev_n_filled_len); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7342 | omxhdr->nFilledLen = 0; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7343 | } |
| 7344 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7345 | omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code, |
| 7346 | OMX_COMPONENT_GENERATE_FBD); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7347 | |
| 7348 | } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7349 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7350 | OMX_COMPONENT_GENERATE_EOS_DONE); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7351 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7352 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7353 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7354 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7355 | break; |
| 7356 | case VDEC_MSG_EVT_CONFIG_CHANGED: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7357 | DEBUG_PRINT_HIGH("Port settings changed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7358 | omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition, |
| 7359 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
| 7360 | break; |
| 7361 | default: |
| 7362 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7363 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7364 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7365 | } |
| 7366 | |
| 7367 | OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary ( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7368 | OMX_HANDLETYPE hComp, |
| 7369 | OMX_BUFFERHEADERTYPE *buffer |
| 7370 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7371 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7372 | unsigned address,p2,id; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7373 | DEBUG_PRINT_LOW("Empty this arbitrary"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7374 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7375 | if (buffer == NULL) { |
| 7376 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7377 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7378 | DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 7379 | DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7380 | buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp); |
| 7381 | |
| 7382 | /* return zero length and not an EOS buffer */ |
| 7383 | /* return buffer if input flush in progress */ |
| 7384 | if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) && |
| 7385 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7386 | DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7387 | m_cb.EmptyBufferDone (hComp,m_app_data,buffer); |
| 7388 | return OMX_ErrorNone; |
| 7389 | } |
| 7390 | |
| 7391 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7392 | 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] | 7393 | psource_frame = buffer; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7394 | DEBUG_PRINT_LOW("Try to Push One Input Buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7395 | push_input_buffer (hComp); |
| 7396 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7397 | DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7398 | if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL, |
| 7399 | (unsigned)NULL)) { |
| 7400 | return OMX_ErrorBadParameter; |
| 7401 | } |
| 7402 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7403 | |
Sowmya Pandiri | 302f5ab | 2014-04-03 13:41:03 -0700 | [diff] [blame] | 7404 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 7405 | codec_config_flag = false; |
| 7406 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7407 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7408 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp) |
| 7412 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7413 | unsigned address,p2,id; |
| 7414 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7415 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7416 | if (pdest_frame == NULL || psource_frame == NULL) { |
| 7417 | /*Check if we have a destination buffer*/ |
| 7418 | if (pdest_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7419 | DEBUG_PRINT_LOW("Get a Destination buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7420 | if (m_input_free_q.m_size) { |
| 7421 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7422 | pdest_frame = (OMX_BUFFERHEADERTYPE *)address; |
| 7423 | pdest_frame->nFilledLen = 0; |
| 7424 | pdest_frame->nTimeStamp = LLONG_MAX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7425 | DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | /*Check if we have a destination buffer*/ |
| 7430 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7431 | DEBUG_PRINT_LOW("Get a source buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7432 | if (m_input_pending_q.m_size) { |
| 7433 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7434 | psource_frame = (OMX_BUFFERHEADERTYPE *)address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7435 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7436 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7437 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7438 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7439 | |
| 7440 | } |
| 7441 | } |
| 7442 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7443 | } |
| 7444 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7445 | while ((pdest_frame != NULL) && (psource_frame != NULL)) { |
| 7446 | switch (codec_type_parse) { |
| 7447 | case CODEC_TYPE_MPEG4: |
| 7448 | case CODEC_TYPE_H263: |
| 7449 | case CODEC_TYPE_MPEG2: |
| 7450 | ret = push_input_sc_codec(hComp); |
| 7451 | break; |
| 7452 | case CODEC_TYPE_H264: |
| 7453 | ret = push_input_h264(hComp); |
| 7454 | break; |
| 7455 | case CODEC_TYPE_VC1: |
| 7456 | ret = push_input_vc1(hComp); |
| 7457 | break; |
| 7458 | default: |
| 7459 | break; |
| 7460 | } |
| 7461 | if (ret != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7462 | DEBUG_PRINT_ERROR("Pushing input Buffer Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7463 | omx_report_error (); |
| 7464 | break; |
| 7465 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7466 | } |
| 7467 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7468 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7469 | } |
| 7470 | |
| 7471 | OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp) |
| 7472 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7473 | OMX_U32 partial_frame = 1; |
| 7474 | OMX_BOOL generate_ebd = OMX_TRUE; |
| 7475 | unsigned address = 0, p2 = 0, id = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7476 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7477 | DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7478 | psource_frame,psource_frame->nTimeStamp); |
| 7479 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7480 | pdest_frame,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7481 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7482 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7483 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7484 | |
| 7485 | if (partial_frame == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7486 | DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7487 | pdest_frame->nFilledLen,psource_frame,frame_count); |
| 7488 | |
| 7489 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7490 | DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7491 | /*First Parsed buffer will have only header Hence skip*/ |
| 7492 | if (frame_count == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7493 | DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7494 | |
| 7495 | if (codec_type_parse == CODEC_TYPE_MPEG4 || |
| 7496 | codec_type_parse == CODEC_TYPE_DIVX) { |
| 7497 | mp4StreamType psBits; |
| 7498 | psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset; |
| 7499 | psBits.numBytes = pdest_frame->nFilledLen; |
| 7500 | mp4_headerparser.parseHeader(&psBits); |
| 7501 | } |
| 7502 | |
| 7503 | frame_count++; |
| 7504 | } else { |
| 7505 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7506 | if (pdest_frame->nFilledLen) { |
| 7507 | /*Push the frame to the Decoder*/ |
| 7508 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7509 | return OMX_ErrorBadParameter; |
| 7510 | } |
| 7511 | frame_count++; |
| 7512 | pdest_frame = NULL; |
| 7513 | |
| 7514 | if (m_input_free_q.m_size) { |
| 7515 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7516 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
| 7517 | pdest_frame->nFilledLen = 0; |
| 7518 | } |
| 7519 | } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7520 | DEBUG_PRINT_ERROR("Zero len buffer return back to POOL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7521 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL, |
| 7522 | (unsigned)NULL); |
| 7523 | pdest_frame = NULL; |
| 7524 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7525 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7526 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7527 | DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7528 | /*Check if Destination Buffer is full*/ |
| 7529 | if (pdest_frame->nAllocLen == |
| 7530 | pdest_frame->nFilledLen + pdest_frame->nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7531 | DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7532 | return OMX_ErrorStreamCorrupt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7533 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7534 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7535 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7536 | if (psource_frame->nFilledLen == 0) { |
| 7537 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7538 | if (pdest_frame) { |
| 7539 | pdest_frame->nFlags |= psource_frame->nFlags; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7540 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7541 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7542 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7543 | pdest_frame->nFilledLen,frame_count++); |
| 7544 | /*Push the frame to the Decoder*/ |
| 7545 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7546 | return OMX_ErrorBadParameter; |
| 7547 | } |
| 7548 | frame_count++; |
| 7549 | pdest_frame = NULL; |
| 7550 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7551 | DEBUG_PRINT_LOW("Last frame in else dest addr") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7552 | generate_ebd = OMX_FALSE; |
| 7553 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7554 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7555 | if (generate_ebd) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7556 | DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7557 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7558 | psource_frame = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7559 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7560 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7561 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7562 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7563 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7564 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7565 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7566 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7567 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7568 | } |
| 7569 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7570 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7571 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7572 | } |
| 7573 | |
| 7574 | OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp) |
| 7575 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7576 | OMX_U32 partial_frame = 1; |
| 7577 | unsigned address = 0, p2 = 0, id = 0; |
| 7578 | OMX_BOOL isNewFrame = OMX_FALSE; |
| 7579 | OMX_BOOL generate_ebd = OMX_TRUE; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7580 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7581 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7582 | DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7583 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7584 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7585 | DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7586 | "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7587 | DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7588 | if (h264_scratch.nFilledLen && look_ahead_nal) { |
| 7589 | look_ahead_nal = false; |
| 7590 | if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7591 | h264_scratch.nFilledLen) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7592 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7593 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7594 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7595 | DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7596 | h264_scratch.nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7597 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7598 | DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7599 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7600 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7601 | } |
Praveen Chavan | ce0b5e8 | 2013-08-08 05:23:34 -0700 | [diff] [blame] | 7602 | |
| 7603 | /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result |
| 7604 | in EOS flag getting associated with the destination |
| 7605 | */ |
| 7606 | if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) && |
| 7607 | pdest_frame->nFilledLen) { |
| 7608 | DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'"); |
| 7609 | generate_ebd = OMX_FALSE; |
| 7610 | } |
| 7611 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7612 | if (nal_length == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7613 | DEBUG_PRINT_LOW("Zero NAL, hence parse using start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7614 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7615 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7616 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7617 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7618 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7619 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7620 | 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] | 7621 | if (m_frame_parser.parse_h264_nallength(psource_frame, |
| 7622 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7623 | DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7624 | return OMX_ErrorBadParameter; |
| 7625 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7626 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7627 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7628 | if (partial_frame == 0) { |
| 7629 | if (nal_count == 0 && h264_scratch.nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7630 | DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7631 | nal_count++; |
| 7632 | h264_scratch.nTimeStamp = psource_frame->nTimeStamp; |
| 7633 | h264_scratch.nFlags = psource_frame->nFlags; |
| 7634 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7635 | DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7636 | if (h264_scratch.nFilledLen) { |
| 7637 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen, |
| 7638 | NALU_TYPE_SPS); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7639 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7640 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) |
| 7641 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7642 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
| 7643 | else if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7644 | // If timeinfo is present frame info from SEI is already processed |
| 7645 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7646 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7647 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7648 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7649 | nal_count++; |
| 7650 | if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) { |
| 7651 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7652 | pdest_frame->nFlags = h264_last_au_flags; |
| 7653 | #ifdef PANSCAN_HDLR |
| 7654 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7655 | h264_parser->update_panscan_data(h264_last_au_ts); |
| 7656 | #endif |
| 7657 | } |
| 7658 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR || |
| 7659 | m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) { |
| 7660 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7661 | h264_last_au_flags = h264_scratch.nFlags; |
| 7662 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7663 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7664 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts); |
| 7665 | if (!VALID_TS(h264_last_au_ts)) |
| 7666 | h264_last_au_ts = ts_in_sei; |
| 7667 | } |
| 7668 | #endif |
| 7669 | } else |
| 7670 | h264_last_au_ts = LLONG_MAX; |
| 7671 | } |
| 7672 | |
| 7673 | if (!isNewFrame) { |
| 7674 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7675 | h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7676 | DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7677 | h264_scratch.nFilledLen); |
| 7678 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7679 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7680 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7681 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ) |
| 7682 | pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7683 | h264_scratch.nFilledLen = 0; |
| 7684 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7685 | DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7686 | return OMX_ErrorBadParameter; |
| 7687 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7688 | } else if(h264_scratch.nFilledLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7689 | look_ahead_nal = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7690 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7691 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7692 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7693 | pdest_frame->nFilledLen,frame_count++); |
| 7694 | |
| 7695 | if (pdest_frame->nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7696 | DEBUG_PRINT_LOW("Copy the Current Frame since and push it"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7697 | look_ahead_nal = false; |
| 7698 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7699 | h264_scratch.nFilledLen) { |
| 7700 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7701 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7702 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7703 | h264_scratch.nFilledLen = 0; |
| 7704 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7705 | DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7706 | return OMX_ErrorBadParameter; |
| 7707 | } |
| 7708 | } else { |
| 7709 | if (psource_frame->nFilledLen || h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7710 | DEBUG_PRINT_LOW("Reset the EOS Flag"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7711 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7712 | } |
| 7713 | /*Push the frame to the Decoder*/ |
| 7714 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7715 | return OMX_ErrorBadParameter; |
| 7716 | } |
| 7717 | //frame_count++; |
| 7718 | pdest_frame = NULL; |
| 7719 | if (m_input_free_q.m_size) { |
| 7720 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7721 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7722 | DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7723 | pdest_frame->nFilledLen = 0; |
| 7724 | pdest_frame->nFlags = 0; |
| 7725 | pdest_frame->nTimeStamp = LLONG_MAX; |
| 7726 | } |
| 7727 | } |
| 7728 | } |
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 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7731 | 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] | 7732 | /*Check if Destination Buffer is full*/ |
| 7733 | if (h264_scratch.nAllocLen == |
| 7734 | h264_scratch.nFilledLen + h264_scratch.nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7735 | DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7736 | return OMX_ErrorStreamCorrupt; |
| 7737 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7738 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7739 | |
| 7740 | if (!psource_frame->nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7741 | 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] | 7742 | |
| 7743 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7744 | if (pdest_frame) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7745 | DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7746 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7747 | h264_scratch.nFilledLen) { |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7748 | if(pdest_frame->nFilledLen == 0) { |
| 7749 | /* No residual frame from before, send whatever |
| 7750 | * we have left */ |
| 7751 | memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7752 | h264_scratch.pBuffer, h264_scratch.nFilledLen); |
| 7753 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7754 | h264_scratch.nFilledLen = 0; |
| 7755 | pdest_frame->nTimeStamp = h264_scratch.nTimeStamp; |
| 7756 | } else { |
| 7757 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7758 | if(!isNewFrame) { |
| 7759 | /* Have a residual frame, but we know that the |
| 7760 | * AU in this frame is belonging to whatever |
| 7761 | * frame we had left over. So append it */ |
| 7762 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7763 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7764 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7765 | h264_scratch.nFilledLen = 0; |
Balamurugan Alagarsamy | efde383 | 2014-09-22 19:52:20 +0530 | [diff] [blame] | 7766 | if (h264_last_au_ts != LLONG_MAX) |
| 7767 | pdest_frame->nTimeStamp = h264_last_au_ts; |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7768 | } else { |
| 7769 | /* Completely new frame, let's just push what |
| 7770 | * we have now. The resulting EBD would trigger |
| 7771 | * another push */ |
| 7772 | generate_ebd = OMX_FALSE; |
| 7773 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7774 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7775 | } |
| 7776 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7777 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7778 | DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7779 | return OMX_ErrorBadParameter; |
| 7780 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7781 | |
| 7782 | /* Iff we coalesced two buffers, inherit the flags of both bufs */ |
| 7783 | if(generate_ebd == OMX_TRUE) { |
| 7784 | pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags; |
| 7785 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7786 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7787 | DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7788 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7789 | DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7790 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7791 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7792 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp); |
| 7793 | if (!VALID_TS(pdest_frame->nTimeStamp)) |
| 7794 | pdest_frame->nTimeStamp = ts_in_sei; |
| 7795 | } |
| 7796 | #endif |
| 7797 | /*Push the frame to the Decoder*/ |
| 7798 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7799 | return OMX_ErrorBadParameter; |
| 7800 | } |
| 7801 | frame_count++; |
| 7802 | pdest_frame = NULL; |
| 7803 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7804 | DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7805 | pdest_frame,h264_scratch.nFilledLen); |
| 7806 | generate_ebd = OMX_FALSE; |
| 7807 | } |
| 7808 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7809 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7810 | if (generate_ebd && !psource_frame->nFilledLen) { |
| 7811 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7812 | psource_frame = NULL; |
| 7813 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7814 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7815 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7816 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7817 | DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7818 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7819 | } |
| 7820 | } |
| 7821 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7822 | } |
| 7823 | |
| 7824 | OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp) |
| 7825 | { |
| 7826 | OMX_U8 *buf, *pdest; |
| 7827 | OMX_U32 partial_frame = 1; |
| 7828 | OMX_U32 buf_len, dest_len; |
| 7829 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7830 | if (first_frame == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7831 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7832 | DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7833 | if (!m_vendor_config.pData) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7834 | DEBUG_PRINT_LOW("Check profile type in 1st source buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7835 | buf = psource_frame->pBuffer; |
| 7836 | buf_len = psource_frame->nFilledLen; |
| 7837 | |
| 7838 | if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) == |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7839 | VC1_SP_MP_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7840 | m_vc1_profile = VC1_SP_MP_RCV; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7841 | } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7842 | m_vc1_profile = VC1_AP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7843 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7844 | DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7845 | return OMX_ErrorStreamCorrupt; |
| 7846 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7847 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7848 | pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen + |
| 7849 | pdest_frame->nOffset; |
| 7850 | dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen + |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7851 | pdest_frame->nOffset); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7852 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7853 | if (dest_len < m_vendor_config.nDataSize) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7854 | DEBUG_PRINT_ERROR("Destination buffer full"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7855 | return OMX_ErrorBadParameter; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7856 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7857 | memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize); |
| 7858 | pdest_frame->nFilledLen += m_vendor_config.nDataSize; |
| 7859 | } |
| 7860 | } |
| 7861 | } |
| 7862 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7863 | switch (m_vc1_profile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7864 | case VC1_AP: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7865 | DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7866 | if (push_input_sc_codec(hComp) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7867 | DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7868 | return OMX_ErrorBadParameter; |
| 7869 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7870 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7871 | |
| 7872 | case VC1_SP_MP_RCV: |
| 7873 | default: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7874 | DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7875 | return OMX_ErrorBadParameter; |
| 7876 | } |
| 7877 | return OMX_ErrorNone; |
| 7878 | } |
| 7879 | |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7880 | #ifndef USE_ION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7881 | 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] | 7882 | OMX_U32 alignment) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7883 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7884 | struct pmem_allocation allocation; |
| 7885 | allocation.size = buffer_size; |
| 7886 | allocation.align = clip2(alignment); |
| 7887 | if (allocation.align < 4096) { |
| 7888 | allocation.align = 4096; |
| 7889 | } |
| 7890 | if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7891 | DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7892 | allocation.align, allocation.size); |
| 7893 | return false; |
| 7894 | } |
| 7895 | return true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7896 | } |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7897 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7898 | #ifdef USE_ION |
| 7899 | int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7900 | OMX_U32 alignment, struct ion_allocation_data *alloc_data, |
| 7901 | struct ion_fd_data *fd_data, int flag) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7902 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7903 | int fd = -EINVAL; |
| 7904 | int rc = -EINVAL; |
| 7905 | int ion_dev_flag; |
| 7906 | struct vdec_ion ion_buf_info; |
| 7907 | if (!alloc_data || buffer_size <= 0 || !fd_data) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7908 | DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7909 | return -EINVAL; |
| 7910 | } |
| 7911 | ion_dev_flag = O_RDONLY; |
| 7912 | fd = open (MEM_DEVICE, ion_dev_flag); |
| 7913 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7914 | DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7915 | return fd; |
| 7916 | } |
| 7917 | alloc_data->flags = 0; |
| 7918 | if (!secure_mode && (flag & ION_FLAG_CACHED)) { |
| 7919 | alloc_data->flags |= ION_FLAG_CACHED; |
| 7920 | } |
| 7921 | alloc_data->len = buffer_size; |
| 7922 | alloc_data->align = clip2(alignment); |
| 7923 | if (alloc_data->align < 4096) { |
| 7924 | alloc_data->align = 4096; |
| 7925 | } |
| 7926 | if ((secure_mode) && (flag & ION_SECURE)) |
| 7927 | alloc_data->flags |= ION_SECURE; |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 7928 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7929 | alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 7930 | if (secure_mode && (alloc_data->flags & ION_SECURE)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7931 | alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID); |
| 7932 | rc = ioctl(fd,ION_IOC_ALLOC,alloc_data); |
| 7933 | if (rc || !alloc_data->handle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7934 | DEBUG_PRINT_ERROR("ION ALLOC memory failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7935 | alloc_data->handle = NULL; |
| 7936 | close(fd); |
| 7937 | fd = -ENOMEM; |
| 7938 | return fd; |
| 7939 | } |
| 7940 | fd_data->handle = alloc_data->handle; |
| 7941 | rc = ioctl(fd,ION_IOC_MAP,fd_data); |
| 7942 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7943 | DEBUG_PRINT_ERROR("ION MAP failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7944 | ion_buf_info.ion_alloc_data = *alloc_data; |
| 7945 | ion_buf_info.ion_device_fd = fd; |
| 7946 | ion_buf_info.fd_ion_data = *fd_data; |
| 7947 | free_ion_memory(&ion_buf_info); |
| 7948 | fd_data->fd =-1; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7949 | fd = -ENOMEM; |
| 7950 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7951 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7952 | return fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7955 | void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info) |
| 7956 | { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7957 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7958 | if (!buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7959 | DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7960 | return; |
| 7961 | } |
| 7962 | if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE, |
| 7963 | &buf_ion_info->ion_alloc_data.handle)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7964 | DEBUG_PRINT_ERROR("ION: free failed" ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7965 | } |
| 7966 | close(buf_ion_info->ion_device_fd); |
| 7967 | buf_ion_info->ion_device_fd = -1; |
| 7968 | buf_ion_info->ion_alloc_data.handle = NULL; |
| 7969 | buf_ion_info->fd_ion_data.fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7970 | } |
| 7971 | #endif |
| 7972 | void omx_vdec::free_output_buffer_header() |
| 7973 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7974 | DEBUG_PRINT_HIGH("ALL output buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7975 | output_use_buffer = false; |
| 7976 | ouput_egl_buffers = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7977 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7978 | if (m_out_mem_ptr) { |
| 7979 | free (m_out_mem_ptr); |
| 7980 | m_out_mem_ptr = NULL; |
| 7981 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7982 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7983 | if (m_platform_list) { |
| 7984 | free(m_platform_list); |
| 7985 | m_platform_list = NULL; |
| 7986 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7987 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7988 | if (drv_ctx.ptr_respbuffer) { |
| 7989 | free (drv_ctx.ptr_respbuffer); |
| 7990 | drv_ctx.ptr_respbuffer = NULL; |
| 7991 | } |
| 7992 | if (drv_ctx.ptr_outputbuffer) { |
| 7993 | free (drv_ctx.ptr_outputbuffer); |
| 7994 | drv_ctx.ptr_outputbuffer = NULL; |
| 7995 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7996 | #ifdef USE_ION |
| 7997 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7998 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7999 | free(drv_ctx.op_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8000 | drv_ctx.op_buf_ion_info = NULL; |
| 8001 | } |
| 8002 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8003 | if (out_dynamic_list) { |
| 8004 | free(out_dynamic_list); |
| 8005 | out_dynamic_list = NULL; |
| 8006 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8007 | } |
| 8008 | |
| 8009 | void omx_vdec::free_input_buffer_header() |
| 8010 | { |
| 8011 | input_use_buffer = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8012 | if (arbitrary_bytes) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8013 | if (m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8014 | DEBUG_PRINT_LOW("Free input Heap Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8015 | free (m_inp_heap_ptr); |
| 8016 | m_inp_heap_ptr = NULL; |
| 8017 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8018 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8019 | if (m_phdr_pmem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8020 | DEBUG_PRINT_LOW("Free input pmem header Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8021 | free (m_phdr_pmem_ptr); |
| 8022 | m_phdr_pmem_ptr = NULL; |
| 8023 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8024 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8025 | if (m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8026 | DEBUG_PRINT_LOW("Free input pmem Pointer area"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8027 | free (m_inp_mem_ptr); |
| 8028 | m_inp_mem_ptr = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8029 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 8030 | /* We just freed all the buffer headers, every thing in m_input_free_q, |
| 8031 | * m_input_pending_q, pdest_frame, and psource_frame is now invalid */ |
Leena Winterrowd | 1d2424a | 2013-08-20 15:26:02 -0700 | [diff] [blame] | 8032 | while (m_input_free_q.m_size) { |
| 8033 | unsigned address, p2, id; |
| 8034 | m_input_free_q.pop_entry(&address, &p2, &id); |
| 8035 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 8036 | while (m_input_pending_q.m_size) { |
| 8037 | unsigned address, p2, id; |
| 8038 | m_input_pending_q.pop_entry(&address, &p2, &id); |
| 8039 | } |
| 8040 | pdest_frame = NULL; |
| 8041 | psource_frame = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8042 | if (drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8043 | DEBUG_PRINT_LOW("Free Driver Context pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8044 | free (drv_ctx.ptr_inputbuffer); |
| 8045 | drv_ctx.ptr_inputbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8046 | } |
| 8047 | #ifdef USE_ION |
| 8048 | if (drv_ctx.ip_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8049 | DEBUG_PRINT_LOW("Free ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8050 | free(drv_ctx.ip_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8051 | drv_ctx.ip_buf_ion_info = NULL; |
| 8052 | } |
| 8053 | #endif |
| 8054 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8055 | |
| 8056 | int omx_vdec::stream_off(OMX_U32 port) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8057 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8058 | enum v4l2_buf_type btype; |
| 8059 | int rc = 0; |
| 8060 | enum v4l2_ports v4l2_port = OUTPUT_PORT; |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8061 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8062 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 8063 | btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8064 | v4l2_port = OUTPUT_PORT; |
| 8065 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 8066 | btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8067 | v4l2_port = CAPTURE_PORT; |
| 8068 | } else if (port == OMX_ALL) { |
| 8069 | int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX); |
| 8070 | int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8071 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8072 | if (!rc_input) |
| 8073 | return rc_input; |
| 8074 | else |
| 8075 | return rc_output; |
| 8076 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8077 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8078 | if (!streaming[v4l2_port]) { |
| 8079 | // already streamed off, warn and move on |
| 8080 | DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port," |
| 8081 | " which is already streamed off", v4l2_port); |
| 8082 | return 0; |
| 8083 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8084 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8085 | DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8086 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8087 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype); |
| 8088 | if (rc) { |
| 8089 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8090 | DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8091 | } else { |
| 8092 | streaming[v4l2_port] = false; |
| 8093 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8094 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8095 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8096 | } |
| 8097 | |
| 8098 | OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 8099 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8100 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8101 | struct v4l2_requestbuffers bufreq; |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 8102 | 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] | 8103 | unsigned int final_extra_data_size = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8104 | struct v4l2_format fmt; |
| 8105 | int ret = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8106 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8107 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8108 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 8109 | bufreq.count = 1; |
| 8110 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8111 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8112 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8113 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 8114 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8115 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8116 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8117 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 8118 | } else { |
| 8119 | eRet = OMX_ErrorBadParameter; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8120 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8121 | if (eRet==OMX_ErrorNone) { |
| 8122 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8123 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8124 | if (ret) { |
| 8125 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 8126 | /*TODO: How to handle this case */ |
| 8127 | eRet = OMX_ErrorInsufficientResources; |
| 8128 | return eRet; |
| 8129 | } else { |
| 8130 | buffer_prop->actualcount = bufreq.count; |
| 8131 | buffer_prop->mincount = bufreq.count; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8132 | DEBUG_PRINT_HIGH("Count = %d",bufreq.count); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8133 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8134 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
| 8135 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8136 | |
| 8137 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 8138 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 8139 | |
| 8140 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 8141 | |
| 8142 | update_resolution(fmt.fmt.pix_mp.width, |
| 8143 | fmt.fmt.pix_mp.height, |
| 8144 | fmt.fmt.pix_mp.plane_fmt[0].bytesperline, |
| 8145 | fmt.fmt.pix_mp.plane_fmt[0].reserved[0]); |
| 8146 | if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 8147 | drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8148 | 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] | 8149 | |
| 8150 | if (ret) { |
| 8151 | /*TODO: How to handle this case */ |
| 8152 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 8153 | eRet = OMX_ErrorInsufficientResources; |
| 8154 | } else { |
| 8155 | int extra_idx = 0; |
| 8156 | |
| 8157 | eRet = is_video_session_supported(); |
| 8158 | if (eRet) |
| 8159 | return eRet; |
| 8160 | |
| 8161 | buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage; |
| 8162 | buf_size = buffer_prop->buffer_size; |
| 8163 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 8164 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 8165 | extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage; |
| 8166 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8167 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8168 | return OMX_ErrorBadParameter; |
| 8169 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8170 | |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 8171 | default_extra_data_size = VENUS_EXTRADATA_SIZE( |
| 8172 | drv_ctx.video_resolution.frame_height, |
| 8173 | drv_ctx.video_resolution.frame_width); |
| 8174 | final_extra_data_size = extra_data_size > default_extra_data_size ? |
| 8175 | extra_data_size : default_extra_data_size; |
| 8176 | |
| 8177 | final_extra_data_size = (final_extra_data_size + buffer_prop->alignment - 1) & |
| 8178 | (~(buffer_prop->alignment - 1)); |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 8179 | |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8180 | drv_ctx.extradata_info.size = buffer_prop->actualcount * final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8181 | drv_ctx.extradata_info.count = buffer_prop->actualcount; |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8182 | drv_ctx.extradata_info.buffer_size = final_extra_data_size; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8183 | if (!secure_mode) |
| 8184 | buf_size += final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8185 | buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8186 | DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)", |
| 8187 | buffer_prop->actualcount, buffer_prop->buffer_size, buf_size); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8188 | if (extra_data_size) |
| 8189 | DEBUG_PRINT_LOW("GetBufReq UPDATE: extradata: TotalSize(%d) BufferSize(%d)", |
| 8190 | drv_ctx.extradata_info.size, drv_ctx.extradata_info.buffer_size); |
| 8191 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8192 | if (in_reconfig) // BufReq will be set to driver when port is disabled |
| 8193 | buffer_prop->buffer_size = buf_size; |
| 8194 | else if (buf_size != buffer_prop->buffer_size) { |
| 8195 | buffer_prop->buffer_size = buf_size; |
| 8196 | eRet = set_buffer_req(buffer_prop); |
| 8197 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8198 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8199 | DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)", |
| 8200 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8201 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8202 | } |
| 8203 | |
| 8204 | OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 8205 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8206 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8207 | unsigned buf_size = 0; |
| 8208 | struct v4l2_format fmt; |
| 8209 | struct v4l2_requestbuffers bufreq; |
| 8210 | int ret; |
| 8211 | DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)", |
| 8212 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8213 | buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8214 | if (buf_size != buffer_prop->buffer_size) { |
| 8215 | DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)", |
| 8216 | buffer_prop->buffer_size, buf_size); |
| 8217 | eRet = OMX_ErrorBadParameter; |
| 8218 | } else { |
| 8219 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 8220 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8221 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8222 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8223 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8224 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Shalaj Jain | d3902bb | 2013-10-07 12:42:55 -0700 | [diff] [blame] | 8225 | fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8226 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8227 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8228 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 8229 | } else { |
| 8230 | eRet = OMX_ErrorBadParameter; |
| 8231 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8232 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8233 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 8234 | if (ret) { |
| 8235 | /*TODO: How to handle this case */ |
| 8236 | DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret); |
| 8237 | eRet = OMX_ErrorInsufficientResources; |
| 8238 | } |
| 8239 | |
| 8240 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 8241 | bufreq.count = buffer_prop->actualcount; |
| 8242 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8243 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8244 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8245 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8246 | } else { |
| 8247 | eRet = OMX_ErrorBadParameter; |
| 8248 | } |
| 8249 | |
| 8250 | if (eRet==OMX_ErrorNone) { |
| 8251 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
| 8252 | } |
| 8253 | |
| 8254 | if (ret) { |
| 8255 | DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret); |
| 8256 | /*TODO: How to handle this case */ |
| 8257 | eRet = OMX_ErrorInsufficientResources; |
| 8258 | } else if (bufreq.count < buffer_prop->actualcount) { |
| 8259 | DEBUG_PRINT_ERROR("Driver refused to change the number of buffers" |
| 8260 | " on v4l2 port %d to %d (prefers %d)", bufreq.type, |
| 8261 | buffer_prop->actualcount, bufreq.count); |
| 8262 | eRet = OMX_ErrorInsufficientResources; |
| 8263 | } else { |
| 8264 | if (!client_buffers.update_buffer_req()) { |
| 8265 | DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed"); |
| 8266 | eRet = OMX_ErrorInsufficientResources; |
| 8267 | } |
| 8268 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8269 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8270 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8271 | } |
| 8272 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8273 | OMX_ERRORTYPE omx_vdec::update_picture_resolution() |
| 8274 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8275 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8276 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8277 | } |
| 8278 | |
| 8279 | OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn) |
| 8280 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8281 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8282 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8283 | if (!portDefn) { |
| 8284 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8285 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8286 | DEBUG_PRINT_LOW("omx_vdec::update_portdef"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8287 | portDefn->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame^] | 8288 | portDefn->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8289 | portDefn->eDomain = OMX_PortDomainVideo; |
| 8290 | if (drv_ctx.frame_rate.fps_denominator > 0) |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 8291 | portDefn->format.video.xFramerate = (drv_ctx.frame_rate.fps_numerator / |
| 8292 | drv_ctx.frame_rate.fps_denominator) << 16; //Q16 format |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8293 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8294 | DEBUG_PRINT_ERROR("Error: Divide by zero"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8295 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8296 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8297 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8298 | if (0 == portDefn->nPortIndex) { |
| 8299 | portDefn->eDir = OMX_DirInput; |
| 8300 | portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount; |
| 8301 | portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount; |
| 8302 | portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size; |
| 8303 | portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused; |
| 8304 | portDefn->format.video.eCompressionFormat = eCompressionFormat; |
| 8305 | portDefn->bEnabled = m_inp_bEnabled; |
| 8306 | portDefn->bPopulated = m_inp_bPopulated; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8307 | |
| 8308 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8309 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8310 | } else if (1 == portDefn->nPortIndex) { |
| 8311 | unsigned int buf_size = 0; |
| 8312 | if (!client_buffers.update_buffer_req()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8313 | DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8314 | return OMX_ErrorHardware; |
| 8315 | } |
| 8316 | if (!client_buffers.get_buffer_req(buf_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8317 | DEBUG_PRINT_ERROR("update buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8318 | return OMX_ErrorHardware; |
| 8319 | } |
| 8320 | portDefn->nBufferSize = buf_size; |
| 8321 | portDefn->eDir = OMX_DirOutput; |
| 8322 | portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount; |
| 8323 | portDefn->nBufferCountMin = drv_ctx.op_buf.mincount; |
| 8324 | portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 8325 | portDefn->bEnabled = m_out_bEnabled; |
| 8326 | portDefn->bPopulated = m_out_bPopulated; |
| 8327 | if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8328 | DEBUG_PRINT_ERROR("Error in getting color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8329 | return OMX_ErrorHardware; |
| 8330 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8331 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8332 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8333 | } else { |
| 8334 | portDefn->eDir = OMX_DirMax; |
| 8335 | DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d", |
| 8336 | (int)portDefn->nPortIndex); |
| 8337 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8338 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8339 | if (is_down_scalar_enabled) { |
| 8340 | int ret = 0; |
| 8341 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 8342 | if (ret) { |
| 8343 | DEBUG_PRINT_ERROR("update_portdef : Error in getting port resolution"); |
| 8344 | return OMX_ErrorHardware; |
| 8345 | } else { |
| 8346 | portDefn->format.video.nFrameWidth = fmt.fmt.pix_mp.width; |
| 8347 | portDefn->format.video.nFrameHeight = fmt.fmt.pix_mp.height; |
| 8348 | portDefn->format.video.nStride = fmt.fmt.pix_mp.plane_fmt[0].bytesperline; |
| 8349 | portDefn->format.video.nSliceHeight = fmt.fmt.pix_mp.plane_fmt[0].reserved[0]; |
| 8350 | } |
| 8351 | } else { |
| 8352 | portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height; |
| 8353 | portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width; |
| 8354 | portDefn->format.video.nStride = drv_ctx.video_resolution.stride; |
| 8355 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines; |
| 8356 | } |
| 8357 | |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 8358 | if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 8359 | (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) { |
Maheshwar Ajja | 77cd19c | 2014-06-05 11:23:18 +0530 | [diff] [blame] | 8360 | portDefn->format.video.nStride = ALIGN(drv_ctx.video_resolution.frame_width, 16); |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8361 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height; |
| 8362 | } |
| 8363 | DEBUG_PRINT_HIGH("update_portdef(%lu): Width = %lu Height = %lu Stride = %ld " |
| 8364 | "SliceHeight = %lu eColorFormat = %lu nBufSize %lu nBufCnt %lu", |
| 8365 | portDefn->nPortIndex, |
| 8366 | portDefn->format.video.nFrameWidth, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8367 | portDefn->format.video.nFrameHeight, |
| 8368 | portDefn->format.video.nStride, |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8369 | portDefn->format.video.nSliceHeight, |
| 8370 | portDefn->format.video.eColorFormat, |
| 8371 | portDefn->nBufferSize, |
| 8372 | portDefn->nBufferCountActual); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8373 | |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8374 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8375 | } |
| 8376 | |
| 8377 | OMX_ERRORTYPE omx_vdec::allocate_output_headers() |
| 8378 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8379 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8380 | OMX_BUFFERHEADERTYPE *bufHdr = NULL; |
| 8381 | unsigned i= 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8382 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8383 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8384 | DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8385 | int nBufHdrSize = 0; |
| 8386 | int nPlatformEntrySize = 0; |
| 8387 | int nPlatformListSize = 0; |
| 8388 | int nPMEMInfoSize = 0; |
| 8389 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 8390 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 8391 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8392 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8393 | DEBUG_PRINT_LOW("Setting First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8394 | drv_ctx.op_buf.actualcount); |
| 8395 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 8396 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8397 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8398 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 8399 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 8400 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 8401 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 8402 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 8403 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8404 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8405 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8406 | sizeof(OMX_BUFFERHEADERTYPE), |
| 8407 | nPMEMInfoSize, |
| 8408 | nPlatformListSize); |
Steve Kondik | f191436 | 2015-11-01 02:50:41 -0800 | [diff] [blame] | 8409 | DEBUG_PRINT_LOW("PE %d bmSize %" PRId64, nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8410 | m_out_bm_count); |
| 8411 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 8412 | // Alloc mem for platform specific info |
| 8413 | char *pPtr=NULL; |
| 8414 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 8415 | nPMEMInfoSize,1); |
| 8416 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \ |
| 8417 | calloc (sizeof(struct vdec_bufferpayload), |
| 8418 | drv_ctx.op_buf.actualcount); |
| 8419 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 8420 | calloc (sizeof (struct vdec_output_frameinfo), |
| 8421 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8422 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 8423 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer"); |
| 8424 | return OMX_ErrorInsufficientResources; |
| 8425 | } |
| 8426 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8427 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8428 | drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \ |
| 8429 | calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8430 | if (!drv_ctx.op_buf_ion_info) { |
| 8431 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 8432 | return OMX_ErrorInsufficientResources; |
| 8433 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8434 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8435 | if (dynamic_buf_mode) { |
| 8436 | out_dynamic_list = (struct dynamic_buf_list *) \ |
| 8437 | calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount); |
| 8438 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8439 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 8440 | && drv_ctx.ptr_respbuffer) { |
| 8441 | bufHdr = m_out_mem_ptr; |
| 8442 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 8443 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 8444 | (((char *) m_platform_list) + nPlatformListSize); |
| 8445 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 8446 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 8447 | pPlatformList = m_platform_list; |
| 8448 | pPlatformEntry = m_platform_entry; |
| 8449 | pPMEMInfo = m_pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8450 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8451 | 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] | 8452 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8453 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8454 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8455 | m_out_mem_ptr,pPlatformEntry); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8456 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8457 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 8458 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 8459 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8460 | // Set the values when we determine the right HxW param |
| 8461 | bufHdr->nAllocLen = 0; |
| 8462 | bufHdr->nFilledLen = 0; |
| 8463 | bufHdr->pAppPrivate = NULL; |
| 8464 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8465 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 8466 | pPlatformEntry->entry = pPMEMInfo; |
| 8467 | // Initialize the Platform List |
| 8468 | pPlatformList->nEntries = 1; |
| 8469 | pPlatformList->entryList = pPlatformEntry; |
| 8470 | // Keep pBuffer NULL till vdec is opened |
| 8471 | bufHdr->pBuffer = NULL; |
| 8472 | pPMEMInfo->offset = 0; |
| 8473 | pPMEMInfo->pmem_fd = 0; |
| 8474 | bufHdr->pPlatformPrivate = pPlatformList; |
| 8475 | drv_ctx.ptr_outputbuffer[i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8476 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8477 | drv_ctx.op_buf_ion_info[i].ion_device_fd =-1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8478 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8479 | /*Create a mapping between buffers*/ |
| 8480 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 8481 | drv_ctx.ptr_respbuffer[i].client_data = (void *) \ |
| 8482 | &drv_ctx.ptr_outputbuffer[i]; |
| 8483 | // Move the buffer and buffer header pointers |
| 8484 | bufHdr++; |
| 8485 | pPMEMInfo++; |
| 8486 | pPlatformEntry++; |
| 8487 | pPlatformList++; |
| 8488 | } |
| 8489 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8490 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8491 | m_out_mem_ptr, pPtr); |
| 8492 | if (m_out_mem_ptr) { |
| 8493 | free(m_out_mem_ptr); |
| 8494 | m_out_mem_ptr = NULL; |
| 8495 | } |
| 8496 | if (pPtr) { |
| 8497 | free(pPtr); |
| 8498 | pPtr = NULL; |
| 8499 | } |
| 8500 | if (drv_ctx.ptr_outputbuffer) { |
| 8501 | free(drv_ctx.ptr_outputbuffer); |
| 8502 | drv_ctx.ptr_outputbuffer = NULL; |
| 8503 | } |
| 8504 | if (drv_ctx.ptr_respbuffer) { |
| 8505 | free(drv_ctx.ptr_respbuffer); |
| 8506 | drv_ctx.ptr_respbuffer = NULL; |
| 8507 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8508 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8509 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8510 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8511 | free(drv_ctx.op_buf_ion_info); |
| 8512 | drv_ctx.op_buf_ion_info = NULL; |
| 8513 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8514 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8515 | eRet = OMX_ErrorInsufficientResources; |
| 8516 | } |
| 8517 | } else { |
| 8518 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8519 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8520 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8521 | } |
| 8522 | |
| 8523 | void omx_vdec::complete_pending_buffer_done_cbs() |
| 8524 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8525 | unsigned p1; |
| 8526 | unsigned p2; |
| 8527 | unsigned ident; |
| 8528 | omx_cmd_queue tmp_q, pending_bd_q; |
| 8529 | pthread_mutex_lock(&m_lock); |
| 8530 | // pop all pending GENERATE FDB from ftb queue |
| 8531 | while (m_ftb_q.m_size) { |
| 8532 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
| 8533 | if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 8534 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8535 | } else { |
| 8536 | tmp_q.insert_entry(p1,p2,ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8537 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8538 | } |
| 8539 | //return all non GENERATE FDB to ftb queue |
| 8540 | while (tmp_q.m_size) { |
| 8541 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8542 | m_ftb_q.insert_entry(p1,p2,ident); |
| 8543 | } |
| 8544 | // pop all pending GENERATE EDB from etb queue |
| 8545 | while (m_etb_q.m_size) { |
| 8546 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 8547 | if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 8548 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8549 | } else { |
| 8550 | tmp_q.insert_entry(p1,p2,ident); |
| 8551 | } |
| 8552 | } |
| 8553 | //return all non GENERATE FDB to etb queue |
| 8554 | while (tmp_q.m_size) { |
| 8555 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8556 | m_etb_q.insert_entry(p1,p2,ident); |
| 8557 | } |
| 8558 | pthread_mutex_unlock(&m_lock); |
| 8559 | // process all pending buffer dones |
| 8560 | while (pending_bd_q.m_size) { |
| 8561 | pending_bd_q.pop_entry(&p1,&p2,&ident); |
| 8562 | switch (ident) { |
| 8563 | case OMX_COMPONENT_GENERATE_EBD: |
| 8564 | if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8565 | DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8566 | omx_report_error (); |
| 8567 | } |
| 8568 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8569 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8570 | case OMX_COMPONENT_GENERATE_FBD: |
| 8571 | if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8572 | DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8573 | omx_report_error (); |
| 8574 | } |
| 8575 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8576 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8577 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8578 | } |
| 8579 | |
| 8580 | void omx_vdec::set_frame_rate(OMX_S64 act_timestamp) |
| 8581 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8582 | OMX_U32 new_frame_interval = 0; |
| 8583 | if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts |
| 8584 | && llabs(act_timestamp - prev_ts) > 2000) { |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 8585 | new_frame_interval = client_set_fps ? frm_int : (act_timestamp - prev_ts) > 0 ? |
| 8586 | llabs(act_timestamp - prev_ts) : llabs(act_timestamp - prev_ts_actual); |
Arun Menon | d9e49f8 | 2014-04-23 18:50:26 -0700 | [diff] [blame] | 8587 | if (new_frame_interval != frm_int || frm_int == 0) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8588 | frm_int = new_frame_interval; |
| 8589 | if (frm_int) { |
| 8590 | drv_ctx.frame_rate.fps_numerator = 1e6; |
| 8591 | drv_ctx.frame_rate.fps_denominator = frm_int; |
| 8592 | DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)", |
| 8593 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 8594 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8595 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8596 | /* We need to report the difference between this FBD and the previous FBD |
| 8597 | * back to the driver for clock scaling purposes. */ |
| 8598 | struct v4l2_outputparm oparm; |
| 8599 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 8600 | * per second.*/ |
| 8601 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 8602 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8603 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8604 | struct v4l2_streamparm sparm; |
| 8605 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8606 | sparm.parm.output = oparm; |
| 8607 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 8608 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 8609 | performance might be affected"); |
| 8610 | } |
| 8611 | |
| 8612 | } |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8613 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8614 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8615 | prev_ts = act_timestamp; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8616 | } |
| 8617 | |
| 8618 | void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp) |
| 8619 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8620 | if (rst_prev_ts && VALID_TS(act_timestamp)) { |
| 8621 | prev_ts = act_timestamp; |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 8622 | prev_ts_actual = act_timestamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8623 | rst_prev_ts = false; |
| 8624 | } else if (VALID_TS(prev_ts)) { |
| 8625 | bool codec_cond = (drv_ctx.timestamp_adjust)? |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 8626 | (!VALID_TS(act_timestamp) || act_timestamp < prev_ts_actual || llabs(act_timestamp - prev_ts_actual) <= 2000) : |
| 8627 | (!VALID_TS(act_timestamp) || act_timestamp <= prev_ts_actual); |
| 8628 | prev_ts_actual = act_timestamp; //unadjusted previous timestamp |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8629 | if (frm_int > 0 && codec_cond) { |
| 8630 | DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp); |
| 8631 | act_timestamp = prev_ts + frm_int; |
| 8632 | DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp); |
| 8633 | prev_ts = act_timestamp; |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8634 | } else { |
| 8635 | if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) { |
| 8636 | // ensure that timestamps can never step backwards when in display order |
| 8637 | act_timestamp = prev_ts; |
| 8638 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8639 | set_frame_rate(act_timestamp); |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8640 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8641 | } else if (frm_int > 0) // In this case the frame rate was set along |
| 8642 | { // with the port definition, start ts with 0 |
| 8643 | act_timestamp = prev_ts = 0; // and correct if a valid ts is received. |
| 8644 | rst_prev_ts = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8645 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8646 | } |
| 8647 | |
| 8648 | void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 8649 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8650 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL; |
| 8651 | OMX_U32 num_conceal_MB = 0; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8652 | OMX_TICKS time_stamp = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8653 | OMX_U32 frame_rate = 0; |
| 8654 | int consumed_len = 0; |
| 8655 | OMX_U32 num_MB_in_frame; |
| 8656 | OMX_U32 recovery_sei_flags = 1; |
| 8657 | int enable = 0; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8658 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8659 | int buf_index = p_buf_hdr - m_out_mem_ptr; |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 8660 | if (buf_index >= drv_ctx.extradata_info.count) { |
| 8661 | DEBUG_PRINT_ERROR("handle_extradata: invalid index(%d) max(%d)", |
| 8662 | buf_index, drv_ctx.extradata_info.count); |
| 8663 | return; |
| 8664 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8665 | struct msm_vidc_panscan_window_payload *panscan_payload = NULL; |
| 8666 | OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) + |
| 8667 | p_buf_hdr->nOffset; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8668 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8669 | if (!drv_ctx.extradata_info.uaddr) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8670 | DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8671 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8672 | } |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8673 | |
| 8674 | if (!secure_mode && (drv_ctx.extradata_info.buffer_size > (p_buf_hdr->nAllocLen - p_buf_hdr->nFilledLen)) ) { |
| 8675 | DEBUG_PRINT_ERROR("Error: Insufficient size allocated for extra-data"); |
| 8676 | p_extra = NULL; |
| 8677 | return; |
| 8678 | } |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8679 | if (!secure_mode) |
| 8680 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8681 | ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3)); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8682 | else |
| 8683 | p_extra = m_other_extradata; |
| 8684 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8685 | 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] | 8686 | if (!secure_mode && ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))) { |
| 8687 | DEBUG_PRINT_ERROR("Error: out of bound memory access by p_extra"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8688 | p_extra = NULL; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8689 | return; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8690 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8691 | OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8692 | if (data && p_extra) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8693 | while ((consumed_len < drv_ctx.extradata_info.buffer_size) |
| 8694 | && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 8695 | if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8696 | DEBUG_PRINT_LOW("Invalid extra data size"); |
| 8697 | break; |
| 8698 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8699 | DEBUG_PRINT_LOW("handle_extradata: eType = %d", data->eType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8700 | switch ((unsigned long)data->eType) { |
| 8701 | case EXTRADATA_INTERLACE_VIDEO: |
| 8702 | struct msm_vidc_interlace_payload *payload; |
| 8703 | payload = (struct msm_vidc_interlace_payload *)data->data; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8704 | if (payload) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8705 | enable = 1; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8706 | switch (payload->format) { |
| 8707 | case INTERLACE_FRAME_PROGRESSIVE: |
| 8708 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 8709 | enable = 0; |
| 8710 | break; |
| 8711 | case INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST: |
| 8712 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8713 | break; |
| 8714 | case INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST: |
| 8715 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameBottomFieldFirst; |
| 8716 | break; |
| 8717 | default: |
| 8718 | DEBUG_PRINT_LOW("default case - set interlace to topfield"); |
| 8719 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8720 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8721 | } |
| 8722 | if (m_enable_android_native_buffers) |
| 8723 | setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle, |
| 8724 | PP_PARAM_INTERLACED, (void*)&enable); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8725 | if (client_extradata & OMX_INTERLACE_EXTRADATA) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8726 | append_interlace_extradata(p_extra, payload->format, |
| 8727 | p_buf_hdr->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8728 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8729 | } |
| 8730 | break; |
| 8731 | case EXTRADATA_FRAME_RATE: |
| 8732 | struct msm_vidc_framerate_payload *frame_rate_payload; |
| 8733 | frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data; |
| 8734 | frame_rate = frame_rate_payload->frame_rate; |
| 8735 | break; |
| 8736 | case EXTRADATA_TIMESTAMP: |
| 8737 | struct msm_vidc_ts_payload *time_stamp_payload; |
| 8738 | time_stamp_payload = (struct msm_vidc_ts_payload *)data->data; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8739 | time_stamp = time_stamp_payload->timestamp_lo; |
| 8740 | time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32); |
| 8741 | p_buf_hdr->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8742 | break; |
| 8743 | case EXTRADATA_NUM_CONCEALED_MB: |
| 8744 | struct msm_vidc_concealmb_payload *conceal_mb_payload; |
| 8745 | conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data; |
| 8746 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8747 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8748 | num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0); |
| 8749 | break; |
| 8750 | case EXTRADATA_INDEX: |
| 8751 | int *etype; |
| 8752 | etype = (int *)(data->data); |
| 8753 | if (etype && *etype == EXTRADATA_ASPECT_RATIO) { |
| 8754 | struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload; |
| 8755 | aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype); |
| 8756 | if (aspect_ratio_payload) { |
| 8757 | ((struct vdec_output_frameinfo *) |
| 8758 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width; |
| 8759 | ((struct vdec_output_frameinfo *) |
| 8760 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height; |
| 8761 | } |
| 8762 | } |
| 8763 | break; |
| 8764 | case EXTRADATA_RECOVERY_POINT_SEI: |
| 8765 | struct msm_vidc_recoverysei_payload *recovery_sei_payload; |
| 8766 | recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data; |
| 8767 | recovery_sei_flags = recovery_sei_payload->flags; |
| 8768 | if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) { |
| 8769 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8770 | DEBUG_PRINT_HIGH(""); |
| 8771 | DEBUG_PRINT_HIGH("***************************************************"); |
| 8772 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 8773 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8774 | } |
| 8775 | break; |
| 8776 | case EXTRADATA_PANSCAN_WINDOW: |
| 8777 | panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data; |
| 8778 | break; |
| 8779 | case EXTRADATA_MPEG2_SEQDISP: |
| 8780 | struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload; |
| 8781 | seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data; |
| 8782 | if (seqdisp_payload) { |
| 8783 | m_disp_hor_size = seqdisp_payload->disp_width; |
| 8784 | m_disp_vert_size = seqdisp_payload->disp_height; |
| 8785 | } |
| 8786 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8787 | case EXTRADATA_S3D_FRAME_PACKING: |
| 8788 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload; |
| 8789 | 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] | 8790 | if (client_extradata & OMX_FRAMEPACK_EXTRADATA) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8791 | append_framepack_extradata(p_extra, s3d_frame_packing_payload); |
| 8792 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8793 | } |
| 8794 | break; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8795 | case EXTRADATA_FRAME_QP: |
| 8796 | struct msm_vidc_frame_qp_payload *qp_payload; |
| 8797 | qp_payload = (struct msm_vidc_frame_qp_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8798 | if (client_extradata & OMX_QP_EXTRADATA) { |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8799 | append_qp_extradata(p_extra, qp_payload); |
| 8800 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8801 | } |
| 8802 | break; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8803 | case EXTRADATA_FRAME_BITS_INFO: |
| 8804 | struct msm_vidc_frame_bits_info_payload *bits_info_payload; |
| 8805 | bits_info_payload = (struct msm_vidc_frame_bits_info_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8806 | if (client_extradata & OMX_BITSINFO_EXTRADATA) { |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8807 | append_bitsinfo_extradata(p_extra, bits_info_payload); |
| 8808 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8809 | } |
| 8810 | break; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8811 | case EXTRADATA_STREAM_USERDATA: |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8812 | if (client_extradata & OMX_EXTNUSER_EXTRADATA) { |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8813 | append_user_extradata(p_extra, data); |
| 8814 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8815 | } |
| 8816 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8817 | default: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8818 | DEBUG_PRINT_LOW("Unrecognized extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8819 | goto unrecognized_extradata; |
| 8820 | } |
| 8821 | consumed_len += data->nSize; |
| 8822 | data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize); |
| 8823 | } |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8824 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8825 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
| 8826 | append_frame_info_extradata(p_extra, |
| 8827 | 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] | 8828 | time_stamp, panscan_payload,&((struct vdec_output_frameinfo *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8829 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info); |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8830 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8831 | } |
| 8832 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8833 | unrecognized_extradata: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8834 | if (client_extradata && p_extra) { |
| 8835 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8836 | append_terminator_extradata(p_extra); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8837 | } |
| 8838 | |
Arun Menon | fd72393 | 2014-05-30 17:56:31 -0700 | [diff] [blame] | 8839 | if (secure_mode && p_extradata && m_other_extradata) { |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8840 | struct vdec_output_frameinfo *ptr_extradatabuff = NULL; |
| 8841 | memcpy(p_extradata, m_other_extradata, drv_ctx.extradata_info.buffer_size); |
| 8842 | ptr_extradatabuff = (struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate; |
| 8843 | ptr_extradatabuff->metadata_info.metabufaddr = (void *)p_extradata; |
| 8844 | ptr_extradatabuff->metadata_info.size = drv_ctx.extradata_info.buffer_size; |
| 8845 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8846 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8847 | } |
| 8848 | |
Vinay Kalia | 9c00cae | 2012-12-06 16:08:20 -0800 | [diff] [blame] | 8849 | OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8850 | bool is_internal, bool enable) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8851 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8852 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 8853 | struct v4l2_control control; |
| 8854 | if (m_state != OMX_StateLoaded) { |
| 8855 | DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only"); |
| 8856 | return OMX_ErrorIncorrectStateOperation; |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 8857 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8858 | 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] | 8859 | client_extradata, requested_extradata, enable, is_internal); |
| 8860 | |
| 8861 | if (!is_internal) { |
| 8862 | if (enable) |
| 8863 | client_extradata |= requested_extradata; |
| 8864 | else |
| 8865 | client_extradata = client_extradata & ~requested_extradata; |
| 8866 | } |
| 8867 | |
| 8868 | if (enable) { |
| 8869 | if (requested_extradata & OMX_INTERLACE_EXTRADATA) { |
| 8870 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8871 | control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO; |
| 8872 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8873 | DEBUG_PRINT_HIGH("Failed to set interlaced extradata." |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8874 | " Quality of interlaced clips might be impacted."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8875 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8876 | } |
| 8877 | if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8878 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8879 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE; |
| 8880 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8881 | DEBUG_PRINT_HIGH("Failed to set framerate extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8882 | } |
| 8883 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8884 | control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB; |
| 8885 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8886 | DEBUG_PRINT_HIGH("Failed to set concealed MB extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8887 | } |
| 8888 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8889 | control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI; |
| 8890 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8891 | DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8892 | } |
| 8893 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8894 | control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW; |
| 8895 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8896 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8897 | } |
| 8898 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8899 | control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO; |
| 8900 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8901 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8902 | } |
| 8903 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 8904 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8905 | control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP; |
| 8906 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8907 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8908 | } |
| 8909 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8910 | } |
| 8911 | if (requested_extradata & OMX_TIMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8912 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8913 | control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP; |
| 8914 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8915 | DEBUG_PRINT_HIGH("Failed to set timeinfo extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8916 | } |
| 8917 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8918 | if (requested_extradata & OMX_FRAMEPACK_EXTRADATA) { |
| 8919 | if (output_capability == V4L2_PIX_FMT_H264) { |
| 8920 | DEBUG_PRINT_HIGH("enable OMX_FRAMEPACK_EXTRADATA"); |
| 8921 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8922 | control.value = V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING; |
| 8923 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8924 | DEBUG_PRINT_HIGH("Failed to set S3D_FRAME_PACKING extradata"); |
| 8925 | } |
| 8926 | } else { |
| 8927 | DEBUG_PRINT_HIGH("OMX_FRAMEPACK_EXTRADATA supported for H264 only"); |
| 8928 | } |
| 8929 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8930 | if (requested_extradata & OMX_QP_EXTRADATA) { |
| 8931 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8932 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP; |
| 8933 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8934 | DEBUG_PRINT_HIGH("Failed to set QP extradata"); |
| 8935 | } |
| 8936 | } |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8937 | if (requested_extradata & OMX_BITSINFO_EXTRADATA) { |
| 8938 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8939 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO; |
| 8940 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8941 | DEBUG_PRINT_HIGH("Failed to set frame bits info extradata"); |
| 8942 | } |
| 8943 | } |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8944 | if (requested_extradata & OMX_EXTNUSER_EXTRADATA) { |
| 8945 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8946 | control.value = V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA; |
| 8947 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8948 | DEBUG_PRINT_HIGH("Failed to set stream userdata extradata"); |
| 8949 | } |
| 8950 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8951 | } |
| 8952 | ret = get_buffer_req(&drv_ctx.op_buf); |
| 8953 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8954 | } |
| 8955 | |
| 8956 | OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8957 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8958 | OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0; |
| 8959 | OMX_U8 *data_ptr = extra->data, data = 0; |
| 8960 | while (byte_count < extra->nDataSize) { |
| 8961 | data = *data_ptr; |
| 8962 | while (data) { |
| 8963 | num_MB += (data&0x01); |
| 8964 | data >>= 1; |
| 8965 | } |
| 8966 | data_ptr++; |
| 8967 | byte_count++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8968 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8969 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8970 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8971 | 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] | 8972 | } |
| 8973 | |
| 8974 | void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8975 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8976 | if (!m_debug_extradata) |
| 8977 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8978 | |
| 8979 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8980 | "============== Extra Data ==============\n" |
| 8981 | " Size: %lu\n" |
| 8982 | " Version: %lu\n" |
| 8983 | " PortIndex: %lu\n" |
| 8984 | " Type: %x\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8985 | " DataSize: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8986 | extra->nSize, extra->nVersion.nVersion, |
| 8987 | extra->nPortIndex, extra->eType, extra->nDataSize); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8988 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8989 | if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) { |
| 8990 | OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 8991 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8992 | "------ Interlace Format ------\n" |
| 8993 | " Size: %lu\n" |
| 8994 | " Version: %lu\n" |
| 8995 | " PortIndex: %lu\n" |
| 8996 | " Is Interlace Format: %d\n" |
| 8997 | " Interlace Formats: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8998 | "=========== End of Interlace ===========", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8999 | intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex, |
| 9000 | intfmt->bInterlaceFormat, intfmt->nInterlaceFormats); |
| 9001 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) { |
| 9002 | OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 9003 | |
| 9004 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 9005 | "-------- Frame Format --------\n" |
| 9006 | " Picture Type: %d\n" |
| 9007 | " Interlace Type: %d\n" |
| 9008 | " Pan Scan Total Frame Num: %lu\n" |
| 9009 | " Concealed Macro Blocks: %lu\n" |
| 9010 | " frame rate: %lu\n" |
| 9011 | " Time Stamp: %llu\n" |
| 9012 | " Aspect Ratio X: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9013 | " Aspect Ratio Y: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9014 | fminfo->ePicType, |
| 9015 | fminfo->interlaceType, |
| 9016 | fminfo->panScan.numWindows, |
| 9017 | fminfo->nConcealedMacroblocks, |
| 9018 | fminfo->nFrameRate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9019 | fminfo->nTimeStamp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9020 | fminfo->aspectRatio.aspectRatioX, |
| 9021 | fminfo->aspectRatio.aspectRatioY); |
| 9022 | |
| 9023 | for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) { |
| 9024 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9025 | "------------------------------" |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 9026 | " Pan Scan Frame Num: %lu\n" |
| 9027 | " Rectangle x: %ld\n" |
| 9028 | " Rectangle y: %ld\n" |
| 9029 | " Rectangle dx: %ld\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9030 | " Rectangle dy: %ld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9031 | i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y, |
| 9032 | fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy); |
| 9033 | } |
| 9034 | |
| 9035 | DEBUG_PRINT_HIGH("========= End of Frame Format =========="); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 9036 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement) { |
| 9037 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 9038 | DEBUG_PRINT_HIGH( |
| 9039 | "------------------ Framepack Format ----------\n" |
| 9040 | " id: %lu \n" |
| 9041 | " cancel_flag: %lu \n" |
| 9042 | " type: %lu \n" |
| 9043 | " quincunx_sampling_flagFormat: %lu \n" |
| 9044 | " content_interpretation_type: %lu \n" |
| 9045 | " content_interpretation_type: %lu \n" |
| 9046 | " spatial_flipping_flag: %lu \n" |
| 9047 | " frame0_flipped_flag: %lu \n" |
| 9048 | " field_views_flag: %lu \n" |
| 9049 | " current_frame_is_frame0_flag: %lu \n" |
| 9050 | " frame0_self_contained_flag: %lu \n" |
| 9051 | " frame1_self_contained_flag: %lu \n" |
| 9052 | " frame0_grid_position_x: %lu \n" |
| 9053 | " frame0_grid_position_y: %lu \n" |
| 9054 | " frame1_grid_position_x: %lu \n" |
| 9055 | " frame1_grid_position_y: %lu \n" |
| 9056 | " reserved_byte: %lu \n" |
| 9057 | " repetition_period: %lu \n" |
| 9058 | " extension_flag: %lu \n" |
| 9059 | "================== End of Framepack ===========", |
| 9060 | framepack->id, |
| 9061 | framepack->cancel_flag, |
| 9062 | framepack->type, |
| 9063 | framepack->quincunx_sampling_flag, |
| 9064 | framepack->content_interpretation_type, |
| 9065 | framepack->spatial_flipping_flag, |
| 9066 | framepack->frame0_flipped_flag, |
| 9067 | framepack->field_views_flag, |
| 9068 | framepack->current_frame_is_frame0_flag, |
| 9069 | framepack->frame0_self_contained_flag, |
| 9070 | framepack->frame1_self_contained_flag, |
| 9071 | framepack->frame0_grid_position_x, |
| 9072 | framepack->frame0_grid_position_y, |
| 9073 | framepack->frame1_grid_position_x, |
| 9074 | framepack->frame1_grid_position_y, |
| 9075 | framepack->reserved_byte, |
| 9076 | framepack->repetition_period, |
| 9077 | framepack->extension_flag); |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 9078 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataQP) { |
| 9079 | OMX_QCOM_EXTRADATA_QP * qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 9080 | DEBUG_PRINT_HIGH( |
| 9081 | "---- QP (Frame quantization parameter) ----\n" |
| 9082 | " Frame QP: %lu \n" |
| 9083 | "================ End of QP ================\n", |
| 9084 | qp->nQP); |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 9085 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo) { |
| 9086 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = (OMX_QCOM_EXTRADATA_BITS_INFO *)extra->data; |
| 9087 | DEBUG_PRINT_HIGH( |
| 9088 | "--------- Input bits information --------\n" |
| 9089 | " Header bits: %lu \n" |
| 9090 | " Frame bits: %lu \n" |
| 9091 | "===== End of Input bits information =====\n", |
| 9092 | bits->header_bits, bits->frame_bits); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9093 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData) { |
| 9094 | OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)extra->data; |
| 9095 | OMX_U8 *data_ptr = (OMX_U8 *)userdata->data; |
| 9096 | OMX_U32 userdata_size = extra->nDataSize - sizeof(userdata->type); |
| 9097 | OMX_U32 i = 0; |
| 9098 | DEBUG_PRINT_HIGH( |
| 9099 | "-------------- Userdata -------------\n" |
| 9100 | " Stream userdata type: %d\n" |
| 9101 | " userdata size: %d\n" |
| 9102 | " STREAM_USERDATA:", |
| 9103 | userdata->type, userdata_size); |
| 9104 | for (i = 0; i < userdata_size; i+=4) { |
| 9105 | DEBUG_PRINT_HIGH(" %x %x %x %x", |
| 9106 | data_ptr[i], data_ptr[i+1], |
| 9107 | data_ptr[i+2], data_ptr[i+3]); |
| 9108 | } |
| 9109 | DEBUG_PRINT_HIGH( |
| 9110 | "=========== End of Userdata ==========="); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9111 | } else if (extra->eType == OMX_ExtraDataNone) { |
| 9112 | DEBUG_PRINT_HIGH("========== End of Terminator ==========="); |
| 9113 | } else { |
| 9114 | DEBUG_PRINT_HIGH("======= End of Driver Extradata ========"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9115 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9116 | } |
| 9117 | |
| 9118 | void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9119 | OMX_U32 interlaced_format_type, bool is_mbaff) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9120 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9121 | OMX_STREAMINTERLACEFORMAT *interlace_format; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9122 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9123 | if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) { |
| 9124 | return; |
| 9125 | } |
| 9126 | extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE; |
| 9127 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9128 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9129 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat; |
| 9130 | extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 9131 | interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 9132 | interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 9133 | interlace_format->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9134 | interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9135 | |
| 9136 | if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !is_mbaff) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9137 | interlace_format->bInterlaceFormat = OMX_FALSE; |
| 9138 | interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive; |
| 9139 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9140 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9141 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9142 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9143 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9144 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9145 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9146 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameBottomFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9147 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9148 | } else { |
| 9149 | interlace_format->bInterlaceFormat = OMX_TRUE; |
| 9150 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
| 9151 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 9152 | } |
| 9153 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9154 | } |
| 9155 | |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9156 | void omx_vdec::fill_aspect_ratio_info( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9157 | struct vdec_aspectratioinfo *aspect_ratio_info, |
| 9158 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info) |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9159 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9160 | m_extradata = frame_info; |
| 9161 | m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width; |
| 9162 | m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9163 | DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9164 | m_extradata->aspectRatio.aspectRatioY); |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9165 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9166 | |
| 9167 | void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9168 | 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] | 9169 | OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload, |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9170 | struct vdec_aspectratioinfo *aspect_ratio_info) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9171 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9172 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL; |
| 9173 | struct msm_vidc_panscan_window *panscan_window; |
| 9174 | if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) { |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9175 | return; |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9176 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9177 | extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE; |
| 9178 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9179 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9180 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo; |
| 9181 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO); |
| 9182 | frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 9183 | switch (picture_type) { |
| 9184 | case PICTURE_TYPE_I: |
| 9185 | frame_info->ePicType = OMX_VIDEO_PictureTypeI; |
| 9186 | break; |
| 9187 | case PICTURE_TYPE_P: |
| 9188 | frame_info->ePicType = OMX_VIDEO_PictureTypeP; |
| 9189 | break; |
| 9190 | case PICTURE_TYPE_B: |
| 9191 | frame_info->ePicType = OMX_VIDEO_PictureTypeB; |
| 9192 | break; |
| 9193 | default: |
| 9194 | frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0; |
| 9195 | } |
| 9196 | if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst) |
| 9197 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 9198 | else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst) |
| 9199 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 9200 | else |
| 9201 | frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 9202 | memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio)); |
| 9203 | frame_info->nConcealedMacroblocks = num_conceal_mb; |
| 9204 | frame_info->nFrameRate = frame_rate; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9205 | frame_info->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9206 | frame_info->panScan.numWindows = 0; |
| 9207 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 9208 | if (m_disp_hor_size && m_disp_vert_size) { |
| 9209 | frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size; |
| 9210 | frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size; |
Pushkaraj Patil | 5e6ebd9 | 2014-03-10 10:29:14 +0530 | [diff] [blame] | 9211 | } else { |
| 9212 | frame_info->displayAspectRatio.displayHorizontalSize = 0; |
| 9213 | frame_info->displayAspectRatio.displayVerticalSize = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9214 | } |
| 9215 | } |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9216 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9217 | if (panscan_payload) { |
| 9218 | frame_info->panScan.numWindows = panscan_payload->num_panscan_windows; |
| 9219 | panscan_window = &panscan_payload->wnd[0]; |
| 9220 | for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) { |
| 9221 | frame_info->panScan.window[i].x = panscan_window->panscan_window_width; |
| 9222 | frame_info->panScan.window[i].y = panscan_window->panscan_window_height; |
| 9223 | frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset; |
| 9224 | frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset; |
| 9225 | panscan_window++; |
| 9226 | } |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9227 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9228 | fill_aspect_ratio_info(aspect_ratio_info, frame_info); |
| 9229 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9230 | } |
| 9231 | |
| 9232 | void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9233 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9234 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL; |
| 9235 | extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE; |
| 9236 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9237 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9238 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef; |
| 9239 | extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
| 9240 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data; |
| 9241 | *portDefn = m_port_def; |
| 9242 | DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu " |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9243 | "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9244 | portDefn->format.video.nFrameWidth, |
| 9245 | portDefn->format.video.nStride, |
| 9246 | portDefn->format.video.nSliceHeight); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9247 | } |
| 9248 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 9249 | void omx_vdec::append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9250 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload) |
| 9251 | { |
| 9252 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack; |
| 9253 | if (FRAME_PACK_SIZE*sizeof(OMX_U32) != sizeof(struct msm_vidc_s3d_frame_packing_payload)) { |
| 9254 | DEBUG_PRINT_ERROR("frame packing size mismatch"); |
| 9255 | return; |
| 9256 | } |
| 9257 | extra->nSize = OMX_FRAMEPACK_EXTRADATA_SIZE; |
| 9258 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9259 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9260 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement; |
| 9261 | extra->nDataSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9262 | framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 9263 | framepack->nSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9264 | framepack->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9265 | framepack->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9266 | memcpy(&framepack->id, s3d_frame_packing_payload, |
| 9267 | sizeof(struct msm_vidc_s3d_frame_packing_payload)); |
| 9268 | memcpy(&m_frame_pack_arrangement, framepack, |
| 9269 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
| 9270 | print_debug_extradata(extra); |
| 9271 | } |
| 9272 | |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 9273 | void omx_vdec::append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9274 | struct msm_vidc_frame_qp_payload *qp_payload) |
| 9275 | { |
| 9276 | OMX_QCOM_EXTRADATA_QP * qp = NULL; |
| 9277 | if (!qp_payload) { |
| 9278 | DEBUG_PRINT_ERROR("QP payload is NULL"); |
| 9279 | return; |
| 9280 | } |
| 9281 | extra->nSize = OMX_QP_EXTRADATA_SIZE; |
| 9282 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9283 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9284 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataQP; |
| 9285 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_QP); |
| 9286 | qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 9287 | qp->nQP = qp_payload->frame_qp; |
| 9288 | print_debug_extradata(extra); |
| 9289 | } |
| 9290 | |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 9291 | void omx_vdec::append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9292 | struct msm_vidc_frame_bits_info_payload *bits_payload) |
| 9293 | { |
| 9294 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = NULL; |
| 9295 | if (!bits_payload) { |
| 9296 | DEBUG_PRINT_ERROR("bits info payload is NULL"); |
| 9297 | return; |
| 9298 | } |
| 9299 | extra->nSize = OMX_BITSINFO_EXTRADATA_SIZE; |
| 9300 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9301 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9302 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo; |
| 9303 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_BITS_INFO); |
| 9304 | bits = (OMX_QCOM_EXTRADATA_BITS_INFO*)extra->data; |
| 9305 | bits->frame_bits = bits_payload->frame_bits; |
| 9306 | bits->header_bits = bits_payload->header_bits; |
| 9307 | print_debug_extradata(extra); |
| 9308 | } |
| 9309 | |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9310 | void omx_vdec::append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9311 | OMX_OTHER_EXTRADATATYPE *p_user) |
| 9312 | { |
| 9313 | int userdata_size = 0; |
| 9314 | struct msm_vidc_stream_userdata_payload *userdata_payload = NULL; |
| 9315 | userdata_payload = |
| 9316 | (struct msm_vidc_stream_userdata_payload *)p_user->data; |
| 9317 | userdata_size = p_user->nDataSize; |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 9318 | extra->nSize = OMX_USERDATA_EXTRADATA_SIZE + p_user->nSize; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9319 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9320 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9321 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData; |
| 9322 | extra->nDataSize = userdata_size; |
| 9323 | if (extra->data && p_user->data && extra->nDataSize) |
| 9324 | memcpy(extra->data, p_user->data, extra->nDataSize); |
| 9325 | print_debug_extradata(extra); |
| 9326 | } |
| 9327 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9328 | void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9329 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9330 | if (!client_extradata) { |
| 9331 | return; |
| 9332 | } |
| 9333 | extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE); |
| 9334 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9335 | extra->eType = OMX_ExtraDataNone; |
| 9336 | extra->nDataSize = 0; |
| 9337 | extra->data[0] = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9338 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9339 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9340 | } |
| 9341 | |
| 9342 | OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index) |
| 9343 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9344 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9345 | if (index >= drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9346 | DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9347 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9348 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9349 | if (m_desc_buffer_ptr == NULL) { |
| 9350 | m_desc_buffer_ptr = (desc_buffer_hdr*) \ |
| 9351 | calloc( (sizeof(desc_buffer_hdr)), |
| 9352 | drv_ctx.ip_buf.actualcount); |
| 9353 | if (m_desc_buffer_ptr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9354 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9355 | return OMX_ErrorInsufficientResources; |
| 9356 | } |
| 9357 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9358 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9359 | m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8)); |
| 9360 | if (m_desc_buffer_ptr[index].buf_addr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9361 | DEBUG_PRINT_ERROR("desc buffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9362 | return OMX_ErrorInsufficientResources; |
| 9363 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9364 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9365 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9366 | } |
| 9367 | |
| 9368 | void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset) |
| 9369 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9370 | DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries); |
| 9371 | if (m_demux_entries < 8192) { |
| 9372 | m_demux_offsets[m_demux_entries++] = address_offset; |
| 9373 | } |
| 9374 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9375 | } |
| 9376 | |
| 9377 | void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr) |
| 9378 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9379 | OMX_U32 bytes_to_parse = buf_hdr->nFilledLen; |
| 9380 | OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset; |
| 9381 | OMX_U32 index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9382 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9383 | m_demux_entries = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9384 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9385 | while (index < bytes_to_parse) { |
| 9386 | if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9387 | (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) || |
| 9388 | ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9389 | (buf[index+2] == 0x01)) ) { |
| 9390 | //Found start code, insert address offset |
| 9391 | insert_demux_addr_offset(index); |
| 9392 | if (buf[index+2] == 0x01) // 3 byte start code |
| 9393 | index += 3; |
| 9394 | else //4 byte start code |
| 9395 | index += 4; |
| 9396 | } else |
| 9397 | index++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9398 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9399 | DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries); |
| 9400 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9401 | } |
| 9402 | |
| 9403 | OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 9404 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9405 | //fix this, handle 3 byte start code, vc1 terminator entry |
| 9406 | OMX_U8 *p_demux_data = NULL; |
| 9407 | OMX_U32 desc_data = 0; |
| 9408 | OMX_U32 start_addr = 0; |
| 9409 | OMX_U32 nal_size = 0; |
| 9410 | OMX_U32 suffix_byte = 0; |
| 9411 | OMX_U32 demux_index = 0; |
| 9412 | OMX_U32 buffer_index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9413 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9414 | if (m_desc_buffer_ptr == NULL) { |
| 9415 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries."); |
| 9416 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9417 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9418 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9419 | buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
| 9420 | if (buffer_index > drv_ctx.ip_buf.actualcount) { |
| 9421 | DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index); |
| 9422 | return OMX_ErrorBadParameter; |
| 9423 | } |
| 9424 | |
| 9425 | p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr; |
| 9426 | |
| 9427 | if ( ((OMX_U8*)p_demux_data == NULL) || |
| 9428 | ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) { |
| 9429 | DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries."); |
| 9430 | return OMX_ErrorBadParameter; |
| 9431 | } else { |
| 9432 | for (; demux_index < m_demux_entries; demux_index++) { |
| 9433 | desc_data = 0; |
| 9434 | start_addr = m_demux_offsets[demux_index]; |
| 9435 | if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) { |
| 9436 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3]; |
| 9437 | } else { |
| 9438 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4]; |
| 9439 | } |
| 9440 | if (demux_index < (m_demux_entries - 1)) { |
| 9441 | nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2; |
| 9442 | } else { |
| 9443 | nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2; |
| 9444 | } |
| 9445 | DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)", |
| 9446 | (void *)start_addr, |
| 9447 | suffix_byte, |
| 9448 | nal_size, |
| 9449 | demux_index); |
| 9450 | desc_data = (start_addr >> 3) << 1; |
| 9451 | desc_data |= (start_addr & 7) << 21; |
| 9452 | desc_data |= suffix_byte << 24; |
| 9453 | |
| 9454 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9455 | memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32)); |
| 9456 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9457 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9458 | |
| 9459 | p_demux_data += 16; |
| 9460 | } |
| 9461 | if (codec_type_parse == CODEC_TYPE_VC1) { |
| 9462 | DEBUG_PRINT_LOW("VC1 terminator entry"); |
| 9463 | desc_data = 0; |
| 9464 | desc_data = 0x82 << 24; |
| 9465 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9466 | memset(p_demux_data + 4, 0, sizeof(OMX_U32)); |
| 9467 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9468 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9469 | p_demux_data += 16; |
| 9470 | m_demux_entries++; |
| 9471 | } |
| 9472 | //Add zero word to indicate end of descriptors |
| 9473 | memset(p_demux_data, 0, sizeof(OMX_U32)); |
| 9474 | |
| 9475 | m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32); |
| 9476 | DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size); |
| 9477 | } |
| 9478 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 9479 | m_demux_entries = 0; |
| 9480 | DEBUG_PRINT_LOW("Demux table complete!"); |
| 9481 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9482 | } |
| 9483 | |
Deva Ramasubramanian | 9403f02 | 2012-11-28 18:27:53 -0800 | [diff] [blame] | 9484 | OMX_ERRORTYPE omx_vdec::createDivxDrmContext() |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9485 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9486 | OMX_ERRORTYPE err = OMX_ErrorNone; |
| 9487 | iDivXDrmDecrypt = DivXDrmDecrypt::Create(); |
| 9488 | if (iDivXDrmDecrypt) { |
| 9489 | OMX_ERRORTYPE err = iDivXDrmDecrypt->Init(); |
| 9490 | if (err!=OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9491 | DEBUG_PRINT_ERROR("ERROR :iDivXDrmDecrypt->Init %d", err); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9492 | delete iDivXDrmDecrypt; |
| 9493 | iDivXDrmDecrypt = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9494 | } |
| 9495 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9496 | DEBUG_PRINT_ERROR("Unable to Create DIVX DRM"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9497 | err = OMX_ErrorUndefined; |
| 9498 | } |
| 9499 | return err; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9500 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9501 | |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9502 | omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf() |
| 9503 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9504 | enabled = false; |
| 9505 | omx = NULL; |
| 9506 | init_members(); |
| 9507 | ColorFormat = OMX_COLOR_FormatMax; |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9508 | dest_format = YCbCr420P; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9509 | } |
| 9510 | |
| 9511 | void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client) |
| 9512 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9513 | omx = reinterpret_cast<omx_vdec*>(client); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9514 | } |
| 9515 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9516 | void omx_vdec::allocate_color_convert_buf::init_members() |
| 9517 | { |
| 9518 | allocated_count = 0; |
| 9519 | buffer_size_req = 0; |
| 9520 | buffer_alignment_req = 0; |
| 9521 | memset(m_platform_list_client,0,sizeof(m_platform_list_client)); |
| 9522 | memset(m_platform_entry_client,0,sizeof(m_platform_entry_client)); |
| 9523 | memset(m_pmem_info_client,0,sizeof(m_pmem_info_client)); |
| 9524 | 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] | 9525 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9526 | memset(op_buf_ion_info,0,sizeof(m_platform_entry_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9527 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9528 | for (int i = 0; i < MAX_COUNT; i++) |
| 9529 | pmem_fd[i] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9530 | } |
| 9531 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9532 | omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf() |
| 9533 | { |
| 9534 | c2d.destroy(); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9535 | } |
| 9536 | |
| 9537 | bool omx_vdec::allocate_color_convert_buf::update_buffer_req() |
| 9538 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9539 | bool status = true; |
| 9540 | unsigned int src_size = 0, destination_size = 0; |
| 9541 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9542 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9543 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9544 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9545 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9546 | if (!enabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9547 | DEBUG_PRINT_HIGH("No color conversion required"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9548 | return status; |
| 9549 | } |
| 9550 | pthread_mutex_lock(&omx->c_lock); |
| 9551 | if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 && |
| 9552 | ColorFormat != OMX_COLOR_FormatYUV420Planar) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9553 | DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9554 | status = false; |
| 9555 | goto fail_update_buf_req; |
| 9556 | } |
| 9557 | c2d.close(); |
| 9558 | status = c2d.open(omx->drv_ctx.video_resolution.frame_height, |
| 9559 | omx->drv_ctx.video_resolution.frame_width, |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9560 | NV12_128m,dest_format); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9561 | if (status) { |
| 9562 | status = c2d.get_buffer_size(C2D_INPUT,src_size); |
| 9563 | if (status) |
| 9564 | status = c2d.get_buffer_size(C2D_OUTPUT,destination_size); |
| 9565 | } |
| 9566 | if (status) { |
| 9567 | if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size || |
| 9568 | !destination_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9569 | DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9570 | "driver size %d destination size %d", |
| 9571 | src_size,omx->drv_ctx.op_buf.buffer_size,destination_size); |
| 9572 | status = false; |
| 9573 | c2d.close(); |
| 9574 | buffer_size_req = 0; |
| 9575 | } else { |
| 9576 | buffer_size_req = destination_size; |
| 9577 | if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size) |
| 9578 | buffer_size_req = omx->drv_ctx.op_buf.buffer_size; |
| 9579 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9580 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
| 9581 | } |
| 9582 | } |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9583 | fail_update_buf_req: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9584 | pthread_mutex_unlock(&omx->c_lock); |
| 9585 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9586 | } |
| 9587 | |
| 9588 | bool omx_vdec::allocate_color_convert_buf::set_color_format( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9589 | OMX_COLOR_FORMATTYPE dest_color_format) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9590 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9591 | bool status = true; |
| 9592 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9593 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9594 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9595 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9596 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9597 | pthread_mutex_lock(&omx->c_lock); |
| 9598 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9599 | drv_color_format = (OMX_COLOR_FORMATTYPE) |
| 9600 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9601 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9602 | DEBUG_PRINT_ERROR("Incorrect color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9603 | status = false; |
| 9604 | } |
| 9605 | if (status && (drv_color_format != dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9606 | DEBUG_PRINT_LOW("Enabling C2D"); |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9607 | if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) && |
| 9608 | (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9609 | DEBUG_PRINT_ERROR("Unsupported color format for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9610 | status = false; |
| 9611 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9612 | ColorFormat = dest_color_format; |
| 9613 | dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ? |
| 9614 | YCbCr420P : YCbCr420SP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9615 | if (enabled) |
| 9616 | c2d.destroy(); |
| 9617 | enabled = false; |
| 9618 | if (!c2d.init()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9619 | DEBUG_PRINT_ERROR("open failed for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9620 | status = false; |
| 9621 | } else |
| 9622 | enabled = true; |
| 9623 | } |
| 9624 | } else { |
| 9625 | if (enabled) |
| 9626 | c2d.destroy(); |
| 9627 | enabled = false; |
| 9628 | } |
| 9629 | pthread_mutex_unlock(&omx->c_lock); |
| 9630 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9631 | } |
| 9632 | |
| 9633 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr() |
| 9634 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9635 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9636 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9637 | return NULL; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9638 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9639 | if (!enabled) |
| 9640 | return omx->m_out_mem_ptr; |
| 9641 | return m_out_mem_ptr_client; |
| 9642 | } |
| 9643 | |
| 9644 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr |
| 9645 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9646 | { |
| 9647 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9648 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9649 | return NULL; |
| 9650 | } |
| 9651 | if (!enabled) |
| 9652 | return bufadd; |
| 9653 | |
| 9654 | unsigned index = 0; |
| 9655 | index = bufadd - omx->m_out_mem_ptr; |
| 9656 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9657 | m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS); |
| 9658 | m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp; |
| 9659 | bool status; |
| 9660 | if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) { |
| 9661 | pthread_mutex_lock(&omx->c_lock); |
| 9662 | status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd, |
| 9663 | omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index], |
| 9664 | pmem_baseaddress[index], pmem_baseaddress[index]); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9665 | if (!status) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9666 | DEBUG_PRINT_ERROR("Failed color conversion %d", status); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9667 | m_out_mem_ptr_client[index].nFilledLen = 0; |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9668 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9669 | return &m_out_mem_ptr_client[index]; |
Praveen Chavan | 6d6b725 | 2014-09-15 17:05:54 -0700 | [diff] [blame] | 9670 | } else { |
| 9671 | unsigned int filledLen = 0; |
| 9672 | c2d.get_output_filled_length(filledLen); |
| 9673 | m_out_mem_ptr_client[index].nFilledLen = filledLen; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9674 | } |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9675 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9676 | } else |
| 9677 | m_out_mem_ptr_client[index].nFilledLen = 0; |
| 9678 | return &m_out_mem_ptr_client[index]; |
| 9679 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9680 | DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9681 | return NULL; |
| 9682 | } |
| 9683 | |
| 9684 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr |
| 9685 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9686 | { |
| 9687 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9688 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9689 | return NULL; |
| 9690 | } |
| 9691 | if (!enabled) |
| 9692 | return bufadd; |
| 9693 | unsigned index = 0; |
| 9694 | index = bufadd - m_out_mem_ptr_client; |
| 9695 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9696 | return &omx->m_out_mem_ptr[index]; |
| 9697 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9698 | DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9699 | return NULL; |
| 9700 | } |
| 9701 | bool omx_vdec::allocate_color_convert_buf::get_buffer_req |
| 9702 | (unsigned int &buffer_size) |
| 9703 | { |
| 9704 | bool status = true; |
| 9705 | pthread_mutex_lock(&omx->c_lock); |
| 9706 | if (!enabled) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9707 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9708 | else { |
| 9709 | if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9710 | DEBUG_PRINT_ERROR("Get buffer size failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9711 | status = false; |
| 9712 | goto fail_get_buffer_size; |
| 9713 | } |
| 9714 | } |
| 9715 | if (buffer_size < omx->drv_ctx.op_buf.buffer_size) |
| 9716 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
| 9717 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9718 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9719 | fail_get_buffer_size: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9720 | pthread_mutex_unlock(&omx->c_lock); |
| 9721 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9722 | } |
| 9723 | OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9724 | OMX_BUFFERHEADERTYPE *bufhdr) |
| 9725 | { |
| 9726 | unsigned int index = 0; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9727 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9728 | if (!enabled) |
| 9729 | return omx->free_output_buffer(bufhdr); |
| 9730 | if (enabled && omx->is_component_secure()) |
| 9731 | return OMX_ErrorNone; |
| 9732 | if (!allocated_count || !bufhdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9733 | DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9734 | return OMX_ErrorBadParameter; |
| 9735 | } |
| 9736 | index = bufhdr - m_out_mem_ptr_client; |
| 9737 | if (index >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9738 | DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9739 | return OMX_ErrorBadParameter; |
| 9740 | } |
| 9741 | if (pmem_fd[index] > 0) { |
| 9742 | munmap(pmem_baseaddress[index], buffer_size_req); |
| 9743 | close(pmem_fd[index]); |
| 9744 | } |
| 9745 | pmem_fd[index] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9746 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9747 | omx->free_ion_memory(&op_buf_ion_info[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9748 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9749 | m_heap_ptr[index].video_heap_ptr = NULL; |
| 9750 | if (allocated_count > 0) |
| 9751 | allocated_count--; |
| 9752 | else |
| 9753 | allocated_count = 0; |
| 9754 | if (!allocated_count) { |
| 9755 | pthread_mutex_lock(&omx->c_lock); |
| 9756 | c2d.close(); |
| 9757 | init_members(); |
| 9758 | pthread_mutex_unlock(&omx->c_lock); |
| 9759 | } |
| 9760 | return omx->free_output_buffer(&omx->m_out_mem_ptr[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9761 | } |
| 9762 | |
| 9763 | 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] | 9764 | OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9765 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9766 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9767 | if (!enabled) { |
| 9768 | eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes); |
| 9769 | return eRet; |
| 9770 | } |
| 9771 | if (enabled && omx->is_component_secure()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9772 | DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9773 | omx->is_component_secure()); |
| 9774 | return OMX_ErrorUnsupportedSetting; |
| 9775 | } |
| 9776 | if (!bufferHdr || bytes > buffer_size_req) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9777 | DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr); |
| 9778 | DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9779 | buffer_size_req,bytes); |
| 9780 | return OMX_ErrorBadParameter; |
| 9781 | } |
| 9782 | if (allocated_count >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9783 | DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9784 | return OMX_ErrorInsufficientResources; |
| 9785 | } |
| 9786 | OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL; |
| 9787 | eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr, |
| 9788 | port,appData,omx->drv_ctx.op_buf.buffer_size); |
| 9789 | if (eRet != OMX_ErrorNone || !temp_bufferHdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9790 | DEBUG_PRINT_ERROR("Buffer allocation failed color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9791 | return eRet; |
| 9792 | } |
| 9793 | if ((temp_bufferHdr - omx->m_out_mem_ptr) >= |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 9794 | (int)omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9795 | DEBUG_PRINT_ERROR("Invalid header index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9796 | (temp_bufferHdr - omx->m_out_mem_ptr)); |
| 9797 | return OMX_ErrorUndefined; |
| 9798 | } |
| 9799 | unsigned int i = allocated_count; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9800 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9801 | op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory( |
| 9802 | buffer_size_req,buffer_alignment_req, |
| 9803 | &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data, |
| 9804 | 0); |
| 9805 | pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd; |
| 9806 | if (op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9807 | DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9808 | return OMX_ErrorInsufficientResources; |
| 9809 | } |
| 9810 | pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req, |
| 9811 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9812 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9813 | if (pmem_baseaddress[i] == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9814 | DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9815 | close(pmem_fd[i]); |
| 9816 | omx->free_ion_memory(&op_buf_ion_info[i]); |
| 9817 | return OMX_ErrorInsufficientResources; |
| 9818 | } |
| 9819 | m_heap_ptr[i].video_heap_ptr = new VideoHeap ( |
| 9820 | op_buf_ion_info[i].ion_device_fd,buffer_size_req, |
| 9821 | 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] | 9822 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9823 | m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get(); |
| 9824 | m_pmem_info_client[i].offset = 0; |
| 9825 | m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i]; |
| 9826 | m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 9827 | m_platform_list_client[i].nEntries = 1; |
| 9828 | m_platform_list_client[i].entryList = &m_platform_entry_client[i]; |
| 9829 | m_out_mem_ptr_client[i].pOutputPortPrivate = NULL; |
| 9830 | m_out_mem_ptr_client[i].nAllocLen = buffer_size_req; |
| 9831 | m_out_mem_ptr_client[i].nFilledLen = 0; |
| 9832 | m_out_mem_ptr_client[i].nFlags = 0; |
| 9833 | m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9834 | m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 9835 | m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION; |
| 9836 | m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i]; |
| 9837 | m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i]; |
| 9838 | m_out_mem_ptr_client[i].pAppPrivate = appData; |
| 9839 | *bufferHdr = &m_out_mem_ptr_client[i]; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9840 | DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9841 | allocated_count++; |
| 9842 | return eRet; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9843 | } |
| 9844 | |
| 9845 | bool omx_vdec::is_component_secure() |
| 9846 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9847 | return secure_mode; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9848 | } |
| 9849 | |
| 9850 | bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format) |
| 9851 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9852 | bool status = true; |
| 9853 | if (!enabled) { |
| 9854 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9855 | dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 9856 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9857 | else |
| 9858 | status = false; |
| 9859 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9860 | if (ColorFormat == OMX_COLOR_FormatYUV420Planar || |
| 9861 | ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) { |
| 9862 | dest_color_format = ColorFormat; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9863 | } else |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9864 | status = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9865 | } |
| 9866 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9867 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9868 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9869 | void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset) |
| 9870 | { |
| 9871 | int i = 0; |
| 9872 | bool buf_present = false; |
| 9873 | pthread_mutex_lock(&m_lock); |
| 9874 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9875 | //check the buffer fd, offset, uv addr with list contents |
| 9876 | //If present increment reference. |
| 9877 | if ((out_dynamic_list[i].fd == fd) && |
| 9878 | (out_dynamic_list[i].offset == offset)) { |
| 9879 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9880 | 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] | 9881 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9882 | buf_present = true; |
| 9883 | break; |
| 9884 | } |
| 9885 | } |
| 9886 | if (!buf_present) { |
| 9887 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9888 | //search for a entry to insert details of the new buffer |
| 9889 | if (out_dynamic_list[i].dup_fd == 0) { |
| 9890 | out_dynamic_list[i].fd = fd; |
| 9891 | out_dynamic_list[i].offset = offset; |
| 9892 | out_dynamic_list[i].dup_fd = dup(fd); |
| 9893 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9894 | DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9895 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9896 | break; |
| 9897 | } |
| 9898 | } |
| 9899 | } |
| 9900 | pthread_mutex_unlock(&m_lock); |
| 9901 | } |
| 9902 | |
| 9903 | void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset) |
| 9904 | { |
| 9905 | int i = 0; |
| 9906 | pthread_mutex_lock(&m_lock); |
| 9907 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9908 | //check the buffer fd, offset, uv addr with list contents |
| 9909 | //If present decrement reference. |
| 9910 | if ((out_dynamic_list[i].fd == fd) && |
| 9911 | (out_dynamic_list[i].offset == offset)) { |
| 9912 | out_dynamic_list[i].ref_count--; |
| 9913 | if (out_dynamic_list[i].ref_count == 0) { |
| 9914 | close(out_dynamic_list[i].dup_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9915 | DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9916 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9917 | out_dynamic_list[i].dup_fd = 0; |
| 9918 | out_dynamic_list[i].fd = 0; |
| 9919 | out_dynamic_list[i].offset = 0; |
| 9920 | } |
| 9921 | break; |
| 9922 | } |
| 9923 | } |
| 9924 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9925 | 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] | 9926 | } |
| 9927 | pthread_mutex_unlock(&m_lock); |
| 9928 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 9929 | |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 9930 | OMX_ERRORTYPE omx_vdec::enable_adaptive_playback(unsigned long nMaxFrameWidth, |
| 9931 | unsigned long nMaxFrameHeight) |
| 9932 | { |
| 9933 | |
| 9934 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9935 | int ret = 0; |
| 9936 | unsigned long min_res_buf_count = 0; |
| 9937 | |
| 9938 | eRet = enable_smoothstreaming(); |
| 9939 | if (eRet != OMX_ErrorNone) { |
| 9940 | DEBUG_PRINT_ERROR("Failed to enable Adaptive Playback on driver"); |
| 9941 | return eRet; |
| 9942 | } |
| 9943 | |
| 9944 | DEBUG_PRINT_HIGH("Enabling Adaptive playback for %lu x %lu", |
| 9945 | nMaxFrameWidth, |
| 9946 | nMaxFrameHeight); |
| 9947 | m_smoothstreaming_mode = true; |
| 9948 | m_smoothstreaming_width = nMaxFrameWidth; |
| 9949 | m_smoothstreaming_height = nMaxFrameHeight; |
| 9950 | |
| 9951 | //Get upper limit buffer count for min supported resolution |
| 9952 | struct v4l2_format fmt; |
| 9953 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9954 | fmt.fmt.pix_mp.height = m_decoder_capability.min_height; |
| 9955 | fmt.fmt.pix_mp.width = m_decoder_capability.min_width; |
| 9956 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9957 | |
| 9958 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9959 | if (ret) { |
| 9960 | DEBUG_PRINT_ERROR("Set Resolution failed for HxW = %ux%u", |
| 9961 | m_decoder_capability.min_height, |
| 9962 | m_decoder_capability.min_width); |
| 9963 | return OMX_ErrorUnsupportedSetting; |
| 9964 | } |
| 9965 | |
| 9966 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9967 | if (eRet != OMX_ErrorNone) { |
| 9968 | DEBUG_PRINT_ERROR("failed to get_buffer_req"); |
| 9969 | return eRet; |
| 9970 | } |
| 9971 | |
| 9972 | min_res_buf_count = drv_ctx.op_buf.mincount; |
| 9973 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer count = %lu for HxW %ux%u", |
| 9974 | min_res_buf_count, m_decoder_capability.min_height, m_decoder_capability.min_width); |
| 9975 | |
| 9976 | update_resolution(m_smoothstreaming_width, m_smoothstreaming_height, |
| 9977 | m_smoothstreaming_width, m_smoothstreaming_height); |
| 9978 | eRet = is_video_session_supported(); |
| 9979 | if (eRet != OMX_ErrorNone) { |
| 9980 | DEBUG_PRINT_ERROR("video session is not supported"); |
| 9981 | return eRet; |
| 9982 | } |
| 9983 | |
| 9984 | //Get upper limit buffer size for max smooth streaming resolution set |
| 9985 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9986 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 9987 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 9988 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9989 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9990 | if (ret) { |
| 9991 | DEBUG_PRINT_ERROR("Set Resolution failed for adaptive playback"); |
| 9992 | return OMX_ErrorUnsupportedSetting; |
| 9993 | } |
| 9994 | |
| 9995 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9996 | if (eRet != OMX_ErrorNone) { |
| 9997 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!"); |
| 9998 | return eRet; |
| 9999 | } |
| 10000 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer size = %u", |
| 10001 | drv_ctx.op_buf.buffer_size); |
| 10002 | |
| 10003 | drv_ctx.op_buf.mincount = min_res_buf_count; |
| 10004 | drv_ctx.op_buf.actualcount = min_res_buf_count; |
| 10005 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 10006 | if (eRet != OMX_ErrorNone) { |
| 10007 | DEBUG_PRINT_ERROR("failed to set_buffer_req"); |
| 10008 | return eRet; |
| 10009 | } |
| 10010 | |
| 10011 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 10012 | if (eRet != OMX_ErrorNone) { |
| 10013 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!!"); |
| 10014 | return eRet; |
| 10015 | } |
| 10016 | DEBUG_PRINT_HIGH("adaptive playback enabled, buf count = %u bufsize = %u", |
| 10017 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size); |
| 10018 | return eRet; |
| 10019 | } |
| 10020 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 10021 | #ifdef _MSM8974_ |
| 10022 | void omx_vdec::send_codec_config() { |
| 10023 | if (codec_config_flag) { |
| 10024 | unsigned p1 = 0; // Parameter - 1 |
| 10025 | unsigned p2 = 0; // Parameter - 2 |
| 10026 | unsigned ident = 0; |
| 10027 | pthread_mutex_lock(&m_lock); |
| 10028 | DEBUG_PRINT_LOW("\n Check Queue for codec_config buffer \n"); |
| 10029 | while (m_etb_q.m_size) { |
| 10030 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 10031 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 10032 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 10033 | if (empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 10034 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 10035 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy_arbitrary failure"); |
| 10036 | omx_report_error(); |
| 10037 | } |
| 10038 | } else { |
| 10039 | DEBUG_PRINT_LOW("\n Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
| 10040 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 10041 | } |
| 10042 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 10043 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 10044 | if (empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 10045 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 10046 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy failure"); |
| 10047 | omx_report_error (); |
| 10048 | } |
| 10049 | } else { |
| 10050 | pending_input_buffers++; |
| 10051 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d", |
| 10052 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 10053 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 10054 | } |
| 10055 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 10056 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
| 10057 | (OMX_BUFFERHEADERTYPE *)p1); |
| 10058 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 10059 | } |
| 10060 | } |
| 10061 | pthread_mutex_unlock(&m_lock); |
| 10062 | } |
| 10063 | } |
| 10064 | #endif |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 10065 | |
| 10066 | //static |
| 10067 | OMX_ERRORTYPE omx_vdec::describeColorFormat(OMX_PTR pParam) { |
| 10068 | |
| 10069 | #ifndef FLEXYUV_SUPPORTED |
| 10070 | (void)pParam; |
| 10071 | return OMX_ErrorUndefined; |
| 10072 | #else |
| 10073 | |
| 10074 | if (pParam == NULL) { |
| 10075 | DEBUG_PRINT_ERROR("describeColorFormat: invalid params"); |
| 10076 | return OMX_ErrorBadParameter; |
| 10077 | } |
| 10078 | |
| 10079 | DescribeColorFormatParams *params = (DescribeColorFormatParams*)pParam; |
| 10080 | |
| 10081 | MediaImage *img = &(params->sMediaImage); |
| 10082 | switch(params->eColorFormat) { |
| 10083 | case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m: |
| 10084 | { |
| 10085 | img->mType = MediaImage::MEDIA_IMAGE_TYPE_YUV; |
| 10086 | img->mNumPlanes = 3; |
| 10087 | // mWidth and mHeight represent the W x H of the largest plane |
| 10088 | // In our case, this happens to be the Stride x Scanlines of Y plane |
| 10089 | img->mWidth = params->nFrameWidth; |
| 10090 | img->mHeight = params->nFrameHeight; |
| 10091 | size_t planeWidth = VENUS_Y_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10092 | size_t planeHeight = VENUS_Y_SCANLINES(COLOR_FMT_NV12, params->nFrameHeight); |
| 10093 | img->mBitDepth = 8; |
| 10094 | //Plane 0 (Y) |
| 10095 | img->mPlane[MediaImage::Y].mOffset = 0; |
| 10096 | img->mPlane[MediaImage::Y].mColInc = 1; |
| 10097 | img->mPlane[MediaImage::Y].mRowInc = planeWidth; //same as stride |
| 10098 | img->mPlane[MediaImage::Y].mHorizSubsampling = 1; |
| 10099 | img->mPlane[MediaImage::Y].mVertSubsampling = 1; |
| 10100 | //Plane 1 (U) |
| 10101 | img->mPlane[MediaImage::U].mOffset = planeWidth * planeHeight; |
| 10102 | img->mPlane[MediaImage::U].mColInc = 2; //interleaved UV |
| 10103 | img->mPlane[MediaImage::U].mRowInc = |
| 10104 | VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10105 | img->mPlane[MediaImage::U].mHorizSubsampling = 2; |
| 10106 | img->mPlane[MediaImage::U].mVertSubsampling = 2; |
| 10107 | //Plane 2 (V) |
| 10108 | img->mPlane[MediaImage::V].mOffset = planeWidth * planeHeight + 1; |
| 10109 | img->mPlane[MediaImage::V].mColInc = 2; //interleaved UV |
| 10110 | img->mPlane[MediaImage::V].mRowInc = |
| 10111 | VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10112 | img->mPlane[MediaImage::V].mHorizSubsampling = 2; |
| 10113 | img->mPlane[MediaImage::V].mVertSubsampling = 2; |
| 10114 | break; |
| 10115 | } |
| 10116 | |
| 10117 | case OMX_COLOR_FormatYUV420Planar: |
| 10118 | case OMX_COLOR_FormatYUV420SemiPlanar: |
| 10119 | // We need not describe the standard OMX linear formats as these are |
| 10120 | // understood by client. Fail this deliberately to let client fill-in |
| 10121 | return OMX_ErrorUnsupportedSetting; |
| 10122 | |
| 10123 | default: |
| 10124 | // Rest all formats which are non-linear cannot be described |
| 10125 | DEBUG_PRINT_LOW("color-format %x is not flexible", params->eColorFormat); |
| 10126 | img->mType = MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN; |
| 10127 | return OMX_ErrorNone; |
| 10128 | }; |
| 10129 | |
| 10130 | DEBUG_PRINT_LOW("NOTE: Describe color format : %x", params->eColorFormat); |
| 10131 | DEBUG_PRINT_LOW(" FrameWidth x FrameHeight : %d x %d", params->nFrameWidth, params->nFrameHeight); |
| 10132 | DEBUG_PRINT_LOW(" YWidth x YHeight : %d x %d", img->mWidth, img->mHeight); |
| 10133 | for (size_t i = 0; i < img->mNumPlanes; ++i) { |
| 10134 | DEBUG_PRINT_LOW(" Plane[%d] : offset=%d / xStep=%d / yStep = %d", |
| 10135 | i, img->mPlane[i].mOffset, img->mPlane[i].mColInc, img->mPlane[i].mRowInc); |
| 10136 | } |
| 10137 | return OMX_ErrorNone; |
| 10138 | #endif //FLEXYUV_SUPPORTED |
| 10139 | } |
| 10140 | |