Test filling of stuff with black.
authorCarl Hetherington <cth@carlh.net>
Fri, 31 May 2013 16:21:35 +0000 (17:21 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 31 May 2013 16:21:35 +0000 (17:21 +0100)
21 files changed:
src/lib/audio_content.cc
src/lib/audio_decoder.cc
src/lib/audio_decoder.h
src/lib/black_decoder.cc
src/lib/black_decoder.h
src/lib/decoder.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/imagemagick_content.cc
src/lib/imagemagick_content.h
src/lib/imagemagick_decoder.cc
src/lib/imagemagick_decoder.h
src/lib/player.cc
src/lib/silence_decoder.cc
src/lib/silence_decoder.h
src/lib/sndfile_decoder.cc
src/lib/sndfile_decoder.h
src/lib/video_decoder.cc
src/lib/video_decoder.h
test/black_fill_test.cc [new file with mode: 0644]
test/test.cc

index fb196c776d4ac82a71d87c290e0aae771f2c8b14..9940574f93bf8cbf11c726638a98a2aec1dc5ce6 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <libcxml/cxml.h>
 #include "audio_content.h"
+#include "film.h"
 
 using std::string;
 using boost::shared_ptr;
@@ -92,4 +93,3 @@ AudioContent::set_audio_delay (int d)
        
        signal_changed (AudioContentProperty::AUDIO_DELAY);
 }
-
index 9b8d15bf163927c69cbe201e5c7427825013db76..bbd4ced6c1a2c114f337729f8fe609f71e1eb353 100644 (file)
@@ -27,6 +27,7 @@
 using std::stringstream;
 using std::list;
 using std::pair;
+using std::cout;
 using boost::optional;
 using boost::shared_ptr;
 
@@ -151,7 +152,16 @@ AudioDecoder::audio (shared_ptr<const AudioBuffers> data, Time time)
        }
 
        Audio (dcp_mapped, time);
+       cout << "bumping n.a. by " << data->frames() << " ie " << film->audio_frames_to_time(data->frames()) << "\n";
        _next_audio = time + film->audio_frames_to_time (data->frames());
 }
 
-               
+bool
+AudioDecoder::audio_done () const
+{
+       shared_ptr<const Film> film = _film.lock ();
+       assert (film);
+       
+       return (_audio_content->length() - _next_audio) < film->audio_frames_to_time (1);
+}
+       
index fb9f23f034be4bd410b5b50bb5ec05c7611e16a7..1da8a676f37c7f59c3deeb46a166829e60ff1687 100644 (file)
@@ -44,6 +44,7 @@ public:
 protected:
 
        void audio (boost::shared_ptr<const AudioBuffers>, Time);
+       bool audio_done () const;
 
        Time _next_audio;
        boost::shared_ptr<const AudioContent> _audio_content;
index 3cdd5eef5c7202e28aa37ef17fd46963b06e0c2d..ce79ba0d77db45620f1d654b7a9e9fae71284321 100644 (file)
@@ -92,3 +92,11 @@ BlackDecoder::seek_forward ()
 
        _next_video += f->video_frames_to_time (1);
 }
+
+bool
+BlackDecoder::done () const
+{
+       return video_done ();
+}
+
+       
index 3aa63e22f23c5c07aac6d4c9d4eeb4f41348ae9a..622489646fe64b76c816a976efcb022df582b2ae 100644 (file)
@@ -33,6 +33,7 @@ public:
        void seek_back ();
        void seek_forward ();
        Time next () const;
+       bool done () const;
 
        /* VideoDecoder */
 
index edb532b9cc8474e0e474ac882d95d114fae71925..b550bf5cbe55e990eadd13aa95baab47a7f3f010 100644 (file)
@@ -72,6 +72,8 @@ public:
         */
        virtual Time next () const = 0;
 
+       virtual bool done () const = 0;
+
 protected:
 
        /** The Film that we are decoding in */
index c148bc530c7cf8f84fb342a9b3aff8aafbfd2c3b..67587a56499b8438de1b9d53d12c155a2ebe1937 100644 (file)
@@ -615,3 +615,10 @@ FFmpegDecoder::next () const
 
        return _next_video;
 }
+
+bool
+FFmpegDecoder::done () const
+{
+       return (!_decode_audio || !_audio_codec_context || audio_done()) && (!_decode_video || video_done());
+}
+       
index 7b8e1b50c14657a89db05eabe7f951e4ac1458a2..2d295db7b68b7bf3a1e6dd18fd604b77090f0e9f 100644 (file)
@@ -69,6 +69,7 @@ public:
        void seek_back ();
        void seek_forward ();
        Time next () const;
