Ticket #6376: 142-savetranscode.fixes.patch
File 142-savetranscode.fixes.patch, 11.4 KB (added by , 17 years ago) |
---|
-
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
1607 1607 return tmpURL; 1608 1608 } 1609 1609 1610 bool 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 1610 1721 /** 1611 1722 * \brief Inserts this ProgramInfo into the database as an existing recording. 1612 1723 * … … 1718 1829 if (!query.isActive()) 1719 1830 MythContext::DBError("insert_program -- select", query); 1720 1831 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"))); 1722 1834 1723 1835 query.prepare("UNLOCK TABLES"); 1724 1836 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
215 215 const QString &newSubtitle); 216 216 void ApplyTranscoderProfileChange(QString); 217 217 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 218 224 // Quick gets 219 225 bool SetRecordBasename(QString basename); 220 226 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
276 276 bool result = false; 277 277 278 278 bool undelete_possible = 279 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0); 279 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) || 280 gContext->GetNumSetting("SaveTranscoding", 0); 280 281 281 282 if (!undelete_possible) 282 283 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
2181 2181 { 2182 2182 bool ret = -1; 2183 2183 bool undelete_possible = 2184 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0); 2184 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) || 2185 gContext->GetNumSetting("SaveTranscoding", 0); 2186 2185 2187 MythSocket *pbssock = NULL; 2186 2188 if (pbs) 2187 2189 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
27 27 ProgramInfo *pginfo); 28 28 int BuildKeyframeIndex(MPEG2fixup *m2f, QString &infile, 29 29 QMap <long long, long long> &posMap, int jobID); 30 void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode);30 void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo, bool useCutlist, int &resultCode); 31 31 void UpdateJobQueue(float percent_done); 32 32 int CheckJobQueue(); 33 33 static int glbl_jobID = -1; … … 472 472 } 473 473 474 474 ProgramInfo *pginfo = NULL; 475 ProgramInfo *saved_pginfo = NULL; // in case we keep the original recording as deleted 475 476 if (isVideo) 476 477 { 477 478 // We want the absolute file path for the filemarkup table … … 495 496 } 496 497 497 498 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 } 498 510 } 499 511 else 500 512 { … … 643 655 delete transcode; 644 656 645 657 if (jobID >= 0) 646 CompleteJob(jobID, pginfo, useCutlist, exitcode);658 CompleteJob(jobID, pginfo, saved_pginfo, useCutlist, exitcode); 647 659 660 if (saved_pginfo) 661 delete saved_pginfo; 648 662 delete pginfo; 649 663 delete gContext; 650 664 return exitcode; … … 777 791 return unlink(filename); 778 792 } 779 793 780 void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode)794 void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo, bool useCutlist, int &resultCode) 781 795 { 782 796 int status = JobQueue::GetJobStatus(jobID); 783 797 … … 817 831 perror(QString("mythtranscode: Error Renaming '%1' to '%2'") 818 832 .arg(tmpfile).arg(newfile).ascii()); 819 833 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 821 865 { 822 866 int err; 823 867 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
122 122 gc->setLabel(QObject::tr("Save original files after transcoding (globally)")); 123 123 gc->setValue(false); 124 124 gc->setHelpText(QObject::tr("When set and the transcoder is active, the " 125 "original files will be renamed to .oldonce the "125 "original recording will be moved to the 'Deleted' recording group once the " 126 126 "transcoding is complete.")); 127 127 return gc; 128 128 };