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
78#define EBML_UINT_INVALID UINT64_MAX78#define EBML_UINT_INVALID UINT64_MAX
79#define EBML_INT_INVALID INT64_MAX79#define EBML_INT_INVALID INT64_MAX
80 80
81/* Block Addition Mappings */
82#define MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35 4
83
81bool ebml_is_mkv_level1_id(uint32_t id);84bool ebml_is_mkv_level1_id(uint32_t id);
82uint32_t ebml_read_id (stream_t *s);85uint32_t ebml_read_id (stream_t *s);
83uint64_t ebml_read_length (stream_t *s);86uint64_t ebml_read_length (stream_t *s);
demux/packet.c+53−3
@@ -21,11 +21,13 @@ · 20 unmodified lines
21#include <assert.h>21#include <assert.h>
22 22
23#include <libavcodec/avcodec.h>23#include <libavcodec/avcodec.h>
24#include <libavutil/hdr_dynamic_metadata.h>
24#include <libavutil/intreadwrite.h>25#include <libavutil/intreadwrite.h>
25 26
26#include "common/av_common.h"27#include "common/av_common.h"
27#include "common/common.h"28#include "common/common.h"
28#include "demux.h"29#include "demux.h"
30#include "demux/ebml.h"
29 31
30#include "packet.h"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 if (!dp->avpacket)235 if (!dp->avpacket)
234 return -1;236 return -1;
235 uint8_t *sd = av_packet_new_side_data(dp->avpacket,237
236 AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,238 switch (id) {
237 8 + size);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 if (!sd)288 if (!sd)
239 return -1;289 return -1;
240 AV_WB64(sd, id);290 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