Put Time types in dcpomatic namespace.
[dcpomatic.git] / src / lib / reel_writer.cc
index 3b9e413a23f47c1b00c3f92b2fffbf9ec769d38d..81057185aea935c24c01ce96f20b53d2c97630b4 100644 (file)
@@ -39,6 +39,7 @@
 #include <dcp/reel_sound_asset.h>
 #include <dcp/reel_subtitle_asset.h>
 #include <dcp/reel_closed_caption_asset.h>
+#include <dcp/reel_markers_asset.h>
 #include <dcp/dcp.h>
 #include <dcp/cpl.h>
 #include <dcp/certificate_chain.h>
@@ -59,6 +60,7 @@ using boost::optional;
 using boost::dynamic_pointer_cast;
 using dcp::Data;
 using dcp::raw_convert;
+using namespace dcpomatic;
 
 int const ReelWriter::_info_size = 48;
 
@@ -407,10 +409,10 @@ maybe_add_text (
        }
 
        if (reel_asset) {
-               if (reel_asset->duration() != period_duration) {
+               if (reel_asset->actual_duration() != period_duration) {
                        throw ProgrammingError (
                                __FILE__, __LINE__,
-                               String::compose ("%1 vs %2", reel_asset->duration(), period_duration)
+                               String::compose ("%1 vs %2", reel_asset->actual_duration(), period_duration)
                                );
                }
                reel->add (reel_asset);
@@ -459,7 +461,7 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr
        if (reel_picture_asset->duration() != period_duration) {
                throw ProgrammingError (
                        __FILE__, __LINE__,
-                       String::compose ("%1 vs %2", reel_picture_asset->duration(), period_duration)
+                       String::compose ("%1 vs %2", reel_picture_asset->actual_duration(), period_duration)
                        );
        }
        reel->add (reel_picture_asset);
@@ -489,31 +491,50 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr
        }
 
        DCPOMATIC_ASSERT (reel_sound_asset);
-       if (reel_sound_asset->duration() != period_duration) {
+       if (reel_sound_asset->actual_duration() != period_duration) {
                LOG_ERROR (
                        "Reel sound asset has length %1 but reel period is %2",
-                       reel_sound_asset->duration(),
+                       reel_sound_asset->actual_duration(),
                        period_duration
                        );
-               if (reel_sound_asset->duration() != period_duration) {
+               if (reel_sound_asset->actual_duration() != period_duration) {
                        throw ProgrammingError (
                                __FILE__, __LINE__,
-                               String::compose ("%1 vs %2", reel_sound_asset->duration(), period_duration)
+                               String::compose ("%1 vs %2", reel_sound_asset->actual_duration(), period_duration)
                                );
                }
 
        }
        reel->add (reel_sound_asset);
 
-       maybe_add_text<dcp::ReelSubtitleAsset> (_subtitle_asset, reel_picture_asset->duration(), reel, refs, fonts, _film, _period);
+       maybe_add_text<dcp::ReelSubtitleAsset> (_subtitle_asset, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period);
        for (map<DCPTextTrack, shared_ptr<dcp::SubtitleAsset> >::const_iterator i = _closed_caption_assets.begin(); i != _closed_caption_assets.end(); ++i) {
                shared_ptr<dcp::ReelClosedCaptionAsset> a = maybe_add_text<dcp::ReelClosedCaptionAsset> (
-                       i->second, reel_picture_asset->duration(), reel, refs, fonts, _film, _period
+                       i->second, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period
                        );
                a->set_annotation_text (i->first.name);
                a->set_language (i->first.language);
        }
 
+       map<dcp::Marker, DCPTime> markers = _film->markers ();
+       map<dcp::Marker, DCPTime> reel_markers;
+       for (map<dcp::Marker, DCPTime>::const_iterator i = markers.begin(); i != markers.end(); ++i) {
+               if (_period.contains(i->second)) {
+                       reel_markers[i->first] = i->second;
+               }
+       }
+
+       if (!reel_markers.empty ()) {
+               shared_ptr<dcp::ReelMarkersAsset> ma (new dcp::ReelMarkersAsset(dcp::Fraction(_film->video_frame_rate(), 1), 0));
+               for (map<dcp::Marker, DCPTime>::const_iterator i = reel_markers.begin(); i != reel_markers.end(); ++i) {
+                       int h, m, s, f;
+                       DCPTime relative = i->second - _period.from;
+                       relative.split (_film->video_frame_rate(), h, m, s, f);
+                       ma->set (i->first, dcp::Time(h, m, s, f, _film->video_frame_rate()));
+               }
+               reel->add (ma);
+       }
+
        return reel;
 }