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