From 2f075f60ea44aed7b7c44c1ec40c103cfbf7ea71 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Tue, 18 Apr 2023 10:38:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=EF=BC=8C=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/source/mk_media.cpp | 49 ++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/api/source/mk_media.cpp b/api/source/mk_media.cpp index 67bcfe30..070c12ed 100755 --- a/api/source/mk_media.cpp +++ b/api/source/mk_media.cpp @@ -16,7 +16,7 @@ using namespace std; using namespace toolkit; using namespace mediakit; -class MediaHelper : public MediaSourceEvent , public std::enable_shared_from_this { +class MediaHelper: public MediaSourceEvent, public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; MediaHelper(const char *vhost, const char *app, const char *stream, float duration, const ProtocolOption &option) { @@ -27,20 +27,16 @@ public: ~MediaHelper() = default; - void attachEvent(){ - _channel->setMediaListener(shared_from_this()); - } + void attachEvent() { _channel->setMediaListener(shared_from_this()); } - DevChannel::Ptr &getChannel(){ - return _channel; - } + DevChannel::Ptr &getChannel() { return _channel; } - void setOnClose(on_mk_media_close cb, std::shared_ptr user_data){ + void setOnClose(on_mk_media_close cb, std::shared_ptr user_data) { _on_close = cb; _on_close_data = std::move(user_data); } - void setOnSeek(on_mk_media_seek cb, std::shared_ptr user_data){ + void setOnSeek(on_mk_media_seek cb, std::shared_ptr user_data) { _on_seek = cb; _on_seek_data = std::move(user_data); } @@ -55,7 +51,7 @@ public: _on_speed_data = std::move(user_data); } - void setOnRegist(on_mk_media_source_regist cb, std::shared_ptr user_data){ + void setOnRegist(on_mk_media_source_regist cb, std::shared_ptr user_data) { _on_regist = cb; _on_regist_data = std::move(user_data); } @@ -97,15 +93,13 @@ protected: return _on_speed(_on_speed_data.get(), speed); } - void onRegist(MediaSource &sender, bool regist) override{ + void onRegist(MediaSource &sender, bool regist) override { if (_on_regist) { _on_regist(_on_regist_data.get(), (mk_media_source)&sender, regist); } } - toolkit::EventPoller::Ptr getOwnerPoller(MediaSource &sender) { - return _poller; - } + toolkit::EventPoller::Ptr getOwnerPoller(MediaSource &sender) override { return _poller; } private: EventPoller::Ptr _poller; @@ -122,7 +116,7 @@ private: std::shared_ptr _on_regist_data; }; -API_EXPORT void API_CALL mk_media_set_on_close(mk_media ctx, on_mk_media_close cb, void *user_data){ +API_EXPORT void API_CALL mk_media_set_on_close(mk_media ctx, on_mk_media_close cb, void *user_data) { mk_media_set_on_close2(ctx, cb, user_data, nullptr); } @@ -159,14 +153,14 @@ API_EXPORT void API_CALL mk_media_set_on_speed(mk_media ctx, on_mk_media_speed c mk_media_set_on_speed2(ctx, cb, user_data, nullptr); } -API_EXPORT void API_CALL mk_media_set_on_speed2(mk_media ctx, on_mk_media_speed cb, void *user_data, on_user_data_free user_data_free){ +API_EXPORT void API_CALL mk_media_set_on_speed2(mk_media ctx, on_mk_media_speed cb, void *user_data, on_user_data_free user_data_free) { assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; std::shared_ptr ptr(user_data, user_data_free ? user_data_free : [](void *) {}); (*obj)->setOnSpeed(cb, std::move(ptr)); } -API_EXPORT void API_CALL mk_media_set_on_regist(mk_media ctx, on_mk_media_source_regist cb, void *user_data){ +API_EXPORT void API_CALL mk_media_set_on_regist(mk_media ctx, on_mk_media_source_regist cb, void *user_data) { mk_media_set_on_regist2(ctx, cb, user_data, nullptr); } @@ -177,7 +171,7 @@ API_EXPORT void API_CALL mk_media_set_on_regist2(mk_media ctx, on_mk_media_sourc (*obj)->setOnRegist(cb, std::move(ptr)); } -API_EXPORT int API_CALL mk_media_total_reader_count(mk_media ctx){ +API_EXPORT int API_CALL mk_media_total_reader_count(mk_media ctx) { assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; return (*obj)->getChannel()->totalReaderCount(); @@ -209,7 +203,7 @@ API_EXPORT void API_CALL mk_media_release(mk_media ctx) { delete obj; } -API_EXPORT int API_CALL mk_media_init_video(mk_media ctx, int codec_id, int width, int height, float fps, int bit_rate){ +API_EXPORT int API_CALL mk_media_init_video(mk_media ctx, int codec_id, int width, int height, float fps, int bit_rate) { assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; VideoInfo info; @@ -221,7 +215,7 @@ API_EXPORT int API_CALL mk_media_init_video(mk_media ctx, int codec_id, int widt return (*obj)->getChannel()->initVideo(info); } -API_EXPORT int API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sample_rate, int channels, int sample_bit){ +API_EXPORT int API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sample_rate, int channels, int sample_bit) { assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; AudioInfo info; @@ -232,19 +226,19 @@ API_EXPORT int API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int samp return (*obj)->getChannel()->initAudio(info); } -API_EXPORT void API_CALL mk_media_init_track(mk_media ctx, mk_track track){ +API_EXPORT void API_CALL mk_media_init_track(mk_media ctx, mk_track track) { assert(ctx && track); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; (*obj)->getChannel()->addTrack(*((Track::Ptr *) track)); } -API_EXPORT void API_CALL mk_media_init_complete(mk_media ctx){ +API_EXPORT void API_CALL mk_media_init_complete(mk_media ctx) { assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; (*obj)->getChannel()->addTrackCompleted(); } -API_EXPORT int API_CALL mk_media_input_frame(mk_media ctx, mk_frame frame){ +API_EXPORT int API_CALL mk_media_input_frame(mk_media ctx, mk_frame frame) { assert(ctx && frame); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; return (*obj)->getChannel()->inputFrame(*((Frame::Ptr *) frame)); @@ -274,13 +268,13 @@ API_EXPORT int API_CALL mk_media_input_aac(mk_media ctx, const void *data, int l return (*obj)->getChannel()->inputAAC((const char *) data, len, dts, (char *) adts); } -API_EXPORT int API_CALL mk_media_input_pcm(mk_media ctx, void *data , int len, uint64_t pts){ +API_EXPORT int API_CALL mk_media_input_pcm(mk_media ctx, void *data, int len, uint64_t pts) { assert(ctx && data && len > 0); MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; return (*obj)->getChannel()->inputPCM((char*)data, len, pts); } -API_EXPORT int API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint64_t dts){ +API_EXPORT int API_CALL mk_media_input_audio(mk_media ctx, const void *data, int len, uint64_t dts) { assert(ctx && data && len > 0); MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; return (*obj)->getChannel()->inputAudio((const char*)data, len, dts); @@ -290,7 +284,8 @@ API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_u mk_media_start_send_rtp2(ctx, dst_url, dst_port, ssrc, is_udp, cb, user_data, nullptr); } -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 is_udp, 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_rtp2(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, + on_user_data_free user_data_free) { assert(ctx && dst_url && ssrc); MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; @@ -312,7 +307,7 @@ API_EXPORT void API_CALL mk_media_start_send_rtp2(mk_media ctx, const char *dst_ }); } -API_EXPORT void API_CALL mk_media_stop_send_rtp(mk_media ctx, const char *ssrc){ +API_EXPORT void API_CALL mk_media_stop_send_rtp(mk_media ctx, const char *ssrc) { assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *)ctx; // sender参数无用