vpxdec: add --loops option
authorJohn Koleszar <jkoleszar@google.com>
Wed, 12 Jun 2013 23:08:35 +0000 (16:08 -0700)
committerJohn Koleszar <jkoleszar@google.com>
Wed, 12 Jun 2013 23:09:20 +0000 (16:09 -0700)
Allows vpxdec to operate multiple times on the same input. Mostly
useful for debugging/development.

Change-Id: Icf25ece22e387052eade4438971eee5ff4f798ba

vpxdec.c

index deb45d35949e26287679dab87bed021505cd6c2d..513d7bd5777a28752cdac1a0cd0a5e5f38c2f3f3 100644 (file)
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -67,6 +67,8 @@ static const struct {
 };
 
 #include "args.h"
+static const arg_def_t looparg = ARG_DEF(NULL, "loops", 1,
+                                          "Number of times to decode the file");
 static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1,
                                           "Codec to use");
 static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0,
@@ -676,7 +678,7 @@ void generate_filename(const char *pattern, char *out, size_t q_len,
 }
 
 
-int main(int argc, const char **argv_) {
+int main_loop(int argc, const char **argv_) {
   vpx_codec_ctx_t          decoder;
   char                  *fn = NULL;
   int                    i;
@@ -737,6 +739,8 @@ int main(int argc, const char **argv_) {
       else
         die("Error: Unrecognized argument (%s) to --codec\n",
             arg.val);
+    } else if (arg_match(&arg, &looparg, argi)) {
+      // no-op
     } else if (arg_match(&arg, &outputfile, argi))
       outfile_pattern = arg.val;
     else if (arg_match(&arg, &use_yv12, argi)) {
@@ -1152,3 +1156,25 @@ fail:
 
   return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS;
 }
+
+int main(int argc, const char **argv_) {
+  unsigned int loops = 1, i;
+  char **argv, **argi, **argj;
+  struct arg arg;
+  int error = 0;
+
+  argv = argv_dup(argc - 1, argv_ + 1);
+  for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
+    memset(&arg, 0, sizeof(arg));
+    arg.argv_step = 1;
+
+    if (arg_match(&arg, &looparg, argi)) {
+      loops = arg_parse_uint(&arg);
+      break;
+    }
+  }
+  free(argv);
+  for (i = 0; !error && i < loops; i++)
+    error = main_loop(argc, argv_);
+  return error;
+}