From 75b571e76a3949f5992e3003dcd501fbc0cd90d9 Mon Sep 17 00:00:00 2001 From: Praveen Chavan Date: Wed, 29 Mar 2017 13:13:36 -0700 Subject: [PATCH] mm-video-v4l2: venc: add extension to support av-timer timestamps Use timestamps sent in-band with graphic handles (updated from camera with av-timer source) for vt usecases. Bug: 32746650 CRs-Fixed: 2026950 Change-Id: I5af29b0155eb108e4d9f0bae76fa72a947e719c2 --- mm-core/inc/OMX_QCOMExtns.h | 3 ++ mm-video-v4l2/vidc/venc/inc/omx_video_base.h | 1 + .../vidc/venc/inc/video_encoder_device_v4l2.h | 1 + .../vidc/venc/src/omx_video_encoder.cpp | 14 +++++++++ .../vidc/venc/src/omx_video_extensions.hpp | 30 +++++++++++++++++-- .../venc/src/video_encoder_device_v4l2.cpp | 18 +++++++++++ 6 files changed, 65 insertions(+), 2 deletions(-) diff --git a/mm-core/inc/OMX_QCOMExtns.h b/mm-core/inc/OMX_QCOMExtns.h index db13f541..bf4c0ae8 100644 --- a/mm-core/inc/OMX_QCOMExtns.h +++ b/mm-core/inc/OMX_QCOMExtns.h @@ -638,6 +638,9 @@ enum OMX_QCOM_EXTN_INDEXTYPE /* Suggest how big Iframe sizes should be */ OMX_QTIIndexParamIframeSizeType = 0x7F000070, + + /* use av-timer ticks as timestamp (used by VT-client) */ + OMX_QTIIndexParamEnableAVTimerTimestamps = 0x7F000071, }; /** diff --git a/mm-video-v4l2/vidc/venc/inc/omx_video_base.h b/mm-video-v4l2/vidc/venc/inc/omx_video_base.h index e10e48bd..27dfc050 100644 --- a/mm-video-v4l2/vidc/venc/inc/omx_video_base.h +++ b/mm-video-v4l2/vidc/venc/inc/omx_video_base.h @@ -685,6 +685,7 @@ class omx_video: public qc_omx_component DescribeColorAspectsParams m_sConfigColorAspects; OMX_VIDEO_PARAM_ANDROID_TEMPORALLAYERINGTYPE m_sParamTemporalLayers; OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE m_sConfigTemporalLayers; + QOMX_ENABLETYPE m_sParamAVTimerTimestampMode; // use VT-timestamps in gralloc-handle // fill this buffer queue omx_cmd_queue m_ftb_q; 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 fab7317c..79698eac 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 @@ -640,6 +640,7 @@ class venc_dev }; BatchInfo mBatchInfo; + bool mUseAVTimerTimestamps; }; enum instance_state { 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 bc1d5bae..382322b8 100644 --- a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp +++ b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp @@ -574,6 +574,9 @@ OMX_ERRORTYPE omx_venc::component_init(OMX_STRING role) OMX_INIT_STRUCT(&m_sConfigTemporalLayers, OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE); + OMX_INIT_STRUCT(&m_sParamAVTimerTimestampMode, QOMX_ENABLETYPE); + m_sParamAVTimerTimestampMode.bEnable = OMX_FALSE; + m_state = OMX_StateLoaded; m_sExtraData = 0; @@ -1786,6 +1789,17 @@ OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp, } break; } + case OMX_QTIIndexParamEnableAVTimerTimestamps: + { + VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE); + if (!handle->venc_set_param(paramData, + (OMX_INDEXTYPE)OMX_QTIIndexParamEnableAVTimerTimestamps)) { + DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamEnableAVTimerTimestamps failed"); + return OMX_ErrorUnsupportedSetting; + } + memcpy(&m_sParamAVTimerTimestampMode, paramData, sizeof(QOMX_ENABLETYPE)); + break; + } case OMX_IndexParamVideoSliceFMO: default: { diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_extensions.hpp b/mm-video-v4l2/vidc/venc/src/omx_video_extensions.hpp index 163fd50b..5be091ee 100644 --- a/mm-video-v4l2/vidc/venc/src/omx_video_extensions.hpp +++ b/mm-video-v4l2/vidc/venc/src/omx_video_extensions.hpp @@ -44,6 +44,9 @@ void omx_video::init_vendor_extensions(VendorExtensionStore &store) { ADD_EXTENSION("qti-ext-enc-custom-profile-level", OMX_IndexParamVideoProfileLevelCurrent, OMX_DirOutput) ADD_PARAM ("profile", OMX_AndroidVendorValueInt32) ADD_PARAM_END("level", OMX_AndroidVendorValueInt32) + + ADD_EXTENSION("qti-ext-enc-timestamp-source-avtimer", OMX_QTIIndexParamEnableAVTimerTimestamps, OMX_DirInput) + ADD_PARAM_END("enable", OMX_AndroidVendorValueInt32) } OMX_ERRORTYPE omx_video::get_vendor_extension_config( @@ -66,7 +69,7 @@ OMX_ERRORTYPE omx_video::get_vendor_extension_config( bool setStatus = true; - switch (vExt.extensionIndex()) { + switch ((OMX_U32)vExt.extensionIndex()) { case OMX_IndexConfigCommonRotate: { setStatus &= vExt.setParamInt32(ext, "angle", m_sConfigFrameRotation.nRotation); @@ -92,6 +95,11 @@ OMX_ERRORTYPE omx_video::get_vendor_extension_config( break; } + case OMX_QTIIndexParamEnableAVTimerTimestamps: + { + setStatus &= vExt.setParamInt32(ext, "enable", m_sParamAVTimerTimestampMode.bEnable); + break; + } default: { return OMX_ErrorNotImplemented; @@ -124,7 +132,7 @@ OMX_ERRORTYPE omx_video::set_vendor_extension_config( vExt.set(); bool valueSet = false; - switch (vExt.extensionIndex()) { + switch ((OMX_U32)vExt.extensionIndex()) { case OMX_IndexConfigCommonRotate: { OMX_CONFIG_ROTATIONTYPE rotationParam; @@ -205,7 +213,25 @@ OMX_ERRORTYPE omx_video::set_vendor_extension_config( break; } + case OMX_QTIIndexParamEnableAVTimerTimestamps: + { + QOMX_ENABLETYPE avTimerEnableParam; + memcpy(&avTimerEnableParam, &m_sParamAVTimerTimestampMode, sizeof(QOMX_ENABLETYPE)); + valueSet |= vExt.readParamInt32(ext, "enable", (OMX_S32 *)&(avTimerEnableParam.bEnable)); + if (!valueSet) { + break; + } + DEBUG_PRINT_HIGH("VENDOR-EXT: AV-timer timestamp mode enable=%u", avTimerEnableParam.bEnable); + + err = set_parameter( + NULL, (OMX_INDEXTYPE)OMX_QTIIndexParamEnableAVTimerTimestamps, &avTimerEnableParam); + if (err != OMX_ErrorNone) { + DEBUG_PRINT_ERROR("set_param: OMX_QTIIndexParamEnableAVTimerTimestamps failed !"); + } + + break; + } default: { return OMX_ErrorNotImplemented; 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 1b4cd07c..4512551d 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 @@ -270,6 +270,8 @@ venc_dev::venc_dev(class omx_venc *venc_class) snprintf(m_debug.log_loc, PROPERTY_VALUE_MAX, "%s", BUFFER_LOG_LOC); + + mUseAVTimerTimestamps = false; } venc_dev::~venc_dev() @@ -2652,6 +2654,13 @@ bool venc_dev::venc_set_param(void *paramData, OMX_INDEXTYPE index) } break; } + case OMX_QTIIndexParamEnableAVTimerTimestamps: + { + QOMX_ENABLETYPE *pParam = (QOMX_ENABLETYPE *)paramData; + mUseAVTimerTimestamps = pParam->bEnable == OMX_TRUE; + DEBUG_PRINT_INFO("AVTimer timestamps enabled"); + break; + } case OMX_IndexParamVideoSliceFMO: default: DEBUG_PRINT_ERROR("ERROR: Unsupported parameter in venc_set_param: %u", @@ -3963,6 +3972,15 @@ bool venc_dev::venc_empty_buf(void *buffer, void *pmem_data_buf, unsigned index, return false; } + if (mUseAVTimerTimestamps) { + uint64_t avTimerTimestampNs = bufhdr->nTimeStamp * 1000; + if (getMetaData(handle, GET_VT_TIMESTAMP, &avTimerTimestampNs) == 0 + && avTimerTimestampNs > 0) { + bufhdr->nTimeStamp = avTimerTimestampNs / 1000; + DEBUG_PRINT_LOW("AVTimer TS : %llu us", (unsigned long long)bufhdr->nTimeStamp); + } + } + if (!streaming[OUTPUT_PORT]) { int color_space = 0; // Moment of truth... actual colorspace is known here..