--- /dev/null
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "data.h"
+#include "cross.h"
+#include "exceptions.h"
+
+#include "i18n.h"
+
+using boost::shared_array;
+
+Data::Data (int size)
+ : _data (new uint8_t[size])
+ , _size (size)
+{
+
+}
+
+Data::Data (uint8_t const * data, int size)
+ : _data (new uint8_t[size])
+ , _size (size)
+{
+ memcpy (_data.get(), data, size);
+}
+
+Data::Data (boost::filesystem::path file)
+{
+ _size = boost::filesystem::file_size (file);
+ _data.reset (new uint8_t[_size]);
+
+ FILE* f = fopen_boost (file, "rb");
+ if (!f) {
+ throw FileError (_("could not open file for reading"), file);
+ }
+
+ size_t const r = fread (_data.get(), 1, _size, f);
+ if (r != size_t (_size)) {
+ fclose (f);
+ throw FileError (_("could not read from file"), file);
+ }
+
+ fclose (f);
+}
+
+void
+Data::write (boost::filesystem::path file) const
+{
+ FILE* f = fopen_boost (file, "wb");
+ if (!f) {
+ throw WriteFileError (file, errno);
+ }
+ size_t const r = fwrite (_data.get(), 1, _size, f);
+ if (r != size_t (_size)) {
+ fclose (f);
+ throw FileError ("could not write to file", file);
+ }
+ fclose (f);
+}
+
+void
+Data::write_via_temp (boost::filesystem::path temp, boost::filesystem::path final) const
+{
+ write (temp);
+ boost::filesystem::rename (temp, final);
+}
--- /dev/null
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/shared_array.hpp>
+#include <boost/filesystem.hpp>
+#include <stdint.h>
+
+class Data
+{
+public:
+ Data (int size);
+ Data (uint8_t const * data, int size);
+ Data (boost::filesystem::path file);
+
+ virtual ~Data () {}
+
+ void write (boost::filesystem::path file) const;
+ void write_via_temp (boost::filesystem::path temp, boost::filesystem::path final) const;
+
+ boost::shared_array<uint8_t> data () const {
+ return _data;
+ }
+
+ int size () const {
+ return _size;
+ }
+
+private:
+ boost::shared_array<uint8_t> _data;
+ int _size;
+};
#include "cross.h"
#include "player_video.h"
#include "raw_convert.h"
-#include "encoded_data.h"
+#include "data.h"
#include <libcxml/cxml.h>
#include <dcp/xyz_image.h>
#include <dcp/rgb_xyz.h>
/** J2K-encode this frame on the local host.
* @return Encoded data.
*/
-shared_ptr<EncodedData>
+shared_ptr<Data>
DCPVideo::encode_locally (dcp::NoteHandler note)
{
shared_ptr<dcp::XYZImage> xyz;
break;
}
- shared_ptr<EncodedData> enc (new LocallyEncodedData (cio->buffer, cio_tell (cio)));
+ shared_ptr<Data> enc (new Data (cio->buffer, cio_tell (cio)));
opj_cio_close (cio);
free (parameters.cp_comment);
* @param serv Server to send to.
* @return Encoded data.
*/
-shared_ptr<EncodedData>
+shared_ptr<Data>
DCPVideo::encode_remotely (ServerDescription serv)
{
boost::asio::io_service io_service;
/* Read the response (JPEG2000-encoded data); this blocks until the data
is ready and sent back.
*/
- shared_ptr<EncodedData> e (new RemotelyEncodedData (socket->read_uint32 ()));
- socket->read (e->data(), e->size());
+ shared_ptr<Data> e (new Data (socket->read_uint32 ()));
+ socket->read (e->data().get(), e->size());
LOG_GENERAL (N_("Finished remotely-encoded frame %1"), _index);
class Log;
class Subtitle;
class PlayerVideo;
-class EncodedData;
+class Data;
/** @class DCPVideo
* @brief A single frame of video destined for a DCP.
DCPVideo (boost::shared_ptr<const PlayerVideo>, int, int, int, Resolution, bool b, boost::shared_ptr<Log>);
DCPVideo (boost::shared_ptr<const PlayerVideo>, cxml::ConstNodePtr, boost::shared_ptr<Log>);
- boost::shared_ptr<EncodedData> encode_locally (dcp::NoteHandler note);
- boost::shared_ptr<EncodedData> encode_remotely (ServerDescription);
+ boost::shared_ptr<Data> encode_locally (dcp::NoteHandler note);
+ boost::shared_ptr<Data> encode_remotely (ServerDescription);
int index () const {
return _index;
+++ /dev/null
-/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include "encoded_data.h"
-#include "cross.h"
-#include "exceptions.h"
-#include "film.h"
-#include "dcpomatic_socket.h"
-
-#include "i18n.h"
-
-using boost::shared_ptr;
-
-EncodedData::EncodedData (int s)
- : _data (new uint8_t[s])
- , _size (s)
-{
-
-}
-
-EncodedData::EncodedData (uint8_t const * d, int s)
- : _data (new uint8_t[s])
- , _size (s)
-{
- memcpy (_data, d, s);
-}
-
-EncodedData::EncodedData (boost::filesystem::path file)
-{
- _size = boost::filesystem::file_size (file);
- _data = new uint8_t[_size];
-
- FILE* f = fopen_boost (file, "rb");
- if (!f) {
- throw FileError (_("could not open file for reading"), file);
- }
-
- size_t const r = fread (_data, 1, _size, f);
- if (r != size_t (_size)) {
- fclose (f);
- throw FileError (_("could not read encoded data"), file);
- }
-
- fclose (f);
-}
-
-
-EncodedData::~EncodedData ()
-{
- delete[] _data;
-}
-
-/** Write this data to a J2K file.
- * @param Film Film.
- * @param frame DCP frame index.
- */
-void
-EncodedData::write (shared_ptr<const Film> film, int frame, Eyes eyes) const
-{
- boost::filesystem::path const tmp_j2c = film->j2c_path (frame, eyes, true);
-
- FILE* f = fopen_boost (tmp_j2c, "wb");
-
- if (!f) {
- throw WriteFileError (tmp_j2c, errno);
- }
-
- fwrite (_data, 1, _size, f);
- fclose (f);
-
- boost::filesystem::path const real_j2c = film->j2c_path (frame, eyes, false);
-
- /* Rename the file from foo.j2c.tmp to foo.j2c now that it is complete */
- boost::filesystem::rename (tmp_j2c, real_j2c);
-}
-
-void
-EncodedData::write_info (shared_ptr<const Film> film, int frame, Eyes eyes, dcp::FrameInfo info) const
-{
- FILE* file = fopen_boost (film->info_file(), "ab");
- if (!file) {
- throw OpenFileError (film->info_file ());
- }
- write_frame_info (file, frame, eyes, info);
- fclose (file);
-}
-
-/** Send this data to a socket.
- * @param socket Socket
- */
-void
-EncodedData::send (shared_ptr<Socket> socket)
-{
- socket->write (_size);
- socket->write (_data, _size);
-}
-
-LocallyEncodedData::LocallyEncodedData (uint8_t* d, int s)
- : EncodedData (s)
-{
- memcpy (_data, d, s);
-}
-
-/** @param s Size of data in bytes */
-RemotelyEncodedData::RemotelyEncodedData (int s)
- : EncodedData (s)
-{
-
-}
+++ /dev/null
-/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include "types.h"
-#include <dcp/picture_asset_writer.h>
-#include <boost/noncopyable.hpp>
-#include <boost/filesystem.hpp>
-
-class Socket;
-class Film;
-
-/** @class EncodedData
- * @brief Container for J2K-encoded data.
- */
-class EncodedData : public boost::noncopyable
-{
-public:
- /** @param s Size of data, in bytes */
- EncodedData (int s);
- EncodedData (uint8_t const * d, int s);
-
- EncodedData (boost::filesystem::path);
-
- virtual ~EncodedData ();
-
- void send (boost::shared_ptr<Socket> socket);
- void write (boost::shared_ptr<const Film>, int, Eyes) const;
- void write_info (boost::shared_ptr<const Film>, int, Eyes, dcp::FrameInfo) const;
-
- /** @return data */
- uint8_t* data () const {
- return _data;
- }
-
- /** @return data size, in bytes */
- int size () const {
- return _size;
- }
-
-protected:
- uint8_t* _data; ///< data
- int _size; ///< data size in bytes
-};
-
-/** @class LocallyEncodedData
- * @brief EncodedData that was encoded locally; this class
- * just keeps a pointer to the data, but does no memory
- * management.
- */
-class LocallyEncodedData : public EncodedData
-{
-public:
- /** @param d Data (which will be copied by this class)
- * @param s Size of data, in bytes.
- */
- LocallyEncodedData (uint8_t* d, int s);
-};
-
-/** @class RemotelyEncodedData
- * @brief EncodedData that is being read from a remote server;
- * this class allocates and manages memory for the data.
- */
-class RemotelyEncodedData : public EncodedData
-{
-public:
- RemotelyEncodedData (int s);
-};
*/
int remote_backoff = 0;
shared_ptr<DCPVideo> last_dcp_video;
- shared_ptr<EncodedData> last_encoded;
+ shared_ptr<Data> last_encoded;
while (true) {
lock.unlock ();
- shared_ptr<EncodedData> encoded;
+ shared_ptr<Data> encoded;
if (last_dcp_video && vf->same (last_dcp_video)) {
/* We already have encoded data for the same input as this one, so take a short-cut */
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
class Film;
class ServerDescription;
class DCPVideo;
-class EncodedData;
class Writer;
class Job;
-class ServerFinder;
class PlayerVideo;
/** @class Encoder
#include "j2k_image_proxy.h"
#include "dcpomatic_socket.h"
#include "image.h"
-#include "encoded_data.h"
+#include "data.h"
#include "raw_convert.h"
#include <dcp/mono_picture_frame.h>
#include <dcp/stereo_picture_frame.h>
}
}
-shared_ptr<EncodedData>
+shared_ptr<Data>
J2KImageProxy::j2k () const
{
if (_mono) {
- return shared_ptr<EncodedData> (new EncodedData (_mono->j2k_data(), _mono->j2k_size()));
+ return shared_ptr<Data> (new Data (_mono->j2k_data(), _mono->j2k_size()));
} else {
if (_eye.get() == dcp::EYE_LEFT) {
- return shared_ptr<EncodedData> (new EncodedData (_stereo->left_j2k_data(), _stereo->left_j2k_size()));
+ return shared_ptr<Data> (new Data (_stereo->left_j2k_data(), _stereo->left_j2k_size()));
} else {
- return shared_ptr<EncodedData> (new EncodedData (_stereo->right_j2k_data(), _stereo->right_j2k_size()));
+ return shared_ptr<Data> (new Data (_stereo->right_j2k_data(), _stereo->right_j2k_size()));
}
}
}
/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "image_proxy.h"
#include <dcp/util.h>
-class EncodedData;
+class Data;
class J2KImageProxy : public ImageProxy
{
void add_metadata (xmlpp::Node *) const;
void send_binary (boost::shared_ptr<Socket>) const;
- boost::shared_ptr<EncodedData> j2k () const;
+ boost::shared_ptr<Data> j2k () const;
dcp::Size size () const {
return _size;
}
return _crop == Crop () && _inter_size == j2k->size();
}
-shared_ptr<EncodedData>
+shared_ptr<Data>
PlayerVideo::j2k () const
{
shared_ptr<const J2KImageProxy> j2k = dynamic_pointer_cast<const J2KImageProxy> (_in);
class Image;
class ImageProxy;
class Socket;
-class EncodedData;
+class Data;
/** Everything needed to describe a video frame coming out of the player, but with the
* bits still their raw form. We may want to combine the bits on a remote machine,
void send_binary (boost::shared_ptr<Socket> socket, bool send_subtitles) const;
bool has_j2k () const;
- boost::shared_ptr<EncodedData> j2k () const;
+ boost::shared_ptr<Data> j2k () const;
DCPTime time () const {
return _time;
#include "config.h"
#include "cross.h"
#include "player_video.h"
-#include "encoded_data.h"
+#include "data.h"
#include "safe_stringstream.h"
#include "raw_convert.h"
#include <libcxml/cxml.h>
gettimeofday (&after_read, 0);
- shared_ptr<EncodedData> encoded = dcp_video_frame.encode_locally (boost::bind (&Log::dcp_log, _log.get(), _1, _2));
+ shared_ptr<Data> encoded = dcp_video_frame.encode_locally (boost::bind (&Log::dcp_log, _log.get(), _1, _2));
gettimeofday (&after_encode, 0);
try {
- encoded->send (socket);
+ socket->write (encoded->size ());
+ socket->write (encoded->data ().get (), encoded->size ());
} catch (std::exception& e) {
cerr << "Send failed; frame " << dcp_video_frame.index() << "\n";
LOG_ERROR ("Send failed; frame %1", dcp_video_frame.index());
#include "cross.h"
#include "audio_buffers.h"
#include "md5_digester.h"
-#include "encoded_data.h"
+#include "data.h"
#include "version.h"
#include "font.h"
#include "util.h"
}
void
-Writer::write (shared_ptr<const EncodedData> encoded, int frame, Eyes eyes)
+Writer::write (shared_ptr<const Data> encoded, int frame, Eyes eyes)
{
boost::mutex::scoped_lock lock (_mutex);
{
LOG_GENERAL (N_("Writer FULL-writes %1 (%2)"), qi.frame, qi.eyes);
if (!qi.encoded) {
- qi.encoded.reset (new EncodedData (_film->j2c_path (qi.frame, qi.eyes, false)));
+ qi.encoded.reset (new Data (_film->j2c_path (qi.frame, qi.eyes, false)));
}
- dcp::FrameInfo fin = _picture_asset_writer->write (qi.encoded->data(), qi.encoded->size());
- qi.encoded->write_info (_film, qi.frame, qi.eyes, fin);
+ dcp::FrameInfo fin = _picture_asset_writer->write (qi.encoded->data().get (), qi.encoded->size());
+ FILE* file = fopen_boost (_film->info_file(), "ab");
+ if (!file) {
+ throw OpenFileError (_film->info_file ());
+ }
+ write_frame_info (file, qi.frame, qi.eyes, fin);
+ fclose (file);
_last_written[qi.eyes] = qi.encoded;
++_full_written;
break;
_last_written_frame + 1,
_last_written_eyes, i->frame
);
-
- i->encoded->write (_film, i->frame, i->eyes);
+
+ i->encoded->write_via_temp (_film->j2c_path (i->frame, i->eyes, true), _film->j2c_path (i->frame, i->eyes, false));
lock.lock ();
i->encoded.reset ();
/* Read the data from the asset and hash it */
dcpomatic_fseek (asset, info.offset, SEEK_SET);
- EncodedData data (info.size);
- size_t const read = fread (data.data(), 1, data.size(), asset);
+ Data data (info.size);
+ size_t const read = fread (data.data().get(), 1, data.size(), asset);
if (read != static_cast<size_t> (data.size ())) {
LOG_GENERAL ("Existing frame %1 is incomplete", f);
return false;
}
MD5Digester digester;
- digester.add (data.data(), data.size());
+ digester.add (data.data().get(), data.size());
if (digester.get() != info.hash) {
LOG_GENERAL ("Existing frame %1 failed hash check", f);
return false;
#include <list>
class Film;
-class EncodedData;
+class Data;
class AudioBuffers;
class Job;
class Font;
} type;
/** encoded data for FULL */
- boost::shared_ptr<const EncodedData> encoded;
+ boost::shared_ptr<const Data> encoded;
/** size of data for FAKE */
int size;
/** frame index */
/** @class Writer
* @brief Class to manage writing JPEG2000 and audio data to assets on disk.
*
- * This class creates sound and picture assets, then takes EncodedData
+ * This class creates sound and picture assets, then takes Data
* or AudioBuffers objects (containing image or sound data respectively)
* and writes them to the assets.
*
- * ::write() for EncodedData can be called out of order, and the Writer
+ * ::write() for Data can be called out of order, and the Writer
* will sort it out. write() for AudioBuffers must be called in order.
*/
bool can_fake_write (int) const;
- void write (boost::shared_ptr<const EncodedData>, int, Eyes);
+ void write (boost::shared_ptr<const Data>, int, Eyes);
void fake_write (int, Eyes);
void write (boost::shared_ptr<const AudioBuffers>);
void write (PlayerSubtitles subs);
/** condition to manage thread wakeups when we have too much to do */
boost::condition _full_condition;
/** the data of the last written frame, or 0 if there isn't one */
- boost::shared_ptr<const EncodedData> _last_written[EYES_COUNT];
+ boost::shared_ptr<const Data> _last_written[EYES_COUNT];
/** the index of the last written frame */
int _last_written_frame;
Eyes _last_written_eyes;
content_factory.cc
content_subtitle.cc
cross.cc
+ data.cc
dcp_content.cc
dcp_content_type.cc
dcp_decoder.cc
dcpomatic_time.cc
dolby_cp750.cc
encoder.cc
- encoded_data.cc
environment_info.cc
examine_content_job.cc
exceptions.cc
#include "lib/video_decoder.h"
#include "lib/player.h"
#include "lib/player_video.h"
-#include "lib/encoded_data.h"
+#include "lib/data.h"
using std::cout;
using std::cerr;
++frame_count;
- shared_ptr<EncodedData> local_encoded = local->encode_locally (boost::bind (&Log::dcp_log, log_.get(), _1, _2));
- shared_ptr<EncodedData> remote_encoded;
+ shared_ptr<Data> local_encoded = local->encode_locally (boost::bind (&Log::dcp_log, log_.get(), _1, _2));
+ shared_ptr<Data> remote_encoded;
string remote_error;
try {
return;
}
- uint8_t* p = local_encoded->data();
- uint8_t* q = remote_encoded->data();
+ uint8_t* p = local_encoded->data().get ();
+ uint8_t* q = remote_encoded->data().get ();
for (int i = 0; i < local_encoded->size(); ++i) {
if (*p++ != *q++) {
cout << "\033[0;31mdata differ\033[0m at byte " << i << "\n";
#include "lib/dcp_video.h"
#include "lib/player_video.h"
#include "lib/raw_image_proxy.h"
-#include "lib/encoded_data.h"
+#include "lib/data.h"
using std::list;
using boost::shared_ptr;
using boost::optional;
void
-do_remote_encode (shared_ptr<DCPVideo> frame, ServerDescription description, shared_ptr<EncodedData> locally_encoded)
+do_remote_encode (shared_ptr<DCPVideo> frame, ServerDescription description, shared_ptr<Data> locally_encoded)
{
- shared_ptr<EncodedData> remotely_encoded;
+ shared_ptr<Data> remotely_encoded;
BOOST_CHECK_NO_THROW (remotely_encoded = frame->encode_remotely (description));
BOOST_CHECK (remotely_encoded);
BOOST_CHECK_EQUAL (locally_encoded->size(), remotely_encoded->size());
- BOOST_CHECK_EQUAL (memcmp (locally_encoded->data(), remotely_encoded->data(), locally_encoded->size()), 0);
+ BOOST_CHECK_EQUAL (memcmp (locally_encoded->data().get(), remotely_encoded->data().get(), locally_encoded->size()), 0);
}
BOOST_AUTO_TEST_CASE (client_server_test_rgb)
)
);
- shared_ptr<EncodedData> locally_encoded = frame->encode_locally (boost::bind (&Log::dcp_log, log.get(), _1, _2));
+ shared_ptr<Data> locally_encoded = frame->encode_locally (boost::bind (&Log::dcp_log, log.get(), _1, _2));
BOOST_ASSERT (locally_encoded);
Server* server = new Server (log, true);
)
);
- shared_ptr<EncodedData> locally_encoded = frame->encode_locally (boost::bind (&Log::dcp_log, log.get(), _1, _2));
+ shared_ptr<Data> locally_encoded = frame->encode_locally (boost::bind (&Log::dcp_log, log.get(), _1, _2));
BOOST_ASSERT (locally_encoded);
Server* server = new Server (log, true);