Fix missing return value in ::pass().
[dcpomatic.git] / src / lib / video_mxf_decoder.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "video_mxf_decoder.h"
22 #include "video_decoder.h"
23 #include "video_mxf_content.h"
24 #include "j2k_image_proxy.h"
25 #include <dcp/mono_picture_asset.h>
26 #include <dcp/stereo_picture_asset.h>
27 #include <dcp/exceptions.h>
28
29 using boost::shared_ptr;
30
31 VideoMXFDecoder::VideoMXFDecoder (shared_ptr<const VideoMXFContent> content, shared_ptr<Log> log)
32         : _content (content)
33 {
34         video.reset (new VideoDecoder (this, content, log));
35 }
36
37 bool
38 VideoMXFDecoder::pass (PassReason, bool)
39 {
40         double const vfr = _content->active_video_frame_rate ();
41         int64_t const frame = _next.frames_round (vfr);
42
43         if (frame >= _content->video->length()) {
44                 return true;
45         }
46
47         shared_ptr<dcp::MonoPictureAsset> mono;
48         try {
49                 mono.reset (new dcp::MonoPictureAsset (_content->path(0)));
50         } catch (dcp::MXFFileError& e) {
51                 /* maybe it's stereo */
52         } catch (dcp::DCPReadError& e) {
53                 /* maybe it's stereo */
54         }
55
56         shared_ptr<dcp::StereoPictureAsset> stereo;
57         try {
58                 stereo.reset (new dcp::StereoPictureAsset (_content->path(0)));
59         } catch (dcp::MXFFileError& e) {
60                 if (!mono) {
61                         throw;
62                 }
63         } catch (dcp::DCPReadError& e) {
64                 if (!mono) {
65                         throw;
66                 }
67         }
68
69         if (mono) {
70                 video->give (shared_ptr<ImageProxy> (new J2KImageProxy (mono->get_frame(frame), mono->size())), frame);
71         } else {
72                 video->give (shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame(frame), stereo->size(), dcp::EYE_LEFT)), frame);
73                 video->give (shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame(frame), stereo->size(), dcp::EYE_RIGHT)), frame);
74         }
75
76         _next += ContentTime::from_frames (1, vfr);
77         return false;
78 }
79
80 void
81 VideoMXFDecoder::seek (ContentTime t, bool accurate)
82 {
83         video->seek (t, accurate);
84         _next = t;
85 }