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;
39 VideoDecoder::VideoDecoder (Decoder* parent, shared_ptr<const Content> c, shared_ptr<Log> log)
40 : DecoderPart (parent, log)
46 /** Called by decoder classes when they have a video frame ready.
47 * @param frame Frame index within the content; this does not take into account 3D
48 * so for 3D_ALTERNATE this value goes:
56 VideoDecoder::emit (shared_ptr<const ImageProxy> image, Frame frame)
62 switch (_content->video->frame_type ()) {
63 case VIDEO_FRAME_TYPE_2D:
64 Data (ContentVideo (image, frame, EYES_BOTH, PART_WHOLE));
66 case VIDEO_FRAME_TYPE_3D:
68 /* We receive the same frame index twice for 3D; hence we know which
71 bool const same = (_last_emitted && _last_emitted.get() == frame);
72 Data (ContentVideo (image, frame, same ? EYES_RIGHT : EYES_LEFT, PART_WHOLE));
73 _last_emitted = frame;
76 case VIDEO_FRAME_TYPE_3D_ALTERNATE:
77 Data (ContentVideo (image, frame / 2, (frame % 2) ? EYES_RIGHT : EYES_LEFT, PART_WHOLE));
80 case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
81 Data (ContentVideo (image, frame, EYES_LEFT, PART_LEFT_HALF));
82 Data (ContentVideo (image, frame, EYES_RIGHT, PART_RIGHT_HALF));
84 case VIDEO_FRAME_TYPE_3D_TOP_BOTTOM:
85 Data (ContentVideo (image, frame, EYES_LEFT, PART_TOP_HALF));
86 Data (ContentVideo (image, frame, EYES_RIGHT, PART_BOTTOM_HALF));
88 case VIDEO_FRAME_TYPE_3D_LEFT:
89 Data (ContentVideo (image, frame, EYES_LEFT, PART_WHOLE));
91 case VIDEO_FRAME_TYPE_3D_RIGHT:
92 Data (ContentVideo (image, frame, EYES_RIGHT, PART_WHOLE));
95 DCPOMATIC_ASSERT (false);
98 _position = ContentTime::from_frames (frame, _content->active_video_frame_rate ());
102 VideoDecoder::seek ()
104 _position = ContentTime();
105 _last_emitted.reset ();