as-02ooooooooooo!
[asdcplib.git] / src / h__02_Reader.cpp
1 /*
2   Copyright (c) 2011-2012, Robert Scheler, Heiko Sparenberg Fraunhofer IIS, 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    h__02_Reader.cpp
28   \version $Id$
29   \brief   MXF file reader base class
30 */
31
32 #include "AS_02_internal.h"
33
34 using namespace ASDCP;
35 using namespace ASDCP::MXF;
36
37 //
38 AS_02::h__Reader::h__Reader(const Dictionary& d) :
39   m_HeaderPart(m_Dict), m_FooterPart(m_Dict), m_Dict(&d), m_EssenceStart(0)
40 {
41   m_pCurrentIndexPartition = 0;
42   ////  start_pos = 0;
43 }
44
45 AS_02::h__Reader::~h__Reader()
46 {
47   std::vector<Partition*>::iterator bli = m_BodyPartList.begin();
48   for ( ; bli != m_BodyPartList.end(); bli++ ){
49     delete(*bli);
50     *bli = 0;
51   }
52   Close();
53 }
54
55 void
56 AS_02::h__Reader::Close()
57 {
58   m_File.Close();
59 }
60
61 //------------------------------------------------------------------------------------------
62 //
63
64 //
65 Result_t
66 AS_02::h__Reader::InitInfo()
67 {
68   assert(m_Dict);
69   InterchangeObject* Object;
70
71   UL OPAtomUL(SMPTE_390_OPAtom_Entry().ul);
72   UL Interop_OPAtomUL(MXFInterop_OPAtom_Entry().ul);
73   m_Info.LabelSetType = LS_MXF_SMPTE;
74
75   // Identification
76   Result_t result = m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(Identification), &Object);
77
78   if( ASDCP_SUCCESS(result) )
79     MD_to_WriterInfo((Identification*)Object, m_Info);
80
81   // SourcePackage
82   if( ASDCP_SUCCESS(result) )
83     result = m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(SourcePackage), &Object);
84
85   if( ASDCP_SUCCESS(result) )
86     {
87       SourcePackage* SP = (SourcePackage*)Object;
88       memcpy(m_Info.AssetUUID, SP->PackageUID.Value() + 16, UUIDlen);
89     }
90
91   // optional CryptographicContext
92   if( ASDCP_SUCCESS(result) )
93     {
94       Result_t cr_result = m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(CryptographicContext), &Object);
95
96       if( ASDCP_SUCCESS(cr_result) )
97         MD_to_CryptoInfo((CryptographicContext*)Object, m_Info, *m_Dict);
98     }
99
100   return result;
101 }
102
103 // standard method of populating the in-memory index
104 Result_t
105 AS_02::h__Reader::InitMXFIndex()
106 {
107   if ( ! m_File.IsOpen() )
108     return RESULT_INIT;
109
110   Result_t result = m_File.Seek(m_HeaderPart.FooterPartition);
111
112   if ( ASDCP_SUCCESS(result) )
113     {
114       m_FooterPart.m_Lookup = &m_HeaderPart.m_Primer;
115       //Footer don't need to be initialized because there is no index table in the footer
116       //result = m_FooterPart.InitFromFile(m_File);
117     }
118
119   if ( ASDCP_SUCCESS(result) )
120     m_File.Seek(m_EssenceStart);
121
122   return result;
123 }
124
125
126 //
127 // end h__02_Reader.cpp
128 //