diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-01-28 18:43:27 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-01-28 18:43:27 +0000 |
| commit | 8e7d91ac8b945d66a65fc7b20249cd1c7796c7fa (patch) | |
| tree | 8cab651afa0d57b99978e1ff472f5d19de4c0ec8 | |
| parent | b1873c51b2e8265a01a8f0eced7fc3465f1677dc (diff) | |
Write more extensive information about frames, and hash the MXF packet rather than the J2K data.
| -rw-r--r-- | src/lib/dcp_video_frame.cc | 8 | ||||
| -rw-r--r-- | src/lib/dcp_video_frame.h | 3 | ||||
| -rw-r--r-- | src/lib/film.cc | 12 | ||||
| -rw-r--r-- | src/lib/film.h | 4 | ||||
| -rw-r--r-- | src/lib/writer.cc | 36 |
5 files changed, 37 insertions, 26 deletions
diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc index 5df2d7a46..4f3fda44a 100644 --- a/src/lib/dcp_video_frame.cc +++ b/src/lib/dcp_video_frame.cc @@ -425,11 +425,11 @@ EncodedData::write (shared_ptr<const Film> film, int frame) const } void -EncodedData::write_hash (shared_ptr<const Film> film, int frame) const +EncodedData::write_info (shared_ptr<const Film> film, int frame, libdcp::FrameInfo fin) const { - string const hash = film->hash_path (frame); - ofstream h (hash.c_str()); - h << md5_digest (_data, _size) << "\n"; + string const info = film->info_path (frame); + ofstream h (info.c_str()); + fin.write (h); } /** Send this data to a socket. diff --git a/src/lib/dcp_video_frame.h b/src/lib/dcp_video_frame.h index e988b663a..be8a559b2 100644 --- a/src/lib/dcp_video_frame.h +++ b/src/lib/dcp_video_frame.h @@ -19,6 +19,7 @@ */ #include <openjpeg.h> +#include <libdcp/picture_asset.h> #include "util.h" /** @file src/dcp_video_frame.h @@ -48,7 +49,7 @@ public: void send (boost::shared_ptr<Socket> socket); void write (boost::shared_ptr<const Film>, int) const; - void write_hash (boost::shared_ptr<const Film>, int) const; + void write_info (boost::shared_ptr<const Film>, int, libdcp::FrameInfo) const; /** @return data */ uint8_t* data () const { diff --git a/src/lib/film.cc b/src/lib/film.cc index bdc4cca73..e7ea77023 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -213,12 +213,12 @@ Film::video_state_identifier () const return s.str (); } -/** @return The path to the directory to write video frame hash files to */ +/** @return The path to the directory to write video frame info files to */ string -Film::hash_dir () const +Film::info_dir () const { boost::filesystem::path p; - p /= "hash"; + p /= "info"; p /= video_state_identifier (); return dir (p.string()); } @@ -344,7 +344,7 @@ Film::encoded_frames () const } int N = 0; - for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (hash_dir ()); i != boost::filesystem::directory_iterator(); ++i) { + for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) { ++N; boost::this_thread::interruption_point (); } @@ -1315,10 +1315,10 @@ Film::audio_stream () const } string -Film::hash_path (int f) const +Film::info_path (int f) const { boost::filesystem::path p; - p /= hash_dir (); + p /= info_dir (); stringstream s; s.width (8); diff --git a/src/lib/film.h b/src/lib/film.h index 7c4c72f7b..5b65a099d 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -60,9 +60,9 @@ public: Film (Film const &); ~Film (); - std::string hash_dir () const; + std::string info_dir () const; std::string j2c_path (int f, bool t) const; - std::string hash_path (int f) const; + std::string info_path (int f) const; std::string video_mxf_dir () const; std::string video_mxf_filename () const; diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 3ec88860a..7f338e238 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -136,12 +136,12 @@ Writer::thread () lock.unlock (); _film->log()->log (String::compose ("Writer writes %1 to MXF", encoded.second)); if (encoded.first) { - _picture_asset_writer->write (encoded.first->data(), encoded.first->size()); - encoded.first->write_hash (_film, encoded.second); + libdcp::FrameInfo const fin = _picture_asset_writer->write (encoded.first->data(), encoded.first->size()); + encoded.first->write_info (_film, encoded.second, fin); _last_written = encoded.first; } else { - _picture_asset_writer->write (_last_written->data(), _last_written->size()); - _last_written->write_hash (_film, encoded.second); + libdcp::FrameInfo const fin = _picture_asset_writer->write (_last_written->data(), _last_written->size()); + _last_written->write_info (_film, encoded.second, fin); } lock.lock (); @@ -279,18 +279,26 @@ Writer::check_existing_picture_mxf () return; } - libdcp::MonoPictureAsset existing (_film->video_mxf_dir(), _film->video_mxf_filename()); + /* Try to open the picture MXF */ + FILE* mxf = fopen (p.string().c_str(), "rb"); + if (!mxf) { + return; + } - while (_first_nonexistant_frame < existing.intrinsic_duration()) { + while (_first_nonexistant_frame < _film->dcp_intrinsic_duration ()) { - shared_ptr<const libdcp::MonoPictureFrame> f = existing.get_frame (_first_nonexistant_frame); - string const existing_hash = md5_digest (f->j2k_data(), f->j2k_size()); - - ifstream hf (_film->hash_path (_first_nonexistant_frame).c_str ()); - string reference_hash; - hf >> reference_hash; + /* Read the frame info as written */ + ifstream ifi (_film->info_path (_first_nonexistant_frame).c_str()); + libdcp::FrameInfo info (ifi); - if (existing_hash != reference_hash) { + /* Read the data from the MXF and hash it */ + fseek (mxf, info.offset, SEEK_SET); + uint8_t* data = new uint8_t[info.length]; + fread (data, 1, info.length, mxf); + string const existing_hash = md5_digest (data, info.length); + delete[] data; + + if (existing_hash != info.hash) { cout << "frame " << _first_nonexistant_frame << " failed hash check.\n"; break; } @@ -298,5 +306,7 @@ Writer::check_existing_picture_mxf () cout << "frame " << _first_nonexistant_frame << " ok.\n"; ++_first_nonexistant_frame; } + + fclose (mxf); } |
