diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-07-31 23:52:02 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-07-31 23:52:02 +0100 |
| commit | 9c01623c3038b978ba732de2ad147d29fad60afe (patch) | |
| tree | 72907bc7560dcef38d43f363881e2b959d4c0d34 /src/lib | |
| parent | 83a2cf5916fe7207e786b95aa5c560b6b5d11e4e (diff) | |
Allow configuration of MXF/XML filenames (part of #710).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/dcp_subtitle_decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/dcpomatic_time.h | 12 | ||||
| -rw-r--r-- | src/lib/ffmpeg_subtitle_stream.cc | 2 | ||||
| -rw-r--r-- | src/lib/film.cc | 6 | ||||
| -rw-r--r-- | src/lib/film.h | 6 | ||||
| -rw-r--r-- | src/lib/overlaps.cc | 2 | ||||
| -rw-r--r-- | src/lib/playlist.cc | 25 | ||||
| -rw-r--r-- | src/lib/playlist.h | 1 | ||||
| -rw-r--r-- | src/lib/reel_writer.cc | 11 | ||||
| -rw-r--r-- | src/lib/reel_writer.h | 10 | ||||
| -rw-r--r-- | src/lib/subtitle_decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/text_subtitle_decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 10 | ||||
| -rw-r--r-- | src/lib/util.h | 4 | ||||
| -rw-r--r-- | src/lib/writer.cc | 2 |
15 files changed, 79 insertions, 18 deletions
diff --git a/src/lib/dcp_subtitle_decoder.cc b/src/lib/dcp_subtitle_decoder.cc index 81dfc6598..d7b39d5de 100644 --- a/src/lib/dcp_subtitle_decoder.cc +++ b/src/lib/dcp_subtitle_decoder.cc @@ -98,7 +98,7 @@ DCPSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) c for (list<dcp::SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { ContentTimePeriod period = content_time_period (*i); - if ((starting && p.contains (period.from)) || (!starting && p.overlaps (period))) { + if ((starting && p.contains(period.from)) || (!starting && p.overlap(period))) { d.push_back (period); } } diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index e6ca493b2..a94b605d2 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -28,6 +28,7 @@ #include "frame_rate_change.h" #include "dcpomatic_assert.h" #include <locked_sstream.h> +#include <boost/optional.hpp> #include <stdint.h> #include <cmath> #include <ostream> @@ -261,8 +262,15 @@ public: return TimePeriod<T> (from + o, to + o); } - bool overlaps (TimePeriod<T> const & other) const { - return (from < other.to && to > other.from); + boost::optional<TimePeriod<T> > overlap (TimePeriod<T> const & other) { + T const max_from = std::max (from, other.from); + T const min_to = std::min (to, other.to); + + if (max_from >= min_to) { + return boost::optional<TimePeriod<T> > (); + } + + return TimePeriod<T> (max_from, min_to); } bool contains (T const & other) const { diff --git a/src/lib/ffmpeg_subtitle_stream.cc b/src/lib/ffmpeg_subtitle_stream.cc index d1992f138..eb870c241 100644 --- a/src/lib/ffmpeg_subtitle_stream.cc +++ b/src/lib/ffmpeg_subtitle_stream.cc @@ -157,7 +157,7 @@ FFmpegSubtitleStream::subtitles_during (ContentTimePeriod period, bool starting, /* XXX: inefficient */ for (map<string, ContentTimePeriod>::const_iterator i = subs.begin(); i != subs.end(); ++i) { - if ((starting && period.contains (i->second.from)) || (!starting && period.overlaps (i->second))) { + if ((starting && period.contains(i->second.from)) || (!starting && period.overlap(i->second))) { d.push_back (i->second); } } diff --git a/src/lib/film.cc b/src/lib/film.cc index 0138211cf..5e204e126 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1447,3 +1447,9 @@ Film::reels () const return p; } + +string +Film::content_summary (DCPTimePeriod period) const +{ + return _playlist->content_summary (period); +} diff --git a/src/lib/film.h b/src/lib/film.h index 3063fc761..d63065f8d 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -157,9 +157,13 @@ public: } std::list<DCPTimePeriod> reels () const; - std::list<int> mapped_audio_channels () const; + /** @param A period within the DCP + * @return Name of the content which most contributes to the given period. + */ + std::string content_summary (DCPTimePeriod period) const; + /** Identifiers for the parts of our state; used for signalling changes. */ diff --git a/src/lib/overlaps.cc b/src/lib/overlaps.cc index 9e1b27517..ccef4cef8 100644 --- a/src/lib/overlaps.cc +++ b/src/lib/overlaps.cc @@ -31,7 +31,7 @@ ContentList overlaps (ContentList cl, function<shared_ptr<ContentPart> (shared_p ContentList overlaps; DCPTimePeriod period (from, to); BOOST_FOREACH (shared_ptr<Content> i, cl) { - if (part(i) && DCPTimePeriod(i->position(), i->end()).overlaps (period)) { + if (part(i) && DCPTimePeriod(i->position(), i->end()).overlap(period)) { overlaps.push_back (i); } } diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 739c5a20b..a8b5a26eb 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -511,3 +511,28 @@ Playlist::required_disk_space (int j2k_bandwidth, int audio_channels, int audio_ /* Add on 64k for bits and pieces (metadata, subs etc) */ return video + audio + 65536; } + +string +Playlist::content_summary (DCPTimePeriod period) const +{ + string best_summary; + int best_score = -1; + BOOST_FOREACH (shared_ptr<Content> i, _content) { + int score = 0; + optional<DCPTimePeriod> const o = DCPTimePeriod(i->position(), i->end()).overlap (period); + if (o) { + score += 100 * o.get().duration().get() / period.duration().get(); + } + + if (i->video) { + score += 100; + } + + if (score > best_score) { + best_summary = i->path(0).leaf().string(); + best_score = score; + } + } + + return best_summary; +} diff --git a/src/lib/playlist.h b/src/lib/playlist.h index 50ae1401a..e84b51a73 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -66,6 +66,7 @@ public: DCPTime video_end () const; DCPTime subtitle_end () const; FrameRateChange active_frame_rate_change (DCPTime, int dcp_frame_rate) const; + std::string content_summary (DCPTimePeriod period) const; void set_sequence (bool); void maybe_sequence (); diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index b712ac3c5..176c54c8f 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -60,7 +60,9 @@ using dcp::Data; int const ReelWriter::_info_size = 48; -ReelWriter::ReelWriter (shared_ptr<const Film> film, DCPTimePeriod period, shared_ptr<Job> job, int reel_index, int reel_count) +ReelWriter::ReelWriter ( + shared_ptr<const Film> film, DCPTimePeriod period, shared_ptr<Job> job, int reel_index, int reel_count, optional<string> content_summary + ) : _film (film) , _period (period) , _first_nonexistant_frame (0) @@ -69,6 +71,7 @@ ReelWriter::ReelWriter (shared_ptr<const Film> film, DCPTimePeriod period, share , _total_written_audio_frames (0) , _reel_index (reel_index) , _reel_count (reel_count) + , _content_summary (content_summary) { /* Create our picture asset in a subdirectory, named according to those film's parameters which affect the video output. We will hard-link @@ -113,7 +116,7 @@ ReelWriter::ReelWriter (shared_ptr<const Film> film, DCPTimePeriod period, share of the DCP directory until the last minute. */ _sound_asset_writer = _sound_asset->start_write ( - _film->directory() / audio_asset_filename (_sound_asset, _reel_index, _reel_count), + _film->directory() / audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary), _film->interop() ? dcp::INTEROP : dcp::SMPTE ); } @@ -268,7 +271,7 @@ ReelWriter::finish () boost::filesystem::path video_from = _picture_asset->file (); boost::filesystem::path video_to; video_to /= _film->dir (_film->dcp_name()); - video_to /= video_asset_filename (_picture_asset, _reel_index, _reel_count); + video_to /= video_asset_filename (_picture_asset, _reel_index, _reel_count, _content_summary); boost::system::error_code ec; boost::filesystem::create_hard_link (video_from, video_to, ec); @@ -288,7 +291,7 @@ ReelWriter::finish () if (_sound_asset) { boost::filesystem::path audio_to; audio_to /= _film->dir (_film->dcp_name ()); - string const aaf = audio_asset_filename (_sound_asset, _reel_index, _reel_count); + string const aaf = audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary); audio_to /= aaf; boost::system::error_code ec; diff --git a/src/lib/reel_writer.h b/src/lib/reel_writer.h index a80f51dc2..274f62b9f 100644 --- a/src/lib/reel_writer.h +++ b/src/lib/reel_writer.h @@ -47,7 +47,14 @@ namespace dcp { class ReelWriter { public: - ReelWriter (boost::shared_ptr<const Film> film, DCPTimePeriod period, boost::shared_ptr<Job> job, int reel_index, int reel_count); + ReelWriter ( + boost::shared_ptr<const Film> film, + DCPTimePeriod period, + boost::shared_ptr<Job> job, + int reel_index, + int reel_count, + boost::optional<std::string> content_summary + ); void write (boost::optional<dcp::Data> encoded, Frame frame, Eyes eyes); void fake_write (Frame frame, Eyes eyes, int size); @@ -106,6 +113,7 @@ private: int _reel_index; /** number of reels in the DCP */ int _reel_count; + boost::optional<std::string> _content_summary; boost::shared_ptr<dcp::PictureAsset> _picture_asset; boost::shared_ptr<dcp::PictureAssetWriter> _picture_asset_writer; diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc index b31b4873f..5ae1a703e 100644 --- a/src/lib/subtitle_decoder.cc +++ b/src/lib/subtitle_decoder.cc @@ -93,7 +93,7 @@ SubtitleDecoder::get (list<T> const & subs, list<ContentTimePeriod> const & sp, list<T> out; for (typename list<T>::const_iterator i = subs.begin(); i != subs.end(); ++i) { - if ((starting && period.contains (i->period().from)) || (!starting && period.overlaps (i->period ()))) { + if ((starting && period.contains(i->period().from)) || (!starting && period.overlap(i->period()))) { out.push_back (*i); } } diff --git a/src/lib/text_subtitle_decoder.cc b/src/lib/text_subtitle_decoder.cc index ad9c00b63..bec2ab9b7 100644 --- a/src/lib/text_subtitle_decoder.cc +++ b/src/lib/text_subtitle_decoder.cc @@ -87,7 +87,7 @@ TextSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) for (vector<sub::Subtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { ContentTimePeriod t = content_time_period (*i); - if ((starting && p.contains (t.from)) || (!starting && p.overlaps (t))) { + if ((starting && p.contains (t.from)) || (!starting && p.overlap (t))) { d.push_back (t); } } diff --git a/src/lib/util.cc b/src/lib/util.cc index c8d0561be..a0d6453ff 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -617,24 +617,30 @@ split_get_request (string url) } string -video_asset_filename (shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count) +video_asset_filename (shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, optional<string> summary) { dcp::NameFormat::Map values; values['t'] = "j2c"; values['i'] = asset->id(); values['r'] = raw_convert<string> (reel_index + 1); values['n'] = raw_convert<string> (reel_count); + if (summary) { + values['c'] = summary.get(); + } return Config::instance()->dcp_filename_format().get(values) + ".mxf"; } string -audio_asset_filename (shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count) +audio_asset_filename (shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, optional<string> summary) { dcp::NameFormat::Map values; values['t'] = "pcm"; values['i'] = asset->id(); values['r'] = raw_convert<string> (reel_index + 1); values['n'] = raw_convert<string> (reel_count); + if (summary) { + values['c'] = summary.get(); + } return Config::instance()->dcp_filename_format().get(values) + ".mxf"; } diff --git a/src/lib/util.h b/src/lib/util.h index b3621bb13..21c0b6661 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -74,8 +74,8 @@ extern int stride_round_up (int, int const *, int); extern void* wrapped_av_malloc (size_t); extern void set_backtrace_file (boost::filesystem::path); extern std::map<std::string, std::string> split_get_request (std::string url); -extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count); -extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count); +extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary); +extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary); extern float relaxed_string_to_float (std::string); extern bool string_not_empty (std::string); diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 9aee7d92f..a5085abae 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -87,7 +87,7 @@ Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j) int reel_index = 0; list<DCPTimePeriod> const reels = _film->reels (); BOOST_FOREACH (DCPTimePeriod p, reels) { - _reels.push_back (ReelWriter (film, p, job, reel_index++, reels.size())); + _reels.push_back (ReelWriter (film, p, job, reel_index++, reels.size(), _film->content_summary(p))); } /* We can keep track of the current audio and subtitle reels easily because audio |
