From 406cf117093a42e9a6c994cc34719869eba77caa Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 30 Jun 2016 22:15:43 +0100 Subject: [PATCH] Fix for crash(es) when joining content. --- src/lib/ffmpeg_content.cc | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index b34fdf6aa..7416630c1 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -119,22 +119,50 @@ FFmpegContent::FFmpegContent (shared_ptr film, cxml::ConstNodePtr no } -FFmpegContent::FFmpegContent (shared_ptr film, vector > c) +FFmpegContent::FFmpegContent (shared_ptr film, vector > c) : Content (film, c) { - /* XXX: this should look at c to decide which of video/audio/subtitle - get created. - */ - video.reset (new VideoContent (this, c)); - audio.reset (new AudioContent (this, c)); - subtitle.reset (new SubtitleContent (this, c)); + vector >::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 ((*i)->video); + need_audio = static_cast ((*i)->audio); + need_subtitle = static_cast ((*i)->subtitle); + } + + while (i != c.end ()) { + if (need_video != static_cast ((*i)->video)) { + throw JoinError (_("Content to be joined must all have or not have video")); + } + if (need_audio != static_cast ((*i)->audio)) { + throw JoinError (_("Content to be joined must all have or not have audio")); + } + if (need_subtitle != static_cast ((*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 SubtitleContent (this, c)); + } shared_ptr ref = dynamic_pointer_cast (c[0]); DCPOMATIC_ASSERT (ref); for (size_t i = 0; i < c.size(); ++i) { shared_ptr fc = dynamic_pointer_cast (c[i]); - if (fc->subtitle->use() && *(fc->_subtitle_stream.get()) != *(ref->_subtitle_stream.get())) { + 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.")); } } -- 2.30.2