summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-05-20 16:21:55 +0100
committerCarl Hetherington <cth@carlh.net>2013-05-20 16:21:55 +0100
commit0c66eaeac227d6aeb63a7a36e202ef87081dc222 (patch)
treefe59970e8ca5d6bfc7859fa6f901b1f1ed04eb33 /src/lib
parent56aa7eef1572e48c96ff198ee52a5a5fe17a6bf0 (diff)
Some basics of AudioMapping.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_content.cc9
-rw-r--r--src/lib/audio_content.h7
-rw-r--r--src/lib/audio_mapping.cc48
-rw-r--r--src/lib/audio_mapping.h18
-rw-r--r--src/lib/content.h2
-rw-r--r--src/lib/ffmpeg_content.cc15
-rw-r--r--src/lib/ffmpeg_content.h5
-rw-r--r--src/lib/ffmpeg_decoder.cc2
-rw-r--r--src/lib/film.h2
-rw-r--r--src/lib/sndfile_content.cc5
-rw-r--r--src/lib/sndfile_content.h8
11 files changed, 93 insertions, 28 deletions
diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc
index 9968f4725..e38d9d265 100644
--- a/src/lib/audio_content.cc
+++ b/src/lib/audio_content.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -35,7 +37,6 @@ AudioContent::AudioContent (boost::filesystem::path f)
AudioContent::AudioContent (shared_ptr<const cxml::Node> node)
: Content (node)
{
-
}
AudioContent::AudioContent (AudioContent const & o)
@@ -43,3 +44,9 @@ AudioContent::AudioContent (AudioContent const & o)
{
}
+
+void
+AudioContent::as_xml (xmlpp::Node* node) const
+{
+
+}
diff --git a/src/lib/audio_content.h b/src/lib/audio_content.h
index 87858488c..51f05efb0 100644
--- a/src/lib/audio_content.h
+++ b/src/lib/audio_content.h
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -21,7 +23,7 @@
#define DCPOMATIC_AUDIO_CONTENT_H
#include "content.h"
-#include "util.h"
+#include "audio_mapping.h"
namespace cxml {
class Node;
@@ -42,10 +44,13 @@ public:
AudioContent (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 (boost::shared_ptr<const Film>) const = 0;
+ virtual AudioMapping audio_mapping () const = 0;
};
#endif
diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc
index e1fa0c220..d0aa33657 100644
--- a/src/lib/audio_mapping.cc
+++ b/src/lib/audio_mapping.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -18,6 +20,7 @@
*/
#include <boost/lexical_cast.hpp>
+#include <libxml++/libxml++.h>
#include <libcxml/cxml.h>
#include "audio_mapping.h"
@@ -30,23 +33,39 @@ using boost::shared_ptr;
using boost::lexical_cast;
using boost::dynamic_pointer_cast;
-void
-AudioMapping::add (int c, libdcp::Channel d)
+AudioMapping::AudioMapping ()
{
- _content_to_dcp.push_back (make_pair (c, d));
+
}
-/* XXX: this is grotty */
-int
-AudioMapping::dcp_channels () const
+/** Create a default AudioMapping for a given channel count.
+ * @param c Number of channels.
+ */
+AudioMapping::AudioMapping (int c)
{
- for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
- if (((int) i->second) >= 2) {
- return 6;
+ 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")));
+ }
+}
- return 2;
+void
+AudioMapping::add (int c, libdcp::Channel d)
+{
+ _content_to_dcp.push_back (make_pair (c, d));
}
list<int>
@@ -97,12 +116,3 @@ AudioMapping::as_xml (xmlpp::Node* node) const
t->add_child ("DCP")->add_child_text (lexical_cast<string> (i->second));
}
}
-
-void
-AudioMapping::set_from_xml (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")));
- }
-}
diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h
index 3c471d3f4..7d76e4f5a 100644
--- a/src/lib/audio_mapping.h
+++ b/src/lib/audio_mapping.h
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -21,20 +23,28 @@
#define DCPOMATIC_AUDIO_MAPPING_H
#include <list>
-#include <string>
#include <libdcp/types.h>
#include <boost/shared_ptr.hpp>
-#include "audio_content.h"
+
+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 set_from_xml (boost::shared_ptr<const cxml::Node>);
void add (int, libdcp::Channel);
- int dcp_channels () const;
std::list<int> dcp_to_content (libdcp::Channel) const;
std::list<std::pair<int, libdcp::Channel> > content_to_dcp () const {
return _content_to_dcp;
diff --git a/src/lib/content.h b/src/lib/content.h
index 9f465570b..8db35891a 100644
--- a/src/lib/content.h
+++ b/src/lib/content.h
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc
index f0df15193..d730f3ecb 100644
--- a/src/lib/ffmpeg_content.cc
+++ b/src/lib/ffmpeg_content.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -88,6 +90,7 @@ 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);
@@ -263,6 +266,7 @@ operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b)
}
FFmpegAudioStream::FFmpegAudioStream (shared_ptr<const cxml::Node> node)
+ : mapping (node->node_child ("Mapping"))
{
name = node->string_child ("Name");
id = node->number_child<int> ("Id");
@@ -277,6 +281,7 @@ FFmpegAudioStream::as_xml (xmlpp::Node* root) const
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().
@@ -308,3 +313,13 @@ FFmpegContent::length (shared_ptr<const Film> film) const
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
+{
+ if (!_audio_stream) {
+ return AudioMapping ();
+ }
+
+ return _audio_stream->mapping;
+}
diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h
index 540df041f..d26c73125 100644
--- a/src/lib/ffmpeg_content.h
+++ b/src/lib/ffmpeg_content.h
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -32,6 +34,7 @@ public:
, id (i)
, frame_rate (f)
, channels (c)
+ , mapping (c)
{}
FFmpegAudioStream (boost::shared_ptr<const cxml::Node>);
@@ -42,6 +45,7 @@ public:
int id;
int frame_rate;
int channels;
+ AudioMapping mapping;
};
extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
@@ -96,6 +100,7 @@ public:
ContentAudioFrame audio_length () const;
int content_audio_frame_rate () const;
int output_audio_frame_rate (boost::shared_ptr<const Film>) const;
+ AudioMapping audio_mapping () const;
std::vector<FFmpegSubtitleStream> subtitle_streams () const {
boost::mutex::scoped_lock lm (_mutex);
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index e99a960ce..adf16c940 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -143,7 +143,7 @@ FFmpegDecoder::setup_general ()
_audio_streams.push_back (
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 (FFmpegSubtitleStream (stream_name (s), i));
}
diff --git a/src/lib/film.h b/src/lib/film.h
index cfc55c0ac..03d472cee 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -154,7 +154,6 @@ public:
J2K_BANDWIDTH,
DCI_METADATA,
DCP_VIDEO_FRAME_RATE,
- AUDIO_MAPPING
};
@@ -322,7 +321,6 @@ private:
void read_metadata ();
void playlist_changed ();
void playlist_content_changed (boost::weak_ptr<Content>, int);
- void setup_default_audio_mapping ();
std::string filename_safe_name () const;
/** Log to write to */
diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc
index 210ca1577..963abb58e 100644
--- a/src/lib/sndfile_content.cc
+++ b/src/lib/sndfile_content.cc
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -48,6 +50,7 @@ SndfileContent::SndfileContent (shared_ptr<const cxml::Node> node)
_audio_channels = node->number_child<int> ("AudioChannels");
_audio_length = node->number_child<ContentAudioFrame> ("AudioLength");
_audio_frame_rate = node->number_child<int> ("AudioFrameRate");
+ _mapping = AudioMapping (node->node_child ("Mapping"));
}
string
@@ -103,6 +106,7 @@ SndfileContent::examine (shared_ptr<Film> film, shared_ptr<Job> job, bool quick)
_audio_channels = dec.audio_channels ();
_audio_length = dec.audio_length ();
_audio_frame_rate = dec.audio_frame_rate ();
+ _mapping = AudioMapping (_audio_channels);
}
signal_changed (AudioContentProperty::AUDIO_CHANNELS);
@@ -118,6 +122,7 @@ SndfileContent::as_xml (xmlpp::Node* node) const
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));
+ _mapping.as_xml (node->add_child("Mapping"));
}
int
diff --git a/src/lib/sndfile_content.h b/src/lib/sndfile_content.h
index 0623aa6f0..e0d66b992 100644
--- a/src/lib/sndfile_content.h
+++ b/src/lib/sndfile_content.h
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
/*
Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
@@ -61,10 +63,16 @@ public:
int output_audio_frame_rate (boost::shared_ptr<const Film>) const;
+ AudioMapping audio_mapping () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _mapping;
+ }
+
static bool valid_file (boost::filesystem::path);
private:
int _audio_channels;
ContentAudioFrame _audio_length;
int _audio_frame_rate;
+ AudioMapping _mapping;
};