History

mpeg2_metadata, cbs_mpeg2: Fix handling of colour_description

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.

Andreas Rheinhardt committed 7 years ago

Commit c2a91641 parent 47b6ca03 files · +31 −0Browse files

Unified · Split

3 files
  1. libavcodec/cbs_mpeg2.c +15 −0
  2. libavcodec/cbs_mpeg2_syntax_template.c +4 −0
  3. libavcodec/mpeg2_metadata_bsf.c +12 −0
libavcodec/cbs_mpeg2.c+15−0
@@ -82,6 +82,10 @@ · 81 unmodified lines
8282 (get_bits_left(rw) >= width && \
8383 (var = show_bits(rw, width)) == (compare))
8484
85+#define infer(name, value) do { \
86+ current->name = value; \
87+ } while (0)
88+
8589 #include "cbs_mpeg2_syntax_template.c"
8690
8791 #undef READ
@@ -91,6 +95,7 @@ · 3 unmodified lines
9195 #undef xsi
9296 #undef marker_bit
9397 #undef nextbits
98+#undef infer
9499
95100
96101 #define WRITE
@@ -116,6 +121,15 @@ · 19 unmodified lines
116121
117122 #define nextbits(width, compare, var) (var)
118123
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+
119133 #include "cbs_mpeg2_syntax_template.c"
120134
121135 #undef WRITE
@@ -125,6 +139,7 @@ · 3 unmodified lines
125139 #undef xsi
126140 #undef marker_bit
127141 #undef nextbits
142+#undef infer
128143
129144
130145 static void cbs_mpeg2_free_user_data(void *unit, uint8_t *content)
libavcodec/cbs_mpeg2_syntax_template.c+4−0
@@ -144,6 +144,10 @@ static int FUNC(sequence_display_extension)(CodedBitstreamContext *ctx, RWContex · 143 unmodified lines
144144 uir(8, transfer_characteristics);
145145 uir(8, matrix_coefficients);
146146 #endif
147+ } else {
148+ infer(colour_primaries, 2);
149+ infer(transfer_characteristics, 2);
150+ infer(matrix_coefficients, 2);
147151 }
148152
149153 ui(14, display_horizontal_size);
libavcodec/mpeg2_metadata_bsf.c+12−0
@@ -213,6 +213,18 @@ static int mpeg2_metadata_init(AVBSFContext *bsf) · 212 unmodified lines
213213 CodedBitstreamFragment *frag = &ctx->fragment;
214214 int err;
215215
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+
216228 err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_MPEG2VIDEO, bsf);
217229 if (err < 0)
218230 return err;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t