Basics of multiple captions per content so that DCPContent can
[dcpomatic.git] / src / lib / ffmpeg_content.cc
index e18977944648fc1faff37e83987d8018a63fe473..ddf4548b41959fe1c8eac9ea304a9d85da77c201 100644 (file)
@@ -32,7 +32,7 @@
 #include "log.h"
 #include "exceptions.h"
 #include "frame_rate_change.h"
-#include "text_content.h"
+#include "caption_content.h"
 #include <dcp/raw_convert.h>
 #include <libcxml/cxml.h>
 extern "C" {
@@ -85,7 +85,7 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> film, cxml::ConstNodePtr no
 {
        video = VideoContent::from_xml (this, node, version);
        audio = AudioContent::from_xml (this, node, version);
-       subtitle = TextContent::from_xml (this, node, version);
+       caption = CaptionContent::from_xml (this, node, version);
 
        list<cxml::NodePtr> c = node->node_children ("SubtitleStream");
        for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
@@ -128,67 +128,6 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> film, cxml::ConstNodePtr no
 
 }
 
-FFmpegContent::FFmpegContent (shared_ptr<const Film> film, vector<shared_ptr<Content> > c)
-       : Content (film, c)
-{
-       vector<shared_ptr<Content> >::const_iterator i = c.begin ();
-
-       bool need_video = false;
-       bool need_audio = false;
-       bool need_subtitle = false;
-
-       if (i != c.end ()) {
-               need_video = static_cast<bool> ((*i)->video);
-               need_audio = static_cast<bool> ((*i)->audio);
-               need_subtitle = static_cast<bool> ((*i)->subtitle);
-       }
-
-       while (i != c.end ()) {
-               if (need_video != static_cast<bool> ((*i)->video)) {
-                       throw JoinError (_("Content to be joined must all have or not have video"));
-               }
-               if (need_audio != static_cast<bool> ((*i)->audio)) {
-                       throw JoinError (_("Content to be joined must all have or not have audio"));
-               }
-               if (need_subtitle != static_cast<bool> ((*i)->subtitle)) {
-                       throw JoinError (_("Content to be joined must all have or not have subtitles"));
-               }
-               ++i;
-       }
-
-       if (need_video) {
-               video.reset (new VideoContent (this, c));
-       }
-       if (need_audio) {
-               audio.reset (new AudioContent (this, c));
-       }
-       if (need_subtitle) {
-               subtitle.reset (new TextContent (this, c));
-       }
-
-       shared_ptr<FFmpegContent> ref = dynamic_pointer_cast<FFmpegContent> (c[0]);
-       DCPOMATIC_ASSERT (ref);
-
-       for (size_t i = 0; i < c.size(); ++i) {
-               shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c[i]);
-               if (fc->subtitle && fc->subtitle->use() && *(fc->_subtitle_stream.get()) != *(ref->_subtitle_stream.get())) {
-                       throw JoinError (_("Content to be joined must use the same subtitle stream."));
-               }
-       }
-
-       /* XXX: should probably check that more of the stuff below is the same in *this and ref */
-
-       _subtitle_streams = ref->subtitle_streams ();
-       _subtitle_stream = ref->subtitle_stream ();
-       _first_video = ref->_first_video;
-       _filters = ref->_filters;
-       _color_range = ref->_color_range;
-       _color_primaries = ref->_color_primaries;
-       _color_trc = ref->_color_trc;
-       _colorspace = ref->_colorspace;
-       _bits_per_pixel = ref->_bits_per_pixel;
-}
-
 void
 FFmpegContent::as_xml (xmlpp::Node* node, bool with_paths) const
 {
@@ -209,8 +148,8 @@ FFmpegContent::as_xml (xmlpp::Node* node, bool with_paths) const
                }
        }
 
-       if (subtitle) {
-               subtitle->as_xml (node);
+       if (only_caption()) {
+               only_caption()->as_xml (node);
        }
 
        boost::mutex::scoped_lock lm (_mutex);
@@ -303,7 +242,8 @@ FFmpegContent::examine (shared_ptr<Job> job)
 
                _subtitle_streams = examiner->subtitle_streams ();
                if (!_subtitle_streams.empty ()) {
-                       subtitle.reset (new TextContent (this));
+                       caption.clear ();
+                       caption.push_back (shared_ptr<CaptionContent> (new CaptionContent (this)));
                        _subtitle_stream = _subtitle_streams.front ();
                }
 
@@ -426,8 +366,8 @@ FFmpegContent::identifier () const
                s += "_" + video->identifier();
        }
 
-       if (subtitle && subtitle->use() && subtitle->burn()) {
-               s += "_" + subtitle->identifier();
+       if (only_caption() && only_caption()->use() && only_caption()->burn()) {
+               s += "_" + only_caption()->identifier();
        }
 
        boost::mutex::scoped_lock lm (_mutex);