diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-05-25 13:29:13 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-05-25 13:29:13 +0100 |
| commit | 4ee6786d1c3db04dcc77e511121e5d62d0d595b5 (patch) | |
| tree | 95ac9aa9af77caccffac5b7fcf63cb1a672ca77a /src | |
| parent | d22243e8cd54c1c5de6c670445395907007428ea (diff) | |
Add VideoMXFContent (part of #803).
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/content_factory.cc | 5 | ||||
| -rw-r--r-- | src/lib/player.cc | 11 | ||||
| -rw-r--r-- | src/lib/video_mxf_content.cc | 128 | ||||
| -rw-r--r-- | src/lib/video_mxf_content.h | 42 | ||||
| -rw-r--r-- | src/lib/video_mxf_decoder.cc | 79 | ||||
| -rw-r--r-- | src/lib/video_mxf_decoder.h | 37 | ||||
| -rw-r--r-- | src/lib/video_mxf_examiner.cc | 72 | ||||
| -rw-r--r-- | src/lib/video_mxf_examiner.h | 41 | ||||
| -rw-r--r-- | src/lib/wscript | 3 |
9 files changed, 418 insertions, 0 deletions
diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index e21a4c0d0..706c79754 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -29,6 +29,7 @@ #include "dcp_subtitle_content.h" #include "util.h" #include "ffmpeg_audio_stream.h" +#include "video_mxf_content.h" #include "film.h" #include "log_entry.h" #include "log.h" @@ -87,6 +88,8 @@ content_factory (shared_ptr<const Film> film, cxml::NodePtr node, int version, l content.reset (new DCPContent (film, node, version)); } else if (type == "DCPSubtitle") { content.reset (new DCPSubtitleContent (film, node, version)); + } else if (type == "VideoMXF") { + content.reset (new VideoMXFContent (film, node, version)); } return content; @@ -162,6 +165,8 @@ content_factory (shared_ptr<const Film> film, boost::filesystem::path path) content.reset (new DCPSubtitleContent (film, path)); } else if (ext == ".mxf" && dcp::SMPTESubtitleAsset::valid_mxf (path)) { content.reset (new DCPSubtitleContent (film, path)); + } else if (ext == ".mxf" && VideoMXFContent::valid_mxf (path)) { + content.reset (new VideoMXFContent (film, path)); } if (!content) { diff --git a/src/lib/player.cc b/src/lib/player.cc index cd841d1ce..0c513056c 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -31,6 +31,8 @@ #include "subtitle_content.h" #include "text_subtitle_decoder.h" #include "text_subtitle_content.h" +#include "video_mxf_decoder.h" +#include "video_mxf_content.h" #include "dcp_content.h" #include "job.h" #include "image.h" @@ -179,6 +181,15 @@ Player::setup_pieces () frc = FrameRateChange (dsc->active_video_frame_rate(), _film->video_frame_rate()); } + /* VideoMXFContent */ + shared_ptr<const VideoMXFContent> vmc = dynamic_pointer_cast<const VideoMXFContent> (i); + if (vmc) { + decoder.reset (new VideoMXFDecoder (vmc, _film->log())); + frc = FrameRateChange (vmc->active_video_frame_rate(), _film->video_frame_rate()); + } + + DCPOMATIC_ASSERT (decoder); + if (decoder->video && _ignore_video) { decoder->video->set_ignore (); } diff --git a/src/lib/video_mxf_content.cc b/src/lib/video_mxf_content.cc new file mode 100644 index 000000000..f049965d4 --- /dev/null +++ b/src/lib/video_mxf_content.cc @@ -0,0 +1,128 @@ +/* + Copyright (C) 2016 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 "video_mxf_examiner.h" +#include "video_mxf_content.h" +#include "video_content.h" +#include "job.h" +#include "film.h" +#include "compose.hpp" +#include <dcp/mono_picture_asset.h> +#include <dcp/stereo_picture_asset.h> +#include <dcp/exceptions.h> +#include <libxml++/libxml++.h> + +#include "i18n.h" + +using std::list; +using std::string; +using boost::shared_ptr; + +VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, boost::filesystem::path path) + : Content (film, path) +{ + +} + +VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version) + : Content (film, node) +{ + video = VideoContent::from_xml (this, node, version); +} + +bool +VideoMXFContent::valid_mxf (boost::filesystem::path path) +{ + try { + shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (path)); + return true; + } catch (dcp::MXFFileError& e) { + + } catch (dcp::DCPReadError& e) { + + } + + try { + shared_ptr<dcp::StereoPictureAsset> sp (new dcp::StereoPictureAsset (path)); + return true; + } catch (dcp::MXFFileError& e) { + + } catch (dcp::DCPReadError& e) { + + } + + return false; +} + +void +VideoMXFContent::examine (shared_ptr<Job> job) +{ + job->set_progress_unknown (); + + Content::examine (job); + + video.reset (new VideoContent (this)); + shared_ptr<VideoMXFExaminer> examiner (new VideoMXFExaminer (shared_from_this ())); + video->take_from_examiner (examiner); +} + +string +VideoMXFContent::summary () const +{ + return String::compose (_("%1 [video]"), path_summary()); +} + +string +VideoMXFContent::technical_summary () const +{ + return Content::technical_summary() + " - " + video->technical_summary (); +} + +string +VideoMXFContent::identifier () const +{ + return Content::identifier() + "_" + video->identifier(); +} + +void +VideoMXFContent::as_xml (xmlpp::Node* node) const +{ + node->add_child("Type")->add_child_text ("VideoMXF"); + Content::as_xml (node); + video->as_xml (node); +} + +DCPTime +VideoMXFContent::full_length () const +{ + FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate()); + return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film()->video_frame_rate()); +} + +void +VideoMXFContent::add_properties (list<UserProperty>& p) const +{ + video->add_properties (p); +} + +void +VideoMXFContent::set_default_colour_conversion () +{ + video->unset_colour_conversion (); +} diff --git a/src/lib/video_mxf_content.h b/src/lib/video_mxf_content.h new file mode 100644 index 000000000..788af11a1 --- /dev/null +++ b/src/lib/video_mxf_content.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2016 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 "content.h" + +class VideoMXFContent : public Content +{ +public: + VideoMXFContent (boost::shared_ptr<const Film> film, boost::filesystem::path path); + VideoMXFContent (boost::shared_ptr<const Film> film, cxml::ConstNodePtr node, int version); + + boost::shared_ptr<VideoMXFContent> shared_from_this () { + return boost::dynamic_pointer_cast<VideoMXFContent> (Content::shared_from_this ()); + } + + void examine (boost::shared_ptr<Job> job); + std::string summary () const; + std::string technical_summary () const; + std::string identifier () const; + void as_xml (xmlpp::Node* node) const; + DCPTime full_length () const; + void add_properties (std::list<UserProperty>& p) const; + void set_default_colour_conversion (); + + static bool valid_mxf (boost::filesystem::path path); +}; diff --git a/src/lib/video_mxf_decoder.cc b/src/lib/video_mxf_decoder.cc new file mode 100644 index 000000000..e8b787d8d --- /dev/null +++ b/src/lib/video_mxf_decoder.cc @@ -0,0 +1,79 @@ +/* + Copyright (C) 2016 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 "video_mxf_decoder.h" +#include "video_decoder.h" +#include "video_mxf_content.h" +#include "j2k_image_proxy.h" +#include <dcp/mono_picture_asset.h> +#include <dcp/stereo_picture_asset.h> +#include <dcp/exceptions.h> + +using boost::shared_ptr; + +VideoMXFDecoder::VideoMXFDecoder (shared_ptr<const VideoMXFContent> content, shared_ptr<Log> log) + : _content (content) +{ + video.reset (new VideoDecoder (this, content, log)); +} + +bool +VideoMXFDecoder::pass (PassReason reason, bool) +{ + shared_ptr<dcp::MonoPictureAsset> mono; + try { + mono.reset (new dcp::MonoPictureAsset (_content->path(0))); + } catch (dcp::MXFFileError& e) { + /* maybe it's stereo */ + } catch (dcp::DCPReadError& e) { + /* maybe it's stereo */ + } + + shared_ptr<dcp::StereoPictureAsset> stereo; + try { + stereo.reset (new dcp::StereoPictureAsset (_content->path(0))); + } catch (dcp::MXFFileError& e) { + if (!mono) { + throw; + } + } catch (dcp::DCPReadError& e) { + if (!mono) { + throw; + } + } + + double const vfr = _content->active_video_frame_rate (); + int64_t const frame = _next.frames_round (vfr); + + if (mono) { + video->give (shared_ptr<ImageProxy> (new J2KImageProxy (mono->get_frame(frame), mono->size())), frame); + } else { + video->give (shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame(frame), stereo->size(), dcp::EYE_LEFT)), frame); + video->give (shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame(frame), stereo->size(), dcp::EYE_RIGHT)), frame); + } + + _next += ContentTime::from_frames (1, vfr); +} + +void +VideoMXFDecoder::seek (ContentTime t, bool accurate) +{ + video->seek (t, accurate); + _next = t; +} diff --git a/src/lib/video_mxf_decoder.h b/src/lib/video_mxf_decoder.h new file mode 100644 index 000000000..fa9bfe818 --- /dev/null +++ b/src/lib/video_mxf_decoder.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2016 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 "decoder.h" + +class VideoMXFContent; +class Log; + +class VideoMXFDecoder : public Decoder +{ +public: + VideoMXFDecoder (boost::shared_ptr<const VideoMXFContent>, boost::shared_ptr<Log> log); + +private: + bool pass (PassReason, bool accurate); + void seek (ContentTime t, bool accurate); + + boost::shared_ptr<const VideoMXFContent> _content; + /** Time of next thing to return from pass */ + ContentTime _next; +}; diff --git a/src/lib/video_mxf_examiner.cc b/src/lib/video_mxf_examiner.cc new file mode 100644 index 000000000..506e6985c --- /dev/null +++ b/src/lib/video_mxf_examiner.cc @@ -0,0 +1,72 @@ +/* + Copyright (C) 2016 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 "video_mxf_content.h" +#include "video_mxf_examiner.h" +#include <dcp/exceptions.h> +#include <dcp/mono_picture_asset.h> +#include <dcp/stereo_picture_asset.h> + +using boost::shared_ptr; +using boost::optional; + +VideoMXFExaminer::VideoMXFExaminer (shared_ptr<const VideoMXFContent> content) +{ + try { + _asset.reset (new dcp::MonoPictureAsset (content->path(0))); + } catch (dcp::MXFFileError& e) { + /* maybe it's stereo */ + } catch (dcp::DCPReadError& e) { + /* maybe it's stereo */ + } + + if (!_asset) { + _asset.reset (new dcp::StereoPictureAsset (content->path(0))); + } +} + +optional<double> +VideoMXFExaminer::video_frame_rate () const +{ + return _asset->frame_rate().as_float (); +} + +dcp::Size +VideoMXFExaminer::video_size () const +{ + return _asset->size (); +} + +Frame +VideoMXFExaminer::video_length () const +{ + return _asset->intrinsic_duration (); +} + +optional<double> +VideoMXFExaminer::sample_aspect_ratio () const +{ + return 1.0; +} + +bool +VideoMXFExaminer::yuv () const +{ + return false; +} diff --git a/src/lib/video_mxf_examiner.h b/src/lib/video_mxf_examiner.h new file mode 100644 index 000000000..a16e76747 --- /dev/null +++ b/src/lib/video_mxf_examiner.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2016 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 "video_examiner.h" + +class VideoMXFContent; + +namespace dcp { + class PictureAsset; +} + +class VideoMXFExaminer : public VideoExaminer +{ +public: + VideoMXFExaminer (boost::shared_ptr<const VideoMXFContent>); + + boost::optional<double> video_frame_rate () const; + dcp::Size video_size () const; + Frame video_length () const; + boost::optional<double> sample_aspect_ratio () const; + bool yuv () const; + +private: + boost::shared_ptr<dcp::PictureAsset> _asset; +}; diff --git a/src/lib/wscript b/src/lib/wscript index 6a9f5106c..727a398af 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -136,6 +136,9 @@ sources = """ video_content_scale.cc video_decoder.cc video_filter_graph.cc + video_mxf_content.cc + video_mxf_decoder.cc + video_mxf_examiner.cc writer.cc """ |
