aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-01-08 14:00:14 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-01-08 14:01:22 +0100
commit9d098ea32fde75bebb170098887cb87aaf0feef2 (patch)
tree5bcf792da57a9bc85806e994ebdad931a5818b7e /libavcodec
parent9e7b477c8c751380e7f5d766f27db7d78be917ef (diff)
downloadffmpeg-9d098ea32fde75bebb170098887cb87aaf0feef2.tar.gz
avcodec/huffyuvenc: Factorize store_huffman_tables() out
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/huffyuvenc.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index dc9d770b46..36dfecd5fb 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -142,12 +142,33 @@ static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
return index;
}
+static int store_huffman_tables(HYuvContext *s, uint8_t *buf)
+{
+ int i;
+ int size = 0;
+ int count = 3;
+
+ if (s->version > 2)
+ count = 1 + s->alpha + 2*s->chroma;
+
+ for (i = 0; i < count; i++) {
+ ff_huff_gen_len_table(s->len[i], s->stats[i]);
+
+ if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0) {
+ return -1;
+ }
+
+ size += store_table(s, s->len[i], buf + size);
+ }
+ return size;
+}
+
static av_cold int encode_init(AVCodecContext *avctx)
{
HYuvContext *s = avctx->priv_data;
int i, j;
+ int ret;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
- int extradata_tables;
ff_huffyuv_common_init(avctx);
@@ -257,7 +278,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- extradata_tables = 1 + 2*s->chroma + s->alpha;
((uint8_t*)avctx->extradata)[0] = s->predictor | (s->decorrelate << 6);
((uint8_t*)avctx->extradata)[2] = s->interlaced ? 0x10 : 0x20;
if (s->context)
@@ -265,7 +285,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
if (s->version < 3) {
((uint8_t*)avctx->extradata)[1] = s->bitstream_bpp;
((uint8_t*)avctx->extradata)[3] = 0;
- extradata_tables = 3;
} else {
((uint8_t*)avctx->extradata)[1] = ((s->bps-1)<<4) | s->chroma_h_shift | (s->chroma_v_shift<<2);
if (s->chroma)
@@ -304,16 +323,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
}
}
- for (i = 0; i < extradata_tables; i++) {
- ff_huff_gen_len_table(s->len[i], s->stats[i]);
-
- if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0) {
- return -1;
- }
-
- s->avctx->extradata_size +=
- store_table(s, s->len[i], &((uint8_t*)s->avctx->extradata)[s->avctx->extradata_size]);
- }
+ ret = store_huffman_tables(s, s->avctx->extradata + s->avctx->extradata_size);
+ if (ret < 0)
+ return ret;
+ s->avctx->extradata_size += ret;
if (s->context) {
for (i = 0; i < 4; i++) {
@@ -554,17 +567,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
return ret;
if (s->context) {
- int count = 3;
-
- if (s->version > 2)
- count = 1 + s->alpha + 2*s->chroma;
-
- for (i = 0; i < count; i++) {
- ff_huff_gen_len_table(s->len[i], s->stats[i]);
- if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0)
- return -1;
- size += store_table(s, s->len[i], &pkt->data[size]);
- }
+ size = store_huffman_tables(s, pkt->data);
+ if (size < 0)
+ return size;
for (i = 0; i < 4; i++)
for (j = 0; j < 256; j++)