Debian Codegraph @

utils/v4l2-tracer/v4l2-tracer-common.h

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright 2022 Collabora Ltd.
4 */
5
6 #ifndef V4L2_TRACER_COMMON_H
7 #define V4L2_TRACER_COMMON_H
8
9 #include "v4l2-info.h"
10 #include "codec-fwht.h"
11 #include "media-info.h"
12 #include <algorithm>
13 #include <dirent.h>
14 #include <fcntl.h>
15 #include <getopt.h>
16 #include <json.h>
17 #include <linux/media.h>
18 #include <linux/videodev2.h>
19 #include <list>
20 #include <poll.h>
21 #include <pthread.h>
22 #include <stdexcept>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/ioctl.h>
27 #include <sys/mman.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <unistd.h>
31 #include <unordered_map>
32 #include <vector>
33
34 #define STR(x) #x
35 #define STRING(x) STR(x)
36
37 #ifdef HAVE_STRERRORNAME_NP
38 #define STRERR(x) strerrorname_np(x)
39 #else
40 #define STRERR(x) strerror(x)
41 #endif
42
43 #ifndef __FILE_NAME__
44 #define __FILE_NAME__ __FILE__
45 #endif
46
47 #define line_info(fmt, args...) \
48 do { \
49 fprintf(stderr, "%s:%s:%d " fmt "\n", \
50 __FILE_NAME__, __func__, __LINE__, ##args); \
51 } while (0) \
52
53 #define debug_line_info(fmt, args...) \
54 do { \
55 if (is_debug()) \
56 line_info(fmt, ##args); \
57 } while (0) \
58
59 struct val_def {
60 __s64 val;
61 const char *str;
62 };
63
64 bool is_debug(void);
65 bool is_verbose(void);
66 void print_v4l2_tracer_info(void);
67 void print_usage(void);
68 std::string ver2s(unsigned int version);
69 std::string number2s_oct(long num);
70 std::string number2s(long num);
71 std::string val2s(long val, const val_def *def);
72 std::string fl2s(unsigned val, const flag_def *def);
73 std::string fl2s_buffer(__u32 flags);
74 std::string fl2s_fwht(__u32 flags);
75 long s2number(const char *char_str);
76 long s2val(const char *char_str, const val_def *def);
77 unsigned long s2flags(const char *char_str, const flag_def *def);
78 unsigned long s2flags_buffer(const char *char_str);
79 unsigned long s2flags_fwht(const char *char_str);
80 std::string which2s(unsigned long which);
81 std::string get_path_media(std::string driver);
82 std::string get_path_video(int media_fd, std::list<std::string> linked_entities);
83 std::list<std::string> get_linked_entities(int media_fd, std::string path_video);
84
85 constexpr val_def which_val_def[] = {
86 { V4L2_CTRL_WHICH_CUR_VAL, "V4L2_CTRL_WHICH_CUR_VAL" },
87 { V4L2_CTRL_WHICH_DEF_VAL, "V4L2_CTRL_WHICH_DEF_VAL" },
88 { V4L2_CTRL_WHICH_REQUEST_VAL, "V4L2_CTRL_WHICH_REQUEST_VAL" },
89 { V4L2_CTRL_WHICH_MIN_VAL, "V4L2_CTRL_WHICH_MIN_VAL" },
90 { V4L2_CTRL_WHICH_MAX_VAL, "V4L2_CTRL_WHICH_MAX_VAL" },
91 { -1, "" }
92 };
93
94 constexpr val_def open_val_def[] = {
95 { O_RDONLY, "O_RDONLY" },
96 { O_WRONLY, "O_WRONLY" },
97 { O_RDWR, "O_RDWR" },
98 { -1, "" }
99 };
100
101 #include "v4l2-tracer-info-gen.h"
102
103 #endif