+ }
+ config = &hw_config->public;
+
+ if (config->methods &
+ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
+ avctx->hw_frames_ctx) {
+ const AVHWFramesContext *frames_ctx =
+ (AVHWFramesContext*)avctx->hw_frames_ctx->data;
+ if (frames_ctx->format != user_choice) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
+ "does not match the format of the provided frames "
+ "context.\n", desc->name);
+ goto try_again;
+ }
+ } else if (config->methods &
+ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
+ avctx->hw_device_ctx) {
+ const AVHWDeviceContext *device_ctx =
+ (AVHWDeviceContext*)avctx->hw_device_ctx->data;
+ if (device_ctx->type != config->device_type) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
+ "does not match the type of the provided device "
+ "context.\n", desc->name);
+ goto try_again;
+ }
+ } else if (config->methods &
+ AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
+ // Internal-only setup, no additional configuration.
+ } else if (config->methods &
+ AV_CODEC_HW_CONFIG_METHOD_AD_HOC) {
+ // Some ad-hoc configuration we can't see and can't check.
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
+ "missing configuration.\n", desc->name);
+ goto try_again;
+ }
+ if (hw_config->hwaccel) {
+ av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
+ "initialisation.\n", desc->name);
+ err = hwaccel_init(avctx, hw_config);
+ if (err < 0)
+ goto try_again;
+ }
+ ret = user_choice;
+ break;