[mythtv] [Patch] updated hdtv-signalcheck patch (v7)

Daniel Thor Kristjansson danielk at cat.nyu.edu
Fri Apr 30 10:19:42 EDT 2004


]For me to apply this, please:
]- Get rid of the tabs
]- Don't get the settings (ATSCCheckSignalWait, ATSCCheckSignalThreshold),
]unless it's going to use them.  Way it is now, that's 2 extra database hits
]per channel change for everyone, not just people who are going to use this.

I got rid of the tabs and put an "if (usingstrength)" around the
database lookups.

-- Daniel
-------------- next part --------------
Index: libs/libmythtv/channel.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/channel.cpp,v
retrieving revision 1.67
diff -u -r1.67 channel.cpp
--- libs/libmythtv/channel.cpp	19 Apr 2004 10:35:37 -0000	1.67
+++ libs/libmythtv/channel.cpp	30 Apr 2004 14:07:40 -0000
@@ -47,7 +47,7 @@
         isopen = true;
     else
     {
-         cerr << "Channel::Open(): Can't open: " << device << endl;
+         VERBOSE(VB_IMPORTANT, QString("Channel::Open(): Can't open: %1").arg(device));
          perror(device.ascii());
          return false;
     }
@@ -282,8 +282,8 @@
 
         if (chancount > totalChannels)
         {
-            cerr << "Error, couldn't find any available channels.\n";
-            cerr << "Your database is most likely setup incorrectly.\n";
+            VERBOSE(VB_IMPORTANT, "Error, couldn't find any available channels.");
+            VERBOSE(VB_IMPORTANT, "Your database is most likely setup incorrectly.");
             break;
         }
     }
@@ -315,8 +315,8 @@
 
         if (chancount > totalChannels)
         {
-            cerr << "Error, couldn't find any available channels.\n";
-            cerr << "Your database is most likely setup incorrectly.\n";
+            VERBOSE(VB_IMPORTANT, "Error, couldn't find any available channels.");
+            VERBOSE(VB_IMPORTANT, "Your database is most likely setup incorrectly.");
             break;
         }
     }
@@ -330,7 +330,7 @@
     
     if (!Open())
     {
-        cerr << "channel object wasn't open, can't change channels\n";
+        VERBOSE(VB_IMPORTANT, "Channel object wasn't open, can't change channels");
         return false;
     }
 
@@ -485,6 +485,8 @@
         return false;
 
     int frequency = curList[i].freq * 16 / 1000 + finetune;
+    VERBOSE(VB_CHANNEL, QString("TuneTo(%1) curList[i].freq(%2) freq*16(%3)")
+            .arg(channum).arg(curList[i].freq).arg(frequency));
 
     VERBOSE(VB_CHANNEL, QString("TuneTo(%1) curList[i].freq(%2)")
                                 .arg(channum).arg(curList[i].freq));
@@ -496,6 +498,13 @@
 {
     VERBOSE(VB_CHANNEL, QString("TuneToFrequency(%1)").arg(frequency));
 
+    int signalThresholdWait = 5000;
+    int signalThreshold = 65;
+    if (usingstrength) {
+        gContext->GetNumSetting("ATSCCheckSignalWait", 5000);
+        gContext->GetNumSetting("ATSCCheckSignalThreshold", 65);
+    }
+
     if (usingv4l2)
     {
         struct v4l2_frequency vf;
@@ -508,7 +517,7 @@
             perror("VIDIOC_S_FREQUENCY");
             return false;
         }
-        return CheckSignal();
+        return CheckSignal(signalThresholdWait, signalThreshold);
     }
 
     if (ioctl(videofd, VIDIOCSFREQ, &frequency) == -1)
@@ -517,7 +526,7 @@
         return false;
     }
 
-    return CheckSignal();
+    return CheckSignal(signalThresholdWait, signalThreshold);
 }
 
 void Channel::SwitchToInput(int newcapchannel, bool setstarting)
