Commit bfe118d9 by ziyue

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

parent f5a032c9
......@@ -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()
......
......@@ -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;
......
......@@ -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() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论