Some more tidying up.
[dcpomatic.git] / src / lib / video_decoder.cc
1 /* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
2
3 /*
4     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
5
6     This program 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     This program 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 this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21
22 #include "video_decoder.h"
23 #include "subtitle.h"
24 #include "film.h"
25 #include "image.h"
26
27 #include "i18n.h"
28
29 using std::cout;
30 using boost::shared_ptr;
31
32 VideoDecoder::VideoDecoder (shared_ptr<const Film> f, shared_ptr<const VideoContent> c)
33         : Decoder (f)
34         , _next_video (0)
35         , _video_content (c)
36         , _frame_rate_conversion (c->video_frame_rate(), f->dcp_frame_rate())
37         , _odd (false)
38 {
39
40 }
41
42 /** Called by subclasses when some video is ready.
43  *  @param image frame to emit.
44  *  @param same true if this frame is the same as the last one passed to this call.
45  *  @param t Time of the frame within the source.
46  */
47 void
48 VideoDecoder::video (shared_ptr<Image> image, bool same, Time t)
49 {
50         if (_frame_rate_conversion.skip && _odd) {
51                 _odd = !_odd;
52                 return;
53         }
54
55         shared_ptr<Subtitle> sub;
56         if (_timed_subtitle && _timed_subtitle->displayed_at (t)) {
57                 sub = _timed_subtitle->subtitle ();
58         }
59
60         Video (image, same, sub, t);
61
62         if (_frame_rate_conversion.repeat) {
63                 Video (image, true, sub, t + _film->video_frames_to_time (1));
64                 _next_video = t + _film->video_frames_to_time (2);
65         } else {
66                 _next_video = t + _film->video_frames_to_time (1);
67         }
68
69         _odd = !_odd;
70 }
71
72 /** Called by subclasses when a subtitle is ready.
73  *  s may be 0 to say that there is no current subtitle.
74  *  @param s New current subtitle, or 0.
75  */
76 void
77 VideoDecoder::subtitle (shared_ptr<TimedSubtitle> s)
78 {
79         _timed_subtitle = s;
80         
81         if (_timed_subtitle) {
82                 Position const p = _timed_subtitle->subtitle()->position ();
83                 _timed_subtitle->subtitle()->set_position (Position (p.x - _video_content->crop().left, p.y - _video_content->crop().top));
84         }
85 }