adjust the code to support both encoder and decoder
for stateless fwht

Signed-off-by: Dafna Hirschfeld <daf...@gmail.com>
---
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp 
b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index daa93968..0d3c89ef 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -82,6 +82,7 @@ static unsigned int composed_height;
 static bool support_cap_compose;
 static bool support_out_crop;
 static bool in_source_change_event;
+static bool is_stateless;
 
 static __u64 last_fwht_bf_ts;
 static fwht_cframe_hdr last_fwht_hdr;
@@ -1234,7 +1235,7 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue 
&q, FILE *fin, bool qbuf
                if (fin && !fill_buffer_from_file(fd, q, buf, fmt, fin))
                        return QUEUE_STOPPED;
 
-               if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) {
+               if (is_stateless) {
                        int media_fd = mi_get_media_fd(fd.g_fd());
 
                        if (media_fd < 0) {
@@ -1268,7 +1269,7 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue 
&q, FILE *fin, bool qbuf
                                if (!--stream_count)
                                        return QUEUE_STOPPED;
                }
-               if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) {
+               if (is_stateless) {
                        set_fwht_req_by_idx(i, &last_fwht_hdr,
                                            last_fwht_bf_ts, 
buf.g_timestamp_ns());
                        last_fwht_bf_ts = buf.g_timestamp_ns();
@@ -1530,7 +1531,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE 
*fin, cv4l_buffer *cap
                                       (u8 *)q.g_dataptr(buf.g_index(), j));
        }
 
-       if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) {
+       if (is_stateless) {
                if (ioctl(buf.g_request_fd(), MEDIA_REQUEST_IOC_REINIT, NULL)) {
                        fprintf(stderr, "Unable to reinit media request: %s\n",
                                strerror(errno));
@@ -1551,7 +1552,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE 
*fin, cv4l_buffer *cap
                fprintf(stderr, "%s: failed: %s\n", "VIDIOC_QBUF", 
strerror(errno));
                return QUEUE_ERROR;
        }
-       if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) {
+       if (is_stateless) {
                if (!set_fwht_req_by_fd(&last_fwht_hdr, buf.g_request_fd(), 
last_fwht_bf_ts,
                                        buf.g_timestamp_ns())) {
                        fprintf(stderr, "%s: request for fd %d does not 
exist\n",
@@ -2392,7 +2393,12 @@ static void stateless_m2m(cv4l_fd &fd, cv4l_queue &in, 
cv4l_queue &out,
        unsigned count[2] = { 0, 0 };
        int fd_flags = fcntl(fd.g_fd(), F_GETFL);
        bool stopped = false;
+       enum codec_type codec_type = get_codec_type(fd);
 
+       if (codec_type == ENCODER) {
+               last_fwht_hdr.width = htonl(cropped_width);
+               last_fwht_hdr.height = htonl(cropped_height);
+       }
        if (out.reqbufs(&fd, reqbufs_count_out)) {
                fprintf(stderr, "%s: out.reqbufs failed\n", __func__);
                return;
@@ -2576,7 +2582,9 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd 
&exp_fd)
                if (out.export_bufs(&exp_fd, exp_fd.g_type()))
                        goto done;
        }
-       if (fmt[OUT].g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS)
+       is_stateless = fmt[OUT].g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS 
||
+                      fmt[CAP].g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS;
+       if (is_stateless)
                stateless_m2m(fd, in, out, file[CAP], file[OUT], fmt[CAP], 
fmt[OUT], exp_fd_p);
        else
                stateful_m2m(fd, in, out, file[CAP], file[OUT], fmt[CAP], 
fmt[OUT], exp_fd_p);
-- 
2.17.1

Reply via email to