avcodec/utils: Unavpriv avpriv_toupper4()

This function is quite small (96B with GCC 11.2 on x64 Ubuntu 21.10
at -O3), making it more economical to duplicate it into libavformat
instead of exporting it as avpriv: Doing so saves 2x24B in .dynsim,
2x16B in .dynstr, 2x2B .gnu.version, 24B in .rela.plt, 16B in .plt,
16B in .plt.sec (if enabled), 4B .gnu.hash; besides the actual
duplicated code this also adds 2x8B .eh_frame_hdr and 24B .eh_frame.

In other words: Duplicating is neutral size-wise (it is also presumed
neutral for other systems). Given that it avoids the runtime
overhead of dynamic symbols, it is advantageouos to duplicate the
function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-12-13 19:55:39 +01:00
parent 007ffbeb53
commit b74e47c4ff
12 changed files with 93 additions and 16 deletions

View File

@ -127,7 +127,8 @@ OBJS-$(CONFIG_MPEGAUDIOHEADER) += mpegaudiodecheader.o mpegaudiotabs.o
OBJS-$(CONFIG_MPEG4AUDIO) += mpeg4audio.o mpeg4audio_sample_rates.o
OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideodsp.o rl.o \
mpegvideo_motion.o mpegutils.o \
mpegvideodata.o mpegpicture.o
mpegvideodata.o mpegpicture.o \
to_upper4.o
OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
motion_est.o ratecontrol.o \
mpegvideoencdsp.o
@ -996,6 +997,7 @@ OBJS-$(CONFIG_FITS_DEMUXER) += fits.o
OBJS-$(CONFIG_TAK_DEMUXER) += tak.o
# libavformat dependencies for static builds
STLIBOBJS-$(CONFIG_AVFORMAT) += to_upper4.o
STLIBOBJS-$(CONFIG_ISO_MEDIA) += mpegaudiotabs.o
STLIBOBJS-$(CONFIG_FLV_MUXER) += mpeg4audio_sample_rates.o
STLIBOBJS-$(CONFIG_HLS_DEMUXER) += ac3_channel_layout_tab.o

View File

@ -225,7 +225,7 @@ extern const uint8_t ff_log2_run[41];
*/
int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
unsigned int avpriv_toupper4(unsigned int x);
unsigned int ff_toupper4(unsigned int x);
void ff_color_frame(AVFrame *frame, const int color[4]);

View File

@ -2832,7 +2832,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
}
#endif
s2->codec_tag = avpriv_toupper4(avctx->codec_tag);
s2->codec_tag = ff_toupper4(avctx->codec_tag);
if (s->mpeg_enc_ctx_allocated == 0 && ( s2->codec_tag == AV_RL32("VCR2")
|| s2->codec_tag == AV_RL32("BW10")
))

View File

@ -701,7 +701,7 @@ void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
s->workaround_bugs = avctx->workaround_bugs;
/* convert fourcc to upper case */
s->codec_tag = avpriv_toupper4(avctx->codec_tag);
s->codec_tag = ff_toupper4(avctx->codec_tag);
}
/**

23
libavcodec/to_upper4.c Normal file
View File

@ -0,0 +1,23 @@
/*
* Converting FOURCCs to uppercase
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* 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 "to_upper4.h"

37
libavcodec/to_upper4.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Converting FOURCCs to uppercase
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* 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_TO_UPPER4_H
#define AVCODEC_TO_UPPER4_H
#include "libavutil/avstring.h"
#include "internal.h"
unsigned int ff_toupper4(unsigned int x)
{
return av_toupper(x & 0xFF) |
(av_toupper((x >> 8) & 0xFF) << 8) |
(av_toupper((x >> 16) & 0xFF) << 16) |
((unsigned)av_toupper((x >> 24) & 0xFF) << 24);
}
#endif

View File

@ -863,14 +863,6 @@ const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index)
return &codec->hw_configs[index]->public;
}
unsigned int avpriv_toupper4(unsigned int x)
{
return av_toupper(x & 0xFF) +
(av_toupper((x >> 8) & 0xFF) << 8) +
(av_toupper((x >> 16) & 0xFF) << 16) +
((unsigned)av_toupper((x >> 24) & 0xFF) << 24);
}
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
{
int ret;

View File

@ -680,7 +680,7 @@ OBJS-$(CONFIG_LIBSSH_PROTOCOL) += libssh.o
OBJS-$(CONFIG_LIBZMQ_PROTOCOL) += libzmq.o
# Objects duplicated from other libraries for shared builds
SHLIBOBJS += log2_tab.o
SHLIBOBJS += log2_tab.o to_upper4.o
SHLIBOBJS-$(CONFIG_ISO_MEDIA) += mpegaudiotabs.o
SHLIBOBJS-$(CONFIG_FLV_MUXER) += mpeg4audio_sample_rates.o
SHLIBOBJS-$(CONFIG_HLS_DEMUXER) += ac3_channel_layout_tab.o

View File

@ -1717,7 +1717,7 @@ static unsigned int validate_codec_tag(const AVCodecTag *const *tags,
for (i = 0; tags && tags[i]; i++) {
const AVCodecTag *codec_tags = tags[i];
while (codec_tags->id != AV_CODEC_ID_NONE) {
if (avpriv_toupper4(codec_tags->tag) == avpriv_toupper4(tag) &&
if (ff_toupper4(codec_tags->tag) == ff_toupper4(tag) &&
codec_tags->id == codec_id)
return codec_tags->tag;
codec_tags++;

View File

@ -204,7 +204,7 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st)
for (int n = 0; s->oformat->codec_tag[n]; n++) {
avctag = s->oformat->codec_tag[n];
while (avctag->id != AV_CODEC_ID_NONE) {
if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codecpar->codec_tag)) {
if (ff_toupper4(avctag->tag) == ff_toupper4(st->codecpar->codec_tag)) {
id = avctag->id;
if (id == st->codecpar->codec_id)
return 1;

23
libavformat/to_upper4.c Normal file
View File

@ -0,0 +1,23 @@
/*
* Converting FOURCCs to uppercase
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* 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/to_upper4.h"

View File

@ -361,7 +361,7 @@ enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
if (tag == tags[i].tag)
return tags[i].id;
for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag))
if (ff_toupper4(tag) == ff_toupper4(tags[i].tag))
return tags[i].id;
return AV_CODEC_ID_NONE;
}