summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-11-19 19:50:49 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-12-01 11:00:41 +0100
commit881e8bcc515ada587b18216da18a402ed88e6f63 (patch)
tree031ecc3460dfb9d6a67d051f09aef2d300da5c81
parent8d481b0234df19851270f4f6fb78b54bac47d4a3 (diff)
avcodec/h264data: Deduplicate H.26[45] aspect ratio table
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/Makefile18
-rw-r--r--libavcodec/h2645data.c39
-rw-r--r--libavcodec/h2645data.h26
-rw-r--r--libavcodec/h264_metadata_bsf.c17
-rw-r--r--libavcodec/h264_ps.c5
-rw-r--r--libavcodec/h264data.h20
-rw-r--r--libavcodec/h265_metadata_bsf.c17
-rw-r--r--libavcodec/hevc_ps.c25
-rw-r--r--libavcodec/vaapi_encode_h264.c16
-rw-r--r--libavcodec/vaapi_encode_h265.c16
10 files changed, 103 insertions, 96 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3063270d81..092c3c964d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -96,11 +96,13 @@ OBJS-$(CONFIG_GOLOMB) += golomb.o
OBJS-$(CONFIG_H263DSP) += h263dsp.o
OBJS-$(CONFIG_H264CHROMA) += h264chroma.o
OBJS-$(CONFIG_H264DSP) += h264dsp.o h264idct.o
-OBJS-$(CONFIG_H264PARSE) += h264_parse.o h2645_parse.o h264_ps.o
+OBJS-$(CONFIG_H264PARSE) += h264_parse.o h264_ps.o h2645data.o \
+ h2645_parse.o
OBJS-$(CONFIG_H264PRED) += h264pred.o
OBJS-$(CONFIG_H264QPEL) += h264qpel.o
OBJS-$(CONFIG_H264_SEI) += h264_sei.o h2645_sei.o
-OBJS-$(CONFIG_HEVCPARSE) += hevc_parse.o h2645_parse.o hevc_ps.o hevc_data.o
+OBJS-$(CONFIG_HEVCPARSE) += hevc_parse.o hevc_ps.o hevc_data.o \
+ h2645data.o h2645_parse.o
OBJS-$(CONFIG_HEVC_SEI) += hevc_sei.o h2645_sei.o \
dynamic_hdr10_plus.o dynamic_hdr_vivid.o
OBJS-$(CONFIG_HPELDSP) += hpeldsp.o
@@ -406,7 +408,8 @@ OBJS-$(CONFIG_H264_OMX_ENCODER) += omx.o
OBJS-$(CONFIG_H264_QSV_DECODER) += qsvdec.o
OBJS-$(CONFIG_H264_QSV_ENCODER) += qsvenc_h264.o
OBJS-$(CONFIG_H264_RKMPP_DECODER) += rkmppdec.o
-OBJS-$(CONFIG_H264_VAAPI_ENCODER) += vaapi_encode_h264.o h264_levels.o
+OBJS-$(CONFIG_H264_VAAPI_ENCODER) += vaapi_encode_h264.o h264_levels.o \
+ h2645data.o
OBJS-$(CONFIG_H264_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
OBJS-$(CONFIG_H264_V4L2M2M_DECODER) += v4l2_m2m_dec.o
OBJS-$(CONFIG_H264_V4L2M2M_ENCODER) += v4l2_m2m_enc.o
@@ -430,7 +433,8 @@ OBJS-$(CONFIG_HEVC_QSV_DECODER) += qsvdec.o
OBJS-$(CONFIG_HEVC_QSV_ENCODER) += qsvenc_hevc.o hevc_ps_enc.o \
hevc_data.o
OBJS-$(CONFIG_HEVC_RKMPP_DECODER) += rkmppdec.o
-OBJS-$(CONFIG_HEVC_VAAPI_ENCODER) += vaapi_encode_h265.o h265_profile_level.o
+OBJS-$(CONFIG_HEVC_VAAPI_ENCODER) += vaapi_encode_h265.o h265_profile_level.o \
+ h2645data.o
OBJS-$(CONFIG_HEVC_V4L2M2M_DECODER) += v4l2_m2m_dec.o
OBJS-$(CONFIG_HEVC_V4L2M2M_ENCODER) += v4l2_m2m_enc.o
OBJS-$(CONFIG_HEVC_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
@@ -1198,11 +1202,13 @@ OBJS-$(CONFIG_EAC3_CORE_BSF) += eac3_core_bsf.o
OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF) += extract_extradata_bsf.o \
av1_parse.o h2645_parse.o
OBJS-$(CONFIG_FILTER_UNITS_BSF) += filter_units_bsf.o
-OBJS-$(CONFIG_H264_METADATA_BSF) += h264_metadata_bsf.o h264_levels.o
+OBJS-$(CONFIG_H264_METADATA_BSF) += h264_metadata_bsf.o h264_levels.o \
+ h2645data.o
OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF) += h264_mp4toannexb_bsf.o
OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
OBJS-$(CONFIG_HAPQA_EXTRACT_BSF) += hapqa_extract_bsf.o hap.o
-OBJS-$(CONFIG_HEVC_METADATA_BSF) += h265_metadata_bsf.o h265_profile_level.o
+OBJS-$(CONFIG_HEVC_METADATA_BSF) += h265_metadata_bsf.o h265_profile_level.o \
+ h2645data.o
OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF) += hevc_mp4toannexb_bsf.o
OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF) += imx_dump_header_bsf.o
OBJS-$(CONFIG_MJPEG2JPEG_BSF) += mjpeg2jpeg_bsf.o
diff --git a/libavcodec/h2645data.c b/libavcodec/h2645data.c
new file mode 100644
index 0000000000..9897ca3186
--- /dev/null
+++ b/libavcodec/h2645data.c
@@ -0,0 +1,39 @@
+/*
+ * 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 "h2645data.h"
+
+const AVRational ff_h2645_pixel_aspect[] = {
+ { 0, 1 },
+ { 1, 1 },
+ { 12, 11 },
+ { 10, 11 },
+ { 16, 11 },
+ { 40, 33 },
+ { 24, 11 },
+ { 20, 11 },
+ { 32, 11 },
+ { 80, 33 },
+ { 18, 11 },
+ { 15, 11 },
+ { 64, 33 },
+ { 160, 99 },
+ { 4, 3 },
+ { 3, 2 },
+ { 2, 1 },
+};
diff --git a/libavcodec/h2645data.h b/libavcodec/h2645data.h
new file mode 100644
index 0000000000..bc56d76870
--- /dev/null
+++ b/libavcodec/h2645data.h
@@ -0,0 +1,26 @@
+/*
+ * 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_H2645DATA_H
+#define AVCODEC_H2645DATA_H
+
+#include "libavutil/rational.h"
+
+extern const AVRational ff_h2645_pixel_aspect[17];
+
+#endif /* AVCODEC_H2645DATA_H */
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 6efdc92476..d318bf0cee 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -29,6 +29,7 @@
#include "h264.h"
#include "h264_levels.h"
#include "h264_sei.h"
+#include "h2645data.h"
enum {
FLIP_HORIZONTAL = 1,
@@ -144,25 +145,17 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
int crop_unit_x, crop_unit_y;
if (ctx->sample_aspect_ratio.num && ctx->sample_aspect_ratio.den) {
- // Table E-1.
- static const AVRational sar_idc[] = {
- { 0, 0 }, // Unspecified (never written here).
- { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
- { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
- { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
- { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
- };
int num, den, i;
av_reduce(&num, &den, ctx->sample_aspect_ratio.num,
ctx->sample_aspect_ratio.den, 65535);
- for (i = 1; i < FF_ARRAY_ELEMS(sar_idc); i++) {
- if (num == sar_idc[i].num &&
- den == sar_idc[i].den)
+ for (i = 1; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
+ if (num == ff_h2645_pixel_aspect[i].num &&
+ den == ff_h2645_pixel_aspect[i].den)
break;
}
- if (i == FF_ARRAY_ELEMS(sar_idc)) {
+ if (i == FF_ARRAY_ELEMS(ff_h2645_pixel_aspect)) {
sps->vui.aspect_ratio_idc = 255;
sps->vui.sar_width = num;
sps->vui.sar_height = den;
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index 55ef5ce0d3..1fd7375a13 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -31,6 +31,7 @@
#include "mathops.h"
#include "avcodec.h"
#include "h264data.h"
+#include "h2645data.h"
#include "h264_ps.h"
#include "golomb.h"
@@ -142,8 +143,8 @@ static inline int decode_vui_parameters(GetBitContext *gb, void *logctx,
if (aspect_ratio_idc == EXTENDED_SAR) {
sps->sar.num = get_bits(gb, 16);
sps->sar.den = get_bits(gb, 16);
- } else if (aspect_ratio_idc < FF_ARRAY_ELEMS(ff_h264_pixel_aspect)) {
- sps->sar = ff_h264_pixel_aspect[aspect_ratio_idc];
+ } else if (aspect_ratio_idc < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect)) {
+ sps->sar = ff_h2645_pixel_aspect[aspect_ratio_idc];
} else {
av_log(logctx, AV_LOG_WARNING, "Unknown SAR index: %u.\n",
aspect_ratio_idc);
diff --git a/libavcodec/h264data.h b/libavcodec/h264data.h
index 4efe76a34d..f809886ae6 100644
--- a/libavcodec/h264data.h
+++ b/libavcodec/h264data.h
@@ -49,26 +49,6 @@ extern const PMbInfo ff_h264_p_sub_mb_type_info[4];
extern const PMbInfo ff_h264_b_mb_type_info[23];
extern const PMbInfo ff_h264_b_sub_mb_type_info[13];
-static const AVRational ff_h264_pixel_aspect[17] = {
- { 0, 1 },
- { 1, 1 },
- { 12, 11 },
- { 10, 11 },
- { 16, 11 },
- { 40, 33 },
- { 24, 11 },
- { 20, 11 },
- { 32, 11 },
- { 80, 33 },
- { 18, 11 },
- { 15, 11 },
- { 64, 33 },
- { 160, 99 },
- { 4, 3 },
- { 3, 2 },
- { 2, 1 },
-};
-
extern const uint8_t ff_h264_dequant4_coeff_init[6][3];
extern const uint8_t ff_h264_dequant8_coeff_init_scan[16];
extern const uint8_t ff_h264_dequant8_coeff_init[6][6];
diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
index ffcbbf0120..6787bd14a1 100644
--- a/libavcodec/h265_metadata_bsf.c
+++ b/libavcodec/h265_metadata_bsf.c
@@ -24,6 +24,7 @@
#include "cbs.h"
#include "cbs_bsf.h"
#include "cbs_h265.h"
+#include "h2645data.h"
#include "hevc.h"
#include "h265_profile_level.h"
@@ -194,25 +195,17 @@ static int h265_metadata_update_sps(AVBSFContext *bsf,
int crop_unit_x, crop_unit_y;
if (ctx->sample_aspect_ratio.num && ctx->sample_aspect_ratio.den) {
- // Table E-1.
- static const AVRational sar_idc[] = {
- { 0, 0 }, // Unspecified (never written here).
- { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
- { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
- { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
- { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
- };
int num, den, i;
av_reduce(&num, &den, ctx->sample_aspect_ratio.num,
ctx->sample_aspect_ratio.den, 65535);
- for (i = 1; i < FF_ARRAY_ELEMS(sar_idc); i++) {
- if (num == sar_idc[i].num &&
- den == sar_idc[i].den)
+ for (i = 1; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
+ if (num == ff_h2645_pixel_aspect[i].num &&
+ den == ff_h2645_pixel_aspect[i].den)
break;
}
- if (i == FF_ARRAY_ELEMS(sar_idc)) {
+ if (i == FF_ARRAY_ELEMS(ff_h2645_pixel_aspect)) {
sps->vui.aspect_ratio_idc = 255;
sps->vui.sar_width = num;
sps->vui.sar_height = den;
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index f665d8053c..bfd4291bb9 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -25,6 +25,7 @@
#include "libavutil/imgutils.h"
#include "golomb.h"
+#include "h2645data.h"
#include "hevc_data.h"
#include "hevc_ps.h"
@@ -50,26 +51,6 @@ static const uint8_t default_scaling_list_inter[] = {
24, 25, 28, 33, 41, 54, 71, 91
};
-static const AVRational vui_sar[] = {
- { 0, 1 },
- { 1, 1 },
- { 12, 11 },
- { 10, 11 },
- { 16, 11 },
- { 40, 33 },
- { 24, 11 },
- { 20, 11 },
- { 32, 11 },
- { 80, 33 },
- { 18, 11 },
- { 15, 11 },
- { 64, 33 },
- { 160, 99 },
- { 4, 3 },
- { 3, 2 },
- { 2, 1 },
-};
-
static const uint8_t hevc_sub_width_c[] = {
1, 2, 2, 1
};
@@ -594,8 +575,8 @@ static void decode_vui(GetBitContext *gb, AVCodecContext *avctx,
sar_present = get_bits1(gb);
if (sar_present) {
uint8_t sar_idx = get_bits(gb, 8);
- if (sar_idx < FF_ARRAY_ELEMS(vui_sar))
- vui->sar = vui_sar[sar_idx];
+ if (sar_idx < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect))
+ vui->sar = ff_h2645_pixel_aspect[sar_idx];
else if (sar_idx == 255) {
vui->sar.num = get_bits(gb, 16);
vui->sar.den = get_bits(gb, 16);
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index b1b503b2a6..dd17be2190 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -33,6 +33,7 @@
#include "h264.h"
#include "h264_levels.h"
#include "h264_sei.h"
+#include "h2645data.h"
#include "vaapi_encode.h"
#include "version.h"
@@ -378,24 +379,17 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
if (avctx->sample_aspect_ratio.num != 0 &&
avctx->sample_aspect_ratio.den != 0) {
- static const AVRational sar_idc[] = {
- { 0, 0 },
- { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
- { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
- { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
- { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
- };
int num, den, i;
av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
avctx->sample_aspect_ratio.den, 65535);
- for (i = 0; i < FF_ARRAY_ELEMS(sar_idc); i++) {
- if (num == sar_idc[i].num &&
- den == sar_idc[i].den) {
+ for (i = 0; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
+ if (num == ff_h2645_pixel_aspect[i].num &&
+ den == ff_h2645_pixel_aspect[i].den) {
sps->vui.aspect_ratio_idc = i;
break;
}
}
- if (i >= FF_ARRAY_ELEMS(sar_idc)) {
+ if (i >= FF_ARRAY_ELEMS(ff_h2645_pixel_aspect)) {
sps->vui.aspect_ratio_idc = 255;
sps->vui.sar_width = num;
sps->vui.sar_height = den;
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 94b56c6578..0833053c74 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -31,6 +31,7 @@
#include "cbs.h"
#include "cbs_h265.h"
#include "codec_internal.h"
+#include "h2645data.h"
#include "h265_profile_level.h"
#include "hevc.h"
#include "hevc_sei.h"
@@ -496,24 +497,17 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
if (avctx->sample_aspect_ratio.num != 0 &&
avctx->sample_aspect_ratio.den != 0) {
- static const AVRational sar_idc[] = {
- { 0, 0 },
- { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
- { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
- { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
- { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
- };
int num, den, i;
av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
avctx->sample_aspect_ratio.den, 65535);
- for (i = 0; i < FF_ARRAY_ELEMS(sar_idc); i++) {
- if (num == sar_idc[i].num &&
- den == sar_idc[i].den) {
+ for (i = 0; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
+ if (num == ff_h2645_pixel_aspect[i].num &&
+ den == ff_h2645_pixel_aspect[i].den) {
vui->aspect_ratio_idc = i;
break;
}
}
- if (i >= FF_ARRAY_ELEMS(sar_idc)) {
+ if (i >= FF_ARRAY_ELEMS(ff_h2645_pixel_aspect)) {
vui->aspect_ratio_idc = 255;
vui->sar_width = num;
vui->sar_height = den;