1b5b03d6868779a0f517e182642df41bcf2701ad
[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
44 /** @class MXF
45  *  @brief Parent class for classes which represent MXF files.
46  */
47 class MXF : public Asset
48 {
49 public:
50         MXF (Fraction edit_rate);
51         MXF (boost::filesystem::path file);
52         ~MXF ();
53
54         bool equals (
55                 boost::shared_ptr<const Asset> other,
56                 EqualityOptions opt,
57                 NoteHandler note
58                 ) const;
59
60         /** Fill in a ADSCP::WriteInfo struct.
61          *  @param w struct to fill in.
62          *  @param standard INTEROP or SMPTE.
63          */
64         void fill_writer_info (ASDCP::WriterInfo* w, Standard standard);
65
66         /** @return true if the data is encrypted */
67         bool encrypted () const {
68                 return !_key_id.empty ();
69         }
70
71         /** Set the ID of the key that is used for encryption/decryption.
72          *  @param i key ID.
73          */
74         void set_key_id (std::string i) {
75                 _key_id = i;
76         }
77
78         /** @return the ID of the key used for encryption/decryption, or an empty string */
79         std::string key_id () const {
80                 return _key_id;
81         }
82
83         void set_key (Key);
84
85         /** @return encryption/decryption key, if one has been set */
86         boost::optional<Key> key () const {
87                 return _key;
88         }
89
90         /** @return encryption context, set up with any key that has been passed to set_key() */
91         ASDCP::AESEncContext* encryption_context () const {
92                 return _encryption_context;
93         }
94
95         /** Set the metadata that is written to the MXF file.
96          *  @param m Metadata.
97          */
98         void set_metadata (MXFMetadata m) {
99                 _metadata = m;
100         }
101
102         /** @return metadata from the MXF file */
103         MXFMetadata metadata () const {
104                 return _metadata;
105         }
106
107         Fraction edit_rate () const {
108                 return _edit_rate;
109         }
110
111         /** @return The total length of this content in video frames.
112          *  The amount of content presented may be less than this.
113          */
114         int64_t intrinsic_duration () const {
115                 return _intrinsic_duration;
116         }
117         
118 protected:
119         friend class MXFWriter;
120
121         virtual std::string asdcp_kind () const = 0;
122         std::string pkl_type (Standard standard) const;
123         void read_writer_info (ASDCP::WriterInfo const &);
124         
125         Fraction _edit_rate;
126         /** The total length of this content in video frames.  The amount of
127          *  content presented may be less than this.
128          */
129         int64_t _intrinsic_duration;
130         
131         ASDCP::AESEncContext* _encryption_context;
132         ASDCP::AESDecContext* _decryption_context;
133         /** ID of the key used for encryption/decryption, or an empty string */
134         std::string _key_id;
135         /** Key used for encryption/decryption, if there is one */
136         boost::optional<Key> _key;
137         MXFMetadata _metadata;
138 };
139
140 }
141
142 #endif