Rename crypt_chain -> signer_chain.
[libdcp.git] / src / picture_asset_writer.h
index 5c2b0fef83a688453a7d7997892941bd7ef01cdd..b6d2e92c8cca02fa0f4bde9ec4db4ed0b739581f 100644 (file)
 #include <boost/shared_ptr.hpp>
 #include <boost/utility.hpp>
 #include "metadata.h"
+#include "types.h"
 
 namespace libdcp {
 
-class MonoPictureAsset;        
-class StereoPictureAsset;      
+class PictureAsset;    
 
 struct FrameInfo
 {
@@ -49,21 +49,29 @@ struct FrameInfo
 class PictureAssetWriter : public boost::noncopyable
 {
 public:
+       virtual ~PictureAssetWriter () {}
        virtual FrameInfo write (uint8_t *, int) = 0;
-       virtual void fake_write (int) = 0;
        virtual void finalize () = 0;
+       virtual void fake_write (int) = 0;
        
 protected:
+       template <class P, class Q>
+       friend void start (PictureAssetWriter *, boost::shared_ptr<P>, Q *, uint8_t *, int);
+
+       PictureAssetWriter (PictureAsset *, bool, bool, MXFMetadata const &);
 
-       PictureAssetWriter (bool, MXFMetadata const &);
-       virtual void start (uint8_t *, int) = 0;
+       PictureAsset* _asset;
        
-       /** Number of picture frames written to the asset so far */
+       /** Number of picture frames written to the asset so far.  For stereo assets
+        *  this will be incremented for each eye (i.e. there will be twice the number
+        *  of frames as in a mono asset).
+        */
        int _frames_written;
        bool _started;
        /** true if finalize() has been called */
        bool _finalized;
        bool _overwrite;
+       bool _interop;
        MXFMetadata _metadata;
 };
 
@@ -73,21 +81,21 @@ protected:
  *  Objects of this class can only be created with MonoPictureAsset::start_write().
  *
  *  Frames can be written to the MonoPictureAsset by calling write() with a JPEG2000 image
- *  (a verbatim .j2 file).  finalize() must be called after the last frame has been written.
+ *  (a verbatim .j2c file).  finalize() must be called after the last frame has been written.
  *  The action of finalize() can't be done in MonoPictureAssetWriter's destructor as it may
  *  throw an exception.
  */
 class MonoPictureAssetWriter : public PictureAssetWriter
 {
 public:
-       FrameInfo write (uint8_t* data, int size);
+       FrameInfo write (uint8_t *, int);
        void fake_write (int size);
        void finalize ();
 
 private:
        friend class MonoPictureAsset;
 
-       MonoPictureAssetWriter (MonoPictureAsset *, bool, MXFMetadata const &);
+       MonoPictureAssetWriter (PictureAsset *, bool, bool, MXFMetadata const &);
        void start (uint8_t *, int);
 
        /* do this with an opaque pointer so we don't have to include
@@ -96,21 +104,29 @@ private:
           
        struct ASDCPState;
        boost::shared_ptr<ASDCPState> _state;
-
-       MonoPictureAsset* _asset;
 };
 
+/** A helper class for writing to StereoPictureAssets progressively (i.e. writing frame-by-frame,
+ *  rather than giving libdcp all the frames in one go).
+ *
+ *  Objects of this class can only be created with StereoPictureAsset::start_write().
+ *
+ *  Frames can be written to the MonoPictureAsset by calling write() with a JPEG2000 image
+ *  (a verbatim .j2c file).  finalize() must be called after the last frame has been written.
+ *  The action of finalize() can't be done in MonoPictureAssetWriter's destructor as it may
+ *  throw an exception.
+ */
 class StereoPictureAssetWriter : public PictureAssetWriter
 {
 public:
-       FrameInfo write (uint8_t* data, int size);
+       FrameInfo write (uint8_t *, int);
        void fake_write (int size);
        void finalize ();
 
 private:
        friend class StereoPictureAsset;
 
-       StereoPictureAssetWriter (StereoPictureAsset *, bool, MXFMetadata const &);
+       StereoPictureAssetWriter (PictureAsset *, bool, bool, MXFMetadata const &);
        void start (uint8_t *, int);
 
        /* do this with an opaque pointer so we don't have to include
@@ -120,7 +136,7 @@ private:
        struct ASDCPState;
        boost::shared_ptr<ASDCPState> _state;
 
-       StereoPictureAsset* _asset;
+       libdcp::Eye _next_eye;
 };
 
 }