From 94d0505ea6ed5ff3c80d6a6aaf8565e66fdca099 Mon Sep 17 00:00:00 2001 From: gongluck <1039994845@qq.com> Date: Mon, 19 Sep 2022 10:46:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E8=BF=87offer?= =?UTF-8?q?=E8=8E=B7=E5=8F=96answer=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E4=BE=9D=E8=B5=96http=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_events_objects.h | 5 +++++ api/source/mk_events_objects.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index 5913c080..1f22f81b 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -82,6 +82,8 @@ API_EXPORT uint16_t API_CALL mk_media_info_get_port(const mk_media_info ctx); typedef void* mk_media_source; //查找MediaSource的回调函数 typedef void(API_CALL *on_mk_media_source_find_cb)(void *user_data, const mk_media_source ctx); +//生成AnswerSdp回调函数 +typedef void(API_CALL *on_mk_media_source_answersdp_cb)(void *user_data, const mk_media_source ctx, const char *answer, const char *err); //MediaSource::getSchema() API_EXPORT const char* API_CALL mk_media_source_get_schema(const mk_media_source ctx); @@ -134,6 +136,9 @@ API_EXPORT void API_CALL mk_media_source_find(const char *schema, //MediaSource::for_each_media() API_EXPORT void API_CALL mk_media_source_for_each(void *user_data, on_mk_media_source_find_cb cb, const char *schema, const char *vhost, const char *app, const char *stream); +//MediaSource::find() + WebRtcPlayer::create + getOffer +API_EXPORT void API_CALL mk_media_source_answersdp(void *user_data, on_mk_media_source_answersdp_cb cb, const char *offer, + const char *schema, const char *vhost, const char *app, const char *stream, int from_mp4); ///////////////////////////////////////////HttpBody///////////////////////////////////////////// //HttpBody对象的C映射 diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 2523b86c..dd19198a 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -257,6 +257,25 @@ API_EXPORT void API_CALL mk_media_source_for_each(void *user_data, on_mk_media_s }, schema ? schema : "", vhost ? vhost : "", app ? app : "", stream ? stream : ""); } +API_EXPORT void API_CALL mk_media_source_answersdp(void *user_data, on_mk_media_source_answersdp_cb cb, const char *offer, + const char *schema, const char *vhost, const char *app, const char *stream, int from_mp4) { +#ifdef ENABLE_WEBRTC + assert(offer && schema && vhost && app && stream && cb); + auto srcfound = MediaSource::find(schema, vhost, app, stream, from_mp4); + mediakit::MediaInfo info; + info._schema = RTC_SCHEMA; + info._host = vhost; + info._app = app; + info._streamid = stream; + try { + auto rtc = WebRtcPlayer::create(EventPollerPool::Instance().getPoller(), std::dynamic_pointer_cast(srcfound), info); + cb(user_data, srcfound.get(), rtc->getAnswerSdp(offer).c_str(), ""); + } catch (std::exception &ex) { + cb(user_data, nullptr, nullptr, ex.what()); + } +#endif +} + ///////////////////////////////////////////HttpBody///////////////////////////////////////////// API_EXPORT mk_http_body API_CALL mk_http_body_from_string(const char *str, size_t len){ assert(str);