@@ -27,7 +27,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2727THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828*/
2929/* ! \file AS_02.h
30- \version $Id: AS_02.h,v 1.12 2013/06/17 17:55:54 jhurst Exp $
30+ \version $Id: AS_02.h,v 1.15 2014/01/02 23:29:21 jhurst Exp $
3131 \brief AS-02 library, public interface
3232
3333This module implements MXF AS-02 is a set of file access objects that
@@ -97,7 +97,6 @@ namespace AS_02
9797 Result_t Lookup (ui32_t frame_num, ASDCP::MXF::IndexTableSegment::IndexEntry&) const ;
9898 };
9999
100-
101100
102101 // Returns size in bytes of a single sample of data described by ADesc
103102 inline ui32_t CalcSampleSize (const ASDCP::MXF::WaveAudioDescriptor& d)
@@ -118,6 +117,15 @@ namespace AS_02
118117 return CalcSampleSize (d) * CalcSamplesPerFrame (d, edit_rate);
119118 }
120119
120+ // Returns number of frames for data described by ADesc, given a duration in samples and an edit rate
121+ inline ui32_t CalcFramesFromDurationInSamples (const ui32_t durationInSamples, const ASDCP::MXF::WaveAudioDescriptor& d,
122+ const ASDCP::Rational& edit_rate)
123+ {
124+ return static_cast <ui32_t >(static_cast <ui64_t >(durationInSamples) *
125+ static_cast <ui64_t >(d.AudioSamplingRate .Denominator * edit_rate.Numerator ) /
126+ static_cast <ui64_t >(d.AudioSamplingRate .Numerator * edit_rate.Denominator ));
127+ }
128+
121129 } // namespace MXF
122130
123131 // ---------------------------------------------------------------------------------
@@ -134,7 +142,7 @@ namespace AS_02
134142 };
135143
136144 namespace JP2K
137- {
145+ {
138146 //
139147 class MXFWriter
140148 {
@@ -159,7 +167,7 @@ namespace AS_02
159167 ASDCP::MXF::InterchangeObject_list_t& essence_sub_descriptor_list,
160168 const ASDCP::Rational& edit_rate, const ui32_t & header_size = 16384 ,
161169 const IndexStrategy_t& strategy = IS_FOLLOW, const ui32_t & partition_space = 10 );
162-
170+
163171 // Writes a frame of essence to the MXF file. If the optional AESEncContext
164172 // argument is present, the essence is encrypted prior to writing.
165173 // Fails if the file is not open, is finalized, or an operating system
@@ -230,7 +238,7 @@ namespace AS_02
230238 // the reader to signal the number of samples to be read by each call to ReadFrame();
231239
232240 //
233- class MXFWriter
241+ class MXFWriter
234242 {
235243 class h__Writer ;
236244 ASDCP::mem_ptr<h__Writer> m_Writer;
@@ -306,6 +314,152 @@ namespace AS_02
306314 };
307315 } // namespace PCM
308316
317+ // ---------------------------------------------------------------------------------
318+ //
319+ namespace TimedText
320+ {
321+ using ASDCP::TimedText::TimedTextDescriptor;
322+ using ASDCP::TimedText::TimedTextResourceDescriptor;
323+ using ASDCP::TimedText::ResourceList_t;
324+
325+ //
326+ class ST2052_TextParser
327+ {
328+ class h__TextParser ;
329+ ASDCP::mem_ptr<h__TextParser> m_Parser;
330+ ASDCP_NO_COPY_CONSTRUCT (ST2052_TextParser);
331+
332+ public:
333+ ST2052_TextParser ();
334+ virtual ~ST2052_TextParser ();
335+
336+ // Opens an XML file for reading, parses data to provide a complete
337+ // set of stream metadata for the MXFWriter below.
338+ Result_t OpenRead (const std::string& filename) const ;
339+
340+ // Parse an XML string
341+ Result_t OpenRead (const std::string& xml_doc, const std::string& filename) const ;
342+
343+ // Fill a TimedTextDescriptor struct with the values from the file's contents.
344+ // Returns RESULT_INIT if the file is not open.
345+ Result_t FillTimedTextDescriptor (ASDCP::TimedText::TimedTextDescriptor&) const ;
346+
347+ // Reads the complete Timed Text Resource into the given string.
348+ Result_t ReadTimedTextResource (std::string&) const ;
349+
350+ // Reads the Ancillary Resource having the given ID. Fails if the buffer
351+ // is too small or the resource does not exist. The optional Resolver
352+ // argument can be provided which will be used to retrieve the resource
353+ // having a particulat UUID. If a Resolver is not supplied, the default
354+ // internal resolver will return the contents of the file having the UUID
355+ // as the filename. The filename must exist in the same directory as the
356+ // XML file opened with OpenRead().
357+ Result_t ReadAncillaryResource (const Kumu::UUID&, ASDCP::TimedText::FrameBuffer&,
358+ const ASDCP::TimedText::IResourceResolver* Resolver = 0 ) const ;
359+ };
360+
361+ //
362+ class MXFWriter
363+ {
364+ class h__Writer ;
365+ ASDCP::mem_ptr<h__Writer> m_Writer;
366+ ASDCP_NO_COPY_CONSTRUCT (MXFWriter);
367+
368+ public:
369+ MXFWriter ();
370+ virtual ~MXFWriter ();
371+
372+ // Warning: direct manipulation of MXF structures can interfere
373+ // with the normal operation of the wrapper. Caveat emptor!
374+ virtual ASDCP::MXF::OP1aHeader& OP1aHeader ();
375+ virtual ASDCP::MXF::RIP& RIP ();
376+
377+ // Open the file for writing. The file must not exist. Returns error if
378+ // the operation cannot be completed or if nonsensical data is discovered
379+ // in the essence descriptor.
380+ Result_t OpenWrite (const std::string& filename, const ASDCP::WriterInfo&,
381+ const ASDCP::TimedText::TimedTextDescriptor&, ui32_t HeaderSize = 16384 );
382+
383+ // Writes the Timed-Text Resource to the MXF file. The file must be UTF-8
384+ // encoded. If the optional AESEncContext argument is present, the essence
385+ // is encrypted prior to writing. Fails if the file is not open, is finalized,
386+ // or an operating system error occurs.
387+ // This method may only be called once, and it must be called before any
388+ // call to WriteAncillaryResource(). RESULT_STATE will be returned if these
389+ // conditions are not met.
390+ Result_t WriteTimedTextResource (const std::string& XMLDoc, ASDCP::AESEncContext* = 0 , ASDCP::HMACContext* = 0 );
391+
392+ // Writes an Ancillary Resource to the MXF file. If the optional AESEncContext
393+ // argument is present, the essence is encrypted prior to writing.
394+ // Fails if the file is not open, is finalized, or an operating system
395+ // error occurs. RESULT_STATE will be returned if the method is called before
396+ // WriteTimedTextResource()
397+ Result_t WriteAncillaryResource (const ASDCP::TimedText::FrameBuffer&, ASDCP::AESEncContext* = 0 , ASDCP::HMACContext* = 0 );
398+
399+ // Closes the MXF file, writing the index and revised header.
400+ Result_t Finalize ();
401+ };
402+
403+ //
404+ class MXFReader
405+ {
406+ class h__Reader ;
407+ ASDCP::mem_ptr<h__Reader> m_Reader;
408+ ASDCP_NO_COPY_CONSTRUCT (MXFReader);
409+
410+ public:
411+ MXFReader ();
412+ virtual ~MXFReader ();
413+
414+ // Warning: direct manipulation of MXF structures can interfere
415+ // with the normal operation of the wrapper. Caveat emptor!
416+ virtual ASDCP::MXF::OP1aHeader& OP1aHeader ();
417+ virtual AS_02::MXF::AS02IndexReader& AS02IndexReader ();
418+ virtual ASDCP::MXF::RIP& RIP ();
419+
420+ // Open the file for reading. The file must exist. Returns error if the
421+ // operation cannot be completed.
422+ Result_t OpenRead (const std::string& filename) const ;
423+
424+ // Returns RESULT_INIT if the file is not open.
425+ Result_t Close () const ;
426+
427+ // Fill a TimedTextDescriptor struct with the values from the file's header.
428+ // Returns RESULT_INIT if the file is not open.
429+ Result_t FillTimedTextDescriptor (ASDCP::TimedText::TimedTextDescriptor&) const ;
430+
431+ // Fill a WriterInfo struct with the values from the file's header.
432+ // Returns RESULT_INIT if the file is not open.
433+ Result_t FillWriterInfo (ASDCP::WriterInfo&) const ;
434+
435+ // Reads the complete Timed Text Resource into the given string. Fails if the resource
436+ // is encrypted and AESDecContext is NULL (use the following method to retrieve the
437+ // raw ciphertet block).
438+ Result_t ReadTimedTextResource (std::string&, ASDCP::AESDecContext* = 0 , ASDCP::HMACContext* = 0 ) const ;
439+
440+ // Reads the complete Timed Text Resource from the MXF file. If the optional AESEncContext
441+ // argument is present, the resource is decrypted after reading. If the MXF
442+ // file is encrypted and the AESDecContext argument is NULL, the frame buffer
443+ // will contain the ciphertext frame data. If the HMACContext argument is
444+ // not NULL, the HMAC will be calculated (if the file supports it).
445+ // Returns RESULT_INIT if the file is not open, failure if the frame number is
446+ // out of range, or if optional decrypt or HAMC operations fail.
447+ Result_t ReadTimedTextResource (ASDCP::TimedText::FrameBuffer&, ASDCP::AESDecContext* = 0 , ASDCP::HMACContext* = 0 ) const ;
448+
449+ // Reads the timed-text resource having the given UUID from the MXF file. If the
450+ // optional AESEncContext argument is present, the resource is decrypted after
451+ // reading. If the MXF file is encrypted and the AESDecContext argument is NULL,
452+ // the frame buffer will contain the ciphertext frame data. If the HMACContext
453+ // argument is not NULL, the HMAC will be calculated (if the file supports it).
454+ // Returns RESULT_INIT if the file is not open, failure if the frame number is
455+ // out of range, or if optional decrypt or HAMC operations fail.
456+ Result_t ReadAncillaryResource (const Kumu::UUID&, ASDCP::TimedText::FrameBuffer&, ASDCP::AESDecContext* = 0 , ASDCP::HMACContext* = 0 ) const ;
457+
458+ // Print debugging information to stream
459+ void DumpHeaderMetadata (FILE* = 0 ) const ;
460+ void DumpIndex (FILE* = 0 ) const ;
461+ };
462+ } // namespace TimedText
309463
310464
311465} // namespace AS_02
0 commit comments