aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2022-07-28 17:43:45 +0200
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2022-07-28 17:43:45 +0200
commit4cf258c24026895c74675a8c55efa7a14edb5ef3 (patch)
tree7a72fddb88a81868b237f98c4cf2a840afa5f20b
parent71112d2147625c79783691d44e17ff2217513e08 (diff)
v4l2-ctl/rds-ctl: move tuner info helpers to v4l2-info.cpp
Move the helper functions to decode tuner/modulator related fields to v4l2-info.cpp to avoid code duplication in between v4l2-ctl and rds-ctl. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r--utils/common/v4l2-info.cpp106
-rw-r--r--utils/common/v4l2-info.h18
-rw-r--r--utils/rds-ctl/rds-ctl.cpp77
-rw-r--r--utils/v4l2-ctl/v4l2-ctl-tuner.cpp112
4 files changed, 128 insertions, 185 deletions
diff --git a/utils/common/v4l2-info.cpp b/utils/common/v4l2-info.cpp
index 00a5fada..40d45471 100644
--- a/utils/common/v4l2-info.cpp
+++ b/utils/common/v4l2-info.cpp
@@ -768,3 +768,109 @@ std::string vbiflags2s(__u32 flags)
{
return flags2s(flags, vbi_def);
}
+
+std::string ttype2s(int type)
+{
+ switch (type) {
+ case V4L2_TUNER_RADIO: return "radio";
+ case V4L2_TUNER_ANALOG_TV: return "Analog TV";
+ case V4L2_TUNER_DIGITAL_TV: return "Digital TV";
+ case V4L2_TUNER_SDR: return "SDR";
+ case V4L2_TUNER_RF: return "RF";
+ default: return "unknown";
+ }
+}
+
+std::string audmode2s(int audmode)
+{
+ switch (audmode) {
+ case V4L2_TUNER_MODE_STEREO: return "stereo";
+ case V4L2_TUNER_MODE_LANG1: return "lang1";
+ case V4L2_TUNER_MODE_LANG2: return "lang2";
+ case V4L2_TUNER_MODE_LANG1_LANG2: return "bilingual";
+ case V4L2_TUNER_MODE_MONO: return "mono";
+ default: return "unknown";
+ }
+}
+
+std::string rxsubchans2s(int rxsubchans)
+{
+ std::string s;
+
+ if (rxsubchans & V4L2_TUNER_SUB_MONO)
+ s += "mono ";
+ if (rxsubchans & V4L2_TUNER_SUB_STEREO)
+ s += "stereo ";
+ if (rxsubchans & V4L2_TUNER_SUB_LANG1)
+ s += "lang1 ";
+ if (rxsubchans & V4L2_TUNER_SUB_LANG2)
+ s += "lang2 ";
+ if (rxsubchans & V4L2_TUNER_SUB_RDS)
+ s += "rds ";
+ return s;
+}
+
+std::string txsubchans2s(int txsubchans)
+{
+ std::string s;
+
+ if (txsubchans & V4L2_TUNER_SUB_MONO)
+ s += "mono ";
+ if (txsubchans & V4L2_TUNER_SUB_STEREO)
+ s += "stereo ";
+ if (txsubchans & V4L2_TUNER_SUB_LANG1)
+ s += "bilingual ";
+ if (txsubchans & V4L2_TUNER_SUB_SAP)
+ s += "sap ";
+ if (txsubchans & V4L2_TUNER_SUB_RDS)
+ s += "rds ";
+ return s;
+}
+
+std::string tcap2s(unsigned cap)
+{
+ std::string s;
+
+ if (cap & V4L2_TUNER_CAP_LOW)
+ s += "62.5 Hz ";
+ else if (cap & V4L2_TUNER_CAP_1HZ)
+ s += "1 Hz ";
+ else
+ s += "62.5 kHz ";
+ if (cap & V4L2_TUNER_CAP_NORM)
+ s += "multi-standard ";
+ if (cap & V4L2_TUNER_CAP_HWSEEK_BOUNDED)
+ s += "hwseek-bounded ";
+ if (cap & V4L2_TUNER_CAP_HWSEEK_WRAP)
+ s += "hwseek-wrap ";
+ if (cap & V4L2_TUNER_CAP_STEREO)
+ s += "stereo ";
+ if (cap & V4L2_TUNER_CAP_LANG1)
+ s += "lang1 ";
+ if (cap & V4L2_TUNER_CAP_LANG2)
+ s += "lang2 ";
+ if (cap & V4L2_TUNER_CAP_RDS)
+ s += "rds ";
+ if (cap & V4L2_TUNER_CAP_RDS_BLOCK_IO)
+ s += "rds-block-I/O ";
+ if (cap & V4L2_TUNER_CAP_RDS_CONTROLS)
+ s += "rds-controls ";
+ if (cap & V4L2_TUNER_CAP_FREQ_BANDS)
+ s += "freq-bands ";
+ if (cap & V4L2_TUNER_CAP_HWSEEK_PROG_LIM)
+ s += "hwseek-prog-lim ";
+ return s;
+}
+
+std::string modulation2s(unsigned modulation)
+{
+ switch (modulation) {
+ case V4L2_BAND_MODULATION_VSB:
+ return "VSB";
+ case V4L2_BAND_MODULATION_FM:
+ return "FM";
+ case V4L2_BAND_MODULATION_AM:
+ return "AM";
+ }
+ return "Unknown";
+}
diff --git a/utils/common/v4l2-info.h b/utils/common/v4l2-info.h
index 6ddd2ee5..35237853 100644
--- a/utils/common/v4l2-info.h
+++ b/utils/common/v4l2-info.h
@@ -118,4 +118,22 @@ std::string bufferflags2s(__u32 flags);
/* Return vbi flags description */
std::string vbiflags2s(__u32 flags);
+/* Return tuner type description */
+std::string ttype2s(int type);
+
+/* Return audio mode description */
+std::string audmode2s(int audmode);
+
+/* Return RX subchannels description */
+std::string rxsubchans2s(int rxsubchans);
+
+/* Return TX subchannels description */
+std::string txsubchans2s(int txsubchans);
+
+/* Return tuner capabilities description */
+std::string tcap2s(unsigned cap);
+
+/* Return band modulation description */
+std::string modulation2s(unsigned modulation);
+
#endif
diff --git a/utils/rds-ctl/rds-ctl.cpp b/utils/rds-ctl/rds-ctl.cpp
index 45770083..813b4f28 100644
--- a/utils/rds-ctl/rds-ctl.cpp
+++ b/utils/rds-ctl/rds-ctl.cpp
@@ -187,81 +187,6 @@ static int doioctl_name(int fd, unsigned long int request, void *parm, const cha
#define doioctl(n, r, p) doioctl_name(n, r, p, #r)
-static const char *audmode2s(int audmode)
-{
- switch (audmode) {
- case V4L2_TUNER_MODE_STEREO: return "stereo";
- case V4L2_TUNER_MODE_LANG1: return "lang1";
- case V4L2_TUNER_MODE_LANG2: return "lang2";
- case V4L2_TUNER_MODE_LANG1_LANG2: return "bilingual";
- case V4L2_TUNER_MODE_MONO: return "mono";
- default: return "unknown";
- }
-}
-
-static std::string rxsubchans2s(int rxsubchans)
-{
- std::string s;
-
- if (rxsubchans & V4L2_TUNER_SUB_MONO)
- s += "mono ";
- if (rxsubchans & V4L2_TUNER_SUB_STEREO)
- s += "stereo ";
- if (rxsubchans & V4L2_TUNER_SUB_LANG1)
- s += "lang1 ";
- if (rxsubchans & V4L2_TUNER_SUB_LANG2)
- s += "lang2 ";
- if (rxsubchans & V4L2_TUNER_SUB_RDS)
- s += "rds ";
- return s;
-}
-
-static std::string tcap2s(unsigned cap)
-{
- std::string s;
-
- if (cap & V4L2_TUNER_CAP_LOW)
- s += "62.5 Hz ";
- else
- s += "62.5 kHz ";
- if (cap & V4L2_TUNER_CAP_NORM)
- s += "multi-standard ";
- if (cap & V4L2_TUNER_CAP_HWSEEK_BOUNDED)
- s += "hwseek-bounded ";
- if (cap & V4L2_TUNER_CAP_HWSEEK_WRAP)
- s += "hwseek-wrap ";
- if (cap & V4L2_TUNER_CAP_STEREO)
- s += "stereo ";
- if (cap & V4L2_TUNER_CAP_LANG1)
- s += "lang1 ";
- if (cap & V4L2_TUNER_CAP_LANG2)
- s += "lang2 ";
- if (cap & V4L2_TUNER_CAP_RDS)
- s += "rds ";
- if (cap & V4L2_TUNER_CAP_RDS_BLOCK_IO)
- s += "rds-block-I/O ";
- if (cap & V4L2_TUNER_CAP_RDS_CONTROLS)
- s += "rds-controls ";
- if (cap & V4L2_TUNER_CAP_FREQ_BANDS)
- s += "freq-bands ";
- if (cap & V4L2_TUNER_CAP_HWSEEK_PROG_LIM)
- s += "hwseek-prog-lim ";
- return s;
-}
-
-static std::string modulation2s(unsigned modulation)
-{
- switch (modulation) {
- case V4L2_BAND_MODULATION_VSB:
- return "VSB";
- case V4L2_BAND_MODULATION_FM:
- return "FM";
- case V4L2_BAND_MODULATION_AM:
- return "AM";
- }
- return "Unknown";
-}
-
static bool is_radio_dev(const char *name)
{
return !memcmp(name, "radio", 5);
@@ -866,7 +791,7 @@ static void get_options(const int fd, const int capabilities, struct v4l2_freque
vt.rangelow / 16.0, vt.rangehigh / 16.0);
printf("\tSignal strength/AFC : %ld%%/%d\n",
lround(vt.signal / 655.25), vt.afc);
- printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode));
+ printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode).c_str());
printf("\tAvailable subchannels: %s\n",
rxsubchans2s(vt.rxsubchans).c_str());
}
diff --git a/utils/v4l2-ctl/v4l2-ctl-tuner.cpp b/utils/v4l2-ctl/v4l2-ctl-tuner.cpp
index 177aa8e6..2b0553d0 100644
--- a/utils/v4l2-ctl/v4l2-ctl-tuner.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-tuner.cpp
@@ -45,112 +45,6 @@ void tuner_usage()
);
}
-static const char *audmode2s(int audmode)
-{
- switch (audmode) {
- case V4L2_TUNER_MODE_STEREO: return "stereo";
- case V4L2_TUNER_MODE_LANG1: return "lang1";
- case V4L2_TUNER_MODE_LANG2: return "lang2";
- case V4L2_TUNER_MODE_LANG1_LANG2: return "bilingual";
- case V4L2_TUNER_MODE_MONO: return "mono";
- default: return "unknown";
- }
-}
-
-static const char *ttype2s(int type)
-{
- switch (type) {
- case V4L2_TUNER_RADIO: return "radio";
- case V4L2_TUNER_ANALOG_TV: return "Analog TV";
- case V4L2_TUNER_DIGITAL_TV: return "Digital TV";
- case V4L2_TUNER_SDR: return "SDR";
- case V4L2_TUNER_RF: return "RF";
- default: return "unknown";
- }
-}
-
-static std::string rxsubchans2s(int rxsubchans)
-{
- std::string s;
-
- if (rxsubchans & V4L2_TUNER_SUB_MONO)
- s += "mono ";
- if (rxsubchans & V4L2_TUNER_SUB_STEREO)
- s += "stereo ";
- if (rxsubchans & V4L2_TUNER_SUB_LANG1)
- s += "lang1 ";
- if (rxsubchans & V4L2_TUNER_SUB_LANG2)
- s += "lang2 ";
- if (rxsubchans & V4L2_TUNER_SUB_RDS)
- s += "rds ";
- return s;
-}
-
-static std::string txsubchans2s(int txsubchans)
-{
- std::string s;
-
- if (txsubchans & V4L2_TUNER_SUB_MONO)
- s += "mono ";
- if (txsubchans & V4L2_TUNER_SUB_STEREO)
- s += "stereo ";
- if (txsubchans & V4L2_TUNER_SUB_LANG1)
- s += "bilingual ";
- if (txsubchans & V4L2_TUNER_SUB_SAP)
- s += "sap ";
- if (txsubchans & V4L2_TUNER_SUB_RDS)
- s += "rds ";
- return s;
-}
-
-static std::string tcap2s(unsigned cap)
-{
- std::string s;
-
- if (cap & V4L2_TUNER_CAP_LOW)
- s += "62.5 Hz ";
- else if (cap & V4L2_TUNER_CAP_1HZ)
- s += "1 Hz ";
- else
- s += "62.5 kHz ";
- if (cap & V4L2_TUNER_CAP_NORM)
- s += "multi-standard ";
- if (cap & V4L2_TUNER_CAP_HWSEEK_BOUNDED)
- s += "hwseek-bounded ";
- if (cap & V4L2_TUNER_CAP_HWSEEK_WRAP)
- s += "hwseek-wrap ";
- if (cap & V4L2_TUNER_CAP_STEREO)
- s += "stereo ";
- if (cap & V4L2_TUNER_CAP_LANG1)
- s += "lang1 ";
- if (cap & V4L2_TUNER_CAP_LANG2)
- s += "lang2 ";
- if (cap & V4L2_TUNER_CAP_RDS)
- s += "rds ";
- if (cap & V4L2_TUNER_CAP_RDS_BLOCK_IO)
- s += "rds-block-I/O ";
- if (cap & V4L2_TUNER_CAP_RDS_CONTROLS)
- s += "rds-controls ";
- if (cap & V4L2_TUNER_CAP_FREQ_BANDS)
- s += "freq-bands ";
- if (cap & V4L2_TUNER_CAP_HWSEEK_PROG_LIM)
- s += "hwseek-prog-lim ";
- return s;
-}
-
-static std::string modulation2s(unsigned modulation)
-{
- switch (modulation) {
- case V4L2_BAND_MODULATION_VSB:
- return "VSB";
- case V4L2_BAND_MODULATION_FM:
- return "FM";
- case V4L2_BAND_MODULATION_AM:
- return "AM";
- }
- return "Unknown";
-}
-
static void parse_freq_seek(char *optarg, struct v4l2_hw_freq_seek &seek)
{
char *value;
@@ -395,7 +289,7 @@ void tuner_get(cv4l_fd &_fd)
if (doioctl(fd, VIDIOC_G_TUNER, &vt) == 0) {
printf("Tuner %d:\n", vt.index);
printf("\tName : %s\n", vt.name);
- printf("\tType : %s\n", ttype2s(vt.type));
+ printf("\tType : %s\n", ttype2s(vt.type).c_str());
printf("\tCapabilities : %s\n", tcap2s(vt.capability).c_str());
if (vt.capability & V4L2_TUNER_CAP_LOW)
printf("\tFrequency range : %.3f MHz - %.3f MHz\n",
@@ -410,7 +304,7 @@ void tuner_get(cv4l_fd &_fd)
if (vt.type != V4L2_TUNER_SDR && vt.type != V4L2_TUNER_RF) {
printf("\tSignal strength/AFC : %ld%%/%d\n",
lround(vt.signal / 655.35), vt.afc);
- printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode));
+ printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode).c_str());
printf("\tAvailable subchannels: %s\n", rxsubchans2s(vt.rxsubchans).c_str());
}
}
@@ -424,7 +318,7 @@ void tuner_get(cv4l_fd &_fd)
if (doioctl(fd, VIDIOC_G_MODULATOR, &mt) == 0) {
printf("Modulator %d:\n", modulator.index);
printf("\tName : %s\n", mt.name);
- printf("\tType : %s\n", ttype2s(mt.type));
+ printf("\tType : %s\n", ttype2s(mt.type).c_str());
printf("\tCapabilities : %s\n", tcap2s(mt.capability).c_str());
if (mt.capability & V4L2_TUNER_CAP_LOW)
printf("\tFrequency range : %.1f MHz - %.1f MHz\n",

Privacy Policy