From 244b6c92e66019c5fb07cfab28b6f7a3f35b5e79 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 28 Jan 2021 00:00:39 +0100 Subject: [PATCH] obs-outputs: Fix RTMP restart not always working Bug is caused by the internal connection variables not being reset on reconnect, leading OBS to both be unable to parse valid packets from and send valid packets to the remote end. This commit splits RTMP_Init off into a new RTMP_Reset function, which resets these internal variables without re-initing the rest of the library. The original RTMP_Init calls the new function, perfectly preserving the old behaviour while adding a new reset function to address the issue with. Fixes obsproject/obs-studio#2865 --- plugins/obs-outputs/librtmp/rtmp.c | 16 +++++++++++----- plugins/obs-outputs/librtmp/rtmp.h | 1 + plugins/obs-outputs/rtmp-stream.c | 5 +++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/obs-outputs/librtmp/rtmp.c b/plugins/obs-outputs/librtmp/rtmp.c index a80320280..9f15e48fb 100644 --- a/plugins/obs-outputs/librtmp/rtmp.c +++ b/plugins/obs-outputs/librtmp/rtmp.c @@ -463,6 +463,17 @@ RTMP_Init(RTMP *r) { memset(r, 0, sizeof(RTMP)); r->m_sb.sb_socket = -1; + RTMP_Reset(r); + +#ifdef CRYPTO + RTMP_TLS_Init(r); +#endif + +} + +void +RTMP_Reset(RTMP *r) +{ r->m_inChunkSize = RTMP_DEFAULT_CHUNKSIZE; r->m_outChunkSize = RTMP_DEFAULT_CHUNKSIZE; r->m_bSendChunkSizeInfo = 1; @@ -476,11 +487,6 @@ RTMP_Init(RTMP *r) r->Link.nStreams = 0; r->Link.timeout = 30; r->Link.swfAge = 30; - -#ifdef CRYPTO - RTMP_TLS_Init(r); -#endif - } void diff --git a/plugins/obs-outputs/librtmp/rtmp.h b/plugins/obs-outputs/librtmp/rtmp.h index a4b5355c2..6c1f2567e 100644 --- a/plugins/obs-outputs/librtmp/rtmp.h +++ b/plugins/obs-outputs/librtmp/rtmp.h @@ -506,6 +506,7 @@ extern "C" int RTMP_ClientPacket(RTMP *r, RTMPPacket *packet); void RTMP_Init(RTMP *r); + void RTMP_Reset(RTMP *r); void RTMP_Close(RTMP *r); RTMP *RTMP_Alloc(void); void RTMP_TLS_Free(RTMP *r); diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c index 50579150a..18cb18cd0 100644 --- a/plugins/obs-outputs/rtmp-stream.c +++ b/plugins/obs-outputs/rtmp-stream.c @@ -969,8 +969,9 @@ static int try_connect(struct rtmp_stream *stream) info("Connecting to RTMP URL %s...", stream->path.array); - // this should have been called already by rtmp_stream_create - //RTMP_Init(&stream->rtmp); + // on reconnect we need to reset the internal variables of librtmp + // otherwise the data sent/received will not parse correctly on the other end + RTMP_Reset(&stream->rtmp); // since we don't call RTMP_Init above, there's no other good place // to reset this as doing it in RTMP_Close breaks the ugly RTMP -- GitLab