mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 20:47:08 +08:00
hls/ts播放器改成绝对时间戳:#1389
This commit is contained in:
parent
cb00dbab0f
commit
a15d59cf23
@ -241,11 +241,6 @@ void HlsPlayer::playDelay() {
|
|||||||
|
|
||||||
void HlsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) {
|
void HlsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) {
|
||||||
_frame_cache.clear();
|
_frame_cache.clear();
|
||||||
_stamp[TrackAudio].setRelativeStamp(0);
|
|
||||||
_stamp[TrackVideo].setRelativeStamp(0);
|
|
||||||
_stamp[TrackAudio].syncTo(_stamp[TrackVideo]);
|
|
||||||
setPlayPosition(0);
|
|
||||||
|
|
||||||
_delegate.setTrackListener(listener);
|
_delegate.setTrackListener(listener);
|
||||||
|
|
||||||
//每50毫秒执行一次
|
//每50毫秒执行一次
|
||||||
@ -267,11 +262,12 @@ bool HlsDemuxer::inputFrame(const Frame::Ptr &frame) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//计算相对时间戳
|
if (_frame_cache.empty()) {
|
||||||
int64_t dts, pts;
|
//设置当前播放位置时间戳
|
||||||
_stamp[frame->getTrackType()].revise(frame->dts(), frame->pts(), dts, pts);
|
setPlayPosition(frame->dts());
|
||||||
|
}
|
||||||
//根据时间戳缓存frame
|
//根据时间戳缓存frame
|
||||||
_frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame));
|
_frame_cache.emplace(frame->dts(), Frame::getCacheAbleFrame(frame));
|
||||||
|
|
||||||
if (getBufferMS() > 30 * 1000) {
|
if (getBufferMS() > 30 * 1000) {
|
||||||
//缓存超过30秒,强制消费至15秒(减少延时或内存占用)
|
//缓存超过30秒,强制消费至15秒(减少延时或内存占用)
|
||||||
|
@ -19,10 +19,7 @@
|
|||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class HlsDemuxer
|
class HlsDemuxer : public MediaSinkInterface , public TrackSource, public std::enable_shared_from_this<HlsDemuxer> {
|
||||||
: public MediaSinkInterface
|
|
||||||
, public TrackSource
|
|
||||||
, public std::enable_shared_from_this<HlsDemuxer> {
|
|
||||||
public:
|
public:
|
||||||
HlsDemuxer() = default;
|
HlsDemuxer() = default;
|
||||||
~HlsDemuxer() override { _timer = nullptr; }
|
~HlsDemuxer() override { _timer = nullptr; }
|
||||||
@ -43,7 +40,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
int64_t _ticker_offset = 0;
|
int64_t _ticker_offset = 0;
|
||||||
toolkit::Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
Stamp _stamp[2];
|
|
||||||
toolkit::Timer::Ptr _timer;
|
toolkit::Timer::Ptr _timer;
|
||||||
MediaSinkDelegate _delegate;
|
MediaSinkDelegate _delegate;
|
||||||
std::multimap<int64_t, Frame::Ptr> _frame_cache;
|
std::multimap<int64_t, Frame::Ptr> _frame_cache;
|
||||||
|
Loading…
Reference in New Issue
Block a user