Ticket #6719: channel-thread-0.23-fixes-25369.patch

File channel-thread-0.23-fixes-25369.patch, 48.7 KB (added by jpoet, 22 months ago)

Fixes interaction with multi-rec

  • libs/libmythtv/analogsignalmonitor.cpp

    old new void AnalogSignalMonitor::UpdateValues(v 
    3232    if (videofd < 0) 
    3333        return; 
    3434 
     35    if (!IsChannelTuned()) 
     36        return; 
     37 
    3538    bool isLocked = false; 
    3639    if (usingv4l2) 
    3740    { 
  • libs/libmythtv/channelbase.cpp

    old new using namespace std; 
    3535#define LOC_WARN QString("ChannelBase(%1) Warning: ").arg(GetCardID()) 
    3636#define LOC_ERR QString("ChannelBase(%1) Error: ").arg(GetCardID()) 
    3737 
     38/* 
     39 * Run the channel change thread, and report the status when done 
     40 */ 
     41void ChannelThread::run(void) 
     42{ 
     43  VERBOSE(VB_CHANNEL, "ChannelThread::run"); 
     44    bool result = tuner->SetChannelByString(channel); 
     45    tuner->setStatus(result ? 
     46                     ChannelBase::changeSuccess : ChannelBase::changeFailed); 
     47} 
     48 
    3849ChannelBase::ChannelBase(TVRec *parent) 
    3950    : 
    4051    pParent(parent), curchannelname(""), 
    41     currentInputID(-1), commfree(false), cardid(0) 
     52    currentInputID(-1), commfree(false), cardid(0), 
     53    abort_change(false) 
    4254{ 
     55    tuneStatus = changeUnknown; 
     56    tuneThread.tuner = this; 
    4357} 
    4458 
    4559ChannelBase::~ChannelBase(void) 
    4660{ 
    4761    ClearInputMap(); 
     62    TeardownAll(); 
     63} 
     64 
     65void ChannelBase::TeardownAll(void) 
     66{ 
     67    if (tuneThread.isRunning()) 
     68    { 
     69        thread_lock.lock(); 
     70        abort_change = true; 
     71        tuneCond.wakeAll(); 
     72        thread_lock.unlock(); 
     73        tuneThread.wait(); 
     74    } 
     75} 
     76 
     77void ChannelBase::SelectChannel(const QString & chan) 
     78{ 
     79    VERBOSE(VB_CHANNEL, LOC + "SelectChannel " + chan); 
     80    TeardownAll(); 
     81 
     82    thread_lock.lock(); 
     83    abort_change = false; 
     84    tuneStatus = changePending; 
     85    thread_lock.unlock(); 
     86 
     87    curchannelname = tuneThread.channel = chan; 
     88    tuneThread.start(); 
     89} 
     90 
     91/* 
     92 * Returns true of the channel change thread should abort 
     93 */ 
     94bool ChannelBase::Aborted(void) 
     95{ 
     96    bool       result; 
     97 
     98    thread_lock.lock(); 
     99    result = abort_change; 
     100    thread_lock.unlock(); 
     101 
     102    return result; 
     103} 
     104 
     105ChannelBase::Status ChannelBase::GetStatus(void) 
     106{ 
     107    Status status; 
     108 
     109    thread_lock.lock(); 
     110    status = tuneStatus; 
     111    thread_lock.unlock(); 
     112 
     113    return status; 
     114} 
     115 
     116ChannelBase::Status ChannelBase::Wait(void) 
     117{ 
     118    tuneThread.wait(); 
     119    return tuneStatus; 
     120} 
     121 
     122void ChannelBase::setStatus(ChannelBase::Status status) 
     123{ 
     124    thread_lock.lock(); 
     125    tuneStatus = status; 
     126    thread_lock.unlock(); 
    48127} 
    49128 
    50129bool ChannelBase::Init(QString &inputname, QString &startchannel, bool setchan) 
    51130{ 
    52131    bool ok; 
    53132 
     133    VERBOSE(VB_CHANNEL, LOC + QString("Init(%1, %2, %3)") 
     134            .arg(inputname).arg(startchannel).arg(setchan)); 
     135 
    54136    if (!setchan) 
    55137        ok = inputname.isEmpty() ? false : IsTunable(inputname, startchannel); 
    56138    else if (inputname.isEmpty()) 
    57         ok = SetChannelByString(startchannel); 
     139    { 
     140        SelectChannel(startchannel); 
     141        ok = Wait(); 
     142    } 
    58143    else 
    59         ok = SwitchToInput(inputname, startchannel); 
     144        ok = SelectInput(inputname, startchannel, false); 
    60145 
    61146    if (ok) 
    62147        return true; 
    bool ChannelBase::Init(QString &inputnam 
    125210            if (chanid && cit != channels.end()) 
    126211            { 
    127212                if (!setchan) 
    128                 { 
    129213                    ok = IsTunable(*it, (mplexid_restriction) ? 
    130214                                   (*cit).channum : startchannel); 
    131                 } 
    132215                else 
    133                     ok = SwitchToInput(*it, (*cit).channum); 
     216                    ok = SelectInput(*it, (*cit).channum, false); 
    134217 
    135218                if (ok) 
    136219                { 
    int ChannelBase::GetInputByName(const QS 
    330413    return -1; 
    331414} 
    332415 
     416#if 0 // Not used? 
    333417bool ChannelBase::SwitchToInput(const QString &inputname) 
    334418{ 
    335419    int input = GetInputByName(inputname); 
    bool ChannelBase::SwitchToInput(const QS 
    341425                                      "%1 on card\n").arg(inputname)); 
    342426    return false; 
    343427} 
     428#endif 
    344429 
    345 bool ChannelBase::SwitchToInput(const QString &inputname, const QString &chan) 
     430bool ChannelBase::SelectInput(const QString &inputname, const QString &chan, 
     431                              bool use_sm) 
    346432{ 
    347433    int input = GetInputByName(inputname); 
    348434 
    349     bool ok = false; 
     435    VERBOSE(VB_CHANNEL, LOC + QString("SelectInput(%1, %2) %3") 
     436            .arg(inputname).arg(chan).arg(input)); 
     437 
    350438    if (input >= 0) 
    351439    { 
    352         ok = SwitchToInput(input, false); 
    353         if (ok) 
    354             ok = SetChannelByString(chan); 
     440        if (!SwitchToInput(input, false)) 
     441            return false; 
     442        if (use_sm) 
     443            SelectChannel(chan); 
     444        else 
     445            return SetChannelByString(chan); 
    355446    } 
    356447    else 
    357448    { 
    358449        VERBOSE(VB_IMPORTANT, 
    359450                QString("ChannelBase: Could not find input: %1 on card when " 
    360451                        "setting channel %2\n").arg(inputname).arg(chan)); 
     452        return false; 
    361453    } 
    362     return ok; 
     454    return true; 
    363455} 
    364456 
    365457bool ChannelBase::SwitchToInput(int newInputNum, bool setstarting) 
    366458{ 
     459    VERBOSE(VB_CHANNEL, LOC + QString("SwitchToInput(%1, %2)") 
     460            .arg(newInputNum).arg(setstarting)); 
     461 
    367462    InputMap::const_iterator it = inputs.find(newInputNum); 
    368463    if (it == inputs.end() || (*it)->startChanNum.isEmpty()) 
    369464        return false; 
    bool ChannelBase::SwitchToInput(int newI 
    375470    // input switching code would go here 
    376471 
    377472    if (setstarting) 
    378         return SetChannelByString((*it)->startChanNum); 
     473        SelectChannel((*it)->startChanNum); 
    379474 
    380475    return true; 
    381476} 
    static bool is_input_busy( 
    486581    return is_busy; 
    487582} 
    488583 
    489 bool ChannelBase::IsInputAvailable( 
    490     int inputid, uint &mplexid_restriction) const 
     584bool ChannelBase::IsInputAvailable(int inputid, uint &mplexid_restriction) const 
    491585{ 
    492586    if (inputid < 0) 
    493587        return false; 
    bool ChannelBase::ChangeExternalChannel( 
    652746    } 
    653747    else 
    654748    {   // child contains the pid of the new process 
    655         int status = 0, pid = 0; 
     749        QMutex      lock; 
     750        int         status = 0, pid = 0; 
     751 
    656752        VERBOSE(VB_CHANNEL, "Waiting for External Tuning program to exit"); 
    657753 
    658754        bool timed_out = false; 
    659755        uint timeout = 30; // how long to wait in seconds 
    660756        time_t start_time = time(0); 
    661         while (-1 != pid && !timed_out) 
     757        while (-1 != pid && !timed_out && !Aborted()) 
    662758        { 
    663             sleep(1); 
     759            lock.lock(); 
     760            tuneCond.wait(&lock, 500);  // sleep up to 0.5 seconds 
    664761            pid = waitpid(child, &status, WUNTRACED|WNOHANG); 
    665762            VERBOSE(VB_IMPORTANT, QString("ret_pid(%1) child(%2) status(0x%3)") 
    666763                    .arg(pid).arg(child).arg(status,0,16)); 
    667764            if (pid==child) 
     765            { 
     766                lock.unlock(); 
    668767                break; 
     768            } 
    669769            else if (time(0) > (time_t)(start_time + timeout)) 
    670770                timed_out = true; 
     771            lock.unlock(); 
    671772        } 
    672         if (timed_out) 
     773 
     774        if (timed_out || Aborted()) 
    673775        { 
    674             VERBOSE(VB_IMPORTANT, "External Tuning program timed out, killing"); 
     776            if (Aborted()) 
     777                VERBOSE(VB_IMPORTANT, "Aborting External Tuning program"); 
     778            else 
     779                VERBOSE(VB_IMPORTANT, "External Tuning program timed out, " 
     780                        "killing"); 
    675781            kill(child, SIGTERM); 
    676782            usleep(500); 
    677783            kill(child, SIGKILL); 
    int ChannelBase::GetChanID() const 
    753859        return -1; 
    754860 
    755861    query.next(); 
     862 
     863    VERBOSE(VB_CHANNEL, LOC + QString(" ChannelBase::GetChanID %1") 
     864            .arg(query.value(0).toInt()));; 
     865 
    756866    return query.value(0).toInt(); 
    757867} 
    758868 
  • libs/libmythtv/channelbase.h

    old new  
    55 
    66// Qt headers 
    77#include <QStringList> 
     8#include <qwaitcondition.h> 
     9#include <qmutex.h> 
     10#include <qthread.h> 
    811 
    912// MythTV headers 
    1013#include "channelutil.h" 
     
    1215#include "tv.h" 
    1316 
    1417class TVRec; 
     18class ChannelBase; 
     19 
     20/* 
     21 * Thread to run tunning process in 
     22 */ 
     23class ChannelThread : public QThread 
     24{ 
     25  public: 
     26    virtual void run(void); 
     27 
     28    QString      channel; 
     29    ChannelBase *tuner; 
     30}; 
    1531 
    1632/** \class ChannelBase 
    1733 *  \brief Abstract class providing a generic interface to tuning hardware. 
    class TVRec; 
    2339 
    2440class ChannelBase 
    2541{ 
    26  public: 
     42    friend class ChannelThread; 
     43 
     44  public: 
     45    enum Status { changeUnknown = 'U', changePending = 'P', 
     46                  changeFailed = 'F', changeSuccess = 'S' }; 
     47 
    2748    ChannelBase(TVRec *parent); 
    28     virtual ~ChannelBase(); 
     49    virtual ~ChannelBase(void); 
    2950 
    3051    virtual bool Init(QString &inputname, QString &startchannel, bool setchan); 
    3152    virtual bool IsTunable(const QString &input, const QString &channum) const; 
    3253 
     54    virtual void SelectChannel(const QString & chan); 
     55 
     56    Status GetStatus(void); 
     57    Status Wait(void); 
     58 
    3359    // Methods that must be implemented. 
    3460    /// \brief Opens the channel changing hardware for use. 
    3561    virtual bool Open(void) = 0; 
    3662    /// \brief Closes the channel changing hardware to use. 
    3763    virtual void Close(void) = 0; 
    38     virtual bool SetChannelByString(const QString &chan) = 0; 
    3964    /// \brief Reports whether channel is already open 
    4065    virtual bool IsOpen(void) const = 0; 
    4166 
    class ChannelBase 
    82107                          const QString &newChanNum); 
    83108 
    84109    // Input toggling convenience methods 
    85     virtual bool SwitchToInput(const QString &input); 
    86     virtual bool SwitchToInput(const QString &input, const QString &chan); 
     110//    virtual bool SwitchToInput(const QString &input); // not used? 
     111    virtual bool SelectInput(const QString &input, const QString &chan, 
     112                             bool use_sm); 
    87113 
    88114    virtual bool InitializeInputs(void); 
    89115 
    class ChannelBase 
    108134 
    109135    virtual int GetCardID(void) const; 
    110136  protected: 
     137    virtual bool SetChannelByString(const QString &chan) = 0; 
     138 
    111139    /// \brief Switches to another input on hardware, 
    112140    ///        and sets the channel is setstarting is true. 
    113141    virtual bool SwitchToInput(int inputNum, bool setstarting); 
    class ChannelBase 
    119147    static void StoreDefaultInput(uint cardid, const QString &input); 
    120148    void ClearInputMap(void); 
    121149 
     150    bool Aborted(); 
     151    void setStatus(Status status); 
     152    void TeardownAll(void); 
     153 
    122154    TVRec   *pParent; 
    123155    QString  curchannelname; 
    124156    int      currentInputID; 
    class ChannelBase 
    126158    uint     cardid; 
    127159    InputMap inputs; 
    128160    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; 
    129169}; 
    130170 
    131171#endif 
  • 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 
     15ChannelChangeMonitor::ChannelChangeMonitor( 
     16    int db_cardnum, V4LChannel *_channel, uint64_t _flags) : 
     17    SignalMonitor(db_cardnum, _channel, _flags) 
     18{ 
     19} 
     20 
     21void 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 
     10class V4LChannel; 
     11 
     12class 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  
    16261626    } 
    16271627 
    16281628    // Start signal monitor for this channel 
    1629     signalMonitor->Start(); 
     1629    signalMonitor->Start(false); 
    16301630 
    16311631    timer.start(); 
    16321632    waitingForTables = (item.tuning.sistandard != "analog"); 
  • libs/libmythtv/channelscan/channelscan_sm.h

    old new class AnalogSignalHandler : public Signa 
    7373  public slots: 
    7474    virtual inline void AllGood(void); 
    7575    virtual void StatusSignalLock(const SignalMonitorValue&) { } 
     76    virtual void StatusChannelTuned(const SignalMonitorValue&) { } 
    7677    virtual void StatusSignalStrength(const SignalMonitorValue&) { } 
    7778 
    7879  private: 
  • libs/libmythtv/channelscan/scanmonitor.cpp

    old new QEvent::Type ScannerEvent::SetStatusSign 
    5555    (QEvent::Type) QEvent::registerEventType(); 
    5656QEvent::Type ScannerEvent::SetStatusSignalLock = 
    5757    (QEvent::Type) QEvent::registerEventType(); 
     58QEvent::Type ScannerEvent::SetStatusChannelTuned = 
     59    (QEvent::Type) QEvent::registerEventType(); 
    5860 
    5961/// Percentage to set to after the transports have been scanned 
    6062#define TRANSPORT_PCT 6 
    void ScanMonitor::StatusSignalLock(const 
    133135    post_event(this, ScannerEvent::SetStatusSignalLock, val.GetValue()); 
    134136} 
    135137 
     138void ScanMonitor::StatusChannelTuned(const SignalMonitorValue &val) 
     139{ 
     140    post_event(this, ScannerEvent::SetStatusChannelTuned, val.GetValue()); 
     141} 
     142 
    136143void ScanMonitor::StatusSignalToNoise(const SignalMonitorValue &val) 
    137144{ 
    138145    post_event(this, ScannerEvent::SetStatusSignalToNoise, 
  • libs/libmythtv/channelscan/scanmonitor.h

    old new class ScanMonitor : 
    6565    // SignalMonitorListener 
    6666    virtual void AllGood(void) { } 
    6767    virtual void StatusSignalLock(const SignalMonitorValue&); 
     68    virtual void StatusChannelTuned(const SignalMonitorValue&); 
    6869    virtual void StatusSignalStrength(const SignalMonitorValue&); 
    6970 
    7071    // DVBSignalMonitorListener 
    class ScannerEvent : public QEvent 
    110111    static Type SetStatusSignalToNoise; 
    111112    static Type SetStatusSignalStrength; 
    112113    static Type SetStatusSignalLock; 
     114    static Type SetStatusChannelTuned; 
    113115 
    114116  private: 
    115117    ~ScannerEvent() { } 
  • libs/libmythtv/dtvsignalmonitor.cpp

    old new DTVSignalMonitor::DTVSignalMonitor(int d 
    2525                                   uint64_t wait_for_mask) 
    2626    : SignalMonitor(db_cardnum, _channel, wait_for_mask), 
    2727      stream_data(NULL), 
     28      channelTuned(QObject::tr("Channel Tuned"), "tuned", 3, true, 0, 3, 0), 
    2829      seenPAT(QObject::tr("Seen")+" PAT", "seen_pat", 1, true, 0, 1, 0), 
    2930      seenPMT(QObject::tr("Seen")+" PMT", "seen_pmt", 1, true, 0, 1, 0), 
    3031      seenMGT(QObject::tr("Seen")+" MGT", "seen_mgt", 1, true, 0, 1, 0), 
    QStringList DTVSignalMonitor::GetStatusL 
    6364{ 
    6465    QStringList list = SignalMonitor::GetStatusList(kick); 
    6566    QMutexLocker locker(&statusLock); 
     67 
     68    // tuned? 
     69    if (flags & kSigMon_Tuned) 
     70    { 
     71        list<<channelTuned.GetName()<<channelTuned.GetStatus(); 
     72    } 
     73 
    6674    // mpeg tables 
    6775    if (flags & kDTVSigMon_WaitForPAT) 
    6876    { 
    void DTVSignalMonitor::RemoveFlags(uint6 
    138146void DTVSignalMonitor::UpdateMonitorValues(void) 
    139147{ 
    140148    QMutexLocker locker(&statusLock); 
     149    channelTuned.SetValue((flags & kSigMon_Tuned)      ? 3 : 1); 
    141150    seenPAT.SetValue(    (flags & kDTVSigMon_PATSeen)  ? 1 : 0); 
    142151    seenPMT.SetValue(    (flags & kDTVSigMon_PMTSeen)  ? 1 : 0); 
    143152    seenMGT.SetValue(    (flags & kDTVSigMon_MGTSeen)  ? 1 : 0); 
  • libs/libmythtv/dtvsignalmonitor.h

    old new class DTVSignalMonitor : public SignalMo 
    111111  protected: 
    112112    MPEGStreamData    *stream_data; 
    113113    vector<uint>       eit_pids; 
     114    SignalMonitorValue channelTuned; 
    114115    SignalMonitorValue seenPAT; 
    115116    SignalMonitorValue seenPMT; 
    116117    SignalMonitorValue seenMGT; 
  • libs/libmythtv/dvbsignalmonitor.cpp

    old new void DVBSignalMonitor::UpdateValues(void 
    230230        return; 
    231231    } 
    232232 
     233    if (!IsChannelTuned()) 
     234        return; 
     235 
    233236    AddFlags(kSigMon_WaitForSig); 
    234237 
    235238    DVBChannel *dvbchannel = GetDVBChannel(); 
  • libs/libmythtv/firewiresignalmonitor.cpp

    old new void FirewireSignalMonitor::UpdateValues 
    190190    if (!running || exit) 
    191191        return; 
    192192 
     193    if (!IsChannelTuned()) 
     194        return; 
     195 
    193196    if (dtvMonitorRunning) 
    194197    { 
    195198        EmitStatus(); 
  • libs/libmythtv/hdhrchannel.cpp

    old new bool HDHRChannel::SetChannelByString(con 
    131131    // change inputs and return, since the act of changing 
    132132    // inputs will change the channel as well. 
    133133    if (!inputName.isEmpty()) 
    134         return SwitchToInput(inputName, channum); 
     134        return SelectInput(inputName, channum, false); 
    135135 
    136136    ClearDTVInfo(); 
    137137 
    bool HDHRChannel::SetChannelByString(con 
    143143    if (!IsInputAvailable(currentInputID, mplexid_restriction)) 
    144144        return false; 
    145145 
     146    if (Aborted()) 
     147        return false; 
     148 
    146149    // Fetch tuning data from the database. 
    147150    QString tvformat, modulation, freqtable, freqid, si_std; 
    148151    int finetune; 
  • libs/libmythtv/hdhrsignalmonitor.cpp

    old new void HDHRSignalMonitor::UpdateValues(voi 
    105105        return; 
    106106    } 
    107107 
     108    if (!IsChannelTuned()) 
     109        return; 
     110 
    108111    struct hdhomerun_tuner_status_t status; 
    109112    streamHandler->GetTunerStatus(&status); 
    110113 
  • libs/libmythtv/iptvsignalmonitor.cpp

    old new void IPTVSignalMonitor::UpdateValues(voi 
    119119    if (!running || exit) 
    120120        return; 
    121121 
     122    if (!IsChannelTuned()) 
     123        return; 
     124 
    122125    if (dtvMonitorRunning) 
    123126    { 
    124127        EmitStatus(); 
  • libs/libmythtv/libmythtv.pro

    old new using_backend { 
    445445        LIBS += $$OSS_LIBS 
    446446    } 
    447447 
     448    HEADERS += channelchangemonitor.h 
     449    SOURCES += channelchangemonitor.cpp 
     450 
    448451    # Support for Video4Linux devices 
    449452    using_v4l { 
    450453        HEADERS += v4lchannel.h                analogsignalmonitor.h 
  • libs/libmythtv/signalmonitor.cpp

    old new  
    88 
    99// MythTV headers 
    1010#include "mythcontext.h" 
     11#include "tv_rec.h" 
    1112#include "signalmonitor.h" 
    1213#include "compat.h" 
    1314#include "mythverbose.h" 
    extern "C" { 
    4243#   include "firewirechannel.h" 
    4344#endif 
    4445 
     46#include "channelchangemonitor.h" 
     47 
    4548#undef DBG_SM 
    4649#define DBG_SM(FUNC, MSG) VERBOSE(VB_CHANNEL, \ 
    4750    "SM("<<channel->GetDevice()<<")::"<<FUNC<<": "<<MSG); 
    SignalMonitor *SignalMonitor::Init(QStri 
    9396#endif 
    9497 
    9598#ifdef USING_V4L 
     99#if 0 // Just use ChannelChangeMonitor for these types 
    96100    if ((cardtype.toUpper() == "V4L") || 
    97         (cardtype.toUpper() == "MPEG") || 
    98         (cardtype.toUpper() == "HDPVR")) 
     101        (cardtype.toUpper() == "MPEG")) 
    99102    { 
    100103        V4LChannel *chan = dynamic_cast<V4LChannel*>(channel); 
    101104        if (chan) 
    102105            signalMonitor = new AnalogSignalMonitor(db_cardnum, chan); 
    103106    } 
    104107#endif 
     108#endif 
    105109 
    106110#ifdef USING_HDHOMERUN 
    107111    if (cardtype.toUpper() == "HDHOMERUN") 
    SignalMonitor *SignalMonitor::Init(QStri 
    132136 
    133137    if (!signalMonitor) 
    134138    { 
     139        V4LChannel *chan = dynamic_cast<V4LChannel*>(channel); 
     140        if (chan) 
     141            signalMonitor = new ChannelChangeMonitor(db_cardnum, chan); 
     142    } 
     143 
     144    if (!signalMonitor) 
     145    { 
    135146        VERBOSE(VB_IMPORTANT, 
    136147                QString("Failed to create signal monitor in Init(%1, %2, 0x%3)") 
    137148                .arg(cardtype).arg(db_cardnum).arg((long)channel,0,16)); 
    SignalMonitor::SignalMonitor(int _captur 
    160171      update_rate(25),                 minimum_update_rate(5), 
    161172      running(false),                  exit(false), 
    162173      update_done(false),              notify_frontend(true), 
    163       error(""), 
     174      is_tuned(false),                 tablemon(false), 
     175      eit_scan(false),                 error(""), 
    164176      signalLock    (QObject::tr("Signal Lock"),  "slock", 
    165177                     1, true, 0,   1, 0), 
    166178      signalStrength(QObject::tr("Signal Power"), "signal", 
    167179                     0, true, 0, 100, 0), 
     180      channelTuned("Channel Tuned", "tuned", 3, true, 0, 3, 0), 
    168181      statusLock(QMutex::Recursive) 
    169182{ 
    170183} 
    bool SignalMonitor::HasAnyFlag(uint64_t  
    202215/** \fn SignalMonitor::Start() 
    203216 *  \brief Start signal monitoring thread. 
    204217 */ 
    205 void SignalMonitor::Start() 
     218void SignalMonitor::Start(bool waitfor_tune) 
    206219{ 
    207220    DBG_SM("Start", "begin"); 
    208221    { 
    209222        QMutexLocker locker(&startStopLock); 
     223 
     224        // When used for scanning, don't wait for the tuning thread 
     225        is_tuned = !waitfor_tune; 
     226 
    210227        if (!running) 
    211228        { 
    212229            int rval = pthread_create( 
    QStringList SignalMonitor::GetStatusList 
    279296 
    280297    QStringList list; 
    281298    statusLock.lock(); 
     299    list<<channelTuned.GetName()<<channelTuned.GetStatus(); 
    282300    list<<signalLock.GetName()<<signalLock.GetStatus(); 
    283301    if (HasFlags(kSigMon_WaitForSig)) 
    284302        list<<signalStrength.GetName()<<signalStrength.GetStatus(); 
    void SignalMonitor::MonitorLoop() 
    306324            QStringList slist = GetStatusList(false); 
    307325            MythEvent me(QString("SIGNAL %1").arg(capturecardnum), slist); 
    308326            gContext->dispatch(me); 
    309             //cerr<<"sent SIGNAL"<<endl; 
    310327        } 
    311328 
    312329        usleep(update_rate * 1000); 
    void SignalMonitor::SendMessage( 
    441458        case kStatusSignalStrength: 
    442459            listener->StatusSignalStrength(val); 
    443460            break; 
     461        case kStatusChannelTuned: 
     462            listener->StatusChannelTuned(val); 
     463            break; 
    444464        case kStatusSignalToNoise: 
    445465            if (dvblistener) 
    446466                dvblistener->StatusSignalToNoise(val); 
    void SignalMonitor::SendMessage( 
    461481    } 
    462482} 
    463483 
     484bool 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 
    464518void SignalMonitor::SendMessageAllGood(void) 
    465519{ 
    466520    QMutexLocker locker(&listenerLock); 
    void SignalMonitor::SendMessageAllGood(v 
    470524 
    471525void SignalMonitor::EmitStatus(void) 
    472526{ 
     527    SendMessage(kStatusChannelTuned, channelTuned); 
    473528    SendMessage(kStatusSignalLock, signalLock); 
    474529    if (HasFlags(kSigMon_WaitForSig)) 
    475530        SendMessage(kStatusSignalStrength,    signalStrength); 
  • libs/libmythtv/signalmonitor.h

    old new using namespace std; 
    2626 
    2727inline QString sm_flags_to_string(uint64_t); 
    2828 
     29class TVRec; 
     30 
    2931class SignalMonitor 
    3032{ 
    3133  public: 
    class SignalMonitor 
    3941    // // // // // // // // // // // // // // // // // // // // // // // // 
    4042    // Control  // // // // // // // // // // // // // // // // // // // // 
    4143 
    42     virtual void Start(); 
     44    virtual void Start(bool waitfor_tune); 
    4345    virtual void Stop(); 
    4446    virtual void Kick(); 
    4547    virtual bool WaitForLock(int timeout = -1); 
    class SignalMonitor 
    8385     */ 
    8486    void SetNotifyFrontend(bool notify) { notify_frontend = notify; } 
    8587 
     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 
    8695    /** \brief Sets the number of milliseconds between signal monitoring 
    8796     *         attempts in the signal monitoring thread. 
    8897     * 
    class SignalMonitor 
    108117    static void* SpawnMonitorLoop(void*); 
    109118    virtual void MonitorLoop(); 
    110119 
     120    bool IsChannelTuned(void); 
     121 
    111122    /// \brief This should be overridden to actually do signal monitoring. 
    112123    virtual void UpdateValues() { ; } 
    113124 
    class SignalMonitor 
    139150    /// We've seen something indicating whether the data stream is encrypted 
    140151    static const uint64_t kDTVSigMon_CryptSeen  = 0x0000000200ULL; 
    141152 
     153    static const uint64_t kSigMon_Tuned         = 0x0000000400ULL; 
     154 
    142155    /// We've seen a PAT matching our requirements 
    143156    static const uint64_t kDTVSigMon_PATMatch   = 0x0000001000ULL; 
    144157    /// We've seen a PMT matching our requirements 
    class SignalMonitor 
    184197  protected: 
    185198    pthread_t    monitor_thread; 
    186199    ChannelBase *channel; 
     200    TVRec       *pParent; 
    187201    int          capturecardnum; 
    188202    uint64_t     flags; 
    189203    int          update_rate; 
    class SignalMonitor 
    192206    bool         exit; 
    193207    bool         update_done; 
    194208    bool         notify_frontend; 
     209    bool         is_tuned; 
     210    bool         tablemon; 
     211    bool         eit_scan; 
    195212    QString      error; 
    196213 
    197214    SignalMonitorValue signalLock; 
    198215    SignalMonitorValue signalStrength; 
     216    SignalMonitorValue channelTuned; 
    199217 
    200218    vector<SignalMonitorListener*> listeners; 
    201219 
  • libs/libmythtv/signalmonitorlistener.h

    old new  
    99 
    1010typedef enum { 
    1111    kAllGood, 
     12    kStatusChannelTuned, 
    1213    kStatusSignalLock, 
    1314    kStatusSignalStrength, 
    1415    kStatusSignalToNoise, 
    class MPUBLIC SignalMonitorListener 
    3031     */ 
    3132    virtual void AllGood(void) = 0; 
    3233 
     34    /** \brief Signal 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 
    3341    /** \brief Signal to be sent as true when it is safe to begin 
    3442     *   or continue recording, and false if it may not be safe. 
    3543     * 
  • libs/libmythtv/tv_play.cpp

    old new void TV::UpdateOSDSignal(const PlayerCon 
    74457445    float snr  = 0.0f; 
    74467446    uint  ber  = 0xffffffff; 
    74477447    int   pos  = -1; 
     7448    int   tuned = -1; 
    74487449    QString pat(""), pmt(""), mgt(""), vct(""), nit(""), sdt(""), crypt(""); 
    74497450    QString err = QString::null, msg = QString::null; 
    74507451    for (it = slist.begin(); it != slist.end(); ++it) 
    void TV::UpdateOSDSignal(const PlayerCon 
    74717472            ber = it->GetValue(); 
    74727473        else if ("pos" == it->GetShortName()) 
    74737474            pos = it->GetValue(); 
     7475        else if ("tuned" == it->GetShortName()) 
     7476            tuned = it->GetValue(); 
    74747477        else if ("seen_pat" == it->GetShortName()) 
    74757478            pat = it->IsGood() ? "a" : "_"; 
    74767479        else if ("matching_pat" == it->GetShortName()) 
    void TV::UpdateOSDSignal(const PlayerCon 
    75047507        infoMap["signal"] = QString::number(sig); // use normalized value 
    75057508 
    75067509    bool    allGood = SignalMonitorValue::AllGood(slist); 
     7510    char    tuneCode; 
    75077511    QString slock   = ("1" == infoMap["slock"]) ? "L" : "l"; 
    75087512    QString lockMsg = (slock=="L") ? tr("Partial Lock") : tr("No Lock"); 
    75097513    QString sigMsg  = allGood ? tr("Lock") : lockMsg; 
    void TV::UpdateOSDSignal(const PlayerCon 
    75167520    if ((pos >= 0) && (pos < 100)) 
    75177521        sigDesc += " | " + tr("Rotor %1\%").arg(pos,2); 
    75187522 
    7519     sigDesc = sigDesc + QString(" | (%1%2%3%4%5%6%7%8) %9") 
    7520         .arg(slock).arg(pat).arg(pmt).arg(mgt).arg(vct) 
    7521         .arg(nit).arg(sdt).arg(crypt).arg(sigMsg); 
     7523    if (tuned == 1) 
     7524        tuneCode = 't'; 
     7525    else if (tuned == 2) 
     7526        tuneCode = 'F'; 
     7527    else if (tuned == 3) 
     7528        tuneCode = 'T'; 
     7529    else 
     7530        tuneCode = '_'; 
     7531 
     7532    sigDesc = sigDesc + QString(" | (%1%2%3%4%5%6%7%8%9) %10") 
     7533              .arg(tuneCode).arg(slock).arg(pat).arg(pmt).arg(mgt).arg(vct) 
     7534              .arg(nit).arg(sdt).arg(crypt).arg(sigMsg); 
    75227535 
    75237536    if (!err.isEmpty()) 
    75247537        sigDesc = err; 
  • libs/libmythtv/tv_rec.cpp

    old new ProgramInfo *TVRec::GetRecording(void) 
    367367void TVRec::RecordPending(const ProgramInfo *rcinfo, int secsleft, 
    368368                          bool hasLater) 
    369369{ 
    370     QMutexLocker lock(&stateChangeLock); 
     370    QMutexLocker statelock(&stateChangeLock); 
     371    QMutexLocker pendlock(&pendingRecLock); 
    371372 
    372373    if (secsleft < 0) 
    373374    { 
    void TVRec::RecordPending(const ProgramI 
    405406 
    406407    pendingRecordings[rcinfo->cardid].possibleConflicts = cardids; 
    407408 
    408     stateChangeLock.unlock(); 
     409    pendlock.unlock(); 
     410    statelock.unlock(); 
    409411    for (uint i = 0; i < cardids.size(); i++) 
    410412        RemoteRecordPending(cardids[i], rcinfo, secsleft, hasLater); 
    411     stateChangeLock.lock(); 
     413    statelock.relock(); 
     414    pendlock.relock(); 
    412415} 
    413416 
    414417/** \fn TVRec::SetPseudoLiveTVRecording(ProgramInfo*) 
    QDateTime TVRec::GetRecordEndTime(const  
    440443 */ 
    441444void TVRec::CancelNextRecording(bool cancel) 
    442445{ 
     446    QMutexLocker pendlock(&pendingRecLock); 
    443447    VERBOSE(VB_RECORD, LOC + "CancelNextRecording("<<cancel<<") -- begin"); 
    444448 
    445449    PendingMap::iterator it = pendingRecordings.find(cardid); 
    RecStatusType TVRec::StartRecording(cons 
    522526        return retval; 
    523527    } 
    524528 
    525     PendingMap::iterator it = pendingRecordings.find(cardid); 
    526529    bool cancelNext = false; 
    527     if (it != pendingRecordings.end()) 
     530    PendingInfo pendinfo; 
     531    PendingMap::iterator it; 
     532    bool has_pending; 
     533 
     534    pendingRecLock.lock(); 
     535    if ((it = pendingRecordings.find(cardid)) != pendingRecordings.end()) 
    528536    { 
    529537        (*it).ask = (*it).doNotAsk = false; 
    530538        cancelNext = (*it).canceled; 
    531539    } 
     540    pendingRecLock.unlock(); 
    532541 
    533542    // Flush out events... 
    534543    WaitForEventThreadSleep(); 
    RecStatusType TVRec::StartRecording(cons 
    536545    // Rescan pending recordings since the event loop may have deleted 
    537546    // a stale entry.  If this happens the info pointer will not be valid 
    538547    // since the HandlePendingRecordings loop will have deleted it. 
     548    pendingRecLock.lock(); 
    539549    it = pendingRecordings.find(cardid); 
     550    has_pending = (it != pendingRecordings.end()); 
     551    if (has_pending) 
     552        pendinfo = *it; 
     553    pendingRecLock.unlock(); 
    540554 
    541555    // If the needed input is in a shared input group, and we are 
    542556    // not canceling the recording anyway, check other recorders 
    543     if (!cancelNext && 
    544         (it != pendingRecordings.end()) && (*it).possibleConflicts.size()) 
     557    if (!cancelNext && has_pending && pendinfo.possibleConflicts.size()) 
    545558    { 
    546559        VERBOSE(VB_RECORD, LOC + "Checking input group recorders - begin"); 
    547         vector<uint> &cardids = (*it).possibleConflicts; 
     560        vector<uint> &cardids = pendinfo.possibleConflicts; 
    548561 
    549562        uint mplexid = 0, sourceid = 0; 
    550563        vector<uint> cardids2; 
    RecStatusType TVRec::StartRecording(cons 
    567580 
    568581            if (is_busy && !sourceid) 
    569582            { 
    570                 mplexid  = (*it).info->GetMplexID(); 
    571                 sourceid = (*it).info->sourceid; 
     583                mplexid  = pendinfo.info->GetMplexID(); 
     584                sourceid = pendinfo.info->sourceid; 
    572585            } 
    573586 
    574587            if (is_busy && 
    void TVRec::HandleStateChange(void) 
    955968void TVRec::ChangeState(TVState nextState) 
    956969{ 
    957970    QMutexLocker lock(&stateChangeLock); 
    958  
    959971    desiredNextState = nextState; 
    960972    changeState = true; 
    961973    WakeEventLoop(); 
    void TVRec::RunTV(void) 
    14281440            QDateTime now   = QDateTime::currentDateTime(); 
    14291441            bool has_finish = HasFlags(kFlagFinishRecording); 
    14301442            bool has_rec    = pseudoLiveTVRecording; 
     1443            bool enable_ui  = true; 
     1444 
     1445            pendingRecLock.lock(); 
    14311446            bool rec_soon   = 
    14321447                pendingRecordings.find(cardid) != pendingRecordings.end(); 
    1433             bool enable_ui  = true; 
     1448            pendingRecLock.unlock(); 
    14341449 
    14351450            if (has_rec && (has_finish || (now > recordEndTime))) 
    14361451            { 
    bool TVRec::WaitForEventThreadSleep(bool 
    16011616 
    16021617void TVRec::HandlePendingRecordings(void) 
    16031618{ 
     1619    QMutexLocker pendlock(&pendingRecLock); 
     1620 
    16041621    if (pendingRecordings.empty()) 
    16051622        return; 
    16061623 
    bool ApplyCachedPids(DTVSignalMonitor *d 
    18891906 *   This method also grabs the ATSCStreamData() from the recorder 
    18901907 *   if possible, or creates one if needed. 
    18911908 */ 
    1892 bool TVRec::SetupDTVSignalMonitor(void) 
     1909bool TVRec::SetupDTVSignalMonitor(bool EITscan) 
    18931910{ 
    18941911    VERBOSE(VB_RECORD, LOC + "Setting up table monitoring."); 
    18951912 
    bool TVRec::SetupDTVSignalMonitor(void) 
    20232040                     SignalMonitor::kDVBSigMon_WaitForPos); 
    20242041        sm->SetRotorTarget(1.0f); 
    20252042 
     2043        if (EITscan) 
     2044        { 
     2045            sm->GetStreamData()->SetVideoStreamsRequired(0); 
     2046            sm->IgnoreEncrypted(true); 
     2047        } 
     2048 
    20262049        VERBOSE(VB_RECORD, LOC + "Successfully set up MPEG table monitoring."); 
    20272050        return true; 
    20282051    } 
    bool TVRec::SetupDTVSignalMonitor(void) 
    20442067 *  \param notify   If set we notify the frontend of the signal values 
    20452068 *  \return true on success, false on failure 
    20462069 */ 
    2047 bool TVRec::SetupSignalMonitor(bool tablemon, bool notify) 
     2070bool TVRec::SetupSignalMonitor(bool tablemon, bool EITscan, bool notify) 
    20482071{ 
    20492072    VERBOSE(VB_RECORD, LOC + "SetupSignalMonitor(" 
    20502073            <<tablemon<<", "<<notify<<")"); 
    bool TVRec::SetupSignalMonitor(bool tabl 
    20602083    // make sure statics are initialized 
    20612084    SignalMonitorValue::Init(); 
    20622085 
    2063     if (SignalMonitor::IsSupported(genOpt.cardtype) && channel->Open()) 
    2064         signalMonitor = SignalMonitor::Init(genOpt.cardtype, cardid, channel); 
     2086    if (channel->Open()) 
     2087        signalMonitor = SignalMonitor::Init(genOpt.cardtype, cardid, 
     2088                                            channel); 
    20652089 
    20662090    if (signalMonitor) 
    20672091    { 
    20682092        VERBOSE(VB_RECORD, LOC + "Signal monitor successfully created"); 
    2069         // If this is a monitor for Digital TV, initialize table monitors 
    2070         if (GetDTVSignalMonitor() && tablemon && !SetupDTVSignalMonitor()) 
    2071         { 
    2072             VERBOSE(VB_IMPORTANT, LOC_ERR + 
    2073                     "Failed to setup digital signal monitoring"); 
    2074  
    2075             return false; 
    2076         } 
    20772093 
     2094        signalMonitor->SetMonitoring(this, EITscan, 
     2095                                     GetDTVSignalMonitor() && tablemon); 
    20782096        signalMonitor->AddListener(this); 
    20792097        signalMonitor->SetUpdateRate(kSignalMonitoringRate); 
    20802098        signalMonitor->SetNotifyFrontend(notify); 
    20812099 
    20822100        // Start the monitoring thread 
    2083         signalMonitor->Start(); 
     2101        signalMonitor->Start(true); 
    20842102    } 
    20852103 
    20862104    return true; 
    bool TVRec::IsReallyRecording(void) 
    24852503 */ 
    24862504bool TVRec::IsBusy(TunedInputInfo *busy_input, int time_buffer) const 
    24872505{ 
    2488     QMutexLocker lock(&stateChangeLock); 
    2489  
    24902506    TunedInputInfo dummy; 
    24912507    if (!busy_input) 
    24922508        busy_input = &dummy; 
    bool TVRec::IsBusy(TunedInputInfo *busy_ 
    25082524        chanid              = channel->GetChanID(); 
    25092525    } 
    25102526 
    2511     PendingMap::const_iterator it = pendingRecordings.find(cardid); 
    2512     if (!busy_input->inputid && (it != pendingRecordings.end())) 
     2527    PendingInfo pendinfo; 
     2528    bool        has_pending; 
     2529    { 
     2530        pendingRecLock.lock(); 
     2531        PendingMap::const_iterator it = pendingRecordings.find(cardid); 
     2532        has_pending = (it != pendingRecordings.end()); 
     2533        if (has_pending) 
     2534            pendinfo = *it; 
     2535        pendingRecLock.unlock(); 
     2536    } 
     2537 
     2538    if (!busy_input->inputid && has_pending) 
    25132539    { 
    25142540        int timeLeft = QDateTime::currentDateTime() 
    2515             .secsTo((*it).recordingStart); 
     2541            .secsTo(pendinfo.recordingStart); 
    25162542 
    25172543        if (timeLeft <= time_buffer) 
    25182544        { 
    25192545            QString channum = QString::null, input = QString::null; 
    2520             if ((*it).info->GetChannel(channum, input)) 
     2546            if (pendinfo.info->GetChannel(channum, input)) 
    25212547            { 
    25222548                busy_input->inputid = channel->GetInputByName(input); 
    2523                 chanid = (*it).info->chanid.toUInt(); 
     2549                chanid = pendinfo.info->chanid.toUInt(); 
    25242550            } 
    25252551        } 
    25262552    } 
    void TVRec::TuningShutdowns(const Tuning 
    36783704void TVRec::TuningFrequency(const TuningRequest &request) 
    36793705{ 
    36803706    DTVChannel *dtvchan = GetDTVChannel(); 
     3707 
     3708    bool livetv = request.flags & kFlagLiveTV; 
     3709    bool antadj = request.flags & kFlagAntennaAdjust; 
     3710    bool has_dummy = false; 
     3711 
    36813712    if (dtvchan) 
    36823713    { 
    36833714        MPEGStreamData *mpeg = NULL; 
    void TVRec::TuningFrequency(const Tuning 
    36943725 
    36953726        if (request.minorChan && (tuningmode == "atsc")) 
    36963727        { 
    3697             channel->SetChannelByString(request.channel); 
    3698  
     3728            channel->SelectChannel(request.channel); 
    36993729            ATSCStreamData *atsc = dynamic_cast<ATSCStreamData*>(mpeg); 
    37003730            if (atsc) 
    37013731                atsc->SetDesiredChannel(request.majorChan, request.minorChan); 
    37023732        } 
    37033733        else if (request.progNum >= 0) 
    37043734        { 
    3705             channel->SetChannelByString(request.channel); 
    3706  
     3735            channel->SelectChannel(request.channel); 
    37073736            if (mpeg) 
    37083737                mpeg->SetDesiredProgram(request.progNum); 
    37093738        } 
    void TVRec::TuningFrequency(const Tuning 
    37323761    if (channel && !channum.isEmpty()) 
    37333762    { 
    37343763        if (!input.isEmpty()) 
    3735             ok = channel->SwitchToInput(input, channum); 
     3764            ok = channel->SelectInput(input, channum, true); 
    37363765        else 
    3737             ok = channel->SetChannelByString(channum); 
     3766        { 
     3767            channel->SelectChannel(channum); 
     3768            ok = true; 
     3769        } 
    37383770    } 
    37393771 
    37403772    if (!ok) 
    void TVRec::TuningFrequency(const Tuning 
    37613793        } 
    37623794    } 
    37633795 
    3764     bool livetv = request.flags & kFlagLiveTV; 
    3765     bool antadj = request.flags & kFlagAntennaAdjust; 
    3766     bool use_sm = SignalMonitor::IsRequired(genOpt.cardtype); 
    3767     bool use_dr = use_sm && (livetv || antadj); 
    3768     bool has_dummy = false; 
    3769  
    3770     if (use_dr) 
     3796    if (livetv || antadj) 
    37713797    { 
    37723798        // We need there to be a ringbuffer for these modes 
    37733799        bool ok; 
    void TVRec::TuningFrequency(const Tuning 
    37933819        has_dummy = true; 
    37943820    } 
    37953821 
    3796     // Start signal monitoring for devices capable of monitoring 
    3797     if (use_sm) 
     3822    // Start signal (or channel change) monitoring 
     3823    VERBOSE(VB_RECORD, LOC + "Starting Signal Monitor"); 
     3824    bool error = false; 
     3825    if (!SetupSignalMonitor(!antadj, request.flags & kFlagEITScan, 
     3826                            livetv | antadj)) 
    37983827    { 
    3799         VERBOSE(VB_RECORD, LOC + "Starting Signal Monitor"); 
    3800         bool error = false; 
    3801         if (!SetupSignalMonitor(!antadj, livetv | antadj)) 
    3802         { 
    3803             VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to setup signal monitor"); 
    3804             if (signalMonitor) 
    3805             { 
    3806                 delete signalMonitor; 
    3807                 signalMonitor = NULL; 
    3808             } 
    3809  
    3810             // pretend the signal monitor is running to prevent segfault 
    3811             SetFlags(kFlagSignalMonitorRunning); 
    3812             ClearFlags(kFlagWaitingForSignal); 
    3813             error = true; 
    3814         } 
    3815  
     3828        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to setup signal monitor"); 
    38163829        if (signalMonitor) 
    38173830        { 
    3818             if (request.flags & kFlagEITScan) 
    3819             { 
    3820                 GetDTVSignalMonitor()->GetStreamData()-> 
    3821                     SetVideoStreamsRequired(0); 
    3822                 GetDTVSignalMonitor()->IgnoreEncrypted(true); 
    3823             } 
    3824  
    3825             SetFlags(kFlagSignalMonitorRunning); 
    3826             ClearFlags(kFlagWaitingForSignal); 
    3827             if (!antadj) 
    3828                 SetFlags(kFlagWaitingForSignal); 
     3831            delete signalMonitor; 
     3832            signalMonitor = NULL; 
    38293833        } 
    38303834 
    3831         if (has_dummy && ringBuffer) 
    3832         { 
    3833             // Make sure recorder doesn't point to bogus ringbuffer before 
    3834             // it is potentially restarted without a new ringbuffer, if 
    3835             // the next channel won't tune and the user exits LiveTV. 
    3836             if (recorder) 
    3837                 recorder->SetRingBuffer(NULL); 
     3835        // pretend the signal monitor is running to prevent segfault 
     3836        SetFlags(kFlagSignalMonitorRunning); 
     3837        ClearFlags(kFlagWaitingForSignal); 
     3838        error = true; 
     3839    } 
    38383840 
    3839             SetFlags(kFlagDummyRecorderRunning); 
    3840             VERBOSE(VB_RECORD, "DummyDTVRecorder -- started"); 
    3841             SetFlags(kFlagRingBufferReady); 
    3842         } 
     3841    if (signalMonitor) 
     3842    { 
     3843        SetFlags(kFlagSignalMonitorRunning); 
     3844        ClearFlags(kFlagWaitingForSignal); 
     3845        if (!antadj) 
     3846            SetFlags(kFlagWaitingForSignal); 
     3847    } 
    38433848 
    3844         // if we had problems starting the signal monitor, 
    3845         // we don't want to start the recorder... 
    3846         if (error) 
    3847             return; 
     3849    if (has_dummy && ringBuffer) 
     3850    { 
     3851        // Make sure recorder doesn't point to bogus ringbuffer before 
     3852        // it is potentially restarted without a new ringbuffer, if 
     3853        // the next channel won't tune and the user exits LiveTV. 
     3854        if (recorder) 
     3855            recorder->SetRingBuffer(NULL); 
     3856 
     3857        SetFlags(kFlagDummyRecorderRunning); 
     3858        VERBOSE(VB_RECORD, "DummyDTVRecorder -- started"); 
     3859        SetFlags(kFlagRingBufferReady); 
    38483860    } 
    38493861 
     3862    // if we had problems starting the signal monitor, 
     3863    // we don't want to start the recorder... 
     3864    if (error) 
     3865        return; 
     3866 
    38503867    // Request a recorder, if the command is a recording command 
    38513868    ClearFlags(kFlagNeedToStartRecorder); 
    38523869    if (request.flags & kFlagRec && !antadj) 
  • libs/libmythtv/tv_rec.h

    old new typedef QMap<uint,PendingInfo> PendingMa 
    150150class MPUBLIC TVRec : public SignalMonitorListener 
    151151{ 
    152152    friend class TuningRequest; 
     153    friend class SignalMonitor; 
    153154 
    154155  public: 
    155156    TVRec(int capturecardnum); 
    class MPUBLIC TVRec : public SignalMonit 
    244245    static TVRec *GetTVRec(uint cardid); 
    245246 
    246247    virtual void AllGood(void) { WakeEventLoop(); } 
     248    virtual void StatusChannelTuned(const SignalMonitorValue&) { } 
    247249    virtual void StatusSignalLock(const SignalMonitorValue&) { } 
    248250    virtual void StatusSignalStrength(const SignalMonitorValue&) { } 
    249251 
    class MPUBLIC TVRec : public SignalMonit 
    252254    bool WaitForEventThreadSleep(bool wake = true, ulong time = ULONG_MAX); 
    253255    static void *EventThread(void *param); 
    254256    static void *RecorderThread(void *param); 
     257    bool SetupDTVSignalMonitor(bool EITscan); 
    255258 
    256259  private: 
    257260    void SetRingBuffer(RingBuffer *); 
    class MPUBLIC TVRec : public SignalMonit 
    281284    FirewireChannel *GetFirewireChannel(void); 
    282285    V4LChannel   *GetV4LChannel(void); 
    283286 
    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); 
    286289    void TeardownSignalMonitor(void); 
    287290    DTVSignalMonitor *GetDTVSignalMonitor(void); 
    288291 
    class MPUBLIC TVRec : public SignalMonit 
    360363 
    361364    // State variables 
    362365    mutable QMutex stateChangeLock; 
     366    mutable QMutex pendingRecLock; 
    363367    TVState        internalState; 
    364368    TVState        desiredNextState; 
    365369    bool           changeState; 
  • libs/libmythtv/v4lchannel.h

    old new class V4LChannel : public DTVChannel 
    4949    QString GetSIStandard(void) const { return "atsc"; } 
    5050 
    5151    // Commands 
    52     bool SwitchToInput(int newcapchannel, bool setstarting); 
    5352    bool Retune(void); 
    5453 
    5554    // Picture attributes. 
    class V4LChannel : public DTVChannel 
    6968    bool Tune(uint frequency, QString inputname, 
    7069              QString modulation, QString si_std); 
    7170 
     71  protected: 
     72    bool SwitchToInput(int newcapchannel, bool setstarting); 
     73 
    7274  private: 
    7375    // Helper Sets 
    7476    void SetFreqTable(const int index); 
  • libs/libmythtv/dvbchannel.cpp

    old new bool DVBChannel::SetChannelByString(cons 
    394394    return true; 
    395395} 
    396396 
    397 bool DVBChannel::SwitchToInput(const QString &inputname, const QString &chan) 
     397bool DVBChannel::SelectInput(const QString &inputname, const QString &chan, 
     398                             bool use_sm) 
    398399{ 
    399400    int input = GetInputByName(inputname); 
    400401 
    401     bool ok = false; 
    402402    if (input >= 0) 
    403403    { 
    404404        nextInputID = input; 
    405         ok = SetChannelByString(chan); 
     405        if (use_sm) 
     406            SelectChannel(chan); 
     407        else 
     408            return SetChannelByString(chan); 
    406409    } 
    407410    else 
    408411    { 
    409412        VERBOSE(VB_IMPORTANT, 
    410413                QString("DVBChannel: Could not find input: %1 on card when " 
    411414                        "setting channel %2\n").arg(inputname).arg(chan)); 
     415        return false; 
    412416    } 
    413     return ok; 
     417    return true; 
    414418} 
    415419 
    416420bool DVBChannel::SwitchToInput(int newInputNum, bool setstarting) 
  • libs/libmythtv/dvbchannel.h

    old new class DVBChannel : public DTVChannel 
    7878    double GetUncorrectedBlockCount(bool *ok = NULL) const; 
    7979 
    8080    // Commands 
     81#if 0 
    8182    bool SwitchToInput(const QString &inputname, const QString &chan); 
     83#else 
     84    bool SelectInput(const QString &inputname, const QString &chan, 
     85                     bool use_sm); 
     86#endif 
    8287    bool SwitchToInput(int newcapchannel, bool setstarting); 
    8388    bool SetChannelByString(const QString &chan); 
    8489    bool Tune(const DTVMultiplex &tuning, QString inputname); 
  • libs/libmythtv/v4lchannel.cpp

    old new bool V4LChannel::SetChannelByString(cons 
    441441    // change inputs and return, since the act of changing 
    442442    // inputs will change the channel as well. 
    443443    if (!inputName.isEmpty()) 
    444         return ChannelBase::SwitchToInput(inputName, channum); 
     444        return ChannelBase::SelectInput(inputName, channum, false); 
    445445 
    446446    ClearDTVInfo(); 
    447447