summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormsheby <msheby@cinecert.com>2007-10-25 18:44:45 +0000
committermsheby <>2007-10-25 18:44:45 +0000
commitdeadc1bf01e8bc68905c7d33578ffb77b8317c8f (patch)
treee23733b29ffed1a996599c00a3c74490dcff3a3d /src
parentc5e3e4e83032b790c62bd55795a20dd912010c9f (diff)
Win32 portability fixes
Diffstat (limited to 'src')
-rwxr-xr-xsrc/AS_DCP_AES.cpp57
-rwxr-xr-xsrc/AS_DCP_JP2K.cpp69
-rwxr-xr-xsrc/AS_DCP_MXF.cpp6
-rwxr-xr-xsrc/AS_DCP_internal.h17
-rw-r--r--src/KM_fileio.cpp3
-rwxr-xr-xsrc/KM_fileio.h2
-rwxr-xr-xsrc/MXF.cpp2
-rwxr-xr-xsrc/MXF.h2
-rwxr-xr-xsrc/asdcp-test.cpp10
-rwxr-xr-xsrc/h__Reader.cpp39
10 files changed, 154 insertions, 53 deletions
diff --git a/src/AS_DCP_AES.cpp b/src/AS_DCP_AES.cpp
index 1146bb7..84229d5 100755
--- a/src/AS_DCP_AES.cpp
+++ b/src/AS_DCP_AES.cpp
@@ -239,6 +239,7 @@ ASDCP::AESDecContext::DecryptBlock(const byte_t* ct_buf, byte_t* pt_buf, ui32_t
//------------------------------------------------------------------------------------------
+static const ui32_t B_len = 64; // rfc 2104, Sec. 2
static byte_t ipad[KeyLen] = { 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 };
@@ -249,12 +250,13 @@ static byte_t opad[KeyLen] = { 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
class HMACContext::h__HMACContext
{
SHA_CTX m_SHA;
- byte_t m_key[KeyLen];
+ byte_t m_key[KeyLen];
ASDCP_NO_COPY_CONSTRUCT(h__HMACContext);
public:
- byte_t sha_value[HMAC_SIZE];
- bool m_Final;
+ byte_t m_SHAValue[HMAC_SIZE];
+ LabelSet_t m_SetType;
+ bool m_Final;
h__HMACContext() : m_Final(false) {}
~h__HMACContext() {}
@@ -265,6 +267,7 @@ public:
byte_t rng_buf[SHA_DIGEST_LENGTH*2];
Kumu::Gen_FIPS_186_Value(key, KeyLen, rng_buf, SHA_DIGEST_LENGTH*2);
memcpy(m_key, rng_buf+SHA_DIGEST_LENGTH, KeyLen);
+ m_SetType = LS_MXF_SMPTE;
Reset();
}
@@ -282,24 +285,37 @@ public:
SHA1_Update(&SHA, key_nonce, KeyLen);
SHA1_Final(sha_buf, &SHA);
memcpy(m_key, sha_buf, KeyLen);
-
+ m_SetType = LS_MXF_INTEROP;
Reset();
}
+ //
void
Reset()
{
- byte_t xor_buf[KeyLen];
- memset(sha_value, 0, HMAC_SIZE);
+ byte_t xor_buf[B_len];
+ memset(m_SHAValue, 0, HMAC_SIZE);
m_Final = false;
SHA1_Init(&m_SHA);
// H(K XOR opad, H(K XOR ipad, text))
// ^^^^^^^^^^
- for ( ui32_t i = 0; i < KeyLen; i++ )
+ ui32_t i = 0;
+
+ for ( ; i < KeyLen; i++ )
xor_buf[i] = m_key[i] ^ ipad[i];
- SHA1_Update(&m_SHA, xor_buf, KeyLen);
+ if ( m_SetType == LS_MXF_SMPTE )
+ {
+ for ( ; i < B_len; i++ )
+ xor_buf[i] = 0 ^ ipad[0];
+
+ SHA1_Update(&m_SHA, xor_buf, B_len);
+ }
+ else
+ {
+ SHA1_Update(&m_SHA, xor_buf, KeyLen);
+ }
}
//
@@ -317,20 +333,33 @@ public:
{
// H(K XOR opad, H(K XOR ipad, text))
// ^^^^^^^^^^^^^^^
- SHA1_Final(sha_value, &m_SHA);
+ SHA1_Final(m_SHAValue, &m_SHA);
SHA_CTX SHA;
SHA1_Init(&SHA);
byte_t xor_buf[KeyLen];
+ ui32_t i = 0;
- for ( ui32_t i = 0; i < KeyLen; i++ )
+ for ( ; i < KeyLen; i++ )
xor_buf[i] = m_key[i] ^ opad[i];
+ if ( m_SetType == LS_MXF_SMPTE )
+ {
+ for ( ; i < B_len; i++ )
+ xor_buf[i] = 0 ^ opad[0];
+
+ SHA1_Update(&m_SHA, xor_buf, B_len);
+ }
+ else
+ {
+ SHA1_Update(&m_SHA, xor_buf, KeyLen);
+ }
+
SHA1_Update(&SHA, xor_buf, KeyLen);
- SHA1_Update(&SHA, sha_value, HMAC_SIZE);
+ SHA1_Update(&SHA, m_SHAValue, HMAC_SIZE);
- SHA1_Final(sha_value, &SHA);
+ SHA1_Final(m_SHAValue, &SHA);
m_Final = true;
}
};
@@ -410,7 +439,7 @@ HMACContext::GetHMACValue(byte_t* buf) const
if ( m_Context.empty() || ! m_Context->m_Final )
return RESULT_INIT;
- memcpy(buf, m_Context->sha_value, HMAC_SIZE);
+ memcpy(buf, m_Context->m_SHAValue, HMAC_SIZE);
return RESULT_OK;
}
@@ -424,7 +453,7 @@ HMACContext::TestHMACValue(const byte_t* buf) const
if ( m_Context.empty() || ! m_Context->m_Final )
return RESULT_INIT;
- return ( memcmp(buf, m_Context->sha_value, HMAC_SIZE) == 0 ) ? RESULT_OK : RESULT_HMACFAIL;
+ return ( memcmp(buf, m_Context->m_SHAValue, HMAC_SIZE) == 0 ) ? RESULT_OK : RESULT_HMACFAIL;
}
diff --git a/src/AS_DCP_JP2K.cpp b/src/AS_DCP_JP2K.cpp
index 0271d23..f5ce335 100755
--- a/src/AS_DCP_JP2K.cpp
+++ b/src/AS_DCP_JP2K.cpp
@@ -386,16 +386,75 @@ ASDCP::JP2K::MXFReader::DumpIndex(FILE* stream) const
class ASDCP::JP2K::MXFSReader::h__SReader : public lh__Reader
{
- StereoscopicPhase_t m_NextPhase;
+ ui32_t m_StereoFrameReady;
public:
- h__SReader() : m_NextPhase(SP_LEFT) {}
+ h__SReader() : m_StereoFrameReady(0xffffffff) {}
//
Result_t ReadFrame(ui32_t FrameNum, StereoscopicPhase_t phase, FrameBuffer& FrameBuf,
- AESDecContext* Ctx, HMACContext* HMAC) const
+ AESDecContext* Ctx, HMACContext* HMAC)
{
- return Kumu::RESULT_NOTIMPL;
+ // look up frame index node
+ IndexTableSegment::IndexEntry TmpEntry;
+
+ if ( ASDCP_FAILURE(m_FooterPart.Lookup(FrameNum, TmpEntry)) )
+ {
+ DefaultLogSink().Error("Frame value out of range: %u\n", FrameNum);
+ return RESULT_RANGE;
+ }
+
+ // get frame position
+ Kumu::fpos_t FilePosition = m_EssenceStart + TmpEntry.StreamOffset;
+ Result_t result = RESULT_OK;
+
+ if ( phase == SP_LEFT )
+ {
+ if ( FilePosition != m_LastPosition )
+ {
+ m_LastPosition = FilePosition;
+ result = m_File.Seek(FilePosition);
+ }
+
+ // the call to ReadEKLVPacket() will leave the file on an R frame
+ m_StereoFrameReady = FrameNum;
+ }
+ else if ( phase == SP_RIGHT )
+ {
+ if ( m_StereoFrameReady != FrameNum )
+ {
+ // the file is not already positioned, we must do some work
+ // seek to the companion SP_LEFT frame and read the frame's key and length
+ if ( FilePosition != m_LastPosition )
+ {
+ m_LastPosition = FilePosition;
+ result = m_File.Seek(FilePosition);
+ }
+
+ KLReader Reader;
+ result = Reader.ReadKLFromFile(m_File);
+
+ if ( ASDCP_SUCCESS(result) )
+ {
+ // skip over the companion SP_LEFT frame
+ Kumu::fpos_t new_pos = FilePosition + SMPTE_UL_LENGTH + Reader.KLLength() + Reader.Length();
+ result = m_File.Seek(new_pos);
+ }
+ }
+
+ // the call to ReadEKLVPacket() will leave the file not on an R frame
+ m_StereoFrameReady = 0xffffffff;
+ }
+ else
+ {
+ DefaultLogSink().Error("Unexpected stereoscopic phase value: %u\n", phase);
+ return RESULT_STATE;
+ }
+
+ if( ASDCP_SUCCESS(result) )
+ result = ReadEKLVPacket(FrameNum, FrameBuf, Dict::ul(MDD_JPEG2000Essence), Ctx, HMAC);
+
+ return result;
}
};
@@ -593,7 +652,7 @@ lh__Writer::OpenWrite(const char* filename, EssenceType_t type, ui32_t HeaderSiz
GenRandomValue(m_EssenceSubDescriptor->InstanceUID);
m_EssenceDescriptor->SubDescriptors.push_back(m_EssenceSubDescriptor->InstanceUID);
- if ( type == ASDCP::ESS_JPEG_2000_S )
+ if ( type == ASDCP::ESS_JPEG_2000_S && m_Info.LabelSetType == LS_MXF_SMPTE )
{
InterchangeObject* StereoSubDesc = new StereoscopicPictureSubDescriptor;
m_EssenceSubDescriptorList.push_back(StereoSubDesc);
diff --git a/src/AS_DCP_MXF.cpp b/src/AS_DCP_MXF.cpp
index 1d4f473..2392057 100755
--- a/src/AS_DCP_MXF.cpp
+++ b/src/AS_DCP_MXF.cpp
@@ -202,14 +202,14 @@ ASDCP::RawEssenceType(const char* filename, EssenceType_t& type)
if ( i > 1 && p[i] == 1 && (p[i+1] == ASDCP::MPEG2::SEQ_START || p[i+1] == ASDCP::MPEG2::PIC_START) )
type = ESS_MPEG2_VES;
- else if ( Kumu::StringIsXML((const char*)p, FB.Size()) )
- type = ESS_TIMED_TEXT;
-
else if ( ASDCP_SUCCESS(WavHeader.ReadFromBuffer(p, read_count, &data_offset)) )
type = ESS_PCM_24b_48k;
else if ( ASDCP_SUCCESS(AIFFHeader.ReadFromBuffer(p, read_count, &data_offset)) )
type = ESS_PCM_24b_48k;
+
+ else if ( Kumu::StringIsXML((const char*)p, FB.Size()) )
+ type = ESS_TIMED_TEXT;
}
}
else if ( Kumu::PathIsDirectory(filename) )
diff --git a/src/AS_DCP_internal.h b/src/AS_DCP_internal.h
index 7f1ef25..143bccf 100755
--- a/src/AS_DCP_internal.h
+++ b/src/AS_DCP_internal.h
@@ -91,6 +91,23 @@ namespace ASDCP
Result_t DecryptFrameBuffer(const ASDCP::FrameBuffer&, ASDCP::FrameBuffer&, AESDecContext*);
//
+ class KLReader : public ASDCP::KLVPacket
+ {
+ ASDCP_NO_COPY_CONSTRUCT(KLReader);
+ byte_t m_KeyBuf[SMPTE_UL_LENGTH*2];
+
+ public:
+ KLReader() {}
+ ~KLReader() {}
+
+ inline const byte_t* Key() { return m_KeyBuf; }
+ inline const ui64_t Length() { return m_ValueLength; }
+ inline const ui64_t KLLength() { return m_KLLength; }
+
+ Result_t ReadKLFromFile(Kumu::FileReader& Reader);
+ };
+
+ //
class h__Reader
{
ASDCP_NO_COPY_CONSTRUCT(h__Reader);
diff --git a/src/KM_fileio.cpp b/src/KM_fileio.cpp
index e94525e..5a56c44 100644
--- a/src/KM_fileio.cpp
+++ b/src/KM_fileio.cpp
@@ -33,6 +33,9 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <KM_log.h>
#include <fcntl.h>
#include <assert.h>
+#ifdef KM_WIN32
+#include <direct.h>
+#endif
using namespace Kumu;
diff --git a/src/KM_fileio.h b/src/KM_fileio.h
index 9d7cc7a..ce41672 100755
--- a/src/KM_fileio.h
+++ b/src/KM_fileio.h
@@ -141,6 +141,7 @@ namespace Kumu
inline bool Match(const std::string& s) const { return true; }
};
+#ifndef KM_WIN32
class PathMatchRegex : public IPathMatch
{
regex_t m_regex;
@@ -166,6 +167,7 @@ namespace Kumu
virtual ~PathMatchGlob();
bool Match(const std::string& s) const;
};
+#endif /* !KM_WIN32 */
// Search all paths in SearchPaths for filenames matching Pattern (no directories are returned).
// Put results in FoundPaths. Returns after first find if one_shot is true.
diff --git a/src/MXF.cpp b/src/MXF.cpp
index be5e58f..be8f031 100755
--- a/src/MXF.cpp
+++ b/src/MXF.cpp
@@ -1070,7 +1070,7 @@ ASDCP::MXF::OPAtomIndexFooter::Dump(FILE* stream)
//
ASDCP::Result_t
-ASDCP::MXF::OPAtomIndexFooter::Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry& Entry)
+ASDCP::MXF::OPAtomIndexFooter::Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry& Entry) const
{
std::list<InterchangeObject*>::iterator li;
for ( li = m_PacketList->m_List.begin(); li != m_PacketList->m_List.end(); li++ )
diff --git a/src/MXF.h b/src/MXF.h
index b43fc84..f3c2449 100755
--- a/src/MXF.h
+++ b/src/MXF.h
@@ -348,7 +348,7 @@ namespace ASDCP
virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui64_t duration);
virtual void Dump(FILE* = 0);
- virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&);
+ virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&) const;
virtual void PushIndexEntry(const IndexTableSegment::IndexEntry&);
virtual void SetIndexParamsCBR(IPrimerLookup* lookup, ui32_t size, const Rational& Rate);
virtual void SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, Kumu::fpos_t offset);
diff --git a/src/asdcp-test.cpp b/src/asdcp-test.cpp
index 22743aa..ffd3246 100755
--- a/src/asdcp-test.cpp
+++ b/src/asdcp-test.cpp
@@ -60,7 +60,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace ASDCP;
-const ui32_t FRAME_BUFFER_SIZE = 4*1024*1024;
+const ui32_t FRAME_BUFFER_SIZE = 4 * Kumu::Megabyte;
//------------------------------------------------------------------------------------------
//
@@ -133,16 +133,18 @@ USAGE: %s -c <output-file> [-3] [-b <buffer-size>] [-d <duration>] [-e|-E]\n\
\n\
%s -t <input-file>\n\
\n\
- %s -x <file-prefix> [-b <buffer-size>] [-d <duration>]\n\
+ %s -x <file-prefix> [-3] [-b <buffer-size>] [-d <duration>]\n\
[-f <starting-frame>] [-m] [-p <frame-rate>] [-R] [-s <num>] [-S|-1]\n\
[-v] [-W] <input-file>\n\
\n", PACKAGE, PACKAGE, PACKAGE, PACKAGE, PACKAGE, PACKAGE, PACKAGE);
fprintf(stream, "\
Major modes:\n\
- -3 - Create a stereoscopic image file. Expects two dir-\n\
- ectories of JP2K codestreams (directories must have\n\
+ -3 - With -c, create a stereoscopic image file. Expects two\n\
+ directories of JP2K codestreams (directories must have\n\
an equal number of frames; left eye is first).\n\
+ - With -x, force stereoscopic interpretation of a JP2K\n\
+ track file.\n\
-c <output-file> - Create an AS-DCP track file from input(s)\n\
-g - Generate a random 16 byte value to stdout\n\
-G - Perform GOP start lookup test on MXF+Interop MPEG file\n\
diff --git a/src/h__Reader.cpp b/src/h__Reader.cpp
index 7bc8955..8035ac8 100755
--- a/src/h__Reader.cpp
+++ b/src/h__Reader.cpp
@@ -150,35 +150,24 @@ ASDCP::h__Reader::InitMXFIndex()
}
//
-class KLReader : public ASDCP::KLVPacket
+Result_t
+ASDCP::KLReader::ReadKLFromFile(Kumu::FileReader& Reader)
{
- ASDCP_NO_COPY_CONSTRUCT(KLReader);
- byte_t m_KeyBuf[32];
-
-public:
- KLReader() {}
- ~KLReader() {}
-
- inline const byte_t* Key() { return m_KeyBuf; }
- inline const ui64_t Length() { return m_ValueLength; }
- inline const ui64_t KLLength() { return m_KLLength; }
+ ui32_t read_count;
+ ui32_t header_length = SMPTE_UL_LENGTH + MXF_BER_LENGTH;
+ Result_t result = Reader.Read(m_KeyBuf, header_length, &read_count);
- Result_t ReadKLFromFile(Kumu::FileReader& Reader)
- {
- ui32_t read_count;
- ui32_t header_length = SMPTE_UL_LENGTH + MXF_BER_LENGTH;
- Result_t result = Reader.Read(m_KeyBuf, header_length, &read_count);
-
- if ( read_count != header_length )
- return RESULT_READFAIL;
+ if ( ASDCP_SUCCESS(result) )
+ {
+ if ( read_count != header_length )
+ result = RESULT_READFAIL;
- if ( ASDCP_SUCCESS(result) )
- result = InitFromBuffer(m_KeyBuf, header_length);
-
- return result;
- }
-};
+ else
+ result = InitFromBuffer(m_KeyBuf, header_length);
+ }
+ return result;
+}
// standard method of reading a plaintext or encrypted frame
Result_t