[xiph-commits] r3189 - oogg/trunk

shans at svn.annodex.net shans at svn.annodex.net
Tue Aug 14 00:40:28 PDT 2007


Author: shans
Date: 2007-08-14 00:40:27 -0700 (Tue, 14 Aug 2007)
New Revision: 3189

Modified:
   oogg/trunk/packet.ml
Log:
Correct packet continuation handling



Modified: oogg/trunk/packet.ml
===================================================================
--- oogg/trunk/packet.ml	2007-08-14 05:41:01 UTC (rev 3188)
+++ oogg/trunk/packet.ml	2007-08-14 07:40:27 UTC (rev 3189)
@@ -1,25 +1,38 @@
 open Types
 
-let new_packet page data isLast =
+let new_packet oc page data isLast =
   {
-    p_data = data ;
+    p_data = (match oc with None -> data | Some d -> d ^ data) ;
     p_granulepos = if isLast then page.raw.granulepos else None ;
     p_time = if isLast then page.time else None ;
     p_page = page
   };;
 
-let page_to_packets page =
-  let rec _ptp raw_data = match raw_data with
-  | h::[l] when page.raw.continued -> 
-        [< 'new_packet page h true; 'new_packet page l false >]
-  | h::[] when not page.raw.continued -> [< 'new_packet page h true >]
-  | h::t  -> [< 'new_packet page h false; _ptp t >]
-  | []    -> [< >] in
+let page_to_packets cont page =
+  let rec _ptp raw_data = 
+    let oc = !cont in 
+    cont := None; 
+    match raw_data with
+      | h::[l] when not page.raw.last_packet_complete -> 
+          (cont := 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));
+            [< >]
+          )
+      | h::[] when page.raw.last_packet_complete -> 
+          [< 'new_packet oc page h true >]
+      | h::t  -> [< 'new_packet oc page h false; _ptp t >]
+      | []    -> [< >] in
   _ptp page.raw.raw_data;;
 
-let rec to_packetStream pstream = match pstream with parser
-  | [< 'page ; rest >] -> [< page_to_packets page ; to_packetStream rest >]
-  | [< >] -> [< >];;
+let to_packetStream pstream =
+  let cont = ref None in
+  let rec _tps pstream = match pstream with parser
+    | [< 'page ; rest >] -> [< page_to_packets cont page ; _tps rest >]
+    | [< >] -> [< >] in 
+  _tps pstream;;
 
 type reconstruct_context = {
   rc_tf : granulePos -> float option;



More information about the commits mailing list