From f2274a34e6fee1d30a1a45e7f82c582e5bea0ec1 Mon Sep 17 00:00:00 2001 From: John Koleszar <jkoleszar@google.com> Date: Mon, 14 Jun 2010 16:08:57 -0400 Subject: [PATCH] dixie: decode token partitions header Change-Id: Id894ef22c1a22a426fa4fcf3a3733711b723b9ec --- vp8/dixie/dixie.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++- vp8/dixie/dixie.h | 16 +++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/vp8/dixie/dixie.c b/vp8/dixie/dixie.c index 6f0a7ba3f5..1193104480 100644 --- a/vp8/dixie/dixie.c +++ b/vp8/dixie/dixie.c @@ -10,7 +10,6 @@ #include "vpx/internal/vpx_codec_internal.h" #include "bit_ops.h" #include "dixie.h" -#include "bool_decoder.h" #include <string.h> enum @@ -20,6 +19,47 @@ enum }; +static void +decode_and_init_token_partitions(struct vp8_decoder_ctx *ctx, + struct bool_decoder *bool, + const unsigned char *data, + unsigned int sz, + struct vp8_token_hdr *hdr) +{ + int i; + + hdr->partitions = 1 << bool_get_uint(bool, 2); + + if (sz < 3 *(hdr->partitions - 1)) + vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME, + "Truncated packet found parsing partition lengths."); + + sz -= 3 * (hdr->partitions - 1); + + for (i = 0; i < hdr->partitions; i++) + { + if (i < hdr->partitions - 1) + hdr->partition_sz[i] = (data[2] << 16) | (data[1] << 8) | data[0]; + else + hdr->partition_sz[i] = sz; + + if (sz < hdr->partition_sz[i]) + vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME, + "Truncated partition %d", i); + + data += 3; + sz -= hdr->partition_sz[i]; + } + + + for (i = 0; i < ctx->token_hdr.partitions; i++) + { + vp8dx_bool_init(&ctx->bool[i], data, ctx->token_hdr.partition_sz[i]); + data += ctx->token_hdr.partition_sz[i]; + } +} + + static void decode_loopfilter_header(struct vp8_decoder_ctx *ctx, struct bool_decoder *bool, @@ -97,6 +137,7 @@ decode_frame(struct vp8_decoder_ctx *ctx, { vpx_codec_err_t res; struct bool_decoder bool; + int i; if ((res = vp8_parse_frame_header(data, sz, &ctx->frame_hdr))) vpx_internal_error(&ctx->error, res, "Failed to parse frame header"); @@ -134,6 +175,13 @@ decode_frame(struct vp8_decoder_ctx *ctx, decode_segmentation_header(ctx, &bool, &ctx->segment_hdr); decode_loopfilter_header(ctx, &bool, &ctx->loopfilter_hdr); + decode_and_init_token_partitions(ctx, + &bool, + data + ctx->frame_hdr.part0_sz, + sz - ctx->frame_hdr.part0_sz, + &ctx->token_hdr); + + } diff --git a/vp8/dixie/dixie.h b/vp8/dixie/dixie.h index 6993135e93..67afe100fb 100644 --- a/vp8/dixie/dixie.h +++ b/vp8/dixie/dixie.h @@ -9,6 +9,7 @@ */ #ifndef DIXIE_H #define DIXIE_H +#include "bool_decoder.h" struct vp8_frame_hdr { @@ -64,6 +65,18 @@ struct vp8_loopfilter_hdr }; +enum +{ + MAX_PARTITIONS = 8 +}; + +struct vp8_token_hdr +{ + unsigned int partitions; + unsigned int partition_sz[MAX_PARTITIONS]; +}; + + struct vp8_decoder_ctx { struct vpx_internal_error_info error; @@ -71,6 +84,9 @@ struct vp8_decoder_ctx struct vp8_frame_hdr frame_hdr; struct vp8_segment_hdr segment_hdr; struct vp8_loopfilter_hdr loopfilter_hdr; + struct vp8_token_hdr token_hdr; + + struct bool_decoder bool[MAX_PARTITIONS]; }; -- GitLab