* [PATCH] utils: fwht: support resolution changes
@ 2026-03-26 8:12 Rivka S
0 siblings, 0 replies; only message in thread
From: Rivka S @ 2026-03-26 8:12 UTC (permalink / raw)
To: linux-media; +Cc: Rivka S
The FWHT decoder currently fails when the resolution changes
between frames.
Instead of returning -EINVAL, update the internal state to match
the new resolution.
When a resolution change is detected:
- Update visible width and height from the frame header
- Recalculate coded dimensions
- Update stride and reference stride
- Reset GOP-related state
Also recompute dependent values such as dst_chroma_stride,
ref_chroma_stride and dst_size after updating the state.
On the userspace side, ensure the destination buffer is large enough
for the updated frame size and reallocate it if needed.
This allows decoding streams with dynamic resolution changes.
Tested using a custom FWHT decoding script.
Signed-off-by: Rivka Sabo <s0533160580@gmail.com>
---
utils/common/codec-v4l2-fwht.c | 29 ++++++++++++++++++++++-------
utils/qvidcap/capture.cpp | 15 ++++++++++++---
2 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/utils/common/codec-v4l2-fwht.c b/utils/common/codec-v4l2-fwht.c
index 0c83678f..f45b06c3 100644
--- a/utils/common/codec-v4l2-fwht.c
+++ b/utils/common/codec-v4l2-fwht.c
@@ -288,9 +288,9 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
const struct v4l2_fwht_pixfmt_info *info;
unsigned int hdr_width_div, hdr_height_div;
struct fwht_raw_frame dst_rf;
- unsigned int dst_chroma_stride = state->stride;
- unsigned int ref_chroma_stride = state->ref_stride;
- unsigned int dst_size = state->stride * state->coded_height;
+ unsigned int dst_chroma_stride;
+ unsigned int ref_chroma_stride;
+ unsigned int dst_size;
unsigned int ref_size;
if (!state->info)
@@ -309,10 +309,25 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
state->header.magic2 != FWHT_MAGIC2)
return -EINVAL;
- /* TODO: support resolution changes */
- if (ntohl(state->header.width) != state->visible_width ||
- ntohl(state->header.height) != state->visible_height)
- return -EINVAL;
+ if (ntohl(state->header.width) != state->visible_width ||
+ ntohl(state->header.height) != state->visible_height) {
+ state->visible_width = ntohl(state->header.width);
+ state->visible_height = ntohl(state->header.height);
+ state->coded_width = vic_round_dim(
+ state->visible_width + (info->width_div - 1),
+ info->width_div);
+ state->coded_height = vic_round_dim(
+ state->visible_height + (info->height_div - 1),
+ info->height_div);
+ state->stride = state->coded_width * info->bytesperline_mult;
+ state->ref_stride = state->stride;
+ state->gop_cnt = 0;
+ state->ref_frame_ts = 0;
+ }
+
+ dst_chroma_stride = state->stride;
+ ref_chroma_stride = state->ref_stride;
+ dst_size = state->stride * state->coded_height;
flags = ntohl(state->header.flags);
diff --git a/utils/qvidcap/capture.cpp b/utils/qvidcap/capture.cpp
index 6b41933e..8fff20c8 100644
--- a/utils/qvidcap/capture.cpp
+++ b/utils/qvidcap/capture.cpp
@@ -1337,9 +1337,18 @@ void CaptureWin::sockReadEvent()
offset += n;
sz -= n;
}
- if (is_fwht)
- fwht_decompress(m_ctx, dst, data_size, m_curData[p], m_curSize[p]);
- else
+ if (is_fwht) {
+ __u32 needed_out = m_v4l_fmt.g_sizeimage(p);
+
+ if (!m_curData[p] || m_curSize[p] < needed_out) {
+ delete[] m_curData[p];
+ m_curData[p] = new __u8[needed_out];
+ m_curSize[p] = needed_out;
+ }
+
+ fwht_decompress(m_ctx, dst, data_size, m_curData[p],
+ m_curSize[p]);
+ } else
rle_decompress(dst, size, data_size,
rle_calc_bpl(m_v4l_fmt.g_bytesperline(p), m_v4l_fmt.g_pixelformat()));
}
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-26 8:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 8:12 [PATCH] utils: fwht: support resolution changes Rivka S
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox