mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
vp3: Move table allocation code into a new function
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
This commit is contained in:
parent
e8dcd73058
commit
edbb0c0708
@ -1511,6 +1511,38 @@ static void render_slice(Vp3DecodeContext *s, int slice)
|
||||
vp3_draw_horiz_band(s, FFMIN((32 << s->chroma_y_shift) * (slice + 1) -16, s->height-16));
|
||||
}
|
||||
|
||||
/// Allocate tables for per-frame data in Vp3DecodeContext
|
||||
static av_cold int allocate_tables(AVCodecContext *avctx)
|
||||
{
|
||||
Vp3DecodeContext *s = avctx->priv_data;
|
||||
int y_fragment_count, c_fragment_count;
|
||||
|
||||
y_fragment_count = s->fragment_width[0] * s->fragment_height[0];
|
||||
c_fragment_count = s->fragment_width[1] * s->fragment_height[1];
|
||||
|
||||
s->superblock_coding = av_malloc(s->superblock_count);
|
||||
s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment));
|
||||
s->coded_fragment_list[0] = av_malloc(s->fragment_count * sizeof(int));
|
||||
s->dct_tokens_base = av_malloc(64*s->fragment_count * sizeof(*s->dct_tokens_base));
|
||||
s->motion_val[0] = av_malloc(y_fragment_count * sizeof(*s->motion_val[0]));
|
||||
s->motion_val[1] = av_malloc(c_fragment_count * sizeof(*s->motion_val[1]));
|
||||
|
||||
/* work out the block mapping tables */
|
||||
s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int));
|
||||
s->macroblock_coding = av_malloc(s->macroblock_count + 1);
|
||||
|
||||
if (!s->superblock_coding || !s->all_fragments || !s->dct_tokens_base ||
|
||||
!s->coded_fragment_list[0] || !s->superblock_fragments || !s->macroblock_coding ||
|
||||
!s->motion_val[0] || !s->motion_val[1]) {
|
||||
vp3_decode_end(avctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
init_block_mapping(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the ffmpeg/libavcodec API init function.
|
||||
*/
|
||||
@ -1560,7 +1592,6 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
|
||||
s->superblock_count = s->y_superblock_count + (s->c_superblock_count * 2);
|
||||
s->u_superblock_start = s->y_superblock_count;
|
||||
s->v_superblock_start = s->u_superblock_start + s->c_superblock_count;
|
||||
s->superblock_coding = av_malloc(s->superblock_count);
|
||||
|
||||
s->macroblock_width = (s->width + 15) / 16;
|
||||
s->macroblock_height = (s->height + 15) / 16;
|
||||
@ -1578,18 +1609,6 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
|
||||
s->fragment_start[1] = y_fragment_count;
|
||||
s->fragment_start[2] = y_fragment_count + c_fragment_count;
|
||||
|
||||
s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment));
|
||||
s->coded_fragment_list[0] = av_malloc(s->fragment_count * sizeof(int));
|
||||
s->dct_tokens_base = av_malloc(64*s->fragment_count * sizeof(*s->dct_tokens_base));
|
||||
s->motion_val[0] = av_malloc(y_fragment_count * sizeof(*s->motion_val[0]));
|
||||
s->motion_val[1] = av_malloc(c_fragment_count * sizeof(*s->motion_val[1]));
|
||||
|
||||
if (!s->superblock_coding || !s->all_fragments || !s->dct_tokens_base ||
|
||||
!s->coded_fragment_list[0] || !s->motion_val[0] || !s->motion_val[1]) {
|
||||
vp3_decode_end(avctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!s->theora_tables)
|
||||
{
|
||||
for (i = 0; i < 64; i++) {
|
||||
@ -1689,22 +1708,13 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
|
||||
&motion_vector_vlc_table[0][1], 2, 1,
|
||||
&motion_vector_vlc_table[0][0], 2, 1, 0);
|
||||
|
||||
/* work out the block mapping tables */
|
||||
s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int));
|
||||
s->macroblock_coding = av_malloc(s->macroblock_count + 1);
|
||||
if (!s->superblock_fragments || !s->macroblock_coding) {
|
||||
vp3_decode_end(avctx);
|
||||
return -1;
|
||||
}
|
||||
init_block_mapping(s);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
s->current_frame.data[i] = NULL;
|
||||
s->last_frame.data[i] = NULL;
|
||||
s->golden_frame.data[i] = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return allocate_tables(avctx);
|
||||
|
||||
vlc_fail:
|
||||
av_log(avctx, AV_LOG_FATAL, "Invalid huffman table\n");
|
||||
|
Loading…
Reference in New Issue
Block a user