X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcp_video.cc;h=b72353d9ecbc6482c6573f496275e53687d495d4;hb=e60bb3e51bd1508b149e6b8f6608f09b5196ae26;hp=9b1c8c33eae12cf36d214cbd81b84af99e9e7ae8;hpb=a6c2aa6cad5872d27654553d447cb34185317974;p=dcpomatic.git diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc index 9b1c8c33e..b72353d9e 100644 --- a/src/lib/dcp_video.cc +++ b/src/lib/dcp_video.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington Taken from code Copyright (C) 2010-2011 Terrence Meiczinger This program is free software; you can redistribute it and/or modify @@ -28,51 +28,45 @@ * of images that require encoding. */ +#include "dcp_video.h" +#include "config.h" +#include "exceptions.h" +#include "server.h" +#include "dcpomatic_socket.h" +#include "image.h" +#include "log.h" +#include "cross.h" +#include "player_video.h" +#include "raw_convert.h" +#include "data.h" +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include #include #include -#include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "film.h" -#include "dcp_video.h" -#include "config.h" -#include "exceptions.h" -#include "server.h" -#include "util.h" -#include "scaler.h" -#include "image.h" -#include "log.h" -#include "cross.h" -#include "player_video.h" -#include "encoded_data.h" #define LOG_GENERAL(...) _log->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL); #include "i18n.h" using std::string; -using std::stringstream; using std::cout; using boost::shared_ptr; using boost::lexical_cast; using dcp::Size; -using dcp::raw_convert; #define DCI_COEFFICENT (48.0 / 52.37) @@ -93,7 +87,7 @@ DCPVideo::DCPVideo ( , _burn_subtitles (b) , _log (l) { - + } DCPVideo::DCPVideo (shared_ptr frame, shared_ptr node, shared_ptr log) @@ -110,29 +104,24 @@ DCPVideo::DCPVideo (shared_ptr frame, shared_ptr -DCPVideo::encode_locally () +Data +DCPVideo::encode_locally (dcp::NoteHandler note) { - shared_ptr in_lut = dcp::GammaLUT::cache.get ( - 12, _frame->colour_conversion().input_gamma, _frame->colour_conversion().input_gamma_linearised - ); - - /* XXX: libdcp should probably use boost */ - - double matrix[3][3]; - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) { - matrix[i][j] = _frame->colour_conversion().matrix (i, j); - } + shared_ptr xyz; + + shared_ptr image = _frame->image (AV_PIX_FMT_RGB48LE, _burn_subtitles, note); + if (_frame->colour_conversion()) { + xyz = dcp::rgb_to_xyz ( + image->data()[0], + image->size(), + image->stride()[0], + _frame->colour_conversion().get(), + note + ); + } else { + xyz = dcp::xyz_to_xyz (image->data()[0], image->size(), image->stride()[0]); } - shared_ptr xyz = dcp::rgb_to_xyz ( - _frame->image (_burn_subtitles), - in_lut, - dcp::GammaLUT::cache.get (16, 1 / _frame->colour_conversion().output_gamma, false), - matrix - ); - /* 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) { @@ -155,11 +144,11 @@ DCPVideo::encode_locally () 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; @@ -170,19 +159,19 @@ DCPVideo::encode_locally () 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; @@ -190,27 +179,27 @@ DCPVideo::encode_locally () if (_resolution == RESOLUTION_4K) { parameters.numpocs = 2; parameters.POC[0].tile = 1; - parameters.POC[0].resno0 = 0; + 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].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); @@ -248,7 +237,7 @@ DCPVideo::encode_locally () break; } - shared_ptr enc (new LocallyEncodedData (cio->buffer, cio_tell (cio))); + Data enc (cio->buffer, cio_tell (cio)); opj_cio_close (cio); free (parameters.cp_comment); @@ -261,7 +250,7 @@ DCPVideo::encode_locally () * @param serv Server to send to. * @return Encoded data. */ -shared_ptr +Data DCPVideo::encode_remotely (ServerDescription serv) { boost::asio::io_service io_service; @@ -280,12 +269,11 @@ DCPVideo::encode_remotely (ServerDescription serv) add_metadata (root); LOG_GENERAL (N_("Sending frame %1 to remote"), _index); - + /* Send XML metadata */ - stringstream xml; - doc.write_to_stream (xml, "UTF-8"); - socket->write (xml.str().length() + 1); - socket->write ((uint8_t *) xml.str().c_str(), xml.str().length() + 1); + string xml = doc.write_to_string ("UTF-8"); + socket->write (xml.length() + 1); + socket->write ((uint8_t *) xml.c_str(), xml.length() + 1); /* Send binary data */ _frame->send_binary (socket, _burn_subtitles); @@ -293,11 +281,11 @@ DCPVideo::encode_remotely (ServerDescription serv) /* Read the response (JPEG2000-encoded data); this blocks until the data is ready and sent back. */ - shared_ptr e (new RemotelyEncodedData (socket->read_uint32 ())); - socket->read (e->data(), e->size()); + Data e (socket->read_uint32 ()); + socket->read (e.data().get(), e.size()); LOG_GENERAL (N_("Finished remotely-encoded frame %1"), _index); - + return e; } @@ -318,3 +306,18 @@ DCPVideo::eyes () const return _frame->eyes (); } +/** @return true if this DCPVideo is definitely the same as another; + * (apart from the frame index), false if it is probably not. + */ +bool +DCPVideo::same (shared_ptr other) const +{ + if (_frames_per_second != other->_frames_per_second || + _j2k_bandwidth != other->_j2k_bandwidth || + _resolution != other->_resolution || + _burn_subtitles != other->_burn_subtitles) { + return false; + } + + return _frame->same (other->_frame); +}