[xiph-commits] r3233 - oogg/trunk
shans at svn.annodex.net
shans at svn.annodex.net
Tue Sep 11 14:56:12 PDT 2007
Author: shans
Date: 2007-09-11 14:56:12 -0700 (Tue, 11 Sep 2007)
New Revision: 3233
Modified:
oogg/trunk/Makefile
oogg/trunk/granules.ml
oogg/trunk/granules.mli
oogg/trunk/packet.ml
oogg/trunk/packet.mli
oogg/trunk/packet_util.ml
oogg/trunk/page.ml
oogg/trunk/types.ml
oogg/trunk/types.mli
Log:
converted granule functions to work on bos packet instead of bos page
removed reference from packet to page and added additional serialno, continued/continues, page_sequenceno, identity, bos and eos fields to packets
split packet generation into raw generation and split packet repair functions
Modified: oogg/trunk/Makefile
===================================================================
--- oogg/trunk/Makefile 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/Makefile 2007-09-11 21:56:12 UTC (rev 3233)
@@ -1,5 +1,6 @@
PROGRAMS = oogg_dump_pages oogg_copy_file oogg_rip oogg_check_checksums \
- oogg_info oogg_dump_packets oogg_sort_stream
+ oogg_info oogg_dump_packets oogg_sort_stream \
+ oogg_dump_complete_packets
LIBINCS = -I +extlib
LIBS = unix.cmxa extLib.cmxa oogg.cmxa
PROF =
@@ -14,6 +15,10 @@
ocamlopt $(PROF) -o oogg_dump_packets $(LIBINCS) $(LIBS) \
oogg_dump_packets.ml
+oogg_dump_complete_packets: oogg.cmxa oogg_dump_complete_packets.ml
+ ocamlopt $(PROF) -o oogg_dump_complete_packets $(LIBINCS) $(LIBS) \
+ oogg_dump_complete_packets.ml
+
oogg_info: oogg.cmxa oogg_info.ml
ocamlopt $(PROF) -o oogg_info $(LIBINCS) $(LIBS) oogg_info.ml
Modified: oogg/trunk/granules.ml
===================================================================
--- oogg/trunk/granules.ml 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/granules.ml 2007-09-11 21:56:12 UTC (rev 3233)
@@ -27,16 +27,14 @@
let granulerate_time num denom gp =
Int64.to_float num *. gp /. Int64.to_float denom;;
-let vorbis_time bos gp = match gp with
+let vorbis_time bos_packet gp = match gp with
| None -> None
| Some gp -> (
- let bos_packet = List.hd bos.raw_data in
let granule_rate = extract_le_int32 bos_packet 12 in
Some (granulerate_time 1L granule_rate (oogg64_to_float gp))
);;
-let theora_shift bos =
- let bos_packet = List.hd bos.raw_data in
+let theora_shift bos_packet =
((extract_int8 bos_packet 40 land 0x03) lsl 3)
lor
((extract_int8 bos_packet 41 land 0xe0) lsr 5);;
@@ -48,13 +46,12 @@
(Int64.sub (Int64.shift_left Int64.one shift) Int64.one) in
(keyframe, offset)
-let theora_time bos gp = match gp with
+let theora_time bos_packet gp = match gp with
| None -> None
| 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 = theora_shift bos in
+ let shift = theora_shift bos_packet in
let (keyframe, offset) = theora_gp_to_frames shift gp in
let gpv = Int64.to_float (Int64.add keyframe offset) in
Some (granulerate_time denom num gpv)
@@ -65,8 +62,7 @@
| Theora -> theora_time bos
| _ -> fun x -> None
-let vorbis_sizes bos =
- let bos_packet = List.hd bos.raw_data in
+let vorbis_sizes bos_packet =
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);;
Modified: oogg/trunk/granules.mli
===================================================================
--- oogg/trunk/granules.mli 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/granules.mli 2007-09-11 21:56:12 UTC (rev 3233)
@@ -1,8 +1,8 @@
-val granulerate_function : Types.mediaType -> Types.rawPage ->
+val granulerate_function : Types.mediaType -> string ->
(Types.granulePos -> float option);;
-val last_gp_function : Types.mediaType -> Types.rawPage ->
+val last_gp_function : Types.mediaType -> string ->
string -> string -> Types.granulePos -> Types.granulePos;;
-val next_gp_function : Types.mediaType -> Types.rawPage ->
+val next_gp_function : Types.mediaType -> string ->
string -> string -> Types.granulePos -> Types.granulePos;;
Modified: oogg/trunk/packet.ml
===================================================================
--- oogg/trunk/packet.ml 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/packet.ml 2007-09-11 21:56:12 UTC (rev 3233)
@@ -1,36 +1,38 @@
open Types
-let new_packet oc page data n isLast =
+let new_packet page data n contd conts isLast =
{
- p_data = (match oc with None -> data | Some d -> d ^ data) ;
+ p_data = data ;
p_granulepos = if isLast then page.raw.granulepos else None ;
p_time = if isLast then page.time else None ;
- p_page = page ;
- p_pageno = n
+ p_pageno = n ;
+ p_serialno = page.raw.serialno ;
+ p_continued = contd ;
+ p_continues = conts ;
+ p_page_seq = page.raw.sequenceno ;
+ p_identity = page.identity ;
+ p_bos = page.raw.bos ;
+ p_eos = page.raw.eos
};;
-type ptp_context = {mutable cont_packet : string option};;
+type ptp_context = {mutable cont_packet : bool};;
+(* pcont indicates whether the previous packet is continued at this packet *)
let page_to_packets cont page =
let sn = page.raw.serialno in
if page.raw.bos then
- cont := (sn, {cont_packet = None})::!cont;
+ cont := (sn, {cont_packet = false})::!cont;
let rec _ptp raw_data n =
let pcont = List.assoc sn !cont in
let oc = pcont.cont_packet in
- pcont.cont_packet <- None;
+ pcont.cont_packet <- false;
match raw_data with
- | h::[l] when not page.raw.last_packet_complete ->
- (pcont.cont_packet <- Some l; [< 'new_packet oc page h n true >])
- | [h] when not page.raw.last_packet_complete ->
- ((match oc with
- | None -> pcont.cont_packet <- Some h
- | Some d -> pcont.cont_packet <- Some (h ^ d));
- [< >]
+ | [h] ->
+ (
+ pcont.cont_packet <- not page.raw.last_packet_complete;
+ [< 'new_packet page h n oc pcont.cont_packet true >]
)
- | h::[] when page.raw.last_packet_complete ->
- [< 'new_packet oc page h n true >]
- | h::t -> [< 'new_packet oc page h n false; _ptp t (n+1) >]
+ | h::t -> [< 'new_packet page h n oc false false; _ptp t (n+1) >]
| [] -> [< >] in
_ptp page.raw.raw_data 0;;
@@ -99,7 +101,9 @@
(* reconstruct packet given a previous gp. Don't store 0 GPs *)
let packet_from_last_gp crec pack =
let gp = crec.rc_last_gp in
- let new_gp = crec.rc_ngpf crec.rc_last_packet pack.p_data gp in
+ let new_gp = if pack.p_continued
+ then gp
+ else 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;
@@ -110,7 +114,7 @@
let new_gp_and_flush crec pack =
let rec _ngaf l p gp = match l with
| h::t -> (
- let last_gp = crec.rc_pgpf h.p_data p gp in
+ let last_gp = if pack.p_continues then gp else 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
@@ -122,21 +126,20 @@
[< _ngaf l pack.p_data pack.p_granulepos; 'pack >]
let reconstruct_packet context pack =
- let sn = pack.p_page.raw.serialno in
- let id = pack.p_page.identity in
- let rpage = pack.p_page.raw in
+ let sn = pack.p_serialno in
+ let id = pack.p_identity in
let gp = pack.p_granulepos in
let crec =
(
- if pack.p_page.raw.bos
+ if pack.p_bos
then (
context :=
- (sn, {rc_tf=Granules.granulerate_function id rpage;
+ (sn, {rc_tf=Granules.granulerate_function id pack.p_data;
rc_cache=[];
rc_last_gp=None;
rc_last_packet="";
- rc_pgpf=Granules.last_gp_function id rpage;
- rc_ngpf=Granules.next_gp_function id rpage})::
+ rc_pgpf=Granules.last_gp_function id pack.p_data;
+ rc_ngpf=Granules.next_gp_function id pack.p_data})::
(!context);
snd (List.hd !context))
else List.assoc sn !context
@@ -154,14 +157,51 @@
| [< >] -> [< >] in
_rt pstream;;
+type repair_context = {
+ mutable rc_packet : packet option
+};;
+
+let new_rc _ = {rc_packet = None}
+
+let repair_splits pstream =
+ let context = ref [] in
+ let rec _rs s = match s with parser
+ | [< 'pack ; rest >] ->
+ (
+ if pack.p_bos then context := (pack.p_serialno, new_rc ())::!context;
+ let crec = List.assoc pack.p_serialno !context in
+ if pack.p_continues
+ then
+ ( (
+ match crec.rc_packet with
+ | None -> crec.rc_packet <- Some pack
+ | Some p ->
+ crec.rc_packet <- Some {p with p_data = p.p_data ^ pack.p_data}
+ );
+ [< _rs rest >]
+ )
+ else
+ (
+ let op = crec.rc_packet in
+ crec.rc_packet <- None ;
+ match op with
+ | None -> [< 'pack ; _rs rest >]
+ | Some p ->
+ [< '{p with p_data = p.p_data ^ pack.p_data ;
+ p_continues = false ; p_continued = false } ; _rs rest >]
+ )
+ )
+ | [< >] -> [< >] in
+ _rs pstream;;
+
module PacketInput =
struct
type k = serialNo
type s = packet
let eq = (=)
- let get_key p = p.p_page.raw.serialno
- let is_first p = p.p_page.raw.bos
- let is_last p = p.p_page.raw.eos
+ let get_key p = p.p_serialno
+ let is_first p = p.p_bos
+ let is_last p = p.p_eos
let printKey s = print_oogg32 s
end;;
Modified: oogg/trunk/packet.mli
===================================================================
--- oogg/trunk/packet.mli 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/packet.mli 2007-09-11 21:56:12 UTC (rev 3233)
@@ -2,4 +2,6 @@
val reconstruct_timing : Types.packetStream -> Types.packetStream;;
+val repair_splits : Types.packetStream -> Types.packetStream;;
+
val sort : Types.packetStream -> (Types.serialNo * Types.packetStream) list;;
Modified: oogg/trunk/packet_util.ml
===================================================================
--- oogg/trunk/packet_util.ml 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/packet_util.ml 2007-09-11 21:56:12 UTC (rev 3233)
@@ -1,12 +1,16 @@
open Types
let print_packet p =
- print_mediaType p.p_page.identity;
+ print_mediaType p.p_identity;
Printf.printf " size %d gp " (String.length p.p_data);
print_granulepos p.p_granulepos;
+ if (p.p_continued) then Printf.printf " (CONTINUED)";
+ if (p.p_continues) then Printf.printf " (CONTINUES)";
Printf.printf " time ";
(match p.p_time with None -> Printf.printf "None" | Some f -> print_float f);
- Printf.printf "\n";;
+ Printf.printf " pageno " ;
+ print_oogg32 p.p_page_seq ;
+ Printf.printf " packetno %d\n" p.p_pageno ;;
let rec print_packetStream s = match s with parser
| [< 'p; rest >] -> (print_packet p; print_packetStream rest)
Modified: oogg/trunk/page.ml
===================================================================
--- oogg/trunk/page.ml 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/page.ml 2007-09-11 21:56:12 UTC (rev 3233)
@@ -200,8 +200,9 @@
let add_bos context rpage =
let sn = rpage.serialno in
let id = identify_bos rpage in
+ let bospack = List.hd rpage.raw_data in
context.ct_info <-
- (sn, (Granules.granulerate_function id rpage, id))::context.ct_info;
+ (sn, (Granules.granulerate_function id bospack, id))::context.ct_info;
id;;
let lookup_bos context rpage =
Modified: oogg/trunk/types.ml
===================================================================
--- oogg/trunk/types.ml 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/types.ml 2007-09-11 21:56:12 UTC (rev 3233)
@@ -105,8 +105,14 @@
{ p_data : string ;
mutable p_granulepos : granulePos ;
mutable p_time : float option ;
- p_page : page ;
- p_pageno : int
+ p_pageno : int ;
+ p_serialno : serialNo ;
+ p_continued : bool ;
+ p_continues : bool ;
+ p_page_seq : sequenceNo ;
+ p_identity : mediaType ;
+ p_bos : bool ;
+ p_eos : bool
};;
type packetStream = packet Stream.t;;
Modified: oogg/trunk/types.mli
===================================================================
--- oogg/trunk/types.mli 2007-09-11 06:42:58 UTC (rev 3232)
+++ oogg/trunk/types.mli 2007-09-11 21:56:12 UTC (rev 3233)
@@ -68,8 +68,14 @@
{ p_data : string ;
mutable p_granulepos : granulePos ;
mutable p_time : float option ;
- p_page : page ;
- p_pageno : int
+ p_pageno : int ;
+ p_serialno : serialNo ;
+ p_continued : bool ;
+ p_continues : bool ;
+ p_page_seq : sequenceNo ;
+ p_identity : mediaType ;
+ p_bos : bool ;
+ p_eos : bool
};;
type packetStream = packet Stream.t;;
More information about the commits
mailing list