Index: libs/libmythtv/tv_rec.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_rec.cpp,v
retrieving revision 1.143
diff -u -r1.143 tv_rec.cpp
--- libs/libmythtv/tv_rec.cpp	19 Apr 2004 10:35:36 -0000	1.143
+++ libs/libmythtv/tv_rec.cpp	30 Apr 2004 14:07:41 -0000
@@ -94,7 +94,7 @@
     }
     else // "V4L" or "MPEG", ie, analog TV, or "HDTV"
     {
-        Channel *achannel = new Channel(this, videodev);
+        Channel *achannel = new Channel(this, videodev, (cardtype == "HDTV"));
         channel = achannel; // here for SetFormat()->RetrieveInputChannels()
         channel->Open();
         achannel->SetFormat(gContext->GetSetting("TVFormat"));
@@ -486,26 +486,47 @@
         autoTranscode = profile.byName("autotranscode")->getValue().toInt();
 
         SetupRecorder(profile);
-        nvr->SetRecording(curRecording);
-        nvr->SetDB(db_conn, &db_lock);
+        bool error=false;
         if (channel != NULL)
-            nvr->ChannelNameChanged(channel->GetCurrentName());
-
-        SetVideoFiltersForChannel(channel, channel->GetCurrentName());
-        if (channel->Open())
-        {
-            channel->SetBrightness();
-            channel->SetContrast();
-            channel->SetColour();
-            channel->SetHue();
-            channel->Close();
-        }
-
-        pthread_create(&encode, NULL, SpawnEncode, nvr);
-
-        while (!nvr->IsRecording() && !nvr->IsErrored())
-            usleep(50);
-
+        { 
+            // If there is a tuner make sure this is a valid station
+            // hdtv will block for a long time if we try to get
+            // mpeg ts packets from outer space.
+            bool success=channel->Open();
+            if (success)
+            {
+                success=channel->SetChannelByString(channel->GetCurrentName());
+                if (!success)
+                {
+                    VERBOSE(VB_IMPORTANT, "Signal level too low?");
+                    error = true;
+                }
+                channel->Close();
+            } else 
+                error = true;
+        }
+        if (!error) 
+        {
+            nvr->SetRecording(curRecording);
+            nvr->SetDB(db_conn, &db_lock);
+            if (channel != NULL)
+                nvr->ChannelNameChanged(channel->GetCurrentName());
+            
+            SetVideoFiltersForChannel(channel, channel->GetCurrentName());
+            if (channel->Open())
+            {
+                channel->SetBrightness();
+                channel->SetContrast();
+                channel->SetColour();
+                channel->SetHue();
+                channel->Close();
+            }
+            pthread_create(&encode, NULL, SpawnEncode, nvr);
+            
+            while (!nvr->IsRecording() && !nvr->IsErrored())
+                usleep(50);
+        } else 
+            VERBOSE(VB_IMPORTANT, "Tuning Error -- aborting recording");
         if (nvr->IsRecording())
         {
             // evil.
Index: programs/mythfrontend/globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/globalsettings.cpp,v
retrieving revision 1.160
diff -u -r1.160 globalsettings.cpp
--- programs/mythfrontend/globalsettings.cpp	30 Apr 2004 06:56:08 -0000	1.160
+++ programs/mythfrontend/globalsettings.cpp	30 Apr 2004 14:07:43 -0000
@@ -1339,6 +1339,35 @@
     };
 };
 
+class ATSCCheckSignalWait: public SpinBoxSetting, public BackendSetting {
+public:
+    ATSCCheckSignalWait():
+        SpinBoxSetting(1000, 10000, 250),
+        BackendSetting("ATSCCheckSignalWait") {
+        setLabel(QObject::tr("Wait for ATSC signal lock (msec)"));
+        setHelpText(QObject::tr("MythTV can check the signal strength "
+                      "When you tune into a HDTV or other over-the-air "
+                      "digital station. This value is the number of "
+                      "milliseconds to allow before we give up trying to "
+                      "get an acceptible signal."));
+        setValue(5000);
+    };
+};
+
+class ATSCCheckSignalThreshold: public SliderSetting, public GlobalSetting {
+public:
+    ATSCCheckSignalThreshold():
+        SliderSetting(50, 90, 1),
+        GlobalSetting("ATSCCheckSignalThreshold") {
+        setLabel(QObject::tr("ATSC Signal Threshold"));
+        setHelpText(QObject::tr("Threshold for a signal to be considered "
+                      "acceptible. If you set this too low Myth may crash, "
+                      "if you set it too low you may not be able to tune "
+                      "to channels on which reception is good."));
+        setValue(65);
+    };
+};
+
 class SmartChannelChange: public CheckBoxSetting, public GlobalSetting {
 public:
     SmartChannelChange():
@@ -2277,6 +2306,8 @@
     general->addChild(new AdvancedRecord());
     general->addChild(new ChannelFormat());
     general->addChild(new LongChannelFormat());
+    general->addChild(new ATSCCheckSignalWait());
+    general->addChild(new ATSCCheckSignalThreshold());
     addChild(general);
 
     VerticalConfigurationGroup* autoexp = new VerticalConfigurationGroup(false);


More information about the mythtv-dev mailing list