summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-02-28 22:17:24 +0200
committerUoti Urpala <uau@mplayer2.org>2012-02-28 22:17:24 +0200
commitc3ef8607ae75c2ae93e94a5f32453c36fca558c8 (patch)
treee264635a227c7cbcae048af1606ad36675687b10
parent9f63c7f17f5c4945e050400c881a8ed1d82ff31e (diff)
downloadmpv-c3ef8607ae75c2ae93e94a5f32453c36fca558c8.tar.bz2
mpv-c3ef8607ae75c2ae93e94a5f32453c36fca558c8.tar.xz
vo_png: set AVCodecContext parameters before opening it
Instead of opening avctx in preinit() and setting paramters later, (re)open it in config() where parameters can be set first. This fixes a failure to open the codec with new libavcodec versions that check pix_fmt during avcodec_open2().
-rw-r--r--libvo/vo_png.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/libvo/vo_png.c b/libvo/vo_png.c
index da08bb379e..6e23bafd5f 100644
--- a/libvo/vo_png.c
+++ b/libvo/vo_png.c
@@ -63,8 +63,24 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
}
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression);
-
+ uninit();
+ struct AVCodec *png_codec = avcodec_find_encoder(CODEC_ID_PNG);
+ if (!png_codec)
+ goto error;
+ avctx = avcodec_alloc_context3(png_codec);
+ if (!avctx)
+ goto error;
+ avctx->width = width;
+ avctx->height = height;
+ avctx->pix_fmt = imgfmt2pixfmt(format);
+ avctx->compression_level = z_compression;
+ if (avcodec_open2(avctx, png_codec, NULL) < 0)
+ goto error;
return 0;
+
+ error:
+ uninit();
+ return -1;
}
@@ -85,9 +101,6 @@ static uint32_t draw_image(mp_image_t* mpi){
return 1;
}
- avctx->width = mpi->w;
- avctx->height = mpi->h;
- avctx->pix_fmt = imgfmt2pixfmt(mpi->imgfmt);
pic.data[0] = mpi->planes[0];
pic.linesize[0] = mpi->stride[0];
buffersize = mpi->w * mpi->h * 8;
@@ -137,8 +150,10 @@ query_format(uint32_t format)
return 0;
}
-static void uninit(void){
- avcodec_close(avctx);
+static void uninit(void)
+{
+ if (avctx)
+ avcodec_close(avctx);
av_freep(&avctx);
av_freep(&outbuffer);
outbuffer_size = 0;
@@ -165,20 +180,7 @@ static int preinit(const char *arg)
if (subopt_parse(arg, subopts) != 0) {
return -1;
}
- struct AVCodec *png_codec = avcodec_find_encoder(CODEC_ID_PNG);
- if (!png_codec)
- goto error;
- avctx = avcodec_alloc_context3(png_codec);
- if (!avctx)
- goto error;
- if (avcodec_open2(avctx, png_codec, NULL) < 0)
- goto error;
- avctx->compression_level = z_compression;
return 0;
-
- error:
- uninit();
- return -1;
}
static int control(uint32_t request, void *data)