Use VerificationNote more 'properly' in a fair few places.
[libdcp.git] / src / asset_reader.h
index 716e854d1aebe23a587c08ffff9da9e679f387d2..dbd2761b0798d68b0f17e36bc05db3dfec79cf93 100644 (file)
 #ifndef LIBDCP_ASSET_READER_H
 #define LIBDCP_ASSET_READER_H
 
+#include "dcp_assert.h"
+#include "asset.h"
+#include "crypto_context.h"
+#include <asdcp/AS_DCP.h>
 #include <boost/noncopyable.hpp>
-
-namespace ASDCP {
-       class AESDecContext;
-}
+#include <boost/shared_ptr.hpp>
 
 namespace dcp {
 
-class MXF;
-
+template <class R, class F>
 class AssetReader : public boost::noncopyable
 {
 public:
-       explicit AssetReader (MXF const * mxf);
-       virtual ~AssetReader ();
+       explicit AssetReader (Asset const * asset, boost::optional<Key> key, Standard standard)
+               : _crypto_context (new DecryptionContext (key, standard))
+       {
+               _reader = new R ();
+               DCP_ASSERT (asset->file ());
+               Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
+               if (ASDCP_FAILURE (r)) {
+                       delete _reader;
+                       boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
+               }
+       }
+
+       ~AssetReader ()
+       {
+               delete _reader;
+       }
+
+       boost::shared_ptr<const F> get_frame (int n) const
+       {
+               return boost::shared_ptr<const F> (new F (_reader, n, _crypto_context));
+       }
 
 protected:
-       ASDCP::AESDecContext* _decryption_context;
+       R* _reader;
+       boost::shared_ptr<DecryptionContext> _crypto_context;
 };
 
 }