Cope with e.g. truehd audio streams having not every audio frame arriving with a...
[dcpomatic.git] / src / lib / j2k_image_proxy.h
index 8fc9040d5a8eda0eccf621fbaeddcce1c1ded1f5..c20d89340318b2040bf3fc60a6c26b8d95e70845 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2017 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -21,6 +21,7 @@
 #include "image_proxy.h"
 #include <dcp/util.h>
 #include <dcp/data.h>
+#include <boost/thread/mutex.hpp>
 
 namespace dcp {
        class MonoPictureFrame;
@@ -31,8 +32,22 @@ class J2KImageProxy : public ImageProxy
 {
 public:
        J2KImageProxy (boost::filesystem::path path, dcp::Size, AVPixelFormat pixel_format);
-       J2KImageProxy (boost::shared_ptr<const dcp::MonoPictureFrame> frame, dcp::Size, AVPixelFormat pixel_format);
-       J2KImageProxy (boost::shared_ptr<const dcp::StereoPictureFrame> frame, dcp::Size, dcp::Eye, AVPixelFormat pixel_format);
+
+       J2KImageProxy (
+               boost::shared_ptr<const dcp::MonoPictureFrame> frame,
+               dcp::Size,
+               AVPixelFormat pixel_format,
+               boost::optional<int> forced_reduction
+               );
+
+       J2KImageProxy (
+               boost::shared_ptr<const dcp::StereoPictureFrame> frame,
+               dcp::Size,
+               dcp::Eye,
+               AVPixelFormat pixel_format,
+               boost::optional<int> forced_reduction
+               );
+
        J2KImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket);
 
        boost::shared_ptr<Image> image (
@@ -44,6 +59,7 @@ public:
        void send_binary (boost::shared_ptr<Socket>) const;
        /** @return true if our image is definitely the same as another, false if it is probably not */
        bool same (boost::shared_ptr<const ImageProxy>) const;
+       void prepare (boost::optional<dcp::Size> = boost::optional<dcp::Size>()) const;
        AVPixelFormat pixel_format () const {
                return _pixel_format;
        }
@@ -65,7 +81,9 @@ private:
        dcp::Data _data;
        dcp::Size _size;
        boost::optional<dcp::Eye> _eye;
-       mutable boost::shared_ptr<dcp::OpenJPEGImage> _j2k;
-       mutable boost::optional<dcp::Size> _j2k_target_size;
+       mutable boost::shared_ptr<dcp::OpenJPEGImage> _decompressed;
+       mutable boost::optional<dcp::Size> _target_size;
        AVPixelFormat _pixel_format;
+       mutable boost::mutex _mutex;
+       boost::optional<int> _forced_reduction;
 };