+       bool done () const;
 
        /* VideoDecoder */
 
index a4777e3cda11350c5823384fb5022c4b8c702e7b..2b7449a6e99870acc3471bbfdfe40644dc0221bb 100644 (file)
@@ -105,3 +105,4 @@ ImageMagickContent::length () const
        FrameRateConversion frc (24, film->dcp_video_frame_rate ());
        return video_length() * frc.factor() * TIME_HZ / film->dcp_video_frame_rate ();
 }
+
index e3e82789238a3a4ee6a2e6ad3638155371e18969..8ed6b08734ad31d34e4c8b75e368510b20d77c07 100644 (file)
@@ -17,6 +17,9 @@
 
 */
 
+#ifndef DVDOMATIC_IMAGEMAGICK_CONTENT_H
+#define DVDOMATIC_IMAGEMAGICK_CONTENT_H
+
 #include <boost/enable_shared_from_this.hpp>
 #include "video_content.h"
 
@@ -44,3 +47,5 @@ public:
 
        static bool valid_file (boost::filesystem::path);
 };
+
+#endif
index 15c919e87ac3e867f9cbbf3ab97a2bb3ebf3a013..7da0ed551e3a86960dd7183c222241ece9318f90 100644 (file)
@@ -138,3 +138,11 @@ ImageMagickDecoder::next () const
 {
        return _next_video;
 }
+
+
+bool
+ImageMagickDecoder::done () const
+{
+       return video_done ();
+}
+       
index 6640032babe4f376a29732fe9edcc1517a55a9e0..82c87876bdc8dba4a69de0c4872ffcfc015897ae 100644 (file)
@@ -37,6 +37,7 @@ public:
        void seek_back ();
        void seek_forward ();
        Time next () const;
+       bool done () const;
 
        /* VideoDecoder */
 
index e64e1e0114edf2cfe63ec17e4aedecad3d190cdd..757f9bbcecfe8f6df35fdc421783f2af0bdabacd 100644 (file)
@@ -101,8 +101,12 @@ Player::pass ()
         shared_ptr<Piece> earliest;
 
        for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
-//             cout << "check " << (*i)->content->file() << " start=" << (*i)->content->start() << ", next=" << (*i)->decoder->next() << ", end=" << (*i)->content->end() << "\n";
-               if (((*i)->decoder->next() + (*i)->content->start()) >= (*i)->content->end()) {
+               cout << "check " << (*i)->content->file()
+                    << " start=" << (*i)->content->start()
+                    << ", next=" << (*i)->decoder->next()
+                    << ", end=" << (*i)->content->end() << "\n";
+               
+               if ((*i)->decoder->done ()) {
                        continue;
                }
 
@@ -112,7 +116,7 @@ Player::pass ()
                
                Time const t = (*i)->content->start() + (*i)->decoder->next();
                if (t < earliest_t) {
-//                     cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n";
+                       cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n";
                        earliest_t = t;
                        earliest = *i;
                }
@@ -248,6 +252,7 @@ void
 Player::add_black_piece (Time s, Time len)
 {
        shared_ptr<NullContent> nc (new NullContent (_film, s, len));
+       nc->set_ratio (_film->container ());
        shared_ptr<BlackDecoder> bd (new BlackDecoder (_film, nc));
        bd->Video.connect (bind (&Player::process_video, this, nc, _1, _2, _3));
        _pieces.push_back (shared_ptr<Piece> (new Piece (nc, bd)));
index 6cf91b41fee15f6f02226d7cb0c30baeac1cd144..c8aa5c632373faba1a52d5f3e4103def822afce9 100644 (file)
@@ -22,6 +22,7 @@
 #include "audio_buffers.h"
 
 using std::min;
+using std::cout;
 using boost::shared_ptr;
 
 SilenceDecoder::SilenceDecoder (shared_ptr<const Film> f, shared_ptr<NullContent> c)
@@ -36,8 +37,9 @@ SilenceDecoder::pass ()
 {
        shared_ptr<const Film> film = _film.lock ();
        assert (film);
-       
+
        Time const this_time = min (_audio_content->length() - _next_audio, TIME_HZ / 2);
+       cout << "silence emit " << this_time << " from " << _audio_content->length() << "\n";
        shared_ptr<AudioBuffers> data (new AudioBuffers (film->dcp_audio_channels(), film->time_to_audio_frames (this_time)));
        data->make_silent ();
        audio (data, _next_audio);
@@ -76,3 +78,10 @@ SilenceDecoder::next () const
 {
        return _next_audio;
 }
+
+bool
+SilenceDecoder::done () const
+{
+       return audio_done ();
+}
+
index 8452bc43f99c2a88629f94aadb6c3191ada15eb1..d05376a144aab7e1f8240e689f9e8465b5afa63d 100644 (file)
@@ -33,4 +33,5 @@ public:
        void seek_back ();
        void seek_forward ();
        Time next () const;
+       bool done () const;
 };
index c4c6e5f4ee065f6dca6145defbb293bedcb5b7d1..c12152e673fcbc0eca679d0da1e08f31e39d4aa8 100644 (file)
@@ -117,3 +117,9 @@ SndfileDecoder::next () const
 {
        return _next_audio;
 }
+
+bool
+SndfileDecoder::done () const
+{
+       return audio_done ();
+}
index b4fa5bc58a8a5538bd6e711f5dc2478664e8e9a2..a5edc196c87a7efeeb06688f70feaf6f5e092beb 100644 (file)
@@ -34,6 +34,7 @@ public:
        void seek_back () {}
        void seek_forward () {}
        Time next () const;
+       bool done () const;
 
        int audio_channels () const;
        ContentAudioFrame audio_length () const;
index cba21d280aae20a51fff025cb470fde6d3f5cb10..086a6b552c8cea76153b991f2ff0de1d0ff2eca5 100644 (file)
@@ -112,3 +112,12 @@ VideoDecoder::subtitle (shared_ptr<TimedSubtitle> s)
                _timed_subtitle->subtitle()->set_position (Position (p.x - _video_content->crop().left, p.y - _video_content->crop().top));
        }
 }
