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: v4l2-info: move mi_is_subdevice() to v4l2-info.cpp
Author:  Hans Verkuil <hans.verk...@cisco.com>
Date:    Sun Feb 4 15:36:22 2018 +0100

The mi_is_subdevice() is v4l2 specific, so it belongs in v4l2-info.cpp,
not in media-info.cpp. Move and rename to v4l2_is_subdevice accordingly.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>

 utils/common/media-info.cpp | 75 ++++++++-------------------------------------
 utils/common/media-info.h   |  4 +--
 utils/common/v4l2-info.cpp  | 68 +++++++++++++++++++++++++++++++++++++---
 utils/common/v4l2-info.h    |  5 +++
 utils/v4l2-ctl/v4l2-ctl.cpp |  2 +-
 5 files changed, 84 insertions(+), 70 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=a209f23976071ec8a1b4af09d798b6ad4b202b2f
diff --git a/utils/common/media-info.cpp b/utils/common/media-info.cpp
index 4ced684dc894..2ca042909822 100644
--- a/utils/common/media-info.cpp
+++ b/utils/common/media-info.cpp
@@ -34,11 +34,14 @@
 
 #include <fstream>
 
-static std::string num2s(unsigned num)
+static std::string num2s(unsigned num, bool is_hex = true)
 {
-       char buf[10];
+       char buf[16];
 
-       sprintf(buf, "%08x", num);
+       if (is_hex)
+               sprintf(buf, "%08x", num);
+       else
+               sprintf(buf, "%u", num);
        return buf;
 }
 
@@ -76,15 +79,14 @@ int mi_get_media_fd(int fd)
                return -1;
        }
 
-       char media_path[100];
-       if (snprintf(media_path, sizeof(media_path), 
"/sys/dev/char/%d:%d/device",
-                    major(sb.st_rdev), minor(sb.st_rdev)) == -1) {
-               fprintf(stderr, "failed to create media file path\n");
-               return -1;
-       }
+       std::string media_path("/sys/dev/char/");
+
+       media_path += num2s(major(sb.st_rdev), false) + ":" +
+               num2s(minor(sb.st_rdev), false) + "/device";
+
        DIR *dp;
        struct dirent *ep;
-       dp = opendir(media_path);
+       dp = opendir(media_path.c_str());
        if (dp == NULL)
                return -1;
        media_path[0] = 0;
@@ -101,59 +103,6 @@ int mi_get_media_fd(int fd)
        return media_fd;
 }
 
