From: Carl Hetherington Date: Fri, 29 Dec 2017 22:51:50 +0000 (+0000) Subject: Add basic memory-used stuff for butler and reduce minimum audio X-Git-Tag: v2.11.31~7 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=a5ea5c0d2637dd41e3d356cb62cac75b8cadf8ce Add basic memory-used stuff for butler and reduce minimum audio readahead quite a bit. This in turn reduces the maximum butler memory usage as it will keep getting audio (and hence video) until the minimum audio readahead is hit. --- diff --git a/src/lib/butler.cc b/src/lib/butler.cc index fd4b824a5..56f8919f5 100644 --- a/src/lib/butler.cc +++ b/src/lib/butler.cc @@ -29,6 +29,7 @@ using std::cout; using std::pair; using std::make_pair; +using std::string; using boost::weak_ptr; using boost::shared_ptr; using boost::bind; @@ -39,9 +40,9 @@ using boost::optional; /** Maximum video readahead in frames; should never be reached unless there are bugs in Player */ #define MAXIMUM_VIDEO_READAHEAD 24 /** Minimum audio readahead in frames */ -#define MINIMUM_AUDIO_READAHEAD (48000*5) +#define MINIMUM_AUDIO_READAHEAD (48000 * MINIMUM_VIDEO_READAHEAD / 24) /** Minimum audio readahead in frames; should never be reached unless there are bugs in Player */ -#define MAXIMUM_AUDIO_READAHEAD (48000*60) +#define MAXIMUM_AUDIO_READAHEAD (48000 * MAXIMUM_VIDEO_READAHEAD / 24) #define LOG_WARNING(...) _log->log (String::compose(__VA_ARGS__), LogEntry::TYPE_WARNING); @@ -254,3 +255,10 @@ Butler::disable_audio () boost::mutex::scoped_lock lm (_mutex); _disable_audio = true; } + +pair +Butler::memory_used () const +{ + /* XXX: should also look at _audio.memory_used() */ + return _video.memory_used(); +} diff --git a/src/lib/butler.h b/src/lib/butler.h index 8fad3614e..a61011f40 100644 --- a/src/lib/butler.h +++ b/src/lib/butler.h @@ -45,6 +45,8 @@ public: void disable_audio (); + std::pair memory_used () const; + private: void thread (); void video (boost::shared_ptr video, DCPTime time); diff --git a/src/lib/image.cc b/src/lib/image.cc index c3955c92a..da1bb86ee 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -1046,3 +1046,13 @@ Image::ensure_aligned (shared_ptr image) return shared_ptr (new Image (image, true)); } + +size_t +Image::memory_used () const +{ + size_t m = 0; + for (int i = 0; i < planes(); ++i) { + m += _stride[i] * sample_size(i).height; + } + return m; +} diff --git a/src/lib/image.h b/src/lib/image.h index 9a5a7dae8..ce57c5317 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -77,6 +77,8 @@ public: return _pixel_format; } + size_t memory_used () const; + static boost::shared_ptr ensure_aligned (boost::shared_ptr image); private: diff --git a/src/lib/image_proxy.h b/src/lib/image_proxy.h index f9a06d1b7..01cb79552 100644 --- a/src/lib/image_proxy.h +++ b/src/lib/image_proxy.h @@ -79,6 +79,7 @@ public: */ virtual void prepare (boost::optional = boost::optional()) const {} virtual AVPixelFormat pixel_format () const = 0; + virtual size_t memory_used () const = 0; }; boost::shared_ptr image_proxy_factory (boost::shared_ptr xml, boost::shared_ptr socket); diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index a60af1eb2..2489a9499 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -212,3 +212,14 @@ J2KImageProxy::J2KImageProxy (Data data, dcp::Size size, AVPixelFormat pixel_for { } + +size_t +J2KImageProxy::memory_used () const +{ + size_t m = _data.size(); + if (_decompressed) { + /* 3 components, 16-bits per pixel */ + m += 3 * 2 * _decompressed->size().width * _decompressed->size().height; + } + return m; +} diff --git a/src/lib/j2k_image_proxy.h b/src/lib/j2k_image_proxy.h index c20d89340..3680de111 100644 --- a/src/lib/j2k_image_proxy.h +++ b/src/lib/j2k_image_proxy.h @@ -72,6 +72,8 @@ public: return _size; } + size_t memory_used () const; + private: friend struct client_server_test_j2k; diff --git a/src/lib/magick_image_proxy.cc b/src/lib/magick_image_proxy.cc index e6733c7de..0fd4a5edb 100644 --- a/src/lib/magick_image_proxy.cc +++ b/src/lib/magick_image_proxy.cc @@ -173,3 +173,13 @@ MagickImageProxy::pixel_format () const { return AV_PIX_FMT_RGB24; } + +size_t +MagickImageProxy::memory_used () const +{ + size_t m = _blob.length(); + if (_image) { + m += _image->memory_used(); + } + return m; +} diff --git a/src/lib/magick_image_proxy.h b/src/lib/magick_image_proxy.h index 5c4532add..1db45d73b 100644 --- a/src/lib/magick_image_proxy.h +++ b/src/lib/magick_image_proxy.h @@ -38,6 +38,7 @@ public: void send_binary (boost::shared_ptr) const; bool same (boost::shared_ptr other) const; AVPixelFormat pixel_format () const; + size_t memory_used () const; private: Magick::Blob _blob; diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index 14291fc35..d3f09947e 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -252,3 +252,9 @@ PlayerVideo::prepare () { _in->prepare (_inter_size); } + +size_t +PlayerVideo::memory_used () const +{ + return _in->memory_used(); +} diff --git a/src/lib/player_video.h b/src/lib/player_video.h index 040145559..fe7ae384e 100644 --- a/src/lib/player_video.h +++ b/src/lib/player_video.h @@ -91,6 +91,8 @@ public: bool same (boost::shared_ptr other) const; + size_t memory_used () const; + private: boost::shared_ptr _in; Crop _crop; diff --git a/src/lib/raw_image_proxy.cc b/src/lib/raw_image_proxy.cc index ea702f138..094b50d05 100644 --- a/src/lib/raw_image_proxy.cc +++ b/src/lib/raw_image_proxy.cc @@ -89,3 +89,9 @@ RawImageProxy::pixel_format () const { return _image->pixel_format (); } + +size_t +RawImageProxy::memory_used () const +{ + return _image->memory_used (); +} diff --git a/src/lib/raw_image_proxy.h b/src/lib/raw_image_proxy.h index 28fd7f263..2b64cbd9b 100644 --- a/src/lib/raw_image_proxy.h +++ b/src/lib/raw_image_proxy.h @@ -38,6 +38,7 @@ public: void send_binary (boost::shared_ptr) const; bool same (boost::shared_ptr) const; AVPixelFormat pixel_format () const; + size_t memory_used () const; private: boost::shared_ptr _image; diff --git a/src/lib/video_ring_buffers.cc b/src/lib/video_ring_buffers.cc index a8688a1cd..2fc39d53c 100644 --- a/src/lib/video_ring_buffers.cc +++ b/src/lib/video_ring_buffers.cc @@ -20,6 +20,7 @@ #include "video_ring_buffers.h" #include "player_video.h" +#include "compose.hpp" #include #include #include @@ -28,6 +29,7 @@ using std::list; using std::make_pair; using std::cout; using std::pair; +using std::string; using boost::shared_ptr; using boost::optional; @@ -81,3 +83,13 @@ VideoRingBuffers::earliest () const return _data.front().second; } + +pair +VideoRingBuffers::memory_used () const +{ + size_t m = 0; + for (list, DCPTime> >::const_iterator i = _data.begin(); i != _data.end(); ++i) { + m += i->first->memory_used(); + } + return make_pair(m, String::compose("%1 frames", _data.size())); +} diff --git a/src/lib/video_ring_buffers.h b/src/lib/video_ring_buffers.h index cf61b90cc..887a5dc2f 100644 --- a/src/lib/video_ring_buffers.h +++ b/src/lib/video_ring_buffers.h @@ -39,6 +39,8 @@ public: bool empty () const; boost::optional earliest () const; + std::pair memory_used () const; + private: mutable boost::mutex _mutex; std::list, DCPTime> > _data;