Ticket #7731: fix_bookmark_3.patch

File fix_bookmark_3.patch, 4.4 KB (added by Jim Stichnoth <stichnot@…>, 14 years ago)
  • programs/mythtranscode/main.cpp

     
    2828                       ProgramInfo *pginfo);
    2929int BuildKeyframeIndex(MPEG2fixup *m2f, QString &infile,
    3030                       QMap <long long, long long> &posMap, int jobID);
    31 void CompleteJob(int jobID, ProgramInfo *pginfo,
    32                  bool useCutlist, int &resultCode);
     31void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist,
     32                 QMap <long long, int> *deleteMap, int &resultCode);
    3333void UpdateJobQueue(float percent_done);
    3434int CheckJobQueue();
    3535static int glbl_jobID = -1;
     
    674674    }
    675675
    676676    if (jobID >= 0)
    677         CompleteJob(jobID, pginfo, useCutlist, exitcode);
     677        CompleteJob(jobID, pginfo, useCutlist, &deleteMap, exitcode);
    678678
    679679    transcode->deleteLater();
    680680
     
    816816    return unlink(filename.toLocal8Bit().constData());
    817817}
    818818
    819 void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode)
     819long long ComputeNewBookmark(long long oldBookmark,
     820                             QMap<long long, int> *deleteMap)
    820821{
     822    if (deleteMap == NULL)
     823        return oldBookmark;
     824    long long subtraction = 0;
     825    long long startOfCutRegion = 0;
     826    QMap<long long, int> delMap = *deleteMap;
     827    bool withinCut = false;
     828    while (delMap.count() && delMap.begin().key() <= oldBookmark)
     829    {
     830        if (delMap.begin().data() == MARK_CUT_START && !withinCut)
     831        {
     832            withinCut = true;
     833            startOfCutRegion = delMap.begin().key();
     834        }
     835        else if (delMap.begin().data() == MARK_CUT_END && withinCut)
     836        {
     837            withinCut = false;
     838            subtraction += (delMap.begin().key() - startOfCutRegion);
     839        }
     840        delMap.remove(delMap.begin());
     841    }
     842    if (withinCut)
     843        subtraction += (oldBookmark - startOfCutRegion);
     844    return oldBookmark - subtraction;
     845}
     846
     847long long ReloadBookmark(ProgramInfo *pginfo)
     848{
     849    MSqlQuery query(MSqlQuery::InitCon());
     850    long long currentBookmark = 0;
     851    query.prepare("SELECT DISTINCT mark FROM recordedmarkup "
     852                  "WHERE chanid = :CHANID "
     853                  "AND starttime = :STARTIME "
     854                  "AND type = :MARKTYPE ;");
     855    query.bindValue(":CHANID", pginfo->chanid);
     856    query.bindValue(":STARTTIME", pginfo->recstartts);
     857    query.bindValue(":MARKTYPE", MARK_BOOKMARK);
     858    if (query.exec() && query.next())
     859    {
     860        currentBookmark = query.value(0).toLongLong();
     861    }
     862    return currentBookmark;
     863}
     864
     865void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist,
     866                 QMap <long long, int> *deleteMap, int &resultCode)
     867{
    821868    int status = JobQueue::GetJobStatus(jobID);
    822869
    823870    if (!pginfo)
     
    832879
    833880    if (status == JOB_STOPPING)
    834881    {
     882        // Transcoding may take several minutes.  Reload the bookmark
     883        // in case it changed, then save its translated value back.
     884        long long previousBookmark =
     885            ComputeNewBookmark(ReloadBookmark(pginfo), deleteMap);
     886        pginfo->SetBookmark(previousBookmark);
     887
    835888        const QString jobArgs = JobQueue::GetJobArgs(jobID);
    836889
    837890        const QString tmpfile = filename + ".tmp";
     
    9771030        {
    9781031            query.prepare("DELETE FROM recordedmarkup "
    9791032                          "WHERE chanid = :CHANID "
    980                           "AND starttime = :STARTTIME ");
     1033                          "AND starttime = :STARTTIME "
     1034                          "AND type != :BOOKMARK ");
    9811035            query.bindValue(":CHANID", pginfo->chanid);
    9821036            query.bindValue(":STARTTIME", pginfo->recstartts);
     1037            query.bindValue(":BOOKMARK", MARK_BOOKMARK);
    9831038
    9841039            if (!query.exec())
    9851040                MythDB::DBError("Error in mythtranscode", query);
    9861041
    9871042            query.prepare("UPDATE recorded "
    988                           "SET cutlist = :CUTLIST, bookmark = :BOOKMARK, "
     1043                          "SET cutlist = :CUTLIST, "
    9891044                          "watched = :WATCHED WHERE chanid = :CHANID "
    9901045                          "AND starttime = :STARTTIME ;");
    9911046            query.bindValue(":CUTLIST", "0");
    992             query.bindValue(":BOOKMARK", "0");
    9931047            query.bindValue(":WATCHED", "0");
    9941048            query.bindValue(":CHANID", pginfo->chanid);
    9951049            query.bindValue(":STARTTIME", pginfo->recstartts);