media: amphion: Reduce decoding latency for HEVC decoder
PATCH v4 1/2 media: amphion: Reduce decoding latency for HEVC decoder
From: Ming Qian <[email protected]>
The amphion decoder firmware supports a low latency flush mode for the HEVC format since v1.9.0. This feature, which is enabled when the display delay is set to 0, can help to reduce the decoding latency by appending some padding data to every frame.
---
v4
- Add CHECK_VERSION macro
v3
- Improve commit message as recommended
v2
- Improve commit message
- Add firmware version check
drivers/media/platform/amphion/vpu_malone.c | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/media/platform/amphion/vpu_malone.c +21 -3
@@ -68,6 +68,12 @@#define MALONE_DEC_FMT_RV_MASK BIT(21) +#define MALONE_VERSION_MASK 0xFFFFF +#define MALONE_VERSION (maj, min, inc) \ + ((((maj) << 16) | ((min) << 16) | (inc)) & MALONE_VERSION_MASK) +#define CHECK_VERSION (iface, maj, min) \ + (((iface)->fw_version & MALONE_VERSION_MASK) >= MALONE_VERSION(maj, min, 0)) +enum vpu_malone_stream_input_mode {INVALID_MODE =0 ,FRAME_LVL ,
@@ -332,6 +338,8 @@ struct vpu_dec_ctrl {u32 buf_addr[VID_API_NUM_STREAMS ]; }; +static const struct malone_padding_scode *get_padding_scode (u32 type,u32 fmt); +u32 vpu_malone_get_data_size (void ) {return sizeof (struct vpu_dec_ctrl );
@@ -654,9 +662,15 @@ static int vpu_malone_set_params(struct vpu_shared_addr *shared, hc->jpg[instance].jpg_mjpeg_interlaced =0 ; } - hc->codec_param[instance].disp_imm = params->display_delay_enable ?1 :0 ; -if (malone_format !=MALONE_FMT_AVC ) +if (params->display_delay_enable && +get_padding_scode (SCODE_PADDING_BUFFLUSH , params->codec_format)) + hc->codec_param[instance].disp_imm =1 ; +else hc->codec_param[instance].disp_imm =0 ; + +if (params->codec_format ==V4L2_PIX_FMT_HEVC && !CHECK_VERSION (iface,1 ,9 )) + hc->codec_param[instance].disp_imm =0 ; + hc->codec_param[instance].dbglog_enable =0 ; iface->dbglog_desc.level =0 ;
@@ -1024,6 +1038,7 @@ static const struct malone_padding_scode padding_scodes[] = { {SCODE_PADDING_EOS, V4L2_PIX_FMT_JPEG, {0x0, 0x0}}, {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_H264, {0x15010000, 0x0}}, {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_H264_MVC, {0x15010000, 0x0}}, + {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_HEVC, {0x3e010000, 0x20}}, };static const struct malone_padding_scode padding_scode_dft = {0x0 ,0x0 };
@@ -1058,8 +1073,11 @@ static int vpu_malone_add_padding_scode(struct vpu_buffer *stream_buffer,int ret; ps =get_padding_scode (scode_type, pixelformat); -if (!ps) +if (!ps) { +if (scode_type ==SCODE_PADDING_BUFFLUSH ) +return 0 ;return -EINVAL ; + } wptr =readl (&str_buf->wptr);if (wptr < stream_buffer->phys || wptr > stream_buffer->phys + stream_buffer->length)
Signature · 1 line
2.43.0-rc1
PATCH v4 2/2 media: amphion: Add a frame flush mode for decoder
From: Ming Qian <[email protected]>
By default the amphion decoder will pre-parse 3 frames before starting to decode the first frame. Alternatively, a block of flush padding data can be appended to the frame, which will ensure that the decoder can start decoding immediately after parsing the flush padding data, thus potentially reducing decoding latency.
This mode was previously only enabled, when the display delay was set to
0. Allow the user to manually toggle the use of that mode via a module parameter called low_latency, which enables the mode without changing the display order.
---
v4
- Improve the comment expressing
v3
- Improve commit message as recommended
- Add some comments to avoid code looks cryptic
drivers/media/platform/amphion/vpu_malone.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/media/platform/amphion/vpu_malone.c +13 -1
@@ -25,6 +25,10 @@#include "vpu_imx8q.h" #include "vpu_malone.h" +static bool low_latency; +module_param (low_latency, bool,0644 ); +MODULE_PARM_DESC (low_latency,"Set low latency frame flush mode: 0 (disable) or 1 (enable)" ); +#define CMD_SIZE 25600#define MSG_SIZE 25600#define CODEC_SIZE 0x1000
@@ -1581,7 +1585,15 @@ static int vpu_malone_input_frame_data(struct vpu_malone_str_buffer __iomem *strvpu_malone_update_wptr (str_buf, wptr); -if (disp_imm && !vpu_vb_is_codecconfig (vbuf)) { +/* +* Enable the low latency flush mode if display delay is set to 0 +* or the low latency frame flush mode if it is set to 1. +* The low latency flush mode requires some padding data to be appended to each frame, +* but there must not be any padding data between the sequence header and the frame. +* This module is currently only supported for the H264 and HEVC formats, +* for other formats, vpu_malone_add_scode() will return 0. +*/ +if ((disp_imm || low_latency) && !vpu_vb_is_codecconfig (vbuf)) { ret = vpu_malone_add_scode(inst->core->iface, inst->id, &inst->stream_buffer,
Signature · 1 line
2.43.0-rc1
Frank Li
maintainerRe: [PATCH v4 2/2] media: amphion: Add a frame flush mode for decoder
Quoted 30 lines · On Fri, Mar 28, 2025 at 02:48:17PM +0800, [email protected] wrote:
From: Ming Qian <[email protected]>
By default the amphion decoder will pre-parse 3 frames before starting to decode the first frame. Alternatively, a block of flush padding data can be appended to the frame, which will ensure that the decoder can start decoding immediately after parsing the flush padding data, thus potentially reducing decoding latency.
This mode was previously only enabled, when the display delay was set to
0. Allow the user to manually toggle the use of that mode via a module parameter calledlow_latency, which enables the mode without changing the display order.Signed-off-by Ming Qian <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>---
v4
- Improve the comment expressing
v3
- Improve commit message as recommended
- Add some comments to avoid code looks crypticdrivers/media/platform/amphion/vpu_malone.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)drivers/media/platform/amphion/vpu_malone.c +0
-0
drivers/media/platform/amphion/vpu_malone.c line 31
Quoted 7 lines
drivers/media/platform/amphion/vpu_malone.c +4
-0@@ -25,6 +25,10 @@#include "vpu_imx8q.h" #include "vpu_malone.h" +static bool low_latency; +module_param (low_latency, bool,0644 ); +MODULE_PARM_DESC (low_latency,"Set low latency frame flush mode: 0 (disable) or 1 (enable)" ); +
If there are two malone instances, it will impact both instances, is it what your expected? Prefer use sys interface to controller it.
Frank
Quoted 23 lines
drivers/media/platform/amphion/vpu_malone.c +9
-2#define CMD_SIZE 25600#define MSG_SIZE 25600#define CODEC_SIZE 0x1000@@ -1581,7 +1585,15 @@ static int vpu_malone_input_frame_data(struct vpu_malone_str_buffer __iomem *strvpu_malone_update_wptr (str_buf, wptr); -if (disp_imm && !vpu_vb_is_codecconfig (vbuf)) { +/* +* Enable the low latency flush mode if display delay is set to 0 +* or the low latency frame flush mode if it is set to 1. +* The low latency flush mode requires some padding data to be appended to each frame, +* but there must not be any padding data between the sequence header and the frame. +* This module is currently only supported for the H264 and HEVC formats, +* for other formats, vpu_malone_add_scode() will return 0. +*/ +if ((disp_imm || low_latency) && !vpu_vb_is_codecconfig (vbuf)) { ret = vpu_malone_add_scode(inst->core->iface, inst->id, &inst->stream_buffer, --2.43.0-rc1
Re: [PATCH v4 2/2] media: amphion: Add a frame flush mode for decoder
Hi Frank,
Quoted 42 lines · Frank Li
Quoted 30 lines · On Fri, Mar 28, 2025 at 02:48:17PM +0800, [email protected] wrote:
From: Ming Qian <[email protected]>
By default the amphion decoder will pre-parse 3 frames before starting to decode the first frame. Alternatively, a block of flush padding data can be appended to the frame, which will ensure that the decoder can start decoding immediately after parsing the flush padding data, thus potentially reducing decoding latency.
This mode was previously only enabled, when the display delay was set to
0. Allow the user to manually toggle the use of that mode via a module parameter calledlow_latency, which enables the mode without changing the display order.Signed-off-by Ming Qian <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>---
v4
- Improve the comment expressing
v3
- Improve commit message as recommended
- Add some comments to avoid code looks crypticdrivers/media/platform/amphion/vpu_malone.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)drivers/media/platform/amphion/vpu_malone.c +0
-0drivers/media/platform/amphion/vpu_malone.c line 31
Quoted 7 lines
drivers/media/platform/amphion/vpu_malone.c +4
-0@@ -25,6 +25,10 @@#include "vpu_imx8q.h" #include "vpu_malone.h" +static bool low_latency; +module_param (low_latency, bool,0644 ); +MODULE_PARM_DESC (low_latency,"Set low latency frame flush mode: 0 (disable) or 1 (enable)" ); +If there are two malone instances, it will impact both instances, is it what your expected? Prefer use sys interface to controller it.
Quoted 1 line
Frank
Yes, that's we expected.
I prefer to say that we use this parameter to adjust the behavior of the firmware. I thought about enabling this mode by default, but our team prefers to add a parameter mode, but keep the previous behavior.and then enable it as needed.
Thanks,
Ming
Quoted 24 lines
Quoted 24 lines
drivers/media/platform/amphion/vpu_malone.c +9
-2#define CMD_SIZE 25600#define MSG_SIZE 25600#define CODEC_SIZE 0x1000@@ -1581,7 +1585,15 @@ static int vpu_malone_input_frame_data(struct vpu_malone_str_buffer __iomem *strvpu_malone_update_wptr (str_buf, wptr); -if (disp_imm && !vpu_vb_is_codecconfig (vbuf)) { +/* +* Enable the low latency flush mode if display delay is set to 0 +* or the low latency frame flush mode if it is set to 1. +* The low latency flush mode requires some padding data to be appended to each frame, +* but there must not be any padding data between the sequence header and the frame. +* This module is currently only supported for the H264 and HEVC formats, +* for other formats, vpu_malone_add_scode() will return 0. +*/ +if ((disp_imm || low_latency) && !vpu_vb_is_codecconfig (vbuf)) { ret = vpu_malone_add_scode(inst->core->iface, inst->id, &inst->stream_buffer, --2.43.0-rc1
Frank Li
maintainerQuoted 26 lines · On Fri, Mar 28, 2025 at 02:48:16PM +0800, [email protected] wrote:
From: Ming Qian <[email protected]>
The amphion decoder firmware supports a low latency flush mode for the HEVC format since v1.9.0. This feature, which is enabled when the display delay is set to 0, can help to reduce the decoding latency by appending some padding data to every frame.
Signed-off-by Ming Qian <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>---
v4
- AddCHECK_VERSIONmacro
v3
- Improve commit message as recommended
v2
- Improve commit message
- Add firmware version checkdrivers/media/platform/amphion/vpu_malone.c | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)drivers/media/platform/amphion/vpu_malone.c +0
-0
drivers/media/platform/amphion/vpu_malone.c line 76
Quoted 9 lines
drivers/media/platform/amphion/vpu_malone.c +6
-0@@ -68,6 +68,12 @@#define MALONE_DEC_FMT_RV_MASK BIT(21) +#define MALONE_VERSION_MASK 0xFFFFF +#define MALONE_VERSION (maj, min, inc) \ + ((((maj) << 16) | ((min) << 16) | (inc)) & MALONE_VERSION_MASK) +#define CHECK_VERSION (iface, maj, min) \ + (((iface)->fw_version & MALONE_VERSION_MASK) >= MALONE_VERSION(maj, min, 0)) +
Suggest use FIELD_PREP FILED_GET macro because it can check input value exceed the range.
#define FIELD_PREP(_mask, _val) \
({ \
__BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
^^^^
((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \
})Frank
Quoted 54 lines
drivers/media/platform/amphion/vpu_malone.c +15
-4enum vpu_malone_stream_input_mode {INVALID_MODE =0 ,FRAME_LVL ,@@ -332,6 +338,8 @@ struct vpu_dec_ctrl {u32 buf_addr[VID_API_NUM_STREAMS ]; }; +static const struct malone_padding_scode *get_padding_scode (u32 type,u32 fmt); +u32 vpu_malone_get_data_size (void ) {return sizeof (struct vpu_dec_ctrl );@@ -654,9 +662,15 @@ static int vpu_malone_set_params(struct vpu_shared_addr *shared, hc->jpg[instance].jpg_mjpeg_interlaced =0 ; } - hc->codec_param[instance].disp_imm = params->display_delay_enable ?1 :0 ; -if (malone_format !=MALONE_FMT_AVC ) +if (params->display_delay_enable && +get_padding_scode (SCODE_PADDING_BUFFLUSH , params->codec_format)) + hc->codec_param[instance].disp_imm =1 ; +else hc->codec_param[instance].disp_imm =0 ; + +if (params->codec_format ==V4L2_PIX_FMT_HEVC && !CHECK_VERSION (iface,1 ,9 )) + hc->codec_param[instance].disp_imm =0 ; + hc->codec_param[instance].dbglog_enable =0 ; iface->dbglog_desc.level =0 ;@@ -1024,6 +1038,7 @@ static const struct malone_padding_scode padding_scodes[] = { {SCODE_PADDING_EOS, V4L2_PIX_FMT_JPEG, {0x0, 0x0}}, {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_H264, {0x15010000, 0x0}}, {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_H264_MVC, {0x15010000, 0x0}}, + {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_HEVC, {0x3e010000, 0x20}}, };static const struct malone_padding_scode padding_scode_dft = {0x0 ,0x0 };@@ -1058,8 +1073,11 @@ static int vpu_malone_add_padding_scode(struct vpu_buffer *stream_buffer,int ret; ps =get_padding_scode (scode_type, pixelformat); -if (!ps) +if (!ps) { +if (scode_type ==SCODE_PADDING_BUFFLUSH ) +return 0 ;return -EINVAL ; + } wptr =readl (&str_buf->wptr);if (wptr < stream_buffer->phys || wptr > stream_buffer->phys + stream_buffer->length) --2.43.0-rc1
Hi Frank,
Quoted 49 lines · Frank Li
Quoted 26 lines · On Fri, Mar 28, 2025 at 02:48:16PM +0800, [email protected] wrote:
From: Ming Qian <[email protected]>
The amphion decoder firmware supports a low latency flush mode for the HEVC format since v1.9.0. This feature, which is enabled when the display delay is set to 0, can help to reduce the decoding latency by appending some padding data to every frame.
Signed-off-by Ming Qian <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>---
v4
- AddCHECK_VERSIONmacro
v3
- Improve commit message as recommended
v2
- Improve commit message
- Add firmware version checkdrivers/media/platform/amphion/vpu_malone.c | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)drivers/media/platform/amphion/vpu_malone.c +0
-0drivers/media/platform/amphion/vpu_malone.c line 76
Quoted 9 lines
drivers/media/platform/amphion/vpu_malone.c +6
-0@@ -68,6 +68,12 @@#define MALONE_DEC_FMT_RV_MASK BIT(21) +#define MALONE_VERSION_MASK 0xFFFFF +#define MALONE_VERSION (maj, min, inc) \ + ((((maj) << 16) | ((min) << 16) | (inc)) & MALONE_VERSION_MASK) +#define CHECK_VERSION (iface, maj, min) \ + (((iface)->fw_version & MALONE_VERSION_MASK) >= MALONE_VERSION(maj, min, 0)) +Suggest use
FIELD_PREPFILED_GETmacro because it can check input value exceed the range.#define FIELD_PREP(_mask, _val) \ ({ \ __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \ ^^^^ ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \ })
Quoted 1 line
Frank
Sure, I'll apply it in V5
Quoted 55 lines
Quoted 55 lines
drivers/media/platform/amphion/vpu_malone.c +15
-4enum vpu_malone_stream_input_mode {INVALID_MODE =0 ,FRAME_LVL ,@@ -332,6 +338,8 @@ struct vpu_dec_ctrl {u32 buf_addr[VID_API_NUM_STREAMS ]; }; +static const struct malone_padding_scode *get_padding_scode (u32 type,u32 fmt); +u32 vpu_malone_get_data_size (void ) {return sizeof (struct vpu_dec_ctrl );@@ -654,9 +662,15 @@ static int vpu_malone_set_params(struct vpu_shared_addr *shared, hc->jpg[instance].jpg_mjpeg_interlaced =0 ; } - hc->codec_param[instance].disp_imm = params->display_delay_enable ?1 :0 ; -if (malone_format !=MALONE_FMT_AVC ) +if (params->display_delay_enable && +get_padding_scode (SCODE_PADDING_BUFFLUSH , params->codec_format)) + hc->codec_param[instance].disp_imm =1 ; +else hc->codec_param[instance].disp_imm =0 ; + +if (params->codec_format ==V4L2_PIX_FMT_HEVC && !CHECK_VERSION (iface,1 ,9 )) + hc->codec_param[instance].disp_imm =0 ; + hc->codec_param[instance].dbglog_enable =0 ; iface->dbglog_desc.level =0 ;@@ -1024,6 +1038,7 @@ static const struct malone_padding_scode padding_scodes[] = { {SCODE_PADDING_EOS, V4L2_PIX_FMT_JPEG, {0x0, 0x0}}, {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_H264, {0x15010000, 0x0}}, {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_H264_MVC, {0x15010000, 0x0}}, + {SCODE_PADDING_BUFFLUSH, V4L2_PIX_FMT_HEVC, {0x3e010000, 0x20}}, };static const struct malone_padding_scode padding_scode_dft = {0x0 ,0x0 };@@ -1058,8 +1073,11 @@ static int vpu_malone_add_padding_scode(struct vpu_buffer *stream_buffer,int ret; ps =get_padding_scode (scode_type, pixelformat); -if (!ps) +if (!ps) { +if (scode_type ==SCODE_PADDING_BUFFLUSH ) +return 0 ;return -EINVAL ; + } wptr =readl (&str_buf->wptr);if (wptr < stream_buffer->phys || wptr > stream_buffer->phys + stream_buffer->length) --2.43.0-rc1