diff options
| author | jhurst <jhurst@cinecert.com> | 2010-06-09 21:27:32 +0000 |
|---|---|---|
| committer | jhurst <> | 2010-06-09 21:27:32 +0000 |
| commit | a3900f7b93b5f405a3c6a414aafb7099f2a5c6da (patch) | |
| tree | 6f22cfeacd69ccd45b7dd044968a0f6f6d5fc8cb /src | |
| parent | fab4dcb49724dc9cdade3857a3f438c22c1df0f9 (diff) | |
buggy less
Diffstat (limited to 'src')
| -rwxr-xr-x | src/asdcp-test.cpp | 39 | ||||
| -rwxr-xr-x | src/h__Reader.cpp | 51 | ||||
| -rwxr-xr-x | src/h__Writer.cpp | 16 |
3 files changed, 88 insertions, 18 deletions
diff --git a/src/asdcp-test.cpp b/src/asdcp-test.cpp index 2af20f2..53d3bf0 100755 --- a/src/asdcp-test.cpp +++ b/src/asdcp-test.cpp @@ -286,7 +286,11 @@ public: Rational PictureRate() { if ( picture_rate == 23 ) return EditRate_23_98; + if ( picture_rate == 25 ) return EditRate_25; + if ( picture_rate == 30 ) return EditRate_30; if ( picture_rate == 48 ) return EditRate_48; + if ( picture_rate == 50 ) return EditRate_50; + if ( picture_rate == 60 ) return EditRate_60; return EditRate_24; } @@ -294,7 +298,11 @@ public: const char* szPictureRate() { if ( picture_rate == 23 ) return "23.976"; + if ( picture_rate == 25 ) return "25"; + if ( picture_rate == 30 ) return "30"; if ( picture_rate == 48 ) return "48"; + if ( picture_rate == 50 ) return "50"; + if ( picture_rate == 60 ) return "60"; return "24"; } @@ -1448,7 +1456,7 @@ write_timed_text_file(CommandOptions& Options) if ( ASDCP_SUCCESS(result) ) { Parser.FillTimedTextDescriptor(TDesc); - FrameBuffer.Capacity(2*Kumu::Megabyte); + FrameBuffer.Capacity(Options.fb_size); if ( Options.verbose_flag ) { @@ -1562,7 +1570,7 @@ read_timed_text_file(CommandOptions& Options) if ( ASDCP_SUCCESS(result) ) { Reader.FillTimedTextDescriptor(TDesc); - FrameBuffer.Capacity(2*Kumu::Megabyte); + FrameBuffer.Capacity(Options.fb_size); if ( Options.verbose_flag ) TimedText::DescriptorDump(TDesc); @@ -1594,23 +1602,38 @@ read_timed_text_file(CommandOptions& Options) return result; std::string XMLDoc; + std::string out_path = Kumu::PathDirname(Options.file_root); + ui32_t write_count; + char buf[64]; TimedText::ResourceList_t::const_iterator ri; result = Reader.ReadTimedTextResource(XMLDoc, Context, HMAC); - // do something with the XML here - fprintf(stderr, "XMLDoc size: %lu\n", XMLDoc.size()); + if ( ASDCP_SUCCESS(result) ) + { + Kumu::FileWriter Writer; + result = Writer.OpenWrite(Options.file_root); + + if ( ASDCP_SUCCESS(result) ) + result = Writer.Write(reinterpret_cast<const byte_t*>(XMLDoc.c_str()), XMLDoc.size(), &write_count); + } for ( ri = TDesc.ResourceList.begin() ; ri != TDesc.ResourceList.end() && ASDCP_SUCCESS(result); ri++ ) { - result = Reader.ReadAncillaryResource((*ri).ResourceID, FrameBuffer, Context, HMAC); + result = Reader.ReadAncillaryResource(ri->ResourceID, FrameBuffer, Context, HMAC); if ( ASDCP_SUCCESS(result) ) { - // if ( Options.verbose_flag ) - FrameBuffer.Dump(stderr, Options.fb_dump_size); + Kumu::FileWriter Writer; + result = Writer.OpenWrite(Kumu::PathJoin(out_path, Kumu::UUID(ri->ResourceID).EncodeHex(buf, 64)).c_str()); - // do something with the resource data here + if ( ASDCP_SUCCESS(result) ) + { + if ( Options.verbose_flag ) + FrameBuffer.Dump(stderr, Options.fb_dump_size); + + result = Writer.Write(FrameBuffer.RoData(), FrameBuffer.Size(), &write_count); + } } } diff --git a/src/h__Reader.cpp b/src/h__Reader.cpp index a463ae1..b0f8870 100755 --- a/src/h__Reader.cpp +++ b/src/h__Reader.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2009, John Hurst +Copyright (c) 2004-2010, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -159,16 +159,51 @@ ASDCP::KLReader::ReadKLFromFile(Kumu::FileReader& Reader) ui32_t header_length = SMPTE_UL_LENGTH + MXF_BER_LENGTH; Result_t result = Reader.Read(m_KeyBuf, header_length, &read_count); - if ( ASDCP_SUCCESS(result) ) + if ( ASDCP_FAILURE(result) ) + return result; + + if ( read_count != header_length ) + return RESULT_READFAIL; + + const byte_t* ber_start = m_KeyBuf + SMPTE_UL_LENGTH; + + if ( ( *ber_start & 0x80 ) == 0 ) { - if ( read_count != header_length ) - result = RESULT_READFAIL; - - else - result = InitFromBuffer(m_KeyBuf, header_length); + DefaultLogSink().Error("BER encoding error.\n"); + return RESULT_FORMAT; } - return result; + ui8_t ber_size = ( *ber_start & 0x0f ) + 1; + + if ( ber_size > 9 ) + { + DefaultLogSink().Error("BER size encoding error.\n"); + return RESULT_FORMAT; + } + + if ( ber_size < MXF_BER_LENGTH ) + { + DefaultLogSink().Error("BER size %d shorter than AS-DCP minimum %d.\n", + ber_size, MXF_BER_LENGTH); + return RESULT_FORMAT; + } + + if ( ber_size > MXF_BER_LENGTH ) + { + ui32_t diff = ber_size - MXF_BER_LENGTH; + assert((SMPTE_UL_LENGTH + MXF_BER_LENGTH + diff) <= (SMPTE_UL_LENGTH * 2)); + result = Reader.Read(m_KeyBuf + SMPTE_UL_LENGTH + MXF_BER_LENGTH, diff, &read_count); + + if ( ASDCP_FAILURE(result) ) + return result; + + if ( read_count != diff ) + return RESULT_READFAIL; + + header_length += diff; + } + + return InitFromBuffer(m_KeyBuf, header_length); } // standard method of reading a plaintext or encrypted frame diff --git a/src/h__Writer.cpp b/src/h__Writer.cpp index 6152a35..2882e33 100755 --- a/src/h__Writer.cpp +++ b/src/h__Writer.cpp @@ -605,9 +605,21 @@ ASDCP::h__Writer::WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf, const byte } else { + ui32_t BER_length = MXF_BER_LENGTH; + + if ( FrameBuf.Size() > 0x00ffffff ) // Need BER integer longer than MXF_BER_LENGTH bytes + { + BER_length = Kumu::get_BER_length_for_value(FrameBuf.Size()); + + if ( BER_length == 0 ) + result = RESULT_KLV_CODING; + } + Overhead.WriteRaw((byte_t*)EssenceUL, SMPTE_UL_LENGTH); - Overhead.WriteBER(FrameBuf.Size(), MXF_BER_LENGTH); - result = m_File.Writev(Overhead.Data(), Overhead.Length()); + Overhead.WriteBER(FrameBuf.Size(), BER_length); + + if ( ASDCP_SUCCESS(result) ) + result = m_File.Writev(Overhead.Data(), Overhead.Length()); if ( ASDCP_SUCCESS(result) ) result = m_File.Writev((byte_t*)FrameBuf.RoData(), FrameBuf.Size()); |
