From 98d0bc27f951a55232f9393280dfcf049344b365 Mon Sep 17 00:00:00 2001 From: baiyfcu Date: Sun, 26 Apr 2020 17:40:34 +0800 Subject: [PATCH] =?UTF-8?q?mk=5Fplayer=20api=20=E5=A2=9E=E5=8A=A0seek?= =?UTF-8?q?=E5=92=8C=E8=8E=B7=E5=8F=96=E8=BF=9B=E5=BA=A6=E4=BB=A5=E7=9B=B8?= =?UTF-8?q?=E5=AF=B9=E5=BC=80=E5=A7=8B=E6=97=B6=E9=97=B4=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BB=A5=E9=80=82=E5=BA=94=E6=8C=89=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=BD=B4=E6=96=B9=E5=BC=8F=E5=9B=9E=E6=94=BE=E7=9A=84=E9=9C=80?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_player.h | 14 +++++++++++++- api/source/mk_player.cpp | 18 ++++++++++++++++++ src/Common/Stamp.cpp | 7 ++++++- src/Common/Stamp.h | 3 +++ src/Player/PlayerBase.h | 25 +++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/api/include/mk_player.h b/api/include/mk_player.h index d93414e2..bd980891 100755 --- a/api/include/mk_player.h +++ b/api/include/mk_player.h @@ -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.0~1.0 + * 获取点播播放进度,取值范围 0.0~1.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 对象指针 diff --git a/api/source/mk_player.cpp b/api/source/mk_player.cpp index b2a01bcd..7db8bc69 100755 --- a/api/source/mk_player.cpp +++ b/api/source/mk_player.cpp @@ -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); diff --git a/src/Common/Stamp.cpp b/src/Common/Stamp.cpp index e184dcdb..7ed1474f 100644 --- a/src/Common/Stamp.cpp +++ b/src/Common/Stamp.cpp @@ -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; } diff --git a/src/Common/Stamp.h b/src/Common/Stamp.h index 9e49f393..5d3897bf 100644 --- a/src/Common/Stamp.h +++ b/src/Common/Stamp.h @@ -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; }; diff --git a/src/Player/PlayerBase.h b/src/Player/PlayerBase.h index e38d723e..656211f2 100644 --- a/src/Player/PlayerBase.h +++ b/src/Player/PlayerBase.h @@ -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) {} + /** * 设置一个MediaSource,直接生产rtsp/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);