diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index 42b72814..63f2a93d 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -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); diff --git a/api/include/mk_media.h b/api/include/mk_media.h index 85327dbf..08c2318d 100755 --- a/api/include/mk_media.h +++ b/api/include/mk_media.h @@ -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 对象指针 diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 91ab640d..592133bb 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -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 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(); + args.ssrc_multi_send = (*ini_ptr)["ssrc_multi_send"].empty() ? false : (*ini_ptr)["ssrc_multi_send"].as(); + args.pt = (*ini_ptr)["pt"].empty() ? 96 : (*ini_ptr)["pt"].as(); + args.data_type = (*ini_ptr)["data_type"].empty() ? MediaSourceEvent::SendRtpArgs::DataType::kRtpPS:(MediaSourceEvent::SendRtpArgs::DataType)(*ini_ptr)["data_type"].as(); + args.only_audio = (*ini_ptr)["only_audio"].empty() ? false : (*ini_ptr)["only_audio"].as(); + args.udp_rtcp_timeout = (*ini_ptr)["udp_rtcp_timeout"].empty() ? false : (*ini_ptr)["udp_rtcp_timeout"].as(); + 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(); + args.rtcp_timeout_ms = (*ini_ptr)["rtcp_timeout_ms"].empty() ? 30000 : (*ini_ptr)["rtcp_timeout_ms"].as(); + args.rtcp_send_interval_ms = (*ini_ptr)["rtcp_send_interval_ms"].empty() ? 5000 : (*ini_ptr)["rtcp_send_interval_ms"].as(); + std::shared_ptr 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()); + } + }); }); } diff --git a/api/source/mk_media.cpp b/api/source/mk_media.cpp index df59aa0f..e3ec7e4b 100755 --- a/api/source/mk_media.cpp +++ b/api/source/mk_media.cpp @@ -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(); + args.ssrc_multi_send = (*ini_ptr)["ssrc_multi_send"].empty() ? false : (*ini_ptr)["ssrc_multi_send"].as(); + args.pt = (*ini_ptr)["pt"].empty() ? 96 : (*ini_ptr)["pt"].as(); + args.data_type = (*ini_ptr)["data_type"].empty() ? MediaSourceEvent::SendRtpArgs::DataType::kRtpPS + : (MediaSourceEvent::SendRtpArgs::DataType)(*ini_ptr)["data_type"].as(); + args.only_audio = (*ini_ptr)["only_audio"].empty() ? false : (*ini_ptr)["only_audio"].as(); + args.udp_rtcp_timeout = (*ini_ptr)["udp_rtcp_timeout"].empty() ? false : (*ini_ptr)["udp_rtcp_timeout"].as(); + 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(); + args.rtcp_timeout_ms = (*ini_ptr)["rtcp_timeout_ms"].empty() ? 30000 : (*ini_ptr)["rtcp_timeout_ms"].as(); + args.rtcp_send_interval_ms = (*ini_ptr)["rtcp_send_interval_ms"].empty() ? 5000 : (*ini_ptr)["rtcp_send_interval_ms"].as(); + // sender参数无用 + auto ref = *obj; + std::shared_ptr 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;