Implemented J2K desc to/from MD
[asdcplib.git] / src / phdr-wrap.cpp
index a00d0916b468d5a00b58087ddc5ea474ec445bf9..b919b96889b3526e1f6da567e35d61d054740ab7 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2011-2014, John Hurst
+Copyright (c) 2011-2018, John Hurst
 
 All rights reserved.
 
@@ -85,13 +85,22 @@ public:
     return;                                                            \
   }
 
+//
+static void
+create_random_uuid(byte_t* uuidbuf)
+{
+  Kumu::UUID tmp_id;
+  GenRandomValue(tmp_id);
+  memcpy(uuidbuf, tmp_id.Value(), tmp_id.Size());
+}
+
 //
 void
 banner(FILE* stream = stdout)
 {
   fprintf(stream, "\n\
 %s (asdcplib %s)\n\n\
-Copyright (c) 2011-2014, John Hurst\n\n\
+Copyright (c) 2011-2018, John Hurst\n\n\
 asdcplib may be copied only under the terms of the license found at\n\
 the top of every file in the asdcplib distribution kit.\n\n\
 Specify the -h (help) option for further information about %s\n\n",
@@ -151,21 +160,6 @@ Options:\n\
          o All option arguments must be separated from the option by whitespace.\n\n");
 }
 
-//
-static ASDCP::Rational
-decode_rational(const char* str_rat)
-{
-  assert(str_rat);
-  ui32_t Num = atoi(str_rat);
-  ui32_t Den = 0;
-
-  const char* den_str = strrchr(str_rat, '/');
-  if ( den_str != 0 )
-    Den = atoi(den_str+1);
-
-  return ASDCP::Rational(Num, Den);
-}
-
 //
 //
 class CommandOptions
@@ -212,7 +206,8 @@ public:
   AS_02::IndexStrategy_t index_strategy; //Shim parameter index_strategy_frame/clip
   ui32_t partition_space; //Shim parameter partition_spacing
 
-  std::string PHDR_master_metadata; //
+  std::string PHDR_master_metadata;
+  std::string global_metadata_filename;
 
   //
   CommandOptions(int argc, const char** argv) :
@@ -246,7 +241,11 @@ public:
              {
              case 'A':
                TEST_EXTRA_ARG(i, 'A');
-               edit_rate = decode_rational(argv[i]);
+               if ( ! DecodeRational(argv[i], aspect_ratio) )
+                 {
+                   fprintf(stderr, "Error decoding aspect ratio value: %s\n", argv[i]);
+                   return;
+                 }
                break;
 
              case 'a':
@@ -266,7 +265,7 @@ public:
 
              case 'b':
                TEST_EXTRA_ARG(i, 'b');
-               fb_size = abs(atoi(argv[i]));
+               fb_size = Kumu::xabs(strtol(argv[i], 0, 10));
 
                if ( verbose_flag )
                  fprintf(stderr, "Frame Buffer size: %u bytes.\n", fb_size);
@@ -275,12 +274,12 @@ public:
 
              case 'D':
                TEST_EXTRA_ARG(i, 'D');
-               component_depth = abs(atoi(argv[i]));
+               component_depth = Kumu::xabs(strtol(argv[i], 0, 10));
                break;
 
              case 'd':
                TEST_EXTRA_ARG(i, 'd');
-               duration = abs(atoi(argv[i]));
+               duration = Kumu::xabs(strtol(argv[i], 0, 10));
                break;
 
              case 'E': encrypt_header_flag = false; break;
@@ -288,7 +287,7 @@ public:
 
              case 'F':
                TEST_EXTRA_ARG(i, 'F');
-               field_dominance = abs(atoi(argv[i]));
+               field_dominance = Kumu::xabs(strtol(argv[i], 0, 10));
                if ( field_dominance > 1 )
                  {
                    fprintf(stderr, "Field dominance value must be \"0\" or \"1\"\n");
@@ -296,6 +295,11 @@ public:
                  }
                break;
 
+             case 'g':
+               TEST_EXTRA_ARG(i, 'g');
+               global_metadata_filename = argv[i];
+               break;
+
              case 'h': help_flag = true; break;
 
              case 'i':
@@ -354,7 +358,12 @@ public:
 
              case 'r':
                TEST_EXTRA_ARG(i, 'r');
-               edit_rate = decode_rational(argv[i]);
+               if ( ! DecodeRational(argv[i], edit_rate) )
+                 {
+                   fprintf(stderr, "Error decoding edit rate value: %s\n", argv[i]);
+                   return;
+                 }
+
                break;
 
              case 'R':
@@ -363,17 +372,17 @@ public:
 
              case 's':
                TEST_EXTRA_ARG(i, 's');
-               partition_space = abs(atoi(argv[i]));
+               partition_space = Kumu::xabs(strtol(argv[i], 0, 10));
                break;
 
              case 't':
                TEST_EXTRA_ARG(i, 't');
-               rgba_MinRef = abs(atoi(argv[i]));
+               rgba_MinRef = Kumu::xabs(strtol(argv[i], 0, 10));
                break;
 
              case 'T':
                TEST_EXTRA_ARG(i, 'T');
-               rgba_MaxRef = abs(atoi(argv[i]));
+               rgba_MaxRef = Kumu::xabs(strtol(argv[i], 0, 10));
                break;
 
              case 'u': show_ul_values_flag = true; break;
@@ -383,12 +392,12 @@ public:
 
              case 'x':
                TEST_EXTRA_ARG(i, 'x');
-               horizontal_subsampling = abs(atoi(argv[i]));
+               horizontal_subsampling = Kumu::xabs(strtol(argv[i], 0, 10));
                break;
 
              case 'X':
                TEST_EXTRA_ARG(i, 'X');
-               vertical_subsampling = abs(atoi(argv[i]));
+               vertical_subsampling = Kumu::xabs(strtol(argv[i], 0, 10));
                break;
 
              case 'Y':
@@ -609,6 +618,7 @@ write_JP2K_file(CommandOptions& Options)
   return result;
 }
 
+
 //
 int
 main(int argc, const char** argv)