Display only required tabs, including subs / ccap.
[dcpomatic.git] / src / lib / ffmpeg_content.cc
index ddf4548b41959fe1c8eac9ea304a9d85da77c201..3f0a692cdd646f7e08444920ebc7e03eaea114d6 100644 (file)
@@ -128,6 +128,67 @@ 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_caption = false;
+
+       if (i != c.end ()) {
+               need_video = static_cast<bool> ((*i)->video);
+               need_audio = static_cast<bool> ((*i)->audio);
+               need_caption = !(*i)->caption.empty();
+       }
+
+       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_caption != !(*i)->caption.empty()) {
+                       throw JoinError (_("Content to be joined must all have or not have captions"));
+               }
+               ++i;
+       }
+
+       if (need_video) {
+               video.reset (new VideoContent (this, c));
+       }
+       if (need_audio) {
+               audio.reset (new AudioContent (this, c));
+       }
+       if (need_caption) {
+               caption.push_back (shared_ptr<CaptionContent> (new CaptionContent (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->only_caption() && fc->only_caption()->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
 {
@@ -243,7 +304,7 @@ FFmpegContent::examine (shared_ptr<Job> job)
                _subtitle_streams = examiner->subtitle_streams ();
                if (!_subtitle_streams.empty ()) {
                        caption.clear ();
-                       caption.push_back (shared_ptr<CaptionContent> (new CaptionContent (this)));
+                       caption.push_back (shared_ptr<CaptionContent> (new CaptionContent (this, CAPTION_OPEN)));
                        _subtitle_stream = _subtitle_streams.front ();
                }