Ticket #820: dvbswitchto.patch

File dvbswitchto.patch, 5.2 KB (added by nooneimprt4nt@…, 20 years ago)
  • libs/libmythtv/dvbchannel.h

     
    6363
    6464    // Commands
    6565    bool SwitchToInput(const QString &inputname, const QString &chan);
    66     bool SwitchToInput(int newcapchannel, bool setstarting)
    67         { (void)newcapchannel; (void)setstarting; return false; }
     66    bool SwitchToInput(int newcapchannel, bool setstarting);
    6867    bool Tune(const dvb_channel_t& channel, bool force_reset=false);
    6968
    7069    // Set/Get/Command just for SIScan/ScanWizardScanner
     
    113112    int               currentTID;  ///< Stores mplexid from database
    114113
    115114    bool              first_tune;  ///< Used to force hardware reset
     115
     116    int               nextcapchannel; ///< Signal an input change
    116117};
    117118
    118119#endif
  • libs/libmythtv/dvbchannel.cpp

     
    132132{
    133133    channelnames.clear();
    134134    inputChannel.clear();
     135    inputTuneTo.clear();
    135136   
    136137    MSqlQuery query(MSqlQuery::InitCon());
    137138    query.prepare(
    138139        "SELECT cardinputid, inputname, "
     140        "       if (tunechan='', 'Undefined', tunechan), "
    139141        "       if (startchan, startchan, '') "
    140142        "FROM cardinput "
    141143        "WHERE cardid = :CARDID");
     
    159161    {
    160162        int inputNum              = query.value(0).toInt();
    161163        channelnames[inputNum]    = query.value(1).toString();
    162         inputChannel[inputNum]    = query.value(2).toString();
     164        inputTuneTo[inputNum]     = query.value(2).toString();
     165        inputChannel[inputNum]    = query.value(3).toString();
    163166    }
    164167
    165168    // print em
     
    170173                .arg(it.key()).arg(*it)
    171174                .arg(inputChannel[it.key()]));
    172175    }
     176    currentcapchannel = nextcapchannel = -1;
    173177}
    174178
    175179bool DVBChannel::Open()
     
    284288    CHANNEL(QString("Tuned to frequency for channel %1.").arg(chan));
    285289
    286290    currentcapchannel = chan_opts.input_id;
     291    nextcapchannel = currentcapchannel;
    287292    inputChannel[currentcapchannel] = curchannelname;
    288293
    289294    return true;
     
    300305
    301306bool DVBChannel::SwitchToInput(const QString &input, const QString &chan)
    302307{
    303     (void)input;
    304     // TODO We should be switching the input even if chan exists on
    305     // the current input, currently this will only work correctly if
    306     // channum's are unique across inputs. -- dtk  Dec 15, 2005
     308    if (input != channelnames[currentcapchannel])
     309    {
     310        nextcapchannel = GetInputByName(input);
     311        if (nextcapchannel == -1)
     312        {
     313            VERBOSE(VB_IMPORTANT, QString("Failed to locate input %1").
     314                    arg(input));
     315            nextcapchannel = currentcapchannel;
     316        }
     317    }
    307318    return SetChannelByString(chan);
    308319}
    309 
     320bool DVBChannel::SwitchToInput(int newcapchannel, bool setstarting)
     321{
     322    (void)setstarting;
     323    if(inputChannel[newcapchannel] != "")
     324     {
     325        nextcapchannel = newcapchannel;
     326        return SetChannelByString(inputChannel[newcapchannel]);
     327    }
     328    return false;
     329}
    310330/** \fn DVBChannel::GetChannelOptions(const QString&)
    311331 *  \brief This function called when tuning to a specific stream.
    312332 */
     
    317337    int cardid = GetCardID();
    318338
    319339    // Reset Channel data
    320     inputChannel[currentcapchannel] = "";
    321340    currentATSCMajorChannel = currentATSCMinorChannel = -1;
    322341    currentProgramNum = -1;
    323342    chan_opts.serviceID = 0;
    324343
    325344    QString thequery =
    326         QString("SELECT chanid, serviceid, mplexid, atscsrcid "
     345        QString("SELECT chanid, serviceid, mplexid, atscsrcid, cardinputid "
    327346                "FROM channel, cardinput, capturecard "
    328347                "WHERE channel.channum='%1' AND "
    329348                "      cardinput.sourceid = channel.sourceid AND "
     
    340359        return false;
    341360    }
    342361
    343     if (query.next())
     362    bool found = false;
     363    int mplexid;
     364    while (query.next())
    344365    {
    345         // TODO: Fix structs to be more useful to new DB structure
    346         currentProgramNum = chan_opts.serviceID = query.value(1).toInt();
    347         if (query.value(3).toInt() > 256)
     366        int this_inputid = query.value(4).toInt();
     367        if (! found || this_inputid == nextcapchannel)
    348368        {
    349             currentATSCMajorChannel = query.value(3).toInt() >> 8;
    350             currentATSCMinorChannel = query.value(3).toInt() & 0xff;
    351             currentProgramNum = -1;
     369            found = true;
     370            mplexid = query.value(2).toInt();
     371            // TODO: Fix structs to be more useful to new DB structure
     372            currentProgramNum = chan_opts.serviceID = query.value(1).toInt();
     373            if (query.value(3).toInt() > 256)
     374            {
     375                currentATSCMajorChannel = query.value(3).toInt() >> 8;
     376                currentATSCMinorChannel = query.value(3).toInt() & 0xff;
     377                currentProgramNum = -1;
     378            }
     379
    352380        }
    353381    }
    354     else
     382    if (! found)
    355383    {
    356384        ERROR("Unable to find channel in database.");
    357385        return false;
    358386    }
    359387
    360     int mplexid = query.value(2).toInt();
    361 
    362388    if (!GetTransportOptions(mplexid))
    363389        return false;
    364390