2 Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
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
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.
35 /** @file src/asset_reader.h
36 * @brief AssetReader class
40 #ifndef LIBDCP_ASSET_READER_H
41 #define LIBDCP_ASSET_READER_H
45 #include "crypto_context.h"
46 #include "dcp_assert.h"
47 #include "filesystem.h"
48 #include <asdcp/AS_DCP.h>
56 class MonoPictureAsset;
58 class StereoPictureAsset;
61 template <class R, class F>
65 AssetReader (AssetReader const&) = delete;
66 AssetReader& operator== (AssetReader const&) = delete;
73 std::shared_ptr<const F> get_frame (int n) const
75 /* Can't use make_shared here as the constructor is private */
76 return std::shared_ptr<const F> (new F(_reader, n, _crypto_context, _check_hmac));
83 void set_check_hmac (bool check) {
89 std::shared_ptr<DecryptionContext> _crypto_context;
92 friend class AtmosAsset;
93 friend class MonoPictureAsset;
94 friend class SoundAsset;
95 friend class StereoPictureAsset;
97 explicit AssetReader (Asset const * asset, boost::optional<Key> key, Standard standard)
98 : _crypto_context (new DecryptionContext(key, standard))
101 DCP_ASSERT (asset->file());
102 auto const r = _reader->OpenRead(dcp::filesystem::fix_long_path(*asset->file()).string().c_str());
103 if (ASDCP_FAILURE(r)) {
105 boost::throw_exception (FileError("could not open MXF file for reading", asset->file().get(), r));
109 bool _check_hmac = true;