Write more extensive information about frames, and hash the MXF packet rather than...
authorCarl Hetherington <cth@carlh.net>
Mon, 28 Jan 2013 18:43:27 +0000 (18:43 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 28 Jan 2013 18:43:27 +0000 (18:43 +0000)
src/lib/dcp_video_frame.cc
src/lib/dcp_video_frame.h
src/lib/film.cc
src/lib/film.h
src/lib/writer.cc

index 5df2d7a46b61b8219467c933671e505f138cd51d..4f3fda44ab759f6645f72f4385bd844a3fb5bde9 100644 (file)
@@ -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.
index e988b663a80493158b552a959d8b8ec09010fea3..be8a559b2464d5da6101d0e5cbc11cebb1bd9581 100644 (file)
@@ -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 {
index bdc4cca734d7075fc58bfaa52b46c2046f368bdd..e7ea770236109b6ea35f00d0d248a67a16138bcb 100644 (file)
@@ -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);
index 7c4c72f7b2689835cc7963b02f80956995c34fc8..5b65a099dc82d760f5f6e342bc6bb19719455bb1 100644 (file)
@@ -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;
 
index 3ec88860a2cb8fda70bcdd2573c7b7c75be2b830..7f338e2382ae308561a8e58c89797548c8ceb375 100644 (file)
@@ -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);
 }