Commit c90f57c6 authored by Anton Khirnov's avatar Anton Khirnov

vp9dec: factorise freeing per-tile allocated data

parent c5844096
...@@ -93,6 +93,12 @@ static void vp9_free_entries(AVCodecContext *avctx) {} ...@@ -93,6 +93,12 @@ static void vp9_free_entries(AVCodecContext *avctx) {}
static int vp9_alloc_entries(AVCodecContext *avctx, int n) { return 0; } static int vp9_alloc_entries(AVCodecContext *avctx, int n) { return 0; }
#endif #endif
static void vp9_tile_data_free(VP9TileData *td)
{
av_freep(&td->b_base);
av_freep(&td->block_base);
}
static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f) static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f)
{ {
ff_thread_release_buffer(avctx, &f->tf); ff_thread_release_buffer(avctx, &f->tf);
...@@ -281,10 +287,8 @@ static int update_size(AVCodecContext *avctx, int w, int h) ...@@ -281,10 +287,8 @@ static int update_size(AVCodecContext *avctx, int w, int h)
#undef assign #undef assign
if (s->td) { if (s->td) {
for (i = 0; i < s->active_tile_cols; i++) { for (i = 0; i < s->active_tile_cols; i++)
av_freep(&s->td[i].b_base); vp9_tile_data_free(&s->td[i]);
av_freep(&s->td[i].block_base);
}
} }
if (s->s.h.bpp != s->last_bpp) { if (s->s.h.bpp != s->last_bpp) {
...@@ -306,8 +310,7 @@ static int update_block_buffers(AVCodecContext *avctx) ...@@ -306,8 +310,7 @@ static int update_block_buffers(AVCodecContext *avctx)
if (td->b_base && td->block_base && s->block_alloc_using_2pass == s->s.frames[CUR_FRAME].uses_2pass) if (td->b_base && td->block_base && s->block_alloc_using_2pass == s->s.frames[CUR_FRAME].uses_2pass)
return 0; return 0;
av_free(td->b_base); vp9_tile_data_free(td);
av_free(td->block_base);
chroma_blocks = 64 * 64 >> (s->ss_h + s->ss_v); chroma_blocks = 64 * 64 >> (s->ss_h + s->ss_v);
chroma_eobs = 16 * 16 >> (s->ss_h + s->ss_v); chroma_eobs = 16 * 16 >> (s->ss_h + s->ss_v);
if (s->s.frames[CUR_FRAME].uses_2pass) { if (s->s.frames[CUR_FRAME].uses_2pass) {
...@@ -324,12 +327,9 @@ static int update_block_buffers(AVCodecContext *avctx) ...@@ -324,12 +327,9 @@ static int update_block_buffers(AVCodecContext *avctx)
td->uveob_base[0] = td->eob_base + 16 * 16 * sbs; td->uveob_base[0] = td->eob_base + 16 * 16 * sbs;
td->uveob_base[1] = td->uveob_base[0] + chroma_eobs * sbs; td->uveob_base[1] = td->uveob_base[0] + chroma_eobs * sbs;
} else { } else {
for (i = 1; i < s->active_tile_cols; i++) { for (i = 1; i < s->active_tile_cols; i++)
if (s->td[i].b_base && s->td[i].block_base) { vp9_tile_data_free(&s->td[i]);
av_free(s->td[i].b_base);
av_free(s->td[i].block_base);
}
}
for (i = 0; i < s->active_tile_cols; i++) { for (i = 0; i < s->active_tile_cols; i++) {
s->td[i].b_base = av_malloc(sizeof(VP9Block)); s->td[i].b_base = av_malloc(sizeof(VP9Block));
s->td[i].block_base = av_mallocz((64 * 64 + 2 * chroma_blocks) * bytesperpixel * sizeof(int16_t) + s->td[i].block_base = av_mallocz((64 * 64 + 2 * chroma_blocks) * bytesperpixel * sizeof(int16_t) +
...@@ -773,10 +773,8 @@ static int decode_frame_header(AVCodecContext *avctx, ...@@ -773,10 +773,8 @@ static int decode_frame_header(AVCodecContext *avctx,
VP56RangeCoder *rc; VP56RangeCoder *rc;
if (s->td) { if (s->td) {
for (i = 0; i < s->active_tile_cols; i++) { for (i = 0; i < s->active_tile_cols; i++)
av_free(s->td[i].b_base); vp9_tile_data_free(&s->td[i]);
av_free(s->td[i].block_base);
}
av_free(s->td); av_free(s->td);
} }
...@@ -1213,10 +1211,8 @@ static void free_buffers(VP9Context *s) ...@@ -1213,10 +1211,8 @@ static void free_buffers(VP9Context *s)
int i; int i;
av_freep(&s->intra_pred_data[0]); av_freep(&s->intra_pred_data[0]);
for (i = 0; i < s->active_tile_cols; i++) { for (i = 0; i < s->active_tile_cols; i++)
av_freep(&s->td[i].b_base); vp9_tile_data_free(&s->td[i]);
av_freep(&s->td[i].block_base);
}
} }
static av_cold int vp9_decode_free(AVCodecContext *avctx) static av_cold int vp9_decode_free(AVCodecContext *avctx)
......
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