Skip to content
  • Vincent Penquerc'h's avatar
    flacdec: avoid timestamp/offset tracking going out of sync · 3e0134f5
    Vincent Penquerc'h authored
    The libFLAC API is callback based, and we must only call it to
    output data when we know we have enough input data. For this
    reason, a single processing step is done when receiving a buffer.
    However, if there were metadata buffers still pending, a step
    intended for the first audio frame might end up writing that
    leftover metadata. Since a single step is done per buffer, this
    will cause every buffer to be written one step late.
    
    This would add some latency (a bufferfull's worth), possibly
    lose a buffer when seeking or the like, and also cause timestamp
    and offset to be applied to the wrong buffer, as updates to
    the "current" segment last_stop (from incoming buffer timestamp)
    will be applied to an output buffer originating from the previous
    incoming buffer.
    
    This fixes the issue by ensuring that, upon receiving the first
    audio frame, processing is done till all metadata is processed,
    so the next "single step" done will be for the audio frame. After
    this, we should keep to 1 input buffer -> 1 output buffer and so
    avoid getting out of sync.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=650960
    3e0134f5