summaryrefslogtreecommitdiff
path: root/libavcodec/vorbisenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-07 02:51:41 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-12 06:00:14 +0200
commit65462185721e3686e27f22e952485ffc4ebd6f97 (patch)
tree30d7ae3583342821c963d626b5a49a7071ab3c93 /libavcodec/vorbisenc.c
parente1e59d738386e50591b5413dd26b44da9e2818ec (diff)
downloadffmpeg-65462185721e3686e27f22e952485ffc4ebd6f97.tar.gz
avcodec/vorbisenc: Combine codebooks, avoid relocations
The Vorbis encoder has an array of a structure containing all the ingredients for a codebook; this includes a pointer to the actual codebook and some even have a pointer to an array containing quant values. Each of these real codebooks is an array of its own. These pointers lead to relocations and therefore the array will be placed in .data.rel.ro and not in .rodata. This commit avoids the pointers altogether by combining all the actual codebooks into one big array; the actual codebooks are now accessed consecutively by incrementing the pointer used to access them by the length of the actual codebook that has just been dealt with (said length is contained in the structure describing the codebook). There is no downside to this given that these codebooks are already only used once during init. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/vorbisenc.c')
-rw-r--r--libavcodec/vorbisenc.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 5c10e49b3f..d8d7d4d4eb 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -272,6 +272,7 @@ static int create_vorbis_context(vorbis_enc_context *venc,
vorbis_enc_floor *fc;
vorbis_enc_residue *rc;
vorbis_enc_mapping *mc;
+ const uint8_t *clens, *quant;
int i, book, ret;
venc->channels = avctx->channels;
@@ -286,6 +287,8 @@ static int create_vorbis_context(vorbis_enc_context *venc,
// codebook 0..14 - floor1 book, values 0..255
// codebook 15 residue masterbook
// codebook 16..29 residue
+ clens = codebooks;
+ quant = quant_tables;
for (book = 0; book < venc->ncodebooks; book++) {
vorbis_enc_codebook *cb = &venc->codebooks[book];
int vals;
@@ -300,8 +303,9 @@ static int create_vorbis_context(vorbis_enc_context *venc,
cb->codewords = av_malloc_array(cb->nentries, sizeof(uint32_t));
if (!cb->lens || !cb->codewords)
return AVERROR(ENOMEM);
- memcpy(cb->lens, cvectors[book].clens, cvectors[book].len);
+ memcpy(cb->lens, clens, cvectors[book].len);
memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len);
+ clens += cvectors[book].len;
if (cb->lookup) {
vals = cb_lookup_vals(cb->lookup, cb->ndimensions, cb->nentries);
@@ -309,7 +313,7 @@ static int create_vorbis_context(vorbis_enc_context *venc,
if (!cb->quantlist)
return AVERROR(ENOMEM);
for (i = 0; i < vals; i++)
- cb->quantlist[i] = cvectors[book].quant[i];
+ cb->quantlist[i] = *quant++;
} else {
cb->quantlist = NULL;
}