修复调用mk_media_stop_send_rtp函数导致崩溃的bug

This commit is contained in:
ziyue 2021-06-16 10:14:24 +08:00
parent 4d0db1b7c1
commit a09de23271
3 changed files with 16 additions and 13 deletions

View File

@ -193,7 +193,7 @@ API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_u
assert(ctx && dst_url && ssrc); assert(ctx && dst_url && ssrc);
MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx;
//sender参数无用 //sender参数无用
(*obj)->getChannel()->startSendRtp(*(MediaSource *) 1, dst_url, dst_port, ssrc, is_udp, 0, [cb, user_data](uint16_t local_port, const SockException &ex){ (*obj)->getChannel()->startSendRtp(*MediaSource::NullMediaSource, dst_url, dst_port, ssrc, is_udp, 0, [cb, user_data](uint16_t local_port, const SockException &ex){
if (cb) { if (cb) {
cb(user_data, local_port, ex.getErrCode(), ex.what()); cb(user_data, local_port, ex.getErrCode(), ex.what());
} }
@ -204,5 +204,5 @@ API_EXPORT int API_CALL mk_media_stop_send_rtp(mk_media ctx){
assert(ctx); assert(ctx);
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
//sender参数无用 //sender参数无用
return (*obj)->getChannel()->stopSendRtp(*(MediaSource *) 1, ""); return (*obj)->getChannel()->stopSendRtp(*MediaSource::NullMediaSource, "");
} }

View File

@ -191,11 +191,12 @@ private:
*/ */
class MediaSource: public TrackSource, public enable_shared_from_this<MediaSource> { class MediaSource: public TrackSource, public enable_shared_from_this<MediaSource> {
public: public:
typedef std::shared_ptr<MediaSource> Ptr; static constexpr MediaSource *NullMediaSource = nullptr;
typedef unordered_map<string, weak_ptr<MediaSource> > StreamMap; using Ptr = std::shared_ptr<MediaSource>;
typedef unordered_map<string, StreamMap > AppStreamMap; using StreamMap = unordered_map<string, weak_ptr<MediaSource> >;
typedef unordered_map<string, AppStreamMap > VhostAppStreamMap; using AppStreamMap = unordered_map<string, StreamMap>;
typedef unordered_map<string, VhostAppStreamMap > SchemaVhostAppStreamMap; using VhostAppStreamMap = unordered_map<string, AppStreamMap>;
using SchemaVhostAppStreamMap = unordered_map<string, VhostAppStreamMap>;
MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id) ; MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id) ;
virtual ~MediaSource() ; virtual ~MediaSource() ;

View File

@ -338,7 +338,7 @@ bool MultiMediaSourceMuxer::isRecording(MediaSource &sender, Recorder::type type
return _muxer->isRecording(sender,type); return _muxer->isRecording(sender,type);
} }
void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb){ void MultiMediaSourceMuxer::startSendRtp(MediaSource &, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb){
#if defined(ENABLE_RTPPROXY) #if defined(ENABLE_RTPPROXY)
RtpSender::Ptr rtp_sender = std::make_shared<RtpSender>(atoi(ssrc.data())); RtpSender::Ptr rtp_sender = std::make_shared<RtpSender>(atoi(ssrc.data()));
weak_ptr<MultiMediaSourceMuxer> weak_self = shared_from_this(); weak_ptr<MultiMediaSourceMuxer> weak_self = shared_from_this();
@ -360,12 +360,14 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const string &dst_
#endif//ENABLE_RTPPROXY #endif//ENABLE_RTPPROXY
} }
bool MultiMediaSourceMuxer::stopSendRtp(MediaSource &sender, const string& ssrc){ bool MultiMediaSourceMuxer::stopSendRtp(MediaSource &sender, const string &ssrc) {
#if defined(ENABLE_RTPPROXY) #if defined(ENABLE_RTPPROXY)
onceToken token(nullptr, [&]() { if (&sender != MediaSource::NullMediaSource) {
//关闭rtp推流可能触发无人观看事件 onceToken token(nullptr, [&]() {
MediaSourceEventInterceptor::onReaderChanged(sender, totalReaderCount()); //关闭rtp推流可能触发无人观看事件
}); MediaSourceEventInterceptor::onReaderChanged(sender, totalReaderCount());
});
}
if (ssrc.empty()) { if (ssrc.empty()) {
//关闭全部 //关闭全部
lock_guard<mutex> lck(_rtp_sender_mtx); lock_guard<mutex> lck(_rtp_sender_mtx);