Explicitly set the DirScanner handle to NULL (-1 for Windows) on instantiation.
[asdcplib.git] / src / TimedText_Parser.cpp
index aad4ea3ed83162dc5d2b38c22ab57c75cb20219a..d86ef7c4772524709b96cc7365fccb978f268e5d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2007-2008, John Hurst
+Copyright (c) 2007-2009, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -166,6 +166,9 @@ ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const char* file
 {
   Result_t result = ReadFileIntoString(filename, m_XMLDoc);
 
+  if ( KM_FAILURE(result) )
+    return result;
+
   if ( ! m_Root.ParseString(m_XMLDoc.c_str()) )
     return RESULT_FORMAT;
 
@@ -260,12 +263,19 @@ ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const char* file
 
   if ( InstanceList.empty() )
     {
-      DefaultLogSink(). Error("XML document contains no Subtitle elements!\n");
+      DefaultLogSink(). Error("XML document contains no Subtitle elements.\n");
       return RESULT_FORMAT;
     }
 
   // assumes 24/1 or 48/1 as constrained above
-  S12MTimecode beginTC(InstanceList.front()->GetAttrWithName("TimeIn"), m_TDesc.EditRate.Numerator);
+  assert(m_TDesc.EditRate.Denominator == 1);
+
+  S12MTimecode beginTC;
+  beginTC.SetFPS(m_TDesc.EditRate.Numerator);
+  XMLElement* StartTime = m_Root.GetChildWithName("StartTime");
+
+  if ( StartTime != 0 )
+    beginTC.DecodeString(StartTime->GetBody());
 
   for ( ei = InstanceList.begin(); ei != InstanceList.end(); ei++ )
     {
@@ -274,7 +284,12 @@ ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const char* file
        end_count = tmpTC.GetFrames();
     }
 
-  assert( end_count > beginTC.GetFrames() );
+  if ( end_count <= beginTC.GetFrames() )
+    {
+      DefaultLogSink(). Error("Timed Text file has zero-length timeline.\n");
+      return RESULT_FORMAT;
+    }
+
   m_TDesc.ContainerDuration = end_count - beginTC.GetFrames();
 
   return RESULT_OK;