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 | |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 70 | #ifdef METADATA_FOR_DYNAMIC_MODE |
Arun Menon | 9af783f | 2013-10-22 12:57:14 -0700 | [diff] [blame] | 71 | #include "QComOMXMetadata.h" |
| 72 | #endif |
| 73 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 74 | #ifdef USE_EGL_IMAGE_GPU |
| 75 | #include <EGL/egl.h> |
| 76 | #include <EGL/eglQCOM.h> |
| 77 | #define EGL_BUFFER_HANDLE_QCOM 0x4F00 |
| 78 | #define EGL_BUFFER_OFFSET_QCOM 0x4F01 |
| 79 | #endif |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 80 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 81 | #define BUFFER_LOG_LOC "/data/misc/media" |
| 82 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 83 | #ifdef OUTPUT_EXTRADATA_LOG |
| 84 | FILE *outputExtradataFile; |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 85 | char output_extradata_filename [] = "/data/misc/extradata"; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 86 | #endif |
| 87 | |
| 88 | #define DEFAULT_FPS 30 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 89 | #define MAX_SUPPORTED_FPS 120 |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 90 | #define DEFAULT_WIDTH_ALIGNMENT 128 |
| 91 | #define DEFAULT_HEIGHT_ALIGNMENT 32 |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 92 | |
| 93 | #define VC1_SP_MP_START_CODE 0xC5000000 |
| 94 | #define VC1_SP_MP_START_CODE_MASK 0xFF000000 |
| 95 | #define VC1_AP_SEQ_START_CODE 0x0F010000 |
| 96 | #define VC1_STRUCT_C_PROFILE_MASK 0xF0 |
| 97 | #define VC1_STRUCT_B_LEVEL_MASK 0xE0000000 |
| 98 | #define VC1_SIMPLE_PROFILE 0 |
| 99 | #define VC1_MAIN_PROFILE 1 |
| 100 | #define VC1_ADVANCE_PROFILE 3 |
| 101 | #define VC1_SIMPLE_PROFILE_LOW_LEVEL 0 |
| 102 | #define VC1_SIMPLE_PROFILE_MED_LEVEL 2 |
| 103 | #define VC1_STRUCT_C_LEN 4 |
| 104 | #define VC1_STRUCT_C_POS 8 |
| 105 | #define VC1_STRUCT_A_POS 12 |
| 106 | #define VC1_STRUCT_B_POS 24 |
| 107 | #define VC1_SEQ_LAYER_SIZE 36 |
Vinay Kalia | b09886c | 2012-08-20 11:27:25 -0700 | [diff] [blame] | 108 | #define POLL_TIMEOUT 0x7fffffff |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 109 | |
| 110 | #define MEM_DEVICE "/dev/ion" |
| 111 | #define MEM_HEAP_ID ION_CP_MM_HEAP_ID |
| 112 | |
| 113 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 114 | extern "C" { |
| 115 | #include<utils/Log.h> |
| 116 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 117 | #endif//_ANDROID_ |
| 118 | |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 119 | #define SZ_4K 0x1000 |
| 120 | #define SZ_1M 0x100000 |
| 121 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 122 | #define Log2(number, power) { OMX_U32 temp = number; power = 0; while( (0 == (temp & 0x1)) && power < 16) { temp >>=0x1; power++; } } |
| 123 | #define Q16ToFraction(q,num,den) { OMX_U32 power; Log2(q,power); num = q >> power; den = 0x1 << (16 - power); } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 124 | #define EXTRADATA_IDX(__num_planes) (__num_planes - 1) |
Maheshwar Ajja | 77cd19c | 2014-06-05 11:23:18 +0530 | [diff] [blame] | 125 | #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] | 126 | |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 127 | #define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA) |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 128 | #define DEFAULT_CONCEAL_COLOR "32896" //0x8080, black by default |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 129 | |
| 130 | int debug_level = PRIO_ERROR; |
| 131 | |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 132 | static OMX_U32 maxSmoothStreamingWidth = 1920; |
| 133 | static OMX_U32 maxSmoothStreamingHeight = 1088; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 134 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 135 | void* async_message_thread (void *input) |
| 136 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 137 | OMX_BUFFERHEADERTYPE *buffer; |
| 138 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 139 | struct pollfd pfd; |
| 140 | struct v4l2_buffer v4l2_buf; |
| 141 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 142 | struct v4l2_event dqevent; |
| 143 | omx_vdec *omx = reinterpret_cast<omx_vdec*>(input); |
| 144 | pfd.events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLRDBAND | POLLPRI; |
| 145 | pfd.fd = omx->drv_ctx.video_driver_fd; |
| 146 | int error_code = 0,rc=0,bytes_read = 0,bytes_written = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 147 | DEBUG_PRINT_HIGH("omx_vdec: Async thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 148 | prctl(PR_SET_NAME, (unsigned long)"VideoDecCallBackThread", 0, 0, 0); |
| 149 | while (1) { |
| 150 | rc = poll(&pfd, 1, POLL_TIMEOUT); |
| 151 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 152 | DEBUG_PRINT_ERROR("Poll timedout"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 153 | break; |
Deepak Kushwah | 4193f60 | 2015-11-17 15:45:22 +0530 | [diff] [blame] | 154 | } else if (rc < 0 && errno != EINTR && errno != EAGAIN) { |
| 155 | DEBUG_PRINT_ERROR("Error while polling: %d, errno = %d", rc, errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 156 | break; |
| 157 | } |
| 158 | if ((pfd.revents & POLLIN) || (pfd.revents & POLLRDNORM)) { |
| 159 | struct vdec_msginfo vdec_msg; |
| 160 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 161 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 162 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 163 | v4l2_buf.m.planes = plane; |
| 164 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 165 | vdec_msg.msgcode=VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 166 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 167 | vdec_msg.msgdata.output_frame.client_data=(void*)&v4l2_buf; |
| 168 | vdec_msg.msgdata.output_frame.len=plane[0].bytesused; |
| 169 | vdec_msg.msgdata.output_frame.bufferaddr=(void*)plane[0].m.userptr; |
| 170 | vdec_msg.msgdata.output_frame.time_stamp= ((uint64_t)v4l2_buf.timestamp.tv_sec * (uint64_t)1000000) + |
| 171 | (uint64_t)v4l2_buf.timestamp.tv_usec; |
| 172 | if (vdec_msg.msgdata.output_frame.len) { |
| 173 | vdec_msg.msgdata.output_frame.framesize.left = plane[0].reserved[2]; |
| 174 | vdec_msg.msgdata.output_frame.framesize.top = plane[0].reserved[3]; |
| 175 | vdec_msg.msgdata.output_frame.framesize.right = plane[0].reserved[4]; |
| 176 | vdec_msg.msgdata.output_frame.framesize.bottom = plane[0].reserved[5]; |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 177 | vdec_msg.msgdata.output_frame.picsize.frame_width = plane[0].reserved[6]; |
| 178 | vdec_msg.msgdata.output_frame.picsize.frame_height = plane[0].reserved[7]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 179 | } |
| 180 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 181 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 182 | break; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | if ((pfd.revents & POLLOUT) || (pfd.revents & POLLWRNORM)) { |
| 187 | struct vdec_msginfo vdec_msg; |
| 188 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 189 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 190 | v4l2_buf.length = 1; |
| 191 | v4l2_buf.m.planes = plane; |
| 192 | while (!ioctl(pfd.fd, VIDIOC_DQBUF, &v4l2_buf)) { |
| 193 | vdec_msg.msgcode=VDEC_MSG_RESP_INPUT_BUFFER_DONE; |
| 194 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 195 | vdec_msg.msgdata.input_frame_clientdata=(void*)&v4l2_buf; |
| 196 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 197 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 198 | break; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | if (pfd.revents & POLLPRI) { |
| 203 | rc = ioctl(pfd.fd, VIDIOC_DQEVENT, &dqevent); |
| 204 | if (dqevent.type == V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT ) { |
| 205 | struct vdec_msginfo vdec_msg; |
| 206 | vdec_msg.msgcode=VDEC_MSG_EVT_CONFIG_CHANGED; |
| 207 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 208 | DEBUG_PRINT_HIGH("VIDC Port Reconfig recieved insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 209 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 210 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 211 | break; |
| 212 | } |
| 213 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_FLUSH_DONE) { |
| 214 | struct vdec_msginfo vdec_msg; |
| 215 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_INPUT_DONE; |
| 216 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 217 | DEBUG_PRINT_HIGH("VIDC Input Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 218 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 219 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | vdec_msg.msgcode=VDEC_MSG_RESP_FLUSH_OUTPUT_DONE; |
| 223 | vdec_msg.status_code=VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 224 | DEBUG_PRINT_HIGH("VIDC Output Flush Done Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 225 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 226 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 227 | break; |
| 228 | } |
| 229 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_CLOSE_DONE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 230 | DEBUG_PRINT_HIGH("VIDC Close Done Recieved and async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 231 | break; |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 232 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_HW_OVERLOAD) { |
| 233 | struct vdec_msginfo vdec_msg; |
| 234 | vdec_msg.msgcode=VDEC_MSG_EVT_HW_OVERLOAD; |
| 235 | vdec_msg.status_code=VDEC_S_SUCCESS; |
| 236 | DEBUG_PRINT_ERROR("HW Overload received"); |
| 237 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
| 238 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
| 239 | break; |
| 240 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 241 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_SYS_ERROR) { |
| 242 | struct vdec_msginfo vdec_msg; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 243 | vdec_msg.msgcode = VDEC_MSG_EVT_HW_ERROR; |
| 244 | vdec_msg.status_code = VDEC_S_SUCCESS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 245 | DEBUG_PRINT_HIGH("SYS Error Recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 246 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 247 | DEBUG_PRINT_HIGH("async_message_thread Exited"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 248 | break; |
| 249 | } |
Arun Menon | 4534605 | 2013-11-13 12:40:08 -0800 | [diff] [blame] | 250 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE) { |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 251 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 252 | DEBUG_PRINT_LOW("REFERENCE RELEASE EVENT RECVD fd = %d offset = %d", ptr[0], ptr[1]); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 253 | omx->buf_ref_remove(ptr[0], ptr[1]); |
| 254 | } else if (dqevent.type == V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER) { |
| 255 | unsigned int *ptr = (unsigned int *)dqevent.u.data; |
| 256 | struct vdec_msginfo vdec_msg; |
| 257 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 258 | DEBUG_PRINT_LOW("Release unqueued buffer event recvd fd = %d offset = %d", ptr[0], ptr[1]); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 259 | |
| 260 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 261 | v4l2_buf.memory = V4L2_MEMORY_USERPTR; |
| 262 | v4l2_buf.length = omx->drv_ctx.num_planes; |
| 263 | v4l2_buf.m.planes = plane; |
| 264 | v4l2_buf.index = ptr[5]; |
| 265 | v4l2_buf.flags = 0; |
| 266 | |
| 267 | vdec_msg.msgcode = VDEC_MSG_RESP_OUTPUT_BUFFER_DONE; |
| 268 | vdec_msg.status_code = VDEC_S_SUCCESS; |
| 269 | vdec_msg.msgdata.output_frame.client_data = (void*)&v4l2_buf; |
| 270 | vdec_msg.msgdata.output_frame.len = 0; |
| 271 | vdec_msg.msgdata.output_frame.bufferaddr = (void*)ptr[2]; |
| 272 | vdec_msg.msgdata.output_frame.time_stamp = ((uint64_t)ptr[3] * (uint64_t)1000000) + |
| 273 | (uint64_t)ptr[4]; |
| 274 | if (omx->async_message_process(input,&vdec_msg) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 275 | DEBUG_PRINT_HIGH("async_message_thread Exitedn"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 276 | break; |
| 277 | } |
| 278 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 279 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 280 | DEBUG_PRINT_HIGH("VIDC Some Event recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 281 | continue; |
| 282 | } |
| 283 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 284 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 285 | DEBUG_PRINT_HIGH("omx_vdec: Async thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 286 | return NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Ashray Kulkarni | a97efbc | 2015-07-15 18:17:23 -0700 | [diff] [blame] | 289 | void* dec_message_thread(void *input) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 290 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 291 | omx_vdec* omx = reinterpret_cast<omx_vdec*>(input); |
| 292 | unsigned char id; |
| 293 | int n; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 294 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 295 | DEBUG_PRINT_HIGH("omx_vdec: message thread start"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 296 | prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0); |
| 297 | while (1) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 298 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 299 | n = read(omx->m_pipe_in, &id, 1); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 300 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 301 | if (0 == n) { |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | if (1 == n) { |
| 306 | omx->process_event_cb(omx, id); |
| 307 | } |
| 308 | if ((n < 0) && (errno != EINTR)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 309 | DEBUG_PRINT_LOW("ERROR: read from pipe failed, ret %d errno %d", n, errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 310 | break; |
| 311 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 312 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 313 | DEBUG_PRINT_HIGH("omx_vdec: message thread stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 314 | return 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void post_message(omx_vdec *omx, unsigned char id) |
| 318 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 319 | int ret_value; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 320 | DEBUG_PRINT_LOW("omx_vdec: post_message %d pipe out%d", id,omx->m_pipe_out); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 321 | ret_value = write(omx->m_pipe_out, &id, 1); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 322 | DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // omx_cmd_queue destructor |
| 326 | omx_vdec::omx_cmd_queue::~omx_cmd_queue() |
| 327 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 328 | // Nothing to do |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | // omx cmd queue constructor |
| 332 | omx_vdec::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0) |
| 333 | { |
| 334 | memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE); |
| 335 | } |
| 336 | |
| 337 | // omx cmd queue insert |
| 338 | bool omx_vdec::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id) |
| 339 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 340 | bool ret = true; |
| 341 | if (m_size < OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 342 | m_q[m_write].id = id; |
| 343 | m_q[m_write].param1 = p1; |
| 344 | m_q[m_write].param2 = p2; |
| 345 | m_write++; |
| 346 | m_size ++; |
| 347 | if (m_write >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 348 | m_write = 0; |
| 349 | } |
| 350 | } else { |
| 351 | ret = false; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 352 | DEBUG_PRINT_ERROR("ERROR: %s()::Command Queue Full", __func__); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 353 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 354 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | // omx cmd queue pop |
| 358 | bool omx_vdec::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id) |
| 359 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 360 | bool ret = true; |
| 361 | if (m_size > 0) { |
| 362 | *id = m_q[m_read].id; |
| 363 | *p1 = m_q[m_read].param1; |
| 364 | *p2 = m_q[m_read].param2; |
| 365 | // Move the read pointer ahead |
| 366 | ++m_read; |
| 367 | --m_size; |
| 368 | if (m_read >= OMX_CORE_CONTROL_CMDQ_SIZE) { |
| 369 | m_read = 0; |
| 370 | } |
| 371 | } else { |
| 372 | ret = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 373 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 374 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // Retrieve the first mesg type in the queue |
| 378 | unsigned omx_vdec::omx_cmd_queue::get_q_msg_type() |
| 379 | { |
| 380 | return m_q[m_read].id; |
| 381 | } |
| 382 | |
| 383 | #ifdef _ANDROID_ |
| 384 | omx_vdec::ts_arr_list::ts_arr_list() |
| 385 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 386 | //initialize timestamps array |
| 387 | memset(m_ts_arr_list, 0, ( sizeof(ts_entry) * MAX_NUM_INPUT_OUTPUT_BUFFERS) ); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 388 | } |
| 389 | omx_vdec::ts_arr_list::~ts_arr_list() |
| 390 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 391 | //free m_ts_arr_list? |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | bool omx_vdec::ts_arr_list::insert_ts(OMX_TICKS ts) |
| 395 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 396 | bool ret = true; |
| 397 | bool duplicate_ts = false; |
| 398 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 399 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 400 | //insert at the first available empty location |
| 401 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 402 | if (!m_ts_arr_list[idx].valid) { |
| 403 | //found invalid or empty entry, save timestamp |
| 404 | m_ts_arr_list[idx].valid = true; |
| 405 | m_ts_arr_list[idx].timestamp = ts; |
| 406 | DEBUG_PRINT_LOW("Insert_ts(): Inserting TIMESTAMP (%lld) at idx (%d)", |
| 407 | ts, idx); |
| 408 | break; |
| 409 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 410 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 411 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 412 | if (idx == MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 413 | DEBUG_PRINT_LOW("Timestamp array list is FULL. Unsuccessful insert"); |
| 414 | ret = false; |
| 415 | } |
| 416 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | bool omx_vdec::ts_arr_list::pop_min_ts(OMX_TICKS &ts) |
| 420 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 421 | bool ret = true; |
| 422 | int min_idx = -1; |
| 423 | OMX_TICKS min_ts = 0; |
| 424 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 425 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 426 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 427 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 428 | if (m_ts_arr_list[idx].valid) { |
| 429 | //found valid entry, save index |
| 430 | if (min_idx < 0) { |
| 431 | //first valid entry |
| 432 | min_ts = m_ts_arr_list[idx].timestamp; |
| 433 | min_idx = idx; |
| 434 | } else if (m_ts_arr_list[idx].timestamp < min_ts) { |
| 435 | min_ts = m_ts_arr_list[idx].timestamp; |
| 436 | min_idx = idx; |
| 437 | } |
| 438 | } |
| 439 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 442 | if (min_idx < 0) { |
| 443 | //no valid entries found |
| 444 | DEBUG_PRINT_LOW("Timestamp array list is empty. Unsuccessful pop"); |
| 445 | ts = 0; |
| 446 | ret = false; |
| 447 | } else { |
| 448 | ts = m_ts_arr_list[min_idx].timestamp; |
| 449 | m_ts_arr_list[min_idx].valid = false; |
| 450 | DEBUG_PRINT_LOW("Pop_min_ts:Timestamp (%lld), index(%d)", |
| 451 | ts, min_idx); |
| 452 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 453 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 454 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 455 | |
| 456 | } |
| 457 | |
| 458 | |
| 459 | bool omx_vdec::ts_arr_list::reset_ts_list() |
| 460 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 461 | bool ret = true; |
| 462 | int idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 463 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 464 | DEBUG_PRINT_LOW("reset_ts_list(): Resetting timestamp array list"); |
| 465 | for ( ; idx < MAX_NUM_INPUT_OUTPUT_BUFFERS; idx++) { |
| 466 | m_ts_arr_list[idx].valid = false; |
| 467 | } |
| 468 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 469 | } |
| 470 | #endif |
| 471 | |
| 472 | // factory function executed by the core to create instances |
| 473 | void *get_omx_component_factory_fn(void) |
| 474 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 475 | return (new omx_vdec); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | #ifdef _ANDROID_ |
| 479 | #ifdef USE_ION |
| 480 | VideoHeap::VideoHeap(int devicefd, size_t size, void* base, |
Mitchel Humpherys | 2294c23 | 2013-12-10 12:14:04 -0800 | [diff] [blame] | 481 | ion_user_handle_t handle, int ionMapfd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 482 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 483 | // ionInit(devicefd, base, size, 0 , MEM_DEVICE,handle,ionMapfd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 484 | } |
| 485 | #else |
| 486 | VideoHeap::VideoHeap(int fd, size_t size, void* base) |
| 487 | { |
| 488 | // dup file descriptor, map once, use pmem |
| 489 | init(dup(fd), base, size, 0 , MEM_DEVICE); |
| 490 | } |
| 491 | #endif |
| 492 | #endif // _ANDROID_ |
| 493 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 494 | FUNCTION |
| 495 | omx_vdec::omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 496 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 497 | DESCRIPTION |
| 498 | Constructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 499 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 500 | PARAMETERS |
| 501 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 502 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 503 | RETURN VALUE |
| 504 | None. |
| 505 | ========================================================================== */ |
Deva Ramasubramanian | 5c24124 | 2013-02-19 17:25:30 -0800 | [diff] [blame] | 506 | omx_vdec::omx_vdec(): m_error_propogated(false), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 507 | m_state(OMX_StateInvalid), |
| 508 | m_app_data(NULL), |
| 509 | m_inp_mem_ptr(NULL), |
| 510 | m_out_mem_ptr(NULL), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 511 | input_flush_progress (false), |
| 512 | output_flush_progress (false), |
| 513 | input_use_buffer (false), |
| 514 | output_use_buffer (false), |
| 515 | ouput_egl_buffers(false), |
| 516 | m_use_output_pmem(OMX_FALSE), |
| 517 | m_out_mem_region_smi(OMX_FALSE), |
| 518 | m_out_pvt_entry_pmem(OMX_FALSE), |
| 519 | pending_input_buffers(0), |
| 520 | pending_output_buffers(0), |
| 521 | m_out_bm_count(0), |
| 522 | m_inp_bm_count(0), |
| 523 | m_inp_bPopulated(OMX_FALSE), |
| 524 | m_out_bPopulated(OMX_FALSE), |
| 525 | m_flags(0), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 526 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 527 | m_heap_ptr(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 528 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 529 | m_inp_bEnabled(OMX_TRUE), |
| 530 | m_out_bEnabled(OMX_TRUE), |
| 531 | m_in_alloc_cnt(0), |
| 532 | m_platform_list(NULL), |
| 533 | m_platform_entry(NULL), |
| 534 | m_pmem_info(NULL), |
| 535 | arbitrary_bytes (true), |
| 536 | psource_frame (NULL), |
| 537 | pdest_frame (NULL), |
| 538 | m_inp_heap_ptr (NULL), |
| 539 | m_phdr_pmem_ptr(NULL), |
| 540 | m_heap_inp_bm_count (0), |
| 541 | codec_type_parse ((codec_type)0), |
| 542 | first_frame_meta (true), |
| 543 | frame_count (0), |
| 544 | nal_count (0), |
| 545 | nal_length(0), |
| 546 | look_ahead_nal (false), |
| 547 | first_frame(0), |
| 548 | first_buffer(NULL), |
| 549 | first_frame_size (0), |
| 550 | m_device_file_ptr(NULL), |
| 551 | m_vc1_profile((vc1_profile_type)0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 552 | h264_last_au_ts(LLONG_MAX), |
| 553 | h264_last_au_flags(0), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 554 | m_disp_hor_size(0), |
| 555 | m_disp_vert_size(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 556 | prev_ts(LLONG_MAX), |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 557 | prev_ts_actual(LLONG_MAX), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 558 | rst_prev_ts(true), |
| 559 | frm_int(0), |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 560 | in_reconfig(false), |
| 561 | m_display_id(NULL), |
| 562 | h264_parser(NULL), |
| 563 | client_extradata(0), |
| 564 | m_reject_avc_1080p_mp (0), |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 565 | m_other_extradata(NULL), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 566 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 567 | m_enable_android_native_buffers(OMX_FALSE), |
| 568 | m_use_android_native_buffers(OMX_FALSE), |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 569 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 570 | m_desc_buffer_ptr(NULL), |
| 571 | secure_mode(false), |
Praveen Chavan | d443c0d | 2016-04-19 12:25:46 -0700 | [diff] [blame] | 572 | allocate_native_handle(false), |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 573 | m_profile(0), |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 574 | client_set_fps(false), |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 575 | m_last_rendered_TS(-1), |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 576 | m_queued_codec_config_count(0), |
| 577 | m_buffer_error(false) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 578 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 579 | /* Assumption is that , to begin with , we have all the frames with decoder */ |
| 580 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 581 | memset(&m_debug,0,sizeof(m_debug)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 582 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 583 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Jayasena Sangaraboina | c4dfc28 | 2013-08-08 12:41:39 -0700 | [diff] [blame] | 584 | property_get("vidc.debug.level", property_value, "0"); |
| 585 | debug_level = atoi(property_value); |
| 586 | property_value[0] = '\0'; |
| 587 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 588 | DEBUG_PRINT_HIGH("In OMX vdec Constructor"); |
| 589 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 590 | property_get("vidc.dec.debug.perf", property_value, "0"); |
| 591 | perf_flag = atoi(property_value); |
| 592 | if (perf_flag) { |
| 593 | DEBUG_PRINT_HIGH("vidc.dec.debug.perf is %d", perf_flag); |
| 594 | dec_time.start(); |
| 595 | proc_frms = latency = 0; |
| 596 | } |
| 597 | prev_n_filled_len = 0; |
| 598 | property_value[0] = '\0'; |
| 599 | property_get("vidc.dec.debug.ts", property_value, "0"); |
| 600 | m_debug_timestamp = atoi(property_value); |
| 601 | DEBUG_PRINT_HIGH("vidc.dec.debug.ts value is %d",m_debug_timestamp); |
| 602 | if (m_debug_timestamp) { |
| 603 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 604 | time_stamp_dts.enable_debug_print(true); |
| 605 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 606 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 607 | property_value[0] = '\0'; |
| 608 | property_get("vidc.dec.debug.concealedmb", property_value, "0"); |
| 609 | m_debug_concealedmb = atoi(property_value); |
| 610 | DEBUG_PRINT_HIGH("vidc.dec.debug.concealedmb value is %d",m_debug_concealedmb); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 611 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 612 | property_value[0] = '\0'; |
| 613 | property_get("vidc.dec.profile.check", property_value, "0"); |
| 614 | m_reject_avc_1080p_mp = atoi(property_value); |
| 615 | DEBUG_PRINT_HIGH("vidc.dec.profile.check value is %d",m_reject_avc_1080p_mp); |
Rajeshwar Kurapaty | e0e7d0c | 2013-07-30 19:46:26 +0530 | [diff] [blame] | 616 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 617 | property_value[0] = '\0'; |
| 618 | property_get("vidc.dec.log.in", property_value, "0"); |
| 619 | m_debug.in_buffer_log = atoi(property_value); |
| 620 | |
| 621 | property_value[0] = '\0'; |
| 622 | property_get("vidc.dec.log.out", property_value, "0"); |
| 623 | m_debug.out_buffer_log = atoi(property_value); |
| 624 | sprintf(m_debug.log_loc, "%s", BUFFER_LOG_LOC); |
| 625 | |
| 626 | property_value[0] = '\0'; |
| 627 | property_get("vidc.log.loc", property_value, ""); |
| 628 | if (*property_value) |
| 629 | strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 630 | |
| 631 | property_value[0] = '\0'; |
| 632 | property_get("vidc.dec.120fps.enabled", property_value, "0"); |
| 633 | |
| 634 | //if this feature is not enabled then reset this value -ve |
| 635 | if(atoi(property_value)) { |
| 636 | DEBUG_PRINT_LOW("feature 120 FPS decode enabled"); |
| 637 | m_last_rendered_TS = 0; |
| 638 | } |
| 639 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 640 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 641 | memset(&m_cmp,0,sizeof(m_cmp)); |
| 642 | memset(&m_cb,0,sizeof(m_cb)); |
| 643 | memset (&drv_ctx,0,sizeof(drv_ctx)); |
| 644 | memset (&h264_scratch,0,sizeof (OMX_BUFFERHEADERTYPE)); |
| 645 | memset (m_hwdevice_name,0,sizeof(m_hwdevice_name)); |
| 646 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 647 | memset(&m_custom_buffersize, 0, sizeof(m_custom_buffersize)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 648 | m_demux_entries = 0; |
| 649 | msg_thread_id = 0; |
| 650 | async_thread_id = 0; |
| 651 | msg_thread_created = false; |
| 652 | async_thread_created = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 653 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 654 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 655 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 656 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 657 | memset(&m_frame_pack_arrangement, 0, sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 658 | drv_ctx.timestamp_adjust = false; |
| 659 | drv_ctx.video_driver_fd = -1; |
| 660 | m_vendor_config.pData = NULL; |
| 661 | pthread_mutex_init(&m_lock, NULL); |
| 662 | pthread_mutex_init(&c_lock, NULL); |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 663 | pthread_mutex_init(&buf_lock, NULL); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 664 | sem_init(&m_cmd_lock,0,0); |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 665 | sem_init(&m_safe_flush, 0, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 666 | streaming[CAPTURE_PORT] = |
| 667 | streaming[OUTPUT_PORT] = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 668 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 669 | char extradata_value[PROPERTY_VALUE_MAX] = {0}; |
| 670 | property_get("vidc.dec.debug.extradata", extradata_value, "0"); |
| 671 | m_debug_extradata = atoi(extradata_value); |
| 672 | DEBUG_PRINT_HIGH("vidc.dec.debug.extradata value is %d",m_debug_extradata); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 673 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 674 | m_fill_output_msg = OMX_COMPONENT_GENERATE_FTB; |
| 675 | client_buffers.set_vdec_client(this); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 676 | dynamic_buf_mode = false; |
| 677 | out_dynamic_list = NULL; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 678 | is_down_scalar_enabled = false; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 679 | m_smoothstreaming_mode = false; |
| 680 | m_smoothstreaming_width = 0; |
| 681 | m_smoothstreaming_height = 0; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 682 | is_q6_platform = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 685 | static const int event_type[] = { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 686 | V4L2_EVENT_MSM_VIDC_FLUSH_DONE, |
| 687 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_SUFFICIENT, |
| 688 | V4L2_EVENT_MSM_VIDC_PORT_SETTINGS_CHANGED_INSUFFICIENT, |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 689 | V4L2_EVENT_MSM_VIDC_RELEASE_BUFFER_REFERENCE, |
| 690 | V4L2_EVENT_MSM_VIDC_RELEASE_UNQUEUED_BUFFER, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 691 | V4L2_EVENT_MSM_VIDC_CLOSE_DONE, |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 692 | V4L2_EVENT_MSM_VIDC_SYS_ERROR, |
| 693 | V4L2_EVENT_MSM_VIDC_HW_OVERLOAD |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 694 | }; |
| 695 | |
| 696 | static OMX_ERRORTYPE subscribe_to_events(int fd) |
| 697 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 698 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 699 | struct v4l2_event_subscription sub; |
| 700 | int array_sz = sizeof(event_type)/sizeof(int); |
| 701 | int i,rc; |
| 702 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 703 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 704 | return OMX_ErrorBadParameter; |
| 705 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 706 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 707 | for (i = 0; i < array_sz; ++i) { |
| 708 | memset(&sub, 0, sizeof(sub)); |
| 709 | sub.type = event_type[i]; |
| 710 | rc = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub); |
| 711 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 712 | DEBUG_PRINT_ERROR("Failed to subscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 713 | break; |
| 714 | } |
| 715 | } |
| 716 | if (i < array_sz) { |
| 717 | for (--i; i >=0 ; i--) { |
| 718 | memset(&sub, 0, sizeof(sub)); |
| 719 | sub.type = event_type[i]; |
| 720 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 721 | if (rc) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 722 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 723 | } |
| 724 | eRet = OMX_ErrorNotImplemented; |
| 725 | } |
| 726 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | static OMX_ERRORTYPE unsubscribe_to_events(int fd) |
| 731 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 732 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 733 | struct v4l2_event_subscription sub; |
| 734 | int array_sz = sizeof(event_type)/sizeof(int); |
| 735 | int i,rc; |
| 736 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 737 | DEBUG_PRINT_ERROR("Invalid input: %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 738 | return OMX_ErrorBadParameter; |
| 739 | } |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 740 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 741 | for (i = 0; i < array_sz; ++i) { |
| 742 | memset(&sub, 0, sizeof(sub)); |
| 743 | sub.type = event_type[i]; |
| 744 | rc = ioctl(fd, VIDIOC_UNSUBSCRIBE_EVENT, &sub); |
| 745 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 746 | DEBUG_PRINT_ERROR("Failed to unsubscribe event: 0x%x", sub.type); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | } |
| 750 | return eRet; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 751 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 752 | |
| 753 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 754 | FUNCTION |
| 755 | omx_vdec::~omx_vdec |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 756 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 757 | DESCRIPTION |
| 758 | Destructor |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 759 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 760 | PARAMETERS |
| 761 | None |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 762 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 763 | RETURN VALUE |
| 764 | None. |
| 765 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 766 | omx_vdec::~omx_vdec() |
| 767 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 768 | m_pmem_info = NULL; |
| 769 | struct v4l2_decoder_cmd dec; |
| 770 | DEBUG_PRINT_HIGH("In OMX vdec Destructor"); |
| 771 | if (m_pipe_in) close(m_pipe_in); |
| 772 | if (m_pipe_out) close(m_pipe_out); |
| 773 | m_pipe_in = -1; |
| 774 | m_pipe_out = -1; |
| 775 | DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit"); |
| 776 | if (msg_thread_created) |
| 777 | pthread_join(msg_thread_id,NULL); |
| 778 | DEBUG_PRINT_HIGH("Waiting on OMX Async Thread exit"); |
| 779 | dec.cmd = V4L2_DEC_CMD_STOP; |
| 780 | if (drv_ctx.video_driver_fd >=0 ) { |
| 781 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 782 | DEBUG_PRINT_ERROR("STOP Command failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 783 | } |
| 784 | if (async_thread_created) |
| 785 | pthread_join(async_thread_id,NULL); |
| 786 | unsubscribe_to_events(drv_ctx.video_driver_fd); |
| 787 | close(drv_ctx.video_driver_fd); |
| 788 | pthread_mutex_destroy(&m_lock); |
| 789 | pthread_mutex_destroy(&c_lock); |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 790 | pthread_mutex_destroy(&buf_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 791 | sem_destroy(&m_cmd_lock); |
| 792 | if (perf_flag) { |
| 793 | DEBUG_PRINT_HIGH("--> TOTAL PROCESSING TIME"); |
| 794 | dec_time.end(); |
| 795 | } |
| 796 | DEBUG_PRINT_HIGH("Exit OMX vdec Destructor"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 799 | int release_buffers(omx_vdec* obj, enum vdec_buffer buffer_type) |
| 800 | { |
| 801 | struct v4l2_requestbuffers bufreq; |
| 802 | int rc = 0; |
| 803 | if (buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 804 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 805 | bufreq.count = 0; |
| 806 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 807 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 808 | } else if(buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 809 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 810 | bufreq.count = 0; |
| 811 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 812 | rc = ioctl(obj->drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 813 | } |
| 814 | return rc; |
Vinay Kalia | feef703 | 2012-09-25 19:23:33 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 817 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 818 | FUNCTION |
| 819 | omx_vdec::OMXCntrlProcessMsgCb |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 820 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 821 | DESCRIPTION |
| 822 | IL Client callbacks are generated through this routine. The decoder |
| 823 | provides the thread context for this routine. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 824 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 825 | PARAMETERS |
| 826 | ctxt -- Context information related to the self. |
| 827 | id -- Event identifier. This could be any of the following: |
| 828 | 1. Command completion event |
| 829 | 2. Buffer done callback event |
| 830 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 831 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 832 | RETURN VALUE |
| 833 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 834 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 835 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 836 | void omx_vdec::process_event_cb(void *ctxt, unsigned char id) |
| 837 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 838 | signed p1; // Parameter - 1 |
| 839 | signed p2; // Parameter - 2 |
| 840 | unsigned ident; |
| 841 | unsigned qsize=0; // qsize |
| 842 | omx_vdec *pThis = (omx_vdec *) ctxt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 843 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 844 | if (!pThis) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 845 | DEBUG_PRINT_ERROR("ERROR: %s()::Context is incorrect, bailing out", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 846 | __func__); |
| 847 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 850 | // Protect the shared queue data structure |
| 851 | do { |
| 852 | /*Read the message id's from the queue*/ |
| 853 | pthread_mutex_lock(&pThis->m_lock); |
| 854 | qsize = pThis->m_cmd_q.m_size; |
| 855 | if (qsize) { |
| 856 | pThis->m_cmd_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 857 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 858 | |
| 859 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 860 | qsize = pThis->m_ftb_q.m_size; |
| 861 | if (qsize) { |
| 862 | pThis->m_ftb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 863 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 864 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 865 | |
| 866 | if (qsize == 0 && pThis->m_state != OMX_StatePause) { |
| 867 | qsize = pThis->m_etb_q.m_size; |
| 868 | if (qsize) { |
| 869 | pThis->m_etb_q.pop_entry((unsigned *)&p1, (unsigned *)&p2, &ident); |
| 870 | } |
| 871 | } |
| 872 | pthread_mutex_unlock(&pThis->m_lock); |
| 873 | |
| 874 | /*process message if we have one*/ |
| 875 | if (qsize > 0) { |
| 876 | id = ident; |
| 877 | switch (id) { |
| 878 | case OMX_COMPONENT_GENERATE_EVENT: |
| 879 | if (pThis->m_cb.EventHandler) { |
| 880 | switch (p1) { |
| 881 | case OMX_CommandStateSet: |
| 882 | pThis->m_state = (OMX_STATETYPE) p2; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 883 | DEBUG_PRINT_HIGH("OMX_CommandStateSet complete, m_state = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 884 | pThis->m_state); |
| 885 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 886 | OMX_EventCmdComplete, p1, p2, NULL); |
| 887 | break; |
| 888 | |
| 889 | case OMX_EventError: |
| 890 | if (p2 == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 891 | DEBUG_PRINT_ERROR("OMX_EventError: p2 is OMX_StateInvalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 892 | pThis->m_state = (OMX_STATETYPE) p2; |
| 893 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 894 | OMX_EventError, OMX_ErrorInvalidState, p2, NULL); |
| 895 | } else if (p2 == OMX_ErrorHardware) { |
| 896 | pThis->omx_report_error(); |
| 897 | } else { |
| 898 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 899 | OMX_EventError, p2, (OMX_U32)NULL, NULL ); |
| 900 | } |
| 901 | break; |
| 902 | |
| 903 | case OMX_CommandPortDisable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 904 | DEBUG_PRINT_HIGH("OMX_CommandPortDisable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 905 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 906 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
| 907 | BITMASK_SET(&pThis->m_flags, OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
| 908 | break; |
| 909 | } |
| 910 | if (p2 == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 911 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 912 | pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
| 913 | if (release_buffers(pThis, VDEC_BUFFER_TYPE_OUTPUT)) |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 914 | DEBUG_PRINT_HIGH("Failed to release output buffers"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 915 | OMX_ERRORTYPE eRet1 = pThis->get_buffer_req(&pThis->drv_ctx.op_buf); |
| 916 | pThis->in_reconfig = false; |
| 917 | if (eRet != OMX_ErrorNone) { |
| 918 | DEBUG_PRINT_ERROR("set_buffer_req failed eRet = %d",eRet); |
| 919 | pThis->omx_report_error(); |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 924 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 925 | break; |
| 926 | case OMX_CommandPortEnable: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 927 | DEBUG_PRINT_HIGH("OMX_CommandPortEnable complete for port [%d]", p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 928 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,\ |
| 929 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 930 | break; |
| 931 | |
| 932 | default: |
| 933 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 934 | OMX_EventCmdComplete, p1, p2, NULL ); |
| 935 | break; |
| 936 | |
| 937 | } |
| 938 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 939 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 940 | } |
| 941 | break; |
| 942 | case OMX_COMPONENT_GENERATE_ETB_ARBITRARY: |
| 943 | if (pThis->empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 944 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 945 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy_arbitrary failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 946 | pThis->omx_report_error (); |
| 947 | } |
| 948 | break; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 949 | case OMX_COMPONENT_GENERATE_ETB: { |
| 950 | OMX_ERRORTYPE iret; |
| 951 | iret = pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1, (OMX_BUFFERHEADERTYPE *)p2); |
| 952 | if (iret == OMX_ErrorInsufficientResources) { |
| 953 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure due to HW overload"); |
| 954 | pThis->omx_report_hw_overload (); |
| 955 | } else if (iret != OMX_ErrorNone) { |
| 956 | DEBUG_PRINT_ERROR("empty_this_buffer_proxy failure"); |
| 957 | pThis->omx_report_error (); |
| 958 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 959 | } |
| 960 | break; |
| 961 | |
| 962 | case OMX_COMPONENT_GENERATE_FTB: |
| 963 | if ( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 964 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 965 | DEBUG_PRINT_ERROR("fill_this_buffer_proxy failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 966 | pThis->omx_report_error (); |
| 967 | } |
| 968 | break; |
| 969 | |
| 970 | case OMX_COMPONENT_GENERATE_COMMAND: |
| 971 | pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\ |
| 972 | (OMX_U32)p2,(OMX_PTR)NULL); |
| 973 | break; |
| 974 | |
| 975 | case OMX_COMPONENT_GENERATE_EBD: |
| 976 | |
| 977 | if (p2 != VDEC_S_SUCCESS && p2 != VDEC_S_INPUT_BITSTREAM_ERR) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 978 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 979 | pThis->omx_report_error (); |
| 980 | } else { |
| 981 | if (p2 == VDEC_S_INPUT_BITSTREAM_ERR && p1) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 982 | pThis->time_stamp_dts.remove_time_stamp( |
| 983 | ((OMX_BUFFERHEADERTYPE *)p1)->nTimeStamp, |
| 984 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 985 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 986 | } |
Deva Ramasubramanian | 02b0d88 | 2014-04-03 14:58:50 -0700 | [diff] [blame] | 987 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 988 | if ( pThis->empty_buffer_done(&pThis->m_cmp, |
| 989 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 990 | DEBUG_PRINT_ERROR("empty_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 991 | pThis->omx_report_error (); |
| 992 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 993 | } |
| 994 | break; |
| 995 | case OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED: { |
| 996 | int64_t *timestamp = (int64_t *)p1; |
| 997 | if (p1) { |
| 998 | pThis->time_stamp_dts.remove_time_stamp(*timestamp, |
| 999 | (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 1000 | ?true:false); |
| 1001 | free(timestamp); |
| 1002 | } |
| 1003 | } |
| 1004 | break; |
| 1005 | case OMX_COMPONENT_GENERATE_FBD: |
| 1006 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1007 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_FBD failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1008 | pThis->omx_report_error (); |
| 1009 | } else if ( pThis->fill_buffer_done(&pThis->m_cmp, |
| 1010 | (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1011 | DEBUG_PRINT_ERROR("fill_buffer_done failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1012 | pThis->omx_report_error (); |
| 1013 | } |
| 1014 | break; |
| 1015 | |
| 1016 | case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1017 | DEBUG_PRINT_HIGH("Driver flush i/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1018 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1019 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1020 | } else { |
| 1021 | pThis->execute_input_flush(); |
| 1022 | if (pThis->m_cb.EventHandler) { |
| 1023 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1024 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1025 | pThis->omx_report_error (); |
| 1026 | } else { |
| 1027 | /*Check if we need generate event for Flush done*/ |
| 1028 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1029 | OMX_COMPONENT_INPUT_FLUSH_PENDING)) { |
| 1030 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1031 | DEBUG_PRINT_LOW("Input Flush completed - Notify Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1032 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1033 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1034 | OMX_CORE_INPUT_PORT_INDEX,NULL ); |
| 1035 | } |
| 1036 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1037 | OMX_COMPONENT_IDLE_PENDING)) { |
| 1038 | if (pThis->stream_off(OMX_CORE_INPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1039 | DEBUG_PRINT_ERROR("Failed to call streamoff on OUTPUT Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1040 | pThis->omx_report_error (); |
| 1041 | } else { |
| 1042 | pThis->streaming[OUTPUT_PORT] = false; |
| 1043 | } |
| 1044 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1045 | DEBUG_PRINT_LOW("Input flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1046 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1047 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | } else { |
| 1052 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1053 | } |
| 1054 | } |
| 1055 | break; |
| 1056 | |
| 1057 | case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1058 | DEBUG_PRINT_HIGH("Driver flush o/p Port complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1059 | if (!pThis->output_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1060 | DEBUG_PRINT_HIGH("WARNING: Unexpected flush from driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1061 | } else { |
| 1062 | pThis->execute_output_flush(); |
| 1063 | if (pThis->m_cb.EventHandler) { |
| 1064 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1065 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1066 | pThis->omx_report_error (); |
| 1067 | } else { |
| 1068 | /*Check if we need generate event for Flush done*/ |
| 1069 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1070 | OMX_COMPONENT_OUTPUT_FLUSH_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1071 | DEBUG_PRINT_LOW("Notify Output Flush done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1072 | BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 1073 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1074 | OMX_EventCmdComplete,OMX_CommandFlush, |
| 1075 | OMX_CORE_OUTPUT_PORT_INDEX,NULL ); |
| 1076 | } |
| 1077 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1078 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1079 | DEBUG_PRINT_LOW("Internal flush complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1080 | BITMASK_CLEAR (&pThis->m_flags, |
| 1081 | OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 1082 | if (BITMASK_PRESENT(&pThis->m_flags, |
| 1083 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED)) { |
| 1084 | pThis->post_event(OMX_CommandPortDisable, |
| 1085 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 1086 | OMX_COMPONENT_GENERATE_EVENT); |
| 1087 | BITMASK_CLEAR (&pThis->m_flags, |
| 1088 | OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED); |
Praneeth Paladugu | b52072a | 2013-08-23 13:54:43 -0700 | [diff] [blame] | 1089 | BITMASK_CLEAR (&pThis->m_flags, |
| 1090 | OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1091 | |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | if (BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING)) { |
| 1096 | if (pThis->stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1097 | DEBUG_PRINT_ERROR("Failed to call streamoff on CAPTURE Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1098 | pThis->omx_report_error (); |
| 1099 | break; |
| 1100 | } |
| 1101 | pThis->streaming[CAPTURE_PORT] = false; |
| 1102 | if (!pThis->input_flush_progress) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1103 | DEBUG_PRINT_LOW("Output flush done hence issue stop"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1104 | pThis->post_event ((unsigned int)NULL, VDEC_S_SUCCESS,\ |
| 1105 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | } else { |
| 1110 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1111 | } |
| 1112 | } |
| 1113 | break; |
| 1114 | |
| 1115 | case OMX_COMPONENT_GENERATE_START_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1116 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_START_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1117 | |
| 1118 | if (pThis->m_cb.EventHandler) { |
| 1119 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1120 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_START_DONE Failure"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1121 | pThis->omx_report_error (); |
| 1122 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1123 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_START_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1124 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1125 | DEBUG_PRINT_LOW("Move to executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1126 | // Send the callback now |
| 1127 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1128 | pThis->m_state = OMX_StateExecuting; |
| 1129 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1130 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1131 | OMX_StateExecuting, NULL); |
| 1132 | } else if (BITMASK_PRESENT(&pThis->m_flags, |
| 1133 | OMX_COMPONENT_PAUSE_PENDING)) { |
| 1134 | if (/*ioctl (pThis->drv_ctx.video_driver_fd, |
| 1135 | VDEC_IOCTL_CMD_PAUSE,NULL ) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1136 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_PAUSE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1137 | pThis->omx_report_error (); |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1142 | DEBUG_PRINT_LOW("Event Handler callback is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1143 | } |
| 1144 | break; |
| 1145 | |
| 1146 | case OMX_COMPONENT_GENERATE_PAUSE_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1147 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_PAUSE_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1148 | if (pThis->m_cb.EventHandler) { |
| 1149 | if (p2 != VDEC_S_SUCCESS) { |
| 1150 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_PAUSE_DONE ret failed"); |
| 1151 | pThis->omx_report_error (); |
| 1152 | } else { |
| 1153 | pThis->complete_pending_buffer_done_cbs(); |
| 1154 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1155 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_PAUSE_DONE nofity"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1156 | //Send the callback now |
| 1157 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING); |
| 1158 | pThis->m_state = OMX_StatePause; |
| 1159 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1160 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1161 | OMX_StatePause, NULL); |
| 1162 | } |
| 1163 | } |
| 1164 | } else { |
| 1165 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1166 | } |
| 1167 | |
| 1168 | break; |
| 1169 | |
| 1170 | case OMX_COMPONENT_GENERATE_RESUME_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1171 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_RESUME_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1172 | if (pThis->m_cb.EventHandler) { |
| 1173 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1174 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_RESUME_DONE failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1175 | pThis->omx_report_error (); |
| 1176 | } else { |
| 1177 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1178 | DEBUG_PRINT_LOW("Moving the decoder to execute state"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1179 | // Send the callback now |
| 1180 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING); |
| 1181 | pThis->m_state = OMX_StateExecuting; |
| 1182 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1183 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1184 | OMX_StateExecuting,NULL); |
| 1185 | } |
| 1186 | } |
| 1187 | } else { |
| 1188 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1189 | } |
| 1190 | |
| 1191 | break; |
| 1192 | |
| 1193 | case OMX_COMPONENT_GENERATE_STOP_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1194 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_STOP_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1195 | if (pThis->m_cb.EventHandler) { |
| 1196 | if (p2 != VDEC_S_SUCCESS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1197 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_STOP_DONE ret failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1198 | pThis->omx_report_error (); |
| 1199 | } else { |
| 1200 | pThis->complete_pending_buffer_done_cbs(); |
| 1201 | if (BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1202 | DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_STOP_DONE Success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1203 | // Send the callback now |
| 1204 | BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 1205 | pThis->m_state = OMX_StateIdle; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1206 | DEBUG_PRINT_LOW("Move to Idle State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1207 | pThis->m_cb.EventHandler(&pThis->m_cmp,pThis->m_app_data, |
| 1208 | OMX_EventCmdComplete,OMX_CommandStateSet, |
| 1209 | OMX_StateIdle,NULL); |
| 1210 | } |
| 1211 | } |
| 1212 | } else { |
| 1213 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1214 | } |
| 1215 | |
| 1216 | break; |
| 1217 | |
| 1218 | case OMX_COMPONENT_GENERATE_PORT_RECONFIG: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1219 | if (p2 == OMX_IndexParamPortDefinition) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1220 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1221 | pThis->in_reconfig = true; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1222 | |
| 1223 | } else if (p2 == OMX_IndexConfigCommonOutputCrop) { |
| 1224 | DEBUG_PRINT_HIGH("Rxd PORT_RECONFIG: OMX_IndexConfigCommonOutputCrop"); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1225 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1226 | /* Check if resolution is changed in smooth streaming mode */ |
| 1227 | if (pThis->m_smoothstreaming_mode && |
| 1228 | (pThis->framesize.nWidth != |
| 1229 | pThis->drv_ctx.video_resolution.frame_width) || |
| 1230 | (pThis->framesize.nHeight != |
| 1231 | pThis->drv_ctx.video_resolution.frame_height)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1232 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1233 | DEBUG_PRINT_HIGH("Resolution changed from: wxh = %dx%d to: wxh = %dx%d", |
| 1234 | pThis->framesize.nWidth, |
| 1235 | pThis->framesize.nHeight, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1236 | pThis->drv_ctx.video_resolution.frame_width, |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1237 | pThis->drv_ctx.video_resolution.frame_height); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1238 | |
| 1239 | /* Update new resolution */ |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1240 | pThis->framesize.nWidth = |
| 1241 | pThis->drv_ctx.video_resolution.frame_width; |
| 1242 | pThis->framesize.nHeight = |
| 1243 | pThis->drv_ctx.video_resolution.frame_height; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 1244 | |
| 1245 | /* Update C2D with new resolution */ |
| 1246 | if (!pThis->client_buffers.update_buffer_req()) { |
| 1247 | DEBUG_PRINT_ERROR("Setting C2D buffer requirements failed"); |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | /* Update new crop information */ |
| 1252 | pThis->rectangle.nLeft = pThis->drv_ctx.frame_size.left; |
| 1253 | pThis->rectangle.nTop = pThis->drv_ctx.frame_size.top; |
| 1254 | pThis->rectangle.nWidth = pThis->drv_ctx.frame_size.right; |
| 1255 | pThis->rectangle.nHeight = pThis->drv_ctx.frame_size.bottom; |
| 1256 | |
| 1257 | /* Validate the new crop information */ |
| 1258 | if (pThis->rectangle.nLeft + pThis->rectangle.nWidth > |
| 1259 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1260 | |
| 1261 | DEBUG_PRINT_HIGH("Crop L[%u] + R[%u] > W[%u]", |
| 1262 | pThis->rectangle.nLeft, pThis->rectangle.nWidth, |
| 1263 | pThis->drv_ctx.video_resolution.frame_width); |
| 1264 | pThis->rectangle.nLeft = 0; |
| 1265 | |
| 1266 | if (pThis->rectangle.nWidth > |
| 1267 | pThis->drv_ctx.video_resolution.frame_width) { |
| 1268 | |
| 1269 | DEBUG_PRINT_HIGH("Crop R[%u] > W[%u]", |
| 1270 | pThis->rectangle.nWidth, |
| 1271 | pThis->drv_ctx.video_resolution.frame_width); |
| 1272 | pThis->rectangle.nWidth = |
| 1273 | pThis->drv_ctx.video_resolution.frame_width; |
| 1274 | } |
| 1275 | } |
| 1276 | if (pThis->rectangle.nTop + pThis->rectangle.nHeight > |
| 1277 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1278 | |
| 1279 | DEBUG_PRINT_HIGH("Crop T[%u] + B[%u] > H[%u]", |
| 1280 | pThis->rectangle.nTop, pThis->rectangle.nHeight, |
| 1281 | pThis->drv_ctx.video_resolution.frame_height); |
| 1282 | pThis->rectangle.nTop = 0; |
| 1283 | |
| 1284 | if (pThis->rectangle.nHeight > |
| 1285 | pThis->drv_ctx.video_resolution.frame_height) { |
| 1286 | |
| 1287 | DEBUG_PRINT_HIGH("Crop B[%u] > H[%u]", |
| 1288 | pThis->rectangle.nHeight, |
| 1289 | pThis->drv_ctx.video_resolution.frame_height); |
| 1290 | pThis->rectangle.nHeight = |
| 1291 | pThis->drv_ctx.video_resolution.frame_height; |
| 1292 | } |
| 1293 | } |
| 1294 | DEBUG_PRINT_HIGH("Updated Crop Info: L: %u, T: %u, R: %u, B: %u", |
| 1295 | pThis->rectangle.nLeft, pThis->rectangle.nTop, |
| 1296 | pThis->rectangle.nWidth, pThis->rectangle.nHeight); |
| 1297 | } else { |
| 1298 | DEBUG_PRINT_ERROR("Rxd Invalid PORT_RECONFIG event (%lu)", p2); |
| 1299 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1300 | } |
| 1301 | if (pThis->m_cb.EventHandler) { |
| 1302 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, |
| 1303 | OMX_EventPortSettingsChanged, p1, p2, NULL ); |
| 1304 | } else { |
| 1305 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1306 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1307 | break; |
| 1308 | |
| 1309 | case OMX_COMPONENT_GENERATE_EOS_DONE: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1310 | DEBUG_PRINT_HIGH("Rxd OMX_COMPONENT_GENERATE_EOS_DONE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1311 | if (pThis->m_cb.EventHandler) { |
| 1312 | pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data, OMX_EventBufferFlag, |
| 1313 | OMX_CORE_OUTPUT_PORT_INDEX, OMX_BUFFERFLAG_EOS, NULL ); |
| 1314 | } else { |
| 1315 | DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__); |
| 1316 | } |
| 1317 | pThis->prev_ts = LLONG_MAX; |
| 1318 | pThis->rst_prev_ts = true; |
| 1319 | break; |
| 1320 | |
| 1321 | case OMX_COMPONENT_GENERATE_HARDWARE_ERROR: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1322 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_ERROR"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1323 | pThis->omx_report_error (); |
| 1324 | break; |
| 1325 | |
| 1326 | case OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1327 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1328 | pThis->omx_report_unsupported_setting(); |
| 1329 | break; |
| 1330 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 1331 | case OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD: |
| 1332 | DEBUG_PRINT_ERROR("OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD"); |
| 1333 | pThis->omx_report_hw_overload(); |
| 1334 | break; |
| 1335 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1336 | default: |
| 1337 | break; |
| 1338 | } |
| 1339 | } |
| 1340 | pthread_mutex_lock(&pThis->m_lock); |
| 1341 | qsize = pThis->m_cmd_q.m_size; |
| 1342 | if (pThis->m_state != OMX_StatePause) |
| 1343 | qsize += (pThis->m_ftb_q.m_size + pThis->m_etb_q.m_size); |
| 1344 | pthread_mutex_unlock(&pThis->m_lock); |
| 1345 | } while (qsize>0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1346 | |
| 1347 | } |
| 1348 | |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 1349 | 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] | 1350 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1351 | int format_changed = 0; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 1352 | if ((height != (int)drv_ctx.video_resolution.frame_height) || |
| 1353 | (width != (int)drv_ctx.video_resolution.frame_width)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1354 | DEBUG_PRINT_HIGH("NOTE_CIF: W/H %d (%d), %d (%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1355 | width, drv_ctx.video_resolution.frame_width, |
| 1356 | height,drv_ctx.video_resolution.frame_height); |
| 1357 | format_changed = 1; |
| 1358 | } |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1359 | drv_ctx.video_resolution.frame_height = height; |
| 1360 | drv_ctx.video_resolution.frame_width = width; |
Vinay Kalia | 21649b3 | 2013-03-18 17:28:07 -0700 | [diff] [blame] | 1361 | drv_ctx.video_resolution.scan_lines = scan_lines; |
| 1362 | drv_ctx.video_resolution.stride = stride; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 1363 | if(!is_down_scalar_enabled) { |
| 1364 | rectangle.nLeft = 0; |
| 1365 | rectangle.nTop = 0; |
| 1366 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1367 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
| 1368 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1369 | return format_changed; |
Vinay Kalia | 592e4b4 | 2012-12-19 15:55:47 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1372 | OMX_ERRORTYPE omx_vdec::is_video_session_supported() |
| 1373 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1374 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", |
| 1375 | OMX_MAX_STRINGNAME_SIZE) && |
| 1376 | (m_profile == HIGH_PROFILE || m_profile == MAIN_PROFILE)) { |
| 1377 | m_decoder_capability.max_width = 1280; |
| 1378 | m_decoder_capability.max_height = 720; |
| 1379 | DEBUG_PRINT_HIGH("Set max_width=1280 & max_height=720 for H264 HP/MP"); |
| 1380 | } |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 1381 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1382 | if ((drv_ctx.video_resolution.frame_width * |
| 1383 | drv_ctx.video_resolution.frame_height > |
| 1384 | m_decoder_capability.max_width * |
| 1385 | m_decoder_capability.max_height) || |
| 1386 | (drv_ctx.video_resolution.frame_width* |
| 1387 | drv_ctx.video_resolution.frame_height < |
| 1388 | m_decoder_capability.min_width * |
| 1389 | m_decoder_capability.min_height)) { |
| 1390 | DEBUG_PRINT_ERROR( |
| 1391 | "Unsupported WxH = (%u)x(%u) supported range is min(%u)x(%u) - max(%u)x(%u)", |
| 1392 | drv_ctx.video_resolution.frame_width, |
| 1393 | drv_ctx.video_resolution.frame_height, |
| 1394 | m_decoder_capability.min_width, |
| 1395 | m_decoder_capability.min_height, |
| 1396 | m_decoder_capability.max_width, |
| 1397 | m_decoder_capability.max_height); |
| 1398 | return OMX_ErrorUnsupportedSetting; |
| 1399 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1400 | DEBUG_PRINT_HIGH("video session supported"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1401 | return OMX_ErrorNone; |
Arun Menon | 6836ba0 | 2013-02-19 20:37:40 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1404 | int omx_vdec::log_input_buffers(const char *buffer_addr, int buffer_len) |
| 1405 | { |
| 1406 | if (m_debug.in_buffer_log && !m_debug.infile) { |
| 1407 | if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4", OMX_MAX_STRINGNAME_SIZE)) { |
| 1408 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.m4v", |
| 1409 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1410 | } |
| 1411 | else if(!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2", OMX_MAX_STRINGNAME_SIZE)) { |
| 1412 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.mpg", m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); } |
| 1413 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263", OMX_MAX_STRINGNAME_SIZE)) { |
| 1414 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.263", |
| 1415 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1416 | } |
| 1417 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc", OMX_MAX_STRINGNAME_SIZE)) { |
| 1418 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.264", |
| 1419 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1420 | } |
| 1421 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1", OMX_MAX_STRINGNAME_SIZE)) { |
| 1422 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1423 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1424 | } |
| 1425 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv", OMX_MAX_STRINGNAME_SIZE)) { |
| 1426 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.vc1", |
| 1427 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1428 | } |
| 1429 | else if(!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1430 | sprintf(m_debug.infile_name, "%s/input_dec_%d_%d_%p.ivf", |
| 1431 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1432 | } |
| 1433 | m_debug.infile = fopen (m_debug.infile_name, "ab"); |
| 1434 | if (!m_debug.infile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1435 | 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] | 1436 | m_debug.infile_name[0] = '\0'; |
| 1437 | return -1; |
| 1438 | } |
| 1439 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1440 | struct ivf_file_header { |
| 1441 | OMX_U8 signature[4]; //='DKIF'; |
| 1442 | OMX_U8 version ; //= 0; |
| 1443 | OMX_U8 headersize ; //= 32; |
| 1444 | OMX_U32 FourCC; |
| 1445 | OMX_U8 width; |
| 1446 | OMX_U8 height; |
| 1447 | OMX_U32 rate; |
| 1448 | OMX_U32 scale; |
| 1449 | OMX_U32 length; |
| 1450 | OMX_U8 unused[4]; |
| 1451 | } file_header; |
| 1452 | |
| 1453 | memset((void *)&file_header,0,sizeof(file_header)); |
| 1454 | file_header.signature[0] = 'D'; |
| 1455 | file_header.signature[1] = 'K'; |
| 1456 | file_header.signature[2] = 'I'; |
| 1457 | file_header.signature[3] = 'F'; |
| 1458 | file_header.version = 0; |
| 1459 | file_header.headersize = 32; |
| 1460 | file_header.FourCC = 0x30385056; |
| 1461 | fwrite((const char *)&file_header, |
| 1462 | sizeof(file_header),1,m_debug.infile); |
| 1463 | } |
| 1464 | } |
| 1465 | if (m_debug.infile && buffer_addr && buffer_len) { |
| 1466 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", OMX_MAX_STRINGNAME_SIZE)) { |
| 1467 | struct vp8_ivf_frame_header { |
| 1468 | OMX_U32 framesize; |
| 1469 | OMX_U32 timestamp_lo; |
| 1470 | OMX_U32 timestamp_hi; |
| 1471 | } vp8_frame_header; |
| 1472 | vp8_frame_header.framesize = buffer_len; |
| 1473 | /* Currently FW doesn't use timestamp values */ |
| 1474 | vp8_frame_header.timestamp_lo = 0; |
| 1475 | vp8_frame_header.timestamp_hi = 0; |
| 1476 | fwrite((const char *)&vp8_frame_header, |
| 1477 | sizeof(vp8_frame_header),1,m_debug.infile); |
| 1478 | } |
| 1479 | fwrite(buffer_addr, buffer_len, 1, m_debug.infile); |
| 1480 | } |
| 1481 | return 0; |
| 1482 | } |
| 1483 | |
| 1484 | int omx_vdec::log_output_buffers(OMX_BUFFERHEADERTYPE *buffer) { |
| 1485 | if (m_debug.out_buffer_log && !m_debug.outfile) { |
| 1486 | sprintf(m_debug.outfile_name, "%s/output_%d_%d_%p.yuv", |
| 1487 | m_debug.log_loc, drv_ctx.video_resolution.frame_width, drv_ctx.video_resolution.frame_height, this); |
| 1488 | m_debug.outfile = fopen (m_debug.outfile_name, "ab"); |
| 1489 | if (!m_debug.outfile) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1490 | 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] | 1491 | m_debug.outfile_name[0] = '\0'; |
| 1492 | return -1; |
| 1493 | } |
| 1494 | } |
| 1495 | if (m_debug.outfile && buffer && buffer->nFilledLen) { |
| 1496 | int buf_index = buffer - m_out_mem_ptr; |
| 1497 | int stride = drv_ctx.video_resolution.stride; |
| 1498 | int scanlines = drv_ctx.video_resolution.scan_lines; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1499 | if (m_smoothstreaming_mode) { |
| 1500 | stride = drv_ctx.video_resolution.frame_width; |
| 1501 | scanlines = drv_ctx.video_resolution.frame_height; |
| 1502 | stride = (stride + DEFAULT_WIDTH_ALIGNMENT - 1) & (~(DEFAULT_WIDTH_ALIGNMENT - 1)); |
| 1503 | scanlines = (scanlines + DEFAULT_HEIGHT_ALIGNMENT - 1) & (~(DEFAULT_HEIGHT_ALIGNMENT - 1)); |
| 1504 | } |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1505 | char *temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr; |
| 1506 | unsigned i; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1507 | DEBUG_PRINT_HIGH("Logging width/height(%u/%u) stride/scanlines(%u/%u)", |
| 1508 | drv_ctx.video_resolution.frame_width, |
| 1509 | drv_ctx.video_resolution.frame_height, stride, scanlines); |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 1510 | int bytes_written = 0; |
| 1511 | for (i = 0; i < drv_ctx.video_resolution.frame_height; i++) { |
| 1512 | bytes_written = fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1513 | temp += stride; |
| 1514 | } |
| 1515 | temp = (char *)drv_ctx.ptr_outputbuffer[buf_index].bufferaddr + stride * scanlines; |
| 1516 | int stride_c = stride; |
| 1517 | for(i = 0; i < drv_ctx.video_resolution.frame_height/2; i++) { |
| 1518 | bytes_written += fwrite(temp, drv_ctx.video_resolution.frame_width, 1, m_debug.outfile); |
| 1519 | temp += stride_c; |
| 1520 | } |
| 1521 | } |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1525 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1526 | FUNCTION |
| 1527 | omx_vdec::ComponentInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1528 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1529 | DESCRIPTION |
| 1530 | Initialize the component. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1531 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1532 | PARAMETERS |
| 1533 | ctxt -- Context information related to the self. |
| 1534 | id -- Event identifier. This could be any of the following: |
| 1535 | 1. Command completion event |
| 1536 | 2. Buffer done callback event |
| 1537 | 3. Frame done callback event |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1538 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1539 | RETURN VALUE |
| 1540 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1541 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1542 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1543 | OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role) |
| 1544 | { |
| 1545 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1546 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 1547 | struct v4l2_fmtdesc fdesc; |
| 1548 | struct v4l2_format fmt; |
| 1549 | struct v4l2_requestbuffers bufreq; |
| 1550 | struct v4l2_control control; |
| 1551 | struct v4l2_frmsizeenum frmsize; |
| 1552 | unsigned int alignment = 0,buffer_size = 0; |
| 1553 | int fds[2]; |
| 1554 | int r,ret=0; |
| 1555 | bool codec_ambiguous = false; |
Praveen Chavan | 00ec0ce | 2015-05-18 09:44:20 -0700 | [diff] [blame] | 1556 | OMX_STRING device_name = (OMX_STRING)"/dev/video32"; |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 1557 | char property_value[PROPERTY_VALUE_MAX] = {0}; |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1558 | |
| 1559 | #ifdef _ANDROID_ |
Praveen Chavan | e9e5620 | 2013-09-19 03:48:16 -0700 | [diff] [blame] | 1560 | char platform_name[PROPERTY_VALUE_MAX]; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1561 | property_get("ro.board.platform", platform_name, "0"); |
| 1562 | if (!strncmp(platform_name, "msm8610", 7)) { |
Balamurugan Alagarsamy | 1693e59 | 2015-07-23 19:19:05 +0530 | [diff] [blame] | 1563 | device_name = (OMX_STRING)"/dev/video34"; |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 1564 | is_q6_platform = true; |
| 1565 | maxSmoothStreamingWidth = 1280; |
| 1566 | maxSmoothStreamingHeight = 720; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1567 | } |
Sachin Shah | c82a18f | 2013-03-29 14:45:38 -0700 | [diff] [blame] | 1568 | #endif |
| 1569 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1570 | if (!strncmp(role, "OMX.qcom.video.decoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) { |
| 1571 | struct v4l2_control control; |
| 1572 | secure_mode = true; |
| 1573 | arbitrary_bytes = false; |
| 1574 | role = (OMX_STRING)"OMX.qcom.video.decoder.avc"; |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 1575 | } else if (!strncmp(role, "OMX.qcom.video.decoder.mpeg2.secure", |
| 1576 | OMX_MAX_STRINGNAME_SIZE)){ |
| 1577 | secure_mode = true; |
| 1578 | arbitrary_bytes = false; |
| 1579 | role = (OMX_STRING)"OMX.qcom.video.decoder.mpeg2"; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1580 | } |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1581 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1582 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1583 | |
Balamurugan Alagarsamy | 1693e59 | 2015-07-23 19:19:05 +0530 | [diff] [blame] | 1584 | DEBUG_PRINT_HIGH("omx_vdec::component_init(): Open device %s returned fd %d", |
| 1585 | device_name, drv_ctx.video_driver_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1586 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1587 | if (drv_ctx.video_driver_fd == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1588 | 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] | 1589 | drv_ctx.video_driver_fd = open(device_name, O_RDWR); |
| 1590 | close(0); |
| 1591 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1592 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1593 | if (drv_ctx.video_driver_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1594 | DEBUG_PRINT_ERROR("Omx_vdec::Comp Init Returning failure, errno %d", errno); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1595 | return OMX_ErrorInsufficientResources; |
| 1596 | } |
| 1597 | drv_ctx.frame_rate.fps_numerator = DEFAULT_FPS; |
| 1598 | drv_ctx.frame_rate.fps_denominator = 1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1599 | |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1600 | ret = subscribe_to_events(drv_ctx.video_driver_fd); |
Vinay Kalia | 184cd0f | 2013-04-29 18:26:42 -0700 | [diff] [blame] | 1601 | if (!ret) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1602 | async_thread_created = true; |
| 1603 | ret = pthread_create(&async_thread_id,0,async_message_thread,this); |
| 1604 | } |
| 1605 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1606 | DEBUG_PRINT_ERROR("Failed to create async_message_thread"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1607 | async_thread_created = false; |
| 1608 | return OMX_ErrorInsufficientResources; |
Vinay Kalia | dae8ad6 | 2013-04-26 20:42:10 -0700 | [diff] [blame] | 1609 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1610 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1611 | #ifdef OUTPUT_EXTRADATA_LOG |
Deva Ramasubramanian | ee6f1f4 | 2014-01-31 12:49:18 -0800 | [diff] [blame] | 1612 | outputExtradataFile = fopen (output_extradata_filename, "ab"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1613 | #endif |
| 1614 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1615 | // Copy the role information which provides the decoder kind |
| 1616 | strlcpy(drv_ctx.kind,role,128); |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 1617 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1618 | if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg4",\ |
| 1619 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1620 | strlcpy((char *)m_cRole, "video_decoder.mpeg4",\ |
| 1621 | OMX_MAX_STRINGNAME_SIZE); |
| 1622 | drv_ctx.timestamp_adjust = true; |
| 1623 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG4; |
| 1624 | eCompressionFormat = OMX_VIDEO_CodingMPEG4; |
| 1625 | output_capability=V4L2_PIX_FMT_MPEG4; |
| 1626 | /*Initialize Start Code for MPEG4*/ |
| 1627 | codec_type_parse = CODEC_TYPE_MPEG4; |
| 1628 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1629 | } else if (!strncmp(drv_ctx.kind,"OMX.qcom.video.decoder.mpeg2",\ |
| 1630 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1631 | strlcpy((char *)m_cRole, "video_decoder.mpeg2",\ |
| 1632 | OMX_MAX_STRINGNAME_SIZE); |
| 1633 | drv_ctx.decoder_format = VDEC_CODECTYPE_MPEG2; |
| 1634 | output_capability = V4L2_PIX_FMT_MPEG2; |
| 1635 | eCompressionFormat = OMX_VIDEO_CodingMPEG2; |
| 1636 | /*Initialize Start Code for MPEG2*/ |
| 1637 | codec_type_parse = CODEC_TYPE_MPEG2; |
| 1638 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1639 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",\ |
| 1640 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1641 | strlcpy((char *)m_cRole, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1642 | DEBUG_PRINT_LOW("H263 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1643 | drv_ctx.decoder_format = VDEC_CODECTYPE_H263; |
| 1644 | eCompressionFormat = OMX_VIDEO_CodingH263; |
| 1645 | output_capability = V4L2_PIX_FMT_H263; |
| 1646 | codec_type_parse = CODEC_TYPE_H263; |
| 1647 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1648 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",\ |
| 1649 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1650 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1651 | DEBUG_PRINT_LOW ("DIVX 311 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1652 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_3; |
| 1653 | output_capability = V4L2_PIX_FMT_DIVX_311; |
| 1654 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1655 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1656 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1657 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1658 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4",\ |
| 1659 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1660 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1661 | DEBUG_PRINT_ERROR ("DIVX 4 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1662 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_4; |
| 1663 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1664 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1665 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1666 | codec_ambiguous = true; |
| 1667 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1668 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1669 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",\ |
| 1670 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1671 | strlcpy((char *)m_cRole, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1672 | DEBUG_PRINT_ERROR ("DIVX 5/6 Decoder selected"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1673 | drv_ctx.decoder_format = VDEC_CODECTYPE_DIVX_6; |
| 1674 | output_capability = V4L2_PIX_FMT_DIVX; |
| 1675 | eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingDivx; |
| 1676 | codec_type_parse = CODEC_TYPE_DIVX; |
| 1677 | codec_ambiguous = true; |
| 1678 | m_frame_parser.init_start_codes (codec_type_parse); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1679 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1680 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",\ |
| 1681 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1682 | strlcpy((char *)m_cRole, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 1683 | drv_ctx.decoder_format = VDEC_CODECTYPE_H264; |
| 1684 | output_capability=V4L2_PIX_FMT_H264; |
| 1685 | eCompressionFormat = OMX_VIDEO_CodingAVC; |
| 1686 | codec_type_parse = CODEC_TYPE_H264; |
| 1687 | m_frame_parser.init_start_codes (codec_type_parse); |
| 1688 | m_frame_parser.init_nal_length(nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1689 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",\ |
| 1690 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1691 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1692 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1; |
| 1693 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1694 | codec_type_parse = CODEC_TYPE_VC1; |
| 1695 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_G; |
| 1696 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1697 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",\ |
| 1698 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1699 | strlcpy((char *)m_cRole, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 1700 | drv_ctx.decoder_format = VDEC_CODECTYPE_VC1_RCV; |
| 1701 | eCompressionFormat = OMX_VIDEO_CodingWMV; |
| 1702 | codec_type_parse = CODEC_TYPE_VC1; |
| 1703 | output_capability = V4L2_PIX_FMT_VC1_ANNEX_L; |
| 1704 | m_frame_parser.init_start_codes (codec_type_parse); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1705 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", \ |
| 1706 | OMX_MAX_STRINGNAME_SIZE)) { |
| 1707 | strlcpy((char *)m_cRole, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 1708 | output_capability=V4L2_PIX_FMT_VP8; |
Praveen Chavan | 76b71c3 | 2014-07-10 18:10:51 -0700 | [diff] [blame] | 1709 | eCompressionFormat = OMX_VIDEO_CodingVP8; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1710 | codec_type_parse = CODEC_TYPE_VP8; |
| 1711 | arbitrary_bytes = false; |
Praneeth Paladugu | 2b2ef2d | 2013-04-10 22:04:51 -0700 | [diff] [blame] | 1712 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1713 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1714 | DEBUG_PRINT_ERROR("ERROR:Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1715 | eRet = OMX_ErrorInvalidComponentName; |
| 1716 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1717 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1718 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1719 | drv_ctx.output_format = VDEC_YUV_FORMAT_NV12; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1720 | OMX_COLOR_FORMATTYPE dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 1721 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 1722 | if (!client_buffers.set_color_format(dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1723 | DEBUG_PRINT_ERROR("Setting color format failed"); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 1724 | eRet = OMX_ErrorInsufficientResources; |
| 1725 | } |
| 1726 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1727 | capture_capability= V4L2_PIX_FMT_NV12; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1728 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1729 | struct v4l2_capability cap; |
| 1730 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_QUERYCAP, &cap); |
| 1731 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1732 | DEBUG_PRINT_ERROR("Failed to query capabilities"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1733 | /*TODO: How to handle this case */ |
| 1734 | } else { |
| 1735 | DEBUG_PRINT_HIGH("Capabilities: driver_name = %s, card = %s, bus_info = %s," |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1736 | " version = %d, capabilities = %x", cap.driver, cap.card, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1737 | cap.bus_info, cap.version, cap.capabilities); |
| 1738 | } |
| 1739 | ret=0; |
| 1740 | fdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1741 | fdesc.index=0; |
| 1742 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1743 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1744 | fdesc.pixelformat, fdesc.flags); |
| 1745 | fdesc.index++; |
| 1746 | } |
| 1747 | fdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1748 | fdesc.index=0; |
| 1749 | while (ioctl(drv_ctx.video_driver_fd, VIDIOC_ENUM_FMT, &fdesc) == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1750 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1751 | DEBUG_PRINT_HIGH("fmt: description: %s, fmt: %x, flags = %x", fdesc.description, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1752 | fdesc.pixelformat, fdesc.flags); |
| 1753 | fdesc.index++; |
| 1754 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1755 | update_resolution(320, 240, 320, 240); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1756 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1757 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1758 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1759 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 1760 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1761 | if (ret) { |
| 1762 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1763 | DEBUG_PRINT_ERROR("Failed to set format on output port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1764 | return OMX_ErrorInsufficientResources; |
| 1765 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1766 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1767 | if (codec_ambiguous) { |
| 1768 | if (output_capability == V4L2_PIX_FMT_DIVX) { |
| 1769 | struct v4l2_control divx_ctrl; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1770 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1771 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_4) { |
| 1772 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_4; |
| 1773 | } else if (drv_ctx.decoder_format == VDEC_CODECTYPE_DIVX_5) { |
| 1774 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_5; |
| 1775 | } else { |
| 1776 | divx_ctrl.value = V4L2_MPEG_VIDC_VIDEO_DIVX_FORMAT_6; |
| 1777 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1778 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1779 | divx_ctrl.id = V4L2_CID_MPEG_VIDC_VIDEO_DIVX_FORMAT; |
| 1780 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &divx_ctrl); |
| 1781 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1782 | DEBUG_PRINT_ERROR("Failed to set divx version"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1783 | } |
| 1784 | } else { |
| 1785 | DEBUG_PRINT_ERROR("Codec should not be ambiguous"); |
| 1786 | } |
| 1787 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1788 | |
Jia Meng | 3a3c649 | 2013-12-19 17:16:52 +0800 | [diff] [blame] | 1789 | property_get("persist.vidc.dec.conceal_color", property_value, DEFAULT_CONCEAL_COLOR); |
| 1790 | m_conceal_color= atoi(property_value); |
| 1791 | DEBUG_PRINT_HIGH("trying to set 0x%x as conceal color\n",m_conceal_color); |
| 1792 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR; |
| 1793 | control.value = m_conceal_color; |
| 1794 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 1795 | if (ret) { |
| 1796 | DEBUG_PRINT_ERROR("Failed to set conceal color %d\n", ret); |
| 1797 | } |
| 1798 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1799 | //Get the hardware capabilities |
| 1800 | memset((void *)&frmsize,0,sizeof(frmsize)); |
| 1801 | frmsize.index = 0; |
| 1802 | frmsize.pixel_format = output_capability; |
| 1803 | ret = ioctl(drv_ctx.video_driver_fd, |
| 1804 | VIDIOC_ENUM_FRAMESIZES, &frmsize); |
| 1805 | if (ret || frmsize.type != V4L2_FRMSIZE_TYPE_STEPWISE) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1806 | DEBUG_PRINT_ERROR("Failed to get framesizes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1807 | return OMX_ErrorHardware; |
| 1808 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1809 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1810 | if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) { |
| 1811 | m_decoder_capability.min_width = frmsize.stepwise.min_width; |
| 1812 | m_decoder_capability.max_width = frmsize.stepwise.max_width; |
| 1813 | m_decoder_capability.min_height = frmsize.stepwise.min_height; |
| 1814 | m_decoder_capability.max_height = frmsize.stepwise.max_height; |
| 1815 | } |
Deva Ramasubramanian | 3c55b21 | 2013-06-18 15:03:49 -0700 | [diff] [blame] | 1816 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1817 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1818 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 1819 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 1820 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 1821 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 1822 | if (ret) { |
| 1823 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1824 | DEBUG_PRINT_ERROR("Failed to set format on capture port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1825 | } |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 1826 | memset(&framesize, 0, sizeof(OMX_FRAMESIZETYPE)); |
| 1827 | framesize.nWidth = drv_ctx.video_resolution.frame_width; |
| 1828 | framesize.nHeight = drv_ctx.video_resolution.frame_height; |
| 1829 | |
| 1830 | memset(&rectangle, 0, sizeof(OMX_CONFIG_RECTTYPE)); |
| 1831 | rectangle.nWidth = drv_ctx.video_resolution.frame_width; |
| 1832 | rectangle.nHeight = drv_ctx.video_resolution.frame_height; |
| 1833 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1834 | DEBUG_PRINT_HIGH("Set Format was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1835 | if (secure_mode) { |
| 1836 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE; |
| 1837 | control.value = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1838 | DEBUG_PRINT_LOW("Omx_vdec:: calling to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1839 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 1840 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1841 | DEBUG_PRINT_ERROR("Omx_vdec:: Unable to open secure device %d", ret); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1842 | return OMX_ErrorInsufficientResources; |
| 1843 | } |
| 1844 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1845 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1846 | /*Get the Buffer requirements for input and output ports*/ |
| 1847 | drv_ctx.ip_buf.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 1848 | drv_ctx.op_buf.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 1849 | if (secure_mode) { |
| 1850 | drv_ctx.op_buf.alignment=SZ_1M; |
| 1851 | drv_ctx.ip_buf.alignment=SZ_1M; |
| 1852 | } else { |
| 1853 | drv_ctx.op_buf.alignment=SZ_4K; |
| 1854 | drv_ctx.ip_buf.alignment=SZ_4K; |
| 1855 | } |
| 1856 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 1857 | drv_ctx.extradata = 0; |
| 1858 | drv_ctx.picture_order = VDEC_ORDER_DISPLAY; |
| 1859 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 1860 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 1861 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 1862 | drv_ctx.idr_only_decoding = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1863 | |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1864 | m_state = OMX_StateLoaded; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1865 | #ifdef DEFAULT_EXTRADATA |
Arun Menon | f8908a6 | 2013-12-20 17:36:21 -0800 | [diff] [blame] | 1866 | if (strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8", |
| 1867 | OMX_MAX_STRINGNAME_SIZE) && (eRet == OMX_ErrorNone)) |
| 1868 | enable_extradata(DEFAULT_EXTRADATA, true, true); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1869 | #endif |
Vinay Kalia | 5713bb3 | 2013-01-16 18:39:59 -0800 | [diff] [blame] | 1870 | eRet=get_buffer_req(&drv_ctx.ip_buf); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1871 | 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] | 1872 | get_buffer_req(&drv_ctx.op_buf); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1873 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
| 1874 | if (m_frame_parser.mutils == NULL) { |
| 1875 | m_frame_parser.mutils = new H264_Utils(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1876 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1877 | if (m_frame_parser.mutils == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1878 | DEBUG_PRINT_ERROR("parser utils Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1879 | eRet = OMX_ErrorInsufficientResources; |
| 1880 | } else { |
| 1881 | h264_scratch.nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 1882 | h264_scratch.pBuffer = (OMX_U8 *)malloc (drv_ctx.ip_buf.buffer_size); |
| 1883 | h264_scratch.nFilledLen = 0; |
| 1884 | h264_scratch.nOffset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1885 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1886 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1887 | DEBUG_PRINT_ERROR("h264_scratch.pBuffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1888 | return OMX_ErrorInsufficientResources; |
| 1889 | } |
| 1890 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 1891 | m_frame_parser.mutils->allocate_rbsp_buffer (drv_ctx.ip_buf.buffer_size); |
| 1892 | } |
| 1893 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1894 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1895 | h264_parser = new h264_stream_parser(); |
| 1896 | if (!h264_parser) { |
| 1897 | DEBUG_PRINT_ERROR("ERROR: H264 parser allocation failed!"); |
| 1898 | eRet = OMX_ErrorInsufficientResources; |
| 1899 | } |
| 1900 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1901 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1902 | if (pipe(fds)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1903 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1904 | eRet = OMX_ErrorInsufficientResources; |
| 1905 | } else { |
| 1906 | int temp1[2]; |
| 1907 | if (fds[0] == 0 || fds[1] == 0) { |
| 1908 | if (pipe (temp1)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1909 | DEBUG_PRINT_ERROR("pipe creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1910 | return OMX_ErrorInsufficientResources; |
| 1911 | } |
| 1912 | //close (fds[0]); |
| 1913 | //close (fds[1]); |
| 1914 | fds[0] = temp1 [0]; |
| 1915 | fds[1] = temp1 [1]; |
| 1916 | } |
| 1917 | m_pipe_in = fds[0]; |
| 1918 | m_pipe_out = fds[1]; |
| 1919 | msg_thread_created = true; |
Ashray Kulkarni | a97efbc | 2015-07-15 18:17:23 -0700 | [diff] [blame] | 1920 | r = pthread_create(&msg_thread_id,0, dec_message_thread,this); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1921 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1922 | if (r < 0) { |
Ashray Kulkarni | a97efbc | 2015-07-15 18:17:23 -0700 | [diff] [blame] | 1923 | DEBUG_PRINT_ERROR("component_init(): dec_message_thread creation failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1924 | msg_thread_created = false; |
| 1925 | eRet = OMX_ErrorInsufficientResources; |
| 1926 | } |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | if (eRet != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1931 | DEBUG_PRINT_ERROR("Component Init Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1932 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1933 | DEBUG_PRINT_HIGH("omx_vdec::component_init() success"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1934 | } |
| 1935 | //memset(&h264_mv_buff,0,sizeof(struct h264_mv_buffer)); |
Praveen Chavan | 898df26 | 2015-04-20 18:52:19 -0700 | [diff] [blame] | 1936 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY; |
| 1937 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE; |
| 1938 | |
| 1939 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 1940 | DEBUG_PRINT_ERROR("Failed to set Default Priority"); |
| 1941 | eRet = OMX_ErrorUnsupportedSetting; |
| 1942 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1943 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1947 | FUNCTION |
| 1948 | omx_vdec::GetComponentVersion |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1949 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1950 | DESCRIPTION |
| 1951 | Returns the component version. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1952 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1953 | PARAMETERS |
| 1954 | TBD. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1955 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1956 | RETURN VALUE |
| 1957 | OMX_ErrorNone. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1958 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1959 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1960 | OMX_ERRORTYPE omx_vdec::get_component_version |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1961 | ( |
| 1962 | OMX_IN OMX_HANDLETYPE hComp, |
| 1963 | OMX_OUT OMX_STRING componentName, |
| 1964 | OMX_OUT OMX_VERSIONTYPE* componentVersion, |
| 1965 | OMX_OUT OMX_VERSIONTYPE* specVersion, |
| 1966 | OMX_OUT OMX_UUIDTYPE* componentUUID |
| 1967 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1968 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1969 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1970 | DEBUG_PRINT_ERROR("Get Comp Version in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1971 | return OMX_ErrorInvalidState; |
| 1972 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1973 | /* TBD -- Return the proper version */ |
| 1974 | if (specVersion) { |
| 1975 | specVersion->nVersion = OMX_SPEC_VERSION; |
| 1976 | } |
| 1977 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1978 | } |
| 1979 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1980 | FUNCTION |
| 1981 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1982 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1983 | DESCRIPTION |
| 1984 | Returns zero if all the buffers released.. |
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 | PARAMETERS |
| 1987 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1988 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1989 | RETURN VALUE |
| 1990 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1991 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1992 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1993 | OMX_ERRORTYPE omx_vdec::send_command(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 1994 | OMX_IN OMX_COMMANDTYPE cmd, |
| 1995 | OMX_IN OMX_U32 param1, |
| 1996 | OMX_IN OMX_PTR cmdData |
| 1997 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 1998 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 1999 | DEBUG_PRINT_LOW("send_command: Recieved a Command from Client"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2000 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2001 | DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2002 | return OMX_ErrorInvalidState; |
| 2003 | } |
| 2004 | if (cmd == OMX_CommandFlush && param1 != OMX_CORE_INPUT_PORT_INDEX |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2005 | && param1 != OMX_CORE_OUTPUT_PORT_INDEX && param1 != OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2006 | DEBUG_PRINT_ERROR("send_command(): ERROR OMX_CommandFlush " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2007 | "to invalid port: %lu", param1); |
| 2008 | return OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2009 | } |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 2010 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2011 | post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND); |
| 2012 | sem_wait(&m_cmd_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2013 | DEBUG_PRINT_LOW("send_command: Command Processed"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2014 | return OMX_ErrorNone; |
| 2015 | } |
| 2016 | |
| 2017 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2018 | FUNCTION |
| 2019 | omx_vdec::SendCommand |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2020 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2021 | DESCRIPTION |
| 2022 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2023 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2024 | PARAMETERS |
| 2025 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2026 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2027 | RETURN VALUE |
| 2028 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2029 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2030 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2031 | OMX_ERRORTYPE omx_vdec::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2032 | OMX_IN OMX_COMMANDTYPE cmd, |
| 2033 | OMX_IN OMX_U32 param1, |
| 2034 | OMX_IN OMX_PTR cmdData |
| 2035 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2036 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2037 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2038 | OMX_STATETYPE eState = (OMX_STATETYPE) param1; |
| 2039 | int bFlag = 1,sem_posted = 0,ret=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2040 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2041 | DEBUG_PRINT_LOW("send_command_proxy(): cmd = %d", cmd); |
| 2042 | DEBUG_PRINT_HIGH("send_command_proxy(): Current State %d, Expected State %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2043 | m_state, eState); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2044 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2045 | if (cmd == OMX_CommandStateSet) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2046 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandStateSet issued"); |
| 2047 | DEBUG_PRINT_HIGH("Current State %d, Expected State %d", m_state, eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2048 | /***************************/ |
| 2049 | /* Current State is Loaded */ |
| 2050 | /***************************/ |
| 2051 | if (m_state == OMX_StateLoaded) { |
| 2052 | if (eState == OMX_StateIdle) { |
| 2053 | //if all buffers are allocated or all ports disabled |
| 2054 | if (allocate_done() || |
| 2055 | (m_inp_bEnabled == OMX_FALSE && m_out_bEnabled == OMX_FALSE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2056 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2057 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2058 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->Idle-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2059 | BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING); |
| 2060 | // Skip the event notification |
| 2061 | bFlag = 0; |
| 2062 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2063 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2064 | /* Requesting transition from Loaded to Loaded */ |
| 2065 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2066 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2067 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2068 | OMX_COMPONENT_GENERATE_EVENT); |
| 2069 | eRet = OMX_ErrorSameState; |
| 2070 | } |
| 2071 | /* Requesting transition from Loaded to WaitForResources */ |
| 2072 | else if (eState == OMX_StateWaitForResources) { |
| 2073 | /* Since error is None , we will post an event |
| 2074 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2075 | DEBUG_PRINT_LOW("send_command_proxy(): Loaded-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2076 | } |
| 2077 | /* Requesting transition from Loaded to Executing */ |
| 2078 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2079 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2080 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2081 | OMX_COMPONENT_GENERATE_EVENT); |
| 2082 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2083 | } |
| 2084 | /* Requesting transition from Loaded to Pause */ |
| 2085 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2086 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2087 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2088 | OMX_COMPONENT_GENERATE_EVENT); |
| 2089 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2090 | } |
| 2091 | /* Requesting transition from Loaded to Invalid */ |
| 2092 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2093 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2094 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2095 | eRet = OMX_ErrorInvalidState; |
| 2096 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2097 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Loaded-->Invalid(%d Not Handled)",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2098 | eState); |
| 2099 | eRet = OMX_ErrorBadParameter; |
| 2100 | } |
| 2101 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2102 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2103 | /***************************/ |
| 2104 | /* Current State is IDLE */ |
| 2105 | /***************************/ |
| 2106 | else if (m_state == OMX_StateIdle) { |
| 2107 | if (eState == OMX_StateLoaded) { |
| 2108 | if (release_done()) { |
| 2109 | /* |
| 2110 | Since error is None , we will post an event at the end |
| 2111 | of this function definition |
| 2112 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2113 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2114 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2115 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Loaded-Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2116 | BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING); |
| 2117 | // Skip the event notification |
| 2118 | bFlag = 0; |
| 2119 | } |
| 2120 | } |
| 2121 | /* Requesting transition from Idle to Executing */ |
| 2122 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2123 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2124 | //BITMASK_SET(&m_flags, OMX_COMPONENT_EXECUTE_PENDING); |
| 2125 | bFlag = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2126 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2127 | m_state=OMX_StateExecuting; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2128 | DEBUG_PRINT_HIGH("Stream On CAPTURE Was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2129 | } |
| 2130 | /* Requesting transition from Idle to Idle */ |
| 2131 | else if (eState == OMX_StateIdle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2132 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2133 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2134 | OMX_COMPONENT_GENERATE_EVENT); |
| 2135 | eRet = OMX_ErrorSameState; |
| 2136 | } |
| 2137 | /* Requesting transition from Idle to WaitForResources */ |
| 2138 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2139 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2140 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2141 | OMX_COMPONENT_GENERATE_EVENT); |
| 2142 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2143 | } |
| 2144 | /* Requesting transition from Idle to Pause */ |
| 2145 | else if (eState == OMX_StatePause) { |
| 2146 | /*To pause the Video core we need to start the driver*/ |
| 2147 | if (/*ioctl (drv_ctx.video_driver_fd,VDEC_IOCTL_CMD_START, |
| 2148 | NULL) < */0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2149 | DEBUG_PRINT_ERROR("VDEC_IOCTL_CMD_START FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2150 | omx_report_error (); |
| 2151 | eRet = OMX_ErrorHardware; |
| 2152 | } else { |
| 2153 | BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2154 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2155 | bFlag = 0; |
| 2156 | } |
| 2157 | } |
| 2158 | /* Requesting transition from Idle to Invalid */ |
| 2159 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2160 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2161 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2162 | eRet = OMX_ErrorInvalidState; |
| 2163 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2164 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Idle --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2165 | eRet = OMX_ErrorBadParameter; |
| 2166 | } |
| 2167 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2168 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2169 | /******************************/ |
| 2170 | /* Current State is Executing */ |
| 2171 | /******************************/ |
| 2172 | else if (m_state == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2173 | DEBUG_PRINT_LOW("Command Recieved in OMX_StateExecuting"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2174 | /* Requesting transition from Executing to Idle */ |
| 2175 | if (eState == OMX_StateIdle) { |
| 2176 | /* Since error is None , we will post an event |
| 2177 | at the end of this function definition |
| 2178 | */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2179 | DEBUG_PRINT_LOW("send_command_proxy(): Executing --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2180 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2181 | if (!sem_posted) { |
| 2182 | sem_posted = 1; |
| 2183 | sem_post (&m_cmd_lock); |
| 2184 | execute_omx_flush(OMX_ALL); |
| 2185 | } |
| 2186 | bFlag = 0; |
| 2187 | } |
| 2188 | /* Requesting transition from Executing to Paused */ |
| 2189 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2190 | DEBUG_PRINT_LOW("PAUSE Command Issued"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2191 | m_state = OMX_StatePause; |
| 2192 | bFlag = 1; |
| 2193 | } |
| 2194 | /* Requesting transition from Executing to Loaded */ |
| 2195 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2196 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2197 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2198 | OMX_COMPONENT_GENERATE_EVENT); |
| 2199 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2200 | } |
| 2201 | /* Requesting transition from Executing to WaitForResources */ |
| 2202 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2203 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2204 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2205 | OMX_COMPONENT_GENERATE_EVENT); |
| 2206 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2207 | } |
| 2208 | /* Requesting transition from Executing to Executing */ |
| 2209 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2210 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2211 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2212 | OMX_COMPONENT_GENERATE_EVENT); |
| 2213 | eRet = OMX_ErrorSameState; |
| 2214 | } |
| 2215 | /* Requesting transition from Executing to Invalid */ |
| 2216 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2217 | DEBUG_PRINT_ERROR("send_command_proxy(): Executing --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2218 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2219 | eRet = OMX_ErrorInvalidState; |
| 2220 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2221 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Executing --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2222 | eRet = OMX_ErrorBadParameter; |
| 2223 | } |
| 2224 | } |
| 2225 | /***************************/ |
| 2226 | /* Current State is Pause */ |
| 2227 | /***************************/ |
| 2228 | else if (m_state == OMX_StatePause) { |
| 2229 | /* Requesting transition from Pause to Executing */ |
| 2230 | if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2231 | DEBUG_PRINT_LOW("Pause --> Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2232 | m_state = OMX_StateExecuting; |
| 2233 | bFlag = 1; |
| 2234 | } |
| 2235 | /* Requesting transition from Pause to Idle */ |
| 2236 | else if (eState == OMX_StateIdle) { |
| 2237 | /* Since error is None , we will post an event |
| 2238 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2239 | DEBUG_PRINT_LOW("Pause --> Idle"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2240 | BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING); |
| 2241 | if (!sem_posted) { |
| 2242 | sem_posted = 1; |
| 2243 | sem_post (&m_cmd_lock); |
| 2244 | execute_omx_flush(OMX_ALL); |
| 2245 | } |
| 2246 | bFlag = 0; |
| 2247 | } |
| 2248 | /* Requesting transition from Pause to loaded */ |
| 2249 | else if (eState == OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2250 | DEBUG_PRINT_ERROR("Pause --> loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2251 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2252 | OMX_COMPONENT_GENERATE_EVENT); |
| 2253 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2254 | } |
| 2255 | /* Requesting transition from Pause to WaitForResources */ |
| 2256 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2257 | DEBUG_PRINT_ERROR("Pause --> WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2258 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2259 | OMX_COMPONENT_GENERATE_EVENT); |
| 2260 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2261 | } |
| 2262 | /* Requesting transition from Pause to Pause */ |
| 2263 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2264 | DEBUG_PRINT_ERROR("Pause --> Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2265 | post_event(OMX_EventError,OMX_ErrorSameState,\ |
| 2266 | OMX_COMPONENT_GENERATE_EVENT); |
| 2267 | eRet = OMX_ErrorSameState; |
| 2268 | } |
| 2269 | /* Requesting transition from Pause to Invalid */ |
| 2270 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2271 | DEBUG_PRINT_ERROR("Pause --> Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2272 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2273 | eRet = OMX_ErrorInvalidState; |
| 2274 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2275 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Paused --> %d Not Handled",eState); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2276 | eRet = OMX_ErrorBadParameter; |
| 2277 | } |
| 2278 | } |
| 2279 | /***************************/ |
| 2280 | /* Current State is WaitForResources */ |
| 2281 | /***************************/ |
| 2282 | else if (m_state == OMX_StateWaitForResources) { |
| 2283 | /* Requesting transition from WaitForResources to Loaded */ |
| 2284 | if (eState == OMX_StateLoaded) { |
| 2285 | /* Since error is None , we will post an event |
| 2286 | at the end of this function definition */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2287 | DEBUG_PRINT_LOW("send_command_proxy(): WaitForResources-->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2288 | } |
| 2289 | /* Requesting transition from WaitForResources to WaitForResources */ |
| 2290 | else if (eState == OMX_StateWaitForResources) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2291 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->WaitForResources"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2292 | post_event(OMX_EventError,OMX_ErrorSameState, |
| 2293 | OMX_COMPONENT_GENERATE_EVENT); |
| 2294 | eRet = OMX_ErrorSameState; |
| 2295 | } |
| 2296 | /* Requesting transition from WaitForResources to Executing */ |
| 2297 | else if (eState == OMX_StateExecuting) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2298 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2299 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2300 | OMX_COMPONENT_GENERATE_EVENT); |
| 2301 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2302 | } |
| 2303 | /* Requesting transition from WaitForResources to Pause */ |
| 2304 | else if (eState == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2305 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Pause"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2306 | post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\ |
| 2307 | OMX_COMPONENT_GENERATE_EVENT); |
| 2308 | eRet = OMX_ErrorIncorrectStateTransition; |
| 2309 | } |
| 2310 | /* Requesting transition from WaitForResources to Invalid */ |
| 2311 | else if (eState == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2312 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): WaitForResources-->Invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2313 | post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2314 | eRet = OMX_ErrorInvalidState; |
| 2315 | } |
| 2316 | /* Requesting transition from WaitForResources to Loaded - |
| 2317 | is NOT tested by Khronos TS */ |
| 2318 | |
| 2319 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2320 | 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] | 2321 | eRet = OMX_ErrorBadParameter; |
| 2322 | } |
| 2323 | } |
| 2324 | /********************************/ |
| 2325 | /* Current State is Invalid */ |
| 2326 | /*******************************/ |
| 2327 | else if (m_state == OMX_StateInvalid) { |
| 2328 | /* State Transition from Inavlid to any state */ |
| 2329 | if (eState == (OMX_StateLoaded || OMX_StateWaitForResources |
| 2330 | || OMX_StateIdle || OMX_StateExecuting |
| 2331 | || OMX_StatePause || OMX_StateInvalid)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2332 | DEBUG_PRINT_ERROR("ERROR::send_command_proxy(): Invalid -->Loaded"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2333 | post_event(OMX_EventError,OMX_ErrorInvalidState,\ |
| 2334 | OMX_COMPONENT_GENERATE_EVENT); |
| 2335 | eRet = OMX_ErrorInvalidState; |
| 2336 | } |
| 2337 | } else if (cmd == OMX_CommandFlush) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2338 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandFlush issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2339 | "with param1: %lu", param1); |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2340 | #ifdef _MSM8974_ |
| 2341 | send_codec_config(); |
| 2342 | #endif |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2343 | if (cmd == OMX_CommandFlush && (param1 == OMX_CORE_INPUT_PORT_INDEX || |
| 2344 | param1 == OMX_ALL)) { |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2345 | if (android_atomic_add(0, &m_queued_codec_config_count) > 0) { |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2346 | struct timespec ts; |
| 2347 | |
| 2348 | clock_gettime(CLOCK_REALTIME, &ts); |
| 2349 | ts.tv_sec += 2; |
| 2350 | DEBUG_PRINT_LOW("waiting for %d EBDs of CODEC CONFIG buffers ", |
| 2351 | m_queued_codec_config_count); |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2352 | BITMASK_SET(&m_flags, OMX_COMPONENT_FLUSH_DEFERRED); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2353 | if (sem_timedwait(&m_safe_flush, &ts)) { |
| 2354 | DEBUG_PRINT_ERROR("Failed to wait for EBDs of CODEC CONFIG buffers"); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2355 | } |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 2356 | BITMASK_CLEAR (&m_flags,OMX_COMPONENT_FLUSH_DEFERRED); |
Srinu Gorle | af1b9fb | 2014-08-29 19:40:27 +0530 | [diff] [blame] | 2357 | } |
| 2358 | } |
| 2359 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2360 | if (OMX_CORE_INPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2361 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING); |
| 2362 | } |
| 2363 | if (OMX_CORE_OUTPUT_PORT_INDEX == param1 || OMX_ALL == param1) { |
| 2364 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING); |
| 2365 | } |
| 2366 | if (!sem_posted) { |
| 2367 | sem_posted = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2368 | DEBUG_PRINT_LOW("Set the Semaphore"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2369 | sem_post (&m_cmd_lock); |
| 2370 | execute_omx_flush(param1); |
| 2371 | } |
| 2372 | bFlag = 0; |
| 2373 | } else if ( cmd == OMX_CommandPortEnable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2374 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortEnable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2375 | "with param1: %lu", param1); |
| 2376 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2377 | m_inp_bEnabled = OMX_TRUE; |
| 2378 | |
| 2379 | if ( (m_state == OMX_StateLoaded && |
| 2380 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2381 | || allocate_input_done()) { |
| 2382 | post_event(OMX_CommandPortEnable,OMX_CORE_INPUT_PORT_INDEX, |
| 2383 | OMX_COMPONENT_GENERATE_EVENT); |
| 2384 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2385 | DEBUG_PRINT_LOW("send_command_proxy(): Disabled-->Enabled Pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2386 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 2387 | // Skip the event notification |
| 2388 | bFlag = 0; |
| 2389 | } |
| 2390 | } |
| 2391 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2392 | DEBUG_PRINT_LOW("Enable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2393 | m_out_bEnabled = OMX_TRUE; |
| 2394 | |
| 2395 | if ( (m_state == OMX_StateLoaded && |
| 2396 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) |
| 2397 | || (allocate_output_done())) { |
| 2398 | post_event(OMX_CommandPortEnable,OMX_CORE_OUTPUT_PORT_INDEX, |
| 2399 | OMX_COMPONENT_GENERATE_EVENT); |
| 2400 | |
| 2401 | } else { |
Deva 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_OUTPUT_ENABLE_PENDING); |
| 2404 | // Skip the event notification |
| 2405 | bFlag = 0; |
| 2406 | } |
| 2407 | } |
| 2408 | } else if (cmd == OMX_CommandPortDisable) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2409 | DEBUG_PRINT_HIGH("send_command_proxy(): OMX_CommandPortDisable issued" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2410 | "with param1: %lu", param1); |
| 2411 | if (param1 == OMX_CORE_INPUT_PORT_INDEX || param1 == OMX_ALL) { |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 2412 | codec_config_flag = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2413 | m_inp_bEnabled = OMX_FALSE; |
| 2414 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2415 | && release_input_done()) { |
| 2416 | post_event(OMX_CommandPortDisable,OMX_CORE_INPUT_PORT_INDEX, |
| 2417 | OMX_COMPONENT_GENERATE_EVENT); |
| 2418 | } else { |
| 2419 | BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 2420 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2421 | if (!sem_posted) { |
| 2422 | sem_posted = 1; |
| 2423 | sem_post (&m_cmd_lock); |
| 2424 | } |
| 2425 | execute_omx_flush(OMX_CORE_INPUT_PORT_INDEX); |
| 2426 | } |
| 2427 | |
| 2428 | // Skip the event notification |
| 2429 | bFlag = 0; |
| 2430 | } |
| 2431 | } |
| 2432 | if (param1 == OMX_CORE_OUTPUT_PORT_INDEX || param1 == OMX_ALL) { |
| 2433 | m_out_bEnabled = OMX_FALSE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2434 | DEBUG_PRINT_LOW("Disable output Port command recieved"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2435 | if ((m_state == OMX_StateLoaded || m_state == OMX_StateIdle) |
| 2436 | && release_output_done()) { |
| 2437 | post_event(OMX_CommandPortDisable,OMX_CORE_OUTPUT_PORT_INDEX,\ |
| 2438 | OMX_COMPONENT_GENERATE_EVENT); |
| 2439 | } else { |
| 2440 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
| 2441 | if (m_state == OMX_StatePause ||m_state == OMX_StateExecuting) { |
| 2442 | if (!sem_posted) { |
| 2443 | sem_posted = 1; |
| 2444 | sem_post (&m_cmd_lock); |
| 2445 | } |
| 2446 | BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING); |
| 2447 | execute_omx_flush(OMX_CORE_OUTPUT_PORT_INDEX); |
| 2448 | } |
| 2449 | // Skip the event notification |
| 2450 | bFlag = 0; |
| 2451 | |
| 2452 | } |
| 2453 | } |
| 2454 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2455 | DEBUG_PRINT_ERROR("Error: Invalid Command other than StateSet (%d)",cmd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2456 | eRet = OMX_ErrorNotImplemented; |
| 2457 | } |
| 2458 | if (eRet == OMX_ErrorNone && bFlag) { |
| 2459 | post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT); |
| 2460 | } |
| 2461 | if (!sem_posted) { |
| 2462 | sem_post(&m_cmd_lock); |
| 2463 | } |
| 2464 | |
| 2465 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2469 | FUNCTION |
| 2470 | omx_vdec::ExecuteOmxFlush |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2471 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2472 | DESCRIPTION |
| 2473 | Executes the OMX flush. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2474 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2475 | PARAMETERS |
| 2476 | flushtype - input flush(1)/output flush(0)/ both. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2477 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2478 | RETURN VALUE |
| 2479 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2480 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2481 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2482 | bool omx_vdec::execute_omx_flush(OMX_U32 flushType) |
| 2483 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2484 | bool bRet = false; |
| 2485 | struct v4l2_plane plane; |
| 2486 | struct v4l2_buffer v4l2_buf; |
| 2487 | struct v4l2_decoder_cmd dec; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 2488 | DEBUG_PRINT_LOW("in %s, flushing %lu", __func__, flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2489 | memset((void *)&v4l2_buf,0,sizeof(v4l2_buf)); |
| 2490 | dec.cmd = V4L2_DEC_QCOM_CMD_FLUSH; |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2491 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2492 | DEBUG_PRINT_HIGH("in %s: reconfig? %d", __func__, in_reconfig); |
Deva Ramasubramanian | cc8fb90 | 2013-05-07 18:19:14 -0700 | [diff] [blame] | 2493 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2494 | if (in_reconfig && flushType == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 2495 | output_flush_progress = true; |
| 2496 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2497 | } else { |
| 2498 | /* XXX: The driver/hardware does not support flushing of individual ports |
| 2499 | * in all states. So we pretty much need to flush both ports internally, |
| 2500 | * but client should only get the FLUSH_(INPUT|OUTPUT)_DONE for the one it |
| 2501 | * requested. Since OMX_COMPONENT_(OUTPUT|INPUT)_FLUSH_PENDING isn't set, |
| 2502 | * we automatically omit sending the FLUSH done for the "opposite" port. */ |
| 2503 | input_flush_progress = true; |
| 2504 | output_flush_progress = true; |
| 2505 | dec.flags = V4L2_DEC_QCOM_CMD_FLUSH_OUTPUT | V4L2_DEC_QCOM_CMD_FLUSH_CAPTURE; |
| 2506 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2507 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2508 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_DECODER_CMD, &dec)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2509 | DEBUG_PRINT_ERROR("Flush Port (%lu) Failed ", flushType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2510 | bRet = false; |
| 2511 | } |
Deva Ramasubramanian | 03c9c74 | 2012-07-02 15:00:15 -0700 | [diff] [blame] | 2512 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2513 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2514 | } |
| 2515 | /*========================================================================= |
| 2516 | FUNCTION : execute_output_flush |
| 2517 | |
| 2518 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2519 | Executes the OMX flush at OUTPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2520 | |
| 2521 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2522 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2523 | |
| 2524 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2525 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2526 | ==========================================================================*/ |
| 2527 | bool omx_vdec::execute_output_flush() |
| 2528 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2529 | unsigned p1 = 0; // Parameter - 1 |
| 2530 | unsigned p2 = 0; // Parameter - 2 |
| 2531 | unsigned ident = 0; |
| 2532 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2533 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2534 | /*Generate FBD for all Buffers in the FTBq*/ |
| 2535 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2536 | DEBUG_PRINT_LOW("Initiate Output Flush"); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 2537 | |
| 2538 | //reset last render TS |
| 2539 | if(m_last_rendered_TS > 0) { |
| 2540 | m_last_rendered_TS = 0; |
| 2541 | } |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 2542 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2543 | while (m_ftb_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2544 | DEBUG_PRINT_LOW("Buffer queue size %d pending buf cnt %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2545 | m_ftb_q.m_size,pending_output_buffers); |
| 2546 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2547 | DEBUG_PRINT_LOW("ID(%x) P1(%x) P2(%x)", ident, p1, p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2548 | if (ident == m_fill_output_msg ) { |
| 2549 | m_cb.FillBufferDone(&m_cmp, m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2550 | } else if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 2551 | fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2552 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2553 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2554 | pthread_mutex_unlock(&m_lock); |
| 2555 | output_flush_progress = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2556 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2557 | if (arbitrary_bytes) { |
| 2558 | prev_ts = LLONG_MAX; |
| 2559 | rst_prev_ts = true; |
| 2560 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2561 | 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] | 2562 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2563 | } |
| 2564 | /*========================================================================= |
| 2565 | FUNCTION : execute_input_flush |
| 2566 | |
| 2567 | DESCRIPTION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2568 | Executes the OMX flush at INPUT PORT. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2569 | |
| 2570 | PARAMETERS |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2571 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2572 | |
| 2573 | RETURN VALUE |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2574 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2575 | ==========================================================================*/ |
| 2576 | bool omx_vdec::execute_input_flush() |
| 2577 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2578 | unsigned i =0; |
| 2579 | unsigned p1 = 0; // Parameter - 1 |
| 2580 | unsigned p2 = 0; // Parameter - 2 |
| 2581 | unsigned ident = 0; |
| 2582 | bool bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2583 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2584 | /*Generate EBD for all Buffers in the ETBq*/ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2585 | DEBUG_PRINT_LOW("Initiate Input Flush"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2586 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2587 | pthread_mutex_lock(&m_lock); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2588 | DEBUG_PRINT_LOW("Check if the Queue is empty"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2589 | while (m_etb_q.m_size) { |
| 2590 | m_etb_q.pop_entry(&p1,&p2,&ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2591 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2592 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2593 | DEBUG_PRINT_LOW("Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2594 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 2595 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 2596 | pending_input_buffers++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2597 | 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] | 2598 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 2599 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 2600 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2601 | DEBUG_PRINT_LOW("Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2602 | (OMX_BUFFERHEADERTYPE *)p1); |
| 2603 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 2604 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2605 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2606 | time_stamp_dts.flush_timestamp(); |
| 2607 | /*Check if Heap Buffers are to be flushed*/ |
| 2608 | if (arbitrary_bytes && !(codec_config_flag)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2609 | DEBUG_PRINT_LOW("Reset all the variables before flusing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2610 | h264_scratch.nFilledLen = 0; |
| 2611 | nal_count = 0; |
| 2612 | look_ahead_nal = false; |
| 2613 | frame_count = 0; |
| 2614 | h264_last_au_ts = LLONG_MAX; |
| 2615 | h264_last_au_flags = 0; |
| 2616 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 2617 | m_demux_entries = 0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2618 | DEBUG_PRINT_LOW("Initialize parser"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2619 | if (m_frame_parser.mutils) { |
| 2620 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 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 | while (m_input_pending_q.m_size) { |
| 2624 | m_input_pending_q.pop_entry(&p1,&p2,&ident); |
| 2625 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p1); |
| 2626 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2627 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2628 | if (psource_frame) { |
| 2629 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data,psource_frame); |
| 2630 | psource_frame = NULL; |
| 2631 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2632 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2633 | if (pdest_frame) { |
| 2634 | pdest_frame->nFilledLen = 0; |
| 2635 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned int)NULL, |
| 2636 | (unsigned int)NULL); |
| 2637 | pdest_frame = NULL; |
| 2638 | } |
| 2639 | m_frame_parser.flush(); |
| 2640 | } else if (codec_config_flag) { |
| 2641 | DEBUG_PRINT_HIGH("frame_parser flushing skipped due to codec config buffer " |
| 2642 | "is not sent to the driver yet"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2643 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2644 | pthread_mutex_unlock(&m_lock); |
| 2645 | input_flush_progress = false; |
| 2646 | if (!arbitrary_bytes) { |
| 2647 | prev_ts = LLONG_MAX; |
| 2648 | rst_prev_ts = true; |
| 2649 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2650 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2651 | if (m_debug_timestamp) { |
| 2652 | m_timestamp_list.reset_ts_list(); |
| 2653 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2654 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2655 | 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] | 2656 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | |
| 2660 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2661 | FUNCTION |
| 2662 | omx_vdec::SendCommandEvent |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2663 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2664 | DESCRIPTION |
| 2665 | Send the event to decoder pipe. This is needed to generate the callbacks |
| 2666 | in decoder thread context. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2667 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2668 | PARAMETERS |
| 2669 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2670 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2671 | RETURN VALUE |
| 2672 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2673 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2674 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2675 | bool omx_vdec::post_event(unsigned int p1, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2676 | unsigned int p2, |
| 2677 | unsigned int id) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2678 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2679 | bool bRet = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2680 | |
| 2681 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2682 | pthread_mutex_lock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2683 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2684 | if (id == m_fill_output_msg || |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 2685 | id == OMX_COMPONENT_GENERATE_FBD || |
| 2686 | id == OMX_COMPONENT_GENERATE_PORT_RECONFIG) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2687 | m_ftb_q.insert_entry(p1,p2,id); |
| 2688 | } else if (id == OMX_COMPONENT_GENERATE_ETB || |
| 2689 | id == OMX_COMPONENT_GENERATE_EBD || |
| 2690 | id == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 2691 | m_etb_q.insert_entry(p1,p2,id); |
| 2692 | } else { |
| 2693 | m_cmd_q.insert_entry(p1,p2,id); |
| 2694 | } |
Shalaj 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 | bRet = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2697 | DEBUG_PRINT_LOW("Value of this pointer in post_event %p",this); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2698 | post_message(this, id); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2699 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2700 | pthread_mutex_unlock(&m_lock); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2701 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2702 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | OMX_ERRORTYPE omx_vdec::get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType) |
| 2706 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2707 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2708 | if (!profileLevelType) |
| 2709 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2710 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2711 | if (profileLevelType->nPortIndex == 0) { |
| 2712 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 2713 | if (profileLevelType->nProfileIndex == 0) { |
| 2714 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline; |
| 2715 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
Shalaj 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 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2718 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain; |
| 2719 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2720 | } else if (profileLevelType->nProfileIndex == 2) { |
| 2721 | profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh; |
| 2722 | profileLevelType->eLevel = OMX_VIDEO_AVCLevel4; |
| 2723 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2724 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2725 | profileLevelType->nProfileIndex); |
| 2726 | eRet = OMX_ErrorNoMore; |
| 2727 | } |
| 2728 | } else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))) { |
| 2729 | if (profileLevelType->nProfileIndex == 0) { |
| 2730 | profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline; |
| 2731 | profileLevelType->eLevel = OMX_VIDEO_H263Level70; |
| 2732 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2733 | 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] | 2734 | eRet = OMX_ErrorNoMore; |
| 2735 | } |
| 2736 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 2737 | if (profileLevelType->nProfileIndex == 0) { |
| 2738 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple; |
| 2739 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2740 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2741 | profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple; |
| 2742 | profileLevelType->eLevel = OMX_VIDEO_MPEG4Level5; |
| 2743 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2744 | 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] | 2745 | eRet = OMX_ErrorNoMore; |
| 2746 | } |
| 2747 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 2748 | eRet = OMX_ErrorNoMore; |
| 2749 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 2750 | if (profileLevelType->nProfileIndex == 0) { |
| 2751 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileSimple; |
| 2752 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2753 | } else if (profileLevelType->nProfileIndex == 1) { |
| 2754 | profileLevelType->eProfile = OMX_VIDEO_MPEG2ProfileMain; |
| 2755 | profileLevelType->eLevel = OMX_VIDEO_MPEG2LevelHL; |
| 2756 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2757 | 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] | 2758 | eRet = OMX_ErrorNoMore; |
| 2759 | } |
| 2760 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2761 | 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] | 2762 | eRet = OMX_ErrorNoMore; |
| 2763 | } |
| 2764 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2765 | 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] | 2766 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2767 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2768 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2772 | FUNCTION |
| 2773 | omx_vdec::GetParameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2774 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2775 | DESCRIPTION |
| 2776 | OMX Get Parameter method implementation |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2777 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2778 | PARAMETERS |
| 2779 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2780 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2781 | RETURN VALUE |
| 2782 | Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2783 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2784 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2785 | OMX_ERRORTYPE omx_vdec::get_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2786 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 2787 | OMX_INOUT OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2788 | { |
| 2789 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 2790 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2791 | DEBUG_PRINT_LOW("get_parameter:"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2792 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2793 | DEBUG_PRINT_ERROR("Get Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2794 | return OMX_ErrorInvalidState; |
| 2795 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2796 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2797 | DEBUG_PRINT_LOW("Get Param in Invalid paramData"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2798 | return OMX_ErrorBadParameter; |
| 2799 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2800 | switch ((unsigned long)paramIndex) { |
| 2801 | case OMX_IndexParamPortDefinition: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2802 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2803 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = |
| 2804 | (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2805 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2806 | eRet = update_portdef(portDefn); |
| 2807 | if (eRet == OMX_ErrorNone) |
| 2808 | m_port_def = *portDefn; |
| 2809 | break; |
| 2810 | } |
| 2811 | case OMX_IndexParamVideoInit: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2812 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2813 | OMX_PORT_PARAM_TYPE *portParamType = |
| 2814 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2815 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2816 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2817 | portParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2818 | portParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2819 | portParamType->nPorts = 2; |
| 2820 | portParamType->nStartPortNumber = 0; |
| 2821 | break; |
| 2822 | } |
| 2823 | case OMX_IndexParamVideoPortFormat: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2824 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2825 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 2826 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2827 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2828 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2829 | portFmt->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2830 | portFmt->nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2831 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2832 | if (0 == portFmt->nPortIndex) { |
| 2833 | if (0 == portFmt->nIndex) { |
| 2834 | portFmt->eColorFormat = OMX_COLOR_FormatUnused; |
| 2835 | portFmt->eCompressionFormat = eCompressionFormat; |
| 2836 | } else { |
| 2837 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2838 | " NoMore compression formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2839 | eRet = OMX_ErrorNoMore; |
| 2840 | } |
| 2841 | } else if (1 == portFmt->nPortIndex) { |
| 2842 | portFmt->eCompressionFormat = OMX_VIDEO_CodingUnused; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2843 | |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2844 | // Distinguish non-surface mode from normal playback use-case based on |
| 2845 | // usage hinted via "OMX.google.android.index.useAndroidNativeBuffer2" |
| 2846 | // For non-android, use the default list |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 2847 | // Also use default format-list if FLEXIBLE YUV is supported, |
| 2848 | // as the client negotiates the standard color-format if it needs to |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2849 | bool useNonSurfaceMode = false; |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 2850 | #if defined(_ANDROID_) && !defined(FLEXYUV_SUPPORTED) |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 2851 | useNonSurfaceMode = (m_enable_android_native_buffers == OMX_FALSE); |
| 2852 | #endif |
| 2853 | portFmt->eColorFormat = useNonSurfaceMode ? |
| 2854 | getPreferredColorFormatNonSurfaceMode(portFmt->nIndex) : |
| 2855 | getPreferredColorFormatDefaultMode(portFmt->nIndex); |
| 2856 | |
| 2857 | if (portFmt->eColorFormat == OMX_COLOR_FormatMax ) { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2858 | eRet = OMX_ErrorNoMore; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2859 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat:"\ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2860 | " NoMore Color formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2861 | } |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 2862 | DEBUG_PRINT_HIGH("returning color-format: 0x%x", portFmt->eColorFormat); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2863 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2864 | DEBUG_PRINT_ERROR("get_parameter: Bad port index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2865 | (int)portFmt->nPortIndex); |
| 2866 | eRet = OMX_ErrorBadPortIndex; |
| 2867 | } |
| 2868 | break; |
| 2869 | } |
| 2870 | /*Component should support this port definition*/ |
| 2871 | case OMX_IndexParamAudioInit: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2872 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2873 | OMX_PORT_PARAM_TYPE *audioPortParamType = |
| 2874 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2875 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2876 | audioPortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2877 | audioPortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2878 | audioPortParamType->nPorts = 0; |
| 2879 | audioPortParamType->nStartPortNumber = 0; |
| 2880 | break; |
| 2881 | } |
| 2882 | /*Component should support this port definition*/ |
| 2883 | case OMX_IndexParamImageInit: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2884 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2885 | OMX_PORT_PARAM_TYPE *imagePortParamType = |
| 2886 | (OMX_PORT_PARAM_TYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2887 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2888 | imagePortParamType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2889 | imagePortParamType->nSize = sizeof(OMX_PORT_PARAM_TYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2890 | imagePortParamType->nPorts = 0; |
| 2891 | imagePortParamType->nStartPortNumber = 0; |
| 2892 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2893 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2894 | } |
| 2895 | /*Component should support this port definition*/ |
| 2896 | case OMX_IndexParamOtherInit: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2897 | DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamOtherInit %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2898 | paramIndex); |
| 2899 | eRet =OMX_ErrorUnsupportedIndex; |
| 2900 | break; |
| 2901 | } |
| 2902 | case OMX_IndexParamStandardComponentRole: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2903 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2904 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 2905 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
| 2906 | comp_role->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2907 | comp_role->nSize = sizeof(*comp_role); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2908 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2909 | DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2910 | paramIndex); |
| 2911 | strlcpy((char*)comp_role->cRole,(const char*)m_cRole, |
| 2912 | OMX_MAX_STRINGNAME_SIZE); |
| 2913 | break; |
| 2914 | } |
| 2915 | /* Added for parameter test */ |
| 2916 | case OMX_IndexParamPriorityMgmt: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2917 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2918 | OMX_PRIORITYMGMTTYPE *priorityMgmType = |
| 2919 | (OMX_PRIORITYMGMTTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2920 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2921 | priorityMgmType->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2922 | priorityMgmType->nSize = sizeof(OMX_PRIORITYMGMTTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2923 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2924 | break; |
| 2925 | } |
| 2926 | /* Added for parameter test */ |
| 2927 | case OMX_IndexParamCompBufferSupplier: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2928 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2929 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = |
| 2930 | (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2931 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2932 | |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2933 | bufferSupplierType->nSize = sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2934 | bufferSupplierType->nVersion.nVersion = OMX_SPEC_VERSION; |
| 2935 | if (0 == bufferSupplierType->nPortIndex) |
| 2936 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2937 | else if (1 == bufferSupplierType->nPortIndex) |
| 2938 | bufferSupplierType->nPortIndex = OMX_BufferSupplyUnspecified; |
| 2939 | else |
| 2940 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2941 | |
| 2942 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2943 | break; |
| 2944 | } |
| 2945 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2946 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2947 | paramIndex); |
| 2948 | break; |
| 2949 | } |
| 2950 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2951 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2952 | paramIndex); |
| 2953 | break; |
| 2954 | } |
| 2955 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2956 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2957 | paramIndex); |
| 2958 | break; |
| 2959 | } |
| 2960 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2961 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg2 %08x", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2962 | paramIndex); |
| 2963 | break; |
| 2964 | } |
| 2965 | case OMX_IndexParamVideoProfileLevelQuerySupported: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2966 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2967 | DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2968 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType = |
| 2969 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)paramData; |
| 2970 | eRet = get_supported_profile_level_for_1080p(profileLevelType); |
| 2971 | break; |
| 2972 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2973 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2974 | case OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2975 | VALIDATE_OMX_PARAM_DATA(paramData, GetAndroidNativeBufferUsageParams); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2976 | DEBUG_PRINT_LOW("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2977 | GetAndroidNativeBufferUsageParams* nativeBuffersUsage = (GetAndroidNativeBufferUsageParams *) paramData; |
| 2978 | if (nativeBuffersUsage->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2979 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2980 | if (secure_mode) { |
| 2981 | nativeBuffersUsage->nUsage = (GRALLOC_USAGE_PRIVATE_MM_HEAP | GRALLOC_USAGE_PROTECTED | |
| 2982 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2983 | } else { |
| 2984 | nativeBuffersUsage->nUsage = |
| 2985 | (GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | |
| 2986 | GRALLOC_USAGE_PRIVATE_UNCACHED); |
| 2987 | } |
| 2988 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 2989 | DEBUG_PRINT_HIGH("get_parameter: OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 2990 | eRet = OMX_ErrorBadParameter; |
| 2991 | } |
| 2992 | } |
| 2993 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 2994 | #endif |
| 2995 | |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 2996 | #ifdef FLEXYUV_SUPPORTED |
| 2997 | case OMX_QcomIndexFlexibleYUVDescription: { |
| 2998 | DEBUG_PRINT_LOW("get_parameter: describeColorFormat"); |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 2999 | VALIDATE_OMX_PARAM_DATA(paramData, DescribeColorFormatParams); |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 3000 | eRet = describeColorFormat(paramData); |
| 3001 | break; |
| 3002 | } |
| 3003 | #endif |
| 3004 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3005 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3006 | DEBUG_PRINT_ERROR("get_parameter: unknown param %08x", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3007 | eRet =OMX_ErrorUnsupportedIndex; |
| 3008 | } |
| 3009 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3012 | 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] | 3013 | drv_ctx.video_resolution.frame_width, |
| 3014 | drv_ctx.video_resolution.frame_height, |
| 3015 | drv_ctx.video_resolution.stride, |
| 3016 | drv_ctx.video_resolution.scan_lines); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3017 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3018 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
| 3022 | OMX_ERRORTYPE omx_vdec::use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data) |
| 3023 | { |
| 3024 | DEBUG_PRINT_LOW("Inside use_android_native_buffer"); |
| 3025 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 3026 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)data; |
| 3027 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3028 | if ((params == NULL) || |
| 3029 | (params->nativeBuffer == NULL) || |
| 3030 | (params->nativeBuffer->handle == NULL) || |
| 3031 | !m_enable_android_native_buffers) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3032 | return OMX_ErrorBadParameter; |
| 3033 | m_use_android_native_buffers = OMX_TRUE; |
| 3034 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 3035 | private_handle_t *handle = (private_handle_t *)nBuf->handle; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3036 | 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] | 3037 | OMX_U8 *buffer = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3038 | if (!secure_mode) { |
| 3039 | buffer = (OMX_U8*)mmap(0, handle->size, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3040 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3041 | if (buffer == MAP_FAILED) { |
| 3042 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 3043 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3044 | } |
| 3045 | } |
| 3046 | eRet = use_buffer(hComp,params->bufferHeader,params->nPortIndex,data,handle->size,buffer); |
| 3047 | } else { |
| 3048 | eRet = OMX_ErrorBadParameter; |
| 3049 | } |
| 3050 | return eRet; |
| 3051 | } |
| 3052 | #endif |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3053 | |
| 3054 | OMX_ERRORTYPE omx_vdec::enable_smoothstreaming() { |
| 3055 | struct v4l2_control control; |
| 3056 | struct v4l2_format fmt; |
| 3057 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER; |
| 3058 | control.value = 1; |
| 3059 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3060 | if (rc < 0) { |
| 3061 | DEBUG_PRINT_ERROR("Failed to enable Smooth Streaming on driver."); |
| 3062 | return OMX_ErrorHardware; |
| 3063 | } |
| 3064 | m_smoothstreaming_mode = true; |
| 3065 | return OMX_ErrorNone; |
| 3066 | } |
| 3067 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3068 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3069 | FUNCTION |
| 3070 | omx_vdec::Setparameter |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3071 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3072 | DESCRIPTION |
| 3073 | OMX Set Parameter method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3074 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3075 | PARAMETERS |
| 3076 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3077 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3078 | RETURN VALUE |
| 3079 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3080 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3081 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3082 | OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3083 | OMX_IN OMX_INDEXTYPE paramIndex, |
| 3084 | OMX_IN OMX_PTR paramData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3085 | { |
| 3086 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Praneeth Paladugu | 226667c | 2012-09-12 16:42:30 -0700 | [diff] [blame] | 3087 | int ret=0; |
| 3088 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3089 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3090 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3091 | return OMX_ErrorInvalidState; |
| 3092 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3093 | if (paramData == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3094 | DEBUG_PRINT_ERROR("Get Param in Invalid paramData"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3095 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3096 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3097 | if ((m_state != OMX_StateLoaded) && |
| 3098 | BITMASK_ABSENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING) && |
| 3099 | (m_out_bEnabled == OMX_TRUE) && |
| 3100 | BITMASK_ABSENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING) && |
| 3101 | (m_inp_bEnabled == OMX_TRUE)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3102 | DEBUG_PRINT_ERROR("Set Param in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3103 | return OMX_ErrorIncorrectStateOperation; |
| 3104 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3105 | switch ((unsigned long)paramIndex) { |
| 3106 | case OMX_IndexParamPortDefinition: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3107 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3108 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn; |
| 3109 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; |
| 3110 | //TODO: Check if any allocate buffer/use buffer/useNativeBuffer has |
| 3111 | //been called. |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3112 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3113 | (int)portDefn->format.video.nFrameHeight, |
| 3114 | (int)portDefn->format.video.nFrameWidth); |
| 3115 | if (OMX_DirOutput == portDefn->eDir) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3116 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition OP port"); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3117 | bool port_format_changed = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3118 | m_display_id = portDefn->format.video.pNativeWindow; |
| 3119 | unsigned int buffer_size; |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3120 | /* update output port resolution with client supplied dimensions |
| 3121 | in case scaling is enabled, else it follows input resolution set |
| 3122 | */ |
| 3123 | if (is_down_scalar_enabled) { |
| 3124 | DEBUG_PRINT_LOW("\n SetParam OP: WxH(%lu x %lu)\n", |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3125 | portDefn->format.video.nFrameWidth, |
| 3126 | portDefn->format.video.nFrameHeight); |
| 3127 | if (portDefn->format.video.nFrameHeight != 0x0 && |
| 3128 | portDefn->format.video.nFrameWidth != 0x0) { |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3129 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
| 3130 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3131 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3132 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 3133 | if (ret) { |
| 3134 | DEBUG_PRINT_ERROR("Get Resolution failed"); |
| 3135 | eRet = OMX_ErrorHardware; |
| 3136 | break; |
| 3137 | } |
| 3138 | if ((portDefn->format.video.nFrameHeight != (int)fmt.fmt.pix_mp.height) || |
| 3139 | (portDefn->format.video.nFrameWidth != (int)fmt.fmt.pix_mp.width)) { |
| 3140 | port_format_changed = true; |
| 3141 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3142 | update_resolution(portDefn->format.video.nFrameWidth, |
| 3143 | portDefn->format.video.nFrameHeight, |
| 3144 | portDefn->format.video.nFrameWidth, |
| 3145 | portDefn->format.video.nFrameHeight); |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3146 | |
| 3147 | /* set crop info */ |
| 3148 | rectangle.nLeft = 0; |
| 3149 | rectangle.nTop = 0; |
| 3150 | rectangle.nWidth = portDefn->format.video.nFrameWidth; |
| 3151 | rectangle.nHeight = portDefn->format.video.nFrameHeight; |
| 3152 | |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3153 | eRet = is_video_session_supported(); |
| 3154 | if (eRet) |
| 3155 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3156 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3157 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3158 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3159 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3160 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3161 | DEBUG_PRINT_LOW("\n fmt.fmt.pix_mp.height = %d , fmt.fmt.pix_mp.width = %d \n",fmt.fmt.pix_mp.height,fmt.fmt.pix_mp.width); |
| 3162 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3163 | if (ret) { |
| 3164 | DEBUG_PRINT_ERROR("\n Set Resolution failed"); |
| 3165 | eRet = OMX_ErrorUnsupportedSetting; |
| 3166 | } else |
| 3167 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3168 | } |
Praveen Chavan | e78460c | 2013-12-06 23:16:04 -0800 | [diff] [blame] | 3169 | } |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3170 | if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 3171 | DEBUG_PRINT_ERROR("Requested o/p buf count (%u) exceeds limit (%u)", |
| 3172 | portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS); |
| 3173 | eRet = OMX_ErrorBadParameter; |
| 3174 | } else if (!client_buffers.get_buffer_req(buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3175 | DEBUG_PRINT_ERROR("Error in getting buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3176 | eRet = OMX_ErrorBadParameter; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3177 | } else if (!port_format_changed) { |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3178 | |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 3179 | // Buffer count can change only when port is unallocated |
| 3180 | if (m_out_mem_ptr && |
| 3181 | (portDefn->nBufferCountActual != drv_ctx.op_buf.actualcount || |
| 3182 | portDefn->nBufferSize != drv_ctx.op_buf.buffer_size)) { |
| 3183 | |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3184 | DEBUG_PRINT_ERROR("Cannot change o/p buffer count since all buffers are not freed yet !"); |
| 3185 | eRet = OMX_ErrorInvalidState; |
| 3186 | break; |
| 3187 | } |
| 3188 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3189 | if ( portDefn->nBufferCountActual >= drv_ctx.op_buf.mincount && |
| 3190 | portDefn->nBufferSize >= drv_ctx.op_buf.buffer_size ) { |
| 3191 | drv_ctx.op_buf.actualcount = portDefn->nBufferCountActual; |
| 3192 | drv_ctx.op_buf.buffer_size = portDefn->nBufferSize; |
| 3193 | drv_ctx.extradata_info.count = drv_ctx.op_buf.actualcount; |
| 3194 | drv_ctx.extradata_info.size = drv_ctx.extradata_info.count * |
| 3195 | drv_ctx.extradata_info.buffer_size; |
| 3196 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 3197 | if (eRet == OMX_ErrorNone) |
| 3198 | m_port_def = *portDefn; |
| 3199 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3200 | DEBUG_PRINT_ERROR("ERROR: OP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3201 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size, |
| 3202 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3203 | eRet = OMX_ErrorBadParameter; |
| 3204 | } |
| 3205 | } |
| 3206 | } else if (OMX_DirInput == portDefn->eDir) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3207 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition IP port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3208 | bool port_format_changed = false; |
| 3209 | if ((portDefn->format.video.xFramerate >> 16) > 0 && |
| 3210 | (portDefn->format.video.xFramerate >> 16) <= MAX_SUPPORTED_FPS) { |
| 3211 | // Frame rate only should be set if this is a "known value" or to |
| 3212 | // activate ts prediction logic (arbitrary mode only) sending input |
| 3213 | // timestamps with max value (LLONG_MAX). |
| 3214 | DEBUG_PRINT_HIGH("set_parameter: frame rate set by omx client : %lu", |
| 3215 | portDefn->format.video.xFramerate >> 16); |
| 3216 | Q16ToFraction(portDefn->format.video.xFramerate, drv_ctx.frame_rate.fps_numerator, |
| 3217 | drv_ctx.frame_rate.fps_denominator); |
| 3218 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 3219 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 3220 | drv_ctx.frame_rate.fps_numerator = 30; |
| 3221 | } |
| 3222 | if (drv_ctx.frame_rate.fps_denominator) |
| 3223 | drv_ctx.frame_rate.fps_numerator = (int) |
| 3224 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 3225 | drv_ctx.frame_rate.fps_denominator = 1; |
| 3226 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 3227 | drv_ctx.frame_rate.fps_numerator; |
| 3228 | DEBUG_PRINT_LOW("set_parameter: frm_int(%lu) fps(%.2f)", |
| 3229 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 3230 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3231 | |
| 3232 | struct v4l2_outputparm oparm; |
| 3233 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 3234 | * per second.*/ |
| 3235 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 3236 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 3237 | |
| 3238 | struct v4l2_streamparm sparm; |
| 3239 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3240 | sparm.parm.output = oparm; |
| 3241 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 3242 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, performance might be affected"); |
| 3243 | eRet = OMX_ErrorHardware; |
| 3244 | break; |
| 3245 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3246 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 3247 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3248 | if (drv_ctx.video_resolution.frame_height != |
| 3249 | portDefn->format.video.nFrameHeight || |
| 3250 | drv_ctx.video_resolution.frame_width != |
| 3251 | portDefn->format.video.nFrameWidth) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3252 | DEBUG_PRINT_LOW("SetParam IP: WxH(%lu x %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3253 | portDefn->format.video.nFrameWidth, |
| 3254 | portDefn->format.video.nFrameHeight); |
| 3255 | port_format_changed = true; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3256 | OMX_U32 frameWidth = portDefn->format.video.nFrameWidth; |
| 3257 | OMX_U32 frameHeight = portDefn->format.video.nFrameHeight; |
| 3258 | if (frameHeight != 0x0 && frameWidth != 0x0) { |
| 3259 | if (m_smoothstreaming_mode && |
| 3260 | ((frameWidth * frameHeight) < |
| 3261 | (m_smoothstreaming_width * m_smoothstreaming_height))) { |
| 3262 | frameWidth = m_smoothstreaming_width; |
| 3263 | frameHeight = m_smoothstreaming_height; |
| 3264 | DEBUG_PRINT_LOW("NOTE: Setting resolution %lu x %lu for adaptive-playback/smooth-streaming", |
| 3265 | frameWidth, frameHeight); |
| 3266 | } |
| 3267 | update_resolution(frameWidth, frameHeight, |
| 3268 | frameWidth, frameHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3269 | eRet = is_video_session_supported(); |
| 3270 | if (eRet) |
| 3271 | break; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3272 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3273 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 3274 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3275 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3276 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3277 | 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] | 3278 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3279 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3280 | DEBUG_PRINT_ERROR("Set Resolution failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3281 | eRet = OMX_ErrorUnsupportedSetting; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 3282 | } else { |
| 3283 | if (!is_down_scalar_enabled) |
| 3284 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3285 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3286 | } |
| 3287 | } |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3288 | if (m_custom_buffersize.input_buffersize |
| 3289 | && (portDefn->nBufferSize > m_custom_buffersize.input_buffersize)) { |
| 3290 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size set by client: %d, trying to set: %d", |
| 3291 | m_custom_buffersize.input_buffersize, portDefn->nBufferSize); |
| 3292 | eRet = OMX_ErrorBadParameter; |
| 3293 | break; |
| 3294 | } |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3295 | if (portDefn->nBufferCountActual > MAX_NUM_INPUT_OUTPUT_BUFFERS) { |
| 3296 | DEBUG_PRINT_ERROR("Requested i/p buf count (%u) exceeds limit (%u)", |
| 3297 | portDefn->nBufferCountActual, MAX_NUM_INPUT_OUTPUT_BUFFERS); |
| 3298 | eRet = OMX_ErrorBadParameter; |
| 3299 | break; |
| 3300 | } |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 3301 | // Buffer count can change only when port is unallocated |
| 3302 | if (m_inp_mem_ptr && |
| 3303 | (portDefn->nBufferCountActual != drv_ctx.ip_buf.actualcount || |
| 3304 | portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size)) { |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 3305 | DEBUG_PRINT_ERROR("Cannot change i/p buffer count since all buffers are not freed yet !"); |
| 3306 | eRet = OMX_ErrorInvalidState; |
| 3307 | break; |
| 3308 | } |
| 3309 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3310 | if (portDefn->nBufferCountActual >= drv_ctx.ip_buf.mincount |
| 3311 | || portDefn->nBufferSize != drv_ctx.ip_buf.buffer_size) { |
| 3312 | port_format_changed = true; |
| 3313 | vdec_allocatorproperty *buffer_prop = &drv_ctx.ip_buf; |
| 3314 | drv_ctx.ip_buf.actualcount = portDefn->nBufferCountActual; |
| 3315 | drv_ctx.ip_buf.buffer_size = (portDefn->nBufferSize + buffer_prop->alignment - 1) & |
| 3316 | (~(buffer_prop->alignment - 1)); |
| 3317 | eRet = set_buffer_req(buffer_prop); |
| 3318 | } |
| 3319 | if (false == port_format_changed) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3320 | DEBUG_PRINT_ERROR("ERROR: IP Requirements(#%d: %u) Requested(#%lu: %lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3321 | drv_ctx.ip_buf.mincount, drv_ctx.ip_buf.buffer_size, |
| 3322 | portDefn->nBufferCountActual, portDefn->nBufferSize); |
| 3323 | eRet = OMX_ErrorBadParameter; |
| 3324 | } |
| 3325 | } else if (portDefn->eDir == OMX_DirMax) { |
| 3326 | DEBUG_PRINT_ERROR(" Set_parameter: Bad Port idx %d", |
| 3327 | (int)portDefn->nPortIndex); |
| 3328 | eRet = OMX_ErrorBadPortIndex; |
| 3329 | } |
| 3330 | } |
| 3331 | break; |
| 3332 | case OMX_IndexParamVideoPortFormat: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3333 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3334 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = |
| 3335 | (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; |
| 3336 | int ret=0; |
| 3337 | struct v4l2_format fmt; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3338 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3339 | portFmt->eColorFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3340 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3341 | if (1 == portFmt->nPortIndex) { |
| 3342 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 3343 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 3344 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 3345 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 3346 | enum vdec_output_fromat op_format; |
| 3347 | if ((portFmt->eColorFormat == (OMX_COLOR_FORMATTYPE) |
| 3348 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m) || |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 3349 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 3350 | (portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3351 | op_format = (enum vdec_output_fromat)VDEC_YUV_FORMAT_NV12; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3352 | else |
| 3353 | eRet = OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3354 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3355 | if (eRet == OMX_ErrorNone) { |
| 3356 | drv_ctx.output_format = op_format; |
| 3357 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 3358 | if (ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3359 | DEBUG_PRINT_ERROR("Set output format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3360 | eRet = OMX_ErrorUnsupportedSetting; |
| 3361 | /*TODO: How to handle this case */ |
| 3362 | } else { |
| 3363 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 3364 | } |
| 3365 | } |
| 3366 | if (eRet == OMX_ErrorNone) { |
| 3367 | if (!client_buffers.set_color_format(portFmt->eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3368 | DEBUG_PRINT_ERROR("Set color format failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3369 | eRet = OMX_ErrorBadParameter; |
| 3370 | } |
| 3371 | } |
| 3372 | } |
| 3373 | } |
| 3374 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3375 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3376 | case OMX_QcomIndexPortDefn: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3377 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3378 | OMX_QCOM_PARAM_PORTDEFINITIONTYPE *portFmt = |
| 3379 | (OMX_QCOM_PARAM_PORTDEFINITIONTYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3380 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexQcomParamPortDefinitionType %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3381 | portFmt->nFramePackingFormat); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3382 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3383 | /* Input port */ |
| 3384 | if (portFmt->nPortIndex == 0) { |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 3385 | // arbitrary_bytes mode cannot be changed arbitrarily since this controls how: |
| 3386 | // - headers are allocated and |
| 3387 | // - headers-indices are derived |
| 3388 | // Avoid changing arbitrary_bytes when the port is already allocated |
| 3389 | if (m_inp_mem_ptr) { |
| 3390 | DEBUG_PRINT_ERROR("Cannot change arbitrary-bytes-mode since input port is not free!"); |
| 3391 | return OMX_ErrorUnsupportedSetting; |
| 3392 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3393 | if (portFmt->nFramePackingFormat == OMX_QCOM_FramePacking_Arbitrary) { |
| 3394 | if (secure_mode) { |
| 3395 | arbitrary_bytes = false; |
| 3396 | DEBUG_PRINT_ERROR("setparameter: cannot set to arbitary bytes mode in secure session"); |
| 3397 | eRet = OMX_ErrorUnsupportedSetting; |
| 3398 | } else { |
| 3399 | arbitrary_bytes = true; |
| 3400 | } |
| 3401 | } else if (portFmt->nFramePackingFormat == |
| 3402 | OMX_QCOM_FramePacking_OnlyOneCompleteFrame) { |
| 3403 | arbitrary_bytes = false; |
| 3404 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3405 | DEBUG_PRINT_ERROR("Setparameter: unknown FramePacking format %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3406 | portFmt->nFramePackingFormat); |
| 3407 | eRet = OMX_ErrorUnsupportedSetting; |
| 3408 | } |
| 3409 | } else if (portFmt->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3410 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3411 | if ( (portFmt->nMemRegion > OMX_QCOM_MemRegionInvalid && |
| 3412 | portFmt->nMemRegion < OMX_QCOM_MemRegionMax) && |
| 3413 | portFmt->nCacheAttr == OMX_QCOM_CacheAttrNone) { |
| 3414 | m_out_mem_region_smi = OMX_TRUE; |
| 3415 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3416 | DEBUG_PRINT_HIGH("set_parameter: OMX_IndexQcomParamPortDefinitionType OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3417 | m_use_output_pmem = OMX_TRUE; |
| 3418 | } |
| 3419 | } |
| 3420 | } |
| 3421 | } |
| 3422 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3423 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3424 | case OMX_IndexParamStandardComponentRole: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3425 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3426 | OMX_PARAM_COMPONENTROLETYPE *comp_role; |
| 3427 | comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3428 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3429 | comp_role->cRole); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3430 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3431 | if ((m_state == OMX_StateLoaded)&& |
| 3432 | !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 3433 | DEBUG_PRINT_LOW("Set Parameter called in valid state"); |
| 3434 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3435 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3436 | return OMX_ErrorIncorrectStateOperation; |
| 3437 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3438 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3439 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3440 | if (!strncmp((char*)comp_role->cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 3441 | strlcpy((char*)m_cRole,"video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
| 3442 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3443 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3444 | eRet =OMX_ErrorUnsupportedSetting; |
| 3445 | } |
| 3446 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3447 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 3448 | strlcpy((char*)m_cRole,"video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
| 3449 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3450 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3451 | eRet = OMX_ErrorUnsupportedSetting; |
| 3452 | } |
| 3453 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3454 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 3455 | strlcpy((char*)m_cRole,"video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
| 3456 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3457 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3458 | eRet =OMX_ErrorUnsupportedSetting; |
| 3459 | } |
| 3460 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3461 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 3462 | strlcpy((char*)m_cRole,"video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
| 3463 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3464 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3465 | eRet = OMX_ErrorUnsupportedSetting; |
| 3466 | } |
| 3467 | } 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] | 3468 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311", OMX_MAX_STRINGNAME_SIZE)) || |
| 3469 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx4", OMX_MAX_STRINGNAME_SIZE)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3470 | ) { |
| 3471 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE)) { |
| 3472 | strlcpy((char*)m_cRole,"video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
| 3473 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3474 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3475 | eRet =OMX_ErrorUnsupportedSetting; |
| 3476 | } |
| 3477 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 3478 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 3479 | ) { |
| 3480 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) { |
| 3481 | strlcpy((char*)m_cRole,"video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
| 3482 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3483 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3484 | eRet =OMX_ErrorUnsupportedSetting; |
| 3485 | } |
| 3486 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 3487 | if (!strncmp((const char*)comp_role->cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE) || |
| 3488 | (!strncmp((const char*)comp_role->cRole,"video_decoder.vpx",OMX_MAX_STRINGNAME_SIZE))) { |
| 3489 | strlcpy((char*)m_cRole,"video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
| 3490 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3491 | DEBUG_PRINT_ERROR("Setparameter: unknown Index %s", comp_role->cRole); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3492 | eRet = OMX_ErrorUnsupportedSetting; |
| 3493 | } |
| 3494 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3495 | DEBUG_PRINT_ERROR("Setparameter: unknown param %s", drv_ctx.kind); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3496 | eRet = OMX_ErrorInvalidComponentName; |
| 3497 | } |
| 3498 | break; |
| 3499 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3500 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3501 | case OMX_IndexParamPriorityMgmt: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3502 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3503 | if (m_state != OMX_StateLoaded) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3504 | DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3505 | return OMX_ErrorIncorrectStateOperation; |
| 3506 | } |
| 3507 | OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3508 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3509 | priorityMgmtype->nGroupID); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3510 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3511 | DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3512 | priorityMgmtype->nGroupPriority); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3513 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3514 | m_priority_mgm.nGroupID = priorityMgmtype->nGroupID; |
| 3515 | m_priority_mgm.nGroupPriority = priorityMgmtype->nGroupPriority; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3516 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3517 | break; |
| 3518 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3519 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3520 | case OMX_IndexParamCompBufferSupplier: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3521 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3522 | OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3523 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3524 | bufferSupplierType->eBufferSupplier); |
| 3525 | if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1) |
| 3526 | m_buffer_supplier.eBufferSupplier = bufferSupplierType->eBufferSupplier; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3527 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3528 | else |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3529 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3530 | eRet = OMX_ErrorBadPortIndex; |
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 | break; |
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 | } |
| 3535 | case OMX_IndexParamVideoAvc: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3536 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3537 | paramIndex); |
| 3538 | break; |
| 3539 | } |
| 3540 | case OMX_IndexParamVideoH263: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3541 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3542 | paramIndex); |
| 3543 | break; |
| 3544 | } |
| 3545 | case OMX_IndexParamVideoMpeg4: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3546 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3547 | paramIndex); |
| 3548 | break; |
| 3549 | } |
| 3550 | case OMX_IndexParamVideoMpeg2: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3551 | DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg2 %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3552 | paramIndex); |
| 3553 | break; |
| 3554 | } |
| 3555 | case OMX_QcomIndexParamVideoDecoderPictureOrder: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3556 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_DECODER_PICTURE_ORDER); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3557 | QOMX_VIDEO_DECODER_PICTURE_ORDER *pictureOrder = |
| 3558 | (QOMX_VIDEO_DECODER_PICTURE_ORDER *)paramData; |
| 3559 | struct v4l2_control control; |
| 3560 | int pic_order,rc=0; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3561 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoDecoderPictureOrder %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3562 | pictureOrder->eOutputPictureOrder); |
| 3563 | if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DISPLAY_ORDER) { |
| 3564 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY; |
| 3565 | } else if (pictureOrder->eOutputPictureOrder == QOMX_VIDEO_DECODE_ORDER) { |
| 3566 | pic_order = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3567 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3568 | } else |
| 3569 | eRet = OMX_ErrorBadParameter; |
| 3570 | if (eRet == OMX_ErrorNone) { |
| 3571 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3572 | control.value = pic_order; |
| 3573 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3574 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3575 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3576 | eRet = OMX_ErrorUnsupportedSetting; |
| 3577 | } |
| 3578 | } |
| 3579 | break; |
| 3580 | } |
| 3581 | case OMX_QcomIndexParamConcealMBMapExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3582 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3583 | eRet = enable_extradata(VDEC_EXTRADATA_MB_ERROR_MAP, false, |
| 3584 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3585 | break; |
| 3586 | case OMX_QcomIndexParamFrameInfoExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3587 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3588 | eRet = enable_extradata(OMX_FRAMEINFO_EXTRADATA, false, |
| 3589 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3590 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3591 | case OMX_QcomIndexParamInterlaceExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3592 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3593 | eRet = enable_extradata(OMX_INTERLACE_EXTRADATA, false, |
| 3594 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3595 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3596 | case OMX_QcomIndexParamH264TimeInfo: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3597 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3598 | eRet = enable_extradata(OMX_TIMEINFO_EXTRADATA, false, |
| 3599 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3600 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3601 | case OMX_QcomIndexParamVideoFramePackingExtradata: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3602 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3603 | eRet = enable_extradata(OMX_FRAMEPACK_EXTRADATA, false, |
| 3604 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3605 | break; |
| 3606 | case OMX_QcomIndexParamVideoQPExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3607 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3608 | eRet = enable_extradata(OMX_QP_EXTRADATA, false, |
| 3609 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3610 | break; |
| 3611 | case OMX_QcomIndexParamVideoInputBitsInfoExtraData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3612 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3613 | eRet = enable_extradata(OMX_BITSINFO_EXTRADATA, false, |
| 3614 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3615 | break; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 3616 | case OMX_QcomIndexEnableExtnUserData: |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3617 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 3618 | eRet = enable_extradata(OMX_EXTNUSER_EXTRADATA, false, |
| 3619 | ((QOMX_ENABLETYPE *)paramData)->bEnable); |
| 3620 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3621 | case OMX_QcomIndexParamVideoDivx: { |
| 3622 | QOMX_VIDEO_PARAM_DIVXTYPE* divXType = (QOMX_VIDEO_PARAM_DIVXTYPE *) paramData; |
| 3623 | } |
| 3624 | break; |
| 3625 | case OMX_QcomIndexPlatformPvt: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3626 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PLATFORMPRIVATE_EXTN); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3627 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3628 | OMX_QCOM_PLATFORMPRIVATE_EXTN* entryType = (OMX_QCOM_PLATFORMPRIVATE_EXTN *) paramData; |
| 3629 | if (entryType->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
| 3630 | DEBUG_PRINT_HIGH("set_parameter: Platform Private entry type (%d) not supported.", entryType->type); |
| 3631 | eRet = OMX_ErrorUnsupportedSetting; |
| 3632 | } else { |
| 3633 | m_out_pvt_entry_pmem = OMX_TRUE; |
| 3634 | if ((m_out_mem_region_smi && m_out_pvt_entry_pmem)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3635 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexPlatformPvt OP Port: out pmem set"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3636 | m_use_output_pmem = OMX_TRUE; |
| 3637 | } |
| 3638 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3639 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3640 | } |
| 3641 | break; |
| 3642 | case OMX_QcomIndexParamVideoSyncFrameDecodingMode: { |
| 3643 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamVideoSyncFrameDecodingMode"); |
| 3644 | DEBUG_PRINT_HIGH("set idr only decoding for thumbnail mode"); |
| 3645 | struct v4l2_control control; |
| 3646 | int rc; |
| 3647 | drv_ctx.idr_only_decoding = 1; |
| 3648 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER; |
| 3649 | control.value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE; |
| 3650 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3651 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3652 | DEBUG_PRINT_ERROR("Set picture order failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3653 | eRet = OMX_ErrorUnsupportedSetting; |
| 3654 | } else { |
| 3655 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE; |
| 3656 | control.value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE; |
| 3657 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control); |
| 3658 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3659 | DEBUG_PRINT_ERROR("Sync frame setting failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3660 | eRet = OMX_ErrorUnsupportedSetting; |
| 3661 | } |
| 3662 | /*Setting sync frame decoding on driver might change buffer |
| 3663 | * requirements so update them here*/ |
| 3664 | if (get_buffer_req(&drv_ctx.ip_buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3665 | 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] | 3666 | eRet = OMX_ErrorUnsupportedSetting; |
| 3667 | } |
| 3668 | if (get_buffer_req(&drv_ctx.op_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 o/p requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3670 | eRet = OMX_ErrorUnsupportedSetting; |
| 3671 | } |
| 3672 | } |
| 3673 | } |
| 3674 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3675 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3676 | case OMX_QcomIndexParamIndexExtraDataType: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3677 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXEXTRADATATYPE); |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 3678 | QOMX_INDEXEXTRADATATYPE *extradataIndexType = (QOMX_INDEXEXTRADATATYPE *) paramData; |
| 3679 | if ((extradataIndexType->nIndex == OMX_IndexParamPortDefinition) && |
| 3680 | (extradataIndexType->bEnabled == OMX_TRUE) && |
| 3681 | (extradataIndexType->nPortIndex == 1)) { |
| 3682 | DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType SmoothStreaming"); |
| 3683 | eRet = enable_extradata(OMX_PORTDEF_EXTRADATA, false, extradataIndexType->bEnabled); |
| 3684 | } |
| 3685 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3686 | break; |
| 3687 | case OMX_QcomIndexParamEnableSmoothStreaming: { |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3688 | #ifndef SMOOTH_STREAMING_DISABLED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3689 | eRet = enable_smoothstreaming(); |
Arun Menon | bc0922f | 2013-06-24 13:02:15 -0700 | [diff] [blame] | 3690 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3691 | eRet = OMX_ErrorUnsupportedSetting; |
Arun Menon | c821d8a | 2013-06-15 10:03:29 -0700 | [diff] [blame] | 3692 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3693 | } |
| 3694 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3695 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3696 | /* Need to allow following two set_parameters even in Idle |
| 3697 | * state. This is ANDROID architecture which is not in sync |
| 3698 | * with openmax standard. */ |
| 3699 | case OMX_GoogleAndroidIndexEnableAndroidNativeBuffers: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3700 | VALIDATE_OMX_PARAM_DATA(paramData, EnableAndroidNativeBuffersParams); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3701 | EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData; |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 3702 | if (enableNativeBuffers->nPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3703 | DEBUG_PRINT_ERROR("Enable/Disable android-native-buffers allowed only on output port!"); |
| 3704 | eRet = OMX_ErrorUnsupportedSetting; |
| 3705 | break; |
| 3706 | } else if (m_out_mem_ptr) { |
| 3707 | DEBUG_PRINT_ERROR("Enable/Disable android-native-buffers is not allowed since Output port is not free !"); |
| 3708 | eRet = OMX_ErrorInvalidState; |
| 3709 | break; |
| 3710 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3711 | if (enableNativeBuffers) { |
| 3712 | m_enable_android_native_buffers = enableNativeBuffers->enable; |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 3713 | } |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 3714 | #if !defined(FLEXYUV_SUPPORTED) |
Manikanta Kanamarlapudi | 78b7fb6 | 2014-04-04 11:46:02 -0700 | [diff] [blame] | 3715 | if (m_enable_android_native_buffers) { |
| 3716 | // Use the most-preferred-native-color-format as surface-mode is hinted here |
| 3717 | if(!client_buffers.set_color_format(getPreferredColorFormatDefaultMode(0))) { |
| 3718 | DEBUG_PRINT_ERROR("Failed to set native color format!"); |
| 3719 | eRet = OMX_ErrorUnsupportedSetting; |
| 3720 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3721 | } |
Praveen Chavan | cac8640 | 2014-10-18 09:14:52 -0700 | [diff] [blame] | 3722 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3723 | } |
| 3724 | break; |
| 3725 | case OMX_GoogleAndroidIndexUseAndroidNativeBuffer: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3726 | VALIDATE_OMX_PARAM_DATA(paramData, UseAndroidNativeBufferParams); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3727 | eRet = use_android_native_buffer(hComp, paramData); |
| 3728 | } |
| 3729 | break; |
Praveen Chavan | d443c0d | 2016-04-19 12:25:46 -0700 | [diff] [blame] | 3730 | #if ALLOCATE_OUTPUT_NATIVEHANDLE |
| 3731 | case OMX_GoogleAndroidIndexAllocateNativeHandle: { |
| 3732 | AllocateNativeHandleParams* allocateNativeHandleParams = (AllocateNativeHandleParams *) paramData; |
| 3733 | if (allocateNativeHandleParams != NULL) { |
| 3734 | allocate_native_handle = allocateNativeHandleParams->enable; |
| 3735 | } |
| 3736 | } |
| 3737 | break; |
| 3738 | #endif //ALLOCATE_OUTPUT_NATIVEHANDLE |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3739 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3740 | case OMX_QcomIndexParamEnableTimeStampReorder: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3741 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXTIMESTAMPREORDER); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3742 | QOMX_INDEXTIMESTAMPREORDER *reorder = (QOMX_INDEXTIMESTAMPREORDER *)paramData; |
| 3743 | if (drv_ctx.picture_order == (vdec_output_order)QOMX_VIDEO_DISPLAY_ORDER) { |
| 3744 | if (reorder->bEnable == OMX_TRUE) { |
| 3745 | frm_int =0; |
| 3746 | time_stamp_dts.set_timestamp_reorder_mode(true); |
| 3747 | } else |
| 3748 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3749 | } else { |
| 3750 | time_stamp_dts.set_timestamp_reorder_mode(false); |
| 3751 | if (reorder->bEnable == OMX_TRUE) { |
| 3752 | eRet = OMX_ErrorUnsupportedSetting; |
| 3753 | } |
| 3754 | } |
| 3755 | } |
| 3756 | break; |
| 3757 | case OMX_IndexParamVideoProfileLevelCurrent: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3758 | VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3759 | OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = |
| 3760 | (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData; |
| 3761 | if (pParam) { |
| 3762 | m_profile_lvl.eProfile = pParam->eProfile; |
| 3763 | m_profile_lvl.eLevel = pParam->eLevel; |
| 3764 | } |
| 3765 | break; |
Arun Menon | 888aa85 | 2013-05-30 11:24:42 -0700 | [diff] [blame] | 3766 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3767 | } |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3768 | case OMX_QcomIndexParamVideoMetaBufferMode: |
| 3769 | { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3770 | VALIDATE_OMX_PARAM_DATA(paramData, StoreMetaDataInBuffersParams); |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3771 | StoreMetaDataInBuffersParams *metabuffer = |
| 3772 | (StoreMetaDataInBuffersParams *)paramData; |
| 3773 | if (!metabuffer) { |
| 3774 | DEBUG_PRINT_ERROR("Invalid param: %p", metabuffer); |
| 3775 | eRet = OMX_ErrorBadParameter; |
| 3776 | break; |
| 3777 | } |
| 3778 | if (metabuffer->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 3779 | |
| 3780 | if (m_out_mem_ptr) { |
| 3781 | DEBUG_PRINT_ERROR("Enable/Disable dynamic-buffer-mode is not allowed since Output port is not free !"); |
| 3782 | eRet = OMX_ErrorInvalidState; |
| 3783 | break; |
| 3784 | } |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3785 | //set property dynamic buffer mode to driver. |
| 3786 | struct v4l2_control control; |
| 3787 | struct v4l2_format fmt; |
| 3788 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_ALLOC_MODE_OUTPUT; |
| 3789 | if (metabuffer->bStoreMetaData == true) { |
| 3790 | control.value = V4L2_MPEG_VIDC_VIDEO_DYNAMIC; |
| 3791 | } else { |
| 3792 | control.value = V4L2_MPEG_VIDC_VIDEO_STATIC; |
| 3793 | } |
| 3794 | int rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3795 | if (!rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3796 | DEBUG_PRINT_HIGH("%s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3797 | (metabuffer->bStoreMetaData == true)? "Enabled dynamic" : "Disabled dynamic"); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 3798 | dynamic_buf_mode = metabuffer->bStoreMetaData; |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3799 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3800 | DEBUG_PRINT_ERROR("Failed to %s buffer mode", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3801 | (metabuffer->bStoreMetaData == true)? "enable dynamic" : "disable dynamic"); |
| 3802 | eRet = OMX_ErrorUnsupportedSetting; |
| 3803 | } |
| 3804 | } else { |
| 3805 | DEBUG_PRINT_ERROR( |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3806 | "OMX_QcomIndexParamVideoMetaBufferMode not supported for port: %lu", |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 3807 | metabuffer->nPortIndex); |
| 3808 | eRet = OMX_ErrorUnsupportedSetting; |
| 3809 | } |
| 3810 | break; |
| 3811 | } |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3812 | case OMX_QcomIndexParamVideoDownScalar: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3813 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXDOWNSCALAR); |
Praneeth Paladugu | 42306bb | 2013-08-27 22:01:28 -0700 | [diff] [blame] | 3814 | QOMX_INDEXDOWNSCALAR* pParam = (QOMX_INDEXDOWNSCALAR*)paramData; |
| 3815 | struct v4l2_control control; |
| 3816 | int rc; |
| 3817 | if (pParam) { |
| 3818 | is_down_scalar_enabled = pParam->bEnable; |
| 3819 | if (is_down_scalar_enabled) { |
| 3820 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE; |
| 3821 | control.value = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY; |
| 3822 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoDownScalar value = %d\n", |
| 3823 | pParam->bEnable); |
| 3824 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3825 | if (rc < 0) { |
| 3826 | DEBUG_PRINT_ERROR("Failed to set down scalar on driver."); |
| 3827 | eRet = OMX_ErrorUnsupportedSetting; |
| 3828 | } |
| 3829 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_KEEP_ASPECT_RATIO; |
| 3830 | control.value = 1; |
| 3831 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL,&control); |
| 3832 | if (rc < 0) { |
| 3833 | DEBUG_PRINT_ERROR("Failed to set keep aspect ratio on driver."); |
| 3834 | eRet = OMX_ErrorUnsupportedSetting; |
| 3835 | } |
| 3836 | } |
| 3837 | } |
| 3838 | break; |
| 3839 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3840 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
| 3841 | case OMX_QcomIndexParamVideoAdaptivePlaybackMode: |
| 3842 | { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3843 | VALIDATE_OMX_PARAM_DATA(paramData, PrepareForAdaptivePlaybackParams); |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3844 | DEBUG_PRINT_LOW("set_parameter: OMX_GoogleAndroidIndexPrepareForAdaptivePlayback"); |
| 3845 | PrepareForAdaptivePlaybackParams* pParams = |
| 3846 | (PrepareForAdaptivePlaybackParams *) paramData; |
| 3847 | if (pParams->nPortIndex == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 3848 | if (!pParams->bEnable) { |
| 3849 | return OMX_ErrorNone; |
| 3850 | } |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3851 | if (pParams->nMaxFrameWidth > maxSmoothStreamingWidth |
| 3852 | || pParams->nMaxFrameHeight > maxSmoothStreamingHeight) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3853 | DEBUG_PRINT_ERROR( |
| 3854 | "Adaptive playback request exceeds max supported resolution : [%lu x %lu] vs [%lu x %lu]", |
| 3855 | pParams->nMaxFrameWidth, pParams->nMaxFrameHeight, |
Deepak Verma | a2efdb1 | 2013-12-26 12:30:05 +0530 | [diff] [blame] | 3856 | maxSmoothStreamingWidth, maxSmoothStreamingHeight); |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3857 | eRet = OMX_ErrorBadParameter; |
| 3858 | } else { |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 3859 | eRet = enable_adaptive_playback(pParams->nMaxFrameWidth, pParams->nMaxFrameHeight); |
| 3860 | } |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 3861 | } else { |
| 3862 | DEBUG_PRINT_ERROR( |
| 3863 | "Prepare for adaptive playback supported only on output port"); |
| 3864 | eRet = OMX_ErrorBadParameter; |
| 3865 | } |
| 3866 | break; |
| 3867 | } |
| 3868 | |
| 3869 | #endif |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3870 | case OMX_QcomIndexParamVideoCustomBufferSize: |
| 3871 | { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3872 | VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_CUSTOM_BUFFERSIZE); |
Pushkaraj Patil | 8d273cb | 2014-07-21 10:43:22 +0530 | [diff] [blame] | 3873 | DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoCustomBufferSize"); |
| 3874 | QOMX_VIDEO_CUSTOM_BUFFERSIZE* pParam = (QOMX_VIDEO_CUSTOM_BUFFERSIZE*)paramData; |
| 3875 | if (pParam->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 3876 | struct v4l2_control control; |
| 3877 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT; |
| 3878 | control.value = pParam->nBufferSize; |
| 3879 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 3880 | DEBUG_PRINT_ERROR("Failed to set input buffer size"); |
| 3881 | eRet = OMX_ErrorUnsupportedSetting; |
| 3882 | } else { |
| 3883 | eRet = get_buffer_req(&drv_ctx.ip_buf); |
| 3884 | if (eRet == OMX_ErrorNone) { |
| 3885 | m_custom_buffersize.input_buffersize = drv_ctx.ip_buf.buffer_size; |
| 3886 | DEBUG_PRINT_HIGH("Successfully set custom input buffer size = %d", |
| 3887 | m_custom_buffersize.input_buffersize); |
| 3888 | } else { |
| 3889 | DEBUG_PRINT_ERROR("Failed to get buffer requirement"); |
| 3890 | } |
| 3891 | } |
| 3892 | } else { |
| 3893 | DEBUG_PRINT_ERROR("ERROR: Custom buffer size in not supported on output port"); |
| 3894 | eRet = OMX_ErrorBadParameter; |
| 3895 | } |
| 3896 | break; |
| 3897 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3898 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3899 | DEBUG_PRINT_ERROR("Setparameter: unknown param %d", paramIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3900 | eRet = OMX_ErrorUnsupportedIndex; |
| 3901 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3902 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 3903 | if (eRet != OMX_ErrorNone) |
| 3904 | 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] | 3905 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3909 | FUNCTION |
| 3910 | omx_vdec::GetConfig |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3911 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3912 | DESCRIPTION |
| 3913 | OMX Get Config Method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3914 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3915 | PARAMETERS |
| 3916 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3917 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3918 | RETURN VALUE |
| 3919 | OMX Error None if successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3920 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3921 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3922 | OMX_ERRORTYPE omx_vdec::get_config(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3923 | OMX_IN OMX_INDEXTYPE configIndex, |
| 3924 | OMX_INOUT OMX_PTR configData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3925 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3926 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3927 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3928 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3929 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3930 | return OMX_ErrorInvalidState; |
| 3931 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3932 | |
| 3933 | switch ((unsigned long)configIndex) { |
| 3934 | case OMX_QcomIndexConfigInterlaced: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3935 | VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_CONFIG_INTERLACETYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3936 | OMX_QCOM_CONFIG_INTERLACETYPE *configFmt = |
| 3937 | (OMX_QCOM_CONFIG_INTERLACETYPE *) configData; |
| 3938 | if (configFmt->nPortIndex == 1) { |
| 3939 | if (configFmt->nIndex == 0) { |
| 3940 | configFmt->eInterlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 3941 | } else if (configFmt->nIndex == 1) { |
| 3942 | configFmt->eInterlaceType = |
| 3943 | OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 3944 | } else if (configFmt->nIndex == 2) { |
| 3945 | configFmt->eInterlaceType = |
| 3946 | OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 3947 | } else { |
| 3948 | DEBUG_PRINT_ERROR("get_config: OMX_QcomIndexConfigInterlaced:" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3949 | " NoMore Interlaced formats"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3950 | eRet = OMX_ErrorNoMore; |
| 3951 | } |
| 3952 | |
| 3953 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3954 | 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] | 3955 | (int)configFmt->nPortIndex); |
| 3956 | eRet = OMX_ErrorBadPortIndex; |
| 3957 | } |
| 3958 | break; |
| 3959 | } |
| 3960 | case OMX_QcomIndexQueryNumberOfVideoDecInstance: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3961 | VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_QUERY_DECODER_INSTANCES); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3962 | QOMX_VIDEO_QUERY_DECODER_INSTANCES *decoderinstances = |
| 3963 | (QOMX_VIDEO_QUERY_DECODER_INSTANCES*)configData; |
| 3964 | decoderinstances->nNumOfInstances = 16; |
| 3965 | /*TODO: How to handle this case */ |
| 3966 | break; |
| 3967 | } |
| 3968 | case OMX_QcomIndexConfigVideoFramePackingArrangement: { |
| 3969 | if (drv_ctx.decoder_format == VDEC_CODECTYPE_H264) { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3970 | VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3971 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt = |
| 3972 | (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 3973 | memcpy(configFmt, &m_frame_pack_arrangement, |
| 3974 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3975 | } else { |
| 3976 | DEBUG_PRINT_ERROR("get_config: Framepack data not supported for non H264 codecs"); |
| 3977 | } |
| 3978 | break; |
| 3979 | } |
| 3980 | case OMX_IndexConfigCommonOutputCrop: { |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 3981 | VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_RECTTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3982 | OMX_CONFIG_RECTTYPE *rect = (OMX_CONFIG_RECTTYPE *) configData; |
| 3983 | memcpy(rect, &rectangle, sizeof(OMX_CONFIG_RECTTYPE)); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 3984 | DEBUG_PRINT_HIGH("get_config: crop info: L: %u, T: %u, R: %u, B: %u", |
| 3985 | rectangle.nLeft, rectangle.nTop, |
| 3986 | rectangle.nWidth, rectangle.nHeight); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3987 | break; |
| 3988 | } |
| 3989 | default: { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 3990 | DEBUG_PRINT_ERROR("get_config: unknown param %d",configIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3991 | eRet = OMX_ErrorBadParameter; |
| 3992 | } |
| 3993 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 3994 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 3995 | |
| 3996 | return eRet; |
| 3997 | } |
| 3998 | |
| 3999 | /* ====================================================================== |
| 4000 | FUNCTION |
| 4001 | omx_vdec::SetConfig |
| 4002 | |
| 4003 | DESCRIPTION |
| 4004 | OMX Set Config method implementation |
| 4005 | |
| 4006 | PARAMETERS |
| 4007 | <TBD>. |
| 4008 | |
| 4009 | RETURN VALUE |
| 4010 | OMX Error None if successful. |
| 4011 | ========================================================================== */ |
| 4012 | OMX_ERRORTYPE omx_vdec::set_config(OMX_IN OMX_HANDLETYPE hComp, |
| 4013 | OMX_IN OMX_INDEXTYPE configIndex, |
| 4014 | OMX_IN OMX_PTR configData) |
| 4015 | { |
| 4016 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4017 | DEBUG_PRINT_ERROR("Get Config in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4018 | return OMX_ErrorInvalidState; |
| 4019 | } |
| 4020 | |
| 4021 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 4022 | OMX_VIDEO_CONFIG_NALSIZE *pNal; |
| 4023 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4024 | DEBUG_PRINT_LOW("Set Config Called"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4025 | |
Praveen Chavan | efda1e0 | 2016-04-11 17:32:32 -0700 | [diff] [blame] | 4026 | if (configIndex == OMX_IndexConfigVideoNalSize) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4027 | struct v4l2_control temp; |
| 4028 | temp.id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT; |
| 4029 | |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 4030 | VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_NALSIZE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4031 | pNal = reinterpret_cast < OMX_VIDEO_CONFIG_NALSIZE * >(configData); |
| 4032 | switch (pNal->nNaluBytes) { |
| 4033 | case 0: |
| 4034 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES; |
| 4035 | break; |
| 4036 | case 2: |
| 4037 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH; |
| 4038 | break; |
| 4039 | case 4: |
| 4040 | temp.value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH; |
| 4041 | break; |
| 4042 | default: |
| 4043 | return OMX_ErrorUnsupportedSetting; |
| 4044 | } |
| 4045 | |
| 4046 | if (!arbitrary_bytes) { |
| 4047 | /* In arbitrary bytes mode, the assembler strips out nal size and replaces |
| 4048 | * with start code, so only need to notify driver in frame by frame mode */ |
| 4049 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &temp)) { |
| 4050 | DEBUG_PRINT_ERROR("Failed to set V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT"); |
| 4051 | return OMX_ErrorHardware; |
| 4052 | } |
| 4053 | } |
| 4054 | |
| 4055 | nal_length = pNal->nNaluBytes; |
| 4056 | m_frame_parser.init_nal_length(nal_length); |
| 4057 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4058 | DEBUG_PRINT_LOW("OMX_IndexConfigVideoNalSize called with Size %d", nal_length); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4059 | return ret; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4060 | } else if ((int)configIndex == (int)OMX_IndexVendorVideoFrameRate) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4061 | OMX_VENDOR_VIDEOFRAMERATE *config = (OMX_VENDOR_VIDEOFRAMERATE *) configData; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4062 | DEBUG_PRINT_HIGH("Index OMX_IndexVendorVideoFrameRate %lu", config->nFps); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4063 | |
| 4064 | if (config->nPortIndex == OMX_CORE_INPUT_PORT_INDEX) { |
| 4065 | if (config->bEnabled) { |
| 4066 | if ((config->nFps >> 16) > 0) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 4067 | DEBUG_PRINT_HIGH("set_config: frame rate set by omx client : %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4068 | config->nFps >> 16); |
| 4069 | Q16ToFraction(config->nFps, drv_ctx.frame_rate.fps_numerator, |
| 4070 | drv_ctx.frame_rate.fps_denominator); |
| 4071 | |
| 4072 | if (!drv_ctx.frame_rate.fps_numerator) { |
| 4073 | DEBUG_PRINT_ERROR("Numerator is zero setting to 30"); |
| 4074 | drv_ctx.frame_rate.fps_numerator = 30; |
| 4075 | } |
| 4076 | |
| 4077 | if (drv_ctx.frame_rate.fps_denominator) { |
| 4078 | drv_ctx.frame_rate.fps_numerator = (int) |
| 4079 | drv_ctx.frame_rate.fps_numerator / drv_ctx.frame_rate.fps_denominator; |
| 4080 | } |
| 4081 | |
| 4082 | drv_ctx.frame_rate.fps_denominator = 1; |
| 4083 | frm_int = drv_ctx.frame_rate.fps_denominator * 1e6 / |
| 4084 | drv_ctx.frame_rate.fps_numerator; |
| 4085 | |
| 4086 | struct v4l2_outputparm oparm; |
| 4087 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 4088 | * per second.*/ |
| 4089 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 4090 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
| 4091 | |
| 4092 | struct v4l2_streamparm sparm; |
| 4093 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 4094 | sparm.parm.output = oparm; |
| 4095 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 4096 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 4097 | performance might be affected"); |
| 4098 | ret = OMX_ErrorHardware; |
| 4099 | } |
| 4100 | client_set_fps = true; |
| 4101 | } else { |
| 4102 | DEBUG_PRINT_ERROR("Frame rate not supported."); |
| 4103 | ret = OMX_ErrorUnsupportedSetting; |
| 4104 | } |
| 4105 | } else { |
| 4106 | DEBUG_PRINT_HIGH("set_config: Disabled client's frame rate"); |
| 4107 | client_set_fps = false; |
| 4108 | } |
| 4109 | } else { |
| 4110 | DEBUG_PRINT_ERROR(" Set_config: Bad Port idx %d", |
| 4111 | (int)config->nPortIndex); |
| 4112 | ret = OMX_ErrorBadPortIndex; |
| 4113 | } |
| 4114 | |
| 4115 | return ret; |
Praveen Chavan | 898df26 | 2015-04-20 18:52:19 -0700 | [diff] [blame] | 4116 | } else if ((int)configIndex == (int)OMX_IndexConfigPriority) { |
| 4117 | OMX_PARAM_U32TYPE *priority = (OMX_PARAM_U32TYPE *)configData; |
| 4118 | DEBUG_PRINT_LOW("Set_config: priority %d", priority->nU32); |
| 4119 | |
| 4120 | struct v4l2_control control; |
| 4121 | |
| 4122 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY; |
| 4123 | if (priority->nU32 == 0) |
| 4124 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_ENABLE; |
| 4125 | else |
| 4126 | control.value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE; |
| 4127 | |
| 4128 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 4129 | DEBUG_PRINT_ERROR("Failed to set Priority"); |
| 4130 | ret = OMX_ErrorUnsupportedSetting; |
| 4131 | } |
| 4132 | return ret; |
Praveen Chavan | 281d502 | 2015-04-30 20:28:44 -0700 | [diff] [blame] | 4133 | } else if ((int)configIndex == (int)OMX_IndexConfigOperatingRate) { |
| 4134 | OMX_PARAM_U32TYPE *rate = (OMX_PARAM_U32TYPE *)configData; |
| 4135 | DEBUG_PRINT_LOW("Set_config: operating-rate %u fps", rate->nU32 >> 16); |
| 4136 | |
| 4137 | struct v4l2_control control; |
| 4138 | |
| 4139 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_OPERATING_RATE; |
| 4140 | control.value = rate->nU32; |
| 4141 | |
| 4142 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 4143 | ret = errno == -EBUSY ? OMX_ErrorInsufficientResources : |
| 4144 | OMX_ErrorUnsupportedSetting; |
| 4145 | DEBUG_PRINT_ERROR("Failed to set operating rate %u fps (%s)", |
| 4146 | rate->nU32 >> 16, errno == -EBUSY ? "HW Overload" : strerror(errno)); |
| 4147 | } |
| 4148 | return ret; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | return OMX_ErrorNotImplemented; |
| 4152 | } |
| 4153 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4154 | #define extn_equals(param, extn) (!strncmp(param, extn, strlen(extn))) |
| 4155 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4156 | /* ====================================================================== |
| 4157 | FUNCTION |
| 4158 | omx_vdec::GetExtensionIndex |
| 4159 | |
| 4160 | DESCRIPTION |
| 4161 | OMX GetExtensionIndex method implementaion. <TBD> |
| 4162 | |
| 4163 | PARAMETERS |
| 4164 | <TBD>. |
| 4165 | |
| 4166 | RETURN VALUE |
| 4167 | OMX Error None if everything successful. |
| 4168 | |
| 4169 | ========================================================================== */ |
| 4170 | OMX_ERRORTYPE omx_vdec::get_extension_index(OMX_IN OMX_HANDLETYPE hComp, |
| 4171 | OMX_IN OMX_STRING paramName, |
| 4172 | OMX_OUT OMX_INDEXTYPE* indexType) |
| 4173 | { |
| 4174 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4175 | DEBUG_PRINT_ERROR("Get Extension Index in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4176 | return OMX_ErrorInvalidState; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4177 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.video.SyncFrameDecodingMode")) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4178 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4179 | } else if (extn_equals(paramName, "OMX.QCOM.index.param.IndexExtraData")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4180 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4181 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_FRAMEPACKING_EXTRADATA)) { |
| 4182 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoFramePackingExtradata; |
| 4183 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_CONFIG_VIDEO_FRAMEPACKING_INFO)) { |
| 4184 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoFramePackingArrangement; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 4185 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_QP_EXTRADATA)) { |
| 4186 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPExtraData; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 4187 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_INPUTBITSINFO_EXTRADATA)) { |
| 4188 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoInputBitsInfoExtraData; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 4189 | } else if (extn_equals(paramName, OMX_QCOM_INDEX_PARAM_VIDEO_EXTNUSER_EXTRADATA)) { |
| 4190 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableExtnUserData; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4191 | } |
| 4192 | #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_) |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4193 | else if (extn_equals(paramName, "OMX.google.android.index.enableAndroidNativeBuffers")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4194 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexEnableAndroidNativeBuffers; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4195 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer2")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4196 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer2; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4197 | } else if (extn_equals(paramName, "OMX.google.android.index.useAndroidNativeBuffer")) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4198 | DEBUG_PRINT_ERROR("Extension: %s is supported", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4199 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexUseAndroidNativeBuffer; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4200 | } else if (extn_equals(paramName, "OMX.google.android.index.getAndroidNativeBufferUsage")) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4201 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexGetAndroidNativeBufferUsage; |
| 4202 | } |
Praveen Chavan | d443c0d | 2016-04-19 12:25:46 -0700 | [diff] [blame] | 4203 | #if ALLOCATE_OUTPUT_NATIVEHANDLE |
| 4204 | else if (extn_equals(paramName, "OMX.google.android.index.allocateNativeHandle")) { |
| 4205 | *indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexAllocateNativeHandle; |
| 4206 | } |
| 4207 | #endif //ALLOCATE_OUTPUT_NATIVEHANDLE |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4208 | #endif |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 4209 | else if (extn_equals(paramName, "OMX.google.android.index.storeMetaDataInBuffers")) { |
Arun Menon | e565248 | 2013-08-04 13:33:05 -0700 | [diff] [blame] | 4210 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode; |
| 4211 | } |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 4212 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 4213 | else if (extn_equals(paramName, "OMX.google.android.index.prepareForAdaptivePlayback")) { |
| 4214 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoAdaptivePlaybackMode; |
| 4215 | } |
| 4216 | #endif |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 4217 | #ifdef FLEXYUV_SUPPORTED |
| 4218 | else if (extn_equals(paramName,"OMX.google.android.index.describeColorFormat")) { |
| 4219 | *indexType = (OMX_INDEXTYPE)OMX_QcomIndexFlexibleYUVDescription; |
| 4220 | } |
| 4221 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4222 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4223 | DEBUG_PRINT_ERROR("Extension: %s not implemented", paramName); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4224 | return OMX_ErrorNotImplemented; |
| 4225 | } |
| 4226 | return OMX_ErrorNone; |
| 4227 | } |
| 4228 | |
| 4229 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4230 | FUNCTION |
| 4231 | omx_vdec::GetState |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4232 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4233 | DESCRIPTION |
| 4234 | Returns the state information back to the caller.<TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4235 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4236 | PARAMETERS |
| 4237 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4238 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4239 | RETURN VALUE |
| 4240 | Error None if everything is successful. |
| 4241 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4242 | OMX_ERRORTYPE omx_vdec::get_state(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4243 | OMX_OUT OMX_STATETYPE* state) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4244 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4245 | *state = m_state; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4246 | DEBUG_PRINT_LOW("get_state: Returning the state %d",*state); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4247 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4251 | FUNCTION |
| 4252 | omx_vdec::ComponentTunnelRequest |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4253 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4254 | DESCRIPTION |
| 4255 | OMX Component Tunnel Request method implementation. <TBD> |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4256 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4257 | PARAMETERS |
| 4258 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4259 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4260 | RETURN VALUE |
| 4261 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4262 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4263 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4264 | OMX_ERRORTYPE omx_vdec::component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4265 | OMX_IN OMX_U32 port, |
| 4266 | OMX_IN OMX_HANDLETYPE peerComponent, |
| 4267 | OMX_IN OMX_U32 peerPort, |
| 4268 | OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4269 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4270 | DEBUG_PRINT_ERROR("Error: component_tunnel_request Not Implemented"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4271 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4275 | FUNCTION |
| 4276 | omx_vdec::UseOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4277 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4278 | DESCRIPTION |
| 4279 | Helper function for Use buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4280 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4281 | PARAMETERS |
| 4282 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4283 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4284 | RETURN VALUE |
| 4285 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4286 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4287 | ========================================================================== */ |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4288 | OMX_ERRORTYPE omx_vdec::allocate_extradata() |
| 4289 | { |
| 4290 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4291 | if (drv_ctx.extradata_info.buffer_size) { |
| 4292 | if (drv_ctx.extradata_info.ion.ion_alloc_data.handle) { |
| 4293 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4294 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4295 | free_ion_memory(&drv_ctx.extradata_info.ion); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4296 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4297 | } |
| 4298 | drv_ctx.extradata_info.size = (drv_ctx.extradata_info.size + 4095) & (~4095); |
| 4299 | drv_ctx.extradata_info.ion.ion_device_fd = alloc_map_ion_memory( |
| 4300 | drv_ctx.extradata_info.size, 4096, |
| 4301 | &drv_ctx.extradata_info.ion.ion_alloc_data, |
| 4302 | &drv_ctx.extradata_info.ion.fd_ion_data, 0); |
| 4303 | if (drv_ctx.extradata_info.ion.ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4304 | DEBUG_PRINT_ERROR("Failed to alloc extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4305 | return OMX_ErrorInsufficientResources; |
| 4306 | } |
| 4307 | drv_ctx.extradata_info.uaddr = (char *)mmap(NULL, |
| 4308 | drv_ctx.extradata_info.size, |
| 4309 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4310 | drv_ctx.extradata_info.ion.fd_ion_data.fd , 0); |
| 4311 | if (drv_ctx.extradata_info.uaddr == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4312 | DEBUG_PRINT_ERROR("Failed to map extradata memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4313 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4314 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4315 | return OMX_ErrorInsufficientResources; |
| 4316 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4317 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4318 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4319 | if (!m_other_extradata) { |
| 4320 | m_other_extradata = (OMX_OTHER_EXTRADATATYPE *)malloc(drv_ctx.extradata_info.buffer_size); |
| 4321 | if (!m_other_extradata) { |
| 4322 | DEBUG_PRINT_ERROR("Failed to alloc memory\n"); |
| 4323 | return OMX_ErrorInsufficientResources; |
| 4324 | } |
| 4325 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4326 | return OMX_ErrorNone; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4327 | } |
| 4328 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4329 | void omx_vdec::free_extradata() |
| 4330 | { |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4331 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4332 | if (drv_ctx.extradata_info.uaddr) { |
| 4333 | munmap((void *)drv_ctx.extradata_info.uaddr, drv_ctx.extradata_info.size); |
| 4334 | close(drv_ctx.extradata_info.ion.fd_ion_data.fd); |
| 4335 | free_ion_memory(&drv_ctx.extradata_info.ion); |
| 4336 | } |
| 4337 | memset(&drv_ctx.extradata_info, 0, sizeof(drv_ctx.extradata_info)); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4338 | #endif |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4339 | if (m_other_extradata) { |
| 4340 | free(m_other_extradata); |
| 4341 | m_other_extradata = NULL; |
| 4342 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4343 | } |
| 4344 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4345 | OMX_ERRORTYPE omx_vdec::use_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4346 | OMX_IN OMX_HANDLETYPE hComp, |
| 4347 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4348 | OMX_IN OMX_U32 port, |
| 4349 | OMX_IN OMX_PTR appData, |
| 4350 | OMX_IN OMX_U32 bytes, |
| 4351 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4352 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4353 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4354 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 4355 | unsigned i= 0; // Temporary counter |
| 4356 | struct vdec_setbuffer_cmd setbuffers; |
| 4357 | OMX_PTR privateAppData = NULL; |
| 4358 | private_handle_t *handle = NULL; |
| 4359 | OMX_U8 *buff = buffer; |
| 4360 | struct v4l2_buffer buf; |
| 4361 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 4362 | int extra_idx = 0; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4363 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4364 | if (!m_out_mem_ptr) { |
| 4365 | DEBUG_PRINT_HIGH("Use_op_buf:Allocating output headers"); |
| 4366 | eRet = allocate_output_headers(); |
| 4367 | if (eRet == OMX_ErrorNone) |
| 4368 | eRet = allocate_extradata(); |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 4369 | output_use_buffer = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4370 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4371 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4372 | if (eRet == OMX_ErrorNone) { |
| 4373 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 4374 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
| 4375 | break; |
| 4376 | } |
| 4377 | } |
| 4378 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4379 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4380 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4381 | 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] | 4382 | eRet = OMX_ErrorInsufficientResources; |
| 4383 | } |
| 4384 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 4385 | if (dynamic_buf_mode) { |
| 4386 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4387 | (*bufferHdr)->pBuffer = NULL; |
| 4388 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4389 | enum v4l2_buf_type buf_type; |
| 4390 | int rr = 0; |
| 4391 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4392 | if (rr = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4393 | DEBUG_PRINT_ERROR("STREAMON FAILED : %d", rr); |
| 4394 | return OMX_ErrorInsufficientResources; |
| 4395 | } else { |
| 4396 | streaming[CAPTURE_PORT] = true; |
| 4397 | DEBUG_PRINT_LOW("STREAMON Successful"); |
| 4398 | } |
| 4399 | } |
| 4400 | BITMASK_SET(&m_out_bm_count,i); |
| 4401 | (*bufferHdr)->pAppPrivate = appData; |
| 4402 | (*bufferHdr)->pBuffer = buffer; |
| 4403 | (*bufferHdr)->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 4404 | return eRet; |
| 4405 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4406 | if (eRet == OMX_ErrorNone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4407 | #if defined(_ANDROID_HONEYCOMB_) || defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4408 | if (m_enable_android_native_buffers) { |
| 4409 | if (m_use_android_native_buffers) { |
| 4410 | UseAndroidNativeBufferParams *params = (UseAndroidNativeBufferParams *)appData; |
| 4411 | sp<android_native_buffer_t> nBuf = params->nativeBuffer; |
| 4412 | handle = (private_handle_t *)nBuf->handle; |
| 4413 | privateAppData = params->pAppPrivate; |
| 4414 | } else { |
| 4415 | handle = (private_handle_t *)buff; |
| 4416 | privateAppData = appData; |
| 4417 | } |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4418 | if (!handle) { |
| 4419 | DEBUG_PRINT_ERROR("handle is invalid"); |
| 4420 | return OMX_ErrorBadParameter; |
| 4421 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4422 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4423 | if ((OMX_U32)handle->size < drv_ctx.op_buf.buffer_size) { |
| 4424 | DEBUG_PRINT_ERROR("Insufficient sized buffer given for playback," |
| 4425 | " expected %u, got %lu", |
| 4426 | drv_ctx.op_buf.buffer_size, (OMX_U32)handle->size); |
| 4427 | return OMX_ErrorBadParameter; |
| 4428 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4429 | |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 4430 | drv_ctx.op_buf.buffer_size = handle->size; |
| 4431 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4432 | if (!m_use_android_native_buffers) { |
| 4433 | if (!secure_mode) { |
| 4434 | buff = (OMX_U8*)mmap(0, handle->size, |
| 4435 | PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0); |
| 4436 | if (buff == MAP_FAILED) { |
| 4437 | DEBUG_PRINT_ERROR("Failed to mmap pmem with fd = %d, size = %d", handle->fd, handle->size); |
| 4438 | return OMX_ErrorInsufficientResources; |
| 4439 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 4440 | } |
| 4441 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4442 | #if defined(_ANDROID_ICS_) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4443 | native_buffer[i].nativehandle = handle; |
| 4444 | native_buffer[i].privatehandle = handle; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4445 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4446 | if (!handle) { |
| 4447 | DEBUG_PRINT_ERROR("Native Buffer handle is NULL"); |
| 4448 | return OMX_ErrorBadParameter; |
| 4449 | } |
| 4450 | drv_ctx.ptr_outputbuffer[i].pmem_fd = handle->fd; |
| 4451 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4452 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4453 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4454 | drv_ctx.ptr_outputbuffer[i].mmaped_size = handle->size; |
| 4455 | } else |
| 4456 | #endif |
| 4457 | |
| 4458 | if (!ouput_egl_buffers && !m_use_output_pmem) { |
| 4459 | #ifdef USE_ION |
| 4460 | drv_ctx.op_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
| 4461 | drv_ctx.op_buf.buffer_size,drv_ctx.op_buf.alignment, |
| 4462 | &drv_ctx.op_buf_ion_info[i].ion_alloc_data, |
| 4463 | &drv_ctx.op_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 4464 | if (drv_ctx.op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4465 | 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] | 4466 | return OMX_ErrorInsufficientResources; |
| 4467 | } |
| 4468 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4469 | drv_ctx.op_buf_ion_info[i].fd_ion_data.fd; |
| 4470 | #else |
| 4471 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4472 | open (MEM_DEVICE,O_RDWR); |
| 4473 | |
| 4474 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4475 | 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] | 4476 | return OMX_ErrorInsufficientResources; |
| 4477 | } |
| 4478 | |
| 4479 | /* FIXME: why is this code even here? We already open MEM_DEVICE a few lines above */ |
| 4480 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd == 0) { |
| 4481 | drv_ctx.ptr_outputbuffer[i].pmem_fd = \ |
| 4482 | open (MEM_DEVICE,O_RDWR); |
| 4483 | if (drv_ctx.ptr_outputbuffer[i].pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4484 | DEBUG_PRINT_ERROR("ION/pmem buffer fd is bad %d", drv_ctx.ptr_outputbuffer[i].pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4485 | return OMX_ErrorInsufficientResources; |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | if (!align_pmem_buffers(drv_ctx.ptr_outputbuffer[i].pmem_fd, |
| 4490 | drv_ctx.op_buf.buffer_size, |
| 4491 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4492 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4493 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4494 | return OMX_ErrorInsufficientResources; |
| 4495 | } |
| 4496 | #endif |
| 4497 | if (!secure_mode) { |
| 4498 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 4499 | (unsigned char *)mmap(NULL, drv_ctx.op_buf.buffer_size, |
| 4500 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 4501 | drv_ctx.ptr_outputbuffer[i].pmem_fd,0); |
| 4502 | if (drv_ctx.ptr_outputbuffer[i].bufferaddr == MAP_FAILED) { |
| 4503 | close(drv_ctx.ptr_outputbuffer[i].pmem_fd); |
| 4504 | #ifdef USE_ION |
| 4505 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
| 4506 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4507 | DEBUG_PRINT_ERROR("Unable to mmap output buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4508 | return OMX_ErrorInsufficientResources; |
| 4509 | } |
| 4510 | } |
| 4511 | drv_ctx.ptr_outputbuffer[i].offset = 0; |
| 4512 | privateAppData = appData; |
| 4513 | } else { |
| 4514 | |
| 4515 | DEBUG_PRINT_LOW("Use_op_buf: out_pmem=%d",m_use_output_pmem); |
| 4516 | if (!appData || !bytes ) { |
| 4517 | if (!secure_mode && !buffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4518 | DEBUG_PRINT_ERROR("Bad parameters for use buffer in EGL image case"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4519 | return OMX_ErrorBadParameter; |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pmem_list; |
| 4524 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pmem_info; |
| 4525 | pmem_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST*) appData; |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4526 | if (!pmem_list || !pmem_list->entryList || !pmem_list->entryList->entry || |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4527 | !pmem_list->nEntries || |
| 4528 | pmem_list->entryList->type != OMX_QCOM_PLATFORM_PRIVATE_PMEM) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4529 | DEBUG_PRINT_ERROR("Pmem info not valid in use buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4530 | return OMX_ErrorBadParameter; |
| 4531 | } |
| 4532 | pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 4533 | pmem_list->entryList->entry; |
| 4534 | DEBUG_PRINT_LOW("vdec: use buf: pmem_fd=0x%lx", |
| 4535 | pmem_info->pmem_fd); |
| 4536 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_info->pmem_fd; |
| 4537 | drv_ctx.ptr_outputbuffer[i].offset = pmem_info->offset; |
| 4538 | drv_ctx.ptr_outputbuffer[i].bufferaddr = buff; |
| 4539 | drv_ctx.ptr_outputbuffer[i].mmaped_size = |
| 4540 | drv_ctx.ptr_outputbuffer[i].buffer_len = drv_ctx.op_buf.buffer_size; |
| 4541 | privateAppData = appData; |
| 4542 | } |
| 4543 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 4544 | m_pmem_info[i].pmem_fd = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 4545 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 4546 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 4547 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4548 | |
| 4549 | *bufferHdr = (m_out_mem_ptr + i ); |
| 4550 | if (secure_mode) |
| 4551 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 4552 | //setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4553 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[i], |
| 4554 | sizeof (vdec_bufferpayload)); |
| 4555 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4556 | 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] | 4557 | drv_ctx.ptr_outputbuffer[i].bufferaddr, |
| 4558 | drv_ctx.ptr_outputbuffer[i].pmem_fd ); |
| 4559 | |
| 4560 | buf.index = i; |
| 4561 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4562 | buf.memory = V4L2_MEMORY_USERPTR; |
| 4563 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 4564 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 4565 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
| 4566 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[i].pmem_fd; |
| 4567 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 4568 | plane[0].data_offset = 0; |
| 4569 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 4570 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 4571 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 4572 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
| 4573 | #ifdef USE_ION |
| 4574 | plane[extra_idx].reserved[0] = drv_ctx.extradata_info.ion.fd_ion_data.fd; |
| 4575 | #endif |
| 4576 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 4577 | plane[extra_idx].data_offset = 0; |
| 4578 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4579 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4580 | return OMX_ErrorBadParameter; |
| 4581 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4582 | buf.m.planes = plane; |
| 4583 | buf.length = drv_ctx.num_planes; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4584 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4585 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4586 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4587 | /*TODO: How to handle this case */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4588 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4589 | } |
| 4590 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4591 | if (i == (drv_ctx.op_buf.actualcount -1) && !streaming[CAPTURE_PORT]) { |
| 4592 | enum v4l2_buf_type buf_type; |
| 4593 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 4594 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type)) { |
| 4595 | return OMX_ErrorInsufficientResources; |
| 4596 | } else { |
| 4597 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4598 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4599 | } |
| 4600 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4601 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4602 | (*bufferHdr)->nAllocLen = drv_ctx.op_buf.buffer_size; |
| 4603 | if (m_enable_android_native_buffers) { |
| 4604 | DEBUG_PRINT_LOW("setting pBuffer to private_handle_t %p", handle); |
| 4605 | (*bufferHdr)->pBuffer = (OMX_U8 *)handle; |
| 4606 | } else { |
| 4607 | (*bufferHdr)->pBuffer = buff; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4608 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4609 | (*bufferHdr)->pAppPrivate = privateAppData; |
| 4610 | BITMASK_SET(&m_out_bm_count,i); |
| 4611 | } |
| 4612 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4616 | FUNCTION |
| 4617 | omx_vdec::use_input_heap_buffers |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4618 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4619 | DESCRIPTION |
| 4620 | OMX Use Buffer Heap allocation method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4621 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4622 | PARAMETERS |
| 4623 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4624 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4625 | RETURN VALUE |
| 4626 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4627 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4628 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4629 | OMX_ERRORTYPE omx_vdec::use_input_heap_buffers( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4630 | OMX_IN OMX_HANDLETYPE hComp, |
| 4631 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4632 | OMX_IN OMX_U32 port, |
| 4633 | OMX_IN OMX_PTR appData, |
| 4634 | OMX_IN OMX_U32 bytes, |
| 4635 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4636 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4637 | DEBUG_PRINT_LOW("Inside %s, %p", __FUNCTION__, buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4638 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4639 | if (!m_inp_heap_ptr) |
| 4640 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) |
| 4641 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4642 | drv_ctx.ip_buf.actualcount); |
| 4643 | if (!m_phdr_pmem_ptr) |
| 4644 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) |
| 4645 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4646 | drv_ctx.ip_buf.actualcount); |
| 4647 | if (!m_inp_heap_ptr || !m_phdr_pmem_ptr) { |
| 4648 | DEBUG_PRINT_ERROR("Insufficent memory"); |
| 4649 | eRet = OMX_ErrorInsufficientResources; |
| 4650 | } else if (m_in_alloc_cnt < drv_ctx.ip_buf.actualcount) { |
| 4651 | input_use_buffer = true; |
| 4652 | memset(&m_inp_heap_ptr[m_in_alloc_cnt], 0, sizeof(OMX_BUFFERHEADERTYPE)); |
| 4653 | m_inp_heap_ptr[m_in_alloc_cnt].pBuffer = buffer; |
| 4654 | m_inp_heap_ptr[m_in_alloc_cnt].nAllocLen = bytes; |
| 4655 | m_inp_heap_ptr[m_in_alloc_cnt].pAppPrivate = appData; |
| 4656 | m_inp_heap_ptr[m_in_alloc_cnt].nInputPortIndex = (OMX_U32) OMX_DirInput; |
| 4657 | m_inp_heap_ptr[m_in_alloc_cnt].nOutputPortIndex = (OMX_U32) OMX_DirMax; |
| 4658 | *bufferHdr = &m_inp_heap_ptr[m_in_alloc_cnt]; |
| 4659 | eRet = allocate_input_buffer(hComp, &m_phdr_pmem_ptr[m_in_alloc_cnt], port, appData, bytes); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4660 | 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] | 4661 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[m_in_alloc_cnt], |
| 4662 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4663 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4664 | return OMX_ErrorInsufficientResources; |
| 4665 | } |
| 4666 | m_in_alloc_cnt++; |
| 4667 | } else { |
| 4668 | DEBUG_PRINT_ERROR("All i/p buffers have been set!"); |
| 4669 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4670 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4671 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4675 | FUNCTION |
| 4676 | omx_vdec::UseBuffer |
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 | DESCRIPTION |
| 4679 | OMX Use Buffer method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4680 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4681 | PARAMETERS |
| 4682 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4683 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4684 | RETURN VALUE |
| 4685 | OMX Error None , if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4686 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4687 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4688 | OMX_ERRORTYPE omx_vdec::use_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4689 | OMX_IN OMX_HANDLETYPE hComp, |
| 4690 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4691 | OMX_IN OMX_U32 port, |
| 4692 | OMX_IN OMX_PTR appData, |
| 4693 | OMX_IN OMX_U32 bytes, |
| 4694 | OMX_IN OMX_U8* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4695 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4696 | OMX_ERRORTYPE error = OMX_ErrorNone; |
| 4697 | struct vdec_setbuffer_cmd setbuffers; |
| 4698 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4699 | if (bufferHdr == NULL || bytes == 0 || (!secure_mode && buffer == NULL)) { |
| 4700 | DEBUG_PRINT_ERROR("bad param 0x%p %ld 0x%p",bufferHdr, bytes, buffer); |
| 4701 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4702 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4703 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4704 | DEBUG_PRINT_ERROR("Use Buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4705 | return OMX_ErrorInvalidState; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4706 | } |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 4707 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 4708 | // If this is not the first allocation (i.e m_inp_mem_ptr is allocated), |
| 4709 | // ensure that use-buffer was called for previous allocation. |
| 4710 | // Mix-and-match of useBuffer and allocateBuffer is not allowed |
| 4711 | if (m_inp_mem_ptr && !input_use_buffer) { |
| 4712 | DEBUG_PRINT_ERROR("'Use' Input buffer called after 'Allocate' Input buffer !"); |
| 4713 | return OMX_ErrorUndefined; |
| 4714 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4715 | error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer); |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 4716 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4717 | error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested |
| 4718 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4719 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4720 | error = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4721 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4722 | DEBUG_PRINT_LOW("Use Buffer: port %lu, buffer %p, eRet %d", port, *bufferHdr, error); |
| 4723 | if (error == OMX_ErrorNone) { |
| 4724 | if (allocate_done() && BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
| 4725 | // Send the callback now |
| 4726 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 4727 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
| 4728 | OMX_COMPONENT_GENERATE_EVENT); |
| 4729 | } |
| 4730 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated && |
| 4731 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 4732 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 4733 | post_event(OMX_CommandPortEnable, |
| 4734 | OMX_CORE_INPUT_PORT_INDEX, |
| 4735 | OMX_COMPONENT_GENERATE_EVENT); |
| 4736 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated && |
| 4737 | BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 4738 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
| 4739 | post_event(OMX_CommandPortEnable, |
| 4740 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 4741 | OMX_COMPONENT_GENERATE_EVENT); |
| 4742 | } |
| 4743 | } |
| 4744 | return error; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | OMX_ERRORTYPE omx_vdec::free_input_buffer(unsigned int bufferindex, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4748 | OMX_BUFFERHEADERTYPE *pmem_bufferHdr) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4749 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4750 | if (m_inp_heap_ptr && !input_use_buffer && arbitrary_bytes) { |
| 4751 | if (m_inp_heap_ptr[bufferindex].pBuffer) |
| 4752 | free(m_inp_heap_ptr[bufferindex].pBuffer); |
| 4753 | m_inp_heap_ptr[bufferindex].pBuffer = NULL; |
| 4754 | } |
| 4755 | if (pmem_bufferHdr) |
| 4756 | free_input_buffer(pmem_bufferHdr); |
| 4757 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | OMX_ERRORTYPE omx_vdec::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4761 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4762 | unsigned int index = 0; |
| 4763 | if (bufferHdr == NULL || m_inp_mem_ptr == NULL) { |
| 4764 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4765 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4766 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4767 | index = bufferHdr - m_inp_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4768 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4769 | |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 4770 | bufferHdr->pInputPortPrivate = NULL; |
| 4771 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4772 | if (index < drv_ctx.ip_buf.actualcount && drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4773 | DEBUG_PRINT_LOW("Free Input Buffer index = %d",index); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4774 | if (drv_ctx.ptr_inputbuffer[index].pmem_fd > 0) { |
| 4775 | struct vdec_setbuffer_cmd setbuffers; |
| 4776 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_INPUT; |
| 4777 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_inputbuffer[index], |
| 4778 | sizeof (vdec_bufferpayload)); |
| 4779 | if (!secure_mode) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4780 | DEBUG_PRINT_LOW("unmap the input buffer fd=%d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4781 | drv_ctx.ptr_inputbuffer[index].pmem_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4782 | DEBUG_PRINT_LOW("unmap the input buffer size=%d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4783 | drv_ctx.ptr_inputbuffer[index].mmaped_size, |
| 4784 | drv_ctx.ptr_inputbuffer[index].bufferaddr); |
| 4785 | munmap (drv_ctx.ptr_inputbuffer[index].bufferaddr, |
| 4786 | drv_ctx.ptr_inputbuffer[index].mmaped_size); |
Praveen Chavan | d443c0d | 2016-04-19 12:25:46 -0700 | [diff] [blame] | 4787 | close (drv_ctx.ptr_inputbuffer[index].pmem_fd); |
| 4788 | } else if (allocate_native_handle){ |
| 4789 | native_handle_t *nh = (native_handle_t *)bufferHdr->pBuffer; |
| 4790 | native_handle_close(nh); |
| 4791 | native_handle_delete(nh); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4792 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4793 | drv_ctx.ptr_inputbuffer[index].pmem_fd = -1; |
| 4794 | if (m_desc_buffer_ptr && m_desc_buffer_ptr[index].buf_addr) { |
| 4795 | free(m_desc_buffer_ptr[index].buf_addr); |
| 4796 | m_desc_buffer_ptr[index].buf_addr = NULL; |
| 4797 | m_desc_buffer_ptr[index].desc_data_size = 0; |
| 4798 | } |
| 4799 | #ifdef USE_ION |
| 4800 | free_ion_memory(&drv_ctx.ip_buf_ion_info[index]); |
| 4801 | #endif |
| 4802 | } |
| 4803 | } |
| 4804 | |
| 4805 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | OMX_ERRORTYPE omx_vdec::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr) |
| 4809 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4810 | unsigned int index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4811 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4812 | if (bufferHdr == NULL || m_out_mem_ptr == NULL) { |
| 4813 | return OMX_ErrorBadParameter; |
| 4814 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4815 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4816 | index = bufferHdr - m_out_mem_ptr; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4817 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d",index); |
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 (index < drv_ctx.op_buf.actualcount |
| 4820 | && drv_ctx.ptr_outputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4821 | DEBUG_PRINT_LOW("Free ouput Buffer index = %d addr = %p", index, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4822 | drv_ctx.ptr_outputbuffer[index].bufferaddr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4823 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4824 | struct vdec_setbuffer_cmd setbuffers; |
| 4825 | setbuffers.buffer_type = VDEC_BUFFER_TYPE_OUTPUT; |
| 4826 | memcpy (&setbuffers.buffer,&drv_ctx.ptr_outputbuffer[index], |
| 4827 | sizeof (vdec_bufferpayload)); |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4828 | |
| 4829 | if (!dynamic_buf_mode) { |
Balamurugan Alagarsamy | e773c58 | 2014-12-17 15:10:25 +0530 | [diff] [blame] | 4830 | if (streaming[CAPTURE_PORT] && |
| 4831 | !(in_reconfig || BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING))) { |
| 4832 | if (stream_off(OMX_CORE_OUTPUT_PORT_INDEX)) { |
| 4833 | DEBUG_PRINT_ERROR("STREAMOFF Failed"); |
| 4834 | } else { |
| 4835 | DEBUG_PRINT_LOW("STREAMOFF Successful"); |
| 4836 | } |
| 4837 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4838 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4839 | if (m_enable_android_native_buffers) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4840 | if (!secure_mode) { |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4841 | if (drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) { |
| 4842 | munmap(drv_ctx.ptr_outputbuffer[index].bufferaddr, |
| 4843 | drv_ctx.ptr_outputbuffer[index].mmaped_size); |
| 4844 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4845 | } |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4846 | drv_ctx.ptr_outputbuffer[index].pmem_fd = -1; |
| 4847 | } else { |
| 4848 | #endif |
| 4849 | if (drv_ctx.ptr_outputbuffer[0].pmem_fd > 0 && !ouput_egl_buffers && !m_use_output_pmem) { |
| 4850 | if (!secure_mode) { |
| 4851 | DEBUG_PRINT_LOW("\n unmap the output buffer fd = %d", |
| 4852 | drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4853 | DEBUG_PRINT_LOW("\n unmap the ouput buffer size=%d address = %p", |
| 4854 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount, |
| 4855 | drv_ctx.ptr_outputbuffer[0].bufferaddr); |
| 4856 | munmap (drv_ctx.ptr_outputbuffer[0].bufferaddr, |
| 4857 | drv_ctx.ptr_outputbuffer[0].mmaped_size * drv_ctx.op_buf.actualcount); |
| 4858 | } |
| 4859 | close (drv_ctx.ptr_outputbuffer[0].pmem_fd); |
| 4860 | drv_ctx.ptr_outputbuffer[0].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4861 | #ifdef USE_ION |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4862 | free_ion_memory(&drv_ctx.op_buf_ion_info[0]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4863 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4864 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4865 | #ifdef _ANDROID_ |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4866 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4867 | #endif |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 4868 | } //!dynamic_buf_mode |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4869 | if (release_output_done()) { |
| 4870 | free_extradata(); |
| 4871 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 4872 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4873 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4874 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4875 | |
| 4876 | } |
| 4877 | |
| 4878 | OMX_ERRORTYPE omx_vdec::allocate_input_heap_buffer(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4879 | OMX_BUFFERHEADERTYPE **bufferHdr, |
| 4880 | OMX_U32 port, |
| 4881 | OMX_PTR appData, |
| 4882 | OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4883 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4884 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4885 | unsigned char *buf_addr = NULL; |
| 4886 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4887 | unsigned i = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4888 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4889 | /* Sanity Check*/ |
| 4890 | if (bufferHdr == NULL) { |
| 4891 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4892 | } |
| 4893 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4894 | if (m_inp_heap_ptr == NULL) { |
| 4895 | m_inp_heap_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4896 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), |
| 4897 | drv_ctx.ip_buf.actualcount); |
| 4898 | m_phdr_pmem_ptr = (OMX_BUFFERHEADERTYPE**) \ |
| 4899 | calloc( (sizeof(OMX_BUFFERHEADERTYPE*)), |
| 4900 | drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4901 | |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 4902 | if (m_inp_heap_ptr == NULL || m_phdr_pmem_ptr == NULL) { |
| 4903 | DEBUG_PRINT_ERROR("m_inp_heap_ptr or m_phdr_pmem_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4904 | return OMX_ErrorInsufficientResources; |
| 4905 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4906 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4907 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4908 | /*Find a Free index*/ |
| 4909 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 4910 | if (BITMASK_ABSENT(&m_heap_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4911 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4912 | break; |
| 4913 | } |
| 4914 | } |
| 4915 | |
| 4916 | if (i < drv_ctx.ip_buf.actualcount) { |
| 4917 | buf_addr = (unsigned char *)malloc (drv_ctx.ip_buf.buffer_size); |
| 4918 | |
| 4919 | if (buf_addr == NULL) { |
| 4920 | return OMX_ErrorInsufficientResources; |
| 4921 | } |
| 4922 | |
| 4923 | *bufferHdr = (m_inp_heap_ptr + i); |
| 4924 | input = *bufferHdr; |
| 4925 | BITMASK_SET(&m_heap_inp_bm_count,i); |
| 4926 | |
| 4927 | input->pBuffer = (OMX_U8 *)buf_addr; |
| 4928 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 4929 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 4930 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 4931 | input->pAppPrivate = appData; |
| 4932 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4933 | DEBUG_PRINT_LOW("Address of Heap Buffer %p",*bufferHdr ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4934 | 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] | 4935 | 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] | 4936 | /*Add the Buffers to freeq*/ |
| 4937 | if (!m_input_free_q.insert_entry((unsigned)m_phdr_pmem_ptr[i], |
| 4938 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4939 | DEBUG_PRINT_ERROR("ERROR:Free_q is full"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4940 | return OMX_ErrorInsufficientResources; |
| 4941 | } |
| 4942 | } else { |
| 4943 | return OMX_ErrorBadParameter; |
| 4944 | } |
| 4945 | |
| 4946 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4947 | |
| 4948 | } |
| 4949 | |
| 4950 | |
| 4951 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4952 | FUNCTION |
| 4953 | omx_vdec::AllocateInputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4954 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4955 | DESCRIPTION |
| 4956 | Helper function for allocate buffer in the input pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4957 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4958 | PARAMETERS |
| 4959 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4960 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4961 | RETURN VALUE |
| 4962 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4963 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4964 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4965 | OMX_ERRORTYPE omx_vdec::allocate_input_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4966 | OMX_IN OMX_HANDLETYPE hComp, |
| 4967 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 4968 | OMX_IN OMX_U32 port, |
| 4969 | OMX_IN OMX_PTR appData, |
| 4970 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4971 | { |
| 4972 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4973 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 4974 | struct vdec_setbuffer_cmd setbuffers; |
| 4975 | OMX_BUFFERHEADERTYPE *input = NULL; |
| 4976 | unsigned i = 0; |
| 4977 | unsigned char *buf_addr = NULL; |
| 4978 | int pmem_fd = -1; |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 4979 | unsigned int align_size = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4980 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4981 | if (bytes != drv_ctx.ip_buf.buffer_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4982 | DEBUG_PRINT_LOW("Requested Size is wrong %lu epected is %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4983 | bytes, drv_ctx.ip_buf.buffer_size); |
| 4984 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4985 | } |
| 4986 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4987 | if (!m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 4988 | DEBUG_PRINT_HIGH("Allocate i/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4989 | drv_ctx.ip_buf.actualcount, |
| 4990 | drv_ctx.ip_buf.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 4991 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 4992 | m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \ |
| 4993 | calloc( (sizeof(OMX_BUFFERHEADERTYPE)), drv_ctx.ip_buf.actualcount); |
| 4994 | |
| 4995 | if (m_inp_mem_ptr == NULL) { |
| 4996 | return OMX_ErrorInsufficientResources; |
| 4997 | } |
| 4998 | |
| 4999 | drv_ctx.ptr_inputbuffer = (struct vdec_bufferpayload *) \ |
| 5000 | calloc ((sizeof (struct vdec_bufferpayload)),drv_ctx.ip_buf.actualcount); |
| 5001 | |
| 5002 | if (drv_ctx.ptr_inputbuffer == NULL) { |
| 5003 | return OMX_ErrorInsufficientResources; |
| 5004 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5005 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5006 | drv_ctx.ip_buf_ion_info = (struct vdec_ion *) \ |
| 5007 | calloc ((sizeof (struct vdec_ion)),drv_ctx.ip_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5008 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5009 | if (drv_ctx.ip_buf_ion_info == NULL) { |
| 5010 | return OMX_ErrorInsufficientResources; |
| 5011 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5012 | #endif |
| 5013 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5014 | for (i=0; i < drv_ctx.ip_buf.actualcount; i++) { |
| 5015 | drv_ctx.ptr_inputbuffer [i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5016 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5017 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5018 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5019 | } |
| 5020 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5021 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5022 | for (i=0; i< drv_ctx.ip_buf.actualcount; i++) { |
| 5023 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5024 | DEBUG_PRINT_LOW("Free Input Buffer Index %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5025 | break; |
| 5026 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5027 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5028 | |
| 5029 | if (i < drv_ctx.ip_buf.actualcount) { |
| 5030 | struct v4l2_buffer buf; |
| 5031 | struct v4l2_plane plane; |
| 5032 | int rc; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5033 | DEBUG_PRINT_LOW("Allocate input Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5034 | #ifdef USE_ION |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 5035 | align_size = drv_ctx.ip_buf.buffer_size + 512; |
| 5036 | align_size = (align_size + drv_ctx.ip_buf.alignment - 1)&(~(drv_ctx.ip_buf.alignment - 1)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5037 | drv_ctx.ip_buf_ion_info[i].ion_device_fd = alloc_map_ion_memory( |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 5038 | align_size, drv_ctx.op_buf.alignment, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5039 | &drv_ctx.ip_buf_ion_info[i].ion_alloc_data, |
| 5040 | &drv_ctx.ip_buf_ion_info[i].fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 5041 | if (drv_ctx.ip_buf_ion_info[i].ion_device_fd < 0) { |
| 5042 | return OMX_ErrorInsufficientResources; |
| 5043 | } |
| 5044 | pmem_fd = drv_ctx.ip_buf_ion_info[i].fd_ion_data.fd; |
| 5045 | #else |
| 5046 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 5047 | |
| 5048 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5049 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5050 | return OMX_ErrorInsufficientResources; |
| 5051 | } |
| 5052 | |
| 5053 | if (pmem_fd == 0) { |
| 5054 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
| 5055 | |
| 5056 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5057 | DEBUG_PRINT_ERROR("open failed for pmem/adsp for input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5058 | return OMX_ErrorInsufficientResources; |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | if (!align_pmem_buffers(pmem_fd, drv_ctx.ip_buf.buffer_size, |
| 5063 | drv_ctx.ip_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5064 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5065 | close(pmem_fd); |
| 5066 | return OMX_ErrorInsufficientResources; |
| 5067 | } |
| 5068 | #endif |
| 5069 | if (!secure_mode) { |
| 5070 | buf_addr = (unsigned char *)mmap(NULL, |
| 5071 | drv_ctx.ip_buf.buffer_size, |
| 5072 | PROT_READ|PROT_WRITE, MAP_SHARED, pmem_fd, 0); |
| 5073 | |
| 5074 | if (buf_addr == MAP_FAILED) { |
| 5075 | close(pmem_fd); |
| 5076 | #ifdef USE_ION |
| 5077 | free_ion_memory(&drv_ctx.ip_buf_ion_info[i]); |
| 5078 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5079 | DEBUG_PRINT_ERROR("Map Failed to allocate input buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5080 | return OMX_ErrorInsufficientResources; |
| 5081 | } |
| 5082 | } |
| 5083 | *bufferHdr = (m_inp_mem_ptr + i); |
| 5084 | if (secure_mode) |
| 5085 | drv_ctx.ptr_inputbuffer [i].bufferaddr = *bufferHdr; |
| 5086 | else |
| 5087 | drv_ctx.ptr_inputbuffer [i].bufferaddr = buf_addr; |
| 5088 | drv_ctx.ptr_inputbuffer [i].pmem_fd = pmem_fd; |
| 5089 | drv_ctx.ptr_inputbuffer [i].buffer_len = drv_ctx.ip_buf.buffer_size; |
| 5090 | drv_ctx.ptr_inputbuffer [i].mmaped_size = drv_ctx.ip_buf.buffer_size; |
| 5091 | drv_ctx.ptr_inputbuffer [i].offset = 0; |
| 5092 | |
| 5093 | |
| 5094 | buf.index = i; |
| 5095 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5096 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5097 | plane.bytesused = 0; |
| 5098 | plane.length = drv_ctx.ptr_inputbuffer [i].mmaped_size; |
| 5099 | plane.m.userptr = (unsigned long)drv_ctx.ptr_inputbuffer[i].bufferaddr; |
| 5100 | plane.reserved[0] =drv_ctx.ptr_inputbuffer [i].pmem_fd; |
| 5101 | plane.reserved[1] = 0; |
| 5102 | plane.data_offset = drv_ctx.ptr_inputbuffer[i].offset; |
| 5103 | buf.m.planes = &plane; |
| 5104 | buf.length = 1; |
| 5105 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5106 | DEBUG_PRINT_LOW("Set the input Buffer Idx: %d Addr: %p", i, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5107 | drv_ctx.ptr_inputbuffer[i].bufferaddr); |
| 5108 | |
| 5109 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5110 | |
| 5111 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5112 | DEBUG_PRINT_ERROR("Failed to prepare bufs"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5113 | /*TODO: How to handle this case */ |
| 5114 | return OMX_ErrorInsufficientResources; |
| 5115 | } |
| 5116 | |
| 5117 | input = *bufferHdr; |
| 5118 | BITMASK_SET(&m_inp_bm_count,i); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5119 | DEBUG_PRINT_LOW("Buffer address %p of pmem",*bufferHdr); |
Praveen Chavan | d443c0d | 2016-04-19 12:25:46 -0700 | [diff] [blame] | 5120 | |
| 5121 | if (allocate_native_handle) { |
| 5122 | native_handle_t *nh = native_handle_create(1 /*numFds*/, 0 /*numInts*/); |
| 5123 | nh->data[0] = drv_ctx.ptr_inputbuffer[i].pmem_fd; |
| 5124 | input->pBuffer = (OMX_U8 *)nh; |
| 5125 | } else if (secure_mode) { |
| 5126 | /*Legacy method, pass ion fd stashed directly in pBuffer*/ |
| 5127 | input->pBuffer = (OMX_U8 *)(intptr_t)drv_ctx.ptr_inputbuffer[i].pmem_fd; |
| 5128 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5129 | input->pBuffer = (OMX_U8 *)buf_addr; |
Praveen Chavan | d443c0d | 2016-04-19 12:25:46 -0700 | [diff] [blame] | 5130 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5131 | input->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5132 | input->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5133 | input->nAllocLen = drv_ctx.ip_buf.buffer_size; |
| 5134 | input->pAppPrivate = appData; |
| 5135 | input->nInputPortIndex = OMX_CORE_INPUT_PORT_INDEX; |
| 5136 | input->pInputPortPrivate = (void *)&drv_ctx.ptr_inputbuffer [i]; |
| 5137 | |
| 5138 | if (drv_ctx.disable_dmx) { |
| 5139 | eRet = allocate_desc_buffer(i); |
| 5140 | } |
| 5141 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5142 | DEBUG_PRINT_ERROR("ERROR:Input Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5143 | eRet = OMX_ErrorInsufficientResources; |
| 5144 | } |
| 5145 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | |
| 5149 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5150 | FUNCTION |
| 5151 | omx_vdec::AllocateOutputBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5152 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5153 | DESCRIPTION |
| 5154 | Helper fn for AllocateBuffer in the output pin |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5155 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5156 | PARAMETERS |
| 5157 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5158 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5159 | RETURN VALUE |
| 5160 | OMX Error None if everything went well. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5161 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5162 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5163 | OMX_ERRORTYPE omx_vdec::allocate_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5164 | OMX_IN OMX_HANDLETYPE hComp, |
| 5165 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5166 | OMX_IN OMX_U32 port, |
| 5167 | OMX_IN OMX_PTR appData, |
| 5168 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5169 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5170 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5171 | OMX_BUFFERHEADERTYPE *bufHdr= NULL; // buffer header |
| 5172 | unsigned i= 0; // Temporary counter |
| 5173 | struct vdec_setbuffer_cmd setbuffers; |
| 5174 | int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5175 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5176 | int ion_device_fd =-1; |
| 5177 | struct ion_allocation_data ion_alloc_data; |
| 5178 | struct ion_fd_data fd_ion_data; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5179 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5180 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5181 | DEBUG_PRINT_HIGH("Allocate o/p buffer Header: Cnt(%d) Sz(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5182 | drv_ctx.op_buf.actualcount, |
| 5183 | drv_ctx.op_buf.buffer_size); |
| 5184 | int nBufHdrSize = 0; |
| 5185 | int nPlatformEntrySize = 0; |
| 5186 | int nPlatformListSize = 0; |
| 5187 | int nPMEMInfoSize = 0; |
| 5188 | int pmem_fd = -1; |
| 5189 | unsigned char *pmem_baseaddress = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5190 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5191 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 5192 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 5193 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5194 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5195 | DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5196 | drv_ctx.op_buf.actualcount); |
| 5197 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 5198 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5199 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5200 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 5201 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 5202 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 5203 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 5204 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 5205 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5206 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5207 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5208 | sizeof(OMX_BUFFERHEADERTYPE), |
| 5209 | nPMEMInfoSize, |
| 5210 | nPlatformListSize); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5211 | DEBUG_PRINT_LOW("PE %d OutputBuffer Count %d",nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5212 | drv_ctx.op_buf.actualcount); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5213 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5214 | ion_device_fd = alloc_map_ion_memory( |
| 5215 | drv_ctx.op_buf.buffer_size * drv_ctx.op_buf.actualcount, |
| 5216 | drv_ctx.op_buf.alignment, |
| 5217 | &ion_alloc_data, &fd_ion_data, secure_mode ? ION_SECURE : 0); |
| 5218 | if (ion_device_fd < 0) { |
| 5219 | return OMX_ErrorInsufficientResources; |
| 5220 | } |
| 5221 | pmem_fd = fd_ion_data.fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5222 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5223 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5224 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5225 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5226 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5227 | drv_ctx.op_buf.buffer_size); |
| 5228 | return OMX_ErrorInsufficientResources; |
| 5229 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5230 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5231 | if (pmem_fd == 0) { |
| 5232 | pmem_fd = open (MEM_DEVICE,O_RDWR); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5233 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5234 | if (pmem_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5235 | DEBUG_PRINT_ERROR("ERROR:pmem fd for output buffer %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5236 | drv_ctx.op_buf.buffer_size); |
| 5237 | return OMX_ErrorInsufficientResources; |
| 5238 | } |
| 5239 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5240 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5241 | if (!align_pmem_buffers(pmem_fd, drv_ctx.op_buf.buffer_size * |
| 5242 | drv_ctx.op_buf.actualcount, |
| 5243 | drv_ctx.op_buf.alignment)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5244 | DEBUG_PRINT_ERROR("align_pmem_buffers() failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5245 | close(pmem_fd); |
| 5246 | return OMX_ErrorInsufficientResources; |
| 5247 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5248 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5249 | if (!secure_mode) { |
| 5250 | pmem_baseaddress = (unsigned char *)mmap(NULL, |
| 5251 | (drv_ctx.op_buf.buffer_size * |
| 5252 | drv_ctx.op_buf.actualcount), |
| 5253 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd,0); |
| 5254 | if (pmem_baseaddress == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5255 | DEBUG_PRINT_ERROR("MMAP failed for Size %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5256 | drv_ctx.op_buf.buffer_size); |
| 5257 | close(pmem_fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5258 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5259 | free_ion_memory(&drv_ctx.op_buf_ion_info[i]); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5260 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5261 | return OMX_ErrorInsufficientResources; |
| 5262 | } |
| 5263 | } |
| 5264 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 5265 | // Alloc mem for platform specific info |
| 5266 | char *pPtr=NULL; |
| 5267 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 5268 | nPMEMInfoSize,1); |
| 5269 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *)\ |
| 5270 | calloc (sizeof(struct vdec_bufferpayload), |
| 5271 | drv_ctx.op_buf.actualcount); |
| 5272 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 5273 | calloc (sizeof (struct vdec_output_frameinfo), |
| 5274 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5275 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 5276 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer "); |
| 5277 | return OMX_ErrorInsufficientResources; |
| 5278 | } |
| 5279 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5280 | #ifdef USE_ION |
| 5281 | drv_ctx.op_buf_ion_info = (struct vdec_ion *)\ |
| 5282 | calloc (sizeof(struct vdec_ion), |
| 5283 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 5284 | if (!drv_ctx.op_buf_ion_info) { |
| 5285 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 5286 | return OMX_ErrorInsufficientResources; |
| 5287 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5288 | #endif |
| 5289 | |
| 5290 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 5291 | && drv_ctx.ptr_respbuffer) { |
| 5292 | drv_ctx.ptr_outputbuffer[0].mmaped_size = |
| 5293 | (drv_ctx.op_buf.buffer_size * |
| 5294 | drv_ctx.op_buf.actualcount); |
| 5295 | bufHdr = m_out_mem_ptr; |
| 5296 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 5297 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 5298 | (((char *) m_platform_list) + nPlatformListSize); |
| 5299 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 5300 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 5301 | pPlatformList = m_platform_list; |
| 5302 | pPlatformEntry = m_platform_entry; |
| 5303 | pPMEMInfo = m_pmem_info; |
| 5304 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5305 | 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] | 5306 | |
| 5307 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5308 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, m_out_mem_ptr,pPlatformEntry); |
| 5309 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5310 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 5311 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 5312 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 5313 | // Set the values when we determine the right HxW param |
| 5314 | bufHdr->nAllocLen = bytes; |
| 5315 | bufHdr->nFilledLen = 0; |
| 5316 | bufHdr->pAppPrivate = appData; |
| 5317 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 5318 | // Platform specific PMEM Information |
| 5319 | // Initialize the Platform Entry |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5320 | //DEBUG_PRINT_LOW("Initializing the Platform Entry for %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5321 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 5322 | pPlatformEntry->entry = pPMEMInfo; |
| 5323 | // Initialize the Platform List |
| 5324 | pPlatformList->nEntries = 1; |
| 5325 | pPlatformList->entryList = pPlatformEntry; |
| 5326 | // Keep pBuffer NULL till vdec is opened |
| 5327 | bufHdr->pBuffer = NULL; |
| 5328 | bufHdr->nOffset = 0; |
| 5329 | |
| 5330 | pPMEMInfo->offset = drv_ctx.op_buf.buffer_size*i; |
| 5331 | pPMEMInfo->pmem_fd = 0; |
| 5332 | bufHdr->pPlatformPrivate = pPlatformList; |
| 5333 | |
| 5334 | drv_ctx.ptr_outputbuffer[i].pmem_fd = pmem_fd; |
| 5335 | m_pmem_info[i].pmem_fd = pmem_fd; |
| 5336 | #ifdef USE_ION |
| 5337 | drv_ctx.op_buf_ion_info[i].ion_device_fd = ion_device_fd; |
| 5338 | drv_ctx.op_buf_ion_info[i].ion_alloc_data = ion_alloc_data; |
| 5339 | drv_ctx.op_buf_ion_info[i].fd_ion_data = fd_ion_data; |
| 5340 | #endif |
| 5341 | |
| 5342 | /*Create a mapping between buffers*/ |
| 5343 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 5344 | drv_ctx.ptr_respbuffer[i].client_data = (void *)\ |
| 5345 | &drv_ctx.ptr_outputbuffer[i]; |
| 5346 | drv_ctx.ptr_outputbuffer[i].offset = drv_ctx.op_buf.buffer_size*i; |
| 5347 | drv_ctx.ptr_outputbuffer[i].bufferaddr = |
| 5348 | pmem_baseaddress + (drv_ctx.op_buf.buffer_size*i); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 5349 | m_pmem_info[i].size = drv_ctx.ptr_outputbuffer[i].buffer_len; |
| 5350 | m_pmem_info[i].mapped_size = drv_ctx.ptr_outputbuffer[i].mmaped_size; |
| 5351 | m_pmem_info[i].buffer = drv_ctx.ptr_outputbuffer[i].bufferaddr; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5352 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5353 | DEBUG_PRINT_LOW("pmem_fd = %d offset = %d address = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5354 | pmem_fd, drv_ctx.ptr_outputbuffer[i].offset, |
| 5355 | drv_ctx.ptr_outputbuffer[i].bufferaddr); |
| 5356 | // Move the buffer and buffer header pointers |
| 5357 | bufHdr++; |
| 5358 | pPMEMInfo++; |
| 5359 | pPlatformEntry++; |
| 5360 | pPlatformList++; |
| 5361 | } |
| 5362 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5363 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5364 | m_out_mem_ptr, pPtr); |
| 5365 | if (m_out_mem_ptr) { |
| 5366 | free(m_out_mem_ptr); |
| 5367 | m_out_mem_ptr = NULL; |
| 5368 | } |
| 5369 | if (pPtr) { |
| 5370 | free(pPtr); |
| 5371 | pPtr = NULL; |
| 5372 | } |
| 5373 | if (drv_ctx.ptr_outputbuffer) { |
| 5374 | free(drv_ctx.ptr_outputbuffer); |
| 5375 | drv_ctx.ptr_outputbuffer = NULL; |
| 5376 | } |
| 5377 | if (drv_ctx.ptr_respbuffer) { |
| 5378 | free(drv_ctx.ptr_respbuffer); |
| 5379 | drv_ctx.ptr_respbuffer = NULL; |
| 5380 | } |
| 5381 | #ifdef USE_ION |
| 5382 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5383 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5384 | free(drv_ctx.op_buf_ion_info); |
| 5385 | drv_ctx.op_buf_ion_info = NULL; |
| 5386 | } |
| 5387 | #endif |
| 5388 | eRet = OMX_ErrorInsufficientResources; |
| 5389 | } |
| 5390 | if (eRet == OMX_ErrorNone) |
| 5391 | eRet = allocate_extradata(); |
| 5392 | } |
| 5393 | |
| 5394 | for (i=0; i< drv_ctx.op_buf.actualcount; i++) { |
| 5395 | if (BITMASK_ABSENT(&m_out_bm_count,i)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5396 | DEBUG_PRINT_LOW("Found a Free Output Buffer %d",i); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5397 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5398 | } |
| 5399 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5400 | |
| 5401 | if (eRet == OMX_ErrorNone) { |
| 5402 | if (i < drv_ctx.op_buf.actualcount) { |
| 5403 | struct v4l2_buffer buf; |
| 5404 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 5405 | int rc; |
| 5406 | m_pmem_info[i].offset = drv_ctx.ptr_outputbuffer[i].offset; |
| 5407 | |
| 5408 | drv_ctx.ptr_outputbuffer[i].buffer_len = |
| 5409 | drv_ctx.op_buf.buffer_size; |
| 5410 | |
| 5411 | *bufferHdr = (m_out_mem_ptr + i ); |
| 5412 | if (secure_mode) { |
| 5413 | drv_ctx.ptr_outputbuffer[i].bufferaddr = *bufferHdr; |
| 5414 | } |
| 5415 | drv_ctx.ptr_outputbuffer[i].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 5416 | |
| 5417 | buf.index = i; |
| 5418 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5419 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5420 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 5421 | plane[0].m.userptr = (unsigned long)drv_ctx.ptr_outputbuffer[i].bufferaddr - |
| 5422 | (unsigned long)drv_ctx.ptr_outputbuffer[i].offset; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5423 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5424 | 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] | 5425 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5426 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[i].offset; |
| 5427 | plane[0].data_offset = 0; |
| 5428 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 5429 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 5430 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 5431 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + i * drv_ctx.extradata_info.buffer_size); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5432 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5433 | 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] | 5434 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5435 | plane[extra_idx].reserved[1] = i * drv_ctx.extradata_info.buffer_size; |
| 5436 | plane[extra_idx].data_offset = 0; |
| 5437 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5438 | DEBUG_PRINT_ERROR("Extradata index higher than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5439 | return OMX_ErrorBadParameter; |
| 5440 | } |
| 5441 | buf.m.planes = plane; |
| 5442 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5443 | 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] | 5444 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_PREPARE_BUF, &buf); |
| 5445 | if (rc) { |
| 5446 | /*TODO: How to handle this case */ |
| 5447 | return OMX_ErrorInsufficientResources; |
| 5448 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5449 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5450 | if (i == (drv_ctx.op_buf.actualcount -1 ) && !streaming[CAPTURE_PORT]) { |
| 5451 | enum v4l2_buf_type buf_type; |
| 5452 | buf_type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 5453 | rc=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 5454 | if (rc) { |
| 5455 | return OMX_ErrorInsufficientResources; |
| 5456 | } else { |
| 5457 | streaming[CAPTURE_PORT] = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5458 | DEBUG_PRINT_LOW("STREAMON Successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5459 | } |
| 5460 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5461 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5462 | (*bufferHdr)->pBuffer = (OMX_U8*)drv_ctx.ptr_outputbuffer[i].bufferaddr; |
| 5463 | (*bufferHdr)->pAppPrivate = appData; |
| 5464 | BITMASK_SET(&m_out_bm_count,i); |
| 5465 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5466 | DEBUG_PRINT_ERROR("All the Output Buffers have been Allocated ; Returning Insufficient"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5467 | eRet = OMX_ErrorInsufficientResources; |
| 5468 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5469 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5470 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5471 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | // AllocateBuffer -- API Call |
| 5476 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5477 | FUNCTION |
| 5478 | omx_vdec::AllocateBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5479 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5480 | DESCRIPTION |
| 5481 | Returns zero if all the buffers released.. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5482 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5483 | PARAMETERS |
| 5484 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5485 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5486 | RETURN VALUE |
| 5487 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5488 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5489 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5490 | OMX_ERRORTYPE omx_vdec::allocate_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5491 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 5492 | OMX_IN OMX_U32 port, |
| 5493 | OMX_IN OMX_PTR appData, |
| 5494 | OMX_IN OMX_U32 bytes) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5495 | { |
| 5496 | unsigned i = 0; |
| 5497 | OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type |
| 5498 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5499 | DEBUG_PRINT_LOW("Allocate buffer on port %d", (int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5500 | if (m_state == OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5501 | DEBUG_PRINT_ERROR("Allocate Buf in Invalid State"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5502 | return OMX_ErrorInvalidState; |
| 5503 | } |
| 5504 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5505 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 5506 | // If this is not the first allocation (i.e m_inp_mem_ptr is allocated), |
| 5507 | // ensure that use-buffer was never called. |
| 5508 | // Mix-and-match of useBuffer and allocateBuffer is not allowed |
| 5509 | if (m_inp_mem_ptr && input_use_buffer) { |
| 5510 | DEBUG_PRINT_ERROR("'Allocate' Input buffer called after 'Use' Input buffer !"); |
| 5511 | return OMX_ErrorUndefined; |
| 5512 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5513 | if (arbitrary_bytes) { |
| 5514 | eRet = allocate_input_heap_buffer (hComp,bufferHdr,port,appData,bytes); |
| 5515 | } else { |
| 5516 | eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes); |
| 5517 | } |
| 5518 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 5519 | if (output_use_buffer) { |
| 5520 | DEBUG_PRINT_ERROR("Allocate output buffer not allowed after use buffer"); |
| 5521 | return OMX_ErrorBadParameter; |
| 5522 | } |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5523 | eRet = client_buffers.allocate_buffers_color_convert(hComp,bufferHdr,port, |
| 5524 | appData,bytes); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5525 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5526 | DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d",(int)port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5527 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5528 | } |
| 5529 | DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5530 | if (eRet == OMX_ErrorNone) { |
| 5531 | if (allocate_done()) { |
| 5532 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5533 | // Send the callback now |
| 5534 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING); |
| 5535 | post_event(OMX_CommandStateSet,OMX_StateIdle, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5536 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5537 | } |
| 5538 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5539 | if (port == OMX_CORE_INPUT_PORT_INDEX && m_inp_bPopulated) { |
| 5540 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING)) { |
| 5541 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING); |
| 5542 | post_event(OMX_CommandPortEnable, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5543 | OMX_CORE_INPUT_PORT_INDEX, |
| 5544 | OMX_COMPONENT_GENERATE_EVENT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5545 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5546 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5547 | if (port == OMX_CORE_OUTPUT_PORT_INDEX && m_out_bPopulated) { |
| 5548 | if (BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING)) { |
| 5549 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5550 | post_event(OMX_CommandPortEnable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5551 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5552 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5553 | } |
| 5554 | } |
| 5555 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5556 | DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d",eRet); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5557 | return eRet; |
| 5558 | } |
| 5559 | |
| 5560 | // Free Buffer - API call |
| 5561 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5562 | FUNCTION |
| 5563 | omx_vdec::FreeBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5564 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5565 | DESCRIPTION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5566 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5567 | PARAMETERS |
| 5568 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5569 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5570 | RETURN VALUE |
| 5571 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5572 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5573 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5574 | OMX_ERRORTYPE omx_vdec::free_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5575 | OMX_IN OMX_U32 port, |
| 5576 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5577 | { |
| 5578 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5579 | unsigned int nPortIndex; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5580 | DEBUG_PRINT_LOW("In for decoder free_buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5581 | |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 5582 | auto_lock l(buf_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5583 | if (m_state == OMX_StateIdle && |
| 5584 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5585 | DEBUG_PRINT_LOW(" free buffer while Component in Loading pending"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5586 | } else if ((m_inp_bEnabled == OMX_FALSE && port == OMX_CORE_INPUT_PORT_INDEX)|| |
| 5587 | (m_out_bEnabled == OMX_FALSE && port == OMX_CORE_OUTPUT_PORT_INDEX)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5588 | DEBUG_PRINT_LOW("Free Buffer while port %lu disabled", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5589 | } else if ((port == OMX_CORE_INPUT_PORT_INDEX && |
| 5590 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING)) || |
| 5591 | (port == OMX_CORE_OUTPUT_PORT_INDEX && |
| 5592 | BITMASK_PRESENT(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5593 | DEBUG_PRINT_LOW("Free Buffer while port %lu enable pending", port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5594 | } else if (m_state == OMX_StateExecuting || m_state == OMX_StatePause) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5595 | 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] | 5596 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5597 | OMX_ErrorPortUnpopulated, |
| 5598 | OMX_COMPONENT_GENERATE_EVENT); |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 5599 | m_buffer_error = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5600 | return OMX_ErrorIncorrectStateOperation; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5601 | } else if (m_state != OMX_StateInvalid) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5602 | DEBUG_PRINT_ERROR("Invalid state to free buffer,port lost Buffers"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5603 | post_event(OMX_EventError, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5604 | OMX_ErrorPortUnpopulated, |
| 5605 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5606 | } |
| 5607 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5608 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 5609 | /*Check if arbitrary bytes*/ |
| 5610 | if (!arbitrary_bytes && !input_use_buffer) |
| 5611 | nPortIndex = buffer - m_inp_mem_ptr; |
| 5612 | else |
| 5613 | nPortIndex = buffer - m_inp_heap_ptr; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5614 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5615 | 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] | 5616 | if (nPortIndex < drv_ctx.ip_buf.actualcount && |
| 5617 | BITMASK_PRESENT(&m_inp_bm_count, nPortIndex)) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5618 | // Clear the bit associated with it. |
| 5619 | BITMASK_CLEAR(&m_inp_bm_count,nPortIndex); |
| 5620 | BITMASK_CLEAR(&m_heap_inp_bm_count,nPortIndex); |
| 5621 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5622 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5623 | DEBUG_PRINT_LOW("Free pmem Buffer index %d",nPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5624 | if (m_phdr_pmem_ptr) |
| 5625 | free_input_buffer(m_phdr_pmem_ptr[nPortIndex]); |
| 5626 | } else { |
| 5627 | if (arbitrary_bytes) { |
| 5628 | if (m_phdr_pmem_ptr) |
| 5629 | free_input_buffer(nPortIndex,m_phdr_pmem_ptr[nPortIndex]); |
| 5630 | else |
| 5631 | free_input_buffer(nPortIndex,NULL); |
| 5632 | } else |
| 5633 | free_input_buffer(buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5634 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5635 | m_inp_bPopulated = OMX_FALSE; |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5636 | if(release_input_done()) |
| 5637 | release_buffers(this, VDEC_BUFFER_TYPE_INPUT); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5638 | /*Free the Buffer Header*/ |
| 5639 | if (release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5640 | DEBUG_PRINT_HIGH("ALL input buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5641 | free_input_buffer_header(); |
| 5642 | } |
| 5643 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5644 | DEBUG_PRINT_ERROR("Error: free_buffer ,Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5645 | eRet = OMX_ErrorBadPortIndex; |
| 5646 | } |
| 5647 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5648 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING) |
| 5649 | && release_input_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5650 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5651 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING); |
| 5652 | post_event(OMX_CommandPortDisable, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5653 | OMX_CORE_INPUT_PORT_INDEX, |
| 5654 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5655 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5656 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5657 | // check if the buffer is valid |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5658 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 5659 | if (nPortIndex < drv_ctx.op_buf.actualcount && |
| 5660 | BITMASK_PRESENT(&m_out_bm_count, nPortIndex)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5661 | 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] | 5662 | // Clear the bit associated with it. |
| 5663 | BITMASK_CLEAR(&m_out_bm_count,nPortIndex); |
| 5664 | m_out_bPopulated = OMX_FALSE; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 5665 | client_buffers.free_output_buffer (buffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5666 | |
Surajit Podder | 12aefac | 2013-08-06 18:43:32 +0530 | [diff] [blame] | 5667 | if(release_output_done()) { |
| 5668 | release_buffers(this, VDEC_BUFFER_TYPE_OUTPUT); |
| 5669 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5670 | if (release_output_done()) { |
| 5671 | free_output_buffer_header(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5672 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5673 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5674 | DEBUG_PRINT_ERROR("Error: free_buffer , Port Index Invalid"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5675 | eRet = OMX_ErrorBadPortIndex; |
| 5676 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5677 | if (BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING) |
| 5678 | && release_output_done()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5679 | DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5680 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5681 | DEBUG_PRINT_LOW("MOVING TO DISABLED STATE"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5682 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5683 | #ifdef _ANDROID_ICS_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5684 | if (m_enable_android_native_buffers) { |
| 5685 | DEBUG_PRINT_LOW("FreeBuffer - outport disabled: reset native buffers"); |
| 5686 | memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 5687 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5688 | #endif |
| 5689 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5690 | post_event(OMX_CommandPortDisable, |
| 5691 | OMX_CORE_OUTPUT_PORT_INDEX, |
| 5692 | OMX_COMPONENT_GENERATE_EVENT); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5693 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5694 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5695 | eRet = OMX_ErrorBadPortIndex; |
| 5696 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5697 | if ((eRet == OMX_ErrorNone) && |
| 5698 | (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING))) { |
| 5699 | if (release_done()) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5700 | // Send the callback now |
| 5701 | BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING); |
| 5702 | post_event(OMX_CommandStateSet, OMX_StateLoaded, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5703 | OMX_COMPONENT_GENERATE_EVENT); |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 5704 | m_buffer_error = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5705 | } |
| 5706 | } |
| 5707 | return eRet; |
| 5708 | } |
| 5709 | |
| 5710 | |
| 5711 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5712 | FUNCTION |
| 5713 | omx_vdec::EmptyThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5714 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5715 | DESCRIPTION |
| 5716 | This routine is used to push the encoded video frames to |
| 5717 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5718 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5719 | PARAMETERS |
| 5720 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5721 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5722 | RETURN VALUE |
| 5723 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5724 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5725 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5726 | OMX_ERRORTYPE omx_vdec::empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5727 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5728 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5729 | OMX_ERRORTYPE ret1 = OMX_ErrorNone; |
| 5730 | unsigned int nBufferIndex = drv_ctx.ip_buf.actualcount; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5731 | |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 5732 | if (m_state != OMX_StateExecuting && |
| 5733 | m_state != OMX_StatePause && |
| 5734 | m_state != OMX_StateIdle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5735 | DEBUG_PRINT_ERROR("Empty this buffer in Invalid State"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5736 | return OMX_ErrorInvalidState; |
| 5737 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5738 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5739 | if (buffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5740 | DEBUG_PRINT_ERROR("ERROR:ETB Buffer is NULL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5741 | return OMX_ErrorBadParameter; |
| 5742 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5743 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5744 | if (!m_inp_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5745 | DEBUG_PRINT_ERROR("ERROR:ETB incorrect state operation, input port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5746 | return OMX_ErrorIncorrectStateOperation; |
| 5747 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5748 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5749 | if (buffer->nInputPortIndex != OMX_CORE_INPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5750 | DEBUG_PRINT_ERROR("ERROR:ETB invalid port in header %lu", buffer->nInputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5751 | return OMX_ErrorBadPortIndex; |
| 5752 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5753 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5754 | if (perf_flag) { |
| 5755 | if (!latency) { |
| 5756 | dec_time.stop(); |
| 5757 | latency = dec_time.processing_time_us(); |
| 5758 | dec_time.start(); |
| 5759 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5760 | } |
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 | if (arbitrary_bytes) { |
| 5763 | nBufferIndex = buffer - m_inp_heap_ptr; |
| 5764 | } else { |
| 5765 | if (input_use_buffer == true) { |
| 5766 | nBufferIndex = buffer - m_inp_heap_ptr; |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 5767 | if (nBufferIndex >= drv_ctx.ip_buf.actualcount ) { |
| 5768 | DEBUG_PRINT_ERROR("ERROR: ETB nBufferIndex is invalid in use-buffer mode"); |
| 5769 | return OMX_ErrorBadParameter; |
| 5770 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5771 | m_inp_mem_ptr[nBufferIndex].nFilledLen = m_inp_heap_ptr[nBufferIndex].nFilledLen; |
| 5772 | m_inp_mem_ptr[nBufferIndex].nTimeStamp = m_inp_heap_ptr[nBufferIndex].nTimeStamp; |
| 5773 | m_inp_mem_ptr[nBufferIndex].nFlags = m_inp_heap_ptr[nBufferIndex].nFlags; |
| 5774 | buffer = &m_inp_mem_ptr[nBufferIndex]; |
| 5775 | DEBUG_PRINT_LOW("Non-Arbitrary mode - buffer address is: malloc %p, pmem%p in Index %d, buffer %p of size %lu", |
| 5776 | &m_inp_heap_ptr[nBufferIndex], &m_inp_mem_ptr[nBufferIndex],nBufferIndex, buffer, buffer->nFilledLen); |
| 5777 | } else { |
| 5778 | nBufferIndex = buffer - m_inp_mem_ptr; |
| 5779 | } |
| 5780 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5781 | |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 5782 | if (nBufferIndex >= drv_ctx.ip_buf.actualcount ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5783 | DEBUG_PRINT_ERROR("ERROR:ETB nBufferIndex is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5784 | return OMX_ErrorBadParameter; |
| 5785 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5786 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 5787 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 5788 | codec_config_flag = true; |
| 5789 | DEBUG_PRINT_LOW("%s: codec_config buffer", __FUNCTION__); |
| 5790 | } |
| 5791 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5792 | DEBUG_PRINT_LOW("[ETB] BHdr(%p) pBuf(%p) nTS(%lld) nFL(%lu)", |
| 5793 | buffer, buffer->pBuffer, buffer->nTimeStamp, buffer->nFilledLen); |
| 5794 | if (arbitrary_bytes) { |
| 5795 | post_event ((unsigned)hComp,(unsigned)buffer, |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5796 | OMX_COMPONENT_GENERATE_ETB_ARBITRARY); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5797 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5798 | post_event ((unsigned)hComp,(unsigned)buffer,OMX_COMPONENT_GENERATE_ETB); |
| 5799 | } |
Praveen Chavan | ece713f | 2014-12-10 18:00:04 -0800 | [diff] [blame] | 5800 | time_stamp_dts.insert_timestamp(buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5801 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5805 | FUNCTION |
| 5806 | omx_vdec::empty_this_buffer_proxy |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5807 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5808 | DESCRIPTION |
| 5809 | This routine is used to push the encoded video frames to |
| 5810 | the video decoder. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5811 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5812 | PARAMETERS |
| 5813 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5814 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5815 | RETURN VALUE |
| 5816 | OMX Error None if everything went successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5817 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5818 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5819 | 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] | 5820 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5821 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5822 | int push_cnt = 0,i=0; |
| 5823 | unsigned nPortIndex = 0; |
| 5824 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 5825 | struct vdec_input_frameinfo frameinfo; |
| 5826 | struct vdec_bufferpayload *temp_buffer; |
| 5827 | struct vdec_seqheader seq_header; |
| 5828 | bool port_setting_changed = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5829 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5830 | /*Should we generate a Aync error event*/ |
| 5831 | if (buffer == NULL || buffer->pInputPortPrivate == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5832 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy is invalid"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5833 | return OMX_ErrorBadParameter; |
| 5834 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5835 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5836 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5837 | |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 5838 | if (nPortIndex >= drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5839 | DEBUG_PRINT_ERROR("ERROR:empty_this_buffer_proxy invalid nPortIndex[%u]", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5840 | nPortIndex); |
| 5841 | return OMX_ErrorBadParameter; |
| 5842 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5843 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5844 | pending_input_buffers++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5845 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5846 | /* return zero length and not an EOS buffer */ |
| 5847 | if (!arbitrary_bytes && (buffer->nFilledLen == 0) && |
| 5848 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5849 | DEBUG_PRINT_HIGH("return zero legth buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5850 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5851 | OMX_COMPONENT_GENERATE_EBD); |
| 5852 | return OMX_ErrorNone; |
| 5853 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5854 | |
c_sridur | 0af9cef | 2015-02-05 12:07:17 +0530 | [diff] [blame] | 5855 | if (input_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5856 | DEBUG_PRINT_LOW("Flush in progress return buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5857 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS, |
| 5858 | OMX_COMPONENT_GENERATE_EBD); |
| 5859 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 5862 | auto_lock l(buf_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5863 | temp_buffer = (struct vdec_bufferpayload *)buffer->pInputPortPrivate; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5864 | |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 5865 | if (!temp_buffer || (temp_buffer - drv_ctx.ptr_inputbuffer) > (int)drv_ctx.ip_buf.actualcount) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5866 | return OMX_ErrorBadParameter; |
| 5867 | } |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 5868 | if (BITMASK_ABSENT(&m_inp_bm_count, nPortIndex) || m_buffer_error) { |
| 5869 | DEBUG_PRINT_ERROR("ETBProxy: ERROR: invalid buffer, nPortIndex %u", nPortIndex); |
| 5870 | return OMX_ErrorBadParameter; |
| 5871 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5872 | /* If its first frame, H264 codec and reject is true, then parse the nal |
| 5873 | and get the profile. Based on this, reject the clip playback */ |
| 5874 | if (first_frame == 0 && codec_type_parse == CODEC_TYPE_H264 && |
| 5875 | m_reject_avc_1080p_mp) { |
| 5876 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5877 | DEBUG_PRINT_ERROR("Parse nal to get the profile"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5878 | h264_parser->parse_nal((OMX_U8*)buffer->pBuffer, buffer->nFilledLen, |
| 5879 | NALU_TYPE_SPS); |
| 5880 | m_profile = h264_parser->get_profile(); |
| 5881 | ret = is_video_session_supported(); |
| 5882 | if (ret) { |
| 5883 | post_event ((unsigned int)buffer,VDEC_S_SUCCESS,OMX_COMPONENT_GENERATE_EBD); |
| 5884 | post_event(OMX_EventError, OMX_ErrorInvalidState,OMX_COMPONENT_GENERATE_EVENT); |
| 5885 | /* Move the state to Invalid to avoid queueing of pending ETB to the driver */ |
| 5886 | m_state = OMX_StateInvalid; |
| 5887 | return OMX_ErrorNone; |
| 5888 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5889 | } |
| 5890 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5891 | DEBUG_PRINT_LOW("ETBProxy: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5892 | /*for use buffer we need to memcpy the data*/ |
| 5893 | temp_buffer->buffer_len = buffer->nFilledLen; |
| 5894 | |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 5895 | if (input_use_buffer && temp_buffer->bufferaddr) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5896 | if (buffer->nFilledLen <= temp_buffer->buffer_len) { |
| 5897 | if (arbitrary_bytes) { |
| 5898 | memcpy (temp_buffer->bufferaddr, (buffer->pBuffer + buffer->nOffset),buffer->nFilledLen); |
| 5899 | } else { |
| 5900 | memcpy (temp_buffer->bufferaddr, (m_inp_heap_ptr[nPortIndex].pBuffer + m_inp_heap_ptr[nPortIndex].nOffset), |
| 5901 | buffer->nFilledLen); |
| 5902 | } |
| 5903 | } else { |
| 5904 | return OMX_ErrorBadParameter; |
| 5905 | } |
| 5906 | |
| 5907 | } |
| 5908 | |
| 5909 | frameinfo.bufferaddr = temp_buffer->bufferaddr; |
| 5910 | frameinfo.client_data = (void *) buffer; |
| 5911 | frameinfo.datalen = temp_buffer->buffer_len; |
| 5912 | frameinfo.flags = 0; |
| 5913 | frameinfo.offset = buffer->nOffset; |
| 5914 | frameinfo.pmem_fd = temp_buffer->pmem_fd; |
| 5915 | frameinfo.pmem_offset = temp_buffer->offset; |
| 5916 | frameinfo.timestamp = buffer->nTimeStamp; |
| 5917 | if (drv_ctx.disable_dmx && m_desc_buffer_ptr && m_desc_buffer_ptr[nPortIndex].buf_addr) { |
| 5918 | DEBUG_PRINT_LOW("ETB: dmx enabled"); |
| 5919 | if (m_demux_entries == 0) { |
| 5920 | extract_demux_addr_offsets(buffer); |
| 5921 | } |
| 5922 | |
| 5923 | DEBUG_PRINT_LOW("ETB: handle_demux_data - entries=%lu",m_demux_entries); |
| 5924 | handle_demux_data(buffer); |
| 5925 | frameinfo.desc_addr = (OMX_U8 *)m_desc_buffer_ptr[nPortIndex].buf_addr; |
| 5926 | frameinfo.desc_size = m_desc_buffer_ptr[nPortIndex].desc_data_size; |
| 5927 | } else { |
| 5928 | frameinfo.desc_addr = NULL; |
| 5929 | frameinfo.desc_size = 0; |
| 5930 | } |
| 5931 | if (!arbitrary_bytes) { |
| 5932 | frameinfo.flags |= buffer->nFlags; |
| 5933 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5934 | |
| 5935 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5936 | if (m_debug_timestamp) { |
| 5937 | if (arbitrary_bytes) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5938 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5939 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5940 | } else if (!arbitrary_bytes && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5941 | DEBUG_PRINT_LOW("Inserting TIMESTAMP (%lld) into queue", buffer->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5942 | m_timestamp_list.insert_ts(buffer->nTimeStamp); |
| 5943 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5944 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5945 | #endif |
| 5946 | |
Praveen Chavan | d443c0d | 2016-04-19 12:25:46 -0700 | [diff] [blame] | 5947 | log_input_buffers((const char *)temp_buffer->bufferaddr, temp_buffer->buffer_len); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5948 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 5949 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5950 | frameinfo.flags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5951 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 5952 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 5953 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5954 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5955 | 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] | 5956 | frameinfo.flags |= VDEC_BUFFERFLAG_EOS; |
| 5957 | h264_scratch.nFilledLen = 0; |
| 5958 | nal_count = 0; |
| 5959 | look_ahead_nal = false; |
| 5960 | frame_count = 0; |
| 5961 | if (m_frame_parser.mutils) |
| 5962 | m_frame_parser.mutils->initialize_frame_checking_environment(); |
| 5963 | m_frame_parser.flush(); |
| 5964 | h264_last_au_ts = LLONG_MAX; |
| 5965 | h264_last_au_flags = 0; |
| 5966 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 5967 | m_demux_entries = 0; |
| 5968 | } |
| 5969 | struct v4l2_buffer buf; |
| 5970 | struct v4l2_plane plane; |
| 5971 | memset( (void *)&buf, 0, sizeof(buf)); |
| 5972 | memset( (void *)&plane, 0, sizeof(plane)); |
| 5973 | int rc; |
| 5974 | unsigned long print_count; |
| 5975 | if (temp_buffer->buffer_len == 0 || (buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 5976 | buf.flags = V4L2_QCOM_BUF_FLAG_EOS; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 5977 | DEBUG_PRINT_HIGH("INPUT EOS reached") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 5978 | } |
| 5979 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 5980 | buf.index = nPortIndex; |
| 5981 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 5982 | buf.memory = V4L2_MEMORY_USERPTR; |
| 5983 | plane.bytesused = temp_buffer->buffer_len; |
| 5984 | plane.length = drv_ctx.ip_buf.buffer_size; |
| 5985 | plane.m.userptr = (unsigned long)temp_buffer->bufferaddr - |
| 5986 | (unsigned long)temp_buffer->offset; |
| 5987 | plane.reserved[0] = temp_buffer->pmem_fd; |
| 5988 | plane.reserved[1] = temp_buffer->offset; |
| 5989 | plane.data_offset = 0; |
| 5990 | buf.m.planes = &plane; |
| 5991 | buf.length = 1; |
| 5992 | if (frameinfo.timestamp >= LLONG_MAX) { |
| 5993 | buf.flags |= V4L2_QCOM_BUF_TIMESTAMP_INVALID; |
| 5994 | } |
| 5995 | //assumption is that timestamp is in milliseconds |
| 5996 | buf.timestamp.tv_sec = frameinfo.timestamp / 1000000; |
| 5997 | buf.timestamp.tv_usec = (frameinfo.timestamp % 1000000); |
| 5998 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ? V4L2_QCOM_BUF_FLAG_CODECCONFIG: 0; |
| 5999 | buf.flags |= (buffer->nFlags & OMX_BUFFERFLAG_DECODEONLY) ? V4L2_QCOM_BUF_FLAG_DECODEONLY: 0; |
Deva Ramasubramanian | 46a1795 | 2012-08-24 11:35:26 -0700 | [diff] [blame] | 6000 | |
Pushkaraj Patil | 20bd6bf | 2014-12-22 19:33:08 +0530 | [diff] [blame] | 6001 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 6002 | DEBUG_PRINT_LOW("Increment codec_config buffer counter"); |
| 6003 | android_atomic_inc(&m_queued_codec_config_count); |
| 6004 | } |
| 6005 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6006 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 6007 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6008 | DEBUG_PRINT_ERROR("Failed to qbuf Input buffer to driver"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6009 | return OMX_ErrorHardware; |
| 6010 | } |
Deva Ramasubramanian | 1fd9381 | 2014-03-26 15:17:15 -0700 | [diff] [blame] | 6011 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 6012 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 6013 | codec_config_flag = false; |
| 6014 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6015 | if (!streaming[OUTPUT_PORT]) { |
| 6016 | enum v4l2_buf_type buf_type; |
| 6017 | int ret,r; |
Vinay Kalia | 8579376 | 2012-06-14 19:12:34 -0700 | [diff] [blame] | 6018 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6019 | buf_type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6020 | DEBUG_PRINT_LOW("send_command_proxy(): Idle-->Executing"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6021 | ret=ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMON,&buf_type); |
| 6022 | if (!ret) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6023 | DEBUG_PRINT_HIGH("Streamon on OUTPUT Plane was successful"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6024 | streaming[OUTPUT_PORT] = true; |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 6025 | } else if (errno == EBUSY) { |
| 6026 | DEBUG_PRINT_ERROR("Failed to call stream on OUTPUT due to HW_OVERLOAD"); |
| 6027 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
| 6028 | OMX_COMPONENT_GENERATE_EBD); |
| 6029 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6030 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6031 | DEBUG_PRINT_ERROR("Failed to call streamon on OUTPUT"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6032 | DEBUG_PRINT_LOW("If Stream on failed no buffer should be queued"); |
Jia Meng | 1e236c8 | 2014-04-03 10:54:39 +0800 | [diff] [blame] | 6033 | post_event ((unsigned int)buffer, VDEC_S_SUCCESS, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6034 | OMX_COMPONENT_GENERATE_EBD); |
| 6035 | return OMX_ErrorBadParameter; |
| 6036 | } |
| 6037 | } |
| 6038 | DEBUG_PRINT_LOW("[ETBP] pBuf(%p) nTS(%lld) Sz(%d)", |
| 6039 | frameinfo.bufferaddr, frameinfo.timestamp, frameinfo.datalen); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6040 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6041 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6045 | FUNCTION |
| 6046 | omx_vdec::FillThisBuffer |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6047 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6048 | DESCRIPTION |
| 6049 | IL client uses this method to release the frame buffer |
| 6050 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6051 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6052 | PARAMETERS |
| 6053 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6054 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6055 | RETURN VALUE |
| 6056 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6057 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6058 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6059 | OMX_ERRORTYPE omx_vdec::fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6060 | OMX_IN OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6061 | { |
Praveen Chavan | eac7fd0 | 2016-04-25 10:03:42 -0700 | [diff] [blame] | 6062 | if (m_state != OMX_StateExecuting && |
| 6063 | m_state != OMX_StatePause && |
| 6064 | m_state != OMX_StateIdle) { |
| 6065 | DEBUG_PRINT_ERROR("FTB in Invalid State"); |
| 6066 | return OMX_ErrorInvalidState; |
| 6067 | } |
| 6068 | |
| 6069 | if (!m_out_bEnabled) { |
| 6070 | DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled."); |
| 6071 | return OMX_ErrorIncorrectStateOperation; |
| 6072 | } |
| 6073 | |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6074 | unsigned nPortIndex = 0; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6075 | if (dynamic_buf_mode) { |
| 6076 | private_handle_t *handle = NULL; |
| 6077 | struct VideoDecoderOutputMetaData *meta; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6078 | unsigned int nPortIndex = 0; |
| 6079 | |
| 6080 | if (!buffer || !buffer->pBuffer) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6081 | DEBUG_PRINT_ERROR("%s: invalid params: %p", __FUNCTION__, buffer); |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6082 | return OMX_ErrorBadParameter; |
| 6083 | } |
| 6084 | |
| 6085 | //get the buffer type and fd info |
| 6086 | meta = (struct VideoDecoderOutputMetaData *)buffer->pBuffer; |
| 6087 | handle = (private_handle_t *)meta->pHandle; |
Arun Menon | b49abf2 | 2013-12-14 21:38:10 -0800 | [diff] [blame] | 6088 | DEBUG_PRINT_LOW("FTB: metabuf: %p buftype: %d bufhndl: %p ", meta, meta->eType, meta->pHandle); |
| 6089 | |
| 6090 | if (!handle) { |
| 6091 | DEBUG_PRINT_ERROR("FTB: Error: IL client passed an invalid buf handle - %p", handle); |
| 6092 | return OMX_ErrorBadParameter; |
| 6093 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6094 | //Fill outputbuffer with buffer details, this will be sent to f/w during VIDIOC_QBUF |
| 6095 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6096 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd = handle->fd; |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6097 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = (OMX_U8*) buffer; |
ApurupaPattapu | f693a4d | 2013-12-04 16:07:07 -0800 | [diff] [blame] | 6098 | |
| 6099 | //Store private handle from GraphicBuffer |
| 6100 | native_buffer[nPortIndex].privatehandle = handle; |
| 6101 | native_buffer[nPortIndex].nativehandle = handle; |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6102 | |
| 6103 | //buffer->nAllocLen will be sizeof(struct VideoDecoderOutputMetaData). Overwrite |
| 6104 | //this with a more sane size so that we don't compensate in rest of code |
| 6105 | //We'll restore this size later on, so that it's transparent to client |
| 6106 | buffer->nFilledLen = 0; |
Deva Ramasubramanian | 03a5bb9 | 2014-04-25 19:03:50 -0700 | [diff] [blame] | 6107 | buffer->nAllocLen = handle->size; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 6108 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6109 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6110 | if (!m_out_bEnabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6111 | DEBUG_PRINT_ERROR("ERROR:FTB incorrect state operation, output port is disabled."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6112 | return OMX_ErrorIncorrectStateOperation; |
| 6113 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6114 | |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6115 | nPortIndex = buffer - client_buffers.get_il_buf_hdr(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6116 | if (buffer == NULL || |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6117 | (nPortIndex >= drv_ctx.op_buf.actualcount)) { |
| 6118 | DEBUG_PRINT_ERROR("FTB: ERROR: invalid buffer index, nPortIndex %u bufCount %u", |
| 6119 | nPortIndex, drv_ctx.op_buf.actualcount); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6120 | return OMX_ErrorBadParameter; |
| 6121 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6122 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6123 | if (buffer->nOutputPortIndex != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6124 | DEBUG_PRINT_ERROR("ERROR:FTB invalid port in header %lu", buffer->nOutputPortIndex); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6125 | return OMX_ErrorBadPortIndex; |
| 6126 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6127 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6128 | DEBUG_PRINT_LOW("[FTB] bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 6129 | post_event((unsigned) hComp, (unsigned)buffer, m_fill_output_msg); |
| 6130 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6131 | } |
| 6132 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6133 | FUNCTION |
| 6134 | omx_vdec::fill_this_buffer_proxy |
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 | DESCRIPTION |
| 6137 | IL client uses this method to release the frame buffer |
| 6138 | after displaying them. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6139 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6140 | PARAMETERS |
| 6141 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6142 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6143 | RETURN VALUE |
| 6144 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6145 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6146 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6147 | OMX_ERRORTYPE omx_vdec::fill_this_buffer_proxy( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6148 | OMX_IN OMX_HANDLETYPE hComp, |
| 6149 | OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6150 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6151 | OMX_ERRORTYPE nRet = OMX_ErrorNone; |
| 6152 | OMX_BUFFERHEADERTYPE *buffer = bufferAdd; |
| 6153 | unsigned nPortIndex = 0; |
| 6154 | struct vdec_fillbuffer_cmd fillbuffer; |
| 6155 | struct vdec_bufferpayload *ptr_outputbuffer = NULL; |
| 6156 | struct vdec_output_frameinfo *ptr_respbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6157 | |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 6158 | auto_lock l(buf_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6159 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6160 | |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 6161 | if (bufferAdd == NULL || nPortIndex >= drv_ctx.op_buf.actualcount) { |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6162 | DEBUG_PRINT_ERROR("FTBProxy: ERROR: invalid buffer index, nPortIndex %u bufCount %u", |
| 6163 | nPortIndex, drv_ctx.op_buf.actualcount); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6164 | return OMX_ErrorBadParameter; |
Jia Meng | 2d51b93 | 2014-07-10 14:02:54 +0800 | [diff] [blame] | 6165 | } |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 6166 | if (BITMASK_ABSENT(&m_out_bm_count, nPortIndex) || m_buffer_error) { |
| 6167 | DEBUG_PRINT_ERROR("FTBProxy: ERROR: invalid buffer, nPortIndex %u", nPortIndex); |
| 6168 | return OMX_ErrorBadParameter; |
| 6169 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6170 | DEBUG_PRINT_LOW("FTBProxy: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6171 | bufferAdd, bufferAdd->pBuffer); |
| 6172 | /*Return back the output buffer to client*/ |
| 6173 | if (m_out_bEnabled != OMX_TRUE || output_flush_progress == true) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6174 | DEBUG_PRINT_LOW("Output Buffers return flush/disable condition"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6175 | buffer->nFilledLen = 0; |
| 6176 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6177 | return OMX_ErrorNone; |
| 6178 | } |
Arun Menon | 50ab1bf | 2014-01-08 18:02:19 -0800 | [diff] [blame] | 6179 | |
| 6180 | if (dynamic_buf_mode) { |
| 6181 | //map the buffer handle based on the size set on output port definition. |
| 6182 | if (!secure_mode) { |
| 6183 | drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr = |
| 6184 | (OMX_U8*)mmap(0, drv_ctx.op_buf.buffer_size, |
| 6185 | PROT_READ|PROT_WRITE, MAP_SHARED, |
| 6186 | drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, 0); |
| 6187 | } |
| 6188 | drv_ctx.ptr_outputbuffer[nPortIndex].offset = 0; |
| 6189 | drv_ctx.ptr_outputbuffer[nPortIndex].buffer_len = drv_ctx.op_buf.buffer_size; |
| 6190 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size = drv_ctx.op_buf.buffer_size; |
| 6191 | buf_ref_add(drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd, |
| 6192 | drv_ctx.ptr_outputbuffer[nPortIndex].offset); |
| 6193 | } |
| 6194 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6195 | pending_output_buffers++; |
| 6196 | buffer = client_buffers.get_dr_buf_hdr(bufferAdd); |
| 6197 | ptr_respbuffer = (struct vdec_output_frameinfo*)buffer->pOutputPortPrivate; |
| 6198 | if (ptr_respbuffer) { |
| 6199 | ptr_outputbuffer = (struct vdec_bufferpayload*)ptr_respbuffer->client_data; |
| 6200 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6201 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6202 | if (ptr_respbuffer == NULL || ptr_outputbuffer == NULL) { |
| 6203 | DEBUG_PRINT_ERROR("resp buffer or outputbuffer is NULL"); |
| 6204 | buffer->nFilledLen = 0; |
| 6205 | m_cb.FillBufferDone (hComp,m_app_data,buffer); |
| 6206 | pending_output_buffers--; |
| 6207 | return OMX_ErrorBadParameter; |
| 6208 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6209 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6210 | int rc = 0; |
| 6211 | struct v4l2_buffer buf; |
| 6212 | struct v4l2_plane plane[VIDEO_MAX_PLANES]; |
| 6213 | memset( (void *)&buf, 0, sizeof(buf)); |
| 6214 | memset( (void *)plane, 0, (sizeof(struct v4l2_plane)*VIDEO_MAX_PLANES)); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6215 | unsigned int extra_idx = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6216 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6217 | buf.index = nPortIndex; |
| 6218 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 6219 | buf.memory = V4L2_MEMORY_USERPTR; |
| 6220 | plane[0].bytesused = buffer->nFilledLen; |
| 6221 | plane[0].length = drv_ctx.op_buf.buffer_size; |
| 6222 | plane[0].m.userptr = |
| 6223 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr - |
| 6224 | (unsigned long)drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6225 | plane[0].reserved[0] = drv_ctx.ptr_outputbuffer[nPortIndex].pmem_fd; |
| 6226 | plane[0].reserved[1] = drv_ctx.ptr_outputbuffer[nPortIndex].offset; |
| 6227 | plane[0].data_offset = 0; |
| 6228 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 6229 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 6230 | plane[extra_idx].bytesused = 0; |
| 6231 | plane[extra_idx].length = drv_ctx.extradata_info.buffer_size; |
| 6232 | plane[extra_idx].m.userptr = (long unsigned int) (drv_ctx.extradata_info.uaddr + nPortIndex * drv_ctx.extradata_info.buffer_size); |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 6233 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6234 | 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] | 6235 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6236 | plane[extra_idx].reserved[1] = nPortIndex * drv_ctx.extradata_info.buffer_size; |
| 6237 | plane[extra_idx].data_offset = 0; |
| 6238 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 6239 | DEBUG_PRINT_ERROR("Extradata index higher than expected: %u", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6240 | return OMX_ErrorBadParameter; |
| 6241 | } |
| 6242 | buf.m.planes = plane; |
| 6243 | buf.length = drv_ctx.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6244 | 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] | 6245 | plane[0].reserved[0],plane[extra_idx].reserved[0], plane[extra_idx].reserved[1]); |
| 6246 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6247 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_QBUF, &buf); |
| 6248 | if (rc) { |
| 6249 | /*TODO: How to handle this case */ |
| 6250 | DEBUG_PRINT_ERROR("Failed to qbuf to driver"); |
| 6251 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6252 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6256 | FUNCTION |
| 6257 | omx_vdec::SetCallbacks |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6258 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6259 | DESCRIPTION |
| 6260 | Set the callbacks. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6261 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6262 | PARAMETERS |
| 6263 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6264 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6265 | RETURN VALUE |
| 6266 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6267 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6268 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6269 | OMX_ERRORTYPE omx_vdec::set_callbacks(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6270 | OMX_IN OMX_CALLBACKTYPE* callbacks, |
| 6271 | OMX_IN OMX_PTR appData) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6272 | { |
| 6273 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6274 | m_cb = *callbacks; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6275 | DEBUG_PRINT_LOW("Callbacks Set %p %p %p",m_cb.EmptyBufferDone,\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6276 | m_cb.EventHandler,m_cb.FillBufferDone); |
| 6277 | m_app_data = appData; |
| 6278 | return OMX_ErrorNotImplemented; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6282 | FUNCTION |
| 6283 | omx_vdec::ComponentDeInit |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6284 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6285 | DESCRIPTION |
| 6286 | Destroys the component and release memory allocated to the heap. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6287 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6288 | PARAMETERS |
| 6289 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6290 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6291 | RETURN VALUE |
| 6292 | OMX Error None if everything successful. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6293 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6294 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6295 | OMX_ERRORTYPE omx_vdec::component_deinit(OMX_IN OMX_HANDLETYPE hComp) |
| 6296 | { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6297 | |
Shalaj Jain | 286b006 | 2013-02-21 20:35:48 -0800 | [diff] [blame] | 6298 | unsigned i = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6299 | if (OMX_StateLoaded != m_state) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6300 | DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6301 | m_state); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6302 | DEBUG_PRINT_ERROR("Playback Ended - FAILED"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6303 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6304 | DEBUG_PRINT_HIGH("Playback Ended - PASSED"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6305 | } |
| 6306 | |
| 6307 | /*Check if the output buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6308 | if (m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6309 | DEBUG_PRINT_LOW("Freeing the Output Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6310 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) { |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 6311 | if (BITMASK_PRESENT(&m_out_bm_count, i)) { |
| 6312 | BITMASK_CLEAR(&m_out_bm_count, i); |
| 6313 | client_buffers.free_output_buffer (&m_out_mem_ptr[i]); |
| 6314 | } |
| 6315 | |
| 6316 | if (release_output_done()) { |
| 6317 | break; |
| 6318 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6319 | } |
| 6320 | #ifdef _ANDROID_ICS_ |
| 6321 | memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS)); |
| 6322 | #endif |
| 6323 | } |
| 6324 | |
| 6325 | /*Check if the input buffers have to be cleaned up*/ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6326 | if (m_inp_mem_ptr || m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6327 | DEBUG_PRINT_LOW("Freeing the Input Memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6328 | for (i = 0; i<drv_ctx.ip_buf.actualcount; i++ ) { |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 6329 | |
| 6330 | if (BITMASK_PRESENT(&m_inp_bm_count, i)) { |
| 6331 | BITMASK_CLEAR(&m_inp_bm_count, i); |
| 6332 | if (m_inp_mem_ptr) |
| 6333 | free_input_buffer (i,&m_inp_mem_ptr[i]); |
| 6334 | else |
| 6335 | free_input_buffer (i,NULL); |
| 6336 | } |
| 6337 | |
| 6338 | if (release_input_done()) { |
| 6339 | break; |
| 6340 | } |
| 6341 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6342 | } |
| 6343 | free_input_buffer_header(); |
| 6344 | free_output_buffer_header(); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6345 | if (h264_scratch.pBuffer) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6346 | free(h264_scratch.pBuffer); |
| 6347 | h264_scratch.pBuffer = NULL; |
| 6348 | } |
| 6349 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6350 | if (h264_parser) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6351 | delete h264_parser; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6352 | h264_parser = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6353 | } |
| 6354 | |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6355 | if (m_frame_parser.mutils) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6356 | DEBUG_PRINT_LOW("Free utils parser"); |
Leena Winterrowd | db9eaca | 2013-08-23 10:40:41 -0700 | [diff] [blame] | 6357 | delete (m_frame_parser.mutils); |
| 6358 | m_frame_parser.mutils = NULL; |
| 6359 | } |
| 6360 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6361 | if (m_platform_list) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6362 | free(m_platform_list); |
| 6363 | m_platform_list = NULL; |
| 6364 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6365 | if (m_vendor_config.pData) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6366 | free(m_vendor_config.pData); |
| 6367 | m_vendor_config.pData = NULL; |
| 6368 | } |
| 6369 | |
| 6370 | // Reset counters in mesg queues |
| 6371 | m_ftb_q.m_size=0; |
| 6372 | m_cmd_q.m_size=0; |
| 6373 | m_etb_q.m_size=0; |
| 6374 | m_ftb_q.m_read = m_ftb_q.m_write =0; |
| 6375 | m_cmd_q.m_read = m_cmd_q.m_write =0; |
| 6376 | m_etb_q.m_read = m_etb_q.m_write =0; |
| 6377 | #ifdef _ANDROID_ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6378 | if (m_debug_timestamp) { |
| 6379 | m_timestamp_list.reset_ts_list(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6380 | } |
| 6381 | #endif |
| 6382 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6383 | DEBUG_PRINT_LOW("Calling VDEC_IOCTL_STOP_NEXT_MSG"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6384 | //(void)ioctl(drv_ctx.video_driver_fd, VDEC_IOCTL_STOP_NEXT_MSG, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6385 | // NULL); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6386 | DEBUG_PRINT_HIGH("Close the driver instance"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6387 | |
Jayasena Sangaraboina | 5123064 | 2013-08-21 18:02:13 -0700 | [diff] [blame] | 6388 | if (m_debug.infile) { |
| 6389 | fclose(m_debug.infile); |
| 6390 | m_debug.infile = NULL; |
| 6391 | } |
| 6392 | if (m_debug.outfile) { |
| 6393 | fclose(m_debug.outfile); |
| 6394 | m_debug.outfile = NULL; |
| 6395 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6396 | #ifdef OUTPUT_EXTRADATA_LOG |
Shalaj Jain | af08f30 | 2013-03-18 13:15:35 -0700 | [diff] [blame] | 6397 | if (outputExtradataFile) |
| 6398 | fclose (outputExtradataFile); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6399 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6400 | DEBUG_PRINT_HIGH("omx_vdec::component_deinit() complete"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6401 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6402 | } |
| 6403 | |
| 6404 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6405 | FUNCTION |
| 6406 | omx_vdec::UseEGLImage |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6407 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6408 | DESCRIPTION |
| 6409 | OMX Use EGL Image method implementation <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6410 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6411 | PARAMETERS |
| 6412 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6413 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6414 | RETURN VALUE |
| 6415 | Not Implemented error. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6416 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6417 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6418 | OMX_ERRORTYPE omx_vdec::use_EGL_image(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6419 | OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, |
| 6420 | OMX_IN OMX_U32 port, |
| 6421 | OMX_IN OMX_PTR appData, |
| 6422 | OMX_IN void* eglImage) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6423 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6424 | OMX_QCOM_PLATFORM_PRIVATE_LIST pmem_list; |
| 6425 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY pmem_entry; |
| 6426 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6427 | |
| 6428 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6429 | PFNEGLQUERYIMAGEQUALCOMMPROC egl_queryfunc; |
| 6430 | EGLint fd = -1, offset = 0,pmemPtr = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6431 | #else |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6432 | int fd = -1, offset = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6433 | #endif |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6434 | DEBUG_PRINT_HIGH("use EGL image support for decoder"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6435 | if (!bufferHdr || !eglImage|| port != OMX_CORE_OUTPUT_PORT_INDEX) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6436 | DEBUG_PRINT_ERROR(""); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6437 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6438 | #ifdef USE_EGL_IMAGE_GPU |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6439 | if (m_display_id == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6440 | DEBUG_PRINT_ERROR("Display ID is not set by IL client"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6441 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6442 | } |
| 6443 | egl_queryfunc = (PFNEGLQUERYIMAGEQUALCOMMPROC) |
| 6444 | eglGetProcAddress("eglQueryImageKHR"); |
| 6445 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_HANDLE_QCOM,&fd); |
| 6446 | egl_queryfunc(m_display_id, eglImage, EGL_BUFFER_OFFSET_QCOM,&offset); |
| 6447 | egl_queryfunc(m_display_id, eglImage, EGL_BITMAP_POINTER_KHR,&pmemPtr); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6448 | #else //with OMX test app |
| 6449 | struct temp_egl { |
| 6450 | int pmem_fd; |
| 6451 | int offset; |
| 6452 | }; |
| 6453 | struct temp_egl *temp_egl_id = NULL; |
| 6454 | void * pmemPtr = (void *) eglImage; |
| 6455 | temp_egl_id = (struct temp_egl *)eglImage; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6456 | if (temp_egl_id != NULL) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6457 | fd = temp_egl_id->pmem_fd; |
| 6458 | offset = temp_egl_id->offset; |
| 6459 | } |
| 6460 | #endif |
| 6461 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6462 | DEBUG_PRINT_ERROR("Improper pmem fd by EGL client %d",fd); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6463 | return OMX_ErrorInsufficientResources; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6464 | } |
| 6465 | pmem_info.pmem_fd = (OMX_U32) fd; |
| 6466 | pmem_info.offset = (OMX_U32) offset; |
| 6467 | pmem_entry.entry = (void *) &pmem_info; |
| 6468 | pmem_entry.type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 6469 | pmem_list.entryList = &pmem_entry; |
| 6470 | pmem_list.nEntries = 1; |
| 6471 | ouput_egl_buffers = true; |
| 6472 | if (OMX_ErrorNone != use_buffer(hComp,bufferHdr, port, |
| 6473 | (void *)&pmem_list, drv_ctx.op_buf.buffer_size, |
| 6474 | (OMX_U8 *)pmemPtr)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6475 | DEBUG_PRINT_ERROR("use buffer call failed for egl image"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6476 | return OMX_ErrorInsufficientResources; |
| 6477 | } |
| 6478 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6482 | FUNCTION |
| 6483 | omx_vdec::ComponentRoleEnum |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6484 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6485 | DESCRIPTION |
| 6486 | OMX Component Role Enum method implementation. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6487 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6488 | PARAMETERS |
| 6489 | <TBD>. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6490 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6491 | RETURN VALUE |
| 6492 | OMX Error None if everything is successful. |
| 6493 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6494 | OMX_ERRORTYPE omx_vdec::component_role_enum(OMX_IN OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6495 | OMX_OUT OMX_U8* role, |
| 6496 | OMX_IN OMX_U32 index) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6497 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6498 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6499 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6500 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) { |
| 6501 | if ((0 == index) && role) { |
| 6502 | strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6503 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6504 | } else { |
| 6505 | eRet = OMX_ErrorNoMore; |
| 6506 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6507 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6508 | if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE)) { |
| 6509 | if ((0 == index) && role) { |
| 6510 | strlcpy((char *)role, "video_decoder.mpeg2",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6511 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6512 | } else { |
| 6513 | eRet = OMX_ErrorNoMore; |
| 6514 | } |
| 6515 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE)) { |
| 6516 | if ((0 == index) && role) { |
| 6517 | strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6518 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6519 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6520 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6521 | eRet = OMX_ErrorNoMore; |
| 6522 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6523 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6524 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6525 | else if ((!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx",OMX_MAX_STRINGNAME_SIZE)) || |
| 6526 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.divx311",OMX_MAX_STRINGNAME_SIZE)) |
| 6527 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6528 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6529 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6530 | if ((0 == index) && role) { |
| 6531 | strlcpy((char *)role, "video_decoder.divx",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6532 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6533 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6534 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6535 | eRet = OMX_ErrorNoMore; |
| 6536 | } |
| 6537 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE)) { |
| 6538 | if ((0 == index) && role) { |
| 6539 | strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6540 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6541 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6542 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6543 | eRet = OMX_ErrorNoMore; |
| 6544 | } |
| 6545 | } else if ( (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE)) || |
| 6546 | (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.wmv",OMX_MAX_STRINGNAME_SIZE)) |
| 6547 | ) { |
| 6548 | if ((0 == index) && role) { |
| 6549 | strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6550 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6551 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6552 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6553 | eRet = OMX_ErrorNoMore; |
| 6554 | } |
| 6555 | } else if (!strncmp(drv_ctx.kind, "OMX.qcom.video.decoder.vp8",OMX_MAX_STRINGNAME_SIZE)) { |
| 6556 | if ((0 == index) && role) { |
| 6557 | strlcpy((char *)role, "video_decoder.vp8",OMX_MAX_STRINGNAME_SIZE); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6558 | DEBUG_PRINT_LOW("component_role_enum: role %s",role); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6559 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6560 | DEBUG_PRINT_LOW("No more roles"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6561 | eRet = OMX_ErrorNoMore; |
| 6562 | } |
| 6563 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6564 | DEBUG_PRINT_ERROR("ERROR:Querying Role on Unknown Component"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6565 | eRet = OMX_ErrorInvalidComponentName; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6566 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6567 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | |
| 6571 | |
| 6572 | |
| 6573 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6574 | FUNCTION |
| 6575 | omx_vdec::AllocateDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6576 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6577 | DESCRIPTION |
| 6578 | Checks if entire buffer pool is allocated by IL Client or not. |
| 6579 | Need this to move to IDLE state. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6580 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6581 | PARAMETERS |
| 6582 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6583 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6584 | RETURN VALUE |
| 6585 | true/false. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6586 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6587 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6588 | bool omx_vdec::allocate_done(void) |
| 6589 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6590 | bool bRet = false; |
| 6591 | bool bRet_In = false; |
| 6592 | bool bRet_Out = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6593 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6594 | bRet_In = allocate_input_done(); |
| 6595 | bRet_Out = allocate_output_done(); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6596 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6597 | if (bRet_In && bRet_Out) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6598 | bRet = true; |
| 6599 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6600 | |
| 6601 | return bRet; |
| 6602 | } |
| 6603 | /* ====================================================================== |
| 6604 | FUNCTION |
| 6605 | omx_vdec::AllocateInputDone |
| 6606 | |
| 6607 | DESCRIPTION |
| 6608 | Checks if I/P buffer pool is allocated by IL Client or not. |
| 6609 | |
| 6610 | PARAMETERS |
| 6611 | None. |
| 6612 | |
| 6613 | RETURN VALUE |
| 6614 | true/false. |
| 6615 | |
| 6616 | ========================================================================== */ |
| 6617 | bool omx_vdec::allocate_input_done(void) |
| 6618 | { |
| 6619 | bool bRet = false; |
| 6620 | unsigned i=0; |
| 6621 | |
| 6622 | if (m_inp_mem_ptr == NULL) { |
| 6623 | return bRet; |
| 6624 | } |
| 6625 | if (m_inp_mem_ptr ) { |
| 6626 | for (; i<drv_ctx.ip_buf.actualcount; i++) { |
| 6627 | if (BITMASK_ABSENT(&m_inp_bm_count,i)) { |
| 6628 | break; |
| 6629 | } |
| 6630 | } |
| 6631 | } |
| 6632 | if (i == drv_ctx.ip_buf.actualcount) { |
| 6633 | bRet = true; |
| 6634 | DEBUG_PRINT_HIGH("Allocate done for all i/p buffers"); |
| 6635 | } |
| 6636 | if (i==drv_ctx.ip_buf.actualcount && m_inp_bEnabled) { |
| 6637 | m_inp_bPopulated = OMX_TRUE; |
| 6638 | } |
| 6639 | return bRet; |
| 6640 | } |
| 6641 | /* ====================================================================== |
| 6642 | FUNCTION |
| 6643 | omx_vdec::AllocateOutputDone |
| 6644 | |
| 6645 | DESCRIPTION |
| 6646 | Checks if entire O/P buffer pool is allocated by IL Client or not. |
| 6647 | |
| 6648 | PARAMETERS |
| 6649 | None. |
| 6650 | |
| 6651 | RETURN VALUE |
| 6652 | true/false. |
| 6653 | |
| 6654 | ========================================================================== */ |
| 6655 | bool omx_vdec::allocate_output_done(void) |
| 6656 | { |
| 6657 | bool bRet = false; |
| 6658 | unsigned j=0; |
| 6659 | |
| 6660 | if (m_out_mem_ptr == NULL) { |
| 6661 | return bRet; |
| 6662 | } |
| 6663 | |
| 6664 | if (m_out_mem_ptr) { |
| 6665 | for (; j < drv_ctx.op_buf.actualcount; j++) { |
| 6666 | if (BITMASK_ABSENT(&m_out_bm_count,j)) { |
| 6667 | break; |
| 6668 | } |
| 6669 | } |
| 6670 | } |
| 6671 | |
| 6672 | if (j == drv_ctx.op_buf.actualcount) { |
| 6673 | bRet = true; |
| 6674 | DEBUG_PRINT_HIGH("Allocate done for all o/p buffers"); |
| 6675 | if (m_out_bEnabled) |
| 6676 | m_out_bPopulated = OMX_TRUE; |
| 6677 | } |
| 6678 | |
| 6679 | return bRet; |
| 6680 | } |
| 6681 | |
| 6682 | /* ====================================================================== |
| 6683 | FUNCTION |
| 6684 | omx_vdec::ReleaseDone |
| 6685 | |
| 6686 | DESCRIPTION |
| 6687 | Checks if IL client has released all the buffers. |
| 6688 | |
| 6689 | PARAMETERS |
| 6690 | None. |
| 6691 | |
| 6692 | RETURN VALUE |
| 6693 | true/false |
| 6694 | |
| 6695 | ========================================================================== */ |
| 6696 | bool omx_vdec::release_done(void) |
| 6697 | { |
| 6698 | bool bRet = false; |
| 6699 | |
| 6700 | if (release_input_done()) { |
| 6701 | if (release_output_done()) { |
| 6702 | bRet = true; |
| 6703 | } |
| 6704 | } |
| 6705 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6706 | } |
| 6707 | |
| 6708 | |
| 6709 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6710 | FUNCTION |
| 6711 | omx_vdec::ReleaseOutputDone |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6712 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6713 | DESCRIPTION |
| 6714 | Checks if IL client has released all the buffers. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6715 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6716 | PARAMETERS |
| 6717 | None. |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6718 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6719 | RETURN VALUE |
| 6720 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6721 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6722 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6723 | bool omx_vdec::release_output_done(void) |
| 6724 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6725 | bool bRet = false; |
| 6726 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6727 | |
Praveen Chavan | 88256fe | 2016-04-11 17:32:45 -0700 | [diff] [blame] | 6728 | 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] | 6729 | if (m_out_mem_ptr) { |
| 6730 | for (; j < drv_ctx.op_buf.actualcount ; j++) { |
| 6731 | if (BITMASK_PRESENT(&m_out_bm_count,j)) { |
| 6732 | break; |
| 6733 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6734 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6735 | if (j == drv_ctx.op_buf.actualcount) { |
| 6736 | m_out_bm_count = 0; |
| 6737 | bRet = true; |
| 6738 | } |
| 6739 | } else { |
| 6740 | m_out_bm_count = 0; |
| 6741 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6742 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6743 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6744 | } |
| 6745 | /* ====================================================================== |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6746 | FUNCTION |
| 6747 | omx_vdec::ReleaseInputDone |
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 | DESCRIPTION |
| 6750 | Checks if IL client has released all the buffers. |
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 | PARAMETERS |
| 6753 | None. |
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 | RETURN VALUE |
| 6756 | true/false |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6757 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6758 | ========================================================================== */ |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6759 | bool omx_vdec::release_input_done(void) |
| 6760 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6761 | bool bRet = false; |
| 6762 | unsigned i=0,j=0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6763 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6764 | 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] | 6765 | if (m_inp_mem_ptr) { |
| 6766 | for (; j<drv_ctx.ip_buf.actualcount; j++) { |
| 6767 | if ( BITMASK_PRESENT(&m_inp_bm_count,j)) { |
| 6768 | break; |
| 6769 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6770 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6771 | if (j==drv_ctx.ip_buf.actualcount) { |
| 6772 | bRet = true; |
| 6773 | } |
| 6774 | } else { |
| 6775 | bRet = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6776 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6777 | return bRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6778 | } |
| 6779 | |
| 6780 | OMX_ERRORTYPE omx_vdec::fill_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6781 | OMX_BUFFERHEADERTYPE * buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6782 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6783 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo = NULL; |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 6784 | 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] | 6785 | DEBUG_PRINT_ERROR("[FBD] ERROR in ptr(%p)", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6786 | return OMX_ErrorBadParameter; |
| 6787 | } else if (output_flush_progress) { |
| 6788 | DEBUG_PRINT_LOW("FBD: Buffer (%p) flushed", buffer); |
| 6789 | buffer->nFilledLen = 0; |
| 6790 | buffer->nTimeStamp = 0; |
| 6791 | buffer->nFlags &= ~OMX_BUFFERFLAG_EXTRADATA; |
| 6792 | buffer->nFlags &= ~QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 6793 | buffer->nFlags &= ~OMX_BUFFERFLAG_DATACORRUPT; |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6794 | } |
| 6795 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6796 | if (m_debug_extradata) { |
| 6797 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_EOSEQ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6798 | DEBUG_PRINT_HIGH(""); |
| 6799 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6800 | DEBUG_PRINT_HIGH("FillBufferDone: End Of Sequence Received"); |
| 6801 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6802 | } |
| 6803 | |
| 6804 | if (buffer->nFlags & OMX_BUFFERFLAG_DATACORRUPT) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6805 | DEBUG_PRINT_HIGH(""); |
| 6806 | DEBUG_PRINT_HIGH("***************************************************"); |
| 6807 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 6808 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6809 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6810 | } |
Praneeth Paladugu | 594e682 | 2013-04-19 10:47:28 -0700 | [diff] [blame] | 6811 | |
| 6812 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6813 | DEBUG_PRINT_LOW("fill_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6814 | buffer, buffer->pBuffer); |
| 6815 | pending_output_buffers --; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6816 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6817 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6818 | DEBUG_PRINT_HIGH("Output EOS has been reached"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6819 | if (!output_flush_progress) |
| 6820 | post_event((unsigned)NULL, (unsigned)NULL, |
| 6821 | OMX_COMPONENT_GENERATE_EOS_DONE); |
| 6822 | |
| 6823 | if (psource_frame) { |
| 6824 | m_cb.EmptyBufferDone(&m_cmp, m_app_data, psource_frame); |
| 6825 | psource_frame = NULL; |
| 6826 | } |
| 6827 | if (pdest_frame) { |
| 6828 | pdest_frame->nFilledLen = 0; |
| 6829 | m_input_free_q.insert_entry((unsigned) pdest_frame,(unsigned)NULL, |
| 6830 | (unsigned)NULL); |
| 6831 | pdest_frame = NULL; |
| 6832 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6833 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6834 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6835 | |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 6836 | if (!output_flush_progress && (buffer->nFilledLen > 0)) { |
| 6837 | DEBUG_PRINT_LOW("Processing extradata"); |
| 6838 | handle_extradata(buffer); |
| 6839 | } |
| 6840 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6841 | /* For use buffer we need to copy the data */ |
| 6842 | if (!output_flush_progress) { |
| 6843 | /* This is the error check for non-recoverable errros */ |
| 6844 | bool is_duplicate_ts_valid = true; |
| 6845 | bool is_interlaced = (drv_ctx.interlace != VDEC_InterlaceFrameProgressive); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6846 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6847 | if (output_capability == V4L2_PIX_FMT_MPEG4 || |
| 6848 | output_capability == V4L2_PIX_FMT_MPEG2 || |
| 6849 | output_capability == V4L2_PIX_FMT_DIVX || |
| 6850 | output_capability == V4L2_PIX_FMT_DIVX_311) |
| 6851 | is_duplicate_ts_valid = false; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 6852 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6853 | if (output_capability == V4L2_PIX_FMT_H264 && is_interlaced) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 6854 | if (buffer->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6855 | is_interlaced = false; |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6856 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6857 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6858 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6859 | if (buffer->nFilledLen > 0) { |
| 6860 | time_stamp_dts.get_next_timestamp(buffer, |
| 6861 | is_interlaced && is_duplicate_ts_valid); |
| 6862 | if (m_debug_timestamp) { |
| 6863 | { |
| 6864 | OMX_TICKS expected_ts = 0; |
| 6865 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6866 | if (is_interlaced && is_duplicate_ts_valid) { |
| 6867 | m_timestamp_list.pop_min_ts(expected_ts); |
| 6868 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6869 | DEBUG_PRINT_LOW("Current timestamp (%lld),Popped TIMESTAMP (%lld) from list", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6870 | buffer->nTimeStamp, expected_ts); |
| 6871 | |
| 6872 | if (buffer->nTimeStamp != expected_ts) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6873 | DEBUG_PRINT_ERROR("ERROR in omx_vdec::async_message_process timestamp Check"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6874 | } |
| 6875 | } |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6876 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6877 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6878 | time_stamp_dts.remove_time_stamp( |
| 6879 | buffer->nTimeStamp, |
| 6880 | is_interlaced && is_duplicate_ts_valid); |
Rajeshwar Kurapaty | 46a24f0 | 2013-07-09 15:13:41 +0530 | [diff] [blame] | 6881 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6882 | |
| 6883 | |
Praneeth Paladugu | 8f12e82 | 2013-03-11 18:47:58 -0700 | [diff] [blame] | 6884 | } |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6885 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 6886 | /* Since we're passing around handles, adjust nFilledLen and nAllocLen |
| 6887 | * to size of the handle. Do it _after_ handle_extradata() which |
| 6888 | * requires the respective sizes to be accurate. */ |
| 6889 | if (dynamic_buf_mode) { |
| 6890 | buffer->nAllocLen = sizeof(struct VideoDecoderOutputMetaData); |
| 6891 | buffer->nFilledLen = buffer->nFilledLen ? |
| 6892 | sizeof(struct VideoDecoderOutputMetaData) : 0; |
| 6893 | } |
| 6894 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6895 | if (m_cb.FillBufferDone) { |
| 6896 | if (buffer->nFilledLen > 0) { |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6897 | if (arbitrary_bytes) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6898 | adjust_timestamp(buffer->nTimeStamp); |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 6899 | else |
| 6900 | set_frame_rate(buffer->nTimeStamp); |
| 6901 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6902 | if (perf_flag) { |
| 6903 | if (!proc_frms) { |
| 6904 | dec_time.stop(); |
| 6905 | latency = dec_time.processing_time_us() - latency; |
| 6906 | DEBUG_PRINT_HIGH(">>> FBD Metrics: Latency(%.2f)mS", latency / 1e3); |
| 6907 | dec_time.start(); |
| 6908 | fps_metrics.start(); |
| 6909 | } |
| 6910 | proc_frms++; |
| 6911 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6912 | OMX_U64 proc_time = 0; |
| 6913 | fps_metrics.stop(); |
| 6914 | proc_time = fps_metrics.processing_time_us(); |
| 6915 | DEBUG_PRINT_HIGH(">>> FBD Metrics: proc_frms(%lu) proc_time(%.2f)S fps(%.2f)", |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6916 | proc_frms, (float)proc_time / 1e6, |
| 6917 | (float)(1e6 * proc_frms) / proc_time); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6918 | proc_frms = 0; |
| 6919 | } |
| 6920 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6921 | |
| 6922 | #ifdef OUTPUT_EXTRADATA_LOG |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6923 | if (outputExtradataFile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6924 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6925 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL; |
| 6926 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
| 6927 | ((unsigned)(buffer->pBuffer + buffer->nOffset + |
| 6928 | buffer->nFilledLen + 3)&(~3)); |
| 6929 | while (p_extra && |
| 6930 | (OMX_U8*)p_extra < (buffer->pBuffer + buffer->nAllocLen) ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6931 | 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] | 6932 | fwrite (p_extra,1,p_extra->nSize,outputExtradataFile); |
| 6933 | if (p_extra->eType == OMX_ExtraDataNone) { |
| 6934 | break; |
| 6935 | } |
| 6936 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 6937 | } |
| 6938 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6939 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6940 | } |
| 6941 | if (buffer->nFlags & OMX_BUFFERFLAG_EOS) { |
| 6942 | prev_ts = LLONG_MAX; |
| 6943 | rst_prev_ts = true; |
| 6944 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 6945 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6946 | pPMEMInfo = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 6947 | ((OMX_QCOM_PLATFORM_PRIVATE_LIST *) |
| 6948 | buffer->pPlatformPrivate)->entryList->entry; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6949 | DEBUG_PRINT_LOW("Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6950 | OMX_BUFFERHEADERTYPE *il_buffer; |
| 6951 | il_buffer = client_buffers.get_il_buf_hdr(buffer); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6952 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6953 | if (il_buffer && m_last_rendered_TS >= 0) { |
| 6954 | int current_framerate = (int)(drv_ctx.frame_rate.fps_numerator /drv_ctx.frame_rate.fps_denominator); |
Manikanta Kanamarlapudi | fb53b26 | 2014-01-20 16:12:47 +0530 | [diff] [blame] | 6955 | 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] | 6956 | |
| 6957 | // Current frame can be send for rendering if |
| 6958 | // (a) current FPS is <= 60 |
| 6959 | // (b) is the next frame after the frame with TS 0 |
| 6960 | // (c) is the first frame after seek |
| 6961 | // (d) the delta TS b\w two consecutive frames is > 16 ms |
| 6962 | // (e) its TS is equal to previous frame TS |
| 6963 | // (f) if marked EOS |
| 6964 | |
| 6965 | if(current_framerate <= 60 || m_last_rendered_TS == 0 || |
| 6966 | il_buffer->nTimeStamp == 0 || ts_delta >= 16000 || |
| 6967 | ts_delta == 0 || (il_buffer->nFlags & OMX_BUFFERFLAG_EOS)) { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6968 | m_last_rendered_TS = il_buffer->nTimeStamp; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6969 | } else { |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6970 | //mark for droping |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6971 | buffer->nFilledLen = 0; |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | DEBUG_PRINT_LOW(" -- %s Frame -- info:: fps(%d) lastRenderTime(%lld) bufferTs(%lld) ts_delta(%d)", |
| 6975 | buffer->nFilledLen? "Rendering":"Dropping",current_framerate,m_last_rendered_TS, |
| 6976 | il_buffer->nTimeStamp,ts_delta); |
vivek mehta | a75c69f | 2014-01-10 21:50:37 -0800 | [diff] [blame] | 6977 | } |
| 6978 | |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6979 | if (il_buffer) { |
Arun Menon | 9230eb8 | 2014-02-11 19:19:02 -0800 | [diff] [blame] | 6980 | log_output_buffers(il_buffer); |
| 6981 | if (dynamic_buf_mode) { |
| 6982 | unsigned int nPortIndex = 0; |
| 6983 | nPortIndex = buffer-((OMX_BUFFERHEADERTYPE *)client_buffers.get_il_buf_hdr()); |
| 6984 | |
| 6985 | if (!secure_mode) { |
| 6986 | munmap(drv_ctx.ptr_outputbuffer[nPortIndex].bufferaddr, |
| 6987 | drv_ctx.ptr_outputbuffer[nPortIndex].mmaped_size); |
| 6988 | } |
| 6989 | |
| 6990 | //Clear graphic buffer handles in dynamic mode |
| 6991 | native_buffer[nPortIndex].privatehandle = NULL; |
| 6992 | native_buffer[nPortIndex].nativehandle = NULL; |
| 6993 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6994 | m_cb.FillBufferDone (hComp,m_app_data,il_buffer); |
vivek mehta | 79cff22 | 2014-01-22 12:17:07 -0800 | [diff] [blame] | 6995 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 6996 | DEBUG_PRINT_ERROR("Invalid buffer address from get_il_buf_hdr"); |
| 6997 | return OMX_ErrorBadParameter; |
| 6998 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 6999 | DEBUG_PRINT_LOW("After Fill Buffer Done callback %lu",pPMEMInfo->pmem_fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7000 | } else { |
| 7001 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 7002 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7003 | |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 7004 | #ifdef ADAPTIVE_PLAYBACK_SUPPORTED |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 7005 | if (m_smoothstreaming_mode && m_out_mem_ptr) { |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 7006 | OMX_U32 buf_index = buffer - m_out_mem_ptr; |
| 7007 | BufferDim_t dim; |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 7008 | private_handle_t *private_handle = NULL; |
Pushkaraj Patil | 065b573 | 2014-11-26 11:08:02 +0530 | [diff] [blame] | 7009 | dim.sliceWidth = framesize.nWidth; |
| 7010 | dim.sliceHeight = framesize.nHeight; |
Pushkaraj Patil | 8f98adf | 2014-02-12 13:32:00 +0530 | [diff] [blame] | 7011 | if (native_buffer[buf_index].privatehandle) |
| 7012 | private_handle = native_buffer[buf_index].privatehandle; |
Praveen Chavan | cf92418 | 2013-12-06 23:16:23 -0800 | [diff] [blame] | 7013 | if (private_handle) { |
| 7014 | DEBUG_PRINT_LOW("set metadata: update buf-geometry with stride %d slice %d", |
| 7015 | dim.sliceWidth, dim.sliceHeight); |
| 7016 | setMetaData(private_handle, UPDATE_BUFFER_GEOMETRY, (void*)&dim); |
| 7017 | } |
| 7018 | } |
| 7019 | #endif |
| 7020 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7021 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7022 | } |
| 7023 | |
| 7024 | OMX_ERRORTYPE omx_vdec::empty_buffer_done(OMX_HANDLETYPE hComp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7025 | OMX_BUFFERHEADERTYPE* buffer) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7026 | { |
| 7027 | |
Praveen Chavan | 58207a2 | 2016-08-17 12:19:29 -0700 | [diff] [blame] | 7028 | int nBufferIndex = buffer - m_inp_mem_ptr; |
| 7029 | |
| 7030 | if (buffer == NULL || (nBufferIndex >= (int)drv_ctx.ip_buf.actualcount)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7031 | DEBUG_PRINT_ERROR("empty_buffer_done: ERROR bufhdr = %p", buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7032 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7033 | } |
| 7034 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7035 | DEBUG_PRINT_LOW("empty_buffer_done: bufhdr = %p, bufhdr->pBuffer = %p", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7036 | buffer, buffer->pBuffer); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7037 | pending_input_buffers--; |
| 7038 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7039 | if (arbitrary_bytes) { |
| 7040 | if (pdest_frame == NULL && input_flush_progress == false) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7041 | 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] | 7042 | pdest_frame = buffer; |
| 7043 | buffer->nFilledLen = 0; |
| 7044 | buffer->nTimeStamp = LLONG_MAX; |
| 7045 | push_input_buffer (hComp); |
| 7046 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7047 | DEBUG_PRINT_LOW("Push buffer into freeq address of Buffer %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7048 | buffer->nFilledLen = 0; |
| 7049 | if (!m_input_free_q.insert_entry((unsigned)buffer, |
| 7050 | (unsigned)NULL, (unsigned)NULL)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7051 | DEBUG_PRINT_ERROR("ERROR:i/p free Queue is FULL Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7052 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7053 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7054 | } else if (m_cb.EmptyBufferDone) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7055 | buffer->nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7056 | if (input_use_buffer == true) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7057 | buffer = &m_inp_heap_ptr[buffer-m_inp_mem_ptr]; |
| 7058 | } |
| 7059 | m_cb.EmptyBufferDone(hComp ,m_app_data, buffer); |
| 7060 | } |
| 7061 | return OMX_ErrorNone; |
| 7062 | } |
| 7063 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7064 | int omx_vdec::async_message_process (void *context, void* message) |
| 7065 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7066 | omx_vdec* omx = NULL; |
| 7067 | struct vdec_msginfo *vdec_msg = NULL; |
| 7068 | OMX_BUFFERHEADERTYPE* omxhdr = NULL; |
| 7069 | struct v4l2_buffer *v4l2_buf_ptr = NULL; |
| 7070 | struct vdec_output_frameinfo *output_respbuf = NULL; |
| 7071 | int rc=1; |
| 7072 | if (context == NULL || message == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7073 | 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] | 7074 | return -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7075 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7076 | vdec_msg = (struct vdec_msginfo *)message; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7077 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7078 | omx = reinterpret_cast<omx_vdec*>(context); |
Vinay Kalia | b9e9810 | 2013-04-02 19:31:43 -0700 | [diff] [blame] | 7079 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7080 | switch (vdec_msg->msgcode) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7081 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7082 | case VDEC_MSG_EVT_HW_ERROR: |
| 7083 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7084 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
| 7085 | break; |
| 7086 | |
Deepak Verma | 24720fb | 2014-01-29 16:57:40 +0530 | [diff] [blame] | 7087 | case VDEC_MSG_EVT_HW_OVERLOAD: |
| 7088 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7089 | OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD); |
| 7090 | break; |
| 7091 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7092 | case VDEC_MSG_RESP_START_DONE: |
| 7093 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7094 | OMX_COMPONENT_GENERATE_START_DONE); |
| 7095 | break; |
| 7096 | |
| 7097 | case VDEC_MSG_RESP_STOP_DONE: |
| 7098 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7099 | OMX_COMPONENT_GENERATE_STOP_DONE); |
| 7100 | break; |
| 7101 | |
| 7102 | case VDEC_MSG_RESP_RESUME_DONE: |
| 7103 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7104 | OMX_COMPONENT_GENERATE_RESUME_DONE); |
| 7105 | break; |
| 7106 | |
| 7107 | case VDEC_MSG_RESP_PAUSE_DONE: |
| 7108 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7109 | OMX_COMPONENT_GENERATE_PAUSE_DONE); |
| 7110 | break; |
| 7111 | |
| 7112 | case VDEC_MSG_RESP_FLUSH_INPUT_DONE: |
| 7113 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7114 | OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH); |
| 7115 | break; |
| 7116 | case VDEC_MSG_RESP_FLUSH_OUTPUT_DONE: |
| 7117 | omx->post_event ((unsigned)NULL, vdec_msg->status_code,\ |
| 7118 | OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH); |
| 7119 | break; |
| 7120 | case VDEC_MSG_RESP_INPUT_FLUSHED: |
| 7121 | case VDEC_MSG_RESP_INPUT_BUFFER_DONE: |
| 7122 | |
| 7123 | /* omxhdr = (OMX_BUFFERHEADERTYPE* ) |
| 7124 | vdec_msg->msgdata.input_frame_clientdata; */ |
| 7125 | |
| 7126 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.input_frame_clientdata; |
| 7127 | omxhdr=omx->m_inp_mem_ptr+v4l2_buf_ptr->index; |
| 7128 | if (omxhdr == NULL || |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7129 | ((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] | 7130 | omxhdr = NULL; |
| 7131 | vdec_msg->status_code = VDEC_S_EFATAL; |
| 7132 | } |
| 7133 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_INPUT_UNSUPPORTED) { |
| 7134 | DEBUG_PRINT_HIGH("Unsupported input"); |
| 7135 | omx->omx_report_error (); |
| 7136 | } |
| 7137 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7138 | vdec_msg->status_code = VDEC_S_INPUT_BITSTREAM_ERR; |
| 7139 | } |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7140 | if (omxhdr->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7141 | |
Pushkaraj Patil | c7e0b9a | 2015-01-22 18:31:13 +0530 | [diff] [blame] | 7142 | DEBUG_PRINT_LOW("Decrement codec_config buffer counter"); |
| 7143 | android_atomic_dec(&omx->m_queued_codec_config_count); |
| 7144 | if ((android_atomic_add(0, &omx->m_queued_codec_config_count) == 0) && |
| 7145 | BITMASK_PRESENT(&omx->m_flags, OMX_COMPONENT_FLUSH_DEFERRED)) { |
| 7146 | DEBUG_PRINT_LOW("sem post for CODEC CONFIG buffer"); |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7147 | sem_post(&omx->m_safe_flush); |
| 7148 | } |
Pushkaraj Patil | 673f14a | 2014-12-03 14:55:19 +0530 | [diff] [blame] | 7149 | } |
| 7150 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7151 | omx->post_event ((unsigned int)omxhdr,vdec_msg->status_code, |
| 7152 | OMX_COMPONENT_GENERATE_EBD); |
| 7153 | break; |
| 7154 | case VDEC_MSG_EVT_INFO_FIELD_DROPPED: |
| 7155 | int64_t *timestamp; |
| 7156 | timestamp = (int64_t *) malloc(sizeof(int64_t)); |
| 7157 | if (timestamp) { |
| 7158 | *timestamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7159 | omx->post_event ((unsigned int)timestamp, vdec_msg->status_code, |
| 7160 | OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7161 | DEBUG_PRINT_HIGH("Field dropped time stamp is %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7162 | vdec_msg->msgdata.output_frame.time_stamp); |
| 7163 | } |
| 7164 | break; |
| 7165 | case VDEC_MSG_RESP_OUTPUT_FLUSHED: |
| 7166 | case VDEC_MSG_RESP_OUTPUT_BUFFER_DONE: |
| 7167 | |
| 7168 | v4l2_buf_ptr = (v4l2_buffer*)vdec_msg->msgdata.output_frame.client_data; |
| 7169 | omxhdr=omx->m_out_mem_ptr+v4l2_buf_ptr->index; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7170 | |
| 7171 | DEBUG_PRINT_LOW("[RespBufDone] Buf(%p) Ts(%lld) PicType(%u) Flags (0x%x) FillLen(%u) Crop: L(%u) T(%u) R(%u) B(%u)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7172 | omxhdr, vdec_msg->msgdata.output_frame.time_stamp, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7173 | vdec_msg->msgdata.output_frame.pic_type, v4l2_buf_ptr->flags, |
| 7174 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7175 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7176 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7177 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7178 | vdec_msg->msgdata.output_frame.framesize.bottom); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7179 | |
| 7180 | if (omxhdr && omxhdr->pOutputPortPrivate && |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7181 | ((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] | 7182 | (((struct vdec_output_frameinfo *)omxhdr->pOutputPortPrivate |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 7183 | - omx->drv_ctx.ptr_respbuffer) < (int)omx->drv_ctx.op_buf.actualcount)) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7184 | |
Deva Ramasubramanian | cdbd31b | 2014-04-14 20:14:28 -0700 | [diff] [blame] | 7185 | if (vdec_msg->msgdata.output_frame.len <= omxhdr->nAllocLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7186 | omxhdr->nFilledLen = vdec_msg->msgdata.output_frame.len; |
| 7187 | omxhdr->nOffset = vdec_msg->msgdata.output_frame.offset; |
| 7188 | omxhdr->nTimeStamp = vdec_msg->msgdata.output_frame.time_stamp; |
| 7189 | omxhdr->nFlags = 0; |
| 7190 | |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7191 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7192 | omxhdr->nFlags |= OMX_BUFFERFLAG_EOS; |
| 7193 | //rc = -1; |
| 7194 | } |
| 7195 | if (omxhdr->nFilledLen) { |
| 7196 | omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; |
| 7197 | } |
| 7198 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME || v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_IDRFRAME) { |
| 7199 | omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; |
| 7200 | } else { |
| 7201 | omxhdr->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME; |
| 7202 | } |
| 7203 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOSEQ) { |
| 7204 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7205 | } |
| 7206 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) { |
| 7207 | omxhdr->nFlags |= OMX_BUFFERFLAG_DECODEONLY; |
| 7208 | } |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 7209 | |
| 7210 | if (v4l2_buf_ptr->flags & V4L2_MSM_BUF_FLAG_MBAFF) { |
| 7211 | omxhdr->nFlags |= QOMX_VIDEO_BUFFERFLAG_MBAFF; |
| 7212 | } |
| 7213 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7214 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY) { |
Arun Menon | e50f6ef | 2013-09-30 15:08:27 -0700 | [diff] [blame] | 7215 | omxhdr->nFlags |= OMX_BUFFERFLAG_READONLY; |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7216 | DEBUG_PRINT_LOW("F_B_D: READONLY BUFFER - REFERENCE WITH F/W fd = %d", |
| 7217 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd); |
| 7218 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7219 | if (omx->dynamic_buf_mode && !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_READONLY)) { |
| 7220 | omx->buf_ref_remove(omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].pmem_fd, |
| 7221 | omxhdr->nOffset); |
| 7222 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7223 | if (omxhdr && (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DROP_FRAME) && |
| 7224 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_DECODEONLY) && |
Deva Ramasubramanian | c1c7c12 | 2013-09-10 21:50:43 -0700 | [diff] [blame] | 7225 | !(v4l2_buf_ptr->flags & V4L2_QCOM_BUF_FLAG_EOS)) { |
Praneeth Paladugu | 17364df | 2013-07-30 11:34:16 -0700 | [diff] [blame] | 7226 | omx->time_stamp_dts.remove_time_stamp( |
| 7227 | omxhdr->nTimeStamp, |
| 7228 | (omx->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) |
| 7229 | ?true:false); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7230 | omx->post_event ((unsigned)NULL,(unsigned int)omxhdr, |
| 7231 | OMX_COMPONENT_GENERATE_FTB); |
| 7232 | break; |
| 7233 | } |
| 7234 | if (v4l2_buf_ptr->flags & V4L2_QCOM_BUF_DATA_CORRUPT) { |
| 7235 | omxhdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
| 7236 | } |
| 7237 | vdec_msg->msgdata.output_frame.bufferaddr = |
| 7238 | omx->drv_ctx.ptr_outputbuffer[v4l2_buf_ptr->index].bufferaddr; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7239 | |
| 7240 | /* Post event if resolution OR crop changed */ |
| 7241 | /* filled length will be changed if resolution changed */ |
| 7242 | /* Crop parameters can be changed even without resolution change */ |
| 7243 | if (omxhdr->nFilledLen |
| 7244 | && ((omx->prev_n_filled_len != omxhdr->nFilledLen) |
| 7245 | || (omx->drv_ctx.frame_size.left != vdec_msg->msgdata.output_frame.framesize.left) |
| 7246 | || (omx->drv_ctx.frame_size.top != vdec_msg->msgdata.output_frame.framesize.top) |
| 7247 | || (omx->drv_ctx.frame_size.right != vdec_msg->msgdata.output_frame.framesize.right) |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 7248 | || (omx->drv_ctx.frame_size.bottom != vdec_msg->msgdata.output_frame.framesize.bottom) |
| 7249 | || (omx->drv_ctx.video_resolution.frame_width != vdec_msg->msgdata.output_frame.picsize.frame_width) |
| 7250 | || (omx->drv_ctx.video_resolution.frame_height != vdec_msg->msgdata.output_frame.picsize.frame_height) )) { |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7251 | |
Maheshwar Ajja | 3cdbad4 | 2014-08-12 17:00:59 +0530 | [diff] [blame] | 7252 | DEBUG_PRINT_HIGH("Paramters Changed From: Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u --> Len: %u, WxH: %dx%d, L: %u, T: %u, R: %u, B: %u", |
| 7253 | omx->prev_n_filled_len, |
| 7254 | omx->drv_ctx.video_resolution.frame_width, |
| 7255 | omx->drv_ctx.video_resolution.frame_height, |
| 7256 | omx->drv_ctx.frame_size.left, omx->drv_ctx.frame_size.top, |
| 7257 | omx->drv_ctx.frame_size.right, omx->drv_ctx.frame_size.bottom, |
| 7258 | omxhdr->nFilledLen, vdec_msg->msgdata.output_frame.picsize.frame_width, |
| 7259 | vdec_msg->msgdata.output_frame.picsize.frame_height, |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7260 | vdec_msg->msgdata.output_frame.framesize.left, |
| 7261 | vdec_msg->msgdata.output_frame.framesize.top, |
| 7262 | vdec_msg->msgdata.output_frame.framesize.right, |
| 7263 | vdec_msg->msgdata.output_frame.framesize.bottom); |
| 7264 | |
Maheshwar Ajja | 0f840ce | 2014-09-29 16:53:42 +0530 | [diff] [blame] | 7265 | omx->drv_ctx.video_resolution.frame_width = |
| 7266 | vdec_msg->msgdata.output_frame.picsize.frame_width; |
| 7267 | omx->drv_ctx.video_resolution.frame_height = |
| 7268 | vdec_msg->msgdata.output_frame.picsize.frame_height; |
Praneeth Paladugu | ca80be7 | 2014-10-22 23:48:54 -0700 | [diff] [blame] | 7269 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) { |
| 7270 | omx->drv_ctx.video_resolution.stride = |
| 7271 | VENUS_Y_STRIDE(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_width); |
| 7272 | omx->drv_ctx.video_resolution.scan_lines = |
| 7273 | VENUS_Y_SCANLINES(COLOR_FMT_NV12, omx->drv_ctx.video_resolution.frame_height); |
| 7274 | } |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7275 | memcpy(&omx->drv_ctx.frame_size, |
| 7276 | &vdec_msg->msgdata.output_frame.framesize, |
| 7277 | sizeof(struct vdec_framesize)); |
| 7278 | |
| 7279 | omx->post_event(OMX_CORE_OUTPUT_PORT_INDEX, |
| 7280 | OMX_IndexConfigCommonOutputCrop, |
| 7281 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7282 | } |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7283 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7284 | if (omxhdr->nFilledLen) |
| 7285 | omx->prev_n_filled_len = omxhdr->nFilledLen; |
| 7286 | |
| 7287 | output_respbuf = (struct vdec_output_frameinfo *)\ |
| 7288 | omxhdr->pOutputPortPrivate; |
| 7289 | output_respbuf->len = vdec_msg->msgdata.output_frame.len; |
| 7290 | output_respbuf->offset = vdec_msg->msgdata.output_frame.offset; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7291 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7292 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_KEYFRAME) { |
| 7293 | output_respbuf->pic_type = PICTURE_TYPE_I; |
| 7294 | } |
| 7295 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_PFRAME) { |
| 7296 | output_respbuf->pic_type = PICTURE_TYPE_P; |
| 7297 | } |
| 7298 | if (v4l2_buf_ptr->flags & V4L2_BUF_FLAG_BFRAME) { |
| 7299 | output_respbuf->pic_type = PICTURE_TYPE_B; |
| 7300 | } |
| 7301 | |
Sri Karri | 3856945 | 2018-03-16 12:46:14 +0530 | [diff] [blame] | 7302 | if (!omx->m_enable_android_native_buffers && |
| 7303 | omx->output_use_buffer) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7304 | memcpy ( omxhdr->pBuffer, (void *) |
| 7305 | ((unsigned long)vdec_msg->msgdata.output_frame.bufferaddr + |
| 7306 | (unsigned long)vdec_msg->msgdata.output_frame.offset), |
| 7307 | vdec_msg->msgdata.output_frame.len); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7308 | } else { |
| 7309 | DEBUG_PRINT_ERROR("Invalid filled length = %u, buffer size = %u, prev_length = %u", |
| 7310 | (unsigned int)vdec_msg->msgdata.output_frame.len, |
| 7311 | omxhdr->nAllocLen, omx->prev_n_filled_len); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7312 | omxhdr->nFilledLen = 0; |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7313 | } |
| 7314 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7315 | omx->post_event ((unsigned int)omxhdr, vdec_msg->status_code, |
| 7316 | OMX_COMPONENT_GENERATE_FBD); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7317 | |
| 7318 | } else if (vdec_msg->msgdata.output_frame.flags & OMX_BUFFERFLAG_EOS) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7319 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7320 | OMX_COMPONENT_GENERATE_EOS_DONE); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7321 | } else { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7322 | omx->post_event ((unsigned int)NULL, vdec_msg->status_code, |
| 7323 | OMX_COMPONENT_GENERATE_HARDWARE_ERROR); |
Maheshwar Ajja | c366ad2 | 2014-07-09 17:31:13 +0530 | [diff] [blame] | 7324 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7325 | break; |
| 7326 | case VDEC_MSG_EVT_CONFIG_CHANGED: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7327 | DEBUG_PRINT_HIGH("Port settings changed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7328 | omx->post_event (OMX_CORE_OUTPUT_PORT_INDEX, OMX_IndexParamPortDefinition, |
| 7329 | OMX_COMPONENT_GENERATE_PORT_RECONFIG); |
| 7330 | break; |
| 7331 | default: |
| 7332 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7333 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7334 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7335 | } |
| 7336 | |
| 7337 | OMX_ERRORTYPE omx_vdec::empty_this_buffer_proxy_arbitrary ( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7338 | OMX_HANDLETYPE hComp, |
| 7339 | OMX_BUFFERHEADERTYPE *buffer |
| 7340 | ) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7341 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7342 | unsigned address,p2,id; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7343 | DEBUG_PRINT_LOW("Empty this arbitrary"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7344 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7345 | if (buffer == NULL) { |
| 7346 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7347 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7348 | DEBUG_PRINT_LOW("ETBProxyArb: bufhdr = %p, bufhdr->pBuffer = %p", buffer, buffer->pBuffer); |
| 7349 | DEBUG_PRINT_LOW("ETBProxyArb: nFilledLen %lu, flags %lu, timestamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7350 | buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp); |
| 7351 | |
| 7352 | /* return zero length and not an EOS buffer */ |
| 7353 | /* return buffer if input flush in progress */ |
| 7354 | if ((input_flush_progress == true) || ((buffer->nFilledLen == 0) && |
| 7355 | ((buffer->nFlags & OMX_BUFFERFLAG_EOS) == 0))) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7356 | DEBUG_PRINT_HIGH("return zero legth buffer or flush in progress"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7357 | m_cb.EmptyBufferDone (hComp,m_app_data,buffer); |
| 7358 | return OMX_ErrorNone; |
| 7359 | } |
| 7360 | |
| 7361 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7362 | 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] | 7363 | psource_frame = buffer; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7364 | DEBUG_PRINT_LOW("Try to Push One Input Buffer "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7365 | push_input_buffer (hComp); |
| 7366 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7367 | DEBUG_PRINT_LOW("Push the source buffer into pendingq %p",buffer); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7368 | if (!m_input_pending_q.insert_entry((unsigned)buffer, (unsigned)NULL, |
| 7369 | (unsigned)NULL)) { |
| 7370 | return OMX_ErrorBadParameter; |
| 7371 | } |
| 7372 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7373 | |
Sowmya Pandiri | 302f5ab | 2014-04-03 13:41:03 -0700 | [diff] [blame] | 7374 | if (codec_config_flag && !(buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { |
| 7375 | codec_config_flag = false; |
| 7376 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7377 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7378 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | OMX_ERRORTYPE omx_vdec::push_input_buffer (OMX_HANDLETYPE hComp) |
| 7382 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7383 | unsigned address,p2,id; |
| 7384 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7385 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7386 | if (pdest_frame == NULL || psource_frame == NULL) { |
| 7387 | /*Check if we have a destination buffer*/ |
| 7388 | if (pdest_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7389 | DEBUG_PRINT_LOW("Get a Destination buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7390 | if (m_input_free_q.m_size) { |
| 7391 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7392 | pdest_frame = (OMX_BUFFERHEADERTYPE *)address; |
| 7393 | pdest_frame->nFilledLen = 0; |
| 7394 | pdest_frame->nTimeStamp = LLONG_MAX; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7395 | DEBUG_PRINT_LOW("Address of Pmem Buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | /*Check if we have a destination buffer*/ |
| 7400 | if (psource_frame == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7401 | DEBUG_PRINT_LOW("Get a source buffer from the queue"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7402 | if (m_input_pending_q.m_size) { |
| 7403 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7404 | psource_frame = (OMX_BUFFERHEADERTYPE *)address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7405 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7406 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7407 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7408 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7409 | |
| 7410 | } |
| 7411 | } |
| 7412 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7413 | } |
| 7414 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7415 | while ((pdest_frame != NULL) && (psource_frame != NULL)) { |
| 7416 | switch (codec_type_parse) { |
| 7417 | case CODEC_TYPE_MPEG4: |
| 7418 | case CODEC_TYPE_H263: |
| 7419 | case CODEC_TYPE_MPEG2: |
| 7420 | ret = push_input_sc_codec(hComp); |
| 7421 | break; |
| 7422 | case CODEC_TYPE_H264: |
| 7423 | ret = push_input_h264(hComp); |
| 7424 | break; |
| 7425 | case CODEC_TYPE_VC1: |
| 7426 | ret = push_input_vc1(hComp); |
| 7427 | break; |
| 7428 | default: |
| 7429 | break; |
| 7430 | } |
| 7431 | if (ret != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7432 | DEBUG_PRINT_ERROR("Pushing input Buffer Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7433 | omx_report_error (); |
| 7434 | break; |
| 7435 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7436 | } |
| 7437 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7438 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7439 | } |
| 7440 | |
| 7441 | OMX_ERRORTYPE omx_vdec::push_input_sc_codec(OMX_HANDLETYPE hComp) |
| 7442 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7443 | OMX_U32 partial_frame = 1; |
| 7444 | OMX_BOOL generate_ebd = OMX_TRUE; |
| 7445 | unsigned address = 0, p2 = 0, id = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7446 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7447 | DEBUG_PRINT_LOW("Start Parsing the bit stream address %p TimeStamp %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7448 | psource_frame,psource_frame->nTimeStamp); |
| 7449 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7450 | pdest_frame,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7451 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7452 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7453 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7454 | |
| 7455 | if (partial_frame == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7456 | DEBUG_PRINT_LOW("Frame size %lu source %p frame count %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7457 | pdest_frame->nFilledLen,psource_frame,frame_count); |
| 7458 | |
| 7459 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7460 | DEBUG_PRINT_LOW("TimeStamp updated %lld", pdest_frame->nTimeStamp); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7461 | /*First Parsed buffer will have only header Hence skip*/ |
| 7462 | if (frame_count == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7463 | DEBUG_PRINT_LOW("H263/MPEG4 Codec First Frame "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7464 | |
| 7465 | if (codec_type_parse == CODEC_TYPE_MPEG4 || |
| 7466 | codec_type_parse == CODEC_TYPE_DIVX) { |
| 7467 | mp4StreamType psBits; |
| 7468 | psBits.data = pdest_frame->pBuffer + pdest_frame->nOffset; |
| 7469 | psBits.numBytes = pdest_frame->nFilledLen; |
| 7470 | mp4_headerparser.parseHeader(&psBits); |
| 7471 | } |
| 7472 | |
| 7473 | frame_count++; |
| 7474 | } else { |
| 7475 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7476 | if (pdest_frame->nFilledLen) { |
| 7477 | /*Push the frame to the Decoder*/ |
| 7478 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7479 | return OMX_ErrorBadParameter; |
| 7480 | } |
| 7481 | frame_count++; |
| 7482 | pdest_frame = NULL; |
| 7483 | |
| 7484 | if (m_input_free_q.m_size) { |
| 7485 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7486 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
| 7487 | pdest_frame->nFilledLen = 0; |
| 7488 | } |
| 7489 | } else if (!(psource_frame->nFlags & OMX_BUFFERFLAG_EOS)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7490 | DEBUG_PRINT_ERROR("Zero len buffer return back to POOL"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7491 | m_input_free_q.insert_entry((unsigned) pdest_frame, (unsigned)NULL, |
| 7492 | (unsigned)NULL); |
| 7493 | pdest_frame = NULL; |
| 7494 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7495 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7496 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7497 | DEBUG_PRINT_LOW("Not a Complete Frame %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7498 | /*Check if Destination Buffer is full*/ |
| 7499 | if (pdest_frame->nAllocLen == |
| 7500 | pdest_frame->nFilledLen + pdest_frame->nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7501 | DEBUG_PRINT_ERROR("ERROR:Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7502 | return OMX_ErrorStreamCorrupt; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7503 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7504 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7505 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7506 | if (psource_frame->nFilledLen == 0) { |
| 7507 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7508 | if (pdest_frame) { |
| 7509 | pdest_frame->nFlags |= psource_frame->nFlags; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7510 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %lld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7511 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7512 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7513 | pdest_frame->nFilledLen,frame_count++); |
| 7514 | /*Push the frame to the Decoder*/ |
| 7515 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7516 | return OMX_ErrorBadParameter; |
| 7517 | } |
| 7518 | frame_count++; |
| 7519 | pdest_frame = NULL; |
| 7520 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7521 | DEBUG_PRINT_LOW("Last frame in else dest addr") ; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7522 | generate_ebd = OMX_FALSE; |
| 7523 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7524 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7525 | if (generate_ebd) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7526 | DEBUG_PRINT_LOW("Buffer Consumed return back to client %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7527 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7528 | psource_frame = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7529 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7530 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7531 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7532 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7533 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7534 | DEBUG_PRINT_LOW("Next source Buffer %p time stamp %lld",psource_frame, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7535 | psource_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7536 | DEBUG_PRINT_LOW("Next source Buffer flag %lu length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7537 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7538 | } |
| 7539 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7540 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7541 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7542 | } |
| 7543 | |
| 7544 | OMX_ERRORTYPE omx_vdec::push_input_h264 (OMX_HANDLETYPE hComp) |
| 7545 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7546 | OMX_U32 partial_frame = 1; |
| 7547 | unsigned address = 0, p2 = 0, id = 0; |
| 7548 | OMX_BOOL isNewFrame = OMX_FALSE; |
| 7549 | OMX_BOOL generate_ebd = OMX_TRUE; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7550 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7551 | if (h264_scratch.pBuffer == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7552 | DEBUG_PRINT_ERROR("ERROR:H.264 Scratch Buffer not allocated"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7553 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7554 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7555 | DEBUG_PRINT_LOW("Pending h264_scratch.nFilledLen %lu " |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7556 | "look_ahead_nal %d", h264_scratch.nFilledLen, look_ahead_nal); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7557 | DEBUG_PRINT_LOW("Pending pdest_frame->nFilledLen %lu",pdest_frame->nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7558 | if (h264_scratch.nFilledLen && look_ahead_nal) { |
| 7559 | look_ahead_nal = false; |
| 7560 | if ((pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7561 | h264_scratch.nFilledLen) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7562 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7563 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7564 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7565 | DEBUG_PRINT_LOW("Copy the previous NAL (h264 scratch) into Dest frame"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7566 | h264_scratch.nFilledLen = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7567 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7568 | DEBUG_PRINT_ERROR("Error:1: Destination buffer overflow for H264"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7569 | return OMX_ErrorBadParameter; |
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 | } |
Praveen Chavan | ce0b5e8 | 2013-08-08 05:23:34 -0700 | [diff] [blame] | 7572 | |
| 7573 | /* If an empty input is queued with EOS, do not coalesce with the destination-frame yet, as this may result |
| 7574 | in EOS flag getting associated with the destination |
| 7575 | */ |
| 7576 | if (!psource_frame->nFilledLen && (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) && |
| 7577 | pdest_frame->nFilledLen) { |
| 7578 | DEBUG_PRINT_HIGH("delay ETB for 'empty buffer with EOS'"); |
| 7579 | generate_ebd = OMX_FALSE; |
| 7580 | } |
| 7581 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7582 | if (nal_length == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7583 | DEBUG_PRINT_LOW("Zero NAL, hence parse using start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7584 | if (m_frame_parser.parse_sc_frame(psource_frame, |
| 7585 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7586 | DEBUG_PRINT_ERROR("Error In Parsing Return Error"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7587 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7588 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7589 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7590 | 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] | 7591 | if (m_frame_parser.parse_h264_nallength(psource_frame, |
| 7592 | &h264_scratch,&partial_frame) == -1) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7593 | DEBUG_PRINT_ERROR("Error In Parsing NAL size, Return Error"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7594 | return OMX_ErrorBadParameter; |
| 7595 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7596 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7597 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7598 | if (partial_frame == 0) { |
| 7599 | if (nal_count == 0 && h264_scratch.nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7600 | DEBUG_PRINT_LOW("First NAL with Zero Length, hence Skip"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7601 | nal_count++; |
| 7602 | h264_scratch.nTimeStamp = psource_frame->nTimeStamp; |
| 7603 | h264_scratch.nFlags = psource_frame->nFlags; |
| 7604 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7605 | DEBUG_PRINT_LOW("Parsed New NAL Length = %lu",h264_scratch.nFilledLen); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7606 | if (h264_scratch.nFilledLen) { |
| 7607 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, h264_scratch.nFilledLen, |
| 7608 | NALU_TYPE_SPS); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7609 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7610 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) |
| 7611 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7612 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
| 7613 | else if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7614 | // If timeinfo is present frame info from SEI is already processed |
| 7615 | h264_parser->parse_nal((OMX_U8*)h264_scratch.pBuffer, |
| 7616 | h264_scratch.nFilledLen, NALU_TYPE_SEI); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7617 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7618 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7619 | nal_count++; |
| 7620 | if (VALID_TS(h264_last_au_ts) && !VALID_TS(pdest_frame->nTimeStamp)) { |
| 7621 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7622 | pdest_frame->nFlags = h264_last_au_flags; |
| 7623 | #ifdef PANSCAN_HDLR |
| 7624 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) |
| 7625 | h264_parser->update_panscan_data(h264_last_au_ts); |
| 7626 | #endif |
| 7627 | } |
| 7628 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_NON_IDR || |
| 7629 | m_frame_parser.mutils->nalu_type == NALU_TYPE_IDR) { |
| 7630 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7631 | h264_last_au_flags = h264_scratch.nFlags; |
| 7632 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7633 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7634 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(h264_last_au_ts); |
| 7635 | if (!VALID_TS(h264_last_au_ts)) |
| 7636 | h264_last_au_ts = ts_in_sei; |
| 7637 | } |
| 7638 | #endif |
| 7639 | } else |
| 7640 | h264_last_au_ts = LLONG_MAX; |
| 7641 | } |
| 7642 | |
| 7643 | if (!isNewFrame) { |
| 7644 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7645 | h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7646 | DEBUG_PRINT_LOW("Not a NewFrame Copy into Dest len %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7647 | h264_scratch.nFilledLen); |
| 7648 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7649 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7650 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7651 | if (m_frame_parser.mutils->nalu_type == NALU_TYPE_EOSEQ) |
| 7652 | pdest_frame->nFlags |= QOMX_VIDEO_BUFFERFLAG_EOSEQ; |
| 7653 | h264_scratch.nFilledLen = 0; |
| 7654 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7655 | DEBUG_PRINT_LOW("Error:2: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7656 | return OMX_ErrorBadParameter; |
| 7657 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7658 | } else if(h264_scratch.nFilledLen) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7659 | look_ahead_nal = true; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7660 | DEBUG_PRINT_LOW("Frame Found start Decoding Size =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7661 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7662 | DEBUG_PRINT_LOW("Found a frame size = %lu number = %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7663 | pdest_frame->nFilledLen,frame_count++); |
| 7664 | |
| 7665 | if (pdest_frame->nFilledLen == 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7666 | DEBUG_PRINT_LOW("Copy the Current Frame since and push it"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7667 | look_ahead_nal = false; |
| 7668 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7669 | h264_scratch.nFilledLen) { |
| 7670 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7671 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7672 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7673 | h264_scratch.nFilledLen = 0; |
| 7674 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7675 | DEBUG_PRINT_ERROR("Error:3: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7676 | return OMX_ErrorBadParameter; |
| 7677 | } |
| 7678 | } else { |
| 7679 | if (psource_frame->nFilledLen || h264_scratch.nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7680 | DEBUG_PRINT_LOW("Reset the EOS Flag"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7681 | pdest_frame->nFlags &= ~OMX_BUFFERFLAG_EOS; |
| 7682 | } |
| 7683 | /*Push the frame to the Decoder*/ |
| 7684 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7685 | return OMX_ErrorBadParameter; |
| 7686 | } |
| 7687 | //frame_count++; |
| 7688 | pdest_frame = NULL; |
| 7689 | if (m_input_free_q.m_size) { |
| 7690 | m_input_free_q.pop_entry(&address,&p2,&id); |
| 7691 | pdest_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7692 | DEBUG_PRINT_LOW("Pop the next pdest_buffer %p",pdest_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7693 | pdest_frame->nFilledLen = 0; |
| 7694 | pdest_frame->nFlags = 0; |
| 7695 | pdest_frame->nTimeStamp = LLONG_MAX; |
| 7696 | } |
| 7697 | } |
| 7698 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7699 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7700 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7701 | 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] | 7702 | /*Check if Destination Buffer is full*/ |
| 7703 | if (h264_scratch.nAllocLen == |
| 7704 | h264_scratch.nFilledLen + h264_scratch.nOffset) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7705 | DEBUG_PRINT_ERROR("ERROR: Frame Not found though Destination Filled"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7706 | return OMX_ErrorStreamCorrupt; |
| 7707 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7708 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7709 | |
| 7710 | if (!psource_frame->nFilledLen) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7711 | 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] | 7712 | |
| 7713 | if (psource_frame->nFlags & OMX_BUFFERFLAG_EOS) { |
| 7714 | if (pdest_frame) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7715 | DEBUG_PRINT_LOW("EOS Reached Pass Last Buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7716 | if ( (pdest_frame->nAllocLen - pdest_frame->nFilledLen) >= |
| 7717 | h264_scratch.nFilledLen) { |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7718 | if(pdest_frame->nFilledLen == 0) { |
| 7719 | /* No residual frame from before, send whatever |
| 7720 | * we have left */ |
| 7721 | memcpy((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7722 | h264_scratch.pBuffer, h264_scratch.nFilledLen); |
| 7723 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7724 | h264_scratch.nFilledLen = 0; |
| 7725 | pdest_frame->nTimeStamp = h264_scratch.nTimeStamp; |
| 7726 | } else { |
| 7727 | m_frame_parser.mutils->isNewFrame(&h264_scratch, 0, isNewFrame); |
| 7728 | if(!isNewFrame) { |
| 7729 | /* Have a residual frame, but we know that the |
| 7730 | * AU in this frame is belonging to whatever |
| 7731 | * frame we had left over. So append it */ |
| 7732 | memcpy ((pdest_frame->pBuffer + pdest_frame->nFilledLen), |
| 7733 | h264_scratch.pBuffer,h264_scratch.nFilledLen); |
| 7734 | pdest_frame->nFilledLen += h264_scratch.nFilledLen; |
| 7735 | h264_scratch.nFilledLen = 0; |
Balamurugan Alagarsamy | efde383 | 2014-09-22 19:52:20 +0530 | [diff] [blame] | 7736 | if (h264_last_au_ts != LLONG_MAX) |
| 7737 | pdest_frame->nTimeStamp = h264_last_au_ts; |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7738 | } else { |
| 7739 | /* Completely new frame, let's just push what |
| 7740 | * we have now. The resulting EBD would trigger |
| 7741 | * another push */ |
| 7742 | generate_ebd = OMX_FALSE; |
| 7743 | pdest_frame->nTimeStamp = h264_last_au_ts; |
| 7744 | h264_last_au_ts = h264_scratch.nTimeStamp; |
| 7745 | } |
| 7746 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7747 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7748 | DEBUG_PRINT_ERROR("ERROR:4: Destination buffer overflow for H264"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7749 | return OMX_ErrorBadParameter; |
| 7750 | } |
Leena Winterrowd | 5a974ce | 2013-08-06 15:10:36 -0700 | [diff] [blame] | 7751 | |
| 7752 | /* Iff we coalesced two buffers, inherit the flags of both bufs */ |
| 7753 | if(generate_ebd == OMX_TRUE) { |
| 7754 | pdest_frame->nFlags = h264_scratch.nFlags | psource_frame->nFlags; |
| 7755 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7756 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7757 | DEBUG_PRINT_LOW("pdest_frame->nFilledLen =%lu TimeStamp = %llu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7758 | pdest_frame->nFilledLen,pdest_frame->nTimeStamp); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7759 | DEBUG_PRINT_LOW("Push AU frame number %d to driver", frame_count++); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7760 | #ifndef PROCESS_EXTRADATA_IN_OUTPUT_PORT |
| 7761 | if (client_extradata & OMX_TIMEINFO_EXTRADATA) { |
| 7762 | OMX_S64 ts_in_sei = h264_parser->process_ts_with_sei_vui(pdest_frame->nTimeStamp); |
| 7763 | if (!VALID_TS(pdest_frame->nTimeStamp)) |
| 7764 | pdest_frame->nTimeStamp = ts_in_sei; |
| 7765 | } |
| 7766 | #endif |
| 7767 | /*Push the frame to the Decoder*/ |
| 7768 | if (empty_this_buffer_proxy(hComp,pdest_frame) != OMX_ErrorNone) { |
| 7769 | return OMX_ErrorBadParameter; |
| 7770 | } |
| 7771 | frame_count++; |
| 7772 | pdest_frame = NULL; |
| 7773 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7774 | DEBUG_PRINT_LOW("Last frame in else dest addr %p size %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7775 | pdest_frame,h264_scratch.nFilledLen); |
| 7776 | generate_ebd = OMX_FALSE; |
| 7777 | } |
| 7778 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7779 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7780 | if (generate_ebd && !psource_frame->nFilledLen) { |
| 7781 | m_cb.EmptyBufferDone (hComp,m_app_data,psource_frame); |
| 7782 | psource_frame = NULL; |
| 7783 | if (m_input_pending_q.m_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7784 | DEBUG_PRINT_LOW("Pull Next source Buffer %p",psource_frame); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7785 | m_input_pending_q.pop_entry(&address,&p2,&id); |
| 7786 | psource_frame = (OMX_BUFFERHEADERTYPE *) address; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7787 | DEBUG_PRINT_LOW("Next source Buffer flag %lu src length %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7788 | psource_frame->nFlags,psource_frame->nFilledLen); |
| 7789 | } |
| 7790 | } |
| 7791 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7792 | } |
| 7793 | |
| 7794 | OMX_ERRORTYPE omx_vdec::push_input_vc1 (OMX_HANDLETYPE hComp) |
| 7795 | { |
| 7796 | OMX_U8 *buf, *pdest; |
| 7797 | OMX_U32 partial_frame = 1; |
| 7798 | OMX_U32 buf_len, dest_len; |
| 7799 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7800 | if (first_frame == 0) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7801 | first_frame = 1; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7802 | DEBUG_PRINT_LOW("First i/p buffer for VC1 arbitrary bytes"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7803 | if (!m_vendor_config.pData) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7804 | DEBUG_PRINT_LOW("Check profile type in 1st source buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7805 | buf = psource_frame->pBuffer; |
| 7806 | buf_len = psource_frame->nFilledLen; |
| 7807 | |
| 7808 | if ((*((OMX_U32 *) buf) & VC1_SP_MP_START_CODE_MASK) == |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7809 | VC1_SP_MP_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7810 | m_vc1_profile = VC1_SP_MP_RCV; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7811 | } else if (*((OMX_U32 *) buf) & VC1_AP_SEQ_START_CODE) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7812 | m_vc1_profile = VC1_AP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7813 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7814 | DEBUG_PRINT_ERROR("Invalid sequence layer in first buffer"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7815 | return OMX_ErrorStreamCorrupt; |
| 7816 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7817 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7818 | pdest = pdest_frame->pBuffer + pdest_frame->nFilledLen + |
| 7819 | pdest_frame->nOffset; |
| 7820 | dest_len = pdest_frame->nAllocLen - (pdest_frame->nFilledLen + |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7821 | pdest_frame->nOffset); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7822 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7823 | if (dest_len < m_vendor_config.nDataSize) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7824 | DEBUG_PRINT_ERROR("Destination buffer full"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7825 | return OMX_ErrorBadParameter; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7826 | } else { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7827 | memcpy(pdest, m_vendor_config.pData, m_vendor_config.nDataSize); |
| 7828 | pdest_frame->nFilledLen += m_vendor_config.nDataSize; |
| 7829 | } |
| 7830 | } |
| 7831 | } |
| 7832 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7833 | switch (m_vc1_profile) { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7834 | case VC1_AP: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7835 | DEBUG_PRINT_LOW("VC1 AP, hence parse using frame start code"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7836 | if (push_input_sc_codec(hComp) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7837 | DEBUG_PRINT_ERROR("Error In Parsing VC1 AP start code"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7838 | return OMX_ErrorBadParameter; |
| 7839 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7840 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7841 | |
| 7842 | case VC1_SP_MP_RCV: |
| 7843 | default: |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7844 | DEBUG_PRINT_ERROR("Unsupported VC1 profile in ArbitraryBytes Mode"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7845 | return OMX_ErrorBadParameter; |
| 7846 | } |
| 7847 | return OMX_ErrorNone; |
| 7848 | } |
| 7849 | |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7850 | #ifndef USE_ION |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7851 | 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] | 7852 | OMX_U32 alignment) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7853 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7854 | struct pmem_allocation allocation; |
| 7855 | allocation.size = buffer_size; |
| 7856 | allocation.align = clip2(alignment); |
| 7857 | if (allocation.align < 4096) { |
| 7858 | allocation.align = 4096; |
| 7859 | } |
| 7860 | if (ioctl(pmem_fd, PMEM_ALLOCATE_ALIGNED, &allocation) < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7861 | DEBUG_PRINT_ERROR("Aligment(%u) failed with pmem driver Sz(%lu)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7862 | allocation.align, allocation.size); |
| 7863 | return false; |
| 7864 | } |
| 7865 | return true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7866 | } |
David Ng | 38e2d23 | 2013-03-15 20:05:58 -0700 | [diff] [blame] | 7867 | #endif |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7868 | #ifdef USE_ION |
| 7869 | int omx_vdec::alloc_map_ion_memory(OMX_U32 buffer_size, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7870 | OMX_U32 alignment, struct ion_allocation_data *alloc_data, |
| 7871 | struct ion_fd_data *fd_data, int flag) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7872 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7873 | int fd = -EINVAL; |
| 7874 | int rc = -EINVAL; |
| 7875 | int ion_dev_flag; |
| 7876 | struct vdec_ion ion_buf_info; |
| 7877 | if (!alloc_data || buffer_size <= 0 || !fd_data) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7878 | DEBUG_PRINT_ERROR("Invalid arguments to alloc_map_ion_memory"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7879 | return -EINVAL; |
| 7880 | } |
| 7881 | ion_dev_flag = O_RDONLY; |
| 7882 | fd = open (MEM_DEVICE, ion_dev_flag); |
| 7883 | if (fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7884 | DEBUG_PRINT_ERROR("opening ion device failed with fd = %d", fd); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7885 | return fd; |
| 7886 | } |
| 7887 | alloc_data->flags = 0; |
| 7888 | if (!secure_mode && (flag & ION_FLAG_CACHED)) { |
| 7889 | alloc_data->flags |= ION_FLAG_CACHED; |
| 7890 | } |
| 7891 | alloc_data->len = buffer_size; |
| 7892 | alloc_data->align = clip2(alignment); |
| 7893 | if (alloc_data->align < 4096) { |
| 7894 | alloc_data->align = 4096; |
| 7895 | } |
| 7896 | if ((secure_mode) && (flag & ION_SECURE)) |
| 7897 | alloc_data->flags |= ION_SECURE; |
Vinay Kalia | 53fa683 | 2012-10-11 17:55:30 -0700 | [diff] [blame] | 7898 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7899 | alloc_data->heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 7900 | if (secure_mode && (alloc_data->flags & ION_SECURE)) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7901 | alloc_data->heap_mask = ION_HEAP(MEM_HEAP_ID); |
| 7902 | rc = ioctl(fd,ION_IOC_ALLOC,alloc_data); |
| 7903 | if (rc || !alloc_data->handle) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7904 | DEBUG_PRINT_ERROR("ION ALLOC memory failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7905 | alloc_data->handle = NULL; |
| 7906 | close(fd); |
| 7907 | fd = -ENOMEM; |
| 7908 | return fd; |
| 7909 | } |
| 7910 | fd_data->handle = alloc_data->handle; |
| 7911 | rc = ioctl(fd,ION_IOC_MAP,fd_data); |
| 7912 | if (rc) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7913 | DEBUG_PRINT_ERROR("ION MAP failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7914 | ion_buf_info.ion_alloc_data = *alloc_data; |
| 7915 | ion_buf_info.ion_device_fd = fd; |
| 7916 | ion_buf_info.fd_ion_data = *fd_data; |
| 7917 | free_ion_memory(&ion_buf_info); |
| 7918 | fd_data->fd =-1; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7919 | fd = -ENOMEM; |
| 7920 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7921 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7922 | return fd; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7923 | } |
| 7924 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7925 | void omx_vdec::free_ion_memory(struct vdec_ion *buf_ion_info) |
| 7926 | { |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7927 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7928 | if (!buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7929 | DEBUG_PRINT_ERROR("ION: free called with invalid fd/allocdata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7930 | return; |
| 7931 | } |
| 7932 | if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE, |
| 7933 | &buf_ion_info->ion_alloc_data.handle)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7934 | DEBUG_PRINT_ERROR("ION: free failed" ); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7935 | } |
| 7936 | close(buf_ion_info->ion_device_fd); |
| 7937 | buf_ion_info->ion_device_fd = -1; |
| 7938 | buf_ion_info->ion_alloc_data.handle = NULL; |
| 7939 | buf_ion_info->fd_ion_data.fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7940 | } |
| 7941 | #endif |
| 7942 | void omx_vdec::free_output_buffer_header() |
| 7943 | { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7944 | DEBUG_PRINT_HIGH("ALL output buffers are freed/released"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7945 | output_use_buffer = false; |
| 7946 | ouput_egl_buffers = false; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7947 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7948 | if (m_out_mem_ptr) { |
| 7949 | free (m_out_mem_ptr); |
| 7950 | m_out_mem_ptr = NULL; |
| 7951 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7952 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7953 | if (m_platform_list) { |
| 7954 | free(m_platform_list); |
| 7955 | m_platform_list = NULL; |
| 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 (drv_ctx.ptr_respbuffer) { |
| 7959 | free (drv_ctx.ptr_respbuffer); |
| 7960 | drv_ctx.ptr_respbuffer = NULL; |
| 7961 | } |
| 7962 | if (drv_ctx.ptr_outputbuffer) { |
| 7963 | free (drv_ctx.ptr_outputbuffer); |
| 7964 | drv_ctx.ptr_outputbuffer = NULL; |
| 7965 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7966 | #ifdef USE_ION |
| 7967 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7968 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7969 | free(drv_ctx.op_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7970 | drv_ctx.op_buf_ion_info = NULL; |
| 7971 | } |
| 7972 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 7973 | if (out_dynamic_list) { |
| 7974 | free(out_dynamic_list); |
| 7975 | out_dynamic_list = NULL; |
| 7976 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7977 | } |
| 7978 | |
| 7979 | void omx_vdec::free_input_buffer_header() |
| 7980 | { |
| 7981 | input_use_buffer = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7982 | if (arbitrary_bytes) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7983 | if (m_inp_heap_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7984 | DEBUG_PRINT_LOW("Free input Heap Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7985 | free (m_inp_heap_ptr); |
| 7986 | m_inp_heap_ptr = NULL; |
| 7987 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7988 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7989 | if (m_phdr_pmem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7990 | DEBUG_PRINT_LOW("Free input pmem header Pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7991 | free (m_phdr_pmem_ptr); |
| 7992 | m_phdr_pmem_ptr = NULL; |
| 7993 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7994 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7995 | if (m_inp_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 7996 | DEBUG_PRINT_LOW("Free input pmem Pointer area"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 7997 | free (m_inp_mem_ptr); |
| 7998 | m_inp_mem_ptr = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 7999 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 8000 | /* We just freed all the buffer headers, every thing in m_input_free_q, |
| 8001 | * m_input_pending_q, pdest_frame, and psource_frame is now invalid */ |
Leena Winterrowd | 1d2424a | 2013-08-20 15:26:02 -0700 | [diff] [blame] | 8002 | while (m_input_free_q.m_size) { |
| 8003 | unsigned address, p2, id; |
| 8004 | m_input_free_q.pop_entry(&address, &p2, &id); |
| 8005 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 8006 | while (m_input_pending_q.m_size) { |
| 8007 | unsigned address, p2, id; |
| 8008 | m_input_pending_q.pop_entry(&address, &p2, &id); |
| 8009 | } |
| 8010 | pdest_frame = NULL; |
| 8011 | psource_frame = NULL; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8012 | if (drv_ctx.ptr_inputbuffer) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8013 | DEBUG_PRINT_LOW("Free Driver Context pointer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8014 | free (drv_ctx.ptr_inputbuffer); |
| 8015 | drv_ctx.ptr_inputbuffer = NULL; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8016 | } |
| 8017 | #ifdef USE_ION |
| 8018 | if (drv_ctx.ip_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8019 | DEBUG_PRINT_LOW("Free ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8020 | free(drv_ctx.ip_buf_ion_info); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8021 | drv_ctx.ip_buf_ion_info = NULL; |
| 8022 | } |
| 8023 | #endif |
| 8024 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8025 | |
| 8026 | int omx_vdec::stream_off(OMX_U32 port) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8027 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8028 | enum v4l2_buf_type btype; |
| 8029 | int rc = 0; |
| 8030 | enum v4l2_ports v4l2_port = OUTPUT_PORT; |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8031 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8032 | if (port == OMX_CORE_INPUT_PORT_INDEX) { |
| 8033 | btype = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8034 | v4l2_port = OUTPUT_PORT; |
| 8035 | } else if (port == OMX_CORE_OUTPUT_PORT_INDEX) { |
| 8036 | btype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8037 | v4l2_port = CAPTURE_PORT; |
| 8038 | } else if (port == OMX_ALL) { |
| 8039 | int rc_input = stream_off(OMX_CORE_INPUT_PORT_INDEX); |
| 8040 | int rc_output = stream_off(OMX_CORE_OUTPUT_PORT_INDEX); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8041 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8042 | if (!rc_input) |
| 8043 | return rc_input; |
| 8044 | else |
| 8045 | return rc_output; |
| 8046 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8047 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8048 | if (!streaming[v4l2_port]) { |
| 8049 | // already streamed off, warn and move on |
| 8050 | DEBUG_PRINT_HIGH("Warning: Attempting to stream off on %d port," |
| 8051 | " which is already streamed off", v4l2_port); |
| 8052 | return 0; |
| 8053 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8054 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8055 | DEBUG_PRINT_HIGH("Streaming off %d port", v4l2_port); |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8056 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8057 | rc = ioctl(drv_ctx.video_driver_fd, VIDIOC_STREAMOFF, &btype); |
| 8058 | if (rc) { |
| 8059 | /*TODO: How to handle this case */ |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8060 | DEBUG_PRINT_ERROR("Failed to call streamoff on %d Port", v4l2_port); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8061 | } else { |
| 8062 | streaming[v4l2_port] = false; |
| 8063 | } |
Deva Ramasubramanian | f97488b | 2012-10-26 18:37:05 -0700 | [diff] [blame] | 8064 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8065 | return rc; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8066 | } |
| 8067 | |
| 8068 | OMX_ERRORTYPE omx_vdec::get_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 8069 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8070 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8071 | struct v4l2_requestbuffers bufreq; |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 8072 | 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] | 8073 | unsigned int final_extra_data_size = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8074 | struct v4l2_format fmt; |
| 8075 | int ret = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8076 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8077 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8078 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 8079 | bufreq.count = 1; |
| 8080 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8081 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8082 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8083 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 8084 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8085 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8086 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8087 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 8088 | } else { |
| 8089 | eRet = OMX_ErrorBadParameter; |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8090 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8091 | if (eRet==OMX_ErrorNone) { |
| 8092 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8093 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8094 | if (ret) { |
| 8095 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 8096 | /*TODO: How to handle this case */ |
| 8097 | eRet = OMX_ErrorInsufficientResources; |
| 8098 | return eRet; |
| 8099 | } else { |
| 8100 | buffer_prop->actualcount = bufreq.count; |
| 8101 | buffer_prop->mincount = bufreq.count; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8102 | DEBUG_PRINT_HIGH("Count = %d",bufreq.count); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8103 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8104 | DEBUG_PRINT_LOW("GetBufReq IN: ActCnt(%d) Size(%d)", |
| 8105 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8106 | |
| 8107 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 8108 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 8109 | |
| 8110 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 8111 | |
| 8112 | update_resolution(fmt.fmt.pix_mp.width, |
| 8113 | fmt.fmt.pix_mp.height, |
| 8114 | fmt.fmt.pix_mp.plane_fmt[0].bytesperline, |
| 8115 | fmt.fmt.pix_mp.plane_fmt[0].reserved[0]); |
| 8116 | if (fmt.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 8117 | drv_ctx.num_planes = fmt.fmt.pix_mp.num_planes; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8118 | 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] | 8119 | |
| 8120 | if (ret) { |
| 8121 | /*TODO: How to handle this case */ |
| 8122 | DEBUG_PRINT_ERROR("Requesting buffer requirements failed"); |
| 8123 | eRet = OMX_ErrorInsufficientResources; |
| 8124 | } else { |
| 8125 | int extra_idx = 0; |
| 8126 | |
| 8127 | eRet = is_video_session_supported(); |
| 8128 | if (eRet) |
| 8129 | return eRet; |
| 8130 | |
| 8131 | buffer_prop->buffer_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage; |
| 8132 | buf_size = buffer_prop->buffer_size; |
| 8133 | extra_idx = EXTRADATA_IDX(drv_ctx.num_planes); |
| 8134 | if (extra_idx && (extra_idx < VIDEO_MAX_PLANES)) { |
| 8135 | extra_data_size = fmt.fmt.pix_mp.plane_fmt[extra_idx].sizeimage; |
| 8136 | } else if (extra_idx >= VIDEO_MAX_PLANES) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8137 | DEBUG_PRINT_ERROR("Extradata index is more than allowed: %d", extra_idx); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8138 | return OMX_ErrorBadParameter; |
| 8139 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8140 | |
Deva Ramasubramanian | 991d0db | 2014-05-08 15:02:24 -0700 | [diff] [blame] | 8141 | default_extra_data_size = VENUS_EXTRADATA_SIZE( |
| 8142 | drv_ctx.video_resolution.frame_height, |
| 8143 | drv_ctx.video_resolution.frame_width); |
| 8144 | final_extra_data_size = extra_data_size > default_extra_data_size ? |
| 8145 | extra_data_size : default_extra_data_size; |
| 8146 | |
| 8147 | final_extra_data_size = (final_extra_data_size + buffer_prop->alignment - 1) & |
| 8148 | (~(buffer_prop->alignment - 1)); |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 8149 | |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8150 | drv_ctx.extradata_info.size = buffer_prop->actualcount * final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8151 | drv_ctx.extradata_info.count = buffer_prop->actualcount; |
Pushkaraj Patil | 1ab1029 | 2014-02-11 20:10:42 +0530 | [diff] [blame] | 8152 | drv_ctx.extradata_info.buffer_size = final_extra_data_size; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8153 | if (!secure_mode) |
| 8154 | buf_size += final_extra_data_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8155 | buf_size = (buf_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8156 | DEBUG_PRINT_LOW("GetBufReq UPDATE: ActCnt(%d) Size(%d) BufSize(%d)", |
| 8157 | buffer_prop->actualcount, buffer_prop->buffer_size, buf_size); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8158 | if (extra_data_size) |
| 8159 | DEBUG_PRINT_LOW("GetBufReq UPDATE: extradata: TotalSize(%d) BufferSize(%d)", |
| 8160 | drv_ctx.extradata_info.size, drv_ctx.extradata_info.buffer_size); |
| 8161 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8162 | if (in_reconfig) // BufReq will be set to driver when port is disabled |
| 8163 | buffer_prop->buffer_size = buf_size; |
| 8164 | else if (buf_size != buffer_prop->buffer_size) { |
| 8165 | buffer_prop->buffer_size = buf_size; |
| 8166 | eRet = set_buffer_req(buffer_prop); |
| 8167 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8168 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8169 | DEBUG_PRINT_LOW("GetBufReq OUT: ActCnt(%d) Size(%d)", |
| 8170 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8171 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8172 | } |
| 8173 | |
| 8174 | OMX_ERRORTYPE omx_vdec::set_buffer_req(vdec_allocatorproperty *buffer_prop) |
| 8175 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8176 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8177 | unsigned buf_size = 0; |
| 8178 | struct v4l2_format fmt; |
| 8179 | struct v4l2_requestbuffers bufreq; |
| 8180 | int ret; |
| 8181 | DEBUG_PRINT_LOW("SetBufReq IN: ActCnt(%d) Size(%d)", |
| 8182 | buffer_prop->actualcount, buffer_prop->buffer_size); |
| 8183 | buf_size = (buffer_prop->buffer_size + buffer_prop->alignment - 1)&(~(buffer_prop->alignment - 1)); |
| 8184 | if (buf_size != buffer_prop->buffer_size) { |
| 8185 | DEBUG_PRINT_ERROR("Buffer size alignment error: Requested(%d) Required(%d)", |
| 8186 | buffer_prop->buffer_size, buf_size); |
| 8187 | eRet = OMX_ErrorBadParameter; |
| 8188 | } else { |
| 8189 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 8190 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8191 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8192 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8193 | fmt.type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8194 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Shalaj Jain | d3902bb | 2013-10-07 12:42:55 -0700 | [diff] [blame] | 8195 | fmt.fmt.pix_mp.plane_fmt[0].sizeimage = buf_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8196 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8197 | fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8198 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
| 8199 | } else { |
| 8200 | eRet = OMX_ErrorBadParameter; |
| 8201 | } |
Deva Ramasubramanian | 614f79e | 2012-08-10 21:42:10 -0700 | [diff] [blame] | 8202 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8203 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 8204 | if (ret) { |
| 8205 | /*TODO: How to handle this case */ |
| 8206 | DEBUG_PRINT_ERROR("Setting buffer requirements (format) failed %d", ret); |
| 8207 | eRet = OMX_ErrorInsufficientResources; |
| 8208 | } |
| 8209 | |
| 8210 | bufreq.memory = V4L2_MEMORY_USERPTR; |
| 8211 | bufreq.count = buffer_prop->actualcount; |
| 8212 | if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_INPUT) { |
| 8213 | bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8214 | } else if (buffer_prop->buffer_type == VDEC_BUFFER_TYPE_OUTPUT) { |
| 8215 | bufreq.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8216 | } else { |
| 8217 | eRet = OMX_ErrorBadParameter; |
| 8218 | } |
| 8219 | |
| 8220 | if (eRet==OMX_ErrorNone) { |
| 8221 | ret = ioctl(drv_ctx.video_driver_fd,VIDIOC_REQBUFS, &bufreq); |
| 8222 | } |
| 8223 | |
| 8224 | if (ret) { |
| 8225 | DEBUG_PRINT_ERROR("Setting buffer requirements (reqbufs) failed %d", ret); |
| 8226 | /*TODO: How to handle this case */ |
| 8227 | eRet = OMX_ErrorInsufficientResources; |
| 8228 | } else if (bufreq.count < buffer_prop->actualcount) { |
| 8229 | DEBUG_PRINT_ERROR("Driver refused to change the number of buffers" |
| 8230 | " on v4l2 port %d to %d (prefers %d)", bufreq.type, |
| 8231 | buffer_prop->actualcount, bufreq.count); |
| 8232 | eRet = OMX_ErrorInsufficientResources; |
| 8233 | } else { |
| 8234 | if (!client_buffers.update_buffer_req()) { |
| 8235 | DEBUG_PRINT_ERROR("Setting c2D buffer requirements failed"); |
| 8236 | eRet = OMX_ErrorInsufficientResources; |
| 8237 | } |
| 8238 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8239 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8240 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8241 | } |
| 8242 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8243 | OMX_ERRORTYPE omx_vdec::update_picture_resolution() |
| 8244 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8245 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8246 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8247 | } |
| 8248 | |
| 8249 | OMX_ERRORTYPE omx_vdec::update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn) |
| 8250 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8251 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8252 | struct v4l2_format fmt; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8253 | if (!portDefn) { |
| 8254 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8255 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8256 | DEBUG_PRINT_LOW("omx_vdec::update_portdef"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8257 | portDefn->nVersion.nVersion = OMX_SPEC_VERSION; |
Praveen Chavan | 366ded5 | 2016-04-11 17:33:02 -0700 | [diff] [blame] | 8258 | portDefn->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8259 | portDefn->eDomain = OMX_PortDomainVideo; |
| 8260 | if (drv_ctx.frame_rate.fps_denominator > 0) |
Deva Ramasubramanian | 9ba5d83 | 2014-01-03 18:32:50 -0800 | [diff] [blame] | 8261 | portDefn->format.video.xFramerate = (drv_ctx.frame_rate.fps_numerator / |
| 8262 | drv_ctx.frame_rate.fps_denominator) << 16; //Q16 format |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8263 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8264 | DEBUG_PRINT_ERROR("Error: Divide by zero"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8265 | return OMX_ErrorBadParameter; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 8266 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8267 | memset(&fmt, 0x0, sizeof(struct v4l2_format)); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8268 | if (0 == portDefn->nPortIndex) { |
| 8269 | portDefn->eDir = OMX_DirInput; |
| 8270 | portDefn->nBufferCountActual = drv_ctx.ip_buf.actualcount; |
| 8271 | portDefn->nBufferCountMin = drv_ctx.ip_buf.mincount; |
| 8272 | portDefn->nBufferSize = drv_ctx.ip_buf.buffer_size; |
| 8273 | portDefn->format.video.eColorFormat = OMX_COLOR_FormatUnused; |
| 8274 | portDefn->format.video.eCompressionFormat = eCompressionFormat; |
| 8275 | portDefn->bEnabled = m_inp_bEnabled; |
| 8276 | portDefn->bPopulated = m_inp_bPopulated; |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8277 | |
| 8278 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8279 | fmt.fmt.pix_mp.pixelformat = output_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8280 | } else if (1 == portDefn->nPortIndex) { |
| 8281 | unsigned int buf_size = 0; |
| 8282 | if (!client_buffers.update_buffer_req()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8283 | DEBUG_PRINT_ERROR("client_buffers.update_buffer_req Failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8284 | return OMX_ErrorHardware; |
| 8285 | } |
| 8286 | if (!client_buffers.get_buffer_req(buf_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8287 | DEBUG_PRINT_ERROR("update buffer requirements"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8288 | return OMX_ErrorHardware; |
| 8289 | } |
| 8290 | portDefn->nBufferSize = buf_size; |
| 8291 | portDefn->eDir = OMX_DirOutput; |
| 8292 | portDefn->nBufferCountActual = drv_ctx.op_buf.actualcount; |
| 8293 | portDefn->nBufferCountMin = drv_ctx.op_buf.mincount; |
| 8294 | portDefn->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 8295 | portDefn->bEnabled = m_out_bEnabled; |
| 8296 | portDefn->bPopulated = m_out_bPopulated; |
| 8297 | if (!client_buffers.get_color_format(portDefn->format.video.eColorFormat)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8298 | DEBUG_PRINT_ERROR("Error in getting color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8299 | return OMX_ErrorHardware; |
| 8300 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8301 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 8302 | fmt.fmt.pix_mp.pixelformat = capture_capability; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8303 | } else { |
| 8304 | portDefn->eDir = OMX_DirMax; |
| 8305 | DEBUG_PRINT_LOW(" get_parameter: Bad Port idx %d", |
| 8306 | (int)portDefn->nPortIndex); |
| 8307 | eRet = OMX_ErrorBadPortIndex; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8308 | } |
Pushkaraj Patil | 4158835 | 2014-02-25 20:51:34 +0530 | [diff] [blame] | 8309 | if (is_down_scalar_enabled) { |
| 8310 | int ret = 0; |
| 8311 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt); |
| 8312 | if (ret) { |
| 8313 | DEBUG_PRINT_ERROR("update_portdef : Error in getting port resolution"); |
| 8314 | return OMX_ErrorHardware; |
| 8315 | } else { |
| 8316 | portDefn->format.video.nFrameWidth = fmt.fmt.pix_mp.width; |
| 8317 | portDefn->format.video.nFrameHeight = fmt.fmt.pix_mp.height; |
| 8318 | portDefn->format.video.nStride = fmt.fmt.pix_mp.plane_fmt[0].bytesperline; |
| 8319 | portDefn->format.video.nSliceHeight = fmt.fmt.pix_mp.plane_fmt[0].reserved[0]; |
| 8320 | } |
| 8321 | } else { |
| 8322 | portDefn->format.video.nFrameHeight = drv_ctx.video_resolution.frame_height; |
| 8323 | portDefn->format.video.nFrameWidth = drv_ctx.video_resolution.frame_width; |
| 8324 | portDefn->format.video.nStride = drv_ctx.video_resolution.stride; |
| 8325 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines; |
| 8326 | } |
| 8327 | |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 8328 | if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) || |
| 8329 | (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) { |
Maheshwar Ajja | 77cd19c | 2014-06-05 11:23:18 +0530 | [diff] [blame] | 8330 | portDefn->format.video.nStride = ALIGN(drv_ctx.video_resolution.frame_width, 16); |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8331 | portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height; |
| 8332 | } |
| 8333 | DEBUG_PRINT_HIGH("update_portdef(%lu): Width = %lu Height = %lu Stride = %ld " |
| 8334 | "SliceHeight = %lu eColorFormat = %lu nBufSize %lu nBufCnt %lu", |
| 8335 | portDefn->nPortIndex, |
| 8336 | portDefn->format.video.nFrameWidth, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8337 | portDefn->format.video.nFrameHeight, |
| 8338 | portDefn->format.video.nStride, |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8339 | portDefn->format.video.nSliceHeight, |
| 8340 | portDefn->format.video.eColorFormat, |
| 8341 | portDefn->nBufferSize, |
| 8342 | portDefn->nBufferCountActual); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8343 | |
Maheshwar Ajja | 507d655 | 2014-01-03 14:54:29 +0530 | [diff] [blame] | 8344 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8345 | } |
| 8346 | |
| 8347 | OMX_ERRORTYPE omx_vdec::allocate_output_headers() |
| 8348 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8349 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 8350 | OMX_BUFFERHEADERTYPE *bufHdr = NULL; |
| 8351 | unsigned i= 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8352 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8353 | if (!m_out_mem_ptr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8354 | DEBUG_PRINT_HIGH("Use o/p buffer case - Header List allocation"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8355 | int nBufHdrSize = 0; |
| 8356 | int nPlatformEntrySize = 0; |
| 8357 | int nPlatformListSize = 0; |
| 8358 | int nPMEMInfoSize = 0; |
| 8359 | OMX_QCOM_PLATFORM_PRIVATE_LIST *pPlatformList; |
| 8360 | OMX_QCOM_PLATFORM_PRIVATE_ENTRY *pPlatformEntry; |
| 8361 | OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pPMEMInfo; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8362 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8363 | DEBUG_PRINT_LOW("Setting First Output Buffer(%d)", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8364 | drv_ctx.op_buf.actualcount); |
| 8365 | nBufHdrSize = drv_ctx.op_buf.actualcount * |
| 8366 | sizeof(OMX_BUFFERHEADERTYPE); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8367 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8368 | nPMEMInfoSize = drv_ctx.op_buf.actualcount * |
| 8369 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO); |
| 8370 | nPlatformListSize = drv_ctx.op_buf.actualcount * |
| 8371 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_LIST); |
| 8372 | nPlatformEntrySize = drv_ctx.op_buf.actualcount * |
| 8373 | sizeof(OMX_QCOM_PLATFORM_PRIVATE_ENTRY); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8374 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8375 | DEBUG_PRINT_LOW("TotalBufHdr %d BufHdrSize %d PMEM %d PL %d",nBufHdrSize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8376 | sizeof(OMX_BUFFERHEADERTYPE), |
| 8377 | nPMEMInfoSize, |
| 8378 | nPlatformListSize); |
Steve Kondik | f191436 | 2015-11-01 02:50:41 -0800 | [diff] [blame] | 8379 | DEBUG_PRINT_LOW("PE %d bmSize %" PRId64, nPlatformEntrySize, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8380 | m_out_bm_count); |
| 8381 | m_out_mem_ptr = (OMX_BUFFERHEADERTYPE *)calloc(nBufHdrSize,1); |
| 8382 | // Alloc mem for platform specific info |
| 8383 | char *pPtr=NULL; |
| 8384 | pPtr = (char*) calloc(nPlatformListSize + nPlatformEntrySize + |
| 8385 | nPMEMInfoSize,1); |
| 8386 | drv_ctx.ptr_outputbuffer = (struct vdec_bufferpayload *) \ |
| 8387 | calloc (sizeof(struct vdec_bufferpayload), |
| 8388 | drv_ctx.op_buf.actualcount); |
| 8389 | drv_ctx.ptr_respbuffer = (struct vdec_output_frameinfo *)\ |
| 8390 | calloc (sizeof (struct vdec_output_frameinfo), |
| 8391 | drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8392 | if (!drv_ctx.ptr_outputbuffer || !drv_ctx.ptr_respbuffer) { |
| 8393 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.ptr_outputbuffer or drv_ctx.ptr_respbuffer"); |
| 8394 | return OMX_ErrorInsufficientResources; |
| 8395 | } |
| 8396 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8397 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8398 | drv_ctx.op_buf_ion_info = (struct vdec_ion * ) \ |
| 8399 | calloc (sizeof(struct vdec_ion),drv_ctx.op_buf.actualcount); |
Arun Menon | 8544ead | 2014-05-08 17:42:29 -0700 | [diff] [blame] | 8400 | if (!drv_ctx.op_buf_ion_info) { |
| 8401 | DEBUG_PRINT_ERROR("Failed to alloc drv_ctx.op_buf_ion_info"); |
| 8402 | return OMX_ErrorInsufficientResources; |
| 8403 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8404 | #endif |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 8405 | if (dynamic_buf_mode) { |
| 8406 | out_dynamic_list = (struct dynamic_buf_list *) \ |
| 8407 | calloc (sizeof(struct dynamic_buf_list), drv_ctx.op_buf.actualcount); |
| 8408 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8409 | if (m_out_mem_ptr && pPtr && drv_ctx.ptr_outputbuffer |
| 8410 | && drv_ctx.ptr_respbuffer) { |
| 8411 | bufHdr = m_out_mem_ptr; |
| 8412 | m_platform_list = (OMX_QCOM_PLATFORM_PRIVATE_LIST *)(pPtr); |
| 8413 | m_platform_entry= (OMX_QCOM_PLATFORM_PRIVATE_ENTRY *) |
| 8414 | (((char *) m_platform_list) + nPlatformListSize); |
| 8415 | m_pmem_info = (OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *) |
| 8416 | (((char *) m_platform_entry) + nPlatformEntrySize); |
| 8417 | pPlatformList = m_platform_list; |
| 8418 | pPlatformEntry = m_platform_entry; |
| 8419 | pPMEMInfo = m_pmem_info; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8420 | |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8421 | 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] | 8422 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8423 | // Settting the entire storage nicely |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8424 | DEBUG_PRINT_LOW("bHdr %p OutMem %p PE %p",bufHdr, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8425 | m_out_mem_ptr,pPlatformEntry); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8426 | DEBUG_PRINT_LOW(" Pmem Info = %p",pPMEMInfo); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8427 | for (i=0; i < drv_ctx.op_buf.actualcount ; i++) { |
| 8428 | bufHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 8429 | bufHdr->nVersion.nVersion = OMX_SPEC_VERSION; |
| 8430 | // Set the values when we determine the right HxW param |
| 8431 | bufHdr->nAllocLen = 0; |
| 8432 | bufHdr->nFilledLen = 0; |
| 8433 | bufHdr->pAppPrivate = NULL; |
| 8434 | bufHdr->nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 8435 | pPlatformEntry->type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 8436 | pPlatformEntry->entry = pPMEMInfo; |
| 8437 | // Initialize the Platform List |
| 8438 | pPlatformList->nEntries = 1; |
| 8439 | pPlatformList->entryList = pPlatformEntry; |
| 8440 | // Keep pBuffer NULL till vdec is opened |
| 8441 | bufHdr->pBuffer = NULL; |
| 8442 | pPMEMInfo->offset = 0; |
| 8443 | pPMEMInfo->pmem_fd = 0; |
| 8444 | bufHdr->pPlatformPrivate = pPlatformList; |
| 8445 | drv_ctx.ptr_outputbuffer[i].pmem_fd = -1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8446 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8447 | drv_ctx.op_buf_ion_info[i].ion_device_fd =-1; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8448 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8449 | /*Create a mapping between buffers*/ |
| 8450 | bufHdr->pOutputPortPrivate = &drv_ctx.ptr_respbuffer[i]; |
| 8451 | drv_ctx.ptr_respbuffer[i].client_data = (void *) \ |
| 8452 | &drv_ctx.ptr_outputbuffer[i]; |
| 8453 | // Move the buffer and buffer header pointers |
| 8454 | bufHdr++; |
| 8455 | pPMEMInfo++; |
| 8456 | pPlatformEntry++; |
| 8457 | pPlatformList++; |
| 8458 | } |
| 8459 | } else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8460 | DEBUG_PRINT_ERROR("Output buf mem alloc failed[0x%p][0x%p]",\ |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8461 | m_out_mem_ptr, pPtr); |
| 8462 | if (m_out_mem_ptr) { |
| 8463 | free(m_out_mem_ptr); |
| 8464 | m_out_mem_ptr = NULL; |
| 8465 | } |
| 8466 | if (pPtr) { |
| 8467 | free(pPtr); |
| 8468 | pPtr = NULL; |
| 8469 | } |
| 8470 | if (drv_ctx.ptr_outputbuffer) { |
| 8471 | free(drv_ctx.ptr_outputbuffer); |
| 8472 | drv_ctx.ptr_outputbuffer = NULL; |
| 8473 | } |
| 8474 | if (drv_ctx.ptr_respbuffer) { |
| 8475 | free(drv_ctx.ptr_respbuffer); |
| 8476 | drv_ctx.ptr_respbuffer = NULL; |
| 8477 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8478 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8479 | if (drv_ctx.op_buf_ion_info) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8480 | DEBUG_PRINT_LOW("Free o/p ion context"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8481 | free(drv_ctx.op_buf_ion_info); |
| 8482 | drv_ctx.op_buf_ion_info = NULL; |
| 8483 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8484 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8485 | eRet = OMX_ErrorInsufficientResources; |
| 8486 | } |
| 8487 | } else { |
| 8488 | eRet = OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8489 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8490 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8491 | } |
| 8492 | |
| 8493 | void omx_vdec::complete_pending_buffer_done_cbs() |
| 8494 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8495 | unsigned p1; |
| 8496 | unsigned p2; |
| 8497 | unsigned ident; |
| 8498 | omx_cmd_queue tmp_q, pending_bd_q; |
| 8499 | pthread_mutex_lock(&m_lock); |
| 8500 | // pop all pending GENERATE FDB from ftb queue |
| 8501 | while (m_ftb_q.m_size) { |
| 8502 | m_ftb_q.pop_entry(&p1,&p2,&ident); |
| 8503 | if (ident == OMX_COMPONENT_GENERATE_FBD) { |
| 8504 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8505 | } else { |
| 8506 | tmp_q.insert_entry(p1,p2,ident); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8507 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8508 | } |
| 8509 | //return all non GENERATE FDB to ftb queue |
| 8510 | while (tmp_q.m_size) { |
| 8511 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8512 | m_ftb_q.insert_entry(p1,p2,ident); |
| 8513 | } |
| 8514 | // pop all pending GENERATE EDB from etb queue |
| 8515 | while (m_etb_q.m_size) { |
| 8516 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 8517 | if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 8518 | pending_bd_q.insert_entry(p1,p2,ident); |
| 8519 | } else { |
| 8520 | tmp_q.insert_entry(p1,p2,ident); |
| 8521 | } |
| 8522 | } |
| 8523 | //return all non GENERATE FDB to etb queue |
| 8524 | while (tmp_q.m_size) { |
| 8525 | tmp_q.pop_entry(&p1,&p2,&ident); |
| 8526 | m_etb_q.insert_entry(p1,p2,ident); |
| 8527 | } |
| 8528 | pthread_mutex_unlock(&m_lock); |
| 8529 | // process all pending buffer dones |
| 8530 | while (pending_bd_q.m_size) { |
| 8531 | pending_bd_q.pop_entry(&p1,&p2,&ident); |
| 8532 | switch (ident) { |
| 8533 | case OMX_COMPONENT_GENERATE_EBD: |
| 8534 | if (empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8535 | DEBUG_PRINT_ERROR("ERROR: empty_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8536 | omx_report_error (); |
| 8537 | } |
| 8538 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8539 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8540 | case OMX_COMPONENT_GENERATE_FBD: |
| 8541 | if (fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone ) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8542 | DEBUG_PRINT_ERROR("ERROR: fill_buffer_done() failed!"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8543 | omx_report_error (); |
| 8544 | } |
| 8545 | break; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8546 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8547 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8548 | } |
| 8549 | |
| 8550 | void omx_vdec::set_frame_rate(OMX_S64 act_timestamp) |
| 8551 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8552 | OMX_U32 new_frame_interval = 0; |
| 8553 | if (VALID_TS(act_timestamp) && VALID_TS(prev_ts) && act_timestamp != prev_ts |
| 8554 | && llabs(act_timestamp - prev_ts) > 2000) { |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 8555 | new_frame_interval = client_set_fps ? frm_int : (act_timestamp - prev_ts) > 0 ? |
| 8556 | llabs(act_timestamp - prev_ts) : llabs(act_timestamp - prev_ts_actual); |
Arun Menon | d9e49f8 | 2014-04-23 18:50:26 -0700 | [diff] [blame] | 8557 | if (new_frame_interval != frm_int || frm_int == 0) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8558 | frm_int = new_frame_interval; |
| 8559 | if (frm_int) { |
| 8560 | drv_ctx.frame_rate.fps_numerator = 1e6; |
| 8561 | drv_ctx.frame_rate.fps_denominator = frm_int; |
| 8562 | DEBUG_PRINT_LOW("set_frame_rate: frm_int(%lu) fps(%f)", |
| 8563 | frm_int, drv_ctx.frame_rate.fps_numerator / |
| 8564 | (float)drv_ctx.frame_rate.fps_denominator); |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8565 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8566 | /* We need to report the difference between this FBD and the previous FBD |
| 8567 | * back to the driver for clock scaling purposes. */ |
| 8568 | struct v4l2_outputparm oparm; |
| 8569 | /*XXX: we're providing timing info as seconds per frame rather than frames |
| 8570 | * per second.*/ |
| 8571 | oparm.timeperframe.numerator = drv_ctx.frame_rate.fps_denominator; |
| 8572 | oparm.timeperframe.denominator = drv_ctx.frame_rate.fps_numerator; |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8573 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8574 | struct v4l2_streamparm sparm; |
| 8575 | sparm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 8576 | sparm.parm.output = oparm; |
| 8577 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_PARM, &sparm)) { |
| 8578 | DEBUG_PRINT_ERROR("Unable to convey fps info to driver, \ |
| 8579 | performance might be affected"); |
| 8580 | } |
| 8581 | |
| 8582 | } |
Deva Ramasubramanian | e47e05b | 2013-04-24 15:23:29 -0700 | [diff] [blame] | 8583 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8584 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8585 | prev_ts = act_timestamp; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8586 | } |
| 8587 | |
| 8588 | void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp) |
| 8589 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8590 | if (rst_prev_ts && VALID_TS(act_timestamp)) { |
| 8591 | prev_ts = act_timestamp; |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 8592 | prev_ts_actual = act_timestamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8593 | rst_prev_ts = false; |
| 8594 | } else if (VALID_TS(prev_ts)) { |
| 8595 | bool codec_cond = (drv_ctx.timestamp_adjust)? |
Ashray Kulkarni | 6ecd037 | 2015-09-02 17:51:20 -0700 | [diff] [blame] | 8596 | (!VALID_TS(act_timestamp) || act_timestamp < prev_ts_actual || llabs(act_timestamp - prev_ts_actual) <= 2000) : |
| 8597 | (!VALID_TS(act_timestamp) || act_timestamp <= prev_ts_actual); |
| 8598 | prev_ts_actual = act_timestamp; //unadjusted previous timestamp |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8599 | if (frm_int > 0 && codec_cond) { |
| 8600 | DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp); |
| 8601 | act_timestamp = prev_ts + frm_int; |
| 8602 | DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp); |
| 8603 | prev_ts = act_timestamp; |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8604 | } else { |
| 8605 | if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) { |
| 8606 | // ensure that timestamps can never step backwards when in display order |
| 8607 | act_timestamp = prev_ts; |
| 8608 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8609 | set_frame_rate(act_timestamp); |
Leena Winterrowd | d139fdc | 2014-08-05 18:04:25 -0700 | [diff] [blame] | 8610 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8611 | } else if (frm_int > 0) // In this case the frame rate was set along |
| 8612 | { // with the port definition, start ts with 0 |
| 8613 | act_timestamp = prev_ts = 0; // and correct if a valid ts is received. |
| 8614 | rst_prev_ts = true; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8615 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8616 | } |
| 8617 | |
| 8618 | void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 8619 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8620 | OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL; |
| 8621 | OMX_U32 num_conceal_MB = 0; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8622 | OMX_TICKS time_stamp = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8623 | OMX_U32 frame_rate = 0; |
| 8624 | int consumed_len = 0; |
| 8625 | OMX_U32 num_MB_in_frame; |
| 8626 | OMX_U32 recovery_sei_flags = 1; |
| 8627 | int enable = 0; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8628 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8629 | int buf_index = p_buf_hdr - m_out_mem_ptr; |
Praveen Chavan | 61e5d16 | 2013-11-01 02:49:19 -0700 | [diff] [blame] | 8630 | if (buf_index >= drv_ctx.extradata_info.count) { |
| 8631 | DEBUG_PRINT_ERROR("handle_extradata: invalid index(%d) max(%d)", |
| 8632 | buf_index, drv_ctx.extradata_info.count); |
| 8633 | return; |
| 8634 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8635 | struct msm_vidc_panscan_window_payload *panscan_payload = NULL; |
| 8636 | OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) + |
| 8637 | p_buf_hdr->nOffset; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8638 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8639 | if (!drv_ctx.extradata_info.uaddr) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8640 | DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8641 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8642 | } |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8643 | |
| 8644 | if (!secure_mode && (drv_ctx.extradata_info.buffer_size > (p_buf_hdr->nAllocLen - p_buf_hdr->nFilledLen)) ) { |
| 8645 | DEBUG_PRINT_ERROR("Error: Insufficient size allocated for extra-data"); |
| 8646 | p_extra = NULL; |
| 8647 | return; |
| 8648 | } |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8649 | if (!secure_mode) |
| 8650 | p_extra = (OMX_OTHER_EXTRADATATYPE *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8651 | ((unsigned)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3)); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8652 | else |
| 8653 | p_extra = m_other_extradata; |
| 8654 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8655 | 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] | 8656 | if (!secure_mode && ((OMX_U8*)p_extra > (pBuffer + p_buf_hdr->nAllocLen))) { |
| 8657 | DEBUG_PRINT_ERROR("Error: out of bound memory access by p_extra"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8658 | p_extra = NULL; |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8659 | return; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8660 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8661 | OMX_OTHER_EXTRADATATYPE *data = (struct OMX_OTHER_EXTRADATATYPE *)p_extradata; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8662 | if (data && p_extra) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8663 | while ((consumed_len < drv_ctx.extradata_info.buffer_size) |
| 8664 | && (data->eType != (OMX_EXTRADATATYPE)EXTRADATA_NONE)) { |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 8665 | if ((consumed_len + data->nSize) > (unsigned)drv_ctx.extradata_info.buffer_size) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8666 | DEBUG_PRINT_LOW("Invalid extra data size"); |
| 8667 | break; |
| 8668 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8669 | DEBUG_PRINT_LOW("handle_extradata: eType = %d", data->eType); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8670 | switch ((unsigned long)data->eType) { |
| 8671 | case EXTRADATA_INTERLACE_VIDEO: |
| 8672 | struct msm_vidc_interlace_payload *payload; |
| 8673 | payload = (struct msm_vidc_interlace_payload *)data->data; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8674 | if (payload) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8675 | enable = 1; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8676 | switch (payload->format) { |
| 8677 | case INTERLACE_FRAME_PROGRESSIVE: |
| 8678 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
| 8679 | enable = 0; |
| 8680 | break; |
| 8681 | case INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST: |
| 8682 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8683 | break; |
| 8684 | case INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST: |
| 8685 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameBottomFieldFirst; |
| 8686 | break; |
| 8687 | default: |
| 8688 | DEBUG_PRINT_LOW("default case - set interlace to topfield"); |
| 8689 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 8690 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8691 | } |
| 8692 | if (m_enable_android_native_buffers) |
| 8693 | setMetaData((private_handle_t *)native_buffer[buf_index].privatehandle, |
| 8694 | PP_PARAM_INTERLACED, (void*)&enable); |
Pushkaraj Patil | 0ddb2e0 | 2013-11-12 11:53:58 +0530 | [diff] [blame] | 8695 | if (client_extradata & OMX_INTERLACE_EXTRADATA) { |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 8696 | append_interlace_extradata(p_extra, payload->format, |
| 8697 | p_buf_hdr->nFlags & QOMX_VIDEO_BUFFERFLAG_MBAFF); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8698 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8699 | } |
| 8700 | break; |
| 8701 | case EXTRADATA_FRAME_RATE: |
| 8702 | struct msm_vidc_framerate_payload *frame_rate_payload; |
| 8703 | frame_rate_payload = (struct msm_vidc_framerate_payload *)data->data; |
| 8704 | frame_rate = frame_rate_payload->frame_rate; |
| 8705 | break; |
| 8706 | case EXTRADATA_TIMESTAMP: |
| 8707 | struct msm_vidc_ts_payload *time_stamp_payload; |
| 8708 | time_stamp_payload = (struct msm_vidc_ts_payload *)data->data; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8709 | time_stamp = time_stamp_payload->timestamp_lo; |
| 8710 | time_stamp |= ((unsigned long long)time_stamp_payload->timestamp_hi << 32); |
| 8711 | p_buf_hdr->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8712 | break; |
| 8713 | case EXTRADATA_NUM_CONCEALED_MB: |
| 8714 | struct msm_vidc_concealmb_payload *conceal_mb_payload; |
| 8715 | conceal_mb_payload = (struct msm_vidc_concealmb_payload *)data->data; |
| 8716 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8717 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8718 | num_conceal_MB = ((num_MB_in_frame > 0)?(conceal_mb_payload->num_mbs * 100 / num_MB_in_frame) : 0); |
| 8719 | break; |
| 8720 | case EXTRADATA_INDEX: |
| 8721 | int *etype; |
| 8722 | etype = (int *)(data->data); |
| 8723 | if (etype && *etype == EXTRADATA_ASPECT_RATIO) { |
| 8724 | struct msm_vidc_aspect_ratio_payload *aspect_ratio_payload; |
| 8725 | aspect_ratio_payload = (struct msm_vidc_aspect_ratio_payload *)(++etype); |
| 8726 | if (aspect_ratio_payload) { |
| 8727 | ((struct vdec_output_frameinfo *) |
| 8728 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_width = aspect_ratio_payload->aspect_width; |
| 8729 | ((struct vdec_output_frameinfo *) |
| 8730 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info.par_height = aspect_ratio_payload->aspect_height; |
| 8731 | } |
| 8732 | } |
| 8733 | break; |
| 8734 | case EXTRADATA_RECOVERY_POINT_SEI: |
| 8735 | struct msm_vidc_recoverysei_payload *recovery_sei_payload; |
| 8736 | recovery_sei_payload = (struct msm_vidc_recoverysei_payload *)data->data; |
| 8737 | recovery_sei_flags = recovery_sei_payload->flags; |
| 8738 | if (recovery_sei_flags != FRAME_RECONSTRUCTION_CORRECT) { |
| 8739 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8740 | DEBUG_PRINT_HIGH(""); |
| 8741 | DEBUG_PRINT_HIGH("***************************************************"); |
| 8742 | DEBUG_PRINT_HIGH("FillBufferDone: OMX_BUFFERFLAG_DATACORRUPT Received"); |
| 8743 | DEBUG_PRINT_HIGH("***************************************************"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8744 | } |
| 8745 | break; |
| 8746 | case EXTRADATA_PANSCAN_WINDOW: |
| 8747 | panscan_payload = (struct msm_vidc_panscan_window_payload *)data->data; |
| 8748 | break; |
| 8749 | case EXTRADATA_MPEG2_SEQDISP: |
| 8750 | struct msm_vidc_mpeg2_seqdisp_payload *seqdisp_payload; |
| 8751 | seqdisp_payload = (struct msm_vidc_mpeg2_seqdisp_payload *)data->data; |
| 8752 | if (seqdisp_payload) { |
| 8753 | m_disp_hor_size = seqdisp_payload->disp_width; |
| 8754 | m_disp_vert_size = seqdisp_payload->disp_height; |
| 8755 | } |
| 8756 | break; |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8757 | case EXTRADATA_S3D_FRAME_PACKING: |
| 8758 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload; |
| 8759 | s3d_frame_packing_payload = (struct msm_vidc_s3d_frame_packing_payload *)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8760 | if (client_extradata & OMX_FRAMEPACK_EXTRADATA) { |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8761 | append_framepack_extradata(p_extra, s3d_frame_packing_payload); |
| 8762 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8763 | } |
| 8764 | break; |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8765 | case EXTRADATA_FRAME_QP: |
| 8766 | struct msm_vidc_frame_qp_payload *qp_payload; |
| 8767 | qp_payload = (struct msm_vidc_frame_qp_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8768 | if (client_extradata & OMX_QP_EXTRADATA) { |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8769 | append_qp_extradata(p_extra, qp_payload); |
| 8770 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8771 | } |
| 8772 | break; |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8773 | case EXTRADATA_FRAME_BITS_INFO: |
| 8774 | struct msm_vidc_frame_bits_info_payload *bits_info_payload; |
| 8775 | bits_info_payload = (struct msm_vidc_frame_bits_info_payload*)data->data; |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8776 | if (client_extradata & OMX_BITSINFO_EXTRADATA) { |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8777 | append_bitsinfo_extradata(p_extra, bits_info_payload); |
| 8778 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8779 | } |
| 8780 | break; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8781 | case EXTRADATA_STREAM_USERDATA: |
Pushkaraj Patil | 74b2eaf | 2014-06-13 17:07:50 +0530 | [diff] [blame] | 8782 | if (client_extradata & OMX_EXTNUSER_EXTRADATA) { |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8783 | append_user_extradata(p_extra, data); |
| 8784 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
| 8785 | } |
| 8786 | break; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8787 | default: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8788 | DEBUG_PRINT_LOW("Unrecognized extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8789 | goto unrecognized_extradata; |
| 8790 | } |
| 8791 | consumed_len += data->nSize; |
| 8792 | data = (OMX_OTHER_EXTRADATATYPE *)((char *)data + data->nSize); |
| 8793 | } |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8794 | if (client_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8795 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
| 8796 | append_frame_info_extradata(p_extra, |
| 8797 | num_conceal_MB, ((struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate)->pic_type, frame_rate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8798 | time_stamp, panscan_payload,&((struct vdec_output_frameinfo *) |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8799 | p_buf_hdr->pOutputPortPrivate)->aspect_ratio_info); |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 8800 | p_extra = (OMX_OTHER_EXTRADATATYPE *) (((OMX_U8 *) p_extra) + p_extra->nSize); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8801 | } |
| 8802 | } |
Vinay Kalia | 0e75e9a | 2012-09-27 15:41:53 -0700 | [diff] [blame] | 8803 | unrecognized_extradata: |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8804 | if (client_extradata && p_extra) { |
| 8805 | p_buf_hdr->nFlags |= OMX_BUFFERFLAG_EXTRADATA; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8806 | append_terminator_extradata(p_extra); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8807 | } |
| 8808 | |
Arun Menon | fd72393 | 2014-05-30 17:56:31 -0700 | [diff] [blame] | 8809 | if (secure_mode && p_extradata && m_other_extradata) { |
Srinu Gorle | 2eb94e4 | 2014-02-14 13:37:40 +0530 | [diff] [blame] | 8810 | struct vdec_output_frameinfo *ptr_extradatabuff = NULL; |
| 8811 | memcpy(p_extradata, m_other_extradata, drv_ctx.extradata_info.buffer_size); |
| 8812 | ptr_extradatabuff = (struct vdec_output_frameinfo *)p_buf_hdr->pOutputPortPrivate; |
| 8813 | ptr_extradatabuff->metadata_info.metabufaddr = (void *)p_extradata; |
| 8814 | ptr_extradatabuff->metadata_info.size = drv_ctx.extradata_info.buffer_size; |
| 8815 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8816 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8817 | } |
| 8818 | |
Vinay Kalia | 9c00cae | 2012-12-06 16:08:20 -0800 | [diff] [blame] | 8819 | OMX_ERRORTYPE omx_vdec::enable_extradata(OMX_U32 requested_extradata, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8820 | bool is_internal, bool enable) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8821 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8822 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 8823 | struct v4l2_control control; |
| 8824 | if (m_state != OMX_StateLoaded) { |
| 8825 | DEBUG_PRINT_ERROR("ERROR: enable extradata allowed in Loaded state only"); |
| 8826 | return OMX_ErrorIncorrectStateOperation; |
Vinay Kalia | db90f8c | 2012-11-19 18:57:56 -0800 | [diff] [blame] | 8827 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8828 | 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] | 8829 | client_extradata, requested_extradata, enable, is_internal); |
| 8830 | |
| 8831 | if (!is_internal) { |
| 8832 | if (enable) |
| 8833 | client_extradata |= requested_extradata; |
| 8834 | else |
| 8835 | client_extradata = client_extradata & ~requested_extradata; |
| 8836 | } |
| 8837 | |
| 8838 | if (enable) { |
| 8839 | if (requested_extradata & OMX_INTERLACE_EXTRADATA) { |
| 8840 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8841 | control.value = V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO; |
| 8842 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8843 | DEBUG_PRINT_HIGH("Failed to set interlaced extradata." |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8844 | " Quality of interlaced clips might be impacted."); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8845 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8846 | } |
| 8847 | if (requested_extradata & OMX_FRAMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8848 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8849 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE; |
| 8850 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8851 | DEBUG_PRINT_HIGH("Failed to set framerate extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8852 | } |
| 8853 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8854 | control.value = V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB; |
| 8855 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8856 | DEBUG_PRINT_HIGH("Failed to set concealed MB extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8857 | } |
| 8858 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8859 | control.value = V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI; |
| 8860 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8861 | DEBUG_PRINT_HIGH("Failed to set recovery point SEI extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8862 | } |
| 8863 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8864 | control.value = V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW; |
| 8865 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8866 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8867 | } |
| 8868 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8869 | control.value = V4L2_MPEG_VIDC_INDEX_EXTRADATA_ASPECT_RATIO; |
| 8870 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8871 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8872 | } |
| 8873 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 8874 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8875 | control.value = V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP; |
| 8876 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8877 | DEBUG_PRINT_HIGH("Failed to set panscan extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8878 | } |
| 8879 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8880 | } |
| 8881 | if (requested_extradata & OMX_TIMEINFO_EXTRADATA) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8882 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8883 | control.value = V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP; |
| 8884 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8885 | DEBUG_PRINT_HIGH("Failed to set timeinfo extradata"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8886 | } |
| 8887 | } |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 8888 | if (requested_extradata & OMX_FRAMEPACK_EXTRADATA) { |
| 8889 | if (output_capability == V4L2_PIX_FMT_H264) { |
| 8890 | DEBUG_PRINT_HIGH("enable OMX_FRAMEPACK_EXTRADATA"); |
| 8891 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8892 | control.value = V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING; |
| 8893 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8894 | DEBUG_PRINT_HIGH("Failed to set S3D_FRAME_PACKING extradata"); |
| 8895 | } |
| 8896 | } else { |
| 8897 | DEBUG_PRINT_HIGH("OMX_FRAMEPACK_EXTRADATA supported for H264 only"); |
| 8898 | } |
| 8899 | } |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 8900 | if (requested_extradata & OMX_QP_EXTRADATA) { |
| 8901 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8902 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP; |
| 8903 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8904 | DEBUG_PRINT_HIGH("Failed to set QP extradata"); |
| 8905 | } |
| 8906 | } |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 8907 | if (requested_extradata & OMX_BITSINFO_EXTRADATA) { |
| 8908 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8909 | control.value = V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO; |
| 8910 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8911 | DEBUG_PRINT_HIGH("Failed to set frame bits info extradata"); |
| 8912 | } |
| 8913 | } |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 8914 | if (requested_extradata & OMX_EXTNUSER_EXTRADATA) { |
| 8915 | control.id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA; |
| 8916 | control.value = V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA; |
| 8917 | if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) { |
| 8918 | DEBUG_PRINT_HIGH("Failed to set stream userdata extradata"); |
| 8919 | } |
| 8920 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8921 | } |
| 8922 | ret = get_buffer_req(&drv_ctx.op_buf); |
| 8923 | return ret; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8924 | } |
| 8925 | |
| 8926 | OMX_U32 omx_vdec::count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8927 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8928 | OMX_U32 num_MB = 0, byte_count = 0, num_MB_in_frame = 0; |
| 8929 | OMX_U8 *data_ptr = extra->data, data = 0; |
| 8930 | while (byte_count < extra->nDataSize) { |
| 8931 | data = *data_ptr; |
| 8932 | while (data) { |
| 8933 | num_MB += (data&0x01); |
| 8934 | data >>= 1; |
| 8935 | } |
| 8936 | data_ptr++; |
| 8937 | byte_count++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8938 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8939 | num_MB_in_frame = ((drv_ctx.video_resolution.frame_width + 15) * |
| 8940 | (drv_ctx.video_resolution.frame_height + 15)) >> 8; |
| 8941 | return ((num_MB_in_frame > 0)?(num_MB * 100 / num_MB_in_frame) : 0); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8942 | } |
| 8943 | |
| 8944 | void omx_vdec::print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 8945 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8946 | if (!m_debug_extradata) |
| 8947 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8948 | |
| 8949 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8950 | "============== Extra Data ==============\n" |
| 8951 | " Size: %lu\n" |
| 8952 | " Version: %lu\n" |
| 8953 | " PortIndex: %lu\n" |
| 8954 | " Type: %x\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8955 | " DataSize: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8956 | extra->nSize, extra->nVersion.nVersion, |
| 8957 | extra->nPortIndex, extra->eType, extra->nDataSize); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 8958 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8959 | if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat) { |
| 8960 | OMX_STREAMINTERLACEFORMAT *intfmt = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 8961 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8962 | "------ Interlace Format ------\n" |
| 8963 | " Size: %lu\n" |
| 8964 | " Version: %lu\n" |
| 8965 | " PortIndex: %lu\n" |
| 8966 | " Is Interlace Format: %d\n" |
| 8967 | " Interlace Formats: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8968 | "=========== End of Interlace ===========", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8969 | intfmt->nSize, intfmt->nVersion.nVersion, intfmt->nPortIndex, |
| 8970 | intfmt->bInterlaceFormat, intfmt->nInterlaceFormats); |
| 8971 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo) { |
| 8972 | OMX_QCOM_EXTRADATA_FRAMEINFO *fminfo = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 8973 | |
| 8974 | DEBUG_PRINT_HIGH( |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8975 | "-------- Frame Format --------\n" |
| 8976 | " Picture Type: %d\n" |
| 8977 | " Interlace Type: %d\n" |
| 8978 | " Pan Scan Total Frame Num: %lu\n" |
| 8979 | " Concealed Macro Blocks: %lu\n" |
| 8980 | " frame rate: %lu\n" |
| 8981 | " Time Stamp: %llu\n" |
| 8982 | " Aspect Ratio X: %lu\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8983 | " Aspect Ratio Y: %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8984 | fminfo->ePicType, |
| 8985 | fminfo->interlaceType, |
| 8986 | fminfo->panScan.numWindows, |
| 8987 | fminfo->nConcealedMacroblocks, |
| 8988 | fminfo->nFrameRate, |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 8989 | fminfo->nTimeStamp, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 8990 | fminfo->aspectRatio.aspectRatioX, |
| 8991 | fminfo->aspectRatio.aspectRatioY); |
| 8992 | |
| 8993 | for (OMX_U32 i = 0; i < fminfo->panScan.numWindows; i++) { |
| 8994 | DEBUG_PRINT_HIGH( |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 8995 | "------------------------------" |
Deepak Verma | 867d513 | 2013-12-05 12:23:20 +0530 | [diff] [blame] | 8996 | " Pan Scan Frame Num: %lu\n" |
| 8997 | " Rectangle x: %ld\n" |
| 8998 | " Rectangle y: %ld\n" |
| 8999 | " Rectangle dx: %ld\n" |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9000 | " Rectangle dy: %ld", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9001 | i, fminfo->panScan.window[i].x, fminfo->panScan.window[i].y, |
| 9002 | fminfo->panScan.window[i].dx, fminfo->panScan.window[i].dy); |
| 9003 | } |
| 9004 | |
| 9005 | DEBUG_PRINT_HIGH("========= End of Frame Format =========="); |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 9006 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement) { |
| 9007 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 9008 | DEBUG_PRINT_HIGH( |
| 9009 | "------------------ Framepack Format ----------\n" |
| 9010 | " id: %lu \n" |
| 9011 | " cancel_flag: %lu \n" |
| 9012 | " type: %lu \n" |
| 9013 | " quincunx_sampling_flagFormat: %lu \n" |
| 9014 | " content_interpretation_type: %lu \n" |
| 9015 | " content_interpretation_type: %lu \n" |
| 9016 | " spatial_flipping_flag: %lu \n" |
| 9017 | " frame0_flipped_flag: %lu \n" |
| 9018 | " field_views_flag: %lu \n" |
| 9019 | " current_frame_is_frame0_flag: %lu \n" |
| 9020 | " frame0_self_contained_flag: %lu \n" |
| 9021 | " frame1_self_contained_flag: %lu \n" |
| 9022 | " frame0_grid_position_x: %lu \n" |
| 9023 | " frame0_grid_position_y: %lu \n" |
| 9024 | " frame1_grid_position_x: %lu \n" |
| 9025 | " frame1_grid_position_y: %lu \n" |
| 9026 | " reserved_byte: %lu \n" |
| 9027 | " repetition_period: %lu \n" |
| 9028 | " extension_flag: %lu \n" |
| 9029 | "================== End of Framepack ===========", |
| 9030 | framepack->id, |
| 9031 | framepack->cancel_flag, |
| 9032 | framepack->type, |
| 9033 | framepack->quincunx_sampling_flag, |
| 9034 | framepack->content_interpretation_type, |
| 9035 | framepack->spatial_flipping_flag, |
| 9036 | framepack->frame0_flipped_flag, |
| 9037 | framepack->field_views_flag, |
| 9038 | framepack->current_frame_is_frame0_flag, |
| 9039 | framepack->frame0_self_contained_flag, |
| 9040 | framepack->frame1_self_contained_flag, |
| 9041 | framepack->frame0_grid_position_x, |
| 9042 | framepack->frame0_grid_position_y, |
| 9043 | framepack->frame1_grid_position_x, |
| 9044 | framepack->frame1_grid_position_y, |
| 9045 | framepack->reserved_byte, |
| 9046 | framepack->repetition_period, |
| 9047 | framepack->extension_flag); |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 9048 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataQP) { |
| 9049 | OMX_QCOM_EXTRADATA_QP * qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 9050 | DEBUG_PRINT_HIGH( |
| 9051 | "---- QP (Frame quantization parameter) ----\n" |
| 9052 | " Frame QP: %lu \n" |
| 9053 | "================ End of QP ================\n", |
| 9054 | qp->nQP); |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 9055 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo) { |
| 9056 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = (OMX_QCOM_EXTRADATA_BITS_INFO *)extra->data; |
| 9057 | DEBUG_PRINT_HIGH( |
| 9058 | "--------- Input bits information --------\n" |
| 9059 | " Header bits: %lu \n" |
| 9060 | " Frame bits: %lu \n" |
| 9061 | "===== End of Input bits information =====\n", |
| 9062 | bits->header_bits, bits->frame_bits); |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9063 | } else if (extra->eType == (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData) { |
| 9064 | OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)extra->data; |
| 9065 | OMX_U8 *data_ptr = (OMX_U8 *)userdata->data; |
| 9066 | OMX_U32 userdata_size = extra->nDataSize - sizeof(userdata->type); |
| 9067 | OMX_U32 i = 0; |
| 9068 | DEBUG_PRINT_HIGH( |
| 9069 | "-------------- Userdata -------------\n" |
| 9070 | " Stream userdata type: %d\n" |
| 9071 | " userdata size: %d\n" |
| 9072 | " STREAM_USERDATA:", |
| 9073 | userdata->type, userdata_size); |
| 9074 | for (i = 0; i < userdata_size; i+=4) { |
| 9075 | DEBUG_PRINT_HIGH(" %x %x %x %x", |
| 9076 | data_ptr[i], data_ptr[i+1], |
| 9077 | data_ptr[i+2], data_ptr[i+3]); |
| 9078 | } |
| 9079 | DEBUG_PRINT_HIGH( |
| 9080 | "=========== End of Userdata ==========="); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9081 | } else if (extra->eType == OMX_ExtraDataNone) { |
| 9082 | DEBUG_PRINT_HIGH("========== End of Terminator ==========="); |
| 9083 | } else { |
| 9084 | DEBUG_PRINT_HIGH("======= End of Driver Extradata ========"); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9085 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | void omx_vdec::append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9089 | OMX_U32 interlaced_format_type, bool is_mbaff) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9090 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9091 | OMX_STREAMINTERLACEFORMAT *interlace_format; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9092 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9093 | if (!(client_extradata & OMX_INTERLACE_EXTRADATA)) { |
| 9094 | return; |
| 9095 | } |
| 9096 | extra->nSize = OMX_INTERLACE_EXTRADATA_SIZE; |
| 9097 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9098 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9099 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInterlaceFormat; |
| 9100 | extra->nDataSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 9101 | interlace_format = (OMX_STREAMINTERLACEFORMAT *)extra->data; |
| 9102 | interlace_format->nSize = sizeof(OMX_STREAMINTERLACEFORMAT); |
| 9103 | interlace_format->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9104 | interlace_format->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9105 | |
| 9106 | if ((interlaced_format_type == INTERLACE_FRAME_PROGRESSIVE) && !is_mbaff) { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9107 | interlace_format->bInterlaceFormat = OMX_FALSE; |
| 9108 | interlace_format->nInterlaceFormats = OMX_InterlaceFrameProgressive; |
| 9109 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9110 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_TOPFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9111 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9112 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9113 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9114 | } else if ((interlaced_format_type == INTERLACE_INTERLEAVE_FRAME_BOTTOMFIELDFIRST) && !is_mbaff) { |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9115 | interlace_format->bInterlaceFormat = OMX_TRUE; |
Arun Menon | 7b6fd64 | 2014-02-13 16:48:36 -0800 | [diff] [blame] | 9116 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameBottomFieldFirst; |
Praneeth Paladugu | dd29c28 | 2013-09-12 15:41:47 -0700 | [diff] [blame] | 9117 | drv_ctx.interlace = VDEC_InterlaceFrameProgressive; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9118 | } else { |
| 9119 | interlace_format->bInterlaceFormat = OMX_TRUE; |
| 9120 | interlace_format->nInterlaceFormats = OMX_InterlaceInterleaveFrameTopFieldFirst; |
| 9121 | drv_ctx.interlace = VDEC_InterlaceInterleaveFrameTopFieldFirst; |
| 9122 | } |
| 9123 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9124 | } |
| 9125 | |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9126 | void omx_vdec::fill_aspect_ratio_info( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9127 | struct vdec_aspectratioinfo *aspect_ratio_info, |
| 9128 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info) |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9129 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9130 | m_extradata = frame_info; |
| 9131 | m_extradata->aspectRatio.aspectRatioX = aspect_ratio_info->par_width; |
| 9132 | m_extradata->aspectRatio.aspectRatioY = aspect_ratio_info->par_height; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9133 | DEBUG_PRINT_LOW("aspectRatioX %lu aspectRatioY %lu", m_extradata->aspectRatio.aspectRatioX, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9134 | m_extradata->aspectRatio.aspectRatioY); |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9135 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9136 | |
| 9137 | void omx_vdec::append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9138 | 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] | 9139 | OMX_TICKS time_stamp, struct msm_vidc_panscan_window_payload *panscan_payload, |
Praneeth Paladugu | f3a492b | 2013-01-03 17:35:34 -0800 | [diff] [blame] | 9140 | struct vdec_aspectratioinfo *aspect_ratio_info) |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9141 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9142 | OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info = NULL; |
| 9143 | struct msm_vidc_panscan_window *panscan_window; |
| 9144 | if (!(client_extradata & OMX_FRAMEINFO_EXTRADATA)) { |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9145 | return; |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9146 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9147 | extra->nSize = OMX_FRAMEINFO_EXTRADATA_SIZE; |
| 9148 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9149 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9150 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFrameInfo; |
| 9151 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO); |
| 9152 | frame_info = (OMX_QCOM_EXTRADATA_FRAMEINFO *)extra->data; |
| 9153 | switch (picture_type) { |
| 9154 | case PICTURE_TYPE_I: |
| 9155 | frame_info->ePicType = OMX_VIDEO_PictureTypeI; |
| 9156 | break; |
| 9157 | case PICTURE_TYPE_P: |
| 9158 | frame_info->ePicType = OMX_VIDEO_PictureTypeP; |
| 9159 | break; |
| 9160 | case PICTURE_TYPE_B: |
| 9161 | frame_info->ePicType = OMX_VIDEO_PictureTypeB; |
| 9162 | break; |
| 9163 | default: |
| 9164 | frame_info->ePicType = (OMX_VIDEO_PICTURETYPE)0; |
| 9165 | } |
| 9166 | if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst) |
| 9167 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameTopFieldFirst; |
| 9168 | else if (drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst) |
| 9169 | frame_info->interlaceType = OMX_QCOM_InterlaceInterleaveFrameBottomFieldFirst; |
| 9170 | else |
| 9171 | frame_info->interlaceType = OMX_QCOM_InterlaceFrameProgressive; |
| 9172 | memset(&frame_info->aspectRatio, 0, sizeof(frame_info->aspectRatio)); |
| 9173 | frame_info->nConcealedMacroblocks = num_conceal_mb; |
| 9174 | frame_info->nFrameRate = frame_rate; |
Rajeshwar Kurapaty | 90a9811 | 2013-09-17 16:07:14 +0530 | [diff] [blame] | 9175 | frame_info->nTimeStamp = time_stamp; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9176 | frame_info->panScan.numWindows = 0; |
| 9177 | if (output_capability == V4L2_PIX_FMT_MPEG2) { |
| 9178 | if (m_disp_hor_size && m_disp_vert_size) { |
| 9179 | frame_info->displayAspectRatio.displayHorizontalSize = m_disp_hor_size; |
| 9180 | frame_info->displayAspectRatio.displayVerticalSize = m_disp_vert_size; |
Pushkaraj Patil | 5e6ebd9 | 2014-03-10 10:29:14 +0530 | [diff] [blame] | 9181 | } else { |
| 9182 | frame_info->displayAspectRatio.displayHorizontalSize = 0; |
| 9183 | frame_info->displayAspectRatio.displayVerticalSize = 0; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9184 | } |
| 9185 | } |
Praneeth Paladugu | d0881ef | 2013-04-23 23:02:55 -0700 | [diff] [blame] | 9186 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9187 | if (panscan_payload) { |
| 9188 | frame_info->panScan.numWindows = panscan_payload->num_panscan_windows; |
| 9189 | panscan_window = &panscan_payload->wnd[0]; |
| 9190 | for (OMX_U32 i = 0; i < frame_info->panScan.numWindows; i++) { |
| 9191 | frame_info->panScan.window[i].x = panscan_window->panscan_window_width; |
| 9192 | frame_info->panScan.window[i].y = panscan_window->panscan_window_height; |
| 9193 | frame_info->panScan.window[i].dx = panscan_window->panscan_width_offset; |
| 9194 | frame_info->panScan.window[i].dy = panscan_window->panscan_height_offset; |
| 9195 | panscan_window++; |
| 9196 | } |
Praneeth Paladugu | 48a9a8a | 2012-12-06 12:12:19 -0800 | [diff] [blame] | 9197 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9198 | fill_aspect_ratio_info(aspect_ratio_info, frame_info); |
| 9199 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9200 | } |
| 9201 | |
| 9202 | void omx_vdec::append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9203 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9204 | OMX_PARAM_PORTDEFINITIONTYPE *portDefn = NULL; |
| 9205 | extra->nSize = OMX_PORTDEF_EXTRADATA_SIZE; |
| 9206 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9207 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9208 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataPortDef; |
| 9209 | extra->nDataSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
| 9210 | portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *)extra->data; |
| 9211 | *portDefn = m_port_def; |
| 9212 | DEBUG_PRINT_LOW("append_portdef_extradata height = %lu width = %lu " |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9213 | "stride = %lu sliceheight = %lu",portDefn->format.video.nFrameHeight, |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9214 | portDefn->format.video.nFrameWidth, |
| 9215 | portDefn->format.video.nStride, |
| 9216 | portDefn->format.video.nSliceHeight); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9217 | } |
| 9218 | |
Maheshwar Ajja | d2df218 | 2013-10-24 19:20:34 +0530 | [diff] [blame] | 9219 | void omx_vdec::append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9220 | struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload) |
| 9221 | { |
| 9222 | OMX_QCOM_FRAME_PACK_ARRANGEMENT *framepack; |
| 9223 | if (FRAME_PACK_SIZE*sizeof(OMX_U32) != sizeof(struct msm_vidc_s3d_frame_packing_payload)) { |
| 9224 | DEBUG_PRINT_ERROR("frame packing size mismatch"); |
| 9225 | return; |
| 9226 | } |
| 9227 | extra->nSize = OMX_FRAMEPACK_EXTRADATA_SIZE; |
| 9228 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9229 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9230 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataFramePackingArrangement; |
| 9231 | extra->nDataSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9232 | framepack = (OMX_QCOM_FRAME_PACK_ARRANGEMENT *)extra->data; |
| 9233 | framepack->nSize = sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT); |
| 9234 | framepack->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9235 | framepack->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9236 | memcpy(&framepack->id, s3d_frame_packing_payload, |
| 9237 | sizeof(struct msm_vidc_s3d_frame_packing_payload)); |
| 9238 | memcpy(&m_frame_pack_arrangement, framepack, |
| 9239 | sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT)); |
| 9240 | print_debug_extradata(extra); |
| 9241 | } |
| 9242 | |
Jorge Solano Altamirano | b10850d | 2014-01-08 11:17:58 -0800 | [diff] [blame] | 9243 | void omx_vdec::append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9244 | struct msm_vidc_frame_qp_payload *qp_payload) |
| 9245 | { |
| 9246 | OMX_QCOM_EXTRADATA_QP * qp = NULL; |
| 9247 | if (!qp_payload) { |
| 9248 | DEBUG_PRINT_ERROR("QP payload is NULL"); |
| 9249 | return; |
| 9250 | } |
| 9251 | extra->nSize = OMX_QP_EXTRADATA_SIZE; |
| 9252 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9253 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9254 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataQP; |
| 9255 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_QP); |
| 9256 | qp = (OMX_QCOM_EXTRADATA_QP *)extra->data; |
| 9257 | qp->nQP = qp_payload->frame_qp; |
| 9258 | print_debug_extradata(extra); |
| 9259 | } |
| 9260 | |
Jorge Solano Altamirano | 5433845 | 2014-01-08 11:04:57 -0800 | [diff] [blame] | 9261 | void omx_vdec::append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9262 | struct msm_vidc_frame_bits_info_payload *bits_payload) |
| 9263 | { |
| 9264 | OMX_QCOM_EXTRADATA_BITS_INFO * bits = NULL; |
| 9265 | if (!bits_payload) { |
| 9266 | DEBUG_PRINT_ERROR("bits info payload is NULL"); |
| 9267 | return; |
| 9268 | } |
| 9269 | extra->nSize = OMX_BITSINFO_EXTRADATA_SIZE; |
| 9270 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9271 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9272 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataInputBitsInfo; |
| 9273 | extra->nDataSize = sizeof(OMX_QCOM_EXTRADATA_BITS_INFO); |
| 9274 | bits = (OMX_QCOM_EXTRADATA_BITS_INFO*)extra->data; |
| 9275 | bits->frame_bits = bits_payload->frame_bits; |
| 9276 | bits->header_bits = bits_payload->header_bits; |
| 9277 | print_debug_extradata(extra); |
| 9278 | } |
| 9279 | |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9280 | void omx_vdec::append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, |
| 9281 | OMX_OTHER_EXTRADATATYPE *p_user) |
| 9282 | { |
| 9283 | int userdata_size = 0; |
| 9284 | struct msm_vidc_stream_userdata_payload *userdata_payload = NULL; |
| 9285 | userdata_payload = |
| 9286 | (struct msm_vidc_stream_userdata_payload *)p_user->data; |
| 9287 | userdata_size = p_user->nDataSize; |
Deva Ramasubramanian | 2ebfed3 | 2014-04-24 13:34:24 -0700 | [diff] [blame] | 9288 | extra->nSize = OMX_USERDATA_EXTRADATA_SIZE + p_user->nSize; |
Jorge Solano Altamirano | 1ae09be | 2014-01-16 12:21:52 -0800 | [diff] [blame] | 9289 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9290 | extra->nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9291 | extra->eType = (OMX_EXTRADATATYPE)OMX_ExtraDataMP2UserData; |
| 9292 | extra->nDataSize = userdata_size; |
| 9293 | if (extra->data && p_user->data && extra->nDataSize) |
| 9294 | memcpy(extra->data, p_user->data, extra->nDataSize); |
| 9295 | print_debug_extradata(extra); |
| 9296 | } |
| 9297 | |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9298 | void omx_vdec::append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra) |
| 9299 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9300 | if (!client_extradata) { |
| 9301 | return; |
| 9302 | } |
| 9303 | extra->nSize = sizeof(OMX_OTHER_EXTRADATATYPE); |
| 9304 | extra->nVersion.nVersion = OMX_SPEC_VERSION; |
| 9305 | extra->eType = OMX_ExtraDataNone; |
| 9306 | extra->nDataSize = 0; |
| 9307 | extra->data[0] = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9308 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9309 | print_debug_extradata(extra); |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9310 | } |
| 9311 | |
| 9312 | OMX_ERRORTYPE omx_vdec::allocate_desc_buffer(OMX_U32 index) |
| 9313 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9314 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9315 | if (index >= drv_ctx.ip_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9316 | DEBUG_PRINT_ERROR("ERROR:Desc Buffer Index not found"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9317 | return OMX_ErrorInsufficientResources; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9318 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9319 | if (m_desc_buffer_ptr == NULL) { |
| 9320 | m_desc_buffer_ptr = (desc_buffer_hdr*) \ |
| 9321 | calloc( (sizeof(desc_buffer_hdr)), |
| 9322 | drv_ctx.ip_buf.actualcount); |
| 9323 | if (m_desc_buffer_ptr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9324 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9325 | return OMX_ErrorInsufficientResources; |
| 9326 | } |
| 9327 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9328 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9329 | m_desc_buffer_ptr[index].buf_addr = (unsigned char *)malloc (DESC_BUFFER_SIZE * sizeof(OMX_U8)); |
| 9330 | if (m_desc_buffer_ptr[index].buf_addr == NULL) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9331 | DEBUG_PRINT_ERROR("desc buffer Allocation failed "); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9332 | return OMX_ErrorInsufficientResources; |
| 9333 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9334 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9335 | return eRet; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9336 | } |
| 9337 | |
| 9338 | void omx_vdec::insert_demux_addr_offset(OMX_U32 address_offset) |
| 9339 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9340 | DEBUG_PRINT_LOW("Inserting address offset (%lu) at idx (%lu)", address_offset,m_demux_entries); |
| 9341 | if (m_demux_entries < 8192) { |
| 9342 | m_demux_offsets[m_demux_entries++] = address_offset; |
| 9343 | } |
| 9344 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9345 | } |
| 9346 | |
| 9347 | void omx_vdec::extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr) |
| 9348 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9349 | OMX_U32 bytes_to_parse = buf_hdr->nFilledLen; |
| 9350 | OMX_U8 *buf = buf_hdr->pBuffer + buf_hdr->nOffset; |
| 9351 | OMX_U32 index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9352 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9353 | m_demux_entries = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9354 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9355 | while (index < bytes_to_parse) { |
| 9356 | if ( ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9357 | (buf[index+2] == 0x00) && (buf[index+3] == 0x01)) || |
| 9358 | ((buf[index] == 0x00) && (buf[index+1] == 0x00) && |
| 9359 | (buf[index+2] == 0x01)) ) { |
| 9360 | //Found start code, insert address offset |
| 9361 | insert_demux_addr_offset(index); |
| 9362 | if (buf[index+2] == 0x01) // 3 byte start code |
| 9363 | index += 3; |
| 9364 | else //4 byte start code |
| 9365 | index += 4; |
| 9366 | } else |
| 9367 | index++; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9368 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9369 | DEBUG_PRINT_LOW("Extracted (%lu) demux entry offsets",m_demux_entries); |
| 9370 | return; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9371 | } |
| 9372 | |
| 9373 | OMX_ERRORTYPE omx_vdec::handle_demux_data(OMX_BUFFERHEADERTYPE *p_buf_hdr) |
| 9374 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9375 | //fix this, handle 3 byte start code, vc1 terminator entry |
| 9376 | OMX_U8 *p_demux_data = NULL; |
| 9377 | OMX_U32 desc_data = 0; |
| 9378 | OMX_U32 start_addr = 0; |
| 9379 | OMX_U32 nal_size = 0; |
| 9380 | OMX_U32 suffix_byte = 0; |
| 9381 | OMX_U32 demux_index = 0; |
| 9382 | OMX_U32 buffer_index = 0; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9383 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9384 | if (m_desc_buffer_ptr == NULL) { |
| 9385 | DEBUG_PRINT_ERROR("m_desc_buffer_ptr is NULL. Cannot append demux entries."); |
| 9386 | return OMX_ErrorBadParameter; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9387 | } |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9388 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9389 | buffer_index = p_buf_hdr - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr); |
| 9390 | if (buffer_index > drv_ctx.ip_buf.actualcount) { |
| 9391 | DEBUG_PRINT_ERROR("handle_demux_data:Buffer index is incorrect (%lu)", buffer_index); |
| 9392 | return OMX_ErrorBadParameter; |
| 9393 | } |
| 9394 | |
| 9395 | p_demux_data = (OMX_U8 *) m_desc_buffer_ptr[buffer_index].buf_addr; |
| 9396 | |
| 9397 | if ( ((OMX_U8*)p_demux_data == NULL) || |
| 9398 | ((m_demux_entries * 16) + 1) > DESC_BUFFER_SIZE) { |
| 9399 | DEBUG_PRINT_ERROR("Insufficient buffer. Cannot append demux entries."); |
| 9400 | return OMX_ErrorBadParameter; |
| 9401 | } else { |
| 9402 | for (; demux_index < m_demux_entries; demux_index++) { |
| 9403 | desc_data = 0; |
| 9404 | start_addr = m_demux_offsets[demux_index]; |
| 9405 | if (p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 2] == 0x01) { |
| 9406 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 3]; |
| 9407 | } else { |
| 9408 | suffix_byte = p_buf_hdr->pBuffer[m_demux_offsets[demux_index] + 4]; |
| 9409 | } |
| 9410 | if (demux_index < (m_demux_entries - 1)) { |
| 9411 | nal_size = m_demux_offsets[demux_index + 1] - m_demux_offsets[demux_index] - 2; |
| 9412 | } else { |
| 9413 | nal_size = p_buf_hdr->nFilledLen - m_demux_offsets[demux_index] - 2; |
| 9414 | } |
| 9415 | DEBUG_PRINT_LOW("Start_addr(%p), suffix_byte(0x%lx),nal_size(%lu),demux_index(%lu)", |
| 9416 | (void *)start_addr, |
| 9417 | suffix_byte, |
| 9418 | nal_size, |
| 9419 | demux_index); |
| 9420 | desc_data = (start_addr >> 3) << 1; |
| 9421 | desc_data |= (start_addr & 7) << 21; |
| 9422 | desc_data |= suffix_byte << 24; |
| 9423 | |
| 9424 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9425 | memcpy(p_demux_data + 4, &nal_size, sizeof(OMX_U32)); |
| 9426 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9427 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9428 | |
| 9429 | p_demux_data += 16; |
| 9430 | } |
| 9431 | if (codec_type_parse == CODEC_TYPE_VC1) { |
| 9432 | DEBUG_PRINT_LOW("VC1 terminator entry"); |
| 9433 | desc_data = 0; |
| 9434 | desc_data = 0x82 << 24; |
| 9435 | memcpy(p_demux_data, &desc_data, sizeof(OMX_U32)); |
| 9436 | memset(p_demux_data + 4, 0, sizeof(OMX_U32)); |
| 9437 | memset(p_demux_data + 8, 0, sizeof(OMX_U32)); |
| 9438 | memset(p_demux_data + 12, 0, sizeof(OMX_U32)); |
| 9439 | p_demux_data += 16; |
| 9440 | m_demux_entries++; |
| 9441 | } |
| 9442 | //Add zero word to indicate end of descriptors |
| 9443 | memset(p_demux_data, 0, sizeof(OMX_U32)); |
| 9444 | |
| 9445 | m_desc_buffer_ptr[buffer_index].desc_data_size = (m_demux_entries * 16) + sizeof(OMX_U32); |
| 9446 | DEBUG_PRINT_LOW("desc table data size=%lu", m_desc_buffer_ptr[buffer_index].desc_data_size); |
| 9447 | } |
| 9448 | memset(m_demux_offsets, 0, ( sizeof(OMX_U32) * 8192) ); |
| 9449 | m_demux_entries = 0; |
| 9450 | DEBUG_PRINT_LOW("Demux table complete!"); |
| 9451 | return OMX_ErrorNone; |
Shalaj Jain | 273b3e0 | 2012-06-22 19:08:03 -0700 | [diff] [blame] | 9452 | } |
| 9453 | |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9454 | omx_vdec::allocate_color_convert_buf::allocate_color_convert_buf() |
| 9455 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9456 | enabled = false; |
| 9457 | omx = NULL; |
| 9458 | init_members(); |
| 9459 | ColorFormat = OMX_COLOR_FormatMax; |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9460 | dest_format = YCbCr420P; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9461 | } |
| 9462 | |
| 9463 | void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client) |
| 9464 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9465 | omx = reinterpret_cast<omx_vdec*>(client); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9466 | } |
| 9467 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9468 | void omx_vdec::allocate_color_convert_buf::init_members() |
| 9469 | { |
| 9470 | allocated_count = 0; |
| 9471 | buffer_size_req = 0; |
| 9472 | buffer_alignment_req = 0; |
| 9473 | memset(m_platform_list_client,0,sizeof(m_platform_list_client)); |
| 9474 | memset(m_platform_entry_client,0,sizeof(m_platform_entry_client)); |
| 9475 | memset(m_pmem_info_client,0,sizeof(m_pmem_info_client)); |
| 9476 | memset(m_out_mem_ptr_client,0,sizeof(m_out_mem_ptr_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9477 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9478 | memset(op_buf_ion_info,0,sizeof(m_platform_entry_client)); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9479 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9480 | for (int i = 0; i < MAX_COUNT; i++) |
| 9481 | pmem_fd[i] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9482 | } |
| 9483 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9484 | omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf() |
| 9485 | { |
| 9486 | c2d.destroy(); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9487 | } |
| 9488 | |
| 9489 | bool omx_vdec::allocate_color_convert_buf::update_buffer_req() |
| 9490 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9491 | bool status = true; |
| 9492 | unsigned int src_size = 0, destination_size = 0; |
| 9493 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9494 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9495 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9496 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9497 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9498 | if (!enabled) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9499 | DEBUG_PRINT_HIGH("No color conversion required"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9500 | return status; |
| 9501 | } |
| 9502 | pthread_mutex_lock(&omx->c_lock); |
| 9503 | if (omx->drv_ctx.output_format != VDEC_YUV_FORMAT_NV12 && |
| 9504 | ColorFormat != OMX_COLOR_FormatYUV420Planar) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9505 | DEBUG_PRINT_ERROR("update_buffer_req: Unsupported color conversion"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9506 | status = false; |
| 9507 | goto fail_update_buf_req; |
| 9508 | } |
| 9509 | c2d.close(); |
| 9510 | status = c2d.open(omx->drv_ctx.video_resolution.frame_height, |
| 9511 | omx->drv_ctx.video_resolution.frame_width, |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9512 | NV12_128m,dest_format); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9513 | if (status) { |
| 9514 | status = c2d.get_buffer_size(C2D_INPUT,src_size); |
| 9515 | if (status) |
| 9516 | status = c2d.get_buffer_size(C2D_OUTPUT,destination_size); |
| 9517 | } |
| 9518 | if (status) { |
| 9519 | if (!src_size || src_size > omx->drv_ctx.op_buf.buffer_size || |
| 9520 | !destination_size) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9521 | DEBUG_PRINT_ERROR("ERROR: Size mismatch in C2D src_size %d" |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9522 | "driver size %d destination size %d", |
| 9523 | src_size,omx->drv_ctx.op_buf.buffer_size,destination_size); |
| 9524 | status = false; |
| 9525 | c2d.close(); |
| 9526 | buffer_size_req = 0; |
| 9527 | } else { |
| 9528 | buffer_size_req = destination_size; |
| 9529 | if (buffer_size_req < omx->drv_ctx.op_buf.buffer_size) |
| 9530 | buffer_size_req = omx->drv_ctx.op_buf.buffer_size; |
| 9531 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9532 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
| 9533 | } |
| 9534 | } |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9535 | fail_update_buf_req: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9536 | pthread_mutex_unlock(&omx->c_lock); |
| 9537 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9538 | } |
| 9539 | |
| 9540 | bool omx_vdec::allocate_color_convert_buf::set_color_format( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9541 | OMX_COLOR_FORMATTYPE dest_color_format) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9542 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9543 | bool status = true; |
| 9544 | OMX_COLOR_FORMATTYPE drv_color_format; |
| 9545 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9546 | DEBUG_PRINT_ERROR("Invalid client in color convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9547 | return false; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9548 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9549 | pthread_mutex_lock(&omx->c_lock); |
| 9550 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9551 | drv_color_format = (OMX_COLOR_FORMATTYPE) |
| 9552 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9553 | else { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9554 | DEBUG_PRINT_ERROR("Incorrect color format"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9555 | status = false; |
| 9556 | } |
| 9557 | if (status && (drv_color_format != dest_color_format)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9558 | DEBUG_PRINT_LOW("Enabling C2D"); |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9559 | if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) && |
| 9560 | (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9561 | DEBUG_PRINT_ERROR("Unsupported color format for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9562 | status = false; |
| 9563 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9564 | ColorFormat = dest_color_format; |
| 9565 | dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ? |
| 9566 | YCbCr420P : YCbCr420SP; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9567 | if (enabled) |
| 9568 | c2d.destroy(); |
| 9569 | enabled = false; |
| 9570 | if (!c2d.init()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9571 | DEBUG_PRINT_ERROR("open failed for c2d"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9572 | status = false; |
| 9573 | } else |
| 9574 | enabled = true; |
| 9575 | } |
| 9576 | } else { |
| 9577 | if (enabled) |
| 9578 | c2d.destroy(); |
| 9579 | enabled = false; |
| 9580 | } |
| 9581 | pthread_mutex_unlock(&omx->c_lock); |
| 9582 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9583 | } |
| 9584 | |
| 9585 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr() |
| 9586 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9587 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9588 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9589 | return NULL; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9590 | } |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9591 | if (!enabled) |
| 9592 | return omx->m_out_mem_ptr; |
| 9593 | return m_out_mem_ptr_client; |
| 9594 | } |
| 9595 | |
| 9596 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr |
| 9597 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9598 | { |
| 9599 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9600 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9601 | return NULL; |
| 9602 | } |
| 9603 | if (!enabled) |
| 9604 | return bufadd; |
| 9605 | |
| 9606 | unsigned index = 0; |
| 9607 | index = bufadd - omx->m_out_mem_ptr; |
| 9608 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9609 | m_out_mem_ptr_client[index].nFlags = (bufadd->nFlags & OMX_BUFFERFLAG_EOS); |
| 9610 | m_out_mem_ptr_client[index].nTimeStamp = bufadd->nTimeStamp; |
| 9611 | bool status; |
| 9612 | if (!omx->in_reconfig && !omx->output_flush_progress && bufadd->nFilledLen) { |
| 9613 | pthread_mutex_lock(&omx->c_lock); |
| 9614 | status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd, |
| 9615 | omx->m_out_mem_ptr->pBuffer, bufadd->pBuffer, pmem_fd[index], |
| 9616 | pmem_baseaddress[index], pmem_baseaddress[index]); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9617 | if (!status) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9618 | DEBUG_PRINT_ERROR("Failed color conversion %d", status); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9619 | m_out_mem_ptr_client[index].nFilledLen = 0; |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9620 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9621 | return &m_out_mem_ptr_client[index]; |
Praveen Chavan | 6d6b725 | 2014-09-15 17:05:54 -0700 | [diff] [blame] | 9622 | } else { |
| 9623 | unsigned int filledLen = 0; |
| 9624 | c2d.get_output_filled_length(filledLen); |
| 9625 | m_out_mem_ptr_client[index].nFilledLen = filledLen; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9626 | } |
Leena Winterrowd | 270a704 | 2014-09-30 13:05:55 -0700 | [diff] [blame] | 9627 | pthread_mutex_unlock(&omx->c_lock); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9628 | } else |
| 9629 | m_out_mem_ptr_client[index].nFilledLen = 0; |
| 9630 | return &m_out_mem_ptr_client[index]; |
| 9631 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9632 | DEBUG_PRINT_ERROR("Index messed up in the get_il_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9633 | return NULL; |
| 9634 | } |
| 9635 | |
| 9636 | OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_dr_buf_hdr |
| 9637 | (OMX_BUFFERHEADERTYPE *bufadd) |
| 9638 | { |
| 9639 | if (!omx) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9640 | DEBUG_PRINT_ERROR("Invalid param get_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9641 | return NULL; |
| 9642 | } |
| 9643 | if (!enabled) |
| 9644 | return bufadd; |
| 9645 | unsigned index = 0; |
| 9646 | index = bufadd - m_out_mem_ptr_client; |
| 9647 | if (index < omx->drv_ctx.op_buf.actualcount) { |
| 9648 | return &omx->m_out_mem_ptr[index]; |
| 9649 | } |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9650 | DEBUG_PRINT_ERROR("Index messed up in the get_dr_buf_hdr"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9651 | return NULL; |
| 9652 | } |
| 9653 | bool omx_vdec::allocate_color_convert_buf::get_buffer_req |
| 9654 | (unsigned int &buffer_size) |
| 9655 | { |
| 9656 | bool status = true; |
| 9657 | pthread_mutex_lock(&omx->c_lock); |
| 9658 | if (!enabled) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9659 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9660 | else { |
| 9661 | if (!c2d.get_buffer_size(C2D_OUTPUT,buffer_size)) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9662 | DEBUG_PRINT_ERROR("Get buffer size failed"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9663 | status = false; |
| 9664 | goto fail_get_buffer_size; |
| 9665 | } |
| 9666 | } |
| 9667 | if (buffer_size < omx->drv_ctx.op_buf.buffer_size) |
| 9668 | buffer_size = omx->drv_ctx.op_buf.buffer_size; |
| 9669 | if (buffer_alignment_req < omx->drv_ctx.op_buf.alignment) |
| 9670 | buffer_alignment_req = omx->drv_ctx.op_buf.alignment; |
Praneeth Paladugu | f699527 | 2013-02-04 14:03:56 -0800 | [diff] [blame] | 9671 | fail_get_buffer_size: |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9672 | pthread_mutex_unlock(&omx->c_lock); |
| 9673 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9674 | } |
| 9675 | OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer( |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9676 | OMX_BUFFERHEADERTYPE *bufhdr) |
| 9677 | { |
| 9678 | unsigned int index = 0; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9679 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9680 | if (!enabled) |
| 9681 | return omx->free_output_buffer(bufhdr); |
| 9682 | if (enabled && omx->is_component_secure()) |
| 9683 | return OMX_ErrorNone; |
| 9684 | if (!allocated_count || !bufhdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9685 | DEBUG_PRINT_ERROR("Color convert no buffer to be freed %p",bufhdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9686 | return OMX_ErrorBadParameter; |
| 9687 | } |
| 9688 | index = bufhdr - m_out_mem_ptr_client; |
| 9689 | if (index >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9690 | DEBUG_PRINT_ERROR("Incorrect index color convert free_output_buffer"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9691 | return OMX_ErrorBadParameter; |
| 9692 | } |
| 9693 | if (pmem_fd[index] > 0) { |
| 9694 | munmap(pmem_baseaddress[index], buffer_size_req); |
| 9695 | close(pmem_fd[index]); |
| 9696 | } |
| 9697 | pmem_fd[index] = -1; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9698 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9699 | omx->free_ion_memory(&op_buf_ion_info[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9700 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9701 | m_heap_ptr[index].video_heap_ptr = NULL; |
| 9702 | if (allocated_count > 0) |
| 9703 | allocated_count--; |
| 9704 | else |
| 9705 | allocated_count = 0; |
| 9706 | if (!allocated_count) { |
| 9707 | pthread_mutex_lock(&omx->c_lock); |
| 9708 | c2d.close(); |
| 9709 | init_members(); |
| 9710 | pthread_mutex_unlock(&omx->c_lock); |
| 9711 | } |
| 9712 | return omx->free_output_buffer(&omx->m_out_mem_ptr[index]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9713 | } |
| 9714 | |
| 9715 | 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] | 9716 | OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,OMX_U32 bytes) |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9717 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9718 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9719 | if (!enabled) { |
| 9720 | eRet = omx->allocate_output_buffer(hComp,bufferHdr,port,appData,bytes); |
| 9721 | return eRet; |
| 9722 | } |
| 9723 | if (enabled && omx->is_component_secure()) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9724 | DEBUG_PRINT_ERROR("Notin color convert mode secure_mode %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9725 | omx->is_component_secure()); |
| 9726 | return OMX_ErrorUnsupportedSetting; |
| 9727 | } |
| 9728 | if (!bufferHdr || bytes > buffer_size_req) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9729 | DEBUG_PRINT_ERROR("Invalid params allocate_buffers_color_convert %p", bufferHdr); |
| 9730 | DEBUG_PRINT_ERROR("color_convert buffer_size_req %d bytes %lu", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9731 | buffer_size_req,bytes); |
| 9732 | return OMX_ErrorBadParameter; |
| 9733 | } |
| 9734 | if (allocated_count >= omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9735 | DEBUG_PRINT_ERROR("Actual count err in allocate_buffers_color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9736 | return OMX_ErrorInsufficientResources; |
| 9737 | } |
| 9738 | OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL; |
| 9739 | eRet = omx->allocate_output_buffer(hComp,&temp_bufferHdr, |
| 9740 | port,appData,omx->drv_ctx.op_buf.buffer_size); |
| 9741 | if (eRet != OMX_ErrorNone || !temp_bufferHdr) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9742 | DEBUG_PRINT_ERROR("Buffer allocation failed color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9743 | return eRet; |
| 9744 | } |
| 9745 | if ((temp_bufferHdr - omx->m_out_mem_ptr) >= |
Surajit Podder | d2644d5 | 2013-08-28 17:59:06 +0530 | [diff] [blame] | 9746 | (int)omx->drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9747 | DEBUG_PRINT_ERROR("Invalid header index %d", |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9748 | (temp_bufferHdr - omx->m_out_mem_ptr)); |
| 9749 | return OMX_ErrorUndefined; |
| 9750 | } |
| 9751 | unsigned int i = allocated_count; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9752 | #ifdef USE_ION |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9753 | op_buf_ion_info[i].ion_device_fd = omx->alloc_map_ion_memory( |
| 9754 | buffer_size_req,buffer_alignment_req, |
| 9755 | &op_buf_ion_info[i].ion_alloc_data,&op_buf_ion_info[i].fd_ion_data, |
| 9756 | 0); |
| 9757 | pmem_fd[i] = op_buf_ion_info[i].fd_ion_data.fd; |
| 9758 | if (op_buf_ion_info[i].ion_device_fd < 0) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9759 | DEBUG_PRINT_ERROR("alloc_map_ion failed in color_convert"); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9760 | return OMX_ErrorInsufficientResources; |
| 9761 | } |
| 9762 | pmem_baseaddress[i] = (unsigned char *)mmap(NULL,buffer_size_req, |
| 9763 | PROT_READ|PROT_WRITE,MAP_SHARED,pmem_fd[i],0); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9764 | |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9765 | if (pmem_baseaddress[i] == MAP_FAILED) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9766 | DEBUG_PRINT_ERROR("MMAP failed for Size %d",buffer_size_req); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9767 | close(pmem_fd[i]); |
| 9768 | omx->free_ion_memory(&op_buf_ion_info[i]); |
| 9769 | return OMX_ErrorInsufficientResources; |
| 9770 | } |
| 9771 | m_heap_ptr[i].video_heap_ptr = new VideoHeap ( |
| 9772 | op_buf_ion_info[i].ion_device_fd,buffer_size_req, |
| 9773 | pmem_baseaddress[i],op_buf_ion_info[i].ion_alloc_data.handle,pmem_fd[i]); |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9774 | #endif |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9775 | m_pmem_info_client[i].pmem_fd = (OMX_U32)m_heap_ptr[i].video_heap_ptr.get(); |
| 9776 | m_pmem_info_client[i].offset = 0; |
| 9777 | m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i]; |
| 9778 | m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM; |
| 9779 | m_platform_list_client[i].nEntries = 1; |
| 9780 | m_platform_list_client[i].entryList = &m_platform_entry_client[i]; |
| 9781 | m_out_mem_ptr_client[i].pOutputPortPrivate = NULL; |
| 9782 | m_out_mem_ptr_client[i].nAllocLen = buffer_size_req; |
| 9783 | m_out_mem_ptr_client[i].nFilledLen = 0; |
| 9784 | m_out_mem_ptr_client[i].nFlags = 0; |
| 9785 | m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX; |
| 9786 | m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE); |
| 9787 | m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION; |
| 9788 | m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i]; |
| 9789 | m_out_mem_ptr_client[i].pBuffer = pmem_baseaddress[i]; |
| 9790 | m_out_mem_ptr_client[i].pAppPrivate = appData; |
| 9791 | *bufferHdr = &m_out_mem_ptr_client[i]; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9792 | DEBUG_PRINT_ERROR("IL client buffer header %p", *bufferHdr); |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9793 | allocated_count++; |
| 9794 | return eRet; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9795 | } |
| 9796 | |
| 9797 | bool omx_vdec::is_component_secure() |
| 9798 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9799 | return secure_mode; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9800 | } |
| 9801 | |
| 9802 | bool omx_vdec::allocate_color_convert_buf::get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format) |
| 9803 | { |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9804 | bool status = true; |
| 9805 | if (!enabled) { |
| 9806 | if (omx->drv_ctx.output_format == VDEC_YUV_FORMAT_NV12) |
| 9807 | dest_color_format = (OMX_COLOR_FORMATTYPE) |
| 9808 | QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; |
| 9809 | else |
| 9810 | status = false; |
| 9811 | } else { |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9812 | if (ColorFormat == OMX_COLOR_FormatYUV420Planar || |
| 9813 | ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) { |
| 9814 | dest_color_format = ColorFormat; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9815 | } else |
Praveen Chavan | db7776f | 2014-02-06 18:17:25 -0800 | [diff] [blame] | 9816 | status = false; |
Arun Menon | 906de57 | 2013-06-18 17:01:40 -0700 | [diff] [blame] | 9817 | } |
| 9818 | return status; |
Vinay Kalia | da4f442 | 2013-01-09 10:45:03 -0800 | [diff] [blame] | 9819 | } |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9820 | |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9821 | void omx_vdec::buf_ref_add(OMX_U32 fd, OMX_U32 offset) |
| 9822 | { |
| 9823 | int i = 0; |
| 9824 | bool buf_present = false; |
| 9825 | pthread_mutex_lock(&m_lock); |
| 9826 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9827 | //check the buffer fd, offset, uv addr with list contents |
| 9828 | //If present increment reference. |
| 9829 | if ((out_dynamic_list[i].fd == fd) && |
| 9830 | (out_dynamic_list[i].offset == offset)) { |
| 9831 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9832 | 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] | 9833 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9834 | buf_present = true; |
| 9835 | break; |
| 9836 | } |
| 9837 | } |
| 9838 | if (!buf_present) { |
| 9839 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9840 | //search for a entry to insert details of the new buffer |
| 9841 | if (out_dynamic_list[i].dup_fd == 0) { |
| 9842 | out_dynamic_list[i].fd = fd; |
| 9843 | out_dynamic_list[i].offset = offset; |
| 9844 | out_dynamic_list[i].dup_fd = dup(fd); |
| 9845 | out_dynamic_list[i].ref_count++; |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9846 | DEBUG_PRINT_LOW("buf_ref_add: [ADDED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9847 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9848 | break; |
| 9849 | } |
| 9850 | } |
| 9851 | } |
| 9852 | pthread_mutex_unlock(&m_lock); |
| 9853 | } |
| 9854 | |
| 9855 | void omx_vdec::buf_ref_remove(OMX_U32 fd, OMX_U32 offset) |
| 9856 | { |
| 9857 | int i = 0; |
| 9858 | pthread_mutex_lock(&m_lock); |
| 9859 | for (i = 0; i < drv_ctx.op_buf.actualcount; i++) { |
| 9860 | //check the buffer fd, offset, uv addr with list contents |
| 9861 | //If present decrement reference. |
| 9862 | if ((out_dynamic_list[i].fd == fd) && |
| 9863 | (out_dynamic_list[i].offset == offset)) { |
| 9864 | out_dynamic_list[i].ref_count--; |
| 9865 | if (out_dynamic_list[i].ref_count == 0) { |
| 9866 | close(out_dynamic_list[i].dup_fd); |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9867 | DEBUG_PRINT_LOW("buf_ref_remove: [REMOVED] fd = %d ref_count = %d", |
Arun Menon | bdb80b0 | 2013-08-12 17:45:54 -0700 | [diff] [blame] | 9868 | out_dynamic_list[i].fd, out_dynamic_list[i].ref_count); |
| 9869 | out_dynamic_list[i].dup_fd = 0; |
| 9870 | out_dynamic_list[i].fd = 0; |
| 9871 | out_dynamic_list[i].offset = 0; |
| 9872 | } |
| 9873 | break; |
| 9874 | } |
| 9875 | } |
| 9876 | if (i >= drv_ctx.op_buf.actualcount) { |
Deva Ramasubramanian | 43918e2 | 2013-10-21 20:04:23 -0700 | [diff] [blame] | 9877 | 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] | 9878 | } |
| 9879 | pthread_mutex_unlock(&m_lock); |
| 9880 | } |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 9881 | |
Arun Menon | 1fc764f | 2014-04-17 15:41:27 -0700 | [diff] [blame] | 9882 | OMX_ERRORTYPE omx_vdec::enable_adaptive_playback(unsigned long nMaxFrameWidth, |
| 9883 | unsigned long nMaxFrameHeight) |
| 9884 | { |
| 9885 | |
| 9886 | OMX_ERRORTYPE eRet = OMX_ErrorNone; |
| 9887 | int ret = 0; |
| 9888 | unsigned long min_res_buf_count = 0; |
| 9889 | |
| 9890 | eRet = enable_smoothstreaming(); |
| 9891 | if (eRet != OMX_ErrorNone) { |
| 9892 | DEBUG_PRINT_ERROR("Failed to enable Adaptive Playback on driver"); |
| 9893 | return eRet; |
| 9894 | } |
| 9895 | |
| 9896 | DEBUG_PRINT_HIGH("Enabling Adaptive playback for %lu x %lu", |
| 9897 | nMaxFrameWidth, |
| 9898 | nMaxFrameHeight); |
| 9899 | m_smoothstreaming_mode = true; |
| 9900 | m_smoothstreaming_width = nMaxFrameWidth; |
| 9901 | m_smoothstreaming_height = nMaxFrameHeight; |
| 9902 | |
| 9903 | //Get upper limit buffer count for min supported resolution |
| 9904 | struct v4l2_format fmt; |
| 9905 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9906 | fmt.fmt.pix_mp.height = m_decoder_capability.min_height; |
| 9907 | fmt.fmt.pix_mp.width = m_decoder_capability.min_width; |
| 9908 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9909 | |
| 9910 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9911 | if (ret) { |
| 9912 | DEBUG_PRINT_ERROR("Set Resolution failed for HxW = %ux%u", |
| 9913 | m_decoder_capability.min_height, |
| 9914 | m_decoder_capability.min_width); |
| 9915 | return OMX_ErrorUnsupportedSetting; |
| 9916 | } |
| 9917 | |
| 9918 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9919 | if (eRet != OMX_ErrorNone) { |
| 9920 | DEBUG_PRINT_ERROR("failed to get_buffer_req"); |
| 9921 | return eRet; |
| 9922 | } |
| 9923 | |
| 9924 | min_res_buf_count = drv_ctx.op_buf.mincount; |
| 9925 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer count = %lu for HxW %ux%u", |
| 9926 | min_res_buf_count, m_decoder_capability.min_height, m_decoder_capability.min_width); |
| 9927 | |
| 9928 | update_resolution(m_smoothstreaming_width, m_smoothstreaming_height, |
| 9929 | m_smoothstreaming_width, m_smoothstreaming_height); |
| 9930 | eRet = is_video_session_supported(); |
| 9931 | if (eRet != OMX_ErrorNone) { |
| 9932 | DEBUG_PRINT_ERROR("video session is not supported"); |
| 9933 | return eRet; |
| 9934 | } |
| 9935 | |
| 9936 | //Get upper limit buffer size for max smooth streaming resolution set |
| 9937 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 9938 | fmt.fmt.pix_mp.height = drv_ctx.video_resolution.frame_height; |
| 9939 | fmt.fmt.pix_mp.width = drv_ctx.video_resolution.frame_width; |
| 9940 | fmt.fmt.pix_mp.pixelformat = output_capability; |
| 9941 | ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_S_FMT, &fmt); |
| 9942 | if (ret) { |
| 9943 | DEBUG_PRINT_ERROR("Set Resolution failed for adaptive playback"); |
| 9944 | return OMX_ErrorUnsupportedSetting; |
| 9945 | } |
| 9946 | |
| 9947 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9948 | if (eRet != OMX_ErrorNone) { |
| 9949 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!"); |
| 9950 | return eRet; |
| 9951 | } |
| 9952 | DEBUG_PRINT_LOW("enable adaptive - upper limit buffer size = %u", |
| 9953 | drv_ctx.op_buf.buffer_size); |
| 9954 | |
| 9955 | drv_ctx.op_buf.mincount = min_res_buf_count; |
| 9956 | drv_ctx.op_buf.actualcount = min_res_buf_count; |
| 9957 | eRet = set_buffer_req(&drv_ctx.op_buf); |
| 9958 | if (eRet != OMX_ErrorNone) { |
| 9959 | DEBUG_PRINT_ERROR("failed to set_buffer_req"); |
| 9960 | return eRet; |
| 9961 | } |
| 9962 | |
| 9963 | eRet = get_buffer_req(&drv_ctx.op_buf); |
| 9964 | if (eRet != OMX_ErrorNone) { |
| 9965 | DEBUG_PRINT_ERROR("failed to get_buffer_req!!!"); |
| 9966 | return eRet; |
| 9967 | } |
| 9968 | DEBUG_PRINT_HIGH("adaptive playback enabled, buf count = %u bufsize = %u", |
| 9969 | drv_ctx.op_buf.mincount, drv_ctx.op_buf.buffer_size); |
| 9970 | return eRet; |
| 9971 | } |
| 9972 | |
Leena Winterrowd | 974fd1f | 2013-10-30 10:58:02 -0700 | [diff] [blame] | 9973 | #ifdef _MSM8974_ |
| 9974 | void omx_vdec::send_codec_config() { |
| 9975 | if (codec_config_flag) { |
| 9976 | unsigned p1 = 0; // Parameter - 1 |
| 9977 | unsigned p2 = 0; // Parameter - 2 |
| 9978 | unsigned ident = 0; |
| 9979 | pthread_mutex_lock(&m_lock); |
| 9980 | DEBUG_PRINT_LOW("\n Check Queue for codec_config buffer \n"); |
| 9981 | while (m_etb_q.m_size) { |
| 9982 | m_etb_q.pop_entry(&p1,&p2,&ident); |
| 9983 | if (ident == OMX_COMPONENT_GENERATE_ETB_ARBITRARY) { |
| 9984 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 9985 | if (empty_this_buffer_proxy_arbitrary((OMX_HANDLETYPE)p1,\ |
| 9986 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 9987 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy_arbitrary failure"); |
| 9988 | omx_report_error(); |
| 9989 | } |
| 9990 | } else { |
| 9991 | DEBUG_PRINT_LOW("\n Flush Input Heap Buffer %p",(OMX_BUFFERHEADERTYPE *)p2); |
| 9992 | m_cb.EmptyBufferDone(&m_cmp ,m_app_data, (OMX_BUFFERHEADERTYPE *)p2); |
| 9993 | } |
| 9994 | } else if (ident == OMX_COMPONENT_GENERATE_ETB) { |
| 9995 | if (((OMX_BUFFERHEADERTYPE *)p2)->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 9996 | if (empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\ |
| 9997 | (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone) { |
| 9998 | DEBUG_PRINT_ERROR("\n empty_this_buffer_proxy failure"); |
| 9999 | omx_report_error (); |
| 10000 | } |
| 10001 | } else { |
| 10002 | pending_input_buffers++; |
| 10003 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_ETB %p, pending_input_buffers %d", |
| 10004 | (OMX_BUFFERHEADERTYPE *)p2, pending_input_buffers); |
| 10005 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2); |
| 10006 | } |
| 10007 | } else if (ident == OMX_COMPONENT_GENERATE_EBD) { |
| 10008 | DEBUG_PRINT_LOW("\n Flush Input OMX_COMPONENT_GENERATE_EBD %p", |
| 10009 | (OMX_BUFFERHEADERTYPE *)p1); |
| 10010 | empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1); |
| 10011 | } |
| 10012 | } |
| 10013 | pthread_mutex_unlock(&m_lock); |
| 10014 | } |
| 10015 | } |
| 10016 | #endif |
Praveen Chavan | 09a82b7 | 2014-10-18 09:09:45 -0700 | [diff] [blame] | 10017 | |
| 10018 | //static |
| 10019 | OMX_ERRORTYPE omx_vdec::describeColorFormat(OMX_PTR pParam) { |
| 10020 | |
| 10021 | #ifndef FLEXYUV_SUPPORTED |
| 10022 | (void)pParam; |
| 10023 | return OMX_ErrorUndefined; |
| 10024 | #else |
| 10025 | |
| 10026 | if (pParam == NULL) { |
| 10027 | DEBUG_PRINT_ERROR("describeColorFormat: invalid params"); |
| 10028 | return OMX_ErrorBadParameter; |
| 10029 | } |
| 10030 | |
| 10031 | DescribeColorFormatParams *params = (DescribeColorFormatParams*)pParam; |
| 10032 | |
| 10033 | MediaImage *img = &(params->sMediaImage); |
| 10034 | switch(params->eColorFormat) { |
| 10035 | case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m: |
| 10036 | { |
| 10037 | img->mType = MediaImage::MEDIA_IMAGE_TYPE_YUV; |
| 10038 | img->mNumPlanes = 3; |
| 10039 | // mWidth and mHeight represent the W x H of the largest plane |
| 10040 | // In our case, this happens to be the Stride x Scanlines of Y plane |
| 10041 | img->mWidth = params->nFrameWidth; |
| 10042 | img->mHeight = params->nFrameHeight; |
| 10043 | size_t planeWidth = VENUS_Y_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10044 | size_t planeHeight = VENUS_Y_SCANLINES(COLOR_FMT_NV12, params->nFrameHeight); |
| 10045 | img->mBitDepth = 8; |
| 10046 | //Plane 0 (Y) |
| 10047 | img->mPlane[MediaImage::Y].mOffset = 0; |
| 10048 | img->mPlane[MediaImage::Y].mColInc = 1; |
| 10049 | img->mPlane[MediaImage::Y].mRowInc = planeWidth; //same as stride |
| 10050 | img->mPlane[MediaImage::Y].mHorizSubsampling = 1; |
| 10051 | img->mPlane[MediaImage::Y].mVertSubsampling = 1; |
| 10052 | //Plane 1 (U) |
| 10053 | img->mPlane[MediaImage::U].mOffset = planeWidth * planeHeight; |
| 10054 | img->mPlane[MediaImage::U].mColInc = 2; //interleaved UV |
| 10055 | img->mPlane[MediaImage::U].mRowInc = |
| 10056 | VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10057 | img->mPlane[MediaImage::U].mHorizSubsampling = 2; |
| 10058 | img->mPlane[MediaImage::U].mVertSubsampling = 2; |
| 10059 | //Plane 2 (V) |
| 10060 | img->mPlane[MediaImage::V].mOffset = planeWidth * planeHeight + 1; |
| 10061 | img->mPlane[MediaImage::V].mColInc = 2; //interleaved UV |
| 10062 | img->mPlane[MediaImage::V].mRowInc = |
| 10063 | VENUS_UV_STRIDE(COLOR_FMT_NV12, params->nFrameWidth); |
| 10064 | img->mPlane[MediaImage::V].mHorizSubsampling = 2; |
| 10065 | img->mPlane[MediaImage::V].mVertSubsampling = 2; |
| 10066 | break; |
| 10067 | } |
| 10068 | |
| 10069 | case OMX_COLOR_FormatYUV420Planar: |
| 10070 | case OMX_COLOR_FormatYUV420SemiPlanar: |
| 10071 | // We need not describe the standard OMX linear formats as these are |
| 10072 | // understood by client. Fail this deliberately to let client fill-in |
| 10073 | return OMX_ErrorUnsupportedSetting; |
| 10074 | |
| 10075 | default: |
| 10076 | // Rest all formats which are non-linear cannot be described |
| 10077 | DEBUG_PRINT_LOW("color-format %x is not flexible", params->eColorFormat); |
| 10078 | img->mType = MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN; |
| 10079 | return OMX_ErrorNone; |
| 10080 | }; |
| 10081 | |
| 10082 | DEBUG_PRINT_LOW("NOTE: Describe color format : %x", params->eColorFormat); |
| 10083 | DEBUG_PRINT_LOW(" FrameWidth x FrameHeight : %d x %d", params->nFrameWidth, params->nFrameHeight); |
| 10084 | DEBUG_PRINT_LOW(" YWidth x YHeight : %d x %d", img->mWidth, img->mHeight); |
| 10085 | for (size_t i = 0; i < img->mNumPlanes; ++i) { |
| 10086 | DEBUG_PRINT_LOW(" Plane[%d] : offset=%d / xStep=%d / yStep = %d", |
| 10087 | i, img->mPlane[i].mOffset, img->mPlane[i].mColInc, img->mPlane[i].mRowInc); |
| 10088 | } |
| 10089 | return OMX_ErrorNone; |
| 10090 | #endif //FLEXYUV_SUPPORTED |
| 10091 | } |
| 10092 | |