#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;
* @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)
/* 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);
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)));
}
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 << " "
<< 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) {
/* 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;
}
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.
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)