Skip to content

Add dedicated-thread method for video sending rate control to improve video latency#4332

Merged
nanangizz merged 1 commit intomasterfrom
vid-rc-thread
Mar 4, 2025
Merged

Add dedicated-thread method for video sending rate control to improve video latency#4332
nanangizz merged 1 commit intomasterfrom
vid-rc-thread

Conversation

@nanangizz
Copy link
Copy Markdown
Member

Currently, by default, video RTP sending rate control is using simple blocking method or PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING. This method seems to introduce significant latency compared to PJMEDIA_VID_STREAM_RC_NONE. So this PR implements an alternative method to avoid the latency impact while still applying the sending rate control by using a dedicated-thread for sending video RTP packets. Moreover, this alternative method will not block the stream's put_frame() invoker. Currently, each video stream will have a dedicated thread.

In #4325, we try to measure the delay between audio & video playbacks (audio is usually played first). When making video call to self using pjsua app, the delay with PJMEDIA_VID_STREAM_RC_NONE method is about 200-400ms while with PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING method is 500-1000ms. With PJMEDIA_VID_STREAM_RC_SEND_THREAD the delay seems to be similar to PJMEDIA_VID_STREAM_RC_NONE. So I think it is a good idea to make this the default rate control method.

Also in this PR, move the copying stream info to before media transport attach, as when testing this patch, I saw occasional crash in on_rx_rtp() due to accessing uninitialized stream info.

@nanangizz nanangizz merged commit 6dabbd5 into master Mar 4, 2025
42 checks passed
@nanangizz nanangizz deleted the vid-rc-thread branch March 4, 2025 07:39
nanangizz added a commit that referenced this pull request Mar 6, 2025
To fix & minor enhance #4332:
- Fix sending time calculation, the total sent should be updated in each queuing packet.
- Protect stream pool usage using group lock.
- Minor optimization: faster buffer reuse to avoid too many buffers, skip printing trace log for sending RTP when there is no packet to send.
nanangizz added a commit that referenced this pull request Mar 6, 2025
To fix & minor enhance #4332:
- Fix sending time calculation, the total sent should be updated in each queuing packet.
- Protect stream pool usage using group lock.
- Minor optimization: faster buffer reuse to avoid too many buffers, skip printing trace log for sending RTP when there is no packet to send.
BarryYin pushed a commit to BarryYin/pjproject that referenced this pull request Feb 3, 2026
BarryYin pushed a commit to BarryYin/pjproject that referenced this pull request Feb 3, 2026
To fix & minor enhance pjsip#4332:
- Fix sending time calculation, the total sent should be updated in each queuing packet.
- Protect stream pool usage using group lock.
- Minor optimization: faster buffer reuse to avoid too many buffers, skip printing trace log for sending RTP when there is no packet to send.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants