[xiph-commits] r3191 - oogg/trunk
shans at svn.annodex.net
shans at svn.annodex.net
Tue Aug 14 22:57:29 PDT 2007
Author: shans
Date: 2007-08-14 22:57:29 -0700 (Tue, 14 Aug 2007)
New Revision: 3191
Modified:
oogg/trunk/granules.ml
oogg/trunk/granules.mli
oogg/trunk/packet.ml
Log:
past packet gp reconstruction for Vorbis
Modified: oogg/trunk/granules.ml
===================================================================
--- oogg/trunk/granules.ml 2007-08-14 23:37:24 UTC (rev 3190)
+++ oogg/trunk/granules.ml 2007-08-15 05:57:29 UTC (rev 3191)
@@ -58,5 +58,37 @@
| Theora -> theora_time bos
| _ -> fun x -> None
-let calculate_next_gp id (Some (a,b,c,d)) = Some (a,b,c,d+1)
-let calculate_last_gp id (Some (a,b,c,d)) = Some (a,b,c,d-1)
+(* 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
+ 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
+ match thisgp with
+ | None -> None
+ | Some gp ->
+ Some (int64_to_oogg64 (Int64.sub (oogg64_to_int64 gp)
+ (Int64.of_int ((thislen + lastlen) / 4))))
+ );;
+
+let theora_last_gp = vorbis_last_gp;;
+
+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 next_gp_function id bos = match id with
+ | Vorbis -> vorbis_next_gp bos
+ | Theora -> theora_next_gp bos
+ | _ -> fun _ _ _ -> None
+
Modified: oogg/trunk/granules.mli
===================================================================
--- oogg/trunk/granules.mli 2007-08-14 23:37:24 UTC (rev 3190)
+++ oogg/trunk/granules.mli 2007-08-15 05:57:29 UTC (rev 3191)
@@ -1,7 +1,8 @@
val granulerate_function : Types.mediaType -> Types.rawPage ->
(Types.granulePos -> float option);;
-val calculate_next_gp : Types.mediaType -> Types.granulePos ->
- Types.granulePos;;
-val calculate_last_gp : Types.mediaType -> Types.granulePos ->
- Types.granulePos;;
+val last_gp_function : Types.mediaType -> Types.rawPage ->
+ string -> string -> Types.granulePos -> Types.granulePos;;
+
+val next_gp_function : Types.mediaType -> Types.rawPage ->
+ string -> string -> Types.granulePos -> Types.granulePos;;
Modified: oogg/trunk/packet.ml
===================================================================
--- oogg/trunk/packet.ml 2007-08-14 23:37:24 UTC (rev 3190)
+++ oogg/trunk/packet.ml 2007-08-15 05:57:29 UTC (rev 3191)
@@ -37,30 +37,36 @@
type reconstruct_context = {
rc_tf : granulePos -> float option;
mutable rc_cache : packet list;
- mutable rc_lgp : granulePos
- (*rc_ngpf : string -> string -> granulePos -> granulePos;*)
+ mutable rc_last_gp : granulePos;
+ mutable rc_last_packet : string;
+ rc_ngpf : string -> string -> granulePos -> granulePos;
+ rc_pgpf : string -> string -> granulePos -> granulePos
} ;;
-(* reconstruct packet given a previous gp *)
+(* reconstruct packet given a previous gp. Don't store 0 GPs *)
let packet_from_last_gp crec pack =
- let gp = crec.rc_lgp in
- let new_gp = Granules.calculate_next_gp pack.p_page.identity gp in
- crec.rc_lgp <- new_gp;
+ let gp = crec.rc_last_gp in
+ let new_gp = crec.rc_ngpf crec.rc_last_packet pack.p_data gp in
+ if not (new_gp = Some (0,0,0,0))
+ then crec.rc_last_gp <- new_gp;
+ crec.rc_last_packet <- pack.p_data;
[< '{ pack with p_granulepos = new_gp; p_time = crec.rc_tf new_gp } >]
(* flush the non-timestamped packets from the context record now that we
have a real granulepos *)
let new_gp_and_flush crec pack =
- let rec _ngaf l gp = match l with
+ let rec _ngaf l p gp = match l with
| h::t -> (
- let last_gp = Granules.calculate_last_gp pack.p_page.identity gp in
- [< _ngaf t last_gp;
+ let last_gp = crec.rc_pgpf h.p_data p gp in
+ [< _ngaf t h.p_data last_gp;
'{ h with p_granulepos = last_gp; p_time = crec.rc_tf last_gp } >])
| [] -> [< >] in
let l = crec.rc_cache in
crec.rc_cache <- [];
- crec.rc_lgp <- pack.p_granulepos;
- [< _ngaf l pack.p_granulepos; 'pack >]
+ if not (pack.p_granulepos = Some (0,0,0,0))
+ then crec.rc_last_gp <- pack.p_granulepos;
+ crec.rc_last_packet <- pack.p_data;
+ [< _ngaf l pack.p_data pack.p_granulepos; 'pack >]
let reconstruct_packet context pack =
let sn = pack.p_page.raw.serialno in
@@ -74,13 +80,16 @@
context :=
(sn, {rc_tf=Granules.granulerate_function id rpage;
rc_cache=[];
- rc_lgp=None})::
+ rc_last_gp=None;
+ rc_last_packet="";
+ rc_pgpf=Granules.last_gp_function id rpage;
+ rc_ngpf=Granules.next_gp_function id rpage})::
(!context);
snd (List.hd !context))
else List.assoc sn !context
) in
match gp with
- | None -> (match crec.rc_lgp with
+ | None -> (match crec.rc_last_gp with
| None -> (crec.rc_cache <- pack::crec.rc_cache; [< >])
| Some _ -> packet_from_last_gp crec pack)
| Some gp -> [< new_gp_and_flush crec pack >];;
More information about the commits
mailing list