Keep encryption context in MXFWriter.
[libdcp.git] / src / mxf.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef LIBDCP_MXF_H
21 #define LIBDCP_MXF_H
22
23 #include "asset.h"
24 #include "key.h"
25 #include "metadata.h"
26
27 #include <boost/signals2.hpp>
28
29 namespace ASDCP {
30         class AESEncContext;
31         class AESDecContext;
32         class WriterInfo;
33 }
34
35 /* Undefine some stuff that the OS X 10.5 SDK defines */
36 #undef Key
37 #undef set_key
38
39 namespace dcp
40 {
41
42 class MXFMetadata;
43 class PictureMXFWriter; 
44
45 /** @class MXF
46  *  @brief Parent class for classes which represent MXF files.
47  */
48 class MXF : public Asset
49 {
50 public:
51         MXF ();
52         MXF (boost::filesystem::path file);
53         ~MXF ();
54
55         bool equals (
56                 boost::shared_ptr<const Asset> other,
57                 EqualityOptions opt,
58                 NoteHandler note
59                 ) const;
60
61         /** @return true if the data is encrypted */
62         bool encrypted () const {
63                 return _key_id;
64         }
65
66         /** Set the ID of the key that is used for encryption/decryption.
67          *  @param i key ID.
68          */
69         void set_key_id (std::string i) {
70                 _key_id = i;
71         }
72
73         /** @return the ID of the key used for encryption/decryption, if there is one */
74         boost::optional<std::string> key_id () const {
75                 return _key_id;
76         }
77
78         void set_key (Key);
79
80         /** @return encryption/decryption key, if one has been set */
81         boost::optional<Key> key () const {
82                 return _key;
83         }
84
85         /** Set the metadata that is written to the MXF file.
86          *  @param m Metadata.
87          */
88         void set_metadata (MXFMetadata m) {
89                 _metadata = m;
90         }
91
92         /** @return metadata from the MXF file */
93         MXFMetadata metadata () const {
94                 return _metadata;
95         }
96         
97 protected:
98         template <class P, class Q>
99         friend void start (PictureMXFWriter* writer, boost::shared_ptr<P> state, Standard standard, Q* mxf, uint8_t* data, int size);
100
101         void read_writer_info (ASDCP::WriterInfo const &);
102         /** Fill in a ADSCP::WriteInfo struct.
103          *  @param w struct to fill in.
104          *  @param standard INTEROP or SMPTE.
105          */
106         void fill_writer_info (ASDCP::WriterInfo* w, Standard standard);
107
108         ASDCP::AESDecContext* _decryption_context;
109         /** ID of the key used for encryption/decryption, if there is one */
110         boost::optional<std::string> _key_id;
111         /** Key used for encryption/decryption, if there is one */
112         boost::optional<Key> _key;
113         MXFMetadata _metadata;
114 };
115
116 }
117
118 #endif