Move _intrinsic_duration and _edit_rate up to the MXF class as XML subtitle files...
authorCarl Hetherington <cth@carlh.net>
Thu, 10 Jul 2014 15:16:51 +0000 (16:16 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 10 Jul 2014 15:16:51 +0000 (16:16 +0100)
14 files changed:
src/content.cc
src/content.h
src/dcp.h
src/mxf.cc
src/mxf.h
src/reel_asset.cc
src/reel_asset.h
src/reel_picture_asset.cc
src/reel_sound_asset.cc
src/reel_sound_asset.h
src/reel_subtitle_asset.cc
src/reel_subtitle_asset.h
src/subtitle_content.cc
src/subtitle_content.h

index 995fd920bdf34e09c00ee638350312b3004a8f59..8a654670b69f2c7d15c4597622b89e57d034a1eb 100644 (file)
@@ -33,19 +33,8 @@ using namespace dcp;
 
 Content::Content (boost::filesystem::path file)
        : Asset (file)
-       , _edit_rate (24, 1)
-       , _intrinsic_duration (0)
 {
-       /* Note: the _edit_rate and _intrinsic_duration above are just defaults,
-          the derived class must set these up according to `file'.
-       */
-}
-
-Content::Content (Fraction edit_rate)
-       : _edit_rate (edit_rate)
-       , _intrinsic_duration (0)
-{
-
+       
 }
 
 bool
@@ -54,16 +43,6 @@ Content::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::fu
        if (!Asset::equals (other, opt, note)) {
                return false;
        }
-       
-       if (_edit_rate != other->_edit_rate) {
-               note (DCP_ERROR, "content edit rates differ");
-               return false;
-       }
-       
-       if (_intrinsic_duration != other->_intrinsic_duration) {
-               note (DCP_ERROR, "asset intrinsic durations differ");
-               return false;
-       }
 
        return true;
 }
index 4bc21570bd0dc3c35ec6509b615ba28445b2ea53..cf92f5365a45241b509c80463459aea26d2be372 100644 (file)
@@ -51,43 +51,21 @@ namespace dcp
 class Content : public Asset
 {
 public:
+       Content () {}
+       
        /** Construct a Content object by reading a file.
         *  @param file File to read.
         */
        Content (boost::filesystem::path file);
 
-       /** Construct a new piece of content with a specified edit rate.
-        *  @param edit_rate Edit rate for the content.
-        */
-       Content (Fraction edit_rate);
-       
        bool equals (
                boost::shared_ptr<const Content> other,
                EqualityOptions opt,
                boost::function<void (NoteType, std::string)>
                ) const;
 
-       Fraction edit_rate () const {
-               return _edit_rate;
-       }
-
-       /** @return The total length of this content in video frames.
-        *  The amount of content presented may be less than this.
-        */
-       int64_t intrinsic_duration () const {
-               return _intrinsic_duration;
-       }
-
 protected:
-       friend class MXFWriter;
-
        virtual std::string asdcp_kind () const = 0;
-       
-       Fraction _edit_rate;
-       /** The total length of this content in video frames.  The amount of
-        *  content presented may be less than this.
-        */
-       int64_t _intrinsic_duration;
 };
 
 }
index 0ff7a9fd4c35f6f26e85ad6e4e7b6d35028c49ca..3d42b92a91f3f72cab836f4d57e7926092bbed35 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -62,8 +62,8 @@ class DCP : public boost::noncopyable
 {
 public:
        /** Construct a DCP.  You can pass an existing DCP's directory
-        *  as the parameter, or an empty folder to create a new
-        *  DCP in.
+        *  as the parameter; alternatively, directory will be created
+        *  if it does not exist.
         *
         *  @param directory Directory containing the DCP's files.
         */
index def53c15b9c21512965b5fcbf00ffec97b7813d8..f5282f1c5f46e27ca740654afa6300dafa2075b9 100644 (file)
@@ -42,19 +42,21 @@ using boost::dynamic_pointer_cast;
 using namespace dcp;
 
 MXF::MXF (Fraction edit_rate)
-       : Content (edit_rate)
+       : _edit_rate (edit_rate)
+       , _intrinsic_duration (0)
        , _encryption_context (0)
        , _decryption_context (0)
 {
-
+       /* _intrinsic_duration must be set up up by a subclass */
 }
 
 MXF::MXF (boost::filesystem::path file)
        : Content (file)
+       , _intrinsic_duration (0)
        , _encryption_context (0)
        , _decryption_context (0)
 {
-
+       /* _edit_rate and _intrinsic_duration must be set up up by a subclass */
 }
 
 MXF::~MXF ()
@@ -102,6 +104,16 @@ MXF::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::functi
                return false;
        }
        
