History

lavfi/vf_hwupload: validate the hw device in init

Rather than query_formats(). Init is a more appropriate place, as query_formats() is supposed to be free of side-effects.

Anton Khirnov committed 2 years ago

Commit 03633621 parent 01458a01 file · +28 −21Browse files

Unified · Split

libavfilter/vf_hwupload.c+28−21
@@ -39,35 +39,41 @@ typedef struct HWUploadContext { · 38 unmodified lines
3939 char *device_type;
4040 } HWUploadContext;
4141
42−static int hwupload_query_formats(AVFilterContext *avctx)
42+static int hwupload_init(AVFilterContext *avctx)
4343 {
4444 HWUploadContext *ctx = avctx->priv;
45− AVHWFramesConstraints *constraints = NULL;
46− const enum AVPixelFormat *input_pix_fmts, *output_pix_fmts;
47− AVFilterFormats *input_formats = NULL;
48− int err, i;
45+ int err;
4946
50− if (ctx->hwdevice_ref) {
51− /* We already have a specified device. */
52− } else if (avctx->hw_device_ctx) {
53− if (ctx->device_type) {
54− err = av_hwdevice_ctx_create_derived(
55− &ctx->hwdevice_ref,
56− av_hwdevice_find_type_by_name(ctx->device_type),
57− avctx->hw_device_ctx, 0);
58− if (err < 0)
59− return err;
60− } else {
61− ctx->hwdevice_ref = av_buffer_ref(avctx->hw_device_ctx);
62− if (!ctx->hwdevice_ref)
63− return AVERROR(ENOMEM);
64− }
65− } else {
47+ if (!avctx->hw_device_ctx) {
6648 av_log(ctx, AV_LOG_ERROR, "A hardware device reference is required "
6749 "to upload frames to.\n");
6850 return AVERROR(EINVAL);
6951 }
7052
53+ if (ctx->device_type) {
54+ err = av_hwdevice_ctx_create_derived(
55+ &ctx->hwdevice_ref,
56+ av_hwdevice_find_type_by_name(ctx->device_type),
57+ avctx->hw_device_ctx, 0);
58+ if (err < 0)
59+ return err;
60+ } else {
61+ ctx->hwdevice_ref = av_buffer_ref(avctx->hw_device_ctx);
62+ if (!ctx->hwdevice_ref)
63+ return AVERROR(ENOMEM);
64+ }
65+
66+ return 0;
67+}
68+
69+static int hwupload_query_formats(AVFilterContext *avctx)
70+{
71+ HWUploadContext *ctx = avctx->priv;
72+ AVHWFramesConstraints *constraints = NULL;
73+ const enum AVPixelFormat *input_pix_fmts, *output_pix_fmts;
74+ AVFilterFormats *input_formats = NULL;
75+ int err, i;
76+
7177 constraints = av_hwdevice_get_hwframe_constraints(ctx->hwdevice_ref, NULL);
7278 if (!constraints) {
7379 err = AVERROR(EINVAL);
@@ -253,6 +259,7 @@ static const AVFilterPad hwupload_outputs[] = { · 179 unmodified lines
253259 const AVFilter ff_vf_hwupload = {
254260 .name = "hwupload",
255261 .description = NULL_IF_CONFIG_SMALL("Upload a normal frame to a hardware frame"),
262+ .init = hwupload_init,
256263 .uninit = hwupload_uninit,
257264 .priv_size = sizeof(HWUploadContext),
258265 .priv_class = &hwupload_class,

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