[mythtv] [PATCH] ATSC/HDTV Signal Check patch

Daniel Thor Kristjansson danielk at cat.nyu.edu
Tue Apr 20 14:47:12 EDT 2004


I submitted this patch earlier and was asked to make the minimum signal
level variable. This patch is that same patch, with a ATSC Signal
Level threshold slider in the TV settings.

-- 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	20 Apr 2004 18:14:45 -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,9 @@
 {
     VERBOSE(VB_CHANNEL, QString("TuneToFrequency(%1)").arg(frequency));
 
+    int signalThresholdWait = gContext->GetNumSetting("ATSCCheckSignalWait", 5000);
+    int signalThreshold = gContext->GetNumSetting("ATSCCheckSignalThreshold", 65);
+
     if (usingv4l2)
     {
         struct v4l2_frequency vf;
@@ -508,7 +513,7 @@
             perror("VIDIOC_S_FREQUENCY");
             return false;
         }
-        return CheckSignal();
+	return CheckSignal(signalThresholdWait, signalThreshold);
     }
 
     if (ioctl(videofd, VIDIOCSFREQ, &frequency) == -1)
@@ -517,7 +522,7 @@
         return false;
     }
 
-    return CheckSignal();
+    return CheckSignal(signalThresholdWait, signalThreshold);
 }
 
 void Channel::SwitchToInput(int newcapchannel, bool setstarting)
@@ -807,4 +812,3 @@
 {
     return ChangeColourAttribute(V4L2_CID_HUE, "hue", up);
 }
-
Index: libs/libmythtv/channel.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/channel.h,v
retrieving revision 1.29
diff -u -r1.29 channel.h
--- libs/libmythtv/channel.h	27 Mar 2004 05:54:20 -0000	1.29
+++ libs/libmythtv/channel.h	20 Apr 2004 18:14:46 -0000
@@ -26,10 +26,9 @@
     bool SetChannelByString(const QString &chan); 
     bool ChannelUp(void);
     bool ChannelDown(void);
-
     bool CheckSignal(int msecWait = 5000, 
-                     int requiredSignalPercentage = 65,
-                     int input = 0);
+		     int requiredSignalPercentage = 65,
+		     int input = 0);
     unsigned short *Channel::GetV4L1Field(int attrib, 
                                           struct video_picture &vid_pic);
     int Channel::ChangeColourAttribute(int attrib, const char *name, bool up);
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	20 Apr 2004 18:14:47 -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,48 @@
         autoTranscode = profile.byName("autotranscode")->getValue().toInt();
 
         SetupRecorder(profile);
-        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);
 
+	bool error=false;
+	if (channel != NULL)
+        { 
+	    // 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.150
diff -u -b -r1.150 globalsettings.cpp
--- programs/mythfrontend/globalsettings.cpp	10 Apr 2004 19:31:58 -0000	1.150
+++ programs/mythfrontend/globalsettings.cpp	20 Apr 2004 18:14:48 -0000
@@ -1208,6 +1208,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():
@@ -2120,6 +2149,8 @@
     general->addChild(new SmartChannelChange());
     general->addChild(new AdvancedRecord());
     general->addChild(new DisplayChanNum());
+    general->addChild(new ATSCCheckSignalWait());
+    general->addChild(new ATSCCheckSignalThreshold());
     addChild(general);
 
     VerticalConfigurationGroup* autoexp = new VerticalConfigurationGroup(false);


More information about the mythtv-dev mailing list