27c0224ec80d0e50ace7996a0dafd3b90843348a
[dcpomatic.git] / src / lib / frame_interval_checker.cc
1 /*
2     Copyright (C) 2020 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 "frame_interval_checker.h"
22
23 using namespace dcpomatic;
24
25 int const FrameIntervalChecker::_frames = 16;
26
27 void
28 FrameIntervalChecker::feed (ContentTime time, double frame_rate)
29 {
30         /* The caller isn't meant to feed too much data before
31            calling guess() and destroying the FrameIntervalChecker.
32          */
33         DCPOMATIC_ASSERT (_intervals.size() < _frames);
34
35         if (_last) {
36                 _intervals.push_back ((time - *_last).seconds() * frame_rate);
37         }
38
39         _last = time;
40 }
41
42 FrameIntervalChecker::Guess
43 FrameIntervalChecker::guess () const
44 {
45         if (_intervals.size() < _frames) {
46                 /* How soon can you land?
47                  * I can't tell.
48                  * You can tell me, I'm a doctor.
49                  * Nom I mean I'm just not sure.
50                  * Can't you take a guess?
51                  * Well, not for another two hours.
52                  * You can't take a guess for another two hours?
53                  */
54                 return AGAIN;
55         }
56
57         int near_1 = 0;
58         BOOST_FOREACH (double i, _intervals) {
59                 if (i > 0.5) {
60                         ++near_1;
61                 }
62         }
63
64         return (near_1 < 3 * _frames / 4) ? PROBABLY_3D : PROBABLY_NOT_3D;
65 }
66