[FFmpeg-devel] [PATCH 09/15] avformat/argo_cvg: Avoid relocations for ArgoCVGOverride

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Mar 23 04:06:17 EET 2024


The average length of the strings used here does not differ much
from the length of the longest string; therefore it makes sense
to use an array big enough for the longest string and not
a pointer to a string. This also moves this array into .rodata
(from .data.rel.ro).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavformat/argo_cvg.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/libavformat/argo_cvg.c b/libavformat/argo_cvg.c
index 5db2a85dd8..03ae6fa59e 100644
--- a/libavformat/argo_cvg.c
+++ b/libavformat/argo_cvg.c
@@ -47,13 +47,6 @@ typedef struct ArgoCVGHeader {
     uint32_t reverb; /*< Reverb flag. */
 } ArgoCVGHeader;
 
-typedef struct ArgoCVGOverride {
-    const char    *name;
-    ArgoCVGHeader header;
-    uint32_t      checksum;
-    int           sample_rate;
-} ArgoCVGOverride;
-
 typedef struct ArgoCVGDemuxContext {
     ArgoCVGHeader header;
     uint32_t      checksum;
@@ -72,12 +65,33 @@ typedef struct ArgoCVGMuxContext {
 
 #if CONFIG_ARGO_CVG_DEMUXER
 /* "Special" files that are played at a different rate. */
+//  FILE(NAME, SIZE, LOOP, REVERB, CHECKSUM, SAMPLE_RATE)
+#define OVERRIDE_FILES(FILE)                               \
+    FILE(CRYS,     23592, 0, 1, 2495499, 88200) /* Beta */ \
+    FILE(REDCRY88, 38280, 0, 1, 4134848, 88200) /* Beta */ \
+    FILE(DANLOOP1, 54744, 1, 0, 5684641, 37800) /* Beta */ \
+    FILE(PICKUP88, 12904, 0, 1, 1348091, 48000) /* Beta */ \
+    FILE(SELECT1,   5080, 0, 1,  549987, 44100) /* Beta */ \
+
+#define MAX_FILENAME_SIZE(NAME, SIZE, LOOP, REVERB, CHECKSUM, SAMPLE_RATE) \
+    MAX_SIZE_BEFORE_ ## NAME,                                  \
+    MAX_SIZE_UNTIL_ ## NAME ## _MINUS1 = FFMAX(sizeof(#NAME ".CVG"), MAX_SIZE_BEFORE_ ## NAME) - 1,
+enum {
+    OVERRIDE_FILES(MAX_FILENAME_SIZE)
+    MAX_OVERRIDE_FILENAME_SIZE
+};
+
+typedef struct ArgoCVGOverride {
+    const char    name[MAX_OVERRIDE_FILENAME_SIZE];
+    ArgoCVGHeader header;
+    uint32_t      checksum;
+    int           sample_rate;
+} ArgoCVGOverride;
+
+#define FILE(NAME, SIZE, LOOP, REVERB, CHECKSUM, SAMPLE_RATE) \
+    { #NAME ".CVG", { SIZE, LOOP, REVERB }, CHECKSUM, SAMPLE_RATE },
 static const ArgoCVGOverride overrides[] = {
-    { "CRYS.CVG",     { 23592, 0, 1 }, 2495499, 88200 }, /* Beta */
-    { "REDCRY88.CVG", { 38280, 0, 1 }, 4134848, 88200 }, /* Beta */
-    { "DANLOOP1.CVG", { 54744, 1, 0 }, 5684641, 37800 }, /* Beta */
-    { "PICKUP88.CVG", { 12904, 0, 1 }, 1348091, 48000 }, /* Beta */
-    { "SELECT1.CVG",  {  5080, 0, 1 },  549987, 44100 }, /* Beta */
+    OVERRIDE_FILES(FILE)
 };
 
 static int argo_cvg_probe(const AVProbeData *p)
-- 
2.40.1



More information about the ffmpeg-devel mailing list