aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-07-21 13:22:04 +0200
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2012-07-23 11:35:21 -0400
commit6c8fdfc5e51902c6011d450b7ddc94bd1fe1030e (patch)
treec434afe9b416a703b71134c34b4adc69c2bb013d /libavcodec
parent61884b9d1b6be16dbbfae6700cf8628e037ea28b (diff)
downloadffmpeg-6c8fdfc5e51902c6011d450b7ddc94bd1fe1030e.tar.gz
zerocodec: fix direct rendering.
Set picture type before calling get_buffer. This allows the DR application to make better decisions. It also fixes a resource leak in case of missing reference frames since it would call get_buffer but never release_buffer. Also use FFSWAP to ensure that the AVFrame is properly initialized in the next get_buffer (in particular that data[0] is NULL). Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de> Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/zerocodec.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c
index 487cb32797..4f43d52a6b 100644
--- a/libavcodec/zerocodec.c
+++ b/libavcodec/zerocodec.c
@@ -33,11 +33,23 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data,
AVFrame *pic = avctx->coded_frame;
AVFrame *prev_pic = &zc->previous_frame;
z_stream *zstream = &zc->zstream;
- uint8_t *prev, *dst;
+ uint8_t *prev = prev_pic->data[0], *dst;
int i, j, zret;
pic->reference = 3;
+ if (avpkt->flags & AV_PKT_FLAG_KEY) {
+ pic->key_frame = 1;
+ pic->pict_type = AV_PICTURE_TYPE_I;
+ } else {
+ if (!prev) {
+ av_log(avctx, AV_LOG_ERROR, "Missing reference frame!\n");
+ return AVERROR_INVALIDDATA;
+ }
+ pic->key_frame = 0;
+ pic->pict_type = AV_PICTURE_TYPE_P;
+ }
+
if (avctx->get_buffer(avctx, pic) < 0) {
av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
return AVERROR(ENOMEM);
@@ -53,7 +65,6 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data,
zstream->next_in = avpkt->data;
zstream->avail_in = avpkt->size;
- prev = prev_pic->data[0];
dst = pic->data[0];
/**
@@ -61,18 +72,6 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data,
* is the same as the previous frame, set it to 0.
*/
- if (avpkt->flags & AV_PKT_FLAG_KEY) {
- pic->key_frame = 1;
- pic->pict_type = AV_PICTURE_TYPE_I;
- } else {
- if (!prev) {
- av_log(avctx, AV_LOG_ERROR, "Missing reference frame!\n");
- return AVERROR_INVALIDDATA;
- }
- pic->key_frame = 0;
- pic->pict_type = AV_PICTURE_TYPE_P;
- }
-
for (i = 0; i < avctx->height; i++) {
zstream->next_out = dst;
zstream->avail_out = avctx->width << 1;
@@ -96,12 +95,13 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data,
if (prev_pic->data[0])
avctx->release_buffer(avctx, prev_pic);
- /* Store the previouse frame for use later */
- *prev_pic = *pic;
-
*data_size = sizeof(AVFrame);
*(AVFrame *)data = *pic;
+ /* Store the previous frame for use later.
+ * FFSWAP ensures that e.g. pic->data is NULLed. */
+ FFSWAP(AVFrame, *pic, *prev_pic);
+
return avpkt->size;
}