Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libavcodec/h264_sei.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
} while (bytestream2_get_byteu(&gbyte) == 255);

if (size > bytestream2_get_bytes_left(&gbyte)) {
av_log(logctx, AV_LOG_ERROR, "SEI type %d size %d truncated at %d\n",
av_log(logctx, AV_LOG_WARNING, "SEI type %d size %d truncated at %d\n",
type, size, bytestream2_get_bytes_left(&gbyte));
return AVERROR_INVALIDDATA;
}
Expand Down
6 changes: 4 additions & 2 deletions libavcodec/hevc_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
}
if (ps->sps != ps->sps_list[ps->pps->sps_id]) {
ps->sps = ps->sps_list[ps->pps->sps_id];
ps->vps = ps->vps_list[ps->sps->vps_id];
if (ps->vps_list && ps->vps_list[ps->sps->vps_id]) {
ps->vps = ps->vps_list[ps->sps->vps_id];
}
}
ow = &ps->sps->output_window;

Expand All @@ -97,7 +99,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
avctx->profile = ps->sps->ptl.general_ptl.profile_idc;
avctx->level = ps->sps->ptl.general_ptl.level_idc;

if (ps->vps->vps_timing_info_present_flag) {
if (ps->vps && ps->vps->vps_timing_info_present_flag) {
num = ps->vps->vps_num_units_in_tick;
den = ps->vps->vps_time_scale;
} else if (ps->sps->vui.vui_timing_info_present_flag) {
Expand Down
4 changes: 1 addition & 3 deletions libavcodec/hevc_ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
sps->vps_id = get_bits(gb, 4);

if (vps_list && !vps_list[sps->vps_id]) {
av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
sps->vps_id);
return AVERROR_INVALIDDATA;
av_log(avctx, AV_LOG_WARNING, "VPS %d does not exist\n", sps->vps_id);
}

sps->max_sub_layers = get_bits(gb, 3) + 1;
Expand Down
11 changes: 8 additions & 3 deletions libavcodec/hevcdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
{
AVCodecContext *avctx = s->avctx;
const HEVCParamSets *ps = &s->ps;
const HEVCVPS *vps = ps->vps_list[sps->vps_id];
const HEVCVPS *vps = NULL;
const HEVCWindow *ow = &sps->output_window;
unsigned int num = 0, den = 0;

Expand Down Expand Up @@ -364,7 +364,10 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
}

if (vps->vps_timing_info_present_flag) {
if (ps->vps_list && ps->vps_list[sps->vps_id]) {
vps = ps->vps_list[sps->vps_id];
}
if (vps && vps->vps_timing_info_present_flag) {
num = vps->vps_num_units_in_tick;
den = vps->vps_time_scale;
} else if (sps->vui.vui_timing_info_present_flag) {
Expand Down Expand Up @@ -571,7 +574,9 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
}

s->ps.sps = sps;
s->ps.vps = s->ps.vps_list[s->ps.sps->vps_id];
if (s->ps.vps_list && s->ps.vps_list[s->ps.sps->vps_id]) {
s->ps.vps = s->ps.vps_list[s->ps.sps->vps_id];
}

return 0;

Expand Down
33 changes: 13 additions & 20 deletions libavcodec/vaapi_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,23 +601,7 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
if (err < 0)
goto fail;

frames->initial_pool_size = 1;
// Add per-codec number of surfaces used for storing reference frames.
switch (avctx->codec_id) {
case AV_CODEC_ID_H264:
case AV_CODEC_ID_HEVC:
case AV_CODEC_ID_AV1:
frames->initial_pool_size += 16;
break;
case AV_CODEC_ID_VP9:
frames->initial_pool_size += 8;
break;
case AV_CODEC_ID_VP8:
frames->initial_pool_size += 3;
break;
default:
frames->initial_pool_size += 2;
}
frames->initial_pool_size = 0;
}

av_hwframe_constraints_free(&constraints);
Expand Down Expand Up @@ -665,6 +649,8 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
VAAPIDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
VAStatus vas;
int err;
AVFrame* frame;
VASurfaceID surface_id;

ctx->va_config = VA_INVALID_ID;
ctx->va_context = VA_INVALID_ID;
Expand All @@ -683,12 +669,19 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
if (err)
goto fail;

frame = av_frame_alloc();
err = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0);
if (err < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to create frame: %d\n", err);
av_frame_free(&frame);
goto fail;
}
surface_id = (VASurfaceID)(uintptr_t)frame->data[3];
vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
avctx->coded_width, avctx->coded_height,
VA_PROGRESSIVE,
ctx->hwfc->surface_ids,
ctx->hwfc->nb_surfaces,
VA_PROGRESSIVE, &surface_id, 1,
&ctx->va_context);
av_frame_free(&frame);
if (vas != VA_STATUS_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, "Failed to create decode "
"context: %d (%s).\n", vas, vaErrorStr(vas));
Expand Down
13 changes: 5 additions & 8 deletions libavcodec/vaapi_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ static int vaapi_encode_get_coded_buffer_data(AVCodecContext *avctx,
VABufferID buf_id, uint8_t **dst)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
size_t len, off;
VACodedBufferSegment *buf_list, *buf;
VAStatus vas;
int err;
Expand Down Expand Up @@ -1544,12 +1545,14 @@ static const VAEntrypoint vaapi_encode_entrypoints_normal[] = {
#endif
0
};
#if VA_CHECK_VERSION(0, 39, 2)
static const VAEntrypoint vaapi_encode_entrypoints_low_power[] = {
#if VA_CHECK_VERSION(0, 39, 2)
VAEntrypointEncSliceLP,
#endif
VAEntrypointEncSlice,
VAEntrypointEncPicture,
0
};
#endif

