avplay: Move the stream setup in the main thread
And refactor the code in preparation of the following patches. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
parent
81306fd4bd
commit
f22f900594
65
avplay.c
65
avplay.c
@ -1204,7 +1204,7 @@ retry:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stream_close(VideoState *is)
|
static void player_close(VideoState *is)
|
||||||
{
|
{
|
||||||
VideoPicture *vp;
|
VideoPicture *vp;
|
||||||
int i;
|
int i;
|
||||||
@ -1235,7 +1235,7 @@ static void stream_close(VideoState *is)
|
|||||||
static void do_exit(void)
|
static void do_exit(void)
|
||||||
{
|
{
|
||||||
if (cur_stream) {
|
if (cur_stream) {
|
||||||
stream_close(cur_stream);
|
player_close(cur_stream);
|
||||||
cur_stream = NULL;
|
cur_stream = NULL;
|
||||||
}
|
}
|
||||||
uninit_opts();
|
uninit_opts();
|
||||||
@ -2256,16 +2256,28 @@ static int decode_interrupt_cb(void *ctx)
|
|||||||
return global_video_state && global_video_state->abort_request;
|
return global_video_state && global_video_state->abort_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this thread gets the stream from the disk or the network */
|
static void stream_close(VideoState *is)
|
||||||
static int decode_thread(void *arg)
|
{
|
||||||
|
/* disable interrupting */
|
||||||
|
global_video_state = NULL;
|
||||||
|
|
||||||
|
/* close each stream */
|
||||||
|
if (is->audio_stream >= 0)
|
||||||
|
stream_component_close(is, is->audio_stream);
|
||||||
|
if (is->video_stream >= 0)
|
||||||
|
stream_component_close(is, is->video_stream);
|
||||||
|
if (is->subtitle_stream >= 0)
|
||||||
|
stream_component_close(is, is->subtitle_stream);
|
||||||
|
if (is->ic) {
|
||||||
|
avformat_close_input(&is->ic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int stream_setup(VideoState *is)
|
||||||
{
|
{
|
||||||
VideoState *is = arg;
|
|
||||||
AVFormatContext *ic = NULL;
|
AVFormatContext *ic = NULL;
|
||||||
int err, i, ret;
|
int err, i, ret;
|
||||||
int st_index[AVMEDIA_TYPE_NB];
|
int st_index[AVMEDIA_TYPE_NB];
|
||||||
AVPacket pkt1, *pkt = &pkt1;
|
|
||||||
int eof = 0;
|
|
||||||
int pkt_in_play_range = 0;
|
|
||||||
AVDictionaryEntry *t;
|
AVDictionaryEntry *t;
|
||||||
AVDictionary **opts;
|
AVDictionary **opts;
|
||||||
int orig_nb_streams;
|
int orig_nb_streams;
|
||||||
@ -2385,6 +2397,23 @@ static int decode_thread(void *arg)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
stream_close(is);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this thread gets the stream from the disk or the network */
|
||||||
|
static int decode_thread(void *arg)
|
||||||
|
{
|
||||||
|
VideoState *is = arg;
|
||||||
|
AVPacket pkt1, *pkt = &pkt1;
|
||||||
|
AVFormatContext *ic = is->ic;
|
||||||
|
int pkt_in_play_range = 0;
|
||||||
|
int ret, eof = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (is->abort_request)
|
if (is->abort_request)
|
||||||
break;
|
break;
|
||||||
@ -2499,20 +2528,9 @@ static int decode_thread(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
fail:
|
|
||||||
/* disable interrupting */
|
|
||||||
global_video_state = NULL;
|
|
||||||
|
|
||||||
/* close each stream */
|
fail:
|
||||||
if (is->audio_stream >= 0)
|
stream_close(is);
|
||||||
stream_component_close(is, is->audio_stream);
|
|
||||||
if (is->video_stream >= 0)
|
|
||||||
stream_component_close(is, is->video_stream);
|
|
||||||
if (is->subtitle_stream >= 0)
|
|
||||||
stream_component_close(is, is->subtitle_stream);
|
|
||||||
if (is->ic) {
|
|
||||||
avformat_close_input(&is->ic);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
@ -2536,6 +2554,11 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
|
|||||||
is->ytop = 0;
|
is->ytop = 0;
|
||||||
is->xleft = 0;
|
is->xleft = 0;
|
||||||
|
|
||||||
|
if (stream_setup(is) < 0) {
|
||||||
|
av_free(is);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* start video display */
|
/* start video display */
|
||||||
is->pictq_mutex = SDL_CreateMutex();
|
is->pictq_mutex = SDL_CreateMutex();
|
||||||
is->pictq_cond = SDL_CreateCond();
|
is->pictq_cond = SDL_CreateCond();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user