aboutsummaryrefslogtreecommitdiffstats
path: root/utils/common/media-info.cpp
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2018-02-04 15:36:22 +0100
committerHans Verkuil <hans.verkuil@cisco.com>2018-02-04 15:36:22 +0100
commita209f23976071ec8a1b4af09d798b6ad4b202b2f (patch)
tree7dcdf8991b5d56f874a76ef0157b2a50551df2fd /utils/common/media-info.cpp
parent824fa2dce45974c0a421baee9d287dd623973e8c (diff)
v4l2-info: move mi_is_subdevice() to v4l2-info.cpp
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.verkuil@cisco.com>
Diffstat (limited to 'utils/common/media-info.cpp')
-rw-r--r--utils/common/media-info.cpp75
1 files changed, 12 insertions, 63 deletions
diff --git a/utils/common/media-info.cpp b/utils/common/media-info.cpp
index 4ced684d..2ca04290 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" },

Privacy Policy