Commit 5b0d4c24 authored by Derek Buitenhuis's avatar Derek Buitenhuis

Merge commit '96c373c7'

* commit '96c373c7':
  lavc: Move context_model to codec private options
Merged-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parents 0e3e3656 96c373c7
...@@ -2575,12 +2575,11 @@ typedef struct AVCodecContext { ...@@ -2575,12 +2575,11 @@ typedef struct AVCodecContext {
int coder_type; int coder_type;
#endif /* FF_API_CODER_TYPE */ #endif /* FF_API_CODER_TYPE */
/** #if FF_API_PRIVATE_OPT
* context model /** @deprecated use encoder private options instead */
* - encoding: Set by user. attribute_deprecated
* - decoding: unused
*/
int context_model; int context_model;
#endif
#if FF_API_MPV_OPT #if FF_API_MPV_OPT
/** /**
......
...@@ -114,6 +114,7 @@ typedef struct FFV1Context { ...@@ -114,6 +114,7 @@ typedef struct FFV1Context {
int intra; int intra;
int slice_damaged; int slice_damaged;
int key_frame_ok; int key_frame_ok;
int context_model;
int bits_per_raw_sample; int bits_per_raw_sample;
int packed_at_lsb; int packed_at_lsb;
......
...@@ -373,7 +373,7 @@ static int encode_plane(FFV1Context *s, uint8_t *src, int w, int h, ...@@ -373,7 +373,7 @@ static int encode_plane(FFV1Context *s, uint8_t *src, int w, int h,
int stride, int plane_index, int pixel_stride) int stride, int plane_index, int pixel_stride)
{ {
int x, y, i, ret; int x, y, i, ret;
const int ring_size = s->avctx->context_model ? 3 : 2; const int ring_size = s->context_model ? 3 : 2;
int16_t *sample[3]; int16_t *sample[3];
s->run_index = 0; s->run_index = 0;
...@@ -413,7 +413,7 @@ static int encode_rgb_frame(FFV1Context *s, const uint8_t *src[3], ...@@ -413,7 +413,7 @@ static int encode_rgb_frame(FFV1Context *s, const uint8_t *src[3],
int w, int h, const int stride[3]) int w, int h, const int stride[3])
{ {
int x, y, p, i; int x, y, p, i;
const int ring_size = s->avctx->context_model ? 3 : 2; const int ring_size = s->context_model ? 3 : 2;
int16_t *sample[4][3]; int16_t *sample[4][3];
int lbd = s->bits_per_raw_sample <= 8; int lbd = s->bits_per_raw_sample <= 8;
int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8; int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8;
...@@ -535,7 +535,7 @@ static void write_header(FFV1Context *f) ...@@ -535,7 +535,7 @@ static void write_header(FFV1Context *f)
0); 0);
for (j = 0; j < f->plane_count; j++) { for (j = 0; j < f->plane_count; j++) {
put_symbol(c, state, f->plane[j].quant_table_index, 0); put_symbol(c, state, f->plane[j].quant_table_index, 0);
av_assert0(f->plane[j].quant_table_index == f->avctx->context_model); av_assert0(f->plane[j].quant_table_index == f->context_model);
} }
} }
} }
...@@ -821,10 +821,16 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -821,10 +821,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (s->transparency) { if (s->transparency) {
av_log(avctx, AV_LOG_WARNING, "Storing alpha plane, this will require a recent FFV1 decoder to playback!\n"); av_log(avctx, AV_LOG_WARNING, "Storing alpha plane, this will require a recent FFV1 decoder to playback!\n");
} }
#if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->context_model)
s->context_model = avctx->context_model;
if (avctx->context_model > 1U) { if (avctx->context_model > 1U) {
av_log(avctx, AV_LOG_ERROR, "Invalid context model %d, valid values are 0 and 1\n", avctx->context_model); av_log(avctx, AV_LOG_ERROR, "Invalid context model %d, valid values are 0 and 1\n", avctx->context_model);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
FF_ENABLE_DEPRECATION_WARNINGS
#endif
if (s->ac == AC_RANGE_CUSTOM_TAB) { if (s->ac == AC_RANGE_CUSTOM_TAB) {
for (i = 1; i < 256; i++) for (i = 1; i < 256; i++)
...@@ -860,14 +866,14 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -860,14 +866,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
} }
s->context_count[0] = (11 * 11 * 11 + 1) / 2; s->context_count[0] = (11 * 11 * 11 + 1) / 2;
s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2; s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
memcpy(s->quant_table, s->quant_tables[avctx->context_model], memcpy(s->quant_table, s->quant_tables[s->context_model],
sizeof(s->quant_table)); sizeof(s->quant_table));
for (i = 0; i < s->plane_count; i++) { for (i = 0; i < s->plane_count; i++) {
PlaneContext *const p = &s->plane[i]; PlaneContext *const p = &s->plane[i];
memcpy(p->quant_table, s->quant_table, sizeof(p->quant_table)); memcpy(p->quant_table, s->quant_table, sizeof(p->quant_table));
p->quant_table_index = avctx->context_model; p->quant_table_index = s->context_model;
p->context_count = s->context_count[p->quant_table_index]; p->context_count = s->context_count[p->quant_table_index];
} }
...@@ -1034,7 +1040,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs) ...@@ -1034,7 +1040,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs)
put_symbol(c, state, (fs->slice_height+1)*f->num_v_slices / f->height-1, 0); put_symbol(c, state, (fs->slice_height+1)*f->num_v_slices / f->height-1, 0);
for (j=0; j<f->plane_count; j++) { for (j=0; j<f->plane_count; j++) {
put_symbol(c, state, f->plane[j].quant_table_index, 0); put_symbol(c, state, f->plane[j].quant_table_index, 0);
av_assert0(f->plane[j].quant_table_index == f->avctx->context_model); av_assert0(f->plane[j].quant_table_index == f->context_model);
} }
if (!f->picture.f->interlaced_frame) if (!f->picture.f->interlaced_frame)
put_symbol(c, state, 3, 0); put_symbol(c, state, 3, 0);
...@@ -1381,6 +1387,8 @@ static const AVOption options[] = { ...@@ -1381,6 +1387,8 @@ static const AVOption options[] = {
{ .i64 = AC_RANGE_CUSTOM_TAB }, INT_MIN, INT_MAX, VE, "coder" }, { .i64 = AC_RANGE_CUSTOM_TAB }, INT_MIN, INT_MAX, VE, "coder" },
{ "ac", "Range with custom table (the ac option exists for compatibility and is deprecated)", 0, AV_OPT_TYPE_CONST, { "ac", "Range with custom table (the ac option exists for compatibility and is deprecated)", 0, AV_OPT_TYPE_CONST,
{ .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" }, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
{ "context", "Context model", OFFSET(context_model), AV_OPT_TYPE_INT,
{ .i64 = 0 }, 0, 1, VE },
{ NULL } { NULL }
}; };
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
* huffyuv encoder * huffyuv encoder
*/ */
#include "libavutil/opt.h"
#include "avcodec.h" #include "avcodec.h"
#include "huffyuv.h" #include "huffyuv.h"
#include "huffman.h" #include "huffman.h"
...@@ -236,6 +238,12 @@ FF_DISABLE_DEPRECATION_WARNINGS ...@@ -236,6 +238,12 @@ FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1; avctx->coded_frame->key_frame = 1;
FF_ENABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS
#endif
#if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->context_model == 1)
s->context = avctx->context_model;
FF_ENABLE_DEPRECATION_WARNINGS
#endif #endif
s->bps = desc->comp[0].depth; s->bps = desc->comp[0].depth;
...@@ -315,15 +323,14 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -315,15 +323,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
s->decorrelate = s->bitstream_bpp >= 24 && !s->yuv && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR); s->decorrelate = s->bitstream_bpp >= 24 && !s->yuv && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
s->predictor = avctx->prediction_method; s->predictor = avctx->prediction_method;
s->interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_ME ? 1 : 0; s->interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_ME ? 1 : 0;
if (avctx->context_model == 1) { if (s->context) {
s->context = avctx->context_model;
if (s->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) { if (s->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"context=1 is not compatible with " "context=1 is not compatible with "
"2 pass huffyuv encoding\n"); "2 pass huffyuv encoding\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
}else s->context= 0; }
if (avctx->codec->id == AV_CODEC_ID_HUFFYUV) { if (avctx->codec->id == AV_CODEC_ID_HUFFYUV) {
if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) { if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
...@@ -332,7 +339,8 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -332,7 +339,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
"vcodec=ffvhuff or format=422p\n"); "vcodec=ffvhuff or format=422p\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
if (avctx->context_model) { #if FF_API_PRIVATE_OPT
if (s->context) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Error: per-frame huffman tables are not supported " "Error: per-frame huffman tables are not supported "
"by huffyuv; use vcodec=ffvhuff\n"); "by huffyuv; use vcodec=ffvhuff\n");
...@@ -344,6 +352,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -344,6 +352,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
"by huffyuv; use vcodec=ffvhuff\n"); "by huffyuv; use vcodec=ffvhuff\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
#endif
if (s->interlaced != ( s->height > 288 )) if (s->interlaced != ( s->height > 288 ))
av_log(avctx, AV_LOG_INFO, av_log(avctx, AV_LOG_INFO,
"using huffyuv 2.2.0 or newer interlacing flag\n"); "using huffyuv 2.2.0 or newer interlacing flag\n");
...@@ -1043,24 +1052,36 @@ static av_cold int encode_end(AVCodecContext *avctx) ...@@ -1043,24 +1052,36 @@ static av_cold int encode_end(AVCodecContext *avctx)
return 0; return 0;
} }
static const AVOption options[] = { #define OFFSET(x) offsetof(HYuvContext, x)
{ "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism", #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
offsetof(HYuvContext, non_determ), AV_OPT_TYPE_BOOL, { .i64 = 1 },
0, 1, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, #define COMMON_OPTIONS \
{ "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism", \
OFFSET(non_determ), AV_OPT_TYPE_BOOL, { .i64 = 1 }, \
0, 1, VE }, \
static const AVOption normal_options[] = {
COMMON_OPTIONS
{ NULL },
};
static const AVOption ff_options[] = {
COMMON_OPTIONS
{ "context", "Set per-frame huffman tables", OFFSET(context), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ NULL }, { NULL },
}; };
static const AVClass normal_class = { static const AVClass normal_class = {
.class_name = "huffyuv", .class_name = "huffyuv",
.item_name = av_default_item_name, .item_name = av_default_item_name,
.option = options, .option = normal_options,
.version = LIBAVUTIL_VERSION_INT, .version = LIBAVUTIL_VERSION_INT,
}; };
static const AVClass ff_class = { static const AVClass ff_class = {
.class_name = "ffvhuff", .class_name = "ffvhuff",
.item_name = av_default_item_name, .item_name = av_default_item_name,
.option = options, .option = ff_options,
.version = LIBAVUTIL_VERSION_INT, .version = LIBAVUTIL_VERSION_INT,
}; };
......
...@@ -327,7 +327,9 @@ static const AVOption avcodec_options[] = { ...@@ -327,7 +327,9 @@ static const AVOption avcodec_options[] = {
{"deflate", "deflate-based coder", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CODER_TYPE_DEFLATE }, INT_MIN, INT_MAX, V|E, "coder"}, {"deflate", "deflate-based coder", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CODER_TYPE_DEFLATE }, INT_MIN, INT_MAX, V|E, "coder"},
#endif /* FF_API_UNUSED_MEMBERS */ #endif /* FF_API_UNUSED_MEMBERS */
#endif /* FF_API_CODER_TYPE */ #endif /* FF_API_CODER_TYPE */
#if FF_API_PRIVATE_OPT
{"context", "context model", OFFSET(context_model), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"context", "context model", OFFSET(context_model), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
#endif
{"slice_flags", NULL, OFFSET(slice_flags), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, {"slice_flags", NULL, OFFSET(slice_flags), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
#if FF_API_XVMC #if FF_API_XVMC
{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment