summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-11-30 00:05:34 +0000
committerCarl Hetherington <cth@carlh.net>2015-12-04 21:14:06 +0000
commit6c19b21e12f73ce63edd406ea617ff25bcc9bfea (patch)
treea671b7fd9913abef6eda535ed2551328a078cbcc /src
parentb1991796d6a4cbed8f8e1378bedbf7ecbf9647a2 (diff)
Use libdcp's compress_j2k; move Data into libdcp.
Diffstat (limited to 'src')
-rw-r--r--src/lib/data.cc88
-rw-r--r--src/lib/data.h53
-rw-r--r--src/lib/dcp_video.cc116
-rw-r--r--src/lib/dcp_video.h6
-rw-r--r--src/lib/emailer.cc2
-rw-r--r--src/lib/encoder.cc2
-rw-r--r--src/lib/j2k_image_proxy.cc3
-rw-r--r--src/lib/j2k_image_proxy.h10
-rw-r--r--src/lib/player_video.cc1
-rw-r--r--src/lib/player_video.h3
-rw-r--r--src/lib/reel_writer.cc1
-rw-r--r--src/lib/reel_writer.h5
-rw-r--r--src/lib/server.cc2
-rw-r--r--src/lib/subrip.cc2
-rw-r--r--src/lib/writer.cc2
-rw-r--r--src/lib/writer.h10
-rw-r--r--src/lib/wscript1
-rw-r--r--src/tools/server_test.cc2
18 files changed, 35 insertions, 274 deletions
diff --git a/src/lib/data.cc b/src/lib/data.cc
deleted file mode 100644
index eb3ec4c63..000000000
--- a/src/lib/data.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- 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 <cstdio>
-
-#include "i18n.h"
-
-using boost::shared_array;
-
-Data::Data ()
- : _size (0)
-{
-
-}
-
-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);
-}
diff --git a/src/lib/data.h b/src/lib/data.h
deleted file mode 100644
index 14658ad4a..000000000
--- a/src/lib/data.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- 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.
-
-*/
-
-#ifndef DCPOMATIC_DATA_H
-#define DCPOMATIC_DATA_H
-
-#include <boost/shared_array.hpp>
-#include <boost/filesystem.hpp>
-#include <stdint.h>
-
-class Data
-{
-public:
- Data ();
- 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;
-};
-
-#endif
diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc
index 91a47a017..9861e5a1a 100644
--- a/src/lib/dcp_video.cc
+++ b/src/lib/dcp_video.cc
@@ -38,11 +38,11 @@
#include "cross.h"
#include "player_video.h"
#include "raw_convert.h"
-#include "data.h"
#include "compose.hpp"
#include <libcxml/cxml.h>
#include <dcp/openjpeg_image.h>
#include <dcp/rgb_xyz.h>
+#include <dcp/j2k.h>
#include <dcp/colour_matrix.h>
#include <openjpeg.h>
#include <libxml++/libxml++.h>
@@ -62,6 +62,7 @@ using std::string;
using std::cout;
using boost::shared_ptr;
using dcp::Size;
+using dcp::Data;
#define DCI_COEFFICENT (48.0 / 52.37)
@@ -123,106 +124,13 @@ DCPVideo::encode_locally (dcp::NoteHandler note)
{
shared_ptr<dcp::OpenJPEGImage> xyz = convert_to_xyz (_frame, note);
- /* Set the max image and component sizes based on frame_rate */
- int max_cs_len = ((float) _j2k_bandwidth) / 8 / _frames_per_second;
- if (_frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT) {
- /* In 3D we have only half the normal bandwidth per eye */
- max_cs_len /= 2;
- }
- int const max_comp_size = max_cs_len / 1.25;
-
- /* get a J2K compressor handle */
- opj_cinfo_t* cinfo = opj_create_compress (CODEC_J2K);
- if (cinfo == 0) {
- throw EncodeError (N_("could not create JPEG2000 encoder"));
- }
-
- /* Set encoding parameters to default values */
- opj_cparameters_t parameters;
- opj_set_default_encoder_parameters (&parameters);
-
- /* Set default cinema parameters */
- parameters.tile_size_on = false;
- parameters.cp_tdx = 1;
- parameters.cp_tdy = 1;
-
- /* Tile part */
- parameters.tp_flag = 'C';
- parameters.tp_on = 1;
-
- /* Tile and Image shall be at (0,0) */
- parameters.cp_tx0 = 0;
- parameters.cp_ty0 = 0;
- parameters.image_offset_x0 = 0;
- parameters.image_offset_y0 = 0;
-
- /* Codeblock size = 32x32 */
- parameters.cblockw_init = 32;
- parameters.cblockh_init = 32;
- parameters.csty |= 0x01;
-
- /* The progression order shall be CPRL */
- parameters.prog_order = CPRL;
-
- /* No ROI */
- parameters.roi_compno = -1;
-
- parameters.subsampling_dx = 1;
- parameters.subsampling_dy = 1;
-
- /* 9-7 transform */
- parameters.irreversible = 1;
-
- parameters.tcp_rates[0] = 0;
- parameters.tcp_numlayers++;
- parameters.cp_disto_alloc = 1;
- parameters.cp_rsiz = _resolution == RESOLUTION_2K ? CINEMA2K : CINEMA4K;
- if (_resolution == RESOLUTION_4K) {
- parameters.numpocs = 2;
- parameters.POC[0].tile = 1;
- parameters.POC[0].resno0 = 0;
- parameters.POC[0].compno0 = 0;
- parameters.POC[0].layno1 = 1;
- parameters.POC[0].resno1 = parameters.numresolution - 1;
- parameters.POC[0].compno1 = 3;
- parameters.POC[0].prg1 = CPRL;
- parameters.POC[1].tile = 1;
- parameters.POC[1].resno0 = parameters.numresolution - 1;
- parameters.POC[1].compno0 = 0;
- parameters.POC[1].layno1 = 1;
- parameters.POC[1].resno1 = parameters.numresolution;
- parameters.POC[1].compno1 = 3;
- parameters.POC[1].prg1 = CPRL;
- }
-
- parameters.cp_comment = strdup (N_("DCP-o-matic"));
- parameters.cp_cinema = _resolution == RESOLUTION_2K ? CINEMA2K_24 : CINEMA4K_24;
-
- /* 3 components, so use MCT */
- parameters.tcp_mct = 1;
-
- /* set max image */
- parameters.max_comp_size = max_comp_size;
- parameters.tcp_rates[0] = ((float) (3 * xyz->size().width * xyz->size().height * 12)) / (max_cs_len * 8);
-
- /* Set event manager to null (openjpeg 1.3 bug) */
- cinfo->event_mgr = 0;
-
- /* Setup the encoder parameters using the current image and user parameters */
- opj_setup_encoder (cinfo, &parameters, xyz->opj_image ());
-
- opj_cio_t* cio = opj_cio_open ((opj_common_ptr) cinfo, 0, 0);
- if (cio == 0) {
- opj_destroy_compress (cinfo);
- throw EncodeError (N_("could not open JPEG2000 stream"));
- }
-
- int const r = opj_encode (cinfo, cio, xyz->opj_image(), 0);
- if (r == 0) {
- opj_cio_close (cio);
- opj_destroy_compress (cinfo);
- throw EncodeError (N_("JPEG2000 encoding failed"));
- }
+ Data enc = compress_j2k (
+ convert_to_xyz (_frame, note),
+ _j2k_bandwidth,
+ _frames_per_second,
+ _frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT,
+ _resolution == RESOLUTION_4K
+ );
switch (_frame->eyes()) {
case EYES_BOTH:
@@ -238,12 +146,6 @@ DCPVideo::encode_locally (dcp::NoteHandler note)
break;
}
- Data enc (cio->buffer, cio_tell (cio));
-
- opj_cio_close (cio);
- free (parameters.cp_comment);
- opj_destroy_compress (cinfo);
-
return enc;
}
diff --git a/src/lib/dcp_video.h b/src/lib/dcp_video.h
index cb38cd542..995ceb547 100644
--- a/src/lib/dcp_video.h
+++ b/src/lib/dcp_video.h
@@ -19,9 +19,9 @@
*/
#include "types.h"
-#include "data.h"
#include "server_description.h"
#include <libcxml/cxml.h>
+#include <dcp/data.h>
/** @file src/dcp_video_frame.h
* @brief A single frame of video destined for a DCP.
@@ -45,8 +45,8 @@ public:
DCPVideo (boost::shared_ptr<const PlayerVideo>, int, int, int, Resolution, boost::shared_ptr<Log>);
DCPVideo (boost::shared_ptr<const PlayerVideo>, cxml::ConstNodePtr, boost::shared_ptr<Log>);
- Data encode_locally (dcp::NoteHandler note);
- Data encode_remotely (ServerDescription);
+ dcp::Data encode_locally (dcp::NoteHandler note);
+ dcp::Data encode_remotely (ServerDescription);
int index () const {
return _index;
diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc
index c7f1b9053..78cbfea8d 100644
--- a/src/lib/emailer.cc
+++ b/src/lib/emailer.cc
@@ -18,7 +18,6 @@
*/
#include "compose.hpp"
-#include "data.h"
#include "config.h"
#include "emailer.h"
#include "exceptions.h"
@@ -35,6 +34,7 @@ using std::list;
using std::cout;
using std::pair;
using boost::shared_ptr;
+using dcp::Data;
Emailer::Emailer (string from, list<string> to, string subject, string body)
: _from (from)
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index f48da1d3a..b03a2ce6a 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -33,7 +33,6 @@
#include "server_finder.h"
#include "player.h"
#include "player_video.h"
-#include "data.h"
#include "server_description.h"
#include "compose.hpp"
#include <libcxml/cxml.h>
@@ -52,6 +51,7 @@ using std::cout;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::optional;
+using dcp::Data;
int const Encoder::_history_size = 25;
diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc
index 35073201c..f2434b23d 100644
--- a/src/lib/j2k_image_proxy.cc
+++ b/src/lib/j2k_image_proxy.cc
@@ -20,13 +20,13 @@
#include "j2k_image_proxy.h"
#include "dcpomatic_socket.h"
#include "image.h"
-#include "data.h"
#include "raw_convert.h"
#include <dcp/openjpeg_image.h>
#include <dcp/mono_picture_frame.h>
#include <dcp/stereo_picture_frame.h>
#include <dcp/colour_conversion.h>
#include <dcp/rgb_xyz.h>
+#include <dcp/j2k.h>
#include <libcxml/cxml.h>
#include <openjpeg.h>
#include <libxml++/libxml++.h>
@@ -39,6 +39,7 @@ using std::cout;
using boost::shared_ptr;
using boost::optional;
using boost::dynamic_pointer_cast;
+using dcp::Data;
/** Construct a J2KImageProxy from a JPEG2000 file */
J2KImageProxy::J2KImageProxy (boost::filesystem::path path, dcp::Size size)
diff --git a/src/lib/j2k_image_proxy.h b/src/lib/j2k_image_proxy.h
index 1d34e7f84..9fc96a543 100644
--- a/src/lib/j2k_image_proxy.h
+++ b/src/lib/j2k_image_proxy.h
@@ -18,16 +18,14 @@
*/
#include "image_proxy.h"
-#include "data.h"
#include <dcp/util.h>
namespace dcp {
class MonoPictureFrame;
class StereoPictureFrame;
+ class Data;
}
-class Data;
-
class J2KImageProxy : public ImageProxy
{
public:
@@ -43,7 +41,7 @@ public:
bool same (boost::shared_ptr<const ImageProxy>) const;
AVPixelFormat pixel_format () const;
- Data j2k () const {
+ dcp::Data j2k () const {
return _data;
}
@@ -55,10 +53,10 @@ private:
friend struct client_server_test_j2k;
/* For tests */
- J2KImageProxy (Data data, dcp::Size size);
+ J2KImageProxy (dcp::Data data, dcp::Size size);
void ensure_j2k () const;
- Data _data;
+ dcp::Data _data;
dcp::Size _size;
boost::optional<dcp::Eye> _eye;
mutable boost::shared_ptr<dcp::OpenJPEGImage> _j2k;
diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc
index 9cdc6c564..ba4503d8e 100644
--- a/src/lib/player_video.cc
+++ b/src/lib/player_video.cc
@@ -34,6 +34,7 @@ using std::cout;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
using boost::optional;
+using dcp::Data;
PlayerVideo::PlayerVideo (
shared_ptr<const ImageProxy> in,
diff --git a/src/lib/player_video.h b/src/lib/player_video.h
index 2a471584b..01b1c74f5 100644
--- a/src/lib/player_video.h
+++ b/src/lib/player_video.h
@@ -22,7 +22,6 @@
#include "dcpomatic_time.h"
#include "colour_conversion.h"
#include "position_image.h"
-#include "data.h"
extern "C" {
#include <libavutil/pixfmt.h>
}
@@ -61,7 +60,7 @@ public:
void send_binary (boost::shared_ptr<Socket> socket) const;
bool has_j2k () const;
- Data j2k () const;
+ dcp::Data j2k () const;
DCPTime time () const {
return _time;
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc
index d9870ec6f..b26ff8064 100644
--- a/src/lib/reel_writer.cc
+++ b/src/lib/reel_writer.cc
@@ -54,6 +54,7 @@ using std::string;
using boost::shared_ptr;
using boost::optional;
using boost::dynamic_pointer_cast;
+using dcp::Data;
int const ReelWriter::_info_size = 48;
diff --git a/src/lib/reel_writer.h b/src/lib/reel_writer.h
index 3adaaf477..64b62fe22 100644
--- a/src/lib/reel_writer.h
+++ b/src/lib/reel_writer.h
@@ -18,7 +18,6 @@
*/
#include "types.h"
-#include "data.h"
#include "dcpomatic_time.h"
#include "referenced_reel_asset.h"
#include "player_subtitles.h"
@@ -49,7 +48,7 @@ class ReelWriter
public:
ReelWriter (boost::shared_ptr<const Film> film, DCPTimePeriod period, boost::shared_ptr<Job> job);
- void write (boost::optional<Data> encoded, Frame frame, Eyes eyes);
+ void write (boost::optional<dcp::Data> encoded, Frame frame, Eyes eyes);
void fake_write (Frame frame, Eyes eyes, int size);
void repeat_write (Frame frame, Eyes eyes);
void write (boost::shared_ptr<const AudioBuffers> audio);
@@ -95,7 +94,7 @@ private:
/** the first frame index that does not already exist in our MXF */
int _first_nonexistant_frame;
/** the data of the last written frame, if there is one */
- boost::optional<Data> _last_written[EYES_COUNT];
+ boost::optional<dcp::Data> _last_written[EYES_COUNT];
/** the index of the last written video frame within the reel */
int _last_written_video_frame;
Eyes _last_written_eyes;
diff --git a/src/lib/server.cc b/src/lib/server.cc
index 5d85d8800..8399421b5 100644
--- a/src/lib/server.cc
+++ b/src/lib/server.cc
@@ -30,7 +30,6 @@
#include "config.h"
#include "cross.h"
#include "player_video.h"
-#include "data.h"
#include "safe_stringstream.h"
#include "raw_convert.h"
#include "compose.hpp"
@@ -64,6 +63,7 @@ using boost::bind;
using boost::scoped_array;
using boost::optional;
using dcp::Size;
+using dcp::Data;
Server::Server (shared_ptr<Log> log, bool verbose)
: _terminate (false)
diff --git a/src/lib/subrip.cc b/src/lib/subrip.cc
index a707d1f9f..c4166cb28 100644
--- a/src/lib/subrip.cc
+++ b/src/lib/subrip.cc
@@ -21,7 +21,6 @@
#include "cross.h"
#include "exceptions.h"
#include "subrip_content.h"
-#include "data.h"
#include <sub/subrip_reader.h>
#include <sub/collect.h>
#include <unicode/ucsdet.h>
@@ -35,6 +34,7 @@ using std::cout;
using std::string;
using boost::shared_ptr;
using boost::scoped_array;
+using dcp::Data;
SubRip::SubRip (shared_ptr<const SubRipContent> content)
{
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 7381d2a90..2a9b6d6d7 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -30,7 +30,6 @@
#include "cross.h"
#include "audio_buffers.h"
#include "md5_digester.h"
-#include "data.h"
#include "version.h"
#include "font.h"
#include "util.h"
@@ -62,6 +61,7 @@ using std::cout;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::dynamic_pointer_cast;
+using dcp::Data;
Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
: _film (film)
diff --git a/src/lib/writer.h b/src/lib/writer.h
index 5c974f0f3..0e17f998d 100644
--- a/src/lib/writer.h
+++ b/src/lib/writer.h
@@ -23,7 +23,6 @@
#include "types.h"
#include "player_subtitles.h"
-#include "data.h"
#include "exception_store.h"
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
@@ -31,8 +30,11 @@
#include <boost/thread/condition.hpp>
#include <list>
+namespace dcp {
+ class Data;
+}
+
class Film;
-class Data;
class AudioBuffers;
class Job;
class Font;
@@ -58,7 +60,7 @@ public:
} type;
/** encoded data for FULL */
- boost::optional<Data> encoded;
+ boost::optional<dcp::Data> encoded;
/** size of data for FAKE */
int size;
/** reel index */
@@ -93,7 +95,7 @@ public:
bool can_fake_write (Frame) const;
- void write (Data, Frame, Eyes);
+ void write (dcp::Data, Frame, Eyes);
void fake_write (Frame, Eyes);
bool can_repeat (Frame) const;
void repeat (Frame, Eyes);
diff --git a/src/lib/wscript b/src/lib/wscript
index a76ca9b74..2e9e641a3 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -42,7 +42,6 @@ sources = """
content_factory.cc
cross.cc
curl_uploader.cc
- data.cc
dcp_content.cc
dcp_content_type.cc
dcp_decoder.cc
diff --git a/src/tools/server_test.cc b/src/tools/server_test.cc
index 9e9a01694..fdfceb567 100644
--- a/src/tools/server_test.cc
+++ b/src/tools/server_test.cc
@@ -29,7 +29,6 @@
#include "lib/video_decoder.h"
#include "lib/player.h"
#include "lib/player_video.h"
-#include "lib/data.h"
#include "lib/server_description.h"
#include <getopt.h>
#include <iostream>
@@ -41,6 +40,7 @@ using std::cerr;
using std::string;
using std::pair;
using boost::shared_ptr;
+using dcp::Data;
static shared_ptr<Film> film;
static ServerDescription* server;