Skip to content

Commit

Permalink
obs-outputs: fix RTMP reconnect (fixes obsproject#2865)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Thulinma committed Jan 27, 2021
1 parent d2ca8b5 commit b592df4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions plugins/obs-outputs/librtmp/rtmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions plugins/obs-outputs/librtmp/rtmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions plugins/obs-outputs/rtmp-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b592df4

Please sign in to comment.