Ticket #6376: 142-savetranscode.trunk.patch

File 142-savetranscode.trunk.patch, 11.3 KB (added by anonymous, 15 years ago)

Patch for Trunk

  • mythtv/libs/libmythtv/programinfo.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/programinfo.cpp myth.20207.0313b/mythtv/libs/libmythtv/programinfo.cpp
     
    17041704    return tmpURL;
    17051705}
    17061706
     1707bool ProgramInfo::DuplicateForTranscoding()
     1708{
     1709    // Create new recording basename and update this object to identify as transcoded
     1710    // recording:
     1711    //   Modify the recgroupd -> "Deleted"
     1712    //   Set to autoexpire
     1713    //   Insert it all into the database
     1714    //   Copy the current seek table and markup to the new recording keys
     1715    //
     1716
     1717    if (!record)
     1718    {
     1719        record = new ScheduledRecording();
     1720        record->loadByProgram(this);
     1721    }
     1722
     1723    QString dirname = pathname;
     1724    QDateTime from_recstartts = recstartts;
     1725    QString from_pathname = pathname;
     1726
     1727    recgroup = "Deleted";
     1728
     1729    QString ext = pathname.section('.', -1);
     1730
     1731    hostname = gContext->GetHostName();
     1732    pathname = CreateRecordBasename(ext);
     1733
     1734    int count = 0;
     1735    while (!insert_program(this, record) && count < 50)
     1736    {
     1737        recstartts = recstartts.addSecs(1);
     1738        pathname = CreateRecordBasename(ext);
     1739        count++;
     1740    }
     1741
     1742    if (count >= 50)
     1743    {
     1744        VERBOSE(VB_IMPORTANT, "Couldn't insert program for transcode");
     1745        return false;
     1746    }
     1747
     1748    VERBOSE(VB_GENERAL, QString("Orig: %1, New: %2").arg(from_pathname).arg(pathname));
     1749
     1750    // Set to autoexpire
     1751    SetAutoExpire(kDeletedAutoExpire);
     1752    UpdateLastDelete(true);
     1753
     1754    MSqlQuery query(MSqlQuery::InitCon());
     1755
     1756    // Copy the original recordedseek
     1757    query.prepare("CREATE TEMPORARY TABLE tmp_recordedseek"
     1758                  " SELECT * FROM recordedseek WHERE chanid = :CHANID"
     1759                  " AND starttime = :START;");
     1760
     1761    query.bindValue(":CHANID", chanid);
     1762    query.bindValue(":START", from_recstartts);
     1763
     1764    if (!query.exec() || !query.isActive())
     1765        MythDB::DBError("Create temp table recordedseek on program duplicate", query);
     1766
     1767    // Update recordedseek to have the new starttime
     1768    query.prepare("UPDATE tmp_recordedseek SET starttime = :START;");
     1769    query.bindValue(":START", recstartts);
     1770
     1771    if (!query.exec() || !query.isActive())
     1772        MythDB::DBError("Update tmp table on program duplicate", query);
     1773
     1774    // Copy back into the real recordedseek table
     1775    query.prepare("INSERT INTO recordedseek SELECT * from tmp_recordedseek;");
     1776
     1777    if (!query.exec() || !query.isActive())
     1778        MythDB::DBError("Copy back into recordedseek on program duplicate", query);
     1779
     1780    query.prepare("DROP TABLE tmp_recordedseek;");
     1781    if (!query.exec() || !query.isActive())
     1782        MythDB::DBError("Drop temp table recordedseek on program duplicate", query);
     1783
     1784
     1785    // Do the same thing for recordedmarkup
     1786
     1787    // Copy the original recordedmarkup
     1788    query.prepare("CREATE TEMPORARY TABLE tmp_recordedmarkup"
     1789                  " SELECT * FROM recordedmarkup WHERE chanid = :CHANID"
     1790                  " AND starttime = :START;");
     1791
     1792    query.bindValue(":CHANID", chanid);
     1793    query.bindValue(":START", from_recstartts);
     1794
     1795    if (!query.exec() || !query.isActive())
     1796        MythDB::DBError("Create temp table recordedmarkup on program duplicate", query);
     1797
     1798    // Update recordedseek to have the new starttime
     1799    query.prepare("UPDATE tmp_recordedmarkup SET starttime = :START;");
     1800    query.bindValue(":START", recstartts);
     1801
     1802    if (!query.exec() || !query.isActive())
     1803        MythDB::DBError("Update tmp table on program duplicate", query);
     1804
     1805    // Copy back into the real recordedmarkup table
     1806    query.prepare("INSERT INTO recordedmarkup SELECT * from tmp_recordedmarkup;");
     1807
     1808    if (!query.exec() || !query.isActive())
     1809        MythDB::DBError("Copy back into recordedmarkup on program duplicate", query);
     1810
     1811    query.prepare("DROP TABLE tmp_recordedmarkup;");
     1812    if (!query.exec() || !query.isActive())
     1813        MythDB::DBError("Drop temp table recordedmarkup on program duplicate", query);
     1814
     1815    return true;
     1816}
     1817
    17071818/**
    17081819 *  \brief Inserts this ProgramInfo into the database as an existing recording.
    17091820 *
     
    18151926        if (!query.isActive())
    18161927            MythDB::DBError("insert_program -- select", query);
    18171928        else
    1818             VERBOSE(VB_IMPORTANT, "recording already exists...");
     1929            VERBOSE(VB_IMPORTANT, QString("recording already exists for chanid %1 starttime %2")
     1930                                  .arg(pg->chanid).arg(pg->recstartts.toString("yyyyMMddhhmmss")));
    18191931
    18201932        if (!query.exec("UNLOCK TABLES"))
    18211933            MythDB::DBError("insert_program -- unlock tables", query);
  • mythtv/libs/libmythtv/programinfo.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/programinfo.h myth.20207.0313b/mythtv/libs/libmythtv/programinfo.h
     
    237237                                   const QString &newSubtitle);
    238238    void ApplyTranscoderProfileChange(QString);
    239239
     240    // If we're transcoding and saving the original file, this
     241    // will duplicate the ProgramInfo so both the original and
     242    // Transcoded recording exist in MythTV
     243    // returns true if successful
     244    bool DuplicateForTranscoding();
     245
    240246    // Quick gets
    241247    bool SetRecordBasename(QString basename);
    242248    QString GetRecordBasename(bool fromDB = false) const;
  • mythtv/libs/libmythtv/remoteutil.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/remoteutil.cpp myth.20207.0313b/mythtv/libs/libmythtv/remoteutil.cpp
     
    273273    bool result = false;
    274274
    275275    bool undelete_possible =
    276             gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0);
     276            gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) ||
     277            gContext->GetNumSetting("SaveTranscoding", 0);
    277278
    278279    if (!undelete_possible)
    279280        return result;
  • mythtv/programs/mythbackend/mainserver.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/programs/mythbackend/mainserver.cpp myth.20207.0313b/mythtv/programs/mythbackend/mainserver.cpp
     
    22462246{
    22472247    bool ret = -1;
    22482248    bool undelete_possible =
    2249             gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0);
     2249            gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) ||
     2250            gContext->GetNumSetting("SaveTranscoding", 0);
    22502251    MythSocket *pbssock = NULL;
    22512252    if (pbs)
    22522253        pbssock = pbs->getSocket();
  • mythtv/programs/mythtranscode/main.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/programs/mythtranscode/main.cpp myth.20207.0313b/mythtv/programs/mythtranscode/main.cpp
     
    2727                       ProgramInfo *pginfo);
    2828int BuildKeyframeIndex(MPEG2fixup *m2f, QString &infile,
    2929                       QMap <long long, long long> &posMap, int jobID);
    30 void CompleteJob(int jobID, ProgramInfo *pginfo,
     30void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo,
    3131                 bool useCutlist, int &resultCode);
    3232void UpdateJobQueue(float percent_done);
    3333int CheckJobQueue();
     
    498498    }
    499499
    500500    ProgramInfo *pginfo = NULL;
     501    ProgramInfo *saved_pginfo = NULL; // in case we keep the original recording as deleted
    501502    if (isVideo)
    502503    {
    503504        // We want the absolute file path for the filemarkup table
     
    522523        }
    523524
    524525        infile = pginfo->GetPlaybackURL(false, true);
     526
     527        // If we're saving the old file we need to save the cut and markup info now
     528        if (gContext->GetNumSetting("SaveTranscoding", 0))
     529        {
     530            saved_pginfo = new ProgramInfo(*pginfo);
     531            if (!saved_pginfo->DuplicateForTranscoding())
     532            {
     533                delete saved_pginfo;
     534                saved_pginfo = NULL;
     535            }
     536        }
    525537    }
    526538    else
    527539    {
     
    673685    }
    674686
    675687    if (jobID >= 0)
    676         CompleteJob(jobID, pginfo, useCutlist, exitcode);
     688        CompleteJob(jobID, pginfo, saved_pginfo, useCutlist, exitcode);
    677689
    678690    transcode->deleteLater();
    679691
     692    if (saved_pginfo)
     693        delete saved_pginfo;
     694
    680695    delete gContext;
    681696    return exitcode;
    682697}
     
    815830    return unlink(filename.toLocal8Bit().constData());
    816831}
    817832
    818 void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode)
     833void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo, bool useCutlist, int &resultCode)
    819834{
    820835    int status = JobQueue::GetJobStatus(jobID);
    821836
     
    868883                    .arg(tmpfile).arg(newfile) + ENO);
    869884        }
    870885
    871         if (!gContext->GetNumSetting("SaveTranscoding", 0))
     886        if (gContext->GetNumSetting("SaveTranscoding", 0))
     887        {
     888            if (saved_pginfo)
     889            {
     890                // Get a new (old) filename
     891                // and move the old transcode file to the new (old) filename
     892
     893                // Can't use GetPlaybackURL() because the target file doesn't exist yet.
     894
     895                QString origfilename = saved_pginfo->GetFileName();
     896                QString origbasename = origfilename.section('/', -1);
     897
     898                QString dirname = oldfile.section('/', 0, -2);
     899
     900                QString origpath = dirname + "/" + origbasename;
     901
     902                if (rename(oldfile.local8Bit(), origpath.local8Bit()) == -1)
     903                    perror(QString("mythtranscode: Error Renaming '%1' to '%2'")
     904                           .arg(oldfile).arg(origpath).ascii());
     905
     906
     907                // If we transcoded a "Deleted" program, undelete the output recording
     908                if (pginfo->recgroup == "Deleted")
     909                {
     910                    pginfo->ApplyRecordRecGroupChange("Default");
     911                    pginfo->UpdateLastDelete(false);
     912                    pginfo->SetAutoExpire(kDisableAutoExpire);
     913                }
     914            }
     915        }
     916        else
    872917        {
    873918            int err;
    874919            bool followLinks = gContext->GetNumSetting("DeletesFollowLinks", 0);
  • mythtv/programs/mythtv-setup/backendsettings.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/programs/mythtv-setup/backendsettings.cpp myth.20207.0313b/mythtv/programs/mythtv-setup/backendsettings.cpp
     
    122122    gc->setLabel(QObject::tr("Save original files after transcoding (globally)"));
    123123    gc->setValue(false);
    124124    gc->setHelpText(QObject::tr("When set and the transcoder is active, the "
    125                     "original files will be renamed to .old once the "
     125                    "original recording will be moved to the 'Deleted' recording group once the "
    126126                    "transcoding is complete."));
    127127    return gc;
    128128};