summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ab_transcode_job.cc9
-rw-r--r--src/lib/ab_transcode_job.h6
-rw-r--r--src/lib/ab_transcoder.cc98
-rw-r--r--src/lib/ab_transcoder.h25
-rw-r--r--src/lib/analyse_audio_job.cc40
-rw-r--r--src/lib/analyse_audio_job.h5
-rw-r--r--src/lib/audio_analysis.h4
-rw-r--r--src/lib/audio_buffers.cc237
-rw-r--r--src/lib/audio_buffers.h68
-rw-r--r--src/lib/audio_content.cc96
-rw-r--r--src/lib/audio_content.h78
-rw-r--r--src/lib/audio_decoder.cc131
-rw-r--r--src/lib/audio_decoder.h35
-rw-r--r--src/lib/audio_mapping.cc118
-rw-r--r--src/lib/audio_mapping.h60
-rw-r--r--src/lib/audio_sink.h15
-rw-r--r--src/lib/audio_source.cc20
-rw-r--r--src/lib/audio_source.h20
-rw-r--r--src/lib/black_decoder.cc94
-rw-r--r--src/lib/black_decoder.h (renamed from src/lib/trimmer.h)35
-rw-r--r--src/lib/combiner.cc7
-rw-r--r--src/lib/combiner.h11
-rw-r--r--src/lib/config.cc138
-rw-r--r--src/lib/config.h29
-rw-r--r--src/lib/container.cc83
-rw-r--r--src/lib/container.h78
-rw-r--r--src/lib/content.cc99
-rw-r--r--src/lib/content.h95
-rw-r--r--src/lib/cross.cc10
-rw-r--r--src/lib/cross.h4
-rw-r--r--src/lib/dci_metadata.cc33
-rw-r--r--src/lib/dci_metadata.h16
-rw-r--r--src/lib/dcp_content_type.h4
-rw-r--r--src/lib/dcp_video_frame.cc14
-rw-r--r--src/lib/dcp_video_frame.h3
-rw-r--r--src/lib/decoder.cc39
-rw-r--r--src/lib/decoder.h53
-rw-r--r--src/lib/decoder_factory.cc60
-rw-r--r--src/lib/decoder_factory.h49
-rw-r--r--src/lib/delay_line.h34
-rw-r--r--src/lib/encoder.cc156
-rw-r--r--src/lib/encoder.h30
-rw-r--r--src/lib/examine_content_job.cc67
-rw-r--r--src/lib/examine_content_job.h16
-rw-r--r--src/lib/exceptions.h5
-rw-r--r--src/lib/ffmpeg_content.cc359
-rw-r--r--src/lib/ffmpeg_content.h147
-rw-r--r--src/lib/ffmpeg_decoder.cc400
-rw-r--r--src/lib/ffmpeg_decoder.h100
-rw-r--r--src/lib/film.cc1053
-rw-r--r--src/lib/film.h336
-rw-r--r--src/lib/filter.h4
-rw-r--r--src/lib/filter_graph.cc47
-rw-r--r--src/lib/filter_graph.h32
-rw-r--r--src/lib/format.cc140
-rw-r--r--src/lib/format.h58
-rw-r--r--src/lib/gain.cc45
-rw-r--r--src/lib/i18n.h2
-rw-r--r--src/lib/image.h4
-rw-r--r--src/lib/imagemagick_content.cc114
-rw-r--r--src/lib/imagemagick_content.h46
-rw-r--r--src/lib/imagemagick_decoder.cc142
-rw-r--r--src/lib/imagemagick_decoder.h63
-rw-r--r--src/lib/job.cc8
-rw-r--r--src/lib/job.h7
-rw-r--r--src/lib/job_manager.cc2
-rw-r--r--src/lib/log.h4
-rw-r--r--src/lib/null_content.cc (renamed from src/lib/delay_line.cc)54
-rw-r--r--src/lib/null_content.h65
-rw-r--r--src/lib/options.h43
-rw-r--r--src/lib/player.cc355
-rw-r--r--src/lib/player.h89
-rw-r--r--src/lib/playlist.cc287
-rw-r--r--src/lib/playlist.h101
-rw-r--r--src/lib/po/es_ES.po6
-rw-r--r--src/lib/po/fr_FR.po6
-rw-r--r--src/lib/po/it_IT.po4
-rw-r--r--src/lib/po/sv_SE.po6
-rw-r--r--src/lib/processor.h115
-rw-r--r--src/lib/scaler.h4
-rw-r--r--src/lib/scp_dcp_job.h2
-rw-r--r--src/lib/server.cc26
-rw-r--r--src/lib/server.h9
-rw-r--r--src/lib/silence_decoder.cc78
-rw-r--r--src/lib/silence_decoder.h (renamed from src/lib/gain.h)21
-rw-r--r--src/lib/sndfile_content.cc144
-rw-r--r--src/lib/sndfile_content.h78
-rw-r--r--src/lib/sndfile_decoder.cc174
-rw-r--r--src/lib/sndfile_decoder.h41
-rw-r--r--src/lib/sound_processor.h4
-rw-r--r--src/lib/stream.cc92
-rw-r--r--src/lib/stream.h121
-rw-r--r--src/lib/subtitle.cc10
-rw-r--r--src/lib/subtitle.h14
-rw-r--r--src/lib/timer.h4
-rw-r--r--src/lib/transcode_job.cc31
-rw-r--r--src/lib/transcode_job.h11
-rw-r--r--src/lib/transcoder.cc101
-rw-r--r--src/lib/transcoder.h34
-rw-r--r--src/lib/trimmer.cc115
-rw-r--r--src/lib/types.cc56
-rw-r--r--src/lib/types.h116
-rw-r--r--src/lib/ui_signaller.h4
-rw-r--r--src/lib/util.cc353
-rw-r--r--src/lib/util.h165
-rw-r--r--src/lib/version.h4
-rw-r--r--src/lib/video_content.cc194
-rw-r--r--src/lib/video_content.h85
-rw-r--r--src/lib/video_decoder.cc72
-rw-r--r--src/lib/video_decoder.h66
-rw-r--r--src/lib/video_sink.h18
-rw-r--r--src/lib/video_source.cc24
-rw-r--r--src/lib/video_source.h29
-rw-r--r--src/lib/writer.cc68
-rw-r--r--src/lib/writer.h4
-rw-r--r--src/lib/wscript37
116 files changed, 4950 insertions, 4030 deletions
diff --git a/src/lib/ab_transcode_job.cc b/src/lib/ab_transcode_job.cc
index 4ffdd9af6..9a883fdd9 100644
--- a/src/lib/ab_transcode_job.cc
+++ b/src/lib/ab_transcode_job.cc
@@ -32,15 +32,14 @@ using std::string;
using boost::shared_ptr;
/** @param f Film to compare.
- * @param o Decode options.
*/
-ABTranscodeJob::ABTranscodeJob (shared_ptr<Film> f, DecodeOptions o)
+ABTranscodeJob::ABTranscodeJob (shared_ptr<Film> f)
: Job (f)
- , _decode_opt (o)
{
_film_b.reset (new Film (*_film));
_film_b->set_scaler (Config::instance()->reference_scaler ());
- _film_b->set_filters (Config::instance()->reference_filters ());
+ /* XXX */
+// _film_b->set_filters (Config::instance()->reference_filters ());
}
string
@@ -54,7 +53,7 @@ ABTranscodeJob::run ()
{
try {
/* _film_b is the one with reference filters */
- ABTranscoder w (_film_b, _film, _decode_opt, this, shared_ptr<Encoder> (new Encoder (_film)));
+ ABTranscoder w (_film_b, _film, shared_from_this ());
w.go ();
set_progress (1);
set_state (FINISHED_OK);
diff --git a/src/lib/ab_transcode_job.h b/src/lib/ab_transcode_job.h
index 8e3cbe2d8..cd82d4247 100644
--- a/src/lib/ab_transcode_job.h
+++ b/src/lib/ab_transcode_job.h
@@ -23,7 +23,6 @@
#include <boost/shared_ptr.hpp>
#include "job.h"
-#include "options.h"
class Film;
@@ -38,16 +37,13 @@ class ABTranscodeJob : public Job
{
public:
ABTranscodeJob (
- boost::shared_ptr<Film> f,
- DecodeOptions o
+ boost::shared_ptr<Film> f
);
std::string name () const;
void run ();
private:
- DecodeOptions _decode_opt;
-
/** Copy of our Film using the reference filters and scaler */
boost::shared_ptr<Film> _film_b;
};
diff --git a/src/lib/ab_transcoder.cc b/src/lib/ab_transcoder.cc
index c42f0d241..1ec298626 100644
--- a/src/lib/ab_transcoder.cc
+++ b/src/lib/ab_transcoder.cc
@@ -21,18 +21,11 @@
#include <boost/shared_ptr.hpp>
#include "ab_transcoder.h"
#include "film.h"
-#include "video_decoder.h"
-#include "audio_decoder.h"
#include "encoder.h"
#include "job.h"
-#include "options.h"
#include "image.h"
-#include "decoder_factory.h"
-#include "matcher.h"
-#include "delay_line.h"
-#include "gain.h"
+#include "player.h"
#include "combiner.h"
-#include "trimmer.h"
/** @file src/ab_transcoder.cc
* @brief A transcoder which uses one Film for the left half of the screen, and a different one
@@ -50,93 +43,24 @@ using boost::dynamic_pointer_cast;
* @param e Encoder to use.
*/
-ABTranscoder::ABTranscoder (
- shared_ptr<Film> a, shared_ptr<Film> b, DecodeOptions o, Job* j, shared_ptr<Encoder> e)
- : _film_a (a)
- , _film_b (b)
+ABTranscoder::ABTranscoder (shared_ptr<Film> film_a, shared_ptr<Film> film_b, shared_ptr<Job> j)
+ : _player_a (film_a->player ())
+ , _player_b (film_b->player ())
, _job (j)
- , _encoder (e)
- , _combiner (new Combiner (a->log()))
+ , _encoder (new Encoder (film_a, j))
+ , _combiner (new Combiner)
{
- _da = decoder_factory (_film_a, o);
- _db = decoder_factory (_film_b, o);
+ _player_a->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2, _3, _4));
+ _player_b->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2, _3, _4));
- shared_ptr<AudioStream> st = _film_a->audio_stream();
- if (st && st->sample_rate()) {
- _matcher.reset (new Matcher (_film_a->log(), st->sample_rate(), _film_a->source_frame_rate()));
- }
- _delay_line.reset (new DelayLine (_film_a->log(), _film_a->audio_delay() / 1000.0f));
- _gain.reset (new Gain (_film_a->log(), _film_a->audio_gain()));
-
- int const sr = st ? st->sample_rate() : 0;
- int const trim_start = _film_a->trim_type() == Film::ENCODE ? _film_a->trim_start() : 0;
- int const trim_end = _film_a->trim_type() == Film::ENCODE ? _film_a->trim_end() : 0;
- _trimmer.reset (new Trimmer (
- _film_a->log(), trim_start, trim_end, _film_a->length().get(),
- sr, _film_a->source_frame_rate(), _film_a->dcp_frame_rate()
- ));
-
- /* Set up the decoder to use the film's set streams */
- _da.video->set_subtitle_stream (_film_a->subtitle_stream ());
- _db.video->set_subtitle_stream (_film_a->subtitle_stream ());
- if (_film_a->audio_stream ()) {
- _da.audio->set_audio_stream (_film_a->audio_stream ());
- }
-
- _da.video->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2, _3, _4));
- _db.video->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2, _3, _4));
-
- _combiner->connect_video (_delay_line);
- if (_matcher) {
- _delay_line->connect_video (_matcher);
- _matcher->connect_video (_trimmer);
- } else {
- _delay_line->connect_video (_trimmer);
- }
- _trimmer->connect_video (_encoder);
-
- _da.audio->connect_audio (_delay_line);
- if (_matcher) {
- _delay_line->connect_audio (_matcher);
- _matcher->connect_audio (_gain);
- } else {
- _delay_line->connect_audio (_gain);
- }
- _gain->connect_audio (_trimmer);
- _trimmer->connect_audio (_encoder);
+ _combiner->connect_video (_encoder);
+ _player_a->connect_audio (_encoder);
}
void
ABTranscoder::go ()
{
_encoder->process_begin ();
-
- bool done[3] = { false, false, false };
-
- while (1) {
- done[0] = _da.video->pass ();
- done[1] = _db.video->pass ();
-
- if (!done[2] && _da.audio && dynamic_pointer_cast<Decoder> (_da.audio) != dynamic_pointer_cast<Decoder> (_da.video)) {
- done[2] = _da.audio->pass ();
- } else {
- done[2] = true;
- }
-
- if (_job) {
- _da.video->set_progress (_job);
- }
-
- if (done[0] && done[1] && done[2]) {
- break;
- }
- }
-
- _delay_line->process_end ();
- if (_matcher) {
- _matcher->process_end ();
- }
- _gain->process_end ();
+ while (!_player_a->pass () || !_player_b->pass ()) {}
_encoder->process_end ();
}
-
diff --git a/src/lib/ab_transcoder.h b/src/lib/ab_transcoder.h
index 4f1b14e48..54d7ed0be 100644
--- a/src/lib/ab_transcoder.h
+++ b/src/lib/ab_transcoder.h
@@ -25,21 +25,14 @@
#include <boost/shared_ptr.hpp>
#include <stdint.h>
#include "util.h"
-#include "decoder_factory.h"
class Job;
class Encoder;
-class VideoDecoder;
-class AudioDecoder;
class Image;
class Log;
-class Subtitle;
class Film;
-class Matcher;
-class DelayLine;
-class Gain;
class Combiner;
-class Trimmer;
+class Player;
/** @class ABTranscoder
* @brief A transcoder which uses one Film for the left half of the screen, and a different one
@@ -51,24 +44,16 @@ public:
ABTranscoder (
boost::shared_ptr<Film> a,
boost::shared_ptr<Film> b,
- DecodeOptions o,
- Job* j,
- boost::shared_ptr<Encoder> e
+ boost::shared_ptr<Job> j
);
void go ();
private:
- boost::shared_ptr<Film> _film_a;
- boost::shared_ptr<Film> _film_b;
- Job* _job;
+ boost::shared_ptr<Player> _player_a;
+ boost::shared_ptr<Player> _player_b;
+ boost::shared_ptr<Job> _job;
boost::shared_ptr<Encoder> _encoder;
- Decoders _da;
- Decoders _db;
boost::shared_ptr<Combiner> _combiner;
- boost::shared_ptr<Matcher> _matcher;
- boost::shared_ptr<DelayLine> _delay_line;
- boost::shared_ptr<Gain> _gain;
- boost::shared_ptr<Trimmer> _trimmer;
boost::shared_ptr<Image> _image;
};
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc
index 88cd65fee..3a44a408f 100644
--- a/src/lib/analyse_audio_job.cc
+++ b/src/lib/analyse_audio_job.cc
@@ -21,9 +21,7 @@
#include "analyse_audio_job.h"
#include "compose.hpp"
#include "film.h"
-#include "options.h"
-#include "decoder_factory.h"
-#include "audio_decoder.h"
+#include "player.h"
#include "i18n.h"
@@ -52,29 +50,19 @@ AnalyseAudioJob::name () const
void
AnalyseAudioJob::run ()
{
- if (!_film->audio_stream () || !_film->length()) {
- set_progress (1);
- set_state (FINISHED_ERROR);
- return;
- }
-
- DecodeOptions options;
- options.decode_video = false;
-
- Decoders decoders = decoder_factory (_film, options);
- assert (decoders.audio);
+ shared_ptr<Player> player = _film->player ();
+ player->disable_video ();
- decoders.audio->set_audio_stream (_film->audio_stream ());
- decoders.audio->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1));
+ player->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1, _2));
+
+ _samples_per_point = max (int64_t (1), _film->time_to_audio_frames (_film->length()) / _num_points);
- int64_t total_audio_frames = video_frames_to_audio_frames (_film->length().get(), _film->audio_stream()->sample_rate(), _film->source_frame_rate());
- _samples_per_point = max (int64_t (1), total_audio_frames / _num_points);
+ _current.resize (_film->dcp_audio_channels ());
+ _analysis.reset (new AudioAnalysis (_film->dcp_audio_channels ()));
- _current.resize (_film->audio_stream()->channels ());
- _analysis.reset (new AudioAnalysis (_film->audio_stream()->channels()));
-
- while (!decoders.audio->pass()) {
- set_progress (float (_done) / total_audio_frames);
+ _done = 0;
+ while (player->pass ()) {
+ set_progress (double (_done) / _film->length ());
}
_analysis->write (_film->audio_analysis_path ());
@@ -84,7 +72,7 @@ AnalyseAudioJob::run ()
}
void
-AnalyseAudioJob::audio (shared_ptr<const AudioBuffers> b)
+AnalyseAudioJob::audio (shared_ptr<const AudioBuffers> b, Time t)
{
for (int i = 0; i < b->frames(); ++i) {
for (int j = 0; j < b->channels(); ++j) {
@@ -104,8 +92,8 @@ AnalyseAudioJob::audio (shared_ptr<const AudioBuffers> b)
_current[j] = AudioPoint ();
}
}
-
- ++_done;
}
+
+ _done = t;
}
diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h
index 5435e0a7c..a0786a017 100644
--- a/src/lib/analyse_audio_job.h
+++ b/src/lib/analyse_audio_job.h
@@ -19,6 +19,7 @@
#include "job.h"
#include "audio_analysis.h"
+#include "types.h"
class AudioBuffers;
@@ -31,9 +32,9 @@ public:
void run ();
private:
- void audio (boost::shared_ptr<const AudioBuffers>);
+ void audio (boost::shared_ptr<const AudioBuffers>, Time);
- int64_t _done;
+ Time _done;
int64_t _samples_per_point;
std::vector<AudioPoint> _current;
diff --git a/src/lib/audio_analysis.h b/src/lib/audio_analysis.h
index 6e0e2b78a..ec6905105 100644
--- a/src/lib/audio_analysis.h
+++ b/src/lib/audio_analysis.h
@@ -17,8 +17,8 @@
*/
-#ifndef DVDOMATIC_AUDIO_ANALYSIS_H
-#define DVDOMATIC_AUDIO_ANALYSIS_H
+#ifndef DCPOMATIC_AUDIO_ANALYSIS_H
+#define DCPOMATIC_AUDIO_ANALYSIS_H
#include <iostream>
#include <vector>
diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc
new file mode 100644
index 000000000..c3e89f130
--- /dev/null
+++ b/src/lib/audio_buffers.cc
@@ -0,0 +1,237 @@
+/*
+ Copyright (C) 2012-2013 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 <cassert>
+#include <cstring>
+#include <stdexcept>
+#include "audio_buffers.h"
+
+using std::bad_alloc;
+using boost::shared_ptr;
+
+/** Construct an AudioBuffers. Audio data is undefined after this constructor.
+ * @param channels Number of channels.
+ * @param frames Number of frames to reserve space for.
+ */
+AudioBuffers::AudioBuffers (int channels, int frames)
+ : _channels (channels)
+ , _frames (frames)
+ , _allocated_frames (frames)
+{
+ _data = static_cast<float**> (malloc (_channels * sizeof (float *)));
+ if (!_data) {
+ throw bad_alloc ();
+ }
+
+ for (int i = 0; i < _channels; ++i) {
+ _data[i] = static_cast<float*> (malloc (frames * sizeof (float)));
+ if (!_data[i]) {
+ throw bad_alloc ();
+ }
+ }
+}
+
+/** Copy constructor.
+ * @param other Other AudioBuffers; data is copied.
+ */
+AudioBuffers::AudioBuffers (AudioBuffers const & other)
+ : _channels (other._channels)
+ , _frames (other._frames)
+ , _allocated_frames (other._frames)
+{
+ _data = static_cast<float**> (malloc (_channels * sizeof (float *)));
+ if (!_data) {
+ throw bad_alloc ();
+ }
+
+ for (int i = 0; i < _channels; ++i) {
+ _data[i] = static_cast<float*> (malloc (_frames * sizeof (float)));
+ if (!_data[i]) {
+ throw bad_alloc ();
+ }
+ memcpy (_data[i], other._data[i], _frames * sizeof (float));
+ }
+}
+
+/* XXX: it's a shame that this is a copy-and-paste of the above;
+ probably fixable with c++0x.
+*/
+AudioBuffers::AudioBuffers (boost::shared_ptr<const AudioBuffers> other)
+ : _channels (other->_channels)
+ , _frames (other->_frames)
+ , _allocated_frames (other->_frames)
+{
+ _data = static_cast<float**> (malloc (_channels * sizeof (float *)));
+ if (!_data) {
+ throw bad_alloc ();
+ }
+
+ for (int i = 0; i < _channels; ++i) {
+ _data[i] = static_cast<float*> (malloc (_frames * sizeof (float)));
+ if (!_data[i]) {
+ throw bad_alloc ();
+ }
+ memcpy (_data[i], other->_data[i], _frames * sizeof (float));
+ }
+}
+
+/** AudioBuffers destructor */
+AudioBuffers::~AudioBuffers ()
+{
+ for (int i = 0; i < _channels; ++i) {
+ free (_data[i]);
+ }
+
+ free (_data);
+}
+
+/** @param c Channel index.
+ * @return Buffer for this channel.
+ */
+float*
+AudioBuffers::data (int c) const
+{
+ assert (c >= 0 && c < _channels);
+ return _data[c];
+}
+
+/** Set the number of frames that these AudioBuffers will report themselves
+ * as having.
+ * @param f Frames; must be less than or equal to the number of allocated frames.
+ */
+void
+AudioBuffers::set_frames (int f)
+{
+ assert (f <= _allocated_frames);
+ _frames = f;
+}
+
+/** Make all samples on all channels silent */
+void
+AudioBuffers::make_silent ()
+{
+ for (int i = 0; i < _channels; ++i) {
+ make_silent (i);
+ }
+}
+
+/** Make all samples on a given channel silent.
+ * @param c Channel.
+ */
+void
+AudioBuffers::make_silent (int c)
+{
+ assert (c >= 0 && c < _channels);
+
+ for (int i = 0; i < _frames; ++i) {
+ _data[c][i] = 0;
+ }
+}
+
+/** Copy data from another AudioBuffers to this one. All channels are copied.
+ * @param from AudioBuffers to copy from; must have the same number of channels as this.
+ * @param frames_to_copy Number of frames to copy.
+ * @param read_offset Offset to read from in `from'.
+ * @param write_offset Offset to write to in `to'.
+ */
+void
+AudioBuffers::copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset)
+{
+ assert (from->channels() == channels());
+
+ assert (from);
+ assert (read_offset >= 0 && (read_offset + frames_to_copy) <= from->_allocated_frames);
+ assert (write_offset >= 0 && (write_offset + frames_to_copy) <= _allocated_frames);
+
+ for (int i = 0; i < _channels; ++i) {
+ memcpy (_data[i] + write_offset, from->_data[i] + read_offset, frames_to_copy * sizeof(float));
+ }
+}
+
+/** Move audio data around.
+ * @param from Offset to move from.
+ * @param to Offset to move to.
+ * @param frames Number of frames to move.
+ */
+
+void
+AudioBuffers::move (int from, int to, int frames)
+{
+ if (frames == 0) {
+ return;
+ }
+
+ assert (from >= 0);
+ assert (from < _frames);
+ assert (to >= 0);
+ assert (to < _frames);
+ assert (frames > 0);
+ assert (frames <= _frames);
+ assert ((from + frames) <= _frames);
+ assert ((to + frames) <= _frames);
+
+ for (int i = 0; i < _channels; ++i) {
+ memmove (_data[i] + to, _data[i] + from, frames * sizeof(float));
+ }
+}
+
+/** Add data from from `from', `from_channel' to our channel `to_channel' */
+void
+AudioBuffers::accumulate_channel (AudioBuffers const * from, int from_channel, int to_channel)
+{
+ int const N = frames ();
+ assert (from->frames() == N);
+
+ float* s = from->data (from_channel);
+ float* d = _data[to_channel];
+
+ for (int i = 0; i < N; ++i) {
+ *d++ += *s++;
+ }
+}
+
+void
+AudioBuffers::ensure_size (int frames)
+{
+ if (_allocated_frames >= frames) {
+ return;
+ }
+
+ for (int i = 0; i < _channels; ++i) {
+ _data[i] = static_cast<float*> (realloc (_data[i], frames * sizeof (float)));
+ if (!_data[i]) {
+ throw bad_alloc ();
+ }
+ }
+
+ _allocated_frames = frames;
+}
+
+void
+AudioBuffers::accumulate_frames (AudioBuffers const * from, int read_offset, int write_offset, int frames)
+{
+ assert (_channels == from->channels ());
+
+ for (int i = 0; i < _channels; ++i) {
+ for (int j = 0; j < frames; ++j) {
+ _data[i][j + write_offset] += from->data()[i][j + read_offset];
+ }
+ }
+}
+
diff --git a/src/lib/audio_buffers.h b/src/lib/audio_buffers.h
new file mode 100644
index 000000000..47b8145a1
--- /dev/null
+++ b/src/lib/audio_buffers.h
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2012-2013 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 <boost/shared_ptr.hpp>
+
+/** @class AudioBuffers
+ * @brief A class to hold multi-channel audio data in float format.
+ */
+class AudioBuffers
+{
+public:
+ AudioBuffers (int channels, int frames);
+ AudioBuffers (AudioBuffers const &);
+ AudioBuffers (boost::shared_ptr<const AudioBuffers>);
+ ~AudioBuffers ();
+
+ void ensure_size (int);
+
+ float** data () const {
+ return _data;
+ }
+
+ float* data (int) const;
+
+ int channels () const {
+ return _channels;
+ }
+
+ int frames () const {
+ return _frames;
+ }
+
+ void set_frames (int f);
+
+ void make_silent ();
+ void make_silent (int c);
+
+ void copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset);
+ void move (int from, int to, int frames);
+ void accumulate_channel (AudioBuffers const *, int, int);
+ void accumulate_frames (AudioBuffers const *, int read_offset, int write_offset, int frames);
+
+private:
+ /** Number of channels */
+ int _channels;
+ /** Number of frames (where a frame is one sample across all channels) */
+ int _frames;
+ /** Number of frames that _data can hold */
+ int _allocated_frames;
+ /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
+ float** _data;
+};
diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc
new file mode 100644
index 000000000..607e71c50
--- /dev/null
+++ b/src/lib/audio_content.cc
@@ -0,0 +1,96 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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 <libcxml/cxml.h>
+#include "audio_content.h"
+
+using std::string;
+using boost::shared_ptr;
+using boost::lexical_cast;
+
+int const AudioContentProperty::AUDIO_CHANNELS = 200;
+int const AudioContentProperty::AUDIO_LENGTH = 201;
+int const AudioContentProperty::AUDIO_FRAME_RATE = 202;
+int const AudioContentProperty::AUDIO_GAIN = 203;
+int const AudioContentProperty::AUDIO_DELAY = 204;
+
+AudioContent::AudioContent (shared_ptr<const Film> f, Time s)
+ : Content (f, s)
+ , _audio_gain (0)
+ , _audio_delay (0)
+{
+
+}
+
+AudioContent::AudioContent (shared_ptr<const Film> f, boost::filesystem::path p)
+ : Content (f, p)
+ , _audio_gain (0)
+ , _audio_delay (0)
+{
+
+}
+
+AudioContent::AudioContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
+ : Content (f, node)
+{
+ _audio_gain = node->number_child<float> ("AudioGain");
+ _audio_delay = node->number_child<int> ("AudioDelay");
+}
+
+AudioContent::AudioContent (AudioContent const & o)
+ : Content (o)
+ , _audio_gain (o._audio_gain)
+ , _audio_delay (o._audio_delay)
+{
+
+}
+
+void
+AudioContent::as_xml (xmlpp::Node* node) const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ node->add_child("AudioGain")->add_child_text (lexical_cast<string> (_audio_gain));
+ node->add_child("AudioDelay")->add_child_text (lexical_cast<string> (_audio_delay));
+}
+
+
+void
+AudioContent::set_audio_gain (float g)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _audio_gain = g;
+ }
+
+ signal_changed (AudioContentProperty::AUDIO_GAIN);
+}
+
+void
+AudioContent::set_audio_delay (int d)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _audio_delay = d;
+ }
+
+ signal_changed (AudioContentProperty::AUDIO_DELAY);
+}
+
diff --git a/src/lib/audio_content.h b/src/lib/audio_content.h
new file mode 100644
index 000000000..0c5287eaf
--- /dev/null
+++ b/src/lib/audio_content.h
@@ -0,0 +1,78 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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_AUDIO_CONTENT_H
+#define DCPOMATIC_AUDIO_CONTENT_H
+
+#include "content.h"
+#include "audio_mapping.h"
+
+namespace cxml {
+ class Node;
+}
+
+class AudioContentProperty
+{
+public:
+ static int const AUDIO_CHANNELS;
+ static int const AUDIO_LENGTH;
+ static int const AUDIO_FRAME_RATE;
+ static int const AUDIO_GAIN;
+ static int const AUDIO_DELAY;
+};
+
+class AudioContent : public virtual Content
+{
+public:
+ AudioContent (boost::shared_ptr<const Film>, Time);
+ AudioContent (boost::shared_ptr<const Film>, boost::filesystem::path);
+ AudioContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+ AudioContent (AudioContent const &);
+
+ void as_xml (xmlpp::Node *) const;
+
+ virtual int audio_channels () const = 0;
+ virtual ContentAudioFrame audio_length () const = 0;
+ virtual int content_audio_frame_rate () const = 0;
+ virtual int output_audio_frame_rate () const = 0;
+ virtual AudioMapping audio_mapping () const = 0;
+
+ void set_audio_gain (float);
+ void set_audio_delay (int);
+
+ float audio_gain () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_gain;
+ }
+
+ int audio_delay () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_delay;
+ }
+
+private:
+ /** Gain to apply to audio in dB */
+ float _audio_gain;
+ /** Delay to apply to audio (positive moves audio later) in milliseconds */
+ int _audio_delay;
+};
+
+#endif
diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc
index a54c14843..9b8d15bf1 100644
--- a/src/lib/audio_decoder.cc
+++ b/src/lib/audio_decoder.cc
@@ -18,19 +18,140 @@
*/
#include "audio_decoder.h"
-#include "stream.h"
+#include "audio_buffers.h"
+#include "exceptions.h"
+#include "log.h"
+#include "i18n.h"
+
+using std::stringstream;
+using std::list;
+using std::pair;
using boost::optional;
using boost::shared_ptr;
-AudioDecoder::AudioDecoder (shared_ptr<Film> f, DecodeOptions o)
- : Decoder (f, o)
+AudioDecoder::AudioDecoder (shared_ptr<const Film> f, shared_ptr<const AudioContent> c)
+ : Decoder (f)
+ , _next_audio (0)
+ , _audio_content (c)
{
+ if (_audio_content->content_audio_frame_rate() != _audio_content->output_audio_frame_rate()) {
+
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ stringstream s;
+ s << String::compose (
+ "Will resample audio from %1 to %2",
+ _audio_content->content_audio_frame_rate(), _audio_content->output_audio_frame_rate()
+ );
+
+ film->log()->log (s.str ());
+
+ /* We will be using planar float data when we call the
+ resampler. As far as I can see, the audio channel
+ layout is not necessary for our purposes; it seems
+ only to be used get the number of channels and
+ decide if rematrixing is needed. It won't be, since
+ input and output layouts are the same.
+ */
+
+ _swr_context = swr_alloc_set_opts (
+ 0,
+ av_get_default_channel_layout (MAX_AUDIO_CHANNELS),
+ AV_SAMPLE_FMT_FLTP,
+ _audio_content->output_audio_frame_rate(),
+ av_get_default_channel_layout (MAX_AUDIO_CHANNELS),
+ AV_SAMPLE_FMT_FLTP,
+ _audio_content->content_audio_frame_rate(),
+ 0, 0
+ );
+
+ swr_init (_swr_context);
+ } else {
+ _swr_context = 0;
+ }
+}
+AudioDecoder::~AudioDecoder ()
+{
+ if (_swr_context) {
+ swr_free (&_swr_context);
+ }
}
+
+#if 0
void
-AudioDecoder::set_audio_stream (shared_ptr<AudioStream> s)
+AudioDecoder::process_end ()
{
- _audio_stream = s;
+ if (_swr_context) {
+
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ shared_ptr<AudioBuffers> out (new AudioBuffers (film->audio_mapping().dcp_channels(), 256));
+
+ while (1) {
+ int const frames = swr_convert (_swr_context, (uint8_t **) out->data(), 256, 0, 0);
+
+ if (frames < 0) {
+ throw EncodeError (_("could not run sample-rate converter"));
+ }
+
+ if (frames == 0) {
+ break;
+ }
+
+ out->set_frames (frames);
+ _writer->write (out);
+ }
+
+ }
}
+#endif
+
+void
+AudioDecoder::audio (shared_ptr<const AudioBuffers> data, Time time)
+{
+ /* Maybe resample */
+ if (_swr_context) {
+
+ /* Compute the resampled frames count and add 32 for luck */
+ int const max_resampled_frames = ceil (
+ (int64_t) data->frames() * _audio_content->output_audio_frame_rate() / _audio_content->content_audio_frame_rate()
+ ) + 32;
+
+ shared_ptr<AudioBuffers> resampled (new AudioBuffers (data->channels(), max_resampled_frames));
+
+ /* Resample audio */
+ int const resampled_frames = swr_convert (
+ _swr_context, (uint8_t **) resampled->data(), max_resampled_frames, (uint8_t const **) data->data(), data->frames()
+ );
+
+ if (resampled_frames < 0) {
+ throw EncodeError (_("could not run sample-rate converter"));
+ }
+
+ resampled->set_frames (resampled_frames);
+
+ /* And point our variables at the resampled audio */
+ data = resampled;
+ }
+
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ /* Remap channels */
+ shared_ptr<AudioBuffers> dcp_mapped (new AudioBuffers (film->dcp_audio_channels(), data->frames()));
+ dcp_mapped->make_silent ();
+ list<pair<int, libdcp::Channel> > map = _audio_content->audio_mapping().content_to_dcp ();
+ for (list<pair<int, libdcp::Channel> >::iterator i = map.begin(); i != map.end(); ++i) {
+ dcp_mapped->accumulate_channel (data.get(), i->first, i->second);
+ }
+
+ Audio (dcp_mapped, time);
+ _next_audio = time + film->audio_frames_to_time (data->frames());
+}
+
+
diff --git a/src/lib/audio_decoder.h b/src/lib/audio_decoder.h
index cfe94b528..fb9f23f03 100644
--- a/src/lib/audio_decoder.h
+++ b/src/lib/audio_decoder.h
@@ -21,38 +21,35 @@
* @brief Parent class for audio decoders.
*/
-#ifndef DVDOMATIC_AUDIO_DECODER_H
-#define DVDOMATIC_AUDIO_DECODER_H
+#ifndef DCPOMATIC_AUDIO_DECODER_H
+#define DCPOMATIC_AUDIO_DECODER_H
#include "audio_source.h"
-#include "stream.h"
#include "decoder.h"
+extern "C" {
+#include <libswresample/swresample.h>
+}
+
+class AudioContent;
/** @class AudioDecoder.
* @brief Parent class for audio decoders.
*/
-class AudioDecoder : public TimedAudioSource, public virtual Decoder
+class AudioDecoder : public AudioSource, public virtual Decoder
{
public:
- AudioDecoder (boost::shared_ptr<Film>, DecodeOptions);
+ AudioDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const AudioContent>);
+ ~AudioDecoder ();
- virtual void set_audio_stream (boost::shared_ptr<AudioStream>);
+protected:
- /** @return Audio stream that we are using */
- boost::shared_ptr<AudioStream> audio_stream () const {
- return _audio_stream;
- }
+ void audio (boost::shared_ptr<const AudioBuffers>, Time);
- /** @return All available audio streams */
- std::vector<boost::shared_ptr<AudioStream> > audio_streams () const {
- return _audio_streams;
- }
+ Time _next_audio;
+ boost::shared_ptr<const AudioContent> _audio_content;
-protected:
- /** Audio stream that we are using */
- boost::shared_ptr<AudioStream> _audio_stream;
- /** All available audio streams */
- std::vector<boost::shared_ptr<AudioStream> > _audio_streams;
+private:
+ SwrContext* _swr_context;
};
#endif
diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc
new file mode 100644
index 000000000..d0aa33657
--- /dev/null
+++ b/src/lib/audio_mapping.cc
@@ -0,0 +1,118 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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 <boost/lexical_cast.hpp>
+#include <libxml++/libxml++.h>
+#include <libcxml/cxml.h>
+#include "audio_mapping.h"
+
+using std::list;
+using std::cout;
+using std::make_pair;
+using std::pair;
+using std::string;
+using boost::shared_ptr;
+using boost::lexical_cast;
+using boost::dynamic_pointer_cast;
+
+AudioMapping::AudioMapping ()
+{
+
+}
+
+/** Create a default AudioMapping for a given channel count.
+ * @param c Number of channels.
+ */
+AudioMapping::AudioMapping (int c)
+{
+ if (c == 1) {
+ /* Mono -> Centre */
+ add (0, libdcp::CENTRE);
+ } else {
+ /* 1:1 mapping */
+ for (int i = 0; i < c; ++i) {
+ add (i, static_cast<libdcp::Channel> (i));
+ }
+ }
+}
+
+AudioMapping::AudioMapping (shared_ptr<const cxml::Node> node)
+{
+ list<shared_ptr<cxml::Node> > const c = node->node_children ("Map");
+ for (list<shared_ptr<cxml::Node> >::const_iterator i = c.begin(); i != c.end(); ++i) {
+ add ((*i)->number_child<int> ("ContentIndex"), static_cast<libdcp::Channel> ((*i)->number_child<int> ("DCP")));
+ }
+}
+
+void
+AudioMapping::add (int c, libdcp::Channel d)
+{
+ _content_to_dcp.push_back (make_pair (c, d));
+}
+
+list<int>
+AudioMapping::dcp_to_content (libdcp::Channel d) const
+{
+ list<int> c;
+ for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
+ if (i->second == d) {
+ c.push_back (i->first);
+ }
+ }
+
+ return c;
+}
+
+list<int>
+AudioMapping::content_channels () const
+{
+ list<int> c;
+ for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
+ if (find (c.begin(), c.end(), i->first) == c.end ()) {
+ c.push_back (i->first);
+ }
+ }
+
+ return c;
+}
+
+list<libdcp::Channel>
+AudioMapping::content_to_dcp (int c) const
+{
+ list<libdcp::Channel> d;
+ for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
+ if (i->first == c) {
+ d.push_back (i->second);
+ }
+ }
+
+ return d;
+}
+
+void
+AudioMapping::as_xml (xmlpp::Node* node) const
+{
+ for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
+ xmlpp::Node* t = node->add_child ("Map");
+ t->add_child ("ContentIndex")->add_child_text (lexical_cast<string> (i->first));
+ t->add_child ("DCP")->add_child_text (lexical_cast<string> (i->second));
+ }
+}
diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h
new file mode 100644
index 000000000..7d76e4f5a
--- /dev/null
+++ b/src/lib/audio_mapping.h
@@ -0,0 +1,60 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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_AUDIO_MAPPING_H
+#define DCPOMATIC_AUDIO_MAPPING_H
+
+#include <list>
+#include <libdcp/types.h>
+#include <boost/shared_ptr.hpp>
+
+namespace xmlpp {
+ class Node;
+}
+
+namespace cxml {
+ class Node;
+}
+
+class AudioMapping
+{
+public:
+ AudioMapping ();
+ AudioMapping (int);
+ AudioMapping (boost::shared_ptr<const cxml::Node>);
+
+ void as_xml (xmlpp::Node *) const;
+
+ void add (int, libdcp::Channel);
+
+ std::list<int> dcp_to_content (libdcp::Channel) const;
+ std::list<std::pair<int, libdcp::Channel> > content_to_dcp () const {
+ return _content_to_dcp;
+ }
+
+ std::list<int> content_channels () const;
+ std::list<libdcp::Channel> content_to_dcp (int) const;
+
+private:
+ std::list<std::pair<int, libdcp::Channel> > _content_to_dcp;
+};
+
+#endif
diff --git a/src/lib/audio_sink.h b/src/lib/audio_sink.h
index 69b3a4b75..1aad5edf9 100644
--- a/src/lib/audio_sink.h
+++ b/src/lib/audio_sink.h
@@ -17,21 +17,16 @@
*/
-#ifndef DVDOMATIC_AUDIO_SINK_H
-#define DVDOMATIC_AUDIO_SINK_H
+#ifndef DCPOMATIC_AUDIO_SINK_H
+#define DCPOMATIC_AUDIO_SINK_H
+
+class AudioBuffers;
class AudioSink
{
public:
/** Call with some audio data */
- virtual void process_audio (boost::shared_ptr<const AudioBuffers>) = 0;
-};
-
-class TimedAudioSink
-{
-public:
- /** Call with some audio data */
- virtual void process_audio (boost::shared_ptr<const AudioBuffers>, double t) = 0;
+ virtual void process_audio (boost::shared_ptr<const AudioBuffers>, Time) = 0;
};
#endif
diff --git a/src/lib/audio_source.cc b/src/lib/audio_source.cc
index d77e89367..e61721646 100644
--- a/src/lib/audio_source.cc
+++ b/src/lib/audio_source.cc
@@ -21,22 +21,22 @@
#include "audio_sink.h"
using boost::shared_ptr;
+using boost::weak_ptr;
using boost::bind;
-void
-AudioSource::connect_audio (shared_ptr<AudioSink> s)
+static void
+process_audio_proxy (weak_ptr<AudioSink> sink, shared_ptr<const AudioBuffers> audio, Time time)
{
- Audio.connect (bind (&AudioSink::process_audio, s, _1));
+ shared_ptr<AudioSink> p = sink.lock ();
+ if (p) {
+ p->process_audio (audio, time);
+ }
}
void
-TimedAudioSource::connect_audio (shared_ptr<TimedAudioSink> s)
+AudioSource::connect_audio (shared_ptr<AudioSink> s)
{
- Audio.connect (bind (&TimedAudioSink::process_audio, s, _1, _2));
+ Audio.connect (bind (process_audio_proxy, weak_ptr<AudioSink> (s), _1, _2));
}
-void
-TimedAudioSource::connect_audio (shared_ptr<AudioSink> s)
-{
- Audio.connect (bind (&AudioSink::process_audio, s, _1));
-}
+
diff --git a/src/lib/audio_source.h b/src/lib/audio_source.h
index c13f1636b..ef47e969b 100644
--- a/src/lib/audio_source.h
+++ b/src/lib/audio_source.h
@@ -21,35 +21,23 @@
* @brief Parent class for classes which emit audio data.
*/
-#ifndef DVDOMATIC_AUDIO_SOURCE_H
-#define DVDOMATIC_AUDIO_SOURCE_H
+#ifndef DCPOMATIC_AUDIO_SOURCE_H
+#define DCPOMATIC_AUDIO_SOURCE_H
#include <boost/signals2.hpp>
+#include "types.h"
class AudioBuffers;
class AudioSink;
-class TimedAudioSink;
/** A class that emits audio data */
class AudioSource
{
public:
/** Emitted when some audio data is ready */
- boost::signals2::signal<void (boost::shared_ptr<const AudioBuffers>)> Audio;
+ boost::signals2::signal<void (boost::shared_ptr<const AudioBuffers>, Time)> Audio;
void connect_audio (boost::shared_ptr<AudioSink>);
};
-
-/** A class that emits audio data with timestamps */
-class TimedAudioSource
-{
-public:
- /** Emitted when some audio data is ready */
- boost::signals2::signal<void (boost::shared_ptr<const AudioBuffers>, double)> Audio;
-
- void connect_audio (boost::shared_ptr<AudioSink>);
- void connect_audio (boost::shared_ptr<TimedAudioSink>);
-};
-
#endif
diff --git a/src/lib/black_decoder.cc b/src/lib/black_decoder.cc
new file mode 100644
index 000000000..3cdd5eef5
--- /dev/null
+++ b/src/lib/black_decoder.cc
@@ -0,0 +1,94 @@
+/*
+ Copyright (C) 2013 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 "black_decoder.h"
+#include "image.h"
+#include "null_content.h"
+
+using boost::shared_ptr;
+
+BlackDecoder::BlackDecoder (shared_ptr<const Film> f, shared_ptr<NullContent> c)
+ : Decoder (f)
+ , VideoDecoder (f, c)
+{
+
+}
+
+void
+BlackDecoder::pass ()
+{
+ if (!_image) {
+ _image.reset (new SimpleImage (AV_PIX_FMT_RGB24, video_size(), true));
+ _image->make_black ();
+ video (_image, false, _next_video);
+ } else {
+ video (_image, true, _next_video);
+ }
+}
+
+float
+BlackDecoder::video_frame_rate () const
+{
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return 24;
+ }
+
+ return f->dcp_video_frame_rate ();
+}
+
+ContentVideoFrame
+BlackDecoder::video_length () const
+{
+ return _video_content->length() * video_frame_rate() / TIME_HZ;
+}
+
+Time
+BlackDecoder::next () const
+{
+ return _next_video;
+}
+
+void
+BlackDecoder::seek (Time t)
+{
+ _next_video = t;
+}
+
+void
+BlackDecoder::seek_back ()
+{
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return;
+ }
+
+ _next_video -= f->video_frames_to_time (2);
+}
+
+void
+BlackDecoder::seek_forward ()
+{
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return;
+ }
+
+ _next_video += f->video_frames_to_time (1);
+}
diff --git a/src/lib/trimmer.h b/src/lib/black_decoder.h
index 98a118fb2..3aa63e22f 100644
--- a/src/lib/trimmer.h
+++ b/src/lib/black_decoder.h
@@ -17,24 +17,31 @@
*/
-#include "processor.h"
+#include "video_decoder.h"
-class Trimmer : public AudioVideoProcessor
+class NullContent;
+
+class BlackDecoder : public VideoDecoder
{
public:
- Trimmer (boost::shared_ptr<Log>, int, int, int, int, float, int);
+ BlackDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<NullContent>);
+
+ /* Decoder */
+
+ void pass ();
+ void seek (Time);
+ void seek_back ();
+ void seek_forward ();
+ Time next () const;
+
+ /* VideoDecoder */
- void process_video (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s);
- void process_audio (boost::shared_ptr<const AudioBuffers>);
+ float video_frame_rate () const;
+ libdcp::Size video_size () const {
+ return libdcp::Size (256, 256);
+ }
+ ContentVideoFrame video_length () const;
private:
- friend class trimmer_test;
-
- int _video_start;
- int _video_end;
- int _video_in;
- int64_t _audio_start;
- int64_t _audio_end;
- int64_t _audio_in;
- bool _no_trim;
+ boost::shared_ptr<Image> _image;
};
diff --git a/src/lib/combiner.cc b/src/lib/combiner.cc
index 367cefa7f..db490fd34 100644
--- a/src/lib/combiner.cc
+++ b/src/lib/combiner.cc
@@ -22,8 +22,7 @@
using boost::shared_ptr;
-Combiner::Combiner (shared_ptr<Log> log)
- : TimedVideoProcessor (log)
+Combiner::Combiner ()
{
}
@@ -33,7 +32,7 @@ Combiner::Combiner (shared_ptr<Log> log)
* @param image Frame image.
*/
void
-Combiner::process_video (shared_ptr<const Image> image, bool, shared_ptr<Subtitle>, double)
+Combiner::process_video (shared_ptr<const Image> image, bool, shared_ptr<Subtitle>, Time)
{
_image.reset (new SimpleImage (image));
}
@@ -43,7 +42,7 @@ Combiner::process_video (shared_ptr<const Image> image, bool, shared_ptr<Subtitl
* @param sub Subtitle (which will be put onto the whole frame)
*/
void
-Combiner::process_video_b (shared_ptr<const Image> image, bool, shared_ptr<Subtitle> sub, double t)
+Combiner::process_video_b (shared_ptr<const Image> image, bool, shared_ptr<Subtitle> sub, Time t)
{
/* Copy the right half of this image into our _image */
/* XXX: this should probably be in the Image class */
diff --git a/src/lib/combiner.h b/src/lib/combiner.h
index 7ed316e26..1b7537d42 100644
--- a/src/lib/combiner.h
+++ b/src/lib/combiner.h
@@ -21,20 +21,21 @@
* @brief Class for combining two video streams.
*/
-#include "processor.h"
+#include "video_source.h"
+#include "video_sink.h"
/** @class Combiner
* @brief A class which can combine two video streams into one, with
* one image used for the left half of the screen and the other for
* the right.
*/
-class Combiner : public TimedVideoProcessor
+class Combiner : public VideoSource, public VideoSink
{
public:
- Combiner (boost::shared_ptr<Log> log);
+ Combiner ();
- void process_video (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s, double);
- void process_video_b (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s, double);
+ void process_video (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s, Time);
+ void process_video_b (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s, Time);
private:
/** The image that we are currently working on */
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 8c65e371a..c5245bfb4 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -22,11 +22,12 @@
#include <fstream>
#include <glib.h>
#include <boost/filesystem.hpp>
+#include <libcxml/cxml.h>
#include "config.h"
#include "server.h"
#include "scaler.h"
#include "filter.h"
-#include "format.h"
+#include "container.h"
#include "dcp_content_type.h"
#include "sound_processor.h"
@@ -36,7 +37,10 @@ using std::vector;
using std::ifstream;
using std::string;
using std::ofstream;
+using std::list;
using boost::shared_ptr;
+using boost::lexical_cast;
+using boost::optional;
Config* Config::_instance = 0;
@@ -47,7 +51,8 @@ Config::Config ()
, _reference_scaler (Scaler::from_id (N_("bicubic")))
, _tms_path (N_("."))
, _sound_processor (SoundProcessor::from_id (N_("dolby_cp750")))
- , _default_format (0)
+ , _default_still_length (10)
+ , _default_container (0)
, _default_dcp_content_type (0)
{
_allowed_dcp_frame_rates.push_back (24);
@@ -56,8 +61,70 @@ Config::Config ()
_allowed_dcp_frame_rates.push_back (48);
_allowed_dcp_frame_rates.push_back (50);
_allowed_dcp_frame_rates.push_back (60);
+}
+
+void
+Config::read ()
+{
+ if (!boost::filesystem::exists (file (false))) {
+ read_old_metadata ();
+ return;
+ }
+
+ cxml::File f (file (false), "Config");
+ optional<string> c;
+
+ _num_local_encoding_threads = f.number_child<int> ("NumLocalEncodingThreads");
+ _default_directory = f.string_child ("DefaultDirectory");
+ _server_port = f.number_child<int> ("ServerPort");
+ c = f.optional_string_child ("ReferenceScaler");
+ if (c) {
+ _reference_scaler = Scaler::from_id (c.get ());
+ }
+
+ list<shared_ptr<cxml::Node> > filters = f.node_children ("ReferenceFilter");
+ for (list<shared_ptr<cxml::Node> >::iterator i = filters.begin(); i != filters.end(); ++i) {
+ _reference_filters.push_back (Filter::from_id ((*i)->content ()));
+ }
- ifstream f (file().c_str ());
+ list<shared_ptr<cxml::Node> > servers = f.node_children ("Server");
+ for (list<shared_ptr<cxml::Node> >::iterator i = servers.begin(); i != servers.end(); ++i) {
+ _servers.push_back (new ServerDescription (*i));
+ }
+
+ _tms_ip = f.string_child ("TMSIP");
+ _tms_path = f.string_child ("TMSPath");
+ _tms_user = f.string_child ("TMSUser");
+ _tms_password = f.string_child ("TMSPassword");
+
+ c = f.optional_string_child ("SoundProcessor");
+ if (c) {
+ _sound_processor = SoundProcessor::from_id (c.get ());
+ }
+
+ _language = f.optional_string_child ("Language");
+
+ c = f.optional_string_child ("DefaultContainer");
+ if (c) {
+ _default_container = Container::from_id (c.get ());
+ }
+
+ c = f.optional_string_child ("DefaultDCPContentType");
+ if (c) {
+ _default_dcp_content_type = DCPContentType::from_dci_name (c.get ());
+ }
+
+ _dcp_metadata.issuer = f.optional_string_child ("DCPMetadataIssuer").get_value_or ("");
+ _dcp_metadata.creator = f.optional_string_child ("DCPMetadataCreator").get_value_or ("");
+
+ _default_dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
+ _default_still_length = f.optional_number_child<int>("DefaultStillLength").get_value_or (10);
+}
+
+void
+Config::read_old_metadata ()
+{
+ ifstream f (file(true).c_str ());
string line;
while (getline (f, line)) {
if (line.empty ()) {
@@ -100,8 +167,8 @@ Config::Config ()
_sound_processor = SoundProcessor::from_id (v);
} else if (k == "language") {
_language = v;
- } else if (k == "default_format") {
- _default_format = Format::from_metadata (v);
+ } else if (k == "default_container") {
+ _default_container = Container::from_id (v);
} else if (k == "default_dcp_content_type") {
_default_dcp_content_type = DCPContentType::from_dci_name (v);
} else if (k == "dcp_metadata_issuer") {
@@ -112,17 +179,21 @@ Config::Config ()
_dcp_metadata.issue_date = v;
}
- _default_dci_metadata.read (k, v);
+ _default_dci_metadata.read_old_metadata (k, v);
}
}
/** @return Filename to write configuration to */
string
-Config::file () const
+Config::file (bool old) const
{
boost::filesystem::path p;
p /= g_get_user_config_dir ();
- p /= N_(".dvdomatic");
+ if (old) {
+ p /= ".dvdomatic";
+ } else {
+ p /= ".dcpomatic.xml";
+ }
return p.string ();
}
@@ -132,6 +203,13 @@ Config::instance ()
{
if (_instance == 0) {
_instance = new Config;
+ try {
+ _instance->read ();
+ } catch (...) {
+ /* configuration load failed; never mind, just
+ stick with the default.
+ */
+ }
}
return _instance;
@@ -141,44 +219,48 @@ Config::instance ()
void
Config::write () const
{
- ofstream f (file().c_str ());
- f << "num_local_encoding_threads " << _num_local_encoding_threads << "\n"
- << "default_directory " << _default_directory << "\n"
- << "server_port " << _server_port << "\n";
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("Config");
+ root->add_child("NumLocalEncodingThreads")->add_child_text (lexical_cast<string> (_num_local_encoding_threads));
+ root->add_child("DefaultDirectory")->add_child_text (_default_directory);
+ root->add_child("ServerPort")->add_child_text (lexical_cast<string> (_server_port));
if (_reference_scaler) {
- f << "reference_scaler " << _reference_scaler->id () << "\n";
+ root->add_child("ReferenceScaler")->add_child_text (_reference_scaler->id ());
}
for (vector<Filter const *>::const_iterator i = _reference_filters.begin(); i != _reference_filters.end(); ++i) {
- f << "reference_filter " << (*i)->id () << "\n";
+ root->add_child("ReferenceFilter")->add_child_text ((*i)->id ());
}
for (vector<ServerDescription*>::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
- f << "server " << (*i)->as_metadata () << "\n";
+ (*i)->as_xml (root->add_child ("Server"));
}
- f << "tms_ip " << _tms_ip << "\n";
- f << "tms_path " << _tms_path << "\n";
- f << "tms_user " << _tms_user << "\n";
- f << "tms_password " << _tms_password << "\n";
+ root->add_child("TMSIP")->add_child_text (_tms_ip);
+ root->add_child("TMSPath")->add_child_text (_tms_path);
+ root->add_child("TMSUser")->add_child_text (_tms_user);
+ root->add_child("TMSPassword")->add_child_text (_tms_password);
if (_sound_processor) {
- f << "sound_processor " << _sound_processor->id () << "\n";
+ root->add_child("SoundProcessor")->add_child_text (_sound_processor->id ());
}
if (_language) {
- f << "language " << _language.get() << "\n";
+ root->add_child("Language")->add_child_text (_language.get());
}
- if (_default_format) {
- f << "default_format " << _default_format->as_metadata() << "\n";
+ if (_default_container) {
+ root->add_child("DefaultContainer")->add_child_text (_default_container->id ());
}
if (_default_dcp_content_type) {
- f << "default_dcp_content_type " << _default_dcp_content_type->dci_name() << "\n";
+ root->add_child("DefaultDCPContentType")->add_child_text (_default_dcp_content_type->dci_name ());
}
- f << "dcp_metadata_issuer " << _dcp_metadata.issuer << "\n";
- f << "dcp_metadata_creator " << _dcp_metadata.creator << "\n";
- f << "dcp_metadata_issue_date " << _dcp_metadata.issue_date << "\n";
+ root->add_child("DCPMetadataIssuer")->add_child_text (_dcp_metadata.issuer);
+ root->add_child("DCPMetadataCreator")->add_child_text (_dcp_metadata.creator);
+
+ _default_dci_metadata.as_xml (root->add_child ("DCIMetadata"));
+
+ root->add_child("DefaultStillLength")->add_child_text (lexical_cast<string> (_default_still_length));
- _default_dci_metadata.write (f);
+ doc.write_to_file_formatted (file (false));
}
string
diff --git a/src/lib/config.h b/src/lib/config.h
index a59cdcae0..c43a4f079 100644
--- a/src/lib/config.h
+++ b/src/lib/config.h
@@ -21,8 +21,8 @@
* @brief Class holding configuration.
*/
-#ifndef DVDOMATIC_CONFIG_H
-#define DVDOMATIC_CONFIG_H
+#ifndef DCPOMATIC_CONFIG_H
+#define DCPOMATIC_CONFIG_H
#include <vector>
#include <boost/shared_ptr.hpp>
@@ -34,7 +34,7 @@ class ServerDescription;
class Scaler;
class Filter;
class SoundProcessor;
-class Format;
+class Container;
class DCPContentType;
/** @class Config
@@ -110,8 +110,12 @@ public:
return _language;
}
- Format const * default_format () const {
- return _default_format;
+ int default_still_length () const {
+ return _default_still_length;
+ }
+
+ Container const * default_container () const {
+ return _default_container;
}
DCPContentType const * default_dcp_content_type () const {
@@ -185,8 +189,12 @@ public:
_language = boost::none;
}
- void set_default_format (Format const * f) {
- _default_format = f;
+ void set_default_still_length (int s) {
+ _default_still_length = s;
+ }
+
+ void set_default_container (Container const * f) {
+ _default_container = f;
}
void set_default_dcp_content_type (DCPContentType const * t) {
@@ -204,7 +212,9 @@ public:
private:
Config ();
- std::string file () const;
+ std::string file (bool) const;
+ void read ();
+ void read_old_metadata ();
/** number of threads to use for J2K encoding on the local machine */
int _num_local_encoding_threads;
@@ -233,7 +243,8 @@ private:
/** Default DCI metadata for newly-created Films */
DCIMetadata _default_dci_metadata;
boost::optional<std::string> _language;
- Format const * _default_format;
+ int _default_still_length;
+ Container const * _default_container;
DCPContentType const * _default_dcp_content_type;
libdcp::XMLMetadata _dcp_metadata;
diff --git a/src/lib/container.cc b/src/lib/container.cc
new file mode 100644
index 000000000..6eaea7300
--- /dev/null
+++ b/src/lib/container.cc
@@ -0,0 +1,83 @@
+/*
+ Copyright (C) 2013 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 <sstream>
+#include <libdcp/types.h>
+#include "container.h"
+
+#include "i18n.h"
+
+using std::string;
+using std::stringstream;
+using std::vector;
+
+vector<Container const *> Container::_containers;
+
+void
+Container::setup_containers ()
+{
+ _containers.push_back (new Container (libdcp::Size (1285, 1080), "119", _("1.19"), "F"));
+ _containers.push_back (new Container (libdcp::Size (1436, 1080), "133", _("4:3"), "F"));
+ _containers.push_back (new Container (libdcp::Size (1480, 1080), "137", _("Academy"), "F"));
+ _containers.push_back (new Container (libdcp::Size (1485, 1080), "138", _("1.375"), "F"));
+ _containers.push_back (new Container (libdcp::Size (1793, 1080), "166", _("1.66"), "F"));
+ _containers.push_back (new Container (libdcp::Size (1920, 1080), "178", _("16:9"), "F"));
+ _containers.push_back (new Container (libdcp::Size (1998, 1080), "185", _("Flat"), "F"));
+ _containers.push_back (new Container (libdcp::Size (2048, 858), "239", _("Scope"), "S"));
+ _containers.push_back (new Container (libdcp::Size (2048, 1080), "full-frame", _("Full frame"), "C"));
+}
+
+/** @return A name to be presented to the user */
+string
+Container::name () const
+{
+ stringstream s;
+ if (!_nickname.empty ()) {
+ s << _nickname << " (";
+ }
+
+ s << _dcp_size.width << "x" << _dcp_size.height;
+
+ if (!_nickname.empty ()) {
+ s << ")";
+ }
+
+ return s.str ();
+}
+
+Container const *
+Container::from_id (string i)
+{
+ vector<Container const *>::iterator j = _containers.begin ();
+ while (j != _containers.end() && (*j)->id() != i) {
+ ++j;
+ }
+
+ if (j == _containers.end ()) {
+ return 0;
+ }
+
+ return *j;
+}
+
+float
+Container::ratio () const
+{
+ return static_cast<float> (_dcp_size.width) / _dcp_size.height;
+}
diff --git a/src/lib/container.h b/src/lib/container.h
new file mode 100644
index 000000000..fc3c72792
--- /dev/null
+++ b/src/lib/container.h
@@ -0,0 +1,78 @@
+/*
+ Copyright (C) 2013 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 <vector>
+#include <libdcp/util.h>
+
+class Container
+{
+public:
+ Container (libdcp::Size dcp, std::string id, std::string n, std::string d)
+ : _dcp_size (dcp)
+ , _id (id)
+ , _nickname (n)
+ , _dci_name (d)
+ {}
+
+ /** @return 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.
+ */
+ libdcp::Size dcp_size () const {
+ return _dcp_size;
+ }
+
+ std::string id () const {
+ return _id;
+ }
+
+ /** @return Full name to present to the user */
+ std::string name () const;
+
+ /** @return Nickname (e.g. Flat, Scope) */
+ std::string nickname () const {
+ return _nickname;
+ }
+
+ std::string dci_name () const {
+ return _dci_name;
+ }
+
+ float ratio () const;
+
+ static void setup_containers ();
+ static Container const * from_id (std::string i);
+ static std::vector<Container const *> all () {
+ return _containers;
+ }
+
+private:
+ /** libdcp::Size in pixels of the images that we should
+ * put in a DCP for this container.
+ */
+ libdcp::Size _dcp_size;
+ /** id for use in metadata */
+ std::string _id;
+ /** nickname (e.g. Flat, Scope) */
+ std::string _nickname;
+ std::string _dci_name;
+
+ /** all available containers */
+ static std::vector<Container const *> _containers;
+};
diff --git a/src/lib/content.cc b/src/lib/content.cc
new file mode 100644
index 000000000..ad61f4d6c
--- /dev/null
+++ b/src/lib/content.cc
@@ -0,0 +1,99 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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 <boost/thread/mutex.hpp>
+#include <libxml++/libxml++.h>
+#include <libcxml/cxml.h>
+#include "content.h"
+#include "util.h"
+
+using std::string;
+using boost::shared_ptr;
+using boost::lexical_cast;
+
+int const ContentProperty::START = 400;
+
+Content::Content (shared_ptr<const Film> f, Time s)
+ : _film (f)
+ , _start (s)
+{
+
+}
+
+Content::Content (shared_ptr<const Film> f, boost::filesystem::path p)
+ : _film (f)
+ , _file (p)
+ , _start (0)
+{
+
+}
+
+Content::Content (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
+ : _film (f)
+{
+ _file = node->string_child ("File");
+ _digest = node->string_child ("Digest");
+ _start = node->number_child<Time> ("Start");
+}
+
+Content::Content (Content const & o)
+ : boost::enable_shared_from_this<Content> (o)
+ , _film (o._film)
+ , _file (o._file)
+ , _digest (o._digest)
+ , _start (o._start)
+{
+
+}
+
+void
+Content::as_xml (xmlpp::Node* node) const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ node->add_child("File")->add_child_text (_file.string());
+ node->add_child("Digest")->add_child_text (_digest);
+ node->add_child("Start")->add_child_text (lexical_cast<string> (_start));
+}
+
+void
+Content::examine (shared_ptr<Job>)
+{
+ string const d = md5_digest (_file);
+ boost::mutex::scoped_lock lm (_mutex);
+ _digest = d;
+}
+
+void
+Content::signal_changed (int p)
+{
+ Changed (shared_from_this (), p);
+}
+
+void
+Content::set_start (Time s)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _start = s;
+ }
+
+ signal_changed (ContentProperty::START);
+}
diff --git a/src/lib/content.h b/src/lib/content.h
new file mode 100644
index 000000000..321252c02
--- /dev/null
+++ b/src/lib/content.h
@@ -0,0 +1,95 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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_CONTENT_H
+#define DCPOMATIC_CONTENT_H
+
+#include <boost/filesystem.hpp>
+#include <boost/signals2.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/enable_shared_from_this.hpp>
+#include <libxml++/libxml++.h>
+#include "types.h"
+
+namespace cxml {
+ class Node;
+}
+
+class Job;
+class Film;
+
+class ContentProperty
+{
+public:
+ static int const START;
+};
+
+class Content : public boost::enable_shared_from_this<Content>
+{
+public:
+ Content (boost::shared_ptr<const Film>, Time);
+ Content (boost::shared_ptr<const Film>, boost::filesystem::path);
+ Content (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+ Content (Content const &);
+
+ virtual void examine (boost::shared_ptr<Job>);
+ virtual std::string summary () const = 0;
+ virtual std::string information () const = 0;
+ virtual void as_xml (xmlpp::Node *) const;
+ virtual boost::shared_ptr<Content> clone () const = 0;
+ virtual Time length () const = 0;
+
+ boost::filesystem::path file () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _file;
+ }
+
+ std::string digest () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _digest;
+ }
+
+ void set_start (Time);
+
+ Time start () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _start;
+ }
+
+ Time end () const {
+ return start() + length();
+ }
+
+ boost::signals2::signal<void (boost::weak_ptr<Content>, int)> Changed;
+
+protected:
+ void signal_changed (int);
+
+ boost::weak_ptr<const Film> _film;
+ mutable boost::mutex _mutex;
+
+private:
+ boost::filesystem::path _file;
+ std::string _digest;
+ Time _start;
+};
+
+#endif
diff --git a/src/lib/cross.cc b/src/lib/cross.cc
index 2c66ab53a..f232f1779 100644
--- a/src/lib/cross.cc
+++ b/src/lib/cross.cc
@@ -18,20 +18,20 @@
*/
#include "cross.h"
-#ifdef DVDOMATIC_POSIX
+#ifdef DCPOMATIC_POSIX
#include <unistd.h>
#endif
-#ifdef DVDOMATIC_WINDOWS
+#ifdef DCPOMATIC_WINDOWS
#include "windows.h"
#endif
void
-dvdomatic_sleep (int s)
+dcpomatic_sleep (int s)
{
-#ifdef DVDOMATIC_POSIX
+#ifdef DCPOMATIC_POSIX
sleep (s);
#endif
-#ifdef DVDOMATIC_WINDOWS
+#ifdef DCPOMATIC_WINDOWS
Sleep (s * 1000);
#endif
}
diff --git a/src/lib/cross.h b/src/lib/cross.h
index 110660b16..00457c968 100644
--- a/src/lib/cross.h
+++ b/src/lib/cross.h
@@ -17,8 +17,8 @@
*/
-#ifdef DVDOMATIC_WINDOWS
+#ifdef DCPOMATIC_WINDOWS
#define WEXITSTATUS(w) (w)
#endif
-void dvdomatic_sleep (int);
+void dcpomatic_sleep (int);
diff --git a/src/lib/dci_metadata.cc b/src/lib/dci_metadata.cc
index 758886db4..f25b3ddb0 100644
--- a/src/lib/dci_metadata.cc
+++ b/src/lib/dci_metadata.cc
@@ -18,26 +18,39 @@
*/
#include <iostream>
+#include <libcxml/cxml.h>
#include "dci_metadata.h"
#include "i18n.h"
-using namespace std;
+using std::string;
+using boost::shared_ptr;
+
+DCIMetadata::DCIMetadata (shared_ptr<const cxml::Node> node)
+{
+ audio_language = node->string_child ("AudioLanguage");
+ subtitle_language = node->string_child ("SubtitleLanguage");
+ territory = node->string_child ("Territory");
+ rating = node->string_child ("Rating");
+ studio = node->string_child ("Studio");
+ facility = node->string_child ("Facility");
+ package_type = node->string_child ("PackageType");
+}
void
-DCIMetadata::write (ostream& f) const
+DCIMetadata::as_xml (xmlpp::Node* root) const
{
- f << N_("audio_language ") << audio_language << N_("\n");
- f << N_("subtitle_language ") << subtitle_language << N_("\n");
- f << N_("territory ") << territory << N_("\n");
- f << N_("rating ") << rating << N_("\n");
- f << N_("studio ") << studio << N_("\n");
- f << N_("facility ") << facility << N_("\n");
- f << N_("package_type ") << package_type << N_("\n");
+ root->add_child("AudioLanguage")->add_child_text (audio_language);
+ root->add_child("SubtitleLanguage")->add_child_text (subtitle_language);
+ root->add_child("Territory")->add_child_text (territory);
+ root->add_child("Rating")->add_child_text (rating);
+ root->add_child("Studio")->add_child_text (studio);
+ root->add_child("Facility")->add_child_text (facility);
+ root->add_child("PackageType")->add_child_text (package_type);
}
void
-DCIMetadata::read (string k, string v)
+DCIMetadata::read_old_metadata (string k, string v)
{
if (k == N_("audio_language")) {
audio_language = v;
diff --git a/src/lib/dci_metadata.h b/src/lib/dci_metadata.h
index eecdc7655..b87609ed0 100644
--- a/src/lib/dci_metadata.h
+++ b/src/lib/dci_metadata.h
@@ -17,16 +17,24 @@
*/
-#ifndef DVDOMATIC_DCI_METADATA_H
-#define DVDOMATIC_DCI_METADATA_H
+#ifndef DCPOMATIC_DCI_METADATA_H
+#define DCPOMATIC_DCI_METADATA_H
#include <string>
+#include <libxml++/libxml++.h>
+
+namespace cxml {
+ class Node;
+}
class DCIMetadata
{
public:
- void read (std::string, std::string);
- void write (std::ostream &) const;
+ DCIMetadata () {}
+ DCIMetadata (boost::shared_ptr<const cxml::Node>);
+
+ void as_xml (xmlpp::Node *) const;
+ void read_old_metadata (std::string, std::string);
std::string audio_language;
std::string subtitle_language;
diff --git a/src/lib/dcp_content_type.h b/src/lib/dcp_content_type.h
index 960bb0129..14204bd72 100644
--- a/src/lib/dcp_content_type.h
+++ b/src/lib/dcp_content_type.h
@@ -17,8 +17,8 @@
*/
-#ifndef DVDOMATIC_DCP_CONTENT_TYPE_H
-#define DVDOMATIC_DCP_CONTENT_TYPE_H
+#ifndef DCPOMATIC_DCP_CONTENT_TYPE_H
+#define DCPOMATIC_DCP_CONTENT_TYPE_H
/** @file src/content_type.h
* @brief A description of the type of content for a DCP (e.g. feature, trailer etc.)
diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc
index d674393a9..1c1838df7 100644
--- a/src/lib/dcp_video_frame.cc
+++ b/src/lib/dcp_video_frame.cc
@@ -47,7 +47,6 @@
#include "dcp_video_frame.h"
#include "lut.h"
#include "config.h"
-#include "options.h"
#include "exceptions.h"
#include "server.h"
#include "util.h"
@@ -80,7 +79,7 @@ using libdcp::Size;
DCPVideoFrame::DCPVideoFrame (
shared_ptr<const Image> yuv, shared_ptr<Subtitle> sub,
Size out, int p, int subtitle_offset, float subtitle_scale,
- Scaler const * s, int f, int dcp_fps, string pp, int clut, int bw, shared_ptr<Log> l
+ Scaler const * s, int f, int dcp_fps, int clut, int bw, shared_ptr<Log> l
)
: _input (yuv)
, _subtitle (sub)
@@ -91,7 +90,6 @@ DCPVideoFrame::DCPVideoFrame (
, _scaler (s)
, _frame (f)
, _frames_per_second (dcp_fps)
- , _post_process (pp)
, _colour_lut (clut)
, _j2k_bandwidth (bw)
, _log (l)
@@ -157,10 +155,6 @@ DCPVideoFrame::~DCPVideoFrame ()
shared_ptr<EncodedData>
DCPVideoFrame::encode_locally ()
{
- if (!_post_process.empty ()) {
- _input = _input->post_process (_post_process, true);
- }
-
shared_ptr<Image> prepared = _input->scale_and_convert_to_rgb (_out_size, _padding, _scaler, true);
if (_subtitle) {
@@ -267,7 +261,7 @@ DCPVideoFrame::encode_locally ()
_parameters->tcp_numlayers++;
_parameters->cp_disto_alloc = 1;
_parameters->cp_rsiz = CINEMA2K;
- _parameters->cp_comment = strdup (N_("DVD-o-matic"));
+ _parameters->cp_comment = strdup (N_("DCP-o-matic"));
_parameters->cp_cinema = CINEMA2K_24;
/* 3 components, so use MCT */
@@ -334,10 +328,6 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
<< N_("frame ") << _frame << N_("\n")
<< N_("frames_per_second ") << _frames_per_second << N_("\n");
- if (!_post_process.empty()) {
- s << N_("post_process ") << _post_process << N_("\n");
- }
-
s << N_("colour_lut ") << _colour_lut << N_("\n")
<< N_("j2k_bandwidth ") << _j2k_bandwidth << N_("\n");
diff --git a/src/lib/dcp_video_frame.h b/src/lib/dcp_video_frame.h
index 4ceb07d26..ba49c95a4 100644
--- a/src/lib/dcp_video_frame.h
+++ b/src/lib/dcp_video_frame.h
@@ -107,7 +107,7 @@ class DCPVideoFrame
public:
DCPVideoFrame (
boost::shared_ptr<const Image>, boost::shared_ptr<Subtitle>, libdcp::Size,
- int, int, float, Scaler const *, int, int, std::string, int, int, boost::shared_ptr<Log>
+ int, int, float, Scaler const *, int, int, int, int, boost::shared_ptr<Log>
);
virtual ~DCPVideoFrame ();
@@ -131,7 +131,6 @@ private:
Scaler const * _scaler; ///< scaler to use
int _frame; ///< frame index within the DCP's intrinsic duration
int _frames_per_second; ///< Frames per second that we will use for the DCP
- std::string _post_process; ///< FFmpeg post-processing string to use
int _colour_lut; ///< Colour look-up table to use
int _j2k_bandwidth; ///< J2K bandwidth to use
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc
index 52b22fa06..637e0ddb2 100644
--- a/src/lib/decoder.cc
+++ b/src/lib/decoder.cc
@@ -21,55 +21,18 @@
* @brief Parent class for decoders of content.
*/
-#include <iostream>
-#include <stdint.h>
-#include <boost/lexical_cast.hpp>
#include "film.h"
-#include "format.h"
-#include "options.h"
-#include "exceptions.h"
-#include "image.h"
-#include "util.h"
-#include "log.h"
#include "decoder.h"
-#include "delay_line.h"
-#include "subtitle.h"
-#include "filter_graph.h"
#include "i18n.h"
-using std::string;
-using std::stringstream;
-using std::min;
-using std::pair;
-using std::list;
using boost::shared_ptr;
-using boost::optional;
/** @param f Film.
* @param o Decode options.
*/
-Decoder::Decoder (boost::shared_ptr<Film> f, DecodeOptions o)
+Decoder::Decoder (shared_ptr<const Film> f)
: _film (f)
- , _opt (o)
{
_film_connection = f->Changed.connect (bind (&Decoder::film_changed, this, _1));
}
-
-/** Seek to a position as a source timestamp in seconds.
- * @return true on error.
- */
-bool
-Decoder::seek (double)
-{
- throw DecodeError (N_("decoder does not support seek"));
-}
-
-/** Seek so that the next frame we will produce is the same as the last one.
- * @return true on error.
- */
-bool
-Decoder::seek_to_last ()
-{
- throw DecodeError (N_("decoder does not support seek"));
-}
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 2bc462c33..edb532b9c 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2013 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
@@ -21,20 +21,17 @@
* @brief Parent class for decoders of content.
*/
-#ifndef DVDOMATIC_DECODER_H
-#define DVDOMATIC_DECODER_H
+#ifndef DCPOMATIC_DECODER_H
+#define DCPOMATIC_DECODER_H
#include <vector>
#include <string>
#include <stdint.h>
#include <boost/shared_ptr.hpp>
#include <boost/signals2.hpp>
-#include "util.h"
-#include "stream.h"
#include "video_source.h"
#include "audio_source.h"
#include "film.h"
-#include "options.h"
class Image;
class Log;
@@ -45,34 +42,46 @@ class FilterGraph;
/** @class Decoder.
* @brief Parent class for decoders of content.
- *
- * These classes can be instructed run through their content (by
- * calling ::go), and they emit signals when video or audio data is
- * ready for something else to process.
*/
class Decoder
{
public:
- Decoder (boost::shared_ptr<Film>, DecodeOptions);
+ Decoder (boost::shared_ptr<const Film>);
virtual ~Decoder () {}
- virtual bool pass () = 0;
- virtual bool seek (double);
- virtual bool seek_to_last ();
- virtual void seek_back () {}
- virtual void seek_forward () {}
+ /** Perform one decode pass of the content, which may or may not
+ * cause the object to emit some data.
+ */
+ virtual void pass () = 0;
- boost::signals2::signal<void()> OutputChanged;
+ /** Seek this decoder to as close as possible to some time,
+ * expressed relative to our source's start.
+ * @param t Time.
+ * @param a true to try hard to be accurate, otherwise false.
+ */
+ virtual void seek (Time) = 0;
+
+ /** Seek back one video frame */
+ virtual void seek_back () = 0;
+
+ /** Seek forward one video frame */
+ virtual void seek_forward () = 0;
+
+ /** @return Approximate time of the next content that we will emit,
+ * expressed relative to the start of our source.
+ */
+ virtual Time next () const = 0;
protected:
- /** our Film */
- boost::shared_ptr<Film> _film;
- /** our decode options */
- DecodeOptions _opt;
+
+ /** The Film that we are decoding in */
+ boost::weak_ptr<const Film> _film;
private:
+ /** This will be called when our Film emits Changed */
virtual void film_changed (Film::Property) {}
-
+
+ /** Connection to our Film */
boost::signals2::scoped_connection _film_connection;
};
diff --git a/src/lib/decoder_factory.cc b/src/lib/decoder_factory.cc
deleted file mode 100644
index f7f9f4074..000000000
--- a/src/lib/decoder_factory.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- Copyright (C) 2012 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.
-
-*/
-
-/** @file src/decoder_factory.cc
- * @brief A method to create an appropriate decoder for some content.
- */
-
-#include <boost/filesystem.hpp>
-#include "ffmpeg_decoder.h"
-#include "imagemagick_decoder.h"
-#include "film.h"
-#include "sndfile_decoder.h"
-#include "decoder_factory.h"
-
-using std::string;
-using std::pair;
-using std::make_pair;
-using boost::shared_ptr;
-using boost::dynamic_pointer_cast;
-
-Decoders
-decoder_factory (
- shared_ptr<Film> f, DecodeOptions o
- )
-{
- if (f->content().empty()) {
- return Decoders ();
- }
-
- if (boost::filesystem::is_directory (f->content_path()) || f->content_type() == STILL) {
- /* A single image file, or a directory of them */
- return Decoders (
- shared_ptr<VideoDecoder> (new ImageMagickDecoder (f, o)),
- shared_ptr<AudioDecoder> (new SndfileDecoder (f, o))
- );
- }
-
- shared_ptr<FFmpegDecoder> fd (new FFmpegDecoder (f, o));
- if (f->use_content_audio()) {
- return Decoders (fd, fd);
- }
-
- return Decoders (fd, shared_ptr<AudioDecoder> (new SndfileDecoder (f, o)));
-}
diff --git a/src/lib/decoder_factory.h b/src/lib/decoder_factory.h
deleted file mode 100644
index 8076b01c7..000000000
--- a/src/lib/decoder_factory.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- Copyright (C) 2012 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 DVDOMATIC_DECODER_FACTORY_H
-#define DVDOMATIC_DECODER_FACTORY_H
-
-/** @file src/decoder_factory.h
- * @brief A method to create appropriate decoders for some content.
- */
-
-#include "options.h"
-
-class Film;
-class VideoDecoder;
-class AudioDecoder;
-
-struct Decoders {
- Decoders () {}
-
- Decoders (boost::shared_ptr<VideoDecoder> v, boost::shared_ptr<AudioDecoder> a)
- : video (v)
- , audio (a)
- {}
-
- boost::shared_ptr<VideoDecoder> video;
- boost::shared_ptr<AudioDecoder> audio;
-};
-
-extern Decoders decoder_factory (
- boost::shared_ptr<Film>, DecodeOptions
- );
-
-#endif
diff --git a/src/lib/delay_line.h b/src/lib/delay_line.h
deleted file mode 100644
index 781dce88a..000000000
--- a/src/lib/delay_line.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- Copyright (C) 2012 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 <boost/shared_ptr.hpp>
-#include "processor.h"
-
-/** A delay line */
-class DelayLine : public TimedAudioVideoProcessor
-{
-public:
- DelayLine (boost::shared_ptr<Log> log, double);
-
- void process_video (boost::shared_ptr<const Image>, bool, boost::shared_ptr<Subtitle>, double);
- void process_audio (boost::shared_ptr<const AudioBuffers>, double);
-
-private:
- double _seconds;
-};
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index 8549962ff..270bf3d43 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -27,7 +27,6 @@
#include <libdcp/picture_asset.h>
#include "encoder.h"
#include "util.h"
-#include "options.h"
#include "film.h"
#include "log.h"
#include "exceptions.h"
@@ -38,6 +37,9 @@
#include "format.h"
#include "cross.h"
#include "writer.h"
+#include "player.h"
+#include "audio_mapping.h"
+#include "container.h"
#include "i18n.h"
@@ -48,18 +50,16 @@ using std::vector;
using std::list;
using std::cout;
using std::make_pair;
-using namespace boost;
+using boost::shared_ptr;
+using boost::optional;
int const Encoder::_history_size = 25;
/** @param f Film that we are encoding */
-Encoder::Encoder (shared_ptr<Film> f)
+Encoder::Encoder (shared_ptr<Film> f, shared_ptr<Job> j)
: _film (f)
- , _video_frames_in (0)
+ , _job (j)
, _video_frames_out (0)
-#ifdef HAVE_SWRESAMPLE
- , _swr_context (0)
-#endif
, _have_a_real_frame (false)
, _terminate (false)
{
@@ -77,35 +77,6 @@ Encoder::~Encoder ()
void
Encoder::process_begin ()
{
- if (_film->audio_stream() && _film->audio_stream()->sample_rate() != _film->target_audio_sample_rate()) {
-#ifdef HAVE_SWRESAMPLE
-
- stringstream s;
- s << String::compose (N_("Will resample audio from %1 to %2"), _film->audio_stream()->sample_rate(), _film->target_audio_sample_rate());
- _film->log()->log (s.str ());
-
- /* We will be using planar float data when we call the resampler */
- _swr_context = swr_alloc_set_opts (
- 0,
- _film->audio_stream()->channel_layout(),
- AV_SAMPLE_FMT_FLTP,
- _film->target_audio_sample_rate(),
- _film->audio_stream()->channel_layout(),
- AV_SAMPLE_FMT_FLTP,
- _film->audio_stream()->sample_rate(),
- 0, 0
- );
-
- swr_init (_swr_context);
-#else
- throw EncodeError (_("Cannot resample audio as libswresample is not present"));
-#endif
- } else {
-#ifdef HAVE_SWRESAMPLE
- _swr_context = 0;
-#endif
- }
-
for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) {
_threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, (ServerDescription *) 0)));
}
@@ -118,37 +89,13 @@ Encoder::process_begin ()
}
}
- _writer.reset (new Writer (_film));
+ _writer.reset (new Writer (_film, _job));
}
void
Encoder::process_end ()
{
-#if HAVE_SWRESAMPLE
- if (_film->audio_stream() && _film->audio_stream()->channels() && _swr_context) {
-
- shared_ptr<AudioBuffers> out (new AudioBuffers (_film->audio_stream()->channels(), 256));
-
- while (1) {
- int const frames = swr_convert (_swr_context, (uint8_t **) out->data(), 256, 0, 0);
-
- if (frames < 0) {
- throw EncodeError (_("could not run sample-rate converter"));
- }
-
- if (frames == 0) {
- break;
- }
-
- out->set_frames (frames);
- write_audio (out);
- }
-
- swr_free (&_swr_context);
- }
-#endif
-
boost::mutex::scoped_lock lock (_mutex);
_film->log()->log (String::compose (N_("Clearing queue of %1"), _queue.size ()));
@@ -193,7 +140,7 @@ Encoder::process_end ()
* or 0 if not known.
*/
float
-Encoder::current_frames_per_second () const
+Encoder::current_encoding_rate () const
{
boost::mutex::scoped_lock lock (_history_mutex);
if (int (_time_history.size()) < _history_size) {
@@ -231,15 +178,8 @@ Encoder::frame_done ()
}
void
-Encoder::process_video (shared_ptr<const Image> image, bool same, boost::shared_ptr<Subtitle> sub)
+Encoder::process_video (shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub, Time)
{
- FrameRateConversion frc (_film->source_frame_rate(), _film->dcp_frame_rate());
-
- if (frc.skip && (_video_frames_in % 2)) {
- ++_video_frames_in;
- return;
- }
-
boost::mutex::scoped_lock lock (_mutex);
/* Wait until the queue has gone down a bit */
@@ -267,13 +207,13 @@ Encoder::process_video (shared_ptr<const Image> image, bool same, boost::shared_
frame_done ();
} else {
/* Queue this new frame for encoding */
- pair<string, string> const s = Filter::ffmpeg_strings (_film->filters());
TIMING ("adding to queue of %1", _queue.size ());
- _queue.push_back (boost::shared_ptr<DCPVideoFrame> (
+ /* XXX: padding */
+ _queue.push_back (shared_ptr<DCPVideoFrame> (
new DCPVideoFrame (
- image, sub, _film->format()->dcp_size(), _film->format()->dcp_padding (_film),
+ image, sub, _film->container()->dcp_size(), 0,
_film->subtitle_offset(), _film->subtitle_scale(),
- _film->scaler(), _video_frames_out, _film->dcp_frame_rate(), s.second,
+ _film->scaler(), _video_frames_out, _film->dcp_video_frame_rate(),
_film->colour_lut(), _film->j2k_bandwidth(),
_film->log()
)
@@ -283,49 +223,13 @@ Encoder::process_video (shared_ptr<const Image> image, bool same, boost::shared_
_have_a_real_frame = true;
}
- ++_video_frames_in;
++_video_frames_out;
-
- if (frc.repeat) {
- _writer->repeat (_video_frames_out);
- ++_video_frames_out;
- frame_done ();
- }
}
void
-Encoder::process_audio (shared_ptr<const AudioBuffers> data)
+Encoder::process_audio (shared_ptr<const AudioBuffers> data, Time)
{
- if (!data->frames ()) {
- return;
- }
-
-#if HAVE_SWRESAMPLE
- /* Maybe sample-rate convert */
- if (_swr_context) {
-
- /* Compute the resampled frames count and add 32 for luck */
- int const max_resampled_frames = ceil ((int64_t) data->frames() * _film->target_audio_sample_rate() / _film->audio_stream()->sample_rate()) + 32;
-
- shared_ptr<AudioBuffers> resampled (new AudioBuffers (_film->audio_stream()->channels(), max_resampled_frames));
-
- /* Resample audio */
- int const resampled_frames = swr_convert (
- _swr_context, (uint8_t **) resampled->data(), max_resampled_frames, (uint8_t const **) data->data(), data->frames()
- );
-
- if (resampled_frames < 0) {
- throw EncodeError (_("could not run sample-rate converter"));
- }
-
- resampled->set_frames (resampled_frames);
-
- /* And point our variables at the resampled audio */
- data = resampled;
- }
-#endif
-
- write_audio (data);
+ _writer->write (data);
}
void
@@ -366,7 +270,7 @@ Encoder::encoder_thread (ServerDescription* server)
}
TIMING ("encoder thread %1 wakes with queue of %2", boost::this_thread::get_id(), _queue.size());
- boost::shared_ptr<DCPVideoFrame> vf = _queue.front ();
+ shared_ptr<DCPVideoFrame> vf = _queue.front ();
_film->log()->log (String::compose (N_("Encoder thread %1 pops frame %2 from queue"), boost::this_thread::get_id(), vf->frame()), Log::VERBOSE);
_queue.pop_front ();
@@ -420,34 +324,10 @@ Encoder::encoder_thread (ServerDescription* server)
}
if (remote_backoff > 0) {
- dvdomatic_sleep (remote_backoff);
+ dcpomatic_sleep (remote_backoff);
}
lock.lock ();
_condition.notify_all ();
}
}
-
-void
-Encoder::write_audio (shared_ptr<const AudioBuffers> data)
-{
- AudioMapping m (_film->audio_channels ());
- if (m.dcp_channels() != _film->audio_channels()) {
-
- /* Remap (currently just for mono -> 5.1) */
-
- shared_ptr<AudioBuffers> b (new AudioBuffers (m.dcp_channels(), data->frames ()));
- for (int i = 0; i < m.dcp_channels(); ++i) {
- optional<int> s = m.dcp_to_source (static_cast<libdcp::Channel> (i));
- if (!s) {
- b->make_silent (i);
- } else {
- memcpy (b->data()[i], data->data()[s.get()], data->frames() * sizeof(float));
- }
- }
-
- data = b;
- }
-
- _writer->write (data);
-}
diff --git a/src/lib/encoder.h b/src/lib/encoder.h
index 70e81a7e0..6815fa6f6 100644
--- a/src/lib/encoder.h
+++ b/src/lib/encoder.h
@@ -17,8 +17,8 @@
*/
-#ifndef DVDOMATIC_ENCODER_H
-#define DVDOMATIC_ENCODER_H
+#ifndef DCPOMATIC_ENCODER_H
+#define DCPOMATIC_ENCODER_H
/** @file src/encoder.h
* @brief Encoder to J2K and WAV for DCP.
@@ -33,12 +33,8 @@
#include <stdint.h>
extern "C" {
#include <libavutil/samplefmt.h>
-}
-#ifdef HAVE_SWRESAMPLE
-extern "C" {
#include <libswresample/swresample.h>
}
-#endif
#include "util.h"
#include "video_sink.h"
#include "audio_sink.h"
@@ -51,6 +47,7 @@ class ServerDescription;
class DCPVideoFrame;
class EncodedData;
class Writer;
+class Job;
/** @class Encoder
* @brief Encoder to J2K and WAV for DCP.
@@ -62,39 +59,38 @@ class Writer;
class Encoder : public VideoSink, public AudioSink
{
public:
- Encoder (boost::shared_ptr<Film> f);
+ Encoder (boost::shared_ptr<Film> f, boost::shared_ptr<Job>);
virtual ~Encoder ();
/** Called to indicate that a processing run is about to begin */
- virtual void process_begin ();
+ void process_begin ();
/** Call with a frame of video.
* @param i Video frame image.
* @param same true if i is the same as the last time we were called.
* @param s A subtitle that should be on this frame, or 0.
*/
- void process_video (boost::shared_ptr<const Image> i, bool same, boost::shared_ptr<Subtitle> s);
+ void process_video (boost::shared_ptr<const Image> i, bool same, boost::shared_ptr<Subtitle> s, Time);
/** Call with some audio data */
- void process_audio (boost::shared_ptr<const AudioBuffers>);
+ void process_audio (boost::shared_ptr<const AudioBuffers>, Time);
/** Called when a processing run has finished */
- virtual void process_end ();
+ void process_end ();
- float current_frames_per_second () const;
+ float current_encoding_rate () const;
int video_frames_out () const;
private:
void frame_done ();
- void write_audio (boost::shared_ptr<const AudioBuffers> data);
-
void encoder_thread (ServerDescription *);
void terminate_threads ();
/** Film that we are encoding */
boost::shared_ptr<Film> _film;
+ boost::shared_ptr<Job> _job;
/** Mutex for _time_history and _last_frame */
mutable boost::mutex _history_mutex;
@@ -105,15 +101,9 @@ private:
/** Number of frames that we should keep history for */
static int const _history_size;
- /** Number of video frames received so far */
- SourceFrame _video_frames_in;
/** Number of video frames written for the DCP so far */
int _video_frames_out;
-#if HAVE_SWRESAMPLE
- SwrContext* _swr_context;
-#endif
-
bool _have_a_real_frame;
bool _terminate;
std::list<boost::shared_ptr<DCPVideoFrame> > _queue;
diff --git a/src/lib/examine_content_job.cc b/src/lib/examine_content_job.cc
index 4b30c9431..6d5f4faf9 100644
--- a/src/lib/examine_content_job.cc
+++ b/src/lib/examine_content_job.cc
@@ -17,29 +17,19 @@
*/
-/** @file src/examine_content_job.cc
- * @brief A class to run through content at high speed to find its length.
- */
-
#include <boost/filesystem.hpp>
#include "examine_content_job.h"
-#include "options.h"
-#include "decoder_factory.h"
-#include "decoder.h"
-#include "transcoder.h"
#include "log.h"
-#include "film.h"
-#include "video_decoder.h"
+#include "content.h"
#include "i18n.h"
using std::string;
-using std::vector;
-using std::pair;
using boost::shared_ptr;
-ExamineContentJob::ExamineContentJob (shared_ptr<Film> f)
+ExamineContentJob::ExamineContentJob (shared_ptr<Film> f, shared_ptr<Content> c)
: Job (f)
+ , _content (c)
{
}
@@ -51,60 +41,13 @@ ExamineContentJob::~ExamineContentJob ()
string
ExamineContentJob::name () const
{
- if (_film->name().empty ()) {
- return _("Examine content");
- }
-
- return String::compose (_("Examine content of %1"), _film->name());
+ return _("Examine content");
}
void
ExamineContentJob::run ()
{
- descend (0.5);
- _film->set_content_digest (md5_digest (_film->content_path ()));
- ascend ();
-
- descend (0.5);
-
- /* Set the film's length to either
- a) a length judged by running through the content or
- b) the length from a decoder's header.
- */
- if (!_film->trust_content_header()) {
- /* Decode the content to get an accurate length */
-
- /* We don't want to use any existing length here, as progress
- will be messed up.
- */
- _film->unset_length ();
- _film->set_crop (Crop ());
-
- DecodeOptions o;
- o.decode_audio = false;
-
- Decoders decoders = decoder_factory (_film, o);
-
- set_progress_unknown ();
- while (!decoders.video->pass()) {
- /* keep going */
- }
-
- _film->set_length (decoders.video->video_frame());
-
- _film->log()->log (String::compose (N_("Video length examined as %1 frames"), _film->length().get()));
-
- } else {
-
- /* Get a quick decoder to get the content's length from its header */
-
- Decoders d = decoder_factory (_film, DecodeOptions());
- _film->set_length (d.video->length());
-
- _film->log()->log (String::compose (N_("Video length obtained from header as %1 frames"), _film->length().get()));
- }
-
- ascend ();
+ _content->examine (shared_from_this ());
set_progress (1);
set_state (FINISHED_OK);
}
diff --git a/src/lib/examine_content_job.h b/src/lib/examine_content_job.h
index 8ee4f0d60..86f1ab111 100644
--- a/src/lib/examine_content_job.h
+++ b/src/lib/examine_content_job.h
@@ -17,22 +17,22 @@
*/
-/** @file src/examine_content_job.h
- * @brief A class to obtain the length and MD5 digest of a content file.
- */
-
+#include <boost/shared_ptr.hpp>
#include "job.h"
-/** @class ExamineContentJob
- * @brief A class to obtain the length and MD5 digest of a content file.
- */
+class Content;
+class Log;
+
class ExamineContentJob : public Job
{
public:
- ExamineContentJob (boost::shared_ptr<Film>);
+ ExamineContentJob (boost::shared_ptr<Film>, boost::shared_ptr<Content>);
~ExamineContentJob ();
std::string name () const;
void run ();
+
+private:
+ boost::shared_ptr<Content> _content;
};
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h
index e45a62353..6bad7c924 100644
--- a/src/lib/exceptions.h
+++ b/src/lib/exceptions.h
@@ -17,8 +17,8 @@
*/
-#ifndef DVDOMATIC_EXCEPTIONS_H
-#define DVDOMATIC_EXCEPTIONS_H
+#ifndef DCPOMATIC_EXCEPTIONS_H
+#define DCPOMATIC_EXCEPTIONS_H
/** @file src/exceptions.h
* @brief Our exceptions.
@@ -112,6 +112,7 @@ class OpenFileError : public FileError
{
public:
/** @param f File that we were trying to open */
+ /* XXX: should be boost::filesystem::path */
OpenFileError (std::string f);
};
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc
new file mode 100644
index 000000000..55139ca56
--- /dev/null
+++ b/src/lib/ffmpeg_content.cc
@@ -0,0 +1,359 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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 <libcxml/cxml.h>
+#include "ffmpeg_content.h"
+#include "ffmpeg_decoder.h"
+#include "compose.hpp"
+#include "job.h"
+#include "util.h"
+#include "filter.h"
+#include "log.h"
+
+#include "i18n.h"
+
+using std::string;
+using std::stringstream;
+using std::vector;
+using std::list;
+using std::cout;
+using boost::shared_ptr;
+using boost::lexical_cast;
+
+int const FFmpegContentProperty::SUBTITLE_STREAMS = 100;
+int const FFmpegContentProperty::SUBTITLE_STREAM = 101;
+int const FFmpegContentProperty::AUDIO_STREAMS = 102;
+int const FFmpegContentProperty::AUDIO_STREAM = 103;
+int const FFmpegContentProperty::FILTERS = 104;
+
+FFmpegContent::FFmpegContent (shared_ptr<const Film> f, boost::filesystem::path p)
+ : Content (f, p)
+ , VideoContent (f, p)
+ , AudioContent (f, p)
+{
+
+}
+
+FFmpegContent::FFmpegContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
+ : Content (f, node)
+ , VideoContent (f, node)
+ , AudioContent (f, node)
+{
+ list<shared_ptr<cxml::Node> > c = node->node_children ("SubtitleStream");
+ for (list<shared_ptr<cxml::Node> >::const_iterator i = c.begin(); i != c.end(); ++i) {
+ _subtitle_streams.push_back (shared_ptr<FFmpegSubtitleStream> (new FFmpegSubtitleStream (*i)));
+ if ((*i)->optional_number_child<int> ("Selected")) {
+ _subtitle_stream = _subtitle_streams.back ();
+ }
+ }
+
+ c = node->node_children ("AudioStream");
+ for (list<shared_ptr<cxml::Node> >::const_iterator i = c.begin(); i != c.end(); ++i) {
+ _audio_streams.push_back (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream (*i)));
+ if ((*i)->optional_number_child<int> ("Selected")) {
+ _audio_stream = _audio_streams.back ();
+ }
+ }
+
+ c = node->node_children ("Filter");
+ for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
+ _filters.push_back (Filter::from_id ((*i)->content ()));
+ }
+}
+
+FFmpegContent::FFmpegContent (FFmpegContent const & o)
+ : Content (o)
+ , VideoContent (o)
+ , AudioContent (o)
+ , _subtitle_streams (o._subtitle_streams)
+ , _subtitle_stream (o._subtitle_stream)
+ , _audio_streams (o._audio_streams)
+ , _audio_stream (o._audio_stream)
+{
+
+}
+
+void
+FFmpegContent::as_xml (xmlpp::Node* node) const
+{
+ node->add_child("Type")->add_child_text ("FFmpeg");
+ Content::as_xml (node);
+ VideoContent::as_xml (node);
+ AudioContent::as_xml (node);
+
+ boost::mutex::scoped_lock lm (_mutex);
+
+ for (vector<shared_ptr<FFmpegSubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
+ xmlpp::Node* t = node->add_child("SubtitleStream");
+ if (_subtitle_stream && *i == _subtitle_stream) {
+ t->add_child("Selected")->add_child_text("1");
+ }
+ (*i)->as_xml (t);
+ }
+
+ for (vector<shared_ptr<FFmpegAudioStream> >::const_iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
+ xmlpp::Node* t = node->add_child("AudioStream");
+ if (_audio_stream && *i == _audio_stream) {
+ t->add_child("Selected")->add_child_text("1");
+ }
+ (*i)->as_xml (t);
+ }
+
+ for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
+ node->add_child("Filter")->add_child_text ((*i)->id ());
+ }
+}
+
+void
+FFmpegContent::examine (shared_ptr<Job> job)
+{
+ job->set_progress_unknown ();
+
+ Content::examine (job);
+
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ shared_ptr<FFmpegDecoder> decoder (new FFmpegDecoder (film, shared_from_this (), true, false, false));
+
+ ContentVideoFrame video_length = 0;
+ video_length = decoder->video_length ();
+ film->log()->log (String::compose ("Video length obtained from header as %1 frames", decoder->video_length ()));
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+
+ _video_length = video_length;
+
+ _subtitle_streams = decoder->subtitle_streams ();
+ if (!_subtitle_streams.empty ()) {
+ _subtitle_stream = _subtitle_streams.front ();
+ }
+
+ _audio_streams = decoder->audio_streams ();
+ if (!_audio_streams.empty ()) {
+ _audio_stream = _audio_streams.front ();
+ }
+ }
+
+ take_from_video_decoder (decoder);
+
+ signal_changed (VideoContentProperty::VIDEO_LENGTH);
+ signal_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
+ signal_changed (FFmpegContentProperty::SUBTITLE_STREAM);
+ signal_changed (FFmpegContentProperty::AUDIO_STREAMS);
+ signal_changed (FFmpegContentProperty::AUDIO_STREAM);
+ signal_changed (AudioContentProperty::AUDIO_CHANNELS);
+}
+
+string
+FFmpegContent::summary () const
+{
+ return String::compose (_("Movie: %1"), file().filename().string());
+}
+
+string
+FFmpegContent::information () const
+{
+ if (video_length() == 0 || video_frame_rate() == 0) {
+ return "";
+ }
+
+ stringstream s;
+
+ s << String::compose (_("%1 frames; %2 frames per second"), video_length(), video_frame_rate()) << "\n";
+ s << VideoContent::information ();
+
+ return s.str ();
+}
+
+void
+FFmpegContent::set_subtitle_stream (shared_ptr<FFmpegSubtitleStream> s)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _subtitle_stream = s;
+ }
+
+ signal_changed (FFmpegContentProperty::SUBTITLE_STREAM);
+}
+
+void
+FFmpegContent::set_audio_stream (shared_ptr<FFmpegAudioStream> s)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _audio_stream = s;
+ }
+
+ signal_changed (FFmpegContentProperty::AUDIO_STREAM);
+}
+
+ContentAudioFrame
+FFmpegContent::audio_length () const
+{
+ int const cafr = content_audio_frame_rate ();
+ int const vfr = video_frame_rate ();
+ ContentVideoFrame const vl = video_length ();
+
+ boost::mutex::scoped_lock lm (_mutex);
+ if (!_audio_stream) {
+ return 0;
+ }
+
+ return video_frames_to_audio_frames (vl, cafr, vfr);
+}
+
+int
+FFmpegContent::audio_channels () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (!_audio_stream) {
+ return 0;
+ }
+
+ return _audio_stream->channels;
+}
+
+int
+FFmpegContent::content_audio_frame_rate () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (!_audio_stream) {
+ return 0;
+ }
+
+ return _audio_stream->frame_rate;
+}
+
+int
+FFmpegContent::output_audio_frame_rate () const
+{
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ /* Resample to a DCI-approved sample rate */
+ double t = dcp_audio_frame_rate (content_audio_frame_rate ());
+
+ FrameRateConversion frc (video_frame_rate(), film->dcp_video_frame_rate());
+
+ /* Compensate if the DCP is being run at a different frame rate
+ to the source; that is, if the video is run such that it will
+ look different in the DCP compared to the source (slower or faster).
+ skip/repeat doesn't come into effect here.
+ */
+
+ if (frc.change_speed) {
+ t *= video_frame_rate() * frc.factor() / film->dcp_video_frame_rate();
+ }
+
+ return rint (t);
+}
+
+bool
+operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b)
+{
+ return a.id == b.id;
+}
+
+bool
+operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b)
+{
+ return a.id == b.id;
+}
+
+FFmpegAudioStream::FFmpegAudioStream (shared_ptr<const cxml::Node> node)
+{
+ name = node->string_child ("Name");
+ id = node->number_child<int> ("Id");
+ frame_rate = node->number_child<int> ("FrameRate");
+ channels = node->number_child<int64_t> ("Channels");
+ mapping = AudioMapping (node->node_child ("Mapping"));
+}
+
+void
+FFmpegAudioStream::as_xml (xmlpp::Node* root) const
+{
+ root->add_child("Name")->add_child_text (name);
+ root->add_child("Id")->add_child_text (lexical_cast<string> (id));
+ root->add_child("FrameRate")->add_child_text (lexical_cast<string> (frame_rate));
+ root->add_child("Channels")->add_child_text (lexical_cast<string> (channels));
+ mapping.as_xml (root->add_child("Mapping"));
+}
+
+/** Construct a SubtitleStream from a value returned from to_string().
+ * @param t String returned from to_string().
+ * @param v State file version.
+ */
+FFmpegSubtitleStream::FFmpegSubtitleStream (shared_ptr<const cxml::Node> node)
+{
+ name = node->string_child ("Name");
+ id = node->number_child<int> ("Id");
+}
+
+void
+FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
+{
+ root->add_child("Name")->add_child_text (name);
+ root->add_child("Id")->add_child_text (lexical_cast<string> (id));
+}
+
+shared_ptr<Content>
+FFmpegContent::clone () const
+{
+ return shared_ptr<Content> (new FFmpegContent (*this));
+}
+
+Time
+FFmpegContent::length () const
+{
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ FrameRateConversion frc (video_frame_rate (), film->dcp_video_frame_rate ());
+ return video_length() * frc.factor() * TIME_HZ / film->dcp_video_frame_rate ();
+}
+
+AudioMapping
+FFmpegContent::audio_mapping () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (!_audio_stream) {
+ return AudioMapping ();
+ }
+
+ return _audio_stream->mapping;
+}
+
+void
+FFmpegContent::set_filters (vector<Filter const *> const & filters)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _filters = filters;
+ }
+
+ signal_changed (FFmpegContentProperty::FILTERS);
+}
+
diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h
new file mode 100644
index 000000000..8f5c773ee
--- /dev/null
+++ b/src/lib/ffmpeg_content.h
@@ -0,0 +1,147 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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_FFMPEG_CONTENT_H
+#define DCPOMATIC_FFMPEG_CONTENT_H
+
+#include <boost/enable_shared_from_this.hpp>
+#include "video_content.h"
+#include "audio_content.h"
+
+class Filter;
+
+class FFmpegAudioStream
+{
+public:
+ FFmpegAudioStream (std::string n, int i, int f, int c)
+ : name (n)
+ , id (i)
+ , frame_rate (f)
+ , channels (c)
+ , mapping (c)
+ {}
+
+ FFmpegAudioStream (boost::shared_ptr<const cxml::Node>);
+
+ void as_xml (xmlpp::Node *) const;
+
+ std::string name;
+ int id;
+ int frame_rate;
+ int channels;
+ AudioMapping mapping;
+};
+
+extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
+
+class FFmpegSubtitleStream
+{
+public:
+ FFmpegSubtitleStream (std::string n, int i)
+ : name (n)
+ , id (i)
+ {}
+
+ FFmpegSubtitleStream (boost::shared_ptr<const cxml::Node>);
+
+ void as_xml (xmlpp::Node *) const;
+
+ std::string name;
+ int id;
+};
+
+extern bool operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
+
+class FFmpegContentProperty : public VideoContentProperty
+{
+public:
+ static int const SUBTITLE_STREAMS;
+ static int const SUBTITLE_STREAM;
+ static int const AUDIO_STREAMS;
+ static int const AUDIO_STREAM;
+ static int const FILTERS;
+};
+
+class FFmpegContent : public VideoContent, public AudioContent
+{
+public:
+ FFmpegContent (boost::shared_ptr<const Film>, boost::filesystem::path);
+ FFmpegContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+ FFmpegContent (FFmpegContent const &);
+
+ boost::shared_ptr<FFmpegContent> shared_from_this () {
+ return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
+ }
+
+ void examine (boost::shared_ptr<Job>);
+ std::string summary () const;
+ std::string information () const;
+ void as_xml (xmlpp::Node *) const;
+ boost::shared_ptr<Content> clone () const;
+ Time length () const;
+
+ /* AudioContent */
+ int audio_channels () const;
+ ContentAudioFrame audio_length () const;
+ int content_audio_frame_rate () const;
+ int output_audio_frame_rate () const;
+ AudioMapping audio_mapping () const;
+
+ void set_filters (std::vector<Filter const *> const &);
+
+ std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _subtitle_streams;
+ }
+
+ boost::shared_ptr<FFmpegSubtitleStream> subtitle_stream () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _subtitle_stream;
+ }
+
+ std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_streams;
+ }
+
+ boost::shared_ptr<FFmpegAudioStream> audio_stream () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_stream;
+ }
+
+ std::vector<Filter const *> filters () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _filters;
+ }
+
+ void set_subtitle_stream (boost::shared_ptr<FFmpegSubtitleStream>);
+ void set_audio_stream (boost::shared_ptr<FFmpegAudioStream>);
+
+private:
+ std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
+ boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
+ std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
+ boost::shared_ptr<FFmpegAudioStream> _audio_stream;
+ /** Video filters that should be used when generating DCPs */
+ std::vector<Filter const *> _filters;
+};
+
+#endif
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 982139515..119e82851 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
@@ -41,7 +43,6 @@ extern "C" {
#include "transcoder.h"
#include "job.h"
#include "filter.h"
-#include "options.h"
#include "exceptions.h"
#include "image.h"
#include "util.h"
@@ -49,6 +50,7 @@ extern "C" {
#include "ffmpeg_decoder.h"
#include "filter_graph.h"
#include "subtitle.h"
+#include "audio_buffers.h"
#include "i18n.h"
@@ -57,15 +59,19 @@ using std::string;
using std::vector;
using std::stringstream;
using std::list;
+using std::min;
using boost::shared_ptr;
using boost::optional;
using boost::dynamic_pointer_cast;
using libdcp::Size;
-FFmpegDecoder::FFmpegDecoder (shared_ptr<Film> f, DecodeOptions o)
- : Decoder (f, o)
- , VideoDecoder (f, o)
- , AudioDecoder (f, o)
+boost::mutex FFmpegDecoder::_mutex;
+
+FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegContent> c, bool video, bool audio, bool subtitles)
+ : Decoder (f)
+ , VideoDecoder (f, c)
+ , AudioDecoder (f, c)
+ , _ffmpeg_content (c)
, _format_context (0)
, _video_stream (-1)
, _frame (0)
@@ -75,6 +81,9 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<Film> f, DecodeOptions o)
, _audio_codec (0)
, _subtitle_codec_context (0)
, _subtitle_codec (0)
+ , _decode_video (video)
+ , _decode_audio (audio)
+ , _decode_subtitles (subtitles)
{
setup_general ();
setup_video ();
@@ -84,10 +93,12 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<Film> f, DecodeOptions o)
FFmpegDecoder::~FFmpegDecoder ()
{
+ boost::mutex::scoped_lock lm (_mutex);
+
if (_audio_codec_context) {
avcodec_close (_audio_codec_context);
}
-
+
if (_video_codec_context) {
avcodec_close (_video_codec_context);
}
@@ -106,15 +117,15 @@ FFmpegDecoder::setup_general ()
{
av_register_all ();
- if (avformat_open_input (&_format_context, _film->content_path().c_str(), 0, 0) < 0) {
- throw OpenFileError (_film->content_path ());
+ if (avformat_open_input (&_format_context, _ffmpeg_content->file().string().c_str(), 0, 0) < 0) {
+ throw OpenFileError (_ffmpeg_content->file().string ());
}
if (avformat_find_stream_info (_format_context, 0) < 0) {
throw DecodeError (_("could not find stream information"));
}
- /* Find video, audio and subtitle streams and choose the first of each */
+ /* Find video, audio and subtitle streams */
for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
AVStream* s = _format_context->streams[i];
@@ -131,17 +142,13 @@ FFmpegDecoder::setup_general ()
}
_audio_streams.push_back (
- shared_ptr<AudioStream> (
- new FFmpegAudioStream (stream_name (s), i, s->codec->sample_rate, s->codec->channel_layout)
+ shared_ptr<FFmpegAudioStream> (
+ new FFmpegAudioStream (stream_name (s), i, s->codec->sample_rate, s->codec->channels)
)
);
-
+
} else if (s->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
- _subtitle_streams.push_back (
- shared_ptr<SubtitleStream> (
- new SubtitleStream (stream_name (s), i)
- )
- );
+ _subtitle_streams.push_back (shared_ptr<FFmpegSubtitleStream> (new FFmpegSubtitleStream (stream_name (s), i)));
}
}
@@ -158,6 +165,8 @@ FFmpegDecoder::setup_general ()
void
FFmpegDecoder::setup_video ()
{
+ boost::mutex::scoped_lock lm (_mutex);
+
_video_codec_context = _format_context->streams[_video_stream]->codec;
_video_codec = avcodec_find_decoder (_video_codec_context->codec_id);
@@ -173,14 +182,13 @@ FFmpegDecoder::setup_video ()
void
FFmpegDecoder::setup_audio ()
{
- if (!_audio_stream) {
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (!_ffmpeg_content->audio_stream ()) {
return;
}
- shared_ptr<FFmpegAudioStream> ffa = dynamic_pointer_cast<FFmpegAudioStream> (_audio_stream);
- assert (ffa);
-
- _audio_codec_context = _format_context->streams[ffa->id()]->codec;
+ _audio_codec_context = _format_context->streams[_ffmpeg_content->audio_stream()->id]->codec;
_audio_codec = avcodec_find_decoder (_audio_codec_context->codec_id);
if (_audio_codec == 0) {
@@ -195,11 +203,13 @@ FFmpegDecoder::setup_audio ()
void
FFmpegDecoder::setup_subtitle ()
{
- if (!_subtitle_stream || _subtitle_stream->id() >= int (_format_context->nb_streams)) {
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (!_ffmpeg_content->subtitle_stream() || _ffmpeg_content->subtitle_stream()->id >= int (_format_context->nb_streams)) {
return;
}
- _subtitle_codec_context = _format_context->streams[_subtitle_stream->id()]->codec;
+ _subtitle_codec_context = _format_context->streams[_ffmpeg_content->subtitle_stream()->id]->codec;
_subtitle_codec = avcodec_find_decoder (_subtitle_codec_context->codec_id);
if (_subtitle_codec == 0) {
@@ -212,17 +222,19 @@ FFmpegDecoder::setup_subtitle ()
}
-bool
+void
FFmpegDecoder::pass ()
{
int r = av_read_frame (_format_context, &_packet);
-
+
if (r < 0) {
if (r != AVERROR_EOF) {
/* Maybe we should fail here, but for now we'll just finish off instead */
char buf[256];
av_strerror (r, buf, sizeof(buf));
- _film->log()->log (String::compose (N_("error on av_read_frame (%1) (%2)"), buf, r));
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+ film->log()->log (String::compose (N_("error on av_read_frame (%1) (%2)"), buf, r));
}
/* Get any remaining frames */
@@ -232,41 +244,24 @@ FFmpegDecoder::pass ()
/* XXX: should we reset _packet.data and size after each *_decode_* call? */
- int frame_finished;
-
- if (_opt.decode_video) {
- while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
- filter_and_emit_video ();
- }
+ if (_decode_video) {
+ while (decode_video_packet ());
}
-
- if (_audio_stream && _opt.decode_audio) {
+
+ if (_ffmpeg_content->audio_stream() && _decode_audio) {
decode_audio_packet ();
}
- return true;
+ return;
}
avcodec_get_frame_defaults (_frame);
- shared_ptr<FFmpegAudioStream> ffa = dynamic_pointer_cast<FFmpegAudioStream> (_audio_stream);
-
- if (_packet.stream_index == _video_stream && _opt.decode_video) {
-
- int frame_finished;
- int const r = avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet);
- if (r >= 0 && frame_finished) {
-
- if (r != _packet.size) {
- _film->log()->log (String::compose (N_("Used only %1 bytes of %2 in packet"), r, _packet.size));
- }
-
- filter_and_emit_video ();
- }
-
- } else if (ffa && _packet.stream_index == ffa->id() && _opt.decode_audio) {
+ if (_packet.stream_index == _video_stream && _decode_video) {
+ decode_video_packet ();
+ } else if (_ffmpeg_content->audio_stream() && _packet.stream_index == _ffmpeg_content->audio_stream()->id && _decode_audio) {
decode_audio_packet ();
- } else if (_subtitle_stream && _packet.stream_index == _subtitle_stream->id() && _opt.decode_subtitles) {
+ } else if (_ffmpeg_content->subtitle_stream() && _packet.stream_index == _ffmpeg_content->subtitle_stream()->id && _decode_subtitles) {
int got_subtitle;
AVSubtitle sub;
@@ -277,19 +272,18 @@ FFmpegDecoder::pass ()
if (sub.num_rects > 0) {
shared_ptr<TimedSubtitle> ts;
try {
- emit_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub)));
+ subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub)));
} catch (...) {
/* some problem with the subtitle; we probably didn't understand it */
}
} else {
- emit_subtitle (shared_ptr<TimedSubtitle> ());
+ subtitle (shared_ptr<TimedSubtitle> ());
}
avsubtitle_free (&sub);
}
}
-
+
av_free_packet (&_packet);
- return false;
}
/** @param data pointer to array of pointers to buffers.
@@ -298,19 +292,16 @@ FFmpegDecoder::pass ()
shared_ptr<AudioBuffers>
FFmpegDecoder::deinterleave_audio (uint8_t** data, int size)
{
- assert (_film->audio_channels());
+ assert (_ffmpeg_content->audio_channels());
assert (bytes_per_audio_sample());
- shared_ptr<FFmpegAudioStream> ffa = dynamic_pointer_cast<FFmpegAudioStream> (_audio_stream);
- assert (ffa);
-
/* Deinterleave and convert to float */
- assert ((size % (bytes_per_audio_sample() * ffa->channels())) == 0);
+ assert ((size % (bytes_per_audio_sample() * _ffmpeg_content->audio_channels())) == 0);
int const total_samples = size / bytes_per_audio_sample();
- int const frames = total_samples / _film->audio_channels();
- shared_ptr<AudioBuffers> audio (new AudioBuffers (ffa->channels(), frames));
+ int const frames = total_samples / _ffmpeg_content->audio_channels();
+ shared_ptr<AudioBuffers> audio (new AudioBuffers (_ffmpeg_content->audio_channels(), frames));
switch (audio_sample_format()) {
case AV_SAMPLE_FMT_S16:
@@ -322,7 +313,7 @@ FFmpegDecoder::deinterleave_audio (uint8_t** data, int size)
audio->data(channel)[sample] = float(*p++) / (1 << 15);
++channel;
- if (channel == _film->audio_channels()) {
+ if (channel == _ffmpeg_content->audio_channels()) {
channel = 0;
++sample;
}
@@ -333,7 +324,7 @@ FFmpegDecoder::deinterleave_audio (uint8_t** data, int size)
case AV_SAMPLE_FMT_S16P:
{
int16_t** p = reinterpret_cast<int16_t **> (data);
- for (int i = 0; i < _film->audio_channels(); ++i) {
+ for (int i = 0; i < _ffmpeg_content->audio_channels(); ++i) {
for (int j = 0; j < frames; ++j) {
audio->data(i)[j] = static_cast<float>(p[i][j]) / (1 << 15);
}
@@ -350,7 +341,7 @@ FFmpegDecoder::deinterleave_audio (uint8_t** data, int size)
audio->data(channel)[sample] = static_cast<float>(*p++) / (1 << 31);
++channel;
- if (channel == _film->audio_channels()) {
+ if (channel == _ffmpeg_content->audio_channels()) {
channel = 0;
++sample;
}
@@ -367,7 +358,7 @@ FFmpegDecoder::deinterleave_audio (uint8_t** data, int size)
audio->data(channel)[sample] = *p++;
++channel;
- if (channel == _film->audio_channels()) {
+ if (channel == _ffmpeg_content->audio_channels()) {
channel = 0;
++sample;
}
@@ -378,7 +369,7 @@ FFmpegDecoder::deinterleave_audio (uint8_t** data, int size)
case AV_SAMPLE_FMT_FLTP:
{
float** p = reinterpret_cast<float**> (data);
- for (int i = 0; i < _film->audio_channels(); ++i) {
+ for (int i = 0; i < _ffmpeg_content->audio_channels(); ++i) {
memcpy (audio->data(i), p[i], frames * sizeof(float));
}
}
@@ -392,7 +383,7 @@ FFmpegDecoder::deinterleave_audio (uint8_t** data, int size)
}
float
-FFmpegDecoder::frames_per_second () const
+FFmpegDecoder::video_frame_rate () const
{
AVStream* s = _format_context->streams[_video_stream];
@@ -414,41 +405,11 @@ FFmpegDecoder::audio_sample_format () const
}
libdcp::Size
-FFmpegDecoder::native_size () const
+FFmpegDecoder::video_size () const
{
return libdcp::Size (_video_codec_context->width, _video_codec_context->height);
}
-PixelFormat
-FFmpegDecoder::pixel_format () const
-{
- return _video_codec_context->pix_fmt;
-}
-
-int
-FFmpegDecoder::time_base_numerator () const
-{
- return _video_codec_context->time_base.num;
-}
-
-int
-FFmpegDecoder::time_base_denominator () const
-{
- return _video_codec_context->time_base.den;
-}
-
-int
-FFmpegDecoder::sample_aspect_ratio_numerator () const
-{
- return _video_codec_context->sample_aspect_ratio.num;
-}
-
-int
-FFmpegDecoder::sample_aspect_ratio_denominator () const
-{
- return _video_codec_context->sample_aspect_ratio.den;
-}
-
string
FFmpegDecoder::stream_name (AVStream* s) const
{
@@ -483,89 +444,36 @@ FFmpegDecoder::bytes_per_audio_sample () const
}
void
-FFmpegDecoder::set_audio_stream (shared_ptr<AudioStream> s)
-{
- AudioDecoder::set_audio_stream (s);
- setup_audio ();
-}
-
-void
-FFmpegDecoder::set_subtitle_stream (shared_ptr<SubtitleStream> s)
+FFmpegDecoder::seek (Time t)
{
- VideoDecoder::set_subtitle_stream (s);
- setup_subtitle ();
- OutputChanged ();
+ do_seek (t, false, false);
}
void
-FFmpegDecoder::filter_and_emit_video ()
+FFmpegDecoder::seek_back ()
{
- int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
- if (bet == AV_NOPTS_VALUE) {
- _film->log()->log ("Dropping frame without PTS");
+ if (next() < (2.5 * TIME_HZ / video_frame_rate())) {
return;
}
- shared_ptr<FilterGraph> graph;
-
- {
- boost::mutex::scoped_lock lm (_filter_graphs_mutex);
-
- list<shared_ptr<FilterGraph> >::iterator i = _filter_graphs.begin();
- while (i != _filter_graphs.end() && !(*i)->can_process (libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format)) {
- ++i;
- }
-
- if (i == _filter_graphs.end ()) {
- graph = filter_graph_factory (_film, this, libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format);
- _filter_graphs.push_back (graph);
- _film->log()->log (String::compose (N_("New graph for %1x%2, pixel format %3"), _frame->width, _frame->height, _frame->format));
- } else {
- graph = *i;
- }
- }
-
- list<shared_ptr<Image> > images = graph->process (_frame);
-
- for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) {
- emit_video (*i, false, bet * av_q2d (_format_context->streams[_video_stream]->time_base));
- }
-}
-
-bool
-FFmpegDecoder::seek (double p)
-{
- return do_seek (p, false, false);
-}
-
-bool
-FFmpegDecoder::seek_to_last ()
-{
- /* This AVSEEK_FLAG_BACKWARD in do_seek is a bit of a hack; without it, if we ask for a seek to the same place as last time
- (used when we change decoder parameters and want to re-fetch the frame) we end up going forwards rather than
- staying in the same place.
- */
- return do_seek (last_source_time(), true, false);
-}
-
-void
-FFmpegDecoder::seek_back ()
-{
- do_seek (last_source_time() - 2.5 / frames_per_second (), true, true);
+ do_seek (next() - 2.5 * TIME_HZ / video_frame_rate(), true, true);
}
void
FFmpegDecoder::seek_forward ()
{
- do_seek (last_source_time() - 0.5 / frames_per_second(), true, true);
+ if (next() >= (_ffmpeg_content->length() - 0.5 * TIME_HZ / video_frame_rate())) {
+ return;
+ }
+
+ do_seek (next() - 0.5 * TIME_HZ / video_frame_rate(), true, true);
}
-bool
-FFmpegDecoder::do_seek (double p, bool backwards, bool accurate)
+void
+FFmpegDecoder::do_seek (Time t, bool backwards, bool accurate)
{
- int64_t const vt = p / av_q2d (_format_context->streams[_video_stream]->time_base);
-
- int const r = av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0);
+ int64_t const vt = t / (av_q2d (_format_context->streams[_video_stream]->time_base) * TIME_HZ);
+ av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0);
avcodec_flush_buffers (_video_codec_context);
if (_subtitle_codec_context) {
@@ -576,7 +484,7 @@ FFmpegDecoder::do_seek (double p, bool backwards, bool accurate)
while (1) {
int r = av_read_frame (_format_context, &_packet);
if (r < 0) {
- return true;
+ return;
}
avcodec_get_frame_defaults (_frame);
@@ -595,93 +503,20 @@ FFmpegDecoder::do_seek (double p, bool backwards, bool accurate)
av_free_packet (&_packet);
}
}
-
- return r < 0;
-}
-
-shared_ptr<FFmpegAudioStream>
-FFmpegAudioStream::create (string t, optional<int> v)
-{
- if (!v) {
- /* version < 1; no type in the string, and there's only FFmpeg streams anyway */
- return shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream (t, v));
- }
-
- stringstream s (t);
- string type;
- s >> type;
- if (type != N_("ffmpeg")) {
- return shared_ptr<FFmpegAudioStream> ();
- }
-
- return shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream (t, v));
-}
-
-FFmpegAudioStream::FFmpegAudioStream (string t, optional<int> version)
-{
- stringstream n (t);
-
- int name_index = 4;
- if (!version) {
- name_index = 2;
- int channels;
- n >> _id >> channels;
- _channel_layout = av_get_default_channel_layout (channels);
- _sample_rate = 0;
- } else {
- string type;
- /* Current (marked version 1) */
- n >> type >> _id >> _sample_rate >> _channel_layout;
- assert (type == N_("ffmpeg"));
- }
-
- for (int i = 0; i < name_index; ++i) {
- size_t const s = t.find (' ');
- if (s != string::npos) {
- t = t.substr (s + 1);
- }
- }
-
- _name = t;
-}
-
-string
-FFmpegAudioStream::to_string () const
-{
- return String::compose (N_("ffmpeg %1 %2 %3 %4"), _id, _sample_rate, _channel_layout, _name);
-}
-
-void
-FFmpegDecoder::film_changed (Film::Property p)
-{
- switch (p) {
- case Film::CROP:
- case Film::FILTERS:
- {
- boost::mutex::scoped_lock lm (_filter_graphs_mutex);
- _filter_graphs.clear ();
- }
- OutputChanged ();
- break;
- default:
- break;
- }
+ return;
}
/** @return Length (in video frames) according to our content's header */
-SourceFrame
-FFmpegDecoder::length () const
+ContentVideoFrame
+FFmpegDecoder::video_length () const
{
- return (double(_format_context->duration) / AV_TIME_BASE) * frames_per_second();
+ return (double(_format_context->duration) / AV_TIME_BASE) * video_frame_rate();
}
void
FFmpegDecoder::decode_audio_packet ()
{
- shared_ptr<FFmpegAudioStream> ffa = dynamic_pointer_cast<FFmpegAudioStream> (_audio_stream);
- assert (ffa);
-
/* Audio packets can contain multiple frames, so we may have to call avcodec_decode_audio4
several times.
*/
@@ -703,7 +538,7 @@ FFmpegDecoder::decode_audio_packet ()
0, _audio_codec_context->channels, _frame->nb_samples, audio_sample_format (), 1
);
- assert (_audio_codec_context->channels == _film->audio_channels());
+ assert (_audio_codec_context->channels == _ffmpeg_content->audio_channels());
Audio (deinterleave_audio (_frame->data, data_size), source_pts_seconds);
}
@@ -712,3 +547,74 @@ FFmpegDecoder::decode_audio_packet ()
}
}
}
+
+bool
+FFmpegDecoder::decode_video_packet ()
+{
+ int frame_finished;
+ if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) < 0 || !frame_finished) {
+ return false;
+ }
+
+ boost::mutex::scoped_lock lm (_filter_graphs_mutex);
+
+ shared_ptr<FilterGraph> graph;
+
+ list<shared_ptr<FilterGraph> >::iterator i = _filter_graphs.begin();
+ while (i != _filter_graphs.end() && !(*i)->can_process (libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format)) {
+ ++i;
+ }
+
+ if (i == _filter_graphs.end ()) {
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ graph.reset (new FilterGraph (_ffmpeg_content, libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format));
+ _filter_graphs.push_back (graph);
+
+ film->log()->log (String::compose (N_("New graph for %1x%2, pixel format %3"), _frame->width, _frame->height, _frame->format));
+ } else {
+ graph = *i;
+ }
+
+ list<shared_ptr<Image> > images = graph->process (_frame);
+
+ string post_process = Filter::ffmpeg_strings (_ffmpeg_content->filters()).second;
+
+ for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) {
+
+ shared_ptr<Image> image = *i;
+ if (!post_process.empty ()) {
+ image = image->post_process (post_process, true);
+ }
+
+ int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
+ if (bet != AV_NOPTS_VALUE) {
+ /* XXX: may need to insert extra frames / remove frames here ...
+ (as per old Matcher)
+ */
+ Time const t = bet * av_q2d (_format_context->streams[_video_stream]->time_base) * TIME_HZ;
+ video (image, false, t);
+ } else {
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+ film->log()->log ("Dropping frame without PTS");
+ }
+ }
+
+ return true;
+}
+
+Time
+FFmpegDecoder::next () const
+{
+ if (_decode_video && _decode_audio) {
+ return min (_next_video, _next_audio);
+ }
+
+ if (_decode_audio) {
+ return _next_audio;
+ }
+
+ return _next_video;
+}
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index 0c89b973d..c37479612 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
@@ -36,6 +38,7 @@ extern "C" {
#include "video_decoder.h"
#include "audio_decoder.h"
#include "film.h"
+#include "ffmpeg_content.h"
struct AVFilterGraph;
struct AVCodecContext;
@@ -50,85 +53,69 @@ class Options;
class Image;
class Log;
-class FFmpegAudioStream : public AudioStream
-{
-public:
- FFmpegAudioStream (std::string n, int i, int s, int64_t c)
- : AudioStream (s, c)
- , _name (n)
- , _id (i)
- {}
-
- std::string to_string () const;
-
- std::string name () const {
- return _name;
- }
-
- int id () const {
- return _id;
- }
-
- static boost::shared_ptr<FFmpegAudioStream> create (std::string t, boost::optional<int> v);
-
-private:
- friend class stream_test;
-
- FFmpegAudioStream (std::string t, boost::optional<int> v);
-
- std::string _name;
- int _id;
-};
-
/** @class FFmpegDecoder
* @brief A decoder using FFmpeg to decode content.
*/
class FFmpegDecoder : public VideoDecoder, public AudioDecoder
{
public:
- FFmpegDecoder (boost::shared_ptr<Film>, DecodeOptions);
+ FFmpegDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const FFmpegContent>, bool video, bool audio, bool subtitles);
~FFmpegDecoder ();
- float frames_per_second () const;
- libdcp::Size native_size () const;
- SourceFrame length () const;
- int time_base_numerator () const;
- int time_base_denominator () const;
- int sample_aspect_ratio_numerator () const;
- int sample_aspect_ratio_denominator () const;
+ /* Decoder */
- void set_audio_stream (boost::shared_ptr<AudioStream>);
- void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
-
- bool seek (double);
- bool seek_to_last ();
- void seek_forward ();
+ void pass ();
+ void seek (Time);
void seek_back ();
+ void seek_forward ();
+ Time next () const;
+
+ /* VideoDecoder */
+
+ float video_frame_rate () const;
+ libdcp::Size video_size () const;
+ ContentVideoFrame video_length () const;
+
+ /* FFmpegDecoder */
+
+ std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
+ return _subtitle_streams;
+ }
+
+ std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams () const {
+ return _audio_streams;
+ }
+
+ boost::shared_ptr<const FFmpegContent> ffmpeg_content () const {
+ return _ffmpeg_content;
+ }
private:
- bool pass ();
- bool do_seek (double p, bool, bool);
+ /* No copy construction */
+ FFmpegDecoder (FFmpegDecoder const &);
+ FFmpegDecoder& operator= (FFmpegDecoder const &);
+
PixelFormat pixel_format () const;
AVSampleFormat audio_sample_format () const;
int bytes_per_audio_sample () const;
-
- void filter_and_emit_video ();
+ void do_seek (Time, bool, bool);
void setup_general ();
void setup_video ();
void setup_audio ();
void setup_subtitle ();
+ bool decode_video_packet ();
void decode_audio_packet ();
void maybe_add_subtitle ();
boost::shared_ptr<AudioBuffers> deinterleave_audio (uint8_t** data, int size);
- void film_changed (Film::Property);
-
std::string stream_name (AVStream* s) const;
+ boost::shared_ptr<const FFmpegContent> _ffmpeg_content;
+
AVFormatContext* _format_context;
int _video_stream;
@@ -145,4 +132,17 @@ private:
std::list<boost::shared_ptr<FilterGraph> > _filter_graphs;
boost::mutex _filter_graphs_mutex;
+
+ std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
+ std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
+
+ bool _decode_video;
+ bool _decode_audio;
+ bool _decode_subtitles;
+
+ /* It would appear (though not completely verified) that one must have
+ a mutex around calls to avcodec_open* and avcodec_close... and here
+ it is.
+ */
+ static boost::mutex _mutex;
};
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 81c7de77f..fc1d2d8a4 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
@@ -29,29 +31,31 @@
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/date_time.hpp>
+#include <libxml++/libxml++.h>
+#include <libcxml/cxml.h>
#include "film.h"
-#include "format.h"
+#include "container.h"
#include "job.h"
#include "filter.h"
-#include "transcoder.h"
#include "util.h"
#include "job_manager.h"
#include "ab_transcode_job.h"
#include "transcode_job.h"
#include "scp_dcp_job.h"
#include "log.h"
-#include "options.h"
#include "exceptions.h"
#include "examine_content_job.h"
#include "scaler.h"
-#include "decoder_factory.h"
#include "config.h"
#include "version.h"
#include "ui_signaller.h"
-#include "video_decoder.h"
-#include "audio_decoder.h"
-#include "sndfile_decoder.h"
#include "analyse_audio_job.h"
+#include "playlist.h"
+#include "player.h"
+#include "ffmpeg_content.h"
+#include "imagemagick_content.h"
+#include "sndfile_content.h"
+#include "dcp_content_type.h"
#include "i18n.h"
@@ -67,6 +71,8 @@ using std::setfill;
using std::min;
using std::make_pair;
using std::endl;
+using std::cout;
+using std::list;
using boost::shared_ptr;
using boost::lexical_cast;
using boost::to_upper_copy;
@@ -77,39 +83,32 @@ using libdcp::Size;
int const Film::state_version = 4;
-/** Construct a Film object in a given directory, reading any metadata
- * file that exists in that directory. An exception will be thrown if
- * must_exist is true and the specified directory does not exist.
+/** Construct a Film object in a given directory.
*
* @param d Film directory.
- * @param must_exist true to throw an exception if does not exist.
*/
-Film::Film (string d, bool must_exist)
- : _use_dci_name (true)
- , _trust_content_header (true)
+Film::Film (string d)
+ : _playlist (new Playlist)
+ , _use_dci_name (true)
, _dcp_content_type (Config::instance()->default_dcp_content_type ())
- , _format (Config::instance()->default_format ())
+ , _container (Config::instance()->default_container ())
, _scaler (Scaler::from_id ("bicubic"))
- , _trim_start (0)
- , _trim_end (0)
- , _trim_type (CPL)
- , _dcp_ab (false)
- , _use_content_audio (true)
- , _audio_gain (0)
- , _audio_delay (0)
- , _still_duration (10)
+ , _ab (false)
, _with_subtitles (false)
, _subtitle_offset (0)
, _subtitle_scale (1)
, _colour_lut (0)
, _j2k_bandwidth (200000000)
, _dci_metadata (Config::instance()->default_dci_metadata ())
- , _dcp_frame_rate (0)
- , _source_frame_rate (0)
+ , _dcp_video_frame_rate (0)
+ , _dcp_audio_channels (MAX_AUDIO_CHANNELS)
, _dirty (false)
{
set_dci_date_today ();
+
+ _playlist->Changed.connect (bind (&Film::playlist_changed, this));
+ _playlist->ContentChanged.connect (bind (&Film::playlist_content_changed, this, _1, _2));
/* Make state.directory a complete path without ..s (where possible)
(Code swiped from Adam Bowen on stackoverflow)
@@ -130,23 +129,6 @@ Film::Film (string d, bool must_exist)
}
set_directory (result.string ());
-
- if (!boost::filesystem::exists (directory())) {
- if (must_exist) {
- throw OpenFileError (directory());
- } else {
- boost::filesystem::create_directory (directory());
- }
- }
-
- _sndfile_stream = SndfileStream::create ();
-
- if (must_exist) {
- read_metadata ();
- } else {
- write_metadata ();
- }
-
_log.reset (new FileLog (file ("log")));
}
@@ -154,71 +136,42 @@ Film::Film (Film const & o)
: boost::enable_shared_from_this<Film> (o)
/* note: the copied film shares the original's log */
, _log (o._log)
+ , _playlist (new Playlist (o._playlist))
, _directory (o._directory)
, _name (o._name)
, _use_dci_name (o._use_dci_name)
- , _content (o._content)
- , _trust_content_header (o._trust_content_header)
, _dcp_content_type (o._dcp_content_type)
- , _format (o._format)
- , _crop (o._crop)
- , _filters (o._filters)
+ , _container (o._container)
, _scaler (o._scaler)
- , _trim_start (o._trim_start)
- , _trim_end (o._trim_end)
- , _trim_type (o._trim_type)
- , _dcp_ab (o._dcp_ab)
- , _content_audio_stream (o._content_audio_stream)
- , _external_audio (o._external_audio)
- , _use_content_audio (o._use_content_audio)
- , _audio_gain (o._audio_gain)
- , _audio_delay (o._audio_delay)
- , _still_duration (o._still_duration)
- , _subtitle_stream (o._subtitle_stream)
+ , _ab (o._ab)
, _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)
, _dci_metadata (o._dci_metadata)
+ , _dcp_video_frame_rate (o._dcp_video_frame_rate)
, _dci_date (o._dci_date)
- , _dcp_frame_rate (o._dcp_frame_rate)
- , _size (o._size)
- , _length (o._length)
- , _content_digest (o._content_digest)
- , _content_audio_streams (o._content_audio_streams)
- , _sndfile_stream (o._sndfile_stream)
- , _subtitle_streams (o._subtitle_streams)
- , _source_frame_rate (o._source_frame_rate)
, _dirty (o._dirty)
{
-
-}
-
-Film::~Film ()
-{
-
+ _playlist->ContentChanged.connect (bind (&Film::playlist_content_changed, this, _1, _2));
}
string
Film::video_state_identifier () const
{
- assert (format ());
+ assert (container ());
LocaleGuard lg;
- pair<string, string> f = Filter::ffmpeg_strings (filters());
-
stringstream s;
- s << format()->id()
- << "_" << content_digest()
- << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
- << "_" << _dcp_frame_rate
- << "_" << f.first << "_" << f.second
+ s << container()->id()
+ << "_" << _playlist->video_digest()
+ << "_" << _dcp_video_frame_rate
<< "_" << scaler()->id()
<< "_" << j2k_bandwidth()
- << "_" << boost::lexical_cast<int> (colour_lut());
+ << "_" << lexical_cast<int> (colour_lut());
- if (dcp_ab()) {
+ if (ab()) {
pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
}
@@ -282,7 +235,7 @@ Film::audio_analysis_path () const
{
boost::filesystem::path p;
p /= "analysis";
- p /= content_digest();
+ p /= _playlist->audio_digest();
return file (p.string ());
}
@@ -296,7 +249,7 @@ Film::make_dcp ()
throw BadSettingError (_("name"), _("cannot contain slashes"));
}
- log()->log (String::compose ("DVD-o-matic %1 git %2 using %3", dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
+ log()->log (String::compose ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary()));
{
char buffer[128];
@@ -304,18 +257,18 @@ Film::make_dcp ()
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"))));
- if (length()) {
- log()->log (String::compose ("Content length %1", length().get()));
- }
- log()->log (String::compose ("Content digest %1", content_digest()));
- log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
+// log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? _("still") : _("video"))));
+// if (length()) {
+// log()->log (String::compose ("Content length %1", length().get()));
+// }
+// log()->log (String::compose ("Content digest %1", content_digest()));
+// log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
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.");
+#ifdef DCPOMATIC_DEBUG
+ log()->log ("DCP-o-matic built in debug mode.");
#else
- log()->log ("DVD-o-matic built in optimised mode.");
+ log()->log ("DCP-o-matic built in optimised mode.");
#endif
#ifdef LIBDCP_DEBUG
log()->log ("libdcp built in debug mode.");
@@ -325,12 +278,12 @@ Film::make_dcp ()
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"));
+ if (container() == 0) {
+ throw MissingSettingError (_("container"));
}
- if (content().empty ()) {
- throw MissingSettingError (_("content"));
+ if (_playlist->content().empty ()) {
+ throw StringError (_("You must add some content to the DCP before creating it"));
}
if (dcp_content_type() == 0) {
@@ -341,19 +294,16 @@ Film::make_dcp ()
throw MissingSettingError (_("name"));
}
- DecodeOptions od;
- od.decode_subtitles = with_subtitles ();
-
shared_ptr<Job> r;
- if (dcp_ab()) {
- r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od)));
+ if (ab()) {
+ r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this())));
} else {
- r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od)));
+ r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this())));
}
}
-/** Start a job to analyse the audio of our content file */
+/** Start a job to analyse the audio in our Playlist */
void
Film::analyse_audio ()
{
@@ -366,17 +316,12 @@ Film::analyse_audio ()
JobManager::instance()->add (_analyse_audio_job);
}
-/** Start a job to examine our content file */
+/** Start a job to examine a piece of content */
void
-Film::examine_content ()
+Film::examine_content (shared_ptr<Content> c)
{
- if (_examine_content_job) {
- return;
- }
-
- _examine_content_job.reset (new ExamineContentJob (shared_from_this()));
- _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
- JobManager::instance()->add (_examine_content_job);
+ shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), c));
+ JobManager::instance()->add (j);
}
void
@@ -391,12 +336,6 @@ Film::analyse_audio_finished ()
_analyse_audio_job.reset ();
}
-void
-Film::examine_content_finished ()
-{
- _examine_content_job.reset ();
-}
-
/** Start a job to send our DCP to the configured TMS */
void
Film::send_dcp_to_tms ()
@@ -411,7 +350,7 @@ Film::send_dcp_to_tms ()
int
Film::encoded_frames () const
{
- if (format() == 0) {
+ if (container() == 0) {
return 0;
}
@@ -428,86 +367,44 @@ Film::encoded_frames () const
void
Film::write_metadata () const
{
+ if (!boost::filesystem::exists (directory())) {
+ boost::filesystem::create_directory (directory());
+ }
+
boost::mutex::scoped_lock lm (_state_mutex);
LocaleGuard lg;
boost::filesystem::create_directories (directory());
- string const m = file ("metadata");
- ofstream f (m.c_str ());
- if (!f.good ()) {
- throw CreateFileError (m);
- }
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("Metadata");
- f << "version " << state_version << endl;
+ root->add_child("Version")->add_child_text (lexical_cast<string> (state_version));
+ root->add_child("Name")->add_child_text (_name);
+ root->add_child("UseDCIName")->add_child_text (_use_dci_name ? "1" : "0");
- /* User stuff */
- f << "name " << _name << endl;
- f << "use_dci_name " << _use_dci_name << endl;
- f << "content " << _content << endl;
- f << "trust_content_header " << (_trust_content_header ? "1" : "0") << endl;
if (_dcp_content_type) {
- f << "dcp_content_type " << _dcp_content_type->dci_name () << endl;
- }
- if (_format) {
- f << "format " << _format->as_metadata () << endl;
- }
- f << "left_crop " << _crop.left << endl;
- f << "right_crop " << _crop.right << endl;
- f << "top_crop " << _crop.top << endl;
- f << "bottom_crop " << _crop.bottom << endl;
- for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
- f << "filter " << (*i)->id () << endl;
- }
- f << "scaler " << _scaler->id () << endl;
- f << "trim_start " << _trim_start << endl;
- f << "trim_end " << _trim_end << endl;
- switch (_trim_type) {
- case CPL:
- f << "trim_type cpl\n";
- break;
- case ENCODE:
- f << "trim_type encode\n";
- break;
- }
- f << "dcp_ab " << (_dcp_ab ? "1" : "0") << endl;
- if (_content_audio_stream) {
- f << "selected_content_audio_stream " << _content_audio_stream->to_string() << endl;
- }
- for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
- f << "external_audio " << *i << endl;
- }
- f << "use_content_audio " << (_use_content_audio ? "1" : "0") << endl;
- f << "audio_gain " << _audio_gain << endl;
- f << "audio_delay " << _audio_delay << endl;
- f << "still_duration " << _still_duration << endl;
- if (_subtitle_stream) {
- f << "selected_subtitle_stream " << _subtitle_stream->to_string() << endl;
- }
- f << "with_subtitles " << _with_subtitles << endl;
- f << "subtitle_offset " << _subtitle_offset << endl;
- f << "subtitle_scale " << _subtitle_scale << endl;
- f << "colour_lut " << _colour_lut << endl;
- f << "j2k_bandwidth " << _j2k_bandwidth << endl;
- _dci_metadata.write (f);
- f << "dci_date " << boost::gregorian::to_iso_string (_dci_date) << endl;
- f << "dcp_frame_rate " << _dcp_frame_rate << endl;
- f << "width " << _size.width << endl;
- f << "height " << _size.height << endl;
- f << "length " << _length.get_value_or(0) << endl;
- f << "content_digest " << _content_digest << endl;
-
- for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
- f << "content_audio_stream " << (*i)->to_string () << endl;
+ root->add_child("DCPContentType")->add_child_text (_dcp_content_type->dci_name ());
}
- f << "external_audio_stream " << _sndfile_stream->to_string() << endl;
-
- for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
- f << "subtitle_stream " << (*i)->to_string () << endl;
+ if (_container) {
+ root->add_child("Container")->add_child_text (_container->id ());
}
- f << "source_frame_rate " << _source_frame_rate << endl;
+ root->add_child("Scaler")->add_child_text (_scaler->id ());
+ root->add_child("AB")->add_child_text (_ab ? "1" : "0");
+ root->add_child("WithSubtitles")->add_child_text (_with_subtitles ? "1" : "0");
+ root->add_child("SubtitleOffset")->add_child_text (lexical_cast<string> (_subtitle_offset));
+ root->add_child("SubtitleScale")->add_child_text (lexical_cast<string> (_subtitle_scale));
+ root->add_child("ColourLUT")->add_child_text (lexical_cast<string> (_colour_lut));
+ root->add_child("J2KBandwidth")->add_child_text (lexical_cast<string> (_j2k_bandwidth));
+ _dci_metadata.as_xml (root->add_child ("DCIMetadata"));
+ root->add_child("DCPVideoFrameRate")->add_child_text (lexical_cast<string> (_dcp_video_frame_rate));
+ root->add_child("DCIDate")->add_child_text (boost::gregorian::to_iso_string (_dci_date));
+ root->add_child("DCPAudioChannels")->add_child_text (lexical_cast<string> (_dcp_audio_channels));
+ _playlist->as_xml (root->add_child ("Playlist"));
+
+ doc.write_to_file_formatted (file ("metadata.xml"));
_dirty = false;
}
@@ -519,177 +416,46 @@ Film::read_metadata ()
boost::mutex::scoped_lock lm (_state_mutex);
LocaleGuard lg;
- _external_audio.clear ();
- _content_audio_streams.clear ();
- _subtitle_streams.clear ();
-
- boost::optional<int> version;
-
- /* Backward compatibility things */
- boost::optional<int> audio_sample_rate;
- boost::optional<int> audio_stream_index;
- boost::optional<int> subtitle_stream_index;
-
- ifstream f (file ("metadata").c_str());
- if (!f.good()) {
- throw OpenFileError (file ("metadata"));
+ if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file ("metadata.xml"))) {
+ throw StringError (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!"));
}
-
- multimap<string, string> kv = read_key_value (f);
- /* We need version before anything else */
- multimap<string, string>::iterator v = kv.find ("version");
- if (v != kv.end ()) {
- version = atoi (v->second.c_str());
- }
+ cxml::File f (file ("metadata.xml"), "Metadata");
- for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
- string const k = i->first;
- string const v = i->second;
-
- if (k == "audio_sample_rate") {
- audio_sample_rate = atoi (v.c_str());
- }
+ _name = f.string_child ("Name");
+ _use_dci_name = f.bool_child ("UseDCIName");
- /* User-specified stuff */
- if (k == "name") {
- _name = v;
- } else if (k == "use_dci_name") {
- _use_dci_name = (v == "1");
- } else if (k == "content") {
- _content = v;
- } else if (k == "trust_content_header") {
- _trust_content_header = (v == "1");
- } else if (k == "dcp_content_type") {
- if (version < 3) {
- _dcp_content_type = DCPContentType::from_pretty_name (v);
- } else {
- _dcp_content_type = DCPContentType::from_dci_name (v);
- }
- } else if (k == "format") {
- _format = Format::from_metadata (v);
- } else if (k == "left_crop") {
- _crop.left = atoi (v.c_str ());
- } else if (k == "right_crop") {
- _crop.right = atoi (v.c_str ());
- } else if (k == "top_crop") {
- _crop.top = atoi (v.c_str ());
- } else if (k == "bottom_crop") {
- _crop.bottom = atoi (v.c_str ());
- } else if (k == "filter") {
- _filters.push_back (Filter::from_id (v));
- } else if (k == "scaler") {
- _scaler = Scaler::from_id (v);
- } else if ( ((!version || version < 2) && k == "dcp_trim_start") || k == "trim_start") {
- _trim_start = atoi (v.c_str ());
- } else if ( ((!version || version < 2) && k == "dcp_trim_end") || k == "trim_end") {
- _trim_end = atoi (v.c_str ());
- } else if (k == "trim_type") {
- if (v == "cpl") {
- _trim_type = CPL;
- } else if (v == "encode") {
- _trim_type = ENCODE;
- }
- } else if (k == "dcp_ab") {
- _dcp_ab = (v == "1");
- } else if (k == "selected_content_audio_stream" || (!version && k == "selected_audio_stream")) {
- if (!version) {
- audio_stream_index = atoi (v.c_str ());
- } else {
- _content_audio_stream = audio_stream_factory (v, version);
- }
- } else if (k == "external_audio") {
- _external_audio.push_back (v);
- } else if (k == "use_content_audio") {
- _use_content_audio = (v == "1");
- } else if (k == "audio_gain") {
- _audio_gain = atof (v.c_str ());
- } else if (k == "audio_delay") {
- _audio_delay = atoi (v.c_str ());
- } else if (k == "still_duration") {
- _still_duration = atoi (v.c_str ());
- } else if (k == "selected_subtitle_stream") {
- if (!version) {
- subtitle_stream_index = atoi (v.c_str ());
- } else {
- _subtitle_stream = subtitle_stream_factory (v, version);
- }
- } else if (k == "with_subtitles") {
- _with_subtitles = (v == "1");
- } else if (k == "subtitle_offset") {
- _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 == "dci_date") {
- _dci_date = boost::gregorian::from_undelimited_string (v);
- } else if (k == "dcp_frame_rate") {
- _dcp_frame_rate = atoi (v.c_str ());
+ {
+ optional<string> c = f.optional_string_child ("DCPContentType");
+ if (c) {
+ _dcp_content_type = DCPContentType::from_dci_name (c.get ());
}
+ }
- _dci_metadata.read (k, v);
-
- /* Cached stuff */
- if (k == "width") {
- _size.width = atoi (v.c_str ());
- } else if (k == "height") {
- _size.height = atoi (v.c_str ());
- } else if (k == "length") {
- int const vv = atoi (v.c_str ());
- if (vv) {
- _length = vv;
- }
- } else if (k == "content_digest") {
- _content_digest = v;
- } else if (k == "content_audio_stream" || (!version && k == "audio_stream")) {
- _content_audio_streams.push_back (audio_stream_factory (v, version));
- } else if (k == "external_audio_stream") {
- _sndfile_stream = audio_stream_factory (v, version);
- } else if (k == "subtitle_stream") {
- _subtitle_streams.push_back (subtitle_stream_factory (v, version));
- } else if (k == "source_frame_rate") {
- _source_frame_rate = atof (v.c_str ());
- } else if (version < 4 && k == "frames_per_second") {
- _source_frame_rate = atof (v.c_str ());
- /* Fill in what would have been used for DCP frame rate by the older version */
- _dcp_frame_rate = best_dcp_frame_rate (_source_frame_rate);
+ {
+ optional<string> c = f.optional_string_child ("Container");
+ if (c) {
+ _container = Container::from_id (c.get ());
}
}
- if (!version) {
- if (audio_sample_rate) {
- /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
- for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
- (*i)->set_sample_rate (audio_sample_rate.get());
- }
- }
+ _scaler = Scaler::from_id (f.string_child ("Scaler"));
+ _ab = f.bool_child ("AB");
+ _with_subtitles = f.bool_child ("WithSubtitles");
+ _subtitle_offset = f.number_child<float> ("SubtitleOffset");
+ _subtitle_scale = f.number_child<float> ("SubtitleScale");
+ _colour_lut = f.number_child<int> ("ColourLUT");
+ _j2k_bandwidth = f.number_child<int> ("J2KBandwidth");
+ _dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
+ _dcp_video_frame_rate = f.number_child<int> ("DCPVideoFrameRate");
+ _dci_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate"));
+ _dcp_audio_channels = f.number_child<int> ("DCPAudioChannels");
- /* also the selected stream was specified as an index */
- if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
- _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
- }
+ _playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"));
- /* similarly the subtitle */
- if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
- _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
- }
- }
-
_dirty = false;
}
-libdcp::Size
-Film::cropped_size (libdcp::Size s) const
-{
- boost::mutex::scoped_lock lm (_state_mutex);
- s.width -= _crop.left + _crop.right;
- s.height -= _crop.top + _crop.bottom;
- return s;
-}
-
/** Given a directory name, return its full path within the Film's directory.
* The directory (and its parents) will be created if they do not exist.
*/
@@ -725,67 +491,6 @@ Film::file (string f) const
return p.string ();
}
-/** @return full path of the content (actual video) file
- * of the Film.
- */
-string
-Film::content_path () const
-{
- boost::mutex::scoped_lock lm (_state_mutex);
- if (boost::filesystem::path(_content).has_root_directory ()) {
- return _content;
- }
-
- return file (_content);
-}
-
-ContentType
-Film::content_type () const
-{
- if (boost::filesystem::is_directory (_content)) {
- /* Directory of images, we assume */
- return VIDEO;
- }
-
- if (still_image_file (_content)) {
- return STILL;
- }
-
- return VIDEO;
-}
-
-/** @return The sampling rate that we will resample the audio to */
-int
-Film::target_audio_sample_rate () const
-{
- if (!audio_stream()) {
- return 0;
- }
-
- /* Resample to a DCI-approved sample rate */
- double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
-
- FrameRateConversion frc (source_frame_rate(), dcp_frame_rate());
-
- /* Compensate if the DCP is being run at a different frame rate
- to the source; that is, if the video is run such that it will
- look different in the DCP compared to the source (slower or faster).
- skip/repeat doesn't come into effect here.
- */
-
- if (frc.change_speed) {
- t *= source_frame_rate() * frc.factor() / dcp_frame_rate();
- }
-
- return rint (t);
-}
-
-int
-Film::still_duration_in_frames () const
-{
- return still_duration() * source_frame_rate();
-}
-
/** @return a DCI-compliant name for a DCP of this film */
string
Film::dci_name (bool if_created_now) const
@@ -810,8 +515,8 @@ Film::dci_name (bool if_created_now) const
d << "_" << dcp_content_type()->dci_name();
}
- if (format()) {
- d << "_" << format()->dci_name();
+ if (container()) {
+ d << "_" << container()->dci_name();
}
DCIMetadata const dm = dci_metadata ();
@@ -832,22 +537,7 @@ Film::dci_name (bool if_created_now) const
}
}
- switch (audio_channels()) {
- case 1:
- d << "_10";
- break;
- case 2:
- d << "_20";
- break;
- case 6:
- d << "_51";
- break;
- case 8:
- d << "_71";
- break;
- }
-
- d << "_2K";
+ d << "_51_2K";
if (!dm.studio.empty ()) {
d << "_" << dm.studio;
@@ -911,107 +601,6 @@ Film::set_use_dci_name (bool u)
}
void
-Film::set_content (string c)
-{
- string check = directory ();
-
- boost::filesystem::path slash ("/");
- string platform_slash = slash.make_preferred().string ();
-
- if (!ends_with (check, platform_slash)) {
- check += platform_slash;
- }
-
- if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
- c = c.substr (_directory.length() + 1);
- }
-
- string old_content;
-
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- if (c == _content) {
- return;
- }
-
- old_content = _content;
- _content = c;
- }
-
- /* Reset streams here in case the new content doesn't have one or the other */
- _content_audio_stream = shared_ptr<AudioStream> ();
- _subtitle_stream = shared_ptr<SubtitleStream> ();
-
- /* Start off using content audio */
- set_use_content_audio (true);
-
- /* Create a temporary decoder so that we can get information
- about the content.
- */
-
- try {
- Decoders d = decoder_factory (shared_from_this(), DecodeOptions());
-
- set_size (d.video->native_size ());
- set_source_frame_rate (d.video->frames_per_second ());
- set_dcp_frame_rate (best_dcp_frame_rate (source_frame_rate ()));
- set_subtitle_streams (d.video->subtitle_streams ());
- if (d.audio) {
- set_content_audio_streams (d.audio->audio_streams ());
- }
-
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _content = c;
- }
-
- signal_changed (CONTENT);
-
- /* Start off with the first audio and subtitle streams */
- if (d.audio && !d.audio->audio_streams().empty()) {
- set_content_audio_stream (d.audio->audio_streams().front());
- }
-
- if (!d.video->subtitle_streams().empty()) {
- set_subtitle_stream (d.video->subtitle_streams().front());
- }
-
- examine_content ();
-
- } catch (...) {
-
- boost::mutex::scoped_lock lm (_state_mutex);
- _content = old_content;
- throw;
-
- }
-
- /* Default format */
- set_format (Config::instance()->default_format ());
-
- /* Still image DCPs must use external audio */
- if (content_type() == STILL) {
- set_use_content_audio (false);
- }
-}
-
-void
-Film::set_trust_content_header (bool t)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _trust_content_header = t;
- }
-
- signal_changed (TRUST_CONTENT_HEADER);
-
- if (!_trust_content_header && !content().empty()) {
- /* We just said that we don't trust the content's header */
- examine_content ();
- }
-}
-
-void
Film::set_dcp_content_type (DCPContentType const * t)
{
{
@@ -1022,90 +611,13 @@ Film::set_dcp_content_type (DCPContentType const * t)
}
void
-Film::set_format (Format const * f)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _format = f;
- }
- signal_changed (FORMAT);
-}
-
-void
-Film::set_crop (Crop c)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _crop = c;
- }
- signal_changed (CROP);
-}
-
-void
-Film::set_left_crop (int c)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
-
- if (_crop.left == c) {
- return;
- }
-
- _crop.left = c;
- }
- signal_changed (CROP);
-}
-
-void
-Film::set_right_crop (int c)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- if (_crop.right == c) {
- return;
- }
-
- _crop.right = c;
- }
- signal_changed (CROP);
-}
-
-void
-Film::set_top_crop (int c)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- if (_crop.top == c) {
- return;
- }
-
- _crop.top = c;
- }
- signal_changed (CROP);
-}
-
-void
-Film::set_bottom_crop (int c)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- if (_crop.bottom == c) {
- return;
- }
-
- _crop.bottom = c;
- }
- signal_changed (CROP);
-}
-
-void
-Film::set_filters (vector<Filter const *> f)
+Film::set_container (Container const * c)
{
{
boost::mutex::scoped_lock lm (_state_mutex);
- _filters = f;
+ _container = c;
}
- signal_changed (FILTERS);
+ signal_changed (CONTAINER);
}
void
@@ -1119,120 +631,13 @@ Film::set_scaler (Scaler const * s)
}
void
-Film::set_trim_start (int t)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _trim_start = t;
- }
- signal_changed (TRIM_START);
-}
-
-void
-Film::set_trim_end (int t)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _trim_end = t;
- }
- signal_changed (TRIM_END);
-}
-
-void
-Film::set_trim_type (TrimType t)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _trim_type = t;
- }
- signal_changed (TRIM_TYPE);
-}
-
-void
-Film::set_dcp_ab (bool a)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _dcp_ab = a;
- }
- signal_changed (DCP_AB);
-}
-
-void
-Film::set_content_audio_stream (shared_ptr<AudioStream> s)
+Film::set_ab (bool a)
{
{
boost::mutex::scoped_lock lm (_state_mutex);
- _content_audio_stream = s;
+ _ab = a;
}
- signal_changed (CONTENT_AUDIO_STREAM);
-}
-
-void
-Film::set_external_audio (vector<string> a)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _external_audio = a;
- }
-
- shared_ptr<SndfileDecoder> decoder (new SndfileDecoder (shared_from_this(), DecodeOptions()));
- if (decoder->audio_stream()) {
- _sndfile_stream = decoder->audio_stream ();
- }
-
- signal_changed (EXTERNAL_AUDIO);
-}
-
-void
-Film::set_use_content_audio (bool e)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _use_content_audio = e;
- }
-
- signal_changed (USE_CONTENT_AUDIO);
-}
-
-void
-Film::set_audio_gain (float g)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _audio_gain = g;
- }
- signal_changed (AUDIO_GAIN);
-}
-
-void
-Film::set_audio_delay (int d)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _audio_delay = d;
- }
- signal_changed (AUDIO_DELAY);
-}
-
-void
-Film::set_still_duration (int d)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _still_duration = d;
- }
- signal_changed (STILL_DURATION);
-}
-
-void
-Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _subtitle_stream = s;
- }
- signal_changed (SUBTITLE_STREAM);
+ signal_changed (AB);
}
void
@@ -1297,86 +702,16 @@ Film::set_dci_metadata (DCIMetadata m)
void
-Film::set_dcp_frame_rate (int f)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _dcp_frame_rate = f;
- }
- signal_changed (DCP_FRAME_RATE);
-}
-
-void
-Film::set_size (libdcp::Size s)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _size = s;
- }
- signal_changed (SIZE);
-}
-
-void
-Film::set_length (SourceFrame l)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _length = l;
- }
- signal_changed (LENGTH);
-}
-
-void
-Film::unset_length ()
+Film::set_dcp_video_frame_rate (int f)
{
{
boost::mutex::scoped_lock lm (_state_mutex);
- _length = boost::none;
+ _dcp_video_frame_rate = f;
}
- signal_changed (LENGTH);
+ signal_changed (DCP_VIDEO_FRAME_RATE);
}
void
-Film::set_content_digest (string d)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _content_digest = d;
- }
- _dirty = true;
-}
-
-void
-Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _content_audio_streams = s;
- }
- signal_changed (CONTENT_AUDIO_STREAMS);
-}
-
-void
-Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _subtitle_streams = s;
- }
- signal_changed (SUBTITLE_STREAMS);
-}
-
-void
-Film::set_source_frame_rate (float f)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _source_frame_rate = f;
- }
- signal_changed (SOURCE_FRAME_RATE);
-}
-
-void
Film::signal_changed (Property p)
{
{
@@ -1384,20 +719,17 @@ Film::signal_changed (Property p)
_dirty = true;
}
- if (ui_signaller) {
- ui_signaller->emit (boost::bind (boost::ref (Changed), p));
+ switch (p) {
+ case Film::CONTENT:
+ set_dcp_video_frame_rate (_playlist->best_dcp_frame_rate ());
+ break;
+ default:
+ break;
}
-}
-int
-Film::audio_channels () const
-{
- shared_ptr<AudioStream> s = audio_stream ();
- if (!s) {
- return 0;
+ if (ui_signaller) {
+ ui_signaller->emit (boost::bind (boost::ref (Changed), p));
}
-
- return s->channels ();
}
void
@@ -1406,16 +738,6 @@ Film::set_dci_date_today ()
_dci_date = boost::gregorian::day_clock::local_day ();
}
-boost::shared_ptr<AudioStream>
-Film::audio_stream () const
-{
- if (use_content_audio()) {
- return _content_audio_stream;
- }
-
- return _sndfile_stream;
-}
-
string
Film::info_path (int f) const
{
@@ -1471,20 +793,113 @@ Film::have_dcp () const
return true;
}
+shared_ptr<Player>
+Film::player () const
+{
+ return shared_ptr<Player> (new Player (shared_from_this (), _playlist));
+}
+
+shared_ptr<Playlist>
+Film::playlist () const
+{
+ boost::mutex::scoped_lock lm (_state_mutex);
+ return _playlist;
+}
+
+Playlist::ContentList
+Film::content () const
+{
+ return _playlist->content ();
+}
+
+void
+Film::add_content (shared_ptr<Content> c)
+{
+ _playlist->add (c);
+ examine_content (c);
+}
+
+void
+Film::remove_content (shared_ptr<Content> c)
+{
+ _playlist->remove (c);
+}
+
+Time
+Film::length () const
+{
+ return _playlist->length ();
+}
+
bool
-Film::has_audio () const
+Film::has_subtitles () const
{
- if (use_content_audio()) {
- return audio_stream();
- }
+ return _playlist->has_subtitles ();
+}
- vector<string> const e = external_audio ();
- for (vector<string>::const_iterator i = e.begin(); i != e.end(); ++i) {
- if (!i->empty ()) {
- return true;
- }
+OutputVideoFrame
+Film::best_dcp_video_frame_rate () const
+{
+ return _playlist->best_dcp_frame_rate ();
+}
+
+void
+Film::playlist_content_changed (boost::weak_ptr<Content> c, int p)
+{
+ if (p == VideoContentProperty::VIDEO_FRAME_RATE) {
+ set_dcp_video_frame_rate (_playlist->best_dcp_frame_rate ());
+ }
+
+ if (ui_signaller) {
+ ui_signaller->emit (boost::bind (boost::ref (ContentChanged), c, p));
}
+}
+
+void
+Film::playlist_changed ()
+{
+ signal_changed (CONTENT);
+}
+
+int
+Film::loop () const
+{
+ return _playlist->loop ();
+}
+
+void
+Film::set_loop (int c)
+{
+ _playlist->set_loop (c);
+}
- return false;
+OutputAudioFrame
+Film::time_to_audio_frames (Time t) const
+{
+ return t * dcp_audio_frame_rate () / TIME_HZ;
+}
+
+OutputVideoFrame
+Film::time_to_video_frames (Time t) const
+{
+ return t * dcp_video_frame_rate () / TIME_HZ;
+}
+
+Time
+Film::audio_frames_to_time (OutputAudioFrame f) const
+{
+ return f * TIME_HZ / dcp_audio_frame_rate ();
+}
+
+Time
+Film::video_frames_to_time (OutputVideoFrame f) const
+{
+ return f * TIME_HZ / dcp_video_frame_rate ();
}
+OutputAudioFrame
+Film::dcp_audio_frame_rate () const
+{
+ /* XXX */
+ return 48000;
+}
diff --git a/src/lib/film.h b/src/lib/film.h
index dd0a83d94..84f0b0233 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -18,12 +18,12 @@
*/
/** @file src/film.h
- * @brief A representation of a piece of video (with sound), including naming,
- * the source content file, and how it should be presented in a DCP.
+ * @brief A representation of some audio and video content, and details of
+ * how they should be presented in a DCP.
*/
-#ifndef DVDOMATIC_FILM_H
-#define DVDOMATIC_FILM_H
+#ifndef DCPOMATIC_FILM_H
+#define DCPOMATIC_FILM_H
#include <string>
#include <vector>
@@ -32,34 +32,32 @@
#include <boost/thread.hpp>
#include <boost/signals2.hpp>
#include <boost/enable_shared_from_this.hpp>
-extern "C" {
-#include <libavcodec/avcodec.h>
-}
-#include "dcp_content_type.h"
#include "util.h"
-#include "stream.h"
#include "dci_metadata.h"
+#include "types.h"
+#include "ffmpeg_content.h"
+#include "playlist.h"
-class Format;
+class DCPContentType;
+class Container;
class Job;
class Filter;
class Log;
class ExamineContentJob;
class AnalyseAudioJob;
class ExternalAudioStream;
+class Content;
+class Player;
/** @class Film
- * @brief A representation of a video, maybe with sound.
- *
- * 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.
+ * @brief A representation of some audio and video content, and details of
+ * how they should be presented in a DCP.
*/
class Film : public boost::enable_shared_from_this<Film>
{
public:
- Film (std::string d, bool must_exist = true);
+ Film (std::string d);
Film (Film const &);
- ~Film ();
std::string info_dir () const;
std::string j2c_path (int f, bool t) const;
@@ -68,13 +66,12 @@ public:
std::string internal_video_mxf_filename () const;
std::string audio_analysis_path () const;
+ void examine_content (boost::shared_ptr<Content>);
std::string dcp_video_mxf_filename () const;
std::string dcp_audio_mxf_filename () const;
- void examine_content ();
void analyse_audio ();
void send_dcp_to_tms ();
-
void make_dcp ();
/** @return Logger.
@@ -89,15 +86,9 @@ public:
std::string file (std::string f) const;
std::string dir (std::string d) const;
- std::string content_path () const;
- ContentType content_type () const;
-
- int target_audio_sample_rate () const;
-
- void write_metadata () const;
void read_metadata ();
+ void write_metadata () const;
- libdcp::Size cropped_size (libdcp::Size) const;
std::string dci_name (bool if_created_now) const;
std::string dcp_name (bool if_created_now = false) const;
@@ -106,16 +97,28 @@ public:
return _dirty;
}
- int audio_channels () const;
+ bool have_dcp () const;
+
+ boost::shared_ptr<Player> player () const;
+ boost::shared_ptr<Playlist> playlist () const;
- void set_dci_date_today ();
+ OutputAudioFrame dcp_audio_frame_rate () const;
- bool have_dcp () const;
+ OutputAudioFrame time_to_audio_frames (Time) const;
+ OutputVideoFrame time_to_video_frames (Time) const;
+ Time video_frames_to_time (OutputVideoFrame) const;
+ Time audio_frames_to_time (OutputAudioFrame) const;
- enum TrimType {
- CPL,
- ENCODE
- };
+ /* Proxies for some Playlist methods */
+
+ Playlist::ContentList content () const;
+
+ Time length () const;
+ bool has_subtitles () const;
+ OutputVideoFrame best_dcp_video_frame_rate () const;
+
+ void set_loop (int);
+ int loop () const;
/** Identifiers for the parts of our state;
used for signalling changes.
@@ -124,36 +127,20 @@ public:
NONE,
NAME,
USE_DCI_NAME,
+ /** The playlist's content list has changed (i.e. content has been added, moved around or removed) */
CONTENT,
- TRUST_CONTENT_HEADER,
+ LOOP,
DCP_CONTENT_TYPE,
- FORMAT,
- CROP,
- FILTERS,
+ CONTAINER,
SCALER,
- TRIM_START,
- TRIM_END,
- TRIM_TYPE,
- DCP_AB,
- CONTENT_AUDIO_STREAM,
- EXTERNAL_AUDIO,
- USE_CONTENT_AUDIO,
- AUDIO_GAIN,
- AUDIO_DELAY,
- STILL_DURATION,
- SUBTITLE_STREAM,
+ AB,
WITH_SUBTITLES,
SUBTITLE_OFFSET,
SUBTITLE_SCALE,
COLOUR_LUT,
J2K_BANDWIDTH,
DCI_METADATA,
- SIZE,
- LENGTH,
- CONTENT_AUDIO_STREAMS,
- SUBTITLE_STREAMS,
- SOURCE_FRAME_RATE,
- DCP_FRAME_RATE
+ DCP_VIDEO_FRAME_RATE,
};
@@ -174,34 +161,14 @@ public:
return _use_dci_name;
}
- std::string content () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _content;
- }
-
- bool trust_content_header () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _trust_content_header;
- }
-
DCPContentType const * dcp_content_type () const {
boost::mutex::scoped_lock lm (_state_mutex);
return _dcp_content_type;
}
- Format const * format () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _format;
- }
-
- Crop crop () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _crop;
- }
-
- std::vector<Filter const *> filters () const {
+ Container const * container () const {
boost::mutex::scoped_lock lm (_state_mutex);
- return _filters;
+ return _container;
}
Scaler const * scaler () const {
@@ -209,61 +176,9 @@ public:
return _scaler;
}
- int trim_start () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _trim_start;
- }
-
- int trim_end () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _trim_end;
- }
-
- TrimType trim_type () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _trim_type;
- }
-
- bool dcp_ab () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _dcp_ab;
- }
-
- boost::shared_ptr<AudioStream> content_audio_stream () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _content_audio_stream;
- }
-
- std::vector<std::string> external_audio () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _external_audio;
- }
-
- bool use_content_audio () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _use_content_audio;
- }
-
- float audio_gain () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _audio_gain;
- }
-
- int audio_delay () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _audio_delay;
- }
-
- int still_duration () const {
+ bool ab () const {
boost::mutex::scoped_lock lm (_state_mutex);
- return _still_duration;
- }
-
- int still_duration_in_frames () const;
-
- boost::shared_ptr<SubtitleStream> subtitle_stream () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _subtitle_stream;
+ return _ab;
}
bool with_subtitles () const {
@@ -296,93 +211,43 @@ public:
return _dci_metadata;
}
- int dcp_frame_rate () const {
+ /* XXX: -> "video_frame_rate" */
+ int dcp_video_frame_rate () const {
boost::mutex::scoped_lock lm (_state_mutex);
- return _dcp_frame_rate;
- }
-
- libdcp::Size size () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _size;
+ return _dcp_video_frame_rate;
}
- boost::optional<SourceFrame> length () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _length;
- }
-
- std::string content_digest () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _content_digest;
- }
-
- std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _content_audio_streams;
- }
-
- std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _subtitle_streams;
- }
-
- float source_frame_rate () const {
+ int dcp_audio_channels () const {
boost::mutex::scoped_lock lm (_state_mutex);
- if (content_type() == STILL) {
- return 24;
- }
-
- return _source_frame_rate;
+ return _dcp_audio_channels;
}
- boost::shared_ptr<AudioStream> audio_stream () const;
- bool has_audio () const;
-
/* SET */
void set_directory (std::string);
void set_name (std::string);
void set_use_dci_name (bool);
- void set_content (std::string);
- void set_trust_content_header (bool);
+ void add_content (boost::shared_ptr<Content>);
+ void remove_content (boost::shared_ptr<Content>);
void set_dcp_content_type (DCPContentType const *);
- void set_format (Format const *);
- void set_crop (Crop);
- void set_left_crop (int);
- void set_right_crop (int);
- void set_top_crop (int);
- void set_bottom_crop (int);
- void set_filters (std::vector<Filter const *>);
+ void set_container (Container const *);
void set_scaler (Scaler const *);
- void set_trim_start (int);
- void set_trim_end (int);
- void set_trim_type (TrimType);
- void set_dcp_ab (bool);
- void set_content_audio_stream (boost::shared_ptr<AudioStream>);
- void set_external_audio (std::vector<std::string>);
- void set_use_content_audio (bool);
- void set_audio_gain (float);
- void set_audio_delay (int);
- void set_still_duration (int);
- void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
+ void set_ab (bool);
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_dci_metadata (DCIMetadata);
- void set_dcp_frame_rate (int);
- void set_size (libdcp::Size);
- void set_length (SourceFrame);
- void unset_length ();
- void set_content_digest (std::string);
- void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
- void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
- void set_source_frame_rate (float);
-
- /** Emitted when some property has changed */
+ void set_dcp_video_frame_rate (int);
+ void set_dci_date_today ();
+
+ /** Emitted when some property has of the Film has changed */
mutable boost::signals2::signal<void (Property)> Changed;
+ /** Emitted when some property of our content has changed */
+ mutable boost::signals2::signal<void (boost::weak_ptr<Content>, int)> ContentChanged;
+
boost::signals2::signal<void ()> AudioAnalysisSucceeded;
/** Current version number of the state file */
@@ -390,20 +255,19 @@ public:
private:
- /** Log to write to */
- boost::shared_ptr<Log> _log;
-
- /** Any running ExamineContentJob, or 0 */
- boost::shared_ptr<ExamineContentJob> _examine_content_job;
- /** Any running AnalyseAudioJob, or 0 */
- boost::shared_ptr<AnalyseAudioJob> _analyse_audio_job;
-
void signal_changed (Property);
- void examine_content_finished ();
void analyse_audio_finished ();
std::string video_state_identifier () const;
+ void playlist_changed ();
+ void playlist_content_changed (boost::weak_ptr<Content>, int);
std::string filename_safe_name () const;
+ /** Log to write to */
+ boost::shared_ptr<Log> _log;
+ /** Any running AnalyseAudioJob, or 0 */
+ boost::shared_ptr<AnalyseAudioJob> _analyse_audio_job;
+ boost::shared_ptr<Playlist> _playlist;
+
/** Complete path to directory containing the film metadata;
* must not be relative.
*/
@@ -411,54 +275,21 @@ private:
/** Mutex for _directory */
mutable boost::mutex _directory_mutex;
- /** Name for DVD-o-matic */
+ /** Name for DCP-o-matic */
std::string _name;
/** True if a auto-generated DCI-compliant name should be used for our DCP */
bool _use_dci_name;
- /** File or directory containing content; may be relative to our directory
- * 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;
- /** The format to present this Film in (flat, scope, etc.) */
- Format const * _format;
- /** The crop to apply to the source */
- Crop _crop;
- /** Video filters that should be used when generating DCPs */
- std::vector<Filter const *> _filters;
+ /** The container to put this Film in (flat, scope, etc.) */
+ Container const * _container;
/** Scaler algorithm to use */
Scaler const * _scaler;
- /** Frames to trim off the start of the DCP */
- int _trim_start;
- /** Frames to trim off the end of the DCP */
- int _trim_end;
- TrimType _trim_type;
/** true to create an A/B comparison DCP, where the left half of the image
is the video without any filters or post-processing, and the right half
has the specified filters and post-processing.
*/
- bool _dcp_ab;
- /** The audio stream to use from our content */
- boost::shared_ptr<AudioStream> _content_audio_stream;
- /** List of filenames of external audio files, in channel order
- (L, R, C, Lfe, Ls, Rs)
- */
- std::vector<std::string> _external_audio;
- /** true to use audio from our content file; false to use external audio */
- bool _use_content_audio;
- /** Gain to apply to audio in dB */
- float _audio_gain;
- /** Delay to apply to audio (positive moves audio later) in milliseconds */
- int _audio_delay;
- /** Duration to make still-sourced films (in seconds) */
- int _still_duration;
- boost::shared_ptr<SubtitleStream> _subtitle_stream;
+ bool _ab;
/** True if subtitles should be shown for this film */
bool _with_subtitles;
/** y offset for placing subtitles, in source pixels; +ve is further down
@@ -474,30 +305,13 @@ private:
int _colour_lut;
/** bandwidth for J2K files in bits per second */
int _j2k_bandwidth;
-
/** DCI naming stuff */
DCIMetadata _dci_metadata;
+ /** Frames per second to run our DCP at */
+ int _dcp_video_frame_rate;
/** The date that we should use in a DCI name */
boost::gregorian::date _dci_date;
- /** Frames per second to run our DCP at */
- int _dcp_frame_rate;
-
- /* Data which are cached to speed things up */
-
- /** 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 */
- std::string _content_digest;
- /** The audio streams in our content */
- std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
- /** A stream to represent possible external audio (will always exist) */
- boost::shared_ptr<AudioStream> _sndfile_stream;
- /** the subtitle streams that we can use */
- std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
- /** Frames per second of the source */
- float _source_frame_rate;
+ int _dcp_audio_channels;
/** true if our state has changed since we last saved it */
mutable bool _dirty;
diff --git a/src/lib/filter.h b/src/lib/filter.h
index 205d92482..7587312c2 100644
--- a/src/lib/filter.h
+++ b/src/lib/filter.h
@@ -21,8 +21,8 @@
* @brief A class to describe one of FFmpeg's video or post-processing filters.
*/
-#ifndef DVDOMATIC_FILTER_H
-#define DVDOMATIC_FILTER_H
+#ifndef DCPOMATIC_FILTER_H
+#define DCPOMATIC_FILTER_H
#include <string>
#include <vector>
diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc
index b0427a23d..4564033d5 100644
--- a/src/lib/filter_graph.cc
+++ b/src/lib/filter_graph.cc
@@ -33,7 +33,6 @@ extern "C" {
#include "filter.h"
#include "exceptions.h"
#include "image.h"
-#include "film.h"
#include "ffmpeg_decoder.h"
#include "i18n.h"
@@ -42,15 +41,15 @@ using std::stringstream;
using std::string;
using std::list;
using boost::shared_ptr;
+using boost::weak_ptr;
using libdcp::Size;
-/** Construct a FFmpegFilterGraph for the settings in a film.
- * @param film Film.
- * @param decoder Decoder that we are using.
+/** Construct a FilterGraph for the settings in a piece of content.
+ * @param content Content.
* @param s Size of the images to process.
* @param p Pixel format of the images to process.
*/
-FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p)
+FilterGraph::FilterGraph (shared_ptr<const FFmpegContent> content, libdcp::Size s, AVPixelFormat p)
: _buffer_src_context (0)
, _buffer_sink_context (0)
, _size (s)
@@ -58,12 +57,16 @@ FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* deco
{
_frame = av_frame_alloc ();
- string filters = Filter::ffmpeg_strings (film->filters()).first;
+ string filters = Filter::ffmpeg_strings (content->filters()).first;
if (!filters.empty ()) {
- filters += N_(",");
+ filters += ",";
}
- filters += crop_string (Position (film->crop().left, film->crop().top), film->cropped_size (decoder->native_size()));
+ Crop crop = content->crop ();
+ libdcp::Size cropped_size = _size;
+ cropped_size.width -= crop.left + crop.right;
+ cropped_size.height -= crop.top + crop.bottom;
+ filters += crop_string (Position (crop.left, crop.top), cropped_size);
AVFilterGraph* graph = avfilter_graph_alloc();
if (graph == 0) {
@@ -83,8 +86,8 @@ FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* deco
stringstream a;
a << "video_size=" << _size.width << "x" << _size.height << ":"
<< "pix_fmt=" << _pixel_format << ":"
- << "time_base=" << decoder->time_base_numerator() << "/" << decoder->time_base_denominator() << ":"
- << "pixel_aspect=" << decoder->sample_aspect_ratio_numerator() << "/" << decoder->sample_aspect_ratio_denominator();
+ << "time_base=0/1:"
+ << "pixel_aspect=0/1";
int r;
@@ -127,7 +130,7 @@ FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* deco
/* XXX: leaking `inputs' / `outputs' ? */
}
-FFmpegFilterGraph::~FFmpegFilterGraph ()
+FilterGraph::~FilterGraph ()
{
av_frame_free (&_frame);
}
@@ -136,7 +139,7 @@ FFmpegFilterGraph::~FFmpegFilterGraph ()
* set of Images. Caller handles memory management of the input frame.
*/
list<shared_ptr<Image> >
-FFmpegFilterGraph::process (AVFrame* frame)
+FilterGraph::process (AVFrame* frame)
{
list<shared_ptr<Image> > images;
@@ -160,25 +163,7 @@ FFmpegFilterGraph::process (AVFrame* frame)
* @return true if this chain can process images with `s' and `p', otherwise false.
*/
bool
-FFmpegFilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const
+FilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const
{
return (_size == s && _pixel_format == p);
}
-
-list<shared_ptr<Image> >
-EmptyFilterGraph::process (AVFrame* frame)
-{
- list<shared_ptr<Image> > im;
- im.push_back (shared_ptr<Image> (new SimpleImage (frame)));
- return im;
-}
-
-shared_ptr<FilterGraph>
-filter_graph_factory (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size size, AVPixelFormat pixel_format)
-{
- if (film->filters().empty() && film->crop() == Crop()) {
- return shared_ptr<FilterGraph> (new EmptyFilterGraph);
- }
-
- return shared_ptr<FilterGraph> (new FFmpegFilterGraph (film, decoder, size, pixel_format));
-}
diff --git a/src/lib/filter_graph.h b/src/lib/filter_graph.h
index 2138943e4..e294812c2 100644
--- a/src/lib/filter_graph.h
+++ b/src/lib/filter_graph.h
@@ -21,40 +21,22 @@
* @brief A graph of FFmpeg filters.
*/
-#ifndef DVDOMATIC_FILTER_GRAPH_H
-#define DVDOMATIC_FILTER_GRAPH_H
+#ifndef DCPOMATIC_FILTER_GRAPH_H
+#define DCPOMATIC_FILTER_GRAPH_H
#include "util.h"
class Image;
class VideoFilter;
-class FFmpegDecoder;
-class FilterGraph
-{
-public:
- virtual bool can_process (libdcp::Size, AVPixelFormat) const = 0;
- virtual std::list<boost::shared_ptr<Image> > process (AVFrame *) = 0;
-};
-
-class EmptyFilterGraph : public FilterGraph
-{
-public:
- bool can_process (libdcp::Size, AVPixelFormat) const {
- return true;
- }
-
- std::list<boost::shared_ptr<Image> > process (AVFrame *);
-};
-
-/** @class FFmpegFilterGraph
+/** @class FilterGraph
* @brief A graph of FFmpeg filters.
*/
-class FFmpegFilterGraph : public FilterGraph
+class FilterGraph
{
public:
- FFmpegFilterGraph (boost::shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p);
- ~FFmpegFilterGraph ();
+ FilterGraph (boost::shared_ptr<const FFmpegContent> content, libdcp::Size s, AVPixelFormat p);
+ ~FilterGraph ();
bool can_process (libdcp::Size s, AVPixelFormat p) const;
std::list<boost::shared_ptr<Image> > process (AVFrame * frame);
@@ -67,6 +49,4 @@ private:
AVFrame* _frame;
};
-boost::shared_ptr<FilterGraph> filter_graph_factory (boost::shared_ptr<Film>, FFmpegDecoder *, libdcp::Size, AVPixelFormat);
-
#endif
diff --git a/src/lib/format.cc b/src/lib/format.cc
index 78e200847..87bdda3d1 100644
--- a/src/lib/format.cc
+++ b/src/lib/format.cc
@@ -29,6 +29,7 @@
#include <iostream>
#include "format.h"
#include "film.h"
+#include "playlist.h"
#include "i18n.h"
@@ -43,14 +44,14 @@ vector<Format const *> Format::_formats;
/** @return A name to be presented to the user */
string
-FixedFormat::name () const
+Format::name () const
{
stringstream s;
if (!_nickname.empty ()) {
s << _nickname << N_(" (");
}
- s << setprecision(3) << _ratio << N_(":1");
+ s << setprecision(3) << ratio() << N_(":1");
if (!_nickname.empty ()) {
s << N_(")");
@@ -59,77 +60,20 @@ FixedFormat::name () const
return s.str ();
}
-/** @return Identifier for this format as metadata for a Film's metadata file */
-string
-Format::as_metadata () const
-{
- return _id;
-}
-
/** Fill our _formats vector with all available formats */
void
Format::setup_formats ()
{
/// TRANSLATORS: these are film picture aspect ratios; "Academy" means 1.37, "Flat" 1.85 and "Scope" 2.39.
- _formats.push_back (
- new FixedFormat (1.19, libdcp::Size (1285, 1080), "119", _("1.19"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (4.0 / 3.0, libdcp::Size (1436, 1080), "133", _("4:3"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.38, libdcp::Size (1485, 1080), "138", _("1.375"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (4.0 / 3.0, libdcp::Size (1998, 1080), "133-in-flat", _("4:3 within Flat"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.37, libdcp::Size (1480, 1080), "137", _("Academy"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.66, libdcp::Size (1793, 1080), "166", _("1.66"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.66, libdcp::Size (1998, 1080), "166-in-flat", _("1.66 within Flat"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.78, libdcp::Size (1998, 1080), "178-in-flat", _("16:9 within Flat"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.78, libdcp::Size (1920, 1080), "178", _("16:9"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.85, libdcp::Size (1998, 1080), "185", _("Flat"), "F"
- ));
-
- _formats.push_back (
- new FixedFormat (1.78, libdcp::Size (2048, 858), "178-in-scope", _("16:9 within Scope"), "S"
- ));
-
- _formats.push_back (
- new FixedFormat (2.39, libdcp::Size (2048, 858), "239", _("Scope"), "S"
- ));
-
- _formats.push_back (
- new FixedFormat (1.896, libdcp::Size (2048, 1080), "full-frame", _("Full frame"), "C"
- ));
-
- _formats.push_back (
- new VariableFormat (libdcp::Size (1998, 1080), "var-185", _("Flat without stretch"), "F"
- ));
-
- _formats.push_back (
- new VariableFormat (libdcp::Size (2048, 858), "var-239", _("Scope without stretch"), "S"
- ));
+ _formats.push_back (new Format (libdcp::Size (1285, 1080), "119", _("1.19")));
+ _formats.push_back (new Format (libdcp::Size (1436, 1080), "133", _("4:3")));
+ _formats.push_back (new Format (libdcp::Size (1485, 1080), "138", _("1.375")));
+ _formats.push_back (new Format (libdcp::Size (1480, 1080), "137", _("Academy")));
+ _formats.push_back (new Format (libdcp::Size (1793, 1080), "166", _("1.66")));
+ _formats.push_back (new Format (libdcp::Size (1920, 1080), "178", _("16:9")));
+ _formats.push_back (new Format (libdcp::Size (1998, 1080), "185", _("Flat")));
+ _formats.push_back (new Format (libdcp::Size (2048, 858), "239", _("Scope")));
+ _formats.push_back (new Format (libdcp::Size (2048, 1080), "full-frame", _("Full frame")));
}
/** @param n Nickname.
@@ -168,16 +112,6 @@ Format::from_id (string i)
return *j;
}
-
-/** @param m Metadata, as returned from as_metadata().
- * @return Matching Format, or 0.
- */
-Format const *
-Format::from_metadata (string m)
-{
- return from_id (m);
-}
-
/** @return All available formats */
vector<Format const *>
Format::all ()
@@ -185,56 +119,8 @@ Format::all ()
return _formats;
}
-/** @param r Ratio
- * @param dcp Size (in pixels) of the images that we should put in a DCP.
- * @param id ID (e.g. 185)
- * @param n Nick name (e.g. Flat)
- */
-FixedFormat::FixedFormat (float r, libdcp::Size dcp, string id, string n, string d)
- : Format (dcp, id, n, d)
- , _ratio (r)
-{
-
-}
-
-/** @return Number of pixels (int the DCP image) to pad either side of the film
- * (so there are dcp_padding() pixels on the left and dcp_padding() on the right)
- */
-int
-Format::dcp_padding (shared_ptr<const Film> f) const
-{
- int p = rint ((_dcp_size.width - (_dcp_size.height * ratio(f))) / 2.0);
-
- /* This comes out -ve for Scope; bodge it */
- if (p < 0) {
- p = 0;
- }
-
- return p;
-}
-
float
-Format::container_ratio () const
+Format::ratio () const
{
return static_cast<float> (_dcp_size.width) / _dcp_size.height;
}
-
-VariableFormat::VariableFormat (libdcp::Size dcp, string id, string n, string d)
- : Format (dcp, id, n, d)
-{
-
-}
-
-float
-VariableFormat::ratio (shared_ptr<const Film> f) const
-{
- libdcp::Size const c = f->cropped_size (f->size ());
- return float (c.width) / c.height;
-}
-
-/** @return A name to be presented to the user */
-string
-VariableFormat::name () const
-{
- return _nickname;
-}
diff --git a/src/lib/format.h b/src/lib/format.h
index e95306232..06423d2b1 100644
--- a/src/lib/format.h
+++ b/src/lib/format.h
@@ -24,28 +24,21 @@
#include <string>
#include <vector>
-#include "util.h"
+#include <libdcp/util.h>
class Film;
class Format
{
public:
- Format (libdcp::Size dcp, std::string id, std::string n, std::string d)
+ Format (libdcp::Size dcp, std::string id, std::string n)
: _dcp_size (dcp)
, _id (id)
, _nickname (n)
- , _dci_name (d)
{}
- /** @return the ratio of the container (including any padding) */
- float container_ratio () const;
-
- int dcp_padding (boost::shared_ptr<const Film> f) const;
-
/** @return 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.
+ * put in a DCP for this format.
*/
libdcp::Size dcp_size () const {
return _dcp_size;
@@ -56,71 +49,32 @@ public:
}
/** @return Full name to present to the user */
- virtual std::string name () const = 0;
+ std::string name () const;
/** @return Nickname (e.g. Flat, Scope) */
std::string nickname () const {
return _nickname;
}
- std::string dci_name () const {
- return _dci_name;
- }
-
- std::string as_metadata () const;
-
static Format const * from_nickname (std::string n);
- static Format const * from_metadata (std::string m);
static Format const * from_id (std::string i);
static std::vector<Format const *> all ();
static void setup_formats ();
protected:
/** @return the ratio */
- virtual float ratio (boost::shared_ptr<const Film> f) const = 0;
+ float ratio () const;
/** 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.
+ * put in a DCP for this format.
*/
libdcp::Size _dcp_size;
/** id for use in metadata */
std::string _id;
/** nickname (e.g. Flat, Scope) */
std::string _nickname;
- std::string _dci_name;
private:
/** all available formats */
static std::vector<Format const *> _formats;
};
-
-/** @class FixedFormat
- * @brief Class to describe a format whose ratio is fixed regardless
- * of source size.
- */
-class FixedFormat : public Format
-{
-public:
- FixedFormat (float, libdcp::Size, std::string, std::string, std::string);
-
- float ratio (boost::shared_ptr<const Film>) const {
- return _ratio;
- }
-
- std::string name () const;
-
-private:
-
- float _ratio;
-};
-
-class VariableFormat : public Format
-{
-public:
- VariableFormat (libdcp::Size, std::string, std::string, std::string);
-
- float ratio (boost::shared_ptr<const Film> f) const;
-
- std::string name () const;
-};
diff --git a/src/lib/gain.cc b/src/lib/gain.cc
deleted file mode 100644
index ccd779d71..000000000
--- a/src/lib/gain.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- Copyright (C) 2012 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 "gain.h"
-
-using boost::shared_ptr;
-
-/** @param gain gain in dB */
-Gain::Gain (shared_ptr<Log> log, float gain)
- : AudioProcessor (log)
- , _gain (gain)
-{
-
-}
-
-void
-Gain::process_audio (shared_ptr<const AudioBuffers> b)
-{
- if (_gain != 0) {
- float const linear_gain = pow (10, _gain / 20);
- for (int i = 0; i < b->channels(); ++i) {
- for (int j = 0; j < b->frames(); ++j) {
- b->data(i)[j] *= linear_gain;
- }
- }
- }
-
- Audio (b);
-}
diff --git a/src/lib/i18n.h b/src/lib/i18n.h
index 46bb1d565..890313bc6 100644
--- a/src/lib/i18n.h
+++ b/src/lib/i18n.h
@@ -19,5 +19,5 @@
#include <libintl.h>
-#define _(x) dgettext ("libdvdomatic", x)
+#define _(x) dgettext ("libdcpomatic", x)
#define N_(x) x
diff --git a/src/lib/image.h b/src/lib/image.h
index 70dacfaee..34f87b188 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -21,8 +21,8 @@
* @brief A set of classes to describe video images.
*/
-#ifndef DVDOMATIC_IMAGE_H
-#define DVDOMATIC_IMAGE_H
+#ifndef DCPOMATIC_IMAGE_H
+#define DCPOMATIC_IMAGE_H
#include <string>
#include <boost/shared_ptr.hpp>
diff --git a/src/lib/imagemagick_content.cc b/src/lib/imagemagick_content.cc
new file mode 100644
index 000000000..ac04fb15b
--- /dev/null
+++ b/src/lib/imagemagick_content.cc
@@ -0,0 +1,114 @@
+/*
+ Copyright (C) 2013 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 <libcxml/cxml.h>
+#include "imagemagick_content.h"
+#include "imagemagick_decoder.h"
+#include "config.h"
+#include "compose.hpp"
+
+#include "i18n.h"
+
+using std::string;
+using std::stringstream;
+using boost::shared_ptr;
+
+ImageMagickContent::ImageMagickContent (shared_ptr<const Film> f, boost::filesystem::path p)
+ : Content (f, p)
+ , VideoContent (f, p)
+{
+
+}
+
+ImageMagickContent::ImageMagickContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
+ : Content (f, node)
+ , VideoContent (f, node)
+{
+
+}
+
+string
+ImageMagickContent::summary () const
+{
+ return String::compose (_("Image: %1"), file().filename().string());
+}
+
+bool
+ImageMagickContent::valid_file (boost::filesystem::path f)
+{
+ string ext = f.extension().string();
+ transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+ return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp");
+}
+
+void
+ImageMagickContent::as_xml (xmlpp::Node* node) const
+{
+ node->add_child("Type")->add_child_text ("ImageMagick");
+ Content::as_xml (node);
+ VideoContent::as_xml (node);
+}
+
+void
+ImageMagickContent::examine (shared_ptr<Job> job)
+{
+ Content::examine (job);
+
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ shared_ptr<ImageMagickDecoder> decoder (new ImageMagickDecoder (film, shared_from_this()));
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ /* Initial length */
+ _video_length = Config::instance()->default_still_length() * 24;
+ }
+
+ take_from_video_decoder (decoder);
+
+ signal_changed (VideoContentProperty::VIDEO_LENGTH);
+}
+
+shared_ptr<Content>
+ImageMagickContent::clone () const
+{
+ return shared_ptr<Content> (new ImageMagickContent (*this));
+}
+
+void
+ImageMagickContent::set_video_length (ContentVideoFrame len)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _video_length = len;
+ }
+
+ signal_changed (VideoContentProperty::VIDEO_LENGTH);
+}
+
+Time
+ImageMagickContent::length () const
+{
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ FrameRateConversion frc (24, film->dcp_video_frame_rate ());
+ return video_length() * frc.factor() * TIME_HZ / film->dcp_video_frame_rate ();
+}
diff --git a/src/lib/imagemagick_content.h b/src/lib/imagemagick_content.h
new file mode 100644
index 000000000..e3e827892
--- /dev/null
+++ b/src/lib/imagemagick_content.h
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2013 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 <boost/enable_shared_from_this.hpp>
+#include "video_content.h"
+
+namespace cxml {
+ class Node;
+}
+
+class ImageMagickContent : public VideoContent
+{
+public:
+ ImageMagickContent (boost::shared_ptr<const Film>, boost::filesystem::path);
+ ImageMagickContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+
+ boost::shared_ptr<ImageMagickContent> shared_from_this () {
+ return boost::dynamic_pointer_cast<ImageMagickContent> (Content::shared_from_this ());
+ };
+
+ void examine (boost::shared_ptr<Job>);
+ std::string summary () const;
+ void as_xml (xmlpp::Node *) const;
+ boost::shared_ptr<Content> clone () const;
+ Time length () const;
+
+ void set_video_length (ContentVideoFrame);
+
+ static bool valid_file (boost::filesystem::path);
+};
diff --git a/src/lib/imagemagick_decoder.cc b/src/lib/imagemagick_decoder.cc
index 5ce22c296..15c919e87 100644
--- a/src/lib/imagemagick_decoder.cc
+++ b/src/lib/imagemagick_decoder.cc
@@ -20,6 +20,7 @@
#include <iostream>
#include <boost/filesystem.hpp>
#include <Magick++.h>
+#include "imagemagick_content.h"
#include "imagemagick_decoder.h"
#include "image.h"
#include "film.h"
@@ -31,66 +32,66 @@ using std::cout;
using boost::shared_ptr;
using libdcp::Size;
-ImageMagickDecoder::ImageMagickDecoder (
- boost::shared_ptr<Film> f, DecodeOptions o)
- : Decoder (f, o)
- , VideoDecoder (f, o)
+ImageMagickDecoder::ImageMagickDecoder (shared_ptr<const Film> f, shared_ptr<const ImageMagickContent> c)
+ : Decoder (f)
+ , VideoDecoder (f, c)
+ , _imagemagick_content (c)
{
- if (boost::filesystem::is_directory (_film->content_path())) {
- for (
- boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (_film->content_path());
- i != boost::filesystem::directory_iterator();
- ++i) {
-
- if (still_image_file (i->path().string())) {
- _files.push_back (i->path().string());
- }
- }
- } else {
- _files.push_back (_film->content_path ());
- }
- _iter = _files.begin ();
}
libdcp::Size
-ImageMagickDecoder::native_size () const
+ImageMagickDecoder::video_size () const
{
- if (_files.empty ()) {
- throw DecodeError (_("no still image files found"));
+ if (!_video_size) {
+ using namespace MagickCore;
+ Magick::Image* image = new Magick::Image (_imagemagick_content->file().string());
+ _video_size = libdcp::Size (image->columns(), image->rows());
+ delete image;
}
- /* Look at the first file and assume its size holds for all */
- using namespace MagickCore;
- Magick::Image* image = new Magick::Image (_film->content_path ());
- libdcp::Size const s = libdcp::Size (image->columns(), image->rows());
- delete image;
+ return _video_size.get ();
+}
- return s;
+int
+ImageMagickDecoder::video_length () const
+{
+ return _imagemagick_content->video_length ();
}
-bool
+float
+ImageMagickDecoder::video_frame_rate () const
+{
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return 24;
+ }
+
+ return f->dcp_video_frame_rate ();
+}
+
+void
ImageMagickDecoder::pass ()
{
- if (_iter == _files.end()) {
- if (video_frame() >= _film->still_duration_in_frames()) {
- return true;
- }
+ if (_next_video >= _imagemagick_content->length ()) {
+ return;
+ }
- emit_video (_image, true, double (video_frame()) / frames_per_second());
- return false;
+ if (_image) {
+ video (_image, true, _next_video);
+ return;
}
+
+ Magick::Image* magick_image = new Magick::Image (_imagemagick_content->file().string ());
+ _video_size = libdcp::Size (magick_image->columns(), magick_image->rows());
- Magick::Image* magick_image = new Magick::Image (_film->content_path ());
-
- libdcp::Size size = native_size ();
- shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, size, false));
+ _image.reset (new SimpleImage (PIX_FMT_RGB24, _video_size.get(), false));
using namespace MagickCore;
- uint8_t* p = image->data()[0];
- for (int y = 0; y < size.height; ++y) {
- for (int x = 0; x < size.width; ++x) {
+ uint8_t* p = _image->data()[0];
+ for (int y = 0; y < _video_size->height; ++y) {
+ for (int x = 0; x < _video_size->width; ++x) {
Magick::Color c = magick_image->pixelColor (x, y);
*p++ = c.redQuantum() * 255 / QuantumRange;
*p++ = c.greenQuantum() * 255 / QuantumRange;
@@ -100,59 +101,40 @@ ImageMagickDecoder::pass ()
delete magick_image;
- _image = image->crop (_film->crop(), true);
-
- emit_video (_image, false, double (video_frame()) / frames_per_second());
-
- ++_iter;
- return false;
+ _image = _image->crop (_imagemagick_content->crop(), true);
+ video (_image, false, _next_video);
}
-PixelFormat
-ImageMagickDecoder::pixel_format () const
-{
- /* XXX: always true? */
- return PIX_FMT_RGB24;
-}
-
-bool
-ImageMagickDecoder::seek_to_last ()
+void
+ImageMagickDecoder::seek (Time t)
{
- if (_iter == _files.end()) {
- _iter = _files.begin();
- } else {
- --_iter;
- }
-
- return false;
+ _next_video = t;
}
-bool
-ImageMagickDecoder::seek (double t)
+void
+ImageMagickDecoder::seek_back ()
{
- int const f = t * frames_per_second();
-
- _iter = _files.begin ();
- for (int i = 0; i < f; ++i) {
- if (_iter == _files.end()) {
- return true;
- }
- ++_iter;
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return;
}
- return false;
+ _next_video -= f->video_frames_to_time (2);
}
void
-ImageMagickDecoder::film_changed (Film::Property p)
+ImageMagickDecoder::seek_forward ()
{
- if (p == Film::CROP) {
- OutputChanged ();
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return;
}
+
+ _next_video += f->video_frames_to_time (1);
}
-float
-ImageMagickDecoder::frames_per_second () const
+Time
+ImageMagickDecoder::next () const
{
- return _film->source_frame_rate ();
+ return _next_video;
}
diff --git a/src/lib/imagemagick_decoder.h b/src/lib/imagemagick_decoder.h
index 80a08f81f..6640032ba 100644
--- a/src/lib/imagemagick_decoder.h
+++ b/src/lib/imagemagick_decoder.h
@@ -23,62 +23,35 @@ namespace Magick {
class Image;
}
+class ImageMagickContent;
+
class ImageMagickDecoder : public VideoDecoder
{
public:
- ImageMagickDecoder (boost::shared_ptr<Film>, DecodeOptions);
-
- float frames_per_second () const;
-
- libdcp::Size native_size () const;
-
- SourceFrame length () const {
- /* We don't know */
- return 0;
- }
+ ImageMagickDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const ImageMagickContent>);
- int audio_channels () const {
- return 0;
- }
+ /* Decoder */
- int audio_sample_rate () const {
- return 0;
- }
+ void pass ();
+ void seek (Time);
+ void seek_back ();
+ void seek_forward ();
+ Time next () const;
- int64_t audio_channel_layout () const {
- return 0;
- }
+ /* VideoDecoder */
- bool seek (double);
- bool seek_to_last ();
+ float video_frame_rate () const;
+ libdcp::Size video_size () const;
+ ContentVideoFrame video_length () const;
-protected:
- bool pass ();
- PixelFormat pixel_format () const;
+ /* ImageMagickDecoder */
- int time_base_numerator () const {
- return 0;
- }
-
- int time_base_denominator () const {
- return 0;
- }
-
- int sample_aspect_ratio_numerator () const {
- /* XXX */
- return 1;
- }
-
- int sample_aspect_ratio_denominator () const {
- /* XXX */
- return 1;
+ boost::shared_ptr<const ImageMagickContent> content () const {
+ return _imagemagick_content;
}
private:
- void film_changed (Film::Property);
-
- std::list<std::string> _files;
- std::list<std::string>::iterator _iter;
-
+ boost::shared_ptr<const ImageMagickContent> _imagemagick_content;
boost::shared_ptr<Image> _image;
+ mutable boost::optional<libdcp::Size> _video_size;
};
diff --git a/src/lib/job.cc b/src/lib/job.cc
index 9a5812fa7..2e6385d62 100644
--- a/src/lib/job.cc
+++ b/src/lib/job.cc
@@ -35,8 +35,6 @@ using std::list;
using std::stringstream;
using boost::shared_ptr;
-/** @param s Film that we are operating on.
- */
Job::Job (shared_ptr<Film> f)
: _film (f)
, _thread (0)
@@ -94,7 +92,7 @@ Job::run_wrapper ()
set_state (FINISHED_ERROR);
set_error (
e.what (),
- _("It is not known what caused this error. The best idea is to report the problem to the DVD-o-matic mailing list (dvdomatic@carlh.net)")
+ _("It is not known what caused this error. The best idea is to report the problem to the DCP-o-matic mailing list (dcpomatic@carlh.net)")
);
} catch (...) {
@@ -103,7 +101,7 @@ Job::run_wrapper ()
set_state (FINISHED_ERROR);
set_error (
_("Unknown error"),
- _("It is not known what caused this error. The best idea is to report the problem to the DVD-o-matic mailing list (dvdomatic@carlh.net)")
+ _("It is not known what caused this error. The best idea is to report the problem to the DCP-o-matic mailing list (dcpomatic@carlh.net)")
);
}
@@ -200,7 +198,7 @@ Job::set_progress (float p)
boost::this_thread::interruption_point ();
if (paused ()) {
- dvdomatic_sleep (1);
+ dcpomatic_sleep (1);
}
}
diff --git a/src/lib/job.h b/src/lib/job.h
index 37fa56d20..40e90b73c 100644
--- a/src/lib/job.h
+++ b/src/lib/job.h
@@ -21,8 +21,8 @@
* @brief A parent class to represent long-running tasks which are run in their own thread.
*/
-#ifndef DVDOMATIC_JOB_H
-#define DVDOMATIC_JOB_H
+#ifndef DCPOMATIC_JOB_H
+#define DCPOMATIC_JOB_H
#include <string>
#include <boost/thread/mutex.hpp>
@@ -38,7 +38,7 @@ class Film;
class Job : public boost::enable_shared_from_this<Job>
{
public:
- Job (boost::shared_ptr<Film> s);
+ Job (boost::shared_ptr<Film>);
virtual ~Job() {}
/** @return user-readable name of this job */
@@ -91,7 +91,6 @@ protected:
void set_state (State);
void set_error (std::string s, std::string d);
- /** Film for this job */
boost::shared_ptr<Film> _film;
private:
diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc
index 910597628..f96275467 100644
--- a/src/lib/job_manager.cc
+++ b/src/lib/job_manager.cc
@@ -126,7 +126,7 @@ JobManager::scheduler ()
}
}
- dvdomatic_sleep (1);
+ dcpomatic_sleep (1);
}
}
diff --git a/src/lib/log.h b/src/lib/log.h
index 3a2cfcbfd..3ad6516c1 100644
--- a/src/lib/log.h
+++ b/src/lib/log.h
@@ -17,8 +17,8 @@
*/
-#ifndef DVDOMATIC_LOG_H
-#define DVDOMATIC_LOG_H
+#ifndef DCPOMATIC_LOG_H
+#define DCPOMATIC_LOG_H
/** @file src/log.h
* @brief A very simple logging class.
diff --git a/src/lib/delay_line.cc b/src/lib/null_content.cc
index f6af6f9b1..3bbda92da 100644
--- a/src/lib/delay_line.cc
+++ b/src/lib/null_content.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013 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
@@ -17,41 +17,41 @@
*/
-#include <stdint.h>
-#include <cstring>
-#include <algorithm>
-#include <iostream>
-#include "delay_line.h"
-#include "util.h"
+#include "null_content.h"
+#include "film.h"
-using std::min;
using boost::shared_ptr;
-/* @param seconds Delay in seconds, +ve to move audio later.
- */
-DelayLine::DelayLine (shared_ptr<Log> log, double seconds)
- : TimedAudioVideoProcessor (log)
- , _seconds (seconds)
+NullContent::NullContent (shared_ptr<const Film> f, Time s, Time len)
+ : Content (f, s)
+ , VideoContent (f, s, f->time_to_video_frames (len))
+ , AudioContent (f, s)
+ , _audio_length (f->time_to_audio_frames (len))
+ , _length (len)
{
-
+
}
-void
-DelayLine::process_audio (shared_ptr<const AudioBuffers> data, double t)
+int
+NullContent::content_audio_frame_rate () const
{
- if (_seconds > 0) {
- t += _seconds;
- }
-
- Audio (data, t);
+ return output_audio_frame_rate ();
}
+
-void
-DelayLine::process_video (shared_ptr<const Image> image, bool same, boost::shared_ptr<Subtitle> sub, double t)
+int
+NullContent::output_audio_frame_rate () const
{
- if (_seconds < 0) {
- t -= _seconds;
- }
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+ return film->dcp_audio_frame_rate ();
+}
- Video (image, same, sub, t);
+int
+NullContent::audio_channels () const
+{
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+ return film->dcp_audio_channels ();
}
+
diff --git a/src/lib/null_content.h b/src/lib/null_content.h
new file mode 100644
index 000000000..f8829658c
--- /dev/null
+++ b/src/lib/null_content.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (C) 2013 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 <string>
+#include <boost/shared_ptr.hpp>
+#include "video_content.h"
+#include "audio_content.h"
+
+class NullContent : public VideoContent, public AudioContent
+{
+public:
+ NullContent (boost::shared_ptr<const Film>, Time, Time);
+
+ std::string summary () const {
+ return "";
+ }
+
+ std::string information () const {
+ return "";
+ }
+
+ void as_xml (xmlpp::Node *) const {}
+
+ boost::shared_ptr<Content> clone () const {
+ return boost::shared_ptr<Content> ();
+ }
+
+ int audio_channels () const;
+
+ ContentAudioFrame audio_length () const {
+ return _audio_length;
+ }
+
+ int content_audio_frame_rate () const;
+
+ int output_audio_frame_rate () const;
+
+ AudioMapping audio_mapping () const {
+ return AudioMapping ();
+ }
+
+ Time length () const {
+ return _length;
+ }
+
+private:
+ ContentAudioFrame _audio_length;
+ Time _length;
+};
diff --git a/src/lib/options.h b/src/lib/options.h
deleted file mode 100644
index 0d2c07fd5..000000000
--- a/src/lib/options.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- Copyright (C) 2012 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 DVDOMATIC_OPTIONS_H
-#define DVDOMATIC_OPTIONS_H
-
-/** @file src/options.h
- * @brief Options for a decoding operation.
- */
-
-class DecodeOptions
-{
-public:
- DecodeOptions ()
- : decode_video (true)
- , decode_audio (true)
- , decode_subtitles (false)
- , video_sync (true)
- {}
-
- bool decode_video;
- bool decode_audio;
- bool decode_subtitles;
- bool video_sync;
-};
-
-#endif
diff --git a/src/lib/player.cc b/src/lib/player.cc
new file mode 100644
index 000000000..ff13f95db
--- /dev/null
+++ b/src/lib/player.cc
@@ -0,0 +1,355 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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 "player.h"
+#include "film.h"
+#include "ffmpeg_decoder.h"
+#include "ffmpeg_content.h"
+#include "imagemagick_decoder.h"
+#include "imagemagick_content.h"
+#include "sndfile_decoder.h"
+#include "sndfile_content.h"
+#include "playlist.h"
+#include "job.h"
+#include "image.h"
+#include "null_content.h"
+#include "black_decoder.h"
+#include "silence_decoder.h"
+
+using std::list;
+using std::cout;
+using std::min;
+using std::max;
+using std::vector;
+using boost::shared_ptr;
+using boost::weak_ptr;
+using boost::dynamic_pointer_cast;
+
+struct Piece
+{
+ Piece (shared_ptr<Content> c, shared_ptr<Decoder> d)
+ : content (c)
+ , decoder (d)
+ {}
+
+ shared_ptr<Content> content;
+ shared_ptr<Decoder> decoder;
+};
+
+Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p)
+ : _film (f)
+ , _playlist (p)
+ , _video (true)
+ , _audio (true)
+ , _subtitles (true)
+ , _have_valid_pieces (false)
+ , _position (0)
+ , _audio_buffers (f->dcp_audio_channels(), 0)
+ , _next_audio (0)
+{
+ _playlist->Changed.connect (bind (&Player::playlist_changed, this));
+ _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2));
+}
+
+void
+Player::disable_video ()
+{
+ _video = false;
+}
+
+void
+Player::disable_audio ()
+{
+ _audio = false;
+}
+
+void
+Player::disable_subtitles ()
+{
+ _subtitles = false;
+}
+
+bool
+Player::pass ()
+{
+ if (!_have_valid_pieces) {
+ setup_pieces ();
+ _have_valid_pieces = true;
+ }
+
+ /* Here we are just finding the active decoder with the earliest last emission time, then
+ calling pass on it.
+ */
+
+ Time earliest_t = TIME_MAX;
+ shared_ptr<Piece> earliest;
+
+ for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
+ cout << "check " << (*i)->content->file() << " start=" << (*i)->content->start() << ", next=" << (*i)->decoder->next() << ", end=" << (*i)->content->end() << "\n";
+ if (((*i)->decoder->next() + (*i)->content->start()) >= (*i)->content->end()) {
+ continue;
+ }
+
+ if (!_audio && dynamic_pointer_cast<SndfileContent> ((*i)->content)) {
+ continue;
+ }
+
+ Time const t = (*i)->content->start() + (*i)->decoder->next();
+ if (t < earliest_t) {
+ cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n";
+ earliest_t = t;
+ earliest = *i;
+ }
+ }
+
+ if (!earliest) {
+ return true;
+ }
+
+ cout << "PASS:\n";
+ cout << "\tpass " << earliest->content->file() << " ";
+ if (dynamic_pointer_cast<FFmpegContent> (earliest->content)) {
+ cout << " FFmpeg.\n";
+ } else if (dynamic_pointer_cast<ImageMagickContent> (earliest->content)) {
+ cout << " ImageMagickContent.\n";
+ } else if (dynamic_pointer_cast<SndfileContent> (earliest->content)) {
+ cout << " SndfileContent.\n";
+ } else if (dynamic_pointer_cast<BlackDecoder> (earliest->decoder)) {
+ cout << " Black.\n";
+ } else if (dynamic_pointer_cast<SilenceDecoder> (earliest->decoder)) {
+ cout << " Silence.\n";
+ }
+
+ earliest->decoder->pass ();
+ _position = earliest->content->start() + earliest->decoder->next ();
+ cout << "\tpassed to " << _position << " " << (_position / TIME_HZ) << "\n";
+
+ return false;
+}
+
+void
+Player::process_video (weak_ptr<Content> weak_content, shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub, Time time)
+{
+ cout << "[V]\n";
+
+ shared_ptr<Content> content = weak_content.lock ();
+ if (!content) {
+ return;
+ }
+
+ time += content->start ();
+
+ Video (image, same, sub, time);
+}
+
+void
+Player::process_audio (weak_ptr<Content> weak_content, shared_ptr<const AudioBuffers> audio, Time time)
+{
+ shared_ptr<Content> content = weak_content.lock ();
+ if (!content) {
+ return;
+ }
+
+ /* The time of this audio may indicate that some of our buffered audio is not going to
+ be added to any more, so it can be emitted.
+ */
+
+ time += content->start ();
+
+ if (time > _next_audio) {
+ /* We can emit some audio from our buffers */
+ assert (_film->time_to_audio_frames (time - _next_audio) <= _audio_buffers.frames());
+ OutputAudioFrame const N = _film->time_to_audio_frames (time - _next_audio);
+ shared_ptr<AudioBuffers> emit (new AudioBuffers (_audio_buffers.channels(), N));
+ emit->copy_from (&_audio_buffers, N, 0, 0);
+ Audio (emit, _next_audio);
+ _next_audio += _film->audio_frames_to_time (N);
+
+ /* And remove it from our buffers */
+ if (_audio_buffers.frames() > N) {
+ _audio_buffers.move (N, 0, _audio_buffers.frames() - N);
+ }
+ _audio_buffers.set_frames (_audio_buffers.frames() - N);
+ }
+
+ /* Now accumulate the new audio into our buffers */
+ _audio_buffers.ensure_size (_audio_buffers.frames() + audio->frames());
+ _audio_buffers.accumulate_frames (audio.get(), 0, 0, audio->frames ());
+}
+
+/** @return true on error */
+void
+Player::seek (Time t)
+{
+ if (!_have_valid_pieces) {
+ setup_pieces ();
+ _have_valid_pieces = true;
+ }
+
+ if (_pieces.empty ()) {
+ return;
+ }
+
+ cout << "seek to " << t << " " << (t / TIME_HZ) << "\n";
+
+ for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
+ Time s = t - (*i)->content->start ();
+ s = max (static_cast<Time> (0), s);
+ s = min ((*i)->content->length(), s);
+ cout << "seek [" << (*i)->content->file() << "," << (*i)->content->start() << "," << (*i)->content->end() << "] to " << s << "\n";
+ (*i)->decoder->seek (s);
+ }
+
+ /* XXX: don't seek audio because we don't need to... */
+}
+
+
+void
+Player::seek_back ()
+{
+
+}
+
+void
+Player::seek_forward ()
+{
+
+}
+
+struct ContentSorter
+{
+ bool operator() (shared_ptr<Content> a, shared_ptr<Content> b)
+ {
+ return a->start() < b->start();
+ }
+};
+
+void
+Player::setup_pieces ()
+{
+// cout << "----- Player SETUP PIECES.\n";
+
+ list<shared_ptr<Piece> > old_pieces = _pieces;
+
+ _pieces.clear ();
+
+ Playlist::ContentList content = _playlist->content ();
+ sort (content.begin(), content.end(), ContentSorter ());
+
+ for (Playlist::ContentList::iterator i = content.begin(); i != content.end(); ++i) {
+
+ shared_ptr<Decoder> decoder;
+
+ /* XXX: into content? */
+
+ shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
+ if (fc) {
+ shared_ptr<FFmpegDecoder> fd (new FFmpegDecoder (_film, fc, _video, _audio, _subtitles));
+
+ fd->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3, _4));
+ fd->Audio.connect (bind (&Player::process_audio, this, *i, _1, _2));
+
+ decoder = fd;
+// cout << "\tFFmpeg @ " << fc->start() << " -- " << fc->end() << "\n";
+ }
+
+ shared_ptr<const ImageMagickContent> ic = dynamic_pointer_cast<const ImageMagickContent> (*i);
+ if (ic) {
+ shared_ptr<ImageMagickDecoder> id;
+
+ /* See if we can re-use an old ImageMagickDecoder */
+ for (list<shared_ptr<Piece> >::const_iterator j = old_pieces.begin(); j != old_pieces.end(); ++j) {
+ shared_ptr<ImageMagickDecoder> imd = dynamic_pointer_cast<ImageMagickDecoder> ((*j)->decoder);
+ if (imd && imd->content() == ic) {
+ id = imd;
+ }
+ }
+
+ if (!id) {
+ id.reset (new ImageMagickDecoder (_film, ic));
+ id->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3, _4));
+ }
+
+ decoder = id;
+// cout << "\tImageMagick @ " << ic->start() << " -- " << ic->end() << "\n";
+ }
+
+ shared_ptr<const SndfileContent> sc = dynamic_pointer_cast<const SndfileContent> (*i);
+ if (sc) {
+ shared_ptr<AudioDecoder> sd (new SndfileDecoder (_film, sc));
+ sd->Audio.connect (bind (&Player::process_audio, this, *i, _1, _2));
+
+ decoder = sd;
+// cout << "\tSndfile @ " << sc->start() << " -- " << sc->end() << "\n";
+ }
+
+ _pieces.push_back (shared_ptr<Piece> (new Piece (*i, decoder)));
+ }
+
+ /* Fill in visual gaps with black and audio gaps with silence */
+
+ Time video_pos = 0;
+ Time audio_pos = 0;
+ list<shared_ptr<Piece> > pieces_copy = _pieces;
+ for (list<shared_ptr<Piece> >::iterator i = pieces_copy.begin(); i != pieces_copy.end(); ++i) {
+ if (dynamic_pointer_cast<VideoContent> ((*i)->content)) {
+ Time const diff = (*i)->content->start() - video_pos;
+ if (diff > 0) {
+ shared_ptr<NullContent> nc (new NullContent (_film, video_pos, diff));
+ shared_ptr<BlackDecoder> bd (new BlackDecoder (_film, nc));
+ bd->Video.connect (bind (&Player::process_video, this, nc, _1, _2, _3, _4));
+ _pieces.push_back (shared_ptr<Piece> (new Piece (nc, bd)));
+// cout << "\tblack @ " << video_pos << " -- " << (video_pos + diff) << "\n";
+ }
+
+ video_pos = (*i)->content->end();
+ } else {
+ Time const diff = (*i)->content->start() - audio_pos;
+ if (diff > 0) {
+ shared_ptr<NullContent> nc (new NullContent (_film, audio_pos, diff));
+ shared_ptr<SilenceDecoder> sd (new SilenceDecoder (_film, nc));
+ sd->Audio.connect (bind (&Player::process_audio, this, nc, _1, _2));
+ _pieces.push_back (shared_ptr<Piece> (new Piece (nc, sd)));
+// cout << "\tsilence @ " << audio_pos << " -- " << (audio_pos + diff) << "\n";
+ }
+ audio_pos = (*i)->content->end();
+ }
+ }
+}
+
+void
+Player::content_changed (weak_ptr<Content> w, int p)
+{
+ shared_ptr<Content> c = w.lock ();
+ if (!c) {
+ return;
+ }
+
+ if (p == ContentProperty::START || p == VideoContentProperty::VIDEO_LENGTH) {
+ _have_valid_pieces = false;
+ }
+}
+
+void
+Player::playlist_changed ()
+{
+ _have_valid_pieces = false;
+}
diff --git a/src/lib/player.h b/src/lib/player.h
new file mode 100644
index 000000000..4d23d1951
--- /dev/null
+++ b/src/lib/player.h
@@ -0,0 +1,89 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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_PLAYER_H
+#define DCPOMATIC_PLAYER_H
+
+#include <list>
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+#include "video_source.h"
+#include "audio_source.h"
+#include "video_sink.h"
+#include "audio_sink.h"
+#include "playlist.h"
+#include "audio_buffers.h"
+
+class Job;
+class Film;
+class Playlist;
+class AudioContent;
+class Piece;
+
+/** @class Player
+ * @brief A class which can `play' a Playlist; emitting its audio and video.
+ */
+
+class Player : public VideoSource, public AudioSource, public boost::enable_shared_from_this<Player>
+{
+public:
+ Player (boost::shared_ptr<const Film>, boost::shared_ptr<const Playlist>);
+
+ void disable_video ();
+ void disable_audio ();
+ void disable_subtitles ();
+
+ bool pass ();
+ void seek (Time);
+ void seek_back ();
+ void seek_forward ();
+
+ Time position () const {
+ return _position;
+ }
+
+private:
+
+ void process_video (boost::weak_ptr<Content>, boost::shared_ptr<const Image>, bool, boost::shared_ptr<Subtitle>, Time);
+ void process_audio (boost::weak_ptr<Content>, boost::shared_ptr<const AudioBuffers>, Time);
+ void setup_pieces ();
+ void playlist_changed ();
+ void content_changed (boost::weak_ptr<Content>, int);
+ void do_seek (Time, bool);
+
+ boost::shared_ptr<const Film> _film;
+ boost::shared_ptr<const Playlist> _playlist;
+
+ bool _video;
+ bool _audio;
+ bool _subtitles;
+
+ /** Our pieces are ready to go; if this is false the pieces must be (re-)created before they are used */
+ bool _have_valid_pieces;
+ std::list<boost::shared_ptr<Piece> > _pieces;
+
+ /** Time of the earliest thing not yet to have been emitted */
+ Time _position;
+ AudioBuffers _audio_buffers;
+ Time _next_audio;
+};
+
+#endif
diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc
new file mode 100644
index 000000000..7ab320558
--- /dev/null
+++ b/src/lib/playlist.cc
@@ -0,0 +1,287 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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 <libcxml/cxml.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/lexical_cast.hpp>
+#include "playlist.h"
+#include "sndfile_content.h"
+#include "sndfile_decoder.h"
+#include "video_content.h"
+#include "ffmpeg_decoder.h"
+#include "ffmpeg_content.h"
+#include "imagemagick_decoder.h"
+#include "imagemagick_content.h"
+#include "job.h"
+#include "config.h"
+#include "util.h"
+
+#include "i18n.h"
+
+using std::list;
+using std::cout;
+using std::vector;
+using std::min;
+using std::max;
+using std::string;
+using std::stringstream;
+using boost::optional;
+using boost::shared_ptr;
+using boost::weak_ptr;
+using boost::dynamic_pointer_cast;
+using boost::lexical_cast;
+
+Playlist::Playlist ()
+ : _loop (1)
+{
+
+}
+
+Playlist::Playlist (shared_ptr<const Playlist> other)
+ : _loop (other->_loop)
+{
+ for (ContentList::const_iterator i = other->_content.begin(); i != other->_content.end(); ++i) {
+ _content.push_back ((*i)->clone ());
+ }
+}
+
+Playlist::~Playlist ()
+{
+ _content.clear ();
+ reconnect ();
+}
+
+void
+Playlist::content_changed (weak_ptr<Content> c, int p)
+{
+ ContentChanged (c, p);
+}
+
+string
+Playlist::audio_digest () const
+{
+ string t;
+
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ if (!dynamic_pointer_cast<const AudioContent> (*i)) {
+ continue;
+ }
+
+ t += (*i)->digest ();
+
+ shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
+ if (fc) {
+ t += lexical_cast<string> (fc->audio_stream()->id);
+ }
+ }
+
+ t += lexical_cast<string> (_loop);
+
+ return md5_digest (t.c_str(), t.length());
+}
+
+string
+Playlist::video_digest () const
+{
+ string t;
+
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ if (!dynamic_pointer_cast<const VideoContent> (*i)) {
+ continue;
+ }
+
+ t += (*i)->digest ();
+ shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
+ if (fc && fc->subtitle_stream()) {
+ t += fc->subtitle_stream()->id;
+ }
+ }
+
+ t += lexical_cast<string> (_loop);
+
+ return md5_digest (t.c_str(), t.length());
+}
+
+/** @param node <Playlist> node */
+void
+Playlist::set_from_xml (shared_ptr<const Film> film, shared_ptr<const cxml::Node> node)
+{
+ list<shared_ptr<cxml::Node> > c = node->node_children ("Content");
+ for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
+ string const type = (*i)->string_child ("Type");
+
+ boost::shared_ptr<Content> content;
+
+ if (type == "FFmpeg") {
+ content.reset (new FFmpegContent (film, *i));
+ } else if (type == "ImageMagick") {
+ content.reset (new ImageMagickContent (film, *i));
+ } else if (type == "Sndfile") {
+ content.reset (new SndfileContent (film, *i));
+ }
+
+ _content.push_back (content);
+ }
+
+ reconnect ();
+ _loop = node->number_child<int> ("Loop");
+}
+
+/** @param node <Playlist> node */
+void
+Playlist::as_xml (xmlpp::Node* node)
+{
+ for (ContentList::iterator i = _content.begin(); i != _content.end(); ++i) {
+ (*i)->as_xml (node->add_child ("Content"));
+ }
+
+ node->add_child("Loop")->add_child_text(lexical_cast<string> (_loop));
+}
+
+void
+Playlist::add (shared_ptr<Content> c)
+{
+ _content.push_back (c);
+ reconnect ();
+ Changed ();
+}
+
+void
+Playlist::remove (shared_ptr<Content> c)
+{
+ ContentList::iterator i = _content.begin ();
+ while (i != _content.end() && *i != c) {
+ ++i;
+ }
+
+ if (i != _content.end ()) {
+ _content.erase (i);
+ Changed ();
+ }
+}
+
+void
+Playlist::set_loop (int l)
+{
+ _loop = l;
+ Changed ();
+}
+
+bool
+Playlist::has_subtitles () const
+{
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (*i);
+ if (fc && !fc->subtitle_streams().empty()) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+class FrameRateCandidate
+{
+public:
+ FrameRateCandidate (float source_, int dcp_)
+ : source (source_)
+ , dcp (dcp_)
+ {}
+
+ float source;
+ int dcp;
+};
+
+int
+Playlist::best_dcp_frame_rate () const
+{
+ list<int> const allowed_dcp_frame_rates = Config::instance()->allowed_dcp_frame_rates ();
+
+ /* Work out what rates we could manage, including those achieved by using skip / repeat. */
+ list<FrameRateCandidate> candidates;
+
+ /* Start with the ones without skip / repeat so they will get matched in preference to skipped/repeated ones */
+ for (list<int>::const_iterator i = allowed_dcp_frame_rates.begin(); i != allowed_dcp_frame_rates.end(); ++i) {
+ candidates.push_back (FrameRateCandidate (*i, *i));
+ }
+
+ /* Then the skip/repeat ones */
+ for (list<int>::const_iterator i = allowed_dcp_frame_rates.begin(); i != allowed_dcp_frame_rates.end(); ++i) {
+ candidates.push_back (FrameRateCandidate (float (*i) / 2, *i));
+ candidates.push_back (FrameRateCandidate (float (*i) * 2, *i));
+ }
+
+ /* Pick the best one, bailing early if we hit an exact match */
+ float error = std::numeric_limits<float>::max ();
+ optional<FrameRateCandidate> best;
+ list<FrameRateCandidate>::iterator i = candidates.begin();
+ while (i != candidates.end()) {
+
+ float this_error = std::numeric_limits<float>::max ();
+ for (ContentList::const_iterator j = _content.begin(); j != _content.end(); ++j) {
+ shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*j);
+ if (!vc) {
+ continue;
+ }
+
+ this_error += fabs (i->source - vc->video_frame_rate ());
+ }
+
+ if (this_error < error) {
+ error = this_error;
+ best = *i;
+ }
+
+ ++i;
+ }
+
+ if (!best) {
+ return 24;
+ }
+
+ return best->dcp;
+}
+
+Time
+Playlist::length () const
+{
+ Time len = 0;
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ len = max (len, (*i)->end ());
+ }
+
+ return len;
+}
+
+void
+Playlist::reconnect ()
+{
+ for (list<boost::signals2::connection>::iterator i = _content_connections.begin(); i != _content_connections.end(); ++i) {
+ i->disconnect ();
+ }
+
+ _content_connections.clear ();
+
+ for (ContentList::iterator i = _content.begin(); i != _content.end(); ++i) {
+ _content_connections.push_back ((*i)->Changed.connect (bind (&Playlist::content_changed, this, _1, _2)));
+ }
+}
+
diff --git a/src/lib/playlist.h b/src/lib/playlist.h
new file mode 100644
index 000000000..aff6017fa
--- /dev/null
+++ b/src/lib/playlist.h
@@ -0,0 +1,101 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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_PLAYLIST_H
+#define DCPOMATIC_PLAYLIST_H
+
+#include <list>
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+#include "video_source.h"
+#include "audio_source.h"
+#include "video_sink.h"
+#include "audio_sink.h"
+#include "ffmpeg_content.h"
+#include "audio_mapping.h"
+
+class Content;
+class FFmpegContent;
+class FFmpegDecoder;
+class ImageMagickContent;
+class ImageMagickDecoder;
+class SndfileContent;
+class SndfileDecoder;
+class Job;
+class Film;
+class Region;
+
+/** @class Playlist
+ * @brief A set of content files (video and audio), with knowledge of how they should be arranged into
+ * a DCP.
+ *
+ * This class holds Content objects, and it knows how they should be arranged. At the moment
+ * the ordering is implicit; video content is placed sequentially, and audio content is taken
+ * from the video unless any sound-only files are present. If sound-only files exist, they
+ * are played simultaneously (i.e. they can be split up into multiple files for different channels)
+ */
+
+class Playlist
+{
+public:
+ Playlist ();
+ Playlist (boost::shared_ptr<const Playlist>);
+ ~Playlist ();
+
+ void as_xml (xmlpp::Node *);
+ void set_from_xml (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+
+ void add (boost::shared_ptr<Content>);
+ void remove (boost::shared_ptr<Content>);
+
+ bool has_subtitles () const;
+
+ typedef std::vector<boost::shared_ptr<Content> > ContentList;
+
+ ContentList content () const {
+ return _content;
+ }
+
+ std::string audio_digest () const;
+ std::string video_digest () const;
+
+ int loop () const {
+ return _loop;
+ }
+
+ void set_loop (int l);
+
+ Time length () const;
+ int best_dcp_frame_rate () const;
+
+ mutable boost::signals2::signal<void ()> Changed;
+ mutable boost::signals2::signal<void (boost::weak_ptr<Content>, int)> ContentChanged;
+
+private:
+ void content_changed (boost::weak_ptr<Content>, int);
+ void reconnect ();
+
+ ContentList _content;
+ int _loop;
+ std::list<boost::signals2::connection> _content_connections;
+};
+
+#endif
diff --git a/src/lib/po/es_ES.po b/src/lib/po/es_ES.po
index 944505007..58ad48a9c 100644
--- a/src/lib/po/es_ES.po
+++ b/src/lib/po/es_ES.po
@@ -5,7 +5,7 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: LIBDVDOMATIC\n"
+"Project-Id-Version: LIBDCPOMATIC\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-05-09 09:51+0100\n"
"PO-Revision-Date: 2013-04-02 19:10-0500\n"
@@ -250,10 +250,10 @@ msgstr "Horizontal deblocking filter A"
#: src/lib/job.cc:97 src/lib/job.cc:106
msgid ""
"It is not known what caused this error. The best idea is to report the "
-"problem to the DVD-o-matic mailing list (dvdomatic@carlh.net)"
+"problem to the DCP-o-matic mailing list (dcpomatic@carlh.net)"
msgstr ""
"Error desconocido. La mejor idea es informar del problema a la lista de "
-"correo de DVD-O-matic (dvdomatic@carlh.net)"
+"correo de DCP-o-matic (dcpomatic@carlh.net)"
#: src/lib/filter.cc:82
msgid "Kernel deinterlacer"
diff --git a/src/lib/po/fr_FR.po b/src/lib/po/fr_FR.po
index 81f61d8b8..f7e362eda 100644
--- a/src/lib/po/fr_FR.po
+++ b/src/lib/po/fr_FR.po
@@ -5,7 +5,7 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: DVD-o-matic FRENCH\n"
+"Project-Id-Version: DCP-o-matic FRENCH\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-05-09 09:51+0100\n"
"PO-Revision-Date: 2013-05-21 10:30+0100\n"
@@ -257,8 +257,8 @@ msgstr "Filtre dé-bloc horizontal"
#: src/lib/job.cc:97
#: src/lib/job.cc:106
-msgid "It is not known what caused this error. The best idea is to report the problem to the DVD-o-matic mailing list (dvdomatic@carlh.net)"
-msgstr "Erreur indéterminée. Merci de rapporter le problème à la liste DVD-o-matic (dvdomatic@carlh.net)"
+msgid "It is not known what caused this error. The best idea is to report the problem to the DCP-o-matic mailing list (dcpomatic@carlh.net)"
+msgstr "Erreur indéterminée. Merci de rapporter le problème à la liste DCP-o-matic (dcpomatic@carlh.net)"
#: src/lib/filter.cc:82
msgid "Kernel deinterlacer"
diff --git a/src/lib/po/it_IT.po b/src/lib/po/it_IT.po
index 6a7486d82..1a46e67be 100644
--- a/src/lib/po/it_IT.po
+++ b/src/lib/po/it_IT.po
@@ -247,10 +247,10 @@ msgstr "Filtro A sblocco orizzontale"
#: src/lib/job.cc:97 src/lib/job.cc:106
msgid ""
"It is not known what caused this error. The best idea is to report the "
-"problem to the DVD-o-matic mailing list (dvdomatic@carlh.net)"
+"problem to the DCP-o-matic mailing list (dcpomatic@carlh.net)"
msgstr ""
"Non sappiamo cosa ha causato questo errore. La cosa migliore è inviare un "
-"report del problema alla mailing list di DVD-o-matic (dvdomatic@carlh.net)"
+"report del problema alla mailing list di DCP-o-matic (dcpomatic@carlh.net)"
#: src/lib/filter.cc:82
msgid "Kernel deinterlacer"
diff --git a/src/lib/po/sv_SE.po b/src/lib/po/sv_SE.po
index 58d336ef8..d9a9c5955 100644
--- a/src/lib/po/sv_SE.po
+++ b/src/lib/po/sv_SE.po
@@ -5,7 +5,7 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: DVD-o-matic\n"
+"Project-Id-Version: DCP-o-matic\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-05-09 09:51+0100\n"
"PO-Revision-Date: 2013-04-10 15:35+0100\n"
@@ -248,10 +248,10 @@ msgstr "Filter för horisontal kantighetsutjämning A"
#: src/lib/job.cc:97 src/lib/job.cc:106
msgid ""
"It is not known what caused this error. The best idea is to report the "
-"problem to the DVD-o-matic mailing list (dvdomatic@carlh.net)"
+"problem to the DCP-o-matic mailing list (dcpomatic@carlh.net)"
msgstr ""
"Det är inte känt vad som orsakade detta fel. Bästa sättet att rapportera "
-"problemet är till DVD-o-matics mejl-lista (dvdomatic@carlh.net)"
+"problemet är till DCP-o-matics mejl-lista (dcpomatic@carlh.net)"
#: src/lib/filter.cc:82
msgid "Kernel deinterlacer"
diff --git a/src/lib/processor.h b/src/lib/processor.h
deleted file mode 100644
index 603239f8f..000000000
--- a/src/lib/processor.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- Copyright (C) 2012 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.
-
-*/
-
-/** @file src/processor.h
- * @brief Parent class for classes which accept and then emit video or audio data.
- */
-
-#ifndef DVDOMATIC_PROCESSOR_H
-#define DVDOMATIC_PROCESSOR_H
-
-#include "video_source.h"
-#include "video_sink.h"
-#include "audio_source.h"
-#include "audio_sink.h"
-
-class Log;
-
-/** @class Processor
- * @brief Base class for processors.
- */
-class Processor
-{
-public:
- /** Construct a Processor.
- * @param log Log to use.
- */
- Processor (boost::shared_ptr<Log> log)
- : _log (log)
- {}
-
- virtual ~Processor() {}
-
- /** Will be called at the end of a processing run */
- virtual void process_end () {}
-
-protected:
- boost::shared_ptr<Log> _log; ///< log to write to
-};
-
-/** @class AudioVideoProcessor
- * @brief A processor which handles both video and audio data.
- */
-class AudioVideoProcessor : public Processor, public VideoSource, public VideoSink, public AudioSource, public AudioSink
-{
-public:
- /** Construct an AudioVideoProcessor.
- * @param log Log to write to.
- */
- AudioVideoProcessor (boost::shared_ptr<Log> log)
- : Processor (log)
- {}
-};
-
-class TimedAudioVideoProcessor : public Processor, public TimedVideoSource, public TimedVideoSink, public TimedAudioSource, public TimedAudioSink
-{
-public:
- TimedAudioVideoProcessor (boost::shared_ptr<Log> log)
- : Processor (log)
- {}
-};
-
-
-/** @class AudioProcessor
- * @brief A processor which handles just audio data.
- */
-class AudioProcessor : public Processor, public AudioSource, public AudioSink
-{
-public:
- /** Construct an AudioProcessor.
- * @param log Log to write to.
- */
- AudioProcessor (boost::shared_ptr<Log> log)
- : Processor (log)
- {}
-};
-
-/** @class VideoProcessor
- * @brief A processor which handles just video data.
- */
-class VideoProcessor : public Processor, public VideoSource, public VideoSink
-{
-public:
- /** Construct an VideoProcessor.
- * @param log Log to write to.
- */
- VideoProcessor (boost::shared_ptr<Log> log)
- : Processor (log)
- {}
-};
-
-class TimedVideoProcessor : public Processor, public TimedVideoSource, public TimedVideoSink
-{
-public:
- TimedVideoProcessor (boost::shared_ptr<Log> log)
- : Processor (log)
- {}
-};
-
-#endif
diff --git a/src/lib/scaler.h b/src/lib/scaler.h
index c80f4b7db..a736e92de 100644
--- a/src/lib/scaler.h
+++ b/src/lib/scaler.h
@@ -21,8 +21,8 @@
* @brief A class to describe one of FFmpeg's software scalers.
*/
-#ifndef DVDOMATIC_SCALER_H
-#define DVDOMATIC_SCALER_H
+#ifndef DCPOMATIC_SCALER_H
+#define DCPOMATIC_SCALER_H
#include <string>
#include <vector>
diff --git a/src/lib/scp_dcp_job.h b/src/lib/scp_dcp_job.h
index 08d8e2c78..8c16d53fb 100644
--- a/src/lib/scp_dcp_job.h
+++ b/src/lib/scp_dcp_job.h
@@ -34,7 +34,7 @@ public:
private:
void set_status (std::string);
-
+
mutable boost::mutex _status_mutex;
std::string _status;
};
diff --git a/src/lib/server.cc b/src/lib/server.cc
index 9c5a77f68..07b826946 100644
--- a/src/lib/server.cc
+++ b/src/lib/server.cc
@@ -29,6 +29,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/scoped_array.hpp>
+#include <libcxml/cxml.h>
#include "server.h"
#include "util.h"
#include "scaler.h"
@@ -51,6 +52,19 @@ using boost::bind;
using boost::scoped_array;
using libdcp::Size;
+ServerDescription::ServerDescription (shared_ptr<const cxml::Node> node)
+{
+ _host_name = node->string_child ("HostName");
+ _threads = node->number_child<int> ("Threads");
+}
+
+void
+ServerDescription::as_xml (xmlpp::Node* root) const
+{
+ root->add_child("HostName")->add_child_text (_host_name);
+ root->add_child("Threads")->add_child_text (boost::lexical_cast<string> (_threads));
+}
+
/** Create a server description from a string of metadata returned from as_metadata().
* @param v Metadata.
* @return ServerDescription, or 0.
@@ -68,15 +82,6 @@ ServerDescription::create_from_metadata (string v)
return new ServerDescription (b[0], atoi (b[1].c_str ()));
}
-/** @return Description of this server as text */
-string
-ServerDescription::as_metadata () const
-{
- stringstream s;
- s << _host_name << N_(" ") << _threads;
- return s.str ();
-}
-
Server::Server (shared_ptr<Log> log)
: _log (log)
{
@@ -106,7 +111,6 @@ Server::process (shared_ptr<Socket> socket)
string scaler_id = get_required_string (kv, N_("scaler"));
int frame = get_required_int (kv, N_("frame"));
int frames_per_second = get_required_int (kv, N_("frames_per_second"));
- string post_process = get_optional_string (kv, N_("post_process"));
int colour_lut_index = get_required_int (kv, N_("colour_lut"));
int j2k_bandwidth = get_required_int (kv, N_("j2k_bandwidth"));
Position subtitle_position (get_optional_int (kv, N_("subtitle_x")), get_optional_int (kv, N_("subtitle_y")));
@@ -131,7 +135,7 @@ Server::process (shared_ptr<Socket> socket)
DCPVideoFrame dcp_video_frame (
image, sub, out_size, padding, subtitle_offset, subtitle_scale,
- scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, _log
+ scaler, frame, frames_per_second, colour_lut_index, j2k_bandwidth, _log
);
shared_ptr<EncodedData> encoded = dcp_video_frame.encode_locally ();
diff --git a/src/lib/server.h b/src/lib/server.h
index 89aeca626..398401a55 100644
--- a/src/lib/server.h
+++ b/src/lib/server.h
@@ -26,10 +26,15 @@
#include <boost/thread.hpp>
#include <boost/asio.hpp>
#include <boost/thread/condition.hpp>
+#include <libxml++/libxml++.h>
#include "log.h"
class Socket;
+namespace cxml {
+ class Node;
+}
+
/** @class ServerDescription
* @brief Class to describe a server to which we can send encoding work.
*/
@@ -44,6 +49,8 @@ public:
, _threads (t)
{}
+ ServerDescription (boost::shared_ptr<const cxml::Node>);
+
/** @return server's host name or IP address in string form */
std::string host_name () const {
return _host_name;
@@ -62,7 +69,7 @@ public:
_threads = t;
}
- std::string as_metadata () const;
+ void as_xml (xmlpp::Node *) const;
static ServerDescription * create_from_metadata (std::string v);
diff --git a/src/lib/silence_decoder.cc b/src/lib/silence_decoder.cc
new file mode 100644
index 000000000..6cf91b41f
--- /dev/null
+++ b/src/lib/silence_decoder.cc
@@ -0,0 +1,78 @@
+/*
+ Copyright (C) 2013 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 "silence_decoder.h"
+#include "null_content.h"
+#include "audio_buffers.h"
+
+using std::min;
+using boost::shared_ptr;
+
+SilenceDecoder::SilenceDecoder (shared_ptr<const Film> f, shared_ptr<NullContent> c)
+ : Decoder (f)
+ , AudioDecoder (f, c)
+{
+
+}
+
+void
+SilenceDecoder::pass ()
+{
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ Time const this_time = min (_audio_content->length() - _next_audio, TIME_HZ / 2);
+ shared_ptr<AudioBuffers> data (new AudioBuffers (film->dcp_audio_channels(), film->time_to_audio_frames (this_time)));
+ data->make_silent ();
+ audio (data, _next_audio);
+}
+
+void
+SilenceDecoder::seek (Time t)
+{
+ _next_audio = t;
+}
+
+void
+SilenceDecoder::seek_back ()
+{
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return;
+ }
+
+ _next_audio -= f->video_frames_to_time (2);
+}
+
+void
+SilenceDecoder::seek_forward ()
+{
+ boost::shared_ptr<const Film> f = _film.lock ();
+ if (!f) {
+ return;
+ }
+
+ _next_audio += f->video_frames_to_time (1);
+}
+
+Time
+SilenceDecoder::next () const
+{
+ return _next_audio;
+}
diff --git a/src/lib/gain.h b/src/lib/silence_decoder.h
index 61fef5e85..8452bc43f 100644
--- a/src/lib/gain.h
+++ b/src/lib/silence_decoder.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013 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
@@ -17,15 +17,20 @@
*/
-#include "processor.h"
+#include <boost/shared_ptr.hpp>
+#include "audio_decoder.h"
-class Gain : public AudioProcessor
+class Film;
+class NullContent;
+
+class SilenceDecoder : public AudioDecoder
{
public:
- Gain (boost::shared_ptr<Log> log, float gain);
-
- void process_audio (boost::shared_ptr<const AudioBuffers>);
+ SilenceDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<NullContent>);
-private:
- float _gain;
+ void pass ();
+ void seek (Time);
+ void seek_back ();
+ void seek_forward ();
+ Time next () const;
};
diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc
new file mode 100644
index 000000000..0f895c95e
--- /dev/null
+++ b/src/lib/sndfile_content.cc
@@ -0,0 +1,144 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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 <libcxml/cxml.h>
+#include "sndfile_content.h"
+#include "sndfile_decoder.h"
+#include "compose.hpp"
+#include "job.h"
+
+#include "i18n.h"
+
+using std::string;
+using std::stringstream;
+using std::cout;
+using boost::shared_ptr;
+using boost::lexical_cast;
+
+SndfileContent::SndfileContent (shared_ptr<const Film> f, boost::filesystem::path p)
+ : Content (f, p)
+ , AudioContent (f, p)
+ , _audio_channels (0)
+ , _audio_length (0)
+ , _audio_frame_rate (0)
+{
+
+}
+
+SndfileContent::SndfileContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
+ : Content (f, node)
+ , AudioContent (f, node)
+{
+ _audio_channels = node->number_child<int> ("AudioChannels");
+ _audio_length = node->number_child<ContentAudioFrame> ("AudioLength");
+ _audio_frame_rate = node->number_child<int> ("AudioFrameRate");
+}
+
+string
+SndfileContent::summary () const
+{
+ return String::compose (_("Sound file: %1"), file().filename().string());
+}
+
+string
+SndfileContent::information () const
+{
+ if (_audio_frame_rate == 0) {
+ return "";
+ }
+
+ stringstream s;
+
+ s << String::compose (
+ _("%1 channels, %2kHz, %3 samples"),
+ audio_channels(),
+ content_audio_frame_rate() / 1000.0,
+ audio_length()
+ );
+
+ return s.str ();
+}
+
+bool
+SndfileContent::valid_file (boost::filesystem::path f)
+{
+ /* XXX: more extensions */
+ string ext = f.extension().string();
+ transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+ return (ext == ".wav" || ext == ".aif" || ext == ".aiff");
+}
+
+shared_ptr<Content>
+SndfileContent::clone () const
+{
+ return shared_ptr<Content> (new SndfileContent (*this));
+}
+
+void
+SndfileContent::examine (shared_ptr<Job> job)
+{
+ job->set_progress_unknown ();
+ Content::examine (job);
+
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ SndfileDecoder dec (film, shared_from_this());
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _audio_channels = dec.audio_channels ();
+ _audio_length = dec.audio_length ();
+ _audio_frame_rate = dec.audio_frame_rate ();
+ }
+
+ signal_changed (AudioContentProperty::AUDIO_CHANNELS);
+ signal_changed (AudioContentProperty::AUDIO_LENGTH);
+ signal_changed (AudioContentProperty::AUDIO_FRAME_RATE);
+}
+
+void
+SndfileContent::as_xml (xmlpp::Node* node) const
+{
+ node->add_child("Type")->add_child_text ("Sndfile");
+ Content::as_xml (node);
+ node->add_child("AudioChannels")->add_child_text (lexical_cast<string> (_audio_channels));
+ node->add_child("AudioLength")->add_child_text (lexical_cast<string> (_audio_length));
+ node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (_audio_frame_rate));
+}
+
+Time
+SndfileContent::length () const
+{
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ return film->audio_frames_to_time (audio_length ());
+}
+
+int
+SndfileContent::output_audio_frame_rate () const
+{
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ return film->dcp_audio_frame_rate ();
+}
diff --git a/src/lib/sndfile_content.h b/src/lib/sndfile_content.h
new file mode 100644
index 000000000..17423b8ed
--- /dev/null
+++ b/src/lib/sndfile_content.h
@@ -0,0 +1,78 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
+/*
+ Copyright (C) 2013 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.
+
+*/
+
+extern "C" {
+#include <libavutil/audioconvert.h>
+}
+#include "audio_content.h"
+
+namespace cxml {
+ class Node;
+}
+
+class SndfileContent : public AudioContent
+{
+public:
+ SndfileContent (boost::shared_ptr<const Film>, boost::filesystem::path);
+ SndfileContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+
+ boost::shared_ptr<SndfileContent> shared_from_this () {
+ return boost::dynamic_pointer_cast<SndfileContent> (Content::shared_from_this ());
+ }
+
+ void examine (boost::shared_ptr<Job>);
+ std::string summary () const;
+ std::string information () const;
+ void as_xml (xmlpp::Node *) const;
+ boost::shared_ptr<Content> clone () const;
+ Time length () const;
+
+ /* AudioContent */
+ int audio_channels () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_channels;
+ }
+
+ ContentAudioFrame audio_length () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_length;
+ }
+
+ int content_audio_frame_rate () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_frame_rate;
+ }
+
+ int output_audio_frame_rate () const;
+
+ AudioMapping audio_mapping () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _audio_mapping;
+ }
+
+ static bool valid_file (boost::filesystem::path);
+
+private:
+ int _audio_channels;
+ ContentAudioFrame _audio_length;
+ int _audio_frame_rate;
+ AudioMapping _audio_mapping;
+};
diff --git a/src/lib/sndfile_decoder.cc b/src/lib/sndfile_decoder.cc
index 7e9e67d0f..c4c6e5f4e 100644
--- a/src/lib/sndfile_decoder.cc
+++ b/src/lib/sndfile_decoder.cc
@@ -19,157 +19,101 @@
#include <iostream>
#include <sndfile.h>
+#include "sndfile_content.h"
#include "sndfile_decoder.h"
#include "film.h"
#include "exceptions.h"
+#include "audio_buffers.h"
#include "i18n.h"
using std::vector;
using std::string;
-using std::stringstream;
using std::min;
using std::cout;
using boost::shared_ptr;
-using boost::optional;
-SndfileDecoder::SndfileDecoder (shared_ptr<Film> f, DecodeOptions o)
- : Decoder (f, o)
- , AudioDecoder (f, o)
- , _done (0)
- , _frames (0)
+SndfileDecoder::SndfileDecoder (shared_ptr<const Film> f, shared_ptr<const SndfileContent> c)
+ : Decoder (f)
+ , AudioDecoder (f, c)
+ , _sndfile_content (c)
+ , _deinterleave_buffer (0)
{
- _done = 0;
- _frames = 0;
-
- vector<string> const files = _film->external_audio ();
-
- int N = 0;
- for (size_t i = 0; i < files.size(); ++i) {
- if (!files[i].empty()) {
- N = i + 1;
- }
- }
-
- if (N == 0) {
- return;
+ _sndfile = sf_open (_sndfile_content->file().string().c_str(), SFM_READ, &_info);
+ if (!_sndfile) {
+ throw DecodeError (_("could not open audio file for reading"));
}
- bool first = true;
-
- for (size_t i = 0; i < (size_t) N; ++i) {
- if (files[i].empty ()) {
- _sndfiles.push_back (0);
- } else {
- SF_INFO info;
- SNDFILE* s = sf_open (files[i].c_str(), SFM_READ, &info);
- if (!s) {
- throw DecodeError (_("could not open external audio file for reading"));
- }
+ _done = 0;
+ _remaining = _info.frames;
+}
- if (info.channels != 1) {
- throw DecodeError (_("external audio files must be mono"));
- }
-
- _sndfiles.push_back (s);
-
- if (first) {
- shared_ptr<SndfileStream> st (
- new SndfileStream (
- info.samplerate, av_get_default_channel_layout (N)
- )
- );
-
- _audio_streams.push_back (st);
- _audio_stream = st;
- _frames = info.frames;
- first = false;
- } else {
- if (info.frames != _frames) {
- throw DecodeError (_("external audio files have differing lengths"));
- }
- }
- }
- }
+SndfileDecoder::~SndfileDecoder ()
+{
+ sf_close (_sndfile);
+ delete[] _deinterleave_buffer;
}
-bool
+void
SndfileDecoder::pass ()
{
- if (_audio_streams.empty ()) {
- return true;
- }
-
/* Do things in half second blocks as I think there may be limits
to what FFmpeg (and in particular the resampler) can cope with.
*/
- sf_count_t const block = _audio_stream->sample_rate() / 2;
- shared_ptr<AudioBuffers> audio (new AudioBuffers (_audio_stream->channels(), block));
- sf_count_t const this_time = min (block, _frames - _done);
- for (size_t i = 0; i < _sndfiles.size(); ++i) {
- if (!_sndfiles[i]) {
- audio->make_silent (i);
- } else {
- sf_read_float (_sndfiles[i], audio->data(i), this_time);
- }
- }
+ sf_count_t const block = _sndfile_content->content_audio_frame_rate() / 2;
+ sf_count_t const this_time = min (block, _remaining);
- audio->set_frames (this_time);
- Audio (audio, double(_done) / _audio_stream->sample_rate());
- _done += this_time;
-
- return (_done == _frames);
-}
-
-SndfileDecoder::~SndfileDecoder ()
-{
- for (size_t i = 0; i < _sndfiles.size(); ++i) {
- if (_sndfiles[i]) {
- sf_close (_sndfiles[i]);
+ int const channels = _sndfile_content->audio_channels ();
+
+ shared_ptr<AudioBuffers> data (new AudioBuffers (channels, this_time));
+
+ if (_sndfile_content->audio_channels() == 1) {
+ /* No de-interleaving required */
+ sf_read_float (_sndfile, data->data(0), this_time);
+ } else {
+ /* Deinterleave */
+ if (!_deinterleave_buffer) {
+ _deinterleave_buffer = new float[block * channels];
+ }
+ sf_readf_float (_sndfile, _deinterleave_buffer, this_time);
+ vector<float*> out_ptr (channels);
+ for (int i = 0; i < channels; ++i) {
+ out_ptr[i] = data->data(i);
+ }
+ float* in_ptr = _deinterleave_buffer;
+ for (int i = 0; i < this_time; ++i) {
+ for (int j = 0; j < channels; ++j) {
+ *out_ptr[j]++ = *in_ptr++;
+ }
}
}
+
+ data->set_frames (this_time);
+ audio (data, double(_done) / audio_frame_rate());
+ _done += this_time;
+ _remaining -= this_time;
}
-shared_ptr<SndfileStream>
-SndfileStream::create ()
-{
- return shared_ptr<SndfileStream> (new SndfileStream);
-}
-
-shared_ptr<SndfileStream>
-SndfileStream::create (string t, optional<int> v)
+int
+SndfileDecoder::audio_channels () const
{
- if (!v) {
- /* version < 1; no type in the string, and there's only FFmpeg streams anyway */
- return shared_ptr<SndfileStream> ();
- }
-
- stringstream s (t);
- string type;
- s >> type;
- if (type != N_("external")) {
- return shared_ptr<SndfileStream> ();
- }
-
- return shared_ptr<SndfileStream> (new SndfileStream (t, v));
+ return _info.channels;
}
-SndfileStream::SndfileStream (string t, optional<int> v)
+ContentAudioFrame
+SndfileDecoder::audio_length () const
{
- assert (v);
-
- stringstream s (t);
- string type;
- s >> type >> _sample_rate >> _channel_layout;
+ return _info.frames;
}
-SndfileStream::SndfileStream ()
+int
+SndfileDecoder::audio_frame_rate () const
{
-
+ return _info.samplerate;
}
-string
-SndfileStream::to_string () const
+Time
+SndfileDecoder::next () const
{
- return String::compose (N_("external %1 %2"), _sample_rate, _channel_layout);
+ return _next_audio;
}
diff --git a/src/lib/sndfile_decoder.h b/src/lib/sndfile_decoder.h
index 9489cb5ec..b4fa5bc58 100644
--- a/src/lib/sndfile_decoder.h
+++ b/src/lib/sndfile_decoder.h
@@ -20,37 +20,30 @@
#include <sndfile.h>
#include "decoder.h"
#include "audio_decoder.h"
-#include "stream.h"
-class SndfileStream : public AudioStream
-{
-public:
- SndfileStream (int sample_rate, int64_t layout)
- : AudioStream (sample_rate, layout)
- {}
-
- std::string to_string () const;
-
- static boost::shared_ptr<SndfileStream> create ();
- static boost::shared_ptr<SndfileStream> create (std::string t, boost::optional<int> v);
-
-private:
- friend class stream_test;
-
- SndfileStream ();
- SndfileStream (std::string t, boost::optional<int> v);
-};
+class SndfileContent;
class SndfileDecoder : public AudioDecoder
{
public:
- SndfileDecoder (boost::shared_ptr<Film>, DecodeOptions);
+ SndfileDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const SndfileContent>);
~SndfileDecoder ();
- bool pass ();
+ void pass ();
+ void seek (Time) {}
+ void seek_back () {}
+ void seek_forward () {}
+ Time next () const;
+
+ int audio_channels () const;
+ ContentAudioFrame audio_length () const;
+ int audio_frame_rate () const;
private:
- std::vector<SNDFILE*> _sndfiles;
- sf_count_t _done;
- sf_count_t _frames;
+ boost::shared_ptr<const SndfileContent> _sndfile_content;
+ SNDFILE* _sndfile;
+ SF_INFO _info;
+ ContentAudioFrame _done;
+ ContentAudioFrame _remaining;
+ float* _deinterleave_buffer;
};
diff --git a/src/lib/sound_processor.h b/src/lib/sound_processor.h
index 2edf38840..bdbe72ba2 100644
--- a/src/lib/sound_processor.h
+++ b/src/lib/sound_processor.h
@@ -21,8 +21,8 @@
* @brief A class to describe a sound processor.
*/
-#ifndef DVDOMATIC_SOUND_PROCESSOR_H
-#define DVDOMATIC_SOUND_PROCESSOR_H
+#ifndef DCPOMATIC_SOUND_PROCESSOR_H
+#define DCPOMATIC_SOUND_PROCESSOR_H
#include <string>
#include <vector>
diff --git a/src/lib/stream.cc b/src/lib/stream.cc
deleted file mode 100644
index bfe7b5eb4..000000000
--- a/src/lib/stream.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- Copyright (C) 2012 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 <sstream>
-#include "compose.hpp"
-#include "stream.h"
-#include "ffmpeg_decoder.h"
-#include "sndfile_decoder.h"
-
-#include "i18n.h"
-
-using std::string;
-using std::stringstream;
-using boost::shared_ptr;
-using boost::optional;
-
-/** Construct a SubtitleStream from a value returned from to_string().
- * @param t String returned from to_string().
- * @param v State file version.
- */
-SubtitleStream::SubtitleStream (string t, boost::optional<int>)
-{
- stringstream n (t);
- n >> _id;
-
- size_t const s = t.find (' ');
- if (s != string::npos) {
- _name = t.substr (s + 1);
- }
-}
-
-/** @return A canonical string representation of this stream */
-string
-SubtitleStream::to_string () const
-{
- return String::compose (N_("%1 %2"), _id, _name);
-}
-
-/** Create a SubtitleStream from a value returned from to_string().
- * @param t String returned from to_string().
- * @param v State file version.
- */
-shared_ptr<SubtitleStream>
-SubtitleStream::create (string t, optional<int> v)
-{
- return shared_ptr<SubtitleStream> (new SubtitleStream (t, v));
-}
-
-/** Create an AudioStream from a string returned from to_string().
- * @param t String returned from to_string().
- * @param v State file version.
- * @return AudioStream, or 0.
- */
-shared_ptr<AudioStream>
-audio_stream_factory (string t, optional<int> v)
-{
- shared_ptr<AudioStream> s;
-
- s = FFmpegAudioStream::create (t, v);
- if (!s) {
- s = SndfileStream::create (t, v);
- }
-
- return s;
-}
-
-/** Create a SubtitleStream from a string returned from to_string().
- * @param t String returned from to_string().
- * @param v State file version.
- * @return SubtitleStream, or 0.
- */
-shared_ptr<SubtitleStream>
-subtitle_stream_factory (string t, optional<int> v)
-{
- return SubtitleStream::create (t, v);
-}
diff --git a/src/lib/stream.h b/src/lib/stream.h
deleted file mode 100644
index 16b06e4bc..000000000
--- a/src/lib/stream.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- Copyright (C) 2012 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.
-
-*/
-
-/** @file src/lib/stream.h
- * @brief Representations of audio and subtitle streams.
- *
- * Some content may have multiple `streams' of audio and/or subtitles; perhaps
- * for multiple languages, or for stereo / surround mixes. These classes represent
- * those streams, and know about their details.
- */
-
-#ifndef DVDOMATIC_STREAM_H
-#define DVDOMATIC_STREAM_H
-
-#include <stdint.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/optional.hpp>
-extern "C" {
-#include <libavutil/audioconvert.h>
-}
-
-/** @class Stream
- * @brief Parent class for streams.
- */
-class Stream
-{
-public:
- virtual ~Stream () {}
- virtual std::string to_string () const = 0;
-};
-
-/** @class AudioStream
- * @brief A stream of audio data.
- */
-struct AudioStream : public Stream
-{
-public:
- AudioStream (int r, int64_t l)
- : _sample_rate (r)
- , _channel_layout (l)
- {}
-
- /* Only used for backwards compatibility for state file version < 1 */
- void set_sample_rate (int s) {
- _sample_rate = s;
- }
-
- int channels () const {
- return av_get_channel_layout_nb_channels (_channel_layout);
- }
-
- int sample_rate () const {
- return _sample_rate;
- }
-
- int64_t channel_layout () const {
- return _channel_layout;
- }
-
-protected:
- AudioStream ()
- : _sample_rate (0)
- , _channel_layout (0)
- {}
-
- int _sample_rate;
- int64_t _channel_layout;
-};
-
-/** @class SubtitleStream
- * @brief A stream of subtitle data.
- */
-class SubtitleStream : public Stream
-{
-public:
- SubtitleStream (std::string n, int i)
- : _name (n)
- , _id (i)
- {}
-
- std::string to_string () const;
-
- std::string name () const {
- return _name;
- }
-
- int id () const {
- return _id;
- }
-
- static boost::shared_ptr<SubtitleStream> create (std::string t, boost::optional<int> v);
-
-private:
- friend class stream_test;
-
- SubtitleStream (std::string t, boost::optional<int> v);
-
- std::string _name;
- int _id;
-};
-
-boost::shared_ptr<AudioStream> audio_stream_factory (std::string t, boost::optional<int> version);
-boost::shared_ptr<SubtitleStream> subtitle_stream_factory (std::string t, boost::optional<int> version);
-
-#endif
diff --git a/src/lib/subtitle.cc b/src/lib/subtitle.cc
index 5c1ad9706..eafccd9b5 100644
--- a/src/lib/subtitle.cc
+++ b/src/lib/subtitle.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
@@ -45,8 +47,8 @@ TimedSubtitle::TimedSubtitle (AVSubtitle const & sub)
double const packet_time = static_cast<double> (sub.pts) / AV_TIME_BASE;
/* hence start time for this sub */
- _from = packet_time + (double (sub.start_display_time) / 1e3);
- _to = packet_time + (double (sub.end_display_time) / 1e3);
+ _from = (packet_time + (double (sub.start_display_time) / 1e3)) * TIME_HZ;
+ _to = (packet_time + (double (sub.end_display_time) / 1e3)) * TIME_HZ;
if (sub.num_rects > 1) {
throw DecodeError (_("multi-part subtitles not yet supported"));
@@ -80,9 +82,9 @@ TimedSubtitle::TimedSubtitle (AVSubtitle const & sub)
_subtitle.reset (new Subtitle (Position (rect->x, rect->y), image));
}
-/** @param t Time in seconds from the start of the source */
+/** @param t Time from the start of the source */
bool
-TimedSubtitle::displayed_at (double t) const
+TimedSubtitle::displayed_at (Time t) const
{
return t >= _from && t <= _to;
}
diff --git a/src/lib/subtitle.h b/src/lib/subtitle.h
index 38ba4e70e..52bd35923 100644
--- a/src/lib/subtitle.h
+++ b/src/lib/subtitle.h
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
@@ -23,7 +25,7 @@
#include <list>
#include <boost/shared_ptr.hpp>
-#include "util.h"
+#include "types.h"
struct AVSubtitle;
class Image;
@@ -65,7 +67,7 @@ class TimedSubtitle
public:
TimedSubtitle (AVSubtitle const &);
- bool displayed_at (double t) const;
+ bool displayed_at (Time) const;
boost::shared_ptr<Subtitle> subtitle () const {
return _subtitle;
@@ -74,8 +76,8 @@ public:
private:
/** the subtitle */
boost::shared_ptr<Subtitle> _subtitle;
- /** display from time in seconds from the start of the film */
- double _from;
- /** display to time in seconds from the start of the film */
- double _to;
+ /** display from time from the start of the content */
+ Time _from;
+ /** display to time from the start of the content */
+ Time _to;
};
diff --git a/src/lib/timer.h b/src/lib/timer.h
index f509a7492..173d0d961 100644
--- a/src/lib/timer.h
+++ b/src/lib/timer.h
@@ -22,8 +22,8 @@
* @brief Some timing classes for debugging and profiling.
*/
-#ifndef DVDOMATIC_TIMER_H
-#define DVDOMATIC_TIMER_H
+#ifndef DCPOMATIC_TIMER_H
+#define DCPOMATIC_TIMER_H
#include <string>
#include <map>
diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc
index 234ebe051..f9a305367 100644
--- a/src/lib/transcode_job.cc
+++ b/src/lib/transcode_job.cc
@@ -39,11 +39,9 @@ using std::setprecision;
using boost::shared_ptr;
/** @param s Film to use.
- * @param o Decode options.
*/
-TranscodeJob::TranscodeJob (shared_ptr<Film> f, DecodeOptions o)
+TranscodeJob::TranscodeJob (shared_ptr<Film> f)
: Job (f)
- , _decode_opt (o)
{
}
@@ -60,11 +58,9 @@ TranscodeJob::run ()
try {
_film->log()->log (N_("Transcode job starting"));
- _film->log()->log (String::compose (N_("Audio delay is %1ms"), _film->audio_delay()));
- _encoder.reset (new Encoder (_film));
- Transcoder w (_film, _decode_opt, this, _encoder);
- w.go ();
+ _transcoder.reset (new Transcoder (_film, shared_from_this ()));
+ _transcoder->go ();
set_progress (1);
set_state (FINISHED_OK);
@@ -83,11 +79,11 @@ TranscodeJob::run ()
string
TranscodeJob::status () const
{
- if (!_encoder) {
+ if (!_transcoder) {
return _("0%");
}
- float const fps = _encoder->current_frames_per_second ();
+ float const fps = _transcoder->current_encoding_rate ();
if (fps == 0) {
return Job::status ();
}
@@ -106,24 +102,17 @@ TranscodeJob::status () const
int
TranscodeJob::remaining_time () const
{
- float fps = _encoder->current_frames_per_second ();
- if (fps == 0) {
+ if (!_transcoder) {
return 0;
}
+
+ float fps = _transcoder->current_encoding_rate ();
- if (!_film->length()) {
+ if (fps == 0) {
return 0;
}
/* Compute approximate proposed length here, as it's only here that we need it */
- int length = _film->length().get();
- FrameRateConversion const frc (_film->source_frame_rate(), _film->dcp_frame_rate());
- if (frc.skip) {
- length /= 2;
- }
- /* If we are repeating it shouldn't affect transcode time, so don't take it into account */
-
- /* We assume that dcp_length() is valid, if it is set */
- int const left = length - _encoder->video_frames_out();
+ OutputVideoFrame const left = _film->time_to_video_frames (_film->length ()) - _transcoder->video_frames_out();
return left / fps;
}
diff --git a/src/lib/transcode_job.h b/src/lib/transcode_job.h
index 9b69e4e65..7880a925e 100644
--- a/src/lib/transcode_job.h
+++ b/src/lib/transcode_job.h
@@ -23,9 +23,8 @@
#include <boost/shared_ptr.hpp>
#include "job.h"
-#include "options.h"
-class Encoder;
+class Transcoder;
/** @class TranscodeJob
* @brief A job which transcodes from one format to another.
@@ -33,16 +32,14 @@ class Encoder;
class TranscodeJob : public Job
{
public:
- TranscodeJob (boost::shared_ptr<Film> f, DecodeOptions od);
+ TranscodeJob (boost::shared_ptr<Film> f);
std::string name () const;
void run ();
std::string status () const;
-protected:
+private:
int remaining_time () const;
-private:
- DecodeOptions _decode_opt;
- boost::shared_ptr<Encoder> _encoder;
+ boost::shared_ptr<Transcoder> _transcoder;
};
diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc
index 48cf402d7..d4c5210dc 100644
--- a/src/lib/transcoder.cc
+++ b/src/lib/transcoder.cc
@@ -28,15 +28,11 @@
#include <boost/signals2.hpp>
#include "transcoder.h"
#include "encoder.h"
-#include "decoder_factory.h"
#include "film.h"
-#include "matcher.h"
-#include "delay_line.h"
-#include "options.h"
-#include "gain.h"
#include "video_decoder.h"
#include "audio_decoder.h"
-#include "trimmer.h"
+#include "player.h"
+#include "job.h"
using std::string;
using boost::shared_ptr;
@@ -44,91 +40,38 @@ using boost::dynamic_pointer_cast;
/** Construct a transcoder using a Decoder that we create and a supplied Encoder.
* @param f Film that we are transcoding.
- * @param o Decode options.
* @param j Job that we are running under, or 0.
* @param e Encoder to use.
*/
-Transcoder::Transcoder (shared_ptr<Film> f, DecodeOptions o, Job* j, shared_ptr<Encoder> e)
+Transcoder::Transcoder (shared_ptr<Film> f, shared_ptr<Job> j)
: _job (j)
- , _encoder (e)
- , _decoders (decoder_factory (f, o))
+ , _player (f->player ())
+ , _encoder (new Encoder (f, j))
{
- assert (_encoder);
-
- shared_ptr<AudioStream> st = f->audio_stream();
- if (st && st->sample_rate ()) {
- _matcher.reset (new Matcher (f->log(), st->sample_rate(), f->source_frame_rate()));
- }
- _delay_line.reset (new DelayLine (f->log(), f->audio_delay() / 1000.0f));
- _gain.reset (new Gain (f->log(), f->audio_gain()));
-
- int const sr = st ? st->sample_rate() : 0;
- int const trim_start = f->trim_type() == Film::ENCODE ? f->trim_start() : 0;
- int const trim_end = f->trim_type() == Film::ENCODE ? f->trim_end() : 0;
- _trimmer.reset (new Trimmer (
- f->log(), trim_start, trim_end, f->length().get_value_or(0),
- sr, f->source_frame_rate(), f->dcp_frame_rate()
- ));
-
- /* Set up the decoder to use the film's set streams */
- _decoders.video->set_subtitle_stream (f->subtitle_stream ());
- if (f->audio_stream ()) {
- _decoders.audio->set_audio_stream (f->audio_stream ());
+ if (!f->with_subtitles ()) {
+ _player->disable_subtitles ();
}
- _decoders.video->connect_video (_delay_line);
- if (_matcher) {
- _delay_line->connect_video (_matcher);
- _matcher->connect_video (_trimmer);
- } else {
- _delay_line->connect_video (_trimmer);
- }
- _trimmer->connect_video (_encoder);
-
- _decoders.audio->connect_audio (_delay_line);
- if (_matcher) {
- _delay_line->connect_audio (_matcher);
- _matcher->connect_audio (_gain);
- } else {
- _delay_line->connect_audio (_gain);
- }
- _gain->connect_audio (_trimmer);
- _trimmer->connect_audio (_encoder);
+ _player->connect_video (_encoder);
+ _player->connect_audio (_encoder);
}
-/** Run the decoder, passing its output to the encoder, until the decoder
- * has no more data to present.
- */
void
Transcoder::go ()
{
_encoder->process_begin ();
-
- bool done[2] = { false, false };
-
- while (1) {
- if (!done[0]) {
- done[0] = _decoders.video->pass ();
- if (_job) {
- _decoders.video->set_progress (_job);
- }
- }
-
- if (!done[1] && _decoders.audio && dynamic_pointer_cast<Decoder> (_decoders.audio) != dynamic_pointer_cast<Decoder> (_decoders.video)) {
- done[1] = _decoders.audio->pass ();
- } else {
- done[1] = true;
- }
-
- if (done[0] && done[1]) {
- break;
- }
- }
-
- _delay_line->process_end ();
- if (_matcher) {
- _matcher->process_end ();
- }
- _gain->process_end ();
+ while (!_player->pass ()) {}
_encoder->process_end ();
}
+
+float
+Transcoder::current_encoding_rate () const
+{
+ return _encoder->current_encoding_rate ();
+}
+
+int
+Transcoder::video_frames_out () const
+{
+ return _encoder->video_frames_out ();
+}
diff --git a/src/lib/transcoder.h b/src/lib/transcoder.h
index f5b8ae6e3..f7da3bd01 100644
--- a/src/lib/transcoder.h
+++ b/src/lib/transcoder.h
@@ -17,28 +17,21 @@
*/
+#include "types.h"
+
/** @file src/transcoder.h
- * @brief A class which takes a Film and some Options, then uses those to transcode the film.
*
* A decoder is selected according to the content type, and the encoder can be specified
* as a parameter to the constructor.
*/
-#include "decoder_factory.h"
-
class Film;
class Job;
class Encoder;
-class Matcher;
class VideoFilter;
-class Gain;
-class VideoDecoder;
-class AudioDecoder;
-class DelayLine;
-class Trimmer;
+class Player;
/** @class Transcoder
- * @brief A class which takes a Film and some Options, then uses those to transcode the film.
*
* A decoder is selected according to the content type, and the encoder can be specified
* as a parameter to the constructor.
@@ -48,26 +41,17 @@ class Transcoder
public:
Transcoder (
boost::shared_ptr<Film> f,
- DecodeOptions o,
- Job* j,
- boost::shared_ptr<Encoder> e
+ boost::shared_ptr<Job> j
);
void go ();
- boost::shared_ptr<VideoDecoder> video_decoder () const {
- return _decoders.video;
- }
+ float current_encoding_rate () const;
+ int video_frames_out () const;
-protected:
+private:
/** A Job that is running this Transcoder, or 0 */
- Job* _job;
- /** The encoder that we will use */
+ boost::shared_ptr<Job> _job;
+ boost::shared_ptr<Player> _player;
boost::shared_ptr<Encoder> _encoder;
- /** The decoders that we will use */
- Decoders _decoders;
- boost::shared_ptr<Matcher> _matcher;
- boost::shared_ptr<DelayLine> _delay_line;
- boost::shared_ptr<Gain> _gain;
- boost::shared_ptr<Trimmer> _trimmer;
};
diff --git a/src/lib/trimmer.cc b/src/lib/trimmer.cc
deleted file mode 100644
index b7afc9299..000000000
--- a/src/lib/trimmer.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- Copyright (C) 2013 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 <boost/shared_ptr.hpp>
-#include "trimmer.h"
-
-using std::cout;
-using std::max;
-using boost::shared_ptr;
-
-/** @param audio_sample_rate Audio sampling rate, or 0 if there is no audio */
-Trimmer::Trimmer (
- shared_ptr<Log> log,
- int video_trim_start,
- int video_trim_end,
- int video_length,
- int audio_sample_rate,
- float frames_per_second,
- int dcp_frames_per_second
- )
- : AudioVideoProcessor (log)
- , _video_start (video_trim_start)
- , _video_end (video_length - video_trim_end)
- , _video_in (0)
- , _audio_in (0)
-{
- FrameRateConversion frc (frames_per_second, dcp_frames_per_second);
-
- if (frc.skip) {
- _video_start /= 2;
- _video_end /= 2;
- } else if (frc.repeat) {
- _video_start *= 2;
- _video_end *= 2;
- }
-
- if (audio_sample_rate) {
- _audio_start = video_frames_to_audio_frames (_video_start, audio_sample_rate, frames_per_second);
- _audio_end = video_frames_to_audio_frames (_video_end, audio_sample_rate, frames_per_second);
- }
-
- /* XXX: this is a hack; this flag means that no trim is happening at the end of the film, and I'm
- using that to prevent audio trim being rounded to video trim, which breaks the current set
- of regression tests. This could be removed if a) the regression tests are regenerated and b)
- I can work out what DCP length should be.
- */
- _no_trim = (_video_start == 0) && (_video_end == (video_length - video_trim_end));
-}
-
-void
-Trimmer::process_video (shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub)
-{
- if (_no_trim || (_video_in >= _video_start && _video_in <= _video_end)) {
- Video (image, same, sub);
- }
-
- ++_video_in;
-}
-
-void
-Trimmer::process_audio (shared_ptr<const AudioBuffers> audio)
-{
- if (_no_trim) {
- Audio (audio);
- return;
- }
-
- int64_t offset = _audio_start - _audio_in;
- if (offset > audio->frames()) {
- _audio_in += audio->frames ();
- return;
- }
-
- if (offset < 0) {
- offset = 0;
- }
-
- int64_t length = _audio_end - max (_audio_in, _audio_start);
- if (length < 0) {
- _audio_in += audio->frames ();
- return;
- }
-
- if (length > (audio->frames() - offset)) {
- length = audio->frames () - offset;
- }
-
- _audio_in += audio->frames ();
-
- if (offset != 0 || length != audio->frames ()) {
- shared_ptr<AudioBuffers> copy (new AudioBuffers (audio));
- copy->move (offset, 0, length);
- copy->set_frames (length);
- audio = copy;
- }
-
- Audio (audio);
-}
-
diff --git a/src/lib/types.cc b/src/lib/types.cc
new file mode 100644
index 000000000..c077bad3e
--- /dev/null
+++ b/src/lib/types.cc
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 2013 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 "types.h"
+
+using std::max;
+using std::min;
+
+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);
+}
+
+bool operator!= (Crop const & a, Crop const & b)
+{
+ return !(a == b);
+}
+
+
+/** @param other A Rect.
+ * @return The intersection of this with `other'.
+ */
+Rect
+Rect::intersection (Rect const & other) const
+{
+ int const tx = max (x, other.x);
+ int const ty = max (y, other.y);
+
+ return Rect (
+ tx, ty,
+ min (x + width, other.x + other.width) - tx,
+ min (y + height, other.y + other.height) - ty
+ );
+}
+
+bool
+Rect::contains (Position p) const
+{
+ return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height));
+}
diff --git a/src/lib/types.h b/src/lib/types.h
new file mode 100644
index 000000000..8f2fe2c71
--- /dev/null
+++ b/src/lib/types.h
@@ -0,0 +1,116 @@
+/*
+ Copyright (C) 2013 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_TYPES_H
+#define DCPOMATIC_TYPES_H
+
+#include <vector>
+#include <stdint.h>
+#include <boost/shared_ptr.hpp>
+#include <libdcp/util.h>
+
+class Content;
+
+typedef int64_t ContentAudioFrame;
+typedef int ContentVideoFrame;
+typedef int64_t Time;
+#define TIME_MAX INT64_MAX
+#define TIME_HZ ((Time) 96000)
+typedef int64_t OutputAudioFrame;
+typedef int OutputVideoFrame;
+
+/** @struct Crop
+ * @brief A description of the crop of an image or video.
+ */
+struct Crop
+{
+ Crop () : left (0), right (0), top (0), bottom (0) {}
+
+ /** Number of pixels to remove from the left-hand side */
+ int left;
+ /** Number of pixels to remove from the right-hand side */
+ int right;
+ /** Number of pixels to remove from the top */
+ int top;
+ /** Number of pixels to remove from the bottom */
+ int bottom;
+};
+
+extern bool operator== (Crop const & a, Crop const & b);
+extern bool operator!= (Crop const & a, Crop const & b);
+
+/** @struct Position
+ * @brief A position.
+ */
+struct Position
+{
+ Position ()
+ : x (0)
+ , y (0)
+ {}
+
+ Position (int x_, int y_)
+ : x (x_)
+ , y (y_)
+ {}
+
+ /** x coordinate */
+ int x;
+ /** y coordinate */
+ int y;
+};
+
+/** @struct Rect
+ * @brief A rectangle.
+ */
+struct Rect
+{
+ Rect ()
+ : x (0)
+ , y (0)
+ , width (0)
+ , height (0)
+ {}
+
+ Rect (int x_, int y_, int w_, int h_)
+ : x (x_)
+ , y (y_)
+ , width (w_)
+ , height (h_)
+ {}
+
+ int x;
+ int y;
+ int width;
+ int height;
+
+ Position position () const {
+ return Position (x, y);
+ }
+
+ libdcp::Size size () const {
+ return libdcp::Size (width, height);
+ }
+
+ Rect intersection (Rect const & other) const;
+
+ bool contains (Position) const;
+};
+
+#endif
diff --git a/src/lib/ui_signaller.h b/src/lib/ui_signaller.h
index 221bcbe95..428ab698f 100644
--- a/src/lib/ui_signaller.h
+++ b/src/lib/ui_signaller.h
@@ -17,8 +17,8 @@
*/
-#ifndef DVDOMATIC_UI_SIGNALLER_H
-#define DVDOMATIC_UI_SIGNALLER_H
+#ifndef DCPOMATIC_UI_SIGNALLER_H
+#define DCPOMATIC_UI_SIGNALLER_H
#include <boost/bind.hpp>
#include <boost/asio.hpp>
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 2f8be6edd..e1bc560c6 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -27,7 +27,7 @@
#include <iostream>
#include <fstream>
#include <climits>
-#ifdef DVDOMATIC_POSIX
+#ifdef DCPOMATIC_POSIX
#include <execinfo.h>
#include <cxxabi.h>
#endif
@@ -61,26 +61,33 @@ extern "C" {
#include "filter.h"
#include "sound_processor.h"
#include "config.h"
+#include "container.h"
#ifdef DVDOMATIC_WINDOWS
#include "stack.hpp"
#endif
#include "i18n.h"
-using std::cout;
using std::string;
using std::stringstream;
-using std::list;
+using std::setfill;
using std::ostream;
+using std::endl;
using std::vector;
+using std::hex;
+using std::setw;
using std::ifstream;
-using std::istream;
+using std::ios;
using std::min;
using std::max;
+using std::list;
using std::multimap;
+using std::istream;
+using std::numeric_limits;
using std::pair;
using std::ofstream;
using boost::shared_ptr;
+using boost::thread;
using boost::lexical_cast;
using boost::optional;
using libdcp::Size;
@@ -113,6 +120,12 @@ seconds_to_hms (int s)
return hms.str ();
}
+string
+time_to_hms (Time t)
+{
+ return seconds_to_hms (t / TIME_HZ);
+}
+
/** @param s Number of seconds.
* @return String containing an approximate description of s (e.g. "about 2 hours")
*/
@@ -149,7 +162,7 @@ seconds_to_approximate_hms (int s)
return ap.str ();
}
-#ifdef DVDOMATIC_POSIX
+#ifdef DCPOMATIC_POSIX
/** @param l Mangled C++ identifier.
* @return Demangled version.
*/
@@ -262,7 +275,7 @@ LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *)
* Must be called from the UI thread, if there is one.
*/
void
-dvdomatic_setup ()
+dcpomatic_setup ()
{
#ifdef DVDOMATIC_WINDOWS
backtrace_file /= g_get_user_config_dir ();
@@ -273,6 +286,7 @@ dvdomatic_setup ()
avfilter_register_all ();
Format::setup_formats ();
+ Container::setup_containers ();
DCPContentType::setup_dcp_content_types ();
Scaler::setup_scalers ();
Filter::setup_filters ();
@@ -281,7 +295,7 @@ dvdomatic_setup ()
ui_thread = boost::this_thread::get_id ();
}
-#ifdef DVDOMATIC_WINDOWS
+#ifdef DCPOMATIC_WINDOWS
boost::filesystem::path
mo_path ()
{
@@ -296,9 +310,9 @@ mo_path ()
#endif
void
-dvdomatic_setup_gettext_i18n (string lang)
+dcpomatic_setup_gettext_i18n (string lang)
{
-#ifdef DVDOMATIC_POSIX
+#ifdef DCPOMATIC_POSIX
lang += ".UTF8";
#endif
@@ -314,15 +328,15 @@ dvdomatic_setup_gettext_i18n (string lang)
}
setlocale (LC_ALL, "");
- textdomain ("libdvdomatic");
+ textdomain ("libdcpomatic");
-#ifdef DVDOMATIC_WINDOWS
- bindtextdomain ("libdvdomatic", mo_path().string().c_str());
- bind_textdomain_codeset ("libdvdomatic", "UTF8");
+#ifdef DCPOMATIC_WINDOWS
+ bindtextdomain ("libdcpomatic", mo_path().string().c_str());
+ bind_textdomain_codeset ("libdcpomatic", "UTF8");
#endif
-#ifdef DVDOMATIC_POSIX
- bindtextdomain ("libdvdomatic", POSIX_LOCALE_PREFIX);
+#ifdef DCPOMATIC_POSIX
+ bindtextdomain ("libdcpomatic", POSIX_LOCALE_PREFIX);
#endif
}
@@ -383,11 +397,11 @@ md5_digest (void const * data, int size)
* @return MD5 digest of file's contents.
*/
string
-md5_digest (string file)
+md5_digest (boost::filesystem::path file)
{
- ifstream f (file.c_str(), std::ios::binary);
+ ifstream f (file.string().c_str(), std::ios::binary);
if (!f.good ()) {
- throw OpenFileError (file);
+ throw OpenFileError (file.string());
}
f.seekg (0, std::ios::end);
@@ -444,66 +458,11 @@ about_equal (float a, float b)
return (fabs (a - b) < 1e-4);
}
-class FrameRateCandidate
-{
-public:
- FrameRateCandidate (float source_, int dcp_)
- : source (source_)
- , dcp (dcp_)
- {}
-
- float source;
- int dcp;
-};
-
-int
-best_dcp_frame_rate (float source_fps)
-{
- list<int> const allowed_dcp_frame_rates = Config::instance()->allowed_dcp_frame_rates ();
-
- /* Work out what rates we could manage, including those achieved by using skip / repeat. */
- list<FrameRateCandidate> candidates;
-
- /* Start with the ones without skip / repeat so they will get matched in preference to skipped/repeated ones */
- for (list<int>::const_iterator i = allowed_dcp_frame_rates.begin(); i != allowed_dcp_frame_rates.end(); ++i) {
- candidates.push_back (FrameRateCandidate (*i, *i));
- }
-
- /* Then the skip/repeat ones */
- for (list<int>::const_iterator i = allowed_dcp_frame_rates.begin(); i != allowed_dcp_frame_rates.end(); ++i) {
- candidates.push_back (FrameRateCandidate (float (*i) / 2, *i));
- candidates.push_back (FrameRateCandidate (float (*i) * 2, *i));
- }
-
- /* Pick the best one, bailing early if we hit an exact match */
- float error = std::numeric_limits<float>::max ();
- optional<FrameRateCandidate> best;
- list<FrameRateCandidate>::iterator i = candidates.begin();
- while (i != candidates.end()) {
-
- if (about_equal (i->source, source_fps)) {
- best = *i;
- break;
- }
-
- float const e = fabs (i->source - source_fps);
- if (e < error) {
- error = e;
- best = *i;
- }
-
- ++i;
- }
-
- assert (best);
- return best->dcp;
-}
-
-/** @param An arbitrary sampling rate.
- * @return The appropriate DCP-approved sampling rate (48kHz or 96kHz).
+/** @param An arbitrary audio frame rate.
+ * @return The appropriate DCP-approved frame rate (48kHz or 96kHz).
*/
int
-dcp_audio_sample_rate (int fs)
+dcp_audio_frame_rate (int fs)
{
if (fs <= 48000) {
return 48000;
@@ -512,16 +471,6 @@ dcp_audio_sample_rate (int fs)
return 96000;
}
-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);
-}
-
-bool operator!= (Crop const & a, Crop const & b)
-{
- return !(a == b);
-}
-
/** @param index Colour LUT index.
* @return Human-readable name.
*/
@@ -634,22 +583,6 @@ Socket::read_uint32 ()
return ntohl (v);
}
-/** @param other A Rect.
- * @return The intersection of this with `other'.
- */
-Rect
-Rect::intersection (Rect const & other) const
-{
- int const tx = max (x, other.x);
- int const ty = max (y, other.y);
-
- return Rect (
- tx, ty,
- min (x + width, other.x + other.width) - tx,
- min (y + height, other.y + other.height) - ty
- );
-}
-
/** Round a number up to the nearest multiple of another number.
* @param c Index.
* @param s Array of numbers to round, indexed by c.
@@ -766,151 +699,6 @@ get_optional_int (multimap<string, string> const & kv, string k)
return lexical_cast<int> (i->second);
}
-/** Construct an AudioBuffers. Audio data is undefined after this constructor.
- * @param channels Number of channels.
- * @param frames Number of frames to reserve space for.
- */
-AudioBuffers::AudioBuffers (int channels, int frames)
- : _channels (channels)
- , _frames (frames)
- , _allocated_frames (frames)
-{
- _data = new float*[_channels];
- for (int i = 0; i < _channels; ++i) {
- _data[i] = new float[frames];
- }
-}
-
-/** Copy constructor.
- * @param other Other AudioBuffers; data is copied.
- */
-AudioBuffers::AudioBuffers (AudioBuffers const & other)
- : _channels (other._channels)
- , _frames (other._frames)
- , _allocated_frames (other._frames)
-{
- _data = new float*[_channels];
- for (int i = 0; i < _channels; ++i) {
- _data[i] = new float[_frames];
- memcpy (_data[i], other._data[i], _frames * sizeof (float));
- }
-}
-
-/* XXX: it's a shame that this is a copy-and-paste of the above;
- probably fixable with c++0x.
-*/
-AudioBuffers::AudioBuffers (boost::shared_ptr<const AudioBuffers> other)
- : _channels (other->_channels)
- , _frames (other->_frames)
- , _allocated_frames (other->_frames)
-{
- _data = new float*[_channels];
- for (int i = 0; i < _channels; ++i) {
- _data[i] = new float[_frames];
- memcpy (_data[i], other->_data[i], _frames * sizeof (float));
- }
-}
-
-/** AudioBuffers destructor */
-AudioBuffers::~AudioBuffers ()
-{
- for (int i = 0; i < _channels; ++i) {
- delete[] _data[i];
- }
-
- delete[] _data;
-}
-
-/** @param c Channel index.
- * @return Buffer for this channel.
- */
-float*
-AudioBuffers::data (int c) const
-{
- assert (c >= 0 && c < _channels);
- return _data[c];
-}
-
-/** Set the number of frames that these AudioBuffers will report themselves
- * as having.
- * @param f Frames; must be less than or equal to the number of allocated frames.
- */
-void
-AudioBuffers::set_frames (int f)
-{
- assert (f <= _allocated_frames);
- _frames = f;
-}
-
-/** Make all samples on all channels silent */
-void
-AudioBuffers::make_silent ()
-{
- for (int i = 0; i < _channels; ++i) {
- make_silent (i);
- }
-}
-
-/** Make all samples on a given channel silent.
- * @param c Channel.
- */
-void
-AudioBuffers::make_silent (int c)
-{
- assert (c >= 0 && c < _channels);
-
- for (int i = 0; i < _frames; ++i) {
- _data[c][i] = 0;
- }
-}
-
-/** Copy data from another AudioBuffers to this one. All channels are copied.
- * @param from AudioBuffers to copy from; must have the same number of channels as this.
- * @param frames_to_copy Number of frames to copy.
- * @param read_offset Offset to read from in `from'.
- * @param write_offset Offset to write to in `to'.
- */
-void
-AudioBuffers::copy_from (AudioBuffers* from, int frames_to_copy, int read_offset, int write_offset)
-{
- assert (from->channels() == channels());
-
- assert (from);
- assert (read_offset >= 0 && (read_offset + frames_to_copy) <= from->_allocated_frames);
- assert (write_offset >= 0 && (write_offset + frames_to_copy) <= _allocated_frames);
-
- for (int i = 0; i < _channels; ++i) {
- memcpy (_data[i] + write_offset, from->_data[i] + read_offset, frames_to_copy * sizeof(float));
- }
-}
-
-/** Move audio data around.
- * @param from Offset to move from.
- * @param to Offset to move to.
- * @param frames Number of frames to move.
- */
-
-void
-AudioBuffers::move (int from, int to, int frames)
-{
- if (frames == 0) {
- return;
- }
-
- assert (from >= 0);
- assert (from < _frames);
- assert (to >= 0);
- assert (to < _frames);
- assert (frames > 0);
- assert (frames <= _frames);
- assert ((from + frames) <= _frames);
- assert ((to + frames) <= _frames);
-
- for (int i = 0; i < _channels; ++i) {
- memmove (_data[i] + to, _data[i] + from, frames * sizeof(float));
- }
-}
-
/** Trip an assert if the caller is not in the UI thread */
void
ensure_ui_thread ()
@@ -918,30 +706,17 @@ ensure_ui_thread ()
assert (boost::this_thread::get_id() == ui_thread);
}
-/** @param v Source video frame.
+/** @param v Content video frame.
* @param audio_sample_rate Source audio sample rate.
* @param frames_per_second Number of video frames per second.
* @return Equivalent number of audio frames for `v'.
*/
int64_t
-video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float frames_per_second)
+video_frames_to_audio_frames (ContentVideoFrame v, float audio_sample_rate, float frames_per_second)
{
return ((int64_t) v * audio_sample_rate / frames_per_second);
}
-/** @param f Filename.
- * @return true if this file is a still image, false if it is something else.
- */
-bool
-still_image_file (string f)
-{
- string ext = boost::filesystem::path(f).extension().string();
-
- transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
-
- return (ext == N_(".tif") || ext == N_(".tiff") || ext == N_(".jpg") || ext == N_(".jpeg") || ext == N_(".png") || ext == N_(".bmp"));
-}
-
/** @return A pair containing CPU model name and the number of processors */
pair<string, int>
cpu_info ()
@@ -949,7 +724,7 @@ cpu_info ()
pair<string, int> info;
info.second = 0;
-#ifdef DVDOMATIC_POSIX
+#ifdef DCPOMATIC_POSIX
ifstream f (N_("/proc/cpuinfo"));
while (f.good ()) {
string l;
@@ -988,58 +763,6 @@ audio_channel_name (int c)
return channels[c];
}
-AudioMapping::AudioMapping (int c)
- : _source_channels (c)
-{
-
-}
-
-optional<libdcp::Channel>
-AudioMapping::source_to_dcp (int c) const
-{
- if (c >= _source_channels) {
- return optional<libdcp::Channel> ();
- }
-
- if (_source_channels == 1) {
- /* mono sources to centre */
- return libdcp::CENTRE;
- }
-
- return static_cast<libdcp::Channel> (c);
-}
-
-optional<int>
-AudioMapping::dcp_to_source (libdcp::Channel c) const
-{
- if (_source_channels == 1) {
- if (c == libdcp::CENTRE) {
- return 0;
- } else {
- return optional<int> ();
- }
- }
-
- if (static_cast<int> (c) >= _source_channels) {
- return optional<int> ();
- }
-
- return static_cast<int> (c);
-}
-
-int
-AudioMapping::dcp_channels () const
-{
- if (_source_channels == 1) {
- /* The source is mono, so to put the mono channel into
- the centre we need to generate a 5.1 soundtrack.
- */
- return 6;
- }
-
- return _source_channels;
-}
-
FrameRateConversion::FrameRateConversion (float source, int dcp)
: skip (false)
, repeat (false)
diff --git a/src/lib/util.h b/src/lib/util.h
index d0c350a56..65859309d 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -22,8 +22,8 @@
* @brief Some utility functions and classes.
*/
-#ifndef DVDOMATIC_UTIL_H
-#define DVDOMATIC_UTIL_H
+#ifndef DCPOMATIC_UTIL_H
+#define DCPOMATIC_UTIL_H
#include <string>
#include <vector>
@@ -37,8 +37,9 @@ extern "C" {
#include <libavfilter/avfilter.h>
}
#include "compose.hpp"
+#include "types.h"
-#ifdef DVDOMATIC_DEBUG
+#ifdef DCPOMATIC_DEBUG
#define TIMING(...) _film->log()->microsecond_log (String::compose (__VA_ARGS__), Log::TIMING);
#else
#define TIMING(...)
@@ -50,23 +51,22 @@ extern "C" {
class Scaler;
extern std::string seconds_to_hms (int);
+extern std::string time_to_hms (Time);
extern std::string seconds_to_approximate_hms (int);
extern void stacktrace (std::ostream &, int);
extern std::string dependency_version_summary ();
extern double seconds (struct timeval);
-extern void dvdomatic_setup ();
-extern void dvdomatic_setup_gettext_i18n (std::string);
+extern void dcpomatic_setup ();
+extern void dcpomatic_setup_gettext_i18n (std::string);
extern std::vector<std::string> split_at_spaces_considering_quotes (std::string);
-extern std::string md5_digest (std::string);
+extern std::string md5_digest (boost::filesystem::path);
extern std::string md5_digest (void const *, int);
extern void ensure_ui_thread ();
extern std::string audio_channel_name (int);
-#ifdef DVDOMATIC_WINDOWS
+#ifdef DCPOMATIC_WINDOWS
extern boost::filesystem::path mo_path ();
#endif
-typedef int SourceFrame;
-
struct FrameRateConversion
{
FrameRateConversion (float, int);
@@ -102,91 +102,8 @@ struct FrameRateConversion
std::string description;
};
-int best_dcp_frame_rate (float);
-
-enum ContentType {
- STILL, ///< content is still images
- VIDEO ///< content is a video
-};
-
-/** @struct Crop
- * @brief A description of the crop of an image or video.
- */
-struct Crop
-{
- Crop () : left (0), right (0), top (0), bottom (0) {}
-
- /** Number of pixels to remove from the left-hand side */
- int left;
- /** Number of pixels to remove from the right-hand side */
- int right;
- /** Number of pixels to remove from the top */
- int top;
- /** Number of pixels to remove from the bottom */
- int bottom;
-};
-
-extern bool operator== (Crop const & a, Crop const & b);
-extern bool operator!= (Crop const & a, Crop const & b);
-
-/** @struct Position
- * @brief A position.
- */
-struct Position
-{
- Position ()
- : x (0)
- , y (0)
- {}
-
- Position (int x_, int y_)
- : x (x_)
- , y (y_)
- {}
-
- /** x coordinate */
- int x;
- /** y coordinate */
- int y;
-};
-
-/** @struct Rect
- * @brief A rectangle.
- */
-struct Rect
-{
- Rect ()
- : x (0)
- , y (0)
- , width (0)
- , height (0)
- {}
-
- Rect (int x_, int y_, int w_, int h_)
- : x (x_)
- , y (y_)
- , width (w_)
- , height (h_)
- {}
-
- int x;
- int y;
- int width;
- int height;
-
- Position position () const {
- return Position (x, y);
- }
-
- libdcp::Size size () const {
- return libdcp::Size (width, height);
- }
-
- Rect intersection (Rect const & other) const;
-};
-
extern std::string crop_string (Position, libdcp::Size);
-extern int dcp_audio_sample_rate (int);
+extern int dcp_audio_frame_rate (int);
extern std::string colour_lut_index_to_name (int index);
extern int stride_round_up (int, int const *, int);
extern int stride_lookup (int c, int const * stride);
@@ -199,7 +116,7 @@ extern std::string get_optional_string (std::multimap<std::string, std::string>
/** @class Socket
* @brief A class to wrap a boost::asio::ip::tcp::socket with some things
- * that are useful for DVD-o-matic.
+ * that are useful for DCP-o-matic.
*
* This class wraps some things that I could not work out how to do with boost;
* most notably, sync read/write calls with timeouts.
@@ -233,65 +150,7 @@ private:
int _timeout;
};
-/** @class AudioBuffers
- * @brief A class to hold multi-channel audio data in float format.
- */
-class AudioBuffers
-{
-public:
- AudioBuffers (int channels, int frames);
- AudioBuffers (AudioBuffers const &);
- AudioBuffers (boost::shared_ptr<const AudioBuffers>);
- ~AudioBuffers ();
-
- float** data () const {
- return _data;
- }
-
- float* data (int) const;
-
- int channels () const {
- return _channels;
- }
-
- int frames () const {
- return _frames;
- }
-
- void set_frames (int f);
-
- void make_silent ();
- void make_silent (int c);
-
- void copy_from (AudioBuffers* from, int frames_to_copy, int read_offset, int write_offset);
- void move (int from, int to, int frames);
-
-private:
- /** Number of channels */
- int _channels;
- /** Number of frames (where a frame is one sample across all channels) */
- int _frames;
- /** Number of frames that _data can hold */
- int _allocated_frames;
- /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
- float** _data;
-};
-
-class AudioMapping
-{
-public:
- AudioMapping (int);
-
- boost::optional<libdcp::Channel> source_to_dcp (int c) const;
- boost::optional<int> dcp_to_source (libdcp::Channel c) const;
- int dcp_channels () const;
-
-private:
- int _source_channels;
-};
-
-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 int64_t video_frames_to_audio_frames (ContentVideoFrame v, float audio_sample_rate, float frames_per_second);
extern std::pair<std::string, int> cpu_info ();
class LocaleGuard
diff --git a/src/lib/version.h b/src/lib/version.h
index 71639e3bc..518862fc4 100644
--- a/src/lib/version.h
+++ b/src/lib/version.h
@@ -1,3 +1,3 @@
-extern char const * dvdomatic_version;
-extern char const * dvdomatic_git_commit;
+extern char const * dcpomatic_version;
+extern char const * dcpomatic_git_commit;
diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc
new file mode 100644
index 000000000..2e413678f
--- /dev/null
+++ b/src/lib/video_content.cc
@@ -0,0 +1,194 @@
+/*
+ Copyright (C) 2013 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 <libcxml/cxml.h>
+#include "video_content.h"
+#include "video_decoder.h"
+
+#include "i18n.h"
+
+int const VideoContentProperty::VIDEO_LENGTH = 0;
+int const VideoContentProperty::VIDEO_SIZE = 1;
+int const VideoContentProperty::VIDEO_FRAME_RATE = 2;
+int const VideoContentProperty::VIDEO_CROP = 3;
+
+using std::string;
+using std::stringstream;
+using std::setprecision;
+using boost::shared_ptr;
+using boost::lexical_cast;
+
+VideoContent::VideoContent (shared_ptr<const Film> f, Time s, ContentVideoFrame len)
+ : Content (f, s)
+ , _video_length (len)
+{
+
+}
+
+VideoContent::VideoContent (shared_ptr<const Film> f, boost::filesystem::path p)
+ : Content (f, p)
+ , _video_length (0)
+{
+
+}
+
+VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
+ : Content (f, node)
+{
+ _video_length = node->number_child<ContentVideoFrame> ("VideoLength");
+ _video_size.width = node->number_child<int> ("VideoWidth");
+ _video_size.height = node->number_child<int> ("VideoHeight");
+ _video_frame_rate = node->number_child<float> ("VideoFrameRate");
+ _crop.left = node->number_child<int> ("LeftCrop");
+ _crop.right = node->number_child<int> ("RightCrop");
+ _crop.top = node->number_child<int> ("TopCrop");
+ _crop.bottom = node->number_child<int> ("BottomCrop");
+}
+
+VideoContent::VideoContent (VideoContent const & o)
+ : Content (o)
+ , _video_length (o._video_length)
+ , _video_size (o._video_size)
+ , _video_frame_rate (o._video_frame_rate)
+{
+
+}
+
+void
+VideoContent::as_xml (xmlpp::Node* node) const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
+ node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
+ node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
+ node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
+ node->add_child("LeftCrop")->add_child_text (boost::lexical_cast<string> (_crop.left));
+ node->add_child("RightCrop")->add_child_text (boost::lexical_cast<string> (_crop.right));
+ node->add_child("TopCrop")->add_child_text (boost::lexical_cast<string> (_crop.top));
+ node->add_child("BottomCrop")->add_child_text (boost::lexical_cast<string> (_crop.bottom));
+}
+
+void
+VideoContent::take_from_video_decoder (shared_ptr<VideoDecoder> d)
+{
+ /* These decoder calls could call other content methods which take a lock on the mutex */
+ libdcp::Size const vs = d->video_size ();
+ float const vfr = d->video_frame_rate ();
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _video_size = vs;
+ _video_frame_rate = vfr;
+ }
+
+ signal_changed (VideoContentProperty::VIDEO_SIZE);
+ signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
+}
+
+
+string
+VideoContent::information () const
+{
+ if (video_size().width == 0 || video_size().height == 0) {
+ return "";
+ }
+
+ stringstream s;
+
+ s << String::compose (
+ _("%1x%2 pixels (%3:1)"),
+ video_size().width,
+ video_size().height,
+ setprecision (3), float (video_size().width) / video_size().height
+ );
+
+ return s.str ();
+}
+
+void
+VideoContent::set_crop (Crop c)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _crop = c;
+ }
+ signal_changed (VideoContentProperty::VIDEO_CROP);
+}
+
+void
+VideoContent::set_left_crop (int c)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (_crop.left == c) {
+ return;
+ }
+
+ _crop.left = c;
+ }
+
+ signal_changed (VideoContentProperty::VIDEO_CROP);
+}
+
+void
+VideoContent::set_right_crop (int c)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ if (_crop.right == c) {
+ return;
+ }
+
+ _crop.right = c;
+ }
+
+ signal_changed (VideoContentProperty::VIDEO_CROP);
+}
+
+void
+VideoContent::set_top_crop (int c)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ if (_crop.top == c) {
+ return;
+ }
+
+ _crop.top = c;
+ }
+
+ signal_changed (VideoContentProperty::VIDEO_CROP);
+}
+
+void
+VideoContent::set_bottom_crop (int c)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ if (_crop.bottom == c) {
+ return;
+ }
+
+ _crop.bottom = c;
+ }
+
+ signal_changed (VideoContentProperty::VIDEO_CROP);
+}
+
diff --git a/src/lib/video_content.h b/src/lib/video_content.h
new file mode 100644
index 000000000..7dde927af
--- /dev/null
+++ b/src/lib/video_content.h
@@ -0,0 +1,85 @@
+/*
+ Copyright (C) 2013 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_VIDEO_CONTENT_H
+#define DCPOMATIC_VIDEO_CONTENT_H
+
+#include "content.h"
+#include "util.h"
+
+class VideoDecoder;
+
+class VideoContentProperty
+{
+public:
+ static int const VIDEO_LENGTH;
+ static int const VIDEO_SIZE;
+ static int const VIDEO_FRAME_RATE;
+ static int const VIDEO_CROP;
+};
+
+class VideoContent : public virtual Content
+{
+public:
+ VideoContent (boost::shared_ptr<const Film>, Time, ContentVideoFrame);
+ VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
+ VideoContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+ VideoContent (VideoContent const &);
+
+ void as_xml (xmlpp::Node *) const;
+ virtual std::string information () const;
+
+ ContentVideoFrame video_length () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _video_length;
+ }
+
+ libdcp::Size video_size () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _video_size;
+ }
+
+ float video_frame_rate () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _video_frame_rate;
+ }
+
+ void set_crop (Crop);
+ void set_left_crop (int);
+ void set_right_crop (int);
+ void set_top_crop (int);
+ void set_bottom_crop (int);
+
+ Crop crop () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _crop;
+ }
+
+protected:
+ void take_from_video_decoder (boost::shared_ptr<VideoDecoder>);
+
+ ContentVideoFrame _video_length;
+
+private:
+ libdcp::Size _video_size;
+ float _video_frame_rate;
+ Crop _crop;
+};
+
+#endif
diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc
index 16a076698..609594e76 100644
--- a/src/lib/video_decoder.cc
+++ b/src/lib/video_decoder.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
@@ -21,74 +23,66 @@
#include "subtitle.h"
#include "film.h"
#include "image.h"
-#include "log.h"
-#include "options.h"
-#include "job.h"
#include "i18n.h"
using std::cout;
using boost::shared_ptr;
-using boost::optional;
-VideoDecoder::VideoDecoder (shared_ptr<Film> f, DecodeOptions o)
- : Decoder (f, o)
- , _video_frame (0)
- , _last_source_time (0)
+VideoDecoder::VideoDecoder (shared_ptr<const Film> f, shared_ptr<const VideoContent> c)
+ : Decoder (f)
+ , _next_video (0)
+ , _video_content (c)
+ , _frame_rate_conversion (c->video_frame_rate(), f->dcp_video_frame_rate())
+ , _odd (false)
{
}
-/** Called by subclasses to tell the world that some video data is ready.
- * We find a subtitle then emit it for listeners.
+/** Called by subclasses when some video is ready.
* @param image frame to emit.
- * @param t Time of the frame within the source, in seconds.
+ * @param same true if this frame is the same as the last one passed to this call.
+ * @param t Time of the frame within the source.
*/
void
-VideoDecoder::emit_video (shared_ptr<Image> image, bool same, double t)
+VideoDecoder::video (shared_ptr<Image> image, bool same, Time t)
{
+ if (_frame_rate_conversion.skip && _odd) {
+ _odd = !_odd;
+ return;
+ }
+
shared_ptr<Subtitle> sub;
if (_timed_subtitle && _timed_subtitle->displayed_at (t)) {
sub = _timed_subtitle->subtitle ();
}
Video (image, same, sub, t);
- ++_video_frame;
-
- _last_source_time = t;
+
+ shared_ptr<const Film> film = _film.lock ();
+ assert (film);
+
+ if (_frame_rate_conversion.repeat) {
+ Video (image, true, sub, t + film->video_frames_to_time (1));
+ _next_video = t + film->video_frames_to_time (2);
+ } else {
+ _next_video = t + film->video_frames_to_time (1);
+ }
+
+ _odd = !_odd;
}
-/** Set up the current subtitle. This will be put onto frames that
- * fit within its time specification. s may be 0 to say that there
- * is no current subtitle.
+/** Called by subclasses when a subtitle is ready.
+ * s may be 0 to say that there is no current subtitle.
* @param s New current subtitle, or 0.
*/
void
-VideoDecoder::emit_subtitle (shared_ptr<TimedSubtitle> s)
+VideoDecoder::subtitle (shared_ptr<TimedSubtitle> s)
{
_timed_subtitle = s;
if (_timed_subtitle) {
Position const p = _timed_subtitle->subtitle()->position ();
- _timed_subtitle->subtitle()->set_position (Position (p.x - _film->crop().left, p.y - _film->crop().top));
- }
-}
-
-/** Set which stream of subtitles we should use from our source.
- * @param s Stream to use.
- */
-void
-VideoDecoder::set_subtitle_stream (shared_ptr<SubtitleStream> s)
-{
- _subtitle_stream = s;
-}
-
-void
-VideoDecoder::set_progress (Job* j) const
-{
- assert (j);
-
- if (_film->length()) {
- j->set_progress (float (_video_frame) / _film->length().get());
+ _timed_subtitle->subtitle()->set_position (Position (p.x - _video_content->crop().left, p.y - _video_content->crop().top));
}
}
diff --git a/src/lib/video_decoder.h b/src/lib/video_decoder.h
index 6e4fd48c0..b31766b50 100644
--- a/src/lib/video_decoder.h
+++ b/src/lib/video_decoder.h
@@ -17,67 +17,41 @@
*/
-#ifndef DVDOMATIC_VIDEO_DECODER_H
-#define DVDOMATIC_VIDEO_DECODER_H
+#ifndef DCPOMATIC_VIDEO_DECODER_H
+#define DCPOMATIC_VIDEO_DECODER_H
#include "video_source.h"
-#include "stream.h"
#include "decoder.h"
+#include "util.h"
-class VideoDecoder : public TimedVideoSource, public virtual Decoder
+class VideoContent;
+
+class VideoDecoder : public VideoSource, public virtual Decoder
{
public:
- VideoDecoder (boost::shared_ptr<Film>, DecodeOptions);
-
- /** @return video frames per second, or 0 if unknown */
- virtual float frames_per_second () const = 0;
- /** @return native size in pixels */
- virtual libdcp::Size native_size () const = 0;
- /** @return length (in source video frames), according to our content's header */
- virtual SourceFrame length () const = 0;
-
- virtual int time_base_numerator () const = 0;
- virtual int time_base_denominator () const = 0;
- virtual int sample_aspect_ratio_numerator () const = 0;
- virtual int sample_aspect_ratio_denominator () const = 0;
+ VideoDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const VideoContent>);
- virtual void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
-
- void set_progress (Job *) const;
-
- int video_frame () const {
- return _video_frame;
- }
+ /* Calls for VideoContent to find out about itself */
- boost::shared_ptr<SubtitleStream> subtitle_stream () const {
- return _subtitle_stream;
- }
-
- std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
- return _subtitle_streams;
- }
-
- double last_source_time () const {
- return _last_source_time;
- }
+ /** @return video frame rate second, or 0 if unknown */
+ virtual float video_frame_rate () const = 0;
+ /** @return video size in pixels */
+ virtual libdcp::Size video_size () const = 0;
+ /** @return length according to our content's header */
+ virtual ContentVideoFrame video_length () const = 0;
protected:
- virtual PixelFormat pixel_format () const = 0;
+ void video (boost::shared_ptr<Image>, bool, Time);
+ void subtitle (boost::shared_ptr<TimedSubtitle>);
- void emit_video (boost::shared_ptr<Image>, bool, double);
- void emit_subtitle (boost::shared_ptr<TimedSubtitle>);
-
- /** Subtitle stream to use when decoding */
- boost::shared_ptr<SubtitleStream> _subtitle_stream;
- /** Subtitle streams that this decoder's content has */
- std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
+ Time _next_video;
+ boost::shared_ptr<const VideoContent> _video_content;
private:
- int _video_frame;
- double _last_source_time;
-
boost::shared_ptr<TimedSubtitle> _timed_subtitle;
+ FrameRateConversion _frame_rate_conversion;
+ bool _odd;
};
#endif
diff --git a/src/lib/video_sink.h b/src/lib/video_sink.h
index 0170c7350..2da42528c 100644
--- a/src/lib/video_sink.h
+++ b/src/lib/video_sink.h
@@ -17,8 +17,8 @@
*/
-#ifndef DVDOMATIC_VIDEO_SINK_H
-#define DVDOMATIC_VIDEO_SINK_H
+#ifndef DCPOMATIC_VIDEO_SINK_H
+#define DCPOMATIC_VIDEO_SINK_H
#include <boost/shared_ptr.hpp>
#include "util.h"
@@ -34,19 +34,7 @@ public:
* @param same true if i is the same as last time we were called.
* @param s A subtitle that should be on this frame, or 0.
*/
- virtual void process_video (boost::shared_ptr<const Image> i, bool same, boost::shared_ptr<Subtitle> s) = 0;
-};
-
-class TimedVideoSink
-{
-public:
- /** Call with a frame of video.
- * @param i Video frame image.
- * @param same true if i is the same as last time we were called.
- * @param s A subtitle that should be on this frame, or 0.
- * @param t Source timestamp.
- */
- virtual void process_video (boost::shared_ptr<const Image> i, bool same, boost::shared_ptr<Subtitle> s, double t) = 0;
+ virtual void process_video (boost::shared_ptr<const Image> i, bool same, boost::shared_ptr<Subtitle> s, Time) = 0;
};
#endif
diff --git a/src/lib/video_source.cc b/src/lib/video_source.cc
index 539243402..39043c860 100644
--- a/src/lib/video_source.cc
+++ b/src/lib/video_source.cc
@@ -21,24 +21,24 @@
#include "video_sink.h"
using boost::shared_ptr;
+using boost::weak_ptr;
using boost::bind;
-void
-VideoSource::connect_video (shared_ptr<VideoSink> s)
+static void
+process_video_proxy (weak_ptr<VideoSink> sink, shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub, Time time)
{
- Video.connect (bind (&VideoSink::process_video, s, _1, _2, _3));
+ shared_ptr<VideoSink> p = sink.lock ();
+ if (p) {
+ p->process_video (image, same, sub, time);
+ }
}
void
-TimedVideoSource::connect_video (shared_ptr<TimedVideoSink> s)
-{
- Video.connect (bind (&TimedVideoSink::process_video, s, _1, _2, _3, _4));
-}
-
-void
-TimedVideoSource::connect_video (shared_ptr<VideoSink> s)
+VideoSource::connect_video (shared_ptr<VideoSink> s)
{
- Video.connect (bind (&VideoSink::process_video, s, _1, _2, _3));
+ /* If we bind, say, a Player (as the VideoSink) to a Decoder (which is owned
+ by the Player) we create a cycle. Use a weak_ptr to break it.
+ */
+ Video.connect (bind (process_video_proxy, weak_ptr<VideoSink> (s), _1, _2, _3, _4));
}
-
diff --git a/src/lib/video_source.h b/src/lib/video_source.h
index 748cb6fe9..c94b5a20a 100644
--- a/src/lib/video_source.h
+++ b/src/lib/video_source.h
@@ -21,20 +21,19 @@
* @brief Parent class for classes which emit video data.
*/
-#ifndef DVDOMATIC_VIDEO_SOURCE_H
-#define DVDOMATIC_VIDEO_SOURCE_H
+#ifndef DCPOMATIC_VIDEO_SOURCE_H
+#define DCPOMATIC_VIDEO_SOURCE_H
#include <boost/shared_ptr.hpp>
#include <boost/signals2.hpp>
#include "util.h"
class VideoSink;
-class TimedVideoSink;
class Subtitle;
class Image;
/** @class VideoSource
- * @param A class that emits video data without timestamps.
+ * @param A class that emits video data.
*/
class VideoSource
{
@@ -44,29 +43,11 @@ public:
* First parameter is the video image.
* Second parameter is true if the image is the same as the last one that was emitted.
* Third parameter is either 0 or a subtitle that should be on this frame.
+ * Fourth parameter is the time relative to the start of this source's content.
*/
- boost::signals2::signal<void (boost::shared_ptr<const Image>, bool, boost::shared_ptr<Subtitle>)> Video;
+ boost::signals2::signal<void (boost::shared_ptr<const Image>, bool, boost::shared_ptr<Subtitle>, Time)> Video;
void connect_video (boost::shared_ptr<VideoSink>);
};
-/** @class TimedVideoSource
- * @param A class that emits video data with timestamps.
- */
-class TimedVideoSource
-{
-public:
-
- /** Emitted when a video frame is ready.
- * First parameter is the video image.
- * Second parameter is true if the image is the same as the last one that was emitted.
- * Third parameter is either 0 or a subtitle that should be on this frame.
- * Fourth parameter is the source timestamp of this frame.
- */
- boost::signals2::signal<void (boost::shared_ptr<const Image>, bool, boost::shared_ptr<Subtitle>, double)> Video;
-
- void connect_video (boost::shared_ptr<VideoSink>);
- void connect_video (boost::shared_ptr<TimedVideoSink>);
-};
-
#endif
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 177e929ae..39b9b9304 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -22,14 +22,19 @@
#include <libdcp/sound_asset.h>
#include <libdcp/picture_frame.h>
#include <libdcp/reel.h>
+#include <libdcp/dcp.h>
#include <libdcp/cpl.h>
#include "writer.h"
#include "compose.hpp"
#include "film.h"
-#include "format.h"
+#include "container.h"
#include "log.h"
#include "dcp_video_frame.h"
+#include "dcp_content_type.h"
+#include "player.h"
+#include "audio_mapping.h"
#include "config.h"
+#include "job.h"
#include "i18n.h"
@@ -43,8 +48,9 @@ using boost::shared_ptr;
int const Writer::_maximum_frames_in_memory = 8;
-Writer::Writer (shared_ptr<Film> f)
+Writer::Writer (shared_ptr<Film> f, shared_ptr<Job> j)
: _film (f)
+ , _job (j)
, _first_nonexistant_frame (0)
, _thread (0)
, _finish (false)
@@ -69,28 +75,24 @@ Writer::Writer (shared_ptr<Film> f)
new libdcp::MonoPictureAsset (
_film->internal_video_mxf_dir (),
_film->internal_video_mxf_filename (),
- _film->dcp_frame_rate (),
- _film->format()->dcp_size ()
+ _film->dcp_video_frame_rate (),
+ _film->container()->dcp_size ()
)
);
_picture_asset_writer = _picture_asset->start_write (_first_nonexistant_frame > 0);
- AudioMapping m (_film->audio_channels ());
+ _sound_asset.reset (
+ new libdcp::SoundAsset (
+ _film->dir (_film->dcp_name()),
+ _film->dcp_audio_mxf_filename (),
+ _film->dcp_video_frame_rate (),
+ _film->dcp_audio_channels (),
+ _film->dcp_audio_frame_rate()
+ )
+ );
- if (m.dcp_channels() > 0) {
- _sound_asset.reset (
- new libdcp::SoundAsset (
- _film->dir (_film->dcp_name()),
- _film->dcp_audio_mxf_filename (),
- _film->dcp_frame_rate (),
- m.dcp_channels (),
- dcp_audio_sample_rate (_film->audio_stream()->sample_rate())
- )
- );
-
- _sound_asset_writer = _sound_asset->start_write ();
- }
+ _sound_asset_writer = _sound_asset->start_write ();
_thread = new boost::thread (boost::bind (&Writer::thread, this));
}
@@ -200,6 +202,10 @@ try
}
}
lock.lock ();
+
+ if (_film->length ()) {
+ _job->set_progress (float(_full_written + _fake_written + _repeat_written) / _film->time_to_video_frames (_film->length()));
+ }
++_last_written_frame;
}
@@ -255,21 +261,11 @@ Writer::finish ()
_thread = 0;
_picture_asset_writer->finalize ();
-
- if (_sound_asset_writer) {
- _sound_asset_writer->finalize ();
- }
-
+ _sound_asset_writer->finalize ();
+
int const frames = _last_written_frame + 1;
- int duration = 0;
- if (_film->trim_type() == Film::CPL) {
- duration = frames - _film->trim_start() - _film->trim_end();
- _picture_asset->set_entry_point (_film->trim_start ());
- } else {
- duration = frames;
- }
- _picture_asset->set_duration (duration);
+ _picture_asset->set_duration (frames);
/* Hard-link the video MXF into the DCP */
@@ -293,13 +289,7 @@ Writer::finish ()
_picture_asset->set_directory (_film->dir (_film->dcp_name ()));
_picture_asset->set_file_name (_film->dcp_video_mxf_filename ());
-
- if (_sound_asset) {
- if (_film->trim_type() == Film::CPL) {
- _sound_asset->set_entry_point (_film->trim_start ());
- }
- _sound_asset->set_duration (duration);
- }
+ _sound_asset->set_duration (frames);
libdcp::DCP dcp (_film->dir (_film->dcp_name()));
@@ -309,7 +299,7 @@ Writer::finish ()
_film->dcp_name(),
_film->dcp_content_type()->libdcp_kind (),
frames,
- _film->dcp_frame_rate ()
+ _film->dcp_video_frame_rate ()
)
);
diff --git a/src/lib/writer.h b/src/lib/writer.h
index beb16c7b9..62714edf3 100644
--- a/src/lib/writer.h
+++ b/src/lib/writer.h
@@ -26,6 +26,7 @@
class Film;
class EncodedData;
class AudioBuffers;
+class Job;
namespace libdcp {
class MonoPictureAsset;
@@ -63,7 +64,7 @@ bool operator== (QueueItem const & a, QueueItem const & b);
class Writer : public ExceptionStore
{
public:
- Writer (boost::shared_ptr<Film>);
+ Writer (boost::shared_ptr<Film>, boost::shared_ptr<Job>);
bool can_fake_write (int) const;
@@ -80,6 +81,7 @@ private:
/** our Film */
boost::shared_ptr<Film> _film;
+ boost::shared_ptr<Job> _job;
/** the first frame index that does not already exist in our MXF */
int _first_nonexistant_frame;
diff --git a/src/lib/wscript b/src/lib/wscript
index 66207b1e4..54941df42 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -6,47 +6,56 @@ sources = """
ab_transcoder.cc
analyse_audio_job.cc
audio_analysis.cc
+ audio_buffers.cc
+ audio_content.cc
audio_decoder.cc
+ audio_mapping.cc
audio_source.cc
+ black_decoder.cc
config.cc
combiner.cc
+ container.cc
+ content.cc
cross.cc
dci_metadata.cc
dcp_content_type.cc
dcp_video_frame.cc
decoder.cc
- decoder_factory.cc
- delay_line.cc
dolby_cp750.cc
encoder.cc
examine_content_job.cc
exceptions.cc
filter_graph.cc
+ ffmpeg_content.cc
ffmpeg_decoder.cc
film.cc
filter.cc
format.cc
- gain.cc
image.cc
+ imagemagick_content.cc
imagemagick_decoder.cc
job.cc
job_manager.cc
log.cc
lut.cc
- matcher.cc
+ null_content.cc
+ player.cc
+ playlist.cc
scp_dcp_job.cc
scaler.cc
server.cc
+ silence_decoder.cc
+ sndfile_content.cc
sndfile_decoder.cc
sound_processor.cc
- stream.cc
subtitle.cc
timer.cc
transcode_job.cc
transcoder.cc
- trimmer.cc
+ types.cc
ui_signaller.cc
util.cc
+ video_content.cc
video_decoder.cc
video_source.cc
writer.cc
@@ -58,12 +67,12 @@ def build(bld):
else:
obj = bld(features = 'cxx cxxshlib')
- obj.name = 'libdvdomatic'
+ obj.name = 'libdcpomatic'
obj.export_includes = ['.']
obj.uselib = """
AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE
BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2
- SNDFILE OPENJPEG POSTPROC TIFF MAGICK SSH DCP GLIB LZMA
+ SNDFILE OPENJPEG POSTPROC TIFF MAGICK SSH DCP CXML GLIB LZMA
"""
obj.source = sources + ' version.cc'
@@ -71,13 +80,15 @@ def build(bld):
if bld.env.TARGET_WINDOWS:
obj.uselib += ' WINSOCK2 BFD DBGHELP IBERTY'
obj.source += ' stack.cpp'
+ if bld.env.STATIC:
+ obj.uselib += ' XML++'
+ obj.source = sources + " version.cc"
+ obj.target = 'dcpomatic'
- obj.target = 'dvdomatic'
-
- i18n.po_to_mo(os.path.join('src', 'lib'), 'libdvdomatic', bld)
+ i18n.po_to_mo(os.path.join('src', 'lib'), 'libdcpomatic', bld)
def pot(bld):
- i18n.pot(os.path.join('src', 'lib'), sources, 'libdvdomatic')
+ i18n.pot(os.path.join('src', 'lib'), sources, 'libdcpomatic')
def pot_merge(bld):
- i18n.pot_merge(os.path.join('src', 'lib'), 'libdvdomatic')
+ i18n.pot_merge(os.path.join('src', 'lib'), 'libdcpomatic')