webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

examples/bandwidth-estimation-from-disk currentTimestamp not updated correctly

Open cozzl opened this issue 1 year ago • 1 comments

In the examples/bandwidth-estimation-from-disk/main.go file, the currentTimestamp variable is intended to track the current video frame's timestamp to ensure correct playback when switching video quality levels. However, currentTimestamp is not being updated correctly and remains at its initial value.

Update currentTimestamp after each video frame is read and sent. Here is the code snippet:

    // ... 
for ; true; <-ticker.C {
    targetBitrate := estimator.GetTargetBitrate()
    switch {

    // ... 

    default:
        frame, frameHeader, err = ivf.ParseNextFrame() // modify this section
    }

    switch {
    // If we have reached the end of the file, start again
    case errors.Is(err, io.EOF):
        ivf.ResetReader(setReaderFile(qualityLevels[currentQuality].fileName))

    // No error, write the video frame
    case err == nil:
        currentTimestamp = frameHeader.Timestamp // Update currentTimestamp
        if err = videoTrack.WriteSample(media.Sample{Data: frame, Duration: time.Second}); err != nil {
            panic(err)
        }
    // Handle other unknown errors
    default:
        panic(err)
    }
}

cozzl avatar Sep 02 '24 13:09 cozzl

Hi @cozzl

Would you be able to make a PR? If you aren't able I am happy to land this code for you!

I would prefer you get credit though :)

Sean-Der avatar Oct 07 '24 16:10 Sean-Der