summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-07-21 01:50:51 +0200
committerCarl Hetherington <cth@carlh.net>2024-07-21 18:58:43 +0200
commit5c6575633a3e9208a4759ba318c759b08904e686 (patch)
tree8632e604f255ea0abd558c247f2feba975616161
parentbc34a710886beb753b449ac7da842aacfff3dd2d (diff)
Represent frame info hash using raw bytes rather than ASCII-encoding.
-rw-r--r--cscript2
-rw-r--r--src/lib/film.cc7
-rw-r--r--src/lib/film.h1
-rw-r--r--src/lib/frame_info.cc14
-rw-r--r--src/lib/frame_info.h4
-rw-r--r--src/lib/reel_writer.cc3
-rw-r--r--test/reel_writer_test.cc8
7 files changed, 22 insertions, 17 deletions
diff --git a/cscript b/cscript
index 9c5dfd502..2c5ccbabe 100644
--- a/cscript
+++ b/cscript
@@ -534,7 +534,7 @@ def make_spec(filename, version, target, options, requires=None):
print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
def dependencies(target, options):
- deps = [('libdcp', 'v1.9.12', {'c++17': target.platform == 'osx'})]
+ deps = [('libdcp', '75aaabf09286893ef6ecf6d24a3af0937fe4c4c9', {'c++17': target.platform == 'osx'})]
deps.append(('libsub', 'v1.6.49'))
deps.append(('leqm-nrt', '30dcaea1373ac62fba050e02ce5b0c1085797a23'))
deps.append(('rtaudio', 'f619b76'))
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 577895161..c7892d555 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -146,6 +146,12 @@ static constexpr char assets_file[] = "assets.xml";
*/
int const Film::current_state_version = 38;
+/* 1 -> 2
+ * Hash stored as raw bytes rather than with ASCII encoding
+ * (16 bytes instead of 32)
+ */
+int const Film::current_frame_info_version = 2;
+
/** Construct a Film object in a given directory.
*
@@ -289,6 +295,7 @@ Film::info_file (DCPTimePeriod period) const
{
boost::filesystem::path p;
p /= "info";
+ p /= raw_convert<string>(current_frame_info_version);
p /= video_identifier () + "_" + raw_convert<string> (period.from.get()) + "_" + raw_convert<string> (period.to.get());
return file (p);
}
diff --git a/src/lib/film.h b/src/lib/film.h
index 2e7a562e1..285f72152 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -456,6 +456,7 @@ public:
/** Current version number of the state file */
static int const current_state_version;
+ static int const current_frame_info_version;
private:
diff --git a/src/lib/frame_info.cc b/src/lib/frame_info.cc
index e9478b7b1..33b895eb7 100644
--- a/src/lib/frame_info.cc
+++ b/src/lib/frame_info.cc
@@ -25,11 +25,11 @@
using std::shared_ptr;
-using std::string;
+using std::vector;
-J2KFrameInfo::J2KFrameInfo(uint64_t offset_, uint64_t size_, string hash_)
- : dcp::J2KFrameInfo(offset_, size_, hash_)
+J2KFrameInfo::J2KFrameInfo(uint64_t offset_, uint64_t size_, vector<unsigned char> hash_)
+ : dcp::J2KFrameInfo(offset_, size_, std::move(hash_))
{
}
@@ -61,10 +61,8 @@ J2KFrameInfo::read(dcp::File& file)
file.checked_read(&offset, sizeof(offset));
file.checked_read(&size, sizeof(size));
- char hash_buffer[33];
- file.checked_read(hash_buffer, 32);
- hash_buffer[32] = '\0';
- hash = hash_buffer;
+ hash.resize(16);
+ file.checked_read(hash.data(), 16);
}
@@ -93,6 +91,6 @@ J2KFrameInfo::write(shared_ptr<InfoFileHandle> info_file, Frame frame, Eyes eyes
info_file->get().seek(position(frame, eyes), SEEK_SET);
info_file->get().checked_write(&offset, sizeof(offset));
info_file->get().checked_write(&size, sizeof(size));
- info_file->get().checked_write(hash.c_str(), hash.size());
+ info_file->get().checked_write(hash.data(), hash.size());
}
diff --git a/src/lib/frame_info.h b/src/lib/frame_info.h
index 9ec141588..064aec91d 100644
--- a/src/lib/frame_info.h
+++ b/src/lib/frame_info.h
@@ -32,7 +32,7 @@ class J2KFrameInfo : public dcp::J2KFrameInfo
{
public:
J2KFrameInfo(dcp::J2KFrameInfo const& info);
- J2KFrameInfo(uint64_t offset_, uint64_t size_, std::string hash_);
+ J2KFrameInfo(uint64_t offset_, uint64_t size_, std::vector<unsigned char> hash_);
explicit J2KFrameInfo(std::shared_ptr<InfoFileHandle> info_file);
J2KFrameInfo(std::shared_ptr<InfoFileHandle> info_file, Frame frame, Eyes eyes);
@@ -46,7 +46,7 @@ private:
void read(dcp::File& file);
long position(Frame frame, Eyes eyes) const;
- static constexpr auto _size_on_disk = 32 + sizeof(dcp::J2KFrameInfo::offset) + sizeof(dcp::J2KFrameInfo::size);
+ static constexpr auto _size_on_disk = 16 + sizeof(dcp::J2KFrameInfo::offset) + sizeof(dcp::J2KFrameInfo::size);
};
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc
index d8aff1162..17ac02c0c 100644
--- a/src/lib/reel_writer.cc
+++ b/src/lib/reel_writer.cc
@@ -986,8 +986,7 @@ ReelWriter::existing_picture_frame_ok (dcp::File& asset_file, shared_ptr<InfoFil
} else {
Digester digester;
digester.add (data.data(), data.size());
- LOG_GENERAL ("Hash %1 vs %2", digester.get(), info.hash);
- if (digester.get() != info.hash) {
+ if (digester.get_vector() != info.hash) {
LOG_GENERAL ("Existing frame %1 failed hash check", frame);
ok = false;
}
diff --git a/test/reel_writer_test.cc b/test/reel_writer_test.cc
index 411de9b1f..bc3004d7a 100644
--- a/test/reel_writer_test.cc
+++ b/test/reel_writer_test.cc
@@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE (write_frame_info_test)
/* Write the first one */
- J2KFrameInfo info1(0, 123, "12345678901234567890123456789012");
+ J2KFrameInfo info1(0, 123, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 });
info1.write(film->info_file_handle(period, false), 0, Eyes::LEFT);
{
auto file = film->info_file_handle(period, true);
@@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE (write_frame_info_test)
/* Write some more */
- J2KFrameInfo info2(596, 14921, "123acb789f1234ae782012n456339522");
+ J2KFrameInfo info2(596, 14921, { 0x12, 0x3a, 0xcb, 0x78, 0x9f, 0x12, 0x34, 0xae, 0x78, 0x20, 0x12, 0x14, 0x56, 0x33, 0x95, 0x22 });
info2.write(film->info_file_handle(period, false), 5, Eyes::RIGHT);
{
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE (write_frame_info_test)
BOOST_CHECK(equal(info2, file, 5, Eyes::RIGHT));
}
- J2KFrameInfo info3(12494, 99157123, "xxxxyyyyabc12356ffsfdsf456339522");
+ J2KFrameInfo info3(12494, 99157123, { 0x12, 0x34, 0x9a, 0x4d, 0x22, 0xae, 0x91, 0x8f, 0x55, 0xaa, 0xee, 0xdd, 0xaa, 0x11, 0x97, 0x56 });
info3.write(film->info_file_handle(period, false), 10, Eyes::LEFT);
{
@@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE (write_frame_info_test)
/* Overwrite one */
- J2KFrameInfo info4(55512494, 123599157123, "ABCDEFGyabc12356ffsfdsf4563395ZZ");
+ J2KFrameInfo info4(55512494, 123599157123, { 0x81, 0x42, 0xf2, 0xe9, 0xd4, 0x81, 0xef, 0x22, 0x89, 0x18, 0xbc, 0xad, 0x7f, 0x6f, 0x2e, 0x8 });
info4.write(film->info_file_handle(period, false), 5, Eyes::RIGHT);
{