diff options
| author | jhurst <jhurst@cinecert.com> | 2012-02-21 02:09:32 +0000 |
|---|---|---|
| committer | jhurst <> | 2012-02-21 02:09:32 +0000 |
| commit | 1a5727137f5b5ff8aecd3ec5a162c198c8c0a5e7 (patch) | |
| tree | c61a1e8ba29253e51a8ebe310db2e0fad217cd78 /src | |
| parent | 80463afc197c90372d3f4c7890c6520f1040aedc (diff) | |
mega datetime patch
Diffstat (limited to 'src')
| -rwxr-xr-x | src/AS_DCP_JP2K.cpp | 44 | ||||
| -rwxr-xr-x | src/AS_DCP_MPEG2.cpp | 24 | ||||
| -rwxr-xr-x | src/AS_DCP_PCM.cpp | 24 | ||||
| -rw-r--r-- | src/AS_DCP_TimedText.cpp | 24 | ||||
| -rwxr-xr-x | src/AS_DCP_internal.h | 12 | ||||
| -rwxr-xr-x | src/Dict.cpp | 19 | ||||
| -rwxr-xr-x | src/KLV.h | 6 | ||||
| -rw-r--r-- | src/KM_tai.cpp | 25 | ||||
| -rw-r--r-- | src/KM_tai.h | 2 | ||||
| -rwxr-xr-x | src/KM_util.cpp | 519 | ||||
| -rwxr-xr-x | src/KM_util.h | 44 | ||||
| -rwxr-xr-x | src/MXF.h | 11 | ||||
| -rwxr-xr-x | src/MXFTypes.cpp | 243 | ||||
| -rwxr-xr-x | src/MXFTypes.h | 53 | ||||
| -rw-r--r-- | src/Makefile.am | 46 | ||||
| -rwxr-xr-x | src/Metadata.h | 6 | ||||
| -rwxr-xr-x | src/PCMParserList.cpp | 2 | ||||
| -rwxr-xr-x | src/asdcp-wrap.cpp | 21 | ||||
| -rwxr-xr-x | src/h__Reader.cpp | 27 | ||||
| -rwxr-xr-x | src/h__Writer.cpp | 3 |
20 files changed, 355 insertions, 800 deletions
diff --git a/src/AS_DCP_JP2K.cpp b/src/AS_DCP_JP2K.cpp index 9e676ae..076ba5c 100755 --- a/src/AS_DCP_JP2K.cpp +++ b/src/AS_DCP_JP2K.cpp @@ -38,10 +38,6 @@ using Kumu::GenRandomValue; //------------------------------------------------------------------------------------------ -static const ASDCP::Dictionary *sg_dict = &DefaultSMPTEDict(); -static MXF::OPAtomHeader sg_OPAtomHeader(sg_dict); -static MXF::OPAtomIndexFooter sg_OPAtomIndexFooter(sg_dict); - static std::string JP2K_PACKAGE_LABEL = "File Package: SMPTE 429-4 frame wrapping of JPEG 2000 codestreams"; static std::string JP2K_S_PACKAGE_LABEL = "File Package: SMPTE 429-10 frame wrapping of stereoscopic JPEG 2000 codestreams"; static std::string PICT_DEF_LABEL = "Picture Track"; @@ -472,7 +468,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::JP2K::MXFReader::OPAtomHeader() { if ( m_Reader.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Reader->m_HeaderPart; } @@ -484,7 +483,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::JP2K::MXFReader::OPAtomIndexFooter() { if ( m_Reader.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Reader->m_FooterPart; } @@ -670,7 +672,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::JP2K::MXFSReader::OPAtomHeader() { if ( m_Reader.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Reader->m_HeaderPart; } @@ -682,7 +687,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::JP2K::MXFSReader::OPAtomIndexFooter() { if ( m_Reader.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Reader->m_FooterPart; } @@ -1036,7 +1044,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::JP2K::MXFWriter::OPAtomHeader() { if ( m_Writer.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Writer->m_HeaderPart; } @@ -1048,7 +1059,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::JP2K::MXFWriter::OPAtomIndexFooter() { if ( m_Writer.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Writer->m_FooterPart; } @@ -1161,7 +1175,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::JP2K::MXFSWriter::OPAtomHeader() { if ( m_Writer.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Writer->m_HeaderPart; } @@ -1173,7 +1190,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::JP2K::MXFSWriter::OPAtomIndexFooter() { if ( m_Writer.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Writer->m_FooterPart; } diff --git a/src/AS_DCP_MPEG2.cpp b/src/AS_DCP_MPEG2.cpp index ea7ed74..18102d4 100755 --- a/src/AS_DCP_MPEG2.cpp +++ b/src/AS_DCP_MPEG2.cpp @@ -36,10 +36,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //------------------------------------------------------------------------------------------ -static const ASDCP::Dictionary *sg_dict = &DefaultSMPTEDict(); -static MXF::OPAtomHeader sg_OPAtomHeader(sg_dict); -static MXF::OPAtomIndexFooter sg_OPAtomIndexFooter(sg_dict); - static std::string MPEG_PACKAGE_LABEL = "File Package: SMPTE 381M frame wrapping of MPEG2 video elementary stream"; static std::string PICT_DEF_LABEL = "Picture Track"; @@ -346,7 +342,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::MPEG2::MXFReader::OPAtomHeader() { if ( m_Reader.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Reader->m_HeaderPart; } @@ -358,7 +357,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::MPEG2::MXFReader::OPAtomIndexFooter() { if ( m_Reader.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Reader->m_FooterPart; } @@ -646,7 +648,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::MPEG2::MXFWriter::OPAtomHeader() { if ( m_Writer.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Writer->m_HeaderPart; } @@ -658,7 +663,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::MPEG2::MXFWriter::OPAtomIndexFooter() { if ( m_Writer.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Writer->m_FooterPart; } diff --git a/src/AS_DCP_PCM.cpp b/src/AS_DCP_PCM.cpp index 3956c71..472ea40 100755 --- a/src/AS_DCP_PCM.cpp +++ b/src/AS_DCP_PCM.cpp @@ -36,10 +36,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //------------------------------------------------------------------------------------------ -static const ASDCP::Dictionary *sg_dict = &DefaultSMPTEDict(); -static MXF::OPAtomHeader sg_OPAtomHeader(sg_dict); -static MXF::OPAtomIndexFooter sg_OPAtomIndexFooter(sg_dict); - static std::string PCM_PACKAGE_LABEL = "File Package: SMPTE 382M frame wrapping of wave audio"; static std::string SOUND_DEF_LABEL = "Sound Track"; @@ -324,7 +320,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::PCM::MXFReader::OPAtomHeader() { if ( m_Reader.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Reader->m_HeaderPart; } @@ -336,7 +335,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::PCM::MXFReader::OPAtomIndexFooter() { if ( m_Reader.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Reader->m_FooterPart; } @@ -579,7 +581,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::PCM::MXFWriter::OPAtomHeader() { if ( m_Writer.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Writer->m_HeaderPart; } @@ -591,7 +596,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::PCM::MXFWriter::OPAtomIndexFooter() { if ( m_Writer.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Writer->m_FooterPart; } diff --git a/src/AS_DCP_TimedText.cpp b/src/AS_DCP_TimedText.cpp index 5d31a8d..07b2631 100644 --- a/src/AS_DCP_TimedText.cpp +++ b/src/AS_DCP_TimedText.cpp @@ -37,10 +37,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using Kumu::GenRandomValue; -static const ASDCP::Dictionary *sg_dict = &DefaultSMPTEDict(); -static MXF::OPAtomHeader sg_OPAtomHeader(sg_dict); -static MXF::OPAtomIndexFooter sg_OPAtomIndexFooter(sg_dict); - static std::string TIMED_TEXT_PACKAGE_LABEL = "File Package: SMPTE 429-5 clip wrapping of D-Cinema Timed Text data"; static std::string TIMED_TEXT_DEF_LABEL = "Timed Text Track"; @@ -352,7 +348,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::TimedText::MXFReader::OPAtomHeader() { if ( m_Reader.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Reader->m_HeaderPart; } @@ -364,7 +363,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::TimedText::MXFReader::OPAtomIndexFooter() { if ( m_Reader.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Reader->m_FooterPart; } @@ -682,7 +684,10 @@ ASDCP::MXF::OPAtomHeader& ASDCP::TimedText::MXFWriter::OPAtomHeader() { if ( m_Writer.empty() ) - return sg_OPAtomHeader; + { + assert(g_OPAtomHeader); + return *g_OPAtomHeader; + } return m_Writer->m_HeaderPart; } @@ -694,7 +699,10 @@ ASDCP::MXF::OPAtomIndexFooter& ASDCP::TimedText::MXFWriter::OPAtomIndexFooter() { if ( m_Writer.empty() ) - return sg_OPAtomIndexFooter; + { + assert(g_OPAtomIndexFooter); + return *g_OPAtomIndexFooter; + } return m_Writer->m_FooterPart; } diff --git a/src/AS_DCP_internal.h b/src/AS_DCP_internal.h index 464771d..661ab65 100755 --- a/src/AS_DCP_internal.h +++ b/src/AS_DCP_internal.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2009, John Hurst +Copyright (c) 2004-2012, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -42,10 +42,20 @@ using Kumu::DefaultLogSink; using namespace ASDCP; using namespace ASDCP::MXF; +#ifdef DEFAULT_MD_DECL +ASDCP::MXF::OPAtomHeader *g_OPAtomHeader; +ASDCP::MXF::OPAtomIndexFooter *g_OPAtomIndexFooter; +#else +extern MXF::OPAtomHeader *g_OPAtomHeader; +extern MXF::OPAtomIndexFooter *g_OPAtomIndexFooter; +#endif namespace ASDCP { + void default_md_object_init(); + + // constant values used to calculate KLV and EKLV packet sizes static const ui32_t klv_cryptinfo_size = MXF_BER_LENGTH diff --git a/src/Dict.cpp b/src/Dict.cpp index d50a836..74a7b4e 100755 --- a/src/Dict.cpp +++ b/src/Dict.cpp @@ -210,6 +210,7 @@ ASDCP::Dictionary::AddEntry(const MDDEntry& Entry, ui32_t index) m_md_lookup.insert(std::map<UL, ui32_t>::value_type(TmpUL, index)); m_md_rev_lookup.insert(std::map<ui32_t, UL>::value_type(index, TmpUL)); + m_md_sym_lookup.insert(std::map<std::string, ui32_t>::value_type(Entry.name, index)); m_MDD_Table[index] = Entry; return result; @@ -274,7 +275,23 @@ ASDCP::Dictionary::FindUL(const byte_t* ul_buf) const } } - return &m_MDD_Table[(*i).second]; + return &m_MDD_Table[i->second]; +} + +// +const ASDCP::MDDEntry* +ASDCP::Dictionary::FindSymbol(const std::string& str) const +{ + assert(m_MDD_Table[0].name[0]); + std::map<std::string, ui32_t>::const_iterator i = m_md_sym_lookup.find(str); + + if ( i == m_md_sym_lookup.end() ) + { + Kumu::DefaultLogSink().Warn("UL Dictionary: unknown symbol: %s\n", str.c_str()); + return 0; + } + + return &m_MDD_Table[i->second]; } // @@ -143,8 +143,9 @@ inline const char* ui64sz(ui64_t i, char* buf) // class Dictionary { - std::map<ASDCP::UL, ui32_t> m_md_lookup; - std::map<ui32_t, ASDCP::UL> m_md_rev_lookup; + std::map<ASDCP::UL, ui32_t> m_md_lookup; + std::map<std::string, ui32_t> m_md_sym_lookup; + std::map<ui32_t, ASDCP::UL> m_md_rev_lookup; MDDEntry m_MDD_Table[(ui32_t)ASDCP::MDD_Max]; ASDCP_NO_COPY_CONSTRUCT(Dictionary); @@ -160,6 +161,7 @@ inline const char* ui64sz(ui64_t i, char* buf) bool DeleteEntry(ui32_t index); const MDDEntry* FindUL(const byte_t*) const; + const MDDEntry* FindSymbol(const std::string&) const; const MDDEntry& Type(MDD_t type_id) const; inline const byte_t* ul(MDD_t type_id) const { diff --git a/src/KM_tai.cpp b/src/KM_tai.cpp index f6cbea5..4cc6c32 100644 --- a/src/KM_tai.cpp +++ b/src/KM_tai.cpp @@ -142,15 +142,8 @@ caltime_utc(Kumu::TAI::caltime* ct, const Kumu::TAI::tai* t) { assert(ct&&t); Kumu::TAI::tai t2 = *t; - ui64_t u; - i32_t s; - - /* XXX: check for overfow? */ - - u = t2.x; - - u += 58486; - s = u % ui64_C(86400); + ui64_t u = t2.x + 58486; + i32_t s = (i32_t)(u % ui64_C(86400)); ct->second = (s % 60); s /= 60; ct->minute = s % 60; s /= 60; @@ -183,11 +176,25 @@ caltime_tai(const Kumu::TAI::caltime* ct, Kumu::TAI::tai* t) void Kumu::TAI::tai::now() { +#ifdef KM_WIN32 + SYSTEMTIME st; + ::GetSystemTime(&st); + TAI::caltime ct; + ct.date.year = st.wYear; + ct.date.month = st.wMonth; + ct.date.day = st.wDay; + ct.hour = st.wHour; + ct.minute = st.wMinute; + ct.second = st.wSecond; + caltime_tai(&ct, this); +#else struct timeval now; gettimeofday(&now, 0); x = ui64_C(4611686018427387914) + (ui64_t)now.tv_sec; +#endif } + // const Kumu::TAI::tai& Kumu::TAI::tai::operator=(const Kumu::TAI::caltime& rhs) diff --git a/src/KM_tai.h b/src/KM_tai.h index ee3b666..da90df7 100644 --- a/src/KM_tai.h +++ b/src/KM_tai.h @@ -64,7 +64,7 @@ namespace Kumu struct tai { ui64_t x; - inline void add_seconds(i32_t s) { x += s * 1; } + inline void add_seconds(i32_t s) { x += s; } inline void add_minutes(i32_t m) { x += m * 60; } inline void add_hours(i32_t h) { x += h * 3600; } inline void add_days(i32_t d) { x += d * 86400; } diff --git a/src/KM_util.cpp b/src/KM_util.cpp index b84f7f5..d6b7141 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2005-2011, John Hurst +Copyright (c) 2005-2012, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,7 +34,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <KM_memio.h> #include <KM_fileio.h> #include <KM_log.h> -#include <KM_tai.h> #include <KM_mutex.h> #include <ctype.h> #include <list> @@ -682,389 +681,133 @@ Kumu::write_BER(byte_t* buf, ui64_t val, ui32_t ber_len) //------------------------------------------------------------------------------------------ -#ifdef KM_WIN32 - -#define TIMESTAMP_TO_SYSTIME(ts, t) \ - (t)->wYear = (ts).Year; /* year */ \ - (t)->wMonth = (ts).Month; /* month of year (1 - 12) */ \ - (t)->wDay = (ts).Day; /* day of month (1 - 31) */ \ - (t)->wHour = (ts).Hour; /* hours (0 - 23) */ \ - (t)->wMinute = (ts).Minute; /* minutes (0 - 59) */ \ - (t)->wSecond = (ts).Second; /* seconds (0 - 60) */ \ - (t)->wDayOfWeek = 0; \ - (t)->wMilliseconds = 0 - -#define SYSTIME_TO_TIMESTAMP(t, ts) \ - (ts).Year = (t)->wYear; /* year */ \ - (ts).Month = (t)->wMonth; /* month of year (1 - 12) */ \ - (ts).Day = (t)->wDay; /* day of month (1 - 31) */ \ - (ts).Hour = (t)->wHour; /* hours (0 - 23) */ \ - (ts).Minute = (t)->wMinute; /* minutes (0 - 59) */ \ - (ts).Second = (t)->wSecond; /* seconds (0 - 60) */ -// -Kumu::Timestamp::Timestamp() : - Year(0), Month(0), Day(0), Hour(0), Minute(0), Second(0) -{ - SYSTEMTIME sys_time; - GetSystemTime(&sys_time); - SYSTIME_TO_TIMESTAMP(&sys_time, *this); -} - -// -bool -Kumu::Timestamp::operator<(const Timestamp& rhs) const -{ - SYSTEMTIME lhst, rhst; - FILETIME lft, rft; - - TIMESTAMP_TO_SYSTIME(*this, &lhst); - TIMESTAMP_TO_SYSTIME(rhs, &rhst); - SystemTimeToFileTime(&lhst, &lft); - SystemTimeToFileTime(&rhst, &rft); - return ( CompareFileTime(&lft, &rft) == -1 ); -} +#ifndef KM_WIN32 +#include <time.h> +#endif // -bool -Kumu::Timestamp::operator>(const Timestamp& rhs) const -{ - SYSTEMTIME lhst, rhst; - FILETIME lft, rft; - - TIMESTAMP_TO_SYSTIME(*this, &lhst); - TIMESTAMP_TO_SYSTIME(rhs, &rhst); - SystemTimeToFileTime(&lhst, &lft); - SystemTimeToFileTime(&rhst, &rft); - return ( CompareFileTime(&lft, &rft) == 1 ); -} - -inline ui64_t -seconds_to_ns100(ui32_t seconds) -{ - return ((ui64_t)seconds * 10000000); +Kumu::Timestamp::Timestamp() : m_TZOffsetMinutes(0) { + m_Timestamp.now(); } -// -void -Kumu::Timestamp::AddDays(i32_t days) -{ - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; - - if ( days != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(86400) * (i64_t)days ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } +Kumu::Timestamp::Timestamp(const Timestamp& rhs) { + m_Timestamp = rhs.m_Timestamp; + m_TZOffsetMinutes = rhs.m_TZOffsetMinutes; } -// -void -Kumu::Timestamp::AddHours(i32_t hours) -{ - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; - - if ( hours != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(3600) * (i64_t)hours ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } +Kumu::Timestamp::Timestamp(const char* datestr) : m_TZOffsetMinutes(0) { + DecodeString(datestr); } -// -void -Kumu::Timestamp::AddMinutes(i32_t minutes) -{ - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; - - if ( minutes != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(60) * (i64_t)minutes ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } +Kumu::Timestamp::~Timestamp() { } // -void -Kumu::Timestamp::AddSeconds(i32_t seconds) +const Kumu::Timestamp& +Kumu::Timestamp::operator=(const Timestamp& rhs) { - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; - - if ( seconds != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(1) * (i64_t)seconds ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } + m_Timestamp = rhs.m_Timestamp; + m_TZOffsetMinutes = rhs.m_TZOffsetMinutes; + return *this; } -#else // KM_WIN32 - -#include <time.h> - -#define TIMESTAMP_TO_CALTIME(ts, ct) \ - (ct)->date.year = (ts).Year; /* year */ \ - (ct)->date.month = (ts).Month; /* month of year (1 - 12) */ \ - (ct)->date.day = (ts).Day; /* day of month (1 - 31) */ \ - (ct)->hour = (ts).Hour; /* hours (0 - 23) */ \ - (ct)->minute = (ts).Minute; /* minutes (0 - 59) */ \ - (ct)->second = (ts).Second; /* seconds (0 - 60) */ \ - (ct)->offset = 0; - -#define CALTIME_TO_TIMESTAMP(ct, ts) \ - assert((ct)->offset == 0); \ - (ts).Year = (ct)->date.year; /* year */ \ - (ts).Month = (ct)->date.month; /* month of year (1 - 12) */ \ - (ts).Day = (ct)->date.day; /* day of month (1 - 31) */ \ - (ts).Hour = (ct)->hour; /* hours (0 - 23) */ \ - (ts).Minute = (ct)->minute; /* minutes (0 - 59) */ \ - (ts).Second = (ct)->second; /* seconds (0 - 60) */ - - -// -Kumu::Timestamp::Timestamp() : - Year(0), Month(0), Day(0), Hour(0), Minute(0), Second(0) -{ - Kumu::TAI::tai now; - Kumu::TAI::caltime ct; - now.now(); - ct = now; - CALTIME_TO_TIMESTAMP(&ct, *this) +bool Kumu::Timestamp::operator<(const Timestamp& rhs) const { + return m_Timestamp.x < rhs.m_Timestamp.x; } -// -bool -Kumu::Timestamp::operator<(const Timestamp& rhs) const -{ - Kumu::TAI::caltime lh_ct, rh_ct; - TIMESTAMP_TO_CALTIME(*this, &lh_ct) - TIMESTAMP_TO_CALTIME(rhs, &rh_ct) - - Kumu::TAI::tai lh_tai, rh_tai; - lh_tai = lh_ct; - rh_tai = rh_ct; - - return ( lh_tai.x < rh_tai.x ); -} - -// -bool -Kumu::Timestamp::operator>(const Timestamp& rhs) const -{ - Kumu::TAI::caltime lh_ct, rh_ct; - TIMESTAMP_TO_CALTIME(*this, &lh_ct) - TIMESTAMP_TO_CALTIME(rhs, &rh_ct) - - Kumu::TAI::tai lh_tai, rh_tai; - lh_tai = lh_ct; - rh_tai = rh_ct; - - return ( lh_tai.x > rh_tai.x ); +bool Kumu::Timestamp::operator>(const Timestamp& rhs) const { + return m_Timestamp.x > rhs.m_Timestamp.x; } -// -void -Kumu::Timestamp::AddDays(i32_t days) -{ - Kumu::TAI::caltime ct; - Kumu::TAI::tai t; - - if ( days != 0 ) - { - TIMESTAMP_TO_CALTIME(*this, &ct) - t = ct; - t.add_days(days); - ct = t; - CALTIME_TO_TIMESTAMP(&ct, *this) - } +bool Kumu::Timestamp::operator==(const Timestamp& rhs) const { + return m_Timestamp.x == rhs.m_Timestamp.x; } -// -void -Kumu::Timestamp::AddHours(i32_t hours) -{ - Kumu::TAI::caltime ct; - Kumu::TAI::tai t; - - if ( hours != 0 ) - { - TIMESTAMP_TO_CALTIME(*this, &ct) - t = ct; - t.add_hours(hours); - ct = t; - CALTIME_TO_TIMESTAMP(&ct, *this) - } +bool Kumu::Timestamp::operator!=(const Timestamp& rhs) const { + return m_Timestamp.x != rhs.m_Timestamp.x; } // void -Kumu::Timestamp::AddMinutes(i32_t minutes) +Kumu::Timestamp::GetComponents(ui16_t& Year, ui8_t& Month, ui8_t& Day, + ui8_t& Hour, ui8_t& Minute, ui8_t& Second) const { - Kumu::TAI::caltime ct; - Kumu::TAI::tai t; - - if ( minutes != 0 ) - { - TIMESTAMP_TO_CALTIME(*this, &ct) - t = ct; - t.add_minutes(minutes); - ct = t; - CALTIME_TO_TIMESTAMP(&ct, *this) - } + TAI::caltime ct; + ct = m_Timestamp; + Year = ct.date.year; + Month = ct.date.month; + Day = ct.date.day; + Hour = ct.hour; + Minute = ct.minute; + Second = ct.second; } // void -Kumu::Timestamp::AddSeconds(i32_t seconds) -{ - Kumu::TAI::caltime ct; - Kumu::TAI::tai t; - - if ( seconds != 0 ) - { - TIMESTAMP_TO_CALTIME(*this, &ct) - t = ct; - t.add_seconds(seconds); - ct = t; - CALTIME_TO_TIMESTAMP(&ct, *this) - } -} - -#endif // KM_WIN32 - - -Kumu::Timestamp::Timestamp(const Timestamp& rhs) : IArchive() -{ - Year = rhs.Year; - Month = rhs.Month; - Day = rhs.Day; - Hour = rhs.Hour; - Minute = rhs.Minute; - Second = rhs.Second; -} - -// -Kumu::Timestamp::Timestamp(const char* datestr) : IArchive() +Kumu::Timestamp::SetComponents(const ui16_t& Year, const ui8_t& Month, const ui8_t& Day, + const ui8_t& Hour, const ui8_t& Minute, const ui8_t& Second) { - if ( ! DecodeString(datestr) ) - { - *this = Timestamp(); - } + TAI::caltime ct; + ct.date.year = Year; + ct.date.month = Month; + ct.date.day = Day; + ct.hour = Hour; + ct.minute = Minute; + ct.second = Second; + ct.offset = 0; + m_Timestamp = ct; + m_TZOffsetMinutes = 0; } -// -Kumu::Timestamp::~Timestamp() -{ -} - -// -const Kumu::Timestamp& -Kumu::Timestamp::operator=(const Timestamp& rhs) -{ - Year = rhs.Year; - Month = rhs.Month; - Day = rhs.Day; - Hour = rhs.Hour; - Minute = rhs.Minute; - Second = rhs.Second; - return *this; -} - -// +// returns false if the requested adjustment is out of range bool -Kumu::Timestamp::operator==(const Timestamp& rhs) const +Kumu::Timestamp::SetTZOffsetMinutes(const i32_t& minutes) { - if ( Year == rhs.Year - && Month == rhs.Month - && Day == rhs.Day - && Hour == rhs.Hour - && Minute == rhs.Minute - && Second == rhs.Second ) - return true; - - return false; -} + static const i32_t tz_limit = 14 * 60 * 60; -// -bool -Kumu::Timestamp::operator!=(const Timestamp& rhs) const -{ - if ( Year != rhs.Year - || Month != rhs.Month - || Day != rhs.Day - || Hour != rhs.Hour - || Minute != rhs.Minute - || Second != rhs.Second ) - return true; - - return false; -} + if ( minutes < ( - tz_limit) || minutes > tz_limit ) + return false; -// -const char* -Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const -{ - return EncodeStringWithOffset(str_buf, buf_len, 0); + m_TZOffsetMinutes = minutes; + return true; } // const char* -Kumu::Timestamp::EncodeStringWithOffset(char* str_buf, ui32_t buf_len, - i32_t offset_minutes) const +Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const { if ( buf_len < ( DateTimeLen + 1 ) ) return 0; - // ensure offset is within +/- 14 hours - if ((offset_minutes < -14 * 60) || (offset_minutes > 14 * 60)) - return 0; + ui16_t year; + ui8_t month, day, hour, minute, second; + ui32_t ofst_hours = 0, ofst_minutes = 0; + char direction = '+'; - // set the apparent time - Kumu::Timestamp tmp_t(*this); - tmp_t.AddMinutes(offset_minutes); + if ( m_TZOffsetMinutes == 0 ) + { + GetComponents(year, month, day, hour, minute, second); + } + else + { + // calculate local time + Kumu::Timestamp tmp_t(*this); + tmp_t.AddMinutes(m_TZOffsetMinutes); + tmp_t.GetComponents(year, month, day, hour, minute, second); - char direction = '+'; - if (offset_minutes < 0) { - direction = '-'; - // need absolute offset from zero - offset_minutes = -offset_minutes; - } + ofst_hours = abs(m_TZOffsetMinutes) / 60; + ofst_minutes = abs(m_TZOffsetMinutes) % 60; + if ( m_TZOffsetMinutes < 0 ) + direction = '-'; + } + // 2004-05-01T13:20:00+00:00 snprintf(str_buf, buf_len, "%04hu-%02hu-%02huT%02hu:%02hu:%02hu%c%02hu:%02hu", - tmp_t.Year, tmp_t.Month, tmp_t.Day, - tmp_t.Hour, tmp_t.Minute, tmp_t.Second, - direction, - offset_minutes / 60, - offset_minutes % 60); + year, month, day, hour, minute, second, + direction, ofst_hours, ofst_minutes); return str_buf; } @@ -1073,8 +816,6 @@ Kumu::Timestamp::EncodeStringWithOffset(char* str_buf, ui32_t buf_len, bool Kumu::Timestamp::DecodeString(const char* datestr) { - Timestamp TmpStamp; - if ( ! ( isdigit(datestr[0]) && isdigit(datestr[1]) && isdigit(datestr[2]) && isdigit(datestr[3]) ) || datestr[4] != '-' || ! ( isdigit(datestr[5]) && isdigit(datestr[6]) ) @@ -1083,10 +824,11 @@ Kumu::Timestamp::DecodeString(const char* datestr) return false; ui32_t char_count = 10; - TmpStamp.Year = atoi(datestr); - TmpStamp.Month = atoi(datestr + 5); - TmpStamp.Day = atoi(datestr + 8); - TmpStamp.Hour = TmpStamp.Minute = TmpStamp.Second = 0; + TAI::caltime YMDhms; + YMDhms.offset = 0; + YMDhms.date.year = atoi(datestr); + YMDhms.date.month = atoi(datestr + 5); + YMDhms.date.day = atoi(datestr + 8); if ( datestr[10] == 'T' ) { @@ -1096,8 +838,8 @@ Kumu::Timestamp::DecodeString(const char* datestr) return false; char_count += 6; - TmpStamp.Hour = atoi(datestr + 11); - TmpStamp.Minute = atoi(datestr + 14); + YMDhms.hour = atoi(datestr + 11); + YMDhms.minute = atoi(datestr + 14); if ( datestr[16] == ':' ) { @@ -1105,7 +847,7 @@ Kumu::Timestamp::DecodeString(const char* datestr) return false; char_count += 3; - TmpStamp.Second = atoi(datestr + 17); + YMDhms.second = atoi(datestr + 17); } if ( datestr[19] == '.' ) @@ -1138,7 +880,7 @@ Kumu::Timestamp::DecodeString(const char* datestr) /* a negative offset is behind UTC and so needs to increment to * convert, while a positive offset must do the reverse */ - TmpStamp.AddMinutes(-TZ_offset); + YMDhms.offset = TZ_offset; } else if (datestr[19] == 'Z') { @@ -1153,23 +895,9 @@ Kumu::Timestamp::DecodeString(const char* datestr) datestr, char_count); return false; } - -#ifdef KM_WIN32 - SYSTEMTIME st; - FILETIME ft; - TIMESTAMP_TO_SYSTIME(TmpStamp, &st); - if ( SystemTimeToFileTime(&st, &ft) == 0 ) - return false; - SYSTIME_TO_TIMESTAMP(&st, *this); -#else - Kumu::TAI::tai t; - Kumu::TAI::caltime ct; - TIMESTAMP_TO_CALTIME(TmpStamp, &ct); - t = ct; // back and forth to tai to normalize offset - ct = t; - CALTIME_TO_TIMESTAMP(&ct, *this) -#endif - + + m_Timestamp = YMDhms; + m_TZOffsetMinutes = YMDhms.offset; return true; } @@ -1177,19 +905,24 @@ Kumu::Timestamp::DecodeString(const char* datestr) bool Kumu::Timestamp::HasValue() const { - if ( Year || Month || Day || Hour || Minute || Second ) - return true; - - return false; + return true; } // bool Kumu::Timestamp::Unarchive(MemIOReader* Reader) { + ui16_t year; + ui8_t month, day, hour, minute, second; + assert(Reader); - if ( ! Reader->ReadUi16BE(&Year) ) return false; - if ( ! Reader->ReadRaw(&Month, 6) ) return false; + if ( ! Reader->ReadUi16BE(&year) ) return false; + if ( ! Reader->ReadUi8(&month) ) return false; + if ( ! Reader->ReadUi8(&day) ) return false; + if ( ! Reader->ReadUi8(&hour) ) return false; + if ( ! Reader->ReadUi8(&minute) ) return false; + if ( ! Reader->ReadUi8(&second) ) return false; + SetComponents(year, month, day, hour, minute, second); return true; } @@ -1198,50 +931,28 @@ bool Kumu::Timestamp::Archive(MemIOWriter* Writer) const { assert(Writer); - if ( ! Writer->WriteUi16BE(Year) ) return false; - if ( ! Writer->WriteRaw(&Month, 6) ) return false; + + ui16_t year; + ui8_t month, day, hour, minute, second; + GetComponents(year, month, day, hour, minute, second); + + if ( ! Writer->WriteUi16BE(year) ) return false; + if ( ! Writer->WriteUi8(month) ) return false; + if ( ! Writer->WriteUi8(day) ) return false; + if ( ! Writer->WriteUi8(hour) ) return false; + if ( ! Writer->WriteUi8(minute) ) return false; + if ( ! Writer->WriteUi8(second) ) return false; return true; } // -long -Kumu::Timestamp::GetSecondsSinceEpoch(void) const +ui64_t +Kumu::Timestamp::GetCTime() const { -#ifdef KM_WIN32 - SYSTEMTIME timeST; - TIMESTAMP_TO_SYSTIME(*this, &timeST); - FILETIME timeFT; - SystemTimeToFileTime(&timeST, &timeFT); - ULARGE_INTEGER timeUL; - timeUL.LowPart = timeFT.dwLowDateTime; - timeUL.HighPart = timeFT.dwHighDateTime; - - SYSTEMTIME epochST; - epochST.wYear = 1970; - epochST.wMonth = 0; - epochST.wDayOfWeek = 4; - epochST.wDay = 1; - epochST.wHour = 0; - epochST.wMinute = 0; - epochST.wSecond = 0; - epochST.wMilliseconds = 0; - FILETIME epochFT; - SystemTimeToFileTime(&epochST, &epochFT); - ULARGE_INTEGER epochUL; - epochUL.LowPart = epochFT.dwLowDateTime; - epochUL.HighPart = epochFT.dwHighDateTime; - - return (timeUL.QuadPart - epochUL.QuadPart) / 10000000; -#else - Kumu::TAI::caltime ct; - Kumu::TAI::tai t; - TIMESTAMP_TO_CALTIME(*this, &ct); - t = ct; - - return (long) (t.x - ui64_C(4611686018427387914)); -#endif + return m_Timestamp.x - ui64_C(4611686018427387914); } + //------------------------------------------------------------------------------------------ Kumu::MemIOWriter::MemIOWriter(ByteString* Buf) diff --git a/src/KM_util.h b/src/KM_util.h index 871a554..177cff7 100755 --- a/src/KM_util.h +++ b/src/KM_util.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2005-2011, John Hurst +Copyright (c) 2005-2012, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <KM_memio.h> #include <KM_error.h> +#include <KM_tai.h> #include <string.h> #include <string> #include <list> @@ -407,17 +408,16 @@ namespace Kumu // UTC time+date representation class Timestamp : public IArchive { - public: - ui16_t Year; - ui8_t Month; - ui8_t Day; - ui8_t Hour; - ui8_t Minute; - ui8_t Second; + TAI::tai m_Timestamp; // always UTC + i32_t m_TZOffsetMinutes; + public: Timestamp(); Timestamp(const Timestamp& rhs); Timestamp(const char* datestr); + Timestamp(const ui16_t& Year, const ui8_t& Month, const ui8_t& Day); + Timestamp(const ui16_t& Year, const ui8_t& Month, const ui8_t& Day, + const ui8_t& Hour, const ui8_t& Minute, const ui8_t& Second); virtual ~Timestamp(); const Timestamp& operator=(const Timestamp& rhs); @@ -426,23 +426,34 @@ namespace Kumu bool operator==(const Timestamp& rhs) const; bool operator!=(const Timestamp& rhs) const; + // always UTC + void GetComponents(ui16_t& Year, ui8_t& Month, ui8_t& Day, + ui8_t& Hour, ui8_t& Minute, ui8_t& Second) const; + void SetComponents(const ui16_t& Year, const ui8_t& Month, const ui8_t& Day, + const ui8_t& Hour, const ui8_t& Minute, const ui8_t& Second); + // Write the timestamp value to the given buffer in the form 2004-05-01T13:20:00+00:00 // returns 0 if the buffer is smaller than DateTimeLen const char* EncodeString(char* str_buf, ui32_t buf_len) const; - const char* EncodeStringWithOffset(char* str_buf, ui32_t buf_len, - i32_t offset_minutes = 0) const; // decode and set value from string formatted by EncodeString bool DecodeString(const char* datestr); // Add the given number of days, hours, minutes, or seconds to the timestamp value. // Values less than zero will cause the timestamp to decrease - void AddDays(i32_t); - void AddHours(i32_t); - void AddMinutes(i32_t); - void AddSeconds(i32_t); + inline void AddDays(const i32_t& d) { m_Timestamp.add_days(d); } + inline void AddHours(const i32_t& h) { m_Timestamp.add_hours(h); } + inline void AddMinutes(const i32_t& m) { m_Timestamp.add_minutes(m); } + inline void AddSeconds(const i32_t& s) { m_Timestamp.add_seconds(s); } + + // returns false if the requested adjustment is out of range + bool SetTZOffsetMinutes(const i32_t& minutes); + inline i32_t GetTZOffsetMinutes() const { return m_TZOffsetMinutes; } - // Read and write the timestamp value as a byte string having + // Return the number of seconds since the Unix epoch UTC (1970-01-01T00:00:00+00:00) + ui64_t GetCTime() const; + + // Read and write the timestamp (always UTC) value as a byte string having // the following format: // | 16 bits int, big-endian | 8 bits | 8 bits | 8 bits | 8 bits | 8 bits | // | Year A.D | Month(1-12) | Day(1-31) | Hour(0-23) | Minute(0-59) | Second(0-59) | @@ -451,9 +462,6 @@ namespace Kumu virtual ui32_t ArchiveLength() const { return 8L; } virtual bool Archive(MemIOWriter* Writer) const; virtual bool Unarchive(MemIOReader* Reader); - - // Get the number of seconds since the Unix epoch (1970-01-01T00:00:00+00:00) - long GetSecondsSinceEpoch(void) const; }; // @@ -162,6 +162,9 @@ namespace ASDCP TagValue Tag; ASDCP::UL UL; + LocalTagEntry() { Tag.a = Tag.b = 0; } + LocalTagEntry(const TagValue& tag, ASDCP::UL& ul) : Tag(tag), UL(ul) {} + inline const char* EncodeString(char* str_buf, ui32_t buf_len) const { snprintf(str_buf, buf_len, "%02x %02x: ", Tag.a, Tag.b); UL.EncodeString(str_buf + strlen(str_buf), buf_len - strlen(str_buf)); @@ -233,8 +236,7 @@ namespace ASDCP public: const Dictionary*& m_Dict; - //// UUID GenerationUID; - Timestamp LastModifiedDate; + Kumu::Timestamp LastModifiedDate; ui16_t Version; ui32_t ObjectModelVersion; UUID PrimaryPackage; @@ -272,6 +274,7 @@ namespace ASDCP ui32_t ElementData; DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {} + DeltaEntry(i8_t pos, ui8_t slice, ui32_t data) : PosTableIndex(pos), Slice(slice), ElementData(data) {} inline bool HasValue() const { return true; } ui32_t ArchiveLength() const { return sizeof(ui32_t) + 2; } bool Unarchive(Kumu::MemIOReader* Reader); @@ -293,7 +296,9 @@ namespace ASDCP // std::list<ui32_t> SliceOffset; // Array<Rational> PosTable; - IndexEntry() : TemporalOffset(0), KeyFrameOffset(0), Flags(0), StreamOffset() {} + IndexEntry() : TemporalOffset(0), KeyFrameOffset(0), Flags(0), StreamOffset(0) {} + IndexEntry(i8_t t_ofst, i8_t k_ofst, ui8_t flags, ui64_t s_ofst) : + TemporalOffset(t_ofst), KeyFrameOffset(k_ofst), Flags(flags), StreamOffset(s_ofst) {} inline bool HasValue() const { return true; } ui32_t ArchiveLength() const { return sizeof(ui64_t) + 3; }; bool Unarchive(Kumu::MemIOReader* Reader); diff --git a/src/MXFTypes.cpp b/src/MXFTypes.cpp index 7b054c7..098b728 100755 --- a/src/MXFTypes.cpp +++ b/src/MXFTypes.cpp @@ -30,6 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <KM_prng.h> +#include <KM_tai.h> #include "MXFTypes.h" #include <KM_log.h> @@ -178,7 +179,10 @@ ASDCP::UMID::MakeUMID(int Type, const UUID& AssetID) } -// Write the timestamp value to the given buffer in the form 2004-05-01 13:20:00.000 +// Write the UMID value to the given buffer in the form +// [00000000.0000.0000.00000000],00,00,00,00,00000000.0000.0000.00000000.00000000] +// or +// [00000000.0000.0000.00000000],00,00,00,00,00000000-0000-0000-0000-000000000000] // returns 0 if the buffer is smaller than DateTimeLen const char* ASDCP::UMID::EncodeString(char* str_buf, ui32_t buf_len) const @@ -380,243 +384,6 @@ ASDCP::MXF::ISO8String::Archive(Kumu::MemIOWriter* Writer) const return Writer->WriteString(*this); } - -//------------------------------------------------------------------------------------------ -// - -#ifdef WIN32 - -#define TIMESTAMP_TO_SYSTIME(ts, t) \ - (t)->wYear = (ts).Year; /* year */ \ - (t)->wMonth = (ts).Month; /* month of year (1 - 12) */ \ - (t)->wDay = (ts).Day; /* day of month (1 - 31) */ \ - (t)->wHour = (ts).Hour; /* hours (0 - 23) */ \ - (t)->wMinute = (ts).Minute; /* minutes (0 - 59) */ \ - (t)->wSecond = (ts).Second; /* seconds (0 - 60) */ \ - (t)->wDayOfWeek = 0; \ - (t)->wMilliseconds = ((ts).Tick * 4); - -#define SYSTIME_TO_TIMESTAMP(t, ts) \ - (ts).Year = (t)->wYear; /* year */ \ - (ts).Month = (t)->wMonth; /* month of year (1 - 12) */ \ - (ts).Day = (t)->wDay; /* day of month (1 - 31) */ \ - (ts).Hour = (t)->wHour; /* hours (0 - 23) */ \ - (ts).Minute = (t)->wMinute; /* minutes (0 - 59) */ \ - (ts).Second = (t)->wSecond; /* seconds (0 - 60) */ \ - (ts).Tick = (t)->wMilliseconds / 4; - -// -ASDCP::MXF::Timestamp::Timestamp() : - Year(0), Month(0), Day(0), Hour(0), Minute(0), Second(0), Tick(0) -{ - SYSTEMTIME sys_time; - GetSystemTime(&sys_time); - SYSTIME_TO_TIMESTAMP(&sys_time, *this); -} - -// -bool -ASDCP::MXF::Timestamp::operator<(const Timestamp& rhs) const -{ - SYSTEMTIME lhst, rhst; - FILETIME lft, rft; - - TIMESTAMP_TO_SYSTIME(*this, &lhst); - TIMESTAMP_TO_SYSTIME(rhs, &rhst); - SystemTimeToFileTime(&lhst, &lft); - SystemTimeToFileTime(&rhst, &rft); - return ( CompareFileTime(&lft, &rft) == -1 ); -} - -inline ui64_t -seconds_to_ns100(ui32_t seconds) -{ - return ((ui64_t)seconds * 10000000); -} - -// -void -ASDCP::MXF::Timestamp::AddDays(i32_t days) -{ - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; - - if ( days != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(86400) * (ui64_t)days ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } -} - -// -void -ASDCP::MXF::Timestamp::AddHours(i32_t hours) -{ - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; - - if ( hours != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(3600) * (ui64_t)hours ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } -} - -#else // KM_WIN32 - -#include <time.h> - -#define TIMESTAMP_TO_TM(ts, t) \ - (t)->tm_year = (ts).Year - 1900; /* year - 1900 */ \ - (t)->tm_mon = (ts).Month - 1; /* month of year (0 - 11) */ \ - (t)->tm_mday = (ts).Day; /* day of month (1 - 31) */ \ - (t)->tm_hour = (ts).Hour; /* hours (0 - 23) */ \ - (t)->tm_min = (ts).Minute; /* minutes (0 - 59) */ \ - (t)->tm_sec = (ts).Second; /* seconds (0 - 60) */ - -#define TM_TO_TIMESTAMP(t, ts) \ - (ts).Year = (t)->tm_year + 1900; /* year - 1900 */ \ - (ts).Month = (t)->tm_mon + 1; /* month of year (0 - 11) */ \ - (ts).Day = (t)->tm_mday; /* day of month (1 - 31) */ \ - (ts).Hour = (t)->tm_hour; /* hours (0 - 23) */ \ - (ts).Minute = (t)->tm_min; /* minutes (0 - 59) */ \ - (ts).Second = (t)->tm_sec; /* seconds (0 - 60) */ - -// -ASDCP::MXF::Timestamp::Timestamp() : - Year(0), Month(0), Day(0), Hour(0), Minute(0), Second(0) -{ - time_t t_now = time(0); - struct tm* now = gmtime(&t_now); - TM_TO_TIMESTAMP(now, *this); -} - -// -bool -ASDCP::MXF::Timestamp::operator<(const Timestamp& rhs) const -{ - struct tm lhtm, rhtm; - TIMESTAMP_TO_TM(*this, &lhtm); - TIMESTAMP_TO_TM(rhs, &rhtm); - return ( timegm(&lhtm) < timegm(&rhtm) ); -} - -// -void -ASDCP::MXF::Timestamp::AddDays(i32_t days) -{ - struct tm current; - - if ( days != 0 ) - { - TIMESTAMP_TO_TM(*this, ¤t); - time_t adj_time = timegm(¤t); - adj_time += 86400 * days; - struct tm* now = gmtime(&adj_time); - TM_TO_TIMESTAMP(now, *this); - } -} - -// -void -ASDCP::MXF::Timestamp::AddHours(i32_t hours) -{ - struct tm current; - - if ( hours != 0 ) - { - TIMESTAMP_TO_TM(*this, ¤t); - time_t adj_time = timegm(¤t); - adj_time += 3600 * hours; - struct tm* now = gmtime(&adj_time); - TM_TO_TIMESTAMP(now, *this); - } -} - -#endif // KM_WIN32 - - -ASDCP::MXF::Timestamp::Timestamp(const Timestamp& rhs) : IArchive() -{ - Year = rhs.Year; - Month = rhs.Month; - Day = rhs.Day; - Hour = rhs.Hour; - Minute = rhs.Minute; - Second = rhs.Second; -} - -ASDCP::MXF::Timestamp::~Timestamp() -{ -} - -// -const ASDCP::MXF::Timestamp& -ASDCP::MXF::Timestamp::operator=(const Timestamp& rhs) -{ - Year = rhs.Year; - Month = rhs.Month; - Day = rhs.Day; - Hour = rhs.Hour; - Minute = rhs.Minute; - Second = rhs.Second; - return *this; -} - -// -bool -ASDCP::MXF::Timestamp::operator==(const Timestamp& rhs) const -{ - if ( Year == rhs.Year - && Month == rhs.Month - && Day == rhs.Day - && Hour == rhs.Hour - && Minute == rhs.Minute - && Second == rhs.Second ) - return true; - - return false; -} - -// -bool -ASDCP::MXF::Timestamp::operator!=(const Timestamp& rhs) const -{ - if ( Year != rhs.Year - || Month != rhs.Month - || Day != rhs.Day - || Hour != rhs.Hour - || Minute != rhs.Minute - || Second != rhs.Second ) - return true; - - return false; -} - -// -const char* -ASDCP::MXF::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const -{ - // 2004-05-01 13:20:00.000 - snprintf(str_buf, buf_len, - "%04hu-%02hu-%02hu %02hu:%02hu:%02hu.000", - Year, Month, Day, Hour, Minute, Second); - - return str_buf; -} - //------------------------------------------------------------------------------------------ // diff --git a/src/MXFTypes.h b/src/MXFTypes.h index 410fa8b..eaddb38 100755 --- a/src/MXFTypes.h +++ b/src/MXFTypes.h @@ -237,58 +237,6 @@ namespace ASDCP }; // - class Timestamp : public Kumu::IArchive - { - public: - ui16_t Year; - ui8_t Month; - ui8_t Day; - ui8_t Hour; - ui8_t Minute; - ui8_t Second; - ui8_t Tick; - - Timestamp(); - Timestamp(const Timestamp& rhs); - Timestamp(const char* datestr); - virtual ~Timestamp(); - - const Timestamp& operator=(const Timestamp& rhs); - bool operator<(const Timestamp& rhs) const; - bool operator==(const Timestamp& rhs) const; - bool operator!=(const Timestamp& rhs) const; - - // decode and set value from string formatted by EncodeAsString - Result_t SetFromString(const char* datestr); - - // add the given number of days or hours to the timestamp value. Values less than zero - // will cause the value to decrease - void AddDays(i32_t); - void AddHours(i32_t); - - // Write the timestamp value to the given buffer in the form 2004-05-01 13:20:00.000 - // returns 0 if the buffer is smaller than DateTimeLen - const char* EncodeString(char* str_buf, ui32_t buf_len) const; - - // - inline virtual bool Unarchive(Kumu::MemIOReader* Reader) { - if ( ! Reader->ReadUi16BE(&Year) ) return false; - if ( ! Reader->ReadRaw(&Month, 6) ) return false; - return true; - } - - inline virtual bool HasValue() const { return true; } - inline virtual ui32_t ArchiveLength() const { return 8L; } - - // - inline virtual bool Archive(Kumu::MemIOWriter* Writer) const { - if ( ! Writer->WriteUi16BE(Year) ) return false; - if ( ! Writer->WriteRaw(&Month, 6) ) return false; - return true; - } - }; - - // class ISO8String : public std::string, public Kumu::IArchive { public: @@ -389,7 +337,6 @@ namespace ASDCP virtual ~VersionType() {} const VersionType& operator=(const VersionType& rhs) { Copy(rhs); return *this; } - void Copy(const VersionType& rhs) { Major = rhs.Major; Minor = rhs.Minor; diff --git a/src/Makefile.am b/src/Makefile.am index 58cfe89..7947d99 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -83,30 +83,38 @@ libasdcp_la_CPPFLAGS = -DASDCP_PLATFORM=\"@host@\" # Python extension if PYTHON_USE -lib_LTLIBRARIES += libpyasdcp.la libnapali.la +lib_LTLIBRARIES += libpyasdcp.la +#### libnapali.la nodist_libpyasdcp_la_SOURCES = \ - kumu_python.cpp kumu_python.h \ - asdcp_python.cpp asdcp_python.h \ + kumu_python.cpp \ + kumu_python.h \ + asdcp_python.cpp \ + asdcp_python.h \ asdcp_python_descriptor.cpp \ - asdcp_python_misc.cpp asdcp_python_writerinfo.h \ - asdcp_wrappers.h asdcp_python_mxf.cpp asdcp_python_mxf_text.cpp + asdcp_python_misc.cpp \ + asdcp_python_writerinfo.h \ + asdcp_wrappers.h \ + asdcp_python_mxf.cpp \ + asdcp_python_mxf_text.cpp \ + asdcp_python_mxf_metadata.cpp -nodist_libnapali_la_SOURCES = \ - napali_python.cpp napali_python.h +####nodist_libnapali_la_SOURCES = \ +#### napali_python.cpp napali_python.h libpyasdcp_la_CPPFLAGS = @PYTHON_CPPFLAGS@ libpyasdcp_la_LDFLAGS = @PYTHON_LSPEC@ -release @VERSION@ libpyasdcp_la_LIBADD = libkumu.la libasdcp.la -libnapali_la_CPPFLAGS = @PYTHON_CPPFLAGS@ -libnapali_la_LDFLAGS = @PYTHON_LSPEC@ -release @VERSION@ -libnapali_la_LIBADD = libkumu.la libasdcp.la +####libnapali_la_CPPFLAGS = @PYTHON_CPPFLAGS@ +####libnapali_la_LDFLAGS = @PYTHON_LSPEC@ -release @VERSION@ +####libnapali_la_LIBADD = libkumu.la libasdcp.la pyexecdir = @PYTHON_EXECDIR@ pyexec_includedir = $(PYTHON_PREFIX)/include/python$(PYTHON_SHORTVERSION) -nodist_pyexec_include_HEADERS = kumu_python.h asdcp_python.h napali_python.h asdcp_wrappers.h -pyexec_LTLIBRARIES = kumu.la asdcp.la napali.la +nodist_pyexec_include_HEADERS = kumu_python.h asdcp_python.h asdcp_wrappers.h +pyexec_LTLIBRARIES = kumu.la asdcp.la +#### napali_python.h napali.la nodist_kumu_la_SOURCES = pykumu.cpp kumu_python.h kumu_la_CPPFLAGS = @PYTHON_CPPFLAGS@ @@ -118,10 +126,10 @@ asdcp_la_CPPFLAGS = @PYTHON_CPPFLAGS@ asdcp_la_LDFLAGS = @PYTHON_LSPEC@ -avoid-version -module asdcp_la_LIBADD = libpyasdcp.la -nodist_napali_la_SOURCES = pynapali.cpp kumu_python.h napali_python.h -napali_la_CPPFLAGS = @PYTHON_CPPFLAGS@ -napali_la_LDFLAGS = @PYTHON_LSPEC@ -avoid-version -module -napali_la_LIBADD = libnapali.la libpyasdcp.la +####nodist_napali_la_SOURCES = pynapali.cpp kumu_python.h napali_python.h +####napali_la_CPPFLAGS = @PYTHON_CPPFLAGS@ +####napali_la_LDFLAGS = @PYTHON_LSPEC@ -avoid-version -module +####napali_la_LIBADD = libnapali.la libpyasdcp.la endif # list of programs to be built and installed @@ -208,10 +216,12 @@ TESTS_ENVIRONMENT = BUILD_DIR="." TEST_FILES=../tests TEST_FILE_PREFIX=DCPd1-M1 EXTRA_DIST = fips-186-test-harness.pl $(TESTS) if !FREEDIST if DEV_HEADERS -EXTRA_DIST += $(nodist_libasdcp_la_SOURCES) $(nodist_tt_xform_SOURCES) $(nodist_napali_la_SOURCES) $(nodist_libnapali_la_SOURCES) +EXTRA_DIST += $(nodist_libasdcp_la_SOURCES) $(nodist_tt_xform_SOURCES) +#### $(nodist_napali_la_SOURCES) $(nodist_libnapali_la_SOURCES) endif if PYTHON_USE -EXTRA_DIST += $(nodist_pyexec_include_HEADERS) $(nodist_libpyasdcp_la_SOURCES) $(nodist_kumu_la_SOURCES) $(nodist_asdcp_la_SOURCES) $(nodist_napali_la_SOURCES) $(nodist_libnapali_la_SOURCES) +EXTRA_DIST += $(nodist_pyexec_include_HEADERS) $(nodist_libpyasdcp_la_SOURCES) $(nodist_kumu_la_SOURCES) $(nodist_asdcp_la_SOURCES) +#### $(nodist_napali_la_SOURCES) $(nodist_libnapali_la_SOURCES) endif endif diff --git a/src/Metadata.h b/src/Metadata.h index 250f379..507a151 100755 --- a/src/Metadata.h +++ b/src/Metadata.h @@ -55,7 +55,7 @@ namespace ASDCP VersionType ProductVersion; UTF16String VersionString; UUID ProductUID; - Timestamp ModificationDate; + Kumu::Timestamp ModificationDate; VersionType ToolkitVersion; UTF16String Platform; @@ -131,8 +131,8 @@ namespace ASDCP const Dictionary*& m_Dict; UMID PackageUID; UTF16String Name; - Timestamp PackageCreationDate; - Timestamp PackageModifiedDate; + Kumu::Timestamp PackageCreationDate; + Kumu::Timestamp PackageModifiedDate; Batch<UUID> Tracks; GenericPackage(const Dictionary*& d); diff --git a/src/PCMParserList.cpp b/src/PCMParserList.cpp index f97b66e..2ebdfa0 100755 --- a/src/PCMParserList.cpp +++ b/src/PCMParserList.cpp @@ -207,7 +207,7 @@ ASDCP::PCMParserList::OpenRead(const Kumu::PathList_t& argv, const Rational& Pic if ( ASDCP_SUCCESS(result) ) { m_ADesc.ChannelCount = m_ChannelCount; - m_ADesc.AvgBps = ceil(m_ADesc.AudioSamplingRate.Quotient()) * m_ADesc.BlockAlign; + m_ADesc.AvgBps = (ui32_t)(ceil(m_ADesc.AudioSamplingRate.Quotient()) * m_ADesc.BlockAlign); } else { diff --git a/src/asdcp-wrap.cpp b/src/asdcp-wrap.cpp index 73b76a3..bca7822 100755 --- a/src/asdcp-wrap.cpp +++ b/src/asdcp-wrap.cpp @@ -137,7 +137,8 @@ Options:\n\ -d <duration> - Number of frames to process, default all\n\ -f <start-frame> - Starting frame number, default 0\n\ -l <label> - Use given channel format label when writing MXF sound\n\ - files. SMPTE 429-2 labels: '5.1', '6.1', '7.1', '7.1DS', 'WTF'.\n\ + files. SMPTE 429-2 labels: '5.1', '6.1', '7.1',\n\ + '7.1DS', 'WTF'\n\ Default is no label (valid for Interop only).\n\ -L - Write SMPTE UL values instead of MXF Interop\n\ -p <rate> - fps of picture when wrapping PCM or JP2K:\n\ @@ -306,6 +307,15 @@ public: break; + case 'C': + TEST_EXTRA_ARG(i, 'U'); + if ( ! channel_assignment.DecodeHex(argv[i]) ) + { + fprintf(stderr, "Error decoding UL value: %s\n", argv[i]); + return; + } + break; + case 'd': TEST_EXTRA_ARG(i, 'd'); duration = abs(atoi(argv[i])); @@ -362,15 +372,6 @@ public: picture_rate = abs(atoi(argv[i])); break; - case 'U': - TEST_EXTRA_ARG(i, 'U'); - if ( ! channel_assignment.DecodeHex(argv[i]) ) - { - fprintf(stderr, "Error decoding UL value: %s\n", argv[i]); - return; - } - break; - case 'V': version_flag = true; break; case 'v': verbose_flag = true; break; case 'W': no_write_flag = true; break; diff --git a/src/h__Reader.cpp b/src/h__Reader.cpp index 62fa834..23b1e1a 100755 --- a/src/h__Reader.cpp +++ b/src/h__Reader.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2010, John Hurst +Copyright (c) 2004-2012, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -29,16 +29,41 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \brief MXF file reader base class */ +#define DEFAULT_MD_DECL #include "AS_DCP_internal.h" #include "KLV.h" using namespace ASDCP; using namespace ASDCP::MXF; +static Kumu::Mutex sg_DefaultMDInitLock; +static bool sg_DefaultMDTypesInit = false; +static const ASDCP::Dictionary *sg_dict; + +// +void +ASDCP::default_md_object_init() +{ + if ( ! sg_DefaultMDTypesInit ) + { + Kumu::AutoMutex BlockLock(sg_DefaultMDInitLock); + + if ( ! sg_DefaultMDTypesInit ) + { + sg_dict = &DefaultSMPTEDict(); + g_OPAtomHeader = new ASDCP::MXF::OPAtomHeader(sg_dict); + g_OPAtomIndexFooter = new ASDCP::MXF::OPAtomIndexFooter(sg_dict); + sg_DefaultMDTypesInit = true; + } + } +} + + // ASDCP::h__Reader::h__Reader(const Dictionary& d) : m_HeaderPart(m_Dict), m_BodyPart(m_Dict), m_FooterPart(m_Dict), m_Dict(&d), m_EssenceStart(0) { + default_md_object_init(); } ASDCP::h__Reader::~h__Reader() diff --git a/src/h__Writer.cpp b/src/h__Writer.cpp index db263bb..9966cea 100755 --- a/src/h__Writer.cpp +++ b/src/h__Writer.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2010, John Hurst +Copyright (c) 2004-2012, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -73,6 +73,7 @@ ASDCP::h__Writer::h__Writer(const Dictionary& d) : m_HeaderSize(0), m_EssenceStart(0), m_EssenceDescriptor(0), m_FramesWritten(0), m_StreamOffset(0) { + default_md_object_init(); } ASDCP::h__Writer::~h__Writer() |
