Ticket #4498: mythtv_chanbase_Init_fixes6.diff

File mythtv_chanbase_Init_fixes6.diff, 3.2 KB (added by Shane Shrybman <gnome42@…>, 12 years ago)

Find good starting channel

  • libs/libmythtv/channelbase.cpp

    
    Updated version v6:
    
    * Make ChannelBase::Init() handle empty inputname better
    * Make a better effort find the requested startchannel,
      even if inputname is empty.
    * Find non-conflicting startchan when mux is busy or not:
      If mux is busy, find a startchan. If mux isn't busy,
      attempt to find input for requested startchan else
      find both an input and startchan.
    
     
    5050    bool ok;
    5151
    5252    if (!setchan)
    53         ok = IsTunable(inputname, startchannel);
     53        ok = inputname.isEmpty() ? false : IsTunable(inputname, startchannel);
    5454    else if (inputname.isEmpty())
    5555        ok = SetChannelByString(startchannel);
    5656    else
     
    7070        find(inputs.begin(), inputs.end(), inputname);
    7171    start = (start == inputs.end()) ?  inputs.begin() : start;
    7272
     73    VERBOSE(VB_IMPORTANT, QString("Looking for startchannel %1 on input %2")
     74            .arg(startchannel).arg(*start));
     75
     76    // Attempt to find an input for the requested startchannel
    7377    QStringList::const_iterator it = start;
     78    while (it != inputs.end())
     79    {
     80        DBChanList channels = GetChannels(*it);
     81
     82        DBChanList::const_iterator cit = channels.begin();
     83        for (; cit != channels.end(); cit++)
     84        {
     85            if ((*cit).channum == startchannel &&
     86                IsTunable(*it, startchannel))
     87            {
     88                inputname = *it;
     89                VERBOSE(VB_IMPORTANT, QString(
     90                    "Found startchannel %1 on input %2")
     91                    .arg(startchannel).arg(inputname));
     92                return true;
     93            }
     94        }
     95
     96        it++;
     97        it = (it == inputs.end()) ? inputs.begin() : it;
     98        if (it == start)
     99            break;
     100    }
     101
     102    it = start;
    74103    while (it != inputs.end() && !ok)
    75104    {
    76105        uint mplexid_restriction = 0;
    77106
    78107        DBChanList channels = GetChannels(*it);
    79         if (IsInputAvailable(GetInputByName(*it), mplexid_restriction) &&
    80             channels.size())
     108        if (channels.size() &&
     109            IsInputAvailable(GetInputByName(*it), mplexid_restriction))
    81110        {
    82111            uint chanid = ChannelUtil::GetNextChannel(
    83112                channels, channels[0].chanid,
     
    89118            if (chanid && cit != channels.end())
    90119            {
    91120                if (!setchan)
    92                     ok = IsTunable(inputname, startchannel);
     121                    ok = IsTunable(*it, (mplexid_restriction) ?
     122                                   (*cit).channum : startchannel);
    93123                else
    94124                    ok = SwitchToInput(*it, (*cit).channum);
    95125
    96126                if (ok)
    97127                {
    98128                    inputname    = *it;
    99                     startchannel = QDeepCopy<QString>((*cit).channum);
     129                    if (mplexid_restriction)
     130                        startchannel = QDeepCopy<QString>((*cit).channum);
    100131                    msg2 = QString("selected to '%1' on input '%2' instead.")
    101132                        .arg(startchannel).arg(inputname);
    102133                    msg_error = false;