[FFmpeg-devel] [PATCH] v4l2: Select input immediately after opening the device

Giorgio Vazzana mywing81 at gmail.com
Thu Jan 24 19:54:26 CET 2013

2013/1/24 Stephan Hilb <stephan at ecshi.net>:
>> +    av_log(s1, AV_LOG_DEBUG, "Selecting V4L2 input_id: %d\n",
>> s->channel);
>> +    if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &s->channel) < 0) {
>> +        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input
>> failed\n");
>> +        return AVERROR(EIO);
>> +    }
>> +
>> +    input.index = s->channel;
>> +    if (v4l2_ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
>> +        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input
>> failed\n");
>> +        return AVERROR(EIO);
>> +    }
>> +    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d,
>> input: %s\n",
>> +            s->channel, input.name);

Hi, thanks for the review.

> I prefer to VIDIOC_ENUMINPUT before VIDIOC_S_INPUT but that's not
> absolutely necessary (then you can use input.name in your first log
> message and leave the last log message out as it will say the same
> thing).

The two calls were in that order, and here's why I switched them:
first, I want to point out that VIDIOC_ENUMINPUT is not strictly
necessary, its only purpose is to get input.name so that we can print
it  in the debug output.
I used the approach of printing a message that informs the user on
what operation the program is trying to do, and then print an error if
something went wrong, or another message that confirms that the
operation was successful.
The advantage is that an user not familiar with the code can see in
the debug output what the program was doing when it failed, instead of
only an error message about a ioctl. The disadvantage is that you need
two av_log().
Anyway, I fine with either way really, so I'm happy to change the
patch if necessary.

> Otherwise I think the patch is fine.


Giorgio Vazzana

More information about the ffmpeg-devel mailing list