+static void nvdec_free_dummy(struct AVHWFramesContext *ctx)
+{
+ av_buffer_pool_uninit(&ctx->pool);
+}
+
+static AVBufferRef *nvdec_alloc_dummy(int size)
+{
+ return av_buffer_create(NULL, 0, NULL, NULL, 0);
+}
+
+static int nvdec_init_hwframes(AVCodecContext *avctx, AVBufferRef **out_frames_ref, int dummy)
+{
+ AVHWFramesContext *frames_ctx;
+ int ret;
+
+ ret = avcodec_get_hw_frames_parameters(avctx,
+ avctx->hw_device_ctx,
+ avctx->hwaccel->pix_fmt,
+ out_frames_ref);
+ if (ret < 0)
+ return ret;
+
+ frames_ctx = (AVHWFramesContext*)(*out_frames_ref)->data;
+
+ if (dummy) {
+ // Copied from ff_decode_get_hw_frames_ctx for compatibility
+ frames_ctx->initial_pool_size += 3;
+
+ frames_ctx->free = nvdec_free_dummy;
+ frames_ctx->pool = av_buffer_pool_init(0, nvdec_alloc_dummy);
+
+ if (!frames_ctx->pool) {
+ av_buffer_unref(out_frames_ref);
+ return AVERROR(ENOMEM);
+ }
+ } else {
+ // This is normally not used to actually allocate frames from
+ frames_ctx->initial_pool_size = 0;
+ }
+
+ ret = av_hwframe_ctx_init(*out_frames_ref);
+ if (ret < 0) {
+ av_buffer_unref(out_frames_ref);
+ return ret;
+ }
+
+ return 0;
+}
+