dump_obu: Calculate and report OBU overhead.

Change-Id: Ib315f9fdcadc83dcc4ed39e59757c0f8a99116ac
diff --git a/tools/dump_obu.cc b/tools/dump_obu.cc
index a621274..cb33cfb 100644
--- a/tools/dump_obu.cc
+++ b/tools/dump_obu.cc
@@ -136,16 +136,22 @@
 
   size_t unit_size = 0;
   int unit_number = 0;
+  int64_t obu_overhead_bytes_total = 0;
   while (ReadTemporalUnit(&input_ctx, &unit_size)) {
     printf("Temporal unit %d\n", unit_number);
-    if (!aom_tools::DumpObu(input_ctx.unit_buffer,
-                            static_cast<int>(unit_size))) {
+
+    int obu_overhead_current_unit = 0;
+    if (!aom_tools::DumpObu(input_ctx.unit_buffer, static_cast<int>(unit_size),
+                            &obu_overhead_current_unit)) {
       fprintf(stderr, "Error: Temporal Unit parse failed on unit number %d.\n",
               unit_number);
       return EXIT_FAILURE;
     }
+    printf("  OBU overhead:    %d\n", obu_overhead_current_unit);
     ++unit_number;
+    obu_overhead_bytes_total += obu_overhead_current_unit;
   }
 
+  printf("File total OBU overhead: %" PRId64 "\n", obu_overhead_bytes_total);
   return EXIT_SUCCESS;
 }
diff --git a/tools/obu_parser.cc b/tools/obu_parser.cc
index 0bef559..fe288f9 100644
--- a/tools/obu_parser.cc
+++ b/tools/obu_parser.cc
@@ -152,10 +152,11 @@
   }
 }
 
-bool DumpObu(const uint8_t *data, int length) {
+bool DumpObu(const uint8_t *data, int length, int *obu_overhead_bytes) {
   const int kObuHeaderLengthSizeBytes = 1;
   const int kMinimumBytesRequired = 1 + kObuHeaderLengthSizeBytes;
   int consumed = 0;
+  int obu_overhead = 0;
   ObuHeader obu_header;
   while (consumed < length) {
     const int remaining = length - consumed;
@@ -180,6 +181,8 @@
     const size_t length_field_size = kObuLengthFieldSizeBytes;
 #endif  // CONFIG_OBU_SIZING
 
+    obu_overhead += length_field_size;
+
     if (current_obu_length > remaining) {
       fprintf(stderr,
               "OBU parsing failed at offset %d with bad length of %d "
@@ -196,6 +199,8 @@
       return false;
     }
 
+    ++obu_overhead;
+
     if (obu_header.has_extension) {
       const uint8_t obu_ext_header_byte =
           *(data + consumed + kObuHeaderLengthSizeBytes);
@@ -205,6 +210,8 @@
                 consumed);
         return false;
       }
+
+      ++obu_overhead;
     }
 
     PrintObuHeader(&obu_header);
@@ -213,6 +220,8 @@
     consumed += current_obu_length;
   }
 
+  if (obu_overhead_bytes) *obu_overhead_bytes = obu_overhead;
+
   return true;
 }
 
diff --git a/tools/obu_parser.h b/tools/obu_parser.h
index f4545ae..54384c1 100644
--- a/tools/obu_parser.h
+++ b/tools/obu_parser.h
@@ -50,8 +50,10 @@
 };
 
 // Print information obtained from OBU(s) in data until data is exhausted or an
-// error occurs. Returns true when all data is consumed successfully.
-bool DumpObu(const uint8_t *data, int length);
+// error occurs. Returns true when all data is consumed successfully, and
+// optionally reports OBU storage overhead via obu_overhead_bytes when the
+// pointer is non-null.
+bool DumpObu(const uint8_t *data, int length, int *obu_overhead_bytes);
 
 }  // namespace aom_tools