]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11394: [mod_av] Fix cpu race created by this patch
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 27 Sep 2018 18:49:07 +0000 (18:49 +0000)
committerAndrey Volk <andrey@signalwire.com>
Tue, 27 Nov 2018 22:47:22 +0000 (02:47 +0400)
src/mod/applications/mod_av/avcodec.c

index a2eda7caf9b5a56a5e0a9301a96c3bbf6fa1fb84..7df1aa42e0e5bcbd8ed67ccb2d6151fc2a99543e 100644 (file)
@@ -1269,22 +1269,19 @@ GCC_DIAG_ON(deprecated-declarations)
                        return SWITCH_STATUS_FALSE;
                }
 
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not open hardware codec %s, trying software encoder\n", codec_string);
-
-               context->hw_encoder = 0;
-               av_opt_free(context->encoder_ctx->priv_data);
-               set_h264_private_data(context, profile);
-               context->encoder = avcodec_find_encoder(context->av_codec_id);
-
-               if (!context->encoder) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find encoder id: %d\n", context->av_codec_id);
-                       return SWITCH_STATUS_FALSE;
+               if (context->encoder_ctx) {
+                       if (avcodec_is_open(context->encoder_ctx)) {
+                               avcodec_close(context->encoder_ctx);
+                       }
+                       av_free(context->encoder_ctx);
+                       context->encoder_ctx = NULL;
                }
 
-               if (avcodec_open2(context->encoder_ctx, context->encoder, NULL) < 0) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open codec %s\n", codec_string);
-                       return SWITCH_STATUS_FALSE;
-               }
+               context->encoder = NULL;
+               context->hw_encoder = 0;
+               context->codec_settings.video.try_hardware_encoder = 0;
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not open hardware codec %s, trying software encoder\n", codec_string);
+               return open_encoder(context, width, height);
        }
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "codec opened: %s\n", codec_string);