From: Dafna Hirschfeld <dafna3@gmail.com>
To: linux-media@vger.kernel.org
Cc: hverkuil@xs4all.nl, helen.koike@collabora.com,
Dafna Hirschfeld <dafna3@gmail.com>
Subject: [v4l-utils PATCH v3 7/8] v4l2-ctl: Add functions and variables to support fwht stateless decoder
Date: Sun, 24 Feb 2019 00:41:25 -0800 [thread overview]
Message-ID: <20190224084126.19412-8-dafna3@gmail.com> (raw)
In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com>
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>
---
utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 121 ++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index adfa6796..82a93d4b 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -20,11 +20,18 @@
#include "v4l2-ctl.h"
#include "v4l-stream.h"
+#include <media-info.h>
+#include <fwht-ctrls.h>
extern "C" {
#include "v4l2-tpg.h"
}
+#define VICODEC_CID_CUSTOM_BASE (V4L2_CID_MPEG_BASE | 0xf000)
+#define VICODEC_CID_I_FRAME_QP (VICODEC_CID_CUSTOM_BASE + 0)
+#define VICODEC_CID_P_FRAME_QP (VICODEC_CID_CUSTOM_BASE + 1)
+#define VICODEC_CID_STATELESS_FWHT (VICODEC_CID_CUSTOM_BASE + 2)
+
static unsigned stream_count;
static unsigned stream_skip;
static __u32 memory = V4L2_MEMORY_MMAP;
@@ -80,6 +87,16 @@ static bool support_cap_compose;
static bool support_out_crop;
static bool in_source_change_event;
+static __u64 last_fwht_bf_ts;
+
+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')
@@ -420,6 +437,12 @@ static int get_out_crop_rect(cv4l_fd &fd)
return 0;
}
+static __u64 get_ns_timestamp(cv4l_buffer &buf)
+{
+ const struct timeval tv = buf.g_timestamp();
+ return v4l2_timeval_to_ns(&tv);
+}
+
static void set_time_stamp(cv4l_buffer &buf)
{
if ((buf.g_flags() & V4L2_BUF_FLAG_TIMESTAMP_MASK) != V4L2_BUF_FLAG_TIMESTAMP_COPY)
@@ -749,6 +772,104 @@ 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 void read_fwht_frame(cv4l_fmt &fmt, unsigned char *buf,
+ FILE *fpointer, unsigned &sz,
+ unsigned &len)
+{
+ struct fwht_cframe_hdr *h = (struct fwht_cframe_hdr *)buf;
+
+ len = sizeof(struct fwht_cframe_hdr);
+ sz = fread(buf, 1, sizeof(struct fwht_cframe_hdr), fpointer);
+ if (sz < sizeof(struct fwht_cframe_hdr))
+ return;
+
+ len += ntohl(h->size);
+ sz += fread(buf + sz, 1, ntohl(h->size), fpointer);
+}
+
+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);
+ fwht_params.comp_frame_size = ntohl(hdr->size);
+
+ if (!last_bf_ts)
+ fwht_params.flags |= FWHT_FL_I_FRAME;
+}
+
+static void set_fwht_req_by_idx(unsigned idx, 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);
+
+ fwht_reqs[idx].fd = req_fd;
+ 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 = VICODEC_CID_STATELESS_FWHT;
+ 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 void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf,
FILE *fpointer, unsigned &sz,
unsigned &len, bool is_read)
--
2.17.1
next prev parent reply other threads:[~2019-02-24 8:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-24 8:41 [v4l-utils PATCH v3 0/8] add support to stateless decoder Dafna Hirschfeld
2019-02-24 8:41 ` [v4l-utils PATCH v3 1/8] v4l2-ctl: rename variable 'vic_fmt' to 'info' Dafna Hirschfeld
2019-02-24 8:41 ` [v4l-utils PATCH v3 2/8] v4l2-ctl: bugfix: correctly read/write V4L2_PIX_FMT_NV24 padded buffer Dafna Hirschfeld
2019-02-24 8:41 ` [v4l-utils PATCH v3 3/8] v4l2-ctl: test if do_setup_out_buffers returns -1 instead of non zero Dafna Hirschfeld
2019-02-24 8:41 ` [v4l-utils PATCH v3 4/8] v4l2-ctl: move stateful m2m decode code to a separate function Dafna Hirschfeld
2019-02-24 8:41 ` [v4l-utils PATCH v3 5/8] (c)v4l-helpers.h: Add support for the request api Dafna Hirschfeld
2019-02-25 10:38 ` Hans Verkuil
2019-02-24 8:41 ` [v4l-utils PATCH v3 6/8] v4l-utils: copy fwht-ctrls.h from kernel dir Dafna Hirschfeld
2019-02-24 8:41 ` Dafna Hirschfeld [this message]
2019-02-24 8:41 ` [v4l-utils PATCH v3 8/8] v4l2-ctl: Add implementation for the stateless fwht decoder Dafna Hirschfeld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190224084126.19412-8-dafna3@gmail.com \
--to=dafna3@gmail.com \
--cc=helen.koike@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox