History

avcodec/itut35: always check the provider code and country code together

ITU-T T.35 provider codes are attributed by national bodies and it's possible to have collisions across countries. This is why the country code must always be checked as well. Use if statements rather than nested switches which would be unreadable.

Maryla Ustarroz-Calonge committed 1 year ago

Commit a3ec70b1 parent 088ace34 files · +52 −78Browse files

Unified · Split

4 files
  1. libavcodec/av1dec.c +12 −20
  2. libavcodec/h2645_sei.c +9 −27
  3. libavcodec/itut35.h +16 −5
  4. libavcodec/libdav1d.c +15 −26
libavcodec/av1dec.c+12−20
@@ -965,13 +965,13 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame, · 964 unmodified lines
965965 {
966966 GetByteContext gb;
967967 AV1DecContext *s = avctx->priv_data;
968− int ret, provider_code;
968+ int ret, provider_code, country_code;
969969
970970 bytestream2_init(&gb, itut_t35->payload, itut_t35->payload_size);
971971
972972 provider_code = bytestream2_get_be16(&gb);
973− switch (provider_code) {
974− case ITU_T_T35_PROVIDER_CODE_ATSC: {
973+ country_code = itut_t35->itu_t_t35_country_code ;
974+ if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_ATSC) {
975975 uint32_t user_identifier = bytestream2_get_be32(&gb);
976976 switch (user_identifier) {
977977 case MKBETAG('G', 'A', '9', '4'): { // closed captions
@@ -997,16 +997,13 @@ FF_ENABLE_DEPRECATION_WARNINGS · 19 unmodified lines
997997 default: // ignore unsupported identifiers
998998 break;
999999 }
1000− break;
1001− }
1002− case ITU_T_T35_PROVIDER_CODE_SMTPE: {
1000+ } else if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_SMTPE) {
10031001 AVDynamicHDRPlus *hdrplus;
10041002 int provider_oriented_code = bytestream2_get_be16(&gb);
10051003 int application_identifier = bytestream2_get_byte(&gb);
10061004
1007− if (itut_t35->itu_t_t35_country_code != ITU_T_T35_COUNTRY_CODE_US ||
1008− provider_oriented_code != 1 || application_identifier != 4)
1009− break;
1005+ if (provider_oriented_code != 1 || application_identifier != 4)
1006+ return 0; // ignore
10101007
10111008 hdrplus = av_dynamic_hdr_plus_create_side_data(frame);
10121009 if (!hdrplus)
@@ -1016,28 +1013,23 @@ FF_ENABLE_DEPRECATION_WARNINGS · 3 unmodified lines
10161013 bytestream2_get_bytes_left(&gb));
10171014 if (ret < 0)
10181015 return ret;
1019− break;
1020− }
1021− case ITU_T_T35_PROVIDER_CODE_DOLBY: {
1016+ } else if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_DOLBY) {
10221017 int provider_oriented_code = bytestream2_get_be32(&gb);
1023− if (itut_t35->itu_t_t35_country_code != ITU_T_T35_COUNTRY_CODE_US ||
1024− provider_oriented_code != 0x800)
1025− break;
1018+ if (provider_oriented_code != 0x800)
1019+ return 0; // ignore
10261020
10271021 ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, gb.buffer_end - gb.buffer,
10281022 avctx->err_recognition);
10291023 if (ret < 0) {
10301024 av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
1031− break; // ignore
1025+ return 0; // ignore
10321026 }
10331027
10341028 ret = ff_dovi_attach_side_data(&s->dovi, frame);
10351029 if (ret < 0)
10361030 return ret;
1037− break;
1038− }
1039− default: // ignore unsupported provider codes
1040− break;
1031+ } else {
1032+ // ignore unsupported provider codes
10411033 }
10421034
10431035 return 0;
libavcodec/h2645_sei.c+9−27
@@ -158,20 +158,10 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, · 157 unmodified lines
158158 bytestream2_skipu(gb, 1); // itu_t_t35_country_code_extension_byte
159159 }
160160
161− if (country_code != ITU_T_T35_COUNTRY_CODE_US &&
162− country_code != ITU_T_T35_COUNTRY_CODE_UK &&
163− country_code != ITU_T_T35_COUNTRY_CODE_CN) {
164− av_log(logctx, AV_LOG_VERBOSE,
165− "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d)\n",
166− country_code);
167− return 0;
168− }
169−
170161 /* itu_t_t35_payload_byte follows */
171162 provider_code = bytestream2_get_be16u(gb);
172163
173− switch (provider_code) {
174− case ITU_T_T35_PROVIDER_CODE_ATSC: {
164+ if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_ATSC) {
175165 uint32_t user_identifier;
176166
177167 if (bytestream2_get_bytes_left(gb) < 4)
@@ -189,9 +179,7 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, · 11 unmodified lines
189179 user_identifier);
190180 break;
191181 }
192− break;
193− }
194− case ITU_T_T35_PROVIDER_CODE_LCEVC: {
182+ } else if (country_code == ITU_T_T35_COUNTRY_CODE_UK && provider_code == ITU_T_T35_PROVIDER_CODE_LCEVC) {
195183 if (bytestream2_get_bytes_left(gb) < 2)
196184 return AVERROR_INVALIDDATA;
197185
@@ -199,7 +187,7 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, · 1 unmodified line
199187 return decode_registered_user_data_lcevc(&h->lcevc, gb);
200188 }
201189 #if CONFIG_HEVC_SEI
202− case ITU_T_T35_PROVIDER_CODE_CUVA: {
190+ else if (country_code == ITU_T_T35_COUNTRY_CODE_CN && provider_code == ITU_T_T35_PROVIDER_CODE_CUVA) {
203191 const uint16_t cuva_provider_oriented_code = 0x0005;
204192 uint16_t provider_oriented_code;
205193
@@ -213,9 +201,7 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, · 7 unmodified lines
213201 if (provider_oriented_code == cuva_provider_oriented_code) {
214202 return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb);
215203 }
216− break;
217− }
218− case ITU_T_T35_PROVIDER_CODE_SMTPE: {
204+ } else if(country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_SMTPE) {
219205 // A/341 Amendment - 2094-40
220206 const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
221207 const uint8_t smpte2094_40_application_identifier = 0x04;
@@ -234,9 +220,7 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, · 12 unmodified lines
234220 application_identifier == smpte2094_40_application_identifier) {
235221 return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb);
236222 }
237− break;
238− }
239− case 0x5890: { // aom_provider_code
223+ } else if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_AOM) {
240224 const uint16_t aom_grain_provider_oriented_code = 0x0001;
241225 uint16_t provider_oriented_code;
242226
@@ -252,15 +236,13 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, · 9 unmodified lines
252236 gb->buffer,
253237 bytestream2_get_bytes_left(gb));
254238 }
255− break;
256239 }
257− unsupported_provider_code:
258240 #endif
259− default:
241+ else {
242+ unsupported_provider_code:
260243 av_log(logctx, AV_LOG_VERBOSE,
261− "Unsupported User Data Registered ITU-T T35 SEI message (provider_code = %d)\n",
262− provider_code);
263− break;
244+ "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d, provider_code = %d)\n",
245+ country_code, provider_code);
264246 }
265247
266248 return 0;
libavcodec/itut35.h+16−5
@@ -23,10 +23,21 @@ · 22 unmodified lines
2323 #define ITU_T_T35_COUNTRY_CODE_UK 0xB4
2424 #define ITU_T_T35_COUNTRY_CODE_US 0xB5
2525
26−#define ITU_T_T35_PROVIDER_CODE_ATSC 0x31
27−#define ITU_T_T35_PROVIDER_CODE_CUVA 0x04
28−#define ITU_T_T35_PROVIDER_CODE_DOLBY 0x3B
29−#define ITU_T_T35_PROVIDER_CODE_LCEVC 0x50
30−#define ITU_T_T35_PROVIDER_CODE_SMTPE 0x3C
26+// The Terminal Provider Code (or "Manufacturer Code") identifies the
27+// manufacturer within a country. An Assignment Authority appointed by the
28+// national body assigns this code nationally. The manufacturer code is always
29+// used in conjunction with a country code.
30+// - CN providers
31+#define ITU_T_T35_PROVIDER_CODE_CUVA 0x0004
32+// - UK providers
33+// V-Nova should be 0x5000 according to UK Register of Manufacturer Codes
34+// https://www.cix.co.uk/~bpechey/H221/h221code.htm
35+// but FFmpeg has been using 0x0050
36+#define ITU_T_T35_PROVIDER_CODE_LCEVC 0x0050
37+// - US providers
38+#define ITU_T_T35_PROVIDER_CODE_ATSC 0x0031
39+#define ITU_T_T35_PROVIDER_CODE_DOLBY 0x003B
40+#define ITU_T_T35_PROVIDER_CODE_AOM 0x5890
41+#define ITU_T_T35_PROVIDER_CODE_SMTPE 0x003C
3142
3243 #endif /* AVCODEC_ITUT35_H */
libavcodec/libdav1d.c+15−26
@@ -390,14 +390,14 @@ static int parse_itut_t35_metadata(Libdav1dContext *dav1d, Dav1dPicture *p, · 389 unmodified lines
390390 const Dav1dITUTT35 *itut_t35, AVCodecContext *c,
391391 AVFrame *frame) {
392392 GetByteContext gb;
393− int provider_code;
393+ int provider_code, country_code;
394394 int res;
395395
396396 bytestream2_init(&gb, itut_t35->payload, itut_t35->payload_size);
397397
398398 provider_code = bytestream2_get_be16(&gb);
399− switch (provider_code) {
400− case ITU_T_T35_PROVIDER_CODE_ATSC: {
399+ country_code = itut_t35->country_code;
400+ if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_ATSC) {
401401 uint32_t user_identifier = bytestream2_get_be32(&gb);
402402 switch (user_identifier) {
403403 case MKBETAG('G', 'A', '9', '4'): { // closed captions
@@ -407,7 +407,7 @@ static int parse_itut_t35_metadata(Libdav1dContext *dav1d, Dav1dPicture *p, · 3 unmodified lines
407407 if (res < 0)
408408 return res;
409409 if (!res)
410− break;
410+ return 0; // no cc found, ignore
411411
412412 res = ff_frame_new_side_data_from_buf(c, frame, AV_FRAME_DATA_A53_CC, &buf);
413413 if (res < 0)
@@ -423,51 +423,40 @@ FF_ENABLE_DEPRECATION_WARNINGS · 9 unmodified lines
423423 default: // ignore unsupported identifiers
424424 break;
425425 }
426− break;
427− }
428− case ITU_T_T35_PROVIDER_CODE_SMTPE: {
426+ } else if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_SMTPE) {
429427 AVDynamicHDRPlus *hdrplus;
430428 int provider_oriented_code = bytestream2_get_be16(&gb);
431429 int application_identifier = bytestream2_get_byte(&gb);
432430
433− if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US ||
434− provider_oriented_code != 1 || application_identifier != 4)
435− break;
431+ if (provider_oriented_code != 1 || application_identifier != 4)
432+ return 0; // ignore
436433
437434 hdrplus = av_dynamic_hdr_plus_create_side_data(frame);
438− if (!hdrplus) {
439− res = AVERROR(ENOMEM);
440− return res;
441− }
435+ if (!hdrplus)
436+ return AVERROR(ENOMEM);
442437
443438 res = av_dynamic_hdr_plus_from_t35(hdrplus, gb.buffer,
444439 bytestream2_get_bytes_left(&gb));
445440 if (res < 0)
446441 return res;
447− break;
448− }
449− case ITU_T_T35_PROVIDER_CODE_DOLBY: {
442+ } else if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_DOLBY) {
450443 int provider_oriented_code = bytestream2_get_be32(&gb);
451− if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US ||
452− provider_oriented_code != 0x800)
453− break;
444+ if (provider_oriented_code != 0x800)
445+ return 0; // ignore
454446
455447 res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer,
456448 c->err_recognition);
457449 if (res < 0) {
458450 av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
459− break; // ignore
451+ return 0; // ignore
460452 }
461453
462454 res = ff_dovi_attach_side_data(&dav1d->dovi, frame);
463455 if (res < 0)
464456 return res;
465− break;
457+ } else {
458+ // ignore unsupported provider codes
466459 }
467− default: // ignore unsupported provider codes
468− break;
469− }
470−
471460 return 0;
472461 }
473462

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