--- /dev/null
+/*
+ Copyright (C) 2012 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 <iostream>
+#include "dcp_time.h"
+
+using namespace std;
+
+bool
+libdcp::operator== (Time const & a, Time const & b)
+{
+ return (a.h == b.h && a.m == b.m && a.s == b.s && a.ms == b.ms);
+}
+
+ostream &
+libdcp::operator<< (ostream& s, Time const & t)
+{
+ s << t.h << ":" << t.m << ":" << t.s << "." << t.ms;
+ return s;
+}
--- /dev/null
+/*
+ Copyright (C) 2012 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 LIBDCP_TIME_H
+#define LIBDCP_TIME_H
+
+namespace libdcp {
+
+class Time
+{
+public:
+ Time () : h (0), m (0), s (0), ms (0) {}
+ Time (int h_, int m_, int s_, int ms_)
+ : h (h_)
+ , m (m_)
+ , s (s_)
+ , ms (ms_)
+ {}
+
+ int h;
+ int m;
+ int s;
+ int ms;
+};
+
+extern bool operator== (Time const & a, Time const & b);
+extern std::ostream & operator<< (std::ostream & s, Time const & t);
+
+}
+
+#endif
--- /dev/null
+/*
+ Copyright (C) 2012 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.
+
+*/
+
+/** @file src/asset.cc
+ * @brief Parent class for assets of DCPs made up of MXF files.
+ */
+
+#include <iostream>
+#include <fstream>
+#include <boost/filesystem.hpp>
+#include "AS_DCP.h"
+#include "KM_util.h"
+#include "mxf_asset.h"
+#include "util.h"
+#include "metadata.h"
+
+using namespace std;
+using namespace boost;
+using namespace libdcp;
+
+MXFAsset::MXFAsset (string directory, string file_name, sigc::signal1<void, float>* progress, int fps, int length)
+ : Asset (directory, file_name)
+ , _progress (progress)
+ , _fps (fps)
+ , _length (length)
+{
+
+}
+
+void
+MXFAsset::fill_writer_info (ASDCP::WriterInfo* writer_info) const
+{
+ writer_info->ProductVersion = Metadata::instance()->product_version;
+ writer_info->CompanyName = Metadata::instance()->company_name;
+ writer_info->ProductName = Metadata::instance()->product_name.c_str();
+
+ writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
+ unsigned int c;
+ Kumu::hex2bin (_uuid.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
+ assert (c == Kumu::UUID_Length);
+}
+
+list<string>
+MXFAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
+{
+ shared_ptr<const MXFAsset> other_mxf = dynamic_pointer_cast<const MXFAsset> (other);
+ if (!other_mxf) {
+ return list<string> ();
+ }
+
+ list<string> notes;
+
+ if (opt.flags & LIBDCP_METADATA) {
+ if (_file_name != other_mxf->_file_name) {
+ notes.push_back ("MXF names differ");
+ }
+ if (_fps != other_mxf->_fps) {
+ notes.push_back ("MXF frames per second differ");
+ }
+ if (_length != other_mxf->_length) {
+ notes.push_back ("MXF lengths differ");
+ }
+ }
+
+ if (opt.flags & MXF_BITWISE) {
+
+ if (digest() != other_mxf->digest()) {
+ notes.push_back ("MXF digests differ");
+ }
+
+ if (filesystem::file_size (path()) != filesystem::file_size (other_mxf->path())) {
+ notes.push_back (path().string() + " and " + other_mxf->path().string() + " sizes differ");
+ return notes;
+ }
+
+ ifstream a (path().string().c_str(), ios::binary);
+ ifstream b (other_mxf->path().string().c_str(), ios::binary);
+
+ int buffer_size = 65536;
+ char abuffer[buffer_size];
+ char bbuffer[buffer_size];
+
+ int n = filesystem::file_size (path ());
+
+ while (n) {
+ int const t = min (n, buffer_size);
+ a.read (abuffer, t);
+ b.read (bbuffer, t);
+
+ if (memcmp (abuffer, bbuffer, t) != 0) {
+ notes.push_back (path().string() + " and " + other_mxf->path().string() + " content differs");
+ return notes;
+ }
+
+ n -= t;
+ }
+ }
+
+ return notes;
+}
+
+int
+MXFAsset::length () const
+{
+ return _length;
+}
+
+
--- /dev/null
+/*
+ Copyright (C) 2012 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 LIBDCP_MXF_ASSET_H
+#define LIBDCP_MXF_ASSET_H
+
+#include "asset.h"
+
+namespace libdcp
+{
+
+class MXFAsset : public Asset
+{
+public:
+ /** Construct an MXFAsset.
+ * @param directory Directory where MXF file is.
+ * @param mxf_name Name of MXF file.
+ * @param progress Signal to inform of progress.
+ * @param fps Frames per second.
+ * @param length Length in frames.
+ */
+ MXFAsset (std::string directory, std::string mxf_path, sigc::signal1<void, float>* progress, int fps, int length);
+
+ virtual std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const;
+
+ int length () const;
+
+protected:
+ /** Fill in a ADSCP::WriteInfo struct.
+ * @param w struct to fill in.
+ */
+ void fill_writer_info (ASDCP::WriterInfo* w) const;
+
+ /** Signal to emit to report progress */
+ sigc::signal1<void, float>* _progress;
+ /** Frames per second */
+ int _fps;
+ /** Length in frames */
+ int _length;
+};
+
+}
+
+#endif
--- /dev/null
+/*
+ Copyright (C) 2012 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 "subtitle_asset.h"
+
+using namespace libdcp;
+
+SubtitleAsset::SubtitleAsset (std::string directory, std::string xml)
+ : Asset (directory, xml)
+ , XMLFile (path().string(), "DCSubtitle")
+{
+ _subtitle_id = string_node ("SubtitleID");
+ _movie_title = string_node ("MovieTitle");
+ _reel_number = int64_node ("ReelNumber");
+ _language = string_node ("Language");
+
+ ignore_node ("LoadFont");
+
+ _fonts = sub_nodes<Font> ("Font");
+}
+
+Font::Font (xmlpp::Node const * node)
+ : XMLNode (node)
+{
+ _subtitles = sub_nodes<Subtitle> ("Subtitle");
+}
+
+Subtitle::Subtitle (xmlpp::Node const * node)
+ : XMLNode (node)
+{
+ _texts = sub_nodes<Text> ("Text");
+}
+
+Text::Text (xmlpp::Node const * node)
+ : XMLNode (node)
+{
+
+}
--- /dev/null
+/*
+ Copyright (C) 2012 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 "asset.h"
+#include "xml.h"
+#include "dcp_time.h"
+
+namespace libdcp
+{
+
+class Text : public XMLNode
+{
+public:
+ Text () {}
+ Text (xmlpp::Node const * node);
+
+ float v_position () const {
+ return _v_position;
+ }
+
+ std::string text () const {
+ return _text;
+ }
+
+private:
+ float _v_position;
+ std::string _text;
+};
+
+class Subtitle : public XMLNode
+{
+public:
+ Subtitle () {}
+ Subtitle (xmlpp::Node const * node);
+
+ Time in () const {
+ return _in;
+ }
+
+ Time out () const {
+ return _out;
+ }
+
+ std::list<boost::shared_ptr<Text> > texts () const {
+ return _texts;
+ }
+
+private:
+ std::list<boost::shared_ptr<Text> > _texts;
+ Time _in;
+ Time _out;
+};
+
+class Font : public XMLNode
+{
+public:
+ Font () {}
+ Font (xmlpp::Node const * node);
+
+ std::list<boost::shared_ptr<Subtitle> > subtitles () const {
+ return _subtitles;
+ }
+
+private:
+ std::list<boost::shared_ptr<Subtitle> > _subtitles;
+};
+
+class SubtitleAsset : public Asset, public XMLFile
+{
+public:
+ SubtitleAsset (std::string directory, std::string xml);
+
+ void write_to_cpl (std::ostream&) const {}
+ virtual std::list<std::string> equals (boost::shared_ptr<const Asset>, EqualityOptions) const {
+ return std::list<std::string> ();
+ }
+
+ std::string language () const {
+ return _language;
+ }
+
+ std::list<boost::shared_ptr<Font> > fonts () const {
+ return _fonts;
+ }
+
+private:
+ std::string _subtitle_id;
+ std::string _movie_title;
+ int64_t _reel_number;
+ std::string _language;
+ std::list<boost::shared_ptr<Font> > _fonts;
+};
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<DCSubtitle Version="1.0">
+ <SubtitleID>cab5c268-222b-41d2-88ae-6d6999441b17</SubtitleID>
+ <MovieTitle>Movie Title</MovieTitle>
+ <ReelNumber>1</ReelNumber>
+ <Language>French</Language>
+ <LoadFont Id="theFontId" URI="arial.ttf"/>
+ <Font Id="theFontId" Color="FFFFFFFF" Effect="border" EffectColor="FF000000" Italic="no" Size="39" Script="normal" Underlined="no" Weight="normal">
+ <Subtitle SpotNumber="1" TimeIn="00:00:05:198" TimeOut="00:00:07:115" FadeUpTime="1" FadeDownTime="1">
+ <Text VAlign="bottom" VPosition="15.0">My jacket was Idi Amin's</Text>
+ </Subtitle>
+ <Subtitle SpotNumber="2" TimeIn="00:00:07:177" TimeOut="00:00:11:031" FadeUpTime="1" FadeDownTime="1">
+ <Text VAlign="bottom" VPosition="21.0">My corset was H.M. The Queen's</Text>
+ <Text VAlign="bottom" VPosition="15.0">My large wonderbra</Text>
+ </Subtitle>
+ <Subtitle SpotNumber="3" TimeIn="00:00:11:094" TimeOut="00:00:13:063" FadeUpTime="1" FadeDownTime="1">
+ <Text VAlign="bottom" VPosition="15.0">Once belonged to the Shah</Text>
+ </Subtitle>
+ <Subtitle SpotNumber="4" TimeIn="00:00:13:104" TimeOut="00:00:15:177" FadeUpTime="1" FadeDownTime="1">
+ <Text VAlign="bottom" VPosition="15.0">And these are Roy Hattersley's jeans</Text>
+ </Subtitle>
+ </Font>
+</DCSubtitle>