[xiph-commits] r9429 - experimental/giles/rogg
giles at motherfish-iii.xiph.org
giles at motherfish-iii.xiph.org
Fri Jun 10 01:32:19 PDT 2005
Author: giles
Date: 2005-06-10 01:32:06 -0700 (Fri, 10 Jun 2005)
New Revision: 9429
Modified:
experimental/giles/rogg/rogg.c
experimental/giles/rogg/rogg.h
experimental/giles/rogg/rogg_pagedump.c
Log:
Implement a capture pattern scan and use it to skip garbage data.
Modified: experimental/giles/rogg/rogg.c
===================================================================
--- experimental/giles/rogg/rogg.c 2005-06-10 06:09:05 UTC (rev 9428)
+++ experimental/giles/rogg/rogg.c 2005-06-10 08:32:06 UTC (rev 9429)
@@ -109,6 +109,21 @@
}
}
+/* scan for the capture pattern */
+unsigned char *rogg_scan(unsigned char *p, int len)
+{
+ unsigned char *end = p + len - 4;
+
+ while (p < end) {
+ if (*p == 'O') {
+ if ((p[1] == 'g') && (p[2] == 'g') && (p[3] == 'S')) return p;
+ }
+ p++;
+ }
+
+ return NULL;
+}
+
/* parse out the header fields of the page starting at p */
void rogg_parse_header(unsigned char *p, rogg_page_header *header)
{
Modified: experimental/giles/rogg/rogg.h
===================================================================
--- experimental/giles/rogg/rogg.h 2005-06-10 06:09:05 UTC (rev 9428)
+++ experimental/giles/rogg/rogg.h 2005-06-10 08:32:06 UTC (rev 9429)
@@ -71,6 +71,9 @@
void rogg_read_uint32(unsigned char *p, uint32_t *v);
void rogg_read_uint16(unsigned char *p, uint16_t *v);
+/* scan for the 'OggS' capture pattern */
+unsigned char *rogg_scan(unsigned char *p, int len);
+
/* calculate the length of the page starting at p */
void rogg_get_length(unsigned char *p, int *length);
Modified: experimental/giles/rogg/rogg_pagedump.c
===================================================================
--- experimental/giles/rogg/rogg_pagedump.c 2005-06-10 06:09:05 UTC (rev 9428)
+++ experimental/giles/rogg/rogg_pagedump.c 2005-06-10 08:32:06 UTC (rev 9429)
@@ -27,8 +27,13 @@
/* simple script example for the rogg library */
+/* compile with
+ gcc -O2 -g -Wall -I. -o rogg_pagedump rogg.c rogg_pagedump.c
+*/
+
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <stdint.h>
#include <sys/types.h>
@@ -53,7 +58,7 @@
int main(int argc, char *argv[])
{
int f, i;
- unsigned char *p, *q, *e;
+ unsigned char *p, *q, *o, *e;
struct stat s;
rogg_page_header header;
@@ -77,11 +82,26 @@
}
fprintf(stdout, "Dumping Ogg file '%s'\n", argv[i]);
e = p + s.st_size;
- q = p;
- while (q < e) {
+ q = rogg_scan(p, s.st_size);
+ if (q == NULL) {
+ fprintf(stdout, "couldn't find ogg data!\n");
+ } else {
+ if (q > p) {
+ fprintf(stdout, "skipping %d garbage bytes at the start\n", q-p);
+ }
+ while (q < e) {
+ o = rogg_scan(q, e-q);
+ if (o > q) {
+ fprintf(stdout, "Hole in data! skipped %d bytes\n", o - q);
+ q = o;
+ } else if (o == NULL) {
+ fprintf(stdout, "Skipped %d garbage bytes as the end\n", e-q);
+ break;
+ }
rogg_parse_header(q, &header);
print_header_info(stdout, &header);
q += header.length;
+ }
}
munmap(p, s.st_size);
close(f);
More information about the commits
mailing list