From 5778f4c92793a7950f02206e735a00731c87b090 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 16 Jul 2013 23:09:34 +0100 Subject: Fix up AudioMapping confusions with respect to number of content channels. --- src/lib/audio_mapping.cc | 31 ++++++++++++++++--------------- src/lib/audio_mapping.h | 12 +++++++++++- src/lib/ffmpeg_content.cc | 2 +- src/lib/ffmpeg_content.h | 10 ++++++++-- src/lib/sndfile_content.cc | 3 ++- 5 files changed, 38 insertions(+), 20 deletions(-) (limited to 'src/lib') diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 4630f17c1..7a5da7d2a 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -32,6 +32,7 @@ using boost::lexical_cast; using boost::dynamic_pointer_cast; AudioMapping::AudioMapping () + : _content_channels (0) { } @@ -40,13 +41,20 @@ AudioMapping::AudioMapping () * @param c Number of channels. */ AudioMapping::AudioMapping (int c) + : _content_channels (c) { - if (c == 1) { + +} + +void +AudioMapping::make_default () +{ + if (_content_channels == 1) { /* Mono -> Centre */ add (0, libdcp::CENTRE); } else { /* 1:1 mapping */ - for (int i = 0; i < c; ++i) { + for (int i = 0; i < _content_channels; ++i) { add (i, static_cast (i)); } } @@ -54,6 +62,8 @@ AudioMapping::AudioMapping (int c) AudioMapping::AudioMapping (shared_ptr node) { + _content_channels = node->number_child ("ContentChannels"); + list > const c = node->node_children ("Map"); for (list >::const_iterator i = c.begin(); i != c.end(); ++i) { add ((*i)->number_child ("ContentIndex"), static_cast ((*i)->number_child ("DCP"))); @@ -79,22 +89,11 @@ AudioMapping::dcp_to_content (libdcp::Channel d) const return c; } -list -AudioMapping::content_channels () const -{ - list c; - for (list >::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 AudioMapping::content_to_dcp (int c) const { + assert (c < _content_channels); + list d; for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { if (i->first == c) { @@ -108,6 +107,8 @@ AudioMapping::content_to_dcp (int c) const void AudioMapping::as_xml (xmlpp::Node* node) const { + node->add_child ("ContentChannels")->add_child_text (lexical_cast (_content_channels)); + for (list >::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 (i->first)); diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h index ed2c3f28d..9a507b550 100644 --- a/src/lib/audio_mapping.h +++ b/src/lib/audio_mapping.h @@ -32,6 +32,11 @@ namespace cxml { class Node; } +/** A many-to-many mapping from some content channels to DCP channels. + * The number of content channels is set on construction and fixed, + * and then each of those content channels can be mapped to zero or + * more DCP channels. + */ class AudioMapping { public: @@ -44,16 +49,21 @@ public: void as_xml (xmlpp::Node *) const; void add (int, libdcp::Channel); + void make_default (); std::list dcp_to_content (libdcp::Channel) const; std::list > content_to_dcp () const { return _content_to_dcp; } - std::list content_channels () const; + int content_channels () const { + return _content_channels; + } + std::list content_to_dcp (int) const; private: + int _content_channels; std::list > _content_to_dcp; }; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 4c9b1d166..ebad8c8bd 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -281,12 +281,12 @@ operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b) } FFmpegAudioStream::FFmpegAudioStream (shared_ptr node) + : mapping (node->node_child ("Mapping")) { name = node->string_child ("Name"); id = node->number_child ("Id"); frame_rate = node->number_child ("FrameRate"); channels = node->number_child ("Channels"); - mapping = AudioMapping (node->node_child ("Mapping")); first_audio = node->optional_number_child ("FirstAudio"); } diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index bf550942a..1af586a71 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -24,6 +24,7 @@ #include "video_content.h" #include "audio_content.h" #include "subtitle_content.h" +#include "audio_mapping.h" class Filter; class ffmpeg_pts_offset_test; @@ -37,7 +38,9 @@ public: , frame_rate (f) , channels (c) , mapping (c) - {} + { + mapping.make_default (); + } FFmpegAudioStream (boost::shared_ptr); @@ -52,8 +55,11 @@ public: private: friend class ffmpeg_pts_offset_test; + /* Constructor for tests */ - FFmpegAudioStream () {} + FFmpegAudioStream () + : mapping (1) + {} }; extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b); diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc index 2dd7d8f67..7e6d56a9e 100644 --- a/src/lib/sndfile_content.cc +++ b/src/lib/sndfile_content.cc @@ -44,11 +44,11 @@ SndfileContent::SndfileContent (shared_ptr f, boost::filesystem::pat SndfileContent::SndfileContent (shared_ptr f, shared_ptr node) : Content (f, node) , AudioContent (f, node) + , _audio_mapping (node->node_child ("AudioMapping")) { _audio_channels = node->number_child ("AudioChannels"); _audio_length = node->number_child ("AudioLength"); _audio_frame_rate = node->number_child ("AudioFrameRate"); - _audio_mapping = AudioMapping (node->node_child ("AudioMapping")); } string @@ -109,6 +109,7 @@ SndfileContent::examine (shared_ptr job) /* XXX: do this in signal_changed...? */ _audio_mapping = AudioMapping (_audio_channels); + _audio_mapping.make_default (); signal_changed (AudioContentProperty::AUDIO_MAPPING); } -- cgit v1.2.3