- /* 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));
-
- shared_ptr<FFmpegContent> ref = dynamic_pointer_cast<FFmpegContent> (c[0]);
+ auto i = c.begin ();
+
+ bool need_video = false;
+ bool need_audio = false;
+ bool need_text = false;
+
+ if (i != c.end ()) {
+ need_video = static_cast<bool> ((*i)->video);
+ need_audio = static_cast<bool> ((*i)->audio);
+ need_text = !(*i)->text.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_text != !(*i)->text.empty()) {
+ throw JoinError (_("Content to be joined must all have or not have subtitles or captions"));
+ }
+ ++i;
+ }
+
+ if (need_video) {
+ video = make_shared<VideoContent>(this, c);
+ }
+ if (need_audio) {
+ audio = make_shared<AudioContent>(this, c);
+ }
+ if (need_text) {
+ text.push_back (make_shared<TextContent>(this, c));
+ }
+
+ auto ref = dynamic_pointer_cast<FFmpegContent> (c[0]);