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

Update inconsistent header size calculation #2662

Closed
wants to merge 7 commits into from

Conversation

aaron-jencks
Copy link
Contributor

Updated inconsistent header size calculation

Not sure why the 16 SRT header bytes aren't included here, but if they really shouldn't be included in the calculation, then an explanation as to why should be included in the document as currently it is unclear and directly contradicts the use of the number 44 in lines 63-66.

Updated inconsistent header size calculation
@aaron-jencks aaron-jencks changed the title Update configuration-guidelines.md Update inconsistent header size calculation Feb 13, 2023
@ethouris
Copy link
Collaborator

The constant you have changed here refers to the UDP header size and was never intended for anything else.

@ethouris ethouris closed this Feb 13, 2023
@aaron-jencks
Copy link
Contributor Author

aaron-jencks commented Feb 13, 2023

Did you add documentation explicitly stating why it's using only the UDP header and not including the SRT header?? If not, then why did you close this??

It seems like you didn't even read what I put in the description of the PR before closing it...

@ethouris ethouris reopened this Feb 14, 2023
@ethouris
Copy link
Collaborator

Ok, I admit the initial view of the changes has tricked me. Still, if this is saying it's UDP header, then it includes only IPv4 and UDP header, so I think it should be fixed a little bit differently.

@ethouris
Copy link
Collaborator

Ah, line 92/95 should get a similar fix. I could not propose it unfortunately because git doesn't allow to do this in a "non-changed" area.

@maxsharabayko
Copy link
Collaborator

maxsharabayko commented Feb 14, 2023

Hi @aaron-jencks
Thank you for the PR!
I have to say the RCV buffer configuration is quite confusing. I already don't remember all the details exactly.

// Maximum SRT payload size. m_config.iMSS = SRTO_MSS.
m_iMaxSRTPayloadSize = m_config.iMSS - CPacket::UDP_HDR_SIZE - CPacket::HDR_SIZE;

// The RCV queue is initialized with s->core().maxPayloadSize() = m_iMaxSRTPayloadSize .
// Internally a CUnit structure is created with CPacket holding SRT header + SRT payload.
m.m_pRcvQueue->init(128, s->core().maxPayloadSize(), m.m_iIPversion, 1024, m.m_pChannel, m.m_pTimer);
m_pUnitQueue = new CUnitQueue(qsize, (int)payload = s->core().maxPayloadSize());

The RCV buffer then stores CUnits. But the number of CUnits to store is calculated without SRT header.
The function getRbufSizePkts(..) from the configuration guidelines corresponds to the conversion when setting the SRTO_RCVBUF value. So it is not the actual size, but the number of packets SRT will allocate for the provided SRTO_RCVBUF value.

@ethouris
Copy link
Collaborator

ethouris commented Feb 14, 2023

Ok, let me be clear on one thing: The MSS (that is, size of the MTU) is only symbolically used to comply with the system value of MTU, but this value as such is not used in any internally defined size, only in intermediate calculations.

The total number of bytes for the sender and receiver buffer is the number of bytes that the application is going to use. So as per a single packet treated as MTU: it does include the payload part AND the SRT header, but NOT the IPv4+UDP header. The actualy size, however, depends on the MSS value.

This means that: bytes per packet = MSS - UDP_HEADER; default: 1500 - 28. And this is for IPv4 only, of course. This part of the code defines in short how the receiver buffer size in packets is defined:

        const int mssin_size = co.iMSS - CPacket::UDP_HDR_SIZE;

        if (val > mssin_size * co.DEF_MIN_FLIGHT_PKT)
            co.iRcvBufSize = val / mssin_size;
        else
            co.iRcvBufSize = co.DEF_MIN_FLIGHT_PKT;

Or, in short: the size of the buffers is not the number of bytes allowed to carry out the user's payload, but the size of the memory - additionally aligned to mutliplicity of the UDP payload size - that the application will allocate for the buffer.

aaron-jencks and others added 4 commits February 14, 2023 08:09
@aaron-jencks
Copy link
Contributor Author

Ah, line 92/95 should get a similar fix. I could not propose it unfortunately because git doesn't allow to do this in a "non-changed" area.

I think I've remedied this, take a look

@aaron-jencks
Copy link
Contributor Author

Okay, I think I've fixed everything, it should be ready for review again

@ethouris
Copy link
Collaborator

@maxsharabayko please review if this fix is ok because I personally have doubt. Not sure what this whole document is all about, so once again:

  1. From the perspective of the total buffer capacity for the payload to be transferred in time, for which you want to estimate how long piece of the live stream it can keep at the current bitrate: you should define this "time translated to buffer size" as the payload fragment - if you don't want to use the standard 1316 bytes for MPEG-TS, use maximum 1456 for IPv4 and 1444 for IPv6 per every packet. Note that this alone has nothing to do with the used memory, as this refers to the part of the packet's memory that will be in use.
  2. From the perspective of the memory size to be allocated, which is simultaneously the value that you should pass to set the SRTO_RCVBUF and SRTO_SNDBUF options, use the value of the "UDP payload" per packet, which is 1472 for IPv4 and 1460 for IPv6 - that is, the SRT header for this calculation is NOT INCLUDED.

@maxsharabayko
Copy link
Collaborator

The document advises how to calculate a value to be set in SRTO_RCVBUF.
Please see my motivation why the existing version is correct. I belive the SRT header should not be subtracted.

@aaron-jencks
Copy link
Contributor Author

I don't actually know what the correct thing is here, but when I read the documentation, it was unclear if UDPHDR_SIZE was supposed to be 28, or 44 and the reasoning for the difference between the two wasn't well defined. I'm sure what you guys have isn't wrong, it's just unclear

@ethouris
Copy link
Collaborator

Ok, I was also a bit confused. I submitted a fix for the description - this should look clearer now. If you have any further suggestions you're welcome to add them there.

@maxsharabayko maxsharabayko added this to the v1.5.2 milestone Feb 16, 2023
@maxsharabayko maxsharabayko added Type: Maintenance Work required to maintain or clean up the code [docs] Area: Improvements or additions to documentation labels Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[docs] Area: Improvements or additions to documentation Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants