Update copyright dates.
[asdcplib.git] / src / AS_DCP_MPEG2.cpp
index b3044f63f3d2551f641331543af037e4a8892138..98d55c62fcc1650ae82b89b1f9ee7124ea689446 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004-2007, John Hurst
+Copyright (c) 2004-2009, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -30,6 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include "AS_DCP_internal.h"
+#include <iostream>
+#include <iomanip>
 
 
 //------------------------------------------------------------------------------------------
@@ -46,7 +48,8 @@ MD_to_MPEG2_VDesc(MXF::MPEG2VideoDescriptor* VDescObj, MPEG2::VideoDescriptor& V
   VDesc.SampleRate             = VDescObj->SampleRate;
   VDesc.EditRate               = VDescObj->SampleRate;
   VDesc.FrameRate              = VDescObj->SampleRate.Numerator;
-  VDesc.ContainerDuration      = VDescObj->ContainerDuration;
+  assert(VDescObj->ContainerDuration <= 0xFFFFFFFFL);
+  VDesc.ContainerDuration      = (ui32_t) VDescObj->ContainerDuration;
 
   VDesc.FrameLayout            = VDescObj->FrameLayout;
   VDesc.StoredWidth            = VDescObj->StoredWidth;
@@ -92,6 +95,27 @@ MPEG2_VDesc_to_MD(MPEG2::VideoDescriptor& VDesc, MXF::MPEG2VideoDescriptor* VDes
   return RESULT_OK;
 }
 
+//
+std::ostream&
+ASDCP::MPEG2::operator << (std::ostream& strm, const VideoDescriptor& VDesc)
+{
+  strm << "        SampleRate: " << VDesc.SampleRate.Numerator << "/" << VDesc.SampleRate.Denominator << std::endl;
+  strm << "       FrameLayout: " << (unsigned) VDesc.FrameLayout << std::endl;
+  strm << "       StoredWidth: " << (unsigned) VDesc.StoredWidth << std::endl;
+  strm << "      StoredHeight: " << (unsigned) VDesc.StoredHeight << std::endl;
+  strm << "       AspectRatio: " << VDesc.AspectRatio.Numerator << "/" << VDesc.AspectRatio.Denominator << std::endl;
+  strm << "    ComponentDepth: " << (unsigned) VDesc.ComponentDepth << std::endl;
+  strm << " HorizontalSubsmpl: " << (unsigned) VDesc.HorizontalSubsampling << std::endl;
+  strm << "   VerticalSubsmpl: " << (unsigned) VDesc.VerticalSubsampling << std::endl;
+  strm << "       ColorSiting: " << (unsigned) VDesc.ColorSiting << std::endl;
+  strm << "  CodedContentType: " << (unsigned) VDesc.CodedContentType << std::endl;
+  strm << "          LowDelay: " << (unsigned) VDesc.LowDelay << std::endl;
+  strm << "           BitRate: " << (unsigned) VDesc.BitRate << std::endl;
+  strm << "   ProfileAndLevel: " << (unsigned) VDesc.ProfileAndLevel << std::endl;
+  strm << " ContainerDuration: " << (unsigned) VDesc.ContainerDuration << std::endl;
+
+  return strm;
+}
 
 //
 void
@@ -230,7 +254,7 @@ ASDCP::MPEG2::MXFReader::h__Reader::ReadFrame(ui32_t FrameNum, FrameBuffer& Fram
   if ( ! m_File.IsOpen() )
     return RESULT_INIT;
 
-  Result_t result = ReadEKLVPacket(FrameNum, FrameBuf, Dict::ul(MDD_MPEG2Essence), Ctx, HMAC);
+  Result_t result = ReadEKLVFrame(FrameNum, FrameBuf, Dict::ul(MDD_MPEG2Essence), Ctx, HMAC);
 
   if ( ASDCP_FAILURE(result) )
     return result;
@@ -492,7 +516,7 @@ ASDCP::MPEG2::MXFWriter::h__Writer::WriteFrame(const FrameBuffer& FrameBuf, AESE
 
   // update the index manager
   Entry.TemporalOffset = - FrameBuf.TemporalOffset();
-  Entry.KeyFrameOffset = - m_GOPOffset;
+  Entry.KeyFrameOffset = - m_GOPOffset;
   Entry.Flags = Flags;
   /*
   fprintf(stderr, "to: %4hd   ko: %4hd   c1: %4hd   c2: %4hd   fl: 0x%02x\n",
@@ -543,14 +567,12 @@ ASDCP::MPEG2::MXFWriter::OpenWrite(const char* filename, const WriterInfo& Info,
                                   const VideoDescriptor& VDesc, ui32_t HeaderSize)
 {
   m_Writer = new h__Writer;
+  m_Writer->m_Info = Info;
   
   Result_t result = m_Writer->OpenWrite(filename, HeaderSize);
 
   if ( ASDCP_SUCCESS(result) )
-    {
-      m_Writer->m_Info = Info;
-      result = m_Writer->SetSourceStream(VDesc);
-    }
+    result = m_Writer->SetSourceStream(VDesc);
 
   if ( ASDCP_FAILURE(result) )
     m_Writer.release();