History

demux/packet: add support for ITU T.35 metadata in Matroska

Kacper Michajłow committed 2 years ago

Commit b68c7421 parent 4f828672 files · +56 −3Browse files

Unified · Split

2 files
  1. demux/ebml.h +3 −0
  2. demux/packet.c +53 −3
demux/ebml.h+3−0
@@ -78,6 +78,9 @@ struct ebml_parse_ctx { · 77 unmodified lines
7878 #define EBML_UINT_INVALID UINT64_MAX
7979 #define EBML_INT_INVALID INT64_MAX
8080
81+/* Block Addition Mappings */
82+#define MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35 4
83+
8184 bool ebml_is_mkv_level1_id(uint32_t id);
8285 uint32_t ebml_read_id (stream_t *s);
8386 uint64_t ebml_read_length (stream_t *s);
demux/packet.c+53−3
@@ -21,11 +21,13 @@ · 20 unmodified lines
2121 #include <assert.h>
2222
2323 #include <libavcodec/avcodec.h>
24+#include <libavutil/hdr_dynamic_metadata.h>
2425 #include <libavutil/intreadwrite.h>
2526
2627 #include "common/av_common.h"
2728 #include "common/common.h"
2829 #include "demux.h"
30+#include "demux/ebml.h"
2931
3032 #include "packet.h"
3133
@@ -232,9 +234,57 @@ int demux_packet_add_blockadditional(struct demux_packet *dp, uint64_t id, · 200 unmodified lines
232234 {
233235 if (!dp->avpacket)
234236 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);
238288 if (!sd)
239289 return -1;
240290 AV_WB64(sd, id);

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