2 Copyright (c) 2006-2009, 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.
37 //------------------------------------------------------------------------------------------
39 //static ASDCP::Dictionary s_SMPTEDict;
40 //static ASDCP::Dictionary s_InteropDict;
42 const ASDCP::Dictionary&
43 ASDCP::DefaultSMPTEDict() {
44 // return s_SMPTEDict;
45 return DefaultCompositeDict();
48 const ASDCP::Dictionary&
49 ASDCP::DefaultInteropDict() {
50 // return s_InteropDict;
51 return DefaultCompositeDict();
56 static ASDCP::Dictionary s_CompositeDict;
57 static Kumu::Mutex s_Lock;
58 static bool s_md_init = false;
61 const ASDCP::Dictionary&
62 ASDCP::DefaultCompositeDict()
66 Kumu::AutoMutex AL(s_Lock);
70 for ( ui32_t x = 0; x < ASDCP::MDD_Table_size; x++ )
71 s_CompositeDict.AddEntry(s_MDD_Table[x], x);
72 // s_md_lookup.insert(std::map<UL, ui32_t>::value_type(UL(s_MDD_Table[x].ul), x));
78 return s_CompositeDict;
81 //------------------------------------------------------------------------------------------
84 ASDCP::Dictionary::Dictionary() {}
85 ASDCP::Dictionary::~Dictionary() {}
90 ASDCP::Dictionary::AddEntry(const MDDEntry& Entry, ui32_t index)
92 m_MDD_Table[index] = Entry;
93 m_md_lookup.insert(std::map<UL, ui32_t>::value_type(UL(Entry.ul), index));
98 const ASDCP::MDDEntry&
99 ASDCP::Dictionary::Type(MDD_t type_id) const
101 return m_MDD_Table[type_id];
105 const ASDCP::MDDEntry*
106 ASDCP::Dictionary::FindUL(const byte_t* ul_buf) const
108 std::map<UL, ui32_t>::const_iterator i = m_md_lookup.find(UL(ul_buf));
110 if ( i == m_md_lookup.end() )
112 byte_t tmp_ul[SMPTE_UL_LENGTH];
113 memcpy(tmp_ul, ul_buf, SMPTE_UL_LENGTH);
114 tmp_ul[SMPTE_UL_LENGTH-1] = 0;
116 i = m_md_lookup.find(UL(tmp_ul));
118 if ( i == m_md_lookup.end() )
122 return &m_MDD_Table[(*i).second];
127 ASDCP::Dictionary::Dump(FILE* stream) const
135 while ( di < MDD_Max )
137 MDDEntry TmpType = m_MDD_Table[di];
138 UL TmpUL(TmpType.ul);
139 fprintf(stream, "%s: %s\n", TmpUL.EncodeString(str_buf, 64), TmpType.name);
140 di = (MDD_t)(di + 1);