From 2cf3da72a017eebf741dfb9a5ec158df94a4e7b7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 9 Jul 2014 09:36:58 +0100 Subject: Basics of DCP import. --- src/lib/dcp_decoder.cc | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 src/lib/dcp_decoder.cc (limited to 'src/lib/dcp_decoder.cc') diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc new file mode 100644 index 000000000..14672a23b --- /dev/null +++ b/src/lib/dcp_decoder.cc @@ -0,0 +1,119 @@ +/* + Copyright (C) 2014 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 +#include +#include +#include +#include +#include +#include +#include "dcp_decoder.h" +#include "dcp_content.h" +#include "image_proxy.h" +#include "image.h" + +using std::list; +using std::cout; +using boost::shared_ptr; +using boost::dynamic_pointer_cast; + +DCPDecoder::DCPDecoder (shared_ptr c, shared_ptr log) + : VideoDecoder (c) + , AudioDecoder (c) + , SubtitleDecoder (c) + , _log (log) + , _dcp_content (c) +{ + dcp::DCP dcp (c->directory ()); + dcp.read (); + assert (dcp.cpls().size() == 1); + _reels = dcp.cpls().front()->reels (); + _reel = _reels.begin (); +} + +bool +DCPDecoder::pass () +{ + if (_reel == _reels.end ()) { + return true; + } + + float const vfr = _dcp_content->video_frame_rate (); + + if ((*_reel)->main_picture ()) { + shared_ptr mxf = (*_reel)->main_picture()->mxf (); + shared_ptr mono = dynamic_pointer_cast (mxf); + shared_ptr stereo = dynamic_pointer_cast (mxf); + if (mono) { + shared_ptr image (new Image (PIX_FMT_RGB24, mxf->size(), false)); + mono->get_frame (_next.frames (vfr))->rgb_frame (image->data()[0]); + shared_ptr aligned (new Image (image, true)); + video (shared_ptr (new RawImageProxy (aligned, _log)), _next.frames (vfr)); + } else { + + shared_ptr left (new Image (PIX_FMT_RGB24, mxf->size(), false)); + stereo->get_frame (_next.frames (vfr))->rgb_frame (dcp::EYE_LEFT, left->data()[0]); + shared_ptr aligned_left (new Image (left, true)); + video (shared_ptr (new RawImageProxy (aligned_left, _log)), _next.frames (vfr)); + + shared_ptr right (new Image (PIX_FMT_RGB24, mxf->size(), false)); + stereo->get_frame (_next.frames (vfr))->rgb_frame (dcp::EYE_RIGHT, right->data()[0]); + shared_ptr aligned_right (new Image (right, true)); + video (shared_ptr (new RawImageProxy (aligned_right, _log)), _next.frames (vfr)); + } + } + + /* XXX: sound */ + /* XXX: subtitle */ + + _next += ContentTime::from_frames (1, vfr); + + if ((*_reel)->main_picture ()) { + if ((*_reel)->main_picture()->duration() >= _next.frames (vfr)) { + ++_reel; + } + } + + return false; +} + +void +DCPDecoder::seek (ContentTime t, bool accurate) +{ + VideoDecoder::seek (t, accurate); + AudioDecoder::seek (t, accurate); + SubtitleDecoder::seek (t, accurate); + + _reel = _reels.begin (); + while (_reel != _reels.end() && t >= ContentTime::from_frames ((*_reel)->main_picture()->duration(), _dcp_content->video_frame_rate ())) { + t -= ContentTime::from_frames ((*_reel)->main_picture()->duration(), _dcp_content->video_frame_rate ()); + ++_reel; + } + + _next = t; +} + + +list +DCPDecoder::subtitles_during (ContentTimePeriod, bool starting) const +{ + return list (); +} -- cgit v1.2.3