Ticket #190: autoexpire-do-not-expire-playing.patch

File autoexpire-do-not-expire-playing.patch, 10.1 KB (added by danielk, 14 years ago)

partial fix

  • libs/libmythtv/remoteutil.h

     
    2525bool RemoteGetUptime(time_t &uptime);
    2626bool RemoteGetMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM);
    2727bool RemoteCheckFile(ProgramInfo *pginfo);
     28bool RemoteIsPlaying(const ProgramInfo *pginfo);
    2829void RemoteStopRecording(ProgramInfo *pginfo);
    2930bool RemoteDeleteRecording(ProgramInfo *pginfo, bool forgetHistory,
    3031                           bool forceMetadataDelete = false);
  • libs/libmythtv/remoteutil.cpp

     
    130130    return strlist[0].toInt();
    131131}
    132132
     133bool RemoteIsPlaying(const ProgramInfo *pginfo)
     134{
     135    QStringList strlist = "QUERY_IS_PLAYING";
     136    pginfo->ToStringList(strlist);
     137
     138    if (!gContext->SendReceiveStringList(strlist))
     139        return false;
     140
     141    return strlist[0].toInt();   
     142}
     143
    133144void RemoteStopRecording(ProgramInfo *pginfo)
    134145{
    135146    QStringList strlist = QString("STOP_RECORDING");
  • libs/libmythtv/tv_rec.cpp

     
    289289    return internalState;
    290290}
    291291
     292/** \fn TVRec::IsPlaying(const ProgramInfo*)
     293 *  \brief Returns true iff we are playing the program indicated.
     294 *  \param pginfo Program we want to compare to curRecording
     295 */
     296bool TVRec::IsPlaying(const ProgramInfo *pginfo)
     297{
     298    QMutexLocker lock(&stateChangeLock);
     299    if (curRecording && pginfo && StateIsPlaying(GetState()))
     300        return (curRecording->IsSameProgram(*pginfo));
     301    return false;
     302}
     303
    292304/** \fn TVRec::GetRecording(void)
    293305 *  \brief Allocates and returns a ProgramInfo for the current recording.
    294306 *
  • libs/libmythtv/tv_rec.h

     
    6767
    6868    bool Init(void);
    6969
     70    bool IsPlaying(const ProgramInfo *pginfo);
    7071    void RecordPending(const ProgramInfo *rcinfo, int secsleft);
    7172    int StartRecording(const ProgramInfo *rcinfo);
    7273
  • programs/mythbackend/encoderlink.h

     
    5252
    5353    TVState GetState();
    5454    bool IsRecording(const ProgramInfo *rec); // scheduler call only.
     55    bool IsPlaying(const ProgramInfo *rec);
    5556
    5657    bool HasEnoughFreeSpace(const ProgramInfo *rec,
    5758                            bool try_to_use_cache = false);
  • programs/mythbackend/playbacksock.cpp

     
    228228    return ret;
    229229}
    230230
     231/** \fn PlaybackSock::IsPlaying(int, const ProgramInfo*)
     232 *  \brief Returns whether the particular program in pginfo is currently.
     233 *         being viewed.
     234 *  \param capturecardnum Recorder ID in the database.
     235 */
     236bool PlaybackSock::IsPlaying(int capturecardnum, const ProgramInfo *pginfo)
     237{
     238    QStringList strlist = QString("QUERY_REMOTEENCODER %1").arg(capturecardnum);
     239    strlist << "IS_PLAYING";
     240    pginfo->ToStringList(strlist);
     241
     242    SendReceiveStringList(strlist);
     243
     244    bool ret = strlist[0].toInt();
     245    return ret;
     246}
     247
     248
    231249int PlaybackSock::StartRecording(int capturecardnum, const ProgramInfo *pginfo)
    232250{
    233251    QStringList strlist = QString("QUERY_REMOTEENCODER %1").arg(capturecardnum);
  • programs/mythbackend/mainserver.cpp

     
    309309    {
    310310        HandleQueryCheckFile(listline, pbs);
    311311    }
     312    else if (command == "QUERY_IS_PLAYING")
     313    {
     314        HandleQueryIsPlaying(listline, pbs);
     315    }
    312316    else if (command == "QUERY_GUIDEDATATHROUGH")
    313317    {
    314318        HandleQueryGuideDataThrough(pbs);
     
    19041908    delete pginfo;
    19051909}
    19061910
     1911void MainServer::HandleQueryIsPlaying(QStringList &slist, PlaybackSock *pbs)
     1912{
     1913    QSocket *pbssock = pbs->getSocket();
     1914
     1915    ProgramInfo *pginfo = new ProgramInfo();
     1916    pginfo->FromStringList(slist, 1);
     1917
     1918    int playing = 0;
     1919
     1920    if (!ismaster)
     1921        VERBOSE(VB_IMPORTANT, "HandleQueryIsPlaying called on non-master...");
     1922
     1923    // check each recorder to see if they are playing the stream.
     1924    QMap<int, EncoderLink *>::Iterator iter = encoderList->begin();
     1925    for (; iter != encoderList->end() && !playing; ++iter)
     1926        playing |= (iter.data())->IsPlaying(pginfo);
     1927
     1928    QStringList strlist = QString::number(playing);
     1929    SendResponse(pbssock, strlist);
     1930
     1931    delete pginfo;
     1932}
     1933
    19071934void MainServer::getGuideDataThrough(QDateTime &GuideDataThrough)
    19081935{
    19091936    MSqlQuery query(MSqlQuery::InitCon());
     
    27152742
    27162743        delete pginfo;
    27172744    }
     2745    else if (command == "IS_PLAYING")
     2746    {
     2747        ProgramInfo *pginfo = new ProgramInfo();
     2748        pginfo->FromStringList(slist, 2);
     2749
     2750        retlist << QString::number((int)enc->IsPlaying(pginfo));
     2751
     2752        delete pginfo;
     2753    }
    27182754    else if (command == "START_RECORDING")
    27192755    {
    27202756        ProgramInfo *pginfo = new ProgramInfo();
  • programs/mythbackend/playbacksock.h

     
    5353    int GetEncoderState(int capturecardnum);
    5454    long long GetMaxBitrate(int capturecardnum);
    5555    bool EncoderIsRecording(int capturecardnum, const ProgramInfo *pginfo);
     56    bool IsPlaying(int capturecardnum, const ProgramInfo *pginfo);
    5657    int StartRecording(int capturecardnum, const ProgramInfo *pginfo);
    5758    void RecordPending(int capturecardnum, const ProgramInfo *pginfo, int secsleft);
    5859    int SetSignalMonitoringRate(int capturecardnum, int rate, int notifyFrontend);
  • programs/mythbackend/mainserver.h

     
    8383    void HandleRescheduleRecordings(int recordid, PlaybackSock *pbs);
    8484    void HandleQueryFreeSpace(PlaybackSock *pbs, bool allBackends);
    8585    void HandleQueryCheckFile(QStringList &slist, PlaybackSock *pbs);
     86    void HandleQueryIsPlaying(QStringList &slist, PlaybackSock *pbs);
    8687    void HandleQueryGuideDataThrough(PlaybackSock *pbs);
    8788    void HandleGetPendingRecordings(PlaybackSock *pbs);
    8889    void HandleGetScheduledRecordings(PlaybackSock *pbs);
  • programs/mythbackend/autoexpire.cpp

     
    278278 *
    279279 *   CheckFile makes sure the file exists and is stored on the same file
    280280 *   system as the recordfileprefix.
     281 *
    281282 *  \param pginfo           ProgramInfo for the program we wish to delete.
    282283 *  \param recordfileprefix Path where new recordings are stored.
    283284 *  \param fsid             Unique ID of recordfileprefix's filesystem.
     
    322323        VERBOSE(VB_FILE, msg);
    323324        return false;
    324325    }
     326
     327    // query recorders to see if the file is currently being played
     328    if (RemoteIsPlaying(pginfo))
     329    {
     330        VERBOSE(VB_FILE, QString("File '%1' is currently being played. "
     331                                 "Not autoexpiring").arg(filename));
     332        return false;
     333    }
     334
    325335    return true;
    326336}
    327337
  • programs/mythbackend/encoderlink.cpp

     
    1 // C++ headers
    2 #include <iostream>
    3 using namespace std;
    4 
    51// C headers
    62#include <unistd.h>
    73
     
    137133    else if (sock)
    138134        retval = (TVState)sock->GetEncoderState(m_capturecardnum);
    139135    else
    140         cerr << "Broken for card: " << m_capturecardnum << endl;
     136        VERBOSE(VB_IMPORTANT,
     137                QString("EncoderLink::GetState() failed for recorder %1")
     138                .arg(m_capturecardnum));
    141139
    142140    return retval;
    143141}
     
    145143/** \fn EncoderLink::IsRecording(const ProgramInfo *rec)
    146144 *  \brief Returns true if rec is scheduled for recording.
    147145 *  \param rec Recording to check.
    148  *  \sa MatchesRecording(const ProgramInfo*)
     146 *  \sa MatchesRecording(const ProgramInfo*), IsPlaying(const ProgramInfo *)
    149147 */
    150148bool EncoderLink::IsRecording(const ProgramInfo *rec)
    151149{
     
    157155    return retval;
    158156}
    159157
     158/** \fn EncoderLink::IsPlaying(const ProgramInfo *)
     159 *  \brief Returns true iff recording is currently being played.
     160 *  \param rec Recording to check.
     161 *  \sa IsRecording(const ProgramInfo*), MatchesRecording(const ProgramInfo*)
     162 */
     163bool EncoderLink::IsPlaying(const ProgramInfo *rec)
     164{
     165    bool retval = false;
     166
     167    if (local)
     168        retval = tv->IsPlaying(rec);
     169    else if (sock)
     170        retval = sock->IsPlaying(m_capturecardnum, rec);
     171    else
     172        VERBOSE(VB_IMPORTANT,
     173                QString("EncoderLink::IsPlaying() failed for recorder %1")
     174                .arg(m_capturecardnum));
     175
     176    return retval;
     177}
     178
    160179/** \fn EncoderLink::MatchesRecording(const ProgramInfo *rec)
    161180 *  \brief Returns true if rec is actually being recorded by TVRec.
    162181 * 
     
    190209            delete tvrec;
    191210        }
    192211    }
     212    else if (sock)
     213        retval = sock->EncoderIsRecording(m_capturecardnum, rec);
    193214    else
    194     {
    195         if (sock)
    196             retval = sock->EncoderIsRecording(m_capturecardnum, rec);
    197     }
     215        VERBOSE(VB_IMPORTANT, QString("EncoderLink::MatchesRecording() "
     216                    "failed for recorder %1").arg(m_capturecardnum));
    198217
    199218    return retval;
    200219}