[xiph-commits] r3184 - oogg/trunk

shans at svn.annodex.net shans at svn.annodex.net
Mon Aug 13 01:01:47 PDT 2007


Author: shans
Date: 2007-08-13 01:01:47 -0700 (Mon, 13 Aug 2007)
New Revision: 3184

Modified:
   oogg/trunk/Makefile
   oogg/trunk/granules.ml
   oogg/trunk/mediaStream.ml
   oogg/trunk/page.ml
   oogg/trunk/page_util.ml
   oogg/trunk/types.ml
   oogg/trunk/types.mli
Log:
turned granulePos into an option type



Modified: oogg/trunk/Makefile
===================================================================
--- oogg/trunk/Makefile	2007-08-13 06:25:08 UTC (rev 3183)
+++ oogg/trunk/Makefile	2007-08-13 08:01:47 UTC (rev 3184)
@@ -1,6 +1,6 @@
 PROGRAMS = oogg_dump_pages oogg_copy_file oogg_rip oogg_check_checksums oogg_info
-LIBINCS = -I +camlp4 -I +extlib
-LIBS = camlp4.cmxa unix.cmxa extLib.cmxa oogg.cmxa 
+LIBINCS = -I +extlib
+LIBS = unix.cmxa extLib.cmxa oogg.cmxa 
 PROF = -p 
 
 all: $(PROGRAMS)

Modified: oogg/trunk/granules.ml
===================================================================
--- oogg/trunk/granules.ml	2007-08-13 06:25:08 UTC (rev 3183)
+++ oogg/trunk/granules.ml	2007-08-13 08:01:47 UTC (rev 3184)
@@ -27,23 +27,25 @@
 let granulerate_time num denom gp =
   Int64.to_float num *. gp /. Int64.to_float denom;;
 
-let vorbis_time bos gp =
-  let bos_packet = List.hd bos.raw_data in
-  let granule_rate = extract_le_int32 bos_packet 12 in
-  if gp = (0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF) then -1. else
-  granulerate_time 1L granule_rate (oogg64_to_float gp);;
+let vorbis_time bos gp = match gp with
+  | None -> -1.
+  | Some gp -> (
+    let bos_packet = List.hd bos.raw_data in
+    let granule_rate = extract_le_int32 bos_packet 12 in
+    granulerate_time 1L granule_rate (oogg64_to_float gp)
+    );;
 
