Index: libs/libmythtv/v4lchannel.h =================================================================== --- libs/libmythtv/v4lchannel.h (revision 18874) +++ libs/libmythtv/v4lchannel.h (working copy) @@ -103,6 +103,8 @@ VidModV4L2 videomode_v4l2; ///< Current video mode if 'usingv4l2' is true int defaultFreqTable; + int prev_inputNumV4L; + v4l2_std_id prev_vid_mode; }; #endif Index: libs/libmythtv/v4lchannel.cpp =================================================================== --- libs/libmythtv/v4lchannel.cpp (revision 18874) +++ libs/libmythtv/v4lchannel.cpp (working copy) @@ -40,7 +40,8 @@ device_name(QString::null), driver_name(QString::null), curList(NULL), totalChannels(0), currentFormat(""), is_dtv(false), - usingv4l2(false), defaultFreqTable(1) + usingv4l2(false), defaultFreqTable(1), + prev_inputNumV4L(-1), prev_vid_mode(-1) { } @@ -795,62 +796,75 @@ { VERBOSE(VB_CHANNEL, LOC + msg + "(v4l v2)"); - int ioctlval = ioctl(videofd, VIDIOC_S_INPUT, &inputNumV4L); + int ioctlval; + bool streamingDisabled = false; + int streamType = V4L2_BUF_TYPE_VIDEO_CAPTURE; - // ConvertX (wis-go7007) requires streaming to be disabled - // before an input switch, do this if initial switch failed. - bool streamingDisabled = false; - int streamType = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if ((ioctlval < 0) && (errno == EBUSY)) + if (prev_inputNumV4L != inputNumV4L) { - ioctlval = ioctl(videofd, VIDIOC_STREAMOFF, &streamType); + ioctlval = ioctl(videofd, VIDIOC_S_INPUT, &inputNumV4L); + + // ConvertX (wis-go7007) requires streaming to be disabled + // before an input switch, do this if initial switch failed. + if ((ioctlval < 0) && (errno == EBUSY)) + { + ioctlval = ioctl(videofd, VIDIOC_STREAMOFF, &streamType); + if (ioctlval < 0) + { + VERBOSE(VB_IMPORTANT, LOC_ERR + msg + + "\n\t\t\twhile disabling streaming (v4l v2)" + ENO); + + ok = false; + ioctlval = 0; + } + else + { + streamingDisabled = true; + + // Resend the input switch ioctl. + ioctlval = ioctl(videofd, VIDIOC_S_INPUT, &inputNumV4L); + } + } + if (ioctlval < 0) { VERBOSE(VB_IMPORTANT, LOC_ERR + msg + - "\n\t\t\twhile disabling streaming (v4l v2)" + ENO); + "\n\t\t\twhile setting input (v4l v2)" + ENO); ok = false; - ioctlval = 0; } - else - { - streamingDisabled = true; - // Resend the input switch ioctl. - ioctlval = ioctl(videofd, VIDIOC_S_INPUT, &inputNumV4L); - } + prev_inputNumV4L = inputNumV4L; } - if (ioctlval < 0) - { - VERBOSE(VB_IMPORTANT, LOC_ERR + msg + - "\n\t\t\twhile setting input (v4l v2)" + ENO); - - ok = false; - } - v4l2_std_id vid_mode = format_to_mode(newFmt, 2); - ioctlval = ioctl(videofd, VIDIOC_S_STD, &vid_mode); - if (ioctlval < 0) - { - VERBOSE(VB_IMPORTANT, LOC_ERR + msg + - "\n\t\t\twhile setting format (v4l v2)" + ENO); - ok = false; - } - - // ConvertX (wis-go7007) requires streaming to be disabled - // before an input switch, here we try to re-enable streaming. - if (streamingDisabled) + if (prev_vid_mode != vid_mode) { - ioctlval = ioctl(videofd, VIDIOC_STREAMON, &streamType); + ioctlval = ioctl(videofd, VIDIOC_S_STD, &vid_mode); if (ioctlval < 0) { VERBOSE(VB_IMPORTANT, LOC_ERR + msg + - "\n\t\t\twhile reenabling streaming (v4l v2)" + ENO); + "\n\t\t\twhile setting format (v4l v2)" + ENO); ok = false; } + + // ConvertX (wis-go7007) requires streaming to be disabled + // before an input switch, here we try to re-enable streaming. + if (streamingDisabled) + { + ioctlval = ioctl(videofd, VIDIOC_STREAMON, &streamType); + if (ioctlval < 0) + { + VERBOSE(VB_IMPORTANT, LOC_ERR + msg + + "\n\t\t\twhile reenabling streaming (v4l v2)" + + ENO); + + ok = false; + } + } + prev_vid_mode = vid_mode; } }