static av_cold int vaapi_encode_profile_entrypoint(AVCodecContext *avctx)
{
Expand All @@ -1567,13 +1570,7 @@ static av_cold int vaapi_encode_profile_entrypoint(AVCodecContext *avctx)


if (ctx->low_power) {
#if VA_CHECK_VERSION(0, 39, 2)
usable_entrypoints = vaapi_encode_entrypoints_low_power;
#else
av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not "
"supported with this VAAPI version.\n");
return AVERROR(EINVAL);
#endif
} else {
usable_entrypoints = vaapi_encode_entrypoints_normal;
}
Expand Down
20 changes: 13 additions & 7 deletions libavfilter/vaapi_vpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
AVVAAPIHWConfig *hwconfig = NULL;
AVHWFramesConstraints *constraints = NULL;
AVHWFramesContext *output_frames;
AVVAAPIFramesContext *va_frames;
VAStatus vas;
int err, i;
AVFrame* frame;
VASurfaceID surface_id;

if (ctx->pipeline_uninit)
ctx->pipeline_uninit(avctx);
Expand Down Expand Up @@ -199,7 +200,7 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
output_frames->width = ctx->output_width;
output_frames->height = ctx->output_height;

output_frames->initial_pool_size = 4;
output_frames->initial_pool_size = 0;

err = ff_filter_init_hw_frames(avctx, outlink, 10);
if (err < 0)
Expand All @@ -212,14 +213,20 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
goto fail;
}

va_frames = output_frames->hwctx;

