确保start_send_rtp相关c api线程安全,同时新增多个接口支持指定配置参数 (#3838)

修复被动tcp发送rtp问题 修改默认tcp send 5s超时设置 增加start_send更多参数配
This commit is contained in:
Lidaofu 2024-08-22 21:12:06 +08:00 committed by GitHub
parent bd40c24745
commit c409fc5754
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 89 additions and 5 deletions

View File

@ -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);

View File

@ -270,12 +270,14 @@ typedef on_mk_media_source_send_rtp_result on_mk_media_send_rtp_result;
* @param dst_port
* @param ssrc rtp的ssrc10
* @param con_type 0: tcp主动1udp主动2tcp被动3udp被动
* @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

View File

@ -307,14 +307,54 @@ 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->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());
}
});
});
}
API_EXPORT int API_CALL mk_media_source_stop_send_rtp(const mk_media_source ctx){

View File

@ -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;