summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-09-10 19:09:07 +0200
committerCarl Hetherington <cth@carlh.net>2022-09-10 23:21:06 +0200
commitc8bd4ead4c9e757d88136a7fdd556272f36be793 (patch)
tree49bfb830af2b179c48c68c577dfaea7b60eec051
parent1c09ae94a4b94395ce2c13020a71526a65b9ce7e (diff)
Move get_reel_assets() out of Player, as it doesn't need to be there.
-rw-r--r--src/lib/dcp_encoder.cc2
-rw-r--r--src/lib/player.cc93
-rw-r--r--src/lib/player.h2
-rw-r--r--src/lib/referenced_reel_asset.cc136
-rw-r--r--src/lib/referenced_reel_asset.h12
-rw-r--r--src/lib/wscript1
-rw-r--r--test/vf_test.cc3
7 files changed, 152 insertions, 97 deletions
diff --git a/src/lib/dcp_encoder.cc b/src/lib/dcp_encoder.cc
index e3443c1ad..e4cb76d79 100644
--- a/src/lib/dcp_encoder.cc
+++ b/src/lib/dcp_encoder.cc
@@ -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);
}
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 2793bd62a..13cd8f11b 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -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 ()
{
diff --git a/src/lib/player.h b/src/lib/player.h
index 31628941f..e07cc8200 100644
--- a/src/lib/player.h
+++ b/src/lib/player.h
@@ -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
index 000000000..bd87b905a
--- /dev/null
+++ b/src/lib/referenced_reel_asset.cc
@@ -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;
+}
+
diff --git a/src/lib/referenced_reel_asset.h b/src/lib/referenced_reel_asset.h
index 813d32148..23da7c028 100644
--- a/src/lib/referenced_reel_asset.h
+++ b/src/lib/referenced_reel_asset.h
@@ -18,11 +18,19 @@
*/
+
#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
diff --git a/src/lib/wscript b/src/lib/wscript
index b566a960c..55c4e735f 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -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
diff --git a/test/vf_test.cc b/test/vf_test.cc
index f3ba156a1..32e7ae431 100644
--- a/test/vf_test.cc
+++ b/test/vf_test.cc
@@ -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)));