-bool mi_is_subdevice(int fd)
-{
-       struct stat sb;
-       if (fstat(fd, &sb) == -1) {
-               fprintf(stderr, "failed to stat file\n");
-               exit(1);
-       }
-
-       char uevent_path[100];
-       if (snprintf(uevent_path, sizeof(uevent_path), 
"/sys/dev/char/%d:%d/uevent",
-                    major(sb.st_rdev), minor(sb.st_rdev)) == -1) {
-               fprintf(stderr, "failed to create uevent file path\n");
-               exit(1);
-       }
-
-       std::ifstream uevent_file(uevent_path);
-       if (uevent_file.fail()) {
-               fprintf(stderr, "failed to open %s\n", uevent_path);
-               exit(1);
-       }
-
-       std::string line;
-
-       while (std::getline(uevent_file, line)) {
-               if (line.compare(0, 8, "DEVNAME="))
-                       continue;
-
-               static const char * devnames[] = {
-                       "v4l-subdev",
-                       "video",
-                       "vbi",
-                       "radio",
-                       "swradio",
-                       "v4l-touch",
-                       NULL
-               };
-
-               for (size_t i = 0; devnames[i]; i++) {
-                       size_t len = strlen(devnames[i]);
-
-                       if (!line.compare(8, len, devnames[i]) && 
isdigit(line[8+len])) {
-                               uevent_file.close();
-                               return i == 0;
-                       }
-               }
-       }
-
-       uevent_file.close();
-
-       fprintf(stderr, "unknown device name\n");
-       exit(1);
-}
-
 static const flag_def entity_flags_def[] = {
        { MEDIA_ENT_FL_DEFAULT, "default" },
        { MEDIA_ENT_FL_CONNECTOR, "connector" },
diff --git a/utils/common/media-info.h b/utils/common/media-info.h
index 2f84af3ef369..5716e951a981 100644
--- a/utils/common/media-info.h
+++ b/utils/common/media-info.h
@@ -25,9 +25,9 @@
 int mi_get_media_fd(int fd);
 
 /*
- * Test if the given fd corresponds to a sub-device.
+ * Show media controller information media_fd and (if >= 0) the
+ * corresponsing entity/interface information for the fd.
  */
-bool mi_is_subdevice(int fd);
 void mi_media_info_for_fd(int media_fd, int fd);
 
 #endif
diff --git a/utils/common/v4l2-info.cpp b/utils/common/v4l2-info.cpp
index 044b67782948..73f5b8f2750c 100644
--- a/utils/common/v4l2-info.cpp
+++ b/utils/common/v4l2-info.cpp
@@ -21,21 +21,81 @@
 #include <string.h>
 #include <inttypes.h>
 #include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <ctype.h>
 #include <errno.h>
 #include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/sysmacros.h>
+#include <dirent.h>
 
 #include <linux/videodev2.h>
 
-#include <string>
+#include <fstream>
 
-static std::string num2s(unsigned num)
+static std::string num2s(unsigned num, bool is_hex = true)
 {
-       char buf[10];
+       char buf[16];
 
-       sprintf(buf, "%08x", num);
+       if (is_hex)
+               sprintf(buf, "%08x", num);
+       else
+               sprintf(buf, "%u", num);
        return buf;
 }
 
+bool v4l2_is_subdevice(int fd)
+{
+       struct stat sb;
+       if (fstat(fd, &sb) == -1) {
+               fprintf(stderr, "failed to stat file\n");
+               exit(1);
+       }
+
+       std::string uevent_path("/sys/dev/char/");
+
+       uevent_path += num2s(major(sb.st_rdev), false) + ":" +
+               num2s(minor(sb.st_rdev), false) + "/uevent";
+
+       std::ifstream uevent_file(uevent_path);
+       if (uevent_file.fail()) {
+               fprintf(stderr, "failed to open %s\n", uevent_path.c_str());
+               exit(1);
+       }
+
+       std::string line;
+
+       while (std::getline(uevent_file, line)) {
+               if (line.compare(0, 8, "DEVNAME="))
+                       continue;
+
+               static const char *devnames[] = {
+                       "v4l-subdev",
+                       "video",
+                       "vbi",
+                       "radio",
+                       "swradio",
+                       "v4l-touch",
+                       NULL
+               };
+
+               for (size_t i = 0; devnames[i]; i++) {
+                       size_t len = strlen(devnames[i]);
+
+                       if (!line.compare(8, len, devnames[i]) && 
isdigit(line[8+len])) {
+                               uevent_file.close();
+                               return i == 0;
+                       }
+               }
+       }
+
+       uevent_file.close();
+
+       fprintf(stderr, "unknown device name\n");
+       exit(1);
+}
+
 typedef struct {
        unsigned flag;
        const char *str;
diff --git a/utils/common/v4l2-info.h b/utils/common/v4l2-info.h
index ae017473ea77..455a6719acd1 100644
--- a/utils/common/v4l2-info.h
+++ b/utils/common/v4l2-info.h
@@ -18,6 +18,11 @@
 #ifndef _V4L2_INFO_H
 #define _V4L2_INFO_H
 
+/*
+ * Test if the given fd corresponds to a sub-device.
+ */
+bool v4l2_is_subdevice(int fd);
+
 /* Print capability information */
 void v4l2_info_capability(const v4l2_capability &cap);
 
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index 03a82a946761..64293059aadc 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -982,7 +982,7 @@ int main(int argc, char **argv)
                exit(1);
        }
        verbose = options[OptVerbose];
-       is_subdev = mi_is_subdevice(fd);
+       is_subdev = v4l2_is_subdevice(fd);
        if (is_subdev)
                options[OptUseWrapper] = 0;
 

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to