Fix loading of SMPTE subtitles that are not MXF-wrapped.
authorCarl Hetherington <cth@carlh.net>
Sun, 4 Jan 2015 01:13:13 +0000 (01:13 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 4 Jan 2015 01:13:13 +0000 (01:13 +0000)
ChangeLog
src/lib/content_factory.cc
src/lib/dcp_subtitle.cc [new file with mode: 0644]
src/lib/dcp_subtitle.h [new file with mode: 0644]
src/lib/dcp_subtitle_content.cc
src/lib/dcp_subtitle_content.h
src/lib/dcp_subtitle_decoder.cc
src/lib/dcp_subtitle_decoder.h
src/lib/wscript

index 35c7bfa125db3c449f7791829c5783bdbd3db639..af1878ba291cca2c7319471ec02ce8d2f889ca63 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-04  Carl Hetherington  <cth@carlh.net>
+
+       * Fix loading of SMPTE XML subtitles which
+       are not MXF-wrapped.
+
 2014-12-14  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.0.25 released.
index de940d0252f1651a53e143bdfefffa1e9dc2ef9d..ed00639a08fab7e342edeffe830f753803cda3ae 100644 (file)
@@ -77,7 +77,7 @@ content_factory (shared_ptr<const Film> film, boost::filesystem::path path)
 
        string ext = path.extension().string ();
        transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
-               
+
        if (valid_image_file (path)) {
                content.reset (new ImageContent (film, path));
        } else if (SndfileContent::valid_file (path)) {
@@ -86,7 +86,18 @@ content_factory (shared_ptr<const Film> film, boost::filesystem::path path)
                content.reset (new SubRipContent (film, path));
        } else if (ext == ".xml") {
                content.reset (new DCPSubtitleContent (film, path));
-       } else {
+       } else if (ext == ".mxf") {
+               /* Try to read this .mxf as a subtitle file; if we fail, we fall back
+                  to using FFmpeg below.
+               */
+               try {
+                       content.reset (new DCPSubtitleContent (film, path));
+               } catch (...) {
+
+               }
+       }
+
+       if (!content) {
                content.reset (new FFmpegContent (film, path));
        }
 
diff --git a/src/lib/dcp_subtitle.cc b/src/lib/dcp_subtitle.cc
new file mode 100644 (file)
index 0000000..17874c2
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+    Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "dcp_subtitle.h"
+#include "exceptions.h"
+#include <dcp/interop_subtitle_content.h>
+#include <dcp/smpte_subtitle_content.h>
+
+#include "i18n.h"
+
+using boost::shared_ptr;
+
+shared_ptr<dcp::SubtitleContent>
+DCPSubtitle::load (boost::filesystem::path file) const
+{
+       shared_ptr<dcp::SubtitleContent> sc;
+       
+       try {
+               sc.reset (new dcp::InteropSubtitleContent (file));
+       } catch (...) {
+               
+       }
+
+       if (!sc) {
+               try {
+                       sc.reset (new dcp::SMPTESubtitleContent (file, true));
+               } catch (...) {
+
+               }
+       }
+
+       if (!sc) {
+               try {
+                       sc.reset (new dcp::SMPTESubtitleContent (file, false));
+               } catch (...) {
+
+               }
+       }
+
+       if (!sc) {
+               throw FileError (_("Could not read subtitles"), file);
+       }
+
+       return sc;
+}
diff --git a/src/lib/dcp_subtitle.h b/src/lib/dcp_subtitle.h
new file mode 100644 (file)
index 0000000..e15acca
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+    Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef DCPOMATIC_SRC_LIB_DCP_SUBTITLE_H
+#define DCPOMATIC_SRC_LIB_DCP_SUBTITLE_H
+
+#include <boost/shared_ptr.hpp>
+#include <boost/filesystem.hpp>
+
+namespace dcp {
+       class SubtitleContent;
+}
+
+class DCPSubtitle
+{
+protected:
+       boost::shared_ptr<dcp::SubtitleContent> load (boost::filesystem::path) const;
+};
+
+#endif
index e814946f4ca1e58d6ee7fcd4791ae25713838782..45c4be9b21bad8e8148154ad4491f0d345e3d4f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
 #include "font.h"
 #include "dcp_subtitle_content.h"
 #include <dcp/interop_subtitle_content.h>
+#include <dcp/smpte_subtitle_content.h>
 #include <dcp/interop_load_font.h>
 #include <dcp/raw_convert.h>
 
@@ -49,16 +50,16 @@ void
 DCPSubtitleContent::examine (shared_ptr<Job> job, bool calculate_digest)
 {
        Content::examine (job, calculate_digest);
-       
-       dcp::InteropSubtitleContent sc (path (0));
 
+       shared_ptr<dcp::SubtitleContent> sc = load (path (0));
+       
        boost::mutex::scoped_lock lm (_mutex);
        
-       _subtitle_language = sc.language ();
-       _length = DCPTime::from_seconds (sc.latest_subtitle_out().to_seconds ());
+       _subtitle_language = sc->language ();
+       _length = DCPTime::from_seconds (sc->latest_subtitle_out().to_seconds ());
 
-       list<shared_ptr<dcp::InteropLoadFont> > fonts = sc.load_font_nodes ();
-       for (list<shared_ptr<dcp::InteropLoadFont> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
+       list<shared_ptr<dcp::LoadFont> > fonts = sc->load_font_nodes ();
+       for (list<shared_ptr<dcp::LoadFont> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
                _fonts.push_back (shared_ptr<Font> (new Font ((*i)->id)));
        }
 }
index e1a0b64908dfa9e3126b97dccc889262da7cc1c9..4b5f1fa058f070fe4c71c9052f4d538600f74f38 100644 (file)
@@ -18,8 +18,9 @@
 */
 
 #include "subtitle_content.h"
+#include "dcp_subtitle.h"
 
-class DCPSubtitleContent : public SubtitleContent
+class DCPSubtitleContent : public SubtitleContent, public DCPSubtitle
 {
 public:
        DCPSubtitleContent (boost::shared_ptr<const Film>, boost::filesystem::path);
index 2a9b52869ce770693f85cb44e8ac7e9d1af78a22..e3c06378b8eabd86216d8f08394e1db57152fab6 100644 (file)
@@ -28,8 +28,8 @@ using boost::shared_ptr;
 DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const DCPSubtitleContent> content)
        : SubtitleDecoder (content)
 {
-       dcp::InteropSubtitleContent c (content->path (0));
-       _subtitles = c.subtitles ();
+       shared_ptr<dcp::SubtitleContent> c (load (content->path (0)));
+       _subtitles = c->subtitles ();
        _next = _subtitles.begin ();
 }
 
index 070562458b64d396468728892c438027637756bc..2326b31ad8098afdfb6fa96135b0872732208771 100644 (file)
 */
 
 #include "subtitle_decoder.h"
+#include "dcp_subtitle.h"
 
 class DCPSubtitleContent;
 
-class DCPSubtitleDecoder : public SubtitleDecoder
+class DCPSubtitleDecoder : public SubtitleDecoder, public DCPSubtitle
 {
 public:
        DCPSubtitleDecoder (boost::shared_ptr<const DCPSubtitleContent>);
index 7d68959494d7631c88a218219962ea75c9c626c3..e3c8def4e77705eba36e24a655b1cf08e946d84b 100644 (file)
@@ -22,6 +22,7 @@ sources = """
           dcp_content_type.cc
           dcp_decoder.cc
           dcp_examiner.cc
+          dcp_subtitle.cc
           dcp_subtitle_content.cc
           dcp_subtitle_decoder.cc
           dcp_video.cc