pion / webrtc

Pure Go implementation of the WebRTC API
https://pion.ly
MIT License
13.84k stars 1.66k forks source link

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

Open cozzl opened 2 months ago

cozzl commented 2 months ago

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)
    }
}
Sean-Der commented 1 month ago

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 :)