当前位置:网站首页>Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
2022-07-05 08:00:00 【Drink more hot water-】
do RTSP server when , No matter what TCP/UDP, We all need to know streaming From which port , The binding of IP What's the address .
live555 There is a default to find the local network card IP Methods :
Get our address by sending a (0-TTL) multicast packet,
receiving it, and looking at the source address used.
(This is kinda bogus, but it provides the best guarantee
that other nodes will think our address is the same as we do.)
It's actually sending a TTL Package to local boardcast, Then resolve the return address of the Group , What you get is this machine IP.
however , One drawback of this is , It always returns the address of the default gateway , When we have multiple network cards , such as wlan0 wlan1 eth0 etc. ,
Suppose the default routing table points to wlan0, But we want to pass wlan1 Push flow , At this time, the mechanism will have problems .
So find this place directly , take IP Write the address as we want .
GroupsockHelper.cpp , You can start from 10.254.1.0 Push the stream
netAddressBits ourIPAddress(UsageEnvironment& env) {
static netAddressBits ourAddress = 0;
int sock = -1;
struct in_addr testAddr;
if (ReceivingInterfaceAddr != INADDR_ANY) {
// Hack: If we were told to receive on a specific interface address, then
// define this to be our ip address:
ourAddress = ReceivingInterfaceAddr;
}
if (ourAddress == 0) {
// We need to find our source address
struct sockaddr_in fromAddr;
fromAddr.sin_addr.s_addr = 0;
// Get our address by sending a (0-TTL) multicast packet,
// receiving it, and looking at the source address used.
// (This is kinda bogus, but it provides the best guarantee
// that other nodes will think our address is the same as we do.)
do {
loopbackWorks = 0; // until we learn otherwise
testAddr.s_addr = our_inet_addr("228.67.43.91"); // arbitrary
Port testPort(15947); // ditto
sock = setupDatagramSocket(env, testPort);
if (sock < 0) break;
if (!socketJoinGroup(env, sock, testAddr.s_addr)) break;
unsigned char testString[] = "hostIdTest";
unsigned testStringLength = sizeof testString;
if (!writeSocket(env, sock, testAddr, testPort.num(), 0,
testString, testStringLength)) break;
// Block until the socket is readable (with a 5-second timeout):
fd_set rd_set;
FD_ZERO(&rd_set);
FD_SET((unsigned)sock, &rd_set);
const unsigned numFds = sock+1;
struct timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
int result = select(numFds, &rd_set, NULL, NULL, &timeout);
if (result <= 0) break;
unsigned char readBuffer[20];
int bytesRead = readSocket(env, sock,
readBuffer, sizeof readBuffer,
fromAddr);
if (bytesRead != (int)testStringLength
|| strncmp((char*)readBuffer, (char*)testString, testStringLength) != 0) {
break;
}
// We use this packet's source address, if it's good:
// loopbackWorks = !badAddressForUs(fromAddr.sin_addr.s_addr);
loopbackWorks = !badAddressForUs(our_inet_addr("10.254.1.0"));// gw
} while (0);
if (sock >= 0) {
socketLeaveGroup(env, sock, testAddr.s_addr);
closeSocket(sock);
}
if (!loopbackWorks) do {
// We couldn't find our address using multicast loopback,
// so try instead to look it up directly - by first getting our host name, and then resolving this host name
char hostname[100];
hostname[0] = '\0';
int result = gethostname(hostname, sizeof hostname);
if (result != 0 || hostname[0] == '\0') {
env.setResultErrMsg("initial gethostname() failed");
break;
}
// Try to resolve "hostname" to an IP address:
NetAddressList addresses(hostname);
NetAddressList::Iterator iter(addresses);
NetAddress const* address;
// Take the first address that's not bad:
netAddressBits addr = 0;
while ((address = iter.nextAddress()) != NULL) {
netAddressBits a = *(netAddressBits*)(address->data());
if (!badAddressForUs(a)) {
addr = a;
break;
}
}
// Assign the address that we found to "fromAddr" (as if the 'loopback' method had worked), to simplify the code below:
fromAddr.sin_addr.s_addr = addr;
} while (0);
// Make sure we have a good address:
// netAddressBits from = fromAddr.sin_addr.s_addr;
netAddressBits from = (our_inet_addr("169.254.1.0"));
if (badAddressForUs(from)) {
char tmp[100];
sprintf(tmp, "This computer has an invalid IP address: %s", AddressString(from).val());
env.setResultMsg(tmp);
from = 0;
}
ourAddress = from;
// Use our newly-discovered IP address, and the current time,
// to initialize the random number generator's seed:
struct timeval timeNow;
gettimeofday(&timeNow, NULL);
unsigned seed = ourAddress^timeNow.tv_sec^timeNow.tv_usec;
our_srandom(seed);
}
return ourAddress;
}
边栏推荐
- Hardware 1 -- relationship between gain and magnification
- 1089 Insert or Merge 含测试点5
- Explain STM32 startup file in detail
- C language uses arrays to realize the intersection, union, difference and complement of sets
- Distinction between heap and stack
- Temperature sensor DS18B20 principle, with STM32 routine code
- Cadence simulation encountered "input.scs": can not open input file change path problem
- TCP and UDP
- Markdown tips
- Process communication mode between different hosts -- socket
猜你喜欢
![Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev](/img/42/d857452ccfeccbbf1ac34f47e47e2e.jpg)
Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev

Application of ultra pure water particle counter in electronic semiconductors

UEFI development learning 3 - create UEFI program

Scm-05 basis of independent keyboard

Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
![C WinForm [help interface - send email] - practice five](/img/2a/c4e7abe054e6fdd45acc7d297a033d.jpg)
C WinForm [help interface - send email] - practice five

Development tools -- gcc compiler usage

Process communication mode between different hosts -- socket
![Halcon's practice based on shape template matching [1]](/img/68/206eed7502fbf108a929aa9365b1ae.jpg)
Halcon's practice based on shape template matching [1]

mysql 盲注常见函数
随机推荐
如何进行导电滑环选型
RTOS in the development of STM32 single chip microcomputer
Global and Chinese markets for anesthesia, breathing and sleep apnea devices 2022-2028: Research Report on technology, participants, trends, market size and share
Interview catalogue
Record the visual shock of the Winter Olympics and the introduction of the screen 2
A simple method to prove 1/t Fourier transform
万字详解八大排序 必读(代码+动图演示)
Reasons for rapid wear of conductive slip rings
Extended application of single chip microcomputer-06 independent key
MySQL - storage engine
Detailed explanation of C language pointer
Cadence simulation encountered "input.scs": can not open input file change path problem
Global and Chinese markets of large aperture scintillators 2022-2028: Research Report on technology, participants, trends, market size and share
Record the opening ceremony of Beijing Winter Olympics with display equipment
About the problem that MySQL connector net cannot be cleared in MySQL
MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
IEEE access personal contribution experience record
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
How to define guid in AMI code
C WinForm [exit application] - practice 3