summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-04 01:13:13 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-04 01:13:13 +0000
commit8af00f5e0862c18e8c7b5f9ac0ea95a5d6ad696c (patch)
tree925d0673ec1c3319a8cc85374acb14a27d555c60 /src
parenta5095486e606adfe36de635a48710cf98872c1c6 (diff)
Fix loading of SMPTE subtitles that are not MXF-wrapped.
Diffstat (limited to 'src')
-rw-r--r--src/lib/content_factory.cc15
-rw-r--r--src/lib/dcp_subtitle.cc61
-rw-r--r--src/lib/dcp_subtitle.h36
-rw-r--r--src/lib/dcp_subtitle_content.cc15
-rw-r--r--src/lib/dcp_subtitle_content.h3
-rw-r--r--src/lib/dcp_subtitle_decoder.cc4
-rw-r--r--src/lib/dcp_subtitle_decoder.h3
-rw-r--r--src/lib/wscript1
8 files changed, 125 insertions, 13 deletions
diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc
index de940d025..ed00639a0 100644
--- a/src/lib/content_factory.cc
+++ b/src/lib/content_factory.cc
@@ -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
index 000000000..17874c27e
--- /dev/null
+++ b/src/lib/dcp_subtitle.cc
@@ -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
index 000000000..e15acca44
--- /dev/null
+++ b/src/lib/dcp_subtitle.h
@@ -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
diff --git a/src/lib/dcp_subtitle_content.cc b/src/lib/dcp_subtitle_content.cc
index e814946f4..45c4be9b2 100644
--- a/src/lib/dcp_subtitle_content.cc
+++ b/src/lib/dcp_subtitle_content.cc
@@ -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)));
}
}
diff --git a/src/lib/dcp_subtitle_content.h b/src/lib/dcp_subtitle_content.h
index e1a0b6490..4b5f1fa05 100644
--- a/src/lib/dcp_subtitle_content.h
+++ b/src/lib/dcp_subtitle_content.h
@@ -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);
diff --git a/src/lib/dcp_subtitle_decoder.cc b/src/lib/dcp_subtitle_decoder.cc
index 2a9b52869..e3c06378b 100644
--- a/src/lib/dcp_subtitle_decoder.cc
+++ b/src/lib/dcp_subtitle_decoder.cc
@@ -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 ();
}
diff --git a/src/lib/dcp_subtitle_decoder.h b/src/lib/dcp_subtitle_decoder.h
index 070562458..2326b31ad 100644
--- a/src/lib/dcp_subtitle_decoder.h
+++ b/src/lib/dcp_subtitle_decoder.h
@@ -18,10 +18,11 @@
*/
#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>);
diff --git a/src/lib/wscript b/src/lib/wscript
index 7d6895949..e3c8def4e 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -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