av_assert0(ctx->va_context == VA_INVALID_ID);
frame = av_frame_alloc();
err = av_hwframe_get_buffer(outlink->hw_frames_ctx, frame, 0);
if (err < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to create frame: %d\n", err);
av_frame_free(&frame);
goto fail;
}
surface_id = (VASurfaceID)(uintptr_t)frame->data[3];
vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
ctx->output_width, ctx->output_height,
VA_PROGRESSIVE,
va_frames->surface_ids, va_frames->nb_surfaces,
VA_PROGRESSIVE, &surface_id, 1,
&ctx->va_context);
av_frame_free(&frame);
if (vas != VA_STATUS_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, "Failed to create processing pipeline "
"context: %d (%s).\n", vas, vaErrorStr(vas));
Expand Down Expand Up @@ -545,7 +552,6 @@ int ff_vaapi_vpp_init_params(AVFilterContext *avctx,
*params = (VAProcPipelineParameterBuffer) {
.surface = ff_vaapi_vpp_get_surface_id(input_frame),
.surface_region = &ctx->input_region,
.output_region = NULL,
.output_background_color = VAAPI_VPP_BACKGROUND_BLACK,
.pipeline_flags = 0,
.filter_flags = VA_FRAME_PICTURE,
Expand Down
8 changes: 6 additions & 2 deletions libavfilter/vf_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
if (in->colorspace == AVCOL_SPC_YCGCO)
av_log(link->dst, AV_LOG_WARNING, "Detected unsupported YCgCo colorspace.\n");

av_frame_apply_cropping(in, 0);
frame_changed = in->width != link->w ||
in->height != link->h ||
in->format != link->format ||
Expand Down Expand Up @@ -762,7 +763,7 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
scale->w && scale->h)
goto scale;

if (scale->eval_mode == EVAL_MODE_INIT) {
/*if (scale->eval_mode == EVAL_MODE_INIT) {
snprintf(buf, sizeof(buf) - 1, "%d", scale->w);
av_opt_set(scale, "w", buf, 0);
snprintf(buf, sizeof(buf) - 1, "%d", scale->h);
Expand All @@ -775,7 +776,7 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
ret = scale_parse_expr(ctx, NULL, &scale->h_pexpr, "height", scale->h_expr);
if (ret < 0)
return ret;
}
}*/

if (ctx->filter == &ff_vf_scale2ref) {
scale->var_values[VAR_S2R_MAIN_N] = link->frame_count_out;
Expand Down Expand Up @@ -804,6 +805,9 @@ FF_ENABLE_DEPRECATION_WARNINGS

if ((ret = config_props(outlink)) < 0)
return ret;

link->dst->inputs[0]->w = link->w;
link->dst->inputs[0]->h = link->h;
}

scale:
Expand Down
42 changes: 39 additions & 3 deletions libavfilter/vf_scale_vaapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct ScaleVAAPIContext {

char *w_expr; // width expression string
char *h_expr; // height expression string
int keep_ar;

int force_original_aspect_ratio;
int force_divisible_by;
Expand All @@ -46,6 +47,8 @@ typedef struct ScaleVAAPIContext {
int colour_range;
char *chroma_location_string;

int enable_passthrough;

enum AVColorPrimaries colour_primaries;
enum AVColorTransferCharacteristic colour_transfer;
enum AVColorSpace colour_matrix;
Expand Down Expand Up @@ -84,15 +87,19 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
ff_scale_adjust_dimensions(inlink, &vpp_ctx->output_width, &vpp_ctx->output_height,
ctx->force_original_aspect_ratio, ctx->force_divisible_by);

if (inlink->w == vpp_ctx->output_width && inlink->h == vpp_ctx->output_height &&
if (ctx->enable_passthrough &&
inlink->w == vpp_ctx->output_width && inlink->h == vpp_ctx->output_height &&
(vpp_ctx->input_frames->sw_format == vpp_ctx->output_format ||
vpp_ctx->output_format == AV_PIX_FMT_NONE) &&
ctx->colour_primaries == AVCOL_PRI_UNSPECIFIED &&
ctx->colour_transfer == AVCOL_TRC_UNSPECIFIED &&
ctx->colour_matrix == AVCOL_SPC_UNSPECIFIED &&
ctx->colour_range == AVCOL_RANGE_UNSPECIFIED &&
ctx->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
ctx->chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
vpp_ctx->passthrough = 1;
} else {
vpp_ctx->passthrough = 0;
}

err = ff_vaapi_vpp_config_output(outlink);
if (err < 0)
Expand All @@ -114,6 +121,7 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
ScaleVAAPIContext *ctx = avctx->priv;
AVFrame *output_frame = NULL;
VAProcPipelineParameterBuffer params;
VARectangle output_region;
int err;

av_log(avctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n",
Expand Down Expand Up @@ -153,6 +161,32 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
if (err < 0)
goto fail;

input_frame->crop_left = 0;
input_frame->crop_right = 0;
input_frame->crop_top = 0;
input_frame->crop_bottom = 0;
if (ctx->keep_ar && fabsf((float)params.surface_region->width / params.surface_region->height -
(float)vpp_ctx->output_width / vpp_ctx->output_height) > 0.01) {
int orx = 0, ory = 0, orw = vpp_ctx->output_width, orh = vpp_ctx->output_height;
if (params.surface_region->width * vpp_ctx->output_height >
vpp_ctx->output_width * params.surface_region->height) {
// Add vertical margins.
orh = vpp_ctx->output_width * params.surface_region->height / params.surface_region->width;
ory = (vpp_ctx->output_height - orh) / 2;
} else {
// Add horizontal margins.
orw = vpp_ctx->output_height * params.surface_region->width / params.surface_region->height;
orx = (vpp_ctx->output_width - orw) / 2;
}
output_region.x = orx;
output_region.y = ory;
output_region.width = orw;
output_region.height = orh;
params.output_region = &output_region;
} else {
params.output_region = NULL;
}

params.filter_flags |= ctx->mode;

err = ff_vaapi_vpp_render_picture(avctx, &params, output_frame);
Expand Down Expand Up @@ -221,6 +255,8 @@ static const AVOption scale_vaapi_options[] = {
OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = FLAGS },
{ "h", "Output video height",
OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = FLAGS },
{ "keep_ar", "Keep aspect ratio by padding",
OFFSET(keep_ar), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = FLAGS },
{ "format", "Output video format (software format of hardware frames)",
OFFSET(output_format_string), AV_OPT_TYPE_STRING, .flags = FLAGS },
{ "mode", "Scaling mode",
Expand Down Expand Up @@ -268,7 +304,7 @@ static const AVOption scale_vaapi_options[] = {
{ "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, "force_oar" },
{ "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" },
{ "force_divisible_by", "enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1}, 1, 256, FLAGS },

{ "enable_passthrough", "Passthrough the frame args check", OFFSET(enable_passthrough), AV_OPT_TYPE_BOOL, { .i64 = 1}, 0, 1, FLAGS },
{ NULL },
};

Expand Down
30 changes: 16 additions & 14 deletions libavformat/avc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,23 @@ static int avc_parse_nal_units(AVIOContext *pb, NALUList *list,
break;

nal_end = ff_avc_find_startcode(nal_start, end);
if (pb) {
avio_wb32(pb, nal_end - nal_start);
avio_write(pb, nal_start, nal_end - nal_start);
} else if (list->nb_nalus >= nalu_limit) {
return AVERROR(ERANGE);
} else {
NALU *tmp = av_fast_realloc(list->nalus, &list->nalus_array_size,
(list->nb_nalus + 1) * sizeof(*list->nalus));
if (!tmp)
return AVERROR(ENOMEM);
list->nalus = tmp;
tmp[list->nb_nalus++] = (NALU){ .offset = nal_start - p,
.size = nal_end - nal_start };
if (nal_end > nal_start) {
if (pb) {
avio_wb32(pb, nal_end - nal_start);
avio_write(pb, nal_start, nal_end - nal_start);
} else if (list->nb_nalus >= nalu_limit) {
return AVERROR(ERANGE);
} else {
NALU *tmp = av_fast_realloc(list->nalus, &list->nalus_array_size,
(list->nb_nalus + 1) * sizeof(*list->nalus));
if (!tmp)
return AVERROR(ENOMEM);
list->nalus = tmp;
tmp[list->nb_nalus++] = (NALU){ .offset = nal_start - p,
.size = nal_end - nal_start };
}
size += 4 + nal_end - nal_start;
}
size += 4 + nal_end - nal_start;
nal_start = nal_end;
}
return size;
Expand Down
Loading