[xiph-commits] r3238 - oogg/trunk
shans at svn.annodex.net
shans at svn.annodex.net
Wed Sep 12 16:38:27 PDT 2007
Author: shans
Date: 2007-09-12 16:38:26 -0700 (Wed, 12 Sep 2007)
New Revision: 3238
Modified:
oogg/trunk/packet.ml
Log:
Packet writeback code - possibly not working, but at least it compiles
Modified: oogg/trunk/packet.ml
===================================================================
--- oogg/trunk/packet.ml 2007-09-12 10:33:07 UTC (rev 3237)
+++ oogg/trunk/packet.ml 2007-09-12 23:38:26 UTC (rev 3238)
@@ -42,42 +42,81 @@
| [< 'page ; rest >] -> [< page_to_packets cont page ; _tps rest >]
| [< >] -> [< >] in
_tps pstream;;
-(*
+
let create_fresh_page packet =
let raw_page =
{
- continued = false;
- bos = packet.page.raw.bos;
- eos = packet.page.raw.eos;
- last_packet_complete = true;
- granulepos = packet.p_granulepos;
- serialno = packet.page.raw.serialno;
- sequenceno =
+ continued = packet.p_continued;
+ bos = packet.p_bos;
+ eos = packet.p_eos;
+ last_packet_complete = not packet.p_continues;
+ granulepos = if packet.p_continues
+ then None
+ else packet.p_granulepos;
+ serialno = packet.p_serialno;
+ sequenceno = packet.p_page_seq;
+ checksum = (0, 0);
+ packet_sizes = [String.length packet.p_data];
+ raw_data = [packet.p_data]
+ } in
+ let page =
+ {
+ raw = raw_page;
+ time = if packet.p_continues
+ then None
+ else packet.p_time;
+ identity = packet.p_identity
+ } in
+ page;;
+let add_packet_to_page page packet =
+ { page with
+ raw = { page.raw with
+ eos = packet.p_eos;
+ last_packet_complete = not packet.p_continues;
+ granulepos = if packet.p_continues
+ then None
+ else packet.p_granulepos;
+ packet_sizes = page.raw.packet_sizes @
+ [String.length packet.p_data];
+ raw_data = page.raw.raw_data @ [packet.p_data]
+ };
+ time = if packet.p_continues
+ then None
+ else packet.p_time
+ };;
+
+let flush_page page = [< 'page >];;
+
let packet_to_page context packet =
let _flush _ =
let old_page = !context in
let page = create_fresh_page packet in
context := Some page;
- [< flush_page old_page >] in
+ match old_page with
+ | Some op -> [< flush_page op >]
+ | None -> [< >] in
match !context with
| None ->
(
- let page = create_fresh_page packet true in
- context := Some page
+ let page = create_fresh_page packet in
+ context := Some page;
+ [< >]
)
| Some page ->
(
- if not (page.raw.serialno = packet.page.raw.serialno)
+ if not (page.raw.serialno = packet.p_serialno)
then [< _flush () >]
else (
- let size = page_size page in
- let new_size = size + (String.length (packet.p_data)) in
- let diff = abs (size - 4096) in
- let new_diff = abs (new_size - 4096) in
- if (diff > new_diff)
- then add_packet_to_page page packet
- else [< _flush () >]
+ if packet.p_page_seq = page.raw.sequenceno
+ then (
+ context := Some (add_packet_to_page page packet);
+ [< >]
+ )
+ else (
+ [< _flush () >];
+ )
+ )
);;
let packetStream_to_pageStream pstream =
@@ -85,10 +124,12 @@
let rec _ptp _ =
match pstream with parser
| [< 'packet >] -> [< packet_to_page context packet; _ptp () >]
- | [< >] -> [< flush_page !context >] in
+ | [< >] -> (match !context with
+ | Some lp -> [< flush_page lp >]
+ | None -> [< >]) in
_ptp ();;
-*)
+
type reconstruct_context = {
rc_tf : granulePos -> float option;
mutable rc_cache : packet list;
More information about the commits
mailing list