2 Copyright (c) 2013-2014, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /*! \file ST2052_TimedText.cpp
29 \brief AS-DCP library, PCM essence reader and writer implementation
33 #include "AS_02_internal.h"
37 using namespace ASDCP;
39 using Kumu::DefaultLogSink;
42 const char* c_dcst_namespace_name = "http://www.smpte-ra.org/schemas/428-7/2007/DCST";
44 //------------------------------------------------------------------------------------------
46 typedef std::map<Kumu::UUID, ASDCP::TimedText::MIMEType_t> ResourceTypeMap_t;
48 class AS_02::TimedText::ST2052_TextParser::h__TextParser
51 ResourceTypeMap_t m_ResourceTypes;
54 ASDCP_NO_COPY_CONSTRUCT(h__TextParser);
57 std::string m_Filename;
59 TimedTextDescriptor m_TDesc;
60 ASDCP::mem_ptr<ASDCP::TimedText::LocalFilenameResolver> m_DefaultResolver;
62 h__TextParser() : m_Root("**ParserRoot**")
64 memset(&m_TDesc.AssetID, 0, UUIDlen);
69 ASDCP::TimedText::IResourceResolver* GetDefaultResolver()
71 if ( m_DefaultResolver.empty() )
73 ASDCP::TimedText::LocalFilenameResolver *resolver = new ASDCP::TimedText::LocalFilenameResolver;
74 resolver->OpenRead(PathDirname(m_Filename));
75 m_DefaultResolver = resolver;
78 return m_DefaultResolver;
81 Result_t OpenRead(const std::string& filename);
82 Result_t OpenRead(const std::string& xml_doc, const std::string& filename);
83 Result_t ReadAncillaryResource(const UUID& uuid, ASDCP::TimedText::FrameBuffer& FrameBuf,
84 const ASDCP::TimedText::IResourceResolver& Resolver) const;
89 AS_02::TimedText::ST2052_TextParser::h__TextParser::OpenRead(const std::string& filename)
91 Result_t result = ReadFileIntoString(filename, m_XMLDoc);
93 if ( KM_SUCCESS(result) )
95 m_Filename = filename;
104 AS_02::TimedText::ST2052_TextParser::h__TextParser::OpenRead(const std::string& xml_doc, const std::string& filename)
107 m_Filename = filename;
113 AS_02::TimedText::ST2052_TextParser::h__TextParser::OpenRead()
115 if ( ! m_Root.ParseString(m_XMLDoc.c_str()) )
116 return RESULT_FORMAT;
118 m_TDesc.EncodingName = "UTF-8"; // the XML parser demands UTF-8
119 m_TDesc.ResourceList.clear();
120 m_TDesc.ContainerDuration = 0;
121 const XMLNamespace* ns = m_Root.Namespace();
125 DefaultLogSink(). Warn("Document has no namespace name, assuming %s\n", c_dcst_namespace_name);
126 m_TDesc.NamespaceName = c_dcst_namespace_name;
130 m_TDesc.NamespaceName = ns->Name();
137 //------------------------------------------------------------------------------------------
139 AS_02::TimedText::ST2052_TextParser::ST2052_TextParser()
143 AS_02::TimedText::ST2052_TextParser::~ST2052_TextParser()
147 // Opens the stream for reading, parses enough data to provide a complete
148 // set of stream metadata for the MXFWriter below.
150 AS_02::TimedText::ST2052_TextParser::OpenRead(const std::string& filename) const
152 const_cast<AS_02::TimedText::ST2052_TextParser*>(this)->m_Parser = new h__TextParser;
154 Result_t result = m_Parser->OpenRead(filename);
156 if ( ASDCP_FAILURE(result) )
157 const_cast<AS_02::TimedText::ST2052_TextParser*>(this)->m_Parser = 0;
162 // Parses an XML document to provide a complete set of stream metadata for the MXFWriter below.
164 AS_02::TimedText::ST2052_TextParser::OpenRead(const std::string& xml_doc, const std::string& filename) const
166 const_cast<AS_02::TimedText::ST2052_TextParser*>(this)->m_Parser = new h__TextParser;
168 Result_t result = m_Parser->OpenRead(xml_doc, filename);
170 if ( ASDCP_FAILURE(result) )
171 const_cast<AS_02::TimedText::ST2052_TextParser*>(this)->m_Parser = 0;
178 AS_02::TimedText::ST2052_TextParser::FillTimedTextDescriptor(TimedTextDescriptor& TDesc) const
180 if ( m_Parser.empty() )
183 TDesc = m_Parser->m_TDesc;
187 // Reads the complete Timed Text Resource into the given string.
189 AS_02::TimedText::ST2052_TextParser::ReadTimedTextResource(std::string& s) const
191 if ( m_Parser.empty() )
194 s = m_Parser->m_XMLDoc;
200 AS_02::TimedText::ST2052_TextParser::ReadAncillaryResource(const Kumu::UUID& uuid, ASDCP::TimedText::FrameBuffer& FrameBuf,
201 const ASDCP::TimedText::IResourceResolver* Resolver) const
203 return RESULT_NOTIMPL;
208 // end ST2052_TextParser.cpp