summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/mythtv/trunk/mythtv-svn/hdpvr-v4lchannel-tweak.patch
blob: 3535310969691cd90fdcb94920e53f209530eae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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;
         }
     }