Browse code

Merge commit '96c373c7704aeb1cc1d2c275fbb5d71777665589'

* commit '96c373c7704aeb1cc1d2c275fbb5d71777665589':
lavc: Move context_model to codec private options

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>

Derek Buitenhuis authored on 2016/01/29 01:54:26
Showing 5 changed files
... ...
@@ -2575,12 +2575,11 @@ typedef struct AVCodecContext {
2575 2575
     int coder_type;
2576 2576
 #endif /* FF_API_CODER_TYPE */
2577 2577
 
2578
-    /**
2579
-     * context model
2580
-     * - encoding: Set by user.
2581
-     * - decoding: unused
2582
-     */
2578
+#if FF_API_PRIVATE_OPT
2579
+    /** @deprecated use encoder private options instead */
2580
+    attribute_deprecated
2583 2581
     int context_model;
2582
+#endif
2584 2583
 
2585 2584
 #if FF_API_MPV_OPT
2586 2585
     /**
... ...
@@ -114,6 +114,7 @@ typedef struct FFV1Context {
114 114
     int intra;
115 115
     int slice_damaged;
116 116
     int key_frame_ok;
117
+    int context_model;
117 118
 
118 119
     int bits_per_raw_sample;
119 120
     int packed_at_lsb;
... ...
@@ -373,7 +373,7 @@ static int encode_plane(FFV1Context *s, uint8_t *src, int w, int h,
373 373
                          int stride, int plane_index, int pixel_stride)
374 374
 {
375 375
     int x, y, i, ret;
376
-    const int ring_size = s->avctx->context_model ? 3 : 2;
376
+    const int ring_size = s->context_model ? 3 : 2;
377 377
     int16_t *sample[3];
378 378
     s->run_index = 0;
379 379
 
... ...
@@ -413,7 +413,7 @@ static int encode_rgb_frame(FFV1Context *s, const uint8_t *src[3],
413 413
                              int w, int h, const int stride[3])
414 414
 {
415 415
     int x, y, p, i;
416
-    const int ring_size = s->avctx->context_model ? 3 : 2;
416
+    const int ring_size = s->context_model ? 3 : 2;
417 417
     int16_t *sample[4][3];
418 418
     int lbd    = s->bits_per_raw_sample <= 8;
419 419
     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 535
                        0);
536 536
             for (j = 0; j < f->plane_count; j++) {
537 537
                 put_symbol(c, state, f->plane[j].quant_table_index, 0);
538
-                av_assert0(f->plane[j].quant_table_index == f->avctx->context_model);
538
+                av_assert0(f->plane[j].quant_table_index == f->context_model);
539 539
             }
540 540
         }
541 541
     }
... ...
@@ -821,10 +821,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
821 821
     if (s->transparency) {
822 822
         av_log(avctx, AV_LOG_WARNING, "Storing alpha plane, this will require a recent FFV1 decoder to playback!\n");
823 823
     }
824
+#if FF_API_PRIVATE_OPT
825
+FF_DISABLE_DEPRECATION_WARNINGS
826
+    if (avctx->context_model)
827
+        s->context_model = avctx->context_model;
824 828
     if (avctx->context_model > 1U) {
825 829
         av_log(avctx, AV_LOG_ERROR, "Invalid context model %d, valid values are 0 and 1\n", avctx->context_model);
826 830
         return AVERROR(EINVAL);
827 831
     }
832
+FF_ENABLE_DEPRECATION_WARNINGS
833
+#endif
828 834
 
829 835
     if (s->ac == AC_RANGE_CUSTOM_TAB) {
830 836
         for (i = 1; i < 256; i++)
... ...
@@ -860,14 +866,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
860 860
     }
861 861
     s->context_count[0] = (11 * 11 * 11        + 1) / 2;
862 862
     s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
863
-    memcpy(s->quant_table, s->quant_tables[avctx->context_model],
863
+    memcpy(s->quant_table, s->quant_tables[s->context_model],
864 864
            sizeof(s->quant_table));
865 865
 
866 866
     for (i = 0; i < s->plane_count; i++) {
867 867
         PlaneContext *const p = &s->plane[i];
868 868
 
869 869
         memcpy(p->quant_table, s->quant_table, sizeof(p->quant_table));
870
-        p->quant_table_index = avctx->context_model;
870
+        p->quant_table_index = s->context_model;
871 871
         p->context_count     = s->context_count[p->quant_table_index];
872 872
     }
873 873
 
... ...
@@ -1034,7 +1040,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs)
1034 1034
     put_symbol(c, state, (fs->slice_height+1)*f->num_v_slices / f->height-1, 0);
1035 1035
     for (j=0; j<f->plane_count; j++) {
1036 1036
         put_symbol(c, state, f->plane[j].quant_table_index, 0);
1037
-        av_assert0(f->plane[j].quant_table_index == f->avctx->context_model);
1037
+        av_assert0(f->plane[j].quant_table_index == f->context_model);
1038 1038
     }
1039 1039
     if (!f->picture.f->interlaced_frame)
1040 1040
         put_symbol(c, state, 3, 0);
... ...
@@ -1381,6 +1387,8 @@ static const AVOption options[] = {
1381 1381
             { .i64 = AC_RANGE_CUSTOM_TAB }, INT_MIN, INT_MAX, VE, "coder" },
1382 1382
         { "ac", "Range with custom table (the ac option exists for compatibility and is deprecated)", 0, AV_OPT_TYPE_CONST,
1383 1383
             { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
1384
+    { "context", "Context model", OFFSET(context_model), AV_OPT_TYPE_INT,
1385
+            { .i64 = 0 }, 0, 1, VE },
1384 1386
 
1385 1387
     { NULL }
1386 1388
 };
... ...
@@ -28,6 +28,8 @@
28 28
  * huffyuv encoder
29 29
  */
30 30
 
31
+#include "libavutil/opt.h"
32
+
31 33
 #include "avcodec.h"
32 34
 #include "huffyuv.h"
33 35
 #include "huffman.h"
... ...
@@ -237,6 +239,12 @@ FF_DISABLE_DEPRECATION_WARNINGS
237 237
     avctx->coded_frame->key_frame = 1;
238 238
 FF_ENABLE_DEPRECATION_WARNINGS
239 239
 #endif
240
+#if FF_API_PRIVATE_OPT
241
+FF_DISABLE_DEPRECATION_WARNINGS
242
+    if (avctx->context_model == 1)
243
+        s->context = avctx->context_model;
244
+FF_ENABLE_DEPRECATION_WARNINGS
245
+#endif
240 246
 
241 247
     s->bps = desc->comp[0].depth;
242 248
     s->yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
... ...
@@ -315,15 +323,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
315 315
     s->decorrelate = s->bitstream_bpp >= 24 && !s->yuv && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
316 316
     s->predictor = avctx->prediction_method;
317 317
     s->interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_ME ? 1 : 0;
318
-    if (avctx->context_model == 1) {
319
-        s->context = avctx->context_model;
318
+    if (s->context) {
320 319
         if (s->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) {
321 320
             av_log(avctx, AV_LOG_ERROR,
322 321
                    "context=1 is not compatible with "
323 322
                    "2 pass huffyuv encoding\n");
324 323
             return AVERROR(EINVAL);
325 324
         }
326
-    }else s->context= 0;
325
+    }
327 326
 
328 327
     if (avctx->codec->id == AV_CODEC_ID_HUFFYUV) {
329 328
         if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
... ...
@@ -332,7 +339,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
332 332
                    "vcodec=ffvhuff or format=422p\n");
333 333
             return AVERROR(EINVAL);
334 334
         }
