aboutsummaryrefslogtreecommitdiffstats
path: root/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
diff options
context:
space:
mode:
authorDafna Hirschfeld <dafna3@gmail.com>2019-03-06 13:17:51 -0800
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2019-03-29 16:04:54 +0100
commit80edda7d43d615da6d3027ec582d79d176e249aa (patch)
tree851d2ed51ce8788f716029256d6ea2a55942f779 /utils/v4l2-ctl/v4l2-ctl-streaming.cpp
parent21e24eeeb835341e7d4f5a65cad03d7b3be45ec6 (diff)
v4l2-ctl: Add functions and variables to support fwht stateless decoder
Add the variable 'last_fwht_bf_ts' and the array 'fwht_reqs' to allow the fwht stateless decoder to maintain the requests. Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> [hverkuil-cisco@xs4all.nl: dropped get_ns_timestamp]
Diffstat (limited to 'utils/v4l2-ctl/v4l2-ctl-streaming.cpp')
-rw-r--r--utils/v4l2-ctl/v4l2-ctl-streaming.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index 31670738..e8762464 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -17,9 +17,12 @@
#include <sys/mman.h>
#include <dirent.h>
#include <math.h>
+#include <linux/media.h>
#include "v4l2-ctl.h"
#include "v4l-stream.h"
+#include <media-info.h>
+#include <fwht-ctrls.h>
extern "C" {
#include "v4l2-tpg.h"
@@ -80,6 +83,17 @@ static bool support_cap_compose;
static bool support_out_crop;
static bool in_source_change_event;
+static __u64 last_fwht_bf_ts;
+static fwht_cframe_hdr last_fwht_hdr;
+
+struct request_fwht {
+ int fd;
+ __u64 ts;
+ struct v4l2_ctrl_fwht_params params;
+};
+
+static request_fwht fwht_reqs[VIDEO_MAX_FRAME];
+
#define TS_WINDOW 241
#define FILE_HDR_ID v4l2_fourcc('V', 'h', 'd', 'r')
@@ -757,6 +771,124 @@ void streaming_cmd(int ch, char *optarg)
}
}
+/*
+ * Assume that the fwht stream is valid and that each
+ * frame starts right after the previous one.
+ */
+static bool read_fwht_frame(cv4l_fmt &fmt, unsigned char *buf,
+ FILE *fpointer, unsigned &sz,
+ unsigned &expected_len, unsigned buf_len)
+{
+ expected_len = sizeof(struct fwht_cframe_hdr);
+ if (expected_len > buf_len)
+ return false;
+ sz = fread(&last_fwht_hdr, 1, sizeof(struct fwht_cframe_hdr), fpointer);
+ if (sz < sizeof(struct fwht_cframe_hdr))
+ return true;
+
+ expected_len = ntohl(last_fwht_hdr.size);
+ if (expected_len > buf_len)
+ return false;
+ sz = fread(buf, 1, ntohl(last_fwht_hdr.size), fpointer);
+ return true;
+}
+
+static void set_fwht_stateless_params(struct v4l2_ctrl_fwht_params &fwht_params,
+ const struct fwht_cframe_hdr *hdr,
+ __u64 last_bf_ts)
+{
+ fwht_params.backward_ref_ts = last_bf_ts;
+ fwht_params.version = ntohl(hdr->version);
+ fwht_params.width = ntohl(hdr->width);
+ fwht_params.height = ntohl(hdr->height);
+ fwht_params.flags = ntohl(hdr->flags);
+ fwht_params.colorspace = ntohl(hdr->colorspace);
+ fwht_params.xfer_func = ntohl(hdr->xfer_func);
+ fwht_params.ycbcr_enc = ntohl(hdr->ycbcr_enc);
+ fwht_params.quantization = ntohl(hdr->quantization);
+
+ /*
+ * if last_bf_ts is 0 it indicates that either this is the
+ * first frame, or that last frame returned with an error so
+ * it is better not to reference it so the error won't propagate
+ */
+ if (!last_bf_ts)
+ fwht_params.flags |= FWHT_FL_I_FRAME;
+}
+
+static int alloc_fwht_req(int media_fd, unsigned index)
+{
+ int rc = 0;
+
+ rc = ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &fwht_reqs[index]);
+ if (rc < 0) {
+ fprintf(stderr, "Unable to allocate media request: %s\n",
+ strerror(errno));
+ return rc;
+ }
+
+ return 0;
+}
+
+static void set_fwht_req_by_idx(unsigned idx, struct fwht_cframe_hdr *hdr,
+ __u64 last_bf_ts, __u64 ts)
+{
+ struct v4l2_ctrl_fwht_params fwht_params;
+
+ set_fwht_stateless_params(fwht_params, hdr, last_bf_ts);
+
+ fwht_reqs[idx].ts = ts;
+ fwht_reqs[idx].params = fwht_params;
+}
+
+static int get_fwht_req_by_ts(__u64 ts)
+{
+ for (int idx = 0; idx < VIDEO_MAX_FRAME; idx++) {
+ if (fwht_reqs[idx].ts == ts)
+ return idx;
+ }
+ return -1;
+}
+
+static bool set_fwht_req_by_fd(struct fwht_cframe_hdr *hdr,
+ int req_fd, __u64 last_bf_ts, __u64 ts)
+{
+ struct v4l2_ctrl_fwht_params fwht_params;
+
+ set_fwht_stateless_params(fwht_params, hdr, last_bf_ts);
+
+ for (int idx = 0; idx < VIDEO_MAX_FRAME; idx++) {
+ if (fwht_reqs[idx].fd == req_fd) {
+ fwht_reqs[idx].ts = ts;
+ fwht_reqs[idx].params = fwht_params;
+ return true;
+ }
+ }
+ return false;
+}
+
+static int set_fwht_ext_ctrl(cv4l_fd &fd, struct fwht_cframe_hdr *hdr,
+ __u64 last_bf_ts, int req_fd)
+{
+ v4l2_ext_controls controls;
+ struct v4l2_ext_control control;
+ struct v4l2_ctrl_fwht_params fwht_params;
+
+ memset(&control, 0, sizeof(control));
+ memset(&controls, 0, sizeof(controls));
+
+ set_fwht_stateless_params(fwht_params, hdr, last_bf_ts);
+
+ control.id = V4L2_CID_MPEG_VIDEO_FWHT_PARAMS;
+ control.ptr = &fwht_params;
+ control.size = sizeof(fwht_params);
+ controls.which = V4L2_CTRL_WHICH_REQUEST_VAL;
+ controls.request_fd = req_fd;
+ controls.controls = &control;
+ controls.count = 1;
+ return fd.s_ext_ctrls(controls);
+}
+
static bool read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf,
FILE *fpointer, unsigned &sz,
unsigned &expected_len, unsigned buf_len,

Privacy Policy