Commit 457a994e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

v4l2: revector tuner setup

So the code is reusable for radio device nodes.
parent 0db42003
...@@ -116,28 +116,13 @@ static int SetupAudio (vlc_object_t *obj, int fd, ...@@ -116,28 +116,13 @@ static int SetupAudio (vlc_object_t *obj, int fd,
return 0; return 0;
} }
static int SetupTuner (vlc_object_t *obj, int fd, static int SetupTuner (vlc_object_t *obj, int fd, uint32_t idx)
const struct v4l2_input *restrict input)
{ {
switch (input->type) struct v4l2_tuner tuner = { .index = idx };
{
case V4L2_INPUT_TYPE_TUNER:
msg_Dbg (obj, "tuning required: tuner %"PRIu32, input->tuner);
break;
case V4L2_INPUT_TYPE_CAMERA:
msg_Dbg (obj, "no tuning required (analog baseband input)");
return 0;
default:
msg_Err (obj, "unknown input tuning type %"PRIu32, input->type);
return 0; // hopefully we can stream regardless...
}
struct v4l2_tuner tuner = { .index = input->tuner };
if (v4l2_ioctl (fd, VIDIOC_G_TUNER, &tuner) < 0) if (v4l2_ioctl (fd, VIDIOC_G_TUNER, &tuner) < 0)
{ {
msg_Err (obj, "cannot get tuner %"PRIu32" properties: %m", msg_Err (obj, "cannot get tuner %"PRIu32" properties: %m", idx);
input->tuner);
return -1; return -1;
} }
...@@ -194,31 +179,29 @@ static int SetupTuner (vlc_object_t *obj, int fd, ...@@ -194,31 +179,29 @@ static int SetupTuner (vlc_object_t *obj, int fd,
if (v4l2_ioctl (fd, VIDIOC_S_TUNER, &tuner) < 0) if (v4l2_ioctl (fd, VIDIOC_S_TUNER, &tuner) < 0)
{ {
msg_Err (obj, "cannot set tuner %"PRIu32" audio mode: %m", msg_Err (obj, "cannot set tuner %"PRIu32" audio mode: %m", idx);
input->tuner);
return -1; return -1;
} }
msg_Dbg (obj, "tuner %"PRIu32" audio mode %u set", input->tuner, msg_Dbg (obj, "tuner %"PRIu32" audio mode %u set", idx, tuner.audmode);
tuner.audmode);
/* Tune to the requested frequency */ /* Tune to the requested frequency */
uint32_t freq = var_InheritInteger (obj, CFG_PREFIX"tuner-frequency"); uint32_t freq = var_InheritInteger (obj, CFG_PREFIX"tuner-frequency");
if (freq != (uint32_t)-1) if (freq != (uint32_t)-1)
{ {
struct v4l2_frequency frequency = { struct v4l2_frequency frequency = {
.tuner = input->tuner, .tuner = idx,
.type = V4L2_TUNER_ANALOG_TV, .type = tuner.type,
.frequency = freq * 125 / 2 .frequency = freq * 125 / 2
}; };
if (v4l2_ioctl (fd, VIDIOC_S_FREQUENCY, &frequency) < 0) if (v4l2_ioctl (fd, VIDIOC_S_FREQUENCY, &frequency) < 0)
{ {
msg_Err (obj, "cannot tune tuner %u to frequency %u %sHz: %m", msg_Err (obj, "cannot tune tuner %"PRIu32
input->tuner, freq, mult); " to frequency %u %sHz: %m", idx, freq, mult);
return -1; return -1;
} }
msg_Dbg (obj, "tuner %"PRIu32" tuned to frequency %"PRIu32" %sHz", msg_Dbg (obj, "tuner %"PRIu32" tuned to frequency %"PRIu32" %sHz",
input->tuner, freq, mult); idx, freq, mult);
} }
else else
msg_Dbg (obj, "tuner not tuned"); msg_Dbg (obj, "tuner not tuned");
...@@ -285,7 +268,21 @@ int SetupInput (vlc_object_t *obj, int fd) ...@@ -285,7 +268,21 @@ int SetupInput (vlc_object_t *obj, int fd)
msg_Dbg (obj, "selected input %"PRIu32, input.index); msg_Dbg (obj, "selected input %"PRIu32, input.index);
SetupStandard (obj, fd, &input); SetupStandard (obj, fd, &input);
SetupTuner (obj, fd, &input);
switch (input.type)
{
case V4L2_INPUT_TYPE_TUNER:
msg_Dbg (obj, "tuning required: tuner %"PRIu32, input.tuner);
SetupTuner (obj, fd, input.tuner);
break;
case V4L2_INPUT_TYPE_CAMERA:
msg_Dbg (obj, "no tuning required (analog baseband input)");
break;
default:
msg_Err (obj, "unknown input tuning type %"PRIu32, input.type);
break; // hopefully we can stream regardless...
}
SetupAudio (obj, fd, &input); SetupAudio (obj, fd, &input);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment