Use libdcp's compress_j2k; move Data into libdcp.
authorCarl Hetherington <cth@carlh.net>
Mon, 30 Nov 2015 00:05:34 +0000 (00:05 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 4 Dec 2015 21:14:06 +0000 (21:14 +0000)
19 files changed:
src/lib/data.cc [deleted file]
src/lib/data.h [deleted file]
src/lib/dcp_video.cc
src/lib/dcp_video.h
src/lib/emailer.cc
src/lib/encoder.cc
src/lib/j2k_image_proxy.cc
src/lib/j2k_image_proxy.h
src/lib/player_video.cc
src/lib/player_video.h
src/lib/reel_writer.cc
src/lib/reel_writer.h
src/lib/server.cc
src/lib/subrip.cc
src/lib/writer.cc
src/lib/writer.h
src/lib/wscript
src/tools/server_test.cc
test/client_server_test.cc

diff --git a/src/lib/data.cc b/src/lib/data.cc
deleted file mode 100644 (file)
index eb3ec4c..0000000
+++ /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 (file)
index 14658ad..0000000
+++ /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
index 91a47a0174128b6ed96a594e0948669ea041b4a7..9861e5a1a94224433863de276f572bafe7de566e 100644 (file)
 #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;
 }
 
index cb38cd542db16471aa2580325ff7c4b659b47e60..995ceb5479244c1079ed93f975d5c129ff48c2ba 100644 (file)
@@ -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;
index c7f1b9053fc2f8bc2c6298620488a2491dd47ea7..78cbfea8d3fae2fddb67e8162ae98797ecf870fe 100644 (file)
@@ -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)
index f48da1d3a1333edcc3999102c6b20a2c530c2747..b03a2ce6aa3b1ac889eab1acea2b80f3415a09f0 100644 (file)
@@ -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;
 
index 35073201c121a6e6a693e43bb64b183bb5f8d8b2..f2434b23d49ec4e346afc188408ed527adeb6b66 100644 (file)
 #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)
index 1d34e7f84e1a218ebc40b052e78a1b6b1cb1feb6..9fc96a54336beb6069a0137b9bef818ad3fa9021 100644 (file)
 */
 
 #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;
index 9cdc6c56403cac517a06233843a1ae37f0136359..ba4503d8e1ef84d9999cde135df9f0776d83688d 100644 (file)
@@ -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,
index 2a471584bdae8c8b5e2d1465f2f6f2b9ede67748..01b1c74f53e29e4878673759f2f73d3fb78031c1 100644 (file)
@@ -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;
index d9870ec6fdef7405ba84b7783f6287aeabf3ab7f..b26ff80640bd83d35e4a8f9d4e0c87218d648fd7 100644 (file)
@@ -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;
 
index 3adaaf477c956be5850b019c18b45afefd720704..64b62fe228efd769118696289da3896c4eaa960c 100644 (file)
@@ -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;
index 5d85d8800054ea83a4434385d5cced9016061fb5..8399421b55269508a4652968ea1d84699cf99b99 100644 (file)
@@ -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)
index a707d1f9fd13641301a3782f0ee84b272ea5a8c9..c4166cb284e26ec13816d5850895f3d8e3cd35a1 100644 (file)
@@ -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)
 {
index 7381d2a904bdf74ae0aebbf250b8e38b8ef53dd4..2a9b6d6d7414a5752dab0cd78f38fa8c6ff6e090 100644 (file)
@@ -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)
index 5c974f0f37ee68b7d2382752ff853c78e03c0f54..0e17f998dfcc1013187b934be38d49aa457a9716 100644 (file)
@@ -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>
 #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);
index a76ca9b74e55a0be51bd9447ba83f2435c8fbf91..2e9e641a3985f6b57ef49c92fad2e5a3e9fe776e 100644 (file)
@@ -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
index 9e9a01694f43bc76e82e74546019c67e28c41896..fdfceb567c7d0651d25aede2c0212a8f662b182a 100644 (file)
@@ -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;
index 26554e46c2c941dd92562ef7ad197687e56cd665..7cd965a61ef8846e5d62d1d9c8e52c9c95bc2d79 100644 (file)
@@ -32,7 +32,6 @@
 #include "lib/player_video.h"
 #include "lib/raw_image_proxy.h"
 #include "lib/j2k_image_proxy.h"
-#include "lib/data.h"
 #include "lib/server_description.h"
 #include "lib/file_log.h"
 #include <boost/test/unit_test.hpp>
@@ -42,6 +41,7 @@ using std::list;
 using boost::shared_ptr;
 using boost::thread;
 using boost::optional;
+using dcp::Data;
 
 void
 do_remote_encode (shared_ptr<DCPVideo> frame, ServerDescription description, Data locally_encoded)