Lines Matching refs:ctx
45 VAAPIEncodeContext *ctx = avctx->priv_data;
60 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
71 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
91 VAAPIEncodeContext *ctx = avctx->priv_data;
101 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
141 VAAPIEncodeContext *ctx = avctx->priv_data;
156 if (ctx->has_sync_buffer_func) {
157 vas = vaSyncBuffer(ctx->hwctx->display,
168 vas = vaSyncSurface(ctx->hwctx->display, pic->input_surface);
186 VAAPIEncodeContext *ctx = avctx->priv_data;
191 pic->slices[i].row_size = ctx->slice_size;
193 rounding = ctx->slice_block_rows - ctx->nb_slices * ctx->slice_size;
211 av_assert0(rounding < ctx->slice_size);
226 slice->block_size = slice->row_size * ctx->slice_block_cols;
241 VAAPIEncodeContext *ctx = avctx->priv_data;
245 for (i = 0; i < ctx->tile_cols; i++) {
246 for (j = 0; j < ctx->tile_rows; j++) {
247 index = j * ctx->tile_cols + i;
251 pic->slices[index].block_start = ctx->col_bd[i] +
252 ctx->row_bd[j] * ctx->slice_block_cols;
253 pic->slices[index].block_size = ctx->row_height[j] * ctx->col_width[i];
256 "width:%2d height:%2d (%d blocks).\n", index, ctx->col_bd[i],
257 ctx->row_bd[j], slice->block_start, ctx->col_width[i],
258 ctx->row_height[j], slice->block_size);
268 VAAPIEncodeContext *ctx = avctx->priv_data;
304 err = av_hwframe_get_buffer(ctx->recon_frames_ref, pic->recon_image, 0);
312 pic->output_buffer_ref = av_buffer_pool_get(ctx->output_buffer_pool);
321 if (ctx->codec->picture_params_size > 0) {
322 pic->codec_picture_params = av_malloc(ctx->codec->picture_params_size);
325 memcpy(pic->codec_picture_params, ctx->codec_picture_params,
326 ctx->codec->picture_params_size);
328 av_assert0(!ctx->codec_picture_params);
333 if (pic->type == PICTURE_TYPE_IDR && ctx->codec->init_sequence_params) {
336 ctx->codec_sequence_params,
337 ctx->codec->sequence_params_size);
343 for (i = 0; i < ctx->nb_global_params; i++) {
345 ctx->global_params_type[i],
346 ctx->global_params[i],
347 ctx->global_params_size[i]);
353 if (ctx->codec->init_picture_params) {
354 err = ctx->codec->init_picture_params(avctx, pic);
363 ctx->codec->picture_params_size);
369 if (ctx->max_frame_size) {
372 &ctx->mfs_params,
373 sizeof(ctx->mfs_params));
380 if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE &&
381 ctx->codec->write_sequence_header) {
383 err = ctx->codec->write_sequence_header(avctx, data, &bit_len);
390 ctx->codec->sequence_header_type,
397 if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_PICTURE &&
398 ctx->codec->write_picture_header) {
400 err = ctx->codec->write_picture_header(avctx, pic, data, &bit_len);
407 ctx->codec->picture_header_type,
413 if (ctx->codec->write_extra_buffer) {
417 err = ctx->codec->write_extra_buffer(avctx, pic, i, &type,
434 if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_MISC &&
435 ctx->codec->write_extra_header) {
439 err = ctx->codec->write_extra_header(avctx, pic, i, &type,
457 pic->nb_slices = ctx->nb_slices;
465 if (ctx->tile_rows && ctx->tile_cols)
474 if (ctx->codec->slice_params_size > 0) {
475 slice->codec_slice_params = av_mallocz(ctx->codec->slice_params_size);
482 if (ctx->codec->init_slice_params) {
483 err = ctx->codec->init_slice_params(avctx, pic, slice);
491 if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SLICE &&
492 ctx->codec->write_slice_header) {
494 err = ctx->codec->write_slice_header(avctx, pic, slice,
502 ctx->codec->slice_header_type,
508 if (ctx->codec->init_slice_params) {
512 ctx->codec->slice_params_size);
521 if (sd && ctx->roi_allowed) {
531 if (nb_roi > ctx->roi_max_regions) {
532 if (!ctx->roi_warned) {
535 nb_roi, ctx->roi_max_regions);
536 ctx->roi_warned = 1;
538 nb_roi = ctx->roi_max_regions;
551 v = roi->qoffset.num * ctx->roi_quant_range / roi->qoffset.den;
583 vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context,
592 vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
601 vas = vaEndPicture(ctx->hwctx->display, ctx->va_context);
608 if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
615 if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
618 vas = vaDestroyBuffer(ctx->hwctx->display,
634 vaEndPicture(ctx->hwctx->display, ctx->va_context);
637 vaDestroyBuffer(ctx->hwctx->display, pic->param_buffers[i]);
656 VAAPIEncodeContext *ctx = avctx->priv_data;
668 vas = vaMapBuffer(ctx->hwctx->display, pic->output_buffer,
699 vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
715 vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
741 VAAPIEncodeContext *ctx = avctx->priv_data;
748 if (ctx->codec->picture_priv_data_size > 0) {
749 pic->priv_data = av_mallocz(ctx->codec->picture_priv_data_size);
861 VAAPIEncodeContext *ctx = avctx->priv_data;
870 if (current_depth == ctx->max_b_depth || start->next->next == end) {
921 VAAPIEncodeContext *ctx = avctx->priv_data;
928 for (pic = ctx->pic_start; pic; pic = pic->next) {
952 closed_gop_end = ctx->closed_gop ||
953 ctx->idr_counter == ctx->gop_per_idr;
954 for (pic = ctx->pic_start; pic; pic = next) {
964 if (b_counter == ctx->b_per_p)
968 if (ctx->gop_counter + b_counter + closed_gop_end >= ctx->gop_size)
978 if (!pic && ctx->end_of_stream) {
980 pic = ctx->pic_end;
992 if (ctx->input_order <= ctx->decode_delay && !ctx->end_of_stream) {
1002 ctx->idr_counter = 1;
1003 ctx->gop_counter = 1;
1005 } else if (ctx->gop_counter + b_counter >= ctx->gop_size) {
1006 if (ctx->idr_counter == ctx->gop_per_idr) {
1010 ctx->idr_counter = 1;
1015 ++ctx->idr_counter;
1017 ctx->gop_counter = 1;
1020 if (ctx->gop_counter + b_counter + closed_gop_end == ctx->gop_size) {
1029 ctx->gop_counter += 1 + b_counter;
1039 vaapi_encode_add_ref(avctx, pic, ctx->next_prev, 0, 0, 1);
1041 if (ctx->next_prev)
1042 --ctx->next_prev->ref_count[0];
1046 &ctx->next_prev);
1048 ctx->next_prev = pic;
1050 ++ctx->next_prev->ref_count[0];
1056 VAAPIEncodeContext *ctx = avctx->priv_data;
1059 av_assert0(ctx->pic_start);
1062 for (pic = ctx->pic_start; pic; pic = pic->next) {
1068 for (pic = ctx->pic_start; pic; pic = pic->next) {
1075 for (pic = ctx->pic_start; pic; pic = next) {
1082 ctx->pic_start = next;
1095 VAAPIEncodeContext *ctx = avctx->priv_data;
1098 frame->crop_left || frame->crop_right) && !ctx->crop_warned) {
1101 ctx->crop_warned = 1;
1104 if (!ctx->roi_allowed) {
1108 if (sd && !ctx->roi_warned) {
1111 ctx->roi_warned = 1;
1120 VAAPIEncodeContext *ctx = avctx->priv_data;
1142 if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I)
1150 if (ctx->input_order == 0)
1151 ctx->first_pts = pic->pts;
1152 if (ctx->input_order == ctx->decode_delay)
1153 ctx->dts_pts_diff = pic->pts - ctx->first_pts;
1154 if (ctx->output_delay > 0)
1155 ctx->ts_ring[ctx->input_order %
1156 (3 * ctx->output_delay + ctx->async_depth)] = pic->pts;
1158 pic->display_order = ctx->input_order;
1159 ++ctx->input_order;
1161 if (ctx->pic_start) {
1162 ctx->pic_end->next = pic;
1163 ctx->pic_end = pic;
1165 ctx->pic_start = pic;
1166 ctx->pic_end = pic;
1170 ctx->end_of_stream = 1;
1174 if (ctx->input_order < ctx->decode_delay)
1175 ctx->dts_pts_diff = ctx->pic_end->pts - ctx->first_pts;
1187 VAAPIEncodeContext *ctx = avctx->priv_data;
1189 AVFrame *frame = ctx->frame;
1203 if (!ctx->pic_start) {
1204 if (ctx->end_of_stream)
1210 if (ctx->has_sync_buffer_func) {
1213 if (av_fifo_can_write(ctx->encode_fifo)) {
1217 pic->encode_order = ctx->encode_order +
1218 av_fifo_can_read(ctx->encode_fifo);
1224 av_fifo_write(ctx->encode_fifo, &pic, 1);
1228 if (!av_fifo_can_read(ctx->encode_fifo))
1232 if (av_fifo_can_write(ctx->encode_fifo) && !ctx->end_of_stream)
1235 av_fifo_read(ctx->encode_fifo, &pic, 1);
1236 ctx->encode_order = pic->encode_order + 1;
1244 pic->encode_order = ctx->encode_order++;
1259 if (ctx->output_delay == 0) {
1261 } else if (pic->encode_order < ctx->decode_delay) {
1262 if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
1265 pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
1267 pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
1268 (3 * ctx->output_delay + ctx->async_depth)];
1273 ctx->output_order = pic->encode_order;
1283 VAAPIEncodeContext *ctx = avctx->priv_data;
1285 av_assert0(ctx->nb_global_params < MAX_GLOBAL_PARAMS);
1287 ctx->global_params_type[ctx->nb_global_params] = type;
1288 ctx->global_params [ctx->nb_global_params] = buffer;
1289 ctx->global_params_size[ctx->nb_global_params] = size;
1291 ++ctx->nb_global_params;
1334 VAAPIEncodeContext *ctx = avctx->priv_data;
1347 if (ctx->low_power) {
1359 desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format);
1362 ctx->input_frames->sw_format);
1376 n = vaMaxNumProfiles(ctx->hwctx->display);
1382 vas = vaQueryConfigProfiles(ctx->hwctx->display, va_profiles, &n);
1390 av_assert0(ctx->codec->profiles);
1391 for (i = 0; (ctx->codec->profiles[i].av_profile !=
1393 profile = &ctx->codec->profiles[i];
1422 ctx->profile = profile;
1425 if (!ctx->profile) {
1432 ctx->va_profile = profile->va_profile;
1434 profile_string, ctx->va_profile);
1436 n = vaMaxNumEntrypoints(ctx->hwctx->display);
1442 vas = vaQueryConfigEntrypoints(ctx->hwctx->display, ctx->va_profile,
1447 ctx->va_profile, vas, vaErrorStr(vas));
1462 "for profile %s (%d).\n", profile_string, ctx->va_profile);
1467 ctx->va_entrypoint = va_entrypoints[i];
1469 entrypoint_string = vaEntrypointStr(ctx->va_entrypoint);
1474 entrypoint_string, ctx->va_entrypoint);
1487 profile_string, ctx->va_profile,
1488 entrypoint_string, ctx->va_entrypoint);
1494 vas = vaGetConfigAttributes(ctx->hwctx->display,
1495 ctx->va_profile, ctx->va_entrypoint,
1511 rt_format->name, profile_string, ctx->va_profile,
1512 entrypoint_string, ctx->va_entrypoint);
1518 ctx->config_attributes[ctx->nb_config_attributes++] =
1555 VAAPIEncodeContext *ctx = avctx->priv_data;
1569 vas = vaGetConfigAttributes(ctx->hwctx->display,
1570 ctx->va_profile, ctx->va_entrypoint,
1638 if (ctx->explicit_rc_mode)
1639 TRY_RC_MODE(ctx->explicit_rc_mode, 1);
1641 if (ctx->explicit_qp)
1644 if (ctx->codec->flags & FLAG_CONSTANT_QUALITY_ONLY)
1736 if (ctx->explicit_qp) {
1737 rc_quality = ctx->explicit_qp;
1741 rc_quality = ctx->codec->default_quality;
1793 ctx->rc_mode = rc_mode;
1794 ctx->rc_quality = rc_quality;
1795 ctx->va_rc_mode = rc_mode->va_mode;
1796 ctx->va_bit_rate = rc_bits_per_second;
1802 ctx->config_attributes[ctx->nb_config_attributes++] =
1805 .value = ctx->va_rc_mode,
1824 ctx->rc_params = (VAEncMiscParameterRateControl) {
1841 &ctx->rc_params,
1842 sizeof(ctx->rc_params));
1850 ctx->hrd_params = (VAEncMiscParameterHRD) {
1856 &ctx->hrd_params,
1857 sizeof(ctx->hrd_params));
1870 ctx->fr_params = (VAEncMiscParameterFrameRate) {
1876 &ctx->fr_params,
1877 sizeof(ctx->fr_params));
1886 VAAPIEncodeContext *ctx = avctx->priv_data;
1890 if (ctx->va_rc_mode == VA_RC_CQP) {
1891 ctx->max_frame_size = 0;
1897 vas = vaGetConfigAttributes(ctx->hwctx->display,
1898 ctx->va_profile,
1899 ctx->va_entrypoint,
1902 ctx->max_frame_size = 0;
1909 ctx->max_frame_size = 0;
1918 ctx->max_frame_size = 0;
1924 ctx->mfs_params = (VAEncMiscParameterBufferMaxFrameSize){
1925 .max_frame_size = ctx->max_frame_size * 8,
1929 ctx->max_frame_size);
1942 VAAPIEncodeContext *ctx = avctx->priv_data;
1948 vas = vaGetConfigAttributes(ctx->hwctx->display,
1949 ctx->va_profile,
1950 ctx->va_entrypoint,
1965 ctx->p_to_gpb = 0;
1969 if (!(ctx->codec->flags & FLAG_INTRA_ONLY ||
1972 vas = vaGetConfigAttributes(ctx->hwctx->display,
1973 ctx->va_profile,
1974 ctx->va_entrypoint,
2001 ctx->p_to_gpb = 1;
2010 if (ctx->codec->flags & FLAG_INTRA_ONLY ||
2013 ctx->gop_size = 1;
2018 } else if (!(ctx->codec->flags & FLAG_B_PICTURES) ||
2021 if (ctx->p_to_gpb)
2028 ctx->gop_size = avctx->gop_size;
2029 ctx->p_per_i = INT_MAX;
2030 ctx->b_per_p = 0;
2032 if (ctx->p_to_gpb)
2039 ctx->gop_size = avctx->gop_size;
2040 ctx->p_per_i = INT_MAX;
2041 ctx->b_per_p = avctx->max_b_frames;
2042 if (ctx->codec->flags & FLAG_B_PICTURE_REFERENCES) {
2043 ctx->max_b_depth = FFMIN(ctx->desired_b_depth,
2044 av_log2(ctx->b_per_p) + 1);
2046 ctx->max_b_depth = 1;
2050 if (ctx->codec->flags & FLAG_NON_IDR_KEY_PICTURES) {
2051 ctx->closed_gop = !!(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
2052 ctx->gop_per_idr = ctx->idr_interval + 1;
2054 ctx->closed_gop = 1;
2055 ctx->gop_per_idr = 1;
2064 VAAPIEncodeContext *ctx = avctx->priv_data;
2072 if (avctx->slices > ctx->slice_block_rows) {
2075 "maximum.\n", ctx->slice_block_rows, avctx->slices);
2076 req_slices = ctx->slice_block_rows;
2082 ctx->nb_slices = req_slices;
2083 ctx->slice_size = ctx->slice_block_rows / ctx->nb_slices;
2087 if (2 * k * (req_slices - 1) + 1 >= ctx->slice_block_rows)
2090 ctx->nb_slices = (ctx->slice_block_rows + k - 1) / k;
2091 ctx->slice_size = k;
2094 ctx->nb_slices = ctx->slice_block_rows;
2095 ctx->slice_size = 1;
2109 VAAPIEncodeContext *ctx = avctx->priv_data;
2114 ctx->tile_cols == 1))) {
2120 if (ctx->tile_rows > ctx->slice_block_rows ||
2121 ctx->tile_cols > ctx->slice_block_cols) {
2124 ctx->slice_block_rows, ctx->slice_block_cols,
2125 ctx->tile_rows, ctx->tile_cols);
2126 ctx->tile_rows = ctx->tile_rows > ctx->slice_block_rows ?
2127 ctx->slice_block_rows : ctx->tile_rows;
2128 ctx->tile_cols = ctx->tile_cols > ctx->slice_block_cols ?
2129 ctx->slice_block_cols : ctx->tile_cols;
2131 ctx->tile_rows, ctx->tile_cols);
2134 req_tiles = ctx->tile_rows * ctx->tile_cols;
2145 ctx->nb_slices = req_tiles;
2149 for (i = 0; i < ctx->tile_cols; i++) {
2150 ctx->col_width[i] = ( i + 1 ) * ctx->slice_block_cols / ctx->tile_cols -
2151 i * ctx->slice_block_cols / ctx->tile_cols;
2152 ctx->col_bd[i + 1] = ctx->col_bd[i] + ctx->col_width[i];
2155 for (i = 0; i < ctx->tile_rows; i++) {
2156 ctx->row_height[i] = ( i + 1 ) * ctx->slice_block_rows / ctx->tile_rows -
2157 i * ctx->slice_block_rows / ctx->tile_rows;
2158 ctx->row_bd[i + 1] = ctx->row_bd[i] + ctx->row_height[i];
2162 ctx->tile_rows, ctx->tile_cols);
2169 VAAPIEncodeContext *ctx = avctx->priv_data;
2180 if (!(ctx->codec->flags & FLAG_SLICE_CONTROL)) {
2188 av_assert0(ctx->slice_block_height > 0 && ctx->slice_block_width > 0);
2190 ctx->slice_block_rows = (avctx->height + ctx->slice_block_height - 1) /
2191 ctx->slice_block_height;
2192 ctx->slice_block_cols = (avctx->width + ctx->slice_block_width - 1) /
2193 ctx->slice_block_width;
2195 if (avctx->slices <= 1 && !ctx->tile_rows && !ctx->tile_cols) {
2196 ctx->nb_slices = 1;
2197 ctx->slice_size = ctx->slice_block_rows;
2201 vas = vaGetConfigAttributes(ctx->hwctx->display,
2202 ctx->va_profile,
2203 ctx->va_entrypoint,
2219 if (ctx->tile_rows && ctx->tile_cols) {
2234 if (ctx->tile_rows && ctx->tile_cols)
2241 if (ctx->nb_slices > avctx->slices) {
2244 "structure.\n", ctx->nb_slices, avctx->slices);
2246 if (ctx->nb_slices > max_slices) {
2249 ctx->nb_slices, max_slices);
2254 ctx->nb_slices);
2260 VAAPIEncodeContext *ctx = avctx->priv_data;
2264 vas = vaGetConfigAttributes(ctx->hwctx->display,
2265 ctx->va_profile,
2266 ctx->va_entrypoint,
2275 if (ctx->desired_packed_headers) {
2278 ctx->desired_packed_headers);
2283 ctx->va_packed_headers = 0;
2285 if (ctx->desired_packed_headers & ~attr.value) {
2288 ctx->desired_packed_headers, attr.value);
2292 ctx->desired_packed_headers, attr.value);
2294 ctx->va_packed_headers = ctx->desired_packed_headers & attr.value;
2297 if (ctx->va_packed_headers) {
2298 ctx->config_attributes[ctx->nb_config_attributes++] =
2301 .value = ctx->va_packed_headers,
2305 if ( (ctx->desired_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE) &&
2306 !(ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE) &&
2321 VAAPIEncodeContext *ctx = avctx->priv_data;
2326 vas = vaGetConfigAttributes(ctx->hwctx->display,
2327 ctx->va_profile,
2328 ctx->va_entrypoint,
2349 ctx->quality_params = (VAEncMiscParameterBufferQualityLevel) {
2354 &ctx->quality_params,
2355 sizeof(ctx->quality_params));
2368 VAAPIEncodeContext *ctx = avctx->priv_data;
2372 vas = vaGetConfigAttributes(ctx->hwctx->display,
2373 ctx->va_profile,
2374 ctx->va_entrypoint,
2383 ctx->roi_allowed = 0;
2389 ctx->roi_max_regions = roi.bits.num_roi_regions;
2390 ctx->roi_allowed = ctx->roi_max_regions > 0 &&
2391 (ctx->va_rc_mode == VA_RC_CQP ||
2402 VAAPIEncodeContext *ctx = avctx->priv_data;
2407 vaDestroyBuffer(ctx->hwctx->display, buffer_id);
2416 VAAPIEncodeContext *ctx = avctx->priv_data;
2425 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
2427 3 * ctx->surface_width * ctx->surface_height +
2442 vaDestroyBuffer(ctx->hwctx->display, buffer_id);
2451 VAAPIEncodeContext *ctx = avctx->priv_data;
2457 hwconfig = av_hwdevice_hwconfig_alloc(ctx->device_ref);
2462 hwconfig->config_id = ctx->va_config;
2464 constraints = av_hwdevice_get_hwframe_constraints(ctx->device_ref,
2477 if (ctx->input_frames->sw_format ==
2479 recon_format = ctx->input_frames->sw_format;
2490 recon_format = ctx->input_frames->sw_format;
2495 if (ctx->surface_width < constraints->min_width ||
2496 ctx->surface_height < constraints->min_height ||
2497 ctx->surface_width > constraints->max_width ||
2498 ctx->surface_height > constraints->max_height) {
2501 ctx->surface_width, ctx->surface_height,
2511 ctx->recon_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
2512 if (!ctx->recon_frames_ref) {
2516 ctx->recon_frames = (AVHWFramesContext*)ctx->recon_frames_ref->data;
2518 ctx->recon_frames->format = AV_PIX_FMT_VAAPI;
2519 ctx->recon_frames->sw_format = recon_format;
2520 ctx->recon_frames->width = ctx->surface_width;
2521 ctx->recon_frames->height = ctx->surface_height;
2523 err = av_hwframe_ctx_init(ctx->recon_frames_ref);
2539 VAAPIEncodeContext *ctx = avctx->priv_data;
2544 ctx->va_config = VA_INVALID_ID;
2545 ctx->va_context = VA_INVALID_ID;
2549 ctx->frame = av_frame_alloc();
2550 if (!ctx->frame) {
2560 ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
2561 if (!ctx->input_frames_ref) {
2565 ctx->input_frames = (AVHWFramesContext*)ctx->input_frames_ref->data;
2567 ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
2568 if (!ctx->device_ref) {
2572 ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
2573 ctx->hwctx = ctx->device->hwctx;
2579 if (ctx->codec->get_encoder_caps) {
2580 err = ctx->codec->get_encoder_caps(avctx);
2585 ctx->surface_width = FFALIGN(avctx->width, 16);
2586 ctx->surface_height = FFALIGN(avctx->height, 16);
2587 if (ctx->codec->flags & FLAG_SLICE_CONTROL) {
2588 ctx->slice_block_width = 16;
2589 ctx->slice_block_height = 16;
2619 if (ctx->max_frame_size) {
2625 vas = vaCreateConfig(ctx->hwctx->display,
2626 ctx->va_profile, ctx->va_entrypoint,
2627 ctx->config_attributes, ctx->nb_config_attributes,
2628 &ctx->va_config);
2640 recon_hwctx = ctx->recon_frames->hwctx;
2641 vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
2642 ctx->surface_width, ctx->surface_height,
2646 &ctx->va_context);
2654 ctx->output_buffer_pool =
2657 if (!ctx->output_buffer_pool) {
2662 if (ctx->codec->configure) {
2663 err = ctx->codec->configure(avctx);
2668 ctx->output_delay = ctx->b_per_p;
2669 ctx->decode_delay = ctx->max_b_depth;
2671 if (ctx->codec->sequence_params_size > 0) {
2672 ctx->codec_sequence_params =
2673 av_mallocz(ctx->codec->sequence_params_size);
2674 if (!ctx->codec_sequence_params) {
2679 if (ctx->codec->picture_params_size > 0) {
2680 ctx->codec_picture_params =
2681 av_mallocz(ctx->codec->picture_params_size);
2682 if (!ctx->codec_picture_params) {
2688 if (ctx->codec->init_sequence_params) {
2689 err = ctx->codec->init_sequence_params(avctx);
2697 if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE &&
2698 ctx->codec->write_sequence_header &&
2703 err = ctx->codec->write_sequence_header(avctx, data, &bit_len);
2722 vas = vaSyncBuffer(ctx->hwctx->display, VA_INVALID_ID, 0);
2724 ctx->has_sync_buffer_func = 1;
2725 ctx->encode_fifo = av_fifo_alloc2(ctx->async_depth,
2728 if (!ctx->encode_fifo)
2741 VAAPIEncodeContext *ctx = avctx->priv_data;
2744 /* We check ctx->frame to know whether ff_vaapi_encode_init()
2746 if (!ctx->frame)
2749 for (pic = ctx->pic_start; pic; pic = next) {
2754 av_buffer_pool_uninit(&ctx->output_buffer_pool);
2756 if (ctx->va_context != VA_INVALID_ID) {
2757 if (ctx->hwctx)
2758 vaDestroyContext(ctx->hwctx->display, ctx->va_context);
2759 ctx->va_context = VA_INVALID_ID;
2762 if (ctx->va_config != VA_INVALID_ID) {
2763 if (ctx->hwctx)
2764 vaDestroyConfig(ctx->hwctx->display, ctx->va_config);
2765 ctx->va_config = VA_INVALID_ID;
2768 av_frame_free(&ctx->frame);
2770 av_freep(&ctx->codec_sequence_params);
2771 av_freep(&ctx->codec_picture_params);
2772 av_fifo_freep2(&ctx->encode_fifo);
2774 av_buffer_unref(&ctx->recon_frames_ref);
2775 av_buffer_unref(&ctx->input_frames_ref);
2776 av_buffer_unref(&ctx->device_ref);