修复RtpProcess析构导致的线程问题

This commit is contained in:
ziyue 2022-11-01 16:05:23 +08:00
parent f5a032c9a0
commit bfe118d94e
3 changed files with 17 additions and 2 deletions

View File

@ -49,10 +49,13 @@ RtpProcess::RtpProcess(const string &stream_id) {
}
}
RtpProcess::~RtpProcess() {
void RtpProcess::flush() {
if (_process) {
_process->flush();
}
}
RtpProcess::~RtpProcess() {
uint64_t duration = (_last_frame_time.createdTime() - _last_frame_time.elapsedTime()) / 1000;
WarnP(this) << "RTP推流器("
<< _media_info.shortUrl()

View File

@ -18,7 +18,7 @@
namespace mediakit {
class RtpProcess : public RtcpContextForRecv, public toolkit::SockInfo, public MediaSinkInterface, public MediaSourceEventInterceptor, public std::enable_shared_from_this<RtpProcess>{
class RtpProcess final : public RtcpContextForRecv, public toolkit::SockInfo, public MediaSinkInterface, public MediaSourceEventInterceptor, public std::enable_shared_from_this<RtpProcess>{
public:
typedef std::shared_ptr<RtpProcess> Ptr;
friend class RtpProcessHelper;
@ -57,6 +57,11 @@ public:
*/
void setStopCheckRtp(bool is_check=false);
/**
* flush输出缓存
*/
void flush() override;
/// SockInfo override
std::string get_local_ip() override;
uint16_t get_local_port() override;

View File

@ -112,6 +112,13 @@ RtpProcessHelper::RtpProcessHelper(const string &stream_id, const weak_ptr<RtpSe
}
RtpProcessHelper::~RtpProcessHelper() {
auto process = std::move(_process);
try {
// flush时确保线程安全
process->getOwnerPoller(MediaSource::NullMediaSource())->async([process]() { process->flush(); });
} catch (...) {
// 忽略getOwnerPoller可能抛出的异常
}
}
void RtpProcessHelper::attachEvent() {