2 Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "video_decoder.h"
23 #include "raw_image_proxy.h"
26 #include "compose.hpp"
27 #include <boost/foreach.hpp>
35 using std::back_inserter;
36 using boost::shared_ptr;
37 using boost::optional;
38 using namespace dcpomatic;
40 VideoDecoder::VideoDecoder (Decoder* parent, shared_ptr<const Content> c)
41 : DecoderPart (parent)
47 /** Called by decoder classes when they have a video frame ready.
48 * @param frame Frame index within the content; this does not take into account 3D
49 * so for 3D_ALTERNATE this value goes:
57 VideoDecoder::emit (shared_ptr<const Film> film, shared_ptr<const ImageProxy> image, Frame frame)
63 switch (_content->video->frame_type ()) {
64 case VIDEO_FRAME_TYPE_2D:
65 Data (ContentVideo (image, frame, EYES_BOTH, PART_WHOLE));
67 case VIDEO_FRAME_TYPE_3D:
69 /* We should receive the same frame index twice for 3D; hence we know which
72 bool const same = (_last_emitted_frame && _last_emitted_frame.get() == frame);
73 if (!same && _last_emitted_eyes && *_last_emitted_eyes == EYES_LEFT) {
74 /* We just got a new frame index but the last frame was left-eye; it looks like
75 this content is not really 3D.
77 boost::throw_exception (
80 _("The content file %1 is set as 3D but does not appear to contain 3D images. Please set it to 2D. "
81 "You can still make a 3D DCP from this content by ticking the 3D option in the DCP video tab."),
87 Eyes const eyes = same ? EYES_RIGHT : EYES_LEFT;
88 Data (ContentVideo (image, frame, eyes, PART_WHOLE));
89 _last_emitted_frame = frame;
90 _last_emitted_eyes = eyes;
93 case VIDEO_FRAME_TYPE_3D_ALTERNATE:
94 Data (ContentVideo (image, frame / 2, (frame % 2) ? EYES_RIGHT : EYES_LEFT, PART_WHOLE));
97 case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
98 Data (ContentVideo (image, frame, EYES_LEFT, PART_LEFT_HALF));
99 Data (ContentVideo (image, frame, EYES_RIGHT, PART_RIGHT_HALF));
101 case VIDEO_FRAME_TYPE_3D_TOP_BOTTOM:
102 Data (ContentVideo (image, frame, EYES_LEFT, PART_TOP_HALF));
103 Data (ContentVideo (image, frame, EYES_RIGHT, PART_BOTTOM_HALF));
105 case VIDEO_FRAME_TYPE_3D_LEFT:
106 Data (ContentVideo (image, frame, EYES_LEFT, PART_WHOLE));
108 case VIDEO_FRAME_TYPE_3D_RIGHT:
109 Data (ContentVideo (image, frame, EYES_RIGHT, PART_WHOLE));
112 DCPOMATIC_ASSERT (false);
115 _position = ContentTime::from_frames (frame, _content->active_video_frame_rate(film));
119 VideoDecoder::seek ()
121 _position = ContentTime();
122 _last_emitted_frame.reset ();
123 _last_emitted_eyes.reset ();