rrrrr
[asdcplib.git] / src / AS_DCP.h
index 65442e146da701f5ec2fcb0fb131920ecb3c9c86..383f270b6ca25b3e8f89722687db37be9868b495 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2003-2008, John Hurst
+Copyright (c) 2003-2010, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -28,20 +28,18 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     \version $Id$       
     \brief   AS-DCP library, public interface
 
-The asdcplib library is a set of wrapper objects that offer simplified
-access to files conforming to the file formats proposed by the SMPTE
-D-Cinema packaging working group DC28.20.  The file format, labeled
-AS-DCP, is described in series of separate documents which include but
-may not be limited to:
+The asdcplib library is a set of file access objects that offer simplified
+access to files conforming to the standards published by the SMPTE
+D-Cinema Technology Committee 21DC. The file format, labeled AS-DCP,
+is described in series of separate documents which include but may not
+be be limited to:
 
- o MXF Interop Track File Specification
- o MXF Interop Track File Essence Encryption Specification
- o MXF Interop Operational Constraints Specification
+ o SMPTE 429-2-2009 DCP Operational Constraints
  o SMPTE 429-3-2006 Track File Specification
  o SMPTE 429-4-2006 JPEG 2000 for D-Cinema
- o SMPTE 429-5-200X Timed Text Track File
+ o SMPTE 429-5-2009 Timed Text Track File
  o SMPTE 429-6-2006 Essence Encryption Specification
- o SMPTE 429-10-200X Stereoscopic Image Track File
+ o SMPTE 429-10-2008 Stereoscopic Image Track File
  o SMPTE 330M - UMID
  o SMPTE 336M - KLV
  o SMPTE 377M - MXF
@@ -53,33 +51,35 @@ may not be limited to:
  o IETF RFC 2104 - HMAC/SHA1
  o NIST FIPS 197 - AES (Rijndael)
 
+ o MXF Interop Track File Specification
+ o MXF Interop Track File Essence Encryption Specification
+ o MXF Interop Operational Constraints Specification
+ - Note: the MXF Interop documents are not formally published.
+   Contact the asdcplib support address to get copies.
+
 The following use cases are supported by the library:
 
- o Write a plaintext MPEG2 Video Elementary Stream to a plaintext ASDCP file
- o Write a plaintext MPEG2 Video Elementary Stream to a ciphertext ASDCP file
- o Read a plaintext MPEG2 Video Elementary Stream from a plaintext ASDCP file
- o Read a plaintext MPEG2 Video Elementary Stream from a ciphertext ASDCP file
- o Read a ciphertext MPEG2 Video Elementary Stream from a ciphertext ASDCP file
- o Write one or more plaintext JPEG 2000 codestreams to a plaintext ASDCP file
- o Write one or more plaintext JPEG 2000 codestreams to a ciphertext ASDCP file
- o Read one or more plaintext JPEG 2000 codestreams from a plaintext ASDCP file
- o Read one or more plaintext JPEG 2000 codestreams from a ciphertext ASDCP file
- o Read one or more ciphertext JPEG 2000 codestreams from a ciphertext ASDCP file
- o Write one or more plaintext JPEG 2000 stereoscopic codestream pairs to a plaintext ASDCP file
- o Write one or more plaintext JPEG 2000 stereoscopic codestream pairs to a ciphertext ASDCP file
- o Read one or more plaintext JPEG 2000 stereoscopic codestream pairs from a plaintext ASDCP file
- o Read one or more plaintext JPEG 2000 stereoscopic codestream pairs from a ciphertext ASDCP file
- o Read one or more ciphertext JPEG 2000 stereoscopic codestream pairs from a ciphertext ASDCP file
- o Write one or more plaintext PCM audio streams to a plaintext ASDCP file
- o Write one or more plaintext PCM audio streams to a ciphertext ASDCP file
- o Read one or more plaintext PCM audio streams from a plaintext ASDCP file
- o Read one or more plaintext PCM audio streams from a ciphertext ASDCP file
- o Read one or more ciphertext PCM audio streams from a ciphertext ASDCP file
- o Read header metadata from an ASDCP file
-
-This project depends upon the following library:
- - OpenSSL http://www.openssl.org/
+ o Write essence to a plaintext or ciphertext AS-DCP file:
+     MPEG2 Video Elementary Stream
+     JPEG 2000 codestreams
+     JPEG 2000 stereoscopic codestream pairs
+     PCM audio streams
+     SMPTE 429-7 Timed Text XML with font and image resources
 
