From c14a05a935886345d4d891a92a31b1c35bf10582 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 13 Aug 2012 01:19:45 +0100 Subject: [PATCH] Missing files. --- src/dcp_time.cc | 36 ++++++++++++ src/dcp_time.h | 47 ++++++++++++++++ src/mxf_asset.cc | 124 ++++++++++++++++++++++++++++++++++++++++++ src/mxf_asset.h | 60 ++++++++++++++++++++ src/subtitle_asset.cc | 54 ++++++++++++++++++ src/subtitle_asset.h | 110 +++++++++++++++++++++++++++++++++++++ test/ref/subs.xml | 23 ++++++++ 7 files changed, 454 insertions(+) create mode 100644 src/dcp_time.cc create mode 100644 src/dcp_time.h create mode 100644 src/mxf_asset.cc create mode 100644 src/mxf_asset.h create mode 100644 src/subtitle_asset.cc create mode 100644 src/subtitle_asset.h create mode 100644 test/ref/subs.xml diff --git a/src/dcp_time.cc b/src/dcp_time.cc new file mode 100644 index 00000000..2e79e742 --- /dev/null +++ b/src/dcp_time.cc @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 +#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; +} diff --git a/src/dcp_time.h b/src/dcp_time.h new file mode 100644 index 00000000..4e91dc18 --- /dev/null +++ b/src/dcp_time.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 diff --git a/src/mxf_asset.cc b/src/mxf_asset.cc new file mode 100644 index 00000000..b5560b26 --- /dev/null +++ b/src/mxf_asset.cc @@ -0,0 +1,124 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 +#include +#include +#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* 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 +MXFAsset::equals (shared_ptr other, EqualityOptions opt) const +{ + shared_ptr other_mxf = dynamic_pointer_cast (other); + if (!other_mxf) { + return list (); + } + + list 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; +} + + diff --git a/src/mxf_asset.h b/src/mxf_asset.h new file mode 100644 index 00000000..35509311 --- /dev/null +++ b/src/mxf_asset.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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* progress, int fps, int length); + + virtual std::list equals (boost::shared_ptr 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* _progress; + /** Frames per second */ + int _fps; + /** Length in frames */ + int _length; +}; + +} + +#endif diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc new file mode 100644 index 00000000..19697a7f --- /dev/null +++ b/src/subtitle_asset.cc @@ -0,0 +1,54 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 (xmlpp::Node const * node) + : XMLNode (node) +{ + _subtitles = sub_nodes ("Subtitle"); +} + +Subtitle::Subtitle (xmlpp::Node const * node) + : XMLNode (node) +{ + _texts = sub_nodes ("Text"); +} + +Text::Text (xmlpp::Node const * node) + : XMLNode (node) +{ + +} diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h new file mode 100644 index 00000000..392d70b4 --- /dev/null +++ b/src/subtitle_asset.h @@ -0,0 +1,110 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 > texts () const { + return _texts; + } + +private: + std::list > _texts; + Time _in; + Time _out; +}; + +class Font : public XMLNode +{ +public: + Font () {} + Font (xmlpp::Node const * node); + + std::list > subtitles () const { + return _subtitles; + } + +private: + std::list > _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 equals (boost::shared_ptr, EqualityOptions) const { + return std::list (); + } + + std::string language () const { + return _language; + } + + std::list > fonts () const { + return _fonts; + } + +private: + std::string _subtitle_id; + std::string _movie_title; + int64_t _reel_number; + std::string _language; + std::list > _fonts; +}; + +} diff --git a/test/ref/subs.xml b/test/ref/subs.xml new file mode 100644 index 00000000..6afeefb3 --- /dev/null +++ b/test/ref/subs.xml @@ -0,0 +1,23 @@ + + + cab5c268-222b-41d2-88ae-6d6999441b17 + Movie Title + 1 + French + + + + My jacket was Idi Amin's + + + My corset was H.M. The Queen's + My large wonderbra + + + Once belonged to the Shah + + + And these are Roy Hattersley's jeans + + + -- 2.30.2