Changeset 3193

Show
Ignore:
Timestamp:
2007-08-15 21:31:14 (1 year ago)
Author:
shans
Message:

Theora forward and backward reconstruction of granulepos values

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • oogg/trunk/granules.ml

    r3192 r3193  
    3636    );; 
    3737 
     38let theora_shift bos =  
     39  let bos_packet = List.hd bos.raw_data in 
     40  ((extract_int8 bos_packet 40 land 0x03) lsl 3) 
     41  lor 
     42  ((extract_int8 bos_packet 41 land 0xe0) lsr 5);; 
     43 
     44let theora_gp_to_frames shift gpv = 
     45  let igp = oogg64_to_int64 gpv in 
     46  let keyframe = Int64.shift_right igp shift in 
     47  let offset = Int64.logand igp  
     48      (Int64.sub (Int64.shift_left Int64.one shift) Int64.one) in 
     49  (keyframe, offset) 
     50 
    3851let theora_time bos gp = match gp with 
    3952  | None -> None 
     
    4255    let num = extract_be_int32 bos_packet 22 in 
    4356    let denom = extract_be_int32 bos_packet 26 in 
    44     let shift =  
    45       ((extract_int8 bos_packet 40 land 0x03) lsl 3) 
    46       lor 
    47       ((extract_int8 bos_packet 41 land 0xe0) lsr 5) in 
    48     let igp = oogg64_to_int64 gp in 
    49     let keyframe = Int64.shift_right igp shift in 
    50     let offset = Int64.logand igp  
    51         (Int64.sub (Int64.shift_left Int64.one shift) Int64.one) in 
     57    let shift = theora_shift bos in 
     58    let (keyframe, offset) = theora_gp_to_frames shift gp in 
    5259    let gpv = Int64.to_float (Int64.add keyframe offset) in 
    5360    Some (granulerate_time denom num gpv) 
     
    8592  );; 
    8693 
    87 let theora_last_gp _ _ _ _ = None;; 
     94let theora_frames_to_gp shift keyframe frame =  
     95  int64_to_oogg64 (Int64.add (Int64.shift_left keyframe shift) frame);; 
     96 
     97(* assume that we only do negative generation at the beginning, and 
     98   that we never go over more than 1 keyframe.  At worst we just miss 
     99   out on a keyframe at the beginning 
     100 *) 
     101let theora_last_gp bos prevpack thispack thisgp =  
     102  match thisgp with 
     103    | None -> None 
     104    | Some gp -> ( 
     105      let shift = theora_shift bos in 
     106      let (keyframe, offset) = theora_gp_to_frames shift gp in 
     107      if offset = 0L 
     108      then Some (theora_frames_to_gp shift 0L (Int64.sub keyframe 1L)) 
     109      else Some (theora_frames_to_gp shift keyframe (Int64.sub offset 1L)));; 
    88110 
    89111let last_gp_function id bos = match id with 
     
    102124                  (Int64.of_int ((thislen + prevlen) / 4))));; 
    103125  
    104 let theora_next_gp _ _ _ _ = None;; 
     126let theora_next_gp bos prevpack thispack lastgp = 
     127  match lastgp with 
     128    | None -> None 
     129    | Some gp -> ( 
     130      let shift = theora_shift bos in 
     131      let (keyframe, offset) = theora_gp_to_frames shift gp in 
     132      let fb = extract_int8 thispack 0 in 
     133      if (fb land 0x80) = 0x80 (* header packet *) 
     134      then Some (0,0,0,0) 
     135      else ( 
     136        if (fb land 0x40) = 0x40 (* inter packet *) 
     137        then Some (theora_frames_to_gp shift keyframe (Int64.add offset 1L)) 
     138        else Some (theora_frames_to_gp shift  
     139            (Int64.add (Int64.add keyframe offset) 1L) 0L) 
     140      ));; 
    105141 
    106142let next_gp_function id bos = match id with