Commit 901f9c0a authored by Vittorio Giovara's avatar Vittorio Giovara

qtrle: Properly use AVFrame API

Rather than copying data buffers around, just add a reference to
the current frame.
Signed-off-by: 's avatarVittorio Giovara <vittorio.giovara@gmail.com>
parent 17e41cf3
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
typedef struct QtrleEncContext { typedef struct QtrleEncContext {
AVCodecContext *avctx; AVCodecContext *avctx;
int pixel_size; int pixel_size;
AVPicture previous_frame; AVFrame *previous_frame;
unsigned int max_buf_size; unsigned int max_buf_size;
/** /**
* This array will contain at ith position the value of the best RLE code * This array will contain at ith position the value of the best RLE code
...@@ -66,7 +66,7 @@ static av_cold int qtrle_encode_end(AVCodecContext *avctx) ...@@ -66,7 +66,7 @@ static av_cold int qtrle_encode_end(AVCodecContext *avctx)
{ {
QtrleEncContext *s = avctx->priv_data; QtrleEncContext *s = avctx->priv_data;
avpicture_free(&s->previous_frame); av_frame_free(&s->previous_frame);
av_free(s->rlecode_table); av_free(s->rlecode_table);
av_free(s->length_table); av_free(s->length_table);
av_free(s->skip_table); av_free(s->skip_table);
...@@ -105,7 +105,8 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx) ...@@ -105,7 +105,8 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "Error allocating memory.\n"); av_log(avctx, AV_LOG_ERROR, "Error allocating memory.\n");
return -1; return -1;
} }
if (avpicture_alloc(&s->previous_frame, avctx->pix_fmt, avctx->width, avctx->height) < 0) { s->previous_frame = av_frame_alloc();
if (!s->previous_frame) {
av_log(avctx, AV_LOG_ERROR, "Error allocating picture\n"); av_log(avctx, AV_LOG_ERROR, "Error allocating picture\n");
return -1; return -1;
} }
...@@ -146,7 +147,7 @@ static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, ui ...@@ -146,7 +147,7 @@ static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, ui
uint8_t *this_line = p-> data[0] + line*p-> linesize[0] + uint8_t *this_line = p-> data[0] + line*p-> linesize[0] +
(width - 1)*s->pixel_size; (width - 1)*s->pixel_size;
uint8_t *prev_line = s->previous_frame.data[0] + line*s->previous_frame.linesize[0] + uint8_t *prev_line = s->previous_frame->data[0] + line * s->previous_frame->linesize[0] +
(width - 1)*s->pixel_size; (width - 1)*s->pixel_size;
s->length_table[width] = 0; s->length_table[width] = 0;
...@@ -262,13 +263,13 @@ static int encode_frame(QtrleEncContext *s, const AVFrame *p, uint8_t *buf) ...@@ -262,13 +263,13 @@ static int encode_frame(QtrleEncContext *s, const AVFrame *p, uint8_t *buf)
unsigned line_size = s->avctx->width * s->pixel_size; unsigned line_size = s->avctx->width * s->pixel_size;
for (start_line = 0; start_line < s->avctx->height; start_line++) for (start_line = 0; start_line < s->avctx->height; start_line++)
if (memcmp(p->data[0] + start_line*p->linesize[0], if (memcmp(p->data[0] + start_line*p->linesize[0],
s->previous_frame.data[0] + start_line*s->previous_frame.linesize[0], s->previous_frame->data[0] + start_line * s->previous_frame->linesize[0],
line_size)) line_size))
break; break;
for (end_line=s->avctx->height; end_line > start_line; end_line--) for (end_line=s->avctx->height; end_line > start_line; end_line--)
if (memcmp(p->data[0] + (end_line - 1)*p->linesize[0], if (memcmp(p->data[0] + (end_line - 1)*p->linesize[0],
s->previous_frame.data[0] + (end_line - 1)*s->previous_frame.linesize[0], s->previous_frame->data[0] + (end_line - 1) * s->previous_frame->linesize[0],
line_size)) line_size))
break; break;
} }
...@@ -318,8 +319,12 @@ static int qtrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt, ...@@ -318,8 +319,12 @@ static int qtrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
pkt->size = encode_frame(s, pict, pkt->data); pkt->size = encode_frame(s, pict, pkt->data);
/* save the current frame */ /* save the current frame */
av_picture_copy(&s->previous_frame, (const AVPicture *)pict, av_frame_unref(s->previous_frame);
avctx->pix_fmt, avctx->width, avctx->height); ret = av_frame_ref(s->previous_frame, pict);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "cannot add reference\n");
return ret;
}
#if FF_API_CODED_FRAME #if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS FF_DISABLE_DEPRECATION_WARNINGS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment