From 97756861b48f16dac2deb9c472afb45138ba3e9e Mon Sep 17 00:00:00 2001 From: tt2468 Date: Sat, 25 Jun 2022 02:45:37 -0700 Subject: [PATCH] obs-outputs: Rework RTMP context init/deinit This commit fixes what is arguably a long-winded series of previous commits that have possibly caused just as many problems as they have fixed. I'll spare the details, but basically, there's no reason that any of the RTMP object should ever be used across socket sessions. This provides a slight enhancement by removing the `RTMP_Init` call in `rtmp_stream_create()`, since it effectively just initializes TLS just for `try_connect` to deinitialize it before it is even used. This also fixes the current `SO_RCVTIMEO` timeout functionality by making sure that `RTMP_Reset` is called last. --- plugins/obs-outputs/librtmp/rtmp.c | 8 +------- plugins/obs-outputs/rtmp-stream.c | 14 ++------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/plugins/obs-outputs/librtmp/rtmp.c b/plugins/obs-outputs/librtmp/rtmp.c index 7310b4b1c..0cd64101c 100644 --- a/plugins/obs-outputs/librtmp/rtmp.c +++ b/plugins/obs-outputs/librtmp/rtmp.c @@ -420,7 +420,7 @@ RTMP_TLS_Init(RTMP *r) void RTMP_TLS_Free(RTMP *r) { -#ifdef USE_MBEDTLS +#if defined(CRYPTO) && defined(USE_MBEDTLS) if (!r->RTMP_TLS_ctx) return; @@ -451,9 +451,7 @@ RTMP_Alloc() void RTMP_Free(RTMP *r) { -#if defined(CRYPTO) && defined(USE_MBEDTLS) RTMP_TLS_Free(r); -#endif free(r); } @@ -463,11 +461,7 @@ 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 diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c index 797a8c12c..85d0ce34e 100644 --- a/plugins/obs-outputs/rtmp-stream.c +++ b/plugins/obs-outputs/rtmp-stream.c @@ -154,7 +154,6 @@ static void *rtmp_stream_create(obs_data_t *settings, obs_output_t *output) pthread_mutex_init_value(&stream->packets_mutex); RTMP_LogSetCallback(log_rtmp); - RTMP_Init(&stream->rtmp); RTMP_LogSetLevel(RTMP_LOGWARNING); if (pthread_mutex_init(&stream->packets_mutex, NULL) != 0) @@ -1050,19 +1049,10 @@ static int try_connect(struct rtmp_stream *stream) info("Connecting to RTMP URL %s...", stream->path.array); - // 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); - - // apparently TLS will not properly persist through connections + // free any existing RTMP TLS context RTMP_TLS_Free(&stream->rtmp); - RTMP_TLS_Init(&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 - // authentication system - memset(&stream->rtmp.Link, 0, sizeof(stream->rtmp.Link)); - stream->rtmp.last_error_code = 0; + RTMP_Init(&stream->rtmp); if (!RTMP_SetupURL(&stream->rtmp, stream->path.array)) return OBS_OUTPUT_BAD_PATH;