X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fproresenc_kostya.c;h=d140ef053ab5475a59bc3db1188a7b8d00013773;hb=a247ac640df3da573cd661065bf53f37863e2b46;hp=81f3865ea6ef4bcb69af63cf11077cfae7fd9f3d;hpb=5c1aafff2d844b177b0b20db4a38d8460992558b;p=ffmpeg diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 81f3865ea6e..d140ef053ab 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -23,11 +23,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mem_internal.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avcodec.h" #include "fdctdsp.h" #include "put_bits.h" +#include "profiles.h" #include "bytestream.h" #include "internal.h" #include "proresdata.h" @@ -221,6 +223,7 @@ typedef struct ProresThreadData { DECLARE_ALIGNED(16, int16_t, blocks)[MAX_PLANES][64 * 4 * MAX_MBS_PER_SLICE]; DECLARE_ALIGNED(16, uint16_t, emu_buf)[16 * 16]; int16_t custom_q[64]; + int16_t custom_chroma_q[64]; struct TrellisNode *nodes; } ProresThreadData; @@ -231,6 +234,7 @@ typedef struct ProresContext { int16_t quants[MAX_STORED_Q][64]; int16_t quants_chroma[MAX_STORED_Q][64]; int16_t custom_q[64]; + int16_t custom_chroma_q[64]; const uint8_t *quant_mat; const uint8_t *quant_chroma_mat; const uint8_t *scantable; @@ -460,23 +464,17 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, } } -static int encode_slice_plane(ProresContext *ctx, PutBitContext *pb, +static void encode_slice_plane(ProresContext *ctx, PutBitContext *pb, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int16_t *blocks, int blocks_per_mb, int plane_size_factor, const int16_t *qmat) { - int blocks_per_slice, saved_pos; - - saved_pos = put_bits_count(pb); - blocks_per_slice = mbs_per_slice * blocks_per_mb; + int blocks_per_slice = mbs_per_slice * blocks_per_mb; encode_dcs(pb, blocks, blocks_per_slice, qmat[0]); encode_acs(pb, blocks, blocks_per_slice, plane_size_factor, ctx->scantable, qmat); - flush_put_bits(pb); - - return (put_bits_count(pb) - saved_pos) >> 3; } static void put_alpha_diff(PutBitContext *pb, int cur, int prev, int abits) @@ -512,14 +510,13 @@ static void put_alpha_run(PutBitContext *pb, int run) } // todo alpha quantisation for high quants -static int encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, +static void encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, int mbs_per_slice, uint16_t *blocks, int quant) { const int abits = ctx->alpha_bits; const int mask = (1 << abits) - 1; const int num_coeffs = mbs_per_slice * 256; - int saved_pos = put_bits_count(pb); int prev = mask, cur; int idx = 0; int run = 0; @@ -540,8 +537,6 @@ static int encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, } while (idx < num_coeffs); if (run) put_alpha_run(pb, run); - flush_put_bits(pb); - return (put_bits_count(pb) - saved_pos) >> 3; } static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, @@ -573,7 +568,7 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, qmat_chroma = ctx->quants_chroma[quant]; } else { qmat = ctx->custom_q; - qmat_chroma = ctx->custom_q; + qmat_chroma = ctx->custom_chroma_q; for (i = 0; i < 64; i++) { qmat[i] = ctx->quant_mat[i] * quant; qmat_chroma[i] = ctx->quant_chroma_mat[i] * quant; @@ -607,29 +602,23 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, ctx->blocks[0], ctx->emu_buf, mbs_per_slice, num_cblocks, is_chroma); if (!is_chroma) {/* luma quant */ - sizes[i] = encode_slice_plane(ctx, pb, src, linesize, - mbs_per_slice, ctx->blocks[0], - num_cblocks, plane_factor, - qmat); + encode_slice_plane(ctx, pb, src, linesize, + mbs_per_slice, ctx->blocks[0], + num_cblocks, plane_factor, qmat); } else { /* chroma plane */ - sizes[i] = encode_slice_plane(ctx, pb, src, linesize, - mbs_per_slice, ctx->blocks[0], - num_cblocks, plane_factor, - qmat_chroma); + encode_slice_plane(ctx, pb, src, linesize, + mbs_per_slice, ctx->blocks[0], + num_cblocks, plane_factor, qmat_chroma); } } else { get_alpha_data(ctx, src, linesize, xp, yp, pwidth, avctx->height / ctx->pictures_per_frame, ctx->blocks[0], mbs_per_slice, ctx->alpha_bits); - sizes[i] = encode_alpha_plane(ctx, pb, mbs_per_slice, - ctx->blocks[0], quant); - } - total_size += sizes[i]; - if (put_bits_left(pb) < 0) { - av_log(avctx, AV_LOG_ERROR, - "Underestimated required buffer size.\n"); - return AVERROR_BUG; + encode_alpha_plane(ctx, pb, mbs_per_slice, ctx->blocks[0], quant); } + flush_put_bits(pb); + sizes[i] = put_bytes_output(pb) - total_size; + total_size = put_bytes_output(pb); } return total_size; } @@ -901,7 +890,7 @@ static int find_slice_quant(AVCodecContext *avctx, qmat_chroma = ctx->quants_chroma[q]; } else { qmat = td->custom_q; - qmat_chroma = td->custom_q; + qmat_chroma = td->custom_chroma_q; for (i = 0; i < 64; i++) { qmat[i] = ctx->quant_mat[i] * q; qmat_chroma[i] = ctx->quant_chroma_mat[i] * q; @@ -1190,12 +1179,6 @@ static av_cold int encode_init(AVCodecContext *avctx) int interlaced = !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT); avctx->bits_per_raw_sample = 10; -#if FF_API_CODED_FRAME -FF_DISABLE_DEPRECATION_WARNINGS - avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; - avctx->coded_frame->key_frame = 1; -FF_ENABLE_DEPRECATION_WARNINGS -#endif ctx->fdct = prores_fdct; ctx->scantable = interlaced ? ff_prores_interlaced_scan @@ -1387,7 +1370,7 @@ static const AVOption options[] = { { "4444xq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_4444XQ }, 0, 0, VE, "profile" }, { "vendor", "vendor ID", OFFSET(vendor), - AV_OPT_TYPE_STRING, { .str = "Lavc" }, CHAR_MIN, CHAR_MAX, VE }, + AV_OPT_TYPE_STRING, { .str = "Lavc" }, 0, 0, VE }, { "bits_per_mb", "desired bits per macroblock", OFFSET(bits_per_mb), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8192, VE }, { "quant_mat", "quantiser matrix", OFFSET(quant_sel), AV_OPT_TYPE_INT, @@ -1416,7 +1399,7 @@ static const AVClass proresenc_class = { .version = LIBAVUTIL_VERSION_INT, }; -AVCodec ff_prores_ks_encoder = { +const AVCodec ff_prores_ks_encoder = { .name = "prores_ks", .long_name = NULL_IF_CONFIG_SMALL("Apple ProRes (iCodec Pro)"), .type = AVMEDIA_TYPE_VIDEO, @@ -1425,10 +1408,11 @@ AVCodec ff_prores_ks_encoder = { .init = encode_init, .close = encode_close, .encode2 = encode_frame, - .capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY, + .capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_NONE }, .priv_class = &proresenc_class, + .profiles = NULL_IF_CONFIG_SMALL(ff_prores_profiles), };