hls/ts播放器改成绝对时间戳:#1389

This commit is contained in:
ziyue 2022-02-22 11:44:37 +08:00
parent cb00dbab0f
commit a15d59cf23
2 changed files with 6 additions and 14 deletions

View File

@ -241,11 +241,6 @@ void HlsPlayer::playDelay() {
void HlsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) {
_frame_cache.clear();
_stamp[TrackAudio].setRelativeStamp(0);
_stamp[TrackVideo].setRelativeStamp(0);
_stamp[TrackAudio].syncTo(_stamp[TrackVideo]);
setPlayPosition(0);
_delegate.setTrackListener(listener);
//每50毫秒执行一次
@ -267,11 +262,12 @@ bool HlsDemuxer::inputFrame(const Frame::Ptr &frame) {
return true;
}
//计算相对时间戳
int64_t dts, pts;
_stamp[frame->getTrackType()].revise(frame->dts(), frame->pts(), dts, pts);
if (_frame_cache.empty()) {
//设置当前播放位置时间戳
setPlayPosition(frame->dts());
}
//根据时间戳缓存frame
_frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame));
_frame_cache.emplace(frame->dts(), Frame::getCacheAbleFrame(frame));
if (getBufferMS() > 30 * 1000) {
//缓存超过30秒强制消费至15秒(减少延时或内存占用)

View File

@ -19,10 +19,7 @@
namespace mediakit {
class HlsDemuxer
: public MediaSinkInterface
, public TrackSource
, public std::enable_shared_from_this<HlsDemuxer> {
class HlsDemuxer : public MediaSinkInterface , public TrackSource, public std::enable_shared_from_this<HlsDemuxer> {
public:
HlsDemuxer() = default;
~HlsDemuxer() override { _timer = nullptr; }
@ -43,7 +40,6 @@ private:
private:
int64_t _ticker_offset = 0;
toolkit::Ticker _ticker;
Stamp _stamp[2];
toolkit::Timer::Ptr _timer;
MediaSinkDelegate _delegate;
std::multimap<int64_t, Frame::Ptr> _frame_cache;