-let theora_time bos gp =
-  let bos_packet = List.hd bos.raw_data in
-  let num = extract_be_int32 bos_packet 22 in
-  let denom = extract_be_int32 bos_packet 26 in
-  let shift = 
-    ((extract_int8 bos_packet 40 land 0x03) lsl 3)
-    lor
-    ((extract_int8 bos_packet 41 land 0xe0) lsr 5) in
-  let igp = oogg64_to_int64 gp in
-  if igp = -1L then -1.
-  else (
+let theora_time bos gp = match gp with
+  | None -> -1.
+  | Some gp -> (
+    let bos_packet = List.hd bos.raw_data in
+    let num = extract_be_int32 bos_packet 22 in
+    let denom = extract_be_int32 bos_packet 26 in
+    let shift = 
+      ((extract_int8 bos_packet 40 land 0x03) lsl 3)
+      lor
+      ((extract_int8 bos_packet 41 land 0xe0) lsr 5) in
+    let igp = oogg64_to_int64 gp in
     let keyframe = Int64.shift_right igp shift in
     let offset = Int64.logand igp 
         (Int64.sub (Int64.shift_left Int64.one shift) Int64.one) in

Modified: oogg/trunk/mediaStream.ml
===================================================================
--- oogg/trunk/mediaStream.ml	2007-08-13 06:25:08 UTC (rev 3183)
+++ oogg/trunk/mediaStream.ml	2007-08-13 08:01:47 UTC (rev 3184)
@@ -6,7 +6,7 @@
 (* internal type *)
 type _ooggMediaStream =
   { _stream_serialno : serialNo ;
-    mutable _stream_cache : option (rawPage list) ;
+    mutable _stream_cache : (rawPage list) option ;
     _stream_type : mediaType ;
     _stream_time : (granulePos -> float) option
   };;

Modified: oogg/trunk/page.ml
===================================================================
--- oogg/trunk/page.ml	2007-08-13 06:25:08 UTC (rev 3183)
+++ oogg/trunk/page.ml	2007-08-13 08:01:47 UTC (rev 3184)
@@ -144,11 +144,18 @@
 let write_oogg32 stream (a, b) =
     IO.write_ui16 stream b; IO.write_ui16 stream a;;
 
+let read_granulepos stream = 
+  let gp = read_oogg64 stream in 
+  if gp = (0xFFFF,0xFFFF,0xFFFF,0xFFFF) then None else Some gp;;
 
+let write_granulepos stream gp = match gp with 
+  | None -> write_oogg64 stream (0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF)
+  | Some gp -> write_oogg64 stream gp;;
+
 let page_to_raw stream page = 
   IO.nwrite stream "OggS"; IO.write_byte stream 0;
   IO.write_byte stream (make_header page);
-  write_oogg64 stream page.granulepos;
+  write_granulepos stream page.granulepos;
   write_oogg32 stream page.serialno;
   write_oogg32 stream page.sequenceno;
   write_oogg32 stream (make_checksum page);
@@ -164,7 +171,7 @@
       begin
         ignore (IO.read_byte stream);
         let header_type = IO.read_byte stream in
-        let granule_pos = read_oogg64 stream in
+        let granule_pos = read_granulepos stream in
         let serial_no = read_oogg32 stream in
         let seq_no = read_oogg32 stream in
         let checksum = read_oogg32 stream in

Modified: oogg/trunk/page_util.ml
===================================================================
--- oogg/trunk/page_util.ml	2007-08-13 06:25:08 UTC (rev 3183)
+++ oogg/trunk/page_util.ml	2007-08-13 08:01:47 UTC (rev 3184)
@@ -16,7 +16,7 @@
 let print_rawPage p =
   print_oogg32 p.serialno;
   print_string ": gp "; 
-  print_oogg64 p.granulepos;
+  print_granulepos p.granulepos;
   print_string " seq "; 
   print_oogg32 p.sequenceno; 
   if p.continued then print_string " (CONTINUATION)";

Modified: oogg/trunk/types.ml
===================================================================
--- oogg/trunk/types.ml	2007-08-13 06:25:08 UTC (rev 3183)
+++ oogg/trunk/types.ml	2007-08-13 08:01:47 UTC (rev 3184)
@@ -3,7 +3,7 @@
 type oogg32 = (int * int);;
 
 type serialNo = oogg32;;
-type granulePos = oogg64;;
+type granulePos = oogg64 option;;
 type checksum = oogg32;;
 type sequenceNo = oogg32;;
 
@@ -90,6 +90,10 @@
   else
     Printf.printf "%x" d;;
 
+let print_granulepos gp = match gp with
+  | None -> Printf.printf "None"
+  | Some gp -> print_oogg64 gp;;
+
 let print_mediaType t = print_string (match t with
   | Skeleton -> "Skeleton"
   | CMML     -> "CMML"

Modified: oogg/trunk/types.mli
===================================================================
--- oogg/trunk/types.mli	2007-08-13 06:25:08 UTC (rev 3183)
+++ oogg/trunk/types.mli	2007-08-13 08:01:47 UTC (rev 3184)
@@ -14,10 +14,12 @@
 
 (* meaningful values *)
 type serialNo = oogg32;;
-type granulePos = oogg64;;
+type granulePos = oogg64 option;;
 type checksum = oogg32;;
 type sequenceNo = oogg32;;
 
+val print_granulepos : granulePos -> unit;;
+
 (* raw byte streams *)
 type stream = IO.input;;
 type outStream = unit IO.output;;



More information about the commits mailing list