Changeset 7124

Show
Ignore:
Timestamp:
01/30/10 07:13:54 (7 months ago)
Author:
dbaelde
Message:

Fix two bugs in content layer management, one of which easily causes crashes when converting mono to stereo. The goal there is to never have two consecutive layers of the same type, and to avoid empty layers.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/liquidsoap/src/stream/frame.ml

    r7075 r7124  
    393393  * invalidation of all data after the given position. *) 
    394394let content_of_type frame pos content_type = 
    395   let rec aux acc = function 
     395  (* Start_pos indicates the start of the first layer, 
     396   * acc contains the previous layers in reverse order, 
     397   * and we're walking through the next layers. *) 
     398  let rec aux start_pos acc = function 
    396399    | [] -> assert false 
    397400    | (end_pos,content)::l -> 
    398         if end_pos<=pos then aux ((end_pos,content)::acc) l else 
     401        if end_pos<=pos then aux end_pos ((end_pos,content)::acc) l else 
     402          (* We are starting somewhere inside that layer. *) 
    399403          if content_has_type content content_type then begin 
    400404            if l=[] then assert (end_pos = !!size) else 
     
    402406            content 
    403407          end else begin 
    404             let acc = 
    405               if pos=0 then acc else (pos,content)::acc 
    406             in 
    407             let content = create_content content_type in 
    408               frame.contents <- List.rev ((!!size, content)::acc) ; 
    409               content 
     408            if pos=start_pos then 
     409              (* We are erasing the current layer. *) 
     410              match acc with 
     411                | (end_pos,content)::acc 
     412                  when content_has_type content content_type -> 
     413                    (* We must re-use the previous layer. *) 
     414                    frame.contents <- List.rev ((!!size, content)::acc) ; 
     415                    content 
     416                | _ -> 
     417                    let content = create_content content_type in 
     418                      frame.contents <- List.rev ((!!size, content)::acc) ; 
     419                      content 
     420            else 
     421              let acc = (pos,content)::acc in 
     422              let content = create_content content_type in 
     423                frame.contents <- List.rev ((!!size, content)::acc) ; 
     424                content 
    410425          end 
    411426  in 
    412     aux [] frame.contents 
     427    aux 0 [] frame.contents 
    413428 
    414429let blit_content src src_pos dst dst_pos len =