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