[mythtv] Experimental DVB signal check patch
Daniel Thor Kristjansson
danielk at cat.nyu.edu
Fri Feb 20 21:10:39 EST 2004
This makes the signal check interface consistent between HDTV and DVB.
However I do not have DVB, so I would love it if some DVB users could
give this a whirl. I basically just employed some programming in the
small to this to move the signal checking code into its own method,
but all the current signal check at the should be functionally the
same.
Hopefully in the future we can use this signal checking interface to
create a channel scanner and simplify MythTV setup.
-- Daniel
-------------- next part --------------
Index: libs/libmythtv/dvbchannel.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/dvbchannel.cpp,v
retrieving revision 1.20
diff -u -r1.20 dvbchannel.cpp
--- libs/libmythtv/dvbchannel.cpp 16 Feb 2004 06:43:42 -0000 1.20
+++ libs/libmythtv/dvbchannel.cpp 21 Feb 2004 01:54:57 -0000
@@ -988,6 +988,89 @@
return true;
}
+bool DVBChannel::CheckSignal(int msecTotal, int reqSignal, int) {
+ CheckSignal(msecTotal, reqSignal, 0);
+}
+
+bool DVBChannel::CheckSignalDVB(int msecTotal, int reqSignal, int* retune) {
+ if (fd_frontend<=0) {
+ ERROR("Card not open!");
+ return false;
+ }
+ struct pollfd polls;
+ polls.fd = fd_frontend;
+ polls.events = POLLIN;
+ polls.revents = 0;
+
+ int max_poll_timeout_count = msecTotal/150;
+ int max_frontend_timeout_count = msecTotal/150;
+
+ struct dvb_frontend_event event;
+
+ if (retune)
+ *retune=false;
+
+ while (true) {
+ int poll_return = poll(&polls, 1, 150);
+ if (poll_return > 0) {
+ if (ioctl(fd_frontend, FE_GET_EVENT, &event) < 0) {
+ if (errno == EOVERFLOW || errno == EAGAIN)
+ continue;
+
+ ERRNO("Failed getting frontend event.");
+ return false;
+ }
+
+ QString status = "Status: ";
+ if (event.status & FE_HAS_CARRIER) status += "CARRIER | ";
+ if (event.status & FE_HAS_VITERBI) status += "VITERBI | ";
+ if (event.status & FE_HAS_SIGNAL) status += "SIGNAL | ";
+ if (event.status & FE_HAS_SYNC) status += "SYNC | ";
+ if (event.status & FE_HAS_LOCK) {
+ status += "LOCK.";
+ CHANNEL(status);
+ return true;
+ } else {
+ status += "NO LOCK!";
+ WARNING(status);
+ continue;
+ }
+
+ if (event.status & FE_TIMEDOUT) {
+ if (max_frontend_timeout_count==0) {
+ ERROR("Frontend timed out too many times, bailing.");
+ return false;
+ }
+
+ ERROR("Timed out, waiting for frontend event, retrying.");
+ max_frontend_timeout_count--;
+ continue;
+ }
+
+ if (event.status & FE_REINIT) {
+ ERROR("Frontend was reinitialized, retuning.");
+ if (retune)
+ *retune=true;
+ }
+ } else {
+ if (poll_return == 0) {
+ if (max_poll_timeout_count) {
+ max_poll_timeout_count--;
+ continue;
+ } else {
+ ERROR("Poll timed out too many times, bailing.");
+ return false;
+ }
+ }
+ if (poll_return == -1) {
+ ERRNO("Poll failed waiting for frontend event.");
+ continue;
+ }
+ }
+ }
+ return false;
+}
+
/*****************************************************************************
Tuning functions for each of the three types of cards.
*****************************************************************************/
@@ -996,21 +1079,14 @@
{
dvb_tuning_t& tuning = channel.tuning;
- if (fd_frontend < 0)
+ if (fd_frontend <= 0)
{
ERROR("Card not open!");
return false;
}
- struct dvb_frontend_event event;
-
bool reset = false;
bool havetuned = false;
- bool tune = true;
-
- int max_poll_timeout_count = 30;
- int max_frontend_timeout_count = 30;
- int poll_return;
if (all == true)
first_tune = true;
@@ -1020,116 +1096,32 @@
first_tune = false;
}
- struct pollfd polls;
- polls.fd = fd_frontend;
-
- while (true)
- {
- if (tune)
- {
- switch(info.type)
- {
- case FE_QPSK:
- if (!TuneQPSK(tuning, reset, havetuned))
- return false;
- break;
- case FE_QAM:
- if (!TuneQAM(tuning, reset, havetuned))
- return false;
- break;
- case FE_OFDM:
- if (!TuneOFDM(tuning, reset, havetuned))
- return false;
- break;
- }
-
- if (havetuned == false)
- return true;
-
- tune = false;
- reset = false;
-
- CHANNEL("Waiting for frontend event after tune.");
- }
-
- polls.events = POLLIN;
- polls.revents = 0;
-
- poll_return = poll(&polls, 1, 150);
-
- if (poll_return > 0)
- {
- if (ioctl(fd_frontend, FE_GET_EVENT, &event) < 0)
- {
- if (errno == EOVERFLOW || errno == EAGAIN)
- continue;
-
- ERRNO("Failed getting frontend event.");
- return false;
- }
-
- QString status = "Status: ";
- if (event.status & FE_HAS_CARRIER) status += "CARRIER | ";
- if (event.status & FE_HAS_VITERBI) status += "VITERBI | ";
- if (event.status & FE_HAS_SIGNAL) status += "SIGNAL | ";
- if (event.status & FE_HAS_SYNC) status += "SYNC | ";
- if (event.status & FE_HAS_LOCK)
- {
- status += "LOCK.";
- CHANNEL(status);
- return true;
- }
- else
- {
- status += "NO LOCK!";
- WARNING(status);
- continue;
- }
-
- if (event.status & FE_TIMEDOUT)
- {
- if (max_frontend_timeout_count==0)
- {
- ERROR("Frontend timed out too many times, bailing.");
- return false;
- }
-
- ERROR("Timed out, waiting for frontend event, retrying.");
- max_frontend_timeout_count--;
- continue;
- }
-
- if (event.status & FE_REINIT)
- {
- ERROR("Frontend was reinitialized, retuning.");
- reset = tune = true;
- }
- }
- else
- {
- if (poll_return == 0)
- {
- if (max_poll_timeout_count)
- {
- max_poll_timeout_count--;
- continue;
- }
- else
- {
- ERROR("Poll timed out too many times, bailing.");
- return false;
- }
- }
-
- if (poll_return == -1)
- {
- ERRNO("Poll failed waiting for frontend event.");
- continue;
- }
- }
+ while (true) {
+ switch(info.type) {
+ case FE_QPSK:
+ if (!TuneQPSK(tuning, reset, havetuned))
+ return false;
+ break;
+ case FE_QAM:
+ if (!TuneQAM(tuning, reset, havetuned))
+ return false;
+ break;
+ case FE_OFDM:
+ if (!TuneOFDM(tuning, reset, havetuned))
+ return false;
+ break;
+ }
+
+ if (havetuned == false)
+ return true;
+
+ CHANNEL("Waiting for frontend event after tune.");
+ int retune=false;
+ bool success=CheckSignalDVB(4500, -1, &retune);
+ if (retune)
+ reset = tune = true;
+ else return success;
}
-
- return true;
}
bool DVBChannel::TuneQPSK(dvb_tuning_t& tuning, bool reset, bool& havetuned)
Index: libs/libmythtv/dvbchannel.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/dvbchannel.h,v
retrieving revision 1.13
diff -u -r1.13 dvbchannel.h
--- libs/libmythtv/dvbchannel.h 10 Feb 2004 22:08:27 -0000 1.13
+++ libs/libmythtv/dvbchannel.h 21 Feb 2004 01:54:58 -0000
@@ -38,6 +38,7 @@
fe_type_t GetCardType() { return info.type; };
bool SetChannelByString(const QString &chan);
+ bool CheckSignal(int msecTotal=4500, int reqSignal=70, int input=0);
bool Tune(dvb_channel_t& channel, bool all=false);
void SetFreqTable(const QString &name);
@@ -95,6 +96,7 @@
void CheckOptions();
bool CheckModulation(fe_modulation_t& modulation);
bool CheckCodeRate(fe_code_rate_t& rate);
+ bool CheckSignalDVB(int msecTotal, int reqSignal, int* retune);
bool TuneQPSK(dvb_tuning_t& tuning, bool reset, bool& havetuned);
bool TuneQAM(dvb_tuning_t& tuning, bool reset, bool& havetuned);
More information about the mythtv-dev
mailing list