From 50d88a14d96044145a67df2cd56c105bd04f8ae5 Mon Sep 17 00:00:00 2001 From: Praveen Chavan Date: Wed, 29 Mar 2017 16:39:05 -0700 Subject: [PATCH] mm-video-v4l2: venc: Update output resolution correctly for rotation Update resolution of output plane based on the rotatio angle to reflect the correct w x h in output-port-def CRs-Fixed: 2026950 Change-Id: I3ef1158785d5967f9089ad988b3ac45982faa57e --- .../vidc/venc/inc/video_encoder_device_v4l2.h | 1 + .../vidc/venc/src/omx_video_encoder.cpp | 9 +++++++ .../venc/src/video_encoder_device_v4l2.cpp | 25 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h b/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h index 79698eac..bf35a229 100644 --- a/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h +++ b/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h @@ -345,6 +345,7 @@ class venc_dev bool venc_h264_transform_8x8(OMX_BOOL enable); bool venc_get_profile_level(OMX_U32 *eProfile,OMX_U32 *eLevel); bool venc_get_seq_hdr(void *, unsigned, unsigned *); + bool venc_get_dimensions(OMX_U32 portIndex, OMX_U32 *w, OMX_U32 *h); bool venc_loaded_start(void); bool venc_loaded_stop(void); bool venc_loaded_start_done(void); diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp index 382322b8..60e18d24 100644 --- a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp +++ b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp @@ -2056,6 +2056,15 @@ OMX_ERRORTYPE omx_venc::set_config(OMX_IN OMX_HANDLETYPE hComp, return OMX_ErrorUnsupportedSetting; } m_sConfigFrameRotation.nRotation = pParam->nRotation; + + // Update output-port resolution (since it might have been flipped by rotation) + if (handle->venc_get_dimensions(PORT_INDEX_OUT, + &m_sOutPortDef.format.video.nFrameWidth, + &m_sOutPortDef.format.video.nFrameHeight)) { + DEBUG_PRINT_HIGH("set Rotation: updated dimensions = %u x %u", + m_sOutPortDef.format.video.nFrameWidth, + m_sOutPortDef.format.video.nFrameHeight); + } break; } case OMX_QcomIndexConfigVideoFramePackingArrangement: diff --git a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp index 4512551d..3dac0856 100644 --- a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp +++ b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp @@ -1654,6 +1654,22 @@ bool venc_dev::venc_get_seq_hdr(void *buffer, return true; } +bool venc_dev::venc_get_dimensions(OMX_U32 portIndex, OMX_U32 *w, OMX_U32 *h) { + struct v4l2_format fmt; + memset(&fmt, 0, sizeof(fmt)); + fmt.type = portIndex == PORT_INDEX_OUT ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; + + if (ioctl(m_nDriver_fd, VIDIOC_G_FMT, &fmt)) { + DEBUG_PRINT_ERROR("Failed to get format on %s port", + portIndex == PORT_INDEX_OUT ? "capture" : "output"); + return false; + } + *w = fmt.fmt.pix_mp.width; + *h = fmt.fmt.pix_mp.height; + return true; +} + bool venc_dev::venc_get_buf_req(OMX_U32 *min_buff_count, OMX_U32 *actual_buff_count, OMX_U32 *buff_size, @@ -6389,6 +6405,15 @@ bool venc_dev::venc_set_vpe_rotation(OMX_S32 rotation_angle) memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; + if (rotation_angle == 90 || rotation_angle == 270) { + OMX_U32 nWidth = m_sVenc_cfg.dvs_height; + OMX_U32 nHeight = m_sVenc_cfg.dvs_width; + m_sVenc_cfg.dvs_height = nHeight; + m_sVenc_cfg.dvs_width = nWidth; + DEBUG_PRINT_LOW("Rotation (%u) Flipping wxh to %lux%lu", + rotation_angle, m_sVenc_cfg.dvs_width, m_sVenc_cfg.dvs_height); + } + fmt.fmt.pix_mp.height = m_sVenc_cfg.dvs_height; fmt.fmt.pix_mp.width = m_sVenc_cfg.dvs_width; fmt.fmt.pix_mp.pixelformat = m_sVenc_cfg.codectype;