Merge master.
[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 "content.h"
24 #include "key.h"
25 #include "metadata.h"
26 #include <boost/signals2.hpp>
27
28 namespace ASDCP {
29         class AESEncContext;
30         class AESDecContext;
31 }
32
33 /* Undefine some stuff that the OS X 10.5 SDK defines */
34 #undef Key
35 #undef set_key
36
37 namespace dcp
38 {
39
40 class MXFMetadata;      
41
42 /** @class MXF
43  *  @brief Parent class for classes which represent MXF files.
44  */
45 class MXF : public Content
46 {
47 public:
48         MXF (Fraction edit_rate);
49         MXF (boost::filesystem::path file);
50         ~MXF ();
51
52         /** @return the 4-character key type for this MXF (MDIK, MDAK, etc.) */
53         virtual std::string key_type () const = 0;
54         
55         bool equals (
56                 boost::shared_ptr<const Content> other,
57                 EqualityOptions opt,
58                 boost::function<void (NoteType, std::string)> note
59                 ) const;
60
61         /** Fill in a ADSCP::WriteInfo struct.
62          *  @param w struct to fill in.
63          *  @param standard INTEROP or SMPTE.
64          */
65         void fill_writer_info (ASDCP::WriterInfo* w, Standard standard);
66
67         /** @return true if the data is encrypted */
68         bool encrypted () const {
69                 return !_key_id.empty ();
70         }
71
72         /** Set the ID of the key that is used for encryption/decryption.
73          *  @param i key ID.
74          */
75         void set_key_id (std::string i) {
76                 _key_id = i;
77         }
78
79         /** @return the ID of the key used for encryption/decryption, or an empty string */
80         std::string key_id () const {
81                 return _key_id;
82         }
83
84         void set_key (Key);
85
86         /** @return encryption/decryption key, if one has been set */
87         boost::optional<Key> key () const {
88                 return _key;
89         }
90
91         /** @return encryption context, set up with any key that has been passed to set_key() */
92         ASDCP::AESEncContext* encryption_context () const {
93                 return _encryption_context;
94         }
95
96         /** Set the metadata that is written to the MXF file.
97          *  @param m Metadata.
98          */
99         void set_metadata (MXFMetadata m) {
100                 _metadata = m;
101         }
102
103         /** @return metadata from the MXF file */
104         MXFMetadata metadata () const {
105                 return _metadata;
106         }
107
108 protected:
109         std::string pkl_type (Standard standard) const;
110         void read_writer_info (ASDCP::WriterInfo const &);
111         
112         ASDCP::AESEncContext* _encryption_context;
113         ASDCP::AESDecContext* _decryption_context;
114         /** ID of the key used for encryption/decryption, or an empty string */
115         std::string _key_id;
116         /** Key used for encryption/decryption, if there is one */
117         boost::optional<Key> _key;
118         MXFMetadata _metadata;
119 };
120
121 }
122
123 #endif