Skip to contentSkip to conversation

v4l2-ctl: declare hdr variable as const

PATCH New Dafna Hirschfeld 1 participant 3 messages Mar 30, 2019 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 v4l2-ctl: declare hdr variable as const

declare the hdr param with 'const' in
functions that use fwht header in order
to set the fwht stateless params.

---
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +3 -3
index 85f97722..28bc8c68 100644
@@ -837,7 +837,7 @@ static int alloc_fwht_req(int media_fd, unsigned index)
 	return 0;
 }
 
-static void set_fwht_req_by_idx(unsigned idx, struct fwht_cframe_hdr *hdr,
+static void set_fwht_req_by_idx(unsigned idx, const struct fwht_cframe_hdr *hdr,
 				__u64 last_bf_ts, __u64 ts)
 {
 	struct v4l2_ctrl_fwht_params fwht_params;
@@ -857,7 +857,7 @@ static int get_fwht_req_by_ts(__u64 ts)
 	return -1;
 }
 
-static bool set_fwht_req_by_fd(struct fwht_cframe_hdr *hdr,
+static bool set_fwht_req_by_fd(const struct fwht_cframe_hdr *hdr,
 			       int req_fd, __u64 last_bf_ts, __u64 ts)
 {
 	struct v4l2_ctrl_fwht_params fwht_params;
@@ -874,7 +874,7 @@ static bool set_fwht_req_by_fd(struct fwht_cframe_hdr *hdr,
 	return false;
 }
 
-static int set_fwht_ext_ctrl(cv4l_fd &fd, struct fwht_cframe_hdr *hdr,
+static int set_fwht_ext_ctrl(cv4l_fd &fd, const struct fwht_cframe_hdr *hdr,
 			     __u64 last_bf_ts, int req_fd)
 {
 	v4l2_ext_controls controls;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 v4l2-ctl: fix debug prints

replace 'set_fwht_ext_ctrls' with 'set_fwht_ext_ctrl' in debug prints

---
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +2 -2
index 28bc8c68..daa93968 100644
@@ -1249,7 +1249,7 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue &q, FILE *fin, bool qbuf
 
 			if (set_fwht_ext_ctrl(fd, &last_fwht_hdr, last_fwht_bf_ts,
 					      buf.g_request_fd())) {
-				fprintf(stderr, "%s: set_fwht_ext_ctrls failed on %dth buf: %s\n",
+				fprintf(stderr, "%s: set_fwht_ext_ctrl failed on %dth buf: %s\n",
 					__func__, i, strerror(errno));
 				return QUEUE_ERROR;
 			}
@@ -1539,7 +1539,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap
 
 		if (set_fwht_ext_ctrl(fd, &last_fwht_hdr, last_fwht_bf_ts,
 				      buf.g_request_fd())) {
-			fprintf(stderr, "%s: set_fwht_ext_ctrls failed: %s\n",
+			fprintf(stderr, "%s: set_fwht_ext_ctrl failed: %s\n",
 				__func__, strerror(errno));
 			return QUEUE_ERROR;
 		}
Signature · 1 line
2.17.1
#2 lore raw

PATCH 3/3 v4l2-ctl: add support for fwht stateless decoder

In reply to Dafna Hirschfeld

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

---
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +13 -5
index daa93968..0d3c89ef 100644
@@ -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);
Signature · 1 line
2.17.1