An input channel could have been previously set with another application, like
v4l2-ctl, so if no input channel is specified use the previosly selected one.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -640,7 +640,8 @@ list of the supported standards, use the @option{list_standards} |
640 | 640 |
option. |
641 | 641 |
|
642 | 642 |
@item channel |
643 |
-Set the input channel number. Default to 0. |
|
643 |
+Set the input channel number. Default to -1, which means using the |
|
644 |
+previously selected channel. |
|
644 | 645 |
|
645 | 646 |
@item video_size |
646 | 647 |
Set the video frame size. The argument must be a string in the form |
... | ... |
@@ -894,14 +894,24 @@ static int v4l2_read_header(AVFormatContext *s1) |
894 | 894 |
if (s->fd < 0) |
895 | 895 |
return s->fd; |
896 | 896 |
|
897 |
- /* set tv video input */ |
|
898 |
- av_log(s1, AV_LOG_DEBUG, "Selecting input_channel: %d\n", s->channel); |
|
899 |
- if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &s->channel) < 0) { |
|
900 |
- res = AVERROR(errno); |
|
901 |
- av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_S_INPUT): %s\n", av_err2str(res)); |
|
902 |
- return res; |
|
897 |
+ if (s->channel != -1) { |
|
898 |
+ /* set video input */ |
|
899 |
+ av_log(s1, AV_LOG_DEBUG, "Selecting input_channel: %d\n", s->channel); |
|
900 |
+ if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &s->channel) < 0) { |
|
901 |
+ res = AVERROR(errno); |
|
902 |
+ av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_S_INPUT): %s\n", av_err2str(res)); |
|
903 |
+ return res; |
|
904 |
+ } |
|
905 |
+ } else { |
|
906 |
+ /* get current video input */ |
|
907 |
+ if (v4l2_ioctl(s->fd, VIDIOC_G_INPUT, &s->channel) < 0) { |
|
908 |
+ res = AVERROR(errno); |
|
909 |
+ av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_INPUT): %s\n", av_err2str(res)); |
|
910 |
+ return res; |
|
911 |
+ } |
|
903 | 912 |
} |
904 | 913 |
|
914 |
+ /* enum input */ |
|
905 | 915 |
input.index = s->channel; |
906 | 916 |
if (v4l2_ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) { |
907 | 917 |
res = AVERROR(errno); |
... | ... |
@@ -909,7 +919,7 @@ static int v4l2_read_header(AVFormatContext *s1) |
909 | 909 |
return res; |
910 | 910 |
} |
911 | 911 |
s->std_id = input.std; |
912 |
- av_log(s1, AV_LOG_DEBUG, "input_channel: %d, input_name: %s\n", |
|
912 |
+ av_log(s1, AV_LOG_DEBUG, "Current input_channel: %d, input_name: %s\n", |
|
913 | 913 |
s->channel, input.name); |
914 | 914 |
|
915 | 915 |
if (s->list_format) { |
... | ... |
@@ -1045,7 +1055,7 @@ static int v4l2_read_close(AVFormatContext *s1) |
1045 | 1045 |
|
1046 | 1046 |
static const AVOption options[] = { |
1047 | 1047 |
{ "standard", "set TV standard, used only by analog frame grabber", OFFSET(standard), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC }, |
1048 |
- { "channel", "set TV channel, used only by frame grabber", OFFSET(channel), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC }, |
|
1048 |
+ { "channel", "set TV channel, used only by frame grabber", OFFSET(channel), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, INT_MAX, DEC }, |
|
1049 | 1049 |
{ "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, |
1050 | 1050 |
{ "pixel_format", "set preferred pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, |
1051 | 1051 |
{ "input_format", "set preferred pixel format (for raw video) or codec name", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, |