Fix player audio, almost totally broken by a stupid mistake v2.16.59
authorCarl Hetherington <cth@carlh.net>
Tue, 6 Jun 2023 17:36:24 +0000 (19:36 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 6 Jun 2023 17:36:26 +0000 (19:36 +0200)
in 78b2c650a9249cb7165d269b4378391d31e68e8b

Following that commit 16 channel audio streams were being read
as 6-channel, with unsurprising consequences.

src/lib/dcp_content.cc
src/lib/dcp_content.h
src/lib/dcp_examiner.cc
src/lib/dcp_examiner.h
src/wx/player_information.cc

index 87e59de50bc7ca27a14bfcde1d39b109b4e45429..e2b19fb8ee1b758876fac521ae1db2f0e5ad10af 100644 (file)
@@ -160,6 +160,8 @@ DCPContent::DCPContent (cxml::ConstNodePtr node, int version)
        for (auto i: node->node_children("ContentVersion")) {
                _content_versions.push_back (i->content());
        }
+
+       _active_audio_channels = node->optional_number_child<int>("ActiveAudioChannels");
 }
 
 void
@@ -252,6 +254,8 @@ DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
                auto m = as->mapping ();
                m.make_default (film ? film->audio_processor() : 0);
                as->set_mapping (m);
+
+               _active_audio_channels = examiner->active_audio_channels();
        }
 
        if (examiner->has_atmos()) {
@@ -413,6 +417,10 @@ DCPContent::as_xml (xmlpp::Node* node, bool with_paths) const
        for (auto i: _content_versions) {
                node->add_child("ContentVersion")->add_child_text(i);
        }
+
+       if (_active_audio_channels) {
+               node->add_child("ActiveAudioChannels")->add_child_text(raw_convert<string>(*_active_audio_channels));
+       }
 }
 
 DCPTime
@@ -862,3 +870,12 @@ DCPContent::check_font_ids()
        add_fonts_from_examiner(text.front(), examiner.fonts());
 }
 
+
+int
+DCPContent::active_audio_channels() const
+{
+       return _active_audio_channels.get_value_or(
+               (audio && audio->stream()) ? audio->stream()->channels() : 0
+               );
+}
+
index 96ae09521fd53f4e1d46ae8bdd19ea5a69ef89ad..fd78cd0aca2390994bf198c023e289db3de738c2 100644 (file)
@@ -174,6 +174,8 @@ public:
                return _content_versions;
        }
 
+       int active_audio_channels() const;
+
        void check_font_ids();
 
 private:
@@ -225,6 +227,8 @@ private:
        std::map<dcp::Marker, dcpomatic::ContentTime> _markers;
        std::vector<dcp::Rating> _ratings;
        std::vector<std::string> _content_versions;
+
+       boost::optional<int> _active_audio_channels;
 };
 
 
index 50b19e2fd2918b01d0a953919af4ac531f0619cc..e369b46ff08171be8ec699b2d03ee612d4b2e1b6 100644 (file)
@@ -175,11 +175,17 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
                        auto asset = reel->main_sound()->asset();
 
                        if (!_audio_channels) {
-                               _audio_channels = asset->active_channels();
-                       } else if (_audio_channels.get() != asset->active_channels()) {
+                               _audio_channels = asset->channels();
+                       } else if (_audio_channels.get() != asset->channels()) {
                                throw DCPError (_("Mismatched audio channel counts in DCP"));
                        }
 
+                       if (!_active_audio_channels) {
+                               _active_audio_channels = asset->active_channels();
+                       } else if (_active_audio_channels.get() != asset->active_channels()) {
+                               throw DCPError(_("Mismatched active audio channel counts in DCP"));
+                       }
+
                        if (!_audio_frame_rate) {
                                _audio_frame_rate = asset->sampling_rate ();
                        } else if (_audio_frame_rate.get() != asset->sampling_rate ()) {
index b51e7ae7a8e53d69cf406a05f2956599e5a22f89..1a3615867b4c101ac944b623e66af97ed632388f 100644 (file)
@@ -90,6 +90,10 @@ public:
                return _audio_channels.get_value_or (0);
        }
 
+       int active_audio_channels() const {
+               return _active_audio_channels.get_value_or(0);
+       }
+
        Frame audio_length () const override {
                return _audio_length;
        }
@@ -179,6 +183,7 @@ private:
        boost::optional<dcp::Size> _video_size;
        Frame _video_length = 0;
        boost::optional<int> _audio_channels;
+       boost::optional<int> _active_audio_channels;
        boost::optional<int> _audio_frame_rate;
        Frame _audio_length = 0;
        std::string _name;
index 4e95e0956fb208de2e17b57553923beb2f1744ce..806611140f2a028d4de5bde16e69fc8c7f31ce36 100644 (file)
@@ -166,7 +166,7 @@ PlayerInformation::triggered_update ()
                checked_set (_dcp[r++], wxString::Format(_("Frame rate: %d"), (int) lrint(*dcp->video_frame_rate())));
        }
        if (dcp->audio && !dcp->audio->streams().empty()) {
-               checked_set (_dcp[r++], wxString::Format(_("Audio channels: %d"), dcp->audio->streams().front()->channels()));
+               checked_set(_dcp[r++], wxString::Format(_("Audio channels: %d"), dcp->active_audio_channels()));
        }
        if (!dcp->text.empty()) {
                checked_set (_dcp[r++], _("Subtitles: yes"));