History

avcodec/libaomenc: Avoid code duplication when setting options

(Some more options could be set via this method if the order in which the options are applied doesn't matter.)

Andreas Rheinhardt committed 1 year ago

Commit 4bd1ce31 parent 3cb37c01 file · +47 −67Browse files

Unified · Split

libavcodec/libaomenc.c+47−67
@@ -140,6 +140,8 @@ typedef struct AOMEncoderContext { · 139 unmodified lines
140140 AVDictionary *aom_params;
141141 } AOMContext;
142142
143+#define OFFSET(x) offsetof(AOMContext, x)
144+
143145 static const char *const ctlidstr[] = {
144146 [AOME_SET_CPUUSED] = "AOME_SET_CPUUSED",
145147 [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
@@ -673,6 +675,46 @@ static int choose_tiling(AVCodecContext *avctx, · 527 unmodified lines
673675 return 0;
674676 }
675677
678+
679+static const struct {
680+ int aom_enum;
681+ unsigned offset;
682+} option_map[] = {
683+ { AOME_SET_ENABLEAUTOALTREF, OFFSET(auto_alt_ref) },
684+ { AOME_SET_ARNR_MAXFRAMES, OFFSET(arnr_max_frames) },
685+ { AOME_SET_ARNR_STRENGTH, OFFSET(arnr_strength) },
686+ { AV1E_SET_ENABLE_CDEF, OFFSET(enable_cdef) },
687+ { AV1E_SET_ENABLE_RESTORATION, OFFSET(enable_restoration) },
688+ { AV1E_SET_ENABLE_RECT_PARTITIONS, OFFSET(enable_rect_partitions) },
689+ { AV1E_SET_ENABLE_1TO4_PARTITIONS, OFFSET(enable_1to4_partitions) },
690+ { AV1E_SET_ENABLE_AB_PARTITIONS, OFFSET(enable_ab_partitions) },
691+ { AV1E_SET_ENABLE_ANGLE_DELTA, OFFSET(enable_angle_delta) },
692+ { AV1E_SET_ENABLE_CFL_INTRA, OFFSET(enable_cfl_intra) },
693+ { AV1E_SET_ENABLE_FILTER_INTRA, OFFSET(enable_filter_intra) },
694+ { AV1E_SET_ENABLE_INTRA_EDGE_FILTER, OFFSET(enable_intra_edge_filter) },
695+ { AV1E_SET_ENABLE_PAETH_INTRA, OFFSET(enable_paeth_intra) },
696+ { AV1E_SET_ENABLE_SMOOTH_INTRA, OFFSET(enable_smooth_intra) },
697+ { AV1E_SET_ENABLE_PALETTE, OFFSET(enable_palette) },
698+ { AV1E_SET_ENABLE_TX64, OFFSET(enable_tx64) },
699+ { AV1E_SET_ENABLE_FLIP_IDTX, OFFSET(enable_flip_idtx) },
700+ { AV1E_SET_INTRA_DCT_ONLY, OFFSET(use_intra_dct_only) },
701+ { AV1E_SET_INTER_DCT_ONLY, OFFSET(use_inter_dct_only) },
702+ { AV1E_SET_INTRA_DEFAULT_TX_ONLY, OFFSET(use_intra_default_tx_only) },
703+ { AV1E_SET_REDUCED_TX_TYPE_SET, OFFSET(reduced_tx_type_set) },
704+ { AV1E_SET_ENABLE_REF_FRAME_MVS, OFFSET(enable_ref_frame_mvs) },
705+ { AV1E_SET_REDUCED_REFERENCE_SET, OFFSET(enable_reduced_reference_set) },
706+ { AV1E_SET_ENABLE_DIFF_WTD_COMP, OFFSET(enable_diff_wtd_comp) },
707+ { AV1E_SET_ENABLE_DIST_WTD_COMP, OFFSET(enable_dist_wtd_comp) },
708+ { AV1E_SET_ENABLE_DUAL_FILTER, OFFSET(enable_dual_filter) },
709+ { AV1E_SET_ENABLE_INTERINTER_WEDGE, OFFSET(enable_interinter_wedge) },
710+ { AV1E_SET_ENABLE_MASKED_COMP, OFFSET(enable_masked_comp) },
711+ { AV1E_SET_ENABLE_INTERINTRA_COMP, OFFSET(enable_interintra_comp) },
712+ { AV1E_SET_ENABLE_INTERINTRA_WEDGE, OFFSET(enable_interintra_wedge) },
713+ { AV1E_SET_ENABLE_OBMC, OFFSET(enable_obmc) },
714+ { AV1E_SET_ENABLE_ONESIDED_COMP, OFFSET(enable_onesided_comp) },
715+ { AV1E_SET_ENABLE_SMOOTH_INTERINTRA, OFFSET(enable_smooth_interintra) },
716+};
717+
676718 static av_cold int aom_init(AVCodecContext *avctx,
677719 const struct aom_codec_iface *iface)
678720 {
@@ -859,73 +901,12 @@ static av_cold int aom_init(AVCodecContext *avctx, · 180 unmodified lines
859901 // codec control failures are currently treated only as warnings
860902 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
861903 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
862− if (ctx->auto_alt_ref >= 0)
863− codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
864− if (ctx->arnr_max_frames >= 0)
865− codecctl_int(avctx, AOME_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames);
866− if (ctx->arnr_strength >= 0)
867− codecctl_int(avctx, AOME_SET_ARNR_STRENGTH, ctx->arnr_strength);
868− if (ctx->enable_cdef >= 0)
869− codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef);
870− if (ctx->enable_restoration >= 0)
871− codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION, ctx->enable_restoration);
872− if (ctx->enable_rect_partitions >= 0)
873− codecctl_int(avctx, AV1E_SET_ENABLE_RECT_PARTITIONS, ctx->enable_rect_partitions);
874− if (ctx->enable_1to4_partitions >= 0)
875− codecctl_int(avctx, AV1E_SET_ENABLE_1TO4_PARTITIONS, ctx->enable_1to4_partitions);
876− if (ctx->enable_ab_partitions >= 0)
877− codecctl_int(avctx, AV1E_SET_ENABLE_AB_PARTITIONS, ctx->enable_ab_partitions);
878− if (ctx->enable_angle_delta >= 0)
879− codecctl_int(avctx, AV1E_SET_ENABLE_ANGLE_DELTA, ctx->enable_angle_delta);
880− if (ctx->enable_cfl_intra >= 0)
881− codecctl_int(avctx, AV1E_SET_ENABLE_CFL_INTRA, ctx->enable_cfl_intra);
882− if (ctx->enable_filter_intra >= 0)
883− codecctl_int(avctx, AV1E_SET_ENABLE_FILTER_INTRA, ctx->enable_filter_intra);
884− if (ctx->enable_intra_edge_filter >= 0)
885− codecctl_int(avctx, AV1E_SET_ENABLE_INTRA_EDGE_FILTER, ctx->enable_intra_edge_filter);
886− if (ctx->enable_paeth_intra >= 0)
887− codecctl_int(avctx, AV1E_SET_ENABLE_PAETH_INTRA, ctx->enable_paeth_intra);
888− if (ctx->enable_smooth_intra >= 0)
889− codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA, ctx->enable_smooth_intra);
890− if (ctx->enable_palette >= 0)
891− codecctl_int(avctx, AV1E_SET_ENABLE_PALETTE, ctx->enable_palette);
892− if (ctx->enable_tx64 >= 0)
893− codecctl_int(avctx, AV1E_SET_ENABLE_TX64, ctx->enable_tx64);
894− if (ctx->enable_flip_idtx >= 0)
895− codecctl_int(avctx, AV1E_SET_ENABLE_FLIP_IDTX, ctx->enable_flip_idtx);
896− if (ctx->use_intra_dct_only >= 0)
897− codecctl_int(avctx, AV1E_SET_INTRA_DCT_ONLY, ctx->use_intra_dct_only);
898− if (ctx->use_inter_dct_only >= 0)
899− codecctl_int(avctx, AV1E_SET_INTER_DCT_ONLY, ctx->use_inter_dct_only);
900− if (ctx->use_intra_default_tx_only >= 0)
901− codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, ctx->use_intra_default_tx_only);
902− if (ctx->reduced_tx_type_set >= 0)
903− codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, ctx->reduced_tx_type_set);
904− if (ctx->enable_ref_frame_mvs >= 0)
905− codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS, ctx->enable_ref_frame_mvs);
906− if (ctx->enable_reduced_reference_set >= 0)
907− codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET, ctx->enable_reduced_reference_set);
908− if (ctx->enable_diff_wtd_comp >= 0)
909− codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP, ctx->enable_diff_wtd_comp);
910− if (ctx->enable_dist_wtd_comp >= 0)
911− codecctl_int(avctx, AV1E_SET_ENABLE_DIST_WTD_COMP, ctx->enable_dist_wtd_comp);
912− if (ctx->enable_dual_filter >= 0)
913− codecctl_int(avctx, AV1E_SET_ENABLE_DUAL_FILTER, ctx->enable_dual_filter);
914− if (ctx->enable_interinter_wedge >= 0)
915− codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTER_WEDGE, ctx->enable_interinter_wedge);
916− if (ctx->enable_masked_comp >= 0)
917− codecctl_int(avctx, AV1E_SET_ENABLE_MASKED_COMP, ctx->enable_masked_comp);
918− if (ctx->enable_interintra_comp >= 0)
919− codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_COMP, ctx->enable_interintra_comp);
920− if (ctx->enable_interintra_wedge >= 0)
921− codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_WEDGE, ctx->enable_interintra_wedge);
922− if (ctx->enable_obmc >= 0)
923− codecctl_int(avctx, AV1E_SET_ENABLE_OBMC, ctx->enable_obmc);
924− if (ctx->enable_onesided_comp >= 0)
925− codecctl_int(avctx, AV1E_SET_ENABLE_ONESIDED_COMP, ctx->enable_onesided_comp);
926− if (ctx->enable_smooth_interintra >= 0)
927− codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTERINTRA, ctx->enable_smooth_interintra);
928904
905+ for (size_t i = 0; i < FF_ARRAY_ELEMS(option_map); ++i) {
906+ int val = *(int*)((char*)ctx + option_map[i].offset);
907+ if (val >= 0)
908+ codecctl_int(avctx, option_map[i].aom_enum, val);
909+ }
929910 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
930911 if (ctx->crf >= 0)
931912 codecctl_int(avctx, AOME_SET_CQ_LEVEL, ctx->crf);
@@ -1457,7 +1438,6 @@ static av_cold int av1_init(AVCodecContext *avctx) · 525 unmodified lines
14571438 return aom_init(avctx, aom_codec_av1_cx());
14581439 }
14591440
1460−#define OFFSET(x) offsetof(AOMContext, x)
14611441 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
14621442 static const AVOption options[] = {
14631443 { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 8, VE},

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t