}
}
+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;
int error;
int i, idx = 0;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
// 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);
}
-
+
handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "file %s is %sseekable\n", filename, handle->seekable ? "" : "not ");
int error;
int sync = 0;
int eof = 0;
-
+
switch_mutex_lock(context->mutex);
context->file_read_thread_started = 1;
context->file_read_thread_running = 1;
context->vid_ready = 1;
switch_queue_push(context->eh.video_queue, img);
context->last_vid_push = switch_time_now();
-
-
-
}
}
}
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");
context->vid_ready = 1;
return SWITCH_STATUS_SUCCESS;
}
+
return SWITCH_STATUS_BREAK;
}
}