From 00b70f8d29960096e13da6f273e0d6bda8b83494 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 22 Sep 2012 16:27:47 +0200 Subject: [PATCH 1/8] ffplay: add update parameter to fill_rectangle Signed-off-by: Marton Balint --- ffplay.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ffplay.c b/ffplay.c index c6cf880ccc..07d7836679 100644 --- a/ffplay.c +++ b/ffplay.c @@ -449,7 +449,7 @@ static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *seria } static inline void fill_rectangle(SDL_Surface *screen, - int x, int y, int w, int h, int color) + int x, int y, int w, int h, int color, int update) { SDL_Rect rect; rect.x = x; @@ -457,6 +457,8 @@ static inline void fill_rectangle(SDL_Surface *screen, rect.w = w; rect.h = h; SDL_FillRect(screen, &rect, color); + if (update && w > 0 && h > 0) + SDL_UpdateRect(screen, x, y, w, h); } #define ALPHA_BLEND(a, oldp, newp, s)\ @@ -824,7 +826,7 @@ static void video_audio_display(VideoState *s) if (s->show_mode == SHOW_MODE_WAVES) { fill_rectangle(screen, s->xleft, s->ytop, s->width, s->height, - bgcolor); + bgcolor, 0); fgcolor = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff); @@ -845,7 +847,7 @@ static void video_audio_display(VideoState *s) } fill_rectangle(screen, s->xleft + x, ys, 1, y, - fgcolor); + fgcolor, 0); i += channels; if (i >= SAMPLE_ARRAY_SIZE) i -= SAMPLE_ARRAY_SIZE; @@ -858,7 +860,7 @@ static void video_audio_display(VideoState *s) y = s->ytop + ch * h; fill_rectangle(screen, s->xleft, y, s->width, 1, - fgcolor); + fgcolor, 0); } SDL_UpdateRect(screen, s->xleft, s->ytop, s->width, s->height); } else { @@ -896,7 +898,7 @@ static void video_audio_display(VideoState *s) fill_rectangle(screen, s->xpos, s->height-y, 1, 1, - fgcolor); + fgcolor, 0); } } SDL_UpdateRect(screen, s->xpos, s->ytop, 1, s->height); @@ -2828,8 +2830,7 @@ static void toggle_audio_display(VideoState *is) is->show_mode = (is->show_mode + 1) % SHOW_MODE_NB; fill_rectangle(screen, is->xleft, is->ytop, is->width, is->height, - bgcolor); - SDL_UpdateRect(screen, is->xleft, is->ytop, is->width, is->height); + bgcolor, 1); } /* handle an event sent by the GUI */ From 65f6c42a9f12211aff4691ffb17c7cbc77972d87 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 22 Sep 2012 16:42:13 +0200 Subject: [PATCH 2/8] ffplay: fill the unused part of the window with black Should fix ticket #1667. Signed-off-by: Marton Balint --- ffplay.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ffplay.c b/ffplay.c index 07d7836679..90c18f4aca 100644 --- a/ffplay.c +++ b/ffplay.c @@ -234,6 +234,7 @@ typedef struct VideoState { #if !CONFIG_AVFILTER struct SwsContext *img_convert_ctx; #endif + SDL_Rect last_display_rect; char filename[1024]; int width, height, xleft, ytop; @@ -461,6 +462,42 @@ static inline void fill_rectangle(SDL_Surface *screen, SDL_UpdateRect(screen, x, y, w, h); } +/* draw only the border of a rectangle */ +static void fill_border(int xleft, int ytop, int width, int height, int x, int y, int w, int h, int color, int update) +{ + int w1, w2, h1, h2; + + /* fill the background */ + w1 = x; + if (w1 < 0) + w1 = 0; + w2 = width - (x + w); + if (w2 < 0) + w2 = 0; + h1 = y; + if (h1 < 0) + h1 = 0; + h2 = height - (y + h); + if (h2 < 0) + h2 = 0; + fill_rectangle(screen, + xleft, ytop, + w1, height, + color, update); + fill_rectangle(screen, + xleft + width - w2, ytop, + w2, height, + color, update); + fill_rectangle(screen, + xleft + w1, ytop, + width - w1 - w2, h1, + color, update); + fill_rectangle(screen, + xleft + w1, ytop + height - h2, + width - w1 - w2, h2, + color, update); +} + #define ALPHA_BLEND(a, oldp, newp, s)\ ((((oldp << s) * (255 - (a))) + (newp * (a))) / (255 << s)) @@ -761,6 +798,12 @@ static void video_image_display(VideoState *is) calculate_display_rect(&rect, is->xleft, is->ytop, is->width, is->height, vp); SDL_DisplayYUVOverlay(vp->bmp, &rect); + + if (rect.x != is->last_display_rect.x || rect.y != is->last_display_rect.y || rect.w != is->last_display_rect.w || rect.h != is->last_display_rect.h || is->force_refresh) { + int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); + fill_border(is->xleft, is->ytop, is->width, is->height, rect.x, rect.y, rect.w, rect.h, bgcolor, 1); + is->last_display_rect = rect; + } } } From abd49a75240f71a3a8c6281c4838a6de42ae930b Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 28 Oct 2012 01:19:34 +0200 Subject: [PATCH 3/8] ffplay: always free inputs and outputs in configure_filtergraph Fixes Coverity CID 733791. Signed-off-by: Marton Balint --- ffplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffplay.c b/ffplay.c index 90c18f4aca..f6831499fb 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1681,7 +1681,7 @@ static int configure_filtergraph(AVFilterGraph *graph, const char *filtergraph, goto fail; } - return avfilter_graph_config(graph, NULL); + ret = avfilter_graph_config(graph, NULL); fail: avfilter_inout_free(&outputs); avfilter_inout_free(&inputs); From afd9e705dea7f61eca49dec1fbe46073f00a43ae Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 28 Oct 2012 01:31:14 +0200 Subject: [PATCH 4/8] ffplay: check for buffersink_params allocation success Signed-off-by: Marton Balint --- ffplay.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ffplay.c b/ffplay.c index f6831499fb..c6bf61198e 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1698,6 +1698,9 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c AVFilterContext *filt_src = NULL, *filt_out = NULL, *filt_format, *filt_crop; AVCodecContext *codec = is->video_st->codec; + if (!buffersink_params) + return AVERROR(ENOMEM); + snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags); graph->scale_sws_opts = av_strdup(sws_flags_str); From 09214f494b2cf7b89c70f4f91d98c60a8b7382fe Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 28 Oct 2012 01:51:25 +0200 Subject: [PATCH 5/8] ffplay: remove uneeded format filter, buffersink format is set Signed-off-by: Marton Balint --- ffplay.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ffplay.c b/ffplay.c index c6bf61198e..0c18940044 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1695,7 +1695,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c char buffersrc_args[256]; int ret; AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc(); - AVFilterContext *filt_src = NULL, *filt_out = NULL, *filt_format, *filt_crop; + AVFilterContext *filt_src = NULL, *filt_out = NULL, *filt_crop; AVCodecContext *codec = is->video_st->codec; if (!buffersink_params) @@ -1730,13 +1730,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c avfilter_get_by_name("crop"), "ffplay_crop", "floor(in_w/2)*2:floor(in_h/2)*2", NULL, graph)) < 0) return ret; - if ((ret = avfilter_graph_create_filter(&filt_format, - avfilter_get_by_name("format"), - "format", "yuv420p", NULL, graph)) < 0) - return ret; - if ((ret = avfilter_link(filt_crop, 0, filt_format, 0)) < 0) - return ret; - if ((ret = avfilter_link(filt_format, 0, filt_out, 0)) < 0) + if ((ret = avfilter_link(filt_crop, 0, filt_out, 0)) < 0) return ret; if ((ret = configure_filtergraph(graph, vfilters, filt_src, filt_crop)) < 0) From 8cb740245daf8a71904787b572d60715654db0b1 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 28 Oct 2012 02:00:52 +0200 Subject: [PATCH 6/8] ffplay: always free buffersink_params in configure_video_filters Fixes Coverity CID 733792. Signed-off-by: Marton Balint --- ffplay.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ffplay.c b/ffplay.c index 0c18940044..23391922ce 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1714,31 +1714,32 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c avfilter_get_by_name("buffer"), "ffplay_buffer", buffersrc_args, NULL, graph)) < 0) - return ret; + goto fail; buffersink_params->pixel_fmts = pix_fmts; ret = avfilter_graph_create_filter(&filt_out, avfilter_get_by_name("ffbuffersink"), "ffplay_buffersink", NULL, buffersink_params, graph); - av_freep(&buffersink_params); if (ret < 0) - return ret; + goto fail; /* SDL YUV code is not handling odd width/height for some driver * combinations, therefore we crop the picture to an even width/height. */ if ((ret = avfilter_graph_create_filter(&filt_crop, avfilter_get_by_name("crop"), "ffplay_crop", "floor(in_w/2)*2:floor(in_h/2)*2", NULL, graph)) < 0) - return ret; + goto fail; if ((ret = avfilter_link(filt_crop, 0, filt_out, 0)) < 0) - return ret; + goto fail; if ((ret = configure_filtergraph(graph, vfilters, filt_src, filt_crop)) < 0) - return ret; + goto fail; is->in_video_filter = filt_src; is->out_video_filter = filt_out; +fail: + av_freep(&buffersink_params); return ret; } From fdb933444add87e026b64639d0db83b0d5177c7b Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 28 Oct 2012 02:19:18 +0200 Subject: [PATCH 7/8] ffplay: only initialize codec opts before using it Fixes Coverity CID 733793. Signed-off-by: Marton Balint --- ffplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffplay.c b/ffplay.c index 23391922ce..beced86493 100644 --- a/ffplay.c +++ b/ffplay.c @@ -2277,7 +2277,6 @@ static int stream_component_open(VideoState *is, int stream_index) avctx = ic->streams[stream_index]->codec; codec = avcodec_find_decoder(avctx->codec_id); - opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index], codec); switch(avctx->codec_type){ case AVMEDIA_TYPE_AUDIO : is->last_audio_stream = stream_index; if(audio_codec_name ) codec= avcodec_find_decoder_by_name( audio_codec_name); break; @@ -2305,6 +2304,7 @@ static int stream_component_open(VideoState *is, int stream_index) if(codec->capabilities & CODEC_CAP_DR1) avctx->flags |= CODEC_FLAG_EMU_EDGE; + opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index], codec); if (!av_dict_get(opts, "threads", NULL, 0)) av_dict_set(&opts, "threads", "auto", 0); if (!codec || From fec39d99d63686cb70f47f33473f9607efe3c968 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 28 Oct 2012 02:22:47 +0200 Subject: [PATCH 8/8] ffplay: remove redundant !codec check Signed-off-by: Marton Balint --- ffplay.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ffplay.c b/ffplay.c index beced86493..e3b156a4f2 100644 --- a/ffplay.c +++ b/ffplay.c @@ -2307,8 +2307,7 @@ static int stream_component_open(VideoState *is, int stream_index) opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index], codec); if (!av_dict_get(opts, "threads", NULL, 0)) av_dict_set(&opts, "threads", "auto", 0); - if (!codec || - avcodec_open2(avctx, codec, &opts) < 0) + if (avcodec_open2(avctx, codec, &opts) < 0) return -1; if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) { av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);