Ticket #6719: channel-thread-v1.5a.patch
File channel-thread-v1.5a.patch, 56.6 KB (added by , 14 years ago) |
---|
-
libs/libmythtv/analogsignalmonitor.cpp
old new void AnalogSignalMonitor::UpdateValues(v 30 30 31 31 int videofd = channel->GetFd(); 32 32 if (videofd < 0) 33 33 return; 34 34 35 if (!IsChannelTuned()) 36 return; 37 35 38 bool isLocked = false; 36 39 if (usingv4l2) 37 40 { 38 41 struct v4l2_tuner tuner; 39 42 bzero(&tuner, sizeof(tuner)); -
libs/libmythtv/channelbase.cpp
old new using namespace std; 33 33 34 34 #define LOC QString("ChannelBase(%1): ").arg(GetCardID()) 35 35 #define LOC_WARN QString("ChannelBase(%1) Warning: ").arg(GetCardID()) 36 36 #define LOC_ERR QString("ChannelBase(%1) Error: ").arg(GetCardID()) 37 37 38 /* 39 * Run the channel change thread, and report the status when done 40 */ 41 void ChannelThread::run(void) 42 { 43 bool result = tuner->SetChannelByString(channel); 44 tuner->setStatus(result ? 45 ChannelBase::changeSuccess : ChannelBase::changeFailed); 46 } 47 38 48 ChannelBase::ChannelBase(TVRec *parent) 39 49 : 40 50 pParent(parent), curchannelname(""), 41 currentInputID(-1), commfree(false), cardid(0) 51 currentInputID(-1), commfree(false), cardid(0), 52 abort_change(false) 42 53 { 54 tuneStatus = changeUnknown; 55 tuneThread.tuner = this; 43 56 } 44 57 45 58 ChannelBase::~ChannelBase(void) 46 59 { 60 TeardownAll(); 61 } 62 63 void ChannelBase::TeardownAll(void) 64 { 65 if (tuneThread.isRunning()) 66 { 67 thread_lock.lock(); 68 abort_change = true; 69 tuneCond.wakeAll(); 70 thread_lock.unlock(); 71 tuneThread.wait(); 72 } 73 } 74 75 void ChannelBase::SelectChannel(const QString & chan) 76 { 77 VERBOSE(VB_CHANNEL, LOC + "SelectChannel " + chan); 78 TeardownAll(); 79 80 thread_lock.lock(); 81 abort_change = false; 82 tuneStatus = changePending; 83 thread_lock.unlock(); 84 85 curchannelname = tuneThread.channel = chan; 86 tuneThread.start(); 87 } 88 89 /* 90 * Returns true of the channel change thread should abort 91 */ 92 bool ChannelBase::Aborted(void) 93 { 94 bool result; 95 96 thread_lock.lock(); 97 result = abort_change; 98 thread_lock.unlock(); 99 100 return result; 101 } 102 103 ChannelBase::Status ChannelBase::GetStatus(void) 104 { 105 Status status; 106 107 thread_lock.lock(); 108 status = tuneStatus; 109 thread_lock.unlock(); 110 111 return status; 112 } 113 114 ChannelBase::Status ChannelBase::Wait(void) 115 { 116 tuneThread.wait(); 117 return tuneStatus; 118 } 119 120 void ChannelBase::setStatus(ChannelBase::Status status) 121 { 122 thread_lock.lock(); 123 tuneStatus = status; 124 thread_lock.unlock(); 47 125 } 48 126 49 127 bool ChannelBase::Init(QString &inputname, QString &startchannel, bool setchan) 50 128 { 51 129 bool ok; 52 130 131 VERBOSE(VB_CHANNEL, LOC + QString("Init(%1, %2, %3)") 132 .arg(inputname).arg(startchannel).arg(setchan)); 133 53 134 if (!setchan) 54 135 ok = inputname.isEmpty() ? false : IsTunable(inputname, startchannel); 55 136 else if (inputname.isEmpty()) 56 ok = SetChannelByString(startchannel); 137 { 138 SelectChannel(startchannel); 139 ok = Wait(); 140 } 57 141 else 58 142 ok = SwitchToInput(inputname, startchannel); 59 143 60 144 if (ok) 61 145 return true; … … bool ChannelBase::Init(QString &inputnam 122 206 find(channels.begin(), channels.end(), chanid); 123 207 124 208 if (chanid && cit != channels.end()) 125 209 { 126 210 if (!setchan) 127 {128 211 ok = IsTunable(*it, (mplexid_restriction) ? 129 212 (*cit).channum : startchannel); 130 }131 213 else 132 214 ok = SwitchToInput(*it, (*cit).channum); 133 215 134 216 if (ok) 135 217 { … … int ChannelBase::GetInputByName(const QS 327 409 return (int)it.key(); 328 410 } 329 411 return -1; 330 412 } 331 413 414 #if 0 // Not used? 332 415 bool ChannelBase::SwitchToInput(const QString &inputname) 333 416 { 334 417 int input = GetInputByName(inputname); 335 418 336 419 if (input >= 0) … … bool ChannelBase::SwitchToInput(const QS 338 421 else 339 422 VERBOSE(VB_IMPORTANT, QString("ChannelBase: Could not find input: " 340 423 "%1 on card\n").arg(inputname)); 341 424 return false; 342 425 } 426 #endif 427 428 bool ChannelBase::SelectInput(const QString &inputname, const QString &chan) 429 { 430 int input = GetInputByName(inputname); 431 432 VERBOSE(VB_CHANNEL, LOC + QString("SelectInput(%1, %2) %3") 433 .arg(inputname).arg(chan).arg(input)); 434 435 if (input >= 0) 436 { 437 if (!SwitchToInput(input, false)) 438 return false; 439 SelectChannel(chan); 440 } 441 else 442 { 443 VERBOSE(VB_IMPORTANT, 444 QString("ChannelBase: Could not find input: %1 on card when " 445 "setting channel %2\n").arg(inputname).arg(chan)); 446 return false; 447 } 448 449 return true; 450 } 343 451 344 452 bool ChannelBase::SwitchToInput(const QString &inputname, const QString &chan) 345 453 { 346 454 int input = GetInputByName(inputname); 347 455 348 bool ok = false; 456 VERBOSE(VB_CHANNEL, LOC + QString("SwitchToInput(%1, %2), %3") 457 .arg(inputname).arg(chan).arg(input)); 458 349 459 if (input >= 0) 350 460 { 351 ok = SwitchToInput(input, false);352 if (ok)353 ok =SetChannelByString(chan);461 if (!SwitchToInput(input, false)) 462 return false; 463 return SetChannelByString(chan); 354 464 } 355 465 else 356 466 { 357 467 VERBOSE(VB_IMPORTANT, 358 468 QString("ChannelBase: Could not find input: %1 on card when " 359 469 "setting channel %2\n").arg(inputname).arg(chan)); 470 return false; 360 471 } 361 return ok; 472 473 return true; 362 474 } 363 475 364 476 bool ChannelBase::SwitchToInput(int newInputNum, bool setstarting) 365 477 { 478 VERBOSE(VB_CHANNEL, LOC + QString("SwitchToInput(%1, %2)") 479 .arg(newInputNum).arg(setstarting)); 480 366 481 InputMap::const_iterator it = inputs.find(newInputNum); 367 482 if (it == inputs.end() || (*it)->startChanNum.isEmpty()) 368 483 return false; 369 484 370 485 uint mplexid_restriction; … … bool ChannelBase::SwitchToInput(int newI 372 487 return false; 373 488 374 489 // input switching code would go here 375 490 376 491 if (setstarting) 377 return SetChannelByString((*it)->startChanNum);492 SelectChannel((*it)->startChanNum); 378 493 379 494 return true; 380 495 } 381 496 382 497 static bool is_input_group_busy( … … static bool is_input_busy( 483 598 busygrp, busyrec, busyin, mplexid_restriction); 484 599 } 485 600 return is_busy; 486 601 } 487 602 488 bool ChannelBase::IsInputAvailable( 489 int inputid, uint &mplexid_restriction) const 603 bool ChannelBase::IsInputAvailable(int inputid, uint &mplexid_restriction) const 490 604 { 491 605 if (inputid < 0) 492 606 return false; 493 607 494 608 // Check each input to make sure it doesn't belong to an … … bool ChannelBase::ChangeExternalChannel( 649 763 VERBOSE(VB_IMPORTANT, msg); 650 764 _exit(CHANNEL__EXIT__EXECL_ERROR); // this exit is ok 651 765 } 652 766 else 653 767 { // child contains the pid of the new process 654 int status = 0, pid = 0; 768 QMutex lock; 769 int status = 0, pid = 0; 770 655 771 VERBOSE(VB_CHANNEL, "Waiting for External Tuning program to exit"); 656 772 657 773 bool timed_out = false; 658 774 uint timeout = 30; // how long to wait in seconds 659 775 time_t start_time = time(0); 660 while (-1 != pid && !timed_out )776 while (-1 != pid && !timed_out && !Aborted()) 661 777 { 662 sleep(1); 778 lock.lock(); 779 tuneCond.wait(&lock, 500); // sleep up to 0.5 seconds 663 780 pid = waitpid(child, &status, WUNTRACED|WNOHANG); 664 781 VERBOSE(VB_IMPORTANT, QString("ret_pid(%1) child(%2) status(0x%3)") 665 782 .arg(pid).arg(child).arg(status,0,16)); 666 783 if (pid==child) 784 { 785 lock.unlock(); 667 786 break; 787 } 668 788 else if (time(0) > (time_t)(start_time + timeout)) 669 789 timed_out = true; 790 lock.unlock(); 670 791 } 671 if (timed_out) 792 793 if (timed_out || Aborted()) 672 794 { 673 VERBOSE(VB_IMPORTANT, "External Tuning program timed out, killing"); 795 if (Aborted()) 796 VERBOSE(VB_IMPORTANT, "Aborting External Tuning program"); 797 else 798 VERBOSE(VB_IMPORTANT, "External Tuning program timed out, " 799 "killing"); 674 800 kill(child, SIGTERM); 675 801 usleep(500); 676 802 kill(child, SIGKILL); 677 803 return false; 678 804 } -
libs/libmythtv/channelbase.h
old new 3 3 #ifndef CHANNELBASE_H 4 4 #define CHANNELBASE_H 5 5 6 6 // Qt headers 7 7 #include <QStringList> 8 #include <qwaitcondition.h> 9 #include <qmutex.h> 10 #include <qthread.h> 8 11 9 12 // MythTV headers 10 13 #include "channelutil.h" 11 14 #include "inputinfo.h" 12 15 #include "tv.h" 13 16 14 17 class TVRec; 18 class ChannelBase; 19 20 /* 21 * Thread to run tunning process in 22 */ 23 class ChannelThread : public QThread 24 { 25 public: 26 virtual void run(void); 27 28 QString channel; 29 ChannelBase *tuner; 30 }; 15 31 16 32 /** \class ChannelBase 17 33 * \brief Abstract class providing a generic interface to tuning hardware. 18 34 * 19 35 * This class abstracts channel implementations for analog TV, ATSC, DVB, etc. … … class TVRec; 21 37 * It is responsible for tuning, i.e. switching channels. 22 38 */ 23 39 24 40 class ChannelBase 25 41 { 26 public: 42 friend class ChannelThread; 43 44 public: 45 enum Status { changeUnknown = 'U', changePending = 'P', 46 changeFailed = 'F', changeSuccess = 'S' }; 47 27 48 ChannelBase(TVRec *parent); 28 virtual ~ChannelBase( );49 virtual ~ChannelBase(void); 29 50 30 51 virtual bool Init(QString &inputname, QString &startchannel, bool setchan); 31 52 virtual bool IsTunable(const QString &input, const QString &channum) const; 32 53 54 virtual void SelectChannel(const QString & chan); 55 56 Status GetStatus(void); 57 Status Wait(void); 58 33 59 // Methods that must be implemented. 34 60 /// \brief Opens the channel changing hardware for use. 35 61 virtual bool Open(void) = 0; 36 62 /// \brief Closes the channel changing hardware to use. 37 63 virtual void Close(void) = 0; 38 virtual bool SetChannelByString(const QString &chan) = 0;39 64 /// \brief Reports whether channel is already open 40 65 virtual bool IsOpen(void) const = 0; 41 66 42 67 // Methods that one might want to specialize 43 68 /// \brief Sets file descriptor. … … class ChannelBase 80 105 // Sets 81 106 virtual void Renumber(uint srcid, const QString &oldChanNum, 82 107 const QString &newChanNum); 83 108 84 109 // Input toggling convenience methods 85 virtual bool SwitchToInput(const QString &input); 86 virtual bool SwitchToInput(const QString &input, const QString &chan); 110 111 // virtual bool SwitchToInput(const QString &input); // not used? 112 virtual bool SelectInput(const QString &input, const QString &chan); 87 113 88 114 virtual bool InitializeInputs(void); 89 115 90 116 // Misc. Commands 91 117 virtual bool Retune(void) { return false; } … … class ChannelBase 106 132 // \brief Set cardid for scanning 107 133 void SetCardID(uint _cardid) { cardid = _cardid; } 108 134 109 135 virtual int GetCardID(void) const; 110 136 protected: 137 virtual bool SetChannelByString(const QString &chan) = 0; 138 111 139 /// \brief Switches to another input on hardware, 112 140 /// and sets the channel is setstarting is true. 141 virtual bool SwitchToInput(const QString &input, const QString &chan); 113 142 virtual bool SwitchToInput(int inputNum, bool setstarting); 114 143 virtual bool IsInputAvailable( 115 144 int inputNum, uint &mplexid_restriction) const; 116 145 117 146 virtual bool ChangeExternalChannel(const QString &newchan); 118 147 static void StoreInputChannels(const InputMap&); 119 148 static void StoreDefaultInput(uint cardid, const QString &input); 120 149 150 bool Aborted(); 151 void setStatus(Status status); 152 void TeardownAll(void); 153 121 154 TVRec *pParent; 122 155 QString curchannelname; 123 156 int currentInputID; 124 157 bool commfree; 125 158 uint cardid; 126 159 InputMap inputs; 127 160 DBChanList allchannels; ///< channels across all inputs 161 162 QWaitCondition tuneCond; 163 164 private: 165 mutable ChannelThread tuneThread; 166 Status tuneStatus; 167 QMutex thread_lock; 168 bool abort_change; 128 169 }; 129 170 130 171 #endif 131 172 -
new file libs/libmythtv/channelchangemonitor.cpp
- + 1 // -*- Mode: c++ -*- 2 3 #include <cerrno> 4 #include <unistd.h> 5 #include <sys/ioctl.h> 6 7 #include "videodev_myth.h" 8 #include "mythcontext.h" 9 #include "channelchangemonitor.h" 10 #include "v4lchannel.h" 11 12 #define LOC QString("ChannelChangeM: ").arg(channel->GetDevice()) 13 #define LOC_ERR QString("ChannelChangeM, Error: ").arg(channel->GetDevice()) 14 15 ChannelChangeMonitor::ChannelChangeMonitor( 16 int db_cardnum, V4LChannel *_channel, uint64_t _flags) : 17 SignalMonitor(db_cardnum, _channel, _flags) 18 { 19 } 20 21 void ChannelChangeMonitor::UpdateValues(void) 22 { 23 if (!running || exit) 24 return; 25 26 if (!IsChannelTuned()) 27 return; 28 29 { 30 QMutexLocker locker(&statusLock); 31 signalLock.SetValue(true); 32 signalStrength.SetValue(100); 33 } 34 35 EmitStatus(); 36 SendMessageAllGood(); 37 } 38 -
new file libs/libmythtv/channelchangemonitor.h
- + 1 // -*- Mode: c++ -*- 2 // Copyright (c) 2005, Daniel Thor Kristjansson 3 4 #ifndef _CHANNEL_CHANGE_MONITOR_H_ 5 #define _CHANNEL_CHANGE_MONITOR_H_ 6 7 // MythTV headers 8 #include "signalmonitor.h" 9 10 class V4LChannel; 11 12 class ChannelChangeMonitor : public SignalMonitor 13 { 14 public: 15 ChannelChangeMonitor( 16 int db_cardnum, V4LChannel *_channel, 17 uint64_t _flags = kSigMon_WaitForSig); 18 19 virtual void UpdateValues(void); 20 }; 21 22 #endif // _CHANNEL_CHANGE_MONITOR_H_ -
libs/libmythtv/channelscan/channelscan_sm.cpp
old new void ChannelScanSM::ScanTransport(const 1512 1512 GetDTVSignalMonitor()->GetScanStreamData()->Reset(); 1513 1513 GetDTVSignalMonitor()->SetChannel(-1,-1); 1514 1514 } 1515 1515 1516 1516 // Start signal monitor for this channel 1517 signalMonitor->Start( );1517 signalMonitor->Start(false); 1518 1518 1519 1519 timer.start(); 1520 1520 waitingForTables = true; 1521 1521 } 1522 1522 -
libs/libmythtv/channelscan/channelscan_sm.h
old new class AnalogSignalHandler : public Signa 70 70 public: 71 71 AnalogSignalHandler(ChannelScanSM *_siscan) : siscan(_siscan) { } 72 72 73 73 public slots: 74 74 virtual inline void AllGood(void); 75 virtual void StatusChannelTuned(const SignalMonitorValue&) { } 75 76 virtual void StatusSignalLock(const SignalMonitorValue&) { } 76 77 virtual void StatusSignalStrength(const SignalMonitorValue&) { } 77 78 78 79 private: 79 80 ChannelScanSM *siscan; -
libs/libmythtv/channelscan/channelscanner_cli.cpp
old new void ChannelScannerCLI::HandleEvent(cons 90 90 case ScannerEvent::SetPercentComplete: 91 91 status_complete = scanEvent->intValue(); 92 92 break; 93 93 case ScannerEvent::SetStatusRotorPosition: 94 94 break; 95 case ScannerEvent::SetStatusChannelTuned: 96 break; 95 97 case ScannerEvent::SetStatusSignalLock: 96 98 status_lock = scanEvent->intValue(); 97 99 break; 98 100 case ScannerEvent::SetStatusSignalToNoise: 99 101 status_snr = scanEvent->intValue() / 65535.0; -
libs/libmythtv/channelscan/channelscanner_gui.cpp
old new void ChannelScannerGUI::HandleEvent(cons 154 154 scanStage->SetScanProgress(scanEvent->intValue() * 0.01); 155 155 break; 156 156 case ScannerEvent::SetStatusRotorPosition: 157 157 scanStage->SetStatusRotorPosition(scanEvent->intValue()); 158 158 break; 159 case ScannerEvent::SetStatusChannelTuned: 160 break; 159 161 case ScannerEvent::SetStatusSignalLock: 160 162 scanStage->SetStatusLock(scanEvent->intValue()); 161 163 break; 162 164 case ScannerEvent::SetStatusSignalToNoise: 163 165 scanStage->SetStatusSignalToNoise(scanEvent->intValue()); -
libs/libmythtv/channelscan/scanmonitor.cpp
old new void ScanMonitor::StatusRotorPosition(co 105 105 { 106 106 post_event(this, ScannerEvent::SetStatusRotorPosition, 107 107 val.GetNormalizedValue(0, 65535)); 108 108 } 109 109 110 void ScanMonitor::StatusChannelTuned(const SignalMonitorValue &val) 111 { 112 post_event(this, ScannerEvent::SetStatusChannelTuned, val.GetValue()); 113 } 114 110 115 void ScanMonitor::StatusSignalLock(const SignalMonitorValue &val) 111 116 { 112 117 post_event(this, ScannerEvent::SetStatusSignalLock, val.GetValue()); 113 118 } 114 119 -
libs/libmythtv/channelscan/scanmonitor.h
old new class ScanMonitor : 62 62 void ScanAppendTextToLog(const QString &status); 63 63 void ScanComplete(void); 64 64 65 65 // SignalMonitorListener 66 66 virtual void AllGood(void) { } 67 virtual void StatusChannelTuned(const SignalMonitorValue&); 67 68 virtual void StatusSignalLock(const SignalMonitorValue&); 68 69 virtual void StatusSignalStrength(const SignalMonitorValue&); 69 70 70 71 // DVBSignalMonitorListener 71 72 virtual void StatusSignalToNoise(const SignalMonitorValue&); … … class ScannerEvent : public QEvent 96 97 SetPercentComplete, 97 98 SetStatusRotorPosition, 98 99 SetStatusSignalToNoise, 99 100 SetStatusSignalStrength, 100 101 SetStatusSignalLock, 102 SetStatusChannelTuned 101 103 }; 102 104 103 105 ScannerEvent(TYPE t) : 104 106 QEvent((QEvent::Type)(t + QEvent::User)), 105 107 str(""), intvalue(0), cfg_ptr(NULL) { ; } -
libs/libmythtv/dtvsignalmonitor.cpp
old new 23 23 DTVSignalMonitor::DTVSignalMonitor(int db_cardnum, 24 24 DTVChannel *_channel, 25 25 uint64_t wait_for_mask) 26 26 : SignalMonitor(db_cardnum, _channel, wait_for_mask), 27 27 stream_data(NULL), 28 channelTuned(QObject::tr("Channel Tuned"), "tuned", 3, true, 0, 3, 0), 28 29 seenPAT(QObject::tr("Seen")+" PAT", "seen_pat", 1, true, 0, 1, 0), 29 30 seenPMT(QObject::tr("Seen")+" PMT", "seen_pmt", 1, true, 0, 1, 0), 30 31 seenMGT(QObject::tr("Seen")+" MGT", "seen_mgt", 1, true, 0, 1, 0), 31 32 seenVCT(QObject::tr("Seen")+" VCT", "seen_vct", 1, true, 0, 1, 0), 32 33 seenNIT(QObject::tr("Seen")+" NIT", "seen_nit", 1, true, 0, 1, 0), … … DTVChannel *DTVSignalMonitor::GetDTVChan 61 62 62 63 QStringList DTVSignalMonitor::GetStatusList(bool kick) 63 64 { 64 65 QStringList list = SignalMonitor::GetStatusList(kick); 65 66 QMutexLocker locker(&statusLock); 67 68 // tuned? 69 if (flags & kSigMon_Tuned) 70 { 71 list<<channelTuned.GetName()<<channelTuned.GetStatus(); 72 } 73 66 74 // mpeg tables 67 75 if (flags & kDTVSigMon_WaitForPAT) 68 76 { 69 77 list<<seenPAT.GetName()<<seenPAT.GetStatus(); 70 78 list<<matchingPAT.GetName()<<matchingPAT.GetStatus(); … … void DTVSignalMonitor::RemoveFlags(uint6 136 144 } 137 145 138 146 void DTVSignalMonitor::UpdateMonitorValues(void) 139 147 { 140 148 QMutexLocker locker(&statusLock); 149 channelTuned.SetValue((flags & kSigMon_Tuned) ? 3 : 1); 141 150 seenPAT.SetValue( (flags & kDTVSigMon_PATSeen) ? 1 : 0); 142 151 seenPMT.SetValue( (flags & kDTVSigMon_PMTSeen) ? 1 : 0); 143 152 seenMGT.SetValue( (flags & kDTVSigMon_MGTSeen) ? 1 : 0); 144 153 seenVCT.SetValue( (flags & kDTVSigMon_VCTSeen) ? 1 : 0); 145 154 seenNIT.SetValue( (flags & kDTVSigMon_NITSeen) ? 1 : 0); -
libs/libmythtv/dtvsignalmonitor.h
old new class DTVSignalMonitor : public SignalMo 109 109 void UpdateListeningForEIT(void); 110 110 111 111 protected: 112 112 MPEGStreamData *stream_data; 113 113 vector<uint> eit_pids; 114 SignalMonitorValue channelTuned; 114 115 SignalMonitorValue seenPAT; 115 116 SignalMonitorValue seenPMT; 116 117 SignalMonitorValue seenMGT; 117 118 SignalMonitorValue seenVCT; 118 119 SignalMonitorValue seenNIT; -
libs/libmythtv/dvbsignalmonitor.cpp
old new void DVBSignalMonitor::UpdateValues(void 228 228 229 229 update_done = true; 230 230 return; 231 231 } 232 232 233 if (!IsChannelTuned()) 234 return; 235 233 236 AddFlags(kSigMon_WaitForSig); 234 237 235 238 DVBChannel *dvbchannel = GetDVBChannel(); 236 239 if (!dvbchannel) 237 240 return; -
libs/libmythtv/firewiresignalmonitor.cpp
old new void FirewireSignalMonitor::AddData(cons 188 188 void FirewireSignalMonitor::UpdateValues(void) 189 189 { 190 190 if (!running || exit) 191 191 return; 192 192 193 if (!IsChannelTuned()) 194 return; 195 193 196 if (dtvMonitorRunning) 194 197 { 195 198 EmitStatus(); 196 199 if (IsAllGood()) 197 200 SendMessageAllGood(); -
libs/libmythtv/hdhrchannel.cpp
old new bool HDHRChannel::SetChannelByString(con 141 141 142 142 uint mplexid_restriction; 143 143 if (!IsInputAvailable(currentInputID, mplexid_restriction)) 144 144 return false; 145 145 146 if (Aborted()) 147 return false; 148 146 149 // Fetch tuning data from the database. 147 150 QString tvformat, modulation, freqtable, freqid, si_std; 148 151 int finetune; 149 152 uint64_t frequency; 150 153 int mpeg_prog_num; -
libs/libmythtv/hdhrsignalmonitor.cpp
old new void HDHRSignalMonitor::UpdateValues(voi 103 103 104 104 update_done = true; 105 105 return; 106 106 } 107 107 108 if (!IsChannelTuned()) 109 return; 110 108 111 struct hdhomerun_tuner_status_t status; 109 112 streamHandler->GetTunerStatus(&status); 110 113 111 114 uint sig = status.signal_strength; 112 115 uint snq = status.signal_to_noise_quality; -
libs/libmythtv/iptvsignalmonitor.cpp
old new void IPTVSignalMonitor::AddData( 117 117 void IPTVSignalMonitor::UpdateValues(void) 118 118 { 119 119 if (!running || exit) 120 120 return; 121 121 122 if (!IsChannelTuned()) 123 return; 124 122 125 if (dtvMonitorRunning) 123 126 { 124 127 EmitStatus(); 125 128 if (IsAllGood()) 126 129 SendMessageAllGood(); -
libs/libmythtv/libmythtv.pro
old new using_backend { 439 439 SOURCES += audioinputoss.cpp 440 440 DEFINES += USING_OSS 441 441 LIBS += $$OSS_LIBS 442 442 } 443 443 444 HEADERS += channelchangemonitor.h 445 SOURCES += channelchangemonitor.cpp 446 444 447 # Support for Video4Linux devices 445 448 using_v4l { 446 449 HEADERS += v4lchannel.h analogsignalmonitor.h 447 450 SOURCES += v4lchannel.cpp analogsignalmonitor.cpp 448 451 -
libs/libmythtv/signalmonitor.cpp
old new 6 6 #include <signal.h> 7 7 #include <unistd.h> 8 8 9 9 // MythTV headers 10 10 #include "mythcontext.h" 11 #include "tv_rec.h" 11 12 #include "signalmonitor.h" 12 13 #include "compat.h" 13 14 #include "mythverbose.h" 14 15 15 16 extern "C" { … … extern "C" { 40 41 #ifdef USING_FIREWIRE 41 42 # include "firewiresignalmonitor.h" 42 43 # include "firewirechannel.h" 43 44 #endif 44 45 46 #include "channelchangemonitor.h" 47 45 48 #undef DBG_SM 46 49 #define DBG_SM(FUNC, MSG) VERBOSE(VB_CHANNEL, \ 47 50 "SM("<<channel->GetDevice()<<")::"<<FUNC<<": "<<MSG); 48 51 49 52 /** \class SignalMonitor … … SignalMonitor *SignalMonitor::Init(QStri 91 94 signalMonitor = new DVBSignalMonitor(db_cardnum, dvbc); 92 95 } 93 96 #endif 94 97 95 98 #ifdef USING_V4L 99 #if 0 // Just use ChannelChangeMonitor for these types 96 100 if ((cardtype.toUpper() == "V4L") || 97 (cardtype.toUpper() == "MPEG") || 98 (cardtype.toUpper() == "HDPVR")) 101 (cardtype.toUpper() == "MPEG")) 99 102 { 100 103 V4LChannel *chan = dynamic_cast<V4LChannel*>(channel); 101 104 if (chan) 102 105 signalMonitor = new AnalogSignalMonitor(db_cardnum, chan); 103 106 } 104 107 #endif 108 #endif 105 109 106 110 #ifdef USING_HDHOMERUN 107 111 if (cardtype.toUpper() == "HDHOMERUN") 108 112 { 109 113 HDHRChannel *hdhrc = dynamic_cast<HDHRChannel*>(channel); … … SignalMonitor *SignalMonitor::Init(QStri 130 134 } 131 135 #endif 132 136 133 137 if (!signalMonitor) 134 138 { 139 V4LChannel *chan = dynamic_cast<V4LChannel*>(channel); 140 if (chan) 141 signalMonitor = new ChannelChangeMonitor(db_cardnum, chan); 142 } 143 144 if (!signalMonitor) 145 { 135 146 VERBOSE(VB_IMPORTANT, 136 147 QString("Failed to create signal monitor in Init(%1, %2, 0x%3)") 137 148 .arg(cardtype).arg(db_cardnum).arg((long)channel,0,16)); 138 149 } 139 150 … … SignalMonitor::SignalMonitor(int _captur 158 169 : channel(_channel), 159 170 capturecardnum(_capturecardnum), flags(wait_for_mask), 160 171 update_rate(25), minimum_update_rate(5), 161 172 running(false), exit(false), 162 173 update_done(false), notify_frontend(true), 163 error(""), 174 is_tuned(false), tablemon(false), 175 eit_scan(false), error(""), 164 176 signalLock (QObject::tr("Signal Lock"), "slock", 165 177 1, true, 0, 1, 0), 166 178 signalStrength(QObject::tr("Signal Power"), "signal", 167 179 0, true, 0, 100, 0), 180 channelTuned("Channel Tuned", "tuned", 3, true, 0, 3, 0), 168 181 statusLock(QMutex::Recursive) 169 182 { 170 183 } 171 184 172 185 /** \fn SignalMonitor::~SignalMonitor() … … bool SignalMonitor::HasAnyFlag(uint64_t 200 213 } 201 214 202 215 /** \fn SignalMonitor::Start() 203 216 * \brief Start signal monitoring thread. 204 217 */ 205 void SignalMonitor::Start( )218 void SignalMonitor::Start(bool waitfor_tune) 206 219 { 207 220 DBG_SM("Start", "begin"); 208 221 { 209 222 QMutexLocker locker(&startStopLock); 223 224 // When used for scanning, don't wait for the tuning thread 225 is_tuned = !waitfor_tune; 226 210 227 if (!running) 211 228 { 212 229 int rval = pthread_create( 213 230 &monitor_thread, NULL, SpawnMonitorLoop, this); 214 231 … … QStringList SignalMonitor::GetStatusList 277 294 else if (!running) 278 295 UpdateValues(); 279 296 280 297 QStringList list; 281 298 statusLock.lock(); 299 list<<channelTuned.GetName()<<channelTuned.GetStatus(); 282 300 list<<signalLock.GetName()<<signalLock.GetStatus(); 283 301 if (HasFlags(kSigMon_WaitForSig)) 284 302 list<<signalStrength.GetName()<<signalStrength.GetStatus(); 285 303 statusLock.unlock(); 286 304 … … void SignalMonitor::MonitorLoop() 304 322 if (notify_frontend && capturecardnum>=0) 305 323 { 306 324 QStringList slist = GetStatusList(false); 307 325 MythEvent me(QString("SIGNAL %1").arg(capturecardnum), slist); 308 326 gContext->dispatch(me); 309 //cerr<<"sent SIGNAL"<<endl;310 327 } 311 328 312 329 usleep(update_rate * 1000); 313 330 } 314 331 … … void SignalMonitor::SendMessage( 439 456 listener->AllGood(); 440 457 break; 441 458 case kStatusSignalStrength: 442 459 listener->StatusSignalStrength(val); 443 460 break; 461 case kStatusChannelTuned: 462 listener->StatusChannelTuned(val); 463 break; 444 464 case kStatusSignalToNoise: 445 465 if (dvblistener) 446 466 dvblistener->StatusSignalToNoise(val); 447 467 break; 448 468 case kStatusBitErrorRate: … … void SignalMonitor::SendMessage( 459 479 break; 460 480 } 461 481 } 462 482 } 463 483 484 bool SignalMonitor::IsChannelTuned(void) 485 { 486 if (is_tuned) 487 return true; 488 489 ChannelBase::Status status = channel->GetStatus(); 490 QMutexLocker locker(&statusLock); 491 492 switch (status) { 493 case ChannelBase::changePending: 494 channelTuned.SetValue(1); 495 break; 496 case ChannelBase::changeFailed: 497 channelTuned.SetValue(2); 498 break; 499 case ChannelBase::changeSuccess: 500 channelTuned.SetValue(3); 501 break; 502 } 503 504 EmitStatus(); 505 506 if (status == ChannelBase::changeSuccess) 507 { 508 if (tablemon) 509 pParent->SetupDTVSignalMonitor(eit_scan); 510 511 is_tuned = true; 512 return true; 513 } 514 515 return false; 516 } 517 464 518 void SignalMonitor::SendMessageAllGood(void) 465 519 { 466 520 QMutexLocker locker(&listenerLock); 467 521 for (uint i = 0; i < listeners.size(); i++) 468 522 listeners[i]->AllGood(); 469 523 } 470 524 471 525 void SignalMonitor::EmitStatus(void) 472 526 { 527 SendMessage(kStatusChannelTuned, channelTuned); 473 528 SendMessage(kStatusSignalLock, signalLock); 474 529 if (HasFlags(kSigMon_WaitForSig)) 475 530 SendMessage(kStatusSignalStrength, signalStrength); 476 531 } -
libs/libmythtv/signalmonitor.h
old new using namespace std; 24 24 #define DBG_SM(FUNC, MSG) VERBOSE(VB_CHANNEL, \ 25 25 "SM("<<channel->GetDevice()<<")::"<<FUNC<<": "<<MSG); 26 26 27 27 inline QString sm_flags_to_string(uint64_t); 28 28 29 class TVRec; 30 29 31 class SignalMonitor 30 32 { 31 33 public: 32 34 /// Returns true iff the card type supports signal monitoring. 33 35 static inline bool IsRequired(const QString &cardtype); … … class SignalMonitor 37 39 virtual ~SignalMonitor(); 38 40 39 41 // // // // // // // // // // // // // // // // // // // // // // // // 40 42 // Control // // // // // // // // // // // // // // // // // // // // 41 43 42 virtual void Start( );44 virtual void Start(bool waitfor_tune); 43 45 virtual void Stop(); 44 46 virtual void Kick(); 45 47 virtual bool WaitForLock(int timeout = -1); 46 48 47 49 // // // // // // // // // // // // // // // // // // // // // // // // … … class SignalMonitor 81 83 * \param notify if true SIGNAL MythEvents are sent to the frontend, 82 84 * otherwise they are not. 83 85 */ 84 86 void SetNotifyFrontend(bool notify) { notify_frontend = notify; } 85 87 88 /** \brief Indicate if table monitoring is needed 89 * \param monitor if true parent->SetupDTVSignalMonitor is called 90 * after the channel is tuned. 91 */ 92 void SetMonitoring(TVRec * parent, bool EITscan, bool monitor) 93 { pParent = parent; eit_scan = EITscan, tablemon = monitor; } 94 86 95 /** \brief Sets the number of milliseconds between signal monitoring 87 96 * attempts in the signal monitoring thread. 88 97 * 89 98 * Defaults to 25 milliseconds. 90 99 * \param msec Milliseconds between signal monitoring events. … … class SignalMonitor 94 103 95 104 // // // // // // // // // // // // // // // // // // // // // // // // 96 105 // Listeners // // // // // // // // // // // // // // // // // // // 97 106 void AddListener(SignalMonitorListener *listener); 98 107 void RemoveListener(SignalMonitorListener *listener); 108 99 109 void SendMessage(SignalMonitorMessageType type, 100 110 const SignalMonitorValue &val); 101 111 void SendMessageAllGood(void); 102 112 virtual void EmitStatus(void); 103 113 … … class SignalMonitor 106 116 uint64_t wait_for_mask); 107 117 108 118 static void* SpawnMonitorLoop(void*); 109 119 virtual void MonitorLoop(); 110 120 121 bool IsChannelTuned(void); 122 111 123 /// \brief This should be overridden to actually do signal monitoring. 112 124 virtual void UpdateValues() { ; } 113 125 114 126 public: 115 127 /// We've seen a PAT, … … class SignalMonitor 137 149 /// We've seen the FireWire STB power state 138 150 static const uint64_t kFWSigMon_PowerSeen = 0x0000000100ULL; 139 151 /// We've seen something indicating whether the data stream is encrypted 140 152 static const uint64_t kDTVSigMon_CryptSeen = 0x0000000200ULL; 141 153 154 static const uint64_t kSigMon_Tuned = 0x0000000400ULL; 155 142 156 /// We've seen a PAT matching our requirements 143 157 static const uint64_t kDTVSigMon_PATMatch = 0x0000001000ULL; 144 158 /// We've seen a PMT matching our requirements 145 159 static const uint64_t kDTVSigMon_PMTMatch = 0x0000002000ULL; 146 160 /// We've seen an MGT matching our requirements … … class SignalMonitor 182 196 static const uint64_t kDVBSigMon_WaitForPos = 0x8000000000ULL; 183 197 184 198 protected: 185 199 pthread_t monitor_thread; 186 200 ChannelBase *channel; 201 TVRec *pParent; 187 202 int capturecardnum; 188 203 uint64_t flags; 189 204 int update_rate; 190 205 uint minimum_update_rate; 191 206 bool running; 192 207 bool exit; 193 208 bool update_done; 194 209 bool notify_frontend; 210 bool is_tuned; 211 bool tablemon; 212 bool eit_scan; 195 213 QString error; 196 214 197 215 SignalMonitorValue signalLock; 198 216 SignalMonitorValue signalStrength; 217 SignalMonitorValue channelTuned; 199 218 200 219 vector<SignalMonitorListener*> listeners; 201 220 202 221 QMutex startStopLock; 203 222 mutable QMutex statusLock; -
libs/libmythtv/signalmonitorlistener.h
old new 7 7 #include "mythexp.h" 8 8 #include "signalmonitorvalue.h" 9 9 10 10 typedef enum { 11 11 kAllGood, 12 kStatusChannelTuned, 12 13 kStatusSignalLock, 13 14 kStatusSignalStrength, 14 15 kStatusSignalToNoise, 15 16 kStatusBitErrorRate, 16 17 kStatusUncorrectedBlocks, … … class MPUBLIC SignalMonitorListener 28 29 * Note: Signals are only sent once the monitoring thread 29 30 * has been started. 30 31 */ 31 32 virtual void AllGood(void) = 0; 32 33 34 /** \brief Singal to be sent with change change status. 35 * 36 * Note: Signals are only sent once the monitoring thread 37 * has been started. 38 */ 39 virtual void StatusChannelTuned(const SignalMonitorValue&) = 0; 40 33 41 /** \brief Signal to be sent as true when it is safe to begin 34 42 * or continue recording, and false if it may not be safe. 35 43 * 36 44 * Note: Signals are only sent once the monitoring thread 37 45 * has been started. -
libs/libmythtv/tv_play.cpp
old new void TV::UpdateOSDSignal(const PlayerCon 7331 7331 7332 7332 uint sig = 0; 7333 7333 float snr = 0.0f; 7334 7334 uint ber = 0xffffffff; 7335 7335 int pos = -1; 7336 int tuned = -1; 7336 7337 QString pat(""), pmt(""), mgt(""), vct(""), nit(""), sdt(""), crypt(""); 7337 7338 QString err = QString::null, msg = QString::null; 7338 7339 for (it = slist.begin(); it != slist.end(); ++it) 7339 7340 { 7340 7341 if ("error" == it->GetShortName()) … … void TV::UpdateOSDSignal(const PlayerCon 7357 7358 snr = it->GetValue(); 7358 7359 else if ("ber" == it->GetShortName()) 7359 7360 ber = it->GetValue(); 7360 7361 else if ("pos" == it->GetShortName()) 7361 7362 pos = it->GetValue(); 7363 else if ("tuned" == it->GetShortName()) 7364 tuned = it->GetValue(); 7362 7365 else if ("seen_pat" == it->GetShortName()) 7363 7366 pat = it->IsGood() ? "a" : "_"; 7364 7367 else if ("matching_pat" == it->GetShortName()) 7365 7368 pat = it->IsGood() ? "A" : pat; 7366 7369 else if ("seen_pmt" == it->GetShortName()) … … void TV::UpdateOSDSignal(const PlayerCon 7390 7393 } 7391 7394 if (sig) 7392 7395 infoMap["signal"] = QString::number(sig); // use normalized value 7393 7396 7394 7397 bool allGood = SignalMonitorValue::AllGood(slist); 7398 char tuneCode; 7395 7399 QString slock = ("1" == infoMap["slock"]) ? "L" : "l"; 7396 7400 QString lockMsg = (slock=="L") ? tr("Partial Lock") : tr("No Lock"); 7397 7401 QString sigMsg = allGood ? tr("Lock") : lockMsg; 7398 7402 7399 7403 QString sigDesc = tr("Signal %1\%").arg(sig,2); … … void TV::UpdateOSDSignal(const PlayerCon 7402 7406 if (ber != 0xffffffff) 7403 7407 sigDesc += " | " + tr("BE %1", "Bit Errors").arg(ber, 2); 7404 7408 if ((pos >= 0) && (pos < 100)) 7405 7409 sigDesc += " | " + tr("Rotor %1\%").arg(pos,2); 7406 7410 7407 sigDesc = sigDesc + QString(" | (%1%2%3%4%5%6%7%8) %9") 7408 .arg(slock).arg(pat).arg(pmt).arg(mgt).arg(vct) 7409 .arg(nit).arg(sdt).arg(crypt).arg(sigMsg); 7411 if (tuned == 1) 7412 tuneCode = 't'; 7413 else if (tuned == 2) 7414 tuneCode = 'F'; 7415 else if (tuned == 3) 7416 tuneCode = 'T'; 7417 else 7418 tuneCode = '_'; 7419 7420 sigDesc = sigDesc + QString(" | (%1%2%3%4%5%6%7%8%9) %10") 7421 .arg(tuneCode).arg(slock).arg(pat).arg(pmt).arg(mgt).arg(vct) 7422 .arg(nit).arg(sdt).arg(crypt).arg(sigMsg); 7410 7423 7411 7424 if (!err.isEmpty()) 7412 7425 sigDesc = err; 7413 7426 else if (!msg.isEmpty()) 7414 7427 sigDesc = msg; -
libs/libmythtv/tv_rec.cpp
old new ProgramInfo *TVRec::GetRecording(void) 362 362 * \param hasLater If true, a later non-conflicting showing is available. 363 363 */ 364 364 void TVRec::RecordPending(const ProgramInfo *rcinfo, int secsleft, 365 365 bool hasLater) 366 366 { 367 QMutexLocker lock(&stateChangeLock); 367 QMutexLocker statelock(&stateChangeLock); 368 QMutexLocker pendlock(&pendingRecLock); 368 369 369 370 if (secsleft < 0) 370 371 { 371 372 VERBOSE(VB_RECORD, LOC + "Pending recording revoked on " + 372 373 QString("inputid %1").arg(rcinfo->inputid)); … … void TVRec::RecordPending(const ProgramI 400 401 vector<uint> cardids = CardUtil::GetConflictingCards( 401 402 rcinfo->inputid, cardid); 402 403 403 404 pendingRecordings[rcinfo->cardid].possibleConflicts = cardids; 404 405 405 state ChangeLock.unlock();406 statelock.unlock(); 406 407 for (uint i = 0; i < cardids.size(); i++) 407 408 RemoteRecordPending(cardids[i], rcinfo, secsleft, hasLater); 408 state ChangeLock.lock();409 statelock.relock(); 409 410 } 410 411 411 412 /** \fn TVRec::SetPseudoLiveTVRecording(ProgramInfo*) 412 413 * \brief Sets the pseudo LiveTV ProgramInfo 413 414 */ … … QDateTime TVRec::GetRecordEndTime(const 435 436 * \sa RecordPending(const ProgramInfo*, int, bool), 436 437 * TV::AskAllowRecording(const QStringList&, int, bool) 437 438 */ 438 439 void TVRec::CancelNextRecording(bool cancel) 439 440 { 441 QMutexLocker pendlock(&pendingRecLock); 440 442 VERBOSE(VB_RECORD, LOC + "CancelNextRecording("<<cancel<<") -- begin"); 441 443 442 444 PendingMap::iterator it = pendingRecordings.find(cardid); 443 445 if (it == pendingRecordings.end()) 444 446 { … … RecStatusType TVRec::StartRecording(cons 518 520 retval = rsRecording; 519 521 return retval; 520 522 } 521 523 522 524 PendingMap::iterator it = pendingRecordings.find(cardid); 525 PendingInfo pendinfo; 523 526 bool cancelNext = false; 527 bool has_pending; 528 524 529 if (it != pendingRecordings.end()) 525 530 { 526 531 (*it).ask = (*it).doNotAsk = false; 527 532 cancelNext = (*it).canceled; 528 533 } … … RecStatusType TVRec::StartRecording(cons 531 536 WaitForEventThreadSleep(); 532 537 533 538 // Rescan pending recordings since the event loop may have deleted 534 539 // a stale entry. If this happens the info pointer will not be valid 535 540 // since the HandlePendingRecordings loop will have deleted it. 541 pendingRecLock.lock(); 536 542 it = pendingRecordings.find(cardid); 543 pendinfo = *it; 544 has_pending = (it != pendingRecordings.end()); 545 pendingRecLock.unlock(); 537 546 538 547 // If the needed input is in a shared input group, and we are 539 548 // not canceling the recording anyway, check other recorders 540 if (!cancelNext && 541 (it != pendingRecordings.end()) && (*it).possibleConflicts.size()) 549 if (!cancelNext && has_pending && pendinfo.possibleConflicts.size()) 542 550 { 543 551 VERBOSE(VB_RECORD, LOC + "Checking input group recorders - begin"); 544 vector<uint> &cardids = (*it).possibleConflicts;552 vector<uint> &cardids = pendinfo.possibleConflicts; 545 553 546 554 uint mplexid = 0, sourceid = 0; 547 555 vector<uint> cardids2; 548 556 vector<TVState> states; 549 557 … … RecStatusType TVRec::StartRecording(cons 562 570 busy_input.inputid, rcinfo->inputid); 563 571 } 564 572 565 573 if (is_busy && !sourceid) 566 574 { 567 mplexid = (*it).info->GetMplexID();568 sourceid = (*it).info->sourceid;575 mplexid = pendinfo.info->GetMplexID(); 576 sourceid = pendinfo.info->sourceid; 569 577 } 570 578 571 579 if (is_busy && 572 580 ((sourceid != busy_input.sourceid) || 573 581 (mplexid != busy_input.mplexid))) … … void TVRec::HandleStateChange(void) 945 953 * \brief Puts a state change on the nextState queue. 946 954 */ 947 955 void TVRec::ChangeState(TVState nextState) 948 956 { 949 957 QMutexLocker lock(&stateChangeLock); 950 951 958 desiredNextState = nextState; 952 959 changeState = true; 953 960 WakeEventLoop(); 954 961 } 955 962 … … void TVRec::RunTV(void) 1408 1415 if (GetState() == kState_WatchingLiveTV) 1409 1416 { 1410 1417 QDateTime now = QDateTime::currentDateTime(); 1411 1418 bool has_finish = HasFlags(kFlagFinishRecording); 1412 1419 bool has_rec = pseudoLiveTVRecording; 1420 bool enable_ui = true; 1421 1422 pendingRecLock.lock(); 1413 1423 bool rec_soon = 1414 1424 pendingRecordings.find(cardid) != pendingRecordings.end(); 1415 bool enable_ui = true;1425 pendingRecLock.unlock(); 1416 1426 1417 1427 if (has_rec && (has_finish || (now > recordEndTime))) 1418 1428 { 1419 1429 if (pseudoLiveTVRecording && curRecording) 1420 1430 { … … bool TVRec::WaitForEventThreadSleep(bool 1581 1591 return ok; 1582 1592 } 1583 1593 1584 1594 void TVRec::HandlePendingRecordings(void) 1585 1595 { 1596 QMutexLocker pendlock(&pendingRecLock); 1597 1586 1598 if (pendingRecordings.empty()) 1587 1599 return; 1588 1600 1589 1601 // If we have a pending recording and AskAllowRecording 1590 1602 // or DoNotAskAllowRecording is set and the frontend is … … bool ApplyCachedPids(DTVSignalMonitor *d 1869 1881 * program number in the PAT. 1870 1882 * 1871 1883 * This method also grabs the ATSCStreamData() from the recorder 1872 1884 * if possible, or creates one if needed. 1873 1885 */ 1874 bool TVRec::SetupDTVSignalMonitor( void)1886 bool TVRec::SetupDTVSignalMonitor(bool EITscan) 1875 1887 { 1876 1888 VERBOSE(VB_RECORD, LOC + "Setting up table monitoring."); 1877 1889 1878 1890 DTVSignalMonitor *sm = GetDTVSignalMonitor(); 1879 1891 DTVChannel *dtvchan = GetDTVChannel(); … … bool TVRec::SetupDTVSignalMonitor(void) 2003 2015 sm->AddFlags(SignalMonitor::kDTVSigMon_WaitForPAT | 2004 2016 SignalMonitor::kDTVSigMon_WaitForPMT | 2005 2017 SignalMonitor::kDVBSigMon_WaitForPos); 2006 2018 sm->SetRotorTarget(1.0f); 2007 2019 2020 if (EITscan) 2021 { 2022 sm->GetStreamData()->SetVideoStreamsRequired(0); 2023 sm->IgnoreEncrypted(true); 2024 } 2025 2008 2026 VERBOSE(VB_RECORD, LOC + "Successfully set up MPEG table monitoring."); 2009 2027 return true; 2010 2028 } 2011 2029 2012 2030 QString msg = "No valid DTV info, ATSC maj(%1) min(%2), MPEG pn(%3)"; … … bool TVRec::SetupDTVSignalMonitor(void) 2024 2042 * 2025 2043 * \param tablemon If set we enable table monitoring 2026 2044 * \param notify If set we notify the frontend of the signal values 2027 2045 * \return true on success, false on failure 2028 2046 */ 2029 bool TVRec::SetupSignalMonitor(bool tablemon, bool notify)2047 bool TVRec::SetupSignalMonitor(bool tablemon, bool EITscan, bool notify) 2030 2048 { 2031 2049 VERBOSE(VB_RECORD, LOC + "SetupSignalMonitor(" 2032 2050 <<tablemon<<", "<<notify<<")"); 2033 2051 2034 2052 // if it already exists, there no need to initialize it … … bool TVRec::SetupSignalMonitor(bool tabl 2040 2058 return false; 2041 2059 2042 2060 // make sure statics are initialized 2043 2061 SignalMonitorValue::Init(); 2044 2062 2045 if (SignalMonitor::IsSupported(genOpt.cardtype) && channel->Open()) 2046 signalMonitor = SignalMonitor::Init(genOpt.cardtype, cardid, channel); 2063 if (channel->Open()) 2064 signalMonitor = SignalMonitor::Init(genOpt.cardtype, cardid, 2065 channel); 2047 2066 2048 2067 if (signalMonitor) 2049 2068 { 2050 2069 VERBOSE(VB_RECORD, LOC + "Signal monitor successfully created"); 2051 // If this is a monitor for Digital TV, initialize table monitors2052 if (GetDTVSignalMonitor() && tablemon && !SetupDTVSignalMonitor())2053 {2054 VERBOSE(VB_IMPORTANT, LOC_ERR +2055 "Failed to setup digital signal monitoring");2056 2057 return false;2058 }2059 2070 2071 signalMonitor->SetMonitoring(this, EITscan, 2072 GetDTVSignalMonitor() && tablemon); 2060 2073 signalMonitor->AddListener(this); 2061 2074 signalMonitor->SetUpdateRate(kSignalMonitoringRate); 2062 2075 signalMonitor->SetNotifyFrontend(notify); 2063 2076 2064 2077 // Start the monitoring thread 2065 signalMonitor->Start( );2078 signalMonitor->Start(true); 2066 2079 } 2067 2080 2068 2081 return true; 2069 2082 } 2070 2083 … … bool TVRec::CheckChannelPrefix(const QSt 2332 2345 2333 2346 for (uint i = 0; i < 2; i++) 2334 2347 { 2335 2348 for (uint j = 0; j < kSpacerListSize; j++) 2336 2349 { 2337 2350 QString qprefix = add_spacer( 2338 2351 prefix, (QString(spacers[j]) == "_") ? "\\_" : spacers[j]); 2339 2352 query.prepare(basequery.arg(qprefix) + cardquery[i]); 2340 2353 2341 2354 if (!query.exec() || !query.isActive()) 2342 2355 { … … bool TVRec::IsReallyRecording(void) 2465 2478 * the next time_buffer seconds. 2466 2479 * \sa EncoderLink::IsBusy(TunedInputInfo*, int time_buffer) 2467 2480 */ 2468 2481 bool TVRec::IsBusy(TunedInputInfo *busy_input, int time_buffer) const 2469 2482 { 2470 QMutexLocker lock(&stateChangeLock);2471 2472 2483 TunedInputInfo dummy; 2473 2484 if (!busy_input) 2474 2485 busy_input = &dummy; 2475 2486 2476 2487 busy_input->Clear(); … … bool TVRec::IsBusy(TunedInputInfo *busy_ 2488 2499 { 2489 2500 busy_input->inputid = channel->GetCurrentInputNum(); 2490 2501 chanid = channel->GetChanID(); 2491 2502 } 2492 2503 2504 QMutexLocker pendlock(&pendingRecLock); 2493 2505 PendingMap::const_iterator it = pendingRecordings.find(cardid); 2494 2506 if (!busy_input->inputid && (it != pendingRecordings.end())) 2495 2507 { 2496 2508 int timeLeft = QDateTime::currentDateTime() 2497 2509 .secsTo((*it).recordingStart); … … void TVRec::GetNextProgram(int direction 3168 3180 chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME); 3169 3181 compare = "<"; 3170 3182 } 3171 3183 else if (BROWSE_RIGHT == direction) 3172 3184 { 3173 3185 chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME); 3174 3186 compare = ">"; 3175 3187 sortorder = "asc"; 3176 3188 } 3177 3189 } 3178 3190 … … void TVRec::TuningShutdowns(const Tuning 3658 3670 * appropriate. 3659 3671 */ 3660 3672 void TVRec::TuningFrequency(const TuningRequest &request) 3661 3673 { 3662 3674 DTVChannel *dtvchan = GetDTVChannel(); 3675 3676 bool livetv = request.flags & kFlagLiveTV; 3677 bool antadj = request.flags & kFlagAntennaAdjust; 3678 bool has_dummy = false; 3679 3663 3680 if (dtvchan) 3664 3681 { 3665 3682 MPEGStreamData *mpeg = NULL; 3666 3683 3667 3684 if (GetDTVRecorder()) … … void TVRec::TuningFrequency(const Tuning 3674 3691 3675 3692 dtvchan->SetTuningMode(tuningmode); 3676 3693 3677 3694 if (request.minorChan && (tuningmode == "atsc")) 3678 3695 { 3679 channel->SetChannelByString(request.channel); 3680 3696 channel->SelectChannel(request.channel); 3681 3697 ATSCStreamData *atsc = dynamic_cast<ATSCStreamData*>(mpeg); 3682 3698 if (atsc) 3683 3699 atsc->SetDesiredChannel(request.majorChan, request.minorChan); 3684 3700 } 3685 3701 else if (request.progNum >= 0) 3686 3702 { 3687 channel->SetChannelByString(request.channel); 3688 3703 channel->SelectChannel(request.channel); 3689 3704 if (mpeg) 3690 3705 mpeg->SetDesiredProgram(request.progNum); 3691 3706 } 3692 3707 } 3693 3708 … … void TVRec::TuningFrequency(const Tuning 3712 3727 ok = true; 3713 3728 3714 3729 if (channel && !channum.isEmpty()) 3715 3730 { 3716 3731 if (!input.isEmpty()) 3717 ok = channel->SwitchToInput(input, channum);3732 channel->SelectInput(input, channum); 3718 3733 else 3719 ok = channel->SetChannelByString(channum); 3734 channel->SelectChannel(channum); 3735 3736 ok = true; 3720 3737 } 3721 3738 3722 3739 if (!ok) 3723 3740 { 3724 3741 if (!(request.flags & kFlagLiveTV) || !(request.flags & kFlagEITScan)) … … void TVRec::TuningFrequency(const Tuning 3741 3758 VERBOSE(VB_IMPORTANT, LOC_ERR + 3742 3759 QString("Failed to set channel to %1.").arg(channum)); 3743 3760 } 3744 3761 } 3745 3762 3746 bool livetv = request.flags & kFlagLiveTV; 3747 bool antadj = request.flags & kFlagAntennaAdjust; 3748 bool use_sm = SignalMonitor::IsRequired(genOpt.cardtype); 3749 bool use_dr = use_sm && (livetv || antadj); 3750 bool has_dummy = false; 3751 3752 if (use_dr) 3763 if (livetv || antadj) 3753 3764 { 3754 3765 // We need there to be a ringbuffer for these modes 3755 3766 bool ok; 3756 3767 ProgramInfo *tmp = pseudoLiveTVRecording; 3757 3768 pseudoLiveTVRecording = NULL; … … void TVRec::TuningFrequency(const Tuning 3773 3784 } 3774 3785 3775 3786 has_dummy = true; 3776 3787 } 3777 3788 3778 // Start signal monitoring for devices capable of monitoring 3779 if (use_sm) 3789 // Start signal (or channel change) monitoring 3790 VERBOSE(VB_RECORD, LOC + "Starting Signal Monitor"); 3791 bool error = false; 3792 if (!SetupSignalMonitor(!antadj, request.flags & kFlagEITScan, 3793 livetv | antadj)) 3780 3794 { 3781 VERBOSE(VB_RECORD, LOC + "Starting Signal Monitor"); 3782 bool error = false; 3783 if (!SetupSignalMonitor(!antadj, livetv | antadj)) 3784 { 3785 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to setup signal monitor"); 3786 if (signalMonitor) 3787 { 3788 delete signalMonitor; 3789 signalMonitor = NULL; 3790 } 3791 3792 // pretend the signal monitor is running to prevent segfault 3793 SetFlags(kFlagSignalMonitorRunning); 3794 ClearFlags(kFlagWaitingForSignal); 3795 error = true; 3796 } 3797 3795 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to setup signal monitor"); 3798 3796 if (signalMonitor) 3799 3797 { 3800 if (request.flags & kFlagEITScan) 3801 { 3802 GetDTVSignalMonitor()->GetStreamData()-> 3803 SetVideoStreamsRequired(0); 3804 GetDTVSignalMonitor()->IgnoreEncrypted(true); 3805 } 3806 3807 SetFlags(kFlagSignalMonitorRunning); 3808 ClearFlags(kFlagWaitingForSignal); 3809 if (!antadj) 3810 SetFlags(kFlagWaitingForSignal); 3798 delete signalMonitor; 3799 signalMonitor = NULL; 3811 3800 } 3812 3801 3813 if (has_dummy && ringBuffer) 3814 { 3815 // Make sure recorder doesn't point to bogus ringbuffer before 3816 // it is potentially restarted without a new ringbuffer, if 3817 // the next channel won't tune and the user exits LiveTV. 3818 if (recorder) 3819 recorder->SetRingBuffer(NULL); 3802 // pretend the signal monitor is running to prevent segfault 3803 SetFlags(kFlagSignalMonitorRunning); 3804 ClearFlags(kFlagWaitingForSignal); 3805 error = true; 3806 } 3820 3807 3821 SetFlags(kFlagDummyRecorderRunning); 3822 VERBOSE(VB_RECORD, "DummyDTVRecorder -- started"); 3823 SetFlags(kFlagRingBufferReady); 3824 } 3808 if (signalMonitor) 3809 { 3810 SetFlags(kFlagSignalMonitorRunning); 3811 ClearFlags(kFlagWaitingForSignal); 3812 if (!antadj) 3813 SetFlags(kFlagWaitingForSignal); 3814 } 3825 3815 3826 // if we had problems starting the signal monitor, 3827 // we don't want to start the recorder... 3828 if (error) 3829 return; 3816 if (has_dummy && ringBuffer) 3817 { 3818 // Make sure recorder doesn't point to bogus ringbuffer before 3819 // it is potentially restarted without a new ringbuffer, if 3820 // the next channel won't tune and the user exits LiveTV. 3821 if (recorder) 3822 recorder->SetRingBuffer(NULL); 3823 3824 SetFlags(kFlagDummyRecorderRunning); 3825 VERBOSE(VB_RECORD, "DummyDTVRecorder -- started"); 3826 SetFlags(kFlagRingBufferReady); 3830 3827 } 3831 3828 3829 // if we had problems starting the signal monitor, 3830 // we don't want to start the recorder... 3831 if (error) 3832 return; 3833 3832 3834 // Request a recorder, if the command is a recording command 3833 3835 ClearFlags(kFlagNeedToStartRecorder); 3834 3836 if (request.flags & kFlagRec && !antadj) 3835 3837 SetFlags(kFlagNeedToStartRecorder); 3836 3838 } -
libs/libmythtv/tv_rec.h
old new class PendingInfo 148 148 typedef QMap<uint,PendingInfo> PendingMap; 149 149 150 150 class MPUBLIC TVRec : public SignalMonitorListener 151 151 { 152 152 friend class TuningRequest; 153 friend class SignalMonitor; 153 154 154 155 public: 155 156 TVRec(int capturecardnum); 156 157 ~TVRec(void); 157 158 … … class MPUBLIC TVRec : public SignalMonit 242 243 uint GetFlags(void) const { return stateFlags; } 243 244 244 245 static TVRec *GetTVRec(uint cardid); 245 246 246 247 virtual void AllGood(void) { WakeEventLoop(); } 248 virtual void StatusChannelTuned(const SignalMonitorValue&) { } 247 249 virtual void StatusSignalLock(const SignalMonitorValue&) { } 248 250 virtual void StatusSignalStrength(const SignalMonitorValue&) { } 249 251 250 252 protected: 251 253 void RunTV(void); 252 254 bool WaitForEventThreadSleep(bool wake = true, ulong time = ULONG_MAX); 253 255 static void *EventThread(void *param); 254 256 static void *RecorderThread(void *param); 257 bool SetupDTVSignalMonitor(bool EITscan); 255 258 256 259 private: 257 260 void SetRingBuffer(RingBuffer *); 258 261 void SetPseudoLiveTVRecording(ProgramInfo*); 259 262 void TeardownAll(void); … … class MPUBLIC TVRec : public SignalMonit 279 282 HDHRChannel *GetHDHRChannel(void); 280 283 DVBChannel *GetDVBChannel(void); 281 284 FirewireChannel *GetFirewireChannel(void); 282 285 V4LChannel *GetV4LChannel(void); 283 286 284 bool SetupSignalMonitor(bool enable_table_monitoring, bool notify);285 bool SetupDTVSignalMonitor(void);287 bool SetupSignalMonitor(bool enable_table_monitoring, 288 bool EITscan, bool notify); 286 289 void TeardownSignalMonitor(void); 287 290 DTVSignalMonitor *GetDTVSignalMonitor(void); 288 291 289 292 bool HasFlags(uint f) const { return (stateFlags & f) == f; } 290 293 void SetFlags(uint f); … … class MPUBLIC TVRec : public SignalMonit 358 361 DVBDBOptions dvbOpt; 359 362 FireWireDBOptions fwOpt; 360 363 361 364 // State variables 362 365 mutable QMutex stateChangeLock; 366 mutable QMutex pendingRecLock; 363 367 TVState internalState; 364 368 TVState desiredNextState; 365 369 bool changeState; 366 370 bool pauseNotify; 367 371 uint stateFlags; -
libs/libmythtv/v4lchannel.h
old new class V4LChannel : public DTVChannel 47 47 int GetFd(void) const { return videofd; } 48 48 QString GetDevice(void) const { return device; } 49 49 QString GetSIStandard(void) const { return "atsc"; } 50 50 51 51 // Commands 52 bool SwitchToInput(int newcapchannel, bool setstarting);53 52 bool Retune(void); 54 53 55 54 // Picture attributes. 56 55 bool InitPictureAttributes(void); 57 56 int GetPictureAttribute(PictureAttribute) const; … … class V4LChannel : public DTVChannel 67 66 68 67 // Analog scanning stuff 69 68 bool Tune(uint frequency, QString inputname, 70 69 QString modulation, QString si_std); 71 70 71 protected: 72 bool SwitchToInput(int newcapchannel, bool setstarting); 73 72 74 private: 73 75 // Helper Sets 74 76 void SetFreqTable(const int index); 75 77 int SetFreqTable(const QString &name); 76 78 bool SetInputAndFormat(int newcapchannel, QString newFmt);