From ad7b28bb0aa7d617b28143e0a8ba0852e5a0fb24 Mon Sep 17 00:00:00 2001 From: Lidaofu <746101210@qq.com> Date: Sat, 15 Jun 2024 15:55:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85mk=5Ftrack=E3=80=81mk=5Fmedia?= =?UTF-8?q?=E9=83=A8=E5=88=86c=20api=20(#3628)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: lidaofu Co-authored-by: xiongziliang <771730766@qq.com> --- api/include/mk_events_objects.h | 11 +++++--- api/include/mk_track.h | 30 +++++++++++++++++++++ api/source/mk_events_objects.cpp | 26 ++++++++++++++++++ api/source/mk_track.cpp | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 3 deletions(-) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index d28dbc62..5d1127a3 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -114,19 +114,24 @@ API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_so API_EXPORT int API_CALL mk_media_source_get_track_count(const mk_media_source ctx); // copy track reference by index from MediaSource, please use mk_track_unref to release it API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx, int index); +// MediaSource::Track:loss +API_EXPORT float API_CALL mk_media_source_get_track_loss(const mk_media_source ctx, const mk_track track); // MediaSource::broadcastMessage API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len); // MediaSource::getOriginUrl() API_EXPORT const char* API_CALL mk_media_source_get_origin_url(const mk_media_source ctx); // MediaSource::getOriginType() API_EXPORT int API_CALL mk_media_source_get_origin_type(const mk_media_source ctx); +// MediaSource::getOriginTypeStr(), 使用后请用mk_free释放返回值 +API_EXPORT const char *API_CALL mk_media_source_get_origin_type_str(const mk_media_source ctx); // MediaSource::getCreateStamp() API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx); // MediaSource::isRecording() 0:hls,1:MP4 API_EXPORT int API_CALL mk_media_source_is_recording(const mk_media_source ctx, int type); - - - +// MediaSource::getBytesSpeed() +API_EXPORT int API_CALL mk_media_source_get_bytes_speed(const mk_media_source ctx); +// MediaSource::getAliveSecond() +API_EXPORT uint64_t API_CALL mk_media_source_get_alive_second(const mk_media_source ctx); /** * 直播源在ZLMediaKit中被称作为MediaSource, * 目前支持3种,分别是RtmpMediaSource、RtspMediaSource、HlsMediaSource diff --git a/api/include/mk_track.h b/api/include/mk_track.h index 430c3cfc..63d34b0f 100644 --- a/api/include/mk_track.h +++ b/api/include/mk_track.h @@ -73,6 +73,21 @@ API_EXPORT const char* API_CALL mk_track_codec_name(mk_track track); */ API_EXPORT int API_CALL mk_track_bit_rate(mk_track track); +/** + * 获取轨道是否已就绪,1: 已就绪,0:未就绪 + */ +API_EXPORT int API_CALL mk_track_ready(mk_track track); + +/** + * 获取累计帧数 + */ +API_EXPORT uint64_t API_CALL mk_track_frames(mk_track track); + +/** + * 获取时间,单位毫秒 + */ +API_EXPORT uint64_t API_CALL mk_track_duration(mk_track track); + /** * 监听frame输出事件 * @param track track对象 @@ -114,6 +129,21 @@ API_EXPORT int API_CALL mk_track_video_height(mk_track track); */ API_EXPORT int API_CALL mk_track_video_fps(mk_track track); +/** + * 获取视频累计关键帧数 + */ +API_EXPORT uint64_t API_CALL mk_track_video_key_frames(mk_track track); + +/** + * 获取视频GOP关键帧间隔 + */ +API_EXPORT int API_CALL mk_track_video_gop_size(mk_track track); + +/** + * 获取视频累计关键帧间隔(毫秒) + */ +API_EXPORT int API_CALL mk_track_video_gop_interval_ms(mk_track track); + /** * 获取音频采样率 */ diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 3615bbcd..097e4201 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -218,6 +218,13 @@ API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx return (mk_track) new Track::Ptr(std::move(tracks[index])); } +API_EXPORT float API_CALL mk_media_source_get_track_loss(const mk_media_source ctx, const mk_track track) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + // rtp推流只有一个统计器,但是可能有多个track,如果短时间多次获取间隔丢包率,第二次会获取为-1 + return src->getLossRate((*((Track::Ptr *)track))->getTrackType()); +} + API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len) { assert(ctx && msg && len); MediaSource *src = (MediaSource *)ctx; @@ -240,6 +247,12 @@ API_EXPORT int API_CALL mk_media_source_get_origin_type(const mk_media_source c return static_cast(src->getOriginType()); } +API_EXPORT const char* API_CALL mk_media_source_get_origin_type_str(const mk_media_source ctx) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return _strdup(getOriginTypeString(src->getOriginType()).c_str()); +} + API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx) { assert(ctx); MediaSource *src = (MediaSource *)ctx; @@ -252,6 +265,19 @@ API_EXPORT int API_CALL mk_media_source_is_recording(const mk_media_source ctx,i return src->isRecording((Recorder::type)type); } +API_EXPORT int API_CALL mk_media_source_get_bytes_speed(const mk_media_source ctx) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return src->getBytesSpeed(); +} + +API_EXPORT uint64_t API_CALL mk_media_source_get_alive_second(const mk_media_source ctx) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return src->getAliveSecond(); +} + + API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){ assert(ctx); MediaSource *src = (MediaSource *)ctx; diff --git a/api/source/mk_track.cpp b/api/source/mk_track.cpp index c409ef22..dbd94eb4 100644 --- a/api/source/mk_track.cpp +++ b/api/source/mk_track.cpp @@ -109,6 +109,21 @@ API_EXPORT int API_CALL mk_track_bit_rate(mk_track track) { return (*((Track::Ptr *) track))->getBitRate(); } +API_EXPORT int API_CALL mk_track_ready(mk_track track) { + assert(track); + return (*((Track::Ptr *)track))->ready(); +} + +API_EXPORT uint64_t API_CALL mk_track_frames(mk_track track) { + assert(track); + return (*((Track::Ptr *)track))->getFrames(); +} + +API_EXPORT uint64_t API_CALL mk_track_duration(mk_track track) { + assert(track); + return (*((Track::Ptr *)track))->getDuration(); +} + API_EXPORT void *API_CALL mk_track_add_delegate(mk_track track, on_mk_frame_out cb, void *user_data) { return mk_track_add_delegate2(track, cb, user_data, nullptr); } @@ -167,6 +182,36 @@ API_EXPORT int API_CALL mk_track_video_fps(mk_track track) { return 0; } +API_EXPORT uint64_t API_CALL mk_track_video_key_frames(mk_track track) { + assert(track); + auto video = dynamic_pointer_cast((*((Track::Ptr *)track))); + if (video) { + return video->getVideoFps(); + } + WarnL << "not video track"; + return 0; +} + +API_EXPORT int API_CALL mk_track_video_gop_size(mk_track track) { + assert(track); + auto video = dynamic_pointer_cast((*((Track::Ptr *)track))); + if (video) { + return video->getVideoGopSize(); + } + WarnL << "not video track"; + return 0; +} + +API_EXPORT int API_CALL mk_track_video_gop_interval_ms(mk_track track) { + assert(track); + auto video = dynamic_pointer_cast((*((Track::Ptr *)track))); + if (video) { + return video->getVideoGopInterval(); + } + WarnL << "not video track"; + return 0; +} + API_EXPORT int API_CALL mk_track_audio_sample_rate(mk_track track) { assert(track); auto audio = dynamic_pointer_cast((*((Track::Ptr *) track)));