Assorted C++11/formatting cleanups.
[dcpomatic.git] / src / lib / video_ring_buffers.cc
1 /*
2     Copyright (C) 2016-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 "video_ring_buffers.h"
23 #include "player_video.h"
24 #include "compose.hpp"
25 #include <list>
26 #include <iostream>
27
28
29 using std::list;
30 using std::make_pair;
31 using std::cout;
32 using std::pair;
33 using std::string;
34 using std::shared_ptr;
35 using boost::optional;
36 using namespace dcpomatic;
37
38
39 void
40 VideoRingBuffers::put (shared_ptr<PlayerVideo> frame, DCPTime time)
41 {
42         boost::mutex::scoped_lock lm (_mutex);
43         _data.push_back (make_pair(frame, time));
44 }
45
46
47 pair<shared_ptr<PlayerVideo>, DCPTime>
48 VideoRingBuffers::get ()
49 {
50         boost::mutex::scoped_lock lm (_mutex);
51         if (_data.empty ()) {
52                 return {};
53         }
54         auto const r = _data.front();
55         _data.pop_front ();
56         return r;
57 }
58
59
60 Frame
61 VideoRingBuffers::size () const
62 {
63         boost::mutex::scoped_lock lm (_mutex);
64         return _data.size ();
65 }
66
67
68 bool
69 VideoRingBuffers::empty () const
70 {
71         boost::mutex::scoped_lock lm (_mutex);
72         return _data.empty ();
73 }
74
75
76 void
77 VideoRingBuffers::clear ()
78 {
79         boost::mutex::scoped_lock lm (_mutex);
80         _data.clear ();
81 }
82
83
84 pair<size_t, string>
85 VideoRingBuffers::memory_used () const
86 {
87         boost::mutex::scoped_lock lm (_mutex);
88         size_t m = 0;
89         for (auto const& i: _data) {
90                 m += i.first->memory_used();
91         }
92         return make_pair(m, String::compose("%1 frames", _data.size()));
93 }
94
95
96 void
97 VideoRingBuffers::reset_metadata (shared_ptr<const Film> film, dcp::Size player_video_container_size)
98 {
99         boost::mutex::scoped_lock lm (_mutex);
100         for (auto const& i: _data) {
101                 i.first->reset_metadata (film, player_video_container_size);
102         }
103 }
104