new stuff
[asdcplib.git] / src / TimedText_Parser.cpp
1 /*
2 Copyright (c) 2007, John Hurst
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
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.
15
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.
26 */
27 /*! \file    AS_DCP_TimedText.cpp
28     \version $Id$       
29     \brief   AS-DCP library, PCM essence reader and writer implementation
30 */
31
32
33 #include "AS_DCP_internal.h"
34 #include "AS_DCP_TimedText.h"
35 #include "KM_xml.h"
36
37 using namespace Kumu;
38 using namespace ASDCP;
39
40 //------------------------------------------------------------------------------------------
41
42 class ASDCP::TimedText::DCSubtitleParser::h__DCSubtitleParser
43 {
44   ui32_t             m_FileReadCount;
45
46   ASDCP_NO_COPY_CONSTRUCT(h__DCSubtitleParser);
47
48 public:
49   TimedTextDescriptor  m_TDesc;
50
51   h__DCSubtitleParser() : m_FileReadCount(0)
52   {
53     memset(&m_TDesc, 0, sizeof(m_TDesc));
54   }
55
56   ~h__DCSubtitleParser()
57   {
58     Close();
59   }
60
61   Result_t OpenRead(const char* filename);
62   void     Close() {}
63
64   Result_t Reset()
65   {
66     m_FileReadCount = 0;
67     return RESULT_OK;
68   }
69
70   Result_t ReadFrame(FrameBuffer&);
71 };
72
73 //------------------------------------------------------------------------------------------
74
75 ASDCP::TimedText::DCSubtitleParser::DCSubtitleParser()
76 {
77 }
78
79 ASDCP::TimedText::DCSubtitleParser::~DCSubtitleParser()
80 {
81 }
82
83 // Opens the stream for reading, parses enough data to provide a complete
84 // set of stream metadata for the MXFWriter below.
85 ASDCP::Result_t
86 ASDCP::TimedText::DCSubtitleParser::OpenRead(const char* filename) const
87 {
88   const_cast<ASDCP::TimedText::DCSubtitleParser*>(this)->m_Parser = new h__DCSubtitleParser;
89
90   Result_t result = m_Parser->OpenRead(filename);
91
92   if ( ASDCP_FAILURE(result) )
93     const_cast<ASDCP::TimedText::DCSubtitleParser*>(this)->m_Parser.release();
94
95   return result;
96 }
97
98 // Rewinds the stream to the beginning.
99 ASDCP::Result_t
100 ASDCP::TimedText::DCSubtitleParser::Reset() const
101 {
102   if ( m_Parser.empty() )
103     return RESULT_INIT;
104
105   return m_Parser->Reset();
106 }
107
108 // Places a frame of data in the frame buffer. Fails if the buffer is too small
109 // or the stream is empty.
110 ASDCP::Result_t
111 ASDCP::TimedText::DCSubtitleParser::ReadFrame(FrameBuffer& FB) const
112 {
113   if ( m_Parser.empty() )
114     return RESULT_INIT;
115
116   return m_Parser->ReadFrame(FB);
117 }
118
119 ASDCP::Result_t
120 ASDCP::TimedText::DCSubtitleParser::FillDescriptor(TimedTextDescriptor& PDesc) const
121 {
122   if ( m_Parser.empty() )
123     return RESULT_INIT;
124
125   PDesc = m_Parser->m_TDesc;
126   return RESULT_OK;
127 }
128
129 //
130 // end AS_DCP_timedText.cpp
131 //