History

vd_lavc: separate opts to two structs and reorganize

The options in vd_lavc are all related, but they don't all require the same thing for runtime changes. To avoid having to manually add UPDATE_* to every single option flag, the options can be split into two separate structs. The vd_lavc_conf becomes a catch all for all the --vd-lavc options that require the full UPDATE_VD flag. The rest of the options are split off into the new hwdec_conf instead. Additionally, --vd-lavc-software-fallback is renamed to --hwdec-software-fallback and moved to the hwdec_conf as well. The new name better reflects what it does and it logically fits with those more. UPDATE_* flags are added on everything now so these should all now be changeable on runtime.

Dudemanguy committed 1 year ago

Commit 8c4ca441 parent 838df2c5 files · +65 −34Browse files

Unified · Split

5 files
  1. DOCS/interface-changes/hwdec-software-fallback.txt +1 −0
  2. DOCS/man/options.rst +8 −8
  3. options/options.c +3 −0
  4. options/options.h +2 −0
  5. video/decode/vd_lavc.c +51 −26
DOCS/interface-changes/hwdec-software-fallback.txt+1−0
@@ -0,0 +1 @@
1+rename `--vd-lavc-software-fallback` to `--hwdec-software-fallback`
DOCS/man/options.rst+8−8
@@ -1826,14 +1826,7 @@ Video · 1825 unmodified lines
18261826 ``mpv --hwdec=vdpau --hwdec-codecs=h264,mpeg2video``
18271827 Enable vdpau decoding for h264 and mpeg2 only.
18281828
1829−``--vd-lavc-check-hw-profile=<yes|no>``
1830− Check hardware decoder profile (default: yes). If ``no`` is set, the
1831− highest profile of the hardware decoder is unconditionally selected, and
1832− decoding is forced even if the profile of the video is higher than that.
1833− The result is most likely broken decoding, but may also help if the
1834− detected or reported profiles are somehow incorrect.
1835−
1836−``--vd-lavc-software-fallback=<yes|no|N>``
1829+``--hwdec-software-fallback=<yes|no|N>``
18371830 Fallback to software decoding if the hardware-accelerated decoder fails
18381831 (default: 3). If this is a number, then fallback will be triggered if
18391832 N frames fail to decode in a row. 1 is equivalent to ``yes``.
@@ -1843,6 +1836,13 @@ Video · 3 unmodified lines
18431836 the number of packets that could not be decoded. Values below an unspecified
18441837 count will not have this problem, because mpv retains the packets.
18451838
1839+``--vd-lavc-check-hw-profile=<yes|no>``
1840+ Check hardware decoder profile (default: yes). If ``no`` is set, the
1841+ highest profile of the hardware decoder is unconditionally selected, and
1842+ decoding is forced even if the profile of the video is higher than that.
1843+ The result is most likely broken decoding, but may also help if the
1844+ detected or reported profiles are somehow incorrect.
1845+
18461846 ``--vd-lavc-film-grain=<auto|cpu|gpu>``
18471847 Enables film grain application on the GPU. If video decoding is done on
18481848 the CPU, doing film grain application on the GPU can speed up decoding.
options/options.c+3−0
@@ -72,6 +72,7 @@ extern const struct m_sub_options demux_lavf_conf; · 71 unmodified lines
7272 extern const struct m_sub_options demux_mkv_conf;
7373 extern const struct m_sub_options vd_lavc_conf;
7474 extern const struct m_sub_options ad_lavc_conf;
75+extern const struct m_sub_options hwdec_conf;
7576 extern const struct m_sub_options input_config;
7677 extern const struct m_sub_options encode_config;
7778 extern const struct m_sub_options ra_ctx_conf;
@@ -671,6 +672,8 @@ static const m_option_t mp_opts[] = { · 593 unmodified lines
671672 {"", OPT_SUBSTRUCT(vd_lavc_params, vd_lavc_conf)},
672673 {"ad-lavc", OPT_SUBSTRUCT(ad_lavc_params, ad_lavc_conf)},
673674
675+ {"", OPT_SUBSTRUCT(hwdec_opts, hwdec_conf)},
676+
674677 {"", OPT_SUBSTRUCT(demux_lavf, demux_lavf_conf)},
675678 {"demuxer-rawaudio", OPT_SUBSTRUCT(demux_rawaudio, demux_rawaudio_conf)},
676679 {"demuxer-rawvideo", OPT_SUBSTRUCT(demux_rawvideo, demux_rawvideo_conf)},
options/options.h+2−0
@@ -363,6 +363,8 @@ typedef struct MPOpts { · 362 unmodified lines
363363 struct vd_lavc_params *vd_lavc_params;
364364 struct ad_lavc_params *ad_lavc_params;
365365
366+ struct hwdec_opts *hwdec_opts;
367+
366368 struct input_opts *input_opts;
367369
368370 struct clipboard_opts *clipboard_opts;
video/decode/vd_lavc.c+51−26
@@ -81,13 +81,8 @@ struct vd_lavc_params { · 80 unmodified lines
8181 bool old_x264;
8282 bool apply_cropping;
8383 bool check_hw_profile;
84− int software_fallback;
8584 char **avopts;
8685 int dr;
87− char **hwdec_api;
88− char *hwdec_codecs;
89− int hwdec_image_format;
90− int hwdec_extra_frames;
9186 };
9287
9388 static const struct m_opt_choice_alternatives discard_names[] = {
@@ -111,34 +106,61 @@ const struct m_sub_options vd_lavc_conf = { · 17 unmodified lines
111106 {"vd-lavc-skipidct", OPT_DISCARD(skip_idct)},
112107 {"vd-lavc-skipframe", OPT_DISCARD(skip_frame)},
113108 {"vd-lavc-framedrop", OPT_DISCARD(framedrop)},
114− {"vd-lavc-threads", OPT_INT(threads), M_RANGE(0, DBL_MAX), .flags = UPDATE_VD},
109+ {"vd-lavc-threads", OPT_INT(threads), M_RANGE(0, DBL_MAX)},
115110 {"vd-lavc-bitexact", OPT_BOOL(bitexact)},
116111 {"vd-lavc-assume-old-x264", OPT_BOOL(old_x264)},
117112 {"vd-lavc-check-hw-profile", OPT_BOOL(check_hw_profile)},
118− {"vd-lavc-software-fallback", OPT_CHOICE(software_fallback,
119− {"no", INT_MAX}, {"yes", 1}), M_RANGE(1, INT_MAX)},
120113 {"vd-lavc-o", OPT_KEYVALUELIST(avopts)},
121114 {"vd-lavc-dr", OPT_CHOICE(dr,
122115 {"auto", -1}, {"no", 0}, {"yes", 1})},
123116 {"vd-apply-cropping", OPT_BOOL(apply_cropping)},
124− {"hwdec", OPT_STRINGLIST(hwdec_api),
125− .help = hwdec_opt_help,
126− .flags = M_OPT_OPTIONAL_PARAM | M_OPT_ALLOW_NO | UPDATE_HWDEC},
127− {"hwdec-codecs", OPT_STRING(hwdec_codecs)},
128− {"hwdec-image-format", OPT_IMAGEFORMAT(hwdec_image_format)},
129− {"hwdec-extra-frames", OPT_INT(hwdec_extra_frames), M_RANGE(0, 256)},
130117 {0}
131118 },
119+ .change_flags = UPDATE_VD,
132120 .size = sizeof(struct vd_lavc_params),
133121 .defaults = &(const struct vd_lavc_params){
134122 .film_grain = -1 /*auto*/,
135123 .check_hw_profile = true,
136− .software_fallback = 3,
137124 .skip_loop_filter = AVDISCARD_DEFAULT,
138125 .skip_idct = AVDISCARD_DEFAULT,
139126 .skip_frame = AVDISCARD_DEFAULT,
140127 .framedrop = AVDISCARD_NONREF,
141128 .dr = -1,
129+ .apply_cropping = true,
130+ },
131+};
132+
133+#undef OPT_BASE_STRUCT
134+#define OPT_BASE_STRUCT struct hwdec_opts
135+
136+struct hwdec_opts {
137+ int software_fallback;
138+ char **hwdec_api;
139+ char *hwdec_codecs;
140+ int hwdec_image_format;
141+ int hwdec_extra_frames;
142+};
143+
144+const struct m_sub_options hwdec_conf = {
145+ .opts = (const m_option_t[]){
146+ {"hwdec", OPT_STRINGLIST(hwdec_api),
147+ .help = hwdec_opt_help,
148+ .flags = M_OPT_OPTIONAL_PARAM | M_OPT_ALLOW_NO | UPDATE_HWDEC},
149+ {"hwdec-codecs", OPT_STRING(hwdec_codecs),
150+ .flags = UPDATE_HWDEC},
151+ {"hwdec-extra-frames", OPT_INT(hwdec_extra_frames), M_RANGE(0, 256),
152+ .flags = UPDATE_VD},
153+ {"hwdec-image-format", OPT_IMAGEFORMAT(hwdec_image_format),
154+ .flags = UPDATE_VO},
155+ {"hwdec-software-fallback", OPT_CHOICE(software_fallback,
156+ {"no", INT_MAX}, {"yes", 1}), M_RANGE(1, INT_MAX),
157+ .flags = UPDATE_HWDEC},
158+ {"vd-lavc-software-fallback", OPT_REPLACED("hwdec-software-fallback")},
159+ {0}
160+ },
161+ .size = sizeof(struct hwdec_opts),
162+ .defaults = &(const struct hwdec_opts){
163+ .software_fallback = 3,
142164 .hwdec_api = (char *[]){"no", NULL,},
143165 .hwdec_codecs = "h264,vc1,hevc,vp8,vp9,av1,prores",
144166 // Maximum number of surfaces the player wants to buffer. This number
@@ -146,7 +168,6 @@ const struct m_sub_options vd_lavc_conf = { · 1 unmodified line
146168 // for example, if vo_gpu increases the number of reference surfaces for
147169 // interpolation, this value has to be increased too.
148170 .hwdec_extra_frames = 6,
149− .apply_cropping = true,
150171 },
151172 };
152173
@@ -170,6 +191,8 @@ typedef struct lavc_ctx { · 17 unmodified lines
170191 struct mp_log *log;
171192 struct m_config_cache *opts_cache;
172193 struct vd_lavc_params *opts;
194+ struct m_config_cache *hwdec_opts_cache;
195+ struct hwdec_opts *hwdec_opts;
173196 struct mp_codec_params *codec;
174197 AVCodecContext *avctx;
175198 AVFrame *pic;
@@ -418,7 +441,7 @@ static void add_all_hwdec_methods(struct hwdec_info **infos, int *num_infos) · 242 unmodified lines
418441 static bool hwdec_codec_allowed(struct mp_filter *vd, const char *codec)
419442 {
420443 vd_ffmpeg_ctx *ctx = vd->priv;
421− bstr s = bstr0(ctx->opts->hwdec_codecs);
444+ bstr s = bstr0(ctx->hwdec_opts->hwdec_codecs);
422445 while (s.len) {
423446 bstr item;
424447 bstr_split_tok(s, ",", &item, &s);
@@ -473,13 +496,13 @@ static void select_and_set_hwdec(struct mp_filter *vd) · 48 unmodified lines
473496 vd_ffmpeg_ctx *ctx = vd->priv;
474497 const char *codec = ctx->codec->codec;
475498
476− m_config_cache_update(ctx->opts_cache);
499+ m_config_cache_update(ctx->hwdec_opts_cache);
477500
478501 struct hwdec_info *hwdecs = NULL;
479502 int num_hwdecs = 0;
480503 add_all_hwdec_methods(&hwdecs, &num_hwdecs);
481504
482− char **hwdec_api = ctx->opts->hwdec_api;
505+ char **hwdec_api = ctx->hwdec_opts->hwdec_api;
483506 for (int i = 0; hwdec_api && hwdec_api[i]; i++) {
484507 bstr opt = bstr0(hwdec_api[i]);
485508
@@ -597,7 +620,7 @@ static void select_and_set_hwdec(struct mp_filter *vd) · 111 unmodified lines
597620 } else {
598621 // If software fallback is disabled and we get here, all hwdec must
599622 // have failed. Tell the ctx to always force an eof.
600− if (ctx->opts->software_fallback == INT_MAX) {
623+ if (ctx->hwdec_opts->software_fallback == INT_MAX) {
601624 MP_WARN(ctx, "Software decoding fallback is disabled.\n");
602625 ctx->force_eof = true;
603626 } else {
@@ -905,13 +928,13 @@ static int init_generic_hwaccel(struct mp_filter *vd, enum AVPixelFormat hw_fmt) · 301 unmodified lines
905928
906929 AVHWFramesContext *new_fctx = (void *)new_frames_ctx->data;
907930
908− if (ctx->opts->hwdec_image_format)
909− new_fctx->sw_format = imgfmt2pixfmt(ctx->opts->hwdec_image_format);
931+ if (ctx->hwdec_opts->hwdec_image_format)
932+ new_fctx->sw_format = imgfmt2pixfmt(ctx->hwdec_opts->hwdec_image_format);
910933
911934 // 1 surface is already included by libavcodec. The field is 0 if the
912935 // hwaccel supports dynamic surface allocation.
913936 if (new_fctx->initial_pool_size)
914− new_fctx->initial_pool_size += ctx->opts->hwdec_extra_frames - 1;
937+ new_fctx->initial_pool_size += ctx->hwdec_opts->hwdec_extra_frames - 1;
915938
916939 const struct hwcontext_fns *fns =
917940 hwdec_get_hwcontext_fns(new_fctx->device_ctx->type);
@@ -1112,14 +1135,14 @@ static void prepare_decoding(struct mp_filter *vd) · 194 unmodified lines
11121135 static void handle_err(struct mp_filter *vd)
11131136 {
11141137 vd_ffmpeg_ctx *ctx = vd->priv;
1115− struct vd_lavc_params *opts = ctx->opts;
1138+ struct hwdec_opts *hwdec_opts = ctx->hwdec_opts;
11161139
11171140 MP_WARN(vd, "Error while decoding frame%s!\n",
11181141 ctx->use_hwdec ? " (hardware decoding)" : "");
11191142
11201143 if (ctx->use_hwdec) {
11211144 ctx->hwdec_fail_count += 1;
1122− if (ctx->hwdec_fail_count >= opts->software_fallback)
1145+ if (ctx->hwdec_fail_count >= hwdec_opts->software_fallback)
11231146 ctx->hwdec_failed = true;
11241147 }
11251148 }
@@ -1150,7 +1173,7 @@ static int send_packet(struct mp_filter *vd, struct demux_packet *pkt) · 24 unmodified lines
11501173 return ret;
11511174
11521175 if (ctx->hw_probing && ctx->num_sent_packets < 32 &&
1153− ctx->opts->software_fallback <= 32)
1176+ ctx->hwdec_opts->software_fallback <= 32)
11541177 {
11551178 pkt = pkt ? demux_copy_packet(pkt) : NULL;
11561179 MP_TARRAY_APPEND(ctx, ctx->sent_packets, ctx->num_sent_packets, pkt);
@@ -1406,6 +1429,8 @@ static struct mp_decoder *create(struct mp_filter *parent, · 249 unmodified lines
14061429 ctx->log = vd->log;
14071430 ctx->opts_cache = m_config_cache_alloc(ctx, vd->global, &vd_lavc_conf);
14081431 ctx->opts = ctx->opts_cache->opts;
1432+ ctx->hwdec_opts_cache = m_config_cache_alloc(ctx, vd->global, &hwdec_conf);
1433+ ctx->hwdec_opts = ctx->hwdec_opts_cache->opts;
14091434 ctx->codec = codec;
14101435 ctx->decoder = talloc_strdup(ctx, decoder);
14111436 ctx->hwdec_swpool = mp_image_pool_new(ctx);

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