2 Copyright (c) 2011-2013, 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_
36 #include "AS_DCP_internal.h"
39 using Kumu::DefaultLogSink;
41 #ifdef DEFAULT_MD_DECL
42 AS_02::MXF::AS02IndexReader *g_AS02IndexReader;
44 extern AS_02::MXF::AS02IndexReader *g_AS02IndexReader;
51 void default_md_object_init();
53 static void CalculateIndexPartitionSize(ui32_t& size,ui32_t numberOfIndexEntries)
55 if(numberOfIndexEntries){
56 //Partition::ArchiveSize(); HeaderSize = 124 bytes
58 //ItemSize IndexEntry = 11 bytes
59 //number of IndexEntries - parameter
60 //IndexEntryArray = 12 bytes
61 //size for other Elements(PosTableCount etc.) = 108 bytes
62 //see Index.cpp ASDCP::MXF::IndexTableSegment::WriteToTLVSet(TLVWriter& TLVSet) how this is computed
63 size = 124 + 20 + 11 * numberOfIndexEntries + 12 +108;
64 size += 20;//because maybe we must fill the last partition, minimum required space for KLV-Item
67 //Partition HeaderSize = 124 bytes
69 //244 for 2 IndexTableSegments
70 size = 124 + 20 + 244;
75 class AS02IndexWriter : public ASDCP::MXF::Partition
77 ASDCP::MXF::IndexTableSegment* m_CurrentSegment;
78 ui32_t m_BytesPerEditUnit;
79 ASDCP::MXF::Rational m_EditRate;
81 KM_NO_COPY_CONSTRUCT(AS02IndexWriter);
85 const ASDCP::Dictionary*& m_Dict;
86 Kumu::fpos_t m_ECOffset;
87 ASDCP::IPrimerLookup* m_Lookup;
89 AS02IndexWriter(const ASDCP::Dictionary*&);
90 virtual ~AS02IndexWriter();
92 Result_t WriteToFile(Kumu::FileWriter& Writer);
93 void ResetCBR(Kumu::fpos_t offset);
96 ui32_t GetDuration() const;
97 void PushIndexEntry(const ASDCP::MXF::IndexTableSegment::IndexEntry&);
98 void SetIndexParamsCBR(ASDCP::IPrimerLookup* lookup, ui32_t size, const ASDCP::Rational& Rate);
99 void SetIndexParamsVBR(ASDCP::IPrimerLookup* lookup, const ASDCP::Rational& Rate, Kumu::fpos_t offset);
103 class h__AS02Reader : public ASDCP::MXF::TrackFileReader<ASDCP::MXF::OP1aHeader, AS_02::MXF::AS02IndexReader>
105 ASDCP_NO_COPY_CONSTRUCT(h__AS02Reader);
109 // Partition *m_pCurrentBodyPartition;
110 // ui64_t m_EssenceStart;
111 // std::vector<Partition*> m_BodyPartList;
112 // ui32_t m_start_pos;
113 // ui32_t m_PartitionSpace;
114 // IndexStrategy_t m_IndexStrategy; //Shim parameter index_strategy_frame/clip
116 h__AS02Reader(const ASDCP::Dictionary&);
117 virtual ~h__AS02Reader();
119 Result_t OpenMXFRead(const char* filename);
121 Result_t ReadEKLVFrame(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf,
122 const byte_t* EssenceUL, ASDCP::AESDecContext* Ctx, ASDCP::HMACContext* HMAC);
124 Result_t LocateFrame(ui32_t FrameNum, Kumu::fpos_t& streamOffset, i8_t& temporalOffset, i8_t& keyFrameOffset);
128 class h__AS02Writer : public ASDCP::MXF::TrackFileWriter<ASDCP::MXF::OP1aHeader>
130 ASDCP_NO_COPY_CONSTRUCT(h__AS02Writer);
134 AS02IndexWriter m_IndexWriter;
135 ui32_t m_PartitionSpace; // edit units per partition
136 IndexStrategy_t m_IndexStrategy; //Shim parameter index_strategy_frame/clip
138 h__AS02Writer(const Dictionary&);
139 virtual ~h__AS02Writer();
141 // all the above for a single source clip
142 Result_t WriteAS02Header(const std::string& PackageLabel, const ASDCP::UL& WrappingUL,
143 const std::string& TrackName, const ASDCP::UL& EssenceUL,
144 const ASDCP::UL& DataDefinition, const ASDCP::Rational& EditRate,
145 ui32_t TCFrameRate, ui32_t BytesPerEditUnit = 0);
147 Result_t WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL,
148 AESEncContext* Ctx, HMACContext* HMAC);
150 Result_t WriteAS02Footer();
155 #endif // _AS_02_INTERNAL_H_
158 // end AS_02_internal.h