sipsorcery-org / sipsorcery

A WebRTC, SIP and VoIP library for C# and .NET. Designed for real-time communications apps.
https://sipsorcery-org.github.io/sipsorcery
Other
1.44k stars 438 forks source link

Support for abs-send-time - closes #1081 #1084

Closed theimowski closed 6 months ago

theimowski commented 6 months ago

closes #1081

theimowski commented 6 months ago

Thanks! When can we expect a new NuGet version released?

ChristopheI commented 6 months ago

Thanks a lot for this PR. Could you please share an example to use it ? Thx

theimowski commented 6 months ago

The abs-send-time extension will apply itself as long as the receiver accepts it.

It will be added to every RTP packet that is send from SIPSorcery sender, in our example it happens when we send Video:

rtcPeerConnection.SendVideo(rtpDuration, sample)

It helps the receiver (in our case web browser) calculate REMB properly, and then on SIPSorcery sender side we can subscribe to REMB events:

  let onReceiveReport: Action<Net.IPEndPoint, SDPMediaTypesEnum, RTCPCompoundPacket> =
    Action<_, _, _>(fun _ _ packet ->
      if not (isNull packet.Feedback) && not (isNull packet.Feedback.Header) then
        let feedback = packet.Feedback
        let header = packet.Feedback.Header

        match header.PacketType, header.PayloadFeedbackMessageType with
        | RTCPReportTypesEnum.PSFB, PSFBFeedbackTypesEnum.AFB ->
          let exponent = feedback.BitrateExp
          let mantissa = feedback.BitrateMantissa
          // This is what REMB tells us the maximum bitrate should be
          let rembMaxBitrateInBitsPerSecond = pown 2u (int exponent) * mantissa
          onREMB.Trigger rembMaxBitrateInBitsPerSecond
        | RTCPReportTypesEnum.PSFB, PSFBFeedbackTypesEnum.PLI -> onPLI.Trigger()
        | _ -> ())

  ...

  rtcPeerConnection.add_OnReceiveReport onReceiveReport
ChristopheI commented 1 month ago

Hi @theimowski ,

Thanks to your PR, I'm trying to add support of multiple headers extensions For the moment I'm using my own repository to do it - check https://github.com/ChristopheI/sipsorcery/tree/master

Your own extension AbsSendTime should still works - Unfortunately I can't test it I added CVO (Coordination of Video Orientation) and when reading its header it's working well (using a remote peer on an Android device with a video)

I think the code is correct when reading headers with several extensions - (based on your previous code) If you can check on your side with AbsSendTime it will help a lot !

But I'm a little stuck when I need to write several headers ... Could you give me some hints ? How to manage several extensions with different length ( one vs two bytes) ? I need to check first all extensions and use always two bytes if at least one is using it ? How to use "HeaderExtensionFlag" in rtpPacket.Header ?

Thx