summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-06-25 00:13:55 +0200
committerCarl Hetherington <cth@carlh.net>2025-09-15 23:18:58 +0200
commitb786ec52435a697f7bcc2ef1870f22e27e446315 (patch)
tree0a2a2ad040e5a73350b853d190acd3277fecd1cd
parent7cb07bcec10bfdfed3e82a2dc138114dc6a5ac68 (diff)
FIXME: Hash to a vector rather than a string.2758-safe-write
Needs asdcplib version bump.
-rw-r--r--cscript2
-rw-r--r--src/frame_info.h11
-rw-r--r--src/mono_j2k_picture_asset_writer.cc5
-rw-r--r--src/mono_mpeg2_picture_asset_writer.cc3
-rw-r--r--src/stereo_j2k_picture_asset_writer.cc7
-rw-r--r--test/frame_info_hash_test.cc11
-rw-r--r--test/recovery_test.cc6
7 files changed, 26 insertions, 19 deletions
diff --git a/cscript b/cscript
index f8a844cf..ef3a9b93 100644
--- a/cscript
+++ b/cscript
@@ -45,7 +45,7 @@ def dependencies(target, options):
deps = [
('libcxml', 'v0.17.13', { 'c++17': build_with_cpp17(target) }),
('openjpeg', 'ad8edaacd54a862940d0a77c41ecda5858b54d6e'),
- ('asdcplib', 'v1.0.8')
+ ('asdcplib', '2eeee990f029779d8d1c2205b99a239bf87fbbe5')
]
if target.platform == 'linux':
diff --git a/src/frame_info.h b/src/frame_info.h
index 325350c4..ea57885c 100644
--- a/src/frame_info.h
+++ b/src/frame_info.h
@@ -42,6 +42,7 @@ LIBDCP_DISABLE_WARNINGS
LIBDCP_ENABLE_WARNINGS
#include <stdint.h>
#include <string>
+#include <vector>
namespace dcp {
@@ -54,15 +55,15 @@ struct FrameInfo
{
FrameInfo () = default;
- FrameInfo(uint64_t o, uint64_t s, std::string h)
+ FrameInfo(uint64_t o, uint64_t s, std::vector<uint8_t> h)
: offset(o)
, size(s)
- , hash(h)
+ , hash(std::move(h))
{}
uint64_t offset = 0;
uint64_t size = 0;
- std::string hash;
+ std::vector<uint8_t> hash;
};
@@ -70,7 +71,7 @@ struct J2KFrameInfo : public FrameInfo
{
J2KFrameInfo() = default;
- J2KFrameInfo(uint64_t offset_, uint64_t size_, std::string hash_)
+ J2KFrameInfo(uint64_t offset_, uint64_t size_, std::vector<uint8_t> hash_)
: FrameInfo(offset_, size_, hash_)
{}
};
@@ -83,7 +84,7 @@ struct MPEG2FrameInfo : public FrameInfo
MPEG2FrameInfo(
uint64_t offset_,
uint64_t size_,
- std::string hash_,
+ std::vector<uint8_t> hash_,
ASDCP::MPEG2::FrameType_t type_,
bool gop_start_,
bool closed_gop_,
diff --git a/src/mono_j2k_picture_asset_writer.cc b/src/mono_j2k_picture_asset_writer.cc
index 644cfd3a..394040ac 100644
--- a/src/mono_j2k_picture_asset_writer.cc
+++ b/src/mono_j2k_picture_asset_writer.cc
@@ -52,8 +52,9 @@ LIBDCP_ENABLE_WARNINGS
#include "j2k_picture_asset_writer_common.cc"
-using std::string;
using std::shared_ptr;
+using std::string;
+using std::vector;
using namespace dcp;
@@ -110,7 +111,7 @@ MonoJ2KPictureAssetWriter::write (uint8_t const * data, int size)
uint64_t const before_offset = _state->mxf_writer.Tell ();
- string hash;
+ vector<uint8_t> hash;
auto const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _crypto_context->context(), _crypto_context->hmac(), &hash);
if (ASDCP_FAILURE(r)) {
throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r));
diff --git a/src/mono_mpeg2_picture_asset_writer.cc b/src/mono_mpeg2_picture_asset_writer.cc
index a8e05ce9..5b841c4d 100644
--- a/src/mono_mpeg2_picture_asset_writer.cc
+++ b/src/mono_mpeg2_picture_asset_writer.cc
@@ -38,6 +38,7 @@
using std::string;
+using std::vector;
using namespace dcp;
@@ -92,7 +93,7 @@ MonoMPEG2PictureAssetWriter::write(uint8_t const * data, int size)
auto const before_offset = _state->mxf_writer.Tell();
- string hash;
+ vector<uint8_t> hash;
auto const r = _state->mxf_writer.WriteFrame(buffer, _crypto_context->context(), _crypto_context->hmac(), &hash);
if (ASDCP_FAILURE(r)) {
throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r));
diff --git a/src/stereo_j2k_picture_asset_writer.cc b/src/stereo_j2k_picture_asset_writer.cc
index 02ccdca1..6874bf7c 100644
--- a/src/stereo_j2k_picture_asset_writer.cc
+++ b/src/stereo_j2k_picture_asset_writer.cc
@@ -49,8 +49,9 @@
#include "j2k_picture_asset_writer_common.cc"
-using std::string;
using std::shared_ptr;
+using std::string;
+using std::vector;
using namespace dcp;
@@ -104,7 +105,7 @@ StereoJ2KPictureAssetWriter::write (uint8_t const * data, int size)
uint64_t const before_offset = _state->mxf_writer.Tell ();
- string hash;
+ vector<uint8_t> hash;
auto r = _state->mxf_writer.WriteFrame (
_state->frame_buffer,
_next_eye == Eye::LEFT ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT,
@@ -123,7 +124,7 @@ StereoJ2KPictureAssetWriter::write (uint8_t const * data, int size)
++_frames_written;
}
- return J2KFrameInfo(before_offset, _state->mxf_writer.Tell() - before_offset, hash);
+ return J2KFrameInfo(before_offset, _state->mxf_writer.Tell() - before_offset, std::move(hash));
}
diff --git a/test/frame_info_hash_test.cc b/test/frame_info_hash_test.cc
index 331eabf1..edf89f5c 100644
--- a/test/frame_info_hash_test.cc
+++ b/test/frame_info_hash_test.cc
@@ -44,10 +44,11 @@
using std::make_shared;
using std::shared_ptr;
using std::string;
+using std::vector;
static void
-check (shared_ptr<dcp::J2KPictureAssetWriter> writer, boost::random::uniform_int_distribution<>& dist, boost::random::mt19937& rng, string hash)
+check(shared_ptr<dcp::J2KPictureAssetWriter> writer, boost::random::uniform_int_distribution<>& dist, boost::random::mt19937& rng, vector<uint8_t> hash)
{
auto xyz = make_shared<dcp::OpenJPEGImage>(dcp::Size(1998, 1080));
for (int c = 0; c < 3; ++c) {
@@ -59,7 +60,7 @@ check (shared_ptr<dcp::J2KPictureAssetWriter> writer, boost::random::uniform_int
auto data = dcp::compress_j2k (xyz, 100000000, 24, false, false);
auto info = writer->write (data.data(), data.size());
- BOOST_CHECK_EQUAL (info.hash, hash);
+ BOOST_CHECK(info.hash == hash);
}
@@ -73,7 +74,7 @@ BOOST_AUTO_TEST_CASE (frame_info_hash_test)
boost::random::uniform_int_distribution<> dist(0, 4095);
/* Check a few random frames */
- check(writer, dist, rng, "8f3dc7321d6dff3d5691011de31fc713");
- check(writer, dist, rng, "a305b83a40367fda1b5cf0efa096fd18");
- check(writer, dist, rng, "1abc71e011ced46d9928a4b2d22e20f6");
+ check(writer, dist, rng, vector<uint8_t>{0x8f, 0x3d, 0xc7, 0x32, 0x1d, 0x6d, 0xff, 0x3d, 0x56, 0x91, 0x01, 0x1d, 0xe3, 0x1f, 0xc7, 0x13});
+ check(writer, dist, rng, vector<uint8_t>{0xa3, 0x05, 0xb8, 0x3a, 0x40, 0x36, 0x7f, 0xda, 0x1b, 0x5c, 0xf0, 0xef, 0xa0, 0x96, 0xfd, 0x18});
+ check(writer, dist, rng, vector<uint8_t>{0x1a, 0xbc, 0x71, 0xe0, 0x11, 0xce, 0xd4, 0x6d, 0x99, 0x28, 0xa4, 0xb2, 0xd2, 0x2e, 0x20, 0xf6});
}
diff --git a/test/recovery_test.cc b/test/recovery_test.cc
index 327c248a..6eb48259 100644
--- a/test/recovery_test.cc
+++ b/test/recovery_test.cc
@@ -43,6 +43,7 @@
using std::make_shared;
using std::shared_ptr;
using std::string;
+using std::vector;
/** Check that recovery from a partially-written MXF works */
@@ -58,10 +59,11 @@ BOOST_AUTO_TEST_CASE (recovery)
auto mp = make_shared<dcp::MonoJ2KPictureAsset>(dcp::Fraction (24, 1), dcp::Standard::SMPTE);
auto writer = mp->start_write("build/test/baz/video1.mxf", dcp::Behaviour::MAKE_NEW);
+ auto ref = vector<uint8_t>{0xc3, 0xc9, 0xa3, 0xad, 0xec, 0x09, 0xba, 0xf2, 0xb0, 0xbc, 0xb6, 0x58, 0x06, 0xfb, 0xea, 0xc8};
uint64_t written_size = 0;
for (int i = 0; i < 24; ++i) {
auto info = writer->write (data.data(), data.size());
- BOOST_CHECK_EQUAL (info.hash, "c3c9a3adec09baf2b0bcb65806fbeac8");
+ BOOST_CHECK(info.hash == ref);
written_size = info.size;
}
@@ -88,7 +90,7 @@ BOOST_AUTO_TEST_CASE (recovery)
writer->write (data.data(), data.size());
for (int i = 1; i < 4; ++i) {
- writer->fake_write(dcp::J2KFrameInfo{0, written_size, "xxx"});
+ writer->fake_write(dcp::J2KFrameInfo{0, written_size, vector<uint8_t>{0x42, 0x42, 0x42}});
}
for (int i = 4; i < 24; ++i) {