[FFmpeg-devel] [PATCH 05/11] avcodec/dca: Unavpriv dca_sample_rates

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Dec 15 14:35:35 EET 2021


Said table is 64 bytes long and exported so that it can be used both
in libavcodec and libavformat. This commit stops doing so and instead
duplicates it for shared builds, because the overhead of exporting the
symbol is bigger than 64 bytes. It consists of the length of the name of
the symbol (2x24 bytes), two entries in .dynsym (2x24 bytes), two
entries for symbol version (2x2 bytes), one hash value in the exporting
library (4 bytes) in addition to one entry in the importing library's
.got and .rela.dyn (8 + 24 bytes).
(The above numbers are for a Linux/GNU/Elf system; the numbers for other
platforms may be different.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/Makefile               |  8 +++++---
 libavcodec/dca.c                  |  7 +------
 libavcodec/dca.h                  |  4 +---
 libavcodec/dca_core.c             |  2 +-
 libavcodec/dca_parser.c           |  2 +-
 libavcodec/dca_sample_rate_tab.c  | 25 +++++++++++++++++++++++
 libavcodec/dca_sample_rate_tab.h  | 33 +++++++++++++++++++++++++++++++
 libavformat/Makefile              |  1 +
 libavformat/dca_sample_rate_tab.c | 25 +++++++++++++++++++++++
 libavformat/spdifenc.c            |  2 +-
 10 files changed, 94 insertions(+), 15 deletions(-)
 create mode 100644 libavcodec/dca_sample_rate_tab.c
 create mode 100644 libavcodec/dca_sample_rate_tab.h
 create mode 100644 libavformat/dca_sample_rate_tab.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 36a1a1a4de..e4a547ffaa 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -275,7 +275,8 @@ OBJS-$(CONFIG_CSCD_DECODER)            += cscd.o
 OBJS-$(CONFIG_CYUV_DECODER)            += cyuv.o
 OBJS-$(CONFIG_DCA_DECODER)             += dcadec.o dca.o dcadata.o dcahuff.o \
                                           dca_core.o dca_exss.o dca_xll.o dca_lbr.o \
-                                          dcadsp.o dcadct.o synth_filter.o
+                                          dcadsp.o dcadct.o dca_sample_rate_tab.o \
+                                          synth_filter.o
 OBJS-$(CONFIG_DCA_ENCODER)             += dcaenc.o dcadata.o dcahuff.o \
                                           dcaadpcm.o
 OBJS-$(CONFIG_DDS_DECODER)             += dds.o
@@ -994,7 +995,6 @@ OBJS-$(CONFIG_MATROSKA_MUXER)          += mpeg4audio.o
 OBJS-$(CONFIG_MATROSKA_DEMUXER)        += mpeg4audio.o
 OBJS-$(CONFIG_NUT_MUXER)               += mpegaudiodata.o
 OBJS-$(CONFIG_RTP_MUXER)               += mpeg4audio.o
-OBJS-$(CONFIG_SPDIF_MUXER)             += dca.o
 OBJS-$(CONFIG_TAK_DEMUXER)             += tak.o
 OBJS-$(CONFIG_WEBM_MUXER)              += mpeg4audio.o
 
@@ -1003,6 +1003,7 @@ STLIBOBJS-$(CONFIG_HLS_DEMUXER)        += ac3_channel_layout_tab.o
 STLIBOBJS-$(CONFIG_MOV_DEMUXER)        += ac3_channel_layout_tab.o
 STLIBOBJS-$(CONFIG_MXF_MUXER)          += golomb.o
 STLIBOBJS-$(CONFIG_RTP_MUXER)          += golomb.o
+STLIBOBJS-$(CONFIG_SPDIF_MUXER)        += dca_sample_rate_tab.o
 
 # libavfilter dependencies
 OBJS-$(CONFIG_ELBG_FILTER)             += elbg.o
@@ -1098,7 +1099,8 @@ OBJS-$(CONFIG_BMP_PARSER)              += bmp_parser.o
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
 OBJS-$(CONFIG_COOK_PARSER)             += cook_parser.o
 OBJS-$(CONFIG_CRI_PARSER)              += cri_parser.o
-OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o dca_exss.o dca.o
+OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o dca_exss.o dca.o \
+                                          dca_sample_rate_tab.o
 OBJS-$(CONFIG_DIRAC_PARSER)            += dirac_parser.o
 OBJS-$(CONFIG_DNXHD_PARSER)            += dnxhd_parser.o dnxhddata.o
 OBJS-$(CONFIG_DOLBY_E_PARSER)          += dolby_e_parser.o dolby_e_parse.o
diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index b2152524a5..fb359b2ff3 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -33,11 +33,6 @@
 #include "get_bits.h"
 #include "put_bits.h"
 
-const uint32_t avpriv_dca_sample_rates[16] = {
-    0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
-    12000, 24000, 48000, 96000, 192000
-};
-
 const uint32_t ff_dca_sampling_freqs[16] = {
       8000,  16000, 32000, 64000, 128000, 22050,  44100,  88200,
     176400, 352800, 12000, 24000,  48000, 96000, 192000, 384000,
@@ -112,7 +107,7 @@ int ff_dca_parse_core_frame_header(DCACoreFrameHeader *h, GetBitContext *gb)
         return DCA_PARSE_ERROR_AMODE;
 
     h->sr_code = get_bits(gb, 4);
-    if (!avpriv_dca_sample_rates[h->sr_code])
+    if (!ff_dca_sample_rates[h->sr_code])
         return DCA_PARSE_ERROR_SAMPLE_RATE;
 
     h->br_code = get_bits(gb, 5);
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index e96c589c02..6be975fdfa 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -32,7 +32,6 @@
 #include "libavutil/intreadwrite.h"
 
 #include "get_bits.h"
-#include "internal.h"
 
 #define DCA_CORE_FRAME_HEADER_SIZE      18
 
@@ -195,8 +194,7 @@ enum DCADownMixType {
     DCA_DMIX_TYPE_COUNT
 };
 
-extern av_export_avcodec const uint32_t avpriv_dca_sample_rates[16];
-
+extern const uint32_t ff_dca_sample_rates[16];
 extern const uint32_t ff_dca_sampling_freqs[16];
 extern const uint8_t ff_dca_freq_ranges[16];
 extern const uint8_t ff_dca_bits_per_sample[8];
diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index f0a3c18d62..758e3447a6 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -129,7 +129,7 @@ static int parse_frame_header(DCACoreDecoder *s)
     s->npcmblocks           = h.npcmblocks;
     s->frame_size           = h.frame_size;
     s->audio_mode           = h.audio_mode;
-    s->sample_rate          = avpriv_dca_sample_rates[h.sr_code];
+    s->sample_rate          = ff_dca_sample_rates[h.sr_code];
     s->bit_rate             = ff_dca_bit_rates[h.br_code];
     s->drc_present          = h.drc_present;
     s->ts_present           = h.ts_present;
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 8b5c354312..3148397b7d 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -267,7 +267,7 @@ static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf,
         return AVERROR_INVALIDDATA;
 
     *duration = h.npcmblocks * DCA_PCMBLOCK_SAMPLES;
-    *sample_rate = avpriv_dca_sample_rates[h.sr_code];
+    *sample_rate = ff_dca_sample_rates[h.sr_code];
     if (*profile != FF_PROFILE_UNKNOWN)
         return 0;
 
diff --git a/libavcodec/dca_sample_rate_tab.c b/libavcodec/dca_sample_rate_tab.c
new file mode 100644
index 0000000000..16ee04b1d2
--- /dev/null
+++ b/libavcodec/dca_sample_rate_tab.c
@@ -0,0 +1,25 @@
+/*
+ * DCA sample rates
+ * Copyright (C) 2004 Gildas Bazin
+ * Copyright (C) 2004 Benjamin Zores
+ * Copyright (C) 2006 Benjamin Larsson
+ * Copyright (C) 2007 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dca_sample_rate_tab.h"
diff --git a/libavcodec/dca_sample_rate_tab.h b/libavcodec/dca_sample_rate_tab.h
new file mode 100644
index 0000000000..93d9a13663
--- /dev/null
+++ b/libavcodec/dca_sample_rate_tab.h
@@ -0,0 +1,33 @@
+/*
+ * DCA sample rates
+ * Copyright (C) 2004 Gildas Bazin
+ * Copyright (C) 2004 Benjamin Zores
+ * Copyright (C) 2006 Benjamin Larssonb
+ * Copyright (C) 2007 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_DCA_SAMPLE_RATE_TAB_H
+#define AVCODEC_DCA_SAMPLE_RATE_TAB_H
+#include <stdint.h>
+
+const uint32_t ff_dca_sample_rates[16] = {
+    0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
+    12000, 24000, 48000, 96000, 192000
+};
+#endif
diff --git a/libavformat/Makefile b/libavformat/Makefile
index e30d34f924..8f05b8d83c 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -682,6 +682,7 @@ SHLIBOBJS-$(CONFIG_HLS_DEMUXER)          += ac3_channel_layout_tab.o
 SHLIBOBJS-$(CONFIG_MOV_DEMUXER)          += ac3_channel_layout_tab.o
 SHLIBOBJS-$(CONFIG_MXF_MUXER)            += golomb_tab.o
 SHLIBOBJS-$(CONFIG_RTP_MUXER)            += golomb_tab.o
+SHLIBOBJS-$(CONFIG_SPDIF_MUXER)          += dca_sample_rate_tab.o
 
 # libavdevice dependencies
 OBJS-$(CONFIG_IEC61883_INDEV)            += dv.o
diff --git a/libavformat/dca_sample_rate_tab.c b/libavformat/dca_sample_rate_tab.c
new file mode 100644
index 0000000000..ed2380b0cd
--- /dev/null
+++ b/libavformat/dca_sample_rate_tab.c
@@ -0,0 +1,25 @@
+/*
+ * DCA sample rates
+ * Copyright (C) 2004 Gildas Bazin
+ * Copyright (C) 2004 Benjamin Zores
+ * Copyright (C) 2006 Benjamin Larsson
+ * Copyright (C) 2007 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/dca_sample_rate_tab.h"
diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index e8f54bff4b..3be89328df 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -263,7 +263,7 @@ static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt)
     case DCA_SYNCWORD_CORE_BE:
         blocks = (AV_RB16(pkt->data + 4) >> 2) & 0x7f;
         core_size = ((AV_RB24(pkt->data + 5) >> 4) & 0x3fff) + 1;
-        sample_rate = avpriv_dca_sample_rates[(pkt->data[8] >> 2) & 0x0f];
+        sample_rate = ff_dca_sample_rates[(pkt->data[8] >> 2) & 0x0f];
         break;
     case DCA_SYNCWORD_CORE_LE:
         blocks = (AV_RL16(pkt->data + 4) >> 2) & 0x7f;
-- 
2.32.0



More information about the ffmpeg-devel mailing list