[xiph-commits] r3192 - oogg/trunk

shans at svn.annodex.net shans at svn.annodex.net
Wed Aug 15 17:23:37 PDT 2007


Author: shans
Date: 2007-08-15 17:23:37 -0700 (Wed, 15 Aug 2007)
New Revision: 3192

Modified:
   oogg/trunk/granules.ml
   oogg/trunk/packet.ml
Log:
Forward generation of gp and timing on packets (still some problems)
Per-stream packet continuations handled correctly



Modified: oogg/trunk/granules.ml
===================================================================
--- oogg/trunk/granules.ml	2007-08-15 05:57:29 UTC (rev 3191)
+++ oogg/trunk/granules.ml	2007-08-16 00:23:37 UTC (rev 3192)
@@ -58,18 +58,25 @@
   | Theora -> theora_time bos
   | _      -> fun x -> None
 
+let vorbis_sizes bos =
+  let bos_packet = List.hd bos.raw_data in
+  let long_size = 1 lsl ((extract_int8 bos_packet 28) lsr 4) in
+  let short_size = 1 lsl ((extract_int8 bos_packet 28) land 0xF) in
+  (long_size, short_size);;
+
+let vorbis_length packet long short = 
+  if ((extract_int8 packet 0) lsr 1) land 1 = 1
+  then long
+  else short;;
+
 (* there are pretty much always 2 modes, with size bits of 0 and 1 respectively.
    for now we'll assume that is *always* the case. *)
 let vorbis_last_gp bos prevpack thispack thisgp = 
-  let bos_packet = List.hd bos.raw_data in
-  let long_size = 1 lsl ((extract_int8 bos_packet 28) lsr 4) in
-  let short_size = 1 lsl ((extract_int8 bos_packet 28) land 0xF) in
+  let (long_size, short_size) = vorbis_sizes bos in
   if thisgp = Some (0,0,0,0) then Some (0,0,0,0) else
   (
-    let len p = if ((extract_int8 p 0) lsr 1) land 1 = 1
-                then long_size else short_size in
-    let thislen = len thispack in
-    let lastlen = len prevpack in
+    let thislen = vorbis_length thispack long_size short_size in
+    let lastlen = vorbis_length prevpack long_size short_size in
     match thisgp with
       | None -> None
       | Some gp -> 
@@ -77,15 +84,24 @@
                     (Int64.of_int ((thislen + lastlen) / 4))))
   );;
 
-let theora_last_gp = vorbis_last_gp;;
+let theora_last_gp _ _ _ _ = None;;
 
 let last_gp_function id bos = match id with
   | Vorbis -> vorbis_last_gp bos
   | Theora -> theora_last_gp bos
   | _      -> fun _ _ _ -> None
 
-let vorbis_next_gp bos prevpack thispack (Some (a,b,c,d)) = (Some (a,b,c,d+1));;
-let theora_next_gp = vorbis_last_gp;;
+let vorbis_next_gp bos prevpack thispack lastgp =
+  let (long_size, short_size) = vorbis_sizes bos in
+  let prevlen = vorbis_length prevpack long_size short_size in
+  let thislen = vorbis_length thispack long_size short_size in
+  match lastgp with
+    | None    -> None
+    | Some gp ->
+              Some (int64_to_oogg64 (Int64.add (oogg64_to_int64 gp)
+                  (Int64.of_int ((thislen + prevlen) / 4))));;
+ 
+let theora_next_gp _ _ _ _ = None;;
 
 let next_gp_function id bos = match id with
   | Vorbis -> vorbis_next_gp bos

Modified: oogg/trunk/packet.ml
===================================================================
--- oogg/trunk/packet.ml	2007-08-15 05:57:29 UTC (rev 3191)
+++ oogg/trunk/packet.ml	2007-08-16 00:23:37 UTC (rev 3192)
@@ -8,17 +8,23 @@
     p_page = page
   };;
 
+type ptp_context = {mutable cont_packet : string option};;
+
 let page_to_packets cont page =
+  let sn = page.raw.serialno in
+  if page.raw.bos then
+    cont := (sn, {cont_packet = None})::!cont;
   let rec _ptp raw_data = 
-    let oc = !cont in 
-    cont := None; 
+    let pcont = List.assoc sn !cont in
+    let oc = pcont.cont_packet in 
+    pcont.cont_packet <- None; 
     match raw_data with
       | h::[l] when not page.raw.last_packet_complete -> 
-          (cont := Some l; [< 'new_packet oc page h true >])
+          (pcont.cont_packet <- Some l; [< 'new_packet oc page h true >])
       | [h] when not page.raw.last_packet_complete ->
           ((match oc with 
-            | None -> cont := Some h 
-            | Some d -> cont := Some (h ^ d));
+            | None -> pcont.cont_packet <- Some h 
+            | Some d -> pcont.cont_packet <- Some (h ^ d));
             [< >]
           )
       | h::[] when page.raw.last_packet_complete -> 
@@ -28,7 +34,7 @@
   _ptp page.raw.raw_data;;
 
 let to_packetStream pstream =
-  let cont = ref None in
+  let cont = ref [] in
   let rec _tps pstream = match pstream with parser
     | [< 'page ; rest >] -> [< page_to_packets cont page ; _tps rest >]
     | [< >] -> [< >] in 



More information about the commits mailing list