If a sequence display extension is read with colour_description equal to zero, but a user wants to add one or more of the colour_description elements, then the colour_description elements the user did not explicitly request to be set are set to zero and not to the value equal to unknown/unspecified (namely 2). A value of zero is not only inappropriate, but explicitly forbidden. This is fixed by inferring the right default values during the reading process if the elements are absent; moreover, changing any of the colour_description elements to zero is now no longer possible.
Unified · Split
| @@ -82,6 +82,10 @@ · 81 unmodified lines | ||
| 82 | 82 | (get_bits_left(rw) >= width && \ |
| 83 | 83 | (var = show_bits(rw, width)) == (compare)) |
| 84 | 84 | |
| 85 | +#define infer(name, value) do { \ | |
| 86 | + current->name = value; \ | |
| 87 | + } while (0) | |
| 88 | + | |
| 85 | 89 | #include "cbs_mpeg2_syntax_template.c" |
| 86 | 90 | |
| 87 | 91 | #undef READ |
| @@ -91,6 +95,7 @@ · 3 unmodified lines | ||
| 91 | 95 | #undef xsi |
| 92 | 96 | #undef marker_bit |
| 93 | 97 | #undef nextbits |
| 98 | +#undef infer | |
| 94 | 99 | |
| 95 | 100 | |
| 96 | 101 | #define WRITE |
| @@ -116,6 +121,15 @@ · 19 unmodified lines | ||
| 116 | 121 | |
| 117 | 122 | #define nextbits(width, compare, var) (var) |
| 118 | 123 | |
| 124 | +#define infer(name, value) do { \ | |
| 125 | + if (current->name != (value)) { \ | |
| 126 | + av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \ | |
| 127 | + "%s does not match inferred value: " \ | |
| 128 | + "%"PRId64", but should be %"PRId64".\n", \ | |
| 129 | + #name, (int64_t)current->name, (int64_t)(value)); \ | |
| 130 | + } \ | |
| 131 | + } while (0) | |
| 132 | + | |
| 119 | 133 | #include "cbs_mpeg2_syntax_template.c" |
| 120 | 134 | |
| 121 | 135 | #undef WRITE |
| @@ -125,6 +139,7 @@ · 3 unmodified lines | ||
| 125 | 139 | #undef xsi |
| 126 | 140 | #undef marker_bit |
| 127 | 141 | #undef nextbits |
| 142 | +#undef infer | |
| 128 | 143 | |
| 129 | 144 | |
| 130 | 145 | static void cbs_mpeg2_free_user_data(void *unit, uint8_t *content) |
| @@ -144,6 +144,10 @@ static int FUNC(sequence_display_extension)(CodedBitstreamContext *ctx, RWContex · 143 unmodified lines | ||
| 144 | 144 | uir(8, transfer_characteristics); |
| 145 | 145 | uir(8, matrix_coefficients); |
| 146 | 146 | #endif |
| 147 | + } else { | |
| 148 | + infer(colour_primaries, 2); | |
| 149 | + infer(transfer_characteristics, 2); | |
| 150 | + infer(matrix_coefficients, 2); | |
| 147 | 151 | } |
| 148 | 152 | |
| 149 | 153 | ui(14, display_horizontal_size); |
| @@ -213,6 +213,18 @@ static int mpeg2_metadata_init(AVBSFContext *bsf) · 212 unmodified lines | ||
| 213 | 213 | CodedBitstreamFragment *frag = &ctx->fragment; |
| 214 | 214 | int err; |
| 215 | 215 | |
| 216 | +#define VALIDITY_CHECK(name) do { \ | |
| 217 | + if (!ctx->name) { \ | |
| 218 | + av_log(bsf, AV_LOG_ERROR, "The value 0 for %s is " \ | |
| 219 | + "forbidden.\n", #name); \ | |
| 220 | + return AVERROR(EINVAL); \ | |
| 221 | + } \ | |
| 222 | + } while (0) | |
| 223 | + VALIDITY_CHECK(colour_primaries); | |
| 224 | + VALIDITY_CHECK(transfer_characteristics); | |
| 225 | + VALIDITY_CHECK(matrix_coefficients); | |
| 226 | +#undef VALIDITY_CHECK | |
| 227 | + | |
| 216 | 228 | err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_MPEG2VIDEO, bsf); |
| 217 | 229 | if (err < 0) |
| 218 | 230 | return err; |