[FFmpeg-devel] [PATCH 4/5] lavfi: replace link.closed by link.status.
Michael Niedermayer
michaelni at gmx.at
Mon Nov 30 23:15:05 CET 2015
On Sun, Nov 29, 2015 at 05:21:51PM +0100, Nicolas George wrote:
> The status field can carry any error code instead of just EOF.
> Also only update it through a wrapper function and provide a timestamp.
> Update the few filters that used it directly.
>
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
> libavfilter/avfilter.c | 25 ++++++++++++++++++-------
> libavfilter/avfilter.h | 12 ++++++------
> libavfilter/buffersink.c | 4 ++--
> libavfilter/f_interleave.c | 4 ++--
> libavfilter/internal.h | 12 ++++++++++++
> libavfilter/split.c | 2 +-
> libavfilter/trim.c | 6 ++++--
> libavfilter/vf_extractplanes.c | 2 +-
> 8 files changed, 46 insertions(+), 21 deletions(-)
>
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 06a8239..9c7b462 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -177,9 +177,20 @@ int avfilter_link_get_channels(AVFilterLink *link)
> return link->channels;
> }
>
> +void ff_avfilter_link_set_in_status(AVFilterLink *link, int status, int64_t pts)
> +{
> + ff_avfilter_link_set_out_status(link, status, pts);
> +}
> +
> +void ff_avfilter_link_set_out_status(AVFilterLink *link, int status, int64_t pts)
> +{
> + link->status = status;
> + ff_update_link_current_pts(link, pts);
> +}
> +
> void avfilter_link_set_closed(AVFilterLink *link, int closed)
> {
> - link->closed = closed;
> + ff_avfilter_link_set_out_status(link, closed ? AVERROR_EOF : 0, AV_NOPTS_VALUE);
> }
>
> int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
> @@ -345,8 +356,8 @@ int ff_request_frame(AVFilterLink *link)
> int ret = -1;
> FF_TPRINTF_START(NULL, request_frame); ff_tlog_link(NULL, link, 1);
>
> - if (link->closed)
> - return AVERROR_EOF;
> + if (link->status)
> + return link->status;
> if (link->srcpad->request_frame)
> ret = link->srcpad->request_frame(link);
> else if (link->src->inputs[0])
> @@ -357,8 +368,8 @@ int ff_request_frame(AVFilterLink *link)
> ret = ff_filter_frame_framed(link, pbuf);
> }
> if (ret < 0) {
> - if (ret == AVERROR_EOF)
> - link->closed = 1;
> + if (ret != AVERROR(EAGAIN) && ret != link->status)
> + ff_avfilter_link_set_in_status(link, ret, AV_NOPTS_VALUE);
> }
> return ret;
> }
> @@ -1004,9 +1015,9 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
> AVFilterCommand *cmd= link->dst->command_queue;
> int64_t pts;
>
> - if (link->closed) {
> + if (link->status) {
> av_frame_free(&frame);
> - return AVERROR_EOF;
> + return link->status;
> }
>
> if (!(filter_frame = dst->filter_frame))
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 58a0cbd..f3a0f2d 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -490,16 +490,16 @@ struct AVFilterLink {
> int max_samples;
>
> /**
> - * True if the link is closed.
> - * If set, all attempts of start_frame, filter_frame or request_frame
> - * will fail with AVERROR_EOF, and if necessary the reference will be
> - * destroyed.
> - * If request_frame returns AVERROR_EOF, this flag is set on the
> + * Link status.
> + * If not zero, all attempts of start_frame, filter_frame or request_frame
> + * will fail with the corresponding code, and if necessary the reference
> + * will be destroyed.
> + * If request_frame returns an error, the status is set on the
> * corresponding link.
> * It can be set also be set by either the source or the destination
> * filter.
> */
> - int closed;
> + int status;
>
> /**
> * Number of channels.
> diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
> index 5db86abd..7a19df2 100644
> --- a/libavfilter/buffersink.c
> +++ b/libavfilter/buffersink.c
> @@ -134,8 +134,8 @@ int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFr
>
> /* no picref available, fetch it from the filterchain */
> while (!av_fifo_size(buf->fifo)) {
> - if (inlink->closed)
> - return AVERROR_EOF;
> + if (inlink->status)
> + return inlink->status;
> if (flags & AV_BUFFERSINK_FLAG_NO_REQUEST)
> return AVERROR(EAGAIN);
> if ((ret = ff_request_frame(inlink)) < 0)
> diff --git a/libavfilter/f_interleave.c b/libavfilter/f_interleave.c
> index e0915b5..422f2bf 100644
> --- a/libavfilter/f_interleave.c
> +++ b/libavfilter/f_interleave.c
> @@ -59,7 +59,7 @@ inline static int push_frame(AVFilterContext *ctx)
> for (i = 0; i < ctx->nb_inputs; i++) {
> struct FFBufQueue *q = &s->queues[i];
>
> - if (!q->available && !ctx->inputs[i]->closed)
> + if (!q->available && !ctx->inputs[i]->status)
> return 0;
> if (q->available) {
> frame = ff_bufqueue_peek(q, 0);
> @@ -190,7 +190,7 @@ static int request_frame(AVFilterLink *outlink)
> int i, ret;
>
> for (i = 0; i < ctx->nb_inputs; i++) {
> - if (!s->queues[i].available && !ctx->inputs[i]->closed) {
> + if (!s->queues[i].available && !ctx->inputs[i]->status) {
> ret = ff_request_frame(ctx->inputs[i]);
> if (ret != AVERROR_EOF)
> return ret;
> diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> index 1cc6bf3..e55ae9d 100644
> --- a/libavfilter/internal.h
> +++ b/libavfilter/internal.h
> @@ -225,6 +225,18 @@ int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
>
> void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
>
> +/**
> + * Set the status field of a link from the source filter.
> + * The pts should reflect the timestamp of the status change.
> + */
> +void ff_avfilter_link_set_in_status(AVFilterLink *link, int status, int64_t pts);
this should mention in which timebase the pts is and possibly
relative to what the timestamp is
its rather obvious to write
AVERROR(ENOMEM)
pts = av_gettime()
based on this documentation
> +
> +/**
> + * Set the status field of a link from the destination filter.
> + * The pts should probably be left unset.
> + */
> +void ff_avfilter_link_set_out_status(AVFilterLink *link, int status, int64_t pts);
s/unset/AV_NOPTS_VALUE/ ?
rest of this patch LGTM, no need to resubmit for just above things
if there are no other reasons to do so
thanks
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
DNS cache poisoning attacks, popular search engine, Google internet authority
dont be evil, please
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151130/b0755720/attachment.sig>
More information about the ffmpeg-devel
mailing list