Subs successfully exported with thumbs.
[dcpomatic.git] / src / lib / dcp_video_frame.cc
index d8af3462d681b477bbd7859c5c618395e4a133e7..13d3efcbf2c4c93ff0e5e32068f163ef2aaaf690 100644 (file)
@@ -36,6 +36,7 @@
 #include <iomanip>
 #include <sstream>
 #include <iostream>
+#include <fstream>
 #include <unistd.h>
 #include <errno.h>
 #include <boost/array.hpp>
 #include "image.h"
 #include "log.h"
 
-#ifdef DEBUG_HASH
-#include <mhash.h>
-#endif
-
 using namespace std;
 using namespace boost;
 
@@ -75,8 +72,9 @@ using namespace boost;
  *  @param l Log to write to.
  */
 DCPVideoFrame::DCPVideoFrame (
-       shared_ptr<Image> yuv, Size out, int p, Scaler const * s, int f, float fps, string pp, int clut, int bw, Log* l)
+       shared_ptr<Image> yuv, shared_ptr<Subtitle> sub, Size out, int p, Scaler const * s, int f, float fps, string pp, int clut, int bw, Log* l)
        : _input (yuv)
+       , _subtitle (sub)
        , _out_size (out)
        , _padding (p)
        , _scaler (s)
@@ -255,12 +253,6 @@ DCPVideoFrame::encode_locally ()
        /* Set event manager to null (openjpeg 1.3 bug) */
        _cinfo->event_mgr = 0;
 
-#ifdef DEBUG_HASH
-       md5_data ("J2K in X frame " + lexical_cast<string> (_frame), _image->comps[0].data, size * sizeof (int));
-       md5_data ("J2K in Y frame " + lexical_cast<string> (_frame), _image->comps[1].data, size * sizeof (int));
-       md5_data ("J2K in Z frame " + lexical_cast<string> (_frame), _image->comps[2].data, size * sizeof (int));
-#endif 
-       
        /* Setup the encoder parameters using the current image and user parameters */
        opj_setup_encoder (_cinfo, _parameters, _image);
 
@@ -271,15 +263,7 @@ DCPVideoFrame::encode_locally ()
                throw EncodeError ("jpeg2000 encoding failed");
        }
 
-#ifdef DEBUG_HASH
-       md5_data ("J2K out frame " + lexical_cast<string> (_frame), _cio->buffer, cio_tell (_cio));
-#endif 
-
-       {
-               stringstream s;
-               s << "Finished locally-encoded frame " << _frame;
-               _log->log (s.str ());
-       }
+       _log->log (String::compose ("Finished locally-encoded frame %1", _frame));
        
        return shared_ptr<EncodedData> (new LocallyEncodedData (_cio->buffer, cio_tell (_cio)));
 }
@@ -300,10 +284,6 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
 
        socket.connect (*endpoint_iterator, 30);
 
-#ifdef DEBUG_HASH
-       _input->hash ("Input for remote encoding (before sending)");
-#endif
-
        stringstream s;
        s << "encode "
          << _input->size().width << " " << _input->size().height << " "
@@ -317,10 +297,6 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
          << Config::instance()->colour_lut_index () << " "
          << Config::instance()->j2k_bandwidth () << " ";
 
-       for (int i = 0; i < _input->components(); ++i) {
-               s << _input->line_size()[i] << " ";
-       }
-
        socket.write ((uint8_t *) s.str().c_str(), s.str().length() + 1, 30);
 
        for (int i = 0; i < _input->components(); ++i) {
@@ -335,15 +311,7 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
        /* now read the rest */
        socket.read_definite_and_consume (e->data(), e->size(), 30);
 
-#ifdef DEBUG_HASH
-       e->hash ("Encoded image (after receiving)");
-#endif
-
-       {
-               stringstream s;
-               s << "Finished remotely-encoded frame " << _frame;
-               _log->log (s.str ());
-       }
+       _log->log (String::compose ("Finished remotely-encoded frame %1", _frame));
        
        return e;
 }
@@ -366,8 +334,16 @@ EncodedData::write (shared_ptr<const Options> opt, int frame)
        fwrite (_data, 1, _size, f);
        fclose (f);
 
+       string const real_j2k = opt->frame_out_path (frame, false);
+
        /* Rename the file from foo.j2c.tmp to foo.j2c now that it is complete */
-       filesystem::rename (tmp_j2k, opt->frame_out_path (frame, false));
+       filesystem::rename (tmp_j2k, real_j2k);
+
+       /* Write a file containing the hash */
+       string const hash = real_j2k + ".md5";
+       ofstream h (hash.c_str());
+       h << md5_digest (_data, _size) << "\n";
+       h.close ();
 }
 
 /** Send this data to a socket.
@@ -382,14 +358,6 @@ EncodedData::send (shared_ptr<Socket> socket)
        socket->write (_data, _size, 30);
 }
 
-#ifdef DEBUG_HASH
-void
-EncodedData::hash (string n) const
-{
-       md5_data (n, _data, _size);
-}
-#endif         
-
 /** @param s Size of data in bytes */
 RemotelyEncodedData::RemotelyEncodedData (int s)
        : EncodedData (new uint8_t[s], s)