+ o Read essence from a plaintext or ciphertext AS-DCP file:
+     MPEG2 Video Elementary Stream
+     JPEG 2000 codestreams
+     JPEG 2000 stereoscopic codestream pairs
+     PCM audio streams
+     SMPTE 429-7 Timed Text XML with font and image resources
+
+ o Read header metadata from an AS-DCP file
+
+This project depends upon the following libraries:
+ - OpenSSL http://www.openssl.org/
+ - Expat http://expat.sourceforge.net/  or
+     Xerces-C http://xerces.apache.org/xerces-c/
+   An XML library is not needed if you don't need support for SMPTE 429-5-2009.
 */
 
 #ifndef _AS_DCP_H_
@@ -89,8 +89,9 @@ This project depends upon the following library:
 #include <stdio.h>
 #include <stdarg.h>
 #include <math.h>
-#include <iostream>
+#include <iosfwd>
 #include <string>
+#include <cstring>
 #include <list>
 
 //--------------------------------------------------------------------------------
@@ -145,17 +146,8 @@ typedef unsigned int   ui32_t;
 // All library components are defined in the namespace ASDCP
 //
 namespace ASDCP {
-  // The version number consists of three segments: major, API minor, and
-  // implementation minor. Whenever a change is made to AS_DCP.h, the API minor
-  // version will increment. Changes made to the internal implementation will
-  // result in the incrementing of the implementation minor version.
-
-  // For example, if asdcplib version 1.0.0 were modified to accomodate changes
-  // in file format, and if no changes were made to AS_DCP.h, the new version would be
-  // 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1.
-  const ui32_t VERSION_MAJOR = 1;
-  const ui32_t VERSION_APIMINOR = 3;
-  const ui32_t VERSION_IMPMINOR = 18;
+  //
+  // The version number declaration and explanation have moved to ../configure.ac
   const char* Version();
 
   // UUIDs are passed around as strings of UUIDlen bytes
@@ -254,6 +246,18 @@ namespace ASDCP {
     inline bool operator!=(const Rational& rhs) const {
       return ( rhs.Numerator != Numerator || rhs.Denominator != Denominator );
     }
+
+    inline bool operator<(const Rational& rhs) {
+      if ( Numerator < rhs.Numerator )     return true;
+      if ( Numerator == rhs.Numerator && Denominator < rhs.Denominator )    return true;
+      return false;
+    }
+    inline bool operator>(const Rational& rhs) {
+      if ( Numerator > rhs.Numerator )     return true;
+      if ( Numerator == rhs.Numerator && Denominator > rhs.Denominator )     return true;
+      return false;
+    }
   };
 
   // common edit rates, use these instead of hard coded constants
@@ -263,6 +267,14 @@ namespace ASDCP {
   const Rational SampleRate_48k(48000,1);
   const Rational SampleRate_96k(96000,1);
 
+  // Additional frame rates, see ST 428-11
+  // These rates are new and not supported by all systems. Do not assume that
+  // a package made using on of these rates will work just anywhere!
+  const Rational EditRate_25(25,1);
+  const Rational EditRate_30(30,1);
+  const Rational EditRate_50(50,1);
+  const Rational EditRate_60(60,1);
+
   // Non-reference counting container for internal member objects.
   // Please do not use this class for any other purpose.
   template <class T>
@@ -294,19 +306,26 @@ namespace ASDCP {
   // MXF files use SMPTE Universal Labels to identify data items. The set of Labels
   // in a file is determined by the MXF Operational Pattern and any constraining
   // documentation. There are currently two flavors of AS-DCP file in use: MXF Interop
-  // and SMPTE. The two differ only in the values of two labels:
+  // (AKA JPEG Interop) and SMPTE. The two differ in the values of three labels:
   //
-  //   OP Atom     / Interop : 06 0e 2b 34 04 01 01 01  0d 01 02 01 10 00 00 00
-  //   OP Atom     / SMPTE   : 06 0e 2b 34 04 01 01 02  0d 01 02 01 10 00 00 00
-  // and 
-  //   EKLV Packet / Interop : 06 0e 2b 34 02 04 01 07  0d 01 03 01 02 7e 01 00
-  //   EKLV Packet / SMPTE   : 06 0e 2b 34 02 04 01 01  0d 01 03 01 02 7e 01 00
+  //   OPAtom
+  //      Interop : 06 0e 2b 34 04 01 01 01  0d 01 02 01 10 00 00 00
+  //      SMPTE   : 06 0e 2b 34 04 01 01 02  0d 01 02 01 10 00 00 00
+  //
+  //   EKLV Packet:
+  //      Interop : 06 0e 2b 34 02 04 01 07  0d 01 03 01 02 7e 01 00
+  //      SMPTE   : 06 0e 2b 34 02 04 01 01  0d 01 03 01 02 7e 01 00
+  //
+  //   GenericDescriptor/SubDescriptors:
+  //      Interop : 06 0e 2b 34 01 01 01 02  06 01 01 04 06 10 00 00
+  //      SMPTE   : 06 0e 2b 34 01 01 01 09  06 01 01 04 06 10 00 00
   //
   // asdcplib will read any (otherwise valid) file which has any combination of the
   // above values. When writing files, MXF Interop labels are used by default. To
   // write a file containing SMPTE labels, replace the default label set value in
   // the WriterInfo before calling OpenWrite()
   //
+  //
   enum LabelSet_t
   {
     LS_MXF_UNKNOWN,
@@ -346,6 +365,8 @@ namespace ASDCP {
     }
   };
 
+  // Print WriterInfo to std::ostream
+  std::ostream& operator << (std::ostream& strm, const WriterInfo& winfo);
   // Print WriterInfo to stream, stderr by default.
   void WriterInfoDump(const WriterInfo&, FILE* = 0);
 
@@ -576,6 +597,8 @@ namespace ASDCP {
          ui32_t   ContainerDuration;       // 
       };
 
+      // Print VideoDescriptor to std::ostream
+      std::ostream& operator << (std::ostream& strm, const VideoDescriptor& vdesc);
       // Print VideoDescriptor to stream, stderr by default.
       void VideoDescriptorDump(const VideoDescriptor&, FILE* = 0);
 
@@ -752,12 +775,29 @@ namespace ASDCP {
        };
     } // namespace MPEG2
 
+  //---------------------------------------------------------------------------------
   //
   namespace PCM
     {
+      // The default value of the ChannelFormat element of the AudioDescriptor struct
+      // is CF_NONE. If the value is set to one of the other ChannelFormat_t enum
+      // values, the file's Wave Audio Descriptor will contain a Channel Assignment
+      // element.
+      //
+      // The channel format should be one of (CF_CFG_1, CF_CFG_2, or CF_CFG_3) for
+      // SMPTE 429-2 files. It should normally be CF_NONE for JPEG Interop files, but
+      // the 429-2 may also be used.
+      //
+      enum ChannelFormat_t {
+       CF_NONE,
+       CF_CFG_1, // 5.1 with optional HI/VI
+       CF_CFG_2, // 6.1 (5.1 + center surround) with optional HI/VI
+       CF_CFG_3, // 7.1 with optional HI/VI
+      };
+
       struct AudioDescriptor
        {
-         Rational SampleRate;         // rate of frame wrapping
+         Rational EditRate;         // rate of frame wrapping
          Rational AudioSamplingRate;  // rate of audio sample
          ui32_t   Locked;             // 
          ui32_t   ChannelCount;       // number of channels
@@ -766,8 +806,11 @@ namespace ASDCP {
          ui32_t   AvgBps;             // 
          ui32_t   LinkedTrackID;      // 
          ui32_t   ContainerDuration;  // number of frames
+         ChannelFormat_t ChannelFormat; // audio channel arrangement
       };
 
+      // Print AudioDescriptor to std::ostream
+      std::ostream& operator << (std::ostream& strm, const AudioDescriptor& adesc);
       // Print debugging information to stream (stderr default)
       void   AudioDescriptorDump(const AudioDescriptor&, FILE* = 0);
 
@@ -780,7 +823,7 @@ namespace ASDCP {
       // Returns number of samples per frame of data described by ADesc
       inline ui32_t CalcSamplesPerFrame(const AudioDescriptor& ADesc)
        {
-         double tmpd = ADesc.AudioSamplingRate.Quotient() / ADesc.SampleRate.Quotient();
+         double tmpd = ADesc.AudioSamplingRate.Quotient() / ADesc.EditRate.Quotient();
          return (ui32_t)ceil(tmpd);
        }
 
@@ -902,6 +945,7 @@ namespace ASDCP {
        };
     } // namespace PCM
 
+  //---------------------------------------------------------------------------------
   //
   namespace JP2K
     {
@@ -970,6 +1014,8 @@ namespace ASDCP {
        QuantizationDefault_t QuantizationDefault;
       };
 
+      // Print debugging information to std::ostream
+      std::ostream& operator << (std::ostream& strm, const PictureDescriptor& pdesc);
       // Print debugging information to stream (stderr default)
       void   PictureDescriptorDump(const PictureDescriptor&, FILE* = 0);
 
@@ -1036,6 +1082,15 @@ namespace ASDCP {
          // mismatch is detected.
          Result_t OpenRead(const char* filename, bool pedantic = false) const;
 
+         // Opens a file sequence for reading.  The sequence is expected to contain one or
+         // more filenames, each naming a file containing the codestream for exactly one
+         // picture. The parser will automatically parse enough data
+         // from the first file to provide a complete set of stream metadata for the
+         // MXFWriter below.  If the "pedantic" parameter is given and is true, the
+         // parser will check the metadata for each codestream and fail if a 
+         // mismatch is detected.
+         Result_t OpenRead(const std::list<std::string>& file_list, bool pedantic = false) const;
+
          // Fill a PictureDescriptor struct with the values from the first file's codestream.
          // Returns RESULT_INIT if the directory is not open.
          Result_t FillPictureDescriptor(PictureDescriptor&) const;
@@ -1228,6 +1283,7 @@ namespace ASDCP {
        };
     } // namespace JP2K
 
+  //---------------------------------------------------------------------------------
   //
   namespace TimedText
     {
@@ -1255,6 +1311,8 @@ namespace ASDCP {
       TimedTextDescriptor() : ContainerDuration(0), EncodingName("UTF-8") {} // D-Cinema format is always UTF-8
       };
 
+      // Print debugging information to std::ostream
+      std::ostream& operator << (std::ostream& strm, const TimedTextDescriptor& tinfo);
       // Print debugging information to stream (stderr default)
       void   DescriptorDump(const TimedTextDescriptor&, FILE* = 0);
 
@@ -1300,13 +1358,18 @@ namespace ASDCP {
          DCSubtitleParser();
          virtual ~DCSubtitleParser();
 
-         // Opens the XML file for reading, parse data to provide a complete
+         // Opens an XML file for reading, parses data to provide a complete
          // set of stream metadata for the MXFWriter below.
          Result_t OpenRead(const char* filename) const;
 
+         // Parses an XML document to provide a complete set of stream metadata
+         // for the MXFWriter below. The optional filename argument is used to
+         // initialize the default resource resolver (see ReadAncillaryResource).
+         Result_t OpenRead(const std::string& xml_doc, const char* filename = 0) const;
+
          // Fill a TimedTextDescriptor struct with the values from the file's contents.
          // Returns RESULT_INIT if the file is not open.
-         Result_t FillDescriptor(TimedTextDescriptor&) const;
+         Result_t FillTimedTextDescriptor(TimedTextDescriptor&) const;
 
          // Reads the complete Timed Text Resource into the given string.
          Result_t ReadTimedTextResource(std::string&) const;
@@ -1379,7 +1442,7 @@ namespace ASDCP {
 
          // Fill a TimedTextDescriptor struct with the values from the file's header.
          // Returns RESULT_INIT if the file is not open.
-         Result_t FillDescriptor(TimedTextDescriptor&) const;
+         Result_t FillTimedTextDescriptor(TimedTextDescriptor&) const;
 
          // Fill a WriterInfo struct with the values from the file's header.
          // Returns RESULT_INIT if the file is not open.