Add basic memory-used stuff for butler and reduce minimum audio
authorCarl Hetherington <cth@carlh.net>
Fri, 29 Dec 2017 22:51:50 +0000 (22:51 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 29 Dec 2017 22:51:50 +0000 (22:51 +0000)
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.

15 files changed:
src/lib/butler.cc
src/lib/butler.h
src/lib/image.cc
src/lib/image.h
src/lib/image_proxy.h
src/lib/j2k_image_proxy.cc
src/lib/j2k_image_proxy.h
src/lib/magick_image_proxy.cc
src/lib/magick_image_proxy.h
src/lib/player_video.cc
src/lib/player_video.h
src/lib/raw_image_proxy.cc
src/lib/raw_image_proxy.h
src/lib/video_ring_buffers.cc
src/lib/video_ring_buffers.h

index fd4b824a52410fcccfd1a6d21df0fe2a5b1484f9..56f8919f5516487742c44b308bf345ceb350d687 100644 (file)
@@ -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<size_t, string>
+Butler::memory_used () const
+{
+       /* XXX: should also look at _audio.memory_used() */
+       return _video.memory_used();
+}
index 8fad3614e5aa75c4144d3400be3e8efd7a1f855e..a61011f4019fa1ddcc5e6e01f184a9e9011a3fb0 100644 (file)
@@ -45,6 +45,8 @@ public:
 
        void disable_audio ();
 
+       std::pair<size_t, std::string> memory_used () const;
+
 private:
        void thread ();
        void video (boost::shared_ptr<PlayerVideo> video, DCPTime time);
index c3955c92add136e25accc3ff2e5aa9ea36cb81fd..da1bb86ee36d7e592971a549480a4e2924e8e67c 100644 (file)
@@ -1046,3 +1046,13 @@ Image::ensure_aligned (shared_ptr<Image> image)
 
        return shared_ptr<Image> (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;
+}
index 9a5a7dae8c961c90756ee439beda9fe774ad010c..ce57c5317f4362d49e93391ace25d27c0bfa3a5f 100644 (file)
@@ -77,6 +77,8 @@ public:
                return _pixel_format;
        }
 
+       size_t memory_used () const;
+
        static boost::shared_ptr<Image> ensure_aligned (boost::shared_ptr<Image> image);
 
 private:
index f9a06d1b701c7c84b1979f52375cbb6c74769f4e..01cb79552d26de566d6ea3ad667c8a819c5618f8 100644 (file)
@@ -79,6 +79,7 @@ public:
         */
        virtual void prepare (boost::optional<dcp::Size> = boost::optional<dcp::Size>()) const {}
        virtual AVPixelFormat pixel_format () const = 0;
+       virtual size_t memory_used () const = 0;
 };
 
 boost::shared_ptr<ImageProxy> image_proxy_factory (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket);
index a60af1eb26182e299261a4a4fdf00b79e1b8f8a5..2489a949925f12ffd535779c0efc2507257d0135 100644 (file)
@@ -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;
+}
index c20d89340318b2040bf3fc60a6c26b8d95e70845..3680de1114c857dcf80e5b64321499293f183107 100644 (file)
@@ -72,6 +72,8 @@ public:
                return _size;
        }
 
+       size_t memory_used () const;
+
 private:
        friend struct client_server_test_j2k;
 
index e6733c7de24552d8b807f64a79a9332be83aed4b..0fd4a5edb2bb36b355f4fb18996394c3e87266b0 100644 (file)
@@ -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;
+}
index 5c4532add9b1e8ae67bad08546e37087b50aa769..1db45d73bf35b3b98b41a315e6c3c3b038e4ba12 100644 (file)
@@ -38,6 +38,7 @@ public:
        void send_binary (boost::shared_ptr<Socket>) const;
        bool same (boost::shared_ptr<const ImageProxy> other) const;
        AVPixelFormat pixel_format () const;
+       size_t memory_used () const;
 
 private:
        Magick::Blob _blob;
index 14291fc35c917d068b74f4ba9726915402663523..d3f09947eeae77966c56f9a8ab4120ba47929882 100644 (file)
@@ -252,3 +252,9 @@ PlayerVideo::prepare ()
 {
        _in->prepare (_inter_size);
 }
+
+size_t
+PlayerVideo::memory_used () const
+{
+       return _in->memory_used();
+}
index 040145559a7e802bd66c67a41cde0da5fbc486bd..fe7ae384e13114bb171c703b6d47804f305c1d03 100644 (file)
@@ -91,6 +91,8 @@ public:
 
        bool same (boost::shared_ptr<const PlayerVideo> other) const;
 
+       size_t memory_used () const;
+
 private:
        boost::shared_ptr<const ImageProxy> _in;
        Crop _crop;
index ea702f138594a9217709786934c5b3ae76051b52..094b50d058c2bef13cece2d1dbe8df402bce4e21 100644 (file)
@@ -89,3 +89,9 @@ RawImageProxy::pixel_format () const
 {
        return _image->pixel_format ();
 }
+
+size_t
+RawImageProxy::memory_used () const
+{
+       return _image->memory_used ();
+}
index 28fd7f26362090241526ae92eaf2a7fe78d70be3..2b64cbd9b812e9d14f0159eb0c2ba2f213e9861c 100644 (file)
@@ -38,6 +38,7 @@ public:
        void send_binary (boost::shared_ptr<Socket>) const;
        bool same (boost::shared_ptr<const ImageProxy>) const;
        AVPixelFormat pixel_format () const;
+       size_t memory_used () const;
 
 private:
        boost::shared_ptr<Image> _image;
index a8688a1cd7f6d246562f63e90780cdda72600563..2fc39d53c663330794a263a8728ffa782a7888b9 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "video_ring_buffers.h"
 #include "player_video.h"
+#include "compose.hpp"
 #include <boost/foreach.hpp>
 #include <list>
 #include <iostream>
@@ -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<size_t, string>
+VideoRingBuffers::memory_used () const
+{
+       size_t m = 0;
+       for (list<pair<shared_ptr<PlayerVideo>, 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()));
+}
index cf61b90cc905c405d1a9c11b0dcac26f020479f9..887a5dc2fd2ca9e2c4c3c0858f9d519773b4441c 100644 (file)
@@ -39,6 +39,8 @@ public:
        bool empty () const;
        boost::optional<DCPTime> earliest () const;
 
+       std::pair<size_t, std::string> memory_used () const;
+
 private:
        mutable boost::mutex _mutex;
        std::list<std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> > _data;