avcodec/raw: Reduce number of avpriv symbols

libavcodec currently exports four avpriv symbols that deal with
PixelFormatTags: avpriv_get_raw_pix_fmt_tags, avpriv_find_pix_fmt,
avpriv_pix_fmt_bps_avi and avpriv_pix_fmt_bps_mov. The latter two are
lists of PixelFormatTags, the former returns such a list and the second
searches a list for a pixel format that matches a given fourcc; only
one of the aforementioned three lists is ever searched.

Yet for avpriv_pix_fmt_bps_avi, avpriv_pix_fmt_bps_mov and
avpriv_find_pix_fmt the overhead of exporting these functions actually
exceeds the size of said objects (at least for ELF; the following numbers
are for x64 Ubuntu 20.10):
The code size of avpriv_find_pix_fmt is small (GCC 10.2 37B, Clang 11 41B),
yet exporting it adds a 20B string for the name alone to the exporting
as well as to each importing library; there is more: Four bytes in the
exporting libraries .gnu.hash; two bytes each for the exporting as well
as each importing libraries .gnu.version; 24B in the exporting as well
as each importing libraries .dynsym; 16B+24B for an entry in .plt as
well as the accompanying relocation entry in .rela.plt for each
importing library.

The overhead for the lists is similar: The strings are 23B and the
.plt+.rela.plt pair is replaced by 8B+24B for an entry in .got and
a relocation entry in .rela.dyn. These lists have a size of 80 resp.
72 bytes.

Yet for ff_raw_pix_fmt_tags, exporting it is advantageous compared to
duplicating it into libavformat and potentially libavdevice. Therefore
this commit replaces all library uses of the four symbols with a single
function that is exported for shared builds. It has an enum parameter
to choose the desired list besides the parameter for the fourcc. New
lists can be supported with new enum values.

Unfortunately, avpriv_get_raw_pix_fmt_tags could not be removed, as the
fourcc2pixfmt tool uses the table of raw pix fmts. No other user of this
function remains.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/383/head
Andreas Rheinhardt 4 years ago
parent e84d8ba441
commit 3d53cefb49
  1. 40
      libavcodec/raw.c
  2. 13
      libavcodec/raw.h
  3. 8
      libavcodec/rawdec.c
  4. 11
      libavcodec/utils.c
  5. 2
      libavdevice/dshow.c
  6. 2
      libavformat/avienc.c
  7. 2
      libavformat/demux.c
  8. 2
      libavformat/movenc.c