+
+bool
+VideoDecoder::video_done () const
+{
+       shared_ptr<const Film> film = _film.lock ();
+       assert (film);
+       
+       return (_video_content->length() - _next_video) < film->video_frames_to_time (1);
+}
index b31766b5080ba8b6abf378cdf594bc391e33a967..5073efead72835ba87edcb3857bfd6d31805ca20 100644 (file)
@@ -44,6 +44,7 @@ protected:
        
        void video (boost::shared_ptr<Image>, bool, Time);
        void subtitle (boost::shared_ptr<TimedSubtitle>);
+       bool video_done () const;
 
        Time _next_video;
        boost::shared_ptr<const VideoContent> _video_content;
diff --git a/test/black_fill_test.cc b/test/black_fill_test.cc
new file mode 100644 (file)
index 0000000..7ea031e
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+    Copyright (C) 2013 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
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "imagemagick_content.h"
+
+/** @file test/black_fill_test.cc
+ *  @brief Test insertion of black frames between video content.
+ */
+
+using boost::shared_ptr;
+
+BOOST_AUTO_TEST_CASE (black_fill_test)
+{
+       shared_ptr<Film> film = new_test_film ("black_fill_test");
+       film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR"));
+       film->set_name ("black_fill_test");
+       film->set_container (Ratio::from_id ("185"));
+       film->set_sequence_video (false);
+       shared_ptr<ImageMagickContent> contentA (new ImageMagickContent (film, "test/data/simple_testcard_640x480.png"));
+       contentA->set_ratio (Ratio::from_id ("185"));
+       shared_ptr<ImageMagickContent> contentB (new ImageMagickContent (film, "test/data/simple_testcard_640x480.png"));
+       contentB->set_ratio (Ratio::from_id ("185"));
+
+       film->examine_and_add_content (contentA);
+       film->examine_and_add_content (contentB);
+       while (JobManager::instance()->work_to_do ());
+
+       contentA->set_video_length (3);
+       contentA->set_start (film->video_frames_to_time (2));
+       contentB->set_video_length (1);
+       contentB->set_start (film->video_frames_to_time (7));
+
+       film->make_dcp ();
+
+       while (JobManager::instance()->work_to_do ());
+
+       BOOST_CHECK (!JobManager::instance()->errors());
+
+       boost::filesystem::path ref;
+       ref = "test";
+       ref /= "data";
+       ref /= "black_fill_test";
+
+       boost::filesystem::path check;
+       check = "build";
+       check /= "test";
+       check /= "black_fill_test";
+       check /= film->dcp_name();
+
+       check_dcp (ref.string(), check.string());
+}
+
index 2837729c581ca83895d9acd103b37691d47a2095..d9c53209c39059677485e52185a5d71dc2512737 100644 (file)
@@ -149,7 +149,7 @@ check_dcp (string ref, string check)
        BOOST_CHECK (ref_dcp.equals (check_dcp, options, boost::bind (note, _1, _2)));
 }
 
-
+#include "black_fill_test.cc"
 #include "scaling_test.cc"
 #include "ratio_test.cc"
 #include "pixel_formats_test.cc"