补充mk_track、mk_media部分c api (#3628)

Co-authored-by: lidaofu <lidf@ahtelit.com>
Co-authored-by: xiongziliang <771730766@qq.com>
This commit is contained in:
Lidaofu 2024-06-15 15:55:39 +08:00 committed by GitHub
parent 720d6304d2
commit ad7b28bb0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 109 additions and 3 deletions

View File

@ -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); 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 // 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); 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 // MediaSource::broadcastMessage
API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len); API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len);
// MediaSource::getOriginUrl() // MediaSource::getOriginUrl()
API_EXPORT const char* API_CALL mk_media_source_get_origin_url(const mk_media_source ctx); API_EXPORT const char* API_CALL mk_media_source_get_origin_url(const mk_media_source ctx);
// MediaSource::getOriginType() // MediaSource::getOriginType()
API_EXPORT int API_CALL mk_media_source_get_origin_type(const mk_media_source ctx); 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() // MediaSource::getCreateStamp()
API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx); API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx);
// MediaSource::isRecording() 0:hls,1:MP4 // MediaSource::isRecording() 0:hls,1:MP4
API_EXPORT int API_CALL mk_media_source_is_recording(const mk_media_source ctx, int type); 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 * ZLMediaKit中被称作为MediaSource
* 3RtmpMediaSourceRtspMediaSourceHlsMediaSource * 3RtmpMediaSourceRtspMediaSourceHlsMediaSource

View File

@ -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); 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输出事件 * frame输出事件
* @param track track对象 * @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 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);
/** /**
* *
*/ */

View File

@ -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])); 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) { 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); assert(ctx && msg && len);
MediaSource *src = (MediaSource *)ctx; 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<int>(src->getOriginType()); return static_cast<int>(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) { API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx) {
assert(ctx); assert(ctx);
MediaSource *src = (MediaSource *)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); 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){ API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){
assert(ctx); assert(ctx);
MediaSource *src = (MediaSource *)ctx; MediaSource *src = (MediaSource *)ctx;

View File

@ -109,6 +109,21 @@ API_EXPORT int API_CALL mk_track_bit_rate(mk_track track) {
return (*((Track::Ptr *) track))->getBitRate(); 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) { 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); 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; return 0;
} }
API_EXPORT uint64_t API_CALL mk_track_video_key_frames(mk_track track) {
assert(track);
auto video = dynamic_pointer_cast<VideoTrack>((*((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<VideoTrack>((*((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<VideoTrack>((*((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) { API_EXPORT int API_CALL mk_track_audio_sample_rate(mk_track track) {
assert(track); assert(track);
auto audio = dynamic_pointer_cast<AudioTrack>((*((Track::Ptr *) track))); auto audio = dynamic_pointer_cast<AudioTrack>((*((Track::Ptr *) track)));