[FFmpeg-devel] [PATCH] avformat/matroskadec: parse all BlockAdditionMapping elements and export the correct value as BlockAdditional side data
James Almer
jamrial at gmail.com
Fri Apr 7 16:58:11 EEST 2023
On 4/5/2023 12:26 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> libavformat/matroskadec.c | 47 +++++++++++++++++++++++++++++++++------
> 1 file changed, 40 insertions(+), 7 deletions(-)
>
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 3c7c2b7c70..175fad6144 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2392,17 +2392,23 @@ static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, M
> MatroskaBlockAdditionMapping *mapping = &mappings[i];
>
> switch (mapping->type) {
> + case MATROSKA_BLOCK_ADD_ID_TYPE_DEFAULT:
> + av_log(s, AV_LOG_DEBUG,
> + "Explicit block Addition Mapping type \"Use BlockAddIDValue\", value %"PRIu64","
> + " name \"%s\" found.\n", mapping->value, mapping->name ? mapping->name : "");
> + break;
> + case MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE:
> case MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35:
> - if (mapping->value != MATROSKA_BLOCK_ADD_ID_ITU_T_T35) {
> + if (mapping->value != mapping->type) {
> int strict = s->strict_std_compliance >= FF_COMPLIANCE_STRICT;
> av_log(s, strict ? AV_LOG_ERROR : AV_LOG_WARNING,
> "Invalid Block Addition Value 0x%"PRIx64" for Block Addition Mapping Type "
> - "\"ITU T.35 metadata\"\n", mapping->value);
> - if (!strict)
> - break;
> - return AVERROR_INVALIDDATA;
> + "0x%"PRIx64", name \"%s\"\n", mapping->value, mapping->type,
> + mapping->name ? mapping->name : "");
> + if (strict)
> + return AVERROR_INVALIDDATA;
> }
> - track->blockaddid_itu_t_t35 = 1;
> + track->blockaddid_itu_t_t35 |= mapping->type == MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35;
> break;
> case MATROSKA_BLOCK_ADD_ID_TYPE_DVCC:
> case MATROSKA_BLOCK_ADD_ID_TYPE_DVVC:
> @@ -2412,8 +2418,18 @@ static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, M
> break;
> default:
> av_log(s, AV_LOG_DEBUG,
> - "Unknown block additional mapping type 0x%"PRIx64", value %"PRIu64", name \"%s\"\n",
> + "Unknown Block Addition Mapping type 0x%"PRIx64", value %"PRIu64", name \"%s\"\n",
> mapping->type, mapping->value, mapping->name ? mapping->name : "");
> + if (mapping->value < 2) {
> + int strict = s->strict_std_compliance >= FF_COMPLIANCE_STRICT;
> + av_log(s, strict ? AV_LOG_ERROR : AV_LOG_WARNING,
> + "Invalid Block Addition value 0x%"PRIu64" for unknown Block Addition Mapping "
> + "type %"PRIx64", name \"%s\"\n", mapping->value, mapping->type,
> + mapping->name ? mapping->name : "");
> + if (strict)
> + return AVERROR_INVALIDDATA;
> + }
> + break;
> }
> }
>
> @@ -3638,6 +3654,8 @@ static int matroska_parse_block_additional(MatroskaDemuxContext *matroska,
> MatroskaTrack *track, AVPacket *pkt,
> const uint8_t *data, int size, uint64_t id)
> {
> + const EbmlList *mappings_list = &track->block_addition_mappings;
> + MatroskaBlockAdditionMapping *mappings = mappings_list->elem, *mapping = NULL;
> uint8_t *side_data;
> int res;
>
> @@ -3685,6 +3703,21 @@ static int matroska_parse_block_additional(MatroskaDemuxContext *matroska,
> break;
> }
>
> + for (int i = 0; i < mappings_list->nb_elem; i++) {
> + if (id != mappings[i].value)
> + continue;
> + mapping = &mappings[i];
> + break;
> + }
> +
> + if (id != 1 && !matroska->is_webm && !mapping) {
> + av_log(matroska->ctx, AV_LOG_WARNING, "BlockAddID %"PRIu64" has no mapping. Skipping\n", id);
> + return 0;
> + }
> +
> + if (mapping && mapping->type)
> + id = mapping->type;
> +
> side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
> size + (size_t)8);
> if (!side_data)
Will apply.
More information about the ffmpeg-devel
mailing list