mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 02:34:26 +08:00
确保start_send_rtp相关c api线程安全,同时新增多个接口支持指定配置参数 (#3838)
修复被动tcp发送rtp问题 修改默认tcp send 5s超时设置 增加start_send更多参数配
This commit is contained in:
parent
bd40c24745
commit
c409fc5754
@ -162,6 +162,8 @@ typedef void(API_CALL *on_mk_media_source_send_rtp_result)(void *user_data, uint
|
||||
// MediaSource::startSendRtp,请参考mk_media_start_send_rtp,注意ctx参数类型不一样
|
||||
API_EXPORT void API_CALL mk_media_source_start_send_rtp(const mk_media_source ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, on_mk_media_source_send_rtp_result cb, void *user_data);
|
||||
API_EXPORT void API_CALL mk_media_source_start_send_rtp2(const mk_media_source ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, on_mk_media_source_send_rtp_result cb, void *user_data, on_user_data_free user_data_free);
|
||||
API_EXPORT void API_CALL mk_media_source_start_send_rtp3(const mk_media_source ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_source_send_rtp_result cb, void *user_data);
|
||||
API_EXPORT void API_CALL mk_media_source_start_send_rtp4(const mk_media_source ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_source_send_rtp_result cb,void *user_data, on_user_data_free user_data_free);
|
||||
//MediaSource::stopSendRtp,请参考mk_media_stop_send_rtp,注意ctx参数类型不一样
|
||||
API_EXPORT int API_CALL mk_media_source_stop_send_rtp(const mk_media_source ctx);
|
||||
|
||||
|
@ -270,12 +270,14 @@ typedef on_mk_media_source_send_rtp_result on_mk_media_send_rtp_result;
|
||||
* @param dst_port 目标端口
|
||||
* @param ssrc rtp的ssrc,10进制的字符串打印
|
||||
* @param con_type 0: tcp主动,1:udp主动,2:tcp被动,3:udp被动
|
||||
* @param options 选项
|
||||
* @param cb 启动成功或失败回调
|
||||
* @param user_data 回调用户指针
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, on_mk_media_send_rtp_result cb, void *user_data);
|
||||
API_EXPORT void API_CALL mk_media_start_send_rtp2(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, on_mk_media_send_rtp_result cb, void *user_data, on_user_data_free user_data_free);
|
||||
|
||||
API_EXPORT void API_CALL mk_media_start_send_rtp3(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_send_rtp_result cb, void *user_data);
|
||||
API_EXPORT void API_CALL mk_media_start_send_rtp4(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_send_rtp_result cb, void *user_data,on_user_data_free user_data_free);
|
||||
/**
|
||||
* 停止某路或全部ps-rtp发送,此api线程安全
|
||||
* @param ctx 对象指针
|
||||
|
@ -307,13 +307,53 @@ API_EXPORT void API_CALL mk_media_source_start_send_rtp2(const mk_media_source c
|
||||
args.dst_url = dst_url;
|
||||
args.dst_port = dst_port;
|
||||
args.ssrc = ssrc;
|
||||
args.close_delay_ms = 30 * 1000;
|
||||
args.con_type = (mediakit::MediaSourceEvent::SendRtpArgs::ConType)con_type;
|
||||
|
||||
std::shared_ptr<void> ptr(user_data, user_data_free ? user_data_free : [](void *) {});
|
||||
src->startSendRtp(args, [cb, ptr](uint16_t local_port, const SockException &ex){
|
||||
if (cb) {
|
||||
cb(ptr.get(), local_port, ex.getErrCode(), ex.what());
|
||||
}
|
||||
src->getOwnerPoller()->async([=]() mutable {
|
||||
src->startSendRtp(args, [cb, ptr](uint16_t local_port, const SockException &ex) {
|
||||
if (cb) {
|
||||
cb(ptr.get(), local_port, ex.getErrCode(), ex.what());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_media_source_start_send_rtp3(const mk_media_source ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_source_send_rtp_result cb,void *user_data) {
|
||||
mk_media_source_start_send_rtp4(ctx, dst_url, dst_port, ssrc, con_type, options, cb, user_data, nullptr);
|
||||
}
|
||||
API_EXPORT void API_CALL mk_media_source_start_send_rtp4(const mk_media_source ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_source_send_rtp_result cb,void *user_data, on_user_data_free user_data_free) {
|
||||
assert(ctx && dst_url && ssrc);
|
||||
MediaSource *src = (MediaSource *)ctx;
|
||||
|
||||
MediaSourceEvent::SendRtpArgs args;
|
||||
args.dst_url = dst_url;
|
||||
args.dst_port = dst_port;
|
||||
args.ssrc = ssrc;
|
||||
args.con_type = (mediakit::MediaSourceEvent::SendRtpArgs::ConType)con_type;
|
||||
auto ini_ptr = (mINI *)options;
|
||||
args.src_port = (*ini_ptr)["src_port"].empty() ? 0 : (*ini_ptr)["src_port"].as<int>();
|
||||
args.ssrc_multi_send = (*ini_ptr)["ssrc_multi_send"].empty() ? false : (*ini_ptr)["ssrc_multi_send"].as<bool>();
|
||||
args.pt = (*ini_ptr)["pt"].empty() ? 96 : (*ini_ptr)["pt"].as<int>();
|
||||
args.data_type = (*ini_ptr)["data_type"].empty() ? MediaSourceEvent::SendRtpArgs::DataType::kRtpPS:(MediaSourceEvent::SendRtpArgs::DataType)(*ini_ptr)["data_type"].as<int>();
|
||||
args.only_audio = (*ini_ptr)["only_audio"].empty() ? false : (*ini_ptr)["only_audio"].as<bool>();
|
||||
args.udp_rtcp_timeout = (*ini_ptr)["udp_rtcp_timeout"].empty() ? false : (*ini_ptr)["udp_rtcp_timeout"].as<bool>();
|
||||
args.recv_stream_id = (*ini_ptr)["recv_stream_id"];
|
||||
args.recv_stream_app = src->getMediaTuple().app.c_str();
|
||||
args.recv_stream_vhost = src->getMediaTuple().vhost.c_str();
|
||||
args.close_delay_ms = (*ini_ptr)["close_delay_ms"].empty() ? 0 : (*ini_ptr)["close_delay_ms"].as<int>();
|
||||
args.rtcp_timeout_ms = (*ini_ptr)["rtcp_timeout_ms"].empty() ? 30000 : (*ini_ptr)["rtcp_timeout_ms"].as<int>();
|
||||
args.rtcp_send_interval_ms = (*ini_ptr)["rtcp_send_interval_ms"].empty() ? 5000 : (*ini_ptr)["rtcp_send_interval_ms"].as<int>();
|
||||
std::shared_ptr<void> ptr(
|
||||
user_data, user_data_free ? user_data_free : [](void *) {});
|
||||
src->getOwnerPoller()->async([=]() mutable {
|
||||
src->startSendRtp(args, [cb, ptr](uint16_t local_port, const SockException &ex) {
|
||||
if (cb) {
|
||||
cb(ptr.get(), local_port, ex.getErrCode(), ex.what());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -294,6 +294,7 @@ API_EXPORT void API_CALL mk_media_start_send_rtp2(mk_media ctx, const char *dst_
|
||||
args.dst_url = dst_url;
|
||||
args.dst_port = dst_port;
|
||||
args.ssrc = ssrc;
|
||||
args.close_delay_ms = 30 * 1000;
|
||||
args.con_type = (mediakit::MediaSourceEvent::SendRtpArgs::ConType)con_type;
|
||||
|
||||
// sender参数无用
|
||||
@ -308,6 +309,45 @@ API_EXPORT void API_CALL mk_media_start_send_rtp2(mk_media ctx, const char *dst_
|
||||
});
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_media_start_send_rtp3(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_send_rtp_result cb, void *user_data) {
|
||||
mk_media_start_send_rtp4(ctx, dst_url, dst_port, ssrc, con_type,options, cb, user_data, nullptr);
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_media_start_send_rtp4(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int con_type, mk_ini options, on_mk_media_send_rtp_result cb, void *user_data,on_user_data_free user_data_free) {
|
||||
assert(ctx && dst_url && ssrc);
|
||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *)ctx;
|
||||
MediaSourceEvent::SendRtpArgs args;
|
||||
args.dst_url = dst_url;
|
||||
args.dst_port = dst_port;
|
||||
args.ssrc = ssrc;
|
||||
args.con_type = (mediakit::MediaSourceEvent::SendRtpArgs::ConType)con_type;
|
||||
auto ini_ptr = (mINI *)options;
|
||||
args.src_port = (*ini_ptr)["src_port"].empty() ? 0 : (*ini_ptr)["src_port"].as<int>();
|
||||
args.ssrc_multi_send = (*ini_ptr)["ssrc_multi_send"].empty() ? false : (*ini_ptr)["ssrc_multi_send"].as<bool>();
|
||||
args.pt = (*ini_ptr)["pt"].empty() ? 96 : (*ini_ptr)["pt"].as<int>();
|
||||
args.data_type = (*ini_ptr)["data_type"].empty() ? MediaSourceEvent::SendRtpArgs::DataType::kRtpPS
|
||||
: (MediaSourceEvent::SendRtpArgs::DataType)(*ini_ptr)["data_type"].as<int>();
|
||||
args.only_audio = (*ini_ptr)["only_audio"].empty() ? false : (*ini_ptr)["only_audio"].as<bool>();
|
||||
args.udp_rtcp_timeout = (*ini_ptr)["udp_rtcp_timeout"].empty() ? false : (*ini_ptr)["udp_rtcp_timeout"].as<bool>();
|
||||
args.recv_stream_id =(*ini_ptr)["recv_stream_id"];
|
||||
args.recv_stream_app =obj->get()->getChannel()->getMediaTuple().app.c_str();
|
||||
args.recv_stream_vhost = obj->get()->getChannel()->getMediaTuple().vhost.c_str();
|
||||
args.close_delay_ms = (*ini_ptr)["close_delay_ms"].empty() ? 30000 : (*ini_ptr)["close_delay_ms"].as<int>();
|
||||
args.rtcp_timeout_ms = (*ini_ptr)["rtcp_timeout_ms"].empty() ? 30000 : (*ini_ptr)["rtcp_timeout_ms"].as<int>();
|
||||
args.rtcp_send_interval_ms = (*ini_ptr)["rtcp_send_interval_ms"].empty() ? 5000 : (*ini_ptr)["rtcp_send_interval_ms"].as<int>();
|
||||
// sender参数无用
|
||||
auto ref = *obj;
|
||||
std::shared_ptr<void> ptr(
|
||||
user_data, user_data_free ? user_data_free : [](void *) {});
|
||||
(*obj)->getChannel()->getOwnerPoller(MediaSource::NullMediaSource())->async([args, ref, cb, ptr]() {
|
||||
ref->getChannel()->startSendRtp(MediaSource::NullMediaSource(), args, [cb, ptr](uint16_t local_port, const SockException &ex) {
|
||||
if (cb) {
|
||||
cb(ptr.get(), local_port, ex.getErrCode(), ex.what());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_media_stop_send_rtp(mk_media ctx, const char *ssrc) {
|
||||
assert(ctx);
|
||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *)ctx;
|
||||
|
Loading…
Reference in New Issue
Block a user