+2016-07-31 Carl Hetherington <cth@carlh.net>
+
+ * Allow configuration of MXF/XML filenames (part of #710).
+
2016-07-29 Carl Hetherington <cth@carlh.net>
* Version 2.9.8 released.
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);
}
}
#include "frame_rate_change.h"
#include "dcpomatic_assert.h"
#include <locked_sstream.h>
+#include <boost/optional.hpp>
#include <stdint.h>
#include <cmath>
#include <ostream>
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 {
/* 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);
}
}
return p;
}
+
+string
+Film::content_summary (DCPTimePeriod period) const
+{
+ return _playlist->content_summary (period);
+}
}
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.
*/
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);
}
}
/* 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;
+}
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 ();
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)
, _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
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
);
}
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);
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;
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);
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;
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);
}
}
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);
}
}
}
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";
}
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);
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
shared_ptr<Content> test_content = test->content();
if (test && test->track() && test->track().get() == t) {
- if (content_period.overlaps (DCPTimePeriod(test_content->position(), test_content->end()))) {
+ if (content_period.overlap (DCPTimePeriod(test_content->position(), test_content->end()))) {
/* we have an overlap on track `t' */
++t;
break;
TimePeriod<DCPTime> a (DCPTime (0), DCPTime (4));
TimePeriod<DCPTime> b (DCPTime (4), DCPTime (8));
- BOOST_CHECK (!a.overlaps (b));
+ BOOST_CHECK (!a.overlap (b));
/* Some more obvious non-overlaps */
a = TimePeriod<DCPTime> (DCPTime (0), DCPTime (4));
b = TimePeriod<DCPTime> (DCPTime (5), DCPTime (8));
- BOOST_CHECK (!a.overlaps (b));
+ BOOST_CHECK (!a.overlap (b));
/* Some overlaps */
a = TimePeriod<DCPTime> (DCPTime (0), DCPTime (4));
b = TimePeriod<DCPTime> (DCPTime (3), DCPTime (8));
- BOOST_CHECK (a.overlaps (b));
+ BOOST_CHECK (a.overlap (b));
+ BOOST_CHECK_EQUAL (a.overlap(b).get(), DCPTimePeriod(DCPTime(3), DCPTime(4)));
a = TimePeriod<DCPTime> (DCPTime (1), DCPTime (9));
b = TimePeriod<DCPTime> (DCPTime (0), DCPTime (10));
- BOOST_CHECK (a.overlaps (b));
+ BOOST_CHECK (a.overlap (b));
+ BOOST_CHECK_EQUAL (a.overlap(b).get(), DCPTimePeriod(DCPTime(1), DCPTime(9)));
}
--- /dev/null
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic 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.
+
+ DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "test.h"
+#include "lib/config.h"
+#include "lib/film.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/dcp_content_type.h"
+#include <boost/test/unit_test.hpp>
+
+using boost::shared_ptr;
+
+BOOST_AUTO_TEST_CASE (file_naming_test)
+{
+ dcp::FilenameFormat nf ("%c");
+ Config::instance()->set_dcp_filename_format (dcp::FilenameFormat ("%c"));
+ shared_ptr<Film> film = new_test_film ("file_naming_test");
+ film->set_name ("file_naming_test");
+ film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
+ shared_ptr<FFmpegContent> r (new FFmpegContent (film, "test/data/flat_red.png"));
+ film->examine_and_add_content (r);
+ shared_ptr<FFmpegContent> g (new FFmpegContent (film, "test/data/flat_green.png"));
+ film->examine_and_add_content (g);
+ shared_ptr<FFmpegContent> b (new FFmpegContent (film, "test/data/flat_blue.png"));
+ film->examine_and_add_content (b);
+ wait_for_jobs ();
+
+ film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
+ film->make_dcp ();
+ wait_for_jobs ();
+
+ BOOST_CHECK (boost::filesystem::exists (film->file (film->dcp_name() + "/flat_red.png.mxf")));
+ BOOST_CHECK (boost::filesystem::exists (film->file (film->dcp_name() + "/flat_green.png.mxf")));
+ BOOST_CHECK (boost::filesystem::exists (film->file (film->dcp_name() + "/flat_blue.png.mxf")));
+}
ffmpeg_pts_offset_test.cc
file_group_test.cc
file_log_test.cc
+ file_naming_test.cc
film_metadata_test.cc
frame_rate_test.cc
image_filename_sorter_test.cc