This is an automatic generated email to let you know that the following patch were queued at the http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:
Subject: (c)v4l-helpers: add s_fd() functions, improve g/s_trace Author: Hans Verkuil <hans.verk...@cisco.com> Date: Mon Jun 25 09:54:25 2018 +0200 Add helpers that can initialize the v4l_fd struct from an fd file descriptor. Change querycap so that it can be forced to do the actual ioctl call instead of returning the cached result. Improve trace so it can also trace if the ioctl was successful. Signed-off-by: Hans Verkuil <hans.verk...@cisco.com> utils/common/cv4l-helpers.h | 12 ++++-- utils/common/v4l-helpers.h | 90 ++++++++++++++++++++++++++++++--------------- utils/qv4l2/general-tab.h | 2 +- 3 files changed, 71 insertions(+), 33 deletions(-) --- http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=32055009dce4186630a1fc54d2d6c595df723420 diff --git a/utils/common/cv4l-helpers.h b/utils/common/cv4l-helpers.h index abdd7d498863..b65037581868 100644 --- a/utils/common/cv4l-helpers.h +++ b/utils/common/cv4l-helpers.h @@ -36,12 +36,15 @@ public: v4l_fd *g_v4l_fd() { return this; } bool g_direct() const { return v4l_fd_g_direct(this); } void s_direct(bool direct) { v4l_fd_s_direct(this, direct); } - bool g_trace() const { return v4l_fd_g_trace(this); } - void s_trace(bool trace) { v4l_fd_s_trace(this, trace); } + unsigned int g_trace() const { return v4l_fd_g_trace(this); } + void s_trace(unsigned int trace) { v4l_fd_s_trace(this, trace); } int open(const char *devname, bool non_blocking = false) { return v4l_open(this, devname, non_blocking); } + int s_fd(int fd, const char *devname, bool direct) { return v4l_s_fd(this, fd, devname, direct); } int subdev_open(const char *devname, bool non_blocking = false) { return v4l_subdev_open(this, devname, non_blocking); } + int subdev_s_fd(int fd, const char *devname) { return v4l_subdev_s_fd(this, fd, devname); } int media_open(const char *devname, bool non_blocking = false) { return v4l_media_open(this, devname, non_blocking); } + int media_s_fd(int fd, const char *devname) { return v4l_media_s_fd(this, fd, devname); } int close() { return v4l_close(this); } int reopen(bool non_blocking = false) { return v4l_reopen(this, non_blocking); } ssize_t read(void *buffer, size_t n) { return v4l_read(this, buffer, n); } @@ -73,9 +76,12 @@ public: bool has_streaming() const { return v4l_has_streaming(this); } bool has_ext_pix_format() const { return v4l_has_ext_pix_format(this); } - void querycap(v4l2_capability &cap) + int querycap(v4l2_capability &cap, bool force = false) { + if (force) + return cv4l_ioctl(VIDIOC_QUERYCAP, &cap); cap = this->cap; + return 0; } int queryctrl(v4l2_queryctrl &qc) diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h index 2116323baf92..41c5def06e1c 100644 --- a/utils/common/v4l-helpers.h +++ b/utils/common/v4l-helpers.h @@ -31,7 +31,7 @@ struct v4l_fd { char devname[128]; __u32 type; __u32 caps; - bool trace; + unsigned int trace; bool direct; bool have_query_ext_ctrl; bool have_ext_ctrls; @@ -102,7 +102,8 @@ static inline bool v4l_fd_g_direct(const struct v4l_fd *f) static inline void v4l_fd_s_direct(struct v4l_fd *f, bool direct) { - f->direct = direct; + if (!f->is_subdev && !f->is_media) + f->direct = direct; } #else @@ -190,12 +191,12 @@ static inline bool v4l_fd_is_v4l2(const struct v4l_fd *f) return !f->is_subdev && !f->is_media; } -static inline bool v4l_fd_g_trace(const struct v4l_fd *f) +static inline unsigned int v4l_fd_g_trace(const struct v4l_fd *f) { return f->trace; } -static inline void v4l_fd_s_trace(struct v4l_fd *f, bool trace) +static inline void v4l_fd_s_trace(struct v4l_fd *f, unsigned int trace) { f->trace = trace; } @@ -208,7 +209,7 @@ static inline int v4l_named_ioctl(struct v4l_fd *f, retval = f->ioctl(f, cmd, arg); e = retval == 0 ? 0 : errno; - if (f->trace) + if (f->trace >= (e ? 1 : 2)) fprintf(stderr, "\t\t%s returned %d (%s)\n", cmd_name, retval, strerror(e)); return retval == -1 ? e : (retval ? -1 : 0); @@ -436,13 +437,21 @@ static inline __u32 v4l_determine_type(const struct v4l_fd *f) return 0; } -static inline int v4l_open(struct v4l_fd *f, const char *devname, bool non_blocking) +static inline int v4l_s_fd(struct v4l_fd *f, int fd, const char *devname, bool direct) { struct v4l2_query_ext_ctrl qec; struct v4l2_ext_controls ec; struct v4l2_queryctrl qc; struct v4l2_selection sel; + if (f->fd >= 0) + f->close(f); + + f->fd = fd; + f->direct = direct; + if (fd < 0) + return fd; + memset(&qec, 0, sizeof(qec)); qec.id = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND; memset(&ec, 0, sizeof(ec)); @@ -450,14 +459,9 @@ static inline int v4l_open(struct v4l_fd *f, const char *devname, bool non_block qc.id = V4L2_CTRL_FLAG_NEXT_CTRL; memset(&sel, 0, sizeof(sel)); - f->fd = f->open(f, devname, O_RDWR | (non_blocking ? O_NONBLOCK : 0)); + strncpy(f->devname, devname, sizeof(f->devname)); + f->devname[sizeof(f->devname) - 1] = '\0'; - if (f->fd < 0) - return f->fd; - if (f->devname != devname) { - strncpy(f->devname, devname, sizeof(f->devname)); - f->devname[sizeof(f->devname) - 1] = '\0'; - } memset(&f->cap, 0, sizeof(f->cap)); if (v4l_querycap(f, &f->cap)) { v4l_close(f); @@ -479,19 +483,30 @@ static inline int v4l_open(struct v4l_fd *f, const char *devname, bool non_block return f->fd; } -static inline int v4l_subdev_open(struct v4l_fd *f, const char *devname, bool non_blocking) +static inline int v4l_open(struct v4l_fd *f, const char *devname, bool non_blocking) { - f->fd = f->open(f, devname, O_RDWR | (non_blocking ? O_NONBLOCK : 0)); + int fd = f->open(f, devname, O_RDWR | (non_blocking ? O_NONBLOCK : 0)); + + return v4l_s_fd(f, fd, devname, f->direct); +} + +static inline int v4l_subdev_s_fd(struct v4l_fd *f, int fd, const char *devname) +{ + if (f->fd >= 0) + f->close(f); + + f->fd = fd; + f->direct = false; + if (fd < 0) + return fd; + + strncpy(f->devname, devname, sizeof(f->devname)); + f->devname[sizeof(f->devname) - 1] = '\0'; - if (f->fd < 0) - return f->fd; - if (f->devname != devname) { - strncpy(f->devname, devname, sizeof(f->devname)); - f->devname[sizeof(f->devname) - 1] = '\0'; - } memset(&f->cap, 0, sizeof(f->cap)); f->is_subdev = true; f->is_media = false; + f->direct = false; f->type = 0; f->have_query_ext_ctrl = false; f->have_ext_ctrls = false; @@ -501,16 +516,26 @@ static inline int v4l_subdev_open(struct v4l_fd *f, const char *devname, bool no return f->fd; } -static inline int v4l_media_open(struct v4l_fd *f, const char *devname, bool non_blocking) +static inline int v4l_subdev_open(struct v4l_fd *f, const char *devname, bool non_blocking) { - f->fd = f->open(f, devname, O_RDWR | (non_blocking ? O_NONBLOCK : 0)); + int fd = f->open(f, devname, O_RDWR | (non_blocking ? O_NONBLOCK : 0)); + + return v4l_subdev_s_fd(f, fd, devname); +} + +static inline int v4l_media_s_fd(struct v4l_fd *f, int fd, const char *devname) +{ + if (f->fd >= 0) + f->close(f); + + f->fd = fd; + f->direct = false; + if (fd < 0) + return fd; + + strncpy(f->devname, devname, sizeof(f->devname)); + f->devname[sizeof(f->devname) - 1] = '\0'; - if (f->fd < 0) - return f->fd; - if (f->devname != devname) { - strncpy(f->devname, devname, sizeof(f->devname)); - f->devname[sizeof(f->devname) - 1] = '\0'; - } memset(&f->cap, 0, sizeof(f->cap)); f->is_subdev = false; f->is_media = true; @@ -523,6 +548,13 @@ static inline int v4l_media_open(struct v4l_fd *f, const char *devname, bool non return f->fd; } +static inline int v4l_media_open(struct v4l_fd *f, const char *devname, bool non_blocking) +{ + int fd = f->open(f, devname, O_RDWR | (non_blocking ? O_NONBLOCK : 0)); + + return v4l_media_s_fd(f, fd, devname); +} + static inline int v4l_reopen(struct v4l_fd *f, bool non_blocking) { f->close(f); diff --git a/utils/qv4l2/general-tab.h b/utils/qv4l2/general-tab.h index f61d495452d0..9b4b5bcd5a46 100644 --- a/utils/qv4l2/general-tab.h +++ b/utils/qv4l2/general-tab.h @@ -226,7 +226,7 @@ private: bool g_direct() const { return m_fd->g_direct(); } void s_direct(bool direct) { m_fd->s_direct(direct); } - void querycap(v4l2_capability &cap) { return m_fd->querycap(cap); } + int querycap(v4l2_capability &cap) { return m_fd->querycap(cap); } int queryctrl(v4l2_queryctrl &qc) { return m_fd->queryctrl(qc); } int querymenu(v4l2_querymenu &qm) { return m_fd->querymenu(qm); } int g_fmt(v4l2_format &fmt, unsigned type = 0) { return m_fd->g_fmt(fmt); } _______________________________________________ linuxtv-commits mailing list linuxtv-commits@linuxtv.org https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits