X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fvideo_ring_buffers.cc;h=63c52ee068879c0b262268ca94589b8c80928781;hb=7bc591abc86ed4742f21f45ca1d6151cb14bc100;hp=e81605732dd323ea240e501f57af299609d12987;hpb=90c782a16c26fa8bfded51cad2bc7bbc14d8f986;p=dcpomatic.git diff --git a/src/lib/video_ring_buffers.cc b/src/lib/video_ring_buffers.cc index e81605732..63c52ee06 100644 --- a/src/lib/video_ring_buffers.cc +++ b/src/lib/video_ring_buffers.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2017 Carl Hetherington + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,41 +18,45 @@ */ + #include "video_ring_buffers.h" #include "player_video.h" -#include +#include "compose.hpp" #include #include + using std::list; using std::make_pair; using std::cout; using std::pair; -using boost::shared_ptr; +using std::string; +using std::shared_ptr; using boost::optional; +using namespace dcpomatic; + void VideoRingBuffers::put (shared_ptr frame, DCPTime time) { - cout << "put " << to_string(time) << "\n"; boost::mutex::scoped_lock lm (_mutex); - _data.push_back (make_pair (frame, time)); + _data.push_back (make_pair(frame, time)); } + pair, DCPTime> VideoRingBuffers::get () { boost::mutex::scoped_lock lm (_mutex); if (_data.empty ()) { - cout << "get: no data.\n"; - return make_pair(shared_ptr(), DCPTime()); + return {}; } - pair, DCPTime> const r = _data.front (); - cout << "get: here we go! " << to_string(r.second) << "\n"; + auto const r = _data.front(); _data.pop_front (); return r; } + Frame VideoRingBuffers::size () const { @@ -60,6 +64,7 @@ VideoRingBuffers::size () const return _data.size (); } + bool VideoRingBuffers::empty () const { @@ -67,6 +72,7 @@ VideoRingBuffers::empty () const return _data.empty (); } + void VideoRingBuffers::clear () { @@ -74,13 +80,25 @@ VideoRingBuffers::clear () _data.clear (); } -optional -VideoRingBuffers::earliest () const + +pair +VideoRingBuffers::memory_used () const { boost::mutex::scoped_lock lm (_mutex); - if (_data.empty ()) { - return optional (); + size_t m = 0; + for (auto const& i: _data) { + m += i.first->memory_used(); } + return make_pair(m, String::compose("%1 frames", _data.size())); +} - return _data.front().second; + +void +VideoRingBuffers::reset_metadata (shared_ptr film, dcp::Size player_video_container_size) +{ + boost::mutex::scoped_lock lm (_mutex); + for (auto const& i: _data) { + i.first->reset_metadata (film, player_video_container_size); + } } +