Implement reproducible ISO output (#309)

This commit is contained in:
Daniel Kamil Kozar 2020-07-01 23:09:26 +02:00 committed by GitHub
parent 61fe6ebbd7
commit bbcacde251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 17 deletions

View File

@ -278,8 +278,8 @@ Parameter | Description
--insertBlankPL | Add an additional short playlist. Used for cropped video muxed to BD disc.
--blankOffset | Blank playlist number.
--label | Disk label when muxing to ISO.
--extra-iso-space | Allocate extra space in 64K units for ISO metadata (file and directory names). Normally, tsMuxeR allocates this space automatically, but if split condition generates a lot of small files, it may be required to define extra space.
--extra-iso-space | Allocate extra space in 64K units for ISO metadata (file and directory names). Normally, tsMuxeR allocates this space automatically, but if split condition generates a lot of small files, it may be required to define extra space.
--constant-iso-hdr | Generates an ISO header that does not depend on the program version or the current time. Normally, the ISO header's "application ID", "implementation ID", and "volume ID" fields are set to strings containing the program version and/or a random number, while the access/modification/creation times of the files in the image are set to the current time. This option disables this behaviour by filling these fields with hardcoded values and setting the file times to the equivalent of `Wed 1 Jul 20:00:00 UTC 2020` in the local timezone. Using this option is not recommended for normal usage, as it is meant only for testing ISO output validity.
## Todo

View File

@ -278,7 +278,8 @@ void BlurayHelper::close()
}
}
bool BlurayHelper::open(const string& dst, DiskType dt, int64_t diskSize, int extraISOBlocks)
bool BlurayHelper::open(const string& dst, DiskType dt, int64_t diskSize, int extraISOBlocks,
bool useReproducibleIsoHeader)
{
m_dstPath = toNativeSeparators(dst);
@ -287,7 +288,7 @@ bool BlurayHelper::open(const string& dst, DiskType dt, int64_t diskSize, int ex
fileExt = unquoteStr(strToUpperCase(fileExt));
if (fileExt == "ISO")
{
m_isoWriter = new IsoWriter();
m_isoWriter = new IsoWriter(useReproducibleIsoHeader ? IsoHeaderData::reproducible() : IsoHeaderData::normal());
m_isoWriter->setLayerBreakPoint(0xBA7200); // around 25Gb
return m_isoWriter->open(m_dstPath, diskSize, extraISOBlocks);
}

View File

@ -19,7 +19,8 @@ class BlurayHelper : public FileFactory
BlurayHelper();
~BlurayHelper() override;
bool open(const std::string& dst, DiskType dt, int64_t diskSize = 0, int extraISOBlocks = 0);
bool open(const std::string& dst, DiskType dt, int64_t diskSize = 0, int extraISOBlocks = 0,
bool useReproducibleIsoHeader = false);
bool createBluRayDirs();
bool writeBluRayFiles(const MuxerManager& muxer, bool usedBlankPL, int mplsNum, int blankNum, bool stereoMode);
bool createCLPIFile(TSMuxer* muxer, int clpiNum, bool doLog);

View File

@ -575,13 +575,9 @@ int64_t ISOFile::size() const { return m_entry ? m_entry->m_fileSize : -1; }
// ------------------------------ IsoWriter ----------------------------------
IsoWriter::IsoWriter()
IsoWriter::IsoWriter(const IsoHeaderData& hdrData)
: m_impId(hdrData.impId), m_appId(hdrData.appId), m_volumeId(hdrData.volumeId), m_currentTime(hdrData.fileTime)
{
m_volumeId = random32();
m_appId = "*tsMuxeR " TSMUXER_VERSION;
m_impId = std::string("*tsMuxeR ") + int32ToHex(random32());
m_currentTime = time(0);
m_objectUniqId = 16;
m_totalFiles = 0;
m_totalDirectories = 0;
@ -1402,3 +1398,11 @@ void IsoWriter::checkLayerBreakPoint(int maxExtentSize)
}
void IsoWriter::setLayerBreakPoint(int lbn) { m_layerBreakPoint = lbn; }
IsoHeaderData IsoHeaderData::normal()
{
return IsoHeaderData{"*tsMuxeR " TSMUXER_VERSION, std::string("*tsMuxeR ") + int32ToHex(random32()), time(0),
random32()};
}
IsoHeaderData IsoHeaderData::reproducible() { return IsoHeaderData{"*tsMuxeR", "*tsMuxeR", 1, 1593630000}; }

View File

@ -167,10 +167,21 @@ struct FileEntryInfo
bool m_subMode; // sub file in stereo interleaved mode
};
struct IsoHeaderData
{
std::string appId;
std::string impId;
time_t fileTime;
uint32_t volumeId;
static IsoHeaderData normal();
static IsoHeaderData reproducible();
};
class IsoWriter
{
public:
IsoWriter();
IsoWriter(const IsoHeaderData&);
~IsoWriter();
void setVolumeLabel(const std::string& value);
@ -230,12 +241,12 @@ class IsoWriter
friend class ISOFile;
std::string m_volumeLabel;
std::string m_impId;
std::string m_appId;
uint32_t m_volumeId;
const std::string m_impId;
const std::string m_appId;
const uint32_t m_volumeId;
File m_file;
uint8_t m_buffer[SECTOR_SIZE];
time_t m_currentTime;
const time_t m_currentTime;
uint32_t m_objectUniqId;
uint32_t m_totalFiles;

View File

@ -548,6 +548,8 @@ All parameters in this group start with two dashes:
and directory names). Normally, tsMuxeR allocates this space
automatically, but if split condition generates a lot
of small files, it may be required to define extra space.
--constant-iso-hdr Generates an ISO header that does not depend on the program
version or the current time. Not meant for normal usage.
)help";
LTRACE(LT_INFO, 2, help);
}
@ -744,7 +746,8 @@ int main(int argc, char** argv)
if (dt != DT_NONE)
{
if (!blurayHelper.open(dstFile, dt, muxerManager.totalSize(), muxerManager.getExtraISOBlocks()))
if (!blurayHelper.open(dstFile, dt, muxerManager.totalSize(), muxerManager.getExtraISOBlocks(),
muxerManager.useReproducibleIsoHeader()))
throw runtime_error(string("Can't create output file ") + dstFile);
blurayHelper.setVolumeLabel(isoDiskLabel);
blurayHelper.createBluRayDirs();

View File

@ -376,6 +376,10 @@ void MuxerManager::parseMuxOpt(const string& opts)
{
m_demuxMode = true;
}
else if (paramPair[0] == "--constant-iso-hdr")
{
m_reproducibleIsoHeader = true;
}
}
}

View File

@ -57,6 +57,8 @@ class MuxerManager
int64_t totalSize() const { return m_metaDemuxer.totalSize(); }
int getExtraISOBlocks() const { return m_extraIsoBlocks; }
bool useReproducibleIsoHeader() const { return m_reproducibleIsoHeader; }
enum class SubTrackMode
{
All,
@ -97,6 +99,7 @@ class MuxerManager
int m_extraIsoBlocks;
bool m_bluRayMode;
bool m_demuxMode;
bool m_reproducibleIsoHeader = false;
};
#endif // __MUXER_MANAGER_H