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