Ticket #6376: 142-savetranscode.fixes.patch

File 142-savetranscode.fixes.patch, 11.4 KB (added by anonymous, 17 years ago)

Patch for 0.21-fixes

  • mythtv/libs/libmythtv/programinfo.cpp

    diff -r -u -N -X diff.exclude -x release.20218.0318a -x release.20218.0318b release.20218.0318a/mythtv/libs/libmythtv/programinfo.cpp release.20218.0318b/mythtv/libs/libmythtv/programinfo.cpp
     
    16071607    return tmpURL;
    16081608}
    16091609
     1610bool ProgramInfo::DuplicateForTranscoding()
     1611{
     1612    // Create new recording basename and update this object to identify as transcoded
     1613    // recording:
     1614    //   Modify the recgroupd -> "Deleted"
     1615    //   Set to autoexpire
     1616    //   Insert it all into the database
     1617    //   Copy the current seek table and markup to the new recording keys
     1618    //
     1619
     1620    if (!record)
     1621    {
     1622        record = new ScheduledRecording();
     1623        record->loadByProgram(this);
     1624    }
     1625
     1626    QString dirname = pathname;
     1627    QDateTime from_recstartts = recstartts;
     1628    QString from_pathname = pathname;
     1629
     1630    recgroup = "Deleted";
     1631
     1632    QString ext = pathname.section('.', -1);
     1633
     1634    hostname = gContext->GetHostName();
     1635    pathname = CreateRecordBasename(ext);
     1636
     1637    int count = 0;
     1638    while (!insert_program(this, record) && count < 50)
     1639    {
     1640        recstartts = recstartts.addSecs(1);
     1641        pathname = CreateRecordBasename(ext);
     1642        count++;
     1643    }
     1644
     1645    if (count >= 50)
     1646    {
     1647        VERBOSE(VB_IMPORTANT, "Couldn't insert program for transcode");
     1648        return false;
     1649    }
     1650
     1651    VERBOSE(VB_GENERAL, QString("Orig: %1, New: %2").arg(from_pathname).arg(pathname));
     1652
     1653    // Set to autoexpire
     1654    SetAutoExpire(kDeletedAutoExpire);
     1655    UpdateLastDelete(true);
     1656
     1657    MSqlQuery query(MSqlQuery::InitCon());
     1658
     1659    // Copy the original recordedseek
     1660    query.prepare("CREATE TEMPORARY TABLE tmp_recordedseek"
     1661                  " SELECT * FROM recordedseek WHERE chanid = :CHANID"
     1662                  " AND starttime = :START;");
     1663
     1664    query.bindValue(":CHANID", chanid);
     1665    query.bindValue(":START", from_recstartts);
     1666
     1667    if (!query.exec() || !query.isActive())
     1668        MythContext::DBError("Create temp table recordedseek on program duplicate", query);
     1669
     1670    // Update recordedseek to have the new starttime
     1671    query.prepare("UPDATE tmp_recordedseek SET starttime = :START;");
     1672    query.bindValue(":START", recstartts);
     1673
     1674    if (!query.exec() || !query.isActive())
     1675        MythContext::DBError("Update tmp table on program duplicate", query);
     1676
     1677    // Copy back into the real recordedseek table
     1678    query.prepare("INSERT INTO recordedseek SELECT * from tmp_recordedseek;");
     1679
     1680    if (!query.exec() || !query.isActive())
     1681        MythContext::DBError("Copy back into recordedseek on program duplicate", query);
     1682
     1683    query.prepare("DROP TABLE tmp_recordedseek;");
     1684    if (!query.exec() || !query.isActive())
     1685        MythContext::DBError("Drop temp table recordedseek on program duplicate", query);
     1686
     1687
     1688    // Do the same thing for recordedmarkup
     1689
     1690    // Copy the original recordedmarkup
     1691    query.prepare("CREATE TEMPORARY TABLE tmp_recordedmarkup"
     1692                  " SELECT * FROM recordedmarkup WHERE chanid = :CHANID"
     1693                  " AND starttime = :START;");
     1694
     1695    query.bindValue(":CHANID", chanid);
     1696    query.bindValue(":START", from_recstartts);
     1697
     1698    if (!query.exec() || !query.isActive())
     1699        MythContext::DBError("Create temp table recordedmarkup on program duplicate", query);
     1700
     1701    // Update recordedseek to have the new starttime
     1702    query.prepare("UPDATE tmp_recordedmarkup SET starttime = :START;");
     1703    query.bindValue(":START", recstartts);
     1704
     1705    if (!query.exec() || !query.isActive())
     1706        MythContext::DBError("Update tmp table on program duplicate", query);
     1707
     1708    // Copy back into the real recordedmarkup table
     1709    query.prepare("INSERT INTO recordedmarkup SELECT * from tmp_recordedmarkup;");
     1710
     1711    if (!query.exec() || !query.isActive())
     1712        MythContext::DBError("Copy back into recordedmarkup on program duplicate", query);
     1713
     1714    query.prepare("DROP TABLE tmp_recordedmarkup;");
     1715    if (!query.exec() || !query.isActive())
     1716        MythContext::DBError("Drop temp table recordedmarkup on program duplicate", query);
     1717
     1718    return true;
     1719}
     1720
    16101721/**
    16111722 *  \brief Inserts this ProgramInfo into the database as an existing recording.
    16121723 * 
     
    17181829        if (!query.isActive())
    17191830            MythContext::DBError("insert_program -- select", query);
    17201831        else
    1721             VERBOSE(VB_IMPORTANT, "recording already exists...");
     1832            VERBOSE(VB_IMPORTANT, QString("recording already exists for chanid %1 starttime %2")
     1833                                  .arg(pg->chanid).arg(pg->recstartts.toString("yyyyMMddhhmmss")));
    17221834
    17231835        query.prepare("UNLOCK TABLES");
    17241836        query.exec();
  • mythtv/libs/libmythtv/programinfo.h

    diff -r -u -N -X diff.exclude -x release.20218.0318a -x release.20218.0318b release.20218.0318a/mythtv/libs/libmythtv/programinfo.h release.20218.0318b/mythtv/libs/libmythtv/programinfo.h
     
    215215                                   const QString &newSubtitle);
    216216    void ApplyTranscoderProfileChange(QString);
    217217
     218    // If we're transcoding and saving the original file, this
     219    // will duplicate the ProgramInfo so both the original and
     220    // Transcoded recording exist in MythTV
     221    // returns true if successful
     222    bool DuplicateForTranscoding();
     223
    218224    // Quick gets
    219225    bool SetRecordBasename(QString basename);
    220226    QString GetRecordBasename(bool fromDB = false) const;
  • mythtv/libs/libmythtv/remoteutil.cpp

    diff -r -u -N -X diff.exclude -x release.20218.0318a -x release.20218.0318b release.20218.0318a/mythtv/libs/libmythtv/remoteutil.cpp release.20218.0318b/mythtv/libs/libmythtv/remoteutil.cpp
     
    276276    bool result = false;
    277277
    278278    bool undelete_possible =
    279             gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0);
     279            gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) ||
     280            gContext->GetNumSetting("SaveTranscoding", 0);
    280281
    281282    if (!undelete_possible)
    282283        return result;
  • mythtv/programs/mythbackend/mainserver.cpp

    diff -r -u -N -X diff.exclude -x release.20218.0318a -x release.20218.0318b release.20218.0318a/mythtv/programs/mythbackend/mainserver.cpp release.20218.0318b/mythtv/programs/mythbackend/mainserver.cpp
     
    21812181{
    21822182    bool ret = -1;
    21832183    bool undelete_possible =
    2184             gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0);
     2184            gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) ||
     2185            gContext->GetNumSetting("SaveTranscoding", 0);
     2186
    21852187    MythSocket *pbssock = NULL;
    21862188    if (pbs)
    21872189        pbssock = pbs->getSocket();
  • mythtv/programs/mythtranscode/main.cpp

    diff -r -u -N -X diff.exclude -x release.20218.0318a -x release.20218.0318b release.20218.0318a/mythtv/programs/mythtranscode/main.cpp release.20218.0318b/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, bool useCutlist, int &resultCode);
     30void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo, bool useCutlist, int &resultCode);
    3131void UpdateJobQueue(float percent_done);
    3232int CheckJobQueue();
    3333static int glbl_jobID = -1;
     
    472472    }
    473473
    474474    ProgramInfo *pginfo = NULL;
     475    ProgramInfo *saved_pginfo = NULL; // in case we keep the original recording as deleted
    475476    if (isVideo)
    476477    {
    477478        // We want the absolute file path for the filemarkup table
     
    495496        }
    496497
    497498        infile = pginfo->GetPlaybackURL(false, true);
     499
     500        // If we're saving the old file we need to save the cut and markup info now
     501        if (gContext->GetNumSetting("SaveTranscoding", 0))
     502        {
     503            saved_pginfo = new ProgramInfo(*pginfo);
     504            if (!saved_pginfo->DuplicateForTranscoding())
     505            {
     506                delete saved_pginfo;
     507                saved_pginfo = NULL;
     508            }
     509        }
    498510    }
    499511    else
    500512    {
     
    643655    delete transcode;
    644656
    645657    if (jobID >= 0)
    646         CompleteJob(jobID, pginfo, useCutlist, exitcode);
     658        CompleteJob(jobID, pginfo, saved_pginfo, useCutlist, exitcode);
    647659
     660    if (saved_pginfo)
     661        delete saved_pginfo;
    648662    delete pginfo;
    649663    delete gContext;
    650664    return exitcode;
     
    777791    return unlink(filename);
    778792}
    779793
    780 void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode)
     794void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo, bool useCutlist, int &resultCode)
    781795{
    782796    int status = JobQueue::GetJobStatus(jobID);
    783797
     
    817831            perror(QString("mythtranscode: Error Renaming '%1' to '%2'")
    818832                   .arg(tmpfile).arg(newfile).ascii());
    819833
    820         if (!gContext->GetNumSetting("SaveTranscoding", 0))
     834        if (gContext->GetNumSetting("SaveTranscoding", 0))
     835        {
     836            if (saved_pginfo)
     837            {
     838                // Get a new (old) filename
     839                // and move the old transcode file to the new (old) filename
     840
     841                // Can't use GetPlaybackURL() because the target file doesn't exist yet.
     842
     843                QString origfilename = saved_pginfo->GetFileName();
     844                QString origbasename = origfilename.section('/', -1);
     845
     846                QString dirname = oldfile.section('/', 0, -2);
     847
     848                QString origpath = dirname + "/" + origbasename;
     849
     850                if (rename(oldfile.local8Bit(), origpath.local8Bit()) == -1)
     851                    perror(QString("mythtranscode: Error Renaming '%1' to '%2'")
     852                           .arg(oldfile).arg(origpath).ascii());
     853
     854
     855                // If we transcoded a "Deleted" program, undelete the output recording
     856                if (pginfo->recgroup == "Deleted")
     857                {
     858                    pginfo->ApplyRecordRecGroupChange("Default");
     859                    pginfo->UpdateLastDelete(false);
     860                    pginfo->SetAutoExpire(kDisableAutoExpire);
     861                }
     862            }
     863        }
     864        else
    821865        {
    822866            int err;
    823867            bool followLinks = gContext->GetNumSetting("DeletesFollowLinks", 0);
  • mythtv/programs/mythtv-setup/backendsettings.cpp

    diff -r -u -N -X diff.exclude -x release.20218.0318a -x release.20218.0318b release.20218.0318a/mythtv/programs/mythtv-setup/backendsettings.cpp release.20218.0318b/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};