[mythtv] Re: [fixed PATCH] Cancel a recording when no free recorder for live tv

Ciaran ciaranj at gmail.com
Fri Jan 14 14:08:26 EST 2005


On Sat, 15 Jan 2005 01:13:17 +0900, Jack Porter <jack at porter.net.au> wrote:
> Sorry!! That patch is missing an "else return 0;" for the case where
> showDialogs is false, possibly causing an infinite loop.
> 
> Please use this one instead.
> 
> Thanks
> Jack
> 
> --
> Jack Porter                       Programmer
> jack at porter.net.au                Softmax
> jack at softmax.co.kr                South Korea
> 
> 
> Index: tv_play.cpp
> ===================================================================
> RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.cpp,v
> retrieving revision 1.233
> diff -u -r1.233 tv_play.cpp
> --- tv_play.cpp 24 Dec 2004 23:24:07 -0000      1.233
> +++ tv_play.cpp 14 Jan 2005 16:06:13 -0000
> @@ -37,6 +37,17 @@
>     float rew_repos;
> };
> 
> +struct CurrentEncRecordingInfo
> +{
> +    RemoteEncoder* enc;
> +    QString chanid;
> +
> +    CurrentEncRecordingInfo(RemoteEncoder* inenc, QString inchanid)
> +    :   enc(inenc)
> +    ,   chanid(inchanid)
> +    {}
> +};
> +
> #define MAX_REPO_LEVEL 3
> SeekSpeedInfo seek_speed_array[MAX_REPO_LEVEL][7] =
> {
> @@ -405,37 +416,106 @@
>     return internalState;
> }
> 
> +
> int TV::LiveTV(bool showDialogs)
> {
>     if (internalState == kState_None)
>     {
> -        RemoteEncoder *testrec = RemoteRequestNextFreeRecorder(lastRecorderNum);
> -
> -        if (!testrec)
> -            return 0;
> -
> -        if (!testrec->IsValidRecorder())
> +        RemoteEncoder* testrec;
> +        for (;;)
>         {
> -            if (showDialogs)
> -            {
> -                QString title = tr("MythTV is already using all available "
> -                                   "inputs for recording.  If you want to "
> -                                   "watch an in-progress recording, select one "
> -                                   "from the playback menu.  If you want to "
> -                                   "watch live TV, cancel one of the "
> -                                   "in-progress recordings from the delete "
> -                                   "menu.");
> -
> -                DialogBox diag(gContext->GetMainWindow(), title);
> -                diag.AddButton(tr("Cancel and go back to the TV menu"));
> -                diag.exec();
> -            }
> +            testrec = RemoteRequestNextFreeRecorder(lastRecorderNum);
> 
> -            delete testrec;
> -
> -            return 0;
> +            if (!testrec)
> +                return 0;
> +
> +            if (!testrec->IsValidRecorder())
> +            {
> +                delete testrec;
> +
> +                if (showDialogs)
> +                {
> +                    QString title = tr("MythTV is already using all available "
> +                                       "inputs for recording.  If you want to "
> +                                       "watch an in-progress recording, select one "
> +                                       "from the playback menu.  If you want to "
> +                                       "watch live TV, cancel one of the "
> +                                       "in-progress recordings from the delete "
> +                                       "menu.");
> +
> +                    DialogBox diag(gContext->GetMainWindow(), title);
> +                    diag.AddButton(tr("Cancel and go back to the TV menu"));
> +
> +                    vector<CurrentEncRecordingInfo> encoderinfos;
> +
> +                    int countRecording = RemoteIsRecording();
> +                    for (int i = 1; i <= countRecording; i++)
> +                    {
> +                        RemoteEncoder* enc = RemoteGetExistingRecorder(i);
> +                        if (enc)
> +                        {
> +                            if (enc->IsValidRecorder())
> +                            {
> +                                enc->Setup();
> +                                QString title, subtitle,
> +                                          desc, category,
> +                                          starttime, endtime,
> +                                          callsign, iconpath,
> +                                          channelname, chanid,
> +                                          seriesid, programid,
> +                                          outputFilters, repeat,
> +                                          airdate, stars;
> +
> +                                enc->GetChannelInfo(title, subtitle,
> +                                                  desc, category,
> +                                                  starttime, endtime,
> +                                                  callsign, iconpath,
> +                                                  channelname, chanid,
> +                                                  seriesid, programid,
> +                                                  outputFilters, repeat,
> +                                                  airdate, stars);
> +                                if (title != "")
> +                                {
> +                                    diag.AddButton(tr("Cancel Recording: ")+title);
> +                                    encoderinfos.push_back(CurrentEncRecordingInfo(enc, chanid));
> +                                }
> +                                else
> +                                    delete enc;
> +                            }
> +                            else
> +                                delete enc;
> +                        }
> +                    }
> +
> +                    int result = diag.exec();
> +                    int c = 2;
> +                    for (vector<CurrentEncRecordingInfo>::iterator i = encoderinfos.begin();
> +                        i != encoderinfos.end();
> +                        ++i)
> +                    {
> +                        RemoteEncoder* enc = (*i).enc;
> +                        if (result == c)
> +                        {
> +                            QDateTime now = QDateTime::currentDateTime();
> +                            ProgramInfo* currentprog = ProgramInfo::GetProgramAtDateTime(QSqlDatabase::database(), (*i).chanid, now);
> +                            cout << "stopping recording " << currentprog->title.local8Bit() << endl;
> +                            RemoteStopRecording(currentprog);
> +                            delete currentprog;
> +                        }
> +                        delete enc;
> +                        c++;
> +                    }
> +
> +                    if (result == 1)    // Cancel and go back to TV menu.
> +                        return 0;
> +                }
> +                else
> +                    return 0;
> +            }
> +            else
> +                break;  // found a valid recorder, fall out of the loop.
>         }
> -
> +
>         activerecorder = recorder = testrec;
>         lastRecorderNum = recorder->GetRecorderNumber();
>         nextState = kState_WatchingLiveTV;
> @@ -4217,4 +4297,3 @@
>         cout << "No sleep timer?";
>     }
> }
> -
> 
> 
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
> 
> 
> 
Good patch,  this exact same thing was bothering me last night! I'll
apply it when I get a chance, thanks :)

-- 
- Ciaran


More information about the mythtv-dev mailing list