Ticket #4472: 4472-v1.patch

File 4472-v1.patch, 7.0 KB (added by danielk, 16 years ago)

fix

  • libs/libmythtv/channel.h

     
    3131    Channel(TVRec *parent, const QString &videodevice);
    3232    virtual ~Channel(void);
    3333
    34     bool Init(QString &inputname, QString &startchannel);
     34    bool Init(QString &inputname, QString &startchannel, bool setchan);
    3535
    3636    bool Open(void);
    3737    void Close(void);
  • libs/libmythtv/channelbase.h

     
    2828    ChannelBase(TVRec *parent);
    2929    virtual ~ChannelBase();
    3030
    31     virtual bool Init(QString &inputname, QString &startchannel);
     31    virtual bool Init(QString &inputname, QString &startchannel, bool setchan);
     32    virtual bool IsTunable(const QString &input, const QString &channum) const;
    3233
    3334    // Methods that must be implemented.
    3435    /// \brief Opens the channel changing hardware for use.
  • libs/libmythtv/channelbase.cpp

     
    4545{
    4646}
    4747
    48 bool ChannelBase::Init(QString &inputname, QString &startchannel)
     48bool ChannelBase::Init(QString &inputname, QString &startchannel, bool setchan)
    4949{
    5050    bool ok;
    5151
    52     if (inputname.isEmpty())
     52    if (!setchan)
     53        ok = IsTunable(inputname, startchannel);
     54    else if (inputname.isEmpty())
    5355        ok = SetChannelByString(startchannel);
    5456    else
    5557        ok = SwitchToInput(inputname, startchannel);
     
    8688
    8789            if (chanid && cit != channels.end())
    8890            {
    89                 ok = SwitchToInput(*it, (*cit).channum);
     91                if (!setchan)
     92                    ok = IsTunable(inputname, startchannel);
     93                else
     94                    ok = SwitchToInput(*it, (*cit).channum);
     95
    9096                if (ok)
    9197                {
    9298                    inputname    = *it;
    9399                    startchannel = QDeepCopy<QString>((*cit).channum);
    94                     msg2 = QString("tuned to '%1' on input '%2' instead.")
     100                    msg2 = QString("selected to '%1' on input '%2' instead.")
    95101                        .arg(startchannel).arg(inputname);
    96102                    msg_error = false;
    97103                }
     
    111117    return ok;
    112118}
    113119
     120bool ChannelBase::IsTunable(const QString &input, const QString &channum) const
     121{
     122    QString loc = LOC + QString("IsTunable(%1,%2)").arg(input).arg(channum);
     123
     124    int inputid = currentInputID;
     125    if (!input.isEmpty())
     126        inputid = GetInputByName(input);
     127
     128    InputMap::const_iterator it = inputs.find(inputid);
     129    if (it == inputs.end())
     130    {
     131        VERBOSE(VB_IMPORTANT, loc + " " + QString(
     132                    "Requested non-existant input '%1':'%2' ")
     133                .arg(input).arg(inputid));
     134
     135        return false;
     136    }
     137
     138    uint mplexid_restriction;
     139    if (!IsInputAvailable(inputid, mplexid_restriction))
     140    {
     141        VERBOSE(VB_IMPORTANT, loc + " " + QString(
     142                    "Requested channel is on input '%1' "
     143                    "which is in a busy input group")
     144                .arg(inputid));
     145
     146        return false;
     147    }
     148
     149    // Fetch tuning data from the database.
     150    QString tvformat, modulation, freqtable, freqid, dtv_si_std;
     151    int finetune;
     152    uint64_t frequency;
     153    int mpeg_prog_num;
     154    uint atsc_major, atsc_minor, mplexid, tsid, netid;
     155    bool commfree;
     156
     157    if (!ChannelUtil::GetChannelData(
     158        (*it)->sourceid, channum,
     159        tvformat, modulation, freqtable, freqid,
     160        finetune, frequency,
     161        dtv_si_std, mpeg_prog_num, atsc_major, atsc_minor, tsid, netid,
     162        mplexid, commfree))
     163    {
     164        VERBOSE(VB_IMPORTANT, loc + " " + QString(
     165                    "Failed to find channel in DB on input '%1' ")
     166                .arg(inputid));
     167
     168        return false;
     169    }
     170
     171    if (mplexid_restriction && (mplexid != mplexid_restriction))
     172    {
     173        VERBOSE(VB_IMPORTANT, loc + " " + QString(
     174                    "Channel is valid, but tuner is busy "
     175                    "on different multiplex (%1 != %2)")
     176                .arg(mplexid).arg(mplexid_restriction));
     177
     178        return false;
     179    }
     180
     181    return true;
     182}
     183
    114184uint ChannelBase::GetNextChannel(uint chanid, int direction) const
    115185{
    116186    if (!chanid)
  • libs/libmythtv/dvbchannel.h

     
    3434    bool Open(void) { return Open(this); }
    3535    void Close(void) { Close(this); }
    3636
    37     bool Init(QString &inputname, QString &startchannel);
     37    bool Init(QString &inputname, QString &startchannel, bool setchan);
    3838
    3939    // Sets
    4040    void SetPMT(const ProgramMapTable*);
  • libs/libmythtv/dvbchannel.cpp

     
    297297    return it != is_open.end();
    298298}
    299299
    300 bool DVBChannel::Init(QString &inputname, QString &startchannel)
     300bool DVBChannel::Init(QString &inputname, QString &startchannel, bool setchan)
    301301{
    302     if (!IsOpen())
     302    if (setchan && !IsOpen())
    303303        Open(this);
    304     return ChannelBase::Init(inputname, startchannel);
     304
     305    return ChannelBase::Init(inputname, startchannel, setchan);
    305306}
    306307
    307308// documented in dtvchannel.h
  • libs/libmythtv/tv_rec.cpp

     
    11751175    QString input   = inputname;
    11761176    QString channum = startchannel;
    11771177
    1178     channel->Init(input, channum);
     1178    channel->Init(input, channum, true);
    11791179}
    11801180
    11811181void TVRec::CloseChannel(void)
     
    33103310        }
    33113311    }
    33123312    if (request.flags & kFlagLiveTV)
    3313         channel->Init(input, channum);
     3313        channel->Init(input, channum, false);
    33143314
    33153315    if (channel && !channum.isEmpty() && (channum.find("NextChannel") >= 0))
    33163316    {
  • libs/libmythtv/channel.cpp

     
    5858    Close();
    5959}
    6060
    61 bool Channel::Init(QString &inputname, QString &startchannel)
     61bool Channel::Init(QString &inputname, QString &startchannel, bool setchan)
    6262{
    63     SetFormat(gContext->GetSetting("TVFormat"));
    64     SetDefaultFreqTable(gContext->GetSetting("FreqTable"));
    65     return ChannelBase::Init(inputname, startchannel);
     63    if (setchan)
     64    {
     65        SetFormat(gContext->GetSetting("TVFormat"));
     66        SetDefaultFreqTable(gContext->GetSetting("FreqTable"));
     67    }
     68    return ChannelBase::Init(inputname, startchannel, setchan);
    6669}
    6770
    6871bool Channel::Open(void)