[Live-devel] Regarding QoS and RTPTransmissionStat
MANDJUKOWSKI Esteban
Esteban.Mandjukowski at telecomnancy.eu
Fri Oct 23 02:41:30 PDT 2026
Hello again,
> For TCP streams, the source IP address is not obtained when the LIVE555 code receives data, because this is done using “recvfrom()”, which doesn’t fill in the “address” parameter if the socket is "connection-oriented”. (See “man recvfrom”)
Indeed, thanks for pointing this out.
Could the usage of "getpeername()" be a possibility to fill the gap here ? Since we have access to the TCP socket in the "RTPInterface::handleRead()" method, we should (from my understanding of "man getpeername"
and https://stackoverflow.com/questions/12873484/tcp-recvfrom-doesnt-store-from) be able to retrieve the correct IP address and port used by the remote client.
I actually applied this method in the library source code to try if it would even work.
In the "RTPInterface::handleRead()" method, I replaced :
Line 294 :
((sockaddr_in&)fromAddress).sin_addr.s_addr = 0;
((sockaddr_in&)fromAddress).sin_port = 0;
By :
socklen_t addrLen = sizeof(fromAddress);
if (getpeername(tcpSocketNum, (struct sockaddr*)&fromAddress, &addrLen) < 0) {
memset(&fromAddress, 0, sizeof(fromAddress));
fromAddress.ss_family = AF_INET;
}
This is the only change I have applied.
So far, the results look promising and I am indeed able to get the correct client IP address and port.
I also measured the performance hit of calling "getpeername()", and the results also look good : initial call (when the first client connects to the server) is around 4 microseconds (not on the biggest sample size I admit, I only tested it around 15 times)
and following calls hover around 1 or 2 microseconds. So I would say that the performance impact is in the negligible range.
Here is the code I used to measure the time :
socklen_t addrLen = sizeof(fromAddress);
_EventTime getpeernameStart = TimeNow();
if (getpeername(tcpSocketNum, (struct sockaddr*)&fromAddress, &addrLen)
< 0) {
memset(&fromAddress, 0, sizeof(fromAddress));
fromAddress.ss_family = AF_INET;
}
_EventTime getpeernameEnd = TimeNow();
long long elapsedUsecs =
((long long)getpeernameEnd.seconds() -
(long long)getpeernameStart.seconds()) * 1000000LL
+ (long long)getpeernameEnd.useconds()
- (long long)getpeernameStart.useconds();
printf("getpeername took %lld us\n", elapsedUsecs);
An issue I am not entirely sure about is that, since "RTPInterface::handleRead" is called by both "MultiFramedRTPSource" and "RTCPInstance", will this code also be ran on the client for no benefits ?
I feel like it would, because no difference is made between client and server in the "RTPInterface::handleRead" method, but I have not tested it.
Would you be willing to implement such changes in the source code ?
Subclassing seems out of reach because the fRTCPInterface member is not a pointer (in RTCP.hh, line 174), and the "RTPInterface::AuxHandlerFunc" type is lacking informations that we would use to retrieve the IP address and port.
Thanks for your answers and time,
MANDJUKOWSKI Esteban
More information about the live-devel
mailing list