ffmpeg: factorize input thread creation and destruction
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
@@ -4053,16 +4053,13 @@ static void *input_thread(void *arg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_input_threads(void)
|
static void free_input_thread(int i)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < nb_input_files; i++) {
|
|
||||||
InputFile *f = input_files[i];
|
InputFile *f = input_files[i];
|
||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
|
|
||||||
if (!f || !f->in_thread_queue)
|
if (!f || !f->in_thread_queue)
|
||||||
continue;
|
return;
|
||||||
av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
|
av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
|
||||||
while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
|
while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
|
||||||
av_packet_unref(&pkt);
|
av_packet_unref(&pkt);
|
||||||
@@ -4070,19 +4067,24 @@ static void free_input_threads(void)
|
|||||||
pthread_join(f->thread, NULL);
|
pthread_join(f->thread, NULL);
|
||||||
f->joined = 1;
|
f->joined = 1;
|
||||||
av_thread_message_queue_free(&f->in_thread_queue);
|
av_thread_message_queue_free(&f->in_thread_queue);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_input_threads(void)
|
static void free_input_threads(void)
|
||||||
{
|
{
|
||||||
int i, ret;
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < nb_input_files; i++)
|
||||||
|
free_input_thread(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int init_input_thread(int i)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
InputFile *f = input_files[i];
|
||||||
|
|
||||||
if (nb_input_files == 1)
|
if (nb_input_files == 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < nb_input_files; i++) {
|
|
||||||
InputFile *f = input_files[i];
|
|
||||||
|
|
||||||
if (f->ctx->pb ? !f->ctx->pb->seekable :
|
if (f->ctx->pb ? !f->ctx->pb->seekable :
|
||||||
strcmp(f->ctx->iformat->name, "lavfi"))
|
strcmp(f->ctx->iformat->name, "lavfi"))
|
||||||
f->non_blocking = 1;
|
f->non_blocking = 1;
|
||||||
@@ -4096,6 +4098,18 @@ static int init_input_threads(void)
|
|||||||
av_thread_message_queue_free(&f->in_thread_queue);
|
av_thread_message_queue_free(&f->in_thread_queue);
|
||||||
return AVERROR(ret);
|
return AVERROR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int init_input_threads(void)
|
||||||
|
{
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
|
for (i = 0; i < nb_input_files; i++) {
|
||||||
|
ret = init_input_thread(i);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user