Fixes for discharging preloaded content
Created by: robertbryer
This PR fixes two issues with using the preload()
function and discharging before it's filled up until buffer target:
- If a video element is attached while it's still pre-loading content, the fragments appended from the discharge() function in BufferController send bytes_appended events out. This causes the scheduling loop to be triggered a second time, meaning remaining fragments will be downloaded 2 at time until buffer target is reached. To fix it, the fragments discharged from the PreBufferSink are tracked in array
dischargeFragments
and bytes_appended events are not sent out for those fragments. - If an init segment is discharged it is appended to the SourceBuffer twice. The discharge function checks the InitCache when
chunk
is an init segment. It returns the exact same init segment asinitChunk
, and so it gets appended twice to the source buffer.
You can reproduce both of these by calling preload and attaching a video element quickly after, before you reach the buffer target.