2 Copyright (c) 2011-2012, Robert Scheler, Heiko Sparenberg Fraunhofer IIS, 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 AS_02_internal.h
28 \version $Id: AS_02_internal.h ***
29 \brief AS-02 library, non-public common elements
32 #ifndef _AS_02_INTERNAL_H_
33 #define _AS_02_INTERNAL_H_
35 #include "KM_platform.h"
39 #include "AS_DCP_internal.h"
42 using Kumu::DefaultLogSink;
44 using namespace ASDCP;
45 using namespace ASDCP::MXF;
49 static void CalculateIndexPartitionSize(ui32_t& size,ui32_t numberOfIndexEntries)
51 if(numberOfIndexEntries){
52 //Partition::ArchiveSize(); HeaderSize = 124 bytes
54 //ItemSize IndexEntry = 11 bytes
55 //number of IndexEntries - parameter
56 //IndexEntryArray = 12 bytes
57 //size for other Elements(PosTableCount etc.) = 108 bytes
58 //see Index.cpp ASDCP::MXF::IndexTableSegment::WriteToTLVSet(TLVWriter& TLVSet) how this is computed
59 size = 124 + 20 + 11 * numberOfIndexEntries + 12 +108;
60 size += 20;//because maybe we must fill the last partition, minimum required space for KLV-Item
63 //Partition HeaderSize = 124 bytes
65 //244 for 2 IndexTableSegments
66 size = 124 + 20 + 244;
73 ASDCP_NO_COPY_CONSTRUCT(h__Reader);
77 const Dictionary* m_Dict;
78 Kumu::FileReader m_File;
79 OPAtomHeader m_HeaderPart;
80 //more than one Body-Partition use a list
81 std::vector<Partition*> m_BodyPartList;
82 OPAtomIndexFooter m_FooterPart;
83 ui64_t m_EssenceStart;
85 ASDCP::FrameBuffer m_CtFrameBuf;
86 Kumu::fpos_t m_LastPosition;
88 IndexStrategy_t m_IndexStrategy; //Shim parameter index_strategy_frame/clip
89 ui32_t m_PartitionSpace;
91 ////new elements for AS-02
92 Partition* m_pCurrentBodyPartition;
93 AS_02::MXF::OP1aIndexBodyPartion* m_pCurrentIndexPartition;
96 h__Reader(const Dictionary&);
100 virtual Result_t OpenMXFRead(const char* filename) = 0;
101 Result_t InitMXFIndex();
103 // positions file before reading
104 virtual Result_t ReadEKLVFrame(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf,
105 const byte_t* EssenceUL, AESDecContext* Ctx, HMACContext* HMAC) = 0;
107 // reads from current position
108 virtual Result_t ReadEKLVPacket(ui32_t FrameNum, ui32_t SequenceNum, ASDCP::FrameBuffer& FrameBuf,
109 const byte_t* EssenceUL, AESDecContext* Ctx, HMACContext* HMAC) = 0;
116 ASDCP_NO_COPY_CONSTRUCT(h__Writer);
120 const Dictionary* m_Dict;
121 Kumu::FileWriter m_File;
123 OPAtomHeader m_HeaderPart;
124 //more than one Body-Partition -> use a list of Partitions
125 std::vector<Partition*> m_BodyPartList;
126 //we don't use the footer like in the dcps but we need also a footer
127 AS_02::MXF::OP1aIndexFooter m_FooterPart;
128 ui64_t m_EssenceStart;
130 MaterialPackage* m_MaterialPackage;
131 SourcePackage* m_FilePackage;
133 FileDescriptor* m_EssenceDescriptor;
134 std::list<InterchangeObject*> m_EssenceSubDescriptorList;
136 ui32_t m_FramesWritten;
137 ui64_t m_StreamOffset;
138 ASDCP::FrameBuffer m_CtFrameBuf;
139 h__WriterState m_State;
141 DurationElementList_t m_DurationUpdateList;
143 //new elements for AS-02
145 //TODO: Currently not used, delete if not necessary
146 // Counter values for BodySID and IndexSID
147 ui32_t m_CurrentBodySID;
148 ui32_t m_CurrentIndexSID;
149 //TODO: maybe set this to the lf__Writer class because this is only in JP2K creation necessary
150 //our computed PartitionSpace
151 ui32_t m_PartitionSpace;
152 IndexStrategy_t m_IndexStrategy; //Shim parameter index_strategy_frame/clip
155 ASDCP::MXF::Rational m_EditRate;
156 //the BytesPerEditUnit
157 ui32_t m_BytesPerEditUnit;
158 //pointer to the current Body Partition(Index)
159 AS_02::MXF::OP1aIndexBodyPartion* m_CurrentIndexBodyPartition;
161 h__Writer(const Dictionary&);
162 virtual ~h__Writer();
164 //virtual methods, implementation details for JP2K or PCM are in the MXFWriter::h__Writer classes if they are different
165 virtual void InitHeader();
166 /*virtual*/ void AddSourceClip(const ASDCP::MXF::Rational& EditRate, ui32_t TCFrameRate,
167 const std::string& TrackName, const UL& EssenceUL,
168 const UL& DataDefinition, const std::string& PackageLabel);
169 /*virtual*/ void AddDMSegment(const ASDCP::MXF::Rational& EditRate, ui32_t TCFrameRate,
170 const std::string& TrackName, const UL& DataDefinition,
171 const std::string& PackageLabel);
172 /*virtual*/ void AddEssenceDescriptor(const ASDCP::UL& WrappingUL);
173 virtual Result_t CreateBodyPart(const ASDCP::MXF::Rational& EditRate, ui32_t BytesPerEditUnit = 0);
175 //new method to create BodyPartition for essence and index
176 virtual Result_t CreateBodyPartPair();
177 //new method to finalize BodyPartion(index)
178 virtual Result_t CompleteIndexBodyPart();
180 // all the above for a single source clip
181 virtual Result_t WriteMXFHeader(const std::string& PackageLabel, const UL& WrappingUL,
182 const std::string& TrackName, const UL& EssenceUL,
183 const UL& DataDefinition, const ASDCP::MXF::Rational& EditRate,
184 ui32_t TCFrameRate, ui32_t BytesPerEditUnit = 0);
186 virtual Result_t WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,
187 const byte_t* EssenceUL, AESEncContext* Ctx, HMACContext* HMAC);
189 virtual Result_t WriteMXFFooter() = 0;
195 #endif // _AS_02_INTERNAL_H_
198 // end AS_02_internal.h