AVRational pixel_aspect;
char *sws_param;
+ AVBufferRef *hw_frames_ctx;
+
/* audio only */
int sample_rate;
enum AVSampleFormat sample_fmt;
uint64_t channel_layout;
char *channel_layout_str;
+ int got_format_from_params;
int eof;
} BufferSourceContext;
return AVERROR(EINVAL);\
}
+AVBufferSrcParameters *av_buffersrc_parameters_alloc(void)
+{
+ AVBufferSrcParameters *par = av_mallocz(sizeof(*par));
+ if (!par)
+ return NULL;
+
+ par->format = -1;
+
+ return par;
+}
+
+int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param)
+{
+ BufferSourceContext *s = ctx->priv;
+
+ if (param->time_base.num > 0 && param->time_base.den > 0)
+ s->time_base = param->time_base;
+
+ switch (ctx->filter->outputs[0].type) {
+ case AVMEDIA_TYPE_VIDEO:
+ if (param->format != AV_PIX_FMT_NONE) {
+ s->got_format_from_params = 1;
+ s->pix_fmt = param->format;
+ }
+ if (param->width > 0)
+ s->w = param->width;
+ if (param->height > 0)
+ s->h = param->height;
+ if (param->sample_aspect_ratio.num > 0 && param->sample_aspect_ratio.den > 0)
+ s->pixel_aspect = param->sample_aspect_ratio;
+ if (param->frame_rate.num > 0 && param->frame_rate.den > 0)
+ s->frame_rate = param->frame_rate;
+ if (param->hw_frames_ctx) {
+ av_buffer_unref(&s->hw_frames_ctx);
+ s->hw_frames_ctx = av_buffer_ref(param->hw_frames_ctx);
+ if (!s->hw_frames_ctx)
+ return AVERROR(ENOMEM);
+ }
+ break;
+ case AVMEDIA_TYPE_AUDIO:
+ if (param->format != AV_SAMPLE_FMT_NONE) {
+ s->got_format_from_params = 1;
+ s->sample_fmt = param->format;
+ }
+ if (param->sample_rate > 0)
+ s->sample_rate = param->sample_rate;
+ if (param->channel_layout)
+ s->channel_layout = param->channel_layout;
+ break;
+ default:
+ return AVERROR_BUG;
+ }
+
+ return 0;
+}
+
int attribute_align_arg av_buffersrc_write_frame(AVFilterContext *ctx, const AVFrame *frame)
{
return av_buffersrc_add_frame_flags(ctx, (AVFrame *)frame,
{
BufferSourceContext *c = ctx->priv;
- if (c->pix_fmt == AV_PIX_FMT_NONE || !c->w || !c->h || av_q2d(c->time_base) <= 0) {
+ if (!(c->pix_fmt != AV_PIX_FMT_NONE || c->got_format_from_params) || !c->w || !c->h ||
+ av_q2d(c->time_base) <= 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid parameters provided.\n");
return AVERROR(EINVAL);
}
{ "sar_num", "deprecated, do not use", OFFSET(pixel_aspect.num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
{ "sar_den", "deprecated, do not use", OFFSET(pixel_aspect.den), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
#endif
- { "sar", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
- { "pixel_aspect", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
+ { "sar", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
+ { "pixel_aspect", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
{ "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
{ "frame_rate", NULL, OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
{ "sws_param", NULL, OFFSET(sws_param), AV_OPT_TYPE_STRING, .flags = V },
BufferSourceContext *s = ctx->priv;
int ret = 0;
- if (s->sample_fmt == AV_SAMPLE_FMT_NONE) {
+ if (!(s->sample_fmt != AV_SAMPLE_FMT_NONE || s->got_format_from_params)) {
av_log(ctx, AV_LOG_ERROR, "Sample format was not set or was invalid\n");
return AVERROR(EINVAL);
}
av_fifo_generic_read(s->fifo, &frame, sizeof(frame), NULL);
av_frame_free(&frame);
}
+ av_buffer_unref(&s->hw_frames_ctx);
av_fifo_freep(&s->fifo);
}
link->w = c->w;
link->h = c->h;
link->sample_aspect_ratio = c->pixel_aspect;
+
+ if (c->hw_frames_ctx) {
+ link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx);
+ if (!link->hw_frames_ctx)
+ return AVERROR(ENOMEM);
+ }
break;
case AVMEDIA_TYPE_AUDIO:
if (!c->channel_layout)
{
BufferSourceContext *c = link->src->priv;
AVFrame *frame;
+ int ret;
if (!av_fifo_size(c->fifo)) {
if (c->eof)
}
av_fifo_generic_read(c->fifo, &frame, sizeof(frame), NULL);
- return ff_filter_frame(link, frame);
+ ret = ff_filter_frame(link, frame);
+
+ return ret;
}
static int poll_frame(AVFilterLink *link)