summaryrefslogtreecommitdiffstats
path: root/libavdevice
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-07-21 17:16:01 +0200
committerStefano Sabatini <stefasab@gmail.com>2012-07-22 10:32:21 +0200
commitc0b91348fe4aec7d2245d95ccabb460a6971e361 (patch)
tree1c4f92b0a6fe945557979817ddd42431792b613f /libavdevice
parent9ce0e19ab61e99cdfe29fcce84b9f6a7f17b431c (diff)
downloadffmpeg-streaming-c0b91348fe4aec7d2245d95ccabb460a6971e361.zip
ffmpeg-streaming-c0b91348fe4aec7d2245d95ccabb460a6971e361.tar.gz
lavd/caca: create display *after* checking dither options
Avoid fastidious creation and immediate destroy of the display in case one of the dither options fails to be set. Also add NULL checks in write_trailer(), which are now necessary since the function can be called when not all the components have been initialized.
Diffstat (limited to 'libavdevice')
-rw-r--r--libavdevice/caca.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/libavdevice/caca.c b/libavdevice/caca.c
index cfbb371..173a28b 100644
--- a/libavdevice/caca.c
+++ b/libavdevice/caca.c
@@ -47,9 +47,18 @@ static int caca_write_trailer(AVFormatContext *s)
av_freep(&c->window_title);
- caca_free_dither(c->dither);
- caca_free_display(c->display);
- caca_free_canvas(c->canvas);
+ if (c->display) {
+ caca_free_display(c->display);
+ c->display = NULL;
+ }
+ if (c->dither) {
+ caca_free_dither(c->dither);
+ c->dither = NULL;
+ }
+ if (c->canvas) {
+ caca_free_canvas(c->canvas);
+ c->canvas = NULL;
+ }
return 0;
}
@@ -127,20 +136,8 @@ static int caca_write_header(AVFormatContext *s)
c->canvas = caca_create_canvas(c->window_width, c->window_height);
if (!c->canvas) {
av_log(s, AV_LOG_ERROR, "Failed to create canvas\n");
- return AVERROR(errno);
- }
-
- c->display = caca_create_display_with_driver(c->canvas, c->driver);
- if (!c->display) {
- av_log(s, AV_LOG_ERROR, "Failed to create display\n");
- list_drivers(c);
- caca_free_canvas(c->canvas);
- return AVERROR(errno);
- }
-
- if (!c->window_width || !c->window_height) {
- c->window_width = caca_get_canvas_width(c->canvas);
- c->window_height = caca_get_canvas_height(c->canvas);
+ ret = AVERROR(errno);
+ goto fail;
}
bpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[encctx->pix_fmt]);
@@ -165,6 +162,19 @@ static int caca_write_header(AVFormatContext *s)
CHECK_DITHER_OPT(charset);
CHECK_DITHER_OPT(color);
+ c->display = caca_create_display_with_driver(c->canvas, c->driver);
+ if (!c->display) {
+ av_log(s, AV_LOG_ERROR, "Failed to create display\n");
+ list_drivers(c);
+ ret = AVERROR(errno);
+ goto fail;
+ }
+
+ if (!c->window_width || !c->window_height) {
+ c->window_width = caca_get_canvas_width(c->canvas);
+ c->window_height = caca_get_canvas_height(c->canvas);
+ }
+
if (!c->window_title)
c->window_title = av_strdup(s->filename);
caca_set_display_title(c->display, c->window_title);
OpenPOWER on IntegriCloud