From ff1ff3cda3a712196ffbfb6d644a33c049aec5e0 Mon Sep 17 00:00:00 2001 From: Amit Pandya Date: Tue, 29 Nov 2016 13:57:26 +0530 Subject: [PATCH] multimedia_api: videoenc: Add extended control Add function for following encoder feature - Encoder HW Preset Bug 200249574 Change-Id: I25d3078e3e016f1030c063010c8978150876b4f7 Reviewed-on: http://git-master/r/1261277 (cherry picked from commit 4667a7a98686520b9197d4846137fd926348518a) --- multimedia_api/ll_samples/include/NvVideoEncoder.h | 13 ++++++++++++ .../samples/01_video_encode/video_encode.h | 1 + .../01_video_encode/video_encode_csvparser.cpp | 24 ++++++++++++++++++++++ .../samples/01_video_encode/video_encode_main.cpp | 6 ++++++ .../samples/common/classes/NvVideoEncoder.cpp | 23 +++++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/multimedia_api/ll_samples/include/NvVideoEncoder.h b/multimedia_api/ll_samples/include/NvVideoEncoder.h index 8e42514..0cd818f 100644 --- a/multimedia_api/ll_samples/include/NvVideoEncoder.h +++ b/multimedia_api/ll_samples/include/NvVideoEncoder.h @@ -240,6 +240,19 @@ public: int setSliceLength(v4l2_enc_slice_length_type type, uint32_t length); /** + * Set the encoder HW Preset Type. + * + * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id + * #V4L2_CID_MPEG_VIDEOENC_HW_PRESET_TYPE_PARAM. Must be called after setFormat on + * both the planes and before #requestBuffers on any of the planes. + * + * @param[in] type HW Preset Type, one of + * enum v4l2_enc_hw_preset_type_param + * @returns 0 for success, -1 for failure + */ + int setHWPresetType(v4l2_enc_hw_preset_type type); + + /** * Sets the Region of Interest (ROI) parameters for the next buffer, which will * be queued on the output plane with index \a buffer_index. * diff --git a/multimedia_api/ll_samples/samples/01_video_encode/video_encode.h b/multimedia_api/ll_samples/samples/01_video_encode/video_encode.h index 3a04589..8c32368 100644 --- a/multimedia_api/ll_samples/samples/01_video_encode/video_encode.h +++ b/multimedia_api/ll_samples/samples/01_video_encode/video_encode.h @@ -72,6 +72,7 @@ typedef struct uint32_t fps_d; enum v4l2_enc_temporal_tradeoff_level_type temporal_tradeoff_level; + enum v4l2_enc_hw_preset_type hw_preset_type; v4l2_enc_slice_length_type slice_length_type; uint32_t slice_length; uint32_t virtual_buffer_size; diff --git a/multimedia_api/ll_samples/samples/01_video_encode/video_encode_csvparser.cpp b/multimedia_api/ll_samples/samples/01_video_encode/video_encode_csvparser.cpp index ef77721..298f46c 100644 --- a/multimedia_api/ll_samples/samples/01_video_encode/video_encode_csvparser.cpp +++ b/multimedia_api/ll_samples/samples/01_video_encode/video_encode_csvparser.cpp @@ -67,6 +67,7 @@ print_help(void) "\t-vbs Virtual buffer size [Default = 0]\n" "\t-nrf Number of reference frames [Default = 1]\n\n" "\t-slt Slice length type (1 = Number of MBs, 2 = Bytes) [Default = 1]\n" + "\t-hpt HW preset type (1 = ultrafast, 2 = fast, 3 = medium, 4 = slow)\n" "\t-slen Slice length [Default = 0]\n" "\t-sir Slice intrarefresh interval [Default = 0]\n\n" "\t-nbf Number of B frames [Default = 0]\n\n" @@ -460,6 +461,29 @@ parse_csv_args(context_t * ctx, int argc, char *argv[]) "Unsupported value for slice length type: " << *argp); } } + else if (!strcmp(arg, "-hpt")) + { + argp++; + CHECK_OPTION_VALUE(argp); + switch (atoi(*argp)) + { + case 1: + ctx->hw_preset_type = V4L2_ENC_HW_PRESET_ULTRAFAST; + break; + case 2: + ctx->hw_preset_type = V4L2_ENC_HW_PRESET_FAST; + break; + case 3: + ctx->hw_preset_type = V4L2_ENC_HW_PRESET_MEDIUM; + break; + case 4: + ctx->hw_preset_type = V4L2_ENC_HW_PRESET_SLOW; + break; + default: + CSV_PARSE_CHECK_ERROR(true, + "Unsupported value for encoder HW Preset Type: " << *argp); + } + } else if (!strcmp(arg, "-slen")) { argp++; diff --git a/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp b/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp index 838dfbe..55b87ca 100644 --- a/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp +++ b/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp @@ -598,6 +598,12 @@ main(int argc, char *argv[]) TEST_ERROR(ret < 0, "Could not set slice length params", cleanup); } + if (ctx.hw_preset_type) + { + ret = ctx.enc->setHWPresetType(ctx.hw_preset_type); + TEST_ERROR(ret < 0, "Could not set encoder HW Preset Type", cleanup); + } + if (ctx.virtual_buffer_size) { ret = ctx.enc->setVirtualBufferSize(ctx.virtual_buffer_size); diff --git a/multimedia_api/ll_samples/samples/common/classes/NvVideoEncoder.cpp b/multimedia_api/ll_samples/samples/common/classes/NvVideoEncoder.cpp index 2cc1ed0..e6fa3bc 100644 --- a/multimedia_api/ll_samples/samples/common/classes/NvVideoEncoder.cpp +++ b/multimedia_api/ll_samples/samples/common/classes/NvVideoEncoder.cpp @@ -389,6 +389,29 @@ NvVideoEncoder::setSliceLength(v4l2_enc_slice_length_type type, uint32_t length) } int +NvVideoEncoder::setHWPresetType(v4l2_enc_hw_preset_type type) +{ + struct v4l2_ext_control control; + struct v4l2_ext_controls ctrls; + + RETURN_ERROR_IF_FORMATS_NOT_SET(); + RETURN_ERROR_IF_BUFFERS_REQUESTED(); + + memset(&control, 0, sizeof(control)); + memset(&ctrls, 0, sizeof(ctrls)); + + ctrls.count = 1; + ctrls.controls = &control; + ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG; + + control.id = V4L2_CID_MPEG_VIDEOENC_HW_PRESET_TYPE_PARAM; + control.value = type; + + CHECK_V4L2_RETURN(setExtControls(ctrls), + "Setting encoder HW Preset type to " << type); +} + +int NvVideoEncoder::setROIParams(uint32_t buffer_index, v4l2_enc_frame_ROI_params ¶ms) { -- 2.1.4