\brief KLV+MXF test
*/
-#include "AS_DCP.h"
#include "MXF.h"
#include <KM_log.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <assert.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+
using namespace ASDCP;
using Kumu::DefaultLogSink;
//
// command line option parser class
-static const char* PROGRAM_NAME = "essence-scraper"; // program name for messages
+static const char* PROGRAM_NAME = "klvsplit"; // program name for messages
typedef std::list<std::string> FileList_t;
// Increment the iterator, test for an additional non-option command line argument.
usage(FILE* stream = stdout)
{
fprintf(stream, "\
-USAGE: %s [-l <limit>] [-p <prefix>] [-s <suffix>] [-v] (JPEG2000Essence|\n\
- MPEG2Essence|WAVEssence|CryptEssence|-u <ul-value>)\n\
+USAGE: %s [-l <limit>] [-p <prefix>] [-s <suffix>] [-u|-U] [-v] \n\
+ (<type-name>|<type-ul>) <mxf-filename>+\n\
+\n\
+ %s -d\n\
\n\
%s [-h|-help] [-V]\n\
\n\
+ -d - List the valid packet type names\n\
-h | -help - Show help\n\
-l <limit> - Stop processing after <limit> matching packets\n\
-p <prefix> - Use <prefix> to start output filenames (default\n\
uses the input filename minus any extension\n\
-s <suffix> - Append <suffix> to output filenames\n\
- -u - Use the given UL to select essence packets\n\
+ -u - Unwrap the packet value (i.e., do not output KL)\n\
+ -U - Do not unwrap (default)\n\
-v - Verbose. Prints informative messages to stderr\n\
-V - Show version information\n\
\n\
NOTES: o There is no option grouping, all options must be distinct arguments.\n\
o All option arguments must be separated from the option by whitespace.\n\
-\n", PROGRAM_NAME, PROGRAM_NAME);
+\n", PROGRAM_NAME, PROGRAM_NAME, PROGRAM_NAME);
}
//
bool version_flag; // true if the version display option was selected
bool help_flag; // true if the help display option was selected
bool verbose_flag; // true if the informative messages option was selected
+ bool unwrap_mode; // true if we are to strip the K and L before writing
+ bool list_mode;
ASDCP::UL target_ul; // a UL value identifying the packets to be extracted
ui64_t extract_limit; // limit extraction to the given number of packets
std::string prefix; // output filename prefix
CommandOptions(int argc, const char** argv, const ASDCP::Dictionary& dict) :
error_flag(true), version_flag(false), help_flag(false),
- verbose_flag(false), extract_limit(ui64_C(-1))
+ verbose_flag(false), unwrap_mode(false), list_mode(false), extract_limit(ui64_C(-1))
{
for ( int i = 1; i < argc; ++i )
{
{
switch ( argv[i][1] )
{
+ case 'd': list_mode = true; break;
case 'h': help_flag = true; break;
case 'l':
suffix = argv[i];
break;
- case 'u':
- TEST_EXTRA_ARG(i, 'u');
-
- if ( ! target_ul.DecodeHex(argv[i]) )
- {
- fprintf(stderr, "Error decoding UL: %s\n", argv[i]);
- return;
- }
-
- break;
-
+ case 'u': unwrap_mode = true; break;
+ case 'U': unwrap_mode = false; break;
case 'V': version_flag = true; break;
case 'v': verbose_flag = true; break;
{
if ( ! target_ul.HasValue() )
{
- if ( strncmp(argv[i], "JPEG2000Essence", 15) == 0 )
- {
- target_ul = dict.ul(MDD_JPEG2000Essence);
- }
- else if ( strncmp(argv[i], "MPEG2Essence", 12) == 0 )
- {
- target_ul = dict.ul(MDD_MPEG2Essence);
- }
- else if ( strncmp(argv[i], "WAVEssence", 10) == 0 )
+ if ( ! target_ul.DecodeHex(argv[i]) )
{
- target_ul = dict.ul(MDD_WAVEssence);
+ const ASDCP::MDDEntry *e = dict.FindSymbol(argv[i]);
+
+ if ( e != 0 )
+ target_ul = e->ul;
}
- else
+
+ if ( ! target_ul.HasValue() )
{
- inFileList.push_back(argv[i]);
+ fprintf(stderr, "Value is not a UL or valid object name: %s\n", argv[i]);
+ return;
}
}
else
if ( help_flag || version_flag )
return;
- if ( inFileList.empty() )
+ if ( ! list_mode )
{
- fputs("Input filename(s) required.\n", stderr);
- return;
- }
+ if ( inFileList.empty() )
+ {
+ fputs("Input filename(s) required.\n", stderr);
+ return;
+ }
- if ( ! target_ul.HasValue() )
- {
- fputs("Packet UL not set. Use %s -u <ul> or keyword.\n", stderr);
- return;
+ if ( ! target_ul.HasValue() )
+ {
+ fputs("Packet UL not set. Use %s -u <ul> or keyword.\n", stderr);
+ return;
+ }
}
error_flag = false;
main(int argc, const char** argv)
{
const Dictionary *dict = &DefaultCompositeDict();
-
CommandOptions Options(argc, argv, *dict);
if ( Options.version_flag )
return 3;
}
+ if ( Options.list_mode )
+ {
+ DefaultLogSink().UnsetFilterFlag(Kumu::LOG_ALLOW_WARN);
+ char buf[64];
+
+ MDD_t di = (MDD_t)0;
+ while ( di < MDD_Max )
+ {
+ const MDDEntry& e = dict->Type(di);
+
+ if ( e.name != 0 && ( e.ul[4] == 1 || e.ul[4] == 2 ) )
+ {
+ if ( Options.verbose_flag )
+ {
+ UL tmp_ul(e.ul);
+ printf("%s %s\n", tmp_ul.EncodeString(buf, 64), e.name);
+ }
+ else
+ {
+ printf("%s\n", e.name);
+ }
+ }
+
+ di = (MDD_t)(di + 1);
+ }
+
+ return 0;
+ }
+
Result_t result = RESULT_OK;
FileList_t::iterator fi;
- for ( fi = Options.inFileList.begin(); ASDCP_SUCCESS(result) && fi != Options.inFileList.end(); ++fi )
+ for ( fi = Options.inFileList.begin(); KM_SUCCESS(result) && fi != Options.inFileList.end(); ++fi )
{
if ( Options.verbose_flag )
fprintf(stderr, "Opening file %s\n", (fi->c_str()));
std::string this_prefix = Options.prefix.empty() ? Kumu::PathSetExtension(*fi, "") + "_" : Options.prefix;
Kumu::FileReader reader;
KLVFilePacket packet;
- char filename_buf[1024], buf1[64], buf2[64];
+ char filename_buf[1024];
ui64_t item_counter = 0;
result = reader.OpenRead(fi->c_str());
if ( KM_SUCCESS(result) )
{
- result = writer.Write(packet.m_Buffer.RoData() + packet.KLLength(), packet.ValueLength());
+ if ( Options.unwrap_mode )
+ {
+ result = writer.Write(packet.m_Buffer.RoData() + packet.KLLength(), packet.ValueLength());
+ }
+ else
+ {
+ result = writer.Write(packet.m_Buffer.RoData(), packet.m_Buffer.Size());
+ }
+
++item_counter;
}
}
result = RESULT_OK;
}
- if ( ASDCP_FAILURE(result) )
+ if ( KM_FAILURE(result) )
{
fputs("Program stopped on error.\n", stderr);