Ticket #11018: 0003-libmythtv-EIT-ActiveScan-Control-optimized-026.commit

File 0003-libmythtv-EIT-ActiveScan-Control-optimized-026.commit, 9.0 KB (added by Shinck@…, 7 years ago)

Patch for master / 0.26-rc

Line 
1From 4d9594d56ad423782a320352baf548562641337d Mon Sep 17 00:00:00 2001
2From: Sascha Hinck <SHinck@web.de>
3Date: Sun, 26 Aug 2012 01:23:24 +0200
4Subject: [PATCH] libmythtv: Stop EIT-Active scan during recording
5
6During recording and Live-TV EIT-Active scan will be stopped on all
7Capture-Cards. Active-Scan-IdleTimer will be restarted after the last
8recording exited.
9---
10 mythtv/libs/libmythtv/eitscanner.cpp         |    4 ++
11 mythtv/libs/libmythtv/tv_rec.cpp             |   92 +++++++++++++++++++++++++-
12 mythtv/libs/libmythtv/tv_rec.h               |    3 +
13 mythtv/programs/mythbackend/main_helpers.cpp |    4 +-
14 4 files changed, 100 insertions(+), 3 deletions(-)
15
16diff --git a/mythtv/libs/libmythtv/eitscanner.cpp b/mythtv/libs/libmythtv/eitscanner.cpp
17index 0c2a70e..8063899 100644
18--- a/mythtv/libs/libmythtv/eitscanner.cpp
19+++ b/mythtv/libs/libmythtv/eitscanner.cpp
20@@ -226,6 +226,8 @@ void EITScanner::StopPassiveScan(void)
21 
22     eitHelper->WriteEITCache();
23     eitHelper->SetSourceID(0);
24+
25+    LOG(VB_EIT, LOG_INFO, LOC_ID + "Stopped passive scan.");
26 }
27 
28 void EITScanner::StartActiveScan(TVRec *_rec, uint max_seconds_per_source)
29@@ -302,4 +304,6 @@ void EITScanner::StopActiveScan(void)
30         activeScanCond.wait(&lock, 100);
31 
32     rec = NULL;
33+
34+    LOG(VB_EIT, LOG_INFO, LOC_ID + "Stopped active scan.");
35 }
36diff --git a/mythtv/libs/libmythtv/tv_rec.cpp b/mythtv/libs/libmythtv/tv_rec.cpp
37index 5387ce5..7063660 100644
38--- a/mythtv/libs/libmythtv/tv_rec.cpp
39+++ b/mythtv/libs/libmythtv/tv_rec.cpp
40@@ -36,6 +36,7 @@
41 #include "tv_rec.h"
42 #include "mythdate.h"
43 #include "osd.h"
44+#include "cardutil.h"
45 
46 #define DEBUG_CHANNEL_PREFIX 0 /**< set to 1 to channel prefixing */
47 
48@@ -988,6 +989,10 @@ void TVRec::HandleStateChange(void)
49 
50     bool changed = false;
51 
52+    LOG(VB_GENERAL, LOG_INFO, LOC + "GetCardIDs to stop EITscan");
53+    vector<uint> cardids = CardUtil::GetCardIDs("","DVB","");
54+    uint no_cards = cardids.size();
55+
56     QString transMsg = QString(" %1 to %2")
57         .arg(StateToString(nextState))
58         .arg(StateToString(desiredNextState));
59@@ -1012,11 +1017,46 @@ void TVRec::HandleStateChange(void)
60     if (TRANSITION(kState_None, kState_WatchingLiveTV))
61     {
62         tuningRequests.enqueue(TuningRequest(kFlagLiveTV));
63+        for (uint i = 0; i < no_cards; i++)
64+        {
65+           if (cardids[i] != cardid)
66+           {       
67+               TVRec *rec = GetTVRec(cardids[i]);
68+               if (rec && !rec->HasFlags(kFlagEITScanPaused))
69+                   rec->SetFlags(kFlagEITScanPaused);
70+           }
71+        }     
72         SET_NEXT();
73     }
74     else if (TRANSITION(kState_WatchingLiveTV, kState_None))
75     {
76         tuningRequests.enqueue(TuningRequest(kFlagKillRec|kFlagKillRingBuffer));
77+        eitScanStartTime = QDateTime::currentDateTime();
78+        uint j = 0;
79+        TVRec *arec = NULL;
80+        for (uint i = 0; i < no_cards; i++)
81+        {
82+            if (cardids[i] != cardid)
83+            {     
84+                TVRec *rec = GetTVRec(cardids[i]);       
85+                if (!HasFlags(kFlagEITScanPaused))
86+                {             
87+                    if (rec && rec->HasFlags(kFlagEITScanPaused))
88+                    {
89+                        rec->eitScanStartTime = eitScanStartTime.addSecs(
90+                            eitCrawlIdleStart + eit_start_rand(cardids[i], eitTransportTimeout));
91+                        rec->ClearFlags(kFlagEITScanPaused);
92+                        LOG(VB_IDLE, LOG_INFO, LOC + "Start EIT-ActiveScanIdle-Timer for " +
93+                            QString("cardid %1, next start time: ").arg(cardids[i]) +
94+                                rec->eitScanStartTime.toString(Qt::ISODate));
95+                    }
96+                }
97+                else if (rec && rec->GetState() != kState_None)
98+                    arec = rec; j++;
99+            }                 
100+        }
101+        if (j == 1)
102+            arec->ClearFlags(kFlagEITScanPaused);       
103         SET_NEXT();
104     }
105     else if (TRANSITION(kState_WatchingLiveTV, kState_RecordingOnly))
106@@ -1029,6 +1069,15 @@ void TVRec::HandleStateChange(void)
107     {
108         SetPseudoLiveTVRecording(NULL);
109         tuningRequests.enqueue(TuningRequest(kFlagRecording, curRecording));
110+        for (uint i = 0; i < no_cards; i++)
111+       {
112+           if (cardids[i] != cardid)
113+           {       
114+               TVRec *rec = GetTVRec(cardids[i]);
115+               if (rec && !rec->HasFlags(kFlagEITScanPaused))
116+                       rec->SetFlags(kFlagEITScanPaused);
117+           }
118+       }       
119         SET_NEXT();
120     }
121     else if (TRANSITION(kState_RecordingOnly, kState_None))
122@@ -1036,6 +1085,32 @@ void TVRec::HandleStateChange(void)
123         tuningRequests.enqueue(
124             TuningRequest(kFlagCloseRec|kFlagKillRingBuffer|
125                           (GetFlags()&kFlagKillRec)));
126+        eitScanStartTime = QDateTime::currentDateTime();
127+        uint j = 0;
128+        TVRec *arec = NULL;
129+        for (uint i = 0; i < no_cards; i++)
130+        {
131+            if (cardids[i] != cardid)
132+            {     
133+                TVRec *rec = GetTVRec(cardids[i]);       
134+                if (!HasFlags(kFlagEITScanPaused))
135+                {             
136+                    if (rec && rec->HasFlags(kFlagEITScanPaused))
137+                    {
138+                        rec->eitScanStartTime = eitScanStartTime.addSecs(
139+                            eitCrawlIdleStart + eit_start_rand(cardids[i], eitTransportTimeout));
140+                        rec->ClearFlags(kFlagEITScanPaused);
141+                        LOG(VB_IDLE, LOG_INFO, LOC + "Start EIT-ActiveScanIdle-Timer for " +
142+                            QString("cardid %1, next start time: ").arg(cardids[i]) +
143+                                rec->eitScanStartTime.toString(Qt::ISODate));
144+                    }
145+                }
146+                else if (rec && rec->GetState() != kState_None)
147+                    arec = rec; j++;
148+            }                 
149+        }
150+        if (j == 1)
151+            arec->ClearFlags(kFlagEITScanPaused);       
152         SET_NEXT();
153     }
154 
155@@ -1147,6 +1222,9 @@ void TVRec::CloseChannel(void)
156          CardUtil::IsV4L(genOpt.cardtype)))
157     {
158         channel->Close();
159+       LOG(VB_GENERAL, LOG_INFO, LOC + QString("Close Card %1")
160+               .arg(CardUtil::ProbeDVBFrontendName(CardUtil::GetVideoDevice(cardid))) );
161+//                     GetDeviceLabel(cardid))
162     }
163 }
164 
165@@ -1391,7 +1469,8 @@ void TVRec::run(void)
166         }
167 
168         if (scanner && channel &&
169-            MythDate::current() > eitScanStartTime)
170+            MythDate::current() > eitScanStartTime &&
171+           !HasFlags(kFlagEITScanPaused))
172         {
173             if (!dvbOpt.dvb_eitscan)
174             {
175@@ -1413,6 +1492,15 @@ void TVRec::run(void)
176             }
177         }
178 
179+        //Stop EIT-Scanning if recording begins on another card,
180+        if (scanner && HasFlags(kFlagEITScanPaused) &&
181+            HasFlags(kFlagEITScannerRunning))
182+        {
183+            scanner->StopActiveScan();
184+            ClearFlags(kFlagEITScannerRunning);
185+            TuningShutdowns(TuningRequest(kFlagNoRec));
186+        }
187+
188         // We should be no more than a few thousand milliseconds,
189         // as the end recording code does not have a trigger...
190         // NOTE: If you change anything here, make sure that
191@@ -4272,6 +4360,8 @@ QString TVRec::FlagToString(uint f)
192         msg += "Errored,";
193     if (kFlagCancelNextRecording & f)
194         msg += "CancelNextRecording,";
195+    if (kFlagEITScanPaused & f)
196+        msg += "EITScanPaused,";
197 
198     // Tuning flags
199     if ((kFlagRec & f) == kFlagRec)
200diff --git a/mythtv/libs/libmythtv/tv_rec.h b/mythtv/libs/libmythtv/tv_rec.h
201index 664b712..f93ab80 100644
202--- a/mythtv/libs/libmythtv/tv_rec.h
203+++ b/mythtv/libs/libmythtv/tv_rec.h
204@@ -156,6 +156,8 @@ class MTV_PUBLIC TVRec : public SignalMonitorListener, public QRunnable
205     void FinishRecording(void)  { SetFlags(kFlagFinishRecording); }
206     /// \brief Tells TVRec that the frontend's TV class is ready for messages.
207     void FrontendReady(void)    { SetFlags(kFlagFrontendReady); }
208+    void PauseEITActiveScan(void)    { SetFlags(kFlagEITScanPaused); }
209+    void RestartEITActiveScan(void)    { ClearFlags(kFlagEITScanPaused); }
210     void CancelNextRecording(bool cancel);
211     ProgramInfo *GetRecording(void);
212 
213@@ -411,6 +413,7 @@ class MTV_PUBLIC TVRec : public SignalMonitorListener, public QRunnable
214     static const uint kFlagFinishRecording      = 0x00000008;
215     static const uint kFlagErrored              = 0x00000010;
216     static const uint kFlagCancelNextRecording  = 0x00000020;
217+    static const uint kFlagEITScanPaused       = 0x00000040;
218 
219     // Tuning flags
220     /// final result desired is LiveTV recording
221diff --git a/mythtv/programs/mythbackend/main_helpers.cpp b/mythtv/programs/mythbackend/main_helpers.cpp
222index bc9d698..d2a8b8e 100644
223--- a/mythtv/programs/mythbackend/main_helpers.cpp
224+++ b/mythtv/programs/mythbackend/main_helpers.cpp
225@@ -195,8 +195,8 @@ bool setupTVs(bool ismaster, bool &error)
226                 }
227                 else
228                 {
229-                    LOG(VB_GENERAL, LOG_ERR, "Problem with capture cards" +
230-                            cidmsg + "failed init");
231+                    LOG(VB_GENERAL, LOG_ERR, "Problem with capture cards - " +
232+                            cidmsg + " failed init");
233                     delete tv;
234                 }
235             }