diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/config.cc | 8 | ||||
| -rw-r--r-- | src/lib/config.h | 29 | ||||
| -rw-r--r-- | src/lib/dcp_video_frame.cc | 32 | ||||
| -rw-r--r-- | src/lib/dcp_video_frame.h | 12 | ||||
| -rw-r--r-- | src/lib/encoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/examine_content_job.h | 4 | ||||
| -rw-r--r-- | src/lib/ffmpeg_compatibility.cc | 8 | ||||
| -rw-r--r-- | src/lib/ffmpeg_compatibility.h | 7 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 8 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.h | 2 | ||||
| -rw-r--r-- | src/lib/film.cc | 74 | ||||
| -rw-r--r-- | src/lib/film.h | 48 | ||||
| -rw-r--r-- | src/lib/filter_graph.cc | 6 | ||||
| -rw-r--r-- | src/lib/filter_graph.h | 7 | ||||
| -rw-r--r-- | src/lib/format.cc | 30 | ||||
| -rw-r--r-- | src/lib/format.h | 12 | ||||
| -rw-r--r-- | src/lib/image.cc | 16 | ||||
| -rw-r--r-- | src/lib/image.h | 17 | ||||
| -rw-r--r-- | src/lib/imagemagick_decoder.cc | 6 | ||||
| -rw-r--r-- | src/lib/imagemagick_decoder.h | 2 | ||||
| -rw-r--r-- | src/lib/make_dcp_job.cc | 19 | ||||
| -rw-r--r-- | src/lib/matcher.h | 3 | ||||
| -rw-r--r-- | src/lib/options.h | 2 | ||||
| -rw-r--r-- | src/lib/server.cc | 6 | ||||
| -rw-r--r-- | src/lib/subtitle.cc | 4 | ||||
| -rw-r--r-- | src/lib/util.cc | 39 | ||||
| -rw-r--r-- | src/lib/util.h | 35 | ||||
| -rw-r--r-- | src/lib/video_decoder.h | 2 |
28 files changed, 242 insertions, 198 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index d19adc2a4..65d01bf00 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -40,8 +40,6 @@ Config* Config::_instance = 0; Config::Config () : _num_local_encoding_threads (2) , _server_port (6192) - , _colour_lut_index (0) - , _j2k_bandwidth (250000000) , _reference_scaler (Scaler::from_id ("bicubic")) , _tms_path (".") , _sound_processor (SoundProcessor::from_id ("dolby_cp750")) @@ -71,10 +69,6 @@ Config::Config () _default_directory = v; } else if (k == "server_port") { _server_port = atoi (v.c_str ()); - } else if (k == "colour_lut_index") { - _colour_lut_index = atoi (v.c_str ()); - } else if (k == "j2k_bandwidth") { - _j2k_bandwidth = atoi (v.c_str ()); } else if (k == "reference_scaler") { _reference_scaler = Scaler::from_id (v); } else if (k == "reference_filter") { @@ -124,8 +118,6 @@ Config::write () const f << "num_local_encoding_threads " << _num_local_encoding_threads << "\n" << "default_directory " << _default_directory << "\n" << "server_port " << _server_port << "\n" - << "colour_lut_index " << _colour_lut_index << "\n" - << "j2k_bandwidth " << _j2k_bandwidth << "\n" << "reference_scaler " << _reference_scaler->id () << "\n"; for (vector<Filter const *>::const_iterator i = _reference_filters.begin(); i != _reference_filters.end(); ++i) { diff --git a/src/lib/config.h b/src/lib/config.h index 4575cb54d..c84ce76b5 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -56,19 +56,6 @@ public: return _server_port; } - /** @return index of colour LUT to use when converting RGB to XYZ. - * 0: sRGB - * 1: Rec 709 - */ - int colour_lut_index () const { - return _colour_lut_index; - } - - /** @return bandwidth for J2K files in bits per second */ - int j2k_bandwidth () const { - return _j2k_bandwidth; - } - /** @return J2K encoding servers to use */ std::vector<ServerDescription*> servers () const { return _servers; @@ -121,16 +108,6 @@ public: _server_port = p; } - /** @param i New colour LUT index */ - void set_colour_lut_index (int i) { - _colour_lut_index = i; - } - - /** @param b New J2K bandwidth */ - void set_j2k_bandwidth (int b) { - _j2k_bandwidth = b; - } - /** @param s New list of servers */ void set_servers (std::vector<ServerDescription*> s) { _servers = s; @@ -178,12 +155,6 @@ private: std::string _default_directory; /** port to use for J2K encoding servers */ int _server_port; - /** index of colour LUT to use when converting RGB to XYZ - * (see colour_lut_index ()) - */ - int _colour_lut_index; - /** bandwidth for J2K files in bits per second */ - int _j2k_bandwidth; /** J2K encoding servers to use */ std::vector<ServerDescription *> _servers; diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc index 8b70b0aa4..921a1876b 100644 --- a/src/lib/dcp_video_frame.cc +++ b/src/lib/dcp_video_frame.cc @@ -75,7 +75,7 @@ using boost::shared_ptr; */ DCPVideoFrame::DCPVideoFrame ( shared_ptr<const Image> yuv, shared_ptr<Subtitle> sub, - Size out, int p, int subtitle_offset, float subtitle_scale, + libdcp::Size out, int p, int subtitle_offset, float subtitle_scale, Scaler const * s, SourceFrame f, float fps, string pp, int clut, int bw, Log* l ) : _input (yuv) @@ -88,7 +88,7 @@ DCPVideoFrame::DCPVideoFrame ( , _frame (f) , _frames_per_second (dcp_frame_rate(fps).frames_per_second) , _post_process (pp) - , _colour_lut_index (clut) + , _colour_lut (clut) , _j2k_bandwidth (bw) , _log (l) , _image (0) @@ -188,22 +188,22 @@ DCPVideoFrame::encode_locally () for (int x = 0; x < _out_size.width; ++x) { /* In gamma LUT (converting 8-bit input to 12-bit) */ - s.r = lut_in[_colour_lut_index][*p++ << 4]; - s.g = lut_in[_colour_lut_index][*p++ << 4]; - s.b = lut_in[_colour_lut_index][*p++ << 4]; + s.r = lut_in[_colour_lut][*p++ << 4]; + s.g = lut_in[_colour_lut][*p++ << 4]; + s.b = lut_in[_colour_lut][*p++ << 4]; /* RGB to XYZ Matrix */ - d.x = ((s.r * color_matrix[_colour_lut_index][0][0]) + - (s.g * color_matrix[_colour_lut_index][0][1]) + - (s.b * color_matrix[_colour_lut_index][0][2])); + d.x = ((s.r * color_matrix[_colour_lut][0][0]) + + (s.g * color_matrix[_colour_lut][0][1]) + + (s.b * color_matrix[_colour_lut][0][2])); - d.y = ((s.r * color_matrix[_colour_lut_index][1][0]) + - (s.g * color_matrix[_colour_lut_index][1][1]) + - (s.b * color_matrix[_colour_lut_index][1][2])); + d.y = ((s.r * color_matrix[_colour_lut][1][0]) + + (s.g * color_matrix[_colour_lut][1][1]) + + (s.b * color_matrix[_colour_lut][1][2])); - d.z = ((s.r * color_matrix[_colour_lut_index][2][0]) + - (s.g * color_matrix[_colour_lut_index][2][1]) + - (s.b * color_matrix[_colour_lut_index][2][2])); + d.z = ((s.r * color_matrix[_colour_lut][2][0]) + + (s.g * color_matrix[_colour_lut][2][1]) + + (s.b * color_matrix[_colour_lut][2][2])); /* DCI companding */ d.x = d.x * DCI_COEFFICENT * (DCI_LUT_SIZE - 1); @@ -334,8 +334,8 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv) s << "post_process " << _post_process << "\n"; } - s << "colour_lut " << Config::instance()->colour_lut_index () << "\n" - << "j2k_bandwidth " << Config::instance()->j2k_bandwidth () << "\n"; + s << "colour_lut " << _colour_lut << "\n" + << "j2k_bandwidth " << _j2k_bandwidth << "\n"; if (_subtitle) { s << "subtitle_x " << _subtitle->position().x << "\n" diff --git a/src/lib/dcp_video_frame.h b/src/lib/dcp_video_frame.h index 57e7e6203..c0eff3f35 100644 --- a/src/lib/dcp_video_frame.h +++ b/src/lib/dcp_video_frame.h @@ -40,7 +40,7 @@ class EncodedData { public: /** @param d Data (will not be freed by this class, but may be by subclasses) - * @param s Size of data, in bytes. + * @param s libdcp::Size of data, in bytes. */ EncodedData (uint8_t* d, int s) : _data (d) @@ -76,7 +76,7 @@ class LocallyEncodedData : public EncodedData { public: /** @param d Data (which will not be freed by this class) - * @param s Size of data, in bytes. + * @param s libdcp::Size of data, in bytes. */ LocallyEncodedData (uint8_t* d, int s) : EncodedData (d, s) @@ -107,7 +107,7 @@ class DCPVideoFrame { public: DCPVideoFrame ( - boost::shared_ptr<const Image>, boost::shared_ptr<Subtitle>, Size, + boost::shared_ptr<const Image>, boost::shared_ptr<Subtitle>, libdcp::Size, int, int, float, Scaler const *, SourceFrame, float, std::string, int, int, Log * ); @@ -125,7 +125,7 @@ private: boost::shared_ptr<const Image> _input; ///< the input image boost::shared_ptr<Subtitle> _subtitle; ///< any subtitle that should be on the image - Size _out_size; ///< the required size of the output, in pixels + libdcp::Size _out_size; ///< the required size of the output, in pixels int _padding; int _subtitle_offset; float _subtitle_scale; @@ -133,8 +133,8 @@ private: SourceFrame _frame; ///< frame index within the Film's source int _frames_per_second; ///< Frames per second that we will use for the DCP (rounded) std::string _post_process; ///< FFmpeg post-processing string to use - int _colour_lut_index; ///< Colour look-up table to use (see Config::colour_lut_index ()) - int _j2k_bandwidth; ///< J2K bandwidth to use (see Config::j2k_bandwidth ()) + int _colour_lut; ///< Colour look-up table to use + int _j2k_bandwidth; ///< J2K bandwidth to use Log* _log; ///< log diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index f396e3cf2..910d7c58e 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -325,7 +325,7 @@ Encoder::process_video (shared_ptr<Image> image, bool same, boost::shared_ptr<Su new DCPVideoFrame ( image, sub, _opt->out_size, _opt->padding, _film->subtitle_offset(), _film->subtitle_scale(), _film->scaler(), _video_frame, _film->frames_per_second(), s.second, - Config::instance()->colour_lut_index (), Config::instance()->j2k_bandwidth (), + _film->colour_lut(), _film->j2k_bandwidth(), _film->log() ) )); diff --git a/src/lib/examine_content_job.h b/src/lib/examine_content_job.h index 2004aca83..729c287b5 100644 --- a/src/lib/examine_content_job.h +++ b/src/lib/examine_content_job.h @@ -18,13 +18,13 @@ */ /** @file src/examine_content_job.h - * @brief A class to run through content at high speed to find its length. + * @brief A class to obtain the length and MD5 digest of a content file. */ #include "job.h" /** @class ExamineContentJob - * @brief A class to run through content at high speed to find its length. + * @brief A class to obtain the length and MD5 digest of a content file. */ class ExamineContentJob : public Job { diff --git a/src/lib/ffmpeg_compatibility.cc b/src/lib/ffmpeg_compatibility.cc index c47cdf5ce..09f9276ac 100644 --- a/src/lib/ffmpeg_compatibility.cc +++ b/src/lib/ffmpeg_compatibility.cc @@ -107,3 +107,11 @@ avfilter_inout_alloc () return (AVFilterInOut *) av_malloc (sizeof (AVFilterInOut)); } #endif + +#ifndef HAVE_AV_FRAME_GET_BEST_EFFORT_TIMESTAMP +int64_t av_frame_get_best_effort_timestamp (AVFrame const * f) +{ + return f->best_effort_timestamp; +} + +#endif diff --git a/src/lib/ffmpeg_compatibility.h b/src/lib/ffmpeg_compatibility.h index 80cc79ffb..772d22c33 100644 --- a/src/lib/ffmpeg_compatibility.h +++ b/src/lib/ffmpeg_compatibility.h @@ -22,3 +22,10 @@ struct AVFilterInOut; extern AVFilter* get_sink (); extern AVFilterInOut* avfilter_inout_alloc (); +#ifndef HAVE_AV_PIXEL_FORMAT +#define AVPixelFormat PixelFormat +#endif + +#ifndef HAVE_AV_FRAME_GET_BEST_EFFORT_TIMESTAMP +extern int64_t av_frame_get_best_effort_timestamp (AVFrame const *); +#endif diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index a19f26ad7..aff3ff666 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -468,10 +468,10 @@ FFmpegDecoder::audio_sample_format () const return _audio_codec_context->sample_fmt; } -Size +libdcp::Size FFmpegDecoder::native_size () const { - return Size (_video_codec_context->width, _video_codec_context->height); + return libdcp::Size (_video_codec_context->width, _video_codec_context->height); } PixelFormat @@ -558,12 +558,12 @@ FFmpegDecoder::filter_and_emit_video (AVFrame* frame) shared_ptr<FilterGraph> graph; list<shared_ptr<FilterGraph> >::iterator i = _filter_graphs.begin(); - while (i != _filter_graphs.end() && !(*i)->can_process (Size (frame->width, frame->height), (AVPixelFormat) frame->format)) { + while (i != _filter_graphs.end() && !(*i)->can_process (libdcp::Size (frame->width, frame->height), (AVPixelFormat) frame->format)) { ++i; } if (i == _filter_graphs.end ()) { - graph.reset (new FilterGraph (_film, this, Size (frame->width, frame->height), (AVPixelFormat) frame->format)); + graph.reset (new FilterGraph (_film, this, libdcp::Size (frame->width, frame->height), (AVPixelFormat) frame->format)); _filter_graphs.push_back (graph); _film->log()->log (String::compose ("New graph for %1x%2, pixel format %3", frame->width, frame->height, frame->format)); } else { diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 2fb8675f9..3b564b826 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -90,7 +90,7 @@ public: ~FFmpegDecoder (); float frames_per_second () const; - Size native_size () const; + libdcp::Size native_size () const; SourceFrame length () const; int time_base_numerator () const; int time_base_denominator () const; diff --git a/src/lib/film.cc b/src/lib/film.cc index 7daf825af..5a11b0ca9 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -99,6 +99,8 @@ Film::Film (string d, bool must_exist) , _with_subtitles (false) , _subtitle_offset (0) , _subtitle_scale (1) + , _colour_lut (0) + , _j2k_bandwidth (200000000) , _frames_per_second (0) , _dirty (false) { @@ -166,6 +168,8 @@ Film::Film (Film const & o) , _with_subtitles (o._with_subtitles) , _subtitle_offset (o._subtitle_offset) , _subtitle_scale (o._subtitle_scale) + , _colour_lut (o._colour_lut) + , _j2k_bandwidth (o._j2k_bandwidth) , _audio_language (o._audio_language) , _subtitle_language (o._subtitle_language) , _territory (o._territory) @@ -212,7 +216,9 @@ Film::j2k_dir () const << "_" << content_digest() << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom << "_" << f.first << "_" << f.second - << "_" << scaler()->id(); + << "_" << scaler()->id() + << "_" << j2k_bandwidth() + << "_" << boost::lexical_cast<int> (colour_lut()); p /= s.str (); @@ -245,10 +251,26 @@ Film::make_dcp (bool transcode) char buffer[128]; gethostname (buffer, sizeof (buffer)); log()->log (String::compose ("Starting to make DCP on %1", buffer)); - log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? "still" : "video"))); - log()->log (String::compose ("Content length %1", length())); } - + + log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? "still" : "video"))); + log()->log (String::compose ("Content length %1", length().get())); + log()->log (String::compose ("Content digest %1", content_digest())); + log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads())); + log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth())); +#ifdef DVDOMATIC_DEBUG + log()->log ("DVD-o-matic built in debug mode."); +#else + log()->log ("DVD-o-matic built in optimised mode."); +#endif +#ifdef LIBDCP_DEBUG + log()->log ("libdcp built in debug mode."); +#else + log()->log ("libdcp built in optimised mode."); +#endif + pair<string, int> const c = cpu_info (); + log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second)); + if (format() == 0) { throw MissingSettingError ("format"); } @@ -327,18 +349,6 @@ Film::examine_content_finished () _examine_content_job.reset (); } -/** @return full paths to any audio files that this Film has */ -vector<string> -Film::audio_files () const -{ - vector<string> f; - for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (dir("wavs")); i != boost::filesystem::directory_iterator(); ++i) { - f.push_back (i->path().string ()); - } - - return f; -} - /** Start a job to send our DCP to the configured TMS */ void Film::send_dcp_to_tms () @@ -420,6 +430,8 @@ Film::write_metadata () const f << "with_subtitles " << _with_subtitles << "\n"; f << "subtitle_offset " << _subtitle_offset << "\n"; f << "subtitle_scale " << _subtitle_scale << "\n"; + f << "colour_lut " << _colour_lut << "\n"; + f << "j2k_bandwidth " << _j2k_bandwidth << "\n"; f << "audio_language " << _audio_language << "\n"; f << "subtitle_language " << _subtitle_language << "\n"; f << "territory " << _territory << "\n"; @@ -545,6 +557,10 @@ Film::read_metadata () _subtitle_offset = atoi (v.c_str ()); } else if (k == "subtitle_scale") { _subtitle_scale = atof (v.c_str ()); + } else if (k == "colour_lut") { + _colour_lut = atoi (v.c_str ()); + } else if (k == "j2k_bandwidth") { + _j2k_bandwidth = atoi (v.c_str ()); } else if (k == "audio_language") { _audio_language = v; } else if (k == "subtitle_language") { @@ -606,8 +622,8 @@ Film::read_metadata () _dirty = false; } -Size -Film::cropped_size (Size s) const +libdcp::Size +Film::cropped_size (libdcp::Size s) const { boost::mutex::scoped_lock lm (_state_mutex); s.width -= _crop.left + _crop.right; @@ -1191,6 +1207,26 @@ Film::set_subtitle_scale (float s) } void +Film::set_colour_lut (int i) +{ + { + boost::mutex::scoped_lock lm (_state_mutex); + _colour_lut = i; + } + signal_changed (COLOUR_LUT); +} + +void +Film::set_j2k_bandwidth (int b) +{ + { + boost::mutex::scoped_lock lm (_state_mutex); + _j2k_bandwidth = b; + } + signal_changed (J2K_BANDWIDTH); +} + +void Film::set_audio_language (string l) { { @@ -1261,7 +1297,7 @@ Film::set_package_type (string p) } void -Film::set_size (Size s) +Film::set_size (libdcp::Size s) { { boost::mutex::scoped_lock lm (_state_mutex); diff --git a/src/lib/film.h b/src/lib/film.h index eb199784e..d3530b817 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -47,9 +47,9 @@ class ExamineContentJob; class ExternalAudioStream; /** @class Film - * @brief A representation of a video with sound. + * @brief A representation of a video, maybe with sound. * - * A representation of a piece of video (with sound), including naming, + * A representation of a piece of video (maybe with sound), including naming, * the source content file, and how it should be presented in a DCP. */ class Film : public boost::enable_shared_from_this<Film> @@ -60,7 +60,6 @@ public: ~Film (); std::string j2k_dir () const; - std::vector<std::string> audio_files () const; void examine_content (); void send_dcp_to_tms (); @@ -87,11 +86,12 @@ public: void write_metadata () const; void read_metadata (); - Size cropped_size (Size) const; + libdcp::Size cropped_size (libdcp::Size) const; boost::optional<int> dcp_length () const; std::string dci_name () const; std::string dcp_name () const; + /** @return true if our state has changed since we last saved it */ bool dirty () const { return _dirty; } @@ -100,6 +100,9 @@ public: void set_dci_date_today (); + /** Identifiers for the parts of our state; + used for signalling changes. + */ enum Property { NONE, NAME, @@ -124,6 +127,8 @@ public: WITH_SUBTITLES, SUBTITLE_OFFSET, SUBTITLE_SCALE, + COLOUR_LUT, + J2K_BANDWIDTH, DCI_METADATA, SIZE, LENGTH, @@ -194,7 +199,7 @@ public: boost::mutex::scoped_lock lm (_state_mutex); return _dcp_trim_end; } - + bool dcp_ab () const { boost::mutex::scoped_lock lm (_state_mutex); return _dcp_ab; @@ -250,6 +255,16 @@ public: return _subtitle_scale; } + int colour_lut () const { + boost::mutex::scoped_lock lm (_state_mutex); + return _colour_lut; + } + + int j2k_bandwidth () const { + boost::mutex::scoped_lock lm (_state_mutex); + return _j2k_bandwidth; + } + std::string audio_language () const { boost::mutex::scoped_lock lm (_state_mutex); return _audio_language; @@ -285,7 +300,7 @@ public: return _package_type; } - Size size () const { + libdcp::Size size () const { boost::mutex::scoped_lock lm (_state_mutex); return _size; } @@ -351,6 +366,8 @@ public: void set_with_subtitles (bool); void set_subtitle_offset (int); void set_subtitle_scale (float); + void set_colour_lut (int); + void set_j2k_bandwidth (int); void set_audio_language (std::string); void set_subtitle_language (std::string); void set_territory (std::string); @@ -358,7 +375,7 @@ public: void set_studio (std::string); void set_facility (std::string); void set_package_type (std::string); - void set_size (Size); + void set_size (libdcp::Size); void set_length (SourceFrame); void unset_length (); void set_content_digest (std::string); @@ -401,6 +418,10 @@ private: * or an absolute path. */ std::string _content; + /** If this is true, we will believe the length specified by the content + * file's header; if false, we will run through the whole content file + * the first time we see it in order to obtain the length. + */ bool _trust_content_header; /** The type of content that this Film represents (feature, trailer etc.) */ DCPContentType const * _dcp_content_type; @@ -444,7 +465,14 @@ private: int _subtitle_offset; /** scale factor to apply to subtitles */ float _subtitle_scale; - + /** index of colour LUT to use when converting RGB to XYZ. + * 0: sRGB + * 1: Rec 709 + */ + int _colour_lut; + /** bandwidth for J2K files in bits per second */ + int _j2k_bandwidth; + /* DCI naming stuff */ std::string _audio_language; std::string _subtitle_language; @@ -456,8 +484,8 @@ private: /* Data which are cached to speed things up */ - /** Size, in pixels, of the source (ignoring cropping) */ - Size _size; + /** libdcp::Size, in pixels, of the source (ignoring cropping) */ + libdcp::Size _size; /** The length of the source, in video frames (as far as we know) */ boost::optional<SourceFrame> _length; /** MD5 digest of our content file */ diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc index 17107a05b..6cd7dc2cb 100644 --- a/src/lib/filter_graph.cc +++ b/src/lib/filter_graph.cc @@ -23,7 +23,9 @@ extern "C" { #include <libavfilter/avfiltergraph.h> +#ifdef HAVE_BUFFERSRC_H #include <libavfilter/buffersrc.h> +#endif #if (LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR >= 53 && LIBAVFILTER_VERSION_MINOR <= 77) || LIBAVFILTER_VERSION_MAJOR == 3 #include <libavfilter/avcodec.h> #include <libavfilter/buffersink.h> @@ -52,7 +54,7 @@ using boost::shared_ptr; * @param s Size of the images to process. * @param p Pixel format of the images to process. */ -FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, Size s, AVPixelFormat p) +FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p) : _buffer_src_context (0) , _buffer_sink_context (0) , _size (s) @@ -203,7 +205,7 @@ FilterGraph::process (AVFrame const * frame) * @return true if this chain can process images with `s' and `p', otherwise false. */ bool -FilterGraph::can_process (Size s, AVPixelFormat p) const +FilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const { return (_size == s && _pixel_format == p); } diff --git a/src/lib/filter_graph.h b/src/lib/filter_graph.h index a4b9ef75f..7e4e8422b 100644 --- a/src/lib/filter_graph.h +++ b/src/lib/filter_graph.h @@ -25,6 +25,7 @@ #define DVDOMATIC_FILTER_GRAPH_H #include "util.h" +#include "ffmpeg_compatibility.h" class Image; class VideoFilter; @@ -36,15 +37,15 @@ class FFmpegDecoder; class FilterGraph { public: - FilterGraph (boost::shared_ptr<Film> film, FFmpegDecoder* decoder, Size s, AVPixelFormat p); + FilterGraph (boost::shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p); - bool can_process (Size s, AVPixelFormat p) const; + bool can_process (libdcp::Size s, AVPixelFormat p) const; std::list<boost::shared_ptr<Image> > process (AVFrame const * frame); private: AVFilterContext* _buffer_src_context; AVFilterContext* _buffer_sink_context; - Size _size; ///< size of the images that this chain can process + libdcp::Size _size; ///< size of the images that this chain can process AVPixelFormat _pixel_format; ///< pixel format of the images that this chain can process }; diff --git a/src/lib/format.cc b/src/lib/format.cc index 975862411..088a16059 100644 --- a/src/lib/format.cc +++ b/src/lib/format.cc @@ -67,19 +67,19 @@ Format::as_metadata () const void Format::setup_formats () { - _formats.push_back (new FixedFormat (119, Size (1285, 1080), "119", "1.19", "F")); - _formats.push_back (new FixedFormat (133, Size (1436, 1080), "133", "1.33", "F")); - _formats.push_back (new FixedFormat (138, Size (1485, 1080), "138", "1.375", "F")); - _formats.push_back (new FixedFormat (133, Size (1998, 1080), "133-in-flat", "4:3 within Flat", "F")); - _formats.push_back (new FixedFormat (137, Size (1480, 1080), "137", "Academy", "F")); - _formats.push_back (new FixedFormat (166, Size (1793, 1080), "166", "1.66", "F")); - _formats.push_back (new FixedFormat (166, Size (1998, 1080), "166-in-flat", "1.66 within Flat", "F")); - _formats.push_back (new FixedFormat (178, Size (1998, 1080), "178-in-flat", "16:9 within Flat", "F")); - _formats.push_back (new FixedFormat (178, Size (1920, 1080), "178", "16:9", "F")); - _formats.push_back (new FixedFormat (185, Size (1998, 1080), "185", "Flat", "F")); - _formats.push_back (new FixedFormat (239, Size (2048, 858), "239", "Scope", "S")); - _formats.push_back (new VariableFormat (Size (1998, 1080), "var-185", "Flat", "F")); - _formats.push_back (new VariableFormat (Size (2048, 858), "var-239", "Scope", "S")); + _formats.push_back (new FixedFormat (119, libdcp::Size (1285, 1080), "119", "1.19", "F")); + _formats.push_back (new FixedFormat (133, libdcp::Size (1436, 1080), "133", "1.33", "F")); + _formats.push_back (new FixedFormat (138, libdcp::Size (1485, 1080), "138", "1.375", "F")); + _formats.push_back (new FixedFormat (133, libdcp::Size (1998, 1080), "133-in-flat", "4:3 within Flat", "F")); + _formats.push_back (new FixedFormat (137, libdcp::Size (1480, 1080), "137", "Academy", "F")); + _formats.push_back (new FixedFormat (166, libdcp::Size (1793, 1080), "166", "1.66", "F")); + _formats.push_back (new FixedFormat (166, libdcp::Size (1998, 1080), "166-in-flat", "1.66 within Flat", "F")); + _formats.push_back (new FixedFormat (178, libdcp::Size (1998, 1080), "178-in-flat", "16:9 within Flat", "F")); + _formats.push_back (new FixedFormat (178, libdcp::Size (1920, 1080), "178", "16:9", "F")); + _formats.push_back (new FixedFormat (185, libdcp::Size (1998, 1080), "185", "Flat", "F")); + _formats.push_back (new FixedFormat (239, libdcp::Size (2048, 858), "239", "Scope", "S")); + _formats.push_back (new VariableFormat (libdcp::Size (1998, 1080), "var-185", "Flat", "F")); + _formats.push_back (new VariableFormat (libdcp::Size (2048, 858), "var-239", "Scope", "S")); } /** @param n Nickname. @@ -140,7 +140,7 @@ Format::all () * @param id ID (e.g. 185) * @param n Nick name (e.g. Flat) */ -FixedFormat::FixedFormat (int r, Size dcp, string id, string n, string d) +FixedFormat::FixedFormat (int r, libdcp::Size dcp, string id, string n, string d) : Format (dcp, id, n, d) , _ratio (r) { @@ -160,7 +160,7 @@ Format::dcp_padding (shared_ptr<const Film> f) const return p; } -VariableFormat::VariableFormat (Size dcp, string id, string n, string d) +VariableFormat::VariableFormat (libdcp::Size dcp, string id, string n, string d) : Format (dcp, id, n, d) { diff --git a/src/lib/format.h b/src/lib/format.h index 2118237a4..b4c691e56 100644 --- a/src/lib/format.h +++ b/src/lib/format.h @@ -31,7 +31,7 @@ class Film; class Format { public: - Format (Size dcp, std::string id, std::string n, std::string d) + Format (libdcp::Size dcp, std::string id, std::string n, std::string d) : _dcp_size (dcp) , _id (id) , _nickname (n) @@ -52,7 +52,7 @@ public: * put in a DCP for this ratio. This size will not correspond * to the ratio when we are doing things like 16:9 in a Flat frame. */ - Size dcp_size () const { + libdcp::Size dcp_size () const { return _dcp_size; } @@ -81,11 +81,11 @@ public: static void setup_formats (); protected: - /** Size in pixels of the images that we should + /** libdcp::Size in pixels of the images that we should * put in a DCP for this ratio. This size will not correspond * to the ratio when we are doing things like 16:9 in a Flat frame. */ - Size _dcp_size; + libdcp::Size _dcp_size; /** id for use in metadata */ std::string _id; /** nickname (e.g. Flat, Scope) */ @@ -104,7 +104,7 @@ private: class FixedFormat : public Format { public: - FixedFormat (int, Size, std::string, std::string, std::string); + FixedFormat (int, libdcp::Size, std::string, std::string, std::string); int ratio_as_integer (boost::shared_ptr<const Film>) const { return _ratio; @@ -125,7 +125,7 @@ private: class VariableFormat : public Format { public: - VariableFormat (Size, std::string, std::string, std::string); + VariableFormat (libdcp::Size, std::string, std::string, std::string); int ratio_as_integer (boost::shared_ptr<const Film> f) const; float ratio_as_float (boost::shared_ptr<const Film> f) const; diff --git a/src/lib/image.cc b/src/lib/image.cc index f774f476f..feda09ec5 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -95,7 +95,7 @@ Image::components () const } shared_ptr<Image> -Image::scale (Size out_size, Scaler const * scaler, bool aligned) const +Image::scale (libdcp::Size out_size, Scaler const * scaler, bool aligned) const { assert (scaler); @@ -124,11 +124,11 @@ Image::scale (Size out_size, Scaler const * scaler, bool aligned) const * @param scaler Scaler to use. */ shared_ptr<Image> -Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scaler, bool aligned) const +Image::scale_and_convert_to_rgb (libdcp::Size out_size, int padding, Scaler const * scaler, bool aligned) const { assert (scaler); - Size content_size = out_size; + libdcp::Size content_size = out_size; content_size.width -= (padding * 2); shared_ptr<Image> rgb (new SimpleImage (PIX_FMT_RGB24, content_size, aligned)); @@ -215,7 +215,7 @@ Image::post_process (string pp, bool aligned) const shared_ptr<Image> Image::crop (Crop crop, bool aligned) const { - Size cropped_size = size (); + libdcp::Size cropped_size = size (); cropped_size.width -= crop.left + crop.right; cropped_size.height -= crop.top + crop.bottom; @@ -368,7 +368,7 @@ Image::bytes_per_pixel (int c) const * @param p Pixel format. * @param s Size in pixels. */ -SimpleImage::SimpleImage (AVPixelFormat p, Size s, bool aligned) +SimpleImage::SimpleImage (AVPixelFormat p, libdcp::Size s, bool aligned) : Image (p) , _size (s) , _aligned (aligned) @@ -466,7 +466,7 @@ SimpleImage::stride () const return _stride; } -Size +libdcp::Size SimpleImage::size () const { return _size; @@ -503,10 +503,10 @@ FilterBufferImage::stride () const return _buffer->linesize; } -Size +libdcp::Size FilterBufferImage::size () const { - return Size (_buffer->video->w, _buffer->video->h); + return libdcp::Size (_buffer->video->w, _buffer->video->h); } RGBPlusAlphaImage::RGBPlusAlphaImage (shared_ptr<const Image> im) diff --git a/src/lib/image.h b/src/lib/image.h index 95e0de9dc..adee8bc4d 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -32,6 +32,7 @@ extern "C" { #include <libavfilter/avfilter.h> } #include "util.h" +#include "ffmpeg_compatibility.h" class Scaler; class RGBFrameImage; @@ -64,14 +65,14 @@ public: /** @return Array of strides for each line (including any alignment padding bytes) */ virtual int * stride () const = 0; - /** @return Size of the image, in pixels */ - virtual Size size () const = 0; + /** @return libdcp::Size of the image, in pixels */ + virtual libdcp::Size size () const = 0; int components () const; int lines (int) const; - boost::shared_ptr<Image> scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scaler, bool aligned) const; - boost::shared_ptr<Image> scale (Size, Scaler const *, bool aligned) const; + boost::shared_ptr<Image> scale_and_convert_to_rgb (libdcp::Size out_size, int padding, Scaler const * scaler, bool aligned) const; + boost::shared_ptr<Image> scale (libdcp::Size, Scaler const *, bool aligned) const; boost::shared_ptr<Image> post_process (std::string, bool aligned) const; void alpha_blend (boost::shared_ptr<const Image> image, Position pos); boost::shared_ptr<Image> crop (Crop c, bool aligned) const; @@ -105,7 +106,7 @@ public: uint8_t ** data () const; int * line_size () const; int * stride () const; - Size size () const; + libdcp::Size size () const; private: /* Not allowed */ @@ -121,7 +122,7 @@ private: class SimpleImage : public Image { public: - SimpleImage (AVPixelFormat, Size, bool); + SimpleImage (AVPixelFormat, libdcp::Size, bool); SimpleImage (SimpleImage const &); SimpleImage& operator= (SimpleImage const &); ~SimpleImage (); @@ -129,14 +130,14 @@ public: uint8_t ** data () const; int * line_size () const; int * stride () const; - Size size () const; + libdcp::Size size () const; protected: void allocate (); void swap (SimpleImage &); private: - Size _size; ///< size in pixels + libdcp::Size _size; ///< size in pixels uint8_t** _data; ///< array of pointers to components int* _line_size; ///< array of sizes of the data in each line, in pixels (without any alignment padding bytes) int* _stride; ///< array of strides for each line (including any alignment padding bytes) diff --git a/src/lib/imagemagick_decoder.cc b/src/lib/imagemagick_decoder.cc index bad1fb813..5ebd6c8e1 100644 --- a/src/lib/imagemagick_decoder.cc +++ b/src/lib/imagemagick_decoder.cc @@ -50,7 +50,7 @@ ImageMagickDecoder::ImageMagickDecoder ( _iter = _files.begin (); } -Size +libdcp::Size ImageMagickDecoder::native_size () const { if (_files.empty ()) { @@ -60,7 +60,7 @@ ImageMagickDecoder::native_size () const /* Look at the first file and assume its size holds for all */ using namespace MagickCore; Magick::Image* image = new Magick::Image (_film->content_path ()); - Size const s = Size (image->columns(), image->rows()); + libdcp::Size const s = libdcp::Size (image->columns(), image->rows()); delete image; return s; @@ -80,7 +80,7 @@ ImageMagickDecoder::pass () Magick::Image* magick_image = new Magick::Image (_film->content_path ()); - Size size = native_size (); + libdcp::Size size = native_size (); shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, size, false)); using namespace MagickCore; diff --git a/src/lib/imagemagick_decoder.h b/src/lib/imagemagick_decoder.h index 6f426f308..c4795b003 100644 --- a/src/lib/imagemagick_decoder.h +++ b/src/lib/imagemagick_decoder.h @@ -33,7 +33,7 @@ public: return 0; } - Size native_size () const; + libdcp::Size native_size () const; SourceFrame length () const { /* We don't know */ diff --git a/src/lib/make_dcp_job.cc b/src/lib/make_dcp_job.cc index 5272d6bad..705521626 100644 --- a/src/lib/make_dcp_job.cc +++ b/src/lib/make_dcp_job.cc @@ -21,6 +21,7 @@ * @brief A job to create DCPs. */ +#include <iostream> #include <boost/filesystem.hpp> #include <libdcp/dcp.h> #include <libdcp/picture_asset.h> @@ -37,6 +38,7 @@ extern "C" { #include "film.h" using std::string; +using std::cout; using boost::shared_ptr; /** @param f Film we are making the DCP for. @@ -75,6 +77,8 @@ MakeDCPJob::run () if (!_film->dcp_length()) { throw EncodeError ("cannot make a DCP when the source length is not known"); } + + descend (0.9); string const dcp_path = _film->dir (_film->dcp_name()); @@ -104,6 +108,7 @@ MakeDCPJob::run () dcp.add_cpl (cpl); descend (0.8); + shared_ptr<libdcp::MonoPictureAsset> pa ( new libdcp::MonoPictureAsset ( boost::bind (&MakeDCPJob::j2c_path, this, _1), @@ -112,15 +117,14 @@ MakeDCPJob::run () &dcp.Progress, dfr.frames_per_second, frames, - _opt->out_size.width, - _opt->out_size.height + _opt->out_size ) ); ascend (); - + shared_ptr<libdcp::SoundAsset> sa; - + if (_film->audio_channels() > 0) { descend (0.1); sa.reset ( @@ -137,11 +141,14 @@ MakeDCPJob::run () ascend (); } - descend (0.1); + descend (0.05); cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (pa, sa, shared_ptr<libdcp::SubtitleAsset> ()))); + ascend (); + + descend (0.05); dcp.write_xml (); ascend (); - + set_progress (1); set_state (FINISHED_OK); } diff --git a/src/lib/matcher.h b/src/lib/matcher.h index 9bd30fe62..60bb87432 100644 --- a/src/lib/matcher.h +++ b/src/lib/matcher.h @@ -19,6 +19,7 @@ #include <boost/optional.hpp> #include "processor.h" +#include "ffmpeg_compatibility.h" class Matcher : public AudioVideoProcessor { @@ -34,6 +35,6 @@ private: int _video_frames; int64_t _audio_frames; boost::optional<AVPixelFormat> _pixel_format; - boost::optional<Size> _size; + boost::optional<libdcp::Size> _size; boost::optional<int> _channels; }; diff --git a/src/lib/options.h b/src/lib/options.h index 55b066a2d..2f2f44b64 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -90,7 +90,7 @@ public: return s.str (); } - Size out_size; ///< size of output images + libdcp::Size out_size; ///< size of output images int padding; ///< number of pixels of padding (in terms of the output size) each side of the image /** Range of video frames to encode (in DCP frames) */ diff --git a/src/lib/server.cc b/src/lib/server.cc index bea75cff8..1bb8f205e 100644 --- a/src/lib/server.cc +++ b/src/lib/server.cc @@ -92,9 +92,9 @@ Server::process (shared_ptr<Socket> socket) return -1; } - Size in_size (get_required_int (kv, "input_width"), get_required_int (kv, "input_height")); + libdcp::Size in_size (get_required_int (kv, "input_width"), get_required_int (kv, "input_height")); int pixel_format_int = get_required_int (kv, "input_pixel_format"); - Size out_size (get_required_int (kv, "output_width"), get_required_int (kv, "output_height")); + libdcp::Size out_size (get_required_int (kv, "output_width"), get_required_int (kv, "output_height")); int padding = get_required_int (kv, "padding"); int subtitle_offset = get_required_int (kv, "subtitle_offset"); float subtitle_scale = get_required_float (kv, "subtitle_scale"); @@ -105,7 +105,7 @@ Server::process (shared_ptr<Socket> socket) int colour_lut_index = get_required_int (kv, "colour_lut"); int j2k_bandwidth = get_required_int (kv, "j2k_bandwidth"); Position subtitle_position (get_optional_int (kv, "subtitle_x"), get_optional_int (kv, "subtitle_y")); - Size subtitle_size (get_optional_int (kv, "subtitle_width"), get_optional_int (kv, "subtitle_height")); + libdcp::Size subtitle_size (get_optional_int (kv, "subtitle_width"), get_optional_int (kv, "subtitle_height")); /* This checks that colour_lut_index is within range */ colour_lut_index_to_name (colour_lut_index); diff --git a/src/lib/subtitle.cc b/src/lib/subtitle.cc index c52d3ac66..b4ac14285 100644 --- a/src/lib/subtitle.cc +++ b/src/lib/subtitle.cc @@ -34,7 +34,7 @@ using namespace boost; */ TimedSubtitle::TimedSubtitle (AVSubtitle const & sub) { - assert (sub.rects > 0); + assert (sub.num_rects > 0); /* Subtitle PTS in seconds (within the source, not taking into account any of the source that we may have chopped off for the DCP) @@ -55,7 +55,7 @@ TimedSubtitle::TimedSubtitle (AVSubtitle const & sub) throw DecodeError ("non-bitmap subtitles not yet supported"); } - shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGBA, Size (rect->w, rect->h), true)); + shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGBA, libdcp::Size (rect->w, rect->h), true)); /* Start of the first line in the subtitle */ uint8_t* sub_p = rect->pict.data[0]; diff --git a/src/lib/util.cc b/src/lib/util.cc index 66743250f..7f370b896 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -244,7 +244,7 @@ dvdomatic_setup () * @return FFmpeg crop filter string. */ string -crop_string (Position start, Size size) +crop_string (Position start, libdcp::Size size) { stringstream s; s << "crop=" << size.width << ":" << size.height << ":" << start.x << ":" << start.y; @@ -377,17 +377,6 @@ dcp_audio_channels (int f) return f; } - -bool operator== (Size const & a, Size const & b) -{ - return (a.width == b.width && a.height == b.height); -} - -bool operator!= (Size const & a, Size const & b) -{ - return !(a == b); -} - bool operator== (Crop const & a, Crop const & b) { return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom); @@ -875,3 +864,29 @@ still_image_file (string f) return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png"); } + +/** @return A pair containing CPU model name and the number of processors */ +pair<string, int> +cpu_info () +{ + pair<string, int> info; + info.second = 0; + +#ifdef DVDOMATIC_POSIX + ifstream f ("/proc/cpuinfo"); + while (f.good ()) { + string l; + getline (f, l); + if (boost::algorithm::starts_with (l, "model name")) { + string::size_type const c = l.find (':'); + if (c != string::npos) { + info.first = l.substr (c + 2); + } + } else if (boost::algorithm::starts_with (l, "processor")) { + ++info.second; + } + } +#endif + + return info; +} diff --git a/src/lib/util.h b/src/lib/util.h index 0744d9c09..77fb943e0 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -29,6 +29,7 @@ #include <vector> #include <boost/shared_ptr.hpp> #include <boost/asio.hpp> +#include <libdcp/util.h> extern "C" { #include <libavcodec/avcodec.h> #include <libavfilter/avfilter.h> @@ -78,33 +79,6 @@ enum ContentType { VIDEO ///< content is a video }; -/** @class Size - * @brief Representation of the size of something */ -struct Size -{ - /** Construct a zero Size */ - Size () - : width (0) - , height (0) - {} - - /** @param w Width. - * @param h Height. - */ - Size (int w, int h) - : width (w) - , height (h) - {} - - /** width */ - int width; - /** height */ - int height; -}; - -extern bool operator== (Size const & a, Size const & b); -extern bool operator!= (Size const & a, Size const & b); - /** @struct Crop * @brief A description of the crop of an image or video. */ @@ -174,14 +148,14 @@ struct Rect return Position (x, y); } - Size size () const { - return Size (width, height); + libdcp::Size size () const { + return libdcp::Size (width, height); } Rect intersection (Rect const & other) const; }; -extern std::string crop_string (Position, Size); +extern std::string crop_string (Position, libdcp::Size); extern int dcp_audio_sample_rate (int); extern DCPFrameRate dcp_frame_rate (float); extern int dcp_audio_channels (int); @@ -280,6 +254,7 @@ private: extern int64_t video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float frames_per_second); extern bool still_image_file (std::string); +extern std::pair<std::string, int> cpu_info (); #endif diff --git a/src/lib/video_decoder.h b/src/lib/video_decoder.h index 7726d2057..b18082c69 100644 --- a/src/lib/video_decoder.h +++ b/src/lib/video_decoder.h @@ -32,7 +32,7 @@ public: /** @return video frames per second, or 0 if unknown */ virtual float frames_per_second () const = 0; /** @return native size in pixels */ - virtual Size native_size () const = 0; + virtual libdcp::Size native_size () const = 0; /** @return length (in source video frames), according to our content's header */ virtual SourceFrame length () const = 0; |
