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
39 char *device_type;39 char *device_type;
40} HWUploadContext;40} HWUploadContext;
41 41
42static int hwupload_query_formats(AVFilterContext *avctx)42static int hwupload_init(AVFilterContext *avctx)
43{43{
44 HWUploadContext *ctx = avctx->priv;44 HWUploadContext *ctx = avctx->priv;
45 AVHWFramesConstraints *constraints = NULL;45 int err;
46 const enum AVPixelFormat *input_pix_fmts, *output_pix_fmts;
47 AVFilterFormats *input_formats = NULL;
48 int err, i;
49 46
50 if (ctx->hwdevice_ref) {47 if (!avctx->hw_device_ctx) {
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 {
66 av_log(ctx, AV_LOG_ERROR, "A hardware device reference is required "48 av_log(ctx, AV_LOG_ERROR, "A hardware device reference is required "
67 "to upload frames to.\n");49 "to upload frames to.\n");
68 return AVERROR(EINVAL);50 return AVERROR(EINVAL);
69 }51 }
70 52
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
69static 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
71 constraints = av_hwdevice_get_hwframe_constraints(ctx->hwdevice_ref, NULL);77 constraints = av_hwdevice_get_hwframe_constraints(ctx->hwdevice_ref, NULL);
72 if (!constraints) {78 if (!constraints) {
73 err = AVERROR(EINVAL);79 err = AVERROR(EINVAL);
@@ -253,6 +259,7 @@ static const AVFilterPad hwupload_outputs[] = { · 179 unmodified lines
253const AVFilter ff_vf_hwupload = {259const AVFilter ff_vf_hwupload = {
254 .name = "hwupload",260 .name = "hwupload",
255 .description = NULL_IF_CONFIG_SMALL("Upload a normal frame to a hardware frame"),261 .description = NULL_IF_CONFIG_SMALL("Upload a normal frame to a hardware frame"),
262 .init = hwupload_init,
256 .uninit = hwupload_uninit,263 .uninit = hwupload_uninit,
257 .priv_size = sizeof(HWUploadContext),264 .priv_size = sizeof(HWUploadContext),
258 .priv_class = &hwupload_class,265 .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