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
82 (get_bits_left(rw) >= width && \82 (get_bits_left(rw) >= width && \
83 (var = show_bits(rw, width)) == (compare))83 (var = show_bits(rw, width)) == (compare))
84 84
85#define infer(name, value) do { \
86 current->name = value; \
87 } while (0)
88
85#include "cbs_mpeg2_syntax_template.c"89#include "cbs_mpeg2_syntax_template.c"
86 90
87#undef READ91#undef READ
@@ -91,6 +95,7 @@ · 3 unmodified lines
91#undef xsi95#undef xsi
92#undef marker_bit96#undef marker_bit
93#undef nextbits97#undef nextbits
98#undef infer
94 99
95 100
96#define WRITE101#define WRITE
@@ -116,6 +121,15 @@ · 19 unmodified lines
116 121
117#define nextbits(width, compare, var) (var)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#include "cbs_mpeg2_syntax_template.c"133#include "cbs_mpeg2_syntax_template.c"
120 134
121#undef WRITE135#undef WRITE
@@ -125,6 +139,7 @@ · 3 unmodified lines
125#undef xsi139#undef xsi
126#undef marker_bit140#undef marker_bit
127#undef nextbits141#undef nextbits
142#undef infer
128 143
129 144
130static void cbs_mpeg2_free_user_data(void *unit, uint8_t *content)145static 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
144 uir(8, transfer_characteristics);144 uir(8, transfer_characteristics);
145 uir(8, matrix_coefficients);145 uir(8, matrix_coefficients);
146#endif146#endif
147 } else {
148 infer(colour_primaries, 2);
149 infer(transfer_characteristics, 2);
150 infer(matrix_coefficients, 2);
147 }151 }
148 152
149 ui(14, display_horizontal_size);153 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
213 CodedBitstreamFragment *frag = &ctx->fragment;213 CodedBitstreamFragment *frag = &ctx->fragment;
214 int err;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 err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_MPEG2VIDEO, bsf);228 err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_MPEG2VIDEO, bsf);
217 if (err < 0)229 if (err < 0)
218 return err;230 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