mirror of https://git.ffmpeg.org/ffmpeg.git
ffplay: factorize thread starting and stopping code into decoder
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
d6910c4b5e
commit
ef1ccea945
54
ffplay.c
54
ffplay.c
|
@ -191,12 +191,11 @@ typedef struct Decoder {
|
||||||
AVRational start_pts_tb;
|
AVRational start_pts_tb;
|
||||||
int64_t next_pts;
|
int64_t next_pts;
|
||||||
AVRational next_pts_tb;
|
AVRational next_pts_tb;
|
||||||
|
SDL_Thread *decoder_tid;
|
||||||
} Decoder;
|
} Decoder;
|
||||||
|
|
||||||
typedef struct VideoState {
|
typedef struct VideoState {
|
||||||
SDL_Thread *read_tid;
|
SDL_Thread *read_tid;
|
||||||
SDL_Thread *video_tid;
|
|
||||||
SDL_Thread *audio_tid;
|
|
||||||
AVInputFormat *iformat;
|
AVInputFormat *iformat;
|
||||||
int abort_request;
|
int abort_request;
|
||||||
int force_refresh;
|
int force_refresh;
|
||||||
|
@ -264,7 +263,6 @@ typedef struct VideoState {
|
||||||
int xpos;
|
int xpos;
|
||||||
double last_vis_time;
|
double last_vis_time;
|
||||||
|
|
||||||
SDL_Thread *subtitle_tid;
|
|
||||||
int subtitle_stream;
|
int subtitle_stream;
|
||||||
AVStream *subtitle_st;
|
AVStream *subtitle_st;
|
||||||
PacketQueue subtitleq;
|
PacketQueue subtitleq;
|
||||||
|
@ -769,6 +767,15 @@ static int64_t frame_queue_last_pos(FrameQueue *f)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void decoder_abort(Decoder *d, FrameQueue *fq)
|
||||||
|
{
|
||||||
|
packet_queue_abort(d->queue);
|
||||||
|
frame_queue_signal(fq);
|
||||||
|
SDL_WaitThread(d->decoder_tid, NULL);
|
||||||
|
d->decoder_tid = NULL;
|
||||||
|
packet_queue_flush(d->queue);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void fill_rectangle(SDL_Surface *screen,
|
static inline void fill_rectangle(SDL_Surface *screen,
|
||||||
int x, int y, int w, int h, int color, int update)
|
int x, int y, int w, int h, int color, int update)
|
||||||
{
|
{
|
||||||
|
@ -2197,6 +2204,12 @@ static int audio_thread(void *arg)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void decoder_start(Decoder *d, int (*fn)(void *), void *arg)
|
||||||
|
{
|
||||||
|
packet_queue_start(d->queue);
|
||||||
|
d->decoder_tid = SDL_CreateThread(fn, arg);
|
||||||
|
}
|
||||||
|
|
||||||
static int video_thread(void *arg)
|
static int video_thread(void *arg)
|
||||||
{
|
{
|
||||||
VideoState *is = arg;
|
VideoState *is = arg;
|
||||||
|
@ -2731,31 +2744,28 @@ static int stream_component_open(VideoState *is, int stream_index)
|
||||||
is->audio_stream = stream_index;
|
is->audio_stream = stream_index;
|
||||||
is->audio_st = ic->streams[stream_index];
|
is->audio_st = ic->streams[stream_index];
|
||||||
|
|
||||||
packet_queue_start(&is->audioq);
|
|
||||||
decoder_init(&is->auddec, avctx, &is->audioq, is->continue_read_thread);
|
decoder_init(&is->auddec, avctx, &is->audioq, is->continue_read_thread);
|
||||||
if ((is->ic->iformat->flags & (AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK)) && !is->ic->iformat->read_seek) {
|
if ((is->ic->iformat->flags & (AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK)) && !is->ic->iformat->read_seek) {
|
||||||
is->auddec.start_pts = is->audio_st->start_time;
|
is->auddec.start_pts = is->audio_st->start_time;
|
||||||
is->auddec.start_pts_tb = is->audio_st->time_base;
|
is->auddec.start_pts_tb = is->audio_st->time_base;
|
||||||
}
|
}
|
||||||
is->audio_tid = SDL_CreateThread(audio_thread, is);
|
decoder_start(&is->auddec, audio_thread, is);
|
||||||
SDL_PauseAudio(0);
|
SDL_PauseAudio(0);
|
||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_VIDEO:
|
case AVMEDIA_TYPE_VIDEO:
|
||||||
is->video_stream = stream_index;
|
is->video_stream = stream_index;
|
||||||
is->video_st = ic->streams[stream_index];
|
is->video_st = ic->streams[stream_index];
|
||||||
|
|
||||||
packet_queue_start(&is->videoq);
|
|
||||||
decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread);
|
decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread);
|
||||||
is->video_tid = SDL_CreateThread(video_thread, is);
|
decoder_start(&is->viddec, video_thread, is);
|
||||||
is->queue_attachments_req = 1;
|
is->queue_attachments_req = 1;
|
||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_SUBTITLE:
|
case AVMEDIA_TYPE_SUBTITLE:
|
||||||
is->subtitle_stream = stream_index;
|
is->subtitle_stream = stream_index;
|
||||||
is->subtitle_st = ic->streams[stream_index];
|
is->subtitle_st = ic->streams[stream_index];
|
||||||
|
|
||||||
packet_queue_start(&is->subtitleq);
|
|
||||||
decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread);
|
decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread);
|
||||||
is->subtitle_tid = SDL_CreateThread(subtitle_thread, is);
|
decoder_start(&is->subdec, subtitle_thread, is);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -2778,13 +2788,9 @@ static void stream_component_close(VideoState *is, int stream_index)
|
||||||
|
|
||||||
switch (avctx->codec_type) {
|
switch (avctx->codec_type) {
|
||||||
case AVMEDIA_TYPE_AUDIO:
|
case AVMEDIA_TYPE_AUDIO:
|
||||||
packet_queue_abort(&is->audioq);
|
decoder_abort(&is->auddec, &is->sampq);
|
||||||
frame_queue_signal(&is->sampq);
|
|
||||||
SDL_CloseAudio();
|
SDL_CloseAudio();
|
||||||
SDL_WaitThread(is->audio_tid, NULL);
|
|
||||||
|
|
||||||
decoder_destroy(&is->auddec);
|
decoder_destroy(&is->auddec);
|
||||||
packet_queue_flush(&is->audioq);
|
|
||||||
swr_free(&is->swr_ctx);
|
swr_free(&is->swr_ctx);
|
||||||
av_freep(&is->audio_buf1);
|
av_freep(&is->audio_buf1);
|
||||||
is->audio_buf1_size = 0;
|
is->audio_buf1_size = 0;
|
||||||
|
@ -2798,28 +2804,12 @@ static void stream_component_close(VideoState *is, int stream_index)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_VIDEO:
|
case AVMEDIA_TYPE_VIDEO:
|
||||||
packet_queue_abort(&is->videoq);
|
decoder_abort(&is->viddec, &is->pictq);
|
||||||
|
|
||||||
/* note: we also signal this mutex to make sure we deblock the
|
|
||||||
video thread in all cases */
|
|
||||||
frame_queue_signal(&is->pictq);
|
|
||||||
|
|
||||||
SDL_WaitThread(is->video_tid, NULL);
|
|
||||||
|
|
||||||
decoder_destroy(&is->viddec);
|
decoder_destroy(&is->viddec);
|
||||||
packet_queue_flush(&is->videoq);
|
|
||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_SUBTITLE:
|
case AVMEDIA_TYPE_SUBTITLE:
|
||||||
packet_queue_abort(&is->subtitleq);
|
decoder_abort(&is->subdec, &is->subpq);
|
||||||
|
|
||||||
/* note: we also signal this mutex to make sure we deblock the
|
|
||||||
video thread in all cases */
|
|
||||||
frame_queue_signal(&is->subpq);
|
|
||||||
|
|
||||||
SDL_WaitThread(is->subtitle_tid, NULL);
|
|
||||||
|
|
||||||
decoder_destroy(&is->subdec);
|
decoder_destroy(&is->subdec);
|
||||||
packet_queue_flush(&is->subtitleq);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue