ZLMediaKit/src/Rtmp/RtmpSession.cpp

494 lines
17 KiB
C++
Raw Normal View History

2017-10-09 22:11:01 +08:00
/*
2017-09-27 16:20:30 +08:00
* MIT License
2017-04-01 16:35:56 +08:00
*
2019-05-08 15:40:07 +08:00
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
2017-09-27 16:20:30 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
2017-04-01 16:35:56 +08:00
*/
#include "RtmpSession.h"
#include "Common/config.h"
2017-04-01 16:35:56 +08:00
#include "Util/onceToken.h"
2018-10-24 17:17:55 +08:00
namespace mediakit {
2017-04-01 16:35:56 +08:00
static int kSockFlags = SOCKET_DEFAULE_FLAGS | FLAG_MORE;
2018-12-20 10:42:51 +08:00
RtmpSession::RtmpSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
2019-05-28 18:46:52 +08:00
DebugP(this);
2019-05-30 10:41:25 +08:00
GET_CONFIG(uint32_t,keep_alive_sec,Rtmp::kKeepAliveSecond);
pSock->setSendTimeOutSecond(keep_alive_sec);
//起始接收buffer缓存设置为4K节省内存
pSock->setReadBuffer(std::make_shared<BufferRaw>(4 * 1024));
2017-04-01 16:35:56 +08:00
}
RtmpSession::~RtmpSession() {
2019-05-28 18:46:52 +08:00
DebugP(this);
2017-04-01 16:35:56 +08:00
}
void RtmpSession::onError(const SockException& err) {
WarnP(this) << err.what();
//流量统计事件广播
2019-05-28 17:14:36 +08:00
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
2018-02-09 11:42:55 +08:00
2018-10-24 15:43:52 +08:00
if(_ui64TotalBytes > iFlowThreshold * 1024){
2019-05-20 17:46:06 +08:00
bool isPlayer = !_pPublisherSrc;
2018-10-09 09:36:03 +08:00
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport,
2018-10-24 15:43:52 +08:00
_mediaInfo,
_ui64TotalBytes,
_ticker.createdTime()/1000,
2019-05-20 17:46:06 +08:00
isPlayer,
2018-10-09 09:36:03 +08:00
*this);
}
2017-04-01 16:35:56 +08:00
}
void RtmpSession::onManager() {
2019-05-29 18:24:35 +08:00
GET_CONFIG(uint32_t,handshake_sec,Rtmp::kKeepAliveSecond);
GET_CONFIG(uint32_t,keep_alive_sec,Rtmp::kKeepAliveSecond);
if (_ticker.createdTime() > handshake_sec * 1000) {
2018-10-24 15:43:52 +08:00
if (!_pRingReader && !_pPublisherSrc) {
2019-05-29 18:08:50 +08:00
shutdown(SockException(Err_timeout,"illegal connection"));
2017-04-01 16:35:56 +08:00
}
}
2018-10-24 15:43:52 +08:00
if (_pPublisherSrc) {
2017-04-01 16:35:56 +08:00
//publisher
2019-05-29 18:24:35 +08:00
if (_ticker.elapsedTime() > keep_alive_sec * 1000) {
2019-05-29 18:08:50 +08:00
shutdown(SockException(Err_timeout,"recv data from rtmp pusher timeout"));
2017-04-01 16:35:56 +08:00
}
}
}
2018-02-23 15:36:51 +08:00
void RtmpSession::onRecv(const Buffer::Ptr &pBuf) {
2018-10-24 15:43:52 +08:00
_ticker.resetTime();
2017-04-01 16:35:56 +08:00
try {
2018-10-24 15:43:52 +08:00
_ui64TotalBytes += pBuf->size();
2017-04-01 16:35:56 +08:00
onParseRtmp(pBuf->data(), pBuf->size());
} catch (exception &e) {
2019-05-30 12:17:26 +08:00
shutdown(SockException(Err_shutdown, e.what()));
2017-04-01 16:35:56 +08:00
}
}
void RtmpSession::onCmd_connect(AMFDecoder &dec) {
auto params = dec.load<AMFValue>();
2017-05-13 17:25:31 +08:00
double amfVer = 0;
AMFValue objectEncoding = params["objectEncoding"];
if(objectEncoding){
amfVer = objectEncoding.as_number();
}
///////////set chunk size////////////////
2018-01-30 11:23:57 +08:00
sendChunkSize(60000);
2017-05-13 17:25:31 +08:00
////////////window Acknowledgement size/////
sendAcknowledgementSize(5000000);
///////////set peerBandwidth////////////////
sendPeerBandwidth(5000000);
2018-10-24 15:43:52 +08:00
_mediaInfo._app = params["app"].as_string();
_strTcUrl = params["tcUrl"].as_string();
if(_strTcUrl.empty()){
//defaultVhost:默认vhost
2018-10-24 15:43:52 +08:00
_strTcUrl = string(RTMP_SCHEMA) + "://" + DEFAULT_VHOST + "/" + _mediaInfo._app;
}
2017-04-01 16:35:56 +08:00
bool ok = true; //(app == APP_NAME);
AMFValue version(AMF_OBJECT);
version.set("fmsVer", "FMS/3,0,1,123");
version.set("capabilities", 31.0);
2017-04-01 16:35:56 +08:00
AMFValue status(AMF_OBJECT);
status.set("level", ok ? "status" : "error");
status.set("code", ok ? "NetConnection.Connect.Success" : "NetConnection.Connect.InvalidApp");
status.set("description", ok ? "Connection succeeded." : "InvalidApp.");
2017-05-13 17:25:31 +08:00
status.set("objectEncoding", amfVer);
2017-04-01 16:35:56 +08:00
sendReply(ok ? "_result" : "_error", version, status);
if (!ok) {
2018-10-24 15:43:52 +08:00
throw std::runtime_error("Unsupported application: " + _mediaInfo._app);
2017-04-01 16:35:56 +08:00
}
2017-05-13 17:25:31 +08:00
AMFEncoder invoke;
invoke << "onBWDone" << 0.0 << nullptr;
sendResponse(MSG_CMD, invoke.data());
2017-04-01 16:35:56 +08:00
}
void RtmpSession::onCmd_createStream(AMFDecoder &dec) {
sendReply("_result", nullptr, double(STREAM_MEDIA));
}
void RtmpSession::onCmd_publish(AMFDecoder &dec) {
std::shared_ptr<Ticker> pTicker(new Ticker);
2019-05-28 18:46:52 +08:00
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
std::shared_ptr<onceToken> pToken(new onceToken(nullptr,[pTicker,weakSelf](){
auto strongSelf = weakSelf.lock();
if(strongSelf){
DebugP(strongSelf.get()) << "publish 回复时间:" << pTicker->elapsedTime() << "ms";
}
}));
2017-04-01 16:35:56 +08:00
dec.load<AMFValue>();/* NULL */
2018-10-24 15:43:52 +08:00
_mediaInfo.parse(_strTcUrl + "/" + dec.load<std::string>());
_mediaInfo._schema = RTMP_SCHEMA;
auto onRes = [this,pToken](const string &err){
auto src = dynamic_pointer_cast<RtmpMediaSource>(MediaSource::find(RTMP_SCHEMA,
2018-10-24 15:43:52 +08:00
_mediaInfo._vhost,
_mediaInfo._app,
_mediaInfo._streamid,
false));
2018-02-06 16:17:37 +08:00
bool authSuccess = err.empty();
2018-10-24 15:43:52 +08:00
bool ok = (!src && !_pPublisherSrc && authSuccess);
AMFValue status(AMF_OBJECT);
status.set("level", ok ? "status" : "error");
status.set("code", ok ? "NetStream.Publish.Start" : (authSuccess ? "NetStream.Publish.BadName" : "NetStream.Publish.BadAuth"));
2018-02-05 17:25:22 +08:00
status.set("description", ok ? "Started publishing stream." : (authSuccess ? "Already publishing." : err.data()));
status.set("clientid", "0");
sendReply("onStatus", nullptr, status);
if (!ok) {
2019-05-29 18:08:50 +08:00
string errMsg = StrPrinter << (authSuccess ? "already publishing:" : err.data()) << " "
<< _mediaInfo._vhost << " "
<< _mediaInfo._app << " "
<< _mediaInfo._streamid;
shutdown(SockException(Err_shutdown,errMsg));
return;
}
2018-10-24 15:43:52 +08:00
_pPublisherSrc.reset(new RtmpToRtspMediaSource(_mediaInfo._vhost,_mediaInfo._app,_mediaInfo._streamid));
_pPublisherSrc->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
//如果是rtmp推流客户端那么加大TCP接收缓存这样能提升接收性能
_sock->setReadBuffer(std::make_shared<BufferRaw>(256 * 1024));
};
Broadcast::AuthInvoker invoker = [weakSelf,onRes,pToken](const string &err){
auto strongSelf = weakSelf.lock();
if(!strongSelf){
return;
}
strongSelf->async([weakSelf,onRes,err,pToken](){
auto strongSelf = weakSelf.lock();
if(!strongSelf){
return;
}
2018-02-06 16:17:37 +08:00
onRes(err);
});
};
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish,
2018-10-24 15:43:52 +08:00
_mediaInfo,
2018-02-09 15:50:21 +08:00
invoker,
*this);
if(!flag){
//该事件无人监听,默认鉴权成功
2018-02-06 16:17:37 +08:00
onRes("");
}
2017-04-01 16:35:56 +08:00
}
void RtmpSession::onCmd_deleteStream(AMFDecoder &dec) {
AMFValue status(AMF_OBJECT);
status.set("level", "status");
status.set("code", "NetStream.Unpublish.Success");
status.set("description", "Stop publishing.");
sendReply("onStatus", nullptr, status);
throw std::runtime_error(StrPrinter << "Stop publishing." << endl);
}
2018-10-31 12:11:14 +08:00
void RtmpSession::sendPlayResponse(const string &err,const RtmpMediaSource::Ptr &src){
bool authSuccess = err.empty();
2018-03-14 22:35:54 +08:00
bool ok = (src.operator bool() && authSuccess);
if (ok) {
//stream begin
sendUserControl(CONTROL_STREAM_BEGIN, STREAM_MEDIA);
}
// onStatus(NetStream.Play.Reset)
AMFValue status(AMF_OBJECT);
status.set("level", ok ? "status" : "error");
status.set("code", ok ? "NetStream.Play.Reset" : (authSuccess ? "NetStream.Play.StreamNotFound" : "NetStream.Play.BadAuth"));
status.set("description", ok ? "Resetting and playing." : (authSuccess ? "No such stream." : err.data()));
2018-10-24 15:43:52 +08:00
status.set("details", _mediaInfo._streamid);
2018-03-14 22:35:54 +08:00
status.set("clientid", "0");
sendReply("onStatus", nullptr, status);
if (!ok) {
2019-05-29 18:08:50 +08:00
string errMsg = StrPrinter << (authSuccess ? "no such stream:" : err.data()) << " "
<< _mediaInfo._vhost << " "
<< _mediaInfo._app << " "
<< _mediaInfo._streamid;
shutdown(SockException(Err_shutdown,errMsg));
2018-03-14 22:35:54 +08:00
return;
}
2017-04-01 16:35:56 +08:00
2018-03-14 22:35:54 +08:00
// onStatus(NetStream.Play.Start)
status.clear();
status.set("level", "status");
status.set("code", "NetStream.Play.Start");
status.set("description", "Started playing.");
2018-10-24 15:43:52 +08:00
status.set("details", _mediaInfo._streamid);
2018-03-14 22:35:54 +08:00
status.set("clientid", "0");
sendReply("onStatus", nullptr, status);
// |RtmpSampleAccess(true, true)
AMFEncoder invoke;
invoke << "|RtmpSampleAccess" << true << true;
sendResponse(MSG_DATA, invoke.data());
//onStatus(NetStream.Data.Start)
invoke.clear();
AMFValue obj(AMF_OBJECT);
obj.set("code", "NetStream.Data.Start");
invoke << "onStatus" << obj;
sendResponse(MSG_DATA, invoke.data());
//onStatus(NetStream.Play.PublishNotify)
status.clear();
status.set("level", "status");
status.set("code", "NetStream.Play.PublishNotify");
status.set("description", "Now published.");
2018-10-24 15:43:52 +08:00
status.set("details", _mediaInfo._streamid);
2018-03-14 22:35:54 +08:00
status.set("clientid", "0");
sendReply("onStatus", nullptr, status);
// onMetaData
invoke.clear();
invoke << "onMetaData" << src->getMetaData();
sendResponse(MSG_DATA, invoke.data());
src->getConfigFrame([&](const RtmpPacket::Ptr &pkt) {
2019-05-28 18:46:52 +08:00
//DebugP(this)<<"send initial frame";
2018-03-14 22:35:54 +08:00
onSendMedia(pkt);
});
_pRingReader = src->getRing()->attach(getPoller());
2018-03-14 22:35:54 +08:00
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
SockUtil::setNoDelay(_sock->rawFD(), false);
2018-10-24 15:43:52 +08:00
_pRingReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt) {
2018-03-14 22:35:54 +08:00
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
return;
}
strongSelf->onSendMedia(pkt);
2018-03-14 22:35:54 +08:00
});
2018-10-24 15:43:52 +08:00
_pRingReader->setDetachCB([weakSelf]() {
2018-03-14 22:35:54 +08:00
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
return;
}
2019-05-29 18:08:50 +08:00
strongSelf->shutdown(SockException(Err_shutdown,"rtmp ring buffer detached"));
2018-03-14 22:35:54 +08:00
});
2018-10-24 15:43:52 +08:00
_pPlayerSrc = src;
2019-05-27 18:39:43 +08:00
if (src->readerCount() == 1) {
2018-03-14 22:35:54 +08:00
src->seekTo(0);
}
//提高发送性能
(*this) << SocketFlags(kSockFlags);
SockUtil::setNoDelay(_sock->rawFD(),false);
2018-03-14 22:35:54 +08:00
}
2018-10-31 12:11:14 +08:00
void RtmpSession::doPlayResponse(const string &err,const std::function<void(bool)> &cb){
if(!err.empty()){
//鉴权失败,直接返回播放失败
sendPlayResponse(err, nullptr);
cb(false);
return;
}
//鉴权成功,查找媒体源并回复
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
2019-05-28 09:25:41 +08:00
MediaSource::findAsync(_mediaInfo,weakSelf.lock(), true,[weakSelf,cb](const MediaSource::Ptr &src){
auto rtmp_src = dynamic_pointer_cast<RtmpMediaSource>(src);
2018-10-31 12:11:14 +08:00
auto strongSelf = weakSelf.lock();
if(strongSelf){
strongSelf->sendPlayResponse("", rtmp_src);
2018-10-31 12:11:14 +08:00
}
cb(rtmp_src.operator bool());
2018-10-31 12:11:14 +08:00
});
}
2018-03-14 22:35:54 +08:00
void RtmpSession::doPlay(AMFDecoder &dec){
std::shared_ptr<Ticker> pTicker(new Ticker);
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
2019-05-28 18:46:52 +08:00
std::shared_ptr<onceToken> pToken(new onceToken(nullptr,[pTicker,weakSelf](){
auto strongSelf = weakSelf.lock();
if(strongSelf) {
DebugP(strongSelf.get()) << "play 回复时间:" << pTicker->elapsedTime() << "ms";
}
}));
Broadcast::AuthInvoker invoker = [weakSelf,pToken](const string &err){
auto strongSelf = weakSelf.lock();
if(!strongSelf){
return;
}
strongSelf->async([weakSelf,err,pToken](){
auto strongSelf = weakSelf.lock();
if(!strongSelf){
return;
}
2018-10-31 12:11:14 +08:00
strongSelf->doPlayResponse(err,[pToken](bool){});
});
};
2018-10-24 15:43:52 +08:00
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,*this);
if(!flag){
//该事件无人监听,默认不鉴权
2018-10-31 12:11:14 +08:00
doPlayResponse("",[pToken](bool){});
}
2017-05-18 16:24:36 +08:00
}
void RtmpSession::onCmd_play2(AMFDecoder &dec) {
doPlay(dec);
2017-05-18 16:24:36 +08:00
}
void RtmpSession::onCmd_play(AMFDecoder &dec) {
dec.load<AMFValue>();/* NULL */
2018-10-24 15:43:52 +08:00
_mediaInfo.parse(_strTcUrl + "/" + dec.load<std::string>());
_mediaInfo._schema = RTMP_SCHEMA;
doPlay(dec);
2017-04-01 16:35:56 +08:00
}
void RtmpSession::onCmd_pause(AMFDecoder &dec) {
dec.load<AMFValue>();/* NULL */
bool paused = dec.load<bool>();
2019-05-28 18:46:52 +08:00
TraceP(this) << paused;
2017-04-01 16:35:56 +08:00
AMFValue status(AMF_OBJECT);
status.set("level", "status");
status.set("code", paused ? "NetStream.Pause.Notify" : "NetStream.Unpause.Notify");
status.set("description", paused ? "Paused stream." : "Unpaused stream.");
sendReply("onStatus", nullptr, status);
//streamBegin
sendUserControl(paused ? CONTROL_STREAM_EOF : CONTROL_STREAM_BEGIN,
STREAM_MEDIA);
2018-10-24 15:43:52 +08:00
if (!_pRingReader) {
2017-04-01 16:35:56 +08:00
throw std::runtime_error("Rtmp not started yet!");
}
if (paused) {
2018-10-24 15:43:52 +08:00
_pRingReader->setReadCB(nullptr);
2017-04-01 16:35:56 +08:00
} else {
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
2018-10-24 15:43:52 +08:00
_pRingReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt) {
2017-04-01 16:35:56 +08:00
auto strongSelf = weakSelf.lock();
if(!strongSelf) {
return;
}
strongSelf->onSendMedia(pkt);
2017-04-01 16:35:56 +08:00
});
}
}
void RtmpSession::setMetaData(AMFDecoder &dec) {
2018-10-24 15:43:52 +08:00
if (!_pPublisherSrc) {
2017-04-01 16:35:56 +08:00
throw std::runtime_error("not a publisher");
}
std::string type = dec.load<std::string>();
if (type != "onMetaData") {
throw std::runtime_error("can only set metadata");
}
2018-10-24 15:43:52 +08:00
_pPublisherSrc->onGetMetaData(dec.load<AMFValue>());
2017-04-01 16:35:56 +08:00
}
void RtmpSession::onProcessCmd(AMFDecoder &dec) {
typedef void (RtmpSession::*rtmpCMDHandle)(AMFDecoder &dec);
static unordered_map<string, rtmpCMDHandle> g_mapCmd;
static onceToken token([]() {
g_mapCmd.emplace("connect",&RtmpSession::onCmd_connect);
g_mapCmd.emplace("createStream",&RtmpSession::onCmd_createStream);
g_mapCmd.emplace("publish",&RtmpSession::onCmd_publish);
g_mapCmd.emplace("deleteStream",&RtmpSession::onCmd_deleteStream);
g_mapCmd.emplace("play",&RtmpSession::onCmd_play);
g_mapCmd.emplace("play2",&RtmpSession::onCmd_play2);
g_mapCmd.emplace("seek",&RtmpSession::onCmd_seek);
g_mapCmd.emplace("pause",&RtmpSession::onCmd_pause);}, []() {});
std::string method = dec.load<std::string>();
2017-04-01 16:35:56 +08:00
auto it = g_mapCmd.find(method);
if (it == g_mapCmd.end()) {
2019-05-28 18:46:52 +08:00
TraceP(this) << "can not support cmd:" << method;
2017-04-01 16:35:56 +08:00
return;
}
2018-10-24 15:43:52 +08:00
_dNowReqID = dec.load<double>();
2017-04-01 16:35:56 +08:00
auto fun = it->second;
(this->*fun)(dec);
}
void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) {
switch (chunkData.typeId) {
case MSG_CMD:
case MSG_CMD3: {
2017-05-13 17:25:31 +08:00
AMFDecoder dec(chunkData.strBuf, chunkData.typeId == MSG_CMD3 ? 1 : 0);
2017-04-01 16:35:56 +08:00
onProcessCmd(dec);
}
break;
case MSG_DATA:
case MSG_DATA3: {
2017-05-13 17:25:31 +08:00
AMFDecoder dec(chunkData.strBuf, chunkData.typeId == MSG_CMD3 ? 1 : 0);
2017-04-01 16:35:56 +08:00
std::string type = dec.load<std::string>();
2019-05-28 18:46:52 +08:00
TraceP(this) << "notify:" << type;
2017-04-01 16:35:56 +08:00
if (type == "@setDataFrame") {
setMetaData(dec);
}
}
break;
case MSG_AUDIO:
case MSG_VIDEO: {
2018-10-24 15:43:52 +08:00
if (!_pPublisherSrc) {
2017-04-01 16:35:56 +08:00
throw std::runtime_error("Not a rtmp publisher!");
}
2019-05-28 17:14:36 +08:00
GET_CONFIG(bool,rtmp_modify_stamp,Rtmp::kModifyStamp);
if(rtmp_modify_stamp){
2018-10-24 15:43:52 +08:00
chunkData.timeStamp = _stampTicker[chunkData.typeId % 2].elapsedTime();
}
2019-02-28 18:20:17 +08:00
_pPublisherSrc->onWrite(std::make_shared<RtmpPacket>(std::move(chunkData)));
2017-04-01 16:35:56 +08:00
}
break;
default:
2019-05-28 18:46:52 +08:00
WarnP(this) << "unhandled message:" << (int) chunkData.typeId << hexdump(chunkData.strBuf.data(), chunkData.strBuf.size());
2017-04-01 16:35:56 +08:00
break;
}
}
void RtmpSession::onCmd_seek(AMFDecoder &dec) {
dec.load<AMFValue>();/* NULL */
auto milliSeconds = dec.load<AMFValue>().as_number();
2019-05-28 18:46:52 +08:00
InfoP(this) << "rtmp seekTo(ms):" << milliSeconds;
2018-10-24 15:43:52 +08:00
auto stongSrc = _pPlayerSrc.lock();
2017-04-01 16:35:56 +08:00
if (stongSrc) {
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);
}
2017-12-04 23:55:09 +08:00
void RtmpSession::onSendMedia(const RtmpPacket::Ptr &pkt) {
auto modifiedStamp = pkt->timeStamp;
2018-10-24 15:43:52 +08:00
auto &firstStamp = _aui32FirstStamp[pkt->typeId % 2];
2017-05-17 11:52:59 +08:00
if(!firstStamp){
firstStamp = modifiedStamp;
}
if(modifiedStamp >= firstStamp){
//计算时间戳增量
modifiedStamp -= firstStamp;
}else{
//发生回环,重新计算时间戳增量
2018-10-24 15:43:52 +08:00
CLEAR_ARR(_aui32FirstStamp);
2017-05-17 11:52:59 +08:00
modifiedStamp = 0;
}
sendRtmp(pkt->typeId, pkt->streamId, pkt, modifiedStamp, pkt->chunkId);
2017-04-01 16:35:56 +08:00
}
2018-03-14 22:35:54 +08:00
2018-10-24 17:17:55 +08:00
} /* namespace mediakit */