mk_player api 增加seek和获取进度以相对开始时间的接口以适应按时间轴方式回放的需求

This commit is contained in:
baiyfcu 2020-04-26 17:40:34 +08:00
parent 12eabbe426
commit 98d0bc27f9
5 changed files with 65 additions and 2 deletions

View File

@ -80,6 +80,13 @@ API_EXPORT void API_CALL mk_player_pause(mk_player ctx, int pause);
*/
API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress);
/**
*
* @param ctx
* @param seekPos
*/
API_EXPORT void API_CALL mk_player_seektoByPos(mk_player ctx, int seekPos);
/**
*
* @param ctx
@ -155,10 +162,15 @@ API_EXPORT int API_CALL mk_player_audio_channel(mk_player ctx);
API_EXPORT float API_CALL mk_player_duration(mk_player ctx);
/**
* 0.01.0
* 0.01.0
*/
API_EXPORT float API_CALL mk_player_progress(mk_player ctx);
/**
*
*/
API_EXPORT int API_CALL mk_player_progress_pos(mk_player ctx);
/**
* rtsp时有效
* @param ctx

View File

@ -62,6 +62,16 @@ API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress) {
});
}
API_EXPORT void API_CALL mk_player_seektoByPos(mk_player ctx, int seekPos)
{
MediaPlayer::Ptr& player = *((MediaPlayer::Ptr*)ctx);
player->getPoller()->async([seekPos, player]() {
//切换线程后再操作
player->seekTo((uint32_t)seekPos);
});
}
static void mk_player_set_on_event(mk_player ctx, on_mk_play_event cb, void *user_data, int type) {
assert(ctx && cb);
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);
@ -169,6 +179,14 @@ API_EXPORT float API_CALL mk_player_progress(mk_player ctx) {
return player->getProgress();
}
API_EXPORT int API_CALL mk_player_progress_pos(mk_player ctx)
{
assert(ctx);
MediaPlayer::Ptr& player = *((MediaPlayer::Ptr*)ctx);
return player->getProgressPos();
}
API_EXPORT float API_CALL mk_player_loss_rate(mk_player ctx, int track_type) {
assert(ctx);
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);

View File

@ -52,7 +52,10 @@ void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out,
//这是点播
dts_out = dts;
pts_out = pts;
_relativeStamp = dts_out;
_last_dts = dts;
if (_dts_base == -1)
_dts_base = dts;
_relativeStamp = _npt_base + dts - _dts_base;
return;
}
@ -84,6 +87,8 @@ void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out,
}
void Stamp::setRelativeStamp(int64_t relativeStamp) {
_dts_base = _last_dts;
_npt_base = relativeStamp;
_relativeStamp = relativeStamp;
}

View File

@ -71,6 +71,9 @@ private:
int64_t _last_dts = -1;
SmoothTicker _ticker;
bool _playback = false;
int64_t _dts_base = 0;
int64_t _npt_base = 0;
};

View File

@ -93,12 +93,24 @@ public:
*/
virtual float getProgress() const { return 0;}
/**
* pos
* @return
*/
virtual uint32_t getProgressPos() const { return 0; }
/**
*
* @param fProgress 0.0 ~ 1.0
*/
virtual void seekTo(float fProgress) {}
/**
*
* @param seekPos
*/
virtual void seekTo(uint32_t seekPos) {}
/**
* MediaSourcertsp/rtmp代理
* @param src
@ -174,6 +186,12 @@ public:
}
return Parent::getProgress();
}
uint32_t getProgressPos() const override {
if (_delegate) {
return _delegate->getProgressPos();
}
return Parent::getProgressPos();
}
void seekTo(float fProgress) override{
if (_delegate) {
return _delegate->seekTo(fProgress);
@ -181,6 +199,13 @@ public:
return Parent::seekTo(fProgress);
}
void seekTo(uint32_t seekPos) override {
if (_delegate) {
return _delegate->seekTo(seekPos);
}
return Parent::seekTo(seekPos);
}
void setMediaSouce(const MediaSource::Ptr & src) override {
if (_delegate) {
_delegate->setMediaSouce(src);