[FFmpeg-cvslog] xxan: make code independent of sizeof(AVFrame)
Michael Niedermayer
git at videolan.org
Mon Mar 25 17:41:14 CET 2013
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Mar 24 15:14:17 2013 +0100| [67607e20e882eb5639a4e9099caecb52a863ab68] | committer: Michael Niedermayer
xxan: make code independent of sizeof(AVFrame)
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=67607e20e882eb5639a4e9099caecb52a863ab68
---
libavcodec/xxan.c | 54 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 31 insertions(+), 23 deletions(-)
diff --git a/libavcodec/xxan.c b/libavcodec/xxan.c
index e2b1b8c..cb913da 100644
--- a/libavcodec/xxan.c
+++ b/libavcodec/xxan.c
@@ -30,7 +30,7 @@
typedef struct XanContext {
AVCodecContext *avctx;
- AVFrame pic;
+ AVFrame *pic;
uint8_t *y_buffer;
uint8_t *scratch_buffer;
@@ -38,6 +38,8 @@ typedef struct XanContext {
GetByteContext gb;
} XanContext;
+static av_cold int xan_decode_end(AVCodecContext *avctx);
+
static av_cold int xan_decode_init(AVCodecContext *avctx)
{
XanContext *s = avctx->priv_data;
@@ -57,7 +59,13 @@ static av_cold int xan_decode_init(AVCodecContext *avctx)
return AVERROR(ENOMEM);
s->scratch_buffer = av_malloc(s->buffer_size + 130);
if (!s->scratch_buffer) {
- av_freep(&s->y_buffer);
+ xan_decode_end(avctx);
+ return AVERROR(ENOMEM);
+ }
+
+ s->pic = av_frame_alloc();
+ if (!s->pic) {
+ xan_decode_end(avctx);
return AVERROR(ENOMEM);
}
@@ -195,8 +203,8 @@ static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)
return dec_size;
}
- U = s->pic.data[1];
- V = s->pic.data[2];
+ U = s->pic->data[1];
+ V = s->pic->data[2];
src = s->scratch_buffer;
src_end = src + dec_size;
if (mode) {
@@ -215,16 +223,16 @@ static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)
V[i] = vval | (vval >> 5);
}
}
- U += s->pic.linesize[1];
- V += s->pic.linesize[2];
+ U += s->pic->linesize[1];
+ V += s->pic->linesize[2];
}
if (avctx->height & 1) {
- memcpy(U, U - s->pic.linesize[1], avctx->width >> 1);
- memcpy(V, V - s->pic.linesize[2], avctx->width >> 1);
+ memcpy(U, U - s->pic->linesize[1], avctx->width >> 1);
+ memcpy(V, V - s->pic->linesize[2], avctx->width >> 1);
}
} else {
- uint8_t *U2 = U + s->pic.linesize[1];
- uint8_t *V2 = V + s->pic.linesize[2];
+ uint8_t *U2 = U + s->pic->linesize[1];
+ uint8_t *V2 = V + s->pic->linesize[2];
for (j = 0; j < avctx->height >> 2; j++) {
for (i = 0; i < avctx->width >> 1; i += 2) {
@@ -241,16 +249,16 @@ static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)
V[i] = V[i+1] = V2[i] = V2[i+1] = vval | (vval >> 5);
}
}
- U += s->pic.linesize[1] * 2;
- V += s->pic.linesize[2] * 2;
- U2 += s->pic.linesize[1] * 2;
- V2 += s->pic.linesize[2] * 2;
+ U += s->pic->linesize[1] * 2;
+ V += s->pic->linesize[2] * 2;
+ U2 += s->pic->linesize[1] * 2;
+ V2 += s->pic->linesize[2] * 2;
}
if (avctx->height & 3) {
int lines = ((avctx->height + 1) >> 1) - (avctx->height >> 2) * 2;
- memcpy(U, U - lines * s->pic.linesize[1], lines * s->pic.linesize[1]);
- memcpy(V, V - lines * s->pic.linesize[2], lines * s->pic.linesize[2]);
+ memcpy(U, U - lines * s->pic->linesize[1], lines * s->pic->linesize[1]);
+ memcpy(V, V - lines * s->pic->linesize[2], lines * s->pic->linesize[2]);
}
}
@@ -327,12 +335,12 @@ static int xan_decode_frame_type0(AVCodecContext *avctx)
}
src = s->y_buffer;
- ybuf = s->pic.data[0];
+ ybuf = s->pic->data[0];
for (j = 0; j < avctx->height; j++) {
for (i = 0; i < avctx->width; i++)
ybuf[i] = (src[i] << 2) | (src[i] >> 3);
src += avctx->width;
- ybuf += s->pic.linesize[0];
+ ybuf += s->pic->linesize[0];
}
return 0;
@@ -373,12 +381,12 @@ static int xan_decode_frame_type1(AVCodecContext *avctx)
}
src = s->y_buffer;
- ybuf = s->pic.data[0];
+ ybuf = s->pic->data[0];
for (j = 0; j < avctx->height; j++) {
for (i = 0; i < avctx->width; i++)
ybuf[i] = (src[i] << 2) | (src[i] >> 3);
src += avctx->width;
- ybuf += s->pic.linesize[0];
+ ybuf += s->pic->linesize[0];
}
return 0;
@@ -392,7 +400,7 @@ static int xan_decode_frame(AVCodecContext *avctx,
int ftype;
int ret;
- if ((ret = ff_reget_buffer(avctx, &s->pic)) < 0)
+ if ((ret = ff_reget_buffer(avctx, s->pic)) < 0)
return ret;
bytestream2_init(&s->gb, avpkt->data, avpkt->size);
@@ -411,7 +419,7 @@ static int xan_decode_frame(AVCodecContext *avctx,
if (ret)
return ret;
- if ((ret = av_frame_ref(data, &s->pic)) < 0)
+ if ((ret = av_frame_ref(data, s->pic)) < 0)
return ret;
*got_frame = 1;
@@ -423,7 +431,7 @@ static av_cold int xan_decode_end(AVCodecContext *avctx)
{
XanContext *s = avctx->priv_data;
- av_frame_unref(&s->pic);
+ av_frame_free(&s->pic);
av_freep(&s->y_buffer);
av_freep(&s->scratch_buffer);
More information about the ffmpeg-cvslog
mailing list