mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
优化rtmp点播
This commit is contained in:
parent
cefb2a7cc4
commit
708300951b
@ -46,15 +46,15 @@ int64_t DeltaStamp::deltaStamp(int64_t stamp) {
|
||||
//时间戳增量为正,返回之
|
||||
_last_stamp = stamp;
|
||||
//在直播情况下,时间戳增量不得大于MAX_DELTA_STAMP
|
||||
return ret < MAX_DELTA_STAMP ? ret : (_playback ? ret : 0);
|
||||
return ret < MAX_DELTA_STAMP ? ret : 0;
|
||||
}
|
||||
|
||||
//时间戳增量为负,说明时间戳回环了或回退了
|
||||
_last_stamp = stamp;
|
||||
return _playback ? ret : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DeltaStamp::setPlayBack(bool playback) {
|
||||
void Stamp::setPlayBack(bool playback) {
|
||||
_playback = playback;
|
||||
}
|
||||
|
||||
@ -64,6 +64,14 @@ void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out,
|
||||
pts = dts;
|
||||
}
|
||||
|
||||
if(_playback){
|
||||
//这是点播
|
||||
dts_out = dts;
|
||||
pts_out = pts;
|
||||
_relativeStamp = dts_out;
|
||||
return;
|
||||
}
|
||||
|
||||
//pts和dts的差值
|
||||
int pts_dts_diff = pts - dts;
|
||||
|
||||
|
@ -45,15 +45,8 @@ public:
|
||||
* @return 时间戳增量
|
||||
*/
|
||||
int64_t deltaStamp(int64_t stamp);
|
||||
|
||||
/**
|
||||
* 设置是否为回放模式,回放模式运行时间戳回退
|
||||
* @param playback 是否为回放模式
|
||||
*/
|
||||
void setPlayBack(bool playback = true);
|
||||
private:
|
||||
int64_t _last_stamp = 0;
|
||||
bool _playback = false;
|
||||
};
|
||||
//该类解决时间戳回环、回退问题
|
||||
//计算相对时间戳或者产生平滑时间戳
|
||||
@ -83,10 +76,17 @@ public:
|
||||
* @return
|
||||
*/
|
||||
int64_t getRelativeStamp() const ;
|
||||
|
||||
/**
|
||||
* 设置是否为回放模式,回放模式运行时间戳回退
|
||||
* @param playback 是否为回放模式
|
||||
*/
|
||||
void setPlayBack(bool playback = true);
|
||||
private:
|
||||
int64_t _relativeStamp = 0;
|
||||
int64_t _last_dts = -1;
|
||||
SmoothTicker _ticker;
|
||||
bool _playback = false;
|
||||
};
|
||||
|
||||
|
||||
|
@ -274,6 +274,12 @@ void RtmpSession::sendPlayResponse(const string &err,const RtmpMediaSource::Ptr
|
||||
invoke.clear();
|
||||
invoke << "onMetaData" << metadata;
|
||||
sendResponse(MSG_DATA, invoke.data());
|
||||
auto duration = metadata["duration"].as_number();
|
||||
if(duration > 0){
|
||||
//这是点播,使用绝对时间戳
|
||||
_stamp[0].setPlayBack();
|
||||
_stamp[1].setPlayBack();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -510,20 +516,19 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) {
|
||||
|
||||
void RtmpSession::onCmd_seek(AMFDecoder &dec) {
|
||||
dec.load<AMFValue>();/* NULL */
|
||||
auto milliSeconds = dec.load<AMFValue>().as_number();
|
||||
InfoP(this) << "rtmp seekTo(ms):" << milliSeconds;
|
||||
auto stongSrc = _pPlayerSrc.lock();
|
||||
if (stongSrc) {
|
||||
_stamp[0].setPlayBack();
|
||||
_stamp[1].setPlayBack();
|
||||
stongSrc->seekTo(milliSeconds);
|
||||
}
|
||||
AMFValue status(AMF_OBJECT);
|
||||
AMFEncoder invoke;
|
||||
status.set("level", "status");
|
||||
status.set("code", "NetStream.Seek.Notify");
|
||||
status.set("description", "Seeking.");
|
||||
sendReply("onStatus", nullptr, status);
|
||||
|
||||
auto milliSeconds = dec.load<AMFValue>().as_number();
|
||||
InfoP(this) << "rtmp seekTo(ms):" << milliSeconds;
|
||||
auto stongSrc = _pPlayerSrc.lock();
|
||||
if (stongSrc) {
|
||||
stongSrc->seekTo(milliSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
void RtmpSession::onSendMedia(const RtmpPacket::Ptr &pkt) {
|
||||
|
Loading…
Reference in New Issue
Block a user