rtmp点播采用简单握手,发送心跳包,兼容fms服务器: #2007

This commit is contained in:
ziyue
2022-09-30 13:34:56 +08:00
parent bfebcd62c7
commit 34838b1b26
3 changed files with 46 additions and 30 deletions

View File

@@ -288,12 +288,14 @@ const char *RtmpProtocol::onSearchPacketTail(const char *data,size_t len){
}
////for client////
void RtmpProtocol::startClientSession(const function<void()> &func) {
void RtmpProtocol::startClientSession(const function<void()> &func, bool complex) {
//发送 C0C1
char handshake_head = HANDSHAKE_PLAINTEXT;
onSendRawData(obtainBuffer(&handshake_head, 1));
RtmpHandshake c1(0);
c1.create_complex_c0c1();
if (complex) {
c1.create_complex_c0c1();
}
onSendRawData(obtainBuffer((char *) (&c1), sizeof(c1)));
_next_step_func = [this, func](const char *data, size_t len) {
//等待 S0+S1+S2
@@ -754,7 +756,8 @@ void RtmpProtocol::handle_chunk(RtmpPacket::Ptr packet) {
case MSG_WIN_SIZE: {
//如果窗口太小会导致发送sendAcknowledgement时无限递归https://github.com/ZLMediaKit/ZLMediaKit/issues/1839
_windows_size = max(load_be32(&chunk_data.buffer[0]), 32 * 1024U);
//窗口太大也可能导致fms服务器认为播放器心跳超时
_windows_size = min(max(load_be32(&chunk_data.buffer[0]), 32 * 1024U), 1280 * 1024U);
TraceL << "MSG_WIN_SIZE:" << _windows_size;
break;
}
@@ -806,7 +809,15 @@ void RtmpProtocol::handle_chunk(RtmpPacket::Ptr packet) {
break;
}
default: onRtmpChunk(std::move(packet)); break;
default: {
_bytes_recv += packet->size();
if (_windows_size > 0 && _bytes_recv - _bytes_recv_last >= _windows_size) {
_bytes_recv_last = _bytes_recv;
sendAcknowledgement(_bytes_recv);
}
onRtmpChunk(std::move(packet));
break;
}
}
}