@ -28,7 +28,7 @@
#include "raw.h" #include "raw.h"
#include "libavutil/common.h" #include "libavutil/common.h"
const PixelFormatTag ff_raw_pix_fmt_tags[] = { static const PixelFormatTag raw_pix_fmt_tags[] = {
{ AV_PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */ { AV_PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */
{ AV_PIX_FMT_YUV420P, MKTAG('I', 'Y', 'U', 'V') }, { AV_PIX_FMT_YUV420P, MKTAG('I', 'Y', 'U', 'V') },
{ AV_PIX_FMT_YUV420P, MKTAG('y', 'v', '1', '2') }, { AV_PIX_FMT_YUV420P, MKTAG('y', 'v', '1', '2') },
@ -299,12 +299,12 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = {
const struct PixelFormatTag *avpriv_get_raw_pix_fmt_tags(void) const struct PixelFormatTag *avpriv_get_raw_pix_fmt_tags(void)
{ {
return ff_raw_pix_fmt_tags; return raw_pix_fmt_tags;
} }
unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat fmt) unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat fmt)
{ {
const PixelFormatTag *tags = ff_raw_pix_fmt_tags; const PixelFormatTag *tags = raw_pix_fmt_tags;
while (tags->pix_fmt >= 0) { while (tags->pix_fmt >= 0) {
if (tags->pix_fmt == fmt) if (tags->pix_fmt == fmt)
return tags->fourcc; return tags->fourcc;
@ -313,7 +313,7 @@ unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat fmt)
return 0; return 0;
} }
const PixelFormatTag avpriv_pix_fmt_bps_avi[] = { static const PixelFormatTag pix_fmt_bps_avi[] = {
{ AV_PIX_FMT_PAL8, 1 }, { AV_PIX_FMT_PAL8, 1 },
{ AV_PIX_FMT_PAL8, 2 }, { AV_PIX_FMT_PAL8, 2 },
{ AV_PIX_FMT_PAL8, 4 }, { AV_PIX_FMT_PAL8, 4 },
@ -326,7 +326,7 @@ const PixelFormatTag avpriv_pix_fmt_bps_avi[] = {
{ AV_PIX_FMT_NONE, 0 }, { AV_PIX_FMT_NONE, 0 },
}; };
const PixelFormatTag avpriv_pix_fmt_bps_mov[] = { static const PixelFormatTag pix_fmt_bps_mov[] = {
{ AV_PIX_FMT_PAL8, 1 }, { AV_PIX_FMT_PAL8, 1 },
{ AV_PIX_FMT_PAL8, 2 }, { AV_PIX_FMT_PAL8, 2 },
{ AV_PIX_FMT_PAL8, 4 }, { AV_PIX_FMT_PAL8, 4 },
@ -337,3 +337,33 @@ const PixelFormatTag avpriv_pix_fmt_bps_mov[] = {
{ AV_PIX_FMT_PAL8, 33 }, { AV_PIX_FMT_PAL8, 33 },
{ AV_PIX_FMT_NONE, 0 }, { AV_PIX_FMT_NONE, 0 },
}; };
static enum AVPixelFormat find_pix_fmt(const PixelFormatTag *tags,
unsigned int fourcc)
{
while (tags->pix_fmt != AV_PIX_FMT_NONE) {
if (tags->fourcc == fourcc)
return tags->pix_fmt;
tags++;
}
return AV_PIX_FMT_NONE;
}
enum AVPixelFormat avpriv_pix_fmt_find(enum PixelFormatTagLists list,
unsigned fourcc)
{
const PixelFormatTag *tags;
switch (list) {
case PIX_FMT_LIST_RAW:
tags = raw_pix_fmt_tags;
break;
case PIX_FMT_LIST_AVI:
tags = pix_fmt_bps_avi;
break;
case PIX_FMT_LIST_MOV:
tags = pix_fmt_bps_mov;
break;
}
return find_pix_fmt(tags, fourcc);
}

@ -28,20 +28,21 @@
#define AVCODEC_RAW_H #define AVCODEC_RAW_H
#include "libavutil/pixfmt.h" #include "libavutil/pixfmt.h"
#include "internal.h"
typedef struct PixelFormatTag { typedef struct PixelFormatTag {
enum AVPixelFormat pix_fmt; enum AVPixelFormat pix_fmt;
unsigned int fourcc; unsigned int fourcc;
} PixelFormatTag; } PixelFormatTag;
extern const PixelFormatTag ff_raw_pix_fmt_tags[]; // exposed through avpriv_get_raw_pix_fmt_tags()
const struct PixelFormatTag *avpriv_get_raw_pix_fmt_tags(void); const struct PixelFormatTag *avpriv_get_raw_pix_fmt_tags(void);
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc); enum PixelFormatTagLists {
PIX_FMT_LIST_RAW,
PIX_FMT_LIST_AVI,
PIX_FMT_LIST_MOV,
};
extern av_export_avcodec const PixelFormatTag avpriv_pix_fmt_bps_avi[]; enum AVPixelFormat avpriv_pix_fmt_find(enum PixelFormatTagLists list,
extern av_export_avcodec const PixelFormatTag avpriv_pix_fmt_bps_mov[]; unsigned fourcc);
#endif /* AVCODEC_RAW_H */ #endif /* AVCODEC_RAW_H */

@ -76,15 +76,15 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
if ( avctx->codec_tag == MKTAG('r','a','w',' ') if ( avctx->codec_tag == MKTAG('r','a','w',' ')
|| avctx->codec_tag == MKTAG('N','O','1','6')) || avctx->codec_tag == MKTAG('N','O','1','6'))
avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_mov, avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_MOV,
avctx->bits_per_coded_sample); avctx->bits_per_coded_sample);
else if (avctx->codec_tag == MKTAG('W', 'R', 'A', 'W')) else if (avctx->codec_tag == MKTAG('W', 'R', 'A', 'W'))
avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi, avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_AVI,
avctx->bits_per_coded_sample); avctx->bits_per_coded_sample);
else if (avctx->codec_tag && (avctx->codec_tag & 0xFFFFFF) != MKTAG('B','I','T', 0)) else if (avctx->codec_tag && (avctx->codec_tag & 0xFFFFFF) != MKTAG('B','I','T', 0))
avctx->pix_fmt = avpriv_find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag); avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, avctx->codec_tag);
else if (avctx->pix_fmt == AV_PIX_FMT_NONE && avctx->bits_per_coded_sample) else if (avctx->pix_fmt == AV_PIX_FMT_NONE && avctx->bits_per_coded_sample)
avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi, avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_AVI,
avctx->bits_per_coded_sample); avctx->bits_per_coded_sample);
desc = av_pix_fmt_desc_get(avctx->pix_fmt); desc = av_pix_fmt_desc_get(avctx->pix_fmt);

@ -436,17 +436,6 @@ void ff_color_frame(AVFrame *frame, const int c[4])
} }
} }
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags,
unsigned int fourcc)
{
while (tags->pix_fmt >= 0) {
if (tags->fourcc == fourcc)
return tags->pix_fmt;
tags++;
}
return AV_PIX_FMT_NONE;
}
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){ int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
return !!(codec->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM); return !!(codec->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
} }

@ -76,7 +76,7 @@ static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
return AV_PIX_FMT_0RGB32; return AV_PIX_FMT_0RGB32;
} }
} }
return avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), biCompression); // all others return avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, biCompression); // all others
} }
static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat *fmt_info) static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat *fmt_info)

@ -448,7 +448,7 @@ static int avi_write_header(AVFormatContext *s)
par->bits_per_coded_sample = 16; par->bits_per_coded_sample = 16;
avist->pal_offset = avio_tell(pb) + 40; avist->pal_offset = avio_tell(pb) + 40;
ff_put_bmp_header(pb, par, 0, 0, avi->flipped_raw_rgb); ff_put_bmp_header(pb, par, 0, 0, avi->flipped_raw_rgb);
pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi, pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_AVI,
par->bits_per_coded_sample); par->bits_per_coded_sample);
if ( !par->codec_tag if ( !par->codec_tag
&& par->codec_id == AV_CODEC_ID_RAWVIDEO && par->codec_id == AV_CODEC_ID_RAWVIDEO

@ -2790,7 +2790,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) {
uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
if (avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), tag) == avctx->pix_fmt) if (avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, tag) == avctx->pix_fmt)
avctx->codec_tag= tag; avctx->codec_tag= tag;
} }

@ -1637,7 +1637,7 @@ static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track)
} }
} }
pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_mov, pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_MOV,
track->par->bits_per_coded_sample); track->par->bits_per_coded_sample);
if (tag == MKTAG('r','a','w',' ') && if (tag == MKTAG('r','a','w',' ') &&
track->par->format != pix_fmt && track->par->format != pix_fmt &&

Loading…
Cancel
Save