summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-08 23:23:07 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-08 23:23:07 +0100
commitf1fab174c7db85a1641bca2830ea75829982723f (patch)
tree80f64c7f5daf22f129b5e286487a704c6c069e14 /src/lib
parent2b4110534a7e3b2a2905c9f25226ba5c1ba4a167 (diff)
parent50e6acde52c7eaa3afa239bc14f08eced3787bd9 (diff)
Merge branch 'staging'
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/combiner.cc8
-rw-r--r--src/lib/encoder.cc19
-rw-r--r--src/lib/film.cc15
-rw-r--r--src/lib/film.h10
-rw-r--r--src/lib/transcoder.cc2
-rw-r--r--src/lib/util.cc20
-rw-r--r--src/lib/util.h6
-rw-r--r--src/lib/writer.cc2
8 files changed, 73 insertions, 9 deletions
diff --git a/src/lib/combiner.cc b/src/lib/combiner.cc
index 367cefa7f..f7d634832 100644
--- a/src/lib/combiner.cc
+++ b/src/lib/combiner.cc
@@ -45,6 +45,14 @@ Combiner::process_video (shared_ptr<const Image> image, bool, shared_ptr<Subtitl
void
Combiner::process_video_b (shared_ptr<const Image> image, bool, shared_ptr<Subtitle> sub, double t)
{
+ if (!_image) {
+ /* It's possible for filters in the A-side to mean that we get a B frame
+ before any A; just skip the B frame in that case. This at least prevents
+ a crash, but may not be right.
+ */
+ return;
+ }
+
/* Copy the right half of this image into our _image */
/* XXX: this should probably be in the Image class */
for (int i = 0; i < image->components(); ++i) {
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index 2c989452d..0ac32d3bf 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -47,6 +47,7 @@ using std::stringstream;
using std::vector;
using std::list;
using std::cout;
+using std::min;
using std::make_pair;
using namespace boost;
@@ -149,6 +150,20 @@ Encoder::process_end ()
}
#endif
+ if (_film->audio_channels() == 0 && _film->minimum_audio_channels() > 0) {
+ /* Put audio in where there is none at all */
+ int64_t af = video_frames_to_audio_frames (_video_frames_out, 48000, _film->dcp_frame_rate ());
+ while (af) {
+ int64_t const this_time = min (af, static_cast<int64_t> (24000));
+ shared_ptr<AudioBuffers> out (new AudioBuffers (_film->minimum_audio_channels(), this_time));
+ out->make_silent ();
+ out->set_frames (this_time);
+ write_audio (out);
+
+ af -= this_time;
+ }
+ }
+
boost::mutex::scoped_lock lock (_mutex);
_film->log()->log (String::compose (N_("Clearing queue of %1"), _queue.size ()));
@@ -433,10 +448,10 @@ Encoder::encoder_thread (ServerDescription* server)
void
Encoder::write_audio (shared_ptr<const AudioBuffers> data)
{
- AudioMapping m (_film->audio_channels ());
+ AudioMapping m (_film);
if (m.dcp_channels() != _film->audio_channels()) {
- /* Remap (currently just for mono -> 5.1) */
+ /* Remap and pad with silence */
shared_ptr<AudioBuffers> b (new AudioBuffers (m.dcp_channels(), data->frames ()));
for (int i = 0; i < m.dcp_channels(); ++i) {
diff --git a/src/lib/film.cc b/src/lib/film.cc
index d92d7a977..ce555ac8b 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -108,6 +108,7 @@ Film::Film (string d, bool must_exist)
, _j2k_bandwidth (200000000)
, _dci_metadata (Config::instance()->default_dci_metadata ())
, _dcp_frame_rate (0)
+ , _minimum_audio_channels (0)
, _source_frame_rate (0)
, _dirty (false)
{
@@ -185,6 +186,7 @@ Film::Film (Film const & o)
, _dci_metadata (o._dci_metadata)
, _dci_date (o._dci_date)
, _dcp_frame_rate (o._dcp_frame_rate)
+ , _minimum_audio_channels (o._minimum_audio_channels)
, _size (o._size)
, _length (o._length)
, _content_digest (o._content_digest)
@@ -506,6 +508,7 @@ Film::write_metadata () const
_dci_metadata.write (f);
f << "dci_date " << boost::gregorian::to_iso_string (_dci_date) << endl;
f << "dcp_frame_rate " << _dcp_frame_rate << endl;
+ f << "minimum_audio_channels " << _minimum_audio_channels << endl;
f << "width " << _size.width << endl;
f << "height " << _size.height << endl;
f << "length " << _length.get_value_or(0) << endl;
@@ -642,6 +645,8 @@ Film::read_metadata ()
_dci_date = boost::gregorian::from_undelimited_string (v);
} else if (k == "dcp_frame_rate") {
_dcp_frame_rate = atoi (v.c_str ());
+ } else if (k == "minimum_audio_channels") {
+ _minimum_audio_channels = atoi (v.c_str ());
}
_dci_metadata.read (k, v);
@@ -1324,6 +1329,16 @@ Film::set_dcp_frame_rate (int f)
}
void
+Film::set_minimum_audio_channels (int c)
+{
+ {
+ boost::mutex::scoped_lock lm (_state_mutex);
+ _minimum_audio_channels = c;
+ }
+ signal_changed (MINIMUM_AUDIO_CHANNELS);
+}
+
+void
Film::set_size (libdcp::Size s)
{
{
diff --git a/src/lib/film.h b/src/lib/film.h
index dd0a83d94..ca9bd57f4 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -153,7 +153,8 @@ public:
CONTENT_AUDIO_STREAMS,
SUBTITLE_STREAMS,
SOURCE_FRAME_RATE,
- DCP_FRAME_RATE
+ DCP_FRAME_RATE,
+ MINIMUM_AUDIO_CHANNELS
};
@@ -335,6 +336,11 @@ public:
return _source_frame_rate;
}
+ int minimum_audio_channels () const {
+ boost::mutex::scoped_lock lm (_state_mutex);
+ return _minimum_audio_channels;
+ }
+
boost::shared_ptr<AudioStream> audio_stream () const;
bool has_audio () const;
@@ -379,6 +385,7 @@ public:
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);
+ void set_minimum_audio_channels (int);
/** Emitted when some property has changed */
mutable boost::signals2::signal<void (Property)> Changed;
@@ -481,6 +488,7 @@ private:
boost::gregorian::date _dci_date;
/** Frames per second to run our DCP at */
int _dcp_frame_rate;
+ int _minimum_audio_channels;
/* Data which are cached to speed things up */
diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc
index 48cf402d7..a202d440c 100644
--- a/src/lib/transcoder.cc
+++ b/src/lib/transcoder.cc
@@ -73,7 +73,7 @@ Transcoder::Transcoder (shared_ptr<Film> f, DecodeOptions o, Job* j, shared_ptr<
/* 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 ());
+ _decoders.audio->set_audio_stream (f->audio_stream ());
}
_decoders.video->connect_video (_delay_line);
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 4cf57368a..83980f828 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -61,6 +61,7 @@ extern "C" {
#include "filter.h"
#include "sound_processor.h"
#include "config.h"
+#include "film.h"
#ifdef DVDOMATIC_WINDOWS
#include "stack.hpp"
#endif
@@ -962,8 +963,9 @@ audio_channel_name (int c)
return channels[c];
}
-AudioMapping::AudioMapping (int c)
- : _source_channels (c)
+AudioMapping::AudioMapping (shared_ptr<const Film> f)
+ : _source_channels (f->audio_stream() ? f->audio_stream()->channels() : 0)
+ , _minimum_channels (f->minimum_audio_channels ())
{
}
@@ -1001,8 +1003,11 @@ AudioMapping::dcp_to_source (libdcp::Channel c) const
return static_cast<int> (c);
}
+/** @return minimum number of DCP channels that we can allow in this
+ DCP, given the nature of the source.
+*/
int
-AudioMapping::dcp_channels () const
+AudioMapping::minimum_dcp_channels () const
{
if (_source_channels == 1) {
/* The source is mono, so to put the mono channel into
@@ -1014,6 +1019,15 @@ AudioMapping::dcp_channels () const
return _source_channels;
}
+/** @return number of channels that there should be in the DCP, including
+ * any silent padded ones.
+ */
+int
+AudioMapping::dcp_channels () const
+{
+ return max (_source_channels, _minimum_channels);
+}
+
FrameRateConversion::FrameRateConversion (float source, int dcp)
: skip (false)
, repeat (false)
diff --git a/src/lib/util.h b/src/lib/util.h
index 0d745e50c..c9e5bef16 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -50,6 +50,7 @@ extern "C" {
#define MAX_AUDIO_CHANNELS 6
class Scaler;
+class Film;
extern std::string seconds_to_hms (int);
extern std::string seconds_to_approximate_hms (int);
@@ -287,14 +288,17 @@ private:
class AudioMapping
{
public:
- AudioMapping (int);
+ AudioMapping (boost::shared_ptr<const Film>);
boost::optional<libdcp::Channel> source_to_dcp (int c) const;
boost::optional<int> dcp_to_source (libdcp::Channel c) const;
+
+ int minimum_dcp_channels () const;
int dcp_channels () const;
private:
int _source_channels;
+ int _minimum_channels;
};
extern int64_t video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float frames_per_second);
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 1a6daa1db..cff0b5be2 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -77,7 +77,7 @@ Writer::Writer (shared_ptr<Film> f)
_picture_asset_writer = _picture_asset->start_write (_first_nonexistant_frame > 0);
- AudioMapping m (_film->audio_channels ());
+ AudioMapping m (_film);
if (m.dcp_channels() > 0) {
_sound_asset.reset (