Use iostreams instead of file descriptors for dumping.
[asdcplib.git] / src / AS_DCP.h
index 1cefa98de534e893579e85a7baddb5ac09d16a37..b49746b9c9fc589b46537d9dbe01f8c9bfd8358d 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2003-2007, John Hurst
+Copyright (c) 2003-2008, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -77,8 +77,9 @@ The following use cases are supported by the library:
  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:
+This project depends upon the following libraries:
  - OpenSSL http://www.openssl.org/
+ - Expat http://expat.sourceforge.net/ (optional)
 
 */
 
@@ -89,7 +90,7 @@ This project depends upon the following library:
 #include <stdio.h>
 #include <stdarg.h>
 #include <math.h>
-#include <iostream>
+#include <iosfwd>
 #include <string>
 #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 = 2;
-  const ui32_t VERSION_IMPMINOR = 17;
+  //
+  // The version number declaration and explanation have moved to ../configure.ac
   const char* Version();
 
   // UUIDs are passed around as strings of UUIDlen bytes
@@ -346,6 +338,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 +570,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);
 
@@ -768,6 +764,8 @@ namespace ASDCP {
          ui32_t   ContainerDuration;  // number of frames
       };
 
+      // 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);
 
@@ -970,6 +968,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);
 
@@ -1011,6 +1011,10 @@ namespace ASDCP {
          Result_t FillPictureDescriptor(PictureDescriptor&) const;
        };
 
+      // Parses the data in the frame buffer to fill in the picture descriptor. Copies
+      // the offset of the image data into start_of_data. Returns error if the parser fails.
+      Result_t ParseMetadataIntoDesc(const FrameBuffer&, PictureDescriptor&, byte_t* start_of_data = 0);
+
       // An object which reads a sequence of files containing JPEG 2000 pictures.
       class SequenceParser
        {
@@ -1125,10 +1129,20 @@ namespace ASDCP {
        SP_LEFT,
        SP_RIGHT
       };
+      
+      struct SFrameBuffer
+      {
+       JP2K::FrameBuffer Left;
+       JP2K::FrameBuffer Right;
 
+       SFrameBuffer(ui32_t size) {
+         Left.Capacity(size);
+         Right.Capacity(size);
+       }
+      };
 
       class MXFSWriter
-       {
+      {
          class h__SWriter;
          mem_ptr<h__SWriter> m_Writer;
          ASDCP_NO_COPY_CONSTRUCT(MXFSWriter);
@@ -1143,6 +1157,12 @@ namespace ASDCP {
          Result_t OpenWrite(const char* filename, const WriterInfo&,
                             const PictureDescriptor&, ui32_t HeaderSize = 16384);
 
+         // Writes a pair of frames of essence to the MXF file. If the optional AESEncContext
+         // argument is present, the essence is encrypted prior to writing.
+         // Fails if the file is not open, is finalized, or an operating system
+         // error occurs.
+         Result_t WriteFrame(const SFrameBuffer&, AESEncContext* = 0, HMACContext* = 0);
+
          // Writes a frame of essence to the MXF file. If the optional AESEncContext
          // argument is present, the essence is encrypted prior to writing.
          // Fails if the file is not open, is finalized, or an operating system
@@ -1183,6 +1203,15 @@ namespace ASDCP {
          // Returns RESULT_INIT if the file is not open.
          Result_t FillWriterInfo(WriterInfo&) const;
 
+         // Reads a pair of frames of essence from the MXF file. If the optional AESEncContext
+         // argument is present, the essence is decrypted after reading. If the MXF
+         // file is encrypted and the AESDecContext argument is NULL, the frame buffer
+         // will contain the ciphertext frame data. If the HMACContext argument is
+         // not NULL, the HMAC will be calculated (if the file supports it).
+         // Returns RESULT_INIT if the file is not open, failure if the frame number is
+         // out of range, or if optional decrypt or HAMC operations fail.
+         Result_t ReadFrame(ui32_t frame_number, SFrameBuffer&, AESDecContext* = 0, HMACContext* = 0) const;
+
          // Reads a frame of essence from the MXF file. If the optional AESEncContext
          // argument is present, the essence is decrypted after reading. If the MXF
          // file is encrypted and the AESDecContext argument is NULL, the frame buffer
@@ -1226,6 +1255,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);