Move get_reel_assets() out of Player, as it doesn't need to be there.
authorCarl Hetherington <cth@carlh.net>
Sat, 10 Sep 2022 17:09:07 +0000 (19:09 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 10 Sep 2022 21:21:06 +0000 (23:21 +0200)
src/lib/dcp_encoder.cc
src/lib/player.cc
src/lib/player.h
src/lib/referenced_reel_asset.cc [new file with mode: 0644]
src/lib/referenced_reel_asset.h
src/lib/wscript
test/vf_test.cc

index e3443c1ad83bcfa43073e2d933a2a40137ad9289..e4cb76d792712064498be8f858573c271fd6b7be 100644 (file)
@@ -109,7 +109,7 @@ DCPEncoder::go ()
 
        while (!_player->pass ()) {}
 
-       for (auto i: _player->get_reel_assets()) {
+       for (auto i: get_referenced_reel_assets(_film, _film->playlist())) {
                _writer->write (i);
        }
 
index 2793bd62a9e70583b5961f08506fa05f08e2d017..13cd8f11badcb35102f33af52249d3abdbcdc79c 100644 (file)
@@ -47,7 +47,6 @@
 #include "playlist.h"
 #include "ratio.h"
 #include "raw_image_proxy.h"
-#include "referenced_reel_asset.h"
 #include "render_text.h"
 #include "shuffler.h"
 #include "text_content.h"
@@ -548,98 +547,6 @@ Player::set_play_referenced ()
 }
 
 
-static void
-maybe_add_asset (list<ReferencedReelAsset>& a, shared_ptr<dcp::ReelAsset> r, Frame reel_trim_start, Frame reel_trim_end, DCPTime from, int const ffr)
-{
-       DCPOMATIC_ASSERT (r);
-       r->set_entry_point (r->entry_point().get_value_or(0) + reel_trim_start);
-       r->set_duration (r->actual_duration() - reel_trim_start - reel_trim_end);
-       if (r->actual_duration() > 0) {
-               a.push_back (
-                       ReferencedReelAsset(r, DCPTimePeriod(from, from + DCPTime::from_frames(r->actual_duration(), ffr)))
-                       );
-       }
-}
-
-
-list<ReferencedReelAsset>
-Player::get_reel_assets ()
-{
-       /* Does not require a lock on _mutex as it's only called from DCPEncoder */
-
-       list<ReferencedReelAsset> reel_assets;
-
-       for (auto content: playlist()->content()) {
-               auto dcp = dynamic_pointer_cast<DCPContent>(content);
-               if (!dcp) {
-                       continue;
-               }
-
-               if (!dcp->reference_video() && !dcp->reference_audio() && !dcp->reference_text(TextType::OPEN_SUBTITLE) && !dcp->reference_text(TextType::CLOSED_CAPTION)) {
-                       continue;
-               }
-
-               scoped_ptr<DCPDecoder> decoder;
-               try {
-                       decoder.reset (new DCPDecoder(_film, dcp, false, false, shared_ptr<DCPDecoder>()));
-               } catch (...) {
-                       return reel_assets;
-               }
-
-               auto const frame_rate = _film->video_frame_rate();
-               DCPOMATIC_ASSERT (dcp->video_frame_rate());
-               /* We should only be referencing if the DCP rate is the same as the film rate */
-               DCPOMATIC_ASSERT (std::round(dcp->video_frame_rate().get()) == frame_rate);
-
-               Frame const trim_start = dcp->trim_start().frames_round(frame_rate);
-               Frame const trim_end = dcp->trim_end().frames_round(frame_rate);
-
-               /* position in the asset from the start */
-               int64_t offset_from_start = 0;
-               /* position i the asset from the end */
-               int64_t offset_from_end = 0;
-               for (auto reel: decoder->reels()) {
-                       /* Assume that main picture duration is the length of the reel */
-                       offset_from_end += reel->main_picture()->actual_duration();
-               }
-
-               for (auto reel: decoder->reels()) {
-
-                       /* Assume that main picture duration is the length of the reel */
-                       int64_t const reel_duration = reel->main_picture()->actual_duration();
-
-                       /* See doc/design/trim_reels.svg */
-                       Frame const reel_trim_start = min(reel_duration, max(int64_t(0), trim_start - offset_from_start));
-                       Frame const reel_trim_end =   min(reel_duration, max(int64_t(0), reel_duration - (offset_from_end - trim_end)));
-
-                       auto const from = content->position() + std::max(DCPTime(), DCPTime::from_frames(offset_from_start - trim_start, frame_rate));
-                       if (dcp->reference_video()) {
-                               maybe_add_asset (reel_assets, reel->main_picture(), reel_trim_start, reel_trim_end, from, frame_rate);
-                       }
-
-                       if (dcp->reference_audio()) {
-                               maybe_add_asset (reel_assets, reel->main_sound(), reel_trim_start, reel_trim_end, from, frame_rate);
-                       }
-
-                       if (dcp->reference_text(TextType::OPEN_SUBTITLE)) {
-                               maybe_add_asset (reel_assets, reel->main_subtitle(), reel_trim_start, reel_trim_end, from, frame_rate);
-                       }
-
-                       if (dcp->reference_text(TextType::CLOSED_CAPTION)) {
-                               for (auto caption: reel->closed_captions()) {
-                                       maybe_add_asset (reel_assets, caption, reel_trim_start, reel_trim_end, from, frame_rate);
-                               }
-                       }
-
-                       offset_from_start += reel_duration;
-                       offset_from_end -= reel_duration;
-               }
-       }
-
-       return reel_assets;
-}
-
-
 bool
 Player::pass ()
 {
index 31628941f5eb04804249bd95583cdba7d6b6400e..e07cc8200a3bb9af2d15b51856511e1902f311c4 100644 (file)
@@ -81,7 +81,7 @@ public:
        void seek (dcpomatic::DCPTime time, bool accurate);
 
        std::vector<std::shared_ptr<dcpomatic::Font>> get_subtitle_fonts ();
-       std::list<ReferencedReelAsset> get_reel_assets ();
+
        dcp::Size video_container_size () const {
                return _video_container_size;
        }
diff --git a/src/lib/referenced_reel_asset.cc b/src/lib/referenced_reel_asset.cc
new file mode 100644 (file)
index 0000000..bd87b90
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "dcp_content.h"
+#include "dcp_decoder.h"
+#include "dcpomatic_assert.h"
+#include "film.h"
+#include "playlist.h"
+#include "referenced_reel_asset.h"
+#include <dcp/reel.h>
+#include <dcp/reel_asset.h>
+#include <dcp/reel_closed_caption_asset.h>
+#include <dcp/reel_picture_asset.h>
+#include <dcp/reel_sound_asset.h>
+#include <dcp/reel_subtitle_asset.h>
+#include <cmath>
+
+
+using std::list;
+using std::max;
+using std::min;
+using std::shared_ptr;
+using boost::dynamic_pointer_cast;
+using boost::scoped_ptr;
+using namespace dcpomatic;
+
+
+static void
+maybe_add_asset (list<ReferencedReelAsset>& a, shared_ptr<dcp::ReelAsset> r, Frame reel_trim_start, Frame reel_trim_end, DCPTime from, int const ffr)
+{
+       DCPOMATIC_ASSERT (r);
+       r->set_entry_point (r->entry_point().get_value_or(0) + reel_trim_start);
+       r->set_duration (r->actual_duration() - reel_trim_start - reel_trim_end);
+       if (r->actual_duration() > 0) {
+               a.push_back (
+                       ReferencedReelAsset(r, DCPTimePeriod(from, from + DCPTime::from_frames(r->actual_duration(), ffr)))
+                       );
+       }
+}
+
+
+
+/** @return Details of all the DCP assets in a playlist that are marked to refer to */
+list<ReferencedReelAsset>
+get_referenced_reel_assets(shared_ptr<const Film> film, shared_ptr<const Playlist> playlist)
+{
+       list<ReferencedReelAsset> reel_assets;
+
+       for (auto content: playlist->content()) {
+               auto dcp = dynamic_pointer_cast<DCPContent>(content);
+               if (!dcp) {
+                       continue;
+               }
+
+               if (!dcp->reference_video() && !dcp->reference_audio() && !dcp->reference_text(TextType::OPEN_SUBTITLE) && !dcp->reference_text(TextType::CLOSED_CAPTION)) {
+                       continue;
+               }
+
+               scoped_ptr<DCPDecoder> decoder;
+               try {
+                       decoder.reset(new DCPDecoder(film, dcp, false, false, shared_ptr<DCPDecoder>()));
+               } catch (...) {
+                       return reel_assets;
+               }
+
+               auto const frame_rate = film->video_frame_rate();
+               DCPOMATIC_ASSERT (dcp->video_frame_rate());
+               /* We should only be referencing if the DCP rate is the same as the film rate */
+               DCPOMATIC_ASSERT (std::round(dcp->video_frame_rate().get()) == frame_rate);
+
+               Frame const trim_start = dcp->trim_start().frames_round(frame_rate);
+               Frame const trim_end = dcp->trim_end().frames_round(frame_rate);
+
+               /* position in the asset from the start */
+               int64_t offset_from_start = 0;
+               /* position i the asset from the end */
+               int64_t offset_from_end = 0;
+               for (auto reel: decoder->reels()) {
+                       /* Assume that main picture duration is the length of the reel */
+                       offset_from_end += reel->main_picture()->actual_duration();
+               }
+
+               for (auto reel: decoder->reels()) {
+
+                       /* Assume that main picture duration is the length of the reel */
+                       int64_t const reel_duration = reel->main_picture()->actual_duration();
+
+                       /* See doc/design/trim_reels.svg */
+                       Frame const reel_trim_start = min(reel_duration, max(int64_t(0), trim_start - offset_from_start));
+                       Frame const reel_trim_end =   min(reel_duration, max(int64_t(0), reel_duration - (offset_from_end - trim_end)));
+
+                       auto const from = content->position() + std::max(DCPTime(), DCPTime::from_frames(offset_from_start - trim_start, frame_rate));
+                       if (dcp->reference_video()) {
+                               maybe_add_asset (reel_assets, reel->main_picture(), reel_trim_start, reel_trim_end, from, frame_rate);
+                       }
+
+                       if (dcp->reference_audio()) {
+                               maybe_add_asset (reel_assets, reel->main_sound(), reel_trim_start, reel_trim_end, from, frame_rate);
+                       }
+
+                       if (dcp->reference_text(TextType::OPEN_SUBTITLE)) {
+                               maybe_add_asset (reel_assets, reel->main_subtitle(), reel_trim_start, reel_trim_end, from, frame_rate);
+                       }
+
+                       if (dcp->reference_text(TextType::CLOSED_CAPTION)) {
+                               for (auto caption: reel->closed_captions()) {
+                                       maybe_add_asset (reel_assets, caption, reel_trim_start, reel_trim_end, from, frame_rate);
+                               }
+                       }
+
+                       offset_from_start += reel_duration;
+                       offset_from_end -= reel_duration;
+               }
+       }
+
+       return reel_assets;
+}
+
index 813d3214864f44c2331ad2711f6441530ed70c07..23da7c028663c7d8b7c18ff901612810831b0b41 100644 (file)
 
 */
 
+
 #ifndef DCPOMATIC_REFERENCED_REEL_ASSET_H
 #define DCPOMATIC_REFERENCED_REEL_ASSET_H
 
+
+#include "dcpomatic_time.h"
 #include <dcp/reel_asset.h>
 
+
+class Film;
+class Playlist;
+
+
 class ReferencedReelAsset
 {
 public:
@@ -37,4 +45,8 @@ public:
        dcpomatic::DCPTimePeriod period;
 };
 
+
+std::list<ReferencedReelAsset> get_referenced_reel_assets(std::shared_ptr<const Film> film, std::shared_ptr<const Playlist> playlist);
+
+
 #endif
index b566a960cf977b6f7273c1d6a30ccaa3c8a2c264..55c4e735f76e7e2e3344fc41bcfca8e6808ac91f 100644 (file)
@@ -152,6 +152,7 @@ sources = """
           ratio.cc
           raw_image_proxy.cc
           reel_writer.cc
+          referenced_reel_asset.cc
           release_notes.cc
           render_text.cc
           resampler.cc
index f3ba156a10518454f66eb85dcb0a2704b08bbbff..32e7ae431c90062d88c877af76b62a68ccad0f80 100644 (file)
@@ -291,8 +291,7 @@ BOOST_AUTO_TEST_CASE (vf_test5)
        make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
 
        /* Check that the selected reel assets are right */
-       auto player = make_shared<Player>(vf, Image::Alignment::COMPACT);
-       auto a = player->get_reel_assets();
+       auto a = get_referenced_reel_assets(vf, vf->playlist());
        BOOST_REQUIRE_EQUAL (a.size(), 4U);
        auto i = a.begin();
        BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));