libdcp
asset_reader.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
6  libdcp is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  libdcp is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with libdcp. If not, see <http://www.gnu.org/licenses/>.
18 
19  In addition, as a special exception, the copyright holders give
20  permission to link the code of portions of this program with the
21  OpenSSL library under certain conditions as described in each
22  individual source file, and distribute linked combinations
23  including the two.
24 
25  You must obey the GNU General Public License in all respects
26  for all of the code used other than OpenSSL. If you modify
27  file(s) with this exception, you may extend this exception to your
28  version of the file(s), but you are not obligated to do so. If you
29  do not wish to do so, delete this exception statement from your
30  version. If you delete this exception statement from all source
31  files in the program, then also delete it here.
32 */
33 
34 
40 #ifndef LIBDCP_ASSET_READER_H
41 #define LIBDCP_ASSET_READER_H
42 
43 
44 #include "asset.h"
45 #include "crypto_context.h"
46 #include "dcp_assert.h"
47 #include <asdcp/AS_DCP.h>
48 #include <memory>
49 
50 
51 namespace dcp {
52 
53 
54 class AtmosAsset;
55 class MonoPictureAsset;
56 class SoundAsset;
57 class StereoPictureAsset;
58 
59 
60 template <class R, class F>
62 {
63 public:
64  AssetReader (AssetReader const&) = delete;
65  AssetReader& operator== (AssetReader const&) = delete;
66 
67  ~AssetReader ()
68  {
69  delete _reader;
70  }
71 
72  std::shared_ptr<const F> get_frame (int n) const
73  {
74  /* Can't use make_shared here as the constructor is private */
75  return std::shared_ptr<const F> (new F(_reader, n, _crypto_context, _check_hmac));
76  }
77 
78  R* reader () const {
79  return _reader;
80  }
81 
82  void set_check_hmac (bool check) {
83  _check_hmac = check;
84  }
85 
86 protected:
87  R* _reader = nullptr;
88  std::shared_ptr<DecryptionContext> _crypto_context;
89 
90 private:
91  friend class AtmosAsset;
92  friend class MonoPictureAsset;
93  friend class SoundAsset;
94  friend class StereoPictureAsset;
95 
96  explicit AssetReader (Asset const * asset, boost::optional<Key> key, Standard standard)
97  : _crypto_context (new DecryptionContext(key, standard))
98  {
99  _reader = new R ();
100  DCP_ASSERT (asset->file());
101  auto const r = _reader->OpenRead (asset->file()->string().c_str());
102  if (ASDCP_FAILURE(r)) {
103  delete _reader;
104  boost::throw_exception (FileError("could not open MXF file for reading", asset->file().get(), r));
105  }
106  }
107 
108  bool _check_hmac = true;
109 };
110 
111 
112 }
113 
114 
115 #endif
Asset class.
Parent class for DCP assets, i.e. picture, sound, subtitles, closed captions, CPLs,...
Definition: asset.h:70
boost::optional< boost::filesystem::path > file() const
Definition: asset.h:97
An asset of Dolby ATMOS sound data.
Definition: atmos_asset.h:59
An exception related to a file.
Definition: exceptions.h:56
A 2D (monoscopic) picture asset.
Representation of a sound asset.
Definition: sound_asset.h:73
A 3D (stereoscopic) picture asset.
DCP_ASSERT macro.
Namespace for everything in libdcp.
Definition: array_data.h:50