335
-        if (avctx->context_model) {
335
+#if FF_API_PRIVATE_OPT
336
+        if (s->context) {
336 337
             av_log(avctx, AV_LOG_ERROR,
337 338
                    "Error: per-frame huffman tables are not supported "
338 339
                    "by huffyuv; use vcodec=ffvhuff\n");
... ...
@@ -344,6 +352,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
344 344
                    "by huffyuv; use vcodec=ffvhuff\n");
345 345
             return AVERROR(EINVAL);
346 346
         }
347
+#endif
347 348
         if (s->interlaced != ( s->height > 288 ))
348 349
             av_log(avctx, AV_LOG_INFO,
349 350
                    "using huffyuv 2.2.0 or newer interlacing flag\n");
... ...
@@ -1043,24 +1052,36 @@ static av_cold int encode_end(AVCodecContext *avctx)
1043 1043
     return 0;
1044 1044
 }
1045 1045
 
1046
-static const AVOption options[] = {
1047
-    { "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism",
1048
-      offsetof(HYuvContext, non_determ), AV_OPT_TYPE_BOOL, { .i64 = 1 },
1049
-      0, 1, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
1046
+#define OFFSET(x) offsetof(HYuvContext, x)
1047
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1048
+
1049
+#define COMMON_OPTIONS \
1050
+    { "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism", \
1051
+      OFFSET(non_determ), AV_OPT_TYPE_BOOL, { .i64 = 1 }, \
1052
+      0, 1, VE }, \
1053
+
1054
+static const AVOption normal_options[] = {
1055
+    COMMON_OPTIONS
1056
+    { NULL },
1057
+};
1058
+
1059
+static const AVOption ff_options[] = {
1060
+    COMMON_OPTIONS
1061
+    { "context", "Set per-frame huffman tables", OFFSET(context), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1050 1062
     { NULL },
1051 1063
 };
1052 1064
 
1053 1065
 static const AVClass normal_class = {
1054 1066
     .class_name = "huffyuv",
1055 1067
     .item_name  = av_default_item_name,
1056
-    .option     = options,
1068
+    .option     = normal_options,
1057 1069
     .version    = LIBAVUTIL_VERSION_INT,
1058 1070
 };
1059 1071
 
1060 1072
 static const AVClass ff_class = {
1061 1073
     .class_name = "ffvhuff",
1062 1074
     .item_name  = av_default_item_name,
1063
-    .option     = options,
1075
+    .option     = ff_options,
1064 1076
     .version    = LIBAVUTIL_VERSION_INT,
1065 1077
 };
1066 1078
 
... ...
@@ -327,7 +327,9 @@ static const AVOption avcodec_options[] = {
327 327
 {"deflate", "deflate-based coder", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CODER_TYPE_DEFLATE }, INT_MIN, INT_MAX, V|E, "coder"},
328 328
 #endif /* FF_API_UNUSED_MEMBERS */
329 329
 #endif /* FF_API_CODER_TYPE */
330
+#if FF_API_PRIVATE_OPT
330 331
 {"context", "context model", OFFSET(context_model), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
332
+#endif
331 333
 {"slice_flags", NULL, OFFSET(slice_flags), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
332 334
 #if FF_API_XVMC
333 335
 {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},