Skip to content

Commit

Permalink
avfilter/buffersrc: add a side_data field
Browse files Browse the repository at this point in the history
This will be used to propagate global side data through the filterchain.

Signed-off-by: James Almer <jamrial@gmail.com>
  • Loading branch information
jamrial committed Jan 26, 2025
1 parent ef1cb1c commit 7a025e1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/APIchanges
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07

API changes, most recent first:

2025-01-25 - xxxxxxxxxx - lavfi 10.8.100 - buffersrc.h
Add AVBufferSrcParameters.side_data and AVBufferSrcParameters.nb_side_data

2025-01-25 - xxxxxxxxxx - lavfi 10.7.100 - avfilter.h
Add AVFilterLink.side_data and AVFilterLink.nb_side_data

Expand Down
26 changes: 26 additions & 0 deletions libavfilter/buffersrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ typedef struct BufferSourceContext {
enum AVSampleFormat sample_fmt;
int channels;
AVChannelLayout ch_layout;
AVFrameSideData **side_data;
int nb_side_data;

int eof;
int64_t last_pts;
Expand Down Expand Up @@ -160,6 +162,17 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par
return AVERROR_BUG;
}

if (param->nb_side_data > 0)
av_frame_side_data_free(&s->side_data, &s->nb_side_data);
for (int i = 0; i < param->nb_side_data; i++) {
int ret = av_frame_side_data_clone(&s->side_data, &s->nb_side_data,
param->side_data[i], 0);
if (ret < 0) {
av_frame_side_data_free(&s->side_data, &s->nb_side_data);
return ret;
}
}

return 0;
}

Expand Down Expand Up @@ -432,6 +445,7 @@ static av_cold void uninit(AVFilterContext *ctx)
BufferSourceContext *s = ctx->priv;
av_buffer_unref(&s->hw_frames_ctx);
av_channel_layout_uninit(&s->ch_layout);
av_frame_side_data_free(&s->side_data, &s->nb_side_data);
}

static int query_formats(const AVFilterContext *ctx,
Expand Down Expand Up @@ -523,6 +537,18 @@ static int config_props(AVFilterLink *link)
return AVERROR(EINVAL);
}

for (int i = 0; i < c->nb_side_data; i++) {
const AVSideDataDescriptor *desc = av_frame_side_data_desc(c->side_data[i]->type);
int ret;

ret = av_frame_side_data_clone(&link->side_data, &link->nb_side_data,
c->side_data[i], 0);
if (ret < 0) {
av_frame_side_data_free(&link->side_data, &link->nb_side_data);
return ret;
}
}

link->time_base = c->time_base;
l->frame_rate = c->frame_rate;
return 0;
Expand Down
3 changes: 3 additions & 0 deletions libavfilter/buffersrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ typedef struct AVBufferSrcParameters {
*/
enum AVColorSpace color_space;
enum AVColorRange color_range;

AVFrameSideData **side_data;
int nb_side_data;
} AVBufferSrcParameters;

/**
Expand Down
2 changes: 1 addition & 1 deletion libavfilter/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include "version_major.h"

#define LIBAVFILTER_VERSION_MINOR 7
#define LIBAVFILTER_VERSION_MINOR 8
#define LIBAVFILTER_VERSION_MICRO 100


Expand Down

0 comments on commit 7a025e1

Please sign in to comment.