Basics of FFmpeg examiner works.
[dcpomatic.git] / src / lib / black_decoder.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "black_decoder.h"
21 #include "image.h"
22 #include "null_content.h"
23
24 using boost::shared_ptr;
25
26 BlackDecoder::BlackDecoder (shared_ptr<const Film> f, shared_ptr<NullContent> c)
27         : Decoder (f)
28         , VideoDecoder (f, c)
29 {
30
31 }
32
33 void
34 BlackDecoder::pass ()
35 {
36         if (!_image) {
37                 _image.reset (new SimpleImage (AV_PIX_FMT_RGB24, video_size(), true));
38                 _image->make_black ();
39                 video (_image, false, _next_video);
40         } else {
41                 video (_image, true, _next_video);
42         }
43 }
44
45 float
46 BlackDecoder::video_frame_rate () const
47 {
48         boost::shared_ptr<const Film> f = _film.lock ();
49         if (!f) {
50                 return 24;
51         }
52
53         return f->dcp_video_frame_rate ();
54 }
55
56 ContentVideoFrame
57 BlackDecoder::video_length () const
58 {
59         return _video_content->length() * video_frame_rate() / TIME_HZ;
60 }
61
62 Time
63 BlackDecoder::position () const
64 {
65         return _next_video;
66 }
67
68 void
69 BlackDecoder::seek (Time t)
70 {
71         _next_video = t;
72 }
73
74 void
75 BlackDecoder::seek_back ()
76 {
77         boost::shared_ptr<const Film> f = _film.lock ();
78         if (!f) {
79                 return;
80         }
81
82         _next_video -= f->video_frames_to_time (2);
83 }
84
85 void
86 BlackDecoder::seek_forward ()
87 {
88         boost::shared_ptr<const Film> f = _film.lock ();
89         if (!f) {
90                 return;
91         }
92
93         _next_video += f->video_frames_to_time (1);
94 }
95
96 bool
97 BlackDecoder::done () const
98 {
99         return video_done ();
100 }
101
102