mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-12 19:24:22 +08:00
确保rtp推流线程安全性
This commit is contained in:
@@ -42,6 +42,8 @@ static bool loadFile(const char *path){
|
||||
addr.ss_family = AF_INET;
|
||||
auto sock = Socket::createSocket();
|
||||
size_t total_size = 0;
|
||||
RtpProcess::Ptr process;
|
||||
uint32_t ssrc = 0;
|
||||
while (true) {
|
||||
if (2 != fread(&len, 1, 2, fp)) {
|
||||
WarnL;
|
||||
@@ -58,9 +60,24 @@ static bool loadFile(const char *path){
|
||||
break;
|
||||
}
|
||||
total_size += len;
|
||||
uint64_t timeStamp;
|
||||
uint64_t timeStamp = 0;
|
||||
|
||||
if (!process) {
|
||||
if (!RtpSelector::getSSRC(rtp, len, ssrc)) {
|
||||
WarnL << "get ssrc from rtp failed:" << len;
|
||||
return false;
|
||||
}
|
||||
process = RtpSelector::Instance().getProcess(printSSRC(ssrc), true);
|
||||
}
|
||||
if (process) {
|
||||
try {
|
||||
process->inputRtp(true, sock, rtp, len, (struct sockaddr *)&addr, &timeStamp);
|
||||
} catch (...) {
|
||||
RtpSelector::Instance().delProcess(printSSRC(ssrc), process.get());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
RtpSelector::Instance().inputRtp(sock, rtp, len, (struct sockaddr *)&addr, &timeStamp);
|
||||
auto diff = timeStamp - timeStamp_last;
|
||||
if (diff > 0 && diff < 500) {
|
||||
usleep(diff * 1000);
|
||||
|
||||
Reference in New Issue
Block a user