Ticket #6376: 142-savetranscode.trunk.patch
File 142-savetranscode.trunk.patch, 11.3 KB (added by , 15 years ago) |
---|
-
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
1704 1704 return tmpURL; 1705 1705 } 1706 1706 1707 bool 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 1707 1818 /** 1708 1819 * \brief Inserts this ProgramInfo into the database as an existing recording. 1709 1820 * … … 1815 1926 if (!query.isActive()) 1816 1927 MythDB::DBError("insert_program -- select", query); 1817 1928 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"))); 1819 1931 1820 1932 if (!query.exec("UNLOCK TABLES")) 1821 1933 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
237 237 const QString &newSubtitle); 238 238 void ApplyTranscoderProfileChange(QString); 239 239 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 240 246 // Quick gets 241 247 bool SetRecordBasename(QString basename); 242 248 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
273 273 bool result = false; 274 274 275 275 bool undelete_possible = 276 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0); 276 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) || 277 gContext->GetNumSetting("SaveTranscoding", 0); 277 278 278 279 if (!undelete_possible) 279 280 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
2246 2246 { 2247 2247 bool ret = -1; 2248 2248 bool undelete_possible = 2249 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0); 2249 gContext->GetNumSetting("AutoExpireInsteadOfDelete", 0) || 2250 gContext->GetNumSetting("SaveTranscoding", 0); 2250 2251 MythSocket *pbssock = NULL; 2251 2252 if (pbs) 2252 2253 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
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, 30 void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo, 31 31 bool useCutlist, int &resultCode); 32 32 void UpdateJobQueue(float percent_done); 33 33 int CheckJobQueue(); … … 498 498 } 499 499 500 500 ProgramInfo *pginfo = NULL; 501 ProgramInfo *saved_pginfo = NULL; // in case we keep the original recording as deleted 501 502 if (isVideo) 502 503 { 503 504 // We want the absolute file path for the filemarkup table … … 522 523 } 523 524 524 525 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 } 525 537 } 526 538 else 527 539 { … … 673 685 } 674 686 675 687 if (jobID >= 0) 676 CompleteJob(jobID, pginfo, useCutlist, exitcode);688 CompleteJob(jobID, pginfo, saved_pginfo, useCutlist, exitcode); 677 689 678 690 transcode->deleteLater(); 679 691 692 if (saved_pginfo) 693 delete saved_pginfo; 694 680 695 delete gContext; 681 696 return exitcode; 682 697 } … … 815 830 return unlink(filename.toLocal8Bit().constData()); 816 831 } 817 832 818 void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist, int &resultCode)833 void CompleteJob(int jobID, ProgramInfo *pginfo, ProgramInfo *saved_pginfo, bool useCutlist, int &resultCode) 819 834 { 820 835 int status = JobQueue::GetJobStatus(jobID); 821 836 … … 868 883 .arg(tmpfile).arg(newfile) + ENO); 869 884 } 870 885 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 872 917 { 873 918 int err; 874 919 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
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 };