From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id B52B34D35D for ; Fri, 19 Dec 2025 13:06:42 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'Aq5bvNQR+HkZ3jabiwBZRXPGdt33hX/VtIzzNf6f6wE=', expected b'QOa0Rr8/ZYtfi44V4n4NppYoZFJ9fcjnUa5hJHluP14=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1766149580; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=Aq5bvNQR+HkZ3jabiwBZRXPGdt33hX/VtIzzNf6f6wE=; b=XJ4G23AkZoIbVoMJcqVhKMZ5vF2RmRS7Zca0hst8tvWZ/9ZCmxG6YO3PnTUGsBU/bYR2r zEAt4evPcEixj7BdaOonBbAQoi0RY7AVR8jk4qwMHE9OJrY6NtLBeeOaVnUOTYWJgOlDaSV wNzvWjfNvGt0MR/faqll8Cnz6XQ0s7nhJQ05ZC5yJjohac4xt2FUAq2ZC9ZmlP/bzNmmZh4 6evZ8GErLIphWAlPEqCyHPqcrB4gQqFLq8J4z3LRdRpByGRE++goVQZ4xWdaRuatGmJtEBU saZHak82sfWUzn8N0DqjQqfvEtGVTy66rdW9c+qDkcM/TZTFJUtKs7ONa/9A== Received: from [172.20.0.2] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id A7C15690A04; Fri, 19 Dec 2025 15:06:20 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1766149573; b=nBvcc1reyV25RsWi6fipyz1aPssheOhMYIASkM2QNC6X9NgtgvsYJ2U9KSeK6XWJSfKWl r36dC0Y8JqMDkBc4M0NiITAccMY8GmCunhX+/DuOqYbVtWz3qmtSMA/1R7xRP+6C/Gf4sOK 7/r9QtD7b6K96ZzxMzK0K1mAzWWUAQGTr6CUczRsNK7WwLnxFCwYXvn/KwEsaecMrIWkrA8 2wgxzPKeO5IgvA4iQh/JUwG3Raao44KaUCsjqGwh+TtW+f45sGn5oMeshbN3eYQ8QkeuFNB ATOpz+2WTuHsaZGh35KLpgGPITM2/yiR1mjHqxsYk92w9wPF0faIi7d3l66w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1766149573; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=zznppdpGazQ+25lsctEEmbUiapYuvdawENmuA/2qtjM=; b=VZoeA2U6UPcmNZQHHCyage7O/tpPRVYVWCmUWWUOWe6sFsTcAKhyYKIvM5b8Sy0SrIn+L OxODg+F+3vWjVe5w37+pjaKa5UwDREwq3/2sUFktN63lmJpXUtBKdm5W3f4IjU9Sg5t/nMP SF1iMwtO5M3InNkjlwH0buejMWY2VHj9H1hnRZhHB9UET7SUUUr2r0NP8SxQMBbh+nNQOT3 +USMOg+jjVSei6JEYhocxi4SB1LZ4tiYjL/kTncRnsx+UTg+wtIM1yB0rSPj8LYLMWqMTki +yKbrzSQrr0sMEnJG//HC1HNQJE+KQZr/YW+RRjt0JWr08ez2h1Wu8fd82mQ== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1766149564; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=QOa0Rr8/ZYtfi44V4n4NppYoZFJ9fcjnUa5hJHluP14=; b=S4d7WVe3c7szhRrk7qH0vMiFq+paUjxLeBtyDzZRwRau6vigIGzgkWzNJ4H8gNZ+ORNUI 5TzRWJ6iV3OWYs679ZXB483OZMdeN/WK9tU8wThFGqmC9WqPa1kDGVfS0z0dHN/hPTn0Khz f+WeVZCXzRoRQZ+tZN0a9DTjZPatvbP0G54uHcLcDrkxt2ycmn3ax/2mPNLo+YZHee1aZyz 4czDZpDEgyq2TdNvVUfmxd4qfOerEmwjH+GlGgz83iRJnEddXOejjQToNVBQgnEQ5YpmJVf 1BjP+p8W+PpdtIwQzXTnh5h/27kNB+smu+8NGZzHYameJHRyvBJjIEPjW5CA== Received: from 55ca25703178 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id ABAB5690941 for ; Fri, 19 Dec 2025 15:06:04 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Dec 2025 13:06:04 -0000 Message-ID: <176614956490.60.15289014832471971406@2cb04c0e5124> Message-ID-Hash: BAX25EGD7AY5XQTTDECXVHFUZD7VR4EU X-Message-ID-Hash: BAX25EGD7AY5XQTTDECXVHFUZD7VR4EU X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avformat/id3: Add macro control ID3 protocol enable (PR #21240) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: nyh163925 via ffmpeg-devel Cc: nyh163925 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21240 opened by nyh163925 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21240 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21240.patch Disabled by --disable-id3, default enabled. Turning off ID3 support when it is clear that the ID3 protocol is not needed can save approximately 11kb of code size. >>From 7ba25a716484b4bd57cdbe35eabae8eee70a4686 Mon Sep 17 00:00:00 2001 From: niyinghao Date: Fri, 19 Dec 2025 20:57:10 +0800 Subject: [PATCH] avformat/id3: Add macro control ID3 protocol enable Disabled by --disable-id3, default enabled. Turning off ID3 support when it is clear that the ID3 protocol is not needed can save approximately 11kb of code size. --- configure | 2 + libavformat/id3v1.c | 22 +++++++++- libavformat/id3v1.h | 2 +- libavformat/id3v2.c | 99 +++++++++++++++++++++++++++++++++++++++++- libavformat/id3v2enc.c | 26 +++++++++++ libavformat/mov.c | 6 ++- libavformat/mp3enc.c | 6 ++- 7 files changed, 156 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 9458a1d964..69a61f8004 100755 --- a/configure +++ b/configure @@ -2101,6 +2101,7 @@ FEATURE_LIST=" ftrapv gray hardcoded_tables + id3 omx_rpi runtime_cpudetect safe_bitstream_reader @@ -4294,6 +4295,7 @@ enable debug enable doc enable faan faandct faanidct enable iamf +enable id3 enable large_tests enable optimizations enable ptx_compression diff --git a/libavformat/id3v1.c b/libavformat/id3v1.c index 3189a48b8c..84c5a33108 100644 --- a/libavformat/id3v1.c +++ b/libavformat/id3v1.c @@ -20,10 +20,12 @@ */ #include "id3v1.h" + +#if CONFIG_ID3 #include "libavutil/dict.h" /* See Genre List at http://id3.org/id3v2.3.0 */ -const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { +const char * const id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { [0] = "Blues", [1] = "Classic Rock", [2] = "Country", @@ -218,6 +220,11 @@ const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { [191] = "Psybient" }; +const char *ff_id3v1_genre_str(int genre) +{ + return (genre < 0 || genre > ID3v1_GENRE_MAX) ? NULL : id3v1_genre_str[genre]; +} + static void get_string(AVFormatContext *s, const char *key, const uint8_t *buf, int buf_size) { @@ -271,7 +278,7 @@ static int parse_tag(AVFormatContext *s, const uint8_t *buf) } genre = buf[127]; if (genre <= ID3v1_GENRE_MAX) - av_dict_set(&s->metadata, "genre", ff_id3v1_genre_str[genre], 0); + av_dict_set(&s->metadata, "genre", ff_id3v1_genre_str(genre), 0); return 0; } @@ -294,3 +301,14 @@ void ff_id3v1_read(AVFormatContext *s) } } } +#else + +void ff_id3v1_read(AVFormatContext *s) +{ +} + +const char *ff_id3v1_genre_str(int genre) +{ + return NULL; +} +#endif diff --git a/libavformat/id3v1.h b/libavformat/id3v1.h index b3ad16df6c..837c19db58 100644 --- a/libavformat/id3v1.h +++ b/libavformat/id3v1.h @@ -31,7 +31,7 @@ /** * ID3v1 genres */ -extern const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1]; +const char *ff_id3v1_genre_str(int genre); /** * Read an ID3v1 tag diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index 9d4a9802a9..806538d41c 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -28,6 +28,7 @@ #include "config.h" +#if CONFIG_ID3 #if CONFIG_ZLIB #include #endif @@ -142,6 +143,10 @@ const CodecMime ff_id3v2_mime_tags[] = { { "PNG", AV_CODEC_ID_PNG }, /* ID3v2.2 */ { "", AV_CODEC_ID_NONE }, }; +#else +#include "avio_internal.h" +#include "id3v2.h" +#endif int ff_id3v2_match(const uint8_t *buf, const char *magic) { @@ -168,6 +173,7 @@ int ff_id3v2_tag_len(const uint8_t *buf) return len; } +#if CONFIG_ID3 static unsigned int get_size(AVIOContext *s, int len) { int v = 0; @@ -351,7 +357,7 @@ static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen, (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1) && genre <= ID3v1_GENRE_MAX) { av_freep(&dst); - dst = av_strdup(ff_id3v1_genre_str[genre]); + dst = av_strdup(ff_id3v1_genre_str(genre)); } else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) { /* dst now contains the key, need to get value */ key = dst; @@ -1266,3 +1272,94 @@ int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta) { return ff_id3v2_parse_priv_dict(&s->metadata, extra_meta); } + +#else + +static void id3v2_read_internal(AVIOContext *pb, AVDictionary **metadata, + AVFormatContext *s, const char *magic, + ID3v2ExtraMeta **extra_metap, int64_t max_search_size) +{ + uint8_t buf[ID3v2_HEADER_SIZE]; + int len, ret, found_header; + int64_t start, off, next; + + if (extra_metap) + *extra_metap = NULL; + + if (max_search_size && max_search_size < ID3v2_HEADER_SIZE) + return; + + start = avio_tell(pb); + do { + /* save the current offset in case there's nothing to read/skip */ + off = avio_tell(pb); + if (max_search_size && off - start >= max_search_size - ID3v2_HEADER_SIZE) { + avio_seek(pb, off, SEEK_SET); + break; + } + + ret = ffio_ensure_seekback(pb, ID3v2_HEADER_SIZE); + if (ret >= 0) + ret = avio_read(pb, buf, ID3v2_HEADER_SIZE); + + if (ret != ID3v2_HEADER_SIZE) { + avio_seek(pb, off, SEEK_SET); + break; + } + found_header = ff_id3v2_match(buf, magic); + if (found_header) { + /* parse ID3v2 header */ + len = ((buf[6] & 0x7f) << 21) | + ((buf[7] & 0x7f) << 14) | + ((buf[8] & 0x7f) << 7) | + (buf[9] & 0x7f); + avio_seek(pb, off + len, SEEK_SET); + } else + avio_seek(pb, off, SEEK_SET); + } while (found_header); +} + +void ff_id3v2_read_dict(AVIOContext *pb, AVDictionary **metadata, const char *magic, + ID3v2ExtraMeta **extra_meta) +{ + id3v2_read_internal(pb, metadata, NULL, magic, extra_meta, 0); +} + +void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, + unsigned int max_search_size) +{ + id3v2_read_internal(s->pb, &s->metadata, s, magic, extra_meta, max_search_size); +} + +void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta) +{ +} + +int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta) +{ + return 0; +} + +int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta *extra_meta) +{ + return 0; +} + +int ff_id3v2_parse_priv_dict(AVDictionary **d, ID3v2ExtraMeta *extra_meta) +{ + return 0; +} + +int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta) +{ + return 0; +} + +const CodecMime ff_id3v2_mime_tags[] = { + { "", AV_CODEC_ID_NONE }, +}; + +const char * const ff_id3v2_picture_types[] = { + "Other", +}; +#endif diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c index ac907c2758..6bf1b64b52 100644 --- a/libavformat/id3v2enc.c +++ b/libavformat/id3v2enc.c @@ -30,6 +30,7 @@ #include "id3v2.h" #include "mux.h" +#if CONFIG_ID3 static void id3v2_put_size(AVIOContext *pb, int size) { avio_w8(pb, size >> 21 & 0x7f); @@ -455,3 +456,28 @@ int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, return 0; } +#else +void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version, + const char *magic) +{ +} + +int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3) +{ + return 0; +} + +int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt) +{ + return 0; +} + +void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb, int padding_bytes) +{ +} + +int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, const char *magic) +{ + return 0; +} +#endif diff --git a/libavformat/mov.c b/libavformat/mov.c index 009ddfec80..19a57e3162 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -134,15 +134,17 @@ static int mov_metadata_int8_no_padding(MOVContext *c, AVIOContext *pb, static int mov_metadata_gnre(MOVContext *c, AVIOContext *pb, unsigned len, const char *key) { + const char *gnre; short genre; avio_r8(pb); // unknown genre = avio_r8(pb); - if (genre < 1 || genre > ID3v1_GENRE_MAX) + gnre = ff_id3v1_genre_str(genre - 1); + if (genre < 1 || genre > ID3v1_GENRE_MAX || !gnre) return 0; c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; - av_dict_set(&c->fc->metadata, key, ff_id3v1_genre_str[genre-1], 0); + av_dict_set(&c->fc->metadata, key, gnre, 0); return 0; } diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 724c7269dc..e3c5db5571 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -52,6 +52,7 @@ static int id3v1_set_string(AVFormatContext *s, const char *key, static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf) { AVDictionaryEntry *tag; + const char *genre; int i, count = 0; memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */ @@ -82,7 +83,10 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf) buf[127] = 0xFF; /* default to unknown genre */ if ((tag = av_dict_get(s->metadata, "TCON", NULL, 0))) { //genre for(i = 0; i <= ID3v1_GENRE_MAX; i++) { - if (!av_strcasecmp(tag->value, ff_id3v1_genre_str[i])) { + if ((genre = ff_id3v1_genre_str(i)) == NULL) + break; + + if (!av_strcasecmp(tag->value, genre)) { buf[127] = i; count++; break; -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org