X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Futvideoenc.c;h=8c8a9535a1ddc5877b998cb3aa5375050188037f;hb=930391e5988abe126d29c5e9b09fab459e0b8936;hp=db00e1eff5f293301cd22664ab2ab51c3898fddb;hpb=762c2b5dcd99a08452299cd1f83070f88115f1f3;p=ffmpeg diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c index db00e1eff5f..8c8a9535a1d 100644 --- a/libavcodec/utvideoenc.c +++ b/libavcodec/utvideoenc.c @@ -37,6 +37,19 @@ #include "utvideo.h" #include "huffman.h" +typedef struct HuffEntry { + uint16_t sym; + uint8_t len; + uint32_t code; +} HuffEntry; + +/* Compare huffman tree nodes */ +static int ut_huff_cmp_len(const void *a, const void *b) +{ + const HuffEntry *aa = a, *bb = b; + return (aa->len - bb->len)*256 + aa->sym - bb->sym; +} + /* Compare huffentry symbols */ static int huff_cmp_sym(const void *a, const void *b) { @@ -121,28 +134,6 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx) ff_bswapdsp_init(&c->bdsp); ff_llvidencdsp_init(&c->llvidencdsp); -#if FF_API_PRIVATE_OPT -FF_DISABLE_DEPRECATION_WARNINGS - /* Check the prediction method, and error out if unsupported */ - if (avctx->prediction_method < 0 || avctx->prediction_method > 4) { - av_log(avctx, AV_LOG_WARNING, - "Prediction method %d is not supported in Ut Video.\n", - avctx->prediction_method); - return AVERROR_OPTION_NOT_FOUND; - } - - if (avctx->prediction_method == FF_PRED_PLANE) { - av_log(avctx, AV_LOG_ERROR, - "Plane prediction is not supported in Ut Video.\n"); - return AVERROR_OPTION_NOT_FOUND; - } - - /* Convert from libavcodec prediction type to Ut Video's */ - if (avctx->prediction_method) - c->frame_pred = ff_ut_pred_order[avctx->prediction_method]; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - if (c->frame_pred == PRED_GRADIENT) { av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n"); return AVERROR_OPTION_NOT_FOUND; @@ -340,13 +331,13 @@ static void calculate_codes(HuffEntry *he) int last, i; uint32_t code; - qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len); + qsort(he, 256, sizeof(*he), ut_huff_cmp_len); last = 255; while (he[last].len == 255 && last) last--; - code = 1; + code = 0; for (i = last; i >= 0; i--) { he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1); @@ -379,13 +370,11 @@ static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size, if (count) put_bits(&pb, 32 - count, 0); - /* Get the amount of bits written */ - count = put_bits_count(&pb); - /* Flush the rest with zeroes */ flush_put_bits(&pb); - return count; + /* Return the amount of bytes written */ + return put_bytes_output(&pb); } static int encode_plane(AVCodecContext *avctx, uint8_t *src, @@ -493,11 +482,11 @@ static int encode_plane(AVCodecContext *avctx, uint8_t *src, /* * Write the huffman codes to a buffer, - * get the offset in bits and convert to bytes. + * get the offset in bytes. */ offset += write_huff_codes(dst + sstart * width, c->slice_bits, width * height + 4, width, - send - sstart, he) >> 3; + send - sstart, he); slice_len = offset - slice_len; @@ -677,7 +666,7 @@ AVCodec ff_utvideo_encoder = { .init = utvideo_encode_init, .encode2 = utvideo_encode_frame, .close = utvideo_encode_close, - .capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY, + .capabilities = AV_CODEC_CAP_FRAME_THREADS, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE