[mod_av] fix interrupt callback is not passed down to the hls context in the first open_input

This commit is contained in:
Anthony Minessale 2020-04-13 23:15:47 +00:00 committed by Andrey Volk
parent 5918d8d4a1
commit f7ed53b58d

View File

@ -342,12 +342,27 @@ static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt)
}
}
static int interrupt_cb(void *cp)
{
av_file_context_t *context = (av_file_context_t *) cp;
if (context->closed) {
return 1;
}
return 0;
}
static int mod_avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
const char *format, const char *filename)
const char *format, const char *filename, av_file_context_t *context)
{
AVFormatContext *s = avformat_alloc_context();
int ret = 0;
s->interrupt_callback.callback = interrupt_cb;
s->interrupt_callback.opaque = context;
*avctx = NULL;
if (!s)
goto nomem;
@ -1126,9 +1141,24 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
// av_dict_set(&opts, "c:v", "libvpx", 0);
/** Open the input file to read from it. */
if (!context->fc) {
context->fc = avformat_alloc_context();
}
if (!context->fc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open input file '%s' (error '%s')\n", filename, "NO MEM");
switch_goto_status(SWITCH_STATUS_FALSE, err);
}
context->fc->interrupt_callback.callback = interrupt_cb;
context->fc->interrupt_callback.opaque = context;
if ((error = avformat_open_input(&context->fc, filename, NULL, NULL)) < 0) {
char ebuf[255] = "";
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not open input file '%s' (error '%s')\n", filename, get_error_text(error, ebuf, sizeof(ebuf)));
avformat_free_context(context->fc);
context->fc = NULL;
switch_goto_status(SWITCH_STATUS_FALSE, err);
}
@ -1542,9 +1572,6 @@ GCC_DIAG_ON(deprecated-declarations)
context->vid_ready = 1;
switch_queue_push(context->eh.video_queue, img);
context->last_vid_push = switch_time_now();
}
}
}
@ -1743,7 +1770,7 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa
return SWITCH_STATUS_SUCCESS;
}
mod_avformat_alloc_output_context2(&context->fc, NULL, format, (char *)file);
mod_avformat_alloc_output_context2(&context->fc, NULL, format, (char *)file, context);
if (!context->fc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not deduce output format from file extension\n");
@ -2581,6 +2608,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
context->vid_ready = 1;
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_BREAK;
}
}