提交 49f02037 编写于 作者: Z Zhang Rui

ff_ffplay: merge: 8dc6e92c3dc67a85026f3010045c7a28b1c0adc8

ffplay: more robust mutex, condition variable handling

SDL_CreateMutex and SDL_CreateCond can fail:
https://wiki.libsdl.org/SDL_CreateMutex.
This patch makes handling more robust in one instance.
Signed-off-by: NGanesh Ajjanagadde <gajjanagadde@gmail.com>
Signed-off-by: NMarton Balint <cus@passwd.hu>
上级 8a577a5a
......@@ -314,12 +314,21 @@ static int packet_queue_put_nullpacket(PacketQueue *q, int stream_index)
}
/* packet queue handling */
static void packet_queue_init(PacketQueue *q)
static int packet_queue_init(PacketQueue *q)
{
memset(q, 0, sizeof(PacketQueue));
q->mutex = SDL_CreateMutex();
if (!q->mutex) {
av_log(q, AV_LOG_FATAL, "SDL_CreateMutex(): %s\n", SDL_GetError());
return AVERROR(ENOMEM);
}
q->cond = SDL_CreateCond();
if (!q->cond) {
av_log(q, AV_LOG_FATAL, "SDL_CreateCond(): %s\n", SDL_GetError());
return AVERROR(ENOMEM);
}
q->abort_request = 1;
return 0;
}
static void packet_queue_flush(PacketQueue *q)
......@@ -2947,11 +2956,14 @@ static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputForma
if (frame_queue_init(&is->sampq, &is->audioq, SAMPLE_QUEUE_SIZE, 1) < 0)
goto fail;
packet_queue_init(&is->videoq);
packet_queue_init(&is->audioq);
if (packet_queue_init(&is->videoq) < 0 ||
packet_queue_init(&is->audioq) < 0 ||
#ifdef FFP_MERGE
packet_queue_init(&is->subtitleq);
packet_queue_init(&is->subtitleq) < 0)
#else
0)
#endif
goto fail;
is->continue_read_thread = SDL_CreateCond();
......@@ -3581,7 +3593,7 @@ int ffp_get_loop(FFPlayer *ffp)
return ffp->loop;
}
void ffp_packet_queue_init(PacketQueue *q)
int ffp_packet_queue_init(PacketQueue *q)
{
return packet_queue_init(q);
}
......
......@@ -69,7 +69,7 @@ void ffp_set_loop(FFPlayer *ffp, int loop);
int ffp_get_loop(FFPlayer *ffp);
/* for internal usage */
void ffp_packet_queue_init(PacketQueue *q);
int ffp_packet_queue_init(PacketQueue *q);
void ffp_packet_queue_destroy(PacketQueue *q);
void ffp_packet_queue_abort(PacketQueue *q);
void ffp_packet_queue_start(PacketQueue *q);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册