Bv2.1 7.2.3: Check that subtitle <StartTime> exists and is 0.
[libdcp.git] / src / asset_reader.h
index 01eddba6ebbe0ba9dd54abbf09e43f583df4f213..d1e0f10e8faacf9e35ed2952a7d9e08c6b2d5c05 100644 (file)
 
     You should have received a copy of the GNU General Public License
     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of portions of this program with the
+    OpenSSL library under certain conditions as described in each
+    individual source file, and distribute linked combinations
+    including the two.
+
+    You must obey the GNU General Public License in all respects
+    for all of the code used other than OpenSSL.  If you modify
+    file(s) with this exception, you may extend this exception to your
+    version of the file(s), but you are not obligated to do so.  If you
+    do not wish to do so, delete this exception statement from your
+    version.  If you delete this exception statement from all source
+    files in the program, then also delete it here.
 */
 
 #ifndef LIBDCP_ASSET_READER_H
 #define LIBDCP_ASSET_READER_H
 
-namespace ASDCP {
-       class AESDecContext;
-}
+#include "dcp_assert.h"
+#include "asset.h"
+#include "crypto_context.h"
+#include <asdcp/AS_DCP.h>
+#include <boost/noncopyable.hpp>
+#include <memory>
 
 namespace dcp {
 
-class MXF;
-
-class AssetReader
+template <class R, class F>
+class AssetReader : public boost::noncopyable
 {
 public:
-       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;
+       }
+
+       std::shared_ptr<const F> get_frame (int n) const
+       {
+               return std::shared_ptr<const F> (new F (_reader, n, _crypto_context));
+       }
+
+       R* reader () const {
+               return _reader;
+       }
 
 protected:
-       ASDCP::AESDecContext* _decryption_context;
+       R* _reader;
+       std::shared_ptr<DecryptionContext> _crypto_context;
 };
 
 }