- // Find the first format in the list which matches the expected
- // bit depth and subsampling. If none are found (this can happen
- // when 10-bit streams are decoded to 8-bit surfaces, for example)
- // then just take the first format on the list.
- ctx->surface_format = constraints->valid_sw_formats[0];
- sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
- for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
- desc = av_pix_fmt_desc_get(constraints->valid_sw_formats[i]);
- if (desc->nb_components != sw_desc->nb_components ||
- desc->log2_chroma_w != sw_desc->log2_chroma_w ||
- desc->log2_chroma_h != sw_desc->log2_chroma_h)
- continue;
- for (j = 0; j < desc->nb_components; j++) {
- if (desc->comp[j].depth != sw_desc->comp[j].depth)
- break;
+ if (frames_ref) {
+ AVHWFramesContext *frames = (AVHWFramesContext *)frames_ref->data;
+
+ frames->format = AV_PIX_FMT_VAAPI;
+ frames->width = avctx->coded_width;
+ frames->height = avctx->coded_height;
+
+ // Find the first format in the list which matches the expected
+ // bit depth and subsampling. If none are found (this can happen
+ // when 10-bit streams are decoded to 8-bit surfaces, for example)
+ // then just take the first format on the list.
+ frames->sw_format = constraints->valid_sw_formats[0];
+ sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
+ for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
+ desc = av_pix_fmt_desc_get(constraints->valid_sw_formats[i]);
+ if (desc->nb_components != sw_desc->nb_components ||
+ desc->log2_chroma_w != sw_desc->log2_chroma_w ||
+ desc->log2_chroma_h != sw_desc->log2_chroma_h)
+ continue;
+ for (j = 0; j < desc->nb_components; j++) {
+ if (desc->comp[j].depth != sw_desc->comp[j].depth)
+ break;
+ }
+ if (j < desc->nb_components)
+ continue;
+ frames->sw_format = constraints->valid_sw_formats[i];
+ break;