1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
/*
Copyright (c), Bjoern Stresing, Patrick Bichiou, Wolfgang Ruppel,
John Hurst, Pierre-Anthony Lemieux
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Reader and writer classes for IAB Track Files, as defined in SMPTE ST 2067-201
*
* @file
*/
#ifndef AS_02_IAB_h__
#define AS_02_IAB_h__
#include "AS_02.h"
#include "Metadata.h"
namespace AS_02 {
namespace IAB {
/**
* Writes IAB Track Files as specified in ST SMPTE 2067-201
*
*/
class MXFWriter {
class h__Writer;
ASDCP::mem_ptr<h__Writer> m_Writer;
ui64_t m_ClipStart;
void Reset();
ASDCP_NO_COPY_CONSTRUCT(MXFWriter);
public:
MXFWriter();
virtual ~MXFWriter();
/**
* Must be preceded by a succesful OpenWrite() call followed by zero or more WriteFrame() calls
*
* Warning: direct manipulation of MXF structures can interfere
* with the normal operation of the wrapper. Caveat emptor!
*
* @return Header of the Track File
*
* @throws std::runtime_error if the Track File is not open
*/
virtual const ASDCP::MXF::OP1aHeader& OP1aHeader() const;
/**
* Must be preceded by a succesful OpenWrite() call followed by zero or more WriteFrame() calls
*
* Warning: direct manipulation of MXF structures can interfere
* with the normal operation of the wrapper. Caveat emptor!
*
* @return RIP of the Track File
*
* @throws std::runtime_error if the Track File is not open
*/
virtual const ASDCP::MXF::RIP& RIP() const;
/**
* Creates and prepares an IAB Track File for writing.
*
* Must be called following instantiation or after Finalize() call
*
* @param filename Path to the file. The file must no exist.
* @param Info MXF file metadata to be written.
* @param sub IAB Soundfield Subdescritor items to be written. MCATagName, MCATagSymbol, MCALabelDictionaryID, MCALinkID are ignored.
* @param conformsToSpecs Value of the ConformsToSpecifications preface item
* @param edit_rate Frame rate of the IA Bitstream
* @param sampling_rate Sampling rate of the audio essence within the IA Bitstream
*
* @return RESULT_OK indicates that frames are ready to be written,
* otherwise the reader is reset and the file is left is an undermined state.
*/
Result_t OpenWrite(
const std::string& filename,
const ASDCP::WriterInfo& Info,
const ASDCP::MXF::IABSoundfieldLabelSubDescriptor& sub,
const std::vector<ASDCP::UL>& conformsToSpecs,
const ASDCP::Rational& edit_rate,
const ASDCP::Rational& sampling_rate = ASDCP::SampleRate_48k
);
/**
* Writes a single frame.
*
* Must be preceded by a succesful OpenWrite() call followed by zero or more WriteFrame() calls
*
*
* @param frame Pointer to a complete IA Frame
* @param sz Size in bytes of the IA Frame
* @return RESULT_OK indicates that the frame is written and additional frames can be written,
* otherwise the reader is reset and the file is left is an undermined state.
*/
Result_t WriteFrame(const ui8_t* frame, ui32_t sz);
/**
* Writes a single frame.
*
* Must be preceded by a succesful OpenWrite() call followed by zero or more WriteFrame() calls
*
*
* @param frame a complete IA Frame
* @return RESULT_OK indicates that the frame is written and additional frames can be written,
* otherwise the reader is reset and the file is left is an undermined state.
*/
Result_t WriteFrame(const ASDCP::FrameBuffer& frame);
/**
* Writes an XML text document to the MXF file as per RP 2057. If the
* optional AESEncContext argument is present, the document is encrypted
* prior to writing. Fails if the file is not open, is finalized, or an
* operating system error occurs.
*/
Result_t AddDmsGenericPartUtf8Text(const ASDCP::FrameBuffer& frame_buffer, ASDCP::AESEncContext* enc = 0, ASDCP::HMACContext* hmac = 0,
const std::string& trackDescription = "Descriptive Track", const std::string& dataDescription = "");
/**
* Writes the Track File footer and closes the file.
*
* Must be preceded by a succesful OpenWrite() call followed by zero or more WriteFrame() calls
*
* @return RESULT_OK indicates that the frame is written and additional frames can be written,
* otherwise the reader is reset and the file is left is an undermined state.
*/
Result_t Finalize();
};
/**
* Reads IAB Track Files as specified in ST SMPTE 2067-201
*
*/
class MXFReader {
class h__Reader;
ASDCP::mem_ptr<h__Reader> m_Reader;
ASDCP::FrameBuffer m_FrameBuffer;
const Kumu::IFileReaderFactory& m_FileReaderFactory;
void Reset();
ASDCP_NO_COPY_CONSTRUCT(MXFReader);
public:
/* typedefs*/
typedef std::pair<size_t, const ui8_t*> Frame;
/* methods */
/**
* Construct MXF Reader
* .
* @param fileReaderFactory Abstract interface that allows
* to override asdcplib's file read access by a user implementation.
* Notice that the factory object reference needs to remain valid
* when performing OpenRead operation.
*/
MXFReader(const Kumu::IFileReaderFactory& fileReaderFactory);
virtual ~MXFReader();
/**
* Warning: direct manipulation of MXF structures can interfere
* with the normal operation of the wrapper. Caveat emptor!
*
* @return Header of the Track File
*
* @throws std::runtime_error if the Track File is not open
*/
virtual ASDCP::MXF::OP1aHeader& OP1aHeader() const;
/**
* Warning: direct manipulation of MXF structures can interfere
* with the normal operation of the wrapper. Caveat emptor!
*
* @return RIP of the Track File
*
* @throws std::runtime_error if the Track File is not open
*/
virtual const ASDCP::MXF::RIP& RIP() const;
/**
* Creates and prepares an IAB Track File for reading.
*
* @param filename Path to the file. The file must no exist.
*
* @return RESULT_OK indicates that frames are ready to be read,
* otherwise the reader is reset
*/
Result_t OpenRead(const std::string& filename);
/**
* Closes the IAB Track File.
*
* @return RESULT_OK indicates that the Track File was successfully closed.
*/
Result_t Close();
/**
* Fill a WriterInfo struct with the values from the Track File's header.
*
* @param writer_info Struct to be filled
* @return RESULT_OK indicates that writer_info was successfully filled.
*/
Result_t FillWriterInfo(ASDCP::WriterInfo& writer_info) const;
/**
* Reads an IA Frame.
*
* @param frame_number Index of the frame to be read. Must be in the range [0, GetFrameCount()).
* @param frame Frame data. Must not be modified. Remains valid until the next call to ReadFrame().
* @return RESULT_OK indicates that more frames are ready to be read,
* otherwise the file is closed and the reader reset
*/
Result_t ReadFrame(ui32_t frame_number, Frame& frame);
/**
* Reads an IA Frame.
*
* @param frame_number Index of the frame to be read. Must be in the range [0, GetFrameCount()).
* @param frame Frame data. Must not be modified. Remains valid until the next call to ReadFrame().
* @return RESULT_OK indicates that more frames are ready to be read,
* otherwise the file is closed and the reader reset
*/
Result_t ReadFrame(ui32_t frame_number, ASDCP::FrameBuffer& frame);
/** Reads a Generic Stream Partition payload. Returns RESULT_INIT if the file is
* not open, or RESULT_FORMAT if the SID is not present in the RIP, or if the
* actual partition at ByteOffset does not have a matching BodySID value.
* Encryption is not currently supported.
*/
Result_t ReadGenericStreamPartitionPayload(ui32_t SID, ASDCP::FrameBuffer& FrameBuf);
/**
* Returns the number of IA Frame in the Track File.
*
* @param frameCount Number of IA Frames
* @return RESULT_OK unless the file is not open
*/
Result_t GetFrameCount(ui32_t& frameCount) const;
// Print debugging information to stream
void DumpHeaderMetadata(FILE* = 0) const;
void DumpIndex(FILE* = 0) const;
};
} //namespace IAB
} // namespace AS_02
#endif // AS_02_IAB_h__
|