Browse Source

Add verbosity flag to output frequency and frame

Matthias Vogelgesang 12 years ago
parent
commit
175df5819e
4 changed files with 57 additions and 27 deletions
  1. 6 5
      src/ufodecode-private.h
  2. 1 1
      src/ufodecode.c
  3. 31 17
      src/ufodecode.h
  4. 19 4
      test/ipedec.c

+ 6 - 5
src/ufodecode-private.h

@@ -4,11 +4,12 @@
 #include <stdbool.h>
 
 struct ufo_decoder_t {
-    int32_t height;
-    uint32_t width;
-    uint32_t *raw;
-    size_t num_bytes; 
-    uint32_t current_pos;
+    int32_t     height;
+    uint32_t    width;
+    uint32_t   *raw;
+    size_t      num_bytes; 
+    uint32_t    current_pos;
+    uint32_t    old_time_stamp;
 };
 
 

+ 1 - 1
src/ufodecode.c

@@ -81,6 +81,7 @@ ufo_decoder ufo_decoder_new(int32_t height, uint32_t width, uint32_t *raw, size_
 
     decoder->width = width;
     decoder->height = height;
+    decoder->old_time_stamp = 0;
     ufo_decoder_set_raw_data(decoder, raw, num_bytes);
     return decoder;
 }
@@ -513,7 +514,6 @@ size_t ufo_decoder_decode_frame(ufo_decoder decoder, uint32_t *raw,
         uint32_t *num_rows, uint32_t *frame_number, uint32_t *time_stamp, 
         uint16_t *cmask)
 {
-
     int err = 0;
     size_t pos = 0;
     size_t advance = 0;

+ 31 - 17
src/ufodecode.h

@@ -9,23 +9,37 @@ typedef struct ufo_decoder_t *ufo_decoder;
 extern "C" {
 #endif
 
-
-ufo_decoder ufo_decoder_new(int32_t height, uint32_t width, uint32_t *raw, size_t num_bytes);
-
-void ufo_decoder_free(ufo_decoder decoder);
-
-size_t ufo_decoder_decode_frame(ufo_decoder decoder, 
-        uint32_t *raw, size_t num_bytes, uint16_t *pixels, 
-        uint32_t *num_rows, uint32_t *frame_number, uint32_t *time_stamp, uint16_t *cmask);
-
-void ufo_decoder_set_raw_data(ufo_decoder decoder, uint32_t *raw, size_t num_bytes);
-
-int ufo_decoder_get_next_frame(ufo_decoder decoder, uint16_t **pixels, 
-        uint32_t *num_rows, uint32_t *frame_number, uint32_t *time_stamp, uint16_t *cmask);
-
-void ufo_deinterlace_interpolate(const uint16_t *frame_in, uint16_t *frame_out, int width, int height);
-void ufo_deinterlace_weave(const uint16_t *in1, const uint16_t *in2, uint16_t *out, int width, int height);
-
+ufo_decoder ufo_decoder_new             (int32_t         height, 
+                                         uint32_t        width, 
+                                         uint32_t       *raw, 
+                                         size_t          num_bytes);
+void        ufo_decoder_free            (ufo_decoder     decoder);
+size_t      ufo_decoder_decode_frame    (ufo_decoder     decoder, 
+                                         uint32_t       *raw, 
+                                         size_t          num_bytes, 
+                                         uint16_t       *pixels, 
+                                         uint32_t       *num_rows, 
+                                         uint32_t       *frame_number, 
+                                         uint32_t       *time_stamp, 
+                                         uint16_t       *cmask);
+void        ufo_decoder_set_raw_data    (ufo_decoder     decoder,
+                                         uint32_t       *raw,
+                                         size_t          num_bytes);
+int         ufo_decoder_get_next_frame  (ufo_decoder     decoder, 
+                                         uint16_t      **pixels, 
+                                         uint32_t       *num_rows, 
+                                         uint32_t       *frame_number, 
+                                         uint32_t       *time_stamp, 
+                                         uint16_t       *cmask);
+void        ufo_deinterlace_interpolate (const uint16_t *frame_in, 
+                                         uint16_t       *frame_out, 
+                                         int             width, 
+                                         int             height);
+void        ufo_deinterlace_weave       (const uint16_t *in1,
+                                         const uint16_t *in2,
+                                         uint16_t       *out, 
+                                         int             width, 
+                                         int             height);
 
 #ifdef __cplusplus
 }

+ 19 - 4
test/ipedec.c

@@ -40,17 +40,18 @@ static void usage(void)
     printf("usage: ipedec [--num-rows=ROWS] [--clear-frame] FILE [FILE ...]\n\
 Options:\n\
   -h, --help         Show this help message and exit\n\
+  -v, --verbose      Print additional information on STDOUT\n\
   -r, --num-rows=N   N rows that are contained in the file\n\
   -c, --clear-frame  Clear the frame for each iteration\n");
 }
 
-static void process_file(const char *filename, int rows, int clear_frame)
+static void process_file(const char *filename, int rows, int clear_frame, int verbose)
 {
     char *buffer = NULL;
     size_t num_bytes = 0;
     int err = 0;
     uint16_t *pixels = (uint16_t *) malloc(2048 * 1088 * sizeof(uint16_t));
-    uint32_t num_rows, frame_number, time_stamp;
+    uint32_t num_rows, frame_number, time_stamp, old_time_stamp = 0;
     int num_frames = 0;
     struct timeval start, end;
     long seconds = 0L, useconds = 0L;
@@ -85,6 +86,15 @@ static void process_file(const char *filename, int rows, int clear_frame)
         err = ufo_decoder_get_next_frame(decoder, &pixels, &num_rows, &frame_number, &time_stamp, NULL);
         gettimeofday(&end, NULL);
 
+        if (verbose) {
+            int time_stamp_diff = 80 * (time_stamp - old_time_stamp);
+
+            if (time_stamp_diff != 0)
+                printf(" %d\t %d\n", 1000000000 / time_stamp_diff, num_rows);
+
+            old_time_stamp = time_stamp;
+        }
+
         if (!err) {
             num_frames++;
             seconds += end.tv_sec - start.tv_sec;
@@ -112,11 +122,13 @@ int main(int argc, char const* argv[])
     static struct option long_options[] = {
         { "num-rows", required_argument, 0, 'r' },
         { "clear-frame", no_argument, 0, 'c' },
+        { "verbose", no_argument, 0, 'v' },
         { "help", no_argument, 0, 'h' },
         { 0, 0, 0, 0 }
     };
 
     int clear_frame = 0;
+    int verbose = 0;
     int rows = 1088;
 
     if (argc == 1) {
@@ -124,7 +136,7 @@ int main(int argc, char const* argv[])
         return 0;
     }
 
-    while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:ch", long_options, &index)) != -1) {
+    while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:cvh", long_options, &index)) != -1) {
         switch (getopt_ret) {
             case 'r': 
                 rows = atoi(optarg);
@@ -132,6 +144,9 @@ int main(int argc, char const* argv[])
             case 'c':
                 clear_frame = 1;
                 break;
+            case 'v':
+                verbose = 1;
+                break;
             case 'h':
                 usage();
                 return 0;
@@ -141,7 +156,7 @@ int main(int argc, char const* argv[])
     }
 
     while (optind < argc)
-        process_file(argv[optind++], rows, clear_frame);
+        process_file(argv[optind++], rows, clear_frame, verbose);
 
     return 0;
 }