avoid returning partial RTP-Info header, omit seq/rtptime if needed #568
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A recent behavioral change introduced by PR #2244 has inadvertently caused a bug affecting the initialization timing of the RTSP server, which now waits until the first playback connection attempt. This change has resulted in playback failures in some video players due to the timing of the server's start-up sequence. The root of the issue lies in the
OnSetup
handler in server_session.go, which activates the RTSP server processor found in stream.go.The server's setup process allows
gortsplib
to asynchronously process packets and extract stream data such as video and audio tracks. However, the immediate return ofOnSetup
means that thegenerateRTPInfo
function might try to construct anRTP-Info
header before all tracks have been detected bygortsplib
, leading to incomplete or incorrect headers.Currently, the server prematurely constructs
RTP-Info
headers based on a list fromsetuppedMediasOrdered
. This results in headers that may lack complete track data ifgortsplib
has not yet processed all packets required to detect the tracks, as seen in the conditional check in server_stream.go.This PR resolves the issue by ensuring that even if the packet data for a track isn't fully available at the time of constructing the
RTP-Info
header, a partial but validRTP-Info
URL entry will still be included. This modification prevents the generation of headers that could cause strict RTSP implementations to fail during playback.Examples of RTP-Info Headers:
Valid header formats:
RTP-Info: url=rtsp://127.0.0.1:8554/foo/trackID=0;seq=55350;rtptime=712469876, url=rtsp://127.0.0.1:8554/foo/trackID=1;seq=17411;rtptime=3933183075
Invalid header formats (due to race condition, one of the tracks is missing):
RTP-Info
RTP-Info: url=rtsp://127.0.0.1:8554/foo/trackID=1;seq=17411;rtptime=3933183075
RTP-Info: url=rtsp://127.0.0.1:8554/foo/trackID=0;seq=55350;rtptime=712469876
Proposed fix example (for missing data cases):
RTP-Info: url=rtsp://127.0.0.1:8554/foo/trackID=0, url=rtsp://127.0.0.1:8554/foo/trackID=1;seq=17411;rtptime=3933183075
Summary of the Fix:
generateRTPInfo
to ensure each track at least has a valid URL entry in theRTP-Info
header, even if sequence and RTP time data are not yet available.