Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TWCC feedbacks #63

Merged
merged 22 commits into from
Feb 16, 2024
Merged

Add support for TWCC feedbacks #63

merged 22 commits into from
Feb 16, 2024

Conversation

LVala
Copy link
Member

@LVala LVala commented Jan 29, 2024

After this PR:

  • TWCC header extension will be added to sent packets
  • user will be able to receive RTCP TWCC feedbacks from the remote peer
  • our PeerConnection will send RTCP TWCC feedbacks based on received RTP packets and their TWCC header extensions

@LVala LVala self-assigned this Jan 29, 2024
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

Merging #63 (936f26f) into master (8bc7dd1) will decrease coverage by 0.13%.
Report is 1 commits behind head on master.
The diff coverage is 84.42%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #63      +/-   ##
==========================================
- Coverage   88.60%   88.47%   -0.13%     
==========================================
  Files          28       29       +1     
  Lines        1185     1302     +117     
==========================================
+ Hits         1050     1152     +102     
- Misses        135      150      +15     
Files Coverage Δ
lib/ex_webrtc/peer_connection/configuration.ex 88.13% <ø> (ø)
lib/ex_webrtc/peer_connection/twcc_recorder.ex 95.45% <95.45%> (ø)
lib/ex_webrtc/dtls_transport.ex 82.60% <0.00%> (-2.22%) ⬇️
lib/ex_webrtc/peer_connection.ex 87.25% <65.51%> (-0.96%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8bc7dd1...936f26f. Read the comment docs.

@LVala LVala mentioned this pull request Jan 31, 2024
54 tasks
@LVala LVala marked this pull request as ready for review February 1, 2024 10:14
@LVala LVala requested a review from mickel8 February 15, 2024 10:57
Copy link
Member

@mickel8 mickel8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Just one question regarding the unroll function and we should be ready to merge

with {:ok, %{id: id}} <-
Map.fetch(
state.config.video_rtp_hdr_exts,
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this into module attribute

notify(state.owner, {:rtcp, packets})

{:error, _res} ->
<<2::2, _::1, count::5, ptype::8, _::binary>> = data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we are sure, this will always match?

Copy link
Member Author

@LVala LVala Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I assume that SRTCP will only spit out valid RTCP packets, so I would assume that yes, but maybe it would be a great idea to place some safety measure there.

end
end

@spec get_feedback(t()) :: {t(), [CC.t()]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, return {[CC.t(), t()]}, that's how most modules in Elixir work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean {[CC.t()], t()} I guess?

Comment on lines 823 to 827
twcc_recorder = %TWCCRecorder{
twcc_recorder
| media_ssrc: packet.ssrc,
sender_ssrc: t.sender.ssrc
}
Copy link
Member

@mickel8 mickel8 Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will moving this into the with block still work? If yes, I think that would be more intuitive?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would, but why? I don't find that more intuitive at all. I can add the comment that we were talking about yesterday.

Comment on lines +121 to +133
defp unroll(seq_no, end_seq_no) do
end_rolled = end_seq_no &&& @max_seq_no
delta = seq_no - end_rolled

delta =
cond do
delta in -@breakpoint..@breakpoint -> delta
delta < -@breakpoint -> delta + @max_seq_no + 1
delta > @breakpoint -> delta - @max_seq_no - 1
end

end_seq_no + delta
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh, that's a piece of a real math. TBH, I am not going to dive into this except one question, will current implementation correctly handle receiving sequence numbers in the following order: 1, 65534?

Copy link
Member Author

@LVala LVala Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on what is the end_seq_no. If the packets with sequence numbers were received after they already wrapped (so packet with sn 1 was actually the 65_537th packet), then it will work like this:

Assuming that seq_no == 65_534 and end_seq_no == 65_557, delta will be equal to 65_534 - 1, so it will fall into third arm of the cond, so the delta will become
65_533 - 65_535 - 1 == -3, which implies that the packet with 65_534 is older than packet with 1, which is most likely the case, when packets like that are received consecutively (the 65_534 is from before sequence numbers wrapped). Btw, the test packets wrapping around sequence number boundary` checks something similar.

On the other hand, if packets with 1 and 65534 were the VERY first packets received (which is basically impossible and would surely imply some implementation errors on the sending side), it's something that our implementation might not handle, and the first feedback sent might be incorrect (which would make sense if the received sequence numbers are incorrect).

@LVala LVala requested a review from mickel8 February 16, 2024 10:22
@LVala LVala merged commit 22d21a5 into master Feb 16, 2024
4 checks passed
@LVala LVala deleted the twcc branch February 16, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants