[xiph-commits] r14337 - experimental/giles/rogg
giles at svn.xiph.org
giles at svn.xiph.org
Wed Jan 2 17:33:38 PST 2008
Author: giles
Date: 2008-01-02 17:33:38 -0800 (Wed, 02 Jan 2008)
New Revision: 14337
Added:
experimental/giles/rogg/rogg_stats.c
Modified:
experimental/giles/rogg/Makefile
Log:
Script for measuring the average encapsulation overhead of Ogg streams.
Modified: experimental/giles/rogg/Makefile
===================================================================
--- experimental/giles/rogg/Makefile 2007-12-31 02:22:21 UTC (rev 14336)
+++ experimental/giles/rogg/Makefile 2008-01-03 01:33:38 UTC (rev 14337)
@@ -7,7 +7,7 @@
OPTS = -g -O2 -Wall
-rogg_UTILS = rogg_pagedump rogg_eosfix rogg_aspect
+rogg_UTILS = rogg_pagedump rogg_eosfix rogg_aspect rogg_stats
all : librogg.a $(rogg_UTILS)
@@ -26,6 +26,9 @@
rogg_aspect : rogg_aspect.o librogg.a
$(CC) $(CFLAGS) -o $@ $^
+rogg_stats : rogg_stats.o librogg.a
+ $(CC) $(CFLAGS) -o $@ $^
+
check : all
clean :
Added: experimental/giles/rogg/rogg_stats.c
===================================================================
--- experimental/giles/rogg/rogg_stats.c (rev 0)
+++ experimental/giles/rogg/rogg_stats.c 2008-01-03 01:33:38 UTC (rev 14337)
@@ -0,0 +1,162 @@
+/*
+ Copyright (C) 2007 Xiph.org Foundation
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Ogg statistics reporter */
+
+/* compile with
+ gcc -O2 -g -Wall -I. -o rogg_stats rogg.c rogg_stats.c
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <rogg.h>
+
+int verbose = 0;
+
+void print_header_info(FILE *out, rogg_page_header *header)
+{
+ fprintf(out, " Ogg page serial %08x seq %d (%5d bytes)",
+ header->serialno, header->sequenceno, header->length);
+ fprintf(out, (header->continued) ? " c" : " ");
+ fprintf(out, " %lld", (long long int)header->granulepos);
+ fprintf(out, (header->bos) ? " bos" : "");
+ fprintf(out, (header->eos) ? " eos" : "");
+ fprintf(out, "\n");
+}
+
+void print_usage(FILE *out, char *name)
+{
+ fprintf(stderr, "Reporter for encapsulation overhead\n");
+ fprintf(stderr, "%s [-v] <file1.ogg> [<file2.ogg>...]\n",
+ name);
+ fprintf(stderr, " -v print more information\n");
+}
+
+int parse_args(int *argc, char *argv[])
+{
+ int arg = 1;
+ int shift;
+
+ while (arg < *argc) {
+ shift = 0;
+ if (argv[arg][0] == '-') {
+ switch (argv[arg][1]) {
+ case 'v':
+ verbose = 1;
+ shift = 1;
+ break;
+ }
+ }
+ if (shift) {
+ memmove(&argv[arg],&argv[arg+shift],shift*sizeof(*argv));
+ *argc -= shift;
+ } else {
+ arg++;
+ }
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int f, i;
+ unsigned char *p, *q, *o, *e;
+ struct stat s;
+ rogg_page_header header;
+ long hbytes = 0;
+ long dbytes = 0;
+
+ parse_args(&argc, argv);
+ if (argc < 2) {
+ print_usage(stderr, argv[0]);
+ exit(1);
+ }
+
+ for (i = 1; i < argc; i++) {
+ f = open(argv[i], O_RDWR);
+ if (f < 0) {
+ fprintf(stderr, "couldn't open '%s'\n", argv[i]);
+ continue;
+ }
+ if (fstat(f, &s) < 0) {
+ fprintf(stderr, "couldn't stat '%s'\n", argv[i]);
+ close(f);
+ continue;
+ }
+ p = mmap(0, s.st_size, PROT_READ|PROT_WRITE,
+ MAP_SHARED, f, 0);
+ if (p == NULL) {
+ fprintf(stderr, "couldn't mmap '%s'\n", argv[i]);
+ close(f);
+ continue;
+ }
+ fprintf(stdout, "Checking Ogg file '%s'\n", argv[i]);
+ e = p + s.st_size; /* pointer to the end of the file */
+ q = rogg_scan(p, s.st_size); /* scan for an Ogg page */
+ if (q == NULL) {
+ fprintf(stdout, "couldn't find ogg data!\n");
+ } else {
+ if (q > p) {
+ fprintf(stdout, "Skipped %d garbage bytes at the start\n", (int)(q-p));
+ }
+ while (q < e) {
+ o = rogg_scan(q, e-q); /* find the next Ogg page */
+ if (o > q) {
+ fprintf(stdout, "Hole in data! skipped %d bytes\n", (int)(o-q));
+ q = o;
+ } else if (o == NULL) {
+ fprintf(stdout, "Skipped %d garbage bytes as the end\n", (int)(e-q));
+ break;
+ }
+ rogg_page_parse(q, &header);
+ hbytes += 27 + header.segments;
+ dbytes += header.length;
+ if (verbose) {
+ print_header_info(stdout, &header);
+ fprintf(stdout, "\n");
+ }
+ q += header.length;
+ }
+ }
+ munmap(p, s.st_size);
+ close(f);
+ }
+ fprintf(stdout, "total overhead: %ld/%ld bytes (%02.3lf%%)\n",
+ hbytes, dbytes, 100.0*hbytes/dbytes);
+ return 0;
+}
+
More information about the commits
mailing list