支持修正时间戳
This commit is contained in:
parent
749fb98439
commit
b70d6cd2c2
|
|
@ -33,6 +33,12 @@ void Stamp::revise(uint32_t dts, uint32_t pts, int64_t &dts_out, int64_t &pts_ou
|
||||||
//记录第一次时间戳,后面好计算时间戳增量
|
//记录第一次时间戳,后面好计算时间戳增量
|
||||||
_start_dts = dts;
|
_start_dts = dts;
|
||||||
_first = false;
|
_first = false;
|
||||||
|
_ticker = std::make_shared<SmoothTicker>();
|
||||||
|
}
|
||||||
|
//pts和dts的差值
|
||||||
|
int pts_dts_diff = pts - dts;
|
||||||
|
if(_modifyStamp){
|
||||||
|
dts = _ticker->elapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
//相对时间戳
|
//相对时间戳
|
||||||
|
|
@ -58,8 +64,7 @@ void Stamp::revise(uint32_t dts, uint32_t pts, int64_t &dts_out, int64_t &pts_ou
|
||||||
//没有播放时间戳
|
//没有播放时间戳
|
||||||
pts = dts;
|
pts = dts;
|
||||||
}
|
}
|
||||||
//pts和dts的差值
|
|
||||||
int pts_dts_diff = pts - dts;
|
|
||||||
if(pts_dts_diff > 200 || pts_dts_diff < -200){
|
if(pts_dts_diff > 200 || pts_dts_diff < -200){
|
||||||
//如果差值大于200毫秒,则认为由于回环导致时间戳错乱了
|
//如果差值大于200毫秒,则认为由于回环导致时间戳错乱了
|
||||||
pts_dts_diff = 0;
|
pts_dts_diff = 0;
|
||||||
|
|
|
||||||
|
|
@ -27,20 +27,23 @@
|
||||||
#ifndef ZLMEDIAKIT_STAMP_H
|
#ifndef ZLMEDIAKIT_STAMP_H
|
||||||
#define ZLMEDIAKIT_STAMP_H
|
#define ZLMEDIAKIT_STAMP_H
|
||||||
|
|
||||||
|
#include "Util/TimeTicker.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class Stamp {
|
class Stamp {
|
||||||
public:
|
public:
|
||||||
Stamp() = default;
|
Stamp(bool modifyStamp = false) {_modifyStamp = modifyStamp;};
|
||||||
~Stamp() = default;
|
~Stamp() = default;
|
||||||
void revise(uint32_t dts, uint32_t pts, int64_t &dts_out, int64_t &pts_out);
|
void revise(uint32_t dts, uint32_t pts, int64_t &dts_out, int64_t &pts_out);
|
||||||
private:
|
private:
|
||||||
int64_t _start_dts = 0;
|
int64_t _start_dts = 0;
|
||||||
int64_t _dts_inc = 0;
|
int64_t _dts_inc = 0;
|
||||||
bool _first = true;
|
bool _first = true;
|
||||||
|
bool _modifyStamp;
|
||||||
|
std::shared_ptr<SmoothTicker> _ticker;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue