From f05422bb659d7f2e33b6d999edfb509ae1092cd2 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 21 Nov 2020 22:13:08 +0800 Subject: [PATCH] =?UTF-8?q?c=20api=E6=94=AF=E6=8C=81=E5=9B=BD=E6=A0=87?= =?UTF-8?q?=E6=8E=A8=E6=B5=81:#578?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_events_objects.h | 10 ++++++++++ api/include/mk_media.h | 24 ++++++++++++++++++++++++ api/source/mk_events_objects.cpp | 16 ++++++++++++++++ api/source/mk_media.cpp | 18 ++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index 2aba7ada..b4eb0998 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -115,6 +115,16 @@ API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int forc //MediaSource::seekTo() API_EXPORT int API_CALL mk_media_source_seek_to(const mk_media_source ctx,uint32_t stamp); +/** + * rtp推流成功与否的回调(第一次成功后,后面将一直重试) + */ +typedef void(API_CALL *on_mk_media_source_send_rtp_result)(void *user_data, int err, const char *msg); + +//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 is_udp, on_mk_media_source_send_rtp_result cb, void *user_data); +//MediaSource::stopSendRtp,请参考mk_media_stop_send_rtp,注意ctx参数类型不一样 +API_EXPORT int API_CALL mk_media_source_stop_send_rtp(const mk_media_source ctx); + //MediaSource::find() API_EXPORT void API_CALL mk_media_source_find(const char *schema, const char *vhost, diff --git a/api/include/mk_media.h b/api/include/mk_media.h index d41f3dc7..7fcdf1c9 100755 --- a/api/include/mk_media.h +++ b/api/include/mk_media.h @@ -173,6 +173,30 @@ typedef void(API_CALL *on_mk_media_source_regist)(void *user_data, mk_media_sour */ API_EXPORT void API_CALL mk_media_set_on_regist(mk_media ctx, on_mk_media_source_regist cb, void *user_data); +/** + * rtp推流成功与否的回调(第一次成功后,后面将一直重试) + */ +typedef on_mk_media_source_send_rtp_result on_mk_media_send_rtp_result; + +/** + * 开始发送ps-rtp流 + * @param ctx 对象指针 + * @param dst_url 目标ip或域名 + * @param dst_port 目标端口 + * @param ssrc rtp的ssrc,10进制的字符串打印 + * @param is_udp 是否为udp + * @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 is_udp, on_mk_media_send_rtp_result cb, void *user_data); + +/** + * 停止ps-rtp发送 + * @param ctx 对象指针 + * @return 1成功,0失败 + */ +API_EXPORT int API_CALL mk_media_stop_send_rtp(mk_media ctx); + #ifdef __cplusplus } #endif diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 6ce06679..50bcbff4 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -211,6 +211,22 @@ API_EXPORT int API_CALL mk_media_source_seek_to(const mk_media_source ctx,uint32 return src->seekTo(stamp); } +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 is_udp, on_mk_media_source_send_rtp_result cb, void *user_data){ + assert(ctx && dst_url && ssrc); + MediaSource *src = (MediaSource *)ctx; + src->startSendRtp(dst_url, dst_port, ssrc, is_udp, [cb, user_data](const SockException &ex){ + if (cb) { + cb(user_data, ex.getErrCode(), ex.what()); + } + }); +} + +API_EXPORT int API_CALL mk_media_source_stop_send_rtp(const mk_media_source ctx){ + assert(ctx); + MediaSource *src = (MediaSource *) ctx; + return src->stopSendRtp(); +} + API_EXPORT void API_CALL mk_media_source_find(const char *schema, const char *vhost, const char *app, diff --git a/api/source/mk_media.cpp b/api/source/mk_media.cpp index 1ad6ba64..2c430f8d 100755 --- a/api/source/mk_media.cpp +++ b/api/source/mk_media.cpp @@ -192,3 +192,21 @@ API_EXPORT void API_CALL mk_media_input_audio(mk_media ctx, void* data, int len, MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; (*obj)->getChannel()->inputAudio((char*)data, len, dts); } + +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 is_udp, on_mk_media_send_rtp_result cb, void *user_data){ + assert(ctx && dst_url && ssrc); + MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; + //sender参数无用 + (*obj)->getChannel()->startSendRtp(*(MediaSource *) 1, dst_url, dst_port, ssrc, is_udp, [cb, user_data](const SockException &ex){ + if (cb) { + cb(user_data, ex.getErrCode(), ex.what()); + } + }); +} + +API_EXPORT int API_CALL mk_media_stop_send_rtp(mk_media ctx){ + assert(ctx); + MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; + //sender参数无用 + return (*obj)->getChannel()->stopSendRtp(*(MediaSource *) 1); +} \ No newline at end of file