| @@ -21,11 +21,13 @@ · 20 unmodified lines |
| 21 | 21 | #include <assert.h> |
| 22 | 22 | |
| 23 | 23 | #include <libavcodec/avcodec.h> |
| 24 | +#include <libavutil/hdr_dynamic_metadata.h> |
| 24 | 25 | #include <libavutil/intreadwrite.h> |
| 25 | 26 | |
| 26 | 27 | #include "common/av_common.h" |
| 27 | 28 | #include "common/common.h" |
| 28 | 29 | #include "demux.h" |
| 30 | +#include "demux/ebml.h" |
| 29 | 31 | |
| 30 | 32 | #include "packet.h" |
| 31 | 33 | |
| @@ -232,9 +234,57 @@ int demux_packet_add_blockadditional(struct demux_packet *dp, uint64_t id, · 200 unmodified lines |
| 232 | 234 | { |
| 233 | 235 | if (!dp->avpacket) |
| 234 | 236 | return -1; |
| 235 | | − uint8_t *sd = av_packet_new_side_data(dp->avpacket, |
| 236 | | − AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, |
| 237 | | − 8 + size); |
| 237 | + |
| 238 | + switch (id) { |
| 239 | +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 5, 100) |
| 240 | + case MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35: { |
| 241 | + static const uint8_t ITU_T_T35_COUNTRY_CODE_US = 0xB5; |
| 242 | + static const uint16_t ITU_T_T35_PROVIDER_CODE_SMTPE = 0x3C; |
| 243 | + |
| 244 | + if (size < 6) |
| 245 | + break; |
| 246 | + |
| 247 | + uint8_t *p = data; |
| 248 | + |
| 249 | + uint8_t country_code = AV_RB8(p); |
| 250 | + p += sizeof(country_code); |
| 251 | + uint16_t provider_code = AV_RB16(p); |
| 252 | + p += sizeof(provider_code); |
| 253 | + |
| 254 | + if (country_code != ITU_T_T35_COUNTRY_CODE_US || |
| 255 | + provider_code != ITU_T_T35_PROVIDER_CODE_SMTPE) |
| 256 | + break; |
| 257 | + |
| 258 | + uint16_t provider_oriented_code = AV_RB16(p); |
| 259 | + p += sizeof(provider_oriented_code); |
| 260 | + uint8_t application_identifier = AV_RB8(p); |
| 261 | + p += sizeof(application_identifier); |
| 262 | + |
| 263 | + if (provider_oriented_code != 1 || application_identifier != 4) |
| 264 | + break; |
| 265 | + |
| 266 | + size_t hdrplus_size; |
| 267 | + AVDynamicHDRPlus *hdrplus = av_dynamic_hdr_plus_alloc(&hdrplus_size); |
| 268 | + MP_HANDLE_OOM(hdrplus); |
| 269 | + |
| 270 | + if (av_dynamic_hdr_plus_from_t35(hdrplus, p, size - (p - (uint8_t *)data)) < 0 || |
| 271 | + av_packet_add_side_data(dp->avpacket, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, |
| 272 | + (uint8_t *)hdrplus, hdrplus_size) < 0) |
| 273 | + { |
| 274 | + av_free(hdrplus); |
| 275 | + return -1; |
| 276 | + } |
| 277 | + |
| 278 | + return 0; |
| 279 | + } |
| 280 | +#endif |
| 281 | + default: |
| 282 | + break; |
| 283 | + } |
| 284 | + |
| 285 | + uint8_t *sd = av_packet_new_side_data(dp->avpacket, |
| 286 | + AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, |
| 287 | + 8 + size); |
| 238 | 288 | if (!sd) |
| 239 | 289 | return -1; |
| 240 | 290 | AV_WB64(sd, id); |