summaryrefslogtreecommitdiff
path: root/tuner.c
diff options
context:
space:
mode:
Diffstat (limited to 'tuner.c')
-rw-r--r--tuner.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/tuner.c b/tuner.c
index eb0cda8..3d8e1ff 100644
--- a/tuner.c
+++ b/tuner.c
@@ -35,6 +35,11 @@ static unsigned long tuner_min, tuner_max;
static unsigned long tuner_freq = 0;
+static inline bool tuner_is_open()
+{
+ return tuner_fd != -1;
+}
+
static inline unsigned long v4l_to_hz(unsigned f)
{
if (tuner_precise) {
@@ -73,7 +78,7 @@ static bool tuner_tune(unsigned long hz)
.frequency = hz_to_v4l(hz)
};
- g_return_val_if_fail(tuner_fd != -1, false);
+ g_return_val_if_fail(tuner_is_open(), false);
if (ioctl(tuner_fd, VIDIOC_S_FREQUENCY, &t_freq) < 0) {
g_warning("Failed to tune: %s", strerror(errno));
@@ -89,7 +94,7 @@ static unsigned long tuner_get_tuned_freq()
.tuner = TUNER_DEVICE_ID
};
- g_return_val_if_fail(tuner_fd != -1, 0);
+ g_return_val_if_fail(tuner_is_open(), 0);
if (ioctl(tuner_fd, VIDIOC_G_FREQUENCY, &t_freq) < 0) {
g_warning("Failed to get freq: %s", strerror(errno));
@@ -105,7 +110,7 @@ static uint16_t tuner_get_signal()
.index = TUNER_DEVICE_ID
};
- g_return_val_if_fail(tuner_fd != -1, 0);
+ g_return_val_if_fail(tuner_is_open(), 0);
if (ioctl(tuner_fd, VIDIOC_G_TUNER, &t_tuner) < 0) {
g_warning("Failed to get signal level: %s", strerror(errno));
@@ -168,7 +173,12 @@ bool tuner_set_frequency(double mhz)
{
unsigned long hz = mhz_to_hz(mhz);
- if (tuner_tune(hz)) {
+ if (!tuner_is_open()) {
+ // This is not an error; we just store the frequency
+ // and will set it later, when the tuner is opened.
+ tuner_freq = hz;
+ return true;
+ } else if (tuner_tune(hz)) {
g_message("Tuned to %.1f Mhz", mhz);
server_notify_tuned(mhz);
tuner_freq = hz;
@@ -187,7 +197,7 @@ bool tuner_search(bool forward)
.seek_upward = forward
};
- g_return_val_if_fail(tuner_fd != -1, false);
+ g_return_val_if_fail(tuner_is_open(), false);
if (ioctl(tuner_fd, VIDIOC_S_HW_FREQ_SEEK, &t_freq_seek) < 0) {
g_warning("Failed to start seek: %s", strerror(errno));