Fix some confusions with FFmpeg audio streams.
authorCarl Hetherington <cth@carlh.net>
Thu, 14 Apr 2016 02:28:38 +0000 (03:28 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 18 May 2016 10:50:29 +0000 (11:50 +0100)
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
test/ffmpeg_pts_offset_test.cc
test/frame_rate_test.cc
test/time_calculation_test.cc

index d9941685d08d43cbbf6eb523c34d8049aeaeb2af..dfeb2a0ad249ed91d67ecdcbda4e58eabe5331c6 100644 (file)
@@ -92,7 +92,7 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> film, cxml::ConstNodePtr no
                audio->add_stream (as);
                if (version < 11 && !(*i)->optional_node_child ("Selected")) {
                        /* This is an old file and this stream is not selected, so un-map it */
-                       as->set_mapping (AudioMapping (_audio_streams.back()->channels (), MAX_DCP_AUDIO_CHANNELS));
+                       as->set_mapping (AudioMapping (as->channels (), MAX_DCP_AUDIO_CHANNELS));
                }
        }
 
@@ -393,16 +393,6 @@ FFmpegContent::set_default_colour_conversion ()
        }
 }
 
-vector<AudioStreamPtr>
-FFmpegContent::audio_streams () const
-{
-       boost::mutex::scoped_lock lm (_mutex);
-
-       vector<AudioStreamPtr> s;
-       copy (_audio_streams.begin(), _audio_streams.end(), back_inserter (s));
-       return s;
-}
-
 void
 FFmpegContent::add_properties (list<UserProperty>& p) const
 {
@@ -540,3 +530,13 @@ FFmpegContent::changed (int property)
                subtitle->set_video_frame_rate (video->frame_rate ());
        }
 }
+
+vector<shared_ptr<FFmpegAudioStream> >
+FFmpegContent::ffmpeg_audio_streams () const
+{
+       vector<shared_ptr<FFmpegAudioStream> > fa;
+       BOOST_FOREACH (AudioStreamPtr i, audio->streams()) {
+               fa.push_back (dynamic_pointer_cast<FFmpegAudioStream> (i));
+       }
+       return fa;
+}
index f39414a61750e50e0eac86cd3ff24fb9b3dfe8f5..de222b0dee4805d2a02e2c954089295aa5fde1b6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2016 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
@@ -63,8 +63,6 @@ public:
 
        void set_default_colour_conversion ();
 
-       std::vector<AudioStreamPtr> audio_streams () const;
-
        bool has_text_subtitles () const;
        bool has_image_subtitles () const;
 
@@ -82,10 +80,7 @@ public:
                return _subtitle_stream;
        }
 
-       std::vector<boost::shared_ptr<FFmpegAudioStream> > ffmpeg_audio_streams () const {
-               boost::mutex::scoped_lock lm (_mutex);
-               return _audio_streams;
-       }
+       std::vector<boost::shared_ptr<FFmpegAudioStream> > ffmpeg_audio_streams () const;
 
        std::vector<Filter const *> filters () const {
                boost::mutex::scoped_lock lm (_mutex);
@@ -112,7 +107,6 @@ private:
 
        std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
        boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
-       std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
        boost::optional<ContentTime> _first_video;
        /** Video filters that should be used when generating DCPs */
        std::vector<Filter const *> _filters;
index 7e3cd9cfd8676e4c3db51c828defa7764161e836..5b1821daeb173bfe52dbf167185ec209256818ad 100644 (file)
@@ -26,6 +26,7 @@
 #include "lib/ffmpeg_decoder.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/ffmpeg_audio_stream.h"
+#include "lib/audio_content.h"
 #include "test.h"
 
 using boost::shared_ptr;
@@ -34,13 +35,13 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
 {
        shared_ptr<Film> film = new_test_film ("ffmpeg_pts_offset_test");
        shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
-       content->_audio_streams.push_back (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream));
+       content->audio->add_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream));
        content->video->_frame_rate = 24;
 
        {
                /* Sound == video so no offset required */
                content->_first_video = ContentTime ();
-               content->_audio_streams.front()->first_audio = ContentTime ();
+               content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
                FFmpegDecoder decoder (content, film->log(), false);
                BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ());
        }
@@ -48,7 +49,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
        {
                /* Common offset should be removed */
                content->_first_video = ContentTime::from_seconds (600);
-               content->_audio_streams.front()->first_audio = ContentTime::from_seconds (600);
+               content->ffmpeg_audio_streams().front()->first_audio = ContentTime::from_seconds (600);
                FFmpegDecoder decoder (content, film->log(), false);
                BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime::from_seconds (-600));
        }
@@ -56,7 +57,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
        {
                /* Video is on a frame boundary */
                content->_first_video = ContentTime::from_frames (1, 24);
-               content->_audio_streams.front()->first_audio = ContentTime ();
+               content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
                FFmpegDecoder decoder (content, film->log(), false);
                BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ());
        }
@@ -65,7 +66,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
                /* Video is off a frame boundary */
                double const frame = 1.0 / 24.0;
                content->_first_video = ContentTime::from_seconds (frame + 0.0215);
-               content->_audio_streams.front()->first_audio = ContentTime ();
+               content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
                FFmpegDecoder decoder (content, film->log(), false);
                BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215), 0.00001);
        }
@@ -74,7 +75,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
                /* Video is off a frame boundary and both have a common offset */
                double const frame = 1.0 / 24.0;
                content->_first_video = ContentTime::from_seconds (frame + 0.0215 + 4.1);
-               content->_audio_streams.front()->first_audio = ContentTime::from_seconds (4.1);
+               content->ffmpeg_audio_streams().front()->first_audio = ContentTime::from_seconds (4.1);
                FFmpegDecoder decoder (content, film->log(), false);
                BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215) - 4.1, 0.1);
        }
index 68a6ffa2d7e3c842bbc0b25331ff410766a7ac22..35cd5523a3329e5f3c24b7244835f97815e7cee5 100644 (file)
@@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
        Config::instance()->set_allowed_dcp_frame_rates (afr);
 
        shared_ptr<FFmpegAudioStream> stream (new FFmpegAudioStream ("foo", 0, 0, 0));
-       content->_audio_streams.push_back (stream);
+       content->audio->add_stream (stream);
        content->video->_frame_rate = 24;
        film->set_video_frame_rate (24);
        stream->_frame_rate = 48000;
index 353a97dd0ec8b4d990a41ee94ef7475d7a1bf1a5..7f13e6c0e64320f1dc7214153b90e063a1a7a855 100644 (file)
@@ -21,6 +21,7 @@
 #include "lib/ffmpeg_content.h"
 #include "lib/video_content.h"
 #include "lib/player.h"
+#include "lib/audio_content.h"
 #include "test.h"
 #include <boost/test/unit_test.hpp>
 
@@ -534,7 +535,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
 
        list<string> notes;
        shared_ptr<FFmpegContent> content (new FFmpegContent (film, doc, film->state_version(), notes));
-       AudioStreamPtr stream = content->audio_streams().front();
+       AudioStreamPtr stream = content->audio->streams().front();
        film->set_sequence (false);
        film->add_content (content);