+       if (_edit_rate != other_mxf->_edit_rate) {
+               note (DCP_ERROR, "content edit rates differ");
+               return false;
+       }
+       
+       if (_intrinsic_duration != other_mxf->_intrinsic_duration) {
+               note (DCP_ERROR, "asset intrinsic durations differ");
+               return false;
+       }
+
        if (_file != other_mxf->file ()) {
                note (DCP_ERROR, "MXF names differ");
                if (!opt.mxf_names_can_differ) {
index c5ecd1b74f18cc22cfca7df9325347c4bb6838cd..4fbc14952a17d1a893e5adaa9f8ed04605246f46 100644 (file)
--- a/src/mxf.h
+++ b/src/mxf.h
@@ -105,10 +105,29 @@ public:
                return _metadata;
        }
 
+       Fraction edit_rate () const {
+               return _edit_rate;
+       }
+
+       /** @return The total length of this content in video frames.
+        *  The amount of content presented may be less than this.
+        */
+       int64_t intrinsic_duration () const {
+               return _intrinsic_duration;
+       }
+       
 protected:
+       friend class MXFWriter;
+
        std::string pkl_type (Standard standard) const;
        void read_writer_info (ASDCP::WriterInfo const &);
        
+       Fraction _edit_rate;
+       /** The total length of this content in video frames.  The amount of
+        *  content presented may be less than this.
+        */
+       int64_t _intrinsic_duration;
+       
        ASDCP::AESEncContext* _encryption_context;
        ASDCP::AESDecContext* _decryption_context;
        /** ID of the key used for encryption/decryption, or an empty string */
index 7987a1554f77c374c993bfcb0bb843a27bb25470..cbb76dd8d28a5f947a92f3596c479472b7ce41f7 100644 (file)
@@ -42,15 +42,17 @@ ReelAsset::ReelAsset ()
 
 /** Construct a ReelAsset.
  *  @param content Content that this asset refers to.
+ *  @param edit_rate Edit rate for the content.
+ *  @param intrinsic_duration Intrinsic duration of this content.
  *  @param entry_point Entry point to use in that content.
  */
-ReelAsset::ReelAsset (boost::shared_ptr<Content> content, int64_t entry_point)
+ReelAsset::ReelAsset (boost::shared_ptr<Content> content, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
        : Object (content->id ())
        , _content (content)
-       , _edit_rate (content->edit_rate ())
-       , _intrinsic_duration (content->intrinsic_duration ())
+       , _edit_rate (edit_rate)
+       , _intrinsic_duration (intrinsic_duration)
        , _entry_point (entry_point)
-       , _duration (_intrinsic_duration - _entry_point)
+       , _duration (intrinsic_duration - entry_point)
        , _hash (make_digest (content->file (), 0))
 {
        /* default _annotation_text to the leaf name of our file */
index d2ea56bfa2a62cc8ae893825ceff1f0786c75698..40eb6986f975aeb27c7b9c69527b9a0ac359cb74 100644 (file)
@@ -48,7 +48,7 @@ class ReelAsset : public Object
 {
 public:
        ReelAsset ();
-       ReelAsset (boost::shared_ptr<Content> content, int64_t entry_point);
+       ReelAsset (boost::shared_ptr<Content> content, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point);
        ReelAsset (boost::shared_ptr<const cxml::Node>);
 
        virtual void write_to_cpl (xmlpp::Node* node, Standard standard) const;
index 1a3d47b99e40240c2d79947e3ad703679c1c011e..344f7019cb28f708221573468a9c33e2803c6f60 100644 (file)
@@ -42,7 +42,7 @@ ReelPictureAsset::ReelPictureAsset ()
 }
 
 ReelPictureAsset::ReelPictureAsset (boost::shared_ptr<PictureMXF> content, int64_t entry_point)
-       : ReelAsset (content, entry_point)
+       : ReelAsset (content, content->edit_rate(), content->intrinsic_duration(), entry_point)
        , _frame_rate (content->frame_rate ())
        , _screen_aspect_ratio (content->screen_aspect_ratio ())
 {
index 984434ddc26d93b8a49c59ac1f3309e8451afa8e..c9af664c6c6bbe0916018cef6f54954bfe94ee91 100644 (file)
@@ -28,8 +28,8 @@ using std::string;
 using boost::shared_ptr;
 using namespace dcp;
 
-ReelSoundAsset::ReelSoundAsset (boost::shared_ptr<Content> content, int64_t entry_point)
-       : ReelAsset (content, entry_point)
+ReelSoundAsset::ReelSoundAsset (boost::shared_ptr<SoundMXF> content, int64_t entry_point)
+       : ReelAsset (content, content->edit_rate(), content->intrinsic_duration(), entry_point)
 {
 
 }
index 42835c848f192652065db6f0b46368a184b68854..7725c6158bc1337760a202b16a81b5edc7c5811e 100644 (file)
@@ -34,7 +34,7 @@ namespace dcp {
 class ReelSoundAsset : public ReelAsset
 {
 public:
-       ReelSoundAsset (boost::shared_ptr<Content> content, int64_t entry_point);
+       ReelSoundAsset (boost::shared_ptr<dcp::SoundMXF> content, int64_t entry_point);
        ReelSoundAsset (boost::shared_ptr<const cxml::Node>);
 
        boost::shared_ptr<SoundMXF> mxf () {
index 1c948200ac97edd7ccc6152a018746fce7357680..139e3a39bf055ee2d2f3bfa4322365c5d23e5088 100644 (file)
@@ -28,8 +28,8 @@ using std::string;
 using boost::shared_ptr;
 using namespace dcp;
 
-ReelSubtitleAsset::ReelSubtitleAsset (boost::shared_ptr<SubtitleContent> content, int64_t entry_point)
-       : ReelAsset (content, entry_point)
+ReelSubtitleAsset::ReelSubtitleAsset (boost::shared_ptr<SubtitleContent> content, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
+       : ReelAsset (content, edit_rate, intrinsic_duration, entry_point)
 {
 
 }
index 5cdfac13a4d5a62417a70a061779e6b6fe1b8358..0f0cf5faccaca018b4995e21dd725880ee478e62 100644 (file)
@@ -36,7 +36,7 @@ class SubtitleContent;
 class ReelSubtitleAsset : public ReelAsset
 {
 public:
-       ReelSubtitleAsset (boost::shared_ptr<SubtitleContent> content, int64_t entry_point);
+       ReelSubtitleAsset (boost::shared_ptr<SubtitleContent> content, Fraction edit_rate, int64_t instrinsic_duration, int64_t entry_point);
        ReelSubtitleAsset (boost::shared_ptr<const cxml::Node>);
 
        boost::shared_ptr<SubtitleContent> subtitle_content () const {
index 85a4b3609f483c1aadc93f9d29283daf20c76c1e..12ed2afcbd7222b0d9069251b041975ab7b009f3 100644 (file)
@@ -43,7 +43,6 @@ using namespace dcp;
 
 SubtitleContent::SubtitleContent (boost::filesystem::path file, bool mxf)
        : Content (file)
-       , _need_sort (false)
 {
        shared_ptr<cxml::Document> xml;
        
@@ -99,12 +98,10 @@ SubtitleContent::SubtitleContent (boost::filesystem::path file, bool mxf)
        examine_font_nodes (xml, font_nodes, parse_state);
 }
 
-SubtitleContent::SubtitleContent (Fraction edit_rate, string movie_title, string language)
-       : Content (edit_rate)
-       , _movie_title (movie_title)
+SubtitleContent::SubtitleContent (string movie_title, string language)
+       : _movie_title (movie_title)
        , _reel_number ("1")
        , _language (language)
-       , _need_sort (false)
 {
 
 }
@@ -223,7 +220,6 @@ void
 SubtitleContent::add (SubtitleString s)
 {
        _subtitles.push_back (s);
-       _need_sort = true;
 }
 
 struct SubtitleSorter {
@@ -277,9 +273,7 @@ SubtitleContent::xml_as_string () const
        }
 
        list<SubtitleString> sorted = _subtitles;
-       if (_need_sort) {
-               sorted.sort (SubtitleSorter ());
-       }
+       sorted.sort (SubtitleSorter ());
 
        /* XXX: multiple fonts not supported */
        /* XXX: script, underlined, weight not supported */
@@ -366,3 +360,15 @@ SubtitleContent::xml_as_string () const
        return doc.write_to_string_formatted ("UTF-8");
 }
 
+Time
+SubtitleContent::latest_subtitle_out () const
+{
+       Time t;
+       for (list<SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
+               if (i->out() > t) {
+                       t = i->out ();
+               }
+       }
+
+       return t;
+}
index c00c3f310a650197e3abf502c1d3327b14156d40..b05fe59c51aeda5034a290fcd41d6b413d8687ef 100644 (file)
@@ -48,7 +48,7 @@ public:
         *  @param mxf true if the file is an MXF file, false for XML.
         */
        SubtitleContent (boost::filesystem::path file, bool mxf);
-       SubtitleContent (Fraction edit_rate, std::string movie_title, std::string language);
+       SubtitleContent (std::string movie_title, std::string language);
 
        bool equals (
                boost::shared_ptr<const Content>,
@@ -74,6 +74,8 @@ public:
        void write_xml (boost::filesystem::path) const;
        Glib::ustring xml_as_string () const;
 
+       Time latest_subtitle_out () const;
+
 protected:
        std::string pkl_type (Standard) const {
                return "text/xml";
@@ -113,7 +115,6 @@ private:
        std::list<boost::shared_ptr<LoadFont> > _load_font_nodes;
 
        std::list<SubtitleString> _subtitles;
-       bool _need_sort;
 };
 
 }