This gives some gains, but would probably be nicer if it leveraged the type system by defining a specific type for 12-byte keys so there can be no accidental mixup
/Tomas
From 367a59ac08624326841bfbecbb5cffb664567d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <g...@haerdin.se> Date: Sat, 14 Sep 2024 11:48:45 +0200 Subject: [PATCH 2/5] lavf/mxfdec: Add and use IS_KLV_KEY_FAST() in some places --- libavformat/mxfdec.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 99bf352e00..5fe6918353 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -376,6 +376,8 @@ static const uint8_t mxf_mastering_display_uls[4][16] = { }; #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y))) +// IS_KLV_KEY_FAST can be used when we know the first four bytes are mxf_klv_key +#define IS_KLV_KEY_FAST(x, y) (!memcmp(&x[4], &y[4], sizeof(y) - 4)) static void mxf_free_metadataset(MXFMetadataSet **ctx, enum MXFMetadataSetType type) { @@ -3740,7 +3742,7 @@ static int mxf_read_header(AVFormatContext *s) size_t x; ret = klv_read_packet(mxf, &klv, s->pb); - if (ret < 0 || IS_KLV_KEY(klv.key, ff_mxf_random_index_pack_key)) { + if (ret < 0 || IS_KLV_KEY_FAST(klv.key, ff_mxf_random_index_pack_key)) { if (ret >= 0 && avio_size(s->pb) > klv.next_klv) av_log(s, AV_LOG_WARNING, "data after the RandomIndexPack, assuming end of file\n"); /* EOF - seek to previous partition or stop */ @@ -3753,11 +3755,11 @@ static int mxf_read_header(AVFormatContext *s) PRINT_KEY(s, "read header", klv.key); av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset); if (mxf_match_uid(klv.key, mxf_encrypted_triplet_key, sizeof(mxf_encrypted_triplet_key)) || - IS_KLV_KEY(klv.key, mxf_essence_element_key) || - IS_KLV_KEY(klv.key, mxf_canopus_essence_element_key) || - IS_KLV_KEY(klv.key, mxf_avid_essence_element_key) || - IS_KLV_KEY(klv.key, mxf_system_item_key_cp) || - IS_KLV_KEY(klv.key, mxf_system_item_key_gc)) { + IS_KLV_KEY_FAST(klv.key, mxf_essence_element_key) || + IS_KLV_KEY_FAST(klv.key, mxf_canopus_essence_element_key) || + IS_KLV_KEY_FAST(klv.key, mxf_avid_essence_element_key) || + IS_KLV_KEY_FAST(klv.key, mxf_system_item_key_cp) || + IS_KLV_KEY_FAST(klv.key, mxf_system_item_key_gc)) { if (!mxf->current_partition) { av_log(mxf->fc, AV_LOG_ERROR, "found essence prior to first PartitionPack\n"); @@ -3785,7 +3787,7 @@ static int mxf_read_header(AVFormatContext *s) for (x = 0; x < FF_ARRAY_ELEMS(mxf_metadata_read_table); x++) { const MXFMetadataReadTableEntry *metadata = &mxf_metadata_read_table[x]; - if (IS_KLV_KEY(klv.key, metadata->key)) { + if (IS_KLV_KEY_FAST(klv.key, metadata->key)) { if (metadata->read) { if ((ret = mxf_parse_klv(mxf, klv, metadata->read, metadata->ctx_size, metadata->type)) < 0) return ret; @@ -4015,9 +4017,9 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) klv = mxf->current_klv_data; max_data_size = klv.next_klv - pos; } - if (IS_KLV_KEY(klv.key, mxf_essence_element_key) || - IS_KLV_KEY(klv.key, mxf_canopus_essence_element_key) || - IS_KLV_KEY(klv.key, mxf_avid_essence_element_key)) { + if (IS_KLV_KEY_FAST(klv.key, mxf_essence_element_key) || + IS_KLV_KEY_FAST(klv.key, mxf_canopus_essence_element_key) || + IS_KLV_KEY_FAST(klv.key, mxf_avid_essence_element_key)) { int body_sid = find_body_sid_by_absolute_offset(mxf, klv.offset); int index = mxf_get_stream_index(s, &klv, body_sid); int64_t next_ofs; -- 2.39.2
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".