/*
- Copyright (C) 2016-2017 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
*/
+
#include "video_ring_buffers.h"
#include "player_video.h"
-#include <boost/foreach.hpp>
+#include "compose.hpp"
#include <list>
#include <iostream>
+
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<PlayerVideo> 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<shared_ptr<PlayerVideo>, DCPTime>
VideoRingBuffers::get ()
{
boost::mutex::scoped_lock lm (_mutex);
if (_data.empty ()) {
- cout << "get: no data.\n";
- return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
+ return {};
}
- pair<shared_ptr<PlayerVideo>, 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
{
return _data.size ();
}
+
+bool
+VideoRingBuffers::empty () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ return _data.empty ();
+}
+
+
void
VideoRingBuffers::clear ()
{
_data.clear ();
}
-optional<DCPTime>
-VideoRingBuffers::latest () const
+
+pair<size_t, string>
+VideoRingBuffers::memory_used () const
{
boost::mutex::scoped_lock lm (_mutex);
- if (_data.empty ()) {
- return optional<DCPTime> ();
+ 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.back().second;
+void
+VideoRingBuffers::reset_metadata (shared_ptr<const Film> 